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

fix: reference /enc/ keys in keyAgreement section of DID doc #146

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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