react-native-quick-crypto 1.0.0-beta.9 → 1.0.1
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 +156 -8
- package/README.md +14 -27
- package/android/CMakeLists.txt +64 -7
- package/android/build.gradle +12 -2
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +0 -2
- 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/GCMCipher.cpp +68 -0
- package/cpp/cipher/GCMCipher.hpp +14 -0
- package/cpp/cipher/HybridCipher.cpp +323 -0
- package/cpp/cipher/HybridCipher.hpp +68 -0
- package/cpp/cipher/HybridCipherFactory.hpp +105 -0
- package/cpp/cipher/HybridRsaCipher.cpp +367 -0
- package/cpp/cipher/HybridRsaCipher.hpp +29 -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 +228 -98
- package/cpp/ed25519/HybridEdKeyPair.hpp +42 -56
- 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 +757 -0
- package/cpp/keys/HybridKeyObjectHandle.hpp +51 -0
- package/cpp/keys/KeyObjectData.cpp +268 -0
- package/cpp/keys/KeyObjectData.hpp +71 -0
- package/cpp/keys/node.h +5 -0
- package/cpp/mldsa/HybridMlDsaKeyPair.cpp +264 -0
- package/cpp/mldsa/HybridMlDsaKeyPair.hpp +47 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +34 -55
- package/cpp/pbkdf2/HybridPbkdf2.hpp +5 -16
- package/cpp/random/HybridRandom.cpp +6 -17
- package/cpp/random/HybridRandom.hpp +5 -6
- package/cpp/rsa/HybridRsaKeyPair.cpp +154 -0
- package/cpp/rsa/HybridRsaKeyPair.hpp +43 -0
- package/cpp/sign/HybridSignHandle.cpp +266 -0
- package/cpp/sign/HybridSignHandle.hpp +36 -0
- package/cpp/sign/HybridVerifyHandle.cpp +227 -0
- package/cpp/sign/HybridVerifyHandle.hpp +36 -0
- package/cpp/sign/SignUtils.hpp +108 -0
- package/cpp/utils/Macros.hpp +68 -0
- package/cpp/utils/Utils.hpp +43 -2
- package/cpp/utils/base64.h +309 -0
- 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 +5 -1
- package/deps/ncrypto/.bazelignore +4 -0
- package/deps/ncrypto/.bazelrc +2 -0
- package/deps/ncrypto/.bazelversion +1 -0
- package/deps/ncrypto/.clang-format +111 -0
- package/deps/ncrypto/.github/workflows/bazel.yml +58 -0
- package/deps/ncrypto/.github/workflows/linter.yml +38 -0
- package/deps/ncrypto/.github/workflows/macos.yml +43 -0
- package/deps/ncrypto/.github/workflows/ubuntu.yml +46 -0
- package/deps/ncrypto/.github/workflows/visual-studio.yml +49 -0
- package/deps/ncrypto/.python-version +1 -0
- package/deps/ncrypto/BUILD.bazel +36 -0
- package/deps/ncrypto/CMakeLists.txt +55 -0
- package/deps/ncrypto/LICENSE +21 -0
- package/deps/ncrypto/MODULE.bazel +1 -0
- package/deps/ncrypto/MODULE.bazel.lock +280 -0
- package/deps/ncrypto/README.md +18 -0
- package/deps/ncrypto/WORKSPACE +15 -0
- package/deps/ncrypto/cmake/CPM.cmake +1225 -0
- package/deps/ncrypto/cmake/ncrypto-flags.cmake +16 -0
- package/deps/ncrypto/include/dh-primes.h +67 -0
- package/deps/ncrypto/include/ncrypto.h +1897 -0
- package/deps/ncrypto/patches/0001-Expose-libdecrepit-so-NodeJS-can-use-it-for-ncrypto.patch +28 -0
- package/deps/ncrypto/pyproject.toml +38 -0
- package/deps/ncrypto/src/CMakeLists.txt +15 -0
- package/deps/ncrypto/src/engine.cpp +93 -0
- package/deps/ncrypto/src/ncrypto.cpp +5613 -0
- package/deps/ncrypto/tests/BUILD.bazel +9 -0
- package/deps/ncrypto/tests/CMakeLists.txt +7 -0
- package/deps/ncrypto/tests/basic.cpp +86 -0
- package/deps/ncrypto/tools/run-clang-format.sh +42 -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/constants.js +32 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/ec.js +480 -0
- package/lib/commonjs/ec.js.map +1 -0
- package/lib/commonjs/ed.js +214 -2
- package/lib/commonjs/ed.js.map +1 -1
- 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 +102 -24
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +115 -52
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/keys/generateKeyPair.js +141 -144
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -1
- package/lib/commonjs/keys/index.js +229 -0
- package/lib/commonjs/keys/index.js.map +1 -1
- package/lib/commonjs/keys/publicCipher.js +152 -0
- package/lib/commonjs/keys/publicCipher.js.map +1 -0
- package/lib/commonjs/keys/signVerify.js +178 -39
- package/lib/commonjs/keys/signVerify.js.map +1 -1
- package/lib/commonjs/keys/utils.js +18 -13
- package/lib/commonjs/keys/utils.js.map +1 -1
- package/lib/commonjs/mldsa.js +69 -0
- package/lib/commonjs/mldsa.js.map +1 -0
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/random.js +6 -0
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/rsa.js +202 -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/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/mlDsaKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/mlDsaKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/rsaCipher.nitro.js +6 -0
- package/lib/commonjs/specs/rsaCipher.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/specs/sign.nitro.js +6 -0
- package/lib/commonjs/specs/sign.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +1092 -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 +44 -5
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/hashnames.js +2 -1
- package/lib/commonjs/utils/hashnames.js.map +1 -1
- package/lib/commonjs/utils/index.js +11 -0
- 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 +32 -17
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/utils/validation.js +74 -1
- package/lib/commonjs/utils/validation.js.map +1 -1
- 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/constants.js +28 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/ec.js +470 -0
- package/lib/module/ec.js.map +1 -0
- package/lib/module/ed.js +212 -3
- package/lib/module/ed.js.map +1 -1
- 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 +21 -21
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +112 -49
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/keys/generateKeyPair.js +134 -143
- package/lib/module/keys/generateKeyPair.js.map +1 -1
- package/lib/module/keys/index.js +161 -22
- package/lib/module/keys/index.js.map +1 -1
- package/lib/module/keys/publicCipher.js +145 -0
- package/lib/module/keys/publicCipher.js.map +1 -0
- package/lib/module/keys/signVerify.js +170 -39
- package/lib/module/keys/signVerify.js.map +1 -1
- package/lib/module/keys/utils.js +16 -12
- package/lib/module/keys/utils.js.map +1 -1
- package/lib/module/mldsa.js +63 -0
- package/lib/module/mldsa.js.map +1 -0
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/random.js +6 -0
- package/lib/module/random.js.map +1 -1
- package/lib/module/rsa.js +194 -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/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/mlDsaKeyPair.nitro.js +4 -0
- package/lib/module/specs/mlDsaKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/rsaCipher.nitro.js +4 -0
- package/lib/module/specs/rsaCipher.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/specs/sign.nitro.js +4 -0
- package/lib/module/specs/sign.nitro.js.map +1 -0
- package/lib/module/subtle.js +1087 -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 +26 -5
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/hashnames.js +2 -1
- package/lib/module/utils/hashnames.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- 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 +32 -17
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/utils/validation.js +69 -1
- package/lib/module/utils/validation.js.map +1 -1
- 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/constants.d.ts +21 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/ec.d.ts +22 -0
- package/lib/typescript/ec.d.ts.map +1 -0
- package/lib/typescript/ed.d.ts +28 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- 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 +102 -10
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +52 -8
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/keys/generateKeyPair.d.ts +5 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -1
- package/lib/typescript/keys/index.d.ts +22 -2
- package/lib/typescript/keys/index.d.ts.map +1 -1
- package/lib/typescript/keys/publicCipher.d.ts +20 -0
- package/lib/typescript/keys/publicCipher.d.ts.map +1 -0
- package/lib/typescript/keys/signVerify.d.ts +28 -0
- package/lib/typescript/keys/signVerify.d.ts.map +1 -1
- package/lib/typescript/keys/utils.d.ts +3 -1
- package/lib/typescript/keys/utils.d.ts.map +1 -1
- package/lib/typescript/mldsa.d.ts +18 -0
- package/lib/typescript/mldsa.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +1 -1
- package/lib/typescript/pbkdf2.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +6 -0
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/rsa.d.ts +19 -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 +1 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -1
- 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 +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/mlDsaKeyPair.nitro.d.ts +16 -0
- package/lib/typescript/specs/mlDsaKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/rsaCipher.nitro.d.ts +44 -0
- package/lib/typescript/specs/rsaCipher.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/specs/sign.nitro.d.ts +19 -0
- package/lib/typescript/specs/sign.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 +1 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/hashnames.d.ts +3 -1
- package/lib/typescript/utils/hashnames.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +1 -0
- 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 +129 -25
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/validation.d.ts +5 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -1
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +31 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +125 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +35 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +3 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +3 -3
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +121 -1
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +1 -1
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +116 -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 +2 -1
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +5 -4
- 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 +1 -1
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +8 -8
- package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +72 -0
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +77 -0
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +17 -18
- package/nitrogen/generated/shared/c++/JWKkty.hpp +12 -14
- package/nitrogen/generated/shared/c++/JWKuse.hpp +8 -10
- package/nitrogen/generated/shared/c++/KFormatType.hpp +14 -16
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +6 -7
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +15 -17
- package/nitrogen/generated/shared/c++/KeyObject.hpp +67 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +11 -13
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +38 -24
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +10 -12
- package/package.json +31 -23
- package/src/blake3.ts +123 -0
- package/src/cipher.ts +335 -0
- package/src/constants.ts +32 -0
- package/src/ec.ts +657 -0
- package/src/ed.ts +297 -13
- 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 +20 -20
- package/src/keys/classes.ts +157 -55
- package/src/keys/generateKeyPair.ts +177 -134
- package/src/keys/index.ts +226 -14
- package/src/keys/publicCipher.ts +229 -0
- package/src/keys/signVerify.ts +239 -39
- package/src/keys/utils.ts +24 -18
- package/src/mldsa.ts +125 -0
- package/src/pbkdf2.ts +1 -1
- package/src/random.ts +7 -0
- package/src/rsa.ts +310 -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 +2 -0
- package/src/specs/hash.nitro.ts +10 -0
- package/src/specs/hmac.nitro.ts +7 -0
- package/src/specs/keyObjectHandle.nitro.ts +1 -1
- package/src/specs/mlDsaKeyPair.nitro.ts +29 -0
- package/src/specs/rsaCipher.nitro.ts +65 -0
- package/src/specs/rsaKeyPair.nitro.ts +33 -0
- package/src/specs/sign.nitro.ts +31 -0
- package/src/subtle.ts +1576 -0
- package/src/utils/cipher.ts +60 -0
- package/src/utils/conversion.ts +33 -4
- package/src/utils/hashnames.ts +4 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/noble.ts +85 -0
- package/src/utils/types.ts +219 -31
- package/src/utils/validation.ts +96 -1
- package/lib/module/package.json +0 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.kt +0 -1
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +0 -86
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Encoding } from './types';
|
|
2
|
+
|
|
3
|
+
// Mimics node behavior for default global encoding
|
|
4
|
+
let defaultEncoding: Encoding = 'buffer';
|
|
5
|
+
|
|
6
|
+
export function setDefaultEncoding(encoding: Encoding) {
|
|
7
|
+
defaultEncoding = encoding;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getDefaultEncoding(): Encoding {
|
|
11
|
+
return defaultEncoding;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function normalizeEncoding(enc: string) {
|
|
15
|
+
if (!enc) return 'utf8';
|
|
16
|
+
let retried;
|
|
17
|
+
while (true) {
|
|
18
|
+
switch (enc) {
|
|
19
|
+
case 'utf8':
|
|
20
|
+
case 'utf-8':
|
|
21
|
+
return 'utf8';
|
|
22
|
+
case 'ucs2':
|
|
23
|
+
case 'ucs-2':
|
|
24
|
+
case 'utf16le':
|
|
25
|
+
case 'utf-16le':
|
|
26
|
+
return 'utf16le';
|
|
27
|
+
case 'latin1':
|
|
28
|
+
case 'binary':
|
|
29
|
+
return 'latin1';
|
|
30
|
+
case 'base64':
|
|
31
|
+
case 'ascii':
|
|
32
|
+
case 'hex':
|
|
33
|
+
return enc;
|
|
34
|
+
default:
|
|
35
|
+
if (retried) return; // undefined
|
|
36
|
+
enc = ('' + enc).toLowerCase();
|
|
37
|
+
retried = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function validateEncoding(data: string, encoding: string) {
|
|
43
|
+
const normalizedEncoding = normalizeEncoding(encoding);
|
|
44
|
+
const length = data.length;
|
|
45
|
+
|
|
46
|
+
if (normalizedEncoding === 'hex' && length % 2 !== 0) {
|
|
47
|
+
throw new Error(`Encoding ${encoding} not valid for data length ${length}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
export function getUIntOption(options: Record<string, any>, key: string) {
|
|
53
|
+
let value;
|
|
54
|
+
if (options && (value = options[key]) != null) {
|
|
55
|
+
// >>> Turns any type into a positive integer (also sets the sign bit to 0)
|
|
56
|
+
if (value >>> 0 !== value) throw new Error(`options.${key}: ${value}`);
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
package/src/utils/conversion.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
|
|
2
2
|
import { Buffer as SafeBuffer } from 'safe-buffer';
|
|
3
3
|
import type { ABV, BinaryLikeNode, BufferLike } from './types';
|
|
4
|
+
import { KeyObject } from '../keys/classes';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Converts supplied argument to an ArrayBuffer. Note this does not copy the
|
|
@@ -56,8 +57,29 @@ export function bufferLikeToArrayBuffer(buf: BufferLike): ArrayBuffer {
|
|
|
56
57
|
if (ArrayBuffer.isView(buf)) {
|
|
57
58
|
return toArrayBuffer(buf);
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
return
|
|
60
|
+
|
|
61
|
+
// If buf is already an ArrayBuffer, return it.
|
|
62
|
+
if (buf instanceof ArrayBuffer) {
|
|
63
|
+
return buf;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// If buf is a SharedArrayBuffer, convert it to ArrayBuffer.
|
|
67
|
+
// This typically involves a copy of the data.
|
|
68
|
+
if (
|
|
69
|
+
typeof SharedArrayBuffer !== 'undefined' &&
|
|
70
|
+
buf instanceof SharedArrayBuffer
|
|
71
|
+
) {
|
|
72
|
+
const arrayBuffer = new ArrayBuffer(buf.byteLength);
|
|
73
|
+
new Uint8Array(arrayBuffer).set(new Uint8Array(buf));
|
|
74
|
+
return arrayBuffer;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If we reach here, 'buf' is of a type within BufferLike that has not been handled by the above checks.
|
|
78
|
+
// This indicates either an incomplete BufferLike definition or an unexpected input type.
|
|
79
|
+
// Throw an error to signal this, ensuring the function's contract (return ArrayBuffer or throw) is met.
|
|
80
|
+
throw new TypeError(
|
|
81
|
+
'Input must be a Buffer, ArrayBufferView, ArrayBuffer, or SharedArrayBuffer.',
|
|
82
|
+
);
|
|
61
83
|
}
|
|
62
84
|
|
|
63
85
|
export function binaryLikeToArrayBuffer(
|
|
@@ -111,9 +133,14 @@ export function binaryLikeToArrayBuffer(
|
|
|
111
133
|
// }
|
|
112
134
|
// }
|
|
113
135
|
|
|
114
|
-
//
|
|
136
|
+
// KeyObject
|
|
137
|
+
if (input instanceof KeyObject) {
|
|
138
|
+
return input.handle.exportKey();
|
|
139
|
+
}
|
|
115
140
|
|
|
116
|
-
throw new Error(
|
|
141
|
+
throw new Error(
|
|
142
|
+
'Invalid argument type for "key". Need ArrayBuffer, TypedArray, KeyObject, CryptoKey, string',
|
|
143
|
+
);
|
|
117
144
|
}
|
|
118
145
|
|
|
119
146
|
export function ab2str(buf: ArrayBuffer, encoding: string = 'hex') {
|
|
@@ -121,3 +148,5 @@ export function ab2str(buf: ArrayBuffer, encoding: string = 'hex') {
|
|
|
121
148
|
}
|
|
122
149
|
|
|
123
150
|
export const kEmptyObject = Object.freeze(Object.create(null));
|
|
151
|
+
|
|
152
|
+
export * from './noble';
|
package/src/utils/hashnames.ts
CHANGED
|
@@ -79,11 +79,13 @@ const kHashNames: HashNames = {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export function normalizeHashName(
|
|
82
|
-
algo: string | HashAlgorithm | undefined,
|
|
82
|
+
algo: string | HashAlgorithm | { name: string } | undefined,
|
|
83
83
|
context: HashContext = HashContext.Node,
|
|
84
84
|
): HashAlgorithm {
|
|
85
85
|
if (typeof algo !== 'undefined') {
|
|
86
|
-
const
|
|
86
|
+
const hashName =
|
|
87
|
+
typeof algo === 'string' ? algo : algo.name || algo.toString();
|
|
88
|
+
const normAlgo = hashName.toLowerCase();
|
|
87
89
|
try {
|
|
88
90
|
const alias = kHashNames[normAlgo]![context] as HashAlgorithm;
|
|
89
91
|
if (alias) return alias;
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Hex } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes hex string or Uint8Array, converts to Uint8Array.
|
|
5
|
+
* Validates output length.
|
|
6
|
+
* Will throw error for other types.
|
|
7
|
+
* @param title descriptive title for an error e.g. 'private key'
|
|
8
|
+
* @param hex hex string or Uint8Array
|
|
9
|
+
* @param expectedLength optional, will compare to result array's length
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function ensureBytes(
|
|
13
|
+
title: string,
|
|
14
|
+
hex: Hex,
|
|
15
|
+
expectedLength?: number,
|
|
16
|
+
): Uint8Array {
|
|
17
|
+
let res: Uint8Array;
|
|
18
|
+
if (typeof hex === 'string') {
|
|
19
|
+
try {
|
|
20
|
+
res = hexToBytes(hex);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw new Error(title + ' must be hex string or Uint8Array, cause: ' + e);
|
|
23
|
+
}
|
|
24
|
+
} else if (isBytes(hex)) {
|
|
25
|
+
// Uint8Array.from() instead of hash.slice() because node.js Buffer
|
|
26
|
+
// is instance of Uint8Array, and its slice() creates **mutable** copy
|
|
27
|
+
res = Uint8Array.from(hex);
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error(title + ' must be hex string or Uint8Array');
|
|
30
|
+
}
|
|
31
|
+
const len = res.length;
|
|
32
|
+
if (typeof expectedLength === 'number' && len !== expectedLength)
|
|
33
|
+
throw new Error(
|
|
34
|
+
title + ' of length ' + expectedLength + ' expected, got ' + len,
|
|
35
|
+
);
|
|
36
|
+
return res;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
40
|
+
export function isBytes(a: unknown): a is Uint8Array {
|
|
41
|
+
return (
|
|
42
|
+
a instanceof Uint8Array ||
|
|
43
|
+
(ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array')
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// We use optimized technique to convert hex string to byte array
|
|
48
|
+
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;
|
|
49
|
+
function asciiToBase16(ch: number): number | undefined {
|
|
50
|
+
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48
|
|
51
|
+
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)
|
|
52
|
+
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Convert hex string to byte array. Uses built-in function, when available.
|
|
58
|
+
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
59
|
+
*/
|
|
60
|
+
export function hexToBytes(hex: string): Uint8Array {
|
|
61
|
+
if (typeof hex !== 'string')
|
|
62
|
+
throw new Error('hex string expected, got ' + typeof hex);
|
|
63
|
+
// @ts-expect-error Uint8Array.fromHex
|
|
64
|
+
if (hasHexBuiltin) return Uint8Array.fromHex(hex);
|
|
65
|
+
const hl = hex.length;
|
|
66
|
+
const al = hl / 2;
|
|
67
|
+
if (hl % 2)
|
|
68
|
+
throw new Error('hex string expected, got unpadded hex of length ' + hl);
|
|
69
|
+
const array = new Uint8Array(al);
|
|
70
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
71
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
72
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
73
|
+
if (n1 === undefined || n2 === undefined) {
|
|
74
|
+
const char = hex.substring(hi, hi + 2);
|
|
75
|
+
throw new Error(
|
|
76
|
+
'hex string expected, got non-hex character "' +
|
|
77
|
+
char +
|
|
78
|
+
'" at index ' +
|
|
79
|
+
hi,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
|
|
83
|
+
}
|
|
84
|
+
return array;
|
|
85
|
+
}
|
package/src/utils/types.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
import type { Buffer } from 'buffer';
|
|
3
|
+
import type { CipherKey } from 'node:crypto'; // @types/node
|
|
2
4
|
import type { Buffer as SafeBuffer } from 'safe-buffer';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
+
import type { KeyObjectHandle as KeyObjectHandleType } from '../specs/keyObjectHandle.nitro';
|
|
6
|
+
import type { KeyObject, CryptoKey } from '../keys';
|
|
5
7
|
|
|
6
8
|
export type ABV = TypedArray | DataView | ArrayBufferLike | CraftzdogBuffer;
|
|
7
9
|
|
|
@@ -20,19 +22,23 @@ export type RandomCallback<T> = (err: Error | null, value: T) => void;
|
|
|
20
22
|
|
|
21
23
|
export type BufferLike =
|
|
22
24
|
| ArrayBuffer
|
|
25
|
+
| ArrayBufferLike
|
|
23
26
|
| CraftzdogBuffer
|
|
24
27
|
| SafeBuffer
|
|
25
28
|
| ArrayBufferView;
|
|
26
29
|
|
|
27
30
|
export type BinaryLike =
|
|
28
31
|
| string
|
|
32
|
+
| Buffer
|
|
29
33
|
| ArrayBuffer
|
|
34
|
+
| ArrayBufferLike
|
|
35
|
+
| ArrayBufferView
|
|
30
36
|
| CraftzdogBuffer
|
|
31
37
|
| SafeBuffer
|
|
32
38
|
| TypedArray
|
|
33
39
|
| DataView;
|
|
34
40
|
|
|
35
|
-
export type BinaryLikeNode = CipherKey | BinaryLike;
|
|
41
|
+
export type BinaryLikeNode = CipherKey | BinaryLike | KeyObject;
|
|
36
42
|
|
|
37
43
|
export type DigestAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
38
44
|
|
|
@@ -40,15 +46,39 @@ export type HashAlgorithm = DigestAlgorithm | 'SHA-224' | 'RIPEMD-160';
|
|
|
40
46
|
|
|
41
47
|
export type RSAKeyPairAlgorithm = 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'RSA-OAEP';
|
|
42
48
|
|
|
49
|
+
export interface RsaHashedKeyGenParams {
|
|
50
|
+
name: RSAKeyPairAlgorithm;
|
|
51
|
+
modulusLength: number;
|
|
52
|
+
publicExponent: Uint8Array;
|
|
53
|
+
hash: string | { name: string };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface RsaKeyAlgorithm {
|
|
57
|
+
name: RSAKeyPairAlgorithm;
|
|
58
|
+
modulusLength: number;
|
|
59
|
+
publicExponent: Uint8Array;
|
|
60
|
+
hash: { name: string };
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
export type ECKeyPairAlgorithm = 'ECDSA' | 'ECDH';
|
|
44
64
|
|
|
45
65
|
export type CFRGKeyPairAlgorithm = 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
|
|
46
66
|
export type CFRGKeyPairType = 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
47
67
|
|
|
68
|
+
export type PQCKeyPairAlgorithm = 'ML-DSA-44' | 'ML-DSA-65' | 'ML-DSA-87';
|
|
69
|
+
export type PQCKeyPairType = 'ml-dsa-44' | 'ml-dsa-65' | 'ml-dsa-87';
|
|
70
|
+
|
|
71
|
+
// Node.js style key pair types (lowercase)
|
|
72
|
+
export type RSAKeyPairType = 'rsa' | 'rsa-pss';
|
|
73
|
+
export type ECKeyPairType = 'ec';
|
|
74
|
+
export type DSAKeyPairType = 'dsa';
|
|
75
|
+
export type DHKeyPairType = 'dh';
|
|
76
|
+
|
|
48
77
|
export type KeyPairAlgorithm =
|
|
49
78
|
| RSAKeyPairAlgorithm
|
|
50
79
|
| ECKeyPairAlgorithm
|
|
51
|
-
| CFRGKeyPairAlgorithm
|
|
80
|
+
| CFRGKeyPairAlgorithm
|
|
81
|
+
| PQCKeyPairAlgorithm;
|
|
52
82
|
|
|
53
83
|
export type AESAlgorithm = 'AES-CTR' | 'AES-CBC' | 'AES-GCM' | 'AES-KW';
|
|
54
84
|
|
|
@@ -60,7 +90,10 @@ export type SignVerifyAlgorithm =
|
|
|
60
90
|
| 'ECDSA'
|
|
61
91
|
| 'HMAC'
|
|
62
92
|
| 'Ed25519'
|
|
63
|
-
| 'Ed448'
|
|
93
|
+
| 'Ed448'
|
|
94
|
+
| 'ML-DSA-44'
|
|
95
|
+
| 'ML-DSA-65'
|
|
96
|
+
| 'ML-DSA-87';
|
|
64
97
|
|
|
65
98
|
export type DeriveBitsAlgorithm =
|
|
66
99
|
| 'PBKDF2'
|
|
@@ -75,6 +108,49 @@ export type EncryptDecryptAlgorithm =
|
|
|
75
108
|
| 'AES-CBC'
|
|
76
109
|
| 'AES-GCM';
|
|
77
110
|
|
|
111
|
+
export type RsaOaepParams = {
|
|
112
|
+
name: 'RSA-OAEP';
|
|
113
|
+
label?: BufferLike;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type AesCbcParams = {
|
|
117
|
+
name: 'AES-CBC';
|
|
118
|
+
iv: BufferLike;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type AesCtrParams = {
|
|
122
|
+
name: 'AES-CTR';
|
|
123
|
+
counter: TypedArray;
|
|
124
|
+
length: number;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type AesGcmParams = {
|
|
128
|
+
name: 'AES-GCM';
|
|
129
|
+
iv: BufferLike;
|
|
130
|
+
tagLength?: TagLength;
|
|
131
|
+
additionalData?: BufferLike;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type AesKwParams = {
|
|
135
|
+
name: 'AES-KW';
|
|
136
|
+
wrappingKey?: BufferLike;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export type AesKeyGenParams = {
|
|
140
|
+
length: AESLength;
|
|
141
|
+
name?: AESAlgorithm;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export type TagLength = 32 | 64 | 96 | 104 | 112 | 120 | 128;
|
|
145
|
+
|
|
146
|
+
export type AESLength = 128 | 192 | 256;
|
|
147
|
+
|
|
148
|
+
export type EncryptDecryptParams =
|
|
149
|
+
| AesCbcParams
|
|
150
|
+
| AesCtrParams
|
|
151
|
+
| AesGcmParams
|
|
152
|
+
| RsaOaepParams;
|
|
153
|
+
|
|
78
154
|
export type AnyAlgorithm =
|
|
79
155
|
| DigestAlgorithm
|
|
80
156
|
| HashAlgorithm
|
|
@@ -94,14 +170,20 @@ export type SubtleAlgorithm = {
|
|
|
94
170
|
name: AnyAlgorithm;
|
|
95
171
|
salt?: string;
|
|
96
172
|
iterations?: number;
|
|
97
|
-
hash?: HashAlgorithm;
|
|
173
|
+
hash?: HashAlgorithm | { name: string };
|
|
98
174
|
namedCurve?: NamedCurve;
|
|
99
175
|
length?: number;
|
|
100
176
|
modulusLength?: number;
|
|
101
177
|
publicExponent?: number | Uint8Array;
|
|
178
|
+
saltLength?: number;
|
|
102
179
|
};
|
|
103
180
|
|
|
104
|
-
export type KeyPairType =
|
|
181
|
+
export type KeyPairType =
|
|
182
|
+
| CFRGKeyPairType
|
|
183
|
+
| RSAKeyPairType
|
|
184
|
+
| ECKeyPairType
|
|
185
|
+
| DSAKeyPairType
|
|
186
|
+
| DHKeyPairType;
|
|
105
187
|
|
|
106
188
|
export type KeyUsage =
|
|
107
189
|
| 'encrypt'
|
|
@@ -110,47 +192,66 @@ export type KeyUsage =
|
|
|
110
192
|
| 'verify'
|
|
111
193
|
| 'deriveKey'
|
|
112
194
|
| 'deriveBits'
|
|
195
|
+
| 'encapsulateBits'
|
|
196
|
+
| 'decapsulateBits'
|
|
197
|
+
| 'encapsulateKey'
|
|
198
|
+
| 'decapsulateKey'
|
|
113
199
|
| 'wrapKey'
|
|
114
200
|
| 'unwrapKey';
|
|
115
201
|
|
|
116
|
-
//
|
|
117
|
-
// TODO(osp) move this into native side to make sure they always match
|
|
202
|
+
// TODO: These enums need to be defined on the native side
|
|
118
203
|
export enum KFormatType {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
204
|
+
DER,
|
|
205
|
+
PEM,
|
|
206
|
+
JWK,
|
|
122
207
|
}
|
|
123
208
|
|
|
124
|
-
// Same as KFormatType, this enum needs to be defined on the native side
|
|
125
209
|
export enum KeyType {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
210
|
+
SECRET,
|
|
211
|
+
PUBLIC,
|
|
212
|
+
PRIVATE,
|
|
129
213
|
}
|
|
130
214
|
|
|
131
215
|
export enum KeyEncoding {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
216
|
+
PKCS1,
|
|
217
|
+
PKCS8,
|
|
218
|
+
SPKI,
|
|
219
|
+
SEC1,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export enum KeyFormat {
|
|
223
|
+
RAW,
|
|
224
|
+
PKCS8,
|
|
225
|
+
SPKI,
|
|
226
|
+
JWK,
|
|
136
227
|
}
|
|
137
228
|
|
|
229
|
+
export type KeyData = BufferLike | BinaryLike | JWK;
|
|
230
|
+
|
|
231
|
+
export const kNamedCurveAliases = {
|
|
232
|
+
'P-256': 'prime256v1',
|
|
233
|
+
'P-384': 'secp384r1',
|
|
234
|
+
'P-521': 'secp521r1',
|
|
235
|
+
} as const;
|
|
236
|
+
// end TODO
|
|
237
|
+
|
|
138
238
|
export type KeyPairGenConfig = {
|
|
139
|
-
publicFormat?: KFormatType;
|
|
239
|
+
publicFormat?: KFormatType | -1;
|
|
140
240
|
publicType?: KeyEncoding;
|
|
141
|
-
privateFormat?: KFormatType;
|
|
241
|
+
privateFormat?: KFormatType | -1;
|
|
142
242
|
privateType?: KeyEncoding;
|
|
143
243
|
cipher?: string;
|
|
144
244
|
passphrase?: ArrayBuffer;
|
|
145
245
|
};
|
|
146
246
|
|
|
147
247
|
export type AsymmetricKeyType =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
CFRGKeyPairType
|
|
248
|
+
| 'rsa'
|
|
249
|
+
| 'rsa-pss'
|
|
250
|
+
| 'dsa'
|
|
251
|
+
| 'ec'
|
|
252
|
+
| 'dh'
|
|
253
|
+
| CFRGKeyPairType
|
|
254
|
+
| PQCKeyPairType;
|
|
154
255
|
|
|
155
256
|
type JWKkty = 'AES' | 'RSA' | 'EC' | 'oct';
|
|
156
257
|
type JWKuse = 'sig' | 'enc';
|
|
@@ -232,9 +333,14 @@ export type GenerateKeyPairOptions = {
|
|
|
232
333
|
mgf1Hash?: string;
|
|
233
334
|
};
|
|
234
335
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
336
|
+
export type KeyPairKey =
|
|
337
|
+
| ArrayBuffer
|
|
338
|
+
| Buffer
|
|
339
|
+
| string
|
|
340
|
+
| KeyObject
|
|
341
|
+
| KeyObjectHandle
|
|
342
|
+
| CryptoKey
|
|
343
|
+
| undefined;
|
|
238
344
|
|
|
239
345
|
export type GenerateKeyPairReturn = [
|
|
240
346
|
error?: Error,
|
|
@@ -260,6 +366,11 @@ export type CryptoKeyPair = {
|
|
|
260
366
|
privateKey: KeyPairKey;
|
|
261
367
|
};
|
|
262
368
|
|
|
369
|
+
export type WebCryptoKeyPair = {
|
|
370
|
+
publicKey: CryptoKey;
|
|
371
|
+
privateKey: CryptoKey;
|
|
372
|
+
};
|
|
373
|
+
|
|
263
374
|
export enum KeyVariant {
|
|
264
375
|
RSA_SSA_PKCS1_v1_5,
|
|
265
376
|
RSA_PSS,
|
|
@@ -273,3 +384,80 @@ export enum KeyVariant {
|
|
|
273
384
|
export type SignCallback = (err: Error | null, signature?: ArrayBuffer) => void;
|
|
274
385
|
|
|
275
386
|
export type VerifyCallback = (err: Error | null, valid?: boolean) => void;
|
|
387
|
+
|
|
388
|
+
export type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary';
|
|
389
|
+
export type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';
|
|
390
|
+
export type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';
|
|
391
|
+
export type Encoding =
|
|
392
|
+
| BinaryToTextEncoding
|
|
393
|
+
| CharacterEncoding
|
|
394
|
+
| LegacyCharacterEncoding
|
|
395
|
+
| 'buffer';
|
|
396
|
+
|
|
397
|
+
// These are for shortcomings in @types/node
|
|
398
|
+
// Here we use "*Type" instead of "*Types" like node does.
|
|
399
|
+
// export type CipherCBCType = 'aes-128-cbc' | 'aes-192-cbc' | 'aes-256-cbc';
|
|
400
|
+
export type CipherCFBType =
|
|
401
|
+
| 'aes-128-cfb'
|
|
402
|
+
| 'aes-192-cfb'
|
|
403
|
+
| 'aes-256-cfb'
|
|
404
|
+
| 'aes-128-cfb1'
|
|
405
|
+
| 'aes-192-cfb1'
|
|
406
|
+
| 'aes-256-cfb1'
|
|
407
|
+
| 'aes-128-cfb8'
|
|
408
|
+
| 'aes-192-cfb8'
|
|
409
|
+
| 'aes-256-cfb8';
|
|
410
|
+
export type CipherCTRType = 'aes-128-ctr' | 'aes-192-ctr' | 'aes-256-ctr';
|
|
411
|
+
export type CipherDESType =
|
|
412
|
+
| 'des'
|
|
413
|
+
| 'des3'
|
|
414
|
+
| 'des-cbc'
|
|
415
|
+
| 'des-ecb'
|
|
416
|
+
| 'des-ede'
|
|
417
|
+
| 'des-ede-cbc'
|
|
418
|
+
| 'des-ede3'
|
|
419
|
+
| 'des-ede3-cbc';
|
|
420
|
+
export type CipherECBType = 'aes-128-ecb' | 'aes-192-ecb' | 'aes-256-ecb';
|
|
421
|
+
export type CipherGCMType = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm';
|
|
422
|
+
export type CipherOFBType = 'aes-128-ofb' | 'aes-192-ofb' | 'aes-256-ofb';
|
|
423
|
+
|
|
424
|
+
export type KeyObjectHandle = KeyObjectHandleType;
|
|
425
|
+
|
|
426
|
+
export type DiffieHellmanOptions = {
|
|
427
|
+
privateKey: KeyObject;
|
|
428
|
+
publicKey: KeyObject;
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
export type DiffieHellmanCallback = (
|
|
432
|
+
err: Error | null,
|
|
433
|
+
secret?: CraftzdogBuffer,
|
|
434
|
+
) => CraftzdogBuffer | void;
|
|
435
|
+
|
|
436
|
+
// from @paulmillr/noble-curves
|
|
437
|
+
export type Hex = string | Uint8Array;
|
|
438
|
+
|
|
439
|
+
export type ImportFormat = 'raw' | 'pkcs8' | 'spki' | 'jwk';
|
|
440
|
+
|
|
441
|
+
export type Operation =
|
|
442
|
+
| 'encrypt'
|
|
443
|
+
| 'decrypt'
|
|
444
|
+
| 'sign'
|
|
445
|
+
| 'verify'
|
|
446
|
+
| 'generateKey'
|
|
447
|
+
| 'importKey'
|
|
448
|
+
| 'exportKey'
|
|
449
|
+
| 'deriveBits';
|
|
450
|
+
|
|
451
|
+
export interface KeyPairOptions {
|
|
452
|
+
namedCurve: string;
|
|
453
|
+
publicKeyEncoding?: {
|
|
454
|
+
type: 'spki';
|
|
455
|
+
format: 'pem' | 'der';
|
|
456
|
+
};
|
|
457
|
+
privateKeyEncoding?: {
|
|
458
|
+
type: 'pkcs8';
|
|
459
|
+
format: 'pem' | 'der';
|
|
460
|
+
cipher?: string;
|
|
461
|
+
passphrase?: string;
|
|
462
|
+
};
|
|
463
|
+
}
|
package/src/utils/validation.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { Buffer as SBuffer } from 'safe-buffer';
|
|
2
|
+
import type { BinaryLike, BufferLike, KeyUsage } from './types';
|
|
3
|
+
import { lazyDOMException } from './errors';
|
|
4
|
+
|
|
5
|
+
// The maximum buffer size that we'll support in the WebCrypto impl
|
|
6
|
+
const kMaxBufferLength = 2 ** 31 - 1;
|
|
7
|
+
|
|
1
8
|
export function validateFunction(f: unknown): boolean {
|
|
2
9
|
return f !== null && typeof f === 'function';
|
|
3
10
|
}
|
|
@@ -29,7 +36,95 @@ export function validateObject<T>(
|
|
|
29
36
|
(typeof value !== 'object' &&
|
|
30
37
|
(!allowFunction || typeof value !== 'function'))
|
|
31
38
|
) {
|
|
32
|
-
throw new Error(`${name} is not a valid object
|
|
39
|
+
throw new Error(`${name} is not a valid object ${value}`);
|
|
33
40
|
}
|
|
34
41
|
return true;
|
|
35
42
|
}
|
|
43
|
+
|
|
44
|
+
export const validateMaxBufferLength = (
|
|
45
|
+
data: BinaryLike | BufferLike,
|
|
46
|
+
name: string,
|
|
47
|
+
): void => {
|
|
48
|
+
const length =
|
|
49
|
+
typeof data === 'string' || data instanceof SBuffer
|
|
50
|
+
? data.length
|
|
51
|
+
: data.byteLength;
|
|
52
|
+
if (length > kMaxBufferLength) {
|
|
53
|
+
throw lazyDOMException(
|
|
54
|
+
`${name} must be less than ${kMaxBufferLength + 1} bits`,
|
|
55
|
+
'OperationError',
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const getUsagesUnion = (usageSet: KeyUsage[], ...usages: KeyUsage[]) => {
|
|
61
|
+
const newset: KeyUsage[] = [];
|
|
62
|
+
for (let n = 0; n < usages.length; n++) {
|
|
63
|
+
if (!usages[n] || usages[n] === undefined) continue;
|
|
64
|
+
if (usageSet.includes(usages[n] as KeyUsage))
|
|
65
|
+
newset.push(usages[n] as KeyUsage);
|
|
66
|
+
}
|
|
67
|
+
return newset;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const kKeyOps: {
|
|
71
|
+
[key in KeyUsage]: number;
|
|
72
|
+
} = {
|
|
73
|
+
sign: 1,
|
|
74
|
+
verify: 2,
|
|
75
|
+
encrypt: 3,
|
|
76
|
+
decrypt: 4,
|
|
77
|
+
wrapKey: 5,
|
|
78
|
+
unwrapKey: 6,
|
|
79
|
+
deriveKey: 7,
|
|
80
|
+
deriveBits: 8,
|
|
81
|
+
encapsulateBits: 9,
|
|
82
|
+
decapsulateBits: 10,
|
|
83
|
+
encapsulateKey: 11,
|
|
84
|
+
decapsulateKey: 12,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const validateKeyOps = (
|
|
88
|
+
keyOps: KeyUsage[] | undefined,
|
|
89
|
+
usagesSet: KeyUsage[],
|
|
90
|
+
) => {
|
|
91
|
+
if (keyOps === undefined) return;
|
|
92
|
+
if (!Array.isArray(keyOps)) {
|
|
93
|
+
throw lazyDOMException('keyData.key_ops', 'InvalidArgument');
|
|
94
|
+
}
|
|
95
|
+
let flags = 0;
|
|
96
|
+
for (let n = 0; n < keyOps.length; n++) {
|
|
97
|
+
const op: KeyUsage = keyOps[n] as KeyUsage;
|
|
98
|
+
const op_flag = kKeyOps[op];
|
|
99
|
+
// Skipping unknown key ops
|
|
100
|
+
if (op_flag === undefined) continue;
|
|
101
|
+
// Have we seen it already? if so, error
|
|
102
|
+
if (flags & (1 << op_flag))
|
|
103
|
+
throw lazyDOMException('Duplicate key operation', 'DataError');
|
|
104
|
+
flags |= 1 << op_flag;
|
|
105
|
+
|
|
106
|
+
// TODO(@jasnell): RFC7517 section 4.3 strong recommends validating
|
|
107
|
+
// key usage combinations. Specifically, it says that unrelated key
|
|
108
|
+
// ops SHOULD NOT be used together. We're not yet validating that here.
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (usagesSet !== undefined) {
|
|
112
|
+
for (const use of usagesSet) {
|
|
113
|
+
if (!keyOps.includes(use)) {
|
|
114
|
+
throw lazyDOMException(
|
|
115
|
+
'Key operations and usage mismatch',
|
|
116
|
+
'DataError',
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export function hasAnyNotIn(set: string[], checks: string[]) {
|
|
124
|
+
for (const s of set) {
|
|
125
|
+
if (!checks.includes(s)) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
package/lib/module/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|