@bigbinary/neeto-playwright-commons 1.9.32 → 1.9.34
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.cjs.js +1628 -2072
- package/index.cjs.js.map +1 -1
- package/index.d.ts +28 -9
- package/index.js +1644 -2089
- package/index.js.map +1 -1
- package/package.json +25 -26
package/index.cjs.js
CHANGED
|
@@ -6,23 +6,24 @@ var child_process = require('child_process');
|
|
|
6
6
|
var fs$d = require('fs');
|
|
7
7
|
var test$1 = require('@playwright/test');
|
|
8
8
|
var ramda = require('ramda');
|
|
9
|
-
var require$$0$
|
|
9
|
+
var require$$0$1 = require('util');
|
|
10
10
|
var Path = require('path');
|
|
11
11
|
var faker = require('@faker-js/faker');
|
|
12
12
|
var MailosaurClient = require('mailosaur');
|
|
13
13
|
var dayjs = require('dayjs');
|
|
14
|
-
var require$$0$
|
|
15
|
-
var require$$0$
|
|
14
|
+
var require$$0$3 = require('tty');
|
|
15
|
+
var require$$0$2 = require('os');
|
|
16
|
+
var stealth$1 = require('puppeteer-extra-plugin-stealth');
|
|
16
17
|
var Stream$4 = require('stream');
|
|
17
|
-
var require$$0$
|
|
18
|
+
var require$$0$4 = require('events');
|
|
18
19
|
var playwrightI18nextFixture = require('playwright-i18next-fixture');
|
|
19
20
|
var neetoCist = require('@bigbinary/neeto-cist');
|
|
20
21
|
var http$1 = require('http');
|
|
21
22
|
var Url = require('url');
|
|
22
|
-
var require$$0$
|
|
23
|
+
var require$$0$5 = require('punycode');
|
|
23
24
|
var https$1 = require('https');
|
|
24
25
|
var zlib$5 = require('zlib');
|
|
25
|
-
var require$$0$
|
|
26
|
+
var require$$0$6 = require('assert');
|
|
26
27
|
var require$$3 = require('buffer');
|
|
27
28
|
var require$$3$1 = require('querystring');
|
|
28
29
|
var require$$1$1 = require('string_decoder');
|
|
@@ -52,21 +53,22 @@ function _interopNamespace(e) {
|
|
|
52
53
|
var fs__namespace = /*#__PURE__*/_interopNamespace(fs$d);
|
|
53
54
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$d);
|
|
54
55
|
var test__default = /*#__PURE__*/_interopDefaultLegacy(test$1);
|
|
55
|
-
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$
|
|
56
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
56
57
|
var Path__default = /*#__PURE__*/_interopDefaultLegacy(Path);
|
|
57
58
|
var Path__namespace = /*#__PURE__*/_interopNamespace(Path);
|
|
58
59
|
var MailosaurClient__default = /*#__PURE__*/_interopDefaultLegacy(MailosaurClient);
|
|
59
60
|
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
60
|
-
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$
|
|
61
|
-
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$
|
|
61
|
+
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
62
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
63
|
+
var stealth__default = /*#__PURE__*/_interopDefaultLegacy(stealth$1);
|
|
62
64
|
var Stream__default = /*#__PURE__*/_interopDefaultLegacy(Stream$4);
|
|
63
|
-
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$
|
|
65
|
+
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
64
66
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http$1);
|
|
65
67
|
var Url__default = /*#__PURE__*/_interopDefaultLegacy(Url);
|
|
66
|
-
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$
|
|
68
|
+
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
67
69
|
var https__default = /*#__PURE__*/_interopDefaultLegacy(https$1);
|
|
68
70
|
var zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib$5);
|
|
69
|
-
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$
|
|
71
|
+
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
70
72
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
71
73
|
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
72
74
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
@@ -2595,7 +2597,7 @@ var arrayToObject = function arrayToObject(source, options) {
|
|
|
2595
2597
|
return obj;
|
|
2596
2598
|
};
|
|
2597
2599
|
|
|
2598
|
-
var merge$
|
|
2600
|
+
var merge$2 = function merge(target, source, options) {
|
|
2599
2601
|
/* eslint no-param-reassign: 0 */
|
|
2600
2602
|
if (!source) {
|
|
2601
2603
|
return target;
|
|
@@ -2812,7 +2814,7 @@ var utils$o = {
|
|
|
2812
2814
|
isBuffer: isBuffer,
|
|
2813
2815
|
isRegExp: isRegExp,
|
|
2814
2816
|
maybeMap: maybeMap,
|
|
2815
|
-
merge: merge$
|
|
2817
|
+
merge: merge$2
|
|
2816
2818
|
};
|
|
2817
2819
|
|
|
2818
2820
|
var getSideChannel = sideChannel;
|
|
@@ -3220,6 +3222,7 @@ var parseValues = function parseQueryStringValues(str, options) {
|
|
|
3220
3222
|
var obj = { __proto__: null };
|
|
3221
3223
|
|
|
3222
3224
|
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
|
3225
|
+
cleanStr = cleanStr.replace(/%5B/gi, '[').replace(/%5D/gi, ']');
|
|
3223
3226
|
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
|
3224
3227
|
var parts = cleanStr.split(options.delimiter, limit);
|
|
3225
3228
|
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
|
@@ -4889,7 +4892,7 @@ if (typeof process === 'undefined' || process.type === 'renderer' || process.bro
|
|
|
4889
4892
|
}
|
|
4890
4893
|
|
|
4891
4894
|
var srcExports = src$1.exports;
|
|
4892
|
-
var
|
|
4895
|
+
var Debug = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
|
|
4893
4896
|
|
|
4894
4897
|
/*!
|
|
4895
4898
|
* playwright-extra v4.3.5 by berstend
|
|
@@ -4972,7 +4975,7 @@ const playwrightLoader = new Loader('playwright', [
|
|
|
4972
4975
|
'playwright'
|
|
4973
4976
|
]);
|
|
4974
4977
|
|
|
4975
|
-
const debug =
|
|
4978
|
+
const debug = Debug('playwright-extra:puppeteer-compat');
|
|
4976
4979
|
const isPlaywrightPage = (obj) => {
|
|
4977
4980
|
return 'unroute' in obj;
|
|
4978
4981
|
};
|
|
@@ -5162,7 +5165,7 @@ function createBrowserShim(browser) {
|
|
|
5162
5165
|
return shim;
|
|
5163
5166
|
}
|
|
5164
5167
|
|
|
5165
|
-
const debug$1 =
|
|
5168
|
+
const debug$1 = Debug('playwright-extra:plugins');
|
|
5166
5169
|
class PluginList {
|
|
5167
5170
|
constructor() {
|
|
5168
5171
|
this._plugins = [];
|
|
@@ -5503,7 +5506,7 @@ If your bundler has issues with dynamic imports take a look at '.plugins.setDepe
|
|
|
5503
5506
|
}
|
|
5504
5507
|
}
|
|
5505
5508
|
|
|
5506
|
-
const debug$2 =
|
|
5509
|
+
const debug$2 = Debug('playwright-extra');
|
|
5507
5510
|
/**
|
|
5508
5511
|
* Modular plugin framework to teach `playwright` new tricks.
|
|
5509
5512
|
*/
|
|
@@ -5781,719 +5784,10 @@ playwrightLoader.lazyloadExportOrDie('selectors');
|
|
|
5781
5784
|
playwrightLoader.lazyloadExportOrDie('devices');
|
|
5782
5785
|
playwrightLoader.lazyloadExportOrDie('errors');
|
|
5783
5786
|
|
|
5784
|
-
/*!
|
|
5785
|
-
* puppeteer-extra-plugin v3.2.2 by berstend
|
|
5786
|
-
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin
|
|
5787
|
-
* @license MIT
|
|
5788
|
-
*/
|
|
5789
|
-
|
|
5790
|
-
/** @private */
|
|
5791
|
-
const merge$2 = require('merge-deep');
|
|
5792
|
-
/**
|
|
5793
|
-
* Base class for `puppeteer-extra` plugins.
|
|
5794
|
-
*
|
|
5795
|
-
* Provides convenience methods to avoid boilerplate.
|
|
5796
|
-
*
|
|
5797
|
-
* All common `puppeteer` browser events will be bound to
|
|
5798
|
-
* the plugin instance, if a respectively named class member is found.
|
|
5799
|
-
*
|
|
5800
|
-
* Please refer to the [puppeteer API documentation](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md) as well.
|
|
5801
|
-
*
|
|
5802
|
-
* @example
|
|
5803
|
-
* // hello-world-plugin.js
|
|
5804
|
-
* const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
|
|
5805
|
-
*
|
|
5806
|
-
* class Plugin extends PuppeteerExtraPlugin {
|
|
5807
|
-
* constructor (opts = { }) { super(opts) }
|
|
5808
|
-
*
|
|
5809
|
-
* get name () { return 'hello-world' }
|
|
5810
|
-
*
|
|
5811
|
-
* async onPageCreated (page) {
|
|
5812
|
-
* this.debug('page created', page.url())
|
|
5813
|
-
* const ua = await page.browser().userAgent()
|
|
5814
|
-
* this.debug('user agent', ua)
|
|
5815
|
-
* }
|
|
5816
|
-
* }
|
|
5817
|
-
*
|
|
5818
|
-
* module.exports = function (pluginConfig) { return new Plugin(pluginConfig) }
|
|
5819
|
-
*
|
|
5820
|
-
*
|
|
5821
|
-
* // foo.js
|
|
5822
|
-
* const puppeteer = require('puppeteer-extra')
|
|
5823
|
-
* puppeteer.use(require('./hello-world-plugin')())
|
|
5824
|
-
*
|
|
5825
|
-
* ;(async () => {
|
|
5826
|
-
* const browser = await puppeteer.launch({headless: false})
|
|
5827
|
-
* const page = await browser.newPage()
|
|
5828
|
-
* await page.goto('http://example.com', {waitUntil: 'domcontentloaded'})
|
|
5829
|
-
* await browser.close()
|
|
5830
|
-
* })()
|
|
5831
|
-
*
|
|
5832
|
-
*/
|
|
5833
|
-
class PuppeteerExtraPlugin$1 {
|
|
5834
|
-
constructor(opts) {
|
|
5835
|
-
this._debugBase = debug$3(`puppeteer-extra-plugin:base:${this.name}`);
|
|
5836
|
-
this._childClassMembers = [];
|
|
5837
|
-
this._opts = merge$2(this.defaults, opts || {});
|
|
5838
|
-
this._debugBase('Initialized.');
|
|
5839
|
-
}
|
|
5840
|
-
/**
|
|
5841
|
-
* Plugin name (required).
|
|
5842
|
-
*
|
|
5843
|
-
* Convention:
|
|
5844
|
-
* - Package: `puppeteer-extra-plugin-anonymize-ua`
|
|
5845
|
-
* - Name: `anonymize-ua`
|
|
5846
|
-
*
|
|
5847
|
-
* @example
|
|
5848
|
-
* get name () { return 'anonymize-ua' }
|
|
5849
|
-
*/
|
|
5850
|
-
get name() {
|
|
5851
|
-
throw new Error('Plugin must override "name"');
|
|
5852
|
-
}
|
|
5853
|
-
/**
|
|
5854
|
-
* Plugin defaults (optional).
|
|
5855
|
-
*
|
|
5856
|
-
* If defined will be ([deep-](https://github.com/jonschlinkert/merge-deep))merged with the (optional) user supplied options (supplied during plugin instantiation).
|
|
5857
|
-
*
|
|
5858
|
-
* The result of merging defaults with user supplied options can be accessed through `this.opts`.
|
|
5859
|
-
*
|
|
5860
|
-
* @see [[opts]]
|
|
5861
|
-
*
|
|
5862
|
-
* @example
|
|
5863
|
-
* get defaults () {
|
|
5864
|
-
* return {
|
|
5865
|
-
* stripHeadless: true,
|
|
5866
|
-
* makeWindows: true,
|
|
5867
|
-
* customFn: null
|
|
5868
|
-
* }
|
|
5869
|
-
* }
|
|
5870
|
-
*
|
|
5871
|
-
* // Users can overwrite plugin defaults during instantiation:
|
|
5872
|
-
* puppeteer.use(require('puppeteer-extra-plugin-foobar')({ makeWindows: false }))
|
|
5873
|
-
*/
|
|
5874
|
-
get defaults() {
|
|
5875
|
-
return {};
|
|
5876
|
-
}
|
|
5877
|
-
/**
|
|
5878
|
-
* Plugin requirements (optional).
|
|
5879
|
-
*
|
|
5880
|
-
* Signal certain plugin requirements to the base class and the user.
|
|
5881
|
-
*
|
|
5882
|
-
* Currently supported:
|
|
5883
|
-
* - `launch`
|
|
5884
|
-
* - If the plugin only supports locally created browser instances (no `puppeteer.connect()`),
|
|
5885
|
-
* will output a warning to the user.
|
|
5886
|
-
* - `headful`
|
|
5887
|
-
* - If the plugin doesn't work in `headless: true` mode,
|
|
5888
|
-
* will output a warning to the user.
|
|
5889
|
-
* - `dataFromPlugins`
|
|
5890
|
-
* - In case the plugin requires data from other plugins.
|
|
5891
|
-
* will enable usage of `this.getDataFromPlugins()`.
|
|
5892
|
-
* - `runLast`
|
|
5893
|
-
* - In case the plugin prefers to run after the others.
|
|
5894
|
-
* Useful when the plugin needs data from others.
|
|
5895
|
-
*
|
|
5896
|
-
* @example
|
|
5897
|
-
* get requirements () {
|
|
5898
|
-
* return new Set(['runLast', 'dataFromPlugins'])
|
|
5899
|
-
* }
|
|
5900
|
-
*/
|
|
5901
|
-
get requirements() {
|
|
5902
|
-
return new Set([]);
|
|
5903
|
-
}
|
|
5904
|
-
/**
|
|
5905
|
-
* Plugin dependencies (optional).
|
|
5906
|
-
*
|
|
5907
|
-
* Missing plugins will be required() by puppeteer-extra.
|
|
5908
|
-
*
|
|
5909
|
-
* @example
|
|
5910
|
-
* get dependencies () {
|
|
5911
|
-
* return new Set(['user-preferences'])
|
|
5912
|
-
* }
|
|
5913
|
-
* // Will ensure the 'puppeteer-extra-plugin-user-preferences' plugin is loaded.
|
|
5914
|
-
*/
|
|
5915
|
-
get dependencies() {
|
|
5916
|
-
return new Set([]);
|
|
5917
|
-
}
|
|
5918
|
-
/**
|
|
5919
|
-
* Plugin data (optional).
|
|
5920
|
-
*
|
|
5921
|
-
* Plugins can expose data (an array of objects), which in turn can be consumed by other plugins,
|
|
5922
|
-
* that list the `dataFromPlugins` requirement (by using `this.getDataFromPlugins()`).
|
|
5923
|
-
*
|
|
5924
|
-
* Convention: `[ {name: 'Any name', value: 'Any value'} ]`
|
|
5925
|
-
*
|
|
5926
|
-
* @see [[getDataFromPlugins]]
|
|
5927
|
-
*
|
|
5928
|
-
* @example
|
|
5929
|
-
* // plugin1.js
|
|
5930
|
-
* get data () {
|
|
5931
|
-
* return [
|
|
5932
|
-
* {
|
|
5933
|
-
* name: 'userPreferences',
|
|
5934
|
-
* value: { foo: 'bar' }
|
|
5935
|
-
* },
|
|
5936
|
-
* {
|
|
5937
|
-
* name: 'userPreferences',
|
|
5938
|
-
* value: { hello: 'world' }
|
|
5939
|
-
* }
|
|
5940
|
-
* ]
|
|
5941
|
-
*
|
|
5942
|
-
* // plugin2.js
|
|
5943
|
-
* get requirements () { return new Set(['dataFromPlugins']) }
|
|
5944
|
-
*
|
|
5945
|
-
* async beforeLaunch () {
|
|
5946
|
-
* const prefs = this.getDataFromPlugins('userPreferences').map(d => d.value)
|
|
5947
|
-
* this.debug(prefs) // => [ { foo: 'bar' }, { hello: 'world' } ]
|
|
5948
|
-
* }
|
|
5949
|
-
*/
|
|
5950
|
-
get data() {
|
|
5951
|
-
return [];
|
|
5952
|
-
}
|
|
5953
|
-
/**
|
|
5954
|
-
* Access the plugin options (usually the `defaults` merged with user defined options)
|
|
5955
|
-
*
|
|
5956
|
-
* To skip the auto-merging of defaults with user supplied opts don't define a `defaults`
|
|
5957
|
-
* property and set the `this._opts` Object in your plugin constructor directly.
|
|
5958
|
-
*
|
|
5959
|
-
* @see [[defaults]]
|
|
5960
|
-
*
|
|
5961
|
-
* @example
|
|
5962
|
-
* get defaults () { return { foo: "bar" } }
|
|
5963
|
-
*
|
|
5964
|
-
* async onPageCreated (page) {
|
|
5965
|
-
* this.debug(this.opts.foo) // => bar
|
|
5966
|
-
* }
|
|
5967
|
-
*/
|
|
5968
|
-
get opts() {
|
|
5969
|
-
return this._opts;
|
|
5970
|
-
}
|
|
5971
|
-
/**
|
|
5972
|
-
* Convenience debug logger based on the [debug] module.
|
|
5973
|
-
* Will automatically namespace the logging output to the plugin package name.
|
|
5974
|
-
* [debug]: https://www.npmjs.com/package/debug
|
|
5975
|
-
*
|
|
5976
|
-
* ```bash
|
|
5977
|
-
* # toggle output using environment variables
|
|
5978
|
-
* DEBUG=puppeteer-extra-plugin:<plugin_name> node foo.js
|
|
5979
|
-
* # to debug all the things:
|
|
5980
|
-
* DEBUG=puppeteer-extra,puppeteer-extra-plugin:* node foo.js
|
|
5981
|
-
* ```
|
|
5982
|
-
*
|
|
5983
|
-
* @example
|
|
5984
|
-
* this.debug('hello world')
|
|
5985
|
-
* // will output e.g. 'puppeteer-extra-plugin:anonymize-ua hello world'
|
|
5986
|
-
*/
|
|
5987
|
-
get debug() {
|
|
5988
|
-
return debug$3(`puppeteer-extra-plugin:${this.name}`);
|
|
5989
|
-
}
|
|
5990
|
-
/**
|
|
5991
|
-
* Before a new browser instance is created/launched.
|
|
5992
|
-
*
|
|
5993
|
-
* Can be used to modify the puppeteer launch options by modifying or returning them.
|
|
5994
|
-
*
|
|
5995
|
-
* Plugins using this method will be called in sequence to each
|
|
5996
|
-
* be able to update the launch options.
|
|
5997
|
-
*
|
|
5998
|
-
* @example
|
|
5999
|
-
* async beforeLaunch (options) {
|
|
6000
|
-
* if (this.opts.flashPluginPath) {
|
|
6001
|
-
* options.args.push(`--ppapi-flash-path=${this.opts.flashPluginPath}`)
|
|
6002
|
-
* }
|
|
6003
|
-
* }
|
|
6004
|
-
*
|
|
6005
|
-
* @param options - Puppeteer launch options
|
|
6006
|
-
*/
|
|
6007
|
-
async beforeLaunch(options) {
|
|
6008
|
-
// noop
|
|
6009
|
-
}
|
|
6010
|
-
/**
|
|
6011
|
-
* After the browser has launched.
|
|
6012
|
-
*
|
|
6013
|
-
* Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
6014
|
-
* It's possible that `pupeeteer.launch` will be called multiple times and more than one browser created.
|
|
6015
|
-
* In order to make the plugins as stateless as possible don't store a reference to the browser instance
|
|
6016
|
-
* in the plugin but rather consider alternatives.
|
|
6017
|
-
*
|
|
6018
|
-
* E.g. when using `onPageCreated` you can get a browser reference by using `page.browser()`.
|
|
6019
|
-
*
|
|
6020
|
-
* Alternatively you could expose a class method that takes a browser instance as a parameter to work with:
|
|
6021
|
-
*
|
|
6022
|
-
* ```es6
|
|
6023
|
-
* const fancyPlugin = require('puppeteer-extra-plugin-fancy')()
|
|
6024
|
-
* puppeteer.use(fancyPlugin)
|
|
6025
|
-
* const browser = await puppeteer.launch()
|
|
6026
|
-
* await fancyPlugin.killBrowser(browser)
|
|
6027
|
-
* ```
|
|
6028
|
-
*
|
|
6029
|
-
* @param browser - The `puppeteer` browser instance.
|
|
6030
|
-
* @param opts.options - Puppeteer launch options used.
|
|
6031
|
-
*
|
|
6032
|
-
* @example
|
|
6033
|
-
* async afterLaunch (browser, opts) {
|
|
6034
|
-
* this.debug('browser has been launched', opts.options)
|
|
6035
|
-
* }
|
|
6036
|
-
*/
|
|
6037
|
-
async afterLaunch(browser, opts = { options: {} }) {
|
|
6038
|
-
// noop
|
|
6039
|
-
}
|
|
6040
|
-
/**
|
|
6041
|
-
* Before connecting to an existing browser instance.
|
|
6042
|
-
*
|
|
6043
|
-
* Can be used to modify the puppeteer connect options by modifying or returning them.
|
|
6044
|
-
*
|
|
6045
|
-
* Plugins using this method will be called in sequence to each
|
|
6046
|
-
* be able to update the launch options.
|
|
6047
|
-
*
|
|
6048
|
-
* @param {Object} options - Puppeteer connect options
|
|
6049
|
-
* @return {Object=}
|
|
6050
|
-
*/
|
|
6051
|
-
async beforeConnect(options) {
|
|
6052
|
-
// noop
|
|
6053
|
-
}
|
|
6054
|
-
/**
|
|
6055
|
-
* After connecting to an existing browser instance.
|
|
6056
|
-
*
|
|
6057
|
-
* > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
6058
|
-
*
|
|
6059
|
-
* @param browser - The `puppeteer` browser instance.
|
|
6060
|
-
* @param {Object} opts
|
|
6061
|
-
* @param {Object} opts.options - Puppeteer connect options used.
|
|
6062
|
-
*
|
|
6063
|
-
*/
|
|
6064
|
-
async afterConnect(browser, opts = {}) {
|
|
6065
|
-
// noop
|
|
6066
|
-
}
|
|
6067
|
-
/**
|
|
6068
|
-
* Called when a browser instance is available.
|
|
6069
|
-
*
|
|
6070
|
-
* This applies to both `puppeteer.launch()` and `puppeteer.connect()`.
|
|
6071
|
-
*
|
|
6072
|
-
* Convenience method created for plugins that need access to a browser instance
|
|
6073
|
-
* and don't mind if it has been created through `launch` or `connect`.
|
|
6074
|
-
*
|
|
6075
|
-
* > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
6076
|
-
*
|
|
6077
|
-
* @param browser - The `puppeteer` browser instance.
|
|
6078
|
-
*/
|
|
6079
|
-
async onBrowser(browser, opts) {
|
|
6080
|
-
// noop
|
|
6081
|
-
}
|
|
6082
|
-
/**
|
|
6083
|
-
* Called when a target is created, for example when a new page is opened by window.open or browser.newPage.
|
|
6084
|
-
*
|
|
6085
|
-
* > Note: This includes target creations 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 onTargetCreated(target) {
|
|
6092
|
-
// noop
|
|
6093
|
-
}
|
|
6094
|
-
/**
|
|
6095
|
-
* Same as `onTargetCreated` but prefiltered to only contain Pages, for convenience.
|
|
6096
|
-
*
|
|
6097
|
-
* > Note: This includes page creations in incognito browser contexts.
|
|
6098
|
-
*
|
|
6099
|
-
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
6100
|
-
*
|
|
6101
|
-
* @param {Puppeteer.Target} target
|
|
6102
|
-
*
|
|
6103
|
-
* @example
|
|
6104
|
-
* async onPageCreated (page) {
|
|
6105
|
-
* let ua = await page.browser().userAgent()
|
|
6106
|
-
* if (this.opts.stripHeadless) {
|
|
6107
|
-
* ua = ua.replace('HeadlessChrome/', 'Chrome/')
|
|
6108
|
-
* }
|
|
6109
|
-
* this.debug('new ua', ua)
|
|
6110
|
-
* await page.setUserAgent(ua)
|
|
6111
|
-
* }
|
|
6112
|
-
*/
|
|
6113
|
-
async onPageCreated(page) {
|
|
6114
|
-
// noop
|
|
6115
|
-
}
|
|
6116
|
-
/**
|
|
6117
|
-
* Called when the url of a target changes.
|
|
6118
|
-
*
|
|
6119
|
-
* > Note: This includes target changes in incognito browser contexts.
|
|
6120
|
-
*
|
|
6121
|
-
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
6122
|
-
*
|
|
6123
|
-
* @param {Puppeteer.Target} target
|
|
6124
|
-
*/
|
|
6125
|
-
async onTargetChanged(target) {
|
|
6126
|
-
// noop
|
|
6127
|
-
}
|
|
6128
|
-
/**
|
|
6129
|
-
* Called when a target is destroyed, for example when a page is closed.
|
|
6130
|
-
*
|
|
6131
|
-
* > Note: This includes target destructions in incognito browser contexts.
|
|
6132
|
-
*
|
|
6133
|
-
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
6134
|
-
*
|
|
6135
|
-
* @param {Puppeteer.Target} target
|
|
6136
|
-
*/
|
|
6137
|
-
async onTargetDestroyed(target) {
|
|
6138
|
-
// noop
|
|
6139
|
-
}
|
|
6140
|
-
/**
|
|
6141
|
-
* Called when Puppeteer gets disconnected from the Chromium instance.
|
|
6142
|
-
*
|
|
6143
|
-
* This might happen because of one of the following:
|
|
6144
|
-
* - Chromium is closed or crashed
|
|
6145
|
-
* - The `browser.disconnect` method was called
|
|
6146
|
-
*/
|
|
6147
|
-
async onDisconnected() {
|
|
6148
|
-
// noop
|
|
6149
|
-
}
|
|
6150
|
-
/**
|
|
6151
|
-
* **Deprecated:** Since puppeteer v1.6.0 `onDisconnected` has been improved
|
|
6152
|
-
* and should be used instead of `onClose`.
|
|
6153
|
-
*
|
|
6154
|
-
* In puppeteer < v1.6.0 `onDisconnected` was not catching all exit scenarios.
|
|
6155
|
-
* In order for plugins to clean up properly (e.g. deleting temporary files)
|
|
6156
|
-
* the `onClose` method had been introduced.
|
|
6157
|
-
*
|
|
6158
|
-
* > Note: Might be called multiple times on exit.
|
|
6159
|
-
*
|
|
6160
|
-
* > Note: This only includes browser instances created through `.launch()`.
|
|
6161
|
-
*/
|
|
6162
|
-
async onClose() {
|
|
6163
|
-
// noop
|
|
6164
|
-
}
|
|
6165
|
-
/**
|
|
6166
|
-
* After the plugin has been registered in `puppeteer-extra`.
|
|
6167
|
-
*
|
|
6168
|
-
* Normally right after `puppeteer.use(plugin)` is called
|
|
6169
|
-
*/
|
|
6170
|
-
async onPluginRegistered() {
|
|
6171
|
-
// noop
|
|
6172
|
-
}
|
|
6173
|
-
/**
|
|
6174
|
-
* Helper method to retrieve `data` objects from other plugins.
|
|
6175
|
-
*
|
|
6176
|
-
* A plugin needs to state the `dataFromPlugins` requirement
|
|
6177
|
-
* in order to use this method. Will be mapped to `puppeteer.getPluginData`.
|
|
6178
|
-
*
|
|
6179
|
-
* @param name - Filter data by `name` property
|
|
6180
|
-
*
|
|
6181
|
-
* @see [data]
|
|
6182
|
-
* @see [requirements]
|
|
6183
|
-
*/
|
|
6184
|
-
getDataFromPlugins(name) {
|
|
6185
|
-
return [];
|
|
6186
|
-
}
|
|
6187
|
-
/**
|
|
6188
|
-
* Will match plugin dependencies against all currently registered plugins.
|
|
6189
|
-
* Is being called by `puppeteer-extra` and used to require missing dependencies.
|
|
6190
|
-
*
|
|
6191
|
-
* @param {Array<Object>} plugins
|
|
6192
|
-
* @return {Set} - list of missing plugin names
|
|
6193
|
-
*
|
|
6194
|
-
* @private
|
|
6195
|
-
*/
|
|
6196
|
-
_getMissingDependencies(plugins) {
|
|
6197
|
-
const pluginNames = new Set(plugins.map((p) => p.name));
|
|
6198
|
-
const missing = new Set(Array.from(this.dependencies.values()).filter(x => !pluginNames.has(x)));
|
|
6199
|
-
return missing;
|
|
6200
|
-
}
|
|
6201
|
-
/**
|
|
6202
|
-
* Conditionally bind browser/process events to class members.
|
|
6203
|
-
* The idea is to reduce event binding boilerplate in plugins.
|
|
6204
|
-
*
|
|
6205
|
-
* For efficiency we make sure the plugin is using the respective event
|
|
6206
|
-
* by checking the child class members before registering the listener.
|
|
6207
|
-
*
|
|
6208
|
-
* @param {<Puppeteer.Browser>} browser
|
|
6209
|
-
* @param {Object} opts - Options
|
|
6210
|
-
* @param {string} opts.context - Puppeteer context (launch/connect)
|
|
6211
|
-
* @param {Object} [opts.options] - Puppeteer launch or connect options
|
|
6212
|
-
* @param {Array<string>} [opts.defaultArgs] - The default flags that Chromium will be launched with
|
|
6213
|
-
*
|
|
6214
|
-
* @private
|
|
6215
|
-
*/
|
|
6216
|
-
async _bindBrowserEvents(browser, opts = {}) {
|
|
6217
|
-
if (this._hasChildClassMember('onTargetCreated') ||
|
|
6218
|
-
this._hasChildClassMember('onPageCreated')) {
|
|
6219
|
-
browser.on('targetcreated', this._onTargetCreated.bind(this));
|
|
6220
|
-
}
|
|
6221
|
-
if (this._hasChildClassMember('onTargetChanged') && this.onTargetChanged) {
|
|
6222
|
-
browser.on('targetchanged', this.onTargetChanged.bind(this));
|
|
6223
|
-
}
|
|
6224
|
-
if (this._hasChildClassMember('onTargetDestroyed') &&
|
|
6225
|
-
this.onTargetDestroyed) {
|
|
6226
|
-
browser.on('targetdestroyed', this.onTargetDestroyed.bind(this));
|
|
6227
|
-
}
|
|
6228
|
-
if (this._hasChildClassMember('onDisconnected') && this.onDisconnected) {
|
|
6229
|
-
browser.on('disconnected', this.onDisconnected.bind(this));
|
|
6230
|
-
}
|
|
6231
|
-
if (opts.context === 'launch' && this._hasChildClassMember('onClose')) {
|
|
6232
|
-
// The disconnect event has been improved since puppeteer v1.6.0
|
|
6233
|
-
// onClose is being kept mostly for legacy reasons
|
|
6234
|
-
if (this.onClose) {
|
|
6235
|
-
process.on('exit', this.onClose.bind(this));
|
|
6236
|
-
browser.on('disconnected', this.onClose.bind(this));
|
|
6237
|
-
if (opts.options.handleSIGINT !== false) {
|
|
6238
|
-
process.on('SIGINT', this.onClose.bind(this));
|
|
6239
|
-
}
|
|
6240
|
-
if (opts.options.handleSIGTERM !== false) {
|
|
6241
|
-
process.on('SIGTERM', this.onClose.bind(this));
|
|
6242
|
-
}
|
|
6243
|
-
if (opts.options.handleSIGHUP !== false) {
|
|
6244
|
-
process.on('SIGHUP', this.onClose.bind(this));
|
|
6245
|
-
}
|
|
6246
|
-
}
|
|
6247
|
-
}
|
|
6248
|
-
if (opts.context === 'launch' && this.afterLaunch) {
|
|
6249
|
-
await this.afterLaunch(browser, opts);
|
|
6250
|
-
}
|
|
6251
|
-
if (opts.context === 'connect' && this.afterConnect) {
|
|
6252
|
-
await this.afterConnect(browser, opts);
|
|
6253
|
-
}
|
|
6254
|
-
if (this.onBrowser)
|
|
6255
|
-
await this.onBrowser(browser, opts);
|
|
6256
|
-
}
|
|
6257
|
-
/**
|
|
6258
|
-
* @private
|
|
6259
|
-
*/
|
|
6260
|
-
async _onTargetCreated(target) {
|
|
6261
|
-
if (this.onTargetCreated)
|
|
6262
|
-
await this.onTargetCreated(target);
|
|
6263
|
-
// Pre filter pages for plugin developers convenience
|
|
6264
|
-
if (target.type() === 'page') {
|
|
6265
|
-
try {
|
|
6266
|
-
const page = await target.page();
|
|
6267
|
-
if (!page) {
|
|
6268
|
-
return;
|
|
6269
|
-
}
|
|
6270
|
-
const validPage = 'isClosed' in page && !page.isClosed();
|
|
6271
|
-
if (this.onPageCreated && validPage) {
|
|
6272
|
-
await this.onPageCreated(page);
|
|
6273
|
-
}
|
|
6274
|
-
}
|
|
6275
|
-
catch (err) {
|
|
6276
|
-
console.error(err);
|
|
6277
|
-
}
|
|
6278
|
-
}
|
|
6279
|
-
}
|
|
6280
|
-
/**
|
|
6281
|
-
* @private
|
|
6282
|
-
*/
|
|
6283
|
-
_register(prototype) {
|
|
6284
|
-
this._registerChildClassMembers(prototype);
|
|
6285
|
-
if (this.onPluginRegistered)
|
|
6286
|
-
this.onPluginRegistered();
|
|
6287
|
-
}
|
|
6288
|
-
/**
|
|
6289
|
-
* @private
|
|
6290
|
-
*/
|
|
6291
|
-
_registerChildClassMembers(prototype) {
|
|
6292
|
-
this._childClassMembers = Object.getOwnPropertyNames(prototype);
|
|
6293
|
-
}
|
|
6294
|
-
/**
|
|
6295
|
-
* @private
|
|
6296
|
-
*/
|
|
6297
|
-
_hasChildClassMember(name) {
|
|
6298
|
-
return !!this._childClassMembers.includes(name);
|
|
6299
|
-
}
|
|
6300
|
-
/**
|
|
6301
|
-
* @private
|
|
6302
|
-
*/
|
|
6303
|
-
get _isPuppeteerExtraPlugin() {
|
|
6304
|
-
return true;
|
|
6305
|
-
}
|
|
6306
|
-
}
|
|
6307
|
-
|
|
6308
|
-
var index_esm = /*#__PURE__*/Object.freeze({
|
|
6309
|
-
__proto__: null,
|
|
6310
|
-
PuppeteerExtraPlugin: PuppeteerExtraPlugin$1
|
|
6311
|
-
});
|
|
6312
|
-
|
|
6313
|
-
var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(index_esm);
|
|
6314
|
-
|
|
6315
|
-
const { PuppeteerExtraPlugin } = require$$0$1;
|
|
6316
|
-
|
|
6317
|
-
/**
|
|
6318
|
-
* Stealth mode: Applies various techniques to make detection of headless puppeteer harder. 💯
|
|
6319
|
-
*
|
|
6320
|
-
* ### Purpose
|
|
6321
|
-
* There are a couple of ways the use of puppeteer can easily be detected by a target website.
|
|
6322
|
-
* The addition of `HeadlessChrome` to the user-agent being only the most obvious one.
|
|
6323
|
-
*
|
|
6324
|
-
* The goal of this plugin is to be the definite companion to puppeteer to avoid
|
|
6325
|
-
* detection, applying new techniques as they surface.
|
|
6326
|
-
*
|
|
6327
|
-
* As this cat & mouse game is in it's infancy and fast-paced the plugin
|
|
6328
|
-
* is kept as flexibile as possible, to support quick testing and iterations.
|
|
6329
|
-
*
|
|
6330
|
-
* ### Modularity
|
|
6331
|
-
* This plugin uses `puppeteer-extra`'s dependency system to only require
|
|
6332
|
-
* code mods for evasions that have been enabled, to keep things modular and efficient.
|
|
6333
|
-
*
|
|
6334
|
-
* The `stealth` plugin is a convenience wrapper that requires multiple [evasion techniques](./evasions/)
|
|
6335
|
-
* automatically and comes with defaults. You could also bypass the main module and require
|
|
6336
|
-
* specific evasion plugins yourself, if you whish to do so (as they're standalone `puppeteer-extra` plugins):
|
|
6337
|
-
*
|
|
6338
|
-
* ```es6
|
|
6339
|
-
* // bypass main module and require a specific stealth plugin directly:
|
|
6340
|
-
* puppeteer.use(require('puppeteer-extra-plugin-stealth/evasions/console.debug')())
|
|
6341
|
-
* ```
|
|
6342
|
-
*
|
|
6343
|
-
* ### Contributing
|
|
6344
|
-
* PRs are welcome, if you want to add a new evasion technique I suggest you
|
|
6345
|
-
* look at the [template](./evasions/_template) to kickstart things.
|
|
6346
|
-
*
|
|
6347
|
-
* ### Kudos
|
|
6348
|
-
* 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!
|
|
6349
|
-
*
|
|
6350
|
-
* ---
|
|
6351
|
-
*
|
|
6352
|
-
* @todo
|
|
6353
|
-
* - white-/blacklist with url globs (make this a generic plugin method?)
|
|
6354
|
-
* - dynamic whitelist based on function evaluation
|
|
6355
|
-
*
|
|
6356
|
-
* @example
|
|
6357
|
-
* const puppeteer = require('puppeteer-extra')
|
|
6358
|
-
* // Enable stealth plugin with all evasions
|
|
6359
|
-
* puppeteer.use(require('puppeteer-extra-plugin-stealth')())
|
|
6360
|
-
*
|
|
6361
|
-
*
|
|
6362
|
-
* ;(async () => {
|
|
6363
|
-
* // Launch the browser in headless mode and set up a page.
|
|
6364
|
-
* const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true })
|
|
6365
|
-
* const page = await browser.newPage()
|
|
6366
|
-
*
|
|
6367
|
-
* // Navigate to the page that will perform the tests.
|
|
6368
|
-
* const testUrl = 'https://intoli.com/blog/' +
|
|
6369
|
-
* 'not-possible-to-block-chrome-headless/chrome-headless-test.html'
|
|
6370
|
-
* await page.goto(testUrl)
|
|
6371
|
-
*
|
|
6372
|
-
* // Save a screenshot of the results.
|
|
6373
|
-
* const screenshotPath = '/tmp/headless-test-result.png'
|
|
6374
|
-
* await page.screenshot({path: screenshotPath})
|
|
6375
|
-
* console.log('have a look at the screenshot:', screenshotPath)
|
|
6376
|
-
*
|
|
6377
|
-
* await browser.close()
|
|
6378
|
-
* })()
|
|
6379
|
-
*
|
|
6380
|
-
* @param {Object} [opts] - Options
|
|
6381
|
-
* @param {Set<string>} [opts.enabledEvasions] - Specify which evasions to use (by default all)
|
|
6382
|
-
*
|
|
6383
|
-
*/
|
|
6384
|
-
class StealthPlugin extends PuppeteerExtraPlugin {
|
|
6385
|
-
constructor(opts = {}) {
|
|
6386
|
-
super(opts);
|
|
6387
|
-
}
|
|
6388
|
-
|
|
6389
|
-
get name() {
|
|
6390
|
-
return 'stealth'
|
|
6391
|
-
}
|
|
6392
|
-
|
|
6393
|
-
get defaults() {
|
|
6394
|
-
const availableEvasions = new Set([
|
|
6395
|
-
'chrome.app',
|
|
6396
|
-
'chrome.csi',
|
|
6397
|
-
'chrome.loadTimes',
|
|
6398
|
-
'chrome.runtime',
|
|
6399
|
-
'defaultArgs',
|
|
6400
|
-
'iframe.contentWindow',
|
|
6401
|
-
'media.codecs',
|
|
6402
|
-
'navigator.hardwareConcurrency',
|
|
6403
|
-
'navigator.languages',
|
|
6404
|
-
'navigator.permissions',
|
|
6405
|
-
'navigator.plugins',
|
|
6406
|
-
'navigator.webdriver',
|
|
6407
|
-
'sourceurl',
|
|
6408
|
-
'user-agent-override',
|
|
6409
|
-
'webgl.vendor',
|
|
6410
|
-
'window.outerdimensions'
|
|
6411
|
-
]);
|
|
6412
|
-
return {
|
|
6413
|
-
availableEvasions,
|
|
6414
|
-
// Enable all available evasions by default
|
|
6415
|
-
enabledEvasions: new Set([...availableEvasions])
|
|
6416
|
-
}
|
|
6417
|
-
}
|
|
6418
|
-
|
|
6419
|
-
/**
|
|
6420
|
-
* Requires evasion techniques dynamically based on configuration.
|
|
6421
|
-
*
|
|
6422
|
-
* @private
|
|
6423
|
-
*/
|
|
6424
|
-
get dependencies() {
|
|
6425
|
-
return new Set(
|
|
6426
|
-
[...this.opts.enabledEvasions].map(e => `${this.name}/evasions/${e}`)
|
|
6427
|
-
)
|
|
6428
|
-
}
|
|
6429
|
-
|
|
6430
|
-
/**
|
|
6431
|
-
* Get all available evasions.
|
|
6432
|
-
*
|
|
6433
|
-
* Please look into the [evasions directory](./evasions/) for an up to date list.
|
|
6434
|
-
*
|
|
6435
|
-
* @type {Set<string>} - A Set of all available evasions.
|
|
6436
|
-
*
|
|
6437
|
-
* @example
|
|
6438
|
-
* const pluginStealth = require('puppeteer-extra-plugin-stealth')()
|
|
6439
|
-
* console.log(pluginStealth.availableEvasions) // => Set { 'user-agent', 'console.debug' }
|
|
6440
|
-
* puppeteer.use(pluginStealth)
|
|
6441
|
-
*/
|
|
6442
|
-
get availableEvasions() {
|
|
6443
|
-
return this.defaults.availableEvasions
|
|
6444
|
-
}
|
|
6445
|
-
|
|
6446
|
-
/**
|
|
6447
|
-
* Get all enabled evasions.
|
|
6448
|
-
*
|
|
6449
|
-
* Enabled evasions can be configured either through `opts` or by modifying this property.
|
|
6450
|
-
*
|
|
6451
|
-
* @type {Set<string>} - A Set of all enabled evasions.
|
|
6452
|
-
*
|
|
6453
|
-
* @example
|
|
6454
|
-
* // Remove specific evasion from enabled ones dynamically
|
|
6455
|
-
* const pluginStealth = require('puppeteer-extra-plugin-stealth')()
|
|
6456
|
-
* pluginStealth.enabledEvasions.delete('console.debug')
|
|
6457
|
-
* puppeteer.use(pluginStealth)
|
|
6458
|
-
*/
|
|
6459
|
-
get enabledEvasions() {
|
|
6460
|
-
return this.opts.enabledEvasions
|
|
6461
|
-
}
|
|
6462
|
-
|
|
6463
|
-
/**
|
|
6464
|
-
* @private
|
|
6465
|
-
*/
|
|
6466
|
-
set enabledEvasions(evasions) {
|
|
6467
|
-
this.opts.enabledEvasions = evasions;
|
|
6468
|
-
}
|
|
6469
|
-
|
|
6470
|
-
async onBrowser(browser) {
|
|
6471
|
-
if (browser && browser.setMaxListeners) {
|
|
6472
|
-
// Increase event emitter listeners to prevent MaxListenersExceededWarning
|
|
6473
|
-
browser.setMaxListeners(30);
|
|
6474
|
-
}
|
|
6475
|
-
}
|
|
6476
|
-
}
|
|
6477
|
-
|
|
6478
|
-
/**
|
|
6479
|
-
* Default export, PuppeteerExtraStealthPlugin
|
|
6480
|
-
*
|
|
6481
|
-
* @param {Object} [opts] - Options
|
|
6482
|
-
* @param {Set<string>} [opts.enabledEvasions] - Specify which evasions to use (by default all)
|
|
6483
|
-
*/
|
|
6484
|
-
const defaultExport = opts => new StealthPlugin(opts);
|
|
6485
|
-
var puppeteerExtraPluginStealth = defaultExport;
|
|
6486
|
-
|
|
6487
|
-
// const moduleExport = defaultExport
|
|
6488
|
-
// moduleExport.StealthPlugin = StealthPlugin
|
|
6489
|
-
// module.exports = moduleExport
|
|
6490
|
-
|
|
6491
|
-
var stealth$1 = /*@__PURE__*/getDefaultExportFromCjs(puppeteerExtraPluginStealth);
|
|
6492
|
-
|
|
6493
5787
|
var stealth = test$1.test.extend({
|
|
6494
5788
|
browser: async ({ browser }, use) => {
|
|
6495
5789
|
await browser.close();
|
|
6496
|
-
chromium.use(
|
|
5790
|
+
chromium.use(stealth__default["default"]());
|
|
6497
5791
|
const stealthBrowser = await chromium.launch();
|
|
6498
5792
|
await use(stealthBrowser);
|
|
6499
5793
|
await stealthBrowser.close();
|
|
@@ -13602,7 +12896,7 @@ const TOASTR_MESSAGES = {
|
|
|
13602
12896
|
zapierApiKeyGenerated: "Zapier API key is generated successfully!",
|
|
13603
12897
|
};
|
|
13604
12898
|
const ZAPIER_LIMIT_EXHAUSTED_MESSAGE = "Zapier free task limit is exhausted. Test will be aborted";
|
|
13605
|
-
const
|
|
12899
|
+
const EMOJI_LABEL = "thumbs up";
|
|
13606
12900
|
const ATTACHMENT_DELETION_TOASTR_MESSAGE = "Attachment has been successfully deleted.";
|
|
13607
12901
|
|
|
13608
12902
|
const HELP_CENTER_SELECTORS = {
|
|
@@ -14459,6 +13753,7 @@ class ZapierPage extends IntegrationBase {
|
|
|
14459
13753
|
const DESCRIPTION_EDITOR_TEXTS = {
|
|
14460
13754
|
fontSize: "Font size",
|
|
14461
13755
|
paragraph: "Paragraph",
|
|
13756
|
+
normalText: "Normal text",
|
|
14462
13757
|
pasteLink: "Paste the link here...",
|
|
14463
13758
|
invalidURLError: "Please enter a valid URL",
|
|
14464
13759
|
pasteURL: "Paste URL",
|
|
@@ -14467,6 +13762,8 @@ const DESCRIPTION_EDITOR_TEXTS = {
|
|
|
14467
13762
|
link: "Link",
|
|
14468
13763
|
cannedResponseHeader: "Canned responses",
|
|
14469
13764
|
paragraphOption: "paragraph",
|
|
13765
|
+
search: "Search",
|
|
13766
|
+
emoji: "Emoji",
|
|
14470
13767
|
};
|
|
14471
13768
|
const EXPANDED_FONT_SIZE = {
|
|
14472
13769
|
h1: "Heading 1",
|
|
@@ -14514,7 +13811,7 @@ const NEETO_EDITOR_SELECTORS = {
|
|
|
14514
13811
|
addLinkTextField: "neeto-editor-add-link-text-input",
|
|
14515
13812
|
addURLTextField: "neeto-editor-add-link-url-input",
|
|
14516
13813
|
submitLinkButton: "neeto-editor-add-link",
|
|
14517
|
-
fontSizeDropdown: (currentOption
|
|
13814
|
+
fontSizeDropdown: (currentOption) => `${joinHyphenCase(currentOption)}-dropdown-icon`,
|
|
14518
13815
|
fixedMenuArrow: "neeto-editor-fixed-menu-arrow",
|
|
14519
13816
|
cannedResponseOption: "neeto-editor-fixed-menu-canned-responses-option",
|
|
14520
13817
|
cannedResponseSelectContainer: "select-a-canned-response-select-container",
|
|
@@ -14540,6 +13837,9 @@ const NEETO_EDITOR_SELECTORS = {
|
|
|
14540
13837
|
errorText: "neeto-editor-error-text",
|
|
14541
13838
|
content: "editor-content",
|
|
14542
13839
|
imageUploadDeleteButton: "neeto-editor-image-menu-Delete",
|
|
13840
|
+
dynamicVariablesButton: "dynamic-variables-button",
|
|
13841
|
+
emojiContainer: "neeto-editor-emoji-picker",
|
|
13842
|
+
dynamicVariableSelector: (variable) => `dynamic-variables-list-item-${neetoCist.hyphenate(variable)}`,
|
|
14543
13843
|
};
|
|
14544
13844
|
const NEETO_TEXT_MODIFIER_SELECTORS = {
|
|
14545
13845
|
strikeOption: "neeto-editor-fixed-menu-strike-option",
|
|
@@ -14550,7 +13850,7 @@ const TEXT_MODIFIER_SELECTORS = {
|
|
|
14550
13850
|
boldOption: "neeto-editor-fixed-menu-bold-option",
|
|
14551
13851
|
italicsOption: "neeto-editor-fixed-menu-italic-option",
|
|
14552
13852
|
codeOption: "neeto-editor-fixed-menu-code-option",
|
|
14553
|
-
blockquoteOption: "neeto-editor-fixed-menu-
|
|
13853
|
+
blockquoteOption: "neeto-editor-fixed-menu-blockquote-option",
|
|
14554
13854
|
codeblockOption: "neeto-editor-fixed-menu-code-block-option",
|
|
14555
13855
|
};
|
|
14556
13856
|
const LIST_MODIFIER_SELECTORS = {
|
|
@@ -14568,40 +13868,44 @@ const FONT_SIZE_SELECTORS = {
|
|
|
14568
13868
|
/* eslint-disable playwright/no-nth-methods */
|
|
14569
13869
|
class EditorPage {
|
|
14570
13870
|
constructor(page, neetoPlaywrightUtilities) {
|
|
14571
|
-
this.verifyDescriptionEditor = async ({ text, linkUrl = faker.faker.internet.url(), filePath = "../../../e2e/assets/images/BigBinary.png", imageUrl = "https://picsum.photos/200/300", videoUrl = "https://youtu.be/jNQXAC9IVRw", cannedResponseSuccessMessage, }) => {
|
|
14572
|
-
|
|
14573
|
-
|
|
14574
|
-
|
|
13871
|
+
this.verifyDescriptionEditor = async ({ text, editorWrapper, dynamicVariables, defaultFontSizeOption = "Paragraph", linkUrl = faker.faker.internet.url(), filePath = "../../../e2e/assets/images/BigBinary.png", imageUrl = "https://picsum.photos/200/300", videoUrl = "https://youtu.be/jNQXAC9IVRw", cannedResponseSuccessMessage, }) => {
|
|
13872
|
+
if (!editorWrapper)
|
|
13873
|
+
editorWrapper = this.page;
|
|
13874
|
+
await editorWrapper
|
|
13875
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
13876
|
+
.fill(text);
|
|
13877
|
+
await editorWrapper
|
|
13878
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.fontSizeDropdown(defaultFontSizeOption))
|
|
14575
13879
|
.click();
|
|
14576
13880
|
const fontSize = Object.keys(FONT_SIZE_SELECTORS);
|
|
14577
13881
|
for (const font of fontSize) {
|
|
14578
13882
|
const fontKey = font;
|
|
14579
|
-
await
|
|
14580
|
-
await test$1.expect(
|
|
13883
|
+
await editorWrapper.getByTestId(FONT_SIZE_SELECTORS[fontKey]).click();
|
|
13884
|
+
await test$1.expect(editorWrapper
|
|
14581
13885
|
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14582
13886
|
.getByRole("heading", { level: Number(font.slice(1)) })).toBeVisible();
|
|
14583
|
-
await
|
|
13887
|
+
await editorWrapper
|
|
14584
13888
|
.getByTestId(NEETO_EDITOR_SELECTORS.fontSizeDropdown(EXPANDED_FONT_SIZE[fontKey]))
|
|
14585
13889
|
.click();
|
|
14586
13890
|
}
|
|
14587
13891
|
if (await this.paragraphSelector.isVisible()) {
|
|
14588
13892
|
await this.paragraphSelector.click();
|
|
14589
13893
|
const paragraphRole = DESCRIPTION_EDITOR_TEXTS.paragraphOption;
|
|
14590
|
-
await test$1.expect(
|
|
13894
|
+
await test$1.expect(editorWrapper
|
|
14591
13895
|
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14592
13896
|
.getByRole(paragraphRole)).toBeVisible();
|
|
14593
13897
|
}
|
|
14594
13898
|
(await this.fixedMenuArrowSelector.isVisible()) &&
|
|
14595
13899
|
(await this.fixedMenuArrowSelector.click());
|
|
14596
|
-
await
|
|
13900
|
+
await editorWrapper.getByText(text).click({ clickCount: 3 });
|
|
14597
13901
|
const textModifier = Object.keys(TEXT_MODIFIER_SELECTORS);
|
|
14598
13902
|
for (const modifier of textModifier) {
|
|
14599
13903
|
const modifierKey = modifier;
|
|
14600
13904
|
const textModifierRole = TEXT_MODIFIER_ROLES[modifierKey];
|
|
14601
|
-
const textModifierSelector =
|
|
13905
|
+
const textModifierSelector = editorWrapper.getByTestId(TEXT_MODIFIER_SELECTORS[modifierKey]);
|
|
14602
13906
|
if (await textModifierSelector.isVisible()) {
|
|
14603
13907
|
await textModifierSelector.click();
|
|
14604
|
-
await test$1.expect(
|
|
13908
|
+
await test$1.expect(editorWrapper
|
|
14605
13909
|
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14606
13910
|
.getByRole(textModifierRole)).toBeVisible();
|
|
14607
13911
|
await textModifierSelector.click();
|
|
@@ -14610,10 +13914,10 @@ class EditorPage {
|
|
|
14610
13914
|
const textDeskModifier = Object.keys(NEETO_TEXT_MODIFIER_SELECTORS);
|
|
14611
13915
|
for (const modifier of textDeskModifier) {
|
|
14612
13916
|
const modifierKey = modifier;
|
|
14613
|
-
const textModifierSelector =
|
|
13917
|
+
const textModifierSelector = editorWrapper.getByTestId(NEETO_TEXT_MODIFIER_SELECTORS[modifierKey]);
|
|
14614
13918
|
if (await textModifierSelector.isVisible()) {
|
|
14615
13919
|
await textModifierSelector.click();
|
|
14616
|
-
await test$1.expect(
|
|
13920
|
+
await test$1.expect(editorWrapper
|
|
14617
13921
|
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14618
13922
|
.locator(TEXT_MODIFIER_TAGS[modifierKey])).toBeVisible();
|
|
14619
13923
|
await textModifierSelector.click();
|
|
@@ -14622,10 +13926,10 @@ class EditorPage {
|
|
|
14622
13926
|
const listModifier = Object.keys(LIST_MODIFIER_SELECTORS);
|
|
14623
13927
|
for (const modifier of listModifier) {
|
|
14624
13928
|
const modifierKey = modifier;
|
|
14625
|
-
const listModifierSelector =
|
|
13929
|
+
const listModifierSelector = editorWrapper.getByTestId(LIST_MODIFIER_SELECTORS[modifierKey]);
|
|
14626
13930
|
if (await listModifierSelector.isVisible()) {
|
|
14627
13931
|
await listModifierSelector.click();
|
|
14628
|
-
await test$1.expect(
|
|
13932
|
+
await test$1.expect(editorWrapper
|
|
14629
13933
|
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14630
13934
|
.locator(LIST_MODIFIER_TAGS[modifierKey])).toBeVisible();
|
|
14631
13935
|
await listModifierSelector.click();
|
|
@@ -14640,7 +13944,7 @@ class EditorPage {
|
|
|
14640
13944
|
.getByTestId(NEETO_EDITOR_SELECTORS.addLinkDoneButton)
|
|
14641
13945
|
.click();
|
|
14642
13946
|
const linkRole = DESCRIPTION_EDITOR_TEXTS.link;
|
|
14643
|
-
await test$1.expect(
|
|
13947
|
+
await test$1.expect(editorWrapper
|
|
14644
13948
|
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14645
13949
|
.getByRole(linkRole)).toBeVisible();
|
|
14646
13950
|
await this.page.getByTestId(NEETO_EDITOR_SELECTORS.unlinkButton).click();
|
|
@@ -14665,10 +13969,10 @@ class EditorPage {
|
|
|
14665
13969
|
await this.page
|
|
14666
13970
|
.getByTestId(COMMON_SELECTORS.alertModalSubmitButton)
|
|
14667
13971
|
.click();
|
|
13972
|
+
await this.neetoPlaywrightUtilities.verifyToast({
|
|
13973
|
+
message: ATTACHMENT_DELETION_TOASTR_MESSAGE,
|
|
13974
|
+
});
|
|
14668
13975
|
}
|
|
14669
|
-
await this.neetoPlaywrightUtilities.verifyToast({
|
|
14670
|
-
message: ATTACHMENT_DELETION_TOASTR_MESSAGE,
|
|
14671
|
-
});
|
|
14672
13976
|
if (await this.imageUploadOption.isVisible()) {
|
|
14673
13977
|
await this.imageUploadOption.click();
|
|
14674
13978
|
const fileUploaderPromise = this.page.waitForEvent("filechooser");
|
|
@@ -14679,7 +13983,6 @@ class EditorPage {
|
|
|
14679
13983
|
const imagePath = Path__namespace.join(__dirname, filePath);
|
|
14680
13984
|
await fileUploader.setFiles(imagePath);
|
|
14681
13985
|
await test$1.expect(this.imageWrapper).toBeVisible({ timeout: 15000 });
|
|
14682
|
-
await this.neetoPlaywrightUtilities.verifyToast();
|
|
14683
13986
|
await this.imageWrapper
|
|
14684
13987
|
.getByTestId(COMMON_SELECTORS.dropdownIcon)
|
|
14685
13988
|
.click();
|
|
@@ -14720,11 +14023,11 @@ class EditorPage {
|
|
|
14720
14023
|
message: cannedResponseSuccessMessage,
|
|
14721
14024
|
});
|
|
14722
14025
|
}
|
|
14723
|
-
if (await
|
|
14026
|
+
if (await editorWrapper
|
|
14724
14027
|
.getByTestId(NEETO_EDITOR_SELECTORS.videoEmbedOption)
|
|
14725
14028
|
.isVisible()) {
|
|
14726
14029
|
await this.videoEmbedOption.click();
|
|
14727
|
-
await this.
|
|
14030
|
+
await this.videoEmbedInput.fill(videoUrl);
|
|
14728
14031
|
await this.page
|
|
14729
14032
|
.getByTestId(NEETO_EDITOR_SELECTORS.videoEmbedSubmit)
|
|
14730
14033
|
.click();
|
|
@@ -14740,12 +14043,35 @@ class EditorPage {
|
|
|
14740
14043
|
if (await this.emojiDropdownIcon.isVisible()) {
|
|
14741
14044
|
await this.emojiDropdownIcon.click();
|
|
14742
14045
|
await this.page
|
|
14743
|
-
.getByRole("
|
|
14744
|
-
name: EMOJI_PICKER_LABEL,
|
|
14745
|
-
})
|
|
14746
|
-
.getByText("👍")
|
|
14046
|
+
.getByRole("button", { name: DESCRIPTION_EDITOR_TEXTS.emoji })
|
|
14747
14047
|
.click();
|
|
14748
|
-
await test$1.expect(this.page.getByTestId(NEETO_EDITOR_SELECTORS.
|
|
14048
|
+
await test$1.expect(this.page.getByTestId(NEETO_EDITOR_SELECTORS.emojiContainer)).toBeVisible({
|
|
14049
|
+
timeout: 10000,
|
|
14050
|
+
});
|
|
14051
|
+
await this.page
|
|
14052
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.emojiContainer)
|
|
14053
|
+
.getByPlaceholder(DESCRIPTION_EDITOR_TEXTS.search)
|
|
14054
|
+
.fill(EMOJI_LABEL);
|
|
14055
|
+
await this.page.keyboard.press("Enter");
|
|
14056
|
+
await test$1.expect(editorWrapper.getByTestId(NEETO_EDITOR_SELECTORS.contentField)).toContainText("👍");
|
|
14057
|
+
await this.page.keyboard.press("Escape");
|
|
14058
|
+
}
|
|
14059
|
+
if (dynamicVariables &&
|
|
14060
|
+
(await editorWrapper
|
|
14061
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.dynamicVariablesButton)
|
|
14062
|
+
.isVisible())) {
|
|
14063
|
+
for (const dynamicVariable of dynamicVariables) {
|
|
14064
|
+
await editorWrapper
|
|
14065
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.dynamicVariablesButton)
|
|
14066
|
+
.click();
|
|
14067
|
+
await test$1.expect(this.page.getByTestId(COMMON_SELECTORS.dropdownContainer)).toBeVisible();
|
|
14068
|
+
await this.page
|
|
14069
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.dynamicVariableSelector(dynamicVariable))
|
|
14070
|
+
.click();
|
|
14071
|
+
await test$1.expect(editorWrapper
|
|
14072
|
+
.getByTestId(NEETO_EDITOR_SELECTORS.contentField)
|
|
14073
|
+
.getByText(dynamicVariable)).toBeVisible();
|
|
14074
|
+
}
|
|
14749
14075
|
}
|
|
14750
14076
|
};
|
|
14751
14077
|
this.page = page;
|
|
@@ -14761,6 +14087,7 @@ class EditorPage {
|
|
|
14761
14087
|
this.imageUploadOption = this.page.getByTestId(NEETO_EDITOR_SELECTORS.imageUploadOption);
|
|
14762
14088
|
this.cannedResponseOption = this.page.getByTestId(NEETO_EDITOR_SELECTORS.cannedResponseOption);
|
|
14763
14089
|
this.videoEmbedOption = this.page.getByTestId(NEETO_EDITOR_SELECTORS.videoEmbedOption);
|
|
14090
|
+
this.videoEmbedInput = this.page.getByTestId(NEETO_EDITOR_SELECTORS.videoEmbedInput);
|
|
14764
14091
|
this.videoWrapperSelector = this.page.getByTestId(NEETO_EDITOR_SELECTORS.videoWrapper);
|
|
14765
14092
|
this.emojiDropdownIcon = this.page
|
|
14766
14093
|
.getByTestId(NEETO_EDITOR_SELECTORS.fixedMenuWrapper)
|
|
@@ -17369,12 +16696,12 @@ function intToRGBA(i) {
|
|
|
17369
16696
|
a
|
|
17370
16697
|
};
|
|
17371
16698
|
}
|
|
17372
|
-
const c
|
|
16699
|
+
const c = [];
|
|
17373
16700
|
function initCoefficients(size) {
|
|
17374
16701
|
for (let i = 1; i < size; i++) {
|
|
17375
|
-
c
|
|
16702
|
+
c[i] = 1;
|
|
17376
16703
|
}
|
|
17377
|
-
c
|
|
16704
|
+
c[0] = 1 / Math.sqrt(2.0);
|
|
17378
16705
|
}
|
|
17379
16706
|
function applyDCT(f, size) {
|
|
17380
16707
|
const N = size;
|
|
@@ -17388,7 +16715,7 @@ function applyDCT(f, size) {
|
|
|
17388
16715
|
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];
|
|
17389
16716
|
}
|
|
17390
16717
|
}
|
|
17391
|
-
sum *= c
|
|
16718
|
+
sum *= c[u] * c[v] / 4;
|
|
17392
16719
|
F[u][v] = sum;
|
|
17393
16720
|
}
|
|
17394
16721
|
}
|
|
@@ -99095,7 +98422,7 @@ function multiply(src, dst) {
|
|
|
99095
98422
|
a
|
|
99096
98423
|
};
|
|
99097
98424
|
}
|
|
99098
|
-
function add(src, dst) {
|
|
98425
|
+
function add$1(src, dst) {
|
|
99099
98426
|
let ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
99100
98427
|
src.a *= ops;
|
|
99101
98428
|
const a = dst.a + src.a - dst.a * src.a;
|
|
@@ -99261,7 +98588,7 @@ var compositeModes = /*#__PURE__*/Object.freeze({
|
|
|
99261
98588
|
srcOver: srcOver,
|
|
99262
98589
|
dstOver: dstOver,
|
|
99263
98590
|
multiply: multiply,
|
|
99264
|
-
add: add,
|
|
98591
|
+
add: add$1,
|
|
99265
98592
|
screen: screen,
|
|
99266
98593
|
overlay: overlay,
|
|
99267
98594
|
darken: darken,
|
|
@@ -120751,31 +120078,31 @@ __export(constants_exports, {
|
|
|
120751
120078
|
// src/constants/bt709.ts
|
|
120752
120079
|
var bt709_exports = {};
|
|
120753
120080
|
__export(bt709_exports, {
|
|
120754
|
-
Y: () => Y
|
|
120755
|
-
x: () => x
|
|
120756
|
-
y: () => y
|
|
120081
|
+
Y: () => Y,
|
|
120082
|
+
x: () => x,
|
|
120083
|
+
y: () => y
|
|
120757
120084
|
});
|
|
120758
|
-
var Y
|
|
120085
|
+
var Y = /* @__PURE__ */ ((Y2) => {
|
|
120759
120086
|
Y2[Y2["RED"] = 0.2126] = "RED";
|
|
120760
120087
|
Y2[Y2["GREEN"] = 0.7152] = "GREEN";
|
|
120761
120088
|
Y2[Y2["BLUE"] = 0.0722] = "BLUE";
|
|
120762
120089
|
Y2[Y2["WHITE"] = 1] = "WHITE";
|
|
120763
120090
|
return Y2;
|
|
120764
|
-
})(Y
|
|
120765
|
-
var x
|
|
120091
|
+
})(Y || {});
|
|
120092
|
+
var x = /* @__PURE__ */ ((x2) => {
|
|
120766
120093
|
x2[x2["RED"] = 0.64] = "RED";
|
|
120767
120094
|
x2[x2["GREEN"] = 0.3] = "GREEN";
|
|
120768
120095
|
x2[x2["BLUE"] = 0.15] = "BLUE";
|
|
120769
120096
|
x2[x2["WHITE"] = 0.3127] = "WHITE";
|
|
120770
120097
|
return x2;
|
|
120771
|
-
})(x
|
|
120772
|
-
var y
|
|
120098
|
+
})(x || {});
|
|
120099
|
+
var y = /* @__PURE__ */ ((y2) => {
|
|
120773
120100
|
y2[y2["RED"] = 0.33] = "RED";
|
|
120774
120101
|
y2[y2["GREEN"] = 0.6] = "GREEN";
|
|
120775
120102
|
y2[y2["BLUE"] = 0.06] = "BLUE";
|
|
120776
120103
|
y2[y2["WHITE"] = 0.329] = "WHITE";
|
|
120777
120104
|
return y2;
|
|
120778
|
-
})(y
|
|
120105
|
+
})(y || {});
|
|
120779
120106
|
|
|
120780
120107
|
// src/conversion/index.ts
|
|
120781
120108
|
var conversion_exports = {};
|
|
@@ -147071,1094 +146398,1420 @@ const decodeQRCodeFromFile = async (filePath) => {
|
|
|
147071
146398
|
return decodedString;
|
|
147072
146399
|
};
|
|
147073
146400
|
|
|
146401
|
+
//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth
|
|
146402
|
+
//! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes
|
|
147074
146403
|
/// <reference types="./otpauth.d.ts" />
|
|
146404
|
+
// @ts-nocheck
|
|
147075
146405
|
/**
|
|
147076
|
-
* Converts an integer to an
|
|
146406
|
+
* Converts an integer to an Uint8Array.
|
|
147077
146407
|
* @param {number} num Integer.
|
|
147078
|
-
* @returns {
|
|
147079
|
-
*/
|
|
147080
|
-
const
|
|
147081
|
-
|
|
147082
|
-
|
|
147083
|
-
|
|
147084
|
-
|
|
147085
|
-
|
|
147086
|
-
|
|
147087
|
-
|
|
147088
|
-
|
|
147089
|
-
|
|
147090
|
-
return buf;
|
|
146408
|
+
* @returns {Uint8Array} Uint8Array.
|
|
146409
|
+
*/ const uintDecode = (num)=>{
|
|
146410
|
+
const buf = new ArrayBuffer(8);
|
|
146411
|
+
const arr = new Uint8Array(buf);
|
|
146412
|
+
let acc = num;
|
|
146413
|
+
for(let i = 7; i >= 0; i--){
|
|
146414
|
+
if (acc === 0) break;
|
|
146415
|
+
arr[i] = acc & 255;
|
|
146416
|
+
acc -= arr[i];
|
|
146417
|
+
acc /= 256;
|
|
146418
|
+
}
|
|
146419
|
+
return arr;
|
|
147091
146420
|
};
|
|
147092
146421
|
|
|
146422
|
+
function number(n) {
|
|
146423
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new Error(`positive integer expected, not ${n}`);
|
|
146424
|
+
}
|
|
146425
|
+
// copied from utils
|
|
146426
|
+
function isBytes(a) {
|
|
146427
|
+
return a instanceof Uint8Array || a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array';
|
|
146428
|
+
}
|
|
146429
|
+
function bytes(b, ...lengths) {
|
|
146430
|
+
if (!isBytes(b)) throw new Error('Uint8Array expected');
|
|
146431
|
+
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
146432
|
+
}
|
|
146433
|
+
function hash(h) {
|
|
146434
|
+
if (typeof h !== 'function' || typeof h.create !== 'function') throw new Error('Hash should be wrapped by utils.wrapConstructor');
|
|
146435
|
+
number(h.outputLen);
|
|
146436
|
+
number(h.blockLen);
|
|
146437
|
+
}
|
|
146438
|
+
function exists(instance, checkFinished = true) {
|
|
146439
|
+
if (instance.destroyed) throw new Error('Hash instance has been destroyed');
|
|
146440
|
+
if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
|
|
146441
|
+
}
|
|
146442
|
+
function output(out, instance) {
|
|
146443
|
+
bytes(out);
|
|
146444
|
+
const min = instance.outputLen;
|
|
146445
|
+
if (out.length < min) {
|
|
146446
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
146447
|
+
}
|
|
146448
|
+
}
|
|
146449
|
+
|
|
146450
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
146451
|
+
// node.js versions earlier than v19 don't declare it in global scope.
|
|
146452
|
+
// For node.js, package.json#exports field mapping rewrites import
|
|
146453
|
+
// from `crypto` to `cryptoNode`, which imports native module.
|
|
146454
|
+
// Makes the utils un-importable in browsers without a bundler.
|
|
146455
|
+
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
|
146456
|
+
const u32 = (arr)=>new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
146457
|
+
// Cast array to view
|
|
146458
|
+
const createView = (arr)=>new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
146459
|
+
// The rotate right (circular right shift) operation for uint32
|
|
146460
|
+
const rotr = (word, shift)=>word << 32 - shift | word >>> shift;
|
|
146461
|
+
// The rotate left (circular left shift) operation for uint32
|
|
146462
|
+
const rotl = (word, shift)=>word << shift | word >>> 32 - shift >>> 0;
|
|
146463
|
+
const isLE = new Uint8Array(new Uint32Array([
|
|
146464
|
+
0x11223344
|
|
146465
|
+
]).buffer)[0] === 0x44;
|
|
146466
|
+
// The byte swap operation for uint32
|
|
146467
|
+
const byteSwap = (word)=>word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff;
|
|
146468
|
+
// In place byte swap for Uint32Array
|
|
146469
|
+
function byteSwap32(arr) {
|
|
146470
|
+
for(let i = 0; i < arr.length; i++){
|
|
146471
|
+
arr[i] = byteSwap(arr[i]);
|
|
146472
|
+
}
|
|
146473
|
+
}
|
|
147093
146474
|
/**
|
|
147094
|
-
*
|
|
147095
|
-
|
|
147096
|
-
|
|
147097
|
-
|
|
147098
|
-
* Distributed under the BSD License
|
|
147099
|
-
* See http://caligatio.github.com/jsSHA/ for more information
|
|
147100
|
-
*/
|
|
147101
|
-
const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
147102
|
-
n = "ARRAYBUFFER not supported by this environment",
|
|
147103
|
-
e = "UINT8ARRAY not supported by this environment";
|
|
147104
|
-
function r(t, n, e, r) {
|
|
147105
|
-
let i, s, o;
|
|
147106
|
-
const h = n || [0],
|
|
147107
|
-
u = (e = e || 0) >>> 3,
|
|
147108
|
-
w = -1 === r ? 3 : 0;
|
|
147109
|
-
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));
|
|
147110
|
-
return {
|
|
147111
|
-
value: h,
|
|
147112
|
-
binLen: 8 * t.length + e
|
|
147113
|
-
};
|
|
146475
|
+
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
146476
|
+
*/ function utf8ToBytes(str) {
|
|
146477
|
+
if (typeof str !== 'string') throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
146478
|
+
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
147114
146479
|
}
|
|
147115
|
-
|
|
147116
|
-
|
|
147117
|
-
|
|
147118
|
-
|
|
147119
|
-
|
|
147120
|
-
|
|
147121
|
-
|
|
147122
|
-
|
|
147123
|
-
|
|
147124
|
-
|
|
147125
|
-
|
|
147126
|
-
|
|
147127
|
-
|
|
147128
|
-
|
|
147129
|
-
|
|
147130
|
-
|
|
147131
|
-
|
|
147132
|
-
|
|
147133
|
-
|
|
147134
|
-
|
|
147135
|
-
|
|
147136
|
-
|
|
147137
|
-
|
|
147138
|
-
|
|
147139
|
-
|
|
147140
|
-
|
|
147141
|
-
|
|
147142
|
-
|
|
147143
|
-
|
|
147144
|
-
|
|
147145
|
-
|
|
147146
|
-
|
|
147147
|
-
|
|
147148
|
-
|
|
147149
|
-
|
|
147150
|
-
|
|
147151
|
-
|
|
147152
|
-
|
|
147153
|
-
|
|
147154
|
-
|
|
147155
|
-
|
|
147156
|
-
|
|
147157
|
-
|
|
147158
|
-
|
|
147159
|
-
|
|
147160
|
-
|
|
147161
|
-
|
|
147162
|
-
|
|
147163
|
-
|
|
147164
|
-
|
|
147165
|
-
|
|
147166
|
-
|
|
147167
|
-
|
|
147168
|
-
|
|
147169
|
-
|
|
147170
|
-
|
|
147171
|
-
|
|
147172
|
-
|
|
147173
|
-
|
|
147174
|
-
|
|
147175
|
-
|
|
147176
|
-
|
|
147177
|
-
|
|
147178
|
-
|
|
147179
|
-
|
|
147180
|
-
|
|
147181
|
-
|
|
147182
|
-
|
|
147183
|
-
|
|
147184
|
-
|
|
147185
|
-
|
|
147186
|
-
|
|
147187
|
-
|
|
147188
|
-
|
|
147189
|
-
|
|
147190
|
-
|
|
147191
|
-
|
|
147192
|
-
|
|
146480
|
+
/**
|
|
146481
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
146482
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
146483
|
+
* Keep in mind for future mutable operations.
|
|
146484
|
+
*/ function toBytes(data) {
|
|
146485
|
+
if (typeof data === 'string') data = utf8ToBytes(data);
|
|
146486
|
+
bytes(data);
|
|
146487
|
+
return data;
|
|
146488
|
+
}
|
|
146489
|
+
// For runtime check if class implements interface
|
|
146490
|
+
class Hash {
|
|
146491
|
+
// Safe version that clones internal state
|
|
146492
|
+
clone() {
|
|
146493
|
+
return this._cloneInto();
|
|
146494
|
+
}
|
|
146495
|
+
}
|
|
146496
|
+
function wrapConstructor(hashCons) {
|
|
146497
|
+
const hashC = (msg)=>hashCons().update(toBytes(msg)).digest();
|
|
146498
|
+
const tmp = hashCons();
|
|
146499
|
+
hashC.outputLen = tmp.outputLen;
|
|
146500
|
+
hashC.blockLen = tmp.blockLen;
|
|
146501
|
+
hashC.create = ()=>hashCons();
|
|
146502
|
+
return hashC;
|
|
146503
|
+
}
|
|
146504
|
+
|
|
146505
|
+
// HMAC (RFC 2104)
|
|
146506
|
+
class HMAC extends Hash {
|
|
146507
|
+
update(buf) {
|
|
146508
|
+
exists(this);
|
|
146509
|
+
this.iHash.update(buf);
|
|
146510
|
+
return this;
|
|
146511
|
+
}
|
|
146512
|
+
digestInto(out) {
|
|
146513
|
+
exists(this);
|
|
146514
|
+
bytes(out, this.outputLen);
|
|
146515
|
+
this.finished = true;
|
|
146516
|
+
this.iHash.digestInto(out);
|
|
146517
|
+
this.oHash.update(out);
|
|
146518
|
+
this.oHash.digestInto(out);
|
|
146519
|
+
this.destroy();
|
|
146520
|
+
}
|
|
146521
|
+
digest() {
|
|
146522
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
146523
|
+
this.digestInto(out);
|
|
146524
|
+
return out;
|
|
146525
|
+
}
|
|
146526
|
+
_cloneInto(to) {
|
|
146527
|
+
// Create new instance without calling constructor since key already in state and we don't know it.
|
|
146528
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
146529
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
146530
|
+
to = to;
|
|
146531
|
+
to.finished = finished;
|
|
146532
|
+
to.destroyed = destroyed;
|
|
146533
|
+
to.blockLen = blockLen;
|
|
146534
|
+
to.outputLen = outputLen;
|
|
146535
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
146536
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
146537
|
+
return to;
|
|
146538
|
+
}
|
|
146539
|
+
destroy() {
|
|
146540
|
+
this.destroyed = true;
|
|
146541
|
+
this.oHash.destroy();
|
|
146542
|
+
this.iHash.destroy();
|
|
146543
|
+
}
|
|
146544
|
+
constructor(hash$1, _key){
|
|
146545
|
+
super();
|
|
146546
|
+
this.finished = false;
|
|
146547
|
+
this.destroyed = false;
|
|
146548
|
+
hash(hash$1);
|
|
146549
|
+
const key = toBytes(_key);
|
|
146550
|
+
this.iHash = hash$1.create();
|
|
146551
|
+
if (typeof this.iHash.update !== 'function') throw new Error('Expected instance of class which extends utils.Hash');
|
|
146552
|
+
this.blockLen = this.iHash.blockLen;
|
|
146553
|
+
this.outputLen = this.iHash.outputLen;
|
|
146554
|
+
const blockLen = this.blockLen;
|
|
146555
|
+
const pad = new Uint8Array(blockLen);
|
|
146556
|
+
// blockLen can be bigger than outputLen
|
|
146557
|
+
pad.set(key.length > blockLen ? hash$1.create().update(key).digest() : key);
|
|
146558
|
+
for(let i = 0; i < pad.length; i++)pad[i] ^= 0x36;
|
|
146559
|
+
this.iHash.update(pad);
|
|
146560
|
+
// By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
|
|
146561
|
+
this.oHash = hash$1.create();
|
|
146562
|
+
// Undo internal XOR && apply outer XOR
|
|
146563
|
+
for(let i = 0; i < pad.length; i++)pad[i] ^= 0x36 ^ 0x5c;
|
|
146564
|
+
this.oHash.update(pad);
|
|
146565
|
+
pad.fill(0);
|
|
146566
|
+
}
|
|
146567
|
+
}
|
|
146568
|
+
/**
|
|
146569
|
+
* HMAC: RFC2104 message authentication code.
|
|
146570
|
+
* @param hash - function that would be used e.g. sha256
|
|
146571
|
+
* @param key - message key
|
|
146572
|
+
* @param message - message data
|
|
146573
|
+
*/ const hmac = (hash, key, message)=>new HMAC(hash, key).update(message).digest();
|
|
146574
|
+
hmac.create = (hash, key)=>new HMAC(hash, key);
|
|
146575
|
+
|
|
146576
|
+
// Polyfill for Safari 14
|
|
146577
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
146578
|
+
if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE);
|
|
146579
|
+
const _32n = BigInt(32);
|
|
146580
|
+
const _u32_max = BigInt(0xffffffff);
|
|
146581
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
146582
|
+
const wl = Number(value & _u32_max);
|
|
146583
|
+
const h = isLE ? 4 : 0;
|
|
146584
|
+
const l = isLE ? 0 : 4;
|
|
146585
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
146586
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
146587
|
+
}
|
|
146588
|
+
// Choice: a ? b : c
|
|
146589
|
+
const Chi = (a, b, c)=>a & b ^ ~a & c;
|
|
146590
|
+
// Majority function, true if any two inpust is true
|
|
146591
|
+
const Maj = (a, b, c)=>a & b ^ a & c ^ b & c;
|
|
146592
|
+
/**
|
|
146593
|
+
* Merkle-Damgard hash construction base class.
|
|
146594
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
146595
|
+
*/ class HashMD extends Hash {
|
|
146596
|
+
update(data) {
|
|
146597
|
+
exists(this);
|
|
146598
|
+
const { view, buffer, blockLen } = this;
|
|
146599
|
+
data = toBytes(data);
|
|
146600
|
+
const len = data.length;
|
|
146601
|
+
for(let pos = 0; pos < len;){
|
|
146602
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
146603
|
+
// Fast path: we have at least one block in input, cast it to view and process
|
|
146604
|
+
if (take === blockLen) {
|
|
146605
|
+
const dataView = createView(data);
|
|
146606
|
+
for(; blockLen <= len - pos; pos += blockLen)this.process(dataView, pos);
|
|
146607
|
+
continue;
|
|
147193
146608
|
}
|
|
147194
|
-
|
|
147195
|
-
|
|
147196
|
-
|
|
147197
|
-
|
|
147198
|
-
|
|
147199
|
-
|
|
147200
|
-
|
|
147201
|
-
|
|
147202
|
-
|
|
147203
|
-
|
|
147204
|
-
|
|
147205
|
-
|
|
147206
|
-
|
|
147207
|
-
|
|
147208
|
-
|
|
147209
|
-
|
|
147210
|
-
|
|
147211
|
-
|
|
147212
|
-
|
|
147213
|
-
|
|
147214
|
-
|
|
147215
|
-
|
|
147216
|
-
|
|
147217
|
-
|
|
147218
|
-
|
|
147219
|
-
|
|
147220
|
-
|
|
147221
|
-
|
|
147222
|
-
|
|
147223
|
-
|
|
147224
|
-
|
|
147225
|
-
|
|
147226
|
-
|
|
147227
|
-
|
|
147228
|
-
|
|
147229
|
-
|
|
147230
|
-
|
|
147231
|
-
|
|
147232
|
-
|
|
147233
|
-
|
|
147234
|
-
|
|
147235
|
-
|
|
147236
|
-
|
|
147237
|
-
|
|
147238
|
-
|
|
147239
|
-
|
|
147240
|
-
|
|
147241
|
-
|
|
147242
|
-
|
|
147243
|
-
|
|
147244
|
-
|
|
147245
|
-
|
|
147246
|
-
|
|
147247
|
-
|
|
147248
|
-
|
|
147249
|
-
|
|
147250
|
-
|
|
147251
|
-
|
|
147252
|
-
|
|
147253
|
-
|
|
147254
|
-
|
|
147255
|
-
|
|
147256
|
-
return
|
|
147257
|
-
|
|
147258
|
-
|
|
147259
|
-
|
|
147260
|
-
|
|
147261
|
-
|
|
147262
|
-
|
|
147263
|
-
|
|
147264
|
-
|
|
147265
|
-
|
|
147266
|
-
|
|
147267
|
-
|
|
147268
|
-
|
|
147269
|
-
|
|
147270
|
-
|
|
147271
|
-
|
|
147272
|
-
|
|
147273
|
-
|
|
147274
|
-
|
|
147275
|
-
|
|
147276
|
-
|
|
147277
|
-
|
|
147278
|
-
|
|
147279
|
-
|
|
147280
|
-
|
|
147281
|
-
|
|
147282
|
-
|
|
147283
|
-
|
|
147284
|
-
|
|
147285
|
-
|
|
147286
|
-
|
|
147287
|
-
|
|
147288
|
-
return
|
|
147289
|
-
|
|
147290
|
-
|
|
147291
|
-
|
|
147292
|
-
|
|
147293
|
-
|
|
147294
|
-
|
|
147295
|
-
|
|
147296
|
-
|
|
147297
|
-
|
|
147298
|
-
|
|
147299
|
-
|
|
147300
|
-
|
|
147301
|
-
|
|
147302
|
-
|
|
147303
|
-
|
|
147304
|
-
|
|
147305
|
-
|
|
147306
|
-
|
|
147307
|
-
|
|
147308
|
-
|
|
147309
|
-
|
|
147310
|
-
|
|
147311
|
-
|
|
147312
|
-
|
|
147313
|
-
|
|
147314
|
-
|
|
147315
|
-
|
|
147316
|
-
|
|
147317
|
-
|
|
147318
|
-
|
|
147319
|
-
|
|
147320
|
-
|
|
147321
|
-
|
|
147322
|
-
|
|
147323
|
-
|
|
147324
|
-
|
|
147325
|
-
|
|
147326
|
-
|
|
147327
|
-
|
|
147328
|
-
|
|
147329
|
-
|
|
147330
|
-
|
|
147331
|
-
|
|
147332
|
-
|
|
147333
|
-
|
|
147334
|
-
|
|
146609
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
146610
|
+
this.pos += take;
|
|
146611
|
+
pos += take;
|
|
146612
|
+
if (this.pos === blockLen) {
|
|
146613
|
+
this.process(view, 0);
|
|
146614
|
+
this.pos = 0;
|
|
146615
|
+
}
|
|
146616
|
+
}
|
|
146617
|
+
this.length += data.length;
|
|
146618
|
+
this.roundClean();
|
|
146619
|
+
return this;
|
|
146620
|
+
}
|
|
146621
|
+
digestInto(out) {
|
|
146622
|
+
exists(this);
|
|
146623
|
+
output(out, this);
|
|
146624
|
+
this.finished = true;
|
|
146625
|
+
// Padding
|
|
146626
|
+
// We can avoid allocation of buffer for padding completely if it
|
|
146627
|
+
// was previously not allocated here. But it won't change performance.
|
|
146628
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
146629
|
+
let { pos } = this;
|
|
146630
|
+
// append the bit '1' to the message
|
|
146631
|
+
buffer[pos++] = 0b10000000;
|
|
146632
|
+
this.buffer.subarray(pos).fill(0);
|
|
146633
|
+
// we have less than padOffset left in buffer, so we cannot put length in
|
|
146634
|
+
// current block, need process it and pad again
|
|
146635
|
+
if (this.padOffset > blockLen - pos) {
|
|
146636
|
+
this.process(view, 0);
|
|
146637
|
+
pos = 0;
|
|
146638
|
+
}
|
|
146639
|
+
// Pad until full block byte with zeros
|
|
146640
|
+
for(let i = pos; i < blockLen; i++)buffer[i] = 0;
|
|
146641
|
+
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
146642
|
+
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
146643
|
+
// So we just write lowest 64 bits of that value.
|
|
146644
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
146645
|
+
this.process(view, 0);
|
|
146646
|
+
const oview = createView(out);
|
|
146647
|
+
const len = this.outputLen;
|
|
146648
|
+
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
|
146649
|
+
if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');
|
|
146650
|
+
const outLen = len / 4;
|
|
146651
|
+
const state = this.get();
|
|
146652
|
+
if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');
|
|
146653
|
+
for(let i = 0; i < outLen; i++)oview.setUint32(4 * i, state[i], isLE);
|
|
146654
|
+
}
|
|
146655
|
+
digest() {
|
|
146656
|
+
const { buffer, outputLen } = this;
|
|
146657
|
+
this.digestInto(buffer);
|
|
146658
|
+
const res = buffer.slice(0, outputLen);
|
|
146659
|
+
this.destroy();
|
|
146660
|
+
return res;
|
|
146661
|
+
}
|
|
146662
|
+
_cloneInto(to) {
|
|
146663
|
+
to || (to = new this.constructor());
|
|
146664
|
+
to.set(...this.get());
|
|
146665
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
146666
|
+
to.length = length;
|
|
146667
|
+
to.pos = pos;
|
|
146668
|
+
to.finished = finished;
|
|
146669
|
+
to.destroyed = destroyed;
|
|
146670
|
+
if (length % blockLen) to.buffer.set(buffer);
|
|
146671
|
+
return to;
|
|
146672
|
+
}
|
|
146673
|
+
constructor(blockLen, outputLen, padOffset, isLE){
|
|
146674
|
+
super();
|
|
146675
|
+
this.blockLen = blockLen;
|
|
146676
|
+
this.outputLen = outputLen;
|
|
146677
|
+
this.padOffset = padOffset;
|
|
146678
|
+
this.isLE = isLE;
|
|
146679
|
+
this.finished = false;
|
|
146680
|
+
this.length = 0;
|
|
146681
|
+
this.pos = 0;
|
|
146682
|
+
this.destroyed = false;
|
|
146683
|
+
this.buffer = new Uint8Array(blockLen);
|
|
146684
|
+
this.view = createView(this.buffer);
|
|
146685
|
+
}
|
|
146686
|
+
}
|
|
146687
|
+
|
|
146688
|
+
// SHA1 (RFC 3174) was cryptographically broken. It's still used. Don't use it for a new protocol.
|
|
146689
|
+
// Initial state
|
|
146690
|
+
const SHA1_IV = /* @__PURE__ */ new Uint32Array([
|
|
146691
|
+
0x67452301,
|
|
146692
|
+
0xefcdab89,
|
|
146693
|
+
0x98badcfe,
|
|
146694
|
+
0x10325476,
|
|
146695
|
+
0xc3d2e1f0
|
|
146696
|
+
]);
|
|
146697
|
+
// Temporary buffer, not used to store anything between runs
|
|
146698
|
+
// Named this way because it matches specification.
|
|
146699
|
+
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
|
|
146700
|
+
class SHA1 extends HashMD {
|
|
146701
|
+
get() {
|
|
146702
|
+
const { A, B, C, D, E } = this;
|
|
146703
|
+
return [
|
|
146704
|
+
A,
|
|
146705
|
+
B,
|
|
146706
|
+
C,
|
|
146707
|
+
D,
|
|
146708
|
+
E
|
|
146709
|
+
];
|
|
146710
|
+
}
|
|
146711
|
+
set(A, B, C, D, E) {
|
|
146712
|
+
this.A = A | 0;
|
|
146713
|
+
this.B = B | 0;
|
|
146714
|
+
this.C = C | 0;
|
|
146715
|
+
this.D = D | 0;
|
|
146716
|
+
this.E = E | 0;
|
|
146717
|
+
}
|
|
146718
|
+
process(view, offset) {
|
|
146719
|
+
for(let i = 0; i < 16; i++, offset += 4)SHA1_W[i] = view.getUint32(offset, false);
|
|
146720
|
+
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);
|
|
146721
|
+
// Compression function main loop, 80 rounds
|
|
146722
|
+
let { A, B, C, D, E } = this;
|
|
146723
|
+
for(let i = 0; i < 80; i++){
|
|
146724
|
+
let F, K;
|
|
146725
|
+
if (i < 20) {
|
|
146726
|
+
F = Chi(B, C, D);
|
|
146727
|
+
K = 0x5a827999;
|
|
146728
|
+
} else if (i < 40) {
|
|
146729
|
+
F = B ^ C ^ D;
|
|
146730
|
+
K = 0x6ed9eba1;
|
|
146731
|
+
} else if (i < 60) {
|
|
146732
|
+
F = Maj(B, C, D);
|
|
146733
|
+
K = 0x8f1bbcdc;
|
|
146734
|
+
} else {
|
|
146735
|
+
F = B ^ C ^ D;
|
|
146736
|
+
K = 0xca62c1d6;
|
|
146737
|
+
}
|
|
146738
|
+
const T = rotl(A, 5) + F + E + K + SHA1_W[i] | 0;
|
|
146739
|
+
E = D;
|
|
146740
|
+
D = C;
|
|
146741
|
+
C = rotl(B, 30);
|
|
146742
|
+
B = A;
|
|
146743
|
+
A = T;
|
|
146744
|
+
}
|
|
146745
|
+
// Add the compressed chunk to the current hash value
|
|
146746
|
+
A = A + this.A | 0;
|
|
146747
|
+
B = B + this.B | 0;
|
|
146748
|
+
C = C + this.C | 0;
|
|
146749
|
+
D = D + this.D | 0;
|
|
146750
|
+
E = E + this.E | 0;
|
|
146751
|
+
this.set(A, B, C, D, E);
|
|
146752
|
+
}
|
|
146753
|
+
roundClean() {
|
|
146754
|
+
SHA1_W.fill(0);
|
|
146755
|
+
}
|
|
146756
|
+
destroy() {
|
|
146757
|
+
this.set(0, 0, 0, 0, 0);
|
|
146758
|
+
this.buffer.fill(0);
|
|
146759
|
+
}
|
|
146760
|
+
constructor(){
|
|
146761
|
+
super(64, 20, 8, false);
|
|
146762
|
+
this.A = SHA1_IV[0] | 0;
|
|
146763
|
+
this.B = SHA1_IV[1] | 0;
|
|
146764
|
+
this.C = SHA1_IV[2] | 0;
|
|
146765
|
+
this.D = SHA1_IV[3] | 0;
|
|
146766
|
+
this.E = SHA1_IV[4] | 0;
|
|
146767
|
+
}
|
|
146768
|
+
}
|
|
146769
|
+
const sha1 = /* @__PURE__ */ wrapConstructor(()=>new SHA1());
|
|
146770
|
+
|
|
146771
|
+
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
|
146772
|
+
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
|
146773
|
+
// Round constants:
|
|
146774
|
+
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
146775
|
+
// prettier-ignore
|
|
146776
|
+
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
146777
|
+
0x428a2f98,
|
|
146778
|
+
0x71374491,
|
|
146779
|
+
0xb5c0fbcf,
|
|
146780
|
+
0xe9b5dba5,
|
|
146781
|
+
0x3956c25b,
|
|
146782
|
+
0x59f111f1,
|
|
146783
|
+
0x923f82a4,
|
|
146784
|
+
0xab1c5ed5,
|
|
146785
|
+
0xd807aa98,
|
|
146786
|
+
0x12835b01,
|
|
146787
|
+
0x243185be,
|
|
146788
|
+
0x550c7dc3,
|
|
146789
|
+
0x72be5d74,
|
|
146790
|
+
0x80deb1fe,
|
|
146791
|
+
0x9bdc06a7,
|
|
146792
|
+
0xc19bf174,
|
|
146793
|
+
0xe49b69c1,
|
|
146794
|
+
0xefbe4786,
|
|
146795
|
+
0x0fc19dc6,
|
|
146796
|
+
0x240ca1cc,
|
|
146797
|
+
0x2de92c6f,
|
|
146798
|
+
0x4a7484aa,
|
|
146799
|
+
0x5cb0a9dc,
|
|
146800
|
+
0x76f988da,
|
|
146801
|
+
0x983e5152,
|
|
146802
|
+
0xa831c66d,
|
|
146803
|
+
0xb00327c8,
|
|
146804
|
+
0xbf597fc7,
|
|
146805
|
+
0xc6e00bf3,
|
|
146806
|
+
0xd5a79147,
|
|
146807
|
+
0x06ca6351,
|
|
146808
|
+
0x14292967,
|
|
146809
|
+
0x27b70a85,
|
|
146810
|
+
0x2e1b2138,
|
|
146811
|
+
0x4d2c6dfc,
|
|
146812
|
+
0x53380d13,
|
|
146813
|
+
0x650a7354,
|
|
146814
|
+
0x766a0abb,
|
|
146815
|
+
0x81c2c92e,
|
|
146816
|
+
0x92722c85,
|
|
146817
|
+
0xa2bfe8a1,
|
|
146818
|
+
0xa81a664b,
|
|
146819
|
+
0xc24b8b70,
|
|
146820
|
+
0xc76c51a3,
|
|
146821
|
+
0xd192e819,
|
|
146822
|
+
0xd6990624,
|
|
146823
|
+
0xf40e3585,
|
|
146824
|
+
0x106aa070,
|
|
146825
|
+
0x19a4c116,
|
|
146826
|
+
0x1e376c08,
|
|
146827
|
+
0x2748774c,
|
|
146828
|
+
0x34b0bcb5,
|
|
146829
|
+
0x391c0cb3,
|
|
146830
|
+
0x4ed8aa4a,
|
|
146831
|
+
0x5b9cca4f,
|
|
146832
|
+
0x682e6ff3,
|
|
146833
|
+
0x748f82ee,
|
|
146834
|
+
0x78a5636f,
|
|
146835
|
+
0x84c87814,
|
|
146836
|
+
0x8cc70208,
|
|
146837
|
+
0x90befffa,
|
|
146838
|
+
0xa4506ceb,
|
|
146839
|
+
0xbef9a3f7,
|
|
146840
|
+
0xc67178f2
|
|
146841
|
+
]);
|
|
146842
|
+
// Initial state:
|
|
146843
|
+
// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
|
|
146844
|
+
// prettier-ignore
|
|
146845
|
+
const SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
146846
|
+
0x6a09e667,
|
|
146847
|
+
0xbb67ae85,
|
|
146848
|
+
0x3c6ef372,
|
|
146849
|
+
0xa54ff53a,
|
|
146850
|
+
0x510e527f,
|
|
146851
|
+
0x9b05688c,
|
|
146852
|
+
0x1f83d9ab,
|
|
146853
|
+
0x5be0cd19
|
|
146854
|
+
]);
|
|
146855
|
+
// Temporary buffer, not used to store anything between runs
|
|
146856
|
+
// Named this way because it matches specification.
|
|
146857
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
146858
|
+
class SHA256 extends HashMD {
|
|
146859
|
+
get() {
|
|
146860
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
146861
|
+
return [
|
|
146862
|
+
A,
|
|
146863
|
+
B,
|
|
146864
|
+
C,
|
|
146865
|
+
D,
|
|
146866
|
+
E,
|
|
146867
|
+
F,
|
|
146868
|
+
G,
|
|
146869
|
+
H
|
|
146870
|
+
];
|
|
146871
|
+
}
|
|
146872
|
+
// prettier-ignore
|
|
146873
|
+
set(A, B, C, D, E, F, G, H) {
|
|
146874
|
+
this.A = A | 0;
|
|
146875
|
+
this.B = B | 0;
|
|
146876
|
+
this.C = C | 0;
|
|
146877
|
+
this.D = D | 0;
|
|
146878
|
+
this.E = E | 0;
|
|
146879
|
+
this.F = F | 0;
|
|
146880
|
+
this.G = G | 0;
|
|
146881
|
+
this.H = H | 0;
|
|
146882
|
+
}
|
|
146883
|
+
process(view, offset) {
|
|
146884
|
+
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
146885
|
+
for(let i = 0; i < 16; i++, offset += 4)SHA256_W[i] = view.getUint32(offset, false);
|
|
146886
|
+
for(let i = 16; i < 64; i++){
|
|
146887
|
+
const W15 = SHA256_W[i - 15];
|
|
146888
|
+
const W2 = SHA256_W[i - 2];
|
|
146889
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
146890
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
146891
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
146892
|
+
}
|
|
146893
|
+
// Compression function main loop, 64 rounds
|
|
146894
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
146895
|
+
for(let i = 0; i < 64; i++){
|
|
146896
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
146897
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
146898
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
146899
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
146900
|
+
H = G;
|
|
146901
|
+
G = F;
|
|
146902
|
+
F = E;
|
|
146903
|
+
E = D + T1 | 0;
|
|
146904
|
+
D = C;
|
|
146905
|
+
C = B;
|
|
146906
|
+
B = A;
|
|
146907
|
+
A = T1 + T2 | 0;
|
|
146908
|
+
}
|
|
146909
|
+
// Add the compressed chunk to the current hash value
|
|
146910
|
+
A = A + this.A | 0;
|
|
146911
|
+
B = B + this.B | 0;
|
|
146912
|
+
C = C + this.C | 0;
|
|
146913
|
+
D = D + this.D | 0;
|
|
146914
|
+
E = E + this.E | 0;
|
|
146915
|
+
F = F + this.F | 0;
|
|
146916
|
+
G = G + this.G | 0;
|
|
146917
|
+
H = H + this.H | 0;
|
|
146918
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
146919
|
+
}
|
|
146920
|
+
roundClean() {
|
|
146921
|
+
SHA256_W.fill(0);
|
|
146922
|
+
}
|
|
146923
|
+
destroy() {
|
|
146924
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
146925
|
+
this.buffer.fill(0);
|
|
146926
|
+
}
|
|
146927
|
+
constructor(){
|
|
146928
|
+
super(64, 32, 8, false);
|
|
146929
|
+
// We cannot use array here since array allows indexing by variable
|
|
146930
|
+
// which means optimizer/compiler cannot use registers.
|
|
146931
|
+
this.A = SHA256_IV[0] | 0;
|
|
146932
|
+
this.B = SHA256_IV[1] | 0;
|
|
146933
|
+
this.C = SHA256_IV[2] | 0;
|
|
146934
|
+
this.D = SHA256_IV[3] | 0;
|
|
146935
|
+
this.E = SHA256_IV[4] | 0;
|
|
146936
|
+
this.F = SHA256_IV[5] | 0;
|
|
146937
|
+
this.G = SHA256_IV[6] | 0;
|
|
146938
|
+
this.H = SHA256_IV[7] | 0;
|
|
146939
|
+
}
|
|
146940
|
+
}
|
|
146941
|
+
// Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
|
146942
|
+
class SHA224 extends SHA256 {
|
|
146943
|
+
constructor(){
|
|
146944
|
+
super();
|
|
146945
|
+
this.A = 0xc1059ed8 | 0;
|
|
146946
|
+
this.B = 0x367cd507 | 0;
|
|
146947
|
+
this.C = 0x3070dd17 | 0;
|
|
146948
|
+
this.D = 0xf70e5939 | 0;
|
|
146949
|
+
this.E = 0xffc00b31 | 0;
|
|
146950
|
+
this.F = 0x68581511 | 0;
|
|
146951
|
+
this.G = 0x64f98fa7 | 0;
|
|
146952
|
+
this.H = 0xbefa4fa4 | 0;
|
|
146953
|
+
this.outputLen = 28;
|
|
146954
|
+
}
|
|
146955
|
+
}
|
|
146956
|
+
/**
|
|
146957
|
+
* SHA2-256 hash function
|
|
146958
|
+
* @param message - data that would be hashed
|
|
146959
|
+
*/ const sha256 = /* @__PURE__ */ wrapConstructor(()=>new SHA256());
|
|
146960
|
+
const sha224 = /* @__PURE__ */ wrapConstructor(()=>new SHA224());
|
|
146961
|
+
|
|
146962
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
146963
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
146964
|
+
// We are not using BigUint64Array, because they are extremely slow as per 2022
|
|
146965
|
+
function fromBig(n, le = false) {
|
|
146966
|
+
if (le) return {
|
|
146967
|
+
h: Number(n & U32_MASK64),
|
|
146968
|
+
l: Number(n >> _32n & U32_MASK64)
|
|
146969
|
+
};
|
|
146970
|
+
return {
|
|
146971
|
+
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
146972
|
+
l: Number(n & U32_MASK64) | 0
|
|
147335
146973
|
};
|
|
147336
|
-
}
|
|
147337
|
-
return {
|
|
147338
|
-
value: t.value.concat(n.value),
|
|
147339
|
-
binLen: t.binLen + n.binLen
|
|
147340
|
-
};
|
|
147341
146974
|
}
|
|
147342
|
-
function
|
|
147343
|
-
|
|
147344
|
-
|
|
147345
|
-
|
|
147346
|
-
|
|
147347
|
-
|
|
147348
|
-
|
|
147349
|
-
|
|
147350
|
-
|
|
147351
|
-
|
|
147352
|
-
|
|
147353
|
-
|
|
147354
|
-
|
|
147355
|
-
|
|
147356
|
-
}
|
|
147357
|
-
if ("boolean" != typeof n.outputUpper) throw new Error("Invalid outputUpper formatting option");
|
|
147358
|
-
if ("string" != typeof n.b64Pad) throw new Error("Invalid b64Pad formatting option");
|
|
147359
|
-
return n;
|
|
146975
|
+
function split(lst, le = false) {
|
|
146976
|
+
let Ah = new Uint32Array(lst.length);
|
|
146977
|
+
let Al = new Uint32Array(lst.length);
|
|
146978
|
+
for(let i = 0; i < lst.length; i++){
|
|
146979
|
+
const { h, l } = fromBig(lst[i], le);
|
|
146980
|
+
[Ah[i], Al[i]] = [
|
|
146981
|
+
h,
|
|
146982
|
+
l
|
|
146983
|
+
];
|
|
146984
|
+
}
|
|
146985
|
+
return [
|
|
146986
|
+
Ah,
|
|
146987
|
+
Al
|
|
146988
|
+
];
|
|
147360
146989
|
}
|
|
147361
|
-
|
|
147362
|
-
|
|
147363
|
-
|
|
147364
|
-
|
|
147365
|
-
|
|
147366
|
-
|
|
147367
|
-
|
|
147368
|
-
|
|
146990
|
+
const toBig = (h, l)=>BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
|
|
146991
|
+
// for Shift in [0, 32)
|
|
146992
|
+
const shrSH = (h, _l, s)=>h >>> s;
|
|
146993
|
+
const shrSL = (h, l, s)=>h << 32 - s | l >>> s;
|
|
146994
|
+
// Right rotate for Shift in [1, 32)
|
|
146995
|
+
const rotrSH = (h, l, s)=>h >>> s | l << 32 - s;
|
|
146996
|
+
const rotrSL = (h, l, s)=>h << 32 - s | l >>> s;
|
|
146997
|
+
// Right rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
146998
|
+
const rotrBH = (h, l, s)=>h << 64 - s | l >>> s - 32;
|
|
146999
|
+
const rotrBL = (h, l, s)=>h >>> s - 32 | l << 64 - s;
|
|
147000
|
+
// Right rotate for shift===32 (just swaps l&h)
|
|
147001
|
+
const rotr32H = (_h, l)=>l;
|
|
147002
|
+
const rotr32L = (h, _l)=>h;
|
|
147003
|
+
// Left rotate for Shift in [1, 32)
|
|
147004
|
+
const rotlSH = (h, l, s)=>h << s | l >>> 32 - s;
|
|
147005
|
+
const rotlSL = (h, l, s)=>l << s | h >>> 32 - s;
|
|
147006
|
+
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
147007
|
+
const rotlBH = (h, l, s)=>l << s - 32 | h >>> 64 - s;
|
|
147008
|
+
const rotlBL = (h, l, s)=>h << s - 32 | l >>> 64 - s;
|
|
147009
|
+
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
147010
|
+
// simple take carry out of low bit sum by shift, we need to use division.
|
|
147011
|
+
function add(Ah, Al, Bh, Bl) {
|
|
147012
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
147013
|
+
return {
|
|
147014
|
+
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
147015
|
+
l: l | 0
|
|
147016
|
+
};
|
|
147369
147017
|
}
|
|
147370
|
-
|
|
147371
|
-
|
|
147372
|
-
|
|
147373
|
-
|
|
147374
|
-
|
|
147375
|
-
|
|
147376
|
-
|
|
147377
|
-
|
|
147378
|
-
|
|
147379
|
-
|
|
147380
|
-
|
|
147381
|
-
|
|
147382
|
-
|
|
147383
|
-
|
|
147384
|
-
|
|
147385
|
-
|
|
147386
|
-
|
|
147387
|
-
|
|
147388
|
-
|
|
147389
|
-
|
|
147390
|
-
|
|
147391
|
-
|
|
147392
|
-
|
|
147393
|
-
|
|
147394
|
-
|
|
147395
|
-
|
|
147396
|
-
|
|
147397
|
-
|
|
147398
|
-
|
|
147399
|
-
|
|
147400
|
-
|
|
147401
|
-
setHMACKey(t, n, e) {
|
|
147402
|
-
if (!this.M) throw new Error("Variant does not support HMAC");
|
|
147403
|
-
if (this.l) throw new Error("Cannot set MAC key after calling update");
|
|
147404
|
-
const r = i(n, (e || {}).encoding || "UTF8", this.T);
|
|
147405
|
-
this.k(r(t));
|
|
147406
|
-
}
|
|
147407
|
-
k(t) {
|
|
147408
|
-
const n = this.m >>> 3,
|
|
147409
|
-
e = n / 4 - 1;
|
|
147410
|
-
let r;
|
|
147411
|
-
if (1 !== this.numRounds) throw new Error(f);
|
|
147412
|
-
if (this.H) throw new Error("MAC key already set");
|
|
147413
|
-
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);
|
|
147414
|
-
for (r = 0; r <= e; r += 1) this.S[r] = 909522486 ^ t.value[r], this.p[r] = 1549556828 ^ t.value[r];
|
|
147415
|
-
this.U = this.v(this.S, this.U), this.A = this.m, this.H = !0;
|
|
147416
|
-
}
|
|
147417
|
-
getHMAC(t, n) {
|
|
147418
|
-
const e = l(n);
|
|
147419
|
-
return s(t, this.R, this.T, e)(this.Y());
|
|
147420
|
-
}
|
|
147421
|
-
Y() {
|
|
147422
|
-
let t;
|
|
147423
|
-
if (!this.H) throw new Error("Cannot call getHMAC without first setting MAC key");
|
|
147424
|
-
const n = this.F(this.h.slice(), this.u, this.A, this.L(this.U), this.R);
|
|
147425
|
-
return t = this.v(this.p, this.B(this.o)), t = this.F(n, this.R, this.m, t, this.R), t;
|
|
147426
|
-
}
|
|
147427
|
-
}
|
|
147428
|
-
function H(t, n) {
|
|
147429
|
-
return t << n | t >>> 32 - n;
|
|
147430
|
-
}
|
|
147431
|
-
function S(t, n) {
|
|
147432
|
-
return t >>> n | t << 32 - n;
|
|
147433
|
-
}
|
|
147434
|
-
function b(t, n) {
|
|
147435
|
-
return t >>> n;
|
|
147436
|
-
}
|
|
147437
|
-
function p(t, n, e) {
|
|
147438
|
-
return t ^ n ^ e;
|
|
147439
|
-
}
|
|
147440
|
-
function d(t, n, e) {
|
|
147441
|
-
return t & n ^ ~t & e;
|
|
147442
|
-
}
|
|
147443
|
-
function m(t, n, e) {
|
|
147444
|
-
return t & n ^ t & e ^ n & e;
|
|
147445
|
-
}
|
|
147446
|
-
function C(t) {
|
|
147447
|
-
return S(t, 2) ^ S(t, 13) ^ S(t, 22);
|
|
147448
|
-
}
|
|
147449
|
-
function y(t, n) {
|
|
147450
|
-
const e = (65535 & t) + (65535 & n);
|
|
147451
|
-
return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16)) << 16 | 65535 & e;
|
|
147452
|
-
}
|
|
147453
|
-
function U(t, n, e, r) {
|
|
147454
|
-
const i = (65535 & t) + (65535 & n) + (65535 & e) + (65535 & r);
|
|
147455
|
-
return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16) + (r >>> 16) + (i >>> 16)) << 16 | 65535 & i;
|
|
147456
|
-
}
|
|
147457
|
-
function v(t, n, e, r, i) {
|
|
147458
|
-
const s = (65535 & t) + (65535 & n) + (65535 & e) + (65535 & r) + (65535 & i);
|
|
147459
|
-
return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16) + (r >>> 16) + (i >>> 16) + (s >>> 16)) << 16 | 65535 & s;
|
|
147460
|
-
}
|
|
147461
|
-
function R(t) {
|
|
147462
|
-
return S(t, 7) ^ S(t, 18) ^ b(t, 3);
|
|
147463
|
-
}
|
|
147464
|
-
function K(t) {
|
|
147465
|
-
return S(t, 6) ^ S(t, 11) ^ S(t, 25);
|
|
147466
|
-
}
|
|
147467
|
-
function T(t) {
|
|
147468
|
-
return [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
147469
|
-
}
|
|
147470
|
-
function g(t, n) {
|
|
147471
|
-
let e, r, i, s, o, h, u;
|
|
147472
|
-
const w = [];
|
|
147473
|
-
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;
|
|
147474
|
-
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;
|
|
147475
|
-
}
|
|
147476
|
-
function F(t, n, e, r) {
|
|
147477
|
-
let i;
|
|
147478
|
-
const s = 15 + (n + 65 >>> 9 << 4),
|
|
147479
|
-
h = n + e;
|
|
147480
|
-
for (; t.length <= s;) t.push(0);
|
|
147481
|
-
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);
|
|
147482
|
-
return r;
|
|
147483
|
-
}
|
|
147484
|
-
let L = class extends E {
|
|
147485
|
-
constructor(t, n, e) {
|
|
147486
|
-
if ("SHA-1" !== t) throw new Error(c);
|
|
147487
|
-
super(t, n, e);
|
|
147488
|
-
const r = e || {};
|
|
147489
|
-
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) {
|
|
147490
|
-
return t.slice();
|
|
147491
|
-
}, 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));
|
|
147492
|
-
}
|
|
147018
|
+
// Addition with more than 2 elements
|
|
147019
|
+
const add3L = (Al, Bl, Cl)=>(Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
147020
|
+
const add3H = (low, Ah, Bh, Ch)=>Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
147021
|
+
const add4L = (Al, Bl, Cl, Dl)=>(Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
147022
|
+
const add4H = (low, Ah, Bh, Ch, Dh)=>Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
147023
|
+
const add5L = (Al, Bl, Cl, Dl, El)=>(Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
147024
|
+
const add5H = (low, Ah, Bh, Ch, Dh, Eh)=>Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
147025
|
+
// prettier-ignore
|
|
147026
|
+
const u64 = {
|
|
147027
|
+
fromBig,
|
|
147028
|
+
split,
|
|
147029
|
+
toBig,
|
|
147030
|
+
shrSH,
|
|
147031
|
+
shrSL,
|
|
147032
|
+
rotrSH,
|
|
147033
|
+
rotrSL,
|
|
147034
|
+
rotrBH,
|
|
147035
|
+
rotrBL,
|
|
147036
|
+
rotr32H,
|
|
147037
|
+
rotr32L,
|
|
147038
|
+
rotlSH,
|
|
147039
|
+
rotlSL,
|
|
147040
|
+
rotlBH,
|
|
147041
|
+
rotlBL,
|
|
147042
|
+
add,
|
|
147043
|
+
add3L,
|
|
147044
|
+
add3H,
|
|
147045
|
+
add4L,
|
|
147046
|
+
add4H,
|
|
147047
|
+
add5H,
|
|
147048
|
+
add5L
|
|
147493
147049
|
};
|
|
147494
|
-
|
|
147495
|
-
|
|
147496
|
-
|
|
147497
|
-
|
|
147498
|
-
|
|
147499
|
-
|
|
147500
|
-
|
|
147501
|
-
|
|
147502
|
-
|
|
147503
|
-
|
|
147504
|
-
|
|
147505
|
-
|
|
147506
|
-
|
|
147507
|
-
|
|
147508
|
-
|
|
147509
|
-
|
|
147510
|
-
|
|
147511
|
-
|
|
147512
|
-
|
|
147513
|
-
|
|
147514
|
-
|
|
147515
|
-
|
|
147516
|
-
|
|
147517
|
-
|
|
147518
|
-
|
|
147519
|
-
|
|
147520
|
-
|
|
147521
|
-
|
|
147522
|
-
|
|
147523
|
-
|
|
147524
|
-
|
|
147525
|
-
|
|
147526
|
-
|
|
147527
|
-
|
|
147528
|
-
|
|
147529
|
-
|
|
147530
|
-
|
|
147531
|
-
|
|
147532
|
-
|
|
147533
|
-
|
|
147534
|
-
|
|
147535
|
-
|
|
147536
|
-
|
|
147537
|
-
|
|
147538
|
-
|
|
147539
|
-
|
|
147540
|
-
|
|
147541
|
-
|
|
147542
|
-
|
|
147543
|
-
|
|
147544
|
-
|
|
147545
|
-
|
|
147546
|
-
|
|
147547
|
-
|
|
147548
|
-
|
|
147549
|
-
|
|
147550
|
-
|
|
147551
|
-
|
|
147552
|
-
|
|
147553
|
-
|
|
147554
|
-
|
|
147555
|
-
|
|
147556
|
-
|
|
147557
|
-
|
|
147558
|
-
|
|
147559
|
-
|
|
147560
|
-
|
|
147561
|
-
|
|
147562
|
-
|
|
147563
|
-
|
|
147564
|
-
|
|
147565
|
-
|
|
147566
|
-
|
|
147567
|
-
|
|
147568
|
-
|
|
147569
|
-
|
|
147570
|
-
|
|
147571
|
-
|
|
147572
|
-
|
|
147573
|
-
|
|
147574
|
-
|
|
147575
|
-
|
|
147576
|
-
|
|
147577
|
-
|
|
147578
|
-
|
|
147579
|
-
|
|
147580
|
-
|
|
147581
|
-
|
|
147582
|
-
|
|
147583
|
-
|
|
147584
|
-
|
|
147585
|
-
|
|
147586
|
-
|
|
147587
|
-
|
|
147588
|
-
|
|
147589
|
-
|
|
147590
|
-
|
|
147591
|
-
|
|
147592
|
-
|
|
147593
|
-
|
|
147594
|
-
|
|
147595
|
-
|
|
147596
|
-
|
|
147597
|
-
|
|
147598
|
-
|
|
147599
|
-
|
|
147600
|
-
|
|
147601
|
-
|
|
147602
|
-
|
|
147603
|
-
|
|
147604
|
-
if ("SHA-384" !== t && "SHA-512" !== t) throw new Error(c);
|
|
147605
|
-
super(t, n, e);
|
|
147606
|
-
const r = e || {};
|
|
147607
|
-
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) {
|
|
147608
|
-
return t.slice();
|
|
147609
|
-
}, this.B = G, this.F = function (n, e, r, i) {
|
|
147610
|
-
return function (t, n, e, r, i) {
|
|
147611
|
-
let s, h;
|
|
147612
|
-
const u = 31 + (n + 129 >>> 10 << 5),
|
|
147613
|
-
w = n + e;
|
|
147614
|
-
for (; t.length <= u;) t.push(0);
|
|
147615
|
-
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);
|
|
147616
|
-
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;
|
|
147617
|
-
}(n, e, r, i, t);
|
|
147618
|
-
}, 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));
|
|
147619
|
-
}
|
|
147620
|
-
};
|
|
147621
|
-
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)],
|
|
147622
|
-
$ = [[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]];
|
|
147623
|
-
function tt(t) {
|
|
147624
|
-
let n;
|
|
147625
|
-
const e = [];
|
|
147626
|
-
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)];
|
|
147627
|
-
return e;
|
|
147628
|
-
}
|
|
147629
|
-
function nt(t) {
|
|
147630
|
-
let n;
|
|
147631
|
-
const e = [];
|
|
147632
|
-
for (n = 0; n < 5; n += 1) e[n] = t[n].slice();
|
|
147633
|
-
return e;
|
|
147634
|
-
}
|
|
147635
|
-
function et(t, n) {
|
|
147636
|
-
let e, r, i, s;
|
|
147637
|
-
const o = [],
|
|
147638
|
-
h = [];
|
|
147639
|
-
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]));
|
|
147640
|
-
for (e = 0; e < 24; e += 1) {
|
|
147641
|
-
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));
|
|
147642
|
-
for (r = 0; r < 5; r += 1) h[r] = V(o[(r + 4) % 5], N(o[(r + 1) % 5], 1));
|
|
147643
|
-
for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) n[r][i] = V(n[r][i], h[r]);
|
|
147644
|
-
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]);
|
|
147645
|
-
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));
|
|
147646
|
-
n[0][0] = V(n[0][0], W[e]);
|
|
147647
|
-
}
|
|
147648
|
-
var u, w, c, f, a;
|
|
147649
|
-
return n;
|
|
147650
|
-
}
|
|
147651
|
-
function rt(t) {
|
|
147652
|
-
let n,
|
|
147653
|
-
e,
|
|
147654
|
-
r = 0;
|
|
147655
|
-
const i = [0, 0],
|
|
147656
|
-
s = [4294967295 & t, t / o & 2097151];
|
|
147657
|
-
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);
|
|
147658
|
-
return r = 0 !== r ? r : 1, i[0] |= r, {
|
|
147659
|
-
value: r + 1 > 4 ? i : [i[0]],
|
|
147660
|
-
binLen: 8 + 8 * r
|
|
147661
|
-
};
|
|
147662
|
-
}
|
|
147663
|
-
function it(t) {
|
|
147664
|
-
return a(rt(t.binLen), t);
|
|
147665
|
-
}
|
|
147666
|
-
function st(t, n) {
|
|
147667
|
-
let e,
|
|
147668
|
-
r = rt(n);
|
|
147669
|
-
r = a(r, t);
|
|
147670
|
-
const i = n >>> 2,
|
|
147671
|
-
s = (i - r.value.length % i) % i;
|
|
147672
|
-
for (e = 0; e < s; e++) r.value.push(0);
|
|
147673
|
-
return r.value;
|
|
147674
|
-
}
|
|
147675
|
-
let ot = class extends E {
|
|
147676
|
-
constructor(t, n, e) {
|
|
147677
|
-
let r = 6,
|
|
147678
|
-
s = 0;
|
|
147679
|
-
super(t, n, e);
|
|
147680
|
-
const o = e || {};
|
|
147681
|
-
if (1 !== this.numRounds) {
|
|
147682
|
-
if (o.kmacKey || o.hmacKey) throw new Error(f);
|
|
147683
|
-
if ("CSHAKE128" === this.o || "CSHAKE256" === this.o) throw new Error("Cannot set numRounds for CSHAKE variants");
|
|
147684
|
-
}
|
|
147685
|
-
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) {
|
|
147686
|
-
case "SHA3-224":
|
|
147687
|
-
this.m = s = 1152, this.R = 224, this.M = !0, this.g = this.Y;
|
|
147688
|
-
break;
|
|
147689
|
-
case "SHA3-256":
|
|
147690
|
-
this.m = s = 1088, this.R = 256, this.M = !0, this.g = this.Y;
|
|
147691
|
-
break;
|
|
147692
|
-
case "SHA3-384":
|
|
147693
|
-
this.m = s = 832, this.R = 384, this.M = !0, this.g = this.Y;
|
|
147694
|
-
break;
|
|
147695
|
-
case "SHA3-512":
|
|
147696
|
-
this.m = s = 576, this.R = 512, this.M = !0, this.g = this.Y;
|
|
147697
|
-
break;
|
|
147698
|
-
case "SHAKE128":
|
|
147699
|
-
r = 31, this.m = s = 1344, this.R = -1, this.K = !0, this.M = !1, this.g = null;
|
|
147700
|
-
break;
|
|
147701
|
-
case "SHAKE256":
|
|
147702
|
-
r = 31, this.m = s = 1088, this.R = -1, this.K = !0, this.M = !1, this.g = null;
|
|
147703
|
-
break;
|
|
147704
|
-
case "KMAC128":
|
|
147705
|
-
r = 4, this.m = s = 1344, this.X(e), this.R = -1, this.K = !0, this.M = !1, this.g = this._;
|
|
147706
|
-
break;
|
|
147707
|
-
case "KMAC256":
|
|
147708
|
-
r = 4, this.m = s = 1088, this.X(e), this.R = -1, this.K = !0, this.M = !1, this.g = this._;
|
|
147709
|
-
break;
|
|
147710
|
-
case "CSHAKE128":
|
|
147711
|
-
this.m = s = 1344, r = this.O(e), this.R = -1, this.K = !0, this.M = !1, this.g = null;
|
|
147712
|
-
break;
|
|
147713
|
-
case "CSHAKE256":
|
|
147714
|
-
this.m = s = 1088, r = this.O(e), this.R = -1, this.K = !0, this.M = !1, this.g = null;
|
|
147715
|
-
break;
|
|
147716
|
-
default:
|
|
147717
|
-
throw new Error(c);
|
|
147718
|
-
}
|
|
147719
|
-
this.F = function (t, n, e, i, o) {
|
|
147720
|
-
return function (t, n, e, r, i, s, o) {
|
|
147721
|
-
let h,
|
|
147722
|
-
u,
|
|
147723
|
-
w = 0;
|
|
147724
|
-
const c = [],
|
|
147725
|
-
f = i >>> 5,
|
|
147726
|
-
a = n >>> 5;
|
|
147727
|
-
for (h = 0; h < a && n >= i; h += f) r = et(t.slice(h, h + f), r), n -= i;
|
|
147728
|
-
for (t = t.slice(h), n %= i; t.length < f;) t.push(0);
|
|
147729
|
-
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);
|
|
147730
|
-
return c;
|
|
147731
|
-
}(t, n, 0, i, s, r, o);
|
|
147732
|
-
}, o.hmacKey && this.k(A("hmacKey", o.hmacKey, this.T));
|
|
147733
|
-
}
|
|
147734
|
-
O(t, n) {
|
|
147735
|
-
const e = function (t) {
|
|
147736
|
-
const n = t || {};
|
|
147737
|
-
return {
|
|
147738
|
-
funcName: A("funcName", n.funcName, 1, {
|
|
147739
|
-
value: [],
|
|
147740
|
-
binLen: 0
|
|
147741
|
-
}),
|
|
147742
|
-
customization: A("Customization", n.customization, 1, {
|
|
147743
|
-
value: [],
|
|
147744
|
-
binLen: 0
|
|
147745
|
-
})
|
|
147746
|
-
};
|
|
147747
|
-
}(t || {});
|
|
147748
|
-
n && (e.funcName = n);
|
|
147749
|
-
const r = a(it(e.funcName), it(e.customization));
|
|
147750
|
-
if (0 !== e.customization.binLen || 0 !== e.funcName.binLen) {
|
|
147751
|
-
const t = st(r, this.m >>> 3);
|
|
147752
|
-
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;
|
|
147753
|
-
return 4;
|
|
147754
|
-
}
|
|
147755
|
-
return 31;
|
|
147756
|
-
}
|
|
147757
|
-
X(t) {
|
|
147758
|
-
const n = function (t) {
|
|
147759
|
-
const n = t || {};
|
|
147760
|
-
return {
|
|
147761
|
-
kmacKey: A("kmacKey", n.kmacKey, 1),
|
|
147762
|
-
funcName: {
|
|
147763
|
-
value: [1128353099],
|
|
147764
|
-
binLen: 32
|
|
147765
|
-
},
|
|
147766
|
-
customization: A("Customization", n.customization, 1, {
|
|
147767
|
-
value: [],
|
|
147768
|
-
binLen: 0
|
|
147769
|
-
})
|
|
147770
|
-
};
|
|
147771
|
-
}(t || {});
|
|
147772
|
-
this.O(t, n.funcName);
|
|
147773
|
-
const e = st(it(n.kmacKey), this.m >>> 3);
|
|
147774
|
-
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;
|
|
147775
|
-
this.H = !0;
|
|
147776
|
-
}
|
|
147777
|
-
_(t) {
|
|
147778
|
-
const n = a({
|
|
147779
|
-
value: this.h.slice(),
|
|
147780
|
-
binLen: this.u
|
|
147781
|
-
}, function (t) {
|
|
147782
|
-
let n,
|
|
147783
|
-
e,
|
|
147784
|
-
r = 0;
|
|
147785
|
-
const i = [0, 0],
|
|
147786
|
-
s = [4294967295 & t, t / o & 2097151];
|
|
147787
|
-
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);
|
|
147788
|
-
return r = 0 !== r ? r : 1, i[r >> 2] |= r << 8 * r, {
|
|
147789
|
-
value: r + 1 > 4 ? i : [i[0]],
|
|
147790
|
-
binLen: 8 + 8 * r
|
|
147791
|
-
};
|
|
147792
|
-
}(t.outputLen));
|
|
147793
|
-
return this.F(n.value, n.binLen, this.A, this.L(this.U), t.outputLen);
|
|
147794
|
-
}
|
|
147795
|
-
};
|
|
147796
|
-
class ht {
|
|
147797
|
-
constructor(t, n, e) {
|
|
147798
|
-
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 {
|
|
147799
|
-
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);
|
|
147800
|
-
this.P = new ot(t, n, e);
|
|
147050
|
+
|
|
147051
|
+
// Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
|
|
147052
|
+
// prettier-ignore
|
|
147053
|
+
const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (()=>u64.split([
|
|
147054
|
+
'0x428a2f98d728ae22',
|
|
147055
|
+
'0x7137449123ef65cd',
|
|
147056
|
+
'0xb5c0fbcfec4d3b2f',
|
|
147057
|
+
'0xe9b5dba58189dbbc',
|
|
147058
|
+
'0x3956c25bf348b538',
|
|
147059
|
+
'0x59f111f1b605d019',
|
|
147060
|
+
'0x923f82a4af194f9b',
|
|
147061
|
+
'0xab1c5ed5da6d8118',
|
|
147062
|
+
'0xd807aa98a3030242',
|
|
147063
|
+
'0x12835b0145706fbe',
|
|
147064
|
+
'0x243185be4ee4b28c',
|
|
147065
|
+
'0x550c7dc3d5ffb4e2',
|
|
147066
|
+
'0x72be5d74f27b896f',
|
|
147067
|
+
'0x80deb1fe3b1696b1',
|
|
147068
|
+
'0x9bdc06a725c71235',
|
|
147069
|
+
'0xc19bf174cf692694',
|
|
147070
|
+
'0xe49b69c19ef14ad2',
|
|
147071
|
+
'0xefbe4786384f25e3',
|
|
147072
|
+
'0x0fc19dc68b8cd5b5',
|
|
147073
|
+
'0x240ca1cc77ac9c65',
|
|
147074
|
+
'0x2de92c6f592b0275',
|
|
147075
|
+
'0x4a7484aa6ea6e483',
|
|
147076
|
+
'0x5cb0a9dcbd41fbd4',
|
|
147077
|
+
'0x76f988da831153b5',
|
|
147078
|
+
'0x983e5152ee66dfab',
|
|
147079
|
+
'0xa831c66d2db43210',
|
|
147080
|
+
'0xb00327c898fb213f',
|
|
147081
|
+
'0xbf597fc7beef0ee4',
|
|
147082
|
+
'0xc6e00bf33da88fc2',
|
|
147083
|
+
'0xd5a79147930aa725',
|
|
147084
|
+
'0x06ca6351e003826f',
|
|
147085
|
+
'0x142929670a0e6e70',
|
|
147086
|
+
'0x27b70a8546d22ffc',
|
|
147087
|
+
'0x2e1b21385c26c926',
|
|
147088
|
+
'0x4d2c6dfc5ac42aed',
|
|
147089
|
+
'0x53380d139d95b3df',
|
|
147090
|
+
'0x650a73548baf63de',
|
|
147091
|
+
'0x766a0abb3c77b2a8',
|
|
147092
|
+
'0x81c2c92e47edaee6',
|
|
147093
|
+
'0x92722c851482353b',
|
|
147094
|
+
'0xa2bfe8a14cf10364',
|
|
147095
|
+
'0xa81a664bbc423001',
|
|
147096
|
+
'0xc24b8b70d0f89791',
|
|
147097
|
+
'0xc76c51a30654be30',
|
|
147098
|
+
'0xd192e819d6ef5218',
|
|
147099
|
+
'0xd69906245565a910',
|
|
147100
|
+
'0xf40e35855771202a',
|
|
147101
|
+
'0x106aa07032bbd1b8',
|
|
147102
|
+
'0x19a4c116b8d2d0c8',
|
|
147103
|
+
'0x1e376c085141ab53',
|
|
147104
|
+
'0x2748774cdf8eeb99',
|
|
147105
|
+
'0x34b0bcb5e19b48a8',
|
|
147106
|
+
'0x391c0cb3c5c95a63',
|
|
147107
|
+
'0x4ed8aa4ae3418acb',
|
|
147108
|
+
'0x5b9cca4f7763e373',
|
|
147109
|
+
'0x682e6ff3d6b2b8a3',
|
|
147110
|
+
'0x748f82ee5defb2fc',
|
|
147111
|
+
'0x78a5636f43172f60',
|
|
147112
|
+
'0x84c87814a1f0ab72',
|
|
147113
|
+
'0x8cc702081a6439ec',
|
|
147114
|
+
'0x90befffa23631e28',
|
|
147115
|
+
'0xa4506cebde82bde9',
|
|
147116
|
+
'0xbef9a3f7b2c67915',
|
|
147117
|
+
'0xc67178f2e372532b',
|
|
147118
|
+
'0xca273eceea26619c',
|
|
147119
|
+
'0xd186b8c721c0c207',
|
|
147120
|
+
'0xeada7dd6cde0eb1e',
|
|
147121
|
+
'0xf57d4f7fee6ed178',
|
|
147122
|
+
'0x06f067aa72176fba',
|
|
147123
|
+
'0x0a637dc5a2c898a6',
|
|
147124
|
+
'0x113f9804bef90dae',
|
|
147125
|
+
'0x1b710b35131c471b',
|
|
147126
|
+
'0x28db77f523047d84',
|
|
147127
|
+
'0x32caab7b40c72493',
|
|
147128
|
+
'0x3c9ebe0a15c9bebc',
|
|
147129
|
+
'0x431d67c49c100d4c',
|
|
147130
|
+
'0x4cc5d4becb3e42b6',
|
|
147131
|
+
'0x597f299cfc657e2a',
|
|
147132
|
+
'0x5fcb6fab3ad6faec',
|
|
147133
|
+
'0x6c44198c4a475817'
|
|
147134
|
+
].map((n)=>BigInt(n))))();
|
|
147135
|
+
// Temporary buffer, not used to store anything between runs
|
|
147136
|
+
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
147137
|
+
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
147138
|
+
class SHA512 extends HashMD {
|
|
147139
|
+
// prettier-ignore
|
|
147140
|
+
get() {
|
|
147141
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
147142
|
+
return [
|
|
147143
|
+
Ah,
|
|
147144
|
+
Al,
|
|
147145
|
+
Bh,
|
|
147146
|
+
Bl,
|
|
147147
|
+
Ch,
|
|
147148
|
+
Cl,
|
|
147149
|
+
Dh,
|
|
147150
|
+
Dl,
|
|
147151
|
+
Eh,
|
|
147152
|
+
El,
|
|
147153
|
+
Fh,
|
|
147154
|
+
Fl,
|
|
147155
|
+
Gh,
|
|
147156
|
+
Gl,
|
|
147157
|
+
Hh,
|
|
147158
|
+
Hl
|
|
147159
|
+
];
|
|
147801
147160
|
}
|
|
147802
|
-
|
|
147803
|
-
|
|
147804
|
-
|
|
147805
|
-
|
|
147806
|
-
|
|
147807
|
-
|
|
147808
|
-
|
|
147809
|
-
|
|
147810
|
-
|
|
147811
|
-
|
|
147812
|
-
|
|
147813
|
-
|
|
147814
|
-
|
|
147815
|
-
|
|
147161
|
+
// prettier-ignore
|
|
147162
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
147163
|
+
this.Ah = Ah | 0;
|
|
147164
|
+
this.Al = Al | 0;
|
|
147165
|
+
this.Bh = Bh | 0;
|
|
147166
|
+
this.Bl = Bl | 0;
|
|
147167
|
+
this.Ch = Ch | 0;
|
|
147168
|
+
this.Cl = Cl | 0;
|
|
147169
|
+
this.Dh = Dh | 0;
|
|
147170
|
+
this.Dl = Dl | 0;
|
|
147171
|
+
this.Eh = Eh | 0;
|
|
147172
|
+
this.El = El | 0;
|
|
147173
|
+
this.Fh = Fh | 0;
|
|
147174
|
+
this.Fl = Fl | 0;
|
|
147175
|
+
this.Gh = Gh | 0;
|
|
147176
|
+
this.Gl = Gl | 0;
|
|
147177
|
+
this.Hh = Hh | 0;
|
|
147178
|
+
this.Hl = Hl | 0;
|
|
147179
|
+
}
|
|
147180
|
+
process(view, offset) {
|
|
147181
|
+
// Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
|
|
147182
|
+
for(let i = 0; i < 16; i++, offset += 4){
|
|
147183
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
147184
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
147185
|
+
}
|
|
147186
|
+
for(let i = 16; i < 80; i++){
|
|
147187
|
+
// s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
|
|
147188
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
147189
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
147190
|
+
const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
|
|
147191
|
+
const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
|
|
147192
|
+
// s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
|
|
147193
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
147194
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
147195
|
+
const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
|
|
147196
|
+
const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
|
|
147197
|
+
// SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
|
|
147198
|
+
const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
147199
|
+
const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
147200
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
147201
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
147202
|
+
}
|
|
147203
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
147204
|
+
// Compression function main loop, 80 rounds
|
|
147205
|
+
for(let i = 0; i < 80; i++){
|
|
147206
|
+
// S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
|
|
147207
|
+
const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
|
|
147208
|
+
const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
|
|
147209
|
+
//const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
147210
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
147211
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
147212
|
+
// T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
|
|
147213
|
+
// prettier-ignore
|
|
147214
|
+
const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
147215
|
+
const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
147216
|
+
const T1l = T1ll | 0;
|
|
147217
|
+
// S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
|
|
147218
|
+
const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
|
|
147219
|
+
const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
|
|
147220
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
147221
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
147222
|
+
Hh = Gh | 0;
|
|
147223
|
+
Hl = Gl | 0;
|
|
147224
|
+
Gh = Fh | 0;
|
|
147225
|
+
Gl = Fl | 0;
|
|
147226
|
+
Fh = Eh | 0;
|
|
147227
|
+
Fl = El | 0;
|
|
147228
|
+
({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
147229
|
+
Dh = Ch | 0;
|
|
147230
|
+
Dl = Cl | 0;
|
|
147231
|
+
Ch = Bh | 0;
|
|
147232
|
+
Cl = Bl | 0;
|
|
147233
|
+
Bh = Ah | 0;
|
|
147234
|
+
Bl = Al | 0;
|
|
147235
|
+
const All = u64.add3L(T1l, sigma0l, MAJl);
|
|
147236
|
+
Ah = u64.add3H(All, T1h, sigma0h, MAJh);
|
|
147237
|
+
Al = All | 0;
|
|
147238
|
+
}
|
|
147239
|
+
// Add the compressed chunk to the current hash value
|
|
147240
|
+
({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
147241
|
+
({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
147242
|
+
({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
147243
|
+
({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
147244
|
+
({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
147245
|
+
({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
147246
|
+
({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
147247
|
+
({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
147248
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
147249
|
+
}
|
|
147250
|
+
roundClean() {
|
|
147251
|
+
SHA512_W_H.fill(0);
|
|
147252
|
+
SHA512_W_L.fill(0);
|
|
147253
|
+
}
|
|
147254
|
+
destroy() {
|
|
147255
|
+
this.buffer.fill(0);
|
|
147256
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
147257
|
+
}
|
|
147258
|
+
constructor(){
|
|
147259
|
+
super(128, 64, 16, false);
|
|
147260
|
+
// We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
|
|
147261
|
+
// Also looks cleaner and easier to verify with spec.
|
|
147262
|
+
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
|
147263
|
+
// h -- high 32 bits, l -- low 32 bits
|
|
147264
|
+
this.Ah = 0x6a09e667 | 0;
|
|
147265
|
+
this.Al = 0xf3bcc908 | 0;
|
|
147266
|
+
this.Bh = 0xbb67ae85 | 0;
|
|
147267
|
+
this.Bl = 0x84caa73b | 0;
|
|
147268
|
+
this.Ch = 0x3c6ef372 | 0;
|
|
147269
|
+
this.Cl = 0xfe94f82b | 0;
|
|
147270
|
+
this.Dh = 0xa54ff53a | 0;
|
|
147271
|
+
this.Dl = 0x5f1d36f1 | 0;
|
|
147272
|
+
this.Eh = 0x510e527f | 0;
|
|
147273
|
+
this.El = 0xade682d1 | 0;
|
|
147274
|
+
this.Fh = 0x9b05688c | 0;
|
|
147275
|
+
this.Fl = 0x2b3e6c1f | 0;
|
|
147276
|
+
this.Gh = 0x1f83d9ab | 0;
|
|
147277
|
+
this.Gl = 0xfb41bd6b | 0;
|
|
147278
|
+
this.Hh = 0x5be0cd19 | 0;
|
|
147279
|
+
this.Hl = 0x137e2179 | 0;
|
|
147280
|
+
}
|
|
147281
|
+
}
|
|
147282
|
+
class SHA384 extends SHA512 {
|
|
147283
|
+
constructor(){
|
|
147284
|
+
super();
|
|
147285
|
+
// h -- high 32 bits, l -- low 32 bits
|
|
147286
|
+
this.Ah = 0xcbbb9d5d | 0;
|
|
147287
|
+
this.Al = 0xc1059ed8 | 0;
|
|
147288
|
+
this.Bh = 0x629a292a | 0;
|
|
147289
|
+
this.Bl = 0x367cd507 | 0;
|
|
147290
|
+
this.Ch = 0x9159015a | 0;
|
|
147291
|
+
this.Cl = 0x3070dd17 | 0;
|
|
147292
|
+
this.Dh = 0x152fecd8 | 0;
|
|
147293
|
+
this.Dl = 0xf70e5939 | 0;
|
|
147294
|
+
this.Eh = 0x67332667 | 0;
|
|
147295
|
+
this.El = 0xffc00b31 | 0;
|
|
147296
|
+
this.Fh = 0x8eb44a87 | 0;
|
|
147297
|
+
this.Fl = 0x68581511 | 0;
|
|
147298
|
+
this.Gh = 0xdb0c2e0d | 0;
|
|
147299
|
+
this.Gl = 0x64f98fa7 | 0;
|
|
147300
|
+
this.Hh = 0x47b5481d | 0;
|
|
147301
|
+
this.Hl = 0xbefa4fa4 | 0;
|
|
147302
|
+
this.outputLen = 48;
|
|
147303
|
+
}
|
|
147304
|
+
}
|
|
147305
|
+
const sha512 = /* @__PURE__ */ wrapConstructor(()=>new SHA512());
|
|
147306
|
+
const sha384 = /* @__PURE__ */ wrapConstructor(()=>new SHA384());
|
|
147307
|
+
|
|
147308
|
+
// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
|
|
147309
|
+
// It's called a sponge function.
|
|
147310
|
+
// Various per round constants calculations
|
|
147311
|
+
const SHA3_PI = [];
|
|
147312
|
+
const SHA3_ROTL = [];
|
|
147313
|
+
const _SHA3_IOTA = [];
|
|
147314
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
147315
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
147316
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
|
147317
|
+
const _7n = /* @__PURE__ */ BigInt(7);
|
|
147318
|
+
const _256n = /* @__PURE__ */ BigInt(256);
|
|
147319
|
+
const _0x71n = /* @__PURE__ */ BigInt(0x71);
|
|
147320
|
+
for(let round = 0, R = _1n, x = 1, y = 0; round < 24; round++){
|
|
147321
|
+
// Pi
|
|
147322
|
+
[x, y] = [
|
|
147323
|
+
y,
|
|
147324
|
+
(2 * x + 3 * y) % 5
|
|
147325
|
+
];
|
|
147326
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
147327
|
+
// Rotational
|
|
147328
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
147329
|
+
// Iota
|
|
147330
|
+
let t = _0n;
|
|
147331
|
+
for(let j = 0; j < 7; j++){
|
|
147332
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
147333
|
+
if (R & _2n) t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
147334
|
+
}
|
|
147335
|
+
_SHA3_IOTA.push(t);
|
|
147336
|
+
}
|
|
147337
|
+
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
|
|
147338
|
+
// Left rotation (without 0, 32, 64)
|
|
147339
|
+
const rotlH = (h, l, s)=>s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
147340
|
+
const rotlL = (h, l, s)=>s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
147341
|
+
// Same as keccakf1600, but allows to skip some rounds
|
|
147342
|
+
function keccakP(s, rounds = 24) {
|
|
147343
|
+
const B = new Uint32Array(5 * 2);
|
|
147344
|
+
// NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
|
|
147345
|
+
for(let round = 24 - rounds; round < 24; round++){
|
|
147346
|
+
// Theta θ
|
|
147347
|
+
for(let x = 0; x < 10; x++)B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
147348
|
+
for(let x = 0; x < 10; x += 2){
|
|
147349
|
+
const idx1 = (x + 8) % 10;
|
|
147350
|
+
const idx0 = (x + 2) % 10;
|
|
147351
|
+
const B0 = B[idx0];
|
|
147352
|
+
const B1 = B[idx0 + 1];
|
|
147353
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
147354
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
147355
|
+
for(let y = 0; y < 50; y += 10){
|
|
147356
|
+
s[x + y] ^= Th;
|
|
147357
|
+
s[x + y + 1] ^= Tl;
|
|
147358
|
+
}
|
|
147359
|
+
}
|
|
147360
|
+
// Rho (ρ) and Pi (π)
|
|
147361
|
+
let curH = s[2];
|
|
147362
|
+
let curL = s[3];
|
|
147363
|
+
for(let t = 0; t < 24; t++){
|
|
147364
|
+
const shift = SHA3_ROTL[t];
|
|
147365
|
+
const Th = rotlH(curH, curL, shift);
|
|
147366
|
+
const Tl = rotlL(curH, curL, shift);
|
|
147367
|
+
const PI = SHA3_PI[t];
|
|
147368
|
+
curH = s[PI];
|
|
147369
|
+
curL = s[PI + 1];
|
|
147370
|
+
s[PI] = Th;
|
|
147371
|
+
s[PI + 1] = Tl;
|
|
147372
|
+
}
|
|
147373
|
+
// Chi (χ)
|
|
147374
|
+
for(let y = 0; y < 50; y += 10){
|
|
147375
|
+
for(let x = 0; x < 10; x++)B[x] = s[y + x];
|
|
147376
|
+
for(let x = 0; x < 10; x++)s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
147377
|
+
}
|
|
147378
|
+
// Iota (ι)
|
|
147379
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
147380
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
147381
|
+
}
|
|
147382
|
+
B.fill(0);
|
|
147383
|
+
}
|
|
147384
|
+
class Keccak extends Hash {
|
|
147385
|
+
keccak() {
|
|
147386
|
+
if (!isLE) byteSwap32(this.state32);
|
|
147387
|
+
keccakP(this.state32, this.rounds);
|
|
147388
|
+
if (!isLE) byteSwap32(this.state32);
|
|
147389
|
+
this.posOut = 0;
|
|
147390
|
+
this.pos = 0;
|
|
147391
|
+
}
|
|
147392
|
+
update(data) {
|
|
147393
|
+
exists(this);
|
|
147394
|
+
const { blockLen, state } = this;
|
|
147395
|
+
data = toBytes(data);
|
|
147396
|
+
const len = data.length;
|
|
147397
|
+
for(let pos = 0; pos < len;){
|
|
147398
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
147399
|
+
for(let i = 0; i < take; i++)state[this.pos++] ^= data[pos++];
|
|
147400
|
+
if (this.pos === blockLen) this.keccak();
|
|
147401
|
+
}
|
|
147402
|
+
return this;
|
|
147403
|
+
}
|
|
147404
|
+
finish() {
|
|
147405
|
+
if (this.finished) return;
|
|
147406
|
+
this.finished = true;
|
|
147407
|
+
const { state, suffix, pos, blockLen } = this;
|
|
147408
|
+
// Do the padding
|
|
147409
|
+
state[pos] ^= suffix;
|
|
147410
|
+
if ((suffix & 0x80) !== 0 && pos === blockLen - 1) this.keccak();
|
|
147411
|
+
state[blockLen - 1] ^= 0x80;
|
|
147412
|
+
this.keccak();
|
|
147413
|
+
}
|
|
147414
|
+
writeInto(out) {
|
|
147415
|
+
exists(this, false);
|
|
147416
|
+
bytes(out);
|
|
147417
|
+
this.finish();
|
|
147418
|
+
const bufferOut = this.state;
|
|
147419
|
+
const { blockLen } = this;
|
|
147420
|
+
for(let pos = 0, len = out.length; pos < len;){
|
|
147421
|
+
if (this.posOut >= blockLen) this.keccak();
|
|
147422
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
147423
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
147424
|
+
this.posOut += take;
|
|
147425
|
+
pos += take;
|
|
147426
|
+
}
|
|
147427
|
+
return out;
|
|
147428
|
+
}
|
|
147429
|
+
xofInto(out) {
|
|
147430
|
+
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
|
|
147431
|
+
if (!this.enableXOF) throw new Error('XOF is not possible for this instance');
|
|
147432
|
+
return this.writeInto(out);
|
|
147433
|
+
}
|
|
147434
|
+
xof(bytes) {
|
|
147435
|
+
number(bytes);
|
|
147436
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
147437
|
+
}
|
|
147438
|
+
digestInto(out) {
|
|
147439
|
+
output(out, this);
|
|
147440
|
+
if (this.finished) throw new Error('digest() was already called');
|
|
147441
|
+
this.writeInto(out);
|
|
147442
|
+
this.destroy();
|
|
147443
|
+
return out;
|
|
147444
|
+
}
|
|
147445
|
+
digest() {
|
|
147446
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
147447
|
+
}
|
|
147448
|
+
destroy() {
|
|
147449
|
+
this.destroyed = true;
|
|
147450
|
+
this.state.fill(0);
|
|
147451
|
+
}
|
|
147452
|
+
_cloneInto(to) {
|
|
147453
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
147454
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
147455
|
+
to.state32.set(this.state32);
|
|
147456
|
+
to.pos = this.pos;
|
|
147457
|
+
to.posOut = this.posOut;
|
|
147458
|
+
to.finished = this.finished;
|
|
147459
|
+
to.rounds = rounds;
|
|
147460
|
+
// Suffix can change in cSHAKE
|
|
147461
|
+
to.suffix = suffix;
|
|
147462
|
+
to.outputLen = outputLen;
|
|
147463
|
+
to.enableXOF = enableXOF;
|
|
147464
|
+
to.destroyed = this.destroyed;
|
|
147465
|
+
return to;
|
|
147466
|
+
}
|
|
147467
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
147468
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24){
|
|
147469
|
+
super();
|
|
147470
|
+
this.blockLen = blockLen;
|
|
147471
|
+
this.suffix = suffix;
|
|
147472
|
+
this.outputLen = outputLen;
|
|
147473
|
+
this.enableXOF = enableXOF;
|
|
147474
|
+
this.rounds = rounds;
|
|
147475
|
+
this.pos = 0;
|
|
147476
|
+
this.posOut = 0;
|
|
147477
|
+
this.finished = false;
|
|
147478
|
+
this.destroyed = false;
|
|
147479
|
+
// Can be passed from user as dkLen
|
|
147480
|
+
number(outputLen);
|
|
147481
|
+
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
|
147482
|
+
if (0 >= this.blockLen || this.blockLen >= 200) throw new Error('Sha3 supports only keccak-f1600 function');
|
|
147483
|
+
this.state = new Uint8Array(200);
|
|
147484
|
+
this.state32 = u32(this.state);
|
|
147485
|
+
}
|
|
147486
|
+
}
|
|
147487
|
+
const gen = (suffix, blockLen, outputLen)=>wrapConstructor(()=>new Keccak(blockLen, suffix, outputLen));
|
|
147488
|
+
const sha3_224 = /* @__PURE__ */ gen(0x06, 144, 224 / 8);
|
|
147489
|
+
/**
|
|
147490
|
+
* SHA3-256 hash function
|
|
147491
|
+
* @param message - that would be hashed
|
|
147492
|
+
*/ const sha3_256 = /* @__PURE__ */ gen(0x06, 136, 256 / 8);
|
|
147493
|
+
const sha3_384 = /* @__PURE__ */ gen(0x06, 104, 384 / 8);
|
|
147494
|
+
const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8);
|
|
147816
147495
|
|
|
147817
147496
|
/**
|
|
147818
147497
|
* "globalThis" ponyfill.
|
|
147819
147498
|
* @see [A horrifying globalThis polyfill in universal JavaScript](https://mathiasbynens.be/notes/globalthis)
|
|
147820
147499
|
* @type {Object.<string, *>}
|
|
147821
|
-
*/
|
|
147822
|
-
|
|
147823
|
-
|
|
147824
|
-
|
|
147825
|
-
|
|
147826
|
-
|
|
147827
|
-
|
|
147828
|
-
|
|
147829
|
-
|
|
147830
|
-
|
|
147831
|
-
|
|
147832
|
-
|
|
147833
|
-
|
|
147834
|
-
|
|
147835
|
-
|
|
147836
|
-
|
|
147500
|
+
*/ const globalScope = (()=>{
|
|
147501
|
+
if (typeof globalThis === "object") return globalThis;
|
|
147502
|
+
else {
|
|
147503
|
+
Object.defineProperty(Object.prototype, "__GLOBALTHIS__", {
|
|
147504
|
+
get () {
|
|
147505
|
+
return this;
|
|
147506
|
+
},
|
|
147507
|
+
configurable: true
|
|
147508
|
+
});
|
|
147509
|
+
try {
|
|
147510
|
+
// @ts-ignore
|
|
147511
|
+
// eslint-disable-next-line no-undef
|
|
147512
|
+
if (typeof __GLOBALTHIS__ !== "undefined") return __GLOBALTHIS__;
|
|
147513
|
+
} finally{
|
|
147514
|
+
// @ts-ignore
|
|
147515
|
+
delete Object.prototype.__GLOBALTHIS__;
|
|
147516
|
+
}
|
|
147837
147517
|
}
|
|
147838
|
-
|
|
147839
|
-
|
|
147840
|
-
|
|
147841
|
-
|
|
147842
|
-
|
|
147518
|
+
// Still unable to determine "globalThis", fall back to a naive method.
|
|
147519
|
+
if (typeof self !== "undefined") return self;
|
|
147520
|
+
else if (typeof window !== "undefined") return window;
|
|
147521
|
+
else if (typeof global !== "undefined") return global;
|
|
147522
|
+
return undefined;
|
|
147843
147523
|
})();
|
|
147844
147524
|
|
|
147845
147525
|
/**
|
|
147846
|
-
* OpenSSL
|
|
147847
|
-
* @type {Object.<string,
|
|
147848
|
-
*/
|
|
147849
|
-
|
|
147850
|
-
|
|
147851
|
-
|
|
147852
|
-
|
|
147853
|
-
|
|
147854
|
-
|
|
147855
|
-
|
|
147856
|
-
|
|
147857
|
-
|
|
147858
|
-
"SHA3-512": "SHA3-512"
|
|
147526
|
+
* OpenSSL-Noble hashes map.
|
|
147527
|
+
* @type {Object.<string, sha1|sha224|sha256|sha384|sha512|sha3_224|sha3_256|sha3_384|sha3_512>}
|
|
147528
|
+
*/ const OPENSSL_NOBLE_HASHES = {
|
|
147529
|
+
SHA1: sha1,
|
|
147530
|
+
SHA224: sha224,
|
|
147531
|
+
SHA256: sha256,
|
|
147532
|
+
SHA384: sha384,
|
|
147533
|
+
SHA512: sha512,
|
|
147534
|
+
"SHA3-224": sha3_224,
|
|
147535
|
+
"SHA3-256": sha3_256,
|
|
147536
|
+
"SHA3-384": sha3_384,
|
|
147537
|
+
"SHA3-512": sha3_512
|
|
147859
147538
|
};
|
|
147860
|
-
|
|
147861
147539
|
/**
|
|
147862
147540
|
* Calculates an HMAC digest.
|
|
147863
147541
|
* In Node.js, the command "openssl list -digest-algorithms" displays the available digest algorithms.
|
|
147864
147542
|
* @param {string} algorithm Algorithm.
|
|
147865
|
-
* @param {
|
|
147866
|
-
* @param {
|
|
147867
|
-
* @returns {
|
|
147868
|
-
*/
|
|
147869
|
-
|
|
147870
|
-
|
|
147871
|
-
|
|
147872
|
-
|
|
147873
|
-
|
|
147543
|
+
* @param {Uint8Array} key Key.
|
|
147544
|
+
* @param {Uint8Array} message Message.
|
|
147545
|
+
* @returns {Uint8Array} Digest.
|
|
147546
|
+
*/ const hmacDigest = (algorithm, key, message)=>{
|
|
147547
|
+
if (hmac) {
|
|
147548
|
+
const hash = OPENSSL_NOBLE_HASHES[algorithm.toUpperCase()];
|
|
147549
|
+
if (!hash) throw new TypeError("Unknown hash function");
|
|
147550
|
+
return hmac(hash, key, message);
|
|
147551
|
+
} else {
|
|
147552
|
+
throw new Error("Missing HMAC function");
|
|
147874
147553
|
}
|
|
147875
|
-
const hmac = new ht(variant, "ARRAYBUFFER");
|
|
147876
|
-
hmac.setHMACKey(key, "ARRAYBUFFER");
|
|
147877
|
-
hmac.update(message);
|
|
147878
|
-
return hmac.getHMAC("ARRAYBUFFER");
|
|
147879
|
-
}
|
|
147880
147554
|
};
|
|
147881
147555
|
|
|
147882
147556
|
/**
|
|
147883
147557
|
* RFC 4648 base32 alphabet without pad.
|
|
147884
147558
|
* @type {string}
|
|
147885
|
-
*/
|
|
147886
|
-
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
147887
|
-
|
|
147559
|
+
*/ const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
147888
147560
|
/**
|
|
147889
|
-
* Converts a base32 string to an
|
|
147561
|
+
* Converts a base32 string to an Uint8Array (RFC 4648).
|
|
147890
147562
|
* @see [LinusU/base32-decode](https://github.com/LinusU/base32-decode)
|
|
147891
147563
|
* @param {string} str Base32 string.
|
|
147892
|
-
* @returns {
|
|
147893
|
-
*/
|
|
147894
|
-
|
|
147895
|
-
|
|
147896
|
-
|
|
147897
|
-
|
|
147898
|
-
|
|
147899
|
-
|
|
147900
|
-
|
|
147901
|
-
|
|
147902
|
-
|
|
147903
|
-
|
|
147904
|
-
|
|
147905
|
-
|
|
147906
|
-
|
|
147907
|
-
|
|
147908
|
-
|
|
147909
|
-
|
|
147910
|
-
|
|
147911
|
-
|
|
147564
|
+
* @returns {Uint8Array} Uint8Array.
|
|
147565
|
+
*/ const base32Decode = (str)=>{
|
|
147566
|
+
// Canonicalize to all upper case and remove padding if it exists.
|
|
147567
|
+
let end = str.length;
|
|
147568
|
+
while(str[end - 1] === "=")--end;
|
|
147569
|
+
const cstr = (end < str.length ? str.substring(0, end) : str).toUpperCase();
|
|
147570
|
+
const buf = new ArrayBuffer(cstr.length * 5 / 8 | 0);
|
|
147571
|
+
const arr = new Uint8Array(buf);
|
|
147572
|
+
let bits = 0;
|
|
147573
|
+
let value = 0;
|
|
147574
|
+
let index = 0;
|
|
147575
|
+
for(let i = 0; i < cstr.length; i++){
|
|
147576
|
+
const idx = ALPHABET.indexOf(cstr[i]);
|
|
147577
|
+
if (idx === -1) throw new TypeError(`Invalid character found: ${cstr[i]}`);
|
|
147578
|
+
value = value << 5 | idx;
|
|
147579
|
+
bits += 5;
|
|
147580
|
+
if (bits >= 8) {
|
|
147581
|
+
bits -= 8;
|
|
147582
|
+
arr[index++] = value >>> bits;
|
|
147583
|
+
}
|
|
147912
147584
|
}
|
|
147913
|
-
|
|
147914
|
-
return buf;
|
|
147585
|
+
return arr;
|
|
147915
147586
|
};
|
|
147916
|
-
|
|
147917
147587
|
/**
|
|
147918
|
-
* Converts an
|
|
147588
|
+
* Converts an Uint8Array to a base32 string (RFC 4648).
|
|
147919
147589
|
* @see [LinusU/base32-encode](https://github.com/LinusU/base32-encode)
|
|
147920
|
-
* @param {
|
|
147590
|
+
* @param {Uint8Array} arr Uint8Array.
|
|
147921
147591
|
* @returns {string} Base32 string.
|
|
147922
|
-
*/
|
|
147923
|
-
|
|
147924
|
-
|
|
147925
|
-
|
|
147926
|
-
|
|
147927
|
-
|
|
147928
|
-
|
|
147929
|
-
|
|
147930
|
-
|
|
147931
|
-
|
|
147932
|
-
|
|
147933
|
-
|
|
147934
|
-
|
|
147935
|
-
|
|
147936
|
-
|
|
147937
|
-
str
|
|
147938
|
-
}
|
|
147939
|
-
return str;
|
|
147592
|
+
*/ const base32Encode = (arr)=>{
|
|
147593
|
+
let bits = 0;
|
|
147594
|
+
let value = 0;
|
|
147595
|
+
let str = "";
|
|
147596
|
+
for(let i = 0; i < arr.length; i++){
|
|
147597
|
+
value = value << 8 | arr[i];
|
|
147598
|
+
bits += 8;
|
|
147599
|
+
while(bits >= 5){
|
|
147600
|
+
str += ALPHABET[value >>> bits - 5 & 31];
|
|
147601
|
+
bits -= 5;
|
|
147602
|
+
}
|
|
147603
|
+
}
|
|
147604
|
+
if (bits > 0) {
|
|
147605
|
+
str += ALPHABET[value << 5 - bits & 31];
|
|
147606
|
+
}
|
|
147607
|
+
return str;
|
|
147940
147608
|
};
|
|
147941
147609
|
|
|
147942
147610
|
/**
|
|
147943
|
-
* Converts a hexadecimal string to an
|
|
147611
|
+
* Converts a hexadecimal string to an Uint8Array.
|
|
147944
147612
|
* @param {string} str Hexadecimal string.
|
|
147945
|
-
* @returns {
|
|
147946
|
-
*/
|
|
147947
|
-
const
|
|
147948
|
-
|
|
147949
|
-
|
|
147950
|
-
|
|
147951
|
-
|
|
147952
|
-
|
|
147953
|
-
return buf;
|
|
147613
|
+
* @returns {Uint8Array} Uint8Array.
|
|
147614
|
+
*/ const hexDecode = (str)=>{
|
|
147615
|
+
const buf = new ArrayBuffer(str.length / 2);
|
|
147616
|
+
const arr = new Uint8Array(buf);
|
|
147617
|
+
for(let i = 0; i < str.length; i += 2){
|
|
147618
|
+
arr[i / 2] = parseInt(str.substring(i, i + 2), 16);
|
|
147619
|
+
}
|
|
147620
|
+
return arr;
|
|
147954
147621
|
};
|
|
147955
|
-
|
|
147956
147622
|
/**
|
|
147957
|
-
* Converts an
|
|
147958
|
-
* @param {
|
|
147623
|
+
* Converts an Uint8Array to a hexadecimal string.
|
|
147624
|
+
* @param {Uint8Array} arr Uint8Array.
|
|
147959
147625
|
* @returns {string} Hexadecimal string.
|
|
147960
|
-
*/
|
|
147961
|
-
|
|
147962
|
-
|
|
147963
|
-
|
|
147964
|
-
|
|
147965
|
-
|
|
147966
|
-
|
|
147967
|
-
str
|
|
147968
|
-
}
|
|
147969
|
-
return str.toUpperCase();
|
|
147626
|
+
*/ const hexEncode = (arr)=>{
|
|
147627
|
+
let str = "";
|
|
147628
|
+
for(let i = 0; i < arr.length; i++){
|
|
147629
|
+
const hex = arr[i].toString(16);
|
|
147630
|
+
if (hex.length === 1) str += "0";
|
|
147631
|
+
str += hex;
|
|
147632
|
+
}
|
|
147633
|
+
return str.toUpperCase();
|
|
147970
147634
|
};
|
|
147971
147635
|
|
|
147972
147636
|
/**
|
|
147973
|
-
* Converts a Latin-1 string to an
|
|
147637
|
+
* Converts a Latin-1 string to an Uint8Array.
|
|
147974
147638
|
* @param {string} str Latin-1 string.
|
|
147975
|
-
* @returns {
|
|
147976
|
-
*/
|
|
147977
|
-
const
|
|
147978
|
-
|
|
147979
|
-
|
|
147980
|
-
|
|
147981
|
-
|
|
147982
|
-
|
|
147983
|
-
return buf;
|
|
147639
|
+
* @returns {Uint8Array} Uint8Array.
|
|
147640
|
+
*/ const latin1Decode = (str)=>{
|
|
147641
|
+
const buf = new ArrayBuffer(str.length);
|
|
147642
|
+
const arr = new Uint8Array(buf);
|
|
147643
|
+
for(let i = 0; i < str.length; i++){
|
|
147644
|
+
arr[i] = str.charCodeAt(i) & 0xff;
|
|
147645
|
+
}
|
|
147646
|
+
return arr;
|
|
147984
147647
|
};
|
|
147985
|
-
|
|
147986
147648
|
/**
|
|
147987
|
-
* Converts an
|
|
147988
|
-
* @param {
|
|
147649
|
+
* Converts an Uint8Array to a Latin-1 string.
|
|
147650
|
+
* @param {Uint8Array} arr Uint8Array.
|
|
147989
147651
|
* @returns {string} Latin-1 string.
|
|
147990
|
-
*/
|
|
147991
|
-
|
|
147992
|
-
|
|
147993
|
-
|
|
147994
|
-
|
|
147995
|
-
str
|
|
147996
|
-
}
|
|
147997
|
-
return str;
|
|
147652
|
+
*/ const latin1Encode = (arr)=>{
|
|
147653
|
+
let str = "";
|
|
147654
|
+
for(let i = 0; i < arr.length; i++){
|
|
147655
|
+
str += String.fromCharCode(arr[i]);
|
|
147656
|
+
}
|
|
147657
|
+
return str;
|
|
147998
147658
|
};
|
|
147999
147659
|
|
|
148000
147660
|
/**
|
|
148001
147661
|
* TextEncoder instance.
|
|
148002
147662
|
* @type {TextEncoder|null}
|
|
148003
|
-
*/
|
|
148004
|
-
const ENCODER = globalScope.TextEncoder ? new globalScope.TextEncoder("utf-8") : null;
|
|
148005
|
-
|
|
147663
|
+
*/ const ENCODER = globalScope.TextEncoder ? new globalScope.TextEncoder() : null;
|
|
148006
147664
|
/**
|
|
148007
147665
|
* TextDecoder instance.
|
|
148008
147666
|
* @type {TextDecoder|null}
|
|
148009
|
-
*/
|
|
148010
|
-
const DECODER = globalScope.TextDecoder ? new globalScope.TextDecoder("utf-8") : null;
|
|
148011
|
-
|
|
147667
|
+
*/ const DECODER = globalScope.TextDecoder ? new globalScope.TextDecoder() : null;
|
|
148012
147668
|
/**
|
|
148013
|
-
* Converts an UTF-8 string to an
|
|
147669
|
+
* Converts an UTF-8 string to an Uint8Array.
|
|
148014
147670
|
* @param {string} str String.
|
|
148015
|
-
* @returns {
|
|
148016
|
-
*/
|
|
148017
|
-
|
|
148018
|
-
|
|
148019
|
-
|
|
148020
|
-
|
|
148021
|
-
return ENCODER.encode(str).buffer;
|
|
147671
|
+
* @returns {Uint8Array} Uint8Array.
|
|
147672
|
+
*/ const utf8Decode = (str)=>{
|
|
147673
|
+
if (!ENCODER) {
|
|
147674
|
+
throw new Error("Encoding API not available");
|
|
147675
|
+
}
|
|
147676
|
+
return ENCODER.encode(str);
|
|
148022
147677
|
};
|
|
148023
|
-
|
|
148024
147678
|
/**
|
|
148025
|
-
* Converts an
|
|
148026
|
-
* @param {
|
|
147679
|
+
* Converts an Uint8Array to an UTF-8 string.
|
|
147680
|
+
* @param {Uint8Array} arr Uint8Array.
|
|
148027
147681
|
* @returns {string} String.
|
|
148028
|
-
*/
|
|
148029
|
-
|
|
148030
|
-
|
|
148031
|
-
|
|
148032
|
-
|
|
148033
|
-
return DECODER.decode(buf);
|
|
147682
|
+
*/ const utf8Encode = (arr)=>{
|
|
147683
|
+
if (!DECODER) {
|
|
147684
|
+
throw new Error("Encoding API not available");
|
|
147685
|
+
}
|
|
147686
|
+
return DECODER.decode(arr);
|
|
148034
147687
|
};
|
|
148035
147688
|
|
|
148036
147689
|
/**
|
|
148037
147690
|
* Returns random bytes.
|
|
148038
147691
|
* @param {number} size Size.
|
|
148039
|
-
* @returns {
|
|
148040
|
-
*/
|
|
148041
|
-
|
|
148042
|
-
|
|
148043
|
-
|
|
148044
|
-
|
|
147692
|
+
* @returns {Uint8Array} Random bytes.
|
|
147693
|
+
*/ const randomBytes = (size)=>{
|
|
147694
|
+
{
|
|
147695
|
+
if (!globalScope.crypto?.getRandomValues) {
|
|
147696
|
+
throw new Error("Cryptography API not available");
|
|
147697
|
+
}
|
|
147698
|
+
return globalScope.crypto.getRandomValues(new Uint8Array(size));
|
|
148045
147699
|
}
|
|
148046
|
-
return globalScope.crypto.getRandomValues(new Uint8Array(size)).buffer;
|
|
148047
|
-
}
|
|
148048
147700
|
};
|
|
148049
147701
|
|
|
148050
147702
|
/**
|
|
148051
147703
|
* OTP secret key.
|
|
148052
|
-
*/
|
|
148053
|
-
class Secret {
|
|
148054
|
-
/**
|
|
148055
|
-
* Creates a secret key object.
|
|
148056
|
-
* @param {Object} [config] Configuration options.
|
|
148057
|
-
* @param {ArrayBuffer} [config.buffer=randomBytes] Secret key.
|
|
148058
|
-
* @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
|
|
148059
|
-
*/
|
|
148060
|
-
constructor({
|
|
148061
|
-
buffer,
|
|
148062
|
-
size = 20
|
|
148063
|
-
} = {}) {
|
|
147704
|
+
*/ class Secret {
|
|
148064
147705
|
/**
|
|
148065
|
-
* Secret key.
|
|
148066
|
-
* @type {ArrayBuffer}
|
|
148067
|
-
*/
|
|
148068
|
-
this.buffer = typeof buffer === "undefined" ? randomBytes(size) : buffer;
|
|
148069
|
-
}
|
|
148070
|
-
|
|
148071
|
-
/**
|
|
148072
147706
|
* Converts a Latin-1 string to a Secret object.
|
|
148073
147707
|
* @param {string} str Latin-1 string.
|
|
148074
147708
|
* @returns {Secret} Secret object.
|
|
148075
|
-
*/
|
|
148076
|
-
|
|
148077
|
-
|
|
148078
|
-
|
|
148079
|
-
}
|
|
148080
|
-
|
|
148081
|
-
|
|
148082
|
-
/**
|
|
147709
|
+
*/ static fromLatin1(str) {
|
|
147710
|
+
return new Secret({
|
|
147711
|
+
buffer: latin1Decode(str).buffer
|
|
147712
|
+
});
|
|
147713
|
+
}
|
|
147714
|
+
/**
|
|
148083
147715
|
* Converts an UTF-8 string to a Secret object.
|
|
148084
147716
|
* @param {string} str UTF-8 string.
|
|
148085
147717
|
* @returns {Secret} Secret object.
|
|
148086
|
-
*/
|
|
148087
|
-
|
|
148088
|
-
|
|
148089
|
-
|
|
148090
|
-
}
|
|
148091
|
-
|
|
148092
|
-
|
|
148093
|
-
/**
|
|
147718
|
+
*/ static fromUTF8(str) {
|
|
147719
|
+
return new Secret({
|
|
147720
|
+
buffer: utf8Decode(str).buffer
|
|
147721
|
+
});
|
|
147722
|
+
}
|
|
147723
|
+
/**
|
|
148094
147724
|
* Converts a base32 string to a Secret object.
|
|
148095
147725
|
* @param {string} str Base32 string.
|
|
148096
147726
|
* @returns {Secret} Secret object.
|
|
148097
|
-
*/
|
|
148098
|
-
|
|
148099
|
-
|
|
148100
|
-
|
|
148101
|
-
}
|
|
148102
|
-
|
|
148103
|
-
|
|
148104
|
-
/**
|
|
147727
|
+
*/ static fromBase32(str) {
|
|
147728
|
+
return new Secret({
|
|
147729
|
+
buffer: base32Decode(str).buffer
|
|
147730
|
+
});
|
|
147731
|
+
}
|
|
147732
|
+
/**
|
|
148105
147733
|
* Converts a hexadecimal string to a Secret object.
|
|
148106
147734
|
* @param {string} str Hexadecimal string.
|
|
148107
147735
|
* @returns {Secret} Secret object.
|
|
148108
|
-
*/
|
|
148109
|
-
|
|
148110
|
-
|
|
148111
|
-
|
|
148112
|
-
}
|
|
148113
|
-
|
|
148114
|
-
|
|
148115
|
-
|
|
147736
|
+
*/ static fromHex(str) {
|
|
147737
|
+
return new Secret({
|
|
147738
|
+
buffer: hexDecode(str).buffer
|
|
147739
|
+
});
|
|
147740
|
+
}
|
|
147741
|
+
/**
|
|
147742
|
+
* Secret key buffer.
|
|
147743
|
+
* @deprecated For backward compatibility, the "bytes" property should be used instead.
|
|
147744
|
+
* @type {ArrayBufferLike}
|
|
147745
|
+
*/ get buffer() {
|
|
147746
|
+
return this.bytes.buffer;
|
|
147747
|
+
}
|
|
147748
|
+
/**
|
|
148116
147749
|
* Latin-1 string representation of secret key.
|
|
148117
147750
|
* @type {string}
|
|
148118
|
-
*/
|
|
148119
|
-
|
|
148120
|
-
|
|
148121
|
-
|
|
148122
|
-
|
|
148123
|
-
|
|
148124
|
-
|
|
148125
|
-
|
|
148126
|
-
|
|
148127
|
-
|
|
147751
|
+
*/ get latin1() {
|
|
147752
|
+
Object.defineProperty(this, "latin1", {
|
|
147753
|
+
enumerable: true,
|
|
147754
|
+
writable: false,
|
|
147755
|
+
configurable: false,
|
|
147756
|
+
value: latin1Encode(this.bytes)
|
|
147757
|
+
});
|
|
147758
|
+
return this.latin1;
|
|
147759
|
+
}
|
|
147760
|
+
/**
|
|
148128
147761
|
* UTF-8 string representation of secret key.
|
|
148129
147762
|
* @type {string}
|
|
148130
|
-
*/
|
|
148131
|
-
|
|
148132
|
-
|
|
148133
|
-
|
|
148134
|
-
|
|
148135
|
-
|
|
148136
|
-
|
|
148137
|
-
|
|
148138
|
-
|
|
148139
|
-
|
|
147763
|
+
*/ get utf8() {
|
|
147764
|
+
Object.defineProperty(this, "utf8", {
|
|
147765
|
+
enumerable: true,
|
|
147766
|
+
writable: false,
|
|
147767
|
+
configurable: false,
|
|
147768
|
+
value: utf8Encode(this.bytes)
|
|
147769
|
+
});
|
|
147770
|
+
return this.utf8;
|
|
147771
|
+
}
|
|
147772
|
+
/**
|
|
148140
147773
|
* Base32 string representation of secret key.
|
|
148141
147774
|
* @type {string}
|
|
148142
|
-
*/
|
|
148143
|
-
|
|
148144
|
-
|
|
148145
|
-
|
|
148146
|
-
|
|
148147
|
-
|
|
148148
|
-
|
|
148149
|
-
|
|
148150
|
-
|
|
148151
|
-
|
|
147775
|
+
*/ get base32() {
|
|
147776
|
+
Object.defineProperty(this, "base32", {
|
|
147777
|
+
enumerable: true,
|
|
147778
|
+
writable: false,
|
|
147779
|
+
configurable: false,
|
|
147780
|
+
value: base32Encode(this.bytes)
|
|
147781
|
+
});
|
|
147782
|
+
return this.base32;
|
|
147783
|
+
}
|
|
147784
|
+
/**
|
|
148152
147785
|
* Hexadecimal string representation of secret key.
|
|
148153
147786
|
* @type {string}
|
|
148154
|
-
*/
|
|
148155
|
-
|
|
148156
|
-
|
|
148157
|
-
|
|
148158
|
-
|
|
148159
|
-
|
|
148160
|
-
|
|
148161
|
-
|
|
147787
|
+
*/ get hex() {
|
|
147788
|
+
Object.defineProperty(this, "hex", {
|
|
147789
|
+
enumerable: true,
|
|
147790
|
+
writable: false,
|
|
147791
|
+
configurable: false,
|
|
147792
|
+
value: hexEncode(this.bytes)
|
|
147793
|
+
});
|
|
147794
|
+
return this.hex;
|
|
147795
|
+
}
|
|
147796
|
+
/**
|
|
147797
|
+
* Creates a secret key object.
|
|
147798
|
+
* @param {Object} [config] Configuration options.
|
|
147799
|
+
* @param {ArrayBufferLike} [config.buffer] Secret key buffer.
|
|
147800
|
+
* @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
|
|
147801
|
+
*/ constructor({ buffer, size = 20 } = {}){
|
|
147802
|
+
/**
|
|
147803
|
+
* Secret key.
|
|
147804
|
+
* @type {Uint8Array}
|
|
147805
|
+
* @readonly
|
|
147806
|
+
*/ this.bytes = typeof buffer === "undefined" ? randomBytes(size) : new Uint8Array(buffer);
|
|
147807
|
+
// Prevent the "bytes" property from being modified.
|
|
147808
|
+
Object.defineProperty(this, "bytes", {
|
|
147809
|
+
enumerable: true,
|
|
147810
|
+
writable: false,
|
|
147811
|
+
configurable: false,
|
|
147812
|
+
value: this.bytes
|
|
147813
|
+
});
|
|
147814
|
+
}
|
|
148162
147815
|
}
|
|
148163
147816
|
|
|
148164
147817
|
/**
|
|
@@ -148166,27 +147819,25 @@ class Secret {
|
|
|
148166
147819
|
* @param {string} a String a.
|
|
148167
147820
|
* @param {string} b String b.
|
|
148168
147821
|
* @returns {boolean} Equality result.
|
|
148169
|
-
*/
|
|
148170
|
-
|
|
148171
|
-
|
|
148172
|
-
|
|
148173
|
-
|
|
148174
|
-
|
|
148175
|
-
|
|
148176
|
-
|
|
148177
|
-
|
|
148178
|
-
|
|
147822
|
+
*/ const timingSafeEqual = (a, b)=>{
|
|
147823
|
+
{
|
|
147824
|
+
if (a.length !== b.length) {
|
|
147825
|
+
throw new TypeError("Input strings must have the same length");
|
|
147826
|
+
}
|
|
147827
|
+
let i = -1;
|
|
147828
|
+
let out = 0;
|
|
147829
|
+
while(++i < a.length){
|
|
147830
|
+
out |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
147831
|
+
}
|
|
147832
|
+
return out === 0;
|
|
148179
147833
|
}
|
|
148180
|
-
return out === 0;
|
|
148181
|
-
}
|
|
148182
147834
|
};
|
|
148183
147835
|
|
|
148184
147836
|
/**
|
|
148185
147837
|
* HOTP: An HMAC-based One-time Password Algorithm.
|
|
148186
147838
|
* @see [RFC 4226](https://tools.ietf.org/html/rfc4226)
|
|
148187
|
-
*/
|
|
148188
|
-
|
|
148189
|
-
/**
|
|
147839
|
+
*/ class HOTP {
|
|
147840
|
+
/**
|
|
148190
147841
|
* Default configuration.
|
|
148191
147842
|
* @type {{
|
|
148192
147843
|
* issuer: string,
|
|
@@ -148197,77 +147848,18 @@ class HOTP {
|
|
|
148197
147848
|
* counter: number
|
|
148198
147849
|
* window: number
|
|
148199
147850
|
* }}
|
|
148200
|
-
*/
|
|
148201
|
-
|
|
148202
|
-
|
|
148203
|
-
|
|
148204
|
-
|
|
148205
|
-
|
|
148206
|
-
|
|
148207
|
-
|
|
148208
|
-
|
|
148209
|
-
|
|
148210
|
-
}
|
|
148211
|
-
}
|
|
148212
|
-
|
|
148213
|
-
/**
|
|
148214
|
-
* Creates an HOTP object.
|
|
148215
|
-
* @param {Object} [config] Configuration options.
|
|
148216
|
-
* @param {string} [config.issuer=''] Account provider.
|
|
148217
|
-
* @param {string} [config.label='OTPAuth'] Account label.
|
|
148218
|
-
* @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
|
|
148219
|
-
* @param {Secret|string} [config.secret=Secret] Secret key.
|
|
148220
|
-
* @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
|
|
148221
|
-
* @param {number} [config.digits=6] Token length.
|
|
148222
|
-
* @param {number} [config.counter=0] Initial counter value.
|
|
148223
|
-
*/
|
|
148224
|
-
constructor({
|
|
148225
|
-
issuer = HOTP.defaults.issuer,
|
|
148226
|
-
label = HOTP.defaults.label,
|
|
148227
|
-
issuerInLabel = HOTP.defaults.issuerInLabel,
|
|
148228
|
-
secret = new Secret(),
|
|
148229
|
-
algorithm = HOTP.defaults.algorithm,
|
|
148230
|
-
digits = HOTP.defaults.digits,
|
|
148231
|
-
counter = HOTP.defaults.counter
|
|
148232
|
-
} = {}) {
|
|
148233
|
-
/**
|
|
148234
|
-
* Account provider.
|
|
148235
|
-
* @type {string}
|
|
148236
|
-
*/
|
|
148237
|
-
this.issuer = issuer;
|
|
148238
|
-
/**
|
|
148239
|
-
* Account label.
|
|
148240
|
-
* @type {string}
|
|
148241
|
-
*/
|
|
148242
|
-
this.label = label;
|
|
148243
|
-
/**
|
|
148244
|
-
* Include issuer prefix in label.
|
|
148245
|
-
* @type {boolean}
|
|
148246
|
-
*/
|
|
148247
|
-
this.issuerInLabel = issuerInLabel;
|
|
148248
|
-
/**
|
|
148249
|
-
* Secret key.
|
|
148250
|
-
* @type {Secret}
|
|
148251
|
-
*/
|
|
148252
|
-
this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
|
|
148253
|
-
/**
|
|
148254
|
-
* HMAC hashing algorithm.
|
|
148255
|
-
* @type {string}
|
|
148256
|
-
*/
|
|
148257
|
-
this.algorithm = algorithm.toUpperCase();
|
|
148258
|
-
/**
|
|
148259
|
-
* Token length.
|
|
148260
|
-
* @type {number}
|
|
148261
|
-
*/
|
|
148262
|
-
this.digits = digits;
|
|
147851
|
+
*/ static get defaults() {
|
|
147852
|
+
return {
|
|
147853
|
+
issuer: "",
|
|
147854
|
+
label: "OTPAuth",
|
|
147855
|
+
issuerInLabel: true,
|
|
147856
|
+
algorithm: "SHA1",
|
|
147857
|
+
digits: 6,
|
|
147858
|
+
counter: 0,
|
|
147859
|
+
window: 1
|
|
147860
|
+
};
|
|
147861
|
+
}
|
|
148263
147862
|
/**
|
|
148264
|
-
* Initial counter value.
|
|
148265
|
-
* @type {number}
|
|
148266
|
-
*/
|
|
148267
|
-
this.counter = counter;
|
|
148268
|
-
}
|
|
148269
|
-
|
|
148270
|
-
/**
|
|
148271
147863
|
* Generates an HOTP token.
|
|
148272
147864
|
* @param {Object} config Configuration options.
|
|
148273
147865
|
* @param {Secret} config.secret Secret key.
|
|
@@ -148275,37 +147867,26 @@ class HOTP {
|
|
|
148275
147867
|
* @param {number} [config.digits=6] Token length.
|
|
148276
147868
|
* @param {number} [config.counter=0] Counter value.
|
|
148277
147869
|
* @returns {string} Token.
|
|
148278
|
-
*/
|
|
148279
|
-
|
|
148280
|
-
|
|
148281
|
-
|
|
148282
|
-
|
|
148283
|
-
|
|
148284
|
-
|
|
148285
|
-
const digest = new Uint8Array(hmacDigest(algorithm, secret.buffer, uintToBuf(counter)));
|
|
148286
|
-
const offset = digest[digest.byteLength - 1] & 15;
|
|
148287
|
-
const otp = ((digest[offset] & 127) << 24 | (digest[offset + 1] & 255) << 16 | (digest[offset + 2] & 255) << 8 | digest[offset + 3] & 255) % 10 ** digits;
|
|
148288
|
-
return otp.toString().padStart(digits, "0");
|
|
148289
|
-
}
|
|
148290
|
-
|
|
148291
|
-
/**
|
|
147870
|
+
*/ static generate({ secret, algorithm = HOTP.defaults.algorithm, digits = HOTP.defaults.digits, counter = HOTP.defaults.counter }) {
|
|
147871
|
+
const digest = hmacDigest(algorithm, secret.bytes, uintDecode(counter));
|
|
147872
|
+
const offset = digest[digest.byteLength - 1] & 15;
|
|
147873
|
+
const otp = ((digest[offset] & 127) << 24 | (digest[offset + 1] & 255) << 16 | (digest[offset + 2] & 255) << 8 | digest[offset + 3] & 255) % 10 ** digits;
|
|
147874
|
+
return otp.toString().padStart(digits, "0");
|
|
147875
|
+
}
|
|
147876
|
+
/**
|
|
148292
147877
|
* Generates an HOTP token.
|
|
148293
147878
|
* @param {Object} [config] Configuration options.
|
|
148294
147879
|
* @param {number} [config.counter=this.counter++] Counter value.
|
|
148295
147880
|
* @returns {string} Token.
|
|
148296
|
-
*/
|
|
148297
|
-
|
|
148298
|
-
|
|
148299
|
-
|
|
148300
|
-
|
|
148301
|
-
|
|
148302
|
-
|
|
148303
|
-
|
|
148304
|
-
|
|
148305
|
-
});
|
|
148306
|
-
}
|
|
148307
|
-
|
|
148308
|
-
/**
|
|
147881
|
+
*/ generate({ counter = this.counter++ } = {}) {
|
|
147882
|
+
return HOTP.generate({
|
|
147883
|
+
secret: this.secret,
|
|
147884
|
+
algorithm: this.algorithm,
|
|
147885
|
+
digits: this.digits,
|
|
147886
|
+
counter
|
|
147887
|
+
});
|
|
147888
|
+
}
|
|
147889
|
+
/**
|
|
148309
147890
|
* Validates an HOTP token.
|
|
148310
147891
|
* @param {Object} config Configuration options.
|
|
148311
147892
|
* @param {string} config.token Token value.
|
|
@@ -148315,103 +147896,56 @@ class HOTP {
|
|
|
148315
147896
|
* @param {number} [config.counter=0] Counter value.
|
|
148316
147897
|
* @param {number} [config.window=1] Window of counter values to test.
|
|
148317
147898
|
* @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
|
|
148318
|
-
*/
|
|
148319
|
-
|
|
148320
|
-
|
|
148321
|
-
|
|
148322
|
-
|
|
148323
|
-
|
|
148324
|
-
|
|
148325
|
-
|
|
148326
|
-
|
|
148327
|
-
|
|
148328
|
-
|
|
148329
|
-
|
|
148330
|
-
|
|
148331
|
-
|
|
148332
|
-
|
|
148333
|
-
|
|
148334
|
-
|
|
148335
|
-
|
|
148336
|
-
|
|
148337
|
-
|
|
148338
|
-
|
|
148339
|
-
|
|
148340
|
-
|
|
148341
|
-
check(counter);
|
|
148342
|
-
for (let i = 1; i <= window && delta === null; ++i) {
|
|
148343
|
-
check(counter - i);
|
|
148344
|
-
if (delta !== null) break;
|
|
148345
|
-
check(counter + i);
|
|
148346
|
-
if (delta !== null) break;
|
|
147899
|
+
*/ static validate({ token, secret, algorithm, digits, counter = HOTP.defaults.counter, window = HOTP.defaults.window }) {
|
|
147900
|
+
// Return early if the token length does not match the digit number.
|
|
147901
|
+
if (token.length !== digits) return null;
|
|
147902
|
+
let delta = null;
|
|
147903
|
+
const check = (/** @type {number} */ i)=>{
|
|
147904
|
+
const generatedToken = HOTP.generate({
|
|
147905
|
+
secret,
|
|
147906
|
+
algorithm,
|
|
147907
|
+
digits,
|
|
147908
|
+
counter: i
|
|
147909
|
+
});
|
|
147910
|
+
if (timingSafeEqual(token, generatedToken)) {
|
|
147911
|
+
delta = i - counter;
|
|
147912
|
+
}
|
|
147913
|
+
};
|
|
147914
|
+
check(counter);
|
|
147915
|
+
for(let i = 1; i <= window && delta === null; ++i){
|
|
147916
|
+
check(counter - i);
|
|
147917
|
+
if (delta !== null) break;
|
|
147918
|
+
check(counter + i);
|
|
147919
|
+
if (delta !== null) break;
|
|
147920
|
+
}
|
|
147921
|
+
return delta;
|
|
148347
147922
|
}
|
|
148348
|
-
|
|
148349
|
-
}
|
|
148350
|
-
|
|
148351
|
-
/**
|
|
147923
|
+
/**
|
|
148352
147924
|
* Validates an HOTP token.
|
|
148353
147925
|
* @param {Object} config Configuration options.
|
|
148354
147926
|
* @param {string} config.token Token value.
|
|
148355
147927
|
* @param {number} [config.counter=this.counter] Counter value.
|
|
148356
147928
|
* @param {number} [config.window=1] Window of counter values to test.
|
|
148357
147929
|
* @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
|
|
148358
|
-
*/
|
|
148359
|
-
|
|
148360
|
-
|
|
148361
|
-
|
|
148362
|
-
|
|
148363
|
-
|
|
148364
|
-
|
|
148365
|
-
|
|
148366
|
-
|
|
148367
|
-
|
|
148368
|
-
|
|
148369
|
-
counter,
|
|
148370
|
-
window
|
|
148371
|
-
});
|
|
148372
|
-
}
|
|
148373
|
-
|
|
148374
|
-
/**
|
|
147930
|
+
*/ validate({ token, counter = this.counter, window }) {
|
|
147931
|
+
return HOTP.validate({
|
|
147932
|
+
token,
|
|
147933
|
+
secret: this.secret,
|
|
147934
|
+
algorithm: this.algorithm,
|
|
147935
|
+
digits: this.digits,
|
|
147936
|
+
counter,
|
|
147937
|
+
window
|
|
147938
|
+
});
|
|
147939
|
+
}
|
|
147940
|
+
/**
|
|
148375
147941
|
* Returns a Google Authenticator key URI.
|
|
148376
147942
|
* @returns {string} URI.
|
|
148377
|
-
*/
|
|
148378
|
-
|
|
148379
|
-
|
|
148380
|
-
|
|
148381
|
-
|
|
148382
|
-
|
|
148383
|
-
|
|
148384
|
-
/**
|
|
148385
|
-
* TOTP: Time-Based One-Time Password Algorithm.
|
|
148386
|
-
* @see [RFC 6238](https://tools.ietf.org/html/rfc6238)
|
|
148387
|
-
*/
|
|
148388
|
-
class TOTP {
|
|
148389
|
-
/**
|
|
148390
|
-
* Default configuration.
|
|
148391
|
-
* @type {{
|
|
148392
|
-
* issuer: string,
|
|
148393
|
-
* label: string,
|
|
148394
|
-
* issuerInLabel: boolean,
|
|
148395
|
-
* algorithm: string,
|
|
148396
|
-
* digits: number,
|
|
148397
|
-
* period: number
|
|
148398
|
-
* window: number
|
|
148399
|
-
* }}
|
|
148400
|
-
*/
|
|
148401
|
-
static get defaults() {
|
|
148402
|
-
return {
|
|
148403
|
-
issuer: "",
|
|
148404
|
-
label: "OTPAuth",
|
|
148405
|
-
issuerInLabel: true,
|
|
148406
|
-
algorithm: "SHA1",
|
|
148407
|
-
digits: 6,
|
|
148408
|
-
period: 30,
|
|
148409
|
-
window: 1
|
|
148410
|
-
};
|
|
148411
|
-
}
|
|
148412
|
-
|
|
148413
|
-
/**
|
|
148414
|
-
* Creates a TOTP object.
|
|
147943
|
+
*/ toString() {
|
|
147944
|
+
const e = encodeURIComponent;
|
|
147945
|
+
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)}`;
|
|
147946
|
+
}
|
|
147947
|
+
/**
|
|
147948
|
+
* Creates an HOTP object.
|
|
148415
147949
|
* @param {Object} [config] Configuration options.
|
|
148416
147950
|
* @param {string} [config.issuer=''] Account provider.
|
|
148417
147951
|
* @param {string} [config.label='OTPAuth'] Account label.
|
|
@@ -148419,55 +147953,66 @@ class TOTP {
|
|
|
148419
147953
|
* @param {Secret|string} [config.secret=Secret] Secret key.
|
|
148420
147954
|
* @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
|
|
148421
147955
|
* @param {number} [config.digits=6] Token length.
|
|
148422
|
-
* @param {number} [config.
|
|
148423
|
-
*/
|
|
148424
|
-
|
|
148425
|
-
issuer = TOTP.defaults.issuer,
|
|
148426
|
-
label = TOTP.defaults.label,
|
|
148427
|
-
issuerInLabel = TOTP.defaults.issuerInLabel,
|
|
148428
|
-
secret = new Secret(),
|
|
148429
|
-
algorithm = TOTP.defaults.algorithm,
|
|
148430
|
-
digits = TOTP.defaults.digits,
|
|
148431
|
-
period = TOTP.defaults.period
|
|
148432
|
-
} = {}) {
|
|
148433
|
-
/**
|
|
147956
|
+
* @param {number} [config.counter=0] Initial counter value.
|
|
147957
|
+
*/ 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 } = {}){
|
|
147958
|
+
/**
|
|
148434
147959
|
* Account provider.
|
|
148435
147960
|
* @type {string}
|
|
148436
|
-
*/
|
|
148437
|
-
|
|
148438
|
-
/**
|
|
147961
|
+
*/ this.issuer = issuer;
|
|
147962
|
+
/**
|
|
148439
147963
|
* Account label.
|
|
148440
147964
|
* @type {string}
|
|
148441
|
-
*/
|
|
148442
|
-
|
|
148443
|
-
/**
|
|
147965
|
+
*/ this.label = label;
|
|
147966
|
+
/**
|
|
148444
147967
|
* Include issuer prefix in label.
|
|
148445
147968
|
* @type {boolean}
|
|
148446
|
-
*/
|
|
148447
|
-
|
|
148448
|
-
/**
|
|
147969
|
+
*/ this.issuerInLabel = issuerInLabel;
|
|
147970
|
+
/**
|
|
148449
147971
|
* Secret key.
|
|
148450
147972
|
* @type {Secret}
|
|
148451
|
-
*/
|
|
148452
|
-
|
|
148453
|
-
/**
|
|
147973
|
+
*/ this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
|
|
147974
|
+
/**
|
|
148454
147975
|
* HMAC hashing algorithm.
|
|
148455
147976
|
* @type {string}
|
|
148456
|
-
*/
|
|
148457
|
-
|
|
148458
|
-
/**
|
|
147977
|
+
*/ this.algorithm = algorithm.toUpperCase();
|
|
147978
|
+
/**
|
|
148459
147979
|
* Token length.
|
|
148460
147980
|
* @type {number}
|
|
148461
|
-
*/
|
|
148462
|
-
|
|
148463
|
-
|
|
148464
|
-
* Token time-step duration.
|
|
147981
|
+
*/ this.digits = digits;
|
|
147982
|
+
/**
|
|
147983
|
+
* Initial counter value.
|
|
148465
147984
|
* @type {number}
|
|
148466
|
-
*/
|
|
148467
|
-
|
|
148468
|
-
|
|
147985
|
+
*/ this.counter = counter;
|
|
147986
|
+
}
|
|
147987
|
+
}
|
|
148469
147988
|
|
|
148470
|
-
|
|
147989
|
+
/**
|
|
147990
|
+
* TOTP: Time-Based One-Time Password Algorithm.
|
|
147991
|
+
* @see [RFC 6238](https://tools.ietf.org/html/rfc6238)
|
|
147992
|
+
*/ class TOTP {
|
|
147993
|
+
/**
|
|
147994
|
+
* Default configuration.
|
|
147995
|
+
* @type {{
|
|
147996
|
+
* issuer: string,
|
|
147997
|
+
* label: string,
|
|
147998
|
+
* issuerInLabel: boolean,
|
|
147999
|
+
* algorithm: string,
|
|
148000
|
+
* digits: number,
|
|
148001
|
+
* period: number
|
|
148002
|
+
* window: number
|
|
148003
|
+
* }}
|
|
148004
|
+
*/ static get defaults() {
|
|
148005
|
+
return {
|
|
148006
|
+
issuer: "",
|
|
148007
|
+
label: "OTPAuth",
|
|
148008
|
+
issuerInLabel: true,
|
|
148009
|
+
algorithm: "SHA1",
|
|
148010
|
+
digits: 6,
|
|
148011
|
+
period: 30,
|
|
148012
|
+
window: 1
|
|
148013
|
+
};
|
|
148014
|
+
}
|
|
148015
|
+
/**
|
|
148471
148016
|
* Generates a TOTP token.
|
|
148472
148017
|
* @param {Object} config Configuration options.
|
|
148473
148018
|
* @param {Secret} config.secret Secret key.
|
|
@@ -148476,41 +148021,29 @@ class TOTP {
|
|
|
148476
148021
|
* @param {number} [config.period=30] Token time-step duration.
|
|
148477
148022
|
* @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
|
|
148478
148023
|
* @returns {string} Token.
|
|
148479
|
-
*/
|
|
148480
|
-
|
|
148481
|
-
|
|
148482
|
-
|
|
148483
|
-
|
|
148484
|
-
|
|
148485
|
-
|
|
148486
|
-
|
|
148487
|
-
|
|
148488
|
-
secret,
|
|
148489
|
-
algorithm,
|
|
148490
|
-
digits,
|
|
148491
|
-
counter: Math.floor(timestamp / 1000 / period)
|
|
148492
|
-
});
|
|
148493
|
-
}
|
|
148494
|
-
|
|
148495
|
-
/**
|
|
148024
|
+
*/ static generate({ secret, algorithm, digits, period = TOTP.defaults.period, timestamp = Date.now() }) {
|
|
148025
|
+
return HOTP.generate({
|
|
148026
|
+
secret,
|
|
148027
|
+
algorithm,
|
|
148028
|
+
digits,
|
|
148029
|
+
counter: Math.floor(timestamp / 1000 / period)
|
|
148030
|
+
});
|
|
148031
|
+
}
|
|
148032
|
+
/**
|
|
148496
148033
|
* Generates a TOTP token.
|
|
148497
148034
|
* @param {Object} [config] Configuration options.
|
|
148498
148035
|
* @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
|
|
148499
148036
|
* @returns {string} Token.
|
|
148500
|
-
*/
|
|
148501
|
-
|
|
148502
|
-
|
|
148503
|
-
|
|
148504
|
-
|
|
148505
|
-
|
|
148506
|
-
|
|
148507
|
-
|
|
148508
|
-
|
|
148509
|
-
|
|
148510
|
-
});
|
|
148511
|
-
}
|
|
148512
|
-
|
|
148513
|
-
/**
|
|
148037
|
+
*/ generate({ timestamp = Date.now() } = {}) {
|
|
148038
|
+
return TOTP.generate({
|
|
148039
|
+
secret: this.secret,
|
|
148040
|
+
algorithm: this.algorithm,
|
|
148041
|
+
digits: this.digits,
|
|
148042
|
+
period: this.period,
|
|
148043
|
+
timestamp
|
|
148044
|
+
});
|
|
148045
|
+
}
|
|
148046
|
+
/**
|
|
148514
148047
|
* Validates a TOTP token.
|
|
148515
148048
|
* @param {Object} config Configuration options.
|
|
148516
148049
|
* @param {string} config.token Token value.
|
|
@@ -148521,58 +148054,81 @@ class TOTP {
|
|
|
148521
148054
|
* @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
|
|
148522
148055
|
* @param {number} [config.window=1] Window of counter values to test.
|
|
148523
148056
|
* @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
|
|
148524
|
-
*/
|
|
148525
|
-
|
|
148526
|
-
|
|
148527
|
-
|
|
148528
|
-
|
|
148529
|
-
|
|
148530
|
-
|
|
148531
|
-
|
|
148532
|
-
|
|
148533
|
-
|
|
148534
|
-
|
|
148535
|
-
token,
|
|
148536
|
-
secret,
|
|
148537
|
-
algorithm,
|
|
148538
|
-
digits,
|
|
148539
|
-
counter: Math.floor(timestamp / 1000 / period),
|
|
148540
|
-
window
|
|
148541
|
-
});
|
|
148542
|
-
}
|
|
148543
|
-
|
|
148544
|
-
/**
|
|
148057
|
+
*/ static validate({ token, secret, algorithm, digits, period = TOTP.defaults.period, timestamp = Date.now(), window }) {
|
|
148058
|
+
return HOTP.validate({
|
|
148059
|
+
token,
|
|
148060
|
+
secret,
|
|
148061
|
+
algorithm,
|
|
148062
|
+
digits,
|
|
148063
|
+
counter: Math.floor(timestamp / 1000 / period),
|
|
148064
|
+
window
|
|
148065
|
+
});
|
|
148066
|
+
}
|
|
148067
|
+
/**
|
|
148545
148068
|
* Validates a TOTP token.
|
|
148546
148069
|
* @param {Object} config Configuration options.
|
|
148547
148070
|
* @param {string} config.token Token value.
|
|
148548
148071
|
* @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
|
|
148549
148072
|
* @param {number} [config.window=1] Window of counter values to test.
|
|
148550
148073
|
* @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
|
|
148551
|
-
*/
|
|
148552
|
-
|
|
148553
|
-
|
|
148554
|
-
|
|
148555
|
-
|
|
148556
|
-
|
|
148557
|
-
|
|
148558
|
-
|
|
148559
|
-
|
|
148560
|
-
|
|
148561
|
-
|
|
148562
|
-
|
|
148563
|
-
timestamp,
|
|
148564
|
-
window
|
|
148565
|
-
});
|
|
148566
|
-
}
|
|
148567
|
-
|
|
148568
|
-
/**
|
|
148074
|
+
*/ validate({ token, timestamp, window }) {
|
|
148075
|
+
return TOTP.validate({
|
|
148076
|
+
token,
|
|
148077
|
+
secret: this.secret,
|
|
148078
|
+
algorithm: this.algorithm,
|
|
148079
|
+
digits: this.digits,
|
|
148080
|
+
period: this.period,
|
|
148081
|
+
timestamp,
|
|
148082
|
+
window
|
|
148083
|
+
});
|
|
148084
|
+
}
|
|
148085
|
+
/**
|
|
148569
148086
|
* Returns a Google Authenticator key URI.
|
|
148570
148087
|
* @returns {string} URI.
|
|
148571
|
-
*/
|
|
148572
|
-
|
|
148573
|
-
|
|
148574
|
-
|
|
148575
|
-
|
|
148088
|
+
*/ toString() {
|
|
148089
|
+
const e = encodeURIComponent;
|
|
148090
|
+
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)}`;
|
|
148091
|
+
}
|
|
148092
|
+
/**
|
|
148093
|
+
* Creates a TOTP object.
|
|
148094
|
+
* @param {Object} [config] Configuration options.
|
|
148095
|
+
* @param {string} [config.issuer=''] Account provider.
|
|
148096
|
+
* @param {string} [config.label='OTPAuth'] Account label.
|
|
148097
|
+
* @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
|
|
148098
|
+
* @param {Secret|string} [config.secret=Secret] Secret key.
|
|
148099
|
+
* @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
|
|
148100
|
+
* @param {number} [config.digits=6] Token length.
|
|
148101
|
+
* @param {number} [config.period=30] Token time-step duration.
|
|
148102
|
+
*/ 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 } = {}){
|
|
148103
|
+
/**
|
|
148104
|
+
* Account provider.
|
|
148105
|
+
* @type {string}
|
|
148106
|
+
*/ this.issuer = issuer;
|
|
148107
|
+
/**
|
|
148108
|
+
* Account label.
|
|
148109
|
+
* @type {string}
|
|
148110
|
+
*/ this.label = label;
|
|
148111
|
+
/**
|
|
148112
|
+
* Include issuer prefix in label.
|
|
148113
|
+
* @type {boolean}
|
|
148114
|
+
*/ this.issuerInLabel = issuerInLabel;
|
|
148115
|
+
/**
|
|
148116
|
+
* Secret key.
|
|
148117
|
+
* @type {Secret}
|
|
148118
|
+
*/ this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
|
|
148119
|
+
/**
|
|
148120
|
+
* HMAC hashing algorithm.
|
|
148121
|
+
* @type {string}
|
|
148122
|
+
*/ this.algorithm = algorithm.toUpperCase();
|
|
148123
|
+
/**
|
|
148124
|
+
* Token length.
|
|
148125
|
+
* @type {number}
|
|
148126
|
+
*/ this.digits = digits;
|
|
148127
|
+
/**
|
|
148128
|
+
* Token time-step duration.
|
|
148129
|
+
* @type {number}
|
|
148130
|
+
*/ this.period = period;
|
|
148131
|
+
}
|
|
148576
148132
|
}
|
|
148577
148133
|
|
|
148578
148134
|
const initializeTotp = ({ issuer, secret, }) => {
|
|
@@ -149300,7 +148856,7 @@ exports.CREDENTIALS = CREDENTIALS;
|
|
|
149300
148856
|
exports.CustomCommands = CustomCommands;
|
|
149301
148857
|
exports.DESCRIPTION_EDITOR_TEXTS = DESCRIPTION_EDITOR_TEXTS;
|
|
149302
148858
|
exports.EMBED_SELECTORS = EMBED_SELECTORS;
|
|
149303
|
-
exports.
|
|
148859
|
+
exports.EMOJI_LABEL = EMOJI_LABEL;
|
|
149304
148860
|
exports.ENVIRONMENT = ENVIRONMENT;
|
|
149305
148861
|
exports.EXPANDED_FONT_SIZE = EXPANDED_FONT_SIZE;
|
|
149306
148862
|
exports.EditorPage = EditorPage;
|