Commit Graph

16 Commits

Author SHA1 Message Date
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
yancy d57ec019d5 Use Amount type for TxOut value field 2023-05-04 17:09:08 +02:00
Martin Habovstiak 8b4280d5ef Update clippy MSRV configuration
We've upgraded MSRV but didn't update clippy config, so some things that
could be improved aren't caught by clippy. This updates the config and
fixes the new issues.

I also `rg '1\.41\.1'`ed for interesting changes and found one
additional improvement.
2023-04-02 16:28:10 +02:00
Tobin C. Harding a11cf07501
Run the formatter
Various formatting issues have crept into the codebase because we do not
run the formatter in CI.

In preparation for enabling formatting checks in CI run `cargo +nightly
fmt` to fix current formatting issues. No changes other than those
create by the formatter.
2023-03-06 10:22:29 +11:00
sanket1729 289dc1e7f5 Remove serde for taprootspendinfo
Implementing this for spendinfo is really complicated because it
contains some cached data without retaining the components that are used
to compute them.

Users should serde the 1) NodeInfo and 2) internal key and reconstruct
TaprootSpendInfo from it.
2023-03-01 16:58:24 -08:00
sanket1729 9affda3012 Introduce Hidden leaves in ScriptLeaves
Cleanly separate `TapTree` and `NodeInfo`. Fix serde not respecting
invariants for several data structures

Repurpose some tests from removed taproot builder for taptree
2023-03-01 16:58:24 -08:00
Tobin C. Harding 42b07586ac
Improve the public API
We created the `crypto` crate as a container for cryptography modules
with the idea that it may be split out into a separate crate. There is
no reason for users of the lib to know about this module. Also, we have
two `taproot` modules, one in `crypto` and one at the crate root, this
makes for un-ergonomic usage of the lib.

Improve the public API by doing:

- Make the `crypto` module private (`pub(crate)`).
- Re-export `crypto::taproot::Signature` (and `Error`) from
  `crate::taproot`
2023-03-01 09:28:42 +11:00
Tobin C. Harding be7b3754a9
Rename schnorr module to taproot
"schnorr" is a dirty word; the current `schnorr` module defines a
`Signature` that includes a sighash type, this sighash type is a bitcoin
specific construct related to taproot. Therefore the `Signature` is
better named `taproot::Signature`. Note also that the usage of `schnorr`
in `secp256k1` is probably justified because the
`secp256::schnorr::Signature` is just doing the crypto.

While we are at it, update docs and error messages to use "taproot"
instead of "schnorr". Also change function names and identifiers that
use "schnorr".
2023-02-20 12:58:09 +11:00
Tobin C. Harding 9f39e872bc
Rename SchnorrSighashType to TapSighashType
As we did for `SchnorrSighash`, rename the `SchnorrSighashType` to
`TapSighashType`.
2023-02-20 12:58:09 +11:00
Tobin C. Harding 7e4da3c0ab
Move taproot keys to the keys module
We have a keys module, taproot keys should live in there.
2023-02-20 12:58:05 +11:00
Tobin C. Harding 32d2d62e0f
Rename from_slice methods to decode
The `TaprootMerkleBranch` and `ControlBlock` both have methods on them
called `from_slice` but these methods do more that just basic copy from
a slice. `decode` is a more descriptive name.

Deprecate the `from_slice` methods and implement `decode`, on other
changes to the logic.
2023-02-07 14:54:08 +11:00
Tobin C. Harding a308e1e2ea
Remove FromHex for all types except Vec and array
Remove `FromHex` from hash and script types

- Remove the `FromHex` implementation from hash types and `ScriptBuf`
- Remove the `FromStr` implementation from `ScriptBuf` because it does not
  roundtrip with `Display`.
- Implement a method `from_hex` on `ScriptBuf`.
- Implement `FromStr` on hash types using a fixed size array.

This leaves `FromHex` implementations only on `Vec` and fixed size arrays.
2023-02-01 08:26:46 +11:00
Martin Habovstiak 8e428562cb Implemented unsized `Script`
This renames `Script` to `ScriptBuf` and adds unsized `Script` modeled
after `PathBuf`/`Path`. The change cleans up the API a bit, especially
all functions that previously accepted `&Script` now accept truly
borrowed version. Some functions that perviously accepted `&[u8]` can
now accept `&Script` because constructing it is no loger costly.
2022-12-14 23:21:27 +01:00
Andrew Poelstra 5b7d801ee6
remove PackedLockTime type
This can be replicated by deleting the `type PackedLockTime = LockTime'
line, and then running
    find . -type f | xargs sed -i 's/PackedLockTime/LockTime/g
at the root of the repo.
2022-12-11 19:08:14 +00:00
sanket1729 3a923980e1 Hotfix: Fix broken serde
My local scripts did not test serde feature on merge commit. While
merging 734, I accidently broke the serde feature on latest master. This
PR fixes it.
2022-12-01 15:57:37 -08:00
Tobin Harding 962abcc963 Add serde regression tests
In order that we can safely change/maintain de/serialization code we
need to have regression tests with hard coded serializations for each
type that implements serde.

It is enough to test a single serde data format, use JSON for `opcodes`
and bincode for other types.

Do regression testing in a newly added `tests` module.
2022-10-29 10:47:16 +11:00