Skip to main content

bsv_wallet_cli/server/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// MetaNet Client request for getPublicKey
4#[derive(Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct McGetPublicKeyReq {
7    #[serde(default)]
8    pub identity_key: bool,
9    #[serde(default, alias = "protocolID")]
10    pub protocol_id: Option<serde_json::Value>,
11    #[serde(default, alias = "keyID")]
12    pub key_id: Option<String>,
13    #[serde(default)]
14    pub counterparty: Option<String>,
15    #[serde(default)]
16    pub for_self: Option<bool>,
17}
18
19/// MetaNet Client response for getPublicKey
20#[derive(Serialize)]
21#[serde(rename_all = "camelCase")]
22pub struct McGetPublicKeyRes {
23    pub public_key: String,
24}
25
26/// MetaNet Client request for createSignature
27#[derive(Deserialize)]
28#[serde(rename_all = "camelCase")]
29pub struct McCreateSignatureReq {
30    pub data: Vec<u8>,
31    #[serde(alias = "protocolID")]
32    pub protocol_id: serde_json::Value,
33    #[serde(alias = "keyID")]
34    pub key_id: String,
35    pub counterparty: String,
36}
37
38/// MetaNet Client response for createSignature
39#[derive(Serialize)]
40pub struct McCreateSignatureRes {
41    pub signature: Vec<u8>,
42}
43
44/// MetaNet Client request for createAction
45#[derive(Deserialize)]
46#[serde(rename_all = "camelCase")]
47pub struct McCreateActionReq {
48    pub description: String,
49    #[serde(default)]
50    pub outputs: Option<Vec<McCreateActionOutput>>,
51    #[serde(default)]
52    pub options: Option<McCreateActionOptions>,
53    #[serde(default)]
54    pub labels: Option<Vec<String>>,
55}
56
57#[derive(Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct McCreateActionOutput {
60    pub locking_script: String,
61    pub satoshis: u64,
62    pub output_description: String,
63    #[serde(default)]
64    pub basket: Option<String>,
65    #[serde(default)]
66    pub custom_instructions: Option<String>,
67    #[serde(default)]
68    pub tags: Option<Vec<String>>,
69}
70
71#[derive(Deserialize)]
72#[serde(rename_all = "camelCase")]
73pub struct McCreateActionOptions {
74    #[serde(default)]
75    pub accept_delayed_broadcast: Option<bool>,
76    #[serde(default)]
77    pub randomize_outputs: Option<bool>,
78    #[serde(default)]
79    pub sign_and_process: Option<bool>,
80    #[serde(default)]
81    pub no_send: Option<bool>,
82}
83
84/// MetaNet Client response for createAction
85#[derive(Serialize)]
86#[serde(rename_all = "camelCase")]
87pub struct McCreateActionRes {
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub txid: Option<String>,
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub tx: Option<Vec<u8>>,
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub send_with_results: Option<serde_json::Value>,
94    /// For signAndProcess: false — contains the unsigned tx and reference for signAction/abortAction.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub signable_transaction: Option<McSignableTransaction>,
97    /// Change outpoints for noSend transactions.
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub no_send_change: Option<serde_json::Value>,
100}
101
102/// Unsigned transaction + reference for deferred signing flow.
103#[derive(Serialize)]
104#[serde(rename_all = "camelCase")]
105pub struct McSignableTransaction {
106    /// The unsigned transaction bytes (number array).
107    pub tx: Vec<u8>,
108    /// The reference string for signAction/abortAction.
109    /// NOTE: The SDK stores this as Vec<u8> (from String.into_bytes()) then hex-encodes it.
110    /// We reverse that: convert bytes back to the original String so signAction/abortAction
111    /// can look it up correctly in the wallet's pending transaction cache.
112    pub reference: String,
113}
114
115/// MetaNet Client request for internalizeAction
116#[derive(Deserialize)]
117#[serde(rename_all = "camelCase")]
118pub struct McInternalizeActionReq {
119    pub tx: Vec<u8>,
120    pub outputs: Vec<McInternalizeOutput>,
121    pub description: String,
122}
123
124#[derive(Deserialize)]
125#[serde(rename_all = "camelCase")]
126pub struct McInternalizeOutput {
127    pub output_index: u32,
128    pub protocol: String,
129    #[serde(default)]
130    pub payment_remittance: Option<McWalletPayment>,
131    #[serde(default)]
132    pub insertion_remittance: Option<McBasketInsertion>,
133}
134
135#[derive(Deserialize)]
136#[serde(rename_all = "camelCase")]
137pub struct McBasketInsertion {
138    pub basket: String,
139    #[serde(default)]
140    pub custom_instructions: Option<String>,
141    #[serde(default)]
142    pub tags: Option<Vec<String>>,
143}
144
145#[derive(Deserialize)]
146#[serde(rename_all = "camelCase")]
147pub struct McWalletPayment {
148    pub derivation_prefix: String,
149    pub derivation_suffix: String,
150    pub sender_identity_key: String,
151}
152
153/// MetaNet Client response for internalizeAction
154#[derive(Serialize)]
155pub struct McInternalizeActionRes {
156    pub accepted: bool,
157}
158
159// =============================================================================
160// Batch 3: Crypto request types (SDK args lack serde)
161// =============================================================================
162
163/// MetaNet Client request for verifySignature
164#[derive(Deserialize)]
165#[serde(rename_all = "camelCase")]
166pub struct McVerifySignatureReq {
167    #[serde(default)]
168    pub data: Option<Vec<u8>>,
169    pub signature: Vec<u8>,
170    #[serde(alias = "protocolID")]
171    pub protocol_id: serde_json::Value,
172    #[serde(alias = "keyID")]
173    pub key_id: String,
174    #[serde(default)]
175    pub counterparty: Option<String>,
176    #[serde(default)]
177    pub for_self: Option<bool>,
178}
179
180/// MetaNet Client request for encrypt
181#[derive(Deserialize)]
182#[serde(rename_all = "camelCase")]
183pub struct McEncryptReq {
184    pub plaintext: Vec<u8>,
185    #[serde(alias = "protocolID")]
186    pub protocol_id: serde_json::Value,
187    #[serde(alias = "keyID")]
188    pub key_id: String,
189    #[serde(default)]
190    pub counterparty: Option<String>,
191}
192
193/// MetaNet Client request for decrypt
194#[derive(Deserialize)]
195#[serde(rename_all = "camelCase")]
196pub struct McDecryptReq {
197    pub ciphertext: Vec<u8>,
198    #[serde(alias = "protocolID")]
199    pub protocol_id: serde_json::Value,
200    #[serde(alias = "keyID")]
201    pub key_id: String,
202    #[serde(default)]
203    pub counterparty: Option<String>,
204}
205
206/// MetaNet Client request for createHmac
207#[derive(Deserialize)]
208#[serde(rename_all = "camelCase")]
209pub struct McCreateHmacReq {
210    pub data: Vec<u8>,
211    #[serde(alias = "protocolID")]
212    pub protocol_id: serde_json::Value,
213    #[serde(alias = "keyID")]
214    pub key_id: String,
215    #[serde(default)]
216    pub counterparty: Option<String>,
217}
218
219/// MetaNet Client request for verifyHmac
220#[derive(Deserialize)]
221#[serde(rename_all = "camelCase")]
222pub struct McVerifyHmacReq {
223    pub data: Vec<u8>,
224    pub hmac: Vec<u8>,
225    #[serde(alias = "protocolID")]
226    pub protocol_id: serde_json::Value,
227    #[serde(alias = "keyID")]
228    pub key_id: String,
229    #[serde(default)]
230    pub counterparty: Option<String>,
231}
232
233// =============================================================================
234// Batch 6: Key linkage request types (SDK args lack serde)
235// =============================================================================
236
237/// MetaNet Client request for revealCounterpartyKeyLinkage
238#[derive(Deserialize)]
239#[serde(rename_all = "camelCase")]
240pub struct McRevealCounterpartyKeyLinkageReq {
241    pub counterparty: String,
242    pub verifier: String,
243    #[serde(default)]
244    pub privileged: Option<bool>,
245    #[serde(default)]
246    pub privileged_reason: Option<String>,
247}
248
249/// MetaNet Client request for revealSpecificKeyLinkage
250#[derive(Deserialize)]
251#[serde(rename_all = "camelCase")]
252pub struct McRevealSpecificKeyLinkageReq {
253    pub counterparty: String,
254    pub verifier: String,
255    #[serde(alias = "protocolID")]
256    pub protocol_id: serde_json::Value,
257    #[serde(alias = "keyID")]
258    pub key_id: String,
259    #[serde(default)]
260    pub privileged: Option<bool>,
261    #[serde(default)]
262    pub privileged_reason: Option<String>,
263}