Skip to content

Commit 0308f9b

Browse files
committed
PR request
1 parent 4cdd87c commit 0308f9b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Sources/Web3Core/KeystoreManager/BIP32HDNode.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ extension UInt32 {
1919
let byteArray = Array(bytePtr)
2020
return Data(byteArray)
2121
}
22-
static var maxIterationIndex = UInt32(1) << 31
2322
}
2423

2524
public class HDNode {
26-
25+
static var maxIterationIndex = UInt32(1) << 31
2726
private struct HDversion {
2827
public static var privatePrefix: Data? = Data.fromHex("0x0488ADE4")
2928
public static var publicPrefix: Data? = Data.fromHex("0x0488B21E")
@@ -37,11 +36,11 @@ public class HDNode {
3736
public var parentFingerprint: Data = Data(repeating: 0, count: 4)
3837
public var childNumber: UInt32 = UInt32(0)
3938
public var isHardened: Bool {
40-
childNumber >= UInt32.maxIterationIndex
39+
childNumber >= Self.maxIterationIndex
4140
}
4241
public var index: UInt32 {
4342
if self.isHardened {
44-
return childNumber - UInt32.maxIterationIndex
43+
return childNumber - Self.maxIterationIndex
4544
} else {
4645
return childNumber
4746
}
@@ -113,7 +112,7 @@ public class HDNode {
113112
public static var defaultPathPrefix: String = "m/44'/60'/0'"
114113
public static var defaultPathMetamask: String = "m/44'/60'/0'/0/0"
115114
public static var defaultPathMetamaskPrefix: String = "m/44'/60'/0'/0"
116-
public static var hardenedIndexPrefix: UInt32 = UInt32.maxIterationIndex
115+
public static var hardenedIndexPrefix: UInt32 { Self.maxIterationIndex }
117116
}
118117

119118
extension HDNode {
@@ -127,7 +126,7 @@ extension HDNode {
127126

128127
public func deriveWithoutPrivateKey(index: UInt32, hardened: Bool = false) -> HDNode? {
129128
var entropy: [UInt8] // derive public key when is itself public key
130-
if index >= UInt32.maxIterationIndex || hardened {
129+
if index >= Self.maxIterationIndex || hardened {
131130
return nil // no derivation of hardened public key from extended public key
132131
} else {
133132
let hmac: Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
@@ -181,10 +180,10 @@ extension HDNode {
181180
}
182181
var entropy: [UInt8]
183182
var trueIndex: UInt32
184-
if index >= UInt32.maxIterationIndex || hardened {
183+
if index >= Self.maxIterationIndex || hardened {
185184
trueIndex = index
186-
if trueIndex < UInt32.maxIterationIndex {
187-
trueIndex = trueIndex + UInt32.maxIterationIndex
185+
if trueIndex < Self.maxIterationIndex {
186+
trueIndex = trueIndex + Self.maxIterationIndex
188187
}
189188
let hmac: Authenticator = HMAC(key: self.chaincode.bytes, variant: .sha2(.sha512))
190189
var inputForHMAC = Data()

0 commit comments

Comments
 (0)