Skip to content

Commit

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

[[example]]
name = "sign_delete_key_secp256k1"
path = "examples/sign_transaction/delete_key_secp256k1.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 @@ -123,6 +123,12 @@ RUST_LOG=sign_delete_account_long,near_ledger=info cargo run --example sign_dele
RUST_LOG=sign_delete_key_ed25519,near_ledger=info cargo run --example sign_delete_key_ed25519
```

#### Delete key (secp256k1)

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

#### Transfer

```bash
Expand Down
22 changes: 22 additions & 0 deletions examples/sign_transaction/delete_key_secp256k1.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::SECP256K1,
&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)
}

0 comments on commit ffc181d

Please sign in to comment.