mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-22 09:38:33 +02:00
add sender nonce proofs
This commit is contained in:
@@ -22,7 +22,7 @@ use crate::api_impl::owner::contract_sign as owner_contract_sign;
|
||||
use crate::api_impl::owner::{check_ttl, post_tx};
|
||||
use crate::api_impl::types::update_tx_slate_state;
|
||||
use crate::backend::WalletBackend;
|
||||
use crate::contract::proofs::InvoiceProof;
|
||||
use crate::contract::proofs::EarlyPaymentProof;
|
||||
use crate::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI};
|
||||
use crate::grin_core::core::FeeFields;
|
||||
use crate::grin_keychain::Keychain;
|
||||
@@ -291,11 +291,11 @@ where
|
||||
owner_contract_sign(w, keychain_mask, args, slate)
|
||||
}
|
||||
|
||||
/// Verify an invoice payment proof
|
||||
pub fn verify_payment_proof_invoice<C, K>(
|
||||
/// Verify an early payment proof
|
||||
pub fn verify_payment_proof_early<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
recipient_address: &DalekPublicKey,
|
||||
proof: &InvoiceProof,
|
||||
proof: &EarlyPaymentProof,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
C: NodeClient,
|
||||
@@ -307,7 +307,7 @@ where
|
||||
Some(w) => w,
|
||||
None => {
|
||||
return Err(Error::PaymentProof(
|
||||
"Cannot verify invoice proof with no witness data".to_string(),
|
||||
"Cannot verify early payment proof with no witness data".to_string(),
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::cmp;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::api_impl::foreign::finalize_tx as foreign_finalize;
|
||||
use crate::contract::proofs::{InvoiceProof, ProofWitness};
|
||||
use crate::contract::proofs::{EarlyPaymentProof, ProofWitness};
|
||||
use crate::grin_core::core::amount_to_hr_string;
|
||||
use crate::grin_core::core::hash::Hashed;
|
||||
use crate::grin_core::core::{FeeFields, Output, OutputFeatures, Transaction};
|
||||
@@ -523,16 +523,15 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
/// Retrieve invoice payment proof
|
||||
/// TODO: Need to unify with legacy above
|
||||
pub fn retrieve_payment_proof_invoice<'a, L, C, K>(
|
||||
/// Retrieve an early payment proof
|
||||
pub fn retrieve_payment_proof_early<'a, L, C, K>(
|
||||
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
status_send_channel: &Option<Sender<StatusMessage>>,
|
||||
refresh_from_node: bool,
|
||||
tx_id: Option<u32>,
|
||||
tx_slate_id: Option<Uuid>,
|
||||
) -> Result<InvoiceProof, Error>
|
||||
) -> Result<EarlyPaymentProof, Error>
|
||||
where
|
||||
L: WalletLCProvider<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
@@ -571,32 +570,36 @@ where
|
||||
let tx = txs.1[0].clone();
|
||||
// Contract tx logs store the agreed net change separately from the fee.
|
||||
let amount = tx.amount_credited.abs_diff(tx.amount_debited);
|
||||
let sender_public_nonce = tx
|
||||
.payment_proof
|
||||
.as_ref()
|
||||
.and_then(|proof| proof.sender_public_nonce);
|
||||
|
||||
let (mut proof, sender_part_sig) = match tx.payment_proof {
|
||||
Some(p) => {
|
||||
if p.receiver_public_nonce.is_none() {
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Invoice Proof requires stored receiver public nonce".into(),
|
||||
"Early payment proof requires stored receiver public nonce".into(),
|
||||
));
|
||||
};
|
||||
if p.receiver_public_excess.is_none() {
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Invoice Proof requires stored receiver public excess".into(),
|
||||
"Early payment proof requires stored receiver public excess".into(),
|
||||
));
|
||||
};
|
||||
if p.timestamp.is_none() {
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Invoice Proof requires stored timestamp".into(),
|
||||
"Early payment proof requires stored timestamp".into(),
|
||||
));
|
||||
};
|
||||
if p.sender_part_sig.is_none() {
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Invoice Proof requires stored sender partial signature".into(),
|
||||
"Early payment proof requires stored sender partial signature".into(),
|
||||
));
|
||||
};
|
||||
|
||||
(
|
||||
InvoiceProof {
|
||||
EarlyPaymentProof {
|
||||
proof_type: PaymentProofType::try_from(
|
||||
p.proof_type.unwrap_or(PaymentProofType::Invoice.as_u8()),
|
||||
)?,
|
||||
@@ -630,7 +633,7 @@ where
|
||||
Some(k) => k,
|
||||
None => {
|
||||
return Err(Error::PaymentProofRetrieval(format!(
|
||||
"Invoice proof transaction kernel excess missing",
|
||||
"Early payment proof transaction kernel excess missing",
|
||||
)))
|
||||
}
|
||||
};
|
||||
@@ -655,6 +658,7 @@ where
|
||||
kernel_index: index,
|
||||
kernel_commitment: retrieved_kernel.excess,
|
||||
sender_partial_sig: sender_part_sig,
|
||||
sender_public_nonce,
|
||||
});
|
||||
|
||||
Ok(proof)
|
||||
|
||||
Reference in New Issue
Block a user