mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-13 19:49:29 +00:00
reorganization
This commit is contained in:
parent
deccbc3ac0
commit
0390977acf
@ -15,7 +15,6 @@ pub type PublicKey = AffinePoint;
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct NSSAUserData {
|
||||
/// Default public accounts.
|
||||
/// TODO: it appears this is unnecessary
|
||||
pub default_pub_account_signing_keys: BTreeMap<nssa::AccountId, nssa::PrivateKey>,
|
||||
/// Default private accounts.
|
||||
pub default_user_private_accounts:
|
||||
@ -33,7 +32,7 @@ impl NSSAUserData {
|
||||
let mut check_res = true;
|
||||
for (account_id, key) in accounts_keys_map {
|
||||
let expected_account_id =
|
||||
nssa::AccountId::from(&nssa::PublicKey::new_from_private_key(&key));
|
||||
nssa::AccountId::from(&nssa::PublicKey::new_from_private_key(key));
|
||||
if &expected_account_id != account_id {
|
||||
println!("{expected_account_id}, {account_id}");
|
||||
check_res = false;
|
||||
@ -56,7 +55,6 @@ impl NSSAUserData {
|
||||
check_res
|
||||
}
|
||||
|
||||
// Default only? (Marvin)
|
||||
pub fn new_with_accounts(
|
||||
default_accounts_keys: BTreeMap<nssa::AccountId, nssa::PrivateKey>,
|
||||
default_accounts_key_chains: BTreeMap<
|
||||
@ -66,7 +64,7 @@ impl NSSAUserData {
|
||||
public_key_tree: KeyTreePublic,
|
||||
private_key_tree: KeyTreePrivate,
|
||||
) -> Result<Self> {
|
||||
if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) { // TODO: modified not to use default_pub... (Marvin)
|
||||
if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) {
|
||||
anyhow::bail!(
|
||||
"Key transaction pairing check not satisfied, there are public account_ids, which are not derived from keys"
|
||||
);
|
||||
@ -114,7 +112,7 @@ impl NSSAUserData {
|
||||
self.default_pub_account_signing_keys
|
||||
.get(&account_id)
|
||||
.or_else(|| self.public_key_tree.get_node(account_id).map(Into::into))
|
||||
} // TODO: dependent on whether keycard is not; part I care about is get-node() (Marvin)
|
||||
}
|
||||
|
||||
/// Generated new private key for privacy preserving transactions.
|
||||
///
|
||||
|
||||
@ -14,12 +14,8 @@ impl WitnessSet {
|
||||
|
||||
let signatures_and_public_keys = signatures
|
||||
.iter()
|
||||
.zip( pub_keys.iter())
|
||||
.map(|(sig,key)| {
|
||||
(
|
||||
sig.clone(), key.clone()
|
||||
)
|
||||
})
|
||||
.zip(pub_keys.iter())
|
||||
.map(|(sig, key)| (sig.clone(), key.clone()))
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
|
||||
@ -56,7 +56,9 @@ impl WalletChainStore {
|
||||
.expect("Malformed persistent account data, must have private root");
|
||||
|
||||
let mut public_tree = KeyTreePublic::new_from_root(match public_root {
|
||||
PersistentAccountData::Public(data) => data.data.expect("Expect valid public account keys"), //TODO: Marvin
|
||||
PersistentAccountData::Public(data) => {
|
||||
data.data.expect("Expect valid public account keys")
|
||||
}
|
||||
_ => unreachable!(),
|
||||
});
|
||||
let mut private_tree = KeyTreePrivate::new_from_root(match private_root {
|
||||
@ -67,7 +69,11 @@ impl WalletChainStore {
|
||||
for pers_acc_data in persistent_accounts {
|
||||
match pers_acc_data {
|
||||
PersistentAccountData::Public(data) => {
|
||||
public_tree.insert(data.account_id, data.chain_index, data.data.expect("Expect valid public account keys")); //TODO: Marvin
|
||||
public_tree.insert(
|
||||
data.account_id,
|
||||
data.chain_index,
|
||||
data.data.expect("Expect valid public account keys"),
|
||||
);
|
||||
}
|
||||
PersistentAccountData::Private(data) => {
|
||||
private_tree.insert(data.account_id, data.chain_index, data.data);
|
||||
|
||||
@ -20,7 +20,8 @@ use log::info;
|
||||
use nssa::{
|
||||
Account, AccountId, PrivacyPreservingTransaction,
|
||||
privacy_preserving_transaction::{
|
||||
circuit::ProgramWithDependencies, message::EncryptedAccountData,
|
||||
circuit::{ProgramWithDependencies, Proof},
|
||||
message::EncryptedAccountData,
|
||||
},
|
||||
};
|
||||
use nssa_core::{
|
||||
@ -413,12 +414,8 @@ impl WalletCore {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let witness_set =
|
||||
nssa::privacy_preserving_transaction::witness_set::WitnessSet::for_message(
|
||||
&message,
|
||||
proof,
|
||||
&acc_manager.public_account_auth(),
|
||||
);
|
||||
let witness_set = Self::sign_privacy_message(&message, &proof, &acc_manager)
|
||||
.expect("Expect a valid witness set");
|
||||
let tx = PrivacyPreservingTransaction::new(message, witness_set);
|
||||
|
||||
let shared_secrets: Vec<_> = private_account_keys
|
||||
@ -550,4 +547,41 @@ impl WalletCore {
|
||||
pub const fn config_overrides(&self) -> &Option<WalletConfigOverrides> {
|
||||
&self.config_overrides
|
||||
}
|
||||
|
||||
pub fn sign_public_message(
|
||||
wallet: &Self,
|
||||
message: &nssa::public_transaction::Message,
|
||||
account_ids: &[AccountId],
|
||||
) -> Result<nssa::public_transaction::WitnessSet, ExecutionFailureKind> {
|
||||
let mut private_keys = Vec::new();
|
||||
|
||||
for &account_id in account_ids {
|
||||
let key = wallet
|
||||
.storage
|
||||
.user_data
|
||||
.get_pub_account_signing_key(account_id)
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
private_keys.push(key);
|
||||
}
|
||||
|
||||
Ok(nssa::public_transaction::WitnessSet::for_message(
|
||||
message,
|
||||
&private_keys,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn sign_privacy_message(
|
||||
message: &nssa::privacy_preserving_transaction::Message,
|
||||
proof: &Proof,
|
||||
acc_manager: &privacy_preserving_tx::AccountManager,
|
||||
) -> Result<nssa::privacy_preserving_transaction::witness_set::WitnessSet, ExecutionFailureKind>
|
||||
{
|
||||
Ok(
|
||||
nssa::privacy_preserving_transaction::witness_set::WitnessSet::for_message(
|
||||
message,
|
||||
proof.clone(),
|
||||
&acc_manager.public_account_auth(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ use nssa::{
|
||||
use sequencer_service_rpc::RpcClient as _;
|
||||
|
||||
use super::NativeTokenTransfer;
|
||||
use crate::ExecutionFailureKind;
|
||||
use crate::{ExecutionFailureKind, WalletCore};
|
||||
|
||||
impl NativeTokenTransfer<'_> {
|
||||
pub async fn send_public_transfer(
|
||||
@ -26,22 +26,17 @@ impl NativeTokenTransfer<'_> {
|
||||
let account_ids = vec![from, to];
|
||||
let program_id = Program::authenticated_transfer_program().id();
|
||||
|
||||
let mut sign_ids = Vec::new();
|
||||
sign_ids.push(from);
|
||||
|
||||
let mut nonces = self
|
||||
.0
|
||||
.get_accounts_nonces(vec![from])
|
||||
.await
|
||||
.map_err(ExecutionFailureKind::SequencerError)?;
|
||||
|
||||
let mut private_keys = Vec::new();
|
||||
let from_signing_key = self.0.storage.user_data.get_pub_account_signing_key(from);
|
||||
let Some(from_signing_key) = from_signing_key else {
|
||||
return Err(ExecutionFailureKind::KeyNotFoundError);
|
||||
};
|
||||
private_keys.push(from_signing_key);
|
||||
|
||||
let to_signing_key = self.0.storage.user_data.get_pub_account_signing_key(to);
|
||||
if let Some(to_signing_key) = to_signing_key {
|
||||
private_keys.push(to_signing_key);
|
||||
if let Some(_to_signing_key) = to_signing_key {
|
||||
sign_ids.push(to);
|
||||
let to_nonces = self
|
||||
.0
|
||||
.get_accounts_nonces(vec![to])
|
||||
@ -56,7 +51,9 @@ impl NativeTokenTransfer<'_> {
|
||||
|
||||
let message =
|
||||
Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap();
|
||||
let witness_set = WitnessSet::for_message(&message, &private_keys);
|
||||
|
||||
let witness_set = WalletCore::sign_public_message(self.0, &message, &sign_ids)
|
||||
.expect("Expect a valid signature");
|
||||
|
||||
let tx = PublicTransaction::new(message, witness_set);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user