diff --git a/src/lib/create.ts b/src/lib/create.ts index 30da64e..5d0d97d 100644 --- a/src/lib/create.ts +++ b/src/lib/create.ts @@ -7,8 +7,11 @@ export const create = async ( numalgo: number, authenticationKeys: IDIDDocumentVerificationMethod[], encryptionKeys?: IDIDDocumentVerificationMethod[], - service?: IDIDDocumentServiceDescriptor + service?: IDIDDocumentServiceDescriptor | IDIDDocumentServiceDescriptor[] ): Promise => { + if (service && !Array.isArray(service)) { + service = [service]; + } switch (numalgo) { case 0: return createNumAlgo0(authenticationKeys[0]); @@ -33,12 +36,12 @@ export const createNumAlgo1 = async (): Promise => { export const createNumAlgo2 = async ( authenticationKeys: IDIDDocumentVerificationMethod[], encryptionKeys?: IDIDDocumentVerificationMethod[], - service?: IDIDDocumentServiceDescriptor + service?: IDIDDocumentServiceDescriptor[] ): Promise => { authenticationKeys.forEach(k => validateAuthentication(k)); encryptionKeys?.forEach(k => validateEncryption(k)); const auth = authenticationKeys.map(k => `.${Numalgo2Prefixes.Authentication}${k.publicKeyMultibase}`) const enc = encryptionKeys ? encryptionKeys.map(k => `.${Numalgo2Prefixes.KeyAgreement}${k.publicKeyMultibase}`) : ''; - const serv = service ? encodeService(service) : ''; + const serv = service ? service?.map(s => encodeService(s)).join("") : ''; return `did:peer:2${auth}${enc}${serv}` -} \ No newline at end of file +} diff --git a/src/lib/resolve.ts b/src/lib/resolve.ts index 68f0e31..ade4a10 100644 --- a/src/lib/resolve.ts +++ b/src/lib/resolve.ts @@ -36,31 +36,31 @@ export const resolveNumAlgo2 = async (did: string): Promise => { let encKeys: IDIDDocumentVerificationMethod[] = []; let services: IDIDDocumentServiceDescriptor[] = []; let keys = did.split('.') - let serviceIndex = 0; + let serviceMetadata = {index: 0}; + let keyIndex = 1; delete keys[0]; keys.forEach(k => { switch (k.slice(0,1)) { case Numalgo2Prefixes.Authentication: authKeys.push({ - id: `${did}#${k.slice(2)}`, + id: `#key-${keyIndex++}`, controller: did, - type: 'Ed25519VerificationKey2020', + type: 'Multikey', publicKeyMultibase: k.slice(1) }) break; case Numalgo2Prefixes.KeyAgreement: encKeys.push({ - id: `${did}#${k.slice(2)}`, + id: `#key-${keyIndex++}`, controller: did, - type: 'X25519KeyAgreementKey2020', + type: 'Multikey', publicKeyMultibase: k.slice(1) }) break; case Numalgo2Prefixes.Service: - services.push(decodeService(did, k.slice(1), serviceIndex)) - serviceIndex++; + services.push(decodeService(did, k.slice(1), serviceMetadata)) break; } }) return createDIDDocument(did, authKeys, encKeys, services) -} \ No newline at end of file +} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d8cf736..052f4e3 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -44,7 +44,7 @@ export const encodeService = (service: IDIDDocumentServiceDescriptor): string => return `.${Numalgo2Prefixes.Service}${base64url.encode(encoded)}` } -export const decodeService = (did: string, service: string, index: number): IDIDDocumentServiceDescriptor => { +export const decodeService = (did: string, service: string, metadata: Record): IDIDDocumentServiceDescriptor => { const val = JSON.parse(utf8.decode(base64url.decode(service))) if (val.s) { val['serviceEndpoint'] = val.s; @@ -73,18 +73,24 @@ export const decodeService = (did: string, service: string, index: number): IDID if (val.t) { if (val.t === 'dm') { val.type = 'DIDCommMessaging' - val.id = `#didcommmessaging-${index}` } else { val.type = val.t; - val.id = `#service-${index}` } delete val['t'] } + if (!val.id) { + if (metadata.index === 0) { + val.id = `#service`; + } else { + val.id = `#service-${metadata.index}`; + } + metadata.index++; + } return val; } export const isPeerDID = (did: string) => { - return new RegExp('^did:peer:(([01](z)([1-9a-km-zA-HJ-NP-Z]*))|(2((\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]*))+(\.(S)[0-9a-zA-Z=]*)?)))$').test(did) + return new RegExp('^did:peer:(([01](z)([1-9a-km-zA-HJ-NP-Z]*))|(2((\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]*))+(\.(S)[0-9a-zA-Z=]*)*)))$').test(did) } export const createDIDDocument = ( @@ -93,7 +99,12 @@ export const createDIDDocument = ( encKeys: IDIDDocumentVerificationMethod[], services: IDIDDocumentServiceDescriptor[] ) => { - let contexts = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/ed25519-2020/v1"] + let contexts = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/multikey/v1", {"@base": did}] + const prefix = "did:peer:"; + const didPeerNumalgo = parseInt(did.slice(prefix.length, prefix.length+1)) + if (didPeerNumalgo < 2) { + contexts = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/ed25519-2020/v1"] + } const auth = authKeys.map(k => k.id); const enc = encKeys.map(k => k.id); const ver = [...authKeys, ...encKeys].map(k => ({ @@ -106,16 +117,20 @@ export const createDIDDocument = ( "id": did, assertionMethod: auth, authentication: auth, - capabilityDelegation: auth, - capabilityInvocation: auth, verificationMethod: ver, } + if (didPeerNumalgo < 2) { + doc["capabilityDelegation"] = auth + doc["capabilityInvocation"] = auth + } if (enc.length > 0) { doc['keyAgreement'] = enc; - contexts.push("https://w3id.org/security/suites/x25519-2020/v1"); + if (didPeerNumalgo < 2) { + contexts.push("https://w3id.org/security/suites/x25519-2020/v1"); + } } if (services.length > 0) { doc['service'] = services } return {"@context": contexts, ...doc}; -} \ No newline at end of file +} diff --git a/src/tests/fixtures/peerdid-python/numalgo2-did.json b/src/tests/fixtures/peerdid-python/numalgo2-did.json index f1686a7..860903a 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-did.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-did.json @@ -1,3 +1,3 @@ { - "did": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ" + "did": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6IiNhLXZlcnktdW5pcXVlLXNlcnZpY2UiLCJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDIiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ" } diff --git a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json index 26506f3..cb1db03 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json @@ -1,46 +1,54 @@ { "@context": [ "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/suites/x25519-2020/v1", - "https://w3id.org/security/suites/ed25519-2020/v1" + "https://w3id.org/security/multikey/v1", + {"@base": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6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ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", + "id": "#key-1", + "type": "Multikey", + "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6IiNhLXZlcnktdW5pcXVlLXNlcnZpY2UiLCJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDIiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", "publicKeyMultibase": "z6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud" }, { - "id": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V", - "type": "Ed25519VerificationKey2020", - "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", + "id": "#key-2", + "type": "Multikey", + "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6IiNhLXZlcnktdW5pcXVlLXNlcnZpY2UiLCJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDIiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", "publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" } ], "authentication": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" + "#key-2" ], "assertionMethod": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" + "#key-2" ], "keyAgreement": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud" - ], - "capabilityInvocation": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" - ], - "capabilityDelegation": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" + "#key-1" ], "service": [ { - "id": "#didcommmessaging-0", + "id": "#service", "type": "DIDCommMessaging", "serviceEndpoint": "https://example.com/endpoint1", "routingKeys": ["did:example:somemediator#somekey1"], "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] + }, + { + "id": "#a-very-unique-service", + "type": "DIDCommMessaging", + "serviceEndpoint": "https://example.com/endpoint2", + "routingKeys": ["did:example:somemediator#somekey1"], + "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] + }, + { + "id": "#service-1", + "type": "DIDCommMessaging", + "serviceEndpoint": "https://example.com/endpoint3", + "routingKeys": ["did:example:somemediator#somekey1"], + "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] } ] } diff --git a/src/tests/fixtures/peerdid-python/numalgo2-inputs.json b/src/tests/fixtures/peerdid-python/numalgo2-inputs.json index 01a34e9..3e4897c 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-inputs.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-inputs.json @@ -2,7 +2,7 @@ "signing_keys": [ { "type": "Ed25519VerificationKey2020", - "publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ" + "publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" } ], "encryption_keys": [ @@ -11,10 +11,25 @@ "publicKeyMultibase": "z6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud" } ], - "service": { - "type": "DIDCommMessaging", - "serviceEndpoint": "https://example.com/endpoint1", - "routingKeys": ["did:example:somemediator#somekey1"], - "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] - } + "service": [ + { + "type": "DIDCommMessaging", + "serviceEndpoint": "https://example.com/endpoint1", + "routingKeys": ["did:example:somemediator#somekey1"], + "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] + }, + { + "id": "#a-very-unique-service", + "type": "DIDCommMessaging", + "serviceEndpoint": "https://example.com/endpoint2", + "routingKeys": ["did:example:somemediator#somekey1"], + "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] + }, + { + "type": "DIDCommMessaging", + "serviceEndpoint": "https://example.com/endpoint3", + "routingKeys": ["did:example:somemediator#somekey1"], + "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] + } + ] } diff --git a/src/tests/lib/create.spec.ts b/src/tests/lib/create.spec.ts index a036743..f21c6c2 100644 --- a/src/tests/lib/create.spec.ts +++ b/src/tests/lib/create.spec.ts @@ -102,13 +102,13 @@ describe('createNumAlgo2', () => { } }) it('should create valid peer:did with NumAlgo2 with service', async () => { - const service = { + const service = [{ 'id': '#didcomm', 'type': 'DIDCommMessaging', 'serviceEndpoint' :'http://example.com', 'routingKeys': ['did:example:123#456'], 'accept': ['didcomm/v2'] - } + }] const did = await createNumAlgo2([ed25519Key], undefined, service); expect(did).toBeTruthy() const segments = did.split('.'); @@ -124,7 +124,7 @@ describe('createNumAlgo2', () => { }) it('should create valid peer:did with NumAlgo2 with service with serviceEndpoint object', async () => { - const service = { + const service = [{ 'id': '#didcomm', 'type': 'DIDCommMessaging', 'serviceEndpoint': { @@ -132,7 +132,7 @@ describe('createNumAlgo2', () => { 'routingKeys': ['did:example:123#456'], 'accept': ['didcomm/v2'] } - } + }] const did = await createNumAlgo2([ed25519Key], undefined, service); expect(did).toBeTruthy() const segments = did.split('.'); @@ -153,4 +153,4 @@ describe('createNumAlgo2', () => { expect(e.message).toBe('verificationMethod type must be X25519KeyAgreementKey2020') } }) -}) \ No newline at end of file +}) diff --git a/src/tests/lib/resolve.spec.ts b/src/tests/lib/resolve.spec.ts index 94b6639..5b4f506 100644 --- a/src/tests/lib/resolve.spec.ts +++ b/src/tests/lib/resolve.spec.ts @@ -20,8 +20,8 @@ describe('resolve', () => { expectArrayEquivalence(resolvedDoc.keyAgreement as IDIDDocumentVerificationMethod[], inputDoc.keyAgreement); expectArrayEquivalence(resolvedDoc.authentication as IDIDDocumentVerificationMethod[], inputDoc.authentication); expectArrayEquivalence(resolvedDoc.assertionMethod as IDIDDocumentVerificationMethod[], inputDoc.assertionMethod); - expectArrayEquivalence(resolvedDoc.capabilityInvocation as IDIDDocumentVerificationMethod[], inputDoc.capabilityInvocation); - expectArrayEquivalence(resolvedDoc.capabilityDelegation as IDIDDocumentVerificationMethod[], inputDoc.capabilityDelegation); + expect(resolvedDoc.capabilityInvocation).toEqual(undefined); + expect(resolvedDoc.capabilityDelegation).toEqual(undefined); expectArrayEquivalence(resolvedDoc.service as IDIDDocumentServiceDescriptor[], inputDoc.service); }) it('should resolve peer:did w/ numalgo0', async () => { @@ -84,4 +84,4 @@ describe('resolveNumAlgo2', () => { expect(doc.keyAgreement!.length).toBe(1) expect(doc.service!.length).toBe(1) }) -}) \ No newline at end of file +})