visaljs 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +45 -2
- package/cli.js +8084 -0
- package/node/include/js_node.h +46 -0
- package/node/prelude/async_hooks.js +88 -0
- package/node/prelude/buffer.js +31 -0
- package/node/prelude/crypto.js +114 -0
- package/node/prelude/events.js +227 -0
- package/node/prelude/fs.js +79 -0
- package/node/prelude/http.js +536 -0
- package/node/prelude/http2.js +30 -0
- package/node/prelude/internal/crypto/asym.js +333 -0
- package/node/prelude/internal/crypto/cipher.js +205 -0
- package/node/prelude/internal/crypto/hash.js +137 -0
- package/node/prelude/internal/crypto/kdf.js +182 -0
- package/node/prelude/internal/crypto/keys.js +603 -0
- package/node/prelude/internal/crypto/random.js +118 -0
- package/node/prelude/internal/crypto/util.js +76 -0
- package/node/prelude/internal/errors.js +88 -0
- package/node/prelude/internal/querystring.js +105 -0
- package/node/prelude/module.js +53 -0
- package/node/prelude/net.js +51 -0
- package/node/prelude/os.js +129 -0
- package/node/prelude/path.js +257 -0
- package/node/prelude/process.js +21 -0
- package/node/prelude/querystring.js +469 -0
- package/node/prelude/stream.js +1327 -0
- package/node/prelude/stream_promises.js +7 -0
- package/node/prelude/stream_web.js +6 -0
- package/node/prelude/string_decoder.js +236 -0
- package/node/prelude/tty.js +18 -0
- package/node/prelude/url.js +1156 -0
- package/node/prelude/util.js +64 -0
- package/node/prelude/zlib.js +81 -0
- package/node/src/host_fs.c +126 -0
- package/node/src/host_http.c +486 -0
- package/node/src/host_os.c +505 -0
- package/node/src/host_sys.c +78 -0
- package/node/third_party/libuv/LICENSE +19 -0
- package/node/third_party/libuv/include/uv/aix.h +32 -0
- package/node/third_party/libuv/include/uv/bsd.h +34 -0
- package/node/third_party/libuv/include/uv/darwin.h +61 -0
- package/node/third_party/libuv/include/uv/errno.h +483 -0
- package/node/third_party/libuv/include/uv/linux.h +34 -0
- package/node/third_party/libuv/include/uv/os390.h +33 -0
- package/node/third_party/libuv/include/uv/posix.h +31 -0
- package/node/third_party/libuv/include/uv/sunos.h +44 -0
- package/node/third_party/libuv/include/uv/threadpool.h +37 -0
- package/node/third_party/libuv/include/uv/tree.h +521 -0
- package/node/third_party/libuv/include/uv/unix.h +512 -0
- package/node/third_party/libuv/include/uv/version.h +43 -0
- package/node/third_party/libuv/include/uv/win.h +698 -0
- package/node/third_party/libuv/include/uv.h +1990 -0
- package/node/third_party/libuv/src/fs-poll.c +290 -0
- package/node/third_party/libuv/src/heap-inl.h +245 -0
- package/node/third_party/libuv/src/idna.c +560 -0
- package/node/third_party/libuv/src/idna.h +31 -0
- package/node/third_party/libuv/src/inet.c +298 -0
- package/node/third_party/libuv/src/queue.h +90 -0
- package/node/third_party/libuv/src/random.c +123 -0
- package/node/third_party/libuv/src/strscpy.c +38 -0
- package/node/third_party/libuv/src/strscpy.h +39 -0
- package/node/third_party/libuv/src/strtok.c +52 -0
- package/node/third_party/libuv/src/strtok.h +27 -0
- package/node/third_party/libuv/src/thread-common.c +175 -0
- package/node/third_party/libuv/src/threadpool.c +419 -0
- package/node/third_party/libuv/src/timer.c +200 -0
- package/node/third_party/libuv/src/unix/async.c +418 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
- package/node/third_party/libuv/src/unix/core.c +2104 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
- package/node/third_party/libuv/src/unix/darwin.c +237 -0
- package/node/third_party/libuv/src/unix/dl.c +80 -0
- package/node/third_party/libuv/src/unix/fs.c +2303 -0
- package/node/third_party/libuv/src/unix/fsevents.c +906 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
- package/node/third_party/libuv/src/unix/internal.h +530 -0
- package/node/third_party/libuv/src/unix/kqueue.c +667 -0
- package/node/third_party/libuv/src/unix/linux.c +2761 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
- package/node/third_party/libuv/src/unix/loop.c +240 -0
- package/node/third_party/libuv/src/unix/pipe.c +555 -0
- package/node/third_party/libuv/src/unix/poll.c +159 -0
- package/node/third_party/libuv/src/unix/process.c +1123 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
- package/node/third_party/libuv/src/unix/proctitle.c +157 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
- package/node/third_party/libuv/src/unix/signal.c +581 -0
- package/node/third_party/libuv/src/unix/stream.c +1567 -0
- package/node/third_party/libuv/src/unix/tcp.c +673 -0
- package/node/third_party/libuv/src/unix/thread.c +975 -0
- package/node/third_party/libuv/src/unix/tty.c +510 -0
- package/node/third_party/libuv/src/unix/udp.c +1434 -0
- package/node/third_party/libuv/src/uv-common.c +1051 -0
- package/node/third_party/libuv/src/uv-common.h +474 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
- package/node/third_party/libuv/src/version.c +45 -0
- package/node/third_party/llhttp/LICENSE +22 -0
- package/node/third_party/llhttp/api.c +509 -0
- package/node/third_party/llhttp/http.c +170 -0
- package/node/third_party/llhttp/llhttp.c +10099 -0
- package/node/third_party/llhttp/llhttp.h +907 -0
- package/package.json +25 -4
- package/runtime/include/js_atoms.gen.h +68 -0
- package/runtime/include/js_atoms.h +54 -0
- package/runtime/include/js_bigint.h +93 -0
- package/runtime/include/js_buffer.h +79 -0
- package/runtime/include/js_builtins.h +168 -0
- package/runtime/include/js_console.h +58 -0
- package/runtime/include/js_convert.h +22 -0
- package/runtime/include/js_core.def +188 -0
- package/runtime/include/js_crypto.h +58 -0
- package/runtime/include/js_error.h +37 -0
- package/runtime/include/js_exception.h +65 -0
- package/runtime/include/js_function.h +167 -0
- package/runtime/include/js_gc.h +195 -0
- package/runtime/include/js_generator.h +96 -0
- package/runtime/include/js_host.h +19 -0
- package/runtime/include/js_jobs.h +84 -0
- package/runtime/include/js_module.h +16 -0
- package/runtime/include/js_object.h +384 -0
- package/runtime/include/js_ops.h +111 -0
- package/runtime/include/js_promise.h +45 -0
- package/runtime/include/js_regexp.h +25 -0
- package/runtime/include/js_runtime.h +30 -0
- package/runtime/include/js_symbol.h +62 -0
- package/runtime/include/js_web.h +110 -0
- package/runtime/include/jscell.h +48 -0
- package/runtime/include/jscontext.h +240 -0
- package/runtime/include/jsnum.h +42 -0
- package/runtime/include/jsstring.h +161 -0
- package/runtime/include/jsvalue.h +142 -0
- package/runtime/src/arguments.c +115 -0
- package/runtime/src/array.c +1145 -0
- package/runtime/src/arraybuffer.c +608 -0
- package/runtime/src/async_iter.c +479 -0
- package/runtime/src/atoms.c +157 -0
- package/runtime/src/base64.c +107 -0
- package/runtime/src/bigint.c +1189 -0
- package/runtime/src/blob.c +371 -0
- package/runtime/src/buffer.c +1357 -0
- package/runtime/src/builtin_table.c +100 -0
- package/runtime/src/builtins.c +987 -0
- package/runtime/src/builtins_util.h +53 -0
- package/runtime/src/collections.c +912 -0
- package/runtime/src/components.c +28 -0
- package/runtime/src/console.c +637 -0
- package/runtime/src/convert.c +82 -0
- package/runtime/src/core_all.c +21 -0
- package/runtime/src/crypto.c +116 -0
- package/runtime/src/crypto_asym.c +644 -0
- package/runtime/src/crypto_cipher.c +671 -0
- package/runtime/src/crypto_hash.c +260 -0
- package/runtime/src/crypto_host.c +414 -0
- package/runtime/src/crypto_internal.h +304 -0
- package/runtime/src/crypto_kdf.c +143 -0
- package/runtime/src/crypto_key.c +171 -0
- package/runtime/src/crypto_pkey.c +794 -0
- package/runtime/src/crypto_subtle.c +1675 -0
- package/runtime/src/date.c +940 -0
- package/runtime/src/domexception.c +169 -0
- package/runtime/src/elements.c +312 -0
- package/runtime/src/elements.h +45 -0
- package/runtime/src/encoding.c +485 -0
- package/runtime/src/error.c +297 -0
- package/runtime/src/events.c +793 -0
- package/runtime/src/exception.c +56 -0
- package/runtime/src/fetch.c +772 -0
- package/runtime/src/function.c +530 -0
- package/runtime/src/gc.c +803 -0
- package/runtime/src/generator.c +218 -0
- package/runtime/src/global.c +119 -0
- package/runtime/src/headers.c +557 -0
- package/runtime/src/inspect.c +1792 -0
- package/runtime/src/internal.h +80 -0
- package/runtime/src/iterate.c +94 -0
- package/runtime/src/iterator.c +409 -0
- package/runtime/src/jobs.c +337 -0
- package/runtime/src/jsnum.c +353 -0
- package/runtime/src/json.c +1028 -0
- package/runtime/src/math.c +243 -0
- package/runtime/src/module.c +336 -0
- package/runtime/src/number.c +176 -0
- package/runtime/src/object.c +1265 -0
- package/runtime/src/ops.c +322 -0
- package/runtime/src/os.c +196 -0
- package/runtime/src/os.h +29 -0
- package/runtime/src/process.c +432 -0
- package/runtime/src/promise.c +721 -0
- package/runtime/src/proxy.c +570 -0
- package/runtime/src/reflect.c +194 -0
- package/runtime/src/regexp.c +1141 -0
- package/runtime/src/regexp_anchor.h +34 -0
- package/runtime/src/regexp_message.h +32 -0
- package/runtime/src/shape.c +294 -0
- package/runtime/src/shape.h +46 -0
- package/runtime/src/streams.c +1046 -0
- package/runtime/src/streams.h +47 -0
- package/runtime/src/string.c +364 -0
- package/runtime/src/string_builtins.c +837 -0
- package/runtime/src/symbol.c +143 -0
- package/runtime/src/test_host.c +59 -0
- package/runtime/src/typedarray.c +1330 -0
- package/runtime/src/tznames.gen.h +712 -0
- package/runtime/src/uri.c +169 -0
- package/runtime/src/url.c +2116 -0
- package/runtime/src/weak.c +486 -0
- package/runtime/src/web.c +214 -0
- package/runtime/src/wrapper.c +59 -0
- package/runtime/src/writable.c +1486 -0
- package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
- package/runtime/third_party/ada-idna/README.md +27 -0
- package/runtime/third_party/ada-idna/convert.mjs +83 -0
- package/runtime/third_party/ada-idna/idna.c +416 -0
- package/runtime/third_party/ada-idna/idna.h +15 -0
- package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
- package/runtime/third_party/bearssl/LICENSE.txt +21 -0
- package/runtime/third_party/bearssl/README.txt +136 -0
- package/runtime/third_party/bearssl/VERSION +1 -0
- package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
- package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
- package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
- package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
- package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
- package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
- package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
- package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
- package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
- package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
- package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
- package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
- package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
- package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
- package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
- package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
- package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
- package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
- package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
- package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
- package/runtime/third_party/bearssl/src/config.h +247 -0
- package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
- package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
- package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
- package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
- package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
- package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
- package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
- package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
- package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
- package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
- package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
- package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
- package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
- package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
- package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
- package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
- package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
- package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
- package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
- package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
- package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
- package/runtime/third_party/bearssl/src/inner.h +2577 -0
- package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
- package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
- package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
- package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
- package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
- package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
- package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
- package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
- package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
- package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
- package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
- package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
- package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
- package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
- package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
- package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
- package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
- package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
- package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
- package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
- package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
- package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
- package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
- package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
- package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
- package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
- package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
- package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
- package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
- package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
- package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
- package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
- package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
- package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
- package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
- package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
- package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
- package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
- package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
- package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
- package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
- package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
- package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
- package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
- package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
- package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
- package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
- package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
- package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
- package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
- package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
- package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
- package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
- package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
- package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
- package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
- package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
- package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
- package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
- package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
- package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
- package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
- package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
- package/runtime/third_party/bearssl/src/settings.c +306 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
- package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
- package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
- package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
- package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
- package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
- package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
- package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
- package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
- package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
- package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
- package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
- package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
- package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
- package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
- package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
- package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
- package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
- package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
- package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
- package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
- package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
- package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
- package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
- package/runtime/third_party/quickjs-dtoa/README.md +23 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
- package/runtime/third_party/quickjs-regexp/README.md +22 -0
- package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
- package/runtime/third_party/v8-ieee754/LICENSE +61 -0
- package/runtime/third_party/v8-ieee754/README.md +22 -0
- package/runtime/third_party/v8-ieee754/convert.py +84 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
- package/runtime/tools/regexp_compile.c +90 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// node:crypto's asymmetric operations (ADR 0018): Sign and Verify (Writable streams, as Node's),
|
|
2
|
+
// sign and verify, publicEncrypt, privateDecrypt, privateEncrypt and publicDecrypt, ECDH,
|
|
3
|
+
// diffieHellman and getCurves: Node's lib/internal/crypto/{sig,cipher,diffiehellman}.js over the
|
|
4
|
+
// runtime's C (crypto_asym.c), which signs digests: the hashing is the Hash primitives'.
|
|
5
|
+
import {
|
|
6
|
+
cryptoDigestFinal, cryptoDigestUpdate, cryptoEcdh, cryptoEcPoint, cryptoEcPrivate, cryptoHashNew, cryptoKeyGenerate, cryptoKeyParts,
|
|
7
|
+
cryptoRsaCrypt, cryptoSign, cryptoVerify,
|
|
8
|
+
} from "visaljs:host";
|
|
9
|
+
import { Writable } from "../../stream.js";
|
|
10
|
+
import { codeError, invalidArgType, invalidArgValue, validateFunction, validateString } from "../errors.js";
|
|
11
|
+
import { asymmetricKeyTypeOf, KeyObject, preparePrivateKey, preparePublicOrPrivateKey, pssParamsOf } from "./keys.js";
|
|
12
|
+
import { isAnyArrayBuffer, isArrayBufferView, kHandle, stringBytes, validateEncoding, validateObject } from "./util.js";
|
|
13
|
+
|
|
14
|
+
const later = (fn) => setTimeout(fn, 0);
|
|
15
|
+
|
|
16
|
+
/* the runtime's error codes (JS_ASYM_ERR_*), as Node reports each */
|
|
17
|
+
function asymError(code, digest) {
|
|
18
|
+
switch (code) {
|
|
19
|
+
case 1: return codeError(Error, "ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE", "error:03000096:digital envelope routines::operation not supported for this keytype");
|
|
20
|
+
case 2: return codeError(TypeError, "ERR_CRYPTO_INVALID_DIGEST", digest === undefined ? "Invalid digest" : "Invalid digest: " + digest);
|
|
21
|
+
case 4: return codeError(Error, "ERR_OSSL_INVALID_SALT_LENGTH", "error:1C800070:Provider routines::invalid salt length");
|
|
22
|
+
case 5: return codeError(Error, "ERR_OSSL_RSA_DATA_TOO_LARGE_FOR_KEY_SIZE", "error:0200006E:rsa routines::data too large for key size");
|
|
23
|
+
case 6: return codeError(Error, "ERR_OSSL_RSA_DATA_TOO_SMALL_FOR_KEY_SIZE", "error:0200007A:rsa routines::data too small for key size");
|
|
24
|
+
case 7: return codeError(Error, "ERR_OSSL_RSA_OAEP_DECODING_ERROR", "error:02000079:rsa routines::oaep decoding error");
|
|
25
|
+
case 8: return codeError(Error, "ERR_OSSL_RSA_PADDING_CHECK_FAILED", "error:02000072:rsa routines::padding check failed");
|
|
26
|
+
case 9: return codeError(Error, "ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY", "Public key is not valid for specified curve");
|
|
27
|
+
case 10: return codeError(TypeError, "ERR_CRYPTO_INVALID_CURVE", "Invalid EC curve name");
|
|
28
|
+
default: return new Error("Crypto operation failed");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** getArrayBufferOrView: a string in `encoding`, or the buffer or view. */
|
|
33
|
+
function bytesOf(value, name, encoding) {
|
|
34
|
+
if (isAnyArrayBuffer(value) || isArrayBufferView(value)) return value;
|
|
35
|
+
if (typeof value === "string") return Buffer.from(value, encoding === undefined || encoding === "buffer" ? "utf8" : encoding);
|
|
36
|
+
throw invalidArgType(name, "of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView", value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const encode = (buffer, encoding) => (encoding && encoding !== "buffer" ? buffer.toString(encoding) : buffer);
|
|
40
|
+
|
|
41
|
+
/* ---- signing options --------------------------------------------------------------------------- */
|
|
42
|
+
|
|
43
|
+
function getIntOption(name, options) {
|
|
44
|
+
const value = options[name];
|
|
45
|
+
if (value !== undefined) {
|
|
46
|
+
if (value === value >> 0) return value;
|
|
47
|
+
throw invalidArgValue(`options.${name}`, "is invalid", value);
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getDSASignatureEncoding(options) {
|
|
53
|
+
if (typeof options === "object") {
|
|
54
|
+
const { dsaEncoding = "der" } = options;
|
|
55
|
+
if (dsaEncoding === "der") return false;
|
|
56
|
+
if (dsaEncoding === "ieee-p1363") return true;
|
|
57
|
+
throw invalidArgValue("options.dsaEncoding", "is invalid", dsaEncoding);
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* The hash a signature uses: the one named, else the key's default (its PSS parameters', or SHA-256) */
|
|
63
|
+
function hashFor(algorithm, handle) {
|
|
64
|
+
if (algorithm != null) return algorithm;
|
|
65
|
+
const pss = pssParamsOf(handle);
|
|
66
|
+
return pss ? pss[0] : "sha256";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function digestOf(hash, data) {
|
|
70
|
+
const h = cryptoHashNew(hash, undefined);
|
|
71
|
+
if (h === null) return null;
|
|
72
|
+
cryptoDigestUpdate(h, data);
|
|
73
|
+
return cryptoDigestFinal(h);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function signDigest(handle, hash, digest, options) {
|
|
77
|
+
const sig = cryptoSign(handle, hash, digest, getIntOption("padding", options), getIntOption("saltLength", options), getDSASignatureEncoding(options));
|
|
78
|
+
if (typeof sig === "number") throw asymError(sig, hash);
|
|
79
|
+
return sig;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function verifyDigest(handle, hash, digest, signature, options) {
|
|
83
|
+
const ok = cryptoVerify(handle, hash, digest, signature, getIntOption("padding", options), getIntOption("saltLength", options),
|
|
84
|
+
getDSASignatureEncoding(options));
|
|
85
|
+
if (typeof ok === "number") throw asymError(ok, hash);
|
|
86
|
+
return ok;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ---- Sign and Verify --------------------------------------------------------------------------- */
|
|
90
|
+
|
|
91
|
+
const notInitialised = () => codeError(Error, "ERR_CRYPTO_INVALID_STATE", "Not initialised");
|
|
92
|
+
|
|
93
|
+
function initDigest(self, algorithm, options) {
|
|
94
|
+
validateString(algorithm, "algorithm");
|
|
95
|
+
const handle = cryptoHashNew(algorithm, undefined);
|
|
96
|
+
if (handle === null) throw codeError(TypeError, "ERR_CRYPTO_INVALID_DIGEST", "Invalid digest");
|
|
97
|
+
self[kHandle] = { hash: handle, algorithm };
|
|
98
|
+
Writable.call(self, options);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function update(data, encoding) {
|
|
102
|
+
if (typeof data === "string") validateEncoding(data, encoding);
|
|
103
|
+
else if (!isArrayBufferView(data)) throw invalidArgType("data", "of type string or an instance of Buffer, TypedArray, or DataView", data);
|
|
104
|
+
if (this[kHandle].hash === null) throw notInitialised();
|
|
105
|
+
cryptoDigestUpdate(this[kHandle].hash, typeof data === "string" ? stringBytes(data, encoding) : data);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function _write(chunk, encoding, callback) {
|
|
110
|
+
this.update(chunk, encoding);
|
|
111
|
+
callback();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* the accumulated digest, once */
|
|
115
|
+
function takeDigest(self) {
|
|
116
|
+
const state = self[kHandle];
|
|
117
|
+
if (state.hash === null) throw notInitialised();
|
|
118
|
+
const digest = cryptoDigestFinal(state.hash);
|
|
119
|
+
state.hash = null;
|
|
120
|
+
return digest;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function Sign(algorithm, options) {
|
|
124
|
+
if (!(this instanceof Sign)) return new Sign(algorithm, options);
|
|
125
|
+
initDigest(this, algorithm, options);
|
|
126
|
+
}
|
|
127
|
+
Object.setPrototypeOf(Sign.prototype, Writable.prototype);
|
|
128
|
+
Object.setPrototypeOf(Sign, Writable);
|
|
129
|
+
Sign.prototype._write = _write;
|
|
130
|
+
Sign.prototype.update = update;
|
|
131
|
+
Sign.prototype.sign = function sign(options, encoding) {
|
|
132
|
+
if (!options) throw codeError(Error, "ERR_CRYPTO_SIGN_KEY_REQUIRED", "No key provided to sign");
|
|
133
|
+
const handle = preparePrivateKey(options);
|
|
134
|
+
const ret = signDigest(handle, this[kHandle].algorithm, takeDigest(this), options);
|
|
135
|
+
return encode(ret, encoding);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export function Verify(algorithm, options) {
|
|
139
|
+
if (!(this instanceof Verify)) return new Verify(algorithm, options);
|
|
140
|
+
initDigest(this, algorithm, options);
|
|
141
|
+
}
|
|
142
|
+
Object.setPrototypeOf(Verify.prototype, Writable.prototype);
|
|
143
|
+
Object.setPrototypeOf(Verify, Writable);
|
|
144
|
+
Verify.prototype._write = _write;
|
|
145
|
+
Verify.prototype.update = update;
|
|
146
|
+
Verify.prototype.verify = function verify(options, signature, sigEncoding) {
|
|
147
|
+
const handle = preparePublicOrPrivateKey(options);
|
|
148
|
+
signature = bytesOf(signature, "signature", sigEncoding);
|
|
149
|
+
return verifyDigest(handle, this[kHandle].algorithm, takeDigest(this), signature, options);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export function createSign(algorithm, options) {
|
|
153
|
+
return new Sign(algorithm, options);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function createVerify(algorithm, options) {
|
|
157
|
+
return new Verify(algorithm, options);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function sign(algorithm, data, key, callback) {
|
|
161
|
+
if (algorithm != null) validateString(algorithm, "algorithm");
|
|
162
|
+
if (callback !== undefined) validateFunction(callback, "callback");
|
|
163
|
+
data = bytesOf(data, "data");
|
|
164
|
+
if (!key) throw codeError(Error, "ERR_CRYPTO_SIGN_KEY_REQUIRED", "No key provided to sign");
|
|
165
|
+
getIntOption("padding", key);
|
|
166
|
+
getIntOption("saltLength", key);
|
|
167
|
+
getDSASignatureEncoding(key);
|
|
168
|
+
const handle = preparePrivateKey(key);
|
|
169
|
+
const hash = hashFor(algorithm, handle);
|
|
170
|
+
const digest = digestOf(hash, data);
|
|
171
|
+
if (digest === null) throw asymError(2, hash);
|
|
172
|
+
if (callback === undefined) return signDigest(handle, hash, digest, key);
|
|
173
|
+
let result;
|
|
174
|
+
try {
|
|
175
|
+
result = signDigest(handle, hash, digest, key);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
later(() => callback(e));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
later(() => callback(null, result));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function verify(algorithm, data, key, signature, callback) {
|
|
184
|
+
if (algorithm != null) validateString(algorithm, "algorithm");
|
|
185
|
+
if (callback !== undefined) validateFunction(callback, "callback");
|
|
186
|
+
data = bytesOf(data, "data");
|
|
187
|
+
if (!isArrayBufferView(data)) throw invalidArgType("data", "an instance of Buffer, TypedArray, or DataView", data);
|
|
188
|
+
getIntOption("padding", key);
|
|
189
|
+
getIntOption("saltLength", key);
|
|
190
|
+
getDSASignatureEncoding(key);
|
|
191
|
+
if (!isArrayBufferView(signature)) throw invalidArgType("signature", "an instance of Buffer, TypedArray, or DataView", signature);
|
|
192
|
+
const handle = preparePublicOrPrivateKey(key);
|
|
193
|
+
const hash = hashFor(algorithm, handle);
|
|
194
|
+
const digest = digestOf(hash, data);
|
|
195
|
+
if (digest === null) throw asymError(2, hash);
|
|
196
|
+
if (callback === undefined) return verifyDigest(handle, hash, digest, signature, key);
|
|
197
|
+
let result;
|
|
198
|
+
try {
|
|
199
|
+
result = verifyDigest(handle, hash, digest, signature, key);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
later(() => callback(e));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
later(() => callback(null, result));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* ---- RSA encryption ---------------------------------------------------------------------------- */
|
|
208
|
+
|
|
209
|
+
const OAEP = 4, PKCS1 = 1;
|
|
210
|
+
|
|
211
|
+
function rsaFunctionFor(op, defaultPadding, wantPrivate) {
|
|
212
|
+
return (options, buffer) => {
|
|
213
|
+
const handle = wantPrivate ? preparePrivateKey(options) : preparePublicOrPrivateKey(options);
|
|
214
|
+
const padding = options.padding || defaultPadding;
|
|
215
|
+
const { oaepHash, encoding } = options;
|
|
216
|
+
let { oaepLabel } = options;
|
|
217
|
+
if (oaepHash !== undefined) validateString(oaepHash, "key.oaepHash");
|
|
218
|
+
if (oaepLabel !== undefined) oaepLabel = bytesOf(oaepLabel, "key.oaepLabel", encoding);
|
|
219
|
+
buffer = bytesOf(buffer, "buffer", encoding);
|
|
220
|
+
const ret = cryptoRsaCrypt(handle, op, buffer, padding, oaepHash, oaepLabel);
|
|
221
|
+
if (typeof ret === "number") throw asymError(ret, oaepHash);
|
|
222
|
+
return ret;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const publicEncrypt = rsaFunctionFor(0, OAEP, false);
|
|
227
|
+
export const privateDecrypt = rsaFunctionFor(1, OAEP, true);
|
|
228
|
+
export const privateEncrypt = rsaFunctionFor(2, PKCS1, true);
|
|
229
|
+
export const publicDecrypt = rsaFunctionFor(3, PKCS1, false);
|
|
230
|
+
|
|
231
|
+
/* ---- ECDH -------------------------------------------------------------------------------------- */
|
|
232
|
+
|
|
233
|
+
const CURVES = ["prime256v1", "secp384r1", "secp521r1"];
|
|
234
|
+
|
|
235
|
+
export function getCurves() {
|
|
236
|
+
return CURVES.slice();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function getFormat(format) {
|
|
240
|
+
if (format) {
|
|
241
|
+
if (format === "compressed") return 2;
|
|
242
|
+
if (format === "hybrid") return 6;
|
|
243
|
+
if (format !== "uncompressed") throw codeError(TypeError, "ERR_CRYPTO_ECDH_INVALID_FORMAT", "Invalid ECDH format: " + format);
|
|
244
|
+
}
|
|
245
|
+
return 4;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function ECDH(curve) {
|
|
249
|
+
if (!(this instanceof ECDH)) return new ECDH(curve);
|
|
250
|
+
validateString(curve, "curve");
|
|
251
|
+
if (!CURVES.includes(curve)) throw asymError(10);
|
|
252
|
+
this[kHandle] = { curve, key: null, publicPoint: null };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
ECDH.prototype.generateKeys = function generateKeys(encoding, format) {
|
|
256
|
+
this[kHandle].key = cryptoKeyGenerate("ec", this[kHandle].curve);
|
|
257
|
+
this[kHandle].publicPoint = null;
|
|
258
|
+
return this.getPublicKey(encoding, format);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
ECDH.prototype.getPublicKey = function getPublicKey(encoding, format) {
|
|
262
|
+
const f = getFormat(format);
|
|
263
|
+
const state = this[kHandle];
|
|
264
|
+
const point = state.key !== null ? cryptoKeyParts(state.key)[0] : state.publicPoint;
|
|
265
|
+
if (point == null) throw codeError(Error, "ERR_CRYPTO_OPERATION_FAILED", "Failed to get ECDH public key");
|
|
266
|
+
return encode(cryptoEcPoint(state.curve, point, f), encoding);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
ECDH.prototype.getPrivateKey = function getPrivateKey(encoding) {
|
|
270
|
+
const state = this[kHandle];
|
|
271
|
+
if (state.key === null) throw codeError(Error, "ERR_CRYPTO_OPERATION_FAILED", "Failed to get ECDH private key");
|
|
272
|
+
return encode(cryptoKeyParts(state.key)[1], encoding);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
ECDH.prototype.setPrivateKey = function setPrivateKey(key, encoding) {
|
|
276
|
+
key = bytesOf(key, "key", encoding);
|
|
277
|
+
const handle = cryptoEcPrivate(this[kHandle].curve, key);
|
|
278
|
+
if (typeof handle === "number") throw codeError(Error, "ERR_CRYPTO_INVALID_KEYTYPE", "Private key is not valid for specified curve.");
|
|
279
|
+
this[kHandle].key = handle;
|
|
280
|
+
this[kHandle].publicPoint = null;
|
|
281
|
+
return this;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
ECDH.prototype.setPublicKey = function setPublicKey(key, encoding) {
|
|
285
|
+
key = bytesOf(key, "key", encoding);
|
|
286
|
+
const point = cryptoEcPoint(this[kHandle].curve, key, 4);
|
|
287
|
+
if (typeof point === "number") throw asymError(9);
|
|
288
|
+
this[kHandle].publicPoint = point;
|
|
289
|
+
return this;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
ECDH.prototype.computeSecret = function computeSecret(key, inEnc, outEnc) {
|
|
293
|
+
key = bytesOf(key, "key", inEnc);
|
|
294
|
+
if (this[kHandle].key === null) throw codeError(Error, "ERR_CRYPTO_OPERATION_FAILED", "Failed to compute ECDH key");
|
|
295
|
+
const ret = cryptoEcdh(this[kHandle].key, key);
|
|
296
|
+
if (typeof ret === "number") throw asymError(9);
|
|
297
|
+
return encode(ret, outEnc);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
ECDH.convertKey = function convertKey(key, curve, inEnc, outEnc, format) {
|
|
301
|
+
validateString(curve, "curve");
|
|
302
|
+
key = bytesOf(key, "key", inEnc);
|
|
303
|
+
const f = getFormat(format);
|
|
304
|
+
const ret = cryptoEcPoint(curve, key, f);
|
|
305
|
+
if (typeof ret === "number") throw asymError(ret === 10 ? 10 : 9);
|
|
306
|
+
return encode(ret, outEnc);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export function createECDH(curve) {
|
|
310
|
+
return new ECDH(curve);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* ---- diffieHellman ----------------------------------------------------------------------------- */
|
|
314
|
+
|
|
315
|
+
const keyObjectType = (actual, expected) =>
|
|
316
|
+
codeError(TypeError, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE", `Invalid key object type ${actual}, expected ${expected}.`);
|
|
317
|
+
|
|
318
|
+
export function diffieHellman(options) {
|
|
319
|
+
validateObject(options, "options");
|
|
320
|
+
const { privateKey, publicKey } = options;
|
|
321
|
+
if (!(privateKey instanceof KeyObject)) throw invalidArgValue("options.privateKey", "is invalid", privateKey);
|
|
322
|
+
if (!(publicKey instanceof KeyObject)) throw invalidArgValue("options.publicKey", "is invalid", publicKey);
|
|
323
|
+
if (privateKey.type !== "private") throw keyObjectType(privateKey.type, "private");
|
|
324
|
+
if (publicKey.type !== "public" && publicKey.type !== "private") throw keyObjectType(publicKey.type, "private or public");
|
|
325
|
+
const privateType = asymmetricKeyTypeOf(privateKey[kHandle]);
|
|
326
|
+
const publicType = asymmetricKeyTypeOf(publicKey[kHandle]);
|
|
327
|
+
if (privateType !== publicType || (privateType !== "ec" && privateType !== "x25519")) {
|
|
328
|
+
throw codeError(Error, "ERR_CRYPTO_INCOMPATIBLE_KEY", `Incompatible key types for Diffie-Hellman: ${privateType} and ${publicType}`);
|
|
329
|
+
}
|
|
330
|
+
const ret = cryptoEcdh(privateKey[kHandle], publicKey[kHandle]);
|
|
331
|
+
if (typeof ret === "number") throw asymError(9);
|
|
332
|
+
return ret;
|
|
333
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// node:crypto's ciphers (ADR 0018): Cipheriv and Decipheriv (lazy Transform streams, as Node's),
|
|
2
|
+
// getCiphers and getCipherInfo, Node's lib/internal/crypto/cipher.js over the runtime's C cipher
|
|
3
|
+
// context. Output encodings go through a StringDecoder, so a multi-byte character or a base64
|
|
4
|
+
// group isn't split between update and final.
|
|
5
|
+
import {
|
|
6
|
+
cryptoCipherFinal, cryptoCipherGetAuthTag, cryptoCipherInfo, cryptoCipherNew, cryptoCiphers, cryptoCipherSetAAD,
|
|
7
|
+
cryptoCipherSetAuthTag, cryptoCipherSetPadding, cryptoCipherUpdate,
|
|
8
|
+
} from "visaljs:host";
|
|
9
|
+
import { codeError, invalidArgType, invalidArgValue, outOfRange, validateString } from "../errors.js";
|
|
10
|
+
import { StringDecoder } from "../../string_decoder.js";
|
|
11
|
+
import { prepareSecretKey } from "./keys.js";
|
|
12
|
+
import { isAnyArrayBuffer, isArrayBufferView, kHandle, LazyTransform, stringBytes, validateEncoding, validateNumber, validateObject } from "./util.js";
|
|
13
|
+
|
|
14
|
+
/* the C side's error codes (JS_CIPHER_ERR_*), as Node reports each */
|
|
15
|
+
function cipherError(code, name, detail) {
|
|
16
|
+
switch (code) {
|
|
17
|
+
case -1: return codeError(Error, "ERR_CRYPTO_UNKNOWN_CIPHER", "Unknown cipher");
|
|
18
|
+
case 1: return codeError(RangeError, "ERR_CRYPTO_INVALID_KEYLEN", "Invalid key length");
|
|
19
|
+
case 2: return codeError(TypeError, "ERR_CRYPTO_INVALID_IV", "Invalid initialization vector");
|
|
20
|
+
case 3: return codeError(TypeError, "ERR_CRYPTO_INVALID_AUTH_TAG", "authTagLength required for " + name);
|
|
21
|
+
case 4: return codeError(TypeError, "ERR_CRYPTO_INVALID_AUTH_TAG", "Invalid authentication tag length: " + detail);
|
|
22
|
+
case 5: return new Error("Trying to add data in unsupported state");
|
|
23
|
+
case 6: return codeError(Error, "ERR_CRYPTO_INVALID_STATE", "Invalid state");
|
|
24
|
+
case 7: return codeError(Error, "ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
25
|
+
case 8: return codeError(Error, "ERR_OSSL_BAD_DECRYPT", "error:1C800064:Provider routines::bad decrypt");
|
|
26
|
+
case 9: return new Error("Unsupported state or unable to authenticate data");
|
|
27
|
+
case 10: return codeError(Error, "ERR_OSSL_TAG_NOT_SET", "error:1C800077:Provider routines::tag not set");
|
|
28
|
+
case 11: return codeError(RangeError, "ERR_CRYPTO_INVALID_MESSAGELEN", "Invalid message length");
|
|
29
|
+
case 12: return codeError(TypeError, "ERR_MISSING_ARGS", "options.plaintextLength required for CCM mode with AAD");
|
|
30
|
+
default: return new Error("Cipher operation failed");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const invalidState = (op) => codeError(Error, "ERR_CRYPTO_INVALID_STATE", "Invalid state for operation " + op);
|
|
35
|
+
|
|
36
|
+
function getUIntOption(options, key) {
|
|
37
|
+
let value;
|
|
38
|
+
if (options && (value = options[key]) != null) {
|
|
39
|
+
if (value >>> 0 !== value) throw invalidArgValue(`options.${key}`, "is invalid", value);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
return -1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getStringOption(options, key) {
|
|
46
|
+
let value;
|
|
47
|
+
if (options && (value = options[key]) != null) validateString(value, `options.${key}`);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** getArrayBufferOrView: a string in `encoding` (UTF-8 by default), or the buffer or view. */
|
|
52
|
+
function bytesOf(value, name, encoding) {
|
|
53
|
+
if (isAnyArrayBuffer(value) || isArrayBufferView(value)) return value;
|
|
54
|
+
if (typeof value === "string") return Buffer.from(value, encoding === undefined || encoding === "buffer" ? "utf8" : encoding);
|
|
55
|
+
throw invalidArgType(name, "of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView", value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getDecoder(decoder, encoding) {
|
|
59
|
+
decoder ||= new StringDecoder(encoding);
|
|
60
|
+
if (decoder.encoding !== new StringDecoder(encoding).encoding) {
|
|
61
|
+
throw codeError(Error, "ERR_INTERNAL_ASSERTION", "Cannot change encoding\nThis is caused by either a bug in Node.js or incorrect " +
|
|
62
|
+
"usage of Node.js internals.\nPlease open an issue with this stack trace at https://github.com/nodejs/node/issues\n");
|
|
63
|
+
}
|
|
64
|
+
return decoder;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createCipherWithIV(self, cipher, key, options, encrypt, iv) {
|
|
68
|
+
validateString(cipher, "cipher");
|
|
69
|
+
const encoding = getStringOption(options, "encoding");
|
|
70
|
+
key = prepareSecretKey(key, encoding);
|
|
71
|
+
iv = iv === null ? null : bytesOf(iv, "iv");
|
|
72
|
+
const authTagLength = getUIntOption(options, "authTagLength");
|
|
73
|
+
const handle = cryptoCipherNew(cipher, encrypt, key, iv, authTagLength);
|
|
74
|
+
if (typeof handle === "number") throw cipherError(handle, cipher, authTagLength);
|
|
75
|
+
self[kHandle] = handle;
|
|
76
|
+
self._decoder = null;
|
|
77
|
+
LazyTransform.call(self, options);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function update(data, inputEncoding, outputEncoding) {
|
|
81
|
+
if (typeof data === "string") validateEncoding(data, inputEncoding);
|
|
82
|
+
else if (!isArrayBufferView(data)) throw invalidArgType("data", "of type string or an instance of Buffer, TypedArray, or DataView", data);
|
|
83
|
+
const ret = cryptoCipherUpdate(this[kHandle], typeof data === "string" ? stringBytes(data, inputEncoding) : data);
|
|
84
|
+
if (typeof ret === "number") throw cipherError(ret);
|
|
85
|
+
if (outputEncoding && outputEncoding !== "buffer") {
|
|
86
|
+
this._decoder = getDecoder(this._decoder, outputEncoding);
|
|
87
|
+
return this._decoder.write(ret);
|
|
88
|
+
}
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function final(outputEncoding) {
|
|
93
|
+
const ret = cryptoCipherFinal(this[kHandle]);
|
|
94
|
+
if (typeof ret === "number") throw cipherError(ret);
|
|
95
|
+
if (outputEncoding && outputEncoding !== "buffer") {
|
|
96
|
+
this._decoder = getDecoder(this._decoder, outputEncoding);
|
|
97
|
+
return this._decoder.end(ret);
|
|
98
|
+
}
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function setAutoPadding(ap) {
|
|
103
|
+
if (!cryptoCipherSetPadding(this[kHandle], !!ap)) throw invalidState("setAutoPadding");
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function setAAD(aadbuf, options) {
|
|
108
|
+
const encoding = getStringOption(options, "encoding");
|
|
109
|
+
const plaintextLength = getUIntOption(options, "plaintextLength");
|
|
110
|
+
aadbuf = bytesOf(aadbuf, "aadbuf", encoding);
|
|
111
|
+
const code = cryptoCipherSetAAD(this[kHandle], aadbuf, plaintextLength);
|
|
112
|
+
if (code === 5) throw invalidState("setAAD");
|
|
113
|
+
if (code !== 0) throw cipherError(code);
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function _transform(chunk, encoding, callback) {
|
|
118
|
+
this.push(update.call(this, chunk, encoding));
|
|
119
|
+
callback();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function _flush(callback) {
|
|
123
|
+
try {
|
|
124
|
+
this.push(final.call(this));
|
|
125
|
+
} catch (e) {
|
|
126
|
+
callback(e);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
callback();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function Cipheriv(cipher, key, iv, options) {
|
|
133
|
+
if (!(this instanceof Cipheriv)) return new Cipheriv(cipher, key, iv, options);
|
|
134
|
+
createCipherWithIV(this, cipher, key, options, true, iv);
|
|
135
|
+
}
|
|
136
|
+
Object.setPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
|
|
137
|
+
Object.setPrototypeOf(Cipheriv, LazyTransform);
|
|
138
|
+
Object.assign(Cipheriv.prototype, { _transform, _flush, update, final, setAutoPadding });
|
|
139
|
+
Cipheriv.prototype.getAuthTag = function getAuthTag() {
|
|
140
|
+
const ret = cryptoCipherGetAuthTag(this[kHandle]);
|
|
141
|
+
if (ret === undefined) throw invalidState("getAuthTag");
|
|
142
|
+
return ret;
|
|
143
|
+
};
|
|
144
|
+
Cipheriv.prototype.setAAD = setAAD;
|
|
145
|
+
|
|
146
|
+
export function Decipheriv(cipher, key, iv, options) {
|
|
147
|
+
if (!(this instanceof Decipheriv)) return new Decipheriv(cipher, key, iv, options);
|
|
148
|
+
createCipherWithIV(this, cipher, key, options, false, iv);
|
|
149
|
+
}
|
|
150
|
+
Object.setPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
|
|
151
|
+
Object.setPrototypeOf(Decipheriv, LazyTransform);
|
|
152
|
+
Object.assign(Decipheriv.prototype, { _transform, _flush, update, final, setAutoPadding });
|
|
153
|
+
Decipheriv.prototype.setAuthTag = function setAuthTag(tagbuf, encoding) {
|
|
154
|
+
tagbuf = bytesOf(tagbuf, "buffer", encoding);
|
|
155
|
+
const code = cryptoCipherSetAuthTag(this[kHandle], tagbuf);
|
|
156
|
+
if (code === 5) throw invalidState("setAuthTag");
|
|
157
|
+
if (code !== 0) throw cipherError(code, undefined, tagbuf.byteLength);
|
|
158
|
+
return this;
|
|
159
|
+
};
|
|
160
|
+
Decipheriv.prototype.setAAD = setAAD;
|
|
161
|
+
|
|
162
|
+
export function createCipheriv(cipher, key, iv, options) {
|
|
163
|
+
return new Cipheriv(cipher, key, iv, options);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function createDecipheriv(cipher, key, iv, options) {
|
|
167
|
+
return new Decipheriv(cipher, key, iv, options);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getCiphers() {
|
|
171
|
+
return cryptoCiphers();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function validateInt32(value, name) {
|
|
175
|
+
validateNumber(value, name);
|
|
176
|
+
if (!Number.isInteger(value)) throw outOfRange(name, "an integer", value);
|
|
177
|
+
if (value < -2147483648 || value > 2147483647) throw outOfRange(name, ">= -2147483648 && <= 2147483647", value);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function getCipherInfo(nameOrNid, options) {
|
|
181
|
+
if (typeof nameOrNid !== "string" && typeof nameOrNid !== "number") {
|
|
182
|
+
throw invalidArgType("nameOrNid", "one of type string or number", nameOrNid);
|
|
183
|
+
}
|
|
184
|
+
if (typeof nameOrNid === "number") validateInt32(nameOrNid, "nameOrNid");
|
|
185
|
+
let keyLength, ivLength;
|
|
186
|
+
if (options !== undefined) {
|
|
187
|
+
validateObject(options, "options");
|
|
188
|
+
({ keyLength, ivLength } = options);
|
|
189
|
+
if (keyLength !== undefined) validateInt32(keyLength, "options.keyLength");
|
|
190
|
+
if (ivLength !== undefined) validateInt32(ivLength, "options.ivLength");
|
|
191
|
+
}
|
|
192
|
+
const info = cryptoCipherInfo(nameOrNid);
|
|
193
|
+
if (info === null) return undefined;
|
|
194
|
+
const [name, nid, mode, blockSize, ivLen, keyLen] = info;
|
|
195
|
+
if (keyLength !== undefined && keyLength !== keyLen) return undefined;
|
|
196
|
+
if (ivLength !== undefined) {
|
|
197
|
+
const ok = mode === "gcm" ? ivLength > 0 : mode === "ccm" ? ivLength >= 7 && ivLength <= 13 : ivLength === ivLen;
|
|
198
|
+
if (!ok) return undefined;
|
|
199
|
+
}
|
|
200
|
+
const ret = { mode, name, nid };
|
|
201
|
+
if (mode !== "stream") ret.blockSize = blockSize;
|
|
202
|
+
if (ivLen !== 0) ret.ivLength = ivLength ?? ivLen;
|
|
203
|
+
ret.keyLength = keyLen;
|
|
204
|
+
return ret;
|
|
205
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// node:crypto's Hash and Hmac, and crypto.hash() (ADR 0018): Node's lib/internal/crypto/hash.js
|
|
2
|
+
// over the host primitives, which hash in C (BearSSL, and SHA-3 of our own).
|
|
3
|
+
import {
|
|
4
|
+
cryptoDigestFinal, cryptoDigestUpdate, cryptoHashCopy, cryptoHashes, cryptoHashInfo, cryptoHashNew, cryptoHmacNew,
|
|
5
|
+
} from "visaljs:host";
|
|
6
|
+
import { codeError, invalidArgType, invalidArgValue, outOfRange, validateString } from "../errors.js";
|
|
7
|
+
import {
|
|
8
|
+
encodeOutput, isArrayBufferView, kFinalized, kHandle, kState, LazyTransform, stringBytes, validateEncoding, validateNumber,
|
|
9
|
+
} from "./util.js";
|
|
10
|
+
import { prepareSecretKey } from "./keys.js";
|
|
11
|
+
|
|
12
|
+
const finalized = () => codeError(Error, "ERR_CRYPTO_HASH_FINALIZED", "Digest already called");
|
|
13
|
+
|
|
14
|
+
function validateUint32(value, name) {
|
|
15
|
+
validateNumber(value, name);
|
|
16
|
+
if (!Number.isInteger(value)) throw outOfRange(name, "an integer", value);
|
|
17
|
+
if (value < 0 || value > 4294967295) throw outOfRange(name, ">= 0 && <= 4294967295", value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The output length option: undefined, or a length the algorithm can give. */
|
|
21
|
+
function outputLength(algorithm, options) {
|
|
22
|
+
const xofLen = typeof options === "object" && options !== null ? options.outputLength : undefined;
|
|
23
|
+
if (xofLen === undefined) return undefined;
|
|
24
|
+
validateUint32(xofLen, "options.outputLength");
|
|
25
|
+
const info = cryptoHashInfo(algorithm);
|
|
26
|
+
if (info >= 0 && xofLen !== info) {
|
|
27
|
+
throw codeError(Error, "ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH", "error:030000B2:digital envelope routines::not XOF or invalid length");
|
|
28
|
+
}
|
|
29
|
+
return xofLen;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function Hash(algorithm, options) {
|
|
33
|
+
if (!new.target) return new Hash(algorithm, options);
|
|
34
|
+
const copyOf = algorithm !== null && typeof algorithm === "object" && kHandle in algorithm ? algorithm : null;
|
|
35
|
+
if (copyOf) {
|
|
36
|
+
this[kHandle] = cryptoHashCopy(copyOf[kHandle], outputLength(copyOf._algorithm, options));
|
|
37
|
+
this._algorithm = copyOf._algorithm;
|
|
38
|
+
} else {
|
|
39
|
+
validateString(algorithm, "algorithm");
|
|
40
|
+
const handle = cryptoHashNew(algorithm, cryptoHashInfo(algorithm) === -1 ? undefined : outputLength(algorithm, options));
|
|
41
|
+
if (handle === null) throw new Error("Digest method not supported");
|
|
42
|
+
this[kHandle] = handle;
|
|
43
|
+
Object.defineProperty(this, "_algorithm", { value: algorithm, writable: true }); /* not shown, as Node keeps it in C++ */
|
|
44
|
+
}
|
|
45
|
+
this[kState] = { [kFinalized]: false };
|
|
46
|
+
LazyTransform.call(this, options);
|
|
47
|
+
}
|
|
48
|
+
Object.setPrototypeOf(Hash.prototype, LazyTransform.prototype);
|
|
49
|
+
Object.setPrototypeOf(Hash, LazyTransform);
|
|
50
|
+
|
|
51
|
+
Hash.prototype.copy = function copy(options) {
|
|
52
|
+
if (this[kState][kFinalized]) throw finalized();
|
|
53
|
+
return new Hash(this, options);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Hash.prototype._transform = function _transform(chunk, encoding, callback) {
|
|
57
|
+
cryptoDigestUpdate(this[kHandle], typeof chunk === "string" ? stringBytes(chunk, encoding) : chunk);
|
|
58
|
+
callback();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
Hash.prototype._flush = function _flush(callback) {
|
|
62
|
+
this.push(cryptoDigestFinal(this[kHandle]));
|
|
63
|
+
callback();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
Hash.prototype.update = function update(data, encoding) {
|
|
67
|
+
if (this[kState][kFinalized]) throw finalized();
|
|
68
|
+
if (typeof data === "string") validateEncoding(data, encoding);
|
|
69
|
+
else if (!isArrayBufferView(data)) throw invalidArgType("data", "of type string or an instance of Buffer, TypedArray, or DataView", data);
|
|
70
|
+
cryptoDigestUpdate(this[kHandle], typeof data === "string" ? stringBytes(data, encoding) : data);
|
|
71
|
+
return this;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
Hash.prototype.digest = function digest(outputEncoding) {
|
|
75
|
+
if (this[kState][kFinalized]) throw finalized();
|
|
76
|
+
const ret = encodeOutput(cryptoDigestFinal(this[kHandle]), outputEncoding && `${outputEncoding}`);
|
|
77
|
+
this[kState][kFinalized] = true;
|
|
78
|
+
return ret;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export function Hmac(hmac, key, options) {
|
|
82
|
+
if (!(this instanceof Hmac)) return new Hmac(hmac, key, options);
|
|
83
|
+
validateString(hmac, "hmac");
|
|
84
|
+
const encoding = options !== null && typeof options === "object" ? options.encoding : undefined;
|
|
85
|
+
const handle = cryptoHmacNew(hmac, prepareSecretKey(key, encoding));
|
|
86
|
+
if (handle === null) throw codeError(TypeError, "ERR_CRYPTO_INVALID_DIGEST", "Invalid digest: " + hmac);
|
|
87
|
+
this[kHandle] = handle;
|
|
88
|
+
this[kState] = { [kFinalized]: false };
|
|
89
|
+
LazyTransform.call(this, options);
|
|
90
|
+
}
|
|
91
|
+
Object.setPrototypeOf(Hmac.prototype, LazyTransform.prototype);
|
|
92
|
+
Object.setPrototypeOf(Hmac, LazyTransform);
|
|
93
|
+
|
|
94
|
+
Hmac.prototype.update = Hash.prototype.update;
|
|
95
|
+
|
|
96
|
+
Hmac.prototype.digest = function digest(outputEncoding) {
|
|
97
|
+
if (this[kState][kFinalized]) {
|
|
98
|
+
const buf = Buffer.from("");
|
|
99
|
+
return outputEncoding && outputEncoding !== "buffer" ? buf.toString(outputEncoding) : buf;
|
|
100
|
+
}
|
|
101
|
+
const ret = encodeOutput(cryptoDigestFinal(this[kHandle]), outputEncoding && `${outputEncoding}`);
|
|
102
|
+
this[kState][kFinalized] = true;
|
|
103
|
+
return ret;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
Hmac.prototype._flush = Hash.prototype._flush;
|
|
107
|
+
Hmac.prototype._transform = Hash.prototype._transform;
|
|
108
|
+
|
|
109
|
+
export function createHash(algorithm, options) {
|
|
110
|
+
return new Hash(algorithm, options);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function createHmac(hmac, key, options) {
|
|
114
|
+
return new Hmac(hmac, key, options);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** crypto.hash(algorithm, data, outputEncoding = "hex"): a one-shot digest. */
|
|
118
|
+
export function hash(algorithm, input, outputEncoding = "hex") {
|
|
119
|
+
validateString(algorithm, "algorithm");
|
|
120
|
+
if (typeof input !== "string" && !isArrayBufferView(input)) {
|
|
121
|
+
throw invalidArgType("input", "of type string or an instance of Buffer, TypedArray, or DataView", input);
|
|
122
|
+
}
|
|
123
|
+
let encoding = outputEncoding;
|
|
124
|
+
if (outputEncoding !== "hex") {
|
|
125
|
+
validateString(outputEncoding, "outputEncoding");
|
|
126
|
+
if (outputEncoding.toLowerCase() === "buffer") encoding = "buffer";
|
|
127
|
+
else if (!Buffer.isEncoding(outputEncoding)) throw invalidArgValue("outputEncoding", "is invalid", outputEncoding);
|
|
128
|
+
}
|
|
129
|
+
const handle = cryptoHashNew(algorithm, undefined);
|
|
130
|
+
if (handle === null) throw new Error("Digest method " + algorithm + " is not supported");
|
|
131
|
+
cryptoDigestUpdate(handle, input);
|
|
132
|
+
return encodeOutput(cryptoDigestFinal(handle), encoding);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function getHashes() {
|
|
136
|
+
return cryptoHashes();
|
|
137
|
+
}
|