use crate::{
cdk::{api, candid::Principal},
infra::{InfraError, ic::IcInfraError, ic::call::Call},
};
use super::{
MgmtInfra, MgmtInfraError,
types::{
InfraEcdsaPublicKeyArgs, InfraEcdsaPublicKeyResult, InfraSignWithEcdsaArgs,
InfraSignWithEcdsaResult,
},
};
impl MgmtInfra {
pub async fn ecdsa_public_key(
args: &InfraEcdsaPublicKeyArgs,
) -> Result<InfraEcdsaPublicKeyResult, InfraError> {
let response = Call::bounded_wait(Principal::management_canister(), "ecdsa_public_key")
.with_arg(args.clone())?
.execute()
.await?;
response.candid()
}
pub async fn sign_with_ecdsa(
args: &InfraSignWithEcdsaArgs,
) -> Result<InfraSignWithEcdsaResult, InfraError> {
let cycles = api::cost_sign_with_ecdsa(&args.key_id.name, args.key_id.curve.into())
.map_err(MgmtInfraError::from)
.map_err(IcInfraError::from)?;
let response = Call::unbounded_wait(Principal::management_canister(), "sign_with_ecdsa")
.with_arg(args.clone())?
.with_cycles(cycles)
.execute()
.await?;
response.candid()
}
}