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

source

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.

source

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();
source

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 keypair
  • pub_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 the pub_hex argument, the two keys will be compared. If they differ, the function returns an error.
source

pub fn to_hex_split(&self) -> (String, String)

Hex-encode the secret and public keys into a String each

source

pub fn to_hex_joined(&self) -> String

Hex-encode the keypair into a combined String

source

pub fn strength(&self) -> u32

The “strength” of a given NodeIdentity is the number of leading one bits set in the inverted public key.

source

pub fn address_with_prefix(&self, prefix: &[u8]) -> Ipv6Addr

Calculate the address for this NodeIdentity with the given IP prefix.

source

pub fn subnet_with_prefix(&self, prefix: &[u8]) -> Ipv6Net

Calculate the /64 subnet for this NodeIdentity with the given IP prefix.

source

pub fn address(&self) -> Ipv6Addr

Calculate the address for this NodeIdentity with the default IP prefix.

source

pub fn subnet(&self) -> Ipv6Net

Calculate the /64 subnet for this NodeIdentity with the default IP prefix.

Trait Implementations§

source§

impl From<NodeIdentity> for Ipv6Addr

source§

fn from(identity: NodeIdentity) -> Ipv6Addr

Converts to this type from the input type.
source§

impl From<NodeIdentity> for Ipv6Net

source§

fn from(identity: NodeIdentity) -> Ipv6Net

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.