@@ -18,7 +18,6 @@ For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin inte
1818
1919* [x] Install the [ IC
2020 SDK] ( https://internetcomputer.org/docs/current/developer-docs/getting-started/install ) .
21- For local testing, ` dfx >= 0.22.0-beta.0 ` is required.
2221* [x] On macOS, ` llvm ` with the ` wasm32-unknown-unknown ` target (which is not included in the XCode installation by default) is required.
2322To install, run ` brew install llvm ` .
2423
@@ -92,43 +91,30 @@ to check [this
9291article] ( https://bitcoinmagazine.com/technical/bitcoin-address-types-compared-p2pkh-p2sh-p2wpkh-and-more )
9392if you are interested in a high-level comparison of different address types.
9493These addresses can be generated from an ECDSA public key or a Schnorr
95- ([ BIP340] ( https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki ) )
96- public key. The example code showcases how your canister can generate and spend
97- from three types of addresses:
94+ ([ BIP340] ( https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki ) ,
95+ [ BIP341] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki ) ) public
96+ key. The example code showcases how your canister can generate and spend from
97+ three types of addresses:
98981 . A [ P2PKH address] ( https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash )
9999 using the
100100 [ ecdsa_public_key] ( https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-ecdsa_public_key )
101101 API.
1021022 . A [ P2TR
103103 address] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki )
104- where the funds can be spent using the raw (untweaked) internal key
105- (so-called P2TR key path spend, but untweaked). The advantage of this
106- approach compared to the one below is its significantly smaller fee per
107- transaction because checking the transaction signature is analogous to P2PK
108- but uses Schnorr instead of ECDSA. IMPORTANT: Note that
109- [ BIP341] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-23 )
110- advises against using taproot addresses that can be spent with an untweaked
111- key. This precaution is to prevent attacks that can occur when creating
112- taproot multisigner addresses using specific multisignature schemes. However,
113- the Schnorr API of the internet computer does not support Schnorr
114- multisignatures.
104+ where the funds can be spent using the internal key only ([ P2TR key path
105+ spend with unspendable script
106+ tree] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-23 ) ).
1151073 . A [ P2TR
116108 address] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki )
117- where the funds can be spent using the provided public key with the script
118- path, where the Merkelized Alternative Script Tree (MAST) consists of a
119- single script allowing to spend funds by exactly one key.
120-
121- Note that P2TR * key path* spending with a tweaked key is currently not available
122- on the IC because the threshold Schnorr signing interface does not allow
123- applying BIP341 tweaks to the private key. In contrast, the
124- tweaked public key is used to spend in the script path, which is available on the
125- IC. For a technical comparison of different ways of how single-signer P2TR
126- addresses can be constructed and used, you may want to take a look at [ this
127- post] ( https://bitcoin.stackexchange.com/a/111100 ) by Pieter Wuille.
109+ where the funds can be spent using either 1) the internal key or 2) the
110+ provided public key with the script path, where the Merkelized Alternative
111+ Script Tree (MAST) consists of a single script allowing to spend funds by
112+ exactly one key.
128113
129114On the Candid UI of your canister, click the "Call" button under
130115` get_${type}_address ` to generate a ` ${type} ` Bitcoin address, where ` ${type} `
131- is one of ` [p2pkh, p2tr_raw_key_spend, p2tr_script_spend] ` .
116+ is one of ` [p2pkh, p2tr_key_only, p2tr] ` (corresponding to the three types of
117+ addresses described above, in the same order).
132118
133119Or, if you prefer the command line:
134120 ` dfx canister --network=ic call basic_bitcoin get_${type}_address `
@@ -176,15 +162,16 @@ Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](ht
176162## Step 5: Sending bitcoin
177163
178164You can send bitcoin using the ` send_from_${type} ` endpoint on your canister, where
179- ` ${type} ` is on of ` [p2pkh, p2tr_raw_key_spend, p2tr_script_spend] ` .
165+ ` ${type} ` is one of
166+ ` [p2pkh_address, p2tr_key_only_address, p2tr_address_key_path, p2tr_address_script_path] ` .
180167
181168In the Candid UI, add a destination address and an amount to send. In the example
182169below, we're sending 4'321 Satoshi (0.00004321 BTC) back to the testnet faucet.
183170
184171Via command line, the same call would look like this:
185172
186173``` bash
187- dfx canister --network=ic call basic_bitcoin send_from_p2pkh ' (record { destination_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"; amount_in_satoshi = 4321; })'
174+ dfx canister --network=ic call basic_bitcoin send_from_p2pkh_address ' (record { destination_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"; amount_in_satoshi = 4321; })'
188175```
189176
190177The ` send_from_${type} ` endpoint can send bitcoin by:
0 commit comments