Skip to content

Commit a4c434f

Browse files
authored
Separate rotate verkey into two steps (#494)
Signed-off-by: Miroslav Kovar <[email protected]> Co-authored-by: Miroslav Kovar <[email protected]>
1 parent 3b15f34 commit a4c434f

File tree

4 files changed

+137
-12
lines changed

4 files changed

+137
-12
lines changed

aries_vcx/src/libindy/utils/signus.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@ pub async fn create_and_store_my_did(seed: Option<&str>, method_name: Option<&st
2222
res
2323
}
2424

25-
pub async fn rotate_verkey(did: &str) -> VcxResult<()> {
26-
let trustee_temp_verkey = libindy_replace_keys_start(did).await?;
27-
let nym_request = ledger::libindy_build_nym_request(&did, &did, Some(&trustee_temp_verkey), None, None).await?;
25+
pub async fn libindy_replace_keys_start(did: &str) -> VcxResult<String> {
26+
if DidMocks::has_did_mock_responses() {
27+
warn!("libindy_replace_keys_start >> retrieving did mock response");
28+
Ok(DidMocks::get_next_did_response())
29+
} else {
30+
did::replace_keys_start(get_wallet_handle(), did, "{}")
31+
.map_err(VcxError::from)
32+
.await
33+
}
34+
}
35+
36+
pub async fn rotate_verkey_apply(did: &str, temp_vk: &str) -> VcxResult<()> {
37+
let nym_request = ledger::libindy_build_nym_request(&did, &did, Some(&temp_vk), None, None).await?;
2838
let nym_request = ledger::append_txn_author_agreement_to_request(&nym_request).await?;
2939
let nym_result = ledger::libindy_sign_and_submit_request(&did, &nym_request).await?;
3040
let nym_result_json: Value = serde_json::from_str(&nym_result)
@@ -37,15 +47,9 @@ pub async fn rotate_verkey(did: &str) -> VcxResult<()> {
3747
libindy_replace_keys_apply(&did).await
3848
}
3949

40-
pub async fn libindy_replace_keys_start(did: &str) -> VcxResult<String> {
41-
if DidMocks::has_did_mock_responses() {
42-
warn!("libindy_replace_keys_start >> retrieving did mock response");
43-
Ok(DidMocks::get_next_did_response())
44-
} else {
45-
did::replace_keys_start(get_wallet_handle(), did, "{}")
46-
.map_err(VcxError::from)
47-
.await
48-
}
50+
pub async fn rotate_verkey(did: &str) -> VcxResult<()> {
51+
let trustee_temp_verkey = libindy_replace_keys_start(did).await?;
52+
rotate_verkey_apply(did, &trustee_temp_verkey).await
4953
}
5054

5155
pub async fn libindy_replace_keys_apply(did: &str) -> VcxResult<()> {

libvcx/src/api_lib/api_c/utils.rs

+65
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,71 @@ pub extern fn vcx_rotate_verkey(command_handle: CommandHandle,
466466
error::SUCCESS.code_num
467467
}
468468

469+
#[no_mangle]
470+
pub extern fn vcx_rotate_verkey_start(command_handle: CommandHandle,
471+
did: *const c_char,
472+
cb: Option<extern fn(xcommand_handle: CommandHandle, err: u32, temp_vk: *const c_char)>) -> u32 {
473+
info!("vcx_rotate_verkey_start >>>");
474+
475+
check_useful_c_str!(did, VcxErrorKind::InvalidOption);
476+
check_useful_c_callback!(cb, VcxErrorKind::InvalidOption);
477+
trace!("vcx_rotate_verkey_start(command_handle: {}, did: {})", command_handle, did);
478+
479+
execute_async::<BoxFuture<'static, Result<(), ()>>>(Box::pin(async move {
480+
match aries_vcx::libindy::utils::signus::libindy_replace_keys_start(&did).await {
481+
Ok(temp_vk) => {
482+
trace!("vcx_rotate_verkey_start_cb(command_handle: {}, rc: {}, temp_vk: {})",
483+
command_handle, error::SUCCESS.message, temp_vk);
484+
let temp_vk = CStringUtils::string_to_cstring(temp_vk);
485+
cb(command_handle, error::SUCCESS.code_num, temp_vk.as_ptr());
486+
}
487+
Err(err) => {
488+
error!("vcx_rotate_verkey_start_cb(command_handle: {}, rc: {})",
489+
command_handle, err);
490+
491+
cb(command_handle, err.into(), ptr::null_mut());
492+
}
493+
};
494+
495+
Ok(())
496+
}));
497+
498+
error::SUCCESS.code_num
499+
}
500+
501+
#[no_mangle]
502+
pub extern fn vcx_rotate_verkey_apply(command_handle: CommandHandle,
503+
did: *const c_char,
504+
temp_vk: *const c_char,
505+
cb: Option<extern fn(xcommand_handle: CommandHandle, err: u32)>) -> u32 {
506+
info!("vcx_rotate_verkey_apply >>>");
507+
508+
check_useful_c_str!(did, VcxErrorKind::InvalidOption);
509+
check_useful_c_str!(temp_vk, VcxErrorKind::InvalidOption);
510+
check_useful_c_callback!(cb, VcxErrorKind::InvalidOption);
511+
trace!("vcx_rotate_verkey_apply(command_handle: {}, did: {}, temp_vk: {:?})", command_handle, did, temp_vk);
512+
513+
execute_async::<BoxFuture<'static, Result<(), ()>>>(Box::pin(async move {
514+
match aries_vcx::libindy::utils::signus::rotate_verkey_apply(&did, &temp_vk).await {
515+
Ok(()) => {
516+
trace!("vcx_rotate_verkey_apply_cb(command_handle: {}, rc: {})",
517+
command_handle, error::SUCCESS.message);
518+
cb(command_handle, error::SUCCESS.code_num);
519+
}
520+
Err(err) => {
521+
error!("vcx_rotate_verkey_apply_cb(command_handle: {}, rc: {})",
522+
command_handle, err);
523+
524+
cb(command_handle, err.into());
525+
}
526+
};
527+
528+
Ok(())
529+
}));
530+
531+
error::SUCCESS.code_num
532+
}
533+
469534
#[no_mangle]
470535
pub extern fn vcx_get_verkey_from_wallet(command_handle: CommandHandle,
471536
did: *const c_char,

wrappers/node/src/api/utils.ts

+46
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,52 @@ export async function rotateVerkey(did: string): Promise<void> {
205205
}
206206
}
207207

208+
export async function rotateVerkeyStart(did: string): Promise<string> {
209+
try {
210+
return await createFFICallbackPromise<string>(
211+
(resolve, reject, cb) => {
212+
const rc = rustAPI().vcx_rotate_verkey_start(0, did, cb);
213+
if (rc) {
214+
reject(rc);
215+
}
216+
},
217+
(resolve, reject) =>
218+
Callback('string', ['uint32', 'uint32', 'string'], (xhandle: number, err: number, tempVk: string) => {
219+
if (err) {
220+
reject(err);
221+
return;
222+
}
223+
resolve(tempVk);
224+
}),
225+
);
226+
} catch (err) {
227+
throw new VCXInternalError(err);
228+
}
229+
}
230+
231+
export async function rotateVerkeyApply(did: string, tempVk: string): Promise<void> {
232+
try {
233+
return await createFFICallbackPromise<void>(
234+
(resolve, reject, cb) => {
235+
const rc = rustAPI().vcx_rotate_verkey_apply(0, did, tempVk, cb);
236+
if (rc) {
237+
reject(rc);
238+
}
239+
},
240+
(resolve, reject) =>
241+
Callback('string', ['uint32', 'uint32'], (xhandle: number, err: number) => {
242+
if (err) {
243+
reject(err);
244+
return;
245+
}
246+
resolve();
247+
}),
248+
);
249+
} catch (err) {
250+
throw new VCXInternalError(err);
251+
}
252+
}
253+
208254
export async function getVerkeyFromWallet(did: string): Promise<string> {
209255
try {
210256
return await createFFICallbackPromise<string>(

wrappers/node/src/rustlib.ts

+10
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ export interface IFFIEntryPoint {
155155
vcx_pool_set_handle: (handle: number) => void;
156156
vcx_endorse_transaction: (commandId: number, transaction: string, cb: ICbRef) => number;
157157
vcx_rotate_verkey: (commandId: number, did: string, cb: ICbRef) => number;
158+
vcx_rotate_verkey_start: (commandId: number, did: string, cb: ICbRef) => number;
159+
vcx_rotate_verkey_apply: (commandId: number, did: string, tempVk: string, cb: ICbRef) => number;
158160
vcx_get_verkey_from_wallet: (commandId: number, did: string, cb: ICbRef) => number;
159161
vcx_get_verkey_from_ledger: (commandId: number, did: string, cb: ICbRef) => number;
160162
vcx_get_ledger_txn: (commandId: number, did: string, seq_no: number, cb: ICbRef) => number;
@@ -633,6 +635,14 @@ export const FFIConfiguration: { [Key in keyof IFFIEntryPoint]: any } = {
633635
FFI_ERROR_CODE,
634636
[FFI_COMMAND_HANDLE, FFI_STRING_DATA, FFI_CALLBACK_PTR],
635637
],
638+
vcx_rotate_verkey_start: [
639+
FFI_ERROR_CODE,
640+
[FFI_COMMAND_HANDLE, FFI_STRING_DATA, FFI_CALLBACK_PTR],
641+
],
642+
vcx_rotate_verkey_apply: [
643+
FFI_ERROR_CODE,
644+
[FFI_COMMAND_HANDLE, FFI_STRING_DATA, FFI_STRING_DATA, FFI_CALLBACK_PTR],
645+
],
636646
vcx_get_verkey_from_wallet: [
637647
FFI_ERROR_CODE,
638648
[FFI_COMMAND_HANDLE, FFI_STRING_DATA, FFI_CALLBACK_PTR],

0 commit comments

Comments
 (0)