@aztec/foundation 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dest/abi/decoder.js +3 -3
  2. package/dest/abi/encoder.d.ts +1 -1
  3. package/dest/abi/encoder.d.ts.map +1 -1
  4. package/dest/abi/encoder.js +3 -3
  5. package/dest/abi/function_selector.js +3 -3
  6. package/dest/aztec-address/index.d.ts +10 -108
  7. package/dest/aztec-address/index.d.ts.map +1 -1
  8. package/dest/aztec-address/index.js +18 -139
  9. package/dest/bigint-buffer/index.d.ts.map +1 -1
  10. package/dest/bigint-buffer/index.js +7 -4
  11. package/dest/collection/array.d.ts.map +1 -1
  12. package/dest/collection/array.js +7 -4
  13. package/dest/crypto/pedersen/pedersen.wasm.d.ts +4 -0
  14. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  15. package/dest/crypto/pedersen/pedersen.wasm.js +18 -6
  16. package/dest/crypto/random/index.d.ts.map +1 -1
  17. package/dest/crypto/random/index.js +5 -3
  18. package/dest/crypto/sha256/index.d.ts +0 -8
  19. package/dest/crypto/sha256/index.d.ts.map +1 -1
  20. package/dest/crypto/sha256/index.js +1 -12
  21. package/dest/fields/fields.d.ts +69 -160
  22. package/dest/fields/fields.d.ts.map +1 -1
  23. package/dest/fields/fields.js +142 -185
  24. package/dest/fields/index.d.ts +0 -1
  25. package/dest/fields/index.d.ts.map +1 -1
  26. package/dest/fields/index.js +1 -2
  27. package/dest/fields/point.d.ts +1 -0
  28. package/dest/fields/point.d.ts.map +1 -1
  29. package/dest/fields/point.js +8 -4
  30. package/dest/json-rpc/class_converter.d.ts.map +1 -1
  31. package/dest/json-rpc/class_converter.js +7 -5
  32. package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -1
  33. package/dest/json-rpc/client/json_rpc_client.js +3 -2
  34. package/dest/log/console.d.ts +1 -1
  35. package/dest/log/console.d.ts.map +1 -1
  36. package/dest/log/debug.d.ts +1 -1
  37. package/dest/log/debug.d.ts.map +1 -1
  38. package/dest/log/index.d.ts +1 -4
  39. package/dest/log/index.d.ts.map +1 -1
  40. package/dest/log/index.js +2 -1
  41. package/dest/log/log_fn.d.ts +5 -0
  42. package/dest/log/log_fn.d.ts.map +1 -0
  43. package/dest/log/log_fn.js +2 -0
  44. package/dest/log/logger.d.ts +1 -1
  45. package/dest/log/logger.d.ts.map +1 -1
  46. package/dest/log/logger.js +7 -4
  47. package/dest/serialize/buffer_reader.d.ts +0 -16
  48. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  49. package/dest/serialize/buffer_reader.js +1 -21
  50. package/dest/serialize/free_funcs.d.ts +6 -0
  51. package/dest/serialize/free_funcs.d.ts.map +1 -1
  52. package/dest/serialize/free_funcs.js +11 -2
  53. package/dest/transport/interface/transferable.d.ts.map +1 -1
  54. package/dest/transport/interface/transferable.js +5 -3
  55. package/dest/wasm/empty_wasi_sdk.d.ts +1 -1
  56. package/dest/wasm/wasm_module.d.ts.map +1 -1
  57. package/dest/wasm/wasm_module.js +4 -3
  58. package/package.json +3 -4
  59. package/src/abi/decoder.ts +2 -2
  60. package/src/abi/encoder.ts +3 -2
  61. package/src/abi/function_selector.ts +2 -2
  62. package/src/aztec-address/index.ts +17 -149
  63. package/src/bigint-buffer/index.ts +9 -3
  64. package/src/collection/array.ts +9 -3
  65. package/src/crypto/pedersen/pedersen.wasm.ts +23 -5
  66. package/src/crypto/random/index.ts +6 -2
  67. package/src/crypto/sha256/index.ts +0 -13
  68. package/src/fields/fields.ts +197 -197
  69. package/src/fields/index.ts +0 -1
  70. package/src/fields/point.ts +9 -3
  71. package/src/json-rpc/class_converter.ts +8 -4
  72. package/src/json-rpc/client/json_rpc_client.ts +3 -1
  73. package/src/log/console.ts +1 -1
  74. package/src/log/debug.ts +1 -1
  75. package/src/log/index.ts +1 -6
  76. package/src/log/log_fn.ts +5 -0
  77. package/src/log/logger.ts +10 -4
  78. package/src/serialize/buffer_reader.ts +0 -22
  79. package/src/serialize/free_funcs.ts +11 -1
  80. package/src/transport/interface/transferable.ts +6 -2
  81. package/src/wasm/wasm_module.ts +3 -1
  82. package/dest/fields/grumpkin_scalar.d.ts +0 -96
  83. package/dest/fields/grumpkin_scalar.d.ts.map +0 -1
  84. package/dest/fields/grumpkin_scalar.js +0 -125
  85. package/src/fields/grumpkin_scalar.ts +0 -138
@@ -1,256 +1,256 @@
1
- import { AztecAddress } from '../aztec-address/index.js';
2
- import { toBigIntBE, toBufferBE, toHex } from '../bigint-buffer/index.js';
1
+ import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
3
2
  import { randomBytes } from '../crypto/index.js';
4
3
  import { BufferReader } from '../serialize/buffer_reader.js';
5
4
 
5
+ const ZERO_BUFFER = Buffer.alloc(32);
6
+
7
+ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
8
+
6
9
  /**
7
- * Fr represents a field of integers modulo the prime number MODULUS.
8
- * It provides utility functions to work with elements in this field, such as conversions between different representations and checks for equality and zero values. The elements can be serialized to and deserialized from byte buffers or strings.
9
- * Some use cases include working with cryptographic operations and finite fields.
10
+ * Represents a field derived from BaseField.
10
11
  */
11
- export class Fr {
12
- static ZERO = new Fr(0n);
13
- static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
14
- static MAX_VALUE = Fr.MODULUS - 1n;
15
- static SIZE_IN_BYTES = 32;
16
-
12
+ type DerivedField<T extends BaseField> = {
13
+ new (value: any): T;
17
14
  /**
18
- * The numeric value of the field element as a bigint.
15
+ * All derived fields will specify a MODULUS.
19
16
  */
20
- public readonly value: bigint;
21
-
22
- constructor(value: boolean | bigint | number | Fr | AztecAddress) {
23
- const isFr = (value: boolean | bigint | number | Fr | AztecAddress): value is Fr | AztecAddress =>
24
- !!(value as Fr).toBigInt;
25
- this.value = isFr(value) ? value.toBigInt() : BigInt(value);
26
- if (this.value > Fr.MAX_VALUE) {
27
- throw new Error(`Fr out of range ${value}.`);
28
- }
29
- }
17
+ MODULUS: bigint;
18
+ };
30
19
 
31
- /**
32
- * Generates a random Fr or Fq instance with a value modulo the respective class' MODULUS.
33
- * This method uses randomBytes to generate a random 32-byte buffer, converts it to a bigint
34
- * and takes the modulus of the result with the class' MODULUS constant.
35
- *
36
- * @returns A new Fr or Fq instance with a random value.
37
- */
38
- static random() {
39
- const r = toBigIntBE(randomBytes(Fr.SIZE_IN_BYTES)) % Fr.MODULUS;
40
- return new Fr(r);
41
- }
20
+ /**
21
+ * Base field class.
22
+ * Conversions from Buffer to BigInt and vice-versa are not cheap.
23
+ * We allow construction with either form and lazily convert to other as needed.
24
+ * We only check we are within the field modulus when initializing with bigint.
25
+ * If NODE_ENV === 'test', we will always initialize both types to check the modulus.
26
+ * This is also necessary in test environment as a lot of tests just use deep equality to check equality.
27
+ * WARNING: This could lead to a bugs in production that don't reveal in tests, but it's low risk.
28
+ */
29
+ abstract class BaseField {
30
+ static SIZE_IN_BYTES = 32;
31
+ private asBuffer?: Buffer;
32
+ private asBigInt?: bigint;
42
33
 
43
34
  /**
44
- * Returns a new zero-value field.
45
- * @returns A new zero-value field.
46
- */
47
- static zero() {
48
- return new Fr(0n);
35
+ * Return bigint representation.
36
+ * @deprecated Just to get things compiling. Use toBigInt().
37
+ * */
38
+ get value(): bigint {
39
+ return this.toBigInt();
49
40
  }
50
41
 
51
- /**
52
- * Create an instance of the corresponding class (Fr or Fq) from a Buffer or a BufferReader.
53
- * Reads 'SIZE_IN_BYTES' bytes from the given Buffer or BufferReader and constructs an instance with the decoded value.
54
- * If the input is a Buffer, it is internally converted to a BufferReader before reading.
55
- * Throws an error if the input length is invalid or the decoded value is out of range.
56
- *
57
- * @param buffer - The Buffer or BufferReader containing the bytes representing the value.
58
- * @returns An instance of the corresponding class (Fr or Fq) with the decoded value.
59
- */
60
- static fromBuffer(buffer: Buffer | BufferReader) {
61
- const reader = BufferReader.asReader(buffer);
62
- return new Fr(toBigIntBE(reader.readBytes(Fr.SIZE_IN_BYTES)));
63
- }
42
+ protected constructor(value: number | bigint | boolean | BaseField | Buffer) {
43
+ if (value instanceof Buffer) {
44
+ this.asBuffer =
45
+ value.length === 32 ? value : Buffer.concat([Buffer.alloc(BaseField.SIZE_IN_BYTES - value.length), value]);
46
+ } else if (typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean') {
47
+ this.asBigInt = BigInt(value);
48
+ if (this.asBigInt >= this.modulus()) {
49
+ throw new Error('Value >= to field modulus.');
50
+ }
51
+ } else if (value instanceof BaseField) {
52
+ this.asBuffer = value.asBuffer;
53
+ this.asBigInt = value.asBigInt;
54
+ } else {
55
+ throw new Error(`Type '${typeof value}' with value '${value}' passed to BaseField ctor.`);
56
+ }
64
57
 
65
- /**
66
- * Create a Fr instance from a hex-encoded string.
67
- * The input 'address' can be either prefixed with '0x' or not, and should have exactly 64 hex characters.
68
- * Throws an error if the input length is invalid or the address value is out of range.
69
- *
70
- * @param address - The hex-encoded string representing the field element.
71
- * @returns A Fr instance.
72
- */
73
- static fromString(address: string) {
74
- return Fr.fromBuffer(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
58
+ // Loads of our tests are just doing deep equality rather than calling e.g. toBigInt() first.
59
+ // This ensures the deep equality passes regardless of the internal representation.
60
+ // It also ensures the value range is checked even when initializing as a buffer.
61
+ if (process.env.NODE_ENV === 'test') {
62
+ this.toBuffer();
63
+ this.toBigInt();
64
+ }
75
65
  }
76
66
 
67
+ protected abstract modulus(): bigint;
68
+
77
69
  /**
78
- * Converts the value of the instance to a buffer with a specified length.
79
- * The method uses the provided value and size in bytes to create a buffer representation
80
- * of the numeric value. This can be useful for serialization and communication purposes.
81
- *
82
- * @returns A buffer representing the instance's value.
70
+ * We return a copy of the Buffer to ensure this remains immutable.
83
71
  */
84
- toBuffer() {
85
- return toBufferBE(this.value, Fr.SIZE_IN_BYTES);
72
+ toBuffer(): Buffer {
73
+ if (!this.asBuffer) {
74
+ this.asBuffer = toBufferBE(this.asBigInt!, 32);
75
+ }
76
+ return Buffer.from(this.asBuffer);
86
77
  }
87
78
 
88
- /**
89
- * Converts the value of the Fr or Fq class instance to a hexadecimal string.
90
- * The resulting string is prefixed with '0x' and represents the bigint value
91
- * in base 16.
92
- *
93
- * @param padTo32 - Whether to pad the string to 32 bytes.
94
- * @returns A hex-encoded string representing the value of the class instance.
95
- */
96
- toString(padTo32 = false): `0x${string}` {
97
- return toHex(this.value, padTo32);
79
+ toString(): `0x${string}` {
80
+ return `0x${this.toBuffer().toString('hex')}`;
98
81
  }
99
82
 
100
- /**
101
- * Retrieves the underlying bigint.
102
- * This method mostly exists to match user expectations, as value is already public.
103
- * @returns The underlying bigint.
104
- */
105
- public toBigInt(): bigint {
106
- return this.value;
83
+ toBigInt(): bigint {
84
+ if (this.asBigInt === undefined) {
85
+ this.asBigInt = toBigIntBE(this.asBuffer!);
86
+ if (this.asBigInt >= this.modulus()) {
87
+ throw new Error('Value >= to field modulus.');
88
+ }
89
+ }
90
+ return this.asBigInt;
107
91
  }
108
92
 
109
- /**
110
- * Returns a shortened string representation of the Fr value, formatted with '0x' prefix and ellipsis in the middle.
111
- * The resulting string has first 10 characters (including '0x') and last 4 characters of the full hexadecimal value.
112
- *
113
- * @returns A shorter, human-readable string representation of the Fr value.
114
- */
115
- toShortString() {
93
+ toShortString(): string {
116
94
  const str = this.toString();
117
95
  return `${str.slice(0, 10)}...${str.slice(-4)}`;
118
96
  }
119
97
 
120
- /**
121
- * Checks if the provided Fr instance is equal to the current instance.
122
- * Two instances are considered equal if their 'value' properties are the same.
123
- *
124
- * @param rhs - The Fr instance to compare with the current instance.
125
- * @returns A boolean indicating whether the two instances are equal.
126
- */
127
- equals(rhs: Fr) {
128
- return this.value === rhs.value;
98
+ equals(rhs: BaseField): boolean {
99
+ return this.toBuffer().equals(rhs.toBuffer());
129
100
  }
130
101
 
131
- /**
132
- * Check if the instance value is zero.
133
- * The method returns true if the value of the instance is 0n (zero in BigInt representation),
134
- * otherwise, it returns false.
135
- *
136
- * @returns A boolean indicating whether the instance value is zero or not.
137
- */
138
- isZero() {
139
- return this.value === 0n;
102
+ isZero(): boolean {
103
+ return this.toBuffer().equals(ZERO_BUFFER);
140
104
  }
141
105
 
142
- /**
143
- * Converts the current value of the Fq or Fr instance to a friendly JSON representation.
144
- * The output will be a hexadecimal string prefixed with '0x'.
145
- *
146
- * @returns A '0x' prefixed hexadecimal string representing the current value.
147
- */
148
- toFriendlyJSON() {
149
- return this.toString();
106
+ toFriendlyJSON(): string {
107
+ return `0x${this.toBigInt().toString()}`;
150
108
  }
151
109
 
152
- /** Returns self. */
153
110
  toField() {
154
111
  return this;
155
112
  }
156
113
  }
157
114
 
158
115
  /**
159
- * Fq represents a field element in a prime finite field with modulus defined by the constant MODULUS.
160
- * It provides methods for creating, manipulating, and comparing field elements, as well as converting
161
- * them to/from different data types like Buffers and hex strings. Field elements are used in various
162
- * cryptographic protocols and operations, such as elliptic curve cryptography.
163
- *
164
- * @example
165
- * const fqElem = new Fq(BigInt("123456789"));
166
- * const randomFqElem = Fq.random();
167
- * const fromBufferFqElem = Fq.fromBuffer(buffer);
116
+ * Constructs a field from a Buffer of BufferReader.
117
+ * It maybe not read the full 32 bytes if the Buffer is shorter, but it will padded in BaseField constructor.
168
118
  */
169
- export class Fq {
170
- static MODULUS = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n;
171
- static MAX_VALUE = Fr.MODULUS - 1n;
172
- static SIZE_IN_BYTES = 32;
119
+ function fromBuffer<T extends BaseField>(buffer: Buffer | BufferReader, f: DerivedField<T>) {
120
+ const reader = BufferReader.asReader(buffer);
121
+ return new f(reader.readBytes(BaseField.SIZE_IN_BYTES));
122
+ }
173
123
 
174
- constructor(
175
- /**
176
- * The element's value as a bigint in the finite field.
177
- */
178
- public readonly value: bigint,
179
- ) {
180
- if (value > Fq.MAX_VALUE) {
181
- throw new Error(`Fq out of range ${value}.`);
182
- }
124
+ /**
125
+ * Constructs a field from a Buffer, but reduces it first.
126
+ * This requires a conversion to a bigint first so the initial underlying representation will be a bigint.
127
+ */
128
+ function fromBufferReduce<T extends BaseField>(buffer: Buffer, f: DerivedField<T>) {
129
+ return new f(toBigIntBE(buffer) % f.MODULUS);
130
+ }
131
+
132
+ /**
133
+ * To ensure a field is uniformly random, it's important to reduce a 512 bit value.
134
+ * If you reduced a 256 bit number, there would a be a high skew in the lower range of the field.
135
+ */
136
+ function random<T extends BaseField>(f: DerivedField<T>): T {
137
+ return fromBufferReduce(randomBytes(64), f);
138
+ }
139
+
140
+ /**
141
+ * Constructs a field from a 0x prefixed hex string.
142
+ */
143
+ function fromString<T extends BaseField>(buf: string, f: DerivedField<T>) {
144
+ const buffer = Buffer.from(buf.replace(/^0x/i, ''), 'hex');
145
+ return new f(buffer);
146
+ }
147
+
148
+ /**
149
+ * Branding to ensure fields are not interchangeable types.
150
+ */
151
+ export interface Fr {
152
+ /** Brand. */
153
+ _branding: 'Fr';
154
+ }
155
+
156
+ /**
157
+ * Fr field class.
158
+ */
159
+ export class Fr extends BaseField {
160
+ static ZERO = new Fr(0n);
161
+ static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
162
+
163
+ constructor(value: number | bigint | boolean | Fr | Buffer) {
164
+ super(value);
165
+ }
166
+
167
+ protected modulus() {
168
+ return Fr.MODULUS;
183
169
  }
184
170
 
185
- /**
186
- * Generates a random Fr or Fq instance with a value within the range of their respective modulus.
187
- * The random value is generated from a byte array of length equal to SIZE_IN_BYTES, then truncated
188
- * to the appropriate modulus before creating the new Fr or Fq instance.
189
- *
190
- * @returns A new Fr or Fq instance with a randomly generated value.
191
- */
192
171
  static random() {
193
- const r = toBigIntBE(randomBytes(64)) % Fq.MODULUS;
194
- return new this(r);
172
+ return random(Fr);
173
+ }
174
+
175
+ static zero() {
176
+ return Fr.ZERO;
195
177
  }
196
178
 
197
- /**
198
- * Create an instance of the calling class (Fr or Fq) from a given buffer or BufferReader.
199
- * Reads SIZE_IN_BYTES from the provided buffer and converts it to a bigint, then creates a new instance
200
- * with that value. Throws an error if the value is out of range for the calling class.
201
- *
202
- * @param buffer - The input buffer or BufferReader containing the bytes representing the value.
203
- * @returns An instance of the calling class (Fr or Fq) initialized with the bigint value.
204
- */
205
179
  static fromBuffer(buffer: Buffer | BufferReader) {
206
- const reader = BufferReader.asReader(buffer);
207
- return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
180
+ return fromBuffer(buffer, Fr);
208
181
  }
209
182
 
210
- /**
211
- * Converts the bigint value of the instance to a Buffer representation.
212
- * The output buffer has a fixed size, determined by the 'SIZE_IN_BYTES' constant.
213
- *
214
- * @returns A Buffer containing the byte representation of the instance's value.
215
- */
216
- toBuffer() {
217
- return toBufferBE(this.value, Fq.SIZE_IN_BYTES);
183
+ static fromBufferReduce(buffer: Buffer) {
184
+ return fromBufferReduce(buffer, Fr);
218
185
  }
219
186
 
220
- /**
221
- * Converts the Fq value to a hexadecimal string representation.
222
- * The resulting string is prefixed with '0x' and contains the exact number of hex characters required
223
- * to represent the numeric value of this instance.
224
- *
225
- * @returns A hexadecimal string representing the Fq value.
226
- */
227
- toString() {
228
- return toHex(this.value);
187
+ static fromString(buf: string) {
188
+ return fromString(buf, Fr);
229
189
  }
190
+ }
230
191
 
231
- /**
232
- * Check if the value of the current instance is zero.
233
- * This function compares the internal 'value' property with 0n (BigInt representation of zero).
234
- * Returns true if the value is zero, otherwise returns false.
235
- *
236
- * @returns A boolean indicating whether the value is zero or not.
237
- */
238
- isZero() {
239
- return this.value === 0n;
192
+ /**
193
+ * Branding to ensure fields are not interchangeable types.
194
+ */
195
+ export interface Fq {
196
+ /** Brand. */
197
+ _branding: 'Fq';
198
+ }
199
+
200
+ /**
201
+ * Fq field class.
202
+ */
203
+ export class Fq extends BaseField {
204
+ static ZERO = new Fq(0n);
205
+ static MODULUS = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n;
206
+ private static HIGH_SHIFT = BigInt((BaseField.SIZE_IN_BYTES / 2) * 8);
207
+ private static LOW_MASK = (1n << Fq.HIGH_SHIFT) - 1n;
208
+
209
+ get low(): Fr {
210
+ return new Fr(this.toBigInt() & Fq.LOW_MASK);
240
211
  }
241
212
 
242
- /**
243
- * Converts the value of the Fr or Fq instance to a friendly JSON format.
244
- * The output is a hexadecimal string representation of the value with '0x' prefix.
245
- *
246
- * @returns A string representing the value in the JSON format.
247
- */
248
- toFriendlyJSON() {
249
- return this.toString();
213
+ get high(): Fr {
214
+ return new Fr(this.toBigInt() >> Fq.HIGH_SHIFT);
250
215
  }
251
216
 
252
- /** Returns self. */
253
- toField() {
254
- return this;
217
+ constructor(value: number | bigint | boolean | Fq | Buffer) {
218
+ super(value);
219
+ }
220
+
221
+ protected modulus() {
222
+ return Fq.MODULUS;
223
+ }
224
+
225
+ static random() {
226
+ return random(Fq);
227
+ }
228
+
229
+ static zero() {
230
+ return Fq.ZERO;
231
+ }
232
+
233
+ static fromBuffer(buffer: Buffer | BufferReader) {
234
+ return fromBuffer(buffer, Fq);
235
+ }
236
+
237
+ static fromBufferReduce(buffer: Buffer) {
238
+ return fromBufferReduce(buffer, Fq);
239
+ }
240
+
241
+ static fromString(buf: string) {
242
+ return fromString(buf, Fq);
243
+ }
244
+
245
+ static fromHighLow(high: Fr, low: Fr): Fq {
246
+ return new Fq((high.toBigInt() << Fq.HIGH_SHIFT) + low.toBigInt());
255
247
  }
256
248
  }
249
+
250
+ /**
251
+ * GrumpkinScalar is an Fq.
252
+ * @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
253
+ * the Aztec Yellow Paper.
254
+ */
255
+ export type GrumpkinScalar = Fq;
256
+ export const GrumpkinScalar = Fq;
@@ -1,4 +1,3 @@
1
1
  export * from './fields.js';
2
2
  export * from './point.js';
3
3
  export * from './coordinate.js';
4
- export * from './grumpkin_scalar.js';
@@ -72,8 +72,8 @@ export class Point {
72
72
  */
73
73
  toBigInts() {
74
74
  return {
75
- x: this.x.value,
76
- y: this.y.value,
75
+ x: this.x.toBigInt(),
76
+ y: this.y.toBigInt(),
77
77
  };
78
78
  }
79
79
 
@@ -120,6 +120,10 @@ export class Point {
120
120
  equals(rhs: Point) {
121
121
  return this.x.equals(rhs.x) && this.y.equals(rhs.y);
122
122
  }
123
+
124
+ isZero() {
125
+ return this.x.isZero() && this.y.isZero();
126
+ }
123
127
  }
124
128
 
125
129
  /**
@@ -128,7 +132,9 @@ export class Point {
128
132
  * @returns Whether it looks like a point.
129
133
  */
130
134
  export function isPoint(obj: object): obj is Point {
131
- if (!obj) return false;
135
+ if (!obj) {
136
+ return false;
137
+ }
132
138
  const point = obj as Point;
133
139
  return point.kind === 'point' && point.x !== undefined && point.y !== undefined;
134
140
  }
@@ -1,4 +1,4 @@
1
- import { assert, hasOwnProperty } from './js_utils.js';
1
+ import { assert } from './js_utils.js';
2
2
 
3
3
  /**
4
4
  * Represents a class compatible with our class conversion system.
@@ -133,7 +133,7 @@ export class ClassConverter {
133
133
  register(type: string, class_: IOClass, encoding: ClassEncoding) {
134
134
  assert(type !== 'Buffer', "'Buffer' handling is hardcoded. Cannot use as name.");
135
135
  assert(
136
- hasOwnProperty(class_.prototype, 'toString') || hasOwnProperty(class_.prototype, 'toJSON'),
136
+ class_.prototype['toString'] || class_.prototype['toJSON'],
137
137
  `Class ${type} must define a toString() OR toJSON() method.`,
138
138
  );
139
139
  assert(
@@ -197,9 +197,13 @@ export class ClassConverter {
197
197
  */
198
198
  private lookupObject(classObj: any) {
199
199
  const nameResult = this.toName.get(classObj.constructor);
200
- if (nameResult) return { type: nameResult[0], encoding: nameResult[1] };
200
+ if (nameResult) {
201
+ return { type: nameResult[0], encoding: nameResult[1] };
202
+ }
201
203
  const classResult = this.toClass.get(classObj.constructor.name);
202
- if (classResult) return { type: classObj.constructor.name, encoding: classResult[1] };
204
+ if (classResult) {
205
+ return { type: classObj.constructor.name, encoding: classResult[1] };
206
+ }
203
207
  throw new Error(`Could not find class ${classObj.constructor.name} in lookup.`);
204
208
  }
205
209
  }
@@ -123,7 +123,9 @@ export function createJsonRpcClient<T extends object>(
123
123
  {},
124
124
  {
125
125
  get: (target, rpcMethod: string) => {
126
- if (['then', 'catch'].includes(rpcMethod)) return Reflect.get(target, rpcMethod);
126
+ if (['then', 'catch'].includes(rpcMethod)) {
127
+ return Reflect.get(target, rpcMethod);
128
+ }
127
129
  return (...params: any[]) => {
128
130
  debug(format(`JsonRpcClient.constructor`, 'proxy', rpcMethod, '<-', params));
129
131
  return request(rpcMethod, params);
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-console */
2
- import { LogFn } from './index.js';
2
+ import { LogFn } from './log_fn.js';
3
3
 
4
4
  /**
5
5
  * ConsoleLogger is a utility class that provides customizable console logging functionality.
package/src/log/debug.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug';
2
2
 
3
- import { LogFn } from './index.js';
3
+ import { LogFn } from './log_fn.js';
4
4
 
5
5
  let preLogHook: ((...args: any[]) => void) | undefined;
6
6
  let postLogHook: ((...args: any[]) => void) | undefined;
package/src/log/index.ts CHANGED
@@ -1,10 +1,5 @@
1
- /** Structured log data to include with the message. */
2
- export type LogData = Record<string, string | number | bigint | boolean>;
3
-
4
- /** A callable logger instance. */
5
- export type LogFn = (msg: string, data?: LogData) => void;
6
-
7
1
  export * from './console.js';
8
2
  export * from './debug.js';
9
3
  export * from './logger.js';
10
4
  export * from './log_history.js';
5
+ export * from './log_fn.js';
@@ -0,0 +1,5 @@
1
+ /** Structured log data to include with the message. */
2
+ export type LogData = Record<string, string | number | bigint | boolean>;
3
+
4
+ /** A callable logger instance. */
5
+ export type LogFn = (msg: string, data?: LogData) => void;
package/src/log/logger.ts CHANGED
@@ -2,7 +2,7 @@ import debug from 'debug';
2
2
  import isNode from 'detect-node';
3
3
  import { isatty } from 'tty';
4
4
 
5
- import { LogData, LogFn } from './index.js';
5
+ import { LogData, LogFn } from './log_fn.js';
6
6
 
7
7
  // Matches a subset of Winston log levels
8
8
  const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug'] as const;
@@ -39,7 +39,9 @@ export type DebugLogger = LogFn & Logger;
39
39
  */
40
40
  export function createDebugLogger(name: string): DebugLogger {
41
41
  const debugLogger = debug(name);
42
- if (currentLevel === 'debug') debugLogger.enabled = true;
42
+ if (currentLevel === 'debug') {
43
+ debugLogger.enabled = true;
44
+ }
43
45
 
44
46
  const logger = {
45
47
  silent: () => {},
@@ -78,7 +80,9 @@ function logWithDebug(debug: debug.Debugger, level: LogLevel, msg: string, data?
78
80
 
79
81
  msg = data ? `${msg} ${fmtLogData(data)}` : msg;
80
82
  if (debug.enabled) {
81
- if (level !== 'debug') msg = `${level.toUpperCase()} ${msg}`;
83
+ if (level !== 'debug') {
84
+ msg = `${level.toUpperCase()} ${msg}`;
85
+ }
82
86
  debug(msg);
83
87
  } else if (LogLevels.indexOf(level) <= LogLevels.indexOf(currentLevel)) {
84
88
  printLog(`${getPrefix(debug, level)} ${msg}`);
@@ -94,7 +98,9 @@ function logWithDebug(debug: debug.Debugger, level: LogLevel, msg: string, data?
94
98
  function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
95
99
  const levelLabel = currentLevel !== level ? ` ${level.toUpperCase()}` : '';
96
100
  const prefix = `${debugLogger.namespace.replace(/^aztec:/, '')}${levelLabel}`;
97
- if (!isNode || !isatty(process.stderr.fd)) return prefix;
101
+ if (!isNode || !isatty(process.stderr.fd)) {
102
+ return prefix;
103
+ }
98
104
  const colorIndex = debug.selectColor(debugLogger.namespace) as number;
99
105
  const colorCode = '\u001B[3' + (colorIndex < 8 ? colorIndex : '8;5;' + colorIndex);
100
106
  return ` ${colorCode};1m${prefix}\u001B[0m`;
@@ -1,4 +1,3 @@
1
- import { Fq, Fr } from '../fields/fields.js';
2
1
  import { Tuple } from './types.js';
3
2
 
4
3
  /**
@@ -83,27 +82,6 @@ export class BufferReader {
83
82
  return Buffer.from(this.buffer.subarray(this.index - n, this.index));
84
83
  }
85
84
 
86
- /**
87
- * Reads a Fr (finite field) element from the buffer using the 'fromBuffer' method of the Fr class.
88
- * The Fr class should provide a 'fromBuffer' method that takes a BufferReader instance as input.
89
- *
90
- * @returns An instance of the Fr class representing the finite field element.
91
- */
92
- public readFr(): Fr {
93
- return Fr.fromBuffer(this);
94
- }
95
-
96
- /**
97
- * Reads the next Fq element from the buffer using the Fq.fromBuffer method.
98
- * The Fq element represents a finite field in elliptic curve cryptography and is used for calculations.
99
- * Advances the internal buffer index by the number of bytes read.
100
- *
101
- * @returns An Fq instance representing the finite field element.
102
- */
103
- public readFq(): Fq {
104
- return Fq.fromBuffer(this);
105
- }
106
-
107
85
  /**
108
86
  * Reads a vector of numbers from the buffer and returns it as an array of numbers.
109
87
  * The method utilizes the 'readVector' method, passing a deserializer that reads numbers.