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/// Unsigned transaction + reference for deferred signing flow.
145#[derive(Serialize)]
146#[serde(rename_all = "camelCase")]
147pub struct McSignableTransaction {
148    /// The unsigned transaction bytes (number array).
149    pub tx: Vec<u8>,
150    /// The reference string for signAction/abortAction.
151    /// NOTE: The SDK stores this as Vec<u8> (from String.into_bytes()) then hex-encodes it.
152    /// We reverse that: convert bytes back to the original String so signAction/abortAction
153    /// can look it up correctly in the wallet's pending transaction cache.
154    pub reference: String,
155}
156
157/// MetaNet Client request for internalizeAction
158#[derive(Deserialize)]
159#[serde(rename_all = "camelCase")]
160pub struct McInternalizeActionReq {
161    pub tx: Vec<u8>,
162    pub outputs: Vec<McInternalizeOutput>,
163    pub description: String,
164    #[serde(default)]
165    pub labels: Option<Vec<String>>,
166}
167
168#[derive(Deserialize)]
169#[serde(rename_all = "camelCase")]
170pub struct McInternalizeOutput {
171    pub output_index: u32,
172    pub protocol: String,
173    #[serde(default)]
174    pub payment_remittance: Option<McWalletPayment>,
175    #[serde(default)]
176    pub insertion_remittance: Option<McBasketInsertion>,
177}
178
179#[derive(Deserialize)]
180#[serde(rename_all = "camelCase")]
181pub struct McBasketInsertion {
182    pub basket: String,
183    #[serde(default)]
184    pub custom_instructions: Option<String>,
185    #[serde(default)]
186    pub tags: Option<Vec<String>>,
187}
188
189#[derive(Deserialize)]
190#[serde(rename_all = "camelCase")]
191pub struct McWalletPayment {
192    pub derivation_prefix: String,
193    pub derivation_suffix: String,
194    pub sender_identity_key: String,
195}
196
197/// MetaNet Client response for internalizeAction
198#[derive(Serialize)]
199pub struct McInternalizeActionRes {
200    pub accepted: bool,
201}
202
203// =============================================================================
204// Batch 3: Crypto request types (SDK args lack serde)
205// =============================================================================
206
207/// MetaNet Client request for verifySignature
208#[derive(Deserialize)]
209#[serde(rename_all = "camelCase")]
210pub struct McVerifySignatureReq {
211    #[serde(default)]
212    pub data: Option<Vec<u8>>,
213    pub signature: Vec<u8>,
214    #[serde(alias = "protocolID")]
215    pub protocol_id: serde_json::Value,
216    #[serde(alias = "keyID")]
217    pub key_id: String,
218    #[serde(default)]
219    pub counterparty: Option<String>,
220    #[serde(default)]
221    pub for_self: Option<bool>,
222}
223
224/// MetaNet Client request for encrypt
225#[derive(Deserialize)]
226#[serde(rename_all = "camelCase")]
227pub struct McEncryptReq {
228    pub plaintext: Vec<u8>,
229    #[serde(alias = "protocolID")]
230    pub protocol_id: serde_json::Value,
231    #[serde(alias = "keyID")]
232    pub key_id: String,
233    #[serde(default)]
234    pub counterparty: Option<String>,
235}
236
237/// MetaNet Client request for decrypt
238#[derive(Deserialize)]
239#[serde(rename_all = "camelCase")]
240pub struct McDecryptReq {
241    pub ciphertext: Vec<u8>,
242    #[serde(alias = "protocolID")]
243    pub protocol_id: serde_json::Value,
244    #[serde(alias = "keyID")]
245    pub key_id: String,
246    #[serde(default)]
247    pub counterparty: Option<String>,
248}
249
250/// MetaNet Client request for createHmac
251#[derive(Deserialize)]
252#[serde(rename_all = "camelCase")]
253pub struct McCreateHmacReq {
254    pub data: 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}
262
263/// MetaNet Client request for verifyHmac
264#[derive(Deserialize)]
265#[serde(rename_all = "camelCase")]
266pub struct McVerifyHmacReq {
267    pub data: Vec<u8>,
268    pub hmac: Vec<u8>,
269    #[serde(alias = "protocolID")]
270    pub protocol_id: serde_json::Value,
271    #[serde(alias = "keyID")]
272    pub key_id: String,
273    #[serde(default)]
274    pub counterparty: Option<String>,
275}
276
277// =============================================================================
278// Batch 6: Key linkage request types (SDK args lack serde)
279// =============================================================================
280
281/// MetaNet Client request for revealCounterpartyKeyLinkage
282#[derive(Deserialize)]
283#[serde(rename_all = "camelCase")]
284pub struct McRevealCounterpartyKeyLinkageReq {
285    pub counterparty: String,
286    pub verifier: String,
287    #[serde(default)]
288    pub privileged: Option<bool>,
289    #[serde(default)]
290    pub privileged_reason: Option<String>,
291}
292
293/// MetaNet Client request for revealSpecificKeyLinkage
294#[derive(Deserialize)]
295#[serde(rename_all = "camelCase")]
296pub struct McRevealSpecificKeyLinkageReq {
297    pub counterparty: String,
298    pub verifier: String,
299    #[serde(alias = "protocolID")]
300    pub protocol_id: serde_json::Value,
301    #[serde(alias = "keyID")]
302    pub key_id: String,
303    #[serde(default)]
304    pub privileged: Option<bool>,
305    #[serde(default)]
306    pub privileged_reason: Option<String>,
307}