mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-25 08:33:08 +00:00
update tests
This commit is contained in:
parent
0b8b1c89b8
commit
c6aa0c41b6
12
README.md
12
README.md
@ -362,10 +362,10 @@ wallet account new private
|
||||
# Output:
|
||||
Generated new account with account_id Private/HacPU3hakLYzWtSqUPw6TUr8fqoMieVWovsUR6sJf7cL
|
||||
With npk e6366f79d026c8bd64ae6b3d601f0506832ec682ab54897f205fffe64ec0d951
|
||||
With ipk 02ddc96d0eb56e00ce14994cfdaec5ae1f76244180a919545983156e3519940a17
|
||||
With vpk 02ddc96d0eb56e00ce14994cfdaec5ae1f76244180a919545983156e3519940a17
|
||||
```
|
||||
|
||||
For now, focus only on the account id. Ignore the `npk` and `ipk` values. These are the Nullifier public key and the Viewing public key. They are stored locally in the wallet and are used internally to build privacy-preserving transactions.
|
||||
For now, focus only on the account id. Ignore the `npk` and `vpk` values. These are the Nullifier public key and the Viewing public key. They are stored locally in the wallet and are used internally to build privacy-preserving transactions.
|
||||
Also, the account id for private accounts is derived from the `npk` value. But we won't need them now.
|
||||
|
||||
Just like public accounts, new private accounts start out uninitialized:
|
||||
@ -439,16 +439,16 @@ wallet account new private
|
||||
# Output:
|
||||
Generated new account with account_id Private/AukXPRBmrYVqoqEW2HTs7N3hvTn3qdNFDcxDHVr5hMm5
|
||||
With npk 0c95ebc4b3830f53da77bb0b80a276a776cdcf6410932acc718dcdb3f788a00e
|
||||
With ipk 039fd12a3674a880d3e917804129141e4170d419d1f9e28a3dcf979c1f2369cb72
|
||||
With vpk 039fd12a3674a880d3e917804129141e4170d419d1f9e28a3dcf979c1f2369cb72
|
||||
```
|
||||
|
||||
Now we'll ignore the private account ID and focus on the `npk` and `ipk` values. We'll need this to send tokens to a foreign private account. Syntax is very similar.
|
||||
Now we'll ignore the private account ID and focus on the `npk` and `vpk` values. We'll need this to send tokens to a foreign private account. Syntax is very similar.
|
||||
|
||||
```bash
|
||||
wallet auth-transfer send \
|
||||
--from Public/Ev1JprP9BmhbFVQyBcbznU8bAXcwrzwRoPTetXdQPAWS \
|
||||
--to-npk 0c95ebc4b3830f53da77bb0b80a276a776cdcf6410932acc718dcdb3f788a00e \
|
||||
--to-ipk 039fd12a3674a880d3e917804129141e4170d419d1f9e28a3dcf979c1f2369cb72 \
|
||||
--to-vpk 039fd12a3674a880d3e917804129141e4170d419d1f9e28a3dcf979c1f2369cb72 \
|
||||
--amount 3
|
||||
```
|
||||
|
||||
@ -557,7 +557,7 @@ wallet account new private
|
||||
# Output:
|
||||
Generated new account with account_id Private/HMRHZdPw4pbyPVZHNGrV6K5AA95wACFsHTRST84fr3CF
|
||||
With npk 6a2dfe433cf28e525aa0196d719be3c16146f7ee358ca39595323f94fde38f93
|
||||
With ipk 03d59abf4bee974cc12ddb44641c19f0b5441fef39191f047c988c29a77252a577
|
||||
With vpk 03d59abf4bee974cc12ddb44641c19f0b5441fef39191f047c988c29a77252a577
|
||||
```
|
||||
|
||||
And we use them to create the token.
|
||||
|
||||
@ -97,7 +97,7 @@ _wallet_auth_transfer() {
|
||||
'--from[Source account ID]:from_account:_wallet_account_ids' \
|
||||
'--to[Destination account ID (for owned accounts)]:to_account:_wallet_account_ids' \
|
||||
'--to-npk[Destination nullifier public key (for foreign private accounts)]:npk:' \
|
||||
'--to-ipk[Destination viewing public key (for foreign private accounts)]:ipk:' \
|
||||
'--to-vpk[Destination viewing public key (for foreign private accounts)]:vpk:' \
|
||||
'--amount[Amount of native tokens to send]:amount:'
|
||||
;;
|
||||
esac
|
||||
@ -163,7 +163,7 @@ _wallet_account() {
|
||||
get)
|
||||
_arguments \
|
||||
'(-r --raw)'{-r,--raw}'[Get raw account data]' \
|
||||
'(-k --keys)'{-k,--keys}'[Display keys (pk for public accounts, npk/ipk for private accounts)]' \
|
||||
'(-k --keys)'{-k,--keys}'[Display keys (pk for public accounts, npk/vpk for private accounts)]' \
|
||||
'(-a --account-id)'{-a,--account-id}'[Account ID to query]:account_id:_wallet_account_ids'
|
||||
;;
|
||||
list|ls)
|
||||
@ -249,7 +249,7 @@ _wallet_token() {
|
||||
'--from[Source holding account ID]:from_account:_wallet_account_ids' \
|
||||
'--to[Destination holding account ID (for owned accounts)]:to_account:_wallet_account_ids' \
|
||||
'--to-npk[Destination nullifier public key (for foreign private accounts)]:npk:' \
|
||||
'--to-ipk[Destination viewing public key (for foreign private accounts)]:ipk:' \
|
||||
'--to-vpk[Destination viewing public key (for foreign private accounts)]:vpk:' \
|
||||
'--amount[Amount of tokens to send]:amount:'
|
||||
;;
|
||||
burn)
|
||||
@ -263,7 +263,7 @@ _wallet_token() {
|
||||
'--definition[Definition account ID]:definition_account:_wallet_account_ids' \
|
||||
'--holder[Holder account ID (for owned accounts)]:holder_account:_wallet_account_ids' \
|
||||
'--holder-npk[Holder nullifier public key (for foreign private accounts)]:npk:' \
|
||||
'--holder-ipk[Holder viewing public key (for foreign private accounts)]:ipk:' \
|
||||
'--holder-vpk[Holder viewing public key (for foreign private accounts)]:vpk:' \
|
||||
'--amount[Amount of tokens to mint]:amount:'
|
||||
;;
|
||||
esac
|
||||
|
||||
@ -219,7 +219,7 @@ This is the account that the program will claim and write data into.
|
||||
let bytecode: Vec<u8> = std::fs::read(program_path).unwrap();
|
||||
let program = Program::new(bytecode).unwrap();
|
||||
```
|
||||
The Risc0 ELF is read from disk and wrapped in a Program object, which can be used to compute the program ID. The ID is used by the node to identify which program is invoked by the transaction.
|
||||
The Risc0 ELF is read from dvsk and wrapped in a Program object, which can be used to compute the program ID. The ID is used by the node to identify which program is invoked by the transaction.
|
||||
|
||||
|
||||
### 4. Preparing the instruction data
|
||||
|
||||
@ -173,7 +173,7 @@
|
||||
75,
|
||||
20
|
||||
],
|
||||
"incoming_viewing_secret_key": [
|
||||
"viewing_secret_key": [
|
||||
251,
|
||||
201,
|
||||
22,
|
||||
@ -206,40 +206,6 @@
|
||||
153,
|
||||
182,
|
||||
158
|
||||
],
|
||||
"outgoing_viewing_secret_key": [
|
||||
25,
|
||||
67,
|
||||
121,
|
||||
76,
|
||||
175,
|
||||
100,
|
||||
30,
|
||||
198,
|
||||
105,
|
||||
123,
|
||||
49,
|
||||
169,
|
||||
75,
|
||||
178,
|
||||
75,
|
||||
210,
|
||||
100,
|
||||
143,
|
||||
210,
|
||||
243,
|
||||
228,
|
||||
243,
|
||||
21,
|
||||
18,
|
||||
36,
|
||||
84,
|
||||
164,
|
||||
186,
|
||||
139,
|
||||
113,
|
||||
214,
|
||||
12
|
||||
]
|
||||
},
|
||||
"nullifer_public_key": [
|
||||
@ -276,7 +242,7 @@
|
||||
228,
|
||||
97
|
||||
],
|
||||
"incoming_viewing_public_key": [
|
||||
"viewing_public_key": [
|
||||
3,
|
||||
235,
|
||||
139,
|
||||
@ -402,7 +368,7 @@
|
||||
164,
|
||||
13
|
||||
],
|
||||
"incoming_viewing_secret_key": [
|
||||
"viewing_secret_key": [
|
||||
193,
|
||||
181,
|
||||
14,
|
||||
@ -435,40 +401,6 @@
|
||||
105,
|
||||
104,
|
||||
231
|
||||
],
|
||||
"outgoing_viewing_secret_key": [
|
||||
20,
|
||||
170,
|
||||
220,
|
||||
108,
|
||||
41,
|
||||
23,
|
||||
155,
|
||||
217,
|
||||
247,
|
||||
190,
|
||||
175,
|
||||
168,
|
||||
247,
|
||||
34,
|
||||
105,
|
||||
134,
|
||||
114,
|
||||
74,
|
||||
104,
|
||||
91,
|
||||
211,
|
||||
62,
|
||||
126,
|
||||
13,
|
||||
130,
|
||||
100,
|
||||
241,
|
||||
214,
|
||||
250,
|
||||
236,
|
||||
38,
|
||||
150
|
||||
]
|
||||
},
|
||||
"nullifer_public_key": [
|
||||
@ -505,7 +437,7 @@
|
||||
140,
|
||||
47
|
||||
],
|
||||
"incoming_viewing_public_key": [
|
||||
"viewing_public_key": [
|
||||
2,
|
||||
181,
|
||||
98,
|
||||
|
||||
@ -104,7 +104,7 @@ async fn amm_public() -> Result<()> {
|
||||
&recipient_account_id_1.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -130,7 +130,7 @@ async fn amm_public() -> Result<()> {
|
||||
&recipient_account_id_2.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ async fn private_transfer_to_owned_account() -> Result<()> {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: Some(format_private_account_id(&to.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -60,13 +60,13 @@ async fn private_transfer_to_foreign_account() -> Result<()> {
|
||||
let from: AccountId = ACC_SENDER_PRIVATE.parse()?;
|
||||
let to_npk = NullifierPublicKey([42; 32]);
|
||||
let to_npk_string = hex::encode(to_npk.0);
|
||||
let to_ipk = Secp256k1Point::from_scalar(to_npk.0);
|
||||
let to_vpk = Secp256k1Point::from_scalar(to_npk.0);
|
||||
|
||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: None,
|
||||
to_npk: Some(to_npk_string),
|
||||
to_ipk: Some(hex::encode(to_ipk.0)),
|
||||
to_vpk: Some(hex::encode(to_vpk.0)),
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -114,7 +114,7 @@ async fn deshielded_transfer_to_public_account() -> Result<()> {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: Some(format_public_account_id(&to.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -172,12 +172,12 @@ async fn private_transfer_to_owned_account_using_claiming_path() -> Result<()> {
|
||||
.cloned()
|
||||
.context("Failed to get private account")?;
|
||||
|
||||
// Send to this account using claiming path (using npk and ipk instead of account ID)
|
||||
// Send to this account using claiming path (using npk and vpk instead of account ID)
|
||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: None,
|
||||
to_npk: Some(hex::encode(to_keys.nullifer_public_key.0)),
|
||||
to_ipk: Some(hex::encode(to_keys.incoming_viewing_public_key.0)),
|
||||
to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)),
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -225,7 +225,7 @@ async fn shielded_transfer_to_owned_private_account() -> Result<()> {
|
||||
from: format_public_account_id(&from.to_string()),
|
||||
to: Some(format_private_account_id(&to.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -263,14 +263,14 @@ async fn shielded_transfer_to_foreign_account() -> Result<()> {
|
||||
|
||||
let to_npk = NullifierPublicKey([42; 32]);
|
||||
let to_npk_string = hex::encode(to_npk.0);
|
||||
let to_ipk = Secp256k1Point::from_scalar(to_npk.0);
|
||||
let to_vpk = Secp256k1Point::from_scalar(to_npk.0);
|
||||
let from: AccountId = ACC_SENDER.parse()?;
|
||||
|
||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||
from: format_public_account_id(&from.to_string()),
|
||||
to: None,
|
||||
to_npk: Some(to_npk_string),
|
||||
to_ipk: Some(hex::encode(to_ipk.0)),
|
||||
to_vpk: Some(hex::encode(to_vpk.0)),
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -335,12 +335,12 @@ async fn private_transfer_to_owned_account_continuous_run_path() -> Result<()> {
|
||||
.cloned()
|
||||
.context("Failed to get private account")?;
|
||||
|
||||
// Send transfer using nullifier and incoming viewing public keys
|
||||
// Send transfer using nullifier and viewing public keys
|
||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: None,
|
||||
to_npk: Some(hex::encode(to_keys.nullifer_public_key.0)),
|
||||
to_ipk: Some(hex::encode(to_keys.incoming_viewing_public_key.0)),
|
||||
to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)),
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ async fn successful_transfer_to_existing_account() -> Result<()> {
|
||||
from: format_public_account_id(ACC_SENDER),
|
||||
to: Some(format_public_account_id(ACC_RECEIVER)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -76,7 +76,7 @@ pub async fn successful_transfer_to_new_account() -> Result<()> {
|
||||
from: format_public_account_id(ACC_SENDER),
|
||||
to: Some(format_public_account_id(&new_persistent_account_id)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -112,7 +112,7 @@ async fn failed_transfer_with_insufficient_balance() -> Result<()> {
|
||||
from: format_public_account_id(ACC_SENDER),
|
||||
to: Some(format_public_account_id(ACC_RECEIVER)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 1000000,
|
||||
});
|
||||
|
||||
@ -150,7 +150,7 @@ async fn two_consecutive_successful_transfers() -> Result<()> {
|
||||
from: format_public_account_id(ACC_SENDER),
|
||||
to: Some(format_public_account_id(ACC_RECEIVER)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
@ -182,7 +182,7 @@ async fn two_consecutive_successful_transfers() -> Result<()> {
|
||||
from: format_public_account_id(ACC_SENDER),
|
||||
to: Some(format_public_account_id(ACC_RECEIVER)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ async fn restore_keys_from_seed() -> Result<()> {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: Some(format_private_account_id(&to_account_id1.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 100,
|
||||
});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
@ -60,7 +60,7 @@ async fn restore_keys_from_seed() -> Result<()> {
|
||||
from: format_private_account_id(&from.to_string()),
|
||||
to: Some(format_private_account_id(&to_account_id2.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 101,
|
||||
});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
@ -96,7 +96,7 @@ async fn restore_keys_from_seed() -> Result<()> {
|
||||
from: format_public_account_id(&from.to_string()),
|
||||
to: Some(format_public_account_id(&to_account_id3.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 102,
|
||||
});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
@ -106,7 +106,7 @@ async fn restore_keys_from_seed() -> Result<()> {
|
||||
from: format_public_account_id(&from.to_string()),
|
||||
to: Some(format_public_account_id(&to_account_id4.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 103,
|
||||
});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
@ -169,7 +169,7 @@ async fn restore_keys_from_seed() -> Result<()> {
|
||||
from: format_private_account_id(&to_account_id1.to_string()),
|
||||
to: Some(format_private_account_id(&to_account_id2.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 10,
|
||||
});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
@ -178,7 +178,7 @@ async fn restore_keys_from_seed() -> Result<()> {
|
||||
from: format_public_account_id(&to_account_id3.to_string()),
|
||||
to: Some(format_public_account_id(&to_account_id4.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 11,
|
||||
});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
|
||||
@ -113,7 +113,7 @@ async fn create_and_transfer_public_token() -> Result<()> {
|
||||
from: format_public_account_id(&supply_account_id.to_string()),
|
||||
to: Some(format_public_account_id(&recipient_account_id.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -185,7 +185,7 @@ async fn create_and_transfer_public_token() -> Result<()> {
|
||||
definition: format_public_account_id(&definition_account_id.to_string()),
|
||||
holder: Some(format_public_account_id(&recipient_account_id.to_string())),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
holder_vpk: None,
|
||||
amount: 10,
|
||||
};
|
||||
|
||||
@ -309,7 +309,7 @@ async fn create_and_transfer_token_with_private_supply() -> Result<()> {
|
||||
from: format_private_account_id(&supply_account_id.to_string()),
|
||||
to: Some(format_private_account_id(&recipient_account_id.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -477,7 +477,7 @@ async fn create_token_with_private_definition() -> Result<()> {
|
||||
&recipient_account_id_public.to_string(),
|
||||
)),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
holder_vpk: None,
|
||||
amount: 10,
|
||||
};
|
||||
|
||||
@ -516,7 +516,7 @@ async fn create_token_with_private_definition() -> Result<()> {
|
||||
&recipient_account_id_private.to_string(),
|
||||
)),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
holder_vpk: None,
|
||||
amount: 5,
|
||||
};
|
||||
|
||||
@ -631,7 +631,7 @@ async fn create_token_with_private_definition_and_supply() -> Result<()> {
|
||||
from: format_private_account_id(&supply_account_id.to_string()),
|
||||
to: Some(format_private_account_id(&recipient_account_id.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -732,7 +732,7 @@ async fn shielded_token_transfer() -> Result<()> {
|
||||
from: format_public_account_id(&supply_account_id.to_string()),
|
||||
to: Some(format_private_account_id(&recipient_account_id.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -829,7 +829,7 @@ async fn deshielded_token_transfer() -> Result<()> {
|
||||
from: format_private_account_id(&supply_account_id.to_string()),
|
||||
to: Some(format_public_account_id(&recipient_account_id.to_string())),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
to_vpk: None,
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -935,7 +935,7 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> {
|
||||
definition: format_private_account_id(&definition_account_id.to_string()),
|
||||
holder: None,
|
||||
holder_npk: Some(hex::encode(holder_keys.nullifer_public_key.0)),
|
||||
holder_ipk: Some(hex::encode(holder_keys.incoming_viewing_public_key.0)),
|
||||
holder_vpk: Some(hex::encode(holder_keys.viewing_public_key.0)),
|
||||
amount: 9,
|
||||
};
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ use nssa::{
|
||||
use nssa_core::{
|
||||
MembershipProof, NullifierPublicKey,
|
||||
account::{AccountWithMetadata, data::Data},
|
||||
encryption::IncomingViewingPublicKey,
|
||||
encryption::ViewingPublicKey,
|
||||
};
|
||||
use sequencer_core::config::{AccountInitialData, CommitmentsInitialData, SequencerConfig};
|
||||
use tokio::test;
|
||||
@ -197,8 +197,8 @@ impl TpsTestManager {
|
||||
fn build_privacy_transaction() -> PrivacyPreservingTransaction {
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender_nsk = [1; 32];
|
||||
let sender_isk = [99; 32];
|
||||
let sender_ipk = IncomingViewingPublicKey::from_scalar(sender_isk);
|
||||
let sender_vsk = [99; 32];
|
||||
let sender_vpk = ViewingPublicKey::from_scalar(sender_vsk);
|
||||
let sender_npk = NullifierPublicKey::from(&sender_nsk);
|
||||
let sender_pre = AccountWithMetadata::new(
|
||||
Account {
|
||||
@ -211,18 +211,18 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
|
||||
AccountId::from(&sender_npk),
|
||||
);
|
||||
let recipient_nsk = [2; 32];
|
||||
let recipient_isk = [99; 32];
|
||||
let recipient_ipk = IncomingViewingPublicKey::from_scalar(recipient_isk);
|
||||
let recipient_vsk = [99; 32];
|
||||
let recipient_vpk = ViewingPublicKey::from_scalar(recipient_vsk);
|
||||
let recipient_npk = NullifierPublicKey::from(&recipient_nsk);
|
||||
let recipient_pre =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::from(&recipient_npk));
|
||||
|
||||
let eph_holder_from = EphemeralKeyHolder::new(&sender_npk);
|
||||
let sender_ss = eph_holder_from.calculate_shared_secret_sender(&sender_ipk);
|
||||
let sender_ss = eph_holder_from.calculate_shared_secret_sender(&sender_vpk);
|
||||
let sender_epk = eph_holder_from.generate_ephemeral_public_key();
|
||||
|
||||
let eph_holder_to = EphemeralKeyHolder::new(&recipient_npk);
|
||||
let recipient_ss = eph_holder_to.calculate_shared_secret_sender(&recipient_ipk);
|
||||
let recipient_ss = eph_holder_to.calculate_shared_secret_sender(&recipient_vpk);
|
||||
let recipient_epk = eph_holder_from.generate_ephemeral_public_key();
|
||||
|
||||
let balance_to_move: u128 = 1;
|
||||
@ -251,8 +251,8 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
|
||||
vec![],
|
||||
vec![],
|
||||
vec![
|
||||
(sender_npk, sender_ipk, sender_epk),
|
||||
(recipient_npk, recipient_ipk, recipient_epk),
|
||||
(sender_npk, sender_vpk, sender_epk),
|
||||
(recipient_npk, recipient_vpk, recipient_epk),
|
||||
],
|
||||
output,
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use nssa_core::{
|
||||
NullifierPublicKey, SharedSecretKey,
|
||||
encryption::{EphemeralPublicKey, EphemeralSecretKey, IncomingViewingPublicKey},
|
||||
encryption::{EphemeralPublicKey, EphemeralSecretKey, ViewingPublicKey},
|
||||
};
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
use sha2::Digest;
|
||||
@ -13,7 +13,7 @@ pub struct EphemeralKeyHolder {
|
||||
}
|
||||
|
||||
pub fn produce_one_sided_shared_secret_receiver(
|
||||
ipk: &IncomingViewingPublicKey,
|
||||
ipk: &ViewingPublicKey,
|
||||
) -> (SharedSecretKey, EphemeralPublicKey) {
|
||||
let mut esk = [0; 32];
|
||||
OsRng.fill_bytes(&mut esk);
|
||||
@ -42,11 +42,8 @@ impl EphemeralKeyHolder {
|
||||
|
||||
pub fn calculate_shared_secret_sender(
|
||||
&self,
|
||||
receiver_incoming_viewing_public_key: &IncomingViewingPublicKey,
|
||||
receiver_viewing_public_key: &ViewingPublicKey,
|
||||
) -> SharedSecretKey {
|
||||
SharedSecretKey::new(
|
||||
&self.ephemeral_secret_key,
|
||||
receiver_incoming_viewing_public_key,
|
||||
)
|
||||
SharedSecretKey::new(&self.ephemeral_secret_key, receiver_viewing_public_key)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use common::HashType;
|
||||
use k256::{Scalar, elliptic_curve::PrimeField};
|
||||
use nssa_core::{NullifierPublicKey, encryption::IncomingViewingPublicKey};
|
||||
use nssa_core::{NullifierPublicKey, encryption::ViewingPublicKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, digest::FixedOutput};
|
||||
|
||||
@ -20,7 +20,7 @@ pub struct ChildKeysPrivate {
|
||||
|
||||
impl KeyNode for ChildKeysPrivate {
|
||||
fn root(seed: [u8; 64]) -> Self {
|
||||
let hash_value = hmac_sha512::HMAC::mac(seed, b"NSSA_master_priv");
|
||||
let hash_value = hmac_sha512::HMAC::mac(seed, b"LEE_master_priv");
|
||||
|
||||
let ssk = SecretSpendingKey(
|
||||
*hash_value
|
||||
@ -31,35 +31,34 @@ impl KeyNode for ChildKeysPrivate {
|
||||
.last_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get last 32");
|
||||
|
||||
//TODO: check these generations
|
||||
let nsk = ssk.generate_nullifier_secret_key();
|
||||
let isk = ssk.generate_incoming_viewing_secret_key();
|
||||
let ovk = ssk.generate_outgoing_viewing_secret_key();
|
||||
let vsk = ssk.generate_viewing_secret_key();
|
||||
|
||||
let npk: NullifierPublicKey = {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
hasher.update("NSSA_keys");
|
||||
hasher.update("LEE/keys");
|
||||
hasher.update(nsk);
|
||||
hasher.update([7u8]);
|
||||
hasher.update([0u8; 22]);
|
||||
hasher.update([0u8; 23]);
|
||||
|
||||
NullifierPublicKey {
|
||||
0: <HashType>::from(hasher.finalize_fixed()),
|
||||
}
|
||||
};
|
||||
|
||||
let ipk = IncomingViewingPublicKey::from_scalar(isk);
|
||||
let vpk = ViewingPublicKey::from_scalar(vsk);
|
||||
|
||||
Self {
|
||||
value: (
|
||||
KeyChain {
|
||||
secret_spending_key: ssk,
|
||||
nullifer_public_key: npk,
|
||||
incoming_viewing_public_key: ipk,
|
||||
viewing_public_key: vpk,
|
||||
private_key_holder: PrivateKeyHolder {
|
||||
nullifier_secret_key: nsk,
|
||||
incoming_viewing_secret_key: isk,
|
||||
outgoing_viewing_secret_key: ovk,
|
||||
viewing_secret_key: vsk,
|
||||
},
|
||||
},
|
||||
nssa::Account::default(),
|
||||
@ -70,28 +69,14 @@ impl KeyNode for ChildKeysPrivate {
|
||||
}
|
||||
|
||||
fn nth_child(&self, cci: u32) -> Self {
|
||||
// parent_pt = ovk_par + scalar(nsk_par)*isk_par
|
||||
let parent_pt = Scalar::from_repr(
|
||||
self.value
|
||||
.0
|
||||
.private_key_holder
|
||||
.outgoing_viewing_secret_key
|
||||
.into(),
|
||||
)
|
||||
.expect("Key generated as scalar, must be valid representation")
|
||||
+ Scalar::from_repr(self.value.0.private_key_holder.nullifier_secret_key.into())
|
||||
let parent_pt =
|
||||
Scalar::from_repr(self.value.0.private_key_holder.nullifier_secret_key.into())
|
||||
.expect("Key generated as scalar, must be valid representation")
|
||||
* Scalar::from_repr(
|
||||
self.value
|
||||
.0
|
||||
.private_key_holder
|
||||
.incoming_viewing_secret_key
|
||||
.into(),
|
||||
)
|
||||
.expect("Key generated as scalar, must be valid representation");
|
||||
|
||||
* Scalar::from_repr(self.value.0.private_key_holder.viewing_secret_key.into())
|
||||
.expect("Key generated as scalar, must be valid representation");
|
||||
let mut input = vec![];
|
||||
input.extend_from_slice(b"NSSA_seed_priv");
|
||||
|
||||
input.extend_from_slice(b"LEE_seed_priv");
|
||||
input.extend_from_slice(&parent_pt.to_bytes());
|
||||
input.extend_from_slice(&cci.to_le_bytes());
|
||||
|
||||
@ -107,13 +92,12 @@ impl KeyNode for ChildKeysPrivate {
|
||||
.expect("hash_value is 64 bytes, must be safe to get last 32");
|
||||
|
||||
let nsk = ssk.generate_child_nullifier_secret_key(cci);
|
||||
let isk = ssk.generate_child_incoming_viewing_secret_key(cci);
|
||||
let ovk = ssk.generate_child_outgoing_viewing_secret_key(cci);
|
||||
let vsk = ssk.generate_child_viewing_secret_key(cci);
|
||||
|
||||
let npk: NullifierPublicKey = {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
hasher.update("NSSAchain");
|
||||
hasher.update("LEE/chain");
|
||||
hasher.update(nsk);
|
||||
hasher.update([7u8]);
|
||||
hasher.update([0u8; 22]);
|
||||
@ -123,18 +107,17 @@ impl KeyNode for ChildKeysPrivate {
|
||||
}
|
||||
};
|
||||
|
||||
let ipk = IncomingViewingPublicKey::from_scalar(isk);
|
||||
let vpk = ViewingPublicKey::from_scalar(vsk);
|
||||
|
||||
Self {
|
||||
value: (
|
||||
KeyChain {
|
||||
secret_spending_key: ssk,
|
||||
nullifer_public_key: npk,
|
||||
incoming_viewing_public_key: ipk,
|
||||
viewing_public_key: vpk,
|
||||
private_key_holder: PrivateKeyHolder {
|
||||
nullifier_secret_key: nsk,
|
||||
incoming_viewing_secret_key: isk,
|
||||
outgoing_viewing_secret_key: ovk,
|
||||
viewing_secret_key: vsk,
|
||||
},
|
||||
},
|
||||
nssa::Account::default(),
|
||||
@ -171,17 +154,10 @@ impl<'a> From<&'a mut ChildKeysPrivate> for &'a mut (KeyChain, nssa::Account) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::process::Child;
|
||||
|
||||
use k256::Secp256k1;
|
||||
use nssa_core::{NullifierSecretKey, encryption::shared_key_derivation::Secp256k1Point};
|
||||
|
||||
use crate::key_management::{
|
||||
self,
|
||||
secret_holders::{IncomingViewingSecretKey, OutgoingViewingSecretKey},
|
||||
};
|
||||
use nssa_core::{NullifierPublicKey, NullifierSecretKey};
|
||||
|
||||
use super::*;
|
||||
use crate::key_management::{self, secret_holders::ViewingSecretKey};
|
||||
|
||||
#[test]
|
||||
fn test_master_key_generation() {
|
||||
@ -195,103 +171,82 @@ mod tests {
|
||||
let keys = ChildKeysPrivate::root(seed);
|
||||
|
||||
let expected_ssk: SecretSpendingKey = key_management::secret_holders::SecretSpendingKey([
|
||||
189, 102, 14, 63, 41, 116, 229, 119, 41, 59, 225, 169, 205, 21, 50, 214, 222, 67, 109,
|
||||
126, 107, 153, 57, 118, 29, 239, 79, 162, 95, 13, 197, 170,
|
||||
246, 79, 26, 124, 135, 95, 52, 51, 201, 27, 48, 194, 2, 144, 51, 219, 245, 128, 139,
|
||||
222, 42, 195, 105, 33, 115, 97, 186, 0, 97, 14, 218, 191,
|
||||
]);
|
||||
|
||||
let expected_ccc = [
|
||||
5, 205, 75, 227, 45, 88, 53, 168, 99, 138, 145, 94, 195, 176, 178, 118, 213, 129, 64,
|
||||
70, 105, 60, 27, 230, 73, 86, 110, 203, 28, 60, 191, 172,
|
||||
56, 114, 70, 249, 67, 169, 206, 9, 192, 11, 180, 168, 149, 129, 42, 95, 43, 157, 130,
|
||||
111, 13, 5, 195, 75, 20, 255, 162, 85, 40, 251, 8, 168,
|
||||
];
|
||||
|
||||
let expected_nsk: NullifierSecretKey = [
|
||||
181, 144, 216, 101, 27, 177, 89, 140, 223, 128, 200, 3, 208, 144, 250, 242, 145, 25,
|
||||
197, 107, 74, 187, 99, 58, 253, 254, 82, 16, 221, 9, 202, 99,
|
||||
154, 102, 103, 5, 34, 235, 227, 13, 22, 182, 226, 11, 7, 67, 110, 162, 99, 193, 174,
|
||||
34, 234, 19, 222, 2, 22, 12, 163, 252, 88, 11, 0, 163,
|
||||
];
|
||||
|
||||
let expected_npk: NullifierPublicKey = nssa_core::NullifierPublicKey([
|
||||
161, 65, 163, 239, 194, 99, 30, 5, 6, 117, 116, 154, 218, 50, 72, 221, 222, 187, 36,
|
||||
25, 18, 98, 242, 140, 117, 18, 183, 150, 235, 207, 150, 205,
|
||||
7, 123, 125, 191, 233, 183, 201, 4, 20, 214, 155, 210, 45, 234, 27, 240, 194, 111, 97,
|
||||
247, 155, 113, 122, 246, 192, 0, 70, 61, 76, 71, 70, 2,
|
||||
]);
|
||||
let expected_isk: IncomingViewingSecretKey = [
|
||||
153, 108, 251, 220, 218, 41, 212, 54, 175, 61, 198, 247, 82, 127, 215, 160, 226, 26,
|
||||
154, 96, 41, 126, 247, 136, 206, 187, 233, 193, 47, 159, 169, 71,
|
||||
let expected_vsk: ViewingSecretKey = [
|
||||
155, 90, 54, 75, 228, 130, 68, 201, 129, 251, 180, 195, 250, 64, 34, 230, 241, 204,
|
||||
216, 50, 149, 156, 10, 67, 208, 74, 9, 10, 47, 59, 50, 202,
|
||||
];
|
||||
let expected_ovk: OutgoingViewingSecretKey = [
|
||||
169, 133, 157, 26, 10, 196, 45, 254, 82, 146, 180, 151, 193, 152, 84, 92, 252, 249,
|
||||
166, 192, 43, 93, 79, 153, 205, 56, 208, 5, 116, 151, 252, 78,
|
||||
];
|
||||
let expected_ipk_as_bytes: [u8; 33] = [
|
||||
2, 14, 226, 128, 146, 254, 56, 61, 3, 24, 211, 151, 194, 41, 166, 67, 146, 0, 73, 4,
|
||||
140, 184, 244, 200, 43, 159, 141, 234, 90, 90, 145, 53, 251,
|
||||
|
||||
let expected_vpk_as_bytes: [u8; 33] = [
|
||||
2, 191, 99, 102, 114, 40, 131, 109, 166, 8, 222, 186, 107, 29, 156, 106, 206, 96, 127,
|
||||
80, 170, 66, 217, 79, 38, 80, 11, 74, 147, 123, 221, 159, 166,
|
||||
];
|
||||
|
||||
assert!(expected_ssk == keys.value.0.secret_spending_key);
|
||||
assert!(expected_ccc == keys.ccc);
|
||||
assert!(expected_nsk == keys.value.0.private_key_holder.nullifier_secret_key);
|
||||
assert!(expected_npk == keys.value.0.nullifer_public_key);
|
||||
assert!(expected_isk == keys.value.0.private_key_holder.incoming_viewing_secret_key);
|
||||
assert!(expected_ovk == keys.value.0.private_key_holder.outgoing_viewing_secret_key);
|
||||
assert!(expected_ipk_as_bytes == keys.value.0.incoming_viewing_public_key.to_bytes());
|
||||
assert!(expected_vsk == keys.value.0.private_key_holder.viewing_secret_key);
|
||||
assert!(expected_vpk_as_bytes == keys.value.0.viewing_public_key.to_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_child_keys_generation() {
|
||||
let seed: [u8; 64] = [
|
||||
88, 189, 37, 237, 199, 125, 151, 226, 69, 153, 165, 113, 191, 69, 188, 221, 9, 34, 173,
|
||||
134, 61, 109, 34, 103, 121, 39, 237, 14, 107, 194, 24, 194, 191, 14, 237, 185, 12, 87,
|
||||
22, 227, 38, 71, 17, 144, 251, 118, 217, 115, 33, 222, 201, 61, 203, 246, 121, 214, 6,
|
||||
187, 148, 92, 44, 253, 210, 37,
|
||||
252, 56, 204, 83, 232, 123, 209, 188, 187, 167, 39, 213, 71, 39, 58, 65, 125, 134, 255,
|
||||
49, 43, 108, 92, 53, 173, 164, 94, 142, 150, 74, 21, 163, 43, 144, 226, 87, 199, 18,
|
||||
129, 223, 176, 198, 5, 150, 157, 70, 210, 254, 14, 105, 89, 191, 246, 27, 52, 170, 56,
|
||||
114, 39, 38, 118, 197, 205, 225,
|
||||
];
|
||||
|
||||
let root_node = ChildKeysPrivate::root(seed);
|
||||
let child_node = ChildKeysPrivate::nth_child(&root_node, 42u32);
|
||||
|
||||
let expected_ccc: [u8; 32] = [
|
||||
131, 6, 100, 230, 202, 63, 5, 206, 158, 3, 81, 177, 221, 107, 27, 194, 192, 38, 104,
|
||||
87, 23, 98, 107, 1, 78, 19, 216, 195, 63, 66, 13, 172,
|
||||
145, 59, 225, 32, 54, 168, 14, 45, 60, 253, 57, 202, 31, 86, 142, 234, 51, 57, 154, 88,
|
||||
132, 200, 92, 191, 220, 144, 42, 184, 108, 35, 226, 146,
|
||||
];
|
||||
|
||||
let expected_nsk: NullifierSecretKey = [
|
||||
118, 91, 48, 86, 184, 103, 178, 151, 169, 126, 198, 254, 177, 130, 48, 175, 250, 255,
|
||||
19, 89, 122, 133, 216, 80, 101, 155, 243, 186, 104, 161, 35, 208,
|
||||
82, 238, 58, 161, 96, 201, 25, 193, 53, 101, 100, 173, 183, 167, 165, 141, 252, 214,
|
||||
214, 3, 176, 186, 62, 112, 56, 54, 6, 197, 29, 178, 88, 214,
|
||||
];
|
||||
|
||||
let expected_npk: NullifierPublicKey = nssa_core::NullifierPublicKey([
|
||||
122, 13, 105, 25, 155, 46, 105, 20, 93, 112, 97, 78, 198, 186, 227, 74, 13, 213, 135,
|
||||
215, 254, 96, 115, 228, 137, 139, 35, 73, 67, 123, 48, 48,
|
||||
40, 104, 183, 124, 101, 11, 61, 45, 140, 53, 3, 155, 139, 134, 105, 108, 60, 229, 165,
|
||||
195, 187, 246, 14, 88, 76, 69, 137, 154, 29, 113, 205, 153,
|
||||
]);
|
||||
|
||||
let expected_isk: IncomingViewingSecretKey = [
|
||||
38, 172, 52, 226, 190, 69, 120, 123, 231, 65, 88, 97, 125, 56, 120, 225, 253, 198, 133,
|
||||
145, 84, 118, 182, 80, 188, 210, 146, 91, 197, 48, 39, 36,
|
||||
let expected_vsk: ViewingSecretKey = [
|
||||
14, 114, 31, 116, 147, 114, 62, 111, 176, 100, 211, 68, 38, 47, 250, 34, 224, 249, 25,
|
||||
40, 35, 37, 237, 224, 161, 58, 228, 154, 44, 162, 128, 138,
|
||||
];
|
||||
let expected_ovk: OutgoingViewingSecretKey = [
|
||||
105, 26, 128, 5, 91, 183, 81, 224, 125, 217, 93, 173, 162, 129, 46, 85, 164, 215, 169,
|
||||
236, 202, 12, 49, 31, 199, 130, 108, 159, 68, 196, 58, 96,
|
||||
];
|
||||
let expected_ipk_as_bytes: [u8; 33] = [
|
||||
2, 249, 186, 99, 214, 150, 242, 196, 122, 68, 237, 126, 129, 14, 189, 238, 132, 31,
|
||||
228, 94, 224, 25, 248, 77, 250, 198, 122, 24, 232, 38, 147, 225, 158,
|
||||
let expected_vpk_as_bytes: [u8; 33] = [
|
||||
3, 243, 200, 219, 91, 171, 128, 76, 173, 117, 255, 212, 233, 71, 205, 204, 89, 104, 92,
|
||||
187, 249, 154, 197, 102, 241, 66, 15, 55, 194, 189, 16, 124, 176,
|
||||
];
|
||||
|
||||
assert!(expected_ccc == child_node.ccc);
|
||||
assert!(expected_nsk == child_node.value.0.private_key_holder.nullifier_secret_key);
|
||||
assert!(expected_npk == child_node.value.0.nullifer_public_key);
|
||||
assert!(
|
||||
expected_isk
|
||||
== child_node
|
||||
.value
|
||||
.0
|
||||
.private_key_holder
|
||||
.incoming_viewing_secret_key
|
||||
);
|
||||
assert!(expected_ipk_as_bytes == child_node.value.0.incoming_viewing_public_key.to_bytes());
|
||||
assert!(
|
||||
expected_ovk
|
||||
== child_node
|
||||
.value
|
||||
.0
|
||||
.private_key_holder
|
||||
.outgoing_viewing_secret_key
|
||||
);
|
||||
assert!(expected_vsk == child_node.value.0.private_key_holder.viewing_secret_key);
|
||||
assert!(expected_vpk_as_bytes == child_node.value.0.viewing_public_key.to_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use nssa_core::{
|
||||
NullifierPublicKey, SharedSecretKey,
|
||||
encryption::{EphemeralPublicKey, IncomingViewingPublicKey},
|
||||
encryption::{EphemeralPublicKey, ViewingPublicKey},
|
||||
};
|
||||
use secret_holders::{PrivateKeyHolder, SecretSpendingKey, SeedHolder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -17,7 +17,7 @@ pub struct KeyChain {
|
||||
pub secret_spending_key: SecretSpendingKey,
|
||||
pub private_key_holder: PrivateKeyHolder,
|
||||
pub nullifer_public_key: NullifierPublicKey,
|
||||
pub incoming_viewing_public_key: IncomingViewingPublicKey,
|
||||
pub viewing_public_key: ViewingPublicKey,
|
||||
}
|
||||
|
||||
impl KeyChain {
|
||||
@ -30,13 +30,13 @@ impl KeyChain {
|
||||
let private_key_holder = secret_spending_key.produce_private_key_holder();
|
||||
|
||||
let nullifer_public_key = private_key_holder.generate_nullifier_public_key();
|
||||
let incoming_viewing_public_key = private_key_holder.generate_incoming_viewing_public_key();
|
||||
let viewing_public_key = private_key_holder.generate_viewing_public_key();
|
||||
|
||||
Self {
|
||||
secret_spending_key,
|
||||
private_key_holder,
|
||||
nullifer_public_key,
|
||||
incoming_viewing_public_key,
|
||||
viewing_public_key,
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,13 +49,13 @@ impl KeyChain {
|
||||
let private_key_holder = secret_spending_key.produce_private_key_holder();
|
||||
|
||||
let nullifer_public_key = private_key_holder.generate_nullifier_public_key();
|
||||
let incoming_viewing_public_key = private_key_holder.generate_incoming_viewing_public_key();
|
||||
let viewing_public_key = private_key_holder.generate_viewing_public_key();
|
||||
|
||||
Self {
|
||||
secret_spending_key,
|
||||
private_key_holder,
|
||||
nullifer_public_key,
|
||||
incoming_viewing_public_key,
|
||||
viewing_public_key,
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,9 +64,7 @@ impl KeyChain {
|
||||
ephemeral_public_key_sender: EphemeralPublicKey,
|
||||
) -> SharedSecretKey {
|
||||
SharedSecretKey::new(
|
||||
&self
|
||||
.secret_spending_key
|
||||
.generate_incoming_viewing_secret_key(),
|
||||
&self.secret_spending_key.generate_viewing_secret_key(),
|
||||
&ephemeral_public_key_sender,
|
||||
)
|
||||
}
|
||||
@ -115,7 +113,7 @@ mod tests {
|
||||
let utxo_secret_key_holder = top_secret_key_holder.produce_private_key_holder();
|
||||
|
||||
let nullifer_public_key = utxo_secret_key_holder.generate_nullifier_public_key();
|
||||
let viewing_public_key = utxo_secret_key_holder.generate_incoming_viewing_public_key();
|
||||
let viewing_public_key = utxo_secret_key_holder.generate_viewing_public_key();
|
||||
|
||||
let pub_account_signing_key = nssa::PrivateKey::new_os_random();
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use bip39::Mnemonic;
|
||||
use common::HashType;
|
||||
use nssa_core::{
|
||||
NullifierPublicKey, NullifierSecretKey,
|
||||
encryption::{IncomingViewingPublicKey, Scalar},
|
||||
encryption::{Scalar, ViewingPublicKey},
|
||||
};
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -18,11 +18,11 @@ pub struct SeedHolder {
|
||||
pub(crate) seed: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
/// Secret spending key object. Can produce `PrivateKeyHolder` objects.
|
||||
pub struct SecretSpendingKey(pub(crate) [u8; 32]);
|
||||
|
||||
pub type IncomingViewingSecretKey = Scalar;
|
||||
pub type ViewingSecretKey = Scalar;
|
||||
pub type OutgoingViewingSecretKey = Scalar;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@ -30,8 +30,7 @@ pub type OutgoingViewingSecretKey = Scalar;
|
||||
/// recepient.
|
||||
pub struct PrivateKeyHolder {
|
||||
pub nullifier_secret_key: NullifierSecretKey,
|
||||
pub(crate) incoming_viewing_secret_key: IncomingViewingSecretKey,
|
||||
pub outgoing_viewing_secret_key: OutgoingViewingSecretKey,
|
||||
pub(crate) viewing_secret_key: ViewingSecretKey,
|
||||
}
|
||||
|
||||
impl SeedHolder {
|
||||
@ -78,32 +77,21 @@ impl SecretSpendingKey {
|
||||
pub fn generate_nullifier_secret_key(&self) -> NullifierSecretKey {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
hasher.update("NSSA_keys");
|
||||
hasher.update("LEE/keys");
|
||||
hasher.update(self.0);
|
||||
hasher.update([1u8]);
|
||||
hasher.update([0u8; 22]);
|
||||
hasher.update([0u8; 23]);
|
||||
|
||||
<NullifierSecretKey>::from(hasher.finalize_fixed())
|
||||
}
|
||||
|
||||
pub fn generate_incoming_viewing_secret_key(&self) -> IncomingViewingSecretKey {
|
||||
pub fn generate_viewing_secret_key(&self) -> ViewingSecretKey {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
hasher.update("NSSA_keys");
|
||||
hasher.update("LEE/keys");
|
||||
hasher.update(self.0);
|
||||
hasher.update([2u8]);
|
||||
hasher.update([0u8; 22]);
|
||||
|
||||
<HashType>::from(hasher.finalize_fixed())
|
||||
}
|
||||
|
||||
pub fn generate_outgoing_viewing_secret_key(&self) -> OutgoingViewingSecretKey {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
hasher.update("NSSA_keys");
|
||||
hasher.update(self.0);
|
||||
hasher.update([3u8]);
|
||||
hasher.update([0u8; 22]);
|
||||
hasher.update([0u8; 23]);
|
||||
|
||||
<HashType>::from(hasher.finalize_fixed())
|
||||
}
|
||||
@ -111,14 +99,13 @@ impl SecretSpendingKey {
|
||||
pub fn produce_private_key_holder(&self) -> PrivateKeyHolder {
|
||||
PrivateKeyHolder {
|
||||
nullifier_secret_key: self.generate_nullifier_secret_key(),
|
||||
incoming_viewing_secret_key: self.generate_incoming_viewing_secret_key(),
|
||||
outgoing_viewing_secret_key: self.generate_outgoing_viewing_secret_key(),
|
||||
viewing_secret_key: self.generate_viewing_secret_key(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_child_nullifier_secret_key(&self, cci: u32) -> NullifierSecretKey {
|
||||
let mut key = vec![];
|
||||
key.extend_from_slice(b"NSSAchain");
|
||||
key.extend_from_slice(b"LEE/chain");
|
||||
|
||||
let mut input = vec![];
|
||||
|
||||
@ -134,9 +121,9 @@ impl SecretSpendingKey {
|
||||
.expect("hash_value is 64 bytes, must be safe to get first 32")
|
||||
}
|
||||
|
||||
pub fn generate_child_incoming_viewing_secret_key(&self, cci: u32) -> IncomingViewingSecretKey {
|
||||
pub fn generate_child_viewing_secret_key(&self, cci: u32) -> ViewingSecretKey {
|
||||
let mut key = vec![];
|
||||
key.extend_from_slice(b"NSSAchain");
|
||||
key.extend_from_slice(b"LEE/chain");
|
||||
|
||||
let mut input = vec![];
|
||||
|
||||
@ -151,42 +138,15 @@ impl SecretSpendingKey {
|
||||
.first_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get first 32")
|
||||
}
|
||||
|
||||
pub fn generate_child_outgoing_viewing_secret_key(&self, cci: u32) -> OutgoingViewingSecretKey {
|
||||
let mut key = vec![];
|
||||
key.extend_from_slice(b"NSSAchain");
|
||||
|
||||
let mut input = vec![];
|
||||
|
||||
input.extend_from_slice(&self.0);
|
||||
input.extend_from_slice(&[3u8]);
|
||||
input.extend_from_slice(&cci.to_le_bytes());
|
||||
input.extend_from_slice(&[0u8; 22]);
|
||||
|
||||
let hash_value = hmac_sha512::HMAC::mac(input, key);
|
||||
|
||||
*hash_value
|
||||
.first_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get first 32")
|
||||
}
|
||||
}
|
||||
|
||||
impl PrivateKeyHolder {
|
||||
pub fn generate_nullifier_public_key(&self) -> NullifierPublicKey {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
hasher.update("NSSA_keys");
|
||||
hasher.update(self.nullifier_secret_key);
|
||||
hasher.update([7u8]);
|
||||
hasher.update([0u8; 22]);
|
||||
|
||||
NullifierPublicKey {
|
||||
0: <HashType>::from(hasher.finalize_fixed()),
|
||||
}
|
||||
(&self.nullifier_secret_key).into()
|
||||
}
|
||||
|
||||
pub fn generate_incoming_viewing_public_key(&self) -> IncomingViewingPublicKey {
|
||||
IncomingViewingPublicKey::from_scalar(self.incoming_viewing_secret_key)
|
||||
pub fn generate_viewing_public_key(&self) -> ViewingPublicKey {
|
||||
ViewingPublicKey::from_scalar(self.viewing_secret_key)
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,6 +154,14 @@ impl PrivateKeyHolder {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
//TODO? are these necessary?
|
||||
#[test]
|
||||
fn seed_generation_test() {
|
||||
let seed_holder = SeedHolder::new_os_random();
|
||||
|
||||
assert_eq!(seed_holder.seed.len(), 64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ssk_generation_test() {
|
||||
let seed_holder = SeedHolder::new_os_random();
|
||||
@ -211,18 +179,7 @@ mod tests {
|
||||
|
||||
let top_secret_key_holder = seed_holder.produce_top_secret_key_holder();
|
||||
|
||||
let _ = top_secret_key_holder.generate_incoming_viewing_secret_key();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ovs_generation_test() {
|
||||
let seed_holder = SeedHolder::new_os_random();
|
||||
|
||||
assert_eq!(seed_holder.seed.len(), 64);
|
||||
|
||||
let top_secret_key_holder = seed_holder.produce_top_secret_key_holder();
|
||||
|
||||
let _ = top_secret_key_holder.generate_outgoing_viewing_secret_key();
|
||||
let _ = top_secret_key_holder.generate_viewing_secret_key();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub mod shared_key_derivation;
|
||||
|
||||
#[cfg(feature = "host")]
|
||||
pub use shared_key_derivation::{EphemeralPublicKey, EphemeralSecretKey, IncomingViewingPublicKey};
|
||||
pub use shared_key_derivation::{EphemeralPublicKey, EphemeralSecretKey, ViewingPublicKey};
|
||||
|
||||
use crate::{Commitment, account::Account};
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ impl Secp256k1Point {
|
||||
|
||||
pub type EphemeralSecretKey = Scalar;
|
||||
pub type EphemeralPublicKey = Secp256k1Point;
|
||||
pub type IncomingViewingPublicKey = Secp256k1Point;
|
||||
pub type ViewingPublicKey = Secp256k1Point;
|
||||
impl From<&EphemeralSecretKey> for EphemeralPublicKey {
|
||||
fn from(value: &EphemeralSecretKey) -> Self {
|
||||
Secp256k1Point::from_scalar(*value)
|
||||
|
||||
@ -213,7 +213,7 @@ mod tests {
|
||||
let expected_sender_pre = sender.clone();
|
||||
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &recipient_keys.ivk());
|
||||
let shared_secret = SharedSecretKey::new(&esk, &recipient_keys.vpk());
|
||||
|
||||
let (output, proof) = execute_and_prove(
|
||||
vec![sender, recipient],
|
||||
@ -306,10 +306,10 @@ mod tests {
|
||||
];
|
||||
|
||||
let esk_1 = [3; 32];
|
||||
let shared_secret_1 = SharedSecretKey::new(&esk_1, &sender_keys.ivk());
|
||||
let shared_secret_1 = SharedSecretKey::new(&esk_1, &sender_keys.vpk());
|
||||
|
||||
let esk_2 = [5; 32];
|
||||
let shared_secret_2 = SharedSecretKey::new(&esk_2, &recipient_keys.ivk());
|
||||
let shared_secret_2 = SharedSecretKey::new(&esk_2, &recipient_keys.vpk());
|
||||
|
||||
let (output, proof) = execute_and_prove(
|
||||
vec![sender_pre.clone(), recipient],
|
||||
|
||||
@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize};
|
||||
use nssa_core::{
|
||||
Commitment, CommitmentSetDigest, Nullifier, NullifierPublicKey, PrivacyPreservingCircuitOutput,
|
||||
account::{Account, Nonce},
|
||||
encryption::{Ciphertext, EphemeralPublicKey, IncomingViewingPublicKey},
|
||||
encryption::{Ciphertext, EphemeralPublicKey, ViewingPublicKey},
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
@ -21,10 +21,10 @@ impl EncryptedAccountData {
|
||||
fn new(
|
||||
ciphertext: Ciphertext,
|
||||
npk: NullifierPublicKey,
|
||||
ivk: IncomingViewingPublicKey,
|
||||
vpk: ViewingPublicKey,
|
||||
epk: EphemeralPublicKey,
|
||||
) -> Self {
|
||||
let view_tag = Self::compute_view_tag(npk, ivk);
|
||||
let view_tag = Self::compute_view_tag(npk, vpk);
|
||||
Self {
|
||||
ciphertext,
|
||||
epk,
|
||||
@ -32,12 +32,12 @@ impl EncryptedAccountData {
|
||||
}
|
||||
}
|
||||
|
||||
/// Computes the tag as the first byte of SHA256("/NSSA/v0.2/ViewTag/" || Npk || Ivk)
|
||||
pub fn compute_view_tag(npk: NullifierPublicKey, ivk: IncomingViewingPublicKey) -> ViewTag {
|
||||
/// Computes the tag as the first byte of SHA256("/NSSA/v0.2/ViewTag/" || Npk || vpk)
|
||||
pub fn compute_view_tag(npk: NullifierPublicKey, vpk: ViewingPublicKey) -> ViewTag {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"/NSSA/v0.2/ViewTag/");
|
||||
hasher.update(npk.to_byte_array());
|
||||
hasher.update(ivk.to_bytes());
|
||||
hasher.update(vpk.to_bytes());
|
||||
let digest: [u8; 32] = hasher.finalize().into();
|
||||
digest[0]
|
||||
}
|
||||
@ -59,7 +59,7 @@ impl Message {
|
||||
nonces: Vec<Nonce>,
|
||||
public_keys: Vec<(
|
||||
NullifierPublicKey,
|
||||
IncomingViewingPublicKey,
|
||||
ViewingPublicKey,
|
||||
EphemeralPublicKey,
|
||||
)>,
|
||||
output: PrivacyPreservingCircuitOutput,
|
||||
@ -74,8 +74,8 @@ impl Message {
|
||||
.ciphertexts
|
||||
.into_iter()
|
||||
.zip(public_keys)
|
||||
.map(|(ciphertext, (npk, ivk, epk))| {
|
||||
EncryptedAccountData::new(ciphertext, npk, ivk, epk)
|
||||
.map(|(ciphertext, (npk, vpk, epk))| {
|
||||
EncryptedAccountData::new(ciphertext, npk, vpk, epk)
|
||||
})
|
||||
.collect();
|
||||
Ok(Self {
|
||||
@ -94,7 +94,7 @@ pub mod tests {
|
||||
use nssa_core::{
|
||||
Commitment, EncryptionScheme, Nullifier, NullifierPublicKey, SharedSecretKey,
|
||||
account::Account,
|
||||
encryption::{EphemeralPublicKey, IncomingViewingPublicKey},
|
||||
encryption::{EphemeralPublicKey, ViewingPublicKey},
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
@ -142,21 +142,21 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_encrypted_account_data_constructor() {
|
||||
let npk = NullifierPublicKey::from(&[1; 32]);
|
||||
let ivk = IncomingViewingPublicKey::from_scalar([2; 32]);
|
||||
let vpk = ViewingPublicKey::from_scalar([2; 32]);
|
||||
let account = Account::default();
|
||||
let commitment = Commitment::new(&npk, &account);
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &ivk);
|
||||
let shared_secret = SharedSecretKey::new(&esk, &vpk);
|
||||
let epk = EphemeralPublicKey::from_scalar(esk);
|
||||
let ciphertext = EncryptionScheme::encrypt(&account, &shared_secret, &commitment, 2);
|
||||
let encrypted_account_data =
|
||||
EncryptedAccountData::new(ciphertext.clone(), npk.clone(), ivk.clone(), epk.clone());
|
||||
EncryptedAccountData::new(ciphertext.clone(), npk.clone(), vpk.clone(), epk.clone());
|
||||
|
||||
let expected_view_tag = {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"/NSSA/v0.2/ViewTag/");
|
||||
hasher.update(npk.to_byte_array());
|
||||
hasher.update(ivk.to_bytes());
|
||||
hasher.update(vpk.to_bytes());
|
||||
let digest: [u8; 32] = hasher.finalize().into();
|
||||
digest[0]
|
||||
};
|
||||
@ -165,7 +165,7 @@ pub mod tests {
|
||||
assert_eq!(encrypted_account_data.epk, epk);
|
||||
assert_eq!(
|
||||
encrypted_account_data.view_tag,
|
||||
EncryptedAccountData::compute_view_tag(npk, ivk)
|
||||
EncryptedAccountData::compute_view_tag(npk, vpk)
|
||||
);
|
||||
assert_eq!(encrypted_account_data.view_tag, expected_view_tag);
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ pub mod tests {
|
||||
use nssa_core::{
|
||||
Commitment, Nullifier, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
|
||||
account::{Account, AccountId, AccountWithMetadata, Nonce, data::Data},
|
||||
encryption::{EphemeralPublicKey, IncomingViewingPublicKey, Scalar},
|
||||
encryption::{EphemeralPublicKey, ViewingPublicKey, Scalar},
|
||||
program::{PdaSeed, ProgramId},
|
||||
};
|
||||
|
||||
@ -818,7 +818,7 @@ pub mod tests {
|
||||
|
||||
pub struct TestPrivateKeys {
|
||||
pub nsk: NullifierSecretKey,
|
||||
pub isk: Scalar,
|
||||
pub vsk: Scalar,
|
||||
}
|
||||
|
||||
impl TestPrivateKeys {
|
||||
@ -826,22 +826,22 @@ pub mod tests {
|
||||
NullifierPublicKey::from(&self.nsk)
|
||||
}
|
||||
|
||||
pub fn ivk(&self) -> IncomingViewingPublicKey {
|
||||
IncomingViewingPublicKey::from_scalar(self.isk)
|
||||
pub fn vpk(&self) -> ViewingPublicKey {
|
||||
ViewingPublicKey::from_scalar(self.vsk)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_private_account_keys_1() -> TestPrivateKeys {
|
||||
TestPrivateKeys {
|
||||
nsk: [13; 32],
|
||||
isk: [31; 32],
|
||||
vsk: [31; 32],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_private_account_keys_2() -> TestPrivateKeys {
|
||||
TestPrivateKeys {
|
||||
nsk: [38; 32],
|
||||
isk: [83; 32],
|
||||
vsk: [83; 32],
|
||||
}
|
||||
}
|
||||
|
||||
@ -862,7 +862,7 @@ pub mod tests {
|
||||
let recipient = AccountWithMetadata::new(Account::default(), false, &recipient_keys.npk());
|
||||
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &recipient_keys.ivk());
|
||||
let shared_secret = SharedSecretKey::new(&esk, &recipient_keys.vpk());
|
||||
let epk = EphemeralPublicKey::from_scalar(esk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
@ -880,7 +880,7 @@ pub mod tests {
|
||||
let message = Message::try_from_circuit_output(
|
||||
vec![sender_keys.account_id()],
|
||||
vec![sender_nonce],
|
||||
vec![(recipient_keys.npk(), recipient_keys.ivk(), epk)],
|
||||
vec![(recipient_keys.npk(), recipient_keys.vpk(), epk)],
|
||||
output,
|
||||
)
|
||||
.unwrap();
|
||||
@ -905,11 +905,11 @@ pub mod tests {
|
||||
AccountWithMetadata::new(Account::default(), false, &recipient_keys.npk());
|
||||
|
||||
let esk_1 = [3; 32];
|
||||
let shared_secret_1 = SharedSecretKey::new(&esk_1, &sender_keys.ivk());
|
||||
let shared_secret_1 = SharedSecretKey::new(&esk_1, &sender_keys.vpk());
|
||||
let epk_1 = EphemeralPublicKey::from_scalar(esk_1);
|
||||
|
||||
let esk_2 = [3; 32];
|
||||
let shared_secret_2 = SharedSecretKey::new(&esk_2, &recipient_keys.ivk());
|
||||
let shared_secret_2 = SharedSecretKey::new(&esk_2, &recipient_keys.vpk());
|
||||
let epk_2 = EphemeralPublicKey::from_scalar(esk_2);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
@ -931,8 +931,8 @@ pub mod tests {
|
||||
vec![],
|
||||
vec![],
|
||||
vec![
|
||||
(sender_keys.npk(), sender_keys.ivk(), epk_1),
|
||||
(recipient_keys.npk(), recipient_keys.ivk(), epk_2),
|
||||
(sender_keys.npk(), sender_keys.vpk(), epk_1),
|
||||
(recipient_keys.npk(), recipient_keys.vpk(), epk_2),
|
||||
],
|
||||
output,
|
||||
)
|
||||
@ -962,7 +962,7 @@ pub mod tests {
|
||||
);
|
||||
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &sender_keys.ivk());
|
||||
let shared_secret = SharedSecretKey::new(&esk, &sender_keys.vpk());
|
||||
let epk = EphemeralPublicKey::from_scalar(esk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
@ -980,7 +980,7 @@ pub mod tests {
|
||||
let message = Message::try_from_circuit_output(
|
||||
vec![*recipient_account_id],
|
||||
vec![],
|
||||
vec![(sender_keys.npk(), sender_keys.ivk(), epk)],
|
||||
vec![(sender_keys.npk(), sender_keys.vpk(), epk)],
|
||||
output,
|
||||
)
|
||||
.unwrap();
|
||||
@ -1494,11 +1494,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1528,7 +1528,7 @@ pub mod tests {
|
||||
// Setting only one key for an execution with two private accounts.
|
||||
let private_account_keys = [(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
)];
|
||||
let result = execute_and_prove(
|
||||
vec![private_account_1, private_account_2],
|
||||
@ -1571,11 +1571,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1613,11 +1613,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
private_account_nsks.to_vec(),
|
||||
@ -1649,12 +1649,12 @@ pub mod tests {
|
||||
// First private account is the sender
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
// Second private account is the recipient
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
];
|
||||
|
||||
@ -1709,11 +1709,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1757,11 +1757,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1804,11 +1804,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1851,11 +1851,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1896,11 +1896,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -1969,11 +1969,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
vec![sender_keys.nsk],
|
||||
@ -2006,15 +2006,15 @@ pub mod tests {
|
||||
let private_account_keys = [
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[57; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[57; 32], &sender_keys.vpk()),
|
||||
),
|
||||
];
|
||||
let result = execute_and_prove(
|
||||
@ -2061,11 +2061,11 @@ pub mod tests {
|
||||
vec![
|
||||
(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[55; 32], &sender_keys.vpk()),
|
||||
),
|
||||
(
|
||||
recipient_keys.npk(),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.ivk()),
|
||||
SharedSecretKey::new(&[56; 32], &recipient_keys.vpk()),
|
||||
),
|
||||
],
|
||||
private_account_nsks.to_vec(),
|
||||
@ -2148,7 +2148,7 @@ pub mod tests {
|
||||
let visibility_mask = [1, 1];
|
||||
let private_account_nsks = [sender_keys.nsk, sender_keys.nsk];
|
||||
let private_account_membership_proofs = [Some((1, vec![])), Some((1, vec![]))];
|
||||
let shared_secret = SharedSecretKey::new(&[55; 32], &sender_keys.ivk());
|
||||
let shared_secret = SharedSecretKey::new(&[55; 32], &sender_keys.vpk());
|
||||
let result = execute_and_prove(
|
||||
vec![private_account_1.clone(), private_account_1],
|
||||
Program::serialize_instruction(100u128).unwrap(),
|
||||
@ -3985,11 +3985,11 @@ pub mod tests {
|
||||
);
|
||||
|
||||
let from_esk = [3; 32];
|
||||
let from_ss = SharedSecretKey::new(&from_esk, &from_keys.ivk());
|
||||
let from_ss = SharedSecretKey::new(&from_esk, &from_keys.vpk());
|
||||
let from_epk = EphemeralPublicKey::from_scalar(from_esk);
|
||||
|
||||
let to_esk = [3; 32];
|
||||
let to_ss = SharedSecretKey::new(&to_esk, &to_keys.ivk());
|
||||
let to_ss = SharedSecretKey::new(&to_esk, &to_keys.vpk());
|
||||
let to_epk = EphemeralPublicKey::from_scalar(to_esk);
|
||||
|
||||
let mut dependencies = HashMap::new();
|
||||
@ -4034,8 +4034,8 @@ pub mod tests {
|
||||
vec![],
|
||||
vec![],
|
||||
vec![
|
||||
(to_keys.npk(), to_keys.ivk(), to_epk),
|
||||
(from_keys.npk(), from_keys.ivk(), from_epk),
|
||||
(to_keys.npk(), to_keys.vpk(), to_epk),
|
||||
(from_keys.npk(), from_keys.vpk(), from_epk),
|
||||
],
|
||||
output,
|
||||
)
|
||||
@ -4247,7 +4247,7 @@ pub mod tests {
|
||||
|
||||
// Set up parameters for the new account
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &private_keys.ivk());
|
||||
let shared_secret = SharedSecretKey::new(&esk, &private_keys.vpk());
|
||||
let epk = EphemeralPublicKey::from_scalar(esk);
|
||||
|
||||
// Balance to initialize the account with (0 for a new account)
|
||||
@ -4272,7 +4272,7 @@ pub mod tests {
|
||||
let message = Message::try_from_circuit_output(
|
||||
vec![],
|
||||
vec![],
|
||||
vec![(private_keys.npk(), private_keys.ivk(), epk)],
|
||||
vec![(private_keys.npk(), private_keys.vpk(), epk)],
|
||||
output,
|
||||
)
|
||||
.unwrap();
|
||||
@ -4302,7 +4302,7 @@ pub mod tests {
|
||||
|
||||
// Set up parameters for claiming the new account
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &private_keys.ivk());
|
||||
let shared_secret = SharedSecretKey::new(&esk, &private_keys.vpk());
|
||||
let epk = EphemeralPublicKey::from_scalar(esk);
|
||||
|
||||
let balance: u128 = 0;
|
||||
@ -4324,7 +4324,7 @@ pub mod tests {
|
||||
let message = Message::try_from_circuit_output(
|
||||
vec![],
|
||||
vec![],
|
||||
vec![(private_keys.npk(), private_keys.ivk(), epk)],
|
||||
vec![(private_keys.npk(), private_keys.vpk(), epk)],
|
||||
output,
|
||||
)
|
||||
.unwrap();
|
||||
@ -4352,7 +4352,7 @@ pub mod tests {
|
||||
|
||||
let noop_program = Program::noop();
|
||||
let esk2 = [4; 32];
|
||||
let shared_secret2 = SharedSecretKey::new(&esk2, &private_keys.ivk());
|
||||
let shared_secret2 = SharedSecretKey::new(&esk2, &private_keys.vpk());
|
||||
|
||||
let nonce2 = 0xdeadbeef2;
|
||||
|
||||
@ -4434,7 +4434,7 @@ pub mod tests {
|
||||
vec![2],
|
||||
vec![(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[3; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[3; 32], &sender_keys.vpk()),
|
||||
)],
|
||||
vec![sender_keys.nsk],
|
||||
vec![Some((0, vec![]))],
|
||||
@ -4462,7 +4462,7 @@ pub mod tests {
|
||||
vec![2],
|
||||
vec![(
|
||||
sender_keys.npk(),
|
||||
SharedSecretKey::new(&[3; 32], &sender_keys.ivk()),
|
||||
SharedSecretKey::new(&[3; 32], &sender_keys.vpk()),
|
||||
)],
|
||||
vec![sender_keys.nsk],
|
||||
vec![Some((0, vec![]))],
|
||||
@ -4505,7 +4505,7 @@ pub mod tests {
|
||||
let instruction = (balance_to_transfer, auth_transfers.id());
|
||||
|
||||
let recipient_esk = [3; 32];
|
||||
let recipient = SharedSecretKey::new(&recipient_esk, &recipient_keys.ivk());
|
||||
let recipient = SharedSecretKey::new(&recipient_esk, &recipient_keys.vpk());
|
||||
|
||||
let mut dependencies = HashMap::new();
|
||||
dependencies.insert(auth_transfers.id(), auth_transfers);
|
||||
|
||||
@ -172,7 +172,7 @@
|
||||
75,
|
||||
20
|
||||
],
|
||||
"incoming_viewing_secret_key": [
|
||||
"viewing_secret_key": [
|
||||
251,
|
||||
201,
|
||||
22,
|
||||
@ -205,40 +205,6 @@
|
||||
153,
|
||||
182,
|
||||
158
|
||||
],
|
||||
"outgoing_viewing_secret_key": [
|
||||
25,
|
||||
67,
|
||||
121,
|
||||
76,
|
||||
175,
|
||||
100,
|
||||
30,
|
||||
198,
|
||||
105,
|
||||
123,
|
||||
49,
|
||||
169,
|
||||
75,
|
||||
178,
|
||||
75,
|
||||
210,
|
||||
100,
|
||||
143,
|
||||
210,
|
||||
243,
|
||||
228,
|
||||
243,
|
||||
21,
|
||||
18,
|
||||
36,
|
||||
84,
|
||||
164,
|
||||
186,
|
||||
139,
|
||||
113,
|
||||
214,
|
||||
12
|
||||
]
|
||||
},
|
||||
"nullifer_public_key": [
|
||||
@ -275,7 +241,7 @@
|
||||
228,
|
||||
97
|
||||
],
|
||||
"incoming_viewing_public_key": [
|
||||
"viewing_public_key": [
|
||||
3,
|
||||
235,
|
||||
139,
|
||||
@ -401,7 +367,7 @@
|
||||
164,
|
||||
13
|
||||
],
|
||||
"incoming_viewing_secret_key": [
|
||||
"viewing_secret_key": [
|
||||
193,
|
||||
181,
|
||||
14,
|
||||
@ -434,40 +400,6 @@
|
||||
105,
|
||||
104,
|
||||
231
|
||||
],
|
||||
"outgoing_viewing_secret_key": [
|
||||
20,
|
||||
170,
|
||||
220,
|
||||
108,
|
||||
41,
|
||||
23,
|
||||
155,
|
||||
217,
|
||||
247,
|
||||
190,
|
||||
175,
|
||||
168,
|
||||
247,
|
||||
34,
|
||||
105,
|
||||
134,
|
||||
114,
|
||||
74,
|
||||
104,
|
||||
91,
|
||||
211,
|
||||
62,
|
||||
126,
|
||||
13,
|
||||
130,
|
||||
100,
|
||||
241,
|
||||
214,
|
||||
250,
|
||||
236,
|
||||
38,
|
||||
150
|
||||
]
|
||||
},
|
||||
"nullifer_public_key": [
|
||||
@ -504,7 +436,7 @@
|
||||
140,
|
||||
47
|
||||
],
|
||||
"incoming_viewing_public_key": [
|
||||
"viewing_public_key": [
|
||||
2,
|
||||
181,
|
||||
98,
|
||||
|
||||
@ -20,7 +20,7 @@ pub enum AccountSubcommand {
|
||||
/// Flag to get raw account data
|
||||
#[arg(short, long)]
|
||||
raw: bool,
|
||||
/// Display keys (pk for public accounts, npk/ipk for private accounts)
|
||||
/// Display keys (pk for public accounts, npk/vpk for private accounts)
|
||||
#[arg(short, long)]
|
||||
keys: bool,
|
||||
/// Valid 32 byte base58 string with privacy prefix
|
||||
@ -99,8 +99,8 @@ impl WalletSubcommand for NewSubcommand {
|
||||
);
|
||||
println!("With npk {}", hex::encode(key.nullifer_public_key.0));
|
||||
println!(
|
||||
"With ipk {}",
|
||||
hex::encode(key.incoming_viewing_public_key.to_bytes())
|
||||
"With vpk {}",
|
||||
hex::encode(key.viewing_public_key.to_bytes())
|
||||
);
|
||||
|
||||
wallet_core.store_persistent_data().await?;
|
||||
@ -252,10 +252,7 @@ impl WalletSubcommand for AccountSubcommand {
|
||||
.ok_or(anyhow::anyhow!("Private account not found in storage"))?;
|
||||
|
||||
println!("npk {}", hex::encode(key.nullifer_public_key.0));
|
||||
println!(
|
||||
"ipk {}",
|
||||
hex::encode(key.incoming_viewing_public_key.to_bytes())
|
||||
);
|
||||
println!("vpk {}", hex::encode(key.viewing_public_key.to_bytes()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@ -399,7 +399,7 @@ impl Default for WalletConfig {
|
||||
75,
|
||||
20
|
||||
],
|
||||
"incoming_viewing_secret_key": [
|
||||
"viewing_secret_key": [
|
||||
251,
|
||||
201,
|
||||
22,
|
||||
@ -432,40 +432,6 @@ impl Default for WalletConfig {
|
||||
153,
|
||||
182,
|
||||
158
|
||||
],
|
||||
"outgoing_viewing_secret_key": [
|
||||
25,
|
||||
67,
|
||||
121,
|
||||
76,
|
||||
175,
|
||||
100,
|
||||
30,
|
||||
198,
|
||||
105,
|
||||
123,
|
||||
49,
|
||||
169,
|
||||
75,
|
||||
178,
|
||||
75,
|
||||
210,
|
||||
100,
|
||||
143,
|
||||
210,
|
||||
243,
|
||||
228,
|
||||
243,
|
||||
21,
|
||||
18,
|
||||
36,
|
||||
84,
|
||||
164,
|
||||
186,
|
||||
139,
|
||||
113,
|
||||
214,
|
||||
12
|
||||
]
|
||||
},
|
||||
"nullifer_public_key": [
|
||||
@ -502,7 +468,7 @@ impl Default for WalletConfig {
|
||||
228,
|
||||
97
|
||||
],
|
||||
"incoming_viewing_public_key": [
|
||||
"viewing_public_key": [
|
||||
3,
|
||||
235,
|
||||
139,
|
||||
@ -628,7 +594,7 @@ impl Default for WalletConfig {
|
||||
164,
|
||||
13
|
||||
],
|
||||
"incoming_viewing_secret_key": [
|
||||
"viewing_secret_key": [
|
||||
193,
|
||||
181,
|
||||
14,
|
||||
@ -661,40 +627,6 @@ impl Default for WalletConfig {
|
||||
105,
|
||||
104,
|
||||
231
|
||||
],
|
||||
"outgoing_viewing_secret_key": [
|
||||
20,
|
||||
170,
|
||||
220,
|
||||
108,
|
||||
41,
|
||||
23,
|
||||
155,
|
||||
217,
|
||||
247,
|
||||
190,
|
||||
175,
|
||||
168,
|
||||
247,
|
||||
34,
|
||||
105,
|
||||
134,
|
||||
114,
|
||||
74,
|
||||
104,
|
||||
91,
|
||||
211,
|
||||
62,
|
||||
126,
|
||||
13,
|
||||
130,
|
||||
100,
|
||||
241,
|
||||
214,
|
||||
250,
|
||||
236,
|
||||
38,
|
||||
150
|
||||
]
|
||||
},
|
||||
"nullifer_public_key": [
|
||||
@ -731,7 +663,7 @@ impl Default for WalletConfig {
|
||||
140,
|
||||
47
|
||||
],
|
||||
"incoming_viewing_public_key": [
|
||||
"viewing_public_key": [
|
||||
2,
|
||||
181,
|
||||
98,
|
||||
|
||||
@ -423,7 +423,7 @@ impl WalletCore {
|
||||
Vec::from_iter(acc_manager.public_account_nonces()),
|
||||
private_account_keys
|
||||
.iter()
|
||||
.map(|keys| (keys.npk.clone(), keys.ipk.clone(), keys.epk.clone()))
|
||||
.map(|keys| (keys.npk.clone(), keys.vpk.clone(), keys.epk.clone()))
|
||||
.collect(),
|
||||
output,
|
||||
)
|
||||
@ -508,7 +508,7 @@ impl WalletCore {
|
||||
.flat_map(|(acc_account_id, key_chain)| {
|
||||
let view_tag = EncryptedAccountData::compute_view_tag(
|
||||
key_chain.nullifer_public_key.clone(),
|
||||
key_chain.incoming_viewing_public_key.clone(),
|
||||
key_chain.viewing_public_key.clone(),
|
||||
);
|
||||
|
||||
tx.message()
|
||||
|
||||
@ -5,7 +5,7 @@ use nssa::{AccountId, PrivateKey};
|
||||
use nssa_core::{
|
||||
MembershipProof, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
|
||||
account::{AccountWithMetadata, Nonce},
|
||||
encryption::{EphemeralPublicKey, IncomingViewingPublicKey},
|
||||
encryption::{EphemeralPublicKey, ViewingPublicKey},
|
||||
};
|
||||
|
||||
use crate::WalletCore;
|
||||
@ -16,7 +16,7 @@ pub enum PrivacyPreservingAccount {
|
||||
PrivateOwned(AccountId),
|
||||
PrivateForeign {
|
||||
npk: NullifierPublicKey,
|
||||
ipk: IncomingViewingPublicKey,
|
||||
vpk: ViewingPublicKey,
|
||||
},
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ impl PrivacyPreservingAccount {
|
||||
pub fn is_private(&self) -> bool {
|
||||
matches!(
|
||||
&self,
|
||||
Self::PrivateOwned(_) | Self::PrivateForeign { npk: _, ipk: _ }
|
||||
Self::PrivateOwned(_) | Self::PrivateForeign { npk: _, vpk: _ }
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ impl PrivacyPreservingAccount {
|
||||
pub struct PrivateAccountKeys {
|
||||
pub npk: NullifierPublicKey,
|
||||
pub ssk: SharedSecretKey,
|
||||
pub ipk: IncomingViewingPublicKey,
|
||||
pub vpk: ViewingPublicKey,
|
||||
pub epk: EphemeralPublicKey,
|
||||
}
|
||||
|
||||
@ -80,13 +80,13 @@ impl AccountManager {
|
||||
|
||||
(State::Private(pre), mask)
|
||||
}
|
||||
PrivacyPreservingAccount::PrivateForeign { npk, ipk } => {
|
||||
PrivacyPreservingAccount::PrivateForeign { npk, vpk } => {
|
||||
let acc = nssa_core::account::Account::default();
|
||||
let auth_acc = AccountWithMetadata::new(acc, false, &npk);
|
||||
let pre = AccountPreparedData {
|
||||
nsk: None,
|
||||
npk,
|
||||
ipk,
|
||||
vpk,
|
||||
pre_state: auth_acc,
|
||||
proof: None,
|
||||
};
|
||||
@ -138,8 +138,8 @@ impl AccountManager {
|
||||
|
||||
Some(PrivateAccountKeys {
|
||||
npk: pre.npk.clone(),
|
||||
ssk: eph_holder.calculate_shared_secret_sender(&pre.ipk),
|
||||
ipk: pre.ipk.clone(),
|
||||
ssk: eph_holder.calculate_shared_secret_sender(&pre.vpk),
|
||||
vpk: pre.vpk.clone(),
|
||||
epk: eph_holder.generate_ephemeral_public_key(),
|
||||
})
|
||||
}
|
||||
@ -192,7 +192,7 @@ impl AccountManager {
|
||||
struct AccountPreparedData {
|
||||
nsk: Option<NullifierSecretKey>,
|
||||
npk: NullifierPublicKey,
|
||||
ipk: IncomingViewingPublicKey,
|
||||
vpk: ViewingPublicKey,
|
||||
pre_state: AccountWithMetadata,
|
||||
proof: Option<MembershipProof>,
|
||||
}
|
||||
@ -213,7 +213,7 @@ async fn private_acc_preparation(
|
||||
let nsk = from_keys.private_key_holder.nullifier_secret_key;
|
||||
|
||||
let from_npk = from_keys.nullifer_public_key;
|
||||
let from_ipk = from_keys.incoming_viewing_public_key;
|
||||
let from_vpk = from_keys.viewing_public_key;
|
||||
|
||||
// TODO: Remove this unwrap, error types must be compatible
|
||||
let proof = wallet
|
||||
@ -228,7 +228,7 @@ async fn private_acc_preparation(
|
||||
Ok(AccountPreparedData {
|
||||
nsk: Some(nsk),
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
pre_state: sender_pre,
|
||||
proof,
|
||||
})
|
||||
|
||||
@ -2,7 +2,7 @@ use std::vec;
|
||||
|
||||
use common::{error::ExecutionFailureKind, rpc_primitives::requests::SendTxResponse};
|
||||
use nssa::{AccountId, program::Program};
|
||||
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey};
|
||||
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::ViewingPublicKey};
|
||||
|
||||
use super::{NativeTokenTransfer, auth_transfer_preparation};
|
||||
use crate::PrivacyPreservingAccount;
|
||||
@ -32,7 +32,7 @@ impl NativeTokenTransfer<'_> {
|
||||
&self,
|
||||
from: AccountId,
|
||||
to_npk: NullifierPublicKey,
|
||||
to_ipk: IncomingViewingPublicKey,
|
||||
to_vpk: ViewingPublicKey,
|
||||
balance_to_move: u128,
|
||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||
let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move);
|
||||
@ -43,7 +43,7 @@ impl NativeTokenTransfer<'_> {
|
||||
PrivacyPreservingAccount::PrivateOwned(from),
|
||||
PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
vpk: to_vpk,
|
||||
},
|
||||
],
|
||||
instruction_data,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use common::{error::ExecutionFailureKind, rpc_primitives::requests::SendTxResponse};
|
||||
use nssa::AccountId;
|
||||
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey};
|
||||
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::ViewingPublicKey};
|
||||
|
||||
use super::{NativeTokenTransfer, auth_transfer_preparation};
|
||||
use crate::PrivacyPreservingAccount;
|
||||
@ -38,7 +38,7 @@ impl NativeTokenTransfer<'_> {
|
||||
&self,
|
||||
from: AccountId,
|
||||
to_npk: NullifierPublicKey,
|
||||
to_ipk: IncomingViewingPublicKey,
|
||||
to_vpk: ViewingPublicKey,
|
||||
balance_to_move: u128,
|
||||
) -> Result<(SendTxResponse, SharedSecretKey), ExecutionFailureKind> {
|
||||
let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move);
|
||||
@ -49,7 +49,7 @@ impl NativeTokenTransfer<'_> {
|
||||
PrivacyPreservingAccount::Public(from),
|
||||
PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
vpk: to_vpk,
|
||||
},
|
||||
],
|
||||
instruction_data,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use common::{error::ExecutionFailureKind, rpc_primitives::requests::SendTxResponse};
|
||||
use nssa::{AccountId, program::Program};
|
||||
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey};
|
||||
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::ViewingPublicKey};
|
||||
|
||||
use crate::{PrivacyPreservingAccount, WalletCore};
|
||||
|
||||
@ -196,7 +196,7 @@ impl Token<'_> {
|
||||
&self,
|
||||
sender_account_id: AccountId,
|
||||
recipient_npk: NullifierPublicKey,
|
||||
recipient_ipk: IncomingViewingPublicKey,
|
||||
recipient_vpk: ViewingPublicKey,
|
||||
amount: u128,
|
||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||
let instruction = token_program_preparation_transfer(amount);
|
||||
@ -209,7 +209,7 @@ impl Token<'_> {
|
||||
PrivacyPreservingAccount::PrivateOwned(sender_account_id),
|
||||
PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: recipient_npk,
|
||||
ipk: recipient_ipk,
|
||||
vpk: recipient_vpk,
|
||||
},
|
||||
],
|
||||
instruction_data,
|
||||
@ -286,7 +286,7 @@ impl Token<'_> {
|
||||
&self,
|
||||
sender_account_id: AccountId,
|
||||
recipient_npk: NullifierPublicKey,
|
||||
recipient_ipk: IncomingViewingPublicKey,
|
||||
recipient_vpk: ViewingPublicKey,
|
||||
amount: u128,
|
||||
) -> Result<(SendTxResponse, SharedSecretKey), ExecutionFailureKind> {
|
||||
let instruction = token_program_preparation_transfer(amount);
|
||||
@ -299,7 +299,7 @@ impl Token<'_> {
|
||||
PrivacyPreservingAccount::Public(sender_account_id),
|
||||
PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: recipient_npk,
|
||||
ipk: recipient_ipk,
|
||||
vpk: recipient_vpk,
|
||||
},
|
||||
],
|
||||
instruction_data,
|
||||
@ -507,7 +507,7 @@ impl Token<'_> {
|
||||
&self,
|
||||
definition_account_id: AccountId,
|
||||
holder_npk: NullifierPublicKey,
|
||||
holder_ipk: IncomingViewingPublicKey,
|
||||
holder_vpk: ViewingPublicKey,
|
||||
amount: u128,
|
||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||
let instruction = token_program_preparation_mint(amount);
|
||||
@ -520,7 +520,7 @@ impl Token<'_> {
|
||||
PrivacyPreservingAccount::PrivateOwned(definition_account_id),
|
||||
PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: holder_npk,
|
||||
ipk: holder_ipk,
|
||||
vpk: holder_vpk,
|
||||
},
|
||||
],
|
||||
instruction_data,
|
||||
@ -597,7 +597,7 @@ impl Token<'_> {
|
||||
&self,
|
||||
definition_account_id: AccountId,
|
||||
holder_npk: NullifierPublicKey,
|
||||
holder_ipk: IncomingViewingPublicKey,
|
||||
holder_vpk: ViewingPublicKey,
|
||||
amount: u128,
|
||||
) -> Result<(SendTxResponse, SharedSecretKey), ExecutionFailureKind> {
|
||||
let instruction = token_program_preparation_mint(amount);
|
||||
@ -610,7 +610,7 @@ impl Token<'_> {
|
||||
PrivacyPreservingAccount::Public(definition_account_id),
|
||||
PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: holder_npk,
|
||||
ipk: holder_ipk,
|
||||
vpk: holder_vpk,
|
||||
},
|
||||
],
|
||||
instruction_data,
|
||||
|
||||
@ -7,7 +7,7 @@ use nssa::{
|
||||
};
|
||||
use nssa_core::{
|
||||
Commitment, MembershipProof, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
|
||||
account::AccountWithMetadata, encryption::IncomingViewingPublicKey, program::InstructionData,
|
||||
account::AccountWithMetadata, encryption::ViewingPublicKey, program::InstructionData,
|
||||
};
|
||||
|
||||
use crate::{WalletCore, helperfunctions::produce_random_nonces};
|
||||
@ -15,7 +15,7 @@ use crate::{WalletCore, helperfunctions::produce_random_nonces};
|
||||
pub(crate) struct AccountPreparedData {
|
||||
pub nsk: Option<NullifierSecretKey>,
|
||||
pub npk: NullifierPublicKey,
|
||||
pub ipk: IncomingViewingPublicKey,
|
||||
pub vpk: ViewingPublicKey,
|
||||
pub auth_acc: AccountWithMetadata,
|
||||
pub proof: Option<MembershipProof>,
|
||||
}
|
||||
@ -40,7 +40,7 @@ impl WalletCore {
|
||||
let mut proof = None;
|
||||
|
||||
let from_npk = from_keys.nullifer_public_key;
|
||||
let from_ipk = from_keys.incoming_viewing_public_key;
|
||||
let from_vpk = from_keys.viewing_public_key;
|
||||
|
||||
let sender_commitment = Commitment::new(&from_npk, &from_acc);
|
||||
|
||||
@ -61,7 +61,7 @@ impl WalletCore {
|
||||
Ok(AccountPreparedData {
|
||||
nsk,
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
auth_acc: sender_pre,
|
||||
proof,
|
||||
})
|
||||
@ -79,7 +79,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: from_nsk,
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
auth_acc: sender_pre,
|
||||
proof: from_proof,
|
||||
} = self.private_acc_preparation(from, true, true).await?;
|
||||
@ -87,7 +87,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: to_nsk,
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
vpk: to_vpk,
|
||||
auth_acc: recipient_pre,
|
||||
proof: _,
|
||||
} = self.private_acc_preparation(to, true, false).await?;
|
||||
@ -95,10 +95,10 @@ impl WalletCore {
|
||||
tx_pre_check(&sender_pre.account, &recipient_pre.account)?;
|
||||
|
||||
let eph_holder_from = EphemeralKeyHolder::new(&from_npk);
|
||||
let shared_secret_from = eph_holder_from.calculate_shared_secret_sender(&from_ipk);
|
||||
let shared_secret_from = eph_holder_from.calculate_shared_secret_sender(&from_vpk);
|
||||
|
||||
let eph_holder_to = EphemeralKeyHolder::new(&to_npk);
|
||||
let shared_secret_to = eph_holder_to.calculate_shared_secret_sender(&to_ipk);
|
||||
let shared_secret_to = eph_holder_to.calculate_shared_secret_sender(&to_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -123,12 +123,12 @@ impl WalletCore {
|
||||
vec![
|
||||
(
|
||||
from_npk.clone(),
|
||||
from_ipk.clone(),
|
||||
from_vpk.clone(),
|
||||
eph_holder_from.generate_ephemeral_public_key(),
|
||||
),
|
||||
(
|
||||
to_npk.clone(),
|
||||
to_ipk.clone(),
|
||||
to_vpk.clone(),
|
||||
eph_holder_to.generate_ephemeral_public_key(),
|
||||
),
|
||||
],
|
||||
@ -156,7 +156,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: from_nsk,
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
auth_acc: sender_pre,
|
||||
proof: from_proof,
|
||||
} = self.private_acc_preparation(from, true, true).await?;
|
||||
@ -164,7 +164,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: _,
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
vpk: to_vpk,
|
||||
auth_acc: recipient_pre,
|
||||
proof: _,
|
||||
} = self.private_acc_preparation(to, false, false).await?;
|
||||
@ -172,10 +172,10 @@ impl WalletCore {
|
||||
tx_pre_check(&sender_pre.account, &recipient_pre.account)?;
|
||||
|
||||
let eph_holder_from = EphemeralKeyHolder::new(&from_npk);
|
||||
let shared_secret_from = eph_holder_from.calculate_shared_secret_sender(&from_ipk);
|
||||
let shared_secret_from = eph_holder_from.calculate_shared_secret_sender(&from_vpk);
|
||||
|
||||
let eph_holder_to = EphemeralKeyHolder::new(&to_npk);
|
||||
let shared_secret_to = eph_holder_to.calculate_shared_secret_sender(&to_ipk);
|
||||
let shared_secret_to = eph_holder_to.calculate_shared_secret_sender(&to_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -197,12 +197,12 @@ impl WalletCore {
|
||||
vec![
|
||||
(
|
||||
from_npk.clone(),
|
||||
from_ipk.clone(),
|
||||
from_vpk.clone(),
|
||||
eph_holder_from.generate_ephemeral_public_key(),
|
||||
),
|
||||
(
|
||||
to_npk.clone(),
|
||||
to_ipk.clone(),
|
||||
to_vpk.clone(),
|
||||
eph_holder_to.generate_ephemeral_public_key(),
|
||||
),
|
||||
],
|
||||
@ -223,7 +223,7 @@ impl WalletCore {
|
||||
&self,
|
||||
from: AccountId,
|
||||
to_npk: NullifierPublicKey,
|
||||
to_ipk: IncomingViewingPublicKey,
|
||||
to_vpk: ViewingPublicKey,
|
||||
instruction_data: InstructionData,
|
||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||
program: Program,
|
||||
@ -231,7 +231,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: from_nsk,
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
auth_acc: sender_pre,
|
||||
proof: from_proof,
|
||||
} = self.private_acc_preparation(from, true, true).await?;
|
||||
@ -244,8 +244,8 @@ impl WalletCore {
|
||||
|
||||
let eph_holder = EphemeralKeyHolder::new(&to_npk);
|
||||
|
||||
let shared_secret_from = eph_holder.calculate_shared_secret_sender(&from_ipk);
|
||||
let shared_secret_to = eph_holder.calculate_shared_secret_sender(&to_ipk);
|
||||
let shared_secret_from = eph_holder.calculate_shared_secret_sender(&from_vpk);
|
||||
let shared_secret_to = eph_holder.calculate_shared_secret_sender(&to_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -267,12 +267,12 @@ impl WalletCore {
|
||||
vec![
|
||||
(
|
||||
from_npk.clone(),
|
||||
from_ipk.clone(),
|
||||
from_vpk.clone(),
|
||||
eph_holder.generate_ephemeral_public_key(),
|
||||
),
|
||||
(
|
||||
to_npk.clone(),
|
||||
to_ipk.clone(),
|
||||
to_vpk.clone(),
|
||||
eph_holder.generate_ephemeral_public_key(),
|
||||
),
|
||||
],
|
||||
@ -301,7 +301,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: from_nsk,
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
auth_acc: sender_pre,
|
||||
proof: from_proof,
|
||||
} = self.private_acc_preparation(from, true, true).await?;
|
||||
@ -315,7 +315,7 @@ impl WalletCore {
|
||||
let recipient_pre = AccountWithMetadata::new(to_acc.clone(), false, to);
|
||||
|
||||
let eph_holder = EphemeralKeyHolder::new(&from_npk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&from_ipk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&from_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -333,7 +333,7 @@ impl WalletCore {
|
||||
vec![],
|
||||
vec![(
|
||||
from_npk.clone(),
|
||||
from_ipk.clone(),
|
||||
from_vpk.clone(),
|
||||
eph_holder.generate_ephemeral_public_key(),
|
||||
)],
|
||||
output,
|
||||
@ -366,7 +366,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: to_nsk,
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
vpk: to_vpk,
|
||||
auth_acc: recipient_pre,
|
||||
proof: _,
|
||||
} = self.private_acc_preparation(to, true, false).await?;
|
||||
@ -376,7 +376,7 @@ impl WalletCore {
|
||||
let sender_pre = AccountWithMetadata::new(from_acc.clone(), true, from);
|
||||
|
||||
let eph_holder = EphemeralKeyHolder::new(&to_npk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&to_ipk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&to_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -394,7 +394,7 @@ impl WalletCore {
|
||||
vec![from_acc.nonce],
|
||||
vec![(
|
||||
to_npk.clone(),
|
||||
to_ipk.clone(),
|
||||
to_vpk.clone(),
|
||||
eph_holder.generate_ephemeral_public_key(),
|
||||
)],
|
||||
output,
|
||||
@ -432,7 +432,7 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: _,
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
vpk: to_vpk,
|
||||
auth_acc: recipient_pre,
|
||||
proof: _,
|
||||
} = self.private_acc_preparation(to, false, false).await?;
|
||||
@ -442,7 +442,7 @@ impl WalletCore {
|
||||
let sender_pre = AccountWithMetadata::new(from_acc.clone(), true, from);
|
||||
|
||||
let eph_holder = EphemeralKeyHolder::new(&to_npk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&to_ipk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&to_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -460,7 +460,7 @@ impl WalletCore {
|
||||
vec![from_acc.nonce],
|
||||
vec![(
|
||||
to_npk.clone(),
|
||||
to_ipk.clone(),
|
||||
to_vpk.clone(),
|
||||
eph_holder.generate_ephemeral_public_key(),
|
||||
)],
|
||||
output,
|
||||
@ -487,7 +487,7 @@ impl WalletCore {
|
||||
&self,
|
||||
from: AccountId,
|
||||
to_npk: NullifierPublicKey,
|
||||
to_ipk: IncomingViewingPublicKey,
|
||||
to_vpk: ViewingPublicKey,
|
||||
instruction_data: InstructionData,
|
||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||
program: Program,
|
||||
@ -504,7 +504,7 @@ impl WalletCore {
|
||||
let recipient_pre = AccountWithMetadata::new(to_acc.clone(), false, &to_npk);
|
||||
|
||||
let eph_holder = EphemeralKeyHolder::new(&to_npk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&to_ipk);
|
||||
let shared_secret = eph_holder.calculate_shared_secret_sender(&to_vpk);
|
||||
|
||||
let (output, proof) = circuit::execute_and_prove(
|
||||
&[sender_pre, recipient_pre],
|
||||
@ -522,7 +522,7 @@ impl WalletCore {
|
||||
vec![from_acc.nonce],
|
||||
vec![(
|
||||
to_npk.clone(),
|
||||
to_ipk.clone(),
|
||||
to_vpk.clone(),
|
||||
eph_holder.generate_ephemeral_public_key(),
|
||||
)],
|
||||
output,
|
||||
@ -548,13 +548,13 @@ impl WalletCore {
|
||||
let AccountPreparedData {
|
||||
nsk: _,
|
||||
npk: from_npk,
|
||||
ipk: from_ipk,
|
||||
vpk: from_vpk,
|
||||
auth_acc: sender_pre,
|
||||
proof: _,
|
||||
} = self.private_acc_preparation(from, false, false).await?;
|
||||
|
||||
let eph_holder_from = EphemeralKeyHolder::new(&from_npk);
|
||||
let shared_secret_from = eph_holder_from.calculate_shared_secret_sender(&from_ipk);
|
||||
let shared_secret_from = eph_holder_from.calculate_shared_secret_sender(&from_vpk);
|
||||
|
||||
let instruction: u128 = 0;
|
||||
|
||||
@ -574,7 +574,7 @@ impl WalletCore {
|
||||
vec![],
|
||||
vec![(
|
||||
from_npk.clone(),
|
||||
from_ipk.clone(),
|
||||
from_vpk.clone(),
|
||||
eph_holder_from.generate_ephemeral_public_key(),
|
||||
)],
|
||||
output,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user