Skip to content

Commit

Permalink
feat!: update encrypt api to take dbc id
Browse files Browse the repository at this point in the history
- This improves the type safety.
  • Loading branch information
oetyng committed Apr 12, 2023
1 parent 23c2a8c commit ef6b308
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dbc_ciphers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl From<(&PublicAddress, &DerivationIndex, RevealedAmount)> for DbcCiphers {
let derivation_index_cipher = public_address.encrypt(derivation_index);
let revealed_amount_cipher = public_address
.new_dbc_id(derivation_index)
.encrypt(revealed_amount);
.encrypt(&revealed_amount);

Self {
public_address: *public_address,
Expand Down
2 changes: 1 addition & 1 deletion src/dbc_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl DbcId {
self.0.verify(sig, msg)
}

pub fn encrypt(&self, revealed_amount: RevealedAmount) -> Ciphertext {
pub fn encrypt(&self, revealed_amount: &RevealedAmount) -> Ciphertext {
self.0.encrypt(revealed_amount.to_bytes())
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/transaction/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// This SAFE Network Software is licensed under the BSD-3-Clause license.
// Please see the LICENSE file for more details.

use crate::{rand::RngCore, BlindedAmount, BlindingFactor, DerivedKey, Error, Result};
use crate::{rand::RngCore, BlindedAmount, BlindingFactor, DbcId, DerivedKey, Error, Result};

use blsttc::{rand::CryptoRng, Ciphertext, PublicKey};
use blsttc::{rand::CryptoRng, Ciphertext};
use bulletproofs::PedersenGens;
use std::convert::TryFrom;

Expand Down Expand Up @@ -56,9 +56,9 @@ impl RevealedAmount {
self.blinding_factor
}

/// Encrypt this instance to given public key, producing `Ciphertext`.
pub fn encrypt(&self, public_key: &PublicKey) -> Ciphertext {
public_key.encrypt(self.to_bytes())
/// Encrypt this instance to given `DbcId`, producing `Ciphertext`.
pub fn encrypt(&self, dbc_id: &DbcId) -> Ciphertext {
dbc_id.encrypt(self)
}

/// Build RevealedAmount from fixed size byte array.
Expand Down

0 comments on commit ef6b308

Please sign in to comment.