Skip to content

Commit 5ec5dbb

Browse files
author
Vyacheslav
authored
Merge pull request #1 from Artemkaaas/feature/wallet-cluster
Updated Java wrapper to satisfy new Wallet API
2 parents 56d0908 + 0780a2b commit 5ec5dbb

20 files changed

+264
-188
lines changed

libindy/src/services/wallet/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl WalletService {
257257
if let Some(rekey) = credentials.rekey {
258258
let metadata = {
259259
let master_key_salt = encryption::gen_master_key_salt()?;
260-
let master_key = encryption::derive_master_key(&credentials.key, &master_key_salt)?;
260+
let master_key = encryption::derive_master_key(&rekey, &master_key_salt)?;
261261

262262
let metadata = Metadata {
263263
master_key_salt: master_key_salt[..].to_vec(),

libindy/src/services/wallet/storage/default/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ impl WalletStorageType for SQLiteStorageType {
631631
let db_file_path = SQLiteStorageType::_db_path(id);
632632

633633
if db_file_path.exists() {
634-
std::fs::remove_file(db_file_path.parent().unwrap())?;
634+
std::fs::remove_dir_all(db_file_path.parent().unwrap())?;
635635
Ok(())
636636
} else {
637637
Err(WalletStorageError::NotFound)

wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public int indy_register_wallet_storage(int command_handle, String type, Callbac
3737
Callback get_record, Callback get_record_id, Callback get_record_type, Callback get_record_value,
3838
Callback get_record_tags, Callback free_record, Callback search_records, Callback search_all_records,
3939
Callback get_search_total_count, Callback fetch_search_next_record, Callback free_search, Callback cb);
40-
public int indy_create_wallet(int command_handle, String pool_name, String name, String xtype, String config, String credentials, Callback cb);
41-
public int indy_open_wallet(int command_handle, String name, String runtime_config, String credentials, Callback cb);
40+
public int indy_create_wallet(int command_handle, String config, String credentials, Callback cb);
41+
public int indy_open_wallet(int command_handle, String config, String credentials, Callback cb);
4242
public int indy_close_wallet(int command_handle, int handle, Callback cb);
43-
public int indy_delete_wallet(int command_handle, String name, String credentials, Callback cb);
43+
public int indy_delete_wallet(int command_handle, String config, String credentials, Callback cb);
4444
public int indy_export_wallet(int command_handle, int handle, String exportConfigJson, Callback cb);
45-
public int indy_import_wallet(int command_handle, String pool_name, String name, String xtype, String config, String credentials, String importConfigJson, Callback cb);
45+
public int indy_import_wallet(int command_handle, String config, String credentials, String importConfigJson, Callback cb);
4646

4747
// ledger.rs
4848

wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java

Lines changed: 104 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,42 @@ public static CompletableFuture<Void> registerWalletType(
137137
/**
138138
* Creates a new secure wallet with the given unique name.
139139
*
140-
* @param poolName Name of the pool that corresponds to this wallet.
141-
* @param name Name of the wallet.
142-
* @param xtype Type of the wallet. Defaults to 'default'.
143-
* @param config Wallet configuration json. List of supported keys are defined by wallet type.
144-
* @param credentials Wallet credentials json: {
145-
* "key": <string>
140+
* @param config Wallet configuration json.
141+
* {
142+
* "id": string, Identifier of the wallet.
143+
* Configured storage uses this identifier to lookup exact wallet data placement.
144+
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
145+
* 'Default' storage type allows to store wallet data in the local file.
146+
* Custom storage types can be registered with indy_register_wallet_storage call.
147+
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
148+
* Can be optional if storage supports default configuration.
149+
* For 'default' storage type configuration is:
150+
* {
151+
* "path": optional<string>, Path to the directory with wallet files.
152+
* Defaults to $HOME/.indy_client/wallets.
153+
* Wallet will be stored in the file {path}/{id}/sqlite.db
154+
* }
155+
* }
156+
* @param credentials Wallet credentials json
157+
* {
158+
* "key": string, Passphrase used to derive wallet master key
159+
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
160+
* Can be optional if storage supports default configuration.
161+
* For 'default' storage type should be empty.
162+
*
146163
* }
147164
* @return A future that resolves no value.
148165
* @throws IndyException Thrown if a call to the underlying SDK fails.
149166
*/
150167
public static CompletableFuture<Void> createWallet(
151-
String poolName,
152-
String name,
153-
String xtype,
154168
String config,
155169
String credentials) throws IndyException {
156170

157-
ParamGuard.notNullOrWhiteSpace(poolName, "poolName");
158-
ParamGuard.notNullOrWhiteSpace(name, "name");
159-
160171
CompletableFuture<Void> future = new CompletableFuture<Void>();
161172
int commandHandle = addFuture(future);
162173

163174
int result = LibIndy.api.indy_create_wallet(
164175
commandHandle,
165-
poolName,
166-
name,
167-
xtype,
168176
config,
169177
credentials,
170178
voidCb);
@@ -177,28 +185,46 @@ public static CompletableFuture<Void> createWallet(
177185
/**
178186
* Opens the wallet with specific name.
179187
*
180-
* @param name Name of the wallet.
181-
* @param runtimeConfig Runtime wallet configuration json. if NULL, then default runtime_config will be used.
182-
* @param credentials Wallet credentials json: {
183-
* "key": <string>
188+
* @param config Wallet configuration json.
189+
* {
190+
* "id": string, Identifier of the wallet.
191+
* Configured storage uses this identifier to lookup exact wallet data placement.
192+
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
193+
* 'Default' storage type allows to store wallet data in the local file.
194+
* Custom storage types can be registered with indy_register_wallet_storage call.
195+
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
196+
* Can be optional if storage supports default configuration.
197+
* For 'default' storage type configuration is:
198+
* {
199+
* "path": optional<string>, Path to the directory with wallet files.
200+
* Defaults to $HOME/.indy_client/wallets.
201+
* Wallet will be stored in the file {path}/{id}/sqlite.db
202+
* }
184203
* }
204+
* @param credentials Wallet credentials json
205+
* {
206+
* "key": string, Passphrase used to derive current wallet master key
207+
* "rekey": optional<string>, If present than wallet master key will be rotated to a new one
208+
* derived from this passphrase.
209+
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
210+
* Can be optional if storage supports default configuration.
211+
* For 'default' storage type should be empty.
212+
*
213+
* }
185214
* @return A future that resolves no value.
186215
* @throws IndyException Thrown if a call to the underlying SDK fails.
187216
*/
188217
public static CompletableFuture<Wallet> openWallet(
189-
String name,
190-
String runtimeConfig,
218+
String config,
191219
String credentials) throws IndyException {
192220

193-
ParamGuard.notNullOrWhiteSpace(name, "name");
194221

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

198225
int result = LibIndy.api.indy_open_wallet(
199226
commandHandle,
200-
name,
201-
runtimeConfig,
227+
config,
202228
credentials,
203229
openWalletCb);
204230

@@ -237,25 +263,46 @@ private static CompletableFuture<Void> closeWallet(
237263
/**
238264
* Deletes an existing wallet.
239265
*
240-
* @param name Name of the wallet to delete.
241-
* @param credentials Wallet credentials json: {
242-
* "key": <string>
266+
* @param config Wallet configuration json.
267+
* {
268+
* "id": string, Identifier of the wallet.
269+
* Configured storage uses this identifier to lookup exact wallet data placement.
270+
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
271+
* 'Default' storage type allows to store wallet data in the local file.
272+
* Custom storage types can be registered with indy_register_wallet_storage call.
273+
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
274+
* Can be optional if storage supports default configuration.
275+
* For 'default' storage type configuration is:
276+
* {
277+
* "path": optional<string>, Path to the directory with wallet files.
278+
* Defaults to $HOME/.indy_client/wallets.
279+
* Wallet will be stored in the file {path}/{id}/sqlite.db
280+
* }
243281
* }
282+
* @param credentials Wallet credentials json
283+
* {
284+
* "key": string, Passphrase used to derive current wallet master key
285+
* "rekey": optional<string>, If present than wallet master key will be rotated to a new one
286+
* derived from this passphrase.
287+
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
288+
* Can be optional if storage supports default configuration.
289+
* For 'default' storage type should be empty.
290+
*
291+
* }
292+
*
244293
* @return A future that resolves no value.
245294
* @throws IndyException Thrown if a call to the underlying SDK fails.
246295
*/
247296
public static CompletableFuture<Void> deleteWallet(
248-
String name,
297+
String config,
249298
String credentials) throws IndyException {
250299

251-
ParamGuard.notNullOrWhiteSpace(name, "name");
252-
253300
CompletableFuture<Void> future = new CompletableFuture<Void>();
254301
int commandHandle = addFuture(future);
255302

256303
int result = LibIndy.api.indy_delete_wallet(
257304
commandHandle,
258-
name,
305+
config,
259306
credentials,
260307
voidCb);
261308

@@ -272,8 +319,8 @@ public static CompletableFuture<Void> deleteWallet(
272319
* @param wallet The wallet to export.
273320
* @param exportConfigJson: JSON containing settings for input operation.
274321
* {
275-
* "path": path of the file that contains exported wallet content
276-
* "key": passphrase used to export key
322+
* "path": <string>, Path of the file that contains exported wallet content
323+
* "key": <string>, Passphrase used to derive export key
277324
* }
278325
* @return A future that resolves no value.
279326
* @throws IndyException Thrown if a call to the underlying SDK fails.
@@ -308,40 +355,47 @@ public static CompletableFuture<Void> exportWallet(
308355
*
309356
* Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
310357
* the future releases.
311-
* @param poolName Name of the pool that corresponds to this wallet.
312-
* @param name Name of the wallet.
313-
* @param xtype Type of the wallet. Defaults to 'default'.
358+
*
314359
* @param config Wallet configuration json. List of supported keys are defined by wallet type.
315-
* @param credentials Wallet credentials json: {
316-
* "key": <string>
317-
* }
318-
* @param importConfigJson JSON containing settings for input operation: {
319-
* "path": path of the file that contains exported wallet content
320-
* "key": passphrase used to export key
360+
* @param credentials Wallet configuration json.
361+
* {
362+
* "id": string, Identifier of the wallet.
363+
* Configured storage uses this identifier to lookup exact wallet data placement.
364+
* "storage_type": optional<string>, Type of the wallet storage. Defaults to 'default'.
365+
* 'Default' storage type allows to store wallet data in the local file.
366+
* Custom storage types can be registered with indy_register_wallet_storage call.
367+
* "storage_config": optional<object>, Storage configuration json. Storage type defines set of supported keys.
368+
* Can be optional if storage supports default configuration.
369+
* For 'default' storage type configuration is:
370+
* {
371+
* "path": optional<string>, Path to the directory with wallet files.
372+
* Defaults to $HOME/.indy_client/wallets.
373+
* Wallet will be stored in the file {path}/{id}/sqlite.db
321374
* }
375+
* }
376+
* @param importConfigJson Wallet credentials json
377+
* {
378+
* "key": string, Passphrase used to derive wallet master key
379+
* "storage_credentials": optional<object> Credentials for wallet storage. Storage type defines set of supported keys.
380+
* Can be optional if storage supports default configuration.
381+
* For 'default' storage type should be empty.
382+
*
383+
* }
322384
* @return A future that resolves no value.
323385
* @throws IndyException Thrown if a call to the underlying SDK fails.
324386
*/
325387
public static CompletableFuture<Void> importWallet(
326-
String poolName,
327-
String name,
328-
String xtype,
329388
String config,
330389
String credentials,
331390
String importConfigJson) throws IndyException {
332391

333-
ParamGuard.notNullOrWhiteSpace(poolName, "poolName");
334-
ParamGuard.notNullOrWhiteSpace(name, "name");
335392
ParamGuard.notNull(importConfigJson, "importConfigJson");
336393

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

340397
int result = LibIndy.api.indy_import_wallet(
341398
commandHandle,
342-
poolName,
343-
name,
344-
xtype,
345399
config,
346400
credentials,
347401
importConfigJson,

wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.hyperledger.indy.sdk.did.DidJSONParameters;
66
import org.hyperledger.indy.sdk.utils.InitHelper;
77
import org.hyperledger.indy.sdk.utils.StorageUtils;
8-
import org.hyperledger.indy.sdk.wallet.InMemWalletType;
9-
import org.hyperledger.indy.sdk.wallet.Wallet;
108
import org.json.JSONObject;
119
import org.junit.After;
1210
import org.junit.Before;
@@ -66,7 +64,21 @@ public class IndyIntegrationTest {
6664
" \"height\": {\"raw\": \"175\", \"encoded\": \"175\"},\n" +
6765
" \"age\": {\"raw\": \"28\", \"encoded\": \"28\"}\n" +
6866
" }";
69-
protected String CREDENTIALS = "{\"key\": \"key\"}";
67+
protected static final String WALLET_CONFIG =
68+
new JSONObject()
69+
.put("id", WALLET)
70+
.put("storage_type", TYPE)
71+
.toString();
72+
protected static final String WALLET_CREDENTIALS =
73+
new JSONObject()
74+
.put("key", "key")
75+
.toString();
76+
protected static final String PLUGGED_WALLET_CONFIG =
77+
new JSONObject()
78+
.put("id", WALLET)
79+
.put("storage_type", "unknown_type")
80+
.toString();
81+
7082
protected int PROTOCOL_VERSION = 2;
7183

7284

wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTestWithPoolAndSingleWallet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public void createPoolAndWallet() throws Exception {
2323
String poolName = PoolUtils.createPoolLedgerConfig();
2424
pool = Pool.openPoolLedger(poolName, null).get();
2525

26-
Wallet.createWallet(poolName, WALLET, TYPE, null, CREDENTIALS).get();
27-
this.wallet = Wallet.openWallet(WALLET, null, CREDENTIALS).get();
26+
Wallet.createWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
27+
this.wallet = Wallet.openWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
2828
}
2929

3030
@After
3131
public void deletePoolAndWallet() throws Exception {
3232
pool.closePoolLedger().get();
3333
wallet.closeWallet().get();
34-
Wallet.deleteWallet(WALLET, CREDENTIALS).get();
34+
Wallet.deleteWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
3535
}
3636

3737
protected void checkResponseType(String response, String expectedType) {

wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTestWithSingleWallet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ public class IndyIntegrationTestWithSingleWallet extends IndyIntegrationTest {
1111

1212
@Before
1313
public void createWallet() throws Exception {
14-
Wallet.createWallet(POOL, WALLET, TYPE, null, CREDENTIALS).get();
15-
this.wallet = Wallet.openWallet(WALLET, null, CREDENTIALS).get();
14+
Wallet.createWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
15+
this.wallet = Wallet.openWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
1616
}
1717

1818
@After
1919
public void deleteWallet() throws Exception {
2020
wallet.closeWallet().get();
21-
Wallet.deleteWallet(WALLET, CREDENTIALS).get();
21+
Wallet.deleteWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
2222
}
2323
}

wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ private void initCommonWallet() throws Exception {
8383

8484
StorageUtils.cleanupStorage();
8585

86-
String walletName = "anoncredsCommonWallet";
86+
String walletConfig =
87+
new JSONObject()
88+
.put("id", "anoncredsCommonWallet")
89+
.toString();
8790

88-
Wallet.createWallet("default", walletName, "default", null, CREDENTIALS).get();
89-
wallet = Wallet.openWallet(walletName, null, CREDENTIALS).get();
91+
Wallet.createWallet(walletConfig, CREDENTIALS).get();
92+
wallet = Wallet.openWallet(walletConfig, CREDENTIALS).get();
9093

9194
AnoncredsResults.IssuerCreateSchemaResult createSchemaResult =
9295
Anoncreds.issuerCreateSchema(issuerDid, gvtSchemaName, schemaVersion, gvtSchemaAttributes).get();

wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerRevokeCredentialTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class IssuerRevokeCredentialTest extends AnoncredsIntegrationTest {
2020
@Test
2121
public void testIssuerRevokeProofWorks() throws Exception {
2222
// Create wallet, get wallet handle
23-
String walletName = "revocationWallet";
24-
Wallet.createWallet("default", walletName, "default", null, CREDENTIALS).get();
25-
Wallet wallet = Wallet.openWallet(walletName, null, CREDENTIALS).get();
23+
String walletConfig = new JSONObject().put("id", "revocationWallet").toString();
24+
Wallet.createWallet(walletConfig, CREDENTIALS).get();
25+
Wallet wallet = Wallet.openWallet(walletConfig, CREDENTIALS).get();
2626

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

109109
// Close and Delete Wallet
110110
wallet.closeWallet().get();
111-
Wallet.deleteWallet(walletName, CREDENTIALS).get();
111+
Wallet.deleteWallet(walletConfig, CREDENTIALS).get();
112112
}
113113
}

0 commit comments

Comments
 (0)