UNPKG

1.48 kBMarkdownView Raw
1# HDKeys
2Create and derive extended public and private keys according to the BIP32 standard for Hierarchical Deterministic (HD) keys.
3
4## Hierarchically Derived Keys
5keyLib provides full support for [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki), allowing for many key management schemas that benefit from this property. Please be sure to read and understand the basic concepts and the warnings on that BIP before using these classes.
6
7## HDPrivateKey
8An instance of a [PrivateKey](privatekey.md) that also contains information required to derive child keys.
9
10Sample usage:
11
12```javascript
13var keyLib = require('@owstack/key-lib');
14var HDPrivateKey = keyLib.HDPrivateKey;
15
16var hdPrivateKey = new HDPrivateKey();
17var retrieved = new HDPrivateKey('xpriv...');
18var derived = hdPrivateKey.deriveChild("m/0'");
19var derivedByNumber = hdPrivateKey.deriveChild(1).deriveChild(2, true);
20var derivedByArgument = hdPrivateKey.deriveChild("m/1/2'");
21assert(derivedByNumber.xprivkey === derivedByArgument.xprivkey);
22
23// obtain HDPublicKey
24var hdPublicKey = hdPrivateKey.hdPublicKey;
25```
26
27## HDPublicKey
28An instance of a PublicKey that can be derived to build extended public keys. Note that hardened paths are not available when deriving an HDPublicKey.
29
30```javascript
31var hdPrivateKey = new HDPrivateKey();
32var hdPublicKey = hdPrivateKey.hdPublicKey;
33try {
34 new HDPublicKey();
35} catch(e) {
36 console.log("Can't generate a public key without a private key");
37}
38```