1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! WalletWire binary protocol for efficient wallet communication.
//!
//! This module implements the WalletWire protocol, which provides efficient binary
//! serialization for wallet operations. The protocol is designed to be binary-compatible
//! with the TypeScript and Go BSV SDK implementations.
//!
//! # Architecture
//!
//! The protocol uses a client-server model:
//!
//! - **[`WalletWireTransceiver`]** (client): Serializes method calls into binary messages
//! and deserializes responses. Implements the wallet interface trait.
//!
//! - **[`WalletWire`]** (transport): Abstract trait for binary message transmission.
//! Can be implemented over HTTP, WebSocket, IPC, etc.
//!
//! - **[`WalletWireProcessor`]** (server): Deserializes incoming messages and dispatches
//! to the appropriate wallet method. Returns serialized responses.
//!
//! # Wire Format
//!
//! ## Request Frame
//!
//! ```text
//! ┌─────────┬──────────────┬────────────┬────────────────┐
//! │ Call │ Originator │ Originator │ Serialized │
//! │ Code │ Length │ String │ Parameters │
//! │ (1 byte)│ (1 byte) │ (N bytes) │ (variable) │
//! └─────────┴──────────────┴────────────┴────────────────┘
//! ```
//!
//! ## Response Frame
//!
//! ```text
//! ┌─────────┬────────────────────────────────────────────┐
//! │ Error │ Result Data (if success) or Error Message │
//! │ (1 byte)│ (variable length) │
//! └─────────┴────────────────────────────────────────────┘
//! ```
//!
//! # Serialization Rules
//!
//! | Type | Encoding |
//! |------|----------|
//! | Strings | VarInt length + UTF-8 bytes |
//! | Optional values | -1 (signed VarInt) for null/undefined |
//! | Booleans | Int8 (1 = true, 0 = false, -1 = undefined) |
//! | Binary data | VarInt length + raw bytes |
//! | Outpoints | 32-byte TXID + VarInt index |
//! | Public keys | 33 bytes (compressed) |
//! | Counterparty | 0 = undefined, 11 = 'self', 12 = 'anyone', else 33-byte pubkey |
//!
//! # Example
//!
//! ```rust,ignore
//! use bsv_rs::wallet::wire::{WalletWire, WalletWireTransceiver};
//!
//! // Implement transport
//! struct HttpWire { /* ... */ }
//!
//! impl WalletWire for HttpWire {
//! async fn transmit_to_wallet(&self, message: &[u8]) -> Result<Vec<u8>, Error> {
//! // Send message over HTTP and return response
//! }
//! }
//!
//! // Create transceiver
//! let wire = HttpWire::new("https://wallet.example.com");
//! let wallet = WalletWireTransceiver::new(wire);
//!
//! // Use wallet methods
//! let result = wallet.get_public_key(args, "originator").await?;
//! ```
pub use WalletCall;
pub use ;
pub use WalletWireProcessor;
pub use WalletWireTransceiver;
use crateError;
/// Transport abstraction for wallet wire protocol.
///
/// Implementations of this trait handle the actual transmission of binary
/// messages to and from the wallet. This could be HTTP, WebSocket, IPC,
/// or any other transport mechanism.
///
/// # Example
///
/// ```rust,ignore
/// use bsv_rs::wallet::wire::WalletWire;
///
/// struct WebSocketWire {
/// url: String,
/// }
///
/// #[async_trait::async_trait]
/// impl WalletWire for WebSocketWire {
/// async fn transmit_to_wallet(&self, message: &[u8]) -> Result<Vec<u8>, Error> {
/// // Send over WebSocket and receive response
/// }
/// }
/// ```
/// Counterparty wire encoding constants.
/// Action status wire encoding.