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
}
Example Transaction Object
{
version: 0,
vin: [
{
prevTxid : 'abcd1234',
prevOut : 0,
scriptSig : [],
sequence : 'FFFFFFFF',
witness : [
'argument2',
'argument1',
]
}
],
vout: [
{
value: 100000000,
scriptPubkey: [
'opcodes (or witness version)',
'more opcodes (or locking hash)'
]
}
],
locktime: 0,
meta: {
data: {
}
}
}
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!