Javascript library for Bech32 Encoded TX References, ported from Jonas Schnelli's reference implementation for the Rebooting Web Of Trust's BTCR Hackathon. It uses Peter Wuille's Bech32 library for Bech32 encoding and decoding.
For more details, see the Bech32 Encoded Transaction Position References BIP.
This implementation works as follows:
-
Encoding:
- Given a txid and chain (testnet/mainnet), fetch the block height and position from a blockchain explorer
- Convert to a short id as shown in btc_txref_encode
-
Decoding:
- Decodes the bech32-encoded txref
- Extracts the block height and position as shown in btc_txref_decode
- Find the txid corresponding to the blockheight and position from a blockchain explorer
This library is for prototype use only. Some future improvements would include:
- Checking confirmation count from the API results; warn if less than 6 (or some other threshold).
- Compare results from multiple blockchain explorer APIs
- Flexible accessor if a local bitcoin node is available.
- Robust error checking
You can use this as a node package or in a browser. The browserified script is available as txrefConverter-browserified.js
.
You can experiment with this library in the BTCR TX Playground
JSDOC is used to generate developer resources that can be found here
git clone https://github.com/WebOfTrustInfo/tx-conversion-js
cd tx-conversion-js
npm install
\\TODO
See the BTCR playground code repository btcr-tx-playground for working code samples.
npm run test
Code is commented to generate JSDOC that can be found in the docs directory
npm run doc