1.4.0 â€Ē Published 1 month ago

@scure/bip32 v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

scure-bip32

Audited & minimal implementation of BIP32 hierarchical deterministic (HD) wallets over secp256k1.

  • 🔒 Audited by an independent security firm
  • ðŸ”ŧ Tree-shaking-friendly: use only what's necessary, other code won't be included
  • ðŸ“Ķ ESM and common.js
  • ➰ Only 3 audited dependencies by the same author: noble-curves, noble-hashes, and scure-base
  • ðŸŠķ 300 lines. 90KB with all dependencies

Check out scure-bip39 if you need mnemonic phrases. See ed25519-keygen if you need SLIP-0010/BIP32 ed25519 hdkey implementation.

This library belongs to scure

scure — audited micro-libraries.

Usage

npm install @scure/bip32

This module exports a single class HDKey, which should be used like this:

import { HDKey } from "@scure/bip32";
const hdkey1 = HDKey.fromMasterSeed(seed);
const hdkey2 = HDKey.fromExtendedKey(base58key);
const hdkey3 = HDKey.fromJSON({ xpriv: string });

// props
[hdkey1.depth, hdkey1.index, hdkey1.chainCode];
console.log(hdkey2.privateKey, hdkey2.publicKey);
console.log(hdkey3.derive("m/0/2147483647'/1"));
const sig = hdkey3.sign(hash);
hdkey3.verify(hash, sig);

Note: chainCode property is essentially a private part of a secret "master" key, it should be guarded from unauthorized access.

The full API is:

class HDKey {
  public static HARDENED_OFFSET: number;
  public static fromMasterSeed(seed: Uint8Array, versions: Versions): HDKey;
  public static fromExtendedKey(base58key: string, versions: Versions): HDKey;
  public static fromJSON(json: { xpriv: string }): HDKey;

  readonly versions: Versions;
  readonly depth: number = 0;
  readonly index: number = 0;
  readonly chainCode: Uint8Array | null = null;
  readonly parentFingerprint: number = 0;

  get fingerprint(): number;
  get identifier(): Uint8Array | undefined;
  get pubKeyHash(): Uint8Array | undefined;
  get privateKey(): Uint8Array | null;
  get publicKey(): Uint8Array | null;
  get privateExtendedKey(): string;
  get publicExtendedKey(): string;

  derive(path: string): HDKey;
  deriveChild(index: number): HDKey;
  sign(hash: Uint8Array): Uint8Array;
  verify(hash: Uint8Array, signature: Uint8Array): boolean;
  wipePrivateData(): this;
}

interface Versions {
  private: number;
  public: number;
}

The module implements bip32 standard: check it out for additional documentation.

The implementation is loosely based on cryptocoinjs/hdkey, which has MIT License.

Security

The library has been independently audited:

The library was initially developed for js-ethereum-cryptography. At commit ae00e6d7, it was extracted to a separate package called micro-bip32. After the audit we've decided to use @scure NPM namespace for security.

License

MIT License

Copyright (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com)

@btq-js/keyring@stacks/clicasper-js-sdk-test-h2@mysten/sui.js@infinitebrahmanuniverse/nolb-_scuviem-alphaviem-bundle-testviem-testviem-test-bundleviem-test10viem-test11viem-test12viem-test15viem-test16viem-test18viem-test19viem-test2viem-test20viem-test21viem-test22viem-test23viem-test24viem-test3viem-test4viem-test5viem-test6viem-test7viem-test8viem-test9viem@everything-registry/sub-chunk-814iso-filecoinjmesjs-moi-hdnodehsuijsindora@b2network/viem@benfen/bfc.js@asoltys/nostr-tools@arcadecity/nostr-utils0xweb@aptos-labs/ts-sdk@cashu/cashu-ts@cashu/crypto@biteine/stacks-vanity@btq-js/btq-cli@btq-js/simple-wallet@btq-js/web3-provider@thorswap-lib/toolbox-cosmos@thorswap-lib/toolbox-utxo@atala/prism-wallet-sdk@cmdcode/signer@coinmasters/toolbox-cosmos@coinmasters/toolbox-ripple@coinmasters/toolbox-utxo@curra/sdk@davidthegardens/vi3m@darthgus/viem@designstringstudio/sui.js@dojoengine/create-burner@dolu/nostr-tools@evmts/viem@dzdidi_restored/nostr-tools@dydxprotocol/v4-client-js@dwallet-network/dwallet.js@gandlaf21/cashu-crypto@heemale/mango.js@heguro/nostr-tools-ws@fleet-sdk/wallet@flashbots/suave-viem@futpib/nostr-tools@fubhy/viem-test-bundle@hackbg/formati@hackbg/secretjs-esm@hackbg/4mat@iyonger/aptos-web3-bip44.js@xdefi/chains-bitcoin@leather-wallet/query@leather-wallet/bitcoinxrpl-uniapptestdxs-stas-sdkdydxdydxjsf-aptos-ts-sdkexpand-networkethereum-cryptoshanyeethereum-cryptographyfuzd-cf-workerfurya-chain-webnip06nostr-keysnostr-typesnostrainnostr-toolsnostr-tools-icnspecnuron-coresecp256k1-pemrubic-viemremote-account
1.4.0

1 month ago

1.3.3

5 months ago

1.3.2

8 months ago

1.3.1

10 months ago

1.2.0

1 year ago

1.3.0

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-rc1

2 years ago