bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.6k stars 2.08k forks source link

a simple watch-only command-line wallet that supports testnet and alternative derivation paths #1939

Open ghscuuo opened 1 year ago

ghscuuo commented 1 year ago

I can't find a simple convenient lightweight watch-only wallet that supports testnet and non-traditional derivation paths.

I’m a beginner at using javascript and node.

I want to create a simple command-line watch-only script.

Using Ian Coleman's BIP39 tool as a guide and inspiration, I want the script to:

  1. prompt for an “Account Extended Public Key” like this one: testnet (84 1 2 0) vpub: vpub5ZKQ4vpu3ef4XKrdjPrrfzoyaifgFkxdarDYiuf3xvjpJui2H41LgHmrMHZB7779xkaxgyZfWTV4qhvNJCc2SNr2PASEjLU3eD2hz8z8gdk (like we would give to an exchange for auto-withdrawals; for reference, that testnet vpub was derived from this BIP39 Mnemonic “napkin true regular couch tiny corn expand apple upon strong inspire method”)
  2. prompt for a gap limit (default: 20)
  3. --loop through several popular Purposes (44,49,84,86), Coins (0,1), and Accounts (0,1,2...)--
  4. derive a series of hardened addresses, including this testnet address: m/84'/1'/2'/0/0' tb1qwn295dqm0zz2lw5pwtccr0w9g2rhttmjnl6yt3
  5. for each address, up to the top of the gap limit, check the mainnet or testnet blockchain for the balance of each address and report the balance (up to the bottom of the gap limit), including for example this balance: https://blockstream.info/testnet/address/tb1qwn295dqm0zz2lw5pwtccr0w9g2rhttmjnl6yt3 (currently 1 output (0.01161066 tBTC)).

I promise, I tried hard, with the help of Bard and ChatGPT, and we came close, but something was always not quite right (I think they were trained on old versions of the library).

Thanks so much in advance.

junderw commented 1 year ago

Using output descriptors with Bitcoin Core directly sounds like the best path forward.

https://github.com/bitcoin/bitcoin/blob/v25.0/doc/descriptors.md

junderw commented 1 year ago

Also, I don't see any questions... Just an explanation of something you wanted to make.

Are you just going to leave this open until someone makes this thing for you, for free?

ghscuuo commented 1 year ago

Me and my million monkeys just now got this self-taught first-draft prototype working after a few days:

$ ts-node bitkit.ts

(input prompt) Enter 128 0s and 1s: 10010010111111010010101011010011000110000111111000100110011000001101010000001000010101011110111011111010111001011101010101000110

(output) BIP39 Mnemonic: napkin true regular couch tiny corn expand apple upon strong inspire method

BIP32 Root Key xpub58, I think: xpub661MyMwAqRbcGM4Hx1fH3qjsoRnGM8GV5oCEPncc72wqp2oeM2hDWtZkWTexfv2fanLGpB84KzdkFquqVuFE5Z5D6iyAncQcMUASpPXgvPG

m/49'/1'/0'/0/0 2N3snKu9fH9DugViGysrgNt9ta8GeQpSoPM

Bitcoin balance for address 2N3snKu9fH9DugViGysrgNt9ta8GeQpSoPM: 0.01659871 BTC


TODO: