pub use thruput_domain_separator::sha2::public_key_hash;
use thruput_xdr::auth_claim::{AuthClaim, PubkeyAccountPreimage};
use thruput_xdr::types::{ContractAddress, PublicKey, PublicKeyHash};
pub const DEFAULT_PUBKEY_ACCOUNT_NONCE: u64 = 0;
#[derive(Clone, Debug)]
pub struct PubkeyAccount {
pub public_key: PublicKey,
pub nonce: u64,
}
impl PubkeyAccount {
pub fn new(public_key: PublicKey, nonce: u64) -> Self {
Self { public_key, nonce }
}
pub fn from_public_key_bytes(public_key: [u8; 32], nonce: u64) -> Self {
Self::new(
PublicKey::Ed25519 {
ed25519: thruput_xdr::types::Ed25519PublicKey::from(public_key),
},
nonce,
)
}
pub fn public_key_hash(&self) -> PublicKeyHash {
public_key_hash(&self.public_key)
}
pub fn preimage(&self) -> PubkeyAccountPreimage {
PubkeyAccountPreimage {
pubkey_hash: self.public_key_hash(),
nonce: self.nonce,
}
}
pub fn auth_claim(&self) -> AuthClaim {
AuthClaim::kPubkeySignature {
pubkey_preimage: self.preimage(),
}
}
pub fn address(&self) -> ContractAddress {
thruput_domain_separator::sha2::pubkey_account_address(&self.preimage())
}
}