@ohos-ports/crypto 0.0.0-stage → 0.3.1-beta.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 (121) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +60 -2
  3. package/dist/bech32.d.ts +53 -0
  4. package/dist/bech32.js +187 -0
  5. package/dist/blake2b.d.ts +7 -0
  6. package/dist/blake2b.js +213 -0
  7. package/dist/bls12_318.d.ts +48 -0
  8. package/dist/bls12_318.js +268 -0
  9. package/dist/ed25519.d.ts +55 -0
  10. package/dist/ed25519.js +721 -0
  11. package/dist/hasGlobalWebCrypto.d.ts +1 -0
  12. package/dist/hasGlobalWebCrypto.js +21 -0
  13. package/dist/hmacSHA512.d.ts +6 -0
  14. package/dist/hmacSHA512.js +14 -0
  15. package/dist/index.d.ts +14 -0
  16. package/dist/index.js +30 -0
  17. package/dist/keccak.d.ts +4 -0
  18. package/dist/keccak.js +43 -0
  19. package/dist/kes/constants.d.ts +2 -0
  20. package/dist/kes/constants.js +5 -0
  21. package/dist/kes/index.d.ts +0 -0
  22. package/dist/kes/index.js +0 -0
  23. package/dist/kes/macro/sum_kes.d.ts +15 -0
  24. package/dist/kes/macro/sum_kes.js +9 -0
  25. package/dist/kes/singleKes.d.ts +0 -0
  26. package/dist/kes/singleKes.js +0 -0
  27. package/dist/noble/_assert.d.ts +23 -0
  28. package/dist/noble/_assert.js +55 -0
  29. package/dist/noble/_md.d.ts +29 -0
  30. package/dist/noble/_md.js +170 -0
  31. package/dist/noble/_shortw_utils.d.ts +61 -0
  32. package/dist/noble/_shortw_utils.js +63 -0
  33. package/dist/noble/_u64.d.ts +28 -0
  34. package/dist/noble/_u64.js +116 -0
  35. package/dist/noble/abstract/bls.d.ts +119 -0
  36. package/dist/noble/abstract/bls.js +334 -0
  37. package/dist/noble/abstract/curve.d.ts +83 -0
  38. package/dist/noble/abstract/curve.js +319 -0
  39. package/dist/noble/abstract/edwards.d.ts +85 -0
  40. package/dist/noble/abstract/edwards.js +508 -0
  41. package/dist/noble/abstract/hash-to-curve.d.ts +57 -0
  42. package/dist/noble/abstract/hash-to-curve.js +220 -0
  43. package/dist/noble/abstract/modular.d.ts +122 -0
  44. package/dist/noble/abstract/modular.js +455 -0
  45. package/dist/noble/abstract/montgomery.d.ts +28 -0
  46. package/dist/noble/abstract/montgomery.js +172 -0
  47. package/dist/noble/abstract/utils.d.ts +106 -0
  48. package/dist/noble/abstract/utils.js +442 -0
  49. package/dist/noble/bls12_381.d.ts +95 -0
  50. package/dist/noble/bls12_381.js +1434 -0
  51. package/dist/noble/crypto.d.ts +1 -0
  52. package/dist/noble/crypto.js +4 -0
  53. package/dist/noble/curves/curve.d.ts +69 -0
  54. package/dist/noble/curves/curve.js +167 -0
  55. package/dist/noble/curves/modular.d.ts +122 -0
  56. package/dist/noble/curves/modular.js +442 -0
  57. package/dist/noble/curves/utils.d.ts +93 -0
  58. package/dist/noble/curves/utils.js +385 -0
  59. package/dist/noble/curves/weierstrass.d.ts +240 -0
  60. package/dist/noble/curves/weierstrass.js +1178 -0
  61. package/dist/noble/ed25519.d.ts +100 -0
  62. package/dist/noble/ed25519.js +494 -0
  63. package/dist/noble/hmac.d.ts +25 -0
  64. package/dist/noble/hmac.js +101 -0
  65. package/dist/noble/index.d.ts +2 -0
  66. package/dist/noble/index.js +20 -0
  67. package/dist/noble/keccak.d.ts +58 -0
  68. package/dist/noble/keccak.js +289 -0
  69. package/dist/noble/ripemd_160.d.ts +20 -0
  70. package/dist/noble/ripemd_160.js +147 -0
  71. package/dist/noble/secp256k1.d.ts +98 -0
  72. package/dist/noble/secp256k1.js +309 -0
  73. package/dist/noble/sha256.d.ts +34 -0
  74. package/dist/noble/sha256.js +146 -0
  75. package/dist/noble/sha512.d.ts +66 -0
  76. package/dist/noble/sha512.js +301 -0
  77. package/dist/noble/utils.d.ts +90 -0
  78. package/dist/noble/utils.js +278 -0
  79. package/dist/ripemd_160.d.ts +1 -0
  80. package/dist/ripemd_160.js +23 -0
  81. package/dist/rust_vrf_reimpl/curves.d.ts +162 -0
  82. package/dist/rust_vrf_reimpl/curves.js +4225 -0
  83. package/dist/rust_vrf_reimpl/vrf03.d.ts +60 -0
  84. package/dist/rust_vrf_reimpl/vrf03.js +373 -0
  85. package/dist/rust_vrf_reimpl/vrf10.d.ts +73 -0
  86. package/dist/rust_vrf_reimpl/vrf10.js +468 -0
  87. package/dist/rust_vrf_reimpl/vrf10_batch.d.ts +53 -0
  88. package/dist/rust_vrf_reimpl/vrf10_batch.js +245 -0
  89. package/dist/secp256k1.d.ts +4 -0
  90. package/dist/secp256k1.js +33 -0
  91. package/dist/sha2_256.d.ts +16 -0
  92. package/dist/sha2_256.js +403 -0
  93. package/dist/sha2_512.d.ts +16 -0
  94. package/dist/sha2_512.js +256 -0
  95. package/dist/sha3.d.ts +17 -0
  96. package/dist/sha3.js +181 -0
  97. package/dist/types.d.ts +26 -0
  98. package/dist/types.js +120 -0
  99. package/dist/utils/assert.d.ts +3 -0
  100. package/dist/utils/assert.js +55 -0
  101. package/dist/utils/base32.d.ts +5 -0
  102. package/dist/utils/base32.js +52 -0
  103. package/dist/utils/bigintToBuffer.d.ts +1 -0
  104. package/dist/utils/bigintToBuffer.js +27 -0
  105. package/dist/utils/bytesToHex.d.ts +2 -0
  106. package/dist/utils/bytesToHex.js +15 -0
  107. package/dist/utils/getRandomValues.d.ts +4 -0
  108. package/dist/utils/getRandomValues.js +12 -0
  109. package/dist/utils/hexToBytes.d.ts +2 -0
  110. package/dist/utils/hexToBytes.js +14 -0
  111. package/dist/utils/index.d.ts +3 -0
  112. package/dist/utils/index.js +19 -0
  113. package/dist/utils/positiveMod.d.ts +1 -0
  114. package/dist/utils/positiveMod.js +11 -0
  115. package/dist/utils/promisifySync.d.ts +0 -0
  116. package/dist/utils/promisifySync.js +0 -0
  117. package/dist/utils/rotr32.d.ts +2 -0
  118. package/dist/utils/rotr32.js +7 -0
  119. package/dist/vrf.d.ts +74 -0
  120. package/dist/vrf.js +286 -0
  121. package/package.json +49 -4
@@ -0,0 +1,4225 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.negate_scalar = exports.pack_unpacked_scalar = exports.unpacked_scalar_from_bytes_wide = exports.unpack_scalar = exports.add_scalars = exports.mul_scalars = exports.scalar_from_bytes_mod_order_wide = exports.scalar_from_u64 = exports.ProjectivePoint = exports.CompletedPoint = exports.decompressCompressedEdwardsY = exports.LookupTableProjectiveNielsPoint = exports.ProjectiveNielsPoint = exports.ED25519_BASEPOINT_POINT = exports.EdwardsPoint = exports.MontgomeryPoint = exports.FieldElem51 = void 0;
20
+ var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
21
+ function load8(bytes, offset) {
22
+ var dataView = bytes instanceof DataView ? bytes : new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
23
+ return dataView.getBigUint64(offset, true);
24
+ }
25
+ var _0n = BigInt(0);
26
+ var _1n = BigInt(1);
27
+ var _51n = BigInt(51);
28
+ var _52n = BigInt(52);
29
+ var _64n = BigInt(64);
30
+ var LOW_51_BIT_MASK = (_1n << _51n) - _1n;
31
+ var LOW_52_BIT_MASK = (_1n << _52n) - _1n;
32
+ var LOW_64_BIT_MASK = (_1n << _64n) - _1n;
33
+ function innerConditionalAssign(self, other, choice) {
34
+ // if choice = 0, mask = (-0) = 0000...0000
35
+ // if choice = 1, mask = (-1) = 1111...1111
36
+ // return self ^ ( choice ? ( self ^ other ) : _0n );
37
+ // const mask = choice ? (_1n << _64n) - _1n : _0n;
38
+ // return self ^ ( mask & ( self ^ other ) );
39
+ return choice ? other : self;
40
+ }
41
+ var FieldElem51 = /** @class */ (function () {
42
+ function FieldElem51(bytes) {
43
+ this.bytes = bytes;
44
+ }
45
+ FieldElem51.zero = function () {
46
+ return new FieldElem51(new BigUint64Array([
47
+ _0n,
48
+ _0n,
49
+ _0n,
50
+ _0n,
51
+ _0n
52
+ ]));
53
+ };
54
+ FieldElem51.one = function () {
55
+ return new FieldElem51(new BigUint64Array([
56
+ _1n,
57
+ _0n,
58
+ _0n,
59
+ _0n,
60
+ _0n,
61
+ ]));
62
+ };
63
+ /*
64
+ /// Construct -1.
65
+ pub fn minus_one() -> FieldElem51 {
66
+ FieldElem51([2251799813685228, 2251799813685247, 2251799813685247, 2251799813685247, 2251799813685247])
67
+ }
68
+ */
69
+ FieldElem51.minus_one = function () {
70
+ return new FieldElem51(new BigUint64Array([
71
+ BigInt("2251799813685228"),
72
+ BigInt("2251799813685247"),
73
+ BigInt("2251799813685247"),
74
+ BigInt("2251799813685247"),
75
+ BigInt("2251799813685247"),
76
+ ]));
77
+ };
78
+ Object.defineProperty(FieldElem51, "EDWARDS_D", {
79
+ get: function () {
80
+ return new FieldElem51(new BigUint64Array([
81
+ BigInt("929955233495203"),
82
+ BigInt("466365720129213"),
83
+ BigInt("1662059464998953"),
84
+ BigInt("2033849074728123"),
85
+ BigInt("1442794654840575"),
86
+ ]));
87
+ },
88
+ enumerable: false,
89
+ configurable: true
90
+ });
91
+ Object.defineProperty(FieldElem51, "EDWARDS_D2", {
92
+ get: function () {
93
+ return new FieldElem51(new BigUint64Array([
94
+ BigInt("1859910466990425"),
95
+ BigInt("932731440258426"),
96
+ BigInt("1072319116312658"),
97
+ BigInt("1815898335770999"),
98
+ BigInt("633789495995903"),
99
+ ]));
100
+ },
101
+ enumerable: false,
102
+ configurable: true
103
+ });
104
+ FieldElem51.fromBytes = function (bytes) {
105
+ var dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
106
+ return new FieldElem51(new BigUint64Array([
107
+ load8(dataView, 0) & LOW_51_BIT_MASK,
108
+ (load8(dataView, 6) >> BigInt(3)) & LOW_51_BIT_MASK,
109
+ (load8(dataView, 12) >> BigInt(6)) & LOW_51_BIT_MASK,
110
+ (load8(dataView, 19) >> BigInt(1)) & LOW_51_BIT_MASK,
111
+ (load8(dataView, 24) >> BigInt(12)) & LOW_51_BIT_MASK,
112
+ ]));
113
+ };
114
+ /*
115
+ #[allow(unused)]
116
+ pub(crate) fn elligator_encode(r_0: &FieldElement) -> MontgomeryPoint {
117
+ let one = FieldElement::one();
118
+ let d_1 = &one + &r_0.square2(); / * 2r^2 * /
119
+
120
+ let d = &MONTGOMERY_A_NEG * &(d_1.invert()); // * A/(1+2r^2) * /
121
+
122
+ let d_sq = &d.square();
123
+ let au = &MONTGOMERY_A * &d;
124
+
125
+ let inner = &(d_sq + &au) + &one;
126
+ let eps = &d * &inner; // * eps = d^3 + Ad^2 + d * /
127
+
128
+ let (eps_is_sq, _eps) = FieldElement::sqrt_ratio_i(&eps, &one);
129
+
130
+ let zero = FieldElement::zero();
131
+ let Atemp = FieldElement::conditional_select(&MONTGOMERY_A, &zero, eps_is_sq); /* 0, or A if nonsquare* /
132
+ let mut u = &d + &Atemp; /* d, or d+A if nonsquare * /
133
+ u.conditional_negate(!eps_is_sq); /* d, or -d-A if nonsquare * /
134
+
135
+ MontgomeryPoint(u.to_bytes())
136
+ }
137
+ */
138
+ FieldElem51.elligator_encode = function (r_0) {
139
+ var one = FieldElem51.one();
140
+ var d_1 = one.add(r_0.square2());
141
+ // const d = d_1.invert().mul( FieldElem51.fromBytes( new Uint8Array( 32 ) ) );
142
+ var d = FieldElem51.MONTGOMERY_A_NEG.mul(d_1.invert());
143
+ var MONTGOMERY_A = FieldElem51.MONTGOMERY_A;
144
+ var d_sq = d.square();
145
+ var au = MONTGOMERY_A.mul(d);
146
+ var inner = d_sq.add(au).add(one);
147
+ var eps = d.mul(inner);
148
+ var _a = __read(FieldElem51.sqrt_ratio_i(eps, one), 2), eps_is_sq = _a[0], _eps = _a[1];
149
+ var zero = FieldElem51.zero();
150
+ // let Atemp = FieldElement::conditional_select(&MONTGOMERY_A, &zero, eps_is_sq); /* 0, or A if nonsquare*/
151
+ var Atemp = FieldElem51.conditional_select(MONTGOMERY_A, zero, eps_is_sq);
152
+ var u = d.add(Atemp);
153
+ u.conditional_negate(!eps_is_sq);
154
+ return new MontgomeryPoint(u.toBytes());
155
+ };
156
+ FieldElem51.elligator_encode_var_time = function (r_0) {
157
+ var one = FieldElem51.one();
158
+ var d_1 = one.add(r_0.square2());
159
+ // const d = d_1.invert().mul( FieldElem51.fromBytes( new Uint8Array( 32 ) ) );
160
+ var d = FieldElem51.MONTGOMERY_A_NEG.mul(d_1.invert());
161
+ var MONTGOMERY_A = FieldElem51.MONTGOMERY_A;
162
+ var d_sq = d.square();
163
+ var au = MONTGOMERY_A.mul(d);
164
+ var inner = d_sq.add(au).add(one);
165
+ var eps = d.mul(inner);
166
+ var _a = __read(FieldElem51.sqrt_ratio_i(eps, one), 2), eps_is_sq = _a[0], _eps = _a[1];
167
+ var zero = FieldElem51.zero();
168
+ // let Atemp = FieldElement::conditional_select(&MONTGOMERY_A, &zero, eps_is_sq); /* 0, or A if nonsquare*/
169
+ var Atemp = FieldElem51.conditional_select(MONTGOMERY_A, zero, eps_is_sq);
170
+ var u = d.add(Atemp);
171
+ u.conditional_negate(!eps_is_sq);
172
+ return new MontgomeryPoint(u.toBytes());
173
+ };
174
+ /*
175
+ fn conditional_select(
176
+ a: &FieldElement51,
177
+ b: &FieldElement51,
178
+ choice: Choice,
179
+ ) -> FieldElement51 {
180
+ FieldElement51([
181
+ u64::conditional_select(&a.0[0], &b.0[0], choice),
182
+ u64::conditional_select(&a.0[1], &b.0[1], choice),
183
+ u64::conditional_select(&a.0[2], &b.0[2], choice),
184
+ u64::conditional_select(&a.0[3], &b.0[3], choice),
185
+ u64::conditional_select(&a.0[4], &b.0[4], choice),
186
+ ])
187
+ }
188
+ // u64::conditional_select(&a.0[0], &b.0[0], choice),
189
+ #[inline]
190
+ fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
191
+ // if choice = 0, mask = (-0) = 0000...0000
192
+ // if choice = 1, mask = (-1) = 1111...1111
193
+ let mask = -(choice.unwrap_u8() as to_signed_int!($t)) as $t;
194
+ a ^ (mask & (a ^ b))
195
+ }
196
+ */
197
+ FieldElem51.conditional_select = function (a, b, choice) {
198
+ var mask = choice ? LOW_64_BIT_MASK : _0n;
199
+ var a_bytes = a.bytes;
200
+ var b_bytes = b.bytes;
201
+ return new FieldElem51(new BigUint64Array([
202
+ a_bytes[0] ^ (mask & (a_bytes[0] ^ b_bytes[0])),
203
+ a_bytes[1] ^ (mask & (a_bytes[1] ^ b_bytes[1])),
204
+ a_bytes[2] ^ (mask & (a_bytes[2] ^ b_bytes[2])),
205
+ a_bytes[3] ^ (mask & (a_bytes[3] ^ b_bytes[3])),
206
+ a_bytes[4] ^ (mask & (a_bytes[4] ^ b_bytes[4])),
207
+ ]));
208
+ };
209
+ Object.defineProperty(FieldElem51, "MONTGOMERY_A_NEG", {
210
+ get: function () {
211
+ return new FieldElem51(new BigUint64Array([
212
+ BigInt("2251799813198567"),
213
+ BigInt("2251799813685247"),
214
+ BigInt("2251799813685247"),
215
+ BigInt("2251799813685247"),
216
+ BigInt("2251799813685247"),
217
+ ]));
218
+ },
219
+ enumerable: false,
220
+ configurable: true
221
+ });
222
+ Object.defineProperty(FieldElem51, "MONTGOMERY_A", {
223
+ get: function () {
224
+ return new FieldElem51(new BigUint64Array([
225
+ BigInt("486662"),
226
+ _0n,
227
+ _0n,
228
+ _0n,
229
+ _0n,
230
+ ]));
231
+ },
232
+ enumerable: false,
233
+ configurable: true
234
+ });
235
+ FieldElem51.prototype.pow2k = function (k) {
236
+ /*
237
+ pub fn pow2k(&self, mut k: u32) -> FieldElem51 {
238
+
239
+ debug_assert!( k > 0 );
240
+
241
+ /// Multiply two 64-bit integers with 128 bits of output.
242
+ #[inline(always)]
243
+ fn m(x: u64, y: u64) -> u128 { (x as u128) * (y as u128) }
244
+
245
+ let mut a: [u64; 5] = self.0;
246
+
247
+ loop {
248
+ // Precondition: assume input limbs a[i] are bounded as
249
+ //
250
+ // a[i] < 2^(51 + b)
251
+ //
252
+ // where b is a real parameter measuring the "bit excess" of the limbs.
253
+
254
+ // Precomputation: 64-bit multiply by 19.
255
+ //
256
+ // This fits into a u64 whenever 51 + b + lg(19) < 64.
257
+ //
258
+ // Since 51 + b + lg(19) < 51 + 4.25 + b
259
+ // = 55.25 + b,
260
+ // this fits if b < 8.75.
261
+ let a3_19 = 19 * a[3];
262
+ let a4_19 = 19 * a[4];
263
+
264
+ // Multiply to get 128-bit coefficients of output.
265
+ //
266
+ // The 128-bit multiplications by 2 turn into 1 slr + 1 slrd each,
267
+ // which doesn't seem any better or worse than doing them as precomputations
268
+ // on the 64-bit inputs.
269
+ let c0: u128 = m(a[0], a[0]) + 2*( m(a[1], a4_19) + m(a[2], a3_19) );
270
+ let mut c1: u128 = m(a[3], a3_19) + 2*( m(a[0], a[1]) + m(a[2], a4_19) );
271
+ let mut c2: u128 = m(a[1], a[1]) + 2*( m(a[0], a[2]) + m(a[4], a3_19) );
272
+ let mut c3: u128 = m(a[4], a4_19) + 2*( m(a[0], a[3]) + m(a[1], a[2]) );
273
+ let mut c4: u128 = m(a[2], a[2]) + 2*( m(a[0], a[4]) + m(a[1], a[3]) );
274
+
275
+ // Same bound as in multiply:
276
+ // c[i] < 2^(102 + 2*b) * (1+i + (4-i)*19)
277
+ // < 2^(102 + lg(1 + 4*19) + 2*b)
278
+ // < 2^(108.27 + 2*b)
279
+ //
280
+ // The carry (c[i] >> 51) fits into a u64 when
281
+ // 108.27 + 2*b - 51 < 64
282
+ // 2*b < 6.73
283
+ // b < 3.365.
284
+ //
285
+ // So we require b < 3 to ensure this fits.
286
+ debug_assert!(a[0] < (1 << 54));
287
+ debug_assert!(a[1] < (1 << 54));
288
+ debug_assert!(a[2] < (1 << 54));
289
+ debug_assert!(a[3] < (1 << 54));
290
+ debug_assert!(a[4] < (1 << 54));
291
+
292
+ const LOW_51_BIT_MASK: u64 = (1u64 << 51) - 1;
293
+
294
+ // Casting to u64 and back tells the compiler that the carry is bounded by 2^64, so
295
+ // that the addition is a u128 + u64 rather than u128 + u128.
296
+ c1 += ((c0 >> 51) as u64) as u128;
297
+ a[0] = (c0 as u64) & LOW_51_BIT_MASK;
298
+
299
+ c2 += ((c1 >> 51) as u64) as u128;
300
+ a[1] = (c1 as u64) & LOW_51_BIT_MASK;
301
+
302
+ c3 += ((c2 >> 51) as u64) as u128;
303
+ a[2] = (c2 as u64) & LOW_51_BIT_MASK;
304
+
305
+ c4 += ((c3 >> 51) as u64) as u128;
306
+ a[3] = (c3 as u64) & LOW_51_BIT_MASK;
307
+
308
+ let carry: u64 = (c4 >> 51) as u64;
309
+ a[4] = (c4 as u64) & LOW_51_BIT_MASK;
310
+
311
+ // To see that this does not overflow, we need a[0] + carry * 19 < 2^64.
312
+ //
313
+ // c4 < a2^2 + 2*a0*a4 + 2*a1*a3 + (carry from c3)
314
+ // < 2^(102 + 2*b + lg(5)) + 2^64.
315
+ //
316
+ // When b < 3 we get
317
+ //
318
+ // c4 < 2^110.33 so that carry < 2^59.33
319
+ //
320
+ // so that
321
+ //
322
+ // a[0] + carry * 19 < 2^51 + 19 * 2^59.33 < 2^63.58
323
+ //
324
+ // and there is no overflow.
325
+ a[0] = a[0] + carry * 19;
326
+
327
+ // Now a[1] < 2^51 + 2^(64 -51) = 2^51 + 2^13 < 2^(51 + epsilon).
328
+ a[1] += a[0] >> 51;
329
+ a[0] &= LOW_51_BIT_MASK;
330
+
331
+ // Now all a[i] < 2^(51 + epsilon) and a = self^(2^k).
332
+
333
+ k = k - 1;
334
+ if k == 0 {
335
+ break;
336
+ }
337
+ }
338
+
339
+ FieldElem51(a)
340
+ }
341
+ */
342
+ k = Math.abs(k);
343
+ var a = this.bytes.slice();
344
+ while (true) {
345
+ var a3_19 = BigInt(19) * a[3];
346
+ var a4_19 = BigInt(19) * a[4];
347
+ var c0 = (a[0] * a[0]) + BigInt(2) * ((a[1] * a4_19) + (a[2] * a3_19));
348
+ var c1 = (a[3] * a3_19) + BigInt(2) * ((a[0] * a[1]) + (a[2] * a4_19));
349
+ var c2 = (a[1] * a[1]) + BigInt(2) * ((a[0] * a[2]) + (a[4] * a3_19));
350
+ var c3 = (a[4] * a4_19) + BigInt(2) * ((a[0] * a[3]) + (a[1] * a[2]));
351
+ var c4 = (a[2] * a[2]) + BigInt(2) * ((a[0] * a[4]) + (a[1] * a[3]));
352
+ c1 += (c0 >> _51n);
353
+ a[0] = c0 & LOW_51_BIT_MASK;
354
+ c2 += (c1 >> _51n);
355
+ a[1] = c1 & LOW_51_BIT_MASK;
356
+ c3 += (c2 >> _51n);
357
+ a[2] = c2 & LOW_51_BIT_MASK;
358
+ c4 += (c3 >> _51n);
359
+ a[3] = c3 & LOW_51_BIT_MASK;
360
+ var carry = (c4 >> _51n);
361
+ a[4] = c4 & LOW_51_BIT_MASK;
362
+ a[0] = a[0] + carry * BigInt(19);
363
+ a[1] += a[0] >> _51n;
364
+ a[0] &= LOW_51_BIT_MASK;
365
+ k = k - 1;
366
+ if (k === 0)
367
+ break;
368
+ }
369
+ return new FieldElem51(a);
370
+ };
371
+ FieldElem51.prototype.square2 = function () {
372
+ var square = this.pow2k(1);
373
+ // for i in 0..5 {
374
+ // square.0[i] *= 2;
375
+ // }
376
+ for (var i = 0; i < 5; i++) {
377
+ square.bytes[i] *= BigInt(2);
378
+ }
379
+ return square;
380
+ };
381
+ /*
382
+ fn add_assign(&mut self, _rhs: &'b FieldElem51) {
383
+ for i in 0..5 {
384
+ self.0[i] += _rhs.0[i];
385
+ }
386
+ }
387
+ add(self, _rhs: &'b FieldElem51) -> FieldElem51 {
388
+ let mut output = *self;
389
+ output += _rhs;
390
+ output
391
+ }
392
+ */
393
+ FieldElem51.prototype.add = function (_rhs) {
394
+ var output = this.bytes.slice();
395
+ for (var i = 0; i < 5; i++) {
396
+ output[i] += _rhs.bytes[i];
397
+ }
398
+ return new FieldElem51(output);
399
+ };
400
+ /*
401
+ /// Given 64-bit input limbs, reduce to enforce the bound 2^(51 + epsilon).
402
+ #[inline(always)]
403
+ fn reduce(mut limbs: [u64; 5]) -> FieldElem51 {
404
+ const LOW_51_BIT_MASK: u64 = (1u64 << 51) - 1;
405
+
406
+ // Since the input limbs are bounded by 2^64, the biggest
407
+ // carry-out is bounded by 2^13.
408
+ //
409
+ // The biggest carry-in is c4 * 19, resulting in
410
+ //
411
+ // 2^51 + 19*2^13 < 2^51.0000000001
412
+ //
413
+ // Because we don't need to canonicalize, only to reduce the
414
+ // limb sizes, it's OK to do a "weak reduction", where we
415
+ // compute the carry-outs in parallel.
416
+
417
+ let c0 = limbs[0] >> 51;
418
+ let c1 = limbs[1] >> 51;
419
+ let c2 = limbs[2] >> 51;
420
+ let c3 = limbs[3] >> 51;
421
+ let c4 = limbs[4] >> 51;
422
+
423
+ limbs[0] &= LOW_51_BIT_MASK;
424
+ limbs[1] &= LOW_51_BIT_MASK;
425
+ limbs[2] &= LOW_51_BIT_MASK;
426
+ limbs[3] &= LOW_51_BIT_MASK;
427
+ limbs[4] &= LOW_51_BIT_MASK;
428
+
429
+ limbs[0] += c4 * 19;
430
+ limbs[1] += c0;
431
+ limbs[2] += c1;
432
+ limbs[3] += c2;
433
+ limbs[4] += c3;
434
+
435
+ FieldElem51(limbs)
436
+ }
437
+ */
438
+ FieldElem51.reduce = function (limbs) {
439
+ var c0 = limbs[0] >> _51n;
440
+ var c1 = limbs[1] >> _51n;
441
+ var c2 = limbs[2] >> _51n;
442
+ var c3 = limbs[3] >> _51n;
443
+ var c4 = limbs[4] >> _51n;
444
+ limbs[0] &= LOW_51_BIT_MASK;
445
+ limbs[1] &= LOW_51_BIT_MASK;
446
+ limbs[2] &= LOW_51_BIT_MASK;
447
+ limbs[3] &= LOW_51_BIT_MASK;
448
+ limbs[4] &= LOW_51_BIT_MASK;
449
+ limbs[0] += c4 * BigInt(19);
450
+ limbs[1] += c0;
451
+ limbs[2] += c1;
452
+ limbs[3] += c2;
453
+ limbs[4] += c3;
454
+ return new FieldElem51(limbs);
455
+ };
456
+ /*
457
+ fn sub_assign(&mut self, _rhs: &'b FieldElem51) {
458
+ let result = (self as &FieldElem51) - _rhs;
459
+ self.0 = result.0;
460
+ }
461
+ type Output = FieldElem51;
462
+ fn sub(self, _rhs: &'b FieldElem51) -> FieldElem51 {
463
+ // To avoid underflow, first add a multiple of p.
464
+ // Choose 16*p = p << 4 to be larger than 54-bit _rhs.
465
+ //
466
+ // If we could statically track the bitlengths of the limbs
467
+ // of every FieldElem51, we could choose a multiple of p
468
+ // just bigger than _rhs and avoid having to do a reduction.
469
+ //
470
+ // Since we don't yet have type-level integers to do this, we
471
+ // have to add an explicit reduction call here.
472
+ FieldElem51::reduce([
473
+ (self.0[0] + 36028797018963664u64) - _rhs.0[0],
474
+ (self.0[1] + 36028797018963952u64) - _rhs.0[1],
475
+ (self.0[2] + 36028797018963952u64) - _rhs.0[2],
476
+ (self.0[3] + 36028797018963952u64) - _rhs.0[3],
477
+ (self.0[4] + 36028797018963952u64) - _rhs.0[4],
478
+ ])
479
+ }
480
+ */
481
+ FieldElem51.prototype.sub = function (_rhs) {
482
+ return FieldElem51.reduce(new BigUint64Array([
483
+ (this.bytes[0] + BigInt("36028797018963664")) - _rhs.bytes[0],
484
+ (this.bytes[1] + BigInt("36028797018963952")) - _rhs.bytes[1],
485
+ (this.bytes[2] + BigInt("36028797018963952")) - _rhs.bytes[2],
486
+ (this.bytes[3] + BigInt("36028797018963952")) - _rhs.bytes[3],
487
+ (this.bytes[4] + BigInt("36028797018963952")) - _rhs.bytes[4],
488
+ ]));
489
+ };
490
+ /*
491
+ fn mul_assign(&mut self, _rhs: &'b FieldElem51) {
492
+ let result = (self as &FieldElem51) * _rhs;
493
+ self.0 = result.0;
494
+ }
495
+ type Output = FieldElem51;
496
+ fn mul(self, _rhs: &'b FieldElem51) -> FieldElem51 {
497
+ /// Helper function to multiply two 64-bit integers with 128
498
+ /// bits of output.
499
+ #[inline(always)]
500
+ fn m(x: u64, y: u64) -> u128 { (x as u128) * (y as u128) }
501
+
502
+ // Alias self, _rhs for more readable formulas
503
+ let a: &[u64; 5] = &self.0;
504
+ let b: &[u64; 5] = &_rhs.0;
505
+
506
+ // Precondition: assume input limbs a[i], b[i] are bounded as
507
+ //
508
+ // a[i], b[i] < 2^(51 + b)
509
+ //
510
+ // where b is a real parameter measuring the "bit excess" of the limbs.
511
+
512
+ // 64-bit precomputations to avoid 128-bit multiplications.
513
+ //
514
+ // This fits into a u64 whenever 51 + b + lg(19) < 64.
515
+ //
516
+ // Since 51 + b + lg(19) < 51 + 4.25 + b
517
+ // = 55.25 + b,
518
+ // this fits if b < 8.75.
519
+ let b1_19 = b[1] * 19;
520
+ let b2_19 = b[2] * 19;
521
+ let b3_19 = b[3] * 19;
522
+ let b4_19 = b[4] * 19;
523
+
524
+ // Multiply to get 128-bit coefficients of output
525
+ let c0: u128 = m(a[0],b[0]) + m(a[4],b1_19) + m(a[3],b2_19) + m(a[2],b3_19) + m(a[1],b4_19);
526
+ let mut c1: u128 = m(a[1],b[0]) + m(a[0],b[1]) + m(a[4],b2_19) + m(a[3],b3_19) + m(a[2],b4_19);
527
+ let mut c2: u128 = m(a[2],b[0]) + m(a[1],b[1]) + m(a[0],b[2]) + m(a[4],b3_19) + m(a[3],b4_19);
528
+ let mut c3: u128 = m(a[3],b[0]) + m(a[2],b[1]) + m(a[1],b[2]) + m(a[0],b[3]) + m(a[4],b4_19);
529
+ let mut c4: u128 = m(a[4],b[0]) + m(a[3],b[1]) + m(a[2],b[2]) + m(a[1],b[3]) + m(a[0],b[4]);
530
+
531
+ // How big are the c[i]? We have
532
+ //
533
+ // c[i] < 2^(102 + 2*b) * (1+i + (4-i)*19)
534
+ // < 2^(102 + lg(1 + 4*19) + 2*b)
535
+ // < 2^(108.27 + 2*b)
536
+ //
537
+ // The carry (c[i] >> 51) fits into a u64 when
538
+ // 108.27 + 2*b - 51 < 64
539
+ // 2*b < 6.73
540
+ // b < 3.365.
541
+ //
542
+ // So we require b < 3 to ensure this fits.
543
+ debug_assert!(a[0] < (1 << 54)); debug_assert!(b[0] < (1 << 54));
544
+ debug_assert!(a[1] < (1 << 54)); debug_assert!(b[1] < (1 << 54));
545
+ debug_assert!(a[2] < (1 << 54)); debug_assert!(b[2] < (1 << 54));
546
+ debug_assert!(a[3] < (1 << 54)); debug_assert!(b[3] < (1 << 54));
547
+ debug_assert!(a[4] < (1 << 54)); debug_assert!(b[4] < (1 << 54));
548
+
549
+ // Casting to u64 and back tells the compiler that the carry is
550
+ // bounded by 2^64, so that the addition is a u128 + u64 rather
551
+ // than u128 + u128.
552
+
553
+ const LOW_51_BIT_MASK: u64 = (1u64 << 51) - 1;
554
+ let mut out = [0u64; 5];
555
+
556
+ c1 += ((c0 >> 51) as u64) as u128;
557
+ out[0] = (c0 as u64) & LOW_51_BIT_MASK;
558
+
559
+ c2 += ((c1 >> 51) as u64) as u128;
560
+ out[1] = (c1 as u64) & LOW_51_BIT_MASK;
561
+
562
+ c3 += ((c2 >> 51) as u64) as u128;
563
+ out[2] = (c2 as u64) & LOW_51_BIT_MASK;
564
+
565
+ c4 += ((c3 >> 51) as u64) as u128;
566
+ out[3] = (c3 as u64) & LOW_51_BIT_MASK;
567
+
568
+ let carry: u64 = (c4 >> 51) as u64;
569
+ out[4] = (c4 as u64) & LOW_51_BIT_MASK;
570
+
571
+ // To see that this does not overflow, we need out[0] + carry * 19 < 2^64.
572
+ //
573
+ // c4 < a0*b4 + a1*b3 + a2*b2 + a3*b1 + a4*b0 + (carry from c3)
574
+ // < 5*(2^(51 + b) * 2^(51 + b)) + (carry from c3)
575
+ // < 2^(102 + 2*b + lg(5)) + 2^64.
576
+ //
577
+ // When b < 3 we get
578
+ //
579
+ // c4 < 2^110.33 so that carry < 2^59.33
580
+ //
581
+ // so that
582
+ //
583
+ // out[0] + carry * 19 < 2^51 + 19 * 2^59.33 < 2^63.58
584
+ //
585
+ // and there is no overflow.
586
+ out[0] = out[0] + carry * 19;
587
+
588
+ // Now out[1] < 2^51 + 2^(64 -51) = 2^51 + 2^13 < 2^(51 + epsilon).
589
+ out[1] += out[0] >> 51;
590
+ out[0] &= LOW_51_BIT_MASK;
591
+
592
+ // Now out[i] < 2^(51 + epsilon) for all i.
593
+ FieldElem51(out)
594
+ }
595
+ */
596
+ FieldElem51.prototype.mul = function (_rhs) {
597
+ var a = this.bytes.slice();
598
+ var b = _rhs.bytes.slice();
599
+ var b1_19 = b[1] * BigInt(19);
600
+ var b2_19 = b[2] * BigInt(19);
601
+ var b3_19 = b[3] * BigInt(19);
602
+ var b4_19 = b[4] * BigInt(19);
603
+ var c0 = (a[0] * b[0]) + (a[4] * b1_19) + (a[3] * b2_19) + (a[2] * b3_19) + (a[1] * b4_19);
604
+ var c1 = (a[1] * b[0]) + (a[0] * b[1]) + (a[4] * b2_19) + (a[3] * b3_19) + (a[2] * b4_19);
605
+ var c2 = (a[2] * b[0]) + (a[1] * b[1]) + (a[0] * b[2]) + (a[4] * b3_19) + (a[3] * b4_19);
606
+ var c3 = (a[3] * b[0]) + (a[2] * b[1]) + (a[1] * b[2]) + (a[0] * b[3]) + (a[4] * b4_19);
607
+ var c4 = (a[4] * b[0]) + (a[3] * b[1]) + (a[2] * b[2]) + (a[1] * b[3]) + (a[0] * b[4]);
608
+ var out = new BigUint64Array(5);
609
+ c1 += (c0 >> _51n);
610
+ out[0] = c0 & LOW_51_BIT_MASK;
611
+ c2 += (c1 >> _51n);
612
+ out[1] = c1 & LOW_51_BIT_MASK;
613
+ c3 += (c2 >> _51n);
614
+ out[2] = c2 & LOW_51_BIT_MASK;
615
+ c4 += (c3 >> _51n);
616
+ out[3] = c3 & LOW_51_BIT_MASK;
617
+ var carry = (c4 >> _51n);
618
+ out[4] = c4 & LOW_51_BIT_MASK;
619
+ out[0] = out[0] + carry * BigInt(19);
620
+ out[1] += out[0] >> _51n;
621
+ out[0] &= LOW_51_BIT_MASK;
622
+ return new FieldElem51(out);
623
+ };
624
+ /*
625
+ pub fn invert(&self) -> FieldElement {
626
+ // The bits of p-2 = 2^255 -19 -2 are 11010111111...11.
627
+ //
628
+ // nonzero bits of exponent
629
+ let (t19, t3) = self.pow22501(); // t19: 249..0 ; t3: 3,1,0
630
+ let t20 = t19.pow2k(5); // 254..5
631
+ let t21 = &t20 * &t3; // 254..5,3,1,0
632
+
633
+ t21
634
+ }
635
+ */
636
+ FieldElem51.prototype.invert = function () {
637
+ var _a = __read(this.pow22501(), 2), t19 = _a[0], t3 = _a[1];
638
+ var t20 = t19.pow2k(5);
639
+ var t21 = t20.mul(t3);
640
+ return t21;
641
+ };
642
+ /*
643
+ /// Compute (self^(2^250-1), self^11), used as a helper function
644
+ /// within invert() and pow22523().
645
+ fn pow22501(&self) -> (FieldElement, FieldElement) {
646
+ // Instead of managing which temporary variables are used
647
+ // for what, we define as many as we need and leave stack
648
+ // allocation to the compiler
649
+ //
650
+ // Each temporary variable t_i is of the form (self)^e_i.
651
+ // Squaring t_i corresponds to multiplying e_i by 2,
652
+ // so the pow2k function shifts e_i left by k places.
653
+ // Multiplying t_i and t_j corresponds to adding e_i + e_j.
654
+ //
655
+ // Temporary t_i Nonzero bits of e_i
656
+ //
657
+ let t0 = self.square(); // 1 e_0 = 2^1
658
+ let t1 = t0.square().square(); // 3 e_1 = 2^3
659
+ let t2 = self * &t1; // 3,0 e_2 = 2^3 + 2^0
660
+ let t3 = &t0 * &t2; // 3,1,0
661
+ let t4 = t3.square(); // 4,2,1
662
+ let t5 = &t2 * &t4; // 4,3,2,1,0
663
+ let t6 = t5.pow2k(5); // 9,8,7,6,5
664
+ let t7 = &t6 * &t5; // 9,8,7,6,5,4,3,2,1,0
665
+ let t8 = t7.pow2k(10); // 19..10
666
+ let t9 = &t8 * &t7; // 19..0
667
+ let t10 = t9.pow2k(20); // 39..20
668
+ let t11 = &t10 * &t9; // 39..0
669
+ let t12 = t11.pow2k(10); // 49..10
670
+ let t13 = &t12 * &t7; // 49..0
671
+ let t14 = t13.pow2k(50); // 99..50
672
+ let t15 = &t14 * &t13; // 99..0
673
+ let t16 = t15.pow2k(100); // 199..100
674
+ let t17 = &t16 * &t15; // 199..0
675
+ let t18 = t17.pow2k(50); // 249..50
676
+ let t19 = &t18 * &t13; // 249..0
677
+
678
+ (t19, t3)
679
+ }
680
+ */
681
+ FieldElem51.prototype.pow22501 = function () {
682
+ var t0 = this.square();
683
+ var t1 = t0.square().square();
684
+ var t2 = this.mul(t1);
685
+ var t3 = t0.mul(t2);
686
+ var t4 = t3.square();
687
+ var t5 = t2.mul(t4);
688
+ var t6 = t5.pow2k(5);
689
+ var t7 = t6.mul(t5);
690
+ var t8 = t7.pow2k(10);
691
+ var t9 = t8.mul(t7);
692
+ var t10 = t9.pow2k(20);
693
+ var t11 = t10.mul(t9);
694
+ var t12 = t11.pow2k(10);
695
+ var t13 = t12.mul(t7);
696
+ var t14 = t13.pow2k(50);
697
+ var t15 = t14.mul(t13);
698
+ var t16 = t15.pow2k(100);
699
+ var t17 = t16.mul(t15);
700
+ var t18 = t17.pow2k(50);
701
+ var t19 = t18.mul(t13);
702
+ return [t19, t3];
703
+ };
704
+ /*
705
+ pub fn square(&self) -> FieldElem51 {
706
+ self.pow2k(1)
707
+ }
708
+ */
709
+ FieldElem51.prototype.square = function () {
710
+ return this.pow2k(1);
711
+ };
712
+ /*
713
+ /// Given `FieldElements` `u` and `v`, compute either `sqrt(u/v)`
714
+ /// or `sqrt(i*u/v)` in constant time.
715
+ ///
716
+ /// This function always returns the nonnegative square root.
717
+ ///
718
+ /// # Return
719
+ ///
720
+ /// - `(Choice(1), +sqrt(u/v)) ` if `v` is nonzero and `u/v` is square;
721
+ /// - `(Choice(1), zero) ` if `u` is zero;
722
+ /// - `(Choice(0), zero) ` if `v` is zero and `u` is nonzero;
723
+ /// - `(Choice(0), +sqrt(i*u/v))` if `u/v` is nonsquare (so `i*u/v` is square).
724
+ ///
725
+ pub fn sqrt_ratio_i(u: &FieldElement, v: &FieldElement) -> (Choice, FieldElement) {
726
+ // Using the same trick as in ed25519 decoding, we merge the
727
+ // inversion, the square root, and the square test as follows.
728
+ //
729
+ // To compute sqrt(α), we can compute β = α^((p+3)/8).
730
+ // Then β^2 = ±α, so multiplying β by sqrt(-1) if necessary
731
+ // gives sqrt(α).
732
+ //
733
+ // To compute 1/sqrt(α), we observe that
734
+ // 1/β = α^(p-1 - (p+3)/8) = α^((7p-11)/8)
735
+ // = α^3 * (α^7)^((p-5)/8).
736
+ //
737
+ // We can therefore compute sqrt(u/v) = sqrt(u)/sqrt(v)
738
+ // by first computing
739
+ // r = u^((p+3)/8) v^(p-1-(p+3)/8)
740
+ // = u u^((p-5)/8) v^3 (v^7)^((p-5)/8)
741
+ // = (uv^3) (uv^7)^((p-5)/8).
742
+ //
743
+ // If v is nonzero and u/v is square, then r^2 = ±u/v,
744
+ // so vr^2 = ±u.
745
+ // If vr^2 = u, then sqrt(u/v) = r.
746
+ // If vr^2 = -u, then sqrt(u/v) = r*sqrt(-1).
747
+ //
748
+ // If v is zero, r is also zero.
749
+
750
+ let v3 = &v.square() * v;
751
+ let v7 = &v3.square() * v;
752
+ let mut r = &(u * &v3) * &(u * &v7).pow_p58();
753
+ let check = v * &r.square();
754
+
755
+ let i = &constants::SQRT_M1;
756
+
757
+ let correct_sign_sqrt = check.ct_eq( u);
758
+ let flipped_sign_sqrt = check.ct_eq( &(-u));
759
+ let flipped_sign_sqrt_i = check.ct_eq(&(&(-u)*i));
760
+
761
+ let r_prime = &constants::SQRT_M1 * &r;
762
+ r.conditional_assign(&r_prime, flipped_sign_sqrt | flipped_sign_sqrt_i);
763
+
764
+ // Choose the nonnegative square root.
765
+ let r_is_negative = r.is_negative();
766
+ r.conditional_negate(r_is_negative);
767
+
768
+ let was_nonzero_square = correct_sign_sqrt | flipped_sign_sqrt;
769
+
770
+ (was_nonzero_square, r)
771
+ }
772
+ */
773
+ FieldElem51.sqrt_ratio_i = function (u, v) {
774
+ var v3 = v.square().mul(v);
775
+ var v7 = v3.square().mul(v);
776
+ var r = u.mul(v3).mul(u.mul(v7).pow_p58());
777
+ var check = v.mul(r.square());
778
+ var i = FieldElem51.SQRT_M1;
779
+ var correct_sign_sqrt = check.ct_eq(u);
780
+ var flipped_sign_sqrt = check.ct_eq(u.neg());
781
+ var flipped_sign_sqrt_i = check.ct_eq(u.neg().mul(i));
782
+ var r_prime = i.mul(r);
783
+ r.conditional_assign(r_prime, flipped_sign_sqrt || flipped_sign_sqrt_i);
784
+ // let r_is_negative = r.is_negative();
785
+ r.conditional_negate(r.is_negative());
786
+ var was_nonzero_square = correct_sign_sqrt || flipped_sign_sqrt;
787
+ // `flipped_sign_sqrt_i` WAS NOT HERE IN THE ORIGINAL CODE
788
+ // but otherwise I get the "Montgomery conversion to Edwards point in Elligator failed" error
789
+ // || flipped_sign_sqrt_i;
790
+ return [was_nonzero_square, r];
791
+ };
792
+ /*
793
+ pub fn is_negative(&self) -> Choice {
794
+ let bytes = self.to_bytes();
795
+ (bytes[0] & 1).into()
796
+ }
797
+ */
798
+ FieldElem51.prototype.is_negative = function () {
799
+ return (this.toBytes()[0] & 1) === 1;
800
+ };
801
+ /*
802
+ fn conditional_negate(&mut self, choice: Choice) {
803
+ // Need to cast to eliminate mutability
804
+ let self_neg: T = -(self as &T);
805
+ self.conditional_assign(&self_neg, choice);
806
+ }
807
+ */
808
+ FieldElem51.prototype.conditional_negate = function (choice) {
809
+ var self_neg = this.neg();
810
+ return this.conditional_assign(self_neg, choice);
811
+ // the above should have been the proper implementation
812
+ // however it was NOT negating for some reason
813
+ // this implementation should be equivalent to the intended implementation
814
+ // with the exception that it is not constant
815
+ // const self_neg = this.neg();
816
+ // if( choice ) (this as any).bytes = self_neg.bytes;
817
+ };
818
+ /*
819
+ // `Choice` is just a `boolean` in a `u8`
820
+ fn conditional_assign(&mut self, other: &FieldElem51, choice: Choice) {
821
+ inner_conditional_assign( self.0[0], (&other.0[0], choice));
822
+ inner_conditional_assign( self.0[1], (&other.0[1], choice));
823
+ inner_conditional_assign( self.0[2], (&other.0[2], choice));
824
+ inner_conditional_assign( self.0[3], (&other.0[3], choice));
825
+ inner_conditional_assign( self.0[4], (&other.0[4], choice));
826
+ }
827
+ #[inline]
828
+ fn inner_conditional_assign(&mut self, other: &Self, choice: Choice) {
829
+ // if choice = 0, mask = (-0) = 0000...0000
830
+ // if choice = 1, mask = (-1) = 1111...1111
831
+ let mask = -(choice.unwrap_u8() as to_signed_int!($t)) as $t;
832
+ *self ^= mask & (*self ^ *other);
833
+ }
834
+ */
835
+ FieldElem51.prototype.conditional_assign = function (other, choice) {
836
+ this.bytes[0] = innerConditionalAssign(this.bytes[0], other.bytes[0], choice);
837
+ this.bytes[1] = innerConditionalAssign(this.bytes[1], other.bytes[1], choice);
838
+ this.bytes[2] = innerConditionalAssign(this.bytes[2], other.bytes[2], choice);
839
+ this.bytes[3] = innerConditionalAssign(this.bytes[3], other.bytes[3], choice);
840
+ this.bytes[4] = innerConditionalAssign(this.bytes[4], other.bytes[4], choice);
841
+ // the above was giving problems
842
+ // I'm not sure this is constant time
843
+ // but it should at least be close to it
844
+ // if( choice ) (this as any).bytes = other.bytes.slice();
845
+ // else (this as any).bytes = this.bytes.slice();
846
+ // return this;
847
+ };
848
+ FieldElem51.prototype.clone = function () {
849
+ return new FieldElem51(this.bytes.slice());
850
+ };
851
+ /*
852
+ fn neg(self) -> FieldElem51 {
853
+ let mut output = *self;
854
+ output.negate();
855
+ output
856
+ }
857
+ */
858
+ FieldElem51.prototype.neg = function () {
859
+ var output = this.clone();
860
+ return output.negate();
861
+ };
862
+ /*
863
+ pub fn negate(&mut self) {
864
+ // See commentary in the Sub impl
865
+ let neg = FieldElem51::reduce([
866
+ 36028797018963664u64 - self.0[0],
867
+ 36028797018963952u64 - self.0[1],
868
+ 36028797018963952u64 - self.0[2],
869
+ 36028797018963952u64 - self.0[3],
870
+ 36028797018963952u64 - self.0[4],
871
+ ]);
872
+ self.0 = neg.0;
873
+ }
874
+ */
875
+ FieldElem51.prototype.negate = function () {
876
+ return FieldElem51.reduce(new BigUint64Array([
877
+ BigInt("36028797018963664") - this.bytes[0],
878
+ BigInt("36028797018963952") - this.bytes[1],
879
+ BigInt("36028797018963952") - this.bytes[2],
880
+ BigInt("36028797018963952") - this.bytes[3],
881
+ BigInt("36028797018963952") - this.bytes[4],
882
+ ]));
883
+ };
884
+ /*
885
+ /// Test equality between two `FieldElement`s. Since the
886
+ /// internal representation is not canonical, the field elements
887
+ /// are normalized to wire format before comparison.
888
+ fn ct_eq(&self, other: &FieldElement) -> Choice {
889
+ self.to_bytes().ct_eq(&other.to_bytes())
890
+ }
891
+ */
892
+ FieldElem51.prototype.ct_eq = function (other) {
893
+ return (0, uint8array_utils_1.uint8ArrayEq)(this.toBytes(), other.toBytes());
894
+ };
895
+ Object.defineProperty(FieldElem51, "SQRT_M1", {
896
+ get: function () {
897
+ return new FieldElem51(new BigUint64Array([
898
+ BigInt("1718705420411056"),
899
+ BigInt("234908883556509"),
900
+ BigInt("2233514472574048"),
901
+ BigInt("2117202627021982"),
902
+ BigInt("765476049583133"),
903
+ ]));
904
+ },
905
+ enumerable: false,
906
+ configurable: true
907
+ });
908
+ /*
909
+ /// Raise this field element to the power (p-5)/8 = 2^252 -3.
910
+ fn pow_p58(&self) -> FieldElement {
911
+ // The bits of (p-5)/8 are 101111.....11.
912
+ //
913
+ // nonzero bits of exponent
914
+ let (t19, _) = self.pow22501(); // 249..0
915
+ let t20 = t19.pow2k(2); // 251..2
916
+ let t21 = self * &t20; // 251..2,0
917
+
918
+ t21
919
+ }
920
+ */
921
+ FieldElem51.prototype.pow_p58 = function () {
922
+ var _a = __read(this.pow22501(), 2), t19 = _a[0], _ = _a[1];
923
+ var t20 = t19.pow2k(2);
924
+ var t21 = this.mul(t20);
925
+ return t21;
926
+ };
927
+ /*
928
+ // Serialize this `FieldElem51` to a 32-byte array. The
929
+ /// encoding is canonical.
930
+ pub fn to_bytes(&self) -> [u8; 32] {
931
+ // Let h = limbs[0] + limbs[1]*2^51 + ... + limbs[4]*2^204.
932
+ //
933
+ // Write h = pq + r with 0 <= r < p.
934
+ //
935
+ // We want to compute r = h mod p.
936
+ //
937
+ // If h < 2*p = 2^256 - 38,
938
+ // then q = 0 or 1,
939
+ //
940
+ // with q = 0 when h < p
941
+ // and q = 1 when h >= p.
942
+ //
943
+ // Notice that h >= p <==> h + 19 >= p + 19 <==> h + 19 >= 2^255.
944
+ // Therefore q can be computed as the carry bit of h + 19.
945
+
946
+ // First, reduce the limbs to ensure h < 2*p.
947
+ let mut limbs = FieldElem51::reduce(self.0).0;
948
+
949
+ let mut q = (limbs[0] + 19) >> 51;
950
+ q = (limbs[1] + q) >> 51;
951
+ q = (limbs[2] + q) >> 51;
952
+ q = (limbs[3] + q) >> 51;
953
+ q = (limbs[4] + q) >> 51;
954
+
955
+ // Now we can compute r as r = h - pq = r - (2^255-19)q = r + 19q - 2^255q
956
+
957
+ limbs[0] += 19*q;
958
+
959
+ // Now carry the result to compute r + 19q ...
960
+ let low_51_bit_mask = (1u64 << 51) - 1;
961
+ limbs[1] += limbs[0] >> 51;
962
+ limbs[0] = limbs[0] & low_51_bit_mask;
963
+ limbs[2] += limbs[1] >> 51;
964
+ limbs[1] = limbs[1] & low_51_bit_mask;
965
+ limbs[3] += limbs[2] >> 51;
966
+ limbs[2] = limbs[2] & low_51_bit_mask;
967
+ limbs[4] += limbs[3] >> 51;
968
+ limbs[3] = limbs[3] & low_51_bit_mask;
969
+ // ... but instead of carrying (limbs[4] >> 51) = 2^255q
970
+ // into another limb, discard it, subtracting the value
971
+ limbs[4] = limbs[4] & low_51_bit_mask;
972
+
973
+ // Now arrange the bits of the limbs.
974
+ let mut s = [0u8;32];
975
+ s[ 0] = limbs[0] as u8;
976
+ s[ 1] = (limbs[0] >> 8) as u8;
977
+ s[ 2] = (limbs[0] >> 16) as u8;
978
+ s[ 3] = (limbs[0] >> 24) as u8;
979
+ s[ 4] = (limbs[0] >> 32) as u8;
980
+ s[ 5] = (limbs[0] >> 40) as u8;
981
+ s[ 6] = ((limbs[0] >> 48) | (limbs[1] << 3)) as u8;
982
+ s[ 7] = (limbs[1] >> 5) as u8;
983
+ s[ 8] = (limbs[1] >> 13) as u8;
984
+ s[ 9] = (limbs[1] >> 21) as u8;
985
+ s[10] = (limbs[1] >> 29) as u8;
986
+ s[11] = (limbs[1] >> 37) as u8;
987
+ s[12] = ((limbs[1] >> 45) | (limbs[2] << 6)) as u8;
988
+ s[13] = (limbs[2] >> 2) as u8;
989
+ s[14] = (limbs[2] >> 10) as u8;
990
+ s[15] = (limbs[2] >> 18) as u8;
991
+ s[16] = (limbs[2] >> 26) as u8;
992
+ s[17] = (limbs[2] >> 34) as u8;
993
+ s[18] = (limbs[2] >> 42) as u8;
994
+ s[19] = ((limbs[2] >> 50) | (limbs[3] << 1)) as u8;
995
+ s[20] = (limbs[3] >> 7) as u8;
996
+ s[21] = (limbs[3] >> 15) as u8;
997
+ s[22] = (limbs[3] >> 23) as u8;
998
+ s[23] = (limbs[3] >> 31) as u8;
999
+ s[24] = (limbs[3] >> 39) as u8;
1000
+ s[25] = ((limbs[3] >> 47) | (limbs[4] << 4)) as u8;
1001
+ s[26] = (limbs[4] >> 4) as u8;
1002
+ s[27] = (limbs[4] >> 12) as u8;
1003
+ s[28] = (limbs[4] >> 20) as u8;
1004
+ s[29] = (limbs[4] >> 28) as u8;
1005
+ s[30] = (limbs[4] >> 36) as u8;
1006
+ s[31] = (limbs[4] >> 44) as u8;
1007
+
1008
+ // High bit should be zero.
1009
+ debug_assert!((s[31] & 0b1000_0000u8) == 0u8);
1010
+
1011
+ s
1012
+ }
1013
+ */
1014
+ FieldElem51.prototype.toBytes = function () {
1015
+ var limbs = FieldElem51.reduce(this.bytes).bytes.slice();
1016
+ var q = (limbs[0] + BigInt(19)) >> _51n;
1017
+ q = (limbs[1] + q) >> _51n;
1018
+ q = (limbs[2] + q) >> _51n;
1019
+ q = (limbs[3] + q) >> _51n;
1020
+ q = (limbs[4] + q) >> _51n;
1021
+ limbs[0] += BigInt(19) * q;
1022
+ limbs[1] += limbs[0] >> _51n;
1023
+ limbs[0] &= LOW_51_BIT_MASK;
1024
+ limbs[2] += limbs[1] >> _51n;
1025
+ limbs[1] &= LOW_51_BIT_MASK;
1026
+ limbs[3] += limbs[2] >> _51n;
1027
+ limbs[2] &= LOW_51_BIT_MASK;
1028
+ limbs[4] += limbs[3] >> _51n;
1029
+ limbs[3] &= LOW_51_BIT_MASK;
1030
+ limbs[4] &= LOW_51_BIT_MASK;
1031
+ var s = new Uint8Array(32);
1032
+ // DO NOT TRY TO DO SMART THINGS
1033
+ //
1034
+ // DO NOT USE `DataView` OR OTHER BULLSHIT
1035
+ //
1036
+ // THIS IS THE CODE AND THIS WE KEEP
1037
+ // IT MIGHT SEEM IT IS JUST SHIFITNG THE BITS TO ALLIGN TO THE BYTES
1038
+ // !!! BUT IT IS NOT !!!
1039
+ // SOME ELEMENTS ARE SHIFTED BY STRANGE NUMBERS
1040
+ s[0] = Number(limbs[0] & BigInt(0xff));
1041
+ s[1] = Number((limbs[0] >> BigInt(8)) & BigInt(0xff));
1042
+ s[2] = Number((limbs[0] >> BigInt(16)) & BigInt(0xff));
1043
+ s[3] = Number((limbs[0] >> BigInt(24)) & BigInt(0xff));
1044
+ s[4] = Number((limbs[0] >> BigInt(32)) & BigInt(0xff));
1045
+ s[5] = Number((limbs[0] >> BigInt(40)) & BigInt(0xff));
1046
+ s[6] = Number((limbs[0] >> BigInt(48)) | (limbs[1] << BigInt(3)) & BigInt(0xff));
1047
+ s[7] = Number((limbs[1] >> BigInt(5)) & BigInt(0xff));
1048
+ s[8] = Number((limbs[1] >> BigInt(13)) & BigInt(0xff));
1049
+ s[9] = Number((limbs[1] >> BigInt(21)) & BigInt(0xff));
1050
+ s[10] = Number((limbs[1] >> BigInt(29)) & BigInt(0xff));
1051
+ s[11] = Number((limbs[1] >> BigInt(37)) & BigInt(0xff));
1052
+ s[12] = Number((limbs[1] >> BigInt(45)) | (limbs[2] << BigInt(6)) & BigInt(0xff));
1053
+ s[13] = Number((limbs[2] >> BigInt(2)) & BigInt(0xff));
1054
+ s[14] = Number((limbs[2] >> BigInt(10)) & BigInt(0xff));
1055
+ s[15] = Number((limbs[2] >> BigInt(18)) & BigInt(0xff));
1056
+ s[16] = Number((limbs[2] >> BigInt(26)) & BigInt(0xff));
1057
+ s[17] = Number((limbs[2] >> BigInt(34)) & BigInt(0xff));
1058
+ s[18] = Number((limbs[2] >> BigInt(42)) & BigInt(0xff));
1059
+ s[19] = Number((limbs[2] >> BigInt(50)) | (limbs[3] << _1n) & BigInt(0xff));
1060
+ s[20] = Number((limbs[3] >> BigInt(7)) & BigInt(0xff));
1061
+ s[21] = Number((limbs[3] >> BigInt(15)) & BigInt(0xff));
1062
+ s[22] = Number((limbs[3] >> BigInt(23)) & BigInt(0xff));
1063
+ s[23] = Number((limbs[3] >> BigInt(31)) & BigInt(0xff));
1064
+ s[24] = Number((limbs[3] >> BigInt(39)) & BigInt(0xff));
1065
+ s[25] = Number((limbs[3] >> BigInt(47)) | (limbs[4] << BigInt(4)) & BigInt(0xff));
1066
+ s[26] = Number((limbs[4] >> BigInt(4)) & BigInt(0xff));
1067
+ s[27] = Number((limbs[4] >> BigInt(12)) & BigInt(0xff));
1068
+ s[28] = Number((limbs[4] >> BigInt(20)) & BigInt(0xff));
1069
+ s[29] = Number((limbs[4] >> BigInt(28)) & BigInt(0xff));
1070
+ s[30] = Number((limbs[4] >> BigInt(36)) & BigInt(0xff));
1071
+ s[31] = Number((limbs[4] >> BigInt(44)) & BigInt(0xff));
1072
+ return s;
1073
+ };
1074
+ return FieldElem51;
1075
+ }());
1076
+ exports.FieldElem51 = FieldElem51;
1077
+ var MontgomeryPoint = /** @class */ (function () {
1078
+ function MontgomeryPoint(bytes) {
1079
+ this.bytes = bytes;
1080
+ }
1081
+ /*
1082
+ pub fn to_edwards(&self, sign: u8) -> Option<EdwardsPoint> {
1083
+ // To decompress the Montgomery u coordinate to an
1084
+ // `EdwardsPoint`, we apply the birational map to obtain the
1085
+ // Edwards y coordinate, then do Edwards decompression.
1086
+ //
1087
+ // The birational map is y = (u-1)/(u+1).
1088
+ //
1089
+ // The exceptional points are the zeros of the denominator,
1090
+ // i.e., u = -1.
1091
+ //
1092
+ // But when u = -1, v^2 = u*(u^2+486662*u+1) = 486660.
1093
+ //
1094
+ // Since this is nonsquare mod p, u = -1 corresponds to a point
1095
+ // on the twist, not the curve, so we can reject it early.
1096
+
1097
+ let u = FieldElement::from_bytes(&self.0);
1098
+
1099
+ if u == FieldElement::minus_one() { return None; }
1100
+
1101
+ let one = FieldElement::one();
1102
+
1103
+ let y = &(&u - &one) * &(&u + &one).invert();
1104
+
1105
+ let mut y_bytes = y.to_bytes();
1106
+ y_bytes[31] ^= sign << 7;
1107
+
1108
+ CompressedEdwardsY(y_bytes).decompress()
1109
+ }
1110
+ */
1111
+ MontgomeryPoint.prototype.to_edwards = function (sign_bit) {
1112
+ var u = FieldElem51.fromBytes(this.bytes);
1113
+ if (u.ct_eq(FieldElem51.minus_one()))
1114
+ return undefined;
1115
+ var one = FieldElem51.one();
1116
+ var y = u.sub(one).mul(u.add(one).invert());
1117
+ var y_bytes = y.toBytes();
1118
+ y_bytes[31] ^= sign_bit << 7;
1119
+ return decompressCompressedEdwardsY(y_bytes);
1120
+ };
1121
+ return MontgomeryPoint;
1122
+ }());
1123
+ exports.MontgomeryPoint = MontgomeryPoint;
1124
+ /*
1125
+ fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<EdwardsPoint>
1126
+ where
1127
+ I: IntoIterator,
1128
+ I::Item: Borrow<Scalar>,
1129
+ J: IntoIterator<Item = Option<EdwardsPoint>>,
1130
+ {
1131
+ use backend::serial::curve_models::{CompletedPoint, ProjectiveNielsPoint, ProjectivePoint};
1132
+ use window::NafLookupTable5;
1133
+ use traits::Identity;
1134
+
1135
+ let nafs: Vec<_> = scalars
1136
+ .into_iter()
1137
+ .map(|c| c.borrow().non_adjacent_form(5))
1138
+ .collect();
1139
+
1140
+ let lookup_tables = points
1141
+ .into_iter()
1142
+ .map(|P_opt| P_opt.map(|P| NafLookupTable5::<ProjectiveNielsPoint>::from(&P)))
1143
+ .collect::<Option<Vec<_>>>()?;
1144
+
1145
+ let mut r = ProjectivePoint::identity();
1146
+
1147
+ for i in (0..256).rev() {
1148
+ let mut t: CompletedPoint = r.double();
1149
+
1150
+ for (naf, lookup_table) in nafs.iter().zip(lookup_tables.iter()) {
1151
+ if naf[i] > 0 {
1152
+ t = &t.to_extended() + &lookup_table.select(naf[i] as usize);
1153
+ } else if naf[i] < 0 {
1154
+ t = &t.to_extended() - &lookup_table.select(-naf[i] as usize);
1155
+ }
1156
+ }
1157
+
1158
+ r = t.to_projective();
1159
+ }
1160
+
1161
+ Some(r.to_extended())
1162
+ }
1163
+ */
1164
+ function straus_optional_multiscalar_mul(scalars, points) {
1165
+ var nafs = scalars.map(function (s) { return scalar_non_adjacent_form(s, 5); });
1166
+ var lookupTables = points.map(function (p) { return NafLookupTable.fromEdwardsPoint(p); });
1167
+ var r = ProjectivePoint.IDENTITY;
1168
+ for (var i = 255; i >= 0; i--) {
1169
+ var t = r.double();
1170
+ for (var j = 0; j < nafs.length; j++) {
1171
+ var naf = nafs[j];
1172
+ var lookupTable = lookupTables[j];
1173
+ if (naf[i] > 0)
1174
+ t = t.toExtended().addProjectiveNiels(lookupTable.select(naf[i]));
1175
+ else if (naf[i] < 0)
1176
+ t = t.toExtended().subProjectiveNiels(lookupTable.select(-naf[i]));
1177
+ r = t.toProjective();
1178
+ }
1179
+ r = t.toProjective();
1180
+ }
1181
+ return r.toExtended();
1182
+ }
1183
+ /*
1184
+ fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<EdwardsPoint>
1185
+ where
1186
+ I: IntoIterator,
1187
+ I::Item: Borrow<Scalar>,
1188
+ J: IntoIterator<Item = Option<EdwardsPoint>>,
1189
+ {
1190
+ use traits::Identity;
1191
+
1192
+ let mut scalars = scalars.into_iter();
1193
+ let size = scalars.by_ref().size_hint().0;
1194
+
1195
+ // Digit width in bits. As digit width grows,
1196
+ // number of point additions goes down, but amount of
1197
+ // buckets and bucket additions grows exponentially.
1198
+ let w = if size < 500 {
1199
+ 6
1200
+ } else if size < 800 {
1201
+ 7
1202
+ } else {
1203
+ 8
1204
+ };
1205
+
1206
+ let max_digit: usize = 1 << w;
1207
+ let digits_count: usize = Scalar::to_radix_2w_size_hint(w);
1208
+ let buckets_count: usize = max_digit / 2; // digits are signed+centered hence 2^w/2, excluding 0-th bucket
1209
+
1210
+ // Collect optimized scalars and points in buffers for repeated access
1211
+ // (scanning the whole set per digit position).
1212
+ let scalars = scalars
1213
+ .map(|s| s.borrow().to_radix_2w(w));
1214
+
1215
+ let points = points
1216
+ .into_iter()
1217
+ .map(|p| p.map(|P| P.to_projective_niels()));
1218
+
1219
+ let scalars_points = scalars
1220
+ .zip(points)
1221
+ .map(|(s, maybe_p)| maybe_p.map(|p| (s, p)))
1222
+ .collect::<Option<Vec<_>>>()?;
1223
+
1224
+ // Prepare 2^w/2 buckets.
1225
+ // buckets[i] corresponds to a multiplication factor (i+1).
1226
+ let mut buckets: Vec<_> = (0..buckets_count)
1227
+ .map(|_| EdwardsPoint::identity())
1228
+ .collect();
1229
+
1230
+ let mut columns = (0..digits_count).rev().map(|digit_index| {
1231
+ // Clear the buckets when processing another digit.
1232
+ for i in 0..buckets_count {
1233
+ buckets[i] = EdwardsPoint::identity();
1234
+ }
1235
+
1236
+ // Iterate over pairs of (point, scalar)
1237
+ // and add/sub the point to the corresponding bucket.
1238
+ // Note: if we add support for precomputed lookup tables,
1239
+ // we'll be adding/subtracting point premultiplied by `digits[i]` to buckets[0].
1240
+ for (digits, pt) in scalars_points.iter() {
1241
+ // Widen digit so that we don't run into edge cases when w=8.
1242
+ let digit = digits[digit_index] as i16;
1243
+ if digit > 0 {
1244
+ let b = (digit - 1) as usize;
1245
+ buckets[b] = (&buckets[b] + pt).to_extended();
1246
+ } else if digit < 0 {
1247
+ let b = (-digit - 1) as usize;
1248
+ buckets[b] = (&buckets[b] - pt).to_extended();
1249
+ }
1250
+ }
1251
+
1252
+ // Add the buckets applying the multiplication factor to each bucket.
1253
+ // The most efficient way to do that is to have a single sum with two running sums:
1254
+ // an intermediate sum from last bucket to the first, and a sum of intermediate sums.
1255
+ //
1256
+ // For example, to add buckets 1*A, 2*B, 3*C we need to add these points:
1257
+ // C
1258
+ // C B
1259
+ // C B A Sum = C + (C+B) + (C+B+A)
1260
+ let mut buckets_intermediate_sum = buckets[buckets_count - 1];
1261
+ let mut buckets_sum = buckets[buckets_count - 1];
1262
+ for i in (0..(buckets_count - 1)).rev() {
1263
+ buckets_intermediate_sum += buckets[i];
1264
+ buckets_sum += buckets_intermediate_sum;
1265
+ }
1266
+
1267
+ buckets_sum
1268
+ });
1269
+
1270
+ // Take the high column as an initial value to avoid wasting time doubling the identity element in `fold()`.
1271
+ // `unwrap()` always succeeds because we know we have more than zero digits.
1272
+ let hi_column = columns.next().unwrap();
1273
+
1274
+ Some(
1275
+ columns
1276
+ .fold(hi_column, |total, p| total.mul_by_pow_2(w as u32) + p),
1277
+ )
1278
+ }
1279
+ }
1280
+ */
1281
+ function pippenger_optional_multiscalar_mul(scalars, points) {
1282
+ var size = scalars.length;
1283
+ var w = size < 500 ? 6 : size < 800 ? 7 : 8;
1284
+ var max_digit = 1 << w;
1285
+ var digits_count = scalar_to_radix_2w_size_hint(w);
1286
+ var buckets_count = (max_digit / 2) >>> 0;
1287
+ var scalras_digits = scalars.map(function (s) { return scalar_to_radix_2w(s, w); });
1288
+ var points_proj = points.map(function (p) { return p.toProjectiveNiels(); });
1289
+ // zipped
1290
+ var scalars_points = scalras_digits.map(function (s, i) { return [s, points_proj[i]]; });
1291
+ // all elems will be replaced in `columns` loop, just a temp value
1292
+ var buckets = new Array(buckets_count).fill(EdwardsPoint.IDENTITY);
1293
+ var columns = new Array(buckets_count).fill(0).map(function () { return EdwardsPoint.IDENTITY; });
1294
+ for (var i = digits_count - 1; i >= 0; i--) {
1295
+ for (var j = 0; j < buckets_count; j++)
1296
+ buckets[j] = EdwardsPoint.IDENTITY;
1297
+ for (var j = 0; j < scalars_points.length; j++) {
1298
+ var _a = __read(scalars_points[j], 2), digits = _a[0], pt = _a[1];
1299
+ var digit = digits[i];
1300
+ if (digit > 0) {
1301
+ var b = digit - 1;
1302
+ buckets[b] = buckets[b].addProjectiveNiels(pt).toExtended();
1303
+ }
1304
+ else if (digit < 0) {
1305
+ var b = -digit - 1;
1306
+ buckets[b] = buckets[b].subProjectiveNiels(pt).toExtended();
1307
+ }
1308
+ }
1309
+ var buckets_intermediate_sum = buckets[buckets_count - 1];
1310
+ var buckets_sum = buckets[buckets_count - 1];
1311
+ for (var j = buckets_count - 2; j >= 0; j--) {
1312
+ buckets_intermediate_sum = buckets_intermediate_sum.add(buckets[j]);
1313
+ buckets_sum = buckets_sum.add(buckets_intermediate_sum);
1314
+ }
1315
+ columns[i] = buckets_sum;
1316
+ }
1317
+ // const hi_column = columns[ columns.length - 1 ];
1318
+ return columns.reduce(function (total, p) { return total.mulByPow2(w).add(p); });
1319
+ }
1320
+ function scalar_to_radix_2w_size_hint(w) {
1321
+ return (((256 + w - 1) / w) >>> 0) + (w >= 8 ? 1 : 0);
1322
+ }
1323
+ /*
1324
+ pub(crate) fn to_radix_2w(&self, w: usize) -> [i8; 64] {
1325
+ debug_assert!(w >= 4);
1326
+ debug_assert!(w <= 8);
1327
+
1328
+ if w == 4 {
1329
+ return self.to_radix_16();
1330
+ }
1331
+
1332
+ use byteorder::{ByteOrder, LittleEndian};
1333
+
1334
+ // Scalar formatted as four `u64`s with carry bit packed into the highest bit.
1335
+ let mut scalar64x4 = [0u64; 4];
1336
+ LittleEndian::read_u64_into(&self.bytes, &mut scalar64x4[0..4]);
1337
+
1338
+ let radix: u64 = 1 << w;
1339
+ let window_mask: u64 = radix - 1;
1340
+
1341
+ let mut carry = 0u64;
1342
+ let mut digits = [0i8; 64];
1343
+ let digits_count = (256 + w - 1)/w as usize;
1344
+ for i in 0..digits_count {
1345
+ // Construct a buffer of bits of the scalar, starting at `bit_offset`.
1346
+ let bit_offset = i*w;
1347
+ let u64_idx = bit_offset / 64;
1348
+ let bit_idx = bit_offset % 64;
1349
+
1350
+ // Read the bits from the scalar
1351
+ let bit_buf: u64;
1352
+ if bit_idx < 64 - w || u64_idx == 3 {
1353
+ // This window's bits are contained in a single u64,
1354
+ // or it's the last u64 anyway.
1355
+ bit_buf = scalar64x4[u64_idx] >> bit_idx;
1356
+ } else {
1357
+ // Combine the current u64's bits with the bits from the next u64
1358
+ bit_buf = (scalar64x4[u64_idx] >> bit_idx) | (scalar64x4[1+u64_idx] << (64 - bit_idx));
1359
+ }
1360
+
1361
+ // Read the actual coefficient value from the window
1362
+ let coef = carry + (bit_buf & window_mask); // coef = [0, 2^r)
1363
+
1364
+ // Recenter coefficients from [0,2^w) to [-2^w/2, 2^w/2)
1365
+ carry = (coef + (radix/2) as u64) >> w;
1366
+ digits[i] = ((coef as i64) - (carry << w) as i64) as i8;
1367
+ }
1368
+
1369
+ // When w < 8, we can fold the final carry onto the last digit d,
1370
+ // because d < 2^w/2 so d + carry*2^w = d + 1*2^w < 2^(w+1) < 2^8.
1371
+ //
1372
+ // When w = 8, we can't fit carry*2^w into an i8. This should
1373
+ // not happen anyways, because the final carry will be 0 for
1374
+ // reduced scalars, but the Scalar invariant allows 255-bit scalars.
1375
+ // To handle this, we expand the size_hint by 1 when w=8,
1376
+ // and accumulate the final carry onto another digit.
1377
+ match w {
1378
+ 8 => digits[digits_count] += carry as i8,
1379
+ _ => digits[digits_count-1] += (carry << w) as i8,
1380
+ }
1381
+
1382
+ digits
1383
+ }
1384
+ */
1385
+ function scalar_to_radix_2w(scalar, w) {
1386
+ if (w === 4)
1387
+ return scalar_to_radix_16(scalar);
1388
+ var scalar64x4 = new BigUint64Array(4);
1389
+ read_u64_into_LE(scalar, scalar64x4);
1390
+ var radix = BigInt(1 << w);
1391
+ var window_mask = radix - _1n;
1392
+ var carry = _0n;
1393
+ var digits = new Int8Array(64);
1394
+ var u8digits = new Uint8Array(digits.buffer);
1395
+ var digits_count = (((256 + w - 1) / w) >>> 0);
1396
+ for (var i = 0; i < digits_count; i++) {
1397
+ var bit_offset = i * w;
1398
+ var u64_idx = (bit_offset / 64) >>> 0;
1399
+ var bit_idx = BigInt(bit_offset % 64);
1400
+ var bit_buf = void 0;
1401
+ if (bit_idx < 64 - w || u64_idx === 3)
1402
+ bit_buf = scalar64x4[u64_idx] >> bit_idx;
1403
+ else
1404
+ bit_buf = (scalar64x4[u64_idx] >> bit_idx) | ((scalar64x4[1 + u64_idx] << (_64n - bit_idx)) & LOW_64_BIT_MASK);
1405
+ var coef = (carry + (bit_buf & window_mask) & LOW_64_BIT_MASK);
1406
+ carry = ((coef + (radix >> _1n)) / radix) & LOW_64_BIT_MASK;
1407
+ u8digits[i] = Number((coef - (carry * radix))) & 0xff;
1408
+ }
1409
+ if (w === 8)
1410
+ u8digits[digits_count] = (u8digits[digits_count] + Number(carry)) & 0xff;
1411
+ else
1412
+ u8digits[digits_count - 1] = (u8digits[digits_count - 1] + (Number(carry) << w)) & 0xff;
1413
+ return digits;
1414
+ }
1415
+ var EdwardsPoint = /** @class */ (function () {
1416
+ function EdwardsPoint(X, Y, Z, T) {
1417
+ this.X = X;
1418
+ this.Y = Y;
1419
+ this.Z = Z;
1420
+ this.T = T;
1421
+ }
1422
+ /*
1423
+ /// Compute \\([2\^k] P \\) by successive doublings. Requires \\( k > 0 \\).
1424
+ pub(crate) fn mul_by_pow_2(&self, k: u32) -> EdwardsPoint {
1425
+ debug_assert!( k > 0 );
1426
+ let mut r: CompletedPoint;
1427
+ let mut s = self.to_projective();
1428
+ for _ in 0..(k-1) {
1429
+ r = s.double(); s = r.to_projective();
1430
+ }
1431
+ // Unroll last iteration so we can go directly to_extended()
1432
+ s.double().to_extended()
1433
+ }
1434
+ */
1435
+ EdwardsPoint.prototype.mulByPow2 = function (k) {
1436
+ if (k <= 0)
1437
+ throw new Error("k must be > 0");
1438
+ var r;
1439
+ var s = this.toProjective();
1440
+ for (var i = 0; i < k - 1; i++) {
1441
+ r = s.double();
1442
+ s = r.toProjective();
1443
+ }
1444
+ return s.double().toExtended();
1445
+ };
1446
+ EdwardsPoint.prototype.equals = function (other) {
1447
+ return this.X.ct_eq(other.X)
1448
+ && this.Y.ct_eq(other.Y)
1449
+ && this.Z.ct_eq(other.Z)
1450
+ && this.T.ct_eq(other.T);
1451
+ };
1452
+ Object.defineProperty(EdwardsPoint, "DOUBLE_BASE_COMPRESSED", {
1453
+ get: function () {
1454
+ return new Uint8Array([0xc9, 0xa3, 0xf8, 0x6a, 0xae, 0x46, 0x5f, 0xe,
1455
+ 0x56, 0x51, 0x38, 0x64, 0x51, 0x0f, 0x39, 0x97,
1456
+ 0x56, 0x1f, 0xa2, 0xc9, 0xe8, 0x5e, 0xa2, 0x1d,
1457
+ 0xc2, 0x29, 0x23, 0x09, 0xf3, 0xcd, 0x60, 0x22]);
1458
+ },
1459
+ enumerable: false,
1460
+ configurable: true
1461
+ });
1462
+ Object.defineProperty(EdwardsPoint, "BASEPOINT_ED25519_COMPRESSED", {
1463
+ get: function () {
1464
+ return new Uint8Array([0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
1465
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
1466
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
1467
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66]);
1468
+ },
1469
+ enumerable: false,
1470
+ configurable: true
1471
+ });
1472
+ Object.defineProperty(EdwardsPoint, "BASEPOINT_ED25519", {
1473
+ get: function () {
1474
+ return new EdwardsPoint(new FieldElem51(new BigUint64Array([
1475
+ BigInt("1738742601995546"),
1476
+ BigInt("1146398526822698"),
1477
+ BigInt("2070867633025821"),
1478
+ BigInt("562264141797630"),
1479
+ BigInt("587772402128613"),
1480
+ ])), new FieldElem51(new BigUint64Array([
1481
+ BigInt("1801439850948184"),
1482
+ BigInt("1351079888211148"),
1483
+ BigInt("450359962737049"),
1484
+ BigInt("900719925474099"),
1485
+ BigInt("1801439850948198"),
1486
+ ])), new FieldElem51(new BigUint64Array([
1487
+ BigInt("1"),
1488
+ BigInt("0"),
1489
+ BigInt("0"),
1490
+ BigInt("0"),
1491
+ BigInt("0")
1492
+ ])), new FieldElem51(new BigUint64Array([
1493
+ BigInt("1841354044333475"),
1494
+ BigInt("16398895984059"),
1495
+ BigInt("755974180946558"),
1496
+ BigInt("900171276175154"),
1497
+ BigInt("1821297809914039"),
1498
+ ])));
1499
+ },
1500
+ enumerable: false,
1501
+ configurable: true
1502
+ });
1503
+ EdwardsPoint.prototype.is_valid = function () {
1504
+ var on_curve = this.toProjective().is_valid();
1505
+ var on_ceger_image = this.X.mul(this.Y).ct_eq(this.Z.mul(this.T));
1506
+ return on_curve && on_ceger_image;
1507
+ };
1508
+ /*
1509
+ fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<EdwardsPoint>
1510
+ where
1511
+ I: IntoIterator,
1512
+ I::Item: Borrow<Scalar>,
1513
+ J: IntoIterator<Item = Option<EdwardsPoint>>,
1514
+ {
1515
+ // Sanity-check lengths of input iterators
1516
+ let mut scalars = scalars.into_iter();
1517
+ let mut points = points.into_iter();
1518
+
1519
+ // Lower and upper bounds on iterators
1520
+ let (s_lo, s_hi) = scalars.by_ref().size_hint();
1521
+ let (p_lo, p_hi) = points.by_ref().size_hint();
1522
+
1523
+ // They should all be equal
1524
+ assert_eq!(s_lo, p_lo);
1525
+ assert_eq!(s_hi, Some(s_lo));
1526
+ assert_eq!(p_hi, Some(p_lo));
1527
+
1528
+ // Now we know there's a single size.
1529
+ // Use this as the hint to decide which algorithm to use.
1530
+ let size = s_lo;
1531
+
1532
+ if size < 190 {
1533
+ scalar_mul::straus::Straus::optional_multiscalar_mul(scalars, points)
1534
+ } else {
1535
+ scalar_mul::pippenger::Pippenger::optional_multiscalar_mul(scalars, points)
1536
+ }
1537
+ }
1538
+ */
1539
+ EdwardsPoint.vartime_multiscalar_mul = function (scalars, points) {
1540
+ return straus_optional_multiscalar_mul(scalars, points);
1541
+ // pippenger impl is wrong
1542
+ // if( scalars.length < 190 )
1543
+ // return straus_optional_multiscalar_mul( scalars, points );
1544
+ // else
1545
+ // return pippenger_optional_multiscalar_mul( scalars, points );
1546
+ };
1547
+ EdwardsPoint.prototype.double = function () {
1548
+ return this.toProjective().double().toExtended();
1549
+ };
1550
+ /*
1551
+ /// Compute \\(aA + bB\\) in variable time, where \\(B\\) is the Ed25519 basepoint.
1552
+ pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
1553
+ let a_naf = a.non_adjacent_form(5);
1554
+ let b_naf = b.non_adjacent_form(8);
1555
+
1556
+ // Find starting index
1557
+ let mut i: usize = 255;
1558
+ for j in (0..256).rev() {
1559
+ i = j;
1560
+ if a_naf[i] != 0 || b_naf[i] != 0 {
1561
+ break;
1562
+ }
1563
+ }
1564
+
1565
+ let table_A = NafLookupTable::<ProjectiveNielsPoint>::from(A);
1566
+ let table_B = &constants::AFFINE_ODD_MULTIPLES_OF_BASEPOINT;
1567
+
1568
+ let mut r = ProjectivePoint::identity();
1569
+ loop {
1570
+ let mut t = r.double();
1571
+
1572
+ if a_naf[i] > 0 {
1573
+ t = &t.to_extended() + &table_A.select(a_naf[i] as usize);
1574
+ } else if a_naf[i] < 0 {
1575
+ t = &t.to_extended() - &table_A.select(-a_naf[i] as usize);
1576
+ }
1577
+
1578
+ if b_naf[i] > 0 {
1579
+ t = &t.to_extended() + &table_B.select(b_naf[i] as usize);
1580
+ } else if b_naf[i] < 0 {
1581
+ t = &t.to_extended() - &table_B.select(-b_naf[i] as usize);
1582
+ }
1583
+
1584
+ r = t.to_projective();
1585
+
1586
+ if i == 0 {
1587
+ break;
1588
+ }
1589
+ i -= 1;
1590
+ }
1591
+
1592
+ r.to_extended()
1593
+ }
1594
+ */
1595
+ EdwardsPoint.vartime_double_scalar_mul_basepoint = function (neg_challenge, pk, response) {
1596
+ var a_naf = scalar_non_adjacent_form(neg_challenge, 5);
1597
+ var b_naf = scalar_non_adjacent_form(response, 8);
1598
+ var i = 255;
1599
+ for (var j = 255; j >= 0; j--) {
1600
+ i = j;
1601
+ if (a_naf[i] !== 0 || b_naf[i] !== 0) {
1602
+ break;
1603
+ }
1604
+ }
1605
+ ;
1606
+ var table_A = NafLookupTable.fromEdwardsPoint(pk);
1607
+ var table_B = AFFINE_ODD_MULTIPLES_OF_BASEPOINT;
1608
+ var r = ProjectivePoint.IDENTITY;
1609
+ while (true) {
1610
+ var t = r.double();
1611
+ if (a_naf[i] > 0)
1612
+ t = t.toExtended().addProjectiveNiels(table_A.select(a_naf[i]));
1613
+ else if (a_naf[i] < 0)
1614
+ t = t.toExtended().subProjectiveNiels(table_A.select(-a_naf[i]));
1615
+ if (b_naf[i] > 0)
1616
+ t = t.toExtended().addAffineNielsPoint(table_B.select(b_naf[i]));
1617
+ else if (b_naf[i] < 0)
1618
+ t = t.toExtended().subAffineNielsPoint(table_B.select(-b_naf[i]));
1619
+ r = t.toProjective();
1620
+ if (i === 0)
1621
+ break;
1622
+ i--;
1623
+ }
1624
+ return r.toExtended();
1625
+ };
1626
+ EdwardsPoint.prototype.ct_eq = function (other) {
1627
+ return (0, uint8array_utils_1.uint8ArrayEq)(this.compress(), other.compress());
1628
+ };
1629
+ EdwardsPoint.decompress = function (compressed) {
1630
+ return decompressCompressedEdwardsY(compressed);
1631
+ };
1632
+ EdwardsPoint.uncompress = function (compressed) {
1633
+ return decompressCompressedEdwardsY(compressed);
1634
+ };
1635
+ /*
1636
+ pub fn is_small_order(&self) -> bool {
1637
+ self.mul_by_cofactor().is_identity()
1638
+ }
1639
+ */
1640
+ EdwardsPoint.prototype.is_small_order = function () {
1641
+ return this.mul_by_cofactor().is_identity();
1642
+ };
1643
+ /*
1644
+ fn is_identity(&self) -> bool {
1645
+ self.ct_eq(&T::identity()).unwrap_u8() == 1u8
1646
+ }
1647
+ */
1648
+ EdwardsPoint.prototype.is_identity = function () {
1649
+ return this.ct_eq(EdwardsPoint.IDENTITY);
1650
+ };
1651
+ EdwardsPoint.prototype.clone = function () {
1652
+ return new EdwardsPoint(this.X.clone(), this.Y.clone(), this.Z.clone(), this.T.clone());
1653
+ };
1654
+ Object.defineProperty(EdwardsPoint, "IDENTITY", {
1655
+ get: function () {
1656
+ return new EdwardsPoint(FieldElem51.zero(), FieldElem51.one(), FieldElem51.one(), FieldElem51.zero());
1657
+ },
1658
+ enumerable: false,
1659
+ configurable: true
1660
+ });
1661
+ /*
1662
+ fn add(self, other: &'b EdwardsPoint) -> EdwardsPoint {
1663
+ (self + &other.to_projective_niels()).to_extended()
1664
+ }
1665
+ */
1666
+ EdwardsPoint.prototype.add = function (other) {
1667
+ return this.addProjectiveNiels(other.toProjectiveNiels()).toExtended();
1668
+ };
1669
+ /*
1670
+ fn add(self, other: &'b ProjectiveNielsPoint) -> CompletedPoint {
1671
+ let Y_plus_X = &self.Y + &self.X;
1672
+ let Y_minus_X = &self.Y - &self.X;
1673
+ let PP = &Y_plus_X * &other.Y_plus_X;
1674
+ let MM = &Y_minus_X * &other.Y_minus_X;
1675
+ let TT2d = &self.T * &other.T2d;
1676
+ let ZZ = &self.Z * &other.Z;
1677
+ let ZZ2 = &ZZ + &ZZ;
1678
+
1679
+ CompletedPoint{
1680
+ X: &PP - &MM,
1681
+ Y: &PP + &MM,
1682
+ Z: &ZZ2 + &TT2d,
1683
+ T: &ZZ2 - &TT2d
1684
+ }
1685
+ }
1686
+ */
1687
+ EdwardsPoint.prototype.addProjectiveNiels = function (other) {
1688
+ var Y_plus_X = this.Y.add(this.X);
1689
+ var Y_minus_X = this.Y.sub(this.X);
1690
+ var PP = Y_plus_X.mul(other.Y_plus_X);
1691
+ var MM = Y_minus_X.mul(other.Y_minus_X);
1692
+ var TT2d = this.T.mul(other.T2d);
1693
+ var ZZ = this.Z.mul(other.Z);
1694
+ var ZZ2 = ZZ.add(ZZ);
1695
+ return new CompletedPoint(PP.sub(MM), PP.add(MM), ZZ2.add(TT2d), ZZ2.sub(TT2d));
1696
+ };
1697
+ /*
1698
+ fn sub(self, other: &'b ProjectiveNielsPoint) -> CompletedPoint {
1699
+ let Y_plus_X = &self.Y + &self.X;
1700
+ let Y_minus_X = &self.Y - &self.X;
1701
+ let PM = &Y_plus_X * &other.Y_minus_X;
1702
+ let MP = &Y_minus_X * &other.Y_plus_X;
1703
+ let TT2d = &self.T * &other.T2d;
1704
+ let ZZ = &self.Z * &other.Z;
1705
+ let ZZ2 = &ZZ + &ZZ;
1706
+
1707
+ CompletedPoint{
1708
+ X: &PM - &MP,
1709
+ Y: &PM + &MP,
1710
+ Z: &ZZ2 - &TT2d,
1711
+ T: &ZZ2 + &TT2d
1712
+ }
1713
+ }
1714
+ */
1715
+ EdwardsPoint.prototype.subProjectiveNiels = function (other) {
1716
+ var Y_plus_X = this.Y.add(this.X);
1717
+ var Y_minus_X = this.Y.sub(this.X);
1718
+ var PM = Y_plus_X.mul(other.Y_minus_X);
1719
+ var MP = Y_minus_X.mul(other.Y_plus_X);
1720
+ var TT2d = this.T.mul(other.T2d);
1721
+ var ZZ = this.Z.mul(other.Z);
1722
+ var ZZ2 = ZZ.add(ZZ);
1723
+ return new CompletedPoint(PM.sub(MP), PM.add(MP), ZZ2.sub(TT2d), ZZ2.add(TT2d));
1724
+ };
1725
+ /*
1726
+ fn add(self, other: &'b AffineNielsPoint) -> CompletedPoint {
1727
+ let Y_plus_X = &self.Y + &self.X;
1728
+ let Y_minus_X = &self.Y - &self.X;
1729
+ let PP = &Y_plus_X * &other.y_plus_x;
1730
+ let MM = &Y_minus_X * &other.y_minus_x;
1731
+ let Txy2d = &self.T * &other.xy2d;
1732
+ let Z2 = &self.Z + &self.Z;
1733
+
1734
+ CompletedPoint{
1735
+ X: &PP - &MM,
1736
+ Y: &PP + &MM,
1737
+ Z: &Z2 + &Txy2d,
1738
+ T: &Z2 - &Txy2d
1739
+ }
1740
+ }
1741
+ */
1742
+ EdwardsPoint.prototype.addAffineNielsPoint = function (other) {
1743
+ var Y_plus_X = this.Y.add(this.X);
1744
+ var Y_minus_X = this.Y.sub(this.X);
1745
+ var PP = Y_plus_X.mul(other.y_plus_x);
1746
+ var MM = Y_minus_X.mul(other.y_minus_x);
1747
+ var Txy2d = this.T.mul(other.xy2d);
1748
+ var Z2 = this.Z.add(this.Z);
1749
+ return new CompletedPoint(PP.sub(MM), PP.add(MM), Z2.add(Txy2d), Z2.sub(Txy2d));
1750
+ };
1751
+ /*
1752
+ fn sub(self, other: &'b AffineNielsPoint) -> CompletedPoint {
1753
+ let Y_plus_X = &self.Y + &self.X;
1754
+ let Y_minus_X = &self.Y - &self.X;
1755
+ let PM = &Y_plus_X * &other.y_minus_x;
1756
+ let MP = &Y_minus_X * &other.y_plus_x;
1757
+ let Txy2d = &self.T * &other.xy2d;
1758
+ let Z2 = &self.Z + &self.Z;
1759
+
1760
+ CompletedPoint{
1761
+ X: &PM - &MP,
1762
+ Y: &PM + &MP,
1763
+ Z: &Z2 - &Txy2d,
1764
+ T: &Z2 + &Txy2d
1765
+ }
1766
+ }
1767
+ */
1768
+ EdwardsPoint.prototype.subAffineNielsPoint = function (other) {
1769
+ var Y_plus_X = this.Y.add(this.X);
1770
+ var Y_minus_X = this.Y.sub(this.X);
1771
+ var PM = Y_plus_X.mul(other.y_minus_x);
1772
+ var MP = Y_minus_X.mul(other.y_plus_x);
1773
+ var Txy2d = this.T.mul(other.xy2d);
1774
+ var Z2 = this.Z.add(this.Z);
1775
+ return new CompletedPoint(PM.sub(MP), PM.add(MP), Z2.sub(Txy2d), Z2.add(Txy2d));
1776
+ };
1777
+ /*
1778
+ /// Convert to a ProjectiveNielsPoint
1779
+ pub(crate) fn to_projective_niels(&self) -> ProjectiveNielsPoint {
1780
+ ProjectiveNielsPoint{
1781
+ Y_plus_X: &self.Y + &self.X,
1782
+ Y_minus_X: &self.Y - &self.X,
1783
+ Z: self.Z,
1784
+ T2d: &self.T * &constants::EDWARDS_D2,
1785
+ }
1786
+ }
1787
+ */
1788
+ EdwardsPoint.prototype.toProjectiveNiels = function () {
1789
+ return new ProjectiveNielsPoint(this.Y.add(this.X), this.Y.sub(this.X), this.Z, this.T.mul(FieldElem51.EDWARDS_D2));
1790
+ };
1791
+ /*
1792
+ /// Multiply by the cofactor: return \\([8]P\\).
1793
+ pub fn mul_by_cofactor(&self) -> EdwardsPoint {
1794
+ self.mul_by_pow_2(3)
1795
+ }
1796
+ */
1797
+ EdwardsPoint.prototype.mul_by_cofactor = function () {
1798
+ return this.mul_by_pow_2(3);
1799
+ };
1800
+ /*
1801
+ /// Compress this point to `CompressedEdwardsY` format.
1802
+ pub fn compress(&self) -> CompressedEdwardsY {
1803
+ let recip = self.Z.invert();
1804
+ let x = &self.X * &recip;
1805
+ let y = &self.Y * &recip;
1806
+ let mut s: [u8; 32];
1807
+
1808
+ s = y.to_bytes();
1809
+ s[31] ^= x.is_negative().unwrap_u8() << 7;
1810
+ CompressedEdwardsY(s)
1811
+ }
1812
+ */
1813
+ EdwardsPoint.prototype.compress = function () {
1814
+ var recip = this.Z.invert();
1815
+ var x = this.X.mul(recip);
1816
+ var y = this.Y.mul(recip);
1817
+ var s = y.toBytes();
1818
+ var bit = x.is_negative() ? 1 : 0;
1819
+ s[31] ^= bit << 7;
1820
+ return s;
1821
+ };
1822
+ EdwardsPoint.prototype.compressed_is_negative = function () {
1823
+ var recip = this.Z.invert();
1824
+ var x = this.X.mul(recip);
1825
+ return x.is_negative();
1826
+ };
1827
+ /*
1828
+ /// Compute \\([2\^k] P \\) by successive doublings. Requires \\( k > 0 \\).
1829
+ pub(crate) fn mul_by_pow_2(&self, k: u32) -> EdwardsPoint {
1830
+ debug_assert!( k > 0 );
1831
+ let mut r: CompletedPoint;
1832
+ let mut s = self.to_projective();
1833
+ for _ in 0..(k-1) {
1834
+ r = s.double(); s = r.to_projective();
1835
+ }
1836
+ // Unroll last iteration so we can go directly to_extended()
1837
+ s.double().to_extended()
1838
+ }
1839
+ */
1840
+ EdwardsPoint.prototype.mul_by_pow_2 = function (k) {
1841
+ if (k <= 0)
1842
+ throw new Error("mul_by_pow_2 :: k must be greater than 0");
1843
+ var r;
1844
+ var s = this.toProjective();
1845
+ for (var i = 0; i < k - 1; i++) {
1846
+ r = s.double();
1847
+ s = r.toProjective();
1848
+ }
1849
+ return s.double().toExtended();
1850
+ };
1851
+ /*
1852
+ /// Convert the representation of this point from extended
1853
+ /// coordinates to projective coordinates.
1854
+ ///
1855
+ /// Free.
1856
+ pub(crate) fn to_projective(&self) -> ProjectivePoint {
1857
+ ProjectivePoint{
1858
+ X: self.X,
1859
+ Y: self.Y,
1860
+ Z: self.Z,
1861
+ }
1862
+ }
1863
+ */
1864
+ EdwardsPoint.prototype.toProjective = function () {
1865
+ return new ProjectivePoint(this.X, this.Y, this.Z);
1866
+ };
1867
+ /*
1868
+ /// Perform constant-time, variable-base scalar multiplication.
1869
+ pub(crate) fn mul(point: &EdwardsPoint, scalar: &Scalar) -> EdwardsPoint {
1870
+ // Construct a lookup table of [P,2P,3P,4P,5P,6P,7P,8P]
1871
+ let lookup_table = LookupTable::<ProjectiveNielsPoint>::from(point);
1872
+ // Setting s = scalar, compute
1873
+ //
1874
+ // s = s_0 + s_1*16^1 + ... + s_63*16^63,
1875
+ //
1876
+ // with `-8 ≤ s_i < 8` for `0 ≤ i < 63` and `-8 ≤ s_63 ≤ 8`.
1877
+ let scalar_digits = scalar.to_radix_16();
1878
+ // Compute s*P as
1879
+ //
1880
+ // s*P = P*(s_0 + s_1*16^1 + s_2*16^2 + ... + s_63*16^63)
1881
+ // s*P = P*s_0 + P*s_1*16^1 + P*s_2*16^2 + ... + P*s_63*16^63
1882
+ // s*P = P*s_0 + 16*(P*s_1 + 16*(P*s_2 + 16*( ... + P*s_63)...))
1883
+ //
1884
+ // We sum right-to-left.
1885
+
1886
+ // Unwrap first loop iteration to save computing 16*identity
1887
+ let mut tmp2;
1888
+ let mut tmp3 = EdwardsPoint::identity();
1889
+ let mut tmp1 = &tmp3 + &lookup_table.select(scalar_digits[63]);
1890
+ // Now tmp1 = s_63*P in P1xP1 coords
1891
+ for i in (0..63).rev() {
1892
+ tmp2 = tmp1.to_projective(); // tmp2 = (prev) in P2 coords
1893
+ tmp1 = tmp2.double(); // tmp1 = 2*(prev) in P1xP1 coords
1894
+ tmp2 = tmp1.to_projective(); // tmp2 = 2*(prev) in P2 coords
1895
+ tmp1 = tmp2.double(); // tmp1 = 4*(prev) in P1xP1 coords
1896
+ tmp2 = tmp1.to_projective(); // tmp2 = 4*(prev) in P2 coords
1897
+ tmp1 = tmp2.double(); // tmp1 = 8*(prev) in P1xP1 coords
1898
+ tmp2 = tmp1.to_projective(); // tmp2 = 8*(prev) in P2 coords
1899
+ tmp1 = tmp2.double(); // tmp1 = 16*(prev) in P1xP1 coords
1900
+ tmp3 = tmp1.to_extended(); // tmp3 = 16*(prev) in P3 coords
1901
+ tmp1 = &tmp3 + &lookup_table.select(scalar_digits[i]);
1902
+ // Now tmp1 = s_i*P + 16*(prev) in P1xP1 coords
1903
+ }
1904
+ tmp1.to_extended()
1905
+ }
1906
+ */
1907
+ /*
1908
+ */
1909
+ EdwardsPoint.prototype.scalarMul = function (scalar) {
1910
+ var lookup_table = ProjectiveNielsPoint.tableFromEdwardPoint(this);
1911
+ var scalar_digits = scalar_to_radix_16(scalar);
1912
+ var tmp2 = ProjectivePoint.IDENTITY;
1913
+ var tmp3 = EdwardsPoint.IDENTITY;
1914
+ var tmp1 = tmp3.addProjectiveNiels(lookup_table.select(scalar_digits[63]));
1915
+ for (var i = 62; i >= 0; i--) {
1916
+ tmp2 = tmp1.toProjective();
1917
+ tmp1 = tmp2.double();
1918
+ tmp2 = tmp1.toProjective();
1919
+ tmp1 = tmp2.double();
1920
+ tmp2 = tmp1.toProjective();
1921
+ tmp1 = tmp2.double();
1922
+ tmp2 = tmp1.toProjective();
1923
+ tmp1 = tmp2.double();
1924
+ tmp3 = tmp1.toExtended();
1925
+ tmp1 = tmp3.addProjectiveNiels(lookup_table.select(scalar_digits[i]));
1926
+ }
1927
+ return tmp1.toExtended();
1928
+ };
1929
+ return EdwardsPoint;
1930
+ }());
1931
+ exports.EdwardsPoint = EdwardsPoint;
1932
+ var NafLookupTable = /** @class */ (function () {
1933
+ function NafLookupTable(points) {
1934
+ this.points = points;
1935
+ }
1936
+ /*
1937
+ /// Given public, odd \\( x \\) with \\( 0 < x < 2^4 \\), return \\(xA\\).
1938
+ pub fn select(&self, x: usize) -> T {
1939
+ debug_assert_eq!(x & 1, 1);
1940
+ debug_assert!(x < 16););
1941
+
1942
+ self.0[x / 2]
1943
+ }
1944
+ */
1945
+ NafLookupTable.prototype.select = function (i) {
1946
+ // debug_assert_eq(x & 1, 1);
1947
+ // debug_assert(x < 16););
1948
+ return this.points[(i / 2) >>> 0];
1949
+ };
1950
+ /*
1951
+ fn from(A: &'a EdwardsPoint) -> Self {
1952
+ let mut Ai: [ProjectiveNielsPoint; 8] = [A.to_projective_niels(); 8];
1953
+ let A2 = A.double();
1954
+ for i in 0..7 {
1955
+ Ai[i + 1] = (&A2 + &Ai[i]).to_extended().to_projective_niels();
1956
+ }
1957
+ // Now Ai = [A, 3A, 5A, 7A, 9A, 11A, 13A, 15A]
1958
+ NafLookupTable(Ai)
1959
+ }
1960
+ */
1961
+ NafLookupTable.fromEdwardsPoint = function (point) {
1962
+ var Ai = new Array(8).fill(0).map(function (_) { return point.toProjectiveNiels(); });
1963
+ var A2 = point.double();
1964
+ for (var i = 0; i < 7; i++) {
1965
+ Ai[i + 1] = A2.addProjectiveNiels(Ai[i]).toExtended().toProjectiveNiels();
1966
+ }
1967
+ // Now Ai = [A, 3A, 5A, 7A, 9A, 11A, 13A, 15A]
1968
+ return new NafLookupTable(Ai);
1969
+ };
1970
+ return NafLookupTable;
1971
+ }());
1972
+ var AffineNielsPoint = /** @class */ (function () {
1973
+ function AffineNielsPoint(y_plus_x, y_minus_x, xy2d) {
1974
+ this.y_plus_x = y_plus_x;
1975
+ this.y_minus_x = y_minus_x;
1976
+ this.xy2d = xy2d;
1977
+ }
1978
+ return AffineNielsPoint;
1979
+ }());
1980
+ exports.ED25519_BASEPOINT_POINT = new EdwardsPoint(new FieldElem51(new BigUint64Array([
1981
+ BigInt("1738742601995546"),
1982
+ BigInt("1146398526822698"),
1983
+ BigInt("2070867633025821"),
1984
+ BigInt("562264141797630"),
1985
+ BigInt("587772402128613"),
1986
+ ])), new FieldElem51(new BigUint64Array([
1987
+ BigInt("1801439850948184"),
1988
+ BigInt("1351079888211148"),
1989
+ BigInt("450359962737049"),
1990
+ BigInt("900719925474099"),
1991
+ BigInt("1801439850948198"),
1992
+ ])), new FieldElem51(new BigUint64Array([
1993
+ BigInt("1"),
1994
+ BigInt("0"),
1995
+ BigInt("0"),
1996
+ BigInt("0"),
1997
+ BigInt("0")
1998
+ ])), new FieldElem51(new BigUint64Array([
1999
+ BigInt("1841354044333475"),
2000
+ BigInt("16398895984059"),
2001
+ BigInt("755974180946558"),
2002
+ BigInt("900171276175154"),
2003
+ BigInt("1821297809914039"),
2004
+ ])));
2005
+ /*
2006
+ pub struct ProjectiveNielsPoint {
2007
+ pub Y_plus_X: FieldElement,
2008
+ pub Y_minus_X: FieldElement,
2009
+ pub Z: FieldElement,
2010
+ pub T2d: FieldElement,
2011
+ }
2012
+
2013
+ */
2014
+ var ProjectiveNielsPoint = /** @class */ (function () {
2015
+ function ProjectiveNielsPoint(Y_plus_X, Y_minus_X, Z, T2d) {
2016
+ this.Y_plus_X = Y_plus_X;
2017
+ this.Y_minus_X = Y_minus_X;
2018
+ this.Z = Z;
2019
+ this.T2d = T2d;
2020
+ }
2021
+ ProjectiveNielsPoint.prototype.clone = function () {
2022
+ return new ProjectiveNielsPoint(this.Y_plus_X.clone(), this.Y_minus_X.clone(), this.Z.clone(), this.T2d.clone());
2023
+ };
2024
+ /** not really, but useful to debug */
2025
+ ProjectiveNielsPoint.prototype.compress = function () {
2026
+ return EdwardsPoint.IDENTITY
2027
+ .addProjectiveNiels(this)
2028
+ .toExtended()
2029
+ .compress();
2030
+ };
2031
+ ProjectiveNielsPoint.prototype.compressed_is_negative = function () {
2032
+ return EdwardsPoint.IDENTITY
2033
+ .addProjectiveNiels(this)
2034
+ .toExtended()
2035
+ .compressed_is_negative();
2036
+ };
2037
+ ProjectiveNielsPoint.identity = function () {
2038
+ return new ProjectiveNielsPoint(FieldElem51.one(), FieldElem51.one(), FieldElem51.one(), FieldElem51.zero());
2039
+ };
2040
+ /**
2041
+ * # WARNING
2042
+ *
2043
+ * **I FOUND NO IMPLEMENTATION** (Thanks generics)
2044
+ *
2045
+ * I am ASSUMING this is what is meant to happen
2046
+ *
2047
+ */
2048
+ ProjectiveNielsPoint.prototype.conditional_negate = function (choice) {
2049
+ // this.Y_plus_X.conditional_negate( choice );
2050
+ // this.Y_minus_X.conditional_negate( choice );
2051
+ // this.Z.conditional_negate( choice );
2052
+ // this.T2d.conditional_negate( choice );
2053
+ // ??? WTF ???
2054
+ // ??? not even this works ???
2055
+ // ??? WHY ???
2056
+ //
2057
+ // if( choice )
2058
+ // {
2059
+ // (this as any).Y_plus_X = this.Y_plus_X.neg();
2060
+ // (this as any).Y_minus_X = this.Y_minus_X.neg();
2061
+ // (this as any).Z = this.Z.neg();
2062
+ // (this as any).T2d = this.T2d.neg();
2063
+ // }
2064
+ if (choice) {
2065
+ var neg = this.neg();
2066
+ this.Y_plus_X = neg.Y_plus_X;
2067
+ this.Y_minus_X = neg.Y_minus_X;
2068
+ this.Z = neg.Z;
2069
+ this.T2d = neg.T2d;
2070
+ }
2071
+ };
2072
+ /**
2073
+ *
2074
+ * I HAD TO FUCKING REVERSE ENGENEER THIS SHIT
2075
+ *
2076
+ * WHO THE FUCK TOUGHT MACROS WERE A GOOD IDEA IN RUST?
2077
+ */
2078
+ ProjectiveNielsPoint.prototype.neg = function () {
2079
+ return new ProjectiveNielsPoint(
2080
+ // swap places minus and plus
2081
+ this.Y_minus_X.clone(), this.Y_plus_X.clone(),
2082
+ // same Z
2083
+ this.Z.clone(),
2084
+ // negate T2d
2085
+ this.T2d.neg());
2086
+ };
2087
+ /*
2088
+ fn conditional_assign(&mut self, other: &Self, choice: Choice) {
2089
+ self.Y_plus_X.conditional_assign(&other.Y_plus_X, choice);
2090
+ self.Y_minus_X.conditional_assign(&other.Y_minus_X, choice);
2091
+ self.Z.conditional_assign(&other.Z, choice);
2092
+ self.T2d.conditional_assign(&other.T2d, choice);
2093
+ }
2094
+ */
2095
+ ProjectiveNielsPoint.prototype.conditional_assign = function (other, choice) {
2096
+ this.Y_plus_X.conditional_assign(other.Y_plus_X, choice);
2097
+ this.Y_minus_X.conditional_assign(other.Y_minus_X, choice);
2098
+ this.Z.conditional_assign(other.Z, choice);
2099
+ this.T2d.conditional_assign(other.T2d, choice);
2100
+ };
2101
+ /*
2102
+ fn from(P: &'a EdwardsPoint) -> Self {
2103
+ let mut points = [P.to_projective_niels(); $size];
2104
+ for j in $conv_range {
2105
+ points[j + 1] = (P + &points[j]).to_extended().to_projective_niels();
2106
+ }
2107
+ $name(points)
2108
+ }
2109
+ */
2110
+ ProjectiveNielsPoint.tableFromEdwardPoint = function (point) {
2111
+ var points = new Array(LookupTableProjectiveNielsPoint.SIZE).fill(0).map(function (_) { return point.toProjectiveNiels(); });
2112
+ for (var j = 0; j < LookupTableProjectiveNielsPoint.CONVERSION_RANGE_MAX; j++) {
2113
+ points[j + 1] = point.addProjectiveNiels(points[j]).toExtended().toProjectiveNiels();
2114
+ }
2115
+ return new LookupTableProjectiveNielsPoint(points);
2116
+ };
2117
+ return ProjectiveNielsPoint;
2118
+ }());
2119
+ exports.ProjectiveNielsPoint = ProjectiveNielsPoint;
2120
+ /*
2121
+ impl_lookup_table! {
2122
+ Name = LookupTable,
2123
+ Size = 8,
2124
+ SizeNeg = -8,
2125
+ SizeRange = 1 .. 9,
2126
+ ConversionRange = 0 .. 7
2127
+ } // radix-16
2128
+ */
2129
+ var LookupTableProjectiveNielsPoint = /** @class */ (function () {
2130
+ function LookupTableProjectiveNielsPoint(points) {
2131
+ this.points = points;
2132
+ }
2133
+ /*
2134
+ /// Given \\(-8 \leq x \leq 8\\), return \\(xP\\) in constant time.
2135
+ pub fn select(&self, x: i8) -> T {
2136
+ debug_assert!(x >= $neg);
2137
+ debug_assert!(x as i16 <= $size as i16); // XXX We have to convert to i16s here for the radix-256 case.. this is wrong.
2138
+
2139
+ // Compute xabs = |x|
2140
+ let xmask = x as i16 >> 7;
2141
+ let xabs = (x as i16 + xmask) ^ xmask;
2142
+
2143
+ // Set t = 0 * P = identity
2144
+ let mut t = T::identity();
2145
+ for j in $range {
2146
+ // Copy `points[j-1] == j*P` onto `t` in constant time if `|x| == j`.
2147
+ let c = (xabs as u16).ct_eq(&(j as u16));
2148
+ t.conditional_assign(&self.0[j - 1], c);
2149
+ }
2150
+ // Now t == |x| * P.
2151
+
2152
+ let neg_mask = Choice::from((xmask & 1) as u8);
2153
+ t.conditional_negate(neg_mask);
2154
+ // Now t == x * P.
2155
+
2156
+ t
2157
+ }
2158
+ */
2159
+ LookupTableProjectiveNielsPoint.prototype.select = function (pos) {
2160
+ var view = new DataView(new ArrayBuffer(2));
2161
+ view.setUint16(0, pos & 0xffff, false);
2162
+ var posI16 = view.getInt16(0, false);
2163
+ // const posU16 = view.getUint16( 0, false );
2164
+ var xmask = posI16 >> 7;
2165
+ var xabs = (posI16 + xmask) ^ xmask;
2166
+ var t = ProjectiveNielsPoint.identity();
2167
+ for (var j = LookupTableProjectiveNielsPoint.SIZE_RANGE_MIN; j <= LookupTableProjectiveNielsPoint.SIZE_RANGE_MAX; j++) {
2168
+ var c = xabs === j;
2169
+ t.conditional_assign(this.points[j - 1].clone(), c);
2170
+ }
2171
+ var neg_mask = xmask & 1;
2172
+ t.conditional_negate(neg_mask === 1);
2173
+ return t;
2174
+ };
2175
+ LookupTableProjectiveNielsPoint.SIZE = 8;
2176
+ LookupTableProjectiveNielsPoint.SIZE_NEG = -8;
2177
+ LookupTableProjectiveNielsPoint.SIZE_RANGE = [1, 2, 3, 4, 5, 6, 7, 8];
2178
+ LookupTableProjectiveNielsPoint.SIZE_RANGE_MIN = 1;
2179
+ LookupTableProjectiveNielsPoint.SIZE_RANGE_MAX = 8;
2180
+ LookupTableProjectiveNielsPoint.CONVERSION_RANGE = [0, 1, 2, 3, 4, 5, 6, 7];
2181
+ LookupTableProjectiveNielsPoint.CONVERSION_RANGE_MAX = 7;
2182
+ return LookupTableProjectiveNielsPoint;
2183
+ }());
2184
+ exports.LookupTableProjectiveNielsPoint = LookupTableProjectiveNielsPoint;
2185
+ /*
2186
+ pub(crate) fn to_radix_16(&self) -> [i8; 64] {
2187
+ debug_assert!(self[31] <= 127);
2188
+ let mut output = [0i8; 64];
2189
+
2190
+ // Step 1: change radix.
2191
+ // Convert from radix 256 (bytes) to radix 16 (nibbles)
2192
+ #[inline(always)]
2193
+ fn bot_half(x: u8) -> u8 { (x >> 0) & 15 }
2194
+ #[inline(always)]
2195
+ fn top_half(x: u8) -> u8 { (x >> 4) & 15 }
2196
+
2197
+ for i in 0..32 {
2198
+ output[2*i ] = bot_half(self[i]) as i8;
2199
+ output[2*i+1] = top_half(self[i]) as i8;
2200
+ }
2201
+ // Precondition note: since self[31] <= 127, output[63] <= 7
2202
+
2203
+ // Step 2: recenter coefficients from [0,16) to [-8,8)
2204
+ for i in 0..63 {
2205
+ let carry = (output[i] + 8) >> 4;
2206
+ output[i ] -= carry << 4;
2207
+ output[i+1] += carry;
2208
+ }
2209
+ // Precondition note: output[63] is not recentered. It
2210
+ // increases by carry <= 1. Thus output[63] <= 8.
2211
+
2212
+ output
2213
+ }
2214
+ */
2215
+ function scalar_to_radix_16(scalar) {
2216
+ var output = new Int8Array(64);
2217
+ var u8 = new Uint8Array(output.buffer);
2218
+ for (var i = 0; i < 32; i++) {
2219
+ u8[2 * i] = (scalar[i] >> 0) & 15;
2220
+ u8[2 * i + 1] = (scalar[i] >> 4) & 15;
2221
+ }
2222
+ for (var i = 0; i < 63; i++) {
2223
+ var carry = (output[i] + 8) >> 4;
2224
+ u8[i] -= (carry << 4) & 0xff;
2225
+ u8[i + 1] += (carry) & 0xff;
2226
+ }
2227
+ return output;
2228
+ }
2229
+ /*
2230
+ /// Attempt to decompress to an `EdwardsPoint`.
2231
+ ///
2232
+ /// Returns `None` if the input is not the \\(y\\)-coordinate of a
2233
+ /// curve point.
2234
+ pub fn decompress( bytes: [u8] ) -> Option<EdwardsPoint> {
2235
+ let Y = FieldElement::from_bytes( bytes );
2236
+ let Z = FieldElement::one();
2237
+ let YY = Y.square();
2238
+ let u = &YY - &Z; // u = y²-1
2239
+ let v = &(&YY * &constants::EDWARDS_D) + &Z; // v = dy²+1
2240
+ let (is_valid_y_coord, mut X) = FieldElement::sqrt_ratio_i(&u, &v);
2241
+
2242
+ if is_valid_y_coord.unwrap_u8() != 1u8 { return None; }
2243
+
2244
+ // FieldElement::sqrt_ratio_i always returns the nonnegative square root,
2245
+ // so we negate according to the supplied sign bit.
2246
+ let compressed_sign_bit = Choice::from(self.as_bytes()[31] >> 7);
2247
+ X.conditional_negate(compressed_sign_bit);
2248
+
2249
+ Some(EdwardsPoint{ X, Y, Z, T: &X * &Y })
2250
+ }
2251
+ */
2252
+ function decompressCompressedEdwardsY(bytes) {
2253
+ var Y = FieldElem51.fromBytes(bytes);
2254
+ var Z = FieldElem51.one();
2255
+ var YY = Y.square();
2256
+ var u = YY.sub(Z);
2257
+ var v = YY.mul(FieldElem51.EDWARDS_D).add(Z);
2258
+ var _a = __read(FieldElem51.sqrt_ratio_i(u, v), 2), is_valid_y_coord = _a[0], X = _a[1];
2259
+ if (is_valid_y_coord !== true)
2260
+ return undefined;
2261
+ var compressed_sign_bit = (bytes[31] >> 7) & 1;
2262
+ X.conditional_negate(compressed_sign_bit === 1);
2263
+ return new EdwardsPoint(X, Y, Z, X.mul(Y));
2264
+ }
2265
+ exports.decompressCompressedEdwardsY = decompressCompressedEdwardsY;
2266
+ var CompletedPoint = /** @class */ (function () {
2267
+ function CompletedPoint(X, Y, Z, T) {
2268
+ this.X = X;
2269
+ this.Y = Y;
2270
+ this.Z = Z;
2271
+ this.T = T;
2272
+ }
2273
+ CompletedPoint.prototype.clone = function () {
2274
+ return new CompletedPoint(this.X.clone(), this.Y.clone(), this.Z.clone(), this.T.clone());
2275
+ };
2276
+ /*
2277
+ pub fn to_projective(&self) -> ProjectivePoint {
2278
+ ProjectivePoint {
2279
+ X: &self.X * &self.T,
2280
+ Y: &self.Y * &self.Z,
2281
+ Z: &self.Z * &self.T,
2282
+ }
2283
+ }
2284
+ */
2285
+ CompletedPoint.prototype.toProjective = function () {
2286
+ return new ProjectivePoint(this.X.mul(this.T), this.Y.mul(this.Z), this.Z.mul(this.T));
2287
+ };
2288
+ /*
2289
+ pub fn to_extended(&self) -> EdwardsPoint {
2290
+ EdwardsPoint {
2291
+ X: &self.X * &self.T,
2292
+ Y: &self.Y * &self.Z,
2293
+ Z: &self.Z * &self.T,
2294
+ T: &self.X * &self.Y,
2295
+ }
2296
+ }
2297
+ */
2298
+ CompletedPoint.prototype.toExtended = function () {
2299
+ return new EdwardsPoint(this.X.mul(this.T), this.Y.mul(this.Z), this.Z.mul(this.T), this.X.mul(this.Y));
2300
+ };
2301
+ return CompletedPoint;
2302
+ }());
2303
+ exports.CompletedPoint = CompletedPoint;
2304
+ var ProjectivePoint = /** @class */ (function () {
2305
+ function ProjectivePoint(X, Y, Z) {
2306
+ this.X = X;
2307
+ this.Y = Y;
2308
+ this.Z = Z;
2309
+ }
2310
+ /*
2311
+ fn is_valid(&self) -> bool {
2312
+ // Curve equation is -x^2 + y^2 = 1 + d*x^2*y^2,
2313
+ // homogenized as (-X^2 + Y^2)*Z^2 = Z^4 + d*X^2*Y^2
2314
+ let XX = self.X.square();
2315
+ let YY = self.Y.square();
2316
+ let ZZ = self.Z.square();
2317
+ let ZZZZ = ZZ.square();
2318
+ let lhs = &(&YY - &XX) * &ZZ;
2319
+ let rhs = &ZZZZ + &(&constants::EDWARDS_D * &(&XX * &YY));
2320
+
2321
+ lhs == rhs
2322
+ }
2323
+ */
2324
+ ProjectivePoint.prototype.is_valid = function () {
2325
+ var XX = this.X.square();
2326
+ var YY = this.Y.square();
2327
+ var ZZ = this.Z.square();
2328
+ var ZZZZ = ZZ.square();
2329
+ var lhs = YY.sub(XX).mul(ZZ);
2330
+ var rhs = ZZZZ.add(FieldElem51.EDWARDS_D.mul(XX.mul(YY)));
2331
+ return lhs.ct_eq(rhs);
2332
+ };
2333
+ ProjectivePoint.prototype.clone = function () {
2334
+ return new ProjectivePoint(this.X.clone(), this.Y.clone(), this.Z.clone());
2335
+ };
2336
+ /*
2337
+ pub fn to_extended(&self) -> EdwardsPoint {
2338
+ EdwardsPoint {
2339
+ X: &self.X * &self.Z,
2340
+ Y: &self.Y * &self.Z,
2341
+ Z: self.Z.square(),
2342
+ T: &self.X * &self.Y,
2343
+ }
2344
+ }
2345
+ */
2346
+ ProjectivePoint.prototype.toExtended = function () {
2347
+ return new EdwardsPoint(this.X.mul(this.Z), this.Y.mul(this.Z), this.Z.square(), this.X.mul(this.Y));
2348
+ };
2349
+ Object.defineProperty(ProjectivePoint, "IDENTITY", {
2350
+ get: function () {
2351
+ return new ProjectivePoint(FieldElem51.zero(), FieldElem51.one(), FieldElem51.one());
2352
+ },
2353
+ enumerable: false,
2354
+ configurable: true
2355
+ });
2356
+ /*
2357
+ /// Double this point: return self + self
2358
+ pub fn double(&self) -> CompletedPoint { // Double()
2359
+ let XX = self.X.square();
2360
+ let YY = self.Y.square();
2361
+ let ZZ2 = self.Z.square2();
2362
+ let X_plus_Y = &self.X + &self.Y;
2363
+ let X_plus_Y_sq = X_plus_Y.square();
2364
+ let YY_plus_XX = &YY + &XX;
2365
+ let YY_minus_XX = &YY - &XX;
2366
+
2367
+ CompletedPoint{
2368
+ X: &X_plus_Y_sq - &YY_plus_XX,
2369
+ Y: YY_plus_XX,
2370
+ Z: YY_minus_XX,
2371
+ T: &ZZ2 - &YY_minus_XX
2372
+ }
2373
+ }
2374
+ */
2375
+ ProjectivePoint.prototype.double = function () {
2376
+ var XX = this.X.square();
2377
+ var YY = this.Y.square();
2378
+ var ZZ2 = this.Z.square2();
2379
+ var X_plus_Y = this.X.add(this.Y);
2380
+ var X_plus_Y_sq = X_plus_Y.square();
2381
+ var YY_plus_XX = YY.add(XX);
2382
+ var YY_minus_XX = YY.sub(XX);
2383
+ return new CompletedPoint(X_plus_Y_sq.sub(YY_plus_XX), YY_plus_XX, YY_minus_XX, ZZ2.sub(YY_minus_XX));
2384
+ };
2385
+ return ProjectivePoint;
2386
+ }());
2387
+ exports.ProjectivePoint = ProjectivePoint;
2388
+ /*
2389
+ #[inline]
2390
+ fn write_u64(buf: &mut [u8], n: u64) {
2391
+ buf[..8].copy_from_slice(&n.to_le_bytes());
2392
+ }
2393
+ fn from(x: u64) -> Scalar {
2394
+ use byteorder::{ByteOrder, LittleEndian};
2395
+ let mut s_bytes = [0u8; 32];
2396
+ LittleEndian::write_u64(&mut s_bytes, x);
2397
+ Scalar{ bytes: s_bytes }
2398
+ }
2399
+ */
2400
+ function scalar_from_u64(n) {
2401
+ n = BigInt(n);
2402
+ var s_bytes = new Uint8Array(32);
2403
+ var view = new DataView(s_bytes.buffer);
2404
+ view.setBigUint64(0, n, true);
2405
+ return s_bytes;
2406
+ }
2407
+ exports.scalar_from_u64 = scalar_from_u64;
2408
+ function scalar_from_bytes_mod_order_wide(input) {
2409
+ // UnpackedScalar::from_bytes_wide(input).pack()
2410
+ return pack_unpacked_scalar(unpacked_scalar_from_bytes_wide(input));
2411
+ }
2412
+ exports.scalar_from_bytes_mod_order_wide = scalar_from_bytes_mod_order_wide;
2413
+ function mul_scalars(a, b) {
2414
+ return pack_unpacked_scalar(mul_unpacked_scalars(unpacked_scalar_from_bytes(a), unpacked_scalar_from_bytes(b)));
2415
+ }
2416
+ exports.mul_scalars = mul_scalars;
2417
+ /*
2418
+ type Output = Scalar;
2419
+ #[allow(non_snake_case)]
2420
+ fn add(self, _rhs: &'b Scalar) -> Scalar {
2421
+ // The UnpackedScalar::add function produces reduced outputs
2422
+ // if the inputs are reduced. However, these inputs may not
2423
+ // be reduced -- they might come from Scalar::from_bits. So
2424
+ // after computing the sum, we explicitly reduce it mod l
2425
+ // before repacking.
2426
+ let sum = UnpackedScalar::add(&self.unpack(), &_rhs.unpack());
2427
+ let sum_R = UnpackedScalar::mul_internal(&sum, &constants::R);
2428
+ let sum_mod_l = UnpackedScalar::montgomery_reduce(&sum_R);
2429
+ sum_mod_l.pack()
2430
+ }
2431
+ */
2432
+ function add_scalars(a, b) {
2433
+ var sum = unpacked_scalar_add(unpacked_scalar_from_bytes(a), unpacked_scalar_from_bytes(b));
2434
+ var sum_R = scalar_mul_internal(sum, SCALAR_R);
2435
+ var sum_mod_l = scalar_montgomery_reduce(sum_R);
2436
+ return pack_unpacked_scalar(sum_mod_l);
2437
+ }
2438
+ exports.add_scalars = add_scalars;
2439
+ /*
2440
+ // Compute `a + b` (mod l)
2441
+ pub fn add(a: &Scalar52, b: &Scalar52) -> Scalar52 {
2442
+ let mut sum = Scalar52::zero();
2443
+ let mask = (1u64 << 52) - 1;
2444
+
2445
+ // a + b
2446
+ let mut carry: u64 = 0;
2447
+ for i in 0..5 {
2448
+ carry = a[i] + b[i] + (carry >> 52);
2449
+ sum[i] = carry & mask;
2450
+ }
2451
+
2452
+ // subtract l if the sum is >= l
2453
+ Scalar52::sub(&sum, &constants::L)
2454
+ }
2455
+ */
2456
+ function unpacked_scalar_add(a, b) {
2457
+ var sum = SCALAR_0.slice();
2458
+ var mask = LOW_52_BIT_MASK;
2459
+ var carry = _0n;
2460
+ for (var i = 0; i < 5; i++) {
2461
+ carry = a[i] + b[i] + (carry >> _52n);
2462
+ sum[i] = carry & mask;
2463
+ }
2464
+ return scalar_sub(sum, SCALAR_L);
2465
+ }
2466
+ /*
2467
+ /// Unpack a 32 byte / 256 bit scalar into 5 52-bit limbs.
2468
+ pub fn from_bytes(bytes: &[u8; 32]) -> Scalar52 {
2469
+ let mut words = [0u64; 4];
2470
+ for i in 0..4 {
2471
+ for j in 0..8 {
2472
+ words[i] |= (bytes[(i * 8) + j] as u64) << (j * 8);
2473
+ }
2474
+ }
2475
+
2476
+ let mask = (1u64 << 52) - 1;
2477
+ let top_mask = (1u64 << 48) - 1;
2478
+ let mut s = Scalar52::zero();
2479
+
2480
+ s[ 0] = words[0] & mask;
2481
+ s[ 1] = ((words[0] >> 52) | (words[1] << 12)) & mask;
2482
+ s[ 2] = ((words[1] >> 40) | (words[2] << 24)) & mask;
2483
+ s[ 3] = ((words[2] >> 28) | (words[3] << 36)) & mask;
2484
+ s[ 4] = (words[3] >> 16) & top_mask;
2485
+
2486
+ s
2487
+ }
2488
+ */
2489
+ function unpacked_scalar_from_bytes(input) {
2490
+ var words = new BigUint64Array(4);
2491
+ for (var i = 0; i < 4; i++) {
2492
+ for (var j = 0; j < 8; j++) {
2493
+ words[i] |= BigInt(input[(i * 8) + j]) << BigInt(j * 8);
2494
+ }
2495
+ }
2496
+ var mask = LOW_52_BIT_MASK;
2497
+ var top_mask = (_1n << BigInt(48)) - _1n;
2498
+ var s = SCALAR_0.slice();
2499
+ s[0] = words[0] & mask;
2500
+ s[1] = ((words[0] >> _52n) | (words[1] << BigInt(12))) & mask;
2501
+ s[2] = ((words[1] >> BigInt(40)) | (words[2] << BigInt(24))) & mask;
2502
+ s[3] = ((words[2] >> BigInt(28)) | (words[3] << BigInt(36))) & mask;
2503
+ s[4] = (words[3] >> BigInt(16)) & top_mask;
2504
+ return s;
2505
+ }
2506
+ exports.unpack_scalar = unpacked_scalar_from_bytes;
2507
+ /*
2508
+ #[inline(never)]
2509
+ pub fn mul(a: &Scalar52, b: &Scalar52) -> Scalar52 {
2510
+ let ab = Scalar52::montgomery_reduce(&Scalar52::mul_internal(a, b));
2511
+ Scalar52::montgomery_reduce(&Scalar52::mul_internal(&ab, &constants::RR))
2512
+ }
2513
+ */
2514
+ function mul_unpacked_scalars(a, b) {
2515
+ var ab = scalar_montgomery_reduce(scalar_mul_internal(a, b));
2516
+ return scalar_montgomery_reduce(scalar_mul_internal(ab, SCALAR_RR));
2517
+ }
2518
+ /*
2519
+ pub struct Scalar52(pub [u64; 5]);
2520
+
2521
+ /// Reduce a 64 byte / 512 bit scalar mod l
2522
+ pub fn from_bytes_wide(bytes: &[u8; 64]) -> Scalar52 {
2523
+ let mut words = [0u64; 8];
2524
+ for i in 0..8 {
2525
+ for j in 0..8 {
2526
+ words[i] |= (bytes[(i * 8) + j] as u64) << (j * 8);
2527
+ }
2528
+ }
2529
+
2530
+ let mask = (1u64 << 52) - 1;
2531
+ let mut lo = Scalar52::zero();
2532
+ let mut hi = Scalar52::zero();
2533
+
2534
+ lo[0] = words[ 0] & mask;
2535
+ lo[1] = ((words[ 0] >> 52) | (words[ 1] << 12)) & mask;
2536
+ lo[2] = ((words[ 1] >> 40) | (words[ 2] << 24)) & mask;
2537
+ lo[3] = ((words[ 2] >> 28) | (words[ 3] << 36)) & mask;
2538
+ lo[4] = ((words[ 3] >> 16) | (words[ 4] << 48)) & mask;
2539
+ hi[0] = (words[ 4] >> 4) & mask;
2540
+ hi[1] = ((words[ 4] >> 56) | (words[ 5] << 8)) & mask;
2541
+ hi[2] = ((words[ 5] >> 44) | (words[ 6] << 20)) & mask;
2542
+ hi[3] = ((words[ 6] >> 32) | (words[ 7] << 32)) & mask;
2543
+ hi[4] = words[ 7] >> 20 ;
2544
+
2545
+ lo = Scalar52::montgomery_mul(&lo, &constants::R); // (lo * R) / R = lo
2546
+ hi = Scalar52::montgomery_mul(&hi, &constants::RR); // (hi * R^2) / R = hi * R
2547
+
2548
+ Scalar52::add(&hi, &lo)
2549
+ }
2550
+
2551
+ */
2552
+ function unpacked_scalar_from_bytes_wide(input) {
2553
+ // UnpackedScalar::from_bytes_wide(input)
2554
+ var words = new BigUint64Array(8);
2555
+ for (var i = 0; i < 8; i++) {
2556
+ for (var j = 0; j < 8; j++) {
2557
+ words[i] |= BigInt(input[(i * 8) + j]) << BigInt((j * 8));
2558
+ }
2559
+ }
2560
+ var mask = LOW_52_BIT_MASK;
2561
+ var lo = new BigUint64Array(5);
2562
+ var hi = new BigUint64Array(5);
2563
+ lo[0] = words[0] & mask;
2564
+ lo[1] = ((words[0] >> _52n) | (words[1] << BigInt(12))) & mask;
2565
+ lo[2] = ((words[1] >> BigInt(40)) | (words[2] << BigInt(24))) & mask;
2566
+ lo[3] = ((words[2] >> BigInt(28)) | (words[3] << BigInt(36))) & mask;
2567
+ lo[4] = ((words[3] >> BigInt(16)) | (words[4] << BigInt(48))) & mask;
2568
+ hi[0] = (words[4] >> BigInt(4)) & mask;
2569
+ hi[1] = ((words[4] >> BigInt(56)) | (words[5] << BigInt(8))) & mask;
2570
+ hi[2] = ((words[5] >> BigInt(44)) | (words[6] << BigInt(20))) & mask;
2571
+ hi[3] = ((words[6] >> BigInt(32)) | (words[7] << BigInt(32))) & mask;
2572
+ hi[4] = words[7] >> BigInt(20);
2573
+ lo = scalar_montgomery_mul(lo, SCALAR_R);
2574
+ hi = scalar_montgomery_mul(hi, SCALAR_RR);
2575
+ return scalar_52_add(hi, lo);
2576
+ }
2577
+ exports.unpacked_scalar_from_bytes_wide = unpacked_scalar_from_bytes_wide;
2578
+ var SCALAR_R = new BigUint64Array([
2579
+ BigInt("0x000f48bd6721e6ed"),
2580
+ BigInt("0x0003bab5ac67e45a"),
2581
+ BigInt("0x000fffffeb35e51b"),
2582
+ BigInt("0x000fffffffffffff"),
2583
+ BigInt("0x00000fffffffffff"),
2584
+ ]);
2585
+ var SCALAR_RR = new BigUint64Array([
2586
+ BigInt("0x0009d265e952d13b"),
2587
+ BigInt("0x000d63c715bea69f"),
2588
+ BigInt("0x0005be65cb687604"),
2589
+ BigInt("0x0003dceec73d217f"),
2590
+ BigInt("0x000009411b7c309a"),
2591
+ ]);
2592
+ /*
2593
+ /// Compute `a + b` (mod l)
2594
+ pub fn add(a: &Scalar52, b: &Scalar52) -> Scalar52 {
2595
+ let mut sum = Scalar52::zero();
2596
+ let mask = (1u64 << 52) - 1;
2597
+
2598
+ // a + b
2599
+ let mut carry: u64 = 0;
2600
+ for i in 0..5 {
2601
+ carry = a[i] + b[i] + (carry >> 52);
2602
+ sum[i] = carry & mask;
2603
+ }
2604
+
2605
+ // subtract l if the sum is >= l
2606
+ Scalar52::sub(&sum, &constants::L)
2607
+ }
2608
+ */
2609
+ function scalar_52_add(a, b) {
2610
+ var sum = SCALAR_0.slice();
2611
+ var mask = LOW_52_BIT_MASK;
2612
+ var carry = _0n;
2613
+ for (var i = 0; i < 5; i++) {
2614
+ carry = a[i] + b[i] + (carry >> _52n);
2615
+ sum[i] = carry & mask;
2616
+ }
2617
+ return scalar_sub(sum, SCALAR_L);
2618
+ }
2619
+ function scalar_montgomery_mul(a, b) {
2620
+ return scalar_montgomery_reduce(scalar_mul_internal(a, b));
2621
+ }
2622
+ /*
2623
+ // Compute `limbs/R` (mod l), where R is the Montgomery modulus 2^260
2624
+ #[inline(always)]
2625
+ pub (crate) fn montgomery_reduce(limbs: &[u128; 9]) -> Scalar52 {
2626
+
2627
+ #[inline(always)]
2628
+ fn part1(sum: u128) -> (u128, u64) {
2629
+ let p = (sum as u64).wrapping_mul(constants::LFACTOR) & ((1u64 << 52) - 1);
2630
+ ((sum + m(p,constants::L[0])) >> 52, p)
2631
+ }
2632
+
2633
+ #[inline(always)]
2634
+ fn part2(sum: u128) -> (u128, u64) {
2635
+ let w = (sum as u64) & ((1u64 << 52) - 1);
2636
+ (sum >> 52, w)
2637
+ }
2638
+
2639
+ // note: l[3] is zero, so its multiples can be skipped
2640
+ let l = &constants::L;
2641
+
2642
+ // the first half computes the Montgomery adjustment factor n, and begins adding n*l to make limbs divisible by R
2643
+ let (carry, n0) = part1( limbs[0]);
2644
+ let (carry, n1) = part1(carry + limbs[1] + m(n0,l[1]));
2645
+ let (carry, n2) = part1(carry + limbs[2] + m(n0,l[2]) + m(n1,l[1]));
2646
+ let (carry, n3) = part1(carry + limbs[3] + m(n1,l[2]) + m(n2,l[1]));
2647
+ let (carry, n4) = part1(carry + limbs[4] + m(n0,l[4]) + m(n2,l[2]) + m(n3,l[1]));
2648
+
2649
+ // limbs is divisible by R now, so we can divide by R by simply storing the upper half as the result
2650
+ let (carry, r0) = part2(carry + limbs[5] + m(n1,l[4]) + m(n3,l[2]) + m(n4,l[1]));
2651
+ let (carry, r1) = part2(carry + limbs[6] + m(n2,l[4]) + m(n4,l[2]));
2652
+ let (carry, r2) = part2(carry + limbs[7] + m(n3,l[4]) );
2653
+ let (carry, r3) = part2(carry + limbs[8] + m(n4,l[4]));
2654
+ let r4 = carry as u64;
2655
+
2656
+ // result may be >= l, so attempt to subtract l
2657
+ Scalar52::sub(&Scalar52([r0,r1,r2,r3,r4]), l)
2658
+ }
2659
+
2660
+ */
2661
+ function scalar_montgomery_reduce(limbs) {
2662
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2663
+ var l = SCALAR_L.slice();
2664
+ var carry, n0, n1, n2, n3, n4, r0, r1, r2, r3, r4;
2665
+ _a = __read(smr_part1(limbs[0]), 2), carry = _a[0], n0 = _a[1];
2666
+ _b = __read(smr_part1(carry + limbs[1] + (n0 * l[1])), 2), carry = _b[0], n1 = _b[1];
2667
+ _c = __read(smr_part1(carry + limbs[2] + (n0 * l[2]) + (n1 * l[1])), 2), carry = _c[0], n2 = _c[1];
2668
+ _d = __read(smr_part1(carry + limbs[3] + (n1 * l[2]) + (n2 * l[1])), 2), carry = _d[0], n3 = _d[1];
2669
+ _e = __read(smr_part1(carry + limbs[4] + (n0 * l[4]) + (n2 * l[2]) + (n3 * l[1])), 2), carry = _e[0], n4 = _e[1];
2670
+ _f = __read(smr_part2(carry + limbs[5] + (n1 * l[4]) + (n3 * l[2]) + (n4 * l[1])), 2), carry = _f[0], r0 = _f[1];
2671
+ _g = __read(smr_part2(carry + limbs[6] + (n2 * l[4]) + (n4 * l[2])), 2), carry = _g[0], r1 = _g[1];
2672
+ _h = __read(smr_part2(carry + limbs[7] + (n3 * l[4])), 2), carry = _h[0], r2 = _h[1];
2673
+ _j = __read(smr_part2(carry + limbs[8] + (n4 * l[4])), 2), carry = _j[0], r3 = _j[1];
2674
+ r4 = carry & LOW_64_BIT_MASK;
2675
+ return scalar_sub(new BigUint64Array([r0, r1, r2, r3, r4]), l);
2676
+ }
2677
+ function smr_part1(sum) {
2678
+ var p = rust_u64_wrapping_mul(sum, LFACTOR) & LOW_52_BIT_MASK;
2679
+ return [
2680
+ (sum + (p * SCALAR_L[0])) >> _52n,
2681
+ p
2682
+ ];
2683
+ }
2684
+ function smr_part2(sum) {
2685
+ var w = sum & LOW_52_BIT_MASK;
2686
+ return [
2687
+ sum >> _52n,
2688
+ w
2689
+ ];
2690
+ }
2691
+ var U64_PLUS_ONE = _1n << _64n;
2692
+ function rust_u64_wrapping_mul(a, b) {
2693
+ // Convert inputs to BigInt and perform multiplication
2694
+ return (a * b) % U64_PLUS_ONE;
2695
+ }
2696
+ /*
2697
+ /// Compute `a - b` (mod l)
2698
+ pub fn sub(a: &Scalar52, b: &Scalar52) -> Scalar52 {
2699
+ let mut difference = Scalar52::zero();
2700
+ let mask = (1u64 << 52) - 1;
2701
+
2702
+ // a - b
2703
+ let mut borrow: u64 = 0;
2704
+ for i in 0..5 {
2705
+ borrow = a[i].wrapping_sub(b[i] + (borrow >> 63));
2706
+ difference[i] = borrow & mask;
2707
+ }
2708
+
2709
+ // conditionally add l if the difference is negative
2710
+ let underflow_mask = ((borrow >> 63) ^ 1).wrapping_sub(1);
2711
+ let mut carry: u64 = 0;
2712
+ for i in 0..5 {
2713
+ carry = (carry >> 52) + difference[i] + (constants::L[i] & underflow_mask);
2714
+ difference[i] = carry & mask;
2715
+ }
2716
+
2717
+ difference
2718
+ }
2719
+ */
2720
+ function scalar_sub(a, b) {
2721
+ var difference = SCALAR_0.slice();
2722
+ var mask = LOW_52_BIT_MASK;
2723
+ var borrow = _0n;
2724
+ for (var i = 0; i < 5; i++) {
2725
+ borrow = rust_u64_wrapping_sub(a[i], (b[i] + (borrow >> BigInt(63))));
2726
+ difference[i] = borrow & mask;
2727
+ }
2728
+ // conditionally add l if the difference is negative
2729
+ var underflow_mask = rust_u64_wrapping_sub((borrow >> BigInt(63)) ^ _1n, _1n);
2730
+ var carry = _0n;
2731
+ for (var i = 0; i < 5; i++) {
2732
+ carry = (carry >> _52n) + difference[i] + (SCALAR_L[i] & underflow_mask);
2733
+ difference[i] = carry & mask;
2734
+ }
2735
+ return difference;
2736
+ }
2737
+ /**
2738
+ * ```rs
2739
+ * pub const fn wrapping_sub_signed(self, rhs: i64) -> u64
2740
+ * ```
2741
+ */
2742
+ function rust_u64_wrapping_sub(self, rhs) {
2743
+ var U64_MAX = LOW_64_BIT_MASK; // 2^64 - 1, max value of u64
2744
+ // Convert inputs to BigInt
2745
+ var result = BigInt(self) - BigInt(rhs);
2746
+ // Wrap around if out of bounds
2747
+ if (result < _0n) {
2748
+ result += U64_MAX + _1n; // Wrap from negative to upper bound
2749
+ }
2750
+ else if (result > U64_MAX) {
2751
+ result %= U64_MAX + _1n; // Wrap around on overflow
2752
+ }
2753
+ return result;
2754
+ }
2755
+ var SCALAR_0 = new BigUint64Array(5).fill(_0n);
2756
+ var SCALAR_L = new BigUint64Array([
2757
+ BigInt("0x0002631a5cf5d3ed"),
2758
+ BigInt("0x000dea2f79cd6581"),
2759
+ BigInt("0x000000000014def9"),
2760
+ BigInt("0x0000000000000000"),
2761
+ BigInt("0x0000100000000000"),
2762
+ ]);
2763
+ var LFACTOR = BigInt("0x51da312547e1b");
2764
+ /*
2765
+ #[inline(always)]
2766
+ fn m(x: u64, y: u64) -> u128 {
2767
+ (x as u128) * (y as u128)
2768
+ }
2769
+ /// Compute `a * b`
2770
+ #[inline(always)]
2771
+ pub (crate) fn mul_internal(a: &Scalar52, b: &Scalar52) -> [u128; 9] {
2772
+ let mut z = [0u128; 9];
2773
+
2774
+ z[0] = m(a[0],b[0]);
2775
+ z[1] = m(a[0],b[1]) + m(a[1],b[0]);
2776
+ z[2] = m(a[0],b[2]) + m(a[1],b[1]) + m(a[2],b[0]);
2777
+ z[3] = m(a[0],b[3]) + m(a[1],b[2]) + m(a[2],b[1]) + m(a[3],b[0]);
2778
+ z[4] = m(a[0],b[4]) + m(a[1],b[3]) + m(a[2],b[2]) + m(a[3],b[1]) + m(a[4],b[0]);
2779
+ z[5] = m(a[1],b[4]) + m(a[2],b[3]) + m(a[3],b[2]) + m(a[4],b[1]);
2780
+ z[6] = m(a[2],b[4]) + m(a[3],b[3]) + m(a[4],b[2]);
2781
+ z[7] = m(a[3],b[4]) + m(a[4],b[3]);
2782
+ z[8] = m(a[4],b[4]);
2783
+
2784
+ z
2785
+ }
2786
+ */
2787
+ function scalar_mul_internal(a, b) {
2788
+ var z = new Array(9);
2789
+ z[0] = a[0] * b[0];
2790
+ z[1] = a[0] * b[1] + a[1] * b[0];
2791
+ z[2] = a[0] * b[2] + a[1] * b[1] + a[2] * b[0];
2792
+ z[3] = a[0] * b[3] + a[1] * b[2] + a[2] * b[1] + a[3] * b[0];
2793
+ z[4] = a[0] * b[4] + a[1] * b[3] + a[2] * b[2] + a[3] * b[1] + a[4] * b[0];
2794
+ z[5] = a[1] * b[4] + a[2] * b[3] + a[3] * b[2] + a[4] * b[1];
2795
+ z[6] = a[2] * b[4] + a[3] * b[3] + a[4] * b[2];
2796
+ z[7] = a[3] * b[4] + a[4] * b[3];
2797
+ z[8] = a[4] * b[4];
2798
+ return z;
2799
+ }
2800
+ /*
2801
+ /// Pack the limbs of this `Scalar52` into 32 bytes
2802
+ pub fn to_bytes(&self) -> [u8; 32] {
2803
+ let mut s = [0u8; 32];
2804
+
2805
+ s[0] = (self.0[ 0] >> 0) as u8;
2806
+ s[1] = (self.0[ 0] >> 8) as u8;
2807
+ s[2] = (self.0[ 0] >> 16) as u8;
2808
+ s[3] = (self.0[ 0] >> 24) as u8;
2809
+ s[4] = (self.0[ 0] >> 32) as u8;
2810
+ s[5] = (self.0[ 0] >> 40) as u8;
2811
+ s[6] = ((self.0[ 0] >> 48) | (self.0[ 1] << 4)) as u8;
2812
+ s[7] = (self.0[ 1] >> 4) as u8;
2813
+ s[8] = (self.0[ 1] >> 12) as u8;
2814
+ s[9] = (self.0[ 1] >> 20) as u8;
2815
+ s[10] = (self.0[ 1] >> 28) as u8;
2816
+ s[11] = (self.0[ 1] >> 36) as u8;
2817
+ s[12] = (self.0[ 1] >> 44) as u8;
2818
+ s[13] = (self.0[ 2] >> 0) as u8;
2819
+ s[14] = (self.0[ 2] >> 8) as u8;
2820
+ s[15] = (self.0[ 2] >> 16) as u8;
2821
+ s[16] = (self.0[ 2] >> 24) as u8;
2822
+ s[17] = (self.0[ 2] >> 32) as u8;
2823
+ s[18] = (self.0[ 2] >> 40) as u8;
2824
+ s[19] = ((self.0[ 2] >> 48) | (self.0[ 3] << 4)) as u8;
2825
+ s[20] = (self.0[ 3] >> 4) as u8;
2826
+ s[21] = (self.0[ 3] >> 12) as u8;
2827
+ s[22] = (self.0[ 3] >> 20) as u8;
2828
+ s[23] = (self.0[ 3] >> 28) as u8;
2829
+ s[24] = (self.0[ 3] >> 36) as u8;
2830
+ s[25] = (self.0[ 3] >> 44) as u8;
2831
+ s[26] = (self.0[ 4] >> 0) as u8;
2832
+ s[27] = (self.0[ 4] >> 8) as u8;
2833
+ s[28] = (self.0[ 4] >> 16) as u8;
2834
+ s[29] = (self.0[ 4] >> 24) as u8;
2835
+ s[30] = (self.0[ 4] >> 32) as u8;
2836
+ s[31] = (self.0[ 4] >> 40) as u8;
2837
+
2838
+ s
2839
+ }
2840
+ */
2841
+ function pack_unpacked_scalar(input) {
2842
+ var s = new Uint8Array(32);
2843
+ var u8mask = BigInt(0xff);
2844
+ s[0] = Number((input[0] >> _0n) & u8mask);
2845
+ s[1] = Number((input[0] >> BigInt(8)) & u8mask);
2846
+ s[2] = Number((input[0] >> BigInt(16)) & u8mask);
2847
+ s[3] = Number((input[0] >> BigInt(24)) & u8mask);
2848
+ s[4] = Number((input[0] >> BigInt(32)) & u8mask);
2849
+ s[5] = Number((input[0] >> BigInt(40)) & u8mask);
2850
+ s[6] = Number(((input[0] >> BigInt(48)) | (input[1] << BigInt(4))) & u8mask);
2851
+ s[7] = Number((input[1] >> BigInt(4)) & u8mask);
2852
+ s[8] = Number((input[1] >> BigInt(12)) & u8mask);
2853
+ s[9] = Number((input[1] >> BigInt(20)) & u8mask);
2854
+ s[10] = Number((input[1] >> BigInt(28)) & u8mask);
2855
+ s[11] = Number((input[1] >> BigInt(36)) & u8mask);
2856
+ s[12] = Number((input[1] >> BigInt(44)) & u8mask);
2857
+ s[13] = Number((input[2] >> _0n) & u8mask);
2858
+ s[14] = Number((input[2] >> BigInt(8)) & u8mask);
2859
+ s[15] = Number((input[2] >> BigInt(16)) & u8mask);
2860
+ s[16] = Number((input[2] >> BigInt(24)) & u8mask);
2861
+ s[17] = Number((input[2] >> BigInt(32)) & u8mask);
2862
+ s[18] = Number((input[2] >> BigInt(40)) & u8mask);
2863
+ s[19] = Number(((input[2] >> BigInt(48)) | (input[3] << BigInt(4))) & u8mask);
2864
+ s[20] = Number((input[3] >> BigInt(4)) & u8mask);
2865
+ s[21] = Number((input[3] >> BigInt(12)) & u8mask);
2866
+ s[22] = Number((input[3] >> BigInt(20)) & u8mask);
2867
+ s[23] = Number((input[3] >> BigInt(28)) & u8mask);
2868
+ s[24] = Number((input[3] >> BigInt(36)) & u8mask);
2869
+ s[25] = Number((input[3] >> BigInt(44)) & u8mask);
2870
+ s[26] = Number((input[4] >> _0n) & u8mask);
2871
+ s[27] = Number((input[4] >> BigInt(8)) & u8mask);
2872
+ s[28] = Number((input[4] >> BigInt(16)) & u8mask);
2873
+ s[29] = Number((input[4] >> BigInt(24)) & u8mask);
2874
+ s[30] = Number((input[4] >> BigInt(32)) & u8mask);
2875
+ s[31] = Number((input[4] >> BigInt(40)) & u8mask);
2876
+ return s;
2877
+ }
2878
+ exports.pack_unpacked_scalar = pack_unpacked_scalar;
2879
+ /*
2880
+ #[allow(non_snake_case)]
2881
+ fn neg(self) -> Scalar {
2882
+ let self_R = UnpackedScalar::mul_internal(&self.unpack(), &constants::R);
2883
+ let self_mod_l = UnpackedScalar::montgomery_reduce(&self_R);
2884
+ UnpackedScalar::sub(&UnpackedScalar::zero(), &self_mod_l).pack()
2885
+ }
2886
+ }
2887
+ */
2888
+ function negate_scalar(scalar) {
2889
+ var self_R = scalar_mul_internal(unpacked_scalar_from_bytes(scalar), SCALAR_R);
2890
+ var self_mod_l = scalar_montgomery_reduce(self_R);
2891
+ return pack_unpacked_scalar(scalar_sub(SCALAR_0, self_mod_l));
2892
+ }
2893
+ exports.negate_scalar = negate_scalar;
2894
+ /*
2895
+ pub(crate) fn non_adjacent_form(&self, w: usize) -> [i8; 256] {
2896
+ // required by the NAF definition
2897
+ debug_assert!( w >= 2 );
2898
+ // required so that the NAF digits fit in i8
2899
+ debug_assert!( w <= 8 );
2900
+
2901
+ use byteorder::{ByteOrder, LittleEndian};
2902
+
2903
+ let mut naf = [0i8; 256];
2904
+
2905
+ let mut x_u64 = [0u64; 5];
2906
+ LittleEndian::read_u64_into(&self.bytes, &mut x_u64[0..4]);
2907
+
2908
+ let width = 1 << w;
2909
+ let window_mask = width - 1;
2910
+
2911
+ let mut pos = 0;
2912
+ let mut carry = 0;
2913
+ while pos < 256 {
2914
+ // Construct a buffer of bits of the scalar, starting at bit `pos`
2915
+ let u64_idx = pos / 64;
2916
+ let bit_idx = pos % 64;
2917
+ let bit_buf: u64;
2918
+ if bit_idx < 64 - w {
2919
+ // This window's bits are contained in a single u64
2920
+ bit_buf = x_u64[u64_idx] >> bit_idx;
2921
+ } else {
2922
+ // Combine the current u64's bits with the bits from the next u64
2923
+ bit_buf = (x_u64[u64_idx] >> bit_idx) | (x_u64[1+u64_idx] << (64 - bit_idx));
2924
+ }
2925
+
2926
+ // Add the carry into the current window
2927
+ let window = carry + (bit_buf & window_mask);
2928
+
2929
+ if window & 1 == 0 {
2930
+ // If the window value is even, preserve the carry and continue.
2931
+ // Why is the carry preserved?
2932
+ // If carry == 0 and window & 1 == 0, then the next carry should be 0
2933
+ // If carry == 1 and window & 1 == 0, then bit_buf & 1 == 1 so the next carry should be 1
2934
+ pos += 1;
2935
+ continue;
2936
+ }
2937
+
2938
+ if window < width/2 {
2939
+ carry = 0;
2940
+ naf[pos] = window as i8;
2941
+ } else {
2942
+ carry = 1;
2943
+ naf[pos] = (window as i8).wrapping_sub(width as i8);
2944
+ }
2945
+
2946
+ pos += w;
2947
+ }
2948
+
2949
+ naf
2950
+ }
2951
+ */
2952
+ function scalar_non_adjacent_form(scalar, w) {
2953
+ // required by the NAF definition
2954
+ if (w < 2)
2955
+ throw new Error("w must be >= 2");
2956
+ // required so that the NAF digits fit in i8
2957
+ if (w > 8)
2958
+ throw new Error("w must be <= 8");
2959
+ var naf = new Int8Array(256);
2960
+ var naf_u8 = new Uint8Array(naf.buffer);
2961
+ var x_u64 = new BigUint64Array(5);
2962
+ // LittleEndian::read_u64_into(&self.bytes, &mut x_u64[0..4]);
2963
+ read_u64_into_LE(scalar, x_u64, 4);
2964
+ var width = _1n << BigInt(w);
2965
+ var window_mask = width - _1n;
2966
+ var pos = 0;
2967
+ var carry = _0n;
2968
+ while (pos < 256) {
2969
+ var u64_idx = (pos / 64) >>> 0;
2970
+ var bit_idx = pos % 64;
2971
+ var bit_buf = void 0;
2972
+ if (bit_idx < 64 - w)
2973
+ bit_buf = x_u64[u64_idx] >> BigInt(bit_idx);
2974
+ else
2975
+ bit_buf = (x_u64[u64_idx] >> BigInt(bit_idx)) | (x_u64[1 + u64_idx] << BigInt(64 - bit_idx));
2976
+ var window_1 = carry + (bit_buf & window_mask);
2977
+ if ((window_1 & _1n) === _0n) {
2978
+ // If the window value is even, preserve the carry and continue.
2979
+ // Why is the carry preserved?
2980
+ // If carry == 0 and window & 1 == 0, then the next carry should be 0
2981
+ // If carry == 1 and window & 1 == 0, then bit_buf & 1 == 1 so the next carry should be 1
2982
+ pos += 1;
2983
+ continue;
2984
+ }
2985
+ if (window_1 < (width / BigInt(2))) {
2986
+ carry = _0n;
2987
+ naf_u8[pos] = Number(window_1) & 0xff;
2988
+ }
2989
+ else {
2990
+ carry = _1n;
2991
+ naf_u8[pos] = (Number(window_1) - Number(width)) & 0xff;
2992
+ }
2993
+ pos += w;
2994
+ }
2995
+ return naf;
2996
+ }
2997
+ function read_u64_into_LE(src, dst, dst_len) {
2998
+ if (dst_len === void 0) { dst_len = (Math.min(dst.length * 8, src.length) / 8) >>> 0; }
2999
+ if (src.length > dst.length * 8) {
3000
+ throw new Error("Source and destination size mismatch");
3001
+ }
3002
+ var srcView = new DataView(src.buffer, src.byteOffset, src.byteLength);
3003
+ var dstView = new DataView(dst.buffer, dst.byteOffset, dst.byteLength);
3004
+ for (var i = 0; i < dst_len; i++) {
3005
+ dstView.setBigUint64(i * 8, srcView.getBigUint64(i * 8, true), true);
3006
+ }
3007
+ }
3008
+ var AFFINE_ODD_MULTIPLES_OF_BASEPOINT = new NafLookupTable([
3009
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3010
+ BigInt("3540182452943730"),
3011
+ BigInt("2497478415033846"),
3012
+ BigInt("2521227595762870"),
3013
+ BigInt("1462984067271729"),
3014
+ BigInt("2389212253076811"),
3015
+ ])), new FieldElem51(new BigUint64Array([
3016
+ BigInt("62697248952638"),
3017
+ BigInt("204681361388450"),
3018
+ BigInt("631292143396476"),
3019
+ BigInt("338455783676468"),
3020
+ BigInt("1213667448819585"),
3021
+ ])), new FieldElem51(new BigUint64Array([
3022
+ BigInt("301289933810280"),
3023
+ BigInt("1259582250014073"),
3024
+ BigInt("1422107436869536"),
3025
+ BigInt("796239922652654"),
3026
+ BigInt("1953934009299142"),
3027
+ ]))),
3028
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3029
+ BigInt("1601611775252272"),
3030
+ BigInt("1720807796594148"),
3031
+ BigInt("1132070835939856"),
3032
+ BigInt("3512254832574799"),
3033
+ BigInt("2147779492816910"),
3034
+ ])), new FieldElem51(new BigUint64Array([
3035
+ BigInt("316559037616741"),
3036
+ BigInt("2177824224946892"),
3037
+ BigInt("1459442586438991"),
3038
+ BigInt("1461528397712656"),
3039
+ BigInt("751590696113597"),
3040
+ ])), new FieldElem51(new BigUint64Array([
3041
+ BigInt("1850748884277385"),
3042
+ BigInt("1200145853858453"),
3043
+ BigInt("1068094770532492"),
3044
+ BigInt("672251375690438"),
3045
+ BigInt("1586055907191707"),
3046
+ ]))),
3047
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3048
+ BigInt("769950342298400"),
3049
+ BigInt("2384754244604994"),
3050
+ BigInt("3095885746880802"),
3051
+ BigInt("3225892188161580"),
3052
+ BigInt("2977876099231263"),
3053
+ ])), new FieldElem51(new BigUint64Array([
3054
+ BigInt("425251763115706"),
3055
+ BigInt("608463272472562"),
3056
+ BigInt("442562545713235"),
3057
+ BigInt("837766094556764"),
3058
+ BigInt("374555092627893"),
3059
+ ])), new FieldElem51(new BigUint64Array([
3060
+ BigInt("1086255230780037"),
3061
+ BigInt("274979815921559"),
3062
+ BigInt("1960002765731872"),
3063
+ BigInt("929474102396301"),
3064
+ BigInt("1190409889297339"),
3065
+ ]))),
3066
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3067
+ BigInt("2916800678241215"),
3068
+ BigInt("2065379846933858"),
3069
+ BigInt("2622030924071124"),
3070
+ BigInt("2602788184473875"),
3071
+ BigInt("1233371373142984"),
3072
+ ])), new FieldElem51(new BigUint64Array([
3073
+ BigInt("2019367628972465"),
3074
+ BigInt("676711900706637"),
3075
+ BigInt("110710997811333"),
3076
+ BigInt("1108646842542025"),
3077
+ BigInt("517791959672113"),
3078
+ ])), new FieldElem51(new BigUint64Array([
3079
+ BigInt("965130719900578"),
3080
+ BigInt("247011430587952"),
3081
+ BigInt("526356006571389"),
3082
+ BigInt("91986625355052"),
3083
+ BigInt("2157223321444601"),
3084
+ ]))),
3085
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3086
+ BigInt("1802695059464988"),
3087
+ BigInt("1664899123557221"),
3088
+ BigInt("2845359304426105"),
3089
+ BigInt("2160434469266658"),
3090
+ BigInt("3179370264440279"),
3091
+ ])), new FieldElem51(new BigUint64Array([
3092
+ BigInt("1725674970513508"),
3093
+ BigInt("1933645953859181"),
3094
+ BigInt("1542344539275782"),
3095
+ BigInt("1767788773573747"),
3096
+ BigInt("1297447965928905"),
3097
+ ])), new FieldElem51(new BigUint64Array([
3098
+ BigInt("1381809363726107"),
3099
+ BigInt("1430341051343062"),
3100
+ BigInt("2061843536018959"),
3101
+ BigInt("1551778050872521"),
3102
+ BigInt("2036394857967624"),
3103
+ ]))),
3104
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3105
+ BigInt("4222693909998302"),
3106
+ BigInt("2779866139518454"),
3107
+ BigInt("1619374932191226"),
3108
+ BigInt("2207306624415883"),
3109
+ BigInt("1169170329061080"),
3110
+ ])), new FieldElem51(new BigUint64Array([
3111
+ BigInt("2070390218572616"),
3112
+ BigInt("1458919061857835"),
3113
+ BigInt("624171843017421"),
3114
+ BigInt("1055332792707765"),
3115
+ BigInt("433987520732508"),
3116
+ ])), new FieldElem51(new BigUint64Array([
3117
+ BigInt("893653801273833"),
3118
+ BigInt("1168026499324677"),
3119
+ BigInt("1242553501121234"),
3120
+ BigInt("1306366254304474"),
3121
+ BigInt("1086752658510815"),
3122
+ ]))),
3123
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3124
+ BigInt("2465253816303469"),
3125
+ BigInt("3191571337672685"),
3126
+ BigInt("1159882208056013"),
3127
+ BigInt("2569188183312765"),
3128
+ BigInt("621213314200686"),
3129
+ ])), new FieldElem51(new BigUint64Array([
3130
+ BigInt("1971678598905747"),
3131
+ BigInt("338026507889165"),
3132
+ BigInt("762398079972271"),
3133
+ BigInt("655096486107477"),
3134
+ BigInt("42299032696322"),
3135
+ ])), new FieldElem51(new BigUint64Array([
3136
+ BigInt("177130678690680"),
3137
+ BigInt("1754759263300204"),
3138
+ BigInt("1864311296286618"),
3139
+ BigInt("1180675631479880"),
3140
+ BigInt("1292726903152791"),
3141
+ ]))),
3142
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3143
+ BigInt("1913163449625248"),
3144
+ BigInt("2712579013977241"),
3145
+ BigInt("2193883288642313"),
3146
+ BigInt("1008900146920800"),
3147
+ BigInt("1721983679009502"),
3148
+ ])), new FieldElem51(new BigUint64Array([
3149
+ BigInt("1070401523076875"),
3150
+ BigInt("1272492007800961"),
3151
+ BigInt("1910153608563310"),
3152
+ BigInt("2075579521696771"),
3153
+ BigInt("1191169788841221"),
3154
+ ])), new FieldElem51(new BigUint64Array([
3155
+ BigInt("692896803108118"),
3156
+ BigInt("500174642072499"),
3157
+ BigInt("2068223309439677"),
3158
+ BigInt("1162190621851337"),
3159
+ BigInt("1426986007309901"),
3160
+ ]))),
3161
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3162
+ BigInt("1819621230288238"),
3163
+ BigInt("2735700366193240"),
3164
+ BigInt("1755134670739586"),
3165
+ BigInt("3080648199451191"),
3166
+ BigInt("4172807995775876"),
3167
+ ])), new FieldElem51(new BigUint64Array([
3168
+ BigInt("992069868904071"),
3169
+ BigInt("799011518185730"),
3170
+ BigInt("1777586403832768"),
3171
+ BigInt("1134820506145684"),
3172
+ BigInt("1999461475558530"),
3173
+ ])), new FieldElem51(new BigUint64Array([
3174
+ BigInt("425204543703124"),
3175
+ BigInt("2040469794090382"),
3176
+ BigInt("1651690622153809"),
3177
+ BigInt("1500530168597569"),
3178
+ BigInt("1253908377065966"),
3179
+ ]))),
3180
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3181
+ BigInt("2105824306960939"),
3182
+ BigInt("1387520302709358"),
3183
+ BigInt("3633176580451016"),
3184
+ BigInt("2211816663841753"),
3185
+ BigInt("1629085891776489"),
3186
+ ])), new FieldElem51(new BigUint64Array([
3187
+ BigInt("1485201376284999"),
3188
+ BigInt("1022406647424656"),
3189
+ BigInt("504181009209019"),
3190
+ BigInt("962621520820995"),
3191
+ BigInt("590876713147230"),
3192
+ ])), new FieldElem51(new BigUint64Array([
3193
+ BigInt("265873406365287"),
3194
+ BigInt("1192742653492898"),
3195
+ BigInt("88553098803050"),
3196
+ BigInt("525037770869640"),
3197
+ BigInt("1266933811251234"),
3198
+ ]))),
3199
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3200
+ BigInt("3552316659826612"),
3201
+ BigInt("1254279525791875"),
3202
+ BigInt("1609927932077699"),
3203
+ BigInt("3578654071679972"),
3204
+ BigInt("3750681296069893"),
3205
+ ])), new FieldElem51(new BigUint64Array([
3206
+ BigInt("37186803519861"),
3207
+ BigInt("1404297334376301"),
3208
+ BigInt("578519728836650"),
3209
+ BigInt("1740727951192592"),
3210
+ BigInt("2095534282477028"),
3211
+ ])), new FieldElem51(new BigUint64Array([
3212
+ BigInt("833234263154399"),
3213
+ BigInt("2023862470013762"),
3214
+ BigInt("1854137933982069"),
3215
+ BigInt("853924318090959"),
3216
+ BigInt("1589812702805850"),
3217
+ ]))),
3218
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3219
+ BigInt("3679150557957763"),
3220
+ BigInt("1319179453661745"),
3221
+ BigInt("497496853611112"),
3222
+ BigInt("2665464286942351"),
3223
+ BigInt("1208137952365560"),
3224
+ ])), new FieldElem51(new BigUint64Array([
3225
+ BigInt("1654513078530905"),
3226
+ BigInt("907489875842908"),
3227
+ BigInt("126098711296368"),
3228
+ BigInt("1726320004173677"),
3229
+ BigInt("28269495058173"),
3230
+ ])), new FieldElem51(new BigUint64Array([
3231
+ BigInt("114436686957443"),
3232
+ BigInt("532739313025996"),
3233
+ BigInt("115428841215897"),
3234
+ BigInt("2191499400074366"),
3235
+ BigInt("370280402676434"),
3236
+ ]))),
3237
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3238
+ BigInt("1111146849833253"),
3239
+ BigInt("2016430049079759"),
3240
+ BigInt("1860522747477948"),
3241
+ BigInt("3537164738290194"),
3242
+ BigInt("4137142824844184"),
3243
+ ])), new FieldElem51(new BigUint64Array([
3244
+ BigInt("429069864577128"),
3245
+ BigInt("975327637149449"),
3246
+ BigInt("237881983565075"),
3247
+ BigInt("1654761232378630"),
3248
+ BigInt("2122527599091807"),
3249
+ ])), new FieldElem51(new BigUint64Array([
3250
+ BigInt("2093793463548278"),
3251
+ BigInt("754827233241879"),
3252
+ BigInt("1420389751719629"),
3253
+ BigInt("1829952782588138"),
3254
+ BigInt("2011865756773717"),
3255
+ ]))),
3256
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3257
+ BigInt("676293365438898"),
3258
+ BigInt("2850296017886344"),
3259
+ BigInt("1205350322490195"),
3260
+ BigInt("2763699392265669"),
3261
+ BigInt("2133931188538142"),
3262
+ ])), new FieldElem51(new BigUint64Array([
3263
+ BigInt("48340340349120"),
3264
+ BigInt("1299261101494832"),
3265
+ BigInt("1137329686775218"),
3266
+ BigInt("1534848106674340"),
3267
+ BigInt("1351662218216799"),
3268
+ ])), new FieldElem51(new BigUint64Array([
3269
+ BigInt("1904520614137939"),
3270
+ BigInt("1590301001714014"),
3271
+ BigInt("215781420985270"),
3272
+ BigInt("2043534301034629"),
3273
+ BigInt("1970888949300424"),
3274
+ ]))),
3275
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3276
+ BigInt("2365217962409710"),
3277
+ BigInt("2061307169694064"),
3278
+ BigInt("1887478590157603"),
3279
+ BigInt("2169639621284316"),
3280
+ BigInt("2373810867477200"),
3281
+ ])), new FieldElem51(new BigUint64Array([
3282
+ BigInt("1020052624656948"),
3283
+ BigInt("1260412094216707"),
3284
+ BigInt("366721640607121"),
3285
+ BigInt("585331442306596"),
3286
+ BigInt("345876457758061"),
3287
+ ])), new FieldElem51(new BigUint64Array([
3288
+ BigInt("975390299880933"),
3289
+ BigInt("1066555195234642"),
3290
+ BigInt("12651997758352"),
3291
+ BigInt("1184252205433068"),
3292
+ BigInt("1058378155074223"),
3293
+ ]))),
3294
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3295
+ BigInt("1431537716602643"),
3296
+ BigInt("2024827957433813"),
3297
+ BigInt("3746434518400495"),
3298
+ BigInt("1087794891033550"),
3299
+ BigInt("2156817571680455"),
3300
+ ])), new FieldElem51(new BigUint64Array([
3301
+ BigInt("929288033346881"),
3302
+ BigInt("255179964546973"),
3303
+ BigInt("711057989588035"),
3304
+ BigInt("208899572612840"),
3305
+ BigInt("185348357387383"),
3306
+ ])), new FieldElem51(new BigUint64Array([
3307
+ BigInt("823689746424808"),
3308
+ BigInt("47266130989546"),
3309
+ BigInt("209403309368097"),
3310
+ BigInt("1100966895202707"),
3311
+ BigInt("710792075292719"),
3312
+ ]))),
3313
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3314
+ BigInt("2311213117823762"),
3315
+ BigInt("3296668540922318"),
3316
+ BigInt("2004276520649823"),
3317
+ BigInt("1861500579441125"),
3318
+ BigInt("3148029033359833"),
3319
+ ])), new FieldElem51(new BigUint64Array([
3320
+ BigInt("1563693677475261"),
3321
+ BigInt("1843782073741194"),
3322
+ BigInt("1950700654453170"),
3323
+ BigInt("911540858113949"),
3324
+ BigInt("2085151496302359"),
3325
+ ])), new FieldElem51(new BigUint64Array([
3326
+ BigInt("1427880892005482"),
3327
+ BigInt("106216431121745"),
3328
+ BigInt("42608394782284"),
3329
+ BigInt("1217295886989793"),
3330
+ BigInt("1514235272796882"),
3331
+ ]))),
3332
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3333
+ BigInt("3544335535746750"),
3334
+ BigInt("2367994491347456"),
3335
+ BigInt("2567261456502612"),
3336
+ BigInt("1854058085060971"),
3337
+ BigInt("2263545563461076"),
3338
+ ])), new FieldElem51(new BigUint64Array([
3339
+ BigInt("787426011300053"),
3340
+ BigInt("2105981035769060"),
3341
+ BigInt("1130476291127206"),
3342
+ BigInt("1748659348100075"),
3343
+ BigInt("53470983013756"),
3344
+ ])), new FieldElem51(new BigUint64Array([
3345
+ BigInt("553548273865386"),
3346
+ BigInt("5927805718390"),
3347
+ BigInt("65184587381926"),
3348
+ BigInt("633576679686953"),
3349
+ BigInt("576048559439973"),
3350
+ ]))),
3351
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3352
+ BigInt("993787326657446"),
3353
+ BigInt("3868807161609258"),
3354
+ BigInt("1615796046728943"),
3355
+ BigInt("2514644292681953"),
3356
+ BigInt("2059021068660907"),
3357
+ ])), new FieldElem51(new BigUint64Array([
3358
+ BigInt("251010270518880"),
3359
+ BigInt("1681684095763484"),
3360
+ BigInt("1521949356387564"),
3361
+ BigInt("431593457045116"),
3362
+ BigInt("1855308922422910"),
3363
+ ])), new FieldElem51(new BigUint64Array([
3364
+ BigInt("618490909691959"),
3365
+ BigInt("1257497595618257"),
3366
+ BigInt("202952467594088"),
3367
+ BigInt("35577762721238"),
3368
+ BigInt("1494883566841973"),
3369
+ ]))),
3370
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3371
+ BigInt("1673474571932262"),
3372
+ BigInt("2409784519770613"),
3373
+ BigInt("2636095316260487"),
3374
+ BigInt("2761112584601925"),
3375
+ BigInt("3333713288149876"),
3376
+ ])), new FieldElem51(new BigUint64Array([
3377
+ BigInt("1600640202645197"),
3378
+ BigInt("1019569075331823"),
3379
+ BigInt("1041916487915822"),
3380
+ BigInt("1680448171313267"),
3381
+ BigInt("2126903137527901"),
3382
+ ])), new FieldElem51(new BigUint64Array([
3383
+ BigInt("894964745143659"),
3384
+ BigInt("106116880092678"),
3385
+ BigInt("1009869382959477"),
3386
+ BigInt("317866368542032"),
3387
+ BigInt("1986983122763912"),
3388
+ ]))),
3389
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3390
+ BigInt("1765281781276487"),
3391
+ BigInt("2863247187455184"),
3392
+ BigInt("2589075472439062"),
3393
+ BigInt("1386435905543054"),
3394
+ BigInt("2182338478845320"),
3395
+ ])), new FieldElem51(new BigUint64Array([
3396
+ BigInt("1144730936996693"),
3397
+ BigInt("2213315231278180"),
3398
+ BigInt("1489676672185125"),
3399
+ BigInt("665039429138074"),
3400
+ BigInt("1131283313040268"),
3401
+ ])), new FieldElem51(new BigUint64Array([
3402
+ BigInt("2004734176670602"),
3403
+ BigInt("1738311085075235"),
3404
+ BigInt("418866995976618"),
3405
+ BigInt("1050782508034394"),
3406
+ BigInt("577747313404652"),
3407
+ ]))),
3408
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3409
+ BigInt("2185209688340293"),
3410
+ BigInt("1309276076461009"),
3411
+ BigInt("2514740038571278"),
3412
+ BigInt("3994889904012999"),
3413
+ BigInt("3018098826231021"),
3414
+ ])), new FieldElem51(new BigUint64Array([
3415
+ BigInt("1405936970888515"),
3416
+ BigInt("1754621155316654"),
3417
+ BigInt("1211862168554999"),
3418
+ BigInt("1813045702919083"),
3419
+ BigInt("997853418197172"),
3420
+ ])), new FieldElem51(new BigUint64Array([
3421
+ BigInt("82037622045021"),
3422
+ BigInt("1646398333621944"),
3423
+ BigInt("613095452763466"),
3424
+ BigInt("1312329542583705"),
3425
+ BigInt("81014679202721"),
3426
+ ]))),
3427
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3428
+ BigInt("2389287991277873"),
3429
+ BigInt("403851022333257"),
3430
+ BigInt("1597473361477193"),
3431
+ BigInt("2953351602509212"),
3432
+ BigInt("2135174663049062"),
3433
+ ])), new FieldElem51(new BigUint64Array([
3434
+ BigInt("1826548187201150"),
3435
+ BigInt("302299893734126"),
3436
+ BigInt("1475477168615781"),
3437
+ BigInt("842617616347376"),
3438
+ BigInt("1438600873676130"),
3439
+ ])), new FieldElem51(new BigUint64Array([
3440
+ BigInt("663049852468609"),
3441
+ BigInt("1649295727846569"),
3442
+ BigInt("1048009692742781"),
3443
+ BigInt("628866177992421"),
3444
+ BigInt("1914360327429204"),
3445
+ ]))),
3446
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3447
+ BigInt("1795645928096646"),
3448
+ BigInt("306878154408959"),
3449
+ BigInt("2924901319092394"),
3450
+ BigInt("2801261341654799"),
3451
+ BigInt("1653782432983523"),
3452
+ ])), new FieldElem51(new BigUint64Array([
3453
+ BigInt("2077597317438627"),
3454
+ BigInt("212642017882064"),
3455
+ BigInt("674844477518888"),
3456
+ BigInt("875487498687554"),
3457
+ BigInt("2060550250171182"),
3458
+ ])), new FieldElem51(new BigUint64Array([
3459
+ BigInt("1420448018683809"),
3460
+ BigInt("1032663994771382"),
3461
+ BigInt("1341927003385267"),
3462
+ BigInt("1340360916546159"),
3463
+ BigInt("1988547473895228"),
3464
+ ]))),
3465
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3466
+ BigInt("1082660122598844"),
3467
+ BigInt("2545055705583789"),
3468
+ BigInt("3888919679589007"),
3469
+ BigInt("1670283344995811"),
3470
+ BigInt("3403239134794618"),
3471
+ ])), new FieldElem51(new BigUint64Array([
3472
+ BigInt("90430593339788"),
3473
+ BigInt("1838338032241275"),
3474
+ BigInt("571293238480915"),
3475
+ BigInt("1639938867416883"),
3476
+ BigInt("257378872001111"),
3477
+ ])), new FieldElem51(new BigUint64Array([
3478
+ BigInt("1528535658865034"),
3479
+ BigInt("1516636853043960"),
3480
+ BigInt("787000569996728"),
3481
+ BigInt("1464531394704506"),
3482
+ BigInt("1684822625133795"),
3483
+ ]))),
3484
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3485
+ BigInt("811329918113934"),
3486
+ BigInt("2783463529007378"),
3487
+ BigInt("1769095754634835"),
3488
+ BigInt("2970819621866866"),
3489
+ BigInt("881037178164325"),
3490
+ ])), new FieldElem51(new BigUint64Array([
3491
+ BigInt("1784566501964517"),
3492
+ BigInt("433890943689325"),
3493
+ BigInt("1186055625589419"),
3494
+ BigInt("1496077405487512"),
3495
+ BigInt("1731807117886548"),
3496
+ ])), new FieldElem51(new BigUint64Array([
3497
+ BigInt("424909811816304"),
3498
+ BigInt("1355993963741797"),
3499
+ BigInt("409606483251841"),
3500
+ BigInt("455665350637068"),
3501
+ BigInt("1617009023642808"),
3502
+ ]))),
3503
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3504
+ BigInt("2478728492077816"),
3505
+ BigInt("2780289048655501"),
3506
+ BigInt("2328687177473769"),
3507
+ BigInt("4107341333582032"),
3508
+ BigInt("1316147724308250"),
3509
+ ])), new FieldElem51(new BigUint64Array([
3510
+ BigInt("1617420574301156"),
3511
+ BigInt("1741273341070467"),
3512
+ BigInt("667135503486508"),
3513
+ BigInt("2100436564640123"),
3514
+ BigInt("1032223920000865"),
3515
+ ])), new FieldElem51(new BigUint64Array([
3516
+ BigInt("1753947659404033"),
3517
+ BigInt("247279202390193"),
3518
+ BigInt("1819288880178945"),
3519
+ BigInt("737334285670249"),
3520
+ BigInt("1037873664856104"),
3521
+ ]))),
3522
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3523
+ BigInt("1762568490530034"),
3524
+ BigInt("673742465299012"),
3525
+ BigInt("2054571050635888"),
3526
+ BigInt("2040165159255111"),
3527
+ BigInt("3040123733327257"),
3528
+ ])), new FieldElem51(new BigUint64Array([
3529
+ BigInt("1627187989987422"),
3530
+ BigInt("1686331580821752"),
3531
+ BigInt("1309895873498183"),
3532
+ BigInt("719718719104086"),
3533
+ BigInt("300063199808722"),
3534
+ ])), new FieldElem51(new BigUint64Array([
3535
+ BigInt("238176707016164"),
3536
+ BigInt("1440454788877048"),
3537
+ BigInt("203336037573144"),
3538
+ BigInt("1437789888677072"),
3539
+ BigInt("101522256664211"),
3540
+ ]))),
3541
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3542
+ BigInt("1895216760098480"),
3543
+ BigInt("1934324337975022"),
3544
+ BigInt("3677350688973167"),
3545
+ BigInt("2536415965456176"),
3546
+ BigInt("714678003308640"),
3547
+ ])), new FieldElem51(new BigUint64Array([
3548
+ BigInt("508185358728815"),
3549
+ BigInt("1691320535341855"),
3550
+ BigInt("2168887448239256"),
3551
+ BigInt("1035124393070661"),
3552
+ BigInt("1936603999698584"),
3553
+ ])), new FieldElem51(new BigUint64Array([
3554
+ BigInt("390562831571647"),
3555
+ BigInt("1390223890708972"),
3556
+ BigInt("1383183990676371"),
3557
+ BigInt("435998174196410"),
3558
+ BigInt("1882086414390730"),
3559
+ ]))),
3560
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3561
+ BigInt("3747620842612921"),
3562
+ BigInt("2081794785291195"),
3563
+ BigInt("3284594056262745"),
3564
+ BigInt("2090090346797895"),
3565
+ BigInt("2581692978935809"),
3566
+ ])), new FieldElem51(new BigUint64Array([
3567
+ BigInt("244144781251265"),
3568
+ BigInt("1290834426417077"),
3569
+ BigInt("1888701171101942"),
3570
+ BigInt("1233922456644870"),
3571
+ BigInt("241117402207491"),
3572
+ ])), new FieldElem51(new BigUint64Array([
3573
+ BigInt("1266169390045455"),
3574
+ BigInt("1148042013187970"),
3575
+ BigInt("878921907853942"),
3576
+ BigInt("1815738019658093"),
3577
+ BigInt("908920199341621"),
3578
+ ]))),
3579
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3580
+ BigInt("2521768507305118"),
3581
+ BigInt("953557056811112"),
3582
+ BigInt("2015863732865770"),
3583
+ BigInt("1358382511861315"),
3584
+ BigInt("2835421647899992"),
3585
+ ])), new FieldElem51(new BigUint64Array([
3586
+ BigInt("2239837206240498"),
3587
+ BigInt("330928973149665"),
3588
+ BigInt("422268062913642"),
3589
+ BigInt("1481280019493032"),
3590
+ BigInt("619879520439841"),
3591
+ ])), new FieldElem51(new BigUint64Array([
3592
+ BigInt("1360166735366017"),
3593
+ BigInt("1770556573948510"),
3594
+ BigInt("1395061284191031"),
3595
+ BigInt("1814003148068126"),
3596
+ BigInt("522781147076884"),
3597
+ ]))),
3598
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3599
+ BigInt("2611794802645686"),
3600
+ BigInt("707234844948070"),
3601
+ BigInt("1314059396506491"),
3602
+ BigInt("2919250341703934"),
3603
+ BigInt("2161831667832785"),
3604
+ ])), new FieldElem51(new BigUint64Array([
3605
+ BigInt("934831784182383"),
3606
+ BigInt("433734253968318"),
3607
+ BigInt("1660867106725771"),
3608
+ BigInt("1968393082772831"),
3609
+ BigInt("873946300968490"),
3610
+ ])), new FieldElem51(new BigUint64Array([
3611
+ BigInt("26306827827554"),
3612
+ BigInt("430884999378685"),
3613
+ BigInt("1504310424376419"),
3614
+ BigInt("1761358720837522"),
3615
+ BigInt("542195685418530"),
3616
+ ]))),
3617
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3618
+ BigInt("1762131062631725"),
3619
+ BigInt("3123952634417535"),
3620
+ BigInt("3619918390837537"),
3621
+ BigInt("2909990877347294"),
3622
+ BigInt("1411594230004385"),
3623
+ ])), new FieldElem51(new BigUint64Array([
3624
+ BigInt("538272372224622"),
3625
+ BigInt("1425714779586199"),
3626
+ BigInt("588313661410172"),
3627
+ BigInt("1497062084392578"),
3628
+ BigInt("1602174047128512"),
3629
+ ])), new FieldElem51(new BigUint64Array([
3630
+ BigInt("907490361939255"),
3631
+ BigInt("1963620338391363"),
3632
+ BigInt("626927432296975"),
3633
+ BigInt("1250748516081414"),
3634
+ BigInt("959901171882527"),
3635
+ ]))),
3636
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3637
+ BigInt("1335066153744413"),
3638
+ BigInt("2887804660779657"),
3639
+ BigInt("2653073855954038"),
3640
+ BigInt("2765226981667422"),
3641
+ BigInt("938831784476763"),
3642
+ ])), new FieldElem51(new BigUint64Array([
3643
+ BigInt("296699434737224"),
3644
+ BigInt("2047543711075683"),
3645
+ BigInt("2076451038937139"),
3646
+ BigInt("227783599906901"),
3647
+ BigInt("1602062110967627"),
3648
+ ])), new FieldElem51(new BigUint64Array([
3649
+ BigInt("1574834773194203"),
3650
+ BigInt("1384279952062839"),
3651
+ BigInt("393652417255803"),
3652
+ BigInt("2166968242848859"),
3653
+ BigInt("1552890441390820"),
3654
+ ]))),
3655
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3656
+ BigInt("1619646774410947"),
3657
+ BigInt("1576090644023562"),
3658
+ BigInt("3035228391320965"),
3659
+ BigInt("1735328519940543"),
3660
+ BigInt("2355324535937066"),
3661
+ ])), new FieldElem51(new BigUint64Array([
3662
+ BigInt("1024074573633446"),
3663
+ BigInt("957088456885874"),
3664
+ BigInt("1690425531356997"),
3665
+ BigInt("2102187380180052"),
3666
+ BigInt("1082544623222033"),
3667
+ ])), new FieldElem51(new BigUint64Array([
3668
+ BigInt("1871906170635853"),
3669
+ BigInt("1719383891167200"),
3670
+ BigInt("1584032250247862"),
3671
+ BigInt("823764804192117"),
3672
+ BigInt("2244048510084261"),
3673
+ ]))),
3674
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3675
+ BigInt("642147846489775"),
3676
+ BigInt("3334304977145699"),
3677
+ BigInt("305205716788147"),
3678
+ BigInt("2589176626729533"),
3679
+ BigInt("2224680511484174"),
3680
+ ])), new FieldElem51(new BigUint64Array([
3681
+ BigInt("1734162377166545"),
3682
+ BigInt("260713621840346"),
3683
+ BigInt("157174591942595"),
3684
+ BigInt("952544272517991"),
3685
+ BigInt("222818702471733"),
3686
+ ])), new FieldElem51(new BigUint64Array([
3687
+ BigInt("1213115494182947"),
3688
+ BigInt("286778704335711"),
3689
+ BigInt("2130189536016490"),
3690
+ BigInt("308349182281342"),
3691
+ BigInt("1217623948685491"),
3692
+ ]))),
3693
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3694
+ BigInt("3360052266973635"),
3695
+ BigInt("1843486583624091"),
3696
+ BigInt("1561693837124349"),
3697
+ BigInt("1084041964025479"),
3698
+ BigInt("1866270922024009"),
3699
+ ])), new FieldElem51(new BigUint64Array([
3700
+ BigInt("460705465481210"),
3701
+ BigInt("1968151453817859"),
3702
+ BigInt("497005926994844"),
3703
+ BigInt("625618055866751"),
3704
+ BigInt("2176893440866887"),
3705
+ ])), new FieldElem51(new BigUint64Array([
3706
+ BigInt("1655800250476757"),
3707
+ BigInt("2036588542300609"),
3708
+ BigInt("666447448675243"),
3709
+ BigInt("1615721995750683"),
3710
+ BigInt("1508669225186765"),
3711
+ ]))),
3712
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3713
+ BigInt("2245948203759141"),
3714
+ BigInt("1058306669699396"),
3715
+ BigInt("1452898014240582"),
3716
+ BigInt("3961024141962768"),
3717
+ BigInt("1633235287338608"),
3718
+ ])), new FieldElem51(new BigUint64Array([
3719
+ BigInt("986647273684279"),
3720
+ BigInt("1507266907811370"),
3721
+ BigInt("1260572633649005"),
3722
+ BigInt("2071672342077446"),
3723
+ BigInt("695976026010857"),
3724
+ ])), new FieldElem51(new BigUint64Array([
3725
+ BigInt("1312356620823495"),
3726
+ BigInt("1635278548098567"),
3727
+ BigInt("901946076841033"),
3728
+ BigInt("585120475533168"),
3729
+ BigInt("1240667113237384"),
3730
+ ]))),
3731
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3732
+ BigInt("2313723935779695"),
3733
+ BigInt("1506054666773895"),
3734
+ BigInt("996040223525031"),
3735
+ BigInt("636592914999692"),
3736
+ BigInt("1497801917020297"),
3737
+ ])), new FieldElem51(new BigUint64Array([
3738
+ BigInt("292042016419794"),
3739
+ BigInt("1158932298133044"),
3740
+ BigInt("2062611870323738"),
3741
+ BigInt("1946058478962569"),
3742
+ BigInt("1749165808126286"),
3743
+ ])), new FieldElem51(new BigUint64Array([
3744
+ BigInt("654683942212830"),
3745
+ BigInt("1526897351349087"),
3746
+ BigInt("2006818439922838"),
3747
+ BigInt("2194919327350361"),
3748
+ BigInt("1451960776874416"),
3749
+ ]))),
3750
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3751
+ BigInt("3015041017808905"),
3752
+ BigInt("2951823141773809"),
3753
+ BigInt("2584865668253675"),
3754
+ BigInt("2508192032998563"),
3755
+ BigInt("2582137700042019"),
3756
+ ])), new FieldElem51(new BigUint64Array([
3757
+ BigInt("1628123495344283"),
3758
+ BigInt("2072923641214546"),
3759
+ BigInt("1647225812023982"),
3760
+ BigInt("855655925244679"),
3761
+ BigInt("1758126430071140"),
3762
+ ])), new FieldElem51(new BigUint64Array([
3763
+ BigInt("1615895096489599"),
3764
+ BigInt("275295258643784"),
3765
+ BigInt("937665541219916"),
3766
+ BigInt("1313496726746346"),
3767
+ BigInt("1186468946422626"),
3768
+ ]))),
3769
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3770
+ BigInt("1603070202850694"),
3771
+ BigInt("2072127623773242"),
3772
+ BigInt("1692648737212158"),
3773
+ BigInt("2493373404187852"),
3774
+ BigInt("1248948672117105"),
3775
+ ])), new FieldElem51(new BigUint64Array([
3776
+ BigInt("11167836031898"),
3777
+ BigInt("596565174397990"),
3778
+ BigInt("2196351068723859"),
3779
+ BigInt("314744641791907"),
3780
+ BigInt("1102014997250781"),
3781
+ ])), new FieldElem51(new BigUint64Array([
3782
+ BigInt("1409047922401191"),
3783
+ BigInt("69960384467966"),
3784
+ BigInt("688103515547600"),
3785
+ BigInt("1309746102488044"),
3786
+ BigInt("150292892873778"),
3787
+ ]))),
3788
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3789
+ BigInt("1986083055103168"),
3790
+ BigInt("691715819340300"),
3791
+ BigInt("1361811659746933"),
3792
+ BigInt("3459052030333434"),
3793
+ BigInt("1063594696046061"),
3794
+ ])), new FieldElem51(new BigUint64Array([
3795
+ BigInt("1201987338414749"),
3796
+ BigInt("2198784582460616"),
3797
+ BigInt("1203335513981498"),
3798
+ BigInt("489243077045066"),
3799
+ BigInt("2205278143582433"),
3800
+ ])), new FieldElem51(new BigUint64Array([
3801
+ BigInt("2034744376624534"),
3802
+ BigInt("2077387101466387"),
3803
+ BigInt("148448542974969"),
3804
+ BigInt("1502697574577258"),
3805
+ BigInt("473186584705655"),
3806
+ ]))),
3807
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3808
+ BigInt("472016956315960"),
3809
+ BigInt("720786972252993"),
3810
+ BigInt("2840633661190043"),
3811
+ BigInt("3150798753357827"),
3812
+ BigInt("2816563335499153"),
3813
+ ])), new FieldElem51(new BigUint64Array([
3814
+ BigInt("253464247569755"),
3815
+ BigInt("168314237403057"),
3816
+ BigInt("511780806170295"),
3817
+ BigInt("1058862316549135"),
3818
+ BigInt("1646858476817137"),
3819
+ ])), new FieldElem51(new BigUint64Array([
3820
+ BigInt("595092995922219"),
3821
+ BigInt("1491311840717691"),
3822
+ BigInt("291581784452778"),
3823
+ BigInt("1569186646367854"),
3824
+ BigInt("1031385061400544"),
3825
+ ]))),
3826
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3827
+ BigInt("3483137021572755"),
3828
+ BigInt("1526955102024322"),
3829
+ BigInt("2778006642704458"),
3830
+ BigInt("457549634924205"),
3831
+ BigInt("1097420237736736"),
3832
+ ])), new FieldElem51(new BigUint64Array([
3833
+ BigInt("1246991699537710"),
3834
+ BigInt("81367319519439"),
3835
+ BigInt("530844036072196"),
3836
+ BigInt("163656863755855"),
3837
+ BigInt("1950742455979290"),
3838
+ ])), new FieldElem51(new BigUint64Array([
3839
+ BigInt("191532664076407"),
3840
+ BigInt("539378506082089"),
3841
+ BigInt("1021612562876554"),
3842
+ BigInt("1026603384732632"),
3843
+ BigInt("1773368780410653"),
3844
+ ]))),
3845
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3846
+ BigInt("4144620731387879"),
3847
+ BigInt("590179521333342"),
3848
+ BigInt("4034023318016108"),
3849
+ BigInt("2255745030335426"),
3850
+ BigInt("2699746851701250"),
3851
+ ])), new FieldElem51(new BigUint64Array([
3852
+ BigInt("2206599697359952"),
3853
+ BigInt("553895797384417"),
3854
+ BigInt("181689161933786"),
3855
+ BigInt("1153123447919104"),
3856
+ BigInt("778568064152659"),
3857
+ ])), new FieldElem51(new BigUint64Array([
3858
+ BigInt("1706307000059211"),
3859
+ BigInt("1885601289314487"),
3860
+ BigInt("889758608505788"),
3861
+ BigInt("550131729999853"),
3862
+ BigInt("1006862664714268"),
3863
+ ]))),
3864
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3865
+ BigInt("3210197754285058"),
3866
+ BigInt("2048500453422630"),
3867
+ BigInt("3403309827888207"),
3868
+ BigInt("927154428508963"),
3869
+ BigInt("4199813798872019"),
3870
+ ])), new FieldElem51(new BigUint64Array([
3871
+ BigInt("992058915374933"),
3872
+ BigInt("476120535358775"),
3873
+ BigInt("1973648780784340"),
3874
+ BigInt("2025282643598818"),
3875
+ BigInt("2182318983793230"),
3876
+ ])), new FieldElem51(new BigUint64Array([
3877
+ BigInt("1343440812005821"),
3878
+ BigInt("1316045839091795"),
3879
+ BigInt("1884951299078063"),
3880
+ BigInt("1765919609219175"),
3881
+ BigInt("2197567554627988"),
3882
+ ]))),
3883
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3884
+ BigInt("3129247779382818"),
3885
+ BigInt("4415026969054274"),
3886
+ BigInt("1900265885969643"),
3887
+ BigInt("1528796215447059"),
3888
+ BigInt("2172730393748688"),
3889
+ ])), new FieldElem51(new BigUint64Array([
3890
+ BigInt("1773355092297603"),
3891
+ BigInt("64654329538271"),
3892
+ BigInt("1332124041660957"),
3893
+ BigInt("748492100858001"),
3894
+ BigInt("895500006200535"),
3895
+ ])), new FieldElem51(new BigUint64Array([
3896
+ BigInt("2000840647851980"),
3897
+ BigInt("546565968824914"),
3898
+ BigInt("420633283457524"),
3899
+ BigInt("195470736374507"),
3900
+ BigInt("1958689297569520"),
3901
+ ]))),
3902
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3903
+ BigInt("743138980705446"),
3904
+ BigInt("3411117504637167"),
3905
+ BigInt("2591389959690621"),
3906
+ BigInt("2380042066577202"),
3907
+ BigInt("3022267940115114"),
3908
+ ])), new FieldElem51(new BigUint64Array([
3909
+ BigInt("165947002229363"),
3910
+ BigInt("115186103724967"),
3911
+ BigInt("1068573292121517"),
3912
+ BigInt("1842565776920938"),
3913
+ BigInt("1969395681111987"),
3914
+ ])), new FieldElem51(new BigUint64Array([
3915
+ BigInt("553322266190633"),
3916
+ BigInt("234265665613185"),
3917
+ BigInt("484544650202821"),
3918
+ BigInt("1238773526575826"),
3919
+ BigInt("2017991917953668"),
3920
+ ]))),
3921
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3922
+ BigInt("2581954631514051"),
3923
+ BigInt("1245093644265357"),
3924
+ BigInt("3537016673825374"),
3925
+ BigInt("1834216551713857"),
3926
+ BigInt("923978372152807"),
3927
+ ])), new FieldElem51(new BigUint64Array([
3928
+ BigInt("1855378315339552"),
3929
+ BigInt("890045579230758"),
3930
+ BigInt("1764718173975590"),
3931
+ BigInt("197904186055854"),
3932
+ BigInt("1718129022310327"),
3933
+ ])), new FieldElem51(new BigUint64Array([
3934
+ BigInt("1278162928734862"),
3935
+ BigInt("1894118254109862"),
3936
+ BigInt("987503995465517"),
3937
+ BigInt("177406744098996"),
3938
+ BigInt("781538103127693"),
3939
+ ]))),
3940
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3941
+ BigInt("1996603431230215"),
3942
+ BigInt("1191888797552937"),
3943
+ BigInt("1207440075928499"),
3944
+ BigInt("2765853449051137"),
3945
+ BigInt("2525314961343288"),
3946
+ ])), new FieldElem51(new BigUint64Array([
3947
+ BigInt("808903879370889"),
3948
+ BigInt("990820108751280"),
3949
+ BigInt("1084429472258867"),
3950
+ BigInt("1078562781312589"),
3951
+ BigInt("254514692695625"),
3952
+ ])), new FieldElem51(new BigUint64Array([
3953
+ BigInt("615855140068469"),
3954
+ BigInt("586046731175395"),
3955
+ BigInt("693470779212674"),
3956
+ BigInt("1964537100203868"),
3957
+ BigInt("1350330550265229"),
3958
+ ]))),
3959
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3960
+ BigInt("3344544372023708"),
3961
+ BigInt("720386671449874"),
3962
+ BigInt("2480841360702110"),
3963
+ BigInt("2036034126860286"),
3964
+ BigInt("2015744690201389"),
3965
+ ])), new FieldElem51(new BigUint64Array([
3966
+ BigInt("1337446193390478"),
3967
+ BigInt("1984110761311871"),
3968
+ BigInt("746489405020285"),
3969
+ BigInt("407347127604128"),
3970
+ BigInt("1740475330360596"),
3971
+ ])), new FieldElem51(new BigUint64Array([
3972
+ BigInt("140840424783613"),
3973
+ BigInt("1063284623568331"),
3974
+ BigInt("1136446106453878"),
3975
+ BigInt("372042229029799"),
3976
+ BigInt("442607248430694"),
3977
+ ]))),
3978
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3979
+ BigInt("2330781679120937"),
3980
+ BigInt("376801425148230"),
3981
+ BigInt("2032603686676107"),
3982
+ BigInt("1488926293635130"),
3983
+ BigInt("1317278311532959"),
3984
+ ])), new FieldElem51(new BigUint64Array([
3985
+ BigInt("1290116731380016"),
3986
+ BigInt("2166899563471713"),
3987
+ BigInt("831997001838078"),
3988
+ BigInt("870954980505220"),
3989
+ BigInt("2108537278055823"),
3990
+ ])), new FieldElem51(new BigUint64Array([
3991
+ BigInt("1912719171026343"),
3992
+ BigInt("846194720551034"),
3993
+ BigInt("2043988124740726"),
3994
+ BigInt("993234269653961"),
3995
+ BigInt("421229796383281"),
3996
+ ]))),
3997
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
3998
+ BigInt("2651184584992902"),
3999
+ BigInt("2775702557638963"),
4000
+ BigInt("2539786009779572"),
4001
+ BigInt("2575974880015305"),
4002
+ BigInt("2122619079836732"),
4003
+ ])), new FieldElem51(new BigUint64Array([
4004
+ BigInt("1154054290132562"),
4005
+ BigInt("931753998725577"),
4006
+ BigInt("1647742001778052"),
4007
+ BigInt("865765466488226"),
4008
+ BigInt("1083816107290025"),
4009
+ ])), new FieldElem51(new BigUint64Array([
4010
+ BigInt("986341121095108"),
4011
+ BigInt("1522330369638573"),
4012
+ BigInt("1990880546211047"),
4013
+ BigInt("501525962272123"),
4014
+ BigInt("198539304862139"),
4015
+ ]))),
4016
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4017
+ BigInt("1496414019192687"),
4018
+ BigInt("3991034436173951"),
4019
+ BigInt("3380311659062196"),
4020
+ BigInt("2854747485359158"),
4021
+ BigInt("3346958036643152"),
4022
+ ])), new FieldElem51(new BigUint64Array([
4023
+ BigInt("805612068303425"),
4024
+ BigInt("1891790027761335"),
4025
+ BigInt("1587008567571549"),
4026
+ BigInt("722120737390201"),
4027
+ BigInt("378156757163816"),
4028
+ ])), new FieldElem51(new BigUint64Array([
4029
+ BigInt("1588994517921951"),
4030
+ BigInt("977362751042302"),
4031
+ BigInt("1329302387067714"),
4032
+ BigInt("2069348224564088"),
4033
+ BigInt("1586007159625211"),
4034
+ ]))),
4035
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4036
+ BigInt("2490539421551682"),
4037
+ BigInt("1985699850375015"),
4038
+ BigInt("2331762317128172"),
4039
+ BigInt("4145097393776678"),
4040
+ BigInt("2521049460190674"),
4041
+ ])), new FieldElem51(new BigUint64Array([
4042
+ BigInt("615817553313996"),
4043
+ BigInt("2245962768078178"),
4044
+ BigInt("482564324326173"),
4045
+ BigInt("2101336843140780"),
4046
+ BigInt("1240914880829407"),
4047
+ ])), new FieldElem51(new BigUint64Array([
4048
+ BigInt("1438242482238189"),
4049
+ BigInt("874267817785463"),
4050
+ BigInt("1620810389770625"),
4051
+ BigInt("866155221338671"),
4052
+ BigInt("1040426546798301"),
4053
+ ]))),
4054
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4055
+ BigInt("2403083624110300"),
4056
+ BigInt("2548561409802975"),
4057
+ BigInt("2492699136535911"),
4058
+ BigInt("2358289519456539"),
4059
+ BigInt("3203964320363148"),
4060
+ ])), new FieldElem51(new BigUint64Array([
4061
+ BigInt("1913986535403097"),
4062
+ BigInt("1977163223054199"),
4063
+ BigInt("1972905914623196"),
4064
+ BigInt("1650122133472502"),
4065
+ BigInt("1905849310819035"),
4066
+ ])), new FieldElem51(new BigUint64Array([
4067
+ BigInt("858174816360838"),
4068
+ BigInt("614595356564037"),
4069
+ BigInt("1099584959044836"),
4070
+ BigInt("636998087084906"),
4071
+ BigInt("1070393269058348"),
4072
+ ]))),
4073
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4074
+ BigInt("3666695924830668"),
4075
+ BigInt("3585640662737501"),
4076
+ BigInt("2372994528684236"),
4077
+ BigInt("2628565977288995"),
4078
+ BigInt("3482812783469694"),
4079
+ ])), new FieldElem51(new BigUint64Array([
4080
+ BigInt("1994161359147952"),
4081
+ BigInt("2198039369802658"),
4082
+ BigInt("62790022842537"),
4083
+ BigInt("1522306785848169"),
4084
+ BigInt("951223194802833"),
4085
+ ])), new FieldElem51(new BigUint64Array([
4086
+ BigInt("852296621440717"),
4087
+ BigInt("431889737774209"),
4088
+ BigInt("370755457746189"),
4089
+ BigInt("437604073958073"),
4090
+ BigInt("627857326892757"),
4091
+ ]))),
4092
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4093
+ BigInt("1794955764684156"),
4094
+ BigInt("2586904290013612"),
4095
+ BigInt("1322647643615887"),
4096
+ BigInt("856117964085888"),
4097
+ BigInt("2652432778663153"),
4098
+ ])), new FieldElem51(new BigUint64Array([
4099
+ BigInt("933592377399646"),
4100
+ BigInt("78031722952813"),
4101
+ BigInt("926049890685253"),
4102
+ BigInt("1471649501316246"),
4103
+ BigInt("33789909190376"),
4104
+ ])), new FieldElem51(new BigUint64Array([
4105
+ BigInt("1479319468832059"),
4106
+ BigInt("203906207621608"),
4107
+ BigInt("659828362330083"),
4108
+ BigInt("44358398435755"),
4109
+ BigInt("1273573524210803"),
4110
+ ]))),
4111
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4112
+ BigInt("1592342143350813"),
4113
+ BigInt("3227219208247713"),
4114
+ BigInt("2345240352078765"),
4115
+ BigInt("2577750109932929"),
4116
+ BigInt("2933512841197243"),
4117
+ ])), new FieldElem51(new BigUint64Array([
4118
+ BigInt("2184946892642995"),
4119
+ BigInt("1517382324576002"),
4120
+ BigInt("1557940277419806"),
4121
+ BigInt("2170635134813213"),
4122
+ BigInt("747314658627002"),
4123
+ ])), new FieldElem51(new BigUint64Array([
4124
+ BigInt("1823193620577742"),
4125
+ BigInt("1135817878516419"),
4126
+ BigInt("1731253819308581"),
4127
+ BigInt("1031652967267804"),
4128
+ BigInt("2123506616999453"),
4129
+ ]))),
4130
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4131
+ BigInt("1346190246005805"),
4132
+ BigInt("2052692552023851"),
4133
+ BigInt("1718128041785940"),
4134
+ BigInt("2491557332978474"),
4135
+ BigInt("3474370880388305"),
4136
+ ])), new FieldElem51(new BigUint64Array([
4137
+ BigInt("424776012994573"),
4138
+ BigInt("281050757243423"),
4139
+ BigInt("626466040846420"),
4140
+ BigInt("990194703866532"),
4141
+ BigInt("38571969885982"),
4142
+ ])), new FieldElem51(new BigUint64Array([
4143
+ BigInt("192408346595466"),
4144
+ BigInt("1054889725292349"),
4145
+ BigInt("584097975693004"),
4146
+ BigInt("1447909807397749"),
4147
+ BigInt("2134645004369136"),
4148
+ ]))),
4149
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4150
+ BigInt("3169895788615063"),
4151
+ BigInt("3503097743181446"),
4152
+ BigInt("601598510029975"),
4153
+ BigInt("1422812237223371"),
4154
+ BigInt("2121009661378329"),
4155
+ ])), new FieldElem51(new BigUint64Array([
4156
+ BigInt("1603348391996783"),
4157
+ BigInt("2066143816131699"),
4158
+ BigInt("1789627290363958"),
4159
+ BigInt("2145705961178118"),
4160
+ BigInt("1985578641438222"),
4161
+ ])), new FieldElem51(new BigUint64Array([
4162
+ BigInt("352633958653380"),
4163
+ BigInt("856927627345554"),
4164
+ BigInt("793925083122702"),
4165
+ BigInt("93551575767286"),
4166
+ BigInt("1222010153634215"),
4167
+ ]))),
4168
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4169
+ BigInt("1756866499986349"),
4170
+ BigInt("911731956999969"),
4171
+ BigInt("2707505543214075"),
4172
+ BigInt("4006920335263786"),
4173
+ BigInt("822501008147910"),
4174
+ ])), new FieldElem51(new BigUint64Array([
4175
+ BigInt("1094036422864347"),
4176
+ BigInt("1897208881572508"),
4177
+ BigInt("1503607738246960"),
4178
+ BigInt("1901060196071406"),
4179
+ BigInt("294068411105729"),
4180
+ ])), new FieldElem51(new BigUint64Array([
4181
+ BigInt("587776484399576"),
4182
+ BigInt("1116861711228807"),
4183
+ BigInt("343398777436088"),
4184
+ BigInt("936544065763093"),
4185
+ BigInt("1643746750211060"),
4186
+ ]))),
4187
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4188
+ BigInt("3477749685790410"),
4189
+ BigInt("267997399528836"),
4190
+ BigInt("2953780922004404"),
4191
+ BigInt("3252368924080907"),
4192
+ BigInt("3787792887348381"),
4193
+ ])), new FieldElem51(new BigUint64Array([
4194
+ BigInt("2042368155872443"),
4195
+ BigInt("41662387210459"),
4196
+ BigInt("1676313264498480"),
4197
+ BigInt("1333968523426810"),
4198
+ BigInt("1765708383352310"),
4199
+ ])), new FieldElem51(new BigUint64Array([
4200
+ BigInt("1453394896690938"),
4201
+ BigInt("1585795827439909"),
4202
+ BigInt("1469309456804303"),
4203
+ BigInt("1294645324464404"),
4204
+ BigInt("2042954198665899"),
4205
+ ]))),
4206
+ new AffineNielsPoint(new FieldElem51(new BigUint64Array([
4207
+ BigInt("1810069207599881"),
4208
+ BigInt("1358344669503239"),
4209
+ BigInt("1989371257548167"),
4210
+ BigInt("2316270051121225"),
4211
+ BigInt("3019675451276507"),
4212
+ ])), new FieldElem51(new BigUint64Array([
4213
+ BigInt("1866114438287676"),
4214
+ BigInt("1663420339568364"),
4215
+ BigInt("1437691317033088"),
4216
+ BigInt("538298302628038"),
4217
+ BigInt("1212711449614363"),
4218
+ ])), new FieldElem51(new BigUint64Array([
4219
+ BigInt("1769235035677897"),
4220
+ BigInt("1562012115317882"),
4221
+ BigInt("31277513664750"),
4222
+ BigInt("536198657928416"),
4223
+ BigInt("1976134212537183"),
4224
+ ]))),
4225
+ ]);