Skip to main content

ToBech32

Trait ToBech32 

Source
pub trait ToBech32 {
    // Required methods
    fn try_to_bech32(&self, hrp: &str) -> Result<String, Bech32Error>;
    fn try_to_bech32_zeroizing(
        &self,
        hrp: &str,
    ) -> Result<EncodedSecret, Bech32Error>;
}
Expand description

Extension trait for encoding byte data as Bech32 (BIP-173) strings.

Requires feature encoding-bech32.

Blanket-implemented for all AsRef<[u8]> types. Use try_to_bech32 with the protocol’s HRP. Test empty and invalid HRP inputs in security-critical code.

Required Methods§

Source

fn try_to_bech32(&self, hrp: &str) -> Result<String, Bech32Error>

Fallibly encodes bytes as a Bech32 (BIP-173) string with the given HRP.

§Errors
§Examples
use secure_gate::ToBech32;

let encoded = b"hello".try_to_bech32("test")?;
assert!(encoded.starts_with("test1"));
Source

fn try_to_bech32_zeroizing( &self, hrp: &str, ) -> Result<EncodedSecret, Bech32Error>

Fallibly encodes bytes as Bech32 and wraps the result in crate::EncodedSecret.

Implementors§

Source§

impl<T: AsRef<[u8]> + ?Sized> ToBech32 for T

Available on crate features encoding-bech32 and alloc only.