react-native-quick-crypto 1.0.0-beta.2 → 1.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QuickCrypto.podspec +143 -7
- package/README.md +12 -6
- package/android/CMakeLists.txt +82 -21
- package/android/build.gradle +47 -4
- package/android/src/main/cpp/cpp-adapter.cpp +3 -10
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +13 -10
- package/app.plugin.js +3 -0
- package/cpp/blake3/HybridBlake3.cpp +118 -0
- package/cpp/blake3/HybridBlake3.hpp +35 -0
- package/cpp/cipher/CCMCipher.cpp +199 -0
- package/cpp/cipher/CCMCipher.hpp +26 -0
- package/cpp/cipher/ChaCha20Cipher.cpp +97 -0
- package/cpp/cipher/ChaCha20Cipher.hpp +25 -0
- package/cpp/cipher/ChaCha20Poly1305Cipher.cpp +170 -0
- package/cpp/cipher/ChaCha20Poly1305Cipher.hpp +30 -0
- package/cpp/cipher/HybridCipher.cpp +322 -0
- package/cpp/cipher/HybridCipher.hpp +68 -0
- package/cpp/cipher/HybridCipherFactory.hpp +97 -0
- package/cpp/cipher/OCBCipher.cpp +55 -0
- package/cpp/cipher/OCBCipher.hpp +19 -0
- package/cpp/cipher/XSalsa20Cipher.cpp +61 -0
- package/cpp/cipher/XSalsa20Cipher.hpp +33 -0
- package/cpp/ec/HybridEcKeyPair.cpp +428 -0
- package/cpp/ec/HybridEcKeyPair.hpp +48 -0
- package/cpp/ed25519/HybridEdKeyPair.cpp +300 -0
- package/cpp/ed25519/HybridEdKeyPair.hpp +63 -0
- package/cpp/hash/HybridHash.cpp +185 -0
- package/cpp/hash/HybridHash.hpp +43 -0
- package/cpp/hmac/HybridHmac.cpp +95 -0
- package/cpp/hmac/HybridHmac.hpp +31 -0
- package/cpp/keys/HybridKeyObjectHandle.cpp +243 -0
- package/cpp/keys/HybridKeyObjectHandle.hpp +42 -0
- package/cpp/keys/KeyObjectData.cpp +226 -0
- package/cpp/keys/KeyObjectData.hpp +71 -0
- package/cpp/keys/node.h +5 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +51 -0
- package/cpp/pbkdf2/HybridPbkdf2.hpp +24 -0
- package/cpp/random/HybridRandom.cpp +32 -18
- package/cpp/random/HybridRandom.hpp +18 -30
- package/cpp/rsa/HybridRsaKeyPair.cpp +154 -0
- package/cpp/rsa/HybridRsaKeyPair.hpp +43 -0
- package/cpp/utils/Macros.hpp +68 -0
- package/cpp/utils/Utils.hpp +53 -1
- package/deps/blake3/.cargo/config.toml +2 -0
- package/deps/blake3/.git-blame-ignore-revs +2 -0
- package/deps/blake3/.github/workflows/build_b3sum.py +38 -0
- package/deps/blake3/.github/workflows/ci.yml +491 -0
- package/deps/blake3/.github/workflows/tag.yml +43 -0
- package/deps/blake3/.github/workflows/upload_github_release_asset.py +73 -0
- package/deps/blake3/CONTRIBUTING.md +31 -0
- package/deps/blake3/Cargo.toml +135 -0
- package/deps/blake3/LICENSE_A2 +202 -0
- package/deps/blake3/LICENSE_A2LLVM +219 -0
- package/deps/blake3/LICENSE_CC0 +121 -0
- package/deps/blake3/README.md +229 -0
- package/deps/blake3/b3sum/Cargo.lock +513 -0
- package/deps/blake3/b3sum/Cargo.toml +26 -0
- package/deps/blake3/b3sum/README.md +72 -0
- package/deps/blake3/b3sum/src/main.rs +564 -0
- package/deps/blake3/b3sum/src/unit_tests.rs +235 -0
- package/deps/blake3/b3sum/tests/cli_tests.rs +680 -0
- package/deps/blake3/b3sum/what_does_check_do.md +176 -0
- package/deps/blake3/benches/bench.rs +623 -0
- package/deps/blake3/build.rs +389 -0
- package/deps/blake3/c/CMakeLists.txt +383 -0
- package/deps/blake3/c/CMakePresets.json +73 -0
- package/deps/blake3/c/Makefile.testing +82 -0
- package/deps/blake3/c/README.md +403 -0
- package/deps/blake3/c/blake3-config.cmake.in +14 -0
- package/deps/blake3/c/blake3.c +650 -0
- package/deps/blake3/c/blake3.h +86 -0
- package/deps/blake3/c/blake3_avx2.c +326 -0
- package/deps/blake3/c/blake3_avx2_x86-64_unix.S +1815 -0
- package/deps/blake3/c/blake3_avx2_x86-64_windows_gnu.S +1817 -0
- package/deps/blake3/c/blake3_avx2_x86-64_windows_msvc.asm +1828 -0
- package/deps/blake3/c/blake3_avx512.c +1388 -0
- package/deps/blake3/c/blake3_avx512_x86-64_unix.S +4824 -0
- package/deps/blake3/c/blake3_avx512_x86-64_windows_gnu.S +2615 -0
- package/deps/blake3/c/blake3_avx512_x86-64_windows_msvc.asm +2634 -0
- package/deps/blake3/c/blake3_c_rust_bindings/Cargo.toml +32 -0
- package/deps/blake3/c/blake3_c_rust_bindings/README.md +4 -0
- package/deps/blake3/c/blake3_c_rust_bindings/benches/bench.rs +477 -0
- package/deps/blake3/c/blake3_c_rust_bindings/build.rs +253 -0
- package/deps/blake3/c/blake3_c_rust_bindings/cross_test.sh +31 -0
- package/deps/blake3/c/blake3_c_rust_bindings/src/lib.rs +333 -0
- package/deps/blake3/c/blake3_c_rust_bindings/src/test.rs +696 -0
- package/deps/blake3/c/blake3_dispatch.c +332 -0
- package/deps/blake3/c/blake3_impl.h +333 -0
- package/deps/blake3/c/blake3_neon.c +366 -0
- package/deps/blake3/c/blake3_portable.c +160 -0
- package/deps/blake3/c/blake3_sse2.c +566 -0
- package/deps/blake3/c/blake3_sse2_x86-64_unix.S +2291 -0
- package/deps/blake3/c/blake3_sse2_x86-64_windows_gnu.S +2332 -0
- package/deps/blake3/c/blake3_sse2_x86-64_windows_msvc.asm +2350 -0
- package/deps/blake3/c/blake3_sse41.c +560 -0
- package/deps/blake3/c/blake3_sse41_x86-64_unix.S +2028 -0
- package/deps/blake3/c/blake3_sse41_x86-64_windows_gnu.S +2069 -0
- package/deps/blake3/c/blake3_sse41_x86-64_windows_msvc.asm +2089 -0
- package/deps/blake3/c/blake3_tbb.cpp +37 -0
- package/deps/blake3/c/dependencies/CMakeLists.txt +3 -0
- package/deps/blake3/c/dependencies/tbb/CMakeLists.txt +28 -0
- package/deps/blake3/c/example.c +36 -0
- package/deps/blake3/c/example_tbb.c +57 -0
- package/deps/blake3/c/libblake3.pc.in +12 -0
- package/deps/blake3/c/main.c +166 -0
- package/deps/blake3/c/test.py +97 -0
- package/deps/blake3/media/B3.svg +70 -0
- package/deps/blake3/media/BLAKE3.svg +85 -0
- package/deps/blake3/media/speed.svg +1474 -0
- package/deps/blake3/reference_impl/Cargo.toml +8 -0
- package/deps/blake3/reference_impl/README.md +14 -0
- package/deps/blake3/reference_impl/reference_impl.rs +374 -0
- package/deps/blake3/src/ffi_avx2.rs +65 -0
- package/deps/blake3/src/ffi_avx512.rs +169 -0
- package/deps/blake3/src/ffi_neon.rs +82 -0
- package/deps/blake3/src/ffi_sse2.rs +126 -0
- package/deps/blake3/src/ffi_sse41.rs +126 -0
- package/deps/blake3/src/guts.rs +60 -0
- package/deps/blake3/src/hazmat.rs +704 -0
- package/deps/blake3/src/io.rs +64 -0
- package/deps/blake3/src/join.rs +92 -0
- package/deps/blake3/src/lib.rs +1835 -0
- package/deps/blake3/src/platform.rs +587 -0
- package/deps/blake3/src/portable.rs +198 -0
- package/deps/blake3/src/rust_avx2.rs +474 -0
- package/deps/blake3/src/rust_sse2.rs +775 -0
- package/deps/blake3/src/rust_sse41.rs +766 -0
- package/deps/blake3/src/test.rs +1049 -0
- package/deps/blake3/src/traits.rs +227 -0
- package/deps/blake3/src/wasm32_simd.rs +794 -0
- package/deps/blake3/test_vectors/Cargo.toml +19 -0
- package/deps/blake3/test_vectors/cross_test.sh +25 -0
- package/deps/blake3/test_vectors/src/bin/generate.rs +4 -0
- package/deps/blake3/test_vectors/src/lib.rs +350 -0
- package/deps/blake3/test_vectors/test_vectors.json +217 -0
- package/deps/blake3/tools/compiler_version/Cargo.toml +7 -0
- package/deps/blake3/tools/compiler_version/build.rs +6 -0
- package/deps/blake3/tools/compiler_version/src/main.rs +27 -0
- package/deps/blake3/tools/instruction_set_support/Cargo.toml +6 -0
- package/deps/blake3/tools/instruction_set_support/src/main.rs +10 -0
- package/deps/blake3/tools/release.md +16 -0
- package/deps/fastpbkdf2/fastpbkdf2.c +356 -0
- package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
- package/deps/ncrypto/ncrypto.cc +4679 -0
- package/deps/ncrypto/ncrypto.h +1625 -0
- package/lib/commonjs/blake3.js +98 -0
- package/lib/commonjs/blake3.js.map +1 -0
- package/lib/commonjs/cipher.js +180 -0
- package/lib/commonjs/cipher.js.map +1 -0
- package/lib/commonjs/ec.js +344 -0
- package/lib/commonjs/ec.js.map +1 -0
- package/lib/commonjs/ed.js +185 -0
- package/lib/commonjs/ed.js.map +1 -0
- package/lib/commonjs/expo-plugin/@types.js +2 -0
- package/lib/commonjs/expo-plugin/@types.js.map +1 -0
- package/lib/commonjs/expo-plugin/withRNQC.js +25 -0
- package/lib/commonjs/expo-plugin/withRNQC.js.map +1 -0
- package/lib/commonjs/expo-plugin/withSodiumAndroid.js +25 -0
- package/lib/commonjs/expo-plugin/withSodiumAndroid.js.map +1 -0
- package/lib/commonjs/expo-plugin/withSodiumIos.js +26 -0
- package/lib/commonjs/expo-plugin/withSodiumIos.js.map +1 -0
- package/lib/commonjs/expo-plugin/withXCode.js +51 -0
- package/lib/commonjs/expo-plugin/withXCode.js.map +1 -0
- package/lib/commonjs/hash.js +215 -0
- package/lib/commonjs/hash.js.map +1 -0
- package/lib/commonjs/hmac.js +109 -0
- package/lib/commonjs/hmac.js.map +1 -0
- package/lib/commonjs/index.js +152 -32
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +250 -0
- package/lib/commonjs/keys/classes.js.map +1 -0
- package/lib/commonjs/keys/generateKeyPair.js +102 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
- package/lib/commonjs/keys/index.js +89 -0
- package/lib/commonjs/keys/index.js.map +1 -0
- package/lib/commonjs/keys/signVerify.js +41 -0
- package/lib/commonjs/keys/signVerify.js.map +1 -0
- package/lib/commonjs/keys/utils.js +123 -0
- package/lib/commonjs/keys/utils.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +89 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +9 -3
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/rsa.js +129 -0
- package/lib/commonjs/rsa.js.map +1 -0
- package/lib/commonjs/specs/blake3.nitro.js +6 -0
- package/lib/commonjs/specs/blake3.nitro.js.map +1 -0
- package/lib/commonjs/specs/cipher.nitro.js +6 -0
- package/lib/commonjs/specs/cipher.nitro.js.map +1 -0
- package/lib/commonjs/specs/ecKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/ecKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/edKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/hash.nitro.js +6 -0
- package/lib/commonjs/specs/hash.nitro.js.map +1 -0
- package/lib/commonjs/specs/hmac.nitro.js +6 -0
- package/lib/commonjs/specs/hmac.nitro.js.map +1 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/commonjs/specs/rsaKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/rsaKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +365 -0
- package/lib/commonjs/subtle.js.map +1 -0
- package/lib/commonjs/utils/cipher.js +64 -0
- package/lib/commonjs/utils/cipher.js.map +1 -0
- package/lib/commonjs/utils/conversion.js +140 -6
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/errors.js +14 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/utils/hashnames.js +91 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -0
- package/lib/commonjs/utils/index.js +65 -5
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/noble.js +82 -0
- package/lib/commonjs/utils/noble.js.map +1 -0
- package/lib/commonjs/utils/types.js +52 -0
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/utils/validation.js +98 -0
- package/lib/commonjs/utils/validation.js.map +1 -0
- package/lib/module/blake3.js +90 -0
- package/lib/module/blake3.js.map +1 -0
- package/lib/module/cipher.js +173 -0
- package/lib/module/cipher.js.map +1 -0
- package/lib/module/ec.js +336 -0
- package/lib/module/ec.js.map +1 -0
- package/lib/module/ed.js +178 -0
- package/lib/module/ed.js.map +1 -0
- package/lib/module/expo-plugin/@types.js +2 -0
- package/lib/module/expo-plugin/@types.js.map +1 -0
- package/lib/module/expo-plugin/withRNQC.js +21 -0
- package/lib/module/expo-plugin/withRNQC.js.map +1 -0
- package/lib/module/expo-plugin/withSodiumAndroid.js +20 -0
- package/lib/module/expo-plugin/withSodiumAndroid.js.map +1 -0
- package/lib/module/expo-plugin/withSodiumIos.js +20 -0
- package/lib/module/expo-plugin/withSodiumIos.js.map +1 -0
- package/lib/module/expo-plugin/withXCode.js +46 -0
- package/lib/module/expo-plugin/withXCode.js.map +1 -0
- package/lib/module/hash.js +207 -0
- package/lib/module/hash.js.map +1 -0
- package/lib/module/hmac.js +104 -0
- package/lib/module/hmac.js.map +1 -0
- package/lib/module/index.js +33 -29
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +241 -0
- package/lib/module/keys/classes.js.map +1 -0
- package/lib/module/keys/generateKeyPair.js +96 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -0
- package/lib/module/keys/index.js +32 -0
- package/lib/module/keys/index.js.map +1 -0
- package/lib/module/keys/signVerify.js +41 -0
- package/lib/module/keys/signVerify.js.map +1 -0
- package/lib/module/keys/utils.js +114 -0
- package/lib/module/keys/utils.js.map +1 -0
- package/lib/module/pbkdf2.js +83 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +7 -1
- package/lib/module/random.js.map +1 -1
- package/lib/module/rsa.js +123 -0
- package/lib/module/rsa.js.map +1 -0
- package/lib/module/specs/blake3.nitro.js +4 -0
- package/lib/module/specs/blake3.nitro.js.map +1 -0
- package/lib/module/specs/cipher.nitro.js +4 -0
- package/lib/module/specs/cipher.nitro.js.map +1 -0
- package/lib/module/specs/ecKeyPair.nitro.js +4 -0
- package/lib/module/specs/ecKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/edKeyPair.nitro.js +4 -0
- package/lib/module/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/hash.nitro.js +4 -0
- package/lib/module/specs/hash.nitro.js.map +1 -0
- package/lib/module/specs/hmac.nitro.js +4 -0
- package/lib/module/specs/hmac.nitro.js.map +1 -0
- package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
- package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/module/specs/pbkdf2.nitro.js +4 -0
- package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/module/specs/rsaKeyPair.nitro.js +4 -0
- package/lib/module/specs/rsaKeyPair.nitro.js.map +1 -0
- package/lib/module/subtle.js +360 -0
- package/lib/module/subtle.js.map +1 -0
- package/lib/module/utils/cipher.js +56 -0
- package/lib/module/utils/cipher.js.map +1 -0
- package/lib/module/utils/conversion.js +120 -8
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/errors.js +10 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/utils/hashnames.js +89 -0
- package/lib/module/utils/hashnames.js.map +1 -0
- package/lib/module/utils/index.js +6 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/noble.js +76 -0
- package/lib/module/utils/noble.js.map +1 -0
- package/lib/module/utils/types.js +53 -0
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/utils/validation.js +87 -0
- package/lib/module/utils/validation.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/blake3.d.ts +33 -0
- package/lib/typescript/blake3.d.ts.map +1 -0
- package/lib/typescript/cipher.d.ts +60 -0
- package/lib/typescript/cipher.d.ts.map +1 -0
- package/lib/typescript/ec.d.ts +13 -0
- package/lib/typescript/ec.d.ts.map +1 -0
- package/lib/typescript/ed.d.ts +43 -0
- package/lib/typescript/ed.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/@types.d.ts +8 -0
- package/lib/typescript/expo-plugin/@types.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withRNQC.d.ts +4 -0
- package/lib/typescript/expo-plugin/withRNQC.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withSodiumAndroid.d.ts +4 -0
- package/lib/typescript/expo-plugin/withSodiumAndroid.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withSodiumIos.d.ts +4 -0
- package/lib/typescript/expo-plugin/withSodiumIos.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withXCode.d.ts +9 -0
- package/lib/typescript/expo-plugin/withXCode.d.ts.map +1 -0
- package/lib/typescript/hash.d.ts +122 -0
- package/lib/typescript/hash.d.ts.map +1 -0
- package/lib/typescript/hmac.d.ts +66 -0
- package/lib/typescript/hmac.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +110 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +79 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts +6 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
- package/lib/typescript/keys/index.d.ts +7 -0
- package/lib/typescript/keys/index.d.ts.map +1 -0
- package/lib/typescript/keys/signVerify.d.ts +1 -0
- package/lib/typescript/keys/signVerify.d.ts.map +1 -0
- package/lib/typescript/keys/utils.d.ts +34 -0
- package/lib/typescript/keys/utils.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +12 -0
- package/lib/typescript/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/random.d.ts +11 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/rsa.d.ts +10 -0
- package/lib/typescript/rsa.d.ts.map +1 -0
- package/lib/typescript/specs/blake3.nitro.d.ts +15 -0
- package/lib/typescript/specs/blake3.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/cipher.nitro.d.ts +29 -0
- package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts +20 -0
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts +17 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/hash.nitro.d.ts +13 -0
- package/lib/typescript/specs/hash.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/hmac.nitro.d.ts +10 -0
- package/lib/typescript/specs/hmac.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +14 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/rsaKeyPair.nitro.d.ts +20 -0
- package/lib/typescript/specs/rsaKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts +17 -0
- package/lib/typescript/subtle.d.ts.map +1 -0
- package/lib/typescript/utils/cipher.d.ts +7 -0
- package/lib/typescript/utils/cipher.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +24 -2
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/errors.d.ts +7 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/utils/hashnames.d.ts +13 -0
- package/lib/typescript/utils/hashnames.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -5
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/noble.d.ts +19 -0
- package/lib/typescript/utils/noble.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +252 -2
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/validation.d.ts +13 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +47 -4
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +4 -3
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +144 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +35 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +11 -8
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +11 -3
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +5 -3
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +16 -7
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +135 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +84 -0
- package/nitrogen/generated/shared/c++/CipherArgs.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +77 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +30 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +92 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +2 -3
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +9 -6
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +77 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +161 -0
- package/nitrogen/generated/shared/c++/JWKkty.hpp +84 -0
- package/nitrogen/generated/shared/c++/JWKuse.hpp +76 -0
- package/nitrogen/generated/shared/c++/KFormatType.hpp +63 -0
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +92 -0
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +64 -0
- package/nitrogen/generated/shared/c++/KeyObject.hpp +67 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +63 -0
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +116 -0
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +80 -0
- package/package.json +66 -39
- package/src/blake3.ts +123 -0
- package/src/cipher.ts +335 -0
- package/src/ec.ts +432 -0
- package/src/ed.ts +256 -0
- package/src/expo-plugin/@types.ts +7 -0
- package/src/expo-plugin/withRNQC.ts +23 -0
- package/src/expo-plugin/withSodiumAndroid.ts +24 -0
- package/src/expo-plugin/withSodiumIos.ts +30 -0
- package/src/expo-plugin/withXCode.ts +55 -0
- package/src/hash.ts +274 -0
- package/src/hmac.ts +135 -0
- package/src/index.ts +32 -29
- package/src/keys/classes.ts +317 -0
- package/src/keys/generateKeyPair.ts +145 -0
- package/src/keys/index.ts +52 -0
- package/src/keys/signVerify.ts +39 -0
- package/src/keys/utils.ts +190 -0
- package/src/pbkdf2.ts +154 -0
- package/src/random.ts +26 -23
- package/src/rsa.ts +176 -0
- package/src/specs/blake3.nitro.ts +12 -0
- package/src/specs/cipher.nitro.ts +25 -0
- package/src/specs/ecKeyPair.nitro.ts +38 -0
- package/src/specs/edKeyPair.nitro.ts +43 -0
- package/src/specs/hash.nitro.ts +10 -0
- package/src/specs/hmac.nitro.ts +7 -0
- package/src/specs/keyObjectHandle.nitro.ts +31 -0
- package/src/specs/pbkdf2.nitro.ts +18 -0
- package/src/specs/random.nitro.ts +2 -2
- package/src/specs/rsaKeyPair.nitro.ts +33 -0
- package/src/subtle.ts +614 -0
- package/src/utils/cipher.ts +60 -0
- package/src/utils/conversion.ts +143 -9
- package/src/utils/errors.ts +15 -0
- package/src/utils/hashnames.ts +98 -0
- package/src/utils/index.ts +6 -6
- package/src/utils/noble.ts +85 -0
- package/src/utils/types.ts +423 -3
- package/src/utils/validation.ts +130 -0
- package/ios/QuickCryptoOnLoad.mm +0 -19
- package/lib/module/package.json +0 -1
package/src/ec.ts
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { EcKeyPair } from './specs/ecKeyPair.nitro';
|
|
3
|
+
import {
|
|
4
|
+
CryptoKey,
|
|
5
|
+
KeyObject,
|
|
6
|
+
PublicKeyObject,
|
|
7
|
+
PrivateKeyObject,
|
|
8
|
+
} from './keys';
|
|
9
|
+
import type {
|
|
10
|
+
CryptoKeyPair,
|
|
11
|
+
KeyPairOptions,
|
|
12
|
+
KeyUsage,
|
|
13
|
+
SubtleAlgorithm,
|
|
14
|
+
BufferLike,
|
|
15
|
+
BinaryLike,
|
|
16
|
+
JWK,
|
|
17
|
+
ImportFormat,
|
|
18
|
+
} from './utils/types';
|
|
19
|
+
import {
|
|
20
|
+
bufferLikeToArrayBuffer,
|
|
21
|
+
getUsagesUnion,
|
|
22
|
+
hasAnyNotIn,
|
|
23
|
+
kNamedCurveAliases,
|
|
24
|
+
lazyDOMException,
|
|
25
|
+
normalizeHashName,
|
|
26
|
+
HashContext,
|
|
27
|
+
KeyEncoding,
|
|
28
|
+
KFormatType,
|
|
29
|
+
} from './utils';
|
|
30
|
+
|
|
31
|
+
export class Ec {
|
|
32
|
+
native: EcKeyPair;
|
|
33
|
+
|
|
34
|
+
constructor(curve: string) {
|
|
35
|
+
this.native = NitroModules.createHybridObject<EcKeyPair>('EcKeyPair');
|
|
36
|
+
this.native.setCurve(curve);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async generateKeyPair(): Promise<CryptoKeyPair> {
|
|
40
|
+
await this.native.generateKeyPair();
|
|
41
|
+
return {
|
|
42
|
+
publicKey: this.native.getPublicKey(),
|
|
43
|
+
privateKey: this.native.getPrivateKey(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
generateKeyPairSync(): CryptoKeyPair {
|
|
48
|
+
this.native.generateKeyPairSync();
|
|
49
|
+
return {
|
|
50
|
+
publicKey: this.native.getPublicKey(),
|
|
51
|
+
privateKey: this.native.getPrivateKey(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// function verifyAcceptableEcKeyUse(
|
|
57
|
+
// name: AnyAlgorithm,
|
|
58
|
+
// isPublic: boolean,
|
|
59
|
+
// usages: KeyUsage[],
|
|
60
|
+
// ): void {
|
|
61
|
+
// let checkSet;
|
|
62
|
+
// switch (name) {
|
|
63
|
+
// case 'ECDH':
|
|
64
|
+
// checkSet = isPublic ? [] : ['deriveKey', 'deriveBits'];
|
|
65
|
+
// break;
|
|
66
|
+
// case 'ECDSA':
|
|
67
|
+
// checkSet = isPublic ? ['verify'] : ['sign'];
|
|
68
|
+
// break;
|
|
69
|
+
// default:
|
|
70
|
+
// throw lazyDOMException(
|
|
71
|
+
// 'The algorithm is not supported',
|
|
72
|
+
// 'NotSupportedError',
|
|
73
|
+
// );
|
|
74
|
+
// }
|
|
75
|
+
// if (hasAnyNotIn(usages, checkSet)) {
|
|
76
|
+
// throw lazyDOMException(
|
|
77
|
+
// `Unsupported key usage for a ${name} key`,
|
|
78
|
+
// 'SyntaxError',
|
|
79
|
+
// );
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
// function createECPublicKeyRaw(
|
|
84
|
+
// namedCurve: NamedCurve | undefined,
|
|
85
|
+
// keyDataBuffer: ArrayBuffer,
|
|
86
|
+
// ): PublicKeyObject {
|
|
87
|
+
// if (!namedCurve) {
|
|
88
|
+
// throw new Error('Invalid namedCurve');
|
|
89
|
+
// }
|
|
90
|
+
// const handle = NitroModules.createHybridObject(
|
|
91
|
+
// 'KeyObjectHandle',
|
|
92
|
+
// ) as KeyObjectHandle;
|
|
93
|
+
|
|
94
|
+
// if (!handle.initECRaw(kNamedCurveAliases[namedCurve], keyDataBuffer)) {
|
|
95
|
+
// console.log('keyData', ab2str(keyDataBuffer));
|
|
96
|
+
// throw new Error('Invalid keyData 1');
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// return new PublicKeyObject(handle);
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
// // Node API
|
|
103
|
+
// export function ec_exportKey(key: CryptoKey, format: KeyFormat): ArrayBuffer {
|
|
104
|
+
// return ec.native.exportKey(format, key.keyObject.handle);
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
// Node API
|
|
108
|
+
export function ecImportKey(
|
|
109
|
+
format: ImportFormat,
|
|
110
|
+
keyData: BufferLike | BinaryLike | JWK,
|
|
111
|
+
algorithm: SubtleAlgorithm,
|
|
112
|
+
extractable: boolean,
|
|
113
|
+
keyUsages: KeyUsage[],
|
|
114
|
+
): CryptoKey {
|
|
115
|
+
const { name, namedCurve } = algorithm;
|
|
116
|
+
|
|
117
|
+
if (
|
|
118
|
+
!namedCurve ||
|
|
119
|
+
!kNamedCurveAliases[namedCurve as keyof typeof kNamedCurveAliases]
|
|
120
|
+
) {
|
|
121
|
+
throw lazyDOMException('Unrecognized namedCurve', 'NotSupportedError');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (format !== 'spki' && format !== 'pkcs8' && format !== 'raw') {
|
|
125
|
+
throw lazyDOMException(
|
|
126
|
+
`Unsupported format: ${format}`,
|
|
127
|
+
'NotSupportedError',
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Handle JWK format separately
|
|
132
|
+
if (typeof keyData === 'object' && 'kty' in keyData) {
|
|
133
|
+
throw lazyDOMException('JWK format not yet supported', 'NotSupportedError');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Convert keyData to ArrayBuffer
|
|
137
|
+
const keyBuffer = bufferLikeToArrayBuffer(keyData as BufferLike);
|
|
138
|
+
|
|
139
|
+
// Create EC instance with the curve
|
|
140
|
+
const ec = new Ec(namedCurve);
|
|
141
|
+
|
|
142
|
+
// Import the key using Nitro module
|
|
143
|
+
ec.native.importKey(
|
|
144
|
+
format === 'raw' ? 'der' : format, // Convert raw to der for now
|
|
145
|
+
keyBuffer,
|
|
146
|
+
name,
|
|
147
|
+
extractable,
|
|
148
|
+
keyUsages,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// Create a KeyObject wrapper for the imported key
|
|
152
|
+
// Use the EC instance's key data to create a proper KeyObject
|
|
153
|
+
const privateKeyData = ec.native.getPrivateKey();
|
|
154
|
+
const keyObject = new KeyObject('private', privateKeyData);
|
|
155
|
+
|
|
156
|
+
// Create and return CryptoKey
|
|
157
|
+
return new CryptoKey(keyObject, algorithm, keyUsages, extractable);
|
|
158
|
+
// // // verifyAcceptableEcKeyUse(name, true, usagesSet);
|
|
159
|
+
// // try {
|
|
160
|
+
// // keyObject = createPublicKey({
|
|
161
|
+
// // key: keyData,
|
|
162
|
+
// // format: 'der',
|
|
163
|
+
// // type: 'spki',
|
|
164
|
+
// // });
|
|
165
|
+
// // } catch (err) {
|
|
166
|
+
// // throw new Error(`Invalid keyData 2: ${err}`);
|
|
167
|
+
// // }
|
|
168
|
+
// // break;
|
|
169
|
+
// // }
|
|
170
|
+
// // case 'pkcs8': {
|
|
171
|
+
// // // verifyAcceptableEcKeyUse(name, false, usagesSet);
|
|
172
|
+
// // try {
|
|
173
|
+
// // keyObject = createPrivateKey({
|
|
174
|
+
// // key: keyData,
|
|
175
|
+
// // format: 'der',
|
|
176
|
+
// // type: 'pkcs8',
|
|
177
|
+
// // });
|
|
178
|
+
// // } catch (err) {
|
|
179
|
+
// // throw new Error(`Invalid keyData 3 ${err}`);
|
|
180
|
+
// // }
|
|
181
|
+
// // break;
|
|
182
|
+
// // }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// case 'jwk': {
|
|
186
|
+
// const data = keyData as JWK;
|
|
187
|
+
|
|
188
|
+
// if (!data.kty) throw lazyDOMException('Invalid keyData 4', 'DataError');
|
|
189
|
+
// if (data.kty !== 'EC')
|
|
190
|
+
// throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
|
|
191
|
+
// if (data.crv !== namedCurve)
|
|
192
|
+
// throw lazyDOMException(
|
|
193
|
+
// 'JWK "crv" does not match the requested algorithm',
|
|
194
|
+
// 'DataError',
|
|
195
|
+
// );
|
|
196
|
+
|
|
197
|
+
// verifyAcceptableEcKeyUse(name, data.d === undefined, keyUsages);
|
|
198
|
+
|
|
199
|
+
// if (keyUsages.length > 0 && data.use !== undefined) {
|
|
200
|
+
// const checkUse = name === 'ECDH' ? 'enc' : 'sig';
|
|
201
|
+
// if (data.use !== checkUse)
|
|
202
|
+
// throw lazyDOMException('Invalid JWK "use" Parameter', 'DataError');
|
|
203
|
+
// }
|
|
204
|
+
|
|
205
|
+
// validateKeyOps(data.key_ops, keyUsages);
|
|
206
|
+
|
|
207
|
+
// if (
|
|
208
|
+
// data.ext !== undefined &&
|
|
209
|
+
// data.ext === false &&
|
|
210
|
+
// extractable === true
|
|
211
|
+
// ) {
|
|
212
|
+
// throw lazyDOMException(
|
|
213
|
+
// 'JWK "ext" Parameter and extractable mismatch',
|
|
214
|
+
// 'DataError',
|
|
215
|
+
// );
|
|
216
|
+
// }
|
|
217
|
+
|
|
218
|
+
// if (algorithm.name === 'ECDSA' && data.alg !== undefined) {
|
|
219
|
+
// let algNamedCurve;
|
|
220
|
+
// switch (data.alg) {
|
|
221
|
+
// case 'ES256':
|
|
222
|
+
// algNamedCurve = 'P-256';
|
|
223
|
+
// break;
|
|
224
|
+
// case 'ES384':
|
|
225
|
+
// algNamedCurve = 'P-384';
|
|
226
|
+
// break;
|
|
227
|
+
// case 'ES512':
|
|
228
|
+
// algNamedCurve = 'P-521';
|
|
229
|
+
// break;
|
|
230
|
+
// }
|
|
231
|
+
// if (algNamedCurve !== namedCurve)
|
|
232
|
+
// throw lazyDOMException(
|
|
233
|
+
// 'JWK "alg" does not match the requested algorithm',
|
|
234
|
+
// 'DataError',
|
|
235
|
+
// );
|
|
236
|
+
// }
|
|
237
|
+
|
|
238
|
+
// const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
|
|
239
|
+
// const type = handle.initJwk(data, namedCurve);
|
|
240
|
+
// if (type === undefined)
|
|
241
|
+
// throw lazyDOMException('Invalid JWK', 'DataError');
|
|
242
|
+
// keyObject =
|
|
243
|
+
// type === KeyType.PRIVATE
|
|
244
|
+
// ? new PrivateKeyObject(handle)
|
|
245
|
+
// : new PublicKeyObject(handle);
|
|
246
|
+
// break;
|
|
247
|
+
// }
|
|
248
|
+
// case 'raw': {
|
|
249
|
+
// const data = keyData as BufferLike | BinaryLike;
|
|
250
|
+
// verifyAcceptableEcKeyUse(name, true, keyUsages);
|
|
251
|
+
// const buffer =
|
|
252
|
+
// typeof data === 'string'
|
|
253
|
+
// ? binaryLikeToArrayBuffer(data)
|
|
254
|
+
// : bufferLikeToArrayBuffer(data);
|
|
255
|
+
// keyObject = createECPublicKeyRaw(namedCurve, buffer);
|
|
256
|
+
// break;
|
|
257
|
+
// }
|
|
258
|
+
// default: {
|
|
259
|
+
// throw new Error(`Unknown EC import format: ${format}`);
|
|
260
|
+
// }
|
|
261
|
+
// }
|
|
262
|
+
|
|
263
|
+
// switch (algorithm.name) {
|
|
264
|
+
// case 'ECDSA':
|
|
265
|
+
// // Fall through
|
|
266
|
+
// case 'ECDH':
|
|
267
|
+
// if (keyObject.asymmetricKeyType !== ('ec' as AsymmetricKeyType))
|
|
268
|
+
// throw new Error('Invalid key type');
|
|
269
|
+
// break;
|
|
270
|
+
// }
|
|
271
|
+
|
|
272
|
+
// // if (!keyObject[kHandle].checkEcKeyData()) {
|
|
273
|
+
// // throw new Error('Invalid keyData 5');
|
|
274
|
+
// // }
|
|
275
|
+
|
|
276
|
+
// // const { namedCurve: checkNamedCurve } = keyObject[kHandle].keyDetail({});
|
|
277
|
+
// // if (kNamedCurveAliases[namedCurve] !== checkNamedCurve)
|
|
278
|
+
// // throw new Error('Named curve mismatch');
|
|
279
|
+
|
|
280
|
+
// return new CryptoKey(keyObject, { name, namedCurve }, keyUsages, extractable);
|
|
281
|
+
// }
|
|
282
|
+
|
|
283
|
+
// Node API
|
|
284
|
+
export const ecdsaSignVerify = (
|
|
285
|
+
key: CryptoKey,
|
|
286
|
+
data: BufferLike,
|
|
287
|
+
{ hash }: SubtleAlgorithm,
|
|
288
|
+
signature?: BufferLike,
|
|
289
|
+
): ArrayBuffer | boolean => {
|
|
290
|
+
const isSign = signature === undefined;
|
|
291
|
+
const expectedKeyType = isSign ? 'private' : 'public';
|
|
292
|
+
|
|
293
|
+
if (key.type !== expectedKeyType) {
|
|
294
|
+
throw lazyDOMException(
|
|
295
|
+
`Key must be a ${expectedKeyType} key`,
|
|
296
|
+
'InvalidAccessError',
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const hashName = typeof hash === 'string' ? hash : hash?.name;
|
|
301
|
+
|
|
302
|
+
if (!hashName) {
|
|
303
|
+
throw lazyDOMException(
|
|
304
|
+
'Hash algorithm is required for ECDSA',
|
|
305
|
+
'InvalidAccessError',
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Normalize hash algorithm name to WebCrypto format for C++ layer
|
|
310
|
+
const normalizedHashName = normalizeHashName(hashName, HashContext.WebCrypto);
|
|
311
|
+
|
|
312
|
+
// Create EC instance with the curve from the key
|
|
313
|
+
const namedCurve = key.algorithm.namedCurve!;
|
|
314
|
+
const ec = new Ec(namedCurve);
|
|
315
|
+
|
|
316
|
+
// Extract and import the actual key data from the CryptoKey
|
|
317
|
+
// Export in DER format with appropriate encoding
|
|
318
|
+
const encoding =
|
|
319
|
+
key.type === 'private' ? KeyEncoding.PKCS8 : KeyEncoding.SPKI;
|
|
320
|
+
const keyData = key.keyObject.handle.exportKey(KFormatType.DER, encoding);
|
|
321
|
+
const keyBuffer = bufferLikeToArrayBuffer(keyData);
|
|
322
|
+
ec.native.importKey(
|
|
323
|
+
'der',
|
|
324
|
+
keyBuffer,
|
|
325
|
+
key.algorithm.name!,
|
|
326
|
+
key.extractable,
|
|
327
|
+
key.usages,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
const dataBuffer = bufferLikeToArrayBuffer(data);
|
|
331
|
+
|
|
332
|
+
if (isSign) {
|
|
333
|
+
// Sign operation
|
|
334
|
+
return ec.native.sign(dataBuffer, normalizedHashName);
|
|
335
|
+
} else {
|
|
336
|
+
// Verify operation
|
|
337
|
+
const signatureBuffer = bufferLikeToArrayBuffer(signature!);
|
|
338
|
+
return ec.native.verify(dataBuffer, signatureBuffer, normalizedHashName);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// Node API
|
|
343
|
+
|
|
344
|
+
export async function ec_generateKeyPair(
|
|
345
|
+
name: string,
|
|
346
|
+
namedCurve: string,
|
|
347
|
+
extractable: boolean,
|
|
348
|
+
keyUsages: KeyUsage[],
|
|
349
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
350
|
+
_options?: KeyPairOptions, // TODO: Implement format options support
|
|
351
|
+
): Promise<CryptoKeyPair> {
|
|
352
|
+
// validation checks
|
|
353
|
+
if (!Object.keys(kNamedCurveAliases).includes(namedCurve || '')) {
|
|
354
|
+
throw lazyDOMException(
|
|
355
|
+
`Unrecognized namedCurve '${namedCurve}'`,
|
|
356
|
+
'NotSupportedError',
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// const usageSet = new SafeSet(keyUsages);
|
|
361
|
+
switch (name) {
|
|
362
|
+
case 'ECDSA':
|
|
363
|
+
if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
|
|
364
|
+
throw lazyDOMException(
|
|
365
|
+
'Unsupported key usage for an ECDSA key',
|
|
366
|
+
'SyntaxError',
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
case 'ECDH':
|
|
371
|
+
if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
|
|
372
|
+
throw lazyDOMException(
|
|
373
|
+
'Unsupported key usage for an ECDH key',
|
|
374
|
+
'SyntaxError',
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
// Fall through
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const ec = new Ec(namedCurve!);
|
|
381
|
+
await ec.generateKeyPair();
|
|
382
|
+
|
|
383
|
+
let publicUsages: KeyUsage[] = [];
|
|
384
|
+
let privateUsages: KeyUsage[] = [];
|
|
385
|
+
switch (name) {
|
|
386
|
+
case 'ECDSA':
|
|
387
|
+
publicUsages = getUsagesUnion(keyUsages, 'verify');
|
|
388
|
+
privateUsages = getUsagesUnion(keyUsages, 'sign');
|
|
389
|
+
break;
|
|
390
|
+
case 'ECDH':
|
|
391
|
+
publicUsages = [];
|
|
392
|
+
privateUsages = getUsagesUnion(keyUsages, 'deriveKey', 'deriveBits');
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const keyAlgorithm = { name, namedCurve: namedCurve! };
|
|
397
|
+
|
|
398
|
+
// Export keys directly from the EC key pair using the internal EVP_PKEY
|
|
399
|
+
// These methods export in DER format (SPKI for public, PKCS8 for private)
|
|
400
|
+
const publicKeyData = ec.native.getPublicKey();
|
|
401
|
+
const privateKeyData = ec.native.getPrivateKey();
|
|
402
|
+
|
|
403
|
+
const pub = KeyObject.createKeyObject(
|
|
404
|
+
'public',
|
|
405
|
+
publicKeyData,
|
|
406
|
+
'der',
|
|
407
|
+
'spki',
|
|
408
|
+
) as PublicKeyObject;
|
|
409
|
+
const publicKey = new CryptoKey(
|
|
410
|
+
pub,
|
|
411
|
+
keyAlgorithm as SubtleAlgorithm,
|
|
412
|
+
publicUsages,
|
|
413
|
+
true,
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
// All keys are now exported in PKCS8 format for consistency
|
|
417
|
+
const privateEncoding = 'pkcs8';
|
|
418
|
+
const priv = KeyObject.createKeyObject(
|
|
419
|
+
'private',
|
|
420
|
+
privateKeyData,
|
|
421
|
+
'der',
|
|
422
|
+
privateEncoding as 'pkcs8' | 'spki' | 'sec1',
|
|
423
|
+
) as PrivateKeyObject;
|
|
424
|
+
const privateKey = new CryptoKey(
|
|
425
|
+
priv,
|
|
426
|
+
keyAlgorithm as SubtleAlgorithm,
|
|
427
|
+
privateUsages,
|
|
428
|
+
extractable,
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
return { publicKey, privateKey };
|
|
432
|
+
}
|
package/src/ed.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
|
+
import type { AsymmetricKeyObject, PrivateKeyObject } from './keys';
|
|
4
|
+
import type { EdKeyPair } from './specs/edKeyPair.nitro';
|
|
5
|
+
import type {
|
|
6
|
+
BinaryLike,
|
|
7
|
+
CFRGKeyPairType,
|
|
8
|
+
DiffieHellmanCallback,
|
|
9
|
+
DiffieHellmanOptions,
|
|
10
|
+
GenerateKeyPairCallback,
|
|
11
|
+
GenerateKeyPairReturn,
|
|
12
|
+
Hex,
|
|
13
|
+
KeyPairGenConfig,
|
|
14
|
+
KeyPairType,
|
|
15
|
+
} from './utils';
|
|
16
|
+
import { binaryLikeToArrayBuffer as toAB } from './utils';
|
|
17
|
+
|
|
18
|
+
export class Ed {
|
|
19
|
+
type: CFRGKeyPairType;
|
|
20
|
+
config: KeyPairGenConfig;
|
|
21
|
+
native: EdKeyPair;
|
|
22
|
+
|
|
23
|
+
constructor(type: CFRGKeyPairType, config: KeyPairGenConfig) {
|
|
24
|
+
this.type = type;
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.native = NitroModules.createHybridObject<EdKeyPair>('EdKeyPair');
|
|
27
|
+
this.native.setCurve(type);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Computes the Diffie-Hellman secret based on a privateKey and a publicKey.
|
|
32
|
+
* Both keys must have the same asymmetricKeyType, which must be one of 'dh'
|
|
33
|
+
* (for Diffie-Hellman), 'ec', 'x448', or 'x25519' (for ECDH).
|
|
34
|
+
*
|
|
35
|
+
* @api nodejs/node
|
|
36
|
+
*
|
|
37
|
+
* @param options `{ privateKey, publicKey }`, both of which are `KeyObject`s
|
|
38
|
+
* @param callback optional `(err, secret) => void`
|
|
39
|
+
* @returns `Buffer` if no callback, or `void` if callback is provided
|
|
40
|
+
*/
|
|
41
|
+
diffieHellman(
|
|
42
|
+
options: DiffieHellmanOptions,
|
|
43
|
+
callback?: DiffieHellmanCallback,
|
|
44
|
+
): Buffer | void {
|
|
45
|
+
checkDiffieHellmanOptions(options);
|
|
46
|
+
|
|
47
|
+
// key types must be of certain type
|
|
48
|
+
const keyType = (options.privateKey as AsymmetricKeyObject)
|
|
49
|
+
.asymmetricKeyType;
|
|
50
|
+
switch (keyType) {
|
|
51
|
+
case 'x25519':
|
|
52
|
+
case 'x448':
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Unsupported or unimplemented curve type: ${keyType}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// extract the private and public keys as ArrayBuffers
|
|
59
|
+
const privateKey = toAB(options.privateKey);
|
|
60
|
+
const publicKey = toAB(options.publicKey);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const ret = this.native.diffieHellman(privateKey, publicKey);
|
|
64
|
+
if (!ret) {
|
|
65
|
+
throw new Error('No secret');
|
|
66
|
+
}
|
|
67
|
+
if (callback) {
|
|
68
|
+
callback(null, Buffer.from(ret));
|
|
69
|
+
} else {
|
|
70
|
+
return Buffer.from(ret);
|
|
71
|
+
}
|
|
72
|
+
} catch (e: unknown) {
|
|
73
|
+
const err = e as Error;
|
|
74
|
+
if (callback) {
|
|
75
|
+
callback(err, undefined);
|
|
76
|
+
} else {
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async generateKeyPair(): Promise<void> {
|
|
83
|
+
this.native.generateKeyPair(
|
|
84
|
+
this.config.publicFormat || (-1 as number),
|
|
85
|
+
this.config.publicType || (-1 as number),
|
|
86
|
+
this.config.privateFormat || (-1 as number),
|
|
87
|
+
this.config.privateType || (-1 as number),
|
|
88
|
+
this.config.cipher as string,
|
|
89
|
+
this.config.passphrase as ArrayBuffer,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
generateKeyPairSync(): void {
|
|
94
|
+
this.native.generateKeyPairSync(
|
|
95
|
+
this.config.publicFormat || (-1 as number),
|
|
96
|
+
this.config.publicType || (-1 as number),
|
|
97
|
+
this.config.privateFormat || (-1 as number),
|
|
98
|
+
this.config.privateType || (-1 as number),
|
|
99
|
+
this.config.cipher as string,
|
|
100
|
+
this.config.passphrase as ArrayBuffer,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getPublicKey(): ArrayBuffer {
|
|
105
|
+
return this.native.getPublicKey();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getPrivateKey(): ArrayBuffer {
|
|
109
|
+
return this.native.getPrivateKey();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Computes the Diffie-Hellman shared secret based on a privateKey and a
|
|
114
|
+
* publicKey for key exchange
|
|
115
|
+
*
|
|
116
|
+
* @api \@paulmillr/noble-curves/ed25519
|
|
117
|
+
*
|
|
118
|
+
* @param privateKey
|
|
119
|
+
* @param publicKey
|
|
120
|
+
* @returns shared secret key
|
|
121
|
+
*/
|
|
122
|
+
getSharedSecret(privateKey: Hex, publicKey: Hex): ArrayBuffer {
|
|
123
|
+
return this.native.diffieHellman(toAB(privateKey), toAB(publicKey));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async sign(message: BinaryLike, key?: BinaryLike): Promise<ArrayBuffer> {
|
|
127
|
+
return key
|
|
128
|
+
? this.native.sign(toAB(message), toAB(key))
|
|
129
|
+
: this.native.sign(toAB(message));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
signSync(message: BinaryLike, key?: BinaryLike): ArrayBuffer {
|
|
133
|
+
return key
|
|
134
|
+
? this.native.signSync(toAB(message), toAB(key))
|
|
135
|
+
: this.native.signSync(toAB(message));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async verify(
|
|
139
|
+
signature: BinaryLike,
|
|
140
|
+
message: BinaryLike,
|
|
141
|
+
key?: BinaryLike,
|
|
142
|
+
): Promise<boolean> {
|
|
143
|
+
return key
|
|
144
|
+
? this.native.verify(toAB(signature), toAB(message), toAB(key))
|
|
145
|
+
: this.native.verify(toAB(signature), toAB(message));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
verifySync(
|
|
149
|
+
signature: BinaryLike,
|
|
150
|
+
message: BinaryLike,
|
|
151
|
+
key?: BinaryLike,
|
|
152
|
+
): boolean {
|
|
153
|
+
return key
|
|
154
|
+
? this.native.verifySync(toAB(signature), toAB(message), toAB(key))
|
|
155
|
+
: this.native.verifySync(toAB(signature), toAB(message));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Node API
|
|
160
|
+
export function diffieHellman(
|
|
161
|
+
options: DiffieHellmanOptions,
|
|
162
|
+
callback?: DiffieHellmanCallback,
|
|
163
|
+
): Buffer | void {
|
|
164
|
+
const privateKey = options.privateKey as PrivateKeyObject;
|
|
165
|
+
const type = privateKey.asymmetricKeyType as CFRGKeyPairType;
|
|
166
|
+
const ed = new Ed(type, {});
|
|
167
|
+
return ed.diffieHellman(options, callback);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Node API
|
|
171
|
+
export function ed_generateKeyPair(
|
|
172
|
+
isAsync: boolean,
|
|
173
|
+
type: KeyPairType,
|
|
174
|
+
encoding: KeyPairGenConfig,
|
|
175
|
+
callback: GenerateKeyPairCallback | undefined,
|
|
176
|
+
): GenerateKeyPairReturn | void {
|
|
177
|
+
const ed = new Ed(type, encoding);
|
|
178
|
+
|
|
179
|
+
// Async path
|
|
180
|
+
if (isAsync) {
|
|
181
|
+
if (!callback) {
|
|
182
|
+
// This should not happen if called from public API
|
|
183
|
+
throw new Error('A callback is required for async key generation.');
|
|
184
|
+
}
|
|
185
|
+
ed.generateKeyPair()
|
|
186
|
+
.then(() => {
|
|
187
|
+
callback(undefined, ed.getPublicKey(), ed.getPrivateKey());
|
|
188
|
+
})
|
|
189
|
+
.catch(err => {
|
|
190
|
+
callback(err, undefined, undefined);
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Sync path
|
|
196
|
+
let err: Error | undefined;
|
|
197
|
+
try {
|
|
198
|
+
ed.generateKeyPairSync();
|
|
199
|
+
} catch (e) {
|
|
200
|
+
err = e instanceof Error ? e : new Error(String(e));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (callback) {
|
|
204
|
+
callback(err, ed.getPublicKey(), ed.getPrivateKey());
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
return [err, ed.getPublicKey(), ed.getPrivateKey()];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function checkDiffieHellmanOptions(options: DiffieHellmanOptions): void {
|
|
211
|
+
const { privateKey, publicKey } = options;
|
|
212
|
+
|
|
213
|
+
// Check if keys are KeyObject instances
|
|
214
|
+
if (
|
|
215
|
+
!privateKey ||
|
|
216
|
+
typeof privateKey !== 'object' ||
|
|
217
|
+
!('type' in privateKey)
|
|
218
|
+
) {
|
|
219
|
+
throw new Error('privateKey must be a KeyObject');
|
|
220
|
+
}
|
|
221
|
+
if (!publicKey || typeof publicKey !== 'object' || !('type' in publicKey)) {
|
|
222
|
+
throw new Error('publicKey must be a KeyObject');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// type checks
|
|
226
|
+
if (privateKey.type !== 'private') {
|
|
227
|
+
throw new Error('privateKey must be a private KeyObject');
|
|
228
|
+
}
|
|
229
|
+
if (publicKey.type !== 'public') {
|
|
230
|
+
throw new Error('publicKey must be a public KeyObject');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// For asymmetric keys, check if they have the asymmetricKeyType property
|
|
234
|
+
const privateKeyAsym = privateKey as AsymmetricKeyObject;
|
|
235
|
+
const publicKeyAsym = publicKey as AsymmetricKeyObject;
|
|
236
|
+
|
|
237
|
+
// key types must match
|
|
238
|
+
if (
|
|
239
|
+
privateKeyAsym.asymmetricKeyType &&
|
|
240
|
+
publicKeyAsym.asymmetricKeyType &&
|
|
241
|
+
privateKeyAsym.asymmetricKeyType !== publicKeyAsym.asymmetricKeyType
|
|
242
|
+
) {
|
|
243
|
+
throw new Error('Keys must be asymmetric and their types must match');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
switch (privateKeyAsym.asymmetricKeyType) {
|
|
247
|
+
// case 'dh': // TODO: uncomment when implemented
|
|
248
|
+
case 'x25519':
|
|
249
|
+
case 'x448':
|
|
250
|
+
break;
|
|
251
|
+
default:
|
|
252
|
+
throw new Error(
|
|
253
|
+
`Unknown curve type: ${privateKeyAsym.asymmetricKeyType}`,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|