Struct yggdrasil_keys::NodeIdentity
source · pub struct NodeIdentity {
pub signing_keys: SigningKey,
}
Expand description
Represents a node in the yggdrasil network.
The keys in here are as used in the reference implementation yggdrasil-go. In a previous version of this crate, it was based on the YS001: Yggdrasil Core Specification, but that spec has not been updated for the new v0.4 release of yggdrasil-go release yet, so for compatibility with the new version, we’re basing this on the reference implementation instead.
Fields§
§signing_keys: SigningKey
ed25519 key pair, used as the node identity and for address generation
Implementations§
source§impl NodeIdentity
impl NodeIdentity
sourcepub const IP_PREFIX: [u8; 1] = _
pub const IP_PREFIX: [u8; 1] = _
This prefix is taken from yggdrasil-go,
it’s the one currently used in the yggdrasil network,
namely 200::/7
.
sourcepub fn new<R: CryptoRng + RngCore>(csprng: &mut R) -> Self
pub fn new<R: CryptoRng + RngCore>(csprng: &mut R) -> Self
Generates node identity using the supplied CSPRNG
use rand::thread_rng;
use std::net::Ipv6Addr;
use yggdrasil_keys::NodeIdentity;
let node = NodeIdentity::new(&mut thread_rng());
let address : Ipv6Addr = node.into();
sourcepub fn from_hex(
sec_hex: &str,
pub_hex: Option<&str>,
) -> Result<Self, FromHexError>
pub fn from_hex( sec_hex: &str, pub_hex: Option<&str>, ) -> Result<Self, FromHexError>
Parses hexadecimally encoded keypairs.
Arguments:
sec_hex
: Either 32 hex encoded bytes for the secret key, or 64 hex encoded bytes for the keypairpub_hex
: Optionally, 32 hex encoded bytes for the public key
These arguments work like this:
- You have to supply the secret key.
- You can supply the public key, but you don’t have to. If it’s missing, one will be generated from the secret key.
- If you pass a keypair to the
sec_hex
argument, and additionally a public key to thepub_hex
argument, the two keys will be compared. If they differ, the function returns an error.
sourcepub fn to_hex_split(&self) -> (String, String)
pub fn to_hex_split(&self) -> (String, String)
Hex-encode the secret and public keys into a String each
sourcepub fn to_hex_joined(&self) -> String
pub fn to_hex_joined(&self) -> String
Hex-encode the keypair into a combined String
sourcepub fn strength(&self) -> u32
pub fn strength(&self) -> u32
The “strength” of a given NodeIdentity is the number of leading one bits set in the inverted public key.
sourcepub fn address_with_prefix(&self, prefix: &[u8]) -> Ipv6Addr
pub fn address_with_prefix(&self, prefix: &[u8]) -> Ipv6Addr
Calculate the address for this NodeIdentity with the given IP prefix.
sourcepub fn subnet_with_prefix(&self, prefix: &[u8]) -> Ipv6Net
pub fn subnet_with_prefix(&self, prefix: &[u8]) -> Ipv6Net
Calculate the /64
subnet for this NodeIdentity with the given IP prefix.