pub struct SecretKey { /* private fields */ }Expand description
Ed25519 or Secp256k1 secret key.
Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn generate_ed25519() -> Self
pub fn generate_ed25519() -> Self
Generate a new random Ed25519 key pair.
Sourcepub fn ed25519_from_bytes(bytes: [u8; 32]) -> Self
pub fn ed25519_from_bytes(bytes: [u8; 32]) -> Self
Create an Ed25519 secret key from raw 32 bytes.
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Derive the public key.
Sourcepub fn from_seed_phrase(phrase: impl AsRef<str>) -> Result<Self, SignerError>
pub fn from_seed_phrase(phrase: impl AsRef<str>) -> Result<Self, SignerError>
Derive an Ed25519 secret key from a BIP-39 seed phrase.
Uses SLIP-10 derivation with the default NEAR HD path (m/44'/397'/0').
§Arguments
phrase- BIP-39 mnemonic phrase (12, 15, 18, 21, or 24 words)
§Example
use near_kit::SecretKey;
// Valid BIP-39 mnemonic (all zeros entropy)
let phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
let secret_key = SecretKey::from_seed_phrase(phrase).unwrap();Sourcepub fn from_seed_phrase_with_path(
phrase: impl AsRef<str>,
hd_path: impl AsRef<str>,
) -> Result<Self, SignerError>
pub fn from_seed_phrase_with_path( phrase: impl AsRef<str>, hd_path: impl AsRef<str>, ) -> Result<Self, SignerError>
Derive an Ed25519 secret key from a BIP-39 seed phrase with custom HD path.
Uses SLIP-10 derivation for Ed25519 keys. Only hardened derivation paths
are supported (all path components must use ' suffix).
§Arguments
phrase- BIP-39 mnemonic phrase (12, 15, 18, 21, or 24 words)hd_path- BIP-32 derivation path (e.g.,"m/44'/397'/0'")
§Example
use near_kit::SecretKey;
let phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
let secret_key = SecretKey::from_seed_phrase_with_path(phrase, "m/44'/397'/1'").unwrap();Sourcepub fn from_seed_phrase_with_path_and_passphrase(
phrase: impl AsRef<str>,
hd_path: impl AsRef<str>,
passphrase: Option<&str>,
) -> Result<Self, SignerError>
pub fn from_seed_phrase_with_path_and_passphrase( phrase: impl AsRef<str>, hd_path: impl AsRef<str>, passphrase: Option<&str>, ) -> Result<Self, SignerError>
Derive an Ed25519 secret key from a BIP-39 seed phrase with passphrase.
The passphrase provides additional entropy for seed generation (BIP-39 feature). An empty passphrase is equivalent to no passphrase.
§Arguments
phrase- BIP-39 mnemonic phrasehd_path- BIP-32 derivation pathpassphrase- Optional passphrase for additional entropy
§Example
use near_kit::SecretKey;
let phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
let secret_key = SecretKey::from_seed_phrase_with_path_and_passphrase(
phrase,
"m/44'/397'/0'",
Some("my-passphrase")
).unwrap();Sourcepub fn generate_with_seed_phrase() -> Result<(String, Self), SignerError>
pub fn generate_with_seed_phrase() -> Result<(String, Self), SignerError>
Generate a new random seed phrase and derive the corresponding secret key.
Returns both the seed phrase (for backup) and the derived secret key. Uses 12 words by default and the standard NEAR HD path.
§Example
use near_kit::SecretKey;
let (phrase, secret_key) = SecretKey::generate_with_seed_phrase().unwrap();
println!("Backup your seed phrase: {}", phrase);Sourcepub fn generate_with_seed_phrase_words(
word_count: usize,
) -> Result<(String, Self), SignerError>
pub fn generate_with_seed_phrase_words( word_count: usize, ) -> Result<(String, Self), SignerError>
Sourcepub fn generate_with_seed_phrase_custom(
word_count: usize,
hd_path: impl AsRef<str>,
passphrase: Option<&str>,
) -> Result<(String, Self), SignerError>
pub fn generate_with_seed_phrase_custom( word_count: usize, hd_path: impl AsRef<str>, passphrase: Option<&str>, ) -> Result<(String, Self), SignerError>
Generate a new random seed phrase with full customization.
§Arguments
word_count- Number of words (12, 15, 18, 21, or 24)hd_path- BIP-32 derivation pathpassphrase- Optional passphrase for additional entropy
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnsafeUnpin for SecretKey
impl UnwindSafe for SecretKey
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.