pub struct SecretKey(pub SecretKey);Expand description
Secret key for peer identity and key sharing
A thin wrapper around Iroh’s SecretKey, representing the private part of an Ed25519 keypair.
This key should be kept secret and securely stored (e.g., in the local config file).
§Security Considerations
- Never share this key over the network
- Store encrypted or in a secure location (e.g.,
~/.config/jax/secret.pem) - Generate a new key for each peer instance
§Examples
ⓘ
// Generate a new keypair
let secret_key = SecretKey::generate();
let public_key = secret_key.public();
// Persist to PEM format
let pem = secret_key.to_pem();
std::fs::write("secret.pem", pem)?;
// Load from PEM
let pem = std::fs::read_to_string("secret.pem")?;
let recovered = SecretKey::from_pem(&pem)?;Tuple Fields§
§0: SecretKeyImplementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn from_hex(hex: &str) -> Result<Self, KeyError>
pub fn from_hex(hex: &str) -> Result<Self, KeyError>
Parse a secret key from a hexadecimal string
Accepts both plain hex and “0x”-prefixed hex strings.
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Generate a new random secret key using a cryptographically secure RNG
Methods from Deref<Target = SSecretKey>§
Sourcepub fn sign(&self, msg: &[u8]) -> Signature
pub fn sign(&self, msg: &[u8]) -> Signature
Sign the given message and return a digital signature
Sourcepub fn to_bytes(&self) -> [u8; 32]
pub fn to_bytes(&self) -> [u8; 32]
Convert this to the bytes representing the secret part. The public part can always be recovered.
Sourcepub fn secret(&self) -> &SigningKey
pub fn secret(&self) -> &SigningKey
Returns the SigningKey for this SecretKey.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SecretKey
impl<'de> Deserialize<'de> for SecretKey
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin 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
Mutably borrows from an owned value. Read more