Skip to content

Commit 57cedc3

Browse files
Merge pull request #443 from skywinder/warns
2 parents c5886dd + 75c7e77 commit 57cedc3

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Sources/web3swift/KeystoreManager/BIP32HDNode.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class HDNode {
100100
public init?(seed: Data) {
101101
guard seed.count >= 16 else {return nil}
102102
let hmacKey = "Bitcoin seed".data(using: .ascii)!
103-
let hmac:Authenticator = HMAC(key: hmacKey.bytes, variant: HMAC.Variant.sha512)
103+
let hmac:Authenticator = HMAC(key: hmacKey.bytes, variant: HMAC.Variant.sha2(.sha512))
104104
guard let entropy = try? hmac.authenticate(seed.bytes) else {return nil}
105105
guard entropy.count == 64 else { return nil}
106106
let I_L = entropy[0..<32]
@@ -135,7 +135,7 @@ extension HDNode {
135135
if trueIndex < (UInt32(1) << 31) {
136136
trueIndex = trueIndex + (UInt32(1) << 31)
137137
}
138-
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha512)
138+
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
139139
var inputForHMAC = Data()
140140
inputForHMAC.append(Data([UInt8(0x00)]))
141141
inputForHMAC.append(self.privateKey!)
@@ -145,7 +145,7 @@ extension HDNode {
145145
entropy = ent
146146
} else {
147147
trueIndex = index
148-
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha512)
148+
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
149149
var inputForHMAC = Data()
150150
inputForHMAC.append(self.publicKey)
151151
inputForHMAC.append(trueIndex.serialize32())
@@ -203,7 +203,7 @@ extension HDNode {
203203
if index >= (UInt32(1) << 31) || hardened {
204204
return nil // no derivation of hardened public key from extended public key
205205
} else {
206-
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha512)
206+
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
207207
var inputForHMAC = Data()
208208
inputForHMAC.append(self.publicKey)
209209
inputForHMAC.append(index.serialize32())

Sources/web3swift/KeystoreManager/BIP32Keystore.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ public class BIP32Keystore: AbstractKeystore {
297297
var hashVariant: HMAC.Variant?;
298298
switch algo {
299299
case "hmac-sha256":
300-
hashVariant = HMAC.Variant.sha256
300+
hashVariant = HMAC.Variant.sha2(.sha256)
301301
case "hmac-sha384":
302-
hashVariant = HMAC.Variant.sha384
302+
hashVariant = HMAC.Variant.sha2(.sha384)
303303
case "hmac-sha512":
304-
hashVariant = HMAC.Variant.sha512
304+
hashVariant = HMAC.Variant.sha2(.sha512)
305305
default:
306306
hashVariant = nil
307307
}

Sources/web3swift/KeystoreManager/BIP39.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class BIP39 {
150150
guard let mnemData = mnemonics.decomposedStringWithCompatibilityMapping.data(using: .utf8) else {return nil}
151151
let salt = "mnemonic" + password
152152
guard let saltData = salt.decomposedStringWithCompatibilityMapping.data(using: .utf8) else {return nil}
153-
guard let seedArray = try? PKCS5.PBKDF2(password: mnemData.bytes, salt: saltData.bytes, iterations: 2048, keyLength: 64, variant: HMAC.Variant.sha512).calculate() else {return nil}
153+
guard let seedArray = try? PKCS5.PBKDF2(password: mnemData.bytes, salt: saltData.bytes, iterations: 2048, keyLength: 64, variant: HMAC.Variant.sha2(.sha512)).calculate() else {return nil}
154154
// let seed = Data(bytes:seedArray)
155155
let seed = Data(seedArray)
156156
return seed

Sources/web3swift/KeystoreManager/EthereumKeystoreV3.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ public class EthereumKeystoreV3: AbstractKeystore {
182182
var hashVariant: HMAC.Variant?;
183183
switch algo {
184184
case "hmac-sha256":
185-
hashVariant = HMAC.Variant.sha256
185+
hashVariant = HMAC.Variant.sha2(.sha256)
186186
case "hmac-sha384":
187-
hashVariant = HMAC.Variant.sha384
187+
hashVariant = HMAC.Variant.sha2(.sha384)
188188
case "hmac-sha512":
189-
hashVariant = HMAC.Variant.sha512
189+
hashVariant = HMAC.Variant.sha2(.sha512)
190190
default:
191191
hashVariant = nil
192192
}

0 commit comments

Comments
 (0)