Skip to content

Commit

Permalink
Merge pull request #1 from Artemkaaas/feature/wallet-cluster
Browse files Browse the repository at this point in the history
Updated Java wrapper to satisfy new Wallet API
  • Loading branch information
Vyacheslav authored Jul 2, 2018
2 parents 56d0908 + 0780a2b commit 5ec5dbb
Show file tree
Hide file tree
Showing 20 changed files with 264 additions and 188 deletions.
2 changes: 1 addition & 1 deletion libindy/src/services/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl WalletService {
if let Some(rekey) = credentials.rekey {
let metadata = {
let master_key_salt = encryption::gen_master_key_salt()?;
let master_key = encryption::derive_master_key(&credentials.key, &master_key_salt)?;
let master_key = encryption::derive_master_key(&rekey, &master_key_salt)?;

let metadata = Metadata {
master_key_salt: master_key_salt[..].to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion libindy/src/services/wallet/storage/default/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl WalletStorageType for SQLiteStorageType {
let db_file_path = SQLiteStorageType::_db_path(id);

if db_file_path.exists() {
std::fs::remove_file(db_file_path.parent().unwrap())?;
std::fs::remove_dir_all(db_file_path.parent().unwrap())?;
Ok(())
} else {
Err(WalletStorageError::NotFound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public int indy_register_wallet_storage(int command_handle, String type, Callbac
Callback get_record, Callback get_record_id, Callback get_record_type, Callback get_record_value,
Callback get_record_tags, Callback free_record, Callback search_records, Callback search_all_records,
Callback get_search_total_count, Callback fetch_search_next_record, Callback free_search, Callback cb);
public int indy_create_wallet(int command_handle, String pool_name, String name, String xtype, String config, String credentials, Callback cb);
public int indy_open_wallet(int command_handle, String name, String runtime_config, String credentials, Callback cb);
public int indy_create_wallet(int command_handle, String config, String credentials, Callback cb);
public int indy_open_wallet(int command_handle, String config, String credentials, Callback cb);
public int indy_close_wallet(int command_handle, int handle, Callback cb);
public int indy_delete_wallet(int command_handle, String name, String credentials, Callback cb);
public int indy_delete_wallet(int command_handle, String config, String credentials, Callback cb);
public int indy_export_wallet(int command_handle, int handle, String exportConfigJson, Callback cb);
public int indy_import_wallet(int command_handle, String pool_name, String name, String xtype, String config, String credentials, String importConfigJson, Callback cb);
public int indy_import_wallet(int command_handle, String config, String credentials, String importConfigJson, Callback cb);

// ledger.rs

Expand Down
154 changes: 104 additions & 50 deletions wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,42 @@ public static CompletableFuture<Void> registerWalletType(
/**
* Creates a new secure wallet with the given unique name.
*
* @param poolName Name of the pool that corresponds to this wallet.
* @param name Name of the wallet.
* @param xtype Type of the wallet. Defaults to 'default'.
* @param config Wallet configuration json. List of supported keys are defined by wallet type.
* @param credentials Wallet credentials json: {
* "key": <string>
* @param config Wallet configuration json.
* {
* "id": string, Identifier of the wallet.
* Configured storage uses this identifier to lookup exact wallet data placement.
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
* 'Default' storage type allows to store wallet data in the local file.
* Custom storage types can be registered with indy_register_wallet_storage call.
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type configuration is:
* {
* "path": optional<string>, Path to the directory with wallet files.
* Defaults to $HOME/.indy_client/wallets.
* Wallet will be stored in the file {path}/{id}/sqlite.db
* }
* }
* @param credentials Wallet credentials json
* {
* "key": string, Passphrase used to derive wallet master key
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type should be empty.
*
* }
* @return A future that resolves no value.
* @throws IndyException Thrown if a call to the underlying SDK fails.
*/
public static CompletableFuture<Void> createWallet(
String poolName,
String name,
String xtype,
String config,
String credentials) throws IndyException {

ParamGuard.notNullOrWhiteSpace(poolName, "poolName");
ParamGuard.notNullOrWhiteSpace(name, "name");

CompletableFuture<Void> future = new CompletableFuture<Void>();
int commandHandle = addFuture(future);

int result = LibIndy.api.indy_create_wallet(
commandHandle,
poolName,
name,
xtype,
config,
credentials,
voidCb);
Expand All @@ -177,28 +185,46 @@ public static CompletableFuture<Void> createWallet(
/**
* Opens the wallet with specific name.
*
* @param name Name of the wallet.
* @param runtimeConfig Runtime wallet configuration json. if NULL, then default runtime_config will be used.
* @param credentials Wallet credentials json: {
* "key": <string>
* @param config Wallet configuration json.
* {
* "id": string, Identifier of the wallet.
* Configured storage uses this identifier to lookup exact wallet data placement.
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
* 'Default' storage type allows to store wallet data in the local file.
* Custom storage types can be registered with indy_register_wallet_storage call.
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type configuration is:
* {
* "path": optional<string>, Path to the directory with wallet files.
* Defaults to $HOME/.indy_client/wallets.
* Wallet will be stored in the file {path}/{id}/sqlite.db
* }
* }
* @param credentials Wallet credentials json
* {
* "key": string, Passphrase used to derive current wallet master key
* "rekey": optional<string>, If present than wallet master key will be rotated to a new one
* derived from this passphrase.
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type should be empty.
*
* }
* @return A future that resolves no value.
* @throws IndyException Thrown if a call to the underlying SDK fails.
*/
public static CompletableFuture<Wallet> openWallet(
String name,
String runtimeConfig,
String config,
String credentials) throws IndyException {

ParamGuard.notNullOrWhiteSpace(name, "name");

CompletableFuture<Wallet> future = new CompletableFuture<Wallet>();
int commandHandle = addFuture(future);

int result = LibIndy.api.indy_open_wallet(
commandHandle,
name,
runtimeConfig,
config,
credentials,
openWalletCb);

Expand Down Expand Up @@ -237,25 +263,46 @@ private static CompletableFuture<Void> closeWallet(
/**
* Deletes an existing wallet.
*
* @param name Name of the wallet to delete.
* @param credentials Wallet credentials json: {
* "key": <string>
* @param config Wallet configuration json.
* {
* "id": string, Identifier of the wallet.
* Configured storage uses this identifier to lookup exact wallet data placement.
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
* 'Default' storage type allows to store wallet data in the local file.
* Custom storage types can be registered with indy_register_wallet_storage call.
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type configuration is:
* {
* "path": optional<string>, Path to the directory with wallet files.
* Defaults to $HOME/.indy_client/wallets.
* Wallet will be stored in the file {path}/{id}/sqlite.db
* }
* }
* @param credentials Wallet credentials json
* {
* "key": string, Passphrase used to derive current wallet master key
* "rekey": optional<string>, If present than wallet master key will be rotated to a new one
* derived from this passphrase.
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type should be empty.
*
* }
*
* @return A future that resolves no value.
* @throws IndyException Thrown if a call to the underlying SDK fails.
*/
public static CompletableFuture<Void> deleteWallet(
String name,
String config,
String credentials) throws IndyException {

ParamGuard.notNullOrWhiteSpace(name, "name");

CompletableFuture<Void> future = new CompletableFuture<Void>();
int commandHandle = addFuture(future);

int result = LibIndy.api.indy_delete_wallet(
commandHandle,
name,
config,
credentials,
voidCb);

Expand All @@ -272,8 +319,8 @@ public static CompletableFuture<Void> deleteWallet(
* @param wallet The wallet to export.
* @param exportConfigJson: JSON containing settings for input operation.
* {
* "path": path of the file that contains exported wallet content
* "key": passphrase used to export key
* "path": <string>, Path of the file that contains exported wallet content
* "key": <string>, Passphrase used to derive export key
* }
* @return A future that resolves no value.
* @throws IndyException Thrown if a call to the underlying SDK fails.
Expand Down Expand Up @@ -308,40 +355,47 @@ public static CompletableFuture<Void> exportWallet(
*
* Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
* the future releases.
* @param poolName Name of the pool that corresponds to this wallet.
* @param name Name of the wallet.
* @param xtype Type of the wallet. Defaults to 'default'.
*
* @param config Wallet configuration json. List of supported keys are defined by wallet type.
* @param credentials Wallet credentials json: {
* "key": <string>
* }
* @param importConfigJson JSON containing settings for input operation: {
* "path": path of the file that contains exported wallet content
* "key": passphrase used to export key
* @param credentials Wallet configuration json.
* {
* "id": string, Identifier of the wallet.
* Configured storage uses this identifier to lookup exact wallet data placement.
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
* 'Default' storage type allows to store wallet data in the local file.
* Custom storage types can be registered with indy_register_wallet_storage call.
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type configuration is:
* {
* "path": optional<string>, Path to the directory with wallet files.
* Defaults to $HOME/.indy_client/wallets.
* Wallet will be stored in the file {path}/{id}/sqlite.db
* }
* }
* @param importConfigJson Wallet credentials json
* {
* "key": string, Passphrase used to derive wallet master key
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
* Can be optional if storage supports default configuration.
* For 'default' storage type should be empty.
*
* }
* @return A future that resolves no value.
* @throws IndyException Thrown if a call to the underlying SDK fails.
*/
public static CompletableFuture<Void> importWallet(
String poolName,
String name,
String xtype,
String config,
String credentials,
String importConfigJson) throws IndyException {

ParamGuard.notNullOrWhiteSpace(poolName, "poolName");
ParamGuard.notNullOrWhiteSpace(name, "name");
ParamGuard.notNull(importConfigJson, "importConfigJson");

CompletableFuture<Void> future = new CompletableFuture<Void>();
int commandHandle = addFuture(future);

int result = LibIndy.api.indy_import_wallet(
commandHandle,
poolName,
name,
xtype,
config,
credentials,
importConfigJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.hyperledger.indy.sdk.did.DidJSONParameters;
import org.hyperledger.indy.sdk.utils.InitHelper;
import org.hyperledger.indy.sdk.utils.StorageUtils;
import org.hyperledger.indy.sdk.wallet.InMemWalletType;
import org.hyperledger.indy.sdk.wallet.Wallet;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -66,7 +64,21 @@ public class IndyIntegrationTest {
" \"height\": {\"raw\": \"175\", \"encoded\": \"175\"},\n" +
" \"age\": {\"raw\": \"28\", \"encoded\": \"28\"}\n" +
" }";
protected String CREDENTIALS = "{\"key\": \"key\"}";
protected static final String WALLET_CONFIG =
new JSONObject()
.put("id", WALLET)
.put("storage_type", TYPE)
.toString();
protected static final String WALLET_CREDENTIALS =
new JSONObject()
.put("key", "key")
.toString();
protected static final String PLUGGED_WALLET_CONFIG =
new JSONObject()
.put("id", WALLET)
.put("storage_type", "unknown_type")
.toString();

protected int PROTOCOL_VERSION = 2;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public void createPoolAndWallet() throws Exception {
String poolName = PoolUtils.createPoolLedgerConfig();
pool = Pool.openPoolLedger(poolName, null).get();

Wallet.createWallet(poolName, WALLET, TYPE, null, CREDENTIALS).get();
this.wallet = Wallet.openWallet(WALLET, null, CREDENTIALS).get();
Wallet.createWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
this.wallet = Wallet.openWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
}

@After
public void deletePoolAndWallet() throws Exception {
pool.closePoolLedger().get();
wallet.closeWallet().get();
Wallet.deleteWallet(WALLET, CREDENTIALS).get();
Wallet.deleteWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
}

protected void checkResponseType(String response, String expectedType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class IndyIntegrationTestWithSingleWallet extends IndyIntegrationTest {

@Before
public void createWallet() throws Exception {
Wallet.createWallet(POOL, WALLET, TYPE, null, CREDENTIALS).get();
this.wallet = Wallet.openWallet(WALLET, null, CREDENTIALS).get();
Wallet.createWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
this.wallet = Wallet.openWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
}

@After
public void deleteWallet() throws Exception {
wallet.closeWallet().get();
Wallet.deleteWallet(WALLET, CREDENTIALS).get();
Wallet.deleteWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ private void initCommonWallet() throws Exception {

StorageUtils.cleanupStorage();

String walletName = "anoncredsCommonWallet";
String walletConfig =
new JSONObject()
.put("id", "anoncredsCommonWallet")
.toString();

Wallet.createWallet("default", walletName, "default", null, CREDENTIALS).get();
wallet = Wallet.openWallet(walletName, null, CREDENTIALS).get();
Wallet.createWallet(walletConfig, CREDENTIALS).get();
wallet = Wallet.openWallet(walletConfig, CREDENTIALS).get();

AnoncredsResults.IssuerCreateSchemaResult createSchemaResult =
Anoncreds.issuerCreateSchema(issuerDid, gvtSchemaName, schemaVersion, gvtSchemaAttributes).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class IssuerRevokeCredentialTest extends AnoncredsIntegrationTest {
@Test
public void testIssuerRevokeProofWorks() throws Exception {
// Create wallet, get wallet handle
String walletName = "revocationWallet";
Wallet.createWallet("default", walletName, "default", null, CREDENTIALS).get();
Wallet wallet = Wallet.openWallet(walletName, null, CREDENTIALS).get();
String walletConfig = new JSONObject().put("id", "revocationWallet").toString();
Wallet.createWallet(walletConfig, CREDENTIALS).get();
Wallet wallet = Wallet.openWallet(walletConfig, CREDENTIALS).get();

// Issuer create Schema
AnoncredsResults.IssuerCreateSchemaResult createSchemaResult = Anoncreds.issuerCreateSchema(issuerDid, gvtSchemaName, schemaVersion, gvtSchemaAttributes).get();
Expand Down Expand Up @@ -108,6 +108,6 @@ public void testIssuerRevokeProofWorks() throws Exception {

// Close and Delete Wallet
wallet.closeWallet().get();
Wallet.deleteWallet(walletName, CREDENTIALS).get();
Wallet.deleteWallet(walletConfig, CREDENTIALS).get();
}
}
Loading

0 comments on commit 5ec5dbb

Please sign in to comment.