Utils

Struct Utils 

Source
pub struct Utils;
Expand description

Helper utilities

Implementations§

Source§

impl WalletCommonUtils

Source

pub fn public_key_rand() -> [u8; 32]

Generate a public key from random bytes. This is useful for testing

Source

pub fn rand_32bytes() -> [u8; 32]

Generate a 32 byte array from random bytes

Source

pub fn public_key( public_key_bytes: &[u8; 32], ) -> Result<VerifyingKey, WalletUtilsError>

Parse a PublicKey from an array of 32 bytes

Source

pub fn signature(signature_bytes: &[u8; 64]) -> Signature

Parse a Signature from an array of 64 bytes

Source

pub fn to32byte_array(bytes: &[u8]) -> Result<[u8; 32], WalletUtilsError>

Convert a slice of bytes into a 32 byte array. This is useful especially if a PublicKey is given as a slice instead of 32 byte array

Source

pub fn to64byte_array(bytes: &[u8]) -> Result<[u8; 64], WalletUtilsError>

Convert a slice of bytes into a 64 byte array. This is useful especially if a Signature is given as a slice instead of 64 byte array

Source

pub fn verify_signature( public_key: VerifyingKey, message: &[u8], signature: Signature, ) -> Result<(), WalletUtilsError>

Verify a message using a PublicKey and Signature

Source

pub fn verify( public_key_bytes: &[u8; 32], message_bytes: &[u8], signature_bytes: &[u8; 64], ) -> Result<(), WalletUtilsError>

Verify a message using a PublicKey and Signature

Source

pub fn address(public_key: VerifyingKey) -> String

Generate the Base58 address from a PublicKey

Source

pub fn base58_signature(signature: Signature) -> String

Generate a Base58 encoded string from a Signature

Source

pub fn shorten_base58<'a>( base58_str: &'a str, ) -> Result<Cow<'a, str>, WalletUtilsError>

Get the shortened string of the Base58 string . It displays the first 4 characters and the last for characters separated by ellipsis eg FXdl...RGd4 . If the string is less than 8 characters, an error is thrown

Source

pub fn custom_shorten_base58<'a>( base58_str: &'a str, take: usize, ) -> Result<Cow<'a, str>, WalletUtilsError>

Same as Self::shorten_base58 but with a custom range instead of taking the first 4 character and the last 4 characters it uses a custom range.

Source

pub fn custom_shorten_address_rl<'a>( base58_address: &'a str, left: usize, right: usize, ) -> Result<Cow<'a, str>, WalletUtilsError>

Same as Self::shorten_base58 but with a custom range instead of taking the first 4 character and the last 4 characters it uses a custom range for first characters before ellipsis and last characters after ellipsis.

Source

pub fn to_iso860(system_time: SystemTime) -> Rfc3339Timestamp

Converts SystemTime to ISO 8601 datetime string as required by Sign In With Solana standard

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V