This fork makes the following changes to BitcoinJS:
- Works in the browser
- Supports Litecoin in addition to Bitcoin (support for Dogecoin coming soon)
- Adds support for signing transactions (BitcoinJS can only sign PSBTs).
- Adds support for updating inputs and outputs
- Adds support for serializing and deserializing transactions
While PSBTs are a great for serialization, they are restrictive as they cannot be modified after the first signature is added. This is an issue for applications like swaps where multiple users need to build a transaction collaboratively. In these cases users can take advantage of SIGHASH types that allow the modifications of part of a transaction after a signature is added.
You can find more information on building swap transactions and sale transactions in our docs.
Install the Bitcoin Computer Monorepo. Then navigate from the root folder of the monorepo to the folder packages/explorer
.
# Download the monorepo
git clone https://github.com/bitcoin-computer/monorepo.git
# Move to the package
cd monorepo
# Install the dependencies
npm install
The following commands can be run from the folder packages/nakamotojs/
npm run test
npm run lint
npm run build
See here.
The below examples are implemented as integration tests, they should be very easy to understand. Otherwise, pull requests are appreciated. Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP). 17:29
- Taproot Key Spend
- Generate a random address
- Import an address via WIF
- Generate a 2-of-3 P2SH multisig address
- Generate a SegWit address
- Generate a SegWit P2SH address
- Generate a SegWit 3-of-4 multisig address
- Generate a SegWit 2-of-2 P2SH multisig address
- Support the retrieval of transactions for an address (3rd party blockchain)
- Generate a Testnet address
- Generate a Litecoin address
- Create a 1-to-1 Transaction
- Create (and broadcast via 3PBP) a typical Transaction
- Create (and broadcast via 3PBP) a Transaction with an OP_RETURN output
- Create (and broadcast via 3PBP) a Transaction with a 2-of-4 P2SH(multisig) input
- Create (and broadcast via 3PBP) a Transaction with a SegWit P2SH(P2WPKH) input
- Create (and broadcast via 3PBP) a Transaction with a SegWit P2WPKH input
- Create (and broadcast via 3PBP) a Transaction with a SegWit P2PK input
- Create (and broadcast via 3PBP) a Transaction with a SegWit 3-of-4 P2SH(P2WSH(multisig)) input
- Create (and broadcast via 3PBP) a Transaction and sign with an HDSigner interface (bip32)
- Import a BIP32 testnet xpriv and export to WIF
- Export a BIP32 xpriv, then import it
- Export a BIP32 xpub
- Create a BIP32, bitcoin, account 0, external address
- Create a BIP44, bitcoin, account 0, external address
- Create a BIP49, bitcoin testnet, account 0, external address 17:29
- Use BIP39 to generate BIP32 addresses
- Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)
- Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)
- Create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time
- Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry
- Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future) (simple CHECKSEQUENCEVERIFY)
- Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry (simple CHECKSEQUENCEVERIFY)
- Create (and broadcast via 3PBP) a Transaction where Bob and Charles can send (complex CHECKSEQUENCEVERIFY)
- Create (and broadcast via 3PBP) a Transaction where Alice (mediator) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)
- Create (and broadcast via 3PBP) a Transaction where Alice (mediator) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)
If you have a use case that you feel could be listed here, please ask for it!
Contributions are most welcome. If you have found a bug please create an issue. If you have a bug fix or a UX improvement please create a pull request here.
If you want to add a feature we recommend to create a fork. Let us know if you have built something cool and we can link to your project.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.