Skip to content

Commit

Permalink
- re-add private key base58 init needed for torus
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Sep 19, 2023
1 parent f5a0314 commit d519571
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/KukaiCryptoSwift/PrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ public struct PrivateKey: Codable {
self.signingCurve = signingCurve
}

/**
Initialize a key with the given base58check encoded string.
- parameter string: A base58check encoded string.
- parameter signingCurve: The elliptical curve to use for the key. Defaults to ed25519.
*/
public init?(_ string: String, signingCurve: EllipticalCurve = .ed25519) {
switch signingCurve {
case .ed25519:
guard let bytes = Base58Check.decode(string: string, prefix: Prefix.Keys.Ed25519.secret) else {
return nil
}
self.init(bytes)

case .secp256k1:
guard let bytes = Base58Check.decode(string: string, prefix: Prefix.Keys.Secp256k1.secret) else {
return nil
}
self.init(bytes, signingCurve: .secp256k1)
}
}



// MARK: - Utils
Expand Down

0 comments on commit d519571

Please sign in to comment.