mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-03 04:13:57 +01:00
Proof of Payment Command Line (#260)
* refactor address generation code into libwallet, bool to flag whether to include proof, add sender address in init_send_tx * rustfmt * require payment proof addr as part of init_tx * rustfmt * store payment proof on sender transaction side * rustfmt * change sig to ed25519 sig * rustfmt * add message creation and signature * rustfmt * add payment proof verification function * rustfmt * validate proof on sender side, store proof * rustfmt * fix json tests * fixes and updates to tests * added API functions for converting and retrieving proof addresses * rustfmt * add payment proof to init_send_tx example * rustfmt * incorrect comment * add commands for requesting payment proofs * rustfmt * wire up payment proofs into command line * rustfmt * add address command * rustfmt * added tor sending from owner api * rustfmt
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
//! Functions defining wallet 'addresses', i.e. ed2559 keys based on
|
||||
//! a derivation path
|
||||
|
||||
use crate::grin_util::from_hex;
|
||||
use crate::grin_util::secp::key::SecretKey;
|
||||
use crate::{Error, ErrorKind};
|
||||
use grin_wallet_util::grin_keychain::{ChildNumber, Identifier, Keychain, SwitchCommitmentType};
|
||||
@@ -66,6 +67,20 @@ pub fn ed25519_keypair(sec_key: &SecretKey) -> Result<(DalekSecretKey, DalekPubl
|
||||
Ok((d_skey, d_pub_key))
|
||||
}
|
||||
|
||||
/// Output ed25519 pubkey represented by string
|
||||
pub fn ed25519_parse_pubkey(pub_key: &str) -> Result<DalekPublicKey, Error> {
|
||||
let bytes = from_hex(pub_key.to_owned())
|
||||
.context(ErrorKind::AddressDecoding("Can't parse pubkey".to_owned()))?;
|
||||
match DalekPublicKey::from_bytes(&bytes) {
|
||||
Ok(k) => Ok(k),
|
||||
Err(_) => {
|
||||
return Err(
|
||||
ErrorKind::AddressDecoding("Not a valid public key".to_owned()).to_owned(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the ed25519 public key represented in an onion address
|
||||
pub fn pubkey_from_onion_v3(onion_address: &str) -> Result<DalekPublicKey, Error> {
|
||||
let mut input = onion_address.to_uppercase();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
//! Selection of inputs for building transactions
|
||||
|
||||
use crate::address;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::grin_core::core::amount_to_hr_string;
|
||||
use crate::grin_core::libtx::{
|
||||
@@ -162,17 +163,25 @@ where
|
||||
|
||||
// store extra payment proof info, if required
|
||||
if let Some(ref p) = slate.payment_proof {
|
||||
let sender_address_path = match context.payment_proof_derivation_index {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
"Payment proof derivation index required".to_owned(),
|
||||
))?;
|
||||
}
|
||||
};
|
||||
let sender_key = address::address_from_derivation_path(
|
||||
&keychain,
|
||||
&parent_key_id,
|
||||
sender_address_path,
|
||||
)?;
|
||||
let sender_address = address::ed25519_keypair(&sender_key)?.1;
|
||||
t.payment_proof = Some(StoredProofInfo {
|
||||
receiver_address: p.receiver_address.clone(),
|
||||
receiver_signature: p.receiver_signature.clone(),
|
||||
sender_address_path: match context.payment_proof_derivation_index {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
"Payment proof derivation index required".to_owned(),
|
||||
))?;
|
||||
}
|
||||
},
|
||||
sender_address,
|
||||
sender_address_path,
|
||||
sender_signature: None,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -349,16 +349,16 @@ where
|
||||
let keychain = wallet.keychain(keychain_mask)?;
|
||||
let parent_key_id = wallet.parent_key_id();
|
||||
let excess = slate.calc_excess(&keychain)?;
|
||||
let sig = create_payment_proof_signature(
|
||||
slate.amount,
|
||||
&excess,
|
||||
p.sender_address,
|
||||
address::address_from_derivation_path(&keychain, &parent_key_id, derivation_index)?,
|
||||
)?;
|
||||
let sender_key =
|
||||
address::address_from_derivation_path(&keychain, &parent_key_id, derivation_index)?;
|
||||
let sender_address = address::ed25519_keypair(&sender_key)?.1;
|
||||
let sig =
|
||||
create_payment_proof_signature(slate.amount, &excess, p.sender_address, sender_key)?;
|
||||
tx.payment_proof = Some(StoredProofInfo {
|
||||
receiver_address: p.receiver_address,
|
||||
receiver_signature: p.receiver_signature,
|
||||
sender_address_path: derivation_index,
|
||||
sender_address,
|
||||
sender_signature: Some(sig),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -858,6 +858,9 @@ pub struct StoredProofInfo {
|
||||
pub receiver_signature: Option<DalekSignature>,
|
||||
/// sender address derivation path index
|
||||
pub sender_address_path: u32,
|
||||
/// sender address
|
||||
#[serde(with = "dalek_ser::dalek_pubkey_serde")]
|
||||
pub sender_address: DalekPublicKey,
|
||||
/// sender signature
|
||||
#[serde(with = "dalek_ser::option_dalek_sig_serde")]
|
||||
pub sender_signature: Option<DalekSignature>,
|
||||
|
||||
Reference in New Issue
Block a user