@midnight-ntwrk/wallet-sdk-hd 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/HDWallet.d.ts +2 -1
- package/dist/HDWallet.js +9 -2
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
> [!IMPORTANT]
|
|
2
|
+
> **This package has moved.** The `@midnight-ntwrk` scope is published only
|
|
3
|
+
> during the migration window and will stop receiving updates. Please migrate to
|
|
4
|
+
> [`@midnightntwrk/wallet-sdk-hd`](https://www.npmjs.com/package/@midnightntwrk/wallet-sdk-hd).
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
1
8
|
# Midnight SDK HD Wallet
|
|
2
9
|
|
|
3
10
|
This package provides support for Hierarchical Deterministic (HD) Wallet.
|
package/dist/HDWallet.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ export declare class HDWallet {
|
|
|
40
40
|
static fromSeed(seed: Uint8Array): HDWalletResult;
|
|
41
41
|
selectAccount(account: number): AccountKey;
|
|
42
42
|
/**
|
|
43
|
-
* Once all keys are derived - clear internals from private data, so that they do not reside in memory longer than
|
|
43
|
+
* Once all keys are derived - clear internals from private data, so that they do not reside in memory longer than
|
|
44
|
+
* needed.
|
|
44
45
|
*/
|
|
45
46
|
clear(): void;
|
|
46
47
|
}
|
package/dist/HDWallet.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { HDKey } from '@scure/bip32';
|
|
13
|
+
import { HARDENED_OFFSET, HDKey } from '@scure/bip32';
|
|
14
14
|
export const Roles = {
|
|
15
15
|
NightExternal: 0,
|
|
16
16
|
NightInternal: 1,
|
|
@@ -20,6 +20,9 @@ export const Roles = {
|
|
|
20
20
|
};
|
|
21
21
|
const PURPOSE = 44;
|
|
22
22
|
const COIN_TYPE = 2400;
|
|
23
|
+
// BIP32 path components (account, role, index) are integers in [0, 2^31);
|
|
24
|
+
// @scure/bip32 inlines this check inside derive() and throws, so guard here
|
|
25
|
+
const isValidChildIndex = (value) => Number.isSafeInteger(value) && value >= 0 && value < HARDENED_OFFSET;
|
|
23
26
|
const CompositeDerivationResult = {
|
|
24
27
|
fromResults: (results) => {
|
|
25
28
|
const { succeededKeys, failedRoles } = results.reduce((acc, result) => {
|
|
@@ -58,7 +61,8 @@ export class HDWallet {
|
|
|
58
61
|
return new AccountKey(this.rootKey, account);
|
|
59
62
|
}
|
|
60
63
|
/**
|
|
61
|
-
* Once all keys are derived - clear internals from private data, so that they do not reside in memory longer than
|
|
64
|
+
* Once all keys are derived - clear internals from private data, so that they do not reside in memory longer than
|
|
65
|
+
* needed.
|
|
62
66
|
*/
|
|
63
67
|
clear() {
|
|
64
68
|
this.rootKey.wipePrivateData();
|
|
@@ -90,6 +94,9 @@ export class RoleKey {
|
|
|
90
94
|
}
|
|
91
95
|
// Finally, derive the key at the given index.
|
|
92
96
|
deriveKeyAt(index) {
|
|
97
|
+
if (![this.account, this.role, index].every(isValidChildIndex)) {
|
|
98
|
+
return { type: 'keyOutOfBounds' };
|
|
99
|
+
}
|
|
93
100
|
const path = `m/${PURPOSE}'/${COIN_TYPE}'/${this.account}'/${this.role}/${index}`;
|
|
94
101
|
const derivedKey = this.rootKey.derive(path);
|
|
95
102
|
return derivedKey.privateKey ? { type: 'keyDerived', key: derivedKey.privateKey } : { type: 'keyOutOfBounds' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-hd",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
"author": "Midnight Foundation",
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"publishConfig": {
|
|
11
|
-
"registry": "https://
|
|
11
|
+
"registry": "https://registry.npmjs.org/",
|
|
12
|
+
"access": "public"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
15
|
"dist/"
|
|
15
16
|
],
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/midnight-
|
|
19
|
+
"url": "git+https://github.com/midnightntwrk/midnight-wallet.git",
|
|
20
|
+
"directory": "packages/hd"
|
|
19
21
|
},
|
|
20
22
|
"exports": {
|
|
21
23
|
".": {
|
|
@@ -28,7 +30,7 @@
|
|
|
28
30
|
"@scure/bip39": "^2.0.1"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"@ethereumjs/wallet": "
|
|
33
|
+
"@ethereumjs/wallet": "10.0.0"
|
|
32
34
|
},
|
|
33
35
|
"scripts": {
|
|
34
36
|
"typecheck": "tsc -b ./tsconfig.json --noEmit --force",
|