Skip to content

Commit

Permalink
Merge pull request #3 from frostyfrog/fix/conform-to-spec
Browse files Browse the repository at this point in the history
Conform to did:peer:2 spec
  • Loading branch information
brianorwhatever authored Dec 8, 2023
2 parents 0c1f126 + 127a675 commit dc98ef8
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 56 deletions.
11 changes: 7 additions & 4 deletions src/lib/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ export const create = async (
numalgo: number,
authenticationKeys: IDIDDocumentVerificationMethod[],
encryptionKeys?: IDIDDocumentVerificationMethod[],
service?: IDIDDocumentServiceDescriptor
service?: IDIDDocumentServiceDescriptor | IDIDDocumentServiceDescriptor[]
): Promise<string> => {
if (service && !Array.isArray(service)) {
service = [service];
}
switch (numalgo) {
case 0:
return createNumAlgo0(authenticationKeys[0]);
Expand All @@ -33,12 +36,12 @@ export const createNumAlgo1 = async (): Promise<string> => {
export const createNumAlgo2 = async (
authenticationKeys: IDIDDocumentVerificationMethod[],
encryptionKeys?: IDIDDocumentVerificationMethod[],
service?: IDIDDocumentServiceDescriptor
service?: IDIDDocumentServiceDescriptor[]
): Promise<string> => {
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}`
}
}
16 changes: 8 additions & 8 deletions src/lib/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ export const resolveNumAlgo2 = async (did: string): Promise<IDIDDocument> => {
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)
}
}
33 changes: 24 additions & 9 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>): IDIDDocumentServiceDescriptor => {
const val = JSON.parse(utf8.decode(base64url.decode(service)))
if (val.s) {
val['serviceEndpoint'] = val.s;
Expand Down Expand Up @@ -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 = (
Expand All @@ -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 => ({
Expand All @@ -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};
}
}
2 changes: 1 addition & 1 deletion src/tests/fixtures/peerdid-python/numalgo2-did.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"did": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ"
"did": "did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJpZCI6IiNhLXZlcnktdW5pcXVlLXNlcnZpY2UiLCJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDIiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ"
}
46 changes: 27 additions & 19 deletions src/tests/fixtures/peerdid-python/numalgo2-diddoc.json
Original file line number Diff line number Diff line change
@@ -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.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iaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#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"]
}
]
}
29 changes: 22 additions & 7 deletions src/tests/fixtures/peerdid-python/numalgo2-inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"signing_keys": [
{
"type": "Ed25519VerificationKey2020",
"publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ"
"publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V"
}
],
"encryption_keys": [
Expand All @@ -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"]
}
]
}
10 changes: 5 additions & 5 deletions src/tests/lib/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('.');
Expand All @@ -124,15 +124,15 @@ 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': {
'uri': '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('.');
Expand All @@ -153,4 +153,4 @@ describe('createNumAlgo2', () => {
expect(e.message).toBe('verificationMethod type must be X25519KeyAgreementKey2020')
}
})
})
})
6 changes: 3 additions & 3 deletions src/tests/lib/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -84,4 +84,4 @@ describe('resolveNumAlgo2', () => {
expect(doc.keyAgreement!.length).toBe(1)
expect(doc.service!.length).toBe(1)
})
})
})

0 comments on commit dc98ef8

Please sign in to comment.