Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dashhd

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashhd - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1

135

dashhd.js

@@ -17,3 +17,3 @@ /**

* @prop {HDToXKeyBytes} toXPubBytes
* @prop {HDUtils} utils
* @prop {HDUtils} _utils
* @prop {HDWipePrivates} wipePrivateData - randomizes private key buffer in-place

@@ -65,3 +65,3 @@ * @prop {HDToPublic} toPublic - returns public key

* @typedef HDKeyOptions
* @prop {HDVersions?} [versions]
* @prop {HDVersionsOption?} [versions]
* @prop {Number?} [depth]

@@ -111,3 +111,3 @@ * @prop {Number?} [parentFingerprint]

* @param {Object} opts
* @param {Number} [opts.version]
* @param {String|Uint32} [opts.version]
*/

@@ -117,4 +117,9 @@ Utils.encodeXPrv = async function (keyBytes, opts) {

if (opts?.version) {
version = opts?.version.toString(16);
version = version.padStart(8, "0");
if (opts.version === "tprv") {
version = opts.version;
} else {
// intended for numbers, but won't break hex strings
version = opts.version.toString(16);
version = version.padStart(8, "0");
}
}

@@ -127,7 +132,18 @@ //@ts-ignore

* @param {Uint8Array} keyBytes
* TODO - pass tpub
* @param {Object} opts
* @param {String|Uint32} [opts.version]
*/
Utils.encodeXPub = async function (keyBytes) {
Utils.encodeXPub = async function (keyBytes, opts) {
let version = "xpub";
if (opts?.version) {
if (opts.version === "tpub") {
version = opts.version;
} else {
// intended for numbers, but won't break hex strings
version = opts.version.toString(16);
version = version.padStart(8, "0");
}
}
//@ts-ignore
return await DashKeys.encodeKey(keyBytes, { version: "xpub" });
return await DashKeys.encodeKey(keyBytes, { version: version });
};

@@ -255,2 +271,3 @@ /** @type {HDKeyTweak} */

//@ts-ignore
DashHd._utils = Utils;

@@ -305,10 +322,10 @@

}
return await DashKeys.encodeKey(privBytes);
return await DashKeys.encodeKey(privBytes, opts);
};
DashHd.toXPrv = async function (hdkey) {
DashHd.toXPrv = async function (hdkey, opts) {
//@ts-ignore - will throw if null
let xprvBytes = DashHd._toXBytes(hdkey, hdkey.privateKey);
//@ts-ignore - wth?
let xprv = await Utils.encodeXPrv(xprvBytes);
let xprv = await Utils.encodeXPrv(xprvBytes, opts);
return xprv;

@@ -319,2 +336,4 @@ };

DashHd.toXPrvBytes = function (hdkey, opts) {
/** @type {Number} */
//@ts-ignore
let version = opts?.version || DashHd.MAINNET.private;

@@ -331,5 +350,5 @@

DashHd.toXPub = async function (hdkey) {
DashHd.toXPub = async function (hdkey, opts) {
let xpubBytes = DashHd._toXBytes(hdkey, hdkey.publicKey);
let xpub = await Utils.encodeXPub(xpubBytes);
let xpub = await Utils.encodeXPub(xpubBytes, opts);
return xpub;

@@ -339,3 +358,17 @@ };

DashHd.toXPubBytes = function (hdkey, opts) {
let version = opts?.version || DashHd.MAINNET.public;
/** @type {Uint32} */
//@ts-ignore - it's a number, I promise
let version = DashHd.MAINNET.public;
if (opts?.version) {
let [_, versionUint32] = // jshint ignore:line
_versionToTuple(
opts.version,
"xpub",
//@ts-ignore - it's a number, I promise
DashHd.MAINNET.public,
"tpub",
DashHd.TESTNET.public,
);
version = versionUint32;
}

@@ -618,7 +651,13 @@ let xpubPart = DashHd._toXBytes(hdkey, hdkey.publicKey);

let xprvHex = "0x0" + versions.private.toString(16);
let xpubHex = "0x0" + versions.public.toString(16);
if (publicKey) {
let [xpubHex, xpubUint32] = _versionToTuple(
versions.public,
"xpub",
//@ts-ignore - it's a number, I promise
DashHd.MAINNET.public,
"tpub",
DashHd.TESTNET.public,
);
assert(
version === versions.public,
version === xpubUint32,
`Version mismatch: version does not match ${xpubHex} (public)`,

@@ -633,4 +672,12 @@ );

} else {
let [xprvHex, xprvUint32] = _versionToTuple(
versions.private,
"xprv",
//@ts-ignore - it's a number, I promise
DashHd.MAINNET.private,
"tprv",
DashHd.TESTNET.private,
);
assert(
version === versions.private,
version === xprvUint32,
`Version mismatch: version does not match ${xprvHex} (private)`,

@@ -667,2 +714,29 @@ );

/**
*
* @param {String|Number} version
* @param {String} mainStr - 'xprv'|'xpub'
* @param {Number} mainInt - DashHd.MAINNET.private|DashHd.MAINNET.public
* @param {String} testStr - 'tprv'|'tpub'
* @param {Number} testInt - DashHd.TESTNET.private|DashHd.TESTNET.publi c
* @returns {[String, Number]}
*/
function _versionToTuple(version, mainStr, mainInt, testInt, testStr) {
let isMainnet = version === mainStr || version === "mainnet";
let isTestnet = version === testStr || version === "testnet";
if (isMainnet) {
version = mainInt;
} else if (isTestnet) {
version = testInt;
}
// intended for uint32, but doesn't break hex
let xkeyHex = version.toString(16);
xkeyHex = xkeyHex.padStart(8, "0");
let xkeyUint32 = parseInt(xkeyHex, 16);
xkeyUint32 = xkeyUint32 >>> 0; /* jshint ignore:line */ // coerce uint32
xkeyHex = `0x${xkeyHex}`;
return [xkeyHex, xkeyUint32];
}
DashHd.toId = async function (hdkey) {

@@ -737,7 +811,13 @@ let idBytes = await DashHd.toIdBytes(hdkey);

* @typedef HDVersions
* @prop {Number} private - 32-bit (4-byte) int (encodes to 'xprv' in base58)
* @prop {Number} public - 32-bit (4-byte) int (encodes to 'xpub' in base58)
* @prop {Uint32} private - 'mainnet', 'testnet', 'xprv' or 'tprv', or 4-byte hex or uint32
* @prop {Uint32} public - 'mainnet', 'testnet', 'xpub' or 'tpub', or 4-byte hex or uint32
*/
/**
* @typedef HDVersionsOption
* @prop {Uint32|String} [private] - 'mainnet', 'testnet', 'xprv' or 'tprv', or 4-byte hex or uint32
* @prop {Uint32|String} [public] - 'mainnet', 'testnet', 'xpub' or 'tpub', or 4-byte hex or uint32
*/
/**
* @typedef {HDKey & HDXKeyPartial} HDXKey

@@ -830,3 +910,3 @@ */

* @param {Uint8Array} pubBytes - Public Key
* @returns {Number}
* @returns {Promise<Number>}
*/

@@ -843,4 +923,3 @@

* @typedef HDFromXKeyOptions
* @prop {HDVersions} [versions]
* @prop {String} xkey - base58check-encoded xkey
* @prop {HDVersionsOption} [versions]
* @prop {Boolean} [bip32] - allow non-account depths

@@ -862,3 +941,3 @@ * @prop {Boolean} [normalizePublicKey]

* @prop {Number} [coinType] - 5 (DASH) by default
* @prop {HDVersions} [versions] - mainnet ('xprv', 'xpub') by default
* @prop {HDVersionsOption} [versions] - mainnet ('xprv', 'xpub') by default
*/

@@ -924,2 +1003,4 @@

* @param {HDKey} hdkey
* @param {Object} [opts]
* @param {String|Uint32} [opts.version]
* @returns {Promise<String>}

@@ -931,2 +1012,4 @@ */

* @param {HDKey} hdkey
* @param {Object} [opts]
* @param {String|Uint32} [opts.version]
* @returns {Promise<String>}

@@ -988,1 +1071,5 @@ */

*/
/**
* @typedef {Number} Uint32
*/

8

package.json
{
"name": "dashhd",
"version": "3.3.0",
"version": "3.3.1",
"description": "Manage HD Keys from HD Wallet Seed and Extended (xprv, xpub) Key Paths. Part of $DASH Tools.",

@@ -11,3 +11,3 @@ "main": "dashhd.js",

"type": "git",
"url": "git://github.com/dashive/dashhd.js"
"url": "git://github.com/dashhive/dashhd.js"
},

@@ -31,5 +31,5 @@ "license": "SEE LICENSE IN LICENSE",

"bugs": {
"url": "https://github.com/dashive/dashhd.js/issues"
"url": "https://github.com/dashhive/dashhd.js/issues"
},
"homepage": "https://github.com/dashive/dashhd.js",
"homepage": "https://github.com/dashhive/dashhd.js",
"files": [

@@ -36,0 +36,0 @@ "dashhd.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc