@@ -22,18 +22,18 @@ extension UInt32 {
22
22
}
23
23
24
24
public class HDNode {
25
- static var maxIterationIndex = UInt32 ( 1 ) << 31
25
+ private static var maxIterationIndex = UInt32 ( 1 ) << 31
26
26
27
27
public struct HDversion {
28
28
// 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 " ) !
31
31
// swiftlint:enable force_unwrapping
32
32
public init ( ) { }
33
- public static var privatePrefix : Data {
33
+ public static var privatePrefix : Data ? {
34
34
HDversion ( ) . privatePrefix
35
35
}
36
- public static var publicPrefix : Data {
36
+ public static var publicPrefix : Data ? {
37
37
HDversion ( ) . publicPrefix
38
38
}
39
39
@@ -49,11 +49,7 @@ public class HDNode {
49
49
childNumber >= Self . maxIterationIndex
50
50
}
51
51
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 )
57
53
}
58
54
public var hasPrivate : Bool {
59
55
privateKey != nil
@@ -101,7 +97,7 @@ public class HDNode {
101
97
guard seed. count >= 16 else { return nil }
102
98
103
99
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) )
105
101
106
102
guard let entropy = try ? hmac. authenticate ( seed. bytes) , entropy. count == 64 else { return nil }
107
103
let I_L = entropy [ 0 ..< 32 ]
0 commit comments