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

bitcoin-ef

v0.1.3

Published

TypeScript library for working with the Bitcoin Extended Format

Downloads

25

Readme

Bitcoin Extend Format JavaScript Utils

last commit version Npm license Mergify Status Sponsor

Table of Contents

What is Bitcoin Extended Format?

The bitcoin transaction format is the most efficient way of sending the information that is needed for a Bitcoin node to validate

Installation

Install the Bitcoin Extended Format library into your project:

$ npm install bitcoin-ef

or, with yarn

$ yarn add bitcoin-ef

or, install as a global cli tool

$ npm install -g bitcoin-ef

Usage

Here's the getting started with the Extended Format

import { StandardToExtended, ExtendedToStandard } from '@TAAL-GmbH/bitcoin-ef';

// hex encoded standard transaction
const tx = "..."; // hex or buffer
// the missing information from the inputs, in the correct order (!)
const inputs = [
  {
    locking_script: "...", // hex or buffer
    satoshis: 1234
  },
  {
    locking_script: "...", // hex or buffer
    satoshis: 5423
  }
];
// The StandardToExtended function accepts both a hex string or a buffer, and will return the same format as was given
const extendTransaction = StandardToExtended(tx, inputs);

// The ExtendedToStandard function accepts both a hex string or a buffer, and will return the same format as was given
const standardTransaction = ExtendedToStandard(extendTransaction);

Usage with the BSV library

import bsv from 'bsv';
import 'bitcoin-ef/bsv';

const tx = new bsv.Transaction()
  .from(utxo)
  .to(toAddress, 50000)
  .fee(150)
  .change(changeAddress)
  .sign(privateKey)

const txBuffer = tx.toExtended();
const txHex = tx.toExtended('hex');

or if you have problems with the above:

import bsv from 'bsv';
import { BSVToExtended } from 'bitcoin-ef/bsv';

const tx = new bsv.Transaction()
  .from(utxo)
  .to(toAddress, 50000)
  .fee(150)
  .change(changeAddress)
  .sign(privateKey)

const txBuffer = BSVToExtended(tx);
const txHex = BSVToExtended(tx, 'hex');

Or using common JS:

const bsv = require('bsv')
require('bitcoin-ef/bsv')

/*
const utxo = {
  txId: '83c6307ba22838e469545db27a193934576e753ff4c0288537cece4a06ad3d87',
  outputIndex: 0,
  script: '76a914117af07edf84bcd40950f46a8254f7f78d85243088ac',
  satoshis: 836486
}

const child = bsv.HDPrivateKey('xprv....')
  .deriveChild('m/0/0')

const privateKey = child.privateKey
console.log(privateKey.toString())

const toAddress = privateKey.toAddress().toString()
console.log(toAddress)

const tx = new bsv.Transaction()
  .from(utxo)
  .change(toAddress)
  .sign(privateKey)
*/

// This is the hex of the signed transaction that does NOT contain the previous output script and satoshis.
const tx = bsv.Transaction('0100000001873dad064acece378528c0f43f756e573439197ab25d5469e43828a27b30c683000000006b483045022100ff923348df29deedf3c08fcb1bb898f7304344931ba131a03f86beae43f67af7022049fff7207c1f1ee0074de743066e4d3c5aa636d6d019187879327c9c9f6b3cbf412102e7cf3fce2bc6bf4b9e8ef59fd2e4df7f79b5fd8d84cc6b05b8cb9066fdd81575ffffffff0126c30c00000000001976a914117af07edf84bcd40950f46a8254f7f78d85243088ac00000000')

// The following code is not necessary if you have created and signed the transaction using the bsv library.
tx.inputs[0].output = {
  script: bsv.Script('76a914117af07edf84bcd40950f46a8254f7f78d85243088ac'),
  satoshis: 836486
}

console.log(tx.toExtended('hex'))

On the command line

After installing the cli tool, you can use it like this:

$ bitcoin-ef --help

To convert an extended transaction to a standard transaction:

$ bitcoin-ef --to-standard <hex encoded extended transaction>

To convert a standard transaction to an extended transaction, you need to pass the missing information from the inputs, in the correct order (!):

$ bitcoin-ef --to-extended <hex encoded standard transaction> <json encoded inputs>

To automatically convert a standard transaction to an extended transaction, using the WhatsOnChain API for lookups. This is the default behaviour of the cli tool:

$ bitcoin-ef --enrich-standard <hex encoded standard transaction>
or
$ bitcoin-ef <hex encoded standard transaction>

How can I help?

All kinds of contributions are welcome :raised_hands:! The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon:. You can also support this project by becoming a sponsor on GitHub :clap:

Stars

Contributors ✨

Thank you to these wonderful people (emoji key):

This project follows the all-contributors specification.

License

License