@sig-net/midnight-serde 0.13.0 → 0.15.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.
- package/README.md +89 -11
- package/dist/deserialize.d.ts +5 -0
- package/dist/deserialize.d.ts.map +1 -1
- package/dist/deserialize.js +41 -19
- package/dist/deserialize.js.map +1 -1
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +41 -10
- package/dist/serialize.js.map +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +20 -6
- package/dist/validate.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,11 +8,21 @@ with one `deserialize<T, N>` call, and decode bytes a contract produced with
|
|
|
8
8
|
Every claim is pinned byte-for-byte against COMPILED circuits: the fixture
|
|
9
9
|
contract in [`tests/fixtures/serde-fixtures.compact`](tests/fixtures/serde-fixtures.compact)
|
|
10
10
|
wraps the builtins over structs exercising all supported types and combos, and
|
|
11
|
-
the tests assert twin/circuit equality in both directions. A second
|
|
12
|
-
|
|
11
|
+
the tests assert twin/circuit equality in both directions. A second oracle
|
|
12
|
+
backs the serialize direction: `toBinaryRepr` from
|
|
13
13
|
`@midnight-ntwrk/compact-runtime` (test-only, never a runtime dependency)
|
|
14
14
|
must agree with the twin on every shape, including the shapes compactc cannot
|
|
15
|
-
compile `serialize<T, N>` for.
|
|
15
|
+
compile `serialize<T, N>` for. The oracle adapter computes its byte widths
|
|
16
|
+
independently of the twin's width logic, so a width bug cannot cancel out of
|
|
17
|
+
the comparison, and a seeded randomised suite sweeps hundreds of generated
|
|
18
|
+
descriptor/value pairs through the roundtrip and the oracle on every run.
|
|
19
|
+
|
|
20
|
+
One honest caveat on what "circuit-pinned" means: the pins execute the
|
|
21
|
+
compiler's JS emission of each circuit (via `@midnight-ntwrk/compact-runtime`
|
|
22
|
+
under vitest), not the Impact VM or a prover. That JS is generated by the
|
|
23
|
+
same expand-serialize compiler pass as the in-circuit code, and the ledger
|
|
24
|
+
sources define the identical atom layout (see Sources), but no test in this
|
|
25
|
+
package runs a proof or a node.
|
|
16
26
|
|
|
17
27
|
## Use
|
|
18
28
|
|
|
@@ -75,21 +85,44 @@ empty struct all occupy no space (circuit-pinned).
|
|
|
75
85
|
zero-pads on the right. N below the packed size is a compile error in Compact
|
|
76
86
|
and a thrown error here.
|
|
77
87
|
|
|
88
|
+
Stdlib generics are plain structs in this layout, described with ordinary
|
|
89
|
+
struct descriptors: `Maybe<T>` is `{ is_some: Boolean; value: T }` and
|
|
90
|
+
`Either<A, B>` is `{ is_left: Boolean; left: A; right: B }`, and both arms
|
|
91
|
+
of an `Either` always occupy their full width regardless of the tag. The
|
|
92
|
+
stdlib constructors (`some`, `none`, `left`, `right`) zero-fill the unused
|
|
93
|
+
arm, and zero is a legal encoding for every Compact type, so
|
|
94
|
+
constructor-built values always decode here, strict mode included (all
|
|
95
|
+
circuit-pinned, straight from the constructors).
|
|
96
|
+
|
|
78
97
|
## Divergences from the circuit
|
|
79
98
|
|
|
80
|
-
|
|
99
|
+
Two divergences, both strict-by-default on DECODE, both pinned by tests with
|
|
100
|
+
bytes the circuit actually receives, and both with an opt-out. Bytes a
|
|
81
101
|
circuit produced never trigger either one, since `serialize<T, N>` only ever
|
|
82
102
|
writes zero padding and 0x00/0x01 booleans:
|
|
83
103
|
|
|
84
104
|
- **Padding:** the circuit ignores bytes in the padding region entirely, the
|
|
85
|
-
twin rejects non-zero padding. Pass `{ ignorePadding: true }` to
|
|
86
|
-
|
|
105
|
+
twin rejects non-zero padding. Pass `{ ignorePadding: true }` to mirror
|
|
106
|
+
the circuit's padding behaviour.
|
|
87
107
|
- **Booleans:** the circuit decodes ANY byte other than 0x01 as `false`
|
|
88
|
-
(0x02..0xff included), the twin rejects bytes above 1.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
(0x02..0xff included), the twin rejects bytes above 1. Pass
|
|
109
|
+
`{ lenientBooleans: true }` to mirror the circuit's boolean behaviour.
|
|
110
|
+
|
|
111
|
+
With both options set, `compactDeserialize` is circuit-exact on arbitrary
|
|
112
|
+
bytes (pinned by tests). Everything else mirrors the circuit exactly,
|
|
113
|
+
including rejections: out-of-range bounded Uint, sized Uint, enum and Field
|
|
114
|
+
encodings throw in-circuit and throw here (all pinned by the tests).
|
|
115
|
+
|
|
116
|
+
The ENCODE side is stricter than TypeScript alone would be, in line with the
|
|
117
|
+
strict descriptor validation: a struct value with a property the descriptor
|
|
118
|
+
does not declare is rejected (a typo'd key alongside the correct ones would
|
|
119
|
+
otherwise vanish silently), array and byte lengths must match the descriptor
|
|
120
|
+
exactly, and out-of-range numerics throw. Two resource guards round this
|
|
121
|
+
off: descriptor lengths must be safe integers and computed packed sizes must
|
|
122
|
+
stay below `Number.MAX_SAFE_INTEGER` (never a silently rounded size), and a
|
|
123
|
+
decode refuses to materialise more than 65536 zero-width vector elements
|
|
124
|
+
(`Vector<huge, Nothing>` decodes from no input at all, so a hostile
|
|
125
|
+
descriptor could otherwise hang the process on an empty buffer).
|
|
93
126
|
|
|
94
127
|
Known compactc 0.33 limits (pinned by the tests): `serialize<T, N>` crashes
|
|
95
128
|
the COMPILER on vectors of structs, vectors of vectors, and struct nesting
|
|
@@ -104,3 +137,48 @@ yarn compile # compile the fixture contract (needed before test/build)
|
|
|
104
137
|
yarn test # pin the twin against the compiled circuits + toBinaryRepr
|
|
105
138
|
yarn build # typecheck + emit ./dist for publishing
|
|
106
139
|
```
|
|
140
|
+
|
|
141
|
+
## Sources
|
|
142
|
+
|
|
143
|
+
Compact's `serialize<T, N>` is a compile-time expansion, not a library call:
|
|
144
|
+
the compiler monomorphises every call site into circuit code that walks the
|
|
145
|
+
type in declaration order and packs each atom at its natural width,
|
|
146
|
+
little-endian, with no tags, prefixes or gaps, then zero-pads the result on
|
|
147
|
+
the right to `Bytes<N>`. The layout it emits is the binary form of Midnight's
|
|
148
|
+
field-aligned binary (FAB) representation, the same bytes the ledger writes as
|
|
149
|
+
`persistentHash` preimages and that `toBinaryRepr` reproduces in the TS
|
|
150
|
+
runtime. This library is an independent TypeScript implementation of that
|
|
151
|
+
layout, pinned byte-for-byte against compiled circuits and against
|
|
152
|
+
`toBinaryRepr`.
|
|
153
|
+
|
|
154
|
+
There is consequently NO reusable serializer for this layout anywhere in
|
|
155
|
+
Midnight's own code: no function producing `Bytes<N>` from a value, no
|
|
156
|
+
`Serialize` opcode in the Impact VM, no ZKIR instruction, nothing in
|
|
157
|
+
`onchain-runtime`. What exists instead is one generator (the compiler pass),
|
|
158
|
+
one Rust preimage writer over the same atoms (`transient-crypto/src/fab.rs`
|
|
159
|
+
plus its in-circuit mirror in `zkir*/src/ir_vm.rs`), one TS flattener
|
|
160
|
+
(`toBinaryRepr`), and hand-rolled decoders in the SDK and the indexer. Beware
|
|
161
|
+
the name collision: the ledger's top-level `serialize/` crate is a different,
|
|
162
|
+
tagged transport format (streams begin with the ASCII string
|
|
163
|
+
`midnight:<tag>:`), not this layout.
|
|
164
|
+
|
|
165
|
+
Repositories are pinned at `LFDT-Minokawa/compact @ 5d8c66c`,
|
|
166
|
+
`midnightntwrk/midnight-ledger @ e1edad2` (branch `ledger-8`),
|
|
167
|
+
`midnightntwrk/midnight-sdk @ 80e6707`, `midnightntwrk/midnight-indexer @
|
|
168
|
+
345fcc2`.
|
|
169
|
+
|
|
170
|
+
| Source | What is here that is relevant |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| [compact: `compiler/analysis-passes/expand-serialize.ss`](https://github.com/LFDT-Minokawa/compact/blob/5d8c66c/compiler/analysis-passes/expand-serialize.ss) | The generator, and the closest thing to ground truth for the serialize direction. A nanopass that expands every `serialize`/`deserialize` call site into circuit expressions: declaration-order field walk, `field->bytes` at natural widths, booleans as literal `0x00`/`0x01`, enums cast to bounded Uint, right zero-padding, and the "serialized size exceeds specified length" compile error. |
|
|
173
|
+
| [compact: PR #470](https://github.com/LFDT-Minokawa/compact/pull/470) | The origin. Commit `0b3be94` ("[Issue 377] Events, phase 1", merged 2026-06-26) introduced the expand-serialize pass inside `analysis-passes.ss` as the canonical event encoding (the standalone file split out later in #632). |
|
|
174
|
+
| [compact: `doc/release-notes/toolchain-0.33.0.md`](https://github.com/LFDT-Minokawa/compact/blob/5d8c66c/doc/release-notes/toolchain-0.33.0.md) | Prose semantics of the user-facing builtins (lines 119-127): works for all Compact types except `Opaque` and contract types, too-small `N` is a compile error, zero padding on serialize, extra trailing bytes ignored on deserialize, events use "the equivalent of `serialize<T, #n>`". |
|
|
175
|
+
| [compact: `compiler/midnight-inlines.ss#L16-L24`](https://github.com/LFDT-Minokawa/compact/blob/5d8c66c/compiler/midnight-inlines.ss#L16-L24) | Where the standard library actually declares the builtins: `serialize` and `deserialize` are registered as inline entries (`[T (nat n)] ([value T]) (Bytes n)`) that expand into the IR forms the expand-serialize pass consumes. No event-type restriction exists in code. |
|
|
176
|
+
| [compact: `doc/api/CompactStandardLibrary/exports.md#L981`](https://github.com/LFDT-Minokawa/compact/blob/5d8c66c/doc/api/CompactStandardLibrary/exports.md#L981) | The documented `circuit serialize<T, #n>` / `deserialize<T, #n>` signatures. Beware: the doc says "`serialize` can only be instantiated for an event type and its canonical serialized size" (L983-985), left over from PR #470 where serialisation existed only for events. The 0.33 compiler accepts any serializable type. |
|
|
177
|
+
| [compact: `runtime/src/compact-types.ts#L651`](https://github.com/LFDT-Minokawa/compact/blob/5d8c66c/runtime/src/compact-types.ts#L651) | `toBinaryRepr`, the undocumented TS runtime re-implementation and our second test oracle. Flattens a descriptor's `ocrt.Value` along its `Alignment` (bytes atoms zero-filled to declared width, field atoms to 32 bytes, compress atoms rejected). |
|
|
178
|
+
| [Compact language reference](https://docs.midnight.network/compact/reference/compact-reference) | The type system: exclusive `Uint<0..n>` bounds, TS representations of each type, implementation limits. |
|
|
179
|
+
| [midnight-ledger: `spec/field-aligned-binary.md`](https://github.com/midnightntwrk/midnight-ledger/blob/e1edad2/spec/field-aligned-binary.md) | The normative FAB spec. It covers two encodings, and only one is ours: the self-describing flagged-int wire format is NOT the `serialize<T, N>` layout, the binary representation of atoms is. The high-level mapping section (lines 186-218) pins declaration-order struct encoding and explicitly assigns the Compact-type-to-FAB mapping to the compiler. |
|
|
180
|
+
| [midnight-ledger: `base-crypto/src/fab/`](https://github.com/midnightntwrk/midnight-ledger/tree/e1edad2/base-crypto/src/fab) | The core FAB data model (`transient-crypto/src/fab.rs` only extends it): `Value`, `ValueAtom`, `Alignment`, `AlignmentAtom`, `AlignedValue` in `encoding.rs`, normal form via trailing-zero strip, declaration-order tuple concat in `alignments.rs`, little-endian integer conversions in `conversions.rs`. |
|
|
181
|
+
| [midnight-ledger: `transient-crypto/src/fab.rs`](https://github.com/midnightntwrk/midnight-ledger/blob/e1edad2/transient-crypto/src/fab.rs) | The byte layout as Rust: the `ValueExt` trait (L35), the `Value::binary_repr_unchecked` traversal with zero-fill padding (L273), and the per-atom byte rules in `ValueAtomExt::binary_repr_unchecked` (L513): `Bytes{n}` as raw LE bytes zero-filled to `n`, `Field` as 32 bytes, `Compress` as a 32-byte Poseidon commitment. |
|
|
182
|
+
| [midnight-ledger: `base-crypto/src/hash.rs`](https://github.com/midnightntwrk/midnight-ledger/blob/e1edad2/base-crypto/src/hash.rs) and [`zkir-v3/src/ir_vm.rs`](https://github.com/midnightntwrk/midnight-ledger/blob/e1edad2/zkir-v3/src/ir_vm.rs) | Proof the layout is load-bearing: `persistent_hash` is SHA-256 over exactly these bytes (`ValueReprAlignedValue(value).binary_repr` at `ir_vm.rs` L524), and `fab_decode_to_bytes` (L80-181) is the in-circuit mirror of the same atom rules. |
|
|
183
|
+
| [midnight-sdk: `compact-js/compact-js/src/effect/ContractLog.ts`](https://github.com/midnightntwrk/midnight-sdk/blob/80e6707/compact-js/compact-js/src/effect/ContractLog.ts) | Hand-rolled decode of the eleven built-in ledger events from this same layout, decode only: 65-byte `Either` as `[is_left:1][left:32][right:32]`, little-endian `Uint<128>`. |
|
|
184
|
+
| [midnight-indexer: `indexer-common/src/domain/ledger/ledger_state.rs`](https://github.com/midnightntwrk/midnight-indexer/blob/345fcc2/indexer-common/src/domain/ledger/ledger_state.rs) | Midnight's production Rust decoder of the same event payload bytes, the reference `ContractLog.ts` itself calls authoritative (`EITHER_SIZE = 1 + 2 * 32`, `make_contract_event_attributes`). |
|
package/dist/deserialize.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { CompactType, CompactValueOf } from './types.ts';
|
|
|
2
2
|
export interface CompactDeserializeOptions {
|
|
3
3
|
/** Skip the all-zero check on bytes after the packed value (circuit behaviour). */
|
|
4
4
|
ignorePadding?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Decode boolean bytes above 0x01 as false instead of throwing (circuit
|
|
7
|
+
* behaviour: only 0x01 is true, anything else is false).
|
|
8
|
+
*/
|
|
9
|
+
lenientBooleans?: boolean;
|
|
5
10
|
}
|
|
6
11
|
/**
|
|
7
12
|
* Inverse of `compactSerialize`: decode the packed prefix of `bytes`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,WAAW,EAAgB,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5E,MAAM,WAAW,yBAAyB;IACxC,mFAAmF;IACnF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAcD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,CAAC,SAAS,WAAW,EAC5D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,yBAA8B,GACtC,cAAc,CAAC,CAAC,CAAC,CA2BnB"}
|
package/dist/deserialize.js
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Two deliberate divergences from the circuit, both strict-by-default
|
|
5
5
|
// (garbage in a buffer means corruption or mis-framing, and failing loudly
|
|
6
|
-
// off-chain is the safer default):
|
|
6
|
+
// off-chain is the safer default), and both with an opt-out:
|
|
7
7
|
// - PADDING: the circuit IGNORES bytes in the padding region entirely
|
|
8
8
|
// (pinned by tests), while this decoder rejects non-zero padding. Pass
|
|
9
9
|
// `{ ignorePadding: true }` to mirror the circuit.
|
|
10
10
|
// - BOOLEANS: the circuit decodes ANY byte other than 0x01 as false, so
|
|
11
11
|
// 0x02..0xff all quietly become false (pinned by tests), while this
|
|
12
|
-
// decoder rejects bytes above 1.
|
|
13
|
-
//
|
|
14
|
-
//
|
|
12
|
+
// decoder rejects bytes above 1. Pass `{ lenientBooleans: true }` to
|
|
13
|
+
// mirror the circuit.
|
|
14
|
+
// With both options set the decode is circuit-exact. Circuit-produced bytes
|
|
15
|
+
// never trigger either divergence: `serialize<T, N>` only writes zero padding
|
|
16
|
+
// and 0x00/0x01 booleans.
|
|
15
17
|
//
|
|
16
18
|
// Everything else mirrors the circuit exactly, including its rejections: the
|
|
17
19
|
// descriptor is fully validated (src/validate.ts) and the input buffer
|
|
@@ -19,7 +21,13 @@
|
|
|
19
21
|
// encodings all throw exactly where the circuit throws (pinned by tests).
|
|
20
22
|
import { FIELD_MODULUS } from "./types.js";
|
|
21
23
|
import { packedSize, uintBound, uintName } from "./serialize.js";
|
|
22
|
-
import { assertCompactType, assertUnreachable } from "./validate.js";
|
|
24
|
+
import { assertCompactType, assertUnreachable, isUint8Array } from "./validate.js";
|
|
25
|
+
// Zero-width elements (empty structs/tuples, `Uint<0..1>`, single-variant
|
|
26
|
+
// enums, `Bytes<0>`) consume no input, so a vector of them decodes purely
|
|
27
|
+
// from the descriptor: a validated-but-hostile `Vector<10^15, Nothing>`
|
|
28
|
+
// would loop forever on an EMPTY buffer. No real circuit is anywhere near
|
|
29
|
+
// this many zero-width elements, so cap them rather than hang.
|
|
30
|
+
const MAX_ZERO_WIDTH_ELEMENTS = 65536;
|
|
23
31
|
/**
|
|
24
32
|
* Inverse of `compactSerialize`: decode the packed prefix of `bytes`.
|
|
25
33
|
*
|
|
@@ -28,10 +36,20 @@ import { assertCompactType, assertUnreachable } from "./validate.js";
|
|
|
28
36
|
*/
|
|
29
37
|
export function compactDeserialize(type, bytes, options = {}) {
|
|
30
38
|
assertCompactType(type);
|
|
31
|
-
if (!(bytes
|
|
39
|
+
if (!isUint8Array(bytes)) {
|
|
32
40
|
throw new Error('bytes must be a Uint8Array');
|
|
33
41
|
}
|
|
34
|
-
|
|
42
|
+
// One size check up front covers every read below: fields and elements
|
|
43
|
+
// tile the packed prefix exactly, so no per-node re-check is needed.
|
|
44
|
+
const need = packedSize(type);
|
|
45
|
+
if (need > bytes.length) {
|
|
46
|
+
throw new Error(`value: needs ${need} bytes, buffer has ${bytes.length}`);
|
|
47
|
+
}
|
|
48
|
+
const context = {
|
|
49
|
+
lenientBooleans: options.lenientBooleans === true,
|
|
50
|
+
zeroWidthElements: 0,
|
|
51
|
+
};
|
|
52
|
+
const [value, consumed] = decodeFrom(bytes, 0, type, 'value', context);
|
|
35
53
|
if (!options.ignorePadding) {
|
|
36
54
|
for (let i = consumed; i < bytes.length; i++) {
|
|
37
55
|
if (bytes[i] !== 0) {
|
|
@@ -42,18 +60,15 @@ export function compactDeserialize(type, bytes, options = {}) {
|
|
|
42
60
|
}
|
|
43
61
|
return value;
|
|
44
62
|
}
|
|
45
|
-
function decodeFrom(bytes, offset, type, label) {
|
|
46
|
-
const need = packedSize(type);
|
|
47
|
-
if (offset + need > bytes.length) {
|
|
48
|
-
throw new Error(`${label}: needs ${need} bytes at offset ${offset}, buffer has ${bytes.length}`);
|
|
49
|
-
}
|
|
63
|
+
function decodeFrom(bytes, offset, type, label, context) {
|
|
50
64
|
switch (type.kind) {
|
|
51
65
|
case 'boolean': {
|
|
52
66
|
const b = bytes[offset];
|
|
53
|
-
//
|
|
67
|
+
// Strict by default; the circuit decodes any byte != 0x01 as false
|
|
54
68
|
// (see the header comment).
|
|
55
|
-
if (b > 1)
|
|
69
|
+
if (b > 1 && !context.lenientBooleans) {
|
|
56
70
|
throw new Error(`${label}: invalid boolean byte 0x${b.toString(16)}`);
|
|
71
|
+
}
|
|
57
72
|
return [b === 1, offset + 1];
|
|
58
73
|
}
|
|
59
74
|
case 'uint': {
|
|
@@ -61,8 +76,8 @@ function decodeFrom(bytes, offset, type, label) {
|
|
|
61
76
|
const size = packedSize(type);
|
|
62
77
|
const value = readUintLE(bytes, offset, size);
|
|
63
78
|
// Mirrors the circuit, which rejects encodings at or above the bound
|
|
64
|
-
// (pinned by tests via the
|
|
65
|
-
// uints when the width is not byte-aligned).
|
|
79
|
+
// (pinned by tests via the Bounded, Wide and U12 fixtures; only
|
|
80
|
+
// reachable for sized uints when the width is not byte-aligned).
|
|
66
81
|
if (value >= bound) {
|
|
67
82
|
throw new Error(`${label}: encoding ${value} exceeds ${uintName(type)}`);
|
|
68
83
|
}
|
|
@@ -89,10 +104,17 @@ function decodeFrom(bytes, offset, type, label) {
|
|
|
89
104
|
return [Number(value), offset + size];
|
|
90
105
|
}
|
|
91
106
|
case 'vector': {
|
|
107
|
+
if (packedSize(type.element) === 0) {
|
|
108
|
+
context.zeroWidthElements += type.length;
|
|
109
|
+
if (context.zeroWidthElements > MAX_ZERO_WIDTH_ELEMENTS) {
|
|
110
|
+
throw new Error(`${label}: refusing to materialise over ${MAX_ZERO_WIDTH_ELEMENTS} ` +
|
|
111
|
+
`zero-width vector elements (the descriptor decodes them from no input at all)`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
92
114
|
const elements = [];
|
|
93
115
|
let cursor = offset;
|
|
94
116
|
for (let i = 0; i < type.length; i++) {
|
|
95
|
-
const [element, next] = decodeFrom(bytes, cursor, type.element, `${label}[${i}]
|
|
117
|
+
const [element, next] = decodeFrom(bytes, cursor, type.element, `${label}[${i}]`, context);
|
|
96
118
|
elements.push(element);
|
|
97
119
|
cursor = next;
|
|
98
120
|
}
|
|
@@ -102,7 +124,7 @@ function decodeFrom(bytes, offset, type, label) {
|
|
|
102
124
|
const elements = [];
|
|
103
125
|
let cursor = offset;
|
|
104
126
|
type.elements.forEach((element, i) => {
|
|
105
|
-
const [decoded, next] = decodeFrom(bytes, cursor, element, `${label}[${i}]
|
|
127
|
+
const [decoded, next] = decodeFrom(bytes, cursor, element, `${label}[${i}]`, context);
|
|
106
128
|
elements.push(decoded);
|
|
107
129
|
cursor = next;
|
|
108
130
|
});
|
|
@@ -112,7 +134,7 @@ function decodeFrom(bytes, offset, type, label) {
|
|
|
112
134
|
const value = {};
|
|
113
135
|
let cursor = offset;
|
|
114
136
|
for (const field of type.fields) {
|
|
115
|
-
const [fieldValue, next] = decodeFrom(bytes, cursor, field.type, `${label}.${field.name}
|
|
137
|
+
const [fieldValue, next] = decodeFrom(bytes, cursor, field.type, `${label}.${field.name}`, context);
|
|
116
138
|
// defineProperty, not assignment: a field named '__proto__' is a
|
|
117
139
|
// legal Compact identifier, and plain assignment would hit the
|
|
118
140
|
// prototype setter and silently drop it.
|
package/dist/deserialize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,sEAAsE;AACtE,EAAE;AACF,sEAAsE;AACtE,2EAA2E;AAC3E,
|
|
1
|
+
{"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,sEAAsE;AACtE,EAAE;AACF,sEAAsE;AACtE,2EAA2E;AAC3E,6DAA6D;AAC7D,wEAAwE;AACxE,2EAA2E;AAC3E,uDAAuD;AACvD,0EAA0E;AAC1E,wEAAwE;AACxE,yEAAyE;AACzE,0BAA0B;AAC1B,4EAA4E;AAC5E,8EAA8E;AAC9E,0BAA0B;AAC1B,EAAE;AACF,6EA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,CAAC;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAgB,cAAc,EAAE,MAAM,YAAY,CAAC;AAwB7F,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAKvD;AAcD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CA2BpD;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAG/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAAS,WAAW,EAC1D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EACxB,KAAK,CAAC,EAAE,MAAM,GACb,UAAU,CAeZ;AAuHD,qEAAqE;AACrE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAKtD"}
|
package/dist/serialize.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// and every switch has a throwing backstop for anything that slips past the
|
|
18
18
|
// type system.
|
|
19
19
|
import { FIELD_MODULUS } from "./types.js";
|
|
20
|
-
import { assertCompactType, assertUnreachable } from "./validate.js";
|
|
20
|
+
import { assertCompactType, assertUnreachable, isUint8Array } from "./validate.js";
|
|
21
21
|
/** Byte length of the largest legal value, given the EXCLUSIVE bound. 0 for a bound of 1. */
|
|
22
22
|
function widthOfBound(bound) {
|
|
23
23
|
let max = bound - 1n;
|
|
@@ -28,12 +28,33 @@ function widthOfBound(bound) {
|
|
|
28
28
|
}
|
|
29
29
|
return width;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The sized-form bit width of a uint descriptor, or undefined for the bounded
|
|
33
|
+
* form. Own-property read: `'bits' in type` would walk the prototype chain.
|
|
34
|
+
*/
|
|
35
|
+
function sizedBits(type) {
|
|
36
|
+
return Object.hasOwn(type, 'bits')
|
|
37
|
+
? type.bits
|
|
38
|
+
: undefined;
|
|
39
|
+
}
|
|
31
40
|
/** The EXCLUSIVE upper bound of a uint descriptor, whichever form it uses. */
|
|
32
41
|
export function uintBound(type) {
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const bits = sizedBits(type);
|
|
43
|
+
return bits !== undefined
|
|
44
|
+
? 1n << BigInt(bits)
|
|
35
45
|
: BigInt(type.bound);
|
|
36
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Guard for the Number arithmetic below: element counts and widths are
|
|
49
|
+
* individually safe integers (validated), but their products and sums can
|
|
50
|
+
* still leave the safe range and silently round. Never produce a wrong size.
|
|
51
|
+
*/
|
|
52
|
+
function assertSafeSize(size, label) {
|
|
53
|
+
if (!Number.isSafeInteger(size)) {
|
|
54
|
+
throw new Error(`${label}: packed size exceeds Number.MAX_SAFE_INTEGER`);
|
|
55
|
+
}
|
|
56
|
+
return size;
|
|
57
|
+
}
|
|
37
58
|
/**
|
|
38
59
|
* Packed byte size of an ALREADY-VALIDATED descriptor. Package-internal: the
|
|
39
60
|
* public {@link compactSerializedSize} validates first.
|
|
@@ -51,11 +72,11 @@ export function packedSize(type) {
|
|
|
51
72
|
case 'enum':
|
|
52
73
|
return widthOfBound(BigInt(type.variants));
|
|
53
74
|
case 'vector':
|
|
54
|
-
return type.length * packedSize(type.element);
|
|
75
|
+
return assertSafeSize(type.length * packedSize(type.element), 'vector');
|
|
55
76
|
case 'tuple':
|
|
56
|
-
return type.elements.reduce((sum, e) => sum + packedSize(e), 0);
|
|
77
|
+
return assertSafeSize(type.elements.reduce((sum, e) => sum + packedSize(e), 0), 'tuple');
|
|
57
78
|
case 'struct':
|
|
58
|
-
return type.fields.reduce((sum, f) => sum + packedSize(f.type), 0);
|
|
79
|
+
return assertSafeSize(type.fields.reduce((sum, f) => sum + packedSize(f.type), 0), 'struct');
|
|
59
80
|
default:
|
|
60
81
|
return assertUnreachable(type, 'packedSize');
|
|
61
82
|
}
|
|
@@ -116,7 +137,7 @@ function encodeInto(out, offset, type, value, label) {
|
|
|
116
137
|
return offset + 32;
|
|
117
138
|
}
|
|
118
139
|
case 'bytes': {
|
|
119
|
-
if (!(value
|
|
140
|
+
if (!isUint8Array(value))
|
|
120
141
|
throw new Error(`${label}: expected Uint8Array`);
|
|
121
142
|
if (value.length !== type.length) {
|
|
122
143
|
throw new Error(`${label}: expected exactly ${type.length} bytes, got ${value.length}`);
|
|
@@ -164,9 +185,18 @@ function encodeInto(out, offset, type, value, label) {
|
|
|
164
185
|
if (typeof value !== 'object' ||
|
|
165
186
|
value === null ||
|
|
166
187
|
Array.isArray(value) ||
|
|
167
|
-
value
|
|
188
|
+
isUint8Array(value)) {
|
|
168
189
|
throw new Error(`${label}: expected an object`);
|
|
169
190
|
}
|
|
191
|
+
// Reject unknown keys, mirroring the strictness on descriptors: a
|
|
192
|
+
// typo'd extra property alongside the correctly-named ones would
|
|
193
|
+
// otherwise vanish silently.
|
|
194
|
+
const declared = new Set(type.fields.map((f) => f.name));
|
|
195
|
+
for (const key of Object.keys(value)) {
|
|
196
|
+
if (!declared.has(key)) {
|
|
197
|
+
throw new Error(`${label}: unknown field '${key}' (not in the descriptor)`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
170
200
|
let cursor = offset;
|
|
171
201
|
for (const field of type.fields) {
|
|
172
202
|
// Own-property lookup: field names like 'toString' or '__proto__'
|
|
@@ -186,8 +216,9 @@ function encodeInto(out, offset, type, value, label) {
|
|
|
186
216
|
}
|
|
187
217
|
/** Display name of a uint descriptor in its own declaration form. */
|
|
188
218
|
export function uintName(type) {
|
|
189
|
-
|
|
190
|
-
|
|
219
|
+
const bits = sizedBits(type);
|
|
220
|
+
return bits !== undefined
|
|
221
|
+
? `Uint<${bits}>`
|
|
191
222
|
: `Uint<0..${type.bound}>`;
|
|
192
223
|
}
|
|
193
224
|
function writeUintLE(out, offset, value, size, label) {
|
package/dist/serialize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,sEAAsE;AACtE,EAAE;AACF,gDAAgD;AAChD,2EAA2E;AAC3E,qBAAqB;AACrB,4EAA4E;AAC5E,8EAA8E;AAC9E,kEAAkE;AAClE,+EAA+E;AAC/E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,8EAA8E;AAC9E,4EAA4E;AAC5E,eAAe;AAEf,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,sEAAsE;AACtE,EAAE;AACF,gDAAgD;AAChD,2EAA2E;AAC3E,qBAAqB;AACrB,4EAA4E;AAC5E,8EAA8E;AAC9E,kEAAkE;AAClE,+EAA+E;AAC/E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,8EAA8E;AAC9E,4EAA4E;AAC5E,eAAe;AAEf,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEnF,6FAA6F;AAC7F,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC;IACrB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,GAAG,GAAG,EAAE,EAAE,CAAC;QAChB,KAAK,EAAE,CAAC;QACR,GAAG,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,C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,CAAC;IACX,CAAC;AACH,CAAC"}
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { CompactType } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Cross-realm-safe Uint8Array check. `instanceof` fails for buffers created
|
|
4
|
+
* in another realm (node:vm context, iframe), which are otherwise perfectly
|
|
5
|
+
* valid inputs, so fall back to the brand check.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
2
8
|
/**
|
|
3
9
|
* Assert that `type` is a structurally valid {@link CompactType}, recursively.
|
|
4
10
|
* Rejects unknown kinds, unexpected extra keys (typo protection), out-of-range
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAuB9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAKhE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,KAAK,SAAS,GACb,OAAO,CAAC,IAAI,IAAI,WAAW,CAiI7B;AAED,iDAAiD;AACjD,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,WAAW,CAOhE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAGpE"}
|
package/dist/validate.js
CHANGED
|
@@ -17,10 +17,21 @@ const KIND_KEYS = {
|
|
|
17
17
|
struct: ['kind', 'fields'],
|
|
18
18
|
};
|
|
19
19
|
function assertNonNegativeInteger(value, label) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// isSafeInteger, not isInteger: a length like 2^60 passes isInteger but
|
|
21
|
+
// breaks the Number arithmetic packed sizes are computed with.
|
|
22
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
|
|
23
|
+
throw new Error(`${label} must be a non-negative safe integer, got ${String(value)}`);
|
|
22
24
|
}
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Cross-realm-safe Uint8Array check. `instanceof` fails for buffers created
|
|
28
|
+
* in another realm (node:vm context, iframe), which are otherwise perfectly
|
|
29
|
+
* valid inputs, so fall back to the brand check.
|
|
30
|
+
*/
|
|
31
|
+
export function isUint8Array(value) {
|
|
32
|
+
return (value instanceof Uint8Array ||
|
|
33
|
+
Object.prototype.toString.call(value) === '[object Uint8Array]');
|
|
34
|
+
}
|
|
24
35
|
/**
|
|
25
36
|
* Assert that `type` is a structurally valid {@link CompactType}, recursively.
|
|
26
37
|
* Rejects unknown kinds, unexpected extra keys (typo protection), out-of-range
|
|
@@ -49,14 +60,18 @@ export function assertCompactType(type, label = 'type') {
|
|
|
49
60
|
case 'field':
|
|
50
61
|
return;
|
|
51
62
|
case 'uint': {
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
// Own-property reads: a plain `record.bits` would resolve through the
|
|
64
|
+
// prototype chain, letting `{ __proto__: { bits: 8 }, kind: 'uint' }`
|
|
65
|
+
// slip past even though Object.keys sees no such key.
|
|
66
|
+
const bits = Object.hasOwn(record, 'bits') ? record.bits : undefined;
|
|
67
|
+
const bound = Object.hasOwn(record, 'bound') ? record.bound : undefined;
|
|
68
|
+
const hasBits = bits !== undefined;
|
|
69
|
+
const hasBound = bound !== undefined;
|
|
54
70
|
if (hasBits === hasBound) {
|
|
55
71
|
throw new Error(`${label}: a uint descriptor needs exactly one of 'bits' (sized Uint<w>) ` +
|
|
56
72
|
`or 'bound' (bounded Uint<0..n>)`);
|
|
57
73
|
}
|
|
58
74
|
if (hasBits) {
|
|
59
|
-
const bits = record.bits;
|
|
60
75
|
if (typeof bits !== 'number' ||
|
|
61
76
|
!Number.isInteger(bits) ||
|
|
62
77
|
bits < 1 ||
|
|
@@ -65,7 +80,6 @@ export function assertCompactType(type, label = 'type') {
|
|
|
65
80
|
}
|
|
66
81
|
return;
|
|
67
82
|
}
|
|
68
|
-
const bound = record.bound;
|
|
69
83
|
if (typeof bound === 'number' && !Number.isSafeInteger(bound)) {
|
|
70
84
|
throw new Error(`${label}: a number uint bound must be a safe integer (use a bigint ` +
|
|
71
85
|
`beyond 2^53), got ${String(bound)}`);
|
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAC3E,sCAAsC;AAGtC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE3D,+EAA+E;AAC/E,MAAM,SAAS,GAAsC;IACnD,OAAO,EAAE,CAAC,MAAM,CAAC;IACjB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;IAC/B,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;IAC1B,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC;IACrC,KAAK,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B,CAAC;AAEF,SAAS,wBAAwB,CAAC,KAAc,EAAE,KAAa;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAA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