Skip to content

Commit

Permalink
[CHANGE] Rename EthereumKeyStorageProtocol -> SingleKeyStorageProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthMike committed Nov 28, 2022
1 parent 72db1e5 commit 29c5e43
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions web3sTests/Account/EthereumAccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion web3sTests/Account/EthereumKeyStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion web3sTests/Mocks/TestEthereumKeyStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation
@testable import web3

class TestEthereumKeyStorage: EthereumKeyStorageProtocol {
class TestEthereumKeyStorage: EthereumSingleKeyStorageProtocol {

private var privateKey: String

Expand Down
8 changes: 4 additions & 4 deletions web3swift/src/Account/EthereumAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion web3swift/src/Account/EthereumKeyStorage+Password.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions web3swift/src/Account/EthereumKeyStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

public protocol EthereumKeyStorageProtocol {
public protocol EthereumSingleKeyStorageProtocol {
func storePrivateKey(key: Data) throws
func loadPrivateKey() throws -> Data
}
Expand All @@ -25,7 +25,7 @@ public enum EthereumKeyStorageError: Error {
case failedToDelete
}

public class EthereumKeyLocalStorage: EthereumKeyStorageProtocol {
public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {

public init() {}

Expand Down

0 comments on commit 29c5e43

Please sign in to comment.