{"id":18767085,"url":"https://github.com/withpaceio/react-native-nacl-jsi","last_synced_at":"2025-04-13T06:32:21.723Z","repository":{"id":59891338,"uuid":"538811743","full_name":"withpaceio/react-native-nacl-jsi","owner":"withpaceio","description":"Sodium library for React Native with JSI binding","archived":false,"fork":false,"pushed_at":"2024-07-02T06:43:59.000Z","size":35896,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T23:11:42.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/withpaceio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-20T04:40:12.000Z","updated_at":"2024-12-19T16:04:58.000Z","dependencies_parsed_at":"2024-05-14T03:45:00.214Z","dependency_job_id":"0c4d0004-2435-4115-a837-dd4fc66b325b","html_url":"https://github.com/withpaceio/react-native-nacl-jsi","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"94943e4b7151ae74ce883933176854715640f53f"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/withpaceio%2Freact-native-nacl-jsi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/withpaceio%2Freact-native-nacl-jsi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/withpaceio%2Freact-native-nacl-jsi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/withpaceio%2Freact-native-nacl-jsi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/withpaceio","download_url":"https://codeload.github.com/withpaceio/react-native-nacl-jsi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674674,"owners_count":21143760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T19:06:17.990Z","updated_at":"2025-04-13T06:32:16.682Z","avatar_url":"https://github.com/withpaceio.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-nacl-jsi\n\nSodium library for React Native with JSI binding.\n\n## Features\n\n- ⚡️ High performance integration of the Sodium library written in C++\n- 🔗 Synchronous calls without the bridge, uses [JSI](https://reactnative.dev/docs/the-new-architecture/landing-page#fast-javascriptnative-interfacing)\n- 🧩 Compatible with the new architecture\n\n## Source compilation\n\nPrecompiled binaries of [libsodium](https://libsodium.org) will be linked by default.\nOptionally, you can choose to compile libsodium by yourself (run **npm\u0026nbsp;run\u0026nbsp;rebuild** in package directory). Source code will be downloaded and verified before compilation.\n\n### MacOS prerequisites\n\n- libtool (macports, homebrew)\n- autoconf (macports, homebrew)\n- automake (macports, homebrew)\n- Xcode (12 or newer)\n\n### Android prerequisites\n\n- Android NDK\n- CMake\n- LLDB\n\n### Recompile\n\n```sh\nnpm run rebuild\n```\n\n## Installation\n\nUsing Hermes on Android is required.\n\n```sh\nnpm install react-native-nacl-jsi\nnpx pod-install\n```\n\n## Usage\n\n## Encoding/decoding\n\nAll functions takes and returns `Uint8Array`.\nThere are helper functions that support encoding and decoding to and from UTF-8, hexadecimal and base64 strings.\n\n## Example\n\n```js\nimport {\n  secretboxGenerateKey,\n  secretboxSeal,\n  secretboxOpen,\n} from 'react-native-nacl-jsi';\n\nconst key = secretboxGenerateKey();\nconst encrypted = secretboxSeal(decodeUtf8('encrypt me'), key);\nconst decrypted = secretboxOpen(encrypted, key);\n\nconsole.log(encodeUtf8(decrypted));\n```\n\n## Public-key authenticated encryption (box)\n\nGenerates a random key pair for box and returns a `KeyPair`:\n\n```ts\nfunction boxGenerateKey(): KeyPair;\n\n// With KeyPair:\ntype KeyPair = {\n  publicKey: Uint8Array;\n  secretKey: Uint8Array;\n};\n```\n\nEncrypts and authenticates message using the recipient's public key and the sender's secret key:\n\n```ts\nfunction boxSeal(\n  message: Uint8Array,\n  recipientPublicKey: Uint8Array,\n  senderSecretKey: Uint8Array\n): Uint8Array;\n```\n\nAuthenticates and decrypts the encrypted message using the sender's public key and the recipient's secret key:\n\n```ts\nfunction boxOpen(\n  encryptedMessage: Uint8Array,\n  senderPublicKey: Uint8Array,\n  recipientSecretKey: Uint8Array\n): Uint8Array;\n```\n\n## Secret-key authenticated encryption (secretbox)\n\nGenerates a random key for secretbox:\n\n```ts\nfunction secretboxGenerateKey(): Uint8Array;\n```\n\nEncrypts and authenticates message using the key:\n\n```ts\nfunction secretboxSeal(message: Uint8Array, secretKey: Uint8Array): Uint8Array;\n```\n\nAuthenticates and decrypts the encrypted message using the key:\n\n```ts\nfunction secretboxOpen(\n  encryptedMessage: Uint8Array,\n  secretKey: Uint8Array\n): Uint8Array;\n```\n\n## Signature\n\nGenerates a signing key pair:\n\n```ts\nfunction signGenerateKey(): KeyPair;\n\n// With KeyPair:\ntype KeyPair = {\n  publicKey: Uint8Array;\n  secretKey: Uint8Array;\n};\n```\n\nSigns a message and returns the signature:\n\n```ts\nfunction signDetached(\n  messageToSign: Uint8Array,\n  secretKey: Uint8Array\n): Uint8Array;\n```\n\nVerifies a signature:\n\n```ts\nfunction signVerifyDetached(\n  message: Uint8Array,\n  publicKey: Uint8Array,\n  signature: Uint8Array\n): boolean;\n```\n\n## Password hashing\n\nHash the password using the Argon2id algorithm:\n\n```ts\nfunction argon2idHash(\n  password: Uint8Array,\n  iterations: BigInt,\n  memoryLimit: BigInt\n): Promise\u003cstring\u003e;\n```\n\nVerifies a hash and returns `true` if the hash matches the password:\n\n```ts\nfunction argon2idVerify(hash: string, password: Uint8Array): Promise\u003cboolean\u003e;\n```\n\n## Key derivation\n\nDerives the key using a salt and the Argon2id algorithm:\n\n```ts\nfunction argon2idDeriveKey(\n  key: Uint8Array,\n  salt: Uint8Array,\n  keyLength: number,\n  iterations: BigInt,\n  memoryLimit: BigInt\n): Promise\u003cUint8Array\u003e;\n```\n\n## AES256-GCM\n\nGenerates a random key to use for AES256-GCM encryption:\n\n```ts\nfunction aesGenerateKey(): Uint8Array;\n```\n\nEncrypts the message using the key and returns a `AesResult`:\n\n```ts\nfunction aesEncrypt(message: Uint8Array, key: Uint8Array): Promise\u003cAesResult\u003e;\n\n// With AesResult:\ntype AesResult = {\n  encrypted: Uint8Array;\n  iv: Uint8Array;\n};\n```\n\nDecrypts the encrypted message using the initialisation vector `iv` and the key:\n\n```ts\nfunction aesDecrypt(\n  cipherText: Uint8Array,\n  key: Uint8Array,\n  iv: Uint8Array\n): Promise\u003cUint8Array\u003e;\n```\n\n## Generates random bytes\n\n```ts\nfunction getRandomBytes(size: number | BigInt): Uint8Array;\n```\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## Author\n\nRémy Dautriche ([@remydautriche](https://twitter.com/remydautriche))\n\n[PACE](https://withpace.io), a private fitness tracker, implements its cryptography using `react-native-nacl-jsi`.\n\n\u003cdiv\u003e\n  \u003ca href=\"https://apps.apple.com/app/pace-privacy/id6444367013\"\u003e\n    \u003cimg height=\"40\" src=\"/assets/img/appstore.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://play.google.com/store/apps/details?id=io.withpace.pace\"\u003e\n    \u003cimg height=\"40\" src=\"/assets/img/googleplay.svg\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwithpaceio%2Freact-native-nacl-jsi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwithpaceio%2Freact-native-nacl-jsi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwithpaceio%2Freact-native-nacl-jsi/lists"}