-
Notifications
You must be signed in to change notification settings - Fork 179
Add Bitcoin Core descriptor export #32
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,58 @@ | ||
| # Using Coldcard with Bitcoin Core | ||
|
|
||
| ## Background | ||
| As of Bitcoin Core v0.19.0+ the setup can be done fully airgapped, but spending | ||
| needs a USB connection and additional software such as [HWI](https://github.com/bitcoin-core/HWI). | ||
|
|
||
| Core has not always supported BIP32 hierarchical keys, and it does not presently | ||
| support BIP44 derivation. Instead it uses derivation like this: | ||
| ## Setup Steps | ||
|
|
||
| m/0'/{change}'/{index}' | ||
| ### Bitcoin Core v0.19.0+ | ||
|
|
||
| It will also, as of 0.16, do Segwit in P2SH by default. In time, `bech32` will | ||
| become the default address format. | ||
| For compatibility with other wallet software we use the BIP84 address derivation | ||
| (m/84'/0'/{account}'/{change}/{index}) and native SegWit (bech32) addresses. It's | ||
| recommended to set `addresstype=bech32` in [bitcoin.conf](https://github.com/bitcoin/bitcoin/blob/9546a785953b7f61a3a50e2175283cbf30bc2151/doc/bitcoin-conf.md). | ||
|
|
||
| ## Setup Steps | ||
| First, generate a new seed phrase on the Coldcard. Then create a watch-only wallet | ||
| in Bitcoin Core: File -> Create Wallet. Give it a name, and ensure "Disable Private Keys" | ||
| is selected. | ||
|
|
||
| - generate a new seed phrase on the Coldcard | ||
| - export the xpub file from Coldcard (USB or MicroSD) | ||
| - import that xpub as a new wallet in core | ||
| - display balances | ||
| The public keys can exported via an SD card, or via USB. | ||
|
|
||
| ## Day-to-day Operation | ||
| To export via SD card: | ||
|
|
||
| - generate unsigned transactions | ||
| - get that onto the Coldcard, and sign it there | ||
| - use core to broadcast the new txn for confirmation | ||
| - go to Advanced -> MicroSD card -> Bitcoin Core | ||
| - on your computer open public.txt, copy the `importmulti` command | ||
| - in Bitcoin Core, go to Windows -> Console | ||
| - select Coldcard in the wallet dropdown | ||
| - paste the `importmulti` command. It should respond with a success message | ||
|
|
||
| To export via USB: | ||
|
|
||
| - install HWI and follow the [instructions for Setup](https://github.com/bitcoin-core/HWI/blob/master/docs/bitcoin-core-usage.md#setup) | ||
| - during the `getkeypool` command, the use of `--wpkh` ensures compatibility with BIP84, | ||
| as long as you only use bech32 (native SegWit) addresses. | ||
|
|
||
| ## Use of "dumpwallet" command | ||
| If you've used this wallet before, Bitcoin Core needs to rescan the blockchain to | ||
| show your balance and earlier transactions. Use the RPC command `rescanblockchain HEIGHT` | ||
| where `HEIGHT` is an old enough block (0 if you don't know). | ||
|
|
||
| - You can do a "dumpwallet" command and get the `xprv` associated with your | ||
| wallet. We can import that, and then you'd need to destroy the existing wallet | ||
| files, backups of those, and so on. | ||
| ### Bitcoin Core v0.18.0 | ||
|
|
||
| - Our output file, called `public.txt`, can be compared to dumpwallet's output, but: | ||
| - you must find the section with appropriate derivation path for core | ||
| - core puts the addresses into a random order, not sequential like ours | ||
| - segwit, and p2sh segwit choice has to match | ||
| The same steps as Bitcoin Core v0.19.0, except that the wallet must be created | ||
| using the RPC (console window in the GUI): | ||
|
|
||
| ``` | ||
| createwallet Coldcard true | ||
| ``` | ||
|
|
||
| ## Day-to-day Operation | ||
|
|
||
| ### Bitcoin Core v0.18.0+ | ||
|
|
||
| See HWI [instructions for usage](https://github.com/bitcoin-core/HWI/blob/master/docs/bitcoin-core-usage.md#usage). | ||
|
|
||
| - generate unsigned transactions | ||
| - get that onto the Coldcard, and sign it there | ||
| - use core to broadcast the new txn for confirmation | ||
|
|
||
| When using the Bitcoin Core GUI (Graphical User Interface), avoid using P2SH wrapped receive | ||
| addresses, as this will cause incompatibility with other wallets. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # From: https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp | ||
|
|
||
| def PolyMod(c, val): | ||
| c0 = c >> 35 | ||
| c = ((c & 0x7ffffffff) << 5) ^ val | ||
| if (c0 & 1): | ||
| c ^= 0xf5dee51989 | ||
| if (c0 & 2): | ||
| c ^= 0xa9fdca3312 | ||
| if (c0 & 4): | ||
| c ^= 0x1bab10e32d | ||
| if (c0 & 8): | ||
| c ^= 0x3706b1677a | ||
| if (c0 & 16): | ||
| c ^= 0x644d626ffd | ||
| return c | ||
|
|
||
| def DescriptorChecksum(desc): | ||
| INPUT_CHARSET = "0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ " | ||
| CHECKSUM_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" | ||
|
|
||
| c = 1 | ||
| cls = 0 | ||
| clscount = 0 | ||
| for ch in desc: | ||
| pos = INPUT_CHARSET.find(ch) | ||
| if pos == -1: | ||
| return "" | ||
| c = PolyMod(c, pos & 31) | ||
| cls = cls * 3 + (pos >> 5) | ||
| clscount += 1 | ||
| if clscount == 3: | ||
| c = PolyMod(c, cls) | ||
| cls = 0 | ||
| clscount = 0 | ||
| if clscount > 0: | ||
| c = PolyMod(c, cls) | ||
| for j in range(0, 8): | ||
| c = PolyMod(c, 0) | ||
| c ^= 1 | ||
|
|
||
| ret = [None] * 8 | ||
| for j in range(0, 8): | ||
| ret[j] = CHECKSUM_CHARSET[(c >> (5 * (7 - j))) & 31] | ||
| return ''.join(ret) | ||
|
|
||
| def AddChecksum(desc): | ||
| return desc + "#" + DescriptorChecksum(desc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Colcard have a clock and know when the seed was generated? If so, that could be added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly Coldcard has no idea of time nor block height.