Skip to content

Commit 8b46324

Browse files
authored
feat: support profile renaming (#61)
* feat: support profile renaming Signed-off-by: Ariel Gentile <[email protected]> * feat: add copy profile support Signed-off-by: Ariel Gentile <[email protected]> * Create six-buttons-kick.md Signed-off-by: Ariel Gentile <[email protected]> --------- Signed-off-by: Ariel Gentile <[email protected]>
1 parent bfbc013 commit 8b46324

File tree

11 files changed

+170
-1
lines changed

11 files changed

+170
-1
lines changed

.changeset/six-buttons-kick.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@openwallet-foundation/askar-nodejs": patch
3+
"@openwallet-foundation/askar-react-native": patch
4+
"@openwallet-foundation/askar-shared": patch
5+
---
6+
7+
feat: support profile renaming and copying

packages/askar-nodejs/src/NodeJSAskar.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import type {
6565
SetCustomLoggerOptions,
6666
SetMaxLogLevelOptions,
6767
StoreCloseOptions,
68+
StoreCopyProfileOptions,
6869
StoreCopyToOptions,
6970
StoreCreateProfileOptions,
7071
StoreGenerateRawKeyOptions,
@@ -76,6 +77,7 @@ import type {
7677
StoreRekeyOptions,
7778
StoreRemoveOptions,
7879
StoreRemoveProfileOptions,
80+
StoreRenameProfileOptions,
7981
StoreSetDefaultProfileOptions,
8082
} from '@openwallet-foundation/askar-shared'
8183
import {
@@ -1088,6 +1090,28 @@ export class NodeJSAskar implements Askar {
10881090
)
10891091
}
10901092

1093+
public async storeRenameProfile(options: StoreRenameProfileOptions): Promise<number> {
1094+
const { storeHandle, fromProfile, toProfile } = serializeArguments(options)
1095+
1096+
const response = await this.promisifyWithResponse<number>(
1097+
(cb, cbId) => this.nativeAskar.askar_store_rename_profile(storeHandle, fromProfile, toProfile, cb, cbId),
1098+
FFI_INT8
1099+
)
1100+
1101+
return handleInvalidNullResponse(response)
1102+
}
1103+
1104+
public async storeCopyProfile(options: StoreCopyProfileOptions): Promise<number> {
1105+
const { fromHandle, toHandle, fromProfile, toProfile } = serializeArguments(options)
1106+
1107+
const response = await this.promisifyWithResponse<number>(
1108+
(cb, cbId) => this.nativeAskar.askar_store_copy_profile(fromHandle, toHandle, fromProfile, toProfile, cb, cbId),
1109+
FFI_INT8
1110+
)
1111+
1112+
return handleInvalidNullResponse(response)
1113+
}
1114+
10911115
public async migrateIndySdk(options: MigrateIndySdkOptions): Promise<void> {
10921116
const { specUri, kdfLevel, walletKey, walletName } = serializeArguments(options)
10931117
await this.promisify((cb, cbId) =>

packages/askar-nodejs/src/library/bindings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ export const nativeBindings = {
231231
askar_store_remove: [FFI_ERROR_CODE, [FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]],
232232
askar_store_remove_profile: [FFI_ERROR_CODE, [FFI_STORE_HANDLE, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]],
233233
askar_store_set_default_profile: [FFI_ERROR_CODE, [FFI_STORE_HANDLE, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]],
234+
askar_store_rename_profile: [
235+
FFI_ERROR_CODE,
236+
[FFI_STORE_HANDLE, FFI_STRING, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID],
237+
],
238+
askar_store_copy_profile: [
239+
FFI_ERROR_CODE,
240+
[FFI_STORE_HANDLE, FFI_STORE_HANDLE, FFI_STRING, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID],
241+
],
234242

235243
askar_migrate_indy_sdk: [
236244
FFI_ERROR_CODE,
0 Bytes
Binary file not shown.

packages/askar-nodejs/tests/store.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,44 @@ describe('Store and Session', () => {
308308

309309
strictEqual(await session7.count(firstEntry), 0)
310310

311+
await session7.insert(firstEntry)
312+
313+
strictEqual(await session7.count(firstEntry), 1)
314+
311315
await session7.close()
316+
317+
ok(await store.renameProfile({ fromProfile: profile, toProfile: 'newProfileName' }))
318+
319+
ok((await store.listProfiles()).includes('newProfileName'))
320+
321+
ok(!(await store.listProfiles()).includes(profile))
322+
323+
const session8 = await store.session('newProfileName').open()
324+
325+
strictEqual(await session8.count(firstEntry), 1)
326+
327+
await session8.close()
328+
329+
const destinationStore = await Store.provision({
330+
uri: 'sqlite://:memory:',
331+
keyMethod: new StoreKeyMethod(KdfMethod.Raw),
332+
passKey: getRawKey(),
333+
recreate: true,
334+
})
335+
336+
ok(
337+
await store.copyProfile({
338+
toStore: destinationStore,
339+
fromProfile: 'newProfileName',
340+
toProfile: 'newerProfileName',
341+
})
342+
)
343+
344+
const session9 = await destinationStore.session('newerProfileName').open()
345+
346+
strictEqual(await session9.count(firstEntry), 1)
347+
348+
await session9.close()
312349
})
313350

314351
test('Copy', async () => {

packages/askar-react-native/cpp/askar.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,37 @@ jsi::Value storeSetDefaultProfile(jsi::Runtime &rt, jsi::Object options) {
286286
return createReturnValue(rt, code, nullptr);
287287
}
288288

289+
jsi::Value storeRenameProfile(jsi::Runtime &rt, jsi::Object options) {
290+
auto storeHandle = jsiToValue<int64_t>(rt, options, "storeHandle");
291+
auto fromProfile = jsiToValue<std::string>(rt, options, "fromProfile");
292+
auto toProfile = jsiToValue<std::string>(rt, options, "toProfile");
293+
294+
jsi::Function cb = options.getPropertyAsFunction(rt, "cb");
295+
State *state = new State(&cb);
296+
state->rt = &rt;
297+
298+
ErrorCode code = askar_store_rename_profile(
299+
storeHandle, fromProfile.c_str(), toProfile.c_str(), callbackWithResponse, CallbackId(state));
300+
301+
return createReturnValue(rt, code, nullptr);
302+
}
303+
304+
jsi::Value storeCopyProfile(jsi::Runtime &rt, jsi::Object options) {
305+
auto fromHandle = jsiToValue<int64_t>(rt, options, "fromHandle");
306+
auto toHandle = jsiToValue<int64_t>(rt, options, "toHandle");
307+
auto fromProfile = jsiToValue<std::string>(rt, options, "fromProfile");
308+
auto toProfile = jsiToValue<std::string>(rt, options, "toProfile");
309+
310+
jsi::Function cb = options.getPropertyAsFunction(rt, "cb");
311+
State *state = new State(&cb);
312+
state->rt = &rt;
313+
314+
ErrorCode code = askar_store_copy_profile(
315+
fromHandle, toHandle, fromProfile.c_str(), toProfile.c_str(), callbackWithResponse, CallbackId(state));
316+
317+
return createReturnValue(rt, code, nullptr);
318+
}
319+
289320
jsi::Value sessionClose(jsi::Runtime &rt, jsi::Object options) {
290321
auto sessionHandle = jsiToValue<int64_t>(rt, options, "sessionHandle");
291322
auto commit = jsiToValue<int8_t>(rt, options, "commit");

packages/askar-react-native/cpp/include/libaries_askar.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ ErrorCode askar_key_wrap_key(LocalKeyHandle handle,
410410
struct EncryptedBuffer *out);
411411

412412
/**
413-
* Migrate an sqlite wallet from an indy-sdk structure to an aries-askar structure.
413+
* Migrate an sqlite wallet from an indy-sdk structure to an Askar structure.
414414
* It is important to note that this does not do any post-processing. If the record values, tags,
415415
* names, etc. have changed, it must be processed manually afterwards. This script does the following:
416416
*
@@ -560,6 +560,13 @@ ErrorCode askar_store_copy(StoreHandle handle,
560560
void (*cb)(CallbackId cb_id, ErrorCode err, StoreHandle handle),
561561
CallbackId cb_id);
562562

563+
ErrorCode askar_store_copy_profile(StoreHandle from_handle,
564+
StoreHandle to_handle,
565+
FfiStr from_profile,
566+
FfiStr to_profile,
567+
void (*cb)(CallbackId cb_id, ErrorCode err),
568+
CallbackId cb_id);
569+
563570
ErrorCode askar_store_create_profile(StoreHandle handle,
564571
FfiStr profile,
565572
void (*cb)(CallbackId cb_id,
@@ -615,6 +622,12 @@ ErrorCode askar_store_remove_profile(StoreHandle handle,
615622
void (*cb)(CallbackId cb_id, ErrorCode err, int8_t removed),
616623
CallbackId cb_id);
617624

625+
ErrorCode askar_store_rename_profile(StoreHandle handle,
626+
FfiStr from_profile,
627+
FfiStr to_profile,
628+
void (*cb)(CallbackId cb_id, ErrorCode err, int8_t renamed),
629+
CallbackId cb_id);
630+
618631
ErrorCode askar_store_set_default_profile(StoreHandle handle,
619632
FfiStr profile,
620633
void (*cb)(CallbackId cb_id, ErrorCode err),

packages/askar-react-native/src/NativeBindings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export interface NativeBindings {
171171

172172
storeRemoveProfile(options: unknown): ReturnObject<never>
173173

174+
storeRenameProfile(options: unknown): ReturnObject<never>
175+
176+
storeCopyProfile(options: unknown): ReturnObject<never>
177+
174178
storeSetDefaultProfile(options: unknown): ReturnObject<never>
175179

176180
migrateIndySdk(options: unknown): ReturnObject<never>

packages/askar-react-native/src/ReactNativeAskar.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import type {
6161
SessionUpdateKeyOptions,
6262
SessionUpdateOptions,
6363
StoreCloseOptions,
64+
StoreCopyProfileOptions,
6465
StoreCopyToOptions,
6566
StoreCreateProfileOptions,
6667
StoreGenerateRawKeyOptions,
@@ -72,6 +73,7 @@ import type {
7273
StoreRekeyOptions,
7374
StoreRemoveOptions,
7475
StoreRemoveProfileOptions,
76+
StoreRenameProfileOptions,
7577
StoreSetDefaultProfileOptions,
7678
} from '@openwallet-foundation/askar-shared'
7779
import type { NativeBindings } from './NativeBindings'
@@ -726,6 +728,24 @@ export class ReactNativeAskar implements Askar {
726728
return handleInvalidNullResponse(response)
727729
}
728730

731+
public async storeRenameProfile(options: StoreRenameProfileOptions): Promise<number> {
732+
const serializedOptions = serializeArguments(options)
733+
const response = await this.promisifyWithResponse<number>((cb) =>
734+
this.handleError(this.askar.storeRenameProfile({ cb, ...serializedOptions }))
735+
)
736+
737+
return handleInvalidNullResponse(response)
738+
}
739+
740+
public async storeCopyProfile(options: StoreCopyProfileOptions): Promise<number> {
741+
const serializedOptions = serializeArguments(options)
742+
const response = await this.promisifyWithResponse<number>((cb) =>
743+
this.handleError(this.askar.storeCopyProfile({ cb, ...serializedOptions }))
744+
)
745+
746+
return handleInvalidNullResponse(response)
747+
}
748+
729749
public async storeSetDefaultProfile(options: StoreSetDefaultProfileOptions): Promise<void> {
730750
const serializedOptions = serializeArguments(options)
731751
const response = await this.promisifyWithResponse((cb) =>

packages/askar-shared/src/askar/Askar.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,17 @@ export type StoreSetDefaultProfileOptions = {
335335
storeHandle: StoreHandle
336336
profile: string
337337
}
338+
export type StoreRenameProfileOptions = {
339+
storeHandle: StoreHandle
340+
fromProfile: string
341+
toProfile: string
342+
}
343+
export type StoreCopyProfileOptions = {
344+
fromHandle: StoreHandle
345+
toHandle: StoreHandle
346+
fromProfile: string
347+
toProfile: string
348+
}
338349

339350
export type MigrateIndySdkOptions = {
340351
specUri: string
@@ -426,6 +437,8 @@ export type Askar = {
426437
storeProvision(options: StoreProvisionOptions): Promise<StoreHandle>
427438
storeRekey(options: StoreRekeyOptions): Promise<void>
428439
storeRemove(options: StoreRemoveOptions): Promise<number>
440+
storeRenameProfile(options: StoreRenameProfileOptions): Promise<number>
441+
storeCopyProfile(options: StoreCopyProfileOptions): Promise<number>
429442
storeRemoveProfile(options: StoreRemoveProfileOptions): Promise<number>
430443
storeSetDefaultProfile(options: StoreSetDefaultProfileOptions): Promise<void>
431444

0 commit comments

Comments
 (0)