From 849489464a7d75a1961e58e5b461671f199ab84a Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 09:04:24 +0100 Subject: [PATCH 01/11] chore: updated header and generation Signed-off-by: blu3beri --- include/cbindgen.toml | 129 +----- include/libaries_askar.h | 29 ++ .../cpp/include/libaries_askar.h | 379 ++++++++++-------- 3 files changed, 248 insertions(+), 289 deletions(-) diff --git a/include/cbindgen.toml b/include/cbindgen.toml index e95c96fd..b3f40f3d 100644 --- a/include/cbindgen.toml +++ b/include/cbindgen.toml @@ -1,131 +1,18 @@ -# This is a template cbindgen.toml file with all of the default values. -# Some values are commented out because their absence is the real default. -# -# See https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml -# for detailed documentation of every option here. - - language = "C" cpp_compat = true - -############## Options for Wrapping the Contents of the Header ################# - -# header = "/* Text to put at the beginning of the generated file. Probably a license. */" -# trailer = "/* Text to put at the end of the generated file */" -# include_guard = "my_bindings_h" -# pragma_once = true -# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" +pragma_once = true +autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" include_version = false -# namespace = "my_namespace" -namespaces = [] -using_namespaces = [] -sys_includes = [] -includes = [] -no_includes = false -after_includes = "" - - -############################ Code Style Options ################################ - -braces = "SameLine" -line_length = 100 -tab_width = 2 -documentation = true -documentation_style = "auto" -# documentation_length = "full" -line_endings = "LF" # also "CR", "CRLF", "Native" - - -############################# Codegen Options ################################## - -style = "both" -sort_by = "Name" # default for `fn.sort_by` and `const.sort_by` usize_is_size_t = true - - -[defines] -# "target_os = freebsd" = "DEFINE_FREEBSD" -# "feature = serde" = "DEFINE_SERDE" -"feature = rich_schema" = "DEFINE_RICH_SCHEMA" -"test" = "DEFINE_TEST" - -[export] -include = [] -exclude = [] -# prefix = "CAPI_" -item_types = [] -renaming_overrides_prefixing = false - - -[export.rename] - - -[export.body] - - -[export.mangle] - - -[fn] -rename_args = "None" -# must_use = "MUST_USE_FUNC" -# no_return = "NO_RETURN" -# prefix = "START_FUNC" -# postfix = "END_FUNC" -args = "auto" -sort_by = "Name" - - -[struct] -rename_fields = "None" -# must_use = "MUST_USE_STRUCT" -derive_constructor = false -derive_eq = false -derive_neq = false -derive_lt = false -derive_lte = false -derive_gt = false -derive_gte = false - - -[enum] -rename_variants = "None" -# must_use = "MUST_USE_ENUM" -add_sentinel = false -prefix_with_name = false -derive_helper_methods = false -derive_const_casts = false -derive_mut_casts = false -# cast_assert_name = "ASSERT" -derive_tagged_enum_destructor = false -derive_tagged_enum_copy_constructor = false -enum_class = true -private_default_tagged_enum_constructor = false - - -[const] -allow_static_const = true -allow_constexpr = false sort_by = "Name" +after_includes = """ - -[macro_expansion] -bitflags = false - - -############## Options for How Your Rust library Should Be Parsed ############## +typedef size_t ScanHandle; +typedef size_t StoreHandle; +typedef size_t SessionHandle; +""" [parse] parse_deps = true -include = ["ffi-support"] -exclude = [] -clean = false -extra_bindings = [] - - -[parse.expand] -crates = [] -all_features = false -default_features = true -features = [] +include = ["ffi-support", "ffi"] diff --git a/include/libaries_askar.h b/include/libaries_askar.h index 54e7c4d4..48f5e3e3 100644 --- a/include/libaries_askar.h +++ b/include/libaries_askar.h @@ -1,9 +1,17 @@ +#pragma once + +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ + #include #include #include #include #include +typedef size_t ScanHandle; +typedef size_t StoreHandle; +typedef size_t SessionHandle; + #define PAGE_SIZE 32 @@ -385,6 +393,25 @@ ErrorCode askar_key_wrap_key(LocalKeyHandle handle, struct ByteBuffer nonce, struct EncryptedBuffer *out); +/** + * Migrate an sqlite wallet from an indy-sdk structure to an aries-askar structure. + * It is important to note that this does not do any post-processing. If the record values, tags, + * names, etc. have changed, it must be processed manually afterwards. This script does the following: + * + * 1. Create and rename the required tables + * 2. Fetch the indy key from the wallet + * 3. Create a new configuration + * 4. Initialize a profile + * 5. Update the items from the indy-sdk + * 6. Clean up (drop tables and add a version of "1") + */ +ErrorCode askar_migrate_indy_sdk(FfiStr spec_uri, + FfiStr wallet_name, + FfiStr wallet_key, + FfiStr kdf_level, + void (*cb)(CallbackId cb_id, ErrorCode err), + CallbackId cb_id); + ErrorCode askar_scan_free(ScanHandle handle); ErrorCode askar_scan_next(ScanHandle handle, @@ -540,6 +567,8 @@ ErrorCode askar_store_remove_profile(StoreHandle handle, void (*cb)(CallbackId cb_id, ErrorCode err, int8_t removed), CallbackId cb_id); +void askar_terminate(void); + char *askar_version(void); #ifdef __cplusplus diff --git a/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h b/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h index 7470db90..48f5e3e3 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h +++ b/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h @@ -1,5 +1,7 @@ #pragma once +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ + #include #include #include @@ -10,11 +12,14 @@ typedef size_t ScanHandle; typedef size_t StoreHandle; typedef size_t SessionHandle; + +#define PAGE_SIZE 32 + enum ErrorCode #ifdef __cplusplus - : int64_t + : int64_t #endif // __cplusplus -{ + { Success = 0, Backend = 1, Busy = 2, @@ -63,24 +68,23 @@ typedef struct ArcHandle_LocalKey { typedef struct ArcHandle_LocalKey LocalKeyHandle; /** - * ByteBuffer is a struct that represents an array of bytes to be sent over the - * FFI boundaries. There are several cases when you might want to use this, but - * the primary one for us is for returning protobuf-encoded data to Swift and - * Java. The type is currently rather limited (implementing almost no - * functionality), however in the future it may be more expanded. + * ByteBuffer is a struct that represents an array of bytes to be sent over the FFI boundaries. + * There are several cases when you might want to use this, but the primary one for us + * is for returning protobuf-encoded data to Swift and Java. The type is currently rather + * limited (implementing almost no functionality), however in the future it may be + * more expanded. * * ## Caveats * - * Note that the order of the fields is `len` (an i64) then `data` (a `*mut - * u8`), getting this wrong on the other side of the FFI will cause memory - * corruption and crashes. `i64` is used for the length instead of `u64` and - * `usize` because JNA has interop issues with both these types. + * Note that the order of the fields is `len` (an i64) then `data` (a `*mut u8`), getting + * this wrong on the other side of the FFI will cause memory corruption and crashes. + * `i64` is used for the length instead of `u64` and `usize` because JNA has interop + * issues with both these types. * * ### `Drop` is not implemented * - * ByteBuffer does not implement Drop. This is intentional. Memory passed into - * it will be leaked if it is not explicitly destroyed by calling - * [`ByteBuffer::destroy`], or + * ByteBuffer does not implement Drop. This is intentional. Memory passed into it will + * be leaked if it is not explicitly destroyed by calling [`ByteBuffer::destroy`], or * [`ByteBuffer::destroy_into_vec`]. This is for two reasons: * * 1. In the future, we may allow it to be used for data that is not managed by @@ -88,32 +92,30 @@ typedef struct ArcHandle_LocalKey LocalKeyHandle; * deallocate this data with the Rust allocator. * * 2. Automatically running destructors in unsafe code is a - * [frequent - * footgun](https://without.boats/blog/two-memory-bugs-from-ringbahn/) (among - * many similar issues across many crates). + * [frequent footgun](https://without.boats/blog/two-memory-bugs-from-ringbahn/) + * (among many similar issues across many crates). * - * Note that calling `destroy` manually is often not needed, as usually you - * should be passing these to the function defined by - * [`define_bytebuffer_destructor!`] from the other side of the FFI. + * Note that calling `destroy` manually is often not needed, as usually you should + * be passing these to the function defined by [`define_bytebuffer_destructor!`] from + * the other side of the FFI. * - * Because this type is essentially *only* useful in unsafe or FFI code (and - * because the most common usage pattern does not require manually managing the - * memory), it does not implement `Drop`. + * Because this type is essentially *only* useful in unsafe or FFI code (and because + * the most common usage pattern does not require manually managing the memory), it + * does not implement `Drop`. * - * \* Note: in the case of multiple Rust shared libraries loaded at the same - * time, there may be multiple instances of "the Rust allocator" (one per shared - * library), in which case we're referring to whichever instance is active for - * the code using the `ByteBuffer`. Note that this doesn't occur on all - * platforms or build configurations, but treating allocators in different - * shared libraries as fully independent is always safe. + * \* Note: in the case of multiple Rust shared libraries loaded at the same time, + * there may be multiple instances of "the Rust allocator" (one per shared library), + * in which case we're referring to whichever instance is active for the code using + * the `ByteBuffer`. Note that this doesn't occur on all platforms or build + * configurations, but treating allocators in different shared libraries as fully + * independent is always safe. * * ## Layout/fields * - * This struct's field are not `pub` (mostly so that we can soundly implement - * `Send`, but also so that we can verify rust users are constructing them - * appropriately), the fields, their types, and their order are *very much* a - * part of the public API of this type. Consumers on the other side of the FFI - * will need to know its layout. + * This struct's field are not `pub` (mostly so that we can soundly implement `Send`, but also so + * that we can verify rust users are constructing them appropriately), the fields, their types, and + * their order are *very much* a part of the public API of this type. Consumers on the other side + * of the FFI will need to know its layout. * * If this were a C struct, it would look like * @@ -127,28 +129,24 @@ typedef struct ArcHandle_LocalKey LocalKeyHandle; * }; * ``` * - * In rust, there are two fields, in this order: `len: i64`, and `data: *mut - * u8`. + * In rust, there are two fields, in this order: `len: i64`, and `data: *mut u8`. * - * For clarity, the fact that the data pointer is nullable means that - * `Option` is not the same size as ByteBuffer, and additionally is - * not FFI-safe (the latter point is not currently guaranteed anyway as of the - * time of writing this comment). + * For clarity, the fact that the data pointer is nullable means that `Option` is not + * the same size as ByteBuffer, and additionally is not FFI-safe (the latter point is not + * currently guaranteed anyway as of the time of writing this comment). * * ### Description of fields * - * `data` is a pointer to an array of `len` bytes. Note that data can be a null - * pointer and therefore should be checked. + * `data` is a pointer to an array of `len` bytes. Note that data can be a null pointer and therefore + * should be checked. * - * The bytes array is allocated on the heap and must be freed on it as well. - * Critically, if there are multiple rust shared libraries using being used in - * the same application, it *must be freed on the same heap that allocated it*, - * or you will corrupt both heaps. + * The bytes array is allocated on the heap and must be freed on it as well. Critically, if there + * are multiple rust shared libraries using being used in the same application, it *must be freed + * on the same heap that allocated it*, or you will corrupt both heaps. * - * Typically, this object is managed on the other side of the FFI (on the "FFI - * consumer"), which means you must expose a function to release the resources - * of `data` which can be done easily using the - * [`define_bytebuffer_destructor!`] macro provided by this crate. + * Typically, this object is managed on the other side of the FFI (on the "FFI consumer"), which + * means you must expose a function to release the resources of `data` which can be done easily + * using the [`define_bytebuffer_destructor!`] macro provided by this crate. */ typedef struct ByteBuffer { int64_t len; @@ -223,10 +221,7 @@ typedef struct ArcHandle_FfiKeyEntryList KeyEntryListHandle; typedef int64_t CallbackId; -typedef void (*LogCallback)(const void *context, int32_t level, - const char *target, const char *message, - const char *module_path, const char *file, - int32_t line); +typedef void (*LogCallback)(const void *context, int32_t level, const char *target, const char *message, const char *module_path, const char *file, int32_t line); #ifdef __cplusplus extern "C" { @@ -240,42 +235,40 @@ ErrorCode askar_entry_list_count(EntryListHandle handle, int32_t *count); void askar_entry_list_free(EntryListHandle handle); -ErrorCode askar_entry_list_get_category(EntryListHandle handle, int32_t index, +ErrorCode askar_entry_list_get_category(EntryListHandle handle, + int32_t index, const char **category); -ErrorCode askar_entry_list_get_name(EntryListHandle handle, int32_t index, - const char **name); +ErrorCode askar_entry_list_get_name(EntryListHandle handle, int32_t index, const char **name); -ErrorCode askar_entry_list_get_tags(EntryListHandle handle, int32_t index, - const char **tags); +ErrorCode askar_entry_list_get_tags(EntryListHandle handle, int32_t index, const char **tags); -ErrorCode askar_entry_list_get_value(EntryListHandle handle, int32_t index, +ErrorCode askar_entry_list_get_value(EntryListHandle handle, + int32_t index, struct SecretBuffer *value); ErrorCode askar_get_current_error(const char **error_json_p); ErrorCode askar_key_aead_decrypt(LocalKeyHandle handle, struct ByteBuffer ciphertext, - struct ByteBuffer nonce, struct ByteBuffer tag, + struct ByteBuffer nonce, + struct ByteBuffer tag, struct ByteBuffer aad, struct SecretBuffer *out); ErrorCode askar_key_aead_encrypt(LocalKeyHandle handle, struct ByteBuffer message, - struct ByteBuffer nonce, struct ByteBuffer aad, + struct ByteBuffer nonce, + struct ByteBuffer aad, struct EncryptedBuffer *out); -ErrorCode askar_key_aead_get_padding(LocalKeyHandle handle, int64_t msg_len, - int32_t *out); +ErrorCode askar_key_aead_get_padding(LocalKeyHandle handle, int64_t msg_len, int32_t *out); -ErrorCode askar_key_aead_get_params(LocalKeyHandle handle, - struct AeadParams *out); +ErrorCode askar_key_aead_get_params(LocalKeyHandle handle, struct AeadParams *out); -ErrorCode askar_key_aead_random_nonce(LocalKeyHandle handle, - struct SecretBuffer *out); +ErrorCode askar_key_aead_random_nonce(LocalKeyHandle handle, struct SecretBuffer *out); -ErrorCode askar_key_convert(LocalKeyHandle handle, FfiStr alg, - LocalKeyHandle *out); +ErrorCode askar_key_convert(LocalKeyHandle handle, FfiStr alg, LocalKeyHandle *out); ErrorCode askar_key_crypto_box(LocalKeyHandle recip_key, LocalKeyHandle sender_key, @@ -299,54 +292,66 @@ ErrorCode askar_key_crypto_box_seal_open(LocalKeyHandle handle, struct ByteBuffer ciphertext, struct SecretBuffer *out); -ErrorCode -askar_key_derive_ecdh_1pu(FfiStr alg, LocalKeyHandle ephem_key, - LocalKeyHandle sender_key, LocalKeyHandle recip_key, - struct ByteBuffer alg_id, struct ByteBuffer apu, - struct ByteBuffer apv, struct ByteBuffer cc_tag, - int8_t receive, LocalKeyHandle *out); - -ErrorCode askar_key_derive_ecdh_es(FfiStr alg, LocalKeyHandle ephem_key, +ErrorCode askar_key_derive_ecdh_1pu(FfiStr alg, + LocalKeyHandle ephem_key, + LocalKeyHandle sender_key, + LocalKeyHandle recip_key, + struct ByteBuffer alg_id, + struct ByteBuffer apu, + struct ByteBuffer apv, + struct ByteBuffer cc_tag, + int8_t receive, + LocalKeyHandle *out); + +ErrorCode askar_key_derive_ecdh_es(FfiStr alg, + LocalKeyHandle ephem_key, LocalKeyHandle recip_key, struct ByteBuffer alg_id, - struct ByteBuffer apu, struct ByteBuffer apv, - int8_t receive, LocalKeyHandle *out); + struct ByteBuffer apu, + struct ByteBuffer apv, + int8_t receive, + LocalKeyHandle *out); ErrorCode askar_key_entry_list_count(KeyEntryListHandle handle, int32_t *count); void askar_key_entry_list_free(KeyEntryListHandle handle); ErrorCode askar_key_entry_list_get_algorithm(KeyEntryListHandle handle, - int32_t index, const char **alg); + int32_t index, + const char **alg); ErrorCode askar_key_entry_list_get_metadata(KeyEntryListHandle handle, int32_t index, const char **metadata); ErrorCode askar_key_entry_list_get_name(KeyEntryListHandle handle, - int32_t index, const char **name); + int32_t index, + const char **name); ErrorCode askar_key_entry_list_get_tags(KeyEntryListHandle handle, - int32_t index, const char **tags); + int32_t index, + const char **tags); ErrorCode askar_key_entry_list_load_local(KeyEntryListHandle handle, - int32_t index, LocalKeyHandle *out); + int32_t index, + LocalKeyHandle *out); void askar_key_free(LocalKeyHandle handle); ErrorCode askar_key_from_jwk(struct ByteBuffer jwk, LocalKeyHandle *out); -ErrorCode askar_key_from_key_exchange(FfiStr alg, LocalKeyHandle sk_handle, +ErrorCode askar_key_from_key_exchange(FfiStr alg, + LocalKeyHandle sk_handle, LocalKeyHandle pk_handle, LocalKeyHandle *out); -ErrorCode askar_key_from_public_bytes(FfiStr alg, struct ByteBuffer public_, - LocalKeyHandle *out); +ErrorCode askar_key_from_public_bytes(FfiStr alg, struct ByteBuffer public_, LocalKeyHandle *out); -ErrorCode askar_key_from_secret_bytes(FfiStr alg, struct ByteBuffer secret, - LocalKeyHandle *out); +ErrorCode askar_key_from_secret_bytes(FfiStr alg, struct ByteBuffer secret, LocalKeyHandle *out); -ErrorCode askar_key_from_seed(FfiStr alg, struct ByteBuffer seed, FfiStr method, +ErrorCode askar_key_from_seed(FfiStr alg, + struct ByteBuffer seed, + FfiStr method, LocalKeyHandle *out); ErrorCode askar_key_generate(FfiStr alg, int8_t ephemeral, LocalKeyHandle *out); @@ -355,123 +360,160 @@ ErrorCode askar_key_get_algorithm(LocalKeyHandle handle, const char **out); ErrorCode askar_key_get_ephemeral(LocalKeyHandle handle, int8_t *out); -ErrorCode askar_key_get_jwk_public(LocalKeyHandle handle, FfiStr alg, - const char **out); +ErrorCode askar_key_get_jwk_public(LocalKeyHandle handle, FfiStr alg, const char **out); -ErrorCode askar_key_get_jwk_secret(LocalKeyHandle handle, - struct SecretBuffer *out); +ErrorCode askar_key_get_jwk_secret(LocalKeyHandle handle, struct SecretBuffer *out); -ErrorCode askar_key_get_jwk_thumbprint(LocalKeyHandle handle, FfiStr alg, - const char **out); +ErrorCode askar_key_get_jwk_thumbprint(LocalKeyHandle handle, FfiStr alg, const char **out); -ErrorCode askar_key_get_public_bytes(LocalKeyHandle handle, - struct SecretBuffer *out); +ErrorCode askar_key_get_public_bytes(LocalKeyHandle handle, struct SecretBuffer *out); -ErrorCode askar_key_get_secret_bytes(LocalKeyHandle handle, - struct SecretBuffer *out); +ErrorCode askar_key_get_secret_bytes(LocalKeyHandle handle, struct SecretBuffer *out); ErrorCode askar_key_sign_message(LocalKeyHandle handle, - struct ByteBuffer message, FfiStr sig_type, + struct ByteBuffer message, + FfiStr sig_type, struct SecretBuffer *out); -ErrorCode askar_key_unwrap_key(LocalKeyHandle handle, FfiStr alg, +ErrorCode askar_key_unwrap_key(LocalKeyHandle handle, + FfiStr alg, struct ByteBuffer ciphertext, - struct ByteBuffer nonce, struct ByteBuffer tag, + struct ByteBuffer nonce, + struct ByteBuffer tag, LocalKeyHandle *out); ErrorCode askar_key_verify_signature(LocalKeyHandle handle, struct ByteBuffer message, struct ByteBuffer signature, - FfiStr sig_type, int8_t *out); + FfiStr sig_type, + int8_t *out); -ErrorCode askar_key_wrap_key(LocalKeyHandle handle, LocalKeyHandle other, +ErrorCode askar_key_wrap_key(LocalKeyHandle handle, + LocalKeyHandle other, struct ByteBuffer nonce, struct EncryptedBuffer *out); +/** + * Migrate an sqlite wallet from an indy-sdk structure to an aries-askar structure. + * It is important to note that this does not do any post-processing. If the record values, tags, + * names, etc. have changed, it must be processed manually afterwards. This script does the following: + * + * 1. Create and rename the required tables + * 2. Fetch the indy key from the wallet + * 3. Create a new configuration + * 4. Initialize a profile + * 5. Update the items from the indy-sdk + * 6. Clean up (drop tables and add a version of "1") + */ +ErrorCode askar_migrate_indy_sdk(FfiStr spec_uri, + FfiStr wallet_name, + FfiStr wallet_key, + FfiStr kdf_level, + void (*cb)(CallbackId cb_id, ErrorCode err), + CallbackId cb_id); + ErrorCode askar_scan_free(ScanHandle handle); ErrorCode askar_scan_next(ScanHandle handle, - void (*cb)(CallbackId cb_id, ErrorCode err, - EntryListHandle results), + void (*cb)(CallbackId cb_id, ErrorCode err, EntryListHandle results), CallbackId cb_id); -ErrorCode askar_scan_start(StoreHandle handle, FfiStr profile, FfiStr category, - FfiStr tag_filter, int64_t offset, int64_t limit, - void (*cb)(CallbackId cb_id, ErrorCode err, - ScanHandle handle), +ErrorCode askar_scan_start(StoreHandle handle, + FfiStr profile, + FfiStr category, + FfiStr tag_filter, + int64_t offset, + int64_t limit, + void (*cb)(CallbackId cb_id, ErrorCode err, ScanHandle handle), CallbackId cb_id); -ErrorCode askar_session_close(SessionHandle handle, int8_t commit, +ErrorCode askar_session_close(SessionHandle handle, + int8_t commit, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); -ErrorCode -askar_session_count(SessionHandle handle, FfiStr category, FfiStr tag_filter, - void (*cb)(CallbackId cb_id, ErrorCode err, int64_t count), - CallbackId cb_id); +ErrorCode askar_session_count(SessionHandle handle, + FfiStr category, + FfiStr tag_filter, + void (*cb)(CallbackId cb_id, ErrorCode err, int64_t count), + CallbackId cb_id); -ErrorCode askar_session_fetch(SessionHandle handle, FfiStr category, - FfiStr name, int8_t for_update, - void (*cb)(CallbackId cb_id, ErrorCode err, - EntryListHandle results), +ErrorCode askar_session_fetch(SessionHandle handle, + FfiStr category, + FfiStr name, + int8_t for_update, + void (*cb)(CallbackId cb_id, ErrorCode err, EntryListHandle results), CallbackId cb_id); -ErrorCode askar_session_fetch_all(SessionHandle handle, FfiStr category, - FfiStr tag_filter, int64_t limit, +ErrorCode askar_session_fetch_all(SessionHandle handle, + FfiStr category, + FfiStr tag_filter, + int64_t limit, int8_t for_update, - void (*cb)(CallbackId cb_id, ErrorCode err, - EntryListHandle results), + void (*cb)(CallbackId cb_id, ErrorCode err, EntryListHandle results), CallbackId cb_id); -ErrorCode askar_session_fetch_all_keys( - SessionHandle handle, FfiStr alg, FfiStr thumbprint, FfiStr tag_filter, - int64_t limit, int8_t for_update, - void (*cb)(CallbackId cb_id, ErrorCode err, KeyEntryListHandle results), - CallbackId cb_id); +ErrorCode askar_session_fetch_all_keys(SessionHandle handle, + FfiStr alg, + FfiStr thumbprint, + FfiStr tag_filter, + int64_t limit, + int8_t for_update, + void (*cb)(CallbackId cb_id, ErrorCode err, KeyEntryListHandle results), + CallbackId cb_id); -ErrorCode askar_session_fetch_key(SessionHandle handle, FfiStr name, +ErrorCode askar_session_fetch_key(SessionHandle handle, + FfiStr name, int8_t for_update, - void (*cb)(CallbackId cb_id, ErrorCode err, - KeyEntryListHandle results), + void (*cb)(CallbackId cb_id, ErrorCode err, KeyEntryListHandle results), CallbackId cb_id); ErrorCode askar_session_insert_key(SessionHandle handle, - LocalKeyHandle key_handle, FfiStr name, - FfiStr metadata, FfiStr tags, + LocalKeyHandle key_handle, + FfiStr name, + FfiStr metadata, + FfiStr tags, int64_t expiry_ms, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); -ErrorCode askar_session_remove_all(SessionHandle handle, FfiStr category, +ErrorCode askar_session_remove_all(SessionHandle handle, + FfiStr category, FfiStr tag_filter, - void (*cb)(CallbackId cb_id, ErrorCode err, - int64_t removed), + void (*cb)(CallbackId cb_id, ErrorCode err, int64_t removed), CallbackId cb_id); -ErrorCode askar_session_remove_key(SessionHandle handle, FfiStr name, +ErrorCode askar_session_remove_key(SessionHandle handle, + FfiStr name, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); -ErrorCode askar_session_start(StoreHandle handle, FfiStr profile, +ErrorCode askar_session_start(StoreHandle handle, + FfiStr profile, int8_t as_transaction, - void (*cb)(CallbackId cb_id, ErrorCode err, - SessionHandle handle), + void (*cb)(CallbackId cb_id, ErrorCode err, SessionHandle handle), CallbackId cb_id); -ErrorCode askar_session_update(SessionHandle handle, int8_t operation, - FfiStr category, FfiStr name, - struct ByteBuffer value, FfiStr tags, +ErrorCode askar_session_update(SessionHandle handle, + int8_t operation, + FfiStr category, + FfiStr name, + struct ByteBuffer value, + FfiStr tags, int64_t expiry_ms, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); -ErrorCode askar_session_update_key(SessionHandle handle, FfiStr name, - FfiStr metadata, FfiStr tags, +ErrorCode askar_session_update_key(SessionHandle handle, + FfiStr name, + FfiStr metadata, + FfiStr tags, int64_t expiry_ms, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); -ErrorCode askar_set_custom_logger(const void *context, LogCallback log, +ErrorCode askar_set_custom_logger(const void *context, + LogCallback log, struct Option_EnabledCallback enabled, struct Option_FlushCallback flush, int32_t max_level); @@ -484,48 +526,49 @@ ErrorCode askar_store_close(StoreHandle handle, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); -ErrorCode askar_store_create_profile(StoreHandle handle, FfiStr profile, - void (*cb)(CallbackId cb_id, ErrorCode err, - const char *result_p), +ErrorCode askar_store_create_profile(StoreHandle handle, + FfiStr profile, + void (*cb)(CallbackId cb_id, ErrorCode err, const char *result_p), CallbackId cb_id); -ErrorCode askar_store_generate_raw_key(struct ByteBuffer seed, - const char **out); +ErrorCode askar_store_generate_raw_key(struct ByteBuffer seed, const char **out); ErrorCode askar_store_get_profile_name(StoreHandle handle, - void (*cb)(CallbackId cb_id, - ErrorCode err, - const char *name), + void (*cb)(CallbackId cb_id, ErrorCode err, const char *name), CallbackId cb_id); -ErrorCode askar_store_open(FfiStr spec_uri, FfiStr key_method, FfiStr pass_key, +ErrorCode askar_store_open(FfiStr spec_uri, + FfiStr key_method, + FfiStr pass_key, FfiStr profile, - void (*cb)(CallbackId cb_id, ErrorCode err, - StoreHandle handle), + void (*cb)(CallbackId cb_id, ErrorCode err, StoreHandle handle), CallbackId cb_id); -ErrorCode askar_store_provision(FfiStr spec_uri, FfiStr key_method, - FfiStr pass_key, FfiStr profile, +ErrorCode askar_store_provision(FfiStr spec_uri, + FfiStr key_method, + FfiStr pass_key, + FfiStr profile, int8_t recreate, - void (*cb)(CallbackId cb_id, ErrorCode err, - StoreHandle handle), + void (*cb)(CallbackId cb_id, ErrorCode err, StoreHandle handle), CallbackId cb_id); -ErrorCode askar_store_rekey(StoreHandle handle, FfiStr key_method, +ErrorCode askar_store_rekey(StoreHandle handle, + FfiStr key_method, FfiStr pass_key, void (*cb)(CallbackId cb_id, ErrorCode err), CallbackId cb_id); ErrorCode askar_store_remove(FfiStr spec_uri, - void (*cb)(CallbackId cb_id, ErrorCode err, - int8_t), + void (*cb)(CallbackId cb_id, ErrorCode err, int8_t), CallbackId cb_id); -ErrorCode askar_store_remove_profile(StoreHandle handle, FfiStr profile, - void (*cb)(CallbackId cb_id, ErrorCode err, - int8_t removed), +ErrorCode askar_store_remove_profile(StoreHandle handle, + FfiStr profile, + void (*cb)(CallbackId cb_id, ErrorCode err, int8_t removed), CallbackId cb_id); +void askar_terminate(void); + char *askar_version(void); #ifdef __cplusplus From d473a4e526d08b8ff9b332f5f1a8a13957c2558c Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 09:11:09 +0100 Subject: [PATCH 02/11] feat(js): indy-sdk to askar migration Signed-off-by: blu3beri --- .../aries-askar-nodejs/src/NodeJSAriesAskar.ts | 8 ++++++++ .../aries-askar-nodejs/src/library/bindings.ts | 5 +++++ .../aries-askar-react-native/cpp/ariesAskar.cpp | 17 +++++++++++++++++ .../cpp/turboModuleUtility.cpp | 2 +- .../src/ReactNativeAriesAskar.ts | 6 ++++++ .../src/library/NativeBindings.ts | 2 ++ .../src/ariesAskar/AriesAskar.ts | 4 ++++ .../javascript/aries-askar-shared/src/index.ts | 1 + .../aries-askar-shared/src/migration.ts | 14 ++++++++++++++ 9 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 wrappers/javascript/aries-askar-shared/src/migration.ts diff --git a/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts b/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts index b178c7c6..7766291e 100644 --- a/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts +++ b/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts @@ -79,6 +79,7 @@ import type { EncryptedBuffer, AriesAskarErrorObject, AeadParamsOptions, + MigrateIndySdkOptions, } from '@hyperledger/aries-askar-shared' import { @@ -954,4 +955,11 @@ export class NodeJSAriesAskar implements AriesAskar { return handleInvalidNullResponse(response) } + + public async migrateIndySdk(options: MigrateIndySdkOptions): Promise { + const { specUri, kdfLevel, walletKey, walletName } = serializeArguments(options) + await this.promisify((cb, cbId) => + nativeAriesAskar.askar_migrate_indy_sdk(specUri, walletName, walletKey, kdfLevel, cb, cbId) + ) + } } diff --git a/wrappers/javascript/aries-askar-nodejs/src/library/bindings.ts b/wrappers/javascript/aries-askar-nodejs/src/library/bindings.ts index f62134d4..65259aa8 100644 --- a/wrappers/javascript/aries-askar-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/aries-askar-nodejs/src/library/bindings.ts @@ -197,4 +197,9 @@ export const nativeBindings = { askar_store_rekey: [FFI_ERROR_CODE, [FFI_STORE_HANDLE, FFI_STRING, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]], askar_store_remove: [FFI_ERROR_CODE, [FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]], askar_store_remove_profile: [FFI_ERROR_CODE, [FFI_STORE_HANDLE, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]], + + askar_migrate_indy_sdk: [ + FFI_ERROR_CODE, + [FFI_STRING, FFI_STRING, FFI_STRING, FFI_STRING, FFI_CALLBACK_PTR, FFI_CALLBACK_ID], + ], } as const diff --git a/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp b/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp index fb7b47dc..d1015800 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp +++ b/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp @@ -960,4 +960,21 @@ jsi::Value keyEntryListLoadLocal(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); } +jsi::Value storeOpen(jsi::Runtime &rt, jsi::Object options) { + auto specUri = jsiToValue(rt, options, "specUri"); + auto walletName = jsiToValue(rt, options, "walletName"); + auto walletKey = jsiToValue(rt, options, "walletKey"); + auto kdfLevel = jsiToValue(rt, options, "kdfLevel"); + + jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); + State *state = new State(&cb); + state->rt = &rt; + + ErrorCode code = askar_migrate_indy_sdk(specUri.c_str(), walletName.c_str(), + walletKey.c_str(), kdfLevel.c_str(), + callback, CallbackId(state)); + + return createReturnValue(rt, code, nullptr); +} + } // namespace ariesAskar diff --git a/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp b/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp index f47b1c10..a969f86c 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp +++ b/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp @@ -253,7 +253,7 @@ jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, auto valueObject = jsi::Object(rt); valueObject.setProperty(rt, "buffer", - secretBufferToArrayBuffer(rt, value->buffer)); + secretBufferToArrayBuffer(rt, value->buffer)); valueObject.setProperty(rt, "tagPos", int(value->tag_pos)); valueObject.setProperty(rt, "noncePos", int(value->nonce_pos)); diff --git a/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts b/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts index 25a595e4..6acd7dfb 100644 --- a/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts +++ b/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts @@ -45,6 +45,7 @@ import type { KeyUnwrapKeyOptions, KeyVerifySignatureOptions, KeyWrapKeyOptions, + MigrateIndySdkOptions, ScanFreeOptions, ScanNextOptions, ScanStartOptions, @@ -651,4 +652,9 @@ export class ReactNativeAriesAskar implements AriesAskar { return handleInvalidNullResponse(response) } + + public async migrateIndySdk(options: MigrateIndySdkOptions): Promise { + const serializedOptions = serializeArguments(options) + return this.promisify((cb) => handleError(ariesAskarReactNative.migrateIndySdk({ cb, ...serializedOptions }))) + } } diff --git a/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts b/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts index b170b85a..d3c51a34 100644 --- a/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts +++ b/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts @@ -164,4 +164,6 @@ export interface NativeBindings { storeRemove(options: any): ReturnObject storeRemoveProfile(options: any): ReturnObject + + migrateIndySdk(options: any): ReturnObject } diff --git a/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts b/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts index 1c23bffc..c7a9aaa2 100644 --- a/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts +++ b/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts @@ -221,6 +221,8 @@ export type StoreRekeyOptions = { storeHandle: StoreHandle; keyMethod: string; p export type StoreRemoveOptions = { specUri: string } export type StoreRemoveProfileOptions = { storeHandle: StoreHandle; profile: string } +export type MigrateIndySdkOptions = { specUri: string; walletName: string; walletKey: string; kdfLevel: string } + export type AriesAskar = { version(): string getCurrentError(): string @@ -302,4 +304,6 @@ export type AriesAskar = { storeRekey(options: StoreRekeyOptions): Promise storeRemove(options: StoreRemoveOptions): Promise storeRemoveProfile(options: StoreRemoveProfileOptions): Promise + + migrateIndySdk(options: MigrateIndySdkOptions): Promise } diff --git a/wrappers/javascript/aries-askar-shared/src/index.ts b/wrappers/javascript/aries-askar-shared/src/index.ts index 9d718caf..47697a83 100644 --- a/wrappers/javascript/aries-askar-shared/src/index.ts +++ b/wrappers/javascript/aries-askar-shared/src/index.ts @@ -6,3 +6,4 @@ export * from './types' export * from './crypto' export * from './enums' export * from './store' +export * from './migration' diff --git a/wrappers/javascript/aries-askar-shared/src/migration.ts b/wrappers/javascript/aries-askar-shared/src/migration.ts new file mode 100644 index 00000000..7d85faa0 --- /dev/null +++ b/wrappers/javascript/aries-askar-shared/src/migration.ts @@ -0,0 +1,14 @@ +import { ariesAskar } from './ariesAskar' + +type MigrationOptions = { + walletName: string + walletKey: string + specUri: string + kdfLevel: string +} + +export class Migration { + public static async migrate(options: MigrationOptions): Promise { + await ariesAskar.migrateIndySdk(options) + } +} From 27b0a85f607bfae35cb53975bdc4f267efaf8c09 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 09:17:57 +0100 Subject: [PATCH 03/11] fix(js): fixed the nodejs tests Signed-off-by: blu3beri --- .../tests/cryptoBox.test.ts | 6 ++--- .../aries-askar-nodejs/tests/joseEcdh.test.ts | 6 +++-- .../aries-askar-nodejs/tests/keys.test.ts | 7 +++--- .../aries-askar-nodejs/tests/store.test.ts | 7 ++++-- .../tests/utils/initialize.ts | 23 +------------------ 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/cryptoBox.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/cryptoBox.test.ts index ab283e8e..2bc5bd3b 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/cryptoBox.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/cryptoBox.test.ts @@ -1,9 +1,9 @@ import { CryptoBox, Key, KeyAlgs } from '@hyperledger/aries-askar-shared' -import { setup } from './utils' - describe('CryptoBox', () => { - beforeAll(() => setup()) + beforeAll(() => { + require('@hyperledger/aries-askar-nodejs') + }) test('seal', () => { const x25519Key = Key.generate(KeyAlgs.X25519) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/joseEcdh.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/joseEcdh.test.ts index d9bf797b..84e7d1f9 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/joseEcdh.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/joseEcdh.test.ts @@ -1,9 +1,11 @@ import { Ecdh1PU, EcdhEs, Jwk, Key, KeyAlgs } from '@hyperledger/aries-askar-shared' -import { base64url, setup } from './utils' +import { base64url } from './utils' describe('jose ecdh', () => { - beforeAll(() => setup()) + beforeAll(() => { + require('@hyperledger/aries-askar-nodejs') + }) test('ecdh es direct', () => { const bobKey = Key.generate(KeyAlgs.EcSecp256r1) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/keys.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/keys.test.ts index 20a9eb21..dd0069f7 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/keys.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/keys.test.ts @@ -1,9 +1,10 @@ import { Key, KeyAlgs, KeyMethod } from '@hyperledger/aries-askar-shared' -import { setup } from './utils' - describe('keys', () => { - beforeAll(() => setup()) + beforeAll(() => { + require('@hyperledger/aries-askar-nodejs') + }) + test('aes cbc hmac', () => { const key = Key.generate(KeyAlgs.AesA128CbcHs256) expect(key.algorithm).toStrictEqual(KeyAlgs.AesA128CbcHs256) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts index 02db78e7..c6b11dd2 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts @@ -1,13 +1,16 @@ import { Store, StoreKeyMethod, Key, KeyAlgs, AriesAskarError } from '@hyperledger/aries-askar-shared' import { promises } from 'fs' -import { firstEntry, getRawKey, secondEntry, setup, setupWallet, testStoreUri } from './utils' +import { firstEntry, getRawKey, secondEntry, setupWallet, testStoreUri } from './utils' describe('Store and Session', () => { let store: Store + beforeAll(() => { + require('@hyperledger/aries-askar-nodejs') + }) + beforeEach(async () => { - setup() store = await setupWallet() }) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts b/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts index 8a5d10b7..baf63d4a 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts @@ -1,30 +1,9 @@ import '@hyperledger/aries-askar-nodejs' -import { ariesAskar, LogLevel, Store, StoreKeyMethod } from '@hyperledger/aries-askar-shared' +import { Store, StoreKeyMethod } from '@hyperledger/aries-askar-shared' export const getRawKey = () => Store.generateRawKey(Buffer.from('00000000000000000000000000000My1')) export const testStoreUri = process.env.URI || 'sqlite://:memory:' -let fnCounter = 0 -const fnOnce = (fn: () => void) => { - if (!fnCounter) { - fn() - fnCounter++ - } -} - -export const setup = () => { - fnOnce( - () => - process.env.LOG && - ariesAskar.setCustomLogger({ - logger: () => { - /* TODO */ - }, - logLevel: LogLevel.Trace, - }) - ) -} - export const setupWallet = async () => { const key = getRawKey() From 56b78082170703f72d2887ee39f61f67b0634f78 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 10:24:25 +0100 Subject: [PATCH 04/11] test(js): added small migration tests and mock wallet Signed-off-by: blu3beri --- wrappers/javascript/.gitignore | 3 ++ .../tests/indy_wallet_sqlite.db | Bin 0 -> 57344 bytes .../tests/migration.test.ts | 51 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 wrappers/javascript/aries-askar-nodejs/tests/indy_wallet_sqlite.db create mode 100644 wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts diff --git a/wrappers/javascript/.gitignore b/wrappers/javascript/.gitignore index c40d1d56..ff49519a 100644 --- a/wrappers/javascript/.gitignore +++ b/wrappers/javascript/.gitignore @@ -53,6 +53,9 @@ android/keystores/debug.keystore aries-askar-react-native/ios/Frameworks aries-askar-react-native/android/libs +# Test wallet +aries-askar-nodejs/tests/indy_wallet_sqlite_upgraded.db + # Example app react-native-example diff --git a/wrappers/javascript/aries-askar-nodejs/tests/indy_wallet_sqlite.db b/wrappers/javascript/aries-askar-nodejs/tests/indy_wallet_sqlite.db new file mode 100644 index 0000000000000000000000000000000000000000..97c3f25a3a41fe1e7d184f620433c04db37a5370 GIT binary patch literal 57344 zcmeI)-D(?06bJB?>{zxXJG~PW0!ywW7+THju68#mw5q)cCaxUIHZ+7H)JiR){%Rx# zo3*KVT-R}&JpOFr&*W9a!Sdt--gCE(?>fvoAMO3LvAN@Htp4FVe7pJQ=6>m~ z%~GjT{JVIy_D}JXwcpoVT;huY6rcbFC_n)U%nMv>6w04gbJq|1r`_IV|FS*od^c#H zA9wnv!`|hvjeo_QwENxZvzuG3q;Z(IJI(FnOZU!6?q1WKo>&=&tDcn#<)=tnxFhY` z&hbTWdhW(ON$r#cDed{{aj{U2k#Ombgr}X8nS7;t^2v+^>Ev|v-IKLKxmwNr^6{|q z_3=#L>20l#(;PNF-%Vz@*4^>TCTs2;y3M2AU6r05?RozEm>C5+Or9q#cYegn*3K7= z)+_f#@~R@il{+cTP4s7btz_qU(~g;3O;gLlTFJAdl{B}K13P36GB1JD55$!>yH z*=ihYHMW!4t4A-lrIBu5tv+2}DeqNtj;++-hhwB}cP@r!_Va9i>S@j5#prVA^dUkDLsng4oNolpyD>waISk%wyxb{syr{`AhNjlxn>9oqYpH~+3b2_Rm zHMKP9slq+^Y>Q34vFR+^9O&oexqeQEOs9D;-_PmDN?QK^RX;ztx1Up?_NbrJ&nviN zugYD!y;Lac^5p(?acO&U&>mi$_iU}@`#D%1+aEP|_KzmF=lQYH$98;0rYl#9QN3>D z3*~Y-_pW1aS@yd9YiX*Wqj_l^``!24VUAMkC_j3X zyB_U9z5!hvPTuoVJDHqyZ@TimySeLLyKp5NC|Ry#9Q^P_0SZun0u-PC1t>rP3Q%B1 z;MW(qW#_jKe|(JRox$TLuZ@nBuGf|Jw9>U$ML3M>%G7-O(HNt27$}2N7#ZM`XOxLl zq!o^%P#G^$^_mJ|RSy+r`W_}C2*T=6PGhRp2p)tgj8%ZRn4!ZOW+IZt)gV&FU>YvV zRGVIT0TzPrMyA@Vby=Y=$+W>p3@|m!L;w%@YsyD1Ez6dK2#>`YtTdD$zB00~Aduw1k!r$`?}`N>-^o zEJ@f9GnUf`sgTXbK+FKNltz-uUdajp{El zpgrP3Q&Lo6rcbFGAytzd*kzehAYgiQGfyzpa2CZKmiI+fC3bt00kU}zyD_! zP=Epypa2CZKmiI+fC3bt00puyz~BF8zsB4l1t>rP3Q&Lo6rcbFC_n)UP=L?>>;Vc; zfC3bt00k&O0SZun0u-P?_67L-pZywhhZLXy1t>rP3Q&Lo6rcbFC_n)||FZ`uKmiI+ zfC3bt00k&O0SZun0@)Yf|Noc$8gqvfpa2CZKmiI+fC3bt00k&O0sj7 { + beforeAll(() => { + require('@hyperledger/aries-askar-nodejs') + }) + + beforeEach(() => { + const tplPaths = [DB_TEMPLATE_PATH, `${DB_TEMPLATE_PATH}-shm`, `${DB_TEMPLATE_PATH}-wal`] + + const updPaths = [DB_UPGRADE_PATH, `${DB_UPGRADE_PATH}-shm`, `${DB_UPGRADE_PATH}-wal`] + + for (let i = 0; i <= 3; i++) { + const tplPath = tplPaths[i] + const updPath = updPaths[i] + + if (fs.existsSync(tplPath)) { + fs.copyFileSync(tplPath, updPath) + } else { + fs.existsSync(updPath) && fs.rmSync(updPath) + } + } + }) + + test('migrate', async () => { + ariesAskar.setDefaultLogger() + await expect( + Migration.migrate({ + specUri: DB_UPGRADE_PATH, + kdfLevel: 'RAW', + walletName: 'walletwallet.0', + walletKey: 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A', + }) + ).resolves.toBeUndefined() + + // Double migrate should not work + await expect( + Migration.migrate({ + specUri: DB_UPGRADE_PATH, + kdfLevel: 'RAW', + walletName: 'walletwallet.0', + walletKey: 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A', + }) + ).rejects.toThrowError('Database is already migrated') + }) +}) From dc21dc766a459b65acdeb14f6d989cb3dd9d71e8 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 10:26:36 +0100 Subject: [PATCH 05/11] fix(js): use the correct name for the RN function Signed-off-by: blu3beri --- wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp b/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp index d1015800..9e0230b3 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp +++ b/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.cpp @@ -960,7 +960,7 @@ jsi::Value keyEntryListLoadLocal(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); } -jsi::Value storeOpen(jsi::Runtime &rt, jsi::Object options) { +jsi::Value migrateIndySdk(jsi::Runtime &rt, jsi::Object options) { auto specUri = jsiToValue(rt, options, "specUri"); auto walletName = jsiToValue(rt, options, "walletName"); auto walletKey = jsiToValue(rt, options, "walletKey"); From 7b983a194069ba87f5ac89696d15be7a20e84164 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 10:53:35 +0100 Subject: [PATCH 06/11] fix(js): add migrateIndySdk to hostobject Signed-off-by: blu3beri --- wrappers/javascript/aries-askar-react-native/cpp/HostObject.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wrappers/javascript/aries-askar-react-native/cpp/HostObject.cpp b/wrappers/javascript/aries-askar-react-native/cpp/HostObject.cpp index 964b185b..ef70ab02 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/HostObject.cpp +++ b/wrappers/javascript/aries-askar-react-native/cpp/HostObject.cpp @@ -131,6 +131,8 @@ FunctionMap AriesAskarTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert(std::make_tuple("keyEntryListLoadLocal", &ariesAskar::keyEntryListLoadLocal)); + fMap.insert(std::make_tuple("migrateIndySdk", &ariesAskar::migrateIndySdk)); + return fMap; } From ac976335cddfac8e62b4d4feb9f755de04004441 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 10:58:19 +0100 Subject: [PATCH 07/11] fix(js): added migrateIndySdk to header Signed-off-by: blu3beri --- wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.h b/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.h index 5b2c7680..879c72f6 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.h +++ b/wrappers/javascript/aries-askar-react-native/cpp/ariesAskar.h @@ -96,4 +96,6 @@ jsi::Value storeRekey(jsi::Runtime &rt, jsi::Object options); jsi::Value storeRemove(jsi::Runtime &rt, jsi::Object options); jsi::Value storeRemoveProfile(jsi::Runtime &rt, jsi::Object options); +jsi::Value migrateIndySdk(jsi::Runtime &rt, jsi::Object options); + } // namespace ariesAskar From b501e2ede55e6bb0cef700f08dac06dcb2f49e49 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 11:54:13 +0100 Subject: [PATCH 08/11] fix: do not add PAGE_SIZE to the header Signed-off-by: blu3beri --- include/libaries_askar.h | 2 -- src/backend/db_utils.rs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/libaries_askar.h b/include/libaries_askar.h index 48f5e3e3..3dae491f 100644 --- a/include/libaries_askar.h +++ b/include/libaries_askar.h @@ -13,8 +13,6 @@ typedef size_t StoreHandle; typedef size_t SessionHandle; -#define PAGE_SIZE 32 - enum ErrorCode #ifdef __cplusplus : int64_t diff --git a/src/backend/db_utils.rs b/src/backend/db_utils.rs index ef4dd5b2..cd8403d7 100644 --- a/src/backend/db_utils.rs +++ b/src/backend/db_utils.rs @@ -20,6 +20,7 @@ use crate::{ }, }; +/// cbindgen:ignore pub const PAGE_SIZE: usize = 32; pub type Expiry = chrono::DateTime; From 7959ccb4d2120aafad7e0ef3485cd112e1713cc4 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 12:21:20 +0100 Subject: [PATCH 09/11] fix(js): removed logger setup Signed-off-by: blu3beri --- wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts index 39a7d2e6..c6dc4e53 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts @@ -28,7 +28,6 @@ describe('migration', () => { }) test('migrate', async () => { - ariesAskar.setDefaultLogger() await expect( Migration.migrate({ specUri: DB_UPGRADE_PATH, From be3ef445fd5f8cd10b82f19937e37f6dfc7fd818 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 12:22:18 +0100 Subject: [PATCH 10/11] fix(js): use new header file Signed-off-by: blu3beri --- .../aries-askar-react-native/cpp/include/libaries_askar.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h b/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h index 48f5e3e3..3dae491f 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h +++ b/wrappers/javascript/aries-askar-react-native/cpp/include/libaries_askar.h @@ -13,8 +13,6 @@ typedef size_t StoreHandle; typedef size_t SessionHandle; -#define PAGE_SIZE 32 - enum ErrorCode #ifdef __cplusplus : int64_t From 940c81d6e957fcd219034e98643bb20098ff6162 Mon Sep 17 00:00:00 2001 From: blu3beri Date: Mon, 13 Mar 2023 12:24:32 +0100 Subject: [PATCH 11/11] fix(js): remove intptr_t because it collides on strict Android Signed-off-by: blu3beri --- .../cpp/turboModuleUtility.cpp | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp b/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp index a969f86c..86c7069b 100644 --- a/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp +++ b/wrappers/javascript/aries-askar-react-native/cpp/turboModuleUtility.cpp @@ -167,22 +167,6 @@ jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, return object; } -template <> -jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, - intptr_t *value) { - auto object = jsi::Object(rt); - - if (code == ErrorCode::Success) { - auto valueWithoutNullptr = - value == nullptr ? jsi::Value::null() : jsi::Value(int(*value)); - object.setProperty(rt, "value", valueWithoutNullptr); - } - - object.setProperty(rt, "errorCode", int(code)); - - return object; -} - template <> jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, std::string value) { @@ -220,7 +204,7 @@ jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, auto isNullptr = value == nullptr || value->_0 == nullptr; return isNullptr ? createReturnValue(rt, code, nullptr) - : createReturnValue(rt, code, std::to_string(intptr_t(value->_0))); + : createReturnValue(rt, code, std::to_string(int32_t(value->_0))); } template <> @@ -229,7 +213,7 @@ jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, auto isNullptr = value == nullptr || value->_0 == nullptr; return isNullptr ? createReturnValue(rt, code, nullptr) - : createReturnValue(rt, code, std::to_string(intptr_t(value->_0))); + : createReturnValue(rt, code, std::to_string(int32_t(value->_0))); } template <> @@ -238,7 +222,7 @@ jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code, auto isNullptr = value == nullptr || value->_0 == nullptr; return isNullptr ? createReturnValue(rt, code, nullptr) - : createReturnValue(rt, code, std::to_string(intptr_t(value->_0))); + : createReturnValue(rt, code, std::to_string(int32_t(value->_0))); } template <>