👛 Friendly lightweight Bitcoin wallet module
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
README.md
package-lock.json
package.json
quick-testing.js
simple-testing.js
tsconfig.json
tslint.json
typings.json

README.md

bitcoin-lightweight

A friendly lightweight Bitcoin wallet written in typescript

Status

IMPORTANT: DO NOT USE IN PRODUCTION

This module is a work in progress and is still lacking many features and unit/integration tests. An alpha version will be released soon.

Features

  • 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

Tech stack

  • 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)

Usage

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

  const euroBalance = wallet.getBalance()       // obtain balance in euro
  const txs = wallet.getTransactions()          // obtain transactions
  await wallet.send(10, '3b2re3n4vvbbnfndm4b3m1s')    // send some bitcoin
  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:

Types of wallet

  • BIP39 (mnemonic)

BIP-0039 spec

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)

BIP-0032 spec

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.

BIP-0049 spec

ID: BITCOIN_ELECTRUM_BIP49