From 29c5e43848a2e21806c6b47a9d29732825ac63b7 Mon Sep 17 00:00:00 2001 From: Miguel Angel Quinones Date: Mon, 28 Nov 2022 11:31:45 +0100 Subject: [PATCH] [CHANGE] Rename EthereumKeyStorageProtocol -> SingleKeyStorageProtocol --- README.md | 2 +- web3sTests/Account/EthereumAccountTests.swift | 4 ++-- web3sTests/Account/EthereumKeyStorageTests.swift | 2 +- web3sTests/Mocks/TestEthereumKeyStorage.swift | 2 +- web3swift/src/Account/EthereumAccount.swift | 8 ++++---- web3swift/src/Account/EthereumKeyStorage+Password.swift | 2 +- web3swift/src/Account/EthereumKeyStorage.swift | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f1138503..f8cef52f 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ $ pod install ### Getting Started -Create an instance of `EthereumAccount` with a `EthereumKeyStorage` provider. This provides a wrapper around your key for web3.swift to use. **NOTE** We recommend you implement your own KeyStorage provider, instead of relying on the provided `EthereumKeyLocalStorage` class. This is provided as an example for conformity to the `EthereumKeyStorageProtocol`. +Create an instance of `EthereumAccount` with a `EthereumKeyStorage` provider. This provides a wrapper around your key for web3.swift to use. **NOTE** We recommend you implement your own KeyStorage provider, instead of relying on the provided `EthereumKeyLocalStorage` class. This is provided as an example for conformity to the `EthereumSingleKeyStorageProtocol`. ```swift import web3 diff --git a/web3sTests/Account/EthereumAccountTests.swift b/web3sTests/Account/EthereumAccountTests.swift index ffb6144c..88a69979 100644 --- a/web3sTests/Account/EthereumAccountTests.swift +++ b/web3sTests/Account/EthereumAccountTests.swift @@ -27,7 +27,7 @@ class EthereumAccountTests: XCTestCase { } func testCreateAccount() { - let storage = EthereumKeyLocalStorage() as EthereumKeyStorageProtocol + let storage = EthereumKeyLocalStorage() let account = try? EthereumAccount.create(keyStorage: storage, keystorePassword: "PASSWORD") XCTAssertNotNil(account, "Failed to create account. Ensure key is valid in TestConfig.swift") } @@ -39,7 +39,7 @@ class EthereumAccountTests: XCTestCase { } func testImportAccount() { - let storage = EthereumKeyLocalStorage() as EthereumKeyStorageProtocol + let storage = EthereumKeyLocalStorage() as EthereumSingleKeyStorageProtocol let account = try! EthereumAccount.importAccount(keyStorage: storage, privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", keystorePassword: "PASSWORD") XCTAssertEqual(account.address.value, "0x675f5810feb3b09528e5cd175061b4eb8de69075") diff --git a/web3sTests/Account/EthereumKeyStorageTests.swift b/web3sTests/Account/EthereumKeyStorageTests.swift index e63f4cc4..2ca37202 100644 --- a/web3sTests/Account/EthereumKeyStorageTests.swift +++ b/web3sTests/Account/EthereumKeyStorageTests.swift @@ -43,7 +43,7 @@ class EthereumKeyStorageTests: XCTestCase { func testEncryptAndStorePrivateKey() { let randomData = Data.randomOfLength(256)! - let keyStorage = EthereumKeyLocalStorage() as EthereumKeyStorageProtocol + let keyStorage = EthereumKeyLocalStorage() as EthereumSingleKeyStorageProtocol let password = "myP4ssw0rD" do { diff --git a/web3sTests/Mocks/TestEthereumKeyStorage.swift b/web3sTests/Mocks/TestEthereumKeyStorage.swift index fc229742..542bd6e4 100644 --- a/web3sTests/Mocks/TestEthereumKeyStorage.swift +++ b/web3sTests/Mocks/TestEthereumKeyStorage.swift @@ -6,7 +6,7 @@ import Foundation @testable import web3 -class TestEthereumKeyStorage: EthereumKeyStorageProtocol { +class TestEthereumKeyStorage: EthereumSingleKeyStorageProtocol { private var privateKey: String diff --git a/web3swift/src/Account/EthereumAccount.swift b/web3swift/src/Account/EthereumAccount.swift index 46065ba0..90b5b529 100644 --- a/web3swift/src/Account/EthereumAccount.swift +++ b/web3swift/src/Account/EthereumAccount.swift @@ -37,7 +37,7 @@ public class EthereumAccount: EthereumAccountProtocol { return KeyUtil.generateAddress(from: self.publicKeyData) }() - required public init(keyStorage: EthereumKeyStorageProtocol, keystorePassword password: String, logger: Logger? = nil) throws { + required public init(keyStorage: EthereumSingleKeyStorageProtocol, keystorePassword password: String, logger: Logger? = nil) throws { self.logger = logger ?? Logger(label: "web3.swift.eth-account") do { let decodedKey = try keyStorage.loadAndDecryptPrivateKey(keystorePassword: password) @@ -49,7 +49,7 @@ public class EthereumAccount: EthereumAccountProtocol { } } - required public init(keyStorage: EthereumKeyStorageProtocol, logger: Logger? = nil) throws { + required public init(keyStorage: EthereumSingleKeyStorageProtocol, logger: Logger? = nil) throws { self.logger = logger ?? Logger(label: "web3.swift.eth-account") do { let data = try keyStorage.loadPrivateKey() @@ -100,7 +100,7 @@ public class EthereumAccount: EthereumAccountProtocol { } } - public static func create(keyStorage: EthereumKeyStorageProtocol, keystorePassword password: String) throws -> EthereumAccount { + public static func create(keyStorage: EthereumSingleKeyStorageProtocol, keystorePassword password: String) throws -> EthereumAccount { guard let privateKey = KeyUtil.generatePrivateKeyData() else { throw EthereumAccountError.createAccountError } @@ -127,7 +127,7 @@ public class EthereumAccount: EthereumAccountProtocol { } } - public static func importAccount(keyStorage: EthereumKeyStorageProtocol, privateKey: String, keystorePassword password: String) throws -> EthereumAccount { + public static func importAccount(keyStorage: EthereumSingleKeyStorageProtocol, privateKey: String, keystorePassword password: String) throws -> EthereumAccount { guard let privateKey = privateKey.web3.hexData else { throw EthereumAccountError.importAccountError } diff --git a/web3swift/src/Account/EthereumKeyStorage+Password.swift b/web3swift/src/Account/EthereumKeyStorage+Password.swift index 61579fb9..5c085b24 100644 --- a/web3swift/src/Account/EthereumKeyStorage+Password.swift +++ b/web3swift/src/Account/EthereumKeyStorage+Password.swift @@ -5,7 +5,7 @@ import Foundation -public extension EthereumKeyStorageProtocol { +public extension EthereumSingleKeyStorageProtocol { func encryptAndStorePrivateKey(key: Data, keystorePassword: String) throws { let encodedKey = try KeystoreUtil.encode(privateKey: key, password: keystorePassword) try storePrivateKey(key: encodedKey) diff --git a/web3swift/src/Account/EthereumKeyStorage.swift b/web3swift/src/Account/EthereumKeyStorage.swift index 6d47bd77..c9fff6e7 100644 --- a/web3swift/src/Account/EthereumKeyStorage.swift +++ b/web3swift/src/Account/EthereumKeyStorage.swift @@ -5,7 +5,7 @@ import Foundation -public protocol EthereumKeyStorageProtocol { +public protocol EthereumSingleKeyStorageProtocol { func storePrivateKey(key: Data) throws func loadPrivateKey() throws -> Data } @@ -25,7 +25,7 @@ public enum EthereumKeyStorageError: Error { case failedToDelete } -public class EthereumKeyLocalStorage: EthereumKeyStorageProtocol { +public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol { public init() {}