@prosopo/procaptcha-bundle 2.5.3 → 2.6.1
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/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/index.js +15 -17
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js +23 -27
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js.map +1 -0
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts +2 -2
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js +4 -7
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js.map +1 -0
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.d.ts +5 -0
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.js.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js.map +1 -0
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.d.ts +2 -2
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js +9 -4
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js.map +1 -0
- package/CHANGELOG.md +29 -0
- package/dist/bundle/ProcaptchaWidget-3gKvjeiH.js +636 -0
- package/dist/bundle/ProcaptchaWidget-D6-M7iAv.js +360 -0
- package/dist/bundle/{asU8a-JliaME7-.js → asU8a-DCECA0Qe.js} +1 -1
- package/dist/bundle/bip39-BQoZog_M.js +365 -0
- package/dist/bundle/captchaComponentProvider-BW2eXmc3.js +1242 -0
- package/dist/bundle/captchaRenderer-B_MgGzr9.js +70 -0
- package/dist/bundle/{emotion-element-5486c51c.browser.esm-Bywq83R5.js → emotion-element-5486c51c.browser.esm-CCAJ8JId.js} +713 -746
- package/dist/bundle/{fp.esm-C0kLYOiJ.js → fp.esm-DYWeNGcH.js} +17 -0
- package/dist/bundle/{hash-CtL1HOjf.js → hash-BR0YLxPF.js} +796 -483
- package/dist/bundle/{i18nFrontend-C_RgmvGh.js → i18nFrontend-CsPT71ro.js} +1 -1
- package/dist/bundle/index-2or4-1WF.js +596 -0
- package/dist/bundle/{captchaRenderer-D-du50M4.js → index-BCjHZ8o6.js} +1293 -1355
- package/dist/bundle/{index-DcG_c-Na.js → index-BYUYvvuq.js} +11 -11
- package/dist/bundle/index-BjRdPnnE.js +1198 -0
- package/dist/bundle/index-WqEmiYQ_.js +4386 -0
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/locales/ar/translation.json +56 -0
- package/dist/bundle/locales/az/translation.json +56 -0
- package/dist/bundle/locales/cs/translation.json +56 -0
- package/dist/bundle/locales/de/translation.json +55 -405
- package/dist/bundle/locales/el/translation.json +56 -0
- package/dist/bundle/locales/en/translation.json +55 -405
- package/dist/bundle/locales/es/translation.json +55 -405
- package/dist/bundle/locales/fi/translation.json +56 -0
- package/dist/bundle/locales/fr/translation.json +55 -405
- package/dist/bundle/locales/hi/translation.json +56 -0
- package/dist/bundle/locales/hu/translation.json +56 -0
- package/dist/bundle/locales/id/translation.json +56 -0
- package/dist/bundle/locales/it/translation.json +55 -405
- package/dist/bundle/locales/ja/translation.json +56 -0
- package/dist/bundle/locales/jv/translation.json +56 -0
- package/dist/bundle/locales/ko/translation.json +56 -0
- package/dist/bundle/locales/ml/translation.json +56 -0
- package/dist/bundle/locales/ms/translation.json +56 -0
- package/dist/bundle/locales/nl/translation.json +56 -0
- package/dist/bundle/locales/no/translation.json +56 -0
- package/dist/bundle/locales/pl/translation.json +56 -0
- package/dist/bundle/locales/pt/translation.json +55 -405
- package/dist/bundle/locales/pt-br/translation.json +56 -0
- package/dist/bundle/locales/ro/translation.json +56 -0
- package/dist/bundle/locales/ru/translation.json +56 -0
- package/dist/bundle/locales/sr/translation.json +56 -0
- package/dist/bundle/locales/sv/translation.json +56 -0
- package/dist/bundle/locales/th/translation.json +56 -0
- package/dist/bundle/locales/tr/translation.json +56 -0
- package/dist/bundle/locales/uk/translation.json +56 -0
- package/dist/bundle/locales/vi/translation.json +56 -0
- package/dist/bundle/locales/zh-cn/translation.json +56 -0
- package/dist/bundle/procaptcha.bundle.js +1 -1
- package/dist/bundle/toU8a-C68WUzs_.js +24 -0
- package/dist/bundle/{translations-B0P9axY3.js → translations-DEL070wJ.js} +59 -26
- package/dist/bundle/{useTranslation-7b6JJ18N.js → useTranslation-BPbGzrhj.js} +3 -3
- package/dist/bundle/util/captcha/captchaRenderer.d.ts +2 -2
- package/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
- package/dist/bundle/util/configCreator.d.ts +2 -2
- package/dist/bundle/util/configCreator.d.ts.map +1 -1
- package/dist/bundle/util/widgetFactory.d.ts +2 -2
- package/dist/bundle/util/widgetFactory.d.ts.map +1 -1
- package/dist/cjs/index.cjs +163 -0
- package/dist/cjs/util/captcha/captchaComponentProvider.cjs +19 -0
- package/dist/cjs/util/captcha/captchaComponentsList.cjs +12 -0
- package/dist/cjs/util/captcha/captchaRenderer.cjs +65 -0
- package/dist/cjs/util/captcha/captchaType.cjs +12 -0
- package/dist/cjs/util/captcha/components/frictionlessCaptcha.cjs +24 -0
- package/dist/cjs/util/captcha/components/imageCaptcha.cjs +17 -0
- package/dist/cjs/util/captcha/components/powCaptcha.cjs +17 -0
- package/dist/cjs/util/config.cjs +16 -0
- package/dist/cjs/util/configCreator.cjs +23 -0
- package/dist/cjs/util/language.cjs +18 -0
- package/dist/cjs/util/timeout.cjs +14 -0
- package/dist/cjs/util/widgetFactory.cjs +84 -0
- package/dist/cjs/util/widgetThemeResolver.cjs +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -17
- package/dist/index.js.map +1 -1
- package/dist/tests/util/renderLogic.test.js +23 -27
- package/dist/tests/util/renderLogic.test.js.map +1 -1
- package/dist/util/captcha/captchaRenderer.d.ts +2 -2
- package/dist/util/captcha/captchaRenderer.d.ts.map +1 -1
- package/dist/util/captcha/captchaRenderer.js +4 -7
- package/dist/util/captcha/captchaRenderer.js.map +1 -1
- package/dist/util/configCreator.d.ts +2 -2
- package/dist/util/configCreator.d.ts.map +1 -1
- package/dist/util/configCreator.js.map +1 -1
- package/dist/util/language.js.map +1 -1
- package/dist/util/widgetFactory.d.ts +2 -2
- package/dist/util/widgetFactory.d.ts.map +1 -1
- package/dist/util/widgetFactory.js +9 -4
- package/dist/util/widgetFactory.js.map +1 -1
- package/package.json +25 -16
- package/stats.html +1 -1
- package/vite.config.ts +18 -3
- package/vite.serve.config.ts +24 -0
- package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js.map +0 -1
- package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js.map +0 -1
- package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.d.ts +0 -5
- package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js.map +0 -1
- package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js.map +0 -1
- package/dist/bundle/ProcaptchaWidget-BlWWnPeB.js +0 -615
- package/dist/bundle/ProcaptchaWidget-Dnwno-4N.js +0 -156
- package/dist/bundle/bip39-CFjno8fK.js +0 -260
- package/dist/bundle/captchaComponentProvider-dcMua0p9.js +0 -1013
- package/dist/bundle/index-B8oMghZ3.js +0 -1120
- package/dist/bundle/index-BMjJnq60.js +0 -4373
- package/dist/bundle/index-BTlHNFX8.js +0 -504
- package/dist/bundle/locales/pt-BR/translation.json +0 -406
- package/dist/bundle/sha256-Cxc9Hrlx.js +0 -171
- package/dist/bundle/toU8a-BWKf-2UU.js +0 -133
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/components.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/components.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/components.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/components.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/captchaType.test.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/captchaType.test.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/captchaType.test.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/captchaType.test.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/config.test.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/config.test.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/config.test.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/config.test.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentsList.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentsList.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentsList.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentsList.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaProps.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaProps.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaProps.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaProps.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaType.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaType.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaType.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaType.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/imageCaptcha.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/imageCaptcha.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/imageCaptcha.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/imageCaptcha.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/powCaptcha.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/powCaptcha.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/powCaptcha.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/powCaptcha.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/config.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/config.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/config.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/config.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/language.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/language.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.js.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetThemeResolver.d.ts +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetThemeResolver.d.ts.map +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetThemeResolver.js +0 -0
- /package/.rollup.cache/home/runner/work/{captcha-private/captcha-private → captcha}/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetThemeResolver.js.map +0 -0
|
@@ -1,4373 +0,0 @@
|
|
|
1
|
-
var go = Object.defineProperty;
|
|
2
|
-
var mo = (t, e, r) => e in t ? go(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
-
var Kt = (t, e, r) => mo(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
-
import { x as hi, s as ee, r as ci, d as po, f as b0, g as yo, h as vo, H as bo, n as Ft, u as Ve, i as Xe, b as je, e as kn, t as xo, j as Eo, o as Mo, k as _o, l as G } from "./toU8a-BWKf-2UU.js";
|
|
5
|
-
import { b as Yr, B as W, c as Se, d as te, u as V, R as Bo, e as So, f as he, g as oe, j as Ht, i as Vt, s as Ao, k as Io, l as ko, m as Uo, n as No, o as Ro, p as Oo, q as Lo, r as To, v as $o, t as qo, x as Po, y as Co, z as Zo, A as Do, C as Ho, D as Vo, E as zo, F as Yo, G as Xo, H as jo, I as Ko, J as Go, K as Wo, L as Jo, M as Qo, N as Fo, O as ts, P as es, Q as rs } from "./hash-CtL1HOjf.js";
|
|
6
|
-
import { g as ns, c as is } from "./_commonjsHelpers-DaMA6jEr.js";
|
|
7
|
-
import { s as rr } from "./sha256-Cxc9Hrlx.js";
|
|
8
|
-
import { h as li, s as ui, m as os, v as ss, a as Un, p as fs, b as di } from "./bip39-CFjno8fK.js";
|
|
9
|
-
import { a as wi } from "./asU8a-JliaME7-.js";
|
|
10
|
-
import { o as on } from "./spread-DEmVz7RJ.js";
|
|
11
|
-
import { p as Ae } from "./emotion-element-5486c51c.browser.esm-Bywq83R5.js";
|
|
12
|
-
const as = { name: "@polkadot/util", path: import.meta && import.meta.url ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf("/") + 1) : "auto", type: "esm", version: "12.6.2" }, hs = "POLKADOTJS_DISABLE_ESM_CJS_WARNING";
|
|
13
|
-
function cs(t) {
|
|
14
|
-
const e = hi;
|
|
15
|
-
return e.__polkadotjs || (e.__polkadotjs = {}), e.__polkadotjs[t] || (e.__polkadotjs[t] = []), e.__polkadotjs[t];
|
|
16
|
-
}
|
|
17
|
-
function ls(t, e) {
|
|
18
|
-
if (t)
|
|
19
|
-
return t;
|
|
20
|
-
if (Yr(e))
|
|
21
|
-
try {
|
|
22
|
-
return e() || "";
|
|
23
|
-
} catch {
|
|
24
|
-
return "";
|
|
25
|
-
}
|
|
26
|
-
return e || "";
|
|
27
|
-
}
|
|
28
|
-
function us({ name: t, path: e, type: r, version: o }, c, i = []) {
|
|
29
|
-
var E, M;
|
|
30
|
-
if (!t.startsWith("@polkadot"))
|
|
31
|
-
throw new Error(`Invalid package descriptor ${t}`);
|
|
32
|
-
const w = cs(t);
|
|
33
|
-
w.push({ path: ls(e, c), type: r, version: o });
|
|
34
|
-
const d = w.every((U) => U.version === o), y = ((M = (E = hi.process) == null ? void 0 : E.env) == null ? void 0 : M[hs]) === "1";
|
|
35
|
-
w.length !== 1 && !(y && d) || i.filter((U) => U && U.version !== o);
|
|
36
|
-
}
|
|
37
|
-
const Ke = /* @__PURE__ */ W(0), Ge = /* @__PURE__ */ W(1);
|
|
38
|
-
Number.MAX_SAFE_INTEGER;
|
|
39
|
-
const Nn = W(256), Rn = W(256 * 256), ds = W("0x10000000000000000");
|
|
40
|
-
function Xr(t, { isLe: e = !0, isNegative: r = !1 } = {}) {
|
|
41
|
-
e || (t = t.slice().reverse());
|
|
42
|
-
const o = t.length;
|
|
43
|
-
if (r && o && t[o - 1] & 128) {
|
|
44
|
-
switch (o) {
|
|
45
|
-
case 0:
|
|
46
|
-
return W(0);
|
|
47
|
-
case 1:
|
|
48
|
-
return W((t[0] ^ 255) * -1 - 1);
|
|
49
|
-
case 2:
|
|
50
|
-
return W((t[0] + (t[1] << 8) ^ 65535) * -1 - 1);
|
|
51
|
-
case 4:
|
|
52
|
-
return W((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) * -1 - 1);
|
|
53
|
-
}
|
|
54
|
-
const i = new DataView(t.buffer, t.byteOffset);
|
|
55
|
-
if (o === 8)
|
|
56
|
-
return i.getBigInt64(0, !0);
|
|
57
|
-
let w = W(0);
|
|
58
|
-
const d = o % 2;
|
|
59
|
-
for (let y = o - 2; y >= d; y -= 2)
|
|
60
|
-
w = w * Rn + W(i.getUint16(y, !0) ^ 65535);
|
|
61
|
-
return d && (w = w * Nn + W(t[0] ^ 255)), w * -Ge - Ge;
|
|
62
|
-
}
|
|
63
|
-
switch (o) {
|
|
64
|
-
case 0:
|
|
65
|
-
return W(0);
|
|
66
|
-
case 1:
|
|
67
|
-
return W(t[0]);
|
|
68
|
-
case 2:
|
|
69
|
-
return W(t[0] + (t[1] << 8));
|
|
70
|
-
case 4:
|
|
71
|
-
return W(t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216);
|
|
72
|
-
}
|
|
73
|
-
const c = new DataView(t.buffer, t.byteOffset);
|
|
74
|
-
switch (o) {
|
|
75
|
-
case 8:
|
|
76
|
-
return c.getBigUint64(0, !0);
|
|
77
|
-
case 16:
|
|
78
|
-
return c.getBigUint64(8, !0) * ds + c.getBigUint64(0, !0);
|
|
79
|
-
default: {
|
|
80
|
-
let i = W(0);
|
|
81
|
-
const w = o % 2;
|
|
82
|
-
for (let d = o - 2; d >= w; d -= 2)
|
|
83
|
-
i = i * Rn + W(c.getUint16(d, !0));
|
|
84
|
-
return w && (i = i * Nn + W(t[0])), i;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function ws(t, { isLe: e = !1, isNegative: r = !1 } = {}) {
|
|
89
|
-
return !t || t === "0x" ? W(0) : Xr(Se(t), { isLe: e, isNegative: r });
|
|
90
|
-
}
|
|
91
|
-
var gi = { exports: {} };
|
|
92
|
-
(function(t) {
|
|
93
|
-
(function(e, r) {
|
|
94
|
-
function o(p, n) {
|
|
95
|
-
if (!p) throw new Error(n || "Assertion failed");
|
|
96
|
-
}
|
|
97
|
-
function c(p, n) {
|
|
98
|
-
p.super_ = n;
|
|
99
|
-
var f = function() {
|
|
100
|
-
};
|
|
101
|
-
f.prototype = n.prototype, p.prototype = new f(), p.prototype.constructor = p;
|
|
102
|
-
}
|
|
103
|
-
function i(p, n, f) {
|
|
104
|
-
if (i.isBN(p))
|
|
105
|
-
return p;
|
|
106
|
-
this.negative = 0, this.words = null, this.length = 0, this.red = null, p !== null && ((n === "le" || n === "be") && (f = n, n = 10), this._init(p || 0, n || 10, f || "be"));
|
|
107
|
-
}
|
|
108
|
-
typeof e == "object" ? e.exports = i : r.BN = i, i.BN = i, i.wordSize = 26;
|
|
109
|
-
var w;
|
|
110
|
-
try {
|
|
111
|
-
typeof window < "u" && typeof window.Buffer < "u" ? w = window.Buffer : w = require("buffer").Buffer;
|
|
112
|
-
} catch {
|
|
113
|
-
}
|
|
114
|
-
i.isBN = function(n) {
|
|
115
|
-
return n instanceof i ? !0 : n !== null && typeof n == "object" && n.constructor.wordSize === i.wordSize && Array.isArray(n.words);
|
|
116
|
-
}, i.max = function(n, f) {
|
|
117
|
-
return n.cmp(f) > 0 ? n : f;
|
|
118
|
-
}, i.min = function(n, f) {
|
|
119
|
-
return n.cmp(f) < 0 ? n : f;
|
|
120
|
-
}, i.prototype._init = function(n, f, a) {
|
|
121
|
-
if (typeof n == "number")
|
|
122
|
-
return this._initNumber(n, f, a);
|
|
123
|
-
if (typeof n == "object")
|
|
124
|
-
return this._initArray(n, f, a);
|
|
125
|
-
f === "hex" && (f = 16), o(f === (f | 0) && f >= 2 && f <= 36), n = n.toString().replace(/\s+/g, "");
|
|
126
|
-
var h = 0;
|
|
127
|
-
n[0] === "-" && (h++, this.negative = 1), h < n.length && (f === 16 ? this._parseHex(n, h, a) : (this._parseBase(n, f, h), a === "le" && this._initArray(this.toArray(), f, a)));
|
|
128
|
-
}, i.prototype._initNumber = function(n, f, a) {
|
|
129
|
-
n < 0 && (this.negative = 1, n = -n), n < 67108864 ? (this.words = [n & 67108863], this.length = 1) : n < 4503599627370496 ? (this.words = [
|
|
130
|
-
n & 67108863,
|
|
131
|
-
n / 67108864 & 67108863
|
|
132
|
-
], this.length = 2) : (o(n < 9007199254740992), this.words = [
|
|
133
|
-
n & 67108863,
|
|
134
|
-
n / 67108864 & 67108863,
|
|
135
|
-
1
|
|
136
|
-
], this.length = 3), a === "le" && this._initArray(this.toArray(), f, a);
|
|
137
|
-
}, i.prototype._initArray = function(n, f, a) {
|
|
138
|
-
if (o(typeof n.length == "number"), n.length <= 0)
|
|
139
|
-
return this.words = [0], this.length = 1, this;
|
|
140
|
-
this.length = Math.ceil(n.length / 3), this.words = new Array(this.length);
|
|
141
|
-
for (var h = 0; h < this.length; h++)
|
|
142
|
-
this.words[h] = 0;
|
|
143
|
-
var l, m, b = 0;
|
|
144
|
-
if (a === "be")
|
|
145
|
-
for (h = n.length - 1, l = 0; h >= 0; h -= 3)
|
|
146
|
-
m = n[h] | n[h - 1] << 8 | n[h - 2] << 16, this.words[l] |= m << b & 67108863, this.words[l + 1] = m >>> 26 - b & 67108863, b += 24, b >= 26 && (b -= 26, l++);
|
|
147
|
-
else if (a === "le")
|
|
148
|
-
for (h = 0, l = 0; h < n.length; h += 3)
|
|
149
|
-
m = n[h] | n[h + 1] << 8 | n[h + 2] << 16, this.words[l] |= m << b & 67108863, this.words[l + 1] = m >>> 26 - b & 67108863, b += 24, b >= 26 && (b -= 26, l++);
|
|
150
|
-
return this._strip();
|
|
151
|
-
};
|
|
152
|
-
function d(p, n) {
|
|
153
|
-
var f = p.charCodeAt(n);
|
|
154
|
-
if (f >= 48 && f <= 57)
|
|
155
|
-
return f - 48;
|
|
156
|
-
if (f >= 65 && f <= 70)
|
|
157
|
-
return f - 55;
|
|
158
|
-
if (f >= 97 && f <= 102)
|
|
159
|
-
return f - 87;
|
|
160
|
-
o(!1, "Invalid character in " + p);
|
|
161
|
-
}
|
|
162
|
-
function y(p, n, f) {
|
|
163
|
-
var a = d(p, f);
|
|
164
|
-
return f - 1 >= n && (a |= d(p, f - 1) << 4), a;
|
|
165
|
-
}
|
|
166
|
-
i.prototype._parseHex = function(n, f, a) {
|
|
167
|
-
this.length = Math.ceil((n.length - f) / 6), this.words = new Array(this.length);
|
|
168
|
-
for (var h = 0; h < this.length; h++)
|
|
169
|
-
this.words[h] = 0;
|
|
170
|
-
var l = 0, m = 0, b;
|
|
171
|
-
if (a === "be")
|
|
172
|
-
for (h = n.length - 1; h >= f; h -= 2)
|
|
173
|
-
b = y(n, f, h) << l, this.words[m] |= b & 67108863, l >= 18 ? (l -= 18, m += 1, this.words[m] |= b >>> 26) : l += 8;
|
|
174
|
-
else {
|
|
175
|
-
var u = n.length - f;
|
|
176
|
-
for (h = u % 2 === 0 ? f + 1 : f; h < n.length; h += 2)
|
|
177
|
-
b = y(n, f, h) << l, this.words[m] |= b & 67108863, l >= 18 ? (l -= 18, m += 1, this.words[m] |= b >>> 26) : l += 8;
|
|
178
|
-
}
|
|
179
|
-
this._strip();
|
|
180
|
-
};
|
|
181
|
-
function x(p, n, f, a) {
|
|
182
|
-
for (var h = 0, l = 0, m = Math.min(p.length, f), b = n; b < m; b++) {
|
|
183
|
-
var u = p.charCodeAt(b) - 48;
|
|
184
|
-
h *= a, u >= 49 ? l = u - 49 + 10 : u >= 17 ? l = u - 17 + 10 : l = u, o(u >= 0 && l < a, "Invalid character"), h += l;
|
|
185
|
-
}
|
|
186
|
-
return h;
|
|
187
|
-
}
|
|
188
|
-
i.prototype._parseBase = function(n, f, a) {
|
|
189
|
-
this.words = [0], this.length = 1;
|
|
190
|
-
for (var h = 0, l = 1; l <= 67108863; l *= f)
|
|
191
|
-
h++;
|
|
192
|
-
h--, l = l / f | 0;
|
|
193
|
-
for (var m = n.length - a, b = m % h, u = Math.min(m, m - b) + a, s = 0, g = a; g < u; g += h)
|
|
194
|
-
s = x(n, g, g + h, f), this.imuln(l), this.words[0] + s < 67108864 ? this.words[0] += s : this._iaddn(s);
|
|
195
|
-
if (b !== 0) {
|
|
196
|
-
var B = 1;
|
|
197
|
-
for (s = x(n, g, n.length, f), g = 0; g < b; g++)
|
|
198
|
-
B *= f;
|
|
199
|
-
this.imuln(B), this.words[0] + s < 67108864 ? this.words[0] += s : this._iaddn(s);
|
|
200
|
-
}
|
|
201
|
-
this._strip();
|
|
202
|
-
}, i.prototype.copy = function(n) {
|
|
203
|
-
n.words = new Array(this.length);
|
|
204
|
-
for (var f = 0; f < this.length; f++)
|
|
205
|
-
n.words[f] = this.words[f];
|
|
206
|
-
n.length = this.length, n.negative = this.negative, n.red = this.red;
|
|
207
|
-
};
|
|
208
|
-
function v(p, n) {
|
|
209
|
-
p.words = n.words, p.length = n.length, p.negative = n.negative, p.red = n.red;
|
|
210
|
-
}
|
|
211
|
-
if (i.prototype._move = function(n) {
|
|
212
|
-
v(n, this);
|
|
213
|
-
}, i.prototype.clone = function() {
|
|
214
|
-
var n = new i(null);
|
|
215
|
-
return this.copy(n), n;
|
|
216
|
-
}, i.prototype._expand = function(n) {
|
|
217
|
-
for (; this.length < n; )
|
|
218
|
-
this.words[this.length++] = 0;
|
|
219
|
-
return this;
|
|
220
|
-
}, i.prototype._strip = function() {
|
|
221
|
-
for (; this.length > 1 && this.words[this.length - 1] === 0; )
|
|
222
|
-
this.length--;
|
|
223
|
-
return this._normSign();
|
|
224
|
-
}, i.prototype._normSign = function() {
|
|
225
|
-
return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
|
|
226
|
-
}, typeof Symbol < "u" && typeof Symbol.for == "function")
|
|
227
|
-
try {
|
|
228
|
-
i.prototype[Symbol.for("nodejs.util.inspect.custom")] = E;
|
|
229
|
-
} catch {
|
|
230
|
-
i.prototype.inspect = E;
|
|
231
|
-
}
|
|
232
|
-
else
|
|
233
|
-
i.prototype.inspect = E;
|
|
234
|
-
function E() {
|
|
235
|
-
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
236
|
-
}
|
|
237
|
-
var M = [
|
|
238
|
-
"",
|
|
239
|
-
"0",
|
|
240
|
-
"00",
|
|
241
|
-
"000",
|
|
242
|
-
"0000",
|
|
243
|
-
"00000",
|
|
244
|
-
"000000",
|
|
245
|
-
"0000000",
|
|
246
|
-
"00000000",
|
|
247
|
-
"000000000",
|
|
248
|
-
"0000000000",
|
|
249
|
-
"00000000000",
|
|
250
|
-
"000000000000",
|
|
251
|
-
"0000000000000",
|
|
252
|
-
"00000000000000",
|
|
253
|
-
"000000000000000",
|
|
254
|
-
"0000000000000000",
|
|
255
|
-
"00000000000000000",
|
|
256
|
-
"000000000000000000",
|
|
257
|
-
"0000000000000000000",
|
|
258
|
-
"00000000000000000000",
|
|
259
|
-
"000000000000000000000",
|
|
260
|
-
"0000000000000000000000",
|
|
261
|
-
"00000000000000000000000",
|
|
262
|
-
"000000000000000000000000",
|
|
263
|
-
"0000000000000000000000000"
|
|
264
|
-
], U = [
|
|
265
|
-
0,
|
|
266
|
-
0,
|
|
267
|
-
25,
|
|
268
|
-
16,
|
|
269
|
-
12,
|
|
270
|
-
11,
|
|
271
|
-
10,
|
|
272
|
-
9,
|
|
273
|
-
8,
|
|
274
|
-
8,
|
|
275
|
-
7,
|
|
276
|
-
7,
|
|
277
|
-
7,
|
|
278
|
-
7,
|
|
279
|
-
6,
|
|
280
|
-
6,
|
|
281
|
-
6,
|
|
282
|
-
6,
|
|
283
|
-
6,
|
|
284
|
-
6,
|
|
285
|
-
6,
|
|
286
|
-
5,
|
|
287
|
-
5,
|
|
288
|
-
5,
|
|
289
|
-
5,
|
|
290
|
-
5,
|
|
291
|
-
5,
|
|
292
|
-
5,
|
|
293
|
-
5,
|
|
294
|
-
5,
|
|
295
|
-
5,
|
|
296
|
-
5,
|
|
297
|
-
5,
|
|
298
|
-
5,
|
|
299
|
-
5,
|
|
300
|
-
5,
|
|
301
|
-
5
|
|
302
|
-
], C = [
|
|
303
|
-
0,
|
|
304
|
-
0,
|
|
305
|
-
33554432,
|
|
306
|
-
43046721,
|
|
307
|
-
16777216,
|
|
308
|
-
48828125,
|
|
309
|
-
60466176,
|
|
310
|
-
40353607,
|
|
311
|
-
16777216,
|
|
312
|
-
43046721,
|
|
313
|
-
1e7,
|
|
314
|
-
19487171,
|
|
315
|
-
35831808,
|
|
316
|
-
62748517,
|
|
317
|
-
7529536,
|
|
318
|
-
11390625,
|
|
319
|
-
16777216,
|
|
320
|
-
24137569,
|
|
321
|
-
34012224,
|
|
322
|
-
47045881,
|
|
323
|
-
64e6,
|
|
324
|
-
4084101,
|
|
325
|
-
5153632,
|
|
326
|
-
6436343,
|
|
327
|
-
7962624,
|
|
328
|
-
9765625,
|
|
329
|
-
11881376,
|
|
330
|
-
14348907,
|
|
331
|
-
17210368,
|
|
332
|
-
20511149,
|
|
333
|
-
243e5,
|
|
334
|
-
28629151,
|
|
335
|
-
33554432,
|
|
336
|
-
39135393,
|
|
337
|
-
45435424,
|
|
338
|
-
52521875,
|
|
339
|
-
60466176
|
|
340
|
-
];
|
|
341
|
-
i.prototype.toString = function(n, f) {
|
|
342
|
-
n = n || 10, f = f | 0 || 1;
|
|
343
|
-
var a;
|
|
344
|
-
if (n === 16 || n === "hex") {
|
|
345
|
-
a = "";
|
|
346
|
-
for (var h = 0, l = 0, m = 0; m < this.length; m++) {
|
|
347
|
-
var b = this.words[m], u = ((b << h | l) & 16777215).toString(16);
|
|
348
|
-
l = b >>> 24 - h & 16777215, h += 2, h >= 26 && (h -= 26, m--), l !== 0 || m !== this.length - 1 ? a = M[6 - u.length] + u + a : a = u + a;
|
|
349
|
-
}
|
|
350
|
-
for (l !== 0 && (a = l.toString(16) + a); a.length % f !== 0; )
|
|
351
|
-
a = "0" + a;
|
|
352
|
-
return this.negative !== 0 && (a = "-" + a), a;
|
|
353
|
-
}
|
|
354
|
-
if (n === (n | 0) && n >= 2 && n <= 36) {
|
|
355
|
-
var s = U[n], g = C[n];
|
|
356
|
-
a = "";
|
|
357
|
-
var B = this.clone();
|
|
358
|
-
for (B.negative = 0; !B.isZero(); ) {
|
|
359
|
-
var I = B.modrn(g).toString(n);
|
|
360
|
-
B = B.idivn(g), B.isZero() ? a = I + a : a = M[s - I.length] + I + a;
|
|
361
|
-
}
|
|
362
|
-
for (this.isZero() && (a = "0" + a); a.length % f !== 0; )
|
|
363
|
-
a = "0" + a;
|
|
364
|
-
return this.negative !== 0 && (a = "-" + a), a;
|
|
365
|
-
}
|
|
366
|
-
o(!1, "Base should be between 2 and 36");
|
|
367
|
-
}, i.prototype.toNumber = function() {
|
|
368
|
-
var n = this.words[0];
|
|
369
|
-
return this.length === 2 ? n += this.words[1] * 67108864 : this.length === 3 && this.words[2] === 1 ? n += 4503599627370496 + this.words[1] * 67108864 : this.length > 2 && o(!1, "Number can only safely store up to 53 bits"), this.negative !== 0 ? -n : n;
|
|
370
|
-
}, i.prototype.toJSON = function() {
|
|
371
|
-
return this.toString(16, 2);
|
|
372
|
-
}, w && (i.prototype.toBuffer = function(n, f) {
|
|
373
|
-
return this.toArrayLike(w, n, f);
|
|
374
|
-
}), i.prototype.toArray = function(n, f) {
|
|
375
|
-
return this.toArrayLike(Array, n, f);
|
|
376
|
-
};
|
|
377
|
-
var k = function(n, f) {
|
|
378
|
-
return n.allocUnsafe ? n.allocUnsafe(f) : new n(f);
|
|
379
|
-
};
|
|
380
|
-
i.prototype.toArrayLike = function(n, f, a) {
|
|
381
|
-
this._strip();
|
|
382
|
-
var h = this.byteLength(), l = a || Math.max(1, h);
|
|
383
|
-
o(h <= l, "byte array longer than desired length"), o(l > 0, "Requested array length <= 0");
|
|
384
|
-
var m = k(n, l), b = f === "le" ? "LE" : "BE";
|
|
385
|
-
return this["_toArrayLike" + b](m, h), m;
|
|
386
|
-
}, i.prototype._toArrayLikeLE = function(n, f) {
|
|
387
|
-
for (var a = 0, h = 0, l = 0, m = 0; l < this.length; l++) {
|
|
388
|
-
var b = this.words[l] << m | h;
|
|
389
|
-
n[a++] = b & 255, a < n.length && (n[a++] = b >> 8 & 255), a < n.length && (n[a++] = b >> 16 & 255), m === 6 ? (a < n.length && (n[a++] = b >> 24 & 255), h = 0, m = 0) : (h = b >>> 24, m += 2);
|
|
390
|
-
}
|
|
391
|
-
if (a < n.length)
|
|
392
|
-
for (n[a++] = h; a < n.length; )
|
|
393
|
-
n[a++] = 0;
|
|
394
|
-
}, i.prototype._toArrayLikeBE = function(n, f) {
|
|
395
|
-
for (var a = n.length - 1, h = 0, l = 0, m = 0; l < this.length; l++) {
|
|
396
|
-
var b = this.words[l] << m | h;
|
|
397
|
-
n[a--] = b & 255, a >= 0 && (n[a--] = b >> 8 & 255), a >= 0 && (n[a--] = b >> 16 & 255), m === 6 ? (a >= 0 && (n[a--] = b >> 24 & 255), h = 0, m = 0) : (h = b >>> 24, m += 2);
|
|
398
|
-
}
|
|
399
|
-
if (a >= 0)
|
|
400
|
-
for (n[a--] = h; a >= 0; )
|
|
401
|
-
n[a--] = 0;
|
|
402
|
-
}, Math.clz32 ? i.prototype._countBits = function(n) {
|
|
403
|
-
return 32 - Math.clz32(n);
|
|
404
|
-
} : i.prototype._countBits = function(n) {
|
|
405
|
-
var f = n, a = 0;
|
|
406
|
-
return f >= 4096 && (a += 13, f >>>= 13), f >= 64 && (a += 7, f >>>= 7), f >= 8 && (a += 4, f >>>= 4), f >= 2 && (a += 2, f >>>= 2), a + f;
|
|
407
|
-
}, i.prototype._zeroBits = function(n) {
|
|
408
|
-
if (n === 0) return 26;
|
|
409
|
-
var f = n, a = 0;
|
|
410
|
-
return f & 8191 || (a += 13, f >>>= 13), f & 127 || (a += 7, f >>>= 7), f & 15 || (a += 4, f >>>= 4), f & 3 || (a += 2, f >>>= 2), f & 1 || a++, a;
|
|
411
|
-
}, i.prototype.bitLength = function() {
|
|
412
|
-
var n = this.words[this.length - 1], f = this._countBits(n);
|
|
413
|
-
return (this.length - 1) * 26 + f;
|
|
414
|
-
};
|
|
415
|
-
function _(p) {
|
|
416
|
-
for (var n = new Array(p.bitLength()), f = 0; f < n.length; f++) {
|
|
417
|
-
var a = f / 26 | 0, h = f % 26;
|
|
418
|
-
n[f] = p.words[a] >>> h & 1;
|
|
419
|
-
}
|
|
420
|
-
return n;
|
|
421
|
-
}
|
|
422
|
-
i.prototype.zeroBits = function() {
|
|
423
|
-
if (this.isZero()) return 0;
|
|
424
|
-
for (var n = 0, f = 0; f < this.length; f++) {
|
|
425
|
-
var a = this._zeroBits(this.words[f]);
|
|
426
|
-
if (n += a, a !== 26) break;
|
|
427
|
-
}
|
|
428
|
-
return n;
|
|
429
|
-
}, i.prototype.byteLength = function() {
|
|
430
|
-
return Math.ceil(this.bitLength() / 8);
|
|
431
|
-
}, i.prototype.toTwos = function(n) {
|
|
432
|
-
return this.negative !== 0 ? this.abs().inotn(n).iaddn(1) : this.clone();
|
|
433
|
-
}, i.prototype.fromTwos = function(n) {
|
|
434
|
-
return this.testn(n - 1) ? this.notn(n).iaddn(1).ineg() : this.clone();
|
|
435
|
-
}, i.prototype.isNeg = function() {
|
|
436
|
-
return this.negative !== 0;
|
|
437
|
-
}, i.prototype.neg = function() {
|
|
438
|
-
return this.clone().ineg();
|
|
439
|
-
}, i.prototype.ineg = function() {
|
|
440
|
-
return this.isZero() || (this.negative ^= 1), this;
|
|
441
|
-
}, i.prototype.iuor = function(n) {
|
|
442
|
-
for (; this.length < n.length; )
|
|
443
|
-
this.words[this.length++] = 0;
|
|
444
|
-
for (var f = 0; f < n.length; f++)
|
|
445
|
-
this.words[f] = this.words[f] | n.words[f];
|
|
446
|
-
return this._strip();
|
|
447
|
-
}, i.prototype.ior = function(n) {
|
|
448
|
-
return o((this.negative | n.negative) === 0), this.iuor(n);
|
|
449
|
-
}, i.prototype.or = function(n) {
|
|
450
|
-
return this.length > n.length ? this.clone().ior(n) : n.clone().ior(this);
|
|
451
|
-
}, i.prototype.uor = function(n) {
|
|
452
|
-
return this.length > n.length ? this.clone().iuor(n) : n.clone().iuor(this);
|
|
453
|
-
}, i.prototype.iuand = function(n) {
|
|
454
|
-
var f;
|
|
455
|
-
this.length > n.length ? f = n : f = this;
|
|
456
|
-
for (var a = 0; a < f.length; a++)
|
|
457
|
-
this.words[a] = this.words[a] & n.words[a];
|
|
458
|
-
return this.length = f.length, this._strip();
|
|
459
|
-
}, i.prototype.iand = function(n) {
|
|
460
|
-
return o((this.negative | n.negative) === 0), this.iuand(n);
|
|
461
|
-
}, i.prototype.and = function(n) {
|
|
462
|
-
return this.length > n.length ? this.clone().iand(n) : n.clone().iand(this);
|
|
463
|
-
}, i.prototype.uand = function(n) {
|
|
464
|
-
return this.length > n.length ? this.clone().iuand(n) : n.clone().iuand(this);
|
|
465
|
-
}, i.prototype.iuxor = function(n) {
|
|
466
|
-
var f, a;
|
|
467
|
-
this.length > n.length ? (f = this, a = n) : (f = n, a = this);
|
|
468
|
-
for (var h = 0; h < a.length; h++)
|
|
469
|
-
this.words[h] = f.words[h] ^ a.words[h];
|
|
470
|
-
if (this !== f)
|
|
471
|
-
for (; h < f.length; h++)
|
|
472
|
-
this.words[h] = f.words[h];
|
|
473
|
-
return this.length = f.length, this._strip();
|
|
474
|
-
}, i.prototype.ixor = function(n) {
|
|
475
|
-
return o((this.negative | n.negative) === 0), this.iuxor(n);
|
|
476
|
-
}, i.prototype.xor = function(n) {
|
|
477
|
-
return this.length > n.length ? this.clone().ixor(n) : n.clone().ixor(this);
|
|
478
|
-
}, i.prototype.uxor = function(n) {
|
|
479
|
-
return this.length > n.length ? this.clone().iuxor(n) : n.clone().iuxor(this);
|
|
480
|
-
}, i.prototype.inotn = function(n) {
|
|
481
|
-
o(typeof n == "number" && n >= 0);
|
|
482
|
-
var f = Math.ceil(n / 26) | 0, a = n % 26;
|
|
483
|
-
this._expand(f), a > 0 && f--;
|
|
484
|
-
for (var h = 0; h < f; h++)
|
|
485
|
-
this.words[h] = ~this.words[h] & 67108863;
|
|
486
|
-
return a > 0 && (this.words[h] = ~this.words[h] & 67108863 >> 26 - a), this._strip();
|
|
487
|
-
}, i.prototype.notn = function(n) {
|
|
488
|
-
return this.clone().inotn(n);
|
|
489
|
-
}, i.prototype.setn = function(n, f) {
|
|
490
|
-
o(typeof n == "number" && n >= 0);
|
|
491
|
-
var a = n / 26 | 0, h = n % 26;
|
|
492
|
-
return this._expand(a + 1), f ? this.words[a] = this.words[a] | 1 << h : this.words[a] = this.words[a] & ~(1 << h), this._strip();
|
|
493
|
-
}, i.prototype.iadd = function(n) {
|
|
494
|
-
var f;
|
|
495
|
-
if (this.negative !== 0 && n.negative === 0)
|
|
496
|
-
return this.negative = 0, f = this.isub(n), this.negative ^= 1, this._normSign();
|
|
497
|
-
if (this.negative === 0 && n.negative !== 0)
|
|
498
|
-
return n.negative = 0, f = this.isub(n), n.negative = 1, f._normSign();
|
|
499
|
-
var a, h;
|
|
500
|
-
this.length > n.length ? (a = this, h = n) : (a = n, h = this);
|
|
501
|
-
for (var l = 0, m = 0; m < h.length; m++)
|
|
502
|
-
f = (a.words[m] | 0) + (h.words[m] | 0) + l, this.words[m] = f & 67108863, l = f >>> 26;
|
|
503
|
-
for (; l !== 0 && m < a.length; m++)
|
|
504
|
-
f = (a.words[m] | 0) + l, this.words[m] = f & 67108863, l = f >>> 26;
|
|
505
|
-
if (this.length = a.length, l !== 0)
|
|
506
|
-
this.words[this.length] = l, this.length++;
|
|
507
|
-
else if (a !== this)
|
|
508
|
-
for (; m < a.length; m++)
|
|
509
|
-
this.words[m] = a.words[m];
|
|
510
|
-
return this;
|
|
511
|
-
}, i.prototype.add = function(n) {
|
|
512
|
-
var f;
|
|
513
|
-
return n.negative !== 0 && this.negative === 0 ? (n.negative = 0, f = this.sub(n), n.negative ^= 1, f) : n.negative === 0 && this.negative !== 0 ? (this.negative = 0, f = n.sub(this), this.negative = 1, f) : this.length > n.length ? this.clone().iadd(n) : n.clone().iadd(this);
|
|
514
|
-
}, i.prototype.isub = function(n) {
|
|
515
|
-
if (n.negative !== 0) {
|
|
516
|
-
n.negative = 0;
|
|
517
|
-
var f = this.iadd(n);
|
|
518
|
-
return n.negative = 1, f._normSign();
|
|
519
|
-
} else if (this.negative !== 0)
|
|
520
|
-
return this.negative = 0, this.iadd(n), this.negative = 1, this._normSign();
|
|
521
|
-
var a = this.cmp(n);
|
|
522
|
-
if (a === 0)
|
|
523
|
-
return this.negative = 0, this.length = 1, this.words[0] = 0, this;
|
|
524
|
-
var h, l;
|
|
525
|
-
a > 0 ? (h = this, l = n) : (h = n, l = this);
|
|
526
|
-
for (var m = 0, b = 0; b < l.length; b++)
|
|
527
|
-
f = (h.words[b] | 0) - (l.words[b] | 0) + m, m = f >> 26, this.words[b] = f & 67108863;
|
|
528
|
-
for (; m !== 0 && b < h.length; b++)
|
|
529
|
-
f = (h.words[b] | 0) + m, m = f >> 26, this.words[b] = f & 67108863;
|
|
530
|
-
if (m === 0 && b < h.length && h !== this)
|
|
531
|
-
for (; b < h.length; b++)
|
|
532
|
-
this.words[b] = h.words[b];
|
|
533
|
-
return this.length = Math.max(this.length, b), h !== this && (this.negative = 1), this._strip();
|
|
534
|
-
}, i.prototype.sub = function(n) {
|
|
535
|
-
return this.clone().isub(n);
|
|
536
|
-
};
|
|
537
|
-
function S(p, n, f) {
|
|
538
|
-
f.negative = n.negative ^ p.negative;
|
|
539
|
-
var a = p.length + n.length | 0;
|
|
540
|
-
f.length = a, a = a - 1 | 0;
|
|
541
|
-
var h = p.words[0] | 0, l = n.words[0] | 0, m = h * l, b = m & 67108863, u = m / 67108864 | 0;
|
|
542
|
-
f.words[0] = b;
|
|
543
|
-
for (var s = 1; s < a; s++) {
|
|
544
|
-
for (var g = u >>> 26, B = u & 67108863, I = Math.min(s, n.length - 1), N = Math.max(0, s - p.length + 1); N <= I; N++) {
|
|
545
|
-
var j = s - N | 0;
|
|
546
|
-
h = p.words[j] | 0, l = n.words[N] | 0, m = h * l + B, g += m / 67108864 | 0, B = m & 67108863;
|
|
547
|
-
}
|
|
548
|
-
f.words[s] = B | 0, u = g | 0;
|
|
549
|
-
}
|
|
550
|
-
return u !== 0 ? f.words[s] = u | 0 : f.length--, f._strip();
|
|
551
|
-
}
|
|
552
|
-
var L = function(n, f, a) {
|
|
553
|
-
var h = n.words, l = f.words, m = a.words, b = 0, u, s, g, B = h[0] | 0, I = B & 8191, N = B >>> 13, j = h[1] | 0, H = j & 8191, z = j >>> 13, $t = h[2] | 0, X = $t & 8191, Y = $t >>> 13, Zt = h[3] | 0, Q = Zt & 8191, F = Zt >>> 13, $e = h[4] | 0, at = $e & 8191, ht = $e >>> 13, qe = h[5] | 0, et = qe & 8191, rt = qe >>> 13, ce = h[6] | 0, nt = ce & 8191, it = ce >>> 13, Ee = h[7] | 0, ot = Ee & 8191, st = Ee >>> 13, Pe = h[8] | 0, ct = Pe & 8191, lt = Pe >>> 13, Ce = h[9] | 0, dt = Ce & 8191, wt = Ce >>> 13, vn = l[0] | 0, gt = vn & 8191, mt = vn >>> 13, bn = l[1] | 0, pt = bn & 8191, yt = bn >>> 13, xn = l[2] | 0, vt = xn & 8191, bt = xn >>> 13, En = l[3] | 0, xt = En & 8191, Et = En >>> 13, Mn = l[4] | 0, Mt = Mn & 8191, _t = Mn >>> 13, _n = l[5] | 0, Bt = _n & 8191, St = _n >>> 13, Bn = l[6] | 0, At = Bn & 8191, It = Bn >>> 13, Sn = l[7] | 0, kt = Sn & 8191, Ut = Sn >>> 13, An = l[8] | 0, Nt = An & 8191, Rt = An >>> 13, In = l[9] | 0, Ot = In & 8191, Lt = In >>> 13;
|
|
554
|
-
a.negative = n.negative ^ f.negative, a.length = 19, u = Math.imul(I, gt), s = Math.imul(I, mt), s = s + Math.imul(N, gt) | 0, g = Math.imul(N, mt);
|
|
555
|
-
var cr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
556
|
-
b = (g + (s >>> 13) | 0) + (cr >>> 26) | 0, cr &= 67108863, u = Math.imul(H, gt), s = Math.imul(H, mt), s = s + Math.imul(z, gt) | 0, g = Math.imul(z, mt), u = u + Math.imul(I, pt) | 0, s = s + Math.imul(I, yt) | 0, s = s + Math.imul(N, pt) | 0, g = g + Math.imul(N, yt) | 0;
|
|
557
|
-
var lr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
558
|
-
b = (g + (s >>> 13) | 0) + (lr >>> 26) | 0, lr &= 67108863, u = Math.imul(X, gt), s = Math.imul(X, mt), s = s + Math.imul(Y, gt) | 0, g = Math.imul(Y, mt), u = u + Math.imul(H, pt) | 0, s = s + Math.imul(H, yt) | 0, s = s + Math.imul(z, pt) | 0, g = g + Math.imul(z, yt) | 0, u = u + Math.imul(I, vt) | 0, s = s + Math.imul(I, bt) | 0, s = s + Math.imul(N, vt) | 0, g = g + Math.imul(N, bt) | 0;
|
|
559
|
-
var ur = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
560
|
-
b = (g + (s >>> 13) | 0) + (ur >>> 26) | 0, ur &= 67108863, u = Math.imul(Q, gt), s = Math.imul(Q, mt), s = s + Math.imul(F, gt) | 0, g = Math.imul(F, mt), u = u + Math.imul(X, pt) | 0, s = s + Math.imul(X, yt) | 0, s = s + Math.imul(Y, pt) | 0, g = g + Math.imul(Y, yt) | 0, u = u + Math.imul(H, vt) | 0, s = s + Math.imul(H, bt) | 0, s = s + Math.imul(z, vt) | 0, g = g + Math.imul(z, bt) | 0, u = u + Math.imul(I, xt) | 0, s = s + Math.imul(I, Et) | 0, s = s + Math.imul(N, xt) | 0, g = g + Math.imul(N, Et) | 0;
|
|
561
|
-
var dr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
562
|
-
b = (g + (s >>> 13) | 0) + (dr >>> 26) | 0, dr &= 67108863, u = Math.imul(at, gt), s = Math.imul(at, mt), s = s + Math.imul(ht, gt) | 0, g = Math.imul(ht, mt), u = u + Math.imul(Q, pt) | 0, s = s + Math.imul(Q, yt) | 0, s = s + Math.imul(F, pt) | 0, g = g + Math.imul(F, yt) | 0, u = u + Math.imul(X, vt) | 0, s = s + Math.imul(X, bt) | 0, s = s + Math.imul(Y, vt) | 0, g = g + Math.imul(Y, bt) | 0, u = u + Math.imul(H, xt) | 0, s = s + Math.imul(H, Et) | 0, s = s + Math.imul(z, xt) | 0, g = g + Math.imul(z, Et) | 0, u = u + Math.imul(I, Mt) | 0, s = s + Math.imul(I, _t) | 0, s = s + Math.imul(N, Mt) | 0, g = g + Math.imul(N, _t) | 0;
|
|
563
|
-
var wr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
564
|
-
b = (g + (s >>> 13) | 0) + (wr >>> 26) | 0, wr &= 67108863, u = Math.imul(et, gt), s = Math.imul(et, mt), s = s + Math.imul(rt, gt) | 0, g = Math.imul(rt, mt), u = u + Math.imul(at, pt) | 0, s = s + Math.imul(at, yt) | 0, s = s + Math.imul(ht, pt) | 0, g = g + Math.imul(ht, yt) | 0, u = u + Math.imul(Q, vt) | 0, s = s + Math.imul(Q, bt) | 0, s = s + Math.imul(F, vt) | 0, g = g + Math.imul(F, bt) | 0, u = u + Math.imul(X, xt) | 0, s = s + Math.imul(X, Et) | 0, s = s + Math.imul(Y, xt) | 0, g = g + Math.imul(Y, Et) | 0, u = u + Math.imul(H, Mt) | 0, s = s + Math.imul(H, _t) | 0, s = s + Math.imul(z, Mt) | 0, g = g + Math.imul(z, _t) | 0, u = u + Math.imul(I, Bt) | 0, s = s + Math.imul(I, St) | 0, s = s + Math.imul(N, Bt) | 0, g = g + Math.imul(N, St) | 0;
|
|
565
|
-
var gr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
566
|
-
b = (g + (s >>> 13) | 0) + (gr >>> 26) | 0, gr &= 67108863, u = Math.imul(nt, gt), s = Math.imul(nt, mt), s = s + Math.imul(it, gt) | 0, g = Math.imul(it, mt), u = u + Math.imul(et, pt) | 0, s = s + Math.imul(et, yt) | 0, s = s + Math.imul(rt, pt) | 0, g = g + Math.imul(rt, yt) | 0, u = u + Math.imul(at, vt) | 0, s = s + Math.imul(at, bt) | 0, s = s + Math.imul(ht, vt) | 0, g = g + Math.imul(ht, bt) | 0, u = u + Math.imul(Q, xt) | 0, s = s + Math.imul(Q, Et) | 0, s = s + Math.imul(F, xt) | 0, g = g + Math.imul(F, Et) | 0, u = u + Math.imul(X, Mt) | 0, s = s + Math.imul(X, _t) | 0, s = s + Math.imul(Y, Mt) | 0, g = g + Math.imul(Y, _t) | 0, u = u + Math.imul(H, Bt) | 0, s = s + Math.imul(H, St) | 0, s = s + Math.imul(z, Bt) | 0, g = g + Math.imul(z, St) | 0, u = u + Math.imul(I, At) | 0, s = s + Math.imul(I, It) | 0, s = s + Math.imul(N, At) | 0, g = g + Math.imul(N, It) | 0;
|
|
567
|
-
var mr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
568
|
-
b = (g + (s >>> 13) | 0) + (mr >>> 26) | 0, mr &= 67108863, u = Math.imul(ot, gt), s = Math.imul(ot, mt), s = s + Math.imul(st, gt) | 0, g = Math.imul(st, mt), u = u + Math.imul(nt, pt) | 0, s = s + Math.imul(nt, yt) | 0, s = s + Math.imul(it, pt) | 0, g = g + Math.imul(it, yt) | 0, u = u + Math.imul(et, vt) | 0, s = s + Math.imul(et, bt) | 0, s = s + Math.imul(rt, vt) | 0, g = g + Math.imul(rt, bt) | 0, u = u + Math.imul(at, xt) | 0, s = s + Math.imul(at, Et) | 0, s = s + Math.imul(ht, xt) | 0, g = g + Math.imul(ht, Et) | 0, u = u + Math.imul(Q, Mt) | 0, s = s + Math.imul(Q, _t) | 0, s = s + Math.imul(F, Mt) | 0, g = g + Math.imul(F, _t) | 0, u = u + Math.imul(X, Bt) | 0, s = s + Math.imul(X, St) | 0, s = s + Math.imul(Y, Bt) | 0, g = g + Math.imul(Y, St) | 0, u = u + Math.imul(H, At) | 0, s = s + Math.imul(H, It) | 0, s = s + Math.imul(z, At) | 0, g = g + Math.imul(z, It) | 0, u = u + Math.imul(I, kt) | 0, s = s + Math.imul(I, Ut) | 0, s = s + Math.imul(N, kt) | 0, g = g + Math.imul(N, Ut) | 0;
|
|
569
|
-
var pr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
570
|
-
b = (g + (s >>> 13) | 0) + (pr >>> 26) | 0, pr &= 67108863, u = Math.imul(ct, gt), s = Math.imul(ct, mt), s = s + Math.imul(lt, gt) | 0, g = Math.imul(lt, mt), u = u + Math.imul(ot, pt) | 0, s = s + Math.imul(ot, yt) | 0, s = s + Math.imul(st, pt) | 0, g = g + Math.imul(st, yt) | 0, u = u + Math.imul(nt, vt) | 0, s = s + Math.imul(nt, bt) | 0, s = s + Math.imul(it, vt) | 0, g = g + Math.imul(it, bt) | 0, u = u + Math.imul(et, xt) | 0, s = s + Math.imul(et, Et) | 0, s = s + Math.imul(rt, xt) | 0, g = g + Math.imul(rt, Et) | 0, u = u + Math.imul(at, Mt) | 0, s = s + Math.imul(at, _t) | 0, s = s + Math.imul(ht, Mt) | 0, g = g + Math.imul(ht, _t) | 0, u = u + Math.imul(Q, Bt) | 0, s = s + Math.imul(Q, St) | 0, s = s + Math.imul(F, Bt) | 0, g = g + Math.imul(F, St) | 0, u = u + Math.imul(X, At) | 0, s = s + Math.imul(X, It) | 0, s = s + Math.imul(Y, At) | 0, g = g + Math.imul(Y, It) | 0, u = u + Math.imul(H, kt) | 0, s = s + Math.imul(H, Ut) | 0, s = s + Math.imul(z, kt) | 0, g = g + Math.imul(z, Ut) | 0, u = u + Math.imul(I, Nt) | 0, s = s + Math.imul(I, Rt) | 0, s = s + Math.imul(N, Nt) | 0, g = g + Math.imul(N, Rt) | 0;
|
|
571
|
-
var yr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
572
|
-
b = (g + (s >>> 13) | 0) + (yr >>> 26) | 0, yr &= 67108863, u = Math.imul(dt, gt), s = Math.imul(dt, mt), s = s + Math.imul(wt, gt) | 0, g = Math.imul(wt, mt), u = u + Math.imul(ct, pt) | 0, s = s + Math.imul(ct, yt) | 0, s = s + Math.imul(lt, pt) | 0, g = g + Math.imul(lt, yt) | 0, u = u + Math.imul(ot, vt) | 0, s = s + Math.imul(ot, bt) | 0, s = s + Math.imul(st, vt) | 0, g = g + Math.imul(st, bt) | 0, u = u + Math.imul(nt, xt) | 0, s = s + Math.imul(nt, Et) | 0, s = s + Math.imul(it, xt) | 0, g = g + Math.imul(it, Et) | 0, u = u + Math.imul(et, Mt) | 0, s = s + Math.imul(et, _t) | 0, s = s + Math.imul(rt, Mt) | 0, g = g + Math.imul(rt, _t) | 0, u = u + Math.imul(at, Bt) | 0, s = s + Math.imul(at, St) | 0, s = s + Math.imul(ht, Bt) | 0, g = g + Math.imul(ht, St) | 0, u = u + Math.imul(Q, At) | 0, s = s + Math.imul(Q, It) | 0, s = s + Math.imul(F, At) | 0, g = g + Math.imul(F, It) | 0, u = u + Math.imul(X, kt) | 0, s = s + Math.imul(X, Ut) | 0, s = s + Math.imul(Y, kt) | 0, g = g + Math.imul(Y, Ut) | 0, u = u + Math.imul(H, Nt) | 0, s = s + Math.imul(H, Rt) | 0, s = s + Math.imul(z, Nt) | 0, g = g + Math.imul(z, Rt) | 0, u = u + Math.imul(I, Ot) | 0, s = s + Math.imul(I, Lt) | 0, s = s + Math.imul(N, Ot) | 0, g = g + Math.imul(N, Lt) | 0;
|
|
573
|
-
var vr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
574
|
-
b = (g + (s >>> 13) | 0) + (vr >>> 26) | 0, vr &= 67108863, u = Math.imul(dt, pt), s = Math.imul(dt, yt), s = s + Math.imul(wt, pt) | 0, g = Math.imul(wt, yt), u = u + Math.imul(ct, vt) | 0, s = s + Math.imul(ct, bt) | 0, s = s + Math.imul(lt, vt) | 0, g = g + Math.imul(lt, bt) | 0, u = u + Math.imul(ot, xt) | 0, s = s + Math.imul(ot, Et) | 0, s = s + Math.imul(st, xt) | 0, g = g + Math.imul(st, Et) | 0, u = u + Math.imul(nt, Mt) | 0, s = s + Math.imul(nt, _t) | 0, s = s + Math.imul(it, Mt) | 0, g = g + Math.imul(it, _t) | 0, u = u + Math.imul(et, Bt) | 0, s = s + Math.imul(et, St) | 0, s = s + Math.imul(rt, Bt) | 0, g = g + Math.imul(rt, St) | 0, u = u + Math.imul(at, At) | 0, s = s + Math.imul(at, It) | 0, s = s + Math.imul(ht, At) | 0, g = g + Math.imul(ht, It) | 0, u = u + Math.imul(Q, kt) | 0, s = s + Math.imul(Q, Ut) | 0, s = s + Math.imul(F, kt) | 0, g = g + Math.imul(F, Ut) | 0, u = u + Math.imul(X, Nt) | 0, s = s + Math.imul(X, Rt) | 0, s = s + Math.imul(Y, Nt) | 0, g = g + Math.imul(Y, Rt) | 0, u = u + Math.imul(H, Ot) | 0, s = s + Math.imul(H, Lt) | 0, s = s + Math.imul(z, Ot) | 0, g = g + Math.imul(z, Lt) | 0;
|
|
575
|
-
var br = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
576
|
-
b = (g + (s >>> 13) | 0) + (br >>> 26) | 0, br &= 67108863, u = Math.imul(dt, vt), s = Math.imul(dt, bt), s = s + Math.imul(wt, vt) | 0, g = Math.imul(wt, bt), u = u + Math.imul(ct, xt) | 0, s = s + Math.imul(ct, Et) | 0, s = s + Math.imul(lt, xt) | 0, g = g + Math.imul(lt, Et) | 0, u = u + Math.imul(ot, Mt) | 0, s = s + Math.imul(ot, _t) | 0, s = s + Math.imul(st, Mt) | 0, g = g + Math.imul(st, _t) | 0, u = u + Math.imul(nt, Bt) | 0, s = s + Math.imul(nt, St) | 0, s = s + Math.imul(it, Bt) | 0, g = g + Math.imul(it, St) | 0, u = u + Math.imul(et, At) | 0, s = s + Math.imul(et, It) | 0, s = s + Math.imul(rt, At) | 0, g = g + Math.imul(rt, It) | 0, u = u + Math.imul(at, kt) | 0, s = s + Math.imul(at, Ut) | 0, s = s + Math.imul(ht, kt) | 0, g = g + Math.imul(ht, Ut) | 0, u = u + Math.imul(Q, Nt) | 0, s = s + Math.imul(Q, Rt) | 0, s = s + Math.imul(F, Nt) | 0, g = g + Math.imul(F, Rt) | 0, u = u + Math.imul(X, Ot) | 0, s = s + Math.imul(X, Lt) | 0, s = s + Math.imul(Y, Ot) | 0, g = g + Math.imul(Y, Lt) | 0;
|
|
577
|
-
var xr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
578
|
-
b = (g + (s >>> 13) | 0) + (xr >>> 26) | 0, xr &= 67108863, u = Math.imul(dt, xt), s = Math.imul(dt, Et), s = s + Math.imul(wt, xt) | 0, g = Math.imul(wt, Et), u = u + Math.imul(ct, Mt) | 0, s = s + Math.imul(ct, _t) | 0, s = s + Math.imul(lt, Mt) | 0, g = g + Math.imul(lt, _t) | 0, u = u + Math.imul(ot, Bt) | 0, s = s + Math.imul(ot, St) | 0, s = s + Math.imul(st, Bt) | 0, g = g + Math.imul(st, St) | 0, u = u + Math.imul(nt, At) | 0, s = s + Math.imul(nt, It) | 0, s = s + Math.imul(it, At) | 0, g = g + Math.imul(it, It) | 0, u = u + Math.imul(et, kt) | 0, s = s + Math.imul(et, Ut) | 0, s = s + Math.imul(rt, kt) | 0, g = g + Math.imul(rt, Ut) | 0, u = u + Math.imul(at, Nt) | 0, s = s + Math.imul(at, Rt) | 0, s = s + Math.imul(ht, Nt) | 0, g = g + Math.imul(ht, Rt) | 0, u = u + Math.imul(Q, Ot) | 0, s = s + Math.imul(Q, Lt) | 0, s = s + Math.imul(F, Ot) | 0, g = g + Math.imul(F, Lt) | 0;
|
|
579
|
-
var Er = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
580
|
-
b = (g + (s >>> 13) | 0) + (Er >>> 26) | 0, Er &= 67108863, u = Math.imul(dt, Mt), s = Math.imul(dt, _t), s = s + Math.imul(wt, Mt) | 0, g = Math.imul(wt, _t), u = u + Math.imul(ct, Bt) | 0, s = s + Math.imul(ct, St) | 0, s = s + Math.imul(lt, Bt) | 0, g = g + Math.imul(lt, St) | 0, u = u + Math.imul(ot, At) | 0, s = s + Math.imul(ot, It) | 0, s = s + Math.imul(st, At) | 0, g = g + Math.imul(st, It) | 0, u = u + Math.imul(nt, kt) | 0, s = s + Math.imul(nt, Ut) | 0, s = s + Math.imul(it, kt) | 0, g = g + Math.imul(it, Ut) | 0, u = u + Math.imul(et, Nt) | 0, s = s + Math.imul(et, Rt) | 0, s = s + Math.imul(rt, Nt) | 0, g = g + Math.imul(rt, Rt) | 0, u = u + Math.imul(at, Ot) | 0, s = s + Math.imul(at, Lt) | 0, s = s + Math.imul(ht, Ot) | 0, g = g + Math.imul(ht, Lt) | 0;
|
|
581
|
-
var Mr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
582
|
-
b = (g + (s >>> 13) | 0) + (Mr >>> 26) | 0, Mr &= 67108863, u = Math.imul(dt, Bt), s = Math.imul(dt, St), s = s + Math.imul(wt, Bt) | 0, g = Math.imul(wt, St), u = u + Math.imul(ct, At) | 0, s = s + Math.imul(ct, It) | 0, s = s + Math.imul(lt, At) | 0, g = g + Math.imul(lt, It) | 0, u = u + Math.imul(ot, kt) | 0, s = s + Math.imul(ot, Ut) | 0, s = s + Math.imul(st, kt) | 0, g = g + Math.imul(st, Ut) | 0, u = u + Math.imul(nt, Nt) | 0, s = s + Math.imul(nt, Rt) | 0, s = s + Math.imul(it, Nt) | 0, g = g + Math.imul(it, Rt) | 0, u = u + Math.imul(et, Ot) | 0, s = s + Math.imul(et, Lt) | 0, s = s + Math.imul(rt, Ot) | 0, g = g + Math.imul(rt, Lt) | 0;
|
|
583
|
-
var _r = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
584
|
-
b = (g + (s >>> 13) | 0) + (_r >>> 26) | 0, _r &= 67108863, u = Math.imul(dt, At), s = Math.imul(dt, It), s = s + Math.imul(wt, At) | 0, g = Math.imul(wt, It), u = u + Math.imul(ct, kt) | 0, s = s + Math.imul(ct, Ut) | 0, s = s + Math.imul(lt, kt) | 0, g = g + Math.imul(lt, Ut) | 0, u = u + Math.imul(ot, Nt) | 0, s = s + Math.imul(ot, Rt) | 0, s = s + Math.imul(st, Nt) | 0, g = g + Math.imul(st, Rt) | 0, u = u + Math.imul(nt, Ot) | 0, s = s + Math.imul(nt, Lt) | 0, s = s + Math.imul(it, Ot) | 0, g = g + Math.imul(it, Lt) | 0;
|
|
585
|
-
var Br = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
586
|
-
b = (g + (s >>> 13) | 0) + (Br >>> 26) | 0, Br &= 67108863, u = Math.imul(dt, kt), s = Math.imul(dt, Ut), s = s + Math.imul(wt, kt) | 0, g = Math.imul(wt, Ut), u = u + Math.imul(ct, Nt) | 0, s = s + Math.imul(ct, Rt) | 0, s = s + Math.imul(lt, Nt) | 0, g = g + Math.imul(lt, Rt) | 0, u = u + Math.imul(ot, Ot) | 0, s = s + Math.imul(ot, Lt) | 0, s = s + Math.imul(st, Ot) | 0, g = g + Math.imul(st, Lt) | 0;
|
|
587
|
-
var Sr = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
588
|
-
b = (g + (s >>> 13) | 0) + (Sr >>> 26) | 0, Sr &= 67108863, u = Math.imul(dt, Nt), s = Math.imul(dt, Rt), s = s + Math.imul(wt, Nt) | 0, g = Math.imul(wt, Rt), u = u + Math.imul(ct, Ot) | 0, s = s + Math.imul(ct, Lt) | 0, s = s + Math.imul(lt, Ot) | 0, g = g + Math.imul(lt, Lt) | 0;
|
|
589
|
-
var Ar = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
590
|
-
b = (g + (s >>> 13) | 0) + (Ar >>> 26) | 0, Ar &= 67108863, u = Math.imul(dt, Ot), s = Math.imul(dt, Lt), s = s + Math.imul(wt, Ot) | 0, g = Math.imul(wt, Lt);
|
|
591
|
-
var Ir = (b + u | 0) + ((s & 8191) << 13) | 0;
|
|
592
|
-
return b = (g + (s >>> 13) | 0) + (Ir >>> 26) | 0, Ir &= 67108863, m[0] = cr, m[1] = lr, m[2] = ur, m[3] = dr, m[4] = wr, m[5] = gr, m[6] = mr, m[7] = pr, m[8] = yr, m[9] = vr, m[10] = br, m[11] = xr, m[12] = Er, m[13] = Mr, m[14] = _r, m[15] = Br, m[16] = Sr, m[17] = Ar, m[18] = Ir, b !== 0 && (m[19] = b, a.length++), a;
|
|
593
|
-
};
|
|
594
|
-
Math.imul || (L = S);
|
|
595
|
-
function A(p, n, f) {
|
|
596
|
-
f.negative = n.negative ^ p.negative, f.length = p.length + n.length;
|
|
597
|
-
for (var a = 0, h = 0, l = 0; l < f.length - 1; l++) {
|
|
598
|
-
var m = h;
|
|
599
|
-
h = 0;
|
|
600
|
-
for (var b = a & 67108863, u = Math.min(l, n.length - 1), s = Math.max(0, l - p.length + 1); s <= u; s++) {
|
|
601
|
-
var g = l - s, B = p.words[g] | 0, I = n.words[s] | 0, N = B * I, j = N & 67108863;
|
|
602
|
-
m = m + (N / 67108864 | 0) | 0, j = j + b | 0, b = j & 67108863, m = m + (j >>> 26) | 0, h += m >>> 26, m &= 67108863;
|
|
603
|
-
}
|
|
604
|
-
f.words[l] = b, a = m, m = h;
|
|
605
|
-
}
|
|
606
|
-
return a !== 0 ? f.words[l] = a : f.length--, f._strip();
|
|
607
|
-
}
|
|
608
|
-
function q(p, n, f) {
|
|
609
|
-
return A(p, n, f);
|
|
610
|
-
}
|
|
611
|
-
i.prototype.mulTo = function(n, f) {
|
|
612
|
-
var a, h = this.length + n.length;
|
|
613
|
-
return this.length === 10 && n.length === 10 ? a = L(this, n, f) : h < 63 ? a = S(this, n, f) : h < 1024 ? a = A(this, n, f) : a = q(this, n, f), a;
|
|
614
|
-
}, i.prototype.mul = function(n) {
|
|
615
|
-
var f = new i(null);
|
|
616
|
-
return f.words = new Array(this.length + n.length), this.mulTo(n, f);
|
|
617
|
-
}, i.prototype.mulf = function(n) {
|
|
618
|
-
var f = new i(null);
|
|
619
|
-
return f.words = new Array(this.length + n.length), q(this, n, f);
|
|
620
|
-
}, i.prototype.imul = function(n) {
|
|
621
|
-
return this.clone().mulTo(n, this);
|
|
622
|
-
}, i.prototype.imuln = function(n) {
|
|
623
|
-
var f = n < 0;
|
|
624
|
-
f && (n = -n), o(typeof n == "number"), o(n < 67108864);
|
|
625
|
-
for (var a = 0, h = 0; h < this.length; h++) {
|
|
626
|
-
var l = (this.words[h] | 0) * n, m = (l & 67108863) + (a & 67108863);
|
|
627
|
-
a >>= 26, a += l / 67108864 | 0, a += m >>> 26, this.words[h] = m & 67108863;
|
|
628
|
-
}
|
|
629
|
-
return a !== 0 && (this.words[h] = a, this.length++), f ? this.ineg() : this;
|
|
630
|
-
}, i.prototype.muln = function(n) {
|
|
631
|
-
return this.clone().imuln(n);
|
|
632
|
-
}, i.prototype.sqr = function() {
|
|
633
|
-
return this.mul(this);
|
|
634
|
-
}, i.prototype.isqr = function() {
|
|
635
|
-
return this.imul(this.clone());
|
|
636
|
-
}, i.prototype.pow = function(n) {
|
|
637
|
-
var f = _(n);
|
|
638
|
-
if (f.length === 0) return new i(1);
|
|
639
|
-
for (var a = this, h = 0; h < f.length && f[h] === 0; h++, a = a.sqr())
|
|
640
|
-
;
|
|
641
|
-
if (++h < f.length)
|
|
642
|
-
for (var l = a.sqr(); h < f.length; h++, l = l.sqr())
|
|
643
|
-
f[h] !== 0 && (a = a.mul(l));
|
|
644
|
-
return a;
|
|
645
|
-
}, i.prototype.iushln = function(n) {
|
|
646
|
-
o(typeof n == "number" && n >= 0);
|
|
647
|
-
var f = n % 26, a = (n - f) / 26, h = 67108863 >>> 26 - f << 26 - f, l;
|
|
648
|
-
if (f !== 0) {
|
|
649
|
-
var m = 0;
|
|
650
|
-
for (l = 0; l < this.length; l++) {
|
|
651
|
-
var b = this.words[l] & h, u = (this.words[l] | 0) - b << f;
|
|
652
|
-
this.words[l] = u | m, m = b >>> 26 - f;
|
|
653
|
-
}
|
|
654
|
-
m && (this.words[l] = m, this.length++);
|
|
655
|
-
}
|
|
656
|
-
if (a !== 0) {
|
|
657
|
-
for (l = this.length - 1; l >= 0; l--)
|
|
658
|
-
this.words[l + a] = this.words[l];
|
|
659
|
-
for (l = 0; l < a; l++)
|
|
660
|
-
this.words[l] = 0;
|
|
661
|
-
this.length += a;
|
|
662
|
-
}
|
|
663
|
-
return this._strip();
|
|
664
|
-
}, i.prototype.ishln = function(n) {
|
|
665
|
-
return o(this.negative === 0), this.iushln(n);
|
|
666
|
-
}, i.prototype.iushrn = function(n, f, a) {
|
|
667
|
-
o(typeof n == "number" && n >= 0);
|
|
668
|
-
var h;
|
|
669
|
-
f ? h = (f - f % 26) / 26 : h = 0;
|
|
670
|
-
var l = n % 26, m = Math.min((n - l) / 26, this.length), b = 67108863 ^ 67108863 >>> l << l, u = a;
|
|
671
|
-
if (h -= m, h = Math.max(0, h), u) {
|
|
672
|
-
for (var s = 0; s < m; s++)
|
|
673
|
-
u.words[s] = this.words[s];
|
|
674
|
-
u.length = m;
|
|
675
|
-
}
|
|
676
|
-
if (m !== 0) if (this.length > m)
|
|
677
|
-
for (this.length -= m, s = 0; s < this.length; s++)
|
|
678
|
-
this.words[s] = this.words[s + m];
|
|
679
|
-
else
|
|
680
|
-
this.words[0] = 0, this.length = 1;
|
|
681
|
-
var g = 0;
|
|
682
|
-
for (s = this.length - 1; s >= 0 && (g !== 0 || s >= h); s--) {
|
|
683
|
-
var B = this.words[s] | 0;
|
|
684
|
-
this.words[s] = g << 26 - l | B >>> l, g = B & b;
|
|
685
|
-
}
|
|
686
|
-
return u && g !== 0 && (u.words[u.length++] = g), this.length === 0 && (this.words[0] = 0, this.length = 1), this._strip();
|
|
687
|
-
}, i.prototype.ishrn = function(n, f, a) {
|
|
688
|
-
return o(this.negative === 0), this.iushrn(n, f, a);
|
|
689
|
-
}, i.prototype.shln = function(n) {
|
|
690
|
-
return this.clone().ishln(n);
|
|
691
|
-
}, i.prototype.ushln = function(n) {
|
|
692
|
-
return this.clone().iushln(n);
|
|
693
|
-
}, i.prototype.shrn = function(n) {
|
|
694
|
-
return this.clone().ishrn(n);
|
|
695
|
-
}, i.prototype.ushrn = function(n) {
|
|
696
|
-
return this.clone().iushrn(n);
|
|
697
|
-
}, i.prototype.testn = function(n) {
|
|
698
|
-
o(typeof n == "number" && n >= 0);
|
|
699
|
-
var f = n % 26, a = (n - f) / 26, h = 1 << f;
|
|
700
|
-
if (this.length <= a) return !1;
|
|
701
|
-
var l = this.words[a];
|
|
702
|
-
return !!(l & h);
|
|
703
|
-
}, i.prototype.imaskn = function(n) {
|
|
704
|
-
o(typeof n == "number" && n >= 0);
|
|
705
|
-
var f = n % 26, a = (n - f) / 26;
|
|
706
|
-
if (o(this.negative === 0, "imaskn works only with positive numbers"), this.length <= a)
|
|
707
|
-
return this;
|
|
708
|
-
if (f !== 0 && a++, this.length = Math.min(a, this.length), f !== 0) {
|
|
709
|
-
var h = 67108863 ^ 67108863 >>> f << f;
|
|
710
|
-
this.words[this.length - 1] &= h;
|
|
711
|
-
}
|
|
712
|
-
return this._strip();
|
|
713
|
-
}, i.prototype.maskn = function(n) {
|
|
714
|
-
return this.clone().imaskn(n);
|
|
715
|
-
}, i.prototype.iaddn = function(n) {
|
|
716
|
-
return o(typeof n == "number"), o(n < 67108864), n < 0 ? this.isubn(-n) : this.negative !== 0 ? this.length === 1 && (this.words[0] | 0) <= n ? (this.words[0] = n - (this.words[0] | 0), this.negative = 0, this) : (this.negative = 0, this.isubn(n), this.negative = 1, this) : this._iaddn(n);
|
|
717
|
-
}, i.prototype._iaddn = function(n) {
|
|
718
|
-
this.words[0] += n;
|
|
719
|
-
for (var f = 0; f < this.length && this.words[f] >= 67108864; f++)
|
|
720
|
-
this.words[f] -= 67108864, f === this.length - 1 ? this.words[f + 1] = 1 : this.words[f + 1]++;
|
|
721
|
-
return this.length = Math.max(this.length, f + 1), this;
|
|
722
|
-
}, i.prototype.isubn = function(n) {
|
|
723
|
-
if (o(typeof n == "number"), o(n < 67108864), n < 0) return this.iaddn(-n);
|
|
724
|
-
if (this.negative !== 0)
|
|
725
|
-
return this.negative = 0, this.iaddn(n), this.negative = 1, this;
|
|
726
|
-
if (this.words[0] -= n, this.length === 1 && this.words[0] < 0)
|
|
727
|
-
this.words[0] = -this.words[0], this.negative = 1;
|
|
728
|
-
else
|
|
729
|
-
for (var f = 0; f < this.length && this.words[f] < 0; f++)
|
|
730
|
-
this.words[f] += 67108864, this.words[f + 1] -= 1;
|
|
731
|
-
return this._strip();
|
|
732
|
-
}, i.prototype.addn = function(n) {
|
|
733
|
-
return this.clone().iaddn(n);
|
|
734
|
-
}, i.prototype.subn = function(n) {
|
|
735
|
-
return this.clone().isubn(n);
|
|
736
|
-
}, i.prototype.iabs = function() {
|
|
737
|
-
return this.negative = 0, this;
|
|
738
|
-
}, i.prototype.abs = function() {
|
|
739
|
-
return this.clone().iabs();
|
|
740
|
-
}, i.prototype._ishlnsubmul = function(n, f, a) {
|
|
741
|
-
var h = n.length + a, l;
|
|
742
|
-
this._expand(h);
|
|
743
|
-
var m, b = 0;
|
|
744
|
-
for (l = 0; l < n.length; l++) {
|
|
745
|
-
m = (this.words[l + a] | 0) + b;
|
|
746
|
-
var u = (n.words[l] | 0) * f;
|
|
747
|
-
m -= u & 67108863, b = (m >> 26) - (u / 67108864 | 0), this.words[l + a] = m & 67108863;
|
|
748
|
-
}
|
|
749
|
-
for (; l < this.length - a; l++)
|
|
750
|
-
m = (this.words[l + a] | 0) + b, b = m >> 26, this.words[l + a] = m & 67108863;
|
|
751
|
-
if (b === 0) return this._strip();
|
|
752
|
-
for (o(b === -1), b = 0, l = 0; l < this.length; l++)
|
|
753
|
-
m = -(this.words[l] | 0) + b, b = m >> 26, this.words[l] = m & 67108863;
|
|
754
|
-
return this.negative = 1, this._strip();
|
|
755
|
-
}, i.prototype._wordDiv = function(n, f) {
|
|
756
|
-
var a = this.length - n.length, h = this.clone(), l = n, m = l.words[l.length - 1] | 0, b = this._countBits(m);
|
|
757
|
-
a = 26 - b, a !== 0 && (l = l.ushln(a), h.iushln(a), m = l.words[l.length - 1] | 0);
|
|
758
|
-
var u = h.length - l.length, s;
|
|
759
|
-
if (f !== "mod") {
|
|
760
|
-
s = new i(null), s.length = u + 1, s.words = new Array(s.length);
|
|
761
|
-
for (var g = 0; g < s.length; g++)
|
|
762
|
-
s.words[g] = 0;
|
|
763
|
-
}
|
|
764
|
-
var B = h.clone()._ishlnsubmul(l, 1, u);
|
|
765
|
-
B.negative === 0 && (h = B, s && (s.words[u] = 1));
|
|
766
|
-
for (var I = u - 1; I >= 0; I--) {
|
|
767
|
-
var N = (h.words[l.length + I] | 0) * 67108864 + (h.words[l.length + I - 1] | 0);
|
|
768
|
-
for (N = Math.min(N / m | 0, 67108863), h._ishlnsubmul(l, N, I); h.negative !== 0; )
|
|
769
|
-
N--, h.negative = 0, h._ishlnsubmul(l, 1, I), h.isZero() || (h.negative ^= 1);
|
|
770
|
-
s && (s.words[I] = N);
|
|
771
|
-
}
|
|
772
|
-
return s && s._strip(), h._strip(), f !== "div" && a !== 0 && h.iushrn(a), {
|
|
773
|
-
div: s || null,
|
|
774
|
-
mod: h
|
|
775
|
-
};
|
|
776
|
-
}, i.prototype.divmod = function(n, f, a) {
|
|
777
|
-
if (o(!n.isZero()), this.isZero())
|
|
778
|
-
return {
|
|
779
|
-
div: new i(0),
|
|
780
|
-
mod: new i(0)
|
|
781
|
-
};
|
|
782
|
-
var h, l, m;
|
|
783
|
-
return this.negative !== 0 && n.negative === 0 ? (m = this.neg().divmod(n, f), f !== "mod" && (h = m.div.neg()), f !== "div" && (l = m.mod.neg(), a && l.negative !== 0 && l.iadd(n)), {
|
|
784
|
-
div: h,
|
|
785
|
-
mod: l
|
|
786
|
-
}) : this.negative === 0 && n.negative !== 0 ? (m = this.divmod(n.neg(), f), f !== "mod" && (h = m.div.neg()), {
|
|
787
|
-
div: h,
|
|
788
|
-
mod: m.mod
|
|
789
|
-
}) : this.negative & n.negative ? (m = this.neg().divmod(n.neg(), f), f !== "div" && (l = m.mod.neg(), a && l.negative !== 0 && l.isub(n)), {
|
|
790
|
-
div: m.div,
|
|
791
|
-
mod: l
|
|
792
|
-
}) : n.length > this.length || this.cmp(n) < 0 ? {
|
|
793
|
-
div: new i(0),
|
|
794
|
-
mod: this
|
|
795
|
-
} : n.length === 1 ? f === "div" ? {
|
|
796
|
-
div: this.divn(n.words[0]),
|
|
797
|
-
mod: null
|
|
798
|
-
} : f === "mod" ? {
|
|
799
|
-
div: null,
|
|
800
|
-
mod: new i(this.modrn(n.words[0]))
|
|
801
|
-
} : {
|
|
802
|
-
div: this.divn(n.words[0]),
|
|
803
|
-
mod: new i(this.modrn(n.words[0]))
|
|
804
|
-
} : this._wordDiv(n, f);
|
|
805
|
-
}, i.prototype.div = function(n) {
|
|
806
|
-
return this.divmod(n, "div", !1).div;
|
|
807
|
-
}, i.prototype.mod = function(n) {
|
|
808
|
-
return this.divmod(n, "mod", !1).mod;
|
|
809
|
-
}, i.prototype.umod = function(n) {
|
|
810
|
-
return this.divmod(n, "mod", !0).mod;
|
|
811
|
-
}, i.prototype.divRound = function(n) {
|
|
812
|
-
var f = this.divmod(n);
|
|
813
|
-
if (f.mod.isZero()) return f.div;
|
|
814
|
-
var a = f.div.negative !== 0 ? f.mod.isub(n) : f.mod, h = n.ushrn(1), l = n.andln(1), m = a.cmp(h);
|
|
815
|
-
return m < 0 || l === 1 && m === 0 ? f.div : f.div.negative !== 0 ? f.div.isubn(1) : f.div.iaddn(1);
|
|
816
|
-
}, i.prototype.modrn = function(n) {
|
|
817
|
-
var f = n < 0;
|
|
818
|
-
f && (n = -n), o(n <= 67108863);
|
|
819
|
-
for (var a = (1 << 26) % n, h = 0, l = this.length - 1; l >= 0; l--)
|
|
820
|
-
h = (a * h + (this.words[l] | 0)) % n;
|
|
821
|
-
return f ? -h : h;
|
|
822
|
-
}, i.prototype.modn = function(n) {
|
|
823
|
-
return this.modrn(n);
|
|
824
|
-
}, i.prototype.idivn = function(n) {
|
|
825
|
-
var f = n < 0;
|
|
826
|
-
f && (n = -n), o(n <= 67108863);
|
|
827
|
-
for (var a = 0, h = this.length - 1; h >= 0; h--) {
|
|
828
|
-
var l = (this.words[h] | 0) + a * 67108864;
|
|
829
|
-
this.words[h] = l / n | 0, a = l % n;
|
|
830
|
-
}
|
|
831
|
-
return this._strip(), f ? this.ineg() : this;
|
|
832
|
-
}, i.prototype.divn = function(n) {
|
|
833
|
-
return this.clone().idivn(n);
|
|
834
|
-
}, i.prototype.egcd = function(n) {
|
|
835
|
-
o(n.negative === 0), o(!n.isZero());
|
|
836
|
-
var f = this, a = n.clone();
|
|
837
|
-
f.negative !== 0 ? f = f.umod(n) : f = f.clone();
|
|
838
|
-
for (var h = new i(1), l = new i(0), m = new i(0), b = new i(1), u = 0; f.isEven() && a.isEven(); )
|
|
839
|
-
f.iushrn(1), a.iushrn(1), ++u;
|
|
840
|
-
for (var s = a.clone(), g = f.clone(); !f.isZero(); ) {
|
|
841
|
-
for (var B = 0, I = 1; !(f.words[0] & I) && B < 26; ++B, I <<= 1) ;
|
|
842
|
-
if (B > 0)
|
|
843
|
-
for (f.iushrn(B); B-- > 0; )
|
|
844
|
-
(h.isOdd() || l.isOdd()) && (h.iadd(s), l.isub(g)), h.iushrn(1), l.iushrn(1);
|
|
845
|
-
for (var N = 0, j = 1; !(a.words[0] & j) && N < 26; ++N, j <<= 1) ;
|
|
846
|
-
if (N > 0)
|
|
847
|
-
for (a.iushrn(N); N-- > 0; )
|
|
848
|
-
(m.isOdd() || b.isOdd()) && (m.iadd(s), b.isub(g)), m.iushrn(1), b.iushrn(1);
|
|
849
|
-
f.cmp(a) >= 0 ? (f.isub(a), h.isub(m), l.isub(b)) : (a.isub(f), m.isub(h), b.isub(l));
|
|
850
|
-
}
|
|
851
|
-
return {
|
|
852
|
-
a: m,
|
|
853
|
-
b,
|
|
854
|
-
gcd: a.iushln(u)
|
|
855
|
-
};
|
|
856
|
-
}, i.prototype._invmp = function(n) {
|
|
857
|
-
o(n.negative === 0), o(!n.isZero());
|
|
858
|
-
var f = this, a = n.clone();
|
|
859
|
-
f.negative !== 0 ? f = f.umod(n) : f = f.clone();
|
|
860
|
-
for (var h = new i(1), l = new i(0), m = a.clone(); f.cmpn(1) > 0 && a.cmpn(1) > 0; ) {
|
|
861
|
-
for (var b = 0, u = 1; !(f.words[0] & u) && b < 26; ++b, u <<= 1) ;
|
|
862
|
-
if (b > 0)
|
|
863
|
-
for (f.iushrn(b); b-- > 0; )
|
|
864
|
-
h.isOdd() && h.iadd(m), h.iushrn(1);
|
|
865
|
-
for (var s = 0, g = 1; !(a.words[0] & g) && s < 26; ++s, g <<= 1) ;
|
|
866
|
-
if (s > 0)
|
|
867
|
-
for (a.iushrn(s); s-- > 0; )
|
|
868
|
-
l.isOdd() && l.iadd(m), l.iushrn(1);
|
|
869
|
-
f.cmp(a) >= 0 ? (f.isub(a), h.isub(l)) : (a.isub(f), l.isub(h));
|
|
870
|
-
}
|
|
871
|
-
var B;
|
|
872
|
-
return f.cmpn(1) === 0 ? B = h : B = l, B.cmpn(0) < 0 && B.iadd(n), B;
|
|
873
|
-
}, i.prototype.gcd = function(n) {
|
|
874
|
-
if (this.isZero()) return n.abs();
|
|
875
|
-
if (n.isZero()) return this.abs();
|
|
876
|
-
var f = this.clone(), a = n.clone();
|
|
877
|
-
f.negative = 0, a.negative = 0;
|
|
878
|
-
for (var h = 0; f.isEven() && a.isEven(); h++)
|
|
879
|
-
f.iushrn(1), a.iushrn(1);
|
|
880
|
-
do {
|
|
881
|
-
for (; f.isEven(); )
|
|
882
|
-
f.iushrn(1);
|
|
883
|
-
for (; a.isEven(); )
|
|
884
|
-
a.iushrn(1);
|
|
885
|
-
var l = f.cmp(a);
|
|
886
|
-
if (l < 0) {
|
|
887
|
-
var m = f;
|
|
888
|
-
f = a, a = m;
|
|
889
|
-
} else if (l === 0 || a.cmpn(1) === 0)
|
|
890
|
-
break;
|
|
891
|
-
f.isub(a);
|
|
892
|
-
} while (!0);
|
|
893
|
-
return a.iushln(h);
|
|
894
|
-
}, i.prototype.invm = function(n) {
|
|
895
|
-
return this.egcd(n).a.umod(n);
|
|
896
|
-
}, i.prototype.isEven = function() {
|
|
897
|
-
return (this.words[0] & 1) === 0;
|
|
898
|
-
}, i.prototype.isOdd = function() {
|
|
899
|
-
return (this.words[0] & 1) === 1;
|
|
900
|
-
}, i.prototype.andln = function(n) {
|
|
901
|
-
return this.words[0] & n;
|
|
902
|
-
}, i.prototype.bincn = function(n) {
|
|
903
|
-
o(typeof n == "number");
|
|
904
|
-
var f = n % 26, a = (n - f) / 26, h = 1 << f;
|
|
905
|
-
if (this.length <= a)
|
|
906
|
-
return this._expand(a + 1), this.words[a] |= h, this;
|
|
907
|
-
for (var l = h, m = a; l !== 0 && m < this.length; m++) {
|
|
908
|
-
var b = this.words[m] | 0;
|
|
909
|
-
b += l, l = b >>> 26, b &= 67108863, this.words[m] = b;
|
|
910
|
-
}
|
|
911
|
-
return l !== 0 && (this.words[m] = l, this.length++), this;
|
|
912
|
-
}, i.prototype.isZero = function() {
|
|
913
|
-
return this.length === 1 && this.words[0] === 0;
|
|
914
|
-
}, i.prototype.cmpn = function(n) {
|
|
915
|
-
var f = n < 0;
|
|
916
|
-
if (this.negative !== 0 && !f) return -1;
|
|
917
|
-
if (this.negative === 0 && f) return 1;
|
|
918
|
-
this._strip();
|
|
919
|
-
var a;
|
|
920
|
-
if (this.length > 1)
|
|
921
|
-
a = 1;
|
|
922
|
-
else {
|
|
923
|
-
f && (n = -n), o(n <= 67108863, "Number is too big");
|
|
924
|
-
var h = this.words[0] | 0;
|
|
925
|
-
a = h === n ? 0 : h < n ? -1 : 1;
|
|
926
|
-
}
|
|
927
|
-
return this.negative !== 0 ? -a | 0 : a;
|
|
928
|
-
}, i.prototype.cmp = function(n) {
|
|
929
|
-
if (this.negative !== 0 && n.negative === 0) return -1;
|
|
930
|
-
if (this.negative === 0 && n.negative !== 0) return 1;
|
|
931
|
-
var f = this.ucmp(n);
|
|
932
|
-
return this.negative !== 0 ? -f | 0 : f;
|
|
933
|
-
}, i.prototype.ucmp = function(n) {
|
|
934
|
-
if (this.length > n.length) return 1;
|
|
935
|
-
if (this.length < n.length) return -1;
|
|
936
|
-
for (var f = 0, a = this.length - 1; a >= 0; a--) {
|
|
937
|
-
var h = this.words[a] | 0, l = n.words[a] | 0;
|
|
938
|
-
if (h !== l) {
|
|
939
|
-
h < l ? f = -1 : h > l && (f = 1);
|
|
940
|
-
break;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
return f;
|
|
944
|
-
}, i.prototype.gtn = function(n) {
|
|
945
|
-
return this.cmpn(n) === 1;
|
|
946
|
-
}, i.prototype.gt = function(n) {
|
|
947
|
-
return this.cmp(n) === 1;
|
|
948
|
-
}, i.prototype.gten = function(n) {
|
|
949
|
-
return this.cmpn(n) >= 0;
|
|
950
|
-
}, i.prototype.gte = function(n) {
|
|
951
|
-
return this.cmp(n) >= 0;
|
|
952
|
-
}, i.prototype.ltn = function(n) {
|
|
953
|
-
return this.cmpn(n) === -1;
|
|
954
|
-
}, i.prototype.lt = function(n) {
|
|
955
|
-
return this.cmp(n) === -1;
|
|
956
|
-
}, i.prototype.lten = function(n) {
|
|
957
|
-
return this.cmpn(n) <= 0;
|
|
958
|
-
}, i.prototype.lte = function(n) {
|
|
959
|
-
return this.cmp(n) <= 0;
|
|
960
|
-
}, i.prototype.eqn = function(n) {
|
|
961
|
-
return this.cmpn(n) === 0;
|
|
962
|
-
}, i.prototype.eq = function(n) {
|
|
963
|
-
return this.cmp(n) === 0;
|
|
964
|
-
}, i.red = function(n) {
|
|
965
|
-
return new T(n);
|
|
966
|
-
}, i.prototype.toRed = function(n) {
|
|
967
|
-
return o(!this.red, "Already a number in reduction context"), o(this.negative === 0, "red works only with positives"), n.convertTo(this)._forceRed(n);
|
|
968
|
-
}, i.prototype.fromRed = function() {
|
|
969
|
-
return o(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
|
|
970
|
-
}, i.prototype._forceRed = function(n) {
|
|
971
|
-
return this.red = n, this;
|
|
972
|
-
}, i.prototype.forceRed = function(n) {
|
|
973
|
-
return o(!this.red, "Already a number in reduction context"), this._forceRed(n);
|
|
974
|
-
}, i.prototype.redAdd = function(n) {
|
|
975
|
-
return o(this.red, "redAdd works only with red numbers"), this.red.add(this, n);
|
|
976
|
-
}, i.prototype.redIAdd = function(n) {
|
|
977
|
-
return o(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, n);
|
|
978
|
-
}, i.prototype.redSub = function(n) {
|
|
979
|
-
return o(this.red, "redSub works only with red numbers"), this.red.sub(this, n);
|
|
980
|
-
}, i.prototype.redISub = function(n) {
|
|
981
|
-
return o(this.red, "redISub works only with red numbers"), this.red.isub(this, n);
|
|
982
|
-
}, i.prototype.redShl = function(n) {
|
|
983
|
-
return o(this.red, "redShl works only with red numbers"), this.red.shl(this, n);
|
|
984
|
-
}, i.prototype.redMul = function(n) {
|
|
985
|
-
return o(this.red, "redMul works only with red numbers"), this.red._verify2(this, n), this.red.mul(this, n);
|
|
986
|
-
}, i.prototype.redIMul = function(n) {
|
|
987
|
-
return o(this.red, "redMul works only with red numbers"), this.red._verify2(this, n), this.red.imul(this, n);
|
|
988
|
-
}, i.prototype.redSqr = function() {
|
|
989
|
-
return o(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
|
|
990
|
-
}, i.prototype.redISqr = function() {
|
|
991
|
-
return o(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
|
|
992
|
-
}, i.prototype.redSqrt = function() {
|
|
993
|
-
return o(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
|
|
994
|
-
}, i.prototype.redInvm = function() {
|
|
995
|
-
return o(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
|
|
996
|
-
}, i.prototype.redNeg = function() {
|
|
997
|
-
return o(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
|
|
998
|
-
}, i.prototype.redPow = function(n) {
|
|
999
|
-
return o(this.red && !n.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, n);
|
|
1000
|
-
};
|
|
1001
|
-
var D = {
|
|
1002
|
-
k256: null,
|
|
1003
|
-
p224: null,
|
|
1004
|
-
p192: null,
|
|
1005
|
-
p25519: null
|
|
1006
|
-
};
|
|
1007
|
-
function R(p, n) {
|
|
1008
|
-
this.name = p, this.p = new i(n, 16), this.n = this.p.bitLength(), this.k = new i(1).iushln(this.n).isub(this.p), this.tmp = this._tmp();
|
|
1009
|
-
}
|
|
1010
|
-
R.prototype._tmp = function() {
|
|
1011
|
-
var n = new i(null);
|
|
1012
|
-
return n.words = new Array(Math.ceil(this.n / 13)), n;
|
|
1013
|
-
}, R.prototype.ireduce = function(n) {
|
|
1014
|
-
var f = n, a;
|
|
1015
|
-
do
|
|
1016
|
-
this.split(f, this.tmp), f = this.imulK(f), f = f.iadd(this.tmp), a = f.bitLength();
|
|
1017
|
-
while (a > this.n);
|
|
1018
|
-
var h = a < this.n ? -1 : f.ucmp(this.p);
|
|
1019
|
-
return h === 0 ? (f.words[0] = 0, f.length = 1) : h > 0 ? f.isub(this.p) : f.strip !== void 0 ? f.strip() : f._strip(), f;
|
|
1020
|
-
}, R.prototype.split = function(n, f) {
|
|
1021
|
-
n.iushrn(this.n, 0, f);
|
|
1022
|
-
}, R.prototype.imulK = function(n) {
|
|
1023
|
-
return n.imul(this.k);
|
|
1024
|
-
};
|
|
1025
|
-
function O() {
|
|
1026
|
-
R.call(
|
|
1027
|
-
this,
|
|
1028
|
-
"k256",
|
|
1029
|
-
"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
1032
|
-
c(O, R), O.prototype.split = function(n, f) {
|
|
1033
|
-
for (var a = 4194303, h = Math.min(n.length, 9), l = 0; l < h; l++)
|
|
1034
|
-
f.words[l] = n.words[l];
|
|
1035
|
-
if (f.length = h, n.length <= 9) {
|
|
1036
|
-
n.words[0] = 0, n.length = 1;
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
var m = n.words[9];
|
|
1040
|
-
for (f.words[f.length++] = m & a, l = 10; l < n.length; l++) {
|
|
1041
|
-
var b = n.words[l] | 0;
|
|
1042
|
-
n.words[l - 10] = (b & a) << 4 | m >>> 22, m = b;
|
|
1043
|
-
}
|
|
1044
|
-
m >>>= 22, n.words[l - 10] = m, m === 0 && n.length > 10 ? n.length -= 10 : n.length -= 9;
|
|
1045
|
-
}, O.prototype.imulK = function(n) {
|
|
1046
|
-
n.words[n.length] = 0, n.words[n.length + 1] = 0, n.length += 2;
|
|
1047
|
-
for (var f = 0, a = 0; a < n.length; a++) {
|
|
1048
|
-
var h = n.words[a] | 0;
|
|
1049
|
-
f += h * 977, n.words[a] = f & 67108863, f = h * 64 + (f / 67108864 | 0);
|
|
1050
|
-
}
|
|
1051
|
-
return n.words[n.length - 1] === 0 && (n.length--, n.words[n.length - 1] === 0 && n.length--), n;
|
|
1052
|
-
};
|
|
1053
|
-
function $() {
|
|
1054
|
-
R.call(
|
|
1055
|
-
this,
|
|
1056
|
-
"p224",
|
|
1057
|
-
"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"
|
|
1058
|
-
);
|
|
1059
|
-
}
|
|
1060
|
-
c($, R);
|
|
1061
|
-
function P() {
|
|
1062
|
-
R.call(
|
|
1063
|
-
this,
|
|
1064
|
-
"p192",
|
|
1065
|
-
"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"
|
|
1066
|
-
);
|
|
1067
|
-
}
|
|
1068
|
-
c(P, R);
|
|
1069
|
-
function J() {
|
|
1070
|
-
R.call(
|
|
1071
|
-
this,
|
|
1072
|
-
"25519",
|
|
1073
|
-
"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"
|
|
1074
|
-
);
|
|
1075
|
-
}
|
|
1076
|
-
c(J, R), J.prototype.imulK = function(n) {
|
|
1077
|
-
for (var f = 0, a = 0; a < n.length; a++) {
|
|
1078
|
-
var h = (n.words[a] | 0) * 19 + f, l = h & 67108863;
|
|
1079
|
-
h >>>= 26, n.words[a] = l, f = h;
|
|
1080
|
-
}
|
|
1081
|
-
return f !== 0 && (n.words[n.length++] = f), n;
|
|
1082
|
-
}, i._prime = function(n) {
|
|
1083
|
-
if (D[n]) return D[n];
|
|
1084
|
-
var f;
|
|
1085
|
-
if (n === "k256")
|
|
1086
|
-
f = new O();
|
|
1087
|
-
else if (n === "p224")
|
|
1088
|
-
f = new $();
|
|
1089
|
-
else if (n === "p192")
|
|
1090
|
-
f = new P();
|
|
1091
|
-
else if (n === "p25519")
|
|
1092
|
-
f = new J();
|
|
1093
|
-
else
|
|
1094
|
-
throw new Error("Unknown prime " + n);
|
|
1095
|
-
return D[n] = f, f;
|
|
1096
|
-
};
|
|
1097
|
-
function T(p) {
|
|
1098
|
-
if (typeof p == "string") {
|
|
1099
|
-
var n = i._prime(p);
|
|
1100
|
-
this.m = n.p, this.prime = n;
|
|
1101
|
-
} else
|
|
1102
|
-
o(p.gtn(1), "modulus must be greater than 1"), this.m = p, this.prime = null;
|
|
1103
|
-
}
|
|
1104
|
-
T.prototype._verify1 = function(n) {
|
|
1105
|
-
o(n.negative === 0, "red works only with positives"), o(n.red, "red works only with red numbers");
|
|
1106
|
-
}, T.prototype._verify2 = function(n, f) {
|
|
1107
|
-
o((n.negative | f.negative) === 0, "red works only with positives"), o(
|
|
1108
|
-
n.red && n.red === f.red,
|
|
1109
|
-
"red works only with red numbers"
|
|
1110
|
-
);
|
|
1111
|
-
}, T.prototype.imod = function(n) {
|
|
1112
|
-
return this.prime ? this.prime.ireduce(n)._forceRed(this) : (v(n, n.umod(this.m)._forceRed(this)), n);
|
|
1113
|
-
}, T.prototype.neg = function(n) {
|
|
1114
|
-
return n.isZero() ? n.clone() : this.m.sub(n)._forceRed(this);
|
|
1115
|
-
}, T.prototype.add = function(n, f) {
|
|
1116
|
-
this._verify2(n, f);
|
|
1117
|
-
var a = n.add(f);
|
|
1118
|
-
return a.cmp(this.m) >= 0 && a.isub(this.m), a._forceRed(this);
|
|
1119
|
-
}, T.prototype.iadd = function(n, f) {
|
|
1120
|
-
this._verify2(n, f);
|
|
1121
|
-
var a = n.iadd(f);
|
|
1122
|
-
return a.cmp(this.m) >= 0 && a.isub(this.m), a;
|
|
1123
|
-
}, T.prototype.sub = function(n, f) {
|
|
1124
|
-
this._verify2(n, f);
|
|
1125
|
-
var a = n.sub(f);
|
|
1126
|
-
return a.cmpn(0) < 0 && a.iadd(this.m), a._forceRed(this);
|
|
1127
|
-
}, T.prototype.isub = function(n, f) {
|
|
1128
|
-
this._verify2(n, f);
|
|
1129
|
-
var a = n.isub(f);
|
|
1130
|
-
return a.cmpn(0) < 0 && a.iadd(this.m), a;
|
|
1131
|
-
}, T.prototype.shl = function(n, f) {
|
|
1132
|
-
return this._verify1(n), this.imod(n.ushln(f));
|
|
1133
|
-
}, T.prototype.imul = function(n, f) {
|
|
1134
|
-
return this._verify2(n, f), this.imod(n.imul(f));
|
|
1135
|
-
}, T.prototype.mul = function(n, f) {
|
|
1136
|
-
return this._verify2(n, f), this.imod(n.mul(f));
|
|
1137
|
-
}, T.prototype.isqr = function(n) {
|
|
1138
|
-
return this.imul(n, n.clone());
|
|
1139
|
-
}, T.prototype.sqr = function(n) {
|
|
1140
|
-
return this.mul(n, n);
|
|
1141
|
-
}, T.prototype.sqrt = function(n) {
|
|
1142
|
-
if (n.isZero()) return n.clone();
|
|
1143
|
-
var f = this.m.andln(3);
|
|
1144
|
-
if (o(f % 2 === 1), f === 3) {
|
|
1145
|
-
var a = this.m.add(new i(1)).iushrn(2);
|
|
1146
|
-
return this.pow(n, a);
|
|
1147
|
-
}
|
|
1148
|
-
for (var h = this.m.subn(1), l = 0; !h.isZero() && h.andln(1) === 0; )
|
|
1149
|
-
l++, h.iushrn(1);
|
|
1150
|
-
o(!h.isZero());
|
|
1151
|
-
var m = new i(1).toRed(this), b = m.redNeg(), u = this.m.subn(1).iushrn(1), s = this.m.bitLength();
|
|
1152
|
-
for (s = new i(2 * s * s).toRed(this); this.pow(s, u).cmp(b) !== 0; )
|
|
1153
|
-
s.redIAdd(b);
|
|
1154
|
-
for (var g = this.pow(s, h), B = this.pow(n, h.addn(1).iushrn(1)), I = this.pow(n, h), N = l; I.cmp(m) !== 0; ) {
|
|
1155
|
-
for (var j = I, H = 0; j.cmp(m) !== 0; H++)
|
|
1156
|
-
j = j.redSqr();
|
|
1157
|
-
o(H < N);
|
|
1158
|
-
var z = this.pow(g, new i(1).iushln(N - H - 1));
|
|
1159
|
-
B = B.redMul(z), g = z.redSqr(), I = I.redMul(g), N = H;
|
|
1160
|
-
}
|
|
1161
|
-
return B;
|
|
1162
|
-
}, T.prototype.invm = function(n) {
|
|
1163
|
-
var f = n._invmp(this.m);
|
|
1164
|
-
return f.negative !== 0 ? (f.negative = 0, this.imod(f).redNeg()) : this.imod(f);
|
|
1165
|
-
}, T.prototype.pow = function(n, f) {
|
|
1166
|
-
if (f.isZero()) return new i(1).toRed(this);
|
|
1167
|
-
if (f.cmpn(1) === 0) return n.clone();
|
|
1168
|
-
var a = 4, h = new Array(1 << a);
|
|
1169
|
-
h[0] = new i(1).toRed(this), h[1] = n;
|
|
1170
|
-
for (var l = 2; l < h.length; l++)
|
|
1171
|
-
h[l] = this.mul(h[l - 1], n);
|
|
1172
|
-
var m = h[0], b = 0, u = 0, s = f.bitLength() % 26;
|
|
1173
|
-
for (s === 0 && (s = 26), l = f.length - 1; l >= 0; l--) {
|
|
1174
|
-
for (var g = f.words[l], B = s - 1; B >= 0; B--) {
|
|
1175
|
-
var I = g >> B & 1;
|
|
1176
|
-
if (m !== h[0] && (m = this.sqr(m)), I === 0 && b === 0) {
|
|
1177
|
-
u = 0;
|
|
1178
|
-
continue;
|
|
1179
|
-
}
|
|
1180
|
-
b <<= 1, b |= I, u++, !(u !== a && (l !== 0 || B !== 0)) && (m = this.mul(m, h[b]), u = 0, b = 0);
|
|
1181
|
-
}
|
|
1182
|
-
s = 26;
|
|
1183
|
-
}
|
|
1184
|
-
return m;
|
|
1185
|
-
}, T.prototype.convertTo = function(n) {
|
|
1186
|
-
var f = n.umod(this.m);
|
|
1187
|
-
return f === n ? f.clone() : f;
|
|
1188
|
-
}, T.prototype.convertFrom = function(n) {
|
|
1189
|
-
var f = n.clone();
|
|
1190
|
-
return f.red = null, f;
|
|
1191
|
-
}, i.mont = function(n) {
|
|
1192
|
-
return new Z(n);
|
|
1193
|
-
};
|
|
1194
|
-
function Z(p) {
|
|
1195
|
-
T.call(this, p), this.shift = this.m.bitLength(), this.shift % 26 !== 0 && (this.shift += 26 - this.shift % 26), this.r = new i(1).iushln(this.shift), this.r2 = this.imod(this.r.sqr()), this.rinv = this.r._invmp(this.m), this.minv = this.rinv.mul(this.r).isubn(1).div(this.m), this.minv = this.minv.umod(this.r), this.minv = this.r.sub(this.minv);
|
|
1196
|
-
}
|
|
1197
|
-
c(Z, T), Z.prototype.convertTo = function(n) {
|
|
1198
|
-
return this.imod(n.ushln(this.shift));
|
|
1199
|
-
}, Z.prototype.convertFrom = function(n) {
|
|
1200
|
-
var f = this.imod(n.mul(this.rinv));
|
|
1201
|
-
return f.red = null, f;
|
|
1202
|
-
}, Z.prototype.imul = function(n, f) {
|
|
1203
|
-
if (n.isZero() || f.isZero())
|
|
1204
|
-
return n.words[0] = 0, n.length = 1, n;
|
|
1205
|
-
var a = n.imul(f), h = a.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m), l = a.isub(h).iushrn(this.shift), m = l;
|
|
1206
|
-
return l.cmp(this.m) >= 0 ? m = l.isub(this.m) : l.cmpn(0) < 0 && (m = l.iadd(this.m)), m._forceRed(this);
|
|
1207
|
-
}, Z.prototype.mul = function(n, f) {
|
|
1208
|
-
if (n.isZero() || f.isZero()) return new i(0)._forceRed(this);
|
|
1209
|
-
var a = n.mul(f), h = a.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m), l = a.isub(h).iushrn(this.shift), m = l;
|
|
1210
|
-
return l.cmp(this.m) >= 0 ? m = l.isub(this.m) : l.cmpn(0) < 0 && (m = l.iadd(this.m)), m._forceRed(this);
|
|
1211
|
-
}, Z.prototype.invm = function(n) {
|
|
1212
|
-
var f = this.imod(n._invmp(this.m).mul(this.r2));
|
|
1213
|
-
return f._forceRed(this);
|
|
1214
|
-
};
|
|
1215
|
-
})(t, is);
|
|
1216
|
-
})(gi);
|
|
1217
|
-
var gs = gi.exports;
|
|
1218
|
-
const K = /* @__PURE__ */ ns(gs);
|
|
1219
|
-
function mi(t) {
|
|
1220
|
-
return K.isBN(t);
|
|
1221
|
-
}
|
|
1222
|
-
function ms(t) {
|
|
1223
|
-
return !!t && typeof t == "object";
|
|
1224
|
-
}
|
|
1225
|
-
function pi(...t) {
|
|
1226
|
-
return (e) => (ms(e) || Yr(e)) && t.every((r) => Yr(e[r]));
|
|
1227
|
-
}
|
|
1228
|
-
const yi = /* @__PURE__ */ pi("toBigInt"), vi = /* @__PURE__ */ pi("toBn");
|
|
1229
|
-
function ps(t) {
|
|
1230
|
-
return typeof t == "bigint" ? t : t ? te(t) ? ws(t.toString()) : mi(t) ? W(t.toString()) : yi(t) ? t.toBigInt() : vi(t) ? W(t.toBn().toString()) : W(t) : W(0);
|
|
1231
|
-
}
|
|
1232
|
-
function Ct(...t) {
|
|
1233
|
-
const e = t.length, r = new Array(e);
|
|
1234
|
-
let o = 0;
|
|
1235
|
-
for (let c = 0; c < e; c++)
|
|
1236
|
-
r[c] = V(t[c]), o += r[c].length;
|
|
1237
|
-
return Re(r, o);
|
|
1238
|
-
}
|
|
1239
|
-
function Re(t, e = 0) {
|
|
1240
|
-
const r = t.length;
|
|
1241
|
-
let o = 0;
|
|
1242
|
-
if (!e)
|
|
1243
|
-
for (let i = 0; i < r; i++)
|
|
1244
|
-
e += t[i].length;
|
|
1245
|
-
const c = new Uint8Array(e);
|
|
1246
|
-
for (let i = 0; i < r; i++)
|
|
1247
|
-
c.set(t[i], o), o += t[i].length;
|
|
1248
|
-
return c;
|
|
1249
|
-
}
|
|
1250
|
-
function bi(t) {
|
|
1251
|
-
const e = t.length | 0;
|
|
1252
|
-
for (let r = 0; r < e; r++)
|
|
1253
|
-
if (t[r] | 0)
|
|
1254
|
-
return !1;
|
|
1255
|
-
return !0;
|
|
1256
|
-
}
|
|
1257
|
-
function jt(t, e) {
|
|
1258
|
-
const r = V(t), o = V(e);
|
|
1259
|
-
if (r.length === o.length) {
|
|
1260
|
-
const c = new DataView(r.buffer, r.byteOffset), i = new DataView(o.buffer, o.byteOffset), w = r.length % 4 | 0, d = r.length - w | 0;
|
|
1261
|
-
for (let y = 0; y < d; y += 4)
|
|
1262
|
-
if (c.getUint32(y) !== i.getUint32(y))
|
|
1263
|
-
return !1;
|
|
1264
|
-
for (let y = d, x = r.length; y < x; y++)
|
|
1265
|
-
if (r[y] !== o[y])
|
|
1266
|
-
return !1;
|
|
1267
|
-
return !0;
|
|
1268
|
-
}
|
|
1269
|
-
return !1;
|
|
1270
|
-
}
|
|
1271
|
-
function ys(t, e = -1, r = !1) {
|
|
1272
|
-
const o = Math.ceil(e / 8);
|
|
1273
|
-
if (e === -1 || t.length === o)
|
|
1274
|
-
return t;
|
|
1275
|
-
if (t.length > o)
|
|
1276
|
-
return t.subarray(0, o);
|
|
1277
|
-
const c = new Uint8Array(o);
|
|
1278
|
-
return c.set(t, r ? 0 : o - t.length), c;
|
|
1279
|
-
}
|
|
1280
|
-
function kr(t, { isLe: e = !0, isNegative: r = !1 } = {}) {
|
|
1281
|
-
e || (t = t.slice().reverse());
|
|
1282
|
-
const o = t.length;
|
|
1283
|
-
if (r && o && t[o - 1] & 128)
|
|
1284
|
-
switch (o) {
|
|
1285
|
-
case 0:
|
|
1286
|
-
return new K(0);
|
|
1287
|
-
case 1:
|
|
1288
|
-
return new K((t[0] ^ 255) * -1 - 1);
|
|
1289
|
-
case 2:
|
|
1290
|
-
return new K((t[0] + (t[1] << 8) ^ 65535) * -1 - 1);
|
|
1291
|
-
case 3:
|
|
1292
|
-
return new K((t[0] + (t[1] << 8) + (t[2] << 16) ^ 16777215) * -1 - 1);
|
|
1293
|
-
case 4:
|
|
1294
|
-
return new K((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) * -1 - 1);
|
|
1295
|
-
case 5:
|
|
1296
|
-
return new K(((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) + (t[4] ^ 255) * 4294967296) * -1 - 1);
|
|
1297
|
-
case 6:
|
|
1298
|
-
return new K(((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) + (t[4] + (t[5] << 8) ^ 65535) * 4294967296) * -1 - 1);
|
|
1299
|
-
default:
|
|
1300
|
-
return new K(t, "le").fromTwos(o * 8);
|
|
1301
|
-
}
|
|
1302
|
-
switch (o) {
|
|
1303
|
-
case 0:
|
|
1304
|
-
return new K(0);
|
|
1305
|
-
case 1:
|
|
1306
|
-
return new K(t[0]);
|
|
1307
|
-
case 2:
|
|
1308
|
-
return new K(t[0] + (t[1] << 8));
|
|
1309
|
-
case 3:
|
|
1310
|
-
return new K(t[0] + (t[1] << 8) + (t[2] << 16));
|
|
1311
|
-
case 4:
|
|
1312
|
-
return new K(t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216);
|
|
1313
|
-
case 5:
|
|
1314
|
-
return new K(t[0] + (t[1] << 8) + (t[2] << 16) + (t[3] + (t[4] << 8)) * 16777216);
|
|
1315
|
-
case 6:
|
|
1316
|
-
return new K(t[0] + (t[1] << 8) + (t[2] << 16) + (t[3] + (t[4] << 8) + (t[5] << 16)) * 16777216);
|
|
1317
|
-
default:
|
|
1318
|
-
return new K(t, "le");
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
const Ur = /* @__PURE__ */ V(`Ethereum Signed Message:
|
|
1322
|
-
`), Ie = /* @__PURE__ */ V("<Bytes>"), ke = /* @__PURE__ */ V("</Bytes>"), vs = Ie.length + ke.length;
|
|
1323
|
-
function We(t, e) {
|
|
1324
|
-
return t.length >= vs && jt(t.subarray(0, Ie.length), Ie) && jt(t.slice(-ke.length), ke) || e && t.length >= Ur.length && jt(t.subarray(0, Ur.length), Ur);
|
|
1325
|
-
}
|
|
1326
|
-
function bs(t) {
|
|
1327
|
-
const e = V(t);
|
|
1328
|
-
return We(e, !1) ? e.subarray(Ie.length, e.length - ke.length) : e;
|
|
1329
|
-
}
|
|
1330
|
-
function xs(t) {
|
|
1331
|
-
const e = V(t);
|
|
1332
|
-
return We(e, !0) ? e : Re([Ie, e, ke]);
|
|
1333
|
-
}
|
|
1334
|
-
const On = W(256), Es = W(255);
|
|
1335
|
-
function Ms(t, e, r) {
|
|
1336
|
-
const o = [], c = r && t < Ke;
|
|
1337
|
-
for (c && (t = (t + Ge) * -Ge); t !== Ke; ) {
|
|
1338
|
-
const i = t % On, w = Number(c ? i ^ Es : i);
|
|
1339
|
-
e ? o.push(w) : o.unshift(w), t = (t - i) / On;
|
|
1340
|
-
}
|
|
1341
|
-
return Uint8Array.from(o);
|
|
1342
|
-
}
|
|
1343
|
-
function _s(t, { bitLength: e = -1, isLe: r = !0, isNegative: o = !1 } = {}) {
|
|
1344
|
-
const c = ps(t);
|
|
1345
|
-
if (c === Ke)
|
|
1346
|
-
return e === -1 ? new Uint8Array(1) : new Uint8Array(Math.ceil((e || 0) / 8));
|
|
1347
|
-
const i = Ms(c, r, o);
|
|
1348
|
-
if (e === -1)
|
|
1349
|
-
return i;
|
|
1350
|
-
const w = Math.ceil((e || 0) / 8), d = new Uint8Array(w);
|
|
1351
|
-
return o && d.fill(255), d.set(i, r ? 0 : w - i.length), d;
|
|
1352
|
-
}
|
|
1353
|
-
function Bs(t) {
|
|
1354
|
-
if (!t || t === "0x")
|
|
1355
|
-
return "";
|
|
1356
|
-
if (Bo.test(t))
|
|
1357
|
-
return t.substring(2);
|
|
1358
|
-
if (So.test(t))
|
|
1359
|
-
return t;
|
|
1360
|
-
throw new Error(`Expected hex value to convert, found '${t}'`);
|
|
1361
|
-
}
|
|
1362
|
-
function Ss(t, { isLe: e = !1, isNegative: r = !1 } = {}) {
|
|
1363
|
-
if (!t || t === "0x")
|
|
1364
|
-
return new K(0);
|
|
1365
|
-
const o = Bs(t), c = new K(o, 16, e ? "le" : "be");
|
|
1366
|
-
return r ? c.fromTwos(o.length * 4) : c;
|
|
1367
|
-
}
|
|
1368
|
-
const nr = /* @__PURE__ */ new K(1), ir = /* @__PURE__ */ new K(2), Ln = /* @__PURE__ */ new K(1e9);
|
|
1369
|
-
Ln.mul(Ln);
|
|
1370
|
-
Number.MAX_SAFE_INTEGER;
|
|
1371
|
-
function xi(t) {
|
|
1372
|
-
return typeof t == "bigint";
|
|
1373
|
-
}
|
|
1374
|
-
function Ei(t) {
|
|
1375
|
-
return t ? K.isBN(t) ? t : te(t) ? Ss(t.toString()) : xi(t) ? new K(t.toString()) : vi(t) ? t.toBn() : yi(t) ? new K(t.toBigInt().toString()) : new K(t) : new K(0);
|
|
1376
|
-
}
|
|
1377
|
-
const As = { bitLength: -1, isLe: !0, isNegative: !1 };
|
|
1378
|
-
function zt(t, { bitLength: e = -1, isLe: r = !0, isNegative: o = !1 } = As) {
|
|
1379
|
-
const c = Ei(t), i = Math.ceil(e === -1 ? c.bitLength() / 8 : (e || 0) / 8);
|
|
1380
|
-
if (!t)
|
|
1381
|
-
return e === -1 ? new Uint8Array(1) : new Uint8Array(i);
|
|
1382
|
-
const w = new Uint8Array(i), d = o ? c.toTwos(i * 8) : c;
|
|
1383
|
-
return w.set(d.toArray(r ? "le" : "be", i), 0), w;
|
|
1384
|
-
}
|
|
1385
|
-
const Is = ir.pow(new K(6)).isub(nr), ks = ir.pow(new K(14)).isub(nr), Us = ir.pow(new K(30)).isub(nr), Ns = { bitLength: 16 }, Rs = { bitLength: 32 };
|
|
1386
|
-
function Os(t) {
|
|
1387
|
-
const e = Ei(t);
|
|
1388
|
-
if (e.lte(Is))
|
|
1389
|
-
return new Uint8Array([e.toNumber() << 2]);
|
|
1390
|
-
if (e.lte(ks))
|
|
1391
|
-
return zt(e.shln(2).iadd(nr), Ns);
|
|
1392
|
-
if (e.lte(Us))
|
|
1393
|
-
return zt(e.shln(2).iadd(ir), Rs);
|
|
1394
|
-
const r = zt(e);
|
|
1395
|
-
let o = r.length;
|
|
1396
|
-
for (; r[o - 1] === 0; )
|
|
1397
|
-
o--;
|
|
1398
|
-
if (o < 4)
|
|
1399
|
-
throw new Error("Invalid length, previous checks match anything less than 2^30");
|
|
1400
|
-
return Re([
|
|
1401
|
-
// subtract 4 as minimum (also catered for in decoding)
|
|
1402
|
-
new Uint8Array([(o - 4 << 2) + 3]),
|
|
1403
|
-
r.subarray(0, o)
|
|
1404
|
-
]);
|
|
1405
|
-
}
|
|
1406
|
-
function sn(t) {
|
|
1407
|
-
return Re([
|
|
1408
|
-
Os(t.length),
|
|
1409
|
-
t
|
|
1410
|
-
]);
|
|
1411
|
-
}
|
|
1412
|
-
function Ls(t) {
|
|
1413
|
-
return typeof t == "string" || t instanceof String;
|
|
1414
|
-
}
|
|
1415
|
-
function Ts(t) {
|
|
1416
|
-
return typeof t == "number";
|
|
1417
|
-
}
|
|
1418
|
-
const $s = { name: "@polkadot/util-crypto", path: import.meta && import.meta.url ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf("/") + 1) : "auto", type: "esm", version: "12.6.2" };
|
|
1419
|
-
function Mi(t) {
|
|
1420
|
-
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
1421
|
-
}
|
|
1422
|
-
function _i(t, e) {
|
|
1423
|
-
return Array.isArray(e) ? e.length === 0 ? !0 : t ? e.every((r) => typeof r == "string") : e.every((r) => Number.isSafeInteger(r)) : !1;
|
|
1424
|
-
}
|
|
1425
|
-
function Je(t, e) {
|
|
1426
|
-
if (typeof e != "string")
|
|
1427
|
-
throw new Error(`${t}: string expected`);
|
|
1428
|
-
return !0;
|
|
1429
|
-
}
|
|
1430
|
-
function Oe(t) {
|
|
1431
|
-
if (!Number.isSafeInteger(t))
|
|
1432
|
-
throw new Error(`invalid integer: ${t}`);
|
|
1433
|
-
}
|
|
1434
|
-
function Qe(t) {
|
|
1435
|
-
if (!Array.isArray(t))
|
|
1436
|
-
throw new Error("array expected");
|
|
1437
|
-
}
|
|
1438
|
-
function Fe(t, e) {
|
|
1439
|
-
if (!_i(!0, e))
|
|
1440
|
-
throw new Error(`${t}: array of strings expected`);
|
|
1441
|
-
}
|
|
1442
|
-
function Bi(t, e) {
|
|
1443
|
-
if (!_i(!1, e))
|
|
1444
|
-
throw new Error(`${t}: array of numbers expected`);
|
|
1445
|
-
}
|
|
1446
|
-
// @__NO_SIDE_EFFECTS__
|
|
1447
|
-
function Si(...t) {
|
|
1448
|
-
const e = (i) => i, r = (i, w) => (d) => i(w(d)), o = t.map((i) => i.encode).reduceRight(r, e), c = t.map((i) => i.decode).reduce(r, e);
|
|
1449
|
-
return { encode: o, decode: c };
|
|
1450
|
-
}
|
|
1451
|
-
// @__NO_SIDE_EFFECTS__
|
|
1452
|
-
function Ai(t) {
|
|
1453
|
-
const e = typeof t == "string" ? t.split("") : t, r = e.length;
|
|
1454
|
-
Fe("alphabet", e);
|
|
1455
|
-
const o = new Map(e.map((c, i) => [c, i]));
|
|
1456
|
-
return {
|
|
1457
|
-
encode: (c) => (Qe(c), c.map((i) => {
|
|
1458
|
-
if (!Number.isSafeInteger(i) || i < 0 || i >= r)
|
|
1459
|
-
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${t}`);
|
|
1460
|
-
return e[i];
|
|
1461
|
-
})),
|
|
1462
|
-
decode: (c) => (Qe(c), c.map((i) => {
|
|
1463
|
-
Je("alphabet.decode", i);
|
|
1464
|
-
const w = o.get(i);
|
|
1465
|
-
if (w === void 0)
|
|
1466
|
-
throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);
|
|
1467
|
-
return w;
|
|
1468
|
-
}))
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
// @__NO_SIDE_EFFECTS__
|
|
1472
|
-
function Ii(t = "") {
|
|
1473
|
-
return Je("join", t), {
|
|
1474
|
-
encode: (e) => (Fe("join.decode", e), e.join(t)),
|
|
1475
|
-
decode: (e) => (Je("join.decode", e), e.split(t))
|
|
1476
|
-
};
|
|
1477
|
-
}
|
|
1478
|
-
// @__NO_SIDE_EFFECTS__
|
|
1479
|
-
function qs(t, e = "=") {
|
|
1480
|
-
return Oe(t), Je("padding", e), {
|
|
1481
|
-
encode(r) {
|
|
1482
|
-
for (Fe("padding.encode", r); r.length * t % 8; )
|
|
1483
|
-
r.push(e);
|
|
1484
|
-
return r;
|
|
1485
|
-
},
|
|
1486
|
-
decode(r) {
|
|
1487
|
-
Fe("padding.decode", r);
|
|
1488
|
-
let o = r.length;
|
|
1489
|
-
if (o * t % 8)
|
|
1490
|
-
throw new Error("padding: invalid, string should have whole number of bytes");
|
|
1491
|
-
for (; o > 0 && r[o - 1] === e; o--)
|
|
1492
|
-
if ((o - 1) * t % 8 === 0)
|
|
1493
|
-
throw new Error("padding: invalid, string has too much padding");
|
|
1494
|
-
return r.slice(0, o);
|
|
1495
|
-
}
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
function Tn(t, e, r) {
|
|
1499
|
-
if (e < 2)
|
|
1500
|
-
throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);
|
|
1501
|
-
if (r < 2)
|
|
1502
|
-
throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);
|
|
1503
|
-
if (Qe(t), !t.length)
|
|
1504
|
-
return [];
|
|
1505
|
-
let o = 0;
|
|
1506
|
-
const c = [], i = Array.from(t, (d) => {
|
|
1507
|
-
if (Oe(d), d < 0 || d >= e)
|
|
1508
|
-
throw new Error(`invalid integer: ${d}`);
|
|
1509
|
-
return d;
|
|
1510
|
-
}), w = i.length;
|
|
1511
|
-
for (; ; ) {
|
|
1512
|
-
let d = 0, y = !0;
|
|
1513
|
-
for (let x = o; x < w; x++) {
|
|
1514
|
-
const v = i[x], E = e * d, M = E + v;
|
|
1515
|
-
if (!Number.isSafeInteger(M) || E / e !== d || M - v !== E)
|
|
1516
|
-
throw new Error("convertRadix: carry overflow");
|
|
1517
|
-
const U = M / r;
|
|
1518
|
-
d = M % r;
|
|
1519
|
-
const C = Math.floor(U);
|
|
1520
|
-
if (i[x] = C, !Number.isSafeInteger(C) || C * r + d !== M)
|
|
1521
|
-
throw new Error("convertRadix: carry overflow");
|
|
1522
|
-
if (y)
|
|
1523
|
-
C ? y = !1 : o = x;
|
|
1524
|
-
else continue;
|
|
1525
|
-
}
|
|
1526
|
-
if (c.push(d), y)
|
|
1527
|
-
break;
|
|
1528
|
-
}
|
|
1529
|
-
for (let d = 0; d < t.length - 1 && t[d] === 0; d++)
|
|
1530
|
-
c.push(0);
|
|
1531
|
-
return c.reverse();
|
|
1532
|
-
}
|
|
1533
|
-
const ki = (t, e) => e === 0 ? t : ki(e, t % e), tr = /* @__NO_SIDE_EFFECTS__ */ (t, e) => t + (e - ki(t, e)), Nr = /* @__PURE__ */ (() => {
|
|
1534
|
-
let t = [];
|
|
1535
|
-
for (let e = 0; e < 40; e++)
|
|
1536
|
-
t.push(2 ** e);
|
|
1537
|
-
return t;
|
|
1538
|
-
})();
|
|
1539
|
-
function $n(t, e, r, o) {
|
|
1540
|
-
if (Qe(t), e <= 0 || e > 32)
|
|
1541
|
-
throw new Error(`convertRadix2: wrong from=${e}`);
|
|
1542
|
-
if (r <= 0 || r > 32)
|
|
1543
|
-
throw new Error(`convertRadix2: wrong to=${r}`);
|
|
1544
|
-
if (/* @__PURE__ */ tr(e, r) > 32)
|
|
1545
|
-
throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${/* @__PURE__ */ tr(e, r)}`);
|
|
1546
|
-
let c = 0, i = 0;
|
|
1547
|
-
const w = Nr[e], d = Nr[r] - 1, y = [];
|
|
1548
|
-
for (const x of t) {
|
|
1549
|
-
if (Oe(x), x >= w)
|
|
1550
|
-
throw new Error(`convertRadix2: invalid data word=${x} from=${e}`);
|
|
1551
|
-
if (c = c << e | x, i + e > 32)
|
|
1552
|
-
throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);
|
|
1553
|
-
for (i += e; i >= r; i -= r)
|
|
1554
|
-
y.push((c >> i - r & d) >>> 0);
|
|
1555
|
-
const v = Nr[i];
|
|
1556
|
-
if (v === void 0)
|
|
1557
|
-
throw new Error("invalid carry");
|
|
1558
|
-
c &= v - 1;
|
|
1559
|
-
}
|
|
1560
|
-
if (c = c << r - i & d, !o && i >= e)
|
|
1561
|
-
throw new Error("Excess padding");
|
|
1562
|
-
if (!o && c > 0)
|
|
1563
|
-
throw new Error(`Non-zero padding: ${c}`);
|
|
1564
|
-
return o && i > 0 && y.push(c >>> 0), y;
|
|
1565
|
-
}
|
|
1566
|
-
// @__NO_SIDE_EFFECTS__
|
|
1567
|
-
function Ps(t) {
|
|
1568
|
-
Oe(t);
|
|
1569
|
-
const e = 2 ** 8;
|
|
1570
|
-
return {
|
|
1571
|
-
encode: (r) => {
|
|
1572
|
-
if (!Mi(r))
|
|
1573
|
-
throw new Error("radix.encode input should be Uint8Array");
|
|
1574
|
-
return Tn(Array.from(r), e, t);
|
|
1575
|
-
},
|
|
1576
|
-
decode: (r) => (Bi("radix.decode", r), Uint8Array.from(Tn(r, t, e)))
|
|
1577
|
-
};
|
|
1578
|
-
}
|
|
1579
|
-
// @__NO_SIDE_EFFECTS__
|
|
1580
|
-
function Cs(t, e = !1) {
|
|
1581
|
-
if (Oe(t), t <= 0 || t > 32)
|
|
1582
|
-
throw new Error("radix2: bits should be in (0..32]");
|
|
1583
|
-
if (/* @__PURE__ */ tr(8, t) > 32 || /* @__PURE__ */ tr(t, 8) > 32)
|
|
1584
|
-
throw new Error("radix2: carry overflow");
|
|
1585
|
-
return {
|
|
1586
|
-
encode: (r) => {
|
|
1587
|
-
if (!Mi(r))
|
|
1588
|
-
throw new Error("radix2.encode input should be Uint8Array");
|
|
1589
|
-
return $n(Array.from(r), 8, t, !e);
|
|
1590
|
-
},
|
|
1591
|
-
decode: (r) => (Bi("radix2.decode", r), Uint8Array.from($n(r, t, 8, e)))
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
const Zs = /* @__PURE__ */ Si(/* @__PURE__ */ Cs(6), /* @__PURE__ */ Ai("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ qs(6), /* @__PURE__ */ Ii("")), Ds = /* @__NO_SIDE_EFFECTS__ */ (t) => /* @__PURE__ */ Si(/* @__PURE__ */ Ps(58), /* @__PURE__ */ Ai(t), /* @__PURE__ */ Ii("")), Hs = /* @__PURE__ */ Ds("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1595
|
-
function Ui({ coder: t, ipfs: e }, r) {
|
|
1596
|
-
return (o, c) => (r(o, c), t.decode(e && c ? o.substring(1) : o));
|
|
1597
|
-
}
|
|
1598
|
-
function Ni({ coder: t, ipfs: e }) {
|
|
1599
|
-
return (r, o) => {
|
|
1600
|
-
const c = t.encode(V(r));
|
|
1601
|
-
return e && o ? `${e}${c}` : c;
|
|
1602
|
-
};
|
|
1603
|
-
}
|
|
1604
|
-
function Ri({ chars: t, ipfs: e, type: r, withPadding: o }) {
|
|
1605
|
-
return (c, i) => {
|
|
1606
|
-
if (typeof c != "string")
|
|
1607
|
-
throw new Error(`Expected ${r} string input`);
|
|
1608
|
-
if (e && i && !c.startsWith(e))
|
|
1609
|
-
throw new Error(`Expected ipfs-compatible ${r} to start with '${e}'`);
|
|
1610
|
-
for (let w = i ? 1 : 0, d = c.length; w < d; w++)
|
|
1611
|
-
if (!t.includes(c[w])) if (o && c[w] === "=") {
|
|
1612
|
-
if (w !== d - 1) {
|
|
1613
|
-
if (c[w + 1] !== "=") throw new Error(`Invalid ${r} padding sequence "${c[w]}${c[w + 1]}" at index ${w}`);
|
|
1614
|
-
}
|
|
1615
|
-
} else
|
|
1616
|
-
throw new Error(`Invalid ${r} character "${c[w]}" (0x${c.charCodeAt(w).toString(16)}) at index ${w}`);
|
|
1617
|
-
return !0;
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
const fn = {
|
|
1621
|
-
chars: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
|
|
1622
|
-
coder: Hs,
|
|
1623
|
-
ipfs: "z",
|
|
1624
|
-
type: "base58"
|
|
1625
|
-
}, Vs = /* @__PURE__ */ Ri(fn), zs = /* @__PURE__ */ Ui(fn, Vs), Ys = /* @__PURE__ */ Ni(fn), Xs = ee("SS58PRE");
|
|
1626
|
-
function Oi(t) {
|
|
1627
|
-
return he(Ct(Xs, t), 512);
|
|
1628
|
-
}
|
|
1629
|
-
function js(t) {
|
|
1630
|
-
const e = t[0] & 64 ? 2 : 1, r = e === 1 ? t[0] : (t[0] & 63) << 2 | t[1] >> 6 | (t[1] & 63) << 8, o = [34 + e, 35 + e].includes(t.length), c = t.length - (o ? 2 : 1), i = Oi(t.subarray(0, c));
|
|
1631
|
-
return [(t[0] & 128) === 0 && ![46, 47].includes(t[0]) && (o ? t[t.length - 2] === i[0] && t[t.length - 1] === i[1] : t[t.length - 1] === i[0]), c, e, r];
|
|
1632
|
-
}
|
|
1633
|
-
const ze = {
|
|
1634
|
-
allowedDecodedLengths: [1, 2, 4, 8, 32, 33],
|
|
1635
|
-
// publicKey has prefix + 2 checksum bytes, short only prefix + 1 checksum byte
|
|
1636
|
-
allowedEncodedLengths: [3, 4, 6, 10, 35, 36, 37, 38],
|
|
1637
|
-
prefix: 42
|
|
1638
|
-
};
|
|
1639
|
-
function ge(t, e, r = -1) {
|
|
1640
|
-
if (!t)
|
|
1641
|
-
throw new Error("Invalid empty address passed");
|
|
1642
|
-
if (oe(t) || te(t))
|
|
1643
|
-
return V(t);
|
|
1644
|
-
try {
|
|
1645
|
-
const o = zs(t);
|
|
1646
|
-
if (!ze.allowedEncodedLengths.includes(o.length))
|
|
1647
|
-
throw new Error("Invalid decoded address length");
|
|
1648
|
-
const [c, i, w, d] = js(o);
|
|
1649
|
-
if (!c && !e)
|
|
1650
|
-
throw new Error("Invalid decoded address checksum");
|
|
1651
|
-
if (r !== -1 && r !== d)
|
|
1652
|
-
throw new Error(`Expected ss58Format ${r}, received ${d}`);
|
|
1653
|
-
return o.slice(w, i);
|
|
1654
|
-
} catch (o) {
|
|
1655
|
-
throw new Error(`Decoding ${t}: ${o.message}`);
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
const qn = { isLe: !1 }, Rr = { isLe: !0 }, Ks = { bitLength: 32, isLe: !1 }, Or = { bitLength: 32, isLe: !0 }, pe = { bitLength: 256, isLe: !1 }, Gs = { bitLength: 256, isLe: !0 }, Ws = /^\d+$/, Js = 32;
|
|
1659
|
-
class an {
|
|
1660
|
-
constructor() {
|
|
1661
|
-
Kt(this, "__internal__chainCode", new Uint8Array(32));
|
|
1662
|
-
Kt(this, "__internal__isHard", !1);
|
|
1663
|
-
}
|
|
1664
|
-
static from(e) {
|
|
1665
|
-
const r = new an(), [o, c] = e.startsWith("/") ? [e.substring(1), !0] : [e, !1];
|
|
1666
|
-
return r.soft(Ws.test(o) ? new K(o, 10) : o), c ? r.harden() : r;
|
|
1667
|
-
}
|
|
1668
|
-
get chainCode() {
|
|
1669
|
-
return this.__internal__chainCode;
|
|
1670
|
-
}
|
|
1671
|
-
get isHard() {
|
|
1672
|
-
return this.__internal__isHard;
|
|
1673
|
-
}
|
|
1674
|
-
get isSoft() {
|
|
1675
|
-
return !this.__internal__isHard;
|
|
1676
|
-
}
|
|
1677
|
-
hard(e) {
|
|
1678
|
-
return this.soft(e).harden();
|
|
1679
|
-
}
|
|
1680
|
-
harden() {
|
|
1681
|
-
return this.__internal__isHard = !0, this;
|
|
1682
|
-
}
|
|
1683
|
-
soft(e) {
|
|
1684
|
-
return Ts(e) || mi(e) || xi(e) ? this.soft(zt(e, Gs)) : te(e) ? this.soft(Se(e)) : Ls(e) ? this.soft(sn(ee(e))) : e.length > Js ? this.soft(he(e)) : (this.__internal__chainCode.fill(0), this.__internal__chainCode.set(e, 0), this);
|
|
1685
|
-
}
|
|
1686
|
-
soften() {
|
|
1687
|
-
return this.__internal__isHard = !1, this;
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
const Qs = /\/(\/?)([^/]+)/g;
|
|
1691
|
-
function Li(t) {
|
|
1692
|
-
const e = t.match(Qs), r = [];
|
|
1693
|
-
let o = "";
|
|
1694
|
-
if (e) {
|
|
1695
|
-
o = e.join("");
|
|
1696
|
-
for (const c of e)
|
|
1697
|
-
r.push(an.from(c.substring(1)));
|
|
1698
|
-
}
|
|
1699
|
-
if (o !== t)
|
|
1700
|
-
throw new Error(`Re-constructed path "${o}" does not match input`);
|
|
1701
|
-
return {
|
|
1702
|
-
parts: e,
|
|
1703
|
-
path: r
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
const Fs = /^(\w+( \w+)*)((\/\/?[^/]+)*)(\/\/\/(.*))?$/;
|
|
1707
|
-
function tf(t) {
|
|
1708
|
-
const e = t.match(Fs);
|
|
1709
|
-
if (e === null)
|
|
1710
|
-
throw new Error("Unable to match provided value to a secret URI");
|
|
1711
|
-
const [, r, , o, , , c] = e, { path: i } = Li(o);
|
|
1712
|
-
return {
|
|
1713
|
-
derivePath: o,
|
|
1714
|
-
password: c,
|
|
1715
|
-
path: i,
|
|
1716
|
-
phrase: r
|
|
1717
|
-
};
|
|
1718
|
-
}
|
|
1719
|
-
const ef = sn(ee("Secp256k1HDKD"));
|
|
1720
|
-
function rf(t, e) {
|
|
1721
|
-
if (!oe(e) || e.length !== 32)
|
|
1722
|
-
throw new Error("Invalid chainCode passed to derive");
|
|
1723
|
-
return he(Ct(ef, t, e), 256);
|
|
1724
|
-
}
|
|
1725
|
-
const hn = /* @__PURE__ */ BigInt(0), or = /* @__PURE__ */ BigInt(1), nf = /* @__PURE__ */ BigInt(2);
|
|
1726
|
-
function se(t) {
|
|
1727
|
-
return t instanceof Uint8Array || t != null && typeof t == "object" && t.constructor.name === "Uint8Array";
|
|
1728
|
-
}
|
|
1729
|
-
function Le(t) {
|
|
1730
|
-
if (!se(t))
|
|
1731
|
-
throw new Error("Uint8Array expected");
|
|
1732
|
-
}
|
|
1733
|
-
function Qt(t, e) {
|
|
1734
|
-
if (typeof e != "boolean")
|
|
1735
|
-
throw new Error(`${t} must be valid boolean, got "${e}".`);
|
|
1736
|
-
}
|
|
1737
|
-
const of = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
|
|
1738
|
-
function fe(t) {
|
|
1739
|
-
Le(t);
|
|
1740
|
-
let e = "";
|
|
1741
|
-
for (let r = 0; r < t.length; r++)
|
|
1742
|
-
e += of[t[r]];
|
|
1743
|
-
return e;
|
|
1744
|
-
}
|
|
1745
|
-
function we(t) {
|
|
1746
|
-
const e = t.toString(16);
|
|
1747
|
-
return e.length & 1 ? `0${e}` : e;
|
|
1748
|
-
}
|
|
1749
|
-
function cn(t) {
|
|
1750
|
-
if (typeof t != "string")
|
|
1751
|
-
throw new Error("hex string expected, got " + typeof t);
|
|
1752
|
-
return BigInt(t === "" ? "0" : `0x${t}`);
|
|
1753
|
-
}
|
|
1754
|
-
const Gt = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
|
|
1755
|
-
function Pn(t) {
|
|
1756
|
-
if (t >= Gt._0 && t <= Gt._9)
|
|
1757
|
-
return t - Gt._0;
|
|
1758
|
-
if (t >= Gt._A && t <= Gt._F)
|
|
1759
|
-
return t - (Gt._A - 10);
|
|
1760
|
-
if (t >= Gt._a && t <= Gt._f)
|
|
1761
|
-
return t - (Gt._a - 10);
|
|
1762
|
-
}
|
|
1763
|
-
function ye(t) {
|
|
1764
|
-
if (typeof t != "string")
|
|
1765
|
-
throw new Error("hex string expected, got " + typeof t);
|
|
1766
|
-
const e = t.length, r = e / 2;
|
|
1767
|
-
if (e % 2)
|
|
1768
|
-
throw new Error("padded hex string expected, got unpadded hex of length " + e);
|
|
1769
|
-
const o = new Uint8Array(r);
|
|
1770
|
-
for (let c = 0, i = 0; c < r; c++, i += 2) {
|
|
1771
|
-
const w = Pn(t.charCodeAt(i)), d = Pn(t.charCodeAt(i + 1));
|
|
1772
|
-
if (w === void 0 || d === void 0) {
|
|
1773
|
-
const y = t[i] + t[i + 1];
|
|
1774
|
-
throw new Error('hex string expected, got non-hex character "' + y + '" at index ' + i);
|
|
1775
|
-
}
|
|
1776
|
-
o[c] = w * 16 + d;
|
|
1777
|
-
}
|
|
1778
|
-
return o;
|
|
1779
|
-
}
|
|
1780
|
-
function ie(t) {
|
|
1781
|
-
return cn(fe(t));
|
|
1782
|
-
}
|
|
1783
|
-
function me(t) {
|
|
1784
|
-
return Le(t), cn(fe(Uint8Array.from(t).reverse()));
|
|
1785
|
-
}
|
|
1786
|
-
function ve(t, e) {
|
|
1787
|
-
return ye(t.toString(16).padStart(e * 2, "0"));
|
|
1788
|
-
}
|
|
1789
|
-
function Ue(t, e) {
|
|
1790
|
-
return ve(t, e).reverse();
|
|
1791
|
-
}
|
|
1792
|
-
function sf(t) {
|
|
1793
|
-
return ye(we(t));
|
|
1794
|
-
}
|
|
1795
|
-
function Tt(t, e, r) {
|
|
1796
|
-
let o;
|
|
1797
|
-
if (typeof e == "string")
|
|
1798
|
-
try {
|
|
1799
|
-
o = ye(e);
|
|
1800
|
-
} catch (i) {
|
|
1801
|
-
throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`);
|
|
1802
|
-
}
|
|
1803
|
-
else if (se(e))
|
|
1804
|
-
o = Uint8Array.from(e);
|
|
1805
|
-
else
|
|
1806
|
-
throw new Error(`${t} must be hex string or Uint8Array`);
|
|
1807
|
-
const c = o.length;
|
|
1808
|
-
if (typeof r == "number" && c !== r)
|
|
1809
|
-
throw new Error(`${t} expected ${r} bytes, got ${c}`);
|
|
1810
|
-
return o;
|
|
1811
|
-
}
|
|
1812
|
-
function ae(...t) {
|
|
1813
|
-
let e = 0;
|
|
1814
|
-
for (let o = 0; o < t.length; o++) {
|
|
1815
|
-
const c = t[o];
|
|
1816
|
-
Le(c), e += c.length;
|
|
1817
|
-
}
|
|
1818
|
-
const r = new Uint8Array(e);
|
|
1819
|
-
for (let o = 0, c = 0; o < t.length; o++) {
|
|
1820
|
-
const i = t[o];
|
|
1821
|
-
r.set(i, c), c += i.length;
|
|
1822
|
-
}
|
|
1823
|
-
return r;
|
|
1824
|
-
}
|
|
1825
|
-
function ff(t, e) {
|
|
1826
|
-
if (t.length !== e.length)
|
|
1827
|
-
return !1;
|
|
1828
|
-
let r = 0;
|
|
1829
|
-
for (let o = 0; o < t.length; o++)
|
|
1830
|
-
r |= t[o] ^ e[o];
|
|
1831
|
-
return r === 0;
|
|
1832
|
-
}
|
|
1833
|
-
function af(t) {
|
|
1834
|
-
if (typeof t != "string")
|
|
1835
|
-
throw new Error(`utf8ToBytes expected string, got ${typeof t}`);
|
|
1836
|
-
return new Uint8Array(new TextEncoder().encode(t));
|
|
1837
|
-
}
|
|
1838
|
-
const Lr = (t) => typeof t == "bigint" && hn <= t;
|
|
1839
|
-
function sr(t, e, r) {
|
|
1840
|
-
return Lr(t) && Lr(e) && Lr(r) && e <= t && t < r;
|
|
1841
|
-
}
|
|
1842
|
-
function Yt(t, e, r, o) {
|
|
1843
|
-
if (!sr(e, r, o))
|
|
1844
|
-
throw new Error(`expected valid ${t}: ${r} <= n < ${o}, got ${typeof e} ${e}`);
|
|
1845
|
-
}
|
|
1846
|
-
function Ti(t) {
|
|
1847
|
-
let e;
|
|
1848
|
-
for (e = 0; t > hn; t >>= or, e += 1)
|
|
1849
|
-
;
|
|
1850
|
-
return e;
|
|
1851
|
-
}
|
|
1852
|
-
function hf(t, e) {
|
|
1853
|
-
return t >> BigInt(e) & or;
|
|
1854
|
-
}
|
|
1855
|
-
function cf(t, e, r) {
|
|
1856
|
-
return t | (r ? or : hn) << BigInt(e);
|
|
1857
|
-
}
|
|
1858
|
-
const ln = (t) => (nf << BigInt(t - 1)) - or, Tr = (t) => new Uint8Array(t), Cn = (t) => Uint8Array.from(t);
|
|
1859
|
-
function $i(t, e, r) {
|
|
1860
|
-
if (typeof t != "number" || t < 2)
|
|
1861
|
-
throw new Error("hashLen must be a number");
|
|
1862
|
-
if (typeof e != "number" || e < 2)
|
|
1863
|
-
throw new Error("qByteLen must be a number");
|
|
1864
|
-
if (typeof r != "function")
|
|
1865
|
-
throw new Error("hmacFn must be a function");
|
|
1866
|
-
let o = Tr(t), c = Tr(t), i = 0;
|
|
1867
|
-
const w = () => {
|
|
1868
|
-
o.fill(1), c.fill(0), i = 0;
|
|
1869
|
-
}, d = (...E) => r(c, o, ...E), y = (E = Tr()) => {
|
|
1870
|
-
c = d(Cn([0]), E), o = d(), E.length !== 0 && (c = d(Cn([1]), E), o = d());
|
|
1871
|
-
}, x = () => {
|
|
1872
|
-
if (i++ >= 1e3)
|
|
1873
|
-
throw new Error("drbg: tried 1000 values");
|
|
1874
|
-
let E = 0;
|
|
1875
|
-
const M = [];
|
|
1876
|
-
for (; E < e; ) {
|
|
1877
|
-
o = d();
|
|
1878
|
-
const U = o.slice();
|
|
1879
|
-
M.push(U), E += o.length;
|
|
1880
|
-
}
|
|
1881
|
-
return ae(...M);
|
|
1882
|
-
};
|
|
1883
|
-
return (E, M) => {
|
|
1884
|
-
w(), y(E);
|
|
1885
|
-
let U;
|
|
1886
|
-
for (; !(U = M(x())); )
|
|
1887
|
-
y();
|
|
1888
|
-
return w(), U;
|
|
1889
|
-
};
|
|
1890
|
-
}
|
|
1891
|
-
const lf = {
|
|
1892
|
-
bigint: (t) => typeof t == "bigint",
|
|
1893
|
-
function: (t) => typeof t == "function",
|
|
1894
|
-
boolean: (t) => typeof t == "boolean",
|
|
1895
|
-
string: (t) => typeof t == "string",
|
|
1896
|
-
stringOrUint8Array: (t) => typeof t == "string" || se(t),
|
|
1897
|
-
isSafeInteger: (t) => Number.isSafeInteger(t),
|
|
1898
|
-
array: (t) => Array.isArray(t),
|
|
1899
|
-
field: (t, e) => e.Fp.isValid(t),
|
|
1900
|
-
hash: (t) => typeof t == "function" && Number.isSafeInteger(t.outputLen)
|
|
1901
|
-
};
|
|
1902
|
-
function xe(t, e, r = {}) {
|
|
1903
|
-
const o = (c, i, w) => {
|
|
1904
|
-
const d = lf[i];
|
|
1905
|
-
if (typeof d != "function")
|
|
1906
|
-
throw new Error(`Invalid validator "${i}", expected function`);
|
|
1907
|
-
const y = t[c];
|
|
1908
|
-
if (!(w && y === void 0) && !d(y, t))
|
|
1909
|
-
throw new Error(`Invalid param ${String(c)}=${y} (${typeof y}), expected ${i}`);
|
|
1910
|
-
};
|
|
1911
|
-
for (const [c, i] of Object.entries(e))
|
|
1912
|
-
o(c, i, !1);
|
|
1913
|
-
for (const [c, i] of Object.entries(r))
|
|
1914
|
-
o(c, i, !0);
|
|
1915
|
-
return t;
|
|
1916
|
-
}
|
|
1917
|
-
const uf = () => {
|
|
1918
|
-
throw new Error("not implemented");
|
|
1919
|
-
};
|
|
1920
|
-
function Ne(t) {
|
|
1921
|
-
const e = /* @__PURE__ */ new WeakMap();
|
|
1922
|
-
return (r, ...o) => {
|
|
1923
|
-
const c = e.get(r);
|
|
1924
|
-
if (c !== void 0)
|
|
1925
|
-
return c;
|
|
1926
|
-
const i = t(r, ...o);
|
|
1927
|
-
return e.set(r, i), i;
|
|
1928
|
-
};
|
|
1929
|
-
}
|
|
1930
|
-
const df = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1931
|
-
__proto__: null,
|
|
1932
|
-
aInRange: Yt,
|
|
1933
|
-
abool: Qt,
|
|
1934
|
-
abytes: Le,
|
|
1935
|
-
bitGet: hf,
|
|
1936
|
-
bitLen: Ti,
|
|
1937
|
-
bitMask: ln,
|
|
1938
|
-
bitSet: cf,
|
|
1939
|
-
bytesToHex: fe,
|
|
1940
|
-
bytesToNumberBE: ie,
|
|
1941
|
-
bytesToNumberLE: me,
|
|
1942
|
-
concatBytes: ae,
|
|
1943
|
-
createHmacDrbg: $i,
|
|
1944
|
-
ensureBytes: Tt,
|
|
1945
|
-
equalBytes: ff,
|
|
1946
|
-
hexToBytes: ye,
|
|
1947
|
-
hexToNumber: cn,
|
|
1948
|
-
inRange: sr,
|
|
1949
|
-
isBytes: se,
|
|
1950
|
-
memoized: Ne,
|
|
1951
|
-
notImplemented: uf,
|
|
1952
|
-
numberToBytesBE: ve,
|
|
1953
|
-
numberToBytesLE: Ue,
|
|
1954
|
-
numberToHexUnpadded: we,
|
|
1955
|
-
numberToVarBytesBE: sf,
|
|
1956
|
-
utf8ToBytes: af,
|
|
1957
|
-
validateObject: xe
|
|
1958
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1959
|
-
const Pt = BigInt(0), ft = BigInt(1), ne = BigInt(2), wf = BigInt(3), jr = BigInt(4), Zn = BigInt(5), Dn = BigInt(8);
|
|
1960
|
-
BigInt(9);
|
|
1961
|
-
BigInt(16);
|
|
1962
|
-
function tt(t, e) {
|
|
1963
|
-
const r = t % e;
|
|
1964
|
-
return r >= Pt ? r : e + r;
|
|
1965
|
-
}
|
|
1966
|
-
function gf(t, e, r) {
|
|
1967
|
-
if (r <= Pt || e < Pt)
|
|
1968
|
-
throw new Error("Expected power/modulo > 0");
|
|
1969
|
-
if (r === ft)
|
|
1970
|
-
return Pt;
|
|
1971
|
-
let o = ft;
|
|
1972
|
-
for (; e > Pt; )
|
|
1973
|
-
e & ft && (o = o * t % r), t = t * t % r, e >>= ft;
|
|
1974
|
-
return o;
|
|
1975
|
-
}
|
|
1976
|
-
function ut(t, e, r) {
|
|
1977
|
-
let o = t;
|
|
1978
|
-
for (; e-- > Pt; )
|
|
1979
|
-
o *= o, o %= r;
|
|
1980
|
-
return o;
|
|
1981
|
-
}
|
|
1982
|
-
function Kr(t, e) {
|
|
1983
|
-
if (t === Pt || e <= Pt)
|
|
1984
|
-
throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);
|
|
1985
|
-
let r = tt(t, e), o = e, c = Pt, i = ft;
|
|
1986
|
-
for (; r !== Pt; ) {
|
|
1987
|
-
const d = o / r, y = o % r, x = c - i * d;
|
|
1988
|
-
o = r, r = y, c = i, i = x;
|
|
1989
|
-
}
|
|
1990
|
-
if (o !== ft)
|
|
1991
|
-
throw new Error("invert: does not exist");
|
|
1992
|
-
return tt(c, e);
|
|
1993
|
-
}
|
|
1994
|
-
function mf(t) {
|
|
1995
|
-
const e = (t - ft) / ne;
|
|
1996
|
-
let r, o, c;
|
|
1997
|
-
for (r = t - ft, o = 0; r % ne === Pt; r /= ne, o++)
|
|
1998
|
-
;
|
|
1999
|
-
for (c = ne; c < t && gf(c, e, t) !== t - ft; c++)
|
|
2000
|
-
;
|
|
2001
|
-
if (o === 1) {
|
|
2002
|
-
const w = (t + ft) / jr;
|
|
2003
|
-
return function(y, x) {
|
|
2004
|
-
const v = y.pow(x, w);
|
|
2005
|
-
if (!y.eql(y.sqr(v), x))
|
|
2006
|
-
throw new Error("Cannot find square root");
|
|
2007
|
-
return v;
|
|
2008
|
-
};
|
|
2009
|
-
}
|
|
2010
|
-
const i = (r + ft) / ne;
|
|
2011
|
-
return function(d, y) {
|
|
2012
|
-
if (d.pow(y, e) === d.neg(d.ONE))
|
|
2013
|
-
throw new Error("Cannot find square root");
|
|
2014
|
-
let x = o, v = d.pow(d.mul(d.ONE, c), r), E = d.pow(y, i), M = d.pow(y, r);
|
|
2015
|
-
for (; !d.eql(M, d.ONE); ) {
|
|
2016
|
-
if (d.eql(M, d.ZERO))
|
|
2017
|
-
return d.ZERO;
|
|
2018
|
-
let U = 1;
|
|
2019
|
-
for (let k = d.sqr(M); U < x && !d.eql(k, d.ONE); U++)
|
|
2020
|
-
k = d.sqr(k);
|
|
2021
|
-
const C = d.pow(v, ft << BigInt(x - U - 1));
|
|
2022
|
-
v = d.sqr(C), E = d.mul(E, C), M = d.mul(M, v), x = U;
|
|
2023
|
-
}
|
|
2024
|
-
return E;
|
|
2025
|
-
};
|
|
2026
|
-
}
|
|
2027
|
-
function pf(t) {
|
|
2028
|
-
if (t % jr === wf) {
|
|
2029
|
-
const e = (t + ft) / jr;
|
|
2030
|
-
return function(o, c) {
|
|
2031
|
-
const i = o.pow(c, e);
|
|
2032
|
-
if (!o.eql(o.sqr(i), c))
|
|
2033
|
-
throw new Error("Cannot find square root");
|
|
2034
|
-
return i;
|
|
2035
|
-
};
|
|
2036
|
-
}
|
|
2037
|
-
if (t % Dn === Zn) {
|
|
2038
|
-
const e = (t - Zn) / Dn;
|
|
2039
|
-
return function(o, c) {
|
|
2040
|
-
const i = o.mul(c, ne), w = o.pow(i, e), d = o.mul(c, w), y = o.mul(o.mul(d, ne), w), x = o.mul(d, o.sub(y, o.ONE));
|
|
2041
|
-
if (!o.eql(o.sqr(x), c))
|
|
2042
|
-
throw new Error("Cannot find square root");
|
|
2043
|
-
return x;
|
|
2044
|
-
};
|
|
2045
|
-
}
|
|
2046
|
-
return mf(t);
|
|
2047
|
-
}
|
|
2048
|
-
const yf = (t, e) => (tt(t, e) & ft) === ft, vf = [
|
|
2049
|
-
"create",
|
|
2050
|
-
"isValid",
|
|
2051
|
-
"is0",
|
|
2052
|
-
"neg",
|
|
2053
|
-
"inv",
|
|
2054
|
-
"sqrt",
|
|
2055
|
-
"sqr",
|
|
2056
|
-
"eql",
|
|
2057
|
-
"add",
|
|
2058
|
-
"sub",
|
|
2059
|
-
"mul",
|
|
2060
|
-
"pow",
|
|
2061
|
-
"div",
|
|
2062
|
-
"addN",
|
|
2063
|
-
"subN",
|
|
2064
|
-
"mulN",
|
|
2065
|
-
"sqrN"
|
|
2066
|
-
];
|
|
2067
|
-
function bf(t) {
|
|
2068
|
-
const e = {
|
|
2069
|
-
ORDER: "bigint",
|
|
2070
|
-
MASK: "bigint",
|
|
2071
|
-
BYTES: "isSafeInteger",
|
|
2072
|
-
BITS: "isSafeInteger"
|
|
2073
|
-
}, r = vf.reduce((o, c) => (o[c] = "function", o), e);
|
|
2074
|
-
return xe(t, r);
|
|
2075
|
-
}
|
|
2076
|
-
function xf(t, e, r) {
|
|
2077
|
-
if (r < Pt)
|
|
2078
|
-
throw new Error("Expected power > 0");
|
|
2079
|
-
if (r === Pt)
|
|
2080
|
-
return t.ONE;
|
|
2081
|
-
if (r === ft)
|
|
2082
|
-
return e;
|
|
2083
|
-
let o = t.ONE, c = e;
|
|
2084
|
-
for (; r > Pt; )
|
|
2085
|
-
r & ft && (o = t.mul(o, c)), c = t.sqr(c), r >>= ft;
|
|
2086
|
-
return o;
|
|
2087
|
-
}
|
|
2088
|
-
function Ef(t, e) {
|
|
2089
|
-
const r = new Array(e.length), o = e.reduce((i, w, d) => t.is0(w) ? i : (r[d] = i, t.mul(i, w)), t.ONE), c = t.inv(o);
|
|
2090
|
-
return e.reduceRight((i, w, d) => t.is0(w) ? i : (r[d] = t.mul(i, r[d]), t.mul(i, w)), c), r;
|
|
2091
|
-
}
|
|
2092
|
-
function qi(t, e) {
|
|
2093
|
-
const r = e !== void 0 ? e : t.toString(2).length, o = Math.ceil(r / 8);
|
|
2094
|
-
return { nBitLength: r, nByteLength: o };
|
|
2095
|
-
}
|
|
2096
|
-
function fr(t, e, r = !1, o = {}) {
|
|
2097
|
-
if (t <= Pt)
|
|
2098
|
-
throw new Error(`Expected Field ORDER > 0, got ${t}`);
|
|
2099
|
-
const { nBitLength: c, nByteLength: i } = qi(t, e);
|
|
2100
|
-
if (i > 2048)
|
|
2101
|
-
throw new Error("Field lengths over 2048 bytes are not supported");
|
|
2102
|
-
const w = pf(t), d = Object.freeze({
|
|
2103
|
-
ORDER: t,
|
|
2104
|
-
BITS: c,
|
|
2105
|
-
BYTES: i,
|
|
2106
|
-
MASK: ln(c),
|
|
2107
|
-
ZERO: Pt,
|
|
2108
|
-
ONE: ft,
|
|
2109
|
-
create: (y) => tt(y, t),
|
|
2110
|
-
isValid: (y) => {
|
|
2111
|
-
if (typeof y != "bigint")
|
|
2112
|
-
throw new Error(`Invalid field element: expected bigint, got ${typeof y}`);
|
|
2113
|
-
return Pt <= y && y < t;
|
|
2114
|
-
},
|
|
2115
|
-
is0: (y) => y === Pt,
|
|
2116
|
-
isOdd: (y) => (y & ft) === ft,
|
|
2117
|
-
neg: (y) => tt(-y, t),
|
|
2118
|
-
eql: (y, x) => y === x,
|
|
2119
|
-
sqr: (y) => tt(y * y, t),
|
|
2120
|
-
add: (y, x) => tt(y + x, t),
|
|
2121
|
-
sub: (y, x) => tt(y - x, t),
|
|
2122
|
-
mul: (y, x) => tt(y * x, t),
|
|
2123
|
-
pow: (y, x) => xf(d, y, x),
|
|
2124
|
-
div: (y, x) => tt(y * Kr(x, t), t),
|
|
2125
|
-
// Same as above, but doesn't normalize
|
|
2126
|
-
sqrN: (y) => y * y,
|
|
2127
|
-
addN: (y, x) => y + x,
|
|
2128
|
-
subN: (y, x) => y - x,
|
|
2129
|
-
mulN: (y, x) => y * x,
|
|
2130
|
-
inv: (y) => Kr(y, t),
|
|
2131
|
-
sqrt: o.sqrt || ((y) => w(d, y)),
|
|
2132
|
-
invertBatch: (y) => Ef(d, y),
|
|
2133
|
-
// TODO: do we really need constant cmov?
|
|
2134
|
-
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
2135
|
-
cmov: (y, x, v) => v ? x : y,
|
|
2136
|
-
toBytes: (y) => r ? Ue(y, i) : ve(y, i),
|
|
2137
|
-
fromBytes: (y) => {
|
|
2138
|
-
if (y.length !== i)
|
|
2139
|
-
throw new Error(`Fp.fromBytes: expected ${i}, got ${y.length}`);
|
|
2140
|
-
return r ? me(y) : ie(y);
|
|
2141
|
-
}
|
|
2142
|
-
});
|
|
2143
|
-
return Object.freeze(d);
|
|
2144
|
-
}
|
|
2145
|
-
function Pi(t) {
|
|
2146
|
-
if (typeof t != "bigint")
|
|
2147
|
-
throw new Error("field order must be bigint");
|
|
2148
|
-
const e = t.toString(2).length;
|
|
2149
|
-
return Math.ceil(e / 8);
|
|
2150
|
-
}
|
|
2151
|
-
function Ci(t) {
|
|
2152
|
-
const e = Pi(t);
|
|
2153
|
-
return e + Math.ceil(e / 2);
|
|
2154
|
-
}
|
|
2155
|
-
function Mf(t, e, r = !1) {
|
|
2156
|
-
const o = t.length, c = Pi(e), i = Ci(e);
|
|
2157
|
-
if (o < 16 || o < i || o > 1024)
|
|
2158
|
-
throw new Error(`expected ${i}-1024 bytes of input, got ${o}`);
|
|
2159
|
-
const w = r ? ie(t) : me(t), d = tt(w, e - ft) + ft;
|
|
2160
|
-
return r ? Ue(d, c) : ve(d, c);
|
|
2161
|
-
}
|
|
2162
|
-
const _f = BigInt(0), $r = BigInt(1), qr = /* @__PURE__ */ new WeakMap(), Hn = /* @__PURE__ */ new WeakMap();
|
|
2163
|
-
function Zi(t, e) {
|
|
2164
|
-
const r = (i, w) => {
|
|
2165
|
-
const d = w.negate();
|
|
2166
|
-
return i ? d : w;
|
|
2167
|
-
}, o = (i) => {
|
|
2168
|
-
if (!Number.isSafeInteger(i) || i <= 0 || i > e)
|
|
2169
|
-
throw new Error(`Wrong window size=${i}, should be [1..${e}]`);
|
|
2170
|
-
}, c = (i) => {
|
|
2171
|
-
o(i);
|
|
2172
|
-
const w = Math.ceil(e / i) + 1, d = 2 ** (i - 1);
|
|
2173
|
-
return { windows: w, windowSize: d };
|
|
2174
|
-
};
|
|
2175
|
-
return {
|
|
2176
|
-
constTimeNegate: r,
|
|
2177
|
-
// non-const time multiplication ladder
|
|
2178
|
-
unsafeLadder(i, w) {
|
|
2179
|
-
let d = t.ZERO, y = i;
|
|
2180
|
-
for (; w > _f; )
|
|
2181
|
-
w & $r && (d = d.add(y)), y = y.double(), w >>= $r;
|
|
2182
|
-
return d;
|
|
2183
|
-
},
|
|
2184
|
-
/**
|
|
2185
|
-
* Creates a wNAF precomputation window. Used for caching.
|
|
2186
|
-
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
2187
|
-
* Number of precomputed points depends on the curve size:
|
|
2188
|
-
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
2189
|
-
* - 𝑊 is the window size
|
|
2190
|
-
* - 𝑛 is the bitlength of the curve order.
|
|
2191
|
-
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
2192
|
-
* @returns precomputed point tables flattened to a single array
|
|
2193
|
-
*/
|
|
2194
|
-
precomputeWindow(i, w) {
|
|
2195
|
-
const { windows: d, windowSize: y } = c(w), x = [];
|
|
2196
|
-
let v = i, E = v;
|
|
2197
|
-
for (let M = 0; M < d; M++) {
|
|
2198
|
-
E = v, x.push(E);
|
|
2199
|
-
for (let U = 1; U < y; U++)
|
|
2200
|
-
E = E.add(v), x.push(E);
|
|
2201
|
-
v = E.double();
|
|
2202
|
-
}
|
|
2203
|
-
return x;
|
|
2204
|
-
},
|
|
2205
|
-
/**
|
|
2206
|
-
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
2207
|
-
* @param W window size
|
|
2208
|
-
* @param precomputes precomputed tables
|
|
2209
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
2210
|
-
* @returns real and fake (for const-time) points
|
|
2211
|
-
*/
|
|
2212
|
-
wNAF(i, w, d) {
|
|
2213
|
-
const { windows: y, windowSize: x } = c(i);
|
|
2214
|
-
let v = t.ZERO, E = t.BASE;
|
|
2215
|
-
const M = BigInt(2 ** i - 1), U = 2 ** i, C = BigInt(i);
|
|
2216
|
-
for (let k = 0; k < y; k++) {
|
|
2217
|
-
const _ = k * x;
|
|
2218
|
-
let S = Number(d & M);
|
|
2219
|
-
d >>= C, S > x && (S -= U, d += $r);
|
|
2220
|
-
const L = _, A = _ + Math.abs(S) - 1, q = k % 2 !== 0, D = S < 0;
|
|
2221
|
-
S === 0 ? E = E.add(r(q, w[L])) : v = v.add(r(D, w[A]));
|
|
2222
|
-
}
|
|
2223
|
-
return { p: v, f: E };
|
|
2224
|
-
},
|
|
2225
|
-
wNAFCached(i, w, d) {
|
|
2226
|
-
const y = Hn.get(i) || 1;
|
|
2227
|
-
let x = qr.get(i);
|
|
2228
|
-
return x || (x = this.precomputeWindow(i, y), y !== 1 && qr.set(i, d(x))), this.wNAF(y, x, w);
|
|
2229
|
-
},
|
|
2230
|
-
// We calculate precomputes for elliptic curve point multiplication
|
|
2231
|
-
// using windowed method. This specifies window size and
|
|
2232
|
-
// stores precomputed values. Usually only base point would be precomputed.
|
|
2233
|
-
setWindowSize(i, w) {
|
|
2234
|
-
o(w), Hn.set(i, w), qr.delete(i);
|
|
2235
|
-
}
|
|
2236
|
-
};
|
|
2237
|
-
}
|
|
2238
|
-
function Di(t, e, r, o) {
|
|
2239
|
-
if (!Array.isArray(r) || !Array.isArray(o) || o.length !== r.length)
|
|
2240
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
2241
|
-
o.forEach((v, E) => {
|
|
2242
|
-
if (!e.isValid(v))
|
|
2243
|
-
throw new Error(`wrong scalar at index ${E}`);
|
|
2244
|
-
}), r.forEach((v, E) => {
|
|
2245
|
-
if (!(v instanceof t))
|
|
2246
|
-
throw new Error(`wrong point at index ${E}`);
|
|
2247
|
-
});
|
|
2248
|
-
const c = Ti(BigInt(r.length)), i = c > 12 ? c - 3 : c > 4 ? c - 2 : c ? 2 : 1, w = (1 << i) - 1, d = new Array(w + 1).fill(t.ZERO), y = Math.floor((e.BITS - 1) / i) * i;
|
|
2249
|
-
let x = t.ZERO;
|
|
2250
|
-
for (let v = y; v >= 0; v -= i) {
|
|
2251
|
-
d.fill(t.ZERO);
|
|
2252
|
-
for (let M = 0; M < o.length; M++) {
|
|
2253
|
-
const U = o[M], C = Number(U >> BigInt(v) & BigInt(w));
|
|
2254
|
-
d[C] = d[C].add(r[M]);
|
|
2255
|
-
}
|
|
2256
|
-
let E = t.ZERO;
|
|
2257
|
-
for (let M = d.length - 1, U = t.ZERO; M > 0; M--)
|
|
2258
|
-
U = U.add(d[M]), E = E.add(U);
|
|
2259
|
-
if (x = x.add(E), v !== 0)
|
|
2260
|
-
for (let M = 0; M < i; M++)
|
|
2261
|
-
x = x.double();
|
|
2262
|
-
}
|
|
2263
|
-
return x;
|
|
2264
|
-
}
|
|
2265
|
-
function un(t) {
|
|
2266
|
-
return bf(t.Fp), xe(t, {
|
|
2267
|
-
n: "bigint",
|
|
2268
|
-
h: "bigint",
|
|
2269
|
-
Gx: "field",
|
|
2270
|
-
Gy: "field"
|
|
2271
|
-
}, {
|
|
2272
|
-
nBitLength: "isSafeInteger",
|
|
2273
|
-
nByteLength: "isSafeInteger"
|
|
2274
|
-
}), Object.freeze({
|
|
2275
|
-
...qi(t.n, t.nBitLength),
|
|
2276
|
-
...t,
|
|
2277
|
-
p: t.Fp.ORDER
|
|
2278
|
-
});
|
|
2279
|
-
}
|
|
2280
|
-
function Vn(t) {
|
|
2281
|
-
t.lowS !== void 0 && Qt("lowS", t.lowS), t.prehash !== void 0 && Qt("prehash", t.prehash);
|
|
2282
|
-
}
|
|
2283
|
-
function Bf(t) {
|
|
2284
|
-
const e = un(t);
|
|
2285
|
-
xe(e, {
|
|
2286
|
-
a: "field",
|
|
2287
|
-
b: "field"
|
|
2288
|
-
}, {
|
|
2289
|
-
allowedPrivateKeyLengths: "array",
|
|
2290
|
-
wrapPrivateKey: "boolean",
|
|
2291
|
-
isTorsionFree: "function",
|
|
2292
|
-
clearCofactor: "function",
|
|
2293
|
-
allowInfinityPoint: "boolean",
|
|
2294
|
-
fromBytes: "function",
|
|
2295
|
-
toBytes: "function"
|
|
2296
|
-
});
|
|
2297
|
-
const { endo: r, Fp: o, a: c } = e;
|
|
2298
|
-
if (r) {
|
|
2299
|
-
if (!o.eql(c, o.ZERO))
|
|
2300
|
-
throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
|
|
2301
|
-
if (typeof r != "object" || typeof r.beta != "bigint" || typeof r.splitScalar != "function")
|
|
2302
|
-
throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
|
|
2303
|
-
}
|
|
2304
|
-
return Object.freeze({ ...e });
|
|
2305
|
-
}
|
|
2306
|
-
const { bytesToNumberBE: Sf, hexToBytes: Af } = df, Wt = {
|
|
2307
|
-
// asn.1 DER encoding utils
|
|
2308
|
-
Err: class extends Error {
|
|
2309
|
-
constructor(e = "") {
|
|
2310
|
-
super(e);
|
|
2311
|
-
}
|
|
2312
|
-
},
|
|
2313
|
-
// Basic building block is TLV (Tag-Length-Value)
|
|
2314
|
-
_tlv: {
|
|
2315
|
-
encode: (t, e) => {
|
|
2316
|
-
const { Err: r } = Wt;
|
|
2317
|
-
if (t < 0 || t > 256)
|
|
2318
|
-
throw new r("tlv.encode: wrong tag");
|
|
2319
|
-
if (e.length & 1)
|
|
2320
|
-
throw new r("tlv.encode: unpadded data");
|
|
2321
|
-
const o = e.length / 2, c = we(o);
|
|
2322
|
-
if (c.length / 2 & 128)
|
|
2323
|
-
throw new r("tlv.encode: long form length too big");
|
|
2324
|
-
const i = o > 127 ? we(c.length / 2 | 128) : "";
|
|
2325
|
-
return `${we(t)}${i}${c}${e}`;
|
|
2326
|
-
},
|
|
2327
|
-
// v - value, l - left bytes (unparsed)
|
|
2328
|
-
decode(t, e) {
|
|
2329
|
-
const { Err: r } = Wt;
|
|
2330
|
-
let o = 0;
|
|
2331
|
-
if (t < 0 || t > 256)
|
|
2332
|
-
throw new r("tlv.encode: wrong tag");
|
|
2333
|
-
if (e.length < 2 || e[o++] !== t)
|
|
2334
|
-
throw new r("tlv.decode: wrong tlv");
|
|
2335
|
-
const c = e[o++], i = !!(c & 128);
|
|
2336
|
-
let w = 0;
|
|
2337
|
-
if (!i)
|
|
2338
|
-
w = c;
|
|
2339
|
-
else {
|
|
2340
|
-
const y = c & 127;
|
|
2341
|
-
if (!y)
|
|
2342
|
-
throw new r("tlv.decode(long): indefinite length not supported");
|
|
2343
|
-
if (y > 4)
|
|
2344
|
-
throw new r("tlv.decode(long): byte length is too big");
|
|
2345
|
-
const x = e.subarray(o, o + y);
|
|
2346
|
-
if (x.length !== y)
|
|
2347
|
-
throw new r("tlv.decode: length bytes not complete");
|
|
2348
|
-
if (x[0] === 0)
|
|
2349
|
-
throw new r("tlv.decode(long): zero leftmost byte");
|
|
2350
|
-
for (const v of x)
|
|
2351
|
-
w = w << 8 | v;
|
|
2352
|
-
if (o += y, w < 128)
|
|
2353
|
-
throw new r("tlv.decode(long): not minimal encoding");
|
|
2354
|
-
}
|
|
2355
|
-
const d = e.subarray(o, o + w);
|
|
2356
|
-
if (d.length !== w)
|
|
2357
|
-
throw new r("tlv.decode: wrong value length");
|
|
2358
|
-
return { v: d, l: e.subarray(o + w) };
|
|
2359
|
-
}
|
|
2360
|
-
},
|
|
2361
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
2362
|
-
// since we always use positive integers here. It must always be empty:
|
|
2363
|
-
// - add zero byte if exists
|
|
2364
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
2365
|
-
_int: {
|
|
2366
|
-
encode(t) {
|
|
2367
|
-
const { Err: e } = Wt;
|
|
2368
|
-
if (t < Jt)
|
|
2369
|
-
throw new e("integer: negative integers are not allowed");
|
|
2370
|
-
let r = we(t);
|
|
2371
|
-
if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
|
|
2372
|
-
throw new e("unexpected assertion");
|
|
2373
|
-
return r;
|
|
2374
|
-
},
|
|
2375
|
-
decode(t) {
|
|
2376
|
-
const { Err: e } = Wt;
|
|
2377
|
-
if (t[0] & 128)
|
|
2378
|
-
throw new e("Invalid signature integer: negative");
|
|
2379
|
-
if (t[0] === 0 && !(t[1] & 128))
|
|
2380
|
-
throw new e("Invalid signature integer: unnecessary leading zero");
|
|
2381
|
-
return Sf(t);
|
|
2382
|
-
}
|
|
2383
|
-
},
|
|
2384
|
-
toSig(t) {
|
|
2385
|
-
const { Err: e, _int: r, _tlv: o } = Wt, c = typeof t == "string" ? Af(t) : t;
|
|
2386
|
-
Le(c);
|
|
2387
|
-
const { v: i, l: w } = o.decode(48, c);
|
|
2388
|
-
if (w.length)
|
|
2389
|
-
throw new e("Invalid signature: left bytes after parsing");
|
|
2390
|
-
const { v: d, l: y } = o.decode(2, i), { v: x, l: v } = o.decode(2, y);
|
|
2391
|
-
if (v.length)
|
|
2392
|
-
throw new e("Invalid signature: left bytes after parsing");
|
|
2393
|
-
return { r: r.decode(d), s: r.decode(x) };
|
|
2394
|
-
},
|
|
2395
|
-
hexFromSig(t) {
|
|
2396
|
-
const { _tlv: e, _int: r } = Wt, o = `${e.encode(2, r.encode(t.r))}${e.encode(2, r.encode(t.s))}`;
|
|
2397
|
-
return e.encode(48, o);
|
|
2398
|
-
}
|
|
2399
|
-
}, Jt = BigInt(0), qt = BigInt(1), k0 = BigInt(2), zn = BigInt(3), U0 = BigInt(4);
|
|
2400
|
-
function If(t) {
|
|
2401
|
-
const e = Bf(t), { Fp: r } = e, o = fr(e.n, e.nBitLength), c = e.toBytes || ((k, _, S) => {
|
|
2402
|
-
const L = _.toAffine();
|
|
2403
|
-
return ae(Uint8Array.from([4]), r.toBytes(L.x), r.toBytes(L.y));
|
|
2404
|
-
}), i = e.fromBytes || ((k) => {
|
|
2405
|
-
const _ = k.subarray(1), S = r.fromBytes(_.subarray(0, r.BYTES)), L = r.fromBytes(_.subarray(r.BYTES, 2 * r.BYTES));
|
|
2406
|
-
return { x: S, y: L };
|
|
2407
|
-
});
|
|
2408
|
-
function w(k) {
|
|
2409
|
-
const { a: _, b: S } = e, L = r.sqr(k), A = r.mul(L, k);
|
|
2410
|
-
return r.add(r.add(A, r.mul(k, _)), S);
|
|
2411
|
-
}
|
|
2412
|
-
if (!r.eql(r.sqr(e.Gy), w(e.Gx)))
|
|
2413
|
-
throw new Error("bad generator point: equation left != right");
|
|
2414
|
-
function d(k) {
|
|
2415
|
-
return sr(k, qt, e.n);
|
|
2416
|
-
}
|
|
2417
|
-
function y(k) {
|
|
2418
|
-
const { allowedPrivateKeyLengths: _, nByteLength: S, wrapPrivateKey: L, n: A } = e;
|
|
2419
|
-
if (_ && typeof k != "bigint") {
|
|
2420
|
-
if (se(k) && (k = fe(k)), typeof k != "string" || !_.includes(k.length))
|
|
2421
|
-
throw new Error("Invalid key");
|
|
2422
|
-
k = k.padStart(S * 2, "0");
|
|
2423
|
-
}
|
|
2424
|
-
let q;
|
|
2425
|
-
try {
|
|
2426
|
-
q = typeof k == "bigint" ? k : ie(Tt("private key", k, S));
|
|
2427
|
-
} catch {
|
|
2428
|
-
throw new Error(`private key must be ${S} bytes, hex or bigint, not ${typeof k}`);
|
|
2429
|
-
}
|
|
2430
|
-
return L && (q = tt(q, A)), Yt("private key", q, qt, A), q;
|
|
2431
|
-
}
|
|
2432
|
-
function x(k) {
|
|
2433
|
-
if (!(k instanceof M))
|
|
2434
|
-
throw new Error("ProjectivePoint expected");
|
|
2435
|
-
}
|
|
2436
|
-
const v = Ne((k, _) => {
|
|
2437
|
-
const { px: S, py: L, pz: A } = k;
|
|
2438
|
-
if (r.eql(A, r.ONE))
|
|
2439
|
-
return { x: S, y: L };
|
|
2440
|
-
const q = k.is0();
|
|
2441
|
-
_ == null && (_ = q ? r.ONE : r.inv(A));
|
|
2442
|
-
const D = r.mul(S, _), R = r.mul(L, _), O = r.mul(A, _);
|
|
2443
|
-
if (q)
|
|
2444
|
-
return { x: r.ZERO, y: r.ZERO };
|
|
2445
|
-
if (!r.eql(O, r.ONE))
|
|
2446
|
-
throw new Error("invZ was invalid");
|
|
2447
|
-
return { x: D, y: R };
|
|
2448
|
-
}), E = Ne((k) => {
|
|
2449
|
-
if (k.is0()) {
|
|
2450
|
-
if (e.allowInfinityPoint && !r.is0(k.py))
|
|
2451
|
-
return;
|
|
2452
|
-
throw new Error("bad point: ZERO");
|
|
2453
|
-
}
|
|
2454
|
-
const { x: _, y: S } = k.toAffine();
|
|
2455
|
-
if (!r.isValid(_) || !r.isValid(S))
|
|
2456
|
-
throw new Error("bad point: x or y not FE");
|
|
2457
|
-
const L = r.sqr(S), A = w(_);
|
|
2458
|
-
if (!r.eql(L, A))
|
|
2459
|
-
throw new Error("bad point: equation left != right");
|
|
2460
|
-
if (!k.isTorsionFree())
|
|
2461
|
-
throw new Error("bad point: not in prime-order subgroup");
|
|
2462
|
-
return !0;
|
|
2463
|
-
});
|
|
2464
|
-
class M {
|
|
2465
|
-
constructor(_, S, L) {
|
|
2466
|
-
if (this.px = _, this.py = S, this.pz = L, _ == null || !r.isValid(_))
|
|
2467
|
-
throw new Error("x required");
|
|
2468
|
-
if (S == null || !r.isValid(S))
|
|
2469
|
-
throw new Error("y required");
|
|
2470
|
-
if (L == null || !r.isValid(L))
|
|
2471
|
-
throw new Error("z required");
|
|
2472
|
-
Object.freeze(this);
|
|
2473
|
-
}
|
|
2474
|
-
// Does not validate if the point is on-curve.
|
|
2475
|
-
// Use fromHex instead, or call assertValidity() later.
|
|
2476
|
-
static fromAffine(_) {
|
|
2477
|
-
const { x: S, y: L } = _ || {};
|
|
2478
|
-
if (!_ || !r.isValid(S) || !r.isValid(L))
|
|
2479
|
-
throw new Error("invalid affine point");
|
|
2480
|
-
if (_ instanceof M)
|
|
2481
|
-
throw new Error("projective point not allowed");
|
|
2482
|
-
const A = (q) => r.eql(q, r.ZERO);
|
|
2483
|
-
return A(S) && A(L) ? M.ZERO : new M(S, L, r.ONE);
|
|
2484
|
-
}
|
|
2485
|
-
get x() {
|
|
2486
|
-
return this.toAffine().x;
|
|
2487
|
-
}
|
|
2488
|
-
get y() {
|
|
2489
|
-
return this.toAffine().y;
|
|
2490
|
-
}
|
|
2491
|
-
/**
|
|
2492
|
-
* Takes a bunch of Projective Points but executes only one
|
|
2493
|
-
* inversion on all of them. Inversion is very slow operation,
|
|
2494
|
-
* so this improves performance massively.
|
|
2495
|
-
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
2496
|
-
*/
|
|
2497
|
-
static normalizeZ(_) {
|
|
2498
|
-
const S = r.invertBatch(_.map((L) => L.pz));
|
|
2499
|
-
return _.map((L, A) => L.toAffine(S[A])).map(M.fromAffine);
|
|
2500
|
-
}
|
|
2501
|
-
/**
|
|
2502
|
-
* Converts hash string or Uint8Array to Point.
|
|
2503
|
-
* @param hex short/long ECDSA hex
|
|
2504
|
-
*/
|
|
2505
|
-
static fromHex(_) {
|
|
2506
|
-
const S = M.fromAffine(i(Tt("pointHex", _)));
|
|
2507
|
-
return S.assertValidity(), S;
|
|
2508
|
-
}
|
|
2509
|
-
// Multiplies generator point by privateKey.
|
|
2510
|
-
static fromPrivateKey(_) {
|
|
2511
|
-
return M.BASE.multiply(y(_));
|
|
2512
|
-
}
|
|
2513
|
-
// Multiscalar Multiplication
|
|
2514
|
-
static msm(_, S) {
|
|
2515
|
-
return Di(M, o, _, S);
|
|
2516
|
-
}
|
|
2517
|
-
// "Private method", don't use it directly
|
|
2518
|
-
_setWindowSize(_) {
|
|
2519
|
-
C.setWindowSize(this, _);
|
|
2520
|
-
}
|
|
2521
|
-
// A point on curve is valid if it conforms to equation.
|
|
2522
|
-
assertValidity() {
|
|
2523
|
-
E(this);
|
|
2524
|
-
}
|
|
2525
|
-
hasEvenY() {
|
|
2526
|
-
const { y: _ } = this.toAffine();
|
|
2527
|
-
if (r.isOdd)
|
|
2528
|
-
return !r.isOdd(_);
|
|
2529
|
-
throw new Error("Field doesn't support isOdd");
|
|
2530
|
-
}
|
|
2531
|
-
/**
|
|
2532
|
-
* Compare one point to another.
|
|
2533
|
-
*/
|
|
2534
|
-
equals(_) {
|
|
2535
|
-
x(_);
|
|
2536
|
-
const { px: S, py: L, pz: A } = this, { px: q, py: D, pz: R } = _, O = r.eql(r.mul(S, R), r.mul(q, A)), $ = r.eql(r.mul(L, R), r.mul(D, A));
|
|
2537
|
-
return O && $;
|
|
2538
|
-
}
|
|
2539
|
-
/**
|
|
2540
|
-
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
2541
|
-
*/
|
|
2542
|
-
negate() {
|
|
2543
|
-
return new M(this.px, r.neg(this.py), this.pz);
|
|
2544
|
-
}
|
|
2545
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
2546
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2547
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2548
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2549
|
-
double() {
|
|
2550
|
-
const { a: _, b: S } = e, L = r.mul(S, zn), { px: A, py: q, pz: D } = this;
|
|
2551
|
-
let R = r.ZERO, O = r.ZERO, $ = r.ZERO, P = r.mul(A, A), J = r.mul(q, q), T = r.mul(D, D), Z = r.mul(A, q);
|
|
2552
|
-
return Z = r.add(Z, Z), $ = r.mul(A, D), $ = r.add($, $), R = r.mul(_, $), O = r.mul(L, T), O = r.add(R, O), R = r.sub(J, O), O = r.add(J, O), O = r.mul(R, O), R = r.mul(Z, R), $ = r.mul(L, $), T = r.mul(_, T), Z = r.sub(P, T), Z = r.mul(_, Z), Z = r.add(Z, $), $ = r.add(P, P), P = r.add($, P), P = r.add(P, T), P = r.mul(P, Z), O = r.add(O, P), T = r.mul(q, D), T = r.add(T, T), P = r.mul(T, Z), R = r.sub(R, P), $ = r.mul(T, J), $ = r.add($, $), $ = r.add($, $), new M(R, O, $);
|
|
2553
|
-
}
|
|
2554
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
2555
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2556
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2557
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2558
|
-
add(_) {
|
|
2559
|
-
x(_);
|
|
2560
|
-
const { px: S, py: L, pz: A } = this, { px: q, py: D, pz: R } = _;
|
|
2561
|
-
let O = r.ZERO, $ = r.ZERO, P = r.ZERO;
|
|
2562
|
-
const J = e.a, T = r.mul(e.b, zn);
|
|
2563
|
-
let Z = r.mul(S, q), p = r.mul(L, D), n = r.mul(A, R), f = r.add(S, L), a = r.add(q, D);
|
|
2564
|
-
f = r.mul(f, a), a = r.add(Z, p), f = r.sub(f, a), a = r.add(S, A);
|
|
2565
|
-
let h = r.add(q, R);
|
|
2566
|
-
return a = r.mul(a, h), h = r.add(Z, n), a = r.sub(a, h), h = r.add(L, A), O = r.add(D, R), h = r.mul(h, O), O = r.add(p, n), h = r.sub(h, O), P = r.mul(J, a), O = r.mul(T, n), P = r.add(O, P), O = r.sub(p, P), P = r.add(p, P), $ = r.mul(O, P), p = r.add(Z, Z), p = r.add(p, Z), n = r.mul(J, n), a = r.mul(T, a), p = r.add(p, n), n = r.sub(Z, n), n = r.mul(J, n), a = r.add(a, n), Z = r.mul(p, a), $ = r.add($, Z), Z = r.mul(h, a), O = r.mul(f, O), O = r.sub(O, Z), Z = r.mul(f, p), P = r.mul(h, P), P = r.add(P, Z), new M(O, $, P);
|
|
2567
|
-
}
|
|
2568
|
-
subtract(_) {
|
|
2569
|
-
return this.add(_.negate());
|
|
2570
|
-
}
|
|
2571
|
-
is0() {
|
|
2572
|
-
return this.equals(M.ZERO);
|
|
2573
|
-
}
|
|
2574
|
-
wNAF(_) {
|
|
2575
|
-
return C.wNAFCached(this, _, M.normalizeZ);
|
|
2576
|
-
}
|
|
2577
|
-
/**
|
|
2578
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
2579
|
-
* It's faster, but should only be used when you don't care about
|
|
2580
|
-
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
2581
|
-
*/
|
|
2582
|
-
multiplyUnsafe(_) {
|
|
2583
|
-
Yt("scalar", _, Jt, e.n);
|
|
2584
|
-
const S = M.ZERO;
|
|
2585
|
-
if (_ === Jt)
|
|
2586
|
-
return S;
|
|
2587
|
-
if (_ === qt)
|
|
2588
|
-
return this;
|
|
2589
|
-
const { endo: L } = e;
|
|
2590
|
-
if (!L)
|
|
2591
|
-
return C.unsafeLadder(this, _);
|
|
2592
|
-
let { k1neg: A, k1: q, k2neg: D, k2: R } = L.splitScalar(_), O = S, $ = S, P = this;
|
|
2593
|
-
for (; q > Jt || R > Jt; )
|
|
2594
|
-
q & qt && (O = O.add(P)), R & qt && ($ = $.add(P)), P = P.double(), q >>= qt, R >>= qt;
|
|
2595
|
-
return A && (O = O.negate()), D && ($ = $.negate()), $ = new M(r.mul($.px, L.beta), $.py, $.pz), O.add($);
|
|
2596
|
-
}
|
|
2597
|
-
/**
|
|
2598
|
-
* Constant time multiplication.
|
|
2599
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
2600
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
2601
|
-
* Uses precomputes when available.
|
|
2602
|
-
* Uses endomorphism for Koblitz curves.
|
|
2603
|
-
* @param scalar by which the point would be multiplied
|
|
2604
|
-
* @returns New point
|
|
2605
|
-
*/
|
|
2606
|
-
multiply(_) {
|
|
2607
|
-
const { endo: S, n: L } = e;
|
|
2608
|
-
Yt("scalar", _, qt, L);
|
|
2609
|
-
let A, q;
|
|
2610
|
-
if (S) {
|
|
2611
|
-
const { k1neg: D, k1: R, k2neg: O, k2: $ } = S.splitScalar(_);
|
|
2612
|
-
let { p: P, f: J } = this.wNAF(R), { p: T, f: Z } = this.wNAF($);
|
|
2613
|
-
P = C.constTimeNegate(D, P), T = C.constTimeNegate(O, T), T = new M(r.mul(T.px, S.beta), T.py, T.pz), A = P.add(T), q = J.add(Z);
|
|
2614
|
-
} else {
|
|
2615
|
-
const { p: D, f: R } = this.wNAF(_);
|
|
2616
|
-
A = D, q = R;
|
|
2617
|
-
}
|
|
2618
|
-
return M.normalizeZ([A, q])[0];
|
|
2619
|
-
}
|
|
2620
|
-
/**
|
|
2621
|
-
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
2622
|
-
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
2623
|
-
* The trick could be useful if both P and Q are not G (not in our case).
|
|
2624
|
-
* @returns non-zero affine point
|
|
2625
|
-
*/
|
|
2626
|
-
multiplyAndAddUnsafe(_, S, L) {
|
|
2627
|
-
const A = M.BASE, q = (R, O) => O === Jt || O === qt || !R.equals(A) ? R.multiplyUnsafe(O) : R.multiply(O), D = q(this, S).add(q(_, L));
|
|
2628
|
-
return D.is0() ? void 0 : D;
|
|
2629
|
-
}
|
|
2630
|
-
// Converts Projective point to affine (x, y) coordinates.
|
|
2631
|
-
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
2632
|
-
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
2633
|
-
toAffine(_) {
|
|
2634
|
-
return v(this, _);
|
|
2635
|
-
}
|
|
2636
|
-
isTorsionFree() {
|
|
2637
|
-
const { h: _, isTorsionFree: S } = e;
|
|
2638
|
-
if (_ === qt)
|
|
2639
|
-
return !0;
|
|
2640
|
-
if (S)
|
|
2641
|
-
return S(M, this);
|
|
2642
|
-
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
2643
|
-
}
|
|
2644
|
-
clearCofactor() {
|
|
2645
|
-
const { h: _, clearCofactor: S } = e;
|
|
2646
|
-
return _ === qt ? this : S ? S(M, this) : this.multiplyUnsafe(e.h);
|
|
2647
|
-
}
|
|
2648
|
-
toRawBytes(_ = !0) {
|
|
2649
|
-
return Qt("isCompressed", _), this.assertValidity(), c(M, this, _);
|
|
2650
|
-
}
|
|
2651
|
-
toHex(_ = !0) {
|
|
2652
|
-
return Qt("isCompressed", _), fe(this.toRawBytes(_));
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
M.BASE = new M(e.Gx, e.Gy, r.ONE), M.ZERO = new M(r.ZERO, r.ONE, r.ZERO);
|
|
2656
|
-
const U = e.nBitLength, C = Zi(M, e.endo ? Math.ceil(U / 2) : U);
|
|
2657
|
-
return {
|
|
2658
|
-
CURVE: e,
|
|
2659
|
-
ProjectivePoint: M,
|
|
2660
|
-
normPrivateKeyToScalar: y,
|
|
2661
|
-
weierstrassEquation: w,
|
|
2662
|
-
isWithinCurveOrder: d
|
|
2663
|
-
};
|
|
2664
|
-
}
|
|
2665
|
-
function kf(t) {
|
|
2666
|
-
const e = un(t);
|
|
2667
|
-
return xe(e, {
|
|
2668
|
-
hash: "hash",
|
|
2669
|
-
hmac: "function",
|
|
2670
|
-
randomBytes: "function"
|
|
2671
|
-
}, {
|
|
2672
|
-
bits2int: "function",
|
|
2673
|
-
bits2int_modN: "function",
|
|
2674
|
-
lowS: "boolean"
|
|
2675
|
-
}), Object.freeze({ lowS: !0, ...e });
|
|
2676
|
-
}
|
|
2677
|
-
function Uf(t) {
|
|
2678
|
-
const e = kf(t), { Fp: r, n: o } = e, c = r.BYTES + 1, i = 2 * r.BYTES + 1;
|
|
2679
|
-
function w(n) {
|
|
2680
|
-
return tt(n, o);
|
|
2681
|
-
}
|
|
2682
|
-
function d(n) {
|
|
2683
|
-
return Kr(n, o);
|
|
2684
|
-
}
|
|
2685
|
-
const { ProjectivePoint: y, normPrivateKeyToScalar: x, weierstrassEquation: v, isWithinCurveOrder: E } = If({
|
|
2686
|
-
...e,
|
|
2687
|
-
toBytes(n, f, a) {
|
|
2688
|
-
const h = f.toAffine(), l = r.toBytes(h.x), m = ae;
|
|
2689
|
-
return Qt("isCompressed", a), a ? m(Uint8Array.from([f.hasEvenY() ? 2 : 3]), l) : m(Uint8Array.from([4]), l, r.toBytes(h.y));
|
|
2690
|
-
},
|
|
2691
|
-
fromBytes(n) {
|
|
2692
|
-
const f = n.length, a = n[0], h = n.subarray(1);
|
|
2693
|
-
if (f === c && (a === 2 || a === 3)) {
|
|
2694
|
-
const l = ie(h);
|
|
2695
|
-
if (!sr(l, qt, r.ORDER))
|
|
2696
|
-
throw new Error("Point is not on curve");
|
|
2697
|
-
const m = v(l);
|
|
2698
|
-
let b;
|
|
2699
|
-
try {
|
|
2700
|
-
b = r.sqrt(m);
|
|
2701
|
-
} catch (g) {
|
|
2702
|
-
const B = g instanceof Error ? ": " + g.message : "";
|
|
2703
|
-
throw new Error("Point is not on curve" + B);
|
|
2704
|
-
}
|
|
2705
|
-
const u = (b & qt) === qt;
|
|
2706
|
-
return (a & 1) === 1 !== u && (b = r.neg(b)), { x: l, y: b };
|
|
2707
|
-
} else if (f === i && a === 4) {
|
|
2708
|
-
const l = r.fromBytes(h.subarray(0, r.BYTES)), m = r.fromBytes(h.subarray(r.BYTES, 2 * r.BYTES));
|
|
2709
|
-
return { x: l, y: m };
|
|
2710
|
-
} else
|
|
2711
|
-
throw new Error(`Point of length ${f} was invalid. Expected ${c} compressed bytes or ${i} uncompressed bytes`);
|
|
2712
|
-
}
|
|
2713
|
-
}), M = (n) => fe(ve(n, e.nByteLength));
|
|
2714
|
-
function U(n) {
|
|
2715
|
-
const f = o >> qt;
|
|
2716
|
-
return n > f;
|
|
2717
|
-
}
|
|
2718
|
-
function C(n) {
|
|
2719
|
-
return U(n) ? w(-n) : n;
|
|
2720
|
-
}
|
|
2721
|
-
const k = (n, f, a) => ie(n.slice(f, a));
|
|
2722
|
-
class _ {
|
|
2723
|
-
constructor(f, a, h) {
|
|
2724
|
-
this.r = f, this.s = a, this.recovery = h, this.assertValidity();
|
|
2725
|
-
}
|
|
2726
|
-
// pair (bytes of r, bytes of s)
|
|
2727
|
-
static fromCompact(f) {
|
|
2728
|
-
const a = e.nByteLength;
|
|
2729
|
-
return f = Tt("compactSignature", f, a * 2), new _(k(f, 0, a), k(f, a, 2 * a));
|
|
2730
|
-
}
|
|
2731
|
-
// DER encoded ECDSA signature
|
|
2732
|
-
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
2733
|
-
static fromDER(f) {
|
|
2734
|
-
const { r: a, s: h } = Wt.toSig(Tt("DER", f));
|
|
2735
|
-
return new _(a, h);
|
|
2736
|
-
}
|
|
2737
|
-
assertValidity() {
|
|
2738
|
-
Yt("r", this.r, qt, o), Yt("s", this.s, qt, o);
|
|
2739
|
-
}
|
|
2740
|
-
addRecoveryBit(f) {
|
|
2741
|
-
return new _(this.r, this.s, f);
|
|
2742
|
-
}
|
|
2743
|
-
recoverPublicKey(f) {
|
|
2744
|
-
const { r: a, s: h, recovery: l } = this, m = R(Tt("msgHash", f));
|
|
2745
|
-
if (l == null || ![0, 1, 2, 3].includes(l))
|
|
2746
|
-
throw new Error("recovery id invalid");
|
|
2747
|
-
const b = l === 2 || l === 3 ? a + e.n : a;
|
|
2748
|
-
if (b >= r.ORDER)
|
|
2749
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
2750
|
-
const u = l & 1 ? "03" : "02", s = y.fromHex(u + M(b)), g = d(b), B = w(-m * g), I = w(h * g), N = y.BASE.multiplyAndAddUnsafe(s, B, I);
|
|
2751
|
-
if (!N)
|
|
2752
|
-
throw new Error("point at infinify");
|
|
2753
|
-
return N.assertValidity(), N;
|
|
2754
|
-
}
|
|
2755
|
-
// Signatures should be low-s, to prevent malleability.
|
|
2756
|
-
hasHighS() {
|
|
2757
|
-
return U(this.s);
|
|
2758
|
-
}
|
|
2759
|
-
normalizeS() {
|
|
2760
|
-
return this.hasHighS() ? new _(this.r, w(-this.s), this.recovery) : this;
|
|
2761
|
-
}
|
|
2762
|
-
// DER-encoded
|
|
2763
|
-
toDERRawBytes() {
|
|
2764
|
-
return ye(this.toDERHex());
|
|
2765
|
-
}
|
|
2766
|
-
toDERHex() {
|
|
2767
|
-
return Wt.hexFromSig({ r: this.r, s: this.s });
|
|
2768
|
-
}
|
|
2769
|
-
// padded bytes of r, then padded bytes of s
|
|
2770
|
-
toCompactRawBytes() {
|
|
2771
|
-
return ye(this.toCompactHex());
|
|
2772
|
-
}
|
|
2773
|
-
toCompactHex() {
|
|
2774
|
-
return M(this.r) + M(this.s);
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
const S = {
|
|
2778
|
-
isValidPrivateKey(n) {
|
|
2779
|
-
try {
|
|
2780
|
-
return x(n), !0;
|
|
2781
|
-
} catch {
|
|
2782
|
-
return !1;
|
|
2783
|
-
}
|
|
2784
|
-
},
|
|
2785
|
-
normPrivateKeyToScalar: x,
|
|
2786
|
-
/**
|
|
2787
|
-
* Produces cryptographically secure private key from random of size
|
|
2788
|
-
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
2789
|
-
*/
|
|
2790
|
-
randomPrivateKey: () => {
|
|
2791
|
-
const n = Ci(e.n);
|
|
2792
|
-
return Mf(e.randomBytes(n), e.n);
|
|
2793
|
-
},
|
|
2794
|
-
/**
|
|
2795
|
-
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
2796
|
-
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
2797
|
-
* @returns cached point
|
|
2798
|
-
* @example
|
|
2799
|
-
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
2800
|
-
* fast.multiply(privKey); // much faster ECDH now
|
|
2801
|
-
*/
|
|
2802
|
-
precompute(n = 8, f = y.BASE) {
|
|
2803
|
-
return f._setWindowSize(n), f.multiply(BigInt(3)), f;
|
|
2804
|
-
}
|
|
2805
|
-
};
|
|
2806
|
-
function L(n, f = !0) {
|
|
2807
|
-
return y.fromPrivateKey(n).toRawBytes(f);
|
|
2808
|
-
}
|
|
2809
|
-
function A(n) {
|
|
2810
|
-
const f = se(n), a = typeof n == "string", h = (f || a) && n.length;
|
|
2811
|
-
return f ? h === c || h === i : a ? h === 2 * c || h === 2 * i : n instanceof y;
|
|
2812
|
-
}
|
|
2813
|
-
function q(n, f, a = !0) {
|
|
2814
|
-
if (A(n))
|
|
2815
|
-
throw new Error("first arg must be private key");
|
|
2816
|
-
if (!A(f))
|
|
2817
|
-
throw new Error("second arg must be public key");
|
|
2818
|
-
return y.fromHex(f).multiply(x(n)).toRawBytes(a);
|
|
2819
|
-
}
|
|
2820
|
-
const D = e.bits2int || function(n) {
|
|
2821
|
-
const f = ie(n), a = n.length * 8 - e.nBitLength;
|
|
2822
|
-
return a > 0 ? f >> BigInt(a) : f;
|
|
2823
|
-
}, R = e.bits2int_modN || function(n) {
|
|
2824
|
-
return w(D(n));
|
|
2825
|
-
}, O = ln(e.nBitLength);
|
|
2826
|
-
function $(n) {
|
|
2827
|
-
return Yt(`num < 2^${e.nBitLength}`, n, Jt, O), ve(n, e.nByteLength);
|
|
2828
|
-
}
|
|
2829
|
-
function P(n, f, a = J) {
|
|
2830
|
-
if (["recovered", "canonical"].some((H) => H in a))
|
|
2831
|
-
throw new Error("sign() legacy options not supported");
|
|
2832
|
-
const { hash: h, randomBytes: l } = e;
|
|
2833
|
-
let { lowS: m, prehash: b, extraEntropy: u } = a;
|
|
2834
|
-
m == null && (m = !0), n = Tt("msgHash", n), Vn(a), b && (n = Tt("prehashed msgHash", h(n)));
|
|
2835
|
-
const s = R(n), g = x(f), B = [$(g), $(s)];
|
|
2836
|
-
if (u != null && u !== !1) {
|
|
2837
|
-
const H = u === !0 ? l(r.BYTES) : u;
|
|
2838
|
-
B.push(Tt("extraEntropy", H));
|
|
2839
|
-
}
|
|
2840
|
-
const I = ae(...B), N = s;
|
|
2841
|
-
function j(H) {
|
|
2842
|
-
const z = D(H);
|
|
2843
|
-
if (!E(z))
|
|
2844
|
-
return;
|
|
2845
|
-
const $t = d(z), X = y.BASE.multiply(z).toAffine(), Y = w(X.x);
|
|
2846
|
-
if (Y === Jt)
|
|
2847
|
-
return;
|
|
2848
|
-
const Zt = w($t * w(N + Y * g));
|
|
2849
|
-
if (Zt === Jt)
|
|
2850
|
-
return;
|
|
2851
|
-
let Q = (X.x === Y ? 0 : 2) | Number(X.y & qt), F = Zt;
|
|
2852
|
-
return m && U(Zt) && (F = C(Zt), Q ^= 1), new _(Y, F, Q);
|
|
2853
|
-
}
|
|
2854
|
-
return { seed: I, k2sig: j };
|
|
2855
|
-
}
|
|
2856
|
-
const J = { lowS: e.lowS, prehash: !1 }, T = { lowS: e.lowS, prehash: !1 };
|
|
2857
|
-
function Z(n, f, a = J) {
|
|
2858
|
-
const { seed: h, k2sig: l } = P(n, f, a), m = e;
|
|
2859
|
-
return $i(m.hash.outputLen, m.nByteLength, m.hmac)(h, l);
|
|
2860
|
-
}
|
|
2861
|
-
y.BASE._setWindowSize(8);
|
|
2862
|
-
function p(n, f, a, h = T) {
|
|
2863
|
-
var X;
|
|
2864
|
-
const l = n;
|
|
2865
|
-
if (f = Tt("msgHash", f), a = Tt("publicKey", a), "strict" in h)
|
|
2866
|
-
throw new Error("options.strict was renamed to lowS");
|
|
2867
|
-
Vn(h);
|
|
2868
|
-
const { lowS: m, prehash: b } = h;
|
|
2869
|
-
let u, s;
|
|
2870
|
-
try {
|
|
2871
|
-
if (typeof l == "string" || se(l))
|
|
2872
|
-
try {
|
|
2873
|
-
u = _.fromDER(l);
|
|
2874
|
-
} catch (Y) {
|
|
2875
|
-
if (!(Y instanceof Wt.Err))
|
|
2876
|
-
throw Y;
|
|
2877
|
-
u = _.fromCompact(l);
|
|
2878
|
-
}
|
|
2879
|
-
else if (typeof l == "object" && typeof l.r == "bigint" && typeof l.s == "bigint") {
|
|
2880
|
-
const { r: Y, s: Zt } = l;
|
|
2881
|
-
u = new _(Y, Zt);
|
|
2882
|
-
} else
|
|
2883
|
-
throw new Error("PARSE");
|
|
2884
|
-
s = y.fromHex(a);
|
|
2885
|
-
} catch (Y) {
|
|
2886
|
-
if (Y.message === "PARSE")
|
|
2887
|
-
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
2888
|
-
return !1;
|
|
2889
|
-
}
|
|
2890
|
-
if (m && u.hasHighS())
|
|
2891
|
-
return !1;
|
|
2892
|
-
b && (f = e.hash(f));
|
|
2893
|
-
const { r: g, s: B } = u, I = R(f), N = d(B), j = w(I * N), H = w(g * N), z = (X = y.BASE.multiplyAndAddUnsafe(s, j, H)) == null ? void 0 : X.toAffine();
|
|
2894
|
-
return z ? w(z.x) === g : !1;
|
|
2895
|
-
}
|
|
2896
|
-
return {
|
|
2897
|
-
CURVE: e,
|
|
2898
|
-
getPublicKey: L,
|
|
2899
|
-
getSharedSecret: q,
|
|
2900
|
-
sign: Z,
|
|
2901
|
-
verify: p,
|
|
2902
|
-
ProjectivePoint: y,
|
|
2903
|
-
Signature: _,
|
|
2904
|
-
utils: S
|
|
2905
|
-
};
|
|
2906
|
-
}
|
|
2907
|
-
function Nf(t) {
|
|
2908
|
-
return {
|
|
2909
|
-
hash: t,
|
|
2910
|
-
hmac: (e, ...r) => li(t, e, po(...r)),
|
|
2911
|
-
randomBytes: ci
|
|
2912
|
-
};
|
|
2913
|
-
}
|
|
2914
|
-
function Rf(t, e) {
|
|
2915
|
-
const r = (o) => Uf({ ...t, ...Nf(o) });
|
|
2916
|
-
return Object.freeze({ ...r(e), create: r });
|
|
2917
|
-
}
|
|
2918
|
-
const Hi = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), Yn = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), Of = BigInt(1), Gr = BigInt(2), Xn = (t, e) => (t + e / Gr) / e;
|
|
2919
|
-
function Lf(t) {
|
|
2920
|
-
const e = Hi, r = BigInt(3), o = BigInt(6), c = BigInt(11), i = BigInt(22), w = BigInt(23), d = BigInt(44), y = BigInt(88), x = t * t * t % e, v = x * x * t % e, E = ut(v, r, e) * v % e, M = ut(E, r, e) * v % e, U = ut(M, Gr, e) * x % e, C = ut(U, c, e) * U % e, k = ut(C, i, e) * C % e, _ = ut(k, d, e) * k % e, S = ut(_, y, e) * _ % e, L = ut(S, d, e) * k % e, A = ut(L, r, e) * v % e, q = ut(A, w, e) * C % e, D = ut(q, o, e) * x % e, R = ut(D, Gr, e);
|
|
2921
|
-
if (!Wr.eql(Wr.sqr(R), t))
|
|
2922
|
-
throw new Error("Cannot find square root");
|
|
2923
|
-
return R;
|
|
2924
|
-
}
|
|
2925
|
-
const Wr = fr(Hi, void 0, void 0, { sqrt: Lf }), Te = Rf({
|
|
2926
|
-
a: BigInt(0),
|
|
2927
|
-
// equation params: a, b
|
|
2928
|
-
b: BigInt(7),
|
|
2929
|
-
// Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
|
|
2930
|
-
Fp: Wr,
|
|
2931
|
-
// Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
|
2932
|
-
n: Yn,
|
|
2933
|
-
// Curve order, total count of valid points in the field
|
|
2934
|
-
// Base point (x, y) aka generator point
|
|
2935
|
-
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
2936
|
-
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
|
2937
|
-
h: BigInt(1),
|
|
2938
|
-
// Cofactor
|
|
2939
|
-
lowS: !0,
|
|
2940
|
-
// Allow only low-S signatures by default in sign() and verify()
|
|
2941
|
-
/**
|
|
2942
|
-
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
|
2943
|
-
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
|
2944
|
-
* For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
2945
|
-
* Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
2946
|
-
*/
|
|
2947
|
-
endo: {
|
|
2948
|
-
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
2949
|
-
splitScalar: (t) => {
|
|
2950
|
-
const e = Yn, r = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), o = -Of * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), c = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), i = r, w = BigInt("0x100000000000000000000000000000000"), d = Xn(i * t, e), y = Xn(-o * t, e);
|
|
2951
|
-
let x = tt(t - d * r - y * c, e), v = tt(-d * o - y * i, e);
|
|
2952
|
-
const E = x > w, M = v > w;
|
|
2953
|
-
if (E && (x = e - x), M && (v = e - v), x > w || v > w)
|
|
2954
|
-
throw new Error("splitScalar: Endomorphism failed, k=" + t);
|
|
2955
|
-
return { k1neg: E, k1: x, k2neg: M, k2: v };
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
}, rr);
|
|
2959
|
-
BigInt(0);
|
|
2960
|
-
function be(t, e) {
|
|
2961
|
-
if (t.length !== 32)
|
|
2962
|
-
throw new Error("Expected valid 32-byte private key as a seed");
|
|
2963
|
-
if (!Ht || !e && Vt()) {
|
|
2964
|
-
const r = Ao(t), o = r.slice(32);
|
|
2965
|
-
if (bi(o))
|
|
2966
|
-
throw new Error("Invalid publicKey generated from WASM interface");
|
|
2967
|
-
return {
|
|
2968
|
-
publicKey: o,
|
|
2969
|
-
secretKey: r.slice(0, 32)
|
|
2970
|
-
};
|
|
2971
|
-
}
|
|
2972
|
-
return {
|
|
2973
|
-
publicKey: Te.getPublicKey(t, !0),
|
|
2974
|
-
secretKey: t
|
|
2975
|
-
};
|
|
2976
|
-
}
|
|
2977
|
-
function Vi(t, e) {
|
|
2978
|
-
return (r, { chainCode: o, isHard: c }) => {
|
|
2979
|
-
if (!c)
|
|
2980
|
-
throw new Error("A soft key was found in the path and is not supported");
|
|
2981
|
-
return t(e(r.secretKey.subarray(0, 32), o));
|
|
2982
|
-
};
|
|
2983
|
-
}
|
|
2984
|
-
const jn = /* @__PURE__ */ Vi(be, rf), Tf = sn(ee("Ed25519HDKD"));
|
|
2985
|
-
function $f(t, e) {
|
|
2986
|
-
if (!oe(e) || e.length !== 32)
|
|
2987
|
-
throw new Error("Invalid chainCode passed to derive");
|
|
2988
|
-
return he(Ct(Tf, t, e));
|
|
2989
|
-
}
|
|
2990
|
-
const Xt = BigInt(0), Dt = BigInt(1), Ze = BigInt(2), qf = BigInt(8), Pf = { zip215: !0 };
|
|
2991
|
-
function Cf(t) {
|
|
2992
|
-
const e = un(t);
|
|
2993
|
-
return xe(t, {
|
|
2994
|
-
hash: "function",
|
|
2995
|
-
a: "bigint",
|
|
2996
|
-
d: "bigint",
|
|
2997
|
-
randomBytes: "function"
|
|
2998
|
-
}, {
|
|
2999
|
-
adjustScalarBytes: "function",
|
|
3000
|
-
domain: "function",
|
|
3001
|
-
uvRatio: "function",
|
|
3002
|
-
mapToCurve: "function"
|
|
3003
|
-
}), Object.freeze({ ...e });
|
|
3004
|
-
}
|
|
3005
|
-
function Zf(t) {
|
|
3006
|
-
const e = Cf(t), { Fp: r, n: o, prehash: c, hash: i, randomBytes: w, nByteLength: d, h: y } = e, x = Ze << BigInt(d * 8) - Dt, v = r.create, E = fr(e.n, e.nBitLength), M = e.uvRatio || ((a, h) => {
|
|
3007
|
-
try {
|
|
3008
|
-
return { isValid: !0, value: r.sqrt(a * r.inv(h)) };
|
|
3009
|
-
} catch {
|
|
3010
|
-
return { isValid: !1, value: Xt };
|
|
3011
|
-
}
|
|
3012
|
-
}), U = e.adjustScalarBytes || ((a) => a), C = e.domain || ((a, h, l) => {
|
|
3013
|
-
if (Qt("phflag", l), h.length || l)
|
|
3014
|
-
throw new Error("Contexts/pre-hash are not supported");
|
|
3015
|
-
return a;
|
|
3016
|
-
});
|
|
3017
|
-
function k(a, h) {
|
|
3018
|
-
Yt("coordinate " + a, h, Xt, x);
|
|
3019
|
-
}
|
|
3020
|
-
function _(a) {
|
|
3021
|
-
if (!(a instanceof A))
|
|
3022
|
-
throw new Error("ExtendedPoint expected");
|
|
3023
|
-
}
|
|
3024
|
-
const S = Ne((a, h) => {
|
|
3025
|
-
const { ex: l, ey: m, ez: b } = a, u = a.is0();
|
|
3026
|
-
h == null && (h = u ? qf : r.inv(b));
|
|
3027
|
-
const s = v(l * h), g = v(m * h), B = v(b * h);
|
|
3028
|
-
if (u)
|
|
3029
|
-
return { x: Xt, y: Dt };
|
|
3030
|
-
if (B !== Dt)
|
|
3031
|
-
throw new Error("invZ was invalid");
|
|
3032
|
-
return { x: s, y: g };
|
|
3033
|
-
}), L = Ne((a) => {
|
|
3034
|
-
const { a: h, d: l } = e;
|
|
3035
|
-
if (a.is0())
|
|
3036
|
-
throw new Error("bad point: ZERO");
|
|
3037
|
-
const { ex: m, ey: b, ez: u, et: s } = a, g = v(m * m), B = v(b * b), I = v(u * u), N = v(I * I), j = v(g * h), H = v(I * v(j + B)), z = v(N + v(l * v(g * B)));
|
|
3038
|
-
if (H !== z)
|
|
3039
|
-
throw new Error("bad point: equation left != right (1)");
|
|
3040
|
-
const $t = v(m * b), X = v(u * s);
|
|
3041
|
-
if ($t !== X)
|
|
3042
|
-
throw new Error("bad point: equation left != right (2)");
|
|
3043
|
-
return !0;
|
|
3044
|
-
});
|
|
3045
|
-
class A {
|
|
3046
|
-
constructor(h, l, m, b) {
|
|
3047
|
-
this.ex = h, this.ey = l, this.ez = m, this.et = b, k("x", h), k("y", l), k("z", m), k("t", b), Object.freeze(this);
|
|
3048
|
-
}
|
|
3049
|
-
get x() {
|
|
3050
|
-
return this.toAffine().x;
|
|
3051
|
-
}
|
|
3052
|
-
get y() {
|
|
3053
|
-
return this.toAffine().y;
|
|
3054
|
-
}
|
|
3055
|
-
static fromAffine(h) {
|
|
3056
|
-
if (h instanceof A)
|
|
3057
|
-
throw new Error("extended point not allowed");
|
|
3058
|
-
const { x: l, y: m } = h || {};
|
|
3059
|
-
return k("x", l), k("y", m), new A(l, m, Dt, v(l * m));
|
|
3060
|
-
}
|
|
3061
|
-
static normalizeZ(h) {
|
|
3062
|
-
const l = r.invertBatch(h.map((m) => m.ez));
|
|
3063
|
-
return h.map((m, b) => m.toAffine(l[b])).map(A.fromAffine);
|
|
3064
|
-
}
|
|
3065
|
-
// Multiscalar Multiplication
|
|
3066
|
-
static msm(h, l) {
|
|
3067
|
-
return Di(A, E, h, l);
|
|
3068
|
-
}
|
|
3069
|
-
// "Private method", don't use it directly
|
|
3070
|
-
_setWindowSize(h) {
|
|
3071
|
-
R.setWindowSize(this, h);
|
|
3072
|
-
}
|
|
3073
|
-
// Not required for fromHex(), which always creates valid points.
|
|
3074
|
-
// Could be useful for fromAffine().
|
|
3075
|
-
assertValidity() {
|
|
3076
|
-
L(this);
|
|
3077
|
-
}
|
|
3078
|
-
// Compare one point to another.
|
|
3079
|
-
equals(h) {
|
|
3080
|
-
_(h);
|
|
3081
|
-
const { ex: l, ey: m, ez: b } = this, { ex: u, ey: s, ez: g } = h, B = v(l * g), I = v(u * b), N = v(m * g), j = v(s * b);
|
|
3082
|
-
return B === I && N === j;
|
|
3083
|
-
}
|
|
3084
|
-
is0() {
|
|
3085
|
-
return this.equals(A.ZERO);
|
|
3086
|
-
}
|
|
3087
|
-
negate() {
|
|
3088
|
-
return new A(v(-this.ex), this.ey, this.ez, v(-this.et));
|
|
3089
|
-
}
|
|
3090
|
-
// Fast algo for doubling Extended Point.
|
|
3091
|
-
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
3092
|
-
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
3093
|
-
double() {
|
|
3094
|
-
const { a: h } = e, { ex: l, ey: m, ez: b } = this, u = v(l * l), s = v(m * m), g = v(Ze * v(b * b)), B = v(h * u), I = l + m, N = v(v(I * I) - u - s), j = B + s, H = j - g, z = B - s, $t = v(N * H), X = v(j * z), Y = v(N * z), Zt = v(H * j);
|
|
3095
|
-
return new A($t, X, Zt, Y);
|
|
3096
|
-
}
|
|
3097
|
-
// Fast algo for adding 2 Extended Points.
|
|
3098
|
-
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
3099
|
-
// Cost: 9M + 1*a + 1*d + 7add.
|
|
3100
|
-
add(h) {
|
|
3101
|
-
_(h);
|
|
3102
|
-
const { a: l, d: m } = e, { ex: b, ey: u, ez: s, et: g } = this, { ex: B, ey: I, ez: N, et: j } = h;
|
|
3103
|
-
if (l === BigInt(-1)) {
|
|
3104
|
-
const et = v((u - b) * (I + B)), rt = v((u + b) * (I - B)), ce = v(rt - et);
|
|
3105
|
-
if (ce === Xt)
|
|
3106
|
-
return this.double();
|
|
3107
|
-
const nt = v(s * Ze * j), it = v(g * Ze * N), Ee = it + nt, ot = rt + et, st = it - nt, Pe = v(Ee * ce), ct = v(ot * st), lt = v(Ee * st), Ce = v(ce * ot);
|
|
3108
|
-
return new A(Pe, ct, Ce, lt);
|
|
3109
|
-
}
|
|
3110
|
-
const H = v(b * B), z = v(u * I), $t = v(g * m * j), X = v(s * N), Y = v((b + u) * (B + I) - H - z), Zt = X - $t, Q = X + $t, F = v(z - l * H), $e = v(Y * Zt), at = v(Q * F), ht = v(Y * F), qe = v(Zt * Q);
|
|
3111
|
-
return new A($e, at, qe, ht);
|
|
3112
|
-
}
|
|
3113
|
-
subtract(h) {
|
|
3114
|
-
return this.add(h.negate());
|
|
3115
|
-
}
|
|
3116
|
-
wNAF(h) {
|
|
3117
|
-
return R.wNAFCached(this, h, A.normalizeZ);
|
|
3118
|
-
}
|
|
3119
|
-
// Constant-time multiplication.
|
|
3120
|
-
multiply(h) {
|
|
3121
|
-
const l = h;
|
|
3122
|
-
Yt("scalar", l, Dt, o);
|
|
3123
|
-
const { p: m, f: b } = this.wNAF(l);
|
|
3124
|
-
return A.normalizeZ([m, b])[0];
|
|
3125
|
-
}
|
|
3126
|
-
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
3127
|
-
// It's faster, but should only be used when you don't care about
|
|
3128
|
-
// an exposed private key e.g. sig verification.
|
|
3129
|
-
// Does NOT allow scalars higher than CURVE.n.
|
|
3130
|
-
multiplyUnsafe(h) {
|
|
3131
|
-
const l = h;
|
|
3132
|
-
return Yt("scalar", l, Xt, o), l === Xt ? D : this.equals(D) || l === Dt ? this : this.equals(q) ? this.wNAF(l).p : R.unsafeLadder(this, l);
|
|
3133
|
-
}
|
|
3134
|
-
// Checks if point is of small order.
|
|
3135
|
-
// If you add something to small order point, you will have "dirty"
|
|
3136
|
-
// point with torsion component.
|
|
3137
|
-
// Multiplies point by cofactor and checks if the result is 0.
|
|
3138
|
-
isSmallOrder() {
|
|
3139
|
-
return this.multiplyUnsafe(y).is0();
|
|
3140
|
-
}
|
|
3141
|
-
// Multiplies point by curve order and checks if the result is 0.
|
|
3142
|
-
// Returns `false` is the point is dirty.
|
|
3143
|
-
isTorsionFree() {
|
|
3144
|
-
return R.unsafeLadder(this, o).is0();
|
|
3145
|
-
}
|
|
3146
|
-
// Converts Extended point to default (x, y) coordinates.
|
|
3147
|
-
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
3148
|
-
toAffine(h) {
|
|
3149
|
-
return S(this, h);
|
|
3150
|
-
}
|
|
3151
|
-
clearCofactor() {
|
|
3152
|
-
const { h } = e;
|
|
3153
|
-
return h === Dt ? this : this.multiplyUnsafe(h);
|
|
3154
|
-
}
|
|
3155
|
-
// Converts hash string or Uint8Array to Point.
|
|
3156
|
-
// Uses algo from RFC8032 5.1.3.
|
|
3157
|
-
static fromHex(h, l = !1) {
|
|
3158
|
-
const { d: m, a: b } = e, u = r.BYTES;
|
|
3159
|
-
h = Tt("pointHex", h, u), Qt("zip215", l);
|
|
3160
|
-
const s = h.slice(), g = h[u - 1];
|
|
3161
|
-
s[u - 1] = g & -129;
|
|
3162
|
-
const B = me(s), I = l ? x : r.ORDER;
|
|
3163
|
-
Yt("pointHex.y", B, Xt, I);
|
|
3164
|
-
const N = v(B * B), j = v(N - Dt), H = v(m * N - b);
|
|
3165
|
-
let { isValid: z, value: $t } = M(j, H);
|
|
3166
|
-
if (!z)
|
|
3167
|
-
throw new Error("Point.fromHex: invalid y coordinate");
|
|
3168
|
-
const X = ($t & Dt) === Dt, Y = (g & 128) !== 0;
|
|
3169
|
-
if (!l && $t === Xt && Y)
|
|
3170
|
-
throw new Error("Point.fromHex: x=0 and x_0=1");
|
|
3171
|
-
return Y !== X && ($t = v(-$t)), A.fromAffine({ x: $t, y: B });
|
|
3172
|
-
}
|
|
3173
|
-
static fromPrivateKey(h) {
|
|
3174
|
-
return P(h).point;
|
|
3175
|
-
}
|
|
3176
|
-
toRawBytes() {
|
|
3177
|
-
const { x: h, y: l } = this.toAffine(), m = Ue(l, r.BYTES);
|
|
3178
|
-
return m[m.length - 1] |= h & Dt ? 128 : 0, m;
|
|
3179
|
-
}
|
|
3180
|
-
toHex() {
|
|
3181
|
-
return fe(this.toRawBytes());
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
A.BASE = new A(e.Gx, e.Gy, Dt, v(e.Gx * e.Gy)), A.ZERO = new A(Xt, Dt, Dt, Xt);
|
|
3185
|
-
const { BASE: q, ZERO: D } = A, R = Zi(A, d * 8);
|
|
3186
|
-
function O(a) {
|
|
3187
|
-
return tt(a, o);
|
|
3188
|
-
}
|
|
3189
|
-
function $(a) {
|
|
3190
|
-
return O(me(a));
|
|
3191
|
-
}
|
|
3192
|
-
function P(a) {
|
|
3193
|
-
const h = d;
|
|
3194
|
-
a = Tt("private key", a, h);
|
|
3195
|
-
const l = Tt("hashed private key", i(a), 2 * h), m = U(l.slice(0, h)), b = l.slice(h, 2 * h), u = $(m), s = q.multiply(u), g = s.toRawBytes();
|
|
3196
|
-
return { head: m, prefix: b, scalar: u, point: s, pointBytes: g };
|
|
3197
|
-
}
|
|
3198
|
-
function J(a) {
|
|
3199
|
-
return P(a).pointBytes;
|
|
3200
|
-
}
|
|
3201
|
-
function T(a = new Uint8Array(), ...h) {
|
|
3202
|
-
const l = ae(...h);
|
|
3203
|
-
return $(i(C(l, Tt("context", a), !!c)));
|
|
3204
|
-
}
|
|
3205
|
-
function Z(a, h, l = {}) {
|
|
3206
|
-
a = Tt("message", a), c && (a = c(a));
|
|
3207
|
-
const { prefix: m, scalar: b, pointBytes: u } = P(h), s = T(l.context, m, a), g = q.multiply(s).toRawBytes(), B = T(l.context, g, u, a), I = O(s + B * b);
|
|
3208
|
-
Yt("signature.s", I, Xt, o);
|
|
3209
|
-
const N = ae(g, Ue(I, r.BYTES));
|
|
3210
|
-
return Tt("result", N, d * 2);
|
|
3211
|
-
}
|
|
3212
|
-
const p = Pf;
|
|
3213
|
-
function n(a, h, l, m = p) {
|
|
3214
|
-
const { context: b, zip215: u } = m, s = r.BYTES;
|
|
3215
|
-
a = Tt("signature", a, 2 * s), h = Tt("message", h), u !== void 0 && Qt("zip215", u), c && (h = c(h));
|
|
3216
|
-
const g = me(a.slice(s, 2 * s));
|
|
3217
|
-
let B, I, N;
|
|
3218
|
-
try {
|
|
3219
|
-
B = A.fromHex(l, u), I = A.fromHex(a.slice(0, s), u), N = q.multiplyUnsafe(g);
|
|
3220
|
-
} catch {
|
|
3221
|
-
return !1;
|
|
3222
|
-
}
|
|
3223
|
-
if (!u && B.isSmallOrder())
|
|
3224
|
-
return !1;
|
|
3225
|
-
const j = T(b, I.toRawBytes(), B.toRawBytes(), h);
|
|
3226
|
-
return I.add(B.multiplyUnsafe(j)).subtract(N).clearCofactor().equals(A.ZERO);
|
|
3227
|
-
}
|
|
3228
|
-
return q._setWindowSize(8), {
|
|
3229
|
-
CURVE: e,
|
|
3230
|
-
getPublicKey: J,
|
|
3231
|
-
sign: Z,
|
|
3232
|
-
verify: n,
|
|
3233
|
-
ExtendedPoint: A,
|
|
3234
|
-
utils: {
|
|
3235
|
-
getExtendedPublicKey: P,
|
|
3236
|
-
// ed25519 private keys are uniform 32b. No need to check for modulo bias, like in secp256k1.
|
|
3237
|
-
randomPrivateKey: () => w(r.BYTES),
|
|
3238
|
-
/**
|
|
3239
|
-
* We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
|
|
3240
|
-
* values. This slows down first getPublicKey() by milliseconds (see Speed section),
|
|
3241
|
-
* but allows to speed-up subsequent getPublicKey() calls up to 20x.
|
|
3242
|
-
* @param windowSize 2, 4, 8, 16
|
|
3243
|
-
*/
|
|
3244
|
-
precompute(a = 8, h = A.BASE) {
|
|
3245
|
-
return h._setWindowSize(a), h.multiply(BigInt(3)), h;
|
|
3246
|
-
}
|
|
3247
|
-
}
|
|
3248
|
-
};
|
|
3249
|
-
}
|
|
3250
|
-
const N0 = BigInt(0), R0 = BigInt(1);
|
|
3251
|
-
const dn = BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"), Kn = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
3252
|
-
BigInt(0);
|
|
3253
|
-
const Df = BigInt(1), Gn = BigInt(2), O0 = BigInt(3), Hf = BigInt(5), Vf = BigInt(8);
|
|
3254
|
-
function zf(t) {
|
|
3255
|
-
const e = BigInt(10), r = BigInt(20), o = BigInt(40), c = BigInt(80), i = dn, d = t * t % i * t % i, y = ut(d, Gn, i) * d % i, x = ut(y, Df, i) * t % i, v = ut(x, Hf, i) * x % i, E = ut(v, e, i) * v % i, M = ut(E, r, i) * E % i, U = ut(M, o, i) * M % i, C = ut(U, c, i) * U % i, k = ut(C, c, i) * U % i, _ = ut(k, e, i) * v % i;
|
|
3256
|
-
return { pow_p_5_8: ut(_, Gn, i) * t % i, b2: d };
|
|
3257
|
-
}
|
|
3258
|
-
function Yf(t) {
|
|
3259
|
-
return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
|
|
3260
|
-
}
|
|
3261
|
-
function Xf(t, e) {
|
|
3262
|
-
const r = dn, o = tt(e * e * e, r), c = tt(o * o * e, r), i = zf(t * c).pow_p_5_8;
|
|
3263
|
-
let w = tt(t * o * i, r);
|
|
3264
|
-
const d = tt(e * w * w, r), y = w, x = tt(w * Kn, r), v = d === t, E = d === tt(-t, r), M = d === tt(-t * Kn, r);
|
|
3265
|
-
return v && (w = y), (E || M) && (w = x), yf(w, r) && (w = tt(-w, r)), { isValid: v || E, value: w };
|
|
3266
|
-
}
|
|
3267
|
-
const jf = fr(dn, void 0, !0), Kf = {
|
|
3268
|
-
// Param: a
|
|
3269
|
-
a: BigInt(-1),
|
|
3270
|
-
// Fp.create(-1) is proper; our way still works and is faster
|
|
3271
|
-
// d is equal to -121665/121666 over finite field.
|
|
3272
|
-
// Negative number is P - number, and division is invert(number, P)
|
|
3273
|
-
d: BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),
|
|
3274
|
-
// Finite field 𝔽p over which we'll do calculations; 2n**255n - 19n
|
|
3275
|
-
Fp: jf,
|
|
3276
|
-
// Subgroup order: how many points curve has
|
|
3277
|
-
// 2n**252n + 27742317777372353535851937790883648493n;
|
|
3278
|
-
n: BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),
|
|
3279
|
-
// Cofactor
|
|
3280
|
-
h: Vf,
|
|
3281
|
-
// Base point (x, y) aka generator point
|
|
3282
|
-
Gx: BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),
|
|
3283
|
-
Gy: BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),
|
|
3284
|
-
hash: ui,
|
|
3285
|
-
randomBytes: ci,
|
|
3286
|
-
adjustScalarBytes: Yf,
|
|
3287
|
-
// dom2
|
|
3288
|
-
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
3289
|
-
// Constant-time, u/√v
|
|
3290
|
-
uvRatio: Xf
|
|
3291
|
-
}, wn = Zf(Kf);
|
|
3292
|
-
function gn(t, e) {
|
|
3293
|
-
if (!Ht || !e && Vt()) {
|
|
3294
|
-
const o = Io(t);
|
|
3295
|
-
return {
|
|
3296
|
-
publicKey: o.slice(32),
|
|
3297
|
-
secretKey: o.slice(0, 64)
|
|
3298
|
-
};
|
|
3299
|
-
}
|
|
3300
|
-
const r = wn.getPublicKey(t);
|
|
3301
|
-
return {
|
|
3302
|
-
publicKey: r,
|
|
3303
|
-
secretKey: Re([t, r])
|
|
3304
|
-
};
|
|
3305
|
-
}
|
|
3306
|
-
function Gf(t, { publicKey: e, secretKey: r }, o) {
|
|
3307
|
-
if (r) {
|
|
3308
|
-
if (!e)
|
|
3309
|
-
throw new Error("Expected a valid publicKey");
|
|
3310
|
-
} else throw new Error("Expected a valid secretKey");
|
|
3311
|
-
const c = V(t), i = r.subarray(0, 32);
|
|
3312
|
-
return !Ht || !o && Vt() ? ko(e, i, c) : wn.sign(c, i);
|
|
3313
|
-
}
|
|
3314
|
-
function zi(t, e, r, o) {
|
|
3315
|
-
const c = V(t), i = V(r), w = V(e);
|
|
3316
|
-
if (i.length !== 32)
|
|
3317
|
-
throw new Error(`Invalid publicKey, received ${i.length}, expected 32`);
|
|
3318
|
-
if (w.length !== 64)
|
|
3319
|
-
throw new Error(`Invalid signature, received ${w.length} bytes, expected 64`);
|
|
3320
|
-
try {
|
|
3321
|
-
return !Ht || !o && Vt() ? Uo(w, c, i) : wn.verify(w, c, i);
|
|
3322
|
-
} catch {
|
|
3323
|
-
return !1;
|
|
3324
|
-
}
|
|
3325
|
-
}
|
|
3326
|
-
const Wf = /* @__PURE__ */ Vi(gn, $f), Jr = 64, Jf = 32, Pr = Jr + Jf;
|
|
3327
|
-
function Yi(t) {
|
|
3328
|
-
const e = V(t);
|
|
3329
|
-
if (e.length !== Pr)
|
|
3330
|
-
throw new Error(`Expected keypair with ${Pr} bytes, found ${e.length}`);
|
|
3331
|
-
return {
|
|
3332
|
-
publicKey: e.slice(Jr, Pr),
|
|
3333
|
-
secretKey: e.slice(0, Jr)
|
|
3334
|
-
};
|
|
3335
|
-
}
|
|
3336
|
-
function Qf({ publicKey: t, secretKey: e }) {
|
|
3337
|
-
return Ct(e, t).slice();
|
|
3338
|
-
}
|
|
3339
|
-
function Xi(t) {
|
|
3340
|
-
return (e, r) => {
|
|
3341
|
-
if (!oe(r) || r.length !== 32)
|
|
3342
|
-
throw new Error("Invalid chainCode passed to derive");
|
|
3343
|
-
return Yi(t(Qf(e), r));
|
|
3344
|
-
};
|
|
3345
|
-
}
|
|
3346
|
-
const Ff = /* @__PURE__ */ Xi(No), ta = /* @__PURE__ */ Xi(Ro);
|
|
3347
|
-
function ea(t, { chainCode: e, isSoft: r }) {
|
|
3348
|
-
return r ? ta(t, e) : Ff(t, e);
|
|
3349
|
-
}
|
|
3350
|
-
const ra = {
|
|
3351
|
-
ecdsa: jn,
|
|
3352
|
-
ed25519: Wf,
|
|
3353
|
-
// FIXME This is Substrate-compatible, not Ethereum-compatible
|
|
3354
|
-
ethereum: jn,
|
|
3355
|
-
sr25519: ea
|
|
3356
|
-
};
|
|
3357
|
-
function ji(t, e, r) {
|
|
3358
|
-
const o = ra[r];
|
|
3359
|
-
let c = t;
|
|
3360
|
-
for (const i of e)
|
|
3361
|
-
c = o(c, i);
|
|
3362
|
-
return c;
|
|
3363
|
-
}
|
|
3364
|
-
function Ki(t) {
|
|
3365
|
-
const e = V(t);
|
|
3366
|
-
if (e.length !== 32)
|
|
3367
|
-
throw new Error(`Expected a seed matching 32 bytes, found ${e.length}`);
|
|
3368
|
-
return Yi(Oo(e));
|
|
3369
|
-
}
|
|
3370
|
-
function na(t, { publicKey: e, secretKey: r }) {
|
|
3371
|
-
if ((e == null ? void 0 : e.length) !== 32)
|
|
3372
|
-
throw new Error("Expected a valid publicKey, 32-bytes");
|
|
3373
|
-
if ((r == null ? void 0 : r.length) !== 64)
|
|
3374
|
-
throw new Error("Expected a valid secretKey, 64-bytes");
|
|
3375
|
-
return Lo(e, r, V(t));
|
|
3376
|
-
}
|
|
3377
|
-
function Gi(t, e, r) {
|
|
3378
|
-
const o = V(r), c = V(e);
|
|
3379
|
-
if (o.length !== 32)
|
|
3380
|
-
throw new Error(`Invalid publicKey, received ${o.length} bytes, expected 32`);
|
|
3381
|
-
if (c.length !== 64)
|
|
3382
|
-
throw new Error(`Invalid signature, received ${c.length} bytes, expected 64`);
|
|
3383
|
-
return To(c, V(t), o);
|
|
3384
|
-
}
|
|
3385
|
-
const Wn = new Uint8Array();
|
|
3386
|
-
function ia(t, { secretKey: e }, r = Wn, o = Wn) {
|
|
3387
|
-
if ((e == null ? void 0 : e.length) !== 64)
|
|
3388
|
-
throw new Error("Invalid secretKey, expected 64-bytes");
|
|
3389
|
-
return $o(e, V(r), V(t), V(o));
|
|
3390
|
-
}
|
|
3391
|
-
const Jn = new Uint8Array();
|
|
3392
|
-
function oa(t, e, r, o = Jn, c = Jn) {
|
|
3393
|
-
const i = V(r), w = V(e);
|
|
3394
|
-
if (i.length !== 32)
|
|
3395
|
-
throw new Error("Invalid publicKey, expected 32-bytes");
|
|
3396
|
-
if (w.length !== 96)
|
|
3397
|
-
throw new Error("Invalid vrfSign output, expected 96 bytes");
|
|
3398
|
-
return qo(i, V(o), V(t), V(c), w);
|
|
3399
|
-
}
|
|
3400
|
-
function sa(t, e = ze.prefix) {
|
|
3401
|
-
const r = ge(t);
|
|
3402
|
-
if (e < 0 || e > 16383 || [46, 47].includes(e))
|
|
3403
|
-
throw new Error("Out of range ss58Format specified");
|
|
3404
|
-
if (!ze.allowedDecodedLengths.includes(r.length))
|
|
3405
|
-
throw new Error(`Expected a valid key to convert, with length ${ze.allowedDecodedLengths.join(", ")}`);
|
|
3406
|
-
const o = Ct(e < 64 ? [e] : [
|
|
3407
|
-
(e & 252) >> 2 | 64,
|
|
3408
|
-
e >> 8 | (e & 3) << 6
|
|
3409
|
-
], r);
|
|
3410
|
-
return Ys(Ct(o, Oi(o).subarray(0, [32, 33].includes(r.length) ? 2 : 1)));
|
|
3411
|
-
}
|
|
3412
|
-
const Wi = [], Ji = [], Qi = [], fa = /* @__PURE__ */ BigInt(0), Me = /* @__PURE__ */ BigInt(1), aa = /* @__PURE__ */ BigInt(2), ha = /* @__PURE__ */ BigInt(7), ca = /* @__PURE__ */ BigInt(256), la = /* @__PURE__ */ BigInt(113);
|
|
3413
|
-
for (let t = 0, e = Me, r = 1, o = 0; t < 24; t++) {
|
|
3414
|
-
[r, o] = [o, (2 * r + 3 * o) % 5], Wi.push(2 * (5 * o + r)), Ji.push((t + 1) * (t + 2) / 2 % 64);
|
|
3415
|
-
let c = fa;
|
|
3416
|
-
for (let i = 0; i < 7; i++)
|
|
3417
|
-
e = (e << Me ^ (e >> ha) * la) % ca, e & aa && (c ^= Me << (Me << /* @__PURE__ */ BigInt(i)) - Me);
|
|
3418
|
-
Qi.push(c);
|
|
3419
|
-
}
|
|
3420
|
-
const [ua, da] = /* @__PURE__ */ Po(Qi, !0), Qn = (t, e, r) => r > 32 ? Co(t, e, r) : Zo(t, e, r), Fn = (t, e, r) => r > 32 ? Do(t, e, r) : Ho(t, e, r);
|
|
3421
|
-
function wa(t, e = 24) {
|
|
3422
|
-
const r = new Uint32Array(10);
|
|
3423
|
-
for (let o = 24 - e; o < 24; o++) {
|
|
3424
|
-
for (let w = 0; w < 10; w++)
|
|
3425
|
-
r[w] = t[w] ^ t[w + 10] ^ t[w + 20] ^ t[w + 30] ^ t[w + 40];
|
|
3426
|
-
for (let w = 0; w < 10; w += 2) {
|
|
3427
|
-
const d = (w + 8) % 10, y = (w + 2) % 10, x = r[y], v = r[y + 1], E = Qn(x, v, 1) ^ r[d], M = Fn(x, v, 1) ^ r[d + 1];
|
|
3428
|
-
for (let U = 0; U < 50; U += 10)
|
|
3429
|
-
t[w + U] ^= E, t[w + U + 1] ^= M;
|
|
3430
|
-
}
|
|
3431
|
-
let c = t[2], i = t[3];
|
|
3432
|
-
for (let w = 0; w < 24; w++) {
|
|
3433
|
-
const d = Ji[w], y = Qn(c, i, d), x = Fn(c, i, d), v = Wi[w];
|
|
3434
|
-
c = t[v], i = t[v + 1], t[v] = y, t[v + 1] = x;
|
|
3435
|
-
}
|
|
3436
|
-
for (let w = 0; w < 50; w += 10) {
|
|
3437
|
-
for (let d = 0; d < 10; d++)
|
|
3438
|
-
r[d] = t[w + d];
|
|
3439
|
-
for (let d = 0; d < 10; d++)
|
|
3440
|
-
t[w + d] ^= ~r[(d + 2) % 10] & r[(d + 4) % 10];
|
|
3441
|
-
}
|
|
3442
|
-
t[0] ^= ua[o], t[1] ^= da[o];
|
|
3443
|
-
}
|
|
3444
|
-
r.fill(0);
|
|
3445
|
-
}
|
|
3446
|
-
class ar extends bo {
|
|
3447
|
-
// NOTE: we accept arguments in bytes instead of bits here.
|
|
3448
|
-
constructor(e, r, o, c = !1, i = 24) {
|
|
3449
|
-
if (super(), this.blockLen = e, this.suffix = r, this.outputLen = o, this.enableXOF = c, this.rounds = i, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, Ft(o), 0 >= this.blockLen || this.blockLen >= 200)
|
|
3450
|
-
throw new Error("Sha3 supports only keccak-f1600 function");
|
|
3451
|
-
this.state = new Uint8Array(200), this.state32 = Ve(this.state);
|
|
3452
|
-
}
|
|
3453
|
-
keccak() {
|
|
3454
|
-
Xe || je(this.state32), wa(this.state32, this.rounds), Xe || je(this.state32), this.posOut = 0, this.pos = 0;
|
|
3455
|
-
}
|
|
3456
|
-
update(e) {
|
|
3457
|
-
kn(this);
|
|
3458
|
-
const { blockLen: r, state: o } = this;
|
|
3459
|
-
e = xo(e);
|
|
3460
|
-
const c = e.length;
|
|
3461
|
-
for (let i = 0; i < c; ) {
|
|
3462
|
-
const w = Math.min(r - this.pos, c - i);
|
|
3463
|
-
for (let d = 0; d < w; d++)
|
|
3464
|
-
o[this.pos++] ^= e[i++];
|
|
3465
|
-
this.pos === r && this.keccak();
|
|
3466
|
-
}
|
|
3467
|
-
return this;
|
|
3468
|
-
}
|
|
3469
|
-
finish() {
|
|
3470
|
-
if (this.finished)
|
|
3471
|
-
return;
|
|
3472
|
-
this.finished = !0;
|
|
3473
|
-
const { state: e, suffix: r, pos: o, blockLen: c } = this;
|
|
3474
|
-
e[o] ^= r, r & 128 && o === c - 1 && this.keccak(), e[c - 1] ^= 128, this.keccak();
|
|
3475
|
-
}
|
|
3476
|
-
writeInto(e) {
|
|
3477
|
-
kn(this, !1), Eo(e), this.finish();
|
|
3478
|
-
const r = this.state, { blockLen: o } = this;
|
|
3479
|
-
for (let c = 0, i = e.length; c < i; ) {
|
|
3480
|
-
this.posOut >= o && this.keccak();
|
|
3481
|
-
const w = Math.min(o - this.posOut, i - c);
|
|
3482
|
-
e.set(r.subarray(this.posOut, this.posOut + w), c), this.posOut += w, c += w;
|
|
3483
|
-
}
|
|
3484
|
-
return e;
|
|
3485
|
-
}
|
|
3486
|
-
xofInto(e) {
|
|
3487
|
-
if (!this.enableXOF)
|
|
3488
|
-
throw new Error("XOF is not possible for this instance");
|
|
3489
|
-
return this.writeInto(e);
|
|
3490
|
-
}
|
|
3491
|
-
xof(e) {
|
|
3492
|
-
return Ft(e), this.xofInto(new Uint8Array(e));
|
|
3493
|
-
}
|
|
3494
|
-
digestInto(e) {
|
|
3495
|
-
if (Mo(e, this), this.finished)
|
|
3496
|
-
throw new Error("digest() was already called");
|
|
3497
|
-
return this.writeInto(e), this.destroy(), e;
|
|
3498
|
-
}
|
|
3499
|
-
digest() {
|
|
3500
|
-
return this.digestInto(new Uint8Array(this.outputLen));
|
|
3501
|
-
}
|
|
3502
|
-
destroy() {
|
|
3503
|
-
this.destroyed = !0, this.state.fill(0);
|
|
3504
|
-
}
|
|
3505
|
-
_cloneInto(e) {
|
|
3506
|
-
const { blockLen: r, suffix: o, outputLen: c, rounds: i, enableXOF: w } = this;
|
|
3507
|
-
return e || (e = new ar(r, o, c, w, i)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = i, e.suffix = o, e.outputLen = c, e.enableXOF = w, e.destroyed = this.destroyed, e;
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
const re = (t, e, r) => yo(() => new ar(e, t, r));
|
|
3511
|
-
224 / 8;
|
|
3512
|
-
256 / 8;
|
|
3513
|
-
384 / 8;
|
|
3514
|
-
512 / 8;
|
|
3515
|
-
224 / 8;
|
|
3516
|
-
const ga = /* @__PURE__ */ re(1, 136, 256 / 8);
|
|
3517
|
-
384 / 8;
|
|
3518
|
-
const ma = /* @__PURE__ */ re(1, 72, 512 / 8), Fi = (t, e, r) => vo((o = {}) => new ar(e, t, o.dkLen === void 0 ? r : o.dkLen, !0));
|
|
3519
|
-
128 / 8;
|
|
3520
|
-
256 / 8;
|
|
3521
|
-
const hr = /* @__PURE__ */ Vo({ 256: Yo, 512: zo }, { 256: ga, 512: ma });
|
|
3522
|
-
function Qr(t, e, r) {
|
|
3523
|
-
return t === "keccak" ? hr(e, void 0, r) : he(e, void 0, void 0, r);
|
|
3524
|
-
}
|
|
3525
|
-
const mn = {
|
|
3526
|
-
chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
3527
|
-
coder: Zs,
|
|
3528
|
-
type: "base64",
|
|
3529
|
-
withPadding: !0
|
|
3530
|
-
}, pa = /* @__PURE__ */ Ri(mn), ya = /* @__PURE__ */ Ui(mn, pa), va = /* @__PURE__ */ Ni(mn);
|
|
3531
|
-
function to(t, e) {
|
|
3532
|
-
if (![33, 65].includes(t.length))
|
|
3533
|
-
throw new Error(`Invalid publicKey provided, received ${t.length} bytes input`);
|
|
3534
|
-
return t.length === 33 ? t : !Ht || Vt() ? Xo(t) : Te.ProjectivePoint.fromHex(t).toRawBytes(!0);
|
|
3535
|
-
}
|
|
3536
|
-
function pn(t, e) {
|
|
3537
|
-
if (![33, 65].includes(t.length))
|
|
3538
|
-
throw new Error(`Invalid publicKey provided, received ${t.length} bytes input`);
|
|
3539
|
-
if (t.length === 65)
|
|
3540
|
-
return t.subarray(1);
|
|
3541
|
-
if (!Ht || Vt())
|
|
3542
|
-
return jo(t).subarray(1);
|
|
3543
|
-
const { px: r, py: o } = Te.ProjectivePoint.fromHex(t);
|
|
3544
|
-
return Ct(zt(r, pe), zt(o, pe));
|
|
3545
|
-
}
|
|
3546
|
-
function ba(t, e, r, o = "blake2", c) {
|
|
3547
|
-
const i = V(e).subarray(0, 64), w = V(t), d = !Ht || Vt() ? Ko(w, i, r) : Te.Signature.fromCompact(i).addRecoveryBit(r).recoverPublicKey(w).toRawBytes();
|
|
3548
|
-
if (!d)
|
|
3549
|
-
throw new Error("Unable to recover publicKey from signature");
|
|
3550
|
-
return o === "keccak" ? pn(d) : to(d);
|
|
3551
|
-
}
|
|
3552
|
-
function ti(t, { secretKey: e }, r = "blake2", o) {
|
|
3553
|
-
if ((e == null ? void 0 : e.length) !== 32)
|
|
3554
|
-
throw new Error("Expected valid secp256k1 secretKey, 32-bytes");
|
|
3555
|
-
const c = Qr(r, t, o);
|
|
3556
|
-
if (!Ht || Vt())
|
|
3557
|
-
return Go(c, e);
|
|
3558
|
-
const i = Te.sign(c, e, { lowS: !0 });
|
|
3559
|
-
return Ct(zt(i.r, pe), zt(i.s, pe), new Uint8Array([i.recovery || 0]));
|
|
3560
|
-
}
|
|
3561
|
-
const eo = "ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141".replace(/ /g, ""), Cr = W(`0x${eo}`), Zr = new K(eo, "hex");
|
|
3562
|
-
function xa(t, e) {
|
|
3563
|
-
let r = Xr(e, qn);
|
|
3564
|
-
if (r >= Cr)
|
|
3565
|
-
throw new Error("Tweak parameter is out of range");
|
|
3566
|
-
if (r += Xr(t, qn), r >= Cr && (r -= Cr), r === Ke)
|
|
3567
|
-
throw new Error("Invalid resulting private key");
|
|
3568
|
-
return _s(r, pe);
|
|
3569
|
-
}
|
|
3570
|
-
function Ea(t, e) {
|
|
3571
|
-
const r = new K(e);
|
|
3572
|
-
if (r.cmp(Zr) >= 0)
|
|
3573
|
-
throw new Error("Tweak parameter is out of range");
|
|
3574
|
-
if (r.iadd(new K(t)), r.cmp(Zr) >= 0 && r.isub(Zr), r.isZero())
|
|
3575
|
-
throw new Error("Invalid resulting private key");
|
|
3576
|
-
return zt(r, pe);
|
|
3577
|
-
}
|
|
3578
|
-
function Ma(t, e, r) {
|
|
3579
|
-
if (!oe(t) || t.length !== 32)
|
|
3580
|
-
throw new Error("Expected seckey to be an Uint8Array with length 32");
|
|
3581
|
-
if (!oe(e) || e.length !== 32)
|
|
3582
|
-
throw new Error("Expected tweak to be an Uint8Array with length 32");
|
|
3583
|
-
return !Ht || r ? Ea(t, e) : xa(t, e);
|
|
3584
|
-
}
|
|
3585
|
-
function _a(t, e, r, o = "blake2", c) {
|
|
3586
|
-
const i = V(e);
|
|
3587
|
-
if (i.length !== 65)
|
|
3588
|
-
throw new Error(`Expected signature with 65 bytes, ${i.length} found instead`);
|
|
3589
|
-
const w = ba(Qr(o, t), i, i[64], o), d = Qr(o, w, c), y = V(r);
|
|
3590
|
-
return jt(w, y) || (o === "keccak" ? jt(d.slice(-20), y.slice(-20)) : jt(d, y));
|
|
3591
|
-
}
|
|
3592
|
-
function Ba(t) {
|
|
3593
|
-
return [33, 65].includes(t.length) && (t = hr(pn(t))), t.slice(-20);
|
|
3594
|
-
}
|
|
3595
|
-
function ro(t) {
|
|
3596
|
-
if (!t)
|
|
3597
|
-
return "0x";
|
|
3598
|
-
const e = V(t);
|
|
3599
|
-
if (![20, 32, 33, 65].includes(e.length))
|
|
3600
|
-
throw new Error(`Invalid address or publicKey provided, received ${e.length} bytes input`);
|
|
3601
|
-
const r = Ae(Ba(e), -1, !1), o = Ae(hr(r), -1, !1);
|
|
3602
|
-
let c = "";
|
|
3603
|
-
for (let i = 0; i < 40; i++)
|
|
3604
|
-
c = `${c}${parseInt(o[i], 16) > 7 ? r[i].toUpperCase() : r[i]}`;
|
|
3605
|
-
return `0x${c}`;
|
|
3606
|
-
}
|
|
3607
|
-
const Sa = {
|
|
3608
|
-
256: rr,
|
|
3609
|
-
512: ui
|
|
3610
|
-
}, Aa = {
|
|
3611
|
-
256: Jo,
|
|
3612
|
-
512: Wo
|
|
3613
|
-
};
|
|
3614
|
-
function no(t, e, r = 256, o) {
|
|
3615
|
-
const c = V(t);
|
|
3616
|
-
return !Ht || Vt() ? Aa[r](c, e) : li(Sa[r], c, e);
|
|
3617
|
-
}
|
|
3618
|
-
const yn = 2147483648;
|
|
3619
|
-
function Ia(t) {
|
|
3620
|
-
if (!t.startsWith("m/"))
|
|
3621
|
-
return !1;
|
|
3622
|
-
const e = t.split("/").slice(1);
|
|
3623
|
-
for (const r of e) {
|
|
3624
|
-
const o = /^\d+'?$/.test(r) ? parseInt(r.replace(/'$/, ""), 10) : Number.NaN;
|
|
3625
|
-
if (isNaN(o) || o >= yn || o < 0)
|
|
3626
|
-
return !1;
|
|
3627
|
-
}
|
|
3628
|
-
return !0;
|
|
3629
|
-
}
|
|
3630
|
-
const ka = ee("Bitcoin seed");
|
|
3631
|
-
function io(t, e) {
|
|
3632
|
-
return {
|
|
3633
|
-
chainCode: e,
|
|
3634
|
-
publicKey: be(t).publicKey,
|
|
3635
|
-
secretKey: t
|
|
3636
|
-
};
|
|
3637
|
-
}
|
|
3638
|
-
function oo(t, e) {
|
|
3639
|
-
const r = zt(e, Ks), o = e >= yn ? Ct(new Uint8Array(1), t.secretKey, r) : Ct(t.publicKey, r);
|
|
3640
|
-
try {
|
|
3641
|
-
const c = no(t.chainCode, o, 512);
|
|
3642
|
-
return io(Ma(t.secretKey, c.slice(0, 32)), c.slice(32));
|
|
3643
|
-
} catch {
|
|
3644
|
-
return oo(t, e + 1);
|
|
3645
|
-
}
|
|
3646
|
-
}
|
|
3647
|
-
function Ua(t, e = "") {
|
|
3648
|
-
const r = no(ka, t, 512);
|
|
3649
|
-
let o = io(r.slice(0, 32), r.slice(32));
|
|
3650
|
-
if (!e || e === "m" || e === "M" || e === "m'" || e === "M'")
|
|
3651
|
-
return o;
|
|
3652
|
-
if (!Ia(e))
|
|
3653
|
-
throw new Error("Invalid derivation path");
|
|
3654
|
-
const c = e.split("/").slice(1);
|
|
3655
|
-
for (const i of c)
|
|
3656
|
-
o = oo(o, parseInt(i, 10) + (i.length > 1 && i.endsWith("'") ? yn : 0));
|
|
3657
|
-
return o;
|
|
3658
|
-
}
|
|
3659
|
-
function Na(t, e, r) {
|
|
3660
|
-
return !Ht || Vt() ? Qo(t) : os(t, e);
|
|
3661
|
-
}
|
|
3662
|
-
function so(t, e, r) {
|
|
3663
|
-
return !Ht || Vt() ? Fo(t) : ss(t, e);
|
|
3664
|
-
}
|
|
3665
|
-
function Ra(t, e = "", r, o = 32) {
|
|
3666
|
-
if (so(t)) {
|
|
3667
|
-
if (![32, 64].includes(o))
|
|
3668
|
-
throw new Error(`Invalid seed length ${o}, expected 32 or 64`);
|
|
3669
|
-
} else throw new Error("Invalid bip39 mnemonic specified");
|
|
3670
|
-
return o === 32 ? !Ht || Vt() ? ts(t, e) : Un(t, e).subarray(0, 32) : Un(t, e);
|
|
3671
|
-
}
|
|
3672
|
-
function Oa(t, e = "", r, o) {
|
|
3673
|
-
if (so(t, r)) {
|
|
3674
|
-
if (Vt())
|
|
3675
|
-
return es(t, e);
|
|
3676
|
-
} else throw new Error("Invalid bip39 mnemonic specified");
|
|
3677
|
-
const c = Na(t, r), i = ee(`mnemonic${e}`);
|
|
3678
|
-
return fs(c, i).password.slice(0, 32);
|
|
3679
|
-
}
|
|
3680
|
-
function De(t, e) {
|
|
3681
|
-
return t << e | t >>> 32 - e;
|
|
3682
|
-
}
|
|
3683
|
-
function le(t, e) {
|
|
3684
|
-
let r = t[e + 3] & 255;
|
|
3685
|
-
return r = r << 8 | t[e + 2] & 255, r = r << 8 | t[e + 1] & 255, r << 8 | t[e + 0] & 255;
|
|
3686
|
-
}
|
|
3687
|
-
function Dr(t, e, r) {
|
|
3688
|
-
for (let o = 0; o < 4; o++)
|
|
3689
|
-
t[e + o] = r & 255, r >>>= 8;
|
|
3690
|
-
}
|
|
3691
|
-
function La(t, e, r, o, c) {
|
|
3692
|
-
let i = 0;
|
|
3693
|
-
for (let w = 0; w < c; w++)
|
|
3694
|
-
i |= t[e + w] ^ r[o + w];
|
|
3695
|
-
return (1 & i - 1 >>> 8) - 1;
|
|
3696
|
-
}
|
|
3697
|
-
function Fr(t, e, r, o, c) {
|
|
3698
|
-
const i = new Uint32Array(16), w = new Uint32Array(16), d = new Uint32Array(16), y = new Uint32Array(4);
|
|
3699
|
-
let x, v, E;
|
|
3700
|
-
for (x = 0; x < 4; x++)
|
|
3701
|
-
w[5 * x] = le(o, 4 * x), w[1 + x] = le(r, 4 * x), w[6 + x] = le(e, 4 * x), w[11 + x] = le(r, 16 + 4 * x);
|
|
3702
|
-
for (x = 0; x < 16; x++)
|
|
3703
|
-
d[x] = w[x];
|
|
3704
|
-
for (x = 0; x < 20; x++) {
|
|
3705
|
-
for (v = 0; v < 4; v++) {
|
|
3706
|
-
for (E = 0; E < 4; E++)
|
|
3707
|
-
y[E] = w[(5 * v + 4 * E) % 16];
|
|
3708
|
-
for (y[1] ^= De(y[0] + y[3] | 0, 7), y[2] ^= De(y[1] + y[0] | 0, 9), y[3] ^= De(y[2] + y[1] | 0, 13), y[0] ^= De(y[3] + y[2] | 0, 18), E = 0; E < 4; E++)
|
|
3709
|
-
i[4 * v + (v + E) % 4] = y[E];
|
|
3710
|
-
}
|
|
3711
|
-
for (E = 0; E < 16; E++)
|
|
3712
|
-
w[E] = i[E];
|
|
3713
|
-
}
|
|
3714
|
-
if (c) {
|
|
3715
|
-
for (x = 0; x < 16; x++)
|
|
3716
|
-
w[x] = w[x] + d[x] | 0;
|
|
3717
|
-
for (x = 0; x < 4; x++)
|
|
3718
|
-
w[5 * x] = w[5 * x] - le(o, 4 * x) | 0, w[6 + x] = w[6 + x] - le(e, 4 * x) | 0;
|
|
3719
|
-
for (x = 0; x < 4; x++)
|
|
3720
|
-
Dr(t, 4 * x, w[5 * x]), Dr(t, 16 + 4 * x, w[6 + x]);
|
|
3721
|
-
} else
|
|
3722
|
-
for (x = 0; x < 16; x++)
|
|
3723
|
-
Dr(t, 4 * x, w[x] + d[x] | 0);
|
|
3724
|
-
}
|
|
3725
|
-
const tn = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
3726
|
-
function Ta(t, e, r, o, c, i, w) {
|
|
3727
|
-
const d = new Uint8Array(16), y = new Uint8Array(64);
|
|
3728
|
-
let x, v;
|
|
3729
|
-
if (!c)
|
|
3730
|
-
return 0;
|
|
3731
|
-
for (v = 0; v < 16; v++)
|
|
3732
|
-
d[v] = 0;
|
|
3733
|
-
for (v = 0; v < 8; v++)
|
|
3734
|
-
d[v] = i[v];
|
|
3735
|
-
for (; c >= 64; ) {
|
|
3736
|
-
for (Fr(y, d, w, tn, !1), v = 0; v < 64; v++)
|
|
3737
|
-
t[e + v] = (r ? r[o + v] : 0) ^ y[v];
|
|
3738
|
-
for (x = 1, v = 8; v < 16; v++)
|
|
3739
|
-
x = x + (d[v] & 255) | 0, d[v] = x & 255, x >>>= 8;
|
|
3740
|
-
c -= 64, e += 64, r && (o += 64);
|
|
3741
|
-
}
|
|
3742
|
-
if (c > 0)
|
|
3743
|
-
for (Fr(y, d, w, tn, !1), v = 0; v < c; v++)
|
|
3744
|
-
t[e + v] = (r ? r[o + v] : 0) ^ y[v];
|
|
3745
|
-
return 0;
|
|
3746
|
-
}
|
|
3747
|
-
function en(t, e, r, o, c, i, w) {
|
|
3748
|
-
const d = new Uint8Array(32);
|
|
3749
|
-
return Fr(d, i, w, tn, !0), Ta(t, e, r, o, c, i.subarray(16), d);
|
|
3750
|
-
}
|
|
3751
|
-
function Hr(t, e) {
|
|
3752
|
-
let r = 0;
|
|
3753
|
-
for (let o = 0; o < 17; o++)
|
|
3754
|
-
r = r + (t[o] + e[o] | 0) | 0, t[o] = r & 255, r >>>= 8;
|
|
3755
|
-
}
|
|
3756
|
-
const $a = new Uint32Array([5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252]);
|
|
3757
|
-
function fo(t, e, r, o, c, i) {
|
|
3758
|
-
let w, d, y;
|
|
3759
|
-
const x = new Uint32Array(17), v = new Uint32Array(17), E = new Uint32Array(17), M = new Uint32Array(17), U = new Uint32Array(17);
|
|
3760
|
-
for (d = 0; d < 17; d++)
|
|
3761
|
-
v[d] = E[d] = 0;
|
|
3762
|
-
for (d = 0; d < 16; d++)
|
|
3763
|
-
v[d] = i[d];
|
|
3764
|
-
for (v[3] &= 15, v[4] &= 252, v[7] &= 15, v[8] &= 252, v[11] &= 15, v[12] &= 252, v[15] &= 15; c > 0; ) {
|
|
3765
|
-
for (d = 0; d < 17; d++)
|
|
3766
|
-
M[d] = 0;
|
|
3767
|
-
for (d = 0; d < 16 && d < c; ++d)
|
|
3768
|
-
M[d] = r[o + d];
|
|
3769
|
-
for (M[d] = 1, o += d, c -= d, Hr(E, M), w = 0; w < 17; w++)
|
|
3770
|
-
for (x[w] = 0, d = 0; d < 17; d++)
|
|
3771
|
-
x[w] = x[w] + E[d] * (d <= w ? v[w - d] : 320 * v[w + 17 - d] | 0) | 0 | 0;
|
|
3772
|
-
for (w = 0; w < 17; w++)
|
|
3773
|
-
E[w] = x[w];
|
|
3774
|
-
for (y = 0, d = 0; d < 16; d++)
|
|
3775
|
-
y = y + E[d] | 0, E[d] = y & 255, y >>>= 8;
|
|
3776
|
-
for (y = y + E[16] | 0, E[16] = y & 3, y = 5 * (y >>> 2) | 0, d = 0; d < 16; d++)
|
|
3777
|
-
y = y + E[d] | 0, E[d] = y & 255, y >>>= 8;
|
|
3778
|
-
y = y + E[16] | 0, E[16] = y;
|
|
3779
|
-
}
|
|
3780
|
-
for (d = 0; d < 17; d++)
|
|
3781
|
-
U[d] = E[d];
|
|
3782
|
-
Hr(E, $a);
|
|
3783
|
-
const C = -(E[16] >>> 7) | 0;
|
|
3784
|
-
for (d = 0; d < 17; d++)
|
|
3785
|
-
E[d] ^= C & (U[d] ^ E[d]);
|
|
3786
|
-
for (d = 0; d < 16; d++)
|
|
3787
|
-
M[d] = i[d + 16];
|
|
3788
|
-
for (M[16] = 0, Hr(E, M), d = 0; d < 16; d++)
|
|
3789
|
-
t[e + d] = E[d];
|
|
3790
|
-
return 0;
|
|
3791
|
-
}
|
|
3792
|
-
function qa(t, e, r, o, c, i) {
|
|
3793
|
-
const w = new Uint8Array(16);
|
|
3794
|
-
return fo(w, 0, r, o, c, i), La(t, e, w, 0, 16);
|
|
3795
|
-
}
|
|
3796
|
-
function Pa(t, e, r, o, c) {
|
|
3797
|
-
if (r < 32)
|
|
3798
|
-
return -1;
|
|
3799
|
-
en(t, 0, e, 0, r, o, c), fo(t, 16, t, 32, r - 32, t);
|
|
3800
|
-
for (let i = 0; i < 16; i++)
|
|
3801
|
-
t[i] = 0;
|
|
3802
|
-
return 0;
|
|
3803
|
-
}
|
|
3804
|
-
function Ca(t, e, r, o, c) {
|
|
3805
|
-
const i = new Uint8Array(32);
|
|
3806
|
-
if (r < 32 || (en(i, 0, null, 0, 32, o, c), qa(e, 16, e, 32, r - 32, i) !== 0))
|
|
3807
|
-
return -1;
|
|
3808
|
-
en(t, 0, e, 0, r, o, c);
|
|
3809
|
-
for (let w = 0; w < 32; w++)
|
|
3810
|
-
t[w] = 0;
|
|
3811
|
-
return 0;
|
|
3812
|
-
}
|
|
3813
|
-
const Za = 32, Da = 24, rn = 32, nn = 16;
|
|
3814
|
-
function ao(t, e) {
|
|
3815
|
-
if (t.length !== Za)
|
|
3816
|
-
throw new Error("bad key size");
|
|
3817
|
-
if (e.length !== Da)
|
|
3818
|
-
throw new Error("bad nonce size");
|
|
3819
|
-
}
|
|
3820
|
-
function ho(...t) {
|
|
3821
|
-
for (let e = 0, r = t.length; e < r; e++)
|
|
3822
|
-
if (!(t[e] instanceof Uint8Array))
|
|
3823
|
-
throw new TypeError("unexpected type, use Uint8Array");
|
|
3824
|
-
}
|
|
3825
|
-
function Ha(t, e, r) {
|
|
3826
|
-
ho(t, e, r), ao(r, e);
|
|
3827
|
-
const o = new Uint8Array(rn + t.length), c = new Uint8Array(o.length);
|
|
3828
|
-
for (let i = 0; i < t.length; i++)
|
|
3829
|
-
o[i + rn] = t[i];
|
|
3830
|
-
return Pa(c, o, o.length, e, r), c.subarray(nn);
|
|
3831
|
-
}
|
|
3832
|
-
function Va(t, e, r) {
|
|
3833
|
-
ho(t, e, r), ao(r, e);
|
|
3834
|
-
const o = new Uint8Array(nn + t.length), c = new Uint8Array(o.length);
|
|
3835
|
-
for (let i = 0; i < t.length; i++)
|
|
3836
|
-
o[i + nn] = t[i];
|
|
3837
|
-
return o.length < 32 || Ca(c, o, o.length, e, r) !== 0 ? null : c.subarray(rn);
|
|
3838
|
-
}
|
|
3839
|
-
function za(t, e, r) {
|
|
3840
|
-
return Va(t, e, r);
|
|
3841
|
-
}
|
|
3842
|
-
function Ya(t, e, r = wi(24)) {
|
|
3843
|
-
return {
|
|
3844
|
-
encrypted: Ha(t, r, e),
|
|
3845
|
-
nonce: r
|
|
3846
|
-
};
|
|
3847
|
-
}
|
|
3848
|
-
function ei(t, e, r, o, c, i) {
|
|
3849
|
-
let w = t[e++] ^ r[o++], d = t[e++] ^ r[o++], y = t[e++] ^ r[o++], x = t[e++] ^ r[o++], v = t[e++] ^ r[o++], E = t[e++] ^ r[o++], M = t[e++] ^ r[o++], U = t[e++] ^ r[o++], C = t[e++] ^ r[o++], k = t[e++] ^ r[o++], _ = t[e++] ^ r[o++], S = t[e++] ^ r[o++], L = t[e++] ^ r[o++], A = t[e++] ^ r[o++], q = t[e++] ^ r[o++], D = t[e++] ^ r[o++], R = w, O = d, $ = y, P = x, J = v, T = E, Z = M, p = U, n = C, f = k, a = _, h = S, l = L, m = A, b = q, u = D;
|
|
3850
|
-
for (let s = 0; s < 8; s += 2)
|
|
3851
|
-
J ^= G(R + l | 0, 7), n ^= G(J + R | 0, 9), l ^= G(n + J | 0, 13), R ^= G(l + n | 0, 18), f ^= G(T + O | 0, 7), m ^= G(f + T | 0, 9), O ^= G(m + f | 0, 13), T ^= G(O + m | 0, 18), b ^= G(a + Z | 0, 7), $ ^= G(b + a | 0, 9), Z ^= G($ + b | 0, 13), a ^= G(Z + $ | 0, 18), P ^= G(u + h | 0, 7), p ^= G(P + u | 0, 9), h ^= G(p + P | 0, 13), u ^= G(h + p | 0, 18), O ^= G(R + P | 0, 7), $ ^= G(O + R | 0, 9), P ^= G($ + O | 0, 13), R ^= G(P + $ | 0, 18), Z ^= G(T + J | 0, 7), p ^= G(Z + T | 0, 9), J ^= G(p + Z | 0, 13), T ^= G(J + p | 0, 18), h ^= G(a + f | 0, 7), n ^= G(h + a | 0, 9), f ^= G(n + h | 0, 13), a ^= G(f + n | 0, 18), l ^= G(u + b | 0, 7), m ^= G(l + u | 0, 9), b ^= G(m + l | 0, 13), u ^= G(b + m | 0, 18);
|
|
3852
|
-
c[i++] = w + R | 0, c[i++] = d + O | 0, c[i++] = y + $ | 0, c[i++] = x + P | 0, c[i++] = v + J | 0, c[i++] = E + T | 0, c[i++] = M + Z | 0, c[i++] = U + p | 0, c[i++] = C + n | 0, c[i++] = k + f | 0, c[i++] = _ + a | 0, c[i++] = S + h | 0, c[i++] = L + l | 0, c[i++] = A + m | 0, c[i++] = q + b | 0, c[i++] = D + u | 0;
|
|
3853
|
-
}
|
|
3854
|
-
function Vr(t, e, r, o, c) {
|
|
3855
|
-
let i = o + 0, w = o + 16 * c;
|
|
3856
|
-
for (let d = 0; d < 16; d++)
|
|
3857
|
-
r[w + d] = t[e + (2 * c - 1) * 16 + d];
|
|
3858
|
-
for (let d = 0; d < c; d++, i += 16, e += 16)
|
|
3859
|
-
ei(r, w, t, e, r, i), d > 0 && (w += 16), ei(r, i, t, e += 16, r, w);
|
|
3860
|
-
}
|
|
3861
|
-
function Xa(t, e, r) {
|
|
3862
|
-
const o = _o({
|
|
3863
|
-
dkLen: 32,
|
|
3864
|
-
asyncTick: 10,
|
|
3865
|
-
maxmem: 1073742848
|
|
3866
|
-
}, r), { N: c, r: i, p: w, dkLen: d, asyncTick: y, maxmem: x, onProgress: v } = o;
|
|
3867
|
-
if (Ft(c), Ft(i), Ft(w), Ft(d), Ft(y), Ft(x), v !== void 0 && typeof v != "function")
|
|
3868
|
-
throw new Error("progressCb should be function");
|
|
3869
|
-
const E = 128 * i, M = E / 4;
|
|
3870
|
-
if (c <= 1 || c & c - 1 || c > 2 ** 32)
|
|
3871
|
-
throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");
|
|
3872
|
-
if (w < 0 || w > (2 ** 32 - 1) * 32 / E)
|
|
3873
|
-
throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
|
|
3874
|
-
if (d < 0 || d > (2 ** 32 - 1) * 32)
|
|
3875
|
-
throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
|
|
3876
|
-
const U = E * (c + w);
|
|
3877
|
-
if (U > x)
|
|
3878
|
-
throw new Error(`Scrypt: parameters too large, ${U} (128 * r * (N + p)) > ${x} (maxmem)`);
|
|
3879
|
-
const C = di(rr, t, e, { c: 1, dkLen: E * w }), k = Ve(C), _ = Ve(new Uint8Array(E * c)), S = Ve(new Uint8Array(E));
|
|
3880
|
-
let L = () => {
|
|
3881
|
-
};
|
|
3882
|
-
if (v) {
|
|
3883
|
-
const A = 2 * c * w, q = Math.max(Math.floor(A / 1e4), 1);
|
|
3884
|
-
let D = 0;
|
|
3885
|
-
L = () => {
|
|
3886
|
-
D++, v && (!(D % q) || D === A) && v(D / A);
|
|
3887
|
-
};
|
|
3888
|
-
}
|
|
3889
|
-
return { N: c, r: i, p: w, dkLen: d, blockSize32: M, V: _, B32: k, B: C, tmp: S, blockMixCb: L, asyncTick: y };
|
|
3890
|
-
}
|
|
3891
|
-
function ja(t, e, r, o, c) {
|
|
3892
|
-
const i = di(rr, t, r, { c: 1, dkLen: e });
|
|
3893
|
-
return r.fill(0), o.fill(0), c.fill(0), i;
|
|
3894
|
-
}
|
|
3895
|
-
function Ka(t, e, r) {
|
|
3896
|
-
const { N: o, r: c, p: i, dkLen: w, blockSize32: d, V: y, B32: x, B: v, tmp: E, blockMixCb: M } = Xa(t, e, r);
|
|
3897
|
-
Xe || je(x);
|
|
3898
|
-
for (let U = 0; U < i; U++) {
|
|
3899
|
-
const C = d * U;
|
|
3900
|
-
for (let k = 0; k < d; k++)
|
|
3901
|
-
y[k] = x[C + k];
|
|
3902
|
-
for (let k = 0, _ = 0; k < o - 1; k++)
|
|
3903
|
-
Vr(y, _, y, _ += d, c), M();
|
|
3904
|
-
Vr(y, (o - 1) * d, x, C, c), M();
|
|
3905
|
-
for (let k = 0; k < o; k++) {
|
|
3906
|
-
const _ = x[C + d - 16] % o;
|
|
3907
|
-
for (let S = 0; S < d; S++)
|
|
3908
|
-
E[S] = x[C + S] ^ y[_ * d + S];
|
|
3909
|
-
Vr(E, 0, x, C, c), M();
|
|
3910
|
-
}
|
|
3911
|
-
}
|
|
3912
|
-
return Xe || je(x), ja(t, w, v, y, E);
|
|
3913
|
-
}
|
|
3914
|
-
const Ye = {
|
|
3915
|
-
N: 32768,
|
|
3916
|
-
p: 1,
|
|
3917
|
-
r: 8
|
|
3918
|
-
};
|
|
3919
|
-
function co(t, e = wi(), r = Ye, o) {
|
|
3920
|
-
const c = V(t);
|
|
3921
|
-
return {
|
|
3922
|
-
params: r,
|
|
3923
|
-
password: !Ht || Vt() ? rs(c, e, Math.log2(r.N), r.r, r.p) : Ka(c, e, on({ dkLen: 64 }, r)),
|
|
3924
|
-
salt: e
|
|
3925
|
-
};
|
|
3926
|
-
}
|
|
3927
|
-
function Ga(t) {
|
|
3928
|
-
const e = t.subarray(0, 32), r = kr(t.subarray(32, 36), Rr).toNumber(), o = kr(t.subarray(36, 40), Rr).toNumber(), c = kr(t.subarray(40, 44), Rr).toNumber();
|
|
3929
|
-
if (r !== Ye.N || o !== Ye.p || c !== Ye.r)
|
|
3930
|
-
throw new Error("Invalid injected scrypt params found");
|
|
3931
|
-
return { params: { N: r, p: o, r: c }, salt: e };
|
|
3932
|
-
}
|
|
3933
|
-
function Wa(t, { N: e, p: r, r: o }) {
|
|
3934
|
-
return Ct(t, zt(e, Or), zt(r, Or), zt(o, Or));
|
|
3935
|
-
}
|
|
3936
|
-
const lo = ["scrypt", "xsalsa20-poly1305"], Ja = ["none"], Qa = "3", ri = 24, Fa = 32 + 3 * 4;
|
|
3937
|
-
function t0(t, e, r = lo) {
|
|
3938
|
-
if (t) {
|
|
3939
|
-
if (r.includes("xsalsa20-poly1305") && !e)
|
|
3940
|
-
throw new Error("Password required to decode encrypted data");
|
|
3941
|
-
} else throw new Error("No encrypted data available to decode");
|
|
3942
|
-
let o = t;
|
|
3943
|
-
if (e) {
|
|
3944
|
-
let c;
|
|
3945
|
-
if (r.includes("scrypt")) {
|
|
3946
|
-
const { params: i, salt: w } = Ga(t);
|
|
3947
|
-
c = co(e, w, i).password, t = t.subarray(Fa);
|
|
3948
|
-
} else
|
|
3949
|
-
c = ee(e);
|
|
3950
|
-
o = za(t.subarray(ri), t.subarray(0, ri), ys(c, 256, !0));
|
|
3951
|
-
}
|
|
3952
|
-
if (!o)
|
|
3953
|
-
throw new Error("Unable to decode using the supplied passphrase");
|
|
3954
|
-
return o;
|
|
3955
|
-
}
|
|
3956
|
-
function e0(t, e, r) {
|
|
3957
|
-
return {
|
|
3958
|
-
encoded: va(t),
|
|
3959
|
-
encoding: {
|
|
3960
|
-
content: e,
|
|
3961
|
-
type: r ? lo : Ja,
|
|
3962
|
-
version: Qa
|
|
3963
|
-
}
|
|
3964
|
-
};
|
|
3965
|
-
}
|
|
3966
|
-
const ni = (t) => (e, r, o) => _a(e, r, o, t), uo = [
|
|
3967
|
-
["ecdsa", ni("blake2")],
|
|
3968
|
-
["ethereum", ni("keccak")]
|
|
3969
|
-
], r0 = [
|
|
3970
|
-
["ed25519", zi],
|
|
3971
|
-
["sr25519", Gi],
|
|
3972
|
-
...uo
|
|
3973
|
-
], n0 = ["ed25519", "sr25519", "ecdsa"];
|
|
3974
|
-
function wo(t, { message: e, publicKey: r, signature: o }, c = r0) {
|
|
3975
|
-
return t.isValid = c.some(([i, w]) => {
|
|
3976
|
-
try {
|
|
3977
|
-
if (w(e, o, r))
|
|
3978
|
-
return t.crypto = i, !0;
|
|
3979
|
-
} catch {
|
|
3980
|
-
}
|
|
3981
|
-
return !1;
|
|
3982
|
-
}), t;
|
|
3983
|
-
}
|
|
3984
|
-
function i0(t, { message: e, publicKey: r, signature: o }) {
|
|
3985
|
-
if (![0, 1, 2].includes(o[0]))
|
|
3986
|
-
throw new Error(`Unknown crypto type, expected signature prefix [0..2], found ${o[0]}`);
|
|
3987
|
-
const c = n0[o[0]] || "none";
|
|
3988
|
-
t.crypto = c;
|
|
3989
|
-
try {
|
|
3990
|
-
t.isValid = {
|
|
3991
|
-
ecdsa: () => wo(t, { message: e, publicKey: r, signature: o.subarray(1) }, uo).isValid,
|
|
3992
|
-
ed25519: () => zi(e, o.subarray(1), r),
|
|
3993
|
-
none: () => {
|
|
3994
|
-
throw Error("no verify for `none` crypto type");
|
|
3995
|
-
},
|
|
3996
|
-
sr25519: () => Gi(e, o.subarray(1), r)
|
|
3997
|
-
}[c]();
|
|
3998
|
-
} catch {
|
|
3999
|
-
}
|
|
4000
|
-
return t;
|
|
4001
|
-
}
|
|
4002
|
-
function o0(t) {
|
|
4003
|
-
return [0, 1, 2].includes(t[0]) && [65, 66].includes(t.length) ? i0 : wo;
|
|
4004
|
-
}
|
|
4005
|
-
function ii(t, e, r) {
|
|
4006
|
-
const o = V(e);
|
|
4007
|
-
if (![64, 65, 66].includes(o.length))
|
|
4008
|
-
throw new Error(`Invalid signature length, expected [64..66] bytes, found ${o.length}`);
|
|
4009
|
-
const c = ge(r), i = { message: V(t), publicKey: c, signature: o }, w = { crypto: "none", isValid: !1, isWrapped: We(i.message, !0), publicKey: c }, d = We(i.message, !1), y = o0(o);
|
|
4010
|
-
return y(w, i), w.crypto !== "none" || w.isWrapped && !d ? w : (i.message = d ? bs(i.message) : xs(i.message), y(w, i));
|
|
4011
|
-
}
|
|
4012
|
-
const s0 = [as, $s], f0 = { name: "@polkadot/keyring", path: import.meta && import.meta.url ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf("/") + 1) : "auto", type: "esm", version: "12.6.2" };
|
|
4013
|
-
us(f0, null, s0);
|
|
4014
|
-
const ue = new Uint8Array([161, 35, 3, 33, 0]), er = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]), a0 = 32, oi = 64, h0 = 32, _e = er.length;
|
|
4015
|
-
function c0(t, e, r) {
|
|
4016
|
-
const o = Array.isArray(r) || r === void 0 ? r : [r], c = t0(e, t, o), i = c.subarray(0, er.length);
|
|
4017
|
-
if (!jt(i, er))
|
|
4018
|
-
throw new Error("Invalid Pkcs8 header found in body");
|
|
4019
|
-
let w = c.subarray(_e, _e + oi), d = _e + oi, y = c.subarray(d, d + ue.length);
|
|
4020
|
-
if (!jt(y, ue) && (d = _e + h0, w = c.subarray(_e, d), y = c.subarray(d, d + ue.length), !jt(y, ue)))
|
|
4021
|
-
throw new Error("Invalid Pkcs8 divider found in body");
|
|
4022
|
-
const x = d + ue.length;
|
|
4023
|
-
return {
|
|
4024
|
-
publicKey: c.subarray(x, x + a0),
|
|
4025
|
-
secretKey: w
|
|
4026
|
-
};
|
|
4027
|
-
}
|
|
4028
|
-
function l0({ publicKey: t, secretKey: e }, r) {
|
|
4029
|
-
if (!e)
|
|
4030
|
-
throw new Error("Expected a valid secretKey to be passed to encode");
|
|
4031
|
-
const o = Ct(er, e, ue, t);
|
|
4032
|
-
if (!r)
|
|
4033
|
-
return o;
|
|
4034
|
-
const { params: c, password: i, salt: w } = co(r), { encrypted: d, nonce: y } = Ya(o, i.subarray(0, 32));
|
|
4035
|
-
return Ct(Wa(w, c), y, d);
|
|
4036
|
-
}
|
|
4037
|
-
function u0(t, { address: e, meta: r }, o, c) {
|
|
4038
|
-
return on(e0(o, ["pkcs8", t], c), {
|
|
4039
|
-
address: e,
|
|
4040
|
-
meta: r
|
|
4041
|
-
});
|
|
4042
|
-
}
|
|
4043
|
-
const d0 = new Uint8Array(), w0 = {
|
|
4044
|
-
ecdsa: be,
|
|
4045
|
-
ed25519: gn,
|
|
4046
|
-
ethereum: be,
|
|
4047
|
-
sr25519: Ki
|
|
4048
|
-
}, si = {
|
|
4049
|
-
ecdsa: new Uint8Array([2]),
|
|
4050
|
-
ed25519: new Uint8Array([0]),
|
|
4051
|
-
ethereum: new Uint8Array([2]),
|
|
4052
|
-
sr25519: new Uint8Array([1])
|
|
4053
|
-
}, fi = {
|
|
4054
|
-
ecdsa: (t, e) => ti(t, e, "blake2"),
|
|
4055
|
-
ed25519: Gf,
|
|
4056
|
-
ethereum: (t, e) => ti(t, e, "keccak"),
|
|
4057
|
-
sr25519: na
|
|
4058
|
-
}, He = {
|
|
4059
|
-
ecdsa: (t) => t.length > 32 ? he(t) : t,
|
|
4060
|
-
ed25519: (t) => t,
|
|
4061
|
-
ethereum: (t) => t.length === 20 ? t : hr(pn(t)),
|
|
4062
|
-
sr25519: (t) => t
|
|
4063
|
-
};
|
|
4064
|
-
function Be(t) {
|
|
4065
|
-
return !t || bi(t);
|
|
4066
|
-
}
|
|
4067
|
-
function ai(t, e, r) {
|
|
4068
|
-
return he(Ct(e || "", r || "", t));
|
|
4069
|
-
}
|
|
4070
|
-
function de({ toSS58: t, type: e }, { publicKey: r, secretKey: o }, c = {}, i = null, w) {
|
|
4071
|
-
const d = (v, E) => {
|
|
4072
|
-
const M = c0(v, E || i, w);
|
|
4073
|
-
if (M.secretKey.length === 64)
|
|
4074
|
-
r = M.publicKey, o = M.secretKey;
|
|
4075
|
-
else {
|
|
4076
|
-
const U = w0[e](M.secretKey);
|
|
4077
|
-
r = U.publicKey, o = U.secretKey;
|
|
4078
|
-
}
|
|
4079
|
-
}, y = (v) => (Be(o) && i && d(v, i), i = l0({ publicKey: r, secretKey: o }, v), w = void 0, i), x = () => {
|
|
4080
|
-
const v = He[e](r);
|
|
4081
|
-
return e === "ethereum" ? ro(v) : t(v);
|
|
4082
|
-
};
|
|
4083
|
-
return {
|
|
4084
|
-
get address() {
|
|
4085
|
-
return x();
|
|
4086
|
-
},
|
|
4087
|
-
get addressRaw() {
|
|
4088
|
-
const v = He[e](r);
|
|
4089
|
-
return e === "ethereum" ? v.slice(-20) : v;
|
|
4090
|
-
},
|
|
4091
|
-
get isLocked() {
|
|
4092
|
-
return Be(o);
|
|
4093
|
-
},
|
|
4094
|
-
get meta() {
|
|
4095
|
-
return c;
|
|
4096
|
-
},
|
|
4097
|
-
get publicKey() {
|
|
4098
|
-
return r;
|
|
4099
|
-
},
|
|
4100
|
-
get type() {
|
|
4101
|
-
return e;
|
|
4102
|
-
},
|
|
4103
|
-
// eslint-disable-next-line sort-keys
|
|
4104
|
-
decodePkcs8: d,
|
|
4105
|
-
derive: (v, E) => {
|
|
4106
|
-
if (e === "ethereum")
|
|
4107
|
-
throw new Error("Unable to derive on this keypair");
|
|
4108
|
-
if (Be(o))
|
|
4109
|
-
throw new Error("Cannot derive on a locked keypair");
|
|
4110
|
-
const { path: M } = Li(v), U = ji({ publicKey: r, secretKey: o }, M, e);
|
|
4111
|
-
return de({ toSS58: t, type: e }, U, E, null);
|
|
4112
|
-
},
|
|
4113
|
-
encodePkcs8: (v) => y(v),
|
|
4114
|
-
lock: () => {
|
|
4115
|
-
o = new Uint8Array();
|
|
4116
|
-
},
|
|
4117
|
-
setMeta: (v) => {
|
|
4118
|
-
c = on({}, c, v);
|
|
4119
|
-
},
|
|
4120
|
-
sign: (v, E = {}) => {
|
|
4121
|
-
if (Be(o))
|
|
4122
|
-
throw new Error("Cannot sign with a locked key pair");
|
|
4123
|
-
return Ct(E.withType ? si[e] : d0, fi[e](V(v), { publicKey: r, secretKey: o }));
|
|
4124
|
-
},
|
|
4125
|
-
toJson: (v) => {
|
|
4126
|
-
const E = ["ecdsa", "ethereum"].includes(e) ? r.length === 20 ? Ae(r) : Ae(to(r)) : x();
|
|
4127
|
-
return u0(e, { address: E, meta: c }, y(v), !!v);
|
|
4128
|
-
},
|
|
4129
|
-
unlock: (v) => d(v),
|
|
4130
|
-
verify: (v, E, M) => ii(v, E, He[e](V(M))).isValid,
|
|
4131
|
-
vrfSign: (v, E, M) => {
|
|
4132
|
-
if (Be(o))
|
|
4133
|
-
throw new Error("Cannot sign with a locked key pair");
|
|
4134
|
-
if (e === "sr25519")
|
|
4135
|
-
return ia(v, { secretKey: o }, E, M);
|
|
4136
|
-
const U = fi[e](V(v), { publicKey: r, secretKey: o });
|
|
4137
|
-
return Ct(ai(U, E, M), U);
|
|
4138
|
-
},
|
|
4139
|
-
vrfVerify: (v, E, M, U, C) => e === "sr25519" ? oa(v, E, r, U, C) : ii(v, Ct(si[e], E.subarray(32)), He[e](V(M))).isValid && jt(E.subarray(0, 32), ai(E.subarray(32), U, C))
|
|
4140
|
-
};
|
|
4141
|
-
}
|
|
4142
|
-
const g0 = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
|
4143
|
-
class m0 {
|
|
4144
|
-
constructor() {
|
|
4145
|
-
Kt(this, "__internal__map", {});
|
|
4146
|
-
}
|
|
4147
|
-
add(e) {
|
|
4148
|
-
return this.__internal__map[ge(e.address).toString()] = e, e;
|
|
4149
|
-
}
|
|
4150
|
-
all() {
|
|
4151
|
-
return Object.values(this.__internal__map);
|
|
4152
|
-
}
|
|
4153
|
-
get(e) {
|
|
4154
|
-
const r = this.__internal__map[ge(e).toString()];
|
|
4155
|
-
if (!r)
|
|
4156
|
-
throw new Error(`Unable to retrieve keypair '${oe(e) || te(e) ? Ae(V(e)) : e}'`);
|
|
4157
|
-
return r;
|
|
4158
|
-
}
|
|
4159
|
-
remove(e) {
|
|
4160
|
-
delete this.__internal__map[ge(e).toString()];
|
|
4161
|
-
}
|
|
4162
|
-
}
|
|
4163
|
-
const zr = {
|
|
4164
|
-
ecdsa: (t) => be(t),
|
|
4165
|
-
ed25519: (t) => gn(t),
|
|
4166
|
-
ethereum: (t) => be(t),
|
|
4167
|
-
sr25519: (t) => Ki(t)
|
|
4168
|
-
};
|
|
4169
|
-
function p0({ publicKey: t }) {
|
|
4170
|
-
return t;
|
|
4171
|
-
}
|
|
4172
|
-
class L0 {
|
|
4173
|
-
constructor(e = {}) {
|
|
4174
|
-
Kt(this, "__internal__pairs");
|
|
4175
|
-
Kt(this, "__internal__type");
|
|
4176
|
-
Kt(this, "__internal__ss58");
|
|
4177
|
-
Kt(this, "decodeAddress", ge);
|
|
4178
|
-
/**
|
|
4179
|
-
* @name encodeAddress
|
|
4180
|
-
* @description Encodes the input into an ss58 representation
|
|
4181
|
-
*/
|
|
4182
|
-
Kt(this, "encodeAddress", (e, r) => this.type === "ethereum" ? ro(e) : sa(e, r ?? this.__internal__ss58));
|
|
4183
|
-
if (e.type = e.type || "ed25519", !["ecdsa", "ethereum", "ed25519", "sr25519"].includes(e.type || "undefined"))
|
|
4184
|
-
throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${e.type || "unknown"}`);
|
|
4185
|
-
this.__internal__pairs = new m0(), this.__internal__ss58 = e.ss58Format, this.__internal__type = e.type;
|
|
4186
|
-
}
|
|
4187
|
-
/**
|
|
4188
|
-
* @description retrieve the pairs (alias for getPairs)
|
|
4189
|
-
*/
|
|
4190
|
-
get pairs() {
|
|
4191
|
-
return this.getPairs();
|
|
4192
|
-
}
|
|
4193
|
-
/**
|
|
4194
|
-
* @description retrieve the publicKeys (alias for getPublicKeys)
|
|
4195
|
-
*/
|
|
4196
|
-
get publicKeys() {
|
|
4197
|
-
return this.getPublicKeys();
|
|
4198
|
-
}
|
|
4199
|
-
/**
|
|
4200
|
-
* @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
|
|
4201
|
-
*/
|
|
4202
|
-
get type() {
|
|
4203
|
-
return this.__internal__type;
|
|
4204
|
-
}
|
|
4205
|
-
/**
|
|
4206
|
-
* @name addPair
|
|
4207
|
-
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
4208
|
-
*/
|
|
4209
|
-
addPair(e) {
|
|
4210
|
-
return this.__internal__pairs.add(e);
|
|
4211
|
-
}
|
|
4212
|
-
/**
|
|
4213
|
-
* @name addFromAddress
|
|
4214
|
-
* @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
4215
|
-
* @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
|
|
4216
|
-
* the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
|
|
4217
|
-
* of an account backup), and then generates a keyring pair from them that it passes to
|
|
4218
|
-
* `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
|
4219
|
-
*/
|
|
4220
|
-
addFromAddress(e, r = {}, o = null, c = this.type, i, w) {
|
|
4221
|
-
const d = this.decodeAddress(e, i);
|
|
4222
|
-
return this.addPair(de({ toSS58: this.encodeAddress, type: c }, { publicKey: d, secretKey: new Uint8Array() }, r, o, w));
|
|
4223
|
-
}
|
|
4224
|
-
/**
|
|
4225
|
-
* @name addFromJson
|
|
4226
|
-
* @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
4227
|
-
* @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
|
|
4228
|
-
* of an account backup), and then generates a keyring pair from it that it passes to
|
|
4229
|
-
* `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
|
4230
|
-
*/
|
|
4231
|
-
addFromJson(e, r) {
|
|
4232
|
-
return this.addPair(this.createFromJson(e, r));
|
|
4233
|
-
}
|
|
4234
|
-
/**
|
|
4235
|
-
* @name addFromMnemonic
|
|
4236
|
-
* @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
4237
|
-
* @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
|
|
4238
|
-
* argument and a metadata argument that contains account information (that may be obtained from the json file
|
|
4239
|
-
* of an account backup), and then generates a keyring pair from it that it passes to
|
|
4240
|
-
* `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
|
4241
|
-
*/
|
|
4242
|
-
addFromMnemonic(e, r = {}, o = this.type) {
|
|
4243
|
-
return this.addFromUri(e, r, o);
|
|
4244
|
-
}
|
|
4245
|
-
/**
|
|
4246
|
-
* @name addFromPair
|
|
4247
|
-
* @summary Stores an account created from an explicit publicKey/secreteKey combination
|
|
4248
|
-
*/
|
|
4249
|
-
addFromPair(e, r = {}, o = this.type) {
|
|
4250
|
-
return this.addPair(this.createFromPair(e, r, o));
|
|
4251
|
-
}
|
|
4252
|
-
/**
|
|
4253
|
-
* @name addFromSeed
|
|
4254
|
-
* @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
4255
|
-
* @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
|
|
4256
|
-
* Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
|
|
4257
|
-
* `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
|
4258
|
-
*/
|
|
4259
|
-
addFromSeed(e, r = {}, o = this.type) {
|
|
4260
|
-
return this.addPair(de({ toSS58: this.encodeAddress, type: o }, zr[o](e), r, null));
|
|
4261
|
-
}
|
|
4262
|
-
/**
|
|
4263
|
-
* @name addFromUri
|
|
4264
|
-
* @summary Creates an account via an suri
|
|
4265
|
-
* @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
|
|
4266
|
-
*/
|
|
4267
|
-
addFromUri(e, r = {}, o = this.type) {
|
|
4268
|
-
return this.addPair(this.createFromUri(e, r, o));
|
|
4269
|
-
}
|
|
4270
|
-
/**
|
|
4271
|
-
* @name createFromJson
|
|
4272
|
-
* @description Creates a pair from a JSON keyfile
|
|
4273
|
-
*/
|
|
4274
|
-
createFromJson({ address: e, encoded: r, encoding: { content: o, type: c, version: i }, meta: w }, d) {
|
|
4275
|
-
if (i === "3" && o[0] !== "pkcs8")
|
|
4276
|
-
throw new Error(`Unable to decode non-pkcs8 type, [${o.join(",")}] found}`);
|
|
4277
|
-
const y = i === "0" || !Array.isArray(o) ? this.type : o[1], x = Array.isArray(c) ? c : [c];
|
|
4278
|
-
if (!["ed25519", "sr25519", "ecdsa", "ethereum"].includes(y))
|
|
4279
|
-
throw new Error(`Unknown crypto type ${y}`);
|
|
4280
|
-
const v = te(e) ? Se(e) : this.decodeAddress(e, d), E = te(r) ? Se(r) : ya(r);
|
|
4281
|
-
return de({ toSS58: this.encodeAddress, type: y }, { publicKey: v, secretKey: new Uint8Array() }, w, E, x);
|
|
4282
|
-
}
|
|
4283
|
-
/**
|
|
4284
|
-
* @name createFromPair
|
|
4285
|
-
* @summary Creates a pair from an explicit publicKey/secreteKey combination
|
|
4286
|
-
*/
|
|
4287
|
-
createFromPair(e, r = {}, o = this.type) {
|
|
4288
|
-
return de({ toSS58: this.encodeAddress, type: o }, e, r, null);
|
|
4289
|
-
}
|
|
4290
|
-
/**
|
|
4291
|
-
* @name createFromUri
|
|
4292
|
-
* @summary Creates a Keypair from an suri
|
|
4293
|
-
* @description This creates a pair from the suri, but does not add it to the keyring
|
|
4294
|
-
*/
|
|
4295
|
-
createFromUri(e, r = {}, o = this.type) {
|
|
4296
|
-
const c = e.startsWith("//") ? `${g0}${e}` : e, { derivePath: i, password: w, path: d, phrase: y } = tf(c);
|
|
4297
|
-
let x;
|
|
4298
|
-
const v = te(y, 256);
|
|
4299
|
-
if (v)
|
|
4300
|
-
x = Se(y);
|
|
4301
|
-
else {
|
|
4302
|
-
const M = y.split(" ");
|
|
4303
|
-
if ([12, 15, 18, 21, 24].includes(M.length))
|
|
4304
|
-
x = o === "ethereum" ? Ra(y, "", !1, 64) : Oa(y, w);
|
|
4305
|
-
else {
|
|
4306
|
-
if (y.length > 32)
|
|
4307
|
-
throw new Error("specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes");
|
|
4308
|
-
x = ee(y.padEnd(32));
|
|
4309
|
-
}
|
|
4310
|
-
}
|
|
4311
|
-
const E = o === "ethereum" ? v ? zr[o](x) : Ua(x, i.substring(1)) : ji(zr[o](x), d, o);
|
|
4312
|
-
return de({ toSS58: this.encodeAddress, type: o }, E, r, null);
|
|
4313
|
-
}
|
|
4314
|
-
/**
|
|
4315
|
-
* @name getPair
|
|
4316
|
-
* @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
|
|
4317
|
-
* @description Returns a keyring pair value from the keyring pair dictionary by performing
|
|
4318
|
-
* a key lookup using the provided account address or public key (after decoding it).
|
|
4319
|
-
*/
|
|
4320
|
-
getPair(e) {
|
|
4321
|
-
return this.__internal__pairs.get(e);
|
|
4322
|
-
}
|
|
4323
|
-
/**
|
|
4324
|
-
* @name getPairs
|
|
4325
|
-
* @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
|
|
4326
|
-
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
|
4327
|
-
*/
|
|
4328
|
-
getPairs() {
|
|
4329
|
-
return this.__internal__pairs.all();
|
|
4330
|
-
}
|
|
4331
|
-
/**
|
|
4332
|
-
* @name getPublicKeys
|
|
4333
|
-
* @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
|
|
4334
|
-
* @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
|
|
4335
|
-
*/
|
|
4336
|
-
getPublicKeys() {
|
|
4337
|
-
return this.__internal__pairs.all().map(p0);
|
|
4338
|
-
}
|
|
4339
|
-
/**
|
|
4340
|
-
* @name removePair
|
|
4341
|
-
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
|
4342
|
-
*/
|
|
4343
|
-
removePair(e) {
|
|
4344
|
-
this.__internal__pairs.remove(e);
|
|
4345
|
-
}
|
|
4346
|
-
/**
|
|
4347
|
-
* @name setSS58Format;
|
|
4348
|
-
* @description Sets the ss58 format for the keyring
|
|
4349
|
-
*/
|
|
4350
|
-
setSS58Format(e) {
|
|
4351
|
-
this.__internal__ss58 = e;
|
|
4352
|
-
}
|
|
4353
|
-
/**
|
|
4354
|
-
* @name toJson
|
|
4355
|
-
* @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
|
|
4356
|
-
* @description Returns a JSON object containing the metadata associated with an account
|
|
4357
|
-
* when valid address or public key and when the account passphrase is provided if the account secret
|
|
4358
|
-
* is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
|
|
4359
|
-
* may backup their account to a JSON file that contains this information.
|
|
4360
|
-
*/
|
|
4361
|
-
toJson(e, r) {
|
|
4362
|
-
return this.__internal__pairs.get(e).toJson(r);
|
|
4363
|
-
}
|
|
4364
|
-
}
|
|
4365
|
-
export {
|
|
4366
|
-
g0 as DEV_PHRASE,
|
|
4367
|
-
L0 as Keyring,
|
|
4368
|
-
de as createPair,
|
|
4369
|
-
ge as decodeAddress,
|
|
4370
|
-
L0 as default,
|
|
4371
|
-
sa as encodeAddress,
|
|
4372
|
-
f0 as packageInfo
|
|
4373
|
-
};
|