WIP: keyfork-shard: traitify functionality #22

Manually merged
ryan merged 8 commits from keyfork-shard-traitify into main 2024-02-19 10:51:04 +00:00
1 changed files with 8 additions and 11 deletions
Showing only changes of commit 6a3018e5e8 - Show all commits

View File

@ -173,7 +173,6 @@ pub trait Format {
reader: impl Read + Send + Sync, reader: impl Read + Send + Sync,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
let mut pm = Terminal::new(stdin(), stdout())?; let mut pm = Terminal::new(stdin(), stdout())?;
let wordlist = Wordlist::default();
// parse input // parse input
let private_keys = private_key_discovery let private_keys = private_key_discovery
@ -207,12 +206,12 @@ pub trait Format {
let validator = MnemonicSetValidator { let validator = MnemonicSetValidator {
word_lengths: [9, 24], word_lengths: [9, 24],
}; };
let [nonce_mnemonic, pubkey_mnemonic] = pm.prompt_validated_wordlist( let [nonce_mnemonic, pubkey_mnemonic] = pm
QRCODE_COULDNT_READ, .prompt_validated_wordlist::<English, _>(
&wordlist, QRCODE_COULDNT_READ,
3, 3,
validator.to_fn(), validator.to_fn(),
)?; )?;
let nonce = nonce_mnemonic let nonce = nonce_mnemonic
.as_bytes() .as_bytes()
@ -228,8 +227,7 @@ pub trait Format {
// create our shared key // create our shared key
let our_key = EphemeralSecret::random(); let our_key = EphemeralSecret::random();
let our_pubkey_mnemonic = let our_pubkey_mnemonic = Mnemonic::from_bytes(PublicKey::from(&our_key).as_bytes())?;
Mnemonic::from_entropy(PublicKey::from(&our_key).as_bytes(), Default::default())?;
let shared_secret = our_key let shared_secret = our_key
.diffie_hellman(&PublicKey::from(their_pubkey)) .diffie_hellman(&PublicKey::from(their_pubkey))
.to_bytes(); .to_bytes();
@ -279,8 +277,7 @@ pub trait Format {
} }
// safety: size of out_bytes is constant and always % 4 == 0 // safety: size of out_bytes is constant and always % 4 == 0
let payload_mnemonic = let payload_mnemonic = unsafe { Mnemonic::from_raw_bytes(&out_bytes) };
unsafe { Mnemonic::from_raw_entropy(&out_bytes, Default::default()) };
#[cfg(feature = "qrcode")] #[cfg(feature = "qrcode")]
{ {