pub struct Utils;
Expand description
Helper utilities
Implementations§
Source§impl WalletCommonUtils
impl WalletCommonUtils
Sourcepub fn public_key_rand() -> [u8; 32]
pub fn public_key_rand() -> [u8; 32]
Generate a public key from random bytes. This is useful for testing
Sourcepub fn rand_32bytes() -> [u8; 32]
pub fn rand_32bytes() -> [u8; 32]
Generate a 32 byte array from random bytes
Sourcepub fn public_key(
public_key_bytes: &[u8; 32],
) -> Result<VerifyingKey, WalletUtilsError>
pub fn public_key( public_key_bytes: &[u8; 32], ) -> Result<VerifyingKey, WalletUtilsError>
Parse a PublicKey from an array of 32 bytes
Sourcepub fn signature(signature_bytes: &[u8; 64]) -> Signature
pub fn signature(signature_bytes: &[u8; 64]) -> Signature
Parse a Signature from an array of 64 bytes
Sourcepub fn to32byte_array(bytes: &[u8]) -> Result<[u8; 32], WalletUtilsError>
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
Sourcepub fn to64byte_array(bytes: &[u8]) -> Result<[u8; 64], WalletUtilsError>
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
Sourcepub fn verify_signature(
public_key: VerifyingKey,
message: &[u8],
signature: Signature,
) -> Result<(), WalletUtilsError>
pub fn verify_signature( public_key: VerifyingKey, message: &[u8], signature: Signature, ) -> Result<(), WalletUtilsError>
Sourcepub fn verify(
public_key_bytes: &[u8; 32],
message_bytes: &[u8],
signature_bytes: &[u8; 64],
) -> Result<(), WalletUtilsError>
pub fn verify( public_key_bytes: &[u8; 32], message_bytes: &[u8], signature_bytes: &[u8; 64], ) -> Result<(), WalletUtilsError>
Sourcepub fn address(public_key: VerifyingKey) -> String
pub fn address(public_key: VerifyingKey) -> String
Generate the Base58 address from a PublicKey
Sourcepub fn base58_signature(signature: Signature) -> String
pub fn base58_signature(signature: Signature) -> String
Generate a Base58 encoded string from a Signature
Sourcepub fn shorten_base58<'a>(
base58_str: &'a str,
) -> Result<Cow<'a, str>, WalletUtilsError>
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
Sourcepub fn custom_shorten_base58<'a>(
base58_str: &'a str,
take: usize,
) -> Result<Cow<'a, str>, WalletUtilsError>
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.
Sourcepub fn custom_shorten_address_rl<'a>(
base58_address: &'a str,
left: usize,
right: usize,
) -> Result<Cow<'a, str>, WalletUtilsError>
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.
Sourcepub fn to_iso860(system_time: SystemTime) -> Rfc3339Timestamp
pub fn to_iso860(system_time: SystemTime) -> Rfc3339Timestamp
Converts SystemTime to ISO 8601 datetime string as required by Sign In With Solana standard