From 4757e0d19bd896c80b72c9f1ff95f19a20435cae Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 13 Feb 2024 13:40:38 -0600 Subject: [PATCH] dht resolve test vector impl --- packages/dids/src/methods/did-dht.ts | 4 ++++ packages/dids/tests/methods/did-dht.spec.ts | 12 ++++++++++++ web5-spec | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index b6091bea6..7a3d574a0 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -889,6 +889,10 @@ export class DidDhtDocument { // Read the Fetch Response stream into a byte array. const messageBytes = await response.arrayBuffer(); + if(!messageBytes) { + throw new DidError(DidErrorCode.NotFound, `Pkarr record not found for: ${identifier}`); + } + if (messageBytes.byteLength < 72) { throw new DidError(DidErrorCode.InvalidDidDocumentLength, `Pkarr response must be at least 72 bytes but got: ${messageBytes.byteLength}`); } diff --git a/packages/dids/tests/methods/did-dht.spec.ts b/packages/dids/tests/methods/did-dht.spec.ts index d8e7ec967..2e17182e8 100644 --- a/packages/dids/tests/methods/did-dht.spec.ts +++ b/packages/dids/tests/methods/did-dht.spec.ts @@ -6,6 +6,8 @@ import type { PortableDid } from '../../src/types/portable-did.js'; import { DidErrorCode } from '../../src/did-error.js'; import { DidDht, DidDhtRegisteredDidType } from '../../src/methods/did-dht.js'; +import DidDhtResolveTestVector from '../../../../web5-spec/test-vectors/did_dht/resolve.json' assert { type: 'json' }; + // Helper function to create a mocked fetch response that fails and returns a 404 Not Found. const fetchNotFoundResponse = () => ({ @@ -802,4 +804,14 @@ describe('DidDht', () => { expect(didResolutionResult.didResolutionMetadata).to.have.property('error', 'invalidDidDocumentLength'); }); }); + + + describe('Web5TestVectorsDidDht', () => { + it('resolve', async () => { + for (const vector of DidDhtResolveTestVector.vectors) { + const didResolutionResult = await DidDht.resolve(vector.input.didUri); + expect(didResolutionResult.didResolutionMetadata.error).to.equal(vector.output.didResolutionMetadata.error); + } + }); + }); }); \ No newline at end of file diff --git a/web5-spec b/web5-spec index f46b53f34..deb64f42c 160000 --- a/web5-spec +++ b/web5-spec @@ -1 +1 @@ -Subproject commit f46b53f34f6ecd6ff2e16e93d67890fa63528424 +Subproject commit deb64f42cc892985c45d33ff40f19ee1947079d9