fix conflicts from merging main

This commit is contained in:
jonesmarvin8 2026-03-17 19:16:09 -04:00
parent 8dd5037e28
commit ba8fdf4f29
31 changed files with 124 additions and 1494 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -52,7 +52,7 @@ impl From<nssa_core::account::Account> for Account {
program_owner: program_owner.into(),
balance,
data: data.into(),
nonce: Nonce(nonce.0),
nonce,
}
}
}
@ -72,7 +72,7 @@ impl TryFrom<Account> for nssa_core::account::Account {
program_owner: program_owner.into(),
balance,
data: data.try_into()?,
nonce: nssa_core::account::Nonce(nonce.0),
nonce,
})
}
}
@ -250,7 +250,7 @@ impl From<nssa::public_transaction::Message> for PublicMessage {
Self {
program_id: program_id.into(),
account_ids: account_ids.into_iter().map(Into::into).collect(),
nonces: nonces.iter().map(|x| Nonce(x.0)).collect(),
nonces,
instruction_data,
}
}
@ -267,10 +267,7 @@ impl From<PublicMessage> for nssa::public_transaction::Message {
Self::new_preserialized(
program_id.into(),
account_ids.into_iter().map(Into::into).collect(),
nonces
.iter()
.map(|x| nssa_core::account::Nonce(x.0))
.collect(),
nonces,
instruction_data,
)
}
@ -288,7 +285,7 @@ impl From<nssa::privacy_preserving_transaction::message::Message> for PrivacyPre
} = value;
Self {
public_account_ids: public_account_ids.into_iter().map(Into::into).collect(),
nonces: nonces.iter().map(|x| Nonce(x.0)).collect(),
nonces,
public_post_states: public_post_states.into_iter().map(Into::into).collect(),
encrypted_private_post_states: encrypted_private_post_states
.into_iter()
@ -317,10 +314,7 @@ impl TryFrom<PrivacyPreservingMessage> for nssa::privacy_preserving_transaction:
} = value;
Ok(Self {
public_account_ids: public_account_ids.into_iter().map(Into::into).collect(),
nonces: nonces
.iter()
.map(|x| nssa_core::account::Nonce(x.0))
.collect(),
nonces,
public_post_states: public_post_states
.into_iter()
.map(TryInto::try_into)

View File

@ -14,8 +14,6 @@ use serde_with::{DeserializeFromStr, SerializeDisplay};
#[cfg(feature = "convert")]
mod convert;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct Nonce(pub u128);
mod base64 {
use base64::prelude::{BASE64_STANDARD, Engine as _};
use serde::{Deserialize as _, Deserializer, Serialize as _, Serializer};

View File

@ -27,7 +27,7 @@ use nssa::{
};
use nssa_core::{
MembershipProof, NullifierPublicKey,
account::{AccountWithMetadata, Nonce, data::Data},
account::{AccountWithMetadata, data::Data},
encryption::ViewingPublicKey,
};
use tokio::test;
@ -216,7 +216,7 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
let sender_pre = AccountWithMetadata::new(
Account {
balance: 100,
nonce: Nonce(0xdeadbeef),
nonce: 0xdead_beef,
program_owner: program.id(),
data: Data::default(),
},
@ -250,6 +250,7 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
vec![sender_pre, recipient_pre],
Program::serialize_instruction(balance_to_move).unwrap(),
vec![1, 2],
vec![0xdead_beef1, 0xdead_beef2],
vec![
(sender_npk.clone(), sender_ss),
(recipient_npk.clone(), recipient_ss),

View File

@ -68,6 +68,7 @@ pub fn execute_and_prove(
pre_states: Vec<AccountWithMetadata>,
instruction_data: InstructionData,
visibility_mask: Vec<u8>,
private_account_nonces: Vec<u128>,
private_account_keys: Vec<(NullifierPublicKey, SharedSecretKey)>,
private_account_nsks: Vec<NullifierSecretKey>,
private_account_membership_proofs: Vec<Option<MembershipProof>>,
@ -126,6 +127,7 @@ pub fn execute_and_prove(
let circuit_input = PrivacyPreservingCircuitInput {
program_outputs,
visibility_mask,
private_account_nonces,
private_account_keys,
private_account_nsks,
private_account_membership_proofs,
@ -175,7 +177,7 @@ mod tests {
use nssa_core::{
Commitment, DUMMY_COMMITMENT_HASH, EncryptionScheme, Nullifier,
account::{Account, AccountId, AccountWithMetadata, Nonce, data::Data},
account::{Account, AccountId, AccountWithMetadata, data::Data},
};
use super::*;
@ -213,14 +215,14 @@ mod tests {
let expected_sender_post = Account {
program_owner: program.id(),
balance: 100 - balance_to_move,
nonce: 0u128.into(),
nonce: 0,
data: Data::default(),
};
let expected_recipient_post = Account {
program_owner: program.id(),
balance: balance_to_move,
nonce: Nonce::private_account_nonce_init(&recipient_keys.npk()),
nonce: 0xdead_beef,
data: Data::default(),
};
@ -233,6 +235,7 @@ mod tests {
vec![sender, recipient],
Program::serialize_instruction(balance_to_move).unwrap(),
vec![0, 2],
vec![0xdead_beef],
vec![(recipient_keys.npk(), shared_secret)],
vec![],
vec![None],
@ -266,11 +269,10 @@ mod tests {
let sender_keys = test_private_account_keys_1();
let recipient_keys = test_private_account_keys_2();
let sender_nonce = Nonce(0xdeadbeef);
let sender_pre = AccountWithMetadata::new(
Account {
balance: 100,
nonce: sender_nonce,
nonce: 0xdead_beef,
program_owner: program.id(),
data: Data::default(),
},
@ -305,13 +307,13 @@ mod tests {
let expected_private_account_1 = Account {
program_owner: program.id(),
balance: 100 - balance_to_move,
nonce: sender_nonce.private_account_nonce_increment(&sender_keys.nsk),
nonce: 0xdead_beef1,
..Default::default()
};
let expected_private_account_2 = Account {
program_owner: program.id(),
balance: balance_to_move,
nonce: Nonce::private_account_nonce_init(&recipient_keys.npk()),
nonce: 0xdead_beef2,
..Default::default()
};
let expected_new_commitments = vec![

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ base58.workspace = true
base64.workspace = true
borsh.workspace = true
hex.workspace = true
rand.workspace = true
itertools.workspace = true
sha2.workspace = true
futures.workspace = true

View File

@ -1,9 +1,11 @@
use std::{collections::HashMap, path::PathBuf, str::FromStr};
use std::{collections::HashMap, path::PathBuf, str::FromStr as _};
use anyhow::Result;
use base58::ToBase58;
use anyhow::{Context as _, Result};
use base58::ToBase58 as _;
use key_protocol::key_protocol_core::NSSAUserData;
use nssa::Account;
use nssa_core::account::Nonce;
use rand::{RngCore as _, rngs::OsRng};
use serde::Serialize;
use crate::{
@ -14,6 +16,39 @@ use crate::{
},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccountPrivacyKind {
Public,
Private,
}
/// Human-readable representation of an account.
#[derive(Serialize)]
pub(crate) struct HumanReadableAccount {
balance: u128,
program_owner: String,
data: String,
nonce: u128,
}
impl From<Account> for HumanReadableAccount {
fn from(account: Account) -> Self {
let program_owner = account
.program_owner
.iter()
.flat_map(|n| n.to_le_bytes())
.collect::<Vec<u8>>()
.to_base58();
let data = hex::encode(account.data);
Self {
balance: account.balance,
program_owner,
data,
nonce: account.nonce,
}
}
}
/// Get home dir for wallet. Env var `NSSA_WALLET_HOME_DIR` must be set before execution to succeed.
fn get_home_nssa_var() -> Result<PathBuf> {
Ok(PathBuf::from_str(&std::env::var(HOME_DIR_ENV_VAR)?)?)
@ -23,26 +58,22 @@ fn get_home_nssa_var() -> Result<PathBuf> {
fn get_home_default_path() -> Result<PathBuf> {
std::env::home_dir()
.map(|path| path.join(".nssa").join("wallet"))
.ok_or(anyhow::anyhow!("Failed to get HOME"))
.context("Failed to get HOME")
}
/// Get home dir for wallet.
pub fn get_home() -> Result<PathBuf> {
if let Ok(home) = get_home_nssa_var() {
Ok(home)
} else {
get_home_default_path()
}
get_home_nssa_var().or_else(|_| get_home_default_path())
}
/// Fetch config path from default home
/// Fetch config path from default home.
pub fn fetch_config_path() -> Result<PathBuf> {
let home = get_home()?;
let config_path = home.join("wallet_config.json");
Ok(config_path)
}
/// Fetch path to data storage from default home
/// Fetch path to data storage from default home.
///
/// File must be created through setup beforehand.
pub fn fetch_persistent_storage_path() -> Result<PathBuf> {
@ -51,7 +82,8 @@ pub fn fetch_persistent_storage_path() -> Result<PathBuf> {
Ok(accs_path)
}
/// Produces data for storage
/// Produces data for storage.
#[must_use]
pub fn produce_data_for_storage(
user_data: &NSSAUserData,
last_synced_block: u64,
@ -92,18 +124,18 @@ pub fn produce_data_for_storage(
pub_sign_key: key.clone(),
})
.into(),
)
);
}
for (account_id, (key_chain, account)) in &user_data.default_user_private_accounts {
vec_for_storage.push(
InitialAccountData::Private(InitialAccountDataPrivate {
InitialAccountData::Private(Box::new(InitialAccountDataPrivate {
account_id: *account_id,
account: account.clone(),
key_chain: key_chain.clone(),
})
}))
.into(),
)
);
}
PersistentStorage {
@ -113,10 +145,12 @@ pub fn produce_data_for_storage(
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccountPrivacyKind {
Public,
Private,
pub(crate) fn produce_random_nonces(size: usize) -> Vec<Nonce> {
let mut result = vec![[0; 16]; size];
for bytes in &mut result {
OsRng.fill_bytes(bytes);
}
result.into_iter().map(Nonce::from_le_bytes).collect()
}
pub(crate) fn parse_addr_with_privacy_prefix(
@ -124,12 +158,12 @@ pub(crate) fn parse_addr_with_privacy_prefix(
) -> Result<(String, AccountPrivacyKind)> {
if account_base58.starts_with("Public/") {
Ok((
account_base58.strip_prefix("Public/").unwrap().to_string(),
account_base58.strip_prefix("Public/").unwrap().to_owned(),
AccountPrivacyKind::Public,
))
} else if account_base58.starts_with("Private/") {
Ok((
account_base58.strip_prefix("Private/").unwrap().to_string(),
account_base58.strip_prefix("Private/").unwrap().to_owned(),
AccountPrivacyKind::Private,
))
} else {
@ -137,54 +171,12 @@ pub(crate) fn parse_addr_with_privacy_prefix(
}
}
/// Human-readable representation of an account.
#[derive(Serialize)]
pub(crate) struct HumanReadableAccount {
balance: u128,
program_owner: String,
data: String,
nonce: u128,
}
impl From<Account> for HumanReadableAccount {
fn from(account: Account) -> Self {
let program_owner = account
.program_owner
.iter()
.flat_map(|n| n.to_le_bytes())
.collect::<Vec<u8>>()
.to_base58();
let data = hex::encode(account.data);
Self {
balance: account.balance,
program_owner,
data,
nonce: account.nonce.0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_home_get_env_var() {
unsafe {
std::env::set_var(HOME_DIR_ENV_VAR, "/path/to/configs");
}
let home = get_home().unwrap();
assert_eq!(PathBuf::from_str("/path/to/configs").unwrap(), home);
unsafe {
std::env::remove_var(HOME_DIR_ENV_VAR);
}
}
#[test]
fn test_addr_parse_with_privacy() {
fn addr_parse_with_privacy() {
let addr_base58 = "Public/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
let (_, addr_kind) = parse_addr_with_privacy_prefix(addr_base58).unwrap();

View File

@ -32,7 +32,7 @@ use tokio::io::AsyncWriteExt as _;
use crate::{
config::{PersistentStorage, WalletConfigOverrides},
helperfunctions::produce_data_for_storage,
helperfunctions::{produce_data_for_storage, produce_random_nonces},
poller::TxPoller,
};
@ -364,6 +364,7 @@ impl WalletCore {
pre_states,
instruction_data,
acc_manager.visibility_mask().to_vec(),
produce_random_nonces(private_account_keys.len()),
private_account_keys
.iter()
.map(|keys| (keys.npk.clone(), keys.ssk))

View File

@ -80,10 +80,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new(
program.id(),
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.unwrap();
@ -190,10 +187,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new(
program.id(),
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.unwrap();
@ -280,10 +274,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new(
program.id(),
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.unwrap();
@ -365,10 +356,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new(
program.id(),
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.unwrap();

View File

@ -29,16 +29,8 @@ impl NativeTokenTransfer<'_> {
let account_ids = vec![from, to];
let program_id = Program::authenticated_transfer_program().id();
let message = Message::try_new(
program_id,
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
balance_to_move,
)
.unwrap();
let message =
Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap();
let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from);
@ -69,16 +61,7 @@ impl NativeTokenTransfer<'_> {
let instruction: u128 = 0;
let account_ids = vec![from];
let program_id = Program::authenticated_transfer_program().id();
let message = Message::try_new(
program_id,
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction,
)
.unwrap();
let message = Message::try_new(program_id, account_ids, nonces, instruction).unwrap();
let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from);

View File

@ -141,10 +141,7 @@ impl Token<'_> {
let message = nssa::public_transaction::Message::try_new(
program_id,
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.unwrap();
@ -345,10 +342,7 @@ impl Token<'_> {
let message = nssa::public_transaction::Message::try_new(
Program::token().id(),
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.expect("Instruction should serialize");
@ -478,10 +472,7 @@ impl Token<'_> {
let message = nssa::public_transaction::Message::try_new(
Program::token().id(),
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
nonces,
instruction,
)
.unwrap();