Skip to content

Commit

Permalink
chore: removes reference to transmission key
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks committed Nov 3, 2023
1 parent 23b2ec4 commit 62a4124
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
33 changes: 13 additions & 20 deletions ironfish-rust/src/keys/public_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ pub const PUBLIC_ADDRESS_SIZE: usize = 32;
/// transmission key. Using the incoming_viewing_key allows
/// the creation of a unique public addresses without revealing the viewing key.
#[derive(Clone, Copy)]
pub struct PublicAddress {
/// The transmission key is the result of combining the diversifier with the
/// incoming viewing key (a non-reversible operation). Together, the two
/// form a public address to which payments can be sent.
pub(crate) transmission_key: SubgroupPoint,
}
pub struct PublicAddress(pub SubgroupPoint);

impl PublicAddress {
/// Initialize a public address from its 32 byte representation.
pub fn new(address_bytes: &[u8; PUBLIC_ADDRESS_SIZE]) -> Result<PublicAddress, IronfishError> {
let transmission_key = PublicAddress::load_transmission_key(&address_bytes[0..])?;
let public_address = PublicAddress::load_public_address(&address_bytes[0..])?;

Ok(PublicAddress { transmission_key })
Ok(PublicAddress(public_address))
}

/// Load a public address from a Read implementation (e.g: socket, file)
Expand All @@ -48,9 +43,7 @@ impl PublicAddress {
}

pub fn from_view_key(view_key: &IncomingViewKey) -> PublicAddress {
PublicAddress {
transmission_key: *PUBLIC_KEY_GENERATOR * view_key.view_key,
}
PublicAddress(*PUBLIC_KEY_GENERATOR * view_key.view_key)
}

/// Convert a String of hex values to a PublicAddress. The String must
Expand All @@ -65,7 +58,7 @@ impl PublicAddress {

/// Retrieve the public address in byte form.
pub fn public_address(&self) -> [u8; PUBLIC_ADDRESS_SIZE] {
self.transmission_key.to_bytes()
self.0.to_bytes()
}

/// Retrieve the public address in hex form.
Expand All @@ -80,15 +73,15 @@ impl PublicAddress {
Ok(())
}

pub(crate) fn load_transmission_key(
transmission_key_bytes: &[u8],
pub(crate) fn load_public_address(
public_address_bytes: &[u8],
) -> Result<SubgroupPoint, IronfishError> {
assert!(transmission_key_bytes.len() == 32);
let transmission_key_non_prime =
SubgroupPoint::from_bytes(transmission_key_bytes.try_into().unwrap());
assert!(public_address_bytes.len() == 32);
let public_address_non_prime =
SubgroupPoint::from_bytes(public_address_bytes.try_into().unwrap());

if transmission_key_non_prime.is_some().into() {
Ok(transmission_key_non_prime.unwrap())
if public_address_non_prime.is_some().into() {
Ok(public_address_non_prime.unwrap())
} else {
Err(IronfishError::new(IronfishErrorKind::InvalidPaymentAddress))
}
Expand All @@ -109,7 +102,7 @@ impl std::cmp::PartialEq for PublicAddress {

#[cfg(test)]
mod test {
use crate::{keys::PUBLIC_ADDRESS_SIZE, PublicAddress, SaplingKey};
use crate::{keys::{PUBLIC_ADDRESS_SIZE, PublicAddress}, SaplingKey};

#[test]
fn public_address_validation() {
Expand Down
10 changes: 5 additions & 5 deletions ironfish-rust/src/keys/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_diffie_hellman_shared_key() {
let secret_key = key_pair.secret();
let public_key = key_pair.public();

let shared_secret1 = shared_secret(secret_key, &address1.transmission_key, public_key);
let shared_secret1 = shared_secret(secret_key, &address1.0, public_key);
let shared_secret2 = shared_secret(&key1.incoming_viewing_key.view_key, public_key, public_key);
assert_eq!(shared_secret1, shared_secret2);
}
Expand All @@ -44,13 +44,13 @@ fn test_diffie_hellman_shared_key_with_other_key() {
let secret_key = key_pair.secret();
let public_key = key_pair.public();

let shared_secret1 = shared_secret(secret_key, &address.transmission_key, public_key);
let shared_secret1 = shared_secret(secret_key, &address.0, public_key);
let shared_secret2 = shared_secret(&key.incoming_viewing_key.view_key, public_key, public_key);
assert_eq!(shared_secret1, shared_secret2);

let shared_secret_third_party1 = shared_secret(
secret_key,
&third_party_address.transmission_key,
&third_party_address.0,
public_key,
);
assert_ne!(shared_secret1, shared_secret_third_party1);
Expand Down Expand Up @@ -90,8 +90,8 @@ fn test_serialization() {
.expect("Should be able to construct address from valid bytes");

assert_eq!(
ExtendedPoint::from(read_back_address.transmission_key).to_affine(),
ExtendedPoint::from(public_address.transmission_key).to_affine()
ExtendedPoint::from(read_back_address.0).to_affine(),
ExtendedPoint::from(public_address.0).to_affine()
)
}

Expand Down
10 changes: 5 additions & 5 deletions ironfish-rust/src/merkle_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl MerkleNote {
let public_key = diffie_hellman_keys.public();

let mut key_bytes = [0; 64];
key_bytes[..32].copy_from_slice(&note.owner.transmission_key.to_bytes());
key_bytes[..32].copy_from_slice(&note.owner.0.to_bytes());
key_bytes[32..].clone_from_slice(secret_key.to_repr().as_ref());

let encryption_key = calculate_key_for_encryption_keys(
Expand Down Expand Up @@ -133,7 +133,7 @@ impl MerkleNote {

let encrypted_note = note.encrypt(&shared_secret(
secret_key,
&note.owner.transmission_key,
&note.owner.0,
public_key,
));

Expand Down Expand Up @@ -204,11 +204,11 @@ impl MerkleNote {

let note_encryption_keys: [u8; ENCRYPTED_SHARED_KEY_SIZE] =
aead::decrypt(&encryption_key, &self.note_encryption_keys)?;
let transmission_key = PublicAddress::load_transmission_key(&note_encryption_keys[..32])?;
let public_address = PublicAddress::load_public_address(&note_encryption_keys[..32])?;
let secret_key = read_scalar(&note_encryption_keys[32..])?;
let shared_key = shared_secret(&secret_key, &transmission_key, &self.ephemeral_public_key);
let shared_key = shared_secret(&secret_key, &public_address, &self.ephemeral_public_key);
let note =
Note::from_spender_encrypted(transmission_key, &shared_key, &self.encrypted_note)?;
Note::from_spender_encrypted(public_address, &shared_key, &self.encrypted_note)?;
note.verify_commitment(self.note_commitment)?;
Ok(note)
}
Expand Down
12 changes: 6 additions & 6 deletions ironfish-rust/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ impl<'a> Note {
/// This function allows the owner to decrypt the note using the derived
/// shared secret and their own view key.
pub(crate) fn from_spender_encrypted(
transmission_key: SubgroupPoint,
secret_key: SubgroupPoint,
shared_secret: &[u8; 32],
encrypted_bytes: &[u8; ENCRYPTED_NOTE_SIZE + aead::MAC_SIZE],
) -> Result<Self, IronfishError> {
let (randomness, asset_id, value, memo, sender) =
Note::decrypt_note_parts(shared_secret, encrypted_bytes)?;

let owner = PublicAddress { transmission_key };
let owner = PublicAddress(secret_key);

Ok(Note {
owner,
Expand Down Expand Up @@ -278,9 +278,9 @@ impl<'a> Note {
commitment_full_point(
self.asset_generator(),
self.value,
self.owner.transmission_key,
self.owner.0,
self.randomness,
self.sender.transmission_key,
self.sender.0,
)
}

Expand Down Expand Up @@ -410,7 +410,7 @@ mod test {
let dh_public = diffie_hellman_keys.public();

let public_shared_secret =
shared_secret(dh_secret, &public_address.transmission_key, dh_public);
shared_secret(dh_secret, &public_address.0, dh_public);
let note = Note::new(public_address, 42, "", NATIVE_ASSET, sender_address);
let encryption_result = note.encrypt(&public_shared_secret);

Expand All @@ -435,7 +435,7 @@ mod test {
);

let spender_decrypted = Note::from_spender_encrypted(
note.owner.transmission_key,
note.owner.0,
&public_shared_secret,
&encryption_result,
)
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/transaction/mints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl MintDescription {
public_inputs[0] = randomized_public_key_point.get_u();
public_inputs[1] = randomized_public_key_point.get_v();

let public_address_point = ExtendedPoint::from(self.owner.transmission_key).to_affine();
let public_address_point = ExtendedPoint::from(self.owner.0).to_affine();
public_inputs[2] = public_address_point.get_u();
public_inputs[3] = public_address_point.get_v();

Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/transaction/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl OutputBuilder {

let circuit = Output {
value_commitment: Some(self.value_commitment.clone()),
payment_address: Some(self.note.owner.transmission_key),
payment_address: Some(self.note.owner.0),
commitment_randomness: Some(self.note.randomness),
esk: Some(*diffie_hellman_keys.secret()),
asset_id: *self.note.asset_id().as_bytes(),
Expand Down
4 changes: 2 additions & 2 deletions ironfish-rust/src/transaction/spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ impl SpendBuilder {
let circuit = Spend {
value_commitment: Some(self.value_commitment.clone()),
proof_generation_key: Some(spender_key.sapling_proof_generation_key()),
payment_address: Some(self.note.owner.transmission_key),
payment_address: Some(self.note.owner.0),
auth_path: self.auth_path.clone(),
commitment_randomness: Some(self.note.randomness),
anchor: Some(self.root_hash),
ar: Some(*public_key_randomness),
sender_address: Some(self.note.sender.transmission_key),
sender_address: Some(self.note.sender.0),
};

// Proof that the spend was valid and successful for the provided owner
Expand Down

0 comments on commit 62a4124

Please sign in to comment.