diff --git a/examples/common/lib.rs b/examples/common/lib.rs index ca3c730..8d316c3 100644 --- a/examples/common/lib.rs +++ b/examples/common/lib.rs @@ -224,12 +224,7 @@ pub fn serialize_and_display_tx(transaction: near_primitives::transaction::Trans log::info!("---"); bytes } - -pub fn display_and_verify_signature( - msg: Vec, - signature_bytes: Vec, - public_key: ed25519_dalek::PublicKey, -) { +pub fn display_signature(signature_bytes: Vec) -> ed25519_dalek::Signature { log::info!("---"); log::info!("Signature:"); let signature = Signature::from_bytes(&signature_bytes).unwrap(); @@ -239,7 +234,15 @@ pub fn display_and_verify_signature( .expect("Signature is not expected to fail on deserialization"); log::info!("{:<20} : {}", "signature (hex)", signature); log::info!("{:<20} : {}", "signature (base58)", signature_near); + signature +} +pub fn display_and_verify_signature( + msg: Vec, + signature_bytes: Vec, + public_key: ed25519_dalek::PublicKey, +) { + let signature = display_signature(signature_bytes); assert!(public_key .verify(&CryptoHash::hash_bytes(&msg).as_ref(), &signature) .is_ok()); diff --git a/examples/sign_nep_366_delegate_action.rs b/examples/sign_nep_366_delegate_action.rs index 30cb1f3..ac18817 100644 --- a/examples/sign_nep_366_delegate_action.rs +++ b/examples/sign_nep_366_delegate_action.rs @@ -1,7 +1,7 @@ use std::{convert::TryInto, str::FromStr}; use near_account_id::AccountId; -use near_crypto::{SecretKey, Signature}; +use near_crypto::Signature; use near_ledger::NEARLedgerError; use near_primitives::action::delegate::{DelegateAction, SignedDelegateAction}; use slip10::BIP32Path; @@ -23,35 +23,7 @@ fn main() -> Result<(), NEARLedgerError> { let sender_id = AccountId::from_str("bob.near").unwrap(); - let sk = SecretKey::from_seed( - near_crypto::KeyType::SECP256K1, - &format!("{:?}", public_key), - ); - let public_key_secp = sk.public_key(); - - let transfer = near_primitives::transaction::Action::Transfer( - near_primitives::transaction::TransferAction { - deposit: 150000000000000000000000, // 0.15 NEAR - }, - ); - - let stake = near_primitives::transaction::Action::Stake(Box::new( - near_primitives::transaction::StakeAction { - stake: 1157130000000000000000000, // 1.15713 NEAR, - public_key: public_key_secp.clone(), - }, - )); - - let add_key_fullaccess = near_primitives::transaction::Action::AddKey(Box::new( - near_primitives::transaction::AddKeyAction { - public_key: public_key_secp.clone(), - access_key: near_primitives_core::account::AccessKey { - nonce: 127127127127, - permission: near_primitives_core::account::AccessKeyPermission::FullAccess, - }, - }, - )); - let actions = vec![transfer, stake, add_key_fullaccess] + let actions = common::batch_of_all_types_of_actions(public_key) .into_iter() .map(|action| action.try_into().unwrap()) .collect::>(); @@ -76,5 +48,7 @@ fn main() -> Result<(), NEARLedgerError> { }; log::info!("{:#?}", signed_delegate); assert!(signed_delegate.verify()); + + common::display_signature(signature_bytes); Ok(()) } diff --git a/examples/sign_nep_413_message.rs b/examples/sign_nep_413_message.rs index 8e783bd..ef4c9ac 100644 --- a/examples/sign_nep_413_message.rs +++ b/examples/sign_nep_413_message.rs @@ -47,7 +47,7 @@ fn main() -> Result<(), NEARLedgerError> { display_pub_key(public_key); let msg = NEP413Payload { - messsage: "Makes it possible to authenticate users without having to add new access keys. This will improve UX, save money and will not increase the on-chain storage of the users' accounts.".to_string(), + messsage: "Makes it possible to authenticate users without having to add new access keys. This will improve UX, save money and will not increase the on-chain storage of the users' accounts./Makes it possible to authenticate users without having to add new access keys. This will improve UX, save money and will not increase the on-chain storage of the users' accounts./Makes it possible to authenticate users without having to add new access keys. This will improve UX, save money and will not increase the on-chain storage of the users' accounts.".to_string(), nonce: [42; 32], recipient: "alice.near".to_string(), callback_url: Some("myapp.com/callback".to_string())