shogun-core 5.2.0 → 5.2.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.
Files changed (185) hide show
  1. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
  2. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
  3. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
  4. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
  5. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
  6. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
  7. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
  8. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
  9. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
  10. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
  11. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
  12. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
  13. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
  14. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
  15. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
  16. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
  17. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
  18. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
  19. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
  20. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
  21. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
  22. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
  23. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
  24. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
  25. package/dist/browser/shogun-core.js +160386 -0
  26. package/dist/browser/shogun-core.js.map +1 -0
  27. package/dist/config/simplified-config.js +236 -0
  28. package/dist/core.js +329 -0
  29. package/dist/crypto/asymmetric.js +99 -0
  30. package/dist/crypto/double-ratchet.js +370 -0
  31. package/dist/crypto/file-encryption.js +213 -0
  32. package/dist/crypto/hashing.js +87 -0
  33. package/dist/crypto/index.js +34 -0
  34. package/dist/crypto/mls-codec.js +202 -0
  35. package/dist/crypto/mls.js +550 -0
  36. package/dist/crypto/pgp.js +390 -0
  37. package/dist/crypto/random-generation.js +341 -0
  38. package/dist/crypto/sframe.js +350 -0
  39. package/dist/crypto/signal-protocol.js +376 -0
  40. package/dist/crypto/symmetric.js +91 -0
  41. package/dist/crypto/types.js +2 -0
  42. package/dist/crypto/utils.js +140 -0
  43. package/dist/examples/auth-test.js +253 -0
  44. package/dist/examples/crypto-identity-example.js +151 -0
  45. package/dist/examples/crypto-working-test.js +83 -0
  46. package/dist/examples/double-ratchet-test.js +155 -0
  47. package/dist/examples/mls-advanced-example.js +294 -0
  48. package/dist/examples/mls-sframe-test.js +304 -0
  49. package/dist/examples/pgp-example.js +200 -0
  50. package/dist/examples/quick-auth-test.js +61 -0
  51. package/dist/examples/random-generation-test.js +151 -0
  52. package/dist/examples/signal-protocol-test.js +38 -0
  53. package/dist/examples/simple-api-test.js +114 -0
  54. package/dist/examples/simple-crypto-identity-example.js +84 -0
  55. package/dist/examples/timeout-test.js +227 -0
  56. package/dist/examples/zkproof-credentials-example.js +212 -0
  57. package/dist/examples/zkproof-example.js +201 -0
  58. package/dist/gundb/api.js +435 -0
  59. package/dist/gundb/crypto.js +283 -0
  60. package/dist/gundb/db.js +1946 -0
  61. package/dist/gundb/derive.js +232 -0
  62. package/dist/gundb/errors.js +76 -0
  63. package/dist/gundb/index.js +22 -0
  64. package/dist/gundb/rxjs.js +447 -0
  65. package/dist/gundb/types.js +5 -0
  66. package/dist/index.js +58 -0
  67. package/dist/interfaces/common.js +2 -0
  68. package/dist/interfaces/events.js +40 -0
  69. package/dist/interfaces/plugin.js +2 -0
  70. package/dist/interfaces/shogun.js +37 -0
  71. package/dist/managers/AuthManager.js +226 -0
  72. package/dist/managers/CoreInitializer.js +228 -0
  73. package/dist/managers/CryptoIdentityManager.js +366 -0
  74. package/dist/managers/EventManager.js +70 -0
  75. package/dist/managers/PluginManager.js +299 -0
  76. package/dist/plugins/base.js +50 -0
  77. package/dist/plugins/index.js +32 -0
  78. package/dist/plugins/nostr/index.js +20 -0
  79. package/dist/plugins/nostr/nostrConnector.js +419 -0
  80. package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
  81. package/dist/plugins/nostr/nostrSigner.js +319 -0
  82. package/dist/plugins/nostr/types.js +2 -0
  83. package/dist/plugins/smartwallet/index.js +18 -0
  84. package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
  85. package/dist/plugins/smartwallet/types.js +2 -0
  86. package/dist/plugins/web3/index.js +20 -0
  87. package/dist/plugins/web3/types.js +2 -0
  88. package/dist/plugins/web3/web3Connector.js +533 -0
  89. package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
  90. package/dist/plugins/web3/web3Signer.js +314 -0
  91. package/dist/plugins/webauthn/index.js +19 -0
  92. package/dist/plugins/webauthn/types.js +14 -0
  93. package/dist/plugins/webauthn/webauthn.js +496 -0
  94. package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
  95. package/dist/plugins/webauthn/webauthnSigner.js +310 -0
  96. package/dist/plugins/zkproof/index.js +53 -0
  97. package/dist/plugins/zkproof/types.js +2 -0
  98. package/dist/plugins/zkproof/zkCredentials.js +213 -0
  99. package/dist/plugins/zkproof/zkProofConnector.js +198 -0
  100. package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
  101. package/dist/storage/storage.js +145 -0
  102. package/dist/types/config/simplified-config.d.ts +114 -0
  103. package/dist/types/core.d.ts +305 -0
  104. package/dist/types/crypto/asymmetric.d.ts +6 -0
  105. package/dist/types/crypto/double-ratchet.d.ts +22 -0
  106. package/dist/types/crypto/file-encryption.d.ts +19 -0
  107. package/dist/types/crypto/hashing.d.ts +9 -0
  108. package/dist/types/crypto/index.d.ts +13 -0
  109. package/dist/types/crypto/mls-codec.d.ts +39 -0
  110. package/dist/types/crypto/mls.d.ts +130 -0
  111. package/dist/types/crypto/pgp.d.ts +95 -0
  112. package/dist/types/crypto/random-generation.d.ts +35 -0
  113. package/dist/types/crypto/sframe.d.ts +102 -0
  114. package/dist/types/crypto/signal-protocol.d.ts +26 -0
  115. package/dist/types/crypto/symmetric.d.ts +9 -0
  116. package/dist/types/crypto/types.d.ts +144 -0
  117. package/dist/types/crypto/utils.d.ts +22 -0
  118. package/dist/types/examples/auth-test.d.ts +8 -0
  119. package/dist/types/examples/crypto-identity-example.d.ts +5 -0
  120. package/dist/types/examples/crypto-working-test.d.ts +1 -0
  121. package/dist/types/examples/double-ratchet-test.d.ts +1 -0
  122. package/dist/types/examples/mls-advanced-example.d.ts +53 -0
  123. package/dist/types/examples/mls-sframe-test.d.ts +1 -0
  124. package/dist/types/examples/pgp-example.d.ts +75 -0
  125. package/dist/types/examples/quick-auth-test.d.ts +8 -0
  126. package/dist/types/examples/random-generation-test.d.ts +1 -0
  127. package/dist/types/examples/signal-protocol-test.d.ts +1 -0
  128. package/dist/types/examples/simple-api-test.d.ts +10 -0
  129. package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
  130. package/dist/types/examples/timeout-test.d.ts +8 -0
  131. package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
  132. package/dist/types/examples/zkproof-example.d.ts +11 -0
  133. package/dist/types/gundb/api.d.ts +185 -0
  134. package/dist/types/gundb/crypto.d.ts +95 -0
  135. package/dist/types/gundb/db.d.ts +397 -0
  136. package/dist/types/gundb/derive.d.ts +21 -0
  137. package/dist/types/gundb/errors.d.ts +42 -0
  138. package/dist/types/gundb/index.d.ts +3 -0
  139. package/dist/types/gundb/rxjs.d.ts +110 -0
  140. package/dist/types/gundb/types.d.ts +255 -0
  141. package/dist/types/index.d.ts +16 -0
  142. package/dist/types/interfaces/common.d.ts +85 -0
  143. package/dist/types/interfaces/events.d.ts +131 -0
  144. package/dist/types/interfaces/plugin.d.ts +162 -0
  145. package/dist/types/interfaces/shogun.d.ts +208 -0
  146. package/dist/types/managers/AuthManager.d.ts +72 -0
  147. package/dist/types/managers/CoreInitializer.d.ts +40 -0
  148. package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
  149. package/dist/types/managers/EventManager.d.ts +49 -0
  150. package/dist/types/managers/PluginManager.d.ts +145 -0
  151. package/dist/types/plugins/base.d.ts +35 -0
  152. package/dist/types/plugins/index.d.ts +18 -0
  153. package/dist/types/plugins/nostr/index.d.ts +4 -0
  154. package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
  155. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
  156. package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
  157. package/dist/types/plugins/nostr/types.d.ts +122 -0
  158. package/dist/types/plugins/smartwallet/index.d.ts +2 -0
  159. package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
  160. package/dist/types/plugins/smartwallet/types.d.ts +80 -0
  161. package/dist/types/plugins/web3/index.d.ts +4 -0
  162. package/dist/types/plugins/web3/types.d.ts +107 -0
  163. package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
  164. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
  165. package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
  166. package/dist/types/plugins/webauthn/index.d.ts +3 -0
  167. package/dist/types/plugins/webauthn/types.d.ts +183 -0
  168. package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
  169. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
  170. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
  171. package/dist/types/plugins/zkproof/index.d.ts +48 -0
  172. package/dist/types/plugins/zkproof/types.d.ts +123 -0
  173. package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
  174. package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
  175. package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
  176. package/dist/types/storage/storage.d.ts +51 -0
  177. package/dist/types/utils/errorHandler.d.ts +119 -0
  178. package/dist/types/utils/eventEmitter.d.ts +39 -0
  179. package/dist/types/utils/seedPhrase.d.ts +50 -0
  180. package/dist/types/utils/validation.d.ts +27 -0
  181. package/dist/utils/errorHandler.js +246 -0
  182. package/dist/utils/eventEmitter.js +79 -0
  183. package/dist/utils/seedPhrase.js +97 -0
  184. package/dist/utils/validation.js +81 -0
  185. package/package.json +10 -1
@@ -0,0 +1,825 @@
1
+ "use strict";
2
+ (this["webpackChunkShogunCore"] = this["webpackChunkShogunCore"] || []).push([["defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056"],{
3
+
4
+ /***/ "./node_modules/@noble/curves/esm/abstract/edwards.js":
5
+ /*!************************************************************!*\
6
+ !*** ./node_modules/@noble/curves/esm/abstract/edwards.js ***!
7
+ \************************************************************/
8
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
9
+
10
+ __webpack_require__.r(__webpack_exports__);
11
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
12
+ /* harmony export */ PrimeEdwardsPoint: () => (/* binding */ PrimeEdwardsPoint),
13
+ /* harmony export */ eddsa: () => (/* binding */ eddsa),
14
+ /* harmony export */ edwards: () => (/* binding */ edwards),
15
+ /* harmony export */ twistedEdwards: () => (/* binding */ twistedEdwards)
16
+ /* harmony export */ });
17
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils.js */ "./node_modules/@noble/curves/esm/utils.js");
18
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils.js */ "./node_modules/@noble/hashes/esm/utils.js");
19
+ /* harmony import */ var _curve_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./curve.js */ "./node_modules/@noble/curves/esm/abstract/curve.js");
20
+ /* harmony import */ var _modular_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./modular.js */ "./node_modules/@noble/curves/esm/abstract/modular.js");
21
+ /**
22
+ * Twisted Edwards curve. The formula is: ax² + y² = 1 + dx²y².
23
+ * For design rationale of types / exports, see weierstrass module documentation.
24
+ * Untwisted Edwards curves exist, but they aren't used in real-world protocols.
25
+ * @module
26
+ */
27
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
28
+
29
+
30
+
31
+ // Be friendly to bad ECMAScript parsers by not using bigint literals
32
+ // prettier-ignore
33
+ const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _8n = BigInt(8);
34
+ function isEdValidXY(Fp, CURVE, x, y) {
35
+ const x2 = Fp.sqr(x);
36
+ const y2 = Fp.sqr(y);
37
+ const left = Fp.add(Fp.mul(CURVE.a, x2), y2);
38
+ const right = Fp.add(Fp.ONE, Fp.mul(CURVE.d, Fp.mul(x2, y2)));
39
+ return Fp.eql(left, right);
40
+ }
41
+ function edwards(params, extraOpts = {}) {
42
+ const validated = (0,_curve_js__WEBPACK_IMPORTED_MODULE_2__._createCurveFields)('edwards', params, extraOpts, extraOpts.FpFnLE);
43
+ const { Fp, Fn } = validated;
44
+ let CURVE = validated.CURVE;
45
+ const { h: cofactor } = CURVE;
46
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._validateObject)(extraOpts, {}, { uvRatio: 'function' });
47
+ // Important:
48
+ // There are some places where Fp.BYTES is used instead of nByteLength.
49
+ // So far, everything has been tested with curves of Fp.BYTES == nByteLength.
50
+ // TODO: test and find curves which behave otherwise.
51
+ const MASK = _2n << (BigInt(Fn.BYTES * 8) - _1n);
52
+ const modP = (n) => Fp.create(n); // Function overrides
53
+ // sqrt(u/v)
54
+ const uvRatio = extraOpts.uvRatio ||
55
+ ((u, v) => {
56
+ try {
57
+ return { isValid: true, value: Fp.sqrt(Fp.div(u, v)) };
58
+ }
59
+ catch (e) {
60
+ return { isValid: false, value: _0n };
61
+ }
62
+ });
63
+ // Validate whether the passed curve params are valid.
64
+ // equation ax² + y² = 1 + dx²y² should work for generator point.
65
+ if (!isEdValidXY(Fp, CURVE, CURVE.Gx, CURVE.Gy))
66
+ throw new Error('bad curve params: generator point');
67
+ /**
68
+ * Asserts coordinate is valid: 0 <= n < MASK.
69
+ * Coordinates >= Fp.ORDER are allowed for zip215.
70
+ */
71
+ function acoord(title, n, banZero = false) {
72
+ const min = banZero ? _1n : _0n;
73
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.aInRange)('coordinate ' + title, n, min, MASK);
74
+ return n;
75
+ }
76
+ function aextpoint(other) {
77
+ if (!(other instanceof Point))
78
+ throw new Error('ExtendedPoint expected');
79
+ }
80
+ // Converts Extended point to default (x, y) coordinates.
81
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
82
+ const toAffineMemo = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.memoized)((p, iz) => {
83
+ const { X, Y, Z } = p;
84
+ const is0 = p.is0();
85
+ if (iz == null)
86
+ iz = is0 ? _8n : Fp.inv(Z); // 8 was chosen arbitrarily
87
+ const x = modP(X * iz);
88
+ const y = modP(Y * iz);
89
+ const zz = Fp.mul(Z, iz);
90
+ if (is0)
91
+ return { x: _0n, y: _1n };
92
+ if (zz !== _1n)
93
+ throw new Error('invZ was invalid');
94
+ return { x, y };
95
+ });
96
+ const assertValidMemo = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.memoized)((p) => {
97
+ const { a, d } = CURVE;
98
+ if (p.is0())
99
+ throw new Error('bad point: ZERO'); // TODO: optimize, with vars below?
100
+ // Equation in affine coordinates: ax² + y² = 1 + dx²y²
101
+ // Equation in projective coordinates (X/Z, Y/Z, Z): (aX² + Y²)Z² = Z⁴ + dX²Y²
102
+ const { X, Y, Z, T } = p;
103
+ const X2 = modP(X * X); // X²
104
+ const Y2 = modP(Y * Y); // Y²
105
+ const Z2 = modP(Z * Z); // Z²
106
+ const Z4 = modP(Z2 * Z2); // Z⁴
107
+ const aX2 = modP(X2 * a); // aX²
108
+ const left = modP(Z2 * modP(aX2 + Y2)); // (aX² + Y²)Z²
109
+ const right = modP(Z4 + modP(d * modP(X2 * Y2))); // Z⁴ + dX²Y²
110
+ if (left !== right)
111
+ throw new Error('bad point: equation left != right (1)');
112
+ // In Extended coordinates we also have T, which is x*y=T/Z: check X*Y == Z*T
113
+ const XY = modP(X * Y);
114
+ const ZT = modP(Z * T);
115
+ if (XY !== ZT)
116
+ throw new Error('bad point: equation left != right (2)');
117
+ return true;
118
+ });
119
+ // Extended Point works in extended coordinates: (X, Y, Z, T) ∋ (x=X/Z, y=Y/Z, T=xy).
120
+ // https://en.wikipedia.org/wiki/Twisted_Edwards_curve#Extended_coordinates
121
+ class Point {
122
+ constructor(X, Y, Z, T) {
123
+ this.X = acoord('x', X);
124
+ this.Y = acoord('y', Y);
125
+ this.Z = acoord('z', Z, true);
126
+ this.T = acoord('t', T);
127
+ Object.freeze(this);
128
+ }
129
+ static CURVE() {
130
+ return CURVE;
131
+ }
132
+ static fromAffine(p) {
133
+ if (p instanceof Point)
134
+ throw new Error('extended point not allowed');
135
+ const { x, y } = p || {};
136
+ acoord('x', x);
137
+ acoord('y', y);
138
+ return new Point(x, y, _1n, modP(x * y));
139
+ }
140
+ // Uses algo from RFC8032 5.1.3.
141
+ static fromBytes(bytes, zip215 = false) {
142
+ const len = Fp.BYTES;
143
+ const { a, d } = CURVE;
144
+ bytes = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.copyBytes)((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abytes2)(bytes, len, 'point'));
145
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abool2)(zip215, 'zip215');
146
+ const normed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.copyBytes)(bytes); // copy again, we'll manipulate it
147
+ const lastByte = bytes[len - 1]; // select last byte
148
+ normed[len - 1] = lastByte & ~0x80; // clear last bit
149
+ const y = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.bytesToNumberLE)(normed);
150
+ // zip215=true is good for consensus-critical apps. =false follows RFC8032 / NIST186-5.
151
+ // RFC8032 prohibits >= p, but ZIP215 doesn't
152
+ // zip215=true: 0 <= y < MASK (2^256 for ed25519)
153
+ // zip215=false: 0 <= y < P (2^255-19 for ed25519)
154
+ const max = zip215 ? MASK : Fp.ORDER;
155
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.aInRange)('point.y', y, _0n, max);
156
+ // Ed25519: x² = (y²-1)/(dy²+1) mod p. Ed448: x² = (y²-1)/(dy²-1) mod p. Generic case:
157
+ // ax²+y²=1+dx²y² => y²-1=dx²y²-ax² => y²-1=x²(dy²-a) => x²=(y²-1)/(dy²-a)
158
+ const y2 = modP(y * y); // denominator is always non-0 mod p.
159
+ const u = modP(y2 - _1n); // u = y² - 1
160
+ const v = modP(d * y2 - a); // v = d y² + 1.
161
+ let { isValid, value: x } = uvRatio(u, v); // √(u/v)
162
+ if (!isValid)
163
+ throw new Error('bad point: invalid y coordinate');
164
+ const isXOdd = (x & _1n) === _1n; // There are 2 square roots. Use x_0 bit to select proper
165
+ const isLastByteOdd = (lastByte & 0x80) !== 0; // x_0, last bit
166
+ if (!zip215 && x === _0n && isLastByteOdd)
167
+ // if x=0 and x_0 = 1, fail
168
+ throw new Error('bad point: x=0 and x_0=1');
169
+ if (isLastByteOdd !== isXOdd)
170
+ x = modP(-x); // if x_0 != x mod 2, set x = p-x
171
+ return Point.fromAffine({ x, y });
172
+ }
173
+ static fromHex(bytes, zip215 = false) {
174
+ return Point.fromBytes((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('point', bytes), zip215);
175
+ }
176
+ get x() {
177
+ return this.toAffine().x;
178
+ }
179
+ get y() {
180
+ return this.toAffine().y;
181
+ }
182
+ precompute(windowSize = 8, isLazy = true) {
183
+ wnaf.createCache(this, windowSize);
184
+ if (!isLazy)
185
+ this.multiply(_2n); // random number
186
+ return this;
187
+ }
188
+ // Useful in fromAffine() - not for fromBytes(), which always created valid points.
189
+ assertValidity() {
190
+ assertValidMemo(this);
191
+ }
192
+ // Compare one point to another.
193
+ equals(other) {
194
+ aextpoint(other);
195
+ const { X: X1, Y: Y1, Z: Z1 } = this;
196
+ const { X: X2, Y: Y2, Z: Z2 } = other;
197
+ const X1Z2 = modP(X1 * Z2);
198
+ const X2Z1 = modP(X2 * Z1);
199
+ const Y1Z2 = modP(Y1 * Z2);
200
+ const Y2Z1 = modP(Y2 * Z1);
201
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
202
+ }
203
+ is0() {
204
+ return this.equals(Point.ZERO);
205
+ }
206
+ negate() {
207
+ // Flips point sign to a negative one (-x, y in affine coords)
208
+ return new Point(modP(-this.X), this.Y, this.Z, modP(-this.T));
209
+ }
210
+ // Fast algo for doubling Extended Point.
211
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
212
+ // Cost: 4M + 4S + 1*a + 6add + 1*2.
213
+ double() {
214
+ const { a } = CURVE;
215
+ const { X: X1, Y: Y1, Z: Z1 } = this;
216
+ const A = modP(X1 * X1); // A = X12
217
+ const B = modP(Y1 * Y1); // B = Y12
218
+ const C = modP(_2n * modP(Z1 * Z1)); // C = 2*Z12
219
+ const D = modP(a * A); // D = a*A
220
+ const x1y1 = X1 + Y1;
221
+ const E = modP(modP(x1y1 * x1y1) - A - B); // E = (X1+Y1)2-A-B
222
+ const G = D + B; // G = D+B
223
+ const F = G - C; // F = G-C
224
+ const H = D - B; // H = D-B
225
+ const X3 = modP(E * F); // X3 = E*F
226
+ const Y3 = modP(G * H); // Y3 = G*H
227
+ const T3 = modP(E * H); // T3 = E*H
228
+ const Z3 = modP(F * G); // Z3 = F*G
229
+ return new Point(X3, Y3, Z3, T3);
230
+ }
231
+ // Fast algo for adding 2 Extended Points.
232
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
233
+ // Cost: 9M + 1*a + 1*d + 7add.
234
+ add(other) {
235
+ aextpoint(other);
236
+ const { a, d } = CURVE;
237
+ const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
238
+ const { X: X2, Y: Y2, Z: Z2, T: T2 } = other;
239
+ const A = modP(X1 * X2); // A = X1*X2
240
+ const B = modP(Y1 * Y2); // B = Y1*Y2
241
+ const C = modP(T1 * d * T2); // C = T1*d*T2
242
+ const D = modP(Z1 * Z2); // D = Z1*Z2
243
+ const E = modP((X1 + Y1) * (X2 + Y2) - A - B); // E = (X1+Y1)*(X2+Y2)-A-B
244
+ const F = D - C; // F = D-C
245
+ const G = D + C; // G = D+C
246
+ const H = modP(B - a * A); // H = B-a*A
247
+ const X3 = modP(E * F); // X3 = E*F
248
+ const Y3 = modP(G * H); // Y3 = G*H
249
+ const T3 = modP(E * H); // T3 = E*H
250
+ const Z3 = modP(F * G); // Z3 = F*G
251
+ return new Point(X3, Y3, Z3, T3);
252
+ }
253
+ subtract(other) {
254
+ return this.add(other.negate());
255
+ }
256
+ // Constant-time multiplication.
257
+ multiply(scalar) {
258
+ // 1 <= scalar < L
259
+ if (!Fn.isValidNot0(scalar))
260
+ throw new Error('invalid scalar: expected 1 <= sc < curve.n');
261
+ const { p, f } = wnaf.cached(this, scalar, (p) => (0,_curve_js__WEBPACK_IMPORTED_MODULE_2__.normalizeZ)(Point, p));
262
+ return (0,_curve_js__WEBPACK_IMPORTED_MODULE_2__.normalizeZ)(Point, [p, f])[0];
263
+ }
264
+ // Non-constant-time multiplication. Uses double-and-add algorithm.
265
+ // It's faster, but should only be used when you don't care about
266
+ // an exposed private key e.g. sig verification.
267
+ // Does NOT allow scalars higher than CURVE.n.
268
+ // Accepts optional accumulator to merge with multiply (important for sparse scalars)
269
+ multiplyUnsafe(scalar, acc = Point.ZERO) {
270
+ // 0 <= scalar < L
271
+ if (!Fn.isValid(scalar))
272
+ throw new Error('invalid scalar: expected 0 <= sc < curve.n');
273
+ if (scalar === _0n)
274
+ return Point.ZERO;
275
+ if (this.is0() || scalar === _1n)
276
+ return this;
277
+ return wnaf.unsafe(this, scalar, (p) => (0,_curve_js__WEBPACK_IMPORTED_MODULE_2__.normalizeZ)(Point, p), acc);
278
+ }
279
+ // Checks if point is of small order.
280
+ // If you add something to small order point, you will have "dirty"
281
+ // point with torsion component.
282
+ // Multiplies point by cofactor and checks if the result is 0.
283
+ isSmallOrder() {
284
+ return this.multiplyUnsafe(cofactor).is0();
285
+ }
286
+ // Multiplies point by curve order and checks if the result is 0.
287
+ // Returns `false` is the point is dirty.
288
+ isTorsionFree() {
289
+ return wnaf.unsafe(this, CURVE.n).is0();
290
+ }
291
+ // Converts Extended point to default (x, y) coordinates.
292
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
293
+ toAffine(invertedZ) {
294
+ return toAffineMemo(this, invertedZ);
295
+ }
296
+ clearCofactor() {
297
+ if (cofactor === _1n)
298
+ return this;
299
+ return this.multiplyUnsafe(cofactor);
300
+ }
301
+ toBytes() {
302
+ const { x, y } = this.toAffine();
303
+ // Fp.toBytes() allows non-canonical encoding of y (>= p).
304
+ const bytes = Fp.toBytes(y);
305
+ // Each y has 2 valid points: (x, y), (x,-y).
306
+ // When compressing, it's enough to store y and use the last byte to encode sign of x
307
+ bytes[bytes.length - 1] |= x & _1n ? 0x80 : 0;
308
+ return bytes;
309
+ }
310
+ toHex() {
311
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.bytesToHex)(this.toBytes());
312
+ }
313
+ toString() {
314
+ return `<Point ${this.is0() ? 'ZERO' : this.toHex()}>`;
315
+ }
316
+ // TODO: remove
317
+ get ex() {
318
+ return this.X;
319
+ }
320
+ get ey() {
321
+ return this.Y;
322
+ }
323
+ get ez() {
324
+ return this.Z;
325
+ }
326
+ get et() {
327
+ return this.T;
328
+ }
329
+ static normalizeZ(points) {
330
+ return (0,_curve_js__WEBPACK_IMPORTED_MODULE_2__.normalizeZ)(Point, points);
331
+ }
332
+ static msm(points, scalars) {
333
+ return (0,_curve_js__WEBPACK_IMPORTED_MODULE_2__.pippenger)(Point, Fn, points, scalars);
334
+ }
335
+ _setWindowSize(windowSize) {
336
+ this.precompute(windowSize);
337
+ }
338
+ toRawBytes() {
339
+ return this.toBytes();
340
+ }
341
+ }
342
+ // base / generator point
343
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n, modP(CURVE.Gx * CURVE.Gy));
344
+ // zero / infinity / identity point
345
+ Point.ZERO = new Point(_0n, _1n, _1n, _0n); // 0, 1, 1, 0
346
+ // math field
347
+ Point.Fp = Fp;
348
+ // scalar field
349
+ Point.Fn = Fn;
350
+ const wnaf = new _curve_js__WEBPACK_IMPORTED_MODULE_2__.wNAF(Point, Fn.BITS);
351
+ Point.BASE.precompute(8); // Enable precomputes. Slows down first publicKey computation by 20ms.
352
+ return Point;
353
+ }
354
+ /**
355
+ * Base class for prime-order points like Ristretto255 and Decaf448.
356
+ * These points eliminate cofactor issues by representing equivalence classes
357
+ * of Edwards curve points.
358
+ */
359
+ class PrimeEdwardsPoint {
360
+ constructor(ep) {
361
+ this.ep = ep;
362
+ }
363
+ // Static methods that must be implemented by subclasses
364
+ static fromBytes(_bytes) {
365
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.notImplemented)();
366
+ }
367
+ static fromHex(_hex) {
368
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.notImplemented)();
369
+ }
370
+ get x() {
371
+ return this.toAffine().x;
372
+ }
373
+ get y() {
374
+ return this.toAffine().y;
375
+ }
376
+ // Common implementations
377
+ clearCofactor() {
378
+ // no-op for prime-order groups
379
+ return this;
380
+ }
381
+ assertValidity() {
382
+ this.ep.assertValidity();
383
+ }
384
+ toAffine(invertedZ) {
385
+ return this.ep.toAffine(invertedZ);
386
+ }
387
+ toHex() {
388
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.bytesToHex)(this.toBytes());
389
+ }
390
+ toString() {
391
+ return this.toHex();
392
+ }
393
+ isTorsionFree() {
394
+ return true;
395
+ }
396
+ isSmallOrder() {
397
+ return false;
398
+ }
399
+ add(other) {
400
+ this.assertSame(other);
401
+ return this.init(this.ep.add(other.ep));
402
+ }
403
+ subtract(other) {
404
+ this.assertSame(other);
405
+ return this.init(this.ep.subtract(other.ep));
406
+ }
407
+ multiply(scalar) {
408
+ return this.init(this.ep.multiply(scalar));
409
+ }
410
+ multiplyUnsafe(scalar) {
411
+ return this.init(this.ep.multiplyUnsafe(scalar));
412
+ }
413
+ double() {
414
+ return this.init(this.ep.double());
415
+ }
416
+ negate() {
417
+ return this.init(this.ep.negate());
418
+ }
419
+ precompute(windowSize, isLazy) {
420
+ return this.init(this.ep.precompute(windowSize, isLazy));
421
+ }
422
+ /** @deprecated use `toBytes` */
423
+ toRawBytes() {
424
+ return this.toBytes();
425
+ }
426
+ }
427
+ /**
428
+ * Initializes EdDSA signatures over given Edwards curve.
429
+ */
430
+ function eddsa(Point, cHash, eddsaOpts = {}) {
431
+ if (typeof cHash !== 'function')
432
+ throw new Error('"hash" function param is required');
433
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._validateObject)(eddsaOpts, {}, {
434
+ adjustScalarBytes: 'function',
435
+ randomBytes: 'function',
436
+ domain: 'function',
437
+ prehash: 'function',
438
+ mapToCurve: 'function',
439
+ });
440
+ const { prehash } = eddsaOpts;
441
+ const { BASE, Fp, Fn } = Point;
442
+ const randomBytes = eddsaOpts.randomBytes || _utils_js__WEBPACK_IMPORTED_MODULE_1__.randomBytes;
443
+ const adjustScalarBytes = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
444
+ const domain = eddsaOpts.domain ||
445
+ ((data, ctx, phflag) => {
446
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abool2)(phflag, 'phflag');
447
+ if (ctx.length || phflag)
448
+ throw new Error('Contexts/pre-hash are not supported');
449
+ return data;
450
+ }); // NOOP
451
+ // Little-endian SHA512 with modulo n
452
+ function modN_LE(hash) {
453
+ return Fn.create((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.bytesToNumberLE)(hash)); // Not Fn.fromBytes: it has length limit
454
+ }
455
+ // Get the hashed private scalar per RFC8032 5.1.5
456
+ function getPrivateScalar(key) {
457
+ const len = lengths.secretKey;
458
+ key = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('private key', key, len);
459
+ // Hash private key with curve's hash function to produce uniformingly random input
460
+ // Check byte lengths: ensure(64, h(ensure(32, key)))
461
+ const hashed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('hashed private key', cHash(key), 2 * len);
462
+ const head = adjustScalarBytes(hashed.slice(0, len)); // clear first half bits, produce FE
463
+ const prefix = hashed.slice(len, 2 * len); // second half is called key prefix (5.1.6)
464
+ const scalar = modN_LE(head); // The actual private scalar
465
+ return { head, prefix, scalar };
466
+ }
467
+ /** Convenience method that creates public key from scalar. RFC8032 5.1.5 */
468
+ function getExtendedPublicKey(secretKey) {
469
+ const { head, prefix, scalar } = getPrivateScalar(secretKey);
470
+ const point = BASE.multiply(scalar); // Point on Edwards curve aka public key
471
+ const pointBytes = point.toBytes();
472
+ return { head, prefix, scalar, point, pointBytes };
473
+ }
474
+ /** Calculates EdDSA pub key. RFC8032 5.1.5. */
475
+ function getPublicKey(secretKey) {
476
+ return getExtendedPublicKey(secretKey).pointBytes;
477
+ }
478
+ // int('LE', SHA512(dom2(F, C) || msgs)) mod N
479
+ function hashDomainToScalar(context = Uint8Array.of(), ...msgs) {
480
+ const msg = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.concatBytes)(...msgs);
481
+ return modN_LE(cHash(domain(msg, (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('context', context), !!prehash)));
482
+ }
483
+ /** Signs message with privateKey. RFC8032 5.1.6 */
484
+ function sign(msg, secretKey, options = {}) {
485
+ msg = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('message', msg);
486
+ if (prehash)
487
+ msg = prehash(msg); // for ed25519ph etc.
488
+ const { prefix, scalar, pointBytes } = getExtendedPublicKey(secretKey);
489
+ const r = hashDomainToScalar(options.context, prefix, msg); // r = dom2(F, C) || prefix || PH(M)
490
+ const R = BASE.multiply(r).toBytes(); // R = rG
491
+ const k = hashDomainToScalar(options.context, R, pointBytes, msg); // R || A || PH(M)
492
+ const s = Fn.create(r + k * scalar); // S = (r + k * s) mod L
493
+ if (!Fn.isValid(s))
494
+ throw new Error('sign failed: invalid s'); // 0 <= s < L
495
+ const rs = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.concatBytes)(R, Fn.toBytes(s));
496
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abytes2)(rs, lengths.signature, 'result');
497
+ }
498
+ // verification rule is either zip215 or rfc8032 / nist186-5. Consult fromHex:
499
+ const verifyOpts = { zip215: true };
500
+ /**
501
+ * Verifies EdDSA signature against message and public key. RFC8032 5.1.7.
502
+ * An extended group equation is checked.
503
+ */
504
+ function verify(sig, msg, publicKey, options = verifyOpts) {
505
+ const { context, zip215 } = options;
506
+ const len = lengths.signature;
507
+ sig = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('signature', sig, len);
508
+ msg = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('message', msg);
509
+ publicKey = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('publicKey', publicKey, lengths.publicKey);
510
+ if (zip215 !== undefined)
511
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abool2)(zip215, 'zip215');
512
+ if (prehash)
513
+ msg = prehash(msg); // for ed25519ph, etc
514
+ const mid = len / 2;
515
+ const r = sig.subarray(0, mid);
516
+ const s = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.bytesToNumberLE)(sig.subarray(mid, len));
517
+ let A, R, SB;
518
+ try {
519
+ // zip215=true is good for consensus-critical apps. =false follows RFC8032 / NIST186-5.
520
+ // zip215=true: 0 <= y < MASK (2^256 for ed25519)
521
+ // zip215=false: 0 <= y < P (2^255-19 for ed25519)
522
+ A = Point.fromBytes(publicKey, zip215);
523
+ R = Point.fromBytes(r, zip215);
524
+ SB = BASE.multiplyUnsafe(s); // 0 <= s < l is done inside
525
+ }
526
+ catch (error) {
527
+ return false;
528
+ }
529
+ if (!zip215 && A.isSmallOrder())
530
+ return false; // zip215 allows public keys of small order
531
+ const k = hashDomainToScalar(context, R.toBytes(), A.toBytes(), msg);
532
+ const RkA = R.add(A.multiplyUnsafe(k));
533
+ // Extended group equation
534
+ // [8][S]B = [8]R + [8][k]A'
535
+ return RkA.subtract(SB).clearCofactor().is0();
536
+ }
537
+ const _size = Fp.BYTES; // 32 for ed25519, 57 for ed448
538
+ const lengths = {
539
+ secretKey: _size,
540
+ publicKey: _size,
541
+ signature: 2 * _size,
542
+ seed: _size,
543
+ };
544
+ function randomSecretKey(seed = randomBytes(lengths.seed)) {
545
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abytes2)(seed, lengths.seed, 'seed');
546
+ }
547
+ function keygen(seed) {
548
+ const secretKey = utils.randomSecretKey(seed);
549
+ return { secretKey, publicKey: getPublicKey(secretKey) };
550
+ }
551
+ function isValidSecretKey(key) {
552
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.isBytes)(key) && key.length === Fn.BYTES;
553
+ }
554
+ function isValidPublicKey(key, zip215) {
555
+ try {
556
+ return !!Point.fromBytes(key, zip215);
557
+ }
558
+ catch (error) {
559
+ return false;
560
+ }
561
+ }
562
+ const utils = {
563
+ getExtendedPublicKey,
564
+ randomSecretKey,
565
+ isValidSecretKey,
566
+ isValidPublicKey,
567
+ /**
568
+ * Converts ed public key to x public key. Uses formula:
569
+ * - ed25519:
570
+ * - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
571
+ * - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
572
+ * - ed448:
573
+ * - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
574
+ * - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
575
+ */
576
+ toMontgomery(publicKey) {
577
+ const { y } = Point.fromBytes(publicKey);
578
+ const size = lengths.publicKey;
579
+ const is25519 = size === 32;
580
+ if (!is25519 && size !== 57)
581
+ throw new Error('only defined for 25519 and 448');
582
+ const u = is25519 ? Fp.div(_1n + y, _1n - y) : Fp.div(y - _1n, y + _1n);
583
+ return Fp.toBytes(u);
584
+ },
585
+ toMontgomerySecret(secretKey) {
586
+ const size = lengths.secretKey;
587
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._abytes2)(secretKey, size);
588
+ const hashed = cHash(secretKey.subarray(0, size));
589
+ return adjustScalarBytes(hashed).subarray(0, size);
590
+ },
591
+ /** @deprecated */
592
+ randomPrivateKey: randomSecretKey,
593
+ /** @deprecated */
594
+ precompute(windowSize = 8, point = Point.BASE) {
595
+ return point.precompute(windowSize, false);
596
+ },
597
+ };
598
+ return Object.freeze({
599
+ keygen,
600
+ getPublicKey,
601
+ sign,
602
+ verify,
603
+ utils,
604
+ Point,
605
+ lengths,
606
+ });
607
+ }
608
+ function _eddsa_legacy_opts_to_new(c) {
609
+ const CURVE = {
610
+ a: c.a,
611
+ d: c.d,
612
+ p: c.Fp.ORDER,
613
+ n: c.n,
614
+ h: c.h,
615
+ Gx: c.Gx,
616
+ Gy: c.Gy,
617
+ };
618
+ const Fp = c.Fp;
619
+ const Fn = (0,_modular_js__WEBPACK_IMPORTED_MODULE_3__.Field)(CURVE.n, c.nBitLength, true);
620
+ const curveOpts = { Fp, Fn, uvRatio: c.uvRatio };
621
+ const eddsaOpts = {
622
+ randomBytes: c.randomBytes,
623
+ adjustScalarBytes: c.adjustScalarBytes,
624
+ domain: c.domain,
625
+ prehash: c.prehash,
626
+ mapToCurve: c.mapToCurve,
627
+ };
628
+ return { CURVE, curveOpts, hash: c.hash, eddsaOpts };
629
+ }
630
+ function _eddsa_new_output_to_legacy(c, eddsa) {
631
+ const Point = eddsa.Point;
632
+ const legacy = Object.assign({}, eddsa, {
633
+ ExtendedPoint: Point,
634
+ CURVE: c,
635
+ nBitLength: Point.Fn.BITS,
636
+ nByteLength: Point.Fn.BYTES,
637
+ });
638
+ return legacy;
639
+ }
640
+ // TODO: remove. Use eddsa
641
+ function twistedEdwards(c) {
642
+ const { CURVE, curveOpts, hash, eddsaOpts } = _eddsa_legacy_opts_to_new(c);
643
+ const Point = edwards(CURVE, curveOpts);
644
+ const EDDSA = eddsa(Point, hash, eddsaOpts);
645
+ return _eddsa_new_output_to_legacy(c, EDDSA);
646
+ }
647
+ //# sourceMappingURL=edwards.js.map
648
+
649
+ /***/ }),
650
+
651
+ /***/ "./node_modules/@noble/curves/esm/abstract/montgomery.js":
652
+ /*!***************************************************************!*\
653
+ !*** ./node_modules/@noble/curves/esm/abstract/montgomery.js ***!
654
+ \***************************************************************/
655
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
656
+
657
+ __webpack_require__.r(__webpack_exports__);
658
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
659
+ /* harmony export */ montgomery: () => (/* binding */ montgomery)
660
+ /* harmony export */ });
661
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils.js */ "./node_modules/@noble/curves/esm/utils.js");
662
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils.js */ "./node_modules/@noble/hashes/esm/utils.js");
663
+ /* harmony import */ var _modular_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modular.js */ "./node_modules/@noble/curves/esm/abstract/modular.js");
664
+ /**
665
+ * Montgomery curve methods. It's not really whole montgomery curve,
666
+ * just bunch of very specific methods for X25519 / X448 from
667
+ * [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
668
+ * @module
669
+ */
670
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
671
+
672
+
673
+ const _0n = BigInt(0);
674
+ const _1n = BigInt(1);
675
+ const _2n = BigInt(2);
676
+ function validateOpts(curve) {
677
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__._validateObject)(curve, {
678
+ adjustScalarBytes: 'function',
679
+ powPminus2: 'function',
680
+ });
681
+ return Object.freeze({ ...curve });
682
+ }
683
+ function montgomery(curveDef) {
684
+ const CURVE = validateOpts(curveDef);
685
+ const { P, type, adjustScalarBytes, powPminus2, randomBytes: rand } = CURVE;
686
+ const is25519 = type === 'x25519';
687
+ if (!is25519 && type !== 'x448')
688
+ throw new Error('invalid type');
689
+ const randomBytes_ = rand || _utils_js__WEBPACK_IMPORTED_MODULE_1__.randomBytes;
690
+ const montgomeryBits = is25519 ? 255 : 448;
691
+ const fieldLen = is25519 ? 32 : 56;
692
+ const Gu = is25519 ? BigInt(9) : BigInt(5);
693
+ // RFC 7748 #5:
694
+ // The constant a24 is (486662 - 2) / 4 = 121665 for curve25519/X25519 and
695
+ // (156326 - 2) / 4 = 39081 for curve448/X448
696
+ // const a = is25519 ? 156326n : 486662n;
697
+ const a24 = is25519 ? BigInt(121665) : BigInt(39081);
698
+ // RFC: x25519 "the resulting integer is of the form 2^254 plus
699
+ // eight times a value between 0 and 2^251 - 1 (inclusive)"
700
+ // x448: "2^447 plus four times a value between 0 and 2^445 - 1 (inclusive)"
701
+ const minScalar = is25519 ? _2n ** BigInt(254) : _2n ** BigInt(447);
702
+ const maxAdded = is25519
703
+ ? BigInt(8) * _2n ** BigInt(251) - _1n
704
+ : BigInt(4) * _2n ** BigInt(445) - _1n;
705
+ const maxScalar = minScalar + maxAdded + _1n; // (inclusive)
706
+ const modP = (n) => (0,_modular_js__WEBPACK_IMPORTED_MODULE_2__.mod)(n, P);
707
+ const GuBytes = encodeU(Gu);
708
+ function encodeU(u) {
709
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.numberToBytesLE)(modP(u), fieldLen);
710
+ }
711
+ function decodeU(u) {
712
+ const _u = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('u coordinate', u, fieldLen);
713
+ // RFC: When receiving such an array, implementations of X25519
714
+ // (but not X448) MUST mask the most significant bit in the final byte.
715
+ if (is25519)
716
+ _u[31] &= 127; // 0b0111_1111
717
+ // RFC: Implementations MUST accept non-canonical values and process them as
718
+ // if they had been reduced modulo the field prime. The non-canonical
719
+ // values are 2^255 - 19 through 2^255 - 1 for X25519 and 2^448 - 2^224
720
+ // - 1 through 2^448 - 1 for X448.
721
+ return modP((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.bytesToNumberLE)(_u));
722
+ }
723
+ function decodeScalar(scalar) {
724
+ return (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.bytesToNumberLE)(adjustScalarBytes((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.ensureBytes)('scalar', scalar, fieldLen)));
725
+ }
726
+ function scalarMult(scalar, u) {
727
+ const pu = montgomeryLadder(decodeU(u), decodeScalar(scalar));
728
+ // Some public keys are useless, of low-order. Curve author doesn't think
729
+ // it needs to be validated, but we do it nonetheless.
730
+ // https://cr.yp.to/ecdh.html#validate
731
+ if (pu === _0n)
732
+ throw new Error('invalid private or public key received');
733
+ return encodeU(pu);
734
+ }
735
+ // Computes public key from private. By doing scalar multiplication of base point.
736
+ function scalarMultBase(scalar) {
737
+ return scalarMult(scalar, GuBytes);
738
+ }
739
+ // cswap from RFC7748 "example code"
740
+ function cswap(swap, x_2, x_3) {
741
+ // dummy = mask(swap) AND (x_2 XOR x_3)
742
+ // Where mask(swap) is the all-1 or all-0 word of the same length as x_2
743
+ // and x_3, computed, e.g., as mask(swap) = 0 - swap.
744
+ const dummy = modP(swap * (x_2 - x_3));
745
+ x_2 = modP(x_2 - dummy); // x_2 = x_2 XOR dummy
746
+ x_3 = modP(x_3 + dummy); // x_3 = x_3 XOR dummy
747
+ return { x_2, x_3 };
748
+ }
749
+ /**
750
+ * Montgomery x-only multiplication ladder.
751
+ * @param pointU u coordinate (x) on Montgomery Curve 25519
752
+ * @param scalar by which the point would be multiplied
753
+ * @returns new Point on Montgomery curve
754
+ */
755
+ function montgomeryLadder(u, scalar) {
756
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.aInRange)('u', u, _0n, P);
757
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.aInRange)('scalar', scalar, minScalar, maxScalar);
758
+ const k = scalar;
759
+ const x_1 = u;
760
+ let x_2 = _1n;
761
+ let z_2 = _0n;
762
+ let x_3 = u;
763
+ let z_3 = _1n;
764
+ let swap = _0n;
765
+ for (let t = BigInt(montgomeryBits - 1); t >= _0n; t--) {
766
+ const k_t = (k >> t) & _1n;
767
+ swap ^= k_t;
768
+ ({ x_2, x_3 } = cswap(swap, x_2, x_3));
769
+ ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
770
+ swap = k_t;
771
+ const A = x_2 + z_2;
772
+ const AA = modP(A * A);
773
+ const B = x_2 - z_2;
774
+ const BB = modP(B * B);
775
+ const E = AA - BB;
776
+ const C = x_3 + z_3;
777
+ const D = x_3 - z_3;
778
+ const DA = modP(D * A);
779
+ const CB = modP(C * B);
780
+ const dacb = DA + CB;
781
+ const da_cb = DA - CB;
782
+ x_3 = modP(dacb * dacb);
783
+ z_3 = modP(x_1 * modP(da_cb * da_cb));
784
+ x_2 = modP(AA * BB);
785
+ z_2 = modP(E * (AA + modP(a24 * E)));
786
+ }
787
+ ({ x_2, x_3 } = cswap(swap, x_2, x_3));
788
+ ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
789
+ const z2 = powPminus2(z_2); // `Fp.pow(x, P - _2n)` is much slower equivalent
790
+ return modP(x_2 * z2); // Return x_2 * (z_2^(p - 2))
791
+ }
792
+ const lengths = {
793
+ secretKey: fieldLen,
794
+ publicKey: fieldLen,
795
+ seed: fieldLen,
796
+ };
797
+ const randomSecretKey = (seed = randomBytes_(fieldLen)) => {
798
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.abytes)(seed, lengths.seed);
799
+ return seed;
800
+ };
801
+ function keygen(seed) {
802
+ const secretKey = randomSecretKey(seed);
803
+ return { secretKey, publicKey: scalarMultBase(secretKey) };
804
+ }
805
+ const utils = {
806
+ randomSecretKey,
807
+ randomPrivateKey: randomSecretKey,
808
+ };
809
+ return {
810
+ keygen,
811
+ getSharedSecret: (secretKey, publicKey) => scalarMult(secretKey, publicKey),
812
+ getPublicKey: (secretKey) => scalarMultBase(secretKey),
813
+ scalarMult,
814
+ scalarMultBase,
815
+ utils,
816
+ GuBytes: GuBytes.slice(),
817
+ lengths,
818
+ };
819
+ }
820
+ //# sourceMappingURL=montgomery.js.map
821
+
822
+ /***/ })
823
+
824
+ }]);
825
+ //# sourceMappingURL=defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map