Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jun 23, 2022
1 parent f6fe082 commit a624076
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Foundation
import CryptoKit





// MARK: - CryptoKit extensions

extension Curve25519.Signing.PublicKey: Equatable {
public static func == (lhs: Curve25519.Signing.PublicKey, rhs: Curve25519.Signing.PublicKey) -> Bool {
lhs.rawRepresentation == rhs.rawRepresentation
Expand All @@ -16,16 +22,17 @@ extension Curve25519.Signing.PrivateKey: Equatable {
// MARK: - Public Key

public struct SigningPublicKey: GenericPasswordConvertible, Equatable {
public init<D>(rawRepresentation data: D) throws where D : ContiguousBytes {
self.key = try Curve25519.Signing.PublicKey(rawRepresentation: data)
}


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)
Expand All @@ -39,33 +46,34 @@ public struct SigningPublicKey: GenericPasswordConvertible, Equatable {
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)
// }
//}

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 {
public init<D>(rawRepresentation: D) throws where D: ContiguousBytes {

self.key = try Curve25519.Signing.PrivateKey(rawRepresentation: data)
self.key = try Curve25519.Signing.PrivateKey(rawRepresentation: rawRepresentation)
}

public var rawRepresentation: Data {
Expand All @@ -76,7 +84,93 @@ public struct SigningPrivateKey: GenericPasswordConvertible, Equatable {
SigningPublicKey(publicKey: key.publicKey)
}

public func signature(for data: Data) throws -> Data {
try key.signature(for: data)
public func signature(_ data: Data) throws -> Data {
return try key.signature(for: data)
}
}






//
//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)
// }
//}
2 changes: 1 addition & 1 deletion Sources/WalletConnectRelay/ClientAuth/JWT/JWTSigning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct EdDSASigner: JWTSigning {
guard let unsignedData = unsignedJWT.data(using: .utf8) else {
throw Errors.invalidJWTString
}
let signature = try privateKey.signature(for: unsignedData)
let signature = try privateKey.signature(unsignedData)
let signatureString = JWTEncoder.base64urlEncodedString(data: signature)
return signatureString
}
Expand Down

0 comments on commit a624076

Please sign in to comment.