From 034a3f729a6ba8cf4ae2ec28f5334f93d2bcf781 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Thu, 16 Nov 2023 12:03:45 -0700 Subject: [PATCH 1/9] fix: did-peer-2 allows for multiple service blocks Signed-off-by: Colton Wolkins (Laptop) --- src/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d8cf736..3b92c1b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -84,7 +84,7 @@ export const decodeService = (did: string, service: string, index: number): IDID } 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 = ( From 17bc44a76bbf796295cc6aff069753cabe609c01 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Thu, 16 Nov 2023 12:31:43 -0700 Subject: [PATCH 2/9] fix: support for multiple service blocks Signed-off-by: Colton Wolkins (Laptop) --- src/lib/create.ts | 11 +++++++---- src/lib/resolve.ts | 7 +++---- src/lib/utils.ts | 16 +++++++++++----- 3 files changed, 21 insertions(+), 13 deletions(-) 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..7587075 100644 --- a/src/lib/resolve.ts +++ b/src/lib/resolve.ts @@ -36,7 +36,7 @@ export const resolveNumAlgo2 = async (did: string): Promise => { let encKeys: IDIDDocumentVerificationMethod[] = []; let services: IDIDDocumentServiceDescriptor[] = []; let keys = did.split('.') - let serviceIndex = 0; + let serviceMetadata = {index: 0}; delete keys[0]; keys.forEach(k => { switch (k.slice(0,1)) { @@ -57,10 +57,9 @@ export const resolveNumAlgo2 = async (did: string): Promise => { }) 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 3b92c1b..03c010a 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,13 +73,19 @@ 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; } @@ -91,7 +97,7 @@ export const createDIDDocument = ( did: string, authKeys: IDIDDocumentVerificationMethod[], encKeys: IDIDDocumentVerificationMethod[], - services: IDIDDocumentServiceDescriptor[] + services: IDIDDocumentServiceDescriptor[], ) => { let contexts = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/ed25519-2020/v1"] const auth = authKeys.map(k => k.id); @@ -118,4 +124,4 @@ export const createDIDDocument = ( doc['service'] = services } return {"@context": contexts, ...doc}; -} \ No newline at end of file +} From 445c1be01903255192270a63c2b4a75ef6c93ed2 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Thu, 16 Nov 2023 12:32:49 -0700 Subject: [PATCH 3/9] fix: key-ids should match spec Signed-off-by: Colton Wolkins (Laptop) --- src/lib/resolve.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/resolve.ts b/src/lib/resolve.ts index 7587075..6115ae8 100644 --- a/src/lib/resolve.ts +++ b/src/lib/resolve.ts @@ -37,12 +37,13 @@ export const resolveNumAlgo2 = async (did: string): Promise => { let services: IDIDDocumentServiceDescriptor[] = []; let keys = did.split('.') 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', publicKeyMultibase: k.slice(1) @@ -50,7 +51,7 @@ export const resolveNumAlgo2 = async (did: string): Promise => { break; case Numalgo2Prefixes.KeyAgreement: encKeys.push({ - id: `${did}#${k.slice(2)}`, + id: `#key-${keyIndex++}`, controller: did, type: 'X25519KeyAgreementKey2020', publicKeyMultibase: k.slice(1) From 1b8115196a3123704bb3f5d44faa7429656899db Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Thu, 16 Nov 2023 12:33:25 -0700 Subject: [PATCH 4/9] fix: switch to multikey for Numalgo 2+ Signed-off-by: Colton Wolkins (Laptop) --- src/lib/resolve.ts | 4 ++-- src/lib/utils.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib/resolve.ts b/src/lib/resolve.ts index 6115ae8..ade4a10 100644 --- a/src/lib/resolve.ts +++ b/src/lib/resolve.ts @@ -45,7 +45,7 @@ export const resolveNumAlgo2 = async (did: string): Promise => { authKeys.push({ id: `#key-${keyIndex++}`, controller: did, - type: 'Ed25519VerificationKey2020', + type: 'Multikey', publicKeyMultibase: k.slice(1) }) break; @@ -53,7 +53,7 @@ export const resolveNumAlgo2 = async (did: string): Promise => { encKeys.push({ id: `#key-${keyIndex++}`, controller: did, - type: 'X25519KeyAgreementKey2020', + type: 'Multikey', publicKeyMultibase: k.slice(1) }) break; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 03c010a..d12acc2 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -99,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"] + 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 => ({ @@ -118,7 +123,9 @@ export const createDIDDocument = ( } 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 From 50f6f6d172ff3ebacb45d63b031f7a8e4bc34396 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Thu, 16 Nov 2023 12:34:18 -0700 Subject: [PATCH 5/9] ci: fix unit tests Signed-off-by: Colton Wolkins (Laptop) --- .../fixtures/peerdid-python/numalgo2-did.json | 2 +- .../peerdid-python/numalgo2-diddoc.json | 43 ++++++++++++------- .../peerdid-python/numalgo2-inputs.json | 29 ++++++++++--- src/tests/lib/create.spec.ts | 10 ++--- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/tests/fixtures/peerdid-python/numalgo2-did.json b/src/tests/fixtures/peerdid-python/numalgo2-did.json index f1686a7..7b7b9bb 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.SeyJpZCI6ImEtdmVyeS11bmlxdWUtc2VydmljZSIsInQiOiJkbSIsInMiOiJodHRwczovL2V4YW1wbGUuY29tL2VuZHBvaW50MiIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkxIl0sImEiOlsiZGlkY29tbS92MiIsImRpZGNvbW0vYWlwMjtlbnY9cmZjNTg3Il19.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ" } diff --git a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json index 26506f3..67ab580 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json @@ -1,46 +1,59 @@ { "@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" ], - "id": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNv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GNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud", - "type": "X25519KeyAgreementKey2020", - "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", + "id": "#key-1", + "type": "Multikey", + "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6ImEtdmVyeS11bmlxdWUtc2VydmljZSIsInQiOiJkbSIsInMiOiJodHRwczovL2V4YW1wbGUuY29tL2VuZHBvaW50MiIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkxIl0sImEiOlsiZGlkY29tbS92MiIsImRpZGNvbW0vYWlwMjtlbnY9cmZjNTg3Il19.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.SeyJpZCI6ImEtdmVyeS11bmlxdWUtc2VydmljZSIsInQiOiJkbSIsInMiOiJodHRwczovL2V4YW1wbGUuY29tL2VuZHBvaW50MiIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkxIl0sImEiOlsiZGlkY29tbS92MiIsImRpZGNvbW0vYWlwMjtlbnY9cmZjNTg3Il19.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" + "#key-1" ], "capabilityInvocation": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" + "#key-2" ], "capabilityDelegation": [ - "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" + "#key-2" ], "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..603e345 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 +}) From 8dd2b3a5cd2b073a1a5cff3bacb5dba72a4e977e Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Thu, 16 Nov 2023 12:46:54 -0700 Subject: [PATCH 6/9] fix: Remove unused attributes Since we aren't getting the capability delegation/invocation from the DID, we shouldn't be including them in the DIDDoc since they weren't specified to begin with. Signed-off-by: Colton Wolkins (Laptop) --- src/lib/utils.ts | 6 ++++-- src/tests/fixtures/peerdid-python/numalgo2-diddoc.json | 6 ------ src/tests/lib/resolve.spec.ts | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d12acc2..13a0cd4 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -117,10 +117,12 @@ 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; if (didPeerNumalgo < 2) { diff --git a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json index 67ab580..527655b 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json @@ -27,12 +27,6 @@ "keyAgreement": [ "#key-1" ], - "capabilityInvocation": [ - "#key-2" - ], - "capabilityDelegation": [ - "#key-2" - ], "service": [ { "id": "#service", 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 +}) From 59773d8e3a3924d4409532b768c4d2d048dd4d44 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Mon, 4 Dec 2023 11:09:26 -0700 Subject: [PATCH 7/9] fix: Address PR feedback Signed-off-by: Colton Wolkins (Laptop) --- src/lib/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 13a0cd4..567a102 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -79,7 +79,7 @@ export const decodeService = (did: string, service: string, metadata: Record { let contexts = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/multikey/v1"] const prefix = "did:peer:"; From 907574e67902e47c067b401399fae7eaff1a6be4 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Mon, 4 Dec 2023 11:09:53 -0700 Subject: [PATCH 8/9] fix: Add @base to context when services are used Signed-off-by: Colton Wolkins (Laptop) --- src/lib/utils.ts | 1 + src/tests/fixtures/peerdid-python/numalgo2-did.json | 2 +- .../fixtures/peerdid-python/numalgo2-diddoc.json | 11 ++++++----- .../fixtures/peerdid-python/numalgo2-inputs.json | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 567a102..9d01a1d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -130,6 +130,7 @@ export const createDIDDocument = ( } } if (services.length > 0) { + contexts.push({'@base': did}) doc['service'] = services } return {"@context": contexts, ...doc}; diff --git a/src/tests/fixtures/peerdid-python/numalgo2-did.json b/src/tests/fixtures/peerdid-python/numalgo2-did.json index 7b7b9bb..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.SeyJpZCI6ImEtdmVyeS11bmlxdWUtc2VydmljZSIsInQiOiJkbSIsInMiOiJodHRwczovL2V4YW1wbGUuY29tL2VuZHBvaW50MiIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkxIl0sImEiOlsiZGlkY29tbS92MiIsImRpZGNvbW0vYWlwMjtlbnY9cmZjNTg3Il19.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ" + "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 527655b..cb1db03 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-diddoc.json @@ -1,20 +1,21 @@ { "@context": [ "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/multikey/v1" + "https://w3id.org/security/multikey/v1", + {"@base": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGx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9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", "publicKeyMultibase": "z6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud" }, { "id": "#key-2", "type": "Multikey", - "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6ImEtdmVyeS11bmlxdWUtc2VydmljZSIsInQiOiJkbSIsInMiOiJodHRwczovL2V4YW1wbGUuY29tL2VuZHBvaW50MiIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkxIl0sImEiOlsiZGlkY29tbS92MiIsImRpZGNvbW0vYWlwMjtlbnY9cmZjNTg3Il19.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", + "controller": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6IiNhLXZlcnktdW5pcXVlLXNlcnZpY2UiLCJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDIiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ", "publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V" } ], @@ -36,7 +37,7 @@ "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] }, { - "id": "a-very-unique-service", + "id": "#a-very-unique-service", "type": "DIDCommMessaging", "serviceEndpoint": "https://example.com/endpoint2", "routingKeys": ["did:example:somemediator#somekey1"], diff --git a/src/tests/fixtures/peerdid-python/numalgo2-inputs.json b/src/tests/fixtures/peerdid-python/numalgo2-inputs.json index 603e345..3e4897c 100644 --- a/src/tests/fixtures/peerdid-python/numalgo2-inputs.json +++ b/src/tests/fixtures/peerdid-python/numalgo2-inputs.json @@ -19,7 +19,7 @@ "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"] }, { - "id": "a-very-unique-service", + "id": "#a-very-unique-service", "type": "DIDCommMessaging", "serviceEndpoint": "https://example.com/endpoint2", "routingKeys": ["did:example:somemediator#somekey1"], From 127a67588e83affcc04354e09775585b9b1634c8 Mon Sep 17 00:00:00 2001 From: "Colton Wolkins (Laptop)" Date: Mon, 4 Dec 2023 11:13:10 -0700 Subject: [PATCH 9/9] fix: Add @base to base context Since @base only affects relative IRIs, we can just have it exist always, generally. See this resource for more information on @base and how it works: https://www.w3.org/TR/json-ld11/#syntax-tokens-and-keywords Signed-off-by: Colton Wolkins (Laptop) --- src/lib/utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 9d01a1d..052f4e3 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -99,7 +99,7 @@ export const createDIDDocument = ( encKeys: IDIDDocumentVerificationMethod[], services: IDIDDocumentServiceDescriptor[] ) => { - let contexts = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/multikey/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) { @@ -130,7 +130,6 @@ export const createDIDDocument = ( } } if (services.length > 0) { - contexts.push({'@base': did}) doc['service'] = services } return {"@context": contexts, ...doc};