Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions applications/tari_wallet_cli/src/command/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum ProofsSubcommand {

#[derive(Debug, Args, Clone)]
pub struct GenerateArgs {
pub amount: i64,
pub amount: u64,
#[clap(short = 'o', long)]
pub output_type: OutputType,
}
Expand Down Expand Up @@ -66,9 +66,7 @@ impl ProofsSubcommand {
match self {
Generate(args) => {
let resp = client
.create_confidential_output_proof(ConfidentialCreateOutputProofRequest {
amount: args.amount.into(),
})
.create_confidential_output_proof(ConfidentialCreateOutputProofRequest { amount: args.amount })
.await?;

match args.output_type {
Expand Down
29 changes: 8 additions & 21 deletions applications/tari_walletd/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ use tokio::task;
use super::context::HandlerContext;
use crate::{
handlers::helpers::{
application_error,
general_error,
get_account,
get_account_by_key_index,
Expand All @@ -95,7 +94,6 @@ use crate::{
wait_for_result,
wait_for_result_and_account,
},
jrpc_server::ApplicationErrorCode,
DEFAULT_FEE,
};

Expand Down Expand Up @@ -295,10 +293,8 @@ pub async fn handle_get_balances(
let confidential_balance = if vault.resource_type.is_stealth() {
let stealth_balance = stealth_outputs
.iter()
.filter(|o| {
o.owner_account == *account.component_address() && o.resource_address == vault.resource_address
})
.map(|o| o.value)
.filter(|o| o.resource_address == vault.resource_address)
.map(|o| Amount::from(o.value))
.sum::<Amount>();

if stealth_balance.is_positive() {
Expand Down Expand Up @@ -328,8 +324,8 @@ pub async fn handle_get_balances(
// NOTE: indexemap used to ensure a consistent order (HashMap causes UI to randomly switch positions for multiple stealth resources)
.fold(IndexMap::new(), |mut acc, o| {
acc.entry(o.resource_address)
.and_modify(|v| *v += o.value)
.or_insert(o.value);
.and_modify(|v| *v += Amount::from(o.value))
.or_insert(Amount::from(o.value));
acc
});

Expand Down Expand Up @@ -479,22 +475,13 @@ pub async fn handle_claim_burn(

let final_amount = decrypted
.value()
.checked_sub_positive(max_fee.into())
.checked_sub(max_fee)
.ok_or_else(|| invalid_params("max_fee", Some("more fees paid than claimed amount")))?;

if final_amount.is_zero() {
if final_amount == 0 {
return Err(invalid_params("max_fee", Some("fee equals or exceeds claimed amount")));
}

let final_amount_u64 = final_amount.to_u64_checked().ok_or_else(|| {
// NOTE: this can never be anywhere close to this large because this would be more than the total supply of XTM
// for thousands of years
application_error(
ApplicationErrorCode::NotImplemented,
format!("Amount to spend {final_amount} is too large and not currently supported"),
)
})?;

let (nonce, output_public_nonce) = RistrettoPublicKey::random_keypair(&mut OsRng);
let account_owner = sdk.key_manager_api().get_account_owner_key(account_owner_key_id)?;
let account_owner_public_key = account_owner.to_public_key();
Expand All @@ -505,7 +492,7 @@ pub async fn handle_claim_burn(
// u64::MAX. Apart from it being insane/basically impossible to have that much XTR in a single UTXO, the L1 emission
// will reach this much in many thousands of years.
let encrypted_data = sdk.stealth_crypto_api().encrypt_value_and_mask(
final_amount_u64,
final_amount,
&mask.key,
&view_only_public_key,
&nonce,
Expand Down Expand Up @@ -1167,7 +1154,7 @@ pub async fn handle_create_stealth_transfer_statement(
let outputs = req
.outputs
.iter()
.filter(|o| o.blinded_amount.is_positive())
.filter(|o| o.blinded_amount > 0)
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?;

Expand Down
67 changes: 28 additions & 39 deletions applications/tari_walletd/src/handlers/confidential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ pub async fn handle_create_transfer_proof(
let sdk = context.wallet_sdk();
context.check_auth(token, &[JrpcPermission::Admin])?;

if req.amount.is_negative() || req.reveal_amount.is_negative() {
if req.reveal_amount.is_negative() {
return Err(invalid_request(format!(
"Amount to send must be positive. Amount = {}, Revealed = {}",
req.amount, req.reveal_amount
"Amount to send must be positive. Revealed amount was {}",
req.reveal_amount
)));
}

Expand All @@ -67,10 +67,10 @@ pub async fn handle_create_transfer_proof(
.get_vault_by_resource(account.component_address(), &req.resource_address)?;
let lock = sdk.locks_api().create_lock_with_timeout(Duration::from_secs(5 * 60))?;

let amount_to_transfer = req.amount.checked_add_positive(req.reveal_amount).ok_or_else(|| {
let amount_to_transfer = req.confidential_amount.checked_add(req.reveal_amount).ok_or_else(|| {
invalid_request(format!(
"Amount to send must be greater than or equal to the amount to reveal. Amount = {}, Revealed = {}",
req.amount, req.reveal_amount
req.confidential_amount, req.reveal_amount
))
})?;
// Lock inputs we're going to spend
Expand All @@ -93,15 +93,15 @@ pub async fn handle_create_transfer_proof(
let output_mask = sdk.key_manager_api().next_key(KeyBranch::ConfidentialMask)?;
let (_, public_nonce) = RistrettoPublicKey::random_keypair(&mut OsRng);

let amount_u64 = req.amount.to_u64_checked().ok_or_else(|| {
let confidential_amount = req.confidential_amount.to_u64_checked().ok_or_else(|| {
invalid_request(format!(
"Amount to send must be a non-negative integer that does not exceed u64::MAX. Amount = {}",
req.amount
"Confidential amount exceeds the maximum value supported in a single UTXO. Amount: {}",
req.confidential_amount
))
})?;

let encrypted_data = sdk.confidential_crypto_api().encrypt_value_and_mask(
amount_u64,
confidential_amount,
&output_mask.key,
&public_nonce,
&account_key.secret,
Expand All @@ -117,34 +117,30 @@ pub async fn handle_create_transfer_proof(
)
})?;

let change_amount = total_input_value
.checked_sub_positive(req.confidential_amount)
.ok_or_else(|| {
invalid_request(format!(
"Insufficient funds to send {}. Total input value = {}",
req.confidential_amount, total_input_value
))
})?;
let change_amount_u64 = change_amount.to_u64_checked().ok_or_else(|| {
invalid_request(format!(
"Change value exceeds the maximum value supported in a single UTXO. Change: {}. Total input value = {}",
change_amount, total_input_value
))
})?;

let output_statement = UnblindedOutputWitness {
amount: req.amount,
amount: confidential_amount,
mask: output_mask.key,
sender_public_nonce: public_nonce,
minimum_value_promise: 0,
encrypted_data,
resource_view_key: resource_view_key.clone(),
};

let spend_amount = req.amount.checked_sub_positive(req.reveal_amount).ok_or_else(|| {
invalid_request(format!(
"Amount to send must be greater than or equal to the amount to reveal. Amount = {}, Revealed = {}",
req.amount, req.reveal_amount
))
})?;
let change_amount = total_input_value.checked_sub_positive(spend_amount).ok_or_else(|| {
invalid_request(format!(
"Insufficient funds to send {}. Total input value = {}",
req.amount, total_input_value
))
})?;
let change_amount_u64 = change_amount.to_u64_checked().ok_or_else(|| {
invalid_request(format!(
"Change value exceeds the maximum value supported in a single UTXO. Change: {}. Total input value = {}",
change_amount, total_input_value
))
})?;

let maybe_change_statement = if change_amount_u64 > 0 {
let change_mask = sdk.key_manager_api().next_key(KeyBranch::ConfidentialMask)?;
let (_, public_nonce) = RistrettoPublicKey::random_keypair(&mut OsRng);
Expand Down Expand Up @@ -175,7 +171,7 @@ pub async fn handle_create_transfer_proof(
})?;

Some(UnblindedOutputWitness {
amount: change_amount,
amount: change_amount_u64,
mask: change_mask.key,
sender_public_nonce: public_nonce,
encrypted_data,
Expand All @@ -192,7 +188,7 @@ pub async fn handle_create_transfer_proof(
&inputs,
// TODO: support for using revealed funds as input for proof generation
Amount::zero(),
Some(&output_statement).filter(|o| !o.amount.is_zero()),
Some(&output_statement).filter(|o| o.amount > 0),
req.reveal_amount,
maybe_change_statement.as_ref(),
Amount::zero(),
Expand Down Expand Up @@ -278,17 +274,10 @@ pub async fn handle_create_output_proof(
let sdk = context.wallet_sdk();
context.check_auth(token, &[JrpcPermission::Admin])?;

let Some(amount) = req.amount.to_u64_checked() else {
return Err(invalid_params(
"amount",
Some("must be positive and less than u64::MAX"),
));
};

let output_mask = sdk.key_manager_api().next_key(KeyBranch::ConfidentialMask)?;
let (_, public_nonce) = RistrettoPublicKey::random_keypair(&mut OsRng);
let encrypted_data = sdk.confidential_crypto_api().encrypt_value_and_mask(
amount,
req.amount,
&output_mask.key,
&public_nonce,
&output_mask.key,
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_walletd/src/handlers/stealth_utxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn handle_list(
.into_iter()
.map(|o| UtxoInfo {
address: o.to_utxo_address(),
value: o.value,
value: o.value.into(),
status: o.status,
memo: o.memo,
is_burnt: o.is_burnt,
Expand Down
1 change: 0 additions & 1 deletion applications/tari_walletd/src/jrpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,4 @@ pub enum ApplicationErrorCode {
InvalidRequest = 400,
TransactionRejected = 1000,
GeneralError = 500,
NotImplemented = 501,
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const useAccountsTransfer = () => {
transfers: [
{
destination_address: params.destination_address,
blinded_output_amount: params.output_to_revealed ? 0 : params.amount,
blinded_output_amount: params.output_to_revealed ? 0n : BigInt(params.amount),
revealed_output_amount: params.output_to_revealed ? params.amount : 0,
output_memo: params.output_memo || null,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "../Amount";

export type ConfidentialCreateOutputProofRequest = { amount: Amount };
export type ConfidentialCreateOutputProofRequest = { amount: bigint };
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RistrettoPublicKeyBytes } from "../RistrettoPublicKeyBytes";
import type { ComponentAddressOrName } from "./ComponentAddressOrName";

export type ProofsGenerateRequest = {
amount: Amount;
confidential_amount: Amount;
reveal_amount: Amount;
account: ComponentAddressOrName | null;
resource_address: ResourceAddress;
Expand Down
2 changes: 1 addition & 1 deletion bindings/src/types/wallet-daemon-client/StealthTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { OotleAddress } from "../OotleAddress";

export type StealthTransfer = {
destination_address: OotleAddress;
blinded_output_amount: Amount;
blinded_output_amount: bigint;
revealed_output_amount: Amount;
output_memo?: Memo | null;
};
2 changes: 1 addition & 1 deletion bindings/src/types/wallet-daemon-client/TransferOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type TransferOutput = {
/**
* Amount to spend to a blinded output
*/
blinded_amount: Amount;
blinded_amount: bigint;
/**
* Optional memo to include a memo in the output. This memo is encrypted and can only be read by the recipient.
*/
Expand Down
6 changes: 1 addition & 5 deletions clients/javascript/wallet_daemon_client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
AccountSetDefaultRequest,
AccountSetDefaultResponse,
AccountsGetBalancesRequest,
AccountsGetBalancesResponse, AccountsGetPayRefAddressRequest, AccountsGetPayRefAddressResponse,
AccountsGetBalancesResponse,
AccountsListRequest,
AccountsListResponse,
AccountsRenameRequest,
Expand Down Expand Up @@ -177,10 +177,6 @@ export class WalletDaemonClient {
return this.__invokeRpc("accounts.create", params);
}

public accountsGetPayRefAddress(params: AccountsGetPayRefAddressRequest): Promise<AccountsGetPayRefAddressResponse> {
return this.__invokeRpc("accounts.get_pay_ref_address", params);
}

public accountsRename(params: AccountsRenameRequest): Promise<AccountsRenameResponse> {
return this.__invokeRpc("accounts.rename", params);
}
Expand Down
11 changes: 7 additions & 4 deletions clients/wallet_daemon_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ pub struct AccountsTransferResponse {
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "ts", derive(ts_rs::TS), ts(export, export_to = "wallet-daemon-client/"))]
pub struct ProofsGenerateRequest {
pub amount: Amount,
pub confidential_amount: Amount,
pub reveal_amount: Amount,
#[serde(deserialize_with = "opt_string_or_struct")]
pub account: Option<ComponentAddressOrName>,
Expand Down Expand Up @@ -529,7 +529,7 @@ pub struct ProofsCancelRequest {
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "ts", derive(ts_rs::TS), ts(export, export_to = "wallet-daemon-client/"))]
pub struct ConfidentialCreateOutputProofRequest {
pub amount: Amount,
pub amount: u64,
}
Comment thread
sdbondi marked this conversation as resolved.

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -1075,7 +1075,10 @@ pub struct TransferStatementRequest {

impl TransferStatementRequest {
pub fn total_output_amount(&self) -> Amount {
self.outputs.iter().map(|o| o.blinded_amount + o.revealed_amount).sum()
self.outputs
.iter()
.map(|o| Amount::from(o.blinded_amount) + o.revealed_amount)
.sum()
}
}

Expand Down Expand Up @@ -1129,7 +1132,7 @@ pub struct StealthTransferRequest {
#[cfg_attr(feature = "ts", derive(ts_rs::TS), ts(export, export_to = "wallet-daemon-client/"))]
pub struct StealthTransfer {
pub destination_address: OotleAddress,
pub blinded_output_amount: Amount,
pub blinded_output_amount: u64,
pub revealed_output_amount: Amount,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub output_memo: Option<Memo>,
Comment thread
sdbondi marked this conversation as resolved.
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn it_burns_all_resource_types() {
let mut test = TemplateTest::new(["tests/templates/burn"]);
let recall_template = test.get_template_address("Burn");

let (mut initial_supply, _mask, _) = generate_confidential_output_statement(Amount::from(1000), None);
let (mut initial_supply, _mask, _) = generate_confidential_output_statement(1000, None);
initial_supply.output_revealed_amount = Amount::from(1000);

let result = test.execute_expect_success(
Expand Down
7 changes: 2 additions & 5 deletions crates/engine/tests/confidential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn setup(

#[test]
fn mint_initial_commitment() {
let (confidential_proof, _mask, _change) = generate_confidential_output_statement(Amount::from(100), None);
let (confidential_proof, _mask, _change) = generate_confidential_output_statement(100, None);
let (test, _faucet, faucet_resx) = setup(confidential_proof, None);

let resource = test
Expand Down Expand Up @@ -359,10 +359,7 @@ fn multi_commitment_join() {
let withdraw_proof1 = generate_withdraw_proof(&faucet_mask, 1000, Some(99_000), 0);
let withdraw_proof2 = generate_withdraw_proof(withdraw_proof1.change_mask.as_ref().unwrap(), 1000, Some(98_000), 0);
let join_proof = generate_withdraw_proof_with_inputs(
&[
(withdraw_proof1.output_mask, 1000.into()),
(withdraw_proof2.output_mask, 1000.into()),
],
&[(withdraw_proof1.output_mask, 1000), (withdraw_proof2.output_mask, 1000)],
0,
2000,
None,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/tests/recall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn it_recalls_all_resource_types() {
let recall_template = test.get_template_address("Recall");
let (account, _, _) = test.create_empty_account();

let (mut initial_supply, mask, _) = generate_confidential_output_statement(Amount::from(1000), None);
let (mut initial_supply, mask, _) = generate_confidential_output_statement(1000, None);
initial_supply.output_revealed_amount = Amount::from(1000);

let result = test.execute_expect_success(
Expand Down
Loading
Loading