Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
The dependency switch does not automatically opt types into `DecodeUntrusted`.
- **Breaking:** `dashcore_hashes` re-exports the hash primitives (`sha1`,
`sha256`, `sha256d`, `sha512`, `sha512_256`, `ripemd160`, `hash160`, `hmac`,
`siphash24`, `cmp`, `hex`) from `bitcoin_hashes` 0.14. The raw types no longer
implement bincode or accept byte and sequence forms in serde, `Error` is
`FromSliceError`, and `forward_hex`, `backward_hex` and the `schemars` feature
are removed
`siphash24`, `cmp`) from `bitcoin_hashes` 0.14. The raw types no longer
implement bincode or accept byte and sequence forms in serde, and `Error` is
`FromSliceError`
- **Breaking:** hex goes through `hex-conservative` 1.x, so `HexToArrayError`
and `HexToBytesError` become `DecodeFixedLengthBytesError` and
`DecodeVariableLengthBytesError` wherever `from_hex`, `FromStr` or a hex
error variant carried them. The raw hash types still report the 0.2 errors,
found under `dashcore_hashes::bitcoin_hashes::hex`
- **Breaking:** `BlsPkBytes::from_hex` and `BlsSigBytes::from_hex` report
`DecodeFixedLengthBytesError` instead of `hex::FromHexError`, and
`dashcore_rpc_json::HexError` wraps `DecodeVariableLengthBytesError`
- **Breaking:** hashes honour the format precision, so `{:.8}` prints 8 digits
- **Breaking:** `hash_x11::Hash` loses `forward_hex`, `backward_hex`,
`from_bytes_ref` and `from_bytes_mut`, `hash_x11::Midstate` is replaced by
`[u8; 32]`, and `n_bytes_hashed()` returns the bytes written
- **Breaking:** `hash_x11::Midstate` is replaced by `[u8; 32]`, and
`hash_x11::HashEngine::n_bytes_hashed()` returns the bytes written
- **Breaking:** `EcdsaSighashType` comes from `bitcoin-crypto` and gains a
`NonStandard` variant, which `from_consensus` returns for non-standard flags
and which displays, parses and serializes as `0xNN`. The `from_standard` error
Expand Down Expand Up @@ -54,12 +57,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
single when checking for the legacy `SIGHASH_SINGLE` bug
- `transaction_sighash` in `key-wallet-ffi` hashes non-standard flags as given
and rejects flags above `0xff`
- Reject 256-bit child numbers in `key-wallet` with an odd number of hex digits

### Removed

- **Breaking:** remove BIP38 from `key-wallet` (the `bip38` feature, `Bip38EncryptedKey`,
`Bip38Mode`, `encrypt_private_key`, `generate_intermediate_code` and the `Wallet` BIP38
export/import methods) and the unimplemented `bip38_*` functions from `key-wallet-ffi`
- **Breaking:** remove the `hex` re-export from `dashcore_hashes`. Depend on
`hex-conservative` 1.x directly, where `decode_to_array` and `decode_to_vec`
replace `FromHex`
- **Breaking:** remove `forward_hex` and `backward_hex` from the hash types,
and the `schemars` feature from `dashcore_hashes`
- **Breaking:** remove `from_bytes_ref` and `from_bytes_mut` from
`hash_x11::Hash`
- **Breaking:** remove the `hex` module from `dashcore-private`, and the
`btreemap_byte_values`, `btreemap_as_seq`, `btreemap_as_seq_byte_values` and
`hex_bytes` serde helpers from `dashcore::serde_utils`

## 0.44.0 - 2026-07-01

Expand Down
47 changes: 37 additions & 10 deletions crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
use core::str::FromStr;
use core::{fmt, iter};

use hashes::hex::{self, FromHex};
use internals::hex::display::DisplayHex;
use hex_conservative::DisplayHex;
use internals::write_err;
use secp256k1;
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -85,16 +84,16 @@ impl Signature {

impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::LowerHex::fmt(&self.sig.serialize_der().as_hex(), f)?;
fmt::LowerHex::fmt(&[self.hash_ty.to_consensus_u8()].as_hex(), f)
write!(f, "{:x}", self.sig.serialize_der().as_hex())?;
write!(f, "{:x}", [self.hash_ty.to_consensus_u8()].as_hex())
}
}

impl FromStr for Signature {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let bytes = Vec::from_hex(s)?;
let bytes = hex_conservative::decode_to_vec(s)?;
let (sighash_byte, signature) = bytes.split_last().ok_or(Error::EmptySignature)?;
Ok(Signature {
sig: secp256k1::ecdsa::Signature::from_der(signature)?,
Expand Down Expand Up @@ -186,14 +185,14 @@ impl fmt::Display for SerializedSignature {
impl fmt::LowerHex for SerializedSignature {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(&(**self).as_hex(), f)
write!(f, "{:x}", (**self).as_hex())
}
}

impl fmt::UpperHex for SerializedSignature {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::UpperHex::fmt(&(**self).as_hex(), f)
write!(f, "{:X}", (**self).as_hex())
}
}

Expand Down Expand Up @@ -227,7 +226,7 @@ impl<'a> IntoIterator for &'a SerializedSignature {
#[non_exhaustive]
pub enum Error {
/// Hex encoding error
HexEncoding(hex::HexToBytesError),
HexEncoding(hex_conservative::DecodeVariableLengthBytesError),
/// Non-standard sighash type
NonStandardSighashType(u32),
/// Empty Signature
Expand Down Expand Up @@ -267,8 +266,36 @@ impl From<secp256k1::Error> for Error {
}
}

impl From<hex::HexToBytesError> for Error {
fn from(err: hex::HexToBytesError) -> Self {
impl From<hex_conservative::DecodeVariableLengthBytesError> for Error {
fn from(err: hex_conservative::DecodeVariableLengthBytesError) -> Self {
Error::HexEncoding(err)
}
}

#[cfg(test)]
mod tests {
use super::*;

// A DER signature with `SIGHASH_ALL` appended.
const SIG_HEX: &str = "3045022100e85425f6d7c589972ee061413bcf08dc8c8e589ce37b217535a42af924f0e4d602205c9ba9cb14ef15513c9d946fa1c4b797883e748e8c32171bdf6166583946e35c01";

/// Formatting flags are ignored, as `hex-conservative` 1.x would otherwise
/// pad and prefix each part of the signature separately.
#[test]
fn display_ignores_format_flags() {
let sig = Signature::from_str(SIG_HEX).unwrap();
for out in [
format!("{}", sig),
format!("{:#}", sig),
format!("{:>200}", sig),
format!("{:.4}", sig),
] {
assert_eq!(out, SIG_HEX);
}

let serialized = sig.serialize();
assert_eq!(format!("{:x}", serialized), SIG_HEX);
assert_eq!(format!("{:#x}", serialized), SIG_HEX);
assert_eq!(format!("{:X}", serialized), SIG_HEX.to_uppercase());
}
}
29 changes: 11 additions & 18 deletions crypto/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use core::str::FromStr;
use std::io;

use dash_network::Network;
use hashes::hex::FromHex;
use hashes::{hash160, hash_newtype, hex, Hash as _};
use hashes::{hash160, hash_newtype, Hash as _};
use hex_conservative::DisplayHex;
use internals::write_err;
pub use secp256k1::{self, constants, Keypair, Parity, Secp256k1, Verification, XOnlyPublicKey};
#[cfg(feature = "serde")]
Expand All @@ -40,7 +40,7 @@ pub enum Error {
/// The base58 decoded correctly but the payload was the wrong length.
InvalidBase58PayloadLength(usize),
/// Hex decoding error
Hex(hex::HexToArrayError),
Hex(hex_conservative::DecodeFixedLengthBytesError),
/// `PublicKey` hex should be 66 or 130 digits long.
InvalidHexLength(usize),
/// Something is not supported based on active features
Expand Down Expand Up @@ -102,8 +102,8 @@ impl From<secp256k1::Error> for Error {
}

#[doc(hidden)]
impl From<hex::HexToArrayError> for Error {
fn from(e: hex::HexToArrayError) -> Self {
impl From<hex_conservative::DecodeFixedLengthBytesError> for Error {
fn from(e: hex_conservative::DecodeFixedLengthBytesError) -> Self {
Error::Hex(e)
}
}
Expand Down Expand Up @@ -312,22 +312,16 @@ pub struct SortKey(u8, [u8; 32], [u8; 32]);

impl fmt::Display for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO: fast hex encoding
self.with_serialized(|bytes| {
for ch in bytes {
write!(f, "{:02x}", ch)?;
}
Ok(())
})
self.with_serialized(|bytes| write!(f, "{:x}", bytes.as_hex()))
}
}

impl FromStr for PublicKey {
type Err = Error;
fn from_str(s: &str) -> Result<PublicKey, Error> {
match s.len() {
66 => PublicKey::from_slice(&<[u8; 33]>::from_hex(s)?),
130 => PublicKey::from_slice(&<[u8; 65]>::from_hex(s)?),
66 => PublicKey::from_slice(&hex_conservative::decode_to_array::<33>(s)?),
130 => PublicKey::from_slice(&hex_conservative::decode_to_array::<65>(s)?),
len => Err(Error::InvalidHexLength(len)),
}
}
Expand Down Expand Up @@ -699,7 +693,6 @@ impl From<TweakedKeyPair> for TweakedPublicKey {

#[cfg(test)]
mod tests {
use hashes::hex::FromHex;

use super::*;

Expand All @@ -715,19 +708,19 @@ mod tests {
};
let expected1 = SortKey(
2,
<[u8; 32]>::from_hex(
hex_conservative::decode_to_array::<32>(
"ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8",
)
.unwrap(),
[0_u8; 32],
);
let expected2 = SortKey(
4,
<[u8; 32]>::from_hex(
hex_conservative::decode_to_array::<32>(
"ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8",
)
.unwrap(),
<[u8; 32]>::from_hex(
hex_conservative::decode_to_array::<32>(
"1794e7f3d5e420641a3bc690067df5541470c966cbca8c694bf39aa16d836918",
)
.unwrap(),
Expand Down
8 changes: 3 additions & 5 deletions dash-spv-ffi/src/bin/ffi_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ extern "C" fn on_transaction_broadcast_result(
relayed_by: u32,
_user_data: *mut c_void,
) {
let txid_hex = unsafe { &*txid }.iter().rev().fold(String::new(), |mut acc, b| {
use std::fmt::Write;
let _ = write!(acc, "{:02x}", b);
acc
});
let mut txid_bytes = unsafe { *txid };
txid_bytes.reverse();
let txid_hex = txid_bytes.to_lower_hex_string();
match status {
FFIBroadcastStatus::Accepted => {
println!("[Broadcast] {} accepted ({} peer(s) relayed it back)", txid_hex, relayed_by)
Expand Down
9 changes: 4 additions & 5 deletions dash/benches/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use dashcore::blockdata::transaction::Transaction;
use dashcore::consensus::{Encodable, deserialize};
use dashcore::hashes::hex::FromHex;
use std::io::Write;

const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
Expand All @@ -20,7 +19,7 @@ impl Write for EmptyWrite {
}

fn bench_transaction_size(c: &mut Criterion) {
let raw_tx = Vec::from_hex(SOME_TX).unwrap();
let raw_tx = hex_conservative::decode_to_vec(SOME_TX).unwrap();
let mut tx: Transaction = deserialize(&raw_tx).unwrap();

c.bench_function("transaction_size", |b| {
Expand All @@ -31,7 +30,7 @@ fn bench_transaction_size(c: &mut Criterion) {
}

fn bench_transaction_serialize(c: &mut Criterion) {
let raw_tx = Vec::from_hex(SOME_TX).unwrap();
let raw_tx = hex_conservative::decode_to_vec(SOME_TX).unwrap();
let tx: Transaction = deserialize(&raw_tx).unwrap();

c.bench_function("transaction_serialize", |b| {
Expand All @@ -45,7 +44,7 @@ fn bench_transaction_serialize(c: &mut Criterion) {
}

fn bench_transaction_serialize_logic(c: &mut Criterion) {
let raw_tx = Vec::from_hex(SOME_TX).unwrap();
let raw_tx = hex_conservative::decode_to_vec(SOME_TX).unwrap();
let tx: Transaction = deserialize(&raw_tx).unwrap();

c.bench_function("transaction_serialize_logic", |b| {
Expand All @@ -57,7 +56,7 @@ fn bench_transaction_serialize_logic(c: &mut Criterion) {
}

fn bench_transaction_deserialize(c: &mut Criterion) {
let raw_tx = Vec::from_hex(SOME_TX).unwrap();
let raw_tx = hex_conservative::decode_to_vec(SOME_TX).unwrap();

c.bench_function("transaction_deserialize", |b| {
b.iter(|| {
Expand Down
5 changes: 2 additions & 3 deletions dash/src/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ impl BlockTransactions {

#[cfg(test)]
mod test {
use hashes::hex::FromHex;

use super::*;
use crate::blockdata::locktime::absolute;
Expand Down Expand Up @@ -442,8 +441,8 @@ mod test {
#[test]
fn test_compact_block_vector() {
// Tested with Elements implementation of compact blocks.
let raw_block = Vec::<u8>::from_hex("000000206c750a364035aefd5f81508a08769975116d9195312ee4520dceac39e1fdc62c4dc67473b8e354358c1e610afeaff7410858bd45df43e2940f8a62bd3d5e3ac943c2975cffff7f200000000002020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04016b0101ffffffff020006062a0100000001510000000000000000266a24aa21a9ed4a3d9f3343dafcc0d6f6d4310f2ee5ce273ed34edca6c75db3a73e7f368734200120000000000000000000000000000000000000000000000000000000000000000000000000020000000001021fc20ba2bd745507b8e00679e3b362558f9457db374ca28ffa5243f4c23a4d5f00000000171600147c9dea14ffbcaec4b575e03f05ceb7a81cd3fcbffdffffff915d689be87b43337f42e26033df59807b768223368f189a023d0242d837768900000000171600147c9dea14ffbcaec4b575e03f05ceb7a81cd3fcbffdffffff0200cdf5050000000017a9146803c72d9154a6a20f404bed6d3dcee07986235a8700e1f5050000000017a9144e6a4c7cb5b5562904843bdf816342f4db9f5797870247304402205e9bf6e70eb0e4b495bf483fd8e6e02da64900f290ef8aaa64bb32600d973c450220670896f5d0e5f33473e5f399ab680cc1d25c2d2afd15abd722f04978f28be887012103e4e4d9312b2261af508b367d8ba9be4f01b61d6d6e78bec499845b4f410bcf2702473044022045ac80596a6ac9c8c572f94708709adaf106677221122e08daf8b9741a04f66a022003ccd52a3b78f8fd08058fc04fc0cffa5f4c196c84eae9e37e2a85babe731b57012103e4e4d9312b2261af508b367d8ba9be4f01b61d6d6e78bec499845b4f410bcf276a000000").unwrap();
let raw_compact = Vec::<u8>::from_hex("000000206c750a364035aefd5f81508a08769975116d9195312ee4520dceac39e1fdc62c4dc67473b8e354358c1e610afeaff7410858bd45df43e2940f8a62bd3d5e3ac943c2975cffff7f2000000000a4df3c3744da89fa010a6979e971450100020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04016b0101ffffffff020006062a0100000001510000000000000000266a24aa21a9ed4a3d9f3343dafcc0d6f6d4310f2ee5ce273ed34edca6c75db3a73e7f368734200120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
let raw_block = hex_conservative::decode_to_vec("000000206c750a364035aefd5f81508a08769975116d9195312ee4520dceac39e1fdc62c4dc67473b8e354358c1e610afeaff7410858bd45df43e2940f8a62bd3d5e3ac943c2975cffff7f200000000002020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04016b0101ffffffff020006062a0100000001510000000000000000266a24aa21a9ed4a3d9f3343dafcc0d6f6d4310f2ee5ce273ed34edca6c75db3a73e7f368734200120000000000000000000000000000000000000000000000000000000000000000000000000020000000001021fc20ba2bd745507b8e00679e3b362558f9457db374ca28ffa5243f4c23a4d5f00000000171600147c9dea14ffbcaec4b575e03f05ceb7a81cd3fcbffdffffff915d689be87b43337f42e26033df59807b768223368f189a023d0242d837768900000000171600147c9dea14ffbcaec4b575e03f05ceb7a81cd3fcbffdffffff0200cdf5050000000017a9146803c72d9154a6a20f404bed6d3dcee07986235a8700e1f5050000000017a9144e6a4c7cb5b5562904843bdf816342f4db9f5797870247304402205e9bf6e70eb0e4b495bf483fd8e6e02da64900f290ef8aaa64bb32600d973c450220670896f5d0e5f33473e5f399ab680cc1d25c2d2afd15abd722f04978f28be887012103e4e4d9312b2261af508b367d8ba9be4f01b61d6d6e78bec499845b4f410bcf2702473044022045ac80596a6ac9c8c572f94708709adaf106677221122e08daf8b9741a04f66a022003ccd52a3b78f8fd08058fc04fc0cffa5f4c196c84eae9e37e2a85babe731b57012103e4e4d9312b2261af508b367d8ba9be4f01b61d6d6e78bec499845b4f410bcf276a000000").unwrap();
let raw_compact = hex_conservative::decode_to_vec("000000206c750a364035aefd5f81508a08769975116d9195312ee4520dceac39e1fdc62c4dc67473b8e354358c1e610afeaff7410858bd45df43e2940f8a62bd3d5e3ac943c2975cffff7f2000000000a4df3c3744da89fa010a6979e971450100020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04016b0101ffffffff020006062a0100000001510000000000000000266a24aa21a9ed4a3d9f3343dafcc0d6f6d4310f2ee5ce273ed34edca6c75db3a73e7f368734200120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();

let block: Block = deserialize(&raw_block).unwrap();
let nonce = 18053200567810711460;
Expand Down
3 changes: 1 addition & 2 deletions dash/src/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ impl From<&Block> for BlockHash {

#[cfg(test)]
mod tests {
use hashes::hex::FromHex;

use super::*;
use crate::consensus::encode::{deserialize, serialize};
Expand All @@ -440,7 +439,7 @@ mod tests {
const BAD_HEX: &str = "0200000035ab154183570282ce9afc0b494c9fc6a3cfea05aa8c1add2ecc56490000000038ba3d78e4500a5a7570dbe61960398add4410d278b21cd9708e6d9743f374d544fc055227f1001c29c1ea3b0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3d09a08601112233445566000427f1001c046a510100522cfabe6d6d0000000000000000000068692066726f6d20706f6f6c7365727665726aac1eeeed88ffffffff0100f2052a010000001976a914912e2b234f941f30b18afbb4fa46171214bf66c888ac00000000";
let bad: Block = deserialize(&hex!(BAD_HEX)).unwrap();

let push = Vec::<u8>::from_hex("a08601112233445566").unwrap();
let push = hex_conservative::decode_to_vec("a08601112233445566").unwrap();
assert_eq!(bad.bip34_block_height(), Err(super::Bip34Error::UnexpectedPush(push)));
}

Expand Down
10 changes: 4 additions & 6 deletions dash/src/blockdata/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,6 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
{
use core::fmt::Formatter;

use hashes::hex::FromHex;

if deserializer.is_human_readable() {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
Expand All @@ -600,7 +598,7 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
where
E: serde::de::Error,
{
let v = Vec::from_hex(v).map_err(E::custom)?;
let v = hex_conservative::decode_to_vec(v).map_err(E::custom)?;
Ok(ScriptBuf::from(v))
}
}
Expand Down Expand Up @@ -727,9 +725,9 @@ pub fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn fmt::Write) -> fmt::Result {
if data_len > 0 {
f.write_str(" ")?;
if data_len <= iter.len() {
for ch in iter.by_ref().take(data_len) {
write!(f, "{:02x}", ch)?;
}
let (data, rest) = iter.as_slice().split_at(data_len);
write!(f, "{:x}", data.as_hex())?;
iter = rest.iter();
} else {
f.write_str("<push past end>")?;
break;
Expand Down
7 changes: 2 additions & 5 deletions dash/src/blockdata/script/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use core::ops::Deref;

#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
use hashes::hex;

use crate::address::{WitnessProgram, WitnessVersion};
use crate::blockdata::opcodes::all::*;
Expand Down Expand Up @@ -168,10 +167,8 @@ impl ScriptBuf {
}

/// Creates a [`ScriptBuf`] from a hex string.
pub fn from_hex(s: &str) -> Result<Self, hex::HexToBytesError> {
use hashes::hex::FromHex;

let v = Vec::from_hex(s)?;
pub fn from_hex(s: &str) -> Result<Self, hex_conservative::DecodeVariableLengthBytesError> {
let v = hex_conservative::decode_to_vec(s)?;
Ok(ScriptBuf::from_bytes(v))
}

Expand Down
Loading
Loading