diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 257ebc38a..85992543b 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -19,12 +19,6 @@ jobs: with: xcode-version: '13.2' - - uses: actions/cache@v2 - with: - path: .build - key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} - restore-keys: | - ${{ runner.os }}-spm- # Package builds - name: Build Package diff --git a/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningKeyCryptoKit.swift b/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningKeyCryptoKit.swift index 8b1378917..fb78a9bfc 100644 --- a/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningKeyCryptoKit.swift +++ b/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningKeyCryptoKit.swift @@ -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(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(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) + } +} diff --git a/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningPrivateKey.swift b/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningPrivateKey.swift deleted file mode 100644 index fb78a9bfc..000000000 --- a/Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/SigningPrivateKey.swift +++ /dev/null @@ -1,82 +0,0 @@ -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(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(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) - } -}