Commit Graph

20 Commits

Author SHA1 Message Date
Daniel Roberts c7bdec14fb Fix clippy lint and formatting for `Xpriv::derive_xpriv` and `Xpriv::derive_xpub` calls 2025-06-23 18:06:02 -05:00
merge-script 7d4b40dfd4
Merge rust-bitcoin/rust-bitcoin#4410: Wrap secp256k1::XOnlyPublicKey to improve error handling
c11772a768 Accept flexible input types for Taproot-related functions (Erick Cestari)
2a518d62e6 Wrap secp256k1::XOnlyPublicKey to improve error handling (Erick Cestari)

Pull request description:

  This PR addresses issue #4361 by creating a wrapper type for XOnlyPublicKey instead of directly re-exporting it from the secp256k1 library.

  ### Key Changes

  1. Created a new `XOnlyPublicKey` struct that wraps `secp256k1::XOnlyPublicKey`
  2. Implemented custom error types:
      - `ParseXOnlyPublicKeyError` for handling parsing errors
      - `TweakXOnlyPublicKeyError` for tweaking an `XOnlyPublicKey`
  3. Updated all imports and usage throughout the codebase
  4. Implemented necessary traits and methods for compatibility

  Closes #4361

ACKs for top commit:
  apoelstra:
    ACK c11772a768eefd89dcc0e3b1a369d535c191f94a; successfully ran local tests
  tcharding:
    ACK c11772a768

Tree-SHA512: c8da3486e7ffcab6c24cc08f9b2f964dd9158449ef2bd720e54d56176bc7027052314ea23cac3f673d217fa785238ea8a9b5323ba57f02199f20e56df5893965
2025-05-07 17:01:31 +00:00
Erick Cestari c11772a768
Accept flexible input types for Taproot-related functions
Refactor Taproot functions to accept any type implementing `Into<XOnlyPublicKey>`,
instead of requiring `XOnlyPublicKey` directly. This improves ergonomics when working
with compatible types, avoiding unnecessary `.into()` conversions at call sites.
2025-05-06 09:01:27 -03:00
Erick Cestari 2a518d62e6
Wrap secp256k1::XOnlyPublicKey to improve error handling
This commit creates a wrapper type for XOnlyPublicKey instead of
directly re-exporting it from the secp256k1 library.
2025-05-06 09:01:17 -03:00
Jamil Lambert, PhD 282434d4bd
Use variable directly in format! string
There is a new lint error on nightly-2025-04-25 "variables can be used
directly in the `format!` string".

Use the variables in the `format!` string for all cases in
`bitcoin/examples/`.
2025-05-06 09:49:03 +01:00
Andrew Poelstra b9a12043b0
bip32: return error when trying to derive a path too deep
This restores the Result return from derive_xpriv which we had removed
in a previous PR, but such is life.

Fixes #4308
2025-04-29 23:09:32 +00:00
Andrew Poelstra beaa2db7e5
amount: add from_sat_i32 and from_sat_u32 methods for small constants
We have a ton of calls to `from_sat_unchecked` for small constants which
were clearly in range, e.g. in fee.rs. Add a new constfn for these
cases. Don't bother making a generic Into<u32>/Into<u16> variant because
there isn't an obvious name for it.

There are 7 instances where we're using this method with values that are
out of range, which we leave as from_sat_unchecked for now.
2025-03-18 19:27:53 +00:00
Tobin C. Harding a7c44cebf9
Use _unchecked to construct amounts
We have a `_unchecked` constructor now for both `Amount` and
`SignedAmount`. In preparation for enforcing the `MAX_MONEY` invariant
use the `_unchecked` constructor throughout the codebase to construct
amounts from hard coded integer values.
2025-01-06 13:14:21 +11:00
Tobin C. Harding c1eccfde25
Move Witness to primitives
Move the `Witness` over to `primitives` leaving behind any method that
takes or returns a `Script` or a signature.

Includes addition of a feature gate to unit test.
2024-10-18 14:02:03 +11:00
ChrisCho-H 3565f70df9 feat: replace ENABLE_RBF_NO_LOCKTIME with ENABLE_LOCKTIME_AND_RBF 2024-10-12 12:42:43 +09:00
Jiri Jakes 5a9341bfc5
Improve naming of methods on Xpub and Xpriv
This change makes method names on Xpub and Xpriv more consistent and
easier to discover by following two patterns:

  - if the method deals with extended key, it contains 'xpub' or
    'xpriv' in its name
  - if the method deals with non-extended key, it contains
    'public_key' or 'private_key'

One exception is 'ckd_*' methods, which are lower-level and their names
come from BIP32; these keep using 'priv' and 'pub'.
2024-09-29 11:07:32 +08:00
Tobin C. Harding 832b726d03
Stop using all_zeros
Recently we deprecated the `all_zeros` functions on `Wtxid` and
`Txid` but for some reason our usage of them is not triggering a lint
warning.

Note please that this changes logic slightly, for example by using an
array of `0xFF` bytes instead of all zeros. Done in an effort to make it
even more obvious that the value is a dummy value and not mix it up with
the all zeros being used for coinbase thing.
2024-09-11 10:39:49 +10:00
Fmt Bot fa71b0e044 2024-09-01 automated rustfmt nightly 2024-09-01 01:22:04 +00:00
Jamil Lambert, PhD 4ad86148c7
Change Address::from_str(s) to s.parse
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed for parsing a string as an `Address`.
2024-08-28 13:50:43 +01:00
Jamil Lambert, PhD 64e668f99e
Change from_str(s) to parse::<T>() in Examples
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed in examples.
2024-08-28 13:50:43 +01:00
Jamil Lambert, PhD 2169b75bba Use lower case error messages
Error messages should start with a lower case character unless it is a
proper noun.

This has been changed everywhere.
2024-07-15 09:25:08 +01:00
Tobin C. Harding bcf6d2839e
Introduce scriptPubkey extension traits
Done in preparation for moving the script types to `primitives`.

The script types have a bunch of functionality to support scriptPubkeys,
and scriptPubkeys are an address thing.

Create a module under `address` and in it create a bunch of extension
traits to hold all scriptPubkey functionality.

Includes adding an ugly-as-hell macro to create the traits.
2024-07-13 08:43:06 +10:00
Divyansh Gupta 3a5f2932a4 create constants for ChildNumber enum
These constants are ->
   * `ONE_NORMAL` & `ZERO_NORMAL`
   * `ZERO_HARDENED` & `ONE_HARDENED`
2024-06-20 10:19:11 +05:30
Tobin C. Harding 6b7d02e5ae
Add inherent functions to hashes
Currently we have a trait `Hash` that is required for `Hmac`, `Hkdf`,
and other use cases. However, it is unegonomic for users who just want
to do a simple hash to have to import the trait.

Add inherent functions to all hash types including those created with
the new wrapper type macros.

This patch introduces some duplicate code but we are trying to make
progress in the hashes API re-write. We can come back and de-dublicate
later.

Includes making `to_byte_array`,`from_byte_array`, `as_byte_array`, and
`all_zeros` const where easily possible.
2024-06-14 10:17:00 +10:00
Jose Storopoli 34a5da5f16
bitcoin: Add Taproot PSBT multiple inputs examples 2024-06-05 13:11:28 +00:00