Skip to content

Commit 43e36ff

Browse files
committed
SchnorrSigHashType -> SchnorrSighashType
1 parent d78493e commit 43e36ff

6 files changed

Lines changed: 78 additions & 78 deletions

File tree

elementsd-tests/src/taproot.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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,
@@ -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/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/map/input.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ 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};
33+
use crate::{transaction::SighashTypeParseError, SchnorrSighashType};
3434
use crate::{AssetIssuance, BlockHash, EcdsaSigHashType, Script, Transaction, TxIn, TxOut, Txid};
3535
use bitcoin::bip32::KeySource;
3636
use bitcoin::{PublicKey, key::XOnlyPublicKey};
@@ -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
})
@@ -349,8 +349,8 @@ impl From<EcdsaSigHashType> for PsbtSighashType {
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
}
@@ -364,13 +364,13 @@ impl PsbtSighashType {
364364
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

@@ -402,16 +402,16 @@ impl Input {
402402
.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/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);

src/sighash.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct TaprootCache {
8686
}
8787

8888
/// Contains outputs of previous transactions.
89-
/// In the case [`SchnorrSigHashType`] variant is `ANYONECANPAY`, [`Prevouts::One`] may be provided
89+
/// In the case [`SchnorrSighashType`] variant is `ANYONECANPAY`, [`Prevouts::One`] may be provided
9090
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
9191
pub enum Prevouts<'u, T> where T: 'u + Borrow<TxOut> {
9292
/// `One` variant allows to provide the single Prevout needed. It's useful for example
@@ -256,7 +256,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
256256
prevouts: &Prevouts<T>,
257257
annex: Option<Annex>,
258258
leaf_hash_code_separator: Option<(TapLeafHash, u32)>,
259-
sighash_type: SchnorrSigHashType,
259+
sighash_type: SchnorrSighashType,
260260
genesis_hash: BlockHash,
261261
) -> Result<(), Error> {
262262
prevouts.check_all(&self.tx)?;
@@ -313,7 +313,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
313313
// If hash_type & 3 does not equal SIGHASH_NONE or SIGHASH_SINGLE:
314314
// sha_outputs (32): the SHA256 of the serialization of all outputs in CTxOut format.
315315
// sha_output_witnesses (32): (ELEMENTS) the SHA256 of the serialization of all output witnesses
316-
if sighash != SchnorrSigHashType::None && sighash != SchnorrSigHashType::Single {
316+
if sighash != SchnorrSighashType::None && sighash != SchnorrSighashType::Single {
317317
self.common_cache().outputs.consensus_encode(&mut writer)?;
318318
self.taproot_cache(prevouts.get_all()?)
319319
.output_witnesses
@@ -388,7 +388,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
388388
// If hash_type & 3 equals SIGHASH_SINGLE:
389389
// sha_single_output (32): the SHA256 of the corresponding output in CTxOut format.
390390
// sha_single_output_witness (32): the sha256 serialization of output witnesses
391-
if sighash == SchnorrSigHashType::Single {
391+
if sighash == SchnorrSighashType::Single {
392392
let mut enc = sha256::Hash::engine();
393393
let out = self.tx
394394
.output
@@ -428,7 +428,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
428428
prevouts: &Prevouts<T>,
429429
annex: Option<Annex>,
430430
leaf_hash_code_separator: Option<(TapLeafHash, u32)>,
431-
sighash_type: SchnorrSigHashType,
431+
sighash_type: SchnorrSighashType,
432432
genesis_hash: BlockHash,
433433
) -> Result<TapSighashHash, Error> {
434434
let mut enc = TapSighashHash::engine();
@@ -449,7 +449,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
449449
&mut self,
450450
input_index: usize,
451451
prevouts: &Prevouts<T>,
452-
sighash_type: SchnorrSigHashType,
452+
sighash_type: SchnorrSighashType,
453453
genesis_hash: BlockHash,
454454
) -> Result<TapSighashHash, Error> {
455455
let mut enc = TapSighashHash::engine();
@@ -474,7 +474,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
474474
input_index: usize,
475475
prevouts: &Prevouts<T>,
476476
leaf_hash: S,
477-
sighash_type: SchnorrSigHashType,
477+
sighash_type: SchnorrSighashType,
478478
genesis_hash: BlockHash,
479479
) -> Result<TapSighashHash, Error> {
480480
let mut enc = TapSighashHash::engine();
@@ -875,8 +875,8 @@ impl<'a> Encodable for Annex<'a> {
875875
/// Hashtype of an input's signature, encoded in the last byte of the signature
876876
/// Fixed values so they can be casted as integer types for encoding
877877
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
878-
pub enum SchnorrSigHashType {
879-
/// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSigHashType::All`]
878+
pub enum SchnorrSighashType {
879+
/// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSighashType::All`]
880880
Default = 0x00,
881881
/// 0x1: Sign all outputs
882882
All = 0x01,
@@ -898,67 +898,67 @@ pub enum SchnorrSigHashType {
898898
Reserved = 0xFF,
899899
}
900900

901-
serde_string_impl!(SchnorrSigHashType, "a SchnorrSigHashType data");
901+
serde_string_impl!(SchnorrSighashType, "a SchnorrSighashType data");
902902

903-
impl SchnorrSigHashType {
903+
impl SchnorrSighashType {
904904
/// Break the sighash flag into the "real" sighash flag and the ANYONECANPAY boolean
905-
pub fn split_anyonecanpay_flag(self) -> (SchnorrSigHashType, bool) {
905+
pub fn split_anyonecanpay_flag(self) -> (SchnorrSighashType, bool) {
906906
match self {
907-
SchnorrSigHashType::Default => (SchnorrSigHashType::Default, false),
908-
SchnorrSigHashType::All => (SchnorrSigHashType::All, false),
909-
SchnorrSigHashType::None => (SchnorrSigHashType::None, false),
910-
SchnorrSigHashType::Single => (SchnorrSigHashType::Single, false),
911-
SchnorrSigHashType::AllPlusAnyoneCanPay => (SchnorrSigHashType::All, true),
912-
SchnorrSigHashType::NonePlusAnyoneCanPay => (SchnorrSigHashType::None, true),
913-
SchnorrSigHashType::SinglePlusAnyoneCanPay => (SchnorrSigHashType::Single, true),
914-
SchnorrSigHashType::Reserved => (SchnorrSigHashType::Reserved, false),
907+
SchnorrSighashType::Default => (SchnorrSighashType::Default, false),
908+
SchnorrSighashType::All => (SchnorrSighashType::All, false),
909+
SchnorrSighashType::None => (SchnorrSighashType::None, false),
910+
SchnorrSighashType::Single => (SchnorrSighashType::Single, false),
911+
SchnorrSighashType::AllPlusAnyoneCanPay => (SchnorrSighashType::All, true),
912+
SchnorrSighashType::NonePlusAnyoneCanPay => (SchnorrSighashType::None, true),
913+
SchnorrSighashType::SinglePlusAnyoneCanPay => (SchnorrSighashType::Single, true),
914+
SchnorrSighashType::Reserved => (SchnorrSighashType::Reserved, false),
915915
}
916916
}
917917

918-
/// Create a [`SchnorrSigHashType`] from raw u8
918+
/// Create a [`SchnorrSighashType`] from raw u8
919919
pub fn from_u8(hash_ty: u8) -> Option<Self> {
920920
match hash_ty {
921-
0x00 => Some(SchnorrSigHashType::Default),
922-
0x01 => Some(SchnorrSigHashType::All),
923-
0x02 => Some(SchnorrSigHashType::None),
924-
0x03 => Some(SchnorrSigHashType::Single),
925-
0x81 => Some(SchnorrSigHashType::AllPlusAnyoneCanPay),
926-
0x82 => Some(SchnorrSigHashType::NonePlusAnyoneCanPay),
927-
0x83 => Some(SchnorrSigHashType::SinglePlusAnyoneCanPay),
921+
0x00 => Some(SchnorrSighashType::Default),
922+
0x01 => Some(SchnorrSighashType::All),
923+
0x02 => Some(SchnorrSighashType::None),
924+
0x03 => Some(SchnorrSighashType::Single),
925+
0x81 => Some(SchnorrSighashType::AllPlusAnyoneCanPay),
926+
0x82 => Some(SchnorrSighashType::NonePlusAnyoneCanPay),
927+
0x83 => Some(SchnorrSighashType::SinglePlusAnyoneCanPay),
928928
_x => None,
929929
}
930930
}
931931
}
932932

933-
impl fmt::Display for SchnorrSigHashType {
933+
impl fmt::Display for SchnorrSighashType {
934934
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
935935
let s = match self {
936-
SchnorrSigHashType::Default => "SIGHASH_DEFAULT",
937-
SchnorrSigHashType::All => "SIGHASH_ALL",
938-
SchnorrSigHashType::None => "SIGHASH_NONE",
939-
SchnorrSigHashType::Single => "SIGHASH_SINGLE",
940-
SchnorrSigHashType::AllPlusAnyoneCanPay => "SIGHASH_ALL|SIGHASH_ANYONECANPAY",
941-
SchnorrSigHashType::NonePlusAnyoneCanPay => "SIGHASH_NONE|SIGHASH_ANYONECANPAY",
942-
SchnorrSigHashType::SinglePlusAnyoneCanPay => "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY",
943-
SchnorrSigHashType::Reserved => "SIGHASH_RESERVED",
936+
SchnorrSighashType::Default => "SIGHASH_DEFAULT",
937+
SchnorrSighashType::All => "SIGHASH_ALL",
938+
SchnorrSighashType::None => "SIGHASH_NONE",
939+
SchnorrSighashType::Single => "SIGHASH_SINGLE",
940+
SchnorrSighashType::AllPlusAnyoneCanPay => "SIGHASH_ALL|SIGHASH_ANYONECANPAY",
941+
SchnorrSighashType::NonePlusAnyoneCanPay => "SIGHASH_NONE|SIGHASH_ANYONECANPAY",
942+
SchnorrSighashType::SinglePlusAnyoneCanPay => "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY",
943+
SchnorrSighashType::Reserved => "SIGHASH_RESERVED",
944944
};
945945
f.write_str(s)
946946
}
947947
}
948948

949-
impl std::str::FromStr for SchnorrSigHashType {
949+
impl std::str::FromStr for SchnorrSighashType {
950950
type Err = SighashTypeParseError;
951951

952952
fn from_str(s: &str) -> Result<Self, Self::Err> {
953953
match s {
954-
"SIGHASH_DEFAULT" => Ok(SchnorrSigHashType::Default),
955-
"SIGHASH_ALL" => Ok(SchnorrSigHashType::All),
956-
"SIGHASH_NONE" => Ok(SchnorrSigHashType::None),
957-
"SIGHASH_SINGLE" => Ok(SchnorrSigHashType::Single),
958-
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(SchnorrSigHashType::AllPlusAnyoneCanPay),
959-
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSigHashType::NonePlusAnyoneCanPay),
960-
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSigHashType::SinglePlusAnyoneCanPay),
961-
"SIGHASH_RESERVED" => Ok(SchnorrSigHashType::Reserved),
954+
"SIGHASH_DEFAULT" => Ok(SchnorrSighashType::Default),
955+
"SIGHASH_ALL" => Ok(SchnorrSighashType::All),
956+
"SIGHASH_NONE" => Ok(SchnorrSighashType::None),
957+
"SIGHASH_SINGLE" => Ok(SchnorrSighashType::Single),
958+
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::AllPlusAnyoneCanPay),
959+
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::NonePlusAnyoneCanPay),
960+
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::SinglePlusAnyoneCanPay),
961+
"SIGHASH_RESERVED" => Ok(SchnorrSighashType::Reserved),
962962
_ => Err(SighashTypeParseError{ unrecognized: s.to_owned() }),
963963
}
964964
}

0 commit comments

Comments
 (0)