Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.
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
8 changes: 5 additions & 3 deletions crates/diem-wallet/src/key_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ pub struct KeyFactory {
}

impl KeyFactory {
const MNEMONIC_SALT_PREFIX: &'static [u8] = b"DIEM WALLET: mnemonic salt prefix$";
const MAIN_KEY_SALT: &'static [u8] = b"DIEM WALLET: main key salt$";
const INFO_PREFIX: &'static [u8] = b"DIEM WALLET: derived key$";
//////// 0L ////////
const MNEMONIC_SALT_PREFIX: &'static [u8] = b"0L WALLET: UNREST, FIRES, AND VIOLENCE AS PROTESTS RAGE ACROSS US: mnemonic salt prefix$"; // https://markets.businessinsider.com/news/stocks/why-stock-market-rising-amid-nationwide-police-brutality-protests-2020-6-1029273996
const MAIN_KEY_SALT: &'static [u8] = b"0L WALLET: 30 MILLION AMERICANS HAVE FILED INITIAL UNEMPLOYMENT CLAIMS: master key salt$"; // https://www.cnn.com/2020/04/30/economy/unemployment-benefits-coronavirus/index.html
const INFO_PREFIX: &'static [u8] = b"0L WALLET: US DEATHS NEAR 100,000, AN INCALCULABLE LOSS: derived key$"; // https://www.nytimes.com/interactive/2020/05/24/us/us-coronavirus-deaths-100000.html

/// Instantiate a new KeyFactor from a Seed, where the [u8; 64] raw bytes of the Seed are used
/// to derive both the Main and its child keys
pub fn new(seed: &Seed) -> Result<Self> {
Expand Down
2 changes: 1 addition & 1 deletion crates/diem-wallet/src/wallet_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl WalletLibrary {

/// Constructor that instantiates a new WalletLibrary from Mnemonic
pub fn new_from_mnemonic(mnemonic: Mnemonic) -> Self {
let seed = Seed::new(&mnemonic, "DIEM");
let seed = Seed::new(&mnemonic, "0L"); //////// 0L ////////
WalletLibrary {
mnemonic,
key_factory: KeyFactory::new(&seed).unwrap(),
Expand Down
20 changes: 20 additions & 0 deletions ol/keys/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ fn wallet() {
assert!(vec_addresses.len() == 1);
}

#[test]
fn fixture_wallet() {
use diem_wallet::Mnemonic;

// alice
let mnemonic_string = "talent sunset lizard pill fame nuclear spy noodle basket okay critic grow sleep legend hurry pitch blanket clerk impose rough degree sock insane purse";


let mut wallet = WalletLibrary::new_from_mnemonic(Mnemonic::from(&mnemonic_string).unwrap());

let (main_addr, child_number) = wallet.new_address().unwrap();
println!("wallet\n:{:?} === {:x}", child_number, main_addr);

let (_, acc, _) = get_account_from_mnem(mnemonic_string.to_owned()).unwrap();
dbg!(&acc);

// expect the same address for alice
assert!(&acc.to_string() == "4C613C2F4B1E67CA8D98A542EE3F59F5");
}

// TODO: this is duplicated with ol/types/config because of a dependency cycle. Move to Global constants?
/// check this is CI environment
pub static IS_TEST: Lazy<bool> = Lazy::new(|| {
Expand Down