Skip to content

Commit

Permalink
refactor(new fragment generator ): signature verification dalek
Browse files Browse the repository at this point in the history
  • Loading branch information
cong-or committed Dec 7, 2023
1 parent 746e12f commit d55cf74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions chain-impl-mockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rand_chacha = { version = "0.3", optional = true }
criterion = { version = "0.3.0", optional = true }
rand = "0.8"
cryptoxide = "0.4"
ed25519-dalek = "1.0.1"

[features]
property-test-api = [
Expand Down
19 changes: 8 additions & 11 deletions chain-impl-mockchain/src/ledger/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
use chain_addr::{Address, Discrimination, Kind};
use chain_crypto::Verification;
use chain_time::{Epoch as TimeEpoch, SlotDuration, TimeEra, TimeFrame, Timeline};
use ed25519_dalek::{PublicKey, Signature};
use std::collections::HashSet;
use std::mem::swap;
use std::sync::Arc;
Expand Down Expand Up @@ -1888,19 +1889,15 @@ fn input_single_account_verify<'a>(
let new_ledger = ledger.remove_value(account, spending_counter, value)?;
ledger = new_ledger;

let verified = witness.verify(
account.as_ref(),
&WitnessAccountData(sign_data_hash.as_ref().to_vec()),
);
let mut sig = witness.as_ref().to_vec();
sig.drain(0..5);
let witness_sig = Signature::from_bytes(&sig).unwrap();

if verified == chain_crypto::Verification::Failed {
return Err(Error::AccountInvalidSignature {
account: account.clone(),
witness: Witness::Account(spending_counter, witness.clone()),
});
};
let pk = PublicKey::from_bytes(account.as_ref().as_ref()).unwrap();

pk.verify_strict(sign_data_hash.as_ref(), &witness_sig)
.unwrap();

// TODO verify sig(pub_key,data)
Ok(ledger)
}

Expand Down
2 changes: 1 addition & 1 deletion chain-impl-mockchain/src/transaction/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl AsRef<[u8]> for WitnessUtxoData {
}
}

pub struct WitnessAccountData(pub Vec<u8>);
pub struct WitnessAccountData(Vec<u8>);

impl WitnessAccountData {
pub fn new(
Expand Down

0 comments on commit d55cf74

Please sign in to comment.