pub struct SigningKey { /* private fields */ }Expand description
A key that can sign messages.
This bundles together a public key and the ability to sign with the corresponding private key. For in-memory keys, signing is instant. For hardware wallets or KMS, signing may involve async operations.
§Example
use near_kit::{InMemorySigner, Signer};
let signer = InMemorySigner::new("alice.testnet", "ed25519:...")?;
let key = signer.key();
println!("Public key: {}", key.public_key());
let signature = key.sign(b"message").await?;Implementations§
Source§impl SigningKey
impl SigningKey
Sourcepub fn public_key(&self) -> &PublicKey
pub fn public_key(&self) -> &PublicKey
Get the public key.
Sourcepub async fn sign(&self, message: &[u8]) -> Result<Signature, SignerError>
pub async fn sign(&self, message: &[u8]) -> Result<Signature, SignerError>
Sign a message.
For in-memory keys, this returns immediately. For hardware wallets or KMS, this may involve user confirmation or network requests.
Sourcepub async fn sign_nep413(
&self,
account_id: &AccountId,
params: &SignMessageParams,
) -> Result<SignedMessage, SignerError>
pub async fn sign_nep413( &self, account_id: &AccountId, params: &SignMessageParams, ) -> Result<SignedMessage, SignerError>
Sign a NEP-413 message for off-chain authentication.
§Example
ⓘ
use near_kit::{InMemorySigner, Signer, nep413};
let signer = InMemorySigner::new("alice.testnet", "ed25519:...")?;
let key = signer.key();
let params = nep413::SignMessageParams {
message: "Login to MyApp".to_string(),
recipient: "myapp.com".to_string(),
nonce: nep413::generate_nonce(),
callback_url: None,
state: None,
};
let signed = key.sign_nep413(&signer.account_id(), ¶ms).await?;Trait Implementations§
Source§impl Clone for SigningKey
impl Clone for SigningKey
Auto Trait Implementations§
impl Freeze for SigningKey
impl !RefUnwindSafe for SigningKey
impl Send for SigningKey
impl Sync for SigningKey
impl Unpin for SigningKey
impl UnsafeUnpin for SigningKey
impl !UnwindSafe for SigningKey
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