Skip to content

Commit 40d3477

Browse files
committed
revert per PR comments
1 parent 0308f9b commit 40d3477

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Sources/Web3Core/KeystoreManager/BIP32HDNode.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ extension UInt32 {
2323

2424
public class HDNode {
2525
static var maxIterationIndex = UInt32(1) << 31
26-
private struct HDversion {
27-
public static var privatePrefix: Data? = Data.fromHex("0x0488ADE4")
28-
public static var publicPrefix: Data? = Data.fromHex("0x0488B21E")
26+
27+
public struct HDversion {
28+
// swiftlint:disable force_unwrapping
29+
public var privatePrefix: Data = Data.fromHex("0x0488ADE4") ?? Data()
30+
public var publicPrefix: Data = Data.fromHex("0x0488B21E") ?? Data()
31+
// swiftlint:enable force_unwrapping
32+
public init() {}
33+
public static var privatePrefix: Data {
34+
HDversion().privatePrefix
35+
}
36+
public static var publicPrefix: Data {
37+
HDversion().publicPrefix
38+
}
2939

3040
}
3141
public var path: String? = "m"
@@ -231,16 +241,16 @@ extension HDNode {
231241
newNode.publicKey = pubKeyCandidate
232242
newNode.privateKey = privKeyCandidate
233243
newNode.childNumber = trueIndex
234-
guard let fprint = try? RIPEMD160.hash(message: self.publicKey.sha256())[0..<4] else {
235-
return nil
236-
}
244+
guard let fprint = try? RIPEMD160.hash(message: self.publicKey.sha256())[0..<4],
245+
let path = path
246+
else { return nil }
237247
newNode.parentFingerprint = fprint
238248
var newPath = String()
239249
if newNode.isHardened {
240-
newPath = self.path! + "/"
250+
newPath = path + "/"
241251
newPath += String(newNode.index % HDNode.hardenedIndexPrefix) + "'"
242252
} else {
243-
newPath = self.path! + "/" + String(newNode.index)
253+
newPath = path + "/" + String(newNode.index)
244254
}
245255
newNode.path = newPath
246256
return newNode
@@ -282,9 +292,9 @@ extension HDNode {
282292
}
283293

284294
if serializePublic {
285-
data.append(HDversion.publicPrefix!)
295+
data.append(HDversion.publicPrefix)
286296
} else {
287-
data.append(HDversion.privatePrefix!)
297+
data.append(HDversion.privatePrefix)
288298
}
289299
data.append(contentsOf: [self.depth])
290300
data.append(self.parentFingerprint)

0 commit comments

Comments
 (0)