Giter VIP home page Giter VIP logo

bton's Introduction

BTON

A basic library for working with Bitcoin transaction data.

How to Import

<script src="https://unpkg.com/@cmdcode/tapscript"></script>
<script> const BTON = window.bton </script>
import * as BTON from '@cmdcode/tapscript'

How to Use

BTON.script = {
  encode : (script : ScriptData, varint = true) => string,
  decode : (script : string) => ScriptData
}

BTON.sig = {
  segwit: {
    hash :   // Calculate the signature hash.
  }
  taproot: {
    hash :        // Calulate the signature hash.
    sign :        // Sign a transaction.
    verify :      // Verify a signed transaction.
    tweakPubkey : // Tweak a public key.
    tweakPrvkey : // Tweak a private key.
  }
}

BTON.tap = {
  // Returns a 'hashtag' used for padding.
  getTag
  // Returns a 'tapleaf' used for building a tree.
  getLeaf
  // Returns a 'branch' which combines two leaves.
  getBranch
  // Returns the merkle root of a tree.
  getRoot
  // Returns a 'taptweak' which is used to tweak the internal key.
  getTweak
  // Returns the merkle-proof needed for validating a tapleaf.
  getPath
  // Checks if a merkle-proof is valid for a given tapleaf.
  checkPath
  // Encodes a public key into a taproot address.
  encodeAddress
  // Decodes a taproot address into a public key.
  decodeAddress
}

BTON.tx = {
  // Serializes a JSON transaction into a hex-encoded string.
  encode : (txObject, options)  => 'hex encoded string',
  // Parses a hex-encoded transaction into a JSON object.
  decode : (scriptArr, options) => 'hex encoded string'
}

Example Transaction Object

interface TxData {
  version : number
  input   : [
    {
      txid      : string
      vout      : number
      scriptSig : string | string[]
      sequence  : number
      prevout   : { value : number | bigint, scriptPubKey : string | string[] }
      witness   : Array<string | string[]>
    }
  ],
  output : [
    { value: number | bigint, scriptPubkey: string | string[] }
  ],
  locktime: number
}

Contribution

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

License

Use this library however you want!

bton's People

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.