react-native-quick-crypto 1.0.0-beta.8 → 1.0.0
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 +145 -6
- package/README.md +14 -27
- package/android/CMakeLists.txt +62 -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 +322 -0
- package/cpp/cipher/HybridCipher.hpp +68 -0
- package/cpp/cipher/HybridCipherFactory.hpp +105 -0
- package/cpp/cipher/HybridRsaCipher.cpp +348 -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 +749 -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/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 +191 -0
- package/cpp/sign/HybridSignHandle.hpp +36 -0
- package/cpp/sign/HybridVerifyHandle.cpp +158 -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/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/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 +109 -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/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/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 +987 -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 +106 -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/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/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 +982 -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 +50 -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/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/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 +125 -23
- 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 +30 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +115 -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 +111 -1
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +1 -1
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +104 -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++/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 +28 -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 +148 -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/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/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 +1436 -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 +209 -29
- 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,11 +46,31 @@ 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
|
+
// Node.js style key pair types (lowercase)
|
|
69
|
+
export type RSAKeyPairType = 'rsa' | 'rsa-pss';
|
|
70
|
+
export type ECKeyPairType = 'ec';
|
|
71
|
+
export type DSAKeyPairType = 'dsa';
|
|
72
|
+
export type DHKeyPairType = 'dh';
|
|
73
|
+
|
|
48
74
|
export type KeyPairAlgorithm =
|
|
49
75
|
| RSAKeyPairAlgorithm
|
|
50
76
|
| ECKeyPairAlgorithm
|
|
@@ -75,6 +101,49 @@ export type EncryptDecryptAlgorithm =
|
|
|
75
101
|
| 'AES-CBC'
|
|
76
102
|
| 'AES-GCM';
|
|
77
103
|
|
|
104
|
+
export type RsaOaepParams = {
|
|
105
|
+
name: 'RSA-OAEP';
|
|
106
|
+
label?: BufferLike;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type AesCbcParams = {
|
|
110
|
+
name: 'AES-CBC';
|
|
111
|
+
iv: BufferLike;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type AesCtrParams = {
|
|
115
|
+
name: 'AES-CTR';
|
|
116
|
+
counter: TypedArray;
|
|
117
|
+
length: number;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type AesGcmParams = {
|
|
121
|
+
name: 'AES-GCM';
|
|
122
|
+
iv: BufferLike;
|
|
123
|
+
tagLength?: TagLength;
|
|
124
|
+
additionalData?: BufferLike;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type AesKwParams = {
|
|
128
|
+
name: 'AES-KW';
|
|
129
|
+
wrappingKey?: BufferLike;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type AesKeyGenParams = {
|
|
133
|
+
length: AESLength;
|
|
134
|
+
name?: AESAlgorithm;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type TagLength = 32 | 64 | 96 | 104 | 112 | 120 | 128;
|
|
138
|
+
|
|
139
|
+
export type AESLength = 128 | 192 | 256;
|
|
140
|
+
|
|
141
|
+
export type EncryptDecryptParams =
|
|
142
|
+
| AesCbcParams
|
|
143
|
+
| AesCtrParams
|
|
144
|
+
| AesGcmParams
|
|
145
|
+
| RsaOaepParams;
|
|
146
|
+
|
|
78
147
|
export type AnyAlgorithm =
|
|
79
148
|
| DigestAlgorithm
|
|
80
149
|
| HashAlgorithm
|
|
@@ -94,14 +163,20 @@ export type SubtleAlgorithm = {
|
|
|
94
163
|
name: AnyAlgorithm;
|
|
95
164
|
salt?: string;
|
|
96
165
|
iterations?: number;
|
|
97
|
-
hash?: HashAlgorithm;
|
|
166
|
+
hash?: HashAlgorithm | { name: string };
|
|
98
167
|
namedCurve?: NamedCurve;
|
|
99
168
|
length?: number;
|
|
100
169
|
modulusLength?: number;
|
|
101
170
|
publicExponent?: number | Uint8Array;
|
|
171
|
+
saltLength?: number;
|
|
102
172
|
};
|
|
103
173
|
|
|
104
|
-
export type KeyPairType =
|
|
174
|
+
export type KeyPairType =
|
|
175
|
+
| CFRGKeyPairType
|
|
176
|
+
| RSAKeyPairType
|
|
177
|
+
| ECKeyPairType
|
|
178
|
+
| DSAKeyPairType
|
|
179
|
+
| DHKeyPairType;
|
|
105
180
|
|
|
106
181
|
export type KeyUsage =
|
|
107
182
|
| 'encrypt'
|
|
@@ -110,47 +185,65 @@ export type KeyUsage =
|
|
|
110
185
|
| 'verify'
|
|
111
186
|
| 'deriveKey'
|
|
112
187
|
| 'deriveBits'
|
|
188
|
+
| 'encapsulateBits'
|
|
189
|
+
| 'decapsulateBits'
|
|
190
|
+
| 'encapsulateKey'
|
|
191
|
+
| 'decapsulateKey'
|
|
113
192
|
| 'wrapKey'
|
|
114
193
|
| 'unwrapKey';
|
|
115
194
|
|
|
116
|
-
//
|
|
117
|
-
// TODO(osp) move this into native side to make sure they always match
|
|
195
|
+
// TODO: These enums need to be defined on the native side
|
|
118
196
|
export enum KFormatType {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
197
|
+
DER,
|
|
198
|
+
PEM,
|
|
199
|
+
JWK,
|
|
122
200
|
}
|
|
123
201
|
|
|
124
|
-
// Same as KFormatType, this enum needs to be defined on the native side
|
|
125
202
|
export enum KeyType {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
203
|
+
SECRET,
|
|
204
|
+
PUBLIC,
|
|
205
|
+
PRIVATE,
|
|
129
206
|
}
|
|
130
207
|
|
|
131
208
|
export enum KeyEncoding {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
209
|
+
PKCS1,
|
|
210
|
+
PKCS8,
|
|
211
|
+
SPKI,
|
|
212
|
+
SEC1,
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export enum KeyFormat {
|
|
216
|
+
RAW,
|
|
217
|
+
PKCS8,
|
|
218
|
+
SPKI,
|
|
219
|
+
JWK,
|
|
136
220
|
}
|
|
137
221
|
|
|
222
|
+
export type KeyData = BufferLike | BinaryLike | JWK;
|
|
223
|
+
|
|
224
|
+
export const kNamedCurveAliases = {
|
|
225
|
+
'P-256': 'prime256v1',
|
|
226
|
+
'P-384': 'secp384r1',
|
|
227
|
+
'P-521': 'secp521r1',
|
|
228
|
+
} as const;
|
|
229
|
+
// end TODO
|
|
230
|
+
|
|
138
231
|
export type KeyPairGenConfig = {
|
|
139
|
-
publicFormat?: KFormatType;
|
|
232
|
+
publicFormat?: KFormatType | -1;
|
|
140
233
|
publicType?: KeyEncoding;
|
|
141
|
-
privateFormat?: KFormatType;
|
|
234
|
+
privateFormat?: KFormatType | -1;
|
|
142
235
|
privateType?: KeyEncoding;
|
|
143
236
|
cipher?: string;
|
|
144
237
|
passphrase?: ArrayBuffer;
|
|
145
238
|
};
|
|
146
239
|
|
|
147
240
|
export type AsymmetricKeyType =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
CFRGKeyPairType;
|
|
241
|
+
| 'rsa'
|
|
242
|
+
| 'rsa-pss'
|
|
243
|
+
| 'dsa'
|
|
244
|
+
| 'ec'
|
|
245
|
+
| 'dh'
|
|
246
|
+
| CFRGKeyPairType;
|
|
154
247
|
|
|
155
248
|
type JWKkty = 'AES' | 'RSA' | 'EC' | 'oct';
|
|
156
249
|
type JWKuse = 'sig' | 'enc';
|
|
@@ -232,9 +325,14 @@ export type GenerateKeyPairOptions = {
|
|
|
232
325
|
mgf1Hash?: string;
|
|
233
326
|
};
|
|
234
327
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
328
|
+
export type KeyPairKey =
|
|
329
|
+
| ArrayBuffer
|
|
330
|
+
| Buffer
|
|
331
|
+
| string
|
|
332
|
+
| KeyObject
|
|
333
|
+
| KeyObjectHandle
|
|
334
|
+
| CryptoKey
|
|
335
|
+
| undefined;
|
|
238
336
|
|
|
239
337
|
export type GenerateKeyPairReturn = [
|
|
240
338
|
error?: Error,
|
|
@@ -260,6 +358,11 @@ export type CryptoKeyPair = {
|
|
|
260
358
|
privateKey: KeyPairKey;
|
|
261
359
|
};
|
|
262
360
|
|
|
361
|
+
export type WebCryptoKeyPair = {
|
|
362
|
+
publicKey: CryptoKey;
|
|
363
|
+
privateKey: CryptoKey;
|
|
364
|
+
};
|
|
365
|
+
|
|
263
366
|
export enum KeyVariant {
|
|
264
367
|
RSA_SSA_PKCS1_v1_5,
|
|
265
368
|
RSA_PSS,
|
|
@@ -273,3 +376,80 @@ export enum KeyVariant {
|
|
|
273
376
|
export type SignCallback = (err: Error | null, signature?: ArrayBuffer) => void;
|
|
274
377
|
|
|
275
378
|
export type VerifyCallback = (err: Error | null, valid?: boolean) => void;
|
|
379
|
+
|
|
380
|
+
export type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary';
|
|
381
|
+
export type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';
|
|
382
|
+
export type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';
|
|
383
|
+
export type Encoding =
|
|
384
|
+
| BinaryToTextEncoding
|
|
385
|
+
| CharacterEncoding
|
|
386
|
+
| LegacyCharacterEncoding
|
|
387
|
+
| 'buffer';
|
|
388
|
+
|
|
389
|
+
// These are for shortcomings in @types/node
|
|
390
|
+
// Here we use "*Type" instead of "*Types" like node does.
|
|
391
|
+
// export type CipherCBCType = 'aes-128-cbc' | 'aes-192-cbc' | 'aes-256-cbc';
|
|
392
|
+
export type CipherCFBType =
|
|
393
|
+
| 'aes-128-cfb'
|
|
394
|
+
| 'aes-192-cfb'
|
|
395
|
+
| 'aes-256-cfb'
|
|
396
|
+
| 'aes-128-cfb1'
|
|
397
|
+
| 'aes-192-cfb1'
|
|
398
|
+
| 'aes-256-cfb1'
|
|
399
|
+
| 'aes-128-cfb8'
|
|
400
|
+
| 'aes-192-cfb8'
|
|
401
|
+
| 'aes-256-cfb8';
|
|
402
|
+
export type CipherCTRType = 'aes-128-ctr' | 'aes-192-ctr' | 'aes-256-ctr';
|
|
403
|
+
export type CipherDESType =
|
|
404
|
+
| 'des'
|
|
405
|
+
| 'des3'
|
|
406
|
+
| 'des-cbc'
|
|
407
|
+
| 'des-ecb'
|
|
408
|
+
| 'des-ede'
|
|
409
|
+
| 'des-ede-cbc'
|
|
410
|
+
| 'des-ede3'
|
|
411
|
+
| 'des-ede3-cbc';
|
|
412
|
+
export type CipherECBType = 'aes-128-ecb' | 'aes-192-ecb' | 'aes-256-ecb';
|
|
413
|
+
export type CipherGCMType = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm';
|
|
414
|
+
export type CipherOFBType = 'aes-128-ofb' | 'aes-192-ofb' | 'aes-256-ofb';
|
|
415
|
+
|
|
416
|
+
export type KeyObjectHandle = KeyObjectHandleType;
|
|
417
|
+
|
|
418
|
+
export type DiffieHellmanOptions = {
|
|
419
|
+
privateKey: KeyObject;
|
|
420
|
+
publicKey: KeyObject;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
export type DiffieHellmanCallback = (
|
|
424
|
+
err: Error | null,
|
|
425
|
+
secret?: CraftzdogBuffer,
|
|
426
|
+
) => CraftzdogBuffer | void;
|
|
427
|
+
|
|
428
|
+
// from @paulmillr/noble-curves
|
|
429
|
+
export type Hex = string | Uint8Array;
|
|
430
|
+
|
|
431
|
+
export type ImportFormat = 'raw' | 'pkcs8' | 'spki' | 'jwk';
|
|
432
|
+
|
|
433
|
+
export type Operation =
|
|
434
|
+
| 'encrypt'
|
|
435
|
+
| 'decrypt'
|
|
436
|
+
| 'sign'
|
|
437
|
+
| 'verify'
|
|
438
|
+
| 'generateKey'
|
|
439
|
+
| 'importKey'
|
|
440
|
+
| 'exportKey'
|
|
441
|
+
| 'deriveBits';
|
|
442
|
+
|
|
443
|
+
export interface KeyPairOptions {
|
|
444
|
+
namedCurve: string;
|
|
445
|
+
publicKeyEncoding?: {
|
|
446
|
+
type: 'spki';
|
|
447
|
+
format: 'pem' | 'der';
|
|
448
|
+
};
|
|
449
|
+
privateKeyEncoding?: {
|
|
450
|
+
type: 'pkcs8';
|
|
451
|
+
format: 'pem' | 'der';
|
|
452
|
+
cipher?: string;
|
|
453
|
+
passphrase?: string;
|
|
454
|
+
};
|
|
455
|
+
}
|
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
|
-
|