thruput_signing/
strkey.rs1use thruput_xdr::types::ContractAddress;
5use zeroize::Zeroizing;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
9pub enum Error {
10 #[error("contract address must be a Z StrKey or base58 encoding of exactly 32 bytes")]
12 ContractAddress,
13 #[error("Ed25519 public key must be a G StrKey or base58 encoding of exactly 32 bytes")]
15 PublicKey,
16 #[error("expected an S StrKey or base58 encoding of a 32-byte Ed25519 seed")]
18 SecretSeed,
19}
20
21pub fn parse_contract_address(value: &str) -> Result<ContractAddress, Error> {
23 thruput_encoding::parse_address(value)
24 .map(Into::into)
25 .map_err(|_| Error::ContractAddress)
26}
27
28pub fn format_contract_address(address: &ContractAddress) -> String {
30 let mut bytes = [0; 32];
31 bytes.copy_from_slice(address.as_ref());
32 thruput_encoding::address_strkey(&bytes)
33}
34
35pub fn parse_public_key(value: &str) -> Result<[u8; 32], Error> {
37 thruput_encoding::parse_public_key(value).map_err(|_| Error::PublicKey)
38}
39
40pub fn format_public_key(key: &[u8; 32]) -> String {
42 thruput_encoding::public_key_strkey(key)
43}
44
45pub fn parse_secret_seed(value: &str) -> Result<Zeroizing<[u8; 32]>, Error> {
48 thruput_encoding::parse_secret_seed(value).map_err(|_| Error::SecretSeed)
49}
50
51pub fn format_secret_seed(seed: &[u8; 32]) -> Zeroizing<String> {
53 thruput_encoding::secret_seed_strkey(seed)
54}