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: fix because restoring keys was not working properly due to typo #93

Merged
merged 1 commit into from
Jun 23, 2023
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
2 changes: 1 addition & 1 deletion AtalaPrismSDK/Apollo/Sources/Model/Ed25519Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension Ed25519PrivateKey: SignableKey {

extension Ed25519PrivateKey: StorableKey {
var securityLevel: SecurityLevel { SecurityLevel.high }
var restorationIdentifier: String { "ed25519+prv" }
var restorationIdentifier: String { "ed25519+priv" }
var storableData: Data { raw }
}

Expand Down
2 changes: 1 addition & 1 deletion AtalaPrismSDK/Apollo/Sources/Model/X25519Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct X25519PrivateKey: PrivateKey {

extension X25519PrivateKey: StorableKey {
var securityLevel: SecurityLevel { SecurityLevel.high }
var restorationIdentifier: String { "x25519+prv" }
var restorationIdentifier: String { "x25519+priv" }
var storableData: Data { raw }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ private extension CDDIDPrivateKey {
else { return }
switch curve {
case .x25519:
self.privateKeyKeyAgreement = $0.storableData
self.curveKeyAgreement = $0.restorationIdentifier
self.privateKeyAuthenticate = $0.storableData
self.curveAuthenticate = $0.restorationIdentifier
case .ed25519:
self.privateKeyAuthenticate = $0.storableData
self.curveAuthenticate = $0.restorationIdentifier
Expand Down
16 changes: 3 additions & 13 deletions AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public extension PrismAgent {
/// - Throws: PrismAgentError, if there is a problem creating the request credential.
func prepareRequestCredentialWithIssuer(did: DID, offer: OfferCredential) async throws -> RequestCredential? {
guard did.method == "prism" else { throw PolluxError.invalidPrismDID }
let apollo = self.apollo
let seed = self.seed
let didInfo = try await pluto
.getDIDInfo(did: did)
.first()
Expand All @@ -60,7 +58,8 @@ public extension PrismAgent {
guard let privateKey = didInfo?.privateKeys.first else { throw PrismAgentError.cannotFindDIDKeyPairIndex }

guard
let signing = privateKey.signing
let exporting = privateKey.exporting,
let pemData = exporting.pem.data(using: .utf8)
else { throw PrismAgentError.cannotFindDIDKeyPairIndex }

guard let offerData = offer
Expand Down Expand Up @@ -93,16 +92,7 @@ public extension PrismAgent {
]))
))

let signer = JWTSigner.none
let withoutSignature = try JWTEncoder(jwtSigner: signer).encodeToString(jwt)
print(withoutSignature)
let removedHeader = withoutSignature.components(separatedBy: ".").last!
let headerBase64 = "{\"typ\": \"JWT\", \"alg\": \"ES256K\"}".data(using: .utf8)!.base64UrlEncodedString()
let body = headerBase64 + "." + removedHeader
let signature = try await signing.sign(data: body.data(using: .utf8)!)
let signatureBase64 = signature.raw.base64UrlEncodedString()

let jwtString = body + "." + signatureBase64
let jwtString = try JWTEncoder(jwtSigner: .es256k(privateKey: pemData)).encodeToString(jwt)

guard let base64String = jwtString.data(using: .utf8)?.base64EncodedString() else {
throw UnknownError.somethingWentWrongError()
Expand Down
19 changes: 4 additions & 15 deletions AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public extension PrismAgent {
throw UnknownError.somethingWentWrongError()
}

let apollo = apollo
let seed = seed
let didInfo = try await pluto
.getDIDInfo(did: subjectDID)
.first()
Expand All @@ -53,7 +51,8 @@ public extension PrismAgent {
guard let privateKey = didInfo?.privateKeys.first else { throw PrismAgentError.cannotFindDIDKeyPairIndex }

guard
let signing = privateKey.signing
let exporting = privateKey.exporting,
let pemData = exporting.pem.data(using: .utf8)
else { throw PrismAgentError.cannotFindDIDKeyPairIndex }

let jwt = JWT(claims: ClaimsProofPresentationJWT(
Expand All @@ -66,18 +65,8 @@ public extension PrismAgent {
verifiableCredential: [credential.id]
)
))
let signer = JWTSigner.none
let withoutSignature = try JWTEncoder(jwtSigner: signer).encodeToString(jwt)
print(withoutSignature)
let removedHeader = withoutSignature.components(separatedBy: ".").last!
let headerBase64 = "{\"typ\": \"JWT\", \"alg\": \"ES256K\"}".data(using: .utf8)!.base64UrlEncodedString()
let body = headerBase64 + "." + removedHeader
let signature = try await signing.sign(data: body.data(using: .utf8)!)
let signatureBase64 = signature.raw.base64UrlEncodedString()

let jwtString = body + "." + signatureBase64
print("JWTString: \(jwtString)")
//let jwtString = try JWTEncoder(jwtSigner: .es256k(privateKey: pemPrivateKey)).encodeToString(jwt)
let jwtString = try JWTEncoder(jwtSigner: .es256k(privateKey: pemData)).encodeToString(jwt)

guard let base64String = jwtString.data(using: .utf8)?.base64EncodedString() else {
throw UnknownError.somethingWentWrongError()
}
Expand Down