Socket
Socket
Sign inDemoInstall

@metamask/key-tree

Package Overview
Dependencies
Maintainers
8
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/key-tree - npm Package Compare versions

Comparing version 6.0.0 to 6.1.0

12

dist/BIP44CoinTypeNode.d.ts

@@ -0,5 +1,5 @@

import { BIP44Node, BIP44NodeInterface, JsonBIP44Node } from './BIP44Node';
import { BIP39Node, BIP44Depth, BIP44PurposeNodeToken, CoinTypeHDPathString, HardenedBIP32Node } from './constants';
import { BIP44Node, BIP44NodeInterface, JsonBIP44Node } from './BIP44Node';
import { SupportedCurve } from './curves';
import { CoinTypeToAddressIndices, getBIP44ChangePathString } from './utils';
import { SupportedCurve } from './curves';
export declare type CoinTypeHDPathTuple = [

@@ -128,3 +128,3 @@ BIP39Node,

* @param indices.address_index - The `address_index` index.
* @returns
* @returns The derived BIP-44 `address_index` node.
*/

@@ -147,4 +147,6 @@ deriveBIP44AddressKey({ account, change, address_index, }: CoinTypeToAddressIndices): Promise<BIP44Node>;

* @param parentKeyOrNode - The `coin_type` parent key to derive from.
* @param indices - The `account`, `change`, and `address_index` used for
* derivation.
* @param indices - The BIP-44 index values to use in key derivation.
* @param indices.account - The `account` index. Default: `0`.
* @param indices.change - The `change` index. Default: `0`.
* @param indices.address_index - The `address_index` index.
* @returns The derived `address_index` key for the specified derivation path.

@@ -151,0 +153,0 @@ */

@@ -16,6 +16,6 @@ "use strict";

exports.getBIP44AddressKeyDeriver = exports.deriveBIP44AddressKey = exports.BIP44CoinTypeNode = exports.BIP_44_COIN_TYPE_DEPTH = void 0;
const BIP44Node_1 = require("./BIP44Node");
const constants_1 = require("./constants");
const BIP44Node_1 = require("./BIP44Node");
const SLIP10Node_1 = require("./SLIP10Node");
const utils_1 = require("./utils");
const SLIP10Node_1 = require("./SLIP10Node");
exports.BIP_44_COIN_TYPE_DEPTH = 2;

@@ -38,2 +38,4 @@ /**

class BIP44CoinTypeNode {
// Constructors cannot use hash names.
// eslint-disable-next-line no-restricted-syntax
constructor(node, coin_type) {

@@ -126,3 +128,4 @@ _BIP44CoinTypeNode_node.set(this, void 0);

validateCoinTypeNodeDepth(node.depth);
return new BIP44CoinTypeNode(node, coin_type);
// TODO: Make this function not async in a future version.
return Promise.resolve(new BIP44CoinTypeNode(node, coin_type));
}

@@ -195,3 +198,3 @@ get depth() {

* @param indices.address_index - The `address_index` index.
* @returns
* @returns The derived BIP-44 `address_index` node.
*/

@@ -244,4 +247,6 @@ async deriveBIP44AddressKey({ account = 0, change = 0, address_index, }) {

* @param parentKeyOrNode - The `coin_type` parent key to derive from.
* @param indices - The `account`, `change`, and `address_index` used for
* derivation.
* @param indices - The BIP-44 index values to use in key derivation.
* @param indices.account - The `account` index. Default: `0`.
* @param indices.change - The `change` index. Default: `0`.
* @param indices.address_index - The `address_index` index.
* @returns The derived `address_index` key for the specified derivation path.

@@ -284,3 +289,3 @@ */

async function getBIP44AddressKeyDeriver(node, accountAndChangeIndices) {
const { account = 0, change = 0 } = accountAndChangeIndices || {};
const { account = 0, change = 0 } = accountAndChangeIndices !== null && accountAndChangeIndices !== void 0 ? accountAndChangeIndices : {};
const actualNode = await getNode(node);

@@ -287,0 +292,0 @@ const accountNode = (0, utils_1.getHardenedBIP32NodeToken)(account);

import { BIP44Depth, PartialHDPathTuple, RootedSLIP10PathTuple } from './constants';
import { SupportedCurve } from './curves';
import { SLIP10Node } from './SLIP10Node';
import { SupportedCurve } from './curves';
export declare type BIP44ExtendedKeyOptions = {

@@ -93,7 +93,7 @@ readonly depth: number;

* public (xpub) or private (xprv) key.
* @param options.depth The depth of the node.
* @param options.privateKey The private key for the node.
* @param options.publicKey The public key for the node. If a private key is
* @param options.depth - The depth of the node.
* @param options.privateKey - The private key for the node.
* @param options.publicKey - The public key for the node. If a private key is
* specified, this parameter is ignored.
* @param options.chainCode The chain code for the node.
* @param options.chainCode - The chain code for the node.
*/

@@ -118,3 +118,4 @@ static fromExtendedKey(options: BIP44ExtendedKeyOptions | string): Promise<BIP44Node>;

*
* @param derivationPath The rooted HD tree path that will be used
* @param options - An object containing the derivation path.
* @param options.derivationPath - The rooted HD tree path that will be used
* to derive the key of this node.

@@ -141,3 +142,5 @@ */

/**
* Returns a neutered version of this node, i.e. a node without a private key.
* Get a neutered version of this node, i.e. a node without a private key.
*
* @returns A neutered version of this node.
*/

@@ -144,0 +147,0 @@ neuter(): BIP44Node;

@@ -17,5 +17,5 @@ "use strict";

const constants_1 = require("./constants");
const extended_keys_1 = require("./extended-keys");
const SLIP10Node_1 = require("./SLIP10Node");
const utils_1 = require("./utils");
const SLIP10Node_1 = require("./SLIP10Node");
const extended_keys_1 = require("./extended-keys");
/**

@@ -54,7 +54,7 @@ * A wrapper for BIP-44 Hierarchical Deterministic (HD) tree nodes, i.e.

* public (xpub) or private (xprv) key.
* @param options.depth The depth of the node.
* @param options.privateKey The private key for the node.
* @param options.publicKey The public key for the node. If a private key is
* @param options.depth - The depth of the node.
* @param options.privateKey - The private key for the node.
* @param options.publicKey - The public key for the node. If a private key is
* specified, this parameter is ignored.
* @param options.chainCode The chain code for the node.
* @param options.chainCode - The chain code for the node.
*/

@@ -114,3 +114,4 @@ static async fromExtendedKey(options) {

*
* @param derivationPath The rooted HD tree path that will be used
* @param options - An object containing the derivation path.
* @param options.derivationPath - The rooted HD tree path that will be used
* to derive the key of this node.

@@ -185,3 +186,5 @@ */

/**
* Returns a neutered version of this node, i.e. a node without a private key.
* Get a neutered version of this node, i.e. a node without a private key.
*
* @returns A neutered version of this node.
*/

@@ -188,0 +191,0 @@ neuter() {

@@ -0,3 +1,3 @@

import * as ed25519 from './ed25519';
import * as secp256k1 from './secp256k1';
import * as ed25519 from './ed25519';
export declare type SupportedCurve = keyof typeof curves;

@@ -26,4 +26,5 @@ export declare const curves: {

* @param curveName - The name of the curve to get.
* @returns The curve.
*/
export declare function getCurveByName(curveName: SupportedCurve): Curve;
export declare const mod: (a: bigint, b?: bigint | undefined) => bigint;

@@ -28,4 +28,4 @@ "use strict";

const secp256k1_1 = require("@noble/secp256k1");
const ed25519 = __importStar(require("./ed25519"));
const secp256k1 = __importStar(require("./secp256k1"));
const ed25519 = __importStar(require("./ed25519"));
exports.curves = {

@@ -39,2 +39,3 @@ secp256k1,

* @param curveName - The name of the curve to get.
* @returns The curve.
*/

@@ -41,0 +42,0 @@ function getCurveByName(curveName) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decompressPublicKey = exports.compressPublicKey = exports.publicAdd = exports.getPublicKey = exports.publicKeyLength = exports.deriveUnhardenedKeys = exports.isValidPrivateKey = exports.secret = exports.name = exports.curve = void 0;
const utils_1 = require("@metamask/utils");
const ed25519_1 = require("@noble/ed25519");
const utils_1 = require("@metamask/utils");
var ed25519_2 = require("@noble/ed25519");

@@ -7,0 +7,0 @@ Object.defineProperty(exports, "curve", { enumerable: true, get: function () { return ed25519_2.CURVE; } });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decompressPublicKey = exports.compressPublicKey = exports.publicAdd = exports.getPublicKey = exports.isValidPrivateKey = exports.publicKeyLength = exports.deriveUnhardenedKeys = exports.secret = exports.name = exports.curve = void 0;
const utils_1 = require("@metamask/utils");
const secp256k1_1 = require("@noble/secp256k1");
const utils_1 = require("@metamask/utils");
var secp256k1_2 = require("@noble/secp256k1");

@@ -7,0 +7,0 @@ Object.defineProperty(exports, "curve", { enumerable: true, get: function () { return secp256k1_2.CURVE; } });

@@ -0,6 +1,6 @@

import { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
import { BIP44Node } from './BIP44Node';
import { SLIP10Path } from './constants';
import { SupportedCurve } from './curves';
import { SLIP10Node } from './SLIP10Node';
import { BIP44Node } from './BIP44Node';
import { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
import { SupportedCurve } from './curves';
/**

@@ -35,3 +35,3 @@ * Ethereum default seed path: "m/44'/60'/0'/0/{account_index}"

* - The path cannot exceed 5 BIP-32 nodes in length, optionally preceded by
* a single BIP-39 node.
* a single BIP-39 node.
*

@@ -41,6 +41,5 @@ * WARNING: It is the consumer's responsibility to ensure that the path is valid

*
* @param args
* @param args - The arguments for deriving a key from a path.
* @param args.path - A full or partial HD path, e.g.:
* bip39:SEED_PHRASE/bip32:44'/bip32:60'/bip32:0'/bip32:0/bip32:0
*
* `bip39:SEED_PHRASE/bip32:44'/bip32:60'/bip32:0'/bip32:0/bip32:0`.
* BIP-39 seed phrases must be lowercase, space-delimited, and 12-24 words long.

@@ -54,11 +53,11 @@ * @param args.node - The node to derive from.

* The path segment must be one of the following:
* - A lone BIP-32 path node
* - A lone BIP-39 path node
* - A multipath
* - A lone BIP-32 path node.
* - A lone BIP-39 path node.
* - A multipath.
*
* @param path - The path segment string to validate.
* @param hasKey
* @param depth
* @param hasKey - Whether the path segment has a key.
* @param depth - The depth of the segment.
*/
export declare function validatePathSegment(path: SLIP10Path, hasKey: boolean, depth?: number): void;
export {};

@@ -5,8 +5,8 @@ "use strict";

const utils_1 = require("@metamask/utils");
const BIP44CoinTypeNode_1 = require("./BIP44CoinTypeNode");
const BIP44Node_1 = require("./BIP44Node");
const constants_1 = require("./constants");
const curves_1 = require("./curves");
const derivers_1 = require("./derivers");
const SLIP10Node_1 = require("./SLIP10Node");
const BIP44Node_1 = require("./BIP44Node");
const BIP44CoinTypeNode_1 = require("./BIP44CoinTypeNode");
const curves_1 = require("./curves");
/**

@@ -19,3 +19,3 @@ * Takes a full or partial HD path string and returns the key corresponding to

* - The path cannot exceed 5 BIP-32 nodes in length, optionally preceded by
* a single BIP-39 node.
* a single BIP-39 node.
*

@@ -25,6 +25,5 @@ * WARNING: It is the consumer's responsibility to ensure that the path is valid

*
* @param args
* @param args - The arguments for deriving a key from a path.
* @param args.path - A full or partial HD path, e.g.:
* bip39:SEED_PHRASE/bip32:44'/bip32:60'/bip32:0'/bip32:0/bip32:0
*
* `bip39:SEED_PHRASE/bip32:44'/bip32:60'/bip32:0'/bip32:0/bip32:0`.
* BIP-39 seed phrases must be lowercase, space-delimited, and 12-24 words long.

@@ -65,3 +64,6 @@ * @param args.node - The node to derive from.

/**
* @param pathType
* Check if the given path type is a valid deriver.
*
* @param pathType - The path type to check.
* @returns Whether the path type is a valid deriver.
*/

@@ -73,9 +75,9 @@ function hasDeriver(pathType) {

* The path segment must be one of the following:
* - A lone BIP-32 path node
* - A lone BIP-39 path node
* - A multipath
* - A lone BIP-32 path node.
* - A lone BIP-39 path node.
* - A multipath.
*
* @param path - The path segment string to validate.
* @param hasKey
* @param depth
* @param hasKey - Whether the path segment has a key.
* @param depth - The depth of the segment.
*/

@@ -99,3 +101,3 @@ function validatePathSegment(path, hasKey, depth) {

if (depth === constants_1.MIN_BIP_44_DEPTH && (!startsWithBip39 || path.length !== 1)) {
throw new Error(`Invalid HD path segment: The segment must consist of a single BIP-39 node for depths of ${constants_1.MIN_BIP_44_DEPTH}. Received: "${path}".`);
throw new Error(`Invalid HD path segment: The segment must consist of a single BIP-39 node for depths of ${constants_1.MIN_BIP_44_DEPTH}. Received: "${String(path)}".`);
}

@@ -110,5 +112,10 @@ if (!hasKey && !startsWithBip39) {

exports.validatePathSegment = validatePathSegment;
/**
* Get the error for a malformed path segment.
*
* @returns The error.
*/
function getMalformedError() {
throw new Error('Invalid HD path segment: The path segment is malformed.');
return new Error('Invalid HD path segment: The path segment is malformed.');
}
//# sourceMappingURL=derivation.js.map

@@ -0,4 +1,4 @@

import { DeriveChildKeyArgs } from '.';
import { Curve } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import { DeriveChildKeyArgs } from '.';
/**

@@ -31,5 +31,6 @@ * Converts a BIP-32 private key to an Ethereum address.

*
* @param path - The derivation path part to derive.
* @param node - The node to derive from.
* @param curve - The curve to use for derivation.
* @param options - The options for deriving a child key.
* @param options.path - The derivation path part to derive.
* @param options.node - The node to derive from.
* @param options.curve - The curve to use for derivation.
* @returns A tuple containing the derived private key, public key and chain

@@ -36,0 +37,0 @@ * code.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.privateAdd = exports.deriveChildKey = exports.publicKeyToEthAddress = exports.privateKeyToEthAddress = void 0;
const utils_1 = require("@metamask/utils");
const hmac_1 = require("@noble/hashes/hmac");
const sha3_1 = require("@noble/hashes/sha3");
const hmac_1 = require("@noble/hashes/hmac");
const sha512_1 = require("@noble/hashes/sha512");
const utils_1 = require("@metamask/utils");
const constants_1 = require("../constants");
const utils_2 = require("../utils");
const curves_1 = require("../curves");
const SLIP10Node_1 = require("../SLIP10Node");
const utils_2 = require("../utils");
/**

@@ -49,5 +49,6 @@ * Converts a BIP-32 private key to an Ethereum address.

*
* @param path - The derivation path part to derive.
* @param node - The node to derive from.
* @param curve - The curve to use for derivation.
* @param options - The options for deriving a child key.
* @param options.path - The derivation path part to derive.
* @param options.node - The node to derive from.
* @param options.curve - The curve to use for derivation.
* @returns A tuple containing the derived private key, public key and chain

@@ -98,3 +99,3 @@ * code.

}
const publicExtension = await derivePublicExtension({
const publicExtension = derivePublicExtension({
parentPublicKey: node.compressedPublicKeyBytes,

@@ -120,8 +121,11 @@ childIndex,

exports.deriveChildKey = deriveChildKey;
// the bip32 secret extension is created from the parent private or public key and the child index
/**
* @param options
* @param options.privateKey
* @param options.childIndex
* @param options.isHardened
* Derive a BIP-32 secret extension from a parent key and child index.
*
* @param options - The options for deriving a secret extension.
* @param options.privateKey - The parent private key bytes.
* @param options.childIndex - The child index to derive.
* @param options.isHardened - Whether the child index is hardened.
* @param options.curve - The curve to use for derivation.
* @returns The secret extension bytes.
*/

@@ -140,3 +144,11 @@ async function deriveSecretExtension({ privateKey, childIndex, isHardened, curve, }) {

}
async function derivePublicExtension({ parentPublicKey, childIndex, }) {
/**
* Derive a BIP-32 public extension from a parent key and child index.
*
* @param options - The options for deriving a public extension.
* @param options.parentPublicKey - The parent public key bytes.
* @param options.childIndex - The child index to derive.
* @returns The public extension bytes.
*/
function derivePublicExtension({ parentPublicKey, childIndex, }) {
const indexBytes = new Uint8Array(4);

@@ -171,6 +183,10 @@ const view = new DataView(indexBytes.buffer);

/**
* @param options
* @param options.privateKey
* @param options.chainCode
* @param options.secretExtension
* Derive a BIP-32 key from a parent key and secret extension.
*
* @param options - The options for deriving a key.
* @param options.privateKey - The parent private key bytes.
* @param options.chainCode - The parent chain code bytes.
* @param options.secretExtension - The secret extension bytes.
* @param options.curve - The curve to use for derivation.
* @returns The derived key.
*/

@@ -191,2 +207,12 @@ async function generateKey({ privateKey, chainCode, secretExtension, curve, }) {

}
/**
* Derive a BIP-32 public key from a parent key and public extension.
*
* @param options - The options for deriving a public key.
* @param options.publicKey - The parent public key bytes.
* @param options.chainCode - The parent chain code bytes.
* @param options.publicExtension - The public extension bytes.
* @param options.curve - The curve to use for derivation.
* @returns The derived public key.
*/
function generatePublicKey({ publicKey, chainCode, publicExtension, curve, }) {

@@ -193,0 +219,0 @@ const entropy = (0, hmac_1.hmac)(sha512_1.sha512, chainCode, publicExtension);

@@ -0,19 +1,29 @@

import { DeriveChildKeyArgs } from '.';
import { BIP39Node } from '../constants';
import { Curve } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import { DeriveChildKeyArgs } from '.';
/**
* @param mnemonic
* Convert a BIP-39 mnemonic phrase to a multi path.
*
* @param mnemonic - The BIP-39 mnemonic phrase to convert.
* @returns The multi path.
*/
export declare function bip39MnemonicToMultipath(mnemonic: string): BIP39Node;
/**
* @param pathPart
* @param curve
* Create a {@link SLIP10Node} from a BIP-39 mnemonic phrase.
*
* @param options - The options for creating the node.
* @param options.path - The multi path.
* @param options.curve - The curve to use for derivation.
* @returns The node.
*/
export declare function deriveChildKey({ path, curve, }: DeriveChildKeyArgs): Promise<SLIP10Node>;
/**
* Create a {@link SLIP10Node} from a BIP-39 seed.
*
* @param seed - The cryptographic seed bytes.
* @param curve - The curve to use.
* @returns An object containing the corresponding BIP-39 master key and chain code.
* @returns An object containing the corresponding BIP-39 master key and chain
* code.
*/
export declare function createBip39KeyFromSeed(seed: Uint8Array, curve?: Curve): Promise<SLIP10Node>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createBip39KeyFromSeed = exports.deriveChildKey = exports.bip39MnemonicToMultipath = void 0;
const bip39_1 = require("@scure/bip39");
const scure_bip39_1 = require("@metamask/scure-bip39");
const english_1 = require("@metamask/scure-bip39/dist/wordlists/english");
const hmac_1 = require("@noble/hashes/hmac");

@@ -11,3 +12,6 @@ const sha512_1 = require("@noble/hashes/sha512");

/**
* @param mnemonic
* Convert a BIP-39 mnemonic phrase to a multi path.
*
* @param mnemonic - The BIP-39 mnemonic phrase to convert.
* @returns The multi path.
*/

@@ -18,15 +22,21 @@ function bip39MnemonicToMultipath(mnemonic) {

exports.bip39MnemonicToMultipath = bip39MnemonicToMultipath;
// this creates a child key using bip39, ignoring the parent key
/**
* @param pathPart
* @param curve
* Create a {@link SLIP10Node} from a BIP-39 mnemonic phrase.
*
* @param options - The options for creating the node.
* @param options.path - The multi path.
* @param options.curve - The curve to use for derivation.
* @returns The node.
*/
async function deriveChildKey({ path, curve, }) {
return createBip39KeyFromSeed(await (0, bip39_1.mnemonicToSeed)(path), curve);
return createBip39KeyFromSeed(await (0, scure_bip39_1.mnemonicToSeed)(path, english_1.wordlist), curve);
}
exports.deriveChildKey = deriveChildKey;
/**
* Create a {@link SLIP10Node} from a BIP-39 seed.
*
* @param seed - The cryptographic seed bytes.
* @param curve - The curve to use.
* @returns An object containing the corresponding BIP-39 master key and chain code.
* @returns An object containing the corresponding BIP-39 master key and chain
* code.
*/

@@ -33,0 +43,0 @@ async function createBip39KeyFromSeed(seed, curve = curves_1.secp256k1) {

@@ -31,2 +31,3 @@ export declare const PUBLIC_KEY_VERSION = 76067358;

* @param extendedKey - The extended key string to attempt to decode.
* @returns The decoded extended key.
*/

@@ -38,4 +39,5 @@ export declare const decodeExtendedKey: (extendedKey: string) => ExtendedKey;

* @param extendedKey - The extended key data to encode.
* @returns The encoded extended key.
*/
export declare const encodeExtendedKey: (extendedKey: ExtendedKey) => string;
export {};

@@ -5,5 +5,5 @@ "use strict";

const utils_1 = require("@metamask/utils");
const utils_2 = require("./utils");
const BIP44Node_1 = require("./BIP44Node");
const secp256k1_1 = require("./curves/secp256k1");
const utils_2 = require("./utils");
// https://github.com/bitcoin/bips/blob/274fa400d630ba757bec0c03b35ebe2345197108/bip-0032.mediawiki#Serialization_format

@@ -19,2 +19,3 @@ exports.PUBLIC_KEY_VERSION = 0x0488b21e;

* @param extendedKey - The extended key string to attempt to decode.
* @returns The decoded extended key.
*/

@@ -74,2 +75,3 @@ const decodeExtendedKey = (extendedKey) => {

* @param extendedKey - The extended key data to encode.
* @returns The encoded extended key.
*/

@@ -76,0 +78,0 @@ const encodeExtendedKey = (extendedKey) => {

@@ -1,6 +0,10 @@

export { BIP44Node, BIP44NodeInterface, JsonBIP44Node, BIP44ExtendedKeyOptions, BIP44DerivationPathOptions, } from './BIP44Node';
export { SLIP10Node, SLIP10NodeInterface, JsonSLIP10Node, SLIP10NodeConstructorOptions, SLIP10ExtendedKeyOptions, SLIP10DerivationPathOptions, } from './SLIP10Node';
export { secp256k1, ed25519, SupportedCurve } from './curves';
export { BIP44CoinTypeNode, BIP44CoinTypeNodeInterface, BIP_44_COIN_TYPE_DEPTH, CoinTypeHDPathTuple, deriveBIP44AddressKey, getBIP44AddressKeyDeriver, JsonBIP44CoinTypeNode, BIP44AddressKeyDeriver, } from './BIP44CoinTypeNode';
export type { BIP44NodeInterface, JsonBIP44Node, BIP44ExtendedKeyOptions, BIP44DerivationPathOptions, } from './BIP44Node';
export { BIP44Node } from './BIP44Node';
export type { SLIP10NodeInterface, JsonSLIP10Node, SLIP10NodeConstructorOptions, SLIP10ExtendedKeyOptions, SLIP10DerivationPathOptions, } from './SLIP10Node';
export { SLIP10Node } from './SLIP10Node';
export type { SupportedCurve } from './curves';
export { secp256k1, ed25519 } from './curves';
export type { BIP44CoinTypeNodeInterface, CoinTypeHDPathTuple, JsonBIP44CoinTypeNode, BIP44AddressKeyDeriver, } from './BIP44CoinTypeNode';
export { BIP44CoinTypeNode, BIP_44_COIN_TYPE_DEPTH, deriveBIP44AddressKey, getBIP44AddressKeyDeriver, } from './BIP44CoinTypeNode';
export * from './constants';
export { CoinTypeToAddressIndices } from './utils';
export type { CoinTypeToAddressIndices } from './utils';

@@ -0,5 +1,5 @@

import { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
import { BIP44Node } from './BIP44Node';
import { RootedSLIP10PathTuple, SLIP10PathTuple } from './constants';
import { SupportedCurve } from './curves';
import { BIP44Node } from './BIP44Node';
import { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
/**

@@ -101,14 +101,15 @@ * A wrapper for SLIP-10 Hierarchical Deterministic (HD) tree nodes, i.e.

*
* @param depth - The depth of the node.
* @param masterFingerprint - The fingerprint of the master node, i.e., the
* @param options - The options for the new node.
* @param options.depth - The depth of the node.
* @param options.masterFingerprint - The fingerprint of the master node, i.e., the
* node at depth 0. May be undefined if this node was created from an extended
* key.
* @param parentFingerprint - The fingerprint of the parent key, or 0 if
* @param options.parentFingerprint - The fingerprint of the parent key, or 0 if
* the node is a master node.
* @param index - The index of the node, or 0 if the node is a master node.
* @param privateKey - The private key for the node.
* @param publicKey - The public key for the node. If a private key is
* @param options.index - The index of the node, or 0 if the node is a master node.
* @param options.privateKey - The private key for the node.
* @param options.publicKey - The public key for the node. If a private key is
* specified, this parameter is ignored.
* @param chainCode - The chain code for the node.
* @param curve - The curve used by the node.
* @param options.chainCode - The chain code for the node.
* @param options.curve - The curve used by the node.
*/

@@ -133,5 +134,7 @@ static fromExtendedKey({ depth, masterFingerprint, parentFingerprint, index, privateKey, publicKey, chainCode, curve, }: SLIP10ExtendedKeyOptions): Promise<SLIP10Node>;

*
* @param derivationPath - The rooted HD tree path that will be used
* @param options - The options for the new node.
* @param options.derivationPath - The rooted HD tree path that will be used
* to derive the key of this node.
* @param curve - The curve used by the node.
* @param options.curve - The curve used by the node.
* @returns A new SLIP-10 node.
*/

@@ -156,3 +159,5 @@ static fromDerivationPath({ derivationPath, curve, }: SLIP10DerivationPathOptions): Promise<SLIP10Node>;

/**
* Returns a neutered version of this node, i.e. a node without a private key.
* Get a neutered version of this node, i.e. a node without a private key.
*
* @returns A neutered version of this node.
*/

@@ -194,4 +199,5 @@ neuter(): SLIP10Node;

*
* @param node - The node to derive from.
* @param path - The path to the child node / key.
* @param options - The options to use when deriving the child key.
* @param options.node - The node to derive from.
* @param options.path - The path to the child node / key.
* @returns The derived key and depth.

@@ -198,0 +204,0 @@ */

@@ -39,14 +39,15 @@ "use strict";

*
* @param depth - The depth of the node.
* @param masterFingerprint - The fingerprint of the master node, i.e., the
* @param options - The options for the new node.
* @param options.depth - The depth of the node.
* @param options.masterFingerprint - The fingerprint of the master node, i.e., the
* node at depth 0. May be undefined if this node was created from an extended
* key.
* @param parentFingerprint - The fingerprint of the parent key, or 0 if
* @param options.parentFingerprint - The fingerprint of the parent key, or 0 if
* the node is a master node.
* @param index - The index of the node, or 0 if the node is a master node.
* @param privateKey - The private key for the node.
* @param publicKey - The public key for the node. If a private key is
* @param options.index - The index of the node, or 0 if the node is a master node.
* @param options.privateKey - The private key for the node.
* @param options.publicKey - The public key for the node. If a private key is
* specified, this parameter is ignored.
* @param chainCode - The chain code for the node.
* @param curve - The curve used by the node.
* @param options.chainCode - The chain code for the node.
* @param options.curve - The curve used by the node.
*/

@@ -103,5 +104,7 @@ static async fromExtendedKey({ depth, masterFingerprint, parentFingerprint, index, privateKey, publicKey, chainCode, curve, }) {

*
* @param derivationPath - The rooted HD tree path that will be used
* @param options - The options for the new node.
* @param options.derivationPath - The rooted HD tree path that will be used
* to derive the key of this node.
* @param curve - The curve used by the node.
* @param options.curve - The curve used by the node.
* @returns A new SLIP-10 node.
*/

@@ -150,3 +153,5 @@ static async fromDerivationPath({ derivationPath, curve, }) {

/**
* Returns a neutered version of this node, i.e. a node without a private key.
* Get a neutered version of this node, i.e. a node without a private key.
*
* @returns A neutered version of this node.
*/

@@ -216,3 +221,3 @@ neuter() {

if (!(0, utils_2.isValidInteger)(depth)) {
throw new Error(`Invalid HD tree path depth: The depth must be a positive integer. Received: "${depth}".`);
throw new Error(`Invalid HD tree path depth: The depth must be a positive integer. Received: "${String(depth)}".`);
}

@@ -229,3 +234,3 @@ }

if (!(0, utils_2.isValidInteger)(parentFingerprint)) {
throw new Error(`Invalid parent fingerprint: The fingerprint must be a positive integer. Received: "${parentFingerprint}".`);
throw new Error(`Invalid parent fingerprint: The fingerprint must be a positive integer. Received: "${String(parentFingerprint)}".`);
}

@@ -237,4 +242,5 @@ }

*
* @param node - The node to derive from.
* @param path - The path to the child node / key.
* @param options - The options to use when deriving the child key.
* @param options.node - The node to derive from.
* @param options.path - The path to the child node / key.
* @returns The derived key and depth.

@@ -241,0 +247,0 @@ */

@@ -82,2 +82,4 @@ import { BIP32Node, ChangeHDPathString, CoinTypeHDPathString, CoinTypeToAddressTuple, HardenedBIP32Node, UnhardenedBIP32Node } from './constants';

/**
* Check if the index is a valid BIP-32 index.
*
* @param index - The BIP-32 index to test.

@@ -88,2 +90,6 @@ * @returns Whether the index is a non-negative integer number.

/**
* Check if the value is a hardened BIP-32 index. This only checks if the value
* ends with a `'` character, and does not validate that the index is a valid
* BIP-32 index.
*
* @param bip32Token - The token to test.

@@ -94,2 +100,6 @@ * @returns Whether the token is hardened, i.e. ends with `'`.

/**
* Get a `Uint8Array` from a hexadecimal string or a `Uint8Array`. If the input
* is a hexadecimal string, it is converted to a `Uint8Array`. If the input is
* a `Uint8Array`, it is returned as-is.
*
* @param hexString - The hexadecimal string to convert.

@@ -100,2 +110,5 @@ * @returns The `Uint8Array` corresponding to the hexadecimal string.

/**
* The same as {@link hexStringToBytes}, but returns `undefined` if the input
* is `undefined`.
*
* @param hexString - The hexadecimal string to convert.

@@ -128,2 +141,3 @@ * @returns The `Uint8Array` corresponding to the hexadecimal string.

* @param length - The length to validate the `Uint8Array` against.
* @returns The `Uint8Array` corresponding to the hexadecimal string.
*/

@@ -137,4 +151,5 @@ export declare function getBytes(value: unknown, length: number): Uint8Array;

* @param publicKey - The compressed public key to get the fingerprint for.
* @returns The fingerprint of the public key.
*/
export declare const getFingerprint: (publicKey: Uint8Array) => number;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFingerprint = exports.encodeBase58check = exports.decodeBase58check = exports.getBytes = exports.isValidInteger = exports.isValidBytesKey = exports.nullableHexStringToBytes = exports.hexStringToBytes = exports.isHardened = exports.isValidBIP32Index = exports.validateBIP32Index = exports.getBIP32NodeToken = exports.getUnhardenedBIP32NodeToken = exports.getHardenedBIP32NodeToken = exports.getBIP44CoinTypeToAddressPathTuple = exports.getBIP44ChangePathString = exports.getBIP44CoinTypePathString = void 0;
const utils_1 = require("@metamask/utils");
const ripemd160_1 = require("@noble/hashes/ripemd160");
const sha256_1 = require("@noble/hashes/sha256");
const base_1 = require("@scure/base");
const sha256_1 = require("@noble/hashes/sha256");
const ripemd160_1 = require("@noble/hashes/ripemd160");
const utils_1 = require("@metamask/utils");
const constants_1 = require("./constants");

@@ -34,3 +34,4 @@ /**

function getBIP44ChangePathString(coinTypePath, indices) {
return `${coinTypePath} / ${getHardenedBIP32NodeToken(indices.account || 0)} / ${getBIP32NodeToken(indices.change || 0)}`;
var _a, _b;
return `${coinTypePath} / ${getHardenedBIP32NodeToken((_a = indices.account) !== null && _a !== void 0 ? _a : 0)} / ${getBIP32NodeToken((_b = indices.change) !== null && _b !== void 0 ? _b : 0)}`;
}

@@ -119,2 +120,4 @@ exports.getBIP44ChangePathString = getBIP44ChangePathString;

/**
* Check if the index is a valid BIP-32 index.
*
* @param index - The BIP-32 index to test.

@@ -128,2 +131,6 @@ * @returns Whether the index is a non-negative integer number.

/**
* Check if the value is a hardened BIP-32 index. This only checks if the value
* ends with a `'` character, and does not validate that the index is a valid
* BIP-32 index.
*
* @param bip32Token - The token to test.

@@ -137,2 +144,6 @@ * @returns Whether the token is hardened, i.e. ends with `'`.

/**
* Get a `Uint8Array` from a hexadecimal string or a `Uint8Array`. If the input
* is a hexadecimal string, it is converted to a `Uint8Array`. If the input is
* a `Uint8Array`, it is returned as-is.
*
* @param hexString - The hexadecimal string to convert.

@@ -149,2 +160,5 @@ * @returns The `Uint8Array` corresponding to the hexadecimal string.

/**
* The same as {@link hexStringToBytes}, but returns `undefined` if the input
* is `undefined`.
*
* @param hexString - The hexadecimal string to convert.

@@ -197,2 +211,3 @@ * @returns The `Uint8Array` corresponding to the hexadecimal string.

* @param length - The length to validate the `Uint8Array` against.
* @returns The `Uint8Array` corresponding to the hexadecimal string.
*/

@@ -212,2 +227,10 @@ function getBytes(value, length) {

exports.getBytes = getBytes;
/**
* Validate that the specified `Uint8Array` is not empty and has the specified
* length.
*
* @param bytes - The `Uint8Array` to validate.
* @param length - The length to validate the `Uint8Array` against.
* @throws An error if the `Uint8Array` is empty or has the wrong length.
*/
function validateBytes(bytes, length) {

@@ -237,2 +260,3 @@ if (!isValidBytesKey(bytes, length)) {

* @param publicKey - The compressed public key to get the fingerprint for.
* @returns The fingerprint of the public key.
*/

@@ -239,0 +263,0 @@ const getFingerprint = (publicKey) => {

{
"name": "@metamask/key-tree",
"version": "6.0.0",
"version": "6.1.0",
"description": "An interface over BIP-32 and BIP-39 key derivation paths.",

@@ -39,2 +39,3 @@ "repository": {

"dependencies": {
"@metamask/scure-bip39": "^2.1.0",
"@metamask/utils": "^3.3.0",

@@ -44,26 +45,25 @@ "@noble/ed25519": "^1.6.0",

"@noble/secp256k1": "^1.5.5",
"@scure/base": "^1.0.0",
"@scure/bip39": "^1.0.0"
"@scure/base": "^1.0.0"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^2.5.0",
"@metamask/eslint-config": "^8.0.0",
"@metamask/eslint-config-jest": "^8.0.0",
"@metamask/eslint-config-nodejs": "^8.0.0",
"@metamask/eslint-config-typescript": "^8.0.0",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^11.0.1",
"@metamask/eslint-config-jest": "^11.0.0",
"@metamask/eslint-config-nodejs": "^11.0.1",
"@metamask/eslint-config-typescript": "^11.0.0",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.4",
"eslint-plugin-jsdoc": "^36.1.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^27.2.5",
"jest-it-up": "^2.0.2",
"lint-staged": "^13.0.3",
"prettier": "^2.4.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.13",

@@ -74,3 +74,3 @@ "rimraf": "^3.0.2",

"typedoc": "^0.23.19",
"typescript": "~4.7.4"
"typescript": "~4.8.4"
},

@@ -77,0 +77,0 @@ "packageManager": "yarn@3.2.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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