rust_libindy_wrapper/
wallet.rs

1use {ErrorCode, IndyHandle};
2
3use std::ffi::CString;
4use std::ptr::null;
5use std::time::Duration;
6
7use utils::callbacks::ClosureHandler;
8use utils::results::ResultHandler;
9
10use native::{wallet, non_secrets};
11use native::{ResponseEmptyCB,
12          ResponseStringCB,
13          ResponseI32CB};
14
15pub struct Wallet {}
16
17impl Wallet {
18    /// Registers custom wallet implementation.
19    ///
20    /// It allows library user to provide custom wallet implementation.
21    ///
22    /// # Arguments
23    /// * `command_handle` - Command handle to map callback to caller context.
24    /// * `xtype` - Wallet type name.
25    /// * `create` - WalletType create operation handler
26    /// * `open` - WalletType open operation handler
27    /// * `set` - Wallet set operation handler
28    /// * `get` - Wallet get operation handler
29    /// * `get_not_expired` - Wallet get_not_expired operation handler
30    /// * `list` - Wallet list operation handler(must to return data in the following format: {"values":[{"key":"", "value":""}, {"key":"", "value":""}]}
31    /// * `close` - Wallet close operation handler
32    /// * `delete` - WalletType delete operation handler
33    /// * `free` - Handler that allows to de-allocate strings allocated in caller code
34    pub fn register_storage(xtype: &str,
35                            create: Option<wallet::WalletCreate>,
36                            open: Option<wallet::WalletOpen>,
37                            close: Option<wallet::WalletClose>,
38                            delete: Option<wallet::WalletDelete>,
39                            add_record: Option<wallet::WalletAddRecord>,
40                            update_record_value: Option<wallet::WalletUpdateRecordValue>,
41                            update_record_tags: Option<wallet::WalletUpdateRecordTags>,
42                            add_record_tags: Option<wallet::WalletAddRecordTags>,
43                            delete_record_tags: Option<wallet::WalletDeleteRecordTags>,
44                            delete_record: Option<wallet::WalletDeleteRecord>,
45                            get_record: Option<wallet::WalletGetRecord>,
46                            get_record_id: Option<wallet::WalletGetRecordId>,
47                            get_record_type: Option<wallet::WalletGetRecordType>,
48                            get_record_value: Option<wallet::WalletGetRecordValue>,
49                            get_record_tags: Option<wallet::WalletGetRecordTags>,
50                            free_record: Option<wallet::WalletFreeRecord>,
51                            get_storage_metadata: Option<wallet::WalletGetStorageMetadata>,
52                            set_storage_metadata: Option<wallet::WalletSetStorageMetadata>,
53                            free_storage_metadata: Option<wallet::WalletFreeStorageMetadata>,
54                            search_records: Option<wallet::WalletSearchRecords>,
55                            search_all_records: Option<wallet::WalletSearchAllRecords>,
56                            get_search_total_count: Option<wallet::WalletGetSearchTotalCount>,
57                            fetch_search_next_record: Option<wallet::WalletFetchSearchNextRecord>,
58                            free_search: Option<wallet::WalletFreeSearch>) -> Result<(), ErrorCode> {
59        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
60
61        let err = Wallet::_register_storage(command_handle,
62                                            xtype,
63                                            create,
64                                            open,
65                                            close,
66                                            delete,
67                                            add_record,
68                                            update_record_value,
69                                            update_record_tags,
70                                            add_record_tags,
71                                            delete_record_tags,
72                                            delete_record,
73                                            get_record,
74                                            get_record_id,
75                                            get_record_type,
76                                            get_record_value,
77                                            get_record_tags,
78                                            free_record,
79                                            get_storage_metadata,
80                                            set_storage_metadata,
81                                            free_storage_metadata,
82                                            search_records,
83                                            search_all_records,
84                                            get_search_total_count,
85                                            fetch_search_next_record,
86                                            free_search,
87                                            cb);
88
89        ResultHandler::empty(err, receiver)
90    }
91
92    /// Registers custom wallet implementation.
93    ///
94    /// It allows library user to provide custom wallet implementation.
95    ///
96    /// # Arguments
97    /// * `command_handle` - Command handle to map callback to caller context.
98    /// * `xtype` - Wallet type name.
99    /// * `create` - WalletType create operation handler
100    /// * `open` - WalletType open operation handler
101    /// * `set` - Wallet set operation handler
102    /// * `get` - Wallet get operation handler
103    /// * `get_not_expired` - Wallet get_not_expired operation handler
104    /// * `list` - Wallet list operation handler(must to return data in the following format: {"values":[{"key":"", "value":""}, {"key":"", "value":""}]}
105    /// * `close` - Wallet close operation handler
106    /// * `delete` - WalletType delete operation handler
107    /// * `free` - Handler that allows to de-allocate strings allocated in caller code
108    /// * `timeout` - the maximum time this function waits for a response
109    pub fn register_storage_timeout(xtype: &str,
110                                    create: Option<wallet::WalletCreate>,
111                                    open: Option<wallet::WalletOpen>,
112                                    close: Option<wallet::WalletClose>,
113                                    delete: Option<wallet::WalletDelete>,
114                                    add_record: Option<wallet::WalletAddRecord>,
115                                    update_record_value: Option<wallet::WalletUpdateRecordValue>,
116                                    update_record_tags: Option<wallet::WalletUpdateRecordTags>,
117                                    add_record_tags: Option<wallet::WalletAddRecordTags>,
118                                    delete_record_tags: Option<wallet::WalletDeleteRecordTags>,
119                                    delete_record: Option<wallet::WalletDeleteRecord>,
120                                    get_record: Option<wallet::WalletGetRecord>,
121                                    get_record_id: Option<wallet::WalletGetRecordId>,
122                                    get_record_type: Option<wallet::WalletGetRecordType>,
123                                    get_record_value: Option<wallet::WalletGetRecordValue>,
124                                    get_record_tags: Option<wallet::WalletGetRecordTags>,
125                                    free_record: Option<wallet::WalletFreeRecord>,
126                                    get_storage_metadata: Option<wallet::WalletGetStorageMetadata>,
127                                    set_storage_metadata: Option<wallet::WalletSetStorageMetadata>,
128                                    free_storage_metadata: Option<wallet::WalletFreeStorageMetadata>,
129                                    search_records: Option<wallet::WalletSearchRecords>,
130                                    search_all_records: Option<wallet::WalletSearchAllRecords>,
131                                    get_search_total_count: Option<wallet::WalletGetSearchTotalCount>,
132                                    fetch_search_next_record: Option<wallet::WalletFetchSearchNextRecord>,
133                                    free_search: Option<wallet::WalletFreeSearch>,
134                                    timeout: Duration) -> Result<(), ErrorCode> {
135        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
136
137        let err = Wallet::_register_storage(command_handle,
138                                            xtype,
139                                            create,
140                                            open,
141                                            close,
142                                            delete,
143                                            add_record,
144                                            update_record_value,
145                                            update_record_tags,
146                                            add_record_tags,
147                                            delete_record_tags,
148                                            delete_record,
149                                            get_record,
150                                            get_record_id,
151                                            get_record_type,
152                                            get_record_value,
153                                            get_record_tags,
154                                            free_record,
155                                            get_storage_metadata,
156                                            set_storage_metadata,
157                                            free_storage_metadata,
158                                            search_records,
159                                            search_all_records,
160                                            get_search_total_count,
161                                            fetch_search_next_record,
162                                            free_search,
163                                            cb);
164
165        ResultHandler::empty_timeout(err, receiver, timeout)
166    }
167
168    /// Registers custom wallet implementation.
169    ///
170    /// It allows library user to provide custom wallet implementation.
171    ///
172    /// # Arguments
173    /// * `command_handle` - Command handle to map callback to caller context.
174    /// * `xtype` - Wallet type name.
175    /// * `create` - WalletType create operation handler
176    /// * `open` - WalletType open operation handler
177    /// * `set` - Wallet set operation handler
178    /// * `get` - Wallet get operation handler
179    /// * `get_not_expired` - Wallet get_not_expired operation handler
180    /// * `list` - Wallet list operation handler(must to return data in the following format: {"values":[{"key":"", "value":""}, {"key":"", "value":""}]}
181    /// * `close` - Wallet close operation handler
182    /// * `delete` - WalletType delete operation handler
183    /// * `free` - Handler that allows to de-allocate strings allocated in caller code
184    /// * `closure` - the closure that is called when finished
185    ///
186    /// # Returns
187    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
188    pub fn register_storage_async<F: 'static>(xtype: &str,
189                                              create: Option<wallet::WalletCreate>,
190                                              open: Option<wallet::WalletOpen>,
191                                              close: Option<wallet::WalletClose>,
192                                              delete: Option<wallet::WalletDelete>,
193                                              add_record: Option<wallet::WalletAddRecord>,
194                                              update_record_value: Option<wallet::WalletUpdateRecordValue>,
195                                              update_record_tags: Option<wallet::WalletUpdateRecordTags>,
196                                              add_record_tags: Option<wallet::WalletAddRecordTags>,
197                                              delete_record_tags: Option<wallet::WalletDeleteRecordTags>,
198                                              delete_record: Option<wallet::WalletDeleteRecord>,
199                                              get_record: Option<wallet::WalletGetRecord>,
200                                              get_record_id: Option<wallet::WalletGetRecordId>,
201                                              get_record_type: Option<wallet::WalletGetRecordType>,
202                                              get_record_value: Option<wallet::WalletGetRecordValue>,
203                                              get_record_tags: Option<wallet::WalletGetRecordTags>,
204                                              free_record: Option<wallet::WalletFreeRecord>,
205                                              get_storage_metadata: Option<wallet::WalletGetStorageMetadata>,
206                                              set_storage_metadata: Option<wallet::WalletSetStorageMetadata>,
207                                              free_storage_metadata: Option<wallet::WalletFreeStorageMetadata>,
208                                              search_records: Option<wallet::WalletSearchRecords>,
209                                              search_all_records: Option<wallet::WalletSearchAllRecords>,
210                                              get_search_total_count: Option<wallet::WalletGetSearchTotalCount>,
211                                              fetch_search_next_record: Option<wallet::WalletFetchSearchNextRecord>,
212                                              free_search: Option<wallet::WalletFreeSearch>,
213                                              closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
214        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
215
216        Wallet::_register_storage(command_handle,
217                                  xtype,
218                                  create,
219                                  open,
220                                  close,
221                                  delete,
222                                  add_record,
223                                  update_record_value,
224                                  update_record_tags,
225                                  add_record_tags,
226                                  delete_record_tags,
227                                  delete_record,
228                                  get_record,
229                                  get_record_id,
230                                  get_record_type,
231                                  get_record_value,
232                                  get_record_tags,
233                                  free_record,
234                                  get_storage_metadata,
235                                  set_storage_metadata,
236                                  free_storage_metadata,
237                                  search_records,
238                                  search_all_records,
239                                  get_search_total_count,
240                                  fetch_search_next_record,
241                                  free_search,
242                                  cb)
243    }
244
245    fn _register_storage(command_handle: IndyHandle,
246                         xtype: &str,
247                         create: Option<wallet::WalletCreate>,
248                         open: Option<wallet::WalletOpen>,
249                         close: Option<wallet::WalletClose>,
250                         delete: Option<wallet::WalletDelete>,
251                         add_record: Option<wallet::WalletAddRecord>,
252                         update_record_value: Option<wallet::WalletUpdateRecordValue>,
253                         update_record_tags: Option<wallet::WalletUpdateRecordTags>,
254                         add_record_tags: Option<wallet::WalletAddRecordTags>,
255                         delete_record_tags: Option<wallet::WalletDeleteRecordTags>,
256                         delete_record: Option<wallet::WalletDeleteRecord>,
257                         get_record: Option<wallet::WalletGetRecord>,
258                         get_record_id: Option<wallet::WalletGetRecordId>,
259                         get_record_type: Option<wallet::WalletGetRecordType>,
260                         get_record_value: Option<wallet::WalletGetRecordValue>,
261                         get_record_tags: Option<wallet::WalletGetRecordTags>,
262                         free_record: Option<wallet::WalletFreeRecord>,
263                         get_storage_metadata: Option<wallet::WalletGetStorageMetadata>,
264                         set_storage_metadata: Option<wallet::WalletSetStorageMetadata>,
265                         free_storage_metadata: Option<wallet::WalletFreeStorageMetadata>,
266                         search_records: Option<wallet::WalletSearchRecords>,
267                         search_all_records: Option<wallet::WalletSearchAllRecords>,
268                         get_search_total_count: Option<wallet::WalletGetSearchTotalCount>,
269                         fetch_search_next_record: Option<wallet::WalletFetchSearchNextRecord>,
270                         free_search: Option<wallet::WalletFreeSearch>,
271                         cb: Option<ResponseEmptyCB>) -> ErrorCode {
272        let xtype = c_str!(xtype);
273
274        ErrorCode::from(unsafe {
275          wallet::indy_register_wallet_storage(command_handle,
276                                               xtype.as_ptr(),
277                                               create,
278                                               open,
279                                               close,
280                                               delete,
281                                               add_record,
282                                               update_record_value,
283                                               update_record_tags,
284                                               add_record_tags,
285                                               delete_record_tags,
286                                               delete_record,
287                                               get_record,
288                                               get_record_id,
289                                               get_record_type,
290                                               get_record_value,
291                                               get_record_tags,
292                                               free_record,
293                                               get_storage_metadata,
294                                               set_storage_metadata,
295                                               free_storage_metadata,
296                                               search_records,
297                                               search_all_records,
298                                               get_search_total_count,
299                                               fetch_search_next_record,
300                                               free_search,
301                                               cb)
302        })
303    }
304
305    /// Creates a new secure wallet with the given unique name.
306    ///
307    /// # Arguments
308    /// * `config` - Wallet configuration json. List of supported keys are defined by wallet type.
309    ///                    if NULL, then default config will be used.
310    /// * `credentials` - Wallet credentials json. List of supported keys are defined by wallet type.
311    ///                    if NULL, then default config will be used.
312    pub fn create(config: &str, credentials: &str) -> Result<(), ErrorCode> {
313        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
314
315        let err = Wallet::_create(command_handle, config, credentials, cb);
316
317        ResultHandler::empty(err, receiver)
318    }
319
320    /// Creates a new secure wallet with the given unique name.
321    ///
322    /// # Arguments
323    /// * `config` - Wallet configuration json. List of supported keys are defined by wallet type.
324    ///                    if NULL, then default config will be used.
325    /// * `credentials` - Wallet credentials json. List of supported keys are defined by wallet type.
326    ///                    if NULL, then default config will be used.
327    /// * `timeout` - the maximum time this function waits for a response
328    pub fn create_timeout(config: &str, credentials: &str, timeout: Duration) -> Result<(), ErrorCode> {
329        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
330
331        let err = Wallet::_create(command_handle, config, credentials, cb);
332
333        ResultHandler::empty_timeout(err, receiver, timeout)
334    }
335
336    /// Creates a new secure wallet with the given unique name.
337    ///
338    /// # Arguments
339    /// * `config` - Wallet configuration json. List of supported keys are defined by wallet type.
340    ///                    if NULL, then default config will be used.
341    /// * `credentials` - Wallet credentials json. List of supported keys are defined by wallet type.
342    ///                    if NULL, then default config will be used.
343    /// * `closure` - the closure that is called when finished
344    ///
345    /// # Returns
346    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
347    pub fn create_async<F: 'static>(config: &str, credentials: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
348        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
349
350        Wallet::_create(command_handle, config, credentials, cb)
351    }
352
353    fn _create(command_handle: IndyHandle, config: &str, credentials: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
354        let config = c_str!(config);
355        let credentials = c_str!(credentials);
356
357        ErrorCode::from(unsafe {
358          wallet::indy_create_wallet(command_handle, config.as_ptr(), credentials.as_ptr(), cb)
359        })
360    }
361
362    /// Opens the wallet with specific name.
363    ///
364    /// Wallet with corresponded name must be previously created with indy_create_wallet method.
365    /// It is impossible to open wallet with the same name more than once.
366    ///
367    /// # Arguments
368    /// * `runtime_config`  (optional)- Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example:
369    /// {
370    ///     "freshness_time": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60.
371    ///     ... List of additional supported keys are defined by wallet type.
372    /// }
373    /// * `credentials` (optional) - Wallet credentials json. List of supported keys are defined by wallet type.
374    ///                    if NULL, then default credentials will be used.
375    ///
376    /// # Returns
377    /// Handle to opened wallet to use in methods that require wallet access.
378    pub fn open(config: &str, credentials: &str) -> Result<i32, ErrorCode> {
379        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
380
381        let err = Wallet::_open(command_handle, config, credentials, cb);
382
383        ResultHandler::one(err, receiver)
384    }
385
386    /// Opens the wallet with specific name.
387    ///
388    /// Wallet with corresponded name must be previously created with indy_create_wallet method.
389    /// It is impossible to open wallet with the same name more than once.
390    ///
391    /// # Arguments
392    /// * `runtime_config`  (optional)- Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example:
393    /// {
394    ///     "freshness_time": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60.
395    ///     ... List of additional supported keys are defined by wallet type.
396    /// }
397    /// * `credentials` (optional) - Wallet credentials json. List of supported keys are defined by wallet type.
398    ///                    if NULL, then default credentials will be used.
399    /// * `timeout` - the maximum time this function waits for a response
400    ///
401    /// # Returns
402    /// Handle to opened wallet to use in methods that require wallet access.
403    pub fn open_timeout(config: &str, credentials: &str, timeout: Duration) -> Result<i32, ErrorCode> {
404        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
405
406        let err = Wallet::_open(command_handle, config, credentials, cb);
407
408        ResultHandler::one_timeout(err, receiver, timeout)
409    }
410
411    /// Opens the wallet with specific name.
412    ///
413    /// Wallet with corresponded name must be previously created with indy_create_wallet method.
414    /// It is impossible to open wallet with the same name more than once.
415    ///
416    /// # Arguments
417    /// * `runtime_config`  (optional)- Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example:
418    /// {
419    ///     "freshness_time": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60.
420    ///     ... List of additional supported keys are defined by wallet type.
421    /// }
422    /// * `credentials` (optional) - Wallet credentials json. List of supported keys are defined by wallet type.
423    ///                    if NULL, then default credentials will be used.
424    /// * `closure` - the closure that is called when finished
425    ///
426    /// # Returns
427    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
428    pub fn open_async<F: 'static>(config: &str, credentials: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, i32) + Send {
429        let (command_handle, cb) = ClosureHandler::convert_cb_ec_i32(Box::new(closure));
430
431        Wallet::_open(command_handle, config, credentials, cb)
432    }
433
434    fn _open(command_handle: IndyHandle, config: &str, credentials: &str, cb: Option<ResponseI32CB>) -> ErrorCode {
435        let config = c_str!(config);
436        let credentials = c_str!(credentials);
437
438        ErrorCode::from(unsafe {
439          wallet::indy_open_wallet(command_handle, config.as_ptr(), credentials.as_ptr(), cb)
440        })
441    }
442
443    /// Exports opened wallet
444    ///
445    /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
446    /// in the future releases.
447    ///
448    /// # Arguments:
449    /// * `wallet_handle` - wallet handle returned by indy_open_wallet
450    /// * `export_config` - JSON containing settings for input operation.
451    ///   {
452    ///     "path": path of the file that contains exported wallet content
453    ///     "key": passphrase used to derive export key
454    ///   }
455    pub fn export(wallet_handle: IndyHandle, export_config: &str) -> Result<(), ErrorCode> {
456        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
457
458        let err = Wallet::_export(command_handle, wallet_handle, export_config, cb);
459
460        ResultHandler::empty(err, receiver)
461    }
462
463    /// Exports opened wallet
464    ///
465    /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
466    /// in the future releases.
467    ///
468    /// # Arguments:
469    /// * `wallet_handle` - wallet handle returned by indy_open_wallet
470    /// * `export_config` - JSON containing settings for input operation.
471    ///   {
472    ///     "path": path of the file that contains exported wallet content
473    ///     "key": passphrase used to derive export key
474    ///   }
475    /// * `timeout` - the maximum time this function waits for a response
476    pub fn export_timeout(wallet_handle: IndyHandle, export_config: &str, timeout: Duration) -> Result<(), ErrorCode> {
477        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
478
479        let err = Wallet::_export(command_handle, wallet_handle, export_config, cb);
480
481        ResultHandler::empty_timeout(err, receiver, timeout)
482    }
483
484    /// Exports opened wallet
485    ///
486    /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
487    /// in the future releases.
488    ///
489    /// # Arguments:
490    /// * `wallet_handle` - wallet handle returned by indy_open_wallet
491    /// * `export_config` - JSON containing settings for input operation.
492    ///   {
493    ///     "path": path of the file that contains exported wallet content
494    ///     "key": passphrase used to derive export key
495    ///   }
496    /// * `closure` - the closure that is called when finished
497    ///
498    /// # Returns
499    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
500    pub fn export_async<F: 'static>(wallet_handle: IndyHandle, export_config: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
501        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
502
503        Wallet::_export(command_handle, wallet_handle, export_config, cb)
504    }
505
506    fn _export(command_handle: IndyHandle, wallet_handle: IndyHandle, export_config: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
507        let export_config = c_str!(export_config);
508
509        ErrorCode::from(unsafe {
510          wallet::indy_export_wallet(command_handle, wallet_handle, export_config.as_ptr(), cb)
511        })
512    }
513
514    /// Creates a new secure wallet with the given unique name and then imports its content
515    /// according to fields provided in import_config
516    /// This can be seen as an Wallet::create call with additional content import
517    ///
518    /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
519    /// in the future releases.
520    ///
521    /// # Arguments
522    /// * `config` - Wallet configuration json.
523    ///   {
524    ///       "storage": <object>  List of supported keys are defined by wallet type.
525    ///   }
526    /// * `credentials` - Wallet credentials json (if NULL, then default config will be used).
527    ///   {
528    ///       "key": string,
529    ///       "storage": Optional<object>  List of supported keys are defined by wallet type.
530    ///
531    ///   }
532    /// * `import_config` - JSON containing settings for input operation.
533    ///   {
534    ///     "path": path of the file that contains exported wallet content
535    ///     "key": passphrase used to derive export key
536    ///   }
537    pub fn import(config: &str, credentials: &str, import_config: &str) -> Result<(), ErrorCode> {
538        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
539
540        let err = Wallet::_import(command_handle, config, credentials, import_config, cb);
541
542        ResultHandler::empty(err, receiver)
543    }
544
545    /// Creates a new secure wallet with the given unique name and then imports its content
546    /// according to fields provided in import_config
547    /// This can be seen as an Wallet::create call with additional content import
548    ///
549    /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
550    /// in the future releases.
551    ///
552    /// # Arguments
553    /// * `config` - Wallet configuration json.
554    ///   {
555    ///       "storage": <object>  List of supported keys are defined by wallet type.
556    ///   }
557    /// * `credentials` - Wallet credentials json (if NULL, then default config will be used).
558    ///   {
559    ///       "key": string,
560    ///       "storage": Optional<object>  List of supported keys are defined by wallet type.
561    ///
562    ///   }
563    /// * `import_config` - JSON containing settings for input operation.
564    ///   {
565    ///     "path": path of the file that contains exported wallet content
566    ///     "key": passphrase used to derive export key
567    ///   }
568    /// * `timeout` - the maximum time this function waits for a response
569    pub fn import_timeout(config: &str, credentials: &str, import_config: &str, timeout: Duration) -> Result<(), ErrorCode> {
570        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
571
572        let err = Wallet::_import(command_handle, config, credentials, import_config, cb);
573
574        ResultHandler::empty_timeout(err, receiver, timeout)
575    }
576
577    /// Creates a new secure wallet with the given unique name and then imports its content
578    /// according to fields provided in import_config
579    /// This can be seen as an Wallet::create call with additional content import
580    ///
581    /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
582    /// in the future releases.
583    ///
584    /// # Arguments
585    /// * `config` - Wallet configuration json.
586    ///   {
587    ///       "storage": <object>  List of supported keys are defined by wallet type.
588    ///   }
589    /// * `credentials` - Wallet credentials json (if NULL, then default config will be used).
590    ///   {
591    ///       "key": string,
592    ///       "storage": Optional<object>  List of supported keys are defined by wallet type.
593    ///
594    ///   }
595    /// * `import_config_json` - JSON containing settings for input operation.
596    ///   {
597    ///     "path": path of the file that contains exported wallet content
598    ///     "key": passphrase used to derive export key
599    ///   }
600    /// * `closure` - the closure that is called when finished
601    ///
602    /// # Returns
603    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
604    pub fn import_async<F: 'static>(config: &str, credentials: &str, import_config: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
605        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
606
607        Wallet::_import(command_handle, config, credentials, import_config, cb)
608    }
609
610    fn _import(command_handle: IndyHandle, config: &str, credentials: &str, import_config: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
611        let config = c_str!(config);
612        let credentials = c_str!(credentials);
613        let import_config = c_str!(import_config);
614
615        ErrorCode::from(unsafe {
616          wallet::indy_import_wallet(command_handle, config.as_ptr(), credentials.as_ptr(), import_config.as_ptr(), cb)
617        })
618    }
619
620    /// Deletes created wallet.
621    pub fn delete(config: &str, credentials: &str) -> Result<(), ErrorCode> {
622        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
623
624        let err = Wallet::_delete(command_handle, config, credentials, cb);
625
626        ResultHandler::empty(err, receiver)
627    }
628
629    /// Deletes created wallet.
630    ///
631    /// # Arguments
632    /// * `timeout` - the maximum time this function waits for a response
633    pub fn delete_timeout(config: &str, credentials: &str, timeout: Duration) -> Result<(), ErrorCode> {
634        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
635
636        let err = Wallet::_delete(command_handle, config, credentials, cb);
637
638        ResultHandler::empty_timeout(err, receiver, timeout)
639    }
640
641    /// Deletes created wallet.
642    ///
643    /// # Arguments
644    /// * `closure` - the closure that is called when finished
645    ///
646    /// # Returns
647    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
648    pub fn delete_async<F: 'static>(config: &str, credentials: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
649        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
650
651        Wallet::_delete(command_handle, config, credentials, cb)
652    }
653
654    fn _delete(command_handle: IndyHandle, config: &str, credentials: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
655        let config = c_str!(config);
656        let credentials = c_str!(credentials);
657
658        ErrorCode::from(unsafe {
659          wallet::indy_delete_wallet(command_handle, config.as_ptr(), credentials.as_ptr(), cb)
660        })
661    }
662
663    /// Closes opened wallet and frees allocated resources.
664    ///
665    /// # Arguments
666    /// * `handle` - wallet handle returned by Wallet::open.
667    pub fn close(wallet_handle: IndyHandle) -> Result<(), ErrorCode> {
668        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
669
670        let err = Wallet::_close(command_handle, wallet_handle, cb);
671
672        ResultHandler::empty(err, receiver)
673    }
674
675    /// Closes opened wallet and frees allocated resources.
676    ///
677    /// # Arguments
678    /// * `handle` - wallet handle returned by Wallet::open.
679    /// * `timeout` - the maximum time this function waits for a response
680    pub fn close_timeout(wallet_handle: IndyHandle, timeout: Duration) -> Result<(), ErrorCode> {
681        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
682
683        let err = Wallet::_close(command_handle, wallet_handle, cb);
684
685        ResultHandler::empty_timeout(err, receiver, timeout)
686    }
687
688    /// Closes opened wallet and frees allocated resources.
689    ///
690    /// # Arguments
691    /// * `handle` - wallet handle returned by Wallet::open.
692    /// * `closure` - the closure that is called when finished
693    ///
694    /// # Returns
695    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
696    pub fn close_async<F: 'static>(wallet_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
697        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
698
699        Wallet::_close(command_handle, wallet_handle, cb)
700    }
701
702    fn _close(command_handle: IndyHandle, wallet_handle: IndyHandle, cb: Option<ResponseEmptyCB>) -> ErrorCode {
703        ErrorCode::from(unsafe { wallet::indy_close_wallet(command_handle, wallet_handle, cb) })
704    }
705
706    /// Create a new non-secret record in the wallet
707    ///
708    /// # Arguments
709    /// * `wallet_handle` - wallet handle (created by open_wallet)
710    /// * `xtype` - allows to separate different record types collections
711    /// * `id` - the id of record
712    /// * `value` - the value of record
713    /// * `tags_json` -  the record tags used for search and storing meta information as json:
714    ///   {
715    ///     "tagName1": <str>, // string tag (will be stored encrypted)
716    ///     "tagName2": <str>, // string tag (will be stored encrypted)
717    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
718    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
719    ///   }
720    ///   Note that null means no tags
721    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
722    ///   usage of this tag in complex search queries (comparison, predicates)
723    ///   Encrypted tags can be searched only for exact matching
724    pub fn add_record(wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, tags_json: Option<&str>) -> Result<(), ErrorCode> {
725        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
726
727        let err = Wallet::_add_record(command_handle, wallet_handle, xtype, id, value, tags_json, cb);
728
729        ResultHandler::empty(err, receiver)
730    }
731
732    /// Create a new non-secret record in the wallet
733    ///
734    /// # Arguments
735    /// * `wallet_handle` - wallet handle (created by open_wallet)
736    /// * `xtype` - allows to separate different record types collections
737    /// * `id` - the id of record
738    /// * `value` - the value of record
739    /// * `tags_json` -  the record tags used for search and storing meta information as json:
740    ///   {
741    ///     "tagName1": <str>, // string tag (will be stored encrypted)
742    ///     "tagName2": <str>, // string tag (will be stored encrypted)
743    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
744    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
745    ///   }
746    ///   Note that null means no tags
747    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
748    ///   usage of this tag in complex search queries (comparison, predicates)
749    ///   Encrypted tags can be searched only for exact matching
750    /// * `timeout` - the maximum time this function waits for a response
751    pub fn add_record_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, tags_json: Option<&str>, timeout: Duration) -> Result<(), ErrorCode> {
752        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
753
754        let err = Wallet::_add_record(command_handle, wallet_handle, xtype, id, value, tags_json, cb);
755
756        ResultHandler::empty_timeout(err, receiver, timeout)
757    }
758
759    /// Create a new non-secret record in the wallet
760    ///
761    /// # Arguments
762    /// * `wallet_handle` - wallet handle (created by open_wallet)
763    /// * `xtype` - allows to separate different record types collections
764    /// * `id` - the id of record
765    /// * `value` - the value of record
766    /// * `tags_json` -  the record tags used for search and storing meta information as json:
767    ///   {
768    ///     "tagName1": <str>, // string tag (will be stored encrypted)
769    ///     "tagName2": <str>, // string tag (will be stored encrypted)
770    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
771    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
772    ///   }
773    ///   Note that null means no tags
774    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
775    ///   usage of this tag in complex search queries (comparison, predicates)
776    ///   Encrypted tags can be searched only for exact matching
777    /// * `closure` - the closure that is called when finished
778    ///
779    /// # Returns
780    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
781    pub fn add_record_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, tags_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
782        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
783
784        Wallet::_add_record(command_handle, wallet_handle, xtype, id, value, tags_json, cb)
785    }
786
787    fn _add_record(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, tags_json: Option<&str>, cb: Option<ResponseEmptyCB>) -> ErrorCode {
788        let xtype = c_str!(xtype);
789        let id = c_str!(id);
790        let value = c_str!(value);
791        let tags_json_str = opt_c_str!(tags_json);
792        ErrorCode::from(unsafe {
793            non_secrets::indy_add_wallet_record(command_handle,
794                                                wallet_handle,
795                                                xtype.as_ptr(),
796                                                id.as_ptr(),
797                                                value.as_ptr(),
798                                                opt_c_ptr!(tags_json, tags_json_str),
799                                                 cb)
800        })
801    }
802
803    /// Update a non-secret wallet record value
804    ///
805    /// # Arguments
806    /// * `wallet_handle` - wallet handle (created by open_wallet)
807    /// * `xtype` - allows to separate different record types collections
808    /// * `id` - the id of record
809    /// * `value` - the new value of record
810    pub fn update_record_value(wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str) -> Result<(), ErrorCode> {
811        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
812
813        let err = Wallet::_update_record_value(command_handle, wallet_handle, xtype, id, value, cb);
814
815        ResultHandler::empty(err, receiver)
816    }
817
818    /// Update a non-secret wallet record value
819    ///
820    /// # Arguments
821    /// * `wallet_handle` - wallet handle (created by open_wallet)
822    /// * `xtype` - allows to separate different record types collections
823    /// * `id` - the id of record
824    /// * `value` - the new value of record
825    /// * `timeout` - the maximum time this function waits for a response
826    pub fn update_record_value_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, timeout: Duration) -> Result<(), ErrorCode> {
827        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
828
829        let err = Wallet::_update_record_value(command_handle, wallet_handle, xtype, id, value, cb);
830
831        ResultHandler::empty_timeout(err, receiver, timeout)
832    }
833
834    /// Update a non-secret wallet record value
835    ///
836    /// # Arguments
837    /// * `wallet_handle` - wallet handle (created by open_wallet)
838    /// * `xtype` - allows to separate different record types collections
839    /// * `id` - the id of record
840    /// * `value` - the new value of record
841    /// * `closure` - the closure that is called when finished
842    ///
843    /// # Returns
844    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
845    pub fn update_record_value_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
846        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
847
848        Wallet::_update_record_value(command_handle, wallet_handle, xtype, id, value, cb)
849    }
850
851    fn _update_record_value(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, value: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
852        let xtype = c_str!(xtype);
853        let id = c_str!(id);
854        let value = c_str!(value);
855
856        ErrorCode::from(unsafe{
857            non_secrets::indy_update_wallet_record_value(command_handle,
858                                                         wallet_handle,
859                                                         xtype.as_ptr(),
860                                                         id.as_ptr(),
861                                                         value.as_ptr(),
862                                                         cb)
863        })
864    }
865
866    /// Update a non-secret wallet record tags
867    ///
868    /// # Arguments
869    /// * `wallet_handle` - wallet handle (created by open_wallet)
870    /// * `xtype` - allows to separate different record types collections
871    /// * `id` - the id of record
872    /// * `tags_json` - the record tags used for search and storing meta information as json:
873    ///   {
874    ///     "tagName1": <str>, // string tag (will be stored encrypted)
875    ///     "tagName2": <str>, // string tag (will be stored encrypted)
876    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
877    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
878    ///   }
879    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
880    ///   usage of this tag in complex search queries (comparison, predicates)
881    ///   Encrypted tags can be searched only for exact matching
882    pub fn update_record_tags(wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str) -> Result<(), ErrorCode> {
883        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
884
885        let err = Wallet::_update_record_tags(command_handle, wallet_handle, xtype, id, tags_json, cb);
886
887        ResultHandler::empty(err, receiver)
888    }
889
890    /// Update a non-secret wallet record tags
891    ///
892    /// # Arguments
893    /// * `wallet_handle` - wallet handle (created by open_wallet)
894    /// * `xtype` - allows to separate different record types collections
895    /// * `id` - the id of record
896    /// * `tags_json` - the record tags used for search and storing meta information as json:
897    ///   {
898    ///     "tagName1": <str>, // string tag (will be stored encrypted)
899    ///     "tagName2": <str>, // string tag (will be stored encrypted)
900    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
901    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
902    ///   }
903    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
904    ///   usage of this tag in complex search queries (comparison, predicates)
905    ///   Encrypted tags can be searched only for exact matching
906    /// * `timeout` - the maximum time this function waits for a response
907    pub fn update_record_tags_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str, timeout: Duration) -> Result<(), ErrorCode> {
908        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
909
910        let err = Wallet::_update_record_tags(command_handle, wallet_handle, xtype, id, tags_json, cb);
911
912        ResultHandler::empty_timeout(err, receiver, timeout)
913    }
914
915    /// Update a non-secret wallet record tags
916    ///
917    /// # Arguments
918    /// * `wallet_handle` - wallet handle (created by open_wallet)
919    /// * `xtype` - allows to separate different record types collections
920    /// * `id` - the id of record
921    /// * `tags_json` - the record tags used for search and storing meta information as json:
922    ///   {
923    ///     "tagName1": <str>, // string tag (will be stored encrypted)
924    ///     "tagName2": <str>, // string tag (will be stored encrypted)
925    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
926    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
927    ///   }
928    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
929    ///   usage of this tag in complex search queries (comparison, predicates)
930    ///   Encrypted tags can be searched only for exact matching
931    /// * `closure` - the closure that is called when finished
932    ///
933    /// # Returns
934    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
935    pub fn update_record_tags_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
936        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
937
938        Wallet::_update_record_tags(command_handle, wallet_handle, xtype, id, tags_json, cb)
939    }
940
941    fn _update_record_tags(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
942        let xtype = c_str!(xtype);
943        let id = c_str!(id);
944        let tags_json = c_str!(tags_json);
945
946        ErrorCode::from(unsafe {
947          non_secrets::indy_update_wallet_record_tags(command_handle, wallet_handle, xtype.as_ptr(), id.as_ptr(), tags_json.as_ptr(), cb)
948        })
949    }
950
951    /// Add new tags to the wallet record
952    ///
953    /// # Arguments
954    /// * `wallet_handle` - wallet handle (created by open_wallet)
955    /// * `xtype` - allows to separate different record types collections
956    /// * `id` - the id of record
957    /// * `tags_json` - the record tags used for search and storing meta information as json:
958    ///   {
959    ///     "tagName1": <str>, // string tag (will be stored encrypted)
960    ///     "tagName2": <str>, // string tag (will be stored encrypted)
961    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
962    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
963    ///   }
964    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
965    ///   usage of this tag in complex search queries (comparison, predicates)
966    ///   Encrypted tags can be searched only for exact matching
967    ///   Note if some from provided tags already assigned to the record than
968    ///     corresponding tags values will be replaced
969    pub fn add_record_tags(wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str) -> Result<(), ErrorCode> {
970        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
971
972        let err = Wallet::_add_record_tags(command_handle, wallet_handle, xtype, id, tags_json, cb);
973
974        ResultHandler::empty(err, receiver)
975    }
976
977    /// Add new tags to the wallet record
978    ///
979    /// # Arguments
980    /// * `wallet_handle` - wallet handle (created by open_wallet)
981    /// * `xtype` - allows to separate different record types collections
982    /// * `id` - the id of record
983    /// * `tags_json` - the record tags used for search and storing meta information as json:
984    ///   {
985    ///     "tagName1": <str>, // string tag (will be stored encrypted)
986    ///     "tagName2": <str>, // string tag (will be stored encrypted)
987    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
988    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
989    ///   }
990    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
991    ///   usage of this tag in complex search queries (comparison, predicates)
992    ///   Encrypted tags can be searched only for exact matching
993    ///   Note if some from provided tags already assigned to the record than
994    ///     corresponding tags values will be replaced
995    /// * `timeout` - the maximum time this function waits for a response
996    pub fn add_record_tags_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str, timeout: Duration) -> Result<(), ErrorCode> {
997        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
998
999        let err = Wallet::_add_record_tags(command_handle, wallet_handle, xtype, id, tags_json, cb);
1000
1001        ResultHandler::empty_timeout(err, receiver, timeout)
1002    }
1003
1004    /// Add new tags to the wallet record
1005    ///
1006    /// # Arguments
1007    /// * `wallet_handle` - wallet handle (created by open_wallet)
1008    /// * `xtype` - allows to separate different record types collections
1009    /// * `id` - the id of record
1010    /// * `tags_json` - the record tags used for search and storing meta information as json:
1011    ///   {
1012    ///     "tagName1": <str>, // string tag (will be stored encrypted)
1013    ///     "tagName2": <str>, // string tag (will be stored encrypted)
1014    ///     "~tagName3": <str>, // string tag (will be stored un-encrypted)
1015    ///     "~tagName4": <str>, // string tag (will be stored un-encrypted)
1016    ///   }
1017    ///   If tag name starts with "~" the tag will be stored un-encrypted that will allow
1018    ///   usage of this tag in complex search queries (comparison, predicates)
1019    ///   Encrypted tags can be searched only for exact matching
1020    ///   Note if some from provided tags already assigned to the record than
1021    ///     corresponding tags values will be replaced
1022    /// * `closure` - the closure that is called when finished
1023    ///
1024    /// # Returns
1025    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1026    pub fn add_record_tags_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
1027        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
1028
1029        Wallet::_add_record_tags(command_handle, wallet_handle, xtype, id, tags_json, cb)
1030    }
1031
1032    fn _add_record_tags(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, tags_json: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
1033        let xtype = c_str!(xtype);
1034        let id = c_str!(id);
1035        let tags_json = c_str!(tags_json);
1036
1037        ErrorCode::from(unsafe {
1038          non_secrets::indy_add_wallet_record_tags(command_handle, wallet_handle, xtype.as_ptr(), id.as_ptr(), tags_json.as_ptr(), cb)
1039        })
1040    }
1041
1042    /// Delete tags from the wallet record
1043    ///
1044    /// # Arguments
1045    /// * `wallet_handle` - wallet handle (created by open_wallet)
1046    /// * `xtype` - allows to separate different record types collections
1047    /// * `id` - the id of record
1048    /// * `tag_names_json` - the list of tag names to remove from the record as json array:
1049    ///   ["tagName1", "tagName2", ...]
1050    pub fn delete_record_tags(wallet_handle: IndyHandle, xtype: &str, id: &str, tag_names_json: &str) -> Result<(), ErrorCode> {
1051        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
1052
1053        let err = Wallet::_delete_record_tags(command_handle, wallet_handle, xtype, id, tag_names_json, cb);
1054
1055        ResultHandler::empty(err, receiver)
1056    }
1057
1058    /// Delete tags from the wallet record
1059    ///
1060    /// # Arguments
1061    /// * `wallet_handle` - wallet handle (created by open_wallet)
1062    /// * `xtype` - allows to separate different record types collections
1063    /// * `id` - the id of record
1064    /// * `tag_names_json` - the list of tag names to remove from the record as json array:
1065    ///   ["tagName1", "tagName2", ...]
1066    /// * `timeout` - the maximum time this function waits for a response
1067    pub fn delete_record_tags_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, tag_names_json: &str, timeout: Duration) -> Result<(), ErrorCode> {
1068        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
1069
1070        let err = Wallet::_delete_record_tags(command_handle, wallet_handle, xtype, id, tag_names_json, cb);
1071
1072        ResultHandler::empty_timeout(err, receiver, timeout)
1073    }
1074
1075    /// Delete tags from the wallet record
1076    ///
1077    /// # Arguments
1078    /// * `wallet_handle` - wallet handle (created by open_wallet)
1079    /// * `xtype` - allows to separate different record types collections
1080    /// * `id` - the id of record
1081    /// * `tag_names_json` - the list of tag names to remove from the record as json array:
1082    ///   ["tagName1", "tagName2", ...]
1083    /// * `closure` - the closure that is called when finished
1084    ///
1085    /// # Returns
1086    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1087    pub fn delete_record_tags_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, tag_names_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
1088        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
1089
1090        Wallet::_delete_record_tags(command_handle, wallet_handle, xtype, id, tag_names_json, cb)
1091    }
1092
1093    fn _delete_record_tags(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, tag_names_json: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
1094        let xtype = c_str!(xtype);
1095        let id = c_str!(id);
1096        let tag_names_json = c_str!(tag_names_json);
1097
1098        ErrorCode::from(unsafe {
1099          non_secrets::indy_delete_wallet_record_tags(command_handle, wallet_handle, xtype.as_ptr(), id.as_ptr(), tag_names_json.as_ptr(), cb)
1100        })
1101    }
1102
1103    /// Delete an existing wallet record in the wallet
1104    ///
1105    /// # Arguments
1106    /// * `wallet_handle` - wallet handle (created by open_wallet)
1107    /// * `xtype` - record type
1108    /// * `id` - the id of record
1109    pub fn delete_record(wallet_handle: IndyHandle, xtype: &str, id: &str) -> Result<(), ErrorCode> {
1110        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
1111
1112        let err = Wallet::_delete_record(command_handle, wallet_handle, xtype, id, cb);
1113
1114        ResultHandler::empty(err, receiver)
1115    }
1116
1117    /// Delete an existing wallet record in the wallet
1118    ///
1119    /// # Arguments
1120    /// * `wallet_handle` - wallet handle (created by open_wallet)
1121    /// * `xtype` - record type
1122    /// * `id` - the id of record
1123    /// * `timeout` - the maximum time this function waits for a response
1124    pub fn delete_record_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, timeout: Duration) -> Result<(), ErrorCode> {
1125        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
1126
1127        let err = Wallet::_delete_record(command_handle, wallet_handle, xtype, id, cb);
1128
1129        ResultHandler::empty_timeout(err, receiver, timeout)
1130    }
1131
1132    /// Delete an existing wallet record in the wallet
1133    ///
1134    /// # Arguments
1135    /// * `wallet_handle` - wallet handle (created by open_wallet)
1136    /// * `xtype` - record type
1137    /// * `id` - the id of record
1138    /// * `closure` - the closure that is called when finished
1139    ///
1140    /// # Returns
1141    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1142    pub fn delete_record_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
1143        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
1144
1145        Wallet::_delete_record(command_handle, wallet_handle, xtype, id, cb)
1146    }
1147
1148    fn _delete_record(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
1149        let xtype = c_str!(xtype);
1150        let id = c_str!(id);
1151
1152        ErrorCode::from(unsafe {
1153          non_secrets::indy_delete_wallet_record(command_handle, wallet_handle, xtype.as_ptr(), id.as_ptr(), cb)
1154        })
1155    }
1156
1157    /// Get an wallet record by id
1158    ///
1159    /// # Arguments
1160    /// * `wallet_handle` - wallet handle (created by open_wallet)
1161    /// * `xtype` - allows to separate different record types collections
1162    /// * `id` - the id of record
1163    /// * `options_json` - //TODO: FIXME: Think about replacing by bitmaks
1164    ///  {
1165    ///    retrieveType: (optional, false by default) Retrieve record type,
1166    ///    retrieveValue: (optional, true by default) Retrieve record value,
1167    ///    retrieveTags: (optional, false by default) Retrieve record tags
1168    ///  }
1169    /// # Returns
1170    /// * `wallet record json` -
1171    /// {
1172    ///   id: "Some id",
1173    ///   type: "Some type", // present only if retrieveType set to true
1174    ///   value: "Some value", // present only if retrieveValue set to true
1175    ///   tags: <tags json>, // present only if retrieveTags set to true
1176    /// }
1177    pub fn get_record(wallet_handle: IndyHandle, xtype: &str, id: &str, options_json: &str) -> Result<String, ErrorCode> {
1178        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1179
1180        let err = Wallet::_get_record(command_handle, wallet_handle, xtype, id, options_json, cb);
1181
1182        ResultHandler::one(err, receiver)
1183    }
1184
1185    /// Get an wallet record by id
1186    ///
1187    /// # Arguments
1188    /// * `wallet_handle` - wallet handle (created by open_wallet)
1189    /// * `xtype` - allows to separate different record types collections
1190    /// * `id` - the id of record
1191    /// * `options_json` - //TODO: FIXME: Think about replacing by bitmaks
1192    ///  {
1193    ///    retrieveType: (optional, false by default) Retrieve record type,
1194    ///    retrieveValue: (optional, true by default) Retrieve record value,
1195    ///    retrieveTags: (optional, false by default) Retrieve record tags
1196    ///  }
1197    /// * `timeout` - the maximum time this function waits for a response
1198    /// # Returns
1199    /// * `wallet record json` -
1200    /// {
1201    ///   id: "Some id",
1202    ///   type: "Some type", // present only if retrieveType set to true
1203    ///   value: "Some value", // present only if retrieveValue set to true
1204    ///   tags: <tags json>, // present only if retrieveTags set to true
1205    /// }
1206    pub fn get_record_timeout(wallet_handle: IndyHandle, xtype: &str, id: &str, options_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
1207        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1208
1209        let err = Wallet::_get_record(command_handle, wallet_handle, xtype, id, options_json, cb);
1210
1211        ResultHandler::one_timeout(err, receiver, timeout)
1212    }
1213
1214    /// Get an wallet record by id
1215    ///
1216    /// # Arguments
1217    /// * `wallet_handle` - wallet handle (created by open_wallet)
1218    /// * `xtype` - allows to separate different record types collections
1219    /// * `id` - the id of record
1220    /// * `options_json` - //TODO: FIXME: Think about replacing by bitmaks
1221    ///  {
1222    ///    retrieveType: (optional, false by default) Retrieve record type,
1223    ///    retrieveValue: (optional, true by default) Retrieve record value,
1224    ///    retrieveTags: (optional, false by default) Retrieve record tags
1225    ///  }
1226    /// * `closure` - the closure that is called when finished
1227    ///
1228    /// # Returns
1229    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1230    pub fn get_record_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, id: &str, options_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1231        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1232
1233        Wallet::_get_record(command_handle, wallet_handle, xtype, id, options_json, cb)
1234    }
1235
1236    fn _get_record(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, id: &str, options_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1237        let xtype = c_str!(xtype);
1238        let id = c_str!(id);
1239        let options_json = c_str!(options_json);
1240
1241        ErrorCode::from(unsafe {
1242          non_secrets::indy_get_wallet_record(command_handle, wallet_handle, xtype.as_ptr(), id.as_ptr(), options_json.as_ptr(), cb)
1243        })
1244    }
1245
1246    /// Search for wallet records.
1247    ///
1248    /// Note instead of immediately returning of fetched records
1249    /// this call returns wallet_search_handle that can be used later
1250    /// to fetch records by small batches (with indy_fetch_wallet_search_next_records).
1251    ///
1252    /// # Arguments
1253    /// * `wallet_handle` - wallet handle (created by open_wallet)
1254    /// * `xtype` - allows to separate different record types collections
1255    /// * `query_json` - MongoDB style query to wallet record tags:
1256    ///  {
1257    ///    "tagName": "tagValue",
1258    ///    $or: {
1259    ///      "tagName2": { $regex: 'pattern' },
1260    ///      "tagName3": { $gte: '123' },
1261    ///    },
1262    ///  }
1263    /// * `options_json` - //TODO: FIXME: Think about replacing by bitmaks
1264    ///  {
1265    ///    retrieveRecords: (optional, true by default) If false only "counts" will be calculated,
1266    ///    retrieveTotalCount: (optional, false by default) Calculate total count,
1267    ///    retrieveType: (optional, false by default) Retrieve record type,
1268    ///    retrieveValue: (optional, true by default) Retrieve record value,
1269    ///    retrieveTags: (optional, false by default) Retrieve record tags,
1270    ///  }
1271    /// # Returns
1272    /// * `search_handle` - Wallet search handle that can be used later
1273    ///   to fetch records by small batches (with indy_fetch_wallet_search_next_records)
1274    pub fn open_search(wallet_handle: IndyHandle, xtype: &str, query_json: &str, options_json: &str) -> Result<IndyHandle, ErrorCode> {
1275        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
1276
1277        let err = Wallet::_open_search(command_handle, wallet_handle, xtype, query_json, options_json, cb);
1278
1279        ResultHandler::one(err, receiver)
1280    }
1281
1282    /// Search for wallet records.
1283    ///
1284    /// Note instead of immediately returning of fetched records
1285    /// this call returns wallet_search_handle that can be used later
1286    /// to fetch records by small batches (with indy_fetch_wallet_search_next_records).
1287    ///
1288    /// # Arguments
1289    /// * `wallet_handle` - wallet handle (created by open_wallet)
1290    /// * `xtype` - allows to separate different record types collections
1291    /// * `query_json` - MongoDB style query to wallet record tags:
1292    ///  {
1293    ///    "tagName": "tagValue",
1294    ///    $or: {
1295    ///      "tagName2": { $regex: 'pattern' },
1296    ///      "tagName3": { $gte: '123' },
1297    ///    },
1298    ///  }
1299    /// * `options_json` - //TODO: FIXME: Think about replacing by bitmaks
1300    ///  {
1301    ///    retrieveRecords: (optional, true by default) If false only "counts" will be calculated,
1302    ///    retrieveTotalCount: (optional, false by default) Calculate total count,
1303    ///    retrieveType: (optional, false by default) Retrieve record type,
1304    ///    retrieveValue: (optional, true by default) Retrieve record value,
1305    ///    retrieveTags: (optional, false by default) Retrieve record tags,
1306    ///  }
1307    /// * `timeout` - the maximum time this function waits for a response
1308    /// # Returns
1309    /// * `search_handle` - Wallet search handle that can be used later
1310    ///   to fetch records by small batches (with indy_fetch_wallet_search_next_records)
1311    pub fn open_search_timeout(wallet_handle: IndyHandle, xtype: &str, query_json: &str, options_json: &str, timeout: Duration) -> Result<IndyHandle, ErrorCode> {
1312        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();
1313
1314        let err = Wallet::_open_search(command_handle, wallet_handle, xtype, query_json, options_json, cb);
1315
1316        ResultHandler::one_timeout(err, receiver, timeout)
1317    }
1318
1319    /// Search for wallet records.
1320    ///
1321    /// Note instead of immediately returning of fetched records
1322    /// this call returns wallet_search_handle that can be used later
1323    /// to fetch records by small batches (with indy_fetch_wallet_search_next_records).
1324    ///
1325    /// # Arguments
1326    /// * `wallet_handle` - wallet handle (created by open_wallet)
1327    /// * `xtype` - allows to separate different record types collections
1328    /// * `query_json` - MongoDB style query to wallet record tags:
1329    ///  {
1330    ///    "tagName": "tagValue",
1331    ///    $or: {
1332    ///      "tagName2": { $regex: 'pattern' },
1333    ///      "tagName3": { $gte: '123' },
1334    ///    },
1335    ///  }
1336    /// * `options_json` - //TODO: FIXME: Think about replacing by bitmaks
1337    ///  {
1338    ///    retrieveRecords: (optional, true by default) If false only "counts" will be calculated,
1339    ///    retrieveTotalCount: (optional, false by default) Calculate total count,
1340    ///    retrieveType: (optional, false by default) Retrieve record type,
1341    ///    retrieveValue: (optional, true by default) Retrieve record value,
1342    ///    retrieveTags: (optional, false by default) Retrieve record tags,
1343    ///  }
1344    /// * `closure` - the closure that is called when finished
1345    ///
1346    /// # Returns
1347    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1348    pub fn open_search_async<F: 'static>(wallet_handle: IndyHandle, xtype: &str, query_json: &str, options_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, IndyHandle) + Send {
1349        let (command_handle, cb) = ClosureHandler::convert_cb_ec_i32(Box::new(closure));
1350
1351        Wallet::_open_search(command_handle, wallet_handle, xtype, query_json, options_json, cb)
1352    }
1353
1354    fn _open_search(command_handle: IndyHandle, wallet_handle: IndyHandle, xtype: &str, query_json: &str, options_json: &str, cb: Option<ResponseI32CB>) -> ErrorCode {
1355        let xtype = c_str!(xtype);
1356        let query_json = c_str!(query_json);
1357        let options_json = c_str!(options_json);
1358
1359        ErrorCode::from(unsafe {
1360          non_secrets::indy_open_wallet_search(command_handle, wallet_handle, xtype.as_ptr(), query_json.as_ptr(), options_json.as_ptr(), cb)
1361        })
1362    }
1363
1364    /// Fetch next records for wallet search.
1365    ///
1366    /// Not if there are no records this call returns WalletNoRecords error.
1367    ///
1368    /// # Arguments
1369    /// * `wallet_handle` - wallet handle (created by open_wallet)
1370    /// * `wallet_search_handle` - wallet search handle (created by indy_open_wallet_search)
1371    /// * `count` - Count of records to fetch
1372    ///
1373    /// # Returns
1374    /// * `wallet records json` -
1375    /// {
1376    ///   totalCount: <str>, // present only if retrieveTotalCount set to true
1377    ///   records: [{ // present only if retrieveRecords set to true
1378    ///       id: "Some id",
1379    ///       type: "Some type", // present only if retrieveType set to true
1380    ///       value: "Some value", // present only if retrieveValue set to true
1381    ///       tags: <tags json>, // present only if retrieveTags set to true
1382    ///   }],
1383    /// }
1384    pub fn fetch_search_next_records(wallet_handle: IndyHandle, wallet_search_handle: IndyHandle, count: usize) -> Result<String, ErrorCode> {
1385        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1386
1387        let err = Wallet::_fetch_search_next_records(command_handle, wallet_handle, wallet_search_handle, count, cb);
1388
1389        ResultHandler::one(err, receiver)
1390    }
1391
1392    /// Fetch next records for wallet search.
1393    ///
1394    /// Not if there are no records this call returns WalletNoRecords error.
1395    ///
1396    /// # Arguments
1397    /// * `wallet_handle` - wallet handle (created by open_wallet)
1398    /// * `wallet_search_handle` - wallet search handle (created by indy_open_wallet_search)
1399    /// * `count` - Count of records to fetch
1400    /// * `timeout` - the maximum time this function waits for a response
1401    ///
1402    /// # Returns
1403    /// * `wallet records json` -
1404    /// {
1405    ///   totalCount: <str>, // present only if retrieveTotalCount set to true
1406    ///   records: [{ // present only if retrieveRecords set to true
1407    ///       id: "Some id",
1408    ///       type: "Some type", // present only if retrieveType set to true
1409    ///       value: "Some value", // present only if retrieveValue set to true
1410    ///       tags: <tags json>, // present only if retrieveTags set to true
1411    ///   }],
1412    /// }
1413    pub fn fetch_search_next_records_timeout(wallet_handle: IndyHandle, wallet_search_handle: IndyHandle, count: usize, timeout: Duration) -> Result<String, ErrorCode> {
1414        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1415
1416        let err = Wallet::_fetch_search_next_records(command_handle, wallet_handle, wallet_search_handle, count, cb);
1417
1418        ResultHandler::one_timeout(err, receiver, timeout)
1419    }
1420
1421    /// Fetch next records for wallet search.
1422    ///
1423    /// Not if there are no records this call returns WalletNoRecords error.
1424    ///
1425    /// # Arguments
1426    /// * `wallet_handle` - wallet handle (created by open_wallet)
1427    /// * `wallet_search_handle` - wallet search handle (created by indy_open_wallet_search)
1428    /// * `count` - Count of records to fetch
1429    /// * `closure` - the closure that is called when finished
1430    ///
1431    /// # Returns
1432    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1433    pub fn fetch_search_next_records_async<F: 'static>(wallet_handle: IndyHandle, wallet_search_handle: IndyHandle, count: usize, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1434        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1435
1436        Wallet::_fetch_search_next_records(command_handle, wallet_handle, wallet_search_handle, count, cb)
1437    }
1438
1439    fn _fetch_search_next_records(command_handle: IndyHandle, wallet_handle: IndyHandle, wallet_search_handle: IndyHandle, count: usize, cb: Option<ResponseStringCB>) -> ErrorCode {
1440        ErrorCode::from(unsafe {
1441          non_secrets::indy_fetch_wallet_search_next_records(command_handle, wallet_handle, wallet_search_handle, count, cb)
1442        })
1443    }
1444
1445    /// Close wallet search (make search handle invalid)
1446    ///
1447    /// # Arguments
1448    /// * `wallet_search_handle` - wallet search handle
1449    pub fn close_search(wallet_search_handle: IndyHandle) -> Result<(), ErrorCode> {
1450        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
1451
1452        let err = Wallet::_close_search(command_handle, wallet_search_handle, cb);
1453
1454        ResultHandler::empty(err, receiver)
1455    }
1456
1457    /// Close wallet search (make search handle invalid)
1458    ///
1459    /// # Arguments
1460    /// * `wallet_search_handle` - wallet search handle
1461    /// * `timeout` - the maximum time this function waits for a response
1462    pub fn close_search_timeout(wallet_search_handle: IndyHandle, timeout: Duration) -> Result<(), ErrorCode> {
1463        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
1464
1465        let err = Wallet::_close_search(command_handle, wallet_search_handle, cb);
1466
1467        ResultHandler::empty_timeout(err, receiver, timeout)
1468    }
1469
1470    /// Close wallet search (make search handle invalid)
1471    ///
1472    /// # Arguments
1473    /// * `wallet_search_handle` - wallet search handle
1474    /// * `closure` - the closure that is called when finished
1475    ///
1476    /// # Returns
1477    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1478    pub fn close_search_async<F: 'static>(wallet_search_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
1479        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
1480
1481        Wallet::_close_search(command_handle, wallet_search_handle, cb)
1482    }
1483
1484    fn _close_search(command_handle: IndyHandle, wallet_search_handle: IndyHandle, cb: Option<ResponseEmptyCB>) -> ErrorCode {
1485        ErrorCode::from(unsafe {
1486          non_secrets::indy_close_wallet_search(command_handle, wallet_search_handle, cb)
1487        })
1488    }
1489
1490    fn _default_credentials(credentials: Option<&str>) -> CString {
1491        match credentials {
1492            Some(s) => c_str!(s),
1493            None => c_str!(r#"{"key":""}"#)
1494        }
1495    }
1496}