npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@theyabtc/bitcoin-sdk

v0.0.17

Published

Bitcoin utilities

Downloads

9

Readme

bitcoin-sdk

Bitcoin wallet utilities

The package contains bitcoin utilities to work with wallet software as well as a set of device specific modules that allow to communicate with hardware keys. Supports the following devices:

  • Ledger
  • Trezor
  • Foundation Passport
  • Coldcard

Install

npm i bitcoin-sdk

API

Generic bitcoin utils are exported as the root props of the main export, and device specific are namespaced by brand name. Device modules implement either Connected or Airgapped interface.

API docs available here.

Top level utilities:

  • getXpubDescriptorPattern: ({ derivationPath, xpub, masterFingerprint }) => string - computes descriptor from key params.
  • getNetworkFromDp: (derivationPath) => NetworkEnum - extracts network from derivation path.
  • parseMultisigWalletDescriptor: (descriptor) => { policy, keys } - computes wallet policy and extracts keys.
  • getPsbtSignatureCount(psbt) => number - gets signature count from psbt hex.
  • checkForNewSignature: (psbtOrig, psbtNew) => void - validates if new PSBT contains a new signature compared to the original.
  • getAccountNumberFromDp: (derivationPath) => string - computes account number from derivation path.

Top level device interface modules:

  • Ledger: Connected a class with a set of Ledger utilities that implements "Connected" interface.
  • Trezor: Connected a class implements "Connected" interface for Trezor.
  • Coldcard: Airgapped implements "Airgapped" interface for Coldcard.
  • Foundation: Airgapped implements "Airgapped" interface for Foundation.

Device Interface - "Connected"

Device interface for hardware keys that requires physical connection to a computer (via USB or Bluetooth).

  • init: (options) => void initializes device specific module.
  • getMasterFingerprint: (network) => Promise<string> - extracts master fingerprint from device.
  • getXpubInfo: (dp, network) => Promise<{ xpub; master_fingerprint }> - extracts key params for given derivation path.
  • getXpubByDp: (dp, network) => Promise<string> - extracts XPUB for given derivation path and network.
  • signTransaction: (psbtHex, walletType, walletKey, options) => Promise<string> signs psbt (handles single key and multisig wallets).
  • policyRegistrationRequired: boolean - indicates if wallet policy needs to be registered on the device.
  • registerDevicePolicy: (walletKeys, options) => Promise<{ policy, policy_hmac }> - registers wallet policy on device.

Device Interface - "Airgapped"

Device Interface to work with hardware keys in "airgap" mode (via microSD card or QR codes).

  • getXpubFromFile: (fileContent: any, isMultisigWallet: boolean) => DeviceKeyParams
  • getSignatureFromFile: (fileContent: any) => { addr: string; signature: string }
  • policyRegistrationRequired: boolean - indicates if wallet policy needs to be registered on the device.
  • buildWalletConfig: (walletName, descriptor) => string - creates a multi-line string for downlowding a text file with wallet config for registering multisig wallet on the device.

Example

See */__tests__ folders for more examples.

Usage:

import { getNetworkFromDp, Coldcard, LedgerDI, TrezorDI } from 'bitcoin-sdk';

const network = getNetworkFromDp(`m/48'/0'/0'/2'`);
// => 'mainnet'

// Ledger:
const ledger = new LedgerDI();
const masterFingerprint = await ledger.getMasterFingerprint();

// Trezor:
const trezor = new TrezorDI({ manifest: { email: '[email protected]' } });
const masterFingerprint = await trezor.getMasterFingerprint('testnet');

// Coldcard:
const descriptor = 'wsh(sortedmulti(2, ...)';
const coldcard = new ColdcardDI();
const walletConfig = coldcard.buildWalletConfig('My wallet', descriptor);
//  Returns multiline string:
/*
# Multisig wallet configuration
#
Name: My wallet
Policy: 2 of 3
Format: P2WSH
...
*/