Commit Graph

70 Commits

Author SHA1 Message Date
Tobin C. Harding aa8ba118ae
Add a new base58 crate
Add a new `base58` crate to the workspace and move the `bitcoin::base58`
module to it.

Done as part of crate smashing, specifically so that we can make `bip32`
into a separate crate.
2024-02-23 12:54:24 +11:00
Tobin C. Harding cf602583bd
io: Bump version to 0.1.1
We attempted to release with the current 0.1.0 version forgetting that
we had previously released an empty crate with that version to reserve
the name on crates.io.

Bump the version to 0.1.1 and release the actual code.
2024-02-18 09:39:28 +11:00
Tobin C. Harding a246dc98a4
Run sighash example in CI
Somehow we forgot to run the `sighash` example in CI.
2024-02-05 17:50:52 +11:00
Tobin C. Harding 518f0970c9
Implement ArbitaryOrd for absolute::LockTime
At times we would like to provide types that do not implement
`PartialOrd` and `Ord` because it does not make sense. I.e., we do not
want users writing `a < b`. This could range from kind-of-iffy to
down-right-buggy (like comparing absolute locktimes).

However this decision effects downstream users who may not care about
what the ordering means they just need to use it for some other reason
e.g., to use as part of a key for a `BTreeMap` (as we do in `miniscript`
requiring the `AbsLockTime` type).

A solution to this problem is to provide a wrapper data type that adds
`PartialOrd` and `Ord` implementations. I wrote the `ordered` crate is
for this very purpose.

Feature gate a new dependency on `ordered` and implement `ArbitraryOrd`
for `absolute::LockTime`.
2024-01-09 13:15:29 +11:00
Tobin C. Harding 69e56a64ed
Add bitcoin-units crate
Add a new crate `bitcoin-units`, move the `amount` module over to it and
re-export all types from `bitcoin::amount` so this as not a breaking
change.
2023-12-11 08:52:31 +11:00
Tobin C. Harding 48879e7ad9
Remove no-std feature
Currently `bitcoin` cannot be built with no features enabled, it must
have either "no-std" or "std" enabled. This is an artifact from when
we depended on `core2` for "no-std", now that we have our own `io` crate
and we unconditionally depend on it we can remove the "no-std" feature.
2023-12-06 09:54:33 +11:00
Tobin C. Harding 7d71fb9fdb
Re-order dependencies in manifest
Currently the feature enabling is different for "std" and "no-std",
which is again different to the order in the dependencies section. These
two things make reading the manifest harder than it needs to be.

Put the dependencies in alphabetic order in the dependencies section as
well as when enabling them.

Refactor only, no logic changes.
2023-12-04 14:21:06 +11:00
Tobin C. Harding 5c0759a390
Inline io module in io crate root
Its not immediately obvious why we nest the whole `io` code in an `io`
submodule within `lib.rs`. As far as I can tell we can inline it and
re-export from `rust-bitcoin` same as we do for our other dependencies.

This change would effect other users of the crate but since the `io`
crate is unreleased this effects no-one except us.
2023-11-28 14:17:14 +11:00
Andrew Poelstra 4806461c75
Merge rust-bitcoin/rust-bitcoin#2188: Bump MSRV to Rust version 1.56.1
761de886be Remove imports of TryFrom and TryInto (Tobin C. Harding)
4d5415f835 Add rust-version to the workspace manifests (Tobin C. Harding)
a41e978855 Update to edition 2021 (Tobin C. Harding)
d9cc724187 Bump MSRV to Rust version 1.56.1 (Tobin C. Harding)

Pull request description:

  Rust version 1.56.0 introduced edition 2021. Shortly afterwards, on October 21 2021 Rust version 1.56.1 was released.

  Debian stable is currently shipping `rustc 1.63.0`. Our stated MSRV policy is: In Debian stable and at least 2 years old. Therefore our MSRV policy is met by Rust version 1.56.1 and we can strat to bump our MSRV org wide. Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1

  Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1, includes:

  - Update docs.
  - Update CI and remove pinning.
  - Update the build files and remove now stale cfg attributes rust_v_1_x for values less than the new MSRV.
  - Use new `IntoIterator` for arrays so we no longer need to allocate a vector to iterate.

  Links:

  - https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html
  - https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
  - https://packages.debian.org/stable/rust/rustc

ACKs for top commit:
  Kixunil:
    ACK 761de886be
  apoelstra:
    ACK 761de886be

Tree-SHA512: 3a81c8bfa37d8cec0ec794f516f014da67ae8e437decf149c9681aa547885acac0ee07ea2c0f42e4f6bfd6f7ed1695fcf4747f53cc50e5f4e70ce3fe7bcba4e9
2023-11-26 13:48:23 +00:00
Andrew Poelstra 71d92bdbb9
Merge rust-bitcoin/rust-bitcoin#2095: bitcoin: Add signing examples
fa104aefa5 bitcoin: Add signing examples (Tobin C. Harding)

Pull request description:

  Add two signing examples to showcase signing a simple one input two output transaction using both segwit v0 outputs and taproot outputs.

  This patch is the result of the recent rust-bitcoin TABConf workshop, with bug fix by Sanket, updated to use APIs from tip of master branch.

  This code, depending on v0.30.0 is what was added to the cookbook.

ACKs for top commit:
  realeinherjar:
    ACK fa104aefa5
  apoelstra:
    ACK fa104aefa5

Tree-SHA512: ce0d5b8291c94387c68b5e1cf740d3267fc00c997af5b96f5be525f348140d9a9af17ab66d556990f09bf081a5a812374cb633ea276100c7c21f218b85eae3fd
2023-11-22 22:08:32 +00:00
Tobin C. Harding 4d5415f835
Add rust-version to the workspace manifests
Add `rust-version = 1.56.1` to all crates in the workspace i.e.,
including `fuzz` but excluding the various test crates.
2023-11-23 06:20:04 +11:00
Tobin C. Harding a41e978855
Update to edition 2021
We just bumped the MSRV to Rust 1.56.1 which includes edition 2021.

Update all crates in this repo to use edition 2021 and build/lint
warnings.
2023-11-23 06:20:03 +11:00
Tobin C. Harding a6d7d542ab
bitcoin:: Remove dev dependency serde_derive
We do not need this dependency because we can get the serde derives
directly from `serde`.

diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml
index 3868bd08..db7fb322 100644
--- a/bitcoin/Cargo.toml
+++ b/bitcoin/Cargo.toml
@@ -53,7 +53,6 @@ actual-serde = { package = "serde", version = "1.0.103", default-features = fals
 [dev-dependencies]
 serde_json = "1.0.0"
 serde_test = "1.0.19"
-serde_derive = "1.0.103"
 bincode = "1.3.1"

 [target.'cfg(mutate)'.dev-dependencies]
2023-11-20 15:17:30 +11:00
Matt Corallo add371d263 Remove `core2` dependency entirely 2023-11-09 16:46:44 +00:00
Matt Corallo 27c7c4e26a Add a `bitcoin_io` crate
In order to support standard (de)serialization of structs, the
`rust-bitcoin` ecosystem uses the standard `std::io::{Read,Write}`
traits. This works great for environments with `std`, however sadly
the `std::io` module has not yet been added to the `core` crate.

Thus, in `no-std`, the `rust-bitcoin` ecosystem has historically
used the `core2` crate to provide copies of the `std::io` module
without any major dependencies. Sadly, its one dependency,
`memchr`, recently broke our MSRV.

Worse, because we didn't want to take on any excess dependencies
for `std` builds, `rust-bitcoin` has had to have
mutually-exclusive `std` and `no-std` builds. This breaks general
assumptions about how features work in Rust, causing substantial
pain for applications far downstream of `rust-bitcoin` crates.

Here, we add a new `bitcoin_io` crate, making it an unconditional
dependency and using its `io` module in the in-repository crates
in place of `std::io` and `core2::io`. As it is not substantial
additional code, the `hashes` io implementations are no longer
feature-gated.

This doesn't actually accomplish anything on its own, only adding
the new crate which still depends on `core2`.
2023-11-07 05:50:42 +00:00
Tobin C. Harding fa104aefa5
bitcoin: Add signing examples
Add two signing examples to showcase signing a simple one input two
output transaction using both segwit v0 outputs and taproot outputs.

This patch is the result of the recent rust-bitcoin TABConf workshop,
wit bug fix by Sanket, updated to use APIs from tip of master branch.

This code, depending on v0.30.0 is what is being introduced to the
cookbook at the moment.
2023-10-31 10:11:48 +11:00
Tobin C. Harding efedf862b0
bitcoin: Bump version number to v0.31.0
In preparation for release of v0.31.0 bump the version number.

The changelog is already up to date because we have done two RC
releases.
2023-10-28 08:32:30 +11:00
Tobin C. Harding 38960ab5a5
Bump version to 0.31.0-rc2
In preparation for doing the next RC release bump the version.
2023-10-18 13:52:49 +11:00
Tobin C. Harding 6731e85dc1
bitcoin: Bump version to 0.31.0-rc1
In preparation for the first rc release; bump the version number.
2023-10-13 08:34:46 +11:00
Tobin C. Harding 6f30ac9d02
Upgrade the secp dependency
Upgrade the `secp256k1` dependency to the newly released `v0.28.0`.

FTR this includes two simple changes:
- Use `Message::from_digest_slice` instead of `Message::from_slice`.
- Use `secp256k1::Keypair` instead of `secp256k1::KeyPair`.
2023-10-10 10:04:31 +11:00
Tobin C. Harding 33ee49f8e5
Update bech32 dependency
Update the `bech32` dependency to use the newly release beta version.

The main fix here is silent, a bug fix in `bech32` that was being hit by
our fuzzing suite.
2023-10-10 06:47:58 +11:00
sanket1729 a1538a42c1
rand-std should enable std
Users should not need to specify both.
2023-10-03 23:10:23 -07:00
Tobin C. Harding e4c7e01a6f
Use the new bech32 iterator API
Use the new bech32 iterator API that Andrew and I wrote.
2023-09-21 15:10:57 +10:00
junderw 18e2854a42
Update base64 usage to 0.21.3 2023-08-30 22:47:56 -07:00
Tobin C. Harding 53f68383b7
hashes: Bump version to 0.13.0
Add a changelog entry and bump the version to 0.13.0

Does not include changes to `bitcoin` to depend on the new version.
2023-08-24 12:25:42 +10:00
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
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
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
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 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
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
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
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 d5655d503a
Bump core2 dependency from 0.3.0 -> 0.3.2
`core2` versions 0.3.0 and 0.3.1 do not work with Rust 1.48.0, set
minimum version to 0.3.2 in the `bitcoin` manifest.
2023-05-01 10:07:43 +10:00
Tobin C. Harding fabcde036f
Use package in manifest and shorten import
We can use `package` to rename `bitcoin_hashes` to `hashes` and
`bitcoin_internals` to `internals`. This makes imports more terse with
no loss of meaning.
2023-03-28 12:20:04 +11:00
Tobin C. Harding 998b204ece
bitcoin: Fix path to the readme
We moved to a submodule and didn't fix the readme path in the `bitcoin`
manifest.
2023-03-22 12:08:48 +11:00
Tobin C. Harding ffee8ad81b
Bump version to v0.30.0
Add changelog notes and bump the version number to v0.30.0.
2023-03-22 08:41:21 +11:00
Andrew Poelstra 6aa640ff8d
update rust-secp to 0.27.0
Also remove the spurious dev-dependency copy of rust-secp, which
should've been updated to remove the "recovery" feature in
https://www.github.com/rust-bitcoin/rust-bitcoin/pull/545 and
then been removed entirely in https://www.github.com/rust-bitcoin/rust-bitcoin/pull/1387
2023-03-18 22:01:42 +00:00
Andrew Poelstra 51f2f8483c
rename bitcoin-internals to bitcoin-private 2023-03-13 16:02:12 +00:00
Andrew Poelstra ca3b4330e8
specify `internals` version in other Cargo.toml files 2023-03-08 15:02:31 +00:00
Andrew Poelstra d1b7b54e3a
bump bitcoin-hashes version to 0.12
Because we have rust-secp in the loop, we need to update rust-secp, push
a new tag, and use that here, to ensure that the direct dependency on
bitcoin_hashes, and the rust-secp version, are compatible.
2023-03-05 13:40:20 +00:00
Tobin C. Harding 161273b209
Re-name hash inner/byte methods
Currently we have an associated type on hash types `Inner` with
accompanying methods `into_inner`, `from_inner`, `as_inner`. Also, we
provide a way to create new wrapped hash types. The use of 'inner'
becomes ambiguous with the addition of wrapped types because the inner
could be the inner hash type or the `Inner` byte array of the inner
wrapped hash type.

In an effort to make the API more clear and uniform do the following:

- Rename `Inner` -> `Bytes`
- Rename `*_inner` -> `*_byte_array`
- Rename the inner hash to/from methods to `*_raw_hash`

Correct method prefix `into_` -> `to_` because theses methods convert
owned `Copy` types.

Add the trait Bound `Copy` to the `Bytes` type because we rely on this
trait bound for the conversion methods to be correctly named according
to convention.

Because of the dependency hole created by `secp256k1` this patch changes
the secp dependency to a git tag dependency that includes changes to the
hashes calls required so that we can get green lights on CI in this
repo.
2023-02-27 14:23:58 +11:00
Tobin C. Harding 2620f3b69d
Put optional = true at the end
In order to be uniform and make it easier to quickly see that the
dependency is optional put `optional = true` as the last item in the
config set.
2023-02-21 08:35:25 +11:00
Tobin C. Harding d86ef3b01b
Put non-optional dependency with other non-optional
We have a separation between optional dependencies and non-optional
dependencies, `hex_lit` snuck in to the wrong group.
2023-02-21 08:33:51 +11:00
Martin Habovstiak bb2c7ec790 Introduce `hex_lit` crate
So far we deserialized hex into `Vec<u8>` at run time. This was mainly
in tests where it had negligible performance cost. However moving the
computation to compile time has a few benefits: it allows proving the
length of the decoded bytes and identifies potential typos before the
code goes through LLVM and other compilation machinery which makes
feedback faster.

This change uses the `hex_lit` crate to move computation to compile
time. It is implemented as `const` declarative macro which doesn't blow
up compilation time.
2023-02-18 12:03:08 +01:00
Tobin C. Harding 8596e402f2
Fix docs.rs to use all features
Many moon ago we were unable to build with `--all-features`, this is no
longer the case.

Instruct docs.rs to build the docs with `--all-features`.
2023-02-10 08:04:11 +11:00
Tobin C. Harding 132d2f90b6
bitcoin: Enable alloc feature in features list
In `bitcoin` when we use the `core2` dependency we always need the
"alloc" feature. Enabling "alloc" when enabling "core2" in the "no-std"
feature is confusing because it makes it seem that we don't always need
it.

Set usage of the "alloc" feature of `core2` in the `features` list.
2023-02-08 08:24:50 +11:00
Tobin C. Harding aa62ca224a
hashes: Do not enable core2/alloc feature
`core2` is for Read/Write, nothing to do with allocation and we do not
use the "alloc" feature of `core2` in `hashes`.

Fix core2 dependency/features by doing:

- Explicitly enable "bitcoin_hashes/core2" in `bitcoin`.
- Do not enable "core2/alloc" in `hashes`
2023-02-08 08:24:49 +11:00
Tobin C. Harding c15f8dee29
Improve manifest package section
Improve all manifest package sections by doing:

- Order the list of options uniformly
- Remove unnecessary homepage option (currently same as repo)
- Add categories section
2023-02-08 08:24:49 +11:00