#include "ariesAskar.h" #include "include/libaries_askar.h" using namespace ariesAskarTurboModuleUtility; namespace ariesAskar { jsi::Value version(jsi::Runtime &rt, jsi::Object options) { return jsi::String::createFromAscii(rt, askar_version()); } jsi::Value getCurrentError(jsi::Runtime &rt, jsi::Object options) { const char *error; askar_get_current_error(&error); return jsi::String::createFromAscii(rt, error); } jsi::Value setDefaultLogger(jsi::Runtime &rt, jsi::Object options) { ErrorCode code = askar_set_default_logger(); return createReturnValue(rt, code, nullptr); } jsi::Value entryListCount(jsi::Runtime &rt, jsi::Object options) { auto entryListHandle = jsiToValue(rt, options, "entryListHandle"); int32_t out; ErrorCode code = askar_entry_list_count(entryListHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value entryListFree(jsi::Runtime &rt, jsi::Object options) { auto entryListHandle = jsiToValue(rt, options, "entryListHandle"); askar_entry_list_free(entryListHandle); return createReturnValue(rt, ErrorCode::Success, nullptr); } jsi::Value entryListGetCategory(jsi::Runtime &rt, jsi::Object options) { auto entryListHandle = jsiToValue(rt, options, "entryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_entry_list_get_category(entryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value entryListGetTags(jsi::Runtime &rt, jsi::Object options) { auto entryListHandle = jsiToValue(rt, options, "entryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_entry_list_get_tags(entryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value entryListGetValue(jsi::Runtime &rt, jsi::Object options) { auto entryListHandle = jsiToValue(rt, options, "entryListHandle"); auto index = jsiToValue(rt, options, "index"); SecretBuffer out; ErrorCode code = askar_entry_list_get_value(entryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value entryListGetName(jsi::Runtime &rt, jsi::Object options) { auto entryListHandle = jsiToValue(rt, options, "entryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_entry_list_get_name(entryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value storeCopyTo(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto targetUri = jsiToValue(rt, options, "targetUri"); auto keyMethod = jsiToValue(rt, options, "keyMethod", true); auto passKey = jsiToValue(rt, options, "passKey", true); auto recreate = jsiToValue(rt, options, "recreate"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_copy( storeHandle, targetUri.c_str(), keyMethod.length() ? keyMethod.c_str() : nullptr, passKey.length() ? passKey.c_str() : nullptr, recreate, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeOpen(jsi::Runtime &rt, jsi::Object options) { auto specUri = jsiToValue(rt, options, "specUri"); auto keyMethod = jsiToValue(rt, options, "keyMethod", true); auto passKey = jsiToValue(rt, options, "passKey", true); auto profile = jsiToValue(rt, options, "profile", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_open( specUri.c_str(), keyMethod.length() ? keyMethod.c_str() : nullptr, passKey.length() ? passKey.c_str() : nullptr, profile.length() ? profile.c_str() : nullptr, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeProvision(jsi::Runtime &rt, jsi::Object options) { auto specUri = jsiToValue(rt, options, "specUri"); auto keyMethod = jsiToValue(rt, options, "keyMethod", true); auto passKey = jsiToValue(rt, options, "passKey", true); auto profile = jsiToValue(rt, options, "profile", true); auto recreate = jsiToValue(rt, options, "recreate"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_provision( specUri.c_str(), keyMethod.length() ? keyMethod.c_str() : nullptr, passKey.length() ? passKey.c_str() : nullptr, profile.length() ? profile.c_str() : nullptr, recreate, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeGenerateRawKey(jsi::Runtime &rt, jsi::Object options) { auto seed = jsiToValue(rt, options, "seed", true); const char *out; ErrorCode code = askar_store_generate_raw_key(seed, &out); return createReturnValue(rt, code, &out); } jsi::Value storeClose(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_close(storeHandle, callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeCreateProfile(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto profile = jsiToValue(rt, options, "profile", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_create_profile( storeHandle, profile.length() ? profile.c_str() : nullptr, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeGetProfileName(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_get_profile_name( storeHandle, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeGetDefaultProfile(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_get_default_profile( storeHandle, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeListProfiles(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_list_profiles( storeHandle, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeRekey(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto keyMethod = jsiToValue(rt, options, "keyMethod", true); auto passKey = jsiToValue(rt, options, "passKey"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_rekey(storeHandle, keyMethod.length() ? keyMethod.c_str() : nullptr, passKey.c_str(), callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeRemove(jsi::Runtime &rt, jsi::Object options) { auto specUri = jsiToValue(rt, options, "specUri"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_remove(specUri.c_str(), callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeRemoveProfile(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto profile = jsiToValue(rt, options, "profile"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_remove_profile( storeHandle, profile.c_str(), callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value storeSetDefaultProfile(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto profile = jsiToValue(rt, options, "profile"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_store_set_default_profile( storeHandle, profile.c_str(), callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionClose(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); int8_t commit = jsiToValue(rt, options, "commit"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_close(sessionHandle, commit, callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionCount(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto category = jsiToValue(rt, options, "category"); auto tagFilter = jsiToValue(rt, options, "tagFilter", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_count(sessionHandle, category.c_str(), tagFilter.length() ? tagFilter.c_str() : nullptr, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionFetch(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto category = jsiToValue(rt, options, "category"); auto name = jsiToValue(rt, options, "name"); int8_t forUpdate = jsiToValue(rt, options, "forUpdate"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_fetch(sessionHandle, category.c_str(), name.c_str(), forUpdate, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionFetchAll(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto category = jsiToValue(rt, options, "category"); auto tagFilter = jsiToValue(rt, options, "tagFilter", true); int64_t limit = jsiToValue(rt, options, "limit", true); int8_t forUpdate = jsiToValue(rt, options, "forUpdate"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_fetch_all( sessionHandle, category.c_str(), tagFilter.length() ? tagFilter.c_str() : nullptr, limit, forUpdate, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionFetchAllKeys(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto algorithm = jsiToValue(rt, options, "algorithm", true); auto thumbprint = jsiToValue(rt, options, "thumbprint", true); auto tagFilter = jsiToValue(rt, options, "tagFilter", true); auto limit = jsiToValue(rt, options, "limit", true); auto forUpdate = jsiToValue(rt, options, "forUpdate"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_fetch_all_keys( sessionHandle, algorithm.length() ? algorithm.c_str() : nullptr, thumbprint.length() ? thumbprint.c_str() : nullptr, tagFilter.length() ? tagFilter.c_str() : nullptr, limit, forUpdate, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionFetchKey(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto name = jsiToValue(rt, options, "name"); auto forUpdate = jsiToValue(rt, options, "forUpdate"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_fetch_key(sessionHandle, name.c_str(), forUpdate, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionInsertKey(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto name = jsiToValue(rt, options, "name"); auto metadata = jsiToValue(rt, options, "metadata", true); auto tags = jsiToValue(rt, options, "tags", true); auto expiryMs = jsiToValue(rt, options, "expiryMs", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_insert_key(sessionHandle, localKeyHandle, name.c_str(), metadata.length() ? metadata.c_str() : nullptr, tags.length() ? tags.c_str() : nullptr, expiryMs, callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionRemoveAll(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto category = jsiToValue(rt, options, "category"); auto tagFilter = jsiToValue(rt, options, "tagFilter", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_remove_all(sessionHandle, category.c_str(), tagFilter.length() ? tagFilter.c_str() : nullptr, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionRemoveKey(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto name = jsiToValue(rt, options, "name"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_remove_key(sessionHandle, name.c_str(), callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionStart(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto profile = jsiToValue(rt, options, "profile", true); int8_t asTransaction = jsiToValue(rt, options, "asTransaction"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_start( storeHandle, profile.length() ? profile.c_str() : nullptr, asTransaction, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionUpdate(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); int8_t operation = jsiToValue(rt, options, "operation"); auto category = jsiToValue(rt, options, "category"); auto name = jsiToValue(rt, options, "name"); auto tags = jsiToValue(rt, options, "tags", true); auto value = jsiToValue(rt, options, "value", true); int64_t expiryMs = jsiToValue(rt, options, "expiryMs", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_update(sessionHandle, operation, category.c_str(), name.c_str(), value, tags.length() ? tags.c_str() : nullptr, expiryMs, callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value sessionUpdateKey(jsi::Runtime &rt, jsi::Object options) { auto sessionHandle = jsiToValue(rt, options, "sessionHandle"); auto name = jsiToValue(rt, options, "name"); auto tags = jsiToValue(rt, options, "tags", true); auto metadata = jsiToValue(rt, options, "metadata", true); auto expiryMs = jsiToValue(rt, options, "expiryMs", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_session_update_key(sessionHandle, name.c_str(), metadata.length() ? metadata.c_str() : nullptr, tags.length() ? tags.c_str() : nullptr, expiryMs, callback, CallbackId(state)); return createReturnValue(rt, code, nullptr); } jsi::Value scanStart(jsi::Runtime &rt, jsi::Object options) { auto storeHandle = jsiToValue(rt, options, "storeHandle"); auto category = jsiToValue(rt, options, "category"); auto tagFilter = jsiToValue(rt, options, "tagFilter", true); auto profile = jsiToValue(rt, options, "profile", true); auto offset = jsiToValue(rt, options, "offset", true); auto limit = jsiToValue(rt, options, "limit", true); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_scan_start( storeHandle, profile.length() ? profile.c_str() : nullptr, category.c_str(), tagFilter.length() ? tagFilter.c_str() : nullptr, offset, limit, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); }; jsi::Value scanNext(jsi::Runtime &rt, jsi::Object options) { auto scanHandle = jsiToValue(rt, options, "scanHandle"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); state->rt = &rt; ErrorCode code = askar_scan_next(scanHandle, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); }; jsi::Value scanFree(jsi::Runtime &rt, jsi::Object options) { auto scanHandle = jsiToValue(rt, options, "scanHandle"); ErrorCode code = askar_scan_free(scanHandle); return createReturnValue(rt, code, nullptr); }; jsi::Value keyFromJwk(jsi::Runtime &rt, jsi::Object options) { auto jwk = jsiToValue(rt, options, "jwk"); LocalKeyHandle out; ErrorCode code = askar_key_from_jwk(jwk, &out); return createReturnValue(rt, code, &out); } jsi::Value keyFromKeyExchange(jsi::Runtime &rt, jsi::Object options) { auto algorithm = jsiToValue(rt, options, "algorithm"); auto skHandle = jsiToValue(rt, options, "skHandle"); auto pkHandle = jsiToValue(rt, options, "pkHandle"); LocalKeyHandle out; ErrorCode code = askar_key_from_key_exchange(algorithm.c_str(), skHandle, pkHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyFromPublicBytes(jsi::Runtime &rt, jsi::Object options) { auto algorithm = jsiToValue(rt, options, "algorithm"); auto publicKey = jsiToValue(rt, options, "publicKey"); LocalKeyHandle out; ErrorCode code = askar_key_from_public_bytes(algorithm.c_str(), publicKey, &out); return createReturnValue(rt, code, &out); } jsi::Value keyFromSecretBytes(jsi::Runtime &rt, jsi::Object options) { auto algorithm = jsiToValue(rt, options, "algorithm"); auto secretKey = jsiToValue(rt, options, "secretKey"); LocalKeyHandle out; ErrorCode code = askar_key_from_secret_bytes(algorithm.c_str(), secretKey, &out); return createReturnValue(rt, code, &out); } jsi::Value keyFromSeed(jsi::Runtime &rt, jsi::Object options) { auto algorithm = jsiToValue(rt, options, "algorithm"); auto seed = jsiToValue(rt, options, "seed"); auto method = jsiToValue(rt, options, "method"); LocalKeyHandle out; ErrorCode code = askar_key_from_seed(algorithm.c_str(), seed, method.c_str(), &out); return createReturnValue(rt, code, &out); } jsi::Value keyGenerate(jsi::Runtime &rt, jsi::Object options) { auto algorithm = jsiToValue(rt, options, "algorithm"); auto ephemeral = jsiToValue(rt, options, "ephemeral"); LocalKeyHandle out; ErrorCode code = askar_key_generate(algorithm.c_str(), ephemeral, &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetAlgorithm(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); const char *out; ErrorCode code = askar_key_get_algorithm(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetEphemeral(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); int8_t out; ErrorCode code = askar_key_get_ephemeral(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetJwkPublic(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto algorithm = jsiToValue(rt, options, "algorithm"); const char *out; ErrorCode code = askar_key_get_jwk_public(localKeyHandle, algorithm.c_str(), &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetJwkSecret(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); SecretBuffer out; ErrorCode code = askar_key_get_jwk_secret(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetJwkThumbprint(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto algorithm = jsiToValue(rt, options, "algorithm"); const char *out; ErrorCode code = askar_key_get_jwk_thumbprint(localKeyHandle, algorithm.c_str(), &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetPublicBytes(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); SecretBuffer out; ErrorCode code = askar_key_get_public_bytes(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyGetSecretBytes(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); SecretBuffer out; ErrorCode code = askar_key_get_secret_bytes(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keySignMessage(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto message = jsiToValue(rt, options, "message"); auto sigType = jsiToValue(rt, options, "sigType", true); SecretBuffer out; ErrorCode code = askar_key_sign_message( localKeyHandle, message, sigType.length() ? sigType.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); } jsi::Value keyUnwrapKey(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto algorithm = jsiToValue(rt, options, "algorithm"); auto ciphertext = jsiToValue(rt, options, "ciphertext"); auto nonce = jsiToValue(rt, options, "nonce", true); auto tag = jsiToValue(rt, options, "tag", true); LocalKeyHandle out; ErrorCode code = askar_key_unwrap_key(localKeyHandle, algorithm.c_str(), ciphertext, nonce, tag, &out); return createReturnValue(rt, code, &out); } jsi::Value keyVerifySignature(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto message = jsiToValue(rt, options, "message"); auto signature = jsiToValue(rt, options, "signature"); auto sigType = jsiToValue(rt, options, "sigType", true); int8_t out; ErrorCode code = askar_key_verify_signature( localKeyHandle, message, signature, sigType.length() ? sigType.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); } jsi::Value keyWrapKey(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto other = jsiToValue(rt, options, "other"); auto nonce = jsiToValue(rt, options, "nonce", true); EncryptedBuffer out; ErrorCode code = askar_key_wrap_key(localKeyHandle, other, nonce, &out); return createReturnValue(rt, code, &out); } jsi::Value keyConvert(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto algorithm = jsiToValue(rt, options, "algorithm"); LocalKeyHandle out; ErrorCode code = askar_key_convert(localKeyHandle, algorithm.c_str(), &out); return createReturnValue(rt, code, &out); }; jsi::Value keyFree(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); askar_key_free(localKeyHandle); return createReturnValue(rt, ErrorCode::Success, nullptr); }; jsi::Value keyCryptoBox(jsi::Runtime &rt, jsi::Object options) { auto recipientKey = jsiToValue(rt, options, "recipientKey"); auto senderKey = jsiToValue(rt, options, "senderKey"); auto message = jsiToValue(rt, options, "message"); auto nonce = jsiToValue(rt, options, "nonce"); SecretBuffer out; ErrorCode code = askar_key_crypto_box(recipientKey, senderKey, message, nonce, &out); return createReturnValue(rt, code, &out); } jsi::Value keyCryptoBoxOpen(jsi::Runtime &rt, jsi::Object options) { auto recipientKey = jsiToValue(rt, options, "recipientKey"); auto senderKey = jsiToValue(rt, options, "senderKey"); auto message = jsiToValue(rt, options, "message"); auto nonce = jsiToValue(rt, options, "nonce"); SecretBuffer out; ErrorCode code = askar_key_crypto_box_open(recipientKey, senderKey, message, nonce, &out); return createReturnValue(rt, code, &out); } jsi::Value keyCryptoBoxRandomNonce(jsi::Runtime &rt, jsi::Object options) { SecretBuffer out; ErrorCode code = askar_key_crypto_box_random_nonce(&out); return createReturnValue(rt, code, &out); } jsi::Value keyCryptoBoxSeal(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto message = jsiToValue(rt, options, "message"); SecretBuffer out; ErrorCode code = askar_key_crypto_box_seal(localKeyHandle, message, &out); return createReturnValue(rt, code, &out); } jsi::Value keyCryptoBoxSealOpen(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto ciphertext = jsiToValue(rt, options, "ciphertext"); SecretBuffer out; ErrorCode code = askar_key_crypto_box_seal_open(localKeyHandle, ciphertext, &out); return createReturnValue(rt, code, &out); } jsi::Value keyDeriveEcdh1pu(jsi::Runtime &rt, jsi::Object options) { auto ephemeralKey = jsiToValue(rt, options, "ephemeralKey"); auto senderKey = jsiToValue(rt, options, "senderKey"); auto recipientKey = jsiToValue(rt, options, "recipientKey"); auto algorithm = jsiToValue(rt, options, "algorithm"); auto algId = jsiToValue(rt, options, "algId"); auto apu = jsiToValue(rt, options, "apu"); auto apv = jsiToValue(rt, options, "apv"); auto ccTag = jsiToValue(rt, options, "ccTag", true); auto receive = jsiToValue(rt, options, "receive"); LocalKeyHandle out; ErrorCode code = askar_key_derive_ecdh_1pu(algorithm.c_str(), ephemeralKey, senderKey, recipientKey, algId, apu, apv, ccTag, receive, &out); return createReturnValue(rt, code, &out); } jsi::Value keyDeriveEcdhEs(jsi::Runtime &rt, jsi::Object options) { auto ephemeralKey = jsiToValue(rt, options, "ephemeralKey"); auto recipientKey = jsiToValue(rt, options, "recipientKey"); auto algorithm = jsiToValue(rt, options, "algorithm"); auto algId = jsiToValue(rt, options, "algId"); auto apu = jsiToValue(rt, options, "apu"); auto apv = jsiToValue(rt, options, "apv"); auto receive = jsiToValue(rt, options, "receive"); LocalKeyHandle out; ErrorCode code = askar_key_derive_ecdh_es(algorithm.c_str(), ephemeralKey, recipientKey, algId, apu, apv, receive, &out); return createReturnValue(rt, code, &out); } jsi::Value keyAeadDecrypt(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto ciphertext = jsiToValue(rt, options, "ciphertext"); auto nonce = jsiToValue(rt, options, "nonce"); auto tag = jsiToValue(rt, options, "tag", true); auto aad = jsiToValue(rt, options, "aad", true); SecretBuffer out; ErrorCode code = askar_key_aead_decrypt(localKeyHandle, ciphertext, nonce, tag, aad, &out); return createReturnValue(rt, code, &out); } jsi::Value keyAeadEncrypt(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto message = jsiToValue(rt, options, "message"); auto nonce = jsiToValue(rt, options, "nonce", true); auto aad = jsiToValue(rt, options, "aad", true); EncryptedBuffer out; ErrorCode code = askar_key_aead_encrypt(localKeyHandle, message, nonce, aad, &out); return createReturnValue(rt, code, &out); } jsi::Value keyAeadGetPadding(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); auto messageLength = jsiToValue(rt, options, "msgLen"); int32_t out; ErrorCode code = askar_key_aead_get_padding(localKeyHandle, messageLength, &out); return createReturnValue(rt, code, &out); } jsi::Value keyAeadGetParams(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); AeadParams out; ErrorCode code = askar_key_aead_get_params(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyAeadRandomNonce(jsi::Runtime &rt, jsi::Object options) { auto localKeyHandle = jsiToValue(rt, options, "localKeyHandle"); SecretBuffer out; ErrorCode code = askar_key_aead_random_nonce(localKeyHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListCount(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); int32_t out; ErrorCode code = askar_key_entry_list_count(keyEntryListHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListFree(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); int32_t out; ErrorCode code = askar_key_entry_list_count(keyEntryListHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListGetAlgorithm(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_key_entry_list_get_algorithm(keyEntryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListGetMetadata(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_key_entry_list_get_metadata(keyEntryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListGetName(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_key_entry_list_get_name(keyEntryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListGetTags(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_key_entry_list_get_tags(keyEntryListHandle, index, &out); return createReturnValue(rt, code, &out); } jsi::Value keyEntryListLoadLocal(jsi::Runtime &rt, jsi::Object options) { auto keyEntryListHandle = jsiToValue(rt, options, "keyEntryListHandle"); auto index = jsiToValue(rt, options, "index"); LocalKeyHandle out; ErrorCode code = askar_key_entry_list_load_local(keyEntryListHandle, index, &out); return createReturnValue(rt, code, &out); } 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"); 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); } jsi::Value stringListCount(jsi::Runtime &rt, jsi::Object options) { auto stringListHandle = jsiToValue(rt, options, "stringListHandle"); int32_t out; ErrorCode code = askar_string_list_count(stringListHandle, &out); return createReturnValue(rt, code, &out); } jsi::Value stringListFree(jsi::Runtime &rt, jsi::Object options) { auto stringListHandle = jsiToValue(rt, options, "stringListHandle"); askar_string_list_free(stringListHandle); return createReturnValue(rt, ErrorCode::Success, nullptr); } jsi::Value stringListGetItem(jsi::Runtime &rt, jsi::Object options) { auto stringListHandle = jsiToValue(rt, options, "stringListHandle"); auto index = jsiToValue(rt, options, "index"); const char *out; ErrorCode code = askar_string_list_get_item(stringListHandle, index, &out); return createReturnValue(rt, code, &out); } } // namespace ariesAskar