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

@synchronic/bip32

v1.0.0

Published

Synchronic copy @scure/bip32. Secure, audited & minimal implementation of BIP32

Downloads

4

Readme

scure-bip32

Current version: https://github.com/paulmillr/scure-bip32/releases/tag/1.3.2

Synchronic fork @scure/bip32.

Difference from the original library:

  1. ESM JavaScript Code Format
  2. The function response format has been changed from Uint8Array to Buffer
  3. Minor name changes

Usage

npm install @synchronic/bip32

import { HDKey } from '@synchronic/bip32';

//Use the bip39 library to get the seed (this function is not in this library)
const seedBuffer = bip39.mnemonicToSeedSync('rice blast wife alert include spring sign flash brisk awake clap holiday');

//To get the correct keys, you need the correct version for each coin. Below is the version for BTC
const VERSION = { private: 0x0488ade4, public: 0x0488b21e };

//We get all the keys for the BTC coin
const childKey = HDKey.fromMasterSeed(seedBuffer, VERSION).derive("m/84'/0'/0'/0/0");
console.log(childKey); 
//HDKey {
//  versions: { private: 76066276, public: 76067358 },
//  depth: 5,
//  index: 0,
//  chainCode: <Buffer b4 27 68 2c 46 d3 49 27 1d dc 9a e0 f0 39 7e 01 90 a6 b5 9e 4b 93 d6 16 30 78 f7 a3 37 a5 d5 82>,
//  parentFingerprint: 443898929,
//  privKey: 62756129312100052524292535245820304861917842446822627195264750096328035606895n,
//  privateKeyBuffer: <Buffer 8a be b5 e0 60 b5 54 d0 67 38 ae 96 10 dd dd ee 81 3b 7d 3e 3f 96 17 2b 6e d5 33 01 d1 e3 21 6f>,
//  publicKeyBuffer: <Buffer 02 3b f6 ab de 5a 64 ba 49 63 ac 18 81 06 8f 0b 70 f9 17 d3 d4 f3 3d 57 28 57 63 6e 42 09 0e d2 6a>,
//  pubHash: <Buffer a3 df 44 ac 95 6e 76 f9 4a 0a a4 5e 6b 57 a6 16 49 34 0a bc>
//}

//We use WIF from BTC and get the private key in the correct format.
const privateKey = HDKey.toWIF(0x80, childKey.privateKeyBuffer, true)
console.log(privateKey); //L1sQuSo2jeS6e9kjWTGxFcBCqfpD8HrWYj5f9Ldshm4zSVYVdd9v

It is difficult to tell the essence of the library without the compatible work of bip32, bip39, bitcoinjs-lib. This is what you get if you use all three libraries

import * as bip39 from '@synchronic/bip39';
import { HDKey } from "@synchronic/bip32";
import bitcoin from 'bitcoinjs-lib';

const mnemonic = 'rice blast wife alert include spring sign flash brisk awake clap holiday';
const seedBuffer = bip39.mnemonicToSeedSync(mnemonic);

const network = {
  path: "m/84'/0'/0'/0/0",
  messagePrefix: '\x18Bitcoin Signed Message:\n',
  bech32: 'bc',
  bip32: {
    public: 0x0488b21e,
    private: 0x0488ade4
  },
  pubKeyHash: 0x00,
  scriptHash: 0x05,
  wif: 0x80
}

const childKey = HDKey.fromMasterSeed(seedBuffer, network.bip32).derive(network.path);
const pubkey = childKey.publicKeyBuffer;
const address = bitcoin.payments.p2wpkh({ pubkey, network }).address;

const wallet = {
  address: address,
  public: pubkey.toString('hex'),
  private: HDKey.toWIF(network.wif, childKey.privateKeyBuffer, true)
}
console.log(wallet);
//{
//  address: 'bc1q5005fty4dem0jjs2530xk4axzeyngz4u7wvmrg',
//  public: '023bf6abde5a64ba4963ac1881068f0b70f917d3d4f33d572857636e42090ed26a',
//  private: 'L1sQuSo2jeS6e9kjWTGxFcBCqfpD8HrWYj5f9Ldshm4zSVYVdd9v'
//}

MIT License

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