diff --git a/Cargo.toml b/Cargo.toml index 411ea97..6f8b4f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index bb1d3ad..171bc85 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/sign_transaction/add_key_functioncall.rs b/examples/sign_transaction/add_key_functioncall.rs new file mode 100644 index 0000000..f9f63e4 --- /dev/null +++ b/examples/sign_transaction/add_key_functioncall.rs @@ -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::>(); + + 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) +}