-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51405d6
commit 3c1e052
Showing
3 changed files
with
81 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningKeyCryptoKit.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,82 @@ | ||
import Foundation | ||
import CryptoKit | ||
|
||
extension Curve25519.Signing.PublicKey: Equatable { | ||
public static func == (lhs: Curve25519.Signing.PublicKey, rhs: Curve25519.Signing.PublicKey) -> Bool { | ||
lhs.rawRepresentation == rhs.rawRepresentation | ||
} | ||
} | ||
|
||
extension Curve25519.Signing.PrivateKey: Equatable { | ||
public static func == (lhs: Curve25519.Signing.PrivateKey, rhs: Curve25519.Signing.PrivateKey) -> Bool { | ||
lhs.rawRepresentation == rhs.rawRepresentation | ||
} | ||
} | ||
|
||
// MARK: - Public Key | ||
|
||
public struct SigningPublicKey: GenericPasswordConvertible, Equatable { | ||
fileprivate let key: Curve25519.Signing.PublicKey | ||
|
||
fileprivate init(publicKey: Curve25519.Signing.PublicKey) { | ||
self.key = publicKey | ||
} | ||
|
||
public init<D>(rawRepresentation data: D) throws where D: ContiguousBytes { | ||
self.key = try Curve25519.Signing.PublicKey(rawRepresentation: data) | ||
} | ||
|
||
public init(hex: String) throws { | ||
let data = Data(hex: hex) | ||
try self.init(rawRepresentation: data) | ||
} | ||
|
||
public var rawRepresentation: Data { | ||
key.rawRepresentation | ||
} | ||
|
||
public var hexRepresentation: String { | ||
key.rawRepresentation.toHexString() | ||
} | ||
} | ||
|
||
extension SigningPublicKey: Codable { | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(key.rawRepresentation) | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let buffer = try container.decode(Data.self) | ||
try self.init(rawRepresentation: buffer) | ||
} | ||
} | ||
|
||
// MARK: - Private Key | ||
|
||
public struct SigningPrivateKey: GenericPasswordConvertible, Equatable { | ||
private let key: Curve25519.Signing.PrivateKey | ||
|
||
public init() { | ||
self.key = Curve25519.Signing.PrivateKey() | ||
} | ||
|
||
public init<D>(rawRepresentation data: D) throws where D: ContiguousBytes { | ||
|
||
self.key = try Curve25519.Signing.PrivateKey(rawRepresentation: data) | ||
} | ||
|
||
public var rawRepresentation: Data { | ||
key.rawRepresentation | ||
} | ||
|
||
public var publicKey: SigningPublicKey { | ||
SigningPublicKey(publicKey: key.publicKey) | ||
} | ||
|
||
public func signature(for data: Data) throws -> Data { | ||
try key.signature(for: data) | ||
} | ||
} |
82 changes: 0 additions & 82 deletions
82
Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningPrivateKey.swift
This file was deleted.
Oops, something went wrong.