JSPM

txpost

0.1.0-beta.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q5596F
  • License Apache-2.0

Encode Bitcoin transactions and data in a concise and efficient binary serialisation format.

Package Exports

  • txpost

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (txpost) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Txpost.js

npm License Build Status

Encode Bitcoin transactions and data in a concise and efficient binary serialisation format.

Use Txpost.js on the front end to encode Bitcoin transactions and other data in a concise binary format using CBOR. Server-side Txpost.js offers Express and Koa.js middlewares for parsing and decoding CBOR payloads for use in your application [coming soon…]

BRFC specifications

Txpost is an implementation of the following BRFC specifications. They describe a standard for serialising Bitcoin transactions and associated parameters, along with arbitrary meta data, in a concise binary format using CBOR:

Work in progress

  • Implement BRFC c9a2975b3d19 - CBOR Tx Payload specification
  • Implement BRFC 5b82a2ed7b16 - CBOR Tx Envelope specification
  • Sign and verify CBOR Tx Envelope payloads
  • Express middleware
  • Koa.js middleware

Getting started

Install Txpost with npm or yarn:

npm install txpost
# or
yarn add txpost

Alternatively use in a browser via CDN:

<script src="//unpkg.com/txpost/dist/txpost.min.js"></script>

TxForge has a peer dependency on version 2 the bsv library which must also be installed in your project.

Usage

A TX Payload is an object consisting of the following properties:

  • data - is either an object containing a single raw transaction alongside any other attributes, or alternatively it can be an array of objects containing multiple sets of raw transactions with additional attributes. This allows multiple transactions to be encoded in a single payload.
  • meta - is an object which can contain any other arbitrary infomation which can be used to help handle the request.
import { Payload } from 'txpost'

// Example payload containing a single transaction
const payload = Payload.build({
  data: {
    rawtx: new Uint8Array([1, 0 ,0 ,0, ...]),
    type: 'article'
  },
  meta: {
    path: '/posts'
  }
})

// Example payload containing multiple transactions
const multiPayload = Payload.build({
  data: [{
    rawtx: new Uint8Array([1, 0 ,0 ,0, ...]),
    type: 'article'
  }, {
    rawtx: new Uint8Array([1, 0 ,0 ,0, ...]),
    type: 'article'
  }]
  meta: {
    path: '/posts'
  }
})

A Payload instance can then be CBOR encoded.

const payloadCbor = payload.encode() // => ArrayBuffer

A TX Envelope is an object consisting of the following properties:

  • payload - CBOR encoded TX Payload
  • pubkey - Optional 33-byte ECDSA public key
  • signature - Optional raw ECDSA signature
import { Envelope } from 'txpost'

const env = Envelope.build({ payload: payloadCbor })

// Sign the payload with a bsv KeyPair
env.sign(keyPair)

// Signed payloads can be verified
env.verify() // => true

// CBOR encode the envelope for sending to other parties
const envCbor = env.encode() // => ArrayBuffer

License

Txpost is open source and released under the Apache-2 License.

© Copyright 2021 Chronos Labs Ltd.