@aztec/foundation 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f
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.
- package/dest/bigint-buffer/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts.map +1 -1
- package/dest/bigint-buffer/index.js +6 -1
- package/dest/branded-types/block_number.d.ts +3 -3
- package/dest/branded-types/block_number.d.ts.map +1 -1
- package/dest/branded-types/block_number.js +15 -4
- package/dest/branded-types/buffer32_hash.d.ts +27 -0
- package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
- package/dest/branded-types/buffer32_hash.js +12 -0
- package/dest/branded-types/checkpoint_number.d.ts +9 -3
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
- package/dest/branded-types/checkpoint_number.js +11 -0
- package/dest/branded-types/epoch.d.ts +2 -2
- package/dest/branded-types/epoch.d.ts.map +1 -1
- package/dest/branded-types/index.d.ts +2 -1
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +1 -0
- package/dest/branded-types/index_within_checkpoint.d.ts +2 -2
- package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -1
- package/dest/branded-types/slot.d.ts +2 -2
- package/dest/branded-types/slot.d.ts.map +1 -1
- package/dest/buffer/buffer16.d.ts +3 -1
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer32.d.ts +28 -61
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +29 -63
- package/dest/collection/array.d.ts +9 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +18 -0
- package/dest/collection/index.d.ts +3 -1
- package/dest/collection/index.d.ts.map +1 -1
- package/dest/collection/index.js +2 -0
- package/dest/collection/lru_map.d.ts +41 -0
- package/dest/collection/lru_map.d.ts.map +1 -0
- package/dest/collection/lru_map.js +119 -0
- package/dest/collection/lru_set.d.ts +35 -0
- package/dest/collection/lru_set.d.ts.map +1 -0
- package/dest/collection/lru_set.js +95 -0
- package/dest/committable/committable.js +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +67 -37
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +72 -71
- package/dest/config/network_config.d.ts +11 -55
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +2 -2
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +3 -3
- package/dest/config/secret_value.d.ts +2 -2
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/crypto/aes128/index.d.ts +2 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +11 -2
- package/dest/crypto/bls/bn254_keystore.d.ts +10 -177
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/bn254_keystore.js +22 -34
- package/dest/crypto/keys/index.d.ts +3 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +30 -6
- package/dest/crypto/schnorr/index.d.ts +8 -7
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +6 -6
- package/dest/crypto/schnorr/signature.d.ts +9 -29
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +20 -36
- package/dest/curves/bls12/field.d.ts +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -1
- package/dest/curves/bls12/field.js +0 -5
- package/dest/curves/bls12/point.d.ts +2 -2
- package/dest/curves/bls12/point.d.ts.map +1 -1
- package/dest/curves/bn254/field.d.ts +23 -19
- package/dest/curves/bn254/field.d.ts.map +1 -1
- package/dest/curves/bn254/field.js +23 -17
- package/dest/curves/grumpkin/point.d.ts +15 -29
- package/dest/curves/grumpkin/point.d.ts.map +1 -1
- package/dest/curves/grumpkin/point.js +31 -48
- package/dest/eth-address/index.d.ts +2 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +0 -3
- package/dest/eth-signature/eth_signature.d.ts +2 -2
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/fifo/fifo_frame_reader.d.ts +41 -0
- package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
- package/dest/fifo/fifo_frame_reader.js +91 -0
- package/dest/fifo/index.d.ts +2 -0
- package/dest/fifo/index.d.ts.map +1 -0
- package/dest/fifo/index.js +1 -0
- package/dest/fifo_set/fifo_set.d.ts +15 -0
- package/dest/fifo_set/fifo_set.d.ts.map +1 -0
- package/dest/fifo_set/fifo_set.js +39 -0
- package/dest/fifo_set/index.d.ts +2 -0
- package/dest/fifo_set/index.d.ts.map +1 -0
- package/dest/fifo_set/index.js +1 -0
- package/dest/jest/setup.js +24 -0
- package/dest/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +4 -3
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +5 -4
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +5 -3
- package/dest/json-rpc/fixtures/test_state.d.ts +4 -8
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/test_state.js +57 -17
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +8 -3
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +27 -13
- package/dest/log/pino-logger.d.ts +1 -1
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +17 -2
- package/dest/noir/noir_package_config.d.ts +19 -104
- package/dest/noir/noir_package_config.d.ts.map +1 -1
- package/dest/noir/noir_package_config.js +1 -1
- package/dest/promise/running-promise.d.ts +5 -4
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +7 -3
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.js +1 -0
- package/dest/retry/index.d.ts +31 -3
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +44 -2
- package/dest/schemas/api.d.ts +11 -9
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/api.js +7 -1
- package/dest/schemas/parse.d.ts +4 -4
- package/dest/schemas/parse.d.ts.map +1 -1
- package/dest/schemas/parse.js +6 -5
- package/dest/schemas/schemas.d.ts +15 -15
- package/dest/schemas/types.d.ts +3 -3
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/utils.d.ts +7 -11
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +2 -18
- package/dest/serialize/buffer_reader.d.ts +7 -20
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +5 -18
- package/dest/serialize/buffer_sink.d.ts +134 -0
- package/dest/serialize/buffer_sink.d.ts.map +1 -0
- package/dest/serialize/buffer_sink.js +297 -0
- package/dest/serialize/field_reader.d.ts +5 -13
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +0 -13
- package/dest/serialize/index.d.ts +2 -1
- package/dest/serialize/index.d.ts.map +1 -1
- package/dest/serialize/index.js +1 -0
- package/dest/sleep/index.d.ts +2 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +10 -1
- package/dest/string/index.js +1 -1
- package/dest/testing/files/index.d.ts +2 -3
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +1 -2
- package/dest/timer/date.d.ts +3 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +4 -0
- package/dest/timer/index.d.ts +2 -2
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +1 -1
- package/dest/timer/timeout.d.ts +3 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timeout.js +26 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
- package/dest/transport/index.d.ts +1 -2
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/trees/balanced_merkle_tree_root.d.ts +2 -3
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree_root.js +2 -3
- package/dest/trees/hasher.d.ts +3 -2
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +5 -5
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
- package/dest/trees/membership_witness.d.ts +2 -6
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +0 -9
- package/dest/trees/merkle_tree_calculator.d.ts +4 -2
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -5
- package/dest/trees/sibling_path.d.ts +5 -4
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +10 -8
- package/dest/trees/unbalanced_merkle_tree_root.d.ts +2 -3
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_root.js +2 -3
- package/dest/types/index.d.ts +23 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +15 -0
- package/package.json +6 -4
- package/src/bigint-buffer/index.ts +6 -1
- package/src/branded-types/block_number.ts +20 -2
- package/src/branded-types/buffer32_hash.ts +38 -0
- package/src/branded-types/checkpoint_number.ts +16 -1
- package/src/branded-types/epoch.ts +1 -1
- package/src/branded-types/index.ts +1 -0
- package/src/branded-types/index_within_checkpoint.ts +1 -1
- package/src/branded-types/slot.ts +1 -1
- package/src/buffer/buffer16.ts +3 -0
- package/src/buffer/buffer32.ts +39 -68
- package/src/collection/array.ts +20 -0
- package/src/collection/index.ts +2 -0
- package/src/collection/lru_map.ts +143 -0
- package/src/collection/lru_set.ts +115 -0
- package/src/committable/committable.ts +1 -1
- package/src/config/env_var.ts +51 -23
- package/src/config/index.ts +143 -122
- package/src/config/network_config.ts +1 -1
- package/src/config/network_name.ts +6 -6
- package/src/config/secret_value.ts +1 -1
- package/src/crypto/aes128/index.ts +11 -2
- package/src/crypto/bls/bn254_keystore.ts +33 -43
- package/src/crypto/keys/index.ts +20 -4
- package/src/crypto/schnorr/index.ts +9 -8
- package/src/crypto/schnorr/signature.ts +17 -46
- package/src/curves/bls12/field.ts +0 -7
- package/src/curves/bn254/field.ts +35 -34
- package/src/curves/grumpkin/point.ts +24 -44
- package/src/eth-address/index.ts +0 -4
- package/src/fifo/fifo_frame_reader.ts +113 -0
- package/src/fifo/index.ts +1 -0
- package/src/fifo_set/fifo_set.ts +52 -0
- package/src/fifo_set/index.ts +1 -0
- package/src/jest/setup.mjs +27 -0
- package/src/json-rpc/client/fetch.ts +4 -3
- package/src/json-rpc/client/safe_json_rpc_client.ts +5 -4
- package/src/json-rpc/client/undici.ts +5 -3
- package/src/json-rpc/fixtures/test_state.ts +10 -10
- package/src/json-rpc/server/safe_json_rpc_server.ts +31 -13
- package/src/log/pino-logger.ts +19 -2
- package/src/noir/noir_package_config.ts +32 -20
- package/src/promise/running-promise.ts +8 -5
- package/src/queue/batch_queue.ts +1 -0
- package/src/retry/index.ts +66 -4
- package/src/schemas/api.ts +21 -24
- package/src/schemas/parse.ts +9 -6
- package/src/schemas/schemas.ts +4 -4
- package/src/schemas/types.ts +2 -2
- package/src/schemas/utils.ts +4 -38
- package/src/serialize/buffer_reader.ts +6 -29
- package/src/serialize/buffer_sink.ts +350 -0
- package/src/serialize/field_reader.ts +4 -22
- package/src/serialize/index.ts +1 -0
- package/src/sleep/index.ts +10 -1
- package/src/string/index.ts +1 -1
- package/src/testing/files/index.ts +1 -2
- package/src/timer/date.ts +6 -0
- package/src/timer/index.ts +1 -1
- package/src/timer/timeout.ts +31 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
- package/src/transport/index.ts +0 -1
- package/src/trees/balanced_merkle_tree_root.ts +2 -5
- package/src/trees/hasher.ts +6 -3
- package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
- package/src/trees/membership_witness.ts +2 -10
- package/src/trees/merkle_tree_calculator.ts +4 -10
- package/src/trees/sibling_path.ts +11 -6
- package/src/trees/unbalanced_merkle_tree_root.ts +2 -5
- package/src/types/index.ts +47 -0
- package/dest/crypto/serialize.d.ts +0 -51
- package/dest/crypto/serialize.d.ts.map +0 -1
- package/dest/crypto/serialize.js +0 -68
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
- package/src/crypto/serialize.ts +0 -85
- package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer_reader.d.ts","sourceRoot":"","sources":["../../src/serialize/buffer_reader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAY;;IAGrB,OAAO,CAAC,MAAM;IAFhB,OAAO,CAAC,KAAK,CAAS;IACtB,YACU,MAAM,EAAE,MAAM,EACtB,MAAM,SAAI,EAGX;IAED;;;;;;;OAOG;IACH,OAAc,QAAQ,CAAC,cAAc,EAAE,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,YAAY,CAUvF;IAED,0EAA0E;I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ACI,SAAS,IAAI,MAAM,CAEzB;IAED;;;OAGG;IACI,cAAc,IAAI,MAAM,CAE9B;CASF;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC;CAC/B"}
|
|
@@ -224,28 +224,15 @@ import { toBigIntBE } from '../bigint-buffer/index.js';
|
|
|
224
224
|
return result;
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
|
-
* Read an array
|
|
228
|
-
*
|
|
227
|
+
* Read an array of a fixed size with elements of type T from the buffer.
|
|
228
|
+
* The 'itemDeserializer' object should have a 'fromBuffer' method that takes a BufferReader instance as input,
|
|
229
|
+
* and returns an instance of the desired deserialized data type T.
|
|
230
|
+
* This method will call the 'fromBuffer' method for each element in the array and return the resulting array.
|
|
229
231
|
*
|
|
230
|
-
* @param size - The number of elements
|
|
232
|
+
* @param size - The fixed number of elements in the array.
|
|
231
233
|
* @param itemDeserializer - An object with a 'fromBuffer' method to deserialize individual elements of type T.
|
|
232
234
|
* @returns An array of instances of type T.
|
|
233
235
|
*/ readArray(size, itemDeserializer) {
|
|
234
|
-
const result = new Array(size);
|
|
235
|
-
for(let i = 0; i < size; i++){
|
|
236
|
-
result[i] = itemDeserializer.fromBuffer(this);
|
|
237
|
-
}
|
|
238
|
-
return result;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Read a fixed-size tuple from the buffer using dense allocation (Array.from).
|
|
242
|
-
* Only use with compile-time constant sizes — the size parameter MUST NOT come from untrusted input
|
|
243
|
-
* as Array.from pre-allocates memory proportional to size.
|
|
244
|
-
*
|
|
245
|
-
* @param size - The fixed number of elements (must be a compile-time constant).
|
|
246
|
-
* @param itemDeserializer - An object with a 'fromBuffer' method to deserialize individual elements of type T.
|
|
247
|
-
* @returns A densely-allocated tuple of instances of type T.
|
|
248
|
-
*/ readTuple(size, itemDeserializer) {
|
|
249
236
|
const result = Array.from({
|
|
250
237
|
length: size
|
|
251
238
|
}, ()=>itemDeserializer.fromBuffer(this));
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value that can be appended to a {@link BufferSink}. Mirrors `Bufferable`, but the object arm allows the
|
|
3
|
+
* optional-sink overload of `toBuffer` so a legacy `toBuffer(): Buffer` and a migrated `toBuffer(sink?)` both fit.
|
|
4
|
+
*/
|
|
5
|
+
export type Sinkable = boolean | Buffer | Uint8Array | number | bigint | string | {
|
|
6
|
+
toBuffer(sink?: BufferSink): Buffer | void;
|
|
7
|
+
} | Sinkable[];
|
|
8
|
+
/**
|
|
9
|
+
* A growable, append-only binary sink backed by a single `ArrayBuffer`.
|
|
10
|
+
*
|
|
11
|
+
* It exists to replace the recursive `toBuffer()` chain — which allocates a `Buffer` at every node and
|
|
12
|
+
* `Buffer.concat`s at every level — with one buffer that the whole object graph streams into and that is sliced
|
|
13
|
+
* exactly once at the root. Encodings are big-endian, matching `serializeToBuffer` byte-for-byte.
|
|
14
|
+
*
|
|
15
|
+
* The migration contract is the optional-sink `toBuffer`:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* toBuffer(): Buffer;
|
|
19
|
+
* toBuffer(sink: BufferSink): void;
|
|
20
|
+
* toBuffer(sink?: BufferSink): Buffer | void {
|
|
21
|
+
* if (!sink) return BufferSink.serialize(this); // own a sink, fill it, slice once
|
|
22
|
+
* serializeToSink(sink, this.a, this.b, this.c); // stream into the caller's sink
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* When a sink is passed it writes and returns `undefined`; otherwise it returns its own buffer. Nodes that have
|
|
27
|
+
* not been migrated keep their plain `toBuffer(): Buffer` and are folded in via the return-value fallback in
|
|
28
|
+
* {@link serializeToSink}, so the tree stays valid at every step of an incremental migration.
|
|
29
|
+
*
|
|
30
|
+
* Performance note: bigints are written via `DataView.setBigUint64` limbs ({@link writeBigInt},
|
|
31
|
+
* {@link writeField}), NOT a per-byte shift loop. The limb form is ~16x faster than the legacy hex round-trip
|
|
32
|
+
* on field-heavy structures, and faster than the legacy path at every width — a naive per-byte shift loop is
|
|
33
|
+
* actually the slowest option, since each byte allocates a fresh BigInt. See the spike benchmark.
|
|
34
|
+
*/
|
|
35
|
+
export declare class BufferSink {
|
|
36
|
+
private buffer;
|
|
37
|
+
private view;
|
|
38
|
+
private offset;
|
|
39
|
+
constructor(initialCapacity?: number);
|
|
40
|
+
/** Number of bytes written so far. */
|
|
41
|
+
get length(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Serialize a migrated value into a fresh sink and return the single resulting buffer. This is the no-sink
|
|
44
|
+
* branch of every migrated `toBuffer`: one allocation, one slice, only at the root.
|
|
45
|
+
*
|
|
46
|
+
* @param obj - The value to serialize via its sink-aware `toBuffer`.
|
|
47
|
+
* @param initialCapacity - Optional size hint (e.g. from `getSize()`) to skip reallocations on hot paths.
|
|
48
|
+
*/
|
|
49
|
+
static serialize(obj: {
|
|
50
|
+
toBuffer(sink: BufferSink): void;
|
|
51
|
+
}, initialCapacity?: number): Buffer;
|
|
52
|
+
private ensure;
|
|
53
|
+
/** Append a single byte (0/1) for a boolean, matching `boolToBuffer`. */
|
|
54
|
+
writeBool(value: boolean): void;
|
|
55
|
+
/** Append an unsigned 8-bit integer. */
|
|
56
|
+
writeUInt8(value: number): void;
|
|
57
|
+
/** Append a big-endian unsigned 16-bit integer. */
|
|
58
|
+
writeUInt16(value: number): void;
|
|
59
|
+
/** Append a big-endian unsigned 32-bit integer, matching `numToUInt32BE`. */
|
|
60
|
+
writeNumber(value: number): void;
|
|
61
|
+
/** Append a big-endian unsigned 64-bit integer, matching `bigintToUInt64BE`. */
|
|
62
|
+
writeUInt64(value: bigint): void;
|
|
63
|
+
/**
|
|
64
|
+
* Append a non-negative bigint as a big-endian unsigned integer of `width` bytes (default 32), matching
|
|
65
|
+
* `serializeBigInt` / `toBufferBE`. Every width is written limb-wise via `setBigUint64` rather than the
|
|
66
|
+
* legacy per-byte BigInt shift loop — that loop allocated a fresh BigInt per byte and benchmarked as the
|
|
67
|
+
* *slowest* option (slower even than the legacy hex round-trip); the limb form is faster at every width.
|
|
68
|
+
*
|
|
69
|
+
* The bulk of the value is written as 64-bit big-endian limbs from the least-significant tail upward, and
|
|
70
|
+
* a final `width % 8` (at most 7) high bytes that don't fill a whole limb are written individually. The
|
|
71
|
+
* common widths (8/16/32) are exact multiples of 8, so they take the pure-limb path with no remainder.
|
|
72
|
+
* `width === 32` keeps its own straight-line four-limb form (shared with {@link writeField}) since it is
|
|
73
|
+
* the `Fr`/`Fq`/Chonk-proof hot path and the unrolled body is marginally faster than the loop.
|
|
74
|
+
*
|
|
75
|
+
* @param value - The non-negative bigint to serialize.
|
|
76
|
+
* @param width - Output width in bytes.
|
|
77
|
+
*/
|
|
78
|
+
writeBigInt(value: bigint, width?: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* Append a 32-byte (256-bit) big-endian non-negative bigint. Specialized form of {@link writeBigInt}
|
|
81
|
+
* with no width parameter and no width-branch, so V8 can inline the four `setBigUint64` limb writes
|
|
82
|
+
* without the wider branchy form's instability. This is the Fr/Fq leaf hot path; prefer it over
|
|
83
|
+
* `writeBigInt(value, 32)` in callers that always serialize 32-byte fields.
|
|
84
|
+
*/
|
|
85
|
+
writeField(value: bigint): void;
|
|
86
|
+
/**
|
|
87
|
+
* Append an array of field elements (or any objects exposing `toBigInt(): bigint`) as a contiguous
|
|
88
|
+
* sequence of 32-byte big-endian limbs. Iterates inline — no per-element `toBuffer` dispatch and no
|
|
89
|
+
* per-element function-call indirection through the generic sinkable dispatcher. Use this in classes
|
|
90
|
+
* that hold large flat field arrays (e.g. the 1632-element ChonkProof field list).
|
|
91
|
+
*/
|
|
92
|
+
writeFields(fields: ReadonlyArray<{
|
|
93
|
+
toBigInt(): bigint;
|
|
94
|
+
}>): void;
|
|
95
|
+
/** Append raw bytes verbatim (no length prefix), matching how a `Buffer`/`Uint8Array` is serialized inline. */
|
|
96
|
+
writeBytes(bytes: Uint8Array): void;
|
|
97
|
+
/** Append a string as a 4-byte big-endian length prefix followed by its UTF-8 bytes, matching the string case. */
|
|
98
|
+
writeString(value: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Reset the write cursor without releasing the backing buffer. Lets the same sink be reused across many
|
|
101
|
+
* serializations without reallocating — the per-call cost drops to the bytes written (no `new ArrayBuffer`).
|
|
102
|
+
* Any `Buffer` previously returned by {@link toBuffer} is a fresh copy and remains valid; any view from
|
|
103
|
+
* {@link asUint8Array} aliases the buffer and is invalidated.
|
|
104
|
+
*/
|
|
105
|
+
reset(): void;
|
|
106
|
+
/** Copy the written region into a freshly allocated `Buffer`. The single allocation of the whole serialization. */
|
|
107
|
+
toBuffer(): Buffer;
|
|
108
|
+
/** A zero-copy view of the written region. Valid only until the next write (which may reallocate). */
|
|
109
|
+
asUint8Array(): Uint8Array;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Streaming counterpart to `serializeToBufferArray`: walk a list of {@link Sinkable}s and append each to the sink.
|
|
113
|
+
* Dispatch matches `serializeToBufferArray` byte-for-byte. An object is serialized via `obj.toBuffer(sink)`; a
|
|
114
|
+
* migrated node writes into the sink and returns `undefined`, while a not-yet-migrated node ignores the argument
|
|
115
|
+
* and returns its `Buffer`, which we copy in. That return-value fallback is what makes the migration incremental.
|
|
116
|
+
*
|
|
117
|
+
* Dispatch is hot-pathed for the common case of objects exposing `toBuffer` (Fr/Fq and every other migrated leaf),
|
|
118
|
+
* and arrays recurse via an inner-array helper to avoid the per-call rest-args allocation that a spread-recurse
|
|
119
|
+
* would force on large flat arrays like the 1632-element ChonkProof field list.
|
|
120
|
+
*
|
|
121
|
+
* @param sink - The destination sink.
|
|
122
|
+
* @param objs - The values to serialize, in order.
|
|
123
|
+
*/
|
|
124
|
+
export declare function serializeToSink(sink: BufferSink, ...objs: Sinkable[]): void;
|
|
125
|
+
/**
|
|
126
|
+
* Streaming counterpart to `serializeArrayOfBufferableToVector`: write a length prefix (1 or 4 bytes) giving the
|
|
127
|
+
* number of serialized elements, then each element. Byte-identical to the buffer version.
|
|
128
|
+
*
|
|
129
|
+
* @param sink - The destination sink.
|
|
130
|
+
* @param objs - The vector elements.
|
|
131
|
+
* @param prefixLength - Width of the count prefix in bytes (1 or 4).
|
|
132
|
+
*/
|
|
133
|
+
export declare function serializeArrayToSink(sink: BufferSink, objs: Sinkable[], prefixLength?: number): void;
|
|
134
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVmZmVyX3NpbmsuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXJpYWxpemUvYnVmZmVyX3NpbmsudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7OztHQUdHO0FBQ0gsTUFBTSxNQUFNLFFBQVEsR0FDaEIsT0FBTyxHQUNQLE1BQU0sR0FDTixVQUFVLEdBQ1YsTUFBTSxHQUNOLE1BQU0sR0FDTixNQUFNLEdBQ047SUFBRSxRQUFRLENBQUMsSUFBSSxDQUFDLEVBQUUsVUFBVSxHQUFHLE1BQU0sR0FBRyxJQUFJLENBQUE7Q0FBRSxHQUM5QyxRQUFRLEVBQUUsQ0FBQztBQUtmOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQTBCRztBQUNILHFCQUFhLFVBQVU7SUFDckIsT0FBTyxDQUFDLE1BQU0sQ0FBYTtJQUMzQixPQUFPLENBQUMsSUFBSSxDQUFXO0lBQ3ZCLE9BQU8sQ0FBQyxNQUFNLENBQUs7SUFFbkIsWUFBWSxlQUFlLEdBQUUsTUFBaUMsRUFJN0Q7SUFFRCxzQ0FBc0M7SUFDdEMsSUFBVyxNQUFNLElBQUksTUFBTSxDQUUxQjtJQUVEOzs7Ozs7T0FNRztJQUNILE9BQWMsU0FBUyxDQUFDLEdBQUcsRUFBRTtRQUFFLFFBQVEsQ0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297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value that can be appended to a {@link BufferSink}. Mirrors `Bufferable`, but the object arm allows the
|
|
3
|
+
* optional-sink overload of `toBuffer` so a legacy `toBuffer(): Buffer` and a migrated `toBuffer(sink?)` both fit.
|
|
4
|
+
*/ const DEFAULT_INITIAL_CAPACITY = 1024;
|
|
5
|
+
const MASK_64 = (1n << 64n) - 1n;
|
|
6
|
+
/**
|
|
7
|
+
* A growable, append-only binary sink backed by a single `ArrayBuffer`.
|
|
8
|
+
*
|
|
9
|
+
* It exists to replace the recursive `toBuffer()` chain — which allocates a `Buffer` at every node and
|
|
10
|
+
* `Buffer.concat`s at every level — with one buffer that the whole object graph streams into and that is sliced
|
|
11
|
+
* exactly once at the root. Encodings are big-endian, matching `serializeToBuffer` byte-for-byte.
|
|
12
|
+
*
|
|
13
|
+
* The migration contract is the optional-sink `toBuffer`:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* toBuffer(): Buffer;
|
|
17
|
+
* toBuffer(sink: BufferSink): void;
|
|
18
|
+
* toBuffer(sink?: BufferSink): Buffer | void {
|
|
19
|
+
* if (!sink) return BufferSink.serialize(this); // own a sink, fill it, slice once
|
|
20
|
+
* serializeToSink(sink, this.a, this.b, this.c); // stream into the caller's sink
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* When a sink is passed it writes and returns `undefined`; otherwise it returns its own buffer. Nodes that have
|
|
25
|
+
* not been migrated keep their plain `toBuffer(): Buffer` and are folded in via the return-value fallback in
|
|
26
|
+
* {@link serializeToSink}, so the tree stays valid at every step of an incremental migration.
|
|
27
|
+
*
|
|
28
|
+
* Performance note: bigints are written via `DataView.setBigUint64` limbs ({@link writeBigInt},
|
|
29
|
+
* {@link writeField}), NOT a per-byte shift loop. The limb form is ~16x faster than the legacy hex round-trip
|
|
30
|
+
* on field-heavy structures, and faster than the legacy path at every width — a naive per-byte shift loop is
|
|
31
|
+
* actually the slowest option, since each byte allocates a fresh BigInt. See the spike benchmark.
|
|
32
|
+
*/ export class BufferSink {
|
|
33
|
+
buffer;
|
|
34
|
+
view;
|
|
35
|
+
offset = 0;
|
|
36
|
+
constructor(initialCapacity = DEFAULT_INITIAL_CAPACITY){
|
|
37
|
+
const ab = new ArrayBuffer(initialCapacity);
|
|
38
|
+
this.buffer = new Uint8Array(ab);
|
|
39
|
+
this.view = new DataView(ab);
|
|
40
|
+
}
|
|
41
|
+
/** Number of bytes written so far. */ get length() {
|
|
42
|
+
return this.offset;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serialize a migrated value into a fresh sink and return the single resulting buffer. This is the no-sink
|
|
46
|
+
* branch of every migrated `toBuffer`: one allocation, one slice, only at the root.
|
|
47
|
+
*
|
|
48
|
+
* @param obj - The value to serialize via its sink-aware `toBuffer`.
|
|
49
|
+
* @param initialCapacity - Optional size hint (e.g. from `getSize()`) to skip reallocations on hot paths.
|
|
50
|
+
*/ static serialize(obj, initialCapacity) {
|
|
51
|
+
const sink = new BufferSink(initialCapacity);
|
|
52
|
+
obj.toBuffer(sink);
|
|
53
|
+
return sink.toBuffer();
|
|
54
|
+
}
|
|
55
|
+
ensure(extra) {
|
|
56
|
+
const required = this.offset + extra;
|
|
57
|
+
if (required <= this.buffer.length) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let next = this.buffer.length * 2;
|
|
61
|
+
while(next < required){
|
|
62
|
+
next *= 2;
|
|
63
|
+
}
|
|
64
|
+
const grown = new Uint8Array(next);
|
|
65
|
+
grown.set(this.buffer.subarray(0, this.offset));
|
|
66
|
+
this.buffer = grown;
|
|
67
|
+
this.view = new DataView(grown.buffer);
|
|
68
|
+
}
|
|
69
|
+
/** Append a single byte (0/1) for a boolean, matching `boolToBuffer`. */ writeBool(value) {
|
|
70
|
+
this.ensure(1);
|
|
71
|
+
this.buffer[this.offset++] = value ? 1 : 0;
|
|
72
|
+
}
|
|
73
|
+
/** Append an unsigned 8-bit integer. */ writeUInt8(value) {
|
|
74
|
+
this.ensure(1);
|
|
75
|
+
this.buffer[this.offset++] = value & 0xff;
|
|
76
|
+
}
|
|
77
|
+
/** Append a big-endian unsigned 16-bit integer. */ writeUInt16(value) {
|
|
78
|
+
this.ensure(2);
|
|
79
|
+
this.view.setUint16(this.offset, value, false);
|
|
80
|
+
this.offset += 2;
|
|
81
|
+
}
|
|
82
|
+
/** Append a big-endian unsigned 32-bit integer, matching `numToUInt32BE`. */ writeNumber(value) {
|
|
83
|
+
this.ensure(4);
|
|
84
|
+
this.view.setUint32(this.offset, value, false);
|
|
85
|
+
this.offset += 4;
|
|
86
|
+
}
|
|
87
|
+
/** Append a big-endian unsigned 64-bit integer, matching `bigintToUInt64BE`. */ writeUInt64(value) {
|
|
88
|
+
this.ensure(8);
|
|
89
|
+
this.view.setBigUint64(this.offset, value, false);
|
|
90
|
+
this.offset += 8;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Append a non-negative bigint as a big-endian unsigned integer of `width` bytes (default 32), matching
|
|
94
|
+
* `serializeBigInt` / `toBufferBE`. Every width is written limb-wise via `setBigUint64` rather than the
|
|
95
|
+
* legacy per-byte BigInt shift loop — that loop allocated a fresh BigInt per byte and benchmarked as the
|
|
96
|
+
* *slowest* option (slower even than the legacy hex round-trip); the limb form is faster at every width.
|
|
97
|
+
*
|
|
98
|
+
* The bulk of the value is written as 64-bit big-endian limbs from the least-significant tail upward, and
|
|
99
|
+
* a final `width % 8` (at most 7) high bytes that don't fill a whole limb are written individually. The
|
|
100
|
+
* common widths (8/16/32) are exact multiples of 8, so they take the pure-limb path with no remainder.
|
|
101
|
+
* `width === 32` keeps its own straight-line four-limb form (shared with {@link writeField}) since it is
|
|
102
|
+
* the `Fr`/`Fq`/Chonk-proof hot path and the unrolled body is marginally faster than the loop.
|
|
103
|
+
*
|
|
104
|
+
* @param value - The non-negative bigint to serialize.
|
|
105
|
+
* @param width - Output width in bytes.
|
|
106
|
+
*/ writeBigInt(value, width = 32) {
|
|
107
|
+
if (value < 0n) {
|
|
108
|
+
throw new Error(`Cannot serialize negative bigint ${value}`);
|
|
109
|
+
}
|
|
110
|
+
this.ensure(width);
|
|
111
|
+
const o = this.offset;
|
|
112
|
+
if (width === 32) {
|
|
113
|
+
let x = value;
|
|
114
|
+
this.view.setBigUint64(o + 24, x & MASK_64, false);
|
|
115
|
+
x >>= 64n;
|
|
116
|
+
this.view.setBigUint64(o + 16, x & MASK_64, false);
|
|
117
|
+
x >>= 64n;
|
|
118
|
+
this.view.setBigUint64(o + 8, x & MASK_64, false);
|
|
119
|
+
x >>= 64n;
|
|
120
|
+
this.view.setBigUint64(o, x & MASK_64, false);
|
|
121
|
+
x >>= 64n;
|
|
122
|
+
if (x !== 0n) {
|
|
123
|
+
throw new Error(`BigInt ${value} does not fit into 32 bytes`);
|
|
124
|
+
}
|
|
125
|
+
this.offset += 32;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let x = value;
|
|
129
|
+
let pos = o + width;
|
|
130
|
+
while(pos - 8 >= o){
|
|
131
|
+
pos -= 8;
|
|
132
|
+
this.view.setBigUint64(pos, x & MASK_64, false);
|
|
133
|
+
x >>= 64n;
|
|
134
|
+
}
|
|
135
|
+
for(let i = pos - 1; i >= o; i--){
|
|
136
|
+
this.buffer[i] = Number(x & 0xffn);
|
|
137
|
+
x >>= 8n;
|
|
138
|
+
}
|
|
139
|
+
if (x !== 0n) {
|
|
140
|
+
throw new Error(`BigInt ${value} does not fit into ${width} bytes`);
|
|
141
|
+
}
|
|
142
|
+
this.offset += width;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Append a 32-byte (256-bit) big-endian non-negative bigint. Specialized form of {@link writeBigInt}
|
|
146
|
+
* with no width parameter and no width-branch, so V8 can inline the four `setBigUint64` limb writes
|
|
147
|
+
* without the wider branchy form's instability. This is the Fr/Fq leaf hot path; prefer it over
|
|
148
|
+
* `writeBigInt(value, 32)` in callers that always serialize 32-byte fields.
|
|
149
|
+
*/ writeField(value) {
|
|
150
|
+
if (value < 0n) {
|
|
151
|
+
throw new Error(`Cannot serialize negative bigint ${value}`);
|
|
152
|
+
}
|
|
153
|
+
this.ensure(32);
|
|
154
|
+
const o = this.offset;
|
|
155
|
+
let x = value;
|
|
156
|
+
this.view.setBigUint64(o + 24, x & MASK_64, false);
|
|
157
|
+
x >>= 64n;
|
|
158
|
+
this.view.setBigUint64(o + 16, x & MASK_64, false);
|
|
159
|
+
x >>= 64n;
|
|
160
|
+
this.view.setBigUint64(o + 8, x & MASK_64, false);
|
|
161
|
+
x >>= 64n;
|
|
162
|
+
this.view.setBigUint64(o, x & MASK_64, false);
|
|
163
|
+
if (x >> 64n !== 0n) {
|
|
164
|
+
throw new Error(`BigInt ${value} does not fit into 32 bytes`);
|
|
165
|
+
}
|
|
166
|
+
this.offset = o + 32;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Append an array of field elements (or any objects exposing `toBigInt(): bigint`) as a contiguous
|
|
170
|
+
* sequence of 32-byte big-endian limbs. Iterates inline — no per-element `toBuffer` dispatch and no
|
|
171
|
+
* per-element function-call indirection through the generic sinkable dispatcher. Use this in classes
|
|
172
|
+
* that hold large flat field arrays (e.g. the 1632-element ChonkProof field list).
|
|
173
|
+
*/ writeFields(fields) {
|
|
174
|
+
this.ensure(32 * fields.length);
|
|
175
|
+
for(let i = 0, n = fields.length; i < n; i++){
|
|
176
|
+
const value = fields[i].toBigInt();
|
|
177
|
+
if (value < 0n) {
|
|
178
|
+
throw new Error(`Cannot serialize negative bigint ${value}`);
|
|
179
|
+
}
|
|
180
|
+
const o = this.offset;
|
|
181
|
+
let x = value;
|
|
182
|
+
this.view.setBigUint64(o + 24, x & MASK_64, false);
|
|
183
|
+
x >>= 64n;
|
|
184
|
+
this.view.setBigUint64(o + 16, x & MASK_64, false);
|
|
185
|
+
x >>= 64n;
|
|
186
|
+
this.view.setBigUint64(o + 8, x & MASK_64, false);
|
|
187
|
+
x >>= 64n;
|
|
188
|
+
this.view.setBigUint64(o, x & MASK_64, false);
|
|
189
|
+
if (x >> 64n !== 0n) {
|
|
190
|
+
throw new Error(`BigInt ${value} does not fit into 32 bytes`);
|
|
191
|
+
}
|
|
192
|
+
this.offset = o + 32;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** Append raw bytes verbatim (no length prefix), matching how a `Buffer`/`Uint8Array` is serialized inline. */ writeBytes(bytes) {
|
|
196
|
+
this.ensure(bytes.length);
|
|
197
|
+
this.buffer.set(bytes, this.offset);
|
|
198
|
+
this.offset += bytes.length;
|
|
199
|
+
}
|
|
200
|
+
/** Append a string as a 4-byte big-endian length prefix followed by its UTF-8 bytes, matching the string case. */ writeString(value) {
|
|
201
|
+
const bytes = Buffer.from(value);
|
|
202
|
+
this.writeNumber(bytes.length);
|
|
203
|
+
this.writeBytes(bytes);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Reset the write cursor without releasing the backing buffer. Lets the same sink be reused across many
|
|
207
|
+
* serializations without reallocating — the per-call cost drops to the bytes written (no `new ArrayBuffer`).
|
|
208
|
+
* Any `Buffer` previously returned by {@link toBuffer} is a fresh copy and remains valid; any view from
|
|
209
|
+
* {@link asUint8Array} aliases the buffer and is invalidated.
|
|
210
|
+
*/ reset() {
|
|
211
|
+
this.offset = 0;
|
|
212
|
+
}
|
|
213
|
+
/** Copy the written region into a freshly allocated `Buffer`. The single allocation of the whole serialization. */ toBuffer() {
|
|
214
|
+
return Buffer.from(this.buffer.subarray(0, this.offset));
|
|
215
|
+
}
|
|
216
|
+
/** A zero-copy view of the written region. Valid only until the next write (which may reallocate). */ asUint8Array() {
|
|
217
|
+
return this.buffer.subarray(0, this.offset);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Streaming counterpart to `serializeToBufferArray`: walk a list of {@link Sinkable}s and append each to the sink.
|
|
222
|
+
* Dispatch matches `serializeToBufferArray` byte-for-byte. An object is serialized via `obj.toBuffer(sink)`; a
|
|
223
|
+
* migrated node writes into the sink and returns `undefined`, while a not-yet-migrated node ignores the argument
|
|
224
|
+
* and returns its `Buffer`, which we copy in. That return-value fallback is what makes the migration incremental.
|
|
225
|
+
*
|
|
226
|
+
* Dispatch is hot-pathed for the common case of objects exposing `toBuffer` (Fr/Fq and every other migrated leaf),
|
|
227
|
+
* and arrays recurse via an inner-array helper to avoid the per-call rest-args allocation that a spread-recurse
|
|
228
|
+
* would force on large flat arrays like the 1632-element ChonkProof field list.
|
|
229
|
+
*
|
|
230
|
+
* @param sink - The destination sink.
|
|
231
|
+
* @param objs - The values to serialize, in order.
|
|
232
|
+
*/ export function serializeToSink(sink, ...objs) {
|
|
233
|
+
serializeArrayToSinkInner(sink, objs);
|
|
234
|
+
}
|
|
235
|
+
function serializeArrayToSinkInner(sink, objs) {
|
|
236
|
+
for(let i = 0, n = objs.length; i < n; i++){
|
|
237
|
+
serializeOneToSink(sink, objs[i]);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function serializeOneToSink(sink, obj) {
|
|
241
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
242
|
+
// Hot path: migrated nodes (anything implementing toBuffer, including Fr/Fq via BaseField). This branch
|
|
243
|
+
// is taken for the vast majority of recursive serialization, so it is checked before the typeof primitives.
|
|
244
|
+
if (obj.toBuffer !== undefined) {
|
|
245
|
+
const ret = obj.toBuffer(sink);
|
|
246
|
+
if (ret !== undefined) {
|
|
247
|
+
sink.writeBytes(ret);
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (Array.isArray(obj)) {
|
|
252
|
+
serializeArrayToSinkInner(sink, obj);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (Buffer.isBuffer(obj) || obj instanceof Uint8Array) {
|
|
256
|
+
sink.writeBytes(obj);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
throw new Error(`Cannot serialize input to sink: ${typeof obj} ${obj.constructor?.name}`);
|
|
260
|
+
}
|
|
261
|
+
if (typeof obj === 'boolean') {
|
|
262
|
+
sink.writeBool(obj);
|
|
263
|
+
} else if (typeof obj === 'bigint') {
|
|
264
|
+
sink.writeBigInt(obj);
|
|
265
|
+
} else if (typeof obj === 'number') {
|
|
266
|
+
sink.writeNumber(obj);
|
|
267
|
+
} else if (typeof obj === 'string') {
|
|
268
|
+
sink.writeString(obj);
|
|
269
|
+
} else {
|
|
270
|
+
throw new Error(`Cannot serialize input to sink: ${typeof obj}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Streaming counterpart to `serializeArrayOfBufferableToVector`: write a length prefix (1 or 4 bytes) giving the
|
|
275
|
+
* number of serialized elements, then each element. Byte-identical to the buffer version.
|
|
276
|
+
*
|
|
277
|
+
* @param sink - The destination sink.
|
|
278
|
+
* @param objs - The vector elements.
|
|
279
|
+
* @param prefixLength - Width of the count prefix in bytes (1 or 4).
|
|
280
|
+
*/ export function serializeArrayToSink(sink, objs, prefixLength = 4) {
|
|
281
|
+
const count = countSinkables(objs);
|
|
282
|
+
if (prefixLength === 1) {
|
|
283
|
+
sink.writeUInt8(count);
|
|
284
|
+
} else if (prefixLength === 4) {
|
|
285
|
+
sink.writeNumber(count);
|
|
286
|
+
} else {
|
|
287
|
+
throw new Error(`Unsupported prefix length. Got ${prefixLength}, expected 1 or 4`);
|
|
288
|
+
}
|
|
289
|
+
serializeArrayToSinkInner(sink, objs);
|
|
290
|
+
}
|
|
291
|
+
/** Count how many top-level buffers `serializeToBufferArray` would emit, flattening nested arrays as it does. */ function countSinkables(objs) {
|
|
292
|
+
let count = 0;
|
|
293
|
+
for (const obj of objs){
|
|
294
|
+
count += Array.isArray(obj) ? countSinkables(obj) : 1;
|
|
295
|
+
}
|
|
296
|
+
return count;
|
|
297
|
+
}
|
|
@@ -93,18 +93,10 @@ export declare class FieldReader {
|
|
|
93
93
|
* @param itemDeserializer - An object with a 'fromFields' method to deserialize individual elements of type T.
|
|
94
94
|
* @returns An array of instances of type T.
|
|
95
95
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
readArray<T>(size: number, itemDeserializer: {
|
|
101
|
-
fromFields: (reader: FieldReader) => T;
|
|
102
|
-
}): T[];
|
|
103
|
-
/**
|
|
104
|
-
* Read a fixed-size tuple from the field array using dense allocation (Array.from).
|
|
105
|
-
* Only use with compile-time constant sizes — the size parameter MUST NOT come from untrusted input.
|
|
106
|
-
*/
|
|
107
|
-
readTuple<T, N extends number>(size: N, itemDeserializer: {
|
|
96
|
+
readArray<T, N extends number>(size: N, itemDeserializer: {
|
|
97
|
+
/**
|
|
98
|
+
* A function for deserializing data from a FieldReader instance.
|
|
99
|
+
*/
|
|
108
100
|
fromFields: (reader: FieldReader) => T;
|
|
109
101
|
}): Tuple<T, N>;
|
|
110
102
|
/**
|
|
@@ -126,4 +118,4 @@ export declare class FieldReader {
|
|
|
126
118
|
*/
|
|
127
119
|
isFinished(): boolean;
|
|
128
120
|
}
|
|
129
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
121
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmllbGRfcmVhZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VyaWFsaXplL2ZpZWxkX3JlYWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLEtBQUssRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDdkQsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sWUFBWSxDQUFDO0FBRXhDOzs7Ozs7O0dBT0c7QUFDSCxxQkFBYSxXQUFXO0lBS3BCLE9BQU8sQ0FBQyxNQUFNO0lBSmhCLE9BQU8sQ0FBQyxLQUFLLENBQVM7SU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CAM7D;IAED;;;;;;;;;OASG;IACI,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAClC,IAAI,EAAE,CAAC,EACP,gBAAgB,EAAE;QAChB;;WAEG;QACH,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,CAAC;KACxC,GACA,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAGb;IAED;;;;;;OAMG;IACI,UAAU,CAAC,CAAC,EAAE,YAAY,EAAE;QACjC;;WAEG;QACH,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,CAAC;KACxC,GAAG,CAAC,CAEJ;IAED;;;OAGG;IACI,UAAU,IAAI,OAAO,CAE3B;CACF"}
|
|
@@ -140,20 +140,7 @@ import { Fq } from '../curves/bn254/field.js';
|
|
|
140
140
|
* @param size - The fixed number of elements in the array.
|
|
141
141
|
* @param itemDeserializer - An object with a 'fromFields' method to deserialize individual elements of type T.
|
|
142
142
|
* @returns An array of instances of type T.
|
|
143
|
-
*/ /**
|
|
144
|
-
* Read an array from the field array using lazy allocation (new Array + loop).
|
|
145
|
-
* Safe for use with untrusted sizes.
|
|
146
143
|
*/ readArray(size, itemDeserializer) {
|
|
147
|
-
const result = new Array(size);
|
|
148
|
-
for(let i = 0; i < size; i++){
|
|
149
|
-
result[i] = itemDeserializer.fromFields(this);
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Read a fixed-size tuple from the field array using dense allocation (Array.from).
|
|
155
|
-
* Only use with compile-time constant sizes — the size parameter MUST NOT come from untrusted input.
|
|
156
|
-
*/ readTuple(size, itemDeserializer) {
|
|
157
144
|
const result = Array.from({
|
|
158
145
|
length: size
|
|
159
146
|
}, ()=>itemDeserializer.fromFields(this));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './free_funcs.js';
|
|
2
2
|
export * from './buffer_reader.js';
|
|
3
|
+
export * from './buffer_sink.js';
|
|
3
4
|
export * from './field_reader.js';
|
|
4
5
|
export * from './types.js';
|
|
5
6
|
export * from './serialize.js';
|
|
6
7
|
export * from './type_registry.js';
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXJpYWxpemUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYyxtQkFBbUIsQ0FBQztBQUNsQyxjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsb0JBQW9CLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialize/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialize/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
package/dest/serialize/index.js
CHANGED
package/dest/sleep/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
export declare class InterruptibleSleep {
|
|
22
22
|
private interrupts;
|
|
23
|
+
private timeoutIds;
|
|
23
24
|
/**
|
|
24
25
|
* Sleep for a specified amount of time in milliseconds.
|
|
25
26
|
* The sleep function will pause the execution of the current async function
|
|
@@ -50,4 +51,4 @@ export declare class InterruptibleSleep {
|
|
|
50
51
|
export declare function sleep<T>(ms: number, returnValue?: T): Promise<T>;
|
|
51
52
|
/** Sleeps until the target date */
|
|
52
53
|
export declare function sleepUntil<T>(target: Date, now: Date, returnValue?: T): Promise<T>;
|
|
53
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zbGVlcC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQTs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQW1CRztBQUNILHFCQUFhLGtCQUFrQjtJQUM3QixPQUFPLENBQUMsVUFBVSxDQUE2QztJQUMvRCxPQUFPLENBQUMsVUFBVSxDQUF3QjtJQUUxQzs7Ozs7OztPQU9HO0lBQ1UsS0FBSyxDQUFDLEVBQUUsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQXFCNUM7SUFFRDs7Ozs7O09BTUc7SUFDSSxTQUFTLENBQUMsZ0JBQWdCLFVBQVEsR0FBRyxJQUFJLENBSy9DO0NBQ0Y7QUFFRDs7Ozs7Ozs7R0FRRztBQUNILHdCQUFnQixLQUFLLENBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBRSxNQUFNLEVBQUUsV0FBVyxDQUFDLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FFaEU7QUFFRCxtQ0FBbUM7QUFDbkMsd0JBQWdCLFVBQVUsQ0FBQyxDQUFDLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxHQUFHLEVBQUUsSUFBSSxFQUFFLFdBQVcsQ0FBQyxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBR2xGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sleep/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,UAAU,CAA6C;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sleep/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,UAAU,CAA6C;IAC/D,OAAO,CAAC,UAAU,CAAwB;IAE1C;;;;;;;OAOG;IACU,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB5C;IAED;;;;;;OAMG;IACI,SAAS,CAAC,gBAAgB,UAAQ,GAAG,IAAI,CAK/C;CACF;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEhE;AAED,mCAAmC;AACnC,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAGlF"}
|
package/dest/sleep/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { InterruptError } from '../error/index.js';
|
|
|
20
20
|
* setTimeout(() =\> sleeper.interrupt(true), 1500); // Interrupt the sleep after 1.5 seconds
|
|
21
21
|
*/ export class InterruptibleSleep {
|
|
22
22
|
interrupts = [];
|
|
23
|
+
timeoutIds = [];
|
|
23
24
|
/**
|
|
24
25
|
* Sleep for a specified amount of time in milliseconds.
|
|
25
26
|
* The sleep function will pause the execution of the current async function
|
|
@@ -33,11 +34,17 @@ import { InterruptError } from '../error/index.js';
|
|
|
33
34
|
interruptResolve = resolve;
|
|
34
35
|
this.interrupts.push(resolve);
|
|
35
36
|
});
|
|
36
|
-
|
|
37
|
+
let timeoutId;
|
|
38
|
+
const timeoutPromise = new Promise((resolve)=>{
|
|
39
|
+
timeoutId = setTimeout(()=>resolve(false), ms);
|
|
40
|
+
this.timeoutIds.push(timeoutId);
|
|
41
|
+
});
|
|
37
42
|
const shouldThrow = await Promise.race([
|
|
38
43
|
interruptPromise,
|
|
39
44
|
timeoutPromise
|
|
40
45
|
]);
|
|
46
|
+
clearTimeout(timeoutId);
|
|
47
|
+
this.timeoutIds = this.timeoutIds.filter((id)=>id !== timeoutId);
|
|
41
48
|
this.interrupts = this.interrupts.filter((res)=>res !== interruptResolve);
|
|
42
49
|
if (shouldThrow) {
|
|
43
50
|
throw new InterruptError('Interrupted.');
|
|
@@ -52,6 +59,8 @@ import { InterruptError } from '../error/index.js';
|
|
|
52
59
|
*/ interrupt(sleepShouldThrow = false) {
|
|
53
60
|
this.interrupts.forEach((resolve)=>resolve(sleepShouldThrow));
|
|
54
61
|
this.interrupts = [];
|
|
62
|
+
this.timeoutIds.forEach((id)=>clearTimeout(id));
|
|
63
|
+
this.timeoutIds = [];
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
/**
|