@umbra-privacy/sdk 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +104 -25
  2. package/dist/{addresses-Brzgurv_.d.ts → addresses-B7HybtbJ.d.ts} +2 -1
  3. package/dist/{addresses-D_0YAS6B.d.cts → addresses-CTVY1oi7.d.cts} +2 -1
  4. package/dist/arcium-BXXlryfe.d.cts +20 -0
  5. package/dist/arcium-BXXlryfe.d.ts +20 -0
  6. package/dist/chunk-4RHXVBNI.js +203 -0
  7. package/dist/chunk-4RHXVBNI.js.map +1 -0
  8. package/dist/chunk-4TZVXB5G.js +324 -0
  9. package/dist/chunk-4TZVXB5G.js.map +1 -0
  10. package/dist/chunk-5GUSMQ74.cjs +549 -0
  11. package/dist/chunk-5GUSMQ74.cjs.map +1 -0
  12. package/dist/chunk-5KPQXPQM.js +36 -0
  13. package/dist/chunk-5KPQXPQM.js.map +1 -0
  14. package/dist/chunk-AXD7LXYY.cjs +405 -0
  15. package/dist/chunk-AXD7LXYY.cjs.map +1 -0
  16. package/dist/{chunk-HOEXDXRC.cjs → chunk-BL6WXLPV.cjs} +32 -360
  17. package/dist/chunk-BL6WXLPV.cjs.map +1 -0
  18. package/dist/chunk-CFFLOE7D.cjs +598 -0
  19. package/dist/chunk-CFFLOE7D.cjs.map +1 -0
  20. package/dist/{chunk-BM7N6N7E.js → chunk-CFTW5WNG.js} +3 -325
  21. package/dist/chunk-CFTW5WNG.js.map +1 -0
  22. package/dist/chunk-DD2WCK4C.js +327 -0
  23. package/dist/chunk-DD2WCK4C.js.map +1 -0
  24. package/dist/chunk-DMPMQ74B.cjs +246 -0
  25. package/dist/chunk-DMPMQ74B.cjs.map +1 -0
  26. package/dist/{chunk-2Q75CQQJ.js → chunk-EEKF4553.js} +2 -2
  27. package/dist/chunk-EEKF4553.js.map +1 -0
  28. package/dist/chunk-ENVYYEM4.cjs +113 -0
  29. package/dist/chunk-ENVYYEM4.cjs.map +1 -0
  30. package/dist/chunk-FQX6ZYGJ.js +500 -0
  31. package/dist/chunk-FQX6ZYGJ.js.map +1 -0
  32. package/dist/chunk-FSK2ICMB.cjs +39 -0
  33. package/dist/chunk-FSK2ICMB.cjs.map +1 -0
  34. package/dist/chunk-FZYWLQAF.cjs +355 -0
  35. package/dist/chunk-FZYWLQAF.cjs.map +1 -0
  36. package/dist/chunk-GP26R377.js +436 -0
  37. package/dist/chunk-GP26R377.js.map +1 -0
  38. package/dist/chunk-HA5FLM63.js +393 -0
  39. package/dist/chunk-HA5FLM63.js.map +1 -0
  40. package/dist/chunk-INJ73LXQ.js +1107 -0
  41. package/dist/chunk-INJ73LXQ.js.map +1 -0
  42. package/dist/chunk-JPDF7BIT.cjs +10892 -0
  43. package/dist/chunk-JPDF7BIT.cjs.map +1 -0
  44. package/dist/{chunk-MDFSBU5W.cjs → chunk-LTCKPTZC.cjs} +2 -351
  45. package/dist/chunk-LTCKPTZC.cjs.map +1 -0
  46. package/dist/chunk-MKNCBUFA.js +564 -0
  47. package/dist/chunk-MKNCBUFA.js.map +1 -0
  48. package/dist/chunk-NKVMSABR.cjs +207 -0
  49. package/dist/chunk-NKVMSABR.cjs.map +1 -0
  50. package/dist/chunk-OFDWNWCL.js +70 -0
  51. package/dist/chunk-OFDWNWCL.js.map +1 -0
  52. package/dist/chunk-QJAUUYZU.cjs +331 -0
  53. package/dist/chunk-QJAUUYZU.cjs.map +1 -0
  54. package/dist/chunk-RVUYPKKD.js +10750 -0
  55. package/dist/chunk-RVUYPKKD.js.map +1 -0
  56. package/dist/chunk-TLR7A64G.js +103 -0
  57. package/dist/chunk-TLR7A64G.js.map +1 -0
  58. package/dist/{chunk-MVKTV3FT.cjs → chunk-TQQZGNOI.cjs} +2 -2
  59. package/dist/chunk-TQQZGNOI.cjs.map +1 -0
  60. package/dist/chunk-UOFYS6M3.js +219 -0
  61. package/dist/chunk-UOFYS6M3.js.map +1 -0
  62. package/dist/chunk-UXMQI6B7.js +2406 -0
  63. package/dist/chunk-UXMQI6B7.js.map +1 -0
  64. package/dist/chunk-WN75ORDT.js +571 -0
  65. package/dist/chunk-WN75ORDT.js.map +1 -0
  66. package/dist/chunk-Y55PYKXH.cjs +595 -0
  67. package/dist/chunk-Y55PYKXH.cjs.map +1 -0
  68. package/dist/chunk-YEZBTYCP.cjs +77 -0
  69. package/dist/chunk-YEZBTYCP.cjs.map +1 -0
  70. package/dist/chunk-ZQOIYCGA.cjs +1126 -0
  71. package/dist/chunk-ZQOIYCGA.cjs.map +1 -0
  72. package/dist/chunk-ZY3TSHMJ.cjs +2665 -0
  73. package/dist/chunk-ZY3TSHMJ.cjs.map +1 -0
  74. package/dist/client-DkVBHMWb.d.cts +2613 -0
  75. package/dist/client-V4AF6Bz9.d.ts +2613 -0
  76. package/dist/common/pda/index.cjs +145 -0
  77. package/dist/common/pda/index.cjs.map +1 -0
  78. package/dist/common/pda/index.d.cts +1250 -0
  79. package/dist/common/pda/index.d.ts +1250 -0
  80. package/dist/common/pda/index.js +8 -0
  81. package/dist/common/pda/index.js.map +1 -0
  82. package/dist/constants/index.cjs +38 -164
  83. package/dist/constants/index.cjs.map +1 -1
  84. package/dist/constants/index.d.cts +8 -425
  85. package/dist/constants/index.d.ts +8 -425
  86. package/dist/constants/index.js +15 -124
  87. package/dist/constants/index.js.map +1 -1
  88. package/dist/crypto/index.cjs +583 -0
  89. package/dist/crypto/index.cjs.map +1 -0
  90. package/dist/crypto/index.d.cts +6731 -0
  91. package/dist/crypto/index.d.ts +6731 -0
  92. package/dist/crypto/index.js +14 -0
  93. package/dist/crypto/index.js.map +1 -0
  94. package/dist/{cryptography-BTGC72u-.d.ts → cryptography-BFSJcvi6.d.ts} +3 -2465
  95. package/dist/{cryptography-BTGC72u-.d.cts → cryptography-D6tPDh-Y.d.cts} +3 -2465
  96. package/dist/errors/index.cjs +64 -54
  97. package/dist/errors/index.d.cts +7 -797
  98. package/dist/errors/index.d.ts +7 -797
  99. package/dist/errors/index.js +3 -1
  100. package/dist/errors-B9EoPeWV.d.cts +593 -0
  101. package/dist/errors-B9EoPeWV.d.ts +593 -0
  102. package/dist/errors-DAIrstEL.d.cts +300 -0
  103. package/dist/errors-DPNMfyh0.d.ts +300 -0
  104. package/dist/index-BG0yjL7C.d.cts +6006 -0
  105. package/dist/index-ByynoyBO.d.ts +6006 -0
  106. package/dist/index.cjs +5126 -16118
  107. package/dist/index.cjs.map +1 -1
  108. package/dist/index.d.cts +1031 -7685
  109. package/dist/index.d.ts +1031 -7685
  110. package/dist/index.js +3219 -14905
  111. package/dist/index.js.map +1 -1
  112. package/dist/interfaces/index.d.cts +14 -6
  113. package/dist/interfaces/index.d.ts +14 -6
  114. package/dist/interfaces-43cReBcS.d.cts +3346 -0
  115. package/dist/interfaces-B8xKNl_6.d.ts +997 -0
  116. package/dist/interfaces-D2NO6kDD.d.cts +997 -0
  117. package/dist/interfaces-z_xYJlgV.d.ts +3346 -0
  118. package/dist/math/index.cjs +115 -0
  119. package/dist/math/index.cjs.map +1 -0
  120. package/dist/math/index.d.cts +1327 -0
  121. package/dist/math/index.d.ts +1327 -0
  122. package/dist/math/index.js +10 -0
  123. package/dist/math/index.js.map +1 -0
  124. package/dist/networks-RMd3abPE.d.ts +44 -0
  125. package/dist/networks-yAoO8peQ.d.cts +44 -0
  126. package/dist/relayer-NRRMSMNB.js +4 -0
  127. package/dist/relayer-NRRMSMNB.js.map +1 -0
  128. package/dist/relayer-RJHEIXJG.cjs +21 -0
  129. package/dist/relayer-RJHEIXJG.cjs.map +1 -0
  130. package/dist/solana/index.cjs +56 -0
  131. package/dist/solana/index.cjs.map +1 -0
  132. package/dist/solana/index.d.cts +105 -0
  133. package/dist/solana/index.d.ts +105 -0
  134. package/dist/solana/index.js +7 -0
  135. package/dist/solana/index.js.map +1 -0
  136. package/dist/{index-CLj_zWSD.d.ts → temporal-BbRaEPoO.d.ts} +1 -1
  137. package/dist/{index-CX6_pIRS.d.cts → temporal-oUj7iCaq.d.cts} +1 -1
  138. package/dist/transaction-forwarder-5mAMTjw6.d.ts +1155 -0
  139. package/dist/transaction-forwarder-C6gMUG7a.d.cts +1155 -0
  140. package/dist/types/index.cjs +232 -231
  141. package/dist/types/index.d.cts +15 -1485
  142. package/dist/types/index.d.ts +15 -1485
  143. package/dist/types/index.js +2 -1
  144. package/dist/types-BohhvPth.d.cts +87 -0
  145. package/dist/types-CW0oTT0j.d.ts +87 -0
  146. package/dist/types-C_V_CaKK.d.cts +2468 -0
  147. package/dist/types-C_V_CaKK.d.ts +2468 -0
  148. package/dist/types-Ca7frykr.d.ts +793 -0
  149. package/dist/types-CuKeoI19.d.cts +1296 -0
  150. package/dist/types-CxfTIpN9.d.ts +1052 -0
  151. package/dist/{types-n-sHFcgr.d.ts → types-D1jDUjfN.d.ts} +2 -2
  152. package/dist/types-DKEDUlH9.d.ts +1296 -0
  153. package/dist/types-EKuIfxTz.d.cts +1052 -0
  154. package/dist/{types-BBuELtY8.d.cts → types-IMGYmlv-.d.cts} +2 -2
  155. package/dist/types-PwNLi_2k.d.cts +793 -0
  156. package/dist/utils/index.cjs +823 -525
  157. package/dist/utils/index.d.cts +1711 -4021
  158. package/dist/utils/index.d.ts +1711 -4021
  159. package/dist/utils/index.js +9 -3
  160. package/dist/{versions-D9PqsEvj.d.cts → versions-BRlR36EA.d.cts} +1 -0
  161. package/dist/{versions-D9PqsEvj.d.ts → versions-BRlR36EA.d.ts} +1 -0
  162. package/package.json +79 -18
  163. package/dist/chunk-2Q75CQQJ.js.map +0 -1
  164. package/dist/chunk-BM7N6N7E.js.map +0 -1
  165. package/dist/chunk-GXKSUB2U.cjs +0 -4416
  166. package/dist/chunk-GXKSUB2U.cjs.map +0 -1
  167. package/dist/chunk-HOEXDXRC.cjs.map +0 -1
  168. package/dist/chunk-MDFSBU5W.cjs.map +0 -1
  169. package/dist/chunk-MQY7HDIA.js +0 -600
  170. package/dist/chunk-MQY7HDIA.js.map +0 -1
  171. package/dist/chunk-MVKTV3FT.cjs.map +0 -1
  172. package/dist/chunk-PG2J6V6Y.js +0 -4094
  173. package/dist/chunk-PG2J6V6Y.js.map +0 -1
  174. package/dist/chunk-VEGLTTYQ.cjs +0 -621
  175. package/dist/chunk-VEGLTTYQ.cjs.map +0 -1
  176. package/dist/chunk-WVHQ46DD.js +0 -758
  177. package/dist/chunk-WVHQ46DD.js.map +0 -1
  178. package/dist/index-B9pDY73x.d.ts +0 -12933
  179. package/dist/index-D33yo0qB.d.cts +0 -12933
  180. package/dist/networks-C-orpSFW.d.ts +0 -65
  181. package/dist/networks-FxYERGD1.d.cts +0 -65
@@ -0,0 +1,595 @@
1
+ 'use strict';
2
+
3
+ var chunkDMPMQ74B_cjs = require('./chunk-DMPMQ74B.cjs');
4
+ var chunk5GUSMQ74_cjs = require('./chunk-5GUSMQ74.cjs');
5
+ var chunkQJAUUYZU_cjs = require('./chunk-QJAUUYZU.cjs');
6
+ var chunkLTCKPTZC_cjs = require('./chunk-LTCKPTZC.cjs');
7
+ var chunkPK6SKIKE_cjs = require('./chunk-PK6SKIKE.cjs');
8
+
9
+ // src/math/bn254/types.ts
10
+ var BN254_FIELD_PRIME = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
11
+ function assertBn254FieldElement(value, name = "value") {
12
+ const variableName = name;
13
+ if (typeof value !== "bigint") {
14
+ throw new chunkQJAUUYZU_cjs.CryptographyAssertionError(`${variableName}: Expected bigint, got ${typeof value}`, {
15
+ value,
16
+ expectedType: "Bn254FieldElement"
17
+ });
18
+ }
19
+ if (value < 0n) {
20
+ throw new chunkQJAUUYZU_cjs.CryptographyAssertionError(`${variableName}: Value ${String(value)} is negative`, {
21
+ value,
22
+ expectedType: "Bn254FieldElement",
23
+ constraint: "value >= 0"
24
+ });
25
+ }
26
+ if (value >= BN254_FIELD_PRIME) {
27
+ throw new chunkQJAUUYZU_cjs.CryptographyAssertionError(`${variableName}: Value exceeds BN254 field prime`, {
28
+ value,
29
+ expectedType: "Bn254FieldElement",
30
+ constraint: `value < ${String(BN254_FIELD_PRIME)}`
31
+ });
32
+ }
33
+ }
34
+ chunkPK6SKIKE_cjs.__name(assertBn254FieldElement, "assertBn254FieldElement");
35
+
36
+ // src/math/bn254/field-arithmetic.ts
37
+ var N64 = 64n;
38
+ var MASK64 = 0xffffffffffffffffn;
39
+ var P_LIMBS = [
40
+ 0x43e1f593f0000001n,
41
+ // limb 0 (bits 0-63)
42
+ 0x2833e84879b97091n,
43
+ // limb 1 (bits 64-127)
44
+ 0xb85045b68181585dn,
45
+ // limb 2 (bits 128-191)
46
+ 0x30644e72e131a029n
47
+ // limb 3 (bits 192-255)
48
+ ];
49
+ var P_PRIME = 0xc2e1f593efffffffn;
50
+ var R2_LIMBS = [
51
+ 0x1bb8e645ae216da7n,
52
+ 0x53fe3ab1e35c59e3n,
53
+ 0x8c49833d53bb8085n,
54
+ 0x0216d0b17f4e44a5n
55
+ ];
56
+ var ONE_MONT = [
57
+ 0xac96341c4ffffffbn,
58
+ 0x36fc76959f60cd29n,
59
+ 0x666ea36f7879462en,
60
+ 0x0e0a77c19a07df2fn
61
+ ];
62
+ function ctSelect(bit, x, y) {
63
+ const mask = -bit;
64
+ return x & mask | y & ~mask;
65
+ }
66
+ chunkPK6SKIKE_cjs.__name(ctSelect, "ctSelect");
67
+ function bigintToLimbs(value) {
68
+ return [
69
+ value & MASK64,
70
+ value >> N64 & MASK64,
71
+ value >> N64 * 2n & MASK64,
72
+ value >> N64 * 3n & MASK64
73
+ ];
74
+ }
75
+ chunkPK6SKIKE_cjs.__name(bigintToLimbs, "bigintToLimbs");
76
+ function limbsToBigint(limbs) {
77
+ return limbs[0] + (limbs[1] << N64) + (limbs[2] << N64 * 2n) + (limbs[3] << N64 * 3n);
78
+ }
79
+ chunkPK6SKIKE_cjs.__name(limbsToBigint, "limbsToBigint");
80
+ function addModuleLimbs(a, b) {
81
+ const t = [0n, 0n, 0n, 0n];
82
+ let carry = 0n;
83
+ for (let index = 0; index < 4; index++) {
84
+ const sum = a[index] + b[index] + carry;
85
+ t[index] = sum & MASK64;
86
+ carry = sum >> N64;
87
+ }
88
+ const tCarry = carry;
89
+ const d = [0n, 0n, 0n, 0n];
90
+ let borrow = 0n;
91
+ for (let index = 0; index < 4; index++) {
92
+ const sub = t[index] - P_LIMBS[index] - borrow;
93
+ d[index] = sub & MASK64;
94
+ borrow = -(sub >> N64);
95
+ }
96
+ const useD = tCarry | 1n - borrow;
97
+ return [
98
+ ctSelect(useD, d[0], t[0]),
99
+ ctSelect(useD, d[1], t[1]),
100
+ ctSelect(useD, d[2], t[2]),
101
+ ctSelect(useD, d[3], t[3])
102
+ ];
103
+ }
104
+ chunkPK6SKIKE_cjs.__name(addModuleLimbs, "addModuleLimbs");
105
+ function subModuleLimbs(a, b) {
106
+ const out = [0n, 0n, 0n, 0n];
107
+ let borrow = 0n;
108
+ for (let index = 0; index < 4; index++) {
109
+ const sub = a[index] - b[index] - borrow;
110
+ out[index] = sub & MASK64;
111
+ borrow = -(sub >> N64);
112
+ }
113
+ const mask = -borrow;
114
+ let carry = 0n;
115
+ for (let index = 0; index < 4; index++) {
116
+ const addValue = P_LIMBS[index] & mask;
117
+ const sum = out[index] + addValue + carry;
118
+ out[index] = sum & MASK64;
119
+ carry = sum >> N64;
120
+ }
121
+ return [out[0], out[1], out[2], out[3]];
122
+ }
123
+ chunkPK6SKIKE_cjs.__name(subModuleLimbs, "subModuleLimbs");
124
+ function montgomeryMulLimbs(a, b) {
125
+ const t = [0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n];
126
+ for (let index = 0; index < 4; index++) {
127
+ let carry = 0n;
128
+ for (let innerIndex = 0; innerIndex < 4; innerIndex++) {
129
+ const sum = t[index + innerIndex] + a[index] * b[innerIndex] + carry;
130
+ t[index + innerIndex] = sum & MASK64;
131
+ carry = sum >> N64;
132
+ }
133
+ t[index + 4] = t[index + 4] + carry;
134
+ const m = t[index] * P_PRIME & MASK64;
135
+ let carryRed = 0n;
136
+ for (let innerIndex = 0; innerIndex < 4; innerIndex++) {
137
+ const sum = t[index + innerIndex] + m * P_LIMBS[innerIndex] + carryRed;
138
+ t[index + innerIndex] = sum & MASK64;
139
+ carryRed = sum >> N64;
140
+ }
141
+ const sumUp = t[index + 4] + carryRed;
142
+ t[index + 4] = sumUp & MASK64;
143
+ t[index + 5] = t[index + 5] + (sumUp >> N64);
144
+ }
145
+ const result = [t[4], t[5], t[6], t[7]];
146
+ const subResult = [0n, 0n, 0n, 0n];
147
+ let borrow = 0n;
148
+ for (let k = 0; k < 4; k++) {
149
+ const s = result[k] - P_LIMBS[k] - borrow;
150
+ subResult[k] = s & MASK64;
151
+ borrow = -(s >> N64);
152
+ }
153
+ const useSub = 1n - borrow;
154
+ return [
155
+ ctSelect(useSub, subResult[0], result[0]),
156
+ ctSelect(useSub, subResult[1], result[1]),
157
+ ctSelect(useSub, subResult[2], result[2]),
158
+ ctSelect(useSub, subResult[3], result[3])
159
+ ];
160
+ }
161
+ chunkPK6SKIKE_cjs.__name(montgomeryMulLimbs, "montgomeryMulLimbs");
162
+ function toMontgomery(a) {
163
+ return montgomeryMulLimbs(a, R2_LIMBS);
164
+ }
165
+ chunkPK6SKIKE_cjs.__name(toMontgomery, "toMontgomery");
166
+ function fromMontgomery(a) {
167
+ const one = [1n, 0n, 0n, 0n];
168
+ return montgomeryMulLimbs(a, one);
169
+ }
170
+ chunkPK6SKIKE_cjs.__name(fromMontgomery, "fromMontgomery");
171
+ function negModuleLimbs(a) {
172
+ const isZero = (a[0] | a[1] | a[2] | a[3]) === 0n ? 1n : 0n;
173
+ const result = subModuleLimbs(P_LIMBS, a);
174
+ return [
175
+ ctSelect(isZero, 0n, result[0]),
176
+ ctSelect(isZero, 0n, result[1]),
177
+ ctSelect(isZero, 0n, result[2]),
178
+ ctSelect(isZero, 0n, result[3])
179
+ ];
180
+ }
181
+ chunkPK6SKIKE_cjs.__name(negModuleLimbs, "negModuleLimbs");
182
+ function moduleExpMontgomery(base, exp) {
183
+ let result = ONE_MONT;
184
+ let current = base;
185
+ while (exp > 0n) {
186
+ if ((exp & 1n) === 1n) {
187
+ result = montgomeryMulLimbs(result, current);
188
+ }
189
+ current = montgomeryMulLimbs(current, current);
190
+ exp >>= 1n;
191
+ }
192
+ return result;
193
+ }
194
+ chunkPK6SKIKE_cjs.__name(moduleExpMontgomery, "moduleExpMontgomery");
195
+ var bn254ModuloAdd = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a, b) => {
196
+ const aLimbs = bigintToLimbs(a);
197
+ const bLimbs = bigintToLimbs(b);
198
+ const resultLimbs = addModuleLimbs(aLimbs, bLimbs);
199
+ return limbsToBigint(resultLimbs);
200
+ }, "bn254ModuloAdd");
201
+ var bn254ModuloSub = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a, b) => {
202
+ const aLimbs = bigintToLimbs(a);
203
+ const bLimbs = bigintToLimbs(b);
204
+ const resultLimbs = subModuleLimbs(aLimbs, bLimbs);
205
+ return limbsToBigint(resultLimbs);
206
+ }, "bn254ModuloSub");
207
+ var bn254ModuloMul = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a, b) => {
208
+ const aLimbs = bigintToLimbs(a);
209
+ const bLimbs = bigintToLimbs(b);
210
+ const aMont = toMontgomery(aLimbs);
211
+ const bMont = toMontgomery(bLimbs);
212
+ const resultMont = montgomeryMulLimbs(aMont, bMont);
213
+ const resultLimbs = fromMontgomery(resultMont);
214
+ return limbsToBigint(resultLimbs);
215
+ }, "bn254ModuloMul");
216
+ var bn254ModuloNeg = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a) => {
217
+ const aLimbs = bigintToLimbs(a);
218
+ const resultLimbs = negModuleLimbs(aLimbs);
219
+ return limbsToBigint(resultLimbs);
220
+ }, "bn254ModuloNeg");
221
+ var bn254ModuloInv = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a) => {
222
+ if (a === 0n) {
223
+ throw new Error("Cannot compute modular inverse of zero");
224
+ }
225
+ const aLimbs = bigintToLimbs(a);
226
+ const aMont = toMontgomery(aLimbs);
227
+ const exp = BN254_FIELD_PRIME - 2n;
228
+ const resultMont = moduleExpMontgomery(aMont, exp);
229
+ const resultLimbs = fromMontgomery(resultMont);
230
+ return limbsToBigint(resultLimbs);
231
+ }, "bn254ModuloInv");
232
+ var cachedModuleAdder = null;
233
+ var cachedModuleSubtractor = null;
234
+ var cachedModuleMultiplier = null;
235
+ var cachedModuleNegator = null;
236
+ var cachedModuleInverter = null;
237
+ function getBn254ModularAdder() {
238
+ cachedModuleAdder ??= bn254ModuloAdd;
239
+ return cachedModuleAdder;
240
+ }
241
+ chunkPK6SKIKE_cjs.__name(getBn254ModularAdder, "getBn254ModularAdder");
242
+ function getBn254ModularSubtractor() {
243
+ cachedModuleSubtractor ??= bn254ModuloSub;
244
+ return cachedModuleSubtractor;
245
+ }
246
+ chunkPK6SKIKE_cjs.__name(getBn254ModularSubtractor, "getBn254ModularSubtractor");
247
+ function getBn254ModularMultiplier() {
248
+ cachedModuleMultiplier ??= bn254ModuloMul;
249
+ return cachedModuleMultiplier;
250
+ }
251
+ chunkPK6SKIKE_cjs.__name(getBn254ModularMultiplier, "getBn254ModularMultiplier");
252
+ function getBn254ModularNegator() {
253
+ cachedModuleNegator ??= bn254ModuloNeg;
254
+ return cachedModuleNegator;
255
+ }
256
+ chunkPK6SKIKE_cjs.__name(getBn254ModularNegator, "getBn254ModularNegator");
257
+ function getBn254ModularInverter() {
258
+ cachedModuleInverter ??= bn254ModuloInv;
259
+ return cachedModuleInverter;
260
+ }
261
+ chunkPK6SKIKE_cjs.__name(getBn254ModularInverter, "getBn254ModularInverter");
262
+ function computeBn254LimbwiseSumInverse(limbs) {
263
+ const sum = (limbs.low + limbs.middle + limbs.high) % BN254_FIELD_PRIME;
264
+ if (sum === 0n) {
265
+ throw new Error(
266
+ "Cannot compute modular inverse of zero sum. The sum of Base85 limbs must be non-zero."
267
+ );
268
+ }
269
+ const inverse = bn254ModuloInv(sum);
270
+ assertBn254FieldElement(inverse);
271
+ return inverse;
272
+ }
273
+ chunkPK6SKIKE_cjs.__name(computeBn254LimbwiseSumInverse, "computeBn254LimbwiseSumInverse");
274
+
275
+ // src/math/bn254/field-element-sampler.ts
276
+ var N642 = 64n;
277
+ var MASK642 = 0xffffffffffffffffn;
278
+ var P_LIMBS2 = [
279
+ 0x43e1f593f0000001n,
280
+ // limb 0 (bits 0-63)
281
+ 0x2833e84879b97091n,
282
+ // limb 1 (bits 64-127)
283
+ 0xb85045b68181585dn,
284
+ // limb 2 (bits 128-191)
285
+ 0x30644e72e131a029n
286
+ // limb 3 (bits 192-255)
287
+ ];
288
+ var R_MOD_P = 6350874878119819312338956282401532410528162663560392320966563075034087161851n;
289
+ function ctSelect2(bit, x, y) {
290
+ const mask = -bit;
291
+ return x & mask | y & ~mask;
292
+ }
293
+ chunkPK6SKIKE_cjs.__name(ctSelect2, "ctSelect");
294
+ function bigintToLimbs2(value) {
295
+ return [
296
+ value & MASK642,
297
+ value >> N642 & MASK642,
298
+ value >> N642 * 2n & MASK642,
299
+ value >> N642 * 3n & MASK642
300
+ ];
301
+ }
302
+ chunkPK6SKIKE_cjs.__name(bigintToLimbs2, "bigintToLimbs");
303
+ function limbsToBigint2(limbs) {
304
+ return limbs[0] + (limbs[1] << N642) + (limbs[2] << N642 * 2n) + (limbs[3] << N642 * 3n);
305
+ }
306
+ chunkPK6SKIKE_cjs.__name(limbsToBigint2, "limbsToBigint");
307
+ function conditionalSubtractP(limbs) {
308
+ const [l0, l1, l2, l3] = limbs;
309
+ const [p0, p1, p2, p3] = P_LIMBS2;
310
+ const sub0 = l0 - p0;
311
+ const d0 = sub0 & MASK642;
312
+ const borrow0 = -(sub0 >> N642) & 1n;
313
+ const sub1 = l1 - p1 - borrow0;
314
+ const d1 = sub1 & MASK642;
315
+ const borrow1 = -(sub1 >> N642) & 1n;
316
+ const sub2 = l2 - p2 - borrow1;
317
+ const d2 = sub2 & MASK642;
318
+ const borrow2 = -(sub2 >> N642) & 1n;
319
+ const sub3 = l3 - p3 - borrow2;
320
+ const d3 = sub3 & MASK642;
321
+ const borrow3 = -(sub3 >> N642) & 1n;
322
+ const useOriginal = borrow3;
323
+ return [
324
+ ctSelect2(useOriginal, l0, d0),
325
+ ctSelect2(useOriginal, l1, d1),
326
+ ctSelect2(useOriginal, l2, d2),
327
+ ctSelect2(useOriginal, l3, d3)
328
+ ];
329
+ }
330
+ chunkPK6SKIKE_cjs.__name(conditionalSubtractP, "conditionalSubtractP");
331
+ function reduce256(value) {
332
+ let limbs = bigintToLimbs2(value);
333
+ limbs = conditionalSubtractP(limbs);
334
+ limbs = conditionalSubtractP(limbs);
335
+ limbs = conditionalSubtractP(limbs);
336
+ limbs = conditionalSubtractP(limbs);
337
+ limbs = conditionalSubtractP(limbs);
338
+ return limbsToBigint2(limbs);
339
+ }
340
+ chunkPK6SKIKE_cjs.__name(reduce256, "reduce256");
341
+ function bytesToBigintBE(bytes, offset) {
342
+ const slice = bytes.slice(offset, offset + chunkLTCKPTZC_cjs.U256_BYTE_LENGTH);
343
+ const u256BeBytes = chunkDMPMQ74B_cjs.createU256BeBytes(slice);
344
+ return chunk5GUSMQ74_cjs.decodeU256BeBytesToU256(u256BeBytes);
345
+ }
346
+ chunkPK6SKIKE_cjs.__name(bytesToBigintBE, "bytesToBigintBE");
347
+ function getBn254FieldElementSampler(deps) {
348
+ const { modAdd: moduleAdd = bn254ModuloAdd, modMul: moduleMul = bn254ModuloMul } = deps ?? {};
349
+ return (input) => {
350
+ const high = bytesToBigintBE(input, 0);
351
+ const low = bytesToBigintBE(input, 32);
352
+ const lowReduced = reduce256(low);
353
+ const highReduced = reduce256(high);
354
+ const highTimesR = moduleMul(highReduced, R_MOD_P);
355
+ const result = moduleAdd(highTimesR, lowReduced);
356
+ return result;
357
+ };
358
+ }
359
+ chunkPK6SKIKE_cjs.__name(getBn254FieldElementSampler, "getBn254FieldElementSampler");
360
+ var bn254FieldElementSampler = getBn254FieldElementSampler();
361
+
362
+ // src/math/curve25519/types.ts
363
+ var CURVE25519_FIELD_PRIME = (1n << 255n) - 19n;
364
+
365
+ // src/math/curve25519/field-arithmetic.ts
366
+ var N643 = 64n;
367
+ var MASK643 = 0xffffffffffffffffn;
368
+ var P_LIMBS3 = [
369
+ 0xffffffffffffffedn,
370
+ // limb 0 (bits 0-63): 2^64 - 19
371
+ 0xffffffffffffffffn,
372
+ // limb 1 (bits 64-127): all 1s
373
+ 0xffffffffffffffffn,
374
+ // limb 2 (bits 128-191): all 1s
375
+ 0x7fffffffffffffffn
376
+ // limb 3 (bits 192-255): 2^63 - 1
377
+ ];
378
+ function ctSelect3(bit, x, y) {
379
+ const mask = -bit;
380
+ return x & mask | y & ~mask;
381
+ }
382
+ chunkPK6SKIKE_cjs.__name(ctSelect3, "ctSelect");
383
+ function bigintToLimbs3(value) {
384
+ return [
385
+ value & MASK643,
386
+ value >> N643 & MASK643,
387
+ value >> N643 * 2n & MASK643,
388
+ value >> N643 * 3n & MASK643
389
+ ];
390
+ }
391
+ chunkPK6SKIKE_cjs.__name(bigintToLimbs3, "bigintToLimbs");
392
+ function limbsToBigint3(limbs) {
393
+ return limbs[0] + (limbs[1] << N643) + (limbs[2] << N643 * 2n) + (limbs[3] << N643 * 3n);
394
+ }
395
+ chunkPK6SKIKE_cjs.__name(limbsToBigint3, "limbsToBigint");
396
+ function addModuleLimbs2(a, b) {
397
+ const t = [0n, 0n, 0n, 0n];
398
+ let carry = 0n;
399
+ for (let index = 0; index < 4; index++) {
400
+ const sum = a[index] + b[index] + carry;
401
+ t[index] = sum & MASK643;
402
+ carry = sum >> N643;
403
+ }
404
+ const tCarry = carry;
405
+ const d = [0n, 0n, 0n, 0n];
406
+ let borrow = 0n;
407
+ for (let index = 0; index < 4; index++) {
408
+ const sub = t[index] - P_LIMBS3[index] - borrow;
409
+ d[index] = sub & MASK643;
410
+ borrow = -(sub >> N643);
411
+ }
412
+ const useD = tCarry | 1n - borrow;
413
+ return [
414
+ ctSelect3(useD, d[0], t[0]),
415
+ ctSelect3(useD, d[1], t[1]),
416
+ ctSelect3(useD, d[2], t[2]),
417
+ ctSelect3(useD, d[3], t[3])
418
+ ];
419
+ }
420
+ chunkPK6SKIKE_cjs.__name(addModuleLimbs2, "addModuleLimbs");
421
+ function subModuleLimbs2(a, b) {
422
+ const out = [0n, 0n, 0n, 0n];
423
+ let borrow = 0n;
424
+ for (let index = 0; index < 4; index++) {
425
+ const sub = a[index] - b[index] - borrow;
426
+ out[index] = sub & MASK643;
427
+ borrow = -(sub >> N643);
428
+ }
429
+ const mask = -borrow;
430
+ let carry = 0n;
431
+ for (let index = 0; index < 4; index++) {
432
+ const addValue = P_LIMBS3[index] & mask;
433
+ const sum = out[index] + addValue + carry;
434
+ out[index] = sum & MASK643;
435
+ carry = sum >> N643;
436
+ }
437
+ return [out[0], out[1], out[2], out[3]];
438
+ }
439
+ chunkPK6SKIKE_cjs.__name(subModuleLimbs2, "subModuleLimbs");
440
+ function mulModuleLimbs(a, b) {
441
+ const aBig = limbsToBigint3(a);
442
+ const bBig = limbsToBigint3(b);
443
+ const product = aBig * bBig % CURVE25519_FIELD_PRIME;
444
+ return bigintToLimbs3(product);
445
+ }
446
+ chunkPK6SKIKE_cjs.__name(mulModuleLimbs, "mulModuleLimbs");
447
+ function moduleExpLimbs(base, exp) {
448
+ let result = [1n, 0n, 0n, 0n];
449
+ let current = base;
450
+ while (exp > 0n) {
451
+ if ((exp & 1n) === 1n) {
452
+ result = mulModuleLimbs(result, current);
453
+ }
454
+ current = mulModuleLimbs(current, current);
455
+ exp >>= 1n;
456
+ }
457
+ return result;
458
+ }
459
+ chunkPK6SKIKE_cjs.__name(moduleExpLimbs, "moduleExpLimbs");
460
+ var curve25519ModuloAdd = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a, b) => {
461
+ const aLimbs = bigintToLimbs3(a);
462
+ const bLimbs = bigintToLimbs3(b);
463
+ const resultLimbs = addModuleLimbs2(aLimbs, bLimbs);
464
+ return limbsToBigint3(resultLimbs);
465
+ }, "curve25519ModuloAdd");
466
+ var curve25519ModuloSub = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a, b) => {
467
+ const aLimbs = bigintToLimbs3(a);
468
+ const bLimbs = bigintToLimbs3(b);
469
+ const resultLimbs = subModuleLimbs2(aLimbs, bLimbs);
470
+ return limbsToBigint3(resultLimbs);
471
+ }, "curve25519ModuloSub");
472
+ var curve25519ModuloMul = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a, b) => {
473
+ const aLimbs = bigintToLimbs3(a);
474
+ const bLimbs = bigintToLimbs3(b);
475
+ const resultLimbs = mulModuleLimbs(aLimbs, bLimbs);
476
+ return limbsToBigint3(resultLimbs);
477
+ }, "curve25519ModuloMul");
478
+ var curve25519ModuloInv = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((a) => {
479
+ if (a === 0n) {
480
+ throw new Error("Cannot compute modular inverse of zero");
481
+ }
482
+ const aLimbs = bigintToLimbs3(a);
483
+ const exp = CURVE25519_FIELD_PRIME - 2n;
484
+ const resultLimbs = moduleExpLimbs(aLimbs, exp);
485
+ return limbsToBigint3(resultLimbs);
486
+ }, "curve25519ModuloInv");
487
+ var curve25519ModuloPow = /* @__PURE__ */ chunkPK6SKIKE_cjs.__name((base, exp) => {
488
+ if (exp === 0n) {
489
+ return 1n;
490
+ }
491
+ const baseLimbs = bigintToLimbs3(base);
492
+ const resultLimbs = moduleExpLimbs(baseLimbs, exp);
493
+ return limbsToBigint3(resultLimbs);
494
+ }, "curve25519ModuloPow");
495
+ var cachedModuleAddFunction = null;
496
+ var cachedModuleSubFunction = null;
497
+ var cachedModuleMulFunction = null;
498
+ var cachedModuleInvFunction = null;
499
+ var cachedModulePowFunction = null;
500
+ function getCurve25519ModularAddFunction() {
501
+ cachedModuleAddFunction ??= curve25519ModuloAdd;
502
+ return cachedModuleAddFunction;
503
+ }
504
+ chunkPK6SKIKE_cjs.__name(getCurve25519ModularAddFunction, "getCurve25519ModularAddFunction");
505
+ function getCurve25519ModularSubFunction() {
506
+ cachedModuleSubFunction ??= curve25519ModuloSub;
507
+ return cachedModuleSubFunction;
508
+ }
509
+ chunkPK6SKIKE_cjs.__name(getCurve25519ModularSubFunction, "getCurve25519ModularSubFunction");
510
+ function getCurve25519ModularMulFunction() {
511
+ cachedModuleMulFunction ??= curve25519ModuloMul;
512
+ return cachedModuleMulFunction;
513
+ }
514
+ chunkPK6SKIKE_cjs.__name(getCurve25519ModularMulFunction, "getCurve25519ModularMulFunction");
515
+ function getCurve25519ModularInvFunction() {
516
+ cachedModuleInvFunction ??= curve25519ModuloInv;
517
+ return cachedModuleInvFunction;
518
+ }
519
+ chunkPK6SKIKE_cjs.__name(getCurve25519ModularInvFunction, "getCurve25519ModularInvFunction");
520
+ function getCurve25519ModularPowFunction() {
521
+ cachedModulePowFunction ??= curve25519ModuloPow;
522
+ return cachedModulePowFunction;
523
+ }
524
+ chunkPK6SKIKE_cjs.__name(getCurve25519ModularPowFunction, "getCurve25519ModularPowFunction");
525
+ var R_MOD_P_CURVE25519 = 38n;
526
+ function reduce256Curve25519(value) {
527
+ const [l0, l1, l2, l3] = bigintToLimbs3(value);
528
+ const [p0, p1, p2, p3] = P_LIMBS3;
529
+ const sub0 = l0 - p0;
530
+ const d0 = sub0 & MASK643;
531
+ const borrow0 = -(sub0 >> N643) & 1n;
532
+ const sub1 = l1 - p1 - borrow0;
533
+ const d1 = sub1 & MASK643;
534
+ const borrow1 = -(sub1 >> N643) & 1n;
535
+ const sub2 = l2 - p2 - borrow1;
536
+ const d2 = sub2 & MASK643;
537
+ const borrow2 = -(sub2 >> N643) & 1n;
538
+ const sub3 = l3 - p3 - borrow2;
539
+ const d3 = sub3 & MASK643;
540
+ const borrow3 = -(sub3 >> N643) & 1n;
541
+ const useOriginal = borrow3;
542
+ return limbsToBigint3([
543
+ ctSelect3(useOriginal, l0, d0),
544
+ ctSelect3(useOriginal, l1, d1),
545
+ ctSelect3(useOriginal, l2, d2),
546
+ ctSelect3(useOriginal, l3, d3)
547
+ ]);
548
+ }
549
+ chunkPK6SKIKE_cjs.__name(reduce256Curve25519, "reduce256Curve25519");
550
+ function bytesToBigintBECurve25519(bytes, offset) {
551
+ const slice = bytes.slice(offset, offset + chunkLTCKPTZC_cjs.U256_BYTE_LENGTH);
552
+ const u256BeBytes = chunkDMPMQ74B_cjs.createU256BeBytes(slice);
553
+ return chunk5GUSMQ74_cjs.decodeU256BeBytesToU256(u256BeBytes);
554
+ }
555
+ chunkPK6SKIKE_cjs.__name(bytesToBigintBECurve25519, "bytesToBigintBECurve25519");
556
+ function getCurve25519FieldElementSampler(deps) {
557
+ const { modAdd: moduleAdd = curve25519ModuloAdd, modMul: moduleMul = curve25519ModuloMul } = deps ?? {};
558
+ return (input) => {
559
+ const high = bytesToBigintBECurve25519(input, 0);
560
+ const low = bytesToBigintBECurve25519(input, 32);
561
+ const lowReduced = reduce256Curve25519(low);
562
+ const highReduced = reduce256Curve25519(high);
563
+ const highTimesR = moduleMul(highReduced, R_MOD_P_CURVE25519);
564
+ const result = moduleAdd(highTimesR, lowReduced);
565
+ return result;
566
+ };
567
+ }
568
+ chunkPK6SKIKE_cjs.__name(getCurve25519FieldElementSampler, "getCurve25519FieldElementSampler");
569
+ var curve25519FieldElementSampler = getCurve25519FieldElementSampler();
570
+
571
+ exports.BN254_FIELD_PRIME = BN254_FIELD_PRIME;
572
+ exports.CURVE25519_FIELD_PRIME = CURVE25519_FIELD_PRIME;
573
+ exports.assertBn254FieldElement = assertBn254FieldElement;
574
+ exports.bn254FieldElementSampler = bn254FieldElementSampler;
575
+ exports.computeBn254LimbwiseSumInverse = computeBn254LimbwiseSumInverse;
576
+ exports.curve25519FieldElementSampler = curve25519FieldElementSampler;
577
+ exports.curve25519ModuloAdd = curve25519ModuloAdd;
578
+ exports.curve25519ModuloInv = curve25519ModuloInv;
579
+ exports.curve25519ModuloMul = curve25519ModuloMul;
580
+ exports.curve25519ModuloPow = curve25519ModuloPow;
581
+ exports.curve25519ModuloSub = curve25519ModuloSub;
582
+ exports.getBn254FieldElementSampler = getBn254FieldElementSampler;
583
+ exports.getBn254ModularAdder = getBn254ModularAdder;
584
+ exports.getBn254ModularInverter = getBn254ModularInverter;
585
+ exports.getBn254ModularMultiplier = getBn254ModularMultiplier;
586
+ exports.getBn254ModularNegator = getBn254ModularNegator;
587
+ exports.getBn254ModularSubtractor = getBn254ModularSubtractor;
588
+ exports.getCurve25519FieldElementSampler = getCurve25519FieldElementSampler;
589
+ exports.getCurve25519ModularAddFunction = getCurve25519ModularAddFunction;
590
+ exports.getCurve25519ModularInvFunction = getCurve25519ModularInvFunction;
591
+ exports.getCurve25519ModularMulFunction = getCurve25519ModularMulFunction;
592
+ exports.getCurve25519ModularPowFunction = getCurve25519ModularPowFunction;
593
+ exports.getCurve25519ModularSubFunction = getCurve25519ModularSubFunction;
594
+ //# sourceMappingURL=chunk-Y55PYKXH.cjs.map
595
+ //# sourceMappingURL=chunk-Y55PYKXH.cjs.map