From 3b5aeb4e1134054380a7bf96f0ef4d021502f032 Mon Sep 17 00:00:00 2001 From: Neal Date: Thu, 16 May 2024 11:32:02 -0700 Subject: [PATCH 1/7] add ns record auth gayway parsing --- packages/dids/src/methods/did-dht.ts | 56 +++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 53fc09623..ae133a1ff 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -805,10 +805,30 @@ export class DidDhtDocument { const publicKeyBytes = DidDhtUtils.identifierToIdentityKeyBytes({ didUri }); // Retrieve the signed BEP44 message from a DID DHT Gateway or Pkarr relay. - const bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri, publicKeyBytes }); + let bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri, publicKeyBytes }); // Verify the signature of the BEP44 message and parse the value to a DNS packet. - const dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); + let dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); + + // Look at the NS records in the DNS packet to find the resolution gateway URIs. + let resolutinGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); + + const accumulatedErrors = []; + for(const nsRecordGatewayUri of resolutinGatewayUris) { + try { + bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri: nsRecordGatewayUri, publicKeyBytes }); + dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); + } catch (error: any) { + accumulatedErrors.push(`Failed retrieval from ${nsRecordGatewayUri}: ${error}`); + + if(nsRecordGatewayUri == resolutinGatewayUris[resolutinGatewayUris.length - 1]) { + throw new Error(`DID document not found for: ${didUri}. Errors: ${accumulatedErrors.join('; ')}`); + } + + // If the retrieval failed, try the next resolution gateway. + continue; + } + } // Convert the DNS packet to a DID document and metadata. const resolutionResult = await DidDhtDocument.fromDnsPacket({ didUri, dnsPacket }); @@ -965,6 +985,38 @@ export class DidDhtDocument { return response.ok; } + + /** + * Extracts authoritative gateway URIs from a DNS packet based on the DID DHT specifications. + * This method filters NS records related to the provided DID URI and extracts gateway URIs + * that are used to resolve the complete DID document. + * + * @see {@link https://did-dht.com/#designating-authoritative-gateways | DID DHT Specification, ยง Authoritative Gateways} + * + * @param {object} params - The parameters to use when extracting gateway URIs from the DNS packet. + * @param {string} params.didUri - The DID URI corresponding to the DNS packet. + * @param {Packet} params.dnsPacket - The DNS packet containing potential NS records for resolution gateways. + * @returns {Promise} Resolves to an array of gateway URIs if found, otherwise an empty array. + */ + public static async getAuthoritativeGatewayUris({ didUri, dnsPacket }: { + didUri: string; + dnsPacket: Packet; + }): Promise { + const authoritativeGatewayUris: string[] = []; + + for (const answer of dnsPacket?.answers ?? []) { + if (answer.type !== 'NS') continue; + + if(answer.name.endsWith(`.${DidDhtDocument.getUniqueDidSuffix(didUri)}.`)) { + const gatewayUri = answer.data.slice(0, -1); // Remove trailing dot + authoritativeGatewayUris.push(gatewayUri); + break; + } + } + + return authoritativeGatewayUris; + } + /** * Converts a DNS packet to a DID document according to the DID DHT specification. * From 05a74ed6d5f60a375f04a5e287c669ddaa5f887e Mon Sep 17 00:00:00 2001 From: Neal Date: Thu, 16 May 2024 13:25:17 -0700 Subject: [PATCH 2/7] add break --- packages/dids/src/methods/did-dht.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index ae133a1ff..1bb8fcb03 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -828,6 +828,9 @@ export class DidDhtDocument { // If the retrieval failed, try the next resolution gateway. continue; } + + // if the retrieval was successful, break the loop. + break; } // Convert the DNS packet to a DID document and metadata. From 5d193a440d38e02981f861699e9190202a2d3719 Mon Sep 17 00:00:00 2001 From: Neal Date: Fri, 17 May 2024 11:29:33 -0700 Subject: [PATCH 3/7] updates --- packages/dids/src/methods/did-dht.ts | 33 +++++---- packages/dids/tests/methods/did-dht.spec.ts | 76 +++++++++++++++++++++ 2 files changed, 94 insertions(+), 15 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 1bb8fcb03..37622d596 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -813,24 +813,27 @@ export class DidDhtDocument { // Look at the NS records in the DNS packet to find the resolution gateway URIs. let resolutinGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); - const accumulatedErrors = []; - for(const nsRecordGatewayUri of resolutinGatewayUris) { - try { - bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri: nsRecordGatewayUri, publicKeyBytes }); - dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); - } catch (error: any) { - accumulatedErrors.push(`Failed retrieval from ${nsRecordGatewayUri}: ${error}`); - - if(nsRecordGatewayUri == resolutinGatewayUris[resolutinGatewayUris.length - 1]) { - throw new Error(`DID document not found for: ${didUri}. Errors: ${accumulatedErrors.join('; ')}`); + // Only do a second retrieval if the authoritative resolution gateway URIs are different from the given gateway URI. + if(!resolutinGatewayUris.includes(gatewayUri)) { + const accumulatedErrors = []; + for(const nsRecordGatewayUri of resolutinGatewayUris) { + try { + bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri: nsRecordGatewayUri, publicKeyBytes }); + dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); + } catch (error: any) { + accumulatedErrors.push(`Failed retrieval from ${nsRecordGatewayUri}: ${error}`); + + if(nsRecordGatewayUri == resolutinGatewayUris[resolutinGatewayUris.length - 1]) { + throw new Error(`DID document not found for: ${didUri}. Errors: ${accumulatedErrors.join('; ')}`); + } + + // If the retrieval failed, try the next resolution gateway. + continue; } - // If the retrieval failed, try the next resolution gateway. - continue; + // If the retrieval was successful, break the loop. + break; } - - // if the retrieval was successful, break the loop. - break; } // Convert the DNS packet to a DID document and metadata. diff --git a/packages/dids/tests/methods/did-dht.spec.ts b/packages/dids/tests/methods/did-dht.spec.ts index 5bc39dcd5..99fb733b6 100644 --- a/packages/dids/tests/methods/did-dht.spec.ts +++ b/packages/dids/tests/methods/did-dht.spec.ts @@ -1157,6 +1157,82 @@ describe('DidDhtDocument', () => { } } }); + + it('handles custom authoritative gateways', async () => { + const dnsPacket = await DidDhtDocument.toDnsPacket({ + didDocument: { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + verificationMethod : [ + { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + type : 'JsonWebKey', + controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : '2zHGF5m_DhcPbBZB6ooIxIOR-Vw-yJVYSPo2NgCMkgg', + kid : 'KDT9PKj4_z7gPk2s279Y-OGlMtt_L93oJzIaiVrrySU', + alg : 'EdDSA', + }, + }, + { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', + type : 'JsonWebKey', + controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : 'FrrBhqvAWxE4lstj-IWgN8_5-O4L1KuZjdNjn5bX_dw', + kid : 'dRnxo2XQ7QT1is5WmpEefwEz3z4_4JdpGea6KWUn3ww', + alg : 'EdDSA', + }, + }, + { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#enc', + type : 'JsonWebKey', + controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + publicKeyJwk : { + kty : 'EC', + crv : 'secp256k1', + x : 'e1_pCWZwI9cxdrotVKIT8t75itk22XkpalDPx7pVpYQ', + y : '5cAlBmnzzuwRNuFtLhyFNdy9v1rVEqEgrFEiiwKMx5I', + kid : 'jGYs9XgQMDH_PCDFWocTN0F06mTUOA1J1McVvluq4lM', + alg : 'ES256K', + }, + }, + ], + authentication: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', + ], + assertionMethod: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', + ], + capabilityDelegation: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + ], + capabilityInvocation: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + ], + keyAgreement: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#enc', + ], + }, + didMetadata: { + published: true, + }, + authoritativeGatewayUris: ['gateway1.example-did-dht-gateway.com', 'gateway2.example-did-dht-gateway.com'] + }); + + for (const record of dnsPacket.answers ?? []) { + if (record.type !== 'NS') + continue; + + expect(record.name).to.equal('_did.5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery.'); + expect(record.data).to.match(/(gateway1.example-did-dht-gateway.com.|gateway2.example-did-dht-gateway.com.)/); + } + }); }); describe('Web5TestVectorsDidDht', () => { From e6b96e16ca70b43ea19404f26bbc623aab27e2cf Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Fri, 17 May 2024 11:30:31 -0700 Subject: [PATCH 4/7] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Gabe <7622243+decentralgabe@users.noreply.github.com> --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 37622d596..01984eb81 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -811,7 +811,7 @@ export class DidDhtDocument { let dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); // Look at the NS records in the DNS packet to find the resolution gateway URIs. - let resolutinGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); + let resolutionGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); // Only do a second retrieval if the authoritative resolution gateway URIs are different from the given gateway URI. if(!resolutinGatewayUris.includes(gatewayUri)) { From d38379a30e5b679e80d54788cd9559cf1135252a Mon Sep 17 00:00:00 2001 From: Neal Date: Fri, 17 May 2024 11:31:24 -0700 Subject: [PATCH 5/7] update --- packages/dids/src/methods/did-dht.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 01984eb81..c8bca1fab 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -814,16 +814,16 @@ export class DidDhtDocument { let resolutionGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); // Only do a second retrieval if the authoritative resolution gateway URIs are different from the given gateway URI. - if(!resolutinGatewayUris.includes(gatewayUri)) { + if(!resolutionGatewayUris.includes(gatewayUri)) { const accumulatedErrors = []; - for(const nsRecordGatewayUri of resolutinGatewayUris) { + for(const nsRecordGatewayUri of resolutionGatewayUris) { try { bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri: nsRecordGatewayUri, publicKeyBytes }); dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); } catch (error: any) { accumulatedErrors.push(`Failed retrieval from ${nsRecordGatewayUri}: ${error}`); - if(nsRecordGatewayUri == resolutinGatewayUris[resolutinGatewayUris.length - 1]) { + if(nsRecordGatewayUri == resolutionGatewayUris[resolutionGatewayUris.length - 1]) { throw new Error(`DID document not found for: ${didUri}. Errors: ${accumulatedErrors.join('; ')}`); } From 6a153e45a2adae8c6b3813bb35c3f2f9c840b4ba Mon Sep 17 00:00:00 2001 From: Henry Tsai Date: Tue, 21 May 2024 10:43:55 -0700 Subject: [PATCH 6/7] Minor Refactoring to NS record PR (#608) * minor refactoring * Fixed an ambiguous if condition --- packages/dids/src/did-error.ts | 3 +++ packages/dids/src/methods/did-dht.ts | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/dids/src/did-error.ts b/packages/dids/src/did-error.ts index efc0b93d5..9c8b672b8 100644 --- a/packages/dids/src/did-error.ts +++ b/packages/dids/src/did-error.ts @@ -61,6 +61,9 @@ export enum DidErrorCode { /** The DID resolver was unable to find the DID document resulting from the resolution request. */ NotFound = 'notFound', + /** The DID resolver was unable to find the DID document in any authoritative gateway. */ + NotFoundInAuthoritativeGateWay = 'notFoundInAuthoritativeGateWay', + /** * The representation requested via the `accept` input metadata property is not supported by the * DID method and/or DID resolver implementation. diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index c8bca1fab..b777f8e75 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -808,13 +808,14 @@ export class DidDhtDocument { let bep44Message = await DidDhtDocument.pkarrGet({ gatewayUri, publicKeyBytes }); // Verify the signature of the BEP44 message and parse the value to a DNS packet. - let dnsPacket = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); + let dnsPacket: Packet | undefined = await DidDhtUtils.parseBep44GetMessage({ bep44Message }); // Look at the NS records in the DNS packet to find the resolution gateway URIs. - let resolutionGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); + const resolutionGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri, dnsPacket }); - // Only do a second retrieval if the authoritative resolution gateway URIs are different from the given gateway URI. - if(!resolutionGatewayUris.includes(gatewayUri)) { + // Only do a second retrieval if authoritative resolution gateway URIs are specified and are different from the given gateway URI. + if(resolutionGatewayUris.length > 0 && !resolutionGatewayUris.includes(gatewayUri)) { + dnsPacket = undefined; // reset to `undefined` to use as a condition check for throwing an error const accumulatedErrors = []; for(const nsRecordGatewayUri of resolutionGatewayUris) { try { @@ -823,10 +824,6 @@ export class DidDhtDocument { } catch (error: any) { accumulatedErrors.push(`Failed retrieval from ${nsRecordGatewayUri}: ${error}`); - if(nsRecordGatewayUri == resolutionGatewayUris[resolutionGatewayUris.length - 1]) { - throw new Error(`DID document not found for: ${didUri}. Errors: ${accumulatedErrors.join('; ')}`); - } - // If the retrieval failed, try the next resolution gateway. continue; } @@ -834,6 +831,13 @@ export class DidDhtDocument { // If the retrieval was successful, break the loop. break; } + + if(dnsPacket === undefined) { + throw new DidError( + DidErrorCode.NotFoundInAuthoritativeGateWay, + `DID document not found for: ${didUri} after looping through all authoritative gateways. Errors: ${accumulatedErrors.join('; ')}` + ); + } } // Convert the DNS packet to a DID document and metadata. @@ -1002,7 +1006,7 @@ export class DidDhtDocument { * @param {object} params - The parameters to use when extracting gateway URIs from the DNS packet. * @param {string} params.didUri - The DID URI corresponding to the DNS packet. * @param {Packet} params.dnsPacket - The DNS packet containing potential NS records for resolution gateways. - * @returns {Promise} Resolves to an array of gateway URIs if found, otherwise an empty array. + * @returns {Promise} Resolves to an array of gateway URIs without trailing '.' if found, otherwise an empty array. */ public static async getAuthoritativeGatewayUris({ didUri, dnsPacket }: { didUri: string; @@ -1013,7 +1017,7 @@ export class DidDhtDocument { for (const answer of dnsPacket?.answers ?? []) { if (answer.type !== 'NS') continue; - if(answer.name.endsWith(`.${DidDhtDocument.getUniqueDidSuffix(didUri)}.`)) { + if (answer.name.endsWith(`.${DidDhtDocument.getUniqueDidSuffix(didUri)}.`)) { const gatewayUri = answer.data.slice(0, -1); // Remove trailing dot authoritativeGatewayUris.push(gatewayUri); break; From 6313e60122bc9b180d99fd0d781d6b95c3fc000a Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 21 May 2024 12:06:44 -0700 Subject: [PATCH 7/7] updates --- packages/dids/src/methods/did-dht.ts | 1 - packages/dids/tests/methods/did-dht.spec.ts | 126 +++++++++++--------- 2 files changed, 68 insertions(+), 59 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index b777f8e75..d14761554 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1020,7 +1020,6 @@ export class DidDhtDocument { if (answer.name.endsWith(`.${DidDhtDocument.getUniqueDidSuffix(didUri)}.`)) { const gatewayUri = answer.data.slice(0, -1); // Remove trailing dot authoritativeGatewayUris.push(gatewayUri); - break; } } diff --git a/packages/dids/tests/methods/did-dht.spec.ts b/packages/dids/tests/methods/did-dht.spec.ts index 99fb733b6..a03ff684b 100644 --- a/packages/dids/tests/methods/did-dht.spec.ts +++ b/packages/dids/tests/methods/did-dht.spec.ts @@ -1159,70 +1159,75 @@ describe('DidDhtDocument', () => { }); it('handles custom authoritative gateways', async () => { - const dnsPacket = await DidDhtDocument.toDnsPacket({ - didDocument: { - id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', - verificationMethod : [ - { - id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', - type : 'JsonWebKey', - controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', - publicKeyJwk : { - crv : 'Ed25519', - kty : 'OKP', - x : '2zHGF5m_DhcPbBZB6ooIxIOR-Vw-yJVYSPo2NgCMkgg', - kid : 'KDT9PKj4_z7gPk2s279Y-OGlMtt_L93oJzIaiVrrySU', - alg : 'EdDSA', - }, + + const didDocument: DidDocument = { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + verificationMethod : [ + { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + type : 'JsonWebKey', + controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : '2zHGF5m_DhcPbBZB6ooIxIOR-Vw-yJVYSPo2NgCMkgg', + kid : 'KDT9PKj4_z7gPk2s279Y-OGlMtt_L93oJzIaiVrrySU', + alg : 'EdDSA', }, - { - id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', - type : 'JsonWebKey', - controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', - publicKeyJwk : { - crv : 'Ed25519', - kty : 'OKP', - x : 'FrrBhqvAWxE4lstj-IWgN8_5-O4L1KuZjdNjn5bX_dw', - kid : 'dRnxo2XQ7QT1is5WmpEefwEz3z4_4JdpGea6KWUn3ww', - alg : 'EdDSA', - }, + }, + { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', + type : 'JsonWebKey', + controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : 'FrrBhqvAWxE4lstj-IWgN8_5-O4L1KuZjdNjn5bX_dw', + kid : 'dRnxo2XQ7QT1is5WmpEefwEz3z4_4JdpGea6KWUn3ww', + alg : 'EdDSA', }, - { - id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#enc', - type : 'JsonWebKey', - controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', - publicKeyJwk : { - kty : 'EC', - crv : 'secp256k1', - x : 'e1_pCWZwI9cxdrotVKIT8t75itk22XkpalDPx7pVpYQ', - y : '5cAlBmnzzuwRNuFtLhyFNdy9v1rVEqEgrFEiiwKMx5I', - kid : 'jGYs9XgQMDH_PCDFWocTN0F06mTUOA1J1McVvluq4lM', - alg : 'ES256K', - }, + }, + { + id : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#enc', + type : 'JsonWebKey', + controller : 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery', + publicKeyJwk : { + kty : 'EC', + crv : 'secp256k1', + x : 'e1_pCWZwI9cxdrotVKIT8t75itk22XkpalDPx7pVpYQ', + y : '5cAlBmnzzuwRNuFtLhyFNdy9v1rVEqEgrFEiiwKMx5I', + kid : 'jGYs9XgQMDH_PCDFWocTN0F06mTUOA1J1McVvluq4lM', + alg : 'ES256K', }, - ], - authentication: [ - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', - ], - assertionMethod: [ - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', - ], - capabilityDelegation: [ - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', - ], - capabilityInvocation: [ - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', - ], - keyAgreement: [ - 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#enc', - ], - }, + }, + ], + authentication: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', + ], + assertionMethod: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#sig', + ], + capabilityDelegation: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + ], + capabilityInvocation: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#0', + ], + keyAgreement: [ + 'did:dht:5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery#enc', + ], + }; + + const authoritativeGatewayUris = ['gateway1.example-did-dht-gateway.com', 'gateway2.example-did-dht-gateway.com']; + + const dnsPacket = await DidDhtDocument.toDnsPacket({ + didDocument, didMetadata: { published: true, }, - authoritativeGatewayUris: ['gateway1.example-did-dht-gateway.com', 'gateway2.example-did-dht-gateway.com'] + authoritativeGatewayUris }); for (const record of dnsPacket.answers ?? []) { @@ -1232,6 +1237,11 @@ describe('DidDhtDocument', () => { expect(record.name).to.equal('_did.5cahcfh3zh8bqd5cn3y6inoea1b3d6kh85rjksne9e5dcyrc1ery.'); expect(record.data).to.match(/(gateway1.example-did-dht-gateway.com.|gateway2.example-did-dht-gateway.com.)/); } + + const resolutionGatewayUris = await DidDhtDocument.getAuthoritativeGatewayUris({ didUri: didDocument.id, dnsPacket }); + + expect(resolutionGatewayUris).to.have.length(2); + expect(resolutionGatewayUris).to.have.members(authoritativeGatewayUris); }); });