Commit Graph

711 Commits

Author SHA1 Message Date
Andrew Poelstra 04976eddcf
Merge rust-bitcoin/rust-bitcoin#1833: Use new `hex-conservative` crate
bb8bd16302 internals: Remove hex module (Tobin C. Harding)
2268b44911 Depend on hex-conservative (Tobin C. Harding)
db50509cd3 Add usage docs to the "core2" feature (Tobin C. Harding)

Pull request description:

  Use the newly released `hex-conservative` crate, by doing the following:

  - Depend on `hex-conservative` in `bitcoin` and `hashes`
  - Re-export `hex-conservative` as `hex` from both crate roots.
  - Remove all the old hex code from `hashes`
  - Remove all the old hex code from `internals`
  - Remove the now unused `internals::prelude`
  - Fix all the import statements (makes up the bulk of the lines changes in this patch)

ACKs for top commit:
  apoelstra:
    ACK bb8bd16302
  sanket1729:
    utACK bb8bd16302

Tree-SHA512: ec83b3941cae6f32272471779f28461bb04959a3f6a126a68bbf2c748d83ff9518ff8932d9e937a6f389c10028bf3eb58c6b6d71ea066924dd7a34faaec7a087
2023-07-27 16:27:01 +00:00
Andrew Poelstra 2b50859753
Merge rust-bitcoin/rust-bitcoin#1958: Fill in deprecated since NEXT-RELEASE placeholder
1edc5f4098 Fill in deprecated since NEXT-RELEASE placeholder (Tobin C. Harding)

Pull request description:

  As we gear up for the v0.31.0 release we can fill in the NEXT-RELEASE placeholders.

ACKs for top commit:
  sanket1729:
    utACK 1edc5f4098
  apoelstra:
    ACK 1edc5f4098

Tree-SHA512: 61a78e9df0d563a1ebefef3d6c3447b767c5d878f05b45e9a20aecdcef897cc9d8c40d499882a7b8d74d5e99b25a256946c39edf2f05abab370cc0223346f66b
2023-07-27 13:14:03 +00:00
Riccardo Casatta 0e6341d4c9
Merge rust-bitcoin/rust-bitcoin#1954: Avoid vector allocation in `RawNetworkMessage` encoding
5c8933001c Avoid serialize inner data in RawNetworkMessage (Riccardo Casatta)
bc66ed82b2 Impl Encodable for NetworkMessage (Riccardo Casatta)
8560baaca2 Make fields of RawNetworkMessage non public (Riccardo Casatta)

Pull request description:

  This PR removes the need to serialize the inner NetworkMessage in the RawNetworkMessage encoding, thus saving memory and reducing allocations.

  To achieve this payload_len and checksum are kept in the RawNetworkMessage and checksum kept in CheckedData, to preserve invariants fields of the struct are made non-public.

ACKs for top commit:
  apoelstra:
    ACK 5c8933001c
  tcharding:
    ACK 5c8933001c

Tree-SHA512: aca3c7ac13d2d71184288f7815449e72c4c04fc617a65effba592592ef4ec50f18b6f83dbff58e9c4237cb1fe8e7af52cd43db9036658bdaf7888c07011e46cc
2023-07-27 08:55:21 +02:00
Tobin C. Harding 50ada8298f
Move EncodeSigningDataResult to sighash module
This type was defined in the `transaction` module because it was
originally used in a function that had been deprecated in favour of
moving the logic to the `sighash` module.

We just removed the deprecated code so we can now move this type to the
`sighash` module where it is used.
2023-07-27 09:21:34 +10:00
Tobin C. Harding 1b7dc51ccb
Remove deprecated code
We only keep deprecated code around for one release so we can now remove
code deprecated in v0.30.0

Done in preparation as we gear up for v0.31.0 release.
2023-07-27 09:20:19 +10:00
Tobin C. Harding 1edc5f4098
Fill in deprecated since NEXT-RELEASE placeholder
As we gear up for the v0.31.0 release we can fill in the NEXT-RELEASE
placeholders.
2023-07-27 07:26:21 +10:00
Riccardo Casatta 5c8933001c
Avoid serialize inner data in RawNetworkMessage
RawNetworkMessage keep the payload_len and its checksum in the struct, thus
is not needed to serialize the inner network message

pub in fields of both RawNetworkMessage and CheckedData are removed so that
invariant are preserved.
2023-07-26 08:34:49 +02:00
Steven Roose 56343bd7b5
Merge pull request #1912 from tcharding/06-20-consensus-validation
Separate out bitcoinconsensus validation code
2023-07-25 11:16:53 -05:00
Riccardo Casatta bc66ed82b2 Impl Encodable for NetworkMessage
Using it in RawNetworkMessage encoding
2023-07-25 14:47:31 +02:00
Riccardo Casatta 8560baaca2 Make fields of RawNetworkMessage non public
provide accessor method and new for downstream libs.
This is done in order to more easily change the struct without impacting
downstream and also in order to add another field while preserving struct
invariant in future commit.
2023-07-25 14:43:13 +02:00
Tobin C. Harding d3460daee7
Rename HashParse error variant to InvalidHash
Recently we changed the inner type of this variant and the name became
stale because it is caused by a from slice constructor not from parsing.
2023-07-24 15:08:07 +10:00
Andrew Poelstra f50bb05e99
Merge rust-bitcoin/rust-bitcoin#1949: key: Impl From<secp256k1::PublicKey> for bitcoin::PublicKey
ebcce38b4f run cargo fmt (Andrew Poelstra)
b3ac00b8b3 key: Impl From<secp256k1::PublicKey> for bitcoin::PublicKey (Steven Roose)

Pull request description:

ACKs for top commit:
  apoelstra:
    ACK ebcce38b4f
  tcharding:
    ACK ebcce38b4f

Tree-SHA512: 9b862f0bb75e74780e935e5292c6a67ae479f699f0ee2f90515f972698dc06af5ea7d1725908fb435cafd6c0bab7263570d780607e507d6127efaea97f2464c8
2023-07-21 15:06:56 +00:00
Tobin C. Harding 2268b44911
Depend on hex-conservative
We have just released the `hex-conservative` crate, we can now use it.

Do the following:

- Depend on `hex-conservative` in `bitcoin` and `hashes`
- Re-export `hex-conservative` as `hex` from both crate roots.
- Remove all the old hex code from `hashes`
- Fix all the import statements (makes up the bulk of the lines changed
  in this patch)
2023-07-21 10:59:46 +10:00
Tobin C. Harding db50509cd3
Add usage docs to the "core2" feature
We do not expect users of `rust-bitcoin` to ever activate the "core2"
dependency directly, add a comment explaining that.
2023-07-21 10:45:23 +10:00
Andrew Poelstra ebcce38b4f
run cargo fmt 2023-07-20 17:13:15 +00:00
Steven Roose b3ac00b8b3
key: Impl From<secp256k1::PublicKey> for bitcoin::PublicKey 2023-07-20 17:09:37 +01:00
Tobin C. Harding f3412325ea
weight: Make docs uniform and terse
Make the docs use the same form as everywhere else, which also mimics
stdlib docs on integer types.
2023-07-20 09:32:23 +10:00
Andrew Poelstra 894c926f56
Merge rust-bitcoin/rust-bitcoin#1935: Infrastructure fixes
7b402e930c schemars: Add pinning docs (Tobin C. Harding)
0848ab7e25 Fix clippy warnings for embedded build (Tobin C. Harding)
5b1443a91c hashes/embedded: Add script dir and README (Tobin C. Harding)
94732aecbf Add patch section to test crates (Tobin C. Harding)
512d982275 Remove path field from internals dependency (Tobin C. Harding)

Pull request description:

  Do a bunch of infrastructure fixes that either are needed for adding additional crate deps (hex) or updating deps (internals, hashes), or just make the tests more maintainable.

ACKs for top commit:
  apoelstra:
    ACK 7b402e930c
  sanket1729:
    ACK 7b402e930c

Tree-SHA512: 9349bb20225363914acc774cca672a23e6562fb02aea644777c558074d5eeb65289d68a93b5be59a93e9b32167e2494f6599caedc8a0d9cfbee2f94d406edbfc
2023-07-19 16:11:40 +00:00
Riccardo Casatta 63a09649f7
Merge rust-bitcoin/rust-bitcoin#1946: bitcoin/bip32: add DerivationPath::to_u32_vec
6640074d34 bitcoin/bip32: add DerivationPath::to_u32_vec (Marko Bencun)

Pull request description:

  This is useful to pass the keypath to other libraries which expect it to be represented with a list of u32 ints.

  Fixes #1944

ACKs for top commit:
  apoelstra:
    ACK 6640074d34
  RCasatta:
    ACK 6640074d34

Tree-SHA512: c2327716370558dd9d7e0419f898707ba5e56555284ea7ca746c973080061aae53674b41d8fe7c68a00d7c4bec1e4bb53e8991141749a87dfa40febe9f456369
2023-07-18 20:20:03 +02:00
Riccardo Casatta 28f6ad80cb
Merge rust-bitcoin/rust-bitcoin#1942: witness: clean up Debug implementation
e30c492faf witness: clean up Debug implementation (Andrew Poelstra)

Pull request description:

  The previous code seems to have been rebased/iterated on too many times, and had room for significant simplification. By inlining the indentation logic we can eliminate 40 LOC and also clean up the output by removing trailing spaces.

  Fixes #1937

  It is not good form to add unit tests for debug output but you can test this locally with the patch
  ```
  diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs
  index d0b7408c..a2c38af0 100644
  --- a/bitcoin/src/blockdata/witness.rs
  +++ b/bitcoin/src/blockdata/witness.rs
  @@ -619,6 +619,9 @@ mod test {
               "304402207c800d698f4b0298c5aac830b822f011bb02df41eb114ade9a6702f364d5e39c0220366900d2a60cab903e77ef7dd415d46509b1f78ac78906e3296f495aa1b1b54101")
               ];
           assert_eq!(witness.to_vec(), expected_witness);
  +
  +            println!("{:?}", witness);
  +            panic!();
       }

       #[test]
  ```
  And by sticking `{:#?}` in there to see the alternate output.

ACKs for top commit:
  tcharding:
    tACK e30c492faf
  RCasatta:
    ACK e30c492faf

Tree-SHA512: 0ec07885f5c75f3f34965852cf5b42b63290295d1f56e9fef7d5b3610b8ac8d318cbf8f184da5b8a9ed5b352bb2c0402797b41714cb9d5488e93c2e290340c2a
2023-07-18 20:18:04 +02:00
Andrew Poelstra 9a34f0cf5e
Merge rust-bitcoin/rust-bitcoin#1925: Rename `Script::empty` to `Script::new`
9787ba6c96 Rename Script::empty to Script::new (Tobin C. Harding)

Pull request description:

  The `empty` constructor is mis-named for the following reasons:

  - Non-uniform with `ScriptBuf::new`
  - Non-standard with respect to stdlib which uses `Path::new` and `PathBuf::new` (on which we based the `Scritp`/`ScriptBuf`)

  Rename the function to `new`, put it at the top of the impl block while we are at it.

ACKs for top commit:
  apoelstra:
    ACK 9787ba6c96
  RCasatta:
    ACK 9787ba6c96

Tree-SHA512: 2dee0f61fa9097a48369a0df802ebf238b00ad3e9ed520fbf31affa1cb2a1820cbb910b525be63513e4586acb2aa0b593cecddcad0b6cd894cdac0ba7fcf0871
2023-07-18 16:49:00 +00:00
Marko Bencun 6640074d34
bitcoin/bip32: add DerivationPath::to_u32_vec
This is useful to pass the keypath to other libraries which expect it
to be represented with a list of u32 ints.
2023-07-18 14:33:29 +02:00
Tobin C. Harding dae2b508bc
Separate out bitcoinconsensus validation code
Pull all the code that depends on `bitcoinconsensus` out into a separate
module `consensus::validation`.

Leave transaction testing of bitcoinconsensus code in the transaction
module.
2023-07-18 10:29:51 +10:00
Tobin C. Harding 0cd1af1f56
Remove unused import statement
This import is not used, our CI obviously does not warn for all feature
combinations.
2023-07-18 10:29:50 +10:00
Tobin C. Harding ca38dbd16d
transaction:: Return custom error from verify function
There is not need to return the general `script::Error` from the
transaction verify functions. We can better describe the error path by
returning a custom error.
2023-07-18 10:29:50 +10:00
Tobin C. Harding ca2512f471
script: Return bitcoinconsensus::Error from verify functions
There is no need no nest the `bitcoinconsensus::Error` type within the
`script::Error`, it is the only error type returned by the verify
functions so just return it directly.
2023-07-18 10:29:50 +10:00
Tobin C. Harding 8ed74c4f0d
Add comment to bitcoinconsensus dependency
Add a comment to point users towards the `bitcoinconsensus-std` feature
for std builds.
2023-07-18 10:29:50 +10:00
Tobin C. Harding 0848ab7e25
Fix clippy warnings for embedded build
When building the `embedded` test crate `clippy` emits two warnings
of form:

  warning: unused variable: `foo`

Use `_` instead of a named variable.
2023-07-18 10:27:48 +10:00
Tobin C. Harding 94732aecbf
Add patch section to test crates
In order to keep the embedded and schemacs test crates building when we
update their local transient dependencies we need to use a `patch`
section.

- For `bitcoin/embedded` add `patch` section for `internals`, `hashes`
already has an entry.
- For `hashes/embedded` add `patch` section for `internals`.
- For `hashes/extendend_tests/schemars` add `patch` section for
  `internals`.

FTR for direct local dependencies we use a `path` field when specifying
the dependency.
2023-07-18 10:27:48 +10:00
Tobin C. Harding 512d982275
Remove path field from internals dependency
We use two different methods for specifying local dependencies, `patch`
and also `path`. There does not seem to be a reason why we use both,
lets be uniform. Elect to use `patch` for all local crates.
2023-07-18 10:27:46 +10:00
Andrew Poelstra 922996b032
Merge rust-bitcoin/rust-bitcoin#1938: Rename PartiallySignedTransaction to Psbt
92749d29e4 Rename PartiallySignedTransaction to Psbt (Tobin C. Harding)

Pull request description:

  Last release we added a type alias for `Psbt`, now lets just rename the type and be done with it.

  Includes re-export at the crate root because `bitcoin::Psbt` is clear and obvious.

ACKs for top commit:
  sanket1729:
    ACK 92749d29e4.
  apoelstra:
    ACK 92749d29e4

Tree-SHA512: 2ded728409829709a46acd2a83ce9a91839bce222264b2fca122b346ec4f45a52c3f970eb05001794e2f355ce9391df1a184b57baf24589e8a5c3f77f72f6ec7
2023-07-17 16:35:43 +00:00
Andrew Poelstra c7eb9e61ec
Merge rust-bitcoin/rust-bitcoin#1916: internals: Bump version to 0.2.0
8813a63ec9 internals: Bump version to 0.2.0 (Tobin C. Harding)

Pull request description:

  In preparation for release bump the version and add a changelog entry. Includes updating the dependency in `bitcoin` and `hashes`.

ACKs for top commit:
  apoelstra:
    ACK 8813a63ec9
  sanket1729:
    utACK 8813a63ec9

Tree-SHA512: a9bd9d4d69cba21329f3f63a9948afe566bb97c8c65f5d46c329a696a814e9eb31372d378de1ecf0f43f0cb42f11d53dc51bc467223b34629e61315d48b39a29
2023-07-17 16:27:22 +00:00
Tobin C. Harding 92749d29e4
Rename PartiallySignedTransaction to Psbt
Last release we added a type alias for `Psbt`, now lets just rename the
type and be done with it.

Includes re-export at the crate root because `bitcoin::Psbt` is clear
and obvious.
2023-07-15 08:32:29 +10:00
Andrew Poelstra e30c492faf
witness: clean up Debug implementation
The previous code seems to have been rebased/iterated on too many times,
and had room for significant simplification. By inlining the indentation
logic we can eliminate 40 LOC and also clean up the output by removing
trailing spaces.
2023-07-14 20:37:11 +00:00
Andrew Poelstra 8f4b57e3c5
Merge rust-bitcoin/rust-bitcoin#1940: Remove docsrs attributes
71c0043127 Remove docsrs attributes (Tobin C. Harding)

Pull request description:

  Somehow when we started using `doc_auto_cfg` we forgot to remove a bunch of docsrs attributes.

ACKs for top commit:
  apoelstra:
    ACK 71c0043127
  sanket1729:
    utACK 71c0043127

Tree-SHA512: 16ff8eec0f6cd392d496f8f07cc0773bbda28f7c71022ae6b5e2c47a98d40c94a9169c60c0d8fa5a819f07910593d65a47b69bdc748d64cda0aac3323e9599a6
2023-07-14 20:11:25 +00:00
Tobin C. Harding 81a42536f9
Use hex_lit::hex in benches
Currently the test `hex` macro is only available when the `test`
compiler configuration option is set but we are using it in benches
code, this works for use because `cargo bench` sets `test` for the
current crate, however it breaks downstream crates.

Fix: #1830
2023-07-14 15:30:22 +10:00
Tobin C. Harding 71c0043127
Remove docsrs attributes
Somehow when we started using `doc_auto_cfg` we forgot to remove a bunch
of docsrs attributes.
2023-07-14 14:59:11 +10:00
Tobin C. Harding 8813a63ec9
internals: Bump version to 0.2.0
In preparation for release bump the version and add a changelog entry.

Includes updating the dependency in `bitcoin` and `hashes` as well as
the minimal/recent lock files.
2023-07-14 14:31:21 +10:00
Andrew Poelstra a7fe0f5695
Merge rust-bitcoin/rust-bitcoin#1913: Manually implement Debug on Witness
d45dbef3e7 Manually implement Debug on Witness (Tobin C. Harding)

Pull request description:

  The current derived debug implementation on `Witness` prints the content field as an array of integers. We can do better than this by manually implementing `Debug`.

  With this applied `Witness` is printed as follows: (first line is `{:?}` and the next is `{:#?}`):

  Using `{:?}`:
  ```
  Witness: { indices: 3, indices_start: 8, witnesses: [[0x00], [0x02, 0x03], [0x04, 0x05]] }
  ```

  Using `{:#?}`:
  ```
  Witness: {
      indices: 3,
      indices_start: 8,
      witnesses: [
          [0x00],
          [0x02, 0x03],
          [0x04, 0x05],
       ],
  }
  ```

ACKs for top commit:
  sanket1729:
    tested ACK d45dbef3e7. This would be helpful for debugging downstream.
  apoelstra:
    ACK d45dbef3e7

Tree-SHA512: eacf4fa8e3f38c4e9ddc45de78afb8eab5b5b196b77a6612f61860e0e4e7ba96de2e7f434b92816e0b00532e73c05378cafc046ec9c34108e9d9216fb36c524a
2023-07-13 23:08:45 +00:00
Tobin C. Harding 552f19abe3
Add more rustdocs to WitnessProgram
Add rustdocs to `WitnessProgram` commenting on why we carry the witness
version number around with the witness program. This is mainly a dev
comment but it helps document the invariants so make it a rustdoc
comment.
2023-07-13 09:53:33 +10:00
Tobin C. Harding 89303c1464
Move witness types to the script module
From BIP 141:

> A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that
> consists of a 1-byte push opcode (for 0 to 16) followed by a data push
> between 2 and 40 bytes gets a new special meaning. The value of the
> first push is called the "version byte". The following byte vector
> pushed is called the "witness program".

`WitnessVersion` and `WitnessProgram` are scriptPubkey concerns and
scriptPubkey is basically synonymous with address so in one way it makes
sense that these types are in `address` however we are in the process of
overhauling the `Address` (and `AddressInner`) types so lets move the
witness stuff to `script` and put it in individual sub-modules.

This move helps simplify the address error type also.

Note please, there are a bunch of formatting changes in here in the
error type that I cannot explain and could not remove.
2023-07-13 09:51:40 +10:00
Tobin C. Harding c3a99c62ad
CI: Pin serde_json for MSRV build
Recent release of `serde_json` depends on `serde` 1.0.66 but we pin to
1.0.56

Pin `serde_json` for MSRV build to v1.0.99
2023-07-12 15:50:18 +10:00
Tobin C. Harding 154552e334
docs: Do not link to std::option::Option
This link breaks when building docs using no-std. Just use code ticks,
everyone knows what `Option` is, no need for a link.
2023-07-08 11:29:11 +10:00
Tobin C. Harding d45dbef3e7
Manually implement Debug on Witness
The current derived debug implementation on `Witness` prints the content
field as an array of integers. We can do better than this by manually
implementing `Debug`.

With this applied `Witness` is printed as follows: (first line is `{:?}`
and the next is `{:#?}`):

Using `{:?}`:
```
Witness: { indices: 3, indices_start: 8, witnesses: [[0x00], [0x02, 0x03], [0x04, 0x05]] }
```

Using `{:#?}`:
```
Witness: {
    indices: 3,
    indices_start: 8,
    witnesses: [
        [0x00],
        [0x02, 0x03],
        [0x04, 0x05],
     ],
}
```
2023-07-08 11:28:04 +10:00
Tobin C. Harding 9787ba6c96
Rename Script::empty to Script::new
The `empty` constructor is mis-named for the following reasons:

- Non-uniform with `ScriptBuf::new`
- Non-standard with respect to stdlib which uses `Path::new` and
  `PathBuf::new` (on which we based the `Scritp`/`ScriptBuf`)

Rename the function to `new`, put it at the top of the impl block while
we are at it.
2023-07-08 11:26:30 +10:00
Andrew Poelstra 83cf389a02
Merge rust-bitcoin/rust-bitcoin#1926: Refactor transaction weight
f5591d8dee Use weight instead of checked_weight (yancy)
80a4d692c4 Change weight to call predict_weight (yancy)

Pull request description:

  Followup from https://github.com/rust-bitcoin/rust-bitcoin/pull/1835.  Call `predict_weight` from `weight` instead of `scaled_size()` https://github.com/rust-bitcoin/rust-bitcoin/pull/1835#issuecomment-1543687210.  I think we could also deprecate `scaled_size()` and `strippedsize()` in a future refactor.

ACKs for top commit:
  apoelstra:
    ACK f5591d8dee
  tcharding:
    ACK f5591d8dee

Tree-SHA512: 73d719a98bd0e7e1b9b667d4a613db86a97cb16c70201ad039094bd8025e16984e74ea5110a02eedd10604663461682b7fd527023a0b0c7c94989e6f79603997
2023-06-29 01:46:46 +00:00
yancy f5591d8dee Use weight instead of checked_weight 2023-06-26 12:44:27 +02:00
yancy 80a4d692c4 Change weight to call predict_weight 2023-06-26 12:35:59 +02:00
Andrew Poelstra 51cc18ef8c
Merge rust-bitcoin/rust-bitcoin#1776: Added examples for signature verification
fc167097aa Added examples for sighash computations (Alec Matusis)

Pull request description:

  So far computed sighashes and verified signatures for:
   - P2WPKH
   - P2MS 2of3
   - P2SH 2of2 multisig
   - P2SH 2of3 multisig
   - P2WSH 2of2 multisig.

  TODOs:
    - Add P2TR script-path multisig and key-path examples
    - Are there mutisig transactions where flags are different for diff signatures within an input?
    - Maybe switch to  segwit_signature_hash()?
    - Consider also verifying script hash if we go for full P2(W)SH transactions verifications?

ACKs for top commit:
  tcharding:
    ACK fc167097aa
  apoelstra:
    ACK fc167097aa

Tree-SHA512: 67750b614592391d8252fc270be8676f8aef61eb842c49816386396e7afaa472921c21df40d13291ee80e653f3a0ec367f7b941920f1777f086815bf222e8e62
2023-06-23 16:23:06 +00:00
Andrew Poelstra f7673d9ddb
Merge rust-bitcoin/rust-bitcoin#1911: Add a verify function to PublicKey
e04ac1e743 Add a verify function to PublicKey (Tobin C. Harding)

Pull request description:

  Expose signature verification functionality for ECDSA signatures on the `PublicKey` type.

  We should have an identical function on `XOnlyPublicKey` but this will have to be done in `secp2561`: https://github.com/rust-bitcoin/rust-secp256k1/pull/618

  Idea from Kixunil: https://github.com/rust-bitcoin/rust-bitcoin/pull/1744#issuecomment-1534200841

ACKs for top commit:
  apoelstra:
    ACK e04ac1e743
  Kixunil:
    ACK e04ac1e743

Tree-SHA512: f26c223a1e5cc89e5c5fc12b22e621b9e8c395b8f91d7a58c6c938d45bc531e6682b178990b5a049718dbea66fff6d19d6fbcf926f142c781ad5213708ee7afa
2023-06-23 15:33:25 +00:00
Alec Matusis fc167097aa Added examples for sighash computations
So far computed sighashes for:
 - P2WPKH
 - P2MS
 - P2SH multisig
 - P2WSH multisig.

TODOs:
  - Add P2TR script-path multisig and key-path examples
2023-06-20 02:07:21 -07:00
Tobin C. Harding 6881080f8e
Fix incorrect comment in ci script
MSRV build breaks because of edition _2021_ not 2018.
2023-06-20 13:34:38 +10:00
Tobin C. Harding e04ac1e743
Add a verify function to PublicKey
Expose signature verification functionality for ECDSA signatures on the
`PublicKey` type.

We should have an identical function on `XOnlyPublicKey` but this will
have to be done in `secp2561`.
2023-06-20 05:08:07 +10:00
sanket1729 de7fe5e4ec
Merge rust-bitcoin/rust-bitcoin#1739: Mutate mul_u64 with mutagen
7cdc90565f Mutate mul_u64 with mutagen (Tobin C. Harding)

Pull request description:

  Add the `mutate` attribute to mutate `mul_u64`. Add non-doc comments listing the two false positives. These are identical but we list them twice so when devs grep for `mutagen false pos` the same number of lines for each function is displayed as is displayed by the `mutagen` run. This coding false positives thing is also introduced in PR #1655.

ACKs for top commit:
  apoelstra:
    ACK 7cdc90565f
  sanket1729:
    utACK 7cdc90565f

Tree-SHA512: d066beb2f9ba198f5af36258ba15cfbd2c7c9ce7596f6340ed1fe2f62a2b0b5296eeb2cb4be30146d019671f1858521c29db917936895b5b3fd36bdb0bd07e57
2023-06-14 17:53:39 -07:00
Andrew Poelstra b1078febc2
Merge rust-bitcoin/rust-bitcoin#1870: Add from_int_btc method to Amount
9f7449b572 Use from_int_btc function for const context (yancy)
f93e67977a Add from_int_btc function to Amount (yancy)

Pull request description:

  Followup PR from https://github.com/rust-bitcoin/rust-bitcoin/pull/1811

  Added a `const` associated function `from_int_btc()` for Amount.  `panic()` in const context is only available after 1.57+ so a work around is provided.

ACKs for top commit:
  tcharding:
    ACK 9f7449b572
  apoelstra:
    ACK 9f7449b572

Tree-SHA512: 7755234f2e573577d754f0224083cb7acc059e58833790fe344b0d9bad0acd89b0f74054d9efcba2133576222c7e9ab8dc3d81ddc10fbdcd4f83638d697118c4
2023-06-14 01:17:59 +00:00
yancy 9f7449b572 Use from_int_btc function for const context 2023-06-13 11:32:58 +02:00
yancy f93e67977a Add from_int_btc function to Amount 2023-06-13 11:32:51 +02:00
Andrew Poelstra 79bd294476
Merge rust-bitcoin/rust-bitcoin#1901: key: Implement From<PublicKey> for XOnlyPublicKey
445aa84f8c cargo fmt (Andrew Poelstra)
d990084481 key: Implement From<PublicKey> for XOnlyPublicKey (Steven Roose)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 445aa84f8c
  apoelstra:
    ACK 445aa84f8c

Tree-SHA512: c27b23dcf66139720011dc8bee379a8e4be642f8f60e8982c643013e163ad1610d355c6f5de04efc57d0dc11ba4ff0e893d3f760d5662d8f0c7eaba87f0a89a0
2023-06-12 23:49:45 +00:00
Andrew Poelstra 445aa84f8c
cargo fmt 2023-06-12 13:01:12 +00:00
roy9495 654f58da17
This library is not solely dependent on Rust 2023-06-08 20:03:17 +00:00
Andrew Poelstra 0750168c4f
Merge rust-bitcoin/rust-bitcoin#1297: `alloc`-free parse errors
2b6bcf085c Implement support for `alloc`-free parse errors (Martin Habovstiak)
783e1e81dc Move `impl_std_error` to `bitcoin-internals` (Martin Habovstiak)

Pull request description:

  This implements various helpers for parse errors that will not require `alloc`. This PR is useless while all of the crates require `alloc` and is thus a draft so that you can look at the design.

ACKs for top commit:
  tcharding:
    ACK 2b6bcf085c
  apoelstra:
    ACK 2b6bcf085c

Tree-SHA512: 776838a754b2c17263cf167c8cf8a3e69e51d8de45eb08d072ef930cbd1149360da2cb5fc430ce58f31c2b07dbf06c9f8384c567358873a3440e85632fcc2af8
2023-06-07 18:45:54 +00:00
Andrew Poelstra 12dc0b013b
Merge rust-bitcoin/rust-bitcoin#1863: Removed only available in 1.46.0 line
6a18997e3c Removed only available in 1.46.0 line (TATHAGATA ROY)

Pull request description:

  Fix: #1850

  Removed "*Important: only available in Rust 1.46+*" on the file  transaction.rs from lines 1288 and 1407 respectively.

ACKs for top commit:
  Kixunil:
    ACK 6a18997e3c
  apoelstra:
    ACK 6a18997e3c
  tcharding:
    ACK 6a18997e3c
  sanket1729:
    ACK 6a18997e3c

Tree-SHA512: 1395384ffe301b628687cc6d154e191b6a4415acd33eb4209065c5bf94115c3210ea1d28f7d7186e41665b39b5bebae849c3fa5394786ce24bdcd57b765cdbd3
2023-06-07 15:22:48 +00:00
Steven Roose d990084481
key: Implement From<PublicKey> for XOnlyPublicKey 2023-06-06 20:24:28 +01:00
Steven Roose 4c18ba779c
network: Implement Default on ServiceFlags 2023-06-06 00:06:28 +01:00
Andrew Poelstra 0266e762bd
Merge rust-bitcoin/rust-bitcoin#1898: Fix comments for #1890
d961b9c4ee Fix minor comments on count_sigops PR (junderw)

Pull request description:

  Fixing some comments that were left on #1890

ACKs for top commit:
  yancyribbens:
    ACK d961b9c4ee
  apoelstra:
    ACK d961b9c4ee
  tcharding:
    ACK d961b9c4ee

Tree-SHA512: caa04428eb7c09915964e4a7bae2d1fca2426317f3620d16e73e992269a99d7adb3d360affb954a173835661a9960cf760d29ae9861816b1a898c01428b0f2d6
2023-06-05 18:16:42 +00:00
junderw d961b9c4ee
Fix minor comments on count_sigops PR 2023-06-04 15:17:36 -07:00
Andrew Poelstra 7eeb3e6a4a
Merge rust-bitcoin/rust-bitcoin#1895: Improve `crytpo::taproot` error type
202d1cd581 Rename taproot::Error to SigFromSliceError (Tobin C. Harding)
29678cb82b Correctly document InvalidSighashType variant (Tobin C. Harding)
13d5c0536b Remove explicit error conversion (Tobin C. Harding)
d86517ae4f taproot: Use error variants locally (Tobin C. Harding)

Pull request description:

  First three patches are preparatory cleanup, last patch renames `crypto::taproot::Error` to `SigFromSliceError`. See commit log for justification of the `Sig` prefix.

  Done as part of the great error cleanup.

ACKs for top commit:
  apoelstra:
    ACK 202d1cd581
  Kixunil:
    ACK 202d1cd581

Tree-SHA512: 87aef07d2a3518c68c070e348d2331a9fbf1dc5cd36fd4d966607ddb0531eca9dc6be08f1923f941d33973f173b915490de9ef0cad724cce7bf108cdc8a82af0
2023-06-04 21:22:21 +00:00
Andrew Poelstra 1a1fe0e313
Merge rust-bitcoin/rust-bitcoin#1890: [script] Add method get_sigop_count
638445f8a9 Feature: Add opcodes::All::decode_pushnum and Script::count_sigops (junderw)

Pull request description:

  Planning to also add methods for the various parts of Transaction etc. to eventually allow for easier sigops calculation.

  Bare multisig is making a comeback, which is causing a large amount of transactions' effective vSizes (for fee calculation) to be dependent on the sigop count.

  This is a first step at making those transactions easier to estimate fees for / template blocks for etc.

ACKs for top commit:
  Kixunil:
    ACK 638445f8a9
  tcharding:
    ACK 638445f8a9

Tree-SHA512: 5e87d0f5ab58ed22ed50e43eac392b9b84ebccab5086553a6234d825766842057ab89bd0753f3c9de50d9ab17536182b8f64a57e8d5632a55494180f2cc26bbd
2023-06-04 19:59:44 +00:00
Martin Habovstiak 2b6bcf085c Implement support for `alloc`-free parse errors
This implements basic facilities to conditionally carry string inputs in
parse errors. This includes:

* `InputString` type that may carry the input and format it
* `parse_error_type!` macro creating a special type for parse errors
* `impl_parse` implementing parsing for various types as well as its
  `serde`-supporting alternative
2023-06-04 21:15:37 +02:00
junderw 638445f8a9
Feature: Add opcodes::All::decode_pushnum and Script::count_sigops 2023-06-02 08:46:46 -07:00
Tobin C. Harding ccb6e3eeba
Rename TaprootSpendInfo::as_script_map to script_map
The `as_script_map` is a getter not a conversion function (to/into/as),
as such it should not include the prefix `as_`.

Deprecate `as_script_map` in favour of `script_map`.
2023-06-02 16:59:08 +10:00
Tobin C. Harding 202d1cd581
Rename taproot::Error to SigFromSliceError
This error type is only used in the `from_slice` function. Use prefix
`Sig` because `taproot::FromSliceError` does not fully express how the
error came about.

Use specific identifier for the error, this aids usage but also prevents
us later adding "random" other variants into this error and using it in
other functions.
2023-06-02 15:48:45 +10:00
Tobin C. Harding 29678cb82b
Correctly document InvalidSighashType variant
The rustdoc on the `taproot::Error::InvalidSighashType` is wrong, fix
it.
2023-06-02 15:05:41 +10:00
Tobin C. Harding 13d5c0536b
Remove explicit error conversion
We provide a `From<secp255k1::Error>` impl so we do not need to
explicitly convert the error return, just use `?`.
2023-06-02 15:05:38 +10:00
Tobin C. Harding d86517ae4f
taproot: Use error variants locally
Add 'use Error::*' locally to make the code more terse.
2023-06-02 14:48:22 +10:00
Martin Habovstiak 783e1e81dc Move `impl_std_error` to `bitcoin-internals`
The macro is useful for all other crates thus it is moved to the
internals crate in this commit.
2023-05-30 18:04:54 +02:00
Tobin C. Harding 042dcaa4b7
Remove doc(hidden) from error conversion functions
Give people access to the error type conversion docs, its no harm and it
may be useful when the compiler does not give enough information.
2023-05-30 15:54:40 +10:00
Steven Roose 7bf0a106dd
Merge pull request #1872 from tcharding/05-24-rm-prevouts-export
psbt: Remove reexport of Prevouts
2023-05-30 02:48:34 +01:00
Andrew Poelstra 80efdb065a
Merge rust-bitcoin/rust-bitcoin#1873: Improve `hashes::Error`
06afd52a12 Improve hashes::Error (Tobin C. Harding)

Pull request description:

  We are trying to make error types stable on the way to v1.0

  The current `hashes::Error` is a "general" enum error type with a single variant, better to use a struct and make the error usecase specific.

  Improve the `hashes::Error` by doing:

  - Make it a struct
  - Rename to `FromSliceError`
  - Move it to the crate root (remove `error` module)

  Includes usage in `bitcoin`.

ACKs for top commit:
  apoelstra:
    ACK 06afd52a12
  Kixunil:
    ACK 06afd52a12

Tree-SHA512: 20a517daaf3e9e09744e2a65cde6e238c8f2d1224899a6c04142a3a4e635d54112b0a2e846d25256071bb27cb70f7482380f98e9a535a5498aa4c7dc0d52cc54
2023-05-29 22:58:17 +00:00
Andrew Poelstra ca17257884
Merge rust-bitcoin/rust-bitcoin#1882: made ckd_priv function private and impl AsRef for ChildNumber
4be019180b correcting formatting (startup-dreamer)

Pull request description:

  closes #1866

ACKs for top commit:
  Kixunil:
    ACK 4be019180b
  junderw:
    ACK 4be019180b
  apoelstra:
    ACK 4be019180b

Tree-SHA512: 9539c987a9636f3c50dde2d4448ca0c30c239f5a8e852e7bf560cc27a2681777fa1a91ace21bdf1fd67b1f60679dfb8eecef45b81506618285536599ad741f7e
2023-05-29 12:19:09 +00:00
Andrew Poelstra 5729b034d8
Merge rust-bitcoin/rust-bitcoin#1874: Add `ValidationError`
0f74eb6876 Remove the unused crate::Error (Tobin C. Harding)
74154c2294 Add block::ValidationError (Tobin C. Harding)
3a9b5526b3 Move BlockHash From impls (Tobin C. Harding)

Pull request description:

  Remove the `crate::Error` and replace its usage with `block::ValidationError`.

ACKs for top commit:
  apoelstra:
    ACK 0f74eb6876
  Kixunil:
    ACK 0f74eb6876

Tree-SHA512: 80b2c98d3d8f7c3f060c8ea2d94e1ebe118c07d0dcf91f6d13aed00df2cb0b15bf5e295ec0976d88d81e029cf7d3e8e4a1fe70120db57e49bbd8dd229291836b
2023-05-28 23:08:32 +00:00
Andrew Poelstra 7315eac5ee
Merge rust-bitcoin/rust-bitcoin#1871: Fix conditional configuration options usage
0046bb8ad8 Fix usage of cfg(rust_1_53) (Tobin C. Harding)
c3450f3913 Remove stale usage of doc(cfg) (Tobin C. Harding)

Pull request description:

  These build cfg options are not features, fix broken usage. And remove stale docsrs attribute while we are at it. Bad rust-bitcoin devs.

  Found while reviewing #1870

ACKs for top commit:
  apoelstra:
    ACK 0046bb8ad8
  Kixunil:
    ACK 0046bb8ad8

Tree-SHA512: 7053affef6654ff203c93590bf081e165f019feb040aa8c55259ffe4e15eaf0e7522f6e5a4f6f62e8f578420b0313f4b7b17c46b741b7fcfd05750e5c5976589
2023-05-28 22:27:27 +00:00
Andrew Poelstra ce44711219
Merge rust-bitcoin/rust-bitcoin#1879: embedded: Document how to clean up linker flags
3af9258025 embedded: Document how to clean up linker flags (Tobin C. Harding)

Pull request description:

  Our embedded crate includes instructions to source a shell script that sets the `RUSTFLAGS` env var. Having the env var set like this in ones environment breaks linkage when trying to do "regular" builds.

  Document how to clean up.

ACKs for top commit:
  apoelstra:
    ACK 3af9258025
  Kixunil:
    ACK 3af9258025

Tree-SHA512: 72758fba4dede873da299f01d75fd64b549fe21f954c2720ba3b7fc3c29fd4ed28fd0a749bbe987a7de1551aa32192253dd0033a18c877e877c9960343a5b07c
2023-05-28 21:47:03 +00:00
startup-dreamer 4be019180b correcting formatting 2023-05-29 00:26:01 +05:30
Andrew Poelstra ca06d64455
rename bitcoin-private to bitcoin-internals
Since we now have control over the name on crates.io.
2023-05-26 19:49:52 +00:00
Tobin C. Harding 3af9258025
embedded: Document how to clean up linker flags
Our embedded crate includes instructions to source a shell script that
sets the `RUSTFLAGS` env var. Having the env var set like this in ones
environment breaks linkage when trying to do "regular" builds.

Document how to clean up.
2023-05-26 14:39:14 +10:00
Tobin C. Harding 0f74eb6876
Remove the unused crate::Error
The `crate::Error` type is now unused, remove it.
2023-05-25 13:35:49 +10:00
Tobin C. Harding 74154c2294
Add block::ValidationError
Add a `ValidationError` to the `block` module and remove the two
variants out of `crate::Error`.

This error is only used by the `validate_pow` function, a specific error
better serves our purposes.
2023-05-25 13:35:49 +10:00
Tobin C. Harding 3a9b5526b3
Move BlockHash From impls
Move the `From` impls on `BlockHash` to below the `BlockHash` impl
block.

Code move only, no other changes.
2023-05-25 13:32:25 +10:00
Tobin C. Harding 06afd52a12
Improve hashes::Error
We are trying to make error types stable on the way to v1.0

The current `hashes::Error` is a "general" enum error type with a single
variant, better to use a struct and make the error usecase specific.

Improve the `hashes::Error` by doing:

- Make it a struct
- Rename to `FromSliceError`
- Move it to the crate root (remove `error` module)

Includes usage in `bitcoin`.
2023-05-25 13:25:13 +10:00
Tobin C. Harding ab4e6d6f27
psbt: Remove reexport of Prevouts
No idea why this re-export is here, the `Prevouts` type is not even used
in the `psbt` module.

Remove the re-export of `crate::sighash::Prevouts` from `pstb`.
2023-05-24 22:10:40 +10:00
Tobin C. Harding 0046bb8ad8
Fix usage of cfg(rust_1_53)
Our custom conditional configuration options enables for various
versions of the compiler are not features.

Fix the incorrect usage.
2023-05-24 22:03:57 +10:00
Tobin C. Harding c3450f3913
Remove stale usage of doc(cfg)
We no longer need to use `doc(cfg())` because we use `doc_cfg_auto`,
remove it.
2023-05-24 22:02:24 +10:00
Andrew Poelstra b5aa482532
Merge rust-bitcoin/rust-bitcoin#1857: tests: Use script hash functions
013dffa65d tests: Use script hash methods (Tobin C. Harding)

Pull request description:

  The `ScriptBuf` type can be serialized using it's `to_bytes` function. Do not use the `psbt::Serialize` trait to do so in test code.

  No logic changes, since the impl of `psbt::Serialize` for `ScriptBuf` just calls `to_bytes`.

ACKs for top commit:
  Kixunil:
    ACK 013dffa65d
  apoelstra:
    ACK 013dffa65d

Tree-SHA512: 08959e065f1528f2ca69c12d5e34bceea3ddd17eefcee45094f071b3fa7357dbf289f6fe54d18fea02eecd1d0a7cd04598bbf014a5f10676387dbe27bb490395
2023-05-22 20:31:42 +00:00
Andrew Poelstra 8d111f20ef
Merge rust-bitcoin/rust-bitcoin#1864: Add a checked version of weight mul fee_rate
b03c24db8c Add a checked version of weight mul fee_rate (yancy)

Pull request description:

  Add a checked version of fee_rate * weight.  While I like the trait version of just being able to multiply `feerate * weight`, it's not really very useful imo since a large input feerate could cause an overflow.  Instead of changing the trait in https://github.com/rust-bitcoin/rust-bitcoin/pull/1849 (not idiomatic enough I guess) I added a `checked_weight_mul` method to `FeeRate`.

ACKs for top commit:
  apoelstra:
    ACK b03c24db8c
  Kixunil:
    ACK b03c24db8c

Tree-SHA512: 231ade94291becadcea9ea2a40a5daf96b77f01a29cca2494d7bbe4f7de5b412fa8fc816ea249268569f5378410185d9349fd687533bf3a422a752997e107a2b
2023-05-22 19:36:17 +00:00
Tobin C. Harding 013dffa65d
tests: Use script hash methods
We have methods to convert a script to a `WScritpHash` and `ScriptHash`,
no need to do this manually, let alone use the `psbt::Serialize` trait
to do so.
2023-05-20 07:31:54 +10:00
yancy b03c24db8c Add a checked version of weight mul fee_rate 2023-05-19 10:17:57 +02:00
TATHAGATA ROY 6a18997e3c Removed only available in 1.46.0 line 2023-05-18 12:14:38 +00:00
Tobin C. Harding c2f33f60b8
Add changelo entry for removal of FromHex
During the last round of releases (bitcoin 0.30, hashes 0.12) we removed
the `FromHex` implementation from all types except vecs and arrays. We
added `FromStr` impls for types that roundtrip with `Display`.

We never added a changelog mention to either `bitcoin` or `hashes`, lets
retroactively add an entry.

Fix: #1747
2023-05-18 14:18:42 +10:00
Martin Habovstiak 6cec19f6d3 Update documentation of `InputWeightPrediction`
The doc was written before alternative constructors existed, update it.
2023-05-11 20:38:32 +02:00