Skip to content

Commit

Permalink
update invalid signature test
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Aug 22, 2022
1 parent 36adc02 commit ffc14fb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Example/IntegrationTests/Auth/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import WalletConnectUtils
@testable import WalletConnectKMS
import WalletConnectRelay
import Combine
import Auth
@testable import Auth

final class AuthTests: XCTestCase {
var app: AuthClient!
Expand Down Expand Up @@ -68,7 +68,7 @@ final class AuthTests: XCTestCase {
try! await wallet.pair(uri: uri)
wallet.authRequestPublisher.sink { [unowned self] (id, message) in
Task(priority: .high) {
let signature = try! MessageSigner(signer: Signer()).sign(message: message, privateKey: prvKey)
let signature = try! MessageSigner().sign(message: message, privateKey: prvKey)
let cacaoSignature = CacaoSignature(t: "eip191", s: signature)
try! await wallet.respond(.success(RespondParams(id: id, signature: cacaoSignature)))
}
Expand All @@ -88,14 +88,15 @@ final class AuthTests: XCTestCase {
try! await wallet.pair(uri: uri)
wallet.authRequestPublisher.sink { [unowned self] (id, message) in
Task(priority: .high) {
let invalidSignature = "43effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b"
let invalidSignature = "438effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b"
let cacaoSignature = CacaoSignature(t: "eip191", s: invalidSignature)
try! await wallet.respond(.success(RespondParams(id: id, signature: cacaoSignature)))
}
}
.store(in: &publishers)
app.authResponsePublisher.sink { (id, result) in
guard case .success = result else { XCTFail(); return }
guard case .failure(let error) = result else { XCTFail(); return }
// TODO - complete after reason codes are merged
responseExpectation.fulfill()
}
.store(in: &publishers)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/Services/Signer/MessageSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct MessageSigner: MessageSignatureVerifying, MessageSigning {

private let signer: Signer

public init(signer: Signer) {
public init(signer: Signer = Signer()) {
self.signer = signer
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/Auth/Services/Signer/Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public struct Signer {

typealias Signature = (v: UInt, r: [UInt8], s: [UInt8])

public init() {}

func sign(message: Data, with key: Data) throws -> Data {
let prefixed = prefixed(message: message)
let privateKey = try EthereumPrivateKey(privateKey: key.bytes)
Expand Down
8 changes: 7 additions & 1 deletion Sources/Auth/Types/Cacao/CacaoSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ import Foundation
public struct CacaoSignature: Codable, Equatable {
let t: String
let s: String
let m: String? = nil
let m: String?

public init(t: String, s: String, m: String? = nil) {
self.t = t
self.s = s
self.m = m
}
}
7 changes: 6 additions & 1 deletion Sources/Auth/Types/RespondParams.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Foundation

public struct RespondParams {
public struct RespondParams: Equatable {
let id: RPCID
let signature: CacaoSignature

public init(id: RPCID, signature: CacaoSignature) {
self.id = id
self.signature = signature
}
}

0 comments on commit ffc14fb

Please sign in to comment.