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}
165
166#[derive(Deserialize)]
167#[serde(rename_all = "camelCase")]
168pub struct McInternalizeOutput {
169    pub output_index: u32,
170    pub protocol: String,
171    #[serde(default)]
172    pub payment_remittance: Option<McWalletPayment>,
173    #[serde(default)]
174    pub insertion_remittance: Option<McBasketInsertion>,
175}
176
177#[derive(Deserialize)]
178#[serde(rename_all = "camelCase")]
179pub struct McBasketInsertion {
180    pub basket: String,
181    #[serde(default)]
182    pub custom_instructions: Option<String>,
183    #[serde(default)]
184    pub tags: Option<Vec<String>>,
185}
186
187#[derive(Deserialize)]
188#[serde(rename_all = "camelCase")]
189pub struct McWalletPayment {
190    pub derivation_prefix: String,
191    pub derivation_suffix: String,
192    pub sender_identity_key: String,
193}
194
195/// MetaNet Client response for internalizeAction
196#[derive(Serialize)]
197pub struct McInternalizeActionRes {
198    pub accepted: bool,
199}
200
201// =============================================================================
202// Batch 3: Crypto request types (SDK args lack serde)
203// =============================================================================
204
205/// MetaNet Client request for verifySignature
206#[derive(Deserialize)]
207#[serde(rename_all = "camelCase")]
208pub struct McVerifySignatureReq {
209    #[serde(default)]
210    pub data: Option<Vec<u8>>,
211    pub signature: Vec<u8>,
212    #[serde(alias = "protocolID")]
213    pub protocol_id: serde_json::Value,
214    #[serde(alias = "keyID")]
215    pub key_id: String,
216    #[serde(default)]
217    pub counterparty: Option<String>,
218    #[serde(default)]
219    pub for_self: Option<bool>,
220}
221
222/// MetaNet Client request for encrypt
223#[derive(Deserialize)]
224#[serde(rename_all = "camelCase")]
225pub struct McEncryptReq {
226    pub plaintext: Vec<u8>,
227    #[serde(alias = "protocolID")]
228    pub protocol_id: serde_json::Value,
229    #[serde(alias = "keyID")]
230    pub key_id: String,
231    #[serde(default)]
232    pub counterparty: Option<String>,
233}
234
235/// MetaNet Client request for decrypt
236#[derive(Deserialize)]
237#[serde(rename_all = "camelCase")]
238pub struct McDecryptReq {
239    pub ciphertext: Vec<u8>,
240    #[serde(alias = "protocolID")]
241    pub protocol_id: serde_json::Value,
242    #[serde(alias = "keyID")]
243    pub key_id: String,
244    #[serde(default)]
245    pub counterparty: Option<String>,
246}
247
248/// MetaNet Client request for createHmac
249#[derive(Deserialize)]
250#[serde(rename_all = "camelCase")]
251pub struct McCreateHmacReq {
252    pub data: Vec<u8>,
253    #[serde(alias = "protocolID")]
254    pub protocol_id: serde_json::Value,
255    #[serde(alias = "keyID")]
256    pub key_id: String,
257    #[serde(default)]
258    pub counterparty: Option<String>,
259}
260
261/// MetaNet Client request for verifyHmac
262#[derive(Deserialize)]
263#[serde(rename_all = "camelCase")]
264pub struct McVerifyHmacReq {
265    pub data: Vec<u8>,
266    pub hmac: Vec<u8>,
267    #[serde(alias = "protocolID")]
268    pub protocol_id: serde_json::Value,
269    #[serde(alias = "keyID")]
270    pub key_id: String,
271    #[serde(default)]
272    pub counterparty: Option<String>,
273}
274
275// =============================================================================
276// Batch 6: Key linkage request types (SDK args lack serde)
277// =============================================================================
278
279/// MetaNet Client request for revealCounterpartyKeyLinkage
280#[derive(Deserialize)]
281#[serde(rename_all = "camelCase")]
282pub struct McRevealCounterpartyKeyLinkageReq {
283    pub counterparty: String,
284    pub verifier: String,
285    #[serde(default)]
286    pub privileged: Option<bool>,
287    #[serde(default)]
288    pub privileged_reason: Option<String>,
289}
290
291/// MetaNet Client request for revealSpecificKeyLinkage
292#[derive(Deserialize)]
293#[serde(rename_all = "camelCase")]
294pub struct McRevealSpecificKeyLinkageReq {
295    pub counterparty: String,
296    pub verifier: String,
297    #[serde(alias = "protocolID")]
298    pub protocol_id: serde_json::Value,
299    #[serde(alias = "keyID")]
300    pub key_id: String,
301    #[serde(default)]
302    pub privileged: Option<bool>,
303    #[serde(default)]
304    pub privileged_reason: Option<String>,
305}