@aztec/foundation 0.0.1-commit.6d63667d → 0.0.1-commit.7b97ef96e

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 (51) hide show
  1. package/dest/array/sorted_array.d.ts +6 -1
  2. package/dest/array/sorted_array.d.ts.map +1 -1
  3. package/dest/array/sorted_array.js +18 -15
  4. package/dest/config/env_var.d.ts +2 -2
  5. package/dest/config/env_var.d.ts.map +1 -1
  6. package/dest/config/network_name.d.ts +2 -2
  7. package/dest/config/network_name.d.ts.map +1 -1
  8. package/dest/config/network_name.js +2 -0
  9. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  10. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  11. package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
  12. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  13. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  14. package/dest/json-rpc/server/api_key_auth.js +57 -0
  15. package/dest/json-rpc/server/index.d.ts +2 -1
  16. package/dest/json-rpc/server/index.d.ts.map +1 -1
  17. package/dest/json-rpc/server/index.js +1 -0
  18. package/dest/log/bigint-utils.d.ts +5 -0
  19. package/dest/log/bigint-utils.d.ts.map +1 -0
  20. package/dest/log/bigint-utils.js +18 -0
  21. package/dest/log/gcloud-logger-config.d.ts +1 -1
  22. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  23. package/dest/log/gcloud-logger-config.js +3 -0
  24. package/dest/log/log-filters.d.ts +17 -4
  25. package/dest/log/log-filters.d.ts.map +1 -1
  26. package/dest/log/log-filters.js +26 -12
  27. package/dest/log/pino-logger.d.ts +1 -1
  28. package/dest/log/pino-logger.d.ts.map +1 -1
  29. package/dest/log/pino-logger.js +6 -2
  30. package/dest/queue/base_memory_queue.d.ts +2 -2
  31. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  32. package/dest/serialize/buffer_reader.d.ts +8 -1
  33. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  34. package/dest/serialize/buffer_reader.js +13 -0
  35. package/dest/serialize/serialize.d.ts +19 -1
  36. package/dest/serialize/serialize.d.ts.map +1 -1
  37. package/dest/serialize/serialize.js +31 -0
  38. package/package.json +2 -2
  39. package/src/array/sorted_array.ts +22 -17
  40. package/src/config/env_var.ts +24 -2
  41. package/src/config/network_name.ts +4 -1
  42. package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
  43. package/src/json-rpc/server/api_key_auth.ts +63 -0
  44. package/src/json-rpc/server/index.ts +1 -0
  45. package/src/log/bigint-utils.ts +22 -0
  46. package/src/log/gcloud-logger-config.ts +5 -0
  47. package/src/log/log-filters.ts +29 -11
  48. package/src/log/pino-logger.ts +6 -2
  49. package/src/queue/base_memory_queue.ts +1 -1
  50. package/src/serialize/buffer_reader.ts +15 -0
  51. package/src/serialize/serialize.ts +32 -0
@@ -269,6 +269,22 @@ export function serializeBigInt(n: bigint, width = 32) {
269
269
  return toBufferBE(n, width);
270
270
  }
271
271
 
272
+ /**
273
+ * Serialize a signed BigInt value into a Buffer of specified width using two's complement.
274
+ * @param n - The signed BigInt value to be serialized.
275
+ * @param width - The width (in bytes) of the output Buffer, optional with default value 32.
276
+ * @returns A Buffer containing the serialized signed BigInt value in big-endian format.
277
+ */
278
+ export function serializeSignedBigInt(n: bigint, width = 32) {
279
+ const widthBits = BigInt(width * 8);
280
+ const max = 1n << (widthBits - 1n);
281
+ if (n < -max || n >= max) {
282
+ throw new Error(`Signed BigInt ${n.toString()} does not fit into ${width} bytes`);
283
+ }
284
+ const unsigned = n < 0n ? (1n << widthBits) + n : n;
285
+ return toBufferBE(unsigned, width);
286
+ }
287
+
272
288
  /**
273
289
  * Deserialize a big integer from a buffer, given an offset and width.
274
290
  * Reads the specified number of bytes from the buffer starting at the offset, converts it to a big integer, and returns the deserialized result along with the number of bytes read (advanced).
@@ -282,6 +298,22 @@ export function deserializeBigInt(buf: Buffer, offset = 0, width = 32) {
282
298
  return { elem: toBigIntBE(buf.subarray(offset, offset + width)), adv: width };
283
299
  }
284
300
 
301
+ /**
302
+ * Deserialize a signed BigInt from a buffer (two's complement).
303
+ * @param buf - The buffer containing the signed big integer to be deserialized.
304
+ * @param offset - The position in the buffer where the integer starts. Defaults to 0.
305
+ * @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
306
+ * @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
307
+ */
308
+ export function deserializeSignedBigInt(buf: Buffer, offset = 0, width = 32) {
309
+ const { elem, adv } = deserializeBigInt(buf, offset, width);
310
+ const widthBits = BigInt(width * 8);
311
+ const signBit = 1n << (widthBits - 1n);
312
+ const fullRange = 1n << widthBits;
313
+ const signed = elem >= signBit ? elem - fullRange : elem;
314
+ return { elem: signed, adv };
315
+ }
316
+
285
317
  /**
286
318
  * Serializes a Date object into a Buffer containing its timestamp as a big integer value.
287
319
  * The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.