Skip to content

Commit

Permalink
feat(node): use separate keys of Foundation and Royalty
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed May 15, 2024
1 parent bbb2033 commit 3898588
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
9 changes: 2 additions & 7 deletions sn_client/src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::{wallet::send, Client, Error, Result};
use sn_transfers::{load_genesis_wallet, HotWallet, MainPubkey, NanoTokens};
use sn_transfers::{load_genesis_wallet, HotWallet, NanoTokens, FOUNDATION_PK};

const INITIAL_FAUCET_BALANCE: NanoTokens = NanoTokens::from(900000000000000000);

/// Foundation wallet public key (used to receive initial disbursment from the genesis wallet)
const FOUNDATION_PK: &str = "a4bd3f928c585a63ab6070337316c1832bffd92be8efe9b235ec1c631f03b4bb91e29bbad34994ddf9f77d9858ddb0bb"; // DevSkim: ignore DS173237

/// Use the client to load the faucet wallet from the genesis Wallet.
/// With all balance transferred from the genesis_wallet to the faucet_wallet.
pub async fn fund_faucet_from_genesis_wallet(
Expand Down Expand Up @@ -42,8 +39,6 @@ pub async fn fund_faucet_from_genesis_wallet(
let genesis_wallet = load_genesis_wallet()?;
let genesis_balance = genesis_wallet.balance();

let foundation_key = MainPubkey::from_hex(FOUNDATION_PK)?; // DevSkim: ignore DS117838

let (foundation_cashnote, faucet_cashnote) = {
println!("Sending {INITIAL_FAUCET_BALANCE} from genesis to faucet wallet..");
debug!("Sending {INITIAL_FAUCET_BALANCE} from genesis to faucet wallet..");
Expand Down Expand Up @@ -76,7 +71,7 @@ pub async fn fund_faucet_from_genesis_wallet(
let foundation_cashnote = send(
genesis_wallet,
foundation_balance,
foundation_key,
*FOUNDATION_PK,
client,
true,
)
Expand Down
4 changes: 0 additions & 4 deletions sn_transfers/src/cashnotes/spend_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use crate::GENESIS_CASHNOTE_SK;
use bls::{Ciphertext, PublicKey, SecretKey};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use xor_name::XorName;

Expand Down Expand Up @@ -71,9 +70,6 @@ impl SpendReason {
}
}

lazy_static! {
pub static ref FOUNDATION_PK: PublicKey = crate::NETWORK_ROYALTIES_PK.public_key();
}
const MAX_CIPHER_SIZE: usize = std::u8::MAX as usize;
const DERIVATION_INDEX_SIZE: usize = 32;
const HASH_SIZE: usize = 32;
Expand Down
8 changes: 2 additions & 6 deletions sn_transfers/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
use super::wallet::HotWallet;

use crate::{
wallet::Result as WalletResult, CashNote, DerivationIndex, Input, MainPubkey, MainSecretKey,
NanoTokens, SignedSpend, SpendReason, Transaction, TransactionBuilder,
TransferError as CashNoteError,
wallet::Result as WalletResult, CashNote, DerivationIndex, Input, MainSecretKey, NanoTokens,
SignedSpend, SpendReason, Transaction, TransactionBuilder, TransferError as CashNoteError,
};

use bls::SecretKey;
Expand Down Expand Up @@ -75,9 +74,6 @@ lazy_static! {
Err(err) => panic!("Failed to create genesis CashNote: {err:?}"),
}
};

/// Public key where network royalties payments are expected to be made to.
pub static ref NETWORK_ROYALTIES_PK: MainPubkey = *GENESIS_CASHNOTE.main_pubkey();
}

/// Return if provided Transaction is genesis parent tx.
Expand Down
29 changes: 28 additions & 1 deletion sn_transfers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use error::{Result, TransferError};
pub use genesis::{
calculate_royalties_fee, create_first_cash_note_from_key, get_faucet_data_dir,
is_genesis_parent_tx, is_genesis_spend, load_genesis_wallet, Error as GenesisError,
GENESIS_CASHNOTE, GENESIS_CASHNOTE_SK, NETWORK_ROYALTIES_PK, TOTAL_SUPPLY,
GENESIS_CASHNOTE, GENESIS_CASHNOTE_SK, TOTAL_SUPPLY,
};
pub use transfers::{CashNoteRedemption, OfflineTransfer, Transfer};
pub use wallet::{
Expand All @@ -39,6 +39,33 @@ pub use wallet::{
QUOTE_EXPIRATION_SECS, WALLET_DIR_NAME,
};

use lazy_static::lazy_static;

/// The following PKs shall be updated to match its correspondent SKs before the formal release
///
/// Foundation wallet public key (used to receive initial disbursment from the genesis wallet)
const FOUNDATION_PK_STR: &str = "8f73b97377f30bed96df1c92daf9f21b4a82c862615439fab8095e68860a5d0dff9f97dba5aef503a26c065e5cb3c7ca"; // DevSkim: ignore DS173237
/// Public key where network royalties payments are expected to be made to.
const NETWORK_ROYALTIES_STR: &str = "b4243ec9ceaec374ef992684cd911b209758c5de53d1e406b395bc37ebc8ce50e68755ea6d32da480ae927e1af4ddadb"; // DevSkim: ignore DS173237

lazy_static! {
pub static ref FOUNDATION_PK: MainPubkey = {
match MainPubkey::from_hex(FOUNDATION_PK_STR) {
Ok(pk) => pk,
Err(err) => panic!("Failed to parse hard-coded foundation PK: {err:?}"),
}
};
}

lazy_static! {
pub static ref NETWORK_ROYALTIES_PK: MainPubkey = {
match MainPubkey::from_hex(NETWORK_ROYALTIES_STR) {
Ok(pk) => pk,
Err(err) => panic!("Failed to parse hard-coded network royalty PK: {err:?}"),
}
};
}

// re-export crates used in our public API
pub use bls::{self, rand, Ciphertext, Signature};

Expand Down

0 comments on commit 3898588

Please sign in to comment.