@@ -23,9 +23,19 @@ extension UInt32 {
23
23
24
24
public class HDNode {
25
25
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
+ }
29
39
30
40
}
31
41
public var path : String ? = " m "
@@ -231,16 +241,16 @@ extension HDNode {
231
241
newNode. publicKey = pubKeyCandidate
232
242
newNode. privateKey = privKeyCandidate
233
243
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 }
237
247
newNode. parentFingerprint = fprint
238
248
var newPath = String ( )
239
249
if newNode. isHardened {
240
- newPath = self . path! + " / "
250
+ newPath = path + " / "
241
251
newPath += String ( newNode. index % HDNode. hardenedIndexPrefix) + " ' "
242
252
} else {
243
- newPath = self . path! + " / " + String( newNode. index)
253
+ newPath = path + " / " + String( newNode. index)
244
254
}
245
255
newNode. path = newPath
246
256
return newNode
@@ -282,9 +292,9 @@ extension HDNode {
282
292
}
283
293
284
294
if serializePublic {
285
- data. append ( HDversion . publicPrefix! )
295
+ data. append ( HDversion . publicPrefix)
286
296
} else {
287
- data. append ( HDversion . privatePrefix! )
297
+ data. append ( HDversion . privatePrefix)
288
298
}
289
299
data. append ( contentsOf: [ self . depth] )
290
300
data. append ( self . parentFingerprint)
0 commit comments