Commit Graph

33 Commits

Author SHA1 Message Date
Andrew Poelstra 0e82376bf8
Merge rust-bitcoin/rust-bitcoin#987: Implement `std::error::Error` for the new MSRV
97a5bb1439 Implement std::error::source codebase wide (Tobin C. Harding)
0a9191b429 Add parenthesis around left hand side of companion (Tobin C. Harding)
7cf8af2f86 Put Error impl block below Display (Tobin C. Harding)
2384712364 Re-order Display match arms (Tobin C. Harding)

Pull request description:

  Now that we have MSRV of 1.41.1 we should use `source` instead of `cause`. Audit the whole codebase and implement `source` for _every_ error type we have.

  The first three patches are preparatory cleanup, patch 3 is particularly shameful (adds parenthesis to make my editor work).

  CC @Kixunil because he is championing the error stuff.

ACKs for top commit:
  apoelstra:
    ACK 97a5bb1439

Tree-SHA512: 46313a28929445f32e01e30ca3b0246b30bc9d5e43db5754d4b441e9c30d3e427efaf247100eb6b452f98beec5a4fcde1daba7943a772114aa34f78ab52cbc60
2022-05-21 14:08:52 +00:00
Tobin C. Harding 97a5bb1439 Implement std::error::source codebase wide
Audit ever error type we have and implement `source` for each.
2022-05-19 16:35:11 +10:00
Tobin C. Harding 2384712364 Re-order Display match arms
Put the match arms in the same order as the enum that defines them.
2022-05-19 16:33:49 +10:00
Tobin Harding e6084a1af8 Improve documentation around EcdsaSig
Improve the rustdocs for serialization methods of the `EcdsaSig` type.
2022-05-19 14:05:34 +10:00
Tobin C. Harding dca0d67771 Fix in preparation for next edition
Use cargo to upgrade from edition 2015 to edition 2018.

 cargo fix --edition

No manual changes made. The result of the command above is just to fix
all the use statements (add `crate::`) and fix the fully qualified path
formats i.e., `::Foo` -> `crate::Foo`.
2022-05-11 10:16:17 +10:00
Tobin Harding c19ec339ef Rename NonStandardSigHashType -> NonStandardSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename the `NonStandardSigHashType` type and error variant to
`NonStandardSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding 5522454583 Rename EcdsaSigHashType -> EcdsaSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `EcdsaSigHashType` to `EcdsaSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding ac462897b1 Remove hungarian-ish notation
The functions `from_u32_standard` and `from_u32_consensus` smell a bit
like hungarian notation. We can look at the method definition to see
that the methods accept `u32` arguments without mentioning that in the
method names.

Remove `_u32_` from the method names. This brings the `from_*` methods
in line  with the `to_standard` method also.
2022-03-28 10:43:37 +11:00
sanket1729 abe52f681b Cleanup/Dedup psbt (De)Serialization code 2022-01-15 06:15:54 +05:30
sanket1729 fbd86dcf63 Update documentation of EcdsaSig::from_slice 2022-01-15 06:15:14 +05:30
Dr Maxim Orlovsky bcb8932ccf Re-org keys and ecdsa mods - pt.3 2022-01-14 01:35:48 +01:00
Dr Maxim Orlovsky d1c2213d3b Re-org keys and ecdsa mods - pt.2 2022-01-14 01:35:48 +01:00
Dr Maxim Orlovsky b9170162d5 Re-org keys and ecdsa mods - pt.1
This commit tries to achieve separation of signature- and key-related types, previously mixed in a single ECDSA module.

Rationale: bitcoin key types are not specific for signature algorithm.

This is achieved through
- Remove key mod with its content moved to ecdsa mod
- Re-export keys under key module in util mod - to make git generate diff for the rename of ecdsa mod in the next commit correctly.
2022-01-14 01:35:48 +01:00
Dr Maxim Orlovsky eb09019720 Rename inner key field in PrivateKey and PublicKey
Closes #532
2022-01-11 08:39:52 +01:00
sanket1729 476eed7f2f
Merge rust-bitcoin/rust-bitcoin#590: Taproot: BIP32 extended keys using Scep256k1 keys instead of bitcoin ECDSA
cf0c48cc86 Improve Debug for PrivateKey (Dr Maxim Orlovsky)
b65a6ae49b Test for extended private key keypair generation  f5875a (Dr Maxim Orlovsky)
e6a3d603c9 BIP32 extended key `to_ecdsa()` and `to_schnorr()` methods (Dr Maxim Orlovsky)
b72f56c4ae BIP32 extended keys are using Scep256k1 keys instead of bitcoin ECDSA (Dr Maxim Orlovsky)

Pull request description:

  This is third step required to introduce Schnorr key support according to #588. This PR starts API-breaking changes and is follow-up to non-API breaking #589, which is already merged.

  PR rationale: BIP32 does not support uncompressed keys and using type with compression flag was a mistake

ACKs for top commit:
  apoelstra:
    ACK cf0c48cc86
  sanket1729:
    ACK cf0c48cc86. #757 might need rework after this

Tree-SHA512: 6356a65004e7517256bacbf9aaeb69a22fd8536b341e567c5c4e819288e1105d083fe12ac0641404c407c97acf039bdc525f8e02b1b594a6cdda90106f3b1bdc
2022-01-10 03:46:05 +05:30
Dr Maxim Orlovsky cf0c48cc86 Improve Debug for PrivateKey 2022-01-09 07:17:10 +01:00
Dr Maxim Orlovsky 141dbbd1b9 Add serde impl for EcdsaSig 2022-01-07 21:57:42 +01:00
Dr Maxim Orlovsky 0af1c3f320 Add Display and FromStr for EcdsaSig 2022-01-07 21:57:11 +01:00
Dr Maxim Orlovsky c36a3da6f0 Add EcdsaSig::sighash_all convenience constructor 2022-01-07 21:49:05 +01:00
sanket1729 2178c7367c Update to secp256k1 0.21.2 2022-01-07 04:45:40 +05:30
Tobin Harding 533120899e Put rustdocs above attributes
Rust idiomatic style is to put the rustdoc _above_ any attributes on
types, functions, etc.

Audit the codebase and move comments/attributes to the correct place.
Add a trailing full stop at times to neaten things up a little extra.
2022-01-06 13:04:47 +11:00
Martin Habovstiak 779d4110c6 Fixed a bunch of clippy lints, added clippy.toml
This is the initial step towards using and maybe enforcing clippy.
It does not fix all lints as some are not applicable. They may be
explicitly ignored later.
2021-12-21 22:50:13 +01:00
sanket1729 94cfe79170 Rename existing SigHashType to EcdsaSigHashType 2021-12-15 20:00:52 +05:30
sanket1729 fa112a793a Add EcdsaSig 2021-12-15 20:00:51 +05:30
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
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
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
Sebastian b0ae2a6842
Merge pull request #521 from RCasatta/errors_enum
Errors enum improvements
2021-06-15 14:01:56 +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
Devrandom 95aa3bf153 std -> core 2021-06-11 17:28:04 +02:00
Dr Maxim Orlovsky 187eae8a13
Streamlining private key construction API in BIP32 2021-05-01 13:40:21 +02:00
Dr Maxim Orlovsky ceacc7d85f
Constructors for compressed and uncompressed ECDSA keys 2021-05-01 13:34:04 +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