Skip to main content

bsv/wallet/
interfaces.rs

1//! WalletInterface trait and all arg/result structs.
2//!
3//! Defines the contract that all wallet implementations must satisfy.
4//! Translated from Go SDK wallet/interfaces.go and TS SDK Wallet.interfaces.ts.
5//! Uses #[async_trait] for object safety -- enables `dyn WalletInterface`.
6
7use std::collections::HashMap;
8
9use async_trait::async_trait;
10
11use crate::primitives::public_key::PublicKey;
12use crate::wallet::error::WalletError;
13use crate::wallet::types::{
14    BasketStringUnder300Bytes, BooleanDefaultFalse, BooleanDefaultTrue, Counterparty,
15    DescriptionString5to50Bytes, LabelStringUnder300Bytes, OutpointString,
16    OutputTagStringUnder300Bytes, PositiveIntegerDefault10Max10000, PositiveIntegerOrZero,
17    Protocol, SatoshiValue, TXIDHexString,
18};
19
20// ---------------------------------------------------------------------------
21// Serde helper modules (only compiled with "network" feature)
22// ---------------------------------------------------------------------------
23
24/// Serde helpers for custom JSON serialization of wallet types.
25/// Gated behind the "network" feature since serde is an optional dependency.
26#[cfg(feature = "network")]
27pub(crate) mod serde_helpers {
28    use crate::primitives::public_key::PublicKey;
29
30    /// Serialize/deserialize PublicKey as DER hex string.
31    pub mod public_key_hex {
32        use super::PublicKey;
33        use serde::{self, Deserialize, Deserializer, Serializer};
34
35        pub fn serialize<S>(pk: &PublicKey, serializer: S) -> Result<S::Ok, S::Error>
36        where
37            S: Serializer,
38        {
39            serializer.serialize_str(&pk.to_der_hex())
40        }
41
42        pub fn deserialize<'de, D>(deserializer: D) -> Result<PublicKey, D::Error>
43        where
44            D: Deserializer<'de>,
45        {
46            let s = String::deserialize(deserializer)?;
47            PublicKey::from_string(&s).map_err(serde::de::Error::custom)
48        }
49    }
50
51    /// Serialize/deserialize `Option<PublicKey>` as optional DER hex string.
52    #[allow(dead_code)]
53    pub mod option_public_key_hex {
54        use super::PublicKey;
55        use serde::{self, Deserialize, Deserializer, Serializer};
56
57        pub fn serialize<S>(pk: &Option<PublicKey>, serializer: S) -> Result<S::Ok, S::Error>
58        where
59            S: Serializer,
60        {
61            match pk {
62                Some(pk) => serializer.serialize_str(&pk.to_der_hex()),
63                None => serializer.serialize_none(),
64            }
65        }
66
67        pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<PublicKey>, D::Error>
68        where
69            D: Deserializer<'de>,
70        {
71            let opt: Option<String> = Option::deserialize(deserializer)?;
72            match opt {
73                Some(s) if !s.is_empty() => PublicKey::from_string(&s)
74                    .map(Some)
75                    .map_err(serde::de::Error::custom),
76                _ => Ok(None),
77            }
78        }
79    }
80
81    /// Serialize/deserialize `Vec<PublicKey>` as array of DER hex strings.
82    pub mod vec_public_key_hex {
83        use super::PublicKey;
84        use serde::ser::SerializeSeq;
85        use serde::{self, Deserialize, Deserializer, Serializer};
86
87        pub fn serialize<S>(pks: &[PublicKey], serializer: S) -> Result<S::Ok, S::Error>
88        where
89            S: Serializer,
90        {
91            let mut seq = serializer.serialize_seq(Some(pks.len()))?;
92            for pk in pks {
93                seq.serialize_element(&pk.to_der_hex())?;
94            }
95            seq.end()
96        }
97
98        pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<PublicKey>, D::Error>
99        where
100            D: Deserializer<'de>,
101        {
102            let strs: Vec<String> = Vec::deserialize(deserializer)?;
103            strs.iter()
104                .map(|s| PublicKey::from_string(s).map_err(serde::de::Error::custom))
105                .collect()
106        }
107    }
108
109    /// Serialize/deserialize [u8; 32] as base64 string (matches Go SDK Bytes32Base64).
110    pub mod bytes32_base64 {
111        use serde::{self, Deserialize, Deserializer, Serializer};
112
113        pub fn serialize<S>(bytes: &[u8; 32], serializer: S) -> Result<S::Ok, S::Error>
114        where
115            S: Serializer,
116        {
117            serializer.serialize_str(&base64_encode(bytes))
118        }
119
120        pub fn deserialize<'de, D>(deserializer: D) -> Result<[u8; 32], D::Error>
121        where
122            D: Deserializer<'de>,
123        {
124            let s = String::deserialize(deserializer)?;
125            let decoded = base64_decode(&s).map_err(serde::de::Error::custom)?;
126            if decoded.len() > 32 {
127                return Err(serde::de::Error::custom(
128                    "base64 decoded value exceeds 32 bytes",
129                ));
130            }
131            let mut buf = [0u8; 32];
132            buf[..decoded.len()].copy_from_slice(&decoded);
133            Ok(buf)
134        }
135
136        fn base64_encode(data: &[u8]) -> String {
137            const CHARS: &[u8] =
138                b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
139            let mut result = String::new();
140            let chunks = data.chunks(3);
141            for chunk in chunks {
142                let b0 = chunk[0] as u32;
143                let b1 = if chunk.len() > 1 { chunk[1] as u32 } else { 0 };
144                let b2 = if chunk.len() > 2 { chunk[2] as u32 } else { 0 };
145                let triple = (b0 << 16) | (b1 << 8) | b2;
146                result.push(CHARS[((triple >> 18) & 0x3F) as usize] as char);
147                result.push(CHARS[((triple >> 12) & 0x3F) as usize] as char);
148                if chunk.len() > 1 {
149                    result.push(CHARS[((triple >> 6) & 0x3F) as usize] as char);
150                } else {
151                    result.push('=');
152                }
153                if chunk.len() > 2 {
154                    result.push(CHARS[(triple & 0x3F) as usize] as char);
155                } else {
156                    result.push('=');
157                }
158            }
159            result
160        }
161
162        fn base64_decode(s: &str) -> Result<Vec<u8>, String> {
163            fn char_to_val(c: u8) -> Result<u8, String> {
164                match c {
165                    b'A'..=b'Z' => Ok(c - b'A'),
166                    b'a'..=b'z' => Ok(c - b'a' + 26),
167                    b'0'..=b'9' => Ok(c - b'0' + 52),
168                    b'+' => Ok(62),
169                    b'/' => Ok(63),
170                    _ => Err(format!("invalid base64 character: {}", c as char)),
171                }
172            }
173            let bytes = s.as_bytes();
174            let mut result = Vec::new();
175            let mut i = 0;
176            while i < bytes.len() {
177                if bytes[i] == b'=' {
178                    break;
179                }
180                let a = char_to_val(bytes[i])?;
181                let b = if i + 1 < bytes.len() && bytes[i + 1] != b'=' {
182                    char_to_val(bytes[i + 1])?
183                } else {
184                    0
185                };
186                let c = if i + 2 < bytes.len() && bytes[i + 2] != b'=' {
187                    char_to_val(bytes[i + 2])?
188                } else {
189                    0
190                };
191                let d = if i + 3 < bytes.len() && bytes[i + 3] != b'=' {
192                    char_to_val(bytes[i + 3])?
193                } else {
194                    0
195                };
196                let triple =
197                    ((a as u32) << 18) | ((b as u32) << 12) | ((c as u32) << 6) | (d as u32);
198                result.push(((triple >> 16) & 0xFF) as u8);
199                if i + 2 < bytes.len() && bytes[i + 2] != b'=' {
200                    result.push(((triple >> 8) & 0xFF) as u8);
201                }
202                if i + 3 < bytes.len() && bytes[i + 3] != b'=' {
203                    result.push((triple & 0xFF) as u8);
204                }
205                i += 4;
206            }
207            Ok(result)
208        }
209    }
210
211    /// Serialize/deserialize `Vec<u8>` as JSON array of numbers (matches Go SDK BytesList).
212    pub mod bytes_as_array {
213        use serde::{Deserialize, Deserializer, Serializer};
214
215        pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error>
216        where
217            S: Serializer,
218        {
219            serializer.collect_seq(bytes.iter())
220        }
221
222        pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
223        where
224            D: Deserializer<'de>,
225        {
226            Vec::<u8>::deserialize(deserializer)
227        }
228    }
229
230    /// Serialize/deserialize `Option<Vec<u8>>` as optional JSON array of numbers.
231    pub mod option_bytes_as_array {
232        use serde::{Deserialize, Deserializer, Serializer};
233
234        pub fn serialize<S>(bytes: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
235        where
236            S: Serializer,
237        {
238            match bytes {
239                Some(b) => serializer.collect_seq(b.iter()),
240                None => serializer.serialize_none(),
241            }
242        }
243
244        pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
245        where
246            D: Deserializer<'de>,
247        {
248            Option::<Vec<u8>>::deserialize(deserializer)
249        }
250    }
251
252    /// Serialize/deserialize `Vec<u8>` as hex string (matches Go SDK BytesHex).
253    pub mod bytes_as_hex {
254        use serde::{self, Deserialize, Deserializer, Serializer};
255
256        pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error>
257        where
258            S: Serializer,
259        {
260            serializer.serialize_str(&to_hex(bytes))
261        }
262
263        pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
264        where
265            D: Deserializer<'de>,
266        {
267            let s = String::deserialize(deserializer)?;
268            from_hex(&s).map_err(serde::de::Error::custom)
269        }
270
271        fn to_hex(bytes: &[u8]) -> String {
272            const HEX: &[u8; 16] = b"0123456789abcdef";
273            let mut s = String::with_capacity(bytes.len() * 2);
274            for &b in bytes {
275                s.push(HEX[(b >> 4) as usize] as char);
276                s.push(HEX[(b & 0xf) as usize] as char);
277            }
278            s
279        }
280
281        pub(crate) fn from_hex(s: &str) -> Result<Vec<u8>, String> {
282            if !s.len().is_multiple_of(2) {
283                return Err("hex string has odd length".to_string());
284            }
285            let bytes = s.as_bytes();
286            let mut result = Vec::with_capacity(bytes.len() / 2);
287            for chunk in bytes.chunks(2) {
288                let hi = hex_val(chunk[0])?;
289                let lo = hex_val(chunk[1])?;
290                result.push((hi << 4) | lo);
291            }
292            Ok(result)
293        }
294
295        fn hex_val(b: u8) -> Result<u8, String> {
296            match b {
297                b'0'..=b'9' => Ok(b - b'0'),
298                b'a'..=b'f' => Ok(b - b'a' + 10),
299                b'A'..=b'F' => Ok(b - b'A' + 10),
300                _ => Err(format!("invalid hex character: {}", b as char)),
301            }
302        }
303    }
304
305    /// Serialize/deserialize `Option<Vec<u8>>` as optional hex string.
306    pub mod option_bytes_as_hex {
307        use serde::{self, Deserialize, Deserializer, Serializer};
308
309        pub fn serialize<S>(bytes: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
310        where
311            S: Serializer,
312        {
313            match bytes {
314                Some(b) => super::bytes_as_hex::serialize(b, serializer),
315                None => serializer.serialize_none(),
316            }
317        }
318
319        pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
320        where
321            D: Deserializer<'de>,
322        {
323            let opt: Option<String> = Option::deserialize(deserializer)?;
324            match opt {
325                Some(s) if !s.is_empty() => super::bytes_as_hex::from_hex(&s)
326                    .map(Some)
327                    .map_err(serde::de::Error::custom),
328                _ => Ok(None),
329            }
330        }
331    }
332}
333
334// ---------------------------------------------------------------------------
335// Enums
336// ---------------------------------------------------------------------------
337
338/// Current state of a transaction action.
339#[derive(Clone, Debug, PartialEq, Eq)]
340#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
341#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
342pub enum ActionStatus {
343    Completed,
344    Unprocessed,
345    Sending,
346    Unproven,
347    Unsigned,
348    #[cfg_attr(feature = "network", serde(rename = "nosend"))]
349    NoSend,
350    #[cfg_attr(feature = "network", serde(rename = "nonfinal"))]
351    NonFinal,
352}
353
354impl ActionStatus {
355    pub fn as_str(&self) -> &'static str {
356        match self {
357            ActionStatus::Completed => "completed",
358            ActionStatus::Unprocessed => "unprocessed",
359            ActionStatus::Sending => "sending",
360            ActionStatus::Unproven => "unproven",
361            ActionStatus::Unsigned => "unsigned",
362            ActionStatus::NoSend => "nosend",
363            ActionStatus::NonFinal => "nonfinal",
364        }
365    }
366}
367
368/// Status of a transaction result (subset of ActionStatus).
369#[derive(Clone, Debug, PartialEq, Eq)]
370#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
371#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
372pub enum ActionResultStatus {
373    Unproven,
374    Sending,
375    Failed,
376}
377
378impl ActionResultStatus {
379    pub fn as_str(&self) -> &'static str {
380        match self {
381            ActionResultStatus::Unproven => "unproven",
382            ActionResultStatus::Sending => "sending",
383            ActionResultStatus::Failed => "failed",
384        }
385    }
386}
387
388/// How multiple criteria are combined in queries.
389#[derive(Clone, Debug, PartialEq, Eq)]
390#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
391#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
392pub enum QueryMode {
393    Any,
394    All,
395}
396
397impl QueryMode {
398    pub fn as_str(&self) -> &'static str {
399        match self {
400            QueryMode::Any => "any",
401            QueryMode::All => "all",
402        }
403    }
404}
405
406/// What additional data to include with output listings.
407#[derive(Clone, Debug, PartialEq, Eq)]
408#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
409pub enum OutputInclude {
410    #[cfg_attr(feature = "network", serde(rename = "locking scripts"))]
411    LockingScripts,
412    #[cfg_attr(feature = "network", serde(rename = "entire transactions"))]
413    EntireTransactions,
414}
415
416impl OutputInclude {
417    pub fn as_str(&self) -> &'static str {
418        match self {
419            OutputInclude::LockingScripts => "locking scripts",
420            OutputInclude::EntireTransactions => "entire transactions",
421        }
422    }
423}
424
425/// Protocol for internalizing transaction outputs.
426#[derive(Clone, Debug, PartialEq, Eq)]
427#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
428pub enum InternalizeProtocol {
429    #[cfg_attr(feature = "network", serde(rename = "wallet payment"))]
430    WalletPayment,
431    #[cfg_attr(feature = "network", serde(rename = "basket insertion"))]
432    BasketInsertion,
433}
434
435impl InternalizeProtocol {
436    pub fn as_str(&self) -> &'static str {
437        match self {
438            InternalizeProtocol::WalletPayment => "wallet payment",
439            InternalizeProtocol::BasketInsertion => "basket insertion",
440        }
441    }
442}
443
444/// Protocol for certificate acquisition.
445#[derive(Clone, Debug, PartialEq, Eq)]
446#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
447#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
448pub enum AcquisitionProtocol {
449    Direct,
450    Issuance,
451}
452
453impl AcquisitionProtocol {
454    pub fn as_str(&self) -> &'static str {
455        match self {
456            AcquisitionProtocol::Direct => "direct",
457            AcquisitionProtocol::Issuance => "issuance",
458        }
459    }
460}
461
462/// Blockchain network type.
463#[derive(Clone, Debug, PartialEq, Eq)]
464#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
465#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
466pub enum Network {
467    Mainnet,
468    Testnet,
469}
470
471impl Network {
472    pub fn as_str(&self) -> &'static str {
473        match self {
474            Network::Mainnet => "mainnet",
475            Network::Testnet => "testnet",
476        }
477    }
478}
479
480/// Trust level for self-referential operations.
481#[derive(Clone, Debug, PartialEq, Eq)]
482#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
483#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
484pub enum TrustSelf {
485    Known,
486}
487
488impl TrustSelf {
489    pub fn as_str(&self) -> &'static str {
490        match self {
491            TrustSelf::Known => "known",
492        }
493    }
494}
495
496// ---------------------------------------------------------------------------
497// Core types: Certificate, CertificateType, SerialNumber, KeyringRevealer
498// ---------------------------------------------------------------------------
499
500/// Newtype wrapper for certificate type identifier (32 bytes).
501/// Serializes as base64 string matching Go SDK Bytes32Base64.
502#[derive(Clone, Debug, PartialEq, Eq, Hash)]
503pub struct CertificateType(pub [u8; 32]);
504
505#[cfg(feature = "network")]
506impl serde::Serialize for CertificateType {
507    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
508        serde_helpers::bytes32_base64::serialize(&self.0, serializer)
509    }
510}
511
512#[cfg(feature = "network")]
513impl<'de> serde::Deserialize<'de> for CertificateType {
514    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
515        serde_helpers::bytes32_base64::deserialize(deserializer).map(CertificateType)
516    }
517}
518
519impl CertificateType {
520    pub fn from_string(s: &str) -> Result<Self, WalletError> {
521        if s.len() > 32 {
522            return Err(WalletError::InvalidParameter(
523                "certificate type string longer than 32 bytes".to_string(),
524            ));
525        }
526        let mut buf = [0u8; 32];
527        buf[..s.len()].copy_from_slice(s.as_bytes());
528        Ok(CertificateType(buf))
529    }
530
531    pub fn bytes(&self) -> &[u8; 32] {
532        &self.0
533    }
534}
535
536/// Newtype wrapper for certificate serial number (32 bytes).
537/// Serializes as base64 string matching Go SDK Bytes32Base64.
538#[derive(Clone, Debug, PartialEq, Eq, Hash)]
539pub struct SerialNumber(pub [u8; 32]);
540
541#[cfg(feature = "network")]
542impl serde::Serialize for SerialNumber {
543    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
544        serde_helpers::bytes32_base64::serialize(&self.0, serializer)
545    }
546}
547
548#[cfg(feature = "network")]
549impl<'de> serde::Deserialize<'de> for SerialNumber {
550    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
551        serde_helpers::bytes32_base64::deserialize(deserializer).map(SerialNumber)
552    }
553}
554
555/// A certificate in the wallet.
556#[derive(Clone, Debug)]
557#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
558#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
559pub struct Certificate {
560    #[cfg_attr(feature = "network", serde(rename = "type"))]
561    pub cert_type: CertificateType,
562    pub serial_number: SerialNumber,
563    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
564    pub subject: PublicKey,
565    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
566    pub certifier: PublicKey,
567    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
568    pub revocation_outpoint: Option<String>,
569    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
570    pub fields: Option<HashMap<String, String>>,
571    #[cfg_attr(
572        feature = "network",
573        serde(with = "serde_helpers::option_bytes_as_hex")
574    )]
575    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
576    pub signature: Option<Vec<u8>>,
577}
578
579/// Identifies who reveals a keyring.
580#[derive(Clone, Debug)]
581pub enum KeyringRevealer {
582    /// The certifier reveals the keyring.
583    Certifier,
584    /// A specific public key reveals the keyring.
585    PubKey(PublicKey),
586}
587
588#[cfg(feature = "network")]
589impl serde::Serialize for KeyringRevealer {
590    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
591        match self {
592            KeyringRevealer::Certifier => serializer.serialize_str("certifier"),
593            KeyringRevealer::PubKey(pk) => serializer.serialize_str(&pk.to_der_hex()),
594        }
595    }
596}
597
598#[cfg(feature = "network")]
599impl<'de> serde::Deserialize<'de> for KeyringRevealer {
600    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
601        let s = String::deserialize(deserializer)?;
602        if s == "certifier" || s.is_empty() {
603            Ok(KeyringRevealer::Certifier)
604        } else {
605            PublicKey::from_string(&s)
606                .map(KeyringRevealer::PubKey)
607                .map_err(serde::de::Error::custom)
608        }
609    }
610}
611
612// ---------------------------------------------------------------------------
613// Action types (CreateAction, SignAction, AbortAction)
614// ---------------------------------------------------------------------------
615
616/// An input to be spent in a new transaction.
617#[derive(Clone, Debug)]
618#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
619#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
620pub struct CreateActionInput {
621    pub outpoint: OutpointString,
622    pub input_description: String,
623    #[cfg_attr(
624        feature = "network",
625        serde(with = "serde_helpers::option_bytes_as_hex")
626    )]
627    #[cfg_attr(
628        feature = "network",
629        serde(skip_serializing_if = "Option::is_none", default)
630    )]
631    pub unlocking_script: Option<Vec<u8>>,
632    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
633    pub unlocking_script_length: Option<u32>,
634    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
635    pub sequence_number: Option<u32>,
636}
637
638/// An output to be created in a new transaction.
639#[derive(Clone, Debug)]
640#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
641#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
642pub struct CreateActionOutput {
643    #[cfg_attr(
644        feature = "network",
645        serde(with = "serde_helpers::option_bytes_as_hex")
646    )]
647    #[cfg_attr(
648        feature = "network",
649        serde(skip_serializing_if = "Option::is_none", default)
650    )]
651    pub locking_script: Option<Vec<u8>>,
652    pub satoshis: SatoshiValue,
653    pub output_description: String,
654    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
655    pub basket: Option<BasketStringUnder300Bytes>,
656    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
657    pub custom_instructions: Option<String>,
658    #[cfg_attr(
659        feature = "network",
660        serde(skip_serializing_if = "Vec::is_empty", default)
661    )]
662    pub tags: Vec<OutputTagStringUnder300Bytes>,
663}
664
665/// Optional parameters for creating a new transaction.
666#[derive(Clone, Debug)]
667#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
668#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
669pub struct CreateActionOptions {
670    pub sign_and_process: BooleanDefaultTrue,
671    pub accept_delayed_broadcast: BooleanDefaultTrue,
672    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
673    pub trust_self: Option<TrustSelf>,
674    #[cfg_attr(
675        feature = "network",
676        serde(skip_serializing_if = "Vec::is_empty", default)
677    )]
678    pub known_txids: Vec<TXIDHexString>,
679    pub return_txid_only: BooleanDefaultFalse,
680    pub no_send: BooleanDefaultFalse,
681    #[cfg_attr(
682        feature = "network",
683        serde(skip_serializing_if = "Vec::is_empty", default)
684    )]
685    pub no_send_change: Vec<OutpointString>,
686    #[cfg_attr(
687        feature = "network",
688        serde(skip_serializing_if = "Vec::is_empty", default)
689    )]
690    pub send_with: Vec<TXIDHexString>,
691    pub randomize_outputs: BooleanDefaultTrue,
692}
693
694/// Arguments for creating a new transaction.
695#[derive(Clone, Debug)]
696#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
697#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
698pub struct CreateActionArgs {
699    pub description: DescriptionString5to50Bytes,
700    #[cfg_attr(
701        feature = "network",
702        serde(with = "serde_helpers::option_bytes_as_array")
703    )]
704    #[cfg_attr(
705        feature = "network",
706        serde(skip_serializing_if = "Option::is_none", default)
707    )]
708    #[cfg_attr(feature = "network", serde(rename = "inputBEEF"))]
709    pub input_beef: Option<Vec<u8>>,
710    #[cfg_attr(
711        feature = "network",
712        serde(skip_serializing_if = "Vec::is_empty", default)
713    )]
714    pub inputs: Vec<CreateActionInput>,
715    #[cfg_attr(
716        feature = "network",
717        serde(skip_serializing_if = "Vec::is_empty", default)
718    )]
719    pub outputs: Vec<CreateActionOutput>,
720    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
721    pub lock_time: Option<u32>,
722    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
723    pub version: Option<u32>,
724    #[cfg_attr(
725        feature = "network",
726        serde(skip_serializing_if = "Vec::is_empty", default)
727    )]
728    pub labels: Vec<LabelStringUnder300Bytes>,
729    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
730    pub options: Option<CreateActionOptions>,
731    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
732    pub reference: Option<String>,
733}
734
735/// Data needed to complete signing of a partial transaction.
736#[derive(Clone, Debug)]
737#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
738#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
739pub struct SignableTransaction {
740    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
741    pub tx: Vec<u8>,
742    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
743    pub reference: Vec<u8>,
744}
745
746/// Status of a transaction sent as part of a batch.
747#[derive(Clone, Debug)]
748#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
749#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
750pub struct SendWithResult {
751    pub txid: TXIDHexString,
752    pub status: ActionResultStatus,
753}
754
755/// Result of creating a transaction.
756#[derive(Clone, Debug)]
757#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
758#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
759pub struct CreateActionResult {
760    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
761    pub txid: Option<TXIDHexString>,
762    #[cfg_attr(
763        feature = "network",
764        serde(with = "serde_helpers::option_bytes_as_array")
765    )]
766    #[cfg_attr(
767        feature = "network",
768        serde(skip_serializing_if = "Option::is_none", default)
769    )]
770    pub tx: Option<Vec<u8>>,
771    #[cfg_attr(
772        feature = "network",
773        serde(skip_serializing_if = "Vec::is_empty", default)
774    )]
775    pub no_send_change: Vec<OutpointString>,
776    #[cfg_attr(
777        feature = "network",
778        serde(skip_serializing_if = "Vec::is_empty", default)
779    )]
780    pub send_with_results: Vec<SendWithResult>,
781    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
782    pub signable_transaction: Option<SignableTransaction>,
783}
784
785/// Unlocking script and sequence number for a specific input.
786#[derive(Clone, Debug)]
787#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
788#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
789pub struct SignActionSpend {
790    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_hex"))]
791    pub unlocking_script: Vec<u8>,
792    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
793    pub sequence_number: Option<u32>,
794}
795
796/// Controls signing and broadcasting behavior.
797#[derive(Clone, Debug)]
798#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
799#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
800pub struct SignActionOptions {
801    pub accept_delayed_broadcast: BooleanDefaultTrue,
802    pub return_txid_only: BooleanDefaultFalse,
803    pub no_send: BooleanDefaultFalse,
804    #[cfg_attr(
805        feature = "network",
806        serde(skip_serializing_if = "Vec::is_empty", default)
807    )]
808    pub send_with: Vec<TXIDHexString>,
809}
810
811/// Arguments for signing a previously created transaction.
812#[derive(Clone, Debug)]
813#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
814#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
815pub struct SignActionArgs {
816    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
817    pub reference: Vec<u8>,
818    pub spends: HashMap<u32, SignActionSpend>,
819    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
820    pub options: Option<SignActionOptions>,
821}
822
823/// Result of a successful signing operation.
824#[derive(Clone, Debug)]
825#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
826#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
827pub struct SignActionResult {
828    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
829    pub txid: Option<TXIDHexString>,
830    #[cfg_attr(
831        feature = "network",
832        serde(with = "serde_helpers::option_bytes_as_array")
833    )]
834    #[cfg_attr(
835        feature = "network",
836        serde(skip_serializing_if = "Option::is_none", default)
837    )]
838    pub tx: Option<Vec<u8>>,
839    #[cfg_attr(
840        feature = "network",
841        serde(skip_serializing_if = "Vec::is_empty", default)
842    )]
843    pub send_with_results: Vec<SendWithResult>,
844}
845
846/// Arguments for aborting a transaction.
847#[derive(Clone, Debug)]
848#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
849#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
850pub struct AbortActionArgs {
851    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
852    pub reference: Vec<u8>,
853}
854
855/// Result of aborting a transaction.
856#[derive(Clone, Debug)]
857#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
858#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
859pub struct AbortActionResult {
860    pub aborted: bool,
861}
862
863// ---------------------------------------------------------------------------
864// Action detail types (for listing)
865// ---------------------------------------------------------------------------
866
867/// A transaction input with full details.
868#[derive(Clone, Debug)]
869#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
870#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
871pub struct ActionInput {
872    pub source_outpoint: OutpointString,
873    pub source_satoshis: SatoshiValue,
874    #[cfg_attr(
875        feature = "network",
876        serde(with = "serde_helpers::option_bytes_as_hex")
877    )]
878    #[cfg_attr(
879        feature = "network",
880        serde(skip_serializing_if = "Option::is_none", default)
881    )]
882    pub source_locking_script: Option<Vec<u8>>,
883    #[cfg_attr(
884        feature = "network",
885        serde(with = "serde_helpers::option_bytes_as_hex")
886    )]
887    #[cfg_attr(
888        feature = "network",
889        serde(skip_serializing_if = "Option::is_none", default)
890    )]
891    pub unlocking_script: Option<Vec<u8>>,
892    pub input_description: String,
893    pub sequence_number: u32,
894}
895
896/// A transaction output with full details.
897#[derive(Clone, Debug)]
898#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
899#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
900pub struct ActionOutput {
901    pub satoshis: SatoshiValue,
902    #[cfg_attr(
903        feature = "network",
904        serde(with = "serde_helpers::option_bytes_as_hex")
905    )]
906    #[cfg_attr(
907        feature = "network",
908        serde(skip_serializing_if = "Option::is_none", default)
909    )]
910    pub locking_script: Option<Vec<u8>>,
911    pub spendable: bool,
912    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
913    pub custom_instructions: Option<String>,
914    pub tags: Vec<String>,
915    pub output_index: u32,
916    pub output_description: String,
917    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
918    pub basket: Option<String>,
919}
920
921/// Full details about a wallet transaction.
922#[derive(Clone, Debug)]
923#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
924#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
925pub struct Action {
926    pub txid: TXIDHexString,
927    pub satoshis: i64,
928    pub status: ActionStatus,
929    pub is_outgoing: bool,
930    pub description: String,
931    #[cfg_attr(
932        feature = "network",
933        serde(skip_serializing_if = "Vec::is_empty", default)
934    )]
935    pub labels: Vec<String>,
936    pub version: u32,
937    pub lock_time: u32,
938    #[cfg_attr(
939        feature = "network",
940        serde(skip_serializing_if = "Vec::is_empty", default)
941    )]
942    pub inputs: Vec<ActionInput>,
943    #[cfg_attr(
944        feature = "network",
945        serde(skip_serializing_if = "Vec::is_empty", default)
946    )]
947    pub outputs: Vec<ActionOutput>,
948}
949
950/// Maximum number of actions or outputs that can be returned.
951pub const MAX_ACTIONS_LIMIT: u32 = 10000;
952
953// ---------------------------------------------------------------------------
954// ListActions
955// ---------------------------------------------------------------------------
956
957/// Filtering and pagination options for listing wallet transactions.
958#[derive(Clone, Debug)]
959#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
960#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
961pub struct ListActionsArgs {
962    pub labels: Vec<LabelStringUnder300Bytes>,
963    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
964    pub label_query_mode: Option<QueryMode>,
965    pub include_labels: BooleanDefaultFalse,
966    pub include_inputs: BooleanDefaultFalse,
967    pub include_input_source_locking_scripts: BooleanDefaultFalse,
968    pub include_input_unlocking_scripts: BooleanDefaultFalse,
969    pub include_outputs: BooleanDefaultFalse,
970    pub include_output_locking_scripts: BooleanDefaultFalse,
971    pub limit: PositiveIntegerDefault10Max10000,
972    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
973    pub offset: Option<PositiveIntegerOrZero>,
974    pub seek_permission: BooleanDefaultTrue,
975}
976
977/// Paginated list of wallet transactions.
978#[derive(Clone, Debug)]
979#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
980#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
981pub struct ListActionsResult {
982    pub total_actions: u32,
983    pub actions: Vec<Action>,
984}
985
986// ---------------------------------------------------------------------------
987// InternalizeAction
988// ---------------------------------------------------------------------------
989
990/// Derivation and identity data for wallet payment outputs.
991#[derive(Clone, Debug)]
992#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
993#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
994pub struct Payment {
995    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
996    pub derivation_prefix: Vec<u8>,
997    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
998    pub derivation_suffix: Vec<u8>,
999    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1000    pub sender_identity_key: PublicKey,
1001}
1002
1003/// Metadata for outputs being inserted into baskets.
1004#[derive(Clone, Debug)]
1005#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1006#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1007pub struct BasketInsertion {
1008    pub basket: BasketStringUnder300Bytes,
1009    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1010    pub custom_instructions: Option<String>,
1011    #[cfg_attr(
1012        feature = "network",
1013        serde(skip_serializing_if = "Vec::is_empty", default)
1014    )]
1015    pub tags: Vec<OutputTagStringUnder300Bytes>,
1016}
1017
1018/// How to process a transaction output -- as payment or basket insertion.
1019#[derive(Clone, Debug)]
1020#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1021#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1022pub struct InternalizeOutput {
1023    pub output_index: u32,
1024    pub protocol: InternalizeProtocol,
1025    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1026    pub payment_remittance: Option<Payment>,
1027    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1028    pub insertion_remittance: Option<BasketInsertion>,
1029}
1030
1031/// Arguments for importing an external transaction into the wallet.
1032#[derive(Clone, Debug)]
1033#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1034#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1035pub struct InternalizeActionArgs {
1036    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1037    pub tx: Vec<u8>,
1038    pub description: String,
1039    #[cfg_attr(
1040        feature = "network",
1041        serde(skip_serializing_if = "Vec::is_empty", default)
1042    )]
1043    pub labels: Vec<LabelStringUnder300Bytes>,
1044    pub seek_permission: BooleanDefaultTrue,
1045    pub outputs: Vec<InternalizeOutput>,
1046}
1047
1048/// Result of internalizing a transaction.
1049#[derive(Clone, Debug)]
1050#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1051#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1052pub struct InternalizeActionResult {
1053    pub accepted: bool,
1054}
1055
1056// ---------------------------------------------------------------------------
1057// ListOutputs
1058// ---------------------------------------------------------------------------
1059
1060/// Filtering and options for listing wallet outputs.
1061#[derive(Clone, Debug)]
1062#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1063#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1064pub struct ListOutputsArgs {
1065    pub basket: BasketStringUnder300Bytes,
1066    #[cfg_attr(
1067        feature = "network",
1068        serde(skip_serializing_if = "Vec::is_empty", default)
1069    )]
1070    pub tags: Vec<OutputTagStringUnder300Bytes>,
1071    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1072    pub tag_query_mode: Option<QueryMode>,
1073    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1074    pub include: Option<OutputInclude>,
1075    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1076    pub include_custom_instructions: BooleanDefaultFalse,
1077    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1078    pub include_tags: BooleanDefaultFalse,
1079    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1080    pub include_labels: BooleanDefaultFalse,
1081    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1082    pub limit: PositiveIntegerDefault10Max10000,
1083    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1084    pub offset: Option<PositiveIntegerOrZero>,
1085    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1086    pub seek_permission: BooleanDefaultTrue,
1087}
1088
1089/// A wallet UTXO with its metadata.
1090#[derive(Clone, Debug)]
1091#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1092#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1093pub struct Output {
1094    pub satoshis: SatoshiValue,
1095    #[cfg_attr(
1096        feature = "network",
1097        serde(with = "serde_helpers::option_bytes_as_hex")
1098    )]
1099    #[cfg_attr(
1100        feature = "network",
1101        serde(skip_serializing_if = "Option::is_none", default)
1102    )]
1103    pub locking_script: Option<Vec<u8>>,
1104    pub spendable: bool,
1105    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1106    pub custom_instructions: Option<String>,
1107    #[cfg_attr(
1108        feature = "network",
1109        serde(skip_serializing_if = "Vec::is_empty", default)
1110    )]
1111    pub tags: Vec<String>,
1112    pub outpoint: OutpointString,
1113    #[cfg_attr(
1114        feature = "network",
1115        serde(skip_serializing_if = "Vec::is_empty", default)
1116    )]
1117    pub labels: Vec<String>,
1118}
1119
1120/// Paginated list of wallet outputs.
1121#[derive(Clone, Debug)]
1122#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1123#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1124pub struct ListOutputsResult {
1125    pub total_outputs: u32,
1126    #[cfg_attr(
1127        feature = "network",
1128        serde(with = "serde_helpers::option_bytes_as_array")
1129    )]
1130    #[cfg_attr(
1131        feature = "network",
1132        serde(skip_serializing_if = "Option::is_none", default)
1133    )]
1134    #[cfg_attr(feature = "network", serde(rename = "BEEF"))]
1135    pub beef: Option<Vec<u8>>,
1136    pub outputs: Vec<Output>,
1137}
1138
1139// ---------------------------------------------------------------------------
1140// RelinquishOutput
1141// ---------------------------------------------------------------------------
1142
1143/// Arguments for relinquishing ownership of an output.
1144#[derive(Clone, Debug)]
1145#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1146#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1147pub struct RelinquishOutputArgs {
1148    pub basket: BasketStringUnder300Bytes,
1149    pub output: OutpointString,
1150}
1151
1152/// Result of relinquishing an output.
1153#[derive(Clone, Debug)]
1154#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1155#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1156pub struct RelinquishOutputResult {
1157    pub relinquished: bool,
1158}
1159
1160// ---------------------------------------------------------------------------
1161// Key/Crypto types
1162// ---------------------------------------------------------------------------
1163
1164/// Arguments for getting a public key.
1165#[derive(Clone, Debug)]
1166#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1167#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1168pub struct GetPublicKeyArgs {
1169    pub identity_key: bool,
1170    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1171    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1172    pub protocol_id: Option<Protocol>,
1173    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1174    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1175    pub key_id: Option<String>,
1176    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1177    pub counterparty: Option<Counterparty>,
1178    pub privileged: bool,
1179    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1180    pub privileged_reason: Option<String>,
1181    pub for_self: Option<bool>,
1182    pub seek_permission: Option<bool>,
1183}
1184
1185/// Result of getting a public key.
1186#[derive(Clone, Debug)]
1187#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1188#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1189pub struct GetPublicKeyResult {
1190    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1191    pub public_key: PublicKey,
1192}
1193
1194/// Arguments for encryption.
1195#[derive(Clone, Debug)]
1196#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1197#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1198pub struct EncryptArgs {
1199    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1200    pub protocol_id: Protocol,
1201    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1202    pub key_id: String,
1203    pub counterparty: Counterparty,
1204    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1205    pub plaintext: Vec<u8>,
1206    pub privileged: bool,
1207    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1208    pub privileged_reason: Option<String>,
1209    pub seek_permission: Option<bool>,
1210}
1211
1212/// Result of encryption.
1213#[derive(Clone, Debug)]
1214#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1215#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1216pub struct EncryptResult {
1217    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1218    pub ciphertext: Vec<u8>,
1219}
1220
1221/// Arguments for decryption.
1222#[derive(Clone, Debug)]
1223#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1224#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1225pub struct DecryptArgs {
1226    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1227    pub protocol_id: Protocol,
1228    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1229    pub key_id: String,
1230    pub counterparty: Counterparty,
1231    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1232    pub ciphertext: Vec<u8>,
1233    pub privileged: bool,
1234    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1235    pub privileged_reason: Option<String>,
1236    pub seek_permission: Option<bool>,
1237}
1238
1239/// Result of decryption.
1240#[derive(Clone, Debug)]
1241#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1242#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1243pub struct DecryptResult {
1244    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1245    pub plaintext: Vec<u8>,
1246}
1247
1248/// Arguments for creating an HMAC.
1249#[derive(Clone, Debug)]
1250#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1251#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1252pub struct CreateHmacArgs {
1253    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1254    pub protocol_id: Protocol,
1255    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1256    pub key_id: String,
1257    pub counterparty: Counterparty,
1258    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1259    pub data: Vec<u8>,
1260    pub privileged: bool,
1261    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1262    pub privileged_reason: Option<String>,
1263    pub seek_permission: Option<bool>,
1264}
1265
1266/// Result of creating an HMAC.
1267#[derive(Clone, Debug)]
1268#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1269#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1270pub struct CreateHmacResult {
1271    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1272    pub hmac: Vec<u8>,
1273}
1274
1275/// Arguments for verifying an HMAC.
1276#[derive(Clone, Debug)]
1277#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1278#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1279pub struct VerifyHmacArgs {
1280    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1281    pub protocol_id: Protocol,
1282    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1283    pub key_id: String,
1284    pub counterparty: Counterparty,
1285    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1286    pub data: Vec<u8>,
1287    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1288    pub hmac: Vec<u8>,
1289    pub privileged: bool,
1290    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1291    pub privileged_reason: Option<String>,
1292    pub seek_permission: Option<bool>,
1293}
1294
1295/// Result of verifying an HMAC.
1296#[derive(Clone, Debug)]
1297#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1298#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1299pub struct VerifyHmacResult {
1300    pub valid: bool,
1301}
1302
1303/// Arguments for creating a digital signature.
1304#[derive(Clone, Debug)]
1305#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1306#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1307pub struct CreateSignatureArgs {
1308    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1309    pub protocol_id: Protocol,
1310    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1311    pub key_id: String,
1312    pub counterparty: Counterparty,
1313    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1314    pub data: Vec<u8>,
1315    pub privileged: bool,
1316    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1317    pub privileged_reason: Option<String>,
1318    pub seek_permission: Option<bool>,
1319}
1320
1321/// Result of creating a digital signature.
1322#[derive(Clone, Debug)]
1323#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1324#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1325pub struct CreateSignatureResult {
1326    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_hex"))]
1327    pub signature: Vec<u8>,
1328}
1329
1330/// Arguments for verifying a digital signature.
1331#[derive(Clone, Debug)]
1332#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1333#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1334pub struct VerifySignatureArgs {
1335    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1336    pub protocol_id: Protocol,
1337    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1338    pub key_id: String,
1339    pub counterparty: Counterparty,
1340    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1341    pub data: Vec<u8>,
1342    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_hex"))]
1343    pub signature: Vec<u8>,
1344    pub for_self: Option<bool>,
1345    pub privileged: bool,
1346    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1347    pub privileged_reason: Option<String>,
1348    pub seek_permission: Option<bool>,
1349}
1350
1351/// Result of verifying a digital signature.
1352#[derive(Clone, Debug)]
1353#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1354#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1355pub struct VerifySignatureResult {
1356    pub valid: bool,
1357}
1358
1359// ---------------------------------------------------------------------------
1360// Certificate operations
1361// ---------------------------------------------------------------------------
1362
1363/// Arguments for acquiring a new certificate.
1364#[derive(Clone, Debug)]
1365#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1366#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1367pub struct AcquireCertificateArgs {
1368    #[cfg_attr(feature = "network", serde(rename = "type"))]
1369    pub cert_type: CertificateType,
1370    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1371    pub certifier: PublicKey,
1372    pub acquisition_protocol: AcquisitionProtocol,
1373    #[cfg_attr(
1374        feature = "network",
1375        serde(skip_serializing_if = "HashMap::is_empty", default)
1376    )]
1377    pub fields: HashMap<String, String>,
1378    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1379    pub serial_number: Option<SerialNumber>,
1380    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1381    pub revocation_outpoint: Option<String>,
1382    #[cfg_attr(
1383        feature = "network",
1384        serde(with = "serde_helpers::option_bytes_as_hex")
1385    )]
1386    #[cfg_attr(
1387        feature = "network",
1388        serde(skip_serializing_if = "Option::is_none", default)
1389    )]
1390    pub signature: Option<Vec<u8>>,
1391    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1392    pub certifier_url: Option<String>,
1393    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1394    pub keyring_revealer: Option<KeyringRevealer>,
1395    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1396    pub keyring_for_subject: Option<HashMap<String, String>>,
1397    pub privileged: bool,
1398    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1399    pub privileged_reason: Option<String>,
1400}
1401
1402/// Arguments for listing certificates.
1403#[derive(Clone, Debug)]
1404#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1405#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1406pub struct ListCertificatesArgs {
1407    #[cfg_attr(feature = "network", serde(with = "serde_helpers::vec_public_key_hex"))]
1408    pub certifiers: Vec<PublicKey>,
1409    pub types: Vec<CertificateType>,
1410    pub limit: PositiveIntegerDefault10Max10000,
1411    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1412    pub offset: Option<PositiveIntegerOrZero>,
1413    pub privileged: BooleanDefaultFalse,
1414    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1415    pub privileged_reason: Option<String>,
1416}
1417
1418/// A certificate with its keyring and verifier.
1419#[derive(Clone, Debug)]
1420#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1421#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1422pub struct CertificateResult {
1423    #[cfg_attr(feature = "network", serde(flatten))]
1424    pub certificate: Certificate,
1425    pub keyring: HashMap<String, String>,
1426    #[cfg_attr(
1427        feature = "network",
1428        serde(with = "serde_helpers::option_bytes_as_hex")
1429    )]
1430    #[cfg_attr(
1431        feature = "network",
1432        serde(skip_serializing_if = "Option::is_none", default)
1433    )]
1434    pub verifier: Option<Vec<u8>>,
1435}
1436
1437/// Paginated list of certificates.
1438#[derive(Clone, Debug)]
1439#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1440#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1441pub struct ListCertificatesResult {
1442    pub total_certificates: u32,
1443    pub certificates: Vec<CertificateResult>,
1444}
1445
1446/// Arguments for creating a verifiable certificate.
1447#[derive(Clone, Debug)]
1448#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1449#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1450pub struct ProveCertificateArgs {
1451    pub certificate: Certificate,
1452    pub fields_to_reveal: Vec<String>,
1453    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1454    pub verifier: PublicKey,
1455    pub privileged: BooleanDefaultFalse,
1456    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1457    pub privileged_reason: Option<String>,
1458}
1459
1460/// Result of creating a verifiable certificate.
1461#[derive(Clone, Debug)]
1462#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1463#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1464pub struct ProveCertificateResult {
1465    pub keyring_for_verifier: HashMap<String, String>,
1466}
1467
1468/// Arguments for relinquishing ownership of a certificate.
1469#[derive(Clone, Debug)]
1470#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1471#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1472pub struct RelinquishCertificateArgs {
1473    #[cfg_attr(feature = "network", serde(rename = "type"))]
1474    pub cert_type: CertificateType,
1475    pub serial_number: SerialNumber,
1476    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1477    pub certifier: PublicKey,
1478}
1479
1480/// Result of relinquishing a certificate.
1481#[derive(Clone, Debug)]
1482#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1483#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1484pub struct RelinquishCertificateResult {
1485    pub relinquished: bool,
1486}
1487
1488// ---------------------------------------------------------------------------
1489// Discovery types
1490// ---------------------------------------------------------------------------
1491
1492/// Information about an entity that issues identity certificates.
1493#[derive(Clone, Debug)]
1494#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1495#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1496pub struct IdentityCertifier {
1497    pub name: String,
1498    pub icon_url: String,
1499    pub description: String,
1500    pub trust: u8,
1501}
1502
1503/// An identity certificate with decoded fields and certifier info.
1504#[derive(Clone, Debug)]
1505#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1506#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1507pub struct IdentityCertificate {
1508    #[cfg_attr(feature = "network", serde(flatten))]
1509    pub certificate: Certificate,
1510    pub certifier_info: IdentityCertifier,
1511    pub publicly_revealed_keyring: HashMap<String, String>,
1512    pub decrypted_fields: HashMap<String, String>,
1513}
1514
1515/// Arguments for discovering certificates by identity key.
1516#[derive(Clone, Debug)]
1517#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1518#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1519pub struct DiscoverByIdentityKeyArgs {
1520    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1521    pub identity_key: PublicKey,
1522    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1523    pub limit: Option<u32>,
1524    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1525    pub offset: Option<u32>,
1526    pub seek_permission: Option<bool>,
1527}
1528
1529/// Arguments for discovering certificates by attributes.
1530#[derive(Clone, Debug)]
1531#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1532#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1533pub struct DiscoverByAttributesArgs {
1534    pub attributes: HashMap<String, String>,
1535    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1536    pub limit: Option<u32>,
1537    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1538    pub offset: Option<u32>,
1539    pub seek_permission: Option<bool>,
1540}
1541
1542/// Paginated list of identity certificates found during discovery.
1543#[derive(Clone, Debug)]
1544#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1545#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1546pub struct DiscoverCertificatesResult {
1547    pub total_certificates: u32,
1548    pub certificates: Vec<IdentityCertificate>,
1549}
1550
1551// ---------------------------------------------------------------------------
1552// Key linkage types
1553// ---------------------------------------------------------------------------
1554
1555/// Arguments for revealing key linkage between counterparties.
1556#[derive(Clone, Debug)]
1557#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1558#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1559pub struct RevealCounterpartyKeyLinkageArgs {
1560    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1561    pub counterparty: PublicKey,
1562    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1563    pub verifier: PublicKey,
1564    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1565    pub privileged: Option<bool>,
1566    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1567    pub privileged_reason: Option<String>,
1568}
1569
1570/// Result of revealing counterparty key linkage.
1571#[derive(Clone, Debug)]
1572#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1573#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1574pub struct RevealCounterpartyKeyLinkageResult {
1575    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1576    pub prover: PublicKey,
1577    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1578    pub counterparty: PublicKey,
1579    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1580    pub verifier: PublicKey,
1581    pub revelation_time: String,
1582    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1583    pub encrypted_linkage: Vec<u8>,
1584    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1585    pub encrypted_linkage_proof: Vec<u8>,
1586}
1587
1588/// Arguments for revealing specific key linkage.
1589#[derive(Clone, Debug)]
1590#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1591#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1592pub struct RevealSpecificKeyLinkageArgs {
1593    pub counterparty: Counterparty,
1594    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1595    pub verifier: PublicKey,
1596    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1597    pub protocol_id: Protocol,
1598    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1599    pub key_id: String,
1600    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1601    pub privileged: Option<bool>,
1602    #[cfg_attr(feature = "network", serde(skip_serializing_if = "Option::is_none"))]
1603    pub privileged_reason: Option<String>,
1604}
1605
1606/// Result of revealing specific key linkage.
1607#[derive(Clone, Debug)]
1608#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1609#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1610pub struct RevealSpecificKeyLinkageResult {
1611    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1612    pub encrypted_linkage: Vec<u8>,
1613    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_array"))]
1614    pub encrypted_linkage_proof: Vec<u8>,
1615    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1616    pub prover: PublicKey,
1617    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1618    pub verifier: PublicKey,
1619    #[cfg_attr(feature = "network", serde(with = "serde_helpers::public_key_hex"))]
1620    pub counterparty: PublicKey,
1621    #[cfg_attr(feature = "network", serde(rename = "protocolID"))]
1622    pub protocol_id: Protocol,
1623    #[cfg_attr(feature = "network", serde(rename = "keyID"))]
1624    pub key_id: String,
1625    pub proof_type: u8,
1626}
1627
1628// ---------------------------------------------------------------------------
1629// Auth/Info types
1630// ---------------------------------------------------------------------------
1631
1632/// Whether the current session is authenticated.
1633#[derive(Clone, Debug)]
1634#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1635#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1636pub struct AuthenticatedResult {
1637    pub authenticated: bool,
1638}
1639
1640/// Current blockchain height.
1641#[derive(Clone, Debug)]
1642#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1643#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1644pub struct GetHeightResult {
1645    pub height: u32,
1646}
1647
1648/// Arguments for retrieving a blockchain header at a specific height.
1649#[derive(Clone, Debug)]
1650#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1651#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1652pub struct GetHeaderArgs {
1653    pub height: u32,
1654}
1655
1656/// Blockchain header data for the requested height.
1657#[derive(Clone, Debug)]
1658#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1659#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1660pub struct GetHeaderResult {
1661    #[cfg_attr(feature = "network", serde(with = "serde_helpers::bytes_as_hex"))]
1662    pub header: Vec<u8>,
1663}
1664
1665/// Current blockchain network.
1666#[derive(Clone, Debug)]
1667#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1668#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1669pub struct GetNetworkResult {
1670    pub network: Network,
1671}
1672
1673/// Version information about the wallet implementation.
1674#[derive(Clone, Debug)]
1675#[cfg_attr(feature = "network", derive(serde::Serialize, serde::Deserialize))]
1676#[cfg_attr(feature = "network", serde(rename_all = "camelCase"))]
1677pub struct GetVersionResult {
1678    pub version: String,
1679}
1680
1681// ---------------------------------------------------------------------------
1682// WalletInterface trait
1683// ---------------------------------------------------------------------------
1684
1685/// The core wallet interface with all 28 async methods.
1686///
1687/// Uses `#[async_trait]` for object safety -- supports both static dispatch
1688/// (`W: WalletInterface`) and dynamic dispatch (`dyn WalletInterface`).
1689///
1690/// Every method takes `originator: Option<&str>` as the last parameter,
1691/// identifying the calling application domain.
1692#[async_trait]
1693pub trait WalletInterface: Send + Sync {
1694    // -- Action methods --
1695
1696    async fn create_action(
1697        &self,
1698        args: CreateActionArgs,
1699        originator: Option<&str>,
1700    ) -> Result<CreateActionResult, WalletError>;
1701
1702    async fn sign_action(
1703        &self,
1704        args: SignActionArgs,
1705        originator: Option<&str>,
1706    ) -> Result<SignActionResult, WalletError>;
1707
1708    async fn abort_action(
1709        &self,
1710        args: AbortActionArgs,
1711        originator: Option<&str>,
1712    ) -> Result<AbortActionResult, WalletError>;
1713
1714    async fn list_actions(
1715        &self,
1716        args: ListActionsArgs,
1717        originator: Option<&str>,
1718    ) -> Result<ListActionsResult, WalletError>;
1719
1720    async fn internalize_action(
1721        &self,
1722        args: InternalizeActionArgs,
1723        originator: Option<&str>,
1724    ) -> Result<InternalizeActionResult, WalletError>;
1725
1726    // -- Output methods --
1727
1728    async fn list_outputs(
1729        &self,
1730        args: ListOutputsArgs,
1731        originator: Option<&str>,
1732    ) -> Result<ListOutputsResult, WalletError>;
1733
1734    async fn relinquish_output(
1735        &self,
1736        args: RelinquishOutputArgs,
1737        originator: Option<&str>,
1738    ) -> Result<RelinquishOutputResult, WalletError>;
1739
1740    // -- Key/Crypto methods --
1741
1742    async fn get_public_key(
1743        &self,
1744        args: GetPublicKeyArgs,
1745        originator: Option<&str>,
1746    ) -> Result<GetPublicKeyResult, WalletError>;
1747
1748    async fn reveal_counterparty_key_linkage(
1749        &self,
1750        args: RevealCounterpartyKeyLinkageArgs,
1751        originator: Option<&str>,
1752    ) -> Result<RevealCounterpartyKeyLinkageResult, WalletError>;
1753
1754    async fn reveal_specific_key_linkage(
1755        &self,
1756        args: RevealSpecificKeyLinkageArgs,
1757        originator: Option<&str>,
1758    ) -> Result<RevealSpecificKeyLinkageResult, WalletError>;
1759
1760    async fn encrypt(
1761        &self,
1762        args: EncryptArgs,
1763        originator: Option<&str>,
1764    ) -> Result<EncryptResult, WalletError>;
1765
1766    async fn decrypt(
1767        &self,
1768        args: DecryptArgs,
1769        originator: Option<&str>,
1770    ) -> Result<DecryptResult, WalletError>;
1771
1772    async fn create_hmac(
1773        &self,
1774        args: CreateHmacArgs,
1775        originator: Option<&str>,
1776    ) -> Result<CreateHmacResult, WalletError>;
1777
1778    async fn verify_hmac(
1779        &self,
1780        args: VerifyHmacArgs,
1781        originator: Option<&str>,
1782    ) -> Result<VerifyHmacResult, WalletError>;
1783
1784    async fn create_signature(
1785        &self,
1786        args: CreateSignatureArgs,
1787        originator: Option<&str>,
1788    ) -> Result<CreateSignatureResult, WalletError>;
1789
1790    async fn verify_signature(
1791        &self,
1792        args: VerifySignatureArgs,
1793        originator: Option<&str>,
1794    ) -> Result<VerifySignatureResult, WalletError>;
1795
1796    // -- Certificate methods --
1797
1798    async fn acquire_certificate(
1799        &self,
1800        args: AcquireCertificateArgs,
1801        originator: Option<&str>,
1802    ) -> Result<Certificate, WalletError>;
1803
1804    async fn list_certificates(
1805        &self,
1806        args: ListCertificatesArgs,
1807        originator: Option<&str>,
1808    ) -> Result<ListCertificatesResult, WalletError>;
1809
1810    async fn prove_certificate(
1811        &self,
1812        args: ProveCertificateArgs,
1813        originator: Option<&str>,
1814    ) -> Result<ProveCertificateResult, WalletError>;
1815
1816    async fn relinquish_certificate(
1817        &self,
1818        args: RelinquishCertificateArgs,
1819        originator: Option<&str>,
1820    ) -> Result<RelinquishCertificateResult, WalletError>;
1821
1822    // -- Discovery methods --
1823
1824    async fn discover_by_identity_key(
1825        &self,
1826        args: DiscoverByIdentityKeyArgs,
1827        originator: Option<&str>,
1828    ) -> Result<DiscoverCertificatesResult, WalletError>;
1829
1830    async fn discover_by_attributes(
1831        &self,
1832        args: DiscoverByAttributesArgs,
1833        originator: Option<&str>,
1834    ) -> Result<DiscoverCertificatesResult, WalletError>;
1835
1836    // -- Auth/Info methods --
1837
1838    async fn is_authenticated(
1839        &self,
1840        originator: Option<&str>,
1841    ) -> Result<AuthenticatedResult, WalletError>;
1842
1843    async fn wait_for_authentication(
1844        &self,
1845        originator: Option<&str>,
1846    ) -> Result<AuthenticatedResult, WalletError>;
1847
1848    async fn get_height(&self, originator: Option<&str>) -> Result<GetHeightResult, WalletError>;
1849
1850    async fn get_header_for_height(
1851        &self,
1852        args: GetHeaderArgs,
1853        originator: Option<&str>,
1854    ) -> Result<GetHeaderResult, WalletError>;
1855
1856    async fn get_network(&self, originator: Option<&str>) -> Result<GetNetworkResult, WalletError>;
1857
1858    async fn get_version(&self, originator: Option<&str>) -> Result<GetVersionResult, WalletError>;
1859}