Onion V3 address consistency (#309)

* initial addition of ov3

* move libwallet address functions into OnionV3Address type

* incorporate OnionV3 type where possible

* factor out manual dalek pubkey manipulations

* corrections due to test failures

* change json-rpc example to use ov3 for payment proof recipient address
This commit is contained in:
Yeastplume
2020-01-24 13:02:09 +00:00
committed by GitHub
parent 3091bd9701
commit a2560179ae
23 changed files with 395 additions and 262 deletions
+11 -9
View File
@@ -22,6 +22,7 @@ use crate::grin_core::ser;
use crate::grin_util;
use crate::grin_util::secp::key::SecretKey;
use crate::grin_util::Mutex;
use crate::util::OnionV3Address;
use crate::api_impl::owner_updater::StatusMessage;
use crate::grin_keychain::{Identifier, Keychain};
@@ -92,7 +93,8 @@ where
let parent_key_id = w.parent_key_id();
let k = w.keychain(keychain_mask)?;
let sec_addr_key = address::address_from_derivation_path(&k, &parent_key_id, index)?;
Ok(address::ed25519_keypair(&sec_addr_key)?.1)
let addr = OnionV3Address::from_private(&sec_addr_key.0)?;
Ok(addr.to_ed25519()?)
}
/// retrieve outputs
@@ -284,9 +286,9 @@ where
Ok(PaymentProof {
amount: amount,
excess: excess,
recipient_address: address::onion_v3_from_pubkey(&proof.receiver_address)?,
recipient_address: OnionV3Address::from_bytes(proof.receiver_address.to_bytes()),
recipient_sig: r_sig,
sender_address: address::onion_v3_from_pubkey(&proof.sender_address)?,
sender_address: OnionV3Address::from_bytes(proof.sender_address.to_bytes()),
sender_sig: s_sig,
})
}
@@ -366,11 +368,11 @@ where
let k = w.keychain(keychain_mask)?;
let sec_addr_key = address::address_from_derivation_path(&k, &parent_key_id, deriv_path)?;
let sender_address = address::ed25519_keypair(&sec_addr_key)?.1;
let sender_address = OnionV3Address::from_private(&sec_addr_key.0)?;
slate.payment_proof = Some(PaymentInfo {
sender_address,
receiver_address: a,
sender_address: sender_address.to_ed25519()?,
receiver_address: a.to_ed25519()?,
receiver_signature: None,
});
@@ -889,7 +891,7 @@ where
C: NodeClient + 'a,
K: Keychain + 'a,
{
let sender_pubkey = address::pubkey_from_onion_v3(&proof.sender_address)?;
let sender_pubkey = proof.sender_address.to_ed25519()?;
let msg = tx::payment_proof_message(proof.amount, &proof.excess, sender_pubkey)?;
let (mut client, parent_key_id, keychain) = {
@@ -921,14 +923,14 @@ where
};
// Check Sigs
let recipient_pubkey = address::pubkey_from_onion_v3(&proof.recipient_address)?;
let recipient_pubkey = proof.recipient_address.to_ed25519()?;
if let Err(_) = recipient_pubkey.verify(&msg, &proof.recipient_sig) {
return Err(ErrorKind::PaymentProof(
"Invalid recipient signature".to_owned(),
))?;
};
let sender_pubkey = address::pubkey_from_onion_v3(&proof.sender_address)?;
let sender_pubkey = proof.sender_address.to_ed25519()?;
if let Err(_) = sender_pubkey.verify(&msg, &proof.sender_sig) {
return Err(ErrorKind::PaymentProof(
"Invalid sender signature".to_owned(),
+7 -5
View File
@@ -20,8 +20,8 @@ use crate::grin_util::secp::pedersen;
use crate::slate_versions::ser as dalek_ser;
use crate::slate_versions::SlateVersion;
use crate::types::OutputData;
use grin_wallet_util::OnionV3Address;
use ed25519_dalek::PublicKey as DalekPublicKey;
use ed25519_dalek::Signature as DalekSignature;
/// Send TX API Args
@@ -94,8 +94,8 @@ pub struct InitTxArgs {
#[serde(with = "secp_ser::opt_string_or_u64")]
pub ttl_blocks: Option<u64>,
/// If set, require a payment proof for the particular recipient
#[serde(with = "dalek_ser::option_dalek_pubkey_serde")]
pub payment_proof_recipient_address: Option<DalekPublicKey>,
#[serde(with = "dalek_ser::option_ov3_serde")]
pub payment_proof_recipient_address: Option<OnionV3Address>,
/// If true, just return an estimate of the resulting slate, containing fees and amounts
/// locked without actually locking outputs or creating the transaction. Note if this is set to
/// 'true', the amount field in the slate will contain the total amount locked, not the provided
@@ -237,12 +237,14 @@ pub struct PaymentProof {
)]
pub excess: pedersen::Commitment,
/// Recipient Wallet Address (Onion V3)
pub recipient_address: String,
#[serde(with = "dalek_ser::ov3_serde")]
pub recipient_address: OnionV3Address,
/// Recipient Signature
#[serde(with = "dalek_ser::dalek_sig_serde")]
pub recipient_sig: DalekSignature,
/// Sender Wallet Address (Onion V3)
pub sender_address: String,
#[serde(with = "dalek_ser::ov3_serde")]
pub sender_address: OnionV3Address,
/// Sender Signature
#[serde(with = "dalek_ser::dalek_sig_serde")]
pub sender_sig: DalekSignature,