@metamask-previews/key-tree 0.0.0-stage → 10.1.1-preview-4dd847ca3
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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +163 -2
- package/dist/BIP44CoinTypeNode.d.ts +244 -0
- package/dist/BIP44CoinTypeNode.d.ts.map +1 -0
- package/dist/BIP44CoinTypeNode.js +365 -0
- package/dist/BIP44CoinTypeNode.js.map +1 -0
- package/dist/BIP44Node.d.ts +220 -0
- package/dist/BIP44Node.d.ts.map +1 -0
- package/dist/BIP44Node.js +327 -0
- package/dist/BIP44Node.js.map +1 -0
- package/dist/SLIP10Node.d.ts +310 -0
- package/dist/SLIP10Node.d.ts.map +1 -0
- package/dist/SLIP10Node.js +443 -0
- package/dist/SLIP10Node.js.map +1 -0
- package/dist/constants.d.ts +132 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +39 -0
- package/dist/constants.js.map +1 -0
- package/dist/cryptography.d.ts +81 -0
- package/dist/cryptography.d.ts.map +1 -0
- package/dist/cryptography.js +112 -0
- package/dist/cryptography.js.map +1 -0
- package/dist/curves/curve.d.ts +40 -0
- package/dist/curves/curve.d.ts.map +1 -0
- package/dist/curves/curve.js +19 -0
- package/dist/curves/curve.js.map +1 -0
- package/dist/curves/ed25519.d.ts +14 -0
- package/dist/curves/ed25519.d.ts.map +1 -0
- package/dist/curves/ed25519.js +40 -0
- package/dist/curves/ed25519.js.map +1 -0
- package/dist/curves/ed25519Bip32.d.ts +68 -0
- package/dist/curves/ed25519Bip32.d.ts.map +1 -0
- package/dist/curves/ed25519Bip32.js +122 -0
- package/dist/curves/ed25519Bip32.js.map +1 -0
- package/dist/curves/index.d.ts +5 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +5 -0
- package/dist/curves/index.js.map +1 -0
- package/dist/curves/secp256k1.d.ts +14 -0
- package/dist/curves/secp256k1.d.ts.map +1 -0
- package/dist/curves/secp256k1.js +51 -0
- package/dist/curves/secp256k1.js.map +1 -0
- package/dist/derivation.d.ts +65 -0
- package/dist/derivation.d.ts.map +1 -0
- package/dist/derivation.js +143 -0
- package/dist/derivation.js.map +1 -0
- package/dist/derivers/bip32.d.ts +40 -0
- package/dist/derivers/bip32.d.ts.map +1 -0
- package/dist/derivers/bip32.js +100 -0
- package/dist/derivers/bip32.js.map +1 -0
- package/dist/derivers/bip39.d.ts +93 -0
- package/dist/derivers/bip39.d.ts.map +1 -0
- package/dist/derivers/bip39.js +209 -0
- package/dist/derivers/bip39.js.map +1 -0
- package/dist/derivers/cip3.d.ts +167 -0
- package/dist/derivers/cip3.d.ts.map +1 -0
- package/dist/derivers/cip3.js +285 -0
- package/dist/derivers/cip3.js.map +1 -0
- package/dist/derivers/index.d.ts +33 -0
- package/dist/derivers/index.d.ts.map +1 -0
- package/dist/derivers/index.js +12 -0
- package/dist/derivers/index.js.map +1 -0
- package/dist/derivers/shared.d.ts +152 -0
- package/dist/derivers/shared.d.ts.map +1 -0
- package/dist/derivers/shared.js +354 -0
- package/dist/derivers/shared.js.map +1 -0
- package/dist/derivers/slip10.d.ts +14 -0
- package/dist/derivers/slip10.d.ts.map +1 -0
- package/dist/derivers/slip10.js +53 -0
- package/dist/derivers/slip10.js.map +1 -0
- package/dist/extended-keys.d.ts +40 -0
- package/dist/extended-keys.d.ts.map +1 -0
- package/dist/extended-keys.js +134 -0
- package/dist/extended-keys.js.map +1 -0
- package/dist/guard.d.ts +8 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +8 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +234 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +379 -0
- package/dist/utils.js.map +1 -0
- package/package.json +71 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **BREAKING:** Drop CommonJS support ([#11361](https://github.com/MetaMask/core/pull/11361))
|
|
13
|
+
- The package is now ESM-only. The `require` export condition and the `main`, `module`, and `types` fields are removed, and `exports` only has `types` and `default` conditions.
|
|
14
|
+
- Consumers that load this package with `require()` must switch to `import`, or use a Node.js version that supports `require(esm)`.
|
|
15
|
+
- **BREAKING:** Bump minimum supported Node.js version to `^22.14.0 || ^24 || ^26` ([#11361](https://github.com/MetaMask/core/pull/11361))
|
|
16
|
+
- **BREAKING:** Compile to `ES2022` instead of `ES2020` ([#11360](https://github.com/MetaMask/core/pull/11360))
|
|
17
|
+
- Consumers that bundle this package for environments that do not support `ES2022` must transpile it.
|
|
18
|
+
- Replace the `@metamask/utils` dependency with `@metamask/byte-utils` and `@metamask/type-utils` ([#11361](https://github.com/MetaMask/core/pull/11361))
|
|
19
|
+
- Bump `@noble/curves` from `^1.8.1` to `^1.9.7`, `@noble/hashes` from `^1.3.2` to `^1.8.0`, and `@scure/base` from `^1.0.0` to `^1.2.6` ([#11361](https://github.com/MetaMask/core/pull/11361))
|
|
20
|
+
- This package was migrated from `MetaMask/key-tree` to the `MetaMask/core` monorepo ([#11354](https://github.com/MetaMask/core/pull/11354))
|
|
21
|
+
- See [`MetaMask/key-tree`](https://github.com/MetaMask/key-tree/blob/742c995fa27144d038941df5bddbc7351ee0e8ff/CHANGELOG.md) for the original changelog.
|
|
22
|
+
|
|
23
|
+
[Unreleased]: https://github.com/MetaMask/core/
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @metamask/key-tree
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An interface over [SLIP-10], [BIP-32], and [BIP-44] key derivation paths.
|
|
4
|
+
|
|
5
|
+
This library was audited by Cure53 in February 2023, and April 2024. The audit reports can be found [here](./audits).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
`yarn add @metamask/key-tree`
|
|
10
|
+
|
|
11
|
+
or
|
|
12
|
+
|
|
13
|
+
`npm install @metamask/key-tree`
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
This package is designed to accommodate the creation of keys for any level of a [SLIP-10] or [BIP-44] path.
|
|
18
|
+
Recall that a [BIP-44] HD tree path consists of the following nodes (and depths):
|
|
19
|
+
|
|
20
|
+
> `m / 44' / coin_type' / account' / change / address_index`
|
|
21
|
+
>
|
|
22
|
+
> `0 / 1 / 2 / 3 / 4 / 5`
|
|
23
|
+
|
|
24
|
+
Where `m` is the "master" or seed node, `coin_type` indicates the protocol for which deeper keys are intended,
|
|
25
|
+
and `address_index` usually furnishes key pairs intended for user addresses / accounts.
|
|
26
|
+
For details, refer to the [BIP-44] specification.
|
|
27
|
+
For the authoritative list of protocol `coin_type` indices, see [SLIP-44].
|
|
28
|
+
|
|
29
|
+
The [SLIP-10] interface provides a more generic way for deriving keys, which is not constrained to the [BIP-44] path
|
|
30
|
+
nodes. Currently only Secp256k1 and Ed25519 are supported for [SLIP-10], but NIST P-256 may be added if there is
|
|
31
|
+
sufficient demand for it.
|
|
32
|
+
|
|
33
|
+
This package exports a few classes intended to facilitate the creation of keys in contexts with different privileges.
|
|
34
|
+
They are used as follows.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { BIP44CoinTypeNode } from '@metamask/key-tree';
|
|
38
|
+
|
|
39
|
+
// Per SLIP-44, Ethereum has a coin_type of 60.
|
|
40
|
+
// Ethereum is only used by way of example.
|
|
41
|
+
const coinType = 60;
|
|
42
|
+
|
|
43
|
+
// Imagine that this takes place in some privileged context with access to
|
|
44
|
+
// the user's secret recovery phrase.
|
|
45
|
+
const secretRecoveryPhrase = getSecretRecoveryPhrase();
|
|
46
|
+
|
|
47
|
+
const coinTypeNode = await BIP44CoinTypeNode.fromDerivationPath([
|
|
48
|
+
`bip39:${secretRecoveryPhrase}`,
|
|
49
|
+
`bip32:44'`, // By BIP-44, the "purpose" node must be "44'"
|
|
50
|
+
`bip32:${coinType}'`,
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
// Imagine that this is some Node.js stream, but it could be anything that
|
|
54
|
+
// can transmit JSON messages, such as window.postMessage.
|
|
55
|
+
// Alternatively you can use `coinTypeNode.extendedKey` as well.
|
|
56
|
+
stream.write(coinTypeNode.toJSON());
|
|
57
|
+
|
|
58
|
+
//===============================
|
|
59
|
+
// Then, on the receiving end...
|
|
60
|
+
//===============================
|
|
61
|
+
|
|
62
|
+
import { getBIP44AddressKeyDeriver } from '@metamask/key-tree';
|
|
63
|
+
|
|
64
|
+
// Get the node sent from the privileged context.
|
|
65
|
+
// It will have the following shape:
|
|
66
|
+
// {
|
|
67
|
+
// privateKey, // A hexadecimal string of the private key
|
|
68
|
+
// publicKey, // A hexadecimal string of the public key
|
|
69
|
+
// chainCode, // A hexadecimal string of the chain code
|
|
70
|
+
// depth, // The number 2, which is the depth of coin_type nodes
|
|
71
|
+
// parentFingerprint, // The fingerprint of the parent node as number
|
|
72
|
+
// index, // The index of the node as number
|
|
73
|
+
// coin_type, // In this case, the number 60
|
|
74
|
+
// path, // For visualization only. In this case: m / 44' / 60'
|
|
75
|
+
// }
|
|
76
|
+
const coinTypeNode = await getCoinTypeNode();
|
|
77
|
+
|
|
78
|
+
// Get an address key deriver for the coin_type node.
|
|
79
|
+
// In this case, its path will be: m / 44' / 60' / 0' / 0 / address_index
|
|
80
|
+
// Alternatively you can use an extended key (`xprv`) as well.
|
|
81
|
+
const addressKeyDeriver = getBIP44AddressKeyDeriver(coinTypeNode);
|
|
82
|
+
|
|
83
|
+
// These are Uint8Array representations of the extended private keys for
|
|
84
|
+
// the respective addresses.
|
|
85
|
+
|
|
86
|
+
// m / 44' / 60' / 0' / 0 / 0
|
|
87
|
+
const addressKey0 = await addressKeyDeriver(0);
|
|
88
|
+
|
|
89
|
+
// m / 44' / 60' / 0' / 0 / 1
|
|
90
|
+
const addressKey1 = await addressKeyDeriver(1);
|
|
91
|
+
|
|
92
|
+
// m / 44' / 60' / 0' / 0 / 2'
|
|
93
|
+
const addressKey2 = await addressKeyDeriver(2, true);
|
|
94
|
+
|
|
95
|
+
// Now, the extended private keys can be used to derive the corresponding public
|
|
96
|
+
// keys and protocol addresses.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
You can derive SLIP-10 keys as follows.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { SLIP10Node } from '@metamask/key-tree';
|
|
103
|
+
|
|
104
|
+
// Create a SLIP10Node from a derivation path. You can also specify a key and depth instead.
|
|
105
|
+
const node = await SLIP10Node.fromDerivationPath({
|
|
106
|
+
curve: 'secp256k1',
|
|
107
|
+
derivationPath: [`bip39:${secretRecoveryPhrase}`, `slip10:0'`],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// SLIP-10 supports Ed25519 as well.
|
|
111
|
+
const ed25519Node = await SLIP10Node.fromDerivationPath({
|
|
112
|
+
curve: 'ed25519',
|
|
113
|
+
derivationPath: [`bip39:${secretRecoveryPhrase}`, `slip10:0'`],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Derive the child node at m / 0' / 1' / 2'. This results in a new SLIP10Node.
|
|
117
|
+
// Note that you cannot derive unhardened child nodes when using Ed25519.
|
|
118
|
+
const childNode = await node.derive([`slip10:1'`, `slip10:2'`]);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The `SLIP10Node` class supports both `bip32:` and `slip10:` paths. While [BIP-32] and [SLIP-10] are mostly compatible with
|
|
122
|
+
each other, there are some differences:
|
|
123
|
+
|
|
124
|
+
- Ed25519 is only supported by [SLIP-10], so you must use `slip10:` paths when deriving Ed25519 keys.
|
|
125
|
+
- Key derivation errors (i.e., invalid keys being derived) are handled slightly different. While the chance of
|
|
126
|
+
encountering such an error is extremely low, it is possible.
|
|
127
|
+
|
|
128
|
+
If you require full compatibility with one or the other, you can choose between the `bip32:` and `slip10:` path types.
|
|
129
|
+
|
|
130
|
+
There are other ways of deriving keys in addition to the above example.
|
|
131
|
+
See the docstrings in the [BIP44Node](./src/BIP44Node.ts), [BIP44CoinTypeNode](./src/BIP44CoinTypeNode.ts) and
|
|
132
|
+
[SLIP10Node](./src/SLIP10Node.ts) files for details.
|
|
133
|
+
|
|
134
|
+
### Internals
|
|
135
|
+
|
|
136
|
+
This package also has methods for deriving arbitrary [SLIP-10] and [BIP-32] keys, and generating seeds from [BIP-39]
|
|
137
|
+
secret recovery phrases.
|
|
138
|
+
These methods do not constitute a safe key derivation API, and their use is **strongly discouraged**.
|
|
139
|
+
Nevertheless, since those methods were the main exports of this package prior to version `3.0.0`, consumers can
|
|
140
|
+
still access them by importing `@metamask/key-tree/derivation`.
|
|
141
|
+
|
|
142
|
+
## Security
|
|
143
|
+
|
|
144
|
+
This package is rigorously tested against reference implementations and the [SLIP-10] and [BIP-32] specifications.
|
|
145
|
+
See the [reference implementation tests](tests/reference-implementations.test.ts) for details.
|
|
146
|
+
|
|
147
|
+
## Further Reading
|
|
148
|
+
|
|
149
|
+
- [BIP-32]
|
|
150
|
+
- [BIP-39]
|
|
151
|
+
- [BIP-44]
|
|
152
|
+
- [SLIP-10]
|
|
153
|
+
- [SLIP-44]
|
|
154
|
+
- Network Working Group: ["Key Derivation Functions and their Uses"](https://trac.tools.ietf.org/html/draft-irtf-cfrg-kdf-uses-00)
|
|
155
|
+
|
|
156
|
+
## Contributing
|
|
157
|
+
|
|
158
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
|
159
|
+
|
|
160
|
+
[bip-32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
|
161
|
+
[bip-39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
|
|
162
|
+
[bip-44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
|
|
163
|
+
[slip-10]: https://github.com/satoshilabs/slips/blob/master/slip-0010.md
|
|
164
|
+
[slip-44]: https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { BIP44NodeInterface, JsonBIP44Node } from './BIP44Node.js';
|
|
2
|
+
import { BIP44Node } from './BIP44Node.js';
|
|
3
|
+
import type { BIP39Node, BIP44Depth, BIP44PurposeNodeToken, CoinTypeHDPathString, HardenedBIP32Node, Network } from './constants.js';
|
|
4
|
+
import type { CryptographicFunctions } from './cryptography.js';
|
|
5
|
+
import type { SupportedCurve } from './curves/index.js';
|
|
6
|
+
import type { CoinTypeToAddressIndices } from './utils.js';
|
|
7
|
+
import { getBIP44ChangePathString } from './utils.js';
|
|
8
|
+
export type CoinTypeHDPathTuple = [
|
|
9
|
+
BIP39Node,
|
|
10
|
+
typeof BIP44PurposeNodeToken,
|
|
11
|
+
HardenedBIP32Node
|
|
12
|
+
];
|
|
13
|
+
export type CoinTypeSeedPathTuple = [
|
|
14
|
+
Uint8Array,
|
|
15
|
+
typeof BIP44PurposeNodeToken,
|
|
16
|
+
HardenedBIP32Node
|
|
17
|
+
];
|
|
18
|
+
export declare const BIP_44_COIN_TYPE_DEPTH = 2;
|
|
19
|
+
export type JsonBIP44CoinTypeNode = JsonBIP44Node & {
|
|
20
|
+
readonly coin_type: number;
|
|
21
|
+
readonly path: CoinTypeHDPathString;
|
|
22
|
+
};
|
|
23
|
+
export type BIP44CoinTypeNodeInterface = BIP44NodeInterface & {
|
|
24
|
+
readonly coin_type: number;
|
|
25
|
+
readonly path: CoinTypeHDPathString;
|
|
26
|
+
};
|
|
27
|
+
export type BIP44CoinTypeSeedOptions = {
|
|
28
|
+
readonly derivationPath: CoinTypeSeedPathTuple;
|
|
29
|
+
readonly network?: Network | undefined;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A wrapper object for BIP-44 `coin_type` keys. `coin_type` is the index
|
|
33
|
+
* specifying the protocol for which deeper keys are intended. For the
|
|
34
|
+
* authoritative list of coin types, please see
|
|
35
|
+
* [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).
|
|
36
|
+
*
|
|
37
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
38
|
+
*
|
|
39
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
40
|
+
*
|
|
41
|
+
* With the following depths:
|
|
42
|
+
*
|
|
43
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
export declare class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
|
|
47
|
+
#private;
|
|
48
|
+
/**
|
|
49
|
+
* Constructs a BIP-44 `coin_type` node. `coin_type` is the index
|
|
50
|
+
* specifying the protocol for which deeper keys are intended. For the
|
|
51
|
+
* authoritative list of coin types, please see
|
|
52
|
+
* [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).
|
|
53
|
+
*
|
|
54
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
55
|
+
*
|
|
56
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
57
|
+
*
|
|
58
|
+
* With the following depths:
|
|
59
|
+
*
|
|
60
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
61
|
+
*
|
|
62
|
+
* @param json - The {@link JsonBIP44Node} for the key of this node.
|
|
63
|
+
* @param coin_type - The coin_type index of this node. Must be a non-negative
|
|
64
|
+
* integer.
|
|
65
|
+
* @param cryptographicFunctions - The cryptographic functions to use. If
|
|
66
|
+
* provided, these will be used instead of the built-in implementations.
|
|
67
|
+
* @returns A BIP44CoinType node.
|
|
68
|
+
*/
|
|
69
|
+
static fromJSON(json: JsonBIP44Node, coin_type: number, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode>;
|
|
70
|
+
/**
|
|
71
|
+
* Construct a BIP-44 `coin_type` node. `coin_type` is the index
|
|
72
|
+
* specifying the protocol for which deeper keys are intended. For the
|
|
73
|
+
* authoritative list of coin types, please see
|
|
74
|
+
* [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).
|
|
75
|
+
*
|
|
76
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
77
|
+
*
|
|
78
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
79
|
+
*
|
|
80
|
+
* With the following depths:
|
|
81
|
+
*
|
|
82
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
83
|
+
*
|
|
84
|
+
* @param derivationPath - The derivation path for the key of this node.
|
|
85
|
+
* @param network - The network for the node. This is only used for extended
|
|
86
|
+
* keys, and defaults to `mainnet`.
|
|
87
|
+
* @param cryptographicFunctions - The cryptographic functions to use. If
|
|
88
|
+
* provided, these will be used instead of the built-in implementations.
|
|
89
|
+
* @returns A BIP44CoinType node.
|
|
90
|
+
*/
|
|
91
|
+
static fromDerivationPath(derivationPath: CoinTypeHDPathTuple, network?: Network | undefined, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode>;
|
|
92
|
+
/**
|
|
93
|
+
* Create a new BIP-44 coin type node from a BIP-39 seed. The derivation path
|
|
94
|
+
* must be rooted, i.e. it must begin with a BIP-39 node, given as a
|
|
95
|
+
* `Uint8Array` of the seed bytes.
|
|
96
|
+
*
|
|
97
|
+
* All parameters are stringently validated, and an error is thrown if
|
|
98
|
+
* validation fails.
|
|
99
|
+
*
|
|
100
|
+
* @param options - The options for the new node.
|
|
101
|
+
* @param options.derivationPath - The rooted HD tree path that will be used
|
|
102
|
+
* to derive the key of this node.
|
|
103
|
+
* @param options.network - The network for the node. This is only used for
|
|
104
|
+
* extended keys, and defaults to `mainnet`.
|
|
105
|
+
* @param cryptographicFunctions - The cryptographic functions to use. If
|
|
106
|
+
* provided, these will be used instead of the built-in implementations.
|
|
107
|
+
* @returns A new BIP-44 node.
|
|
108
|
+
*/
|
|
109
|
+
static fromSeed({ derivationPath, network }: BIP44CoinTypeSeedOptions, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode>;
|
|
110
|
+
/**
|
|
111
|
+
* Constructs a BIP-44 `coin_type` node. `coin_type` is the index
|
|
112
|
+
* specifying the protocol for which deeper keys are intended. For the
|
|
113
|
+
* authoritative list of coin types, please see
|
|
114
|
+
* [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).
|
|
115
|
+
*
|
|
116
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
117
|
+
*
|
|
118
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
119
|
+
*
|
|
120
|
+
* With the following depths:
|
|
121
|
+
*
|
|
122
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
123
|
+
*
|
|
124
|
+
* @param node - The {@link BIP44Node} for the key of this node.
|
|
125
|
+
* @param coin_type - The coin_type index of this node. Must be a non-negative
|
|
126
|
+
* integer.
|
|
127
|
+
* @returns A BIP44CoinType node.
|
|
128
|
+
*/
|
|
129
|
+
static fromNode(node: BIP44Node, coin_type: number): Promise<BIP44CoinTypeNode>;
|
|
130
|
+
readonly path: CoinTypeHDPathString;
|
|
131
|
+
readonly coin_type: number;
|
|
132
|
+
private constructor();
|
|
133
|
+
get depth(): BIP44Depth;
|
|
134
|
+
get privateKeyBytes(): Uint8Array | undefined;
|
|
135
|
+
get publicKeyBytes(): Uint8Array;
|
|
136
|
+
get chainCodeBytes(): Uint8Array;
|
|
137
|
+
get privateKey(): string | undefined;
|
|
138
|
+
get publicKey(): string;
|
|
139
|
+
get compressedPublicKey(): string;
|
|
140
|
+
get compressedPublicKeyBytes(): Uint8Array;
|
|
141
|
+
get chainCode(): string;
|
|
142
|
+
get address(): string;
|
|
143
|
+
get masterFingerprint(): number | undefined;
|
|
144
|
+
get parentFingerprint(): number;
|
|
145
|
+
get fingerprint(): number;
|
|
146
|
+
get index(): number;
|
|
147
|
+
get network(): Network;
|
|
148
|
+
get curve(): SupportedCurve;
|
|
149
|
+
get extendedKey(): string;
|
|
150
|
+
/**
|
|
151
|
+
* Derives a BIP-44 `address_index` key corresponding to the path of this
|
|
152
|
+
* node and the specified `account`, `change`, and `address_index` values.
|
|
153
|
+
* `address_index` keys are normally the keys used to generate user account
|
|
154
|
+
* addresses.
|
|
155
|
+
*
|
|
156
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
157
|
+
*
|
|
158
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
159
|
+
*
|
|
160
|
+
* With the following depths:
|
|
161
|
+
*
|
|
162
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
163
|
+
*
|
|
164
|
+
* @param indices - The BIP-44 index values to use in key derivation.
|
|
165
|
+
* @param indices.account - The `account` index. Default: `0`
|
|
166
|
+
* @param indices.change - The `change` index. Default: `0`
|
|
167
|
+
* @param indices.address_index - The `address_index` index.
|
|
168
|
+
* @returns The derived BIP-44 `address_index` node.
|
|
169
|
+
*/
|
|
170
|
+
deriveBIP44AddressKey({ account, change, address_index, }: CoinTypeToAddressIndices): Promise<BIP44Node>;
|
|
171
|
+
toJSON(): JsonBIP44CoinTypeNode;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Derives a BIP-44 address key corresponding to the specified derivation path,
|
|
175
|
+
* given either by a {@link BIP44CoinTypeNode} or derivation path tuple.
|
|
176
|
+
*
|
|
177
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
178
|
+
*
|
|
179
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
180
|
+
*
|
|
181
|
+
* With the following depths:
|
|
182
|
+
*
|
|
183
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
184
|
+
*
|
|
185
|
+
* @param parentKeyOrNode - The `coin_type` parent key to derive from.
|
|
186
|
+
* @param indices - The BIP-44 index values to use in key derivation.
|
|
187
|
+
* @param indices.account - The `account` index. Default: `0`.
|
|
188
|
+
* @param indices.change - The `change` index. Default: `0`.
|
|
189
|
+
* @param indices.address_index - The `address_index` index.
|
|
190
|
+
* @param cryptographicFunctions - The cryptographic functions to use. If
|
|
191
|
+
* provided, these will be used instead of the built-in implementations.
|
|
192
|
+
* @returns The derived `address_index` key for the specified derivation path.
|
|
193
|
+
*/
|
|
194
|
+
export declare function deriveBIP44AddressKey(parentKeyOrNode: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string, { account, change, address_index }: CoinTypeToAddressIndices, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44Node>;
|
|
195
|
+
export type BIP44AddressKeyDeriver = {
|
|
196
|
+
/**
|
|
197
|
+
* @param address_index - The `address_index` value.
|
|
198
|
+
* @param isHardened - Whether the derived index is hardened.
|
|
199
|
+
* @returns The key corresponding to the path of this deriver and the
|
|
200
|
+
* specified `address_index` value.
|
|
201
|
+
*/
|
|
202
|
+
(address_index: number, isHardened?: boolean): Promise<BIP44Node>;
|
|
203
|
+
/**
|
|
204
|
+
* A human-readable representation of the derivation path of this deriver
|
|
205
|
+
* function, excluding the `address_index`, which is parameterized.
|
|
206
|
+
*
|
|
207
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
208
|
+
*
|
|
209
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
210
|
+
*
|
|
211
|
+
* With the following depths:
|
|
212
|
+
*
|
|
213
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
214
|
+
*/
|
|
215
|
+
path: ReturnType<typeof getBIP44ChangePathString>;
|
|
216
|
+
/**
|
|
217
|
+
* The `coin_type` index of addresses derived by this deriver function.
|
|
218
|
+
*/
|
|
219
|
+
coin_type: number;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Creates a function that derives BIP-44 address keys corresponding to the
|
|
223
|
+
* specified derivation path, given either by a {@link BIP44CoinTypeNode} or
|
|
224
|
+
* derivation path tuple.
|
|
225
|
+
*
|
|
226
|
+
* Recall that a BIP-44 HD tree path consists of the following nodes:
|
|
227
|
+
*
|
|
228
|
+
* `m / 44' / coin_type' / account' / change / address_index`
|
|
229
|
+
*
|
|
230
|
+
* With the following depths:
|
|
231
|
+
*
|
|
232
|
+
* `0 / 1 / 2 / 3 / 4 / 5`
|
|
233
|
+
*
|
|
234
|
+
* @param node - The {@link BIP44CoinTypeNode} to derive address keys from.
|
|
235
|
+
* This node contains a BIP-44 key of depth 2, `coin_type`.
|
|
236
|
+
* @param accountAndChangeIndices - The `account` and `change` indices that
|
|
237
|
+
* will be used to derive addresses.
|
|
238
|
+
* @param cryptographicFunctions - The cryptographic functions to use. If
|
|
239
|
+
* provided, these will be used instead of the built-in implementations.
|
|
240
|
+
* @returns The deriver function for the derivation path specified by the
|
|
241
|
+
* `coin_type` node, `account`, and `change` indices.
|
|
242
|
+
*/
|
|
243
|
+
export declare function getBIP44AddressKeyDeriver(node: BIP44CoinTypeNode | JsonBIP44CoinTypeNode | string, accountAndChangeIndices?: Omit<CoinTypeToAddressIndices, 'address_index'>, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44AddressKeyDeriver>;
|
|
244
|
+
//# sourceMappingURL=BIP44CoinTypeNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BIP44CoinTypeNode.d.ts","sourceRoot":"","sources":["../src/BIP44CoinTypeNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,OAAO,EACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAGL,wBAAwB,EAOzB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS;IACT,OAAO,qBAAqB;IAC5B,iBAAiB;CAClB,CA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