Skip to content

Commit 605ce5b

Browse files
committed
cleanup per PR comments
1 parent b5fb56a commit 605ce5b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

Sources/Web3Core/KeystoreManager/BIP32HDNode.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ extension UInt32 {
2222
}
2323

2424
public class HDNode {
25-
static var maxIterationIndex = UInt32(1) << 31
25+
private static var maxIterationIndex = UInt32(1) << 31
2626

2727
public struct HDversion {
2828
// swiftlint:disable force_unwrapping
29-
public var privatePrefix: Data = Data.fromHex("0x0488ADE4") ?? Data()
30-
public var publicPrefix: Data = Data.fromHex("0x0488B21E") ?? Data()
29+
public var privatePrefix: Data = Data.fromHex("0x0488ADE4")!
30+
public var publicPrefix: Data = Data.fromHex("0x0488B21E")!
3131
// swiftlint:enable force_unwrapping
3232
public init() {}
33-
public static var privatePrefix: Data {
33+
public static var privatePrefix: Data? {
3434
HDversion().privatePrefix
3535
}
36-
public static var publicPrefix: Data {
36+
public static var publicPrefix: Data? {
3737
HDversion().publicPrefix
3838
}
3939

@@ -49,11 +49,7 @@ public class HDNode {
4949
childNumber >= Self.maxIterationIndex
5050
}
5151
public var index: UInt32 {
52-
if self.isHardened {
53-
return childNumber - Self.maxIterationIndex
54-
} else {
55-
return childNumber
56-
}
52+
childNumber - (isHardened ? Self.maxIterationIndex : 0)
5753
}
5854
public var hasPrivate: Bool {
5955
privateKey != nil
@@ -101,7 +97,7 @@ public class HDNode {
10197
guard seed.count >= 16 else { return nil }
10298

10399
guard let hmacKey = "Bitcoin seed".data(using: .ascii) else { return nil }
104-
let hmac: Authenticator = HMAC(key: hmacKey.bytes, variant: HMAC.Variant.sha2(.sha512))
100+
let hmac = HMAC(key: hmacKey.bytes, variant: .sha2(.sha512))
105101

106102
guard let entropy = try? hmac.authenticate(seed.bytes), entropy.count == 64 else { return nil }
107103
let I_L = entropy[0..<32]

0 commit comments

Comments
 (0)