Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename improperly named foundation_key #1733

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions sn_auditor/src/dag_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct SpendDagDb {
dag: Arc<RwLock<SpendDag>>,
forwarded_payments: Arc<RwLock<ForwardedPayments>>,
beta_participants: BTreeMap<Hash, String>,
foundation_sk: SecretKey,
encrption_sk: SecretKey,
}

/// Map of Discord usernames to their tracked forwarded payments
Expand All @@ -52,7 +52,7 @@ impl SpendDagDb {
/// Create a new SpendDagDb
/// If a local spend DAG file is found, it will be loaded
/// Else a new DAG will be created containing only Genesis
pub async fn new(path: PathBuf, client: Client, foundation_sk: SecretKey) -> Result<Self> {
pub async fn new(path: PathBuf, client: Client, encrption_sk: SecretKey) -> Result<Self> {
let dag_path = path.join(SPEND_DAG_FILENAME);
let dag = match SpendDag::load_from_file(&dag_path) {
Ok(d) => {
Expand All @@ -71,12 +71,12 @@ impl SpendDagDb {
dag: Arc::new(RwLock::new(dag)),
forwarded_payments: Arc::new(RwLock::new(BTreeMap::new())),
beta_participants: BTreeMap::new(),
foundation_sk,
encrption_sk,
})
}

/// Create a new SpendDagDb from a local file and no network connection
pub fn offline(dag_path: PathBuf, foundation_sk: SecretKey) -> Result<Self> {
pub fn offline(dag_path: PathBuf, encrption_sk: SecretKey) -> Result<Self> {
let path = dag_path
.parent()
.ok_or_else(|| eyre!("Failed to get parent path"))?
Expand All @@ -88,7 +88,7 @@ impl SpendDagDb {
dag: Arc::new(RwLock::new(dag)),
forwarded_payments: Arc::new(RwLock::new(BTreeMap::new())),
beta_participants: BTreeMap::new(),
foundation_sk,
encrption_sk,
})
}

Expand Down Expand Up @@ -272,7 +272,7 @@ impl SpendDagDb {
// find spends with payments
let mut payments: ForwardedPayments = BTreeMap::new();
for spend in all_spends {
let user_name_hash = match spend.reason().get_sender_hash(&self.foundation_sk) {
let user_name_hash = match spend.reason().get_sender_hash(&self.encrption_sk) {
Some(n) => n,
None => continue,
};
Expand Down
16 changes: 8 additions & 8 deletions sn_transfers/src/cashnotes/spend_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl DiscordName {
impl DiscordNameCipher {
/// Create a new DiscordNameCipher from a Discord username
/// it is encrypted to the given pubkey
pub fn create(user_name: &str, foundation_pk: PublicKey) -> Result<Self> {
pub fn create(user_name: &str, encryption_pk: PublicKey) -> Result<Self> {
let discord_name = DiscordName::new(user_name);
let cipher = foundation_pk.encrypt(discord_name.to_sized_bytes());
let cipher = encryption_pk.encrypt(discord_name.to_sized_bytes());
let bytes = cipher.to_bytes();
if bytes.len() > MAX_CIPHER_SIZE {
return Err(TransferError::DiscordNameCipherTooBig);
Expand Down Expand Up @@ -145,24 +145,24 @@ mod tests {

#[test]
fn test_discord_name_cyphering() {
let foundation_sk = SecretKey::random();
let foundation_pk = foundation_sk.public_key();
let encryption_sk = SecretKey::random();
let encryption_pk = encryption_sk.public_key();

let user_name = "JohnDoe#1234";
let user_name_hash = Hash::hash(user_name.as_bytes());
let cypher =
DiscordNameCipher::create(user_name, foundation_pk).expect("cypher creation failed");
DiscordNameCipher::create(user_name, encryption_pk).expect("cypher creation failed");
let recovered_hash = cypher
.decrypt_to_username_hash(&foundation_sk)
.decrypt_to_username_hash(&encryption_sk)
.expect("decryption failed");
assert_eq!(user_name_hash, recovered_hash);

let user_name2 = "JackMa#5678";
let user_name_hash2 = Hash::hash(user_name2.as_bytes());
let cypher =
DiscordNameCipher::create(user_name2, foundation_pk).expect("cypher creation failed");
DiscordNameCipher::create(user_name2, encryption_pk).expect("cypher creation failed");
let recovered_hash = cypher
.decrypt_to_username_hash(&foundation_sk)
.decrypt_to_username_hash(&encryption_sk)
.expect("decryption failed");
assert_eq!(user_name_hash2, recovered_hash);

Expand Down
Loading