You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cookbook/src/tx_segwit-v0.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ In a real application these would be actual secrets[^secp].
66
66
We use the `SecretKey::new` method to generate a random private key `sk`.
67
67
We then use the `PublicKey::new` method to derive the corresponding public key `pk`.
68
68
Finally, we use the `PublicKey::wpubkey_hash` method to derive the corresponding public key hash `wpkh`.
69
-
Note that `senders_keys` is generic over the [`Signing`](https://docs.rs/secp256k1/0.27.0/secp256k1/trait.Signing.html) trait.
69
+
Note that `senders_keys` is generic over the [`Signing`](https://docs.rs/secp256k1/0.29.0/secp256k1/trait.Signing.html) trait.
70
70
This is used to indicate that is an instance of `Secp256k1` and can be used for signing.
71
71
We conclude returning the private key `sk` and the public key hash `wpkh` as a tuple.
72
72
@@ -228,7 +228,7 @@ Let's go over the main function code block by block.
228
228
229
229
`let secp = Secp256k1::new();` creates a new `Secp256k1` context with all capabilities.
230
230
Since we added the `rand-std` feature to our `Cargo.toml`,
231
-
we can use the [`SecretKey::new`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Secp256k1.html#method.new) method to generate a random private key `sk`.
231
+
we can use the [`SecretKey::new`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Secp256k1.html#method.new) method to generate a random private key `sk`.
232
232
233
233
`let (sk, wpkh) = senders_keys(&secp);` generates a random private key `sk` and derives the corresponding public key hash `wpkh`.
234
234
`let address = receivers_address();` generates a receiver's address `address`.
@@ -302,13 +302,13 @@ It takes the following arguments:
302
302
We are using the [`All`](https://docs.rs/bitcoin/0.32.0/bitcoin/sighash/enum.EcdsaSighashType.html#variant.All) variant,
303
303
which indicates that the sighash will include all the inputs and outputs.
304
304
305
-
We create the message `msg` by converting the `sighash` to a [`Message`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Message.html) type.
305
+
We create the message `msg` by converting the `sighash` to a [`Message`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Message.html) type.
306
306
This is the message that we will sign.
307
-
The [Message::from](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Message.html#impl-From%3C%26%27_%20bitcoin%3A%3Ahashes%3A%3Asha256d%3A%3AHash%3E) method takes anything that implements the promises to be a thirty two byte hash i.e., 32 bytes that came from a cryptographically secure hashing algorithm.
307
+
The [Message::from](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Message.html#impl-From%3C%26%27_%20bitcoin%3A%3Ahashes%3A%3Asha256d%3A%3AHash%3E) method takes anything that implements the promises to be a thirty two byte hash i.e., 32 bytes that came from a cryptographically secure hashing algorithm.
308
308
309
-
We compute the signature `sig` by using the [`sign_ecdsa`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Secp256k1.html#method.sign_ecdsa) method.
310
-
It takes a refence to a [`Message`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Message.html) and a reference to a [`SecretKey`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.SecretKey.html) as arguments,
311
-
and returns a [`Signature`](https://docs.rs/secp256k1/0.27.0/secp256k1/ecdsa/struct.Signature.html) type.
309
+
We compute the signature `sig` by using the [`sign_ecdsa`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Secp256k1.html#method.sign_ecdsa) method.
310
+
It takes a refence to a [`Message`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Message.html) and a reference to a [`SecretKey`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.SecretKey.html) as arguments,
311
+
and returns a [`Signature`](https://docs.rs/secp256k1/0.29.0/secp256k1/ecdsa/struct.Signature.html) type.
312
312
313
313
In the next step, we update the witness stack for the input we just signed by first converting the `sighash_cache` into a [`Transaction`](https://docs.rs/bitcoin/0.32.0/bitcoin/blockdata/transaction/struct.Transaction.html)
314
314
by using the [`into_transaction`](https://docs.rs/bitcoin/0.32.0/bitcoin/sighash/struct.SighashCache.html#method.into_transaction) method.
@@ -317,8 +317,8 @@ It is a [`Witness`](https://docs.rs/bitcoin/0.32.0/bitcoin/blockdata/witness/str
317
317
We use the [`push_bitcoin_signature`](https://docs.rs/bitcoin/0.32.0/bitcoin/blockdata/witness/struct.Witness.html#method.push_bitcoin_signature) method.
318
318
It expects two arguments:
319
319
320
-
1. A reference to a [`SerializedSignature`](https://docs.rs/secp256k1/0.27.0/secp256k1/ecdsa/serialized_signature/struct.SerializedSignature.html) type.
321
-
This is accomplished by calling the [`serialize_der`](https://docs.rs/secp256k1/0.27.0/secp256k1/ecdsa/struct.Signature.html#method.serialize_der) method on the `Signature``sig`,
320
+
1. A reference to a [`SerializedSignature`](https://docs.rs/secp256k1/0.29.0/secp256k1/ecdsa/serialized_signature/struct.SerializedSignature.html) type.
321
+
This is accomplished by calling the [`serialize_der`](https://docs.rs/secp256k1/0.29.0/secp256k1/ecdsa/struct.Signature.html#method.serialize_der) method on the `Signature``sig`,
322
322
which returns a `SerializedSignature` type.
323
323
1. A [`EcdsaSighashType`](https://docs.rs/bitcoin/0.32.0/bitcoin/sighash/enum.EcdsaSighashType.html) enum.
324
324
Again we are using the same [`All`](https://docs.rs/bitcoin/0.32.0/bitcoin/sighash/enum.EcdsaSighashType.html#variant.All) variant that we used earlier.
Copy file name to clipboardExpand all lines: cookbook/src/tx_taproot.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ In a real application these would be actual secrets[^secp].
64
64
We use the `SecretKey::new` method to generate a random private key `sk`.
65
65
We then use the [`Keypair::from_secret_key`](https://docs.rs/bitcoin/0.32.0/bitcoin/key/struct.Keypair.html#method.from_secret_key) method to instatiate a [`Keypair`](https://docs.rs/bitcoin/0.32.0/bitcoin/key/struct.Keypair.html) type,
66
66
which is a data structure that holds a keypair consisting of a secret and a public key.
67
-
Note that `senders_keys` is generic over the [`Signing`](https://docs.rs/secp256k1/0.27.0/secp256k1/trait.Signing.html) trait.
67
+
Note that `senders_keys` is generic over the [`Signing`](https://docs.rs/secp256k1/0.29.0/secp256k1/trait.Signing.html) trait.
68
68
This is used to indicate that is an instance of `Secp256k1` and can be used for signing.
-`secp` is a reference to a [`Secp256k1`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Secp256k1.html) type.
117
+
-`secp` is a reference to a [`Secp256k1`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Secp256k1.html) type.
118
118
This is used to verify the internal key.
119
119
-`internal_key` is a [`UntweakedPublicKey`](https://docs.rs/bitcoin/0.32.0/bitcoin/key/type.UntweakedPublicKey.html) type.
120
120
This is the internal key that is used to generate the script pubkey.
@@ -251,7 +251,7 @@ Let's go over the main function code block by block.
251
251
252
252
`let secp = Secp256k1::new();` creates a new `Secp256k1` context with all capabilities.
253
253
Since we added the `rand-std` feature to our `Cargo.toml`,
254
-
we can use the [`SecretKey::new`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Secp256k1.html#method.new) method to generate a random private key `sk`.
254
+
we can use the [`SecretKey::new`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Secp256k1.html#method.new) method to generate a random private key `sk`.
255
255
256
256
`let keypair = senders_keys(&secp);` generates a keypair that we control,
257
257
and `let (internal_key, _parity) = keypair.x_only_public_key();` generates a [`XOnlyPublicKey`](https://docs.rs/bitcoin/0.32.0/bitcoin/key/struct.XOnlyPublicKey.html) that represent an X-only public key, used for verification of Schnorr signatures according to [BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
@@ -333,13 +333,13 @@ It takes the following arguments:
333
333
Taproot signatures are generated by tweaking the private (and public) key(s).
We create the message `msg` by converting the `sighash` to a [`Message`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Message.html) type.
336
+
We create the message `msg` by converting the `sighash` to a [`Message`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Message.html) type.
337
337
This is a the message that we will sign.
338
-
The [Message::from](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Message.html#impl-From%3C%26%27_%20bitcoin%3A%3Ahashes%3A%3Asha256d%3A%3AHash%3E) method takes anything that implements the promises to be a thirty two byte hash i.e., 32 bytes that came from a cryptographically secure hashing algorithm.
338
+
The [Message::from](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Message.html#impl-From%3C%26%27_%20bitcoin%3A%3Ahashes%3A%3Asha256d%3A%3AHash%3E) method takes anything that implements the promises to be a thirty two byte hash i.e., 32 bytes that came from a cryptographically secure hashing algorithm.
339
339
340
-
We compute the signature `sig` by using the [`sign_schnorr`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Secp256k1.html#method.sign_schnorr) method.
341
-
It takes a refence to a [`Message`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Message.html) and a reference to a [`Keypair`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Keypair.html) as arguments,
342
-
and returns a [`Signature`](https://docs.rs/secp256k1/0.27.0/secp256k1/ecdsa/struct.Signature.html) type.
340
+
We compute the signature `sig` by using the [`sign_schnorr`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Secp256k1.html#method.sign_schnorr) method.
341
+
It takes a refence to a [`Message`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Message.html) and a reference to a [`Keypair`](https://docs.rs/secp256k1/0.29.0/secp256k1/struct.Keypair.html) as arguments,
342
+
and returns a [`Signature`](https://docs.rs/secp256k1/0.29.0/secp256k1/ecdsa/struct.Signature.html) type.
343
343
344
344
In the next step, we update the witness stack for the input we just signed by first converting the `sighash_cache` into a [`Transaction`](https://docs.rs/bitcoin/0.32.0/bitcoin/blockdata/transaction/struct.Transaction.html)
345
345
by using the [`into_transaction`](https://docs.rs/bitcoin/0.32.0/bitcoin/sighash/struct.SighashCache.html#method.into_transaction) method.
0 commit comments