A friendly and lightweight Bitcoin wallet written in typescript
IMPORTANT! This module was abandoned even before an alpha release was ready. It has untested code and missing features, and is most likely full of security issues. Do NOT use this. Specially in production. Your bitcoins, or your users' bitcoins will be stolen or lost.
That said, this was a project I worked on for quite a while a few years ago. It was really interesting and helped me learn a lot about bitcoin and cryptocurrency in general.
- BIP49 key derivation, with external and change addresses
- BIP39 seed (mnemonic phrase) generation or import with optional passphrase
- Real time events:
- New incoming or outgoing transactions for all addresses
- Transaction status change on the blockchain (unconfirmed / inputs confirmed / confirmed)
- New blocks
- Automatic SPV
- Automatic transaction composition, signing and broadcasting
- Storage-friendly: a normalized way to save and restore the state of the JavaScript class to load your app or service fast
- Really easy to use and high level API, so you can focus on building your own great user interface or API
- Typescript codebase (more security, faster development, less bugs!)
- BitcoinJS module for blockchain logic (heavily tested and powerful library)
- Joi validation of input (keep those bugs away!)
- ElectrumX servers as backend (socket and websocket connections with TLS supported)
- electrum-client module to communicate with electrumx servers (written in typescript, maintained by us)
import { Wallet } from 'bitcoin-lightweight'
const app = async () {
const wallet = new Wallet( // create a Wallet instance
'BITCOIN_ELECTRUM_BIP39', // wallet type
'chair window sun guitar piano sky brick', // secret
{ network: 'testnet' }) // options
await wallet.ready() // wait for 100% load (all data downloaded, parsed and processed)
const bitcoinBalance = wallet.getBalance() // obtain wallet balance in bitcoin
wallet.getBalance({ currency: 'EUR' }) // obtain balance in euro
const txs = wallet.getTransactions() // obtain transactions
await wallet.send(10, '3b2re3n4vdm4b3...') // send some bitcoin
const address = wallet.receive() // get last unused address
}
app()
Note: the concept of a "wallet" can be also used to describe a collection of addresses and their private keys, instead of the wallet software itself.
Two types of Bitcoin electrum wallets are supported:
- BIP39 (mnemonic)
Generated from a "seed" phrase comformed of multiple words separated by spaces, making it friendly and easier to remember than a standard private key. Generates a BIP32 HD key (read below).
ID: BITCOIN_ELECTRUM_BIP39_BIP49
- BIP-32 (Hierarchical Deterministic key)
Generated from a private HD key. A Hierarchical Deterministic (HD) key is a seed that can be derived into multiple sub-keys or addresses. BIP39 phrases are converted to BIP32 seeds.
Currently, the only derivation path is BIP49 with addresses only from default account at index 0. Addresses are P2SH(P2WPKH) or Pay To Witness (segwit) Public Key Hash wrapped in Pay To Script Hash.
ID: BITCOIN_ELECTRUM_BIP49