rust_libindy_wrapper/
did.rs

1use {ErrorCode, IndyHandle};
2
3use std::ffi::CString;
4use std::time::Duration;
5
6use native::did;
7use native::{ResponseEmptyCB,
8          ResponseStringCB,
9          ResponseStringStringCB};
10
11use utils::callbacks::ClosureHandler;
12use utils::results::ResultHandler;
13
14pub struct Did {}
15
16impl Did {
17    /// Creates keys (signing and encryption keys) for a new
18    /// DID (owned by the caller of the library).
19    /// Identity's DID must be either explicitly provided, or taken as the first 16 bit of verkey.
20    /// Saves the Identity DID with keys in a secured Wallet, so that it can be used to sign
21    /// and encrypt transactions.
22    ///
23    /// # Arguments
24    /// * `wallet_handle` - wallet handler (created by Wallet::open).
25    /// * `did_json` - Identity information as json.
26    ///
27    ///  # Examples
28    /// `did_json`
29    /// {
30    ///     "did": string, (optional;
31    ///             if not provided and cid param is false then the first 16 bit of the verkey will be used as a new DID;
32    ///             if not provided and cid is true then the full verkey will be used as a new DID;
33    ///             if provided, then keys will be replaced - key rotation use case)
34    ///     "seed": string, (optional; if not provide then a random one will be created)
35    ///     "crypto_type": string, (optional; if not set then ed25519 curve is used;
36    ///               currently only 'ed25519' value is supported for this field)
37    ///     "cid": bool, (optional; if not set then false is used;)
38    /// }
39    ///
40    /// # Returns
41    ///   * `did` - DID generated and stored in the wallet
42    ///   * `verkey` - The DIDs verification key
43    pub fn new(wallet_handle: IndyHandle, did_json: &str) -> Result<(String, String), ErrorCode> {
44        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
45
46        let err = Did::_new(command_handle, wallet_handle, did_json, cb);
47
48        ResultHandler::two(err, receiver)
49    }
50
51    /// Creates keys (signing and encryption keys) for a new
52    /// DID (owned by the caller of the library).
53    /// Identity's DID must be either explicitly provided, or taken as the first 16 bit of verkey.
54    /// Saves the Identity DID with keys in a secured Wallet, so that it can be used to sign
55    /// and encrypt transactions.
56    ///
57    /// # Arguments
58    /// * `wallet_handle` - wallet handler (created by Wallet::open).
59    /// * `did_json` - Identity information as json.
60    /// * `timeout` - the maximum time this function waits for a response
61    ///
62    ///  # Examples
63    /// `did_json`
64    /// {
65    ///     "did": string, (optional;
66    ///             if not provided and cid param is false then the first 16 bit of the verkey will be used as a new DID;
67    ///             if not provided and cid is true then the full verkey will be used as a new DID;
68    ///             if provided, then keys will be replaced - key rotation use case)
69    ///     "seed": string, (optional; if not provide then a random one will be created)
70    ///     "crypto_type": string, (optional; if not set then ed25519 curve is used;
71    ///               currently only 'ed25519' value is supported for this field)
72    ///     "cid": bool, (optional; if not set then false is used;)
73    /// }
74    ///
75    /// # Returns
76    ///   * `did` - DID generated and stored in the wallet
77    ///   * `verkey` - The DIDs verification key
78    pub fn new_timeout(wallet_handle: IndyHandle, did_json: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
79        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
80
81        let err = Did::_new(command_handle, wallet_handle, did_json, cb);
82
83        ResultHandler::two_timeout(err, receiver, timeout)
84    }
85
86    /// Creates keys (signing and encryption keys) for a new
87    /// DID (owned by the caller of the library).
88    /// Identity's DID must be either explicitly provided, or taken as the first 16 bit of verkey.
89    /// Saves the Identity DID with keys in a secured Wallet, so that it can be used to sign
90    /// and encrypt transactions.
91    ///
92    /// # Arguments
93    /// * `wallet_handle` - wallet handler (created by Wallet::open).
94    /// * `did_json` - Identity information as json.
95    /// * `closure` - the closure that is called when finished
96    ///
97    ///  # Examples
98    /// `did_json`
99    /// {
100    ///     "did": string, (optional;
101    ///             if not provided and cid param is false then the first 16 bit of the verkey will be used as a new DID;
102    ///             if not provided and cid is true then the full verkey will be used as a new DID;
103    ///             if provided, then keys will be replaced - key rotation use case)
104    ///     "seed": string, (optional; if not provide then a random one will be created)/**/
105    ///     "crypto_type": string, (optional; if not set then ed25519 curve is used;
106    ///               currently only 'ed25519' value is supported for this field)
107    ///     "cid": bool, (optional; if not set then false is used;)
108    /// }
109    ///
110    /// # Returns
111    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
112    pub fn new_async<F: 'static>(wallet_handle: IndyHandle, did_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
113        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
114
115        Did::_new(command_handle, wallet_handle, did_json, cb)
116    }
117
118    fn _new(command_handle: IndyHandle, wallet_handle: IndyHandle, did_json: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
119        let did_json = c_str!(did_json);
120
121        ErrorCode::from(unsafe { did::indy_create_and_store_my_did(command_handle, wallet_handle, did_json.as_ptr(), cb) })
122    }
123
124    /// Generated temporary keys (signing and encryption keys) for an existing
125    /// DID (owned by the caller of the library).
126    ///
127    /// # Arguments
128    /// * `wallet_handle` - wallet handler (created by Wallet::open).
129    /// * `tgt_did` - DID to replace keys.
130    /// * `identity_json` - Identity information as json.
131    /// # Example
132    /// * `identity_json`- 
133    /// {
134    ///     "seed": string, (optional; if not provide then a random one will be created)
135    ///     "crypto_type": string, (optional; if not set then ed25519 curve is used;
136    ///               currently only 'ed25519' value is supported for this field)
137    /// }
138    ///
139    /// # Returns
140    /// * `verkey` - The DIDs verification key
141    pub fn replace_keys_start(wallet_handle: IndyHandle, tgt_did: &str, identity_json: &str) -> Result<String, ErrorCode> {
142        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
143
144        let err = Did::_replace_keys_start(command_handle, wallet_handle, tgt_did, identity_json, cb);
145
146        ResultHandler::one(err, receiver)
147    }
148
149    /// Generated temporary keys (signing and encryption keys) for an existing
150    /// DID (owned by the caller of the library).
151    ///
152    /// # Arguments
153    /// * `wallet_handle` - wallet handler (created by Wallet::open).
154    /// * `tgt_did` - DID to replace keys.
155    /// * `identity_json` - Identity information as json.
156    /// * `timeout` - the maximum time this function waits for a response
157    ///
158    /// # Example
159    /// * `identity_json`- 
160    /// {
161    ///     "seed": string, (optional; if not provide then a random one will be created)
162    ///     "crypto_type": string, (optional; if not set then ed25519 curve is used;
163    ///               currently only 'ed25519' value is supported for this field)
164    /// }
165    ///
166    /// # Returns
167    /// * `verkey` - The DIDs verification key
168    pub fn replace_keys_start_timeout(wallet_handle: IndyHandle, tgt_did: &str, identity_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
169        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
170
171        let err = Did::_replace_keys_start(command_handle, wallet_handle, tgt_did, identity_json, cb);
172
173        ResultHandler::one_timeout(err, receiver, timeout)
174    }
175
176    /// Generated temporary keys (signing and encryption keys) for an existing
177    /// DID (owned by the caller of the library).
178    ///
179    /// # Arguments
180    /// * `wallet_handle` - wallet handler (created by Wallet::open).
181    /// * `tgt_did` - DID to replace keys.
182    /// * `identity_json` - Identity information as json.
183    /// * `closure` - the closure that is called when finished
184    ///
185    /// # Example
186    /// * `identity_json`- 
187    /// {
188    ///     "seed": string, (optional; if not provide then a random one will be created)
189    ///     "crypto_type": string, (optional; if not set then ed25519 curve is used;
190    ///               currently only 'ed25519' value is supported for this field)
191    /// }
192    ///
193    /// # Returns
194    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
195    pub fn replace_keys_start_async<F: 'static>(wallet_handle: IndyHandle, tgt_did: &str, identity_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
196        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
197
198        Did::_replace_keys_start(command_handle, wallet_handle, tgt_did, identity_json, cb)
199    }
200
201    fn _replace_keys_start(command_handle: IndyHandle, wallet_handle: IndyHandle, tgt_did: &str, identity_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
202        let tgt_did = c_str!(tgt_did);
203        let identity_json = c_str!(identity_json);
204
205        ErrorCode::from(unsafe { did::indy_replace_keys_start(command_handle, wallet_handle, tgt_did.as_ptr(), identity_json.as_ptr(), cb) })
206    }
207
208    /// Apply temporary keys as main for an existing DID (owned by the caller of the library).
209    ///
210    /// # Arguments
211    /// * `wallet_handle` - wallet handler (created by Wallet::open).
212    /// * `tgt_did` - DID stored in the wallet
213    pub fn replace_keys_apply(wallet_handle: IndyHandle, tgt_did: &str) -> Result<(), ErrorCode> {
214        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
215
216        let err = Did::_replace_keys_apply(command_handle, wallet_handle, tgt_did, cb);
217
218        ResultHandler::empty(err, receiver)
219    }
220
221    /// Apply temporary keys as main for an existing DID (owned by the caller of the library).
222    ///
223    /// # Arguments
224    /// * `wallet_handle` - wallet handler (created by Wallet::open).
225    /// * `tgt_did` - DID stored in the wallet
226    /// * `timeout` - the maximum time this function waits for a response
227    pub fn replace_keys_apply_timeout(wallet_handle: IndyHandle, tgt_did: &str, timeout: Duration) -> Result<(), ErrorCode> {
228        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
229
230        let err = Did::_replace_keys_apply(command_handle, wallet_handle, tgt_did, cb);
231
232        ResultHandler::empty_timeout(err, receiver, timeout)
233    }
234
235    /// Apply temporary keys as main for an existing DID (owned by the caller of the library).
236    ///
237    /// # Arguments
238    /// * `wallet_handle` - wallet handler (created by Wallet::open).
239    /// * `tgt_did` - DID stored in the wallet
240    /// * `closure` - the closure that is called when finished
241    ///
242    /// # Returns
243    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
244    pub fn replace_keys_apply_async<F: 'static>(wallet_handle: IndyHandle, tgt_did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
245        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
246
247        Did::_replace_keys_apply(command_handle, wallet_handle, tgt_did, cb)
248    }
249    
250    fn _replace_keys_apply(command_handle: IndyHandle, wallet_handle: IndyHandle, tgt_did: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
251        let tgt_did = c_str!(tgt_did);
252
253        ErrorCode::from(unsafe { did::indy_replace_keys_apply(command_handle, wallet_handle, tgt_did.as_ptr(), cb) })
254    }
255
256    /// Saves their DID for a pairwise connection in a secured Wallet,
257    /// so that it can be used to verify transaction.
258    ///
259    /// # Arguments
260    /// * `wallet_handle` - wallet handler (created by Wallet::open).
261    /// * `identity_json` - Identity information as json.
262    /// # Example:
263    /// * `identity_json`
264    ///     {
265    ///        "did": string, (required)
266    ///        "verkey": string (optional, can be avoided if did is cryptonym: did == verkey),
267    ///     }
268    pub fn store_their_did(wallet_handle: IndyHandle, identity_json: &str) -> Result<(), ErrorCode> {
269        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
270
271        let err = Did::_store_their_did(command_handle, wallet_handle, identity_json, cb);
272
273        ResultHandler::empty(err, receiver)
274    }
275
276    /// Saves their DID for a pairwise connection in a secured Wallet,
277    /// so that it can be used to verify transaction.
278    ///
279    /// # Arguments
280    /// * `wallet_handle` - wallet handler (created by Wallet::open).
281    /// * `identity_json` - Identity information as json.
282    /// * `timeout` - the maximum time this function waits for a response
283    /// # Example:
284    /// * `identity_json`
285    ///     {
286    ///        "did": string, (required)
287    ///        "verkey": string (optional, can be avoided if did is cryptonym: did == verkey),
288    ///     }
289    pub fn store_their_did_timeout(wallet_handle: IndyHandle, identity_json: &str, timeout: Duration) -> Result<(), ErrorCode> {
290        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
291
292        let err = Did::_store_their_did(command_handle, wallet_handle, identity_json, cb);
293
294        ResultHandler::empty_timeout(err, receiver, timeout)
295    }
296
297    /// Saves their DID for a pairwise connection in a secured Wallet,
298    /// so that it can be used to verify transaction.
299    ///
300    /// # Arguments
301    /// * `wallet_handle` - wallet handler (created by Wallet::open).
302    /// * `identity_json` - Identity information as json.
303    /// * `closure` - the closure that is called when finished
304    /// # Example:
305    /// * `identity_json`
306    ///     {
307    ///        "did": string, (required)
308    ///        "verkey": string (optional, can be avoided if did is cryptonym: did == verkey),
309    ///     }
310    ///
311    /// # Returns
312    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
313    pub fn store_their_did_async<F: 'static>(wallet_handle: IndyHandle, identity_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
314        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
315
316        Did::_store_their_did(command_handle, wallet_handle, identity_json, cb)
317    }
318
319    fn _store_their_did(command_handle: IndyHandle, wallet_handle: IndyHandle, identity_json: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
320        let identity_json = c_str!(identity_json);
321
322        ErrorCode::from(unsafe { did::indy_store_their_did(command_handle, wallet_handle, identity_json.as_ptr(), cb) })
323    }
324
325    /// Returns ver key (key id) for the given DID.
326    ///
327    /// "Did::get_ver_key" call follow the idea that we resolve information about their DID from
328    /// the ledger with cache in the local wallet. The "indy_Wallet::open" call has freshness parameter
329    /// that is used for checking the freshness of cached pool value.
330    ///
331    /// Note if you don't want to resolve their DID info from the ledger you can use
332    /// "Did::get_ver_key" call instead that will look only to the local wallet and skip
333    /// freshness checking.
334    ///
335    /// Note that "Did::new" makes similar wallet record as "Key::create".
336    /// As result we can use returned ver key in all generic crypto and messaging functions.
337    ///
338    /// # Arguments
339    /// * `pool_handle` - Pool handle (created by Pool::open).
340    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
341    /// * `did` - The DID to resolve key.
342    ///
343    /// # Returns
344    /// * `key` - The DIDs ver key (key id).
345    pub fn get_ver_key(pool_handle: IndyHandle, wallet_handle: IndyHandle, did: &str) -> Result<String, ErrorCode> {
346        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
347
348        let err = Did::_get_ver_key(command_handle, pool_handle, wallet_handle, did, cb);
349
350        ResultHandler::one(err, receiver)
351    }
352
353    /// Returns ver key (key id) for the given DID.
354    ///
355    /// "Did::get_ver_key" call follow the idea that we resolve information about their DID from
356    /// the ledger with cache in the local wallet. The "indy_Wallet::open" call has freshness parameter
357    /// that is used for checking the freshness of cached pool value.
358    ///
359    /// Note if you don't want to resolve their DID info from the ledger you can use
360    /// "Did::get_ver_key" call instead that will look only to the local wallet and skip
361    /// freshness checking.
362    ///
363    /// Note that "Did::new" makes similar wallet record as "Key::create".
364    /// As result we can use returned ver key in all generic crypto and messaging functions.
365    ///
366    /// # Arguments
367    /// * `pool_handle` - Pool handle (created by Pool::open).
368    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
369    /// * `did` - The DID to resolve key.
370    /// * `timeout` - the maximum time this function waits for a response
371    ///
372    /// # Returns
373    /// * `key` - The DIDs ver key (key id).
374    pub fn get_ver_key_timeout(pool_handle: IndyHandle, wallet_handle: IndyHandle, did: &str, timeout: Duration) -> Result<String, ErrorCode> {
375        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
376
377        let err = Did::_get_ver_key(command_handle, pool_handle, wallet_handle, did, cb);
378
379        ResultHandler::one_timeout(err, receiver, timeout)
380    }
381
382    /// Returns ver key (key id) for the given DID.
383    ///
384    /// "Did::get_ver_key" call follow the idea that we resolve information about their DID from
385    /// the ledger with cache in the local wallet. The "indy_Wallet::open" call has freshness parameter
386    /// that is used for checking the freshness of cached pool value.
387    ///
388    /// Note if you don't want to resolve their DID info from the ledger you can use
389    /// "Did::get_ver_key" call instead that will look only to the local wallet and skip
390    /// freshness checking.
391    ///
392    /// Note that "Did::new" makes similar wallet record as "Key::create".
393    /// As result we can use returned ver key in all generic crypto and messaging functions.
394    ///
395    /// # Arguments
396    /// * `pool_handle` - Pool handle (created by Pool::open).
397    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
398    /// * `did` - The DID to resolve key.
399    /// * `closure` - the closure that is called when finished
400    ///
401    /// # Returns
402    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
403    pub fn get_ver_key_async<F: 'static>(pool_handle: IndyHandle, wallet_handle: IndyHandle, did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
404        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
405
406        Did::_get_ver_key(command_handle, pool_handle, wallet_handle, did, cb)
407    }
408    
409    fn _get_ver_key(command_handle: IndyHandle, pool_handle: IndyHandle, wallet_handle: IndyHandle, did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
410        let did = c_str!(did);
411
412        ErrorCode::from(unsafe { did::indy_key_for_did(command_handle, pool_handle, wallet_handle, did.as_ptr(), cb) })
413    }
414
415    /// Returns ver key (key id) for the given DID.
416    ///
417    /// "Did::get_ver_key_did" call looks data stored in the local wallet only and skips freshness
418    /// checking.
419    ///
420    /// Note if you want to get fresh data from the ledger you can use "Did::get_ver_key" call
421    /// instead.
422    ///
423    /// Note that "Did::new" makes similar wallet record as "Key::create".
424    /// As result we can use returned ver key in all generic crypto and messaging functions.
425    ///
426    /// # Arguments
427    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
428    /// * `did` - The DID to resolve key.
429    ///
430    /// # Returns
431    /// * `key` - The DIDs ver key (key id).
432    pub fn get_ver_key_local(wallet_handle: IndyHandle, did: &str) -> Result<String, ErrorCode> {
433        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
434
435        let err = Did::_get_ver_key_local(command_handle, wallet_handle, did, cb);
436
437        ResultHandler::one(err, receiver)
438    }
439
440    /// Returns ver key (key id) for the given DID.
441    ///
442    /// "Did::get_ver_key_did" call looks data stored in the local wallet only and skips freshness
443    /// checking.
444    ///
445    /// Note if you want to get fresh data from the ledger you can use "Did::get_ver_key" call
446    /// instead.
447    ///
448    /// Note that "Did::new" makes similar wallet record as "Key::create".
449    /// As result we can use returned ver key in all generic crypto and messaging functions.
450    ///
451    /// # Arguments
452    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
453    /// * `did` - The DID to resolve key.
454    /// * `timeout` - the maximum time this function waits for a response
455    ///
456    /// # Returns
457    /// * `key` - The DIDs ver key (key id).
458    pub fn get_ver_key_local_timeout(wallet_handle: IndyHandle, did: &str, timeout: Duration) -> Result<String, ErrorCode> {
459        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
460
461        let err = Did::_get_ver_key_local(command_handle, wallet_handle, did, cb);
462
463        ResultHandler::one_timeout(err, receiver, timeout)
464    }
465
466    /// Returns ver key (key id) for the given DID.
467    ///
468    /// "Did::get_ver_key_did" call looks data stored in the local wallet only and skips freshness
469    /// checking.
470    ///
471    /// Note if you want to get fresh data from the ledger you can use "Did::get_ver_key" call
472    /// instead.
473    ///
474    /// Note that "Did::new" makes similar wallet record as "Key::create".
475    /// As result we can use returned ver key in all generic crypto and messaging functions.
476    ///
477    /// # Arguments
478    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
479    /// * `did` - The DID to resolve key.
480    /// * `closure` - the closure that is called when finished
481    ///
482    /// # Returns
483    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
484    pub fn get_ver_key_local_async<F: 'static>(wallet_handle: IndyHandle, did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
485        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
486
487        Did::_get_ver_key_local(command_handle, wallet_handle, did, cb)
488    }
489    
490    fn _get_ver_key_local(command_handle: IndyHandle, wallet_handle: IndyHandle, did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
491        let did = c_str!(did);
492
493        ErrorCode::from(unsafe { did::indy_key_for_local_did(command_handle, wallet_handle, did.as_ptr(), cb) })
494    }
495
496    /// Set/replaces endpoint information for the given DID.
497    ///
498    /// # Arguments
499    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
500    /// * `did` - The DID to resolve endpoint.
501    /// * `address` -  The DIDs endpoint address.
502    /// * `transport_key` - The DIDs transport key (ver key, key id).
503    pub fn set_endpoint(wallet_handle: IndyHandle, did: &str, address: &str, transport_key: &str) -> Result<(), ErrorCode> {
504        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
505
506        let err = Did::_set_endpoint(command_handle, wallet_handle, did, address, transport_key, cb);
507
508        ResultHandler::empty(err, receiver)
509    }
510
511    /// Set/replaces endpoint information for the given DID.
512    ///
513    /// # Arguments
514    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
515    /// * `did` - The DID to resolve endpoint.
516    /// * `address` -  The DIDs endpoint address.
517    /// * `transport_key` - The DIDs transport key (ver key, key id).
518    /// * `timeout` - the maximum time this function waits for a response
519    pub fn set_endpoint_timeout(wallet_handle: IndyHandle, did: &str, address: &str, transport_key: &str, timeout: Duration) -> Result<(), ErrorCode> {
520        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
521
522        let err = Did::_set_endpoint(command_handle, wallet_handle, did, address, transport_key, cb);
523
524        ResultHandler::empty_timeout(err, receiver, timeout)
525    }
526
527    /// Set/replaces endpoint information for the given DID.
528    ///
529    /// # Arguments
530    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
531    /// * `did` - The DID to resolve endpoint.
532    /// * `address` -  The DIDs endpoint address.
533    /// * `transport_key` - The DIDs transport key (ver key, key id).
534    /// * `closure` - the closure that is called when finished
535    ///
536    /// # Returns
537    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
538    pub fn set_endpoint_async<F: 'static>(wallet_handle: IndyHandle, did: &str, address: &str, transport_key: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
539        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
540
541        Did::_set_endpoint(command_handle, wallet_handle, did, address, transport_key, cb)
542    }
543    
544    fn _set_endpoint(command_handle: IndyHandle, wallet_handle: IndyHandle, did: &str, address: &str, transport_key: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
545        let did = c_str!(did);
546        let address = c_str!(address);
547        let transport_key = c_str!(transport_key);
548
549        ErrorCode::from(unsafe { did::indy_set_endpoint_for_did(command_handle, wallet_handle, did.as_ptr(), address.as_ptr(), transport_key.as_ptr(), cb) })
550    }
551
552    /// Returns endpoint information for the given DID.
553    ///
554    /// # Arguments
555    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
556    /// * `did` - The DID to resolve endpoint.
557    ///
558    /// # Returns
559    /// * `endpoint` - The DIDs endpoint.
560    /// * `transport_vk` - The DIDs transport key (ver key, key id).
561    pub fn get_endpoint(wallet_handle: IndyHandle, pool_handle: IndyHandle, did: &str) -> Result<(String, Option<String>), ErrorCode> {
562        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_opt_string();
563
564        let err = Did::_get_endpoint(command_handle, wallet_handle, pool_handle, did, cb);
565
566        ResultHandler::two(err, receiver)
567    }
568
569    /// Returns endpoint information for the given DID.
570    ///
571    /// # Arguments
572    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
573    /// * `did` - The DID to resolve endpoint.
574    /// * `timeout` - the maximum time this function waits for a response
575    ///
576    /// # Returns
577    /// * `endpoint` - The DIDs endpoint.
578    /// * `transport_vk` - The DIDs transport key (ver key, key id).
579    pub fn get_endpoint_timeout(wallet_handle: IndyHandle, pool_handle: IndyHandle, did: &str, timeout: Duration) -> Result<(String, Option<String>), ErrorCode> {
580        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_opt_string();
581
582        let err = Did::_get_endpoint(command_handle, wallet_handle, pool_handle, did, cb);
583
584        ResultHandler::two_timeout(err, receiver, timeout)
585    }
586
587    /// Returns endpoint information for the given DID.
588    ///
589    /// # Arguments
590    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
591    /// * `did` - The DID to resolve endpoint.
592    /// * `closure` - the closure that is called when finished
593    ///
594    /// # Returns
595    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
596    pub fn get_endpoint_async<F: 'static>(wallet_handle: IndyHandle, pool_handle: IndyHandle, did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, Option<String>) + Send {
597        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_opt_string(Box::new(closure));
598
599        Did::_get_endpoint(command_handle, wallet_handle, pool_handle, did, cb)
600    }
601    
602    fn _get_endpoint(command_handle: IndyHandle, wallet_handle: IndyHandle, pool_handle: IndyHandle, did: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
603        let did = c_str!(did);
604
605        ErrorCode::from(unsafe { did::indy_get_endpoint_for_did(command_handle, wallet_handle, pool_handle, did.as_ptr(), cb) })
606    }
607
608    /// Saves/replaces the meta information for the giving DID in the wallet.
609    ///
610    /// # Arguments
611    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
612    /// * `did` - the DID to store metadata.
613    /// * `metadata`  - the meta information that will be store with the DID.
614    pub fn set_metadata(wallet_handle: IndyHandle, tgt_did: &str, metadata: &str) -> Result<(), ErrorCode> {
615        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
616
617        let err = Did::_set_metadata(command_handle, wallet_handle, tgt_did, metadata, cb);
618
619        ResultHandler::empty(err, receiver)
620    }
621
622    /// Saves/replaces the meta information for the giving DID in the wallet.
623    ///
624    /// # Arguments
625    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
626    /// * `did` - the DID to store metadata.
627    /// * `metadata`  - the meta information that will be store with the DID.
628    /// * `timeout` - the maximum time this function waits for a response
629    pub fn set_metadata_timeout(wallet_handle: IndyHandle, tgt_did: &str, metadata: &str, timeout: Duration) -> Result<(), ErrorCode> {
630        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
631
632        let err = Did::_set_metadata(command_handle, wallet_handle, tgt_did, metadata, cb);
633
634        ResultHandler::empty_timeout(err, receiver, timeout)
635    }
636
637    /// Saves/replaces the meta information for the giving DID in the wallet.
638    ///
639    /// # Arguments
640    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
641    /// * `did` - the DID to store metadata.
642    /// * `metadata`  - the meta information that will be store with the DID.
643    /// * `closure` - the closure that is called when finished
644    ///
645    /// # Returns
646    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
647    pub fn set_metadata_async<F: 'static>(wallet_handle: IndyHandle, tgt_did: &str, metadata: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
648        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
649
650        Did::_set_metadata(command_handle, wallet_handle, tgt_did, metadata, cb)
651    }
652    
653    fn _set_metadata(command_handle: IndyHandle, wallet_handle: IndyHandle, tgt_did: &str, metadata: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
654        let tgt_did = c_str!(tgt_did);
655        let metadata = c_str!(metadata);
656
657        ErrorCode::from(unsafe { did::indy_set_did_metadata(command_handle, wallet_handle, tgt_did.as_ptr(), metadata.as_ptr(), cb) })
658    }
659
660    /// Retrieves the meta information for the giving DID in the wallet.
661    ///
662    /// # Arguments
663    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
664    /// * `did`  - The DID to retrieve metadata.
665    ///
666    /// #Returns
667    /// * `metadata`  - The meta information stored with the DID; Can be null if no metadata was saved for this DID.
668    pub fn get_metadata(wallet_handle: IndyHandle, tgt_did: &str) -> Result<String, ErrorCode> {
669        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
670
671        let err = Did::_get_metadata(command_handle, wallet_handle, tgt_did, cb);
672
673        ResultHandler::one(err, receiver)
674    }
675
676    /// Retrieves the meta information for the giving DID in the wallet.
677    ///
678    /// # Arguments
679    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
680    /// * `did`  - The DID to retrieve metadata.
681    /// * `timeout` - the maximum time this function waits for a response
682    ///
683    /// #Returns
684    /// * `metadata`  - The meta information stored with the DID; Can be null if no metadata was saved for this DID.
685    pub fn get_metadata_timeout(wallet_handle: IndyHandle, tgt_did: &str, timeout: Duration) -> Result<String, ErrorCode> {
686        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
687
688        let err = Did::_get_metadata(command_handle, wallet_handle, tgt_did, cb);
689
690        ResultHandler::one_timeout(err, receiver, timeout)
691    }
692
693    /// Retrieves the meta information for the giving DID in the wallet.
694    ///
695    /// # Arguments
696    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
697    /// * `did`  - The DID to retrieve metadata.
698    /// * `closure` - the closure that is called when finished
699    ///
700    /// # Returns
701    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
702    pub fn get_metadata_async<F: 'static>(wallet_handle: IndyHandle, tgt_did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
703        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
704
705        Did::_get_metadata(command_handle, wallet_handle, tgt_did, cb)
706    }
707    
708    fn _get_metadata(command_handle: IndyHandle, wallet_handle: IndyHandle, tgt_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
709        let tgt_did = c_str!(tgt_did);
710
711        ErrorCode::from(unsafe { did::indy_get_did_metadata(command_handle, wallet_handle, tgt_did.as_ptr(), cb) })
712    }
713
714    /// Retrieves the information about the giving DID in the wallet.
715    ///
716    /// # Arguments
717    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
718    /// * `did` - The DID to retrieve information.
719    ///
720    /// # Returns
721    ///  * `did_with_meta` -  {
722    ///     "did": string - DID stored in the wallet,
723    ///     "verkey": string - The DIDs transport key (ver key, key id),
724    ///     "metadata": string - The meta information stored with the DID
725    ///   }
726    pub fn get_my_metadata(wallet_handle: IndyHandle, my_did: &str) -> Result<String, ErrorCode> {
727        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
728
729        let err = Did::_get_my_metadata(command_handle, wallet_handle, my_did, cb);
730
731        ResultHandler::one(err, receiver)
732    }
733
734    /// Retrieves the information about the giving DID in the wallet.
735    ///
736    /// # Arguments
737    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
738    /// * `did` - The DID to retrieve information.
739    /// * `timeout` - the maximum time this function waits for a response
740    ///
741    /// # Returns
742    ///  * `did_with_meta` -  {
743    ///     "did": string - DID stored in the wallet,
744    ///     "verkey": string - The DIDs transport key (ver key, key id),
745    ///     "metadata": string - The meta information stored with the DID
746    ///   }
747    pub fn get_my_metadata_timeout(wallet_handle: IndyHandle, my_did: &str, timeout: Duration) -> Result<String, ErrorCode> {
748        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
749
750        let err = Did::_get_my_metadata(command_handle, wallet_handle, my_did, cb);
751
752        ResultHandler::one_timeout(err, receiver, timeout)
753    }
754
755    /// Retrieves the information about the giving DID in the wallet.
756    ///
757    /// # Arguments
758    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
759    /// * `did` - The DID to retrieve information.
760    /// * `closure` - the closure that is called when finished
761    ///
762    /// # Returns
763    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
764    pub fn get_my_metadata_async<F: 'static>(wallet_handle: IndyHandle, my_did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
765        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
766
767        Did::_get_my_metadata(command_handle, wallet_handle, my_did, cb)
768    }
769    
770    fn _get_my_metadata(command_handle: IndyHandle, wallet_handle: IndyHandle, my_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
771        let my_did = c_str!(my_did);
772
773        ErrorCode::from(unsafe { did::indy_get_my_did_with_meta(command_handle, wallet_handle, my_did.as_ptr(), cb) })
774    }
775
776    /// Retrieves the information about all DIDs stored in the wallet.
777    ///
778    /// # Arguments
779    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
780    ///
781    /// # Returns
782    ///  * `dids` - [{
783    ///     "did": string - DID stored in the wallet,
784    ///     "verkey": string - The DIDs transport key (ver key, key id).,
785    ///     "metadata": string - The meta information stored with the DID
786    ///   }]
787    pub fn list_with_metadata(wallet_handle: IndyHandle) -> Result<String, ErrorCode> {
788        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
789
790        let err = Did::_list_with_metadata(command_handle, wallet_handle, cb);
791
792        ResultHandler::one(err, receiver)
793    }
794
795    /// Retrieves the information about all DIDs stored in the wallet.
796    ///
797    /// # Arguments
798    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
799    /// * `timeout` - the maximum time this function waits for a response
800    ///
801    /// # Returns
802    ///  * `dids` - [{
803    ///     "did": string - DID stored in the wallet,
804    ///     "verkey": string - The DIDs transport key (ver key, key id).,
805    ///     "metadata": string - The meta information stored with the DID
806    ///   }]
807    pub fn list_with_metadata_timeout(wallet_handle: IndyHandle, timeout: Duration) -> Result<String, ErrorCode> {
808        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
809
810        let err = Did::_list_with_metadata(command_handle, wallet_handle, cb);
811
812        ResultHandler::one_timeout(err, receiver, timeout)
813    }
814
815    /// Retrieves the information about all DIDs stored in the wallet.
816    ///
817    /// # Arguments
818    /// * `wallet_handle` - Wallet handle (created by Wallet::open).
819    /// * `closure` - the closure that is called when finished
820    ///
821    /// # Returns
822    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
823    pub fn list_with_metadata_async<F: 'static>(wallet_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
824        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
825
826        Did::_list_with_metadata(command_handle, wallet_handle, cb)
827    }
828    
829    fn _list_with_metadata(command_handle: IndyHandle, wallet_handle: IndyHandle, cb: Option<ResponseStringCB>) -> ErrorCode {
830        ErrorCode::from(unsafe { did::indy_list_my_dids_with_meta(command_handle, wallet_handle, cb) })
831    }
832
833    /// Retrieves abbreviated verkey if it is possible otherwise return full verkey.
834    ///
835    /// # Arguments
836    /// * `tgt_did` - DID.
837    /// * `full_verkey` - The DIDs verification key,
838    ///
839    /// #Returns
840    ///  * `verkey` - The DIDs verification key in either abbreviated or full form
841    pub fn abbreviate_verkey(tgt_did: &str, verkey: &str) -> Result<String, ErrorCode> {
842        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
843
844        let err = Did::_abbreviate_verkey(command_handle, tgt_did, verkey, cb);
845
846        ResultHandler::one(err, receiver)
847    }
848
849    /// Retrieves abbreviated verkey if it is possible otherwise return full verkey.
850    ///
851    /// # Arguments
852    /// * `tgt_did` - DID.
853    /// * `full_verkey` - The DIDs verification key,
854    /// * `timeout` - the maximum time this function waits for a response
855    ///
856    /// #Returns
857    ///  * `verkey` - The DIDs verification key in either abbreviated or full form
858    pub fn abbreviate_verkey_timeout(tgt_did: &str, verkey: &str, timeout: Duration) -> Result<String, ErrorCode> {
859        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
860
861        let err = Did::_abbreviate_verkey(command_handle, tgt_did, verkey, cb);
862
863        ResultHandler::one_timeout(err, receiver, timeout)
864    }
865
866    /// Retrieves abbreviated verkey if it is possible otherwise return full verkey.
867    ///
868    /// # Arguments
869    /// * `tgt_did` - DID.
870    /// * `full_verkey` - The DIDs verification key,
871    /// * `closure` - the closure that is called when finished
872    ///
873    /// # Returns
874    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
875    pub fn abbreviate_verkey_async<F: 'static>(tgt_did: &str, verkey: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
876        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
877
878        Did::_abbreviate_verkey(command_handle, tgt_did, verkey, cb)
879    }
880    
881    fn _abbreviate_verkey(command_handle: IndyHandle, tgt_did: &str, verkey: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
882        let tgt_did = c_str!(tgt_did);
883        let verkey = c_str!(verkey);
884
885        ErrorCode::from(unsafe { did::indy_abbreviate_verkey(command_handle, tgt_did.as_ptr(), verkey.as_ptr(), cb) })
886    }
887}