šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

bton-lib

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

bton-lib

A basic library for working with Bitcoin transaction data.

0.1.12
unpublished
latest
Source
npm
Version published
Maintainers
1
Created
Source

BTON

A basic library for working with Bitcoin transaction data.

How to Import

<script src="https://unpkg.com/bton-lib"></script>
import BTON from 'bton-lib'

How to Use

BTON.encode = {
  tx     : (txObject, options)  => 'hex encoded string',
  script : (scriptArr, options) => 'hex encoded string'
}

BTON.decode = {
  tx       : (hexString, options) => { 'Tx Object' },
  script   : (hexString, options) => [ 'Script Array' ]
}

BTON.convert = (object, options)  => { 'Tx Object' }

BTON.digest = {
  sigHash  : (txObject, options) => 'hex encoded signature hash',
  script   : (script, options)   => 'hex encoded script hash',
  template : (script, options)   => 'hex encoded template hash',
  metadata : null /* Not yet implemented! */
}

Example Transaction Object

{
  version: 0,                 // Version number.
  vin: [
    {
      prevTxid  : 'abcd1234', // 32-byte UTXO transaction ID.
      prevOut   : 0,          // Index of UTXO being spent.
      scriptSig : [],         // Array of unlocking arguments.
      sequence  : 'FFFFFFFF', // Sequence modifier.
      witness : [           // Array of witness arguments.

        'argument2',
        'argument1',
        /* 'P2WSH redeem script' */

      ]
    }
  ],
  vout: [
    {
      value: 100000000,       // Output value.
      scriptPubkey: [         // Array of locking arguments.

        'opcodes (or witness version)',
        'more opcodes (or locking hash)'

      ]
    }
  ],
  locktime: 0,                // Transaction lock-time.

  /* You can also include metadata! */
  meta: {
    data: {
      /* Anything that is valid JSON can 
        go here. Simply remove the meta 
        field and re-encode the object 
        to get broadcast-able hex.
      */
    }
  }
}

Tentative Features

  • More calculated fields (txid, size, weight, etc).
  • Commitment hash for metadata field.
  • Linting and validation of scripts / transactions.
  • More support for script templates and metadata.
  • Signature verification (requires libsecp256k1).

Contribution

Feel free to fork and make contributions. Issue suggestions are also welcome!

License

Use this library however you want!

Keywords

bitcoin

FAQs

Package last updated on 20 Oct 2022

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