From 112a01eb769e54c9a36d8a1fc2ef51a07bdd5b6b Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:40:15 -0600 Subject: [PATCH] dht resolve test vector impl (#411) --- 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 bdabc55a7..deb64f42c 160000 --- a/web5-spec +++ b/web5-spec @@ -1 +1 @@ -Subproject commit bdabc55a7cad4b469855706f0ab4167d3755756d +Subproject commit deb64f42cc892985c45d33ff40f19ee1947079d9