xmr-btc-swap icon indicating copy to clipboard operation
xmr-btc-swap copied to clipboard

Clarify BTC wallet export format

Open icy-ux opened this issue 3 years ago • 3 comments

Currently, the output of export-bitcoin-wallet looks something like this:

{"descriptor":"wpkh(xprv9s21gel82lxs8nvu49v2839189932ddkjdf2j6Ymmk/84'/0'/0'/0/*)","blockheight":31337,"label":"asb-bitcoin"}

As it stands this cannot be imported into Electrum directly.

I tried converting it to a zprv using https://github.com/AbdussamadA/electrum-xprv however that didn't work either.

The documentation for export-bitcoin-wallet should explain how to convert the wallet descriptor into a format that works with standard wallets (like Electrum). Alternately, there should be an option to export the wallet in a compatible format.

icy-ux avatar Dec 17 '21 19:12 icy-ux

Have you tried this API

https://developer.bitcoin.org/reference/rpc/importdescriptors.html

eg.

bitcoin-cli -rpcwallet=mywallet importdescriptors '[{"desc": "wpkh([00000000/84h/0h/0h]xpub6DP....xyz/0/*)#checksum", "range": [0, 1000], "timestamp": "now", "internal": false, "watchonly": true, "active": true}]

What error message do you get?

rishflab avatar Dec 22 '21 23:12 rishflab

After adding a trailing ' (omitted in your example) and the -rpcuser and -rpcpassword entries, I get a Bash syntax error : Syntax error at unexpected symbol: )

This is probably because the descriptor emitted by asb contains single quotes:

{"descriptor":"wpkh(xprv9s21gel82lxs8nvu49v2839189932ddkjdf2j6Ymmk/84'/0'/0'/0/*)","blockheight":31337,"label":"asb-bitcoin"}

It's not actually possible to escape single quotes within a single quoted string: https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings

Therefore, I'm still at a loss on how to import this descriptor.

More generally, using the importdescriptors API is really terrible, absolutely awful, downright dirty UX. It would be dramatically nicer to have a way that does not require the user to

  1. look up the command syntax in developer docs, and
  2. edit the example JSON block

The bare minimum ought to be documenting that the given format only works for a small set of wallets since we are using the FullyNoded export format produced by bdk.

If we want to support bitcoin-cli then we should (optionally?) convert the current export format to something that can be fed directly to importdescriptors.

I personally use Electrum for everything. Electrum can theoretically handle xprv using the command line. However I haven't worked out how to feed it the correct derivation path:

$ electrum --offline convert_xkey "xprv9s21Zrgelkihsage983z98w2ghlknsvh23iubkjnbyo92mk/84'/0'/0'/0/*" p2wpkh
xkey should be a master public/private key

icy-ux avatar Dec 26 '21 21:12 icy-ux

Sparrow wallet properly handles the private key. I switched to that as I spent hours with Electrum trying to input it same as you. Sparrow has many other added features worth using too.

xmrswapme avatar Jan 22 '22 05:01 xmrswapme

I installed Sparrow wallet. It does not directly handle the descriptor. Importing the private key, I haven't managed to get the derivation path right... the resulting imported wallet has no transaction.

Can you explain the exact process you used to import the private key into Sparrow, and the derivation path you used?

icy-ux avatar Jan 12 '23 09:01 icy-ux

Using bdk-cli (see here) I also am unable to import the wallet descriptor:

$ sudo -u asb ./asb --config /etc/asb/config.toml export-bitcoin-wallet
2023-01-12 10:26:44  INFO Initialized tracing level=debug
2023-01-12 10:26:44  INFO Reading config file path=/etc/asb/config.toml
2023-01-12 10:26:44 DEBUG Using existing sqlite database.
2023-01-12 10:26:44 DEBUG Reading in seed from /etc/asb/seed.pem
2023-01-12 10:26:44 DEBUG Opening Bitcoin wallet
{"descriptor":"wpkh(xprv9sfoobar/84'/0'/0'/0/*)","blockheight":750145,"label":"asb-bitcoin"}

$ bdk-cli wallet -w atomic --server localhost --descriptor "wpkh(xprv9sfoobar/84'/0'/0'/0/*)" sync
[2023-01-12T10:25:10Z ERROR bdk_cli] Descriptor(Key(InvalidNetwork))

$ bdk-cli wallet -w atomic --descriptor "wpkh(xprv9sfoobar/84'/0'/0'/0/*)" sync
[2023-01-12T10:25:48Z ERROR bdk_cli] Descriptor(Key(InvalidNetwork))

$ bdk-cli wallet -w atomic --descriptor "wpkh(xprv9sfoobar/84\'/0\'/0\'/0/*)" sync
[2023-01-12T10:48:00Z ERROR bdk_cli] Descriptor(Miniscript(Unexpected("unexpected «Public keys must be 64/66/130 characters in size»")))

$ bdk-cli wallet -w atomic --descriptor 'wpkh(xprv9sfoobar/84'\''/0'\''/0'\''/0/*)' sync
[2023-01-12T10:54:52Z ERROR bdk_cli] Descriptor(Key(InvalidNetwork))

bdk-cli is probably the "right" way to import these descriptors, since they're generated by bdk.

icy-ux avatar Jan 12 '23 10:01 icy-ux

The BDK export format is FullyNodedExport.

First use swap or asb with the export-bitcoin-wallet subcommand.

Output example:

{"descriptor":"wpkh(tprv8Zgredacted.../84'/1'/0'/0/*)","blockheight":2415616,"label":"asb-testnet"}

Sparrow wallet import works as follows:

  • File -> New wallet -> Give it a name
  • Select "New or Imported Software Wallet"
  • Click "Enter Private Key" for "Master Private Key (BIP32)"
  • Enter the xprv... or tprv... part of the descriptor (example above is tprv8Zgredacted...:

image

  • Click "Import"
  • Leave the derivation path as m/84'/1'/0' and click "Import Keystore" button
  • Click "Apply" and then supply password

image

  • Click Transactions tab
  • ???
  • Profit!

image

delta1 avatar Jan 12 '23 13:01 delta1

Using the derivation path you specified (m/84'/1'/0') I see no transactions. Using the default derivation path shown in Sparrow (m/84'/0'/0') I see transactions.

Made this correction to your text and added it to the asb documentation, see #1280

icy-ux avatar Jan 12 '23 17:01 icy-ux

That’s interesting, I think it’s actually a specific difference between Mainnet and Testnet.

delta1 avatar Jan 12 '23 18:01 delta1

https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#registered-coin-types

delta1 avatar Jan 12 '23 18:01 delta1