|
| 1 | +import type { PortableDid } from '../../src/types/portable-did.js'; |
| 2 | + |
1 | 3 | import sinon from 'sinon';
|
| 4 | +import resolveTestVectors from '../../../../web5-spec/test-vectors/did_dht/resolve.json' assert { type: 'json' }; |
| 5 | +import officialTestVector1DidDocument from '../fixtures/test-vectors/did-dht/vector-1-did-document.json' assert { type: 'json' }; |
| 6 | +import officialTestVector1DnsRecords from '../fixtures/test-vectors/did-dht/vector-1-dns-records.json' assert { type: 'json' }; |
| 7 | + |
2 | 8 | import { expect } from 'chai';
|
3 | 9 | import { Convert } from '@web5/common';
|
4 |
| - |
5 |
| -import type { PortableDid } from '../../src/types/portable-did.js'; |
6 |
| - |
| 10 | +import { DidDocument } from '../../src/index.js'; |
7 | 11 | import { DidErrorCode } from '../../src/did-error.js';
|
8 | 12 | import { DidDht, DidDhtDocument, DidDhtRegisteredDidType } from '../../src/methods/did-dht.js';
|
9 | 13 |
|
10 |
| -import DidDhtResolveTestVector from '../../../../web5-spec/test-vectors/did_dht/resolve.json' assert { type: 'json' }; |
11 |
| - |
12 | 14 | // Helper function to create a mocked fetch response that fails and returns a 404 Not Found.
|
13 | 15 | const fetchNotFoundResponse = () => ({
|
14 | 16 | status : 404,
|
@@ -431,10 +433,15 @@ describe('DidDht', () => {
|
431 | 433 |
|
432 | 434 | it('throws an error if the resulting DID document would exceed the 1000 byte maximum', async () => {
|
433 | 435 | try {
|
434 |
| - // Attempt to create a DID with 6 verification methods (Identity Key plus 5 additional). |
| 436 | + // Attempt to create a DID with DID Document that exceeds the maximum size. |
435 | 437 | await DidDht.create({
|
436 | 438 | options: {
|
437 | 439 | verificationMethods: [
|
| 440 | + { algorithm: 'Ed25519' }, |
| 441 | + { algorithm: 'Ed25519' }, |
| 442 | + { algorithm: 'Ed25519' }, |
| 443 | + { algorithm: 'Ed25519' }, |
| 444 | + { algorithm: 'Ed25519' }, |
438 | 445 | { algorithm: 'Ed25519' },
|
439 | 446 | { algorithm: 'Ed25519' },
|
440 | 447 | { algorithm: 'Ed25519' },
|
@@ -1153,10 +1160,35 @@ describe('DidDhtDocument', () => {
|
1153 | 1160 |
|
1154 | 1161 | describe('Web5TestVectorsDidDht', () => {
|
1155 | 1162 | it('resolve', async () => {
|
1156 |
| - for (const vector of DidDhtResolveTestVector.vectors as any[]) { |
| 1163 | + for (const vector of resolveTestVectors.vectors as any[]) { |
1157 | 1164 | const didResolutionResult = await DidDht.resolve(vector.input.didUri);
|
1158 | 1165 | expect(didResolutionResult.didResolutionMetadata.error).to.equal(vector.output.didResolutionMetadata.error);
|
1159 | 1166 | }
|
1160 | 1167 | }).timeout(30000); // Set timeout to 30 seconds for this test for did:dht resolution timeout test
|
1161 | 1168 | });
|
1162 | 1169 | });
|
| 1170 | + |
| 1171 | +// vectors come from https://did-dht.com/#test-vectors |
| 1172 | +describe('Official DID:DHT Vector tests', () => { |
| 1173 | + it('vector 1', async () => { |
| 1174 | + const dnsPacket = await DidDhtDocument.toDnsPacket({ |
| 1175 | + didDocument : officialTestVector1DidDocument as DidDocument, |
| 1176 | + didMetadata : { published: false } |
| 1177 | + }); |
| 1178 | + |
| 1179 | + expect(dnsPacket.answers).to.have.length(officialTestVector1DnsRecords.length); |
| 1180 | + |
| 1181 | + // NOTE: the DNS library we use uses name `data` instead of `rdata` used in DID:DHT spec, |
| 1182 | + // but prefer to keep the naming in test vector files identical to that of the DID:DHT spec, |
| 1183 | + // hence this additional normalization step |
| 1184 | + const normalizedConstructedRecords = dnsPacket.answers!.map(record => { |
| 1185 | + const { data: rdata, ...otherProperties } = record; |
| 1186 | + return { |
| 1187 | + ...otherProperties, |
| 1188 | + rdata |
| 1189 | + }; |
| 1190 | + }); |
| 1191 | + |
| 1192 | + expect(normalizedConstructedRecords).to.deep.include.members(officialTestVector1DnsRecords); |
| 1193 | + }); |
| 1194 | +}); |
0 commit comments