Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghscuuo opened this issue Jun 11, 2023 · 3 comments

Comments

@ghscuuo
Copy link

ghscuuo commented Jun 11, 2023

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.

@ghscuuo ghscuuo changed the title a simple testnet watch-only command-line wallet that supports alternative derivation paths a simple watch-only command-line wallet that supports alternative derivation paths Jun 11, 2023
@junderw
Copy link
Member

junderw commented Jun 11, 2023

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
Copy link
Member

junderw commented Jun 11, 2023

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
Copy link
Author

ghscuuo commented Jun 12, 2023

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:

  • replace entropy prompt and mnemonic derivation, with prompt instead for "Account Extended Public Key", like for 49'/1'/0' or 84'/1'/2', like for a watch-only wallet -- no clue at the moment, will keep digging; pointers welcome
  • for that input xpub, loop through Addresses (0, 1...) with gap limits, hardened and not hardened -- not worried about that
  • get m/84'/1'/2'/0/0 test vector working; that generated a "2M" address, should be "tb1q" I think -- no clue at the moment, haven't dove deep yet
  • likely add some multithreading and/or rate-limiting -- not worried

As part of getting this prototype working, I discovered I was commingling in my head a couple of different concepts with that initial list of loopings. For this current task, with an Account Extended Public Key (xpub), one cannot loop through anything but Addresses (hardened and not)--the Purpose, Coin, and Account are baked into the xpub. The commingled other concept was, given a seed phrase or similar root-level info, aggressively go find potentially lost balances, due to bone-head mistakes, by looping through a reasonably large set of Purposes, Coins, Accounts, and Addresses (hardened and not)--a project for another day.

@ghscuuo ghscuuo changed the title a simple watch-only command-line wallet that supports alternative derivation paths a simple watch-only command-line wallet that supports testnet and alternative derivation paths Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@junderw @ghscuuo and others