Skip to content

Commit

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

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

#### Add key (function call)

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

#### Transfer

```bash
Expand Down
42 changes: 42 additions & 0 deletions examples/sign_transaction/add_key_functioncall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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();
let method_names = vec![
"first_method", "saturating_add_signed", "iterator_chain_to_do_multiple_instances_of_an_operation_that_can_fail",
"from_residual", "from_output", "unwrap_err_unchecked", "try_reserve_exact",
"first_method", "saturating_add_signed", "iterator_chain_to_do_multiple_instances_of_an_operation_that_can_fail",
].into_iter().map(Into::into).collect::<Vec<_>>();

let permission = near_primitives_core::account::FunctionCallPermission {
allowance: Some(150000000000000000000),
receiver_id:
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c1b11b3b31673033936ad07bddc01f9da27d974811e480fb197c799e23480a489".into(),
method_names,
};


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::FunctionCall(permission),
},
},
))];
tx
}

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

0 comments on commit 96d5eb2

Please sign in to comment.