Struct Utils

Source
pub struct Utils;
Expand description

Helper utilities

Implementations§

Source§

impl Utils

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 jsvalue_to_error<T: Debug>( value: Result<T, JsValue>, ) -> Result<(), WalletError>

Convert a JsValue error to a WalletError

Source

pub fn public_key(public_key_bytes: [u8; 32]) -> WalletResult<VerifyingKey>

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]) -> WalletResult<[u8; 32]>

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]) -> WalletResult<[u8; 64]>

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, ) -> WalletResult<()>

Verify a message using a PublicKey and Signature

Source

pub fn jsvalue_to_signature( value: JsValue, namespace: &str, ) -> WalletResult<Signature>

Convert a JsValue to a 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(base58_str: &str) -> WalletResult<Cow<'_, str>>

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( base58_str: &str, take: usize, ) -> WalletResult<Cow<'_, str>>

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.

Auto Trait Implementations§

§

impl Freeze for Utils

§

impl RefUnwindSafe for Utils

§

impl Send for Utils

§

impl Sync for Utils

§

impl Unpin for Utils

§

impl UnwindSafe for Utils

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