This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dj8yfo/delete_key_action
feat: `DeleteKey` action
- Loading branch information
Showing
32 changed files
with
296 additions
and
160 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
use crate::parsing; | ||
use ledger_device_sdk::ui::gadgets::Field; | ||
|
||
use crate::{ | ||
app_ui::fields_writer::FieldsWriter, | ||
utils::types::capped_string::ElipsisFields, | ||
}; | ||
use crate::{app_ui::fields_writer::FieldsWriter, utils::types::capped_string::ElipsisFields}; | ||
|
||
pub fn format( | ||
_create_account: &parsing::types::CreateAccount, | ||
writer: &'_ mut FieldsWriter<'_, 1>, | ||
) { | ||
match writer.push_fields(ElipsisFields::one(Field { | ||
name: "Action type:", | ||
value: "Create Account", | ||
})) { | ||
Ok(..) => {} | ||
Err(_err) => panic!("wrong total fields in tx prefix FieldsWriter"), | ||
} | ||
writer | ||
.push_fields(ElipsisFields::one(Field { | ||
name: "Action type:", | ||
value: "Create Account", | ||
})) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
use crate::parsing; | ||
use ledger_device_sdk::ui::gadgets::Field; | ||
|
||
use crate::{ | ||
app_ui::fields_writer::FieldsWriter, | ||
utils::types::capped_string::ElipsisFields, | ||
}; | ||
use crate::{app_ui::fields_writer::FieldsWriter, utils::types::capped_string::ElipsisFields}; | ||
|
||
pub fn format<'b, 'a: 'b>( | ||
delete_account: &'a parsing::types::DeleteAccount, | ||
writer: &'_ mut FieldsWriter<'b, 3>, | ||
) { | ||
match writer.push_fields(ElipsisFields::one(Field { | ||
name: "Action type:", | ||
value: "Delete Account", | ||
})) { | ||
Ok(..) => {} | ||
Err(_err) => panic!("wrong total fields in tx prefix FieldsWriter"), | ||
} | ||
writer | ||
.push_fields(ElipsisFields::one(Field { | ||
name: "Action type:", | ||
value: "Delete Account", | ||
})) | ||
.unwrap(); | ||
|
||
let beneficiary_id = delete_account.beneficiary_id.ui_fields("Beneficiary"); | ||
match writer.push_fields(beneficiary_id) { | ||
Ok(..) => {} | ||
Err(_err) => panic!("wrong total fields in tx prefix FieldsWriter"), | ||
} | ||
writer.push_fields(beneficiary_id).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use ledger_device_sdk::ui::gadgets::Field; | ||
|
||
use crate::{ | ||
app_ui::fields_writer::FieldsWriter, | ||
parsing::{self, types::tx_public_key::TxPublicKey}, | ||
utils::types::{capped_string::ElipsisFields, fmt_buffer::FmtBuffer}, | ||
}; | ||
|
||
pub struct FieldsContext { | ||
buffer: FmtBuffer<100>, | ||
} | ||
|
||
impl FieldsContext { | ||
pub fn new() -> Self { | ||
Self { | ||
buffer: FmtBuffer::new(), | ||
} | ||
} | ||
|
||
fn format_public_key(&mut self, public_key: &TxPublicKey) { | ||
match public_key { | ||
TxPublicKey::ED25519(arr) => { | ||
let mut tmp_buf = [0u8; 50]; | ||
// NOTE: expecting `tmp_buf` to be always large enough : 1.4 * 32 | ||
let len = bs58::encode(arr).onto(&mut tmp_buf[..]).unwrap(); | ||
// expecting `bs58` to always produce correct strings | ||
// https://docs.rs/bs58/0.5.0/src/bs58/encode.rs.html#201 | ||
let bs58_str = core::str::from_utf8(&tmp_buf[..len]).unwrap(); | ||
|
||
self.buffer.write_str("ed25519:"); | ||
self.buffer.write_str(bs58_str); | ||
} | ||
TxPublicKey::SECP256K1(arr) => { | ||
let mut tmp_buf = [0u8; 90]; | ||
|
||
// expecting `tmp_buf` to be always large enough: 1.4 * 64 | ||
let len = bs58::encode(arr).onto(&mut tmp_buf[..]).unwrap(); | ||
// expecting `bs58` to always produce correct strings | ||
// https://docs.rs/bs58/0.5.0/src/bs58/encode.rs.html#201 | ||
let bs58_str = core::str::from_utf8(&tmp_buf[..len]).unwrap(); | ||
|
||
self.buffer.write_str("secp256k1:"); | ||
self.buffer.write_str(bs58_str); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn format<'b, 'a: 'b>( | ||
delete_key: &parsing::types::DeleteKey, | ||
field_context: &'a mut FieldsContext, | ||
writer: &'_ mut FieldsWriter<'b, 2>, | ||
) { | ||
field_context.format_public_key(&delete_key.public_key); | ||
writer | ||
.push_fields(ElipsisFields::one(Field { | ||
name: "Action type:", | ||
value: "Delete Key", | ||
})) | ||
.unwrap(); | ||
|
||
writer | ||
.push_fields(ElipsisFields::one(Field { | ||
name: "Public Key:", | ||
value: field_context.buffer.as_str(), | ||
})) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
use crate::{AppSW, parsing::{HashingStream, SingleTxStream, types::CreateAccount, borsh::BorshDeserialize}}; | ||
use crate::sign_ui; | ||
use crate::{ | ||
parsing::{borsh::BorshDeserialize, types::CreateAccount, HashingStream, SingleTxStream}, | ||
AppSW, | ||
}; | ||
|
||
pub fn handle(stream: &mut HashingStream<SingleTxStream<'_>>, ordinal_action: u32, total_actions: u32) -> Result<(), AppSW> { | ||
let create_account = CreateAccount::deserialize_reader(stream).map_err(|_err| AppSW::TxParsingFail)?; | ||
pub fn handle( | ||
stream: &mut HashingStream<SingleTxStream<'_>>, | ||
ordinal_action: u32, | ||
total_actions: u32, | ||
) -> Result<(), AppSW> { | ||
let create_account = | ||
CreateAccount::deserialize_reader(stream).map_err(|_err| AppSW::TxParsingFail)?; | ||
|
||
#[cfg(feature = "speculos")] | ||
create_account.debug_print(); | ||
|
||
|
||
if !sign_ui::action::ui_display_create_account(&create_account, ordinal_action + 1, total_actions) { | ||
if !sign_ui::action::ui_display_create_account( | ||
&create_account, | ||
ordinal_action + 1, | ||
total_actions, | ||
) { | ||
return Err(AppSW::Deny); | ||
} | ||
Ok(()) | ||
|
||
} |
Oops, something went wrong.