Skip to content

Commit

Permalink
chore: add delete_key_ed25519 example
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 25, 2024
1 parent 84ab665 commit 619ac75
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ path = "examples/sign_transaction/delete_account_short.rs"
name = "sign_delete_account_long"
path = "examples/sign_transaction/delete_account_long.rs"

[[example]]
name = "sign_delete_key_ed25519"
path = "examples/sign_transaction/delete_key_ed25519.rs"

[[example]]
name = "blind_sign_transaction"

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ RUST_LOG=sign_delete_account_short,near_ledger=info cargo run --example sign_del
RUST_LOG=sign_delete_account_long,near_ledger=info cargo run --example sign_delete_account_long
```

#### Delete key (ed25519)

```bash
RUST_LOG=sign_delete_key_ed25519,near_ledger=info cargo run --example sign_delete_key_ed25519
```

#### Transfer

```bash
Expand Down
2 changes: 1 addition & 1 deletion examples/get_public_key/display.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use near_ledger::{NEARLedgerError, get_public_key_with_display_flag};
use near_ledger::{get_public_key_with_display_flag, NEARLedgerError};
use slip10::BIP32Path;

#[path = "../common/lib.rs"]
Expand Down
2 changes: 1 addition & 1 deletion examples/get_public_key/silent.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use near_ledger::{NEARLedgerError, get_public_key_with_display_flag};
use near_ledger::{get_public_key_with_display_flag, NEARLedgerError};
use slip10::BIP32Path;

#[path = "../common/lib.rs"]
Expand Down
2 changes: 1 addition & 1 deletion examples/get_wallet_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use near_ledger::{NEARLedgerError, get_wallet_id};
use near_ledger::{get_wallet_id, NEARLedgerError};
use slip10::BIP32Path;

#[path = "./common/lib.rs"]
Expand Down
22 changes: 22 additions & 0 deletions examples/sign_transaction/delete_key_ed25519.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use near_crypto::SecretKey;
use near_ledger::NEARLedgerError;

#[path = "../common/lib.rs"]
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let sk = SecretKey::from_seed(
near_crypto::KeyType::ED25519,
&format!("{:?}", ledger_pub_key),
);
let public_key = sk.public_key();
tx.actions = vec![near_primitives::transaction::Action::DeleteKey(
near_primitives::transaction::DeleteKeyAction { public_key },
)];
tx
}

fn main() -> Result<(), NEARLedgerError> {
common::get_key_sign_and_verify_flow(tx)
}
1 change: 0 additions & 1 deletion examples/sign_transaction/multiple_transfers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use near_ledger::NEARLedgerError;


#[path = "../common/lib.rs"]
mod common;

Expand Down
1 change: 0 additions & 1 deletion examples/sign_transaction/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use near_ledger::NEARLedgerError;


#[path = "../common/lib.rs"]
mod common;

Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use near_primitives_core::hash::CryptoHash;

const CLA: u8 = 0x80; // Instruction class
const INS_GET_PUBLIC_KEY: u8 = 4; // Instruction code to get public key
const INS_GET_WALLET_ID: u8 = 0x05; // Get Wallet ID
const INS_GET_WALLET_ID: u8 = 0x05; // Get Wallet ID
const INS_GET_VERSION: u8 = 6; // Instruction code to get app version from the Ledger
const INS_SIGN_TRANSACTION: u8 = 2; // Instruction code to sign a transaction on the Ledger
const NETWORK_ID: u8 = 'W' as u8; // Instruction parameter 2
Expand Down Expand Up @@ -218,7 +218,6 @@ pub fn get_wallet_id(
// hd_path must be converted into bytes to be sent as `data` to the Ledger
let hd_path_bytes = hd_path_to_bytes(&hd_path);


let command = APDUCommand {
cla: CLA,
ins: INS_GET_WALLET_ID,
Expand Down

0 comments on commit 619ac75

Please sign in to comment.