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,747 @@
1
+ "use strict";
2
+ (this["webpackChunkShogunCore"] = this["webpackChunkShogunCore"] || []).push([["defaultVendors-node_modules_noble_curves_esm_ed448_js"],{
3
+
4
+ /***/ "./node_modules/@noble/curves/esm/ed448.js":
5
+ /*!*************************************************************!*\
6
+ !*** ./node_modules/@noble/curves/esm/ed448.js + 1 modules ***!
7
+ \*************************************************************/
8
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
9
+
10
+ // ESM COMPAT FLAG
11
+ __webpack_require__.r(__webpack_exports__);
12
+
13
+ // EXPORTS
14
+ __webpack_require__.d(__webpack_exports__, {
15
+ DecafPoint: () => (/* binding */ DecafPoint),
16
+ E448: () => (/* binding */ E448),
17
+ ED448_TORSION_SUBGROUP: () => (/* binding */ ED448_TORSION_SUBGROUP),
18
+ decaf448: () => (/* binding */ decaf448),
19
+ decaf448_hasher: () => (/* binding */ decaf448_hasher),
20
+ ed448: () => (/* binding */ ed448),
21
+ ed448_hasher: () => (/* binding */ ed448_hasher),
22
+ ed448ph: () => (/* binding */ ed448ph),
23
+ edwardsToMontgomery: () => (/* binding */ edwardsToMontgomery),
24
+ edwardsToMontgomeryPub: () => (/* binding */ edwardsToMontgomeryPub),
25
+ encodeToCurve: () => (/* binding */ encodeToCurve),
26
+ hashToCurve: () => (/* binding */ hashToCurve),
27
+ hashToDecaf448: () => (/* binding */ hashToDecaf448),
28
+ hash_to_decaf448: () => (/* binding */ hash_to_decaf448),
29
+ x448: () => (/* binding */ x448)
30
+ });
31
+
32
+ // EXTERNAL MODULE: ./node_modules/@noble/hashes/esm/_u64.js
33
+ var _u64 = __webpack_require__("./node_modules/@noble/hashes/esm/_u64.js");
34
+ // EXTERNAL MODULE: ./node_modules/@noble/hashes/esm/utils.js + 1 modules
35
+ var utils = __webpack_require__("./node_modules/@noble/hashes/esm/utils.js");
36
+ ;// ./node_modules/@noble/hashes/esm/sha3.js
37
+ /**
38
+ * SHA3 (keccak) hash function, based on a new "Sponge function" design.
39
+ * Different from older hashes, the internal state is bigger than output size.
40
+ *
41
+ * Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
42
+ * [Website](https://keccak.team/keccak.html),
43
+ * [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub).
44
+ *
45
+ * Check out `sha3-addons` module for cSHAKE, k12, and others.
46
+ * @module
47
+ */
48
+
49
+ // prettier-ignore
50
+
51
+ // No __PURE__ annotations in sha3 header:
52
+ // EVERYTHING is in fact used on every export.
53
+ // Various per round constants calculations
54
+ const _0n = BigInt(0);
55
+ const _1n = BigInt(1);
56
+ const _2n = BigInt(2);
57
+ const _7n = BigInt(7);
58
+ const _256n = BigInt(256);
59
+ const _0x71n = BigInt(0x71);
60
+ const SHA3_PI = [];
61
+ const SHA3_ROTL = [];
62
+ const _SHA3_IOTA = [];
63
+ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
64
+ // Pi
65
+ [x, y] = [y, (2 * x + 3 * y) % 5];
66
+ SHA3_PI.push(2 * (5 * y + x));
67
+ // Rotational
68
+ SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
69
+ // Iota
70
+ let t = _0n;
71
+ for (let j = 0; j < 7; j++) {
72
+ R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
73
+ if (R & _2n)
74
+ t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
75
+ }
76
+ _SHA3_IOTA.push(t);
77
+ }
78
+ const IOTAS = (0,_u64.split)(_SHA3_IOTA, true);
79
+ const SHA3_IOTA_H = IOTAS[0];
80
+ const SHA3_IOTA_L = IOTAS[1];
81
+ // Left rotation (without 0, 32, 64)
82
+ const rotlH = (h, l, s) => (s > 32 ? (0,_u64.rotlBH)(h, l, s) : (0,_u64.rotlSH)(h, l, s));
83
+ const rotlL = (h, l, s) => (s > 32 ? (0,_u64.rotlBL)(h, l, s) : (0,_u64.rotlSL)(h, l, s));
84
+ /** `keccakf1600` internal function, additionally allows to adjust round count. */
85
+ function keccakP(s, rounds = 24) {
86
+ const B = new Uint32Array(5 * 2);
87
+ // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
88
+ for (let round = 24 - rounds; round < 24; round++) {
89
+ // Theta θ
90
+ for (let x = 0; x < 10; x++)
91
+ B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
92
+ for (let x = 0; x < 10; x += 2) {
93
+ const idx1 = (x + 8) % 10;
94
+ const idx0 = (x + 2) % 10;
95
+ const B0 = B[idx0];
96
+ const B1 = B[idx0 + 1];
97
+ const Th = rotlH(B0, B1, 1) ^ B[idx1];
98
+ const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
99
+ for (let y = 0; y < 50; y += 10) {
100
+ s[x + y] ^= Th;
101
+ s[x + y + 1] ^= Tl;
102
+ }
103
+ }
104
+ // Rho (ρ) and Pi (π)
105
+ let curH = s[2];
106
+ let curL = s[3];
107
+ for (let t = 0; t < 24; t++) {
108
+ const shift = SHA3_ROTL[t];
109
+ const Th = rotlH(curH, curL, shift);
110
+ const Tl = rotlL(curH, curL, shift);
111
+ const PI = SHA3_PI[t];
112
+ curH = s[PI];
113
+ curL = s[PI + 1];
114
+ s[PI] = Th;
115
+ s[PI + 1] = Tl;
116
+ }
117
+ // Chi (χ)
118
+ for (let y = 0; y < 50; y += 10) {
119
+ for (let x = 0; x < 10; x++)
120
+ B[x] = s[y + x];
121
+ for (let x = 0; x < 10; x++)
122
+ s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
123
+ }
124
+ // Iota (ι)
125
+ s[0] ^= SHA3_IOTA_H[round];
126
+ s[1] ^= SHA3_IOTA_L[round];
127
+ }
128
+ (0,utils.clean)(B);
129
+ }
130
+ /** Keccak sponge function. */
131
+ class Keccak extends utils.Hash {
132
+ // NOTE: we accept arguments in bytes instead of bits here.
133
+ constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
134
+ super();
135
+ this.pos = 0;
136
+ this.posOut = 0;
137
+ this.finished = false;
138
+ this.destroyed = false;
139
+ this.enableXOF = false;
140
+ this.blockLen = blockLen;
141
+ this.suffix = suffix;
142
+ this.outputLen = outputLen;
143
+ this.enableXOF = enableXOF;
144
+ this.rounds = rounds;
145
+ // Can be passed from user as dkLen
146
+ (0,utils.anumber)(outputLen);
147
+ // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
148
+ // 0 < blockLen < 200
149
+ if (!(0 < blockLen && blockLen < 200))
150
+ throw new Error('only keccak-f1600 function is supported');
151
+ this.state = new Uint8Array(200);
152
+ this.state32 = (0,utils.u32)(this.state);
153
+ }
154
+ clone() {
155
+ return this._cloneInto();
156
+ }
157
+ keccak() {
158
+ (0,utils.swap32IfBE)(this.state32);
159
+ keccakP(this.state32, this.rounds);
160
+ (0,utils.swap32IfBE)(this.state32);
161
+ this.posOut = 0;
162
+ this.pos = 0;
163
+ }
164
+ update(data) {
165
+ (0,utils.aexists)(this);
166
+ data = (0,utils.toBytes)(data);
167
+ (0,utils.abytes)(data);
168
+ const { blockLen, state } = this;
169
+ const len = data.length;
170
+ for (let pos = 0; pos < len;) {
171
+ const take = Math.min(blockLen - this.pos, len - pos);
172
+ for (let i = 0; i < take; i++)
173
+ state[this.pos++] ^= data[pos++];
174
+ if (this.pos === blockLen)
175
+ this.keccak();
176
+ }
177
+ return this;
178
+ }
179
+ finish() {
180
+ if (this.finished)
181
+ return;
182
+ this.finished = true;
183
+ const { state, suffix, pos, blockLen } = this;
184
+ // Do the padding
185
+ state[pos] ^= suffix;
186
+ if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
187
+ this.keccak();
188
+ state[blockLen - 1] ^= 0x80;
189
+ this.keccak();
190
+ }
191
+ writeInto(out) {
192
+ (0,utils.aexists)(this, false);
193
+ (0,utils.abytes)(out);
194
+ this.finish();
195
+ const bufferOut = this.state;
196
+ const { blockLen } = this;
197
+ for (let pos = 0, len = out.length; pos < len;) {
198
+ if (this.posOut >= blockLen)
199
+ this.keccak();
200
+ const take = Math.min(blockLen - this.posOut, len - pos);
201
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
202
+ this.posOut += take;
203
+ pos += take;
204
+ }
205
+ return out;
206
+ }
207
+ xofInto(out) {
208
+ // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
209
+ if (!this.enableXOF)
210
+ throw new Error('XOF is not possible for this instance');
211
+ return this.writeInto(out);
212
+ }
213
+ xof(bytes) {
214
+ (0,utils.anumber)(bytes);
215
+ return this.xofInto(new Uint8Array(bytes));
216
+ }
217
+ digestInto(out) {
218
+ (0,utils.aoutput)(out, this);
219
+ if (this.finished)
220
+ throw new Error('digest() was already called');
221
+ this.writeInto(out);
222
+ this.destroy();
223
+ return out;
224
+ }
225
+ digest() {
226
+ return this.digestInto(new Uint8Array(this.outputLen));
227
+ }
228
+ destroy() {
229
+ this.destroyed = true;
230
+ (0,utils.clean)(this.state);
231
+ }
232
+ _cloneInto(to) {
233
+ const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
234
+ to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
235
+ to.state32.set(this.state32);
236
+ to.pos = this.pos;
237
+ to.posOut = this.posOut;
238
+ to.finished = this.finished;
239
+ to.rounds = rounds;
240
+ // Suffix can change in cSHAKE
241
+ to.suffix = suffix;
242
+ to.outputLen = outputLen;
243
+ to.enableXOF = enableXOF;
244
+ to.destroyed = this.destroyed;
245
+ return to;
246
+ }
247
+ }
248
+ const gen = (suffix, blockLen, outputLen) => (0,utils.createHasher)(() => new Keccak(blockLen, suffix, outputLen));
249
+ /** SHA3-224 hash function. */
250
+ const sha3_224 = /* @__PURE__ */ (() => gen(0x06, 144, 224 / 8))();
251
+ /** SHA3-256 hash function. Different from keccak-256. */
252
+ const sha3_256 = /* @__PURE__ */ (() => gen(0x06, 136, 256 / 8))();
253
+ /** SHA3-384 hash function. */
254
+ const sha3_384 = /* @__PURE__ */ (() => gen(0x06, 104, 384 / 8))();
255
+ /** SHA3-512 hash function. */
256
+ const sha3_512 = /* @__PURE__ */ (() => gen(0x06, 72, 512 / 8))();
257
+ /** keccak-224 hash function. */
258
+ const keccak_224 = /* @__PURE__ */ (() => gen(0x01, 144, 224 / 8))();
259
+ /** keccak-256 hash function. Different from SHA3-256. */
260
+ const keccak_256 = /* @__PURE__ */ (() => gen(0x01, 136, 256 / 8))();
261
+ /** keccak-384 hash function. */
262
+ const keccak_384 = /* @__PURE__ */ (() => gen(0x01, 104, 384 / 8))();
263
+ /** keccak-512 hash function. */
264
+ const keccak_512 = /* @__PURE__ */ (() => gen(0x01, 72, 512 / 8))();
265
+ const genShake = (suffix, blockLen, outputLen) => (0,utils.createXOFer)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
266
+ /** SHAKE128 XOF with 128-bit security. */
267
+ const shake128 = /* @__PURE__ */ (() => genShake(0x1f, 168, 128 / 8))();
268
+ /** SHAKE256 XOF with 256-bit security. */
269
+ const shake256 = /* @__PURE__ */ (() => genShake(0x1f, 136, 256 / 8))();
270
+ //# sourceMappingURL=sha3.js.map
271
+ // EXTERNAL MODULE: ./node_modules/@noble/curves/esm/abstract/curve.js
272
+ var curve = __webpack_require__("./node_modules/@noble/curves/esm/abstract/curve.js");
273
+ // EXTERNAL MODULE: ./node_modules/@noble/curves/esm/abstract/edwards.js
274
+ var edwards = __webpack_require__("./node_modules/@noble/curves/esm/abstract/edwards.js");
275
+ // EXTERNAL MODULE: ./node_modules/@noble/curves/esm/abstract/hash-to-curve.js
276
+ var hash_to_curve = __webpack_require__("./node_modules/@noble/curves/esm/abstract/hash-to-curve.js");
277
+ // EXTERNAL MODULE: ./node_modules/@noble/curves/esm/abstract/modular.js
278
+ var modular = __webpack_require__("./node_modules/@noble/curves/esm/abstract/modular.js");
279
+ // EXTERNAL MODULE: ./node_modules/@noble/curves/esm/abstract/montgomery.js
280
+ var montgomery = __webpack_require__("./node_modules/@noble/curves/esm/abstract/montgomery.js");
281
+ // EXTERNAL MODULE: ./node_modules/@noble/curves/esm/utils.js
282
+ var esm_utils = __webpack_require__("./node_modules/@noble/curves/esm/utils.js");
283
+ ;// ./node_modules/@noble/curves/esm/ed448.js
284
+ /**
285
+ * Edwards448 (not Ed448-Goldilocks) curve with following addons:
286
+ * - X448 ECDH
287
+ * - Decaf cofactor elimination
288
+ * - Elligator hash-to-group / point indistinguishability
289
+ * Conforms to RFC 8032 https://www.rfc-editor.org/rfc/rfc8032.html#section-5.2
290
+ * @module
291
+ */
292
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+ // edwards448 curve
302
+ // a = 1n
303
+ // d = Fp.neg(39081n)
304
+ // Finite field 2n**448n - 2n**224n - 1n
305
+ // Subgroup order
306
+ // 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
307
+ const ed448_CURVE = {
308
+ p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
309
+ n: BigInt('0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3'),
310
+ h: BigInt(4),
311
+ a: BigInt(1),
312
+ d: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffff6756'),
313
+ Gx: BigInt('0x4f1970c66bed0ded221d15a622bf36da9e146570470f1767ea6de324a3d3a46412ae1af72ab66511433b80e18b00938e2626a82bc70cc05e'),
314
+ Gy: BigInt('0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'),
315
+ };
316
+ // E448 NIST curve is identical to edwards448, except for:
317
+ // d = 39082/39081
318
+ // Gx = 3/2
319
+ const E448_CURVE = Object.assign({}, ed448_CURVE, {
320
+ d: BigInt('0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'),
321
+ Gx: BigInt('0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'),
322
+ Gy: BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'),
323
+ });
324
+ const shake256_114 = /* @__PURE__ */ (0,utils.createHasher)(() => shake256.create({ dkLen: 114 }));
325
+ const shake256_64 = /* @__PURE__ */ (0,utils.createHasher)(() => shake256.create({ dkLen: 64 }));
326
+ // prettier-ignore
327
+ const ed448_1n = BigInt(1), ed448_2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
328
+ // prettier-ignore
329
+ const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
330
+ // powPminus3div4 calculates z = x^k mod p, where k = (p-3)/4.
331
+ // Used for efficient square root calculation.
332
+ // ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
333
+ function ed448_pow_Pminus3div4(x) {
334
+ const P = ed448_CURVE.p;
335
+ const b2 = (x * x * x) % P;
336
+ const b3 = (b2 * b2 * x) % P;
337
+ const b6 = ((0,modular.pow2)(b3, _3n, P) * b3) % P;
338
+ const b9 = ((0,modular.pow2)(b6, _3n, P) * b3) % P;
339
+ const b11 = ((0,modular.pow2)(b9, ed448_2n, P) * b2) % P;
340
+ const b22 = ((0,modular.pow2)(b11, _11n, P) * b11) % P;
341
+ const b44 = ((0,modular.pow2)(b22, _22n, P) * b22) % P;
342
+ const b88 = ((0,modular.pow2)(b44, _44n, P) * b44) % P;
343
+ const b176 = ((0,modular.pow2)(b88, _88n, P) * b88) % P;
344
+ const b220 = ((0,modular.pow2)(b176, _44n, P) * b44) % P;
345
+ const b222 = ((0,modular.pow2)(b220, ed448_2n, P) * b2) % P;
346
+ const b223 = ((0,modular.pow2)(b222, ed448_1n, P) * x) % P;
347
+ return ((0,modular.pow2)(b223, _223n, P) * b222) % P;
348
+ }
349
+ function adjustScalarBytes(bytes) {
350
+ // Section 5: Likewise, for X448, set the two least significant bits of the first byte to 0,
351
+ bytes[0] &= 252; // 0b11111100
352
+ // and the most significant bit of the last byte to 1.
353
+ bytes[55] |= 128; // 0b10000000
354
+ // NOTE: is NOOP for 56 bytes scalars (X25519/X448)
355
+ bytes[56] = 0; // Byte outside of group (456 buts vs 448 bits)
356
+ return bytes;
357
+ }
358
+ // Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
359
+ // Uses algo from RFC8032 5.1.3.
360
+ function uvRatio(u, v) {
361
+ const P = ed448_CURVE.p;
362
+ // https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
363
+ // To compute the square root of (u/v), the first step is to compute the
364
+ // candidate root x = (u/v)^((p+1)/4). This can be done using the
365
+ // following trick, to use a single modular powering for both the
366
+ // inversion of v and the square root:
367
+ // x = (u/v)^((p+1)/4) = u³v(u⁵v³)^((p-3)/4) (mod p)
368
+ const u2v = (0,modular.mod)(u * u * v, P); // u²v
369
+ const u3v = (0,modular.mod)(u2v * u, P); // u³v
370
+ const u5v3 = (0,modular.mod)(u3v * u2v * v, P); // u⁵v³
371
+ const root = ed448_pow_Pminus3div4(u5v3);
372
+ const x = (0,modular.mod)(u3v * root, P);
373
+ // Verify that root is exists
374
+ const x2 = (0,modular.mod)(x * x, P); // x²
375
+ // If vx² = u, the recovered x-coordinate is x. Otherwise, no
376
+ // square root exists, and the decoding fails.
377
+ return { isValid: (0,modular.mod)(x2 * v, P) === u, value: x };
378
+ }
379
+ // Finite field 2n**448n - 2n**224n - 1n
380
+ // The value fits in 448 bits, but we use 456-bit (57-byte) elements because of bitflags.
381
+ // - ed25519 fits in 255 bits, allowing using last 1 byte for specifying bit flag of point negation.
382
+ // - ed448 fits in 448 bits. We can't use last 1 byte: we can only use a bit 224 in the middle.
383
+ const Fp = /* @__PURE__ */ (() => (0,modular.Field)(ed448_CURVE.p, { BITS: 456, isLE: true }))();
384
+ const Fn = /* @__PURE__ */ (() => (0,modular.Field)(ed448_CURVE.n, { BITS: 456, isLE: true }))();
385
+ // decaf448 uses 448-bit (56-byte) keys
386
+ const Fp448 = /* @__PURE__ */ (() => (0,modular.Field)(ed448_CURVE.p, { BITS: 448, isLE: true }))();
387
+ const Fn448 = /* @__PURE__ */ (() => (0,modular.Field)(ed448_CURVE.n, { BITS: 448, isLE: true }))();
388
+ // SHAKE256(dom4(phflag,context)||x, 114)
389
+ function dom4(data, ctx, phflag) {
390
+ if (ctx.length > 255)
391
+ throw new Error('context must be smaller than 255, got: ' + ctx.length);
392
+ return (0,utils.concatBytes)((0,esm_utils.asciiToBytes)('SigEd448'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
393
+ }
394
+ // const ed448_eddsa_opts = { adjustScalarBytes, domain: dom4 };
395
+ // const ed448_Point = edwards(ed448_CURVE, { Fp, Fn, uvRatio });
396
+ const ED448_DEF = /* @__PURE__ */ (() => ({
397
+ ...ed448_CURVE,
398
+ Fp,
399
+ Fn,
400
+ nBitLength: Fn.BITS,
401
+ hash: shake256_114,
402
+ adjustScalarBytes,
403
+ domain: dom4,
404
+ uvRatio,
405
+ }))();
406
+ /**
407
+ * ed448 EdDSA curve and methods.
408
+ * @example
409
+ * import { ed448 } from '@noble/curves/ed448';
410
+ * const { secretKey, publicKey } = ed448.keygen();
411
+ * const msg = new TextEncoder().encode('hello');
412
+ * const sig = ed448.sign(msg, secretKey);
413
+ * const isValid = ed448.verify(sig, msg, publicKey);
414
+ */
415
+ const ed448 = (0,edwards.twistedEdwards)(ED448_DEF);
416
+ // There is no ed448ctx, since ed448 supports ctx by default
417
+ /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
418
+ const ed448ph = /* @__PURE__ */ (() => (0,edwards.twistedEdwards)({
419
+ ...ED448_DEF,
420
+ prehash: shake256_64,
421
+ }))();
422
+ /**
423
+ * E448 curve, defined by NIST.
424
+ * E448 != edwards448 used in ed448.
425
+ * E448 is birationally equivalent to edwards448.
426
+ */
427
+ const E448 = (0,edwards.edwards)(E448_CURVE);
428
+ /**
429
+ * ECDH using curve448 aka x448.
430
+ * x448 has 56-byte keys as per RFC 7748, while
431
+ * ed448 has 57-byte keys as per RFC 8032.
432
+ */
433
+ const x448 = /* @__PURE__ */ (() => {
434
+ const P = ed448_CURVE.p;
435
+ return (0,montgomery.montgomery)({
436
+ P,
437
+ type: 'x448',
438
+ powPminus2: (x) => {
439
+ const Pminus3div4 = ed448_pow_Pminus3div4(x);
440
+ const Pminus3 = (0,modular.pow2)(Pminus3div4, ed448_2n, P);
441
+ return (0,modular.mod)(Pminus3 * x, P); // Pminus3 * x = Pminus2
442
+ },
443
+ adjustScalarBytes,
444
+ });
445
+ })();
446
+ // Hash To Curve Elligator2 Map
447
+ const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
448
+ const ELL2_J = /* @__PURE__ */ BigInt(156326);
449
+ function map_to_curve_elligator2_curve448(u) {
450
+ let tv1 = Fp.sqr(u); // 1. tv1 = u^2
451
+ let e1 = Fp.eql(tv1, Fp.ONE); // 2. e1 = tv1 == 1
452
+ tv1 = Fp.cmov(tv1, Fp.ZERO, e1); // 3. tv1 = CMOV(tv1, 0, e1) # If Z * u^2 == -1, set tv1 = 0
453
+ let xd = Fp.sub(Fp.ONE, tv1); // 4. xd = 1 - tv1
454
+ let x1n = Fp.neg(ELL2_J); // 5. x1n = -J
455
+ let tv2 = Fp.sqr(xd); // 6. tv2 = xd^2
456
+ let gxd = Fp.mul(tv2, xd); // 7. gxd = tv2 * xd # gxd = xd^3
457
+ let gx1 = Fp.mul(tv1, Fp.neg(ELL2_J)); // 8. gx1 = -J * tv1 # x1n + J * xd
458
+ gx1 = Fp.mul(gx1, x1n); // 9. gx1 = gx1 * x1n # x1n^2 + J * x1n * xd
459
+ gx1 = Fp.add(gx1, tv2); // 10. gx1 = gx1 + tv2 # x1n^2 + J * x1n * xd + xd^2
460
+ gx1 = Fp.mul(gx1, x1n); // 11. gx1 = gx1 * x1n # x1n^3 + J * x1n^2 * xd + x1n * xd^2
461
+ let tv3 = Fp.sqr(gxd); // 12. tv3 = gxd^2
462
+ tv2 = Fp.mul(gx1, gxd); // 13. tv2 = gx1 * gxd # gx1 * gxd
463
+ tv3 = Fp.mul(tv3, tv2); // 14. tv3 = tv3 * tv2 # gx1 * gxd^3
464
+ let y1 = Fp.pow(tv3, ELL2_C1); // 15. y1 = tv3^c1 # (gx1 * gxd^3)^((p - 3) / 4)
465
+ y1 = Fp.mul(y1, tv2); // 16. y1 = y1 * tv2 # gx1 * gxd * (gx1 * gxd^3)^((p - 3) / 4)
466
+ let x2n = Fp.mul(x1n, Fp.neg(tv1)); // 17. x2n = -tv1 * x1n # x2 = x2n / xd = -1 * u^2 * x1n / xd
467
+ let y2 = Fp.mul(y1, u); // 18. y2 = y1 * u
468
+ y2 = Fp.cmov(y2, Fp.ZERO, e1); // 19. y2 = CMOV(y2, 0, e1)
469
+ tv2 = Fp.sqr(y1); // 20. tv2 = y1^2
470
+ tv2 = Fp.mul(tv2, gxd); // 21. tv2 = tv2 * gxd
471
+ let e2 = Fp.eql(tv2, gx1); // 22. e2 = tv2 == gx1
472
+ let xn = Fp.cmov(x2n, x1n, e2); // 23. xn = CMOV(x2n, x1n, e2) # If e2, x = x1, else x = x2
473
+ let y = Fp.cmov(y2, y1, e2); // 24. y = CMOV(y2, y1, e2) # If e2, y = y1, else y = y2
474
+ let e3 = Fp.isOdd(y); // 25. e3 = sgn0(y) == 1 # Fix sign of y
475
+ y = Fp.cmov(y, Fp.neg(y), e2 !== e3); // 26. y = CMOV(y, -y, e2 XOR e3)
476
+ return { xn, xd, yn: y, yd: Fp.ONE }; // 27. return (xn, xd, y, 1)
477
+ }
478
+ function map_to_curve_elligator2_edwards448(u) {
479
+ let { xn, xd, yn, yd } = map_to_curve_elligator2_curve448(u); // 1. (xn, xd, yn, yd) = map_to_curve_elligator2_curve448(u)
480
+ let xn2 = Fp.sqr(xn); // 2. xn2 = xn^2
481
+ let xd2 = Fp.sqr(xd); // 3. xd2 = xd^2
482
+ let xd4 = Fp.sqr(xd2); // 4. xd4 = xd2^2
483
+ let yn2 = Fp.sqr(yn); // 5. yn2 = yn^2
484
+ let yd2 = Fp.sqr(yd); // 6. yd2 = yd^2
485
+ let xEn = Fp.sub(xn2, xd2); // 7. xEn = xn2 - xd2
486
+ let tv2 = Fp.sub(xEn, xd2); // 8. tv2 = xEn - xd2
487
+ xEn = Fp.mul(xEn, xd2); // 9. xEn = xEn * xd2
488
+ xEn = Fp.mul(xEn, yd); // 10. xEn = xEn * yd
489
+ xEn = Fp.mul(xEn, yn); // 11. xEn = xEn * yn
490
+ xEn = Fp.mul(xEn, _4n); // 12. xEn = xEn * 4
491
+ tv2 = Fp.mul(tv2, xn2); // 13. tv2 = tv2 * xn2
492
+ tv2 = Fp.mul(tv2, yd2); // 14. tv2 = tv2 * yd2
493
+ let tv3 = Fp.mul(yn2, _4n); // 15. tv3 = 4 * yn2
494
+ let tv1 = Fp.add(tv3, yd2); // 16. tv1 = tv3 + yd2
495
+ tv1 = Fp.mul(tv1, xd4); // 17. tv1 = tv1 * xd4
496
+ let xEd = Fp.add(tv1, tv2); // 18. xEd = tv1 + tv2
497
+ tv2 = Fp.mul(tv2, xn); // 19. tv2 = tv2 * xn
498
+ let tv4 = Fp.mul(xn, xd4); // 20. tv4 = xn * xd4
499
+ let yEn = Fp.sub(tv3, yd2); // 21. yEn = tv3 - yd2
500
+ yEn = Fp.mul(yEn, tv4); // 22. yEn = yEn * tv4
501
+ yEn = Fp.sub(yEn, tv2); // 23. yEn = yEn - tv2
502
+ tv1 = Fp.add(xn2, xd2); // 24. tv1 = xn2 + xd2
503
+ tv1 = Fp.mul(tv1, xd2); // 25. tv1 = tv1 * xd2
504
+ tv1 = Fp.mul(tv1, xd); // 26. tv1 = tv1 * xd
505
+ tv1 = Fp.mul(tv1, yn2); // 27. tv1 = tv1 * yn2
506
+ tv1 = Fp.mul(tv1, BigInt(-2)); // 28. tv1 = -2 * tv1
507
+ let yEd = Fp.add(tv2, tv1); // 29. yEd = tv2 + tv1
508
+ tv4 = Fp.mul(tv4, yd2); // 30. tv4 = tv4 * yd2
509
+ yEd = Fp.add(yEd, tv4); // 31. yEd = yEd + tv4
510
+ tv1 = Fp.mul(xEd, yEd); // 32. tv1 = xEd * yEd
511
+ let e = Fp.eql(tv1, Fp.ZERO); // 33. e = tv1 == 0
512
+ xEn = Fp.cmov(xEn, Fp.ZERO, e); // 34. xEn = CMOV(xEn, 0, e)
513
+ xEd = Fp.cmov(xEd, Fp.ONE, e); // 35. xEd = CMOV(xEd, 1, e)
514
+ yEn = Fp.cmov(yEn, Fp.ONE, e); // 36. yEn = CMOV(yEn, 1, e)
515
+ yEd = Fp.cmov(yEd, Fp.ONE, e); // 37. yEd = CMOV(yEd, 1, e)
516
+ const inv = (0,modular.FpInvertBatch)(Fp, [xEd, yEd], true); // batch division
517
+ return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
518
+ }
519
+ /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
520
+ const ed448_hasher = /* @__PURE__ */ (() => (0,hash_to_curve.createHasher)(ed448.Point, (scalars) => map_to_curve_elligator2_edwards448(scalars[0]), {
521
+ DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
522
+ encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
523
+ p: Fp.ORDER,
524
+ m: 1,
525
+ k: 224,
526
+ expand: 'xof',
527
+ hash: shake256,
528
+ }))();
529
+ // 1-d
530
+ const ONE_MINUS_D = /* @__PURE__ */ BigInt('39082');
531
+ // 1-2d
532
+ const ONE_MINUS_TWO_D = /* @__PURE__ */ BigInt('78163');
533
+ // √(-d)
534
+ const SQRT_MINUS_D = /* @__PURE__ */ BigInt('98944233647732219769177004876929019128417576295529901074099889598043702116001257856802131563896515373927712232092845883226922417596214');
535
+ // 1 / √(-d)
536
+ const INVSQRT_MINUS_D = /* @__PURE__ */ BigInt('315019913931389607337177038330951043522456072897266928557328499619017160722351061360252776265186336876723201881398623946864393857820716');
537
+ // Calculates 1/√(number)
538
+ const invertSqrt = (number) => uvRatio(ed448_1n, number);
539
+ /**
540
+ * Elligator map for hash-to-curve of decaf448.
541
+ * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C)
542
+ * and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
543
+ */
544
+ function calcElligatorDecafMap(r0) {
545
+ const { d } = ed448_CURVE;
546
+ const P = Fp.ORDER;
547
+ const mod = (n) => Fp.create(n);
548
+ const r = mod(-(r0 * r0)); // 1
549
+ const u0 = mod(d * (r - ed448_1n)); // 2
550
+ const u1 = mod((u0 + ed448_1n) * (u0 - r)); // 3
551
+ const { isValid: was_square, value: v } = uvRatio(ONE_MINUS_TWO_D, mod((r + ed448_1n) * u1)); // 4
552
+ let v_prime = v; // 5
553
+ if (!was_square)
554
+ v_prime = mod(r0 * v);
555
+ let sgn = ed448_1n; // 6
556
+ if (!was_square)
557
+ sgn = mod(-ed448_1n);
558
+ const s = mod(v_prime * (r + ed448_1n)); // 7
559
+ let s_abs = s;
560
+ if ((0,modular.isNegativeLE)(s, P))
561
+ s_abs = mod(-s);
562
+ const s2 = s * s;
563
+ const W0 = mod(s_abs * ed448_2n); // 8
564
+ const W1 = mod(s2 + ed448_1n); // 9
565
+ const W2 = mod(s2 - ed448_1n); // 10
566
+ const W3 = mod(v_prime * s * (r - ed448_1n) * ONE_MINUS_TWO_D + sgn); // 11
567
+ return new ed448.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
568
+ }
569
+ function decaf448_map(bytes) {
570
+ (0,utils.abytes)(bytes, 112);
571
+ const skipValidation = true;
572
+ // Note: Similar to the field element decoding described in
573
+ // [RFC7748], and unlike the field element decoding described in
574
+ // Section 5.3.1, non-canonical values are accepted.
575
+ const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
576
+ const R1 = calcElligatorDecafMap(r1);
577
+ const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
578
+ const R2 = calcElligatorDecafMap(r2);
579
+ return new _DecafPoint(R1.add(R2));
580
+ }
581
+ /**
582
+ * Each ed448/EdwardsPoint has 4 different equivalent points. This can be
583
+ * a source of bugs for protocols like ring signatures. Decaf was created to solve this.
584
+ * Decaf point operates in X:Y:Z:T extended coordinates like EdwardsPoint,
585
+ * but it should work in its own namespace: do not combine those two.
586
+ * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
587
+ */
588
+ class _DecafPoint extends edwards.PrimeEdwardsPoint {
589
+ constructor(ep) {
590
+ super(ep);
591
+ }
592
+ static fromAffine(ap) {
593
+ return new _DecafPoint(ed448.Point.fromAffine(ap));
594
+ }
595
+ assertSame(other) {
596
+ if (!(other instanceof _DecafPoint))
597
+ throw new Error('DecafPoint expected');
598
+ }
599
+ init(ep) {
600
+ return new _DecafPoint(ep);
601
+ }
602
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
603
+ static hashToCurve(hex) {
604
+ return decaf448_map((0,esm_utils.ensureBytes)('decafHash', hex, 112));
605
+ }
606
+ static fromBytes(bytes) {
607
+ (0,utils.abytes)(bytes, 56);
608
+ const { d } = ed448_CURVE;
609
+ const P = Fp.ORDER;
610
+ const mod = (n) => Fp448.create(n);
611
+ const s = Fp448.fromBytes(bytes);
612
+ // 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
613
+ // 2. Check that s is non-negative, or else abort
614
+ if (!(0,esm_utils.equalBytes)(Fn448.toBytes(s), bytes) || (0,modular.isNegativeLE)(s, P))
615
+ throw new Error('invalid decaf448 encoding 1');
616
+ const s2 = mod(s * s); // 1
617
+ const u1 = mod(ed448_1n + s2); // 2
618
+ const u1sq = mod(u1 * u1);
619
+ const u2 = mod(u1sq - _4n * d * s2); // 3
620
+ const { isValid, value: invsqrt } = invertSqrt(mod(u2 * u1sq)); // 4
621
+ let u3 = mod((s + s) * invsqrt * u1 * SQRT_MINUS_D); // 5
622
+ if ((0,modular.isNegativeLE)(u3, P))
623
+ u3 = mod(-u3);
624
+ const x = mod(u3 * invsqrt * u2 * INVSQRT_MINUS_D); // 6
625
+ const y = mod((ed448_1n - s2) * invsqrt * u1); // 7
626
+ const t = mod(x * y); // 8
627
+ if (!isValid)
628
+ throw new Error('invalid decaf448 encoding 2');
629
+ return new _DecafPoint(new ed448.Point(x, y, ed448_1n, t));
630
+ }
631
+ /**
632
+ * Converts decaf-encoded string to decaf point.
633
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
634
+ * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
635
+ */
636
+ static fromHex(hex) {
637
+ return _DecafPoint.fromBytes((0,esm_utils.ensureBytes)('decafHex', hex, 56));
638
+ }
639
+ /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
640
+ static msm(points, scalars) {
641
+ return (0,curve.pippenger)(_DecafPoint, Fn, points, scalars);
642
+ }
643
+ /**
644
+ * Encodes decaf point to Uint8Array.
645
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
646
+ */
647
+ toBytes() {
648
+ const { X, Z, T } = this.ep;
649
+ const P = Fp.ORDER;
650
+ const mod = (n) => Fp.create(n);
651
+ const u1 = mod(mod(X + T) * mod(X - T)); // 1
652
+ const x2 = mod(X * X);
653
+ const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
654
+ let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
655
+ if ((0,modular.isNegativeLE)(ratio, P))
656
+ ratio = mod(-ratio);
657
+ const u2 = mod(INVSQRT_MINUS_D * ratio * Z - T); // 4
658
+ let s = mod(ONE_MINUS_D * invsqrt * X * u2); // 5
659
+ if ((0,modular.isNegativeLE)(s, P))
660
+ s = mod(-s);
661
+ return Fn448.toBytes(s);
662
+ }
663
+ /**
664
+ * Compare one point to another.
665
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals-2).
666
+ */
667
+ equals(other) {
668
+ this.assertSame(other);
669
+ const { X: X1, Y: Y1 } = this.ep;
670
+ const { X: X2, Y: Y2 } = other.ep;
671
+ // (x1 * y2 == y1 * x2)
672
+ return Fp.create(X1 * Y2) === Fp.create(Y1 * X2);
673
+ }
674
+ is0() {
675
+ return this.equals(_DecafPoint.ZERO);
676
+ }
677
+ }
678
+ // The following gymnastics is done because typescript strips comments otherwise
679
+ // prettier-ignore
680
+ _DecafPoint.BASE =
681
+ /* @__PURE__ */ (() => new _DecafPoint(ed448.Point.BASE).multiplyUnsafe(ed448_2n))();
682
+ // prettier-ignore
683
+ _DecafPoint.ZERO =
684
+ /* @__PURE__ */ (() => new _DecafPoint(ed448.Point.ZERO))();
685
+ // prettier-ignore
686
+ _DecafPoint.Fp =
687
+ /* @__PURE__ */ (() => Fp448)();
688
+ // prettier-ignore
689
+ _DecafPoint.Fn =
690
+ /* @__PURE__ */ (() => Fn448)();
691
+ const decaf448 = { Point: _DecafPoint };
692
+ /** Hashing to decaf448 points / field. RFC 9380 methods. */
693
+ const decaf448_hasher = {
694
+ hashToCurve(msg, options) {
695
+ const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
696
+ return decaf448_map((0,hash_to_curve.expand_message_xof)(msg, DST, 112, 224, shake256));
697
+ },
698
+ // Warning: has big modulo bias of 2^-64.
699
+ // RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
700
+ // it must use 84-byte xof (56+56/2), not 64.
701
+ hashToScalar(msg, options = { DST: hash_to_curve._DST_scalar }) {
702
+ // Can't use `Fn448.fromBytes()`. 64-byte input => 56-byte field element
703
+ const xof = (0,hash_to_curve.expand_message_xof)(msg, options.DST, 64, 256, shake256);
704
+ return Fn448.create((0,esm_utils.bytesToNumberLE)(xof));
705
+ },
706
+ };
707
+ // export const decaf448_oprf: OPRF = createORPF({
708
+ // name: 'decaf448-SHAKE256',
709
+ // Point: DecafPoint,
710
+ // hash: (msg: Uint8Array) => shake256(msg, { dkLen: 64 }),
711
+ // hashToGroup: decaf448_hasher.hashToCurve,
712
+ // hashToScalar: decaf448_hasher.hashToScalar,
713
+ // });
714
+ /**
715
+ * Weird / bogus points, useful for debugging.
716
+ * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
717
+ * Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
718
+ * (0, 1), (0, -1), (-1, 0), (1, 0).
719
+ */
720
+ const ED448_TORSION_SUBGROUP = [
721
+ '010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
722
+ 'fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffff00',
723
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
724
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
725
+ ];
726
+ /** @deprecated use `decaf448.Point` */
727
+ const DecafPoint = _DecafPoint;
728
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
729
+ const hashToCurve = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
730
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
731
+ const encodeToCurve = /* @__PURE__ */ (() => ed448_hasher.encodeToCurve)();
732
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
733
+ const hashToDecaf448 = /* @__PURE__ */ (() => decaf448_hasher.hashToCurve)();
734
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
735
+ const hash_to_decaf448 = /* @__PURE__ */ (() => decaf448_hasher.hashToCurve)();
736
+ /** @deprecated use `ed448.utils.toMontgomery` */
737
+ function edwardsToMontgomeryPub(edwardsPub) {
738
+ return ed448.utils.toMontgomery((0,esm_utils.ensureBytes)('pub', edwardsPub));
739
+ }
740
+ /** @deprecated use `ed448.utils.toMontgomery` */
741
+ const edwardsToMontgomery = edwardsToMontgomeryPub;
742
+ //# sourceMappingURL=ed448.js.map
743
+
744
+ /***/ })
745
+
746
+ }]);
747
+ //# sourceMappingURL=defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map