Compare commits

..

1 Commits

Author SHA1 Message Date
Ryan Heywood 8ddebfc3bb
keyfork-shard: traitify functionality 2024-02-12 08:46:27 -05:00
1 changed files with 10 additions and 18 deletions

View File

@ -180,7 +180,9 @@ pub trait Format {
// receive remote data via scanning QR code from camera // receive remote data via scanning QR code from camera
#[cfg(feature = "qrcode")] #[cfg(feature = "qrcode")]
{ {
pm.prompt_message(PromptMessage::Text(QRCODE_PROMPT.to_string()))?; pm.prompt_message(PromptMessage::Text(
"Press enter, then present QR code to camera".to_string(),
))?;
if let Ok(Some(hex)) = if let Ok(Some(hex)) =
keyfork_qrcode::scan_camera(std::time::Duration::from_secs(30), 0) keyfork_qrcode::scan_camera(std::time::Duration::from_secs(30), 0)
{ {
@ -188,7 +190,9 @@ pub trait Format {
nonce_data = Some(decoded_data[..12].try_into().map_err(|_| InvalidData)?); nonce_data = Some(decoded_data[..12].try_into().map_err(|_| InvalidData)?);
pubkey_data = Some(decoded_data[12..].try_into().map_err(|_| InvalidData)?) pubkey_data = Some(decoded_data[12..].try_into().map_err(|_| InvalidData)?)
} else { } else {
pm.prompt_message(PromptMessage::Text(QRCODE_ERROR.to_string()))?; pm.prompt_message(PromptMessage::Text(
"Unable to detect QR code, falling back to text".to_string(),
))?;
}; };
} }
@ -199,12 +203,8 @@ 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] =
QRCODE_COULDNT_READ, pm.prompt_validated_wordlist("Their words: ", &wordlist, 3, validator.to_fn())?;
&wordlist,
3,
validator.to_fn(),
)?;
let nonce = nonce_mnemonic let nonce = nonce_mnemonic
.as_bytes() .as_bytes()
@ -279,21 +279,13 @@ pub trait Format {
use keyfork_qrcode::{qrencode, ErrorCorrection}; use keyfork_qrcode::{qrencode, ErrorCorrection};
let mut qrcode_data = our_pubkey_mnemonic.to_bytes(); let mut qrcode_data = our_pubkey_mnemonic.to_bytes();
qrcode_data.extend(payload_mnemonic.as_bytes()); qrcode_data.extend(payload_mnemonic.as_bytes());
if let Ok(qrcode) = qrencode(&smex::encode(&qrcode_data), ErrorCorrection::Highest) { if let Ok(qrcode) = qrencode(&smex::encode(&qrcode_data), ErrorCorrection::Lowest) {
pm.prompt_message(PromptMessage::Text(
concat!(
"A QR code will be displayed after this prompt. ",
"Send the QR code back to the operator combining the shards. ",
"Nobody else should scan this QR code."
)
.to_string(),
))?;
pm.prompt_message(PromptMessage::Data(qrcode))?; pm.prompt_message(PromptMessage::Data(qrcode))?;
} }
} }
pm.prompt_message(PromptMessage::Text(format!( pm.prompt_message(PromptMessage::Text(format!(
"Upon request, these words should be sent: {our_pubkey_mnemonic} {payload_mnemonic}" "Our words: {our_pubkey_mnemonic} {payload_mnemonic}"
)))?; )))?;
Ok(()) Ok(())