Skip to content

Commit

Permalink
renamed SigCheck to Sr25519Signature
Browse files Browse the repository at this point in the history
Signed-off-by: muraca <mmuraca247@gmail.com>
  • Loading branch information
muraca committed Nov 13, 2023
1 parent d6c52b8 commit 15ce27d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
20 changes: 10 additions & 10 deletions tuxedo-core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ pub trait Verifier: Debug + Encode + Decode + Clone {

/// A typical verifier that checks an sr25519 signature
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct SigCheck {
pub struct Sr25519Signature {
pub owner_pubkey: H256,
}

impl SigCheck {
impl Sr25519Signature {
pub fn new<T: Into<H256>>(value: T) -> Self {
SigCheck {
Sr25519Signature {
owner_pubkey: value.into(),
}
}
}

impl Verifier for SigCheck {
impl Verifier for Sr25519Signature {
fn verify(&self, simplified_tx: &[u8], redeemer: &[u8]) -> bool {
let sig = match Signature::try_from(redeemer) {
Ok(s) => s,
Expand Down Expand Up @@ -190,17 +190,17 @@ mod test {
}

#[test]
fn sig_check_with_good_sig() {
fn sr25519_signature_with_good_sig() {
let pair = Pair::from_seed(&[0u8; 32]);
let simplified_tx = b"hello world".as_slice();
let sig = pair.sign(simplified_tx);
let redeemer: &[u8] = sig.as_ref();

let sig_check = SigCheck {
let sr25519_signature = Sr25519Signature {
owner_pubkey: pair.public().into(),
};

assert!(sig_check.verify(simplified_tx, redeemer));
assert!(sr25519_signature.verify(simplified_tx, redeemer));
}

#[test]
Expand Down Expand Up @@ -354,15 +354,15 @@ mod test {
}

#[test]
fn sig_check_with_bad_sig() {
fn sr25519_signature_with_bad_sig() {
let simplified_tx = b"hello world".as_slice();
let redeemer = b"bogus_signature".as_slice();

let sig_check = SigCheck {
let sr25519_signature = Sr25519Signature {
owner_pubkey: H256::zero(),
};

assert!(!sig_check.verify(simplified_tx, redeemer));
assert!(!sr25519_signature.verify(simplified_tx, redeemer));
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions tuxedo-template-runtime/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
use hex_literal::hex;
use tuxedo_core::{
inherents::InherentInternal,
verifier::{SigCheck, ThresholdMultiSignature, UpForGrabs},
verifier::{Sr25519Signature, ThresholdMultiSignature, UpForGrabs},
};

/// Helper type for the ChainSpec.
Expand All @@ -28,7 +28,7 @@ pub fn development_genesis_config() -> RuntimeGenesisConfig {

genesis_transactions.extend([
// Money Transactions
Coin::<0>::mint(100, SigCheck::new(SHAWN_PUB_KEY_BYTES)),
Coin::<0>::mint(100, Sr25519Signature::new(SHAWN_PUB_KEY_BYTES)),
Coin::<0>::mint(100, ThresholdMultiSignature::new(1, signatories)),
// Kitty Transactions
KittyData::mint(Parent::mom(), b"mother", UpForGrabs),
Expand Down Expand Up @@ -85,7 +85,7 @@ mod tests {
let mut genesis_transactions = OuterConstraintCheckerInherentHooks::genesis_transactions();
genesis_transactions.extend([
// Money Transactions
Coin::<0>::mint(100, SigCheck::new(shawn_pub_key_bytes)),
Coin::<0>::mint(100, Sr25519Signature::new(shawn_pub_key_bytes)),
Coin::<0>::mint(100, ThresholdMultiSignature::new(1, signatories)),
]);

Expand Down Expand Up @@ -118,7 +118,7 @@ mod tests {

// Grab genesis value from storage and assert it is correct
let genesis_utxo = Output {
verifier: OuterVerifier::SigCheck(SigCheck {
verifier: OuterVerifier::Sr25519Signature(Sr25519Signature {
owner_pubkey: shawn_pub_key.into(),
}),
payload: DynamicallyTypedData {
Expand Down
4 changes: 2 additions & 2 deletions tuxedo-template-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use sp_version::RuntimeVersion;
use tuxedo_core::{
tuxedo_constraint_checker, tuxedo_verifier,
types::Transaction as TuxedoTransaction,
verifier::{SigCheck, ThresholdMultiSignature, UpForGrabs},
verifier::{Sr25519Signature, ThresholdMultiSignature, UpForGrabs},
};

pub use amoeba;
Expand Down Expand Up @@ -122,7 +122,7 @@ const BLOCK_TIME: u64 = 3000;
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[tuxedo_verifier]
pub enum OuterVerifier {
SigCheck(SigCheck),
Sr25519Signature(Sr25519Signature),
UpForGrabs(UpForGrabs),
ThresholdMultiSignature(ThresholdMultiSignature),
}
Expand Down
6 changes: 3 additions & 3 deletions wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn main() -> anyhow::Result<()> {
let keystore_filter = |v: &OuterVerifier| -> bool {
matches![
v,
OuterVerifier::SigCheck(SigCheck { owner_pubkey }) if crate::keystore::has_key(&keystore, owner_pubkey)
OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey }) if crate::keystore::has_key(&keystore, owner_pubkey)
]
};

Expand Down Expand Up @@ -243,8 +243,8 @@ fn default_data_path() -> PathBuf {
/// Utility to pretty print an outer verifier
pub fn pretty_print_verifier(v: &OuterVerifier) {
match v {
OuterVerifier::SigCheck(sig_check) => {
println! {"owned by {}", sig_check.owner_pubkey}
OuterVerifier::Sr25519Signature(sr25519_signature) => {
println! {"owned by {}", sr25519_signature.owner_pubkey}
}
OuterVerifier::UpForGrabs(_) => println!("that can be spent by anyone"),
OuterVerifier::ThresholdMultiSignature(multi_sig) => {
Expand Down
6 changes: 3 additions & 3 deletions wallet/src/money.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sp_core::sr25519::Public;
use sp_runtime::traits::{BlakeTwo256, Hash};
use tuxedo_core::{
types::{Input, Output, OutputRef},
verifier::SigCheck,
verifier::Sr25519Signature,
};

/// Create and send a transaction that spends coins on the network
Expand All @@ -40,7 +40,7 @@ pub async fn spend_coins(
for amount in &args.output_amount {
let output = Output {
payload: Coin::<0>::new(*amount).into(),
verifier: OuterVerifier::SigCheck(SigCheck {
verifier: OuterVerifier::Sr25519Signature(Sr25519Signature {
owner_pubkey: args.recipient,
}),
};
Expand Down Expand Up @@ -93,7 +93,7 @@ pub async fn spend_coins(

// Construct the proof that it can be consumed
let redeemer = match utxo.verifier {
OuterVerifier::SigCheck(SigCheck { owner_pubkey }) => {
OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey }) => {
let public = Public::from_h256(owner_pubkey);
crate::keystore::sign_with(keystore, &public, &stripped_encoded_transaction)?
}
Expand Down
22 changes: 12 additions & 10 deletions wallet/src/output_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub trait OutputFilter {
fn build_filter(verifier: OuterVerifier) -> Self::Filter;
}

pub struct SigCheckFilter;
impl OutputFilter for SigCheckFilter {
pub struct Sr25519SignatureFilter;
impl OutputFilter for Sr25519SignatureFilter {
// Todo Add filter error
type Filter = Result<Filter, ()>;

Expand Down Expand Up @@ -48,8 +48,8 @@ mod tests {
#[cfg(test)]
use tuxedo_core::{dynamic_typing::DynamicallyTypedData, verifier::*};

pub struct TestSigCheckFilter;
impl OutputFilter for TestSigCheckFilter {
pub struct TestSr25519SignatureFilter;
impl OutputFilter for TestSr25519SignatureFilter {
type Filter = Result<Filter, ()>;

fn build_filter(_verifier: OuterVerifier) -> Self::Filter {
Expand All @@ -62,7 +62,7 @@ mod tests {

#[test]
fn filter_prints() {
let verifier = OuterVerifier::SigCheck(SigCheck {
let verifier = OuterVerifier::Sr25519Signature(Sr25519Signature {
owner_pubkey: H256::zero(),
});
let output = Output {
Expand All @@ -73,13 +73,14 @@ mod tests {
},
};

let my_filter = TestSigCheckFilter::build_filter(verifier).expect("Can build print filter");
let my_filter =
TestSr25519SignatureFilter::build_filter(verifier).expect("Can build print filter");
let _ = my_filter(&[output], &H256::zero());
}

#[test]
fn filter_sig_check_works() {
let verifier = OuterVerifier::SigCheck(SigCheck {
fn filter_sr25519_signature_works() {
let verifier = OuterVerifier::Sr25519Signature(Sr25519Signature {
owner_pubkey: H256::zero(),
});

Expand All @@ -92,7 +93,7 @@ mod tests {
},
},
Output {
verifier: OuterVerifier::SigCheck(SigCheck {
verifier: OuterVerifier::Sr25519Signature(Sr25519Signature {
owner_pubkey: H256::from_slice(b"asdfasdfasdfasdfasdfasdfasdfasdf"),
}),
payload: DynamicallyTypedData {
Expand Down Expand Up @@ -126,7 +127,8 @@ mod tests {
},
)];

let my_filter = SigCheckFilter::build_filter(verifier).expect("Can build sigcheck filter");
let my_filter = Sr25519SignatureFilter::build_filter(verifier)
.expect("Can build Sr25519Signature filter");
let filtered_output_infos = my_filter(&outputs_to_filter, &H256::zero())
.expect("Can filter the outputs by verifier correctly");

Expand Down
4 changes: 2 additions & 2 deletions wallet/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, Hash};
use tuxedo_core::{
types::{Input, OutputRef},
verifier::SigCheck,
verifier::Sr25519Signature,
};

use jsonrpsee::http_client::HttpClient;
Expand Down Expand Up @@ -274,7 +274,7 @@ async fn apply_transaction<F: Fn(&OuterVerifier) -> bool>(
};

match output.verifier {
OuterVerifier::SigCheck(SigCheck { owner_pubkey }) => {
OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey }) => {
// Add it to the global unspent_outputs table
add_unspent_output(db, &output_ref, &owner_pubkey, &amount)?;
}
Expand Down

0 comments on commit 15ce27d

Please sign in to comment.