Skip to content

Commit

Permalink
fix: key ids order was not correct (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
beatt83 authored Feb 14, 2024
1 parent 8e2e438 commit 083b8fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
9 changes: 9 additions & 0 deletions Sources/PeerDID/Models/PeerDID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public struct PeerDID {
methodIdWithoutAlgo.components(separatedBy: ".")
}

public var algo2Keys: [String] {
guard algo == ._2 else { return [] }
return allAttributes
.filter {
$0.hasPrefix(Algorithm.Algo2Prefix.authentication.rawValue) || $0.hasPrefix(Algorithm.Algo2Prefix.agreement.rawValue)
}
.map { String($0.dropFirst()) }
}

public var algo2AuthenticationKeys: [String] {
guard algo == ._2 else { return [] }
return allAttributes
Expand Down
19 changes: 3 additions & 16 deletions Sources/PeerDID/PeerDID/PeerDIDHelper+ResolveAlgo2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,11 @@ import Foundation
extension PeerDIDHelper {

public func resolvePeerDIDAlgo2(peerDID: PeerDID, format: VerificationMaterialFormat) throws -> DIDDocument {
let authenticationKeys = peerDID.algo2AuthenticationKeys
let agreementKeys = peerDID.algo2KeyAgreementKeys
let keys = peerDID.algo2Keys
let services = peerDID.algo2Service

var keyIdCount = 1
let authenticationVerificationMethods = try authenticationKeys
.map { try decodeMultibaseEcnumbasis(ecnumbasis: $0, format: format) }
.map {
let method = try DIDDocument.VerificationMethod(
did: peerDID.string,
id: "key-\(keyIdCount)",
material: $0
)
keyIdCount+=1
return method
}

let agreementVerificationMethods = try agreementKeys
let verificationMethods = try keys
.map { try decodeMultibaseEcnumbasis(ecnumbasis: $0, format: format) }
.map {
let method = try DIDDocument.VerificationMethod(
Expand All @@ -46,7 +33,7 @@ extension PeerDIDHelper {

return DIDDocument(
id: peerDID.string,
verificationMethods: authenticationVerificationMethods + agreementVerificationMethods,
verificationMethods: verificationMethods,
services: documentServices
)
}
Expand Down

0 comments on commit 083b8fd

Please sign in to comment.