You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/Web3Core/KeystoreManager/BIP44.swift
+45-39Lines changed: 45 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -7,66 +7,72 @@ import Foundation
7
7
8
8
publicprotocolBIP44{
9
9
/**
10
-
Derive an `HDNode` based on the provided `path`. The function will throws `BIP44Error.warning` if it was invoked with `warns` as true and the root key doesn't have a previous child with at least one transaction, using false the child node will be derived directly not throwing. This function needs to query the blockchain history when `warns`is true, so it can throw network errors.
11
-
- Parameter path: valid BIP32 path.
12
-
- Parameter warns: true to be warned about following BIP44 standard, false otherwise.
13
-
- Throws: `BIP44Error.warning` if the child key shouldn't be used according to BIP44 standard.
14
-
- Returns: an HDNode child key for the provided `path` if it can be created, otherwise nil
10
+
Derive an ``HDNode`` based on the provided path. The function will throw ``BIP44Error.warning`` if it was invoked with throwOnError equal to`true` and the root key doesn't have a previous child with at least one transaction. If it is invoked with throwOnError equal to `false` the child node will be derived directly using the derive function of ``HDNode``. This function needs to query the blockchain history when throwOnError is `true`, so it can throw network errors.
11
+
- Parameter path: valid BIP44 path.
12
+
- Parameter throwOnError: `true` to use [Account Discovery](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery) standard, otherwise it will dervive the key using the derive function of ``HDNode``.
13
+
- Throws: ``BIP44Error.warning`` if the child key shouldn't be used according to [Account Discovery](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery) standard.
14
+
- Returns: an ``HDNode`` child key for the provided `path` if it can be created, otherwise `nil`
/// Verifies if current value matches BIP44 path standard
75
+
/// Verifies if self matches BIP44 path
70
76
varisBip44Path:Bool{
71
77
do{
72
78
letpattern="^m/44'/\\d+'/\\d+'/[0-1]/\\d+$"
@@ -78,7 +84,7 @@ extension String {
78
84
}
79
85
}
80
86
81
-
/// Returns the account from the path if the string contains a well formed BIP44 path
87
+
/// Returns the account from the path if self contains a well formed BIP44 path
82
88
varaccountFromPath:Int?{
83
89
guard isBip44Path else{
84
90
returnnil
@@ -93,10 +99,10 @@ extension String {
93
99
}
94
100
95
101
/**
96
-
Transforms a bip44 path into a new one changing `account` & `index`. The resulting one will have the change value equal to `0` to represent external chain. Format `m/44'/coin_type'/account'/change/address_index`
97
-
- Parameter account: the new `account` to use
98
-
- Parameter addressIndex: the new `addressIndex` to use
99
-
- Returns: a valid bip44 path with the provided `account`, `addressIndex`and external `change` or nil otherwise
102
+
Transforms a bip44 path into a new one changing account & index. The resulting one will have the change value equal to `0` to represent the external chain. The format will be `m/44'/coin_type'/account'/change/address_index`
103
+
- Parameter account: the new account to use
104
+
- Parameter addressIndex: the new addressIndex to use
105
+
- Returns: a valid bip44 path with the provided account, addressIndexand external change or `nil` otherwise
0 commit comments