pub struct Utils;
Expand description
Helper utilities
Implementations§
Source§impl Utils
impl Utils
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 jsvalue_to_error<T: Debug>(
value: Result<T, JsValue>,
) -> Result<(), WalletError>
pub fn jsvalue_to_error<T: Debug>( value: Result<T, JsValue>, ) -> Result<(), WalletError>
Convert a JsValue error to a WalletError
Sourcepub fn public_key(public_key_bytes: [u8; 32]) -> WalletResult<VerifyingKey>
pub fn public_key(public_key_bytes: [u8; 32]) -> WalletResult<VerifyingKey>
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]) -> WalletResult<[u8; 32]>
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
Sourcepub fn to64byte_array(bytes: &[u8]) -> WalletResult<[u8; 64]>
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
Sourcepub fn verify_signature(
public_key: VerifyingKey,
message: &[u8],
signature: Signature,
) -> WalletResult<()>
pub fn verify_signature( public_key: VerifyingKey, message: &[u8], signature: Signature, ) -> WalletResult<()>
Sourcepub fn jsvalue_to_signature(
value: JsValue,
namespace: &str,
) -> WalletResult<Signature>
pub fn jsvalue_to_signature( value: JsValue, namespace: &str, ) -> WalletResult<Signature>
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(base58_str: &str) -> WalletResult<Cow<'_, str>>
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
Sourcepub fn custom_shorten_base58(
base58_str: &str,
take: usize,
) -> WalletResult<Cow<'_, str>>
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.