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    /// R1 (d), the action's word at the door, beside `options` (the
74    /// toolbox's `CreateActionOptions` is the reference's shape and stays
75    /// as it is): the one value `"received"` offers a received coin whose
76    /// creator is not yet mined; absent or anything else is off.
77    #[serde(default)]
78    pub allow_pending: Option<serde_json::Value>,
79}
80
81/// A single caller-provided input for createAction.
82#[derive(Deserialize)]
83#[serde(rename_all = "camelCase")]
84pub struct McCreateActionInput {
85    /// "txid.vout"
86    pub outpoint: String,
87    /// Fully-provided unlocking script (hex). Use this OR unlocking_script_length.
88    #[serde(default)]
89    pub unlocking_script: Option<String>,
90    /// Length of a to-be-signed unlocking script (deferred-signing flow).
91    #[serde(default)]
92    pub unlocking_script_length: Option<u32>,
93    #[serde(default)]
94    pub input_description: Option<String>,
95    /// nSequence for this input (e.g. 0xfffffffe to make a covenant timeLock non-final).
96    #[serde(default)]
97    pub sequence_number: Option<u32>,
98}
99
100#[derive(Deserialize)]
101#[serde(rename_all = "camelCase")]
102pub struct McCreateActionOutput {
103    pub locking_script: String,
104    pub satoshis: u64,
105    pub output_description: String,
106    #[serde(default)]
107    pub basket: Option<String>,
108    #[serde(default)]
109    pub custom_instructions: Option<String>,
110    #[serde(default)]
111    pub tags: Option<Vec<String>>,
112}
113
114#[derive(Deserialize)]
115#[serde(rename_all = "camelCase")]
116pub struct McCreateActionOptions {
117    #[serde(default)]
118    pub accept_delayed_broadcast: Option<bool>,
119    #[serde(default)]
120    pub randomize_outputs: Option<bool>,
121    #[serde(default)]
122    pub sign_and_process: Option<bool>,
123    #[serde(default)]
124    pub no_send: Option<bool>,
125    /// "known" => input source txs may omit validity proofs for TXIDs the wallet
126    /// already knows (needed when spending a self-created covenant output whose
127    /// inputBEEF is proof-incomplete).
128    #[serde(default)]
129    pub trust_self: Option<String>,
130}
131
132/// MetaNet Client response for createAction
133#[derive(Serialize)]
134#[serde(rename_all = "camelCase")]
135pub struct McCreateActionRes {
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub txid: Option<String>,
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub tx: Option<Vec<u8>>,
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub send_with_results: Option<serde_json::Value>,
142    /// For signAndProcess: false — contains the unsigned tx and reference for signAction/abortAction.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub signable_transaction: Option<McSignableTransaction>,
145    /// Change outpoints for noSend transactions.
146    #[serde(skip_serializing_if = "Option::is_none")]
147    pub no_send_change: Option<serde_json::Value>,
148    /// The doors' word when the immediate post drew no accepting word
149    /// (`built`, the request's status, the toolbox's hint, the inputs
150    /// `locked`); absent when a broadcaster took it. See
151    /// [`crate::server::post_word`].
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub broadcast: Option<crate::server::post_word::PostWord>,
154}
155
156/// signAction response, in the SAME wire shape as `McCreateActionRes`:
157/// `tx` is AtomicBEEF as a plain number array. The toolbox's own
158/// `SignActionResult` serde hex-encodes byte fields, which no BRC-100 client
159/// expects (MetaNet and the TS toolbox both send number arrays); passing that
160/// struct straight to `Json(...)` handed callers a hex STRING they then read
161/// as bytes and failed to parse — after the transaction had already broadcast.
162#[derive(Serialize)]
163#[serde(rename_all = "camelCase")]
164pub struct McSignActionRes {
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub txid: Option<String>,
167    #[serde(skip_serializing_if = "Option::is_none")]
168    pub tx: Option<Vec<u8>>,
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub send_with_results: Option<serde_json::Value>,
171    /// The doors' word when the immediate post drew no accepting word
172    /// (`built`, the request's status, the toolbox's hint, the inputs
173    /// `locked`); absent when a broadcaster took it. See
174    /// [`crate::server::post_word`].
175    #[serde(skip_serializing_if = "Option::is_none")]
176    pub broadcast: Option<crate::server::post_word::PostWord>,
177}
178
179/// Unsigned transaction + reference for deferred signing flow.
180#[derive(Serialize)]
181#[serde(rename_all = "camelCase")]
182pub struct McSignableTransaction {
183    /// The unsigned transaction bytes (number array).
184    pub tx: Vec<u8>,
185    /// The reference string for signAction/abortAction.
186    /// NOTE: The SDK stores this as Vec<u8> (from String.into_bytes()) then hex-encodes it.
187    /// We reverse that: convert bytes back to the original String so signAction/abortAction
188    /// can look it up correctly in the wallet's pending transaction cache.
189    pub reference: String,
190}
191
192/// MetaNet Client request for internalizeAction
193#[derive(Deserialize)]
194#[serde(rename_all = "camelCase")]
195pub struct McInternalizeActionReq {
196    pub tx: Vec<u8>,
197    pub outputs: Vec<McInternalizeOutput>,
198    pub description: String,
199    #[serde(default)]
200    pub labels: Option<Vec<String>>,
201}
202
203#[derive(Deserialize)]
204#[serde(rename_all = "camelCase")]
205pub struct McInternalizeOutput {
206    pub output_index: u32,
207    pub protocol: String,
208    #[serde(default)]
209    pub payment_remittance: Option<McWalletPayment>,
210    #[serde(default)]
211    pub insertion_remittance: Option<McBasketInsertion>,
212}
213
214#[derive(Deserialize)]
215#[serde(rename_all = "camelCase")]
216pub struct McBasketInsertion {
217    pub basket: String,
218    #[serde(default)]
219    pub custom_instructions: Option<String>,
220    #[serde(default)]
221    pub tags: Option<Vec<String>>,
222}
223
224#[derive(Deserialize)]
225#[serde(rename_all = "camelCase")]
226pub struct McWalletPayment {
227    pub derivation_prefix: String,
228    pub derivation_suffix: String,
229    pub sender_identity_key: String,
230}
231
232/// MetaNet Client response for internalizeAction
233#[derive(Serialize)]
234pub struct McInternalizeActionRes {
235    pub accepted: bool,
236    /// The doors' word when the immediate post drew no accepting word
237    /// (`built`, the request's status, the toolbox's hint, the inputs
238    /// `locked`); absent when a broadcaster took it. See
239    /// [`crate::server::post_word`].
240    #[serde(skip_serializing_if = "Option::is_none")]
241    pub broadcast: Option<crate::server::post_word::PostWord>,
242}
243
244// =============================================================================
245// Batch 3: Crypto request types (SDK args lack serde)
246// =============================================================================
247
248/// MetaNet Client request for verifySignature
249#[derive(Deserialize)]
250#[serde(rename_all = "camelCase")]
251pub struct McVerifySignatureReq {
252    #[serde(default)]
253    pub data: Option<Vec<u8>>,
254    pub signature: Vec<u8>,
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 counterparty: Option<String>,
261    #[serde(default)]
262    pub for_self: Option<bool>,
263}
264
265/// MetaNet Client request for encrypt
266#[derive(Deserialize)]
267#[serde(rename_all = "camelCase")]
268pub struct McEncryptReq {
269    pub plaintext: Vec<u8>,
270    #[serde(alias = "protocolID")]
271    pub protocol_id: serde_json::Value,
272    #[serde(alias = "keyID")]
273    pub key_id: String,
274    #[serde(default)]
275    pub counterparty: Option<String>,
276}
277
278/// MetaNet Client request for decrypt
279#[derive(Deserialize)]
280#[serde(rename_all = "camelCase")]
281pub struct McDecryptReq {
282    pub ciphertext: Vec<u8>,
283    #[serde(alias = "protocolID")]
284    pub protocol_id: serde_json::Value,
285    #[serde(alias = "keyID")]
286    pub key_id: String,
287    #[serde(default)]
288    pub counterparty: Option<String>,
289}
290
291/// MetaNet Client request for createHmac
292#[derive(Deserialize)]
293#[serde(rename_all = "camelCase")]
294pub struct McCreateHmacReq {
295    pub data: Vec<u8>,
296    #[serde(alias = "protocolID")]
297    pub protocol_id: serde_json::Value,
298    #[serde(alias = "keyID")]
299    pub key_id: String,
300    #[serde(default)]
301    pub counterparty: Option<String>,
302}
303
304/// MetaNet Client request for verifyHmac
305#[derive(Deserialize)]
306#[serde(rename_all = "camelCase")]
307pub struct McVerifyHmacReq {
308    pub data: Vec<u8>,
309    pub hmac: Vec<u8>,
310    #[serde(alias = "protocolID")]
311    pub protocol_id: serde_json::Value,
312    #[serde(alias = "keyID")]
313    pub key_id: String,
314    #[serde(default)]
315    pub counterparty: Option<String>,
316}
317
318// =============================================================================
319// Batch 6: Key linkage request types (SDK args lack serde)
320// =============================================================================
321
322/// MetaNet Client request for revealCounterpartyKeyLinkage
323#[derive(Deserialize)]
324#[serde(rename_all = "camelCase")]
325pub struct McRevealCounterpartyKeyLinkageReq {
326    pub counterparty: String,
327    pub verifier: String,
328    #[serde(default)]
329    pub privileged: Option<bool>,
330    #[serde(default)]
331    pub privileged_reason: Option<String>,
332}
333
334/// MetaNet Client request for revealSpecificKeyLinkage
335#[derive(Deserialize)]
336#[serde(rename_all = "camelCase")]
337pub struct McRevealSpecificKeyLinkageReq {
338    pub counterparty: String,
339    pub verifier: String,
340    #[serde(alias = "protocolID")]
341    pub protocol_id: serde_json::Value,
342    #[serde(alias = "keyID")]
343    pub key_id: String,
344    #[serde(default)]
345    pub privileged: Option<bool>,
346    #[serde(default)]
347    pub privileged_reason: Option<String>,
348}