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