Skip to content

Commit

Permalink
Add dht resolve test vector (#453)
Browse files Browse the repository at this point in the history
* add dht resolve test vector

* Update did-dht.spec.ts
  • Loading branch information
nitro-neal authored Mar 21, 2024
1 parent f96e9c1 commit 50cbc22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 2 additions & 3 deletions packages/dids/src/methods/did-jwk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ export class DidJwk extends DidMethod {

const didDocument: DidDocument = {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://w3id.org/security/suites/jws-2020/v1'
'https://www.w3.org/ns/did/v1'
],
id: parsedDid.uri
};
Expand All @@ -373,7 +372,7 @@ export class DidJwk extends DidMethod {
// Set the Verification Method property.
didDocument.verificationMethod = [{
id : keyUri,
type : 'JsonWebKey2020',
type : 'JsonWebKey',
controller : didDocument.id,
publicKeyJwk : publicKey
}];
Expand Down
13 changes: 12 additions & 1 deletion packages/dids/tests/methods/did-dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { PortableDid } from '../../src/types/portable-did.js';
import { DidErrorCode } from '../../src/did-error.js';
import { DidDht, DidDhtDocument, 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 = () => ({
status : 404,
Expand Down Expand Up @@ -1148,4 +1150,13 @@ describe('DidDhtDocument', () => {
}
});
});
});

describe('Web5TestVectorsDidDht', () => {
it('resolve', async () => {
for (const vector of DidDhtResolveTestVector.vectors as any[]) {
const didResolutionResult = await DidDht.resolve(vector.input.didUri);
expect(didResolutionResult.didResolutionMetadata.error).to.equal(vector.output.didResolutionMetadata.error);
}
}).timeout(30000); // Set timeout to 30 seconds for this test for did:dht resolution timeout test
});
});
2 changes: 1 addition & 1 deletion packages/dids/tests/methods/did-jwk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('DidJwk', () => {
const signingMethod = await DidJwk.getSigningMethod({ didDocument: did.document });

expect(signingMethod).to.have.property('publicKeyJwk');
expect(signingMethod).to.have.property('type', 'JsonWebKey2020');
expect(signingMethod).to.have.property('type', 'JsonWebKey');
expect(signingMethod).to.have.property('id', `${did.uri}#0`);
expect(signingMethod).to.have.property('controller', did.uri);
});
Expand Down
2 changes: 1 addition & 1 deletion web5-spec

0 comments on commit 50cbc22

Please sign in to comment.