Skip to main content

Signer

Trait Signer 

Source
pub trait Signer: Send + Sync {
    // Required methods
    fn account_id(&self) -> &AccountId;
    fn key(&self) -> SigningKey;
}
Expand description

Trait for signing transactions.

A signer knows which account it signs for and provides keys for signing. The key() method returns a SigningKey that bundles together the public key and signing capability, ensuring atomic key claiming.

§Example Implementation

use near_kit::{Signer, SigningKey, AccountId, SecretKey};

struct MyCustomSigner {
    account_id: AccountId,
    secret_key: SecretKey,
}

impl Signer for MyCustomSigner {
    fn account_id(&self) -> &AccountId {
        &self.account_id
    }

    fn key(&self) -> SigningKey {
        SigningKey::new(self.secret_key.clone())
    }
}

Required Methods§

Source

fn account_id(&self) -> &AccountId

The account this signer signs for.

Source

fn key(&self) -> SigningKey

Get a key for signing.

Returns a SigningKey that contains both the public key and the capability to sign with the corresponding private key.

For single-key signers, this always returns the same key. For rotating signers, this atomically claims the next key in rotation.

Implementations on Foreign Types§

Source§

impl Signer for Arc<dyn Signer>

Implement Signer for Arc<dyn Signer> for convenience.

Implementors§