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
use async_trait;
use Deserialize;
use Serialize;
use TypedBuilder;
use crateWallet;
use crateWalletAccountInfo;
use crateWalletResult;
/// Feature identifier for the standard connect feature.
///
/// This constant is used to identify the connect feature in the wallet's
/// feature list.
pub const STANDARD_CONNECT: &str = "standard:connect";
/// Output of a successful wallet connection.
///
/// This trait defines the structure of the data returned when a wallet
/// connection is established. It provides access to the accounts that the app
/// has been authorized to use.
///
/// # Example Implementation
///
/// ```rust,ignore
/// struct MyConnectOutput {
/// accounts: Vec<MyAccount>,
/// }
///
/// impl StandardConnectOutput for MyConnectOutput {
/// type Account = MyAccount;
///
/// fn accounts(&self) -> Vec<Self::Account> {
/// self.accounts.clone()
/// }
/// }
/// ```
/// Input options for connecting to a wallet.
///
/// This struct provides configuration options for the wallet connection
/// process. It allows apps to specify whether the connection should be silent
/// (without user prompts) or interactive.
///
/// # Example
///
/// ```rust
/// use wallet_standard::StandardConnectInput;
///
/// // Create a silent connection request
/// let silent_connect = StandardConnectInput::builder().silent(true).build();
///
/// // Create a default connection request (interactive)
/// let default_connect = StandardConnectInput::default();
/// ```
/// Trait for wallets that support connecting to authorize accounts.
///
/// This trait defines methods for connecting to a wallet and authorizing
/// accounts for use by the app. It provides both a simple connect method and a
/// method that accepts connection options.
///
/// # Example Implementation
///
/// ```rust,ignore
/// #[async_trait(?Send)]
/// impl WalletStandardConnect for MyWallet {
/// async fn connect(&mut self) -> WalletResult<Vec<Self::Account>> {
/// // Prompt the user to select accounts
/// let selected_accounts = prompt_user_for_accounts();
///
/// // Update the wallet's state
/// self.current_account = selected_accounts.first().cloned();
///
/// Ok(selected_accounts)
/// }
///
/// async fn connect_with_options(
/// &mut self,
/// options: StandardConnectInput,
/// ) -> WalletResult<Vec<Self::Account>> {
/// if options.silent.unwrap_or(false) {
/// // Return previously authorized accounts without prompting
/// Ok(self.authorized_accounts.clone())
/// } else {
/// // Prompt the user
/// self.connect().await
/// }
/// }
/// }
/// ```