Skip to content

Commit 0a9b9b9

Browse files
committed
feat+doc: expose toPublic and document wipePrivateData
1 parent d2c2d56 commit 0a9b9b9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ However, production code will look more like this:
239239
RECEIVE, CHANGE
240240
async fromSeed(seedBytes, opts) // depth-0 hdkey (Wallet)
241241
async fromXKey(xprv||xpub, opts) // depth-4 hdkey (XKey)
242+
async toPublic(xKey)
243+
async wipePrivateData(xKey)
242244
async toWif(privBytes, opts)
243245
async toAddr(pubBytes, opts)
244246
async toXPrv(xprvKey, opts)
@@ -415,6 +417,22 @@ let xkey = await DashHd.fromXKey(xprvOrXPub, options);
415417
}
416418
```
417419
420+
### `toPublic(xkey)`
421+
422+
Creates a copy of the HD Key with `privateKey` set to `null`.
423+
424+
```js
425+
let xpubKey = await DashHd.toPublic(xprvKey);
426+
```
427+
428+
### `wipePrivateData(xkey)`
429+
430+
Performs an in-place secure erase of the private key memory.
431+
432+
```js
433+
await DashHd.wipePrivateData(xprvKey);
434+
```
435+
418436
### `toWif(privBytes, opts)`
419437
420438
Wrapper around `DashKeys.encodeKey(keyBytes, options)` to Base58Check-encode a

dashhd.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @prop {HDToXKeyBytes} toXPubBytes
1515
* @prop {HDUtils} utils
1616
* @prop {HDWipePrivates} wipePrivateData - randomizes private key buffer in-place
17+
* @prop {HDToPublic} toPublic - returns public key
1718
* @prop {Number} HARDENED_OFFSET - 0x80000000
1819
* @prop {HDVersions} MAINNET - 'xprv' & 'xpub'
1920
* @prop {HDVersions} TESTNET - 'tprv' & 'tpub'
@@ -651,6 +652,12 @@ var DashHd = ("object" === typeof module && exports) || {};
651652
return hdkey;
652653
};
653654

655+
DashHd.toPublic = function (_hdkey) {
656+
let hdkey = Object.assign({}, _hdkey);
657+
hdkey.privateKey = null;
658+
return hdkey;
659+
};
660+
654661
DashHd.wipePrivateData = function (hdkey) {
655662
if (hdkey.privateKey) {
656663
Utils.secureErase(hdkey.privateKey);
@@ -908,6 +915,12 @@ if ("object" === typeof module) {
908915
* @param {Uint8Array} buf
909916
*/
910917

918+
/**
919+
* @callback HDToPublic
920+
* @param {HDKey} hdkey
921+
* @returns {HDKey}
922+
*/
923+
911924
/**
912925
* @callback HDWipePrivates
913926
* @param {HDKey} hdkey

0 commit comments

Comments
 (0)