Skip to content

Commit

Permalink
fix: reference /enc/ keys in keyAgreement section of DID doc (#146)
Browse files Browse the repository at this point in the history
fixes #145
  • Loading branch information
mirceanis authored Nov 10, 2021
1 parent 9693c90 commit 5d507ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/__tests__/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ describe('ethrResolver', () => {
],
authentication: [`${keyAgrDid}#controller`],
assertionMethod: [`${keyAgrDid}#controller`, `${keyAgrDid}#delegate-1`],
keyAgreement: [`${keyAgrDid}#delegate-1`]
})
})
})
Expand Down
7 changes: 7 additions & 0 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ export class EthrDidResolver {
let controller = address

const authentication = [`${did}#controller`]
const keyAgreement: string[] = []

let versionId = 0
let nextVersionId = Number.POSITIVE_INFINITY
let deactivated = false
let delegateCount = 0
let serviceCount = 0
const auth: Record<string, string> = {}
const keyAgreementRefs: Record<string, string> = {}
const pks: Record<string, VerificationMethod> = {}
const services: Record<string, ServiceEndpoint> = {}
for (const event of history) {
Expand Down Expand Up @@ -213,6 +215,8 @@ export class EthrDidResolver {
pks[eventIndex] = pk
if (match[4] === 'sigAuth') {
auth[eventIndex] = pk.id
} else if (match[4] === 'enc') {
keyAgreementRefs[eventIndex] = pk.id
}
break
}
Expand Down Expand Up @@ -280,6 +284,9 @@ export class EthrDidResolver {
if (Object.values(services).length > 0) {
didDocument.service = Object.values(services)
}
if (Object.values(keyAgreementRefs).length > 0) {
didDocument.keyAgreement = keyAgreement.concat(Object.values(keyAgreementRefs))
}
didDocument.assertionMethod = [...(didDocument.verificationMethod?.map((pk) => pk.id) || [])]

return deactivated
Expand Down

0 comments on commit 5d507ef

Please sign in to comment.