Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform to did:peer:2 spec #3

Merged
merged 9 commits into from
Dec 8, 2023
Merged
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++}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer absolute URIs over relative. I know the spec uses relative and these get quite ugly but I don't think it will matter at an interoperability level unless I'm missing something

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you're correct; whether the URLs are "expanded" or left as relative should not significantly impact interop as either should be considered acceptable. Using absolute URIs here I think is fair. @frostyfrog

Copy link
Contributor

@brianorwhatever brianorwhatever Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I'd be ok with using relative and putting an "@base": "did:peer:2z123najb..." in the @context which will effectively do the same thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using @base as it allows the document to be a bit cleaner when a Human is reading it. I have added it to the context property according to the pattern demonstrated in example 150 in the JSON-LD docs.

controller: did,
type: 'X25519KeyAgreementKey2020',
type: 'Multikey',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool to use new Data Integrity suites. I need to update my other libraries but will pin versions if I can't get to updating them as this is the right path forward

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)
}
}
35 changes: 25 additions & 10 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,27 +73,38 @@ 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) {
TheTechmage marked this conversation as resolved.
Show resolved Hide resolved
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 = (
did: string,
authKeys: IDIDDocumentVerificationMethod[],
encKeys: IDIDDocumentVerificationMethod[],
services: IDIDDocumentServiceDescriptor[]
services: IDIDDocumentServiceDescriptor[],
TheTechmage marked this conversation as resolved.
Show resolved Hide resolved
) => {
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 => ({
Expand All @@ -106,16 +117,20 @@ export const createDIDDocument = (
"id": did,
assertionMethod: auth,
authentication: auth,
capabilityDelegation: auth,
capabilityInvocation: auth,
verificationMethod: ver,
}
if (didPeerNumalgo < 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did:peer:2 doesn't have capabilityDelegation or capabilityInvocation?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did:peer:2 does support expressing capabilityDelegation and capabilityInvocation but, unfortunately, only as an explicitly marked value; for instance: .Dz6Mkj3PUd1WjvaDhNZhhhXQdz5UnZXmS7ehtx8bsPpD47kKc will cause the key with multikey material z6Mkj3PUd1WjvaDhNZhhhXQdz5UnZXmS7ehtx8bsPpD47kKc to be added to the verification method list and a reference added to capabilityDelegation but not into any other verification relationship.

It is because of limitations like these that we're moving to did:peer:4 which can express any DID Document without limitations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what needs to be done here as Delegation and Invocation are foreign diddoc concepts to me. All of my recent work has revolved around .E and .V. I've only seen references to .I and .D and I've never seen them used in practice.

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.SeyJpZCI6ImEtdmVyeS11bmlxdWUtc2VydmljZSIsInQiOiJkbSIsInMiOiJodHRwczovL2V4YW1wbGUuY29tL2VuZHBvaW50MiIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkxIl0sImEiOlsiZGlkY29tbS92MiIsImRpZGNvbW0vYWlwMjtlbnY9cmZjNTg3Il19.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDMiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ"
}
45 changes: 26 additions & 19 deletions src/tests/fixtures/peerdid-python/numalgo2-diddoc.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
{
"@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": "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Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#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.SeyJ0IjoiZG0iLC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s2ZWUkGv22od935YF4s8M7V.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",
TheTechmage marked this conversation as resolved.
Show resolved Hide resolved
"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)
})
})
})