Skip to content

Commit 70a1256

Browse files
authored
refactor!: pin existing serde layout, abstract EDDSA backend types behind newtypes, switch to dash-pkc, re-export some bitcoin-crypto ECDSA types (#1151)
* refactor: move `impl_bytes_newtype` to `internals` * refactor(crypto)!: re-export rust-bitcoin's ECDSA `Signature` types * refactor!: re-export rust-bitcoin's Taproot key types * build: bump base SDK packages to dashpay/base-sdk@d9e0d24, drop `codec` * refactor: serialize `impl_bytes_newtype!` types through `dash_types` * refactor(crypto): serialize `PublicKey` through `dash_types` * test(crypto): pin the serde layout of the ECDSA signature * test(key-wallet): pin the serde layout of the root extended keys * refactor!: serialize the pinned secp256k1 types through thin newtypes * refactor!: isolate the backend ECDSA public key type behind its newtype * refactor!: isolate the backend ECDSA secret key type behind its newtype * refactor!: isolate the backend ECDSA signature type behind its newtype * refactor!: isolate the backend ECDSA recoverable signature in a newtype * refactor(dash)!: replace `CompactSignature` with `EcdsaRecSignature` * refactor(dash)!: replace `MessageSignature` with `EcdsaRecSignature` * build!: drop `secp256k1` from `key-wallet{,-ffi}`, reap error variants * feat(crypto)!: switch ECDSA backend to `dash-pkc` * refactor(crypto)!: use `dash-pkc`'s `EcdsaError` directly * refactor(crypto): forward the ECDSA newtype methods with `delegate` * build!: drop the `secp256k1` dependency from `dashcore{,-crypto}` * docs: update changelog
1 parent 280b3f2 commit 70a1256

60 files changed

Lines changed: 1196 additions & 1393 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
99
### Added
1010

1111
- Make `PublicKey::with_serialized` public
12+
- `EcdsaPublicKey`, `EcdsaSecretKey`, `EcdsaSignature`, `EcdsaRecSignature`,
13+
`EcdsaError` and the `ECDSA_*_LEN` constants in `dashcore::ecdsa`
14+
- `EcdsaSecretKey::generate` with the `rand` feature
15+
- `TryFrom<&[u8]>` for `PublicKey`
1216

1317
### Changed
1418

@@ -41,6 +45,29 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
4145
- **Breaking:** the taproot types come from `bitcoin-crypto`. `Signature`
4246
fields are renamed to `signature` and `sighash_type`, and `taproot::Error` is
4347
`SigFromSliceError`, without a `Secp256k1` variant
48+
- **Breaking:** `ecdsa::Signature` and `ecdsa::SerializedSignature` come from
49+
`bitcoin-crypto`. `Signature` fields and human-readable serde keys are
50+
renamed from `sig` and `hash_ty` to `signature` and `sighash_type`.
51+
`signature` is a `secp256k1` signature.
52+
`DecodeError` and `ParseSignatureError` replace `ecdsa::Error`. Formatting
53+
flags apply to the whole encoding instead of being ignored
54+
- **Breaking:** the `dashcore::ecdsa` newtypes replace the `secp256k1` keys and
55+
signatures in `PublicKey`, `PrivateKey`, `ExtendedPrivKey`, `ExtendedPubKey`,
56+
`RootExtendedPrivKey`, `RootExtendedPubKey`, `Wallet` key derivation,
57+
`AssetLockCreditKeys` and `Signer`. `EcdsaPublicKey` converts into
58+
`XOnlyPublicKey` and `EcdsaSecretKey` into `Keypair`
59+
- **Breaking:** `key::XOnlyPublicKey`, `Keypair`, `Parity`, `TweakedPublicKey`
60+
and `UntweakedPublicKey` come from `bitcoin-crypto`, whose `XOnlyPublicKey`
61+
keeps its parity. `TweakedKeyPair` and `UntweakedKeyPair` are renamed to
62+
`TweakedKeypair` and `UntweakedKeypair`
63+
- **Breaking:** `TaprootError::InvalidInternalKey` and
64+
`TaprootBuilderError::InvalidInternalKey` no longer hold a `secp256k1::Error`
65+
- **Breaking:** `PrivateKey` is no longer `Copy`. `to_bytes` and `to_wif` take
66+
`&self` instead of `self`
67+
- **Breaking:** `Ecdsa(EcdsaError)` replaces `key::Error::Secp256k1` and
68+
`bip32::Error::Secp256k1`. `MessageSignatureError::InvalidEncoding` holds an
69+
`EcdsaError` instead of a `secp256k1::Error`. Failed verification reads
70+
"signature verification failed" instead of "signature failed verification"
4471
- **Breaking:** `dashcore::eddsa` uses the `dash-pkc` types, so `EddsaPkBytes`
4572
and `EddsaSkBytes` no longer implement `BaseCodec` and `EddsaError` changes
4673
shape. Use `EddsaPublicKey::try_from`, `EddsaPkHash::from` and
@@ -59,10 +86,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5986
- **Breaking:** `ExtendedPrivKey::new_master` rejects seeds outside 16 to 64
6087
bytes with `bip32::Error::InvalidSeedLength`, which
6188
`RootExtendedPrivKey::new_master` returns instead of `InvalidParameter`
62-
- **Breaking:** `MessageSignature::from_slice` rejects headers above 34
89+
- **Breaking:** `EcdsaRecSignature` rejects headers above 34 when read
6390
- Relicense `dash-network`, `dash-network-seeds`, `dash-spv`, `dash-spv-ffi`,
6491
`dash-spv-bench`, `git-state` and `masternode-seeds-fetcher` to CC0-1.0
6592
- All workspace crates declare a MSRV of 1.89
93+
- Human-readable serde of `PublicKey`, `ShortId` and `PlatformNodeId` also
94+
accepts raw bytes, and their deserialization errors read differently
95+
- `RootExtendedPubKey` now supports hybrid SEC1 public keys in human-readable
96+
serde, and writes them back compressed
6697

6798
### Fixed
6899

@@ -102,8 +133,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
102133
`Witness::push_bitcoin_signature`
103134
- **Breaking:** remove `key::Error::NotSupported`,
104135
`bip32::Error::NotSupported` and `dashcore_rpc::Error::Secp256k1`
105-
- **Breaking:** remove `signer::CompactSignature`. Use `MessageSignature`
136+
- **Breaking:** remove `signer::CompactSignature`. Use `EcdsaRecSignature`
106137
instead
138+
- **Breaking:** remove `bip32::PublicKey`, `bip32::PrivateKey`,
139+
`key_wallet::Error::Secp256k1` and `Index<RangeFull>` for `PrivateKey`
140+
- **Breaking:** remove the `secp256k1` re-exports from `dashcore` and
141+
`dashcore-crypto`, `key::Secp256k1`, `key::Verification` and
142+
`TaprootError::InvalidParity`
143+
- **Breaking:** remove the `secp-recovery` and `secp-lowmemory` features.
144+
Message signature recovery is always available
145+
- **Breaking:** remove `MessageSignature`. Signed messages are
146+
`EcdsaRecSignature`s, which carry the key compression, and the
147+
`sign_message` functions `from_slice`, `from_base64`, `to_base64`,
148+
`recover_pubkey` and `is_signed_by_address` replace its methods
107149

108150
### Fixed
109151

‎Cargo.toml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ bincode = { package = "grovedb-bincode", version = "=2.1.0" }
88
bincode_derive = { package = "grovedb-bincode-derive", version = "=2.1.0" }
99
futures = "0.3"
1010
rayon = "1.11"
11-
secp256k1 = "0.33.1" # must match with version used in `bitcoin-crypto` and `dash-pkc`
1211
serde = { version = "1.0.219", default-features = false }
1312
zeroize = { version = "1.8", features = ["derive"] }
1413

1514
# Packages from `dashpay/base-sdk`, MUST share same version ACROSS crates
16-
dash-num = { git = "https://github.com/dashpay/base-sdk", rev = "33fcc59e1868c803f9608e0e78ee8bddf3abcee7", default-features = false }
17-
dash-pkc = { git = "https://github.com/dashpay/base-sdk", rev = "33fcc59e1868c803f9608e0e78ee8bddf3abcee7", default-features = false }
18-
dash-types = { git = "https://github.com/dashpay/base-sdk", rev = "33fcc59e1868c803f9608e0e78ee8bddf3abcee7", default-features = false }
15+
dash-num = { git = "https://github.com/dashpay/base-sdk", rev = "d9e0d241e2e06edff455f88c9cb3b9ce0d8a8ac5", default-features = false }
16+
dash-pkc = { git = "https://github.com/dashpay/base-sdk", rev = "d9e0d241e2e06edff455f88c9cb3b9ce0d8a8ac5", default-features = false }
17+
dash-types = { git = "https://github.com/dashpay/base-sdk", rev = "d9e0d241e2e06edff455f88c9cb3b9ce0d8a8ac5", default-features = false }
1918

2019
# Packages from `rust-bitcoin/rust-bitcoin`, `bitcoin-crypto` uses revision due to `secp256k1`
2120
base58ck = { version = "0.5.0" }

‎crypto/Cargo.toml‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,31 @@ version.workspace = true
1414
default = []
1515

1616
bincode = ["dep:bincode", "dep:bincode_derive", "dashcore_hashes/bincode", "dash-network/bincode"]
17-
bls = ["dash-pkc/bls", "dep:tracing"]
17+
bls = ["dash-pkc/bls", "dash-pkc/portable", "dep:tracing"]
1818
eddsa = ["dash-pkc/eddsa"]
19-
serde = ["dep:serde", "bitcoin-crypto/serde", "dash-types/serde", "dashcore_hashes/serde", "dash-network/serde", "dash-pkc/serde", "secp256k1/serde"]
19+
rand = ["bitcoin-crypto/rand"]
20+
serde = ["dep:serde", "bitcoin-crypto/serde", "dash-types/serde", "dashcore_hashes/serde", "dash-network/serde", "dash-pkc/serde"]
2021

2122
[dependencies]
2223
base58ck = { workspace = true }
2324
bitcoin-crypto = { workspace = true, features = ["std", "hex"] }
2425
bincode = { workspace = true, optional = true }
2526
bincode_derive = { workspace = true, optional = true }
2627
dash-network = { path = "../dash-network" }
27-
dash-pkc = { workspace = true, features = ["std"] }
28-
dash-types = { workspace = true, features = ["codec"] }
28+
dash-pkc = { workspace = true, features = ["ecdsa", "std"] }
29+
dash-types = { workspace = true }
30+
delegate = "0.13"
2931
dashcore_hashes = { path = "../hashes" }
3032
hex-conservative = { workspace = true }
3133
internals = { path = "../internals", package = "dashcore-private" }
32-
secp256k1 = { workspace = true }
3334
serde = { workspace = true, features = ["derive", "alloc"], optional = true }
3435
thiserror = "2"
3536
tracing = { version = "0.1", optional = true }
37+
zeroize = { workspace = true }
3638

3739
[lints.rust]
3840
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(fuzzing)', 'cfg(kani)'] }
3941

4042
[dev-dependencies]
43+
bincode = { workspace = true, features = ["serde"] }
4144
serde_json = { version = "1.0" }

0 commit comments

Comments
 (0)