1use ssi_jwk::{Params, JWK};
2
3use super::BlockchainAccountIdType;
4
5pub(crate) fn encode_aleo_address(jwk: &JWK, network_id: &str) -> Result<String, &'static str> {
7 if network_id != "1" {
8 return Err("Unexpected Aleo network id");
9 }
10 let params = match jwk.params {
11 Params::OKP(ref params) if params.curve == ssi_jwk::aleo::OKP_CURVE => params,
12 _ => return Err("Invalid public key type for Aleo"),
13 };
14
15 use bech32::ToBase32;
16 let address = bech32::encode(
17 "aleo",
18 params.public_key.0.to_base32(),
19 bech32::Variant::Bech32m,
20 )
21 .map_err(|_| "Unable to encode Aleo account address")?;
22
23 Ok(address)
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
27pub struct Aleo;
28
29impl BlockchainAccountIdType for Aleo {
30 const NAMESPACE: &'static str = "aleo";
31
32 const REFERENCE: &'static str = "1";
33}
34
35pub type AleoBlockchainAccountId = super::TypedBlockchainAccountId<Aleo>;