Skip to content

Commit d822776

Browse files
author
AJ ONeal
committed
fix: pass XKey version to DashKeys, update comments
1 parent 2a77353 commit d822776

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

dashhd.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,19 @@ var DashHd = ("object" === typeof module && exports) || {};
100100

101101
/**
102102
* @param {Uint8Array} keyBytes
103-
* TODO - pass tprv
103+
* @param {Object} opts
104+
* @param {Number} [opts.version]
104105
*/
105-
Utils.encodeXPrv = async function (keyBytes) {
106+
Utils.encodeXPrv = async function (keyBytes, opts) {
106107
//@ts-ignore - wth?
107108
let DashKeys = window.DashKeys || require("dashkeys");
109+
let version = "xprv";
110+
if (opts?.version) {
111+
version = opts?.version.toString(16);
112+
version = version.padStart(8, "0");
113+
}
108114
//@ts-ignore
109-
return await DashKeys.encodeKey(keyBytes, { version: "xprv" });
115+
return await DashKeys.encodeKey(keyBytes, { version });
110116
};
111117

112118
/**
@@ -514,7 +520,7 @@ var DashHd = ("object" === typeof module && exports) || {};
514520
};
515521

516522
DashHd.fromXKey = async function (xkey, opts) {
517-
// version(4) + depth(1) + fingerprint(4) + index(4) + chain(32) + key(33)
523+
// version(4) + depth(1) + fingerprint(4) + index(4) + chain(32) + key(1 + 32)
518524
let versions = opts?.versions ?? DashHd.MAINNET;
519525
let normalizePublicKey = opts?.normalizePublicKey ?? false;
520526
let bip32 = opts?.bip32 ?? false;
@@ -606,7 +612,7 @@ var DashHd = ("object" === typeof module && exports) || {};
606612
* @param {Uint8Array} keyBytes
607613
*/
608614
function serialize(hdkey, keyBytes) {
609-
// version(4) + depth(1) + fingerprint(4) + index(4) + chain(32) + key(33)
615+
// version(4) + depth(1) + fingerprint(4) + index(4) + chain(32) + key(1 + 32)
610616
let xkey = new Uint8Array(XKEY_SIZE);
611617
let xkeyDv = new DataView(xkey.buffer);
612618

0 commit comments

Comments
 (0)