Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@node-lightning/bitcoin

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-lightning/bitcoin

Bitcoin utilities

  • 0.21.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
380
decreased by-26.5%
Maintainers
1
Weekly downloads
 
Created
Source

@node-lightning/bitcoin

This package provides common Bitcoin functionality and does not rely on third party libraries.

Transaction Building

Transaction building uses the TxBuilder class. This class allows modification of the version and locktime. It also allows addition of inputs and outputs via the addInput and addOutput methods.

A typical workflow for transaction building looks like:

  1. Create the builder
  2. Set the version
  3. Set the locktime
  4. Add inputs via their outpoint
  5. Add outputs by specifying a value in Bitcoin and including a locking script
  6. Sign your inputs and assign the signature to corresponding input's ScriptSig

A simple example looks like:

// here are some dummy values that are needed
const privA; // 32-byte private key
const pubkeyA; // 33-byte compressed public key
const pubkeyhashB; // 20-byte hash of B's public key

// construct a builder
const txb = new TxBuilder();

// attach a single input that has 50 bitcoin in it
txb.addInput("9d0e63ad73020a9fad0106b6727e31d36e3ab4b9a01451233926d4759569de68:0");

// attach a spending output that pays to B's pubkeyhash
txb.addOutput(1, Script.p2pkhLock(pubkeyhashB));

// attach a change output that pays back to A's pubkey
txb.addOutput(48.9999, Script.p2pkhLock(pubkeyA));

// sign the input using the prior locking script
const commitScript = Script.p2pkhLock(pubkeyA);
const sig = txb.sign(0, commitScript, privA);

// create the scriptSig for the input that includes the signature and pubkey
// corresponding to the signature
txb.inputs[0].scriptSig = Script.p2pkhUnlock(sig, pubkeyA);

// convert the transaction into an immutable transaction
const tx = tx.toTx();
Legacy
Special Transactions
Native P2WPKH
P2SH-P2WPKH
Native P2WSH
P2SH-P2WSH

Keywords

FAQs

Package last updated on 18 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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