Shamir secret API (indy-crypto and indy-sdk)¶
Objective: indy-crypto exposes the low level API for generating and reconstructing secrets. indy-sdk uses the underlying indy-crypto and exposes an API to shard a JSON message, store the shards and reconstitute the secret.
Indy-crypto¶
shard_secret(secret: bytes, m: u8, n: u8, sign_shares: Option<bool>) -> Result<Vec<Share>, IndyCryptoError>.Splits the bytes of the secretsecretinndifferent shares andm-of-nshares are required to reconstitute the secret.sign_sharesif provided, all shards are signed.recover_secret(shards: Vec<Share>, verify_signatures: Option<bool>) -> Result<Vec<u8>, IndyCryptoError>.Recover the secret from the givenshards.verify_signaturesif given verifies the signatures.
Indy-sdk¶
shard_JSON(msg: String, m: u8, n: u8, sign_shares: Option<bool>) -> Result<Vec<String>, IndyError>Takes the message as a JSON string and serialises it to bytes and passes it toshard_secretofindy-crypto. The serialisation has to be deterministic, i.e the same JSON should always serialise to same bytes everytime. The resultingSharegiven byindy-cryptois converted to JSON before returning.shard_JSON_with_wallet_data(wallet_handle: i32, msg: String, wallet_keys:Vec<&str>, m: u8, n: u8, sign_shares: Option<bool>) -> Result<Vec<String>, IndyError>Takes the message as a JSON string, updates the JSON with key-values from wallet given by handlewallet_handle, keys present in the vectorwallet_keysand passes the resulting JSON toshard_JSON.recover_secret(shards: Vec<String>, verify_signatures: Option<bool>) -> Result<String, IndyError>Takes a collection of shards each encoded as JSON, deserialises them intoShares and passes them torecover_secretfromindy-crypto. It converts the resulting secret back to JSON before returning it.shard_JSON_and_store_shards(wallet_handle: i32, msg: String, m: u8, n: u8, sign_shares: Option<bool>) -> Result<String, IndyError>Shards the given JSON usingshard_JSONand store shards as a JSON array (each shard is an object in itself) in the wallet given bywallet_handle. Returns the wallet key used to store the shards.