wallet_standard/experimental/
decrypt.rs

1use async_trait::async_trait;
2use serde::Deserialize;
3use serde::Serialize;
4use typed_builder::TypedBuilder;
5
6use crate::WalletResult;
7
8pub const EXPERIMENTAL_DECRYPT: &str = "experimental:decrypt";
9
10pub trait ExperimentalDecryptOutput {
11	/// `cleartext` that was decrypted.
12	fn cleartext(&self) -> Vec<u8>;
13}
14
15#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TypedBuilder)]
16#[serde(rename_all = "camelCase")]
17pub struct ExperimentalDecryptProps {
18	/// Cipher to use for decryption.
19	#[builder(setter(into))]
20	cipher: String,
21	/// Public key to derive a shared key to decrypt the data using.
22	#[builder(setter(into))]
23	#[serde(with = "serde_bytes")]
24	public_key: Vec<u8>,
25	/// Ciphertext to decrypt.
26	#[builder(setter(into))]
27	#[serde(with = "serde_bytes")]
28	pub cipher_text: Vec<u8>,
29	/// Nonce to use for decryption.
30	#[builder(setter(into))]
31	#[serde(with = "serde_bytes")]
32	pub nonce: Vec<u8>,
33	/// Multiple of padding bytes to use for decryption, defaulting to 0.
34	///
35	/// Valid values `0 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048`
36	#[builder(default, setter(into, strip_option))]
37	padding: Option<u8>,
38}
39
40#[async_trait(?Send)]
41pub trait WalletExperimentalDecrypt {
42	type Output: ExperimentalDecryptOutput;
43
44	async fn decrypt_many(
45		&self,
46		props: Vec<ExperimentalDecryptProps>,
47	) -> WalletResult<Vec<Self::Output>>;
48	async fn decrypt(&self, props: ExperimentalDecryptProps) -> WalletResult<Self::Output>;
49}