lyubo / react-native-sodium

ISC License
61 stars 46 forks source link

crypto_sign_detached is failing #52

Closed nikgraf closed 2 years ago

nikgraf commented 2 years ago
import sodium from "react-native-sodium-expo-plugin";

const keypair = await sodium.crypto_sign_keypair();
try {
  const signature = await sodium.crypto_sign_detached(
    "Hello",
    keypair.sk
  );
  console.log("signature", signature);
} catch (err) {
  console.log(err);
}

Fails with:


FAILURE

Stack trace:
  /mypath/node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:104:50 in promiseMethodWrapper
  screens/LibsodiumTestScreen.tsx:20:32 in run
  /mypath/node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
  /mypath/node_modules/regenerator-runtime/runtime.js:294:29 in invoke
  /mypath/node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
  /mypath/node_modules/regenerator-runtime/runtime.js:155:27 in invoke
  /mypath/node_modules/regenerator-runtime/runtime.js:165:18 in PromiseImpl.resolve.then$argument_0
  /mypath/node_modules/promise/setimmediate/core.js:37:13 in tryCallOne
  /mypath/node_modules/promise/setimmediate/core.js:123:24 in setImmediate$argument_0
  /mypath/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:123:14 in _callTimer
  /mypath/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:177:14 in _callImmediatesPass
  /mypath/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:437:30 in callImmediates
  /mypath/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:388:6 in __callImmediates
  /mypath/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:132:6 in __guard$argument_0
  /mypath/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:365:10 in __guard
  /mypath/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:131:4 in flushedQueue
  [native code]:null in flushedQueue
  [native code]:null in invokeCallbackAndReturnFlushedQueue

I also couldn't find any tests for it in https://github.com/lyubo/react-native-sodium-example

nikgraf commented 2 years ago

I realised also the message must be base64 encoded