@bigbinary/neeto-playwright-commons 1.9.33 → 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/index.js CHANGED
@@ -3,24 +3,25 @@ import * as fs$d from 'fs';
3
3
  import fs__default, { writeFileSync as writeFileSync$1, unlinkSync, readFileSync } from 'fs';
4
4
  import test$1, { expect, test as test$2, defineConfig, devices } from '@playwright/test';
5
5
  import { curry, not, isEmpty as isEmpty$1, isNil, isNotNil, mergeDeepLeft, mergeAll } from 'ramda';
6
- import require$$0$2 from 'util';
6
+ import require$$0$1 from 'util';
7
7
  import * as Path from 'path';
8
8
  import Path__default from 'path';
9
9
  import { faker } from '@faker-js/faker';
10
10
  import MailosaurClient from 'mailosaur';
11
11
  import dayjs from 'dayjs';
12
- import require$$0$4 from 'tty';
13
- import require$$0$3 from 'os';
12
+ import require$$0$3 from 'tty';
13
+ import require$$0$2 from 'os';
14
+ import stealth$1 from 'puppeteer-extra-plugin-stealth';
14
15
  import Stream$4 from 'stream';
15
- import require$$0$5 from 'events';
16
+ import require$$0$4 from 'events';
16
17
  import { getI18nInstance, initI18n } from 'playwright-i18next-fixture';
17
18
  import { isNotEmpty, humanize, hyphenate, isPresent, dynamicArray, isNotPresent } from '@bigbinary/neeto-cist';
18
19
  import http$1 from 'http';
19
20
  import Url from 'url';
20
- import require$$0$6 from 'punycode';
21
+ import require$$0$5 from 'punycode';
21
22
  import https$1 from 'https';
22
23
  import zlib$5 from 'zlib';
23
- import require$$0$7 from 'assert';
24
+ import require$$0$6 from 'assert';
24
25
  import require$$3 from 'buffer';
25
26
  import require$$3$1 from 'querystring';
26
27
  import require$$1$1 from 'string_decoder';
@@ -1828,7 +1829,7 @@ var callBound$1 = function callBoundIntrinsic(name, allowMissing) {
1828
1829
  return intrinsic;
1829
1830
  };
1830
1831
 
1831
- var util_inspect = require$$0$2.inspect;
1832
+ var util_inspect = require$$0$1.inspect;
1832
1833
 
1833
1834
  var hasMap = typeof Map === 'function' && Map.prototype;
1834
1835
  var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
@@ -2549,7 +2550,7 @@ var arrayToObject = function arrayToObject(source, options) {
2549
2550
  return obj;
2550
2551
  };
2551
2552
 
2552
- var merge$3 = function merge(target, source, options) {
2553
+ var merge$2 = function merge(target, source, options) {
2553
2554
  /* eslint no-param-reassign: 0 */
2554
2555
  if (!source) {
2555
2556
  return target;
@@ -2766,7 +2767,7 @@ var utils$o = {
2766
2767
  isBuffer: isBuffer,
2767
2768
  isRegExp: isRegExp,
2768
2769
  maybeMap: maybeMap,
2769
- merge: merge$3
2770
+ merge: merge$2
2770
2771
  };
2771
2772
 
2772
2773
  var getSideChannel = sideChannel;
@@ -3174,6 +3175,7 @@ var parseValues = function parseQueryStringValues(str, options) {
3174
3175
  var obj = { __proto__: null };
3175
3176
 
3176
3177
  var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
3178
+ cleanStr = cleanStr.replace(/%5B/gi, '[').replace(/%5D/gi, ']');
3177
3179
  var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
3178
3180
  var parts = cleanStr.split(options.delimiter, limit);
3179
3181
  var skipIndex = -1; // Keep track of where the utf8 sentinel was found
@@ -4424,7 +4426,7 @@ var hasRequiredSupportsColor;
4424
4426
  function requireSupportsColor () {
4425
4427
  if (hasRequiredSupportsColor) return supportsColor_1;
4426
4428
  hasRequiredSupportsColor = 1;
4427
- const os = require$$0$3;
4429
+ const os = require$$0$2;
4428
4430
  const hasFlag = requireHasFlag();
4429
4431
 
4430
4432
  const env = process.env;
@@ -4568,8 +4570,8 @@ function requireNode () {
4568
4570
  if (hasRequiredNode) return node.exports;
4569
4571
  hasRequiredNode = 1;
4570
4572
  (function (module, exports) {
4571
- const tty = require$$0$4;
4572
- const util = require$$0$2;
4573
+ const tty = require$$0$3;
4574
+ const util = require$$0$1;
4573
4575
 
4574
4576
  /**
4575
4577
  * This is the Node.js implementation of `debug()`.
@@ -4843,7 +4845,7 @@ if (typeof process === 'undefined' || process.type === 'renderer' || process.bro
4843
4845
  }
4844
4846
 
4845
4847
  var srcExports = src$1.exports;
4846
- var debug$3 = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
4848
+ var Debug = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
4847
4849
 
4848
4850
  /*!
4849
4851
  * playwright-extra v4.3.5 by berstend
@@ -4926,7 +4928,7 @@ const playwrightLoader = new Loader('playwright', [
4926
4928
  'playwright'
4927
4929
  ]);
4928
4930
 
4929
- const debug = debug$3('playwright-extra:puppeteer-compat');
4931
+ const debug = Debug('playwright-extra:puppeteer-compat');
4930
4932
  const isPlaywrightPage = (obj) => {
4931
4933
  return 'unroute' in obj;
4932
4934
  };
@@ -5116,7 +5118,7 @@ function createBrowserShim(browser) {
5116
5118
  return shim;
5117
5119
  }
5118
5120
 
5119
- const debug$1 = debug$3('playwright-extra:plugins');
5121
+ const debug$1 = Debug('playwright-extra:plugins');
5120
5122
  class PluginList {
5121
5123
  constructor() {
5122
5124
  this._plugins = [];
@@ -5457,7 +5459,7 @@ If your bundler has issues with dynamic imports take a look at '.plugins.setDepe
5457
5459
  }
5458
5460
  }
5459
5461
 
5460
- const debug$2 = debug$3('playwright-extra');
5462
+ const debug$2 = Debug('playwright-extra');
5461
5463
  /**
5462
5464
  * Modular plugin framework to teach `playwright` new tricks.
5463
5465
  */
@@ -5735,715 +5737,6 @@ playwrightLoader.lazyloadExportOrDie('selectors');
5735
5737
  playwrightLoader.lazyloadExportOrDie('devices');
5736
5738
  playwrightLoader.lazyloadExportOrDie('errors');
5737
5739
 
5738
- /*!
5739
- * puppeteer-extra-plugin v3.2.2 by berstend
5740
- * https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin
5741
- * @license MIT
5742
- */
5743
-
5744
- /** @private */
5745
- const merge$2 = require('merge-deep');
5746
- /**
5747
- * Base class for `puppeteer-extra` plugins.
5748
- *
5749
- * Provides convenience methods to avoid boilerplate.
5750
- *
5751
- * All common `puppeteer` browser events will be bound to
5752
- * the plugin instance, if a respectively named class member is found.
5753
- *
5754
- * Please refer to the [puppeteer API documentation](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md) as well.
5755
- *
5756
- * @example
5757
- * // hello-world-plugin.js
5758
- * const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
5759
- *
5760
- * class Plugin extends PuppeteerExtraPlugin {
5761
- * constructor (opts = { }) { super(opts) }
5762
- *
5763
- * get name () { return 'hello-world' }
5764
- *
5765
- * async onPageCreated (page) {
5766
- * this.debug('page created', page.url())
5767
- * const ua = await page.browser().userAgent()
5768
- * this.debug('user agent', ua)
5769
- * }
5770
- * }
5771
- *
5772
- * module.exports = function (pluginConfig) { return new Plugin(pluginConfig) }
5773
- *
5774
- *
5775
- * // foo.js
5776
- * const puppeteer = require('puppeteer-extra')
5777
- * puppeteer.use(require('./hello-world-plugin')())
5778
- *
5779
- * ;(async () => {
5780
- * const browser = await puppeteer.launch({headless: false})
5781
- * const page = await browser.newPage()
5782
- * await page.goto('http://example.com', {waitUntil: 'domcontentloaded'})
5783
- * await browser.close()
5784
- * })()
5785
- *
5786
- */
5787
- class PuppeteerExtraPlugin$1 {
5788
- constructor(opts) {
5789
- this._debugBase = debug$3(`puppeteer-extra-plugin:base:${this.name}`);
5790
- this._childClassMembers = [];
5791
- this._opts = merge$2(this.defaults, opts || {});
5792
- this._debugBase('Initialized.');
5793
- }
5794
- /**
5795
- * Plugin name (required).
5796
- *
5797
- * Convention:
5798
- * - Package: `puppeteer-extra-plugin-anonymize-ua`
5799
- * - Name: `anonymize-ua`
5800
- *
5801
- * @example
5802
- * get name () { return 'anonymize-ua' }
5803
- */
5804
- get name() {
5805
- throw new Error('Plugin must override "name"');
5806
- }
5807
- /**
5808
- * Plugin defaults (optional).
5809
- *
5810
- * If defined will be ([deep-](https://github.com/jonschlinkert/merge-deep))merged with the (optional) user supplied options (supplied during plugin instantiation).
5811
- *
5812
- * The result of merging defaults with user supplied options can be accessed through `this.opts`.
5813
- *
5814
- * @see [[opts]]
5815
- *
5816
- * @example
5817
- * get defaults () {
5818
- * return {
5819
- * stripHeadless: true,
5820
- * makeWindows: true,
5821
- * customFn: null
5822
- * }
5823
- * }
5824
- *
5825
- * // Users can overwrite plugin defaults during instantiation:
5826
- * puppeteer.use(require('puppeteer-extra-plugin-foobar')({ makeWindows: false }))
5827
- */
5828
- get defaults() {
5829
- return {};
5830
- }
5831
- /**
5832
- * Plugin requirements (optional).
5833
- *
5834
- * Signal certain plugin requirements to the base class and the user.
5835
- *
5836
- * Currently supported:
5837
- * - `launch`
5838
- * - If the plugin only supports locally created browser instances (no `puppeteer.connect()`),
5839
- * will output a warning to the user.
5840
- * - `headful`
5841
- * - If the plugin doesn't work in `headless: true` mode,
5842
- * will output a warning to the user.
5843
- * - `dataFromPlugins`
5844
- * - In case the plugin requires data from other plugins.
5845
- * will enable usage of `this.getDataFromPlugins()`.
5846
- * - `runLast`
5847
- * - In case the plugin prefers to run after the others.
5848
- * Useful when the plugin needs data from others.
5849
- *
5850
- * @example
5851
- * get requirements () {
5852
- * return new Set(['runLast', 'dataFromPlugins'])
5853
- * }
5854
- */
5855
- get requirements() {
5856
- return new Set([]);
5857
- }
5858
- /**
5859
- * Plugin dependencies (optional).
5860
- *
5861
- * Missing plugins will be required() by puppeteer-extra.
5862
- *
5863
- * @example
5864
- * get dependencies () {
5865
- * return new Set(['user-preferences'])
5866
- * }
5867
- * // Will ensure the 'puppeteer-extra-plugin-user-preferences' plugin is loaded.
5868
- */
5869
- get dependencies() {
5870
- return new Set([]);
5871
- }
5872
- /**
5873
- * Plugin data (optional).
5874
- *
5875
- * Plugins can expose data (an array of objects), which in turn can be consumed by other plugins,
5876
- * that list the `dataFromPlugins` requirement (by using `this.getDataFromPlugins()`).
5877
- *
5878
- * Convention: `[ {name: 'Any name', value: 'Any value'} ]`
5879
- *
5880
- * @see [[getDataFromPlugins]]
5881
- *
5882
- * @example
5883
- * // plugin1.js
5884
- * get data () {
5885
- * return [
5886
- * {
5887
- * name: 'userPreferences',
5888
- * value: { foo: 'bar' }
5889
- * },
5890
- * {
5891
- * name: 'userPreferences',
5892
- * value: { hello: 'world' }
5893
- * }
5894
- * ]
5895
- *
5896
- * // plugin2.js
5897
- * get requirements () { return new Set(['dataFromPlugins']) }
5898
- *
5899
- * async beforeLaunch () {
5900
- * const prefs = this.getDataFromPlugins('userPreferences').map(d => d.value)
5901
- * this.debug(prefs) // => [ { foo: 'bar' }, { hello: 'world' } ]
5902
- * }
5903
- */
5904
- get data() {
5905
- return [];
5906
- }
5907
- /**
5908
- * Access the plugin options (usually the `defaults` merged with user defined options)
5909
- *
5910
- * To skip the auto-merging of defaults with user supplied opts don't define a `defaults`
5911
- * property and set the `this._opts` Object in your plugin constructor directly.
5912
- *
5913
- * @see [[defaults]]
5914
- *
5915
- * @example
5916
- * get defaults () { return { foo: "bar" } }
5917
- *
5918
- * async onPageCreated (page) {
5919
- * this.debug(this.opts.foo) // => bar
5920
- * }
5921
- */
5922
- get opts() {
5923
- return this._opts;
5924
- }
5925
- /**
5926
- * Convenience debug logger based on the [debug] module.
5927
- * Will automatically namespace the logging output to the plugin package name.
5928
- * [debug]: https://www.npmjs.com/package/debug
5929
- *
5930
- * ```bash
5931
- * # toggle output using environment variables
5932
- * DEBUG=puppeteer-extra-plugin:<plugin_name> node foo.js
5933
- * # to debug all the things:
5934
- * DEBUG=puppeteer-extra,puppeteer-extra-plugin:* node foo.js
5935
- * ```
5936
- *
5937
- * @example
5938
- * this.debug('hello world')
5939
- * // will output e.g. 'puppeteer-extra-plugin:anonymize-ua hello world'
5940
- */
5941
- get debug() {
5942
- return debug$3(`puppeteer-extra-plugin:${this.name}`);
5943
- }
5944
- /**
5945
- * Before a new browser instance is created/launched.
5946
- *
5947
- * Can be used to modify the puppeteer launch options by modifying or returning them.
5948
- *
5949
- * Plugins using this method will be called in sequence to each
5950
- * be able to update the launch options.
5951
- *
5952
- * @example
5953
- * async beforeLaunch (options) {
5954
- * if (this.opts.flashPluginPath) {
5955
- * options.args.push(`--ppapi-flash-path=${this.opts.flashPluginPath}`)
5956
- * }
5957
- * }
5958
- *
5959
- * @param options - Puppeteer launch options
5960
- */
5961
- async beforeLaunch(options) {
5962
- // noop
5963
- }
5964
- /**
5965
- * After the browser has launched.
5966
- *
5967
- * Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
5968
- * It's possible that `pupeeteer.launch` will be called multiple times and more than one browser created.
5969
- * In order to make the plugins as stateless as possible don't store a reference to the browser instance
5970
- * in the plugin but rather consider alternatives.
5971
- *
5972
- * E.g. when using `onPageCreated` you can get a browser reference by using `page.browser()`.
5973
- *
5974
- * Alternatively you could expose a class method that takes a browser instance as a parameter to work with:
5975
- *
5976
- * ```es6
5977
- * const fancyPlugin = require('puppeteer-extra-plugin-fancy')()
5978
- * puppeteer.use(fancyPlugin)
5979
- * const browser = await puppeteer.launch()
5980
- * await fancyPlugin.killBrowser(browser)
5981
- * ```
5982
- *
5983
- * @param browser - The `puppeteer` browser instance.
5984
- * @param opts.options - Puppeteer launch options used.
5985
- *
5986
- * @example
5987
- * async afterLaunch (browser, opts) {
5988
- * this.debug('browser has been launched', opts.options)
5989
- * }
5990
- */
5991
- async afterLaunch(browser, opts = { options: {} }) {
5992
- // noop
5993
- }
5994
- /**
5995
- * Before connecting to an existing browser instance.
5996
- *
5997
- * Can be used to modify the puppeteer connect options by modifying or returning them.
5998
- *
5999
- * Plugins using this method will be called in sequence to each
6000
- * be able to update the launch options.
6001
- *
6002
- * @param {Object} options - Puppeteer connect options
6003
- * @return {Object=}
6004
- */
6005
- async beforeConnect(options) {
6006
- // noop
6007
- }
6008
- /**
6009
- * After connecting to an existing browser instance.
6010
- *
6011
- * > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
6012
- *
6013
- * @param browser - The `puppeteer` browser instance.
6014
- * @param {Object} opts
6015
- * @param {Object} opts.options - Puppeteer connect options used.
6016
- *
6017
- */
6018
- async afterConnect(browser, opts = {}) {
6019
- // noop
6020
- }
6021
- /**
6022
- * Called when a browser instance is available.
6023
- *
6024
- * This applies to both `puppeteer.launch()` and `puppeteer.connect()`.
6025
- *
6026
- * Convenience method created for plugins that need access to a browser instance
6027
- * and don't mind if it has been created through `launch` or `connect`.
6028
- *
6029
- * > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
6030
- *
6031
- * @param browser - The `puppeteer` browser instance.
6032
- */
6033
- async onBrowser(browser, opts) {
6034
- // noop
6035
- }
6036
- /**
6037
- * Called when a target is created, for example when a new page is opened by window.open or browser.newPage.
6038
- *
6039
- * > Note: This includes target creations in incognito browser contexts.
6040
- *
6041
- * > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
6042
- *
6043
- * @param {Puppeteer.Target} target
6044
- */
6045
- async onTargetCreated(target) {
6046
- // noop
6047
- }
6048
- /**
6049
- * Same as `onTargetCreated` but prefiltered to only contain Pages, for convenience.
6050
- *
6051
- * > Note: This includes page creations in incognito browser contexts.
6052
- *
6053
- * > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
6054
- *
6055
- * @param {Puppeteer.Target} target
6056
- *
6057
- * @example
6058
- * async onPageCreated (page) {
6059
- * let ua = await page.browser().userAgent()
6060
- * if (this.opts.stripHeadless) {
6061
- * ua = ua.replace('HeadlessChrome/', 'Chrome/')
6062
- * }
6063
- * this.debug('new ua', ua)
6064
- * await page.setUserAgent(ua)
6065
- * }
6066
- */
6067
- async onPageCreated(page) {
6068
- // noop
6069
- }
6070
- /**
6071
- * Called when the url of a target changes.
6072
- *
6073
- * > Note: This includes target changes in incognito browser contexts.
6074
- *
6075
- * > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
6076
- *
6077
- * @param {Puppeteer.Target} target
6078
- */
6079
- async onTargetChanged(target) {
6080
- // noop
6081
- }
6082
- /**
6083
- * Called when a target is destroyed, for example when a page is closed.
6084
- *
6085
- * > Note: This includes target destructions in incognito browser contexts.
6086
- *
6087
- * > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
6088
- *
6089
- * @param {Puppeteer.Target} target
6090
- */
6091
- async onTargetDestroyed(target) {
6092
- // noop
6093
- }
6094
- /**
6095
- * Called when Puppeteer gets disconnected from the Chromium instance.
6096
- *
6097
- * This might happen because of one of the following:
6098
- * - Chromium is closed or crashed
6099
- * - The `browser.disconnect` method was called
6100
- */
6101
- async onDisconnected() {
6102
- // noop
6103
- }
6104
- /**
6105
- * **Deprecated:** Since puppeteer v1.6.0 `onDisconnected` has been improved
6106
- * and should be used instead of `onClose`.
6107
- *
6108
- * In puppeteer < v1.6.0 `onDisconnected` was not catching all exit scenarios.
6109
- * In order for plugins to clean up properly (e.g. deleting temporary files)
6110
- * the `onClose` method had been introduced.
6111
- *
6112
- * > Note: Might be called multiple times on exit.
6113
- *
6114
- * > Note: This only includes browser instances created through `.launch()`.
6115
- */
6116
- async onClose() {
6117
- // noop
6118
- }
6119
- /**
6120
- * After the plugin has been registered in `puppeteer-extra`.
6121
- *
6122
- * Normally right after `puppeteer.use(plugin)` is called
6123
- */
6124
- async onPluginRegistered() {
6125
- // noop
6126
- }
6127
- /**
6128
- * Helper method to retrieve `data` objects from other plugins.
6129
- *
6130
- * A plugin needs to state the `dataFromPlugins` requirement
6131
- * in order to use this method. Will be mapped to `puppeteer.getPluginData`.
6132
- *
6133
- * @param name - Filter data by `name` property
6134
- *
6135
- * @see [data]
6136
- * @see [requirements]
6137
- */
6138
- getDataFromPlugins(name) {
6139
- return [];
6140
- }
6141
- /**
6142
- * Will match plugin dependencies against all currently registered plugins.
6143
- * Is being called by `puppeteer-extra` and used to require missing dependencies.
6144
- *
6145
- * @param {Array<Object>} plugins
6146
- * @return {Set} - list of missing plugin names
6147
- *
6148
- * @private
6149
- */
6150
- _getMissingDependencies(plugins) {
6151
- const pluginNames = new Set(plugins.map((p) => p.name));
6152
- const missing = new Set(Array.from(this.dependencies.values()).filter(x => !pluginNames.has(x)));
6153
- return missing;
6154
- }
6155
- /**
6156
- * Conditionally bind browser/process events to class members.
6157
- * The idea is to reduce event binding boilerplate in plugins.
6158
- *
6159
- * For efficiency we make sure the plugin is using the respective event
6160
- * by checking the child class members before registering the listener.
6161
- *
6162
- * @param {<Puppeteer.Browser>} browser
6163
- * @param {Object} opts - Options
6164
- * @param {string} opts.context - Puppeteer context (launch/connect)
6165
- * @param {Object} [opts.options] - Puppeteer launch or connect options
6166
- * @param {Array<string>} [opts.defaultArgs] - The default flags that Chromium will be launched with
6167
- *
6168
- * @private
6169
- */
6170
- async _bindBrowserEvents(browser, opts = {}) {
6171
- if (this._hasChildClassMember('onTargetCreated') ||
6172
- this._hasChildClassMember('onPageCreated')) {
6173
- browser.on('targetcreated', this._onTargetCreated.bind(this));
6174
- }
6175
- if (this._hasChildClassMember('onTargetChanged') && this.onTargetChanged) {
6176
- browser.on('targetchanged', this.onTargetChanged.bind(this));
6177
- }
6178
- if (this._hasChildClassMember('onTargetDestroyed') &&
6179
- this.onTargetDestroyed) {
6180
- browser.on('targetdestroyed', this.onTargetDestroyed.bind(this));
6181
- }
6182
- if (this._hasChildClassMember('onDisconnected') && this.onDisconnected) {
6183
- browser.on('disconnected', this.onDisconnected.bind(this));
6184
- }
6185
- if (opts.context === 'launch' && this._hasChildClassMember('onClose')) {
6186
- // The disconnect event has been improved since puppeteer v1.6.0
6187
- // onClose is being kept mostly for legacy reasons
6188
- if (this.onClose) {
6189
- process.on('exit', this.onClose.bind(this));
6190
- browser.on('disconnected', this.onClose.bind(this));
6191
- if (opts.options.handleSIGINT !== false) {
6192
- process.on('SIGINT', this.onClose.bind(this));
6193
- }
6194
- if (opts.options.handleSIGTERM !== false) {
6195
- process.on('SIGTERM', this.onClose.bind(this));
6196
- }
6197
- if (opts.options.handleSIGHUP !== false) {
6198
- process.on('SIGHUP', this.onClose.bind(this));
6199
- }
6200
- }
6201
- }
6202
- if (opts.context === 'launch' && this.afterLaunch) {
6203
- await this.afterLaunch(browser, opts);
6204
- }
6205
- if (opts.context === 'connect' && this.afterConnect) {
6206
- await this.afterConnect(browser, opts);
6207
- }
6208
- if (this.onBrowser)
6209
- await this.onBrowser(browser, opts);
6210
- }
6211
- /**
6212
- * @private
6213
- */
6214
- async _onTargetCreated(target) {
6215
- if (this.onTargetCreated)
6216
- await this.onTargetCreated(target);
6217
- // Pre filter pages for plugin developers convenience
6218
- if (target.type() === 'page') {
6219
- try {
6220
- const page = await target.page();
6221
- if (!page) {
6222
- return;
6223
- }
6224
- const validPage = 'isClosed' in page && !page.isClosed();
6225
- if (this.onPageCreated && validPage) {
6226
- await this.onPageCreated(page);
6227
- }
6228
- }
6229
- catch (err) {
6230
- console.error(err);
6231
- }
6232
- }
6233
- }
6234
- /**
6235
- * @private
6236
- */
6237
- _register(prototype) {
6238
- this._registerChildClassMembers(prototype);
6239
- if (this.onPluginRegistered)
6240
- this.onPluginRegistered();
6241
- }
6242
- /**
6243
- * @private
6244
- */
6245
- _registerChildClassMembers(prototype) {
6246
- this._childClassMembers = Object.getOwnPropertyNames(prototype);
6247
- }
6248
- /**
6249
- * @private
6250
- */
6251
- _hasChildClassMember(name) {
6252
- return !!this._childClassMembers.includes(name);
6253
- }
6254
- /**
6255
- * @private
6256
- */
6257
- get _isPuppeteerExtraPlugin() {
6258
- return true;
6259
- }
6260
- }
6261
-
6262
- var index_esm = /*#__PURE__*/Object.freeze({
6263
- __proto__: null,
6264
- PuppeteerExtraPlugin: PuppeteerExtraPlugin$1
6265
- });
6266
-
6267
- var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(index_esm);
6268
-
6269
- const { PuppeteerExtraPlugin } = require$$0$1;
6270
-
6271
- /**
6272
- * Stealth mode: Applies various techniques to make detection of headless puppeteer harder. 💯
6273
- *
6274
- * ### Purpose
6275
- * There are a couple of ways the use of puppeteer can easily be detected by a target website.
6276
- * The addition of `HeadlessChrome` to the user-agent being only the most obvious one.
6277
- *
6278
- * The goal of this plugin is to be the definite companion to puppeteer to avoid
6279
- * detection, applying new techniques as they surface.
6280
- *
6281
- * As this cat & mouse game is in it's infancy and fast-paced the plugin
6282
- * is kept as flexibile as possible, to support quick testing and iterations.
6283
- *
6284
- * ### Modularity
6285
- * This plugin uses `puppeteer-extra`'s dependency system to only require
6286
- * code mods for evasions that have been enabled, to keep things modular and efficient.
6287
- *
6288
- * The `stealth` plugin is a convenience wrapper that requires multiple [evasion techniques](./evasions/)
6289
- * automatically and comes with defaults. You could also bypass the main module and require
6290
- * specific evasion plugins yourself, if you whish to do so (as they're standalone `puppeteer-extra` plugins):
6291
- *
6292
- * ```es6
6293
- * // bypass main module and require a specific stealth plugin directly:
6294
- * puppeteer.use(require('puppeteer-extra-plugin-stealth/evasions/console.debug')())
6295
- * ```
6296
- *
6297
- * ### Contributing
6298
- * PRs are welcome, if you want to add a new evasion technique I suggest you
6299
- * look at the [template](./evasions/_template) to kickstart things.
6300
- *
6301
- * ### Kudos
6302
- * Thanks to [Evan Sangaline](https://intoli.com/blog/not-possible-to-block-chrome-headless/) and [Paul Irish](https://github.com/paulirish/headless-cat-n-mouse) for kickstarting the discussion!
6303
- *
6304
- * ---
6305
- *
6306
- * @todo
6307
- * - white-/blacklist with url globs (make this a generic plugin method?)
6308
- * - dynamic whitelist based on function evaluation
6309
- *
6310
- * @example
6311
- * const puppeteer = require('puppeteer-extra')
6312
- * // Enable stealth plugin with all evasions
6313
- * puppeteer.use(require('puppeteer-extra-plugin-stealth')())
6314
- *
6315
- *
6316
- * ;(async () => {
6317
- * // Launch the browser in headless mode and set up a page.
6318
- * const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true })
6319
- * const page = await browser.newPage()
6320
- *
6321
- * // Navigate to the page that will perform the tests.
6322
- * const testUrl = 'https://intoli.com/blog/' +
6323
- * 'not-possible-to-block-chrome-headless/chrome-headless-test.html'
6324
- * await page.goto(testUrl)
6325
- *
6326
- * // Save a screenshot of the results.
6327
- * const screenshotPath = '/tmp/headless-test-result.png'
6328
- * await page.screenshot({path: screenshotPath})
6329
- * console.log('have a look at the screenshot:', screenshotPath)
6330
- *
6331
- * await browser.close()
6332
- * })()
6333
- *
6334
- * @param {Object} [opts] - Options
6335
- * @param {Set<string>} [opts.enabledEvasions] - Specify which evasions to use (by default all)
6336
- *
6337
- */
6338
- class StealthPlugin extends PuppeteerExtraPlugin {
6339
- constructor(opts = {}) {
6340
- super(opts);
6341
- }
6342
-
6343
- get name() {
6344
- return 'stealth'
6345
- }
6346
-
6347
- get defaults() {
6348
- const availableEvasions = new Set([
6349
- 'chrome.app',
6350
- 'chrome.csi',
6351
- 'chrome.loadTimes',
6352
- 'chrome.runtime',
6353
- 'defaultArgs',
6354
- 'iframe.contentWindow',
6355
- 'media.codecs',
6356
- 'navigator.hardwareConcurrency',
6357
- 'navigator.languages',
6358
- 'navigator.permissions',
6359
- 'navigator.plugins',
6360
- 'navigator.webdriver',
6361
- 'sourceurl',
6362
- 'user-agent-override',
6363
- 'webgl.vendor',
6364
- 'window.outerdimensions'
6365
- ]);
6366
- return {
6367
- availableEvasions,
6368
- // Enable all available evasions by default
6369
- enabledEvasions: new Set([...availableEvasions])
6370
- }
6371
- }
6372
-
6373
- /**
6374
- * Requires evasion techniques dynamically based on configuration.
6375
- *
6376
- * @private
6377
- */
6378
- get dependencies() {
6379
- return new Set(
6380
- [...this.opts.enabledEvasions].map(e => `${this.name}/evasions/${e}`)
6381
- )
6382
- }
6383
-
6384
- /**
6385
- * Get all available evasions.
6386
- *
6387
- * Please look into the [evasions directory](./evasions/) for an up to date list.
6388
- *
6389
- * @type {Set<string>} - A Set of all available evasions.
6390
- *
6391
- * @example
6392
- * const pluginStealth = require('puppeteer-extra-plugin-stealth')()
6393
- * console.log(pluginStealth.availableEvasions) // => Set { 'user-agent', 'console.debug' }
6394
- * puppeteer.use(pluginStealth)
6395
- */
6396
- get availableEvasions() {
6397
- return this.defaults.availableEvasions
6398
- }
6399
-
6400
- /**
6401
- * Get all enabled evasions.
6402
- *
6403
- * Enabled evasions can be configured either through `opts` or by modifying this property.
6404
- *
6405
- * @type {Set<string>} - A Set of all enabled evasions.
6406
- *
6407
- * @example
6408
- * // Remove specific evasion from enabled ones dynamically
6409
- * const pluginStealth = require('puppeteer-extra-plugin-stealth')()
6410
- * pluginStealth.enabledEvasions.delete('console.debug')
6411
- * puppeteer.use(pluginStealth)
6412
- */
6413
- get enabledEvasions() {
6414
- return this.opts.enabledEvasions
6415
- }
6416
-
6417
- /**
6418
- * @private
6419
- */
6420
- set enabledEvasions(evasions) {
6421
- this.opts.enabledEvasions = evasions;
6422
- }
6423
-
6424
- async onBrowser(browser) {
6425
- if (browser && browser.setMaxListeners) {
6426
- // Increase event emitter listeners to prevent MaxListenersExceededWarning
6427
- browser.setMaxListeners(30);
6428
- }
6429
- }
6430
- }
6431
-
6432
- /**
6433
- * Default export, PuppeteerExtraStealthPlugin
6434
- *
6435
- * @param {Object} [opts] - Options
6436
- * @param {Set<string>} [opts.enabledEvasions] - Specify which evasions to use (by default all)
6437
- */
6438
- const defaultExport = opts => new StealthPlugin(opts);
6439
- var puppeteerExtraPluginStealth = defaultExport;
6440
-
6441
- // const moduleExport = defaultExport
6442
- // moduleExport.StealthPlugin = StealthPlugin
6443
- // module.exports = moduleExport
6444
-
6445
- var stealth$1 = /*@__PURE__*/getDefaultExportFromCjs(puppeteerExtraPluginStealth);
6446
-
6447
5740
  var stealth = test$2.extend({
6448
5741
  browser: async ({ browser }, use) => {
6449
5742
  await browser.close();
@@ -6572,7 +5865,7 @@ var path$a = {};
6572
5865
 
6573
5866
  Object.defineProperty(path$a, "__esModule", { value: true });
6574
5867
  path$a.convertPosixPathToPattern = path$a.convertWindowsPathToPattern = path$a.convertPathToPattern = path$a.escapePosixPath = path$a.escapeWindowsPath = path$a.escape = path$a.removeLeadingDotSegment = path$a.makeAbsolute = path$a.unixify = void 0;
6575
- const os$1 = require$$0$3;
5868
+ const os$1 = require$$0$2;
6576
5869
  const path$9 = Path__default;
6577
5870
  const IS_WINDOWS_PLATFORM = os$1.platform() === 'win32';
6578
5871
  const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
@@ -6814,7 +6107,7 @@ var isGlob$1 = function isGlob(str, options) {
6814
6107
 
6815
6108
  var isGlob = isGlob$1;
6816
6109
  var pathPosixDirname = Path__default.posix.dirname;
6817
- var isWin32 = require$$0$3.platform() === 'win32';
6110
+ var isWin32 = require$$0$2.platform() === 'win32';
6818
6111
 
6819
6112
  var slash = '/';
6820
6113
  var backslash = /\\/g;
@@ -7310,7 +6603,7 @@ var toRegexRange_1 = toRegexRange$1;
7310
6603
  * Licensed under the MIT License.
7311
6604
  */
7312
6605
 
7313
- const util$8 = require$$0$2;
6606
+ const util$8 = require$$0$1;
7314
6607
  const toRegexRange = toRegexRange_1;
7315
6608
 
7316
6609
  const isObject$2 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
@@ -10342,7 +9635,7 @@ var picomatch_1 = picomatch$2;
10342
9635
 
10343
9636
  var picomatch$1 = picomatch_1;
10344
9637
 
10345
- const util$7 = require$$0$2;
9638
+ const util$7 = require$$0$1;
10346
9639
  const braces = braces_1;
10347
9640
  const picomatch = picomatch$1;
10348
9641
  const utils$c = utils$g;
@@ -12176,7 +11469,7 @@ class Reader$1 {
12176
11469
  reader$1.default = Reader$1;
12177
11470
 
12178
11471
  Object.defineProperty(async$4, "__esModule", { value: true });
12179
- const events_1 = require$$0$5;
11472
+ const events_1 = require$$0$4;
12180
11473
  const fsScandir$2 = out$2;
12181
11474
  const fastq = queueExports;
12182
11475
  const common$2 = common$4;
@@ -13047,7 +12340,7 @@ var settings = {};
13047
12340
  Object.defineProperty(exports, "__esModule", { value: true });
13048
12341
  exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
13049
12342
  const fs = fs__default;
13050
- const os = require$$0$3;
12343
+ const os = require$$0$2;
13051
12344
  /**
13052
12345
  * The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
13053
12346
  * https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
@@ -13505,7 +12798,7 @@ class EmbedBase {
13505
12798
  }
13506
12799
 
13507
12800
  const CHAT_WIDGET_TEXTS = {
13508
- newConversation: "New Conversation",
12801
+ newConversation: "Ask a question",
13509
12802
  welcomeChatBubble: "Hi! I'm here to assist you with any questions you may have. What can I do for you?",
13510
12803
  };
13511
12804
  const MEMBER_TEXTS = {
@@ -17356,12 +16649,12 @@ function intToRGBA(i) {
17356
16649
  a
17357
16650
  };
17358
16651
  }
17359
- const c$1 = [];
16652
+ const c = [];
17360
16653
  function initCoefficients(size) {
17361
16654
  for (let i = 1; i < size; i++) {
17362
- c$1[i] = 1;
16655
+ c[i] = 1;
17363
16656
  }
17364
- c$1[0] = 1 / Math.sqrt(2.0);
16657
+ c[0] = 1 / Math.sqrt(2.0);
17365
16658
  }
17366
16659
  function applyDCT(f, size) {
17367
16660
  const N = size;
@@ -17375,7 +16668,7 @@ function applyDCT(f, size) {
17375
16668
  sum += Math.cos((2 * i + 1) / (2.0 * N) * u * Math.PI) * Math.cos((2 * j + 1) / (2.0 * N) * v * Math.PI) * f[i][j];
17376
16669
  }
17377
16670
  }
17378
- sum *= c$1[u] * c$1[v] / 4;
16671
+ sum *= c[u] * c[v] / 4;
17379
16672
  F[u][v] = sum;
17380
16673
  }
17381
16674
  }
@@ -95260,7 +94553,7 @@ var require$$1 = [
95260
94553
  ]
95261
94554
  ];
95262
94555
 
95263
- var punycode = require$$0$6;
94556
+ var punycode = require$$0$5;
95264
94557
  var mappingTable = require$$1;
95265
94558
 
95266
94559
  var PROCESSING_OPTIONS = {
@@ -95455,7 +94748,7 @@ tr46.PROCESSING_OPTIONS = PROCESSING_OPTIONS;
95455
94748
  urlStateMachine.exports;
95456
94749
 
95457
94750
  (function (module) {
95458
- const punycode = require$$0$6;
94751
+ const punycode = require$$0$5;
95459
94752
  const tr46$1 = tr46;
95460
94753
 
95461
94754
  const specialSchemes = {
@@ -99082,7 +98375,7 @@ function multiply(src, dst) {
99082
98375
  a
99083
98376
  };
99084
98377
  }
99085
- function add(src, dst) {
98378
+ function add$1(src, dst) {
99086
98379
  let ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
99087
98380
  src.a *= ops;
99088
98381
  const a = dst.a + src.a - dst.a * src.a;
@@ -99248,7 +98541,7 @@ var compositeModes = /*#__PURE__*/Object.freeze({
99248
98541
  srcOver: srcOver,
99249
98542
  dstOver: dstOver,
99250
98543
  multiply: multiply,
99251
- add: add,
98544
+ add: add$1,
99252
98545
  screen: screen,
99253
98546
  overlay: overlay,
99254
98547
  darken: darken,
@@ -104011,7 +103304,7 @@ const emptyBitmap = {
104011
103304
  * @param {function(Error, Jimp)} cb (optional) a function to call when the image is parsed to a bitmap
104012
103305
  */
104013
103306
 
104014
- class Jimp$1 extends require$$0$5 {
103307
+ class Jimp$1 extends require$$0$4 {
104015
103308
  // An object representing a bitmap in memory, comprising:
104016
103309
  // - data: a buffer of the bitmap data
104017
103310
  // - width: the width of the image in pixels
@@ -107623,7 +106916,7 @@ var parserAsync = {exports: {}};
107623
106916
 
107624
106917
  var chunkstream = {exports: {}};
107625
106918
 
107626
- let util$5 = require$$0$2;
106919
+ let util$5 = require$$0$1;
107627
106920
  let Stream$2 = Stream$4;
107628
106921
 
107629
106922
  let ChunkStream$2 = (chunkstream.exports = function () {
@@ -108106,7 +107399,7 @@ Filter$2.prototype._reverseFilterLine = function (rawData) {
108106
107399
 
108107
107400
  var filterParseExports = filterParse.exports;
108108
107401
 
108109
- let util$4 = require$$0$2;
107402
+ let util$4 = require$$0$1;
108110
107403
  let ChunkStream$1 = chunkstreamExports;
108111
107404
  let Filter$1 = filterParseExports;
108112
107405
 
@@ -108858,7 +108151,7 @@ var formatNormaliser$2 = function (indata, imageData, skipRescale = false) {
108858
108151
  return outdata;
108859
108152
  };
108860
108153
 
108861
- let util$3 = require$$0$2;
108154
+ let util$3 = require$$0$1;
108862
108155
  let zlib$4 = zlib$5;
108863
108156
  let ChunkStream = chunkstreamExports;
108864
108157
  let FilterAsync = filterParseAsyncExports;
@@ -109489,7 +108782,7 @@ Packer$3.prototype.packIEND = function () {
109489
108782
 
109490
108783
  var packerExports = packer.exports;
109491
108784
 
109492
- let util$2 = require$$0$2;
108785
+ let util$2 = require$$0$1;
109493
108786
  let Stream$1 = Stream$4;
109494
108787
  let constants$2 = constants$6;
109495
108788
  let Packer$2 = packerExports;
@@ -109548,9 +108841,9 @@ syncInflate.exports;
109548
108841
 
109549
108842
  (function (module, exports) {
109550
108843
 
109551
- let assert = require$$0$7.ok;
108844
+ let assert = require$$0$6.ok;
109552
108845
  let zlib = zlib$5;
109553
- let util = require$$0$2;
108846
+ let util = require$$0$1;
109554
108847
 
109555
108848
  let kMaxLength = require$$3.kMaxLength;
109556
108849
 
@@ -109967,7 +109260,7 @@ pngSync.write = function (png, options) {
109967
109260
 
109968
109261
  var PNG_1;
109969
109262
 
109970
- let util$1 = require$$0$2;
109263
+ let util$1 = require$$0$1;
109971
109264
  let Stream = Stream$4;
109972
109265
  let Parser = parserAsyncExports;
109973
109266
  let Packer = packerAsyncExports;
@@ -120738,31 +120031,31 @@ __export(constants_exports, {
120738
120031
  // src/constants/bt709.ts
120739
120032
  var bt709_exports = {};
120740
120033
  __export(bt709_exports, {
120741
- Y: () => Y$1,
120742
- x: () => x$1,
120743
- y: () => y$1
120034
+ Y: () => Y,
120035
+ x: () => x,
120036
+ y: () => y
120744
120037
  });
120745
- var Y$1 = /* @__PURE__ */ ((Y2) => {
120038
+ var Y = /* @__PURE__ */ ((Y2) => {
120746
120039
  Y2[Y2["RED"] = 0.2126] = "RED";
120747
120040
  Y2[Y2["GREEN"] = 0.7152] = "GREEN";
120748
120041
  Y2[Y2["BLUE"] = 0.0722] = "BLUE";
120749
120042
  Y2[Y2["WHITE"] = 1] = "WHITE";
120750
120043
  return Y2;
120751
- })(Y$1 || {});
120752
- var x$1 = /* @__PURE__ */ ((x2) => {
120044
+ })(Y || {});
120045
+ var x = /* @__PURE__ */ ((x2) => {
120753
120046
  x2[x2["RED"] = 0.64] = "RED";
120754
120047
  x2[x2["GREEN"] = 0.3] = "GREEN";
120755
120048
  x2[x2["BLUE"] = 0.15] = "BLUE";
120756
120049
  x2[x2["WHITE"] = 0.3127] = "WHITE";
120757
120050
  return x2;
120758
- })(x$1 || {});
120759
- var y$1 = /* @__PURE__ */ ((y2) => {
120051
+ })(x || {});
120052
+ var y = /* @__PURE__ */ ((y2) => {
120760
120053
  y2[y2["RED"] = 0.33] = "RED";
120761
120054
  y2[y2["GREEN"] = 0.6] = "GREEN";
120762
120055
  y2[y2["BLUE"] = 0.06] = "BLUE";
120763
120056
  y2[y2["WHITE"] = 0.329] = "WHITE";
120764
120057
  return y2;
120765
- })(y$1 || {});
120058
+ })(y || {});
120766
120059
 
120767
120060
  // src/conversion/index.ts
120768
120061
  var conversion_exports = {};
@@ -125732,7 +125025,7 @@ var normalize$1 = (() => ({
125732
125025
  }
125733
125026
  }));
125734
125027
 
125735
- var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var http=http$1;var https=https$1;var url$1=Url;var qs=require$$3$1;var zlib=zlib$5;var util=require$$0$2;var phin=function phin(opts,cb){if(typeof opts!=='string'){if(!opts.hasOwnProperty('url')){throw new Error('Missing url option from options for request method.')}}var addr=(typeof opts==='undefined'?'undefined':_typeof(opts))==='object'?url$1.parse(opts.url):url$1.parse(opts);var options={'hostname':addr.hostname,'port':addr.port||(addr.protocol.toLowerCase()==='http:'?80:443),'path':addr.path,'method':'GET','headers':{},'auth':addr.auth||null,'parse':'none','stream':false};if((typeof opts==='undefined'?'undefined':_typeof(opts))==='object'){options=Object.assign(options,opts);}options.port=Number(options.port);if(options.hasOwnProperty('timeout'))delete options.timeout;if(options.compressed===true){options.headers['accept-encoding']='gzip, deflate';}if(opts.hasOwnProperty('form')){if(_typeof(opts.form)!=='object'){throw new Error('phin \'form\' option must be of type Object if present.')}var formDataString=qs.stringify(opts.form);options.headers['Content-Type']='application/x-www-form-urlencoded';options.headers['Content-Length']=Buffer.byteLength(formDataString);opts.data=formDataString;}var req=void 0;var resHandler=function resHandler(res){var stream=res;if(options.compressed===true){if(res.headers['content-encoding']==='gzip'){stream=res.pipe(zlib.createGunzip());}else if(res.headers['content-encoding']==='deflate'){stream=res.pipe(zlib.createInflate());}}if(options.stream===true){res.stream=stream;if(cb)cb(null,res);}else {res.body=new Buffer([]);stream.on('data',function(chunk){res.body=Buffer.concat([res.body,chunk]);});stream.on('end',function(){if(cb){if(options.parse==='json'){try{res.body=JSON.parse(res.body.toString());}catch(err){cb('Invalid JSON received.',res);return}}cb(null,res);}});}};switch(addr.protocol.toLowerCase()){case'http:':req=http.request(options,resHandler);break;case'https:':req=https.request(options,resHandler);break;default:if(cb)cb(new Error('Invalid / unknown URL protocol. Expected HTTP or HTTPS.'),null);return;}if(typeof opts.timeout==='number'){req.setTimeout(opts.timeout,function(){req.abort();if(cb)cb(new Error('Timeout has been reached.'),null);cb=null;});}req.on('error',function(err){if(cb)cb(err,null);});if(opts.hasOwnProperty('data')){var postData=opts.data;if(!(opts.data instanceof Buffer)&&_typeof(opts.data)==='object'){var contentType=options.headers['content-type']||options.headers['Content-Type'];if(contentType==='application/x-www-form-urlencoded'){postData=qs.stringify(opts.data);}else {try{postData=JSON.stringify(opts.data);}catch(err){if(cb)cb(new Error('Couldn\'t stringify object. (Likely due to a circular reference.)'),null);}}}req.write(postData);}req.end();};phin.promisified=function(opts,http){return new Promise(function(resolve,reject){phin(opts,function(err,res){if(err){reject(err);}else {resolve(res);}});})};if(util.promisify){phin[util.promisify.custom]=phin.promisified;}var phin_compiled=phin;
125028
+ var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var http=http$1;var https=https$1;var url$1=Url;var qs=require$$3$1;var zlib=zlib$5;var util=require$$0$1;var phin=function phin(opts,cb){if(typeof opts!=='string'){if(!opts.hasOwnProperty('url')){throw new Error('Missing url option from options for request method.')}}var addr=(typeof opts==='undefined'?'undefined':_typeof(opts))==='object'?url$1.parse(opts.url):url$1.parse(opts);var options={'hostname':addr.hostname,'port':addr.port||(addr.protocol.toLowerCase()==='http:'?80:443),'path':addr.path,'method':'GET','headers':{},'auth':addr.auth||null,'parse':'none','stream':false};if((typeof opts==='undefined'?'undefined':_typeof(opts))==='object'){options=Object.assign(options,opts);}options.port=Number(options.port);if(options.hasOwnProperty('timeout'))delete options.timeout;if(options.compressed===true){options.headers['accept-encoding']='gzip, deflate';}if(opts.hasOwnProperty('form')){if(_typeof(opts.form)!=='object'){throw new Error('phin \'form\' option must be of type Object if present.')}var formDataString=qs.stringify(opts.form);options.headers['Content-Type']='application/x-www-form-urlencoded';options.headers['Content-Length']=Buffer.byteLength(formDataString);opts.data=formDataString;}var req=void 0;var resHandler=function resHandler(res){var stream=res;if(options.compressed===true){if(res.headers['content-encoding']==='gzip'){stream=res.pipe(zlib.createGunzip());}else if(res.headers['content-encoding']==='deflate'){stream=res.pipe(zlib.createInflate());}}if(options.stream===true){res.stream=stream;if(cb)cb(null,res);}else {res.body=new Buffer([]);stream.on('data',function(chunk){res.body=Buffer.concat([res.body,chunk]);});stream.on('end',function(){if(cb){if(options.parse==='json'){try{res.body=JSON.parse(res.body.toString());}catch(err){cb('Invalid JSON received.',res);return}}cb(null,res);}});}};switch(addr.protocol.toLowerCase()){case'http:':req=http.request(options,resHandler);break;case'https:':req=https.request(options,resHandler);break;default:if(cb)cb(new Error('Invalid / unknown URL protocol. Expected HTTP or HTTPS.'),null);return;}if(typeof opts.timeout==='number'){req.setTimeout(opts.timeout,function(){req.abort();if(cb)cb(new Error('Timeout has been reached.'),null);cb=null;});}req.on('error',function(err){if(cb)cb(err,null);});if(opts.hasOwnProperty('data')){var postData=opts.data;if(!(opts.data instanceof Buffer)&&_typeof(opts.data)==='object'){var contentType=options.headers['content-type']||options.headers['Content-Type'];if(contentType==='application/x-www-form-urlencoded'){postData=qs.stringify(opts.data);}else {try{postData=JSON.stringify(opts.data);}catch(err){if(cb)cb(new Error('Couldn\'t stringify object. (Likely due to a circular reference.)'),null);}}}req.write(postData);}req.end();};phin.promisified=function(opts,http){return new Promise(function(resolve,reject){phin(opts,function(err,res){if(err){reject(err);}else {resolve(res);}});})};if(util.promisify){phin[util.promisify.custom]=phin.promisified;}var phin_compiled=phin;
125736
125029
 
125737
125030
  var parseBmfontAscii = function parseBMFontAscii(data) {
125738
125031
  if (!data)
@@ -132106,7 +131399,7 @@ function requireParser () {
132106
131399
 
132107
131400
  sax = requireSax();
132108
131401
 
132109
- events = require$$0$5;
131402
+ events = require$$0$4;
132110
131403
 
132111
131404
  bom = requireBom();
132112
131405
 
@@ -147058,1094 +146351,1420 @@ const decodeQRCodeFromFile = async (filePath) => {
147058
146351
  return decodedString;
147059
146352
  };
147060
146353
 
146354
+ //! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth
146355
+ //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes
147061
146356
  /// <reference types="./otpauth.d.ts" />
146357
+ // @ts-nocheck
147062
146358
  /**
147063
- * Converts an integer to an ArrayBuffer.
146359
+ * Converts an integer to an Uint8Array.
147064
146360
  * @param {number} num Integer.
147065
- * @returns {ArrayBuffer} ArrayBuffer.
147066
- */
147067
- const uintToBuf = num => {
147068
- const buf = new ArrayBuffer(8);
147069
- const arr = new Uint8Array(buf);
147070
- let acc = num;
147071
- for (let i = 7; i >= 0; i--) {
147072
- if (acc === 0) break;
147073
- arr[i] = acc & 255;
147074
- acc -= arr[i];
147075
- acc /= 256;
147076
- }
147077
- return buf;
146361
+ * @returns {Uint8Array} Uint8Array.
146362
+ */ const uintDecode = (num)=>{
146363
+ const buf = new ArrayBuffer(8);
146364
+ const arr = new Uint8Array(buf);
146365
+ let acc = num;
146366
+ for(let i = 7; i >= 0; i--){
146367
+ if (acc === 0) break;
146368
+ arr[i] = acc & 255;
146369
+ acc -= arr[i];
146370
+ acc /= 256;
146371
+ }
146372
+ return arr;
147078
146373
  };
147079
146374
 
146375
+ function number(n) {
146376
+ if (!Number.isSafeInteger(n) || n < 0) throw new Error(`positive integer expected, not ${n}`);
146377
+ }
146378
+ // copied from utils
146379
+ function isBytes(a) {
146380
+ return a instanceof Uint8Array || a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array';
146381
+ }
146382
+ function bytes(b, ...lengths) {
146383
+ if (!isBytes(b)) throw new Error('Uint8Array expected');
146384
+ if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
146385
+ }
146386
+ function hash(h) {
146387
+ if (typeof h !== 'function' || typeof h.create !== 'function') throw new Error('Hash should be wrapped by utils.wrapConstructor');
146388
+ number(h.outputLen);
146389
+ number(h.blockLen);
146390
+ }
146391
+ function exists(instance, checkFinished = true) {
146392
+ if (instance.destroyed) throw new Error('Hash instance has been destroyed');
146393
+ if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
146394
+ }
146395
+ function output(out, instance) {
146396
+ bytes(out);
146397
+ const min = instance.outputLen;
146398
+ if (out.length < min) {
146399
+ throw new Error(`digestInto() expects output buffer of length at least ${min}`);
146400
+ }
146401
+ }
146402
+
146403
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
146404
+ // node.js versions earlier than v19 don't declare it in global scope.
146405
+ // For node.js, package.json#exports field mapping rewrites import
146406
+ // from `crypto` to `cryptoNode`, which imports native module.
146407
+ // Makes the utils un-importable in browsers without a bundler.
146408
+ // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
146409
+ const u32 = (arr)=>new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
146410
+ // Cast array to view
146411
+ const createView = (arr)=>new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
146412
+ // The rotate right (circular right shift) operation for uint32
146413
+ const rotr = (word, shift)=>word << 32 - shift | word >>> shift;
146414
+ // The rotate left (circular left shift) operation for uint32
146415
+ const rotl = (word, shift)=>word << shift | word >>> 32 - shift >>> 0;
146416
+ const isLE = new Uint8Array(new Uint32Array([
146417
+ 0x11223344
146418
+ ]).buffer)[0] === 0x44;
146419
+ // The byte swap operation for uint32
146420
+ const byteSwap = (word)=>word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff;
146421
+ // In place byte swap for Uint32Array
146422
+ function byteSwap32(arr) {
146423
+ for(let i = 0; i < arr.length; i++){
146424
+ arr[i] = byteSwap(arr[i]);
146425
+ }
146426
+ }
147080
146427
  /**
147081
- * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202,
147082
- * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1.
147083
- *
147084
- * Copyright 2008-2023 Brian Turek, 1998-2009 Paul Johnston & Contributors
147085
- * Distributed under the BSD License
147086
- * See http://caligatio.github.com/jsSHA/ for more information
147087
- */
147088
- const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
147089
- n = "ARRAYBUFFER not supported by this environment",
147090
- e = "UINT8ARRAY not supported by this environment";
147091
- function r(t, n, e, r) {
147092
- let i, s, o;
147093
- const h = n || [0],
147094
- u = (e = e || 0) >>> 3,
147095
- w = -1 === r ? 3 : 0;
147096
- for (i = 0; i < t.length; i += 1) o = i + u, s = o >>> 2, h.length <= s && h.push(0), h[s] |= t[i] << 8 * (w + r * (o % 4));
147097
- return {
147098
- value: h,
147099
- binLen: 8 * t.length + e
147100
- };
146428
+ * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
146429
+ */ function utf8ToBytes(str) {
146430
+ if (typeof str !== 'string') throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
146431
+ return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
147101
146432
  }
147102
- function i(i, s, o) {
147103
- switch (s) {
147104
- case "UTF8":
147105
- case "UTF16BE":
147106
- case "UTF16LE":
147107
- break;
147108
- default:
147109
- throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE");
147110
- }
147111
- switch (i) {
147112
- case "HEX":
147113
- return function (t, n, e) {
147114
- return function (t, n, e, r) {
147115
- let i, s, o, h;
147116
- if (0 != t.length % 2) throw new Error("String of HEX type must be in byte increments");
147117
- const u = n || [0],
147118
- w = (e = e || 0) >>> 3,
147119
- c = -1 === r ? 3 : 0;
147120
- for (i = 0; i < t.length; i += 2) {
147121
- if (s = parseInt(t.substr(i, 2), 16), isNaN(s)) throw new Error("String of HEX type contains invalid characters");
147122
- for (h = (i >>> 1) + w, o = h >>> 2; u.length <= o;) u.push(0);
147123
- u[o] |= s << 8 * (c + r * (h % 4));
147124
- }
147125
- return {
147126
- value: u,
147127
- binLen: 4 * t.length + e
147128
- };
147129
- }(t, n, e, o);
147130
- };
147131
- case "TEXT":
147132
- return function (t, n, e) {
147133
- return function (t, n, e, r, i) {
147134
- let s,
147135
- o,
147136
- h,
147137
- u,
147138
- w,
147139
- c,
147140
- f,
147141
- a,
147142
- l = 0;
147143
- const A = e || [0],
147144
- E = (r = r || 0) >>> 3;
147145
- if ("UTF8" === n) for (f = -1 === i ? 3 : 0, h = 0; h < t.length; h += 1) for (s = t.charCodeAt(h), o = [], 128 > s ? o.push(s) : 2048 > s ? (o.push(192 | s >>> 6), o.push(128 | 63 & s)) : 55296 > s || 57344 <= s ? o.push(224 | s >>> 12, 128 | s >>> 6 & 63, 128 | 63 & s) : (h += 1, s = 65536 + ((1023 & s) << 10 | 1023 & t.charCodeAt(h)), o.push(240 | s >>> 18, 128 | s >>> 12 & 63, 128 | s >>> 6 & 63, 128 | 63 & s)), u = 0; u < o.length; u += 1) {
147146
- for (c = l + E, w = c >>> 2; A.length <= w;) A.push(0);
147147
- A[w] |= o[u] << 8 * (f + i * (c % 4)), l += 1;
147148
- } else for (f = -1 === i ? 2 : 0, a = "UTF16LE" === n && 1 !== i || "UTF16LE" !== n && 1 === i, h = 0; h < t.length; h += 1) {
147149
- for (s = t.charCodeAt(h), !0 === a && (u = 255 & s, s = u << 8 | s >>> 8), c = l + E, w = c >>> 2; A.length <= w;) A.push(0);
147150
- A[w] |= s << 8 * (f + i * (c % 4)), l += 2;
147151
- }
147152
- return {
147153
- value: A,
147154
- binLen: 8 * l + r
147155
- };
147156
- }(t, s, n, e, o);
147157
- };
147158
- case "B64":
147159
- return function (n, e, r) {
147160
- return function (n, e, r, i) {
147161
- let s,
147162
- o,
147163
- h,
147164
- u,
147165
- w,
147166
- c,
147167
- f,
147168
- a = 0;
147169
- const l = e || [0],
147170
- A = (r = r || 0) >>> 3,
147171
- E = -1 === i ? 3 : 0,
147172
- H = n.indexOf("=");
147173
- if (-1 === n.search(/^[a-zA-Z0-9=+/]+$/)) throw new Error("Invalid character in base-64 string");
147174
- if (n = n.replace(/=/g, ""), -1 !== H && H < n.length) throw new Error("Invalid '=' found in base-64 string");
147175
- for (o = 0; o < n.length; o += 4) {
147176
- for (w = n.substr(o, 4), u = 0, h = 0; h < w.length; h += 1) s = t.indexOf(w.charAt(h)), u |= s << 18 - 6 * h;
147177
- for (h = 0; h < w.length - 1; h += 1) {
147178
- for (f = a + A, c = f >>> 2; l.length <= c;) l.push(0);
147179
- l[c] |= (u >>> 16 - 8 * h & 255) << 8 * (E + i * (f % 4)), a += 1;
147180
- }
147181
- }
147182
- return {
147183
- value: l,
147184
- binLen: 8 * a + r
147185
- };
147186
- }(n, e, r, o);
147187
- };
147188
- case "BYTES":
147189
- return function (t, n, e) {
147190
- return function (t, n, e, r) {
147191
- let i, s, o, h;
147192
- const u = n || [0],
147193
- w = (e = e || 0) >>> 3,
147194
- c = -1 === r ? 3 : 0;
147195
- for (s = 0; s < t.length; s += 1) i = t.charCodeAt(s), h = s + w, o = h >>> 2, u.length <= o && u.push(0), u[o] |= i << 8 * (c + r * (h % 4));
147196
- return {
147197
- value: u,
147198
- binLen: 8 * t.length + e
147199
- };
147200
- }(t, n, e, o);
147201
- };
147202
- case "ARRAYBUFFER":
147203
- try {
147204
- new ArrayBuffer(0);
147205
- } catch (t) {
147206
- throw new Error(n);
147207
- }
147208
- return function (t, n, e) {
147209
- return function (t, n, e, i) {
147210
- return r(new Uint8Array(t), n, e, i);
147211
- }(t, n, e, o);
147212
- };
147213
- case "UINT8ARRAY":
147214
- try {
147215
- new Uint8Array(0);
147216
- } catch (t) {
147217
- throw new Error(e);
147218
- }
147219
- return function (t, n, e) {
147220
- return r(t, n, e, o);
147221
- };
147222
- default:
147223
- throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY");
147224
- }
147225
- }
147226
- function s(r, i, s, o) {
147227
- switch (r) {
147228
- case "HEX":
147229
- return function (t) {
147230
- return function (t, n, e, r) {
147231
- const i = "0123456789abcdef";
147232
- let s,
147233
- o,
147234
- h = "";
147235
- const u = n / 8,
147236
- w = -1 === e ? 3 : 0;
147237
- for (s = 0; s < u; s += 1) o = t[s >>> 2] >>> 8 * (w + e * (s % 4)), h += i.charAt(o >>> 4 & 15) + i.charAt(15 & o);
147238
- return r.outputUpper ? h.toUpperCase() : h;
147239
- }(t, i, s, o);
147240
- };
147241
- case "B64":
147242
- return function (n) {
147243
- return function (n, e, r, i) {
147244
- let s,
147245
- o,
147246
- h,
147247
- u,
147248
- w,
147249
- c = "";
147250
- const f = e / 8,
147251
- a = -1 === r ? 3 : 0;
147252
- for (s = 0; s < f; s += 3) for (u = s + 1 < f ? n[s + 1 >>> 2] : 0, w = s + 2 < f ? n[s + 2 >>> 2] : 0, h = (n[s >>> 2] >>> 8 * (a + r * (s % 4)) & 255) << 16 | (u >>> 8 * (a + r * ((s + 1) % 4)) & 255) << 8 | w >>> 8 * (a + r * ((s + 2) % 4)) & 255, o = 0; o < 4; o += 1) c += 8 * s + 6 * o <= e ? t.charAt(h >>> 6 * (3 - o) & 63) : i.b64Pad;
147253
- return c;
147254
- }(n, i, s, o);
147255
- };
147256
- case "BYTES":
147257
- return function (t) {
147258
- return function (t, n, e) {
147259
- let r,
147260
- i,
147261
- s = "";
147262
- const o = n / 8,
147263
- h = -1 === e ? 3 : 0;
147264
- for (r = 0; r < o; r += 1) i = t[r >>> 2] >>> 8 * (h + e * (r % 4)) & 255, s += String.fromCharCode(i);
147265
- return s;
147266
- }(t, i, s);
147267
- };
147268
- case "ARRAYBUFFER":
147269
- try {
147270
- new ArrayBuffer(0);
147271
- } catch (t) {
147272
- throw new Error(n);
147273
- }
147274
- return function (t) {
147275
- return function (t, n, e) {
147276
- let r;
147277
- const i = n / 8,
147278
- s = new ArrayBuffer(i),
147279
- o = new Uint8Array(s),
147280
- h = -1 === e ? 3 : 0;
147281
- for (r = 0; r < i; r += 1) o[r] = t[r >>> 2] >>> 8 * (h + e * (r % 4)) & 255;
147282
- return s;
147283
- }(t, i, s);
147284
- };
147285
- case "UINT8ARRAY":
147286
- try {
147287
- new Uint8Array(0);
147288
- } catch (t) {
147289
- throw new Error(e);
147290
- }
147291
- return function (t) {
147292
- return function (t, n, e) {
147293
- let r;
147294
- const i = n / 8,
147295
- s = -1 === e ? 3 : 0,
147296
- o = new Uint8Array(i);
147297
- for (r = 0; r < i; r += 1) o[r] = t[r >>> 2] >>> 8 * (s + e * (r % 4)) & 255;
147298
- return o;
147299
- }(t, i, s);
147300
- };
147301
- default:
147302
- throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY");
147303
- }
147304
- }
147305
- const o = 4294967296,
147306
- h = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298],
147307
- u = [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428],
147308
- w = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225],
147309
- c = "Chosen SHA variant is not supported",
147310
- f = "Cannot set numRounds with MAC";
147311
- function a(t, n) {
147312
- let e, r;
147313
- const i = t.binLen >>> 3,
147314
- s = n.binLen >>> 3,
147315
- o = i << 3,
147316
- h = 4 - i << 3;
147317
- if (i % 4 != 0) {
147318
- for (e = 0; e < s; e += 4) r = i + e >>> 2, t.value[r] |= n.value[e >>> 2] << o, t.value.push(0), t.value[r + 1] |= n.value[e >>> 2] >>> h;
147319
- return (t.value.length << 2) - 4 >= s + i && t.value.pop(), {
147320
- value: t.value,
147321
- binLen: t.binLen + n.binLen
147322
- };
147323
- }
147324
- return {
147325
- value: t.value.concat(n.value),
147326
- binLen: t.binLen + n.binLen
147327
- };
146433
+ /**
146434
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
146435
+ * Warning: when Uint8Array is passed, it would NOT get copied.
146436
+ * Keep in mind for future mutable operations.
146437
+ */ function toBytes(data) {
146438
+ if (typeof data === 'string') data = utf8ToBytes(data);
146439
+ bytes(data);
146440
+ return data;
146441
+ }
146442
+ // For runtime check if class implements interface
146443
+ class Hash {
146444
+ // Safe version that clones internal state
146445
+ clone() {
146446
+ return this._cloneInto();
146447
+ }
146448
+ }
146449
+ function wrapConstructor(hashCons) {
146450
+ const hashC = (msg)=>hashCons().update(toBytes(msg)).digest();
146451
+ const tmp = hashCons();
146452
+ hashC.outputLen = tmp.outputLen;
146453
+ hashC.blockLen = tmp.blockLen;
146454
+ hashC.create = ()=>hashCons();
146455
+ return hashC;
146456
+ }
146457
+
146458
+ // HMAC (RFC 2104)
146459
+ class HMAC extends Hash {
146460
+ update(buf) {
146461
+ exists(this);
146462
+ this.iHash.update(buf);
146463
+ return this;
146464
+ }
146465
+ digestInto(out) {
146466
+ exists(this);
146467
+ bytes(out, this.outputLen);
146468
+ this.finished = true;
146469
+ this.iHash.digestInto(out);
146470
+ this.oHash.update(out);
146471
+ this.oHash.digestInto(out);
146472
+ this.destroy();
146473
+ }
146474
+ digest() {
146475
+ const out = new Uint8Array(this.oHash.outputLen);
146476
+ this.digestInto(out);
146477
+ return out;
146478
+ }
146479
+ _cloneInto(to) {
146480
+ // Create new instance without calling constructor since key already in state and we don't know it.
146481
+ to || (to = Object.create(Object.getPrototypeOf(this), {}));
146482
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
146483
+ to = to;
146484
+ to.finished = finished;
146485
+ to.destroyed = destroyed;
146486
+ to.blockLen = blockLen;
146487
+ to.outputLen = outputLen;
146488
+ to.oHash = oHash._cloneInto(to.oHash);
146489
+ to.iHash = iHash._cloneInto(to.iHash);
146490
+ return to;
146491
+ }
146492
+ destroy() {
146493
+ this.destroyed = true;
146494
+ this.oHash.destroy();
146495
+ this.iHash.destroy();
146496
+ }
146497
+ constructor(hash$1, _key){
146498
+ super();
146499
+ this.finished = false;
146500
+ this.destroyed = false;
146501
+ hash(hash$1);
146502
+ const key = toBytes(_key);
146503
+ this.iHash = hash$1.create();
146504
+ if (typeof this.iHash.update !== 'function') throw new Error('Expected instance of class which extends utils.Hash');
146505
+ this.blockLen = this.iHash.blockLen;
146506
+ this.outputLen = this.iHash.outputLen;
146507
+ const blockLen = this.blockLen;
146508
+ const pad = new Uint8Array(blockLen);
146509
+ // blockLen can be bigger than outputLen
146510
+ pad.set(key.length > blockLen ? hash$1.create().update(key).digest() : key);
146511
+ for(let i = 0; i < pad.length; i++)pad[i] ^= 0x36;
146512
+ this.iHash.update(pad);
146513
+ // By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
146514
+ this.oHash = hash$1.create();
146515
+ // Undo internal XOR && apply outer XOR
146516
+ for(let i = 0; i < pad.length; i++)pad[i] ^= 0x36 ^ 0x5c;
146517
+ this.oHash.update(pad);
146518
+ pad.fill(0);
146519
+ }
147328
146520
  }
147329
- function l(t) {
147330
- const n = {
147331
- outputUpper: !1,
147332
- b64Pad: "=",
147333
- outputLen: -1
147334
- },
147335
- e = t || {},
147336
- r = "Output length must be a multiple of 8";
147337
- if (n.outputUpper = e.outputUpper || !1, e.b64Pad && (n.b64Pad = e.b64Pad), e.outputLen) {
147338
- if (e.outputLen % 8 != 0) throw new Error(r);
147339
- n.outputLen = e.outputLen;
147340
- } else if (e.shakeLen) {
147341
- if (e.shakeLen % 8 != 0) throw new Error(r);
147342
- n.outputLen = e.shakeLen;
147343
- }
147344
- if ("boolean" != typeof n.outputUpper) throw new Error("Invalid outputUpper formatting option");
147345
- if ("string" != typeof n.b64Pad) throw new Error("Invalid b64Pad formatting option");
147346
- return n;
146521
+ /**
146522
+ * HMAC: RFC2104 message authentication code.
146523
+ * @param hash - function that would be used e.g. sha256
146524
+ * @param key - message key
146525
+ * @param message - message data
146526
+ */ const hmac = (hash, key, message)=>new HMAC(hash, key).update(message).digest();
146527
+ hmac.create = (hash, key)=>new HMAC(hash, key);
146528
+
146529
+ // Polyfill for Safari 14
146530
+ function setBigUint64(view, byteOffset, value, isLE) {
146531
+ if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE);
146532
+ const _32n = BigInt(32);
146533
+ const _u32_max = BigInt(0xffffffff);
146534
+ const wh = Number(value >> _32n & _u32_max);
146535
+ const wl = Number(value & _u32_max);
146536
+ const h = isLE ? 4 : 0;
146537
+ const l = isLE ? 0 : 4;
146538
+ view.setUint32(byteOffset + h, wh, isLE);
146539
+ view.setUint32(byteOffset + l, wl, isLE);
146540
+ }
146541
+ // Choice: a ? b : c
146542
+ const Chi = (a, b, c)=>a & b ^ ~a & c;
146543
+ // Majority function, true if any two inpust is true
146544
+ const Maj = (a, b, c)=>a & b ^ a & c ^ b & c;
146545
+ /**
146546
+ * Merkle-Damgard hash construction base class.
146547
+ * Could be used to create MD5, RIPEMD, SHA1, SHA2.
146548
+ */ class HashMD extends Hash {
146549
+ update(data) {
146550
+ exists(this);
146551
+ const { view, buffer, blockLen } = this;
146552
+ data = toBytes(data);
146553
+ const len = data.length;
146554
+ for(let pos = 0; pos < len;){
146555
+ const take = Math.min(blockLen - this.pos, len - pos);
146556
+ // Fast path: we have at least one block in input, cast it to view and process
146557
+ if (take === blockLen) {
146558
+ const dataView = createView(data);
146559
+ for(; blockLen <= len - pos; pos += blockLen)this.process(dataView, pos);
146560
+ continue;
146561
+ }
146562
+ buffer.set(data.subarray(pos, pos + take), this.pos);
146563
+ this.pos += take;
146564
+ pos += take;
146565
+ if (this.pos === blockLen) {
146566
+ this.process(view, 0);
146567
+ this.pos = 0;
146568
+ }
146569
+ }
146570
+ this.length += data.length;
146571
+ this.roundClean();
146572
+ return this;
146573
+ }
146574
+ digestInto(out) {
146575
+ exists(this);
146576
+ output(out, this);
146577
+ this.finished = true;
146578
+ // Padding
146579
+ // We can avoid allocation of buffer for padding completely if it
146580
+ // was previously not allocated here. But it won't change performance.
146581
+ const { buffer, view, blockLen, isLE } = this;
146582
+ let { pos } = this;
146583
+ // append the bit '1' to the message
146584
+ buffer[pos++] = 0b10000000;
146585
+ this.buffer.subarray(pos).fill(0);
146586
+ // we have less than padOffset left in buffer, so we cannot put length in
146587
+ // current block, need process it and pad again
146588
+ if (this.padOffset > blockLen - pos) {
146589
+ this.process(view, 0);
146590
+ pos = 0;
146591
+ }
146592
+ // Pad until full block byte with zeros
146593
+ for(let i = pos; i < blockLen; i++)buffer[i] = 0;
146594
+ // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
146595
+ // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
146596
+ // So we just write lowest 64 bits of that value.
146597
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
146598
+ this.process(view, 0);
146599
+ const oview = createView(out);
146600
+ const len = this.outputLen;
146601
+ // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
146602
+ if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');
146603
+ const outLen = len / 4;
146604
+ const state = this.get();
146605
+ if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');
146606
+ for(let i = 0; i < outLen; i++)oview.setUint32(4 * i, state[i], isLE);
146607
+ }
146608
+ digest() {
146609
+ const { buffer, outputLen } = this;
146610
+ this.digestInto(buffer);
146611
+ const res = buffer.slice(0, outputLen);
146612
+ this.destroy();
146613
+ return res;
146614
+ }
146615
+ _cloneInto(to) {
146616
+ to || (to = new this.constructor());
146617
+ to.set(...this.get());
146618
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
146619
+ to.length = length;
146620
+ to.pos = pos;
146621
+ to.finished = finished;
146622
+ to.destroyed = destroyed;
146623
+ if (length % blockLen) to.buffer.set(buffer);
146624
+ return to;
146625
+ }
146626
+ constructor(blockLen, outputLen, padOffset, isLE){
146627
+ super();
146628
+ this.blockLen = blockLen;
146629
+ this.outputLen = outputLen;
146630
+ this.padOffset = padOffset;
146631
+ this.isLE = isLE;
146632
+ this.finished = false;
146633
+ this.length = 0;
146634
+ this.pos = 0;
146635
+ this.destroyed = false;
146636
+ this.buffer = new Uint8Array(blockLen);
146637
+ this.view = createView(this.buffer);
146638
+ }
146639
+ }
146640
+
146641
+ // SHA1 (RFC 3174) was cryptographically broken. It's still used. Don't use it for a new protocol.
146642
+ // Initial state
146643
+ const SHA1_IV = /* @__PURE__ */ new Uint32Array([
146644
+ 0x67452301,
146645
+ 0xefcdab89,
146646
+ 0x98badcfe,
146647
+ 0x10325476,
146648
+ 0xc3d2e1f0
146649
+ ]);
146650
+ // Temporary buffer, not used to store anything between runs
146651
+ // Named this way because it matches specification.
146652
+ const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
146653
+ class SHA1 extends HashMD {
146654
+ get() {
146655
+ const { A, B, C, D, E } = this;
146656
+ return [
146657
+ A,
146658
+ B,
146659
+ C,
146660
+ D,
146661
+ E
146662
+ ];
146663
+ }
146664
+ set(A, B, C, D, E) {
146665
+ this.A = A | 0;
146666
+ this.B = B | 0;
146667
+ this.C = C | 0;
146668
+ this.D = D | 0;
146669
+ this.E = E | 0;
146670
+ }
146671
+ process(view, offset) {
146672
+ for(let i = 0; i < 16; i++, offset += 4)SHA1_W[i] = view.getUint32(offset, false);
146673
+ for(let i = 16; i < 80; i++)SHA1_W[i] = rotl(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1);
146674
+ // Compression function main loop, 80 rounds
146675
+ let { A, B, C, D, E } = this;
146676
+ for(let i = 0; i < 80; i++){
146677
+ let F, K;
146678
+ if (i < 20) {
146679
+ F = Chi(B, C, D);
146680
+ K = 0x5a827999;
146681
+ } else if (i < 40) {
146682
+ F = B ^ C ^ D;
146683
+ K = 0x6ed9eba1;
146684
+ } else if (i < 60) {
146685
+ F = Maj(B, C, D);
146686
+ K = 0x8f1bbcdc;
146687
+ } else {
146688
+ F = B ^ C ^ D;
146689
+ K = 0xca62c1d6;
146690
+ }
146691
+ const T = rotl(A, 5) + F + E + K + SHA1_W[i] | 0;
146692
+ E = D;
146693
+ D = C;
146694
+ C = rotl(B, 30);
146695
+ B = A;
146696
+ A = T;
146697
+ }
146698
+ // Add the compressed chunk to the current hash value
146699
+ A = A + this.A | 0;
146700
+ B = B + this.B | 0;
146701
+ C = C + this.C | 0;
146702
+ D = D + this.D | 0;
146703
+ E = E + this.E | 0;
146704
+ this.set(A, B, C, D, E);
146705
+ }
146706
+ roundClean() {
146707
+ SHA1_W.fill(0);
146708
+ }
146709
+ destroy() {
146710
+ this.set(0, 0, 0, 0, 0);
146711
+ this.buffer.fill(0);
146712
+ }
146713
+ constructor(){
146714
+ super(64, 20, 8, false);
146715
+ this.A = SHA1_IV[0] | 0;
146716
+ this.B = SHA1_IV[1] | 0;
146717
+ this.C = SHA1_IV[2] | 0;
146718
+ this.D = SHA1_IV[3] | 0;
146719
+ this.E = SHA1_IV[4] | 0;
146720
+ }
146721
+ }
146722
+ const sha1 = /* @__PURE__ */ wrapConstructor(()=>new SHA1());
146723
+
146724
+ // SHA2-256 need to try 2^128 hashes to execute birthday attack.
146725
+ // BTC network is doing 2^67 hashes/sec as per early 2023.
146726
+ // Round constants:
146727
+ // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
146728
+ // prettier-ignore
146729
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
146730
+ 0x428a2f98,
146731
+ 0x71374491,
146732
+ 0xb5c0fbcf,
146733
+ 0xe9b5dba5,
146734
+ 0x3956c25b,
146735
+ 0x59f111f1,
146736
+ 0x923f82a4,
146737
+ 0xab1c5ed5,
146738
+ 0xd807aa98,
146739
+ 0x12835b01,
146740
+ 0x243185be,
146741
+ 0x550c7dc3,
146742
+ 0x72be5d74,
146743
+ 0x80deb1fe,
146744
+ 0x9bdc06a7,
146745
+ 0xc19bf174,
146746
+ 0xe49b69c1,
146747
+ 0xefbe4786,
146748
+ 0x0fc19dc6,
146749
+ 0x240ca1cc,
146750
+ 0x2de92c6f,
146751
+ 0x4a7484aa,
146752
+ 0x5cb0a9dc,
146753
+ 0x76f988da,
146754
+ 0x983e5152,
146755
+ 0xa831c66d,
146756
+ 0xb00327c8,
146757
+ 0xbf597fc7,
146758
+ 0xc6e00bf3,
146759
+ 0xd5a79147,
146760
+ 0x06ca6351,
146761
+ 0x14292967,
146762
+ 0x27b70a85,
146763
+ 0x2e1b2138,
146764
+ 0x4d2c6dfc,
146765
+ 0x53380d13,
146766
+ 0x650a7354,
146767
+ 0x766a0abb,
146768
+ 0x81c2c92e,
146769
+ 0x92722c85,
146770
+ 0xa2bfe8a1,
146771
+ 0xa81a664b,
146772
+ 0xc24b8b70,
146773
+ 0xc76c51a3,
146774
+ 0xd192e819,
146775
+ 0xd6990624,
146776
+ 0xf40e3585,
146777
+ 0x106aa070,
146778
+ 0x19a4c116,
146779
+ 0x1e376c08,
146780
+ 0x2748774c,
146781
+ 0x34b0bcb5,
146782
+ 0x391c0cb3,
146783
+ 0x4ed8aa4a,
146784
+ 0x5b9cca4f,
146785
+ 0x682e6ff3,
146786
+ 0x748f82ee,
146787
+ 0x78a5636f,
146788
+ 0x84c87814,
146789
+ 0x8cc70208,
146790
+ 0x90befffa,
146791
+ 0xa4506ceb,
146792
+ 0xbef9a3f7,
146793
+ 0xc67178f2
146794
+ ]);
146795
+ // Initial state:
146796
+ // first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
146797
+ // prettier-ignore
146798
+ const SHA256_IV = /* @__PURE__ */ new Uint32Array([
146799
+ 0x6a09e667,
146800
+ 0xbb67ae85,
146801
+ 0x3c6ef372,
146802
+ 0xa54ff53a,
146803
+ 0x510e527f,
146804
+ 0x9b05688c,
146805
+ 0x1f83d9ab,
146806
+ 0x5be0cd19
146807
+ ]);
146808
+ // Temporary buffer, not used to store anything between runs
146809
+ // Named this way because it matches specification.
146810
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
146811
+ class SHA256 extends HashMD {
146812
+ get() {
146813
+ const { A, B, C, D, E, F, G, H } = this;
146814
+ return [
146815
+ A,
146816
+ B,
146817
+ C,
146818
+ D,
146819
+ E,
146820
+ F,
146821
+ G,
146822
+ H
146823
+ ];
146824
+ }
146825
+ // prettier-ignore
146826
+ set(A, B, C, D, E, F, G, H) {
146827
+ this.A = A | 0;
146828
+ this.B = B | 0;
146829
+ this.C = C | 0;
146830
+ this.D = D | 0;
146831
+ this.E = E | 0;
146832
+ this.F = F | 0;
146833
+ this.G = G | 0;
146834
+ this.H = H | 0;
146835
+ }
146836
+ process(view, offset) {
146837
+ // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
146838
+ for(let i = 0; i < 16; i++, offset += 4)SHA256_W[i] = view.getUint32(offset, false);
146839
+ for(let i = 16; i < 64; i++){
146840
+ const W15 = SHA256_W[i - 15];
146841
+ const W2 = SHA256_W[i - 2];
146842
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
146843
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
146844
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
146845
+ }
146846
+ // Compression function main loop, 64 rounds
146847
+ let { A, B, C, D, E, F, G, H } = this;
146848
+ for(let i = 0; i < 64; i++){
146849
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
146850
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
146851
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
146852
+ const T2 = sigma0 + Maj(A, B, C) | 0;
146853
+ H = G;
146854
+ G = F;
146855
+ F = E;
146856
+ E = D + T1 | 0;
146857
+ D = C;
146858
+ C = B;
146859
+ B = A;
146860
+ A = T1 + T2 | 0;
146861
+ }
146862
+ // Add the compressed chunk to the current hash value
146863
+ A = A + this.A | 0;
146864
+ B = B + this.B | 0;
146865
+ C = C + this.C | 0;
146866
+ D = D + this.D | 0;
146867
+ E = E + this.E | 0;
146868
+ F = F + this.F | 0;
146869
+ G = G + this.G | 0;
146870
+ H = H + this.H | 0;
146871
+ this.set(A, B, C, D, E, F, G, H);
146872
+ }
146873
+ roundClean() {
146874
+ SHA256_W.fill(0);
146875
+ }
146876
+ destroy() {
146877
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
146878
+ this.buffer.fill(0);
146879
+ }
146880
+ constructor(){
146881
+ super(64, 32, 8, false);
146882
+ // We cannot use array here since array allows indexing by variable
146883
+ // which means optimizer/compiler cannot use registers.
146884
+ this.A = SHA256_IV[0] | 0;
146885
+ this.B = SHA256_IV[1] | 0;
146886
+ this.C = SHA256_IV[2] | 0;
146887
+ this.D = SHA256_IV[3] | 0;
146888
+ this.E = SHA256_IV[4] | 0;
146889
+ this.F = SHA256_IV[5] | 0;
146890
+ this.G = SHA256_IV[6] | 0;
146891
+ this.H = SHA256_IV[7] | 0;
146892
+ }
146893
+ }
146894
+ // Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
146895
+ class SHA224 extends SHA256 {
146896
+ constructor(){
146897
+ super();
146898
+ this.A = 0xc1059ed8 | 0;
146899
+ this.B = 0x367cd507 | 0;
146900
+ this.C = 0x3070dd17 | 0;
146901
+ this.D = 0xf70e5939 | 0;
146902
+ this.E = 0xffc00b31 | 0;
146903
+ this.F = 0x68581511 | 0;
146904
+ this.G = 0x64f98fa7 | 0;
146905
+ this.H = 0xbefa4fa4 | 0;
146906
+ this.outputLen = 28;
146907
+ }
147347
146908
  }
147348
- function A(t, n, e, r) {
147349
- const s = t + " must include a value and format";
147350
- if (!n) {
147351
- if (!r) throw new Error(s);
147352
- return r;
147353
- }
147354
- if (void 0 === n.value || !n.format) throw new Error(s);
147355
- return i(n.format, n.encoding || "UTF8", e)(n.value);
146909
+ /**
146910
+ * SHA2-256 hash function
146911
+ * @param message - data that would be hashed
146912
+ */ const sha256 = /* @__PURE__ */ wrapConstructor(()=>new SHA256());
146913
+ const sha224 = /* @__PURE__ */ wrapConstructor(()=>new SHA224());
146914
+
146915
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
146916
+ const _32n = /* @__PURE__ */ BigInt(32);
146917
+ // We are not using BigUint64Array, because they are extremely slow as per 2022
146918
+ function fromBig(n, le = false) {
146919
+ if (le) return {
146920
+ h: Number(n & U32_MASK64),
146921
+ l: Number(n >> _32n & U32_MASK64)
146922
+ };
146923
+ return {
146924
+ h: Number(n >> _32n & U32_MASK64) | 0,
146925
+ l: Number(n & U32_MASK64) | 0
146926
+ };
147356
146927
  }
147357
- class E {
147358
- constructor(t, n, e) {
147359
- const r = e || {};
147360
- if (this.t = n, this.i = r.encoding || "UTF8", this.numRounds = r.numRounds || 1, isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) throw new Error("numRounds must a integer >= 1");
147361
- this.o = t, this.h = [], this.u = 0, this.l = !1, this.A = 0, this.H = !1, this.S = [], this.p = [];
147362
- }
147363
- update(t) {
147364
- let n,
147365
- e = 0;
147366
- const r = this.m >>> 5,
147367
- i = this.C(t, this.h, this.u),
147368
- s = i.binLen,
147369
- o = i.value,
147370
- h = s >>> 5;
147371
- for (n = 0; n < h; n += r) e + this.m <= s && (this.U = this.v(o.slice(n, n + r), this.U), e += this.m);
147372
- return this.A += e, this.h = o.slice(e >>> 5), this.u = s % this.m, this.l = !0, this;
147373
- }
147374
- getHash(t, n) {
147375
- let e,
147376
- r,
147377
- i = this.R;
147378
- const o = l(n);
147379
- if (this.K) {
147380
- if (-1 === o.outputLen) throw new Error("Output length must be specified in options");
147381
- i = o.outputLen;
147382
- }
147383
- const h = s(t, i, this.T, o);
147384
- if (this.H && this.g) return h(this.g(o));
147385
- for (r = this.F(this.h.slice(), this.u, this.A, this.L(this.U), i), e = 1; e < this.numRounds; e += 1) this.K && i % 32 != 0 && (r[r.length - 1] &= 16777215 >>> 24 - i % 32), r = this.F(r, i, 0, this.B(this.o), i);
147386
- return h(r);
147387
- }
147388
- setHMACKey(t, n, e) {
147389
- if (!this.M) throw new Error("Variant does not support HMAC");
147390
- if (this.l) throw new Error("Cannot set MAC key after calling update");
147391
- const r = i(n, (e || {}).encoding || "UTF8", this.T);
147392
- this.k(r(t));
147393
- }
147394
- k(t) {
147395
- const n = this.m >>> 3,
147396
- e = n / 4 - 1;
147397
- let r;
147398
- if (1 !== this.numRounds) throw new Error(f);
147399
- if (this.H) throw new Error("MAC key already set");
147400
- for (n < t.binLen / 8 && (t.value = this.F(t.value, t.binLen, 0, this.B(this.o), this.R)); t.value.length <= e;) t.value.push(0);
147401
- for (r = 0; r <= e; r += 1) this.S[r] = 909522486 ^ t.value[r], this.p[r] = 1549556828 ^ t.value[r];
147402
- this.U = this.v(this.S, this.U), this.A = this.m, this.H = !0;
147403
- }
147404
- getHMAC(t, n) {
147405
- const e = l(n);
147406
- return s(t, this.R, this.T, e)(this.Y());
147407
- }
147408
- Y() {
147409
- let t;
147410
- if (!this.H) throw new Error("Cannot call getHMAC without first setting MAC key");
147411
- const n = this.F(this.h.slice(), this.u, this.A, this.L(this.U), this.R);
147412
- return t = this.v(this.p, this.B(this.o)), t = this.F(n, this.R, this.m, t, this.R), t;
147413
- }
147414
- }
147415
- function H(t, n) {
147416
- return t << n | t >>> 32 - n;
147417
- }
147418
- function S(t, n) {
147419
- return t >>> n | t << 32 - n;
147420
- }
147421
- function b(t, n) {
147422
- return t >>> n;
147423
- }
147424
- function p(t, n, e) {
147425
- return t ^ n ^ e;
147426
- }
147427
- function d(t, n, e) {
147428
- return t & n ^ ~t & e;
147429
- }
147430
- function m(t, n, e) {
147431
- return t & n ^ t & e ^ n & e;
147432
- }
147433
- function C(t) {
147434
- return S(t, 2) ^ S(t, 13) ^ S(t, 22);
147435
- }
147436
- function y(t, n) {
147437
- const e = (65535 & t) + (65535 & n);
147438
- return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16)) << 16 | 65535 & e;
147439
- }
147440
- function U(t, n, e, r) {
147441
- const i = (65535 & t) + (65535 & n) + (65535 & e) + (65535 & r);
147442
- return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16) + (r >>> 16) + (i >>> 16)) << 16 | 65535 & i;
147443
- }
147444
- function v(t, n, e, r, i) {
147445
- const s = (65535 & t) + (65535 & n) + (65535 & e) + (65535 & r) + (65535 & i);
147446
- return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16) + (r >>> 16) + (i >>> 16) + (s >>> 16)) << 16 | 65535 & s;
147447
- }
147448
- function R(t) {
147449
- return S(t, 7) ^ S(t, 18) ^ b(t, 3);
147450
- }
147451
- function K(t) {
147452
- return S(t, 6) ^ S(t, 11) ^ S(t, 25);
147453
- }
147454
- function T(t) {
147455
- return [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
147456
- }
147457
- function g(t, n) {
147458
- let e, r, i, s, o, h, u;
147459
- const w = [];
147460
- for (e = n[0], r = n[1], i = n[2], s = n[3], o = n[4], u = 0; u < 80; u += 1) w[u] = u < 16 ? t[u] : H(w[u - 3] ^ w[u - 8] ^ w[u - 14] ^ w[u - 16], 1), h = u < 20 ? v(H(e, 5), d(r, i, s), o, 1518500249, w[u]) : u < 40 ? v(H(e, 5), p(r, i, s), o, 1859775393, w[u]) : u < 60 ? v(H(e, 5), m(r, i, s), o, 2400959708, w[u]) : v(H(e, 5), p(r, i, s), o, 3395469782, w[u]), o = s, s = i, i = H(r, 30), r = e, e = h;
147461
- return n[0] = y(e, n[0]), n[1] = y(r, n[1]), n[2] = y(i, n[2]), n[3] = y(s, n[3]), n[4] = y(o, n[4]), n;
147462
- }
147463
- function F(t, n, e, r) {
147464
- let i;
147465
- const s = 15 + (n + 65 >>> 9 << 4),
147466
- h = n + e;
147467
- for (; t.length <= s;) t.push(0);
147468
- for (t[n >>> 5] |= 128 << 24 - n % 32, t[s] = 4294967295 & h, t[s - 1] = h / o | 0, i = 0; i < t.length; i += 16) r = g(t.slice(i, i + 16), r);
147469
- return r;
147470
- }
147471
- let L = class extends E {
147472
- constructor(t, n, e) {
147473
- if ("SHA-1" !== t) throw new Error(c);
147474
- super(t, n, e);
147475
- const r = e || {};
147476
- this.M = !0, this.g = this.Y, this.T = -1, this.C = i(this.t, this.i, this.T), this.v = g, this.L = function (t) {
147477
- return t.slice();
147478
- }, this.B = T, this.F = F, this.U = [1732584193, 4023233417, 2562383102, 271733878, 3285377520], this.m = 512, this.R = 160, this.K = !1, r.hmacKey && this.k(A("hmacKey", r.hmacKey, this.T));
147479
- }
147480
- };
147481
- function B(t) {
147482
- let n;
147483
- return n = "SHA-224" == t ? u.slice() : w.slice(), n;
147484
- }
147485
- function M(t, n) {
147486
- let e, r, i, s, o, u, w, c, f, a, l;
147487
- const A = [];
147488
- for (e = n[0], r = n[1], i = n[2], s = n[3], o = n[4], u = n[5], w = n[6], c = n[7], l = 0; l < 64; l += 1) A[l] = l < 16 ? t[l] : U(S(E = A[l - 2], 17) ^ S(E, 19) ^ b(E, 10), A[l - 7], R(A[l - 15]), A[l - 16]), f = v(c, K(o), d(o, u, w), h[l], A[l]), a = y(C(e), m(e, r, i)), c = w, w = u, u = o, o = y(s, f), s = i, i = r, r = e, e = y(f, a);
147489
- var E;
147490
- return n[0] = y(e, n[0]), n[1] = y(r, n[1]), n[2] = y(i, n[2]), n[3] = y(s, n[3]), n[4] = y(o, n[4]), n[5] = y(u, n[5]), n[6] = y(w, n[6]), n[7] = y(c, n[7]), n;
147491
- }
147492
- let k = class extends E {
147493
- constructor(t, n, e) {
147494
- if ("SHA-224" !== t && "SHA-256" !== t) throw new Error(c);
147495
- super(t, n, e);
147496
- const r = e || {};
147497
- this.g = this.Y, this.M = !0, this.T = -1, this.C = i(this.t, this.i, this.T), this.v = M, this.L = function (t) {
147498
- return t.slice();
147499
- }, this.B = B, this.F = function (n, e, r, i) {
147500
- return function (t, n, e, r, i) {
147501
- let s, h;
147502
- const u = 15 + (n + 65 >>> 9 << 4),
147503
- w = n + e;
147504
- for (; t.length <= u;) t.push(0);
147505
- for (t[n >>> 5] |= 128 << 24 - n % 32, t[u] = 4294967295 & w, t[u - 1] = w / o | 0, s = 0; s < t.length; s += 16) r = M(t.slice(s, s + 16), r);
147506
- return h = "SHA-224" === i ? [r[0], r[1], r[2], r[3], r[4], r[5], r[6]] : r, h;
147507
- }(n, e, r, i, t);
147508
- }, this.U = B(t), this.m = 512, this.R = "SHA-224" === t ? 224 : 256, this.K = !1, r.hmacKey && this.k(A("hmacKey", r.hmacKey, this.T));
147509
- }
147510
- };
147511
- class Y {
147512
- constructor(t, n) {
147513
- this.N = t, this.I = n;
147514
- }
147515
- }
147516
- function N(t, n) {
147517
- let e;
147518
- return n > 32 ? (e = 64 - n, new Y(t.I << n | t.N >>> e, t.N << n | t.I >>> e)) : 0 !== n ? (e = 32 - n, new Y(t.N << n | t.I >>> e, t.I << n | t.N >>> e)) : t;
147519
- }
147520
- function I(t, n) {
147521
- let e;
147522
- return n < 32 ? (e = 32 - n, new Y(t.N >>> n | t.I << e, t.I >>> n | t.N << e)) : (e = 64 - n, new Y(t.I >>> n | t.N << e, t.N >>> n | t.I << e));
147523
- }
147524
- function X(t, n) {
147525
- return new Y(t.N >>> n, t.I >>> n | t.N << 32 - n);
147526
- }
147527
- function z(t, n, e) {
147528
- return new Y(t.N & n.N ^ t.N & e.N ^ n.N & e.N, t.I & n.I ^ t.I & e.I ^ n.I & e.I);
147529
- }
147530
- function x(t) {
147531
- const n = I(t, 28),
147532
- e = I(t, 34),
147533
- r = I(t, 39);
147534
- return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
147535
- }
147536
- function _(t, n) {
147537
- let e, r;
147538
- e = (65535 & t.I) + (65535 & n.I), r = (t.I >>> 16) + (n.I >>> 16) + (e >>> 16);
147539
- const i = (65535 & r) << 16 | 65535 & e;
147540
- e = (65535 & t.N) + (65535 & n.N) + (r >>> 16), r = (t.N >>> 16) + (n.N >>> 16) + (e >>> 16);
147541
- return new Y((65535 & r) << 16 | 65535 & e, i);
147542
- }
147543
- function O(t, n, e, r) {
147544
- let i, s;
147545
- i = (65535 & t.I) + (65535 & n.I) + (65535 & e.I) + (65535 & r.I), s = (t.I >>> 16) + (n.I >>> 16) + (e.I >>> 16) + (r.I >>> 16) + (i >>> 16);
147546
- const o = (65535 & s) << 16 | 65535 & i;
147547
- i = (65535 & t.N) + (65535 & n.N) + (65535 & e.N) + (65535 & r.N) + (s >>> 16), s = (t.N >>> 16) + (n.N >>> 16) + (e.N >>> 16) + (r.N >>> 16) + (i >>> 16);
147548
- return new Y((65535 & s) << 16 | 65535 & i, o);
147549
- }
147550
- function P(t, n, e, r, i) {
147551
- let s, o;
147552
- s = (65535 & t.I) + (65535 & n.I) + (65535 & e.I) + (65535 & r.I) + (65535 & i.I), o = (t.I >>> 16) + (n.I >>> 16) + (e.I >>> 16) + (r.I >>> 16) + (i.I >>> 16) + (s >>> 16);
147553
- const h = (65535 & o) << 16 | 65535 & s;
147554
- s = (65535 & t.N) + (65535 & n.N) + (65535 & e.N) + (65535 & r.N) + (65535 & i.N) + (o >>> 16), o = (t.N >>> 16) + (n.N >>> 16) + (e.N >>> 16) + (r.N >>> 16) + (i.N >>> 16) + (s >>> 16);
147555
- return new Y((65535 & o) << 16 | 65535 & s, h);
147556
- }
147557
- function V(t, n) {
147558
- return new Y(t.N ^ n.N, t.I ^ n.I);
147559
- }
147560
- function Z(t) {
147561
- const n = I(t, 19),
147562
- e = I(t, 61),
147563
- r = X(t, 6);
147564
- return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
147565
- }
147566
- function j(t) {
147567
- const n = I(t, 1),
147568
- e = I(t, 8),
147569
- r = X(t, 7);
147570
- return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
147571
- }
147572
- function q(t) {
147573
- const n = I(t, 14),
147574
- e = I(t, 18),
147575
- r = I(t, 41);
147576
- return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
147577
- }
147578
- const D = [new Y(h[0], 3609767458), new Y(h[1], 602891725), new Y(h[2], 3964484399), new Y(h[3], 2173295548), new Y(h[4], 4081628472), new Y(h[5], 3053834265), new Y(h[6], 2937671579), new Y(h[7], 3664609560), new Y(h[8], 2734883394), new Y(h[9], 1164996542), new Y(h[10], 1323610764), new Y(h[11], 3590304994), new Y(h[12], 4068182383), new Y(h[13], 991336113), new Y(h[14], 633803317), new Y(h[15], 3479774868), new Y(h[16], 2666613458), new Y(h[17], 944711139), new Y(h[18], 2341262773), new Y(h[19], 2007800933), new Y(h[20], 1495990901), new Y(h[21], 1856431235), new Y(h[22], 3175218132), new Y(h[23], 2198950837), new Y(h[24], 3999719339), new Y(h[25], 766784016), new Y(h[26], 2566594879), new Y(h[27], 3203337956), new Y(h[28], 1034457026), new Y(h[29], 2466948901), new Y(h[30], 3758326383), new Y(h[31], 168717936), new Y(h[32], 1188179964), new Y(h[33], 1546045734), new Y(h[34], 1522805485), new Y(h[35], 2643833823), new Y(h[36], 2343527390), new Y(h[37], 1014477480), new Y(h[38], 1206759142), new Y(h[39], 344077627), new Y(h[40], 1290863460), new Y(h[41], 3158454273), new Y(h[42], 3505952657), new Y(h[43], 106217008), new Y(h[44], 3606008344), new Y(h[45], 1432725776), new Y(h[46], 1467031594), new Y(h[47], 851169720), new Y(h[48], 3100823752), new Y(h[49], 1363258195), new Y(h[50], 3750685593), new Y(h[51], 3785050280), new Y(h[52], 3318307427), new Y(h[53], 3812723403), new Y(h[54], 2003034995), new Y(h[55], 3602036899), new Y(h[56], 1575990012), new Y(h[57], 1125592928), new Y(h[58], 2716904306), new Y(h[59], 442776044), new Y(h[60], 593698344), new Y(h[61], 3733110249), new Y(h[62], 2999351573), new Y(h[63], 3815920427), new Y(3391569614, 3928383900), new Y(3515267271, 566280711), new Y(3940187606, 3454069534), new Y(4118630271, 4000239992), new Y(116418474, 1914138554), new Y(174292421, 2731055270), new Y(289380356, 3203993006), new Y(460393269, 320620315), new Y(685471733, 587496836), new Y(852142971, 1086792851), new Y(1017036298, 365543100), new Y(1126000580, 2618297676), new Y(1288033470, 3409855158), new Y(1501505948, 4234509866), new Y(1607167915, 987167468), new Y(1816402316, 1246189591)];
147579
- function G(t) {
147580
- return "SHA-384" === t ? [new Y(3418070365, u[0]), new Y(1654270250, u[1]), new Y(2438529370, u[2]), new Y(355462360, u[3]), new Y(1731405415, u[4]), new Y(41048885895, u[5]), new Y(3675008525, u[6]), new Y(1203062813, u[7])] : [new Y(w[0], 4089235720), new Y(w[1], 2227873595), new Y(w[2], 4271175723), new Y(w[3], 1595750129), new Y(w[4], 2917565137), new Y(w[5], 725511199), new Y(w[6], 4215389547), new Y(w[7], 327033209)];
147581
- }
147582
- function J(t, n) {
147583
- let e, r, i, s, o, h, u, w, c, f, a, l;
147584
- const A = [];
147585
- for (e = n[0], r = n[1], i = n[2], s = n[3], o = n[4], h = n[5], u = n[6], w = n[7], a = 0; a < 80; a += 1) a < 16 ? (l = 2 * a, A[a] = new Y(t[l], t[l + 1])) : A[a] = O(Z(A[a - 2]), A[a - 7], j(A[a - 15]), A[a - 16]), c = P(w, q(o), (H = h, S = u, new Y((E = o).N & H.N ^ ~E.N & S.N, E.I & H.I ^ ~E.I & S.I)), D[a], A[a]), f = _(x(e), z(e, r, i)), w = u, u = h, h = o, o = _(s, c), s = i, i = r, r = e, e = _(c, f);
147586
- var E, H, S;
147587
- return n[0] = _(e, n[0]), n[1] = _(r, n[1]), n[2] = _(i, n[2]), n[3] = _(s, n[3]), n[4] = _(o, n[4]), n[5] = _(h, n[5]), n[6] = _(u, n[6]), n[7] = _(w, n[7]), n;
147588
- }
147589
- let Q = class extends E {
147590
- constructor(t, n, e) {
147591
- if ("SHA-384" !== t && "SHA-512" !== t) throw new Error(c);
147592
- super(t, n, e);
147593
- const r = e || {};
147594
- this.g = this.Y, this.M = !0, this.T = -1, this.C = i(this.t, this.i, this.T), this.v = J, this.L = function (t) {
147595
- return t.slice();
147596
- }, this.B = G, this.F = function (n, e, r, i) {
147597
- return function (t, n, e, r, i) {
147598
- let s, h;
147599
- const u = 31 + (n + 129 >>> 10 << 5),
147600
- w = n + e;
147601
- for (; t.length <= u;) t.push(0);
147602
- for (t[n >>> 5] |= 128 << 24 - n % 32, t[u] = 4294967295 & w, t[u - 1] = w / o | 0, s = 0; s < t.length; s += 32) r = J(t.slice(s, s + 32), r);
147603
- return h = "SHA-384" === i ? [r[0].N, r[0].I, r[1].N, r[1].I, r[2].N, r[2].I, r[3].N, r[3].I, r[4].N, r[4].I, r[5].N, r[5].I] : [r[0].N, r[0].I, r[1].N, r[1].I, r[2].N, r[2].I, r[3].N, r[3].I, r[4].N, r[4].I, r[5].N, r[5].I, r[6].N, r[6].I, r[7].N, r[7].I], h;
147604
- }(n, e, r, i, t);
147605
- }, this.U = G(t), this.m = 1024, this.R = "SHA-384" === t ? 384 : 512, this.K = !1, r.hmacKey && this.k(A("hmacKey", r.hmacKey, this.T));
147606
- }
147607
- };
147608
- const W = [new Y(0, 1), new Y(0, 32898), new Y(2147483648, 32906), new Y(2147483648, 2147516416), new Y(0, 32907), new Y(0, 2147483649), new Y(2147483648, 2147516545), new Y(2147483648, 32777), new Y(0, 138), new Y(0, 136), new Y(0, 2147516425), new Y(0, 2147483658), new Y(0, 2147516555), new Y(2147483648, 139), new Y(2147483648, 32905), new Y(2147483648, 32771), new Y(2147483648, 32770), new Y(2147483648, 128), new Y(0, 32778), new Y(2147483648, 2147483658), new Y(2147483648, 2147516545), new Y(2147483648, 32896), new Y(0, 2147483649), new Y(2147483648, 2147516424)],
147609
- $ = [[0, 36, 3, 41, 18], [1, 44, 10, 45, 2], [62, 6, 43, 15, 61], [28, 55, 25, 21, 56], [27, 20, 39, 8, 14]];
147610
- function tt(t) {
147611
- let n;
147612
- const e = [];
147613
- for (n = 0; n < 5; n += 1) e[n] = [new Y(0, 0), new Y(0, 0), new Y(0, 0), new Y(0, 0), new Y(0, 0)];
147614
- return e;
147615
- }
147616
- function nt(t) {
147617
- let n;
147618
- const e = [];
147619
- for (n = 0; n < 5; n += 1) e[n] = t[n].slice();
147620
- return e;
147621
- }
147622
- function et(t, n) {
147623
- let e, r, i, s;
147624
- const o = [],
147625
- h = [];
147626
- if (null !== t) for (r = 0; r < t.length; r += 2) n[(r >>> 1) % 5][(r >>> 1) / 5 | 0] = V(n[(r >>> 1) % 5][(r >>> 1) / 5 | 0], new Y(t[r + 1], t[r]));
147627
- for (e = 0; e < 24; e += 1) {
147628
- for (s = tt(), r = 0; r < 5; r += 1) o[r] = (u = n[r][0], w = n[r][1], c = n[r][2], f = n[r][3], a = n[r][4], new Y(u.N ^ w.N ^ c.N ^ f.N ^ a.N, u.I ^ w.I ^ c.I ^ f.I ^ a.I));
147629
- for (r = 0; r < 5; r += 1) h[r] = V(o[(r + 4) % 5], N(o[(r + 1) % 5], 1));
147630
- for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) n[r][i] = V(n[r][i], h[r]);
147631
- for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) s[i][(2 * r + 3 * i) % 5] = N(n[r][i], $[r][i]);
147632
- for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) n[r][i] = V(s[r][i], new Y(~s[(r + 1) % 5][i].N & s[(r + 2) % 5][i].N, ~s[(r + 1) % 5][i].I & s[(r + 2) % 5][i].I));
147633
- n[0][0] = V(n[0][0], W[e]);
147634
- }
147635
- var u, w, c, f, a;
147636
- return n;
146928
+ function split(lst, le = false) {
146929
+ let Ah = new Uint32Array(lst.length);
146930
+ let Al = new Uint32Array(lst.length);
146931
+ for(let i = 0; i < lst.length; i++){
146932
+ const { h, l } = fromBig(lst[i], le);
146933
+ [Ah[i], Al[i]] = [
146934
+ h,
146935
+ l
146936
+ ];
146937
+ }
146938
+ return [
146939
+ Ah,
146940
+ Al
146941
+ ];
147637
146942
  }
147638
- function rt(t) {
147639
- let n,
147640
- e,
147641
- r = 0;
147642
- const i = [0, 0],
147643
- s = [4294967295 & t, t / o & 2097151];
147644
- for (n = 6; n >= 0; n--) e = s[n >> 2] >>> 8 * n & 255, 0 === e && 0 === r || (i[r + 1 >> 2] |= e << 8 * (r + 1), r += 1);
147645
- return r = 0 !== r ? r : 1, i[0] |= r, {
147646
- value: r + 1 > 4 ? i : [i[0]],
147647
- binLen: 8 + 8 * r
147648
- };
146943
+ const toBig = (h, l)=>BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
146944
+ // for Shift in [0, 32)
146945
+ const shrSH = (h, _l, s)=>h >>> s;
146946
+ const shrSL = (h, l, s)=>h << 32 - s | l >>> s;
146947
+ // Right rotate for Shift in [1, 32)
146948
+ const rotrSH = (h, l, s)=>h >>> s | l << 32 - s;
146949
+ const rotrSL = (h, l, s)=>h << 32 - s | l >>> s;
146950
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
146951
+ const rotrBH = (h, l, s)=>h << 64 - s | l >>> s - 32;
146952
+ const rotrBL = (h, l, s)=>h >>> s - 32 | l << 64 - s;
146953
+ // Right rotate for shift===32 (just swaps l&h)
146954
+ const rotr32H = (_h, l)=>l;
146955
+ const rotr32L = (h, _l)=>h;
146956
+ // Left rotate for Shift in [1, 32)
146957
+ const rotlSH = (h, l, s)=>h << s | l >>> 32 - s;
146958
+ const rotlSL = (h, l, s)=>l << s | h >>> 32 - s;
146959
+ // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
146960
+ const rotlBH = (h, l, s)=>l << s - 32 | h >>> 64 - s;
146961
+ const rotlBL = (h, l, s)=>h << s - 32 | l >>> 64 - s;
146962
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
146963
+ // simple take carry out of low bit sum by shift, we need to use division.
146964
+ function add(Ah, Al, Bh, Bl) {
146965
+ const l = (Al >>> 0) + (Bl >>> 0);
146966
+ return {
146967
+ h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
146968
+ l: l | 0
146969
+ };
147649
146970
  }
147650
- function it(t) {
147651
- return a(rt(t.binLen), t);
147652
- }
147653
- function st(t, n) {
147654
- let e,
147655
- r = rt(n);
147656
- r = a(r, t);
147657
- const i = n >>> 2,
147658
- s = (i - r.value.length % i) % i;
147659
- for (e = 0; e < s; e++) r.value.push(0);
147660
- return r.value;
147661
- }
147662
- let ot = class extends E {
147663
- constructor(t, n, e) {
147664
- let r = 6,
147665
- s = 0;
147666
- super(t, n, e);
147667
- const o = e || {};
147668
- if (1 !== this.numRounds) {
147669
- if (o.kmacKey || o.hmacKey) throw new Error(f);
147670
- if ("CSHAKE128" === this.o || "CSHAKE256" === this.o) throw new Error("Cannot set numRounds for CSHAKE variants");
147671
- }
147672
- switch (this.T = 1, this.C = i(this.t, this.i, this.T), this.v = et, this.L = nt, this.B = tt, this.U = tt(), this.K = !1, t) {
147673
- case "SHA3-224":
147674
- this.m = s = 1152, this.R = 224, this.M = !0, this.g = this.Y;
147675
- break;
147676
- case "SHA3-256":
147677
- this.m = s = 1088, this.R = 256, this.M = !0, this.g = this.Y;
147678
- break;
147679
- case "SHA3-384":
147680
- this.m = s = 832, this.R = 384, this.M = !0, this.g = this.Y;
147681
- break;
147682
- case "SHA3-512":
147683
- this.m = s = 576, this.R = 512, this.M = !0, this.g = this.Y;
147684
- break;
147685
- case "SHAKE128":
147686
- r = 31, this.m = s = 1344, this.R = -1, this.K = !0, this.M = !1, this.g = null;
147687
- break;
147688
- case "SHAKE256":
147689
- r = 31, this.m = s = 1088, this.R = -1, this.K = !0, this.M = !1, this.g = null;
147690
- break;
147691
- case "KMAC128":
147692
- r = 4, this.m = s = 1344, this.X(e), this.R = -1, this.K = !0, this.M = !1, this.g = this._;
147693
- break;
147694
- case "KMAC256":
147695
- r = 4, this.m = s = 1088, this.X(e), this.R = -1, this.K = !0, this.M = !1, this.g = this._;
147696
- break;
147697
- case "CSHAKE128":
147698
- this.m = s = 1344, r = this.O(e), this.R = -1, this.K = !0, this.M = !1, this.g = null;
147699
- break;
147700
- case "CSHAKE256":
147701
- this.m = s = 1088, r = this.O(e), this.R = -1, this.K = !0, this.M = !1, this.g = null;
147702
- break;
147703
- default:
147704
- throw new Error(c);
147705
- }
147706
- this.F = function (t, n, e, i, o) {
147707
- return function (t, n, e, r, i, s, o) {
147708
- let h,
147709
- u,
147710
- w = 0;
147711
- const c = [],
147712
- f = i >>> 5,
147713
- a = n >>> 5;
147714
- for (h = 0; h < a && n >= i; h += f) r = et(t.slice(h, h + f), r), n -= i;
147715
- for (t = t.slice(h), n %= i; t.length < f;) t.push(0);
147716
- for (h = n >>> 3, t[h >> 2] ^= s << h % 4 * 8, t[f - 1] ^= 2147483648, r = et(t, r); 32 * c.length < o && (u = r[w % 5][w / 5 | 0], c.push(u.I), !(32 * c.length >= o));) c.push(u.N), w += 1, 0 == 64 * w % i && (et(null, r), w = 0);
147717
- return c;
147718
- }(t, n, 0, i, s, r, o);
147719
- }, o.hmacKey && this.k(A("hmacKey", o.hmacKey, this.T));
147720
- }
147721
- O(t, n) {
147722
- const e = function (t) {
147723
- const n = t || {};
147724
- return {
147725
- funcName: A("funcName", n.funcName, 1, {
147726
- value: [],
147727
- binLen: 0
147728
- }),
147729
- customization: A("Customization", n.customization, 1, {
147730
- value: [],
147731
- binLen: 0
147732
- })
147733
- };
147734
- }(t || {});
147735
- n && (e.funcName = n);
147736
- const r = a(it(e.funcName), it(e.customization));
147737
- if (0 !== e.customization.binLen || 0 !== e.funcName.binLen) {
147738
- const t = st(r, this.m >>> 3);
147739
- for (let n = 0; n < t.length; n += this.m >>> 5) this.U = this.v(t.slice(n, n + (this.m >>> 5)), this.U), this.A += this.m;
147740
- return 4;
147741
- }
147742
- return 31;
147743
- }
147744
- X(t) {
147745
- const n = function (t) {
147746
- const n = t || {};
147747
- return {
147748
- kmacKey: A("kmacKey", n.kmacKey, 1),
147749
- funcName: {
147750
- value: [1128353099],
147751
- binLen: 32
147752
- },
147753
- customization: A("Customization", n.customization, 1, {
147754
- value: [],
147755
- binLen: 0
147756
- })
147757
- };
147758
- }(t || {});
147759
- this.O(t, n.funcName);
147760
- const e = st(it(n.kmacKey), this.m >>> 3);
147761
- for (let t = 0; t < e.length; t += this.m >>> 5) this.U = this.v(e.slice(t, t + (this.m >>> 5)), this.U), this.A += this.m;
147762
- this.H = !0;
147763
- }
147764
- _(t) {
147765
- const n = a({
147766
- value: this.h.slice(),
147767
- binLen: this.u
147768
- }, function (t) {
147769
- let n,
147770
- e,
147771
- r = 0;
147772
- const i = [0, 0],
147773
- s = [4294967295 & t, t / o & 2097151];
147774
- for (n = 6; n >= 0; n--) e = s[n >> 2] >>> 8 * n & 255, 0 === e && 0 === r || (i[r >> 2] |= e << 8 * r, r += 1);
147775
- return r = 0 !== r ? r : 1, i[r >> 2] |= r << 8 * r, {
147776
- value: r + 1 > 4 ? i : [i[0]],
147777
- binLen: 8 + 8 * r
147778
- };
147779
- }(t.outputLen));
147780
- return this.F(n.value, n.binLen, this.A, this.L(this.U), t.outputLen);
147781
- }
146971
+ // Addition with more than 2 elements
146972
+ const add3L = (Al, Bl, Cl)=>(Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
146973
+ const add3H = (low, Ah, Bh, Ch)=>Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
146974
+ const add4L = (Al, Bl, Cl, Dl)=>(Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
146975
+ const add4H = (low, Ah, Bh, Ch, Dh)=>Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
146976
+ const add5L = (Al, Bl, Cl, Dl, El)=>(Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
146977
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh)=>Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
146978
+ // prettier-ignore
146979
+ const u64 = {
146980
+ fromBig,
146981
+ split,
146982
+ toBig,
146983
+ shrSH,
146984
+ shrSL,
146985
+ rotrSH,
146986
+ rotrSL,
146987
+ rotrBH,
146988
+ rotrBL,
146989
+ rotr32H,
146990
+ rotr32L,
146991
+ rotlSH,
146992
+ rotlSL,
146993
+ rotlBH,
146994
+ rotlBL,
146995
+ add,
146996
+ add3L,
146997
+ add3H,
146998
+ add4L,
146999
+ add4H,
147000
+ add5H,
147001
+ add5L
147782
147002
  };
147783
- class ht {
147784
- constructor(t, n, e) {
147785
- if ("SHA-1" == t) this.P = new L(t, n, e);else if ("SHA-224" == t || "SHA-256" == t) this.P = new k(t, n, e);else if ("SHA-384" == t || "SHA-512" == t) this.P = new Q(t, n, e);else {
147786
- if ("SHA3-224" != t && "SHA3-256" != t && "SHA3-384" != t && "SHA3-512" != t && "SHAKE128" != t && "SHAKE256" != t && "CSHAKE128" != t && "CSHAKE256" != t && "KMAC128" != t && "KMAC256" != t) throw new Error(c);
147787
- this.P = new ot(t, n, e);
147003
+
147004
+ // Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
147005
+ // prettier-ignore
147006
+ const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (()=>u64.split([
147007
+ '0x428a2f98d728ae22',
147008
+ '0x7137449123ef65cd',
147009
+ '0xb5c0fbcfec4d3b2f',
147010
+ '0xe9b5dba58189dbbc',
147011
+ '0x3956c25bf348b538',
147012
+ '0x59f111f1b605d019',
147013
+ '0x923f82a4af194f9b',
147014
+ '0xab1c5ed5da6d8118',
147015
+ '0xd807aa98a3030242',
147016
+ '0x12835b0145706fbe',
147017
+ '0x243185be4ee4b28c',
147018
+ '0x550c7dc3d5ffb4e2',
147019
+ '0x72be5d74f27b896f',
147020
+ '0x80deb1fe3b1696b1',
147021
+ '0x9bdc06a725c71235',
147022
+ '0xc19bf174cf692694',
147023
+ '0xe49b69c19ef14ad2',
147024
+ '0xefbe4786384f25e3',
147025
+ '0x0fc19dc68b8cd5b5',
147026
+ '0x240ca1cc77ac9c65',
147027
+ '0x2de92c6f592b0275',
147028
+ '0x4a7484aa6ea6e483',
147029
+ '0x5cb0a9dcbd41fbd4',
147030
+ '0x76f988da831153b5',
147031
+ '0x983e5152ee66dfab',
147032
+ '0xa831c66d2db43210',
147033
+ '0xb00327c898fb213f',
147034
+ '0xbf597fc7beef0ee4',
147035
+ '0xc6e00bf33da88fc2',
147036
+ '0xd5a79147930aa725',
147037
+ '0x06ca6351e003826f',
147038
+ '0x142929670a0e6e70',
147039
+ '0x27b70a8546d22ffc',
147040
+ '0x2e1b21385c26c926',
147041
+ '0x4d2c6dfc5ac42aed',
147042
+ '0x53380d139d95b3df',
147043
+ '0x650a73548baf63de',
147044
+ '0x766a0abb3c77b2a8',
147045
+ '0x81c2c92e47edaee6',
147046
+ '0x92722c851482353b',
147047
+ '0xa2bfe8a14cf10364',
147048
+ '0xa81a664bbc423001',
147049
+ '0xc24b8b70d0f89791',
147050
+ '0xc76c51a30654be30',
147051
+ '0xd192e819d6ef5218',
147052
+ '0xd69906245565a910',
147053
+ '0xf40e35855771202a',
147054
+ '0x106aa07032bbd1b8',
147055
+ '0x19a4c116b8d2d0c8',
147056
+ '0x1e376c085141ab53',
147057
+ '0x2748774cdf8eeb99',
147058
+ '0x34b0bcb5e19b48a8',
147059
+ '0x391c0cb3c5c95a63',
147060
+ '0x4ed8aa4ae3418acb',
147061
+ '0x5b9cca4f7763e373',
147062
+ '0x682e6ff3d6b2b8a3',
147063
+ '0x748f82ee5defb2fc',
147064
+ '0x78a5636f43172f60',
147065
+ '0x84c87814a1f0ab72',
147066
+ '0x8cc702081a6439ec',
147067
+ '0x90befffa23631e28',
147068
+ '0xa4506cebde82bde9',
147069
+ '0xbef9a3f7b2c67915',
147070
+ '0xc67178f2e372532b',
147071
+ '0xca273eceea26619c',
147072
+ '0xd186b8c721c0c207',
147073
+ '0xeada7dd6cde0eb1e',
147074
+ '0xf57d4f7fee6ed178',
147075
+ '0x06f067aa72176fba',
147076
+ '0x0a637dc5a2c898a6',
147077
+ '0x113f9804bef90dae',
147078
+ '0x1b710b35131c471b',
147079
+ '0x28db77f523047d84',
147080
+ '0x32caab7b40c72493',
147081
+ '0x3c9ebe0a15c9bebc',
147082
+ '0x431d67c49c100d4c',
147083
+ '0x4cc5d4becb3e42b6',
147084
+ '0x597f299cfc657e2a',
147085
+ '0x5fcb6fab3ad6faec',
147086
+ '0x6c44198c4a475817'
147087
+ ].map((n)=>BigInt(n))))();
147088
+ // Temporary buffer, not used to store anything between runs
147089
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
147090
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
147091
+ class SHA512 extends HashMD {
147092
+ // prettier-ignore
147093
+ get() {
147094
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
147095
+ return [
147096
+ Ah,
147097
+ Al,
147098
+ Bh,
147099
+ Bl,
147100
+ Ch,
147101
+ Cl,
147102
+ Dh,
147103
+ Dl,
147104
+ Eh,
147105
+ El,
147106
+ Fh,
147107
+ Fl,
147108
+ Gh,
147109
+ Gl,
147110
+ Hh,
147111
+ Hl
147112
+ ];
147788
147113
  }
147789
- }
147790
- update(t) {
147791
- return this.P.update(t), this;
147792
- }
147793
- getHash(t, n) {
147794
- return this.P.getHash(t, n);
147795
- }
147796
- setHMACKey(t, n, e) {
147797
- this.P.setHMACKey(t, n, e);
147798
- }
147799
- getHMAC(t, n) {
147800
- return this.P.getHMAC(t, n);
147801
- }
147802
- }
147114
+ // prettier-ignore
147115
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
147116
+ this.Ah = Ah | 0;
147117
+ this.Al = Al | 0;
147118
+ this.Bh = Bh | 0;
147119
+ this.Bl = Bl | 0;
147120
+ this.Ch = Ch | 0;
147121
+ this.Cl = Cl | 0;
147122
+ this.Dh = Dh | 0;
147123
+ this.Dl = Dl | 0;
147124
+ this.Eh = Eh | 0;
147125
+ this.El = El | 0;
147126
+ this.Fh = Fh | 0;
147127
+ this.Fl = Fl | 0;
147128
+ this.Gh = Gh | 0;
147129
+ this.Gl = Gl | 0;
147130
+ this.Hh = Hh | 0;
147131
+ this.Hl = Hl | 0;
147132
+ }
147133
+ process(view, offset) {
147134
+ // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
147135
+ for(let i = 0; i < 16; i++, offset += 4){
147136
+ SHA512_W_H[i] = view.getUint32(offset);
147137
+ SHA512_W_L[i] = view.getUint32(offset += 4);
147138
+ }
147139
+ for(let i = 16; i < 80; i++){
147140
+ // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
147141
+ const W15h = SHA512_W_H[i - 15] | 0;
147142
+ const W15l = SHA512_W_L[i - 15] | 0;
147143
+ const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
147144
+ const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
147145
+ // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
147146
+ const W2h = SHA512_W_H[i - 2] | 0;
147147
+ const W2l = SHA512_W_L[i - 2] | 0;
147148
+ const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
147149
+ const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
147150
+ // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
147151
+ const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
147152
+ const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
147153
+ SHA512_W_H[i] = SUMh | 0;
147154
+ SHA512_W_L[i] = SUMl | 0;
147155
+ }
147156
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
147157
+ // Compression function main loop, 80 rounds
147158
+ for(let i = 0; i < 80; i++){
147159
+ // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
147160
+ const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
147161
+ const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
147162
+ //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
147163
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
147164
+ const CHIl = El & Fl ^ ~El & Gl;
147165
+ // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
147166
+ // prettier-ignore
147167
+ const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
147168
+ const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
147169
+ const T1l = T1ll | 0;
147170
+ // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
147171
+ const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
147172
+ const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
147173
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
147174
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
147175
+ Hh = Gh | 0;
147176
+ Hl = Gl | 0;
147177
+ Gh = Fh | 0;
147178
+ Gl = Fl | 0;
147179
+ Fh = Eh | 0;
147180
+ Fl = El | 0;
147181
+ ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
147182
+ Dh = Ch | 0;
147183
+ Dl = Cl | 0;
147184
+ Ch = Bh | 0;
147185
+ Cl = Bl | 0;
147186
+ Bh = Ah | 0;
147187
+ Bl = Al | 0;
147188
+ const All = u64.add3L(T1l, sigma0l, MAJl);
147189
+ Ah = u64.add3H(All, T1h, sigma0h, MAJh);
147190
+ Al = All | 0;
147191
+ }
147192
+ // Add the compressed chunk to the current hash value
147193
+ ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
147194
+ ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
147195
+ ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
147196
+ ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
147197
+ ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
147198
+ ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
147199
+ ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
147200
+ ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
147201
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
147202
+ }
147203
+ roundClean() {
147204
+ SHA512_W_H.fill(0);
147205
+ SHA512_W_L.fill(0);
147206
+ }
147207
+ destroy() {
147208
+ this.buffer.fill(0);
147209
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
147210
+ }
147211
+ constructor(){
147212
+ super(128, 64, 16, false);
147213
+ // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
147214
+ // Also looks cleaner and easier to verify with spec.
147215
+ // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
147216
+ // h -- high 32 bits, l -- low 32 bits
147217
+ this.Ah = 0x6a09e667 | 0;
147218
+ this.Al = 0xf3bcc908 | 0;
147219
+ this.Bh = 0xbb67ae85 | 0;
147220
+ this.Bl = 0x84caa73b | 0;
147221
+ this.Ch = 0x3c6ef372 | 0;
147222
+ this.Cl = 0xfe94f82b | 0;
147223
+ this.Dh = 0xa54ff53a | 0;
147224
+ this.Dl = 0x5f1d36f1 | 0;
147225
+ this.Eh = 0x510e527f | 0;
147226
+ this.El = 0xade682d1 | 0;
147227
+ this.Fh = 0x9b05688c | 0;
147228
+ this.Fl = 0x2b3e6c1f | 0;
147229
+ this.Gh = 0x1f83d9ab | 0;
147230
+ this.Gl = 0xfb41bd6b | 0;
147231
+ this.Hh = 0x5be0cd19 | 0;
147232
+ this.Hl = 0x137e2179 | 0;
147233
+ }
147234
+ }
147235
+ class SHA384 extends SHA512 {
147236
+ constructor(){
147237
+ super();
147238
+ // h -- high 32 bits, l -- low 32 bits
147239
+ this.Ah = 0xcbbb9d5d | 0;
147240
+ this.Al = 0xc1059ed8 | 0;
147241
+ this.Bh = 0x629a292a | 0;
147242
+ this.Bl = 0x367cd507 | 0;
147243
+ this.Ch = 0x9159015a | 0;
147244
+ this.Cl = 0x3070dd17 | 0;
147245
+ this.Dh = 0x152fecd8 | 0;
147246
+ this.Dl = 0xf70e5939 | 0;
147247
+ this.Eh = 0x67332667 | 0;
147248
+ this.El = 0xffc00b31 | 0;
147249
+ this.Fh = 0x8eb44a87 | 0;
147250
+ this.Fl = 0x68581511 | 0;
147251
+ this.Gh = 0xdb0c2e0d | 0;
147252
+ this.Gl = 0x64f98fa7 | 0;
147253
+ this.Hh = 0x47b5481d | 0;
147254
+ this.Hl = 0xbefa4fa4 | 0;
147255
+ this.outputLen = 48;
147256
+ }
147257
+ }
147258
+ const sha512 = /* @__PURE__ */ wrapConstructor(()=>new SHA512());
147259
+ const sha384 = /* @__PURE__ */ wrapConstructor(()=>new SHA384());
147260
+
147261
+ // SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
147262
+ // It's called a sponge function.
147263
+ // Various per round constants calculations
147264
+ const SHA3_PI = [];
147265
+ const SHA3_ROTL = [];
147266
+ const _SHA3_IOTA = [];
147267
+ const _0n = /* @__PURE__ */ BigInt(0);
147268
+ const _1n = /* @__PURE__ */ BigInt(1);
147269
+ const _2n = /* @__PURE__ */ BigInt(2);
147270
+ const _7n = /* @__PURE__ */ BigInt(7);
147271
+ const _256n = /* @__PURE__ */ BigInt(256);
147272
+ const _0x71n = /* @__PURE__ */ BigInt(0x71);
147273
+ for(let round = 0, R = _1n, x = 1, y = 0; round < 24; round++){
147274
+ // Pi
147275
+ [x, y] = [
147276
+ y,
147277
+ (2 * x + 3 * y) % 5
147278
+ ];
147279
+ SHA3_PI.push(2 * (5 * y + x));
147280
+ // Rotational
147281
+ SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
147282
+ // Iota
147283
+ let t = _0n;
147284
+ for(let j = 0; j < 7; j++){
147285
+ R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
147286
+ if (R & _2n) t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
147287
+ }
147288
+ _SHA3_IOTA.push(t);
147289
+ }
147290
+ const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
147291
+ // Left rotation (without 0, 32, 64)
147292
+ const rotlH = (h, l, s)=>s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
147293
+ const rotlL = (h, l, s)=>s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
147294
+ // Same as keccakf1600, but allows to skip some rounds
147295
+ function keccakP(s, rounds = 24) {
147296
+ const B = new Uint32Array(5 * 2);
147297
+ // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
147298
+ for(let round = 24 - rounds; round < 24; round++){
147299
+ // Theta θ
147300
+ for(let x = 0; x < 10; x++)B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
147301
+ for(let x = 0; x < 10; x += 2){
147302
+ const idx1 = (x + 8) % 10;
147303
+ const idx0 = (x + 2) % 10;
147304
+ const B0 = B[idx0];
147305
+ const B1 = B[idx0 + 1];
147306
+ const Th = rotlH(B0, B1, 1) ^ B[idx1];
147307
+ const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
147308
+ for(let y = 0; y < 50; y += 10){
147309
+ s[x + y] ^= Th;
147310
+ s[x + y + 1] ^= Tl;
147311
+ }
147312
+ }
147313
+ // Rho (ρ) and Pi (π)
147314
+ let curH = s[2];
147315
+ let curL = s[3];
147316
+ for(let t = 0; t < 24; t++){
147317
+ const shift = SHA3_ROTL[t];
147318
+ const Th = rotlH(curH, curL, shift);
147319
+ const Tl = rotlL(curH, curL, shift);
147320
+ const PI = SHA3_PI[t];
147321
+ curH = s[PI];
147322
+ curL = s[PI + 1];
147323
+ s[PI] = Th;
147324
+ s[PI + 1] = Tl;
147325
+ }
147326
+ // Chi (χ)
147327
+ for(let y = 0; y < 50; y += 10){
147328
+ for(let x = 0; x < 10; x++)B[x] = s[y + x];
147329
+ for(let x = 0; x < 10; x++)s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
147330
+ }
147331
+ // Iota (ι)
147332
+ s[0] ^= SHA3_IOTA_H[round];
147333
+ s[1] ^= SHA3_IOTA_L[round];
147334
+ }
147335
+ B.fill(0);
147336
+ }
147337
+ class Keccak extends Hash {
147338
+ keccak() {
147339
+ if (!isLE) byteSwap32(this.state32);
147340
+ keccakP(this.state32, this.rounds);
147341
+ if (!isLE) byteSwap32(this.state32);
147342
+ this.posOut = 0;
147343
+ this.pos = 0;
147344
+ }
147345
+ update(data) {
147346
+ exists(this);
147347
+ const { blockLen, state } = this;
147348
+ data = toBytes(data);
147349
+ const len = data.length;
147350
+ for(let pos = 0; pos < len;){
147351
+ const take = Math.min(blockLen - this.pos, len - pos);
147352
+ for(let i = 0; i < take; i++)state[this.pos++] ^= data[pos++];
147353
+ if (this.pos === blockLen) this.keccak();
147354
+ }
147355
+ return this;
147356
+ }
147357
+ finish() {
147358
+ if (this.finished) return;
147359
+ this.finished = true;
147360
+ const { state, suffix, pos, blockLen } = this;
147361
+ // Do the padding
147362
+ state[pos] ^= suffix;
147363
+ if ((suffix & 0x80) !== 0 && pos === blockLen - 1) this.keccak();
147364
+ state[blockLen - 1] ^= 0x80;
147365
+ this.keccak();
147366
+ }
147367
+ writeInto(out) {
147368
+ exists(this, false);
147369
+ bytes(out);
147370
+ this.finish();
147371
+ const bufferOut = this.state;
147372
+ const { blockLen } = this;
147373
+ for(let pos = 0, len = out.length; pos < len;){
147374
+ if (this.posOut >= blockLen) this.keccak();
147375
+ const take = Math.min(blockLen - this.posOut, len - pos);
147376
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
147377
+ this.posOut += take;
147378
+ pos += take;
147379
+ }
147380
+ return out;
147381
+ }
147382
+ xofInto(out) {
147383
+ // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
147384
+ if (!this.enableXOF) throw new Error('XOF is not possible for this instance');
147385
+ return this.writeInto(out);
147386
+ }
147387
+ xof(bytes) {
147388
+ number(bytes);
147389
+ return this.xofInto(new Uint8Array(bytes));
147390
+ }
147391
+ digestInto(out) {
147392
+ output(out, this);
147393
+ if (this.finished) throw new Error('digest() was already called');
147394
+ this.writeInto(out);
147395
+ this.destroy();
147396
+ return out;
147397
+ }
147398
+ digest() {
147399
+ return this.digestInto(new Uint8Array(this.outputLen));
147400
+ }
147401
+ destroy() {
147402
+ this.destroyed = true;
147403
+ this.state.fill(0);
147404
+ }
147405
+ _cloneInto(to) {
147406
+ const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
147407
+ to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
147408
+ to.state32.set(this.state32);
147409
+ to.pos = this.pos;
147410
+ to.posOut = this.posOut;
147411
+ to.finished = this.finished;
147412
+ to.rounds = rounds;
147413
+ // Suffix can change in cSHAKE
147414
+ to.suffix = suffix;
147415
+ to.outputLen = outputLen;
147416
+ to.enableXOF = enableXOF;
147417
+ to.destroyed = this.destroyed;
147418
+ return to;
147419
+ }
147420
+ // NOTE: we accept arguments in bytes instead of bits here.
147421
+ constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24){
147422
+ super();
147423
+ this.blockLen = blockLen;
147424
+ this.suffix = suffix;
147425
+ this.outputLen = outputLen;
147426
+ this.enableXOF = enableXOF;
147427
+ this.rounds = rounds;
147428
+ this.pos = 0;
147429
+ this.posOut = 0;
147430
+ this.finished = false;
147431
+ this.destroyed = false;
147432
+ // Can be passed from user as dkLen
147433
+ number(outputLen);
147434
+ // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
147435
+ if (0 >= this.blockLen || this.blockLen >= 200) throw new Error('Sha3 supports only keccak-f1600 function');
147436
+ this.state = new Uint8Array(200);
147437
+ this.state32 = u32(this.state);
147438
+ }
147439
+ }
147440
+ const gen = (suffix, blockLen, outputLen)=>wrapConstructor(()=>new Keccak(blockLen, suffix, outputLen));
147441
+ const sha3_224 = /* @__PURE__ */ gen(0x06, 144, 224 / 8);
147442
+ /**
147443
+ * SHA3-256 hash function
147444
+ * @param message - that would be hashed
147445
+ */ const sha3_256 = /* @__PURE__ */ gen(0x06, 136, 256 / 8);
147446
+ const sha3_384 = /* @__PURE__ */ gen(0x06, 104, 384 / 8);
147447
+ const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8);
147803
147448
 
147804
147449
  /**
147805
147450
  * "globalThis" ponyfill.
147806
147451
  * @see [A horrifying globalThis polyfill in universal JavaScript](https://mathiasbynens.be/notes/globalthis)
147807
147452
  * @type {Object.<string, *>}
147808
- */
147809
- const globalScope = (() => {
147810
- if (typeof globalThis === "object") return globalThis;else {
147811
- Object.defineProperty(Object.prototype, "__GLOBALTHIS__", {
147812
- get() {
147813
- return this;
147814
- },
147815
- configurable: true
147816
- });
147817
- try {
147818
- // @ts-ignore
147819
- // eslint-disable-next-line no-undef
147820
- if (typeof __GLOBALTHIS__ !== "undefined") return __GLOBALTHIS__;
147821
- } finally {
147822
- // @ts-ignore
147823
- delete Object.prototype.__GLOBALTHIS__;
147453
+ */ const globalScope = (()=>{
147454
+ if (typeof globalThis === "object") return globalThis;
147455
+ else {
147456
+ Object.defineProperty(Object.prototype, "__GLOBALTHIS__", {
147457
+ get () {
147458
+ return this;
147459
+ },
147460
+ configurable: true
147461
+ });
147462
+ try {
147463
+ // @ts-ignore
147464
+ // eslint-disable-next-line no-undef
147465
+ if (typeof __GLOBALTHIS__ !== "undefined") return __GLOBALTHIS__;
147466
+ } finally{
147467
+ // @ts-ignore
147468
+ delete Object.prototype.__GLOBALTHIS__;
147469
+ }
147824
147470
  }
147825
- }
147826
-
147827
- // Still unable to determine "globalThis", fall back to a naive method.
147828
- if (typeof self !== "undefined") return self;else if (typeof window !== "undefined") return window;else if (typeof global !== "undefined") return global;
147829
- return undefined;
147471
+ // Still unable to determine "globalThis", fall back to a naive method.
147472
+ if (typeof self !== "undefined") return self;
147473
+ else if (typeof window !== "undefined") return window;
147474
+ else if (typeof global !== "undefined") return global;
147475
+ return undefined;
147830
147476
  })();
147831
147477
 
147832
147478
  /**
147833
- * OpenSSL to jsSHA algorithms map.
147834
- * @type {Object.<string, "SHA-1"|"SHA-224"|"SHA-256"|"SHA-384"|"SHA-512"|"SHA3-224"|"SHA3-256"|"SHA3-384"|"SHA3-512">}
147835
- */
147836
- const OPENSSL_JSSHA_ALGO_MAP = {
147837
- SHA1: "SHA-1",
147838
- SHA224: "SHA-224",
147839
- SHA256: "SHA-256",
147840
- SHA384: "SHA-384",
147841
- SHA512: "SHA-512",
147842
- "SHA3-224": "SHA3-224",
147843
- "SHA3-256": "SHA3-256",
147844
- "SHA3-384": "SHA3-384",
147845
- "SHA3-512": "SHA3-512"
147479
+ * OpenSSL-Noble hashes map.
147480
+ * @type {Object.<string, sha1|sha224|sha256|sha384|sha512|sha3_224|sha3_256|sha3_384|sha3_512>}
147481
+ */ const OPENSSL_NOBLE_HASHES = {
147482
+ SHA1: sha1,
147483
+ SHA224: sha224,
147484
+ SHA256: sha256,
147485
+ SHA384: sha384,
147486
+ SHA512: sha512,
147487
+ "SHA3-224": sha3_224,
147488
+ "SHA3-256": sha3_256,
147489
+ "SHA3-384": sha3_384,
147490
+ "SHA3-512": sha3_512
147846
147491
  };
147847
-
147848
147492
  /**
147849
147493
  * Calculates an HMAC digest.
147850
147494
  * In Node.js, the command "openssl list -digest-algorithms" displays the available digest algorithms.
147851
147495
  * @param {string} algorithm Algorithm.
147852
- * @param {ArrayBuffer} key Key.
147853
- * @param {ArrayBuffer} message Message.
147854
- * @returns {ArrayBuffer} Digest.
147855
- */
147856
- const hmacDigest = (algorithm, key, message) => {
147857
- {
147858
- const variant = OPENSSL_JSSHA_ALGO_MAP[algorithm.toUpperCase()];
147859
- if (typeof variant === "undefined") {
147860
- throw new TypeError("Unknown hash function");
147496
+ * @param {Uint8Array} key Key.
147497
+ * @param {Uint8Array} message Message.
147498
+ * @returns {Uint8Array} Digest.
147499
+ */ const hmacDigest = (algorithm, key, message)=>{
147500
+ if (hmac) {
147501
+ const hash = OPENSSL_NOBLE_HASHES[algorithm.toUpperCase()];
147502
+ if (!hash) throw new TypeError("Unknown hash function");
147503
+ return hmac(hash, key, message);
147504
+ } else {
147505
+ throw new Error("Missing HMAC function");
147861
147506
  }
147862
- const hmac = new ht(variant, "ARRAYBUFFER");
147863
- hmac.setHMACKey(key, "ARRAYBUFFER");
147864
- hmac.update(message);
147865
- return hmac.getHMAC("ARRAYBUFFER");
147866
- }
147867
147507
  };
147868
147508
 
147869
147509
  /**
147870
147510
  * RFC 4648 base32 alphabet without pad.
147871
147511
  * @type {string}
147872
- */
147873
- const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
147874
-
147512
+ */ const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
147875
147513
  /**
147876
- * Converts a base32 string to an ArrayBuffer (RFC 4648).
147514
+ * Converts a base32 string to an Uint8Array (RFC 4648).
147877
147515
  * @see [LinusU/base32-decode](https://github.com/LinusU/base32-decode)
147878
147516
  * @param {string} str Base32 string.
147879
- * @returns {ArrayBuffer} ArrayBuffer.
147880
- */
147881
- const base32ToBuf = str => {
147882
- // Canonicalize to all upper case and remove padding if it exists.
147883
- let end = str.length;
147884
- while (str[end - 1] === "=") --end;
147885
- const cstr = (end < str.length ? str.substring(0, end) : str).toUpperCase();
147886
- const buf = new ArrayBuffer(cstr.length * 5 / 8 | 0);
147887
- const arr = new Uint8Array(buf);
147888
- let bits = 0;
147889
- let value = 0;
147890
- let index = 0;
147891
- for (let i = 0; i < cstr.length; i++) {
147892
- const idx = ALPHABET.indexOf(cstr[i]);
147893
- if (idx === -1) throw new TypeError(`Invalid character found: ${cstr[i]}`);
147894
- value = value << 5 | idx;
147895
- bits += 5;
147896
- if (bits >= 8) {
147897
- bits -= 8;
147898
- arr[index++] = value >>> bits;
147517
+ * @returns {Uint8Array} Uint8Array.
147518
+ */ const base32Decode = (str)=>{
147519
+ // Canonicalize to all upper case and remove padding if it exists.
147520
+ let end = str.length;
147521
+ while(str[end - 1] === "=")--end;
147522
+ const cstr = (end < str.length ? str.substring(0, end) : str).toUpperCase();
147523
+ const buf = new ArrayBuffer(cstr.length * 5 / 8 | 0);
147524
+ const arr = new Uint8Array(buf);
147525
+ let bits = 0;
147526
+ let value = 0;
147527
+ let index = 0;
147528
+ for(let i = 0; i < cstr.length; i++){
147529
+ const idx = ALPHABET.indexOf(cstr[i]);
147530
+ if (idx === -1) throw new TypeError(`Invalid character found: ${cstr[i]}`);
147531
+ value = value << 5 | idx;
147532
+ bits += 5;
147533
+ if (bits >= 8) {
147534
+ bits -= 8;
147535
+ arr[index++] = value >>> bits;
147536
+ }
147899
147537
  }
147900
- }
147901
- return buf;
147538
+ return arr;
147902
147539
  };
147903
-
147904
147540
  /**
147905
- * Converts an ArrayBuffer to a base32 string (RFC 4648).
147541
+ * Converts an Uint8Array to a base32 string (RFC 4648).
147906
147542
  * @see [LinusU/base32-encode](https://github.com/LinusU/base32-encode)
147907
- * @param {ArrayBuffer} buf ArrayBuffer.
147543
+ * @param {Uint8Array} arr Uint8Array.
147908
147544
  * @returns {string} Base32 string.
147909
- */
147910
- const base32FromBuf = buf => {
147911
- const arr = new Uint8Array(buf);
147912
- let bits = 0;
147913
- let value = 0;
147914
- let str = "";
147915
- for (let i = 0; i < arr.length; i++) {
147916
- value = value << 8 | arr[i];
147917
- bits += 8;
147918
- while (bits >= 5) {
147919
- str += ALPHABET[value >>> bits - 5 & 31];
147920
- bits -= 5;
147921
- }
147922
- }
147923
- if (bits > 0) {
147924
- str += ALPHABET[value << 5 - bits & 31];
147925
- }
147926
- return str;
147545
+ */ const base32Encode = (arr)=>{
147546
+ let bits = 0;
147547
+ let value = 0;
147548
+ let str = "";
147549
+ for(let i = 0; i < arr.length; i++){
147550
+ value = value << 8 | arr[i];
147551
+ bits += 8;
147552
+ while(bits >= 5){
147553
+ str += ALPHABET[value >>> bits - 5 & 31];
147554
+ bits -= 5;
147555
+ }
147556
+ }
147557
+ if (bits > 0) {
147558
+ str += ALPHABET[value << 5 - bits & 31];
147559
+ }
147560
+ return str;
147927
147561
  };
147928
147562
 
147929
147563
  /**
147930
- * Converts a hexadecimal string to an ArrayBuffer.
147564
+ * Converts a hexadecimal string to an Uint8Array.
147931
147565
  * @param {string} str Hexadecimal string.
147932
- * @returns {ArrayBuffer} ArrayBuffer.
147933
- */
147934
- const hexToBuf = str => {
147935
- const buf = new ArrayBuffer(str.length / 2);
147936
- const arr = new Uint8Array(buf);
147937
- for (let i = 0; i < str.length; i += 2) {
147938
- arr[i / 2] = parseInt(str.substring(i, i + 2), 16);
147939
- }
147940
- return buf;
147566
+ * @returns {Uint8Array} Uint8Array.
147567
+ */ const hexDecode = (str)=>{
147568
+ const buf = new ArrayBuffer(str.length / 2);
147569
+ const arr = new Uint8Array(buf);
147570
+ for(let i = 0; i < str.length; i += 2){
147571
+ arr[i / 2] = parseInt(str.substring(i, i + 2), 16);
147572
+ }
147573
+ return arr;
147941
147574
  };
147942
-
147943
147575
  /**
147944
- * Converts an ArrayBuffer to a hexadecimal string.
147945
- * @param {ArrayBuffer} buf ArrayBuffer.
147576
+ * Converts an Uint8Array to a hexadecimal string.
147577
+ * @param {Uint8Array} arr Uint8Array.
147946
147578
  * @returns {string} Hexadecimal string.
147947
- */
147948
- const hexFromBuf = buf => {
147949
- const arr = new Uint8Array(buf);
147950
- let str = "";
147951
- for (let i = 0; i < arr.length; i++) {
147952
- const hex = arr[i].toString(16);
147953
- if (hex.length === 1) str += "0";
147954
- str += hex;
147955
- }
147956
- return str.toUpperCase();
147579
+ */ const hexEncode = (arr)=>{
147580
+ let str = "";
147581
+ for(let i = 0; i < arr.length; i++){
147582
+ const hex = arr[i].toString(16);
147583
+ if (hex.length === 1) str += "0";
147584
+ str += hex;
147585
+ }
147586
+ return str.toUpperCase();
147957
147587
  };
147958
147588
 
147959
147589
  /**
147960
- * Converts a Latin-1 string to an ArrayBuffer.
147590
+ * Converts a Latin-1 string to an Uint8Array.
147961
147591
  * @param {string} str Latin-1 string.
147962
- * @returns {ArrayBuffer} ArrayBuffer.
147963
- */
147964
- const latin1ToBuf = str => {
147965
- const buf = new ArrayBuffer(str.length);
147966
- const arr = new Uint8Array(buf);
147967
- for (let i = 0; i < str.length; i++) {
147968
- arr[i] = str.charCodeAt(i) & 0xff;
147969
- }
147970
- return buf;
147592
+ * @returns {Uint8Array} Uint8Array.
147593
+ */ const latin1Decode = (str)=>{
147594
+ const buf = new ArrayBuffer(str.length);
147595
+ const arr = new Uint8Array(buf);
147596
+ for(let i = 0; i < str.length; i++){
147597
+ arr[i] = str.charCodeAt(i) & 0xff;
147598
+ }
147599
+ return arr;
147971
147600
  };
147972
-
147973
147601
  /**
147974
- * Converts an ArrayBuffer to a Latin-1 string.
147975
- * @param {ArrayBuffer} buf ArrayBuffer.
147602
+ * Converts an Uint8Array to a Latin-1 string.
147603
+ * @param {Uint8Array} arr Uint8Array.
147976
147604
  * @returns {string} Latin-1 string.
147977
- */
147978
- const latin1FromBuf = buf => {
147979
- const arr = new Uint8Array(buf);
147980
- let str = "";
147981
- for (let i = 0; i < arr.length; i++) {
147982
- str += String.fromCharCode(arr[i]);
147983
- }
147984
- return str;
147605
+ */ const latin1Encode = (arr)=>{
147606
+ let str = "";
147607
+ for(let i = 0; i < arr.length; i++){
147608
+ str += String.fromCharCode(arr[i]);
147609
+ }
147610
+ return str;
147985
147611
  };
147986
147612
 
147987
147613
  /**
147988
147614
  * TextEncoder instance.
147989
147615
  * @type {TextEncoder|null}
147990
- */
147991
- const ENCODER = globalScope.TextEncoder ? new globalScope.TextEncoder("utf-8") : null;
147992
-
147616
+ */ const ENCODER = globalScope.TextEncoder ? new globalScope.TextEncoder() : null;
147993
147617
  /**
147994
147618
  * TextDecoder instance.
147995
147619
  * @type {TextDecoder|null}
147996
- */
147997
- const DECODER = globalScope.TextDecoder ? new globalScope.TextDecoder("utf-8") : null;
147998
-
147620
+ */ const DECODER = globalScope.TextDecoder ? new globalScope.TextDecoder() : null;
147999
147621
  /**
148000
- * Converts an UTF-8 string to an ArrayBuffer.
147622
+ * Converts an UTF-8 string to an Uint8Array.
148001
147623
  * @param {string} str String.
148002
- * @returns {ArrayBuffer} ArrayBuffer.
148003
- */
148004
- const utf8ToBuf = str => {
148005
- if (!ENCODER) {
148006
- throw new Error("Encoding API not available");
148007
- }
148008
- return ENCODER.encode(str).buffer;
147624
+ * @returns {Uint8Array} Uint8Array.
147625
+ */ const utf8Decode = (str)=>{
147626
+ if (!ENCODER) {
147627
+ throw new Error("Encoding API not available");
147628
+ }
147629
+ return ENCODER.encode(str);
148009
147630
  };
148010
-
148011
147631
  /**
148012
- * Converts an ArrayBuffer to an UTF-8 string.
148013
- * @param {ArrayBuffer} buf ArrayBuffer.
147632
+ * Converts an Uint8Array to an UTF-8 string.
147633
+ * @param {Uint8Array} arr Uint8Array.
148014
147634
  * @returns {string} String.
148015
- */
148016
- const utf8FromBuf = buf => {
148017
- if (!DECODER) {
148018
- throw new Error("Encoding API not available");
148019
- }
148020
- return DECODER.decode(buf);
147635
+ */ const utf8Encode = (arr)=>{
147636
+ if (!DECODER) {
147637
+ throw new Error("Encoding API not available");
147638
+ }
147639
+ return DECODER.decode(arr);
148021
147640
  };
148022
147641
 
148023
147642
  /**
148024
147643
  * Returns random bytes.
148025
147644
  * @param {number} size Size.
148026
- * @returns {ArrayBuffer} Random bytes.
148027
- */
148028
- const randomBytes = size => {
148029
- {
148030
- if (!globalScope.crypto?.getRandomValues) {
148031
- throw new Error("Cryptography API not available");
147645
+ * @returns {Uint8Array} Random bytes.
147646
+ */ const randomBytes = (size)=>{
147647
+ {
147648
+ if (!globalScope.crypto?.getRandomValues) {
147649
+ throw new Error("Cryptography API not available");
147650
+ }
147651
+ return globalScope.crypto.getRandomValues(new Uint8Array(size));
148032
147652
  }
148033
- return globalScope.crypto.getRandomValues(new Uint8Array(size)).buffer;
148034
- }
148035
147653
  };
148036
147654
 
148037
147655
  /**
148038
147656
  * OTP secret key.
148039
- */
148040
- class Secret {
148041
- /**
148042
- * Creates a secret key object.
148043
- * @param {Object} [config] Configuration options.
148044
- * @param {ArrayBuffer} [config.buffer=randomBytes] Secret key.
148045
- * @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
148046
- */
148047
- constructor({
148048
- buffer,
148049
- size = 20
148050
- } = {}) {
147657
+ */ class Secret {
148051
147658
  /**
148052
- * Secret key.
148053
- * @type {ArrayBuffer}
148054
- */
148055
- this.buffer = typeof buffer === "undefined" ? randomBytes(size) : buffer;
148056
- }
148057
-
148058
- /**
148059
147659
  * Converts a Latin-1 string to a Secret object.
148060
147660
  * @param {string} str Latin-1 string.
148061
147661
  * @returns {Secret} Secret object.
148062
- */
148063
- static fromLatin1(str) {
148064
- return new Secret({
148065
- buffer: latin1ToBuf(str)
148066
- });
148067
- }
148068
-
148069
- /**
147662
+ */ static fromLatin1(str) {
147663
+ return new Secret({
147664
+ buffer: latin1Decode(str).buffer
147665
+ });
147666
+ }
147667
+ /**
148070
147668
  * Converts an UTF-8 string to a Secret object.
148071
147669
  * @param {string} str UTF-8 string.
148072
147670
  * @returns {Secret} Secret object.
148073
- */
148074
- static fromUTF8(str) {
148075
- return new Secret({
148076
- buffer: utf8ToBuf(str)
148077
- });
148078
- }
148079
-
148080
- /**
147671
+ */ static fromUTF8(str) {
147672
+ return new Secret({
147673
+ buffer: utf8Decode(str).buffer
147674
+ });
147675
+ }
147676
+ /**
148081
147677
  * Converts a base32 string to a Secret object.
148082
147678
  * @param {string} str Base32 string.
148083
147679
  * @returns {Secret} Secret object.
148084
- */
148085
- static fromBase32(str) {
148086
- return new Secret({
148087
- buffer: base32ToBuf(str)
148088
- });
148089
- }
148090
-
148091
- /**
147680
+ */ static fromBase32(str) {
147681
+ return new Secret({
147682
+ buffer: base32Decode(str).buffer
147683
+ });
147684
+ }
147685
+ /**
148092
147686
  * Converts a hexadecimal string to a Secret object.
148093
147687
  * @param {string} str Hexadecimal string.
148094
147688
  * @returns {Secret} Secret object.
148095
- */
148096
- static fromHex(str) {
148097
- return new Secret({
148098
- buffer: hexToBuf(str)
148099
- });
148100
- }
148101
-
148102
- /**
147689
+ */ static fromHex(str) {
147690
+ return new Secret({
147691
+ buffer: hexDecode(str).buffer
147692
+ });
147693
+ }
147694
+ /**
147695
+ * Secret key buffer.
147696
+ * @deprecated For backward compatibility, the "bytes" property should be used instead.
147697
+ * @type {ArrayBufferLike}
147698
+ */ get buffer() {
147699
+ return this.bytes.buffer;
147700
+ }
147701
+ /**
148103
147702
  * Latin-1 string representation of secret key.
148104
147703
  * @type {string}
148105
- */
148106
- get latin1() {
148107
- Object.defineProperty(this, "latin1", {
148108
- enumerable: true,
148109
- value: latin1FromBuf(this.buffer)
148110
- });
148111
- return this.latin1;
148112
- }
148113
-
148114
- /**
147704
+ */ get latin1() {
147705
+ Object.defineProperty(this, "latin1", {
147706
+ enumerable: true,
147707
+ writable: false,
147708
+ configurable: false,
147709
+ value: latin1Encode(this.bytes)
147710
+ });
147711
+ return this.latin1;
147712
+ }
147713
+ /**
148115
147714
  * UTF-8 string representation of secret key.
148116
147715
  * @type {string}
148117
- */
148118
- get utf8() {
148119
- Object.defineProperty(this, "utf8", {
148120
- enumerable: true,
148121
- value: utf8FromBuf(this.buffer)
148122
- });
148123
- return this.utf8;
148124
- }
148125
-
148126
- /**
147716
+ */ get utf8() {
147717
+ Object.defineProperty(this, "utf8", {
147718
+ enumerable: true,
147719
+ writable: false,
147720
+ configurable: false,
147721
+ value: utf8Encode(this.bytes)
147722
+ });
147723
+ return this.utf8;
147724
+ }
147725
+ /**
148127
147726
  * Base32 string representation of secret key.
148128
147727
  * @type {string}
148129
- */
148130
- get base32() {
148131
- Object.defineProperty(this, "base32", {
148132
- enumerable: true,
148133
- value: base32FromBuf(this.buffer)
148134
- });
148135
- return this.base32;
148136
- }
148137
-
148138
- /**
147728
+ */ get base32() {
147729
+ Object.defineProperty(this, "base32", {
147730
+ enumerable: true,
147731
+ writable: false,
147732
+ configurable: false,
147733
+ value: base32Encode(this.bytes)
147734
+ });
147735
+ return this.base32;
147736
+ }
147737
+ /**
148139
147738
  * Hexadecimal string representation of secret key.
148140
147739
  * @type {string}
148141
- */
148142
- get hex() {
148143
- Object.defineProperty(this, "hex", {
148144
- enumerable: true,
148145
- value: hexFromBuf(this.buffer)
148146
- });
148147
- return this.hex;
148148
- }
147740
+ */ get hex() {
147741
+ Object.defineProperty(this, "hex", {
147742
+ enumerable: true,
147743
+ writable: false,
147744
+ configurable: false,
147745
+ value: hexEncode(this.bytes)
147746
+ });
147747
+ return this.hex;
147748
+ }
147749
+ /**
147750
+ * Creates a secret key object.
147751
+ * @param {Object} [config] Configuration options.
147752
+ * @param {ArrayBufferLike} [config.buffer] Secret key buffer.
147753
+ * @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
147754
+ */ constructor({ buffer, size = 20 } = {}){
147755
+ /**
147756
+ * Secret key.
147757
+ * @type {Uint8Array}
147758
+ * @readonly
147759
+ */ this.bytes = typeof buffer === "undefined" ? randomBytes(size) : new Uint8Array(buffer);
147760
+ // Prevent the "bytes" property from being modified.
147761
+ Object.defineProperty(this, "bytes", {
147762
+ enumerable: true,
147763
+ writable: false,
147764
+ configurable: false,
147765
+ value: this.bytes
147766
+ });
147767
+ }
148149
147768
  }
148150
147769
 
148151
147770
  /**
@@ -148153,27 +147772,25 @@ class Secret {
148153
147772
  * @param {string} a String a.
148154
147773
  * @param {string} b String b.
148155
147774
  * @returns {boolean} Equality result.
148156
- */
148157
- const timingSafeEqual = (a, b) => {
148158
- {
148159
- if (a.length !== b.length) {
148160
- throw new TypeError("Input strings must have the same length");
148161
- }
148162
- let i = -1;
148163
- let out = 0;
148164
- while (++i < a.length) {
148165
- out |= a.charCodeAt(i) ^ b.charCodeAt(i);
147775
+ */ const timingSafeEqual = (a, b)=>{
147776
+ {
147777
+ if (a.length !== b.length) {
147778
+ throw new TypeError("Input strings must have the same length");
147779
+ }
147780
+ let i = -1;
147781
+ let out = 0;
147782
+ while(++i < a.length){
147783
+ out |= a.charCodeAt(i) ^ b.charCodeAt(i);
147784
+ }
147785
+ return out === 0;
148166
147786
  }
148167
- return out === 0;
148168
- }
148169
147787
  };
148170
147788
 
148171
147789
  /**
148172
147790
  * HOTP: An HMAC-based One-time Password Algorithm.
148173
147791
  * @see [RFC 4226](https://tools.ietf.org/html/rfc4226)
148174
- */
148175
- class HOTP {
148176
- /**
147792
+ */ class HOTP {
147793
+ /**
148177
147794
  * Default configuration.
148178
147795
  * @type {{
148179
147796
  * issuer: string,
@@ -148184,77 +147801,18 @@ class HOTP {
148184
147801
  * counter: number
148185
147802
  * window: number
148186
147803
  * }}
148187
- */
148188
- static get defaults() {
148189
- return {
148190
- issuer: "",
148191
- label: "OTPAuth",
148192
- issuerInLabel: true,
148193
- algorithm: "SHA1",
148194
- digits: 6,
148195
- counter: 0,
148196
- window: 1
148197
- };
148198
- }
148199
-
148200
- /**
148201
- * Creates an HOTP object.
148202
- * @param {Object} [config] Configuration options.
148203
- * @param {string} [config.issuer=''] Account provider.
148204
- * @param {string} [config.label='OTPAuth'] Account label.
148205
- * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
148206
- * @param {Secret|string} [config.secret=Secret] Secret key.
148207
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
148208
- * @param {number} [config.digits=6] Token length.
148209
- * @param {number} [config.counter=0] Initial counter value.
148210
- */
148211
- constructor({
148212
- issuer = HOTP.defaults.issuer,
148213
- label = HOTP.defaults.label,
148214
- issuerInLabel = HOTP.defaults.issuerInLabel,
148215
- secret = new Secret(),
148216
- algorithm = HOTP.defaults.algorithm,
148217
- digits = HOTP.defaults.digits,
148218
- counter = HOTP.defaults.counter
148219
- } = {}) {
148220
- /**
148221
- * Account provider.
148222
- * @type {string}
148223
- */
148224
- this.issuer = issuer;
148225
- /**
148226
- * Account label.
148227
- * @type {string}
148228
- */
148229
- this.label = label;
148230
- /**
148231
- * Include issuer prefix in label.
148232
- * @type {boolean}
148233
- */
148234
- this.issuerInLabel = issuerInLabel;
148235
- /**
148236
- * Secret key.
148237
- * @type {Secret}
148238
- */
148239
- this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
148240
- /**
148241
- * HMAC hashing algorithm.
148242
- * @type {string}
148243
- */
148244
- this.algorithm = algorithm.toUpperCase();
148245
- /**
148246
- * Token length.
148247
- * @type {number}
148248
- */
148249
- this.digits = digits;
147804
+ */ static get defaults() {
147805
+ return {
147806
+ issuer: "",
147807
+ label: "OTPAuth",
147808
+ issuerInLabel: true,
147809
+ algorithm: "SHA1",
147810
+ digits: 6,
147811
+ counter: 0,
147812
+ window: 1
147813
+ };
147814
+ }
148250
147815
  /**
148251
- * Initial counter value.
148252
- * @type {number}
148253
- */
148254
- this.counter = counter;
148255
- }
148256
-
148257
- /**
148258
147816
  * Generates an HOTP token.
148259
147817
  * @param {Object} config Configuration options.
148260
147818
  * @param {Secret} config.secret Secret key.
@@ -148262,37 +147820,26 @@ class HOTP {
148262
147820
  * @param {number} [config.digits=6] Token length.
148263
147821
  * @param {number} [config.counter=0] Counter value.
148264
147822
  * @returns {string} Token.
148265
- */
148266
- static generate({
148267
- secret,
148268
- algorithm = HOTP.defaults.algorithm,
148269
- digits = HOTP.defaults.digits,
148270
- counter = HOTP.defaults.counter
148271
- }) {
148272
- const digest = new Uint8Array(hmacDigest(algorithm, secret.buffer, uintToBuf(counter)));
148273
- const offset = digest[digest.byteLength - 1] & 15;
148274
- const otp = ((digest[offset] & 127) << 24 | (digest[offset + 1] & 255) << 16 | (digest[offset + 2] & 255) << 8 | digest[offset + 3] & 255) % 10 ** digits;
148275
- return otp.toString().padStart(digits, "0");
148276
- }
148277
-
148278
- /**
147823
+ */ static generate({ secret, algorithm = HOTP.defaults.algorithm, digits = HOTP.defaults.digits, counter = HOTP.defaults.counter }) {
147824
+ const digest = hmacDigest(algorithm, secret.bytes, uintDecode(counter));
147825
+ const offset = digest[digest.byteLength - 1] & 15;
147826
+ const otp = ((digest[offset] & 127) << 24 | (digest[offset + 1] & 255) << 16 | (digest[offset + 2] & 255) << 8 | digest[offset + 3] & 255) % 10 ** digits;
147827
+ return otp.toString().padStart(digits, "0");
147828
+ }
147829
+ /**
148279
147830
  * Generates an HOTP token.
148280
147831
  * @param {Object} [config] Configuration options.
148281
147832
  * @param {number} [config.counter=this.counter++] Counter value.
148282
147833
  * @returns {string} Token.
148283
- */
148284
- generate({
148285
- counter = this.counter++
148286
- } = {}) {
148287
- return HOTP.generate({
148288
- secret: this.secret,
148289
- algorithm: this.algorithm,
148290
- digits: this.digits,
148291
- counter
148292
- });
148293
- }
148294
-
148295
- /**
147834
+ */ generate({ counter = this.counter++ } = {}) {
147835
+ return HOTP.generate({
147836
+ secret: this.secret,
147837
+ algorithm: this.algorithm,
147838
+ digits: this.digits,
147839
+ counter
147840
+ });
147841
+ }
147842
+ /**
148296
147843
  * Validates an HOTP token.
148297
147844
  * @param {Object} config Configuration options.
148298
147845
  * @param {string} config.token Token value.
@@ -148302,103 +147849,56 @@ class HOTP {
148302
147849
  * @param {number} [config.counter=0] Counter value.
148303
147850
  * @param {number} [config.window=1] Window of counter values to test.
148304
147851
  * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
148305
- */
148306
- static validate({
148307
- token,
148308
- secret,
148309
- algorithm,
148310
- digits,
148311
- counter = HOTP.defaults.counter,
148312
- window = HOTP.defaults.window
148313
- }) {
148314
- // Return early if the token length does not match the digit number.
148315
- if (token.length !== digits) return null;
148316
- let delta = null;
148317
- const check = ( /** @type {number} */i) => {
148318
- const generatedToken = HOTP.generate({
148319
- secret,
148320
- algorithm,
148321
- digits,
148322
- counter: i
148323
- });
148324
- if (timingSafeEqual(token, generatedToken)) {
148325
- delta = i - counter;
148326
- }
148327
- };
148328
- check(counter);
148329
- for (let i = 1; i <= window && delta === null; ++i) {
148330
- check(counter - i);
148331
- if (delta !== null) break;
148332
- check(counter + i);
148333
- if (delta !== null) break;
147852
+ */ static validate({ token, secret, algorithm, digits, counter = HOTP.defaults.counter, window = HOTP.defaults.window }) {
147853
+ // Return early if the token length does not match the digit number.
147854
+ if (token.length !== digits) return null;
147855
+ let delta = null;
147856
+ const check = (/** @type {number} */ i)=>{
147857
+ const generatedToken = HOTP.generate({
147858
+ secret,
147859
+ algorithm,
147860
+ digits,
147861
+ counter: i
147862
+ });
147863
+ if (timingSafeEqual(token, generatedToken)) {
147864
+ delta = i - counter;
147865
+ }
147866
+ };
147867
+ check(counter);
147868
+ for(let i = 1; i <= window && delta === null; ++i){
147869
+ check(counter - i);
147870
+ if (delta !== null) break;
147871
+ check(counter + i);
147872
+ if (delta !== null) break;
147873
+ }
147874
+ return delta;
148334
147875
  }
148335
- return delta;
148336
- }
148337
-
148338
- /**
147876
+ /**
148339
147877
  * Validates an HOTP token.
148340
147878
  * @param {Object} config Configuration options.
148341
147879
  * @param {string} config.token Token value.
148342
147880
  * @param {number} [config.counter=this.counter] Counter value.
148343
147881
  * @param {number} [config.window=1] Window of counter values to test.
148344
147882
  * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
148345
- */
148346
- validate({
148347
- token,
148348
- counter = this.counter,
148349
- window
148350
- }) {
148351
- return HOTP.validate({
148352
- token,
148353
- secret: this.secret,
148354
- algorithm: this.algorithm,
148355
- digits: this.digits,
148356
- counter,
148357
- window
148358
- });
148359
- }
148360
-
148361
- /**
147883
+ */ validate({ token, counter = this.counter, window }) {
147884
+ return HOTP.validate({
147885
+ token,
147886
+ secret: this.secret,
147887
+ algorithm: this.algorithm,
147888
+ digits: this.digits,
147889
+ counter,
147890
+ window
147891
+ });
147892
+ }
147893
+ /**
148362
147894
  * Returns a Google Authenticator key URI.
148363
147895
  * @returns {string} URI.
148364
- */
148365
- toString() {
148366
- const e = encodeURIComponent;
148367
- return "otpauth://hotp/" + `${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}` + `secret=${e(this.secret.base32)}&` + `algorithm=${e(this.algorithm)}&` + `digits=${e(this.digits)}&` + `counter=${e(this.counter)}`;
148368
- }
148369
- }
148370
-
148371
- /**
148372
- * TOTP: Time-Based One-Time Password Algorithm.
148373
- * @see [RFC 6238](https://tools.ietf.org/html/rfc6238)
148374
- */
148375
- class TOTP {
148376
- /**
148377
- * Default configuration.
148378
- * @type {{
148379
- * issuer: string,
148380
- * label: string,
148381
- * issuerInLabel: boolean,
148382
- * algorithm: string,
148383
- * digits: number,
148384
- * period: number
148385
- * window: number
148386
- * }}
148387
- */
148388
- static get defaults() {
148389
- return {
148390
- issuer: "",
148391
- label: "OTPAuth",
148392
- issuerInLabel: true,
148393
- algorithm: "SHA1",
148394
- digits: 6,
148395
- period: 30,
148396
- window: 1
148397
- };
148398
- }
148399
-
148400
- /**
148401
- * Creates a TOTP object.
147896
+ */ toString() {
147897
+ const e = encodeURIComponent;
147898
+ return "otpauth://hotp/" + `${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}` + `secret=${e(this.secret.base32)}&` + `algorithm=${e(this.algorithm)}&` + `digits=${e(this.digits)}&` + `counter=${e(this.counter)}`;
147899
+ }
147900
+ /**
147901
+ * Creates an HOTP object.
148402
147902
  * @param {Object} [config] Configuration options.
148403
147903
  * @param {string} [config.issuer=''] Account provider.
148404
147904
  * @param {string} [config.label='OTPAuth'] Account label.
@@ -148406,55 +147906,66 @@ class TOTP {
148406
147906
  * @param {Secret|string} [config.secret=Secret] Secret key.
148407
147907
  * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
148408
147908
  * @param {number} [config.digits=6] Token length.
148409
- * @param {number} [config.period=30] Token time-step duration.
148410
- */
148411
- constructor({
148412
- issuer = TOTP.defaults.issuer,
148413
- label = TOTP.defaults.label,
148414
- issuerInLabel = TOTP.defaults.issuerInLabel,
148415
- secret = new Secret(),
148416
- algorithm = TOTP.defaults.algorithm,
148417
- digits = TOTP.defaults.digits,
148418
- period = TOTP.defaults.period
148419
- } = {}) {
148420
- /**
147909
+ * @param {number} [config.counter=0] Initial counter value.
147910
+ */ constructor({ issuer = HOTP.defaults.issuer, label = HOTP.defaults.label, issuerInLabel = HOTP.defaults.issuerInLabel, secret = new Secret(), algorithm = HOTP.defaults.algorithm, digits = HOTP.defaults.digits, counter = HOTP.defaults.counter } = {}){
147911
+ /**
148421
147912
  * Account provider.
148422
147913
  * @type {string}
148423
- */
148424
- this.issuer = issuer;
148425
- /**
147914
+ */ this.issuer = issuer;
147915
+ /**
148426
147916
  * Account label.
148427
147917
  * @type {string}
148428
- */
148429
- this.label = label;
148430
- /**
147918
+ */ this.label = label;
147919
+ /**
148431
147920
  * Include issuer prefix in label.
148432
147921
  * @type {boolean}
148433
- */
148434
- this.issuerInLabel = issuerInLabel;
148435
- /**
147922
+ */ this.issuerInLabel = issuerInLabel;
147923
+ /**
148436
147924
  * Secret key.
148437
147925
  * @type {Secret}
148438
- */
148439
- this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
148440
- /**
147926
+ */ this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
147927
+ /**
148441
147928
  * HMAC hashing algorithm.
148442
147929
  * @type {string}
148443
- */
148444
- this.algorithm = algorithm.toUpperCase();
148445
- /**
147930
+ */ this.algorithm = algorithm.toUpperCase();
147931
+ /**
148446
147932
  * Token length.
148447
147933
  * @type {number}
148448
- */
148449
- this.digits = digits;
148450
- /**
148451
- * Token time-step duration.
147934
+ */ this.digits = digits;
147935
+ /**
147936
+ * Initial counter value.
148452
147937
  * @type {number}
148453
- */
148454
- this.period = period;
148455
- }
147938
+ */ this.counter = counter;
147939
+ }
147940
+ }
148456
147941
 
148457
- /**
147942
+ /**
147943
+ * TOTP: Time-Based One-Time Password Algorithm.
147944
+ * @see [RFC 6238](https://tools.ietf.org/html/rfc6238)
147945
+ */ class TOTP {
147946
+ /**
147947
+ * Default configuration.
147948
+ * @type {{
147949
+ * issuer: string,
147950
+ * label: string,
147951
+ * issuerInLabel: boolean,
147952
+ * algorithm: string,
147953
+ * digits: number,
147954
+ * period: number
147955
+ * window: number
147956
+ * }}
147957
+ */ static get defaults() {
147958
+ return {
147959
+ issuer: "",
147960
+ label: "OTPAuth",
147961
+ issuerInLabel: true,
147962
+ algorithm: "SHA1",
147963
+ digits: 6,
147964
+ period: 30,
147965
+ window: 1
147966
+ };
147967
+ }
147968
+ /**
148458
147969
  * Generates a TOTP token.
148459
147970
  * @param {Object} config Configuration options.
148460
147971
  * @param {Secret} config.secret Secret key.
@@ -148463,41 +147974,29 @@ class TOTP {
148463
147974
  * @param {number} [config.period=30] Token time-step duration.
148464
147975
  * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
148465
147976
  * @returns {string} Token.
148466
- */
148467
- static generate({
148468
- secret,
148469
- algorithm,
148470
- digits,
148471
- period = TOTP.defaults.period,
148472
- timestamp = Date.now()
148473
- }) {
148474
- return HOTP.generate({
148475
- secret,
148476
- algorithm,
148477
- digits,
148478
- counter: Math.floor(timestamp / 1000 / period)
148479
- });
148480
- }
148481
-
148482
- /**
147977
+ */ static generate({ secret, algorithm, digits, period = TOTP.defaults.period, timestamp = Date.now() }) {
147978
+ return HOTP.generate({
147979
+ secret,
147980
+ algorithm,
147981
+ digits,
147982
+ counter: Math.floor(timestamp / 1000 / period)
147983
+ });
147984
+ }
147985
+ /**
148483
147986
  * Generates a TOTP token.
148484
147987
  * @param {Object} [config] Configuration options.
148485
147988
  * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
148486
147989
  * @returns {string} Token.
148487
- */
148488
- generate({
148489
- timestamp = Date.now()
148490
- } = {}) {
148491
- return TOTP.generate({
148492
- secret: this.secret,
148493
- algorithm: this.algorithm,
148494
- digits: this.digits,
148495
- period: this.period,
148496
- timestamp
148497
- });
148498
- }
148499
-
148500
- /**
147990
+ */ generate({ timestamp = Date.now() } = {}) {
147991
+ return TOTP.generate({
147992
+ secret: this.secret,
147993
+ algorithm: this.algorithm,
147994
+ digits: this.digits,
147995
+ period: this.period,
147996
+ timestamp
147997
+ });
147998
+ }
147999
+ /**
148501
148000
  * Validates a TOTP token.
148502
148001
  * @param {Object} config Configuration options.
148503
148002
  * @param {string} config.token Token value.
@@ -148508,58 +148007,81 @@ class TOTP {
148508
148007
  * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
148509
148008
  * @param {number} [config.window=1] Window of counter values to test.
148510
148009
  * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
148511
- */
148512
- static validate({
148513
- token,
148514
- secret,
148515
- algorithm,
148516
- digits,
148517
- period = TOTP.defaults.period,
148518
- timestamp = Date.now(),
148519
- window
148520
- }) {
148521
- return HOTP.validate({
148522
- token,
148523
- secret,
148524
- algorithm,
148525
- digits,
148526
- counter: Math.floor(timestamp / 1000 / period),
148527
- window
148528
- });
148529
- }
148530
-
148531
- /**
148010
+ */ static validate({ token, secret, algorithm, digits, period = TOTP.defaults.period, timestamp = Date.now(), window }) {
148011
+ return HOTP.validate({
148012
+ token,
148013
+ secret,
148014
+ algorithm,
148015
+ digits,
148016
+ counter: Math.floor(timestamp / 1000 / period),
148017
+ window
148018
+ });
148019
+ }
148020
+ /**
148532
148021
  * Validates a TOTP token.
148533
148022
  * @param {Object} config Configuration options.
148534
148023
  * @param {string} config.token Token value.
148535
148024
  * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
148536
148025
  * @param {number} [config.window=1] Window of counter values to test.
148537
148026
  * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
148538
- */
148539
- validate({
148540
- token,
148541
- timestamp,
148542
- window
148543
- }) {
148544
- return TOTP.validate({
148545
- token,
148546
- secret: this.secret,
148547
- algorithm: this.algorithm,
148548
- digits: this.digits,
148549
- period: this.period,
148550
- timestamp,
148551
- window
148552
- });
148553
- }
148554
-
148555
- /**
148027
+ */ validate({ token, timestamp, window }) {
148028
+ return TOTP.validate({
148029
+ token,
148030
+ secret: this.secret,
148031
+ algorithm: this.algorithm,
148032
+ digits: this.digits,
148033
+ period: this.period,
148034
+ timestamp,
148035
+ window
148036
+ });
148037
+ }
148038
+ /**
148556
148039
  * Returns a Google Authenticator key URI.
148557
148040
  * @returns {string} URI.
148558
- */
148559
- toString() {
148560
- const e = encodeURIComponent;
148561
- return "otpauth://totp/" + `${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}` + `secret=${e(this.secret.base32)}&` + `algorithm=${e(this.algorithm)}&` + `digits=${e(this.digits)}&` + `period=${e(this.period)}`;
148562
- }
148041
+ */ toString() {
148042
+ const e = encodeURIComponent;
148043
+ return "otpauth://totp/" + `${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}` + `secret=${e(this.secret.base32)}&` + `algorithm=${e(this.algorithm)}&` + `digits=${e(this.digits)}&` + `period=${e(this.period)}`;
148044
+ }
148045
+ /**
148046
+ * Creates a TOTP object.
148047
+ * @param {Object} [config] Configuration options.
148048
+ * @param {string} [config.issuer=''] Account provider.
148049
+ * @param {string} [config.label='OTPAuth'] Account label.
148050
+ * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
148051
+ * @param {Secret|string} [config.secret=Secret] Secret key.
148052
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
148053
+ * @param {number} [config.digits=6] Token length.
148054
+ * @param {number} [config.period=30] Token time-step duration.
148055
+ */ constructor({ issuer = TOTP.defaults.issuer, label = TOTP.defaults.label, issuerInLabel = TOTP.defaults.issuerInLabel, secret = new Secret(), algorithm = TOTP.defaults.algorithm, digits = TOTP.defaults.digits, period = TOTP.defaults.period } = {}){
148056
+ /**
148057
+ * Account provider.
148058
+ * @type {string}
148059
+ */ this.issuer = issuer;
148060
+ /**
148061
+ * Account label.
148062
+ * @type {string}
148063
+ */ this.label = label;
148064
+ /**
148065
+ * Include issuer prefix in label.
148066
+ * @type {boolean}
148067
+ */ this.issuerInLabel = issuerInLabel;
148068
+ /**
148069
+ * Secret key.
148070
+ * @type {Secret}
148071
+ */ this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
148072
+ /**
148073
+ * HMAC hashing algorithm.
148074
+ * @type {string}
148075
+ */ this.algorithm = algorithm.toUpperCase();
148076
+ /**
148077
+ * Token length.
148078
+ * @type {number}
148079
+ */ this.digits = digits;
148080
+ /**
148081
+ * Token time-step duration.
148082
+ * @type {number}
148083
+ */ this.period = period;
148084
+ }
148563
148085
  }
148564
148086
 
148565
148087
  const initializeTotp = ({ issuer, secret, }) => {
@@ -148732,7 +148254,7 @@ var require$$4 = {
148732
148254
 
148733
148255
  const fs = fs__default;
148734
148256
  const path = Path__default;
148735
- const os = require$$0$3;
148257
+ const os = require$$0$2;
148736
148258
  const crypto = require$$3$2;
148737
148259
  const packageJson = require$$4;
148738
148260