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    /// Raw data to hash-then-sign. Mutually exclusive with
31    /// `hash_to_directly_sign` (ts-sdk sends exactly one of the two).
32    #[serde(default)]
33    pub data: Option<Vec<u8>>,
34    /// A 32-byte digest to sign as-is (ts-sdk `hashToDirectlySign`).
35    #[serde(default)]
36    pub hash_to_directly_sign: Option<Vec<u8>>,
37    #[serde(alias = "protocolID")]
38    pub protocol_id: serde_json::Value,
39    #[serde(alias = "keyID")]
40    pub key_id: String,
41    pub counterparty: String,
42}
43
44/// MetaNet Client response for createSignature
45#[derive(Serialize)]
46pub struct McCreateSignatureRes {
47    pub signature: Vec<u8>,
48}
49
50/// MetaNet Client request for createAction
51#[derive(Deserialize)]
52#[serde(rename_all = "camelCase")]
53pub struct McCreateActionReq {
54    pub description: String,
55    /// Caller-provided explicit inputs (covenant spends carry a full
56    /// unlockingScript). Absent/empty => wallet auto-selects its own UTXOs.
57    #[serde(default)]
58    pub inputs: Option<Vec<McCreateActionInput>>,
59    /// BEEF (Byte[]) of the input transactions' source txs/ancestry, so the
60    /// wallet can validate explicit external inputs. `@bsv/sdk` sends this key
61    /// as `inputBEEF` (not camelCase `inputBeef`), as a raw JSON byte array.
62    #[serde(default, rename = "inputBEEF")]
63    pub input_beef: Option<Vec<u8>>,
64    #[serde(default)]
65    pub outputs: Option<Vec<McCreateActionOutput>>,
66    /// nLockTime for the spending tx (required by CLTV-gated covenants).
67    #[serde(default)]
68    pub lock_time: Option<u32>,
69    #[serde(default)]
70    pub options: Option<McCreateActionOptions>,
71    #[serde(default)]
72    pub labels: Option<Vec<String>>,
73}
74
75/// A single caller-provided input for createAction.
76#[derive(Deserialize)]
77#[serde(rename_all = "camelCase")]
78pub struct McCreateActionInput {
79    /// "txid.vout"
80    pub outpoint: String,
81    /// Fully-provided unlocking script (hex). Use this OR unlocking_script_length.
82    #[serde(default)]
83    pub unlocking_script: Option<String>,
84    /// Length of a to-be-signed unlocking script (deferred-signing flow).
85    #[serde(default)]
86    pub unlocking_script_length: Option<u32>,
87    #[serde(default)]
88    pub input_description: Option<String>,
89    /// nSequence for this input (e.g. 0xfffffffe to make a covenant timeLock non-final).
90    #[serde(default)]
91    pub sequence_number: Option<u32>,
92}
93
94#[derive(Deserialize)]
95#[serde(rename_all = "camelCase")]
96pub struct McCreateActionOutput {
97    pub locking_script: String,
98    pub satoshis: u64,
99    pub output_description: String,
100    #[serde(default)]
101    pub basket: Option<String>,
102    #[serde(default)]
103    pub custom_instructions: Option<String>,
104    #[serde(default)]
105    pub tags: Option<Vec<String>>,
106}
107
108#[derive(Deserialize)]
109#[serde(rename_all = "camelCase")]
110pub struct McCreateActionOptions {
111    #[serde(default)]
112    pub accept_delayed_broadcast: Option<bool>,
113    #[serde(default)]
114    pub randomize_outputs: Option<bool>,
115    #[serde(default)]
116    pub sign_and_process: Option<bool>,
117    #[serde(default)]
118    pub no_send: Option<bool>,
119    /// "known" => input source txs may omit validity proofs for TXIDs the wallet
120    /// already knows (needed when spending a self-created covenant output whose
121    /// inputBEEF is proof-incomplete).
122    #[serde(default)]
123    pub trust_self: Option<String>,
124}
125
126/// MetaNet Client response for createAction
127#[derive(Serialize)]
128#[serde(rename_all = "camelCase")]
129pub struct McCreateActionRes {
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub txid: Option<String>,
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub tx: Option<Vec<u8>>,
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub send_with_results: Option<serde_json::Value>,
136    /// For signAndProcess: false — contains the unsigned tx and reference for signAction/abortAction.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub signable_transaction: Option<McSignableTransaction>,
139    /// Change outpoints for noSend transactions.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub no_send_change: Option<serde_json::Value>,
142}
143
144/// signAction response, in the SAME wire shape as `McCreateActionRes`:
145/// `tx` is AtomicBEEF as a plain number array. The toolbox's own
146/// `SignActionResult` serde hex-encodes byte fields, which no BRC-100 client
147/// expects (MetaNet and the TS toolbox both send number arrays); passing that
148/// struct straight to `Json(...)` handed callers a hex STRING they then read
149/// as bytes and failed to parse — after the transaction had already broadcast.
150#[derive(Serialize)]
151#[serde(rename_all = "camelCase")]
152pub struct McSignActionRes {
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub txid: Option<String>,
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub tx: Option<Vec<u8>>,
157    #[serde(skip_serializing_if = "Option::is_none")]
158    pub send_with_results: Option<serde_json::Value>,
159}
160
161/// Unsigned transaction + reference for deferred signing flow.
162#[derive(Serialize)]
163#[serde(rename_all = "camelCase")]
164pub struct McSignableTransaction {
165    /// The unsigned transaction bytes (number array).
166    pub tx: Vec<u8>,
167    /// The reference string for signAction/abortAction.
168    /// NOTE: The SDK stores this as Vec<u8> (from String.into_bytes()) then hex-encodes it.
169    /// We reverse that: convert bytes back to the original String so signAction/abortAction
170    /// can look it up correctly in the wallet's pending transaction cache.
171    pub reference: String,
172}
173
174/// MetaNet Client request for internalizeAction
175#[derive(Deserialize)]
176#[serde(rename_all = "camelCase")]
177pub struct McInternalizeActionReq {
178    pub tx: Vec<u8>,
179    pub outputs: Vec<McInternalizeOutput>,
180    pub description: String,
181    #[serde(default)]
182    pub labels: Option<Vec<String>>,
183}
184
185#[derive(Deserialize)]
186#[serde(rename_all = "camelCase")]
187pub struct McInternalizeOutput {
188    pub output_index: u32,
189    pub protocol: String,
190    #[serde(default)]
191    pub payment_remittance: Option<McWalletPayment>,
192    #[serde(default)]
193    pub insertion_remittance: Option<McBasketInsertion>,
194}
195
196#[derive(Deserialize)]
197#[serde(rename_all = "camelCase")]
198pub struct McBasketInsertion {
199    pub basket: String,
200    #[serde(default)]
201    pub custom_instructions: Option<String>,
202    #[serde(default)]
203    pub tags: Option<Vec<String>>,
204}
205
206#[derive(Deserialize)]
207#[serde(rename_all = "camelCase")]
208pub struct McWalletPayment {
209    pub derivation_prefix: String,
210    pub derivation_suffix: String,
211    pub sender_identity_key: String,
212}
213
214/// MetaNet Client response for internalizeAction
215#[derive(Serialize)]
216pub struct McInternalizeActionRes {
217    pub accepted: bool,
218}
219
220// =============================================================================
221// Batch 3: Crypto request types (SDK args lack serde)
222// =============================================================================
223
224/// MetaNet Client request for verifySignature
225#[derive(Deserialize)]
226#[serde(rename_all = "camelCase")]
227pub struct McVerifySignatureReq {
228    #[serde(default)]
229    pub data: Option<Vec<u8>>,
230    pub signature: Vec<u8>,
231    #[serde(alias = "protocolID")]
232    pub protocol_id: serde_json::Value,
233    #[serde(alias = "keyID")]
234    pub key_id: String,
235    #[serde(default)]
236    pub counterparty: Option<String>,
237    #[serde(default)]
238    pub for_self: Option<bool>,
239}
240
241/// MetaNet Client request for encrypt
242#[derive(Deserialize)]
243#[serde(rename_all = "camelCase")]
244pub struct McEncryptReq {
245    pub plaintext: Vec<u8>,
246    #[serde(alias = "protocolID")]
247    pub protocol_id: serde_json::Value,
248    #[serde(alias = "keyID")]
249    pub key_id: String,
250    #[serde(default)]
251    pub counterparty: Option<String>,
252}
253
254/// MetaNet Client request for decrypt
255#[derive(Deserialize)]
256#[serde(rename_all = "camelCase")]
257pub struct McDecryptReq {
258    pub ciphertext: Vec<u8>,
259    #[serde(alias = "protocolID")]
260    pub protocol_id: serde_json::Value,
261    #[serde(alias = "keyID")]
262    pub key_id: String,
263    #[serde(default)]
264    pub counterparty: Option<String>,
265}
266
267/// MetaNet Client request for createHmac
268#[derive(Deserialize)]
269#[serde(rename_all = "camelCase")]
270pub struct McCreateHmacReq {
271    pub data: Vec<u8>,
272    #[serde(alias = "protocolID")]
273    pub protocol_id: serde_json::Value,
274    #[serde(alias = "keyID")]
275    pub key_id: String,
276    #[serde(default)]
277    pub counterparty: Option<String>,
278}
279
280/// MetaNet Client request for verifyHmac
281#[derive(Deserialize)]
282#[serde(rename_all = "camelCase")]
283pub struct McVerifyHmacReq {
284    pub data: Vec<u8>,
285    pub hmac: Vec<u8>,
286    #[serde(alias = "protocolID")]
287    pub protocol_id: serde_json::Value,
288    #[serde(alias = "keyID")]
289    pub key_id: String,
290    #[serde(default)]
291    pub counterparty: Option<String>,
292}
293
294// =============================================================================
295// Batch 6: Key linkage request types (SDK args lack serde)
296// =============================================================================
297
298/// MetaNet Client request for revealCounterpartyKeyLinkage
299#[derive(Deserialize)]
300#[serde(rename_all = "camelCase")]
301pub struct McRevealCounterpartyKeyLinkageReq {
302    pub counterparty: String,
303    pub verifier: String,
304    #[serde(default)]
305    pub privileged: Option<bool>,
306    #[serde(default)]
307    pub privileged_reason: Option<String>,
308}
309
310/// MetaNet Client request for revealSpecificKeyLinkage
311#[derive(Deserialize)]
312#[serde(rename_all = "camelCase")]
313pub struct McRevealSpecificKeyLinkageReq {
314    pub counterparty: String,
315    pub verifier: String,
316    #[serde(alias = "protocolID")]
317    pub protocol_id: serde_json::Value,
318    #[serde(alias = "keyID")]
319    pub key_id: String,
320    #[serde(default)]
321    pub privileged: Option<bool>,
322    #[serde(default)]
323    pub privileged_reason: Option<String>,
324}