Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Did Dht Resolve Web5 Test Vector Impl #411

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/dids/src/methods/did-dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/dids/tests/methods/did-dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => ({
Expand Down Expand Up @@ -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);
}
});
});
});
2 changes: 1 addition & 1 deletion web5-spec
Loading