Skip to content

Fix warnings #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/web3swift/KeystoreManager/BIP32HDNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class HDNode {
public init?(seed: Data) {
guard seed.count >= 16 else {return nil}
let hmacKey = "Bitcoin seed".data(using: .ascii)!
let hmac:Authenticator = HMAC(key: hmacKey.bytes, variant: HMAC.Variant.sha512)
let hmac:Authenticator = HMAC(key: hmacKey.bytes, variant: HMAC.Variant.sha2(.sha512))
guard let entropy = try? hmac.authenticate(seed.bytes) else {return nil}
guard entropy.count == 64 else { return nil}
let I_L = entropy[0..<32]
Expand Down Expand Up @@ -135,7 +135,7 @@ extension HDNode {
if trueIndex < (UInt32(1) << 31) {
trueIndex = trueIndex + (UInt32(1) << 31)
}
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha512)
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
var inputForHMAC = Data()
inputForHMAC.append(Data([UInt8(0x00)]))
inputForHMAC.append(self.privateKey!)
Expand All @@ -145,7 +145,7 @@ extension HDNode {
entropy = ent
} else {
trueIndex = index
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha512)
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
var inputForHMAC = Data()
inputForHMAC.append(self.publicKey)
inputForHMAC.append(trueIndex.serialize32())
Expand Down Expand Up @@ -203,7 +203,7 @@ extension HDNode {
if index >= (UInt32(1) << 31) || hardened {
return nil // no derivation of hardened public key from extended public key
} else {
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha512)
let hmac:Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
var inputForHMAC = Data()
inputForHMAC.append(self.publicKey)
inputForHMAC.append(index.serialize32())
Expand Down
6 changes: 3 additions & 3 deletions Sources/web3swift/KeystoreManager/BIP32Keystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ public class BIP32Keystore: AbstractKeystore {
var hashVariant: HMAC.Variant?;
switch algo {
case "hmac-sha256":
hashVariant = HMAC.Variant.sha256
hashVariant = HMAC.Variant.sha2(.sha256)
case "hmac-sha384":
hashVariant = HMAC.Variant.sha384
hashVariant = HMAC.Variant.sha2(.sha384)
case "hmac-sha512":
hashVariant = HMAC.Variant.sha512
hashVariant = HMAC.Variant.sha2(.sha512)
default:
hashVariant = nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/web3swift/KeystoreManager/BIP39.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class BIP39 {
guard let mnemData = mnemonics.decomposedStringWithCompatibilityMapping.data(using: .utf8) else {return nil}
let salt = "mnemonic" + password
guard let saltData = salt.decomposedStringWithCompatibilityMapping.data(using: .utf8) else {return nil}
guard let seedArray = try? PKCS5.PBKDF2(password: mnemData.bytes, salt: saltData.bytes, iterations: 2048, keyLength: 64, variant: HMAC.Variant.sha512).calculate() else {return nil}
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}
// let seed = Data(bytes:seedArray)
let seed = Data(seedArray)
return seed
Expand Down
6 changes: 3 additions & 3 deletions Sources/web3swift/KeystoreManager/EthereumKeystoreV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public class EthereumKeystoreV3: AbstractKeystore {
var hashVariant: HMAC.Variant?;
switch algo {
case "hmac-sha256":
hashVariant = HMAC.Variant.sha256
hashVariant = HMAC.Variant.sha2(.sha256)
case "hmac-sha384":
hashVariant = HMAC.Variant.sha384
hashVariant = HMAC.Variant.sha2(.sha384)
case "hmac-sha512":
hashVariant = HMAC.Variant.sha512
hashVariant = HMAC.Variant.sha2(.sha512)
default:
hashVariant = nil
}
Expand Down