Skip to content

Commit

Permalink
chore: add add_key_fullaccess example
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 26, 2024
1 parent 9696dbb commit e78fb01
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ path = "examples/sign_transaction/delete_key_secp256k1.rs"
name = "sign_stake"
path = "examples/sign_transaction/stake.rs"

[[example]]
name = "sign_add_key_fullaccess"
path = "examples/sign_transaction/add_key_fullaccess.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 @@ -135,6 +135,12 @@ RUST_LOG=sign_delete_key_secp256k1,near_ledger=info cargo run --example sign_del
RUST_LOG=sign_stake,near_ledger=info cargo run --example sign_stake
```

#### Add key (full access)

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

#### Transfer

```bash
Expand Down
28 changes: 28 additions & 0 deletions examples/sign_transaction/add_key_fullaccess.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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::AddKey(Box::new(
near_primitives::transaction::AddKeyAction {
public_key,
access_key: near_primitives_core::account::AccessKey {
nonce: 127127127127,
permission: near_primitives_core::account::AccessKeyPermission::FullAccess,
},
},
))];
tx
}

fn main() -> Result<(), NEARLedgerError> {
common::get_key_sign_and_verify_flow(tx)
}

0 comments on commit e78fb01

Please sign in to comment.