From f1025c1012659e63185161a35262a85a5b103109 Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Tue, 20 Feb 2024 10:03:11 -0800 Subject: [PATCH 1/6] Clean up unused and extraneous code --- .../http-server/tests/create-exchange.spec.ts | 41 +++++++++++-------- .../http-server/tests/get-exchanges.spec.ts | 4 +- .../http-server/tests/get-offerings.spec.ts | 7 ++-- .../http-server/tests/submit-close.spec.ts | 39 +++++++++--------- .../http-server/tests/submit-order.spec.ts | 29 ++++++------- packages/protocol/src/crypto.ts | 24 +---------- packages/protocol/src/dev-tools.ts | 41 +------------------ packages/protocol/src/did-resolver.ts | 14 ++----- packages/protocol/tests/crypto.spec.ts | 24 ++--------- packages/protocol/tests/exchange.spec.ts | 6 +-- .../protocol/tests/generate-test-vectors.ts | 13 +++--- packages/protocol/tests/offering.spec.ts | 11 ++--- packages/protocol/tests/parse.spec.ts | 7 ++-- packages/protocol/tests/rfq.spec.ts | 21 +++++----- 14 files changed, 104 insertions(+), 177 deletions(-) diff --git a/packages/http-server/tests/create-exchange.spec.ts b/packages/http-server/tests/create-exchange.spec.ts index b192e14f..a232d17e 100644 --- a/packages/http-server/tests/create-exchange.spec.ts +++ b/packages/http-server/tests/create-exchange.spec.ts @@ -1,12 +1,13 @@ -import { ErrorDetail, Offering, Rfq } from '@tbdex/http-client' +import { ErrorDetail, Offering, Order, Rfq } from '@tbdex/http-client' import type { Server } from 'http' import { DevTools, RequestContext, TbdexHttpServer } from '../src/main.js' import { expect } from 'chai' import { InMemoryExchangesApi } from '../src/in-memory-exchanges-api.js' import { InMemoryOfferingsApi } from '../src/in-memory-offerings-api.js' -import { BearerDid } from '@web5/dids' +import { BearerDid, DidDht, DidJwk } from '@web5/dids' import Sinon from 'sinon' +import { Message } from '@tbdex/protocol' describe('POST /exchanges/:exchangeId/rfq', () => { let api: TbdexHttpServer @@ -54,8 +55,8 @@ describe('POST /exchanges/:exchangeId/rfq', () => { }) it('returns a 400 if create exchange request contains a replyTo which is not a valid URL', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid('dht') + const aliceDid = await DidJwk.create() + const pfiDid = await DidDht.create() const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid }) await rfq.sign(aliceDid) @@ -75,10 +76,16 @@ describe('POST /exchanges/:exchangeId/rfq', () => { }) it('returns a 400 if request body is not a valid RFQ', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() - const order = await DevTools.createOrder({ sender: aliceDid, receiver: pfiDid }) + const order = Order.create({ + metadata: { + from : aliceDid.uri, + to : pfiDid.uri, + exchangeId : Message.generateId('rfq') + } + }) await order.sign(aliceDid) const resp = await fetch('http://localhost:8000/exchanges/123/rfq', { @@ -97,8 +104,8 @@ describe('POST /exchanges/:exchangeId/rfq', () => { }) it('returns a 400 if request body if integrity check fails', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid }) // deliberately omit rfq.sign(aliceDid) @@ -119,8 +126,8 @@ describe('POST /exchanges/:exchangeId/rfq', () => { }) it('returns a 409 if request body if RFQ already exists', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid }) await rfq.sign(aliceDid); @@ -143,8 +150,8 @@ describe('POST /exchanges/:exchangeId/rfq', () => { }) it('returns a 400 if request body if offering doesnt exist', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const offering = DevTools.createOffering() // deliberately omit (api.offeringsApi as InMemoryOfferingsApi).addOffering(offering) @@ -176,8 +183,8 @@ describe('POST /exchanges/:exchangeId/rfq', () => { }) it(`returns a 400 if request body if RFQ does not fulfill offering's requirements`, async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() // Add offering to api.offeringsApi const offering = DevTools.createOffering() @@ -220,8 +227,8 @@ describe('POST /exchanges/:exchangeId/rfq', () => { let rfq: Rfq beforeEach(async () => { - aliceDid = await DevTools.createDid() - pfiDid = await DevTools.createDid() + aliceDid = await DidJwk.create() + pfiDid = await DidJwk.create() // Add offering with no required claims to api.offeringsApi offering = Offering.create({ diff --git a/packages/http-server/tests/get-exchanges.spec.ts b/packages/http-server/tests/get-exchanges.spec.ts index c3c924b4..27edc55e 100644 --- a/packages/http-server/tests/get-exchanges.spec.ts +++ b/packages/http-server/tests/get-exchanges.spec.ts @@ -139,8 +139,8 @@ describe('GET /exchanges', () => { }) it('calls the callback if it is provided', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid }) await rfq.sign(aliceDid); (api.exchangesApi as InMemoryExchangesApi).addMessage(rfq) diff --git a/packages/http-server/tests/get-offerings.spec.ts b/packages/http-server/tests/get-offerings.spec.ts index 436d043a..5a99a6f9 100644 --- a/packages/http-server/tests/get-offerings.spec.ts +++ b/packages/http-server/tests/get-offerings.spec.ts @@ -5,6 +5,7 @@ import { GetOfferingsFilter, RequestContext, TbdexHttpServer } from '../src/main import { expect } from 'chai' import { InMemoryOfferingsApi } from '../src/in-memory-offerings-api.js' import Sinon from 'sinon' +import { DidJwk } from '@web5/dids' describe('GET /offerings', () => { let api: TbdexHttpServer @@ -21,7 +22,7 @@ describe('GET /offerings', () => { }) it('returns an array of offerings', async () => { - const pfiDid = await DevTools.createDid() + const pfiDid = await DidJwk.create() const offering = DevTools.createOffering() await offering.sign(pfiDid); (api.offeringsApi as InMemoryOfferingsApi).addOffering(offering) @@ -36,7 +37,7 @@ describe('GET /offerings', () => { }) it('constructs the filter from query params and passes it to OfferingsApi', async () => { - const pfiDid = await DevTools.createDid() + const pfiDid = await DidJwk.create() // Add an offering to OfferingsApi const offering = DevTools.createOffering() @@ -69,7 +70,7 @@ describe('GET /offerings', () => { }) it('calls the callback if it is provided', async () => { - const pfiDid = await DevTools.createDid() + const pfiDid = await DidJwk.create() const offering = DevTools.createOffering() await offering.sign(pfiDid); (api.offeringsApi as InMemoryOfferingsApi).addOffering(offering) diff --git a/packages/http-server/tests/submit-close.spec.ts b/packages/http-server/tests/submit-close.spec.ts index 2da13d12..51496893 100644 --- a/packages/http-server/tests/submit-close.spec.ts +++ b/packages/http-server/tests/submit-close.spec.ts @@ -5,6 +5,7 @@ import { Close, DevTools, TbdexHttpServer } from '../src/main.js' import { expect } from 'chai' import { InMemoryExchangesApi } from '../src/in-memory-exchanges-api.js' import Sinon from 'sinon' +import { DidJwk } from '@web5/dids' describe('POST /exchanges/:exchangeId/close', () => { @@ -53,8 +54,8 @@ describe('POST /exchanges/:exchangeId/close', () => { }) it('returns a 400 if request body is not a valid close object', async () => { - const alice = await DevTools.createDid() - const rfq = DevTools.createRfq({ + const alice = await DidJwk.create() + const rfq = await DevTools.createRfq({ sender: alice }) const resp = await fetch('http://localhost:8000/exchanges/123/close', { @@ -73,8 +74,8 @@ describe('POST /exchanges/:exchangeId/close', () => { }) it(`returns a 404 if the exchange doesn't exist`, async () => { - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() const close = Close.create({ metadata: { from : alice.uri, @@ -100,8 +101,8 @@ describe('POST /exchanges/:exchangeId/close', () => { }) it(`returns a 409 if close is not allowed based on the exchange's current state`, async () => { - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() const rfq = await DevTools.createRfq({ sender : alice, @@ -147,8 +148,8 @@ describe('POST /exchanges/:exchangeId/close', () => { }) it('returns a 400 if request body if integrity check fails', async () => { - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() const rfq = await DevTools.createRfq({ sender : alice, @@ -188,8 +189,8 @@ describe('POST /exchanges/:exchangeId/close', () => { it('returns a 202 if close is created by alice', async () => { // scenario: Alice creates an exchange and submits a Close message - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() const rfq = await DevTools.createRfq({ sender : alice, @@ -222,8 +223,8 @@ describe('POST /exchanges/:exchangeId/close', () => { it('returns a 202 if close is created by pfi', async () => { // scenario: Alice creates an exchange and PFI submits a Close message - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() const rfq = await DevTools.createRfq({ sender : alice, @@ -255,9 +256,9 @@ describe('POST /exchanges/:exchangeId/close', () => { it('returns a 400 if the close is created by neither alice nor pfi', async () => { - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() - const imposter = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() + const imposter = await DidJwk.create() const rfq = await DevTools.createRfq({ sender : alice, @@ -296,8 +297,8 @@ describe('POST /exchanges/:exchangeId/close', () => { describe('onSubmitClose callback', () => { it('does not call the callback if the close is is not valid for the current exchange', async () => { - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() // Close message signed by Alice const close = Close.create({ @@ -323,8 +324,8 @@ describe('POST /exchanges/:exchangeId/close', () => { }) it('returns a 202 if the provided callback succeeds and passes correct arguments to callback', async () => { - const alice = await DevTools.createDid() - const pfi = await DevTools.createDid() + const alice = await DidJwk.create() + const pfi = await DidJwk.create() const rfq = await DevTools.createRfq({ sender : alice, diff --git a/packages/http-server/tests/submit-order.spec.ts b/packages/http-server/tests/submit-order.spec.ts index 84781b20..1fa14c79 100644 --- a/packages/http-server/tests/submit-order.spec.ts +++ b/packages/http-server/tests/submit-order.spec.ts @@ -5,6 +5,7 @@ import { DevTools, Order, RequestContext, TbdexHttpServer } from '../src/main.js import { expect } from 'chai' import { InMemoryExchangesApi } from '../src/in-memory-exchanges-api.js' import Sinon from 'sinon' +import { DidJwk } from '@web5/dids' describe('POST /exchanges/:exchangeId/order', () => { @@ -53,8 +54,8 @@ describe('POST /exchanges/:exchangeId/order', () => { }) it(`returns a 404 if the exchange doesn't exist`, async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const order = Order.create({ metadata: { from : aliceDid.uri, @@ -81,8 +82,8 @@ describe('POST /exchanges/:exchangeId/order', () => { it('returns a 400 if request body is not a valid order object', async () => { // scenario: Send an Rfq to the submitOrder endpoint - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid }) await rfq.sign(aliceDid) @@ -103,8 +104,8 @@ describe('POST /exchanges/:exchangeId/order', () => { }) it('returns a 400 if request body if integrity check fails', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const order = Order.create({ metadata: { @@ -131,8 +132,8 @@ describe('POST /exchanges/:exchangeId/order', () => { }) it(`returns a 409 if order is not allowed based on the exchange's current state`, async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() const rfq = Rfq.create({ metadata: { from : aliceDid.uri, @@ -168,8 +169,8 @@ describe('POST /exchanges/:exchangeId/order', () => { }) it(`returns a 400 if quote has expired`, async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() // Add an exchange which has a Quote that expired 10 seconds ago const rfq = Rfq.create({ @@ -220,8 +221,8 @@ describe('POST /exchanges/:exchangeId/order', () => { }) it('returns a 202 if order is accepted', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() // Add an exchange of Rfq and Quote to the exchangesApi const rfq = Rfq.create({ @@ -268,8 +269,8 @@ describe('POST /exchanges/:exchangeId/order', () => { describe('onSubmitClose callback', () => { it('returns a 202 if the provided callback succeeds and passes correct arguments to callback', async () => { - const aliceDid = await DevTools.createDid() - const pfiDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() + const pfiDid = await DidJwk.create() // Add an exchange of Rfq and Quote to the exchangesApi const rfq = Rfq.create({ diff --git a/packages/protocol/src/crypto.ts b/packages/protocol/src/crypto.ts index e8536440..312bbaa4 100644 --- a/packages/protocol/src/crypto.ts +++ b/packages/protocol/src/crypto.ts @@ -2,8 +2,6 @@ import type { JwsHeaderParams, JwkParamsEcPublic, JwkParamsOkpPublic, - PrivateKeyJwk, - PublicKeyJwk, } from '@web5/crypto' import { sha256 } from '@noble/hashes/sha256' @@ -76,9 +74,7 @@ export class Crypto { verificationMethodId = `${did.uri}${verificationMethodId}` } - - - const jwsHeader: JwsHeader = { alg: signer.algorithm, kid: verificationMethodId } + const jwsHeader: JwsHeaderParams = { alg: signer.algorithm, kid: verificationMethodId } const base64UrlEncodedJwsHeader = Convert.object(jwsHeader).toBase64Url() const base64urlEncodedJwsPayload = Convert.uint8Array(payload).toBase64Url() @@ -157,22 +153,4 @@ export class Crypto { const [did] = jwsHeader.kid.split('#') return did } - - /** - * Gets crv property from a PublicKeyJwk or PrivateKeyJwk. Returns empty string if crv is undefined. - */ - static extractNamedCurve(jwk: PrivateKeyJwk | PublicKeyJwk | undefined): string { - if (jwk && 'crv' in jwk) { - return jwk.crv - } else { - return '' - } - } } - -/** - * monkey patch of JwsHeaderParams to include `EdDSA` as a valid alg - * **NOTE**: Remove this once upstream `@web5/crypto` package is fixed - * @internal - */ -type JwsHeader = Omit & { alg: JwsHeaderParams['alg'] | 'EdDSA' } \ No newline at end of file diff --git a/packages/protocol/src/dev-tools.ts b/packages/protocol/src/dev-tools.ts index 38f84116..5e001db3 100644 --- a/packages/protocol/src/dev-tools.ts +++ b/packages/protocol/src/dev-tools.ts @@ -2,19 +2,11 @@ import type { OfferingData, QuoteData, RfqData } from './types.js' import type { BearerDid } from '@web5/dids' -import { DidDht, DidJwk } from '@web5/dids' import { Offering } from './resource-kinds/index.js' -import { Order, Rfq } from './message-kinds/index.js' +import { Rfq } from './message-kinds/index.js' import { Resource } from './resource.js' -import { Message } from './main.js' import { VerifiableCredential } from '@web5/credentials' -/** - * Supported DID Methods - * @beta - */ -export type DidMethodOptions = 'dht' | 'jwk' - /** * Options passed to {@link DevTools.createRfq} * @beta @@ -36,20 +28,6 @@ export type MessageOptions = { * @beta */ export class DevTools { - /** - * creates and returns a DID - * @param didMethod - the type of DID to create. defaults to did:jwk - */ - static async createDid(didMethod: DidMethodOptions = 'jwk'): Promise { - if (didMethod === 'jwk') { - return await DidJwk.create() - } else if (didMethod === 'dht') { - return await DidDht.create() - } else { - throw new Error(`${didMethod} method not implemented.`) - } - } - /** * creates and returns an example offering. Useful for testing purposes */ @@ -185,23 +163,6 @@ export class DevTools { }) } - /** - * Creates and returns an example Order with a generated exchangeId. Useful for testing purposes - * @param opts - options used to create a Message - * @returns Order message - */ - static createOrder(opts: MessageOptions) { - const { sender, receiver } = opts - - return Order.create({ - metadata: { - from : sender.uri, - to : receiver?.uri ?? 'did:ex:pfi', - exchangeId : Message.generateId('rfq') - } - }) - } - /** * creates an example RfqData. Useful for testing purposes */ diff --git a/packages/protocol/src/did-resolver.ts b/packages/protocol/src/did-resolver.ts index 3e899e84..7b082e92 100644 --- a/packages/protocol/src/did-resolver.ts +++ b/packages/protocol/src/did-resolver.ts @@ -1,9 +1,9 @@ -import type { DidDocument, DidService, DidVerificationMethod } from '@web5/dids' +import type { DidDocument, DidResource, DidVerificationMethod } from '@web5/dids' import { DidResolver as Web5DidResolver, DidDht, DidJwk, DidWeb } from '@web5/dids' /** - * Can be used to resolve did:ion and did:key DIDs + * Can be used to resolve and dereference did:dht, did:jwk, and did:web DIDs * * @beta */ @@ -20,9 +20,7 @@ export const DidResolver = new Web5DidResolver({ export async function resolveDid(did: string): Promise { const { didResolutionMetadata, didDocument } = await DidResolver.resolve(did) - // TODO: remove the '?' after we ask OSE peeps about why DID ION resolution doesn't return didResolutionMetadata - // despite being required as per the did-core spec - if (didResolutionMetadata?.error) { + if (didResolutionMetadata.error) { throw new Error(`Failed to resolve DID: ${did}. Error: ${didResolutionMetadata.error}`) } @@ -30,12 +28,6 @@ export async function resolveDid(did: string): Promise { return didDocument! } -/** - * A DID Resource is either a DID Document, a DID Verification method or a DID Service - * @beta - */ -export type DidResource = DidDocument | DidVerificationMethod | DidService - /** * type guard for {@link @web5/dids#VerificationMethod} * @param didResource - the resource to check diff --git a/packages/protocol/tests/crypto.spec.ts b/packages/protocol/tests/crypto.spec.ts index a65145d9..30059295 100644 --- a/packages/protocol/tests/crypto.spec.ts +++ b/packages/protocol/tests/crypto.spec.ts @@ -1,31 +1,13 @@ import { expect } from 'chai' import { Convert } from '@web5/common' -import { Crypto, DevTools } from '../src/main.js' +import { Crypto } from '../src/main.js' +import { DidJwk } from '@web5/dids' describe('Crypto', () => { describe('sign / verify', () => { - it('works with did:ion', async () => { - const alice = await DevTools.createDid() - const payload = { timestamp: new Date().toISOString() } - const payloadBytes = Convert.object(payload).toUint8Array() - - const token = await Crypto.sign({ did: alice, payload: payloadBytes, detached: false }) - await Crypto.verify({ signature: token }) - }).timeout(30_000) - - it('works with did:key', async () => { - const alice = await DevTools.createDid() - - const payload = { timestamp: new Date().toISOString() } - const payloadBytes = Convert.object(payload).toUint8Array() - - const token = await Crypto.sign({ did: alice, payload: payloadBytes, detached: false }) - await Crypto.verify({ signature: token }) - }) - it('works with detached content', async () => { - const alice = await DevTools.createDid() + const alice = await DidJwk.create() const payload = { timestamp: new Date().toISOString() } const payloadBytes = Convert.object(payload).toUint8Array() diff --git a/packages/protocol/tests/exchange.spec.ts b/packages/protocol/tests/exchange.spec.ts index e7c6f70e..b934f3f8 100644 --- a/packages/protocol/tests/exchange.spec.ts +++ b/packages/protocol/tests/exchange.spec.ts @@ -1,4 +1,4 @@ -import { BearerDid } from '@web5/dids' +import { BearerDid, DidDht, DidJwk } from '@web5/dids' import { expect } from 'chai' import { Close, DevTools, Exchange, Message, Order, OrderStatus, Quote, Rfq } from '../src/main.js' @@ -13,8 +13,8 @@ describe('Exchange', () => { let orderStatus: OrderStatus beforeEach(async () => { - aliceDid = await DevTools.createDid() - pfiDid = await DevTools.createDid('dht') + aliceDid = await DidJwk.create() + pfiDid = await DidDht.create() rfq = Rfq.create({ metadata: { diff --git a/packages/protocol/tests/generate-test-vectors.ts b/packages/protocol/tests/generate-test-vectors.ts index 1eef4019..0528c011 100644 --- a/packages/protocol/tests/generate-test-vectors.ts +++ b/packages/protocol/tests/generate-test-vectors.ts @@ -1,6 +1,7 @@ import { VerifiableCredential } from '@web5/credentials' import { Close, DevTools, Message, Order, OrderStatus, Quote, Resource, Rfq } from '../src/main.js' import fs from 'fs' +import { DidDht, DidJwk } from '@web5/dids' /** * Use this util when you are modifying or adding a new test vector to `tbdex`. @@ -13,7 +14,7 @@ type TestVector = { } const generateParseOfferingVector = async () => { - const pfiDid = await await DevTools.createDid('dht') + const pfiDid = await await DidDht.create() const offering = DevTools.createOffering({ from: pfiDid.uri }) await offering.sign(pfiDid) @@ -27,7 +28,7 @@ const generateParseOfferingVector = async () => { } const generateParseQuoteVector = async () => { - const pfiDid = await DevTools.createDid('dht') + const pfiDid = await DidDht.create() const quote = Quote.create({ metadata: { exchangeId : Message.generateId('rfq'), @@ -47,7 +48,7 @@ const generateParseQuoteVector = async () => { } const generateParseRfqVector = async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const vc = await VerifiableCredential.create({ type : 'PuupuuCredential', issuer : aliceDid.uri, @@ -94,7 +95,7 @@ const generateParseRfqVector = async () => { } const generateParseOrderVector = async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const order = Order.create({ metadata: { from: aliceDid.uri, to: 'did:ex:pfi', exchangeId: Message.generateId('rfq'), externalId: 'ext_1234' } }) @@ -110,7 +111,7 @@ const generateParseOrderVector = async () => { } const generateParseCloseVector = async () => { - const pfiDid = await DevTools.createDid('dht') + const pfiDid = await DidDht.create() const close = Close.create({ metadata : { from: pfiDid.uri, to: 'did:ex:alice', exchangeId: Message.generateId('rfq') }, data : { @@ -129,7 +130,7 @@ const generateParseCloseVector = async () => { } const generateParseOrderStatusVector = async () => { - const pfiDid = await DevTools.createDid() + const pfiDid = await DidJwk.create() const orderStatus = OrderStatus.create({ metadata : { from: pfiDid.uri, to: 'did:ex:alice', exchangeId: Message.generateId('rfq') }, data : { diff --git a/packages/protocol/tests/offering.spec.ts b/packages/protocol/tests/offering.spec.ts index 3527132d..154b8ddd 100644 --- a/packages/protocol/tests/offering.spec.ts +++ b/packages/protocol/tests/offering.spec.ts @@ -2,6 +2,7 @@ import { Offering, Parser } from '../src/main.js' import { DevTools } from '../src/dev-tools.js' import { Convert } from '@web5/common' import { expect } from 'chai' +import { DidDht } from '@web5/dids' describe('Offering', () => { describe('create', () => { @@ -36,7 +37,7 @@ describe('Offering', () => { describe('sign', () => { it('sets signature property', async () => { - const pfi = await DevTools.createDid('dht') + const pfi = await DidDht.create() const offering = Offering.create({ metadata : { from: pfi.uri }, data : DevTools.createOfferingData() @@ -50,7 +51,7 @@ describe('Offering', () => { }) it('includes alg and kid in jws header', async () => { - const pfi = await DevTools.createDid('dht') + const pfi = await DidDht.create() const offering = Offering.create({ metadata : { from: pfi.uri }, data : DevTools.createOfferingData() @@ -68,7 +69,7 @@ describe('Offering', () => { describe('verify', () => { it('does not throw an exception if resource integrity is intact', async () => { - const pfi = await DevTools.createDid('dht') + const pfi = await DidDht.create() const offering = Offering.create({ metadata : { from: pfi.uri }, data : DevTools.createOfferingData() @@ -79,7 +80,7 @@ describe('Offering', () => { }) it('throws an error if no signature is present on the resource provided', async () => { - const pfi = await DevTools.createDid('dht') + const pfi = await DidDht.create() const offering = Offering.create({ metadata : { from: pfi.uri }, data : DevTools.createOfferingData() @@ -113,7 +114,7 @@ describe('Offering', () => { }) it('returns a Resource instance if parsing is successful', async () => { - const pfi = await DevTools.createDid('dht') + const pfi = await DidDht.create() const offering = Offering.create({ metadata : { from: pfi.uri }, data : DevTools.createOfferingData() diff --git a/packages/protocol/tests/parse.spec.ts b/packages/protocol/tests/parse.spec.ts index 37d768d8..335869de 100644 --- a/packages/protocol/tests/parse.spec.ts +++ b/packages/protocol/tests/parse.spec.ts @@ -1,10 +1,11 @@ +import { DidJwk } from '@web5/dids' import { expect } from 'chai' -import { DevTools, Parser } from '../src/main.js' +import { Parser } from '../src/main.js' describe('Parser', () => { describe('parseMessage', async () => { it('throws if an unrecognized message kind is passed', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const unrecognizedMessageKind = { metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : {}, @@ -24,7 +25,7 @@ describe('Parser', () => { describe('parseResource', async () => { it('throws if an unrecognized resource kind is passed', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const unrecognizedResourceKind = { metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : {}, diff --git a/packages/protocol/tests/rfq.spec.ts b/packages/protocol/tests/rfq.spec.ts index 63e44ed3..67207a30 100644 --- a/packages/protocol/tests/rfq.spec.ts +++ b/packages/protocol/tests/rfq.spec.ts @@ -4,11 +4,12 @@ import { CreateRfqOptions, Offering } from '../src/main.js' import { Rfq, DevTools } from '../src/main.js' import { Convert } from '@web5/common' import { expect } from 'chai' +import { DidDht, DidJwk } from '@web5/dids' describe('Rfq', () => { describe('create', () => { it('creates an rfq', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const message = Rfq.create({ metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : await DevTools.createRfqData() @@ -23,7 +24,7 @@ describe('Rfq', () => { describe('sign', () => { it('sets signature property', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const rfq = Rfq.create({ metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : await DevTools.createRfqData() @@ -36,7 +37,7 @@ describe('Rfq', () => { }) it('includes alg and kid in jws header', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const rfq = Rfq.create({ metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : await DevTools.createRfqData() @@ -54,7 +55,7 @@ describe('Rfq', () => { describe('verify', () => { it('does not throw an exception if message integrity is intact', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const rfq = Rfq.create({ metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : await DevTools.createRfqData() @@ -65,7 +66,7 @@ describe('Rfq', () => { }) it('throws an error if no signature is present on the message provided', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const rfq = Rfq.create({ metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : await DevTools.createRfqData() @@ -98,7 +99,7 @@ describe('Rfq', () => { }) it('returns an instance of Message if parsing is successful', async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const rfq = Rfq.create({ metadata : { from: aliceDid.uri, to: 'did:ex:pfi' }, data : await DevTools.createRfqData() @@ -134,7 +135,7 @@ describe('Rfq', () => { let rfqOptions: CreateRfqOptions beforeEach(async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const vc = await VerifiableCredential.create({ // this credential fulfills the offering's required claims type : 'SanctionsCredential', issuer : aliceDid.uri, @@ -167,7 +168,7 @@ describe('Rfq', () => { }) it('succeeds if Rfq satisfies required payin amount and Offering has no required claims', async () => { - const pfi = await DevTools.createDid('dht') + const pfi = await DidDht.create() const offeringData = DevTools.createOfferingData() offeringData.requiredClaims = undefined @@ -459,7 +460,7 @@ describe('Rfq', () => { describe('verifyClaims', () => { it(`does not throw an exception if an rfq's claims fulfill the provided offering's requirements`, async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const offering = DevTools.createOffering() const vc = await VerifiableCredential.create({ // this credential fulfills the offering's required claims type : 'SanctionsCredential', @@ -484,7 +485,7 @@ describe('Rfq', () => { }) it(`throws an exception if an rfq's claims dont fulfill the provided offering's requirements`, async () => { - const aliceDid = await DevTools.createDid() + const aliceDid = await DidJwk.create() const offering = DevTools.createOffering() const vc = await VerifiableCredential.create({ type : 'PuupuuCredential', From 399647fa1a6a8d96744cb7808da7eea9bcb8a63f Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Thu, 22 Feb 2024 10:58:18 -0800 Subject: [PATCH 2/6] Changeset --- .changeset/fluffy-eggs-collect.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/fluffy-eggs-collect.md diff --git a/.changeset/fluffy-eggs-collect.md b/.changeset/fluffy-eggs-collect.md new file mode 100644 index 00000000..aeae2eae --- /dev/null +++ b/.changeset/fluffy-eggs-collect.md @@ -0,0 +1,6 @@ +--- +"@tbdex/http-server": minor +"@tbdex/protocol": minor +--- + +Remove DevTools.createDid, extractNamedCurve, and JwsHeader From f63f48280738a54f1aada83bb59637ea2aa6c57f Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Thu, 22 Feb 2024 11:07:10 -0800 Subject: [PATCH 3/6] woops --- packages/protocol/tests/rfq.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/tests/rfq.spec.ts b/packages/protocol/tests/rfq.spec.ts index 67207a30..a2836791 100644 --- a/packages/protocol/tests/rfq.spec.ts +++ b/packages/protocol/tests/rfq.spec.ts @@ -427,7 +427,7 @@ describe('Rfq', () => { } ] - const pfi = await DevTools.createDid() + const pfi = await DidJwk.create() const offering = Offering.create({ metadata : { from: pfi.uri }, @@ -436,7 +436,7 @@ describe('Rfq', () => { await offering.sign(pfi) // Construct RFQ with a payin method that has payin detail 'cardNumber' - const alice = await DevTools.createDid() + const alice = await DidJwk.create() const rfqData = await DevTools.createRfqData() rfqData.offeringId = offering.metadata.id rfqData.payinMethod = { From 7cf3f127bc6d256eff8d19c51fdc23d95a218a1c Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Fri, 23 Feb 2024 12:16:58 -0800 Subject: [PATCH 4/6] Update submodule to use updated test vectors --- packages/protocol/tests/test-vectors.spec.ts | 3 ++- tbdex | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/protocol/tests/test-vectors.spec.ts b/packages/protocol/tests/test-vectors.spec.ts index 0e42ca7f..1de26464 100644 --- a/packages/protocol/tests/test-vectors.spec.ts +++ b/packages/protocol/tests/test-vectors.spec.ts @@ -8,7 +8,8 @@ import ParseRfq from '../../../tbdex/hosted/test-vectors/protocol/vectors/parse- import { Close, Offering, Order, OrderStatus, Quote, Rfq } from '../src/main.js' import { Parser } from '../src/parser.js' -describe('TbdexTestVectorsProtocol', () => { +describe('TbdexTestVectorsProtocol', function () { + this.timeout(10000); it('parse_close', async () => { // Parse with parseMessage() const message = await Parser.parseMessage(ParseClose.input) diff --git a/tbdex b/tbdex index 9a9ed692..27eed587 160000 --- a/tbdex +++ b/tbdex @@ -1 +1 @@ -Subproject commit 9a9ed69272a92119a71655876f697a992f444dcb +Subproject commit 27eed5878ad5baafb363b65d4cde6c58d9a8b9f8 From a6e5ef220fd43236a661f6dee1dba0c1a7499d49 Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Mon, 26 Feb 2024 17:04:42 -0800 Subject: [PATCH 5/6] Lint --- packages/protocol/tests/test-vectors.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/tests/test-vectors.spec.ts b/packages/protocol/tests/test-vectors.spec.ts index 1de26464..b5853a35 100644 --- a/packages/protocol/tests/test-vectors.spec.ts +++ b/packages/protocol/tests/test-vectors.spec.ts @@ -9,7 +9,7 @@ import { Close, Offering, Order, OrderStatus, Quote, Rfq } from '../src/main.js' import { Parser } from '../src/parser.js' describe('TbdexTestVectorsProtocol', function () { - this.timeout(10000); + this.timeout(10000) it('parse_close', async () => { // Parse with parseMessage() const message = await Parser.parseMessage(ParseClose.input) From b31514078a11889cb680d323c96657d0c6117ec8 Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Tue, 27 Feb 2024 06:24:57 -0800 Subject: [PATCH 6/6] Remove remaining DevTools.createDid() --- packages/protocol/tests/generate-test-vectors.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/protocol/tests/generate-test-vectors.ts b/packages/protocol/tests/generate-test-vectors.ts index 60617713..a0f9e8c6 100644 --- a/packages/protocol/tests/generate-test-vectors.ts +++ b/packages/protocol/tests/generate-test-vectors.ts @@ -13,8 +13,8 @@ type TestVector = { error: boolean } -const pfiDid = await DevTools.createDid('dht') -const aliceDid = await DevTools.createDid('dht') +const pfiDid = await DidDht.create() +const aliceDid = await DidDht.create() const generateParseOfferingVector = async () => { const pfiDid = await await DidDht.create() @@ -52,7 +52,6 @@ const generateParseQuoteVector = async () => { const generateParseRfqVector = async () => { const aliceDid = await DidJwk.create() - const aliceDid = await DevTools.createDid() const vc = await VerifiableCredential.create({ type : 'PuupuuCredential', issuer : aliceDid.uri,