Skip to content

Commit 4a963db

Browse files
committed
Merge #169: Rename Sighash type downcasing the middle h
0a97313 update CHANGELOG with Sighash renaming (Riccardo Casatta) bb7bddc SigHash -> Sighash (Riccardo Casatta) 468b787 SigHashType -> SighashType (Riccardo Casatta) 229be29 EcdsaSigHashType -> EcdsaSighashType (Riccardo Casatta) 43e36ff SchnorrSigHashType -> SchnorrSighashType (Riccardo Casatta) d78493e SigHashCache -> SighashCache (Riccardo Casatta) Pull request description: The same has been made in rust-bitcoin ACKs for top commit: apoelstra: ACK 0a97313 Tree-SHA512: df871a1ee4fbe23dd532ab3a9b3ca64092085508152916d505e894f9c315614afb4c546ac17665a2c7e9e128ea4068aca516b602159332ebbb9fc9e5d234dd49
2 parents ba4aad3 + 0a97313 commit 4a963db

12 files changed

Lines changed: 207 additions & 203 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
# 0.23.0 -
3+
4+
* rename all Sighash types downcasing the middle "h", for example: SigHash -> Sighash
5+
26
# 0.22.0 - 2023-06-08
37

48
* [https://github.com/ElementsProject/rust-elements/pull/159](Update `TapTweak`, and `schnorr` module generally, to match rust-bitcoin)

elementsd-tests/src/taproot.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use elements::encode::{deserialize, serialize_hex};
1313
use elements::hashes::Hash;
1414
use elements::script::Builder;
1515
use elements::secp256k1_zkp;
16-
use elements::sighash::{self, SigHashCache};
16+
use elements::sighash::{self, SighashCache};
1717
use elements::taproot::{LeafVersion, TapTweakHash, TaprootBuilder, TaprootSpendInfo, TapLeafHash};
1818
use elements::OutPoint;
1919
use elements::{
20-
confidential, opcodes, AssetIssuance, BlockHash, LockTime, SchnorrSig, SchnorrSigHashType, Script,
20+
confidential, opcodes, AssetIssuance, BlockHash, LockTime, SchnorrSig, SchnorrSighashType, Script,
2121
Sequence, TxInWitness, TxOut, Txid,
2222
};
2323
use elements::{AddressParams, Transaction, TxIn, TxOutSecrets};
@@ -144,7 +144,7 @@ fn taproot_spend_test(
144144
elementsd: &ElementsD,
145145
secp: &Secp256k1<secp256k1_zkp::All>,
146146
genesis_hash: BlockHash,
147-
sighash_ty: SchnorrSigHashType,
147+
sighash_ty: SchnorrSighashType,
148148
blind_prevout: bool,
149149
blind_tx: bool,
150150
key_spend: bool,
@@ -193,7 +193,7 @@ fn taproot_spend_test(
193193
.unwrap();
194194
}
195195

196-
let mut cache = SigHashCache::new(&tx);
196+
let mut cache = SighashCache::new(&tx);
197197

198198
if key_spend {
199199
// test key spend
@@ -274,13 +274,13 @@ fn taproot_tests() {
274274
let genesis_hash = BlockHash::from_str(&genesis_hash_str).unwrap();
275275

276276
let sighash_tys = [
277-
SchnorrSigHashType::Default,
278-
SchnorrSigHashType::Single,
279-
SchnorrSigHashType::SinglePlusAnyoneCanPay,
280-
SchnorrSigHashType::None,
281-
SchnorrSigHashType::NonePlusAnyoneCanPay,
282-
SchnorrSigHashType::All,
283-
SchnorrSigHashType::AllPlusAnyoneCanPay,
277+
SchnorrSighashType::Default,
278+
SchnorrSighashType::Single,
279+
SchnorrSighashType::SinglePlusAnyoneCanPay,
280+
SchnorrSighashType::None,
281+
SchnorrSighashType::NonePlusAnyoneCanPay,
282+
SchnorrSighashType::All,
283+
SchnorrSighashType::AllPlusAnyoneCanPay,
284284
];
285285

286286
for &conf_prevout in &[true, false] {

src/hash_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ hash_newtype! {
4444
pub struct BlockHash(sha256d::Hash);
4545

4646
/// "Hash of the transaction according to the signature algorithm"
47-
pub struct SigHash(sha256d::Hash);
47+
pub struct Sighash(sha256d::Hash);
4848

4949
/// A hash of a public key.
5050
pub struct PubkeyHash(hash160::Hash);
@@ -62,11 +62,11 @@ hash_newtype! {
6262

6363
impl_hashencode!(Txid);
6464
impl_hashencode!(Wtxid);
65-
impl_hashencode!(SigHash);
65+
impl_hashencode!(Sighash);
6666
impl_hashencode!(BlockHash);
6767
impl_hashencode!(TxMerkleNode);
6868

69-
impl ThirtyTwoByteHash for SigHash {
69+
impl ThirtyTwoByteHash for Sighash {
7070
fn into_32(self) -> [u8; 32] {
7171
self.0.to_byte_array()
7272
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub use bitcoin::bech32;
7272
pub use bitcoin::hashes;
7373
// export everything at the top level so it can be used as `elements::Transaction` etc.
7474
pub use crate::address::{Address, AddressParams, AddressError};
75-
pub use crate::transaction::{OutPoint, PeginData, PegoutData, EcdsaSigHashType, TxIn, TxOut, TxInWitness, TxOutWitness, Transaction, AssetIssuance};
75+
pub use crate::transaction::{OutPoint, PeginData, PegoutData, EcdsaSighashType, TxIn, TxOut, TxInWitness, TxOutWitness, Transaction, AssetIssuance};
7676
pub use crate::transaction::Sequence;
7777
pub use crate::blind::{ConfidentialTxOutError, TxOutSecrets, SurjectionInput, TxOutError, VerificationError, BlindError, UnblindError, BlindValueProofs, BlindAssetProofs};
7878
pub use crate::block::{BlockHeader, Block};
@@ -83,5 +83,5 @@ pub use crate::hash_types::*;
8383
pub use crate::issuance::{AssetId, ContractHash};
8484
pub use crate::locktime::LockTime;
8585
pub use crate::script::Script;
86-
pub use crate::sighash::SchnorrSigHashType;
86+
pub use crate::sighash::SchnorrSighashType;
8787
pub use crate::schnorr::{SchnorrSig, SchnorrSigError};

src/pset/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub enum Error {
6464
/// Actual
6565
actual: Txid,
6666
},
67-
/// Unable to parse as a standard SigHash type.
68-
NonStandardSigHashType(u32),
67+
/// Unable to parse as a standard Sighash type.
68+
NonStandardSighashType(u32),
6969
/// Parsing errors from bitcoin_hashes
7070
HashParseError(hashes::Error),
7171
/// The pre-image must hash to the correponding pset hash
@@ -129,7 +129,7 @@ impl fmt::Display for Error {
129129
expected: ref e,
130130
actual: ref a,
131131
} => write!(f, "different id: expected {}, actual {}", e, a),
132-
Error::NonStandardSigHashType(ref sht) => {
132+
Error::NonStandardSighashType(ref sht) => {
133133
write!(f, "non-standard sighash type: {}", sht)
134134
}
135135
Error::InvalidMagic => f.write_str("invalid magic"),

src/pset/map/input.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::pset::map::Map;
3030
use crate::pset::raw;
3131
use crate::pset::serialize;
3232
use crate::pset::{self, error, Error};
33-
use crate::{transaction::SighashTypeParseError, SchnorrSigHashType};
34-
use crate::{AssetIssuance, BlockHash, EcdsaSigHashType, Script, Transaction, TxIn, TxOut, Txid};
33+
use crate::{transaction::SighashTypeParseError, SchnorrSighashType};
34+
use crate::{AssetIssuance, BlockHash, EcdsaSighashType, Script, Transaction, TxIn, TxOut, Txid};
3535
use bitcoin::bip32::KeySource;
3636
use bitcoin::{PublicKey, key::XOnlyPublicKey};
3737
use secp256k1_zkp::{self, RangeProof, Tweak, ZERO_TWEAK};
@@ -292,7 +292,7 @@ impl Default for Input {
292292
}
293293

294294
/// A Signature hash type for the corresponding input. As of taproot upgrade, the signature hash
295-
/// type can be either [`EcdsaSigHashType`] or [`SchnorrSigHashType`] but it is not possible to know
295+
/// type can be either [`EcdsaSighashType`] or [`SchnorrSighashType`] but it is not possible to know
296296
/// directly which signature hash type the user is dealing with. Therefore, the user is responsible
297297
/// for converting to/from [`PsbtSighashType`] from/to the desired signature hash type they need.
298298
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -305,7 +305,7 @@ serde_string_impl!(PsbtSighashType, "a PsbtSighashType data");
305305
impl fmt::Display for PsbtSighashType {
306306
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
307307
match self.schnorr_hash_ty() {
308-
Some(SchnorrSigHashType::Reserved) | None => write!(f, "{:#x}", self.inner),
308+
Some(SchnorrSighashType::Reserved) | None => write!(f, "{:#x}", self.inner),
309309
Some(schnorr_hash_ty) => fmt::Display::fmt(&schnorr_hash_ty, f),
310310
}
311311
}
@@ -321,8 +321,8 @@ impl FromStr for PsbtSighashType {
321321
// NB: some of Schnorr sighash types are non-standard for pre-taproot
322322
// inputs. We also do not support SIGHASH_RESERVED in verbatim form
323323
// ("0xFF" string should be used instead).
324-
match SchnorrSigHashType::from_str(s) {
325-
Ok(SchnorrSigHashType::Reserved) => {
324+
match SchnorrSighashType::from_str(s) {
325+
Ok(SchnorrSighashType::Reserved) => {
326326
return Err(SighashTypeParseError {
327327
unrecognized: s.to_owned(),
328328
})
@@ -341,36 +341,36 @@ impl FromStr for PsbtSighashType {
341341
})
342342
}
343343
}
344-
impl From<EcdsaSigHashType> for PsbtSighashType {
345-
fn from(ecdsa_hash_ty: EcdsaSigHashType) -> Self {
344+
impl From<EcdsaSighashType> for PsbtSighashType {
345+
fn from(ecdsa_hash_ty: EcdsaSighashType) -> Self {
346346
PsbtSighashType {
347347
inner: ecdsa_hash_ty as u32,
348348
}
349349
}
350350
}
351351

352-
impl From<SchnorrSigHashType> for PsbtSighashType {
353-
fn from(schnorr_hash_ty: SchnorrSigHashType) -> Self {
352+
impl From<SchnorrSighashType> for PsbtSighashType {
353+
fn from(schnorr_hash_ty: SchnorrSighashType) -> Self {
354354
PsbtSighashType {
355355
inner: schnorr_hash_ty as u32,
356356
}
357357
}
358358
}
359359

360360
impl PsbtSighashType {
361-
/// Returns the [`EcdsaSigHashType`] if the [`PsbtSighashType`] can be
361+
/// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be
362362
/// converted to one.
363-
pub fn ecdsa_hash_ty(self) -> Option<EcdsaSigHashType> {
364-
EcdsaSigHashType::from_standard(self.inner).ok()
363+
pub fn ecdsa_hash_ty(self) -> Option<EcdsaSighashType> {
364+
EcdsaSighashType::from_standard(self.inner).ok()
365365
}
366366

367-
/// Returns the [`SchnorrSigHashType`] if the [`PsbtSighashType`] can be
367+
/// Returns the [`SchnorrSighashType`] if the [`PsbtSighashType`] can be
368368
/// converted to one.
369-
pub fn schnorr_hash_ty(self) -> Option<SchnorrSigHashType> {
369+
pub fn schnorr_hash_ty(self) -> Option<SchnorrSighashType> {
370370
if self.inner > 0xffu32 {
371371
None
372372
} else {
373-
SchnorrSigHashType::from_u8(self.inner as u8)
373+
SchnorrSighashType::from_u8(self.inner as u8)
374374
}
375375
}
376376

@@ -390,28 +390,28 @@ impl PsbtSighashType {
390390
}
391391

392392
impl Input {
393-
/// Obtains the [`EcdsaSigHashType`] for this input if one is specified. If no sighash type is
394-
/// specified, returns [`EcdsaSigHashType::All`].
393+
/// Obtains the [`EcdsaSighashType`] for this input if one is specified. If no sighash type is
394+
/// specified, returns [`EcdsaSighashType::All`].
395395
///
396396
/// # Errors
397397
///
398398
/// If the `sighash_type` field is set to a non-standard ECDSA sighash value.
399-
pub fn ecdsa_hash_ty(&self) -> Option<EcdsaSigHashType> {
399+
pub fn ecdsa_hash_ty(&self) -> Option<EcdsaSighashType> {
400400
self.sighash_type
401401
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
402-
.unwrap_or(Some(EcdsaSigHashType::All))
402+
.unwrap_or(Some(EcdsaSighashType::All))
403403
}
404404

405-
/// Obtains the [`SchnorrSigHashType`] for this input if one is specified. If no sighash type is
406-
/// specified, returns [`SchnorrSigHashType::Default`].
405+
/// Obtains the [`SchnorrSighashType`] for this input if one is specified. If no sighash type is
406+
/// specified, returns [`SchnorrSighashType::Default`].
407407
///
408408
/// # Errors
409409
///
410410
/// If the `sighash_type` field is set to a invalid Schnorr sighash value.
411-
pub fn schnorr_hash_ty(&self) -> Option<SchnorrSigHashType> {
411+
pub fn schnorr_hash_ty(&self) -> Option<SchnorrSighashType> {
412412
self.sighash_type
413413
.map(|sighash_type| sighash_type.schnorr_hash_ty())
414-
.unwrap_or(Some(SchnorrSigHashType::Default))
414+
.unwrap_or(Some(SchnorrSighashType::Default))
415415
}
416416

417417
/// Create a psbt input from prevout

src/pset/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//!
1717
//! Implementation of BIP174 Partially Signed Bitcoin Transaction Format as
1818
//! defined at <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>
19-
//! except we define PSETs containing non-standard SigHash types as invalid.
19+
//! except we define PSETs containing non-standard Sighash types as invalid.
2020
//! Extension for PSET is based on PSET defined in BIP370.
2121
//! <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>
2222

src/pset/serialize.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::map::{PsbtSighashType, TapTree};
3434
use crate::schnorr;
3535
use crate::taproot::{ControlBlock, LeafVersion, TapBranchHash, TapLeafHash};
3636

37-
use crate::sighash::SchnorrSigHashType;
37+
use crate::sighash::SchnorrSighashType;
3838
use crate::taproot::TaprootBuilder;
3939

4040
/// A trait for serializing a value as raw data for insertion into PSET
@@ -300,7 +300,7 @@ impl Deserialize for schnorr::SchnorrSig {
300300
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
301301
match bytes.len() {
302302
65 => {
303-
let hash_ty = SchnorrSigHashType::from_u8(bytes[64])
303+
let hash_ty = SchnorrSighashType::from_u8(bytes[64])
304304
.ok_or(encode::Error::ParseFailed("Invalid Sighash type"))?;
305305
let sig = secp256k1_zkp::schnorr::Signature::from_slice(&bytes[..64])
306306
.map_err(|_| encode::Error::ParseFailed("Invalid Schnorr signature"))?;
@@ -311,7 +311,7 @@ impl Deserialize for schnorr::SchnorrSig {
311311
.map_err(|_| encode::Error::ParseFailed("Invalid Schnorr signature"))?;
312312
Ok(schnorr::SchnorrSig {
313313
sig,
314-
hash_ty: SchnorrSigHashType::Default,
314+
hash_ty: SchnorrSighashType::Default,
315315
})
316316
}
317317
_ => Err(encode::Error::ParseFailed("Invalid Schnorr signature len")),

src/schnorr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::fmt;
2121

2222
use crate::taproot::{TapBranchHash, TapTweakHash};
23-
use crate::SchnorrSigHashType;
23+
use crate::SchnorrSighashType;
2424
use secp256k1_zkp::{self, constants::SCHNORR_SIGNATURE_SIZE, Secp256k1, Verification};
2525
pub use secp256k1_zkp::{KeyPair, XOnlyPublicKey};
2626

@@ -209,7 +209,7 @@ pub struct SchnorrSig {
209209
/// The underlying schnorr signature
210210
pub sig: secp256k1_zkp::schnorr::Signature,
211211
/// The corresponding hash type
212-
pub hash_ty: SchnorrSigHashType,
212+
pub hash_ty: SchnorrSighashType,
213213
}
214214

215215
impl SchnorrSig {
@@ -220,11 +220,11 @@ impl SchnorrSig {
220220
// default type
221221
let sig = secp256k1_zkp::schnorr::Signature::from_slice(sl)
222222
.map_err(|_| SchnorrSigError::InvalidSchnorrSig)?;
223-
return Ok( SchnorrSig { sig, hash_ty : SchnorrSigHashType::Default });
223+
return Ok( SchnorrSig { sig, hash_ty : SchnorrSighashType::Default });
224224
}
225225
let (hash_ty, sig) = sl.split_last()
226226
.ok_or(SchnorrSigError::InvalidSchnorrSig)?;
227-
let hash_ty = SchnorrSigHashType::from_u8(*hash_ty)
227+
let hash_ty = SchnorrSighashType::from_u8(*hash_ty)
228228
.ok_or(SchnorrSigError::InvalidSighashType(*hash_ty))?;
229229
let sig = secp256k1_zkp::schnorr::Signature::from_slice(sig)
230230
.map_err(|_| SchnorrSigError::InvalidSchnorrSig)?;
@@ -235,7 +235,7 @@ impl SchnorrSig {
235235
pub fn to_vec(&self) -> Vec<u8> {
236236
// TODO: add support to serialize to a writer to SerializedSig
237237
let mut ser_sig = self.sig.as_ref().to_vec();
238-
if let SchnorrSigHashType::Default = self.hash_ty {
238+
if let SchnorrSighashType::Default = self.hash_ty {
239239
// default sighash type, don't add extra sighash byte
240240
} else {
241241
ser_sig.push(self.hash_ty as u8);

0 commit comments

Comments
 (0)