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: correctly parse multiple service blocks #66

Merged
Merged
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
7 changes: 5 additions & 2 deletions src/lib/peer2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export default class DIDPeer {
const doc: any = {
"@context": "https://www.w3.org/ns/did/v1",
id: did,
service: [],
}
let serviceIndex = 0;

elements.forEach(element => {
const purposeCode = element.charAt(0)
Expand Down Expand Up @@ -229,13 +231,14 @@ export default class DIDPeer {
.map((service: any) => {
// TODO This is a bandaid! Mediator should include id in services.
if (!("id" in service)) {
service.id = "#service"
let suffix = serviceIndex++ > 0 ? "" : `-${serviceIndex}`
service.id = `#service${suffix}`
}
return service
})
.map(DIDPeer.transformOldServiceStyleToNew)

doc.service = services
doc.service.push(...services)
break
}

Expand Down