mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
fmt clippy
This commit is contained in:
parent
24a3165634
commit
acaf62f31f
@ -55,8 +55,8 @@ impl Message {
|
||||
assert_eq!(&prefix, MESSAGE_ENCODING_PREFIX);
|
||||
let program_id: ProgramId = {
|
||||
let mut this = [0u32; 8];
|
||||
for i in 0..8 {
|
||||
this[i] = u32_from_cursor(cursor)?;
|
||||
for item in &mut this {
|
||||
*item = u32_from_cursor(cursor)?;
|
||||
}
|
||||
this
|
||||
};
|
||||
@ -128,7 +128,7 @@ impl PublicTransaction {
|
||||
|
||||
pub fn from_bytes(bytes: &[u8]) -> Result<Self, NssaError> {
|
||||
let mut cursor = Cursor::new(bytes);
|
||||
Ok(Self::from_cursor(&mut cursor)?)
|
||||
Self::from_cursor(&mut cursor)
|
||||
}
|
||||
|
||||
pub fn from_cursor(cursor: &mut Cursor<&[u8]>) -> Result<Self, NssaError> {
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
|
||||
mod encoding;
|
||||
mod message;
|
||||
mod witness_set;
|
||||
mod transaction;
|
||||
mod witness_set;
|
||||
|
||||
pub use message::Message;
|
||||
pub use witness_set::WitnessSet;
|
||||
pub use transaction::PublicTransaction;
|
||||
pub use witness_set::WitnessSet;
|
||||
|
||||
@ -13,7 +13,6 @@ use crate::{
|
||||
public_transaction::{Message, WitnessSet},
|
||||
};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PublicTransaction {
|
||||
pub(crate) message: Message,
|
||||
@ -114,4 +113,3 @@ impl PublicTransaction {
|
||||
Ok(message.addresses.iter().cloned().zip(post_states).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,43 @@
|
||||
mod encoding;
|
||||
mod private_key;
|
||||
mod public_key;
|
||||
mod signature;
|
||||
|
||||
pub use private_key::PrivateKey;
|
||||
pub use public_key::PublicKey;
|
||||
pub use signature::Signature;
|
||||
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Signature {
|
||||
pub(crate) value: [u8; 64],
|
||||
}
|
||||
|
||||
impl Signature {
|
||||
pub fn new(key: &PrivateKey, message: &[u8]) -> Self {
|
||||
let mut aux_random = [0u8; 32];
|
||||
OsRng.fill_bytes(&mut aux_random);
|
||||
Self::new_with_aux_random(key, message, aux_random)
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_aux_random(
|
||||
key: &PrivateKey,
|
||||
message: &[u8],
|
||||
aux_random: [u8; 32],
|
||||
) -> Self {
|
||||
let value = {
|
||||
let secp = secp256k1::Secp256k1::new();
|
||||
let secret_key = secp256k1::SecretKey::from_byte_array(key.0).unwrap();
|
||||
let keypair = secp256k1::Keypair::from_secret_key(&secp, &secret_key);
|
||||
let signature = secp.sign_schnorr_with_aux_rand(message, &keypair, &aux_random);
|
||||
signature.to_byte_array()
|
||||
};
|
||||
Self { value }
|
||||
}
|
||||
|
||||
pub fn is_valid_for(&self, bytes: &[u8], public_key: &PublicKey) -> bool {
|
||||
let pk = secp256k1::XOnlyPublicKey::from_byte_array(public_key.0).unwrap();
|
||||
let secp = secp256k1::Secp256k1::new();
|
||||
let sig = secp256k1::schnorr::Signature::from_byte_array(self.value);
|
||||
secp.verify_schnorr(&sig, bytes, &pk).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
|
||||
use crate::{PrivateKey, PublicKey};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Signature {
|
||||
pub(crate) value: [u8; 64],
|
||||
}
|
||||
|
||||
impl Signature {
|
||||
pub fn new(key: &PrivateKey, message: &[u8]) -> Self {
|
||||
let mut aux_random = [0u8; 32];
|
||||
OsRng.fill_bytes(&mut aux_random);
|
||||
Self::new_with_aux_random(key, message, aux_random)
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_aux_random(
|
||||
key: &PrivateKey,
|
||||
message: &[u8],
|
||||
aux_random: [u8; 32],
|
||||
) -> Self {
|
||||
let value = {
|
||||
let secp = secp256k1::Secp256k1::new();
|
||||
let secret_key = secp256k1::SecretKey::from_byte_array(key.0).unwrap();
|
||||
let keypair = secp256k1::Keypair::from_secret_key(&secp, &secret_key);
|
||||
let signature = secp.sign_schnorr_with_aux_rand(message, &keypair, &aux_random);
|
||||
signature.to_byte_array()
|
||||
};
|
||||
Self { value }
|
||||
}
|
||||
|
||||
pub fn is_valid_for(&self, bytes: &[u8], public_key: &PublicKey) -> bool {
|
||||
let pk = secp256k1::XOnlyPublicKey::from_byte_array(public_key.0).unwrap();
|
||||
let secp = secp256k1::Secp256k1::new();
|
||||
let sig = secp256k1::schnorr::Signature::from_byte_array(self.value);
|
||||
secp.verify_schnorr(&sig, bytes, &pk).is_ok()
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
mod bip340_test_vectors;
|
||||
mod program_tests;
|
||||
mod public_transaction_tests;
|
||||
mod signature_tests;
|
||||
mod state_tests;
|
||||
mod valid_execution_tests;
|
||||
mod public_transaction_tests;
|
||||
|
||||
@ -16,7 +16,7 @@ fn keys_for_tests() -> (PrivateKey, PrivateKey, Address, Address) {
|
||||
}
|
||||
|
||||
fn state_for_tests() -> V01State {
|
||||
let (key1, key2, addr1, addr2) = keys_for_tests();
|
||||
let (_, _, addr1, addr2) = keys_for_tests();
|
||||
let initial_data = [(*addr1.value(), 10000), (*addr2.value(), 20000)];
|
||||
V01State::new_with_genesis_accounts(&initial_data)
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::{
|
||||
Address, PublicKey, PublicTransaction, V01State, error::NssaError, program::Program,
|
||||
public_transaction, signature::PrivateKey,
|
||||
};
|
||||
use nssa_core::{account::Account, program::ProgramId};
|
||||
use nssa_core::account::Account;
|
||||
|
||||
fn transfer_transaction(
|
||||
from: Address,
|
||||
@ -101,12 +101,6 @@ fn test_get_account_by_address_default_account() {
|
||||
#[test]
|
||||
fn test_builtin_programs_getter() {
|
||||
let state = V01State::new_with_genesis_accounts(&[]);
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let expected_builtin_programs = {
|
||||
let mut this = HashMap::new();
|
||||
this.insert(program.id(), program);
|
||||
this
|
||||
};
|
||||
|
||||
let builtin_programs = state.builtin_programs();
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use nssa_core::{account::Account, program::read_nssa_inputs};
|
||||
use nssa_core::program::read_nssa_inputs;
|
||||
use risc0_zkvm::guest::env;
|
||||
|
||||
type Instruction = ();
|
||||
@ -17,4 +17,3 @@ fn main() {
|
||||
|
||||
env::commit(&vec![account_post]);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user