Skip to content

Commit

Permalink
feat: add assertionMethod by default to didDocument (decentralized-…
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis authored Apr 20, 2021
1 parent c5c9633 commit 11b2096
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/networks.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('ethrResolver (alt-chains)', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -62,6 +63,7 @@ describe('ethrResolver (alt-chains)', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -90,6 +92,7 @@ describe('ethrResolver (alt-chains)', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand All @@ -116,6 +119,7 @@ describe('ethrResolver (alt-chains)', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand All @@ -142,6 +146,7 @@ describe('ethrResolver (alt-chains)', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -175,6 +180,7 @@ describe('ethrResolver (alt-chains)', () => {
},
],
authentication: [`${did}#controller`, `${did}#controllerKey`],
assertionMethod: [`${did}#controller`, `${did}#controllerKey`],
},
})
})
Expand Down
42 changes: 42 additions & 0 deletions src/__tests__/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -98,6 +99,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${pubdid}#controller`, `${pubdid}#controllerKey`],
assertionMethod: [`${pubdid}#controller`, `${pubdid}#controllerKey`],
},
})
})
Expand Down Expand Up @@ -127,6 +129,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand All @@ -151,6 +154,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${pubdid}#controller`],
assertionMethod: [`${pubdid}#controller`],
})
expect(didDocument?.verificationMethod?.length).toBe(1)
expect(didDocument?.authentication?.length).toBe(1)
Expand Down Expand Up @@ -190,6 +194,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
},
})
})
Expand Down Expand Up @@ -234,6 +239,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-2`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`, `${did}#delegate-2`],
},
})
})
Expand Down Expand Up @@ -271,6 +277,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
},
})
})
Expand Down Expand Up @@ -304,6 +311,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -342,6 +350,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
},
})
})
Expand Down Expand Up @@ -386,6 +395,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-5`],
})
})

Expand Down Expand Up @@ -434,6 +444,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-5`, `${did}#delegate-6`],
})
})

Expand Down Expand Up @@ -488,6 +499,13 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [
`${did}#controller`,
`${did}#delegate-4`,
`${did}#delegate-5`,
`${did}#delegate-6`,
`${did}#delegate-7`,
],
})
})

Expand Down Expand Up @@ -522,6 +540,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${keyAgrDid}#controller`],
assertionMethod: [`${keyAgrDid}#controller`, `${keyAgrDid}#delegate-1`],
})
})
})
Expand Down Expand Up @@ -578,6 +597,13 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [
`${did}#controller`,
`${did}#delegate-4`,
`${did}#delegate-5`,
`${did}#delegate-6`,
`${did}#delegate-7`,
],
service: [
{
id: `${did}#service-1`,
Expand Down Expand Up @@ -635,6 +661,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-6`, `${did}#delegate-7`],
service: [
{
id: `${did}#service-1`,
Expand Down Expand Up @@ -680,6 +707,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-7`],
service: [
{
id: `${did}#service-1`,
Expand Down Expand Up @@ -719,6 +747,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
service: [
{
id: `${did}#service-1`,
Expand Down Expand Up @@ -759,6 +788,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
})
})
})
Expand Down Expand Up @@ -810,6 +840,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
service: [
{
id: `${did}#service-4`,
Expand Down Expand Up @@ -870,6 +901,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
service: [
{
id: `${did}#service-4`,
Expand Down Expand Up @@ -936,6 +968,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-1`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
})
})

Expand Down Expand Up @@ -981,6 +1014,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
},
})
})
Expand Down Expand Up @@ -1008,6 +1042,7 @@ describe('ethrResolver', () => {
id: did,
verificationMethod: [],
authentication: [],
assertionMethod: [],
},
})
})
Expand Down Expand Up @@ -1039,6 +1074,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${virginDID}#controller`],
assertionMethod: [`${virginDID}#controller`],
},
})
})
Expand Down Expand Up @@ -1076,6 +1112,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${modifiedDid}#controller`],
assertionMethod: [`${modifiedDid}#controller`, `${modifiedDid}#delegate-1`],
},
})
})
Expand Down Expand Up @@ -1111,6 +1148,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
},
})
})
Expand Down Expand Up @@ -1140,6 +1178,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -1169,6 +1208,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
})
})
Expand Down Expand Up @@ -1199,6 +1239,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${deactivatedDid}#controller`],
assertionMethod: [`${deactivatedDid}#controller`],
},
})
})
Expand Down Expand Up @@ -1239,6 +1280,7 @@ describe('ethrResolver', () => {
},
],
authentication: [`${did}#controller`, `${did}#delegate-2`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`, `${did}#delegate-2`],
},
})
})
Expand Down
9 changes: 5 additions & 4 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class EthrDidResolver {
id: did,
verificationMethod: [],
authentication: [],
assertionMethod: [],
}

let controller = address
Expand Down Expand Up @@ -272,14 +273,15 @@ export class EthrDidResolver {
authentication.push(`${did}#controllerKey`)
}

const doc: DIDDocument = {
const didDocument: DIDDocument = {
...baseDIDDocument,
verificationMethod: publicKeys.concat(Object.values(pks)),
authentication: authentication.concat(Object.values(auth)),
}
if (Object.values(services).length > 0) {
doc.service = Object.values(services)
didDocument.service = Object.values(services)
}
didDocument.assertionMethod = [...(didDocument.verificationMethod?.map((pk) => pk.id) || [])]

return deactivated
? {
Expand All @@ -288,7 +290,7 @@ export class EthrDidResolver {
versionId,
nextVersionId,
}
: { didDocument: doc, deactivated, versionId, nextVersionId }
: { didDocument, deactivated, versionId, nextVersionId }
}

async resolve(
Expand All @@ -312,7 +314,6 @@ export class EthrDidResolver {
const id = fullId[2]
const networkId = !fullId[1] ? 'mainnet' : fullId[1].slice(0, -1)
let blockTag: string | number = options.blockTag || 'latest'
// let versionAtMost: string | number = -1
if (typeof parsed.query === 'string') {
const qParams = qs.decode(parsed.query)
blockTag = typeof qParams['versionId'] === 'string' ? qParams['versionId'] : blockTag
Expand Down

0 comments on commit 11b2096

Please sign in to comment.