utneque 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +10 -0
- package/.eslintrc.isomorphic.js +26 -0
- package/.eslintrc.js +86 -0
- package/.gitattributes +1 -0
- package/.github/workflows/ci.yml +33 -0
- package/.github/workflows/deploy-browser-cdn-candidate.yml +51 -0
- package/.github/workflows/deploy-releases.yml +178 -0
- package/.nvmrc +1 -0
- package/.prettierrc +7 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/launch.json +81 -0
- package/.vscode/settings.json +41 -0
- package/.yarn/plugins/@yarnpkg/plugin-constraints.cjs +52 -0
- package/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs +546 -0
- package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
- package/.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs +28 -0
- package/.yarn/releases/yarn-3.4.1.cjs +873 -0
- package/.yarnrc.yml +15 -0
- package/jest.config.js +18 -0
- package/package.json +59 -0
- package/packages/browser/.eslintrc.js +9 -0
- package/packages/browser/.lintstagedrc.js +1 -0
- package/packages/browser/ARCHITECTURE.md +48 -0
- package/packages/browser/LICENSE.MD +45 -0
- package/packages/browser/Makefile +64 -0
- package/packages/browser/README.md +227 -0
- package/packages/browser/e2e-tests/local-server.ts +28 -0
- package/packages/browser/e2e-tests/performance/ajs-perf-browser.test.ts +75 -0
- package/packages/browser/jest.config.js +15 -0
- package/packages/browser/jest.setup.js +10 -0
- package/packages/browser/package.json +106 -0
- package/packages/browser/qa/README.md +41 -0
- package/packages/browser/qa/__fixtures__/snippets.ts +148 -0
- package/packages/browser/qa/__tests__/backwards-compatibility.test.ts +180 -0
- package/packages/browser/qa/__tests__/destinations.test.ts +101 -0
- package/packages/browser/qa/__tests__/smoke.test.ts +170 -0
- package/packages/browser/qa/lib/benchmark.ts +36 -0
- package/packages/browser/qa/lib/browser.ts +28 -0
- package/packages/browser/qa/lib/jest-reporter.js +57 -0
- package/packages/browser/qa/lib/runner.ts +142 -0
- package/packages/browser/qa/lib/schema.ts +59 -0
- package/packages/browser/qa/lib/server.ts +54 -0
- package/packages/browser/qa/lib/stats.ts +52 -0
- package/packages/browser/scripts/build-prep.sh +7 -0
- package/packages/browser/scripts/ci.sh +15 -0
- package/packages/browser/scripts/release.js +121 -0
- package/packages/browser/scripts/release.sh +9 -0
- package/packages/browser/scripts/run.sh +8 -0
- package/packages/browser/src/browser/__tests__/analytics-lazy-init.integration.test.ts +51 -0
- package/packages/browser/src/browser/__tests__/analytics-pre-init.integration.test.ts +440 -0
- package/packages/browser/src/browser/__tests__/anon-id-and-reset.integration.test.ts +73 -0
- package/packages/browser/src/browser/__tests__/cdn.test.ts +53 -0
- package/packages/browser/src/browser/__tests__/csp-detection.test.ts +140 -0
- package/packages/browser/src/browser/__tests__/inspector.integration.test.ts +121 -0
- package/packages/browser/src/browser/__tests__/integration.test.ts +1213 -0
- package/packages/browser/src/browser/__tests__/integrations.integration.test.ts +260 -0
- package/packages/browser/src/browser/__tests__/page-enrichment.integration.test.ts +216 -0
- package/packages/browser/src/browser/__tests__/query-string.integration.test.ts +116 -0
- package/packages/browser/src/browser/__tests__/standalone-analytics.test.ts +303 -0
- package/packages/browser/src/browser/__tests__/standalone-errors.test.ts +136 -0
- package/packages/browser/src/browser/__tests__/standalone.test.ts +97 -0
- package/packages/browser/src/browser/__tests__/typedef-tests/analytics-browser.ts +150 -0
- package/packages/browser/src/browser/__tests__/update-cdn-settings.test.ts +71 -0
- package/packages/browser/src/browser/browser-umd.ts +19 -0
- package/packages/browser/src/browser/index.ts +486 -0
- package/packages/browser/src/browser/standalone-analytics.ts +62 -0
- package/packages/browser/src/browser/standalone-interface.ts +11 -0
- package/packages/browser/src/browser/standalone.ts +92 -0
- package/packages/browser/src/core/__tests__/track-form.test.ts +193 -0
- package/packages/browser/src/core/__tests__/track-link.test.ts +252 -0
- package/packages/browser/src/core/analytics/__tests__/integration.test.ts +334 -0
- package/packages/browser/src/core/analytics/__tests__/test-plugins.ts +94 -0
- package/packages/browser/src/core/analytics/index.ts +672 -0
- package/packages/browser/src/core/analytics/interfaces.ts +100 -0
- package/packages/browser/src/core/arguments-resolver/__tests__/index.test.ts +524 -0
- package/packages/browser/src/core/arguments-resolver/index.ts +200 -0
- package/packages/browser/src/core/auto-track.ts +152 -0
- package/packages/browser/src/core/buffer/__tests__/index.test.ts +455 -0
- package/packages/browser/src/core/buffer/index.ts +371 -0
- package/packages/browser/src/core/callback/index.ts +1 -0
- package/packages/browser/src/core/connection/__tests__/index.test.ts +25 -0
- package/packages/browser/src/core/connection/index.ts +13 -0
- package/packages/browser/src/core/constants/index.ts +1 -0
- package/packages/browser/src/core/context/__tests__/index.test.ts +201 -0
- package/packages/browser/src/core/context/index.ts +21 -0
- package/packages/browser/src/core/environment/index.ts +7 -0
- package/packages/browser/src/core/events/__tests__/index.test.ts +450 -0
- package/packages/browser/src/core/events/index.ts +280 -0
- package/packages/browser/src/core/events/interfaces.ts +36 -0
- package/packages/browser/src/core/inspector/index.ts +14 -0
- package/packages/browser/src/core/page/__tests__/index.test.ts +130 -0
- package/packages/browser/src/core/page/add-page-context.ts +33 -0
- package/packages/browser/src/core/page/get-page-context.ts +140 -0
- package/packages/browser/src/core/page/index.ts +2 -0
- package/packages/browser/src/core/plugin/index.ts +12 -0
- package/packages/browser/src/core/query-string/__tests__/gracefulDecodeURIComponent.test.ts +17 -0
- package/packages/browser/src/core/query-string/__tests__/index.test.ts +149 -0
- package/packages/browser/src/core/query-string/__tests__/pickPrefix.test.ts +31 -0
- package/packages/browser/src/core/query-string/__tests__/useQueryString.test.ts +60 -0
- package/packages/browser/src/core/query-string/gracefulDecodeURIComponent.ts +16 -0
- package/packages/browser/src/core/query-string/index.ts +64 -0
- package/packages/browser/src/core/query-string/pickPrefix.ts +20 -0
- package/packages/browser/src/core/queue/__tests__/event-queue.test.ts +82 -0
- package/packages/browser/src/core/queue/event-queue.ts +22 -0
- package/packages/browser/src/core/session/__tests__/index.test.ts +41 -0
- package/packages/browser/src/core/session/index.ts +107 -0
- package/packages/browser/src/core/stats/__tests__/index.test.ts +15 -0
- package/packages/browser/src/core/stats/__tests__/remote-metrics.test.ts +189 -0
- package/packages/browser/src/core/stats/index.ts +15 -0
- package/packages/browser/src/core/stats/remote-metrics.ts +144 -0
- package/packages/browser/src/core/storage/__tests__/cookieStorage.test.ts +58 -0
- package/packages/browser/src/core/storage/__tests__/localStorage.test.ts +70 -0
- package/packages/browser/src/core/storage/__tests__/test-helpers.ts +26 -0
- package/packages/browser/src/core/storage/__tests__/universalStorage.test.ts +167 -0
- package/packages/browser/src/core/storage/cookieStorage.ts +80 -0
- package/packages/browser/src/core/storage/index.ts +64 -0
- package/packages/browser/src/core/storage/localStorage.ts +45 -0
- package/packages/browser/src/core/storage/memoryStorage.ts +22 -0
- package/packages/browser/src/core/storage/settings.ts +23 -0
- package/packages/browser/src/core/storage/types.ts +49 -0
- package/packages/browser/src/core/storage/universalStorage.ts +78 -0
- package/packages/browser/src/core/user/__tests__/index.test.ts +922 -0
- package/packages/browser/src/core/user/__tests__/migrate.test.ts +101 -0
- package/packages/browser/src/core/user/__tests__/session.test.ts +136 -0
- package/packages/browser/src/core/user/__tests__/tld.test.ts +36 -0
- package/packages/browser/src/core/user/index.ts +399 -0
- package/packages/browser/src/core/user/migrate.ts +126 -0
- package/packages/browser/src/core/user/tld.ts +65 -0
- package/packages/browser/src/core/user/vendor/crypto-es/LICENSE +53 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/aes.ts +302 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/cipher-core.ts +922 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/core.ts +806 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/enc-base64.ts +110 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/evpkdf.ts +110 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/md5.ts +238 -0
- package/packages/browser/src/core/user/vendor/readme.md +7 -0
- package/packages/browser/src/generated/__tests__/version.test.ts +18 -0
- package/packages/browser/src/generated/version.ts +2 -0
- package/packages/browser/src/index.ts +13 -0
- package/packages/browser/src/lib/__tests__/embedded-write-key.test.ts +15 -0
- package/packages/browser/src/lib/__tests__/fetch.test.ts +35 -0
- package/packages/browser/src/lib/__tests__/get-process-env.test.ts +5 -0
- package/packages/browser/src/lib/__tests__/group-by.test.ts +96 -0
- package/packages/browser/src/lib/__tests__/is-plan-event-enabled.test.ts +36 -0
- package/packages/browser/src/lib/__tests__/is-thenable.test.ts +39 -0
- package/packages/browser/src/lib/__tests__/merged-options.test.ts +123 -0
- package/packages/browser/src/lib/__tests__/on-page-change.test.ts +74 -0
- package/packages/browser/src/lib/__tests__/parse-cdn.test.ts +88 -0
- package/packages/browser/src/lib/__tests__/pick.test.ts +34 -0
- package/packages/browser/src/lib/__tests__/pick.typedef.ts +39 -0
- package/packages/browser/src/lib/bind-all.ts +19 -0
- package/packages/browser/src/lib/browser-polyfill.ts +23 -0
- package/packages/browser/src/lib/client-hints/__tests__/index.test.ts +66 -0
- package/packages/browser/src/lib/client-hints/index.ts +16 -0
- package/packages/browser/src/lib/client-hints/interfaces.ts +42 -0
- package/packages/browser/src/lib/create-deferred.ts +16 -0
- package/packages/browser/src/lib/csp-detection.ts +8 -0
- package/packages/browser/src/lib/embedded-write-key.ts +24 -0
- package/packages/browser/src/lib/fetch.ts +10 -0
- package/packages/browser/src/lib/get-global.ts +16 -0
- package/packages/browser/src/lib/get-process-env.ts +11 -0
- package/packages/browser/src/lib/global-analytics-helper.ts +31 -0
- package/packages/browser/src/lib/group-by.ts +30 -0
- package/packages/browser/src/lib/is-plan-event-enabled.ts +20 -0
- package/packages/browser/src/lib/is-thenable.ts +9 -0
- package/packages/browser/src/lib/load-script.ts +66 -0
- package/packages/browser/src/lib/merged-options.ts +46 -0
- package/packages/browser/src/lib/on-page-change.ts +29 -0
- package/packages/browser/src/lib/p-while.ts +12 -0
- package/packages/browser/src/lib/parse-cdn.ts +56 -0
- package/packages/browser/src/lib/pick.ts +28 -0
- package/packages/browser/src/lib/priority-queue/__tests__/backoff.test.ts +23 -0
- package/packages/browser/src/lib/priority-queue/__tests__/index.test.ts +158 -0
- package/packages/browser/src/lib/priority-queue/__tests__/persisted.test.ts +228 -0
- package/packages/browser/src/lib/priority-queue/backoff.ts +24 -0
- package/packages/browser/src/lib/priority-queue/index.ts +6 -0
- package/packages/browser/src/lib/priority-queue/persisted.ts +127 -0
- package/packages/browser/src/lib/sleep.ts +4 -0
- package/packages/browser/src/lib/to-facade.ts +53 -0
- package/packages/browser/src/lib/version-type.ts +10 -0
- package/packages/browser/src/node/__tests__/node-integration.test.ts +19 -0
- package/packages/browser/src/node/index.ts +36 -0
- package/packages/browser/src/node/node.browser.ts +7 -0
- package/packages/browser/src/plugins/ajs-destination/__tests__/index.test.ts +834 -0
- package/packages/browser/src/plugins/ajs-destination/index.ts +392 -0
- package/packages/browser/src/plugins/ajs-destination/loader.ts +129 -0
- package/packages/browser/src/plugins/ajs-destination/types.ts +44 -0
- package/packages/browser/src/plugins/ajs-destination/utils.ts +32 -0
- package/packages/browser/src/plugins/analytics-node/__tests__/index.test.ts +69 -0
- package/packages/browser/src/plugins/analytics-node/index.ts +67 -0
- package/packages/browser/src/plugins/env-enrichment/__tests__/index.test.ts +421 -0
- package/packages/browser/src/plugins/env-enrichment/index.ts +208 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/batched-dispatcher.test.ts +299 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/index.test.ts +317 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/normalize.test.ts +181 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/retries.test.ts +82 -0
- package/packages/browser/src/plugins/hightouchio/batched-dispatcher.ts +127 -0
- package/packages/browser/src/plugins/hightouchio/fetch-dispatcher.ts +27 -0
- package/packages/browser/src/plugins/hightouchio/index.ts +147 -0
- package/packages/browser/src/plugins/hightouchio/normalize.ts +71 -0
- package/packages/browser/src/plugins/hightouchio/schedule-flush.ts +58 -0
- package/packages/browser/src/plugins/legacy-video-plugins/__tests__/index.test.ts +48 -0
- package/packages/browser/src/plugins/legacy-video-plugins/index.ts +16 -0
- package/packages/browser/src/plugins/middleware/__tests__/index.test.ts +268 -0
- package/packages/browser/src/plugins/middleware/index.ts +131 -0
- package/packages/browser/src/plugins/remote-loader/__tests__/index.test.ts +943 -0
- package/packages/browser/src/plugins/remote-loader/index.ts +256 -0
- package/packages/browser/src/plugins/remote-middleware/__tests__/index.test.ts +116 -0
- package/packages/browser/src/plugins/remote-middleware/index.ts +44 -0
- package/packages/browser/src/plugins/routing-middleware/__tests__/index.test.ts +64 -0
- package/packages/browser/src/plugins/routing-middleware/index.ts +37 -0
- package/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts +520 -0
- package/packages/browser/src/plugins/schema-filter/index.ts +90 -0
- package/packages/browser/src/plugins/validation/__tests__/index.test.ts +78 -0
- package/packages/browser/src/plugins/validation/index.ts +44 -0
- package/packages/browser/src/test-helpers/browser-storage.ts +75 -0
- package/packages/browser/src/test-helpers/factories.ts +18 -0
- package/packages/browser/src/test-helpers/fetch-parse.ts +8 -0
- package/packages/browser/src/test-helpers/fixtures/cdn-settings.ts +301 -0
- package/packages/browser/src/test-helpers/fixtures/classic-destination.ts +25 -0
- package/packages/browser/src/test-helpers/fixtures/client-hints.ts +28 -0
- package/packages/browser/src/test-helpers/fixtures/create-fetch-method.ts +30 -0
- package/packages/browser/src/test-helpers/fixtures/index.ts +4 -0
- package/packages/browser/src/test-helpers/fixtures/page-context.ts +11 -0
- package/packages/browser/src/test-helpers/test-writekeys.ts +5 -0
- package/packages/browser/src/test-helpers/type-assertions.ts +11 -0
- package/packages/browser/src/tester/__fixtures__/hightouch-snippet.ts +64 -0
- package/packages/browser/src/tester/__fixtures__/index.html +8 -0
- package/packages/browser/src/tester/ajs-perf.ts +30 -0
- package/packages/browser/src/tester/ajs-tester.ts +119 -0
- package/packages/browser/src/tester/server.js +16 -0
- package/packages/browser/tsconfig.build.json +9 -0
- package/packages/browser/tsconfig.json +13 -0
- package/packages/browser/webpack.config.js +106 -0
- package/packages/config/package.json +10 -0
- package/packages/config/src/index.js +4 -0
- package/packages/config/src/jest/config.js +50 -0
- package/packages/config/src/jest/get-module-map.js +34 -0
- package/packages/config/src/lint-staged/config.js +4 -0
- package/packages/config-webpack/package.json +20 -0
- package/packages/config-webpack/webpack.config.common.js +75 -0
- package/packages/consent/consent-tools/.eslintrc.js +7 -0
- package/packages/consent/consent-tools/.lintstagedrc.js +1 -0
- package/packages/consent/consent-tools/LICENSE +45 -0
- package/packages/consent/consent-tools/README.md +104 -0
- package/packages/consent/consent-tools/jest.config.js +6 -0
- package/packages/consent/consent-tools/jest.setup.js +4 -0
- package/packages/consent/consent-tools/package.json +48 -0
- package/packages/consent/consent-tools/src/domain/__tests__/assertions/integrations-assertions.ts +37 -0
- package/packages/consent/consent-tools/src/domain/__tests__/consent-stamping.test.ts +45 -0
- package/packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts +816 -0
- package/packages/consent/consent-tools/src/domain/__tests__/typedef-tests.ts +21 -0
- package/packages/consent/consent-tools/src/domain/consent-changed.ts +51 -0
- package/packages/consent/consent-tools/src/domain/consent-stamping.ts +19 -0
- package/packages/consent/consent-tools/src/domain/create-wrapper.ts +238 -0
- package/packages/consent/consent-tools/src/domain/get-initialized-analytics.ts +25 -0
- package/packages/consent/consent-tools/src/domain/load-cancellation.ts +31 -0
- package/packages/consent/consent-tools/src/domain/validation/__tests__/options-validators.test.ts +77 -0
- package/packages/consent/consent-tools/src/domain/validation/__tests__/validation-error.test.ts +15 -0
- package/packages/consent/consent-tools/src/domain/validation/common-validators.ts +19 -0
- package/packages/consent/consent-tools/src/domain/validation/index.ts +1 -0
- package/packages/consent/consent-tools/src/domain/validation/options-validators.ts +74 -0
- package/packages/consent/consent-tools/src/domain/validation/validation-error.ts +11 -0
- package/packages/consent/consent-tools/src/index.ts +16 -0
- package/packages/consent/consent-tools/src/types/errors.ts +14 -0
- package/packages/consent/consent-tools/src/types/index.ts +3 -0
- package/packages/consent/consent-tools/src/types/settings.ts +121 -0
- package/packages/consent/consent-tools/src/types/wrapper.ts +107 -0
- package/packages/consent/consent-tools/src/utils/index.ts +4 -0
- package/packages/consent/consent-tools/src/utils/pick.ts +18 -0
- package/packages/consent/consent-tools/src/utils/pipe.ts +14 -0
- package/packages/consent/consent-tools/src/utils/resolve-when.ts +32 -0
- package/packages/consent/consent-tools/src/utils/uniq.ts +4 -0
- package/packages/consent/consent-tools/tsconfig.build.json +9 -0
- package/packages/consent/consent-tools/tsconfig.json +12 -0
- package/packages/consent/consent-wrapper-onetrust/.eslintrc.js +7 -0
- package/packages/consent/consent-wrapper-onetrust/.lintstagedrc.js +1 -0
- package/packages/consent/consent-wrapper-onetrust/LICENSE +45 -0
- package/packages/consent/consent-wrapper-onetrust/README.md +125 -0
- package/packages/consent/consent-wrapper-onetrust/img/onetrust-cat-id.jpg +0 -0
- package/packages/consent/consent-wrapper-onetrust/img/onetrust-popup.jpg +0 -0
- package/packages/consent/consent-wrapper-onetrust/jest.config.js +6 -0
- package/packages/consent/consent-wrapper-onetrust/jest.setup.js +4 -0
- package/packages/consent/consent-wrapper-onetrust/package.json +60 -0
- package/packages/consent/consent-wrapper-onetrust/src/domain/__tests__/wrapper.test.ts +151 -0
- package/packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts +61 -0
- package/packages/consent/consent-wrapper-onetrust/src/index.ts +6 -0
- package/packages/consent/consent-wrapper-onetrust/src/index.umd.ts +11 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/__tests__/onetrust-api.test.ts +181 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/onetrust-api.ts +155 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/validation/index.ts +1 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/validation/onetrust-api-error.ts +11 -0
- package/packages/consent/consent-wrapper-onetrust/src/test-helpers/mocks.ts +23 -0
- package/packages/consent/consent-wrapper-onetrust/src/test-helpers/onetrust-globals.d.ts +11 -0
- package/packages/consent/consent-wrapper-onetrust/src/test-helpers/utils.ts +3 -0
- package/packages/consent/consent-wrapper-onetrust/tsconfig.build.json +9 -0
- package/packages/consent/consent-wrapper-onetrust/tsconfig.json +11 -0
- package/packages/consent/consent-wrapper-onetrust/webpack.config.js +25 -0
- package/packages/core/.eslintrc.js +4 -0
- package/packages/core/.lintstagedrc.js +1 -0
- package/packages/core/LICENSE.MD +45 -0
- package/packages/core/README.md +3 -0
- package/packages/core/jest.config.js +5 -0
- package/packages/core/jest.setup.js +10 -0
- package/packages/core/package.json +40 -0
- package/packages/core/src/analytics/__tests__/dispatch.test.ts +95 -0
- package/packages/core/src/analytics/dispatch.ts +58 -0
- package/packages/core/src/analytics/index.ts +11 -0
- package/packages/core/src/callback/__tests__/index.test.ts +85 -0
- package/packages/core/src/callback/index.ts +51 -0
- package/packages/core/src/context/index.ts +123 -0
- package/packages/core/src/emitter/__tests__/emitter.test.ts +74 -0
- package/packages/core/src/emitter/index.ts +65 -0
- package/packages/core/src/emitter/interface.ts +31 -0
- package/packages/core/src/events/__tests__/index.test.ts +394 -0
- package/packages/core/src/events/index.ts +280 -0
- package/packages/core/src/events/interfaces.ts +475 -0
- package/packages/core/src/index.ts +19 -0
- package/packages/core/src/logger/__tests__/index.test.ts +66 -0
- package/packages/core/src/logger/index.ts +74 -0
- package/packages/core/src/plugins/index.ts +43 -0
- package/packages/core/src/priority-queue/__tests__/backoff.test.ts +23 -0
- package/packages/core/src/priority-queue/__tests__/index.test.ts +158 -0
- package/packages/core/src/priority-queue/backoff.ts +24 -0
- package/packages/core/src/priority-queue/index.ts +103 -0
- package/packages/core/src/queue/__tests__/event-queue.test.ts +678 -0
- package/packages/core/src/queue/__tests__/extension-flushing.test.ts +416 -0
- package/packages/core/src/queue/delivery.ts +73 -0
- package/packages/core/src/queue/event-queue.ts +318 -0
- package/packages/core/src/stats/__tests__/index.test.ts +103 -0
- package/packages/core/src/stats/index.ts +88 -0
- package/packages/core/src/task/__tests__/task-group.test.ts +26 -0
- package/packages/core/src/task/task-group.ts +31 -0
- package/packages/core/src/user/index.ts +7 -0
- package/packages/core/src/utils/__tests__/group-by.test.ts +96 -0
- package/packages/core/src/utils/__tests__/is-plain-object.test.ts +27 -0
- package/packages/core/src/utils/__tests__/is-thenable.test.ts +39 -0
- package/packages/core/src/utils/bind-all.ts +19 -0
- package/packages/core/src/utils/get-global.ts +17 -0
- package/packages/core/src/utils/group-by.ts +30 -0
- package/packages/core/src/utils/has-properties.ts +7 -0
- package/packages/core/src/utils/is-plain-object.ts +26 -0
- package/packages/core/src/utils/is-thenable.ts +9 -0
- package/packages/core/src/utils/p-while.ts +12 -0
- package/packages/core/src/utils/pick.ts +8 -0
- package/packages/core/src/utils/ts-helpers.ts +13 -0
- package/packages/core/src/validation/__tests__/assertions.test.ts +155 -0
- package/packages/core/src/validation/assertions.ts +72 -0
- package/packages/core/src/validation/errors.ts +8 -0
- package/packages/core/src/validation/helpers.ts +23 -0
- package/packages/core/test-helpers/index.ts +2 -0
- package/packages/core/test-helpers/test-ctx.ts +7 -0
- package/packages/core/test-helpers/test-event-queue.ts +7 -0
- package/packages/core/tsconfig.build.json +9 -0
- package/packages/core/tsconfig.json +11 -0
- package/packages/node/.eslintrc.js +7 -0
- package/packages/node/.lintstagedrc.js +1 -0
- package/packages/node/LICENSE +45 -0
- package/packages/node/README.md +138 -0
- package/packages/node/jest.config.js +5 -0
- package/packages/node/jest.setup.js +4 -0
- package/packages/node/package.json +50 -0
- package/packages/node/scripts/version.sh +11 -0
- package/packages/node/src/__tests__/callback.test.ts +47 -0
- package/packages/node/src/__tests__/disable.integration.test.ts +42 -0
- package/packages/node/src/__tests__/emitter.integration.test.ts +45 -0
- package/packages/node/src/__tests__/graceful-shutdown-integration.test.ts +244 -0
- package/packages/node/src/__tests__/http-client.integration.test.ts +69 -0
- package/packages/node/src/__tests__/http-integration.test.ts +362 -0
- package/packages/node/src/__tests__/integration.test.ts +357 -0
- package/packages/node/src/__tests__/plugins.test.ts +16 -0
- package/packages/node/src/__tests__/settings.test.ts +9 -0
- package/packages/node/src/__tests__/test-helpers/assert-shape/http-request-event.ts +13 -0
- package/packages/node/src/__tests__/test-helpers/assert-shape/index.ts +2 -0
- package/packages/node/src/__tests__/test-helpers/assert-shape/segment-http-api.ts +43 -0
- package/packages/node/src/__tests__/test-helpers/create-test-analytics.ts +42 -0
- package/packages/node/src/__tests__/test-helpers/factories.ts +17 -0
- package/packages/node/src/__tests__/test-helpers/is-valid-date.ts +6 -0
- package/packages/node/src/__tests__/test-helpers/resolve-ctx.ts +19 -0
- package/packages/node/src/__tests__/test-helpers/resolve-emitter.ts +11 -0
- package/packages/node/src/__tests__/test-helpers/sleep.ts +3 -0
- package/packages/node/src/__tests__/test-helpers/test-plugin.ts +16 -0
- package/packages/node/src/__tests__/typedef-tests.ts +120 -0
- package/packages/node/src/app/analytics-node.ts +299 -0
- package/packages/node/src/app/context.ts +11 -0
- package/packages/node/src/app/dispatch-emit.ts +42 -0
- package/packages/node/src/app/emitter.ts +23 -0
- package/packages/node/src/app/event-factory.ts +20 -0
- package/packages/node/src/app/event-queue.ts +23 -0
- package/packages/node/src/app/settings.ts +49 -0
- package/packages/node/src/app/types/index.ts +3 -0
- package/packages/node/src/app/types/params.ts +76 -0
- package/packages/node/src/app/types/plugin.ts +5 -0
- package/packages/node/src/app/types/segment-event.ts +7 -0
- package/packages/node/src/generated/version.ts +2 -0
- package/packages/node/src/index.ts +26 -0
- package/packages/node/src/lib/__tests__/abort.test.ts +54 -0
- package/packages/node/src/lib/__tests__/create-url.test.ts +35 -0
- package/packages/node/src/lib/__tests__/env.test.ts +52 -0
- package/packages/node/src/lib/__tests__/get-message-id.test.ts +21 -0
- package/packages/node/src/lib/abort.ts +77 -0
- package/packages/node/src/lib/base-64-encode.ts +8 -0
- package/packages/node/src/lib/create-url.ts +11 -0
- package/packages/node/src/lib/env.ts +45 -0
- package/packages/node/src/lib/extract-promise-parts.ts +21 -0
- package/packages/node/src/lib/fetch.ts +16 -0
- package/packages/node/src/lib/get-message-id.ts +10 -0
- package/packages/node/src/lib/http-client.ts +95 -0
- package/packages/node/src/lib/uuid.ts +1 -0
- package/packages/node/src/plugins/segmentio/__tests__/methods.test.ts +223 -0
- package/packages/node/src/plugins/segmentio/__tests__/publisher.test.ts +411 -0
- package/packages/node/src/plugins/segmentio/context-batch.ts +71 -0
- package/packages/node/src/plugins/segmentio/index.ts +66 -0
- package/packages/node/src/plugins/segmentio/publisher.ts +265 -0
- package/packages/node/tsconfig.build.json +9 -0
- package/packages/node/tsconfig.json +10 -0
- package/packages/test-helpers/.eslintrc.js +7 -0
- package/packages/test-helpers/.lintstagedrc.js +1 -0
- package/packages/test-helpers/jest.config.js +3 -0
- package/packages/test-helpers/package.json +26 -0
- package/packages/test-helpers/src/analytics/cdn-settings-builder.ts +79 -0
- package/packages/test-helpers/src/analytics/index.ts +1 -0
- package/packages/test-helpers/src/index.ts +2 -0
- package/packages/test-helpers/src/utils/index.ts +1 -0
- package/packages/test-helpers/src/utils/sleep.ts +4 -0
- package/packages/test-helpers/tsconfig.build.json +9 -0
- package/packages/test-helpers/tsconfig.json +11 -0
- package/tsconfig.json +21 -0
- package/turbo.json +39 -0
- package/typings/get-monorepo-packages.d.ts +9 -0
- package/typings/spawn.d.ts +10 -0
|
@@ -0,0 +1,922 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
/* eslint-disable no-use-before-define */
|
|
3
|
+
|
|
4
|
+
import { Base, WordArray, BufferedBlockAlgorithm } from './core'
|
|
5
|
+
import { Base64 } from './enc-base64'
|
|
6
|
+
import { EvpKDFAlgo } from './evpkdf'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Abstract base cipher template.
|
|
10
|
+
*
|
|
11
|
+
* @property {number} keySize This cipher's key size. Default: 4 (128 bits)
|
|
12
|
+
* @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
|
|
13
|
+
* @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
|
|
14
|
+
* @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
|
|
15
|
+
*/
|
|
16
|
+
export class Cipher extends BufferedBlockAlgorithm {
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a newly created cipher.
|
|
19
|
+
*
|
|
20
|
+
* @param {number} xformMode Either the encryption or decryption transormation mode constant.
|
|
21
|
+
* @param {WordArray} key The key.
|
|
22
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* const cipher = CryptoJS.algo.AES.create(
|
|
27
|
+
* CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }
|
|
28
|
+
* );
|
|
29
|
+
*/
|
|
30
|
+
constructor(xformMode, key, cfg) {
|
|
31
|
+
super()
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options.
|
|
35
|
+
*
|
|
36
|
+
* @property {WordArray} iv The IV to use for this operation.
|
|
37
|
+
*/
|
|
38
|
+
this.cfg = Object.assign(new Base(), cfg)
|
|
39
|
+
|
|
40
|
+
// Store transform mode and key
|
|
41
|
+
this._xformMode = xformMode
|
|
42
|
+
this._key = key
|
|
43
|
+
|
|
44
|
+
// Set initial values
|
|
45
|
+
this.reset()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates this cipher in encryption mode.
|
|
50
|
+
*
|
|
51
|
+
* @param {WordArray} key The key.
|
|
52
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
53
|
+
*
|
|
54
|
+
* @return {Cipher} A cipher instance.
|
|
55
|
+
*
|
|
56
|
+
* @static
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
*
|
|
60
|
+
* const cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
|
|
61
|
+
*/
|
|
62
|
+
static createEncryptor(key, cfg) {
|
|
63
|
+
return this.create(this._ENC_XFORM_MODE, key, cfg)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Creates this cipher in decryption mode.
|
|
68
|
+
*
|
|
69
|
+
* @param {WordArray} key The key.
|
|
70
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
71
|
+
*
|
|
72
|
+
* @return {Cipher} A cipher instance.
|
|
73
|
+
*
|
|
74
|
+
* @static
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
*
|
|
78
|
+
* const cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
|
|
79
|
+
*/
|
|
80
|
+
static createDecryptor(key, cfg) {
|
|
81
|
+
return this.create(this._DEC_XFORM_MODE, key, cfg)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Creates shortcut functions to a cipher's object interface.
|
|
86
|
+
*
|
|
87
|
+
* @param {Cipher} cipher The cipher to create a helper for.
|
|
88
|
+
*
|
|
89
|
+
* @return {Object} An object with encrypt and decrypt shortcut functions.
|
|
90
|
+
*
|
|
91
|
+
* @static
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
*
|
|
95
|
+
* const AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
|
|
96
|
+
*/
|
|
97
|
+
static _createHelper(SubCipher) {
|
|
98
|
+
const selectCipherStrategy = (key) => {
|
|
99
|
+
if (typeof key === 'string') {
|
|
100
|
+
return PasswordBasedCipher
|
|
101
|
+
}
|
|
102
|
+
return SerializableCipher
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
encrypt(message, key, cfg) {
|
|
107
|
+
return selectCipherStrategy(key).encrypt(SubCipher, message, key, cfg)
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
decrypt(ciphertext, key, cfg) {
|
|
111
|
+
return selectCipherStrategy(key).decrypt(
|
|
112
|
+
SubCipher,
|
|
113
|
+
ciphertext,
|
|
114
|
+
key,
|
|
115
|
+
cfg
|
|
116
|
+
)
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Resets this cipher to its initial state.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* cipher.reset();
|
|
127
|
+
*/
|
|
128
|
+
reset() {
|
|
129
|
+
// Reset data buffer
|
|
130
|
+
super.reset.call(this)
|
|
131
|
+
|
|
132
|
+
// Perform concrete-cipher logic
|
|
133
|
+
this._doReset()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Adds data to be encrypted or decrypted.
|
|
138
|
+
*
|
|
139
|
+
* @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
|
|
140
|
+
*
|
|
141
|
+
* @return {WordArray} The data after processing.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
*
|
|
145
|
+
* const encrypted = cipher.process('data');
|
|
146
|
+
* const encrypted = cipher.process(wordArray);
|
|
147
|
+
*/
|
|
148
|
+
process(dataUpdate) {
|
|
149
|
+
// Append
|
|
150
|
+
this._append(dataUpdate)
|
|
151
|
+
|
|
152
|
+
// Process available blocks
|
|
153
|
+
return this._process()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Finalizes the encryption or decryption process.
|
|
158
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
159
|
+
*
|
|
160
|
+
* @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
|
|
161
|
+
*
|
|
162
|
+
* @return {WordArray} The data after final processing.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
*
|
|
166
|
+
* const encrypted = cipher.finalize();
|
|
167
|
+
* const encrypted = cipher.finalize('data');
|
|
168
|
+
* const encrypted = cipher.finalize(wordArray);
|
|
169
|
+
*/
|
|
170
|
+
finalize(dataUpdate) {
|
|
171
|
+
// Final data update
|
|
172
|
+
if (dataUpdate) {
|
|
173
|
+
this._append(dataUpdate)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Perform concrete-cipher logic
|
|
177
|
+
const finalProcessedData = this._doFinalize()
|
|
178
|
+
|
|
179
|
+
return finalProcessedData
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
Cipher._ENC_XFORM_MODE = 1
|
|
183
|
+
Cipher._DEC_XFORM_MODE = 2
|
|
184
|
+
Cipher.keySize = 128 / 32
|
|
185
|
+
Cipher.ivSize = 128 / 32
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Abstract base stream cipher template.
|
|
189
|
+
*
|
|
190
|
+
* @property {number} blockSize
|
|
191
|
+
*
|
|
192
|
+
* The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
|
|
193
|
+
*/
|
|
194
|
+
export class StreamCipher extends Cipher {
|
|
195
|
+
constructor(...args) {
|
|
196
|
+
super(...args)
|
|
197
|
+
|
|
198
|
+
this.blockSize = 1
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_doFinalize() {
|
|
202
|
+
// Process partial blocks
|
|
203
|
+
const finalProcessedBlocks = this._process(!!'flush')
|
|
204
|
+
|
|
205
|
+
return finalProcessedBlocks
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Abstract base block cipher mode template.
|
|
211
|
+
*/
|
|
212
|
+
export class BlockCipherMode extends Base {
|
|
213
|
+
/**
|
|
214
|
+
* Initializes a newly created mode.
|
|
215
|
+
*
|
|
216
|
+
* @param {Cipher} cipher A block cipher instance.
|
|
217
|
+
* @param {Array} iv The IV words.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
*
|
|
221
|
+
* const mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
|
|
222
|
+
*/
|
|
223
|
+
constructor(cipher, iv) {
|
|
224
|
+
super()
|
|
225
|
+
|
|
226
|
+
this._cipher = cipher
|
|
227
|
+
this._iv = iv
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Creates this mode for encryption.
|
|
232
|
+
*
|
|
233
|
+
* @param {Cipher} cipher A block cipher instance.
|
|
234
|
+
* @param {Array} iv The IV words.
|
|
235
|
+
*
|
|
236
|
+
* @static
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
*
|
|
240
|
+
* const mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
|
|
241
|
+
*/
|
|
242
|
+
static createEncryptor(cipher, iv) {
|
|
243
|
+
return this.Encryptor.create(cipher, iv)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Creates this mode for decryption.
|
|
248
|
+
*
|
|
249
|
+
* @param {Cipher} cipher A block cipher instance.
|
|
250
|
+
* @param {Array} iv The IV words.
|
|
251
|
+
*
|
|
252
|
+
* @static
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
*
|
|
256
|
+
* const mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
|
|
257
|
+
*/
|
|
258
|
+
static createDecryptor(cipher, iv) {
|
|
259
|
+
return this.Decryptor.create(cipher, iv)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function xorBlock(words, offset, blockSize) {
|
|
264
|
+
const _words = words
|
|
265
|
+
let block
|
|
266
|
+
|
|
267
|
+
// Shortcut
|
|
268
|
+
const iv = this._iv
|
|
269
|
+
|
|
270
|
+
// Choose mixing block
|
|
271
|
+
if (iv) {
|
|
272
|
+
block = iv
|
|
273
|
+
|
|
274
|
+
// Remove IV for subsequent blocks
|
|
275
|
+
this._iv = undefined
|
|
276
|
+
} else {
|
|
277
|
+
block = this._prevBlock
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// XOR blocks
|
|
281
|
+
for (let i = 0; i < blockSize; i += 1) {
|
|
282
|
+
_words[offset + i] ^= block[i]
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Cipher Block Chaining mode.
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Abstract base CBC mode.
|
|
292
|
+
*/
|
|
293
|
+
export class CBC extends BlockCipherMode {}
|
|
294
|
+
/**
|
|
295
|
+
* CBC encryptor.
|
|
296
|
+
*/
|
|
297
|
+
CBC.Encryptor = class extends CBC {
|
|
298
|
+
/**
|
|
299
|
+
* Processes the data block at offset.
|
|
300
|
+
*
|
|
301
|
+
* @param {Array} words The data words to operate on.
|
|
302
|
+
* @param {number} offset The offset where the block starts.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
*
|
|
306
|
+
* mode.processBlock(data.words, offset);
|
|
307
|
+
*/
|
|
308
|
+
processBlock(words, offset) {
|
|
309
|
+
// Shortcuts
|
|
310
|
+
const cipher = this._cipher
|
|
311
|
+
const { blockSize } = cipher
|
|
312
|
+
|
|
313
|
+
// XOR and encrypt
|
|
314
|
+
xorBlock.call(this, words, offset, blockSize)
|
|
315
|
+
cipher.encryptBlock(words, offset)
|
|
316
|
+
|
|
317
|
+
// Remember this block to use with next block
|
|
318
|
+
this._prevBlock = words.slice(offset, offset + blockSize)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* CBC decryptor.
|
|
323
|
+
*/
|
|
324
|
+
CBC.Decryptor = class extends CBC {
|
|
325
|
+
/**
|
|
326
|
+
* Processes the data block at offset.
|
|
327
|
+
*
|
|
328
|
+
* @param {Array} words The data words to operate on.
|
|
329
|
+
* @param {number} offset The offset where the block starts.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
*
|
|
333
|
+
* mode.processBlock(data.words, offset);
|
|
334
|
+
*/
|
|
335
|
+
processBlock(words, offset) {
|
|
336
|
+
// Shortcuts
|
|
337
|
+
const cipher = this._cipher
|
|
338
|
+
const { blockSize } = cipher
|
|
339
|
+
|
|
340
|
+
// Remember this block to use with next block
|
|
341
|
+
const thisBlock = words.slice(offset, offset + blockSize)
|
|
342
|
+
|
|
343
|
+
// Decrypt and XOR
|
|
344
|
+
cipher.decryptBlock(words, offset)
|
|
345
|
+
xorBlock.call(this, words, offset, blockSize)
|
|
346
|
+
|
|
347
|
+
// This block becomes the previous block
|
|
348
|
+
this._prevBlock = thisBlock
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* PKCS #5/7 padding strategy.
|
|
354
|
+
*/
|
|
355
|
+
export const Pkcs7 = {
|
|
356
|
+
/**
|
|
357
|
+
* Pads data using the algorithm defined in PKCS #5/7.
|
|
358
|
+
*
|
|
359
|
+
* @param {WordArray} data The data to pad.
|
|
360
|
+
* @param {number} blockSize The multiple that the data should be padded to.
|
|
361
|
+
*
|
|
362
|
+
* @static
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
*
|
|
366
|
+
* CryptoJS.pad.Pkcs7.pad(wordArray, 4);
|
|
367
|
+
*/
|
|
368
|
+
pad(data, blockSize) {
|
|
369
|
+
// Shortcut
|
|
370
|
+
const blockSizeBytes = blockSize * 4
|
|
371
|
+
|
|
372
|
+
// Count padding bytes
|
|
373
|
+
const nPaddingBytes = blockSizeBytes - (data.sigBytes % blockSizeBytes)
|
|
374
|
+
|
|
375
|
+
// Create padding word
|
|
376
|
+
const paddingWord =
|
|
377
|
+
(nPaddingBytes << 24) |
|
|
378
|
+
(nPaddingBytes << 16) |
|
|
379
|
+
(nPaddingBytes << 8) |
|
|
380
|
+
nPaddingBytes
|
|
381
|
+
|
|
382
|
+
// Create padding
|
|
383
|
+
const paddingWords = []
|
|
384
|
+
for (let i = 0; i < nPaddingBytes; i += 4) {
|
|
385
|
+
paddingWords.push(paddingWord)
|
|
386
|
+
}
|
|
387
|
+
const padding = WordArray.create(paddingWords, nPaddingBytes)
|
|
388
|
+
|
|
389
|
+
// Add padding
|
|
390
|
+
data.concat(padding)
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Unpads data that had been padded using the algorithm defined in PKCS #5/7.
|
|
395
|
+
*
|
|
396
|
+
* @param {WordArray} data The data to unpad.
|
|
397
|
+
*
|
|
398
|
+
* @static
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
*
|
|
402
|
+
* CryptoJS.pad.Pkcs7.unpad(wordArray);
|
|
403
|
+
*/
|
|
404
|
+
unpad(data) {
|
|
405
|
+
const _data = data
|
|
406
|
+
|
|
407
|
+
// Get number of padding bytes from last byte
|
|
408
|
+
const nPaddingBytes = _data.words[(_data.sigBytes - 1) >>> 2] & 0xff
|
|
409
|
+
|
|
410
|
+
// Remove padding
|
|
411
|
+
_data.sigBytes -= nPaddingBytes
|
|
412
|
+
},
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Abstract base block cipher template.
|
|
417
|
+
*
|
|
418
|
+
* @property {number} blockSize
|
|
419
|
+
*
|
|
420
|
+
* The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
|
|
421
|
+
*/
|
|
422
|
+
export class BlockCipher extends Cipher {
|
|
423
|
+
constructor(xformMode, key, cfg) {
|
|
424
|
+
/**
|
|
425
|
+
* Configuration options.
|
|
426
|
+
*
|
|
427
|
+
* @property {Mode} mode The block mode to use. Default: CBC
|
|
428
|
+
* @property {Padding} padding The padding strategy to use. Default: Pkcs7
|
|
429
|
+
*/
|
|
430
|
+
super(
|
|
431
|
+
xformMode,
|
|
432
|
+
key,
|
|
433
|
+
Object.assign(
|
|
434
|
+
{
|
|
435
|
+
mode: CBC,
|
|
436
|
+
padding: Pkcs7,
|
|
437
|
+
},
|
|
438
|
+
cfg
|
|
439
|
+
)
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
this.blockSize = 128 / 32
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
reset() {
|
|
446
|
+
let modeCreator
|
|
447
|
+
|
|
448
|
+
// Reset cipher
|
|
449
|
+
super.reset.call(this)
|
|
450
|
+
|
|
451
|
+
// Shortcuts
|
|
452
|
+
const { cfg } = this
|
|
453
|
+
const { iv, mode } = cfg
|
|
454
|
+
|
|
455
|
+
// Reset block mode
|
|
456
|
+
if (this._xformMode === this.constructor._ENC_XFORM_MODE) {
|
|
457
|
+
modeCreator = mode.createEncryptor
|
|
458
|
+
} /* if (this._xformMode == this._DEC_XFORM_MODE) */ else {
|
|
459
|
+
modeCreator = mode.createDecryptor
|
|
460
|
+
// Keep at least one block in the buffer for unpadding
|
|
461
|
+
this._minBufferSize = 1
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
this._mode = modeCreator.call(mode, this, iv && iv.words)
|
|
465
|
+
this._mode.__creator = modeCreator
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
_doProcessBlock(words, offset) {
|
|
469
|
+
this._mode.processBlock(words, offset)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
_doFinalize() {
|
|
473
|
+
let finalProcessedBlocks
|
|
474
|
+
|
|
475
|
+
// Shortcut
|
|
476
|
+
const { padding } = this.cfg
|
|
477
|
+
|
|
478
|
+
// Finalize
|
|
479
|
+
if (this._xformMode === this.constructor._ENC_XFORM_MODE) {
|
|
480
|
+
// Pad data
|
|
481
|
+
padding.pad(this._data, this.blockSize)
|
|
482
|
+
|
|
483
|
+
// Process final blocks
|
|
484
|
+
finalProcessedBlocks = this._process(!!'flush')
|
|
485
|
+
} /* if (this._xformMode == this._DEC_XFORM_MODE) */ else {
|
|
486
|
+
// Process final blocks
|
|
487
|
+
finalProcessedBlocks = this._process(!!'flush')
|
|
488
|
+
|
|
489
|
+
// Unpad data
|
|
490
|
+
padding.unpad(finalProcessedBlocks)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return finalProcessedBlocks
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* A collection of cipher parameters.
|
|
499
|
+
*
|
|
500
|
+
* @property {WordArray} ciphertext The raw ciphertext.
|
|
501
|
+
* @property {WordArray} key The key to this ciphertext.
|
|
502
|
+
* @property {WordArray} iv The IV used in the ciphering operation.
|
|
503
|
+
* @property {WordArray} salt The salt used with a key derivation function.
|
|
504
|
+
* @property {Cipher} algorithm The cipher algorithm.
|
|
505
|
+
* @property {Mode} mode The block mode used in the ciphering operation.
|
|
506
|
+
* @property {Padding} padding The padding scheme used in the ciphering operation.
|
|
507
|
+
* @property {number} blockSize The block size of the cipher.
|
|
508
|
+
* @property {Format} formatter
|
|
509
|
+
* The default formatting strategy to convert this cipher params object to a string.
|
|
510
|
+
*/
|
|
511
|
+
export class CipherParams extends Base {
|
|
512
|
+
/**
|
|
513
|
+
* Initializes a newly created cipher params object.
|
|
514
|
+
*
|
|
515
|
+
* @param {Object} cipherParams An object with any of the possible cipher parameters.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
*
|
|
519
|
+
* var cipherParams = CryptoJS.lib.CipherParams.create({
|
|
520
|
+
* ciphertext: ciphertextWordArray,
|
|
521
|
+
* key: keyWordArray,
|
|
522
|
+
* iv: ivWordArray,
|
|
523
|
+
* salt: saltWordArray,
|
|
524
|
+
* algorithm: CryptoJS.algo.AES,
|
|
525
|
+
* mode: CryptoJS.mode.CBC,
|
|
526
|
+
* padding: CryptoJS.pad.PKCS7,
|
|
527
|
+
* blockSize: 4,
|
|
528
|
+
* formatter: CryptoJS.format.OpenSSL
|
|
529
|
+
* });
|
|
530
|
+
*/
|
|
531
|
+
constructor(cipherParams) {
|
|
532
|
+
super()
|
|
533
|
+
|
|
534
|
+
this.mixIn(cipherParams)
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Converts this cipher params object to a string.
|
|
539
|
+
*
|
|
540
|
+
* @param {Format} formatter (Optional) The formatting strategy to use.
|
|
541
|
+
*
|
|
542
|
+
* @return {string} The stringified cipher params.
|
|
543
|
+
*
|
|
544
|
+
* @throws Error If neither the formatter nor the default formatter is set.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
*
|
|
548
|
+
* var string = cipherParams + '';
|
|
549
|
+
* var string = cipherParams.toString();
|
|
550
|
+
* var string = cipherParams.toString(CryptoJS.format.OpenSSL);
|
|
551
|
+
*/
|
|
552
|
+
toString(formatter) {
|
|
553
|
+
return (formatter || this.formatter).stringify(this)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* OpenSSL formatting strategy.
|
|
559
|
+
*/
|
|
560
|
+
export const OpenSSLFormatter = {
|
|
561
|
+
/**
|
|
562
|
+
* Converts a cipher params object to an OpenSSL-compatible string.
|
|
563
|
+
*
|
|
564
|
+
* @param {CipherParams} cipherParams The cipher params object.
|
|
565
|
+
*
|
|
566
|
+
* @return {string} The OpenSSL-compatible string.
|
|
567
|
+
*
|
|
568
|
+
* @static
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
*
|
|
572
|
+
* var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
|
|
573
|
+
*/
|
|
574
|
+
stringify(cipherParams) {
|
|
575
|
+
let wordArray
|
|
576
|
+
|
|
577
|
+
// Shortcuts
|
|
578
|
+
const { ciphertext, salt } = cipherParams
|
|
579
|
+
|
|
580
|
+
// Format
|
|
581
|
+
if (salt) {
|
|
582
|
+
wordArray = WordArray.create([0x53616c74, 0x65645f5f])
|
|
583
|
+
.concat(salt)
|
|
584
|
+
.concat(ciphertext)
|
|
585
|
+
} else {
|
|
586
|
+
wordArray = ciphertext
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return wordArray.toString(Base64)
|
|
590
|
+
},
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Converts an OpenSSL-compatible string to a cipher params object.
|
|
594
|
+
*
|
|
595
|
+
* @param {string} openSSLStr The OpenSSL-compatible string.
|
|
596
|
+
*
|
|
597
|
+
* @return {CipherParams} The cipher params object.
|
|
598
|
+
*
|
|
599
|
+
* @static
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
*
|
|
603
|
+
* var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
|
|
604
|
+
*/
|
|
605
|
+
parse(openSSLStr) {
|
|
606
|
+
let salt
|
|
607
|
+
|
|
608
|
+
// Parse base64
|
|
609
|
+
const ciphertext = Base64.parse(openSSLStr)
|
|
610
|
+
|
|
611
|
+
// Shortcut
|
|
612
|
+
const ciphertextWords = ciphertext.words
|
|
613
|
+
|
|
614
|
+
// Test for salt
|
|
615
|
+
if (
|
|
616
|
+
ciphertextWords[0] === 0x53616c74 &&
|
|
617
|
+
ciphertextWords[1] === 0x65645f5f
|
|
618
|
+
) {
|
|
619
|
+
// Extract salt
|
|
620
|
+
salt = WordArray.create(ciphertextWords.slice(2, 4))
|
|
621
|
+
|
|
622
|
+
// Remove salt from ciphertext
|
|
623
|
+
ciphertextWords.splice(0, 4)
|
|
624
|
+
ciphertext.sigBytes -= 16
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
return CipherParams.create({ ciphertext, salt })
|
|
628
|
+
},
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* A cipher wrapper that returns ciphertext as a serializable cipher params object.
|
|
633
|
+
*/
|
|
634
|
+
export class SerializableCipher extends Base {
|
|
635
|
+
/**
|
|
636
|
+
* Encrypts a message.
|
|
637
|
+
*
|
|
638
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
639
|
+
* @param {WordArray|string} message The message to encrypt.
|
|
640
|
+
* @param {WordArray} key The key.
|
|
641
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
642
|
+
*
|
|
643
|
+
* @return {CipherParams} A cipher params object.
|
|
644
|
+
*
|
|
645
|
+
* @static
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
*
|
|
649
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher
|
|
650
|
+
* .encrypt(CryptoJS.algo.AES, message, key);
|
|
651
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher
|
|
652
|
+
* .encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
|
|
653
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher
|
|
654
|
+
* .encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
|
655
|
+
*/
|
|
656
|
+
static encrypt(cipher, message, key, cfg) {
|
|
657
|
+
// Apply config defaults
|
|
658
|
+
const _cfg = Object.assign(new Base(), this.cfg, cfg)
|
|
659
|
+
|
|
660
|
+
// Encrypt
|
|
661
|
+
const encryptor = cipher.createEncryptor(key, _cfg)
|
|
662
|
+
const ciphertext = encryptor.finalize(message)
|
|
663
|
+
|
|
664
|
+
// Shortcut
|
|
665
|
+
const cipherCfg = encryptor.cfg
|
|
666
|
+
|
|
667
|
+
// Create and return serializable cipher params
|
|
668
|
+
return CipherParams.create({
|
|
669
|
+
ciphertext,
|
|
670
|
+
key,
|
|
671
|
+
iv: cipherCfg.iv,
|
|
672
|
+
algorithm: cipher,
|
|
673
|
+
mode: cipherCfg.mode,
|
|
674
|
+
padding: cipherCfg.padding,
|
|
675
|
+
blockSize: encryptor.blockSize,
|
|
676
|
+
formatter: _cfg.format,
|
|
677
|
+
})
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Decrypts serialized ciphertext.
|
|
682
|
+
*
|
|
683
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
684
|
+
* @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
|
685
|
+
* @param {WordArray} key The key.
|
|
686
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
687
|
+
*
|
|
688
|
+
* @return {WordArray} The plaintext.
|
|
689
|
+
*
|
|
690
|
+
* @static
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
*
|
|
694
|
+
* var plaintext = CryptoJS.lib.SerializableCipher
|
|
695
|
+
* .decrypt(CryptoJS.algo.AES, formattedCiphertext, key,
|
|
696
|
+
* { iv: iv, format: CryptoJS.format.OpenSSL });
|
|
697
|
+
* var plaintext = CryptoJS.lib.SerializableCipher
|
|
698
|
+
* .decrypt(CryptoJS.algo.AES, ciphertextParams, key,
|
|
699
|
+
* { iv: iv, format: CryptoJS.format.OpenSSL });
|
|
700
|
+
*/
|
|
701
|
+
static decrypt(cipher, ciphertext, key, cfg) {
|
|
702
|
+
let _ciphertext = ciphertext
|
|
703
|
+
|
|
704
|
+
// Apply config defaults
|
|
705
|
+
const _cfg = Object.assign(new Base(), this.cfg, cfg)
|
|
706
|
+
|
|
707
|
+
// Convert string to CipherParams
|
|
708
|
+
_ciphertext = this._parse(_ciphertext, _cfg.format)
|
|
709
|
+
|
|
710
|
+
// Decrypt
|
|
711
|
+
const plaintext = cipher
|
|
712
|
+
.createDecryptor(key, _cfg)
|
|
713
|
+
.finalize(_ciphertext.ciphertext)
|
|
714
|
+
|
|
715
|
+
return plaintext
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Converts serialized ciphertext to CipherParams,
|
|
720
|
+
* else assumed CipherParams already and returns ciphertext unchanged.
|
|
721
|
+
*
|
|
722
|
+
* @param {CipherParams|string} ciphertext The ciphertext.
|
|
723
|
+
* @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
|
|
724
|
+
*
|
|
725
|
+
* @return {CipherParams} The unserialized ciphertext.
|
|
726
|
+
*
|
|
727
|
+
* @static
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
*
|
|
731
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher
|
|
732
|
+
* ._parse(ciphertextStringOrParams, format);
|
|
733
|
+
*/
|
|
734
|
+
static _parse(ciphertext, format) {
|
|
735
|
+
if (typeof ciphertext === 'string') {
|
|
736
|
+
return format.parse(ciphertext, this)
|
|
737
|
+
}
|
|
738
|
+
return ciphertext
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Configuration options.
|
|
743
|
+
*
|
|
744
|
+
* @property {Formatter} format
|
|
745
|
+
*
|
|
746
|
+
* The formatting strategy to convert cipher param objects to and from a string.
|
|
747
|
+
* Default: OpenSSL
|
|
748
|
+
*/
|
|
749
|
+
SerializableCipher.cfg = Object.assign(new Base(), { format: OpenSSLFormatter })
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* OpenSSL key derivation function.
|
|
753
|
+
*/
|
|
754
|
+
export const OpenSSLKdf = {
|
|
755
|
+
/**
|
|
756
|
+
* Derives a key and IV from a password.
|
|
757
|
+
*
|
|
758
|
+
* @param {string} password The password to derive from.
|
|
759
|
+
* @param {number} keySize The size in words of the key to generate.
|
|
760
|
+
* @param {number} ivSize The size in words of the IV to generate.
|
|
761
|
+
* @param {WordArray|string} salt
|
|
762
|
+
* (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
|
|
763
|
+
*
|
|
764
|
+
* @return {CipherParams} A cipher params object with the key, IV, and salt.
|
|
765
|
+
*
|
|
766
|
+
* @static
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
*
|
|
770
|
+
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
|
|
771
|
+
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
|
|
772
|
+
*/
|
|
773
|
+
execute(password, keySize, ivSize, salt, hasher) {
|
|
774
|
+
let _salt = salt
|
|
775
|
+
|
|
776
|
+
// Generate random salt
|
|
777
|
+
if (!_salt) {
|
|
778
|
+
_salt = WordArray.random(64 / 8)
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// Derive key and IV
|
|
782
|
+
let key
|
|
783
|
+
if (!hasher) {
|
|
784
|
+
key = EvpKDFAlgo.create({ keySize: keySize + ivSize }).compute(
|
|
785
|
+
password,
|
|
786
|
+
_salt
|
|
787
|
+
)
|
|
788
|
+
} else {
|
|
789
|
+
key = EvpKDFAlgo.create({ keySize: keySize + ivSize, hasher }).compute(
|
|
790
|
+
password,
|
|
791
|
+
_salt
|
|
792
|
+
)
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Separate key and IV
|
|
796
|
+
const iv = WordArray.create(key.words.slice(keySize), ivSize * 4)
|
|
797
|
+
key.sigBytes = keySize * 4
|
|
798
|
+
|
|
799
|
+
// Return params
|
|
800
|
+
return CipherParams.create({ key, iv, salt: _salt })
|
|
801
|
+
},
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* A serializable cipher wrapper that derives the key from a password,
|
|
806
|
+
* and returns ciphertext as a serializable cipher params object.
|
|
807
|
+
*/
|
|
808
|
+
export class PasswordBasedCipher extends SerializableCipher {
|
|
809
|
+
/**
|
|
810
|
+
* Encrypts a message using a password.
|
|
811
|
+
*
|
|
812
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
813
|
+
* @param {WordArray|string} message The message to encrypt.
|
|
814
|
+
* @param {string} password The password.
|
|
815
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
816
|
+
*
|
|
817
|
+
* @return {CipherParams} A cipher params object.
|
|
818
|
+
*
|
|
819
|
+
* @static
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
*
|
|
823
|
+
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher
|
|
824
|
+
* .encrypt(CryptoJS.algo.AES, message, 'password');
|
|
825
|
+
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher
|
|
826
|
+
* .encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
|
|
827
|
+
*/
|
|
828
|
+
static encrypt(cipher, message, password, cfg) {
|
|
829
|
+
// Apply config defaults
|
|
830
|
+
const _cfg = Object.assign(new Base(), this.cfg, cfg)
|
|
831
|
+
|
|
832
|
+
// Derive key and other params
|
|
833
|
+
const derivedParams = _cfg.kdf.execute(
|
|
834
|
+
password,
|
|
835
|
+
cipher.keySize,
|
|
836
|
+
cipher.ivSize,
|
|
837
|
+
_cfg.salt,
|
|
838
|
+
_cfg.hasher
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
// Add IV to config
|
|
842
|
+
_cfg.iv = derivedParams.iv
|
|
843
|
+
|
|
844
|
+
// Encrypt
|
|
845
|
+
const ciphertext = SerializableCipher.encrypt.call(
|
|
846
|
+
this,
|
|
847
|
+
cipher,
|
|
848
|
+
message,
|
|
849
|
+
derivedParams.key,
|
|
850
|
+
_cfg
|
|
851
|
+
)
|
|
852
|
+
|
|
853
|
+
// Mix in derived params
|
|
854
|
+
ciphertext.mixIn(derivedParams)
|
|
855
|
+
|
|
856
|
+
return ciphertext
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Decrypts serialized ciphertext using a password.
|
|
861
|
+
*
|
|
862
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
863
|
+
* @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
|
864
|
+
* @param {string} password The password.
|
|
865
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
866
|
+
*
|
|
867
|
+
* @return {WordArray} The plaintext.
|
|
868
|
+
*
|
|
869
|
+
* @static
|
|
870
|
+
*
|
|
871
|
+
* @example
|
|
872
|
+
*
|
|
873
|
+
* var plaintext = CryptoJS.lib.PasswordBasedCipher
|
|
874
|
+
* .decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password',
|
|
875
|
+
* { format: CryptoJS.format.OpenSSL });
|
|
876
|
+
* var plaintext = CryptoJS.lib.PasswordBasedCipher
|
|
877
|
+
* .decrypt(CryptoJS.algo.AES, ciphertextParams, 'password',
|
|
878
|
+
* { format: CryptoJS.format.OpenSSL });
|
|
879
|
+
*/
|
|
880
|
+
static decrypt(cipher, ciphertext, password, cfg) {
|
|
881
|
+
let _ciphertext = ciphertext
|
|
882
|
+
|
|
883
|
+
// Apply config defaults
|
|
884
|
+
const _cfg = Object.assign(new Base(), this.cfg, cfg)
|
|
885
|
+
|
|
886
|
+
// Convert string to CipherParams
|
|
887
|
+
_ciphertext = this._parse(_ciphertext, _cfg.format)
|
|
888
|
+
|
|
889
|
+
// Derive key and other params
|
|
890
|
+
const derivedParams = _cfg.kdf.execute(
|
|
891
|
+
password,
|
|
892
|
+
cipher.keySize,
|
|
893
|
+
cipher.ivSize,
|
|
894
|
+
_ciphertext.salt,
|
|
895
|
+
_cfg.hasher
|
|
896
|
+
)
|
|
897
|
+
|
|
898
|
+
// Add IV to config
|
|
899
|
+
_cfg.iv = derivedParams.iv
|
|
900
|
+
|
|
901
|
+
// Decrypt
|
|
902
|
+
const plaintext = SerializableCipher.decrypt.call(
|
|
903
|
+
this,
|
|
904
|
+
cipher,
|
|
905
|
+
_ciphertext,
|
|
906
|
+
derivedParams.key,
|
|
907
|
+
_cfg
|
|
908
|
+
)
|
|
909
|
+
|
|
910
|
+
return plaintext
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Configuration options.
|
|
915
|
+
*
|
|
916
|
+
* @property {KDF} kdf
|
|
917
|
+
* The key derivation function to use to generate a key and IV from a password.
|
|
918
|
+
* Default: OpenSSL
|
|
919
|
+
*/
|
|
920
|
+
PasswordBasedCipher.cfg = Object.assign(SerializableCipher.cfg, {
|
|
921
|
+
kdf: OpenSSLKdf,
|
|
922
|
+
})
|