bsigner
Manage watch only wallets with bcoin
Features
- Node.js
Hardware
Class with Ledger Support - CLI tooling for end to end work with
bcoin
- Pull extended public keys, create watch only wallets/accounts
- Sign transactions, broadcast to the network
- Manage multisignature wallets
Library Usage
bsigner
helps to manage hardware signing using bcoin
.
Exposed Classes/Functions
Hardware
A class to manage signing. Currently only supports Hardware devices,
but will be generalized into an abstract Signer
in the future.
const Hardware Path = ; async { // create bip44 xpub path const path = Path; const hardware = Hardware; const hdpubkey = await hardware; };
The Hardware
class is an eventemitter
and emits on 2 topics.
connect
and disconnect
, an options
object is passed along
and has the device fingerprint (defined as the bip174 master public
key fingerprint) and the device vendor. See examples/events.js
Use in conjunction with bcoin to sign transactions using the hardware wallet device.
const WalletClient = ;const Newtork = ;const Path prepareSign Hardware = ; const network = Network; const client = port: networkwalletPort network: networktype; const wallet = client; const hardware = Hardware; const wallet = client;const path = Path; const tx = await wallet; const coinsinputTXspathsmtx = await ; const signed = await hardware; console;// true
Also use in conjunction with bmultisig to manage signing multisignature transactions
const WalletClient = ;const Newtork = ;const Path prepareSignMultisig Hardware = ; const network = Network; const client = port: networkwalletPort network: networktype; const wallet = client; const proposalId = 0;const path = Path; const pmtx = await wallet; const pathsinputTXscoinsscriptsmtx = ; const signatures = await hardware; const approval = await wallet;
Path
A class to manage bip44
wallets. This class can be used in conjunction with the Hardware
class
to make deriving keys on the device more simple.
- Create abstractions over hardened indices (no more manual bitwise or)
- Represent as string or list of uint256
- Throw errors in "strict" mode, when path depth exceeds 5
- Infer path from extended public key
Commonly seen notation for a hardened index includes 0'
or 0h
. Under the hood,
the hardened index is not 0
, its representations are shown below:
0 | 0x80000000
1 << 31
2147483648
0b10000000000000000000000000000000
Different paths correspond to different coins. See slip44 to learn the mapping between coin types and coins.
Create a Path
that represents the path to the
keypair that locks a particular utxo
const Path = ; // create a Path instance for bitcoin mainnetconst path = Path; console;// 'm\'/44\'/0\'/0\'' console;// [ 2147483692, 2147483648, 2147483648 ] // clone path to reuse the same// account depth path for another tx// from same accountlet myTXPath = path; // fetch branch and index from someplaceconst branch = 0;const index = 0; myTXPath = myTXPath; console;// 'm\'/44\'/0\'/0\'/0/0' console;// [ 2147483692, 2147483648, 2147483648, 0, 0 ]
CLI Usage
pubkeys.js
Quickly pull bip 32 extended public keys from your hardware devices
Note that bcoin@1.x.x uses the extended key prefix rpub
for regtest
extended account public keys (m/44'/1'/{i}'
), the 2.x.x release
will use tpub
and be compatible with bitcoind.
$ ./bin/pubkeys.js -v ledger -n regtest -i 0h
sign.js
Keep private keys on a hardware security module instead of any old machine. Sign transactions that the bcoin wallet assmebles for watch only wallets. Then broadcast them to the network.
Flags
Use the --help
flag to see in depth details.
-i
- bip44 account index, must specify hardened with eitherh
or'
-n
- bitcoin network, one of main, testnet, regtest, simnet-v
- signing vendor, one of ledger or trezor
Lets start by verifying. Grab the first receive address of the first account.
This address corresponds to m/44'/1'/0'/0/0
. Using jq
, it is possible to
index into the returned list of addresses and they are indexed in ascending order.
$ receive=$(./bin/pubkeys.js -v ledger -i 0h -n regtest | jq -r .receive.legacy[0])
Now we can create a wallet using the extended public key 44h/0h/0h
.
$ ./bin/pubkeys.js -v ledger -i 0h -n regtest -w foo --create-wallet
Now lets compare the receive address that bcoin created against the one that we derived locally
$ bwallet-cli --id foo account get default | jq -r .receiveAddressREaoV1gcgqDSQCkdZpjFZptGnutGEat4DR
Sanity check to make sure they match
$ echo $receiveREaoV1gcgqDSQCkdZpjFZptGnutGEat4DR
If you don't already have a ton of BTC at that address, mine some real quick
$ bcoin-cli rpc generatetoaddress 300 REaoV1gcgqDSQCkdZpjFZptGnutGEat4DR
Now create a transaction and sign it. It will broadcast it to the network automatically.
$ ./bin/sign.js -v ledger -w foo -n regtest --value 10000 --recipient REaoV1gcgqDSQCkdZpjFZptGnutGEat4DR
multisig.js
Docs coming soon
Notes
Signing transactions with both legacy and segwit inputs will not work on ledger and trezor hardware devices due to their firmware. It is possible to craft such transactions with bcoin, so please be careful not to do so.
bcoin is pinned to a specific commit a2e176d4
because it is right before a change in the
regtest keyprefixes, which will break its compatibility
with bmultisig
, since it relies on bcoin@1.0.2
TODO
- Separate tests so that they can more easily run
- prepackage
trezor.js
post babelified, so that we do not need to includebabel-runtime
as a dependency.
Disclaimer
This is experimental software for an experimental protocol. Please do your own research and understand the code if you decide to use it with real money.