@emulsify/cli 1.9.0 → 1.10.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/README.md +20 -13
- package/dist/node_modules/.package-lock.json +37 -24
- package/dist/node_modules/@types/node/README.md +5 -6
- package/dist/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/dist/node_modules/@types/node/assert.d.ts +955 -45
- package/dist/node_modules/@types/node/async_hooks.d.ts +391 -87
- package/dist/node_modules/@types/node/buffer.d.ts +2210 -17
- package/dist/node_modules/@types/node/child_process.d.ts +1051 -189
- package/dist/node_modules/@types/node/cluster.d.ts +421 -143
- package/dist/node_modules/@types/node/console.d.ts +359 -49
- package/dist/node_modules/@types/node/constants.d.ts +3 -3
- package/dist/node_modules/@types/node/crypto.d.ts +3528 -291
- package/dist/node_modules/@types/node/dgram.d.ts +446 -30
- package/dist/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- package/dist/node_modules/@types/node/dns/promises.d.ts +476 -0
- package/dist/node_modules/@types/node/dns.d.ts +588 -240
- package/dist/node_modules/@types/node/dom-events.d.ts +124 -0
- package/dist/node_modules/@types/node/domain.d.ts +159 -16
- package/dist/node_modules/@types/node/events.d.ts +890 -41
- package/dist/node_modules/@types/node/fs/promises.d.ts +980 -369
- package/dist/node_modules/@types/node/fs.d.ts +2599 -869
- package/dist/node_modules/@types/node/globals.d.ts +374 -727
- package/dist/node_modules/@types/node/globals.global.d.ts +1 -1
- package/dist/node_modules/@types/node/http.d.ts +1459 -132
- package/dist/node_modules/@types/node/http2.d.ts +1333 -123
- package/dist/node_modules/@types/node/https.d.ts +289 -13
- package/dist/node_modules/@types/node/index.d.ts +37 -46
- package/dist/node_modules/@types/node/inspector.d.ts +367 -671
- package/dist/node_modules/@types/node/module.d.ts +273 -14
- package/dist/node_modules/@types/node/net.d.ts +741 -66
- package/dist/node_modules/@types/node/os.d.ts +275 -23
- package/dist/node_modules/@types/node/package.json +95 -110
- package/dist/node_modules/@types/node/path.d.ts +27 -4
- package/dist/node_modules/@types/node/perf_hooks.d.ts +756 -125
- package/dist/node_modules/@types/node/process.d.ts +1429 -127
- package/dist/node_modules/@types/node/punycode.d.ts +65 -26
- package/dist/node_modules/@types/node/querystring.d.ts +121 -9
- package/dist/node_modules/@types/node/readline/promises.d.ts +150 -0
- package/dist/node_modules/@types/node/readline.d.ts +405 -49
- package/dist/node_modules/@types/node/repl.d.ts +99 -73
- package/dist/node_modules/@types/node/sea.d.ts +153 -0
- package/dist/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/dist/node_modules/@types/node/stream/promises.d.ts +83 -0
- package/dist/node_modules/@types/node/stream/web.d.ts +367 -0
- package/dist/node_modules/@types/node/stream.d.ts +1462 -273
- package/dist/node_modules/@types/node/string_decoder.d.ts +59 -2
- package/dist/node_modules/@types/node/test.d.ts +1719 -0
- package/dist/node_modules/@types/node/timers/promises.d.ts +97 -0
- package/dist/node_modules/@types/node/timers.d.ts +233 -12
- package/dist/node_modules/@types/node/tls.d.ts +540 -189
- package/dist/node_modules/@types/node/trace_events.d.ts +143 -10
- package/dist/node_modules/@types/node/tty.d.ts +156 -17
- package/dist/node_modules/@types/node/url.d.ts +812 -47
- package/dist/node_modules/@types/node/util.d.ts +2159 -145
- package/dist/node_modules/@types/node/v8.d.ts +693 -74
- package/dist/node_modules/@types/node/vm.d.ts +813 -44
- package/dist/node_modules/@types/node/wasi.d.ts +121 -28
- package/dist/node_modules/@types/node/worker_threads.d.ts +514 -61
- package/dist/node_modules/@types/node/zlib.d.ts +220 -54
- package/dist/node_modules/ajv-formats/node_modules/ajv/README.md +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/code.js +1 -0
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/code.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/index.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.d.ts +2 -2
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.d.ts +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/index.d.ts +3 -3
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/json-schema.d.ts +10 -10
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.js +5 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/codegen/code.ts +1 -0
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/index.ts +2 -2
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/resolve.ts +2 -2
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/runtime/uri.ts +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/index.ts +3 -3
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/json-schema.ts +10 -10
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/vocabularies/discriminator/index.ts +4 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/package.json +5 -5
- package/dist/node_modules/commander/Readme.md +10 -8
- package/dist/node_modules/commander/esm.mjs +1 -1
- package/dist/node_modules/commander/lib/argument.js +9 -5
- package/dist/node_modules/commander/lib/command.js +406 -196
- package/dist/node_modules/commander/lib/error.js +0 -4
- package/dist/node_modules/commander/lib/help.js +101 -38
- package/dist/node_modules/commander/lib/option.js +11 -8
- package/dist/node_modules/commander/lib/suggestSimilar.js +5 -4
- package/dist/node_modules/commander/package.json +23 -19
- package/dist/node_modules/commander/typings/index.d.ts +110 -40
- package/dist/node_modules/debug/package.json +4 -3
- package/dist/node_modules/debug/src/browser.js +3 -1
- package/dist/node_modules/debug/src/node.js +2 -2
- package/dist/node_modules/fast-uri/.gitattributes +2 -0
- package/dist/node_modules/fast-uri/.github/.stale.yml +21 -0
- package/dist/node_modules/fast-uri/.github/dependabot.yml +13 -0
- package/dist/node_modules/fast-uri/.github/tests_checker.yml +8 -0
- package/dist/node_modules/fast-uri/.github/workflows/ci.yml +23 -0
- package/dist/node_modules/fast-uri/.github/workflows/package-manager-ci.yml +20 -0
- package/dist/node_modules/fast-uri/.taprc +3 -0
- package/dist/node_modules/fast-uri/LICENSE +30 -0
- package/dist/node_modules/fast-uri/README.md +125 -0
- package/dist/node_modules/fast-uri/benchmark.js +105 -0
- package/dist/node_modules/fast-uri/index.js +309 -0
- package/dist/node_modules/fast-uri/lib/schemes.js +188 -0
- package/dist/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/dist/node_modules/fast-uri/lib/utils.js +242 -0
- package/dist/node_modules/fast-uri/package.json +39 -0
- package/dist/node_modules/fast-uri/test/.gitkeep +0 -0
- package/dist/node_modules/fast-uri/test/ajv.test.js +39 -0
- package/dist/node_modules/fast-uri/test/compatibility.test.js +130 -0
- package/dist/node_modules/fast-uri/test/equal.test.js +104 -0
- package/dist/node_modules/fast-uri/test/parse.test.js +319 -0
- package/dist/node_modules/fast-uri/test/resolve.test.js +76 -0
- package/dist/node_modules/fast-uri/test/serialize.test.js +144 -0
- package/dist/node_modules/fast-uri/test/uri-js.test.js +940 -0
- package/dist/node_modules/fast-uri/test/util.test.js +24 -0
- package/dist/node_modules/fast-uri/types/index.d.ts +53 -0
- package/dist/node_modules/fast-uri/types/index.test-d.ts +17 -0
- package/dist/node_modules/fs-extra/README.md +32 -2
- package/dist/node_modules/fs-extra/lib/copy/copy-sync.js +3 -11
- package/dist/node_modules/fs-extra/lib/copy/copy.js +120 -178
- package/dist/node_modules/fs-extra/lib/copy/index.js +1 -1
- package/dist/node_modules/fs-extra/lib/ensure/file.js +31 -34
- package/dist/node_modules/fs-extra/lib/ensure/link.js +27 -27
- package/dist/node_modules/fs-extra/lib/ensure/symlink-paths.js +57 -55
- package/dist/node_modules/fs-extra/lib/ensure/symlink-type.js +16 -13
- package/dist/node_modules/fs-extra/lib/ensure/symlink.js +29 -44
- package/dist/node_modules/fs-extra/lib/esm.mjs +68 -0
- package/dist/node_modules/fs-extra/lib/fs/index.js +29 -17
- package/dist/node_modules/fs-extra/lib/move/index.js +1 -1
- package/dist/node_modules/fs-extra/lib/move/move-sync.js +2 -1
- package/dist/node_modules/fs-extra/lib/move/move.js +38 -54
- package/dist/node_modules/fs-extra/lib/output-file/index.js +10 -19
- package/dist/node_modules/fs-extra/lib/remove/index.js +2 -7
- package/dist/node_modules/fs-extra/lib/util/stat.js +46 -42
- package/dist/node_modules/fs-extra/lib/util/utimes.js +21 -11
- package/dist/node_modules/fs-extra/package.json +11 -7
- package/dist/node_modules/simple-git/dist/cjs/index.js +4958 -0
- package/dist/node_modules/simple-git/dist/cjs/index.js.map +7 -0
- package/dist/node_modules/simple-git/dist/esm/index.js +4813 -0
- package/dist/node_modules/simple-git/dist/esm/index.js.map +7 -0
- package/dist/node_modules/simple-git/dist/esm/package.json +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/api.d.ts +3 -13
- package/dist/node_modules/simple-git/dist/src/lib/args/log-format.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/args/pathspec.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/git-error.d.ts +3 -2
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/git-factory.d.ts +15 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-branch.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-diff-summary.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-list-log-summary.d.ts +2 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-pull.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/abort-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/block-unsafe-operations-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/completion-detection.plugin.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/plugins/custom-binary.plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/index.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/plugin-store.d.ts +11 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/progress-monitor-plugin.d.ts +1 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/simple-git-plugin.d.ts +10 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/suffix-paths.plugin.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/timout-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchSummary.d.ts +14 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/FileStatusSummary.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/responses/PullSummary.d.ts +25 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/StatusSummary.d.ts +2 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/git-executor-chain.d.ts +1 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/git-executor.d.ts +3 -4
- package/dist/node_modules/simple-git/dist/src/lib/tasks/checkout.d.ts +2 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/clone.d.ts +3 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/commit.d.ts +4 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/config.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff.d.ts +5 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/fetch.d.ts +2 -1
- package/dist/node_modules/simple-git/dist/src/lib/tasks/first-commit.d.ts +2 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/log.d.ts +3 -3
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/remote.d.ts +3 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/show.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +4 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/task.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/tasks/version.d.ts +9 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/types/index.d.ts +64 -5
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/exit-codes.d.ts +1 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/line-parser.d.ts +1 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/task-parser.d.ts +2 -2
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/util.d.ts +3 -1
- package/dist/node_modules/simple-git/{typings → dist/typings}/errors.d.ts +0 -1
- package/dist/node_modules/simple-git/{typings → dist/typings}/index.d.ts +2 -1
- package/dist/node_modules/simple-git/{typings → dist/typings}/response.d.ts +68 -25
- package/dist/node_modules/simple-git/{typings → dist/typings}/simple-git.d.ts +493 -110
- package/dist/node_modules/simple-git/dist/typings/types.d.ts +23 -0
- package/dist/node_modules/simple-git/package.json +32 -35
- package/dist/node_modules/simple-git/promise.js +14 -4
- package/dist/node_modules/simple-git/readme.md +372 -389
- package/dist/node_modules/undici-types/README.md +6 -0
- package/dist/node_modules/undici-types/agent.d.ts +31 -0
- package/dist/node_modules/undici-types/api.d.ts +43 -0
- package/dist/node_modules/undici-types/balanced-pool.d.ts +18 -0
- package/dist/node_modules/undici-types/cache.d.ts +36 -0
- package/dist/node_modules/undici-types/client.d.ts +97 -0
- package/dist/node_modules/undici-types/connector.d.ts +34 -0
- package/dist/node_modules/undici-types/content-type.d.ts +21 -0
- package/dist/node_modules/undici-types/cookies.d.ts +28 -0
- package/dist/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
- package/dist/node_modules/undici-types/dispatcher.d.ts +241 -0
- package/dist/node_modules/undici-types/errors.d.ts +128 -0
- package/dist/node_modules/undici-types/fetch.d.ts +209 -0
- package/dist/node_modules/undici-types/file.d.ts +39 -0
- package/dist/node_modules/undici-types/filereader.d.ts +54 -0
- package/dist/node_modules/undici-types/formdata.d.ts +108 -0
- package/dist/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/dist/node_modules/undici-types/global-origin.d.ts +7 -0
- package/dist/node_modules/undici-types/handlers.d.ts +9 -0
- package/dist/node_modules/undici-types/header.d.ts +4 -0
- package/dist/node_modules/undici-types/index.d.ts +63 -0
- package/dist/node_modules/undici-types/interceptors.d.ts +5 -0
- package/dist/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/dist/node_modules/undici-types/mock-client.d.ts +25 -0
- package/dist/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/dist/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/dist/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/dist/node_modules/undici-types/package.json +55 -0
- package/dist/node_modules/undici-types/patch.d.ts +71 -0
- package/dist/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/dist/node_modules/undici-types/pool.d.ts +28 -0
- package/dist/node_modules/undici-types/proxy-agent.d.ts +30 -0
- package/dist/node_modules/undici-types/readable.d.ts +61 -0
- package/dist/node_modules/undici-types/webidl.d.ts +220 -0
- package/dist/node_modules/undici-types/websocket.d.ts +131 -0
- package/dist/package-lock.json +10146 -0
- package/dist/package.json +23 -23
- package/dist/schemas/variant.json +5 -21
- package/package.json +24 -24
- package/dist/node_modules/@types/node/ts4.8/assert.d.ts +0 -130
- package/dist/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -237
- package/dist/node_modules/@types/node/ts4.8/buffer.d.ts +0 -89
- package/dist/node_modules/@types/node/ts4.8/child_process.d.ts +0 -682
- package/dist/node_modules/@types/node/ts4.8/cluster.d.ts +0 -300
- package/dist/node_modules/@types/node/ts4.8/console.d.ts +0 -142
- package/dist/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/dist/node_modules/@types/node/ts4.8/crypto.d.ts +0 -1287
- package/dist/node_modules/@types/node/ts4.8/dgram.d.ts +0 -180
- package/dist/node_modules/@types/node/ts4.8/dns.d.ts +0 -516
- package/dist/node_modules/@types/node/ts4.8/domain.d.ts +0 -27
- package/dist/node_modules/@types/node/ts4.8/events.d.ts +0 -82
- package/dist/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -634
- package/dist/node_modules/@types/node/ts4.8/fs.d.ts +0 -2587
- package/dist/node_modules/@types/node/ts4.8/globals.d.ts +0 -763
- package/dist/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/dist/node_modules/@types/node/ts4.8/http.d.ts +0 -580
- package/dist/node_modules/@types/node/ts4.8/http2.d.ts +0 -1208
- package/dist/node_modules/@types/node/ts4.8/https.d.ts +0 -274
- package/dist/node_modules/@types/node/ts4.8/index.d.ts +0 -53
- package/dist/node_modules/@types/node/ts4.8/inspector.d.ts +0 -3050
- package/dist/node_modules/@types/node/ts4.8/module.d.ts +0 -56
- package/dist/node_modules/@types/node/ts4.8/net.d.ts +0 -324
- package/dist/node_modules/@types/node/ts4.8/os.d.ts +0 -243
- package/dist/node_modules/@types/node/ts4.8/path.d.ts +0 -168
- package/dist/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -274
- package/dist/node_modules/@types/node/ts4.8/process.d.ts +0 -452
- package/dist/node_modules/@types/node/ts4.8/punycode.d.ts +0 -78
- package/dist/node_modules/@types/node/ts4.8/querystring.d.ts +0 -41
- package/dist/node_modules/@types/node/ts4.8/readline.d.ts +0 -184
- package/dist/node_modules/@types/node/ts4.8/repl.d.ts +0 -404
- package/dist/node_modules/@types/node/ts4.8/stream.d.ts +0 -518
- package/dist/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -10
- package/dist/node_modules/@types/node/ts4.8/timers.d.ts +0 -19
- package/dist/node_modules/@types/node/ts4.8/tls.d.ts +0 -866
- package/dist/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -64
- package/dist/node_modules/@types/node/ts4.8/tty.d.ts +0 -69
- package/dist/node_modules/@types/node/ts4.8/url.d.ts +0 -187
- package/dist/node_modules/@types/node/ts4.8/util.d.ts +0 -278
- package/dist/node_modules/@types/node/ts4.8/v8.d.ts +0 -189
- package/dist/node_modules/@types/node/ts4.8/vm.d.ts +0 -155
- package/dist/node_modules/@types/node/ts4.8/wasi.d.ts +0 -88
- package/dist/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -241
- package/dist/node_modules/@types/node/ts4.8/zlib.d.ts +0 -364
- package/dist/node_modules/fs-extra/lib/remove/rimraf.js +0 -302
- package/dist/node_modules/simple-git/CHANGELOG.md +0 -529
- package/dist/node_modules/simple-git/LICENSE +0 -20
- package/dist/node_modules/simple-git/promise.d.ts +0 -46
- package/dist/node_modules/simple-git/src/git.js +0 -700
- package/dist/node_modules/simple-git/src/index.js +0 -7
- package/dist/node_modules/simple-git/src/lib/api.js +0 -26
- package/dist/node_modules/simple-git/src/lib/api.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-construct-error.js +0 -21
- package/dist/node_modules/simple-git/src/lib/errors/git-construct-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-error.js +0 -37
- package/dist/node_modules/simple-git/src/lib/errors/git-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-plugin-error.d.ts +0 -6
- package/dist/node_modules/simple-git/src/lib/errors/git-plugin-error.js +0 -14
- package/dist/node_modules/simple-git/src/lib/errors/git-plugin-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-response-error.js +0 -36
- package/dist/node_modules/simple-git/src/lib/errors/git-response-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/task-configuration-error.js +0 -19
- package/dist/node_modules/simple-git/src/lib/errors/task-configuration-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/git-factory.d.ts +0 -25
- package/dist/node_modules/simple-git/src/lib/git-factory.js +0 -45
- package/dist/node_modules/simple-git/src/lib/git-factory.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/git-logger.js +0 -101
- package/dist/node_modules/simple-git/src/lib/git-logger.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch-delete.js +0 -29
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch-delete.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch.js +0 -18
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-commit.js +0 -53
- package/dist/node_modules/simple-git/src/lib/parsers/parse-commit.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-diff-summary.d.ts +0 -2
- package/dist/node_modules/simple-git/src/lib/parsers/parse-diff-summary.js +0 -74
- package/dist/node_modules/simple-git/src/lib/parsers/parse-diff-summary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-fetch.js +0 -32
- package/dist/node_modules/simple-git/src/lib/parsers/parse-fetch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-list-log-summary.js +0 -35
- package/dist/node_modules/simple-git/src/lib/parsers/parse-list-log-summary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-merge.js +0 -39
- package/dist/node_modules/simple-git/src/lib/parsers/parse-merge.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-move.js +0 -14
- package/dist/node_modules/simple-git/src/lib/parsers/parse-move.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-pull.js +0 -42
- package/dist/node_modules/simple-git/src/lib/parsers/parse-pull.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-push.js +0 -58
- package/dist/node_modules/simple-git/src/lib/parsers/parse-push.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-messages.js +0 -33
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-messages.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-objects.js +0 -41
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-objects.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/command-config-prefixing-plugin.js +0 -15
- package/dist/node_modules/simple-git/src/lib/plugins/command-config-prefixing-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/completion-detection.plugin.js +0 -80
- package/dist/node_modules/simple-git/src/lib/plugins/completion-detection.plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/error-detection.plugin.js +0 -39
- package/dist/node_modules/simple-git/src/lib/plugins/error-detection.plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/index.js +0 -21
- package/dist/node_modules/simple-git/src/lib/plugins/index.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/plugin-store.d.ts +0 -6
- package/dist/node_modules/simple-git/src/lib/plugins/plugin-store.js +0 -28
- package/dist/node_modules/simple-git/src/lib/plugins/plugin-store.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/progress-monitor-plugin.js +0 -45
- package/dist/node_modules/simple-git/src/lib/plugins/progress-monitor-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/simple-git-plugin.js +0 -3
- package/dist/node_modules/simple-git/src/lib/plugins/simple-git-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/spawn-options-plugin.js +0 -15
- package/dist/node_modules/simple-git/src/lib/plugins/spawn-options-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/timout-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/plugins/timout-plugin.js +0 -37
- package/dist/node_modules/simple-git/src/lib/plugins/timout-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/BranchDeleteSummary.js +0 -31
- package/dist/node_modules/simple-git/src/lib/responses/BranchDeleteSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/BranchSummary.d.ts +0 -10
- package/dist/node_modules/simple-git/src/lib/responses/BranchSummary.js +0 -26
- package/dist/node_modules/simple-git/src/lib/responses/BranchSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/CheckIgnore.js +0 -13
- package/dist/node_modules/simple-git/src/lib/responses/CheckIgnore.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/CleanSummary.js +0 -28
- package/dist/node_modules/simple-git/src/lib/responses/CleanSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/ConfigList.js +0 -89
- package/dist/node_modules/simple-git/src/lib/responses/ConfigList.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/DiffSummary.js +0 -16
- package/dist/node_modules/simple-git/src/lib/responses/DiffSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/FileStatusSummary.js +0 -18
- package/dist/node_modules/simple-git/src/lib/responses/FileStatusSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/GetRemoteSummary.js +0 -30
- package/dist/node_modules/simple-git/src/lib/responses/GetRemoteSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/InitSummary.js +0 -36
- package/dist/node_modules/simple-git/src/lib/responses/InitSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/MergeSummary.js +0 -35
- package/dist/node_modules/simple-git/src/lib/responses/MergeSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/PullSummary.d.ts +0 -12
- package/dist/node_modules/simple-git/src/lib/responses/PullSummary.js +0 -22
- package/dist/node_modules/simple-git/src/lib/responses/PullSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/StatusSummary.js +0 -128
- package/dist/node_modules/simple-git/src/lib/responses/StatusSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/TagList.js +0 -56
- package/dist/node_modules/simple-git/src/lib/responses/TagList.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/git-executor-chain.js +0 -173
- package/dist/node_modules/simple-git/src/lib/runners/git-executor-chain.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/git-executor.js +0 -21
- package/dist/node_modules/simple-git/src/lib/runners/git-executor.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/promise-wrapped.js +0 -133
- package/dist/node_modules/simple-git/src/lib/runners/promise-wrapped.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/scheduler.js +0 -48
- package/dist/node_modules/simple-git/src/lib/runners/scheduler.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/tasks-pending-queue.js +0 -64
- package/dist/node_modules/simple-git/src/lib/runners/tasks-pending-queue.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/simple-git-api.js +0 -80
- package/dist/node_modules/simple-git/src/lib/simple-git-api.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/task-callback.js +0 -39
- package/dist/node_modules/simple-git/src/lib/task-callback.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/apply-patch.js +0 -9
- package/dist/node_modules/simple-git/src/lib/tasks/apply-patch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/branch.js +0 -76
- package/dist/node_modules/simple-git/src/lib/tasks/branch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/change-working-directory.js +0 -15
- package/dist/node_modules/simple-git/src/lib/tasks/change-working-directory.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/check-ignore.js +0 -13
- package/dist/node_modules/simple-git/src/lib/tasks/check-ignore.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/check-is-repo.js +0 -61
- package/dist/node_modules/simple-git/src/lib/tasks/check-is-repo.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/clean.js +0 -85
- package/dist/node_modules/simple-git/src/lib/tasks/clean.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/clone.js +0 -22
- package/dist/node_modules/simple-git/src/lib/tasks/clone.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/commit.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/tasks/commit.js +0 -16
- package/dist/node_modules/simple-git/src/lib/tasks/commit.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/config.js +0 -73
- package/dist/node_modules/simple-git/src/lib/tasks/config.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/diff.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/tasks/diff.js +0 -15
- package/dist/node_modules/simple-git/src/lib/tasks/diff.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/fetch.js +0 -17
- package/dist/node_modules/simple-git/src/lib/tasks/fetch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/grep.js +0 -76
- package/dist/node_modules/simple-git/src/lib/tasks/grep.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/hash-object.js +0 -16
- package/dist/node_modules/simple-git/src/lib/tasks/hash-object.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/init.js +0 -23
- package/dist/node_modules/simple-git/src/lib/tasks/init.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/log.js +0 -109
- package/dist/node_modules/simple-git/src/lib/tasks/log.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/merge.js +0 -24
- package/dist/node_modules/simple-git/src/lib/tasks/merge.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/move.js +0 -14
- package/dist/node_modules/simple-git/src/lib/tasks/move.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/pull.js +0 -19
- package/dist/node_modules/simple-git/src/lib/tasks/pull.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/push.js +0 -29
- package/dist/node_modules/simple-git/src/lib/tasks/push.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/remote.js +0 -42
- package/dist/node_modules/simple-git/src/lib/tasks/remote.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/reset.js +0 -38
- package/dist/node_modules/simple-git/src/lib/tasks/reset.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/stash-list.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/tasks/stash-list.js +0 -16
- package/dist/node_modules/simple-git/src/lib/tasks/stash-list.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/status.js +0 -15
- package/dist/node_modules/simple-git/src/lib/tasks/status.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/sub-module.js +0 -25
- package/dist/node_modules/simple-git/src/lib/tasks/sub-module.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/tag.js +0 -45
- package/dist/node_modules/simple-git/src/lib/tasks/tag.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/task.js +0 -52
- package/dist/node_modules/simple-git/src/lib/tasks/task.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/types/handlers.js +0 -3
- package/dist/node_modules/simple-git/src/lib/types/handlers.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/types/index.js +0 -15
- package/dist/node_modules/simple-git/src/lib/types/index.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/types/tasks.js +0 -3
- package/dist/node_modules/simple-git/src/lib/types/tasks.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/argument-filters.js +0 -47
- package/dist/node_modules/simple-git/src/lib/utils/argument-filters.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/exit-codes.js +0 -14
- package/dist/node_modules/simple-git/src/lib/utils/exit-codes.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/git-output-streams.js +0 -14
- package/dist/node_modules/simple-git/src/lib/utils/git-output-streams.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/index.js +0 -21
- package/dist/node_modules/simple-git/src/lib/utils/index.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/line-parser.js +0 -52
- package/dist/node_modules/simple-git/src/lib/utils/line-parser.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/simple-git-options.js +0 -16
- package/dist/node_modules/simple-git/src/lib/utils/simple-git-options.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/task-options.js +0 -58
- package/dist/node_modules/simple-git/src/lib/utils/task-options.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/task-parser.js +0 -24
- package/dist/node_modules/simple-git/src/lib/utils/task-parser.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/util.js +0 -146
- package/dist/node_modules/simple-git/src/lib/utils/util.js.map +0 -1
- package/dist/node_modules/simple-git/typings/types.d.ts +0 -14
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/git-construct-error.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/git-response-error.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/task-configuration-error.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/git-logger.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-branch-delete.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-commit.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-fetch.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-merge.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-move.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-push.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-remote-messages.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-remote-objects.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/command-config-prefixing-plugin.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/error-detection.plugin.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/spawn-options-plugin.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/BranchDeleteSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/CheckIgnore.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/CleanSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/ConfigList.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/DiffSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/GetRemoteSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/InitSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/MergeSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/TagList.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/promise-wrapped.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/scheduler.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/tasks-pending-queue.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/simple-git-api.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/task-callback.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/apply-patch.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/branch.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/change-working-directory.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/check-ignore.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/check-is-repo.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/clean.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/grep.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/hash-object.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/init.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/merge.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/move.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/pull.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/push.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/reset.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/status.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/sub-module.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/tag.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/types/handlers.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/types/tasks.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/argument-filters.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/git-output-streams.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/index.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/simple-git-options.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/task-options.d.ts +0 -0
|
@@ -1,14 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `node:crypto` module provides cryptographic functionality that includes a
|
|
3
|
+
* set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify
|
|
4
|
+
* functions.
|
|
5
|
+
*
|
|
6
|
+
* ```js
|
|
7
|
+
* const { createHmac } = await import('node:crypto');
|
|
8
|
+
*
|
|
9
|
+
* const secret = 'abcdefg';
|
|
10
|
+
* const hash = createHmac('sha256', secret)
|
|
11
|
+
* .update('I love cupcakes')
|
|
12
|
+
* .digest('hex');
|
|
13
|
+
* console.log(hash);
|
|
14
|
+
* // Prints:
|
|
15
|
+
* // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
|
|
16
|
+
* ```
|
|
17
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/crypto.js)
|
|
18
|
+
*/
|
|
1
19
|
declare module "crypto" {
|
|
2
|
-
import * as stream from "stream";
|
|
3
|
-
|
|
4
|
-
|
|
20
|
+
import * as stream from "node:stream";
|
|
21
|
+
import { PeerCertificate } from "node:tls";
|
|
22
|
+
/**
|
|
23
|
+
* SPKAC is a Certificate Signing Request mechanism originally implemented by
|
|
24
|
+
* Netscape and was specified formally as part of HTML5's `keygen` element.
|
|
25
|
+
*
|
|
26
|
+
* `<keygen>` is deprecated since [HTML 5.2](https://www.w3.org/TR/html52/changes.html#features-removed) and new projects
|
|
27
|
+
* should not use this element anymore.
|
|
28
|
+
*
|
|
29
|
+
* The `node:crypto` module provides the `Certificate` class for working with SPKAC
|
|
30
|
+
* data. The most common usage is handling output generated by the HTML5 `<keygen>` element. Node.js uses [OpenSSL's SPKAC
|
|
31
|
+
* implementation](https://www.openssl.org/docs/man3.0/man1/openssl-spkac.html) internally.
|
|
32
|
+
* @since v0.11.8
|
|
33
|
+
*/
|
|
34
|
+
class Certificate {
|
|
35
|
+
/**
|
|
36
|
+
* ```js
|
|
37
|
+
* const { Certificate } = await import('node:crypto');
|
|
38
|
+
* const spkac = getSpkacSomehow();
|
|
39
|
+
* const challenge = Certificate.exportChallenge(spkac);
|
|
40
|
+
* console.log(challenge.toString('utf8'));
|
|
41
|
+
* // Prints: the challenge as a UTF8 string
|
|
42
|
+
* ```
|
|
43
|
+
* @since v9.0.0
|
|
44
|
+
* @param encoding The `encoding` of the `spkac` string.
|
|
45
|
+
* @return The challenge component of the `spkac` data structure, which includes a public key and a challenge.
|
|
46
|
+
*/
|
|
47
|
+
static exportChallenge(spkac: BinaryLike): Buffer;
|
|
48
|
+
/**
|
|
49
|
+
* ```js
|
|
50
|
+
* const { Certificate } = await import('node:crypto');
|
|
51
|
+
* const spkac = getSpkacSomehow();
|
|
52
|
+
* const publicKey = Certificate.exportPublicKey(spkac);
|
|
53
|
+
* console.log(publicKey);
|
|
54
|
+
* // Prints: the public key as <Buffer ...>
|
|
55
|
+
* ```
|
|
56
|
+
* @since v9.0.0
|
|
57
|
+
* @param encoding The `encoding` of the `spkac` string.
|
|
58
|
+
* @return The public key component of the `spkac` data structure, which includes a public key and a challenge.
|
|
59
|
+
*/
|
|
60
|
+
static exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer;
|
|
61
|
+
/**
|
|
62
|
+
* ```js
|
|
63
|
+
* import { Buffer } from 'node:buffer';
|
|
64
|
+
* const { Certificate } = await import('node:crypto');
|
|
65
|
+
*
|
|
66
|
+
* const spkac = getSpkacSomehow();
|
|
67
|
+
* console.log(Certificate.verifySpkac(Buffer.from(spkac)));
|
|
68
|
+
* // Prints: true or false
|
|
69
|
+
* ```
|
|
70
|
+
* @since v9.0.0
|
|
71
|
+
* @param encoding The `encoding` of the `spkac` string.
|
|
72
|
+
* @return `true` if the given `spkac` data structure is valid, `false` otherwise.
|
|
73
|
+
*/
|
|
74
|
+
static verifySpkac(spkac: NodeJS.ArrayBufferView): boolean;
|
|
5
75
|
/**
|
|
76
|
+
* @deprecated
|
|
6
77
|
* @param spkac
|
|
7
78
|
* @returns The challenge component of the `spkac` data structure,
|
|
8
79
|
* which includes a public key and a challenge.
|
|
9
80
|
*/
|
|
10
81
|
exportChallenge(spkac: BinaryLike): Buffer;
|
|
11
82
|
/**
|
|
83
|
+
* @deprecated
|
|
12
84
|
* @param spkac
|
|
13
85
|
* @param encoding The encoding of the spkac string.
|
|
14
86
|
* @returns The public key component of the `spkac` data structure,
|
|
@@ -16,30 +88,25 @@ declare module "crypto" {
|
|
|
16
88
|
*/
|
|
17
89
|
exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer;
|
|
18
90
|
/**
|
|
91
|
+
* @deprecated
|
|
19
92
|
* @param spkac
|
|
20
93
|
* @returns `true` if the given `spkac` data structure is valid,
|
|
21
94
|
* `false` otherwise.
|
|
22
95
|
*/
|
|
23
96
|
verifySpkac(spkac: NodeJS.ArrayBufferView): boolean;
|
|
24
97
|
}
|
|
25
|
-
const Certificate: Certificate & {
|
|
26
|
-
/** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
|
|
27
|
-
new(): Certificate;
|
|
28
|
-
/** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
|
|
29
|
-
(): Certificate;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
98
|
namespace constants {
|
|
33
|
-
// https://nodejs.org/dist/latest-
|
|
99
|
+
// https://nodejs.org/dist/latest-v20.x/docs/api/crypto.html#crypto-constants
|
|
34
100
|
const OPENSSL_VERSION_NUMBER: number;
|
|
35
|
-
|
|
36
101
|
/** Applies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html for detail. */
|
|
37
102
|
const SSL_OP_ALL: number;
|
|
103
|
+
/** Instructs OpenSSL to allow a non-[EC]DHE-based key exchange mode for TLS v1.3 */
|
|
104
|
+
const SSL_OP_ALLOW_NO_DHE_KEX: number;
|
|
38
105
|
/** Allows legacy insecure renegotiation between OpenSSL and unpatched clients or servers. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
|
|
39
106
|
const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number;
|
|
40
107
|
/** Attempts to use the server's preferences instead of the client's when selecting a cipher. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
|
|
41
108
|
const SSL_OP_CIPHER_SERVER_PREFERENCE: number;
|
|
42
|
-
/** Instructs OpenSSL to use Cisco's
|
|
109
|
+
/** Instructs OpenSSL to use Cisco's version identifier of DTLS_BAD_VER. */
|
|
43
110
|
const SSL_OP_CISCO_ANYCONNECT: number;
|
|
44
111
|
/** Instructs OpenSSL to turn on cookie exchange. */
|
|
45
112
|
const SSL_OP_COOKIE_EXCHANGE: number;
|
|
@@ -47,42 +114,35 @@ declare module "crypto" {
|
|
|
47
114
|
const SSL_OP_CRYPTOPRO_TLSEXT_BUG: number;
|
|
48
115
|
/** Instructs OpenSSL to disable a SSL 3.0/TLS 1.0 vulnerability workaround added in OpenSSL 0.9.6d. */
|
|
49
116
|
const SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number;
|
|
50
|
-
/** Instructs OpenSSL to always use the tmp_rsa key when performing RSA operations. */
|
|
51
|
-
const SSL_OP_EPHEMERAL_RSA: number;
|
|
52
117
|
/** Allows initial connection to servers that do not support RI. */
|
|
53
118
|
const SSL_OP_LEGACY_SERVER_CONNECT: number;
|
|
54
|
-
const SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number;
|
|
55
|
-
const SSL_OP_MICROSOFT_SESS_ID_BUG: number;
|
|
56
|
-
/** Instructs OpenSSL to disable the workaround for a man-in-the-middle protocol-version vulnerability in the SSL 2.0 server implementation. */
|
|
57
|
-
const SSL_OP_MSIE_SSLV2_RSA_PADDING: number;
|
|
58
|
-
const SSL_OP_NETSCAPE_CA_DN_BUG: number;
|
|
59
|
-
const SSL_OP_NETSCAPE_CHALLENGE_BUG: number;
|
|
60
|
-
const SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number;
|
|
61
|
-
const SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number;
|
|
62
119
|
/** Instructs OpenSSL to disable support for SSL/TLS compression. */
|
|
63
120
|
const SSL_OP_NO_COMPRESSION: number;
|
|
121
|
+
/** Instructs OpenSSL to disable encrypt-then-MAC. */
|
|
122
|
+
const SSL_OP_NO_ENCRYPT_THEN_MAC: number;
|
|
64
123
|
const SSL_OP_NO_QUERY_MTU: number;
|
|
124
|
+
/** Instructs OpenSSL to disable renegotiation. */
|
|
125
|
+
const SSL_OP_NO_RENEGOTIATION: number;
|
|
65
126
|
/** Instructs OpenSSL to always start a new session when performing renegotiation. */
|
|
66
127
|
const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number;
|
|
128
|
+
/** Instructs OpenSSL to turn off SSL v2 */
|
|
67
129
|
const SSL_OP_NO_SSLv2: number;
|
|
130
|
+
/** Instructs OpenSSL to turn off SSL v3 */
|
|
68
131
|
const SSL_OP_NO_SSLv3: number;
|
|
132
|
+
/** Instructs OpenSSL to disable use of RFC4507bis tickets. */
|
|
69
133
|
const SSL_OP_NO_TICKET: number;
|
|
134
|
+
/** Instructs OpenSSL to turn off TLS v1 */
|
|
70
135
|
const SSL_OP_NO_TLSv1: number;
|
|
136
|
+
/** Instructs OpenSSL to turn off TLS v1.1 */
|
|
71
137
|
const SSL_OP_NO_TLSv1_1: number;
|
|
138
|
+
/** Instructs OpenSSL to turn off TLS v1.2 */
|
|
72
139
|
const SSL_OP_NO_TLSv1_2: number;
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
/** Instructs OpenSSL to
|
|
76
|
-
const
|
|
77
|
-
/** Instructs OpenSSL to always create a new key when using temporary/ephemeral ECDH parameters. */
|
|
78
|
-
const SSL_OP_SINGLE_ECDH_USE: number;
|
|
79
|
-
const SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number;
|
|
80
|
-
const SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number;
|
|
81
|
-
const SSL_OP_TLS_BLOCK_PADDING_BUG: number;
|
|
82
|
-
const SSL_OP_TLS_D5_BUG: number;
|
|
140
|
+
/** Instructs OpenSSL to turn off TLS v1.3 */
|
|
141
|
+
const SSL_OP_NO_TLSv1_3: number;
|
|
142
|
+
/** Instructs OpenSSL server to prioritize ChaCha20-Poly1305 when the client does. This option has no effect if `SSL_OP_CIPHER_SERVER_PREFERENCE` is not enabled. */
|
|
143
|
+
const SSL_OP_PRIORITIZE_CHACHA: number;
|
|
83
144
|
/** Instructs OpenSSL to disable version rollback attack detection. */
|
|
84
145
|
const SSL_OP_TLS_ROLLBACK_BUG: number;
|
|
85
|
-
|
|
86
146
|
const ENGINE_METHOD_RSA: number;
|
|
87
147
|
const ENGINE_METHOD_DSA: number;
|
|
88
148
|
const ENGINE_METHOD_DH: number;
|
|
@@ -94,14 +154,10 @@ declare module "crypto" {
|
|
|
94
154
|
const ENGINE_METHOD_PKEY_ASN1_METHS: number;
|
|
95
155
|
const ENGINE_METHOD_ALL: number;
|
|
96
156
|
const ENGINE_METHOD_NONE: number;
|
|
97
|
-
|
|
98
157
|
const DH_CHECK_P_NOT_SAFE_PRIME: number;
|
|
99
158
|
const DH_CHECK_P_NOT_PRIME: number;
|
|
100
159
|
const DH_UNABLE_TO_CHECK_GENERATOR: number;
|
|
101
160
|
const DH_NOT_SUITABLE_GENERATOR: number;
|
|
102
|
-
|
|
103
|
-
const ALPN_ENABLED: number;
|
|
104
|
-
|
|
105
161
|
const RSA_PKCS1_PADDING: number;
|
|
106
162
|
const RSA_SSLV23_PADDING: number;
|
|
107
163
|
const RSA_NO_PADDING: number;
|
|
@@ -114,17 +170,14 @@ declare module "crypto" {
|
|
|
114
170
|
const RSA_PSS_SALTLEN_MAX_SIGN: number;
|
|
115
171
|
/** Causes the salt length for RSA_PKCS1_PSS_PADDING to be determined automatically when verifying a signature. */
|
|
116
172
|
const RSA_PSS_SALTLEN_AUTO: number;
|
|
117
|
-
|
|
118
173
|
const POINT_CONVERSION_COMPRESSED: number;
|
|
119
174
|
const POINT_CONVERSION_UNCOMPRESSED: number;
|
|
120
175
|
const POINT_CONVERSION_HYBRID: number;
|
|
121
|
-
|
|
122
176
|
/** Specifies the built-in default cipher list used by Node.js (colon-separated values). */
|
|
123
177
|
const defaultCoreCipherList: string;
|
|
124
178
|
/** Specifies the active default cipher list used by the current Node.js process (colon-separated values). */
|
|
125
179
|
const defaultCipherList: string;
|
|
126
180
|
}
|
|
127
|
-
|
|
128
181
|
interface HashOptions extends stream.TransformOptions {
|
|
129
182
|
/**
|
|
130
183
|
* For XOF hash functions such as `shake256`, the
|
|
@@ -132,69 +185,500 @@ declare module "crypto" {
|
|
|
132
185
|
*/
|
|
133
186
|
outputLength?: number | undefined;
|
|
134
187
|
}
|
|
135
|
-
|
|
136
188
|
/** @deprecated since v10.0.0 */
|
|
137
189
|
const fips: boolean;
|
|
138
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Creates and returns a `Hash` object that can be used to generate hash digests
|
|
192
|
+
* using the given `algorithm`. Optional `options` argument controls stream
|
|
193
|
+
* behavior. For XOF hash functions such as `'shake256'`, the `outputLength` option
|
|
194
|
+
* can be used to specify the desired output length in bytes.
|
|
195
|
+
*
|
|
196
|
+
* The `algorithm` is dependent on the available algorithms supported by the
|
|
197
|
+
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
|
|
198
|
+
* On recent releases of OpenSSL, `openssl list -digest-algorithms` will
|
|
199
|
+
* display the available digest algorithms.
|
|
200
|
+
*
|
|
201
|
+
* Example: generating the sha256 sum of a file
|
|
202
|
+
*
|
|
203
|
+
* ```js
|
|
204
|
+
* import {
|
|
205
|
+
* createReadStream,
|
|
206
|
+
* } from 'node:fs';
|
|
207
|
+
* import { argv } from 'node:process';
|
|
208
|
+
* const {
|
|
209
|
+
* createHash,
|
|
210
|
+
* } = await import('node:crypto');
|
|
211
|
+
*
|
|
212
|
+
* const filename = argv[2];
|
|
213
|
+
*
|
|
214
|
+
* const hash = createHash('sha256');
|
|
215
|
+
*
|
|
216
|
+
* const input = createReadStream(filename);
|
|
217
|
+
* input.on('readable', () => {
|
|
218
|
+
* // Only one element is going to be produced by the
|
|
219
|
+
* // hash stream.
|
|
220
|
+
* const data = input.read();
|
|
221
|
+
* if (data)
|
|
222
|
+
* hash.update(data);
|
|
223
|
+
* else {
|
|
224
|
+
* console.log(`${hash.digest('hex')} ${filename}`);
|
|
225
|
+
* }
|
|
226
|
+
* });
|
|
227
|
+
* ```
|
|
228
|
+
* @since v0.1.92
|
|
229
|
+
* @param options `stream.transform` options
|
|
230
|
+
*/
|
|
139
231
|
function createHash(algorithm: string, options?: HashOptions): Hash;
|
|
232
|
+
/**
|
|
233
|
+
* Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
|
|
234
|
+
* Optional `options` argument controls stream behavior.
|
|
235
|
+
*
|
|
236
|
+
* The `algorithm` is dependent on the available algorithms supported by the
|
|
237
|
+
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
|
|
238
|
+
* On recent releases of OpenSSL, `openssl list -digest-algorithms` will
|
|
239
|
+
* display the available digest algorithms.
|
|
240
|
+
*
|
|
241
|
+
* The `key` is the HMAC key used to generate the cryptographic HMAC hash. If it is
|
|
242
|
+
* a `KeyObject`, its type must be `secret`. If it is a string, please consider `caveats when using strings as inputs to cryptographic APIs`. If it was
|
|
243
|
+
* obtained from a cryptographically secure source of entropy, such as {@link randomBytes} or {@link generateKey}, its length should not
|
|
244
|
+
* exceed the block size of `algorithm` (e.g., 512 bits for SHA-256).
|
|
245
|
+
*
|
|
246
|
+
* Example: generating the sha256 HMAC of a file
|
|
247
|
+
*
|
|
248
|
+
* ```js
|
|
249
|
+
* import {
|
|
250
|
+
* createReadStream,
|
|
251
|
+
* } from 'node:fs';
|
|
252
|
+
* import { argv } from 'node:process';
|
|
253
|
+
* const {
|
|
254
|
+
* createHmac,
|
|
255
|
+
* } = await import('node:crypto');
|
|
256
|
+
*
|
|
257
|
+
* const filename = argv[2];
|
|
258
|
+
*
|
|
259
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
260
|
+
*
|
|
261
|
+
* const input = createReadStream(filename);
|
|
262
|
+
* input.on('readable', () => {
|
|
263
|
+
* // Only one element is going to be produced by the
|
|
264
|
+
* // hash stream.
|
|
265
|
+
* const data = input.read();
|
|
266
|
+
* if (data)
|
|
267
|
+
* hmac.update(data);
|
|
268
|
+
* else {
|
|
269
|
+
* console.log(`${hmac.digest('hex')} ${filename}`);
|
|
270
|
+
* }
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
* @since v0.1.94
|
|
274
|
+
* @param options `stream.transform` options
|
|
275
|
+
*/
|
|
140
276
|
function createHmac(algorithm: string, key: BinaryLike | KeyObject, options?: stream.TransformOptions): Hmac;
|
|
141
|
-
|
|
142
277
|
// https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
|
|
143
|
-
type BinaryToTextEncoding = "base64" | "base64url" | "hex";
|
|
144
|
-
type CharacterEncoding = "utf8" | "utf-8" | "utf16le" | "latin1";
|
|
278
|
+
type BinaryToTextEncoding = "base64" | "base64url" | "hex" | "binary";
|
|
279
|
+
type CharacterEncoding = "utf8" | "utf-8" | "utf16le" | "utf-16le" | "latin1";
|
|
145
280
|
type LegacyCharacterEncoding = "ascii" | "binary" | "ucs2" | "ucs-2";
|
|
146
|
-
|
|
147
281
|
type Encoding = BinaryToTextEncoding | CharacterEncoding | LegacyCharacterEncoding;
|
|
148
|
-
|
|
149
282
|
type ECDHKeyFormat = "compressed" | "uncompressed" | "hybrid";
|
|
150
|
-
|
|
283
|
+
/**
|
|
284
|
+
* The `Hash` class is a utility for creating hash digests of data. It can be
|
|
285
|
+
* used in one of two ways:
|
|
286
|
+
*
|
|
287
|
+
* * As a `stream` that is both readable and writable, where data is written
|
|
288
|
+
* to produce a computed hash digest on the readable side, or
|
|
289
|
+
* * Using the `hash.update()` and `hash.digest()` methods to produce the
|
|
290
|
+
* computed hash.
|
|
291
|
+
*
|
|
292
|
+
* The {@link createHash} method is used to create `Hash` instances. `Hash`objects are not to be created directly using the `new` keyword.
|
|
293
|
+
*
|
|
294
|
+
* Example: Using `Hash` objects as streams:
|
|
295
|
+
*
|
|
296
|
+
* ```js
|
|
297
|
+
* const {
|
|
298
|
+
* createHash,
|
|
299
|
+
* } = await import('node:crypto');
|
|
300
|
+
*
|
|
301
|
+
* const hash = createHash('sha256');
|
|
302
|
+
*
|
|
303
|
+
* hash.on('readable', () => {
|
|
304
|
+
* // Only one element is going to be produced by the
|
|
305
|
+
* // hash stream.
|
|
306
|
+
* const data = hash.read();
|
|
307
|
+
* if (data) {
|
|
308
|
+
* console.log(data.toString('hex'));
|
|
309
|
+
* // Prints:
|
|
310
|
+
* // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
|
|
311
|
+
* }
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* hash.write('some data to hash');
|
|
315
|
+
* hash.end();
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* Example: Using `Hash` and piped streams:
|
|
319
|
+
*
|
|
320
|
+
* ```js
|
|
321
|
+
* import { createReadStream } from 'node:fs';
|
|
322
|
+
* import { stdout } from 'node:process';
|
|
323
|
+
* const { createHash } = await import('node:crypto');
|
|
324
|
+
*
|
|
325
|
+
* const hash = createHash('sha256');
|
|
326
|
+
*
|
|
327
|
+
* const input = createReadStream('test.js');
|
|
328
|
+
* input.pipe(hash).setEncoding('hex').pipe(stdout);
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* Example: Using the `hash.update()` and `hash.digest()` methods:
|
|
332
|
+
*
|
|
333
|
+
* ```js
|
|
334
|
+
* const {
|
|
335
|
+
* createHash,
|
|
336
|
+
* } = await import('node:crypto');
|
|
337
|
+
*
|
|
338
|
+
* const hash = createHash('sha256');
|
|
339
|
+
*
|
|
340
|
+
* hash.update('some data to hash');
|
|
341
|
+
* console.log(hash.digest('hex'));
|
|
342
|
+
* // Prints:
|
|
343
|
+
* // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
|
|
344
|
+
* ```
|
|
345
|
+
* @since v0.1.92
|
|
346
|
+
*/
|
|
151
347
|
class Hash extends stream.Transform {
|
|
152
348
|
private constructor();
|
|
153
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Creates a new `Hash` object that contains a deep copy of the internal state
|
|
351
|
+
* of the current `Hash` object.
|
|
352
|
+
*
|
|
353
|
+
* The optional `options` argument controls stream behavior. For XOF hash
|
|
354
|
+
* functions such as `'shake256'`, the `outputLength` option can be used to
|
|
355
|
+
* specify the desired output length in bytes.
|
|
356
|
+
*
|
|
357
|
+
* An error is thrown when an attempt is made to copy the `Hash` object after
|
|
358
|
+
* its `hash.digest()` method has been called.
|
|
359
|
+
*
|
|
360
|
+
* ```js
|
|
361
|
+
* // Calculate a rolling hash.
|
|
362
|
+
* const {
|
|
363
|
+
* createHash,
|
|
364
|
+
* } = await import('node:crypto');
|
|
365
|
+
*
|
|
366
|
+
* const hash = createHash('sha256');
|
|
367
|
+
*
|
|
368
|
+
* hash.update('one');
|
|
369
|
+
* console.log(hash.copy().digest('hex'));
|
|
370
|
+
*
|
|
371
|
+
* hash.update('two');
|
|
372
|
+
* console.log(hash.copy().digest('hex'));
|
|
373
|
+
*
|
|
374
|
+
* hash.update('three');
|
|
375
|
+
* console.log(hash.copy().digest('hex'));
|
|
376
|
+
*
|
|
377
|
+
* // Etc.
|
|
378
|
+
* ```
|
|
379
|
+
* @since v13.1.0
|
|
380
|
+
* @param options `stream.transform` options
|
|
381
|
+
*/
|
|
382
|
+
copy(options?: HashOptions): Hash;
|
|
383
|
+
/**
|
|
384
|
+
* Updates the hash content with the given `data`, the encoding of which
|
|
385
|
+
* is given in `inputEncoding`.
|
|
386
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
387
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
388
|
+
*
|
|
389
|
+
* This can be called many times with new data as it is streamed.
|
|
390
|
+
* @since v0.1.92
|
|
391
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
392
|
+
*/
|
|
154
393
|
update(data: BinaryLike): Hash;
|
|
155
|
-
update(data: string,
|
|
394
|
+
update(data: string, inputEncoding: Encoding): Hash;
|
|
395
|
+
/**
|
|
396
|
+
* Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
|
|
397
|
+
* If `encoding` is provided a string will be returned; otherwise
|
|
398
|
+
* a `Buffer` is returned.
|
|
399
|
+
*
|
|
400
|
+
* The `Hash` object can not be used again after `hash.digest()` method has been
|
|
401
|
+
* called. Multiple calls will cause an error to be thrown.
|
|
402
|
+
* @since v0.1.92
|
|
403
|
+
* @param encoding The `encoding` of the return value.
|
|
404
|
+
*/
|
|
156
405
|
digest(): Buffer;
|
|
157
406
|
digest(encoding: BinaryToTextEncoding): string;
|
|
158
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* The `Hmac` class is a utility for creating cryptographic HMAC digests. It can
|
|
410
|
+
* be used in one of two ways:
|
|
411
|
+
*
|
|
412
|
+
* * As a `stream` that is both readable and writable, where data is written
|
|
413
|
+
* to produce a computed HMAC digest on the readable side, or
|
|
414
|
+
* * Using the `hmac.update()` and `hmac.digest()` methods to produce the
|
|
415
|
+
* computed HMAC digest.
|
|
416
|
+
*
|
|
417
|
+
* The {@link createHmac} method is used to create `Hmac` instances. `Hmac`objects are not to be created directly using the `new` keyword.
|
|
418
|
+
*
|
|
419
|
+
* Example: Using `Hmac` objects as streams:
|
|
420
|
+
*
|
|
421
|
+
* ```js
|
|
422
|
+
* const {
|
|
423
|
+
* createHmac,
|
|
424
|
+
* } = await import('node:crypto');
|
|
425
|
+
*
|
|
426
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
427
|
+
*
|
|
428
|
+
* hmac.on('readable', () => {
|
|
429
|
+
* // Only one element is going to be produced by the
|
|
430
|
+
* // hash stream.
|
|
431
|
+
* const data = hmac.read();
|
|
432
|
+
* if (data) {
|
|
433
|
+
* console.log(data.toString('hex'));
|
|
434
|
+
* // Prints:
|
|
435
|
+
* // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
|
|
436
|
+
* }
|
|
437
|
+
* });
|
|
438
|
+
*
|
|
439
|
+
* hmac.write('some data to hash');
|
|
440
|
+
* hmac.end();
|
|
441
|
+
* ```
|
|
442
|
+
*
|
|
443
|
+
* Example: Using `Hmac` and piped streams:
|
|
444
|
+
*
|
|
445
|
+
* ```js
|
|
446
|
+
* import { createReadStream } from 'node:fs';
|
|
447
|
+
* import { stdout } from 'node:process';
|
|
448
|
+
* const {
|
|
449
|
+
* createHmac,
|
|
450
|
+
* } = await import('node:crypto');
|
|
451
|
+
*
|
|
452
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
453
|
+
*
|
|
454
|
+
* const input = createReadStream('test.js');
|
|
455
|
+
* input.pipe(hmac).pipe(stdout);
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* Example: Using the `hmac.update()` and `hmac.digest()` methods:
|
|
459
|
+
*
|
|
460
|
+
* ```js
|
|
461
|
+
* const {
|
|
462
|
+
* createHmac,
|
|
463
|
+
* } = await import('node:crypto');
|
|
464
|
+
*
|
|
465
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
466
|
+
*
|
|
467
|
+
* hmac.update('some data to hash');
|
|
468
|
+
* console.log(hmac.digest('hex'));
|
|
469
|
+
* // Prints:
|
|
470
|
+
* // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
|
|
471
|
+
* ```
|
|
472
|
+
* @since v0.1.94
|
|
473
|
+
* @deprecated Since v20.13.0 Calling `Hmac` class directly with `Hmac()` or `new Hmac()` is deprecated due to being internals, not intended for public use. Please use the {@link createHmac} method to create Hmac instances.
|
|
474
|
+
*/
|
|
159
475
|
class Hmac extends stream.Transform {
|
|
160
476
|
private constructor();
|
|
477
|
+
/**
|
|
478
|
+
* Updates the `Hmac` content with the given `data`, the encoding of which
|
|
479
|
+
* is given in `inputEncoding`.
|
|
480
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
481
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
482
|
+
*
|
|
483
|
+
* This can be called many times with new data as it is streamed.
|
|
484
|
+
* @since v0.1.94
|
|
485
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
486
|
+
*/
|
|
161
487
|
update(data: BinaryLike): Hmac;
|
|
162
|
-
update(data: string,
|
|
488
|
+
update(data: string, inputEncoding: Encoding): Hmac;
|
|
489
|
+
/**
|
|
490
|
+
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
|
|
491
|
+
* If `encoding` is
|
|
492
|
+
* provided a string is returned; otherwise a `Buffer` is returned;
|
|
493
|
+
*
|
|
494
|
+
* The `Hmac` object can not be used again after `hmac.digest()` has been
|
|
495
|
+
* called. Multiple calls to `hmac.digest()` will result in an error being thrown.
|
|
496
|
+
* @since v0.1.94
|
|
497
|
+
* @param encoding The `encoding` of the return value.
|
|
498
|
+
*/
|
|
163
499
|
digest(): Buffer;
|
|
164
500
|
digest(encoding: BinaryToTextEncoding): string;
|
|
165
501
|
}
|
|
166
|
-
|
|
167
502
|
type KeyObjectType = "secret" | "public" | "private";
|
|
168
|
-
|
|
169
503
|
interface KeyExportOptions<T extends KeyFormat> {
|
|
170
504
|
type: "pkcs1" | "spki" | "pkcs8" | "sec1";
|
|
171
505
|
format: T;
|
|
172
506
|
cipher?: string | undefined;
|
|
173
507
|
passphrase?: string | Buffer | undefined;
|
|
174
508
|
}
|
|
175
|
-
|
|
509
|
+
interface JwkKeyExportOptions {
|
|
510
|
+
format: "jwk";
|
|
511
|
+
}
|
|
512
|
+
interface JsonWebKey {
|
|
513
|
+
crv?: string | undefined;
|
|
514
|
+
d?: string | undefined;
|
|
515
|
+
dp?: string | undefined;
|
|
516
|
+
dq?: string | undefined;
|
|
517
|
+
e?: string | undefined;
|
|
518
|
+
k?: string | undefined;
|
|
519
|
+
kty?: string | undefined;
|
|
520
|
+
n?: string | undefined;
|
|
521
|
+
p?: string | undefined;
|
|
522
|
+
q?: string | undefined;
|
|
523
|
+
qi?: string | undefined;
|
|
524
|
+
x?: string | undefined;
|
|
525
|
+
y?: string | undefined;
|
|
526
|
+
[key: string]: unknown;
|
|
527
|
+
}
|
|
528
|
+
interface AsymmetricKeyDetails {
|
|
529
|
+
/**
|
|
530
|
+
* Key size in bits (RSA, DSA).
|
|
531
|
+
*/
|
|
532
|
+
modulusLength?: number | undefined;
|
|
533
|
+
/**
|
|
534
|
+
* Public exponent (RSA).
|
|
535
|
+
*/
|
|
536
|
+
publicExponent?: bigint | undefined;
|
|
537
|
+
/**
|
|
538
|
+
* Name of the message digest (RSA-PSS).
|
|
539
|
+
*/
|
|
540
|
+
hashAlgorithm?: string | undefined;
|
|
541
|
+
/**
|
|
542
|
+
* Name of the message digest used by MGF1 (RSA-PSS).
|
|
543
|
+
*/
|
|
544
|
+
mgf1HashAlgorithm?: string | undefined;
|
|
545
|
+
/**
|
|
546
|
+
* Minimal salt length in bytes (RSA-PSS).
|
|
547
|
+
*/
|
|
548
|
+
saltLength?: number | undefined;
|
|
549
|
+
/**
|
|
550
|
+
* Size of q in bits (DSA).
|
|
551
|
+
*/
|
|
552
|
+
divisorLength?: number | undefined;
|
|
553
|
+
/**
|
|
554
|
+
* Name of the curve (EC).
|
|
555
|
+
*/
|
|
556
|
+
namedCurve?: string | undefined;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Node.js uses a `KeyObject` class to represent a symmetric or asymmetric key,
|
|
560
|
+
* and each kind of key exposes different functions. The {@link createSecretKey}, {@link createPublicKey} and {@link createPrivateKey} methods are used to create `KeyObject`instances. `KeyObject`
|
|
561
|
+
* objects are not to be created directly using the `new`keyword.
|
|
562
|
+
*
|
|
563
|
+
* Most applications should consider using the new `KeyObject` API instead of
|
|
564
|
+
* passing keys as strings or `Buffer`s due to improved security features.
|
|
565
|
+
*
|
|
566
|
+
* `KeyObject` instances can be passed to other threads via `postMessage()`.
|
|
567
|
+
* The receiver obtains a cloned `KeyObject`, and the `KeyObject` does not need to
|
|
568
|
+
* be listed in the `transferList` argument.
|
|
569
|
+
* @since v11.6.0
|
|
570
|
+
*/
|
|
176
571
|
class KeyObject {
|
|
177
572
|
private constructor();
|
|
573
|
+
/**
|
|
574
|
+
* Example: Converting a `CryptoKey` instance to a `KeyObject`:
|
|
575
|
+
*
|
|
576
|
+
* ```js
|
|
577
|
+
* const { KeyObject } = await import('node:crypto');
|
|
578
|
+
* const { subtle } = globalThis.crypto;
|
|
579
|
+
*
|
|
580
|
+
* const key = await subtle.generateKey({
|
|
581
|
+
* name: 'HMAC',
|
|
582
|
+
* hash: 'SHA-256',
|
|
583
|
+
* length: 256,
|
|
584
|
+
* }, true, ['sign', 'verify']);
|
|
585
|
+
*
|
|
586
|
+
* const keyObject = KeyObject.from(key);
|
|
587
|
+
* console.log(keyObject.symmetricKeySize);
|
|
588
|
+
* // Prints: 32 (symmetric key size in bytes)
|
|
589
|
+
* ```
|
|
590
|
+
* @since v15.0.0
|
|
591
|
+
*/
|
|
592
|
+
static from(key: webcrypto.CryptoKey): KeyObject;
|
|
593
|
+
/**
|
|
594
|
+
* For asymmetric keys, this property represents the type of the key. Supported key
|
|
595
|
+
* types are:
|
|
596
|
+
*
|
|
597
|
+
* * `'rsa'` (OID 1.2.840.113549.1.1.1)
|
|
598
|
+
* * `'rsa-pss'` (OID 1.2.840.113549.1.1.10)
|
|
599
|
+
* * `'dsa'` (OID 1.2.840.10040.4.1)
|
|
600
|
+
* * `'ec'` (OID 1.2.840.10045.2.1)
|
|
601
|
+
* * `'x25519'` (OID 1.3.101.110)
|
|
602
|
+
* * `'x448'` (OID 1.3.101.111)
|
|
603
|
+
* * `'ed25519'` (OID 1.3.101.112)
|
|
604
|
+
* * `'ed448'` (OID 1.3.101.113)
|
|
605
|
+
* * `'dh'` (OID 1.2.840.113549.1.3.1)
|
|
606
|
+
*
|
|
607
|
+
* This property is `undefined` for unrecognized `KeyObject` types and symmetric
|
|
608
|
+
* keys.
|
|
609
|
+
* @since v11.6.0
|
|
610
|
+
*/
|
|
178
611
|
asymmetricKeyType?: KeyType | undefined;
|
|
179
612
|
/**
|
|
180
613
|
* For asymmetric keys, this property represents the size of the embedded key in
|
|
181
614
|
* bytes. This property is `undefined` for symmetric keys.
|
|
182
615
|
*/
|
|
183
616
|
asymmetricKeySize?: number | undefined;
|
|
617
|
+
/**
|
|
618
|
+
* This property exists only on asymmetric keys. Depending on the type of the key,
|
|
619
|
+
* this object contains information about the key. None of the information obtained
|
|
620
|
+
* through this property can be used to uniquely identify a key or to compromise
|
|
621
|
+
* the security of the key.
|
|
622
|
+
*
|
|
623
|
+
* For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence,
|
|
624
|
+
* the `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` properties will be
|
|
625
|
+
* set.
|
|
626
|
+
*
|
|
627
|
+
* Other key details might be exposed via this API using additional attributes.
|
|
628
|
+
* @since v15.7.0
|
|
629
|
+
*/
|
|
630
|
+
asymmetricKeyDetails?: AsymmetricKeyDetails | undefined;
|
|
631
|
+
/**
|
|
632
|
+
* For symmetric keys, the following encoding options can be used:
|
|
633
|
+
*
|
|
634
|
+
* For public keys, the following encoding options can be used:
|
|
635
|
+
*
|
|
636
|
+
* For private keys, the following encoding options can be used:
|
|
637
|
+
*
|
|
638
|
+
* The result type depends on the selected encoding format, when PEM the
|
|
639
|
+
* result is a string, when DER it will be a buffer containing the data
|
|
640
|
+
* encoded as DER, when [JWK](https://tools.ietf.org/html/rfc7517) it will be an object.
|
|
641
|
+
*
|
|
642
|
+
* When [JWK](https://tools.ietf.org/html/rfc7517) encoding format was selected, all other encoding options are
|
|
643
|
+
* ignored.
|
|
644
|
+
*
|
|
645
|
+
* PKCS#1, SEC1, and PKCS#8 type keys can be encrypted by using a combination of
|
|
646
|
+
* the `cipher` and `format` options. The PKCS#8 `type` can be used with any`format` to encrypt any key algorithm (RSA, EC, or DH) by specifying a`cipher`. PKCS#1 and SEC1 can only be
|
|
647
|
+
* encrypted by specifying a `cipher`when the PEM `format` is used. For maximum compatibility, use PKCS#8 for
|
|
648
|
+
* encrypted private keys. Since PKCS#8 defines its own
|
|
649
|
+
* encryption mechanism, PEM-level encryption is not supported when encrypting
|
|
650
|
+
* a PKCS#8 key. See [RFC 5208](https://www.rfc-editor.org/rfc/rfc5208.txt) for PKCS#8 encryption and [RFC 1421](https://www.rfc-editor.org/rfc/rfc1421.txt) for
|
|
651
|
+
* PKCS#1 and SEC1 encryption.
|
|
652
|
+
* @since v11.6.0
|
|
653
|
+
*/
|
|
184
654
|
export(options: KeyExportOptions<"pem">): string | Buffer;
|
|
185
655
|
export(options?: KeyExportOptions<"der">): Buffer;
|
|
656
|
+
export(options?: JwkKeyExportOptions): JsonWebKey;
|
|
657
|
+
/**
|
|
658
|
+
* Returns `true` or `false` depending on whether the keys have exactly the same
|
|
659
|
+
* type, value, and parameters. This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack).
|
|
660
|
+
* @since v17.7.0, v16.15.0
|
|
661
|
+
* @param otherKeyObject A `KeyObject` with which to compare `keyObject`.
|
|
662
|
+
*/
|
|
663
|
+
equals(otherKeyObject: KeyObject): boolean;
|
|
664
|
+
/**
|
|
665
|
+
* For secret keys, this property represents the size of the key in bytes. This
|
|
666
|
+
* property is `undefined` for asymmetric keys.
|
|
667
|
+
* @since v11.6.0
|
|
668
|
+
*/
|
|
186
669
|
symmetricKeySize?: number | undefined;
|
|
670
|
+
/**
|
|
671
|
+
* Depending on the type of this `KeyObject`, this property is either`'secret'` for secret (symmetric) keys, `'public'` for public (asymmetric) keys
|
|
672
|
+
* or `'private'` for private (asymmetric) keys.
|
|
673
|
+
* @since v11.6.0
|
|
674
|
+
*/
|
|
187
675
|
type: KeyObjectType;
|
|
188
676
|
}
|
|
189
|
-
|
|
190
677
|
type CipherCCMTypes = "aes-128-ccm" | "aes-192-ccm" | "aes-256-ccm" | "chacha20-poly1305";
|
|
191
678
|
type CipherGCMTypes = "aes-128-gcm" | "aes-192-gcm" | "aes-256-gcm";
|
|
192
679
|
type CipherOCBTypes = "aes-128-ocb" | "aes-192-ocb" | "aes-256-ocb";
|
|
193
|
-
|
|
194
680
|
type BinaryLike = string | NodeJS.ArrayBufferView;
|
|
195
|
-
|
|
196
681
|
type CipherKey = BinaryLike | KeyObject;
|
|
197
|
-
|
|
198
682
|
interface CipherCCMOptions extends stream.TransformOptions {
|
|
199
683
|
authTagLength: number;
|
|
200
684
|
}
|
|
@@ -204,13 +688,78 @@ declare module "crypto" {
|
|
|
204
688
|
interface CipherOCBOptions extends stream.TransformOptions {
|
|
205
689
|
authTagLength: number;
|
|
206
690
|
}
|
|
207
|
-
/**
|
|
691
|
+
/**
|
|
692
|
+
* Creates and returns a `Cipher` object that uses the given `algorithm` and `password`.
|
|
693
|
+
*
|
|
694
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
695
|
+
* cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the
|
|
696
|
+
* authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication
|
|
697
|
+
* tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
|
|
698
|
+
* For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes.
|
|
699
|
+
*
|
|
700
|
+
* The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
|
|
701
|
+
* recent OpenSSL releases, `openssl list -cipher-algorithms` will
|
|
702
|
+
* display the available cipher algorithms.
|
|
703
|
+
*
|
|
704
|
+
* The `password` is used to derive the cipher key and initialization vector (IV).
|
|
705
|
+
* The value must be either a `'latin1'` encoded string, a `Buffer`, a`TypedArray`, or a `DataView`.
|
|
706
|
+
*
|
|
707
|
+
* **This function is semantically insecure for all**
|
|
708
|
+
* **supported ciphers and fatally flawed for ciphers in counter mode (such as CTR,**
|
|
709
|
+
* **GCM, or CCM).**
|
|
710
|
+
*
|
|
711
|
+
* The implementation of `crypto.createCipher()` derives keys using the OpenSSL
|
|
712
|
+
* function [`EVP_BytesToKey`](https://www.openssl.org/docs/man3.0/man3/EVP_BytesToKey.html) with the digest algorithm set to MD5, one
|
|
713
|
+
* iteration, and no salt. The lack of salt allows dictionary attacks as the same
|
|
714
|
+
* password always creates the same key. The low iteration count and
|
|
715
|
+
* non-cryptographically secure hash algorithm allow passwords to be tested very
|
|
716
|
+
* rapidly.
|
|
717
|
+
*
|
|
718
|
+
* In line with OpenSSL's recommendation to use a more modern algorithm instead of [`EVP_BytesToKey`](https://www.openssl.org/docs/man3.0/man3/EVP_BytesToKey.html) it is recommended that
|
|
719
|
+
* developers derive a key and IV on
|
|
720
|
+
* their own using {@link scrypt} and to use {@link createCipheriv} to create the `Cipher` object. Users should not use ciphers with counter mode
|
|
721
|
+
* (e.g. CTR, GCM, or CCM) in `crypto.createCipher()`. A warning is emitted when
|
|
722
|
+
* they are used in order to avoid the risk of IV reuse that causes
|
|
723
|
+
* vulnerabilities. For the case when IV is reused in GCM, see [Nonce-Disrespecting Adversaries](https://github.com/nonce-disrespect/nonce-disrespect) for details.
|
|
724
|
+
* @since v0.1.94
|
|
725
|
+
* @deprecated Since v10.0.0 - Use {@link createCipheriv} instead.
|
|
726
|
+
* @param options `stream.transform` options
|
|
727
|
+
*/
|
|
208
728
|
function createCipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): CipherCCM;
|
|
209
729
|
/** @deprecated since v10.0.0 use `createCipheriv()` */
|
|
210
730
|
function createCipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): CipherGCM;
|
|
211
731
|
/** @deprecated since v10.0.0 use `createCipheriv()` */
|
|
212
732
|
function createCipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Cipher;
|
|
213
|
-
|
|
733
|
+
/**
|
|
734
|
+
* Creates and returns a `Cipher` object, with the given `algorithm`, `key` and
|
|
735
|
+
* initialization vector (`iv`).
|
|
736
|
+
*
|
|
737
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
738
|
+
* cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the
|
|
739
|
+
* authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication
|
|
740
|
+
* tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
|
|
741
|
+
* For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes.
|
|
742
|
+
*
|
|
743
|
+
* The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
|
|
744
|
+
* recent OpenSSL releases, `openssl list -cipher-algorithms` will
|
|
745
|
+
* display the available cipher algorithms.
|
|
746
|
+
*
|
|
747
|
+
* The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded
|
|
748
|
+
* strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
|
|
749
|
+
* a `KeyObject` of type `secret`. If the cipher does not need
|
|
750
|
+
* an initialization vector, `iv` may be `null`.
|
|
751
|
+
*
|
|
752
|
+
* When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
753
|
+
*
|
|
754
|
+
* Initialization vectors should be unpredictable and unique; ideally, they will be
|
|
755
|
+
* cryptographically random. They do not have to be secret: IVs are typically just
|
|
756
|
+
* added to ciphertext messages unencrypted. It may sound contradictory that
|
|
757
|
+
* something has to be unpredictable and unique, but does not have to be secret;
|
|
758
|
+
* remember that an attacker must not be able to predict ahead of time what a
|
|
759
|
+
* given IV will be.
|
|
760
|
+
* @since v0.1.94
|
|
761
|
+
* @param options `stream.transform` options
|
|
762
|
+
*/
|
|
214
763
|
function createCipheriv(
|
|
215
764
|
algorithm: CipherCCMTypes,
|
|
216
765
|
key: CipherKey,
|
|
@@ -235,38 +784,259 @@ declare module "crypto" {
|
|
|
235
784
|
iv: BinaryLike | null,
|
|
236
785
|
options?: stream.TransformOptions,
|
|
237
786
|
): Cipher;
|
|
238
|
-
|
|
787
|
+
/**
|
|
788
|
+
* Instances of the `Cipher` class are used to encrypt data. The class can be
|
|
789
|
+
* used in one of two ways:
|
|
790
|
+
*
|
|
791
|
+
* * As a `stream` that is both readable and writable, where plain unencrypted
|
|
792
|
+
* data is written to produce encrypted data on the readable side, or
|
|
793
|
+
* * Using the `cipher.update()` and `cipher.final()` methods to produce
|
|
794
|
+
* the encrypted data.
|
|
795
|
+
*
|
|
796
|
+
* The {@link createCipher} or {@link createCipheriv} methods are
|
|
797
|
+
* used to create `Cipher` instances. `Cipher` objects are not to be created
|
|
798
|
+
* directly using the `new` keyword.
|
|
799
|
+
*
|
|
800
|
+
* Example: Using `Cipher` objects as streams:
|
|
801
|
+
*
|
|
802
|
+
* ```js
|
|
803
|
+
* const {
|
|
804
|
+
* scrypt,
|
|
805
|
+
* randomFill,
|
|
806
|
+
* createCipheriv,
|
|
807
|
+
* } = await import('node:crypto');
|
|
808
|
+
*
|
|
809
|
+
* const algorithm = 'aes-192-cbc';
|
|
810
|
+
* const password = 'Password used to generate key';
|
|
811
|
+
*
|
|
812
|
+
* // First, we'll generate the key. The key length is dependent on the algorithm.
|
|
813
|
+
* // In this case for aes192, it is 24 bytes (192 bits).
|
|
814
|
+
* scrypt(password, 'salt', 24, (err, key) => {
|
|
815
|
+
* if (err) throw err;
|
|
816
|
+
* // Then, we'll generate a random initialization vector
|
|
817
|
+
* randomFill(new Uint8Array(16), (err, iv) => {
|
|
818
|
+
* if (err) throw err;
|
|
819
|
+
*
|
|
820
|
+
* // Once we have the key and iv, we can create and use the cipher...
|
|
821
|
+
* const cipher = createCipheriv(algorithm, key, iv);
|
|
822
|
+
*
|
|
823
|
+
* let encrypted = '';
|
|
824
|
+
* cipher.setEncoding('hex');
|
|
825
|
+
*
|
|
826
|
+
* cipher.on('data', (chunk) => encrypted += chunk);
|
|
827
|
+
* cipher.on('end', () => console.log(encrypted));
|
|
828
|
+
*
|
|
829
|
+
* cipher.write('some clear text data');
|
|
830
|
+
* cipher.end();
|
|
831
|
+
* });
|
|
832
|
+
* });
|
|
833
|
+
* ```
|
|
834
|
+
*
|
|
835
|
+
* Example: Using `Cipher` and piped streams:
|
|
836
|
+
*
|
|
837
|
+
* ```js
|
|
838
|
+
* import {
|
|
839
|
+
* createReadStream,
|
|
840
|
+
* createWriteStream,
|
|
841
|
+
* } from 'node:fs';
|
|
842
|
+
*
|
|
843
|
+
* import {
|
|
844
|
+
* pipeline,
|
|
845
|
+
* } from 'node:stream';
|
|
846
|
+
*
|
|
847
|
+
* const {
|
|
848
|
+
* scrypt,
|
|
849
|
+
* randomFill,
|
|
850
|
+
* createCipheriv,
|
|
851
|
+
* } = await import('node:crypto');
|
|
852
|
+
*
|
|
853
|
+
* const algorithm = 'aes-192-cbc';
|
|
854
|
+
* const password = 'Password used to generate key';
|
|
855
|
+
*
|
|
856
|
+
* // First, we'll generate the key. The key length is dependent on the algorithm.
|
|
857
|
+
* // In this case for aes192, it is 24 bytes (192 bits).
|
|
858
|
+
* scrypt(password, 'salt', 24, (err, key) => {
|
|
859
|
+
* if (err) throw err;
|
|
860
|
+
* // Then, we'll generate a random initialization vector
|
|
861
|
+
* randomFill(new Uint8Array(16), (err, iv) => {
|
|
862
|
+
* if (err) throw err;
|
|
863
|
+
*
|
|
864
|
+
* const cipher = createCipheriv(algorithm, key, iv);
|
|
865
|
+
*
|
|
866
|
+
* const input = createReadStream('test.js');
|
|
867
|
+
* const output = createWriteStream('test.enc');
|
|
868
|
+
*
|
|
869
|
+
* pipeline(input, cipher, output, (err) => {
|
|
870
|
+
* if (err) throw err;
|
|
871
|
+
* });
|
|
872
|
+
* });
|
|
873
|
+
* });
|
|
874
|
+
* ```
|
|
875
|
+
*
|
|
876
|
+
* Example: Using the `cipher.update()` and `cipher.final()` methods:
|
|
877
|
+
*
|
|
878
|
+
* ```js
|
|
879
|
+
* const {
|
|
880
|
+
* scrypt,
|
|
881
|
+
* randomFill,
|
|
882
|
+
* createCipheriv,
|
|
883
|
+
* } = await import('node:crypto');
|
|
884
|
+
*
|
|
885
|
+
* const algorithm = 'aes-192-cbc';
|
|
886
|
+
* const password = 'Password used to generate key';
|
|
887
|
+
*
|
|
888
|
+
* // First, we'll generate the key. The key length is dependent on the algorithm.
|
|
889
|
+
* // In this case for aes192, it is 24 bytes (192 bits).
|
|
890
|
+
* scrypt(password, 'salt', 24, (err, key) => {
|
|
891
|
+
* if (err) throw err;
|
|
892
|
+
* // Then, we'll generate a random initialization vector
|
|
893
|
+
* randomFill(new Uint8Array(16), (err, iv) => {
|
|
894
|
+
* if (err) throw err;
|
|
895
|
+
*
|
|
896
|
+
* const cipher = createCipheriv(algorithm, key, iv);
|
|
897
|
+
*
|
|
898
|
+
* let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
|
|
899
|
+
* encrypted += cipher.final('hex');
|
|
900
|
+
* console.log(encrypted);
|
|
901
|
+
* });
|
|
902
|
+
* });
|
|
903
|
+
* ```
|
|
904
|
+
* @since v0.1.94
|
|
905
|
+
*/
|
|
239
906
|
class Cipher extends stream.Transform {
|
|
240
907
|
private constructor();
|
|
908
|
+
/**
|
|
909
|
+
* Updates the cipher with `data`. If the `inputEncoding` argument is given,
|
|
910
|
+
* the `data`argument is a string using the specified encoding. If the `inputEncoding`argument is not given, `data` must be a `Buffer`, `TypedArray`, or `DataView`. If `data` is a `Buffer`,
|
|
911
|
+
* `TypedArray`, or `DataView`, then `inputEncoding` is ignored.
|
|
912
|
+
*
|
|
913
|
+
* The `outputEncoding` specifies the output format of the enciphered
|
|
914
|
+
* data. If the `outputEncoding`is specified, a string using the specified encoding is returned. If no`outputEncoding` is provided, a `Buffer` is returned.
|
|
915
|
+
*
|
|
916
|
+
* The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being
|
|
917
|
+
* thrown.
|
|
918
|
+
* @since v0.1.94
|
|
919
|
+
* @param inputEncoding The `encoding` of the data.
|
|
920
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
921
|
+
*/
|
|
241
922
|
update(data: BinaryLike): Buffer;
|
|
242
|
-
update(data: string,
|
|
243
|
-
update(data: NodeJS.ArrayBufferView,
|
|
244
|
-
update(data: string,
|
|
923
|
+
update(data: string, inputEncoding: Encoding): Buffer;
|
|
924
|
+
update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string;
|
|
925
|
+
update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string;
|
|
926
|
+
/**
|
|
927
|
+
* Once the `cipher.final()` method has been called, the `Cipher` object can no
|
|
928
|
+
* longer be used to encrypt data. Attempts to call `cipher.final()` more than
|
|
929
|
+
* once will result in an error being thrown.
|
|
930
|
+
* @since v0.1.94
|
|
931
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
932
|
+
* @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
|
|
933
|
+
*/
|
|
245
934
|
final(): Buffer;
|
|
246
|
-
final(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
935
|
+
final(outputEncoding: BufferEncoding): string;
|
|
936
|
+
/**
|
|
937
|
+
* When using block encryption algorithms, the `Cipher` class will automatically
|
|
938
|
+
* add padding to the input data to the appropriate block size. To disable the
|
|
939
|
+
* default padding call `cipher.setAutoPadding(false)`.
|
|
940
|
+
*
|
|
941
|
+
* When `autoPadding` is `false`, the length of the entire input data must be a
|
|
942
|
+
* multiple of the cipher's block size or `cipher.final()` will throw an error.
|
|
943
|
+
* Disabling automatic padding is useful for non-standard padding, for instance
|
|
944
|
+
* using `0x0` instead of PKCS padding.
|
|
945
|
+
*
|
|
946
|
+
* The `cipher.setAutoPadding()` method must be called before `cipher.final()`.
|
|
947
|
+
* @since v0.7.1
|
|
948
|
+
* @param [autoPadding=true]
|
|
949
|
+
* @return for method chaining.
|
|
950
|
+
*/
|
|
951
|
+
setAutoPadding(autoPadding?: boolean): this;
|
|
250
952
|
}
|
|
251
953
|
interface CipherCCM extends Cipher {
|
|
252
|
-
setAAD(
|
|
954
|
+
setAAD(
|
|
955
|
+
buffer: NodeJS.ArrayBufferView,
|
|
956
|
+
options: {
|
|
957
|
+
plaintextLength: number;
|
|
958
|
+
},
|
|
959
|
+
): this;
|
|
253
960
|
getAuthTag(): Buffer;
|
|
254
961
|
}
|
|
255
962
|
interface CipherGCM extends Cipher {
|
|
256
|
-
setAAD(
|
|
963
|
+
setAAD(
|
|
964
|
+
buffer: NodeJS.ArrayBufferView,
|
|
965
|
+
options?: {
|
|
966
|
+
plaintextLength: number;
|
|
967
|
+
},
|
|
968
|
+
): this;
|
|
257
969
|
getAuthTag(): Buffer;
|
|
258
970
|
}
|
|
259
971
|
interface CipherOCB extends Cipher {
|
|
260
|
-
setAAD(
|
|
972
|
+
setAAD(
|
|
973
|
+
buffer: NodeJS.ArrayBufferView,
|
|
974
|
+
options?: {
|
|
975
|
+
plaintextLength: number;
|
|
976
|
+
},
|
|
977
|
+
): this;
|
|
261
978
|
getAuthTag(): Buffer;
|
|
262
979
|
}
|
|
263
|
-
/**
|
|
980
|
+
/**
|
|
981
|
+
* Creates and returns a `Decipher` object that uses the given `algorithm` and `password` (key).
|
|
982
|
+
*
|
|
983
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
984
|
+
* cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the
|
|
985
|
+
* authentication tag in bytes, see `CCM mode`.
|
|
986
|
+
* For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes.
|
|
987
|
+
*
|
|
988
|
+
* **This function is semantically insecure for all**
|
|
989
|
+
* **supported ciphers and fatally flawed for ciphers in counter mode (such as CTR,**
|
|
990
|
+
* **GCM, or CCM).**
|
|
991
|
+
*
|
|
992
|
+
* The implementation of `crypto.createDecipher()` derives keys using the OpenSSL
|
|
993
|
+
* function [`EVP_BytesToKey`](https://www.openssl.org/docs/man3.0/man3/EVP_BytesToKey.html) with the digest algorithm set to MD5, one
|
|
994
|
+
* iteration, and no salt. The lack of salt allows dictionary attacks as the same
|
|
995
|
+
* password always creates the same key. The low iteration count and
|
|
996
|
+
* non-cryptographically secure hash algorithm allow passwords to be tested very
|
|
997
|
+
* rapidly.
|
|
998
|
+
*
|
|
999
|
+
* In line with OpenSSL's recommendation to use a more modern algorithm instead of [`EVP_BytesToKey`](https://www.openssl.org/docs/man3.0/man3/EVP_BytesToKey.html) it is recommended that
|
|
1000
|
+
* developers derive a key and IV on
|
|
1001
|
+
* their own using {@link scrypt} and to use {@link createDecipheriv} to create the `Decipher` object.
|
|
1002
|
+
* @since v0.1.94
|
|
1003
|
+
* @deprecated Since v10.0.0 - Use {@link createDecipheriv} instead.
|
|
1004
|
+
* @param options `stream.transform` options
|
|
1005
|
+
*/
|
|
264
1006
|
function createDecipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): DecipherCCM;
|
|
265
1007
|
/** @deprecated since v10.0.0 use `createDecipheriv()` */
|
|
266
1008
|
function createDecipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): DecipherGCM;
|
|
267
1009
|
/** @deprecated since v10.0.0 use `createDecipheriv()` */
|
|
268
1010
|
function createDecipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Decipher;
|
|
269
|
-
|
|
1011
|
+
/**
|
|
1012
|
+
* Creates and returns a `Decipher` object that uses the given `algorithm`, `key` and initialization vector (`iv`).
|
|
1013
|
+
*
|
|
1014
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
1015
|
+
* cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the
|
|
1016
|
+
* authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength` option is not required but can be used to restrict accepted authentication tags
|
|
1017
|
+
* to those with the specified length.
|
|
1018
|
+
* For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes.
|
|
1019
|
+
*
|
|
1020
|
+
* The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
|
|
1021
|
+
* recent OpenSSL releases, `openssl list -cipher-algorithms` will
|
|
1022
|
+
* display the available cipher algorithms.
|
|
1023
|
+
*
|
|
1024
|
+
* The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded
|
|
1025
|
+
* strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
|
|
1026
|
+
* a `KeyObject` of type `secret`. If the cipher does not need
|
|
1027
|
+
* an initialization vector, `iv` may be `null`.
|
|
1028
|
+
*
|
|
1029
|
+
* When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1030
|
+
*
|
|
1031
|
+
* Initialization vectors should be unpredictable and unique; ideally, they will be
|
|
1032
|
+
* cryptographically random. They do not have to be secret: IVs are typically just
|
|
1033
|
+
* added to ciphertext messages unencrypted. It may sound contradictory that
|
|
1034
|
+
* something has to be unpredictable and unique, but does not have to be secret;
|
|
1035
|
+
* remember that an attacker must not be able to predict ahead of time what a given
|
|
1036
|
+
* IV will be.
|
|
1037
|
+
* @since v0.1.94
|
|
1038
|
+
* @param options `stream.transform` options
|
|
1039
|
+
*/
|
|
270
1040
|
function createDecipheriv(
|
|
271
1041
|
algorithm: CipherCCMTypes,
|
|
272
1042
|
key: CipherKey,
|
|
@@ -291,53 +1061,297 @@ declare module "crypto" {
|
|
|
291
1061
|
iv: BinaryLike | null,
|
|
292
1062
|
options?: stream.TransformOptions,
|
|
293
1063
|
): Decipher;
|
|
294
|
-
|
|
1064
|
+
/**
|
|
1065
|
+
* Instances of the `Decipher` class are used to decrypt data. The class can be
|
|
1066
|
+
* used in one of two ways:
|
|
1067
|
+
*
|
|
1068
|
+
* * As a `stream` that is both readable and writable, where plain encrypted
|
|
1069
|
+
* data is written to produce unencrypted data on the readable side, or
|
|
1070
|
+
* * Using the `decipher.update()` and `decipher.final()` methods to
|
|
1071
|
+
* produce the unencrypted data.
|
|
1072
|
+
*
|
|
1073
|
+
* The {@link createDecipher} or {@link createDecipheriv} methods are
|
|
1074
|
+
* used to create `Decipher` instances. `Decipher` objects are not to be created
|
|
1075
|
+
* directly using the `new` keyword.
|
|
1076
|
+
*
|
|
1077
|
+
* Example: Using `Decipher` objects as streams:
|
|
1078
|
+
*
|
|
1079
|
+
* ```js
|
|
1080
|
+
* import { Buffer } from 'node:buffer';
|
|
1081
|
+
* const {
|
|
1082
|
+
* scryptSync,
|
|
1083
|
+
* createDecipheriv,
|
|
1084
|
+
* } = await import('node:crypto');
|
|
1085
|
+
*
|
|
1086
|
+
* const algorithm = 'aes-192-cbc';
|
|
1087
|
+
* const password = 'Password used to generate key';
|
|
1088
|
+
* // Key length is dependent on the algorithm. In this case for aes192, it is
|
|
1089
|
+
* // 24 bytes (192 bits).
|
|
1090
|
+
* // Use the async `crypto.scrypt()` instead.
|
|
1091
|
+
* const key = scryptSync(password, 'salt', 24);
|
|
1092
|
+
* // The IV is usually passed along with the ciphertext.
|
|
1093
|
+
* const iv = Buffer.alloc(16, 0); // Initialization vector.
|
|
1094
|
+
*
|
|
1095
|
+
* const decipher = createDecipheriv(algorithm, key, iv);
|
|
1096
|
+
*
|
|
1097
|
+
* let decrypted = '';
|
|
1098
|
+
* decipher.on('readable', () => {
|
|
1099
|
+
* let chunk;
|
|
1100
|
+
* while (null !== (chunk = decipher.read())) {
|
|
1101
|
+
* decrypted += chunk.toString('utf8');
|
|
1102
|
+
* }
|
|
1103
|
+
* });
|
|
1104
|
+
* decipher.on('end', () => {
|
|
1105
|
+
* console.log(decrypted);
|
|
1106
|
+
* // Prints: some clear text data
|
|
1107
|
+
* });
|
|
1108
|
+
*
|
|
1109
|
+
* // Encrypted with same algorithm, key and iv.
|
|
1110
|
+
* const encrypted =
|
|
1111
|
+
* 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
|
|
1112
|
+
* decipher.write(encrypted, 'hex');
|
|
1113
|
+
* decipher.end();
|
|
1114
|
+
* ```
|
|
1115
|
+
*
|
|
1116
|
+
* Example: Using `Decipher` and piped streams:
|
|
1117
|
+
*
|
|
1118
|
+
* ```js
|
|
1119
|
+
* import {
|
|
1120
|
+
* createReadStream,
|
|
1121
|
+
* createWriteStream,
|
|
1122
|
+
* } from 'node:fs';
|
|
1123
|
+
* import { Buffer } from 'node:buffer';
|
|
1124
|
+
* const {
|
|
1125
|
+
* scryptSync,
|
|
1126
|
+
* createDecipheriv,
|
|
1127
|
+
* } = await import('node:crypto');
|
|
1128
|
+
*
|
|
1129
|
+
* const algorithm = 'aes-192-cbc';
|
|
1130
|
+
* const password = 'Password used to generate key';
|
|
1131
|
+
* // Use the async `crypto.scrypt()` instead.
|
|
1132
|
+
* const key = scryptSync(password, 'salt', 24);
|
|
1133
|
+
* // The IV is usually passed along with the ciphertext.
|
|
1134
|
+
* const iv = Buffer.alloc(16, 0); // Initialization vector.
|
|
1135
|
+
*
|
|
1136
|
+
* const decipher = createDecipheriv(algorithm, key, iv);
|
|
1137
|
+
*
|
|
1138
|
+
* const input = createReadStream('test.enc');
|
|
1139
|
+
* const output = createWriteStream('test.js');
|
|
1140
|
+
*
|
|
1141
|
+
* input.pipe(decipher).pipe(output);
|
|
1142
|
+
* ```
|
|
1143
|
+
*
|
|
1144
|
+
* Example: Using the `decipher.update()` and `decipher.final()` methods:
|
|
1145
|
+
*
|
|
1146
|
+
* ```js
|
|
1147
|
+
* import { Buffer } from 'node:buffer';
|
|
1148
|
+
* const {
|
|
1149
|
+
* scryptSync,
|
|
1150
|
+
* createDecipheriv,
|
|
1151
|
+
* } = await import('node:crypto');
|
|
1152
|
+
*
|
|
1153
|
+
* const algorithm = 'aes-192-cbc';
|
|
1154
|
+
* const password = 'Password used to generate key';
|
|
1155
|
+
* // Use the async `crypto.scrypt()` instead.
|
|
1156
|
+
* const key = scryptSync(password, 'salt', 24);
|
|
1157
|
+
* // The IV is usually passed along with the ciphertext.
|
|
1158
|
+
* const iv = Buffer.alloc(16, 0); // Initialization vector.
|
|
1159
|
+
*
|
|
1160
|
+
* const decipher = createDecipheriv(algorithm, key, iv);
|
|
1161
|
+
*
|
|
1162
|
+
* // Encrypted using same algorithm, key and iv.
|
|
1163
|
+
* const encrypted =
|
|
1164
|
+
* 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
|
|
1165
|
+
* let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
1166
|
+
* decrypted += decipher.final('utf8');
|
|
1167
|
+
* console.log(decrypted);
|
|
1168
|
+
* // Prints: some clear text data
|
|
1169
|
+
* ```
|
|
1170
|
+
* @since v0.1.94
|
|
1171
|
+
*/
|
|
295
1172
|
class Decipher extends stream.Transform {
|
|
296
1173
|
private constructor();
|
|
1174
|
+
/**
|
|
1175
|
+
* Updates the decipher with `data`. If the `inputEncoding` argument is given,
|
|
1176
|
+
* the `data` argument is a string using the specified encoding. If the `inputEncoding` argument is not given, `data` must be a `Buffer`. If `data` is a `Buffer` then `inputEncoding` is
|
|
1177
|
+
* ignored.
|
|
1178
|
+
*
|
|
1179
|
+
* The `outputEncoding` specifies the output format of the enciphered
|
|
1180
|
+
* data. If the `outputEncoding` is specified, a string using the specified encoding is returned. If no `outputEncoding` is provided, a `Buffer` is returned.
|
|
1181
|
+
*
|
|
1182
|
+
* The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error
|
|
1183
|
+
* being thrown.
|
|
1184
|
+
* @since v0.1.94
|
|
1185
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
1186
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
1187
|
+
*/
|
|
297
1188
|
update(data: NodeJS.ArrayBufferView): Buffer;
|
|
298
|
-
update(data: string,
|
|
299
|
-
update(data: NodeJS.ArrayBufferView,
|
|
300
|
-
update(data: string,
|
|
1189
|
+
update(data: string, inputEncoding: Encoding): Buffer;
|
|
1190
|
+
update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string;
|
|
1191
|
+
update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string;
|
|
1192
|
+
/**
|
|
1193
|
+
* Once the `decipher.final()` method has been called, the `Decipher` object can
|
|
1194
|
+
* no longer be used to decrypt data. Attempts to call `decipher.final()` more
|
|
1195
|
+
* than once will result in an error being thrown.
|
|
1196
|
+
* @since v0.1.94
|
|
1197
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
1198
|
+
* @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
|
|
1199
|
+
*/
|
|
301
1200
|
final(): Buffer;
|
|
302
|
-
final(
|
|
1201
|
+
final(outputEncoding: BufferEncoding): string;
|
|
1202
|
+
/**
|
|
1203
|
+
* When data has been encrypted without standard block padding, calling `decipher.setAutoPadding(false)` will disable automatic padding to prevent `decipher.final()` from checking for and
|
|
1204
|
+
* removing padding.
|
|
1205
|
+
*
|
|
1206
|
+
* Turning auto padding off will only work if the input data's length is a
|
|
1207
|
+
* multiple of the ciphers block size.
|
|
1208
|
+
*
|
|
1209
|
+
* The `decipher.setAutoPadding()` method must be called before `decipher.final()`.
|
|
1210
|
+
* @since v0.7.1
|
|
1211
|
+
* @param [autoPadding=true]
|
|
1212
|
+
* @return for method chaining.
|
|
1213
|
+
*/
|
|
303
1214
|
setAutoPadding(auto_padding?: boolean): this;
|
|
304
|
-
// setAuthTag(tag: NodeJS.ArrayBufferView): this;
|
|
305
|
-
// setAAD(buffer: NodeJS.ArrayBufferView): this;
|
|
306
1215
|
}
|
|
307
1216
|
interface DecipherCCM extends Decipher {
|
|
308
1217
|
setAuthTag(buffer: NodeJS.ArrayBufferView): this;
|
|
309
|
-
setAAD(
|
|
1218
|
+
setAAD(
|
|
1219
|
+
buffer: NodeJS.ArrayBufferView,
|
|
1220
|
+
options: {
|
|
1221
|
+
plaintextLength: number;
|
|
1222
|
+
},
|
|
1223
|
+
): this;
|
|
310
1224
|
}
|
|
311
1225
|
interface DecipherGCM extends Decipher {
|
|
312
1226
|
setAuthTag(buffer: NodeJS.ArrayBufferView): this;
|
|
313
|
-
setAAD(
|
|
1227
|
+
setAAD(
|
|
1228
|
+
buffer: NodeJS.ArrayBufferView,
|
|
1229
|
+
options?: {
|
|
1230
|
+
plaintextLength: number;
|
|
1231
|
+
},
|
|
1232
|
+
): this;
|
|
314
1233
|
}
|
|
315
1234
|
interface DecipherOCB extends Decipher {
|
|
316
1235
|
setAuthTag(buffer: NodeJS.ArrayBufferView): this;
|
|
317
|
-
setAAD(
|
|
1236
|
+
setAAD(
|
|
1237
|
+
buffer: NodeJS.ArrayBufferView,
|
|
1238
|
+
options?: {
|
|
1239
|
+
plaintextLength: number;
|
|
1240
|
+
},
|
|
1241
|
+
): this;
|
|
318
1242
|
}
|
|
319
|
-
|
|
320
1243
|
interface PrivateKeyInput {
|
|
321
1244
|
key: string | Buffer;
|
|
322
1245
|
format?: KeyFormat | undefined;
|
|
323
1246
|
type?: "pkcs1" | "pkcs8" | "sec1" | undefined;
|
|
324
1247
|
passphrase?: string | Buffer | undefined;
|
|
1248
|
+
encoding?: string | undefined;
|
|
325
1249
|
}
|
|
326
|
-
|
|
327
1250
|
interface PublicKeyInput {
|
|
328
1251
|
key: string | Buffer;
|
|
329
1252
|
format?: KeyFormat | undefined;
|
|
330
1253
|
type?: "pkcs1" | "spki" | undefined;
|
|
1254
|
+
encoding?: string | undefined;
|
|
331
1255
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
1256
|
+
/**
|
|
1257
|
+
* Asynchronously generates a new random secret key of the given `length`. The `type` will determine which validations will be performed on the `length`.
|
|
1258
|
+
*
|
|
1259
|
+
* ```js
|
|
1260
|
+
* const {
|
|
1261
|
+
* generateKey,
|
|
1262
|
+
* } = await import('node:crypto');
|
|
1263
|
+
*
|
|
1264
|
+
* generateKey('hmac', { length: 512 }, (err, key) => {
|
|
1265
|
+
* if (err) throw err;
|
|
1266
|
+
* console.log(key.export().toString('hex')); // 46e..........620
|
|
1267
|
+
* });
|
|
1268
|
+
* ```
|
|
1269
|
+
*
|
|
1270
|
+
* The size of a generated HMAC key should not exceed the block size of the
|
|
1271
|
+
* underlying hash function. See {@link createHmac} for more information.
|
|
1272
|
+
* @since v15.0.0
|
|
1273
|
+
* @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
|
|
1274
|
+
*/
|
|
1275
|
+
function generateKey(
|
|
1276
|
+
type: "hmac" | "aes",
|
|
1277
|
+
options: {
|
|
1278
|
+
length: number;
|
|
1279
|
+
},
|
|
1280
|
+
callback: (err: Error | null, key: KeyObject) => void,
|
|
1281
|
+
): void;
|
|
1282
|
+
/**
|
|
1283
|
+
* Synchronously generates a new random secret key of the given `length`. The `type` will determine which validations will be performed on the `length`.
|
|
1284
|
+
*
|
|
1285
|
+
* ```js
|
|
1286
|
+
* const {
|
|
1287
|
+
* generateKeySync,
|
|
1288
|
+
* } = await import('node:crypto');
|
|
1289
|
+
*
|
|
1290
|
+
* const key = generateKeySync('hmac', { length: 512 });
|
|
1291
|
+
* console.log(key.export().toString('hex')); // e89..........41e
|
|
1292
|
+
* ```
|
|
1293
|
+
*
|
|
1294
|
+
* The size of a generated HMAC key should not exceed the block size of the
|
|
1295
|
+
* underlying hash function. See {@link createHmac} for more information.
|
|
1296
|
+
* @since v15.0.0
|
|
1297
|
+
* @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
|
|
1298
|
+
*/
|
|
1299
|
+
function generateKeySync(
|
|
1300
|
+
type: "hmac" | "aes",
|
|
1301
|
+
options: {
|
|
1302
|
+
length: number;
|
|
1303
|
+
},
|
|
1304
|
+
): KeyObject;
|
|
1305
|
+
interface JsonWebKeyInput {
|
|
1306
|
+
key: JsonWebKey;
|
|
1307
|
+
format: "jwk";
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Creates and returns a new key object containing a private key. If `key` is a
|
|
1311
|
+
* string or `Buffer`, `format` is assumed to be `'pem'`; otherwise, `key` must be an object with the properties described above.
|
|
1312
|
+
*
|
|
1313
|
+
* If the private key is encrypted, a `passphrase` must be specified. The length
|
|
1314
|
+
* of the passphrase is limited to 1024 bytes.
|
|
1315
|
+
* @since v11.6.0
|
|
1316
|
+
*/
|
|
1317
|
+
function createPrivateKey(key: PrivateKeyInput | string | Buffer | JsonWebKeyInput): KeyObject;
|
|
1318
|
+
/**
|
|
1319
|
+
* Creates and returns a new key object containing a public key. If `key` is a
|
|
1320
|
+
* string or `Buffer`, `format` is assumed to be `'pem'`; if `key` is a `KeyObject` with type `'private'`, the public key is derived from the given private key;
|
|
1321
|
+
* otherwise, `key` must be an object with the properties described above.
|
|
1322
|
+
*
|
|
1323
|
+
* If the format is `'pem'`, the `'key'` may also be an X.509 certificate.
|
|
1324
|
+
*
|
|
1325
|
+
* Because public keys can be derived from private keys, a private key may be
|
|
1326
|
+
* passed instead of a public key. In that case, this function behaves as if {@link createPrivateKey} had been called, except that the type of the
|
|
1327
|
+
* returned `KeyObject` will be `'public'` and that the private key cannot be
|
|
1328
|
+
* extracted from the returned `KeyObject`. Similarly, if a `KeyObject` with type `'private'` is given, a new `KeyObject` with type `'public'` will be returned
|
|
1329
|
+
* and it will be impossible to extract the private key from the returned object.
|
|
1330
|
+
* @since v11.6.0
|
|
1331
|
+
*/
|
|
1332
|
+
function createPublicKey(key: PublicKeyInput | string | Buffer | KeyObject | JsonWebKeyInput): KeyObject;
|
|
1333
|
+
/**
|
|
1334
|
+
* Creates and returns a new key object containing a secret key for symmetric
|
|
1335
|
+
* encryption or `Hmac`.
|
|
1336
|
+
* @since v11.6.0
|
|
1337
|
+
* @param encoding The string encoding when `key` is a string.
|
|
1338
|
+
*/
|
|
335
1339
|
function createSecretKey(key: NodeJS.ArrayBufferView): KeyObject;
|
|
336
|
-
|
|
1340
|
+
function createSecretKey(key: string, encoding: BufferEncoding): KeyObject;
|
|
1341
|
+
/**
|
|
1342
|
+
* Creates and returns a `Sign` object that uses the given `algorithm`. Use {@link getHashes} to obtain the names of the available digest algorithms.
|
|
1343
|
+
* Optional `options` argument controls the `stream.Writable` behavior.
|
|
1344
|
+
*
|
|
1345
|
+
* In some cases, a `Sign` instance can be created using the name of a signature
|
|
1346
|
+
* algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
|
|
1347
|
+
* the corresponding digest algorithm. This does not work for all signature
|
|
1348
|
+
* algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
|
|
1349
|
+
* algorithm names.
|
|
1350
|
+
* @since v0.1.92
|
|
1351
|
+
* @param options `stream.Writable` options
|
|
1352
|
+
*/
|
|
337
1353
|
function createSign(algorithm: string, options?: stream.WritableOptions): Sign;
|
|
338
|
-
|
|
339
1354
|
type DSAEncoding = "der" | "ieee-p1363";
|
|
340
|
-
|
|
341
1355
|
interface SigningOptions {
|
|
342
1356
|
/**
|
|
343
1357
|
* @see crypto.constants.RSA_PKCS1_PADDING
|
|
@@ -346,66 +1360,280 @@ declare module "crypto" {
|
|
|
346
1360
|
saltLength?: number | undefined;
|
|
347
1361
|
dsaEncoding?: DSAEncoding | undefined;
|
|
348
1362
|
}
|
|
349
|
-
|
|
350
1363
|
interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {}
|
|
351
1364
|
interface SignKeyObjectInput extends SigningOptions {
|
|
352
1365
|
key: KeyObject;
|
|
353
1366
|
}
|
|
1367
|
+
interface SignJsonWebKeyInput extends JsonWebKeyInput, SigningOptions {}
|
|
354
1368
|
interface VerifyPublicKeyInput extends PublicKeyInput, SigningOptions {}
|
|
355
1369
|
interface VerifyKeyObjectInput extends SigningOptions {
|
|
356
1370
|
key: KeyObject;
|
|
357
1371
|
}
|
|
358
|
-
|
|
1372
|
+
interface VerifyJsonWebKeyInput extends JsonWebKeyInput, SigningOptions {}
|
|
359
1373
|
type KeyLike = string | Buffer | KeyObject;
|
|
360
|
-
|
|
1374
|
+
/**
|
|
1375
|
+
* The `Sign` class is a utility for generating signatures. It can be used in one
|
|
1376
|
+
* of two ways:
|
|
1377
|
+
*
|
|
1378
|
+
* * As a writable `stream`, where data to be signed is written and the `sign.sign()` method is used to generate and return the signature, or
|
|
1379
|
+
* * Using the `sign.update()` and `sign.sign()` methods to produce the
|
|
1380
|
+
* signature.
|
|
1381
|
+
*
|
|
1382
|
+
* The {@link createSign} method is used to create `Sign` instances. The
|
|
1383
|
+
* argument is the string name of the hash function to use. `Sign` objects are not
|
|
1384
|
+
* to be created directly using the `new` keyword.
|
|
1385
|
+
*
|
|
1386
|
+
* Example: Using `Sign` and `Verify` objects as streams:
|
|
1387
|
+
*
|
|
1388
|
+
* ```js
|
|
1389
|
+
* const {
|
|
1390
|
+
* generateKeyPairSync,
|
|
1391
|
+
* createSign,
|
|
1392
|
+
* createVerify,
|
|
1393
|
+
* } = await import('node:crypto');
|
|
1394
|
+
*
|
|
1395
|
+
* const { privateKey, publicKey } = generateKeyPairSync('ec', {
|
|
1396
|
+
* namedCurve: 'sect239k1',
|
|
1397
|
+
* });
|
|
1398
|
+
*
|
|
1399
|
+
* const sign = createSign('SHA256');
|
|
1400
|
+
* sign.write('some data to sign');
|
|
1401
|
+
* sign.end();
|
|
1402
|
+
* const signature = sign.sign(privateKey, 'hex');
|
|
1403
|
+
*
|
|
1404
|
+
* const verify = createVerify('SHA256');
|
|
1405
|
+
* verify.write('some data to sign');
|
|
1406
|
+
* verify.end();
|
|
1407
|
+
* console.log(verify.verify(publicKey, signature, 'hex'));
|
|
1408
|
+
* // Prints: true
|
|
1409
|
+
* ```
|
|
1410
|
+
*
|
|
1411
|
+
* Example: Using the `sign.update()` and `verify.update()` methods:
|
|
1412
|
+
*
|
|
1413
|
+
* ```js
|
|
1414
|
+
* const {
|
|
1415
|
+
* generateKeyPairSync,
|
|
1416
|
+
* createSign,
|
|
1417
|
+
* createVerify,
|
|
1418
|
+
* } = await import('node:crypto');
|
|
1419
|
+
*
|
|
1420
|
+
* const { privateKey, publicKey } = generateKeyPairSync('rsa', {
|
|
1421
|
+
* modulusLength: 2048,
|
|
1422
|
+
* });
|
|
1423
|
+
*
|
|
1424
|
+
* const sign = createSign('SHA256');
|
|
1425
|
+
* sign.update('some data to sign');
|
|
1426
|
+
* sign.end();
|
|
1427
|
+
* const signature = sign.sign(privateKey);
|
|
1428
|
+
*
|
|
1429
|
+
* const verify = createVerify('SHA256');
|
|
1430
|
+
* verify.update('some data to sign');
|
|
1431
|
+
* verify.end();
|
|
1432
|
+
* console.log(verify.verify(publicKey, signature));
|
|
1433
|
+
* // Prints: true
|
|
1434
|
+
* ```
|
|
1435
|
+
* @since v0.1.92
|
|
1436
|
+
*/
|
|
361
1437
|
class Sign extends stream.Writable {
|
|
362
1438
|
private constructor();
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
1439
|
+
/**
|
|
1440
|
+
* Updates the `Sign` content with the given `data`, the encoding of which
|
|
1441
|
+
* is given in `inputEncoding`.
|
|
1442
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
1443
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
1444
|
+
*
|
|
1445
|
+
* This can be called many times with new data as it is streamed.
|
|
1446
|
+
* @since v0.1.92
|
|
1447
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
1448
|
+
*/
|
|
1449
|
+
update(data: BinaryLike): this;
|
|
1450
|
+
update(data: string, inputEncoding: Encoding): this;
|
|
1451
|
+
/**
|
|
1452
|
+
* Calculates the signature on all the data passed through using either `sign.update()` or `sign.write()`.
|
|
1453
|
+
*
|
|
1454
|
+
* If `privateKey` is not a `KeyObject`, this function behaves as if `privateKey` had been passed to {@link createPrivateKey}. If it is an
|
|
1455
|
+
* object, the following additional properties can be passed:
|
|
1456
|
+
*
|
|
1457
|
+
* If `outputEncoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
1458
|
+
*
|
|
1459
|
+
* The `Sign` object can not be again used after `sign.sign()` method has been
|
|
1460
|
+
* called. Multiple calls to `sign.sign()` will result in an error being thrown.
|
|
1461
|
+
* @since v0.1.92
|
|
1462
|
+
*/
|
|
1463
|
+
sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): Buffer;
|
|
367
1464
|
sign(
|
|
368
|
-
|
|
369
|
-
|
|
1465
|
+
privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput,
|
|
1466
|
+
outputFormat: BinaryToTextEncoding,
|
|
370
1467
|
): string;
|
|
371
1468
|
}
|
|
372
|
-
|
|
1469
|
+
/**
|
|
1470
|
+
* Creates and returns a `Verify` object that uses the given algorithm.
|
|
1471
|
+
* Use {@link getHashes} to obtain an array of names of the available
|
|
1472
|
+
* signing algorithms. Optional `options` argument controls the `stream.Writable` behavior.
|
|
1473
|
+
*
|
|
1474
|
+
* In some cases, a `Verify` instance can be created using the name of a signature
|
|
1475
|
+
* algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
|
|
1476
|
+
* the corresponding digest algorithm. This does not work for all signature
|
|
1477
|
+
* algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
|
|
1478
|
+
* algorithm names.
|
|
1479
|
+
* @since v0.1.92
|
|
1480
|
+
* @param options `stream.Writable` options
|
|
1481
|
+
*/
|
|
373
1482
|
function createVerify(algorithm: string, options?: stream.WritableOptions): Verify;
|
|
1483
|
+
/**
|
|
1484
|
+
* The `Verify` class is a utility for verifying signatures. It can be used in one
|
|
1485
|
+
* of two ways:
|
|
1486
|
+
*
|
|
1487
|
+
* * As a writable `stream` where written data is used to validate against the
|
|
1488
|
+
* supplied signature, or
|
|
1489
|
+
* * Using the `verify.update()` and `verify.verify()` methods to verify
|
|
1490
|
+
* the signature.
|
|
1491
|
+
*
|
|
1492
|
+
* The {@link createVerify} method is used to create `Verify` instances. `Verify` objects are not to be created directly using the `new` keyword.
|
|
1493
|
+
*
|
|
1494
|
+
* See `Sign` for examples.
|
|
1495
|
+
* @since v0.1.92
|
|
1496
|
+
*/
|
|
374
1497
|
class Verify extends stream.Writable {
|
|
375
1498
|
private constructor();
|
|
376
|
-
|
|
1499
|
+
/**
|
|
1500
|
+
* Updates the `Verify` content with the given `data`, the encoding of which
|
|
1501
|
+
* is given in `inputEncoding`.
|
|
1502
|
+
* If `inputEncoding` is not provided, and the `data` is a string, an
|
|
1503
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or `DataView`, then `inputEncoding` is ignored.
|
|
1504
|
+
*
|
|
1505
|
+
* This can be called many times with new data as it is streamed.
|
|
1506
|
+
* @since v0.1.92
|
|
1507
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
1508
|
+
*/
|
|
377
1509
|
update(data: BinaryLike): Verify;
|
|
378
|
-
update(data: string,
|
|
1510
|
+
update(data: string, inputEncoding: Encoding): Verify;
|
|
1511
|
+
/**
|
|
1512
|
+
* Verifies the provided data using the given `object` and `signature`.
|
|
1513
|
+
*
|
|
1514
|
+
* If `object` is not a `KeyObject`, this function behaves as if `object` had been passed to {@link createPublicKey}. If it is an
|
|
1515
|
+
* object, the following additional properties can be passed:
|
|
1516
|
+
*
|
|
1517
|
+
* The `signature` argument is the previously calculated signature for the data, in
|
|
1518
|
+
* the `signatureEncoding`.
|
|
1519
|
+
* If a `signatureEncoding` is specified, the `signature` is expected to be a
|
|
1520
|
+
* string; otherwise `signature` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1521
|
+
*
|
|
1522
|
+
* The `verify` object can not be used again after `verify.verify()` has been
|
|
1523
|
+
* called. Multiple calls to `verify.verify()` will result in an error being
|
|
1524
|
+
* thrown.
|
|
1525
|
+
*
|
|
1526
|
+
* Because public keys can be derived from private keys, a private key may
|
|
1527
|
+
* be passed instead of a public key.
|
|
1528
|
+
* @since v0.1.92
|
|
1529
|
+
*/
|
|
379
1530
|
verify(
|
|
380
|
-
object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
|
|
1531
|
+
object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput | VerifyJsonWebKeyInput,
|
|
381
1532
|
signature: NodeJS.ArrayBufferView,
|
|
382
1533
|
): boolean;
|
|
383
1534
|
verify(
|
|
384
|
-
object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
|
|
1535
|
+
object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput | VerifyJsonWebKeyInput,
|
|
385
1536
|
signature: string,
|
|
386
1537
|
signature_format?: BinaryToTextEncoding,
|
|
387
1538
|
): boolean;
|
|
388
|
-
// https://nodejs.org/api/crypto.html#crypto_verifier_verify_object_signature_signature_format
|
|
389
|
-
// The signature field accepts a TypedArray type, but it is only available starting ES2017
|
|
390
1539
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
1540
|
+
/**
|
|
1541
|
+
* Creates a `DiffieHellman` key exchange object using the supplied `prime` and an
|
|
1542
|
+
* optional specific `generator`.
|
|
1543
|
+
*
|
|
1544
|
+
* The `generator` argument can be a number, string, or `Buffer`. If `generator` is not specified, the value `2` is used.
|
|
1545
|
+
*
|
|
1546
|
+
* If `primeEncoding` is specified, `prime` is expected to be a string; otherwise
|
|
1547
|
+
* a `Buffer`, `TypedArray`, or `DataView` is expected.
|
|
1548
|
+
*
|
|
1549
|
+
* If `generatorEncoding` is specified, `generator` is expected to be a string;
|
|
1550
|
+
* otherwise a number, `Buffer`, `TypedArray`, or `DataView` is expected.
|
|
1551
|
+
* @since v0.11.12
|
|
1552
|
+
* @param primeEncoding The `encoding` of the `prime` string.
|
|
1553
|
+
* @param [generator=2]
|
|
1554
|
+
* @param generatorEncoding The `encoding` of the `generator` string.
|
|
1555
|
+
*/
|
|
1556
|
+
function createDiffieHellman(primeLength: number, generator?: number): DiffieHellman;
|
|
1557
|
+
function createDiffieHellman(
|
|
1558
|
+
prime: ArrayBuffer | NodeJS.ArrayBufferView,
|
|
1559
|
+
generator?: number | ArrayBuffer | NodeJS.ArrayBufferView,
|
|
1560
|
+
): DiffieHellman;
|
|
1561
|
+
function createDiffieHellman(
|
|
1562
|
+
prime: ArrayBuffer | NodeJS.ArrayBufferView,
|
|
1563
|
+
generator: string,
|
|
1564
|
+
generatorEncoding: BinaryToTextEncoding,
|
|
1565
|
+
): DiffieHellman;
|
|
394
1566
|
function createDiffieHellman(
|
|
395
1567
|
prime: string,
|
|
396
|
-
|
|
397
|
-
generator
|
|
1568
|
+
primeEncoding: BinaryToTextEncoding,
|
|
1569
|
+
generator?: number | ArrayBuffer | NodeJS.ArrayBufferView,
|
|
398
1570
|
): DiffieHellman;
|
|
399
1571
|
function createDiffieHellman(
|
|
400
1572
|
prime: string,
|
|
401
|
-
|
|
1573
|
+
primeEncoding: BinaryToTextEncoding,
|
|
402
1574
|
generator: string,
|
|
403
|
-
|
|
1575
|
+
generatorEncoding: BinaryToTextEncoding,
|
|
404
1576
|
): DiffieHellman;
|
|
1577
|
+
/**
|
|
1578
|
+
* The `DiffieHellman` class is a utility for creating Diffie-Hellman key
|
|
1579
|
+
* exchanges.
|
|
1580
|
+
*
|
|
1581
|
+
* Instances of the `DiffieHellman` class can be created using the {@link createDiffieHellman} function.
|
|
1582
|
+
*
|
|
1583
|
+
* ```js
|
|
1584
|
+
* import assert from 'node:assert';
|
|
1585
|
+
*
|
|
1586
|
+
* const {
|
|
1587
|
+
* createDiffieHellman,
|
|
1588
|
+
* } = await import('node:crypto');
|
|
1589
|
+
*
|
|
1590
|
+
* // Generate Alice's keys...
|
|
1591
|
+
* const alice = createDiffieHellman(2048);
|
|
1592
|
+
* const aliceKey = alice.generateKeys();
|
|
1593
|
+
*
|
|
1594
|
+
* // Generate Bob's keys...
|
|
1595
|
+
* const bob = createDiffieHellman(alice.getPrime(), alice.getGenerator());
|
|
1596
|
+
* const bobKey = bob.generateKeys();
|
|
1597
|
+
*
|
|
1598
|
+
* // Exchange and generate the secret...
|
|
1599
|
+
* const aliceSecret = alice.computeSecret(bobKey);
|
|
1600
|
+
* const bobSecret = bob.computeSecret(aliceKey);
|
|
1601
|
+
*
|
|
1602
|
+
* // OK
|
|
1603
|
+
* assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
|
|
1604
|
+
* ```
|
|
1605
|
+
* @since v0.5.0
|
|
1606
|
+
*/
|
|
405
1607
|
class DiffieHellman {
|
|
406
1608
|
private constructor();
|
|
1609
|
+
/**
|
|
1610
|
+
* Generates private and public Diffie-Hellman key values unless they have been
|
|
1611
|
+
* generated or computed already, and returns
|
|
1612
|
+
* the public key in the specified `encoding`. This key should be
|
|
1613
|
+
* transferred to the other party.
|
|
1614
|
+
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
1615
|
+
*
|
|
1616
|
+
* This function is a thin wrapper around [`DH_generate_key()`](https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html). In particular,
|
|
1617
|
+
* once a private key has been generated or set, calling this function only updates
|
|
1618
|
+
* the public key but does not generate a new private key.
|
|
1619
|
+
* @since v0.5.0
|
|
1620
|
+
* @param encoding The `encoding` of the return value.
|
|
1621
|
+
*/
|
|
407
1622
|
generateKeys(): Buffer;
|
|
408
1623
|
generateKeys(encoding: BinaryToTextEncoding): string;
|
|
1624
|
+
/**
|
|
1625
|
+
* Computes the shared secret using `otherPublicKey` as the other
|
|
1626
|
+
* party's public key and returns the computed shared secret. The supplied
|
|
1627
|
+
* key is interpreted using the specified `inputEncoding`, and secret is
|
|
1628
|
+
* encoded using specified `outputEncoding`.
|
|
1629
|
+
* If the `inputEncoding` is not
|
|
1630
|
+
* provided, `otherPublicKey` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1631
|
+
*
|
|
1632
|
+
* If `outputEncoding` is given a string is returned; otherwise, a `Buffer` is returned.
|
|
1633
|
+
* @since v0.5.0
|
|
1634
|
+
* @param inputEncoding The `encoding` of an `otherPublicKey` string.
|
|
1635
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
1636
|
+
*/
|
|
409
1637
|
computeSecret(otherPublicKey: NodeJS.ArrayBufferView, inputEncoding?: null, outputEncoding?: null): Buffer;
|
|
410
1638
|
computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding?: null): Buffer;
|
|
411
1639
|
computeSecret(
|
|
@@ -414,22 +1642,79 @@ declare module "crypto" {
|
|
|
414
1642
|
outputEncoding: BinaryToTextEncoding,
|
|
415
1643
|
): string;
|
|
416
1644
|
computeSecret(
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1645
|
+
otherPublicKey: string,
|
|
1646
|
+
inputEncoding: BinaryToTextEncoding,
|
|
1647
|
+
outputEncoding: BinaryToTextEncoding,
|
|
420
1648
|
): string;
|
|
1649
|
+
/**
|
|
1650
|
+
* Returns the Diffie-Hellman prime in the specified `encoding`.
|
|
1651
|
+
* If `encoding` is provided a string is
|
|
1652
|
+
* returned; otherwise a `Buffer` is returned.
|
|
1653
|
+
* @since v0.5.0
|
|
1654
|
+
* @param encoding The `encoding` of the return value.
|
|
1655
|
+
*/
|
|
421
1656
|
getPrime(): Buffer;
|
|
422
1657
|
getPrime(encoding: BinaryToTextEncoding): string;
|
|
1658
|
+
/**
|
|
1659
|
+
* Returns the Diffie-Hellman generator in the specified `encoding`.
|
|
1660
|
+
* If `encoding` is provided a string is
|
|
1661
|
+
* returned; otherwise a `Buffer` is returned.
|
|
1662
|
+
* @since v0.5.0
|
|
1663
|
+
* @param encoding The `encoding` of the return value.
|
|
1664
|
+
*/
|
|
423
1665
|
getGenerator(): Buffer;
|
|
424
1666
|
getGenerator(encoding: BinaryToTextEncoding): string;
|
|
1667
|
+
/**
|
|
1668
|
+
* Returns the Diffie-Hellman public key in the specified `encoding`.
|
|
1669
|
+
* If `encoding` is provided a
|
|
1670
|
+
* string is returned; otherwise a `Buffer` is returned.
|
|
1671
|
+
* @since v0.5.0
|
|
1672
|
+
* @param encoding The `encoding` of the return value.
|
|
1673
|
+
*/
|
|
425
1674
|
getPublicKey(): Buffer;
|
|
426
1675
|
getPublicKey(encoding: BinaryToTextEncoding): string;
|
|
1676
|
+
/**
|
|
1677
|
+
* Returns the Diffie-Hellman private key in the specified `encoding`.
|
|
1678
|
+
* If `encoding` is provided a
|
|
1679
|
+
* string is returned; otherwise a `Buffer` is returned.
|
|
1680
|
+
* @since v0.5.0
|
|
1681
|
+
* @param encoding The `encoding` of the return value.
|
|
1682
|
+
*/
|
|
427
1683
|
getPrivateKey(): Buffer;
|
|
428
1684
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
1685
|
+
/**
|
|
1686
|
+
* Sets the Diffie-Hellman public key. If the `encoding` argument is provided, `publicKey` is expected
|
|
1687
|
+
* to be a string. If no `encoding` is provided, `publicKey` is expected
|
|
1688
|
+
* to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1689
|
+
* @since v0.5.0
|
|
1690
|
+
* @param encoding The `encoding` of the `publicKey` string.
|
|
1691
|
+
*/
|
|
1692
|
+
setPublicKey(publicKey: NodeJS.ArrayBufferView): void;
|
|
1693
|
+
setPublicKey(publicKey: string, encoding: BufferEncoding): void;
|
|
1694
|
+
/**
|
|
1695
|
+
* Sets the Diffie-Hellman private key. If the `encoding` argument is provided,`privateKey` is expected
|
|
1696
|
+
* to be a string. If no `encoding` is provided, `privateKey` is expected
|
|
1697
|
+
* to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1698
|
+
*
|
|
1699
|
+
* This function does not automatically compute the associated public key. Either `diffieHellman.setPublicKey()` or `diffieHellman.generateKeys()` can be
|
|
1700
|
+
* used to manually provide the public key or to automatically derive it.
|
|
1701
|
+
* @since v0.5.0
|
|
1702
|
+
* @param encoding The `encoding` of the `privateKey` string.
|
|
1703
|
+
*/
|
|
1704
|
+
setPrivateKey(privateKey: NodeJS.ArrayBufferView): void;
|
|
1705
|
+
setPrivateKey(privateKey: string, encoding: BufferEncoding): void;
|
|
1706
|
+
/**
|
|
1707
|
+
* A bit field containing any warnings and/or errors resulting from a check
|
|
1708
|
+
* performed during initialization of the `DiffieHellman` object.
|
|
1709
|
+
*
|
|
1710
|
+
* The following values are valid for this property (as defined in `node:constants` module):
|
|
1711
|
+
*
|
|
1712
|
+
* * `DH_CHECK_P_NOT_SAFE_PRIME`
|
|
1713
|
+
* * `DH_CHECK_P_NOT_PRIME`
|
|
1714
|
+
* * `DH_UNABLE_TO_CHECK_GENERATOR`
|
|
1715
|
+
* * `DH_NOT_SUITABLE_GENERATOR`
|
|
1716
|
+
* @since v0.11.12
|
|
1717
|
+
*/
|
|
433
1718
|
verifyError: number;
|
|
434
1719
|
}
|
|
435
1720
|
/**
|
|
@@ -462,20 +1747,114 @@ declare module "crypto" {
|
|
|
462
1747
|
readonly prototype: DiffieHellmanGroup;
|
|
463
1748
|
}
|
|
464
1749
|
type DiffieHellmanGroup = Omit<DiffieHellman, "setPublicKey" | "setPrivateKey">;
|
|
1750
|
+
/**
|
|
1751
|
+
* Creates a predefined `DiffieHellmanGroup` key exchange object. The
|
|
1752
|
+
* supported groups are listed in the documentation for `DiffieHellmanGroup`.
|
|
1753
|
+
*
|
|
1754
|
+
* The returned object mimics the interface of objects created by {@link createDiffieHellman}, but will not allow changing
|
|
1755
|
+
* the keys (with `diffieHellman.setPublicKey()`, for example). The
|
|
1756
|
+
* advantage of using this method is that the parties do not have to
|
|
1757
|
+
* generate nor exchange a group modulus beforehand, saving both processor
|
|
1758
|
+
* and communication time.
|
|
1759
|
+
*
|
|
1760
|
+
* Example (obtaining a shared secret):
|
|
1761
|
+
*
|
|
1762
|
+
* ```js
|
|
1763
|
+
* const {
|
|
1764
|
+
* getDiffieHellman,
|
|
1765
|
+
* } = await import('node:crypto');
|
|
1766
|
+
* const alice = getDiffieHellman('modp14');
|
|
1767
|
+
* const bob = getDiffieHellman('modp14');
|
|
1768
|
+
*
|
|
1769
|
+
* alice.generateKeys();
|
|
1770
|
+
* bob.generateKeys();
|
|
1771
|
+
*
|
|
1772
|
+
* const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
|
|
1773
|
+
* const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
|
|
1774
|
+
*
|
|
1775
|
+
* // aliceSecret and bobSecret should be the same
|
|
1776
|
+
* console.log(aliceSecret === bobSecret);
|
|
1777
|
+
* ```
|
|
1778
|
+
* @since v0.7.5
|
|
1779
|
+
*/
|
|
465
1780
|
function getDiffieHellman(groupName: string): DiffieHellmanGroup;
|
|
466
1781
|
/**
|
|
467
1782
|
* An alias for {@link getDiffieHellman}
|
|
468
1783
|
* @since v0.9.3
|
|
469
1784
|
*/
|
|
470
1785
|
function createDiffieHellmanGroup(name: string): DiffieHellmanGroup;
|
|
1786
|
+
/**
|
|
1787
|
+
* Provides an asynchronous Password-Based Key Derivation Function 2 (PBKDF2)
|
|
1788
|
+
* implementation. A selected HMAC digest algorithm specified by `digest` is
|
|
1789
|
+
* applied to derive a key of the requested byte length (`keylen`) from the `password`, `salt` and `iterations`.
|
|
1790
|
+
*
|
|
1791
|
+
* The supplied `callback` function is called with two arguments: `err` and `derivedKey`. If an error occurs while deriving the key, `err` will be set;
|
|
1792
|
+
* otherwise `err` will be `null`. By default, the successfully generated `derivedKey` will be passed to the callback as a `Buffer`. An error will be
|
|
1793
|
+
* thrown if any of the input arguments specify invalid values or types.
|
|
1794
|
+
*
|
|
1795
|
+
* The `iterations` argument must be a number set as high as possible. The
|
|
1796
|
+
* higher the number of iterations, the more secure the derived key will be,
|
|
1797
|
+
* but will take a longer amount of time to complete.
|
|
1798
|
+
*
|
|
1799
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
1800
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
1801
|
+
*
|
|
1802
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1803
|
+
*
|
|
1804
|
+
* ```js
|
|
1805
|
+
* const {
|
|
1806
|
+
* pbkdf2,
|
|
1807
|
+
* } = await import('node:crypto');
|
|
1808
|
+
*
|
|
1809
|
+
* pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
|
|
1810
|
+
* if (err) throw err;
|
|
1811
|
+
* console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
|
|
1812
|
+
* });
|
|
1813
|
+
* ```
|
|
1814
|
+
*
|
|
1815
|
+
* An array of supported digest functions can be retrieved using {@link getHashes}.
|
|
1816
|
+
*
|
|
1817
|
+
* This API uses libuv's threadpool, which can have surprising and
|
|
1818
|
+
* negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
|
|
1819
|
+
* @since v0.5.5
|
|
1820
|
+
*/
|
|
471
1821
|
function pbkdf2(
|
|
472
1822
|
password: BinaryLike,
|
|
473
1823
|
salt: BinaryLike,
|
|
474
1824
|
iterations: number,
|
|
475
1825
|
keylen: number,
|
|
476
1826
|
digest: string,
|
|
477
|
-
callback: (err: Error | null, derivedKey: Buffer) =>
|
|
1827
|
+
callback: (err: Error | null, derivedKey: Buffer) => void,
|
|
478
1828
|
): void;
|
|
1829
|
+
/**
|
|
1830
|
+
* Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2)
|
|
1831
|
+
* implementation. A selected HMAC digest algorithm specified by `digest` is
|
|
1832
|
+
* applied to derive a key of the requested byte length (`keylen`) from the `password`, `salt` and `iterations`.
|
|
1833
|
+
*
|
|
1834
|
+
* If an error occurs an `Error` will be thrown, otherwise the derived key will be
|
|
1835
|
+
* returned as a `Buffer`.
|
|
1836
|
+
*
|
|
1837
|
+
* The `iterations` argument must be a number set as high as possible. The
|
|
1838
|
+
* higher the number of iterations, the more secure the derived key will be,
|
|
1839
|
+
* but will take a longer amount of time to complete.
|
|
1840
|
+
*
|
|
1841
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
1842
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
1843
|
+
*
|
|
1844
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1845
|
+
*
|
|
1846
|
+
* ```js
|
|
1847
|
+
* const {
|
|
1848
|
+
* pbkdf2Sync,
|
|
1849
|
+
* } = await import('node:crypto');
|
|
1850
|
+
*
|
|
1851
|
+
* const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
|
|
1852
|
+
* console.log(key.toString('hex')); // '3745e48...08d59ae'
|
|
1853
|
+
* ```
|
|
1854
|
+
*
|
|
1855
|
+
* An array of supported digest functions can be retrieved using {@link getHashes}.
|
|
1856
|
+
* @since v0.9.3
|
|
1857
|
+
*/
|
|
479
1858
|
function pbkdf2Sync(
|
|
480
1859
|
password: BinaryLike,
|
|
481
1860
|
salt: BinaryLike,
|
|
@@ -483,18 +1862,229 @@ declare module "crypto" {
|
|
|
483
1862
|
keylen: number,
|
|
484
1863
|
digest: string,
|
|
485
1864
|
): Buffer;
|
|
486
|
-
|
|
1865
|
+
/**
|
|
1866
|
+
* Generates cryptographically strong pseudorandom data. The `size` argument
|
|
1867
|
+
* is a number indicating the number of bytes to generate.
|
|
1868
|
+
*
|
|
1869
|
+
* If a `callback` function is provided, the bytes are generated asynchronously
|
|
1870
|
+
* and the `callback` function is invoked with two arguments: `err` and `buf`.
|
|
1871
|
+
* If an error occurs, `err` will be an `Error` object; otherwise it is `null`. The `buf` argument is a `Buffer` containing the generated bytes.
|
|
1872
|
+
*
|
|
1873
|
+
* ```js
|
|
1874
|
+
* // Asynchronous
|
|
1875
|
+
* const {
|
|
1876
|
+
* randomBytes,
|
|
1877
|
+
* } = await import('node:crypto');
|
|
1878
|
+
*
|
|
1879
|
+
* randomBytes(256, (err, buf) => {
|
|
1880
|
+
* if (err) throw err;
|
|
1881
|
+
* console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
|
|
1882
|
+
* });
|
|
1883
|
+
* ```
|
|
1884
|
+
*
|
|
1885
|
+
* If the `callback` function is not provided, the random bytes are generated
|
|
1886
|
+
* synchronously and returned as a `Buffer`. An error will be thrown if
|
|
1887
|
+
* there is a problem generating the bytes.
|
|
1888
|
+
*
|
|
1889
|
+
* ```js
|
|
1890
|
+
* // Synchronous
|
|
1891
|
+
* const {
|
|
1892
|
+
* randomBytes,
|
|
1893
|
+
* } = await import('node:crypto');
|
|
1894
|
+
*
|
|
1895
|
+
* const buf = randomBytes(256);
|
|
1896
|
+
* console.log(
|
|
1897
|
+
* `${buf.length} bytes of random data: ${buf.toString('hex')}`);
|
|
1898
|
+
* ```
|
|
1899
|
+
*
|
|
1900
|
+
* The `crypto.randomBytes()` method will not complete until there is
|
|
1901
|
+
* sufficient entropy available.
|
|
1902
|
+
* This should normally never take longer than a few milliseconds. The only time
|
|
1903
|
+
* when generating the random bytes may conceivably block for a longer period of
|
|
1904
|
+
* time is right after boot, when the whole system is still low on entropy.
|
|
1905
|
+
*
|
|
1906
|
+
* This API uses libuv's threadpool, which can have surprising and
|
|
1907
|
+
* negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
|
|
1908
|
+
*
|
|
1909
|
+
* The asynchronous version of `crypto.randomBytes()` is carried out in a single
|
|
1910
|
+
* threadpool request. To minimize threadpool task length variation, partition
|
|
1911
|
+
* large `randomBytes` requests when doing so as part of fulfilling a client
|
|
1912
|
+
* request.
|
|
1913
|
+
* @since v0.5.8
|
|
1914
|
+
* @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`.
|
|
1915
|
+
* @return if the `callback` function is not provided.
|
|
1916
|
+
*/
|
|
487
1917
|
function randomBytes(size: number): Buffer;
|
|
488
1918
|
function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
|
|
489
1919
|
function pseudoRandomBytes(size: number): Buffer;
|
|
490
1920
|
function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
|
|
491
|
-
|
|
1921
|
+
/**
|
|
1922
|
+
* Return a random integer `n` such that `min <= n < max`. This
|
|
1923
|
+
* implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias).
|
|
1924
|
+
*
|
|
1925
|
+
* The range (`max - min`) must be less than 2**48. `min` and `max` must
|
|
1926
|
+
* be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).
|
|
1927
|
+
*
|
|
1928
|
+
* If the `callback` function is not provided, the random integer is
|
|
1929
|
+
* generated synchronously.
|
|
1930
|
+
*
|
|
1931
|
+
* ```js
|
|
1932
|
+
* // Asynchronous
|
|
1933
|
+
* const {
|
|
1934
|
+
* randomInt,
|
|
1935
|
+
* } = await import('node:crypto');
|
|
1936
|
+
*
|
|
1937
|
+
* randomInt(3, (err, n) => {
|
|
1938
|
+
* if (err) throw err;
|
|
1939
|
+
* console.log(`Random number chosen from (0, 1, 2): ${n}`);
|
|
1940
|
+
* });
|
|
1941
|
+
* ```
|
|
1942
|
+
*
|
|
1943
|
+
* ```js
|
|
1944
|
+
* // Synchronous
|
|
1945
|
+
* const {
|
|
1946
|
+
* randomInt,
|
|
1947
|
+
* } = await import('node:crypto');
|
|
1948
|
+
*
|
|
1949
|
+
* const n = randomInt(3);
|
|
1950
|
+
* console.log(`Random number chosen from (0, 1, 2): ${n}`);
|
|
1951
|
+
* ```
|
|
1952
|
+
*
|
|
1953
|
+
* ```js
|
|
1954
|
+
* // With `min` argument
|
|
1955
|
+
* const {
|
|
1956
|
+
* randomInt,
|
|
1957
|
+
* } = await import('node:crypto');
|
|
1958
|
+
*
|
|
1959
|
+
* const n = randomInt(1, 7);
|
|
1960
|
+
* console.log(`The dice rolled: ${n}`);
|
|
1961
|
+
* ```
|
|
1962
|
+
* @since v14.10.0, v12.19.0
|
|
1963
|
+
* @param [min=0] Start of random range (inclusive).
|
|
1964
|
+
* @param max End of random range (exclusive).
|
|
1965
|
+
* @param callback `function(err, n) {}`.
|
|
1966
|
+
*/
|
|
492
1967
|
function randomInt(max: number): number;
|
|
493
1968
|
function randomInt(min: number, max: number): number;
|
|
494
1969
|
function randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
|
|
495
1970
|
function randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
|
|
496
|
-
|
|
1971
|
+
/**
|
|
1972
|
+
* Synchronous version of {@link randomFill}.
|
|
1973
|
+
*
|
|
1974
|
+
* ```js
|
|
1975
|
+
* import { Buffer } from 'node:buffer';
|
|
1976
|
+
* const { randomFillSync } = await import('node:crypto');
|
|
1977
|
+
*
|
|
1978
|
+
* const buf = Buffer.alloc(10);
|
|
1979
|
+
* console.log(randomFillSync(buf).toString('hex'));
|
|
1980
|
+
*
|
|
1981
|
+
* randomFillSync(buf, 5);
|
|
1982
|
+
* console.log(buf.toString('hex'));
|
|
1983
|
+
*
|
|
1984
|
+
* // The above is equivalent to the following:
|
|
1985
|
+
* randomFillSync(buf, 5, 5);
|
|
1986
|
+
* console.log(buf.toString('hex'));
|
|
1987
|
+
* ```
|
|
1988
|
+
*
|
|
1989
|
+
* Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`.
|
|
1990
|
+
*
|
|
1991
|
+
* ```js
|
|
1992
|
+
* import { Buffer } from 'node:buffer';
|
|
1993
|
+
* const { randomFillSync } = await import('node:crypto');
|
|
1994
|
+
*
|
|
1995
|
+
* const a = new Uint32Array(10);
|
|
1996
|
+
* console.log(Buffer.from(randomFillSync(a).buffer,
|
|
1997
|
+
* a.byteOffset, a.byteLength).toString('hex'));
|
|
1998
|
+
*
|
|
1999
|
+
* const b = new DataView(new ArrayBuffer(10));
|
|
2000
|
+
* console.log(Buffer.from(randomFillSync(b).buffer,
|
|
2001
|
+
* b.byteOffset, b.byteLength).toString('hex'));
|
|
2002
|
+
*
|
|
2003
|
+
* const c = new ArrayBuffer(10);
|
|
2004
|
+
* console.log(Buffer.from(randomFillSync(c)).toString('hex'));
|
|
2005
|
+
* ```
|
|
2006
|
+
* @since v7.10.0, v6.13.0
|
|
2007
|
+
* @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
|
|
2008
|
+
* @param [offset=0]
|
|
2009
|
+
* @param [size=buffer.length - offset]
|
|
2010
|
+
* @return The object passed as `buffer` argument.
|
|
2011
|
+
*/
|
|
497
2012
|
function randomFillSync<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number, size?: number): T;
|
|
2013
|
+
/**
|
|
2014
|
+
* This function is similar to {@link randomBytes} but requires the first
|
|
2015
|
+
* argument to be a `Buffer` that will be filled. It also
|
|
2016
|
+
* requires that a callback is passed in.
|
|
2017
|
+
*
|
|
2018
|
+
* If the `callback` function is not provided, an error will be thrown.
|
|
2019
|
+
*
|
|
2020
|
+
* ```js
|
|
2021
|
+
* import { Buffer } from 'node:buffer';
|
|
2022
|
+
* const { randomFill } = await import('node:crypto');
|
|
2023
|
+
*
|
|
2024
|
+
* const buf = Buffer.alloc(10);
|
|
2025
|
+
* randomFill(buf, (err, buf) => {
|
|
2026
|
+
* if (err) throw err;
|
|
2027
|
+
* console.log(buf.toString('hex'));
|
|
2028
|
+
* });
|
|
2029
|
+
*
|
|
2030
|
+
* randomFill(buf, 5, (err, buf) => {
|
|
2031
|
+
* if (err) throw err;
|
|
2032
|
+
* console.log(buf.toString('hex'));
|
|
2033
|
+
* });
|
|
2034
|
+
*
|
|
2035
|
+
* // The above is equivalent to the following:
|
|
2036
|
+
* randomFill(buf, 5, 5, (err, buf) => {
|
|
2037
|
+
* if (err) throw err;
|
|
2038
|
+
* console.log(buf.toString('hex'));
|
|
2039
|
+
* });
|
|
2040
|
+
* ```
|
|
2041
|
+
*
|
|
2042
|
+
* Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`.
|
|
2043
|
+
*
|
|
2044
|
+
* While this includes instances of `Float32Array` and `Float64Array`, this
|
|
2045
|
+
* function should not be used to generate random floating-point numbers. The
|
|
2046
|
+
* result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array
|
|
2047
|
+
* contains finite numbers only, they are not drawn from a uniform random
|
|
2048
|
+
* distribution and have no meaningful lower or upper bounds.
|
|
2049
|
+
*
|
|
2050
|
+
* ```js
|
|
2051
|
+
* import { Buffer } from 'node:buffer';
|
|
2052
|
+
* const { randomFill } = await import('node:crypto');
|
|
2053
|
+
*
|
|
2054
|
+
* const a = new Uint32Array(10);
|
|
2055
|
+
* randomFill(a, (err, buf) => {
|
|
2056
|
+
* if (err) throw err;
|
|
2057
|
+
* console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
|
|
2058
|
+
* .toString('hex'));
|
|
2059
|
+
* });
|
|
2060
|
+
*
|
|
2061
|
+
* const b = new DataView(new ArrayBuffer(10));
|
|
2062
|
+
* randomFill(b, (err, buf) => {
|
|
2063
|
+
* if (err) throw err;
|
|
2064
|
+
* console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
|
|
2065
|
+
* .toString('hex'));
|
|
2066
|
+
* });
|
|
2067
|
+
*
|
|
2068
|
+
* const c = new ArrayBuffer(10);
|
|
2069
|
+
* randomFill(c, (err, buf) => {
|
|
2070
|
+
* if (err) throw err;
|
|
2071
|
+
* console.log(Buffer.from(buf).toString('hex'));
|
|
2072
|
+
* });
|
|
2073
|
+
* ```
|
|
2074
|
+
*
|
|
2075
|
+
* This API uses libuv's threadpool, which can have surprising and
|
|
2076
|
+
* negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
|
|
2077
|
+
*
|
|
2078
|
+
* The asynchronous version of `crypto.randomFill()` is carried out in a single
|
|
2079
|
+
* threadpool request. To minimize threadpool task length variation, partition
|
|
2080
|
+
* large `randomFill` requests when doing so as part of fulfilling a client
|
|
2081
|
+
* request.
|
|
2082
|
+
* @since v7.10.0, v6.13.0
|
|
2083
|
+
* @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
|
|
2084
|
+
* @param [offset=0]
|
|
2085
|
+
* @param [size=buffer.length - offset]
|
|
2086
|
+
* @param callback `function(err, buf) {}`.
|
|
2087
|
+
*/
|
|
498
2088
|
function randomFill<T extends NodeJS.ArrayBufferView>(
|
|
499
2089
|
buffer: T,
|
|
500
2090
|
callback: (err: Error | null, buf: T) => void,
|
|
@@ -510,21 +2100,6 @@ declare module "crypto" {
|
|
|
510
2100
|
size: number,
|
|
511
2101
|
callback: (err: Error | null, buf: T) => void,
|
|
512
2102
|
): void;
|
|
513
|
-
|
|
514
|
-
interface RandomUUIDOptions {
|
|
515
|
-
/**
|
|
516
|
-
* By default, to improve performance,
|
|
517
|
-
* Node.js will pre-emptively generate and persistently cache enough
|
|
518
|
-
* random data to generate up to 128 random UUIDs. To generate a UUID
|
|
519
|
-
* without using the cache, set `disableEntropyCache` to `true`.
|
|
520
|
-
*
|
|
521
|
-
* @default `false`
|
|
522
|
-
*/
|
|
523
|
-
disableEntropyCache?: boolean | undefined;
|
|
524
|
-
}
|
|
525
|
-
type UUID = `${string}-${string}-${string}-${string}-${string}`;
|
|
526
|
-
function randomUUID(options?: RandomUUIDOptions): UUID;
|
|
527
|
-
|
|
528
2103
|
interface ScryptOptions {
|
|
529
2104
|
cost?: number | undefined;
|
|
530
2105
|
blockSize?: number | undefined;
|
|
@@ -534,6 +2109,40 @@ declare module "crypto" {
|
|
|
534
2109
|
p?: number | undefined;
|
|
535
2110
|
maxmem?: number | undefined;
|
|
536
2111
|
}
|
|
2112
|
+
/**
|
|
2113
|
+
* Provides an asynchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
|
|
2114
|
+
* key derivation function that is designed to be expensive computationally and
|
|
2115
|
+
* memory-wise in order to make brute-force attacks unrewarding.
|
|
2116
|
+
*
|
|
2117
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
2118
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
2119
|
+
*
|
|
2120
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
2121
|
+
*
|
|
2122
|
+
* The `callback` function is called with two arguments: `err` and `derivedKey`. `err` is an exception object when key derivation fails, otherwise `err` is `null`. `derivedKey` is passed to the
|
|
2123
|
+
* callback as a `Buffer`.
|
|
2124
|
+
*
|
|
2125
|
+
* An exception is thrown when any of the input arguments specify invalid values
|
|
2126
|
+
* or types.
|
|
2127
|
+
*
|
|
2128
|
+
* ```js
|
|
2129
|
+
* const {
|
|
2130
|
+
* scrypt,
|
|
2131
|
+
* } = await import('node:crypto');
|
|
2132
|
+
*
|
|
2133
|
+
* // Using the factory defaults.
|
|
2134
|
+
* scrypt('password', 'salt', 64, (err, derivedKey) => {
|
|
2135
|
+
* if (err) throw err;
|
|
2136
|
+
* console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
|
|
2137
|
+
* });
|
|
2138
|
+
* // Using a custom N parameter. Must be a power of two.
|
|
2139
|
+
* scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
|
|
2140
|
+
* if (err) throw err;
|
|
2141
|
+
* console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
|
|
2142
|
+
* });
|
|
2143
|
+
* ```
|
|
2144
|
+
* @since v10.5.0
|
|
2145
|
+
*/
|
|
537
2146
|
function scrypt(
|
|
538
2147
|
password: BinaryLike,
|
|
539
2148
|
salt: BinaryLike,
|
|
@@ -547,8 +2156,37 @@ declare module "crypto" {
|
|
|
547
2156
|
options: ScryptOptions,
|
|
548
2157
|
callback: (err: Error | null, derivedKey: Buffer) => void,
|
|
549
2158
|
): void;
|
|
2159
|
+
/**
|
|
2160
|
+
* Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
|
|
2161
|
+
* key derivation function that is designed to be expensive computationally and
|
|
2162
|
+
* memory-wise in order to make brute-force attacks unrewarding.
|
|
2163
|
+
*
|
|
2164
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
2165
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
2166
|
+
*
|
|
2167
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
2168
|
+
*
|
|
2169
|
+
* An exception is thrown when key derivation fails, otherwise the derived key is
|
|
2170
|
+
* returned as a `Buffer`.
|
|
2171
|
+
*
|
|
2172
|
+
* An exception is thrown when any of the input arguments specify invalid values
|
|
2173
|
+
* or types.
|
|
2174
|
+
*
|
|
2175
|
+
* ```js
|
|
2176
|
+
* const {
|
|
2177
|
+
* scryptSync,
|
|
2178
|
+
* } = await import('node:crypto');
|
|
2179
|
+
* // Using the factory defaults.
|
|
2180
|
+
*
|
|
2181
|
+
* const key1 = scryptSync('password', 'salt', 64);
|
|
2182
|
+
* console.log(key1.toString('hex')); // '3745e48...08d59ae'
|
|
2183
|
+
* // Using a custom N parameter. Must be a power of two.
|
|
2184
|
+
* const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
|
|
2185
|
+
* console.log(key2.toString('hex')); // '3745e48...aa39b34'
|
|
2186
|
+
* ```
|
|
2187
|
+
* @since v10.5.0
|
|
2188
|
+
*/
|
|
550
2189
|
function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer;
|
|
551
|
-
|
|
552
2190
|
interface RsaPublicKey {
|
|
553
2191
|
key: KeyLike;
|
|
554
2192
|
padding?: number | undefined;
|
|
@@ -563,22 +2201,170 @@ declare module "crypto" {
|
|
|
563
2201
|
oaepLabel?: NodeJS.TypedArray | undefined;
|
|
564
2202
|
padding?: number | undefined;
|
|
565
2203
|
}
|
|
2204
|
+
/**
|
|
2205
|
+
* Encrypts the content of `buffer` with `key` and returns a new `Buffer` with encrypted content. The returned data can be decrypted using
|
|
2206
|
+
* the corresponding private key, for example using {@link privateDecrypt}.
|
|
2207
|
+
*
|
|
2208
|
+
* If `key` is not a `KeyObject`, this function behaves as if `key` had been passed to {@link createPublicKey}. If it is an
|
|
2209
|
+
* object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`.
|
|
2210
|
+
*
|
|
2211
|
+
* Because RSA public keys can be derived from private keys, a private key may
|
|
2212
|
+
* be passed instead of a public key.
|
|
2213
|
+
* @since v0.11.14
|
|
2214
|
+
*/
|
|
566
2215
|
function publicEncrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
2216
|
+
/**
|
|
2217
|
+
* Decrypts `buffer` with `key`.`buffer` was previously encrypted using
|
|
2218
|
+
* the corresponding private key, for example using {@link privateEncrypt}.
|
|
2219
|
+
*
|
|
2220
|
+
* If `key` is not a `KeyObject`, this function behaves as if `key` had been passed to {@link createPublicKey}. If it is an
|
|
2221
|
+
* object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`.
|
|
2222
|
+
*
|
|
2223
|
+
* Because RSA public keys can be derived from private keys, a private key may
|
|
2224
|
+
* be passed instead of a public key.
|
|
2225
|
+
* @since v1.1.0
|
|
2226
|
+
*/
|
|
567
2227
|
function publicDecrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
568
|
-
|
|
569
|
-
|
|
2228
|
+
/**
|
|
2229
|
+
* Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using
|
|
2230
|
+
* the corresponding public key, for example using {@link publicEncrypt}.
|
|
2231
|
+
*
|
|
2232
|
+
* If `privateKey` is not a `KeyObject`, this function behaves as if `privateKey` had been passed to {@link createPrivateKey}. If it is an
|
|
2233
|
+
* object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`.
|
|
2234
|
+
* @since v0.11.14
|
|
2235
|
+
*/
|
|
2236
|
+
function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
2237
|
+
/**
|
|
2238
|
+
* Encrypts `buffer` with `privateKey`. The returned data can be decrypted using
|
|
2239
|
+
* the corresponding public key, for example using {@link publicDecrypt}.
|
|
2240
|
+
*
|
|
2241
|
+
* If `privateKey` is not a `KeyObject`, this function behaves as if `privateKey` had been passed to {@link createPrivateKey}. If it is an
|
|
2242
|
+
* object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`.
|
|
2243
|
+
* @since v1.1.0
|
|
2244
|
+
*/
|
|
2245
|
+
function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
2246
|
+
/**
|
|
2247
|
+
* ```js
|
|
2248
|
+
* const {
|
|
2249
|
+
* getCiphers,
|
|
2250
|
+
* } = await import('node:crypto');
|
|
2251
|
+
*
|
|
2252
|
+
* console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
|
|
2253
|
+
* ```
|
|
2254
|
+
* @since v0.9.3
|
|
2255
|
+
* @return An array with the names of the supported cipher algorithms.
|
|
2256
|
+
*/
|
|
570
2257
|
function getCiphers(): string[];
|
|
2258
|
+
/**
|
|
2259
|
+
* ```js
|
|
2260
|
+
* const {
|
|
2261
|
+
* getCurves,
|
|
2262
|
+
* } = await import('node:crypto');
|
|
2263
|
+
*
|
|
2264
|
+
* console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
|
|
2265
|
+
* ```
|
|
2266
|
+
* @since v2.3.0
|
|
2267
|
+
* @return An array with the names of the supported elliptic curves.
|
|
2268
|
+
*/
|
|
571
2269
|
function getCurves(): string[];
|
|
2270
|
+
/**
|
|
2271
|
+
* @since v10.0.0
|
|
2272
|
+
* @return `1` if and only if a FIPS compliant crypto provider is currently in use, `0` otherwise. A future semver-major release may change the return type of this API to a {boolean}.
|
|
2273
|
+
*/
|
|
572
2274
|
function getFips(): 1 | 0;
|
|
573
2275
|
/**
|
|
574
|
-
* Enables the FIPS compliant crypto provider in a FIPS-enabled Node.js build.
|
|
2276
|
+
* Enables the FIPS compliant crypto provider in a FIPS-enabled Node.js build.
|
|
2277
|
+
* Throws an error if FIPS mode is not available.
|
|
575
2278
|
* @since v10.0.0
|
|
576
2279
|
* @param bool `true` to enable FIPS mode.
|
|
577
2280
|
*/
|
|
578
2281
|
function setFips(bool: boolean): void;
|
|
2282
|
+
/**
|
|
2283
|
+
* ```js
|
|
2284
|
+
* const {
|
|
2285
|
+
* getHashes,
|
|
2286
|
+
* } = await import('node:crypto');
|
|
2287
|
+
*
|
|
2288
|
+
* console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
|
|
2289
|
+
* ```
|
|
2290
|
+
* @since v0.9.3
|
|
2291
|
+
* @return An array of the names of the supported hash algorithms, such as `'RSA-SHA256'`. Hash algorithms are also called "digest" algorithms.
|
|
2292
|
+
*/
|
|
579
2293
|
function getHashes(): string[];
|
|
2294
|
+
/**
|
|
2295
|
+
* The `ECDH` class is a utility for creating Elliptic Curve Diffie-Hellman (ECDH)
|
|
2296
|
+
* key exchanges.
|
|
2297
|
+
*
|
|
2298
|
+
* Instances of the `ECDH` class can be created using the {@link createECDH} function.
|
|
2299
|
+
*
|
|
2300
|
+
* ```js
|
|
2301
|
+
* import assert from 'node:assert';
|
|
2302
|
+
*
|
|
2303
|
+
* const {
|
|
2304
|
+
* createECDH,
|
|
2305
|
+
* } = await import('node:crypto');
|
|
2306
|
+
*
|
|
2307
|
+
* // Generate Alice's keys...
|
|
2308
|
+
* const alice = createECDH('secp521r1');
|
|
2309
|
+
* const aliceKey = alice.generateKeys();
|
|
2310
|
+
*
|
|
2311
|
+
* // Generate Bob's keys...
|
|
2312
|
+
* const bob = createECDH('secp521r1');
|
|
2313
|
+
* const bobKey = bob.generateKeys();
|
|
2314
|
+
*
|
|
2315
|
+
* // Exchange and generate the secret...
|
|
2316
|
+
* const aliceSecret = alice.computeSecret(bobKey);
|
|
2317
|
+
* const bobSecret = bob.computeSecret(aliceKey);
|
|
2318
|
+
*
|
|
2319
|
+
* assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
|
|
2320
|
+
* // OK
|
|
2321
|
+
* ```
|
|
2322
|
+
* @since v0.11.14
|
|
2323
|
+
*/
|
|
580
2324
|
class ECDH {
|
|
581
2325
|
private constructor();
|
|
2326
|
+
/**
|
|
2327
|
+
* Converts the EC Diffie-Hellman public key specified by `key` and `curve` to the
|
|
2328
|
+
* format specified by `format`. The `format` argument specifies point encoding
|
|
2329
|
+
* and can be `'compressed'`, `'uncompressed'` or `'hybrid'`. The supplied key is
|
|
2330
|
+
* interpreted using the specified `inputEncoding`, and the returned key is encoded
|
|
2331
|
+
* using the specified `outputEncoding`.
|
|
2332
|
+
*
|
|
2333
|
+
* Use {@link getCurves} to obtain a list of available curve names.
|
|
2334
|
+
* On recent OpenSSL releases, `openssl ecparam -list_curves` will also display
|
|
2335
|
+
* the name and description of each available elliptic curve.
|
|
2336
|
+
*
|
|
2337
|
+
* If `format` is not specified the point will be returned in `'uncompressed'` format.
|
|
2338
|
+
*
|
|
2339
|
+
* If the `inputEncoding` is not provided, `key` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
2340
|
+
*
|
|
2341
|
+
* Example (uncompressing a key):
|
|
2342
|
+
*
|
|
2343
|
+
* ```js
|
|
2344
|
+
* const {
|
|
2345
|
+
* createECDH,
|
|
2346
|
+
* ECDH,
|
|
2347
|
+
* } = await import('node:crypto');
|
|
2348
|
+
*
|
|
2349
|
+
* const ecdh = createECDH('secp256k1');
|
|
2350
|
+
* ecdh.generateKeys();
|
|
2351
|
+
*
|
|
2352
|
+
* const compressedKey = ecdh.getPublicKey('hex', 'compressed');
|
|
2353
|
+
*
|
|
2354
|
+
* const uncompressedKey = ECDH.convertKey(compressedKey,
|
|
2355
|
+
* 'secp256k1',
|
|
2356
|
+
* 'hex',
|
|
2357
|
+
* 'hex',
|
|
2358
|
+
* 'uncompressed');
|
|
2359
|
+
*
|
|
2360
|
+
* // The converted key and the uncompressed public key should be the same
|
|
2361
|
+
* console.log(uncompressedKey === ecdh.getPublicKey('hex'));
|
|
2362
|
+
* ```
|
|
2363
|
+
* @since v10.0.0
|
|
2364
|
+
* @param inputEncoding The `encoding` of the `key` string.
|
|
2365
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
2366
|
+
* @param [format='uncompressed']
|
|
2367
|
+
*/
|
|
582
2368
|
static convertKey(
|
|
583
2369
|
key: BinaryLike,
|
|
584
2370
|
curve: string,
|
|
@@ -586,107 +2372,193 @@ declare module "crypto" {
|
|
|
586
2372
|
outputEncoding?: "latin1" | "hex" | "base64" | "base64url",
|
|
587
2373
|
format?: "uncompressed" | "compressed" | "hybrid",
|
|
588
2374
|
): Buffer | string;
|
|
2375
|
+
/**
|
|
2376
|
+
* Generates private and public EC Diffie-Hellman key values, and returns
|
|
2377
|
+
* the public key in the specified `format` and `encoding`. This key should be
|
|
2378
|
+
* transferred to the other party.
|
|
2379
|
+
*
|
|
2380
|
+
* The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified, the point will be returned in`'uncompressed'` format.
|
|
2381
|
+
*
|
|
2382
|
+
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
2383
|
+
* @since v0.11.14
|
|
2384
|
+
* @param encoding The `encoding` of the return value.
|
|
2385
|
+
* @param [format='uncompressed']
|
|
2386
|
+
*/
|
|
589
2387
|
generateKeys(): Buffer;
|
|
590
2388
|
generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
2389
|
+
/**
|
|
2390
|
+
* Computes the shared secret using `otherPublicKey` as the other
|
|
2391
|
+
* party's public key and returns the computed shared secret. The supplied
|
|
2392
|
+
* key is interpreted using specified `inputEncoding`, and the returned secret
|
|
2393
|
+
* is encoded using the specified `outputEncoding`.
|
|
2394
|
+
* If the `inputEncoding` is not
|
|
2395
|
+
* provided, `otherPublicKey` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
2396
|
+
*
|
|
2397
|
+
* If `outputEncoding` is given a string will be returned; otherwise a `Buffer` is returned.
|
|
2398
|
+
*
|
|
2399
|
+
* `ecdh.computeSecret` will throw an`ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY` error when `otherPublicKey` lies outside of the elliptic curve. Since `otherPublicKey` is
|
|
2400
|
+
* usually supplied from a remote user over an insecure network,
|
|
2401
|
+
* be sure to handle this exception accordingly.
|
|
2402
|
+
* @since v0.11.14
|
|
2403
|
+
* @param inputEncoding The `encoding` of the `otherPublicKey` string.
|
|
2404
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
2405
|
+
*/
|
|
2406
|
+
computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer;
|
|
2407
|
+
computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer;
|
|
2408
|
+
computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string;
|
|
594
2409
|
computeSecret(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
2410
|
+
otherPublicKey: string,
|
|
2411
|
+
inputEncoding: BinaryToTextEncoding,
|
|
2412
|
+
outputEncoding: BinaryToTextEncoding,
|
|
598
2413
|
): string;
|
|
2414
|
+
/**
|
|
2415
|
+
* If `encoding` is specified, a string is returned; otherwise a `Buffer` is
|
|
2416
|
+
* returned.
|
|
2417
|
+
* @since v0.11.14
|
|
2418
|
+
* @param encoding The `encoding` of the return value.
|
|
2419
|
+
* @return The EC Diffie-Hellman in the specified `encoding`.
|
|
2420
|
+
*/
|
|
599
2421
|
getPrivateKey(): Buffer;
|
|
600
2422
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
|
601
|
-
|
|
2423
|
+
/**
|
|
2424
|
+
* The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified the point will be returned in`'uncompressed'` format.
|
|
2425
|
+
*
|
|
2426
|
+
* If `encoding` is specified, a string is returned; otherwise a `Buffer` is
|
|
2427
|
+
* returned.
|
|
2428
|
+
* @since v0.11.14
|
|
2429
|
+
* @param encoding The `encoding` of the return value.
|
|
2430
|
+
* @param [format='uncompressed']
|
|
2431
|
+
* @return The EC Diffie-Hellman public key in the specified `encoding` and `format`.
|
|
2432
|
+
*/
|
|
2433
|
+
getPublicKey(encoding?: null, format?: ECDHKeyFormat): Buffer;
|
|
602
2434
|
getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
|
|
603
|
-
|
|
604
|
-
|
|
2435
|
+
/**
|
|
2436
|
+
* Sets the EC Diffie-Hellman private key.
|
|
2437
|
+
* If `encoding` is provided, `privateKey` is expected
|
|
2438
|
+
* to be a string; otherwise `privateKey` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
2439
|
+
*
|
|
2440
|
+
* If `privateKey` is not valid for the curve specified when the `ECDH` object was
|
|
2441
|
+
* created, an error is thrown. Upon setting the private key, the associated
|
|
2442
|
+
* public point (key) is also generated and set in the `ECDH` object.
|
|
2443
|
+
* @since v0.11.14
|
|
2444
|
+
* @param encoding The `encoding` of the `privateKey` string.
|
|
2445
|
+
*/
|
|
2446
|
+
setPrivateKey(privateKey: NodeJS.ArrayBufferView): void;
|
|
2447
|
+
setPrivateKey(privateKey: string, encoding: BinaryToTextEncoding): void;
|
|
605
2448
|
}
|
|
606
|
-
|
|
2449
|
+
/**
|
|
2450
|
+
* Creates an Elliptic Curve Diffie-Hellman (`ECDH`) key exchange object using a
|
|
2451
|
+
* predefined curve specified by the `curveName` string. Use {@link getCurves} to obtain a list of available curve names. On recent
|
|
2452
|
+
* OpenSSL releases, `openssl ecparam -list_curves` will also display the name
|
|
2453
|
+
* and description of each available elliptic curve.
|
|
2454
|
+
* @since v0.11.14
|
|
2455
|
+
*/
|
|
2456
|
+
function createECDH(curveName: string): ECDH;
|
|
2457
|
+
/**
|
|
2458
|
+
* This function compares the underlying bytes that represent the given `ArrayBuffer`, `TypedArray`, or `DataView` instances using a constant-time
|
|
2459
|
+
* algorithm.
|
|
2460
|
+
*
|
|
2461
|
+
* This function does not leak timing information that
|
|
2462
|
+
* would allow an attacker to guess one of the values. This is suitable for
|
|
2463
|
+
* comparing HMAC digests or secret values like authentication cookies or [capability urls](https://www.w3.org/TR/capability-urls/).
|
|
2464
|
+
*
|
|
2465
|
+
* `a` and `b` must both be `Buffer`s, `TypedArray`s, or `DataView`s, and they
|
|
2466
|
+
* must have the same byte length. An error is thrown if `a` and `b` have
|
|
2467
|
+
* different byte lengths.
|
|
2468
|
+
*
|
|
2469
|
+
* If at least one of `a` and `b` is a `TypedArray` with more than one byte per
|
|
2470
|
+
* entry, such as `Uint16Array`, the result will be computed using the platform
|
|
2471
|
+
* byte order.
|
|
2472
|
+
*
|
|
2473
|
+
* **When both of the inputs are `Float32Array`s or `Float64Array`s, this function might return unexpected results due to IEEE 754**
|
|
2474
|
+
* **encoding of floating-point numbers. In particular, neither `x === y` nor `Object.is(x, y)` implies that the byte representations of two floating-point**
|
|
2475
|
+
* **numbers `x` and `y` are equal.**
|
|
2476
|
+
*
|
|
2477
|
+
* Use of `crypto.timingSafeEqual` does not guarantee that the _surrounding_ code
|
|
2478
|
+
* is timing-safe. Care should be taken to ensure that the surrounding code does
|
|
2479
|
+
* not introduce timing vulnerabilities.
|
|
2480
|
+
* @since v6.6.0
|
|
2481
|
+
*/
|
|
607
2482
|
function timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
type KeyType = "rsa" | "dsa" | "ec" | "ed25519" | "ed448" | "x25519" | "x448";
|
|
612
|
-
type KeyFormat = "pem" | "der";
|
|
613
|
-
|
|
2483
|
+
type KeyType = "rsa" | "rsa-pss" | "dsa" | "ec" | "ed25519" | "ed448" | "x25519" | "x448";
|
|
2484
|
+
type KeyFormat = "pem" | "der" | "jwk";
|
|
614
2485
|
interface BasePrivateKeyEncodingOptions<T extends KeyFormat> {
|
|
615
2486
|
format: T;
|
|
616
2487
|
cipher?: string | undefined;
|
|
617
2488
|
passphrase?: string | undefined;
|
|
618
2489
|
}
|
|
619
|
-
|
|
620
2490
|
interface KeyPairKeyObjectResult {
|
|
621
2491
|
publicKey: KeyObject;
|
|
622
2492
|
privateKey: KeyObject;
|
|
623
2493
|
}
|
|
624
|
-
|
|
625
|
-
interface
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
interface ED448KeyPairKeyObjectOptions {
|
|
2494
|
+
interface ED25519KeyPairKeyObjectOptions {}
|
|
2495
|
+
interface ED448KeyPairKeyObjectOptions {}
|
|
2496
|
+
interface X25519KeyPairKeyObjectOptions {}
|
|
2497
|
+
interface X448KeyPairKeyObjectOptions {}
|
|
2498
|
+
interface ECKeyPairKeyObjectOptions {
|
|
632
2499
|
/**
|
|
633
|
-
*
|
|
2500
|
+
* Name of the curve to use
|
|
634
2501
|
*/
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
interface X25519KeyPairKeyObjectOptions {
|
|
2502
|
+
namedCurve: string;
|
|
638
2503
|
/**
|
|
639
|
-
*
|
|
2504
|
+
* Must be `'named'` or `'explicit'`. Default: `'named'`.
|
|
640
2505
|
*/
|
|
2506
|
+
paramEncoding?: "explicit" | "named" | undefined;
|
|
641
2507
|
}
|
|
642
|
-
|
|
643
|
-
interface X448KeyPairKeyObjectOptions {
|
|
2508
|
+
interface RSAKeyPairKeyObjectOptions {
|
|
644
2509
|
/**
|
|
645
|
-
*
|
|
2510
|
+
* Key size in bits
|
|
646
2511
|
*/
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
interface ECKeyPairKeyObjectOptions {
|
|
2512
|
+
modulusLength: number;
|
|
650
2513
|
/**
|
|
651
|
-
*
|
|
2514
|
+
* Public exponent
|
|
2515
|
+
* @default 0x10001
|
|
652
2516
|
*/
|
|
653
|
-
|
|
2517
|
+
publicExponent?: number | undefined;
|
|
654
2518
|
}
|
|
655
|
-
|
|
656
|
-
interface RSAKeyPairKeyObjectOptions {
|
|
2519
|
+
interface RSAPSSKeyPairKeyObjectOptions {
|
|
657
2520
|
/**
|
|
658
2521
|
* Key size in bits
|
|
659
2522
|
*/
|
|
660
2523
|
modulusLength: number;
|
|
661
|
-
|
|
662
2524
|
/**
|
|
2525
|
+
* Public exponent
|
|
663
2526
|
* @default 0x10001
|
|
664
2527
|
*/
|
|
665
2528
|
publicExponent?: number | undefined;
|
|
2529
|
+
/**
|
|
2530
|
+
* Name of the message digest
|
|
2531
|
+
*/
|
|
2532
|
+
hashAlgorithm?: string;
|
|
2533
|
+
/**
|
|
2534
|
+
* Name of the message digest used by MGF1
|
|
2535
|
+
*/
|
|
2536
|
+
mgf1HashAlgorithm?: string;
|
|
2537
|
+
/**
|
|
2538
|
+
* Minimal salt length in bytes
|
|
2539
|
+
*/
|
|
2540
|
+
saltLength?: string;
|
|
666
2541
|
}
|
|
667
|
-
|
|
668
2542
|
interface DSAKeyPairKeyObjectOptions {
|
|
669
2543
|
/**
|
|
670
2544
|
* Key size in bits
|
|
671
2545
|
*/
|
|
672
2546
|
modulusLength: number;
|
|
673
|
-
|
|
674
2547
|
/**
|
|
675
2548
|
* Size of q in bits
|
|
676
2549
|
*/
|
|
677
2550
|
divisorLength: number;
|
|
678
2551
|
}
|
|
679
|
-
|
|
680
2552
|
interface RSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
681
2553
|
/**
|
|
682
2554
|
* Key size in bits
|
|
683
2555
|
*/
|
|
684
2556
|
modulusLength: number;
|
|
685
2557
|
/**
|
|
2558
|
+
* Public exponent
|
|
686
2559
|
* @default 0x10001
|
|
687
2560
|
*/
|
|
688
2561
|
publicExponent?: number | undefined;
|
|
689
|
-
|
|
690
2562
|
publicKeyEncoding: {
|
|
691
2563
|
type: "pkcs1" | "spki";
|
|
692
2564
|
format: PubF;
|
|
@@ -695,7 +2567,36 @@ declare module "crypto" {
|
|
|
695
2567
|
type: "pkcs1" | "pkcs8";
|
|
696
2568
|
};
|
|
697
2569
|
}
|
|
698
|
-
|
|
2570
|
+
interface RSAPSSKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
2571
|
+
/**
|
|
2572
|
+
* Key size in bits
|
|
2573
|
+
*/
|
|
2574
|
+
modulusLength: number;
|
|
2575
|
+
/**
|
|
2576
|
+
* Public exponent
|
|
2577
|
+
* @default 0x10001
|
|
2578
|
+
*/
|
|
2579
|
+
publicExponent?: number | undefined;
|
|
2580
|
+
/**
|
|
2581
|
+
* Name of the message digest
|
|
2582
|
+
*/
|
|
2583
|
+
hashAlgorithm?: string;
|
|
2584
|
+
/**
|
|
2585
|
+
* Name of the message digest used by MGF1
|
|
2586
|
+
*/
|
|
2587
|
+
mgf1HashAlgorithm?: string;
|
|
2588
|
+
/**
|
|
2589
|
+
* Minimal salt length in bytes
|
|
2590
|
+
*/
|
|
2591
|
+
saltLength?: string;
|
|
2592
|
+
publicKeyEncoding: {
|
|
2593
|
+
type: "spki";
|
|
2594
|
+
format: PubF;
|
|
2595
|
+
};
|
|
2596
|
+
privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
|
|
2597
|
+
type: "pkcs8";
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
699
2600
|
interface DSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
700
2601
|
/**
|
|
701
2602
|
* Key size in bits
|
|
@@ -705,7 +2606,6 @@ declare module "crypto" {
|
|
|
705
2606
|
* Size of q in bits
|
|
706
2607
|
*/
|
|
707
2608
|
divisorLength: number;
|
|
708
|
-
|
|
709
2609
|
publicKeyEncoding: {
|
|
710
2610
|
type: "spki";
|
|
711
2611
|
format: PubF;
|
|
@@ -714,13 +2614,7 @@ declare module "crypto" {
|
|
|
714
2614
|
type: "pkcs8";
|
|
715
2615
|
};
|
|
716
2616
|
}
|
|
717
|
-
|
|
718
|
-
interface ECKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
719
|
-
/**
|
|
720
|
-
* Name of the curve to use.
|
|
721
|
-
*/
|
|
722
|
-
namedCurve: string;
|
|
723
|
-
|
|
2617
|
+
interface ECKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> extends ECKeyPairKeyObjectOptions {
|
|
724
2618
|
publicKeyEncoding: {
|
|
725
2619
|
type: "pkcs1" | "spki";
|
|
726
2620
|
format: PubF;
|
|
@@ -729,7 +2623,6 @@ declare module "crypto" {
|
|
|
729
2623
|
type: "sec1" | "pkcs8";
|
|
730
2624
|
};
|
|
731
2625
|
}
|
|
732
|
-
|
|
733
2626
|
interface ED25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
734
2627
|
publicKeyEncoding: {
|
|
735
2628
|
type: "spki";
|
|
@@ -739,7 +2632,6 @@ declare module "crypto" {
|
|
|
739
2632
|
type: "pkcs8";
|
|
740
2633
|
};
|
|
741
2634
|
}
|
|
742
|
-
|
|
743
2635
|
interface ED448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
744
2636
|
publicKeyEncoding: {
|
|
745
2637
|
type: "spki";
|
|
@@ -749,7 +2641,6 @@ declare module "crypto" {
|
|
|
749
2641
|
type: "pkcs8";
|
|
750
2642
|
};
|
|
751
2643
|
}
|
|
752
|
-
|
|
753
2644
|
interface X25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
754
2645
|
publicKeyEncoding: {
|
|
755
2646
|
type: "spki";
|
|
@@ -759,7 +2650,6 @@ declare module "crypto" {
|
|
|
759
2650
|
type: "pkcs8";
|
|
760
2651
|
};
|
|
761
2652
|
}
|
|
762
|
-
|
|
763
2653
|
interface X448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
764
2654
|
publicKeyEncoding: {
|
|
765
2655
|
type: "spki";
|
|
@@ -769,12 +2659,51 @@ declare module "crypto" {
|
|
|
769
2659
|
type: "pkcs8";
|
|
770
2660
|
};
|
|
771
2661
|
}
|
|
772
|
-
|
|
773
2662
|
interface KeyPairSyncResult<T1 extends string | Buffer, T2 extends string | Buffer> {
|
|
774
2663
|
publicKey: T1;
|
|
775
2664
|
privateKey: T2;
|
|
776
2665
|
}
|
|
777
|
-
|
|
2666
|
+
/**
|
|
2667
|
+
* Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC,
|
|
2668
|
+
* Ed25519, Ed448, X25519, X448, and DH are currently supported.
|
|
2669
|
+
*
|
|
2670
|
+
* If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
|
|
2671
|
+
* behaves as if `keyObject.export()` had been called on its result. Otherwise,
|
|
2672
|
+
* the respective part of the key is returned as a `KeyObject`.
|
|
2673
|
+
*
|
|
2674
|
+
* When encoding public keys, it is recommended to use `'spki'`. When encoding
|
|
2675
|
+
* private keys, it is recommended to use `'pkcs8'` with a strong passphrase,
|
|
2676
|
+
* and to keep the passphrase confidential.
|
|
2677
|
+
*
|
|
2678
|
+
* ```js
|
|
2679
|
+
* const {
|
|
2680
|
+
* generateKeyPairSync,
|
|
2681
|
+
* } = await import('node:crypto');
|
|
2682
|
+
*
|
|
2683
|
+
* const {
|
|
2684
|
+
* publicKey,
|
|
2685
|
+
* privateKey,
|
|
2686
|
+
* } = generateKeyPairSync('rsa', {
|
|
2687
|
+
* modulusLength: 4096,
|
|
2688
|
+
* publicKeyEncoding: {
|
|
2689
|
+
* type: 'spki',
|
|
2690
|
+
* format: 'pem',
|
|
2691
|
+
* },
|
|
2692
|
+
* privateKeyEncoding: {
|
|
2693
|
+
* type: 'pkcs8',
|
|
2694
|
+
* format: 'pem',
|
|
2695
|
+
* cipher: 'aes-256-cbc',
|
|
2696
|
+
* passphrase: 'top secret',
|
|
2697
|
+
* },
|
|
2698
|
+
* });
|
|
2699
|
+
* ```
|
|
2700
|
+
*
|
|
2701
|
+
* The return value `{ publicKey, privateKey }` represents the generated key pair.
|
|
2702
|
+
* When PEM encoding was selected, the respective key will be a string, otherwise
|
|
2703
|
+
* it will be a buffer containing the data encoded as DER.
|
|
2704
|
+
* @since v10.12.0
|
|
2705
|
+
* @param type Must be `'rsa'`, `'rsa-pss'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'`, `'x448'`, or `'dh'`.
|
|
2706
|
+
*/
|
|
778
2707
|
function generateKeyPairSync(
|
|
779
2708
|
type: "rsa",
|
|
780
2709
|
options: RSAKeyPairOptions<"pem", "pem">,
|
|
@@ -792,7 +2721,23 @@ declare module "crypto" {
|
|
|
792
2721
|
options: RSAKeyPairOptions<"der", "der">,
|
|
793
2722
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
794
2723
|
function generateKeyPairSync(type: "rsa", options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
795
|
-
|
|
2724
|
+
function generateKeyPairSync(
|
|
2725
|
+
type: "rsa-pss",
|
|
2726
|
+
options: RSAPSSKeyPairOptions<"pem", "pem">,
|
|
2727
|
+
): KeyPairSyncResult<string, string>;
|
|
2728
|
+
function generateKeyPairSync(
|
|
2729
|
+
type: "rsa-pss",
|
|
2730
|
+
options: RSAPSSKeyPairOptions<"pem", "der">,
|
|
2731
|
+
): KeyPairSyncResult<string, Buffer>;
|
|
2732
|
+
function generateKeyPairSync(
|
|
2733
|
+
type: "rsa-pss",
|
|
2734
|
+
options: RSAPSSKeyPairOptions<"der", "pem">,
|
|
2735
|
+
): KeyPairSyncResult<Buffer, string>;
|
|
2736
|
+
function generateKeyPairSync(
|
|
2737
|
+
type: "rsa-pss",
|
|
2738
|
+
options: RSAPSSKeyPairOptions<"der", "der">,
|
|
2739
|
+
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2740
|
+
function generateKeyPairSync(type: "rsa-pss", options: RSAPSSKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
796
2741
|
function generateKeyPairSync(
|
|
797
2742
|
type: "dsa",
|
|
798
2743
|
options: DSAKeyPairOptions<"pem", "pem">,
|
|
@@ -810,7 +2755,6 @@ declare module "crypto" {
|
|
|
810
2755
|
options: DSAKeyPairOptions<"der", "der">,
|
|
811
2756
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
812
2757
|
function generateKeyPairSync(type: "dsa", options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
813
|
-
|
|
814
2758
|
function generateKeyPairSync(
|
|
815
2759
|
type: "ec",
|
|
816
2760
|
options: ECKeyPairOptions<"pem", "pem">,
|
|
@@ -828,7 +2772,6 @@ declare module "crypto" {
|
|
|
828
2772
|
options: ECKeyPairOptions<"der", "der">,
|
|
829
2773
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
830
2774
|
function generateKeyPairSync(type: "ec", options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
831
|
-
|
|
832
2775
|
function generateKeyPairSync(
|
|
833
2776
|
type: "ed25519",
|
|
834
2777
|
options: ED25519KeyPairOptions<"pem", "pem">,
|
|
@@ -846,7 +2789,6 @@ declare module "crypto" {
|
|
|
846
2789
|
options: ED25519KeyPairOptions<"der", "der">,
|
|
847
2790
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
848
2791
|
function generateKeyPairSync(type: "ed25519", options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
849
|
-
|
|
850
2792
|
function generateKeyPairSync(
|
|
851
2793
|
type: "ed448",
|
|
852
2794
|
options: ED448KeyPairOptions<"pem", "pem">,
|
|
@@ -864,7 +2806,6 @@ declare module "crypto" {
|
|
|
864
2806
|
options: ED448KeyPairOptions<"der", "der">,
|
|
865
2807
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
866
2808
|
function generateKeyPairSync(type: "ed448", options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
867
|
-
|
|
868
2809
|
function generateKeyPairSync(
|
|
869
2810
|
type: "x25519",
|
|
870
2811
|
options: X25519KeyPairOptions<"pem", "pem">,
|
|
@@ -882,7 +2823,6 @@ declare module "crypto" {
|
|
|
882
2823
|
options: X25519KeyPairOptions<"der", "der">,
|
|
883
2824
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
884
2825
|
function generateKeyPairSync(type: "x25519", options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
885
|
-
|
|
886
2826
|
function generateKeyPairSync(
|
|
887
2827
|
type: "x448",
|
|
888
2828
|
options: X448KeyPairOptions<"pem", "pem">,
|
|
@@ -900,7 +2840,45 @@ declare module "crypto" {
|
|
|
900
2840
|
options: X448KeyPairOptions<"der", "der">,
|
|
901
2841
|
): KeyPairSyncResult<Buffer, Buffer>;
|
|
902
2842
|
function generateKeyPairSync(type: "x448", options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
903
|
-
|
|
2843
|
+
/**
|
|
2844
|
+
* Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC,
|
|
2845
|
+
* Ed25519, Ed448, X25519, X448, and DH are currently supported.
|
|
2846
|
+
*
|
|
2847
|
+
* If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
|
|
2848
|
+
* behaves as if `keyObject.export()` had been called on its result. Otherwise,
|
|
2849
|
+
* the respective part of the key is returned as a `KeyObject`.
|
|
2850
|
+
*
|
|
2851
|
+
* It is recommended to encode public keys as `'spki'` and private keys as `'pkcs8'` with encryption for long-term storage:
|
|
2852
|
+
*
|
|
2853
|
+
* ```js
|
|
2854
|
+
* const {
|
|
2855
|
+
* generateKeyPair,
|
|
2856
|
+
* } = await import('node:crypto');
|
|
2857
|
+
*
|
|
2858
|
+
* generateKeyPair('rsa', {
|
|
2859
|
+
* modulusLength: 4096,
|
|
2860
|
+
* publicKeyEncoding: {
|
|
2861
|
+
* type: 'spki',
|
|
2862
|
+
* format: 'pem',
|
|
2863
|
+
* },
|
|
2864
|
+
* privateKeyEncoding: {
|
|
2865
|
+
* type: 'pkcs8',
|
|
2866
|
+
* format: 'pem',
|
|
2867
|
+
* cipher: 'aes-256-cbc',
|
|
2868
|
+
* passphrase: 'top secret',
|
|
2869
|
+
* },
|
|
2870
|
+
* }, (err, publicKey, privateKey) => {
|
|
2871
|
+
* // Handle errors and use the generated key pair.
|
|
2872
|
+
* });
|
|
2873
|
+
* ```
|
|
2874
|
+
*
|
|
2875
|
+
* On completion, `callback` will be called with `err` set to `undefined` and `publicKey` / `privateKey` representing the generated key pair.
|
|
2876
|
+
*
|
|
2877
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
2878
|
+
* a `Promise` for an `Object` with `publicKey` and `privateKey` properties.
|
|
2879
|
+
* @since v10.12.0
|
|
2880
|
+
* @param type Must be `'rsa'`, `'rsa-pss'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'`, `'x448'`, or `'dh'`.
|
|
2881
|
+
*/
|
|
904
2882
|
function generateKeyPair(
|
|
905
2883
|
type: "rsa",
|
|
906
2884
|
options: RSAKeyPairOptions<"pem", "pem">,
|
|
@@ -922,11 +2900,35 @@ declare module "crypto" {
|
|
|
922
2900
|
callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
|
|
923
2901
|
): void;
|
|
924
2902
|
function generateKeyPair(
|
|
925
|
-
type: "rsa",
|
|
926
|
-
options: RSAKeyPairKeyObjectOptions,
|
|
2903
|
+
type: "rsa",
|
|
2904
|
+
options: RSAKeyPairKeyObjectOptions,
|
|
2905
|
+
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
2906
|
+
): void;
|
|
2907
|
+
function generateKeyPair(
|
|
2908
|
+
type: "rsa-pss",
|
|
2909
|
+
options: RSAPSSKeyPairOptions<"pem", "pem">,
|
|
2910
|
+
callback: (err: Error | null, publicKey: string, privateKey: string) => void,
|
|
2911
|
+
): void;
|
|
2912
|
+
function generateKeyPair(
|
|
2913
|
+
type: "rsa-pss",
|
|
2914
|
+
options: RSAPSSKeyPairOptions<"pem", "der">,
|
|
2915
|
+
callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
|
|
2916
|
+
): void;
|
|
2917
|
+
function generateKeyPair(
|
|
2918
|
+
type: "rsa-pss",
|
|
2919
|
+
options: RSAPSSKeyPairOptions<"der", "pem">,
|
|
2920
|
+
callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
|
|
2921
|
+
): void;
|
|
2922
|
+
function generateKeyPair(
|
|
2923
|
+
type: "rsa-pss",
|
|
2924
|
+
options: RSAPSSKeyPairOptions<"der", "der">,
|
|
2925
|
+
callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
|
|
2926
|
+
): void;
|
|
2927
|
+
function generateKeyPair(
|
|
2928
|
+
type: "rsa-pss",
|
|
2929
|
+
options: RSAPSSKeyPairKeyObjectOptions,
|
|
927
2930
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
928
2931
|
): void;
|
|
929
|
-
|
|
930
2932
|
function generateKeyPair(
|
|
931
2933
|
type: "dsa",
|
|
932
2934
|
options: DSAKeyPairOptions<"pem", "pem">,
|
|
@@ -952,7 +2954,6 @@ declare module "crypto" {
|
|
|
952
2954
|
options: DSAKeyPairKeyObjectOptions,
|
|
953
2955
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
954
2956
|
): void;
|
|
955
|
-
|
|
956
2957
|
function generateKeyPair(
|
|
957
2958
|
type: "ec",
|
|
958
2959
|
options: ECKeyPairOptions<"pem", "pem">,
|
|
@@ -978,7 +2979,6 @@ declare module "crypto" {
|
|
|
978
2979
|
options: ECKeyPairKeyObjectOptions,
|
|
979
2980
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
980
2981
|
): void;
|
|
981
|
-
|
|
982
2982
|
function generateKeyPair(
|
|
983
2983
|
type: "ed25519",
|
|
984
2984
|
options: ED25519KeyPairOptions<"pem", "pem">,
|
|
@@ -1004,7 +3004,6 @@ declare module "crypto" {
|
|
|
1004
3004
|
options: ED25519KeyPairKeyObjectOptions | undefined,
|
|
1005
3005
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1006
3006
|
): void;
|
|
1007
|
-
|
|
1008
3007
|
function generateKeyPair(
|
|
1009
3008
|
type: "ed448",
|
|
1010
3009
|
options: ED448KeyPairOptions<"pem", "pem">,
|
|
@@ -1030,7 +3029,6 @@ declare module "crypto" {
|
|
|
1030
3029
|
options: ED448KeyPairKeyObjectOptions | undefined,
|
|
1031
3030
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1032
3031
|
): void;
|
|
1033
|
-
|
|
1034
3032
|
function generateKeyPair(
|
|
1035
3033
|
type: "x25519",
|
|
1036
3034
|
options: X25519KeyPairOptions<"pem", "pem">,
|
|
@@ -1056,7 +3054,6 @@ declare module "crypto" {
|
|
|
1056
3054
|
options: X25519KeyPairKeyObjectOptions | undefined,
|
|
1057
3055
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1058
3056
|
): void;
|
|
1059
|
-
|
|
1060
3057
|
function generateKeyPair(
|
|
1061
3058
|
type: "x448",
|
|
1062
3059
|
options: X448KeyPairOptions<"pem", "pem">,
|
|
@@ -1082,205 +3079,1445 @@ declare module "crypto" {
|
|
|
1082
3079
|
options: X448KeyPairKeyObjectOptions | undefined,
|
|
1083
3080
|
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1084
3081
|
): void;
|
|
1085
|
-
|
|
1086
3082
|
namespace generateKeyPair {
|
|
1087
3083
|
function __promisify__(
|
|
1088
3084
|
type: "rsa",
|
|
1089
3085
|
options: RSAKeyPairOptions<"pem", "pem">,
|
|
1090
|
-
): Promise<{
|
|
3086
|
+
): Promise<{
|
|
3087
|
+
publicKey: string;
|
|
3088
|
+
privateKey: string;
|
|
3089
|
+
}>;
|
|
1091
3090
|
function __promisify__(
|
|
1092
3091
|
type: "rsa",
|
|
1093
3092
|
options: RSAKeyPairOptions<"pem", "der">,
|
|
1094
|
-
): Promise<{
|
|
3093
|
+
): Promise<{
|
|
3094
|
+
publicKey: string;
|
|
3095
|
+
privateKey: Buffer;
|
|
3096
|
+
}>;
|
|
1095
3097
|
function __promisify__(
|
|
1096
3098
|
type: "rsa",
|
|
1097
3099
|
options: RSAKeyPairOptions<"der", "pem">,
|
|
1098
|
-
): Promise<{
|
|
3100
|
+
): Promise<{
|
|
3101
|
+
publicKey: Buffer;
|
|
3102
|
+
privateKey: string;
|
|
3103
|
+
}>;
|
|
1099
3104
|
function __promisify__(
|
|
1100
3105
|
type: "rsa",
|
|
1101
3106
|
options: RSAKeyPairOptions<"der", "der">,
|
|
1102
|
-
): Promise<{
|
|
3107
|
+
): Promise<{
|
|
3108
|
+
publicKey: Buffer;
|
|
3109
|
+
privateKey: Buffer;
|
|
3110
|
+
}>;
|
|
1103
3111
|
function __promisify__(type: "rsa", options: RSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1104
|
-
|
|
3112
|
+
function __promisify__(
|
|
3113
|
+
type: "rsa-pss",
|
|
3114
|
+
options: RSAPSSKeyPairOptions<"pem", "pem">,
|
|
3115
|
+
): Promise<{
|
|
3116
|
+
publicKey: string;
|
|
3117
|
+
privateKey: string;
|
|
3118
|
+
}>;
|
|
3119
|
+
function __promisify__(
|
|
3120
|
+
type: "rsa-pss",
|
|
3121
|
+
options: RSAPSSKeyPairOptions<"pem", "der">,
|
|
3122
|
+
): Promise<{
|
|
3123
|
+
publicKey: string;
|
|
3124
|
+
privateKey: Buffer;
|
|
3125
|
+
}>;
|
|
3126
|
+
function __promisify__(
|
|
3127
|
+
type: "rsa-pss",
|
|
3128
|
+
options: RSAPSSKeyPairOptions<"der", "pem">,
|
|
3129
|
+
): Promise<{
|
|
3130
|
+
publicKey: Buffer;
|
|
3131
|
+
privateKey: string;
|
|
3132
|
+
}>;
|
|
3133
|
+
function __promisify__(
|
|
3134
|
+
type: "rsa-pss",
|
|
3135
|
+
options: RSAPSSKeyPairOptions<"der", "der">,
|
|
3136
|
+
): Promise<{
|
|
3137
|
+
publicKey: Buffer;
|
|
3138
|
+
privateKey: Buffer;
|
|
3139
|
+
}>;
|
|
3140
|
+
function __promisify__(
|
|
3141
|
+
type: "rsa-pss",
|
|
3142
|
+
options: RSAPSSKeyPairKeyObjectOptions,
|
|
3143
|
+
): Promise<KeyPairKeyObjectResult>;
|
|
1105
3144
|
function __promisify__(
|
|
1106
3145
|
type: "dsa",
|
|
1107
3146
|
options: DSAKeyPairOptions<"pem", "pem">,
|
|
1108
|
-
): Promise<{
|
|
3147
|
+
): Promise<{
|
|
3148
|
+
publicKey: string;
|
|
3149
|
+
privateKey: string;
|
|
3150
|
+
}>;
|
|
1109
3151
|
function __promisify__(
|
|
1110
3152
|
type: "dsa",
|
|
1111
3153
|
options: DSAKeyPairOptions<"pem", "der">,
|
|
1112
|
-
): Promise<{
|
|
3154
|
+
): Promise<{
|
|
3155
|
+
publicKey: string;
|
|
3156
|
+
privateKey: Buffer;
|
|
3157
|
+
}>;
|
|
1113
3158
|
function __promisify__(
|
|
1114
3159
|
type: "dsa",
|
|
1115
3160
|
options: DSAKeyPairOptions<"der", "pem">,
|
|
1116
|
-
): Promise<{
|
|
3161
|
+
): Promise<{
|
|
3162
|
+
publicKey: Buffer;
|
|
3163
|
+
privateKey: string;
|
|
3164
|
+
}>;
|
|
1117
3165
|
function __promisify__(
|
|
1118
3166
|
type: "dsa",
|
|
1119
3167
|
options: DSAKeyPairOptions<"der", "der">,
|
|
1120
|
-
): Promise<{
|
|
3168
|
+
): Promise<{
|
|
3169
|
+
publicKey: Buffer;
|
|
3170
|
+
privateKey: Buffer;
|
|
3171
|
+
}>;
|
|
1121
3172
|
function __promisify__(type: "dsa", options: DSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1122
|
-
|
|
1123
3173
|
function __promisify__(
|
|
1124
3174
|
type: "ec",
|
|
1125
3175
|
options: ECKeyPairOptions<"pem", "pem">,
|
|
1126
|
-
): Promise<{
|
|
3176
|
+
): Promise<{
|
|
3177
|
+
publicKey: string;
|
|
3178
|
+
privateKey: string;
|
|
3179
|
+
}>;
|
|
1127
3180
|
function __promisify__(
|
|
1128
3181
|
type: "ec",
|
|
1129
3182
|
options: ECKeyPairOptions<"pem", "der">,
|
|
1130
|
-
): Promise<{
|
|
3183
|
+
): Promise<{
|
|
3184
|
+
publicKey: string;
|
|
3185
|
+
privateKey: Buffer;
|
|
3186
|
+
}>;
|
|
1131
3187
|
function __promisify__(
|
|
1132
3188
|
type: "ec",
|
|
1133
3189
|
options: ECKeyPairOptions<"der", "pem">,
|
|
1134
|
-
): Promise<{
|
|
3190
|
+
): Promise<{
|
|
3191
|
+
publicKey: Buffer;
|
|
3192
|
+
privateKey: string;
|
|
3193
|
+
}>;
|
|
1135
3194
|
function __promisify__(
|
|
1136
3195
|
type: "ec",
|
|
1137
3196
|
options: ECKeyPairOptions<"der", "der">,
|
|
1138
|
-
): Promise<{
|
|
3197
|
+
): Promise<{
|
|
3198
|
+
publicKey: Buffer;
|
|
3199
|
+
privateKey: Buffer;
|
|
3200
|
+
}>;
|
|
1139
3201
|
function __promisify__(type: "ec", options: ECKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1140
|
-
|
|
1141
3202
|
function __promisify__(
|
|
1142
3203
|
type: "ed25519",
|
|
1143
3204
|
options: ED25519KeyPairOptions<"pem", "pem">,
|
|
1144
|
-
): Promise<{
|
|
3205
|
+
): Promise<{
|
|
3206
|
+
publicKey: string;
|
|
3207
|
+
privateKey: string;
|
|
3208
|
+
}>;
|
|
1145
3209
|
function __promisify__(
|
|
1146
3210
|
type: "ed25519",
|
|
1147
3211
|
options: ED25519KeyPairOptions<"pem", "der">,
|
|
1148
|
-
): Promise<{
|
|
3212
|
+
): Promise<{
|
|
3213
|
+
publicKey: string;
|
|
3214
|
+
privateKey: Buffer;
|
|
3215
|
+
}>;
|
|
1149
3216
|
function __promisify__(
|
|
1150
3217
|
type: "ed25519",
|
|
1151
3218
|
options: ED25519KeyPairOptions<"der", "pem">,
|
|
1152
|
-
): Promise<{
|
|
3219
|
+
): Promise<{
|
|
3220
|
+
publicKey: Buffer;
|
|
3221
|
+
privateKey: string;
|
|
3222
|
+
}>;
|
|
1153
3223
|
function __promisify__(
|
|
1154
3224
|
type: "ed25519",
|
|
1155
3225
|
options: ED25519KeyPairOptions<"der", "der">,
|
|
1156
|
-
): Promise<{
|
|
3226
|
+
): Promise<{
|
|
3227
|
+
publicKey: Buffer;
|
|
3228
|
+
privateKey: Buffer;
|
|
3229
|
+
}>;
|
|
1157
3230
|
function __promisify__(
|
|
1158
3231
|
type: "ed25519",
|
|
1159
3232
|
options?: ED25519KeyPairKeyObjectOptions,
|
|
1160
3233
|
): Promise<KeyPairKeyObjectResult>;
|
|
1161
|
-
|
|
1162
3234
|
function __promisify__(
|
|
1163
3235
|
type: "ed448",
|
|
1164
3236
|
options: ED448KeyPairOptions<"pem", "pem">,
|
|
1165
|
-
): Promise<{
|
|
3237
|
+
): Promise<{
|
|
3238
|
+
publicKey: string;
|
|
3239
|
+
privateKey: string;
|
|
3240
|
+
}>;
|
|
1166
3241
|
function __promisify__(
|
|
1167
3242
|
type: "ed448",
|
|
1168
3243
|
options: ED448KeyPairOptions<"pem", "der">,
|
|
1169
|
-
): Promise<{
|
|
3244
|
+
): Promise<{
|
|
3245
|
+
publicKey: string;
|
|
3246
|
+
privateKey: Buffer;
|
|
3247
|
+
}>;
|
|
1170
3248
|
function __promisify__(
|
|
1171
3249
|
type: "ed448",
|
|
1172
3250
|
options: ED448KeyPairOptions<"der", "pem">,
|
|
1173
|
-
): Promise<{
|
|
3251
|
+
): Promise<{
|
|
3252
|
+
publicKey: Buffer;
|
|
3253
|
+
privateKey: string;
|
|
3254
|
+
}>;
|
|
1174
3255
|
function __promisify__(
|
|
1175
3256
|
type: "ed448",
|
|
1176
3257
|
options: ED448KeyPairOptions<"der", "der">,
|
|
1177
|
-
): Promise<{
|
|
3258
|
+
): Promise<{
|
|
3259
|
+
publicKey: Buffer;
|
|
3260
|
+
privateKey: Buffer;
|
|
3261
|
+
}>;
|
|
1178
3262
|
function __promisify__(type: "ed448", options?: ED448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1179
|
-
|
|
1180
3263
|
function __promisify__(
|
|
1181
3264
|
type: "x25519",
|
|
1182
3265
|
options: X25519KeyPairOptions<"pem", "pem">,
|
|
1183
|
-
): Promise<{
|
|
3266
|
+
): Promise<{
|
|
3267
|
+
publicKey: string;
|
|
3268
|
+
privateKey: string;
|
|
3269
|
+
}>;
|
|
1184
3270
|
function __promisify__(
|
|
1185
3271
|
type: "x25519",
|
|
1186
3272
|
options: X25519KeyPairOptions<"pem", "der">,
|
|
1187
|
-
): Promise<{
|
|
3273
|
+
): Promise<{
|
|
3274
|
+
publicKey: string;
|
|
3275
|
+
privateKey: Buffer;
|
|
3276
|
+
}>;
|
|
1188
3277
|
function __promisify__(
|
|
1189
3278
|
type: "x25519",
|
|
1190
3279
|
options: X25519KeyPairOptions<"der", "pem">,
|
|
1191
|
-
): Promise<{
|
|
3280
|
+
): Promise<{
|
|
3281
|
+
publicKey: Buffer;
|
|
3282
|
+
privateKey: string;
|
|
3283
|
+
}>;
|
|
1192
3284
|
function __promisify__(
|
|
1193
3285
|
type: "x25519",
|
|
1194
3286
|
options: X25519KeyPairOptions<"der", "der">,
|
|
1195
|
-
): Promise<{
|
|
3287
|
+
): Promise<{
|
|
3288
|
+
publicKey: Buffer;
|
|
3289
|
+
privateKey: Buffer;
|
|
3290
|
+
}>;
|
|
1196
3291
|
function __promisify__(
|
|
1197
3292
|
type: "x25519",
|
|
1198
3293
|
options?: X25519KeyPairKeyObjectOptions,
|
|
1199
3294
|
): Promise<KeyPairKeyObjectResult>;
|
|
1200
|
-
|
|
1201
3295
|
function __promisify__(
|
|
1202
3296
|
type: "x448",
|
|
1203
3297
|
options: X448KeyPairOptions<"pem", "pem">,
|
|
1204
|
-
): Promise<{
|
|
3298
|
+
): Promise<{
|
|
3299
|
+
publicKey: string;
|
|
3300
|
+
privateKey: string;
|
|
3301
|
+
}>;
|
|
1205
3302
|
function __promisify__(
|
|
1206
3303
|
type: "x448",
|
|
1207
3304
|
options: X448KeyPairOptions<"pem", "der">,
|
|
1208
|
-
): Promise<{
|
|
3305
|
+
): Promise<{
|
|
3306
|
+
publicKey: string;
|
|
3307
|
+
privateKey: Buffer;
|
|
3308
|
+
}>;
|
|
1209
3309
|
function __promisify__(
|
|
1210
3310
|
type: "x448",
|
|
1211
3311
|
options: X448KeyPairOptions<"der", "pem">,
|
|
1212
|
-
): Promise<{
|
|
3312
|
+
): Promise<{
|
|
3313
|
+
publicKey: Buffer;
|
|
3314
|
+
privateKey: string;
|
|
3315
|
+
}>;
|
|
1213
3316
|
function __promisify__(
|
|
1214
3317
|
type: "x448",
|
|
1215
3318
|
options: X448KeyPairOptions<"der", "der">,
|
|
1216
|
-
): Promise<{
|
|
3319
|
+
): Promise<{
|
|
3320
|
+
publicKey: Buffer;
|
|
3321
|
+
privateKey: Buffer;
|
|
3322
|
+
}>;
|
|
1217
3323
|
function __promisify__(type: "x448", options?: X448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1218
3324
|
}
|
|
1219
|
-
|
|
1220
3325
|
/**
|
|
1221
3326
|
* Calculates and returns the signature for `data` using the given private key and
|
|
1222
3327
|
* algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
|
|
1223
3328
|
* dependent upon the key type (especially Ed25519 and Ed448).
|
|
1224
3329
|
*
|
|
1225
|
-
* If `key` is not a
|
|
1226
|
-
* passed to
|
|
3330
|
+
* If `key` is not a `KeyObject`, this function behaves as if `key` had been
|
|
3331
|
+
* passed to {@link createPrivateKey}. If it is an object, the following
|
|
3332
|
+
* additional properties can be passed:
|
|
3333
|
+
*
|
|
3334
|
+
* If the `callback` function is provided this function uses libuv's threadpool.
|
|
3335
|
+
* @since v12.0.0
|
|
1227
3336
|
*/
|
|
1228
3337
|
function sign(
|
|
1229
3338
|
algorithm: string | null | undefined,
|
|
1230
3339
|
data: NodeJS.ArrayBufferView,
|
|
1231
|
-
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
|
|
3340
|
+
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput,
|
|
1232
3341
|
): Buffer;
|
|
1233
|
-
|
|
3342
|
+
function sign(
|
|
3343
|
+
algorithm: string | null | undefined,
|
|
3344
|
+
data: NodeJS.ArrayBufferView,
|
|
3345
|
+
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput,
|
|
3346
|
+
callback: (error: Error | null, data: Buffer) => void,
|
|
3347
|
+
): void;
|
|
1234
3348
|
/**
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
* dependent upon the key type (especially Ed25519 and Ed448).
|
|
3349
|
+
* Verifies the given signature for `data` using the given key and algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is dependent upon the
|
|
3350
|
+
* key type (especially Ed25519 and Ed448).
|
|
1238
3351
|
*
|
|
1239
|
-
* If `key` is not a
|
|
1240
|
-
* passed to
|
|
3352
|
+
* If `key` is not a `KeyObject`, this function behaves as if `key` had been
|
|
3353
|
+
* passed to {@link createPublicKey}. If it is an object, the following
|
|
3354
|
+
* additional properties can be passed:
|
|
3355
|
+
*
|
|
3356
|
+
* The `signature` argument is the previously calculated signature for the `data`.
|
|
3357
|
+
*
|
|
3358
|
+
* Because public keys can be derived from private keys, a private key or a public
|
|
3359
|
+
* key may be passed for `key`.
|
|
3360
|
+
*
|
|
3361
|
+
* If the `callback` function is provided this function uses libuv's threadpool.
|
|
3362
|
+
* @since v12.0.0
|
|
1241
3363
|
*/
|
|
1242
3364
|
function verify(
|
|
1243
3365
|
algorithm: string | null | undefined,
|
|
1244
3366
|
data: NodeJS.ArrayBufferView,
|
|
1245
|
-
key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
|
|
3367
|
+
key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput | VerifyJsonWebKeyInput,
|
|
1246
3368
|
signature: NodeJS.ArrayBufferView,
|
|
1247
3369
|
): boolean;
|
|
1248
|
-
|
|
3370
|
+
function verify(
|
|
3371
|
+
algorithm: string | null | undefined,
|
|
3372
|
+
data: NodeJS.ArrayBufferView,
|
|
3373
|
+
key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput | VerifyJsonWebKeyInput,
|
|
3374
|
+
signature: NodeJS.ArrayBufferView,
|
|
3375
|
+
callback: (error: Error | null, result: boolean) => void,
|
|
3376
|
+
): void;
|
|
1249
3377
|
/**
|
|
1250
|
-
* Computes the Diffie-Hellman secret based on a privateKey and a publicKey
|
|
1251
|
-
* Both keys must have the same asymmetricKeyType
|
|
1252
|
-
*
|
|
3378
|
+
* Computes the Diffie-Hellman secret based on a `privateKey` and a `publicKey`.
|
|
3379
|
+
* Both keys must have the same `asymmetricKeyType`, which must be one of `'dh'` (for Diffie-Hellman), `'ec'` (for ECDH), `'x448'`, or `'x25519'` (for ECDH-ES).
|
|
3380
|
+
* @since v13.9.0, v12.17.0
|
|
1253
3381
|
*/
|
|
1254
3382
|
function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer;
|
|
3383
|
+
/**
|
|
3384
|
+
* A utility for creating one-shot hash digests of data. It can be faster than the object-based `crypto.createHash()` when hashing a smaller amount of data
|
|
3385
|
+
* (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to use `crypto.createHash()` instead. The `algorithm`
|
|
3386
|
+
* is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc. On recent releases
|
|
3387
|
+
* of OpenSSL, `openssl list -digest-algorithms` will display the available digest algorithms.
|
|
3388
|
+
*
|
|
3389
|
+
* Example:
|
|
3390
|
+
*
|
|
3391
|
+
* ```js
|
|
3392
|
+
* const crypto = require('node:crypto');
|
|
3393
|
+
* const { Buffer } = require('node:buffer');
|
|
3394
|
+
*
|
|
3395
|
+
* // Hashing a string and return the result as a hex-encoded string.
|
|
3396
|
+
* const string = 'Node.js';
|
|
3397
|
+
* // 10b3493287f831e81a438811a1ffba01f8cec4b7
|
|
3398
|
+
* console.log(crypto.hash('sha1', string));
|
|
3399
|
+
*
|
|
3400
|
+
* // Encode a base64-encoded string into a Buffer, hash it and return
|
|
3401
|
+
* // the result as a buffer.
|
|
3402
|
+
* const base64 = 'Tm9kZS5qcw==';
|
|
3403
|
+
* // <Buffer 10 b3 49 32 87 f8 31 e8 1a 43 88 11 a1 ff ba 01 f8 ce c4 b7>
|
|
3404
|
+
* console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
|
|
3405
|
+
* ```
|
|
3406
|
+
* @since v21.7.0, v20.12.0
|
|
3407
|
+
* @param data When `data` is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user
|
|
3408
|
+
* could encode the string into a `TypedArray` using either `TextEncoder` or `Buffer.from()` and passing the encoded `TypedArray` into this API instead.
|
|
3409
|
+
* @param [outputEncoding='hex'] [Encoding](https://nodejs.org/docs/latest-v20.x/api/buffer.html#buffers-and-character-encodings) used to encode the returned digest.
|
|
3410
|
+
*/
|
|
3411
|
+
function hash(algorithm: string, data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
3412
|
+
function hash(algorithm: string, data: BinaryLike, outputEncoding: "buffer"): Buffer;
|
|
3413
|
+
function hash(
|
|
3414
|
+
algorithm: string,
|
|
3415
|
+
data: BinaryLike,
|
|
3416
|
+
outputEncoding?: BinaryToTextEncoding | "buffer",
|
|
3417
|
+
): string | Buffer;
|
|
3418
|
+
type CipherMode = "cbc" | "ccm" | "cfb" | "ctr" | "ecb" | "gcm" | "ocb" | "ofb" | "stream" | "wrap" | "xts";
|
|
3419
|
+
interface CipherInfoOptions {
|
|
3420
|
+
/**
|
|
3421
|
+
* A test key length.
|
|
3422
|
+
*/
|
|
3423
|
+
keyLength?: number | undefined;
|
|
3424
|
+
/**
|
|
3425
|
+
* A test IV length.
|
|
3426
|
+
*/
|
|
3427
|
+
ivLength?: number | undefined;
|
|
3428
|
+
}
|
|
3429
|
+
interface CipherInfo {
|
|
3430
|
+
/**
|
|
3431
|
+
* The name of the cipher.
|
|
3432
|
+
*/
|
|
3433
|
+
name: string;
|
|
3434
|
+
/**
|
|
3435
|
+
* The nid of the cipher.
|
|
3436
|
+
*/
|
|
3437
|
+
nid: number;
|
|
3438
|
+
/**
|
|
3439
|
+
* The block size of the cipher in bytes.
|
|
3440
|
+
* This property is omitted when mode is 'stream'.
|
|
3441
|
+
*/
|
|
3442
|
+
blockSize?: number | undefined;
|
|
3443
|
+
/**
|
|
3444
|
+
* The expected or default initialization vector length in bytes.
|
|
3445
|
+
* This property is omitted if the cipher does not use an initialization vector.
|
|
3446
|
+
*/
|
|
3447
|
+
ivLength?: number | undefined;
|
|
3448
|
+
/**
|
|
3449
|
+
* The expected or default key length in bytes.
|
|
3450
|
+
*/
|
|
3451
|
+
keyLength: number;
|
|
3452
|
+
/**
|
|
3453
|
+
* The cipher mode.
|
|
3454
|
+
*/
|
|
3455
|
+
mode: CipherMode;
|
|
3456
|
+
}
|
|
3457
|
+
/**
|
|
3458
|
+
* Returns information about a given cipher.
|
|
3459
|
+
*
|
|
3460
|
+
* Some ciphers accept variable length keys and initialization vectors. By default,
|
|
3461
|
+
* the `crypto.getCipherInfo()` method will return the default values for these
|
|
3462
|
+
* ciphers. To test if a given key length or iv length is acceptable for given
|
|
3463
|
+
* cipher, use the `keyLength` and `ivLength` options. If the given values are
|
|
3464
|
+
* unacceptable, `undefined` will be returned.
|
|
3465
|
+
* @since v15.0.0
|
|
3466
|
+
* @param nameOrNid The name or nid of the cipher to query.
|
|
3467
|
+
*/
|
|
3468
|
+
function getCipherInfo(nameOrNid: string | number, options?: CipherInfoOptions): CipherInfo | undefined;
|
|
3469
|
+
/**
|
|
3470
|
+
* HKDF is a simple key derivation function defined in RFC 5869\. The given `ikm`, `salt` and `info` are used with the `digest` to derive a key of `keylen` bytes.
|
|
3471
|
+
*
|
|
3472
|
+
* The supplied `callback` function is called with two arguments: `err` and `derivedKey`. If an errors occurs while deriving the key, `err` will be set;
|
|
3473
|
+
* otherwise `err` will be `null`. The successfully generated `derivedKey` will
|
|
3474
|
+
* be passed to the callback as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). An error will be thrown if any
|
|
3475
|
+
* of the input arguments specify invalid values or types.
|
|
3476
|
+
*
|
|
3477
|
+
* ```js
|
|
3478
|
+
* import { Buffer } from 'node:buffer';
|
|
3479
|
+
* const {
|
|
3480
|
+
* hkdf,
|
|
3481
|
+
* } = await import('node:crypto');
|
|
3482
|
+
*
|
|
3483
|
+
* hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
|
|
3484
|
+
* if (err) throw err;
|
|
3485
|
+
* console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
|
|
3486
|
+
* });
|
|
3487
|
+
* ```
|
|
3488
|
+
* @since v15.0.0
|
|
3489
|
+
* @param digest The digest algorithm to use.
|
|
3490
|
+
* @param ikm The input keying material. Must be provided but can be zero-length.
|
|
3491
|
+
* @param salt The salt value. Must be provided but can be zero-length.
|
|
3492
|
+
* @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
|
|
3493
|
+
* @param keylen The length of the key to generate. Must be greater than 0. The maximum allowable value is `255` times the number of bytes produced by the selected digest function (e.g. `sha512`
|
|
3494
|
+
* generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
|
|
3495
|
+
*/
|
|
3496
|
+
function hkdf(
|
|
3497
|
+
digest: string,
|
|
3498
|
+
irm: BinaryLike | KeyObject,
|
|
3499
|
+
salt: BinaryLike,
|
|
3500
|
+
info: BinaryLike,
|
|
3501
|
+
keylen: number,
|
|
3502
|
+
callback: (err: Error | null, derivedKey: ArrayBuffer) => void,
|
|
3503
|
+
): void;
|
|
3504
|
+
/**
|
|
3505
|
+
* Provides a synchronous HKDF key derivation function as defined in RFC 5869\. The
|
|
3506
|
+
* given `ikm`, `salt` and `info` are used with the `digest` to derive a key of `keylen` bytes.
|
|
3507
|
+
*
|
|
3508
|
+
* The successfully generated `derivedKey` will be returned as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
|
|
3509
|
+
*
|
|
3510
|
+
* An error will be thrown if any of the input arguments specify invalid values or
|
|
3511
|
+
* types, or if the derived key cannot be generated.
|
|
3512
|
+
*
|
|
3513
|
+
* ```js
|
|
3514
|
+
* import { Buffer } from 'node:buffer';
|
|
3515
|
+
* const {
|
|
3516
|
+
* hkdfSync,
|
|
3517
|
+
* } = await import('node:crypto');
|
|
3518
|
+
*
|
|
3519
|
+
* const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
|
|
3520
|
+
* console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
|
|
3521
|
+
* ```
|
|
3522
|
+
* @since v15.0.0
|
|
3523
|
+
* @param digest The digest algorithm to use.
|
|
3524
|
+
* @param ikm The input keying material. Must be provided but can be zero-length.
|
|
3525
|
+
* @param salt The salt value. Must be provided but can be zero-length.
|
|
3526
|
+
* @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
|
|
3527
|
+
* @param keylen The length of the key to generate. Must be greater than 0. The maximum allowable value is `255` times the number of bytes produced by the selected digest function (e.g. `sha512`
|
|
3528
|
+
* generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
|
|
3529
|
+
*/
|
|
3530
|
+
function hkdfSync(
|
|
3531
|
+
digest: string,
|
|
3532
|
+
ikm: BinaryLike | KeyObject,
|
|
3533
|
+
salt: BinaryLike,
|
|
3534
|
+
info: BinaryLike,
|
|
3535
|
+
keylen: number,
|
|
3536
|
+
): ArrayBuffer;
|
|
3537
|
+
interface SecureHeapUsage {
|
|
3538
|
+
/**
|
|
3539
|
+
* The total allocated secure heap size as specified using the `--secure-heap=n` command-line flag.
|
|
3540
|
+
*/
|
|
3541
|
+
total: number;
|
|
3542
|
+
/**
|
|
3543
|
+
* The minimum allocation from the secure heap as specified using the `--secure-heap-min` command-line flag.
|
|
3544
|
+
*/
|
|
3545
|
+
min: number;
|
|
3546
|
+
/**
|
|
3547
|
+
* The total number of bytes currently allocated from the secure heap.
|
|
3548
|
+
*/
|
|
3549
|
+
used: number;
|
|
3550
|
+
/**
|
|
3551
|
+
* The calculated ratio of `used` to `total` allocated bytes.
|
|
3552
|
+
*/
|
|
3553
|
+
utilization: number;
|
|
3554
|
+
}
|
|
3555
|
+
/**
|
|
3556
|
+
* @since v15.6.0
|
|
3557
|
+
*/
|
|
3558
|
+
function secureHeapUsed(): SecureHeapUsage;
|
|
3559
|
+
interface RandomUUIDOptions {
|
|
3560
|
+
/**
|
|
3561
|
+
* By default, to improve performance,
|
|
3562
|
+
* Node.js will pre-emptively generate and persistently cache enough
|
|
3563
|
+
* random data to generate up to 128 random UUIDs. To generate a UUID
|
|
3564
|
+
* without using the cache, set `disableEntropyCache` to `true`.
|
|
3565
|
+
*
|
|
3566
|
+
* @default `false`
|
|
3567
|
+
*/
|
|
3568
|
+
disableEntropyCache?: boolean | undefined;
|
|
3569
|
+
}
|
|
3570
|
+
type UUID = `${string}-${string}-${string}-${string}-${string}`;
|
|
3571
|
+
/**
|
|
3572
|
+
* Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
|
|
3573
|
+
* cryptographic pseudorandom number generator.
|
|
3574
|
+
* @since v15.6.0, v14.17.0
|
|
3575
|
+
*/
|
|
3576
|
+
function randomUUID(options?: RandomUUIDOptions): UUID;
|
|
3577
|
+
interface X509CheckOptions {
|
|
3578
|
+
/**
|
|
3579
|
+
* @default 'always'
|
|
3580
|
+
*/
|
|
3581
|
+
subject?: "always" | "default" | "never";
|
|
3582
|
+
/**
|
|
3583
|
+
* @default true
|
|
3584
|
+
*/
|
|
3585
|
+
wildcards?: boolean;
|
|
3586
|
+
/**
|
|
3587
|
+
* @default true
|
|
3588
|
+
*/
|
|
3589
|
+
partialWildcards?: boolean;
|
|
3590
|
+
/**
|
|
3591
|
+
* @default false
|
|
3592
|
+
*/
|
|
3593
|
+
multiLabelWildcards?: boolean;
|
|
3594
|
+
/**
|
|
3595
|
+
* @default false
|
|
3596
|
+
*/
|
|
3597
|
+
singleLabelSubdomains?: boolean;
|
|
3598
|
+
}
|
|
3599
|
+
/**
|
|
3600
|
+
* Encapsulates an X509 certificate and provides read-only access to
|
|
3601
|
+
* its information.
|
|
3602
|
+
*
|
|
3603
|
+
* ```js
|
|
3604
|
+
* const { X509Certificate } = await import('node:crypto');
|
|
3605
|
+
*
|
|
3606
|
+
* const x509 = new X509Certificate('{... pem encoded cert ...}');
|
|
3607
|
+
*
|
|
3608
|
+
* console.log(x509.subject);
|
|
3609
|
+
* ```
|
|
3610
|
+
* @since v15.6.0
|
|
3611
|
+
*/
|
|
3612
|
+
class X509Certificate {
|
|
3613
|
+
/**
|
|
3614
|
+
* Will be \`true\` if this is a Certificate Authority (CA) certificate.
|
|
3615
|
+
* @since v15.6.0
|
|
3616
|
+
*/
|
|
3617
|
+
readonly ca: boolean;
|
|
3618
|
+
/**
|
|
3619
|
+
* The SHA-1 fingerprint of this certificate.
|
|
3620
|
+
*
|
|
3621
|
+
* Because SHA-1 is cryptographically broken and because the security of SHA-1 is
|
|
3622
|
+
* significantly worse than that of algorithms that are commonly used to sign
|
|
3623
|
+
* certificates, consider using `x509.fingerprint256` instead.
|
|
3624
|
+
* @since v15.6.0
|
|
3625
|
+
*/
|
|
3626
|
+
readonly fingerprint: string;
|
|
3627
|
+
/**
|
|
3628
|
+
* The SHA-256 fingerprint of this certificate.
|
|
3629
|
+
* @since v15.6.0
|
|
3630
|
+
*/
|
|
3631
|
+
readonly fingerprint256: string;
|
|
3632
|
+
/**
|
|
3633
|
+
* The SHA-512 fingerprint of this certificate.
|
|
3634
|
+
*
|
|
3635
|
+
* Because computing the SHA-256 fingerprint is usually faster and because it is
|
|
3636
|
+
* only half the size of the SHA-512 fingerprint, `x509.fingerprint256` may be
|
|
3637
|
+
* a better choice. While SHA-512 presumably provides a higher level of security in
|
|
3638
|
+
* general, the security of SHA-256 matches that of most algorithms that are
|
|
3639
|
+
* commonly used to sign certificates.
|
|
3640
|
+
* @since v17.2.0, v16.14.0
|
|
3641
|
+
*/
|
|
3642
|
+
readonly fingerprint512: string;
|
|
3643
|
+
/**
|
|
3644
|
+
* The complete subject of this certificate.
|
|
3645
|
+
* @since v15.6.0
|
|
3646
|
+
*/
|
|
3647
|
+
readonly subject: string;
|
|
3648
|
+
/**
|
|
3649
|
+
* The subject alternative name specified for this certificate.
|
|
3650
|
+
*
|
|
3651
|
+
* This is a comma-separated list of subject alternative names. Each entry begins
|
|
3652
|
+
* with a string identifying the kind of the subject alternative name followed by
|
|
3653
|
+
* a colon and the value associated with the entry.
|
|
3654
|
+
*
|
|
3655
|
+
* Earlier versions of Node.js incorrectly assumed that it is safe to split this
|
|
3656
|
+
* property at the two-character sequence `', '` (see [CVE-2021-44532](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44532)). However,
|
|
3657
|
+
* both malicious and legitimate certificates can contain subject alternative names
|
|
3658
|
+
* that include this sequence when represented as a string.
|
|
3659
|
+
*
|
|
3660
|
+
* After the prefix denoting the type of the entry, the remainder of each entry
|
|
3661
|
+
* might be enclosed in quotes to indicate that the value is a JSON string literal.
|
|
3662
|
+
* For backward compatibility, Node.js only uses JSON string literals within this
|
|
3663
|
+
* property when necessary to avoid ambiguity. Third-party code should be prepared
|
|
3664
|
+
* to handle both possible entry formats.
|
|
3665
|
+
* @since v15.6.0
|
|
3666
|
+
*/
|
|
3667
|
+
readonly subjectAltName: string | undefined;
|
|
3668
|
+
/**
|
|
3669
|
+
* A textual representation of the certificate's authority information access
|
|
3670
|
+
* extension.
|
|
3671
|
+
*
|
|
3672
|
+
* This is a line feed separated list of access descriptions. Each line begins with
|
|
3673
|
+
* the access method and the kind of the access location, followed by a colon and
|
|
3674
|
+
* the value associated with the access location.
|
|
3675
|
+
*
|
|
3676
|
+
* After the prefix denoting the access method and the kind of the access location,
|
|
3677
|
+
* the remainder of each line might be enclosed in quotes to indicate that the
|
|
3678
|
+
* value is a JSON string literal. For backward compatibility, Node.js only uses
|
|
3679
|
+
* JSON string literals within this property when necessary to avoid ambiguity.
|
|
3680
|
+
* Third-party code should be prepared to handle both possible entry formats.
|
|
3681
|
+
* @since v15.6.0
|
|
3682
|
+
*/
|
|
3683
|
+
readonly infoAccess: string | undefined;
|
|
3684
|
+
/**
|
|
3685
|
+
* An array detailing the key usages for this certificate.
|
|
3686
|
+
* @since v15.6.0
|
|
3687
|
+
*/
|
|
3688
|
+
readonly keyUsage: string[];
|
|
3689
|
+
/**
|
|
3690
|
+
* The issuer identification included in this certificate.
|
|
3691
|
+
* @since v15.6.0
|
|
3692
|
+
*/
|
|
3693
|
+
readonly issuer: string;
|
|
3694
|
+
/**
|
|
3695
|
+
* The issuer certificate or `undefined` if the issuer certificate is not
|
|
3696
|
+
* available.
|
|
3697
|
+
* @since v15.9.0
|
|
3698
|
+
*/
|
|
3699
|
+
readonly issuerCertificate?: X509Certificate | undefined;
|
|
3700
|
+
/**
|
|
3701
|
+
* The public key `KeyObject` for this certificate.
|
|
3702
|
+
* @since v15.6.0
|
|
3703
|
+
*/
|
|
3704
|
+
readonly publicKey: KeyObject;
|
|
3705
|
+
/**
|
|
3706
|
+
* A `Buffer` containing the DER encoding of this certificate.
|
|
3707
|
+
* @since v15.6.0
|
|
3708
|
+
*/
|
|
3709
|
+
readonly raw: Buffer;
|
|
3710
|
+
/**
|
|
3711
|
+
* The serial number of this certificate.
|
|
3712
|
+
*
|
|
3713
|
+
* Serial numbers are assigned by certificate authorities and do not uniquely
|
|
3714
|
+
* identify certificates. Consider using `x509.fingerprint256` as a unique
|
|
3715
|
+
* identifier instead.
|
|
3716
|
+
* @since v15.6.0
|
|
3717
|
+
*/
|
|
3718
|
+
readonly serialNumber: string;
|
|
3719
|
+
/**
|
|
3720
|
+
* The date/time from which this certificate is considered valid.
|
|
3721
|
+
* @since v15.6.0
|
|
3722
|
+
*/
|
|
3723
|
+
readonly validFrom: string;
|
|
3724
|
+
/**
|
|
3725
|
+
* The date/time until which this certificate is considered valid.
|
|
3726
|
+
* @since v15.6.0
|
|
3727
|
+
*/
|
|
3728
|
+
readonly validTo: string;
|
|
3729
|
+
constructor(buffer: BinaryLike);
|
|
3730
|
+
/**
|
|
3731
|
+
* Checks whether the certificate matches the given email address.
|
|
3732
|
+
*
|
|
3733
|
+
* If the `'subject'` option is undefined or set to `'default'`, the certificate
|
|
3734
|
+
* subject is only considered if the subject alternative name extension either does
|
|
3735
|
+
* not exist or does not contain any email addresses.
|
|
3736
|
+
*
|
|
3737
|
+
* If the `'subject'` option is set to `'always'` and if the subject alternative
|
|
3738
|
+
* name extension either does not exist or does not contain a matching email
|
|
3739
|
+
* address, the certificate subject is considered.
|
|
3740
|
+
*
|
|
3741
|
+
* If the `'subject'` option is set to `'never'`, the certificate subject is never
|
|
3742
|
+
* considered, even if the certificate contains no subject alternative names.
|
|
3743
|
+
* @since v15.6.0
|
|
3744
|
+
* @return Returns `email` if the certificate matches, `undefined` if it does not.
|
|
3745
|
+
*/
|
|
3746
|
+
checkEmail(email: string, options?: Pick<X509CheckOptions, "subject">): string | undefined;
|
|
3747
|
+
/**
|
|
3748
|
+
* Checks whether the certificate matches the given host name.
|
|
3749
|
+
*
|
|
3750
|
+
* If the certificate matches the given host name, the matching subject name is
|
|
3751
|
+
* returned. The returned name might be an exact match (e.g., `foo.example.com`)
|
|
3752
|
+
* or it might contain wildcards (e.g., `*.example.com`). Because host name
|
|
3753
|
+
* comparisons are case-insensitive, the returned subject name might also differ
|
|
3754
|
+
* from the given `name` in capitalization.
|
|
3755
|
+
*
|
|
3756
|
+
* If the `'subject'` option is undefined or set to `'default'`, the certificate
|
|
3757
|
+
* subject is only considered if the subject alternative name extension either does
|
|
3758
|
+
* not exist or does not contain any DNS names. This behavior is consistent with [RFC 2818](https://www.rfc-editor.org/rfc/rfc2818.txt) ("HTTP Over TLS").
|
|
3759
|
+
*
|
|
3760
|
+
* If the `'subject'` option is set to `'always'` and if the subject alternative
|
|
3761
|
+
* name extension either does not exist or does not contain a matching DNS name,
|
|
3762
|
+
* the certificate subject is considered.
|
|
3763
|
+
*
|
|
3764
|
+
* If the `'subject'` option is set to `'never'`, the certificate subject is never
|
|
3765
|
+
* considered, even if the certificate contains no subject alternative names.
|
|
3766
|
+
* @since v15.6.0
|
|
3767
|
+
* @return Returns a subject name that matches `name`, or `undefined` if no subject name matches `name`.
|
|
3768
|
+
*/
|
|
3769
|
+
checkHost(name: string, options?: X509CheckOptions): string | undefined;
|
|
3770
|
+
/**
|
|
3771
|
+
* Checks whether the certificate matches the given IP address (IPv4 or IPv6).
|
|
3772
|
+
*
|
|
3773
|
+
* Only [RFC 5280](https://www.rfc-editor.org/rfc/rfc5280.txt) `iPAddress` subject alternative names are considered, and they
|
|
3774
|
+
* must match the given `ip` address exactly. Other subject alternative names as
|
|
3775
|
+
* well as the subject field of the certificate are ignored.
|
|
3776
|
+
* @since v15.6.0
|
|
3777
|
+
* @return Returns `ip` if the certificate matches, `undefined` if it does not.
|
|
3778
|
+
*/
|
|
3779
|
+
checkIP(ip: string): string | undefined;
|
|
3780
|
+
/**
|
|
3781
|
+
* Checks whether this certificate was issued by the given `otherCert`.
|
|
3782
|
+
* @since v15.6.0
|
|
3783
|
+
*/
|
|
3784
|
+
checkIssued(otherCert: X509Certificate): boolean;
|
|
3785
|
+
/**
|
|
3786
|
+
* Checks whether the public key for this certificate is consistent with
|
|
3787
|
+
* the given private key.
|
|
3788
|
+
* @since v15.6.0
|
|
3789
|
+
* @param privateKey A private key.
|
|
3790
|
+
*/
|
|
3791
|
+
checkPrivateKey(privateKey: KeyObject): boolean;
|
|
3792
|
+
/**
|
|
3793
|
+
* There is no standard JSON encoding for X509 certificates. The`toJSON()` method returns a string containing the PEM encoded
|
|
3794
|
+
* certificate.
|
|
3795
|
+
* @since v15.6.0
|
|
3796
|
+
*/
|
|
3797
|
+
toJSON(): string;
|
|
3798
|
+
/**
|
|
3799
|
+
* Returns information about this certificate using the legacy `certificate object` encoding.
|
|
3800
|
+
* @since v15.6.0
|
|
3801
|
+
*/
|
|
3802
|
+
toLegacyObject(): PeerCertificate;
|
|
3803
|
+
/**
|
|
3804
|
+
* Returns the PEM-encoded certificate.
|
|
3805
|
+
* @since v15.6.0
|
|
3806
|
+
*/
|
|
3807
|
+
toString(): string;
|
|
3808
|
+
/**
|
|
3809
|
+
* Verifies that this certificate was signed by the given public key.
|
|
3810
|
+
* Does not perform any other validation checks on the certificate.
|
|
3811
|
+
* @since v15.6.0
|
|
3812
|
+
* @param publicKey A public key.
|
|
3813
|
+
*/
|
|
3814
|
+
verify(publicKey: KeyObject): boolean;
|
|
3815
|
+
}
|
|
3816
|
+
type LargeNumberLike = NodeJS.ArrayBufferView | SharedArrayBuffer | ArrayBuffer | bigint;
|
|
3817
|
+
interface GeneratePrimeOptions {
|
|
3818
|
+
add?: LargeNumberLike | undefined;
|
|
3819
|
+
rem?: LargeNumberLike | undefined;
|
|
3820
|
+
/**
|
|
3821
|
+
* @default false
|
|
3822
|
+
*/
|
|
3823
|
+
safe?: boolean | undefined;
|
|
3824
|
+
bigint?: boolean | undefined;
|
|
3825
|
+
}
|
|
3826
|
+
interface GeneratePrimeOptionsBigInt extends GeneratePrimeOptions {
|
|
3827
|
+
bigint: true;
|
|
3828
|
+
}
|
|
3829
|
+
interface GeneratePrimeOptionsArrayBuffer extends GeneratePrimeOptions {
|
|
3830
|
+
bigint?: false | undefined;
|
|
3831
|
+
}
|
|
3832
|
+
/**
|
|
3833
|
+
* Generates a pseudorandom prime of `size` bits.
|
|
3834
|
+
*
|
|
3835
|
+
* If `options.safe` is `true`, the prime will be a safe prime -- that is, `(prime - 1) / 2` will also be a prime.
|
|
3836
|
+
*
|
|
3837
|
+
* The `options.add` and `options.rem` parameters can be used to enforce additional
|
|
3838
|
+
* requirements, e.g., for Diffie-Hellman:
|
|
3839
|
+
*
|
|
3840
|
+
* * If `options.add` and `options.rem` are both set, the prime will satisfy the
|
|
3841
|
+
* condition that `prime % add = rem`.
|
|
3842
|
+
* * If only `options.add` is set and `options.safe` is not `true`, the prime will
|
|
3843
|
+
* satisfy the condition that `prime % add = 1`.
|
|
3844
|
+
* * If only `options.add` is set and `options.safe` is set to `true`, the prime
|
|
3845
|
+
* will instead satisfy the condition that `prime % add = 3`. This is necessary
|
|
3846
|
+
* because `prime % add = 1` for `options.add > 2` would contradict the condition
|
|
3847
|
+
* enforced by `options.safe`.
|
|
3848
|
+
* * `options.rem` is ignored if `options.add` is not given.
|
|
3849
|
+
*
|
|
3850
|
+
* Both `options.add` and `options.rem` must be encoded as big-endian sequences
|
|
3851
|
+
* if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or `DataView`.
|
|
3852
|
+
*
|
|
3853
|
+
* By default, the prime is encoded as a big-endian sequence of octets
|
|
3854
|
+
* in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
|
|
3855
|
+
* [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
|
|
3856
|
+
* @since v15.8.0
|
|
3857
|
+
* @param size The size (in bits) of the prime to generate.
|
|
3858
|
+
*/
|
|
3859
|
+
function generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
|
|
3860
|
+
function generatePrime(
|
|
3861
|
+
size: number,
|
|
3862
|
+
options: GeneratePrimeOptionsBigInt,
|
|
3863
|
+
callback: (err: Error | null, prime: bigint) => void,
|
|
3864
|
+
): void;
|
|
3865
|
+
function generatePrime(
|
|
3866
|
+
size: number,
|
|
3867
|
+
options: GeneratePrimeOptionsArrayBuffer,
|
|
3868
|
+
callback: (err: Error | null, prime: ArrayBuffer) => void,
|
|
3869
|
+
): void;
|
|
3870
|
+
function generatePrime(
|
|
3871
|
+
size: number,
|
|
3872
|
+
options: GeneratePrimeOptions,
|
|
3873
|
+
callback: (err: Error | null, prime: ArrayBuffer | bigint) => void,
|
|
3874
|
+
): void;
|
|
3875
|
+
/**
|
|
3876
|
+
* Generates a pseudorandom prime of `size` bits.
|
|
3877
|
+
*
|
|
3878
|
+
* If `options.safe` is `true`, the prime will be a safe prime -- that is, `(prime - 1) / 2` will also be a prime.
|
|
3879
|
+
*
|
|
3880
|
+
* The `options.add` and `options.rem` parameters can be used to enforce additional
|
|
3881
|
+
* requirements, e.g., for Diffie-Hellman:
|
|
3882
|
+
*
|
|
3883
|
+
* * If `options.add` and `options.rem` are both set, the prime will satisfy the
|
|
3884
|
+
* condition that `prime % add = rem`.
|
|
3885
|
+
* * If only `options.add` is set and `options.safe` is not `true`, the prime will
|
|
3886
|
+
* satisfy the condition that `prime % add = 1`.
|
|
3887
|
+
* * If only `options.add` is set and `options.safe` is set to `true`, the prime
|
|
3888
|
+
* will instead satisfy the condition that `prime % add = 3`. This is necessary
|
|
3889
|
+
* because `prime % add = 1` for `options.add > 2` would contradict the condition
|
|
3890
|
+
* enforced by `options.safe`.
|
|
3891
|
+
* * `options.rem` is ignored if `options.add` is not given.
|
|
3892
|
+
*
|
|
3893
|
+
* Both `options.add` and `options.rem` must be encoded as big-endian sequences
|
|
3894
|
+
* if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or `DataView`.
|
|
3895
|
+
*
|
|
3896
|
+
* By default, the prime is encoded as a big-endian sequence of octets
|
|
3897
|
+
* in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
|
|
3898
|
+
* [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
|
|
3899
|
+
* @since v15.8.0
|
|
3900
|
+
* @param size The size (in bits) of the prime to generate.
|
|
3901
|
+
*/
|
|
3902
|
+
function generatePrimeSync(size: number): ArrayBuffer;
|
|
3903
|
+
function generatePrimeSync(size: number, options: GeneratePrimeOptionsBigInt): bigint;
|
|
3904
|
+
function generatePrimeSync(size: number, options: GeneratePrimeOptionsArrayBuffer): ArrayBuffer;
|
|
3905
|
+
function generatePrimeSync(size: number, options: GeneratePrimeOptions): ArrayBuffer | bigint;
|
|
3906
|
+
interface CheckPrimeOptions {
|
|
3907
|
+
/**
|
|
3908
|
+
* The number of Miller-Rabin probabilistic primality iterations to perform.
|
|
3909
|
+
* When the value is 0 (zero), a number of checks is used that yields a false positive rate of at most `2**-64` for random input.
|
|
3910
|
+
* Care must be used when selecting a number of checks.
|
|
3911
|
+
* Refer to the OpenSSL documentation for the BN_is_prime_ex function nchecks options for more details.
|
|
3912
|
+
*
|
|
3913
|
+
* @default 0
|
|
3914
|
+
*/
|
|
3915
|
+
checks?: number | undefined;
|
|
3916
|
+
}
|
|
3917
|
+
/**
|
|
3918
|
+
* Checks the primality of the `candidate`.
|
|
3919
|
+
* @since v15.8.0
|
|
3920
|
+
* @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
|
|
3921
|
+
*/
|
|
3922
|
+
function checkPrime(value: LargeNumberLike, callback: (err: Error | null, result: boolean) => void): void;
|
|
3923
|
+
function checkPrime(
|
|
3924
|
+
value: LargeNumberLike,
|
|
3925
|
+
options: CheckPrimeOptions,
|
|
3926
|
+
callback: (err: Error | null, result: boolean) => void,
|
|
3927
|
+
): void;
|
|
3928
|
+
/**
|
|
3929
|
+
* Checks the primality of the `candidate`.
|
|
3930
|
+
* @since v15.8.0
|
|
3931
|
+
* @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
|
|
3932
|
+
* @return `true` if the candidate is a prime with an error probability less than `0.25 ** options.checks`.
|
|
3933
|
+
*/
|
|
3934
|
+
function checkPrimeSync(candidate: LargeNumberLike, options?: CheckPrimeOptions): boolean;
|
|
1255
3935
|
/**
|
|
1256
3936
|
* Load and set the `engine` for some or all OpenSSL functions (selected by flags).
|
|
1257
3937
|
*
|
|
1258
3938
|
* `engine` could be either an id or a path to the engine's shared library.
|
|
1259
3939
|
*
|
|
1260
|
-
* The optional `flags` argument uses `ENGINE_METHOD_ALL` by default.
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1266
|
-
*
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
* - `crypto.constants.ENGINE_METHOD_NONE`
|
|
1274
|
-
*
|
|
1275
|
-
* The flags below are deprecated in OpenSSL-1.1.0.
|
|
1276
|
-
*
|
|
1277
|
-
* - `crypto.constants.ENGINE_METHOD_ECDH`
|
|
1278
|
-
* - `crypto.constants.ENGINE_METHOD_ECDSA`
|
|
1279
|
-
* - `crypto.constants.ENGINE_METHOD_STORE`
|
|
3940
|
+
* The optional `flags` argument uses `ENGINE_METHOD_ALL` by default. The `flags` is a bit field taking one of or a mix of the following flags (defined in `crypto.constants`):
|
|
3941
|
+
*
|
|
3942
|
+
* * `crypto.constants.ENGINE_METHOD_RSA`
|
|
3943
|
+
* * `crypto.constants.ENGINE_METHOD_DSA`
|
|
3944
|
+
* * `crypto.constants.ENGINE_METHOD_DH`
|
|
3945
|
+
* * `crypto.constants.ENGINE_METHOD_RAND`
|
|
3946
|
+
* * `crypto.constants.ENGINE_METHOD_EC`
|
|
3947
|
+
* * `crypto.constants.ENGINE_METHOD_CIPHERS`
|
|
3948
|
+
* * `crypto.constants.ENGINE_METHOD_DIGESTS`
|
|
3949
|
+
* * `crypto.constants.ENGINE_METHOD_PKEY_METHS`
|
|
3950
|
+
* * `crypto.constants.ENGINE_METHOD_PKEY_ASN1_METHS`
|
|
3951
|
+
* * `crypto.constants.ENGINE_METHOD_ALL`
|
|
3952
|
+
* * `crypto.constants.ENGINE_METHOD_NONE`
|
|
1280
3953
|
* @since v0.11.11
|
|
1281
|
-
* @param
|
|
3954
|
+
* @param flags
|
|
1282
3955
|
*/
|
|
1283
3956
|
function setEngine(engine: string, flags?: number): void;
|
|
3957
|
+
/**
|
|
3958
|
+
* A convenient alias for {@link webcrypto.getRandomValues}. This
|
|
3959
|
+
* implementation is not compliant with the Web Crypto spec, to write
|
|
3960
|
+
* web-compatible code use {@link webcrypto.getRandomValues} instead.
|
|
3961
|
+
* @since v17.4.0
|
|
3962
|
+
* @return Returns `typedArray`.
|
|
3963
|
+
*/
|
|
3964
|
+
function getRandomValues<T extends webcrypto.BufferSource>(typedArray: T): T;
|
|
3965
|
+
/**
|
|
3966
|
+
* A convenient alias for `crypto.webcrypto.subtle`.
|
|
3967
|
+
* @since v17.4.0
|
|
3968
|
+
*/
|
|
3969
|
+
const subtle: webcrypto.SubtleCrypto;
|
|
3970
|
+
/**
|
|
3971
|
+
* An implementation of the Web Crypto API standard.
|
|
3972
|
+
*
|
|
3973
|
+
* See the {@link https://nodejs.org/docs/latest/api/webcrypto.html Web Crypto API documentation} for details.
|
|
3974
|
+
* @since v15.0.0
|
|
3975
|
+
*/
|
|
3976
|
+
const webcrypto: webcrypto.Crypto;
|
|
3977
|
+
namespace webcrypto {
|
|
3978
|
+
type BufferSource = ArrayBufferView | ArrayBuffer;
|
|
3979
|
+
type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki";
|
|
3980
|
+
type KeyType = "private" | "public" | "secret";
|
|
3981
|
+
type KeyUsage =
|
|
3982
|
+
| "decrypt"
|
|
3983
|
+
| "deriveBits"
|
|
3984
|
+
| "deriveKey"
|
|
3985
|
+
| "encrypt"
|
|
3986
|
+
| "sign"
|
|
3987
|
+
| "unwrapKey"
|
|
3988
|
+
| "verify"
|
|
3989
|
+
| "wrapKey";
|
|
3990
|
+
type AlgorithmIdentifier = Algorithm | string;
|
|
3991
|
+
type HashAlgorithmIdentifier = AlgorithmIdentifier;
|
|
3992
|
+
type NamedCurve = string;
|
|
3993
|
+
type BigInteger = Uint8Array;
|
|
3994
|
+
interface AesCbcParams extends Algorithm {
|
|
3995
|
+
iv: BufferSource;
|
|
3996
|
+
}
|
|
3997
|
+
interface AesCtrParams extends Algorithm {
|
|
3998
|
+
counter: BufferSource;
|
|
3999
|
+
length: number;
|
|
4000
|
+
}
|
|
4001
|
+
interface AesDerivedKeyParams extends Algorithm {
|
|
4002
|
+
length: number;
|
|
4003
|
+
}
|
|
4004
|
+
interface AesGcmParams extends Algorithm {
|
|
4005
|
+
additionalData?: BufferSource;
|
|
4006
|
+
iv: BufferSource;
|
|
4007
|
+
tagLength?: number;
|
|
4008
|
+
}
|
|
4009
|
+
interface AesKeyAlgorithm extends KeyAlgorithm {
|
|
4010
|
+
length: number;
|
|
4011
|
+
}
|
|
4012
|
+
interface AesKeyGenParams extends Algorithm {
|
|
4013
|
+
length: number;
|
|
4014
|
+
}
|
|
4015
|
+
interface Algorithm {
|
|
4016
|
+
name: string;
|
|
4017
|
+
}
|
|
4018
|
+
interface EcKeyAlgorithm extends KeyAlgorithm {
|
|
4019
|
+
namedCurve: NamedCurve;
|
|
4020
|
+
}
|
|
4021
|
+
interface EcKeyGenParams extends Algorithm {
|
|
4022
|
+
namedCurve: NamedCurve;
|
|
4023
|
+
}
|
|
4024
|
+
interface EcKeyImportParams extends Algorithm {
|
|
4025
|
+
namedCurve: NamedCurve;
|
|
4026
|
+
}
|
|
4027
|
+
interface EcdhKeyDeriveParams extends Algorithm {
|
|
4028
|
+
public: CryptoKey;
|
|
4029
|
+
}
|
|
4030
|
+
interface EcdsaParams extends Algorithm {
|
|
4031
|
+
hash: HashAlgorithmIdentifier;
|
|
4032
|
+
}
|
|
4033
|
+
interface Ed448Params extends Algorithm {
|
|
4034
|
+
context?: BufferSource;
|
|
4035
|
+
}
|
|
4036
|
+
interface HkdfParams extends Algorithm {
|
|
4037
|
+
hash: HashAlgorithmIdentifier;
|
|
4038
|
+
info: BufferSource;
|
|
4039
|
+
salt: BufferSource;
|
|
4040
|
+
}
|
|
4041
|
+
interface HmacImportParams extends Algorithm {
|
|
4042
|
+
hash: HashAlgorithmIdentifier;
|
|
4043
|
+
length?: number;
|
|
4044
|
+
}
|
|
4045
|
+
interface HmacKeyAlgorithm extends KeyAlgorithm {
|
|
4046
|
+
hash: KeyAlgorithm;
|
|
4047
|
+
length: number;
|
|
4048
|
+
}
|
|
4049
|
+
interface HmacKeyGenParams extends Algorithm {
|
|
4050
|
+
hash: HashAlgorithmIdentifier;
|
|
4051
|
+
length?: number;
|
|
4052
|
+
}
|
|
4053
|
+
interface JsonWebKey {
|
|
4054
|
+
alg?: string;
|
|
4055
|
+
crv?: string;
|
|
4056
|
+
d?: string;
|
|
4057
|
+
dp?: string;
|
|
4058
|
+
dq?: string;
|
|
4059
|
+
e?: string;
|
|
4060
|
+
ext?: boolean;
|
|
4061
|
+
k?: string;
|
|
4062
|
+
key_ops?: string[];
|
|
4063
|
+
kty?: string;
|
|
4064
|
+
n?: string;
|
|
4065
|
+
oth?: RsaOtherPrimesInfo[];
|
|
4066
|
+
p?: string;
|
|
4067
|
+
q?: string;
|
|
4068
|
+
qi?: string;
|
|
4069
|
+
use?: string;
|
|
4070
|
+
x?: string;
|
|
4071
|
+
y?: string;
|
|
4072
|
+
}
|
|
4073
|
+
interface KeyAlgorithm {
|
|
4074
|
+
name: string;
|
|
4075
|
+
}
|
|
4076
|
+
interface Pbkdf2Params extends Algorithm {
|
|
4077
|
+
hash: HashAlgorithmIdentifier;
|
|
4078
|
+
iterations: number;
|
|
4079
|
+
salt: BufferSource;
|
|
4080
|
+
}
|
|
4081
|
+
interface RsaHashedImportParams extends Algorithm {
|
|
4082
|
+
hash: HashAlgorithmIdentifier;
|
|
4083
|
+
}
|
|
4084
|
+
interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm {
|
|
4085
|
+
hash: KeyAlgorithm;
|
|
4086
|
+
}
|
|
4087
|
+
interface RsaHashedKeyGenParams extends RsaKeyGenParams {
|
|
4088
|
+
hash: HashAlgorithmIdentifier;
|
|
4089
|
+
}
|
|
4090
|
+
interface RsaKeyAlgorithm extends KeyAlgorithm {
|
|
4091
|
+
modulusLength: number;
|
|
4092
|
+
publicExponent: BigInteger;
|
|
4093
|
+
}
|
|
4094
|
+
interface RsaKeyGenParams extends Algorithm {
|
|
4095
|
+
modulusLength: number;
|
|
4096
|
+
publicExponent: BigInteger;
|
|
4097
|
+
}
|
|
4098
|
+
interface RsaOaepParams extends Algorithm {
|
|
4099
|
+
label?: BufferSource;
|
|
4100
|
+
}
|
|
4101
|
+
interface RsaOtherPrimesInfo {
|
|
4102
|
+
d?: string;
|
|
4103
|
+
r?: string;
|
|
4104
|
+
t?: string;
|
|
4105
|
+
}
|
|
4106
|
+
interface RsaPssParams extends Algorithm {
|
|
4107
|
+
saltLength: number;
|
|
4108
|
+
}
|
|
4109
|
+
/**
|
|
4110
|
+
* Calling `require('node:crypto').webcrypto` returns an instance of the `Crypto` class.
|
|
4111
|
+
* `Crypto` is a singleton that provides access to the remainder of the crypto API.
|
|
4112
|
+
* @since v15.0.0
|
|
4113
|
+
*/
|
|
4114
|
+
interface Crypto {
|
|
4115
|
+
/**
|
|
4116
|
+
* Provides access to the `SubtleCrypto` API.
|
|
4117
|
+
* @since v15.0.0
|
|
4118
|
+
*/
|
|
4119
|
+
readonly subtle: SubtleCrypto;
|
|
4120
|
+
/**
|
|
4121
|
+
* Generates cryptographically strong random values.
|
|
4122
|
+
* The given `typedArray` is filled with random values, and a reference to `typedArray` is returned.
|
|
4123
|
+
*
|
|
4124
|
+
* The given `typedArray` must be an integer-based instance of {@link NodeJS.TypedArray}, i.e. `Float32Array` and `Float64Array` are not accepted.
|
|
4125
|
+
*
|
|
4126
|
+
* An error will be thrown if the given `typedArray` is larger than 65,536 bytes.
|
|
4127
|
+
* @since v15.0.0
|
|
4128
|
+
*/
|
|
4129
|
+
getRandomValues<T extends Exclude<NodeJS.TypedArray, Float32Array | Float64Array>>(typedArray: T): T;
|
|
4130
|
+
/**
|
|
4131
|
+
* Generates a random {@link https://www.rfc-editor.org/rfc/rfc4122.txt RFC 4122} version 4 UUID.
|
|
4132
|
+
* The UUID is generated using a cryptographic pseudorandom number generator.
|
|
4133
|
+
* @since v16.7.0
|
|
4134
|
+
*/
|
|
4135
|
+
randomUUID(): UUID;
|
|
4136
|
+
CryptoKey: CryptoKeyConstructor;
|
|
4137
|
+
}
|
|
4138
|
+
// This constructor throws ILLEGAL_CONSTRUCTOR so it should not be newable.
|
|
4139
|
+
interface CryptoKeyConstructor {
|
|
4140
|
+
/** Illegal constructor */
|
|
4141
|
+
(_: { readonly _: unique symbol }): never; // Allows instanceof to work but not be callable by the user.
|
|
4142
|
+
readonly length: 0;
|
|
4143
|
+
readonly name: "CryptoKey";
|
|
4144
|
+
readonly prototype: CryptoKey;
|
|
4145
|
+
}
|
|
4146
|
+
/**
|
|
4147
|
+
* @since v15.0.0
|
|
4148
|
+
*/
|
|
4149
|
+
interface CryptoKey {
|
|
4150
|
+
/**
|
|
4151
|
+
* An object detailing the algorithm for which the key can be used along with additional algorithm-specific parameters.
|
|
4152
|
+
* @since v15.0.0
|
|
4153
|
+
*/
|
|
4154
|
+
readonly algorithm: KeyAlgorithm;
|
|
4155
|
+
/**
|
|
4156
|
+
* When `true`, the {@link CryptoKey} can be extracted using either `subtleCrypto.exportKey()` or `subtleCrypto.wrapKey()`.
|
|
4157
|
+
* @since v15.0.0
|
|
4158
|
+
*/
|
|
4159
|
+
readonly extractable: boolean;
|
|
4160
|
+
/**
|
|
4161
|
+
* A string identifying whether the key is a symmetric (`'secret'`) or asymmetric (`'private'` or `'public'`) key.
|
|
4162
|
+
* @since v15.0.0
|
|
4163
|
+
*/
|
|
4164
|
+
readonly type: KeyType;
|
|
4165
|
+
/**
|
|
4166
|
+
* An array of strings identifying the operations for which the key may be used.
|
|
4167
|
+
*
|
|
4168
|
+
* The possible usages are:
|
|
4169
|
+
* - `'encrypt'` - The key may be used to encrypt data.
|
|
4170
|
+
* - `'decrypt'` - The key may be used to decrypt data.
|
|
4171
|
+
* - `'sign'` - The key may be used to generate digital signatures.
|
|
4172
|
+
* - `'verify'` - The key may be used to verify digital signatures.
|
|
4173
|
+
* - `'deriveKey'` - The key may be used to derive a new key.
|
|
4174
|
+
* - `'deriveBits'` - The key may be used to derive bits.
|
|
4175
|
+
* - `'wrapKey'` - The key may be used to wrap another key.
|
|
4176
|
+
* - `'unwrapKey'` - The key may be used to unwrap another key.
|
|
4177
|
+
*
|
|
4178
|
+
* Valid key usages depend on the key algorithm (identified by `cryptokey.algorithm.name`).
|
|
4179
|
+
* @since v15.0.0
|
|
4180
|
+
*/
|
|
4181
|
+
readonly usages: KeyUsage[];
|
|
4182
|
+
}
|
|
4183
|
+
/**
|
|
4184
|
+
* The `CryptoKeyPair` is a simple dictionary object with `publicKey` and `privateKey` properties, representing an asymmetric key pair.
|
|
4185
|
+
* @since v15.0.0
|
|
4186
|
+
*/
|
|
4187
|
+
interface CryptoKeyPair {
|
|
4188
|
+
/**
|
|
4189
|
+
* A {@link CryptoKey} whose type will be `'private'`.
|
|
4190
|
+
* @since v15.0.0
|
|
4191
|
+
*/
|
|
4192
|
+
privateKey: CryptoKey;
|
|
4193
|
+
/**
|
|
4194
|
+
* A {@link CryptoKey} whose type will be `'public'`.
|
|
4195
|
+
* @since v15.0.0
|
|
4196
|
+
*/
|
|
4197
|
+
publicKey: CryptoKey;
|
|
4198
|
+
}
|
|
4199
|
+
/**
|
|
4200
|
+
* @since v15.0.0
|
|
4201
|
+
*/
|
|
4202
|
+
interface SubtleCrypto {
|
|
4203
|
+
/**
|
|
4204
|
+
* Using the method and parameters specified in `algorithm` and the keying material provided by `key`,
|
|
4205
|
+
* `subtle.decrypt()` attempts to decipher the provided `data`. If successful,
|
|
4206
|
+
* the returned promise will be resolved with an `<ArrayBuffer>` containing the plaintext result.
|
|
4207
|
+
*
|
|
4208
|
+
* The algorithms currently supported include:
|
|
4209
|
+
*
|
|
4210
|
+
* - `'RSA-OAEP'`
|
|
4211
|
+
* - `'AES-CTR'`
|
|
4212
|
+
* - `'AES-CBC'`
|
|
4213
|
+
* - `'AES-GCM'`
|
|
4214
|
+
* @since v15.0.0
|
|
4215
|
+
*/
|
|
4216
|
+
decrypt(
|
|
4217
|
+
algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams,
|
|
4218
|
+
key: CryptoKey,
|
|
4219
|
+
data: BufferSource,
|
|
4220
|
+
): Promise<ArrayBuffer>;
|
|
4221
|
+
/**
|
|
4222
|
+
* Using the method and parameters specified in `algorithm` and the keying material provided by `baseKey`,
|
|
4223
|
+
* `subtle.deriveBits()` attempts to generate `length` bits.
|
|
4224
|
+
* The Node.js implementation requires that when `length` is a number it must be multiple of `8`.
|
|
4225
|
+
* When `length` is `null` the maximum number of bits for a given algorithm is generated. This is allowed
|
|
4226
|
+
* for the `'ECDH'`, `'X25519'`, and `'X448'` algorithms.
|
|
4227
|
+
* If successful, the returned promise will be resolved with an `<ArrayBuffer>` containing the generated data.
|
|
4228
|
+
*
|
|
4229
|
+
* The algorithms currently supported include:
|
|
4230
|
+
*
|
|
4231
|
+
* - `'ECDH'`
|
|
4232
|
+
* - `'X25519'`
|
|
4233
|
+
* - `'X448'`
|
|
4234
|
+
* - `'HKDF'`
|
|
4235
|
+
* - `'PBKDF2'`
|
|
4236
|
+
* @since v15.0.0
|
|
4237
|
+
*/
|
|
4238
|
+
deriveBits(algorithm: EcdhKeyDeriveParams, baseKey: CryptoKey, length: number | null): Promise<ArrayBuffer>;
|
|
4239
|
+
deriveBits(
|
|
4240
|
+
algorithm: AlgorithmIdentifier | HkdfParams | Pbkdf2Params,
|
|
4241
|
+
baseKey: CryptoKey,
|
|
4242
|
+
length: number,
|
|
4243
|
+
): Promise<ArrayBuffer>;
|
|
4244
|
+
/**
|
|
4245
|
+
* Using the method and parameters specified in `algorithm`, and the keying material provided by `baseKey`,
|
|
4246
|
+
* `subtle.deriveKey()` attempts to generate a new <CryptoKey>` based on the method and parameters in `derivedKeyAlgorithm`.
|
|
4247
|
+
*
|
|
4248
|
+
* Calling `subtle.deriveKey()` is equivalent to calling `subtle.deriveBits()` to generate raw keying material,
|
|
4249
|
+
* then passing the result into the `subtle.importKey()` method using the `deriveKeyAlgorithm`, `extractable`, and `keyUsages` parameters as input.
|
|
4250
|
+
*
|
|
4251
|
+
* The algorithms currently supported include:
|
|
4252
|
+
*
|
|
4253
|
+
* - `'ECDH'`
|
|
4254
|
+
* - `'X25519'`
|
|
4255
|
+
* - `'X448'`
|
|
4256
|
+
* - `'HKDF'`
|
|
4257
|
+
* - `'PBKDF2'`
|
|
4258
|
+
* @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
|
|
4259
|
+
* @since v15.0.0
|
|
4260
|
+
*/
|
|
4261
|
+
deriveKey(
|
|
4262
|
+
algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params,
|
|
4263
|
+
baseKey: CryptoKey,
|
|
4264
|
+
derivedKeyAlgorithm:
|
|
4265
|
+
| AlgorithmIdentifier
|
|
4266
|
+
| AesDerivedKeyParams
|
|
4267
|
+
| HmacImportParams
|
|
4268
|
+
| HkdfParams
|
|
4269
|
+
| Pbkdf2Params,
|
|
4270
|
+
extractable: boolean,
|
|
4271
|
+
keyUsages: readonly KeyUsage[],
|
|
4272
|
+
): Promise<CryptoKey>;
|
|
4273
|
+
/**
|
|
4274
|
+
* Using the method identified by `algorithm`, `subtle.digest()` attempts to generate a digest of `data`.
|
|
4275
|
+
* If successful, the returned promise is resolved with an `<ArrayBuffer>` containing the computed digest.
|
|
4276
|
+
*
|
|
4277
|
+
* If `algorithm` is provided as a `<string>`, it must be one of:
|
|
4278
|
+
*
|
|
4279
|
+
* - `'SHA-1'`
|
|
4280
|
+
* - `'SHA-256'`
|
|
4281
|
+
* - `'SHA-384'`
|
|
4282
|
+
* - `'SHA-512'`
|
|
4283
|
+
*
|
|
4284
|
+
* If `algorithm` is provided as an `<Object>`, it must have a `name` property whose value is one of the above.
|
|
4285
|
+
* @since v15.0.0
|
|
4286
|
+
*/
|
|
4287
|
+
digest(algorithm: AlgorithmIdentifier, data: BufferSource): Promise<ArrayBuffer>;
|
|
4288
|
+
/**
|
|
4289
|
+
* Using the method and parameters specified by `algorithm` and the keying material provided by `key`,
|
|
4290
|
+
* `subtle.encrypt()` attempts to encipher `data`. If successful,
|
|
4291
|
+
* the returned promise is resolved with an `<ArrayBuffer>` containing the encrypted result.
|
|
4292
|
+
*
|
|
4293
|
+
* The algorithms currently supported include:
|
|
4294
|
+
*
|
|
4295
|
+
* - `'RSA-OAEP'`
|
|
4296
|
+
* - `'AES-CTR'`
|
|
4297
|
+
* - `'AES-CBC'`
|
|
4298
|
+
* - `'AES-GCM'`
|
|
4299
|
+
* @since v15.0.0
|
|
4300
|
+
*/
|
|
4301
|
+
encrypt(
|
|
4302
|
+
algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams,
|
|
4303
|
+
key: CryptoKey,
|
|
4304
|
+
data: BufferSource,
|
|
4305
|
+
): Promise<ArrayBuffer>;
|
|
4306
|
+
/**
|
|
4307
|
+
* Exports the given key into the specified format, if supported.
|
|
4308
|
+
*
|
|
4309
|
+
* If the `<CryptoKey>` is not extractable, the returned promise will reject.
|
|
4310
|
+
*
|
|
4311
|
+
* When `format` is either `'pkcs8'` or `'spki'` and the export is successful,
|
|
4312
|
+
* the returned promise will be resolved with an `<ArrayBuffer>` containing the exported key data.
|
|
4313
|
+
*
|
|
4314
|
+
* When `format` is `'jwk'` and the export is successful, the returned promise will be resolved with a
|
|
4315
|
+
* JavaScript object conforming to the {@link https://tools.ietf.org/html/rfc7517 JSON Web Key} specification.
|
|
4316
|
+
* @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
|
4317
|
+
* @returns `<Promise>` containing `<ArrayBuffer>`.
|
|
4318
|
+
* @since v15.0.0
|
|
4319
|
+
*/
|
|
4320
|
+
exportKey(format: "jwk", key: CryptoKey): Promise<JsonWebKey>;
|
|
4321
|
+
exportKey(format: Exclude<KeyFormat, "jwk">, key: CryptoKey): Promise<ArrayBuffer>;
|
|
4322
|
+
/**
|
|
4323
|
+
* Using the method and parameters provided in `algorithm`,
|
|
4324
|
+
* `subtle.generateKey()` attempts to generate new keying material.
|
|
4325
|
+
* Depending the method used, the method may generate either a single `<CryptoKey>` or a `<CryptoKeyPair>`.
|
|
4326
|
+
*
|
|
4327
|
+
* The `<CryptoKeyPair>` (public and private key) generating algorithms supported include:
|
|
4328
|
+
*
|
|
4329
|
+
* - `'RSASSA-PKCS1-v1_5'`
|
|
4330
|
+
* - `'RSA-PSS'`
|
|
4331
|
+
* - `'RSA-OAEP'`
|
|
4332
|
+
* - `'ECDSA'`
|
|
4333
|
+
* - `'Ed25519'`
|
|
4334
|
+
* - `'Ed448'`
|
|
4335
|
+
* - `'ECDH'`
|
|
4336
|
+
* - `'X25519'`
|
|
4337
|
+
* - `'X448'`
|
|
4338
|
+
* The `<CryptoKey>` (secret key) generating algorithms supported include:
|
|
4339
|
+
*
|
|
4340
|
+
* - `'HMAC'`
|
|
4341
|
+
* - `'AES-CTR'`
|
|
4342
|
+
* - `'AES-CBC'`
|
|
4343
|
+
* - `'AES-GCM'`
|
|
4344
|
+
* - `'AES-KW'`
|
|
4345
|
+
* @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
|
|
4346
|
+
* @since v15.0.0
|
|
4347
|
+
*/
|
|
4348
|
+
generateKey(
|
|
4349
|
+
algorithm: RsaHashedKeyGenParams | EcKeyGenParams,
|
|
4350
|
+
extractable: boolean,
|
|
4351
|
+
keyUsages: readonly KeyUsage[],
|
|
4352
|
+
): Promise<CryptoKeyPair>;
|
|
4353
|
+
generateKey(
|
|
4354
|
+
algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params,
|
|
4355
|
+
extractable: boolean,
|
|
4356
|
+
keyUsages: readonly KeyUsage[],
|
|
4357
|
+
): Promise<CryptoKey>;
|
|
4358
|
+
generateKey(
|
|
4359
|
+
algorithm: AlgorithmIdentifier,
|
|
4360
|
+
extractable: boolean,
|
|
4361
|
+
keyUsages: KeyUsage[],
|
|
4362
|
+
): Promise<CryptoKeyPair | CryptoKey>;
|
|
4363
|
+
/**
|
|
4364
|
+
* The `subtle.importKey()` method attempts to interpret the provided `keyData` as the given `format`
|
|
4365
|
+
* to create a `<CryptoKey>` instance using the provided `algorithm`, `extractable`, and `keyUsages` arguments.
|
|
4366
|
+
* If the import is successful, the returned promise will be resolved with the created `<CryptoKey>`.
|
|
4367
|
+
*
|
|
4368
|
+
* If importing a `'PBKDF2'` key, `extractable` must be `false`.
|
|
4369
|
+
* @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
|
4370
|
+
* @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
|
|
4371
|
+
* @since v15.0.0
|
|
4372
|
+
*/
|
|
4373
|
+
importKey(
|
|
4374
|
+
format: "jwk",
|
|
4375
|
+
keyData: JsonWebKey,
|
|
4376
|
+
algorithm:
|
|
4377
|
+
| AlgorithmIdentifier
|
|
4378
|
+
| RsaHashedImportParams
|
|
4379
|
+
| EcKeyImportParams
|
|
4380
|
+
| HmacImportParams
|
|
4381
|
+
| AesKeyAlgorithm,
|
|
4382
|
+
extractable: boolean,
|
|
4383
|
+
keyUsages: readonly KeyUsage[],
|
|
4384
|
+
): Promise<CryptoKey>;
|
|
4385
|
+
importKey(
|
|
4386
|
+
format: Exclude<KeyFormat, "jwk">,
|
|
4387
|
+
keyData: BufferSource,
|
|
4388
|
+
algorithm:
|
|
4389
|
+
| AlgorithmIdentifier
|
|
4390
|
+
| RsaHashedImportParams
|
|
4391
|
+
| EcKeyImportParams
|
|
4392
|
+
| HmacImportParams
|
|
4393
|
+
| AesKeyAlgorithm,
|
|
4394
|
+
extractable: boolean,
|
|
4395
|
+
keyUsages: KeyUsage[],
|
|
4396
|
+
): Promise<CryptoKey>;
|
|
4397
|
+
/**
|
|
4398
|
+
* Using the method and parameters given by `algorithm` and the keying material provided by `key`,
|
|
4399
|
+
* `subtle.sign()` attempts to generate a cryptographic signature of `data`. If successful,
|
|
4400
|
+
* the returned promise is resolved with an `<ArrayBuffer>` containing the generated signature.
|
|
4401
|
+
*
|
|
4402
|
+
* The algorithms currently supported include:
|
|
4403
|
+
*
|
|
4404
|
+
* - `'RSASSA-PKCS1-v1_5'`
|
|
4405
|
+
* - `'RSA-PSS'`
|
|
4406
|
+
* - `'ECDSA'`
|
|
4407
|
+
* - `'Ed25519'`
|
|
4408
|
+
* - `'Ed448'`
|
|
4409
|
+
* - `'HMAC'`
|
|
4410
|
+
* @since v15.0.0
|
|
4411
|
+
*/
|
|
4412
|
+
sign(
|
|
4413
|
+
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params,
|
|
4414
|
+
key: CryptoKey,
|
|
4415
|
+
data: BufferSource,
|
|
4416
|
+
): Promise<ArrayBuffer>;
|
|
4417
|
+
/**
|
|
4418
|
+
* In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material.
|
|
4419
|
+
* The `subtle.unwrapKey()` method attempts to decrypt a wrapped key and create a `<CryptoKey>` instance.
|
|
4420
|
+
* It is equivalent to calling `subtle.decrypt()` first on the encrypted key data (using the `wrappedKey`, `unwrapAlgo`, and `unwrappingKey` arguments as input)
|
|
4421
|
+
* then passing the results in to the `subtle.importKey()` method using the `unwrappedKeyAlgo`, `extractable`, and `keyUsages` arguments as inputs.
|
|
4422
|
+
* If successful, the returned promise is resolved with a `<CryptoKey>` object.
|
|
4423
|
+
*
|
|
4424
|
+
* The wrapping algorithms currently supported include:
|
|
4425
|
+
*
|
|
4426
|
+
* - `'RSA-OAEP'`
|
|
4427
|
+
* - `'AES-CTR'`
|
|
4428
|
+
* - `'AES-CBC'`
|
|
4429
|
+
* - `'AES-GCM'`
|
|
4430
|
+
* - `'AES-KW'`
|
|
4431
|
+
*
|
|
4432
|
+
* The unwrapped key algorithms supported include:
|
|
4433
|
+
*
|
|
4434
|
+
* - `'RSASSA-PKCS1-v1_5'`
|
|
4435
|
+
* - `'RSA-PSS'`
|
|
4436
|
+
* - `'RSA-OAEP'`
|
|
4437
|
+
* - `'ECDSA'`
|
|
4438
|
+
* - `'Ed25519'`
|
|
4439
|
+
* - `'Ed448'`
|
|
4440
|
+
* - `'ECDH'`
|
|
4441
|
+
* - `'X25519'`
|
|
4442
|
+
* - `'X448'`
|
|
4443
|
+
* - `'HMAC'`
|
|
4444
|
+
* - `'AES-CTR'`
|
|
4445
|
+
* - `'AES-CBC'`
|
|
4446
|
+
* - `'AES-GCM'`
|
|
4447
|
+
* - `'AES-KW'`
|
|
4448
|
+
* @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
|
4449
|
+
* @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
|
|
4450
|
+
* @since v15.0.0
|
|
4451
|
+
*/
|
|
4452
|
+
unwrapKey(
|
|
4453
|
+
format: KeyFormat,
|
|
4454
|
+
wrappedKey: BufferSource,
|
|
4455
|
+
unwrappingKey: CryptoKey,
|
|
4456
|
+
unwrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams,
|
|
4457
|
+
unwrappedKeyAlgorithm:
|
|
4458
|
+
| AlgorithmIdentifier
|
|
4459
|
+
| RsaHashedImportParams
|
|
4460
|
+
| EcKeyImportParams
|
|
4461
|
+
| HmacImportParams
|
|
4462
|
+
| AesKeyAlgorithm,
|
|
4463
|
+
extractable: boolean,
|
|
4464
|
+
keyUsages: KeyUsage[],
|
|
4465
|
+
): Promise<CryptoKey>;
|
|
4466
|
+
/**
|
|
4467
|
+
* Using the method and parameters given in `algorithm` and the keying material provided by `key`,
|
|
4468
|
+
* `subtle.verify()` attempts to verify that `signature` is a valid cryptographic signature of `data`.
|
|
4469
|
+
* The returned promise is resolved with either `true` or `false`.
|
|
4470
|
+
*
|
|
4471
|
+
* The algorithms currently supported include:
|
|
4472
|
+
*
|
|
4473
|
+
* - `'RSASSA-PKCS1-v1_5'`
|
|
4474
|
+
* - `'RSA-PSS'`
|
|
4475
|
+
* - `'ECDSA'`
|
|
4476
|
+
* - `'Ed25519'`
|
|
4477
|
+
* - `'Ed448'`
|
|
4478
|
+
* - `'HMAC'`
|
|
4479
|
+
* @since v15.0.0
|
|
4480
|
+
*/
|
|
4481
|
+
verify(
|
|
4482
|
+
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params,
|
|
4483
|
+
key: CryptoKey,
|
|
4484
|
+
signature: BufferSource,
|
|
4485
|
+
data: BufferSource,
|
|
4486
|
+
): Promise<boolean>;
|
|
4487
|
+
/**
|
|
4488
|
+
* In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material.
|
|
4489
|
+
* The `subtle.wrapKey()` method exports the keying material into the format identified by `format`,
|
|
4490
|
+
* then encrypts it using the method and parameters specified by `wrapAlgo` and the keying material provided by `wrappingKey`.
|
|
4491
|
+
* It is the equivalent to calling `subtle.exportKey()` using `format` and `key` as the arguments,
|
|
4492
|
+
* then passing the result to the `subtle.encrypt()` method using `wrappingKey` and `wrapAlgo` as inputs.
|
|
4493
|
+
* If successful, the returned promise will be resolved with an `<ArrayBuffer>` containing the encrypted key data.
|
|
4494
|
+
*
|
|
4495
|
+
* The wrapping algorithms currently supported include:
|
|
4496
|
+
*
|
|
4497
|
+
* - `'RSA-OAEP'`
|
|
4498
|
+
* - `'AES-CTR'`
|
|
4499
|
+
* - `'AES-CBC'`
|
|
4500
|
+
* - `'AES-GCM'`
|
|
4501
|
+
* - `'AES-KW'`
|
|
4502
|
+
* @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
|
4503
|
+
* @since v15.0.0
|
|
4504
|
+
*/
|
|
4505
|
+
wrapKey(
|
|
4506
|
+
format: KeyFormat,
|
|
4507
|
+
key: CryptoKey,
|
|
4508
|
+
wrappingKey: CryptoKey,
|
|
4509
|
+
wrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams,
|
|
4510
|
+
): Promise<ArrayBuffer>;
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
|
|
4514
|
+
global {
|
|
4515
|
+
var crypto: typeof globalThis extends {
|
|
4516
|
+
crypto: infer T;
|
|
4517
|
+
onmessage: any;
|
|
4518
|
+
} ? T
|
|
4519
|
+
: webcrypto.Crypto;
|
|
4520
|
+
}
|
|
1284
4521
|
}
|
|
1285
4522
|
declare module "node:crypto" {
|
|
1286
4523
|
export * from "crypto";
|