use std::collections::BTreeMap; use cosmwasm_std::{Addr, HexBinary, Uint128}; use ecies::encrypt; use k256::ecdsa::VerifyingKey; use serde::{Deserialize, Serialize}; use transfers_contract::msg::execute::ClearTextTransferRequestMsg; pub type RawCipherText = HexBinary; #[derive(Clone, Debug)] pub struct State { pub state: BTreeMap, } #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct RawState { pub state: BTreeMap, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RawEncryptedState { pub ciphertext: HexBinary, } impl From for RawState { fn from(o: State) -> Self { Self { state: o.state } } } impl TryFrom for State { type Error = anyhow::Error; fn try_from(o: RawState) -> Result { Ok(Self { state: o.state }) } } fn main() { let msg = ClearTextTransferRequestMsg { sender: Addr::unchecked("alice"), receiver: Addr::unchecked("bob"), amount: Uint128::from(100_u32), }; let decoded: Vec = hex::decode("03e8d63b96a3b3fa442f0a8f39a580f5e898dab7b86eaa685466e82d79022eedff") .expect("Decoding failed"); let sk = VerifyingKey::from_sec1_bytes(&decoded).unwrap(); let serialized_state = serde_json::to_string(&msg).expect("infallible serializer"); let encrypted_state = encrypt(&sk.to_sec1_bytes(), serialized_state.as_bytes()).unwrap(); let result: HexBinary = encrypted_state.into(); println!("{}", result); }