Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import {
crypto_sign_SEEDBYTES,
crypto_sign_verify_detached,
from_base64,
from_hex,
randombytes_buf,
randombytes_uniform,
to_base64,
Expand Down
36 changes: 36 additions & 0 deletions cpp/react-native-libsodium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,42 @@ namespace ReactNativeLibsodium

jsiRuntime.global().setProperty(jsiRuntime, "jsi_to_base64", std::move(jsi_to_base64));

auto jsi_from_hex_to_arraybuffer = jsi::Function::createFromHostFunction(
jsiRuntime,
jsi::PropNameID::forUtf8(jsiRuntime, "from_hex"),
2,
[](jsi::Runtime &runtime, const jsi::Value &thisValue, const jsi::Value *arguments, size_t count) -> jsi::Value
{
const std::string functionName = "from_hex";

std::string valueArgumentName = "value";
unsigned int valueArgumentPosition = 0;
validateRequired(functionName, runtime, arguments[valueArgumentPosition], valueArgumentName);

std::string hexString = arguments[0].asString(runtime).utf8(runtime);

std::vector<uint8_t> uint8Vector;
uint8Vector.resize(hexString.size());

size_t length = 0;
int result = sodium_hex2bin(
reinterpret_cast<unsigned char *>(uint8Vector.data()),
uint8Vector.size(),
reinterpret_cast<const char *>(hexString.data()),
hexString.size(),
nullptr,
&length,
nullptr);

throwOnBadResult(functionName, runtime, result);

uint8Vector.resize(length);
jsi::Object returnBufferAsObject = arrayBufferAsObject(runtime, uint8Vector);
return returnBufferAsObject;
});

jsiRuntime.global().setProperty(jsiRuntime, "jsi_from_hex_to_arraybuffer", std::move(jsi_from_hex_to_arraybuffer));

auto jsi_to_hex = jsi::Function::createFromHostFunction(
jsiRuntime,
jsi::PropNameID::forUtf8(jsiRuntime, "jsi_to_hex"),
Expand Down
13 changes: 13 additions & 0 deletions example/ios/LibsodiumExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -598,6 +599,10 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
};
Expand Down Expand Up @@ -639,6 +644,10 @@
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -662,6 +671,10 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
Loading