Add --payment-proof CLI flag for contracts

Expose contract payment proofs (already supported via the owner API) on the CLI.
contract new / contract sign --payment-proof opts the receiver into generating the
invoice proof. The proof commits to the sender's address, derived from the
--encrypt-for counterparty (mirroring how send derives its proof address from the
destination), and errors if --encrypt-for is absent.

Wiring: flag in grin-wallet.yml; ContractNewArgs/ContractSetupArgs carry the derived
sender address; to_api_args sets proof_args (suppress_proof=false + sender_address).
ed25519-dalek promoted to a controller dependency.
This commit is contained in:
jwinterm
2026-06-04 07:44:23 -04:00
parent 4fcb6053d5
commit 7b67d20b8e
4 changed files with 63 additions and 2 deletions
+1
View File
@@ -11,6 +11,7 @@ exclude = ["**/*.grin", "**/*.grin2"]
edition = "2021"
[dependencies]
ed25519-dalek = "1.0.0-pre.4"
futures = "0.3"
hyper = "0.14"
rand = "0.7"
+18 -2
View File
@@ -24,8 +24,9 @@ use crate::keychain;
use crate::libwallet::api_impl::owner;
use crate::libwallet::contract::can_finalize;
use crate::libwallet::contract::types::{
ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI, OutputSelectionArgs,
ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI, OutputSelectionArgs, ProofArgs,
};
use ed25519_dalek::PublicKey as DalekPublicKey;
use crate::libwallet::{
self, InitTxArgs, IssueInvoiceTxArgs, NodeClient, PaymentProof, Slate, SlateState, Slatepack,
SlatepackAddress, Slatepacker, SlatepackerArgs, WalletLCProvider,
@@ -1646,6 +1647,8 @@ pub struct ContractNewArgs {
pub outfile: Option<String>,
/// Select outputs early
pub add_outputs: bool,
/// Sender address for a requested payment proof (set when --payment-proof is passed)
pub payment_proof_sender: Option<DalekPublicKey>,
}
impl ContractNewArgs {
@@ -1663,6 +1666,11 @@ impl ContractNewArgs {
// Create a ContractNewArgsAPI from the ContractNewArgs
fn to_api_args(&self) -> ContractNewArgsAPI {
let net_change = self.get_net_change();
let mut proof_args = ProofArgs::default();
if let Some(sender) = self.payment_proof_sender {
proof_args.suppress_proof = false;
proof_args.sender_address = Some(sender);
}
ContractNewArgsAPI {
setup_args: ContractSetupArgsAPI {
src_acct_name: match self.src_acct_name.as_ref() {
@@ -1683,7 +1691,7 @@ impl ContractNewArgs {
},
..Default::default()
},
proof_args: Default::default(),
proof_args,
},
..Default::default()
}
@@ -1745,6 +1753,8 @@ pub struct ContractSetupArgs {
pub outfile: Option<String>,
/// Add outputs
pub add_outputs: bool, // lock outputs early
/// Sender address for a requested payment proof (set when --payment-proof is passed)
pub payment_proof_sender: Option<DalekPublicKey>,
}
impl ContractSetupArgs {
@@ -1766,11 +1776,17 @@ impl ContractSetupArgs {
// Create a ContractSetupArgsAPI from the ContractSetupArgs
fn to_api_args(&self) -> ContractSetupArgsAPI {
let net_change = self.get_net_change();
let mut proof_args = ProofArgs::default();
if let Some(sender) = self.payment_proof_sender {
proof_args.suppress_proof = false;
proof_args.sender_address = Some(sender);
}
ContractSetupArgsAPI {
// TODO: num_participants is derived here. It should be an Option and read from the slate.
// Need to check no attack are possible regarding kernel fee contribution.
net_change: net_change,
add_outputs: self.add_outputs,
proof_args,
selection_args: OutputSelectionArgs {
use_inputs: match self.use_inputs.as_ref() {
Some(v) => Some(v.to_string()),
+8
View File
@@ -497,6 +497,10 @@ subcommands:
short: o
long: make-outputs
takes_value: true
- payment-proof:
help: Request a payment proof (receiver signs a receipt). Requires --encrypt-for.
long: payment-proof
takes_value: false
# - setup:
# about: Perform a key setup on a contract
# args:
@@ -578,6 +582,10 @@ subcommands:
short: o
long: make-outputs
takes_value: true
- payment-proof:
help: Request a payment proof (receiver signs a receipt). Requires --encrypt-for.
long: payment-proof
takes_value: false
- no-broadcast:
help: Don't broadcast the transaction if it was finalized
long: no-broadcast
+36
View File
@@ -1044,6 +1044,23 @@ pub fn parse_contract_new_args(
None => 2,
};
// A payment proof commits to the sender's address, so it requires --encrypt-for
// (the counterparty) to derive that address from.
let payment_proof_sender = if args.is_present("payment-proof") {
let addr_str = counterparty_addr.as_deref().ok_or_else(|| {
ParseError::ArgumentError("--payment-proof requires --encrypt-for".into())
})?;
let addr = SlatepackAddress::try_from(addr_str).map_err(|e| {
ParseError::ArgumentError(format!(
"Invalid --encrypt-for address for payment proof: {}",
e
))
})?;
Some(addr.pub_key)
} else {
None
};
Ok(command::ContractNewArgs {
counterparty_addr: counterparty_addr,
receive: receive,
@@ -1054,6 +1071,7 @@ pub fn parse_contract_new_args(
add_outputs: add_outputs,
use_inputs: use_inputs,
make_outputs: make_outputs,
payment_proof_sender: payment_proof_sender,
// TODO: Future features below
fee_rate: None,
outfile: None,
@@ -1118,6 +1136,23 @@ pub fn parse_contract_setup_args(
// TODO: should we catch if the person calls "--receive=5" when it should be "--send=5"?
// Perhaps we could detect this from the slate state e.g. S1 -> receive, I1 -> send?
// A payment proof commits to the sender's address; require --encrypt-for so we can
// derive it (when signing, the counterparty is the sender).
let payment_proof_sender = if args.is_present("payment-proof") {
let addr_str = counterparty_addr.as_ref().ok_or_else(|| {
ParseError::ArgumentError("--payment-proof requires --encrypt-for".into())
})?;
let addr = SlatepackAddress::try_from(addr_str.as_str()).map_err(|e| {
ParseError::ArgumentError(format!(
"Invalid --encrypt-for address for payment proof: {}",
e
))
})?;
Some(addr.pub_key)
} else {
None
};
Ok(command::ContractSetupArgs {
counterparty_addr: counterparty_addr,
receive: receive,
@@ -1126,6 +1161,7 @@ pub fn parse_contract_setup_args(
add_outputs: false,
use_inputs: use_inputs,
make_outputs: make_outputs,
payment_proof_sender: payment_proof_sender,
// TODO: Future features below
fee_rate: None,
outfile: None,