Commit Graph

816 Commits

Author SHA1 Message Date
Marko Bencun ad83f6ae00
util/address: make address encoding more modular
This allow library clients to plug their own encoding parameters in a
backwards compatible manner.
2021-12-12 13:10:48 +01:00
Dr. Maxim Orlovsky ed40f3d3a6
Merge rust-bitcoin/rust-bitcoin#728: Use un/tweaked public key types
b5bf6d7319 Improve rustdocs on schnorr module (Tobin Harding)
a6d3514f2b Return parity when doing tap_tweak (Tobin Harding)
7af0999745 Re-name TweakedPublicKey constructor (Tobin Harding)
3c3cf0396b Remove use of unreachable in error branch (Tobin Harding)
d8e42d153e Remove 'what' comments (Tobin Harding)
b60db79a3b Use un/tweaked public key types (Tobin Harding)
402bd993b2 Add standard derives to TweakedPublickKey (Tobin Harding)
9c015d9ce3 Add newline to end of file (Tobin Harding)

Pull request description:

  We have two types for tweaked/untweaked schnorr public keys to help users of the taproot API not mix these two keys up. Currently the `taproot` module uses 'raw' `schnoor::PublicKey`s.

  Use the `schnoor` module's tweak/untweaked public key types for the `taproot` API.

  Fixes: #725

  Please note, I saw this was labeled 'good-first-issue' but I ignored that and greedily implemented a solution because of two reasons
  1. We want to get taproot stuff done post haste.
  2. I'm struggling to follow what is going on with all the taproot work so this seemed like a way to get my hands dirty.

ACKs for top commit:
  dr-orlovsky:
    utACK b5bf6d7319
  sanket1729:
    ACK b5bf6d7319

Tree-SHA512: e3e0480e0d193877c33ac11d0e3a288b0393d9475b26056914e439cb3f19583c1936e70d048df8d2120a36a63b6b592d12e21ca3ab7e058dce6f8f873c3b598b
2021-12-12 08:31:50 +02:00
Dr. Maxim Orlovsky 9ae0f05d74
Merge rust-bitcoin/rust-bitcoin#701: Decrease Huffman Weights to u32
1518517374 Decrease Huffman weight type to 32 bits (Jeremy Rubin)

Pull request description:

  This builds on https://github.com/rust-bitcoin/rust-bitcoin/pull/699 but is the more bikesheddable part since it changes the API.

  > u32 of weight should be enough for any branch.
  -- Bill Gates

ACKs for top commit:
  dr-orlovsky:
    utACK 1518517374
  Kixunil:
    ACK 1518517374

Tree-SHA512: 9c507ae6129dda8dc069b0a142181a78cf89cb3ebf9d2169c46662822cb4ea9ed075bf484528f5399fe0ed383a425174a702e2d685f31c246f5a86c46ed17c3a
2021-12-11 22:41:16 +02:00
Tobin Harding b5bf6d7319 Improve rustdocs on schnorr module
Improve the docs by doing:

- Use [`Foo`] for types
- Use third person tense
- Add trailing periods
2021-12-10 11:46:20 +11:00
Tobin Harding a6d3514f2b Return parity when doing tap_tweak
Currently we calculate the parity during `tap_tweak` but do not return
it, this means others must re-do work done inside `tap_tweak` in order
to calculate the parity. We can just return the parity along with the
tweaked key.
2021-12-10 11:45:58 +11:00
Tobin Harding 7af0999745 Re-name TweakedPublicKey constructor
Keeping inline with the method on `UntweakedPublicKey` that outputs a
`TweakedPublicKey` we can use the same name, for the same reasons.

Use `dangerous_assume_tweaked` as the constructor name to highlight the
fact that this constructor should probably not be being used.
2021-12-10 11:45:06 +11:00
Tobin Harding 3c3cf0396b Remove use of unreachable in error branch
We currently run `tweak_add_check` and use the result as a conditional
branch, the error path of which uses `unreachable`. This usage of
`unreachable` is non-typical. An 'unreachable' statement is by
definition supposed to be unreachable, it is not clear why we would need
to have a conditional branch to check an unreachable statement.

Use `debug_assert!` so programmer errors get caught in un-optimised
builds but in optimised builds the call to `tweak_add_check` is not even
done.
2021-12-10 11:37:07 +11:00
Tobin Harding d8e42d153e Remove 'what' comments
When used, code comments should say _why_ we do something not _what_ we
do, the code already says what we do.

Remove 'what we do' style comments.
2021-12-10 11:37:07 +11:00
Tobin Harding b60db79a3b Use un/tweaked public key types
We have two types for tweaked/untweaked schnorr public keys to help
users of the taproot API not mix these two keys up. Currently the
`taproot` module uses 'raw' `schnoor::PublicKey`s.

Use the `schnoor` module's tweak/untweaked public key types for the
`taproot` API.
2021-12-10 11:37:07 +11:00
Tobin Harding 402bd993b2 Add standard derives to TweakedPublickKey
All new types in `rust-bitcoin` should use our standard set of derives.

Add said standard derives to `TweakedPublickKey`.
2021-12-10 11:37:07 +11:00
Tobin Harding 9c015d9ce3 Add newline to end of file
Idiomatic UNIX file handling leaves files with a newline at the end.

Add newline to end of `schnorr` module.
2021-12-10 11:37:07 +11:00
Tobin Harding b454cf8e15 Return None from merkle_root functions
The merkle_root of an empty tree is undefined, this is the only error
case we have for the two `bitcoin_merkle_root*` functions. We can fully
describe this error case by returning an `Option` if args are found to
be empty. We can do the same for the wrapper functions in `block`
module.

While we are at it, refactor out a recursive helper function to make
reading the code between the two functions easier.
2021-12-10 11:24:30 +11:00
Tobin Harding 7a8b017ea3 Use correct spelling of merkle
Fix typo in test function name to use the correct spelling of
'merkle' (not 'merkel').
2021-12-10 11:18:23 +11:00
Tobin Harding 628168e493 Add missing white space character 2021-12-10 10:03:15 +11:00
Dr. Maxim Orlovsky 95cf9b0a44
Merge rust-bitcoin/rust-bitcoin#697: Use TapTweakHash::from_key_and_tweak() method in computing tweak for UntweakedPublicKey
5b21a9cb1f Use TapTweakHash method for computing tweak (Noah)

Pull request description:

  Quick follow up PR to #691 using a method from #677.

  ### Changes
  - Updated `UntweakedPublicKey::tap_tweak(...)` to use `TapTweakHash::from_key_and_tweak(...)`

ACKs for top commit:
  Kixunil:
    ACK 5b21a9cb1f
  dr-orlovsky:
    utACK 5b21a9cb1f

Tree-SHA512: d00455bba51981e9ec942a6cf69672666e227850d073b1fdcd92d2eb6ad553659fb2967aec2ce12d3ed109cee5fa125cdda649cddb25404f08adae2bfd3e19bb
2021-12-02 10:43:50 +02:00
Riccardo Casatta 51b1abdab2
Merge rust-bitcoin/rust-bitcoin#719: Use expect instead of unwrap for calls to consensus_encode
e7b84e20d3 Use expect for concensus_encode on Vec (Tobin Harding)
4031fbf4ba Use expect for concensus_encode on sinks (Tobin Harding)
fa513bb5b5 Use expect for concensus_encode on engines (Tobin Harding)
a2efafcf9a Use error instead of err (Tobin Harding)

Pull request description:

  Calls to `unwrap` outside of tests are generally unfavourable. We currently call `unwrap` in a bunch of places on calls to `consensus_encode` when passing writers that do not fail.

  Remove `unwrap` calls on all calls to `consensus_encode` that pass a writer argument for which write functions do not fail. Use `expect` with a descriptive string instead.

  Fixes: #714

ACKs for top commit:
  Kixunil:
    ACK e7b84e20d3
  RCasatta:
    ACK e7b84e20d3

Tree-SHA512: 3f84598a14ecf3dcde4f418ad1a1dc5278b3ef8b2604f4e9fc4cf4e9aed8390a4a1cf0df47edb5956cc5b667d6c8864e34621c0dae974ea75d6daf1b133165dd
2021-12-01 10:57:27 +01:00
Tobin Harding e7b84e20d3 Use expect for concensus_encode on Vec
Calls to `unwrap` outside of tests are typically unfavourable.

In memory writers (`Vec`) do not error. We can use `expect` with a
descriptive message string to indicate this.
2021-11-25 10:07:25 +11:00
Tobin Harding fa513bb5b5 Use expect for concensus_encode on engines
Calls to `unwrap` outside of tests are typically unfavourable.

Hash engines do not error when calling `consensus_encode`. Instead of
the current usage of `unwrap` we can use `expect` with a descriptive
string as is done in other parts of the codebase.
2021-11-25 10:01:41 +11:00
Jeremy Rubin 1518517374 Decrease Huffman weight type to 32 bits 2021-11-24 14:55:34 -08:00
Tobin Harding a2efafcf9a Use error instead of err
In the name of uniformity use the same error message as argument to
`expect` througout the codebase.

Use "engines don't error" instead of "engines don't err".
2021-11-25 09:51:30 +11:00
Noah 5b21a9cb1f Use TapTweakHash method for computing tweak 2021-11-25 09:45:27 +11:00
Jeremy Rubin 3b968e482c Add Huffman Encoding Test 2021-11-24 12:21:55 -08:00
Dr Maxim Orlovsky 5286d0ab0c
Merge rust-bitcoin/rust-bitcoin#699: Huffman Bug Fix
f2a6827982 Fix BinaryHeap direction for Taproot Huffman Encoder (Jeremy Rubin)
cccd75d004 Fix Weighting Addition to never error on overflow + prevent overflows from ever happening with wider integers (Jeremy Rubin)

Pull request description:

  I noticed one cleanup & one bugfix while looking into the huffman algorithm:

  1) the cleanup: we can use a u128 to guarantee no overflows, and saturating_add to guarantee reasonable behavior in any case
  2) the bug: the binary heap is a max heap so the behavior ends up merging the nodes of the most likely entries repeatedly. a huffman encoder requires merging the least likely elements, so it should be reversed.

ACKs for top commit:
  sanket1729:
    ACK f2a6827982
  dr-orlovsky:
    utACK f2a6827982

Tree-SHA512: 07cadb8dd5cc2b7e6ae3ebc2c1639de054e41bcd7f3b7d338a93e77fd200c9591a89915aaae5d9f5313eff3d94032fdfe06d89fda1e2398881b711d149e9afe9
2021-11-23 19:23:03 +01:00
Dr Maxim Orlovsky d614b6c759
Merge rust-bitcoin/rust-bitcoin#704: util/address: Improve docs
822c99222d Improve constructor rustdocs for Address (Tobin Harding)
804a38cb67 Improve documentation of `WitnessVersion` (Tobin Harding)
eb8278fd2e util/address: Improve docs (Tobin Harding)

Pull request description:

  Improve documentation of the `address` module by doing:

  - Add full stops to all sentences
  - Use code ticks even inside links e.g., [`WitnessVersion`]
  - Use 100 character line length
  - Do grammar fixes
  - Use comment sections (e.g. `# Returns`)
  - Use 3rd person for function comments e.g. 'Converts foo to bar' instead of 'Convert foo to bar'
  - Use ticks for scriptPubkey

  This patch does a single file because a bunch of these changes pick an
  arbitrary stlye, if we can bikeshed on this PR then future PRs should be
  able to progress more quickly. I'll take lack of comment on any of the
  above as approval and I'll attempt to be uniform when doing the rest of
  the codebase. I plan on just chipping away at this, I can only do so
  much docs work in a day without getting bored of it :)

  Notes:

  - I didn't touch 'segwit' vs 'SegWit', seems both are widely used.
  - Using ticks inside links may be an overkill but seems more correct?
  - I'm not totally sure where the line is in the Rust ecosystem between
    readability in an editor and rendering as HTML, open to input on this.

ACKs for top commit:
  Kixunil:
    ACK 822c99222d
  dr-orlovsky:
    ACK 822c99222d

Tree-SHA512: bfbaeec74803dd0704ed3e39b9a4966db34dbb3d7ea850ed6230abf220b877687ac1479f4940b7bf39d7e8172cd62c36b232bfaa8186a92cc58b3d7e642674f6
2021-11-23 18:00:55 +01:00
Dr Maxim Orlovsky 435298c427
Merge rust-bitcoin/rust-bitcoin#707: P2tr fixes
e4774e74eb fixups to taptweaking code (sanket1729)

Pull request description:

  This was my bad for not clearly stating the expected spec #687 . Changed values to references so that we only take ownership where it is required.

  This should simplify the #697

ACKs for top commit:
  Kixunil:
    ACK e4774e74eb
  dr-orlovsky:
    utACK e4774e74eb

Tree-SHA512: adacbfa8a77f46b2c85720f3760ed12a437f40d8422731d0207662d7947c95dda79d576923f6056c77f57977a3dcd25afd270f0ee11e9c3be9d067ccdc63371a
2021-11-23 17:41:31 +01:00
Tobin Harding e04795093f Add unit test for bitcoin_merkle_root functions
We test `bitcoin_merkle_root` over in the `blockdata::block` module.
Although the `bitcoin_merkle_root` and `bitcoin_merkle_root_inline`
functions are almost identical there is enough index manipulation done
that it is not immediately obvious that the code is error free.

Add a unit test that verifies that the two functions return the same
resulting merkle root.
2021-11-22 13:03:31 +11:00
sanket1729 e4774e74eb fixups to taptweaking code 2021-11-21 11:53:55 -08:00
Tobin Harding 822c99222d Improve constructor rustdocs for Address
Improve the rustdocs for the various `Address` constructors by putting
the brief description on a separate line with further description in its
own paragraph. This is the layout best practice for function documentation
using rustdocs.

Also, favour 'creates' over 'constructs' because it is more common in
the docs of this struct.
2021-11-19 09:42:19 +11:00
Tobin Harding 804a38cb67 Improve documentation of `WitnessVersion`
Attempt to improve the rustdocs for `WitnessVersion` in line with
review comments from a previous patch.
2021-11-19 09:35:14 +11:00
Tobin Harding eb8278fd2e util/address: Improve docs
Improve documentation of the `address` module by doing:

- Add full stops to all sentences
- Use code ticks even inside links e.g., [`WitnessVersion`]
- Use 100 character line length
- Do grammar fixes
- Use comment sections (e.g. `# Returns`)
- Use 3rd person for function comments e.g. 'Converts foo to bar' instead of 'Convert foo to bar'
- Use ticks for scriptPubkey

This patch does a single file because a bunch of these changes pick an
arbitrary stlye, if we can bikeshed on this PR then future PRs should be
able to progress more quickly. I'll take lack of comment on any of the
above as approval and I'll attempt to be uniform when doing the rest of
the codebase. I plan on just chipping away at this, I can only do so
much docs work in a day without getting bored of it :)

Notes:

- I didn't touch 'segwit' vs 'SegWit', seems both are widely used.
- Using ticks inside links may be an overkill but seems more correct?
- I'm not totally sure where the line is in the Rust ecosystem between
  readability in an editor and rendering as HTML, open to input on this.
2021-11-18 09:43:08 +11:00
sanket1729 df72500465
Merge rust-bitcoin/rust-bitcoin#703: Return the correct `LeafVersion` when building a Taproot `ControlBlock`
0af5a433b6 Return the correct `LeafVersion` when building a Taproot `ControlBlock` (Alekos Filini)

Pull request description:

ACKs for top commit:
  sanket1729:
    ACK 0af5a433b6

Tree-SHA512: 6b887e86b32b070a2a42ba1a2309b094c36d5a0b0bbf7d4c49c4fd2d8d2b4a7b1d87da699f1bd5f7116926c590413609a292d900b55c27c6bdbadc408529999f
2021-11-16 14:59:39 -08:00
sanket1729 e66a94fa40
Merge rust-bitcoin/rust-bitcoin#683: tests: improve coverage for P2tr and AddressType
0d463ec19e tests: improve coverage for P2tr and AddressType (Leonardo Comandini)

Pull request description:

  The new AddressType test shows addresses that are valid but have
  no type. If in the future some of those get a type or become
  invalid (either voluntarily or due to a regression), this will
  highlight it.

ACKs for top commit:
  dr-orlovsky:
    utACK 0d463ec19e
  sanket1729:
    ACK 0d463ec19e

Tree-SHA512: 9e062a1807173638cb62a61a2e8ea5be8324449a8944c356073e8bd9f53941dea369c65a35dfa0019bd8323eaa5dd26a9907c1823522fef9a524e919728973a6
2021-11-16 08:49:13 -08:00
Martin Habovštiak ab97d2db1a
Merge pull request #689 from tcharding/module-rustdocs
Clean up module level rustdocs
2021-11-16 13:21:20 +01:00
Alekos Filini 0af5a433b6
Return the correct `LeafVersion` when building a Taproot `ControlBlock` 2021-11-16 11:45:23 +01:00
Tobin Harding dbb3edd482 Add deprecation comment
Module `contracthash` is deprecated, add this info to the module
rustdoc.
2021-11-16 13:01:51 +11:00
Leonardo Comandini 0d463ec19e
tests: improve coverage for P2tr and AddressType
The new AddressType test shows addresses that are valid but have
no type. If in the future some of those get a type or become
invalid (either voluntarily or due to a regression), this will
highlight it.
2021-11-15 21:36:13 +01:00
Jeremy Rubin f2a6827982 Fix BinaryHeap direction for Taproot Huffman Encoder 2021-11-15 09:38:44 -08:00
Jeremy Rubin cccd75d004 Fix Weighting Addition to never error on overflow + prevent overflows from ever happening with wider integers 2021-11-15 09:38:44 -08:00
Marko Bencun 8b1dbf5c9f
util/address: remove unused generic type 2021-11-14 13:10:40 +01:00
sanket1729 abc242dfe1
Merge rust-bitcoin/rust-bitcoin#654: Making globals part of PSBT struct. Closes #652
55c627715f Moving globals into PSBT struct (Dr Maxim Orlovsky)

Pull request description:

  I took the most non-invasive approach to reduce diff size. Many parts of the code can be improved in style or further refactored (like some functions are not necessary and can be just moved to be part of other functions), but I'd prefer to do that as a separate PR once this will be merged.

  My approach with this PR:
  1. Remove `Global` struct by moving its fields right into `PartiallySignedTransaction` - but keep the `util/psbt/map/global.rs` file with all its logic
  2. Keep existing `Map for Global` implementation in the same file, but just change it to `Map for PartiallySignedTransaction`
  3. With serialization, convert `Global` deserialization into crate-private function and use it from `PartiallySignedTransaction` deserialization
  4. Refactor the tests and imports as required to get the thing compile and pass tests

  The refactoring will be followed by PR(s) adding support for Taproot

ACKs for top commit:
  apoelstra:
    ACK 55c627715f
  sanket1729:
    ACK 55c627715f . Reviewed range diff with ac0c908 that I previously ACKed

Tree-SHA512: 79b329b6e4e60af905e4e00507d6abc558261d921bcf8f5d4ee34dd685322d7a529b18015423da50a388ba6732b7b662a92bc95ad078228cc809254ad010d467
2021-11-12 11:50:51 -08:00
Dr. Maxim Orlovsky 5631ec521e
Merge pull request #691 from nlanson/p2tr_address
P2TR address from untweaked key
2021-11-12 20:33:19 +01:00
sanket1729 fa8c3f6e44 Add tests for taproot utilities
Add tests for taproot Builder
Add tests for taproot huffman tree encoding
Add tests for merkle proof verification
2021-11-12 05:56:51 -08:00
sanket1729 1490ff36ee Add support for verifying merkle proofs 2021-11-12 05:56:51 -08:00
sanket1729 15f99df4ba Add huffman tree encoding 2021-11-12 05:56:51 -08:00
Noah Lanson 803b5fed8a P2TR address from untweaked public key
Ambiguous TweakedPublicKey and UntweakedPublicKey type aliases and methods to convert

Use structs for Untweaked and Tweaked key type

swap dangerous api to work on tweaked keys

remove unecessary allocations and rename methods

Use type alias for UntweakedPublicKey

TweakedPublicKey::new(...) method added

minor naming and doc changes
2021-11-11 14:36:56 +11:00
sanket1729 03f01b9965 Add taproot builder 2021-11-10 07:33:31 -08:00
sanket1729 e387cd1f7f Add taprootSpendInfo 2021-11-10 07:01:46 -08:00
sanket1729 b8e5909e04 Update sighash code to use LeafVersion instead of bare u8 2021-11-10 07:01:46 -08:00
sanket1729 ce887d373e Add taproot structures for Merkle Branch and ControlBlock 2021-11-10 07:01:45 -08:00
Tobin Harding 3f5caa501f Clean up module level rustdocs
Docs can always do with a bit of love.

Clean up the module level (`//!`) rustdocs for all public modules.

I claim uniform is better than any specific method/style. I tried to fit
in with what ever was either most sane of most prevalent, therefore
attaining uniformity without unnecessary code churn (one exception being
the changes to headings described below).

Notes:

* Headings - use heading as a regular sentence for all modules e.g.,

```
//! Bitcoin network messages.
```

as opposed to
```
//! # Bitcoin Network Messages
```

It was not clear which style to use so I picked a 'random' mature
project and copied their style.

* Added 'This module' in _most_ places as the start of the module
description, however I was not religious about this one.

* Fixed line length if necessary since most of our code seems to follow
short (80 char) line lengths for comments anyways.

* Added periods and fixed obvious (and sometimes not so obvious)
grammatically errors.

* Added a trailing `//!` to every block since this was almost universal
already. I don't really like this one but I'm guessing it is Andrew's
preferred style since its on the copyright notices as well.
2021-11-06 10:59:53 +11:00
Andrew Poelstra 454379cdfa
Merge rust-bitcoin/rust-bitcoin#612: Fix `Uint256::increment` panics
5d71a9dd89 Correct input length check for uin128 fuzzer (Matt Corallo)
9c256cc88e Add a fuzz check for `Uint128::increment` (Matt Corallo)
a15f263c4e Move the `increment` fn into the uint macro to add it to Uint128 (Matt Corallo)
d52b88b525 Fix increment of Uint256 with carry (carolcapps)

Pull request description:

  This is #578 with review feedback addressed.

ACKs for top commit:
  apoelstra:
    ACK 5d71a9dd89
  sanket1729:
    ACK 5d71a9d

Tree-SHA512: 32e5ea6387943ecad8f190a0de336a545fda72b6ff7388d3479037a5f880434276a7d0607f5cf61710d45e984c01954f4e3199a60c542be48b397717afb3d406
2021-09-27 17:45:53 +00:00
Dr. Maxim Orlovsky e49cdbd8e2
Merge pull request #563 from LNP-BP/taproot/address 2021-09-25 22:56:33 +02:00
Andrew Poelstra 9fe840c20e
Merge pull request #644 from sanket1729/tap_opcodes
Add OP_CHECKSIGADD and OP_SUCCESSxxx
2021-09-24 22:47:48 +00:00
Dr Maxim Orlovsky c1991d748f
Improving error information for address parser 2021-09-21 12:45:17 +02:00
Clark Moody eeeb722155
Bump bech32 to 0.8.0 and use BIP-0350 Bech32m checksum
Replace BIP-0173 test vectors with those in BIP-0350.
2021-09-21 12:45:17 +02:00
Dr Maxim Orlovsky 5573a546ca
Taproot P2TR address 2021-09-21 12:45:17 +02:00
Dr Maxim Orlovsky 55c627715f
Moving globals into PSBT struct 2021-09-16 12:34:04 +02:00
Dr. Maxim Orlovsky b7f984972a
Merge pull request #655 from vss96/Limit-Script-Size 2021-09-16 10:42:08 +02:00
Andrew Poelstra b6b60fc4aa
Merge rust-bitcoin/rust-bitcoin#628: Adds Taproot BIP341 signature message and create a unified sighash cache for legacy, segwit and taproot inputs
c704ee7ffe [docs-only] Use backtick in addition to square parentheses for types references, clarify legacy, non_exhaustive comment, remove std:: (Riccardo Casatta)
f223be618f Rename access_witness to witness_mut and return Option (Riccardo Casatta)
c9bc0b928a [fmt-only] autoformatting with `rustfmt src/util/sighash.rs` (Riccardo Casatta)
07774917c2 Use get_or_insert_with in segwit_cache (Martin Habovstiak)
497dbfb7c3 Use get_or_insert_with in common_cache() (Martin Habovstiak)
ca80a5a030 Use get_or_insert_with in taproot_cache (Martin Habovstiak)
6e06a32ccc Wrap ErrorKind in Io enum variant, fix doc comment for the IO variant (Riccardo Casatta)
1a2b54ff23 introduce constant KEY_VERSION_0 (Riccardo Casatta)
417cfe31e3 Derive common traits for structs and enum, make internal struct not pub (Riccardo Casatta)
55ce3dd6ae Fix validation error if SINGLE with missing corresponding output, remove check_index and check with get().ok_or(), more details in errors (Riccardo Casatta)
2b3b22f559 impl Encodable for Annex to avoid allocation (Riccardo Casatta)
1a7afed068 Add Reserved variant to SigHashType for future use (ie SIGHASH_ANYPREVOUT) (Riccardo Casatta)
53d0e176d3 Deprecate bip143::SigHashCache in favor of sighash::SigHashCache (Riccardo Casatta)
15e3caf62d [test] Test also sighash legacy API with legacy tests (Riccardo Casatta)
24acfe3672 Implement Bip341 signature hash, create unified SigHashCache for taproot, segwit and legacy inputs (Riccardo Casatta)
683b9c14ff add [En|De]codable trait for sha256::Hash (Riccardo Casatta)

Pull request description:

  Adds https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki message signature algorithm

  The base is taken from `bip143::SigHashCache`, some code results duplicated but I think it's more clear to keep things separated

  Would mark some bullet point on https://github.com/rust-bitcoin/rust-bitcoin/issues/503

  Test vectors are taken by running d1e4c56309/test/functional/feature_taproot.py with a modified `TaprootSignatureHash` function to print intermediate values that I cannot found in the bip341 [test vector json](https://raw.githubusercontent.com/bitcoin-core/qa-assets/main/unit_test_data/script_assets_test.json)

  UPDATE: Latest version includes the suggestion from @sanket1729 to create a unified tool for signature message hash for legacy, segwit, and taproot inputs. In particular, makes sense for mixed segwit v0 and taproot v1 inputs because cached values could be shared

ACKs for top commit:
  sanket1729:
    ACK c704ee7ffe. Reviewed the diff from a37de1ade475e0c31c932121abaa7aec701b9987 which I previously ACKed
  dr-orlovsky:
    utACK c704ee7ffe by diffing it to 6e06a32ccc having my ACK before.
  apoelstra:
    ACK c704ee7ffe

Tree-SHA512: 35530995fe9d078acd0178cfca654ca980109f4502c91d578c1a0d5c6cafacab7db1ffd6216288eac99f6a763776cbc0298cfbdff00b5a83e98ec4b15aa764e8
2021-09-15 17:47:17 +00:00
Vikas S Shetty 48c732e934 Changes for checking script size and returning Error appropriately 2021-09-15 16:16:20 +05:30
Martin Habovstiak 95fb4e01f9 Document cargo features
This documents cargo features in two ways: explictly in text and in code
using `#[doc(cfg(...))]` attribute where possible. Notably, this is
impossible for `serde` derives. The attribute is contitional and only
activated for docs.rs or explicit local builds.

This change also adds `package.metadata.docs.rs` field to `Cargo.toml`
which instructs docs.rs to build with relevant features and with
`docsrs` config activated enabling `#[doc(cfg(...))] attributes.

I also took the opportunity to fix a few missing spaces in nearby code.
2021-09-14 12:24:57 +02:00
sanket1729 c252b36786 Add CHECKSIGADD and update classify API 2021-09-13 07:45:00 -07:00
Dr Maxim Orlovsky d20669522e
Fixing no_std for Amount sum iterator 2021-09-13 10:36:07 +02:00
Dr. Maxim Orlovsky b2c8a7ebc1
Merge pull request #615 from sgeisler/2021-06-sum-amounts
Implement `Sum` for amount types
2021-09-11 00:11:15 +02:00
Andrew Poelstra 13a6c3b4d6
Merge rust-bitcoin/rust-bitcoin#625: Improvements to Error types (part 4)
994079b099 Refactoring error variants: removing unused; better names & inner types (Dr Maxim Orlovsky)

Pull request description:

  Removes controversial aspects from #560 (all `io::Error`-related changes) and leaves the rest

ACKs for top commit:
  sanket1729:
    ACK 994079b099
  apoelstra:
    ACK 994079b099

Tree-SHA512: 020e49193c885e862f45e5f7baabf1d22a3ec09e78fd7f573b2f3d327beb4f91683951ba080b3d804e8337a188dcad0f38ba70ee8059aef0681a0b2bba0a2140
2021-09-08 21:22:32 +00:00
Andrew Poelstra 2a655f4b58
Merge pull request #617 from LNP-BP/feat/witness-version
WitnessVersion type
2021-09-08 20:58:57 +00:00
Riccardo Casatta c704ee7ffe
[docs-only] Use backtick in addition to square parentheses for types references, clarify legacy, non_exhaustive comment, remove std:: 2021-08-31 13:58:48 +02:00
Riccardo Casatta f223be618f
Rename access_witness to witness_mut and return Option
fix the example in sighash to refer to sighash::SigHashCache instead of bip143::SigHashCache
2021-08-31 13:55:52 +02:00
Riccardo Casatta c9bc0b928a
[fmt-only] autoformatting with `rustfmt src/util/sighash.rs` 2021-08-31 13:54:41 +02:00
Sanket Kanjalkar bd5d875e8a
Merge pull request #623 from RCasatta/fixdoc
Fix documentation referencing macro var
2021-08-12 18:38:07 -07:00
Martin Habovstiak 07774917c2 Use get_or_insert_with in segwit_cache
This refactors the code to make it possible to use `get_or_insert_with`
instead of unwrapping in `segwit_cache()`. To achieve it `common_cache`
is refactored into two functions: one taking only the required borrows
and the original calling the new one. `segwit_cache` then calls the new
function so that borrows are OK.

Apart from removing unwrap, this avoids calling `common_cache` multiple
times.
2021-08-10 10:36:51 +02:00
Dr Maxim Orlovsky 64c1ec0b76
WitnessVersion type 2021-08-10 10:34:15 +02:00
Martin Habovstiak 497dbfb7c3 Use get_or_insert_with in common_cache()
There was a question whether this is equally performant. There are
multiple good reasons why it should be:

1. `get_or_insert_with` is marked `#[inline]`
2. Any good optimizer will inline a function that is used exactly once
3. 1 and 2 conclude that the closure will get inlined
4. Computing self.tx can then be moved to the only branch where it is
   required.
5. Even if get_or_insert_with didn't get optimized, which is extremely
   unlikely, the `tx` field is at the beginning of the struct and it
   probably has pointer alignment (`Deref` suggests it's a pointer).
   Alignment larger than pointer is not used, so we can expect the
   fields to be ordered as-defined. (This is not guaranteed by Rust but
   there's not good reason to change the order in this case.) We can
   assume that offset to tx is zero in most cases which means no
   computation is actually needed so the expression before closure is
   no-op short of passing it into the closure as an argument.

At the time of writing `#[inline]` can be seen at
https://doc.rust-lang.org/src/core/option.rs.html#933
2021-08-10 10:20:41 +02:00
Martin Habovstiak ca80a5a030 Use get_or_insert_with in taproot_cache 2021-08-10 10:02:33 +02:00
Dr. Maxim Orlovsky 4e3c2c32fc
Merge pull request #632 from tcharding/prefixes 2021-08-09 23:26:15 +02:00
Dr. Maxim Orlovsky 8ae030b951
Merge pull request #618 from elsirion/possible_networks 2021-08-09 23:25:06 +02:00
Dr Maxim Orlovsky 994079b099
Refactoring error variants: removing unused; better names & inner types 2021-08-01 21:08:39 +02:00
Tobin Harding adc1543e7c
Use consts for address prefix values
Instead of using magic numbers we can define constants for the address
prefix bytes. This makes it easier for future readers of the code to see
what these values are if they don't know them and/or see that they are
correct if they do know them.
2021-07-22 10:31:14 +10:00
Riccardo Casatta 6e06a32ccc
Wrap ErrorKind in Io enum variant, fix doc comment for the IO variant 2021-07-21 12:07:12 +02:00
Riccardo Casatta 1a2b54ff23
introduce constant KEY_VERSION_0 2021-07-21 12:07:10 +02:00
Riccardo Casatta 417cfe31e3
Derive common traits for structs and enum, make internal struct not pub 2021-07-21 12:07:08 +02:00
Riccardo Casatta 55ce3dd6ae
Fix validation error if SINGLE with missing corresponding output, remove check_index and check with get().ok_or(), more details in errors 2021-07-21 12:07:05 +02:00
Riccardo Casatta 2b3b22f559
impl Encodable for Annex to avoid allocation 2021-07-21 12:07:00 +02:00
Riccardo Casatta 1a7afed068
Add Reserved variant to SigHashType for future use (ie SIGHASH_ANYPREVOUT) 2021-07-21 12:05:42 +02:00
Riccardo Casatta 53d0e176d3
Deprecate bip143::SigHashCache in favor of sighash::SigHashCache 2021-07-21 12:05:40 +02:00
Riccardo Casatta 24acfe3672
Implement Bip341 signature hash, create unified SigHashCache for taproot, segwit and legacy inputs 2021-07-21 12:05:18 +02:00
Andrew Poelstra df4d70a37e
Merge pull request #627 from RCasatta/bigendian
Bigendian fixes and CI test
2021-07-20 20:56:16 +00:00
Devrandom 4826d0c6cc no_std support
Based on the original work by Justin Moon.

*MSRV unchanged from 1.29.0.*

When `std` is off, `no-std` must be on, and we use the [`alloc`](https://doc.rust-lang.org/alloc/) and core2 crates. The `alloc` crate requires the user define a global allocator.

* Import from `core` and `alloc` instead of `std`
* `alloc` only used if `no-std` is on
* Create `std` feature
* Create `no-std` feature which adds a core2 dependency to polyfill `std::io` features. This is an experimental feature and should be
used with caution.
* CI runs tests `no-std`
* MSRV for `no-std` is 1.51 or so
2021-07-15 09:04:49 +02:00
Riccardo Casatta 0f4d2cfcaa
swap bytes in network code instead of swapping only in little-endian 2021-06-29 16:01:34 +02:00
elsirion 94229ae964 Implement is_valid_for_network function for Address 2021-06-26 19:34:33 +02:00
Riccardo Casatta 8f27579c7f
fix documentation referencing macro var 2021-06-25 09:56:40 +02:00
Sebastian Geisler 4dae56908b Seal `CheckedSum` 2021-06-23 15:14:24 +02:00
Andrew Poelstra abff973e83
Merge pull request #601 from LNP-BP/feat/bech32m-1
Bech32m adoption
2021-06-18 21:14:12 +00:00
Dr Maxim Orlovsky aa5c36df12
Covering all BIP-173 and BIP-350 test vectors 2021-06-16 08:43:18 +02:00
Sebastian b0ae2a6842
Merge pull request #521 from RCasatta/errors_enum
Errors enum improvements
2021-06-15 14:01:56 +02:00
Riccardo Casatta 88c186e436
nits on display implementation 2021-06-14 12:24:31 +02:00
Riccardo Casatta c26b3b9679
remove unused RngError, saving 24 bytes 2021-06-13 22:40:55 +02:00
Riccardo Casatta 9613181601
Split invalid version for address and extended key, saving also 16 bytes on the stack 2021-06-13 22:39:32 +02:00
Riccardo Casatta bace07d8f8
Remove base58::Error::Other variant in favor of specific variant 2021-06-13 22:33:54 +02:00
Riccardo Casatta 0eaf45ca81
Use boxed sliced instead of Vec in InvalidPreimageHashPair variant 2021-06-13 22:33:52 +02:00
Riccardo Casatta 781b0e014a
Box big Transaction type in psbt error 2021-06-13 22:33:48 +02:00
Sebastian Geisler 6f7da5f2ef Implement `CheckedSum` for amount types
It's just `Sum` with checked arithmetic.
2021-06-12 17:23:30 +02:00
Sebastian Geisler f28110b31c implement `Sum` for amount types
To be able to sum up iterators of amounts it is
not sufficient that these implement `Add`, they
also need to implement `Sum`.
2021-06-12 17:23:27 +02:00
Devrandom 95aa3bf153 std -> core 2021-06-11 17:28:04 +02:00
Matt Corallo a15f263c4e Move the `increment` fn into the uint macro to add it to Uint128 2021-06-08 22:20:36 +00:00
Sebastian Geisler 091ac89440 Fix semver breaking Display change of ChildNumber
Fixes #608. In #567 the Display impl for ChildNumber was
consciously changed, assuming the semver break would not
affect any correctly implemented downstream projects. We
were wrong.
2021-06-08 15:33:02 +02:00
Dr Maxim Orlovsky c1fae03686
Non-API breaking Bech32m adoption 2021-06-08 08:43:39 +02:00
Roman Zeyde 60e51ada36 Fix bip158 example formatting 2021-05-28 16:01:49 +03:00
Andrew Poelstra 052aaf1d80
Merge pull request #559 from LNP-BP/fix/error-derives-2
Fix/error derives 2
2021-05-19 15:02:10 +00:00
Andrew Poelstra e5f37b817d
Merge pull request #581 from RCasatta/qr_string
Address to optimized QR string
2021-05-06 17:12:17 +00:00
Andrew Poelstra d0fb626baf
Merge pull request #592 from LNP-BP/feat/ecdsa-key-creation
Constructors for compressed and uncompressed ECDSA keys
2021-05-06 15:50:06 +00:00
Dr Maxim Orlovsky c0b7defc86
More non-API breaking error derives depending on upstream PRs 2021-05-04 03:58:56 +02:00
Riccardo Casatta c96f7ec71c
use markdown autolink syntax for urls with no text 2021-05-03 13:46:10 +02:00
Riccardo Casatta ef471ccca7
Fix documentation, in particular link to code elements 2021-05-03 11:43:11 +02:00
Dr. Maxim Orlovsky 68096242d3
Merge pull request #594 from RCasatta/capped
Count bytes read in encoding
2021-05-01 16:28:57 +02:00
Dr Maxim Orlovsky 187eae8a13
Streamlining private key construction API in BIP32 2021-05-01 13:40:21 +02:00
Dr Maxim Orlovsky 18b6bd0d15
Adopting new ECDSA key constructors throughout the library 2021-05-01 13:34:31 +02:00
Dr Maxim Orlovsky ceacc7d85f
Constructors for compressed and uncompressed ECDSA keys 2021-05-01 13:34:04 +02:00
Andrew Poelstra 4db4e604cb
Merge pull request #589 from LNP-BP/taproot/key-1
Non-API breaking introduction of Schnorr keys
2021-04-29 20:30:54 +00:00
Riccardo Casatta f692c4a938
Limit bytes read with Take 2021-04-28 09:33:37 +02:00
Riccardo Casatta 0a91496570
rename to_qr_string into to_qr_uri returning also the schema 2021-04-15 10:40:57 +02:00
Dr Maxim Orlovsky 230813b578
Making old ECDSA key type paths depeicated 2021-04-12 14:18:15 +02:00
Dr Maxim Orlovsky 664b09cdfd
Re-export Scep256k1 Schnorr keys under `util::schnorr`
This is second step in introducing Schnorr key support as per #588
2021-04-12 14:18:00 +02:00
Dr Maxim Orlovsky b17d7fc31c
Moving keys under `util::ecdsa`, re-exporting them at `util::key`
This is the first step in introducing Schnorr key support as per #588
2021-04-12 14:17:42 +02:00
Riccardo Casatta 3158cedea0
document alternate formatting 2021-04-11 18:14:28 +02:00
Martin Habovstiak bc406bfdd6 Use &mut dyn fmt::Write instead of bool
This replaces manually-written dynamic dispatch with `&mut dyn
fmt::Write` which is hopefully more readable.
2021-04-09 17:58:35 +02:00
Riccardo Casatta 85ae82febb
use the char trick to avoid allocation 2021-04-07 16:56:54 +02:00
Riccardo Casatta 104836a042
implements alternate formatting for address 2021-04-07 15:49:58 +02:00
Dr Maxim Orlovsky 7fe3c4a605
Non-API breaking derives for error types 2021-04-06 14:44:50 +02:00
Riccardo Casatta cac3f460a2
improve to_qr_string doc 2021-03-23 09:42:58 +01:00
Riccardo Casatta d18554e756
Address to string conversion optimized for qr codes 2021-03-22 13:58:59 +01:00
Riccardo Casatta b9d5200448
Access Display and Formatter with fmt:: like in other places 2021-03-22 13:42:32 +01:00
Andrew Poelstra 20f1543f79
Merge pull request #552 from JeremyRubin/fix-amount-serde
Fix Optional Amount Serialization
2021-03-15 15:48:20 +00:00
Steven Roose 7df0d14f1a
Merge pull request #577 from RCasatta/proprietary_key
Include proprietary key in deserialized PSBT
2021-03-15 12:16:30 +00:00
Steven Roose 6a0f68df85
Merge pull request #557 from LNP-BP/psbt/display_from_str
PSBT base64 (de)serialization with Display & FromStr
2021-03-13 19:39:58 +00:00
carolcapps d52b88b525 Fix increment of Uint256 with carry 2021-03-13 15:19:43 +00:00
Riccardo Casatta 7e25c133d8
Include proprietary keys in deserialized fields 2021-03-13 15:41:07 +01:00
Riccardo Casatta fcd7200efe
Proprietary key test failing rtt 2021-03-13 15:19:21 +01:00
Andrew Poelstra bee5e8a090
Merge pull request #567 from LNP-BP/bip32/child-number-display
Improving bip32 ChildNumber display implementation
2021-03-12 21:01:56 +00:00
Jeremy Rubin a0c7f530ba Localize breaking changes of fixing the Amount serialization to only the
broken Option<SerdeAmount> serializer.
2021-02-28 09:13:52 -08:00
Dr Maxim Orlovsky 7b7b73f6d2
Improving PSBT FromStr error type 2021-02-22 12:46:22 +01:00
Dr Maxim Orlovsky 79f2729b20
Improving PSBT error tests 2021-02-22 12:46:22 +01:00
Dr Maxim Orlovsky 94102fa597
PSBT Base64 serialization test cases 2021-02-22 12:46:22 +01:00
Dr Maxim Orlovsky 072e1d1b86
PSBT Display & FromStr using Base64 serialization 2021-02-22 12:46:22 +01:00
Andrew Poelstra 2414c5b0a9
Merge pull request #573 from darosior/standard_sighash
SigHashType: add a method to error on non-standard hashtypes
2021-02-21 15:34:58 +00:00
Andrew Poelstra 81c56dec60
Merge pull request #551 from LNP-BP/feat/key-error-derives
More derives for key::Error
2021-02-21 14:14:54 +00:00
Sebastian 3ecab20c17
Merge pull request #414 from stevenroose/amount-debug
Change Amount Debug impl to BTC with 8 decimals
2021-02-21 15:14:40 +01:00
Antoine Poinsot e36f3a38e4
transaction: deprecate SigHashType::from_u32 in favor of from_u32_consensus
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-02-19 11:36:44 +01:00
Dr Maxim Orlovsky 017cd71ca7
Improving bip32 ChildNumber display implementation 2021-02-11 23:06:24 +01:00
Nadav Ivgi a1e98a6796
Implement Ord for ParseLengthError 2021-01-22 00:27:28 +02:00
Nadav Ivgi 55657cbffb
Implement Error and Eq for ParseLengthError 2021-01-16 13:02:22 +02:00
Nadav Ivgi 0df86b4426
Switch to a single-variant error type, implement standard derives 2021-01-14 22:17:18 +02:00
Jeremy Rubin da21294ac5 Fix Optional Amount Serialization 2021-01-14 10:46:20 -08:00
Nadav Ivgi 4a7cf34eeb
Use efficient serialization for non-human-readable formats 2021-01-14 19:36:36 +02:00
Nadav Ivgi b70361370b
Make uint types (un)serializable 2021-01-14 19:36:35 +02:00
Nadav Ivgi 67ae602e2a
Implement Uint::from_be_slice()
Needed because Rust 1.29 does not easily allow converting from a slice
into an array.
2021-01-14 19:36:30 +02:00
Nadav Ivgi 3761b0d808 Implement Uint::to_be_bytes() 2021-01-14 19:28:02 +02:00
Dr Maxim Orlovsky 246713821d
More derives for key error 2021-01-14 16:03:53 +01:00
Steven Roose 61918dfe81
Change the signature of consensus_encode to return io::Error's
This is instead of encode::Errors because the encoders should
not be allowed to return errors that don't originate in the writer
they are writing into.

This is a part of the method definition that has been relied upon for a
while already.
2021-01-12 17:39:41 +00:00
Andrew Poelstra b48f374c2c
Merge pull request #542 from apoelstra/2021-01--keyread
PublicKey: add read_from method to be symmetric with write_into
2021-01-11 19:50:04 +00:00
Andrew Poelstra 92000bf51b PublicKey: add read_from method to be symmetric with write_into 2021-01-04 19:07:27 +00:00
Steven Roose 5fd92d1c09 psbt: Serialize maps with byte values using hex 2020-12-30 16:32:52 +01:00
Steven Roose a05f8feec6 serde_util: Rename the btreemap module to btreemap_as_seq
So that we can later distinguish other modules over maps.
2020-12-30 16:32:52 +01:00
Steven Roose a9c13272a0 psbt: Fix serde for maps with non-string keys and binary values 2020-12-30 16:32:52 +01:00
Steven Roose e5f3bca2b4 Add serde_utils module to fix JSON serialization 2020-12-30 16:32:52 +01:00
Steven Roose cdedb0a9d5 psbt::raw: Use hex::format_hex to format the raw key bytes 2020-12-30 16:32:52 +01:00
Steven Roose 94b7371424 Replace serde_struct_impl with derive-based impls 2020-12-30 16:32:52 +01:00
Steven Roose d527a2c2cf Remove the impl_array_newtype_show macro
Instead, implement Debug in impl_bytes_newtype.
2020-12-30 16:32:52 +01:00
Andrew Poelstra 1cc466fec6
Merge pull request #498 from LNP-BP/pending/derivation
Derivation path improvements, closes #473
2020-12-28 00:53:25 +00:00
Dr Maxim Orlovsky 7400bccb60
PSBT: proprietary keys type system according to BIP 174 2020-12-21 12:22:35 +01:00
Dr Maxim Orlovsky c3024c3ebb
PSBT: basic support for proprietary keys 2020-12-21 12:17:07 +01:00
Dr Maxim Orlovsky 44ffddab8c
Impl IntoDerivationPath for string types 2020-12-20 23:39:01 +01:00
Dr Maxim Orlovsky f9290438cd
DerivationPath improvements
Adding IntoDerivationPath trait
DerivationPath is_master function
DerivationPath constructor for empty path + Default impl
2020-12-20 23:39:01 +01:00
Dr Maxim Orlovsky 7f5c2795d6
PSBT global xpub merging algorithm reworked 2020-12-20 11:41:24 +01:00
Dr Maxim Orlovsky b84faa7f5e
PSBT: Improved global keys version and xpub handling 2020-12-16 16:46:28 +01:00
Dr Maxim Orlovsky 21c11e3315
BSPT: Improving global xpub merging algorithm 2020-12-16 16:39:46 +01:00
Dr Maxim Orlovsky 8b1666295c
Nits in new PSBT global types reviews 2020-12-15 16:04:02 +01:00
Dr Maxim Orlovsky 0235abfac2
Improving PSBT merge with dedicated 1.29 rustc borrow scope 2020-12-15 15:50:18 +01:00
Dr Maxim Orlovsky df8635c5fe
PSBT: Key pair serialization for new global keys
Conflicts:
	src/util/psbt/map/global.rs
2020-12-15 15:50:18 +01:00
Dr Maxim Orlovsky 2f838218a8
PSBT: merging new global keys
Plus necessary changes to BIP 32 implementations and error type
2020-12-15 15:47:37 +01:00
Dr Maxim Orlovsky af61d7e7bc
PSBT: adding global types (version, xpub) 2020-12-15 15:47:37 +01:00
Steven Roose 6df16b7ce2
Merge pull request #530 from LNP-BP/psbt/constants
PSBT types are now constants
2020-12-15 14:45:52 +00:00
Steven Roose 874ab8eca6
Make signed message prefix a public constant 2020-12-08 17:31:28 +00:00
Dr Maxim Orlovsky 881f4d75dd
PSBT: Making hash preimage constant names match BIP 174 2020-12-07 16:35:28 +01:00
Dr Maxim Orlovsky 214e10baef
PSBT types are now constants 2020-12-07 15:37:16 +01:00
Steven Roose b4c8e12f36
Merge pull request #259 from stevenroose/taproot
Tagged hashes for taproot
2020-12-07 11:34:37 +00:00
Steven Roose f0ee94f2b2
Merge pull request #513 from LNP-BP/psbt/standard-names
PSBT: making input and output field names match spec type names
2020-12-07 11:34:06 +00:00
Dr Maxim Orlovsky 27037e2c72
PSBT: Making RIPEMD160 hash match standard name 2020-12-05 15:46:30 +01:00
Dr Maxim Orlovsky 9b106ee161
PSBT: making BIP32 field name match spec type names 2020-12-05 15:45:20 +01:00
Steven Roose a56712befc
Create tagged taproot hashes 2020-11-30 20:13:11 +00:00
Steven Roose ee192eb61d
Merge pull request #470 from LNP-BP/feat/bip32-bin
BIP 32 binary encoding functions are extracted from base58
2020-11-23 21:33:54 +00:00
Elichai Turkel 7c05673b86
Merge pull request #487 from RCasatta/map_with_u128
use u128 in map_to_range
2020-11-15 15:42:00 +02:00
Dr Maxim Orlovsky fa4ecb4a6a
Making ExtendedPubKey decode aligned with ExtendedPrivKey variant 2020-11-10 09:30:33 +01:00
Dr Maxim Orlovsky a802ca88ef
Using base58::check_encode_slice_to_fmt for BIP32 encodings 2020-11-08 18:29:30 +01:00
Dr Maxim Orlovsky d802872310
Improvements to extended keys encoding logic end errors 2020-11-08 13:03:32 +01:00
Dr Maxim Orlovsky 259259eabf
BIP 32 binary encoding functions are extracted from base58 2020-11-08 13:03:32 +01:00
Dr Maxim Orlovsky b5f0e9e144
Fixing serde impl for PSBT inputs 2020-11-06 17:01:34 +01:00
Andrew Poelstra d3210b39fb
Merge pull request #507 from stevenroose/pubkey-write-result
Change PublicKey::write_into to return Result
2020-11-05 19:21:39 +00:00
Andrew Poelstra 35d729d9f0
Merge pull request #478 from sanket1729/psbt_again
Psbt hash preimages (again)
2020-11-05 17:49:58 +00:00
Andrew Poelstra 8295885e8e
Merge pull request #454 from jrawsthorne/improved-bip158-types
Implement new FilterHeader type to differentiate from FilterHash
2020-11-05 16:46:50 +00:00
Andrew Poelstra 93df7cbd3e
Merge pull request #291 from kallewoof/2019-07-signet
add signet support
2020-10-26 19:46:10 +00:00
Steven Roose 9699c622fc
Return Result<(), io::Error> from PublicKey::write_into 2020-10-23 21:31:12 +01:00
Steven Roose 90e1125eff
Remove debug_assert in PublicKey::write_into 2020-10-23 21:28:46 +01:00
Steven Roose cc095a4ba7
Remove assert in Uint256::from_i64 and return None instead 2020-10-23 21:28:15 +01:00
Steven Roose 5c04a059d5
Change some static assertions to debug_assert 2020-10-23 21:28:13 +01:00
Andrew Poelstra e7980ac8a5
Merge pull request #413 from stevenroose/message-signature
Add MessageSignature type for dealing with signed messages
2020-10-14 16:30:15 +00:00
Steven Roose 3f65fb1aed
Don't support signed messages with p2wpkh addresses 2020-10-14 16:54:58 +02:00
Dr Maxim Orlovsky 00c3466363
Serde implementation for PSBT 2020-10-14 16:31:24 +02:00
sanket1729 57b63d4b52 Add tests for psbt hash serde 2020-10-11 21:51:03 -05:00
sanket1729 48151ef204 Added Hash preimages to psbt
Added hash preimages to psbt as per updated bip174
2020-10-11 21:51:02 -05:00
Steven Roose f7422fb8d1
Add MessageSignature type for dealing with signed messages 2020-10-11 22:44:00 +02:00
Alexis Sellier 210ff9edc7
Derive useful traits on `BlockFilter` 2020-10-11 22:31:32 +02:00
Jake Rawsthorne eeb14c4b08 Implement new FilterHeader type to differentiate from FilterHash 2020-10-10 20:38:10 +01:00
Steven Roose e60bfe2f61
Revert the sighash method signatures
Hash engines don't product I/O errors, so encoding into them
shouldn't produce errors either.
2020-10-09 16:27:38 +02:00
Andrew Poelstra 3618d7a41d
Merge pull request #485 from ipaljak-tbtl/expose-tx-signature-data
Expose serialized data for transaction signatures
2020-10-09 13:24:51 +00:00
Ivan Paljak e66caab956 Improve error handling, fix forgotten early return 2020-10-08 16:40:30 +02:00
Elichai Turkel eda47c31c9
Remove redundant code / configurations 2020-10-08 17:11:18 +03:00
Elichai Turkel 2d70623356
Remove deprecated Error::description impl 2020-10-08 17:11:18 +03:00
Elichai Turkel 023fae1f65
Add the dyn keyword where appropriate 2020-10-08 17:11:16 +03:00
Elichai Turkel efe1a55819
Use new inclusive range syntax 2020-10-08 17:08:51 +03:00
Elichai Turkel ad0064db14
Remove hex as a dev-dependency 2020-10-08 17:08:48 +03:00
Andrew Poelstra 7c47c9a341
Merge pull request #356 from elichai/2019-12-macros
Simplifying macros
2020-10-08 14:05:23 +00:00
Elichai Turkel fdd6f4f196
Derive macros instead of implementing via macro_rules 2020-10-08 16:17:14 +03:00
Riccardo Casatta 8ac3af68a4
use u128 in map_to_range 2020-10-08 08:57:59 +02:00
Ivan Paljak c21dabb824 Expose serialized data for transaction signatures 2020-10-08 01:21:10 +02:00
Andrew Poelstra 8c82129442
Merge pull request #480 from LNP-BP/feat/keysource
Introducing `bip32::KeySource`: wrapper for `(Fingerprint, DerivationPath)`
2020-10-07 22:23:39 +00:00
Andrew Poelstra 3748e8faf5
Merge pull request #459 from sgeisler/2020-08-extend-derivation-path
Allow easy concatenation of bip32 derivation paths
2020-10-07 21:34:17 +00:00
Steven Roose d92ca87c69
Merge pull request #488 from sgeisler/2020-10-bip32-doc-fix
Bip32 documentation fix
2020-10-07 21:15:14 +02:00
Sebastian Geisler b8c7bc8dcb Bip32 documentation fix 2020-10-07 16:50:27 +02:00
Karl-Johan Alm a3d9899cb1
add signet support 2020-09-18 16:32:33 +09:00
Dr Maxim Orlovsky c098dfa7f2 BIP32 KeySource refactored to type aliace 2020-09-14 00:37:29 +02:00
Dr Maxim Orlovsky aa67f10162 Introducing `bip32::KeySource`: wrapper for `(Fingerprint, DerivationPath)` 2020-09-13 22:49:52 +02:00
Dr Maxim Orlovsky ff1b4a8dbd WPubkeyHash constructor failing on uncompressed PublicKey 2020-09-11 15:43:05 +02:00
Dr Maxim Orlovsky 1d9f531581 Pubkey hash functions (normal and witness) 2020-09-11 15:04:26 +02:00
Andrew Poelstra c94295c3a9
Revert "Added hash Preimages to psbt" 2020-09-11 11:31:10 +00:00
Andrew Poelstra 3f33bd74e4
Merge pull request #465 from sanket1729/psbt_updates
Added hash Preimages to psbt
2020-09-11 11:30:27 +00:00
Andrew Poelstra 49e97cca65
Merge pull request #387 from pandoracore/builder-p2wildcard
Refactoring script generating functions into a single place
2020-09-11 11:29:09 +00:00
sanket1729 c1eafff9ef Added Sighash calculation for psbt 2020-09-11 01:01:33 -05:00
Andrew Poelstra 05f3451b10 un-deperate contracthash during testing
Avoids a rust test runner bug, see https://github.com/rust-lang/rust/issues/47238
2020-09-10 16:40:31 +00:00
Andrew Poelstra 4e737f708a
Merge pull request #461 from TheBlueMatt/2020-08-mut-sighash
Expose the witnesses of the tx being hashed in SigHashCache
2020-09-10 13:04:51 +00:00
Dr Maxim Orlovsky 38a412c4d5 Fixing review comments for script generators refactoring 2020-09-10 14:44:44 +02:00
Dr Maxim Orlovsky 9143fd3888 All script generation functionality moved to standalone methods in Script 2020-09-10 12:09:04 +02:00
Sebastian Geisler 202a946fc3 Allow easy concatenation of bip32 derivation paths
Currently one has to convert the path into a Vec<ChildNumber>, extend it and finally convert it back again.
2020-09-09 21:42:27 +02:00
sanket1729 e97dda0ffe Add tests for psbt serde 2020-09-09 12:53:09 -05:00
Andrew Poelstra addb54ffc7
Merge pull request #458 from braydonf/version
Transaction and header version is signed int
2020-09-09 17:06:31 +00:00
Andrew Poelstra 5fd91ca2d8
Merge pull request #451 from stevenroose/deprecate-contracthash
Deprecate the util::contracthash module
2020-09-09 17:02:19 +00:00
Andrew Poelstra c8633b5bce
Merge pull request #436 from LNP-BP/feat-u256u8
Big integers (Uint*) from byte slice array with `from_be_bytes`
2020-09-09 16:42:32 +00:00
Andrew Poelstra 45da3add10
Merge pull request #428 from stevenroose/no-witness-uncompressed
Don't allow uncompressed pks in witness addresses
2020-09-09 16:37:06 +00:00
Elichai Turkel a44ba2d878
Merge pull request #397 from stevenroose/script-iter
Improve the Instructions iterator for scripts
2020-09-09 19:06:05 +03:00
Dr. Maxim Orlovsky 42bf893d8b
Update big int from_be_bytes with iterators
Co-authored-by: Sebastian <geisler.sebastian@googlemail.com>
2020-09-03 16:42:00 +02:00
sanket1729 c5204c001f Added Hash Preimages to psbt
Added hash preimages to psbt as per updated bip174
2020-08-31 17:22:40 -05:00
Matt Corallo 3d80a0c962 Expose the witnesses of the tx being hashed in SigHashCache
See docuemntation of the new method for more, but this allows
certain use patterns which were broken with the introduction of
SigHashCache.
2020-08-26 11:18:14 -04:00
Braydon Fuller e9f1f11c2c
Transaction and header version is signed int 2020-08-17 10:28:51 -07:00
Dr Maxim Orlovsky 2fd353d5ab Big integers (Uint*) from byte slice array with `from_be_bytes` 2020-08-09 18:00:00 +02:00
Elichai Turkel e8bcde4d38
Merge pull request #403 from LNP-BP/fix-macro-ns
Hygiene/single code style for all existing macros
2020-08-09 18:16:36 +03:00
Steven Roose c03d2d59c6
Merge pull request #445 from elichai/2020-07-divmod
Use the remainder from div_rem instead of recomputing it
2020-08-09 16:59:39 +02:00
Roman Zeyde 0a25d87f2e Remove empty code block 2020-08-07 14:48:46 +02:00
Steven Roose 1ffdce99ed
Deprecate the util::contracthash module 2020-08-06 12:24:08 +02:00
Elichai Turkel 478e091af6
Merge pull request #443 from sgeisler/2020-06-bip32-derive-more
Derive more traits to use for bip32 Types
2020-07-23 11:24:50 +03:00
Elichai Turkel c20d356d7e
Use the remainder from div_rem instead of recomputing it 2020-07-22 12:39:32 +03:00
Dr Maxim Orlovsky 257ca8e504 Using :: for std namespaces in macro 2020-07-21 22:28:05 +02:00
Dr Maxim Orlovsky f6aa8853a0 Namespace hygiene for macros.rs 2020-07-21 22:28:05 +02:00
Dr Maxim Orlovsky 3a5e8d8504 Namespace hygiene for internal macros 2020-07-21 22:25:59 +02:00
Dr Maxim Orlovsky 7588b211ff Adding Rem op (%) to Uint128 & Uint256 types 2020-07-21 14:37:21 +02:00
Sebastian Geisler a3bb03eeb9 Derive more traits to use DerivationPath in rust-miniscript 2020-07-20 16:52:18 +02:00
Elichai Turkel f4e26caa94
Merge pull request #415 from shesek/merkleblock-txids
Allow to construct MerkleBlock using the header and txids
2020-05-24 16:32:17 +03:00
Steven Roose ed9bf41ff5
Don't allow uncompressed pks in witness addresses 2020-05-23 23:20:46 +01:00
Steven Roose 59b5a73a55
Fix typo and minor formatting in address::Error 2020-05-23 23:20:19 +01:00
Andrew Poelstra 7efde3ae47
Merge pull request #419 from elichai/2020-03-description
Deprecate Error::description
2020-05-23 17:26:38 +00:00
Elichai Turkel af31017eb1
Remove the cursor overhead, write is implemented on vec these days 2020-05-19 12:57:39 +03:00
Elichai Turkel 654232a3dc
Deprecate Error::description 2020-04-13 02:15:28 +03:00
Elichai Turkel 25cb3d3539
Remove alloc when hashing for Bitcoin message signing format 2020-04-12 19:04:13 +03:00
Steven Roose fea09a0a94
Improve the Instructions iterator for scripts
- Rename the `iter` method to `instructions`.
- Add `instructions_minimal` for minimal-enforced iteration.
- Iterator has `Result<Instruction, Error>` as items.
2020-04-11 23:52:26 +01:00
Elichai Turkel 2cc88a99aa
Removed PartialEq,PartialOrd impls, shouldn't be manually impl when Hash is derived 2020-03-29 17:15:15 +03:00
Elichai Turkel a473d01b17
Made some idiomatic changes 2020-03-29 17:15:15 +03:00
Elichai Turkel 3f2d428706
Remove needless references 2020-03-29 17:15:14 +03:00
Elichai Turkel 16eb81e1f7
Replaced slow vec initialization, and dual calls to hashmap 2020-03-29 17:10:27 +03:00
Nadav Ivgi 65efc5cd37 Allow to construct MerkleBlock using the header and txids
Co-Authored-By: Elichai Turkel <elichai.turkel@gmail.com>
2020-03-21 18:23:08 +02:00
Steven Roose 6186ee6269
Change Amount Debug impl to BTC with 8 decimals 2020-03-07 19:52:16 +00:00
Elichai Turkel 07b30c7fac
Mutation testing: amount: Added tests to fix mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel ab6e20c87e
Fix an overflow bug in SignedAmount to_string/fmt 2020-02-23 15:59:26 +02:00
Elichai Turkel abc70781e7
Fix a logic problem in base58 (isn't a real bug) 2020-02-23 15:59:26 +02:00
Elichai Turkel 1d01262d5c
Mutation testing: base58: Added tests to "fix" mutation misses 2020-02-23 15:59:26 +02:00
Andrew Poelstra a2bfcb5a89
Merge pull request #395 from pandoracore/fix-construct_uint
Improving `construct_uint` macro
2020-01-24 19:39:32 +00:00
Andrew Poelstra 659f2edb3b
Merge pull request #381 from elichai/2020-01-hex
Remove the hex dependency
2020-01-24 19:14:20 +00:00
Steven Roose 930a6ca1dc
Merge pull request #390 from instagibbs/bip143_sighash_notall
Add bip143 sighash support for other flags
2020-01-21 23:26:17 +00:00
Gregory Sanders d1c5c7b08d Deprecate SigHashComponents 2020-01-21 09:50:41 -05:00
Gregory Sanders 908aff50bc Add bip143 sighash support for other flags 2020-01-21 09:50:41 -05:00
Dr Maxim Orlovsky f3e762b555 Improving `construct_uint` macro 2020-01-21 13:16:34 +01:00
Elichai Turkel c19b736566
Remove the hex dependency 2020-01-20 18:50:02 +02:00
Steven Roose 8e52b8ce4d
Remove the BitcoinHash trait
Replaced by a `block_hash` method on both `Block` and `BlockHeader`.
2020-01-10 11:34:16 +00:00
Dr Maxim Orlovsky 5fc24dea33 Multiple fixes for hash types and their computing
Unit test for wtxid and SegWit transactions
2020-01-01 13:54:23 +01:00
Dr Maxim Orlovsky 0abe15b1f6 Moving from BitcoinHash to Wtxid for Transactions 2020-01-01 13:52:20 +01:00
Dr Maxim Orlovsky f5a8087105 New hash types: MerkleRoot/Branch, WitnessCommit, SigHash, FilterHash 2020-01-01 13:50:17 +01:00
Dr Maxim Orlovsky d20ab1dbc4 Switching to XpubIdentifier 2020-01-01 13:46:44 +01:00
Dr Maxim Orlovsky 5f4f629bb1 Replaced all hash160, sha256 and sha256d with the new hash types throughout the code
Embedding Txid's in the doc exaples
2020-01-01 13:44:34 +01:00
Dr Maxim Orlovsky 5ef39e34fa Implementing (W)Pubkey/ScriptHash and BlockHash 2020-01-01 13:42:22 +01:00
Dr Maxim Orlovsky ec92a05682 New HashTypes defined according to #284 (WIP), Txid is completed 2020-01-01 13:41:42 +01:00
Steven Roose 5f4555bfac
Remove util::misc::hex_bytes in favor of bitcoin_hashes::hex 2019-12-09 14:19:09 +00:00
Steven Roose 0469453da6
Use psbt::Error in PartiallySignedTransaction::from_unsigned_tx 2019-12-09 14:19:07 +00:00