Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-716 update RegisterNotificationTokenRequest
- Loading branch information
Andrey Scherbovich
committed
Nov 25, 2020
1 parent
72e2baf
commit 8c9350d
Showing
10 changed files
with
187 additions
and
37 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Signer.swift | ||
// Multisig | ||
// | ||
// Created by Andrey Scherbovich on 25.11.20. | ||
// Copyright © 2020 Gnosis Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Web3 | ||
|
||
class Signer { | ||
struct Signature { | ||
var value: String | ||
var signer: String | ||
} | ||
|
||
/// Signs the hash of the provided string with a stored private key. | ||
/// Currently the app can store only one private key. | ||
/// - Parameters: | ||
/// - string: string to hash and sign | ||
/// - Throws: errors during sisgning process | ||
/// - Returns: Signature object containing hex(r) hex(s) hex(v + 27) as one strig of secp256k1 signature | ||
static func sign(_ string: String) throws -> Signature { | ||
let hash = EthHasher.hash(string.data(using: .ascii)!) | ||
return try sign(hash: hash) | ||
} | ||
|
||
/// Signs the hash with a stored private key by provided address. | ||
/// Currently the app can store only one private key. | ||
/// - Parameters: | ||
/// - hash: hash to sign | ||
/// - Throws: errors during sisgning process | ||
/// - Returns: Signature object containing hex(r) hex(s) hex(v + 27) as one strig of secp256k1 signature | ||
static func sign(hash: Data) throws -> Signature { | ||
guard let pkData = try App.shared.keychainService.data(forKey: KeychainKey.ownerPrivateKey.rawValue) else { | ||
throw "Private key not found" | ||
} | ||
let privateKey = try EthereumPrivateKey(pkData.bytes) | ||
let signer = privateKey.address.hex(eip55: true) | ||
let eoaSignature = try privateKey.sign(hash: hash.bytes) | ||
let v = String(eoaSignature.v + 27, radix: 16) | ||
let signature = "\(eoaSignature.r.toHexString())\(eoaSignature.s.toHexString())\(v)" | ||
return Signature(value: signature, signer: signer) | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// MockSecureStore.swift | ||
// MultisigTests | ||
// | ||
// Created by Andrey Scherbovich on 25.11.20. | ||
// Copyright © 2020 Gnosis Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import Multisig | ||
|
||
class MockSecureStore: SecureStore { | ||
private var _store = [String: Data]() | ||
|
||
func save(data: Data, forKey: String) throws { | ||
_store[forKey] = data | ||
} | ||
|
||
func data(forKey: String) throws -> Data? { | ||
return _store[forKey] | ||
} | ||
|
||
func removeData(forKey: String) throws { | ||
_store.removeValue(forKey: forKey) | ||
} | ||
|
||
func destroy() throws { | ||
_store = [String: Data]() | ||
} | ||
} |
Oops, something went wrong.