Skip to content

Commit e6dba0f

Browse files
committed
fix errors with typealiases
1 parent f33b07e commit e6dba0f

File tree

9 files changed

+36
-76
lines changed

9 files changed

+36
-76
lines changed

Example/web3swiftBrowser/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 18 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftBrowser/web3swiftBrowser.xcodeproj/xcshareddata/xcschemes/web3swiftBrowser.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1210"
3+
LastUpgradeVersion = "1170"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ extension web3.BrowserFunctions {
196196
transaction.chainID = self.web3.provider.network?.chainID
197197
}
198198

199-
guard let keystore = keystoreManager.walletForAddress(from) else {return nil}
199+
guard let keystore: AbstractKeystore = keystoreManager.walletForAddress(from) else {return nil}
200200
try Web3Signer.signTX(transaction: &transaction, keystore: keystore, account: from, password: password)
201201
print(transaction)
202202
let signedData = transaction.encode(forSignature: false, chainID: nil)?.toHexString().addHexPrefix()

Sources/web3swift/KeystoreManager/AbstractKeystore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
//import EthereumAddress
1010

1111
public protocol AbstractKeystore {
12-
public associatedtype Params: AbstractKeystoreParams
12+
associatedtype Params: AbstractKeystoreParams
1313
func giveKeystoreParams() -> Params
1414
var addresses: [EthereumAddress]? { get }
1515
var isHDKeystore: Bool { get }

Sources/web3swift/KeystoreManager/BIP32Keystore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import Foundation
1212

1313
public class BIP32Keystore: AbstractKeystore {
1414

15-
typealias Params = KeystoreParamsBIP32
15+
public typealias Params = KeystoreParamsBIP32
1616
public func giveKeystoreParams() -> Params {
17-
self.keystoreParams
17+
self.keystoreParams!
1818
}
1919

2020
// Protocol

Sources/web3swift/KeystoreManager/EthereumKeystoreV3.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import CryptoSwift
99
import Foundation
1010

1111
public class EthereumKeystoreV3: AbstractKeystore {
12-
typealias Params = KeystoreParamsV3
13-
public var keystoreParams: KeystoreParamsV3?
12+
public typealias Params = KeystoreParamsV3
13+
public var keystoreParams: Params?
1414

1515
public func giveKeystoreParams() -> Params {
16-
keystoreParams
16+
keystoreParams!
1717
}
1818

1919

Sources/web3swift/KeystoreManager/KeystoreManager.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import Foundation
99
//import EthereumAddress
1010

1111
public class KeystoreManager: AbstractKeystore {
12-
associatedtype Params = KeystoreParamsV3
12+
public typealias Params = KeystoreParamsV3
1313
public func giveKeystoreParams() -> Params {
1414
fatalError("giveKeystoreParams() is not available for manager implemented")
15-
return nil
1615
}
1716

1817
public var isHDKeystore: Bool = false
@@ -109,13 +108,13 @@ public class KeystoreManager: AbstractKeystore {
109108

110109
public var path: String
111110

112-
public func walletForAddress(_ address: EthereumAddress) -> AbstractKeystore? {
111+
public func walletForAddress(_ address: EthereumAddress) -> <T: AbstractKeystore> T {
113112
for keystore in _keystores {
114113
guard let key = keystore.addresses?.first else {
115114
continue
116115
}
117116
if key == address && key.isValid {
118-
return keystore
117+
return keystore as? T
119118
}
120119
}
121120
for keystore in _bip32keystores {
@@ -124,7 +123,7 @@ public class KeystoreManager: AbstractKeystore {
124123
}
125124
for addr in allAddresses {
126125
if addr == address && addr.isValid {
127-
return keystore
126+
return keystore as? T
128127
}
129128
}
130129
}
@@ -133,7 +132,7 @@ public class KeystoreManager: AbstractKeystore {
133132
continue
134133
}
135134
if key == address && key.isValid {
136-
return keystore
135+
return keystore as? T
137136
}
138137
}
139138
return nil

Sources/web3swift/KeystoreManager/PlainKeystore.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import Foundation
1010
//import EthereumAddress
1111

1212
public class PlainKeystore: AbstractKeystore {
13-
typealias Params = KeystoreParamsV3
13+
public typealias Params = KeystoreParamsV3
1414

1515
public var keystoreParams: KeystoreParamsV3?
1616

17-
public func giveKeystoreParams() -> T {
18-
keystoreParams
17+
public func giveKeystoreParams() -> Params {
18+
keystoreParams!
1919
}
2020

2121

Sources/web3swift/Transaction/TransactionSigner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum TransactionSignerError: Error {
1414
}
1515

1616
public struct Web3Signer {
17-
public static func signTX(transaction:inout EthereumTransaction, keystore: AbstractKeystore, account: EthereumAddress, password: String, useExtraEntropy: Bool = false) throws {
17+
public static func signTX<T: AbstractKeystore>(transaction:inout EthereumTransaction, keystore: T, account: EthereumAddress, password: String, useExtraEntropy: Bool = false) throws {
1818
var privateKey = try keystore.UNSAFE_getPrivateKeyData(password: password, account: account)
1919
defer {Data.zero(&privateKey)}
2020
if (transaction.chainID != nil) {
@@ -24,7 +24,7 @@ public struct Web3Signer {
2424
}
2525
}
2626

27-
public static func signPersonalMessage(_ personalMessage: Data, keystore: AbstractKeystore, account: EthereumAddress, password: String, useExtraEntropy: Bool = false) throws -> Data? {
27+
public static func signPersonalMessage<T:AbstractKeystore>(_ personalMessage: Data, keystore: T, account: EthereumAddress, password: String, useExtraEntropy: Bool = false) throws -> Data? {
2828
var privateKey = try keystore.UNSAFE_getPrivateKeyData(password: password, account: account)
2929
defer {Data.zero(&privateKey)}
3030
guard let hash = Web3.Utils.hashPersonalMessage(personalMessage) else {return nil}

0 commit comments

Comments
 (0)