pub struct InMemorySigner { /* private fields */ }Expand description
A signer with a single key stored in memory.
This is the simplest signer implementation, suitable for scripts, bots, and testing.
§Example
use near_kit::InMemorySigner;
let signer = InMemorySigner::new(
"alice.testnet",
"ed25519:3D4YudUahN1nawWogh8pAKSj92sUNMdbZGjn7kERKzYoTy8tnFQuwoGUC51DowKqorvkr2pytJSnwuSbsNVfqygr"
).unwrap();Implementations§
Source§impl InMemorySigner
impl InMemorySigner
Sourcepub fn new(
account_id: impl TryIntoAccountId,
secret_key: impl AsRef<str>,
) -> Result<Self, Error>
pub fn new( account_id: impl TryIntoAccountId, secret_key: impl AsRef<str>, ) -> Result<Self, Error>
Sourcepub fn from_secret_key(
account_id: impl TryIntoAccountId,
secret_key: SecretKey,
) -> Result<Self, Error>
pub fn from_secret_key( account_id: impl TryIntoAccountId, secret_key: SecretKey, ) -> Result<Self, Error>
Sourcepub fn generate_implicit() -> Self
pub fn generate_implicit() -> Self
Generate a random Ed25519 key and derive an implicit account ID.
The account ID is the hex-encoded Ed25519 public key bytes (64 characters).
§Example
use near_kit::{InMemorySigner, Signer};
let signer = InMemorySigner::generate_implicit();
assert_eq!(signer.account_id().as_str().len(), 64);Sourcepub fn implicit(secret_key: SecretKey) -> Self
pub fn implicit(secret_key: SecretKey) -> Self
Create a signer from an existing secret key, deriving an implicit account ID.
The account ID is the hex-encoded Ed25519 public key bytes (64 characters).
§Panics
Panics if the secret key is not Ed25519.
§Example
use near_kit::{InMemorySigner, SecretKey, Signer};
let secret_key = SecretKey::generate_ed25519();
let signer = InMemorySigner::implicit(secret_key);
assert_eq!(signer.account_id().as_str().len(), 64);Sourcepub fn from_seed_phrase(
account_id: impl TryIntoAccountId,
phrase: impl AsRef<str>,
) -> Result<Self, Error>
pub fn from_seed_phrase( account_id: impl TryIntoAccountId, phrase: impl AsRef<str>, ) -> Result<Self, Error>
Create a signer from a BIP-39 seed phrase.
Uses SLIP-10 derivation with the default NEAR HD path (m/44'/397'/0').
§Arguments
account_id- The NEAR account ID (e.g., “alice.testnet”)phrase- BIP-39 mnemonic phrase (12, 15, 18, 21, or 24 words)
§Example
use near_kit::InMemorySigner;
let signer = InMemorySigner::from_seed_phrase(
"alice.testnet",
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
).unwrap();Sourcepub fn from_seed_phrase_with_path(
account_id: impl TryIntoAccountId,
phrase: impl AsRef<str>,
hd_path: impl AsRef<str>,
) -> Result<Self, Error>
pub fn from_seed_phrase_with_path( account_id: impl TryIntoAccountId, phrase: impl AsRef<str>, hd_path: impl AsRef<str>, ) -> Result<Self, Error>
Create a signer from a BIP-39 seed phrase with custom HD path.
§Arguments
account_id- The NEAR account IDphrase- BIP-39 mnemonic phrasehd_path- BIP-32 derivation path (e.g.,"m/44'/397'/0'")
§Example
use near_kit::InMemorySigner;
let signer = InMemorySigner::from_seed_phrase_with_path(
"alice.testnet",
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
"m/44'/397'/1'"
).unwrap();Sourcepub fn public_key(&self) -> &PublicKey
pub fn public_key(&self) -> &PublicKey
Get the public key.
Trait Implementations§
Source§impl Clone for InMemorySigner
impl Clone for InMemorySigner
Source§fn clone(&self) -> InMemorySigner
fn clone(&self) -> InMemorySigner
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InMemorySigner
impl Debug for InMemorySigner
Source§impl Signer for InMemorySigner
impl Signer for InMemorySigner
Source§fn account_id(&self) -> &AccountId
fn account_id(&self) -> &AccountId
The account this signer signs for.
Source§fn key(&self) -> SigningKey
fn key(&self) -> SigningKey
Get a key for signing. Read more
Source§fn public_key(&self) -> PublicKey
fn public_key(&self) -> PublicKey
Get the signer’s public key without side effects. Read more
Auto Trait Implementations§
impl Freeze for InMemorySigner
impl RefUnwindSafe for InMemorySigner
impl Send for InMemorySigner
impl Sync for InMemorySigner
impl Unpin for InMemorySigner
impl UnsafeUnpin for InMemorySigner
impl UnwindSafe for InMemorySigner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more