|
28 | 28 | //! trigger any assertion failures in the upstream library.
|
29 | 29 | //!
|
30 | 30 | //! ```rust
|
31 |
| -//! # #[cfg(all(feature = "rand", feature = "hashes", feature = "std"))] { |
| 31 | +//! # #[cfg(all(feature = "rand", feature = "std"))] { |
32 | 32 | //! use secp256k1::rand;
|
33 | 33 | //! use secp256k1::{Secp256k1, Message};
|
34 | 34 | //! use secp256k1::hashes::{sha256, Hash};
|
35 | 35 | //!
|
| 36 | +//! // Our message to sign. We explicitly obtain a hash and convert it to a |
| 37 | +//! // `Message`. In a real application, we would produce a signature hash |
| 38 | +//! // type, e.g. `bitcoin::LegacySigHash`, which is convertible to `Message` |
| 39 | +//! // and can be passed directly to `sign_ecdsa`. |
| 40 | +//! const HELLO_WORLD_SHA2: [u8; 32] = [ |
| 41 | +//! 0x31, 0x5f, 0x5b, 0xdb, 0x76, 0xd0, 0x78, 0xc4, 0x3b, 0x8a, 0xc0, 0x06, 0x4e, 0x4a, 0x01, 0x64, |
| 42 | +//! 0x61, 0x2b, 0x1f, 0xce, 0x77, 0xc8, 0x69, 0x34, 0x5b, 0xfc, 0x94, 0xc7, 0x58, 0x94, 0xed, 0xd3, |
| 43 | +//! ]; |
| 44 | +//! |
36 | 45 | //! let secp = Secp256k1::new();
|
37 | 46 | //! let (secret_key, public_key) = secp.generate_keypair(&mut rand::rng());
|
38 |
| -//! let digest = sha256::Hash::hash("Hello World!".as_bytes()); |
39 |
| -//! let message = Message::from_digest(digest.to_byte_array()); |
| 47 | +//! let message = Message::from_digest(HELLO_WORLD_SHA2); |
40 | 48 | //!
|
41 | 49 | //! let sig = secp.sign_ecdsa(message, &secret_key);
|
42 | 50 | //! assert!(secp.verify_ecdsa(&sig, message, &public_key).is_ok());
|
|
46 | 54 | //! If the "global-context" feature is enabled you have access to an alternate API.
|
47 | 55 | //!
|
48 | 56 | //! ```rust
|
49 |
| -//! # #[cfg(all(feature = "global-context", feature = "hashes", feature = "rand", feature = "std"))] { |
| 57 | +//! # #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] { |
50 | 58 | //! use secp256k1::{rand, generate_keypair, Message};
|
51 | 59 | //! use secp256k1::hashes::{sha256, Hash};
|
52 | 60 | //!
|
| 61 | +//! // See previous example regarding this constant. |
| 62 | +//! const HELLO_WORLD_SHA2: [u8; 32] = [ |
| 63 | +//! 0x31, 0x5f, 0x5b, 0xdb, 0x76, 0xd0, 0x78, 0xc4, 0x3b, 0x8a, 0xc0, 0x06, 0x4e, 0x4a, 0x01, 0x64, |
| 64 | +//! 0x61, 0x2b, 0x1f, 0xce, 0x77, 0xc8, 0x69, 0x34, 0x5b, 0xfc, 0x94, 0xc7, 0x58, 0x94, 0xed, 0xd3, |
| 65 | +//! ]; |
| 66 | +//! |
53 | 67 | //! let (secret_key, public_key) = generate_keypair(&mut rand::rng());
|
54 | 68 | //! let digest = sha256::Hash::hash("Hello World!".as_bytes());
|
55 |
| -//! let message = Message::from_digest(digest.to_byte_array()); |
| 69 | +//! let message = Message::from_digest(HELLO_WORLD_SHA2); |
56 | 70 | //!
|
57 | 71 | //! let sig = secret_key.sign_ecdsa(message);
|
58 | 72 | //! assert!(sig.verify(message, &public_key).is_ok());
|
|
0 commit comments