@thru/passkey-manager 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1667 @@
1
+ /* Auto-generated TypeScript code */
2
+ /* WARNING: Do not modify this file directly. It is generated from ABI definitions. */
3
+
4
+ import { Hash, Pubkey } from "../../common/primitives/types";
5
+
6
+ type __TnIrNode =
7
+ | { readonly op: "zero" }
8
+ | { readonly op: "const"; readonly value: bigint }
9
+ | { readonly op: "field"; readonly param: string }
10
+ | {
11
+ readonly op: "add";
12
+ readonly left: __TnIrNode;
13
+ readonly right: __TnIrNode;
14
+ }
15
+ | {
16
+ readonly op: "mul";
17
+ readonly left: __TnIrNode;
18
+ readonly right: __TnIrNode;
19
+ }
20
+ | {
21
+ readonly op: "align";
22
+ readonly alignment: number;
23
+ readonly node: __TnIrNode;
24
+ }
25
+ | {
26
+ readonly op: "switch";
27
+ readonly tag: string;
28
+ readonly cases: readonly { readonly value: number; readonly node: __TnIrNode }[];
29
+ readonly default?: __TnIrNode;
30
+ }
31
+ | {
32
+ readonly op: "call";
33
+ readonly typeName: string;
34
+ readonly args: readonly { readonly name: string; readonly source: string }[];
35
+ };
36
+
37
+ type __TnIrContext = {
38
+ params: Record<string, bigint>;
39
+ buffer?: Uint8Array;
40
+ typeName?: string;
41
+ };
42
+
43
+ type __TnValidateResult = { ok: boolean; code?: string; consumed?: bigint };
44
+ type __TnEvalResult =
45
+ | { ok: true; value: bigint }
46
+ | { ok: false; code: string };
47
+ type __TnBuilderLike = { build(): Uint8Array };
48
+ type __TnStructFieldInput =
49
+ | Uint8Array
50
+ | __TnBuilderLike
51
+ | { buffer?: Uint8Array }
52
+ | { asUint8Array?: () => Uint8Array }
53
+ | { bytes?: () => Uint8Array };
54
+ type __TnVariantDescriptor = {
55
+ readonly name: string;
56
+ readonly tag: number;
57
+ readonly payloadSize: number | null;
58
+ readonly payloadType?: string;
59
+ readonly createPayloadBuilder?: () => unknown | null;
60
+ };
61
+ type __TnVariantSelectorResult<Parent> = {
62
+ select(
63
+ name: string
64
+ ): { writePayload(payload: Uint8Array | __TnBuilderLike): { finish(): Parent } };
65
+ finish(): Parent;
66
+ };
67
+ type __TnFamWriterResult<Parent> = {
68
+ write(payload: Uint8Array | __TnBuilderLike): { finish(): Parent };
69
+ finish(): Parent;
70
+ };
71
+ type __TnConsole = { warn?: (...args: unknown[]) => void };
72
+
73
+ const __tnWarnings = new Set<string>();
74
+ const __tnHasNativeBigInt = typeof BigInt === "function";
75
+ const __tnHasBigIntDataView =
76
+ typeof DataView !== "undefined" &&
77
+ typeof DataView.prototype.getBigInt64 === "function" &&
78
+ typeof DataView.prototype.getBigUint64 === "function" &&
79
+ typeof DataView.prototype.setBigInt64 === "function" &&
80
+ typeof DataView.prototype.setBigUint64 === "function";
81
+ const __tnConsole: __TnConsole | undefined =
82
+ typeof globalThis !== "undefined"
83
+ ? (globalThis as { console?: __TnConsole }).console
84
+ : undefined;
85
+
86
+ function __tnLogWarn(message: string): void {
87
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
88
+ __tnConsole.warn(message);
89
+ }
90
+ }
91
+
92
+ function __tnWarnOnce(message: string): void {
93
+ if (!__tnWarnings.has(message)) {
94
+ __tnWarnings.add(message);
95
+ __tnLogWarn(message);
96
+ }
97
+ }
98
+
99
+ function __tnResolveBuilderInput(
100
+ input: Uint8Array | __TnBuilderLike,
101
+ context: string
102
+ ): Uint8Array {
103
+ if (input instanceof Uint8Array) {
104
+ return new Uint8Array(input);
105
+ }
106
+ if (input && typeof (input as __TnBuilderLike).build === "function") {
107
+ const built = (input as __TnBuilderLike).build();
108
+ if (!(built instanceof Uint8Array)) {
109
+ throw new Error(`${context}: builder did not return Uint8Array`);
110
+ }
111
+ return new Uint8Array(built);
112
+ }
113
+ throw new Error(`${context}: expected Uint8Array or builder`);
114
+ }
115
+
116
+ function __tnResolveStructFieldInput(
117
+ input: __TnStructFieldInput,
118
+ context: string
119
+ ): Uint8Array {
120
+ if (
121
+ input instanceof Uint8Array ||
122
+ (input && typeof (input as __TnBuilderLike).build === "function")
123
+ ) {
124
+ return __tnResolveBuilderInput(input as Uint8Array | __TnBuilderLike, context);
125
+ }
126
+ if (input && typeof (input as { asUint8Array?: () => Uint8Array }).asUint8Array === "function") {
127
+ const bytes = (input as { asUint8Array: () => Uint8Array }).asUint8Array();
128
+ return new Uint8Array(bytes);
129
+ }
130
+ if (input && typeof (input as { bytes?: () => Uint8Array }).bytes === "function") {
131
+ const bytes = (input as { bytes: () => Uint8Array }).bytes();
132
+ return new Uint8Array(bytes);
133
+ }
134
+ if (input && (input as { buffer?: unknown }).buffer instanceof Uint8Array) {
135
+ return new Uint8Array((input as { buffer: Uint8Array }).buffer);
136
+ }
137
+ throw new Error(`${context}: expected Uint8Array, builder, or view-like value`);
138
+ }
139
+
140
+ function __tnMaybeCallBuilder(ctor: unknown): unknown | null {
141
+ if (!ctor) {
142
+ return null;
143
+ }
144
+ const builderFn = (ctor as { builder?: () => unknown }).builder;
145
+ return typeof builderFn === "function" ? builderFn() : null;
146
+ }
147
+
148
+ function __tnCreateVariantSelector<Parent, Descriptor extends __TnVariantDescriptor>(
149
+ parent: Parent,
150
+ descriptors: readonly Descriptor[],
151
+ assign: (descriptor: Descriptor, payload: Uint8Array) => void
152
+ ): __TnVariantSelectorResult<Parent> {
153
+ return {
154
+ select(name: string) {
155
+ const descriptor = descriptors.find((variant) => variant.name === name);
156
+ if (!descriptor) {
157
+ throw new Error(`Unknown variant '${name}'`);
158
+ }
159
+ return {
160
+ writePayload(payload: Uint8Array | __TnBuilderLike) {
161
+ const bytes = __tnResolveBuilderInput(
162
+ payload,
163
+ `variant ${descriptor.name}`
164
+ );
165
+ if (
166
+ descriptor.payloadSize !== null &&
167
+ bytes.length !== descriptor.payloadSize
168
+ ) {
169
+ throw new Error(
170
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
171
+ );
172
+ }
173
+ assign(descriptor, bytes);
174
+ return {
175
+ finish(): Parent {
176
+ return parent;
177
+ },
178
+ };
179
+ },
180
+ };
181
+ },
182
+ finish(): Parent {
183
+ return parent;
184
+ },
185
+ };
186
+ }
187
+
188
+ function __tnCreateFamWriter<Parent>(
189
+ parent: Parent,
190
+ fieldName: string,
191
+ assign: (bytes: Uint8Array) => void
192
+ ): __TnFamWriterResult<Parent> {
193
+ let hasWritten = false;
194
+ return {
195
+ write(payload: Uint8Array | __TnBuilderLike) {
196
+ const bytes = __tnResolveBuilderInput(
197
+ payload,
198
+ `flexible array '${fieldName}'`
199
+ );
200
+ const copy = new Uint8Array(bytes);
201
+ assign(copy);
202
+ hasWritten = true;
203
+ return {
204
+ finish(): Parent {
205
+ return parent;
206
+ },
207
+ };
208
+ },
209
+ finish(): Parent {
210
+ if (!hasWritten) {
211
+ throw new Error(
212
+ `flexible array '${fieldName}' requires write() before finish()`
213
+ );
214
+ }
215
+ return parent;
216
+ },
217
+ };
218
+ }
219
+
220
+ const __tnMask32 = __tnHasNativeBigInt
221
+ ? (BigInt(1) << BigInt(32)) - BigInt(1)
222
+ : 0xffffffff;
223
+ const __tnSignBit32 = __tnHasNativeBigInt
224
+ ? BigInt(1) << BigInt(31)
225
+ : 0x80000000;
226
+
227
+ function __tnToBigInt(value: number | bigint): bigint {
228
+ if (__tnHasNativeBigInt) {
229
+ return typeof value === "bigint" ? value : BigInt(value);
230
+ }
231
+ if (typeof value === "bigint") return value;
232
+ if (!Number.isFinite(value)) {
233
+ throw new Error("IR runtime received non-finite numeric input");
234
+ }
235
+ if (!Number.isSafeInteger(value)) {
236
+ __tnWarnOnce(
237
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
238
+ );
239
+ }
240
+ return (value as unknown) as bigint;
241
+ }
242
+
243
+ function __tnBigIntToNumber(value: bigint, context: string): number {
244
+ if (__tnHasNativeBigInt) {
245
+ const converted = Number(value);
246
+ if (!Number.isFinite(converted)) {
247
+ throw new Error(`${context} overflowed Number range`);
248
+ }
249
+ return converted;
250
+ }
251
+ return value as unknown as number;
252
+ }
253
+
254
+ function __tnBigIntEquals(lhs: bigint, rhs: bigint): boolean {
255
+ if (__tnHasNativeBigInt) return lhs === rhs;
256
+ return (lhs as unknown as number) === (rhs as unknown as number);
257
+ }
258
+
259
+ function __tnBigIntGreaterThan(lhs: bigint, rhs: bigint): boolean {
260
+ if (__tnHasNativeBigInt) return lhs > rhs;
261
+ return (lhs as unknown as number) > (rhs as unknown as number);
262
+ }
263
+
264
+ function __tnPopcount(value: number | bigint): number {
265
+ let v =
266
+ typeof value === "bigint"
267
+ ? Number(value & BigInt(0xffffffff))
268
+ : Number(value) >>> 0;
269
+ v = v - ((v >>> 1) & 0x55555555);
270
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
271
+ return (((v + (v >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
272
+ }
273
+
274
+ function __tnRaiseIrError(code: string, message: string): never {
275
+ const err = new Error(message);
276
+ (err as { code?: string }).code = code;
277
+ throw err;
278
+ }
279
+
280
+ function __tnCheckedAdd(lhs: bigint, rhs: bigint): bigint {
281
+ if (__tnHasNativeBigInt) {
282
+ const result = (lhs as bigint) + (rhs as bigint);
283
+ if (result < BigInt(0)) {
284
+ __tnRaiseIrError(
285
+ "tn.ir.overflow",
286
+ "IR runtime detected negative size via addition"
287
+ );
288
+ }
289
+ return result;
290
+ }
291
+ const left = lhs as unknown as number;
292
+ const right = rhs as unknown as number;
293
+ const sum = left + right;
294
+ if (sum < 0 || !Number.isFinite(sum)) {
295
+ __tnRaiseIrError(
296
+ "tn.ir.overflow",
297
+ "IR runtime detected invalid addition result"
298
+ );
299
+ }
300
+ if (!Number.isSafeInteger(sum)) {
301
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
302
+ }
303
+ return (sum as unknown) as bigint;
304
+ }
305
+
306
+ function __tnCheckedMul(lhs: bigint, rhs: bigint): bigint {
307
+ if (__tnHasNativeBigInt) {
308
+ const result = (lhs as bigint) * (rhs as bigint);
309
+ if (result < BigInt(0)) {
310
+ __tnRaiseIrError(
311
+ "tn.ir.overflow",
312
+ "IR runtime detected negative size via multiplication"
313
+ );
314
+ }
315
+ return result;
316
+ }
317
+ const left = lhs as unknown as number;
318
+ const right = rhs as unknown as number;
319
+ const product = left * right;
320
+ if (product < 0 || !Number.isFinite(product)) {
321
+ __tnRaiseIrError(
322
+ "tn.ir.overflow",
323
+ "IR runtime detected invalid multiplication result"
324
+ );
325
+ }
326
+ if (!Number.isSafeInteger(product)) {
327
+ __tnWarnOnce(
328
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
329
+ );
330
+ }
331
+ return (product as unknown) as bigint;
332
+ }
333
+
334
+ function __tnAlign(value: bigint, alignment: number): bigint {
335
+ if (alignment <= 1) return value;
336
+ const alignBig = __tnToBigInt(alignment);
337
+ if (__tnHasNativeBigInt) {
338
+ const remainder = value % alignBig;
339
+ if (__tnBigIntEquals(remainder, __tnToBigInt(0))) {
340
+ return value;
341
+ }
342
+ const delta = alignBig - remainder;
343
+ return __tnCheckedAdd(value, delta);
344
+ }
345
+ const current = __tnBigIntToNumber(value, "IR align");
346
+ const alignNum = alignment >>> 0;
347
+ const remainder = current % alignNum;
348
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
349
+ return __tnToBigInt(next);
350
+ }
351
+
352
+ function __tnSplitUint64(value: bigint): { high: number; low: number } {
353
+ if (__tnHasNativeBigInt) {
354
+ const low = Number(value & (__tnMask32 as bigint));
355
+ const high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
356
+ return { high, low };
357
+ }
358
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
359
+ const low = num >>> 0;
360
+ const high = Math.floor(num / 4294967296) >>> 0;
361
+ return { high, low };
362
+ }
363
+
364
+ function __tnSplitInt64(value: bigint): { high: number; low: number } {
365
+ if (__tnHasNativeBigInt) {
366
+ const low = Number(value & (__tnMask32 as bigint));
367
+ let high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
368
+ if ((BigInt(high) & (__tnSignBit32 as bigint)) !== BigInt(0)) {
369
+ high -= 0x100000000;
370
+ }
371
+ return { high, low };
372
+ }
373
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
374
+ const low = num >>> 0;
375
+ const high = Math.floor(num / 4294967296);
376
+ return { high, low };
377
+ }
378
+
379
+ function __tnPolyfillReadUint64(
380
+ view: DataView,
381
+ offset: number,
382
+ littleEndian: boolean
383
+ ): bigint {
384
+ const low = littleEndian
385
+ ? view.getUint32(offset, true)
386
+ : view.getUint32(offset + 4, false);
387
+ const high = littleEndian
388
+ ? view.getUint32(offset + 4, true)
389
+ : view.getUint32(offset, false);
390
+ if (__tnHasNativeBigInt) {
391
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
392
+ }
393
+ const value = high * 4294967296 + low;
394
+ if (!Number.isSafeInteger(value)) {
395
+ __tnWarnOnce(
396
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
397
+ );
398
+ }
399
+ return (value as unknown) as bigint;
400
+ }
401
+
402
+ function __tnPolyfillReadInt64(
403
+ view: DataView,
404
+ offset: number,
405
+ littleEndian: boolean
406
+ ): bigint {
407
+ const low = littleEndian
408
+ ? view.getUint32(offset, true)
409
+ : view.getUint32(offset + 4, false);
410
+ const high = littleEndian
411
+ ? view.getInt32(offset + 4, true)
412
+ : view.getInt32(offset, false);
413
+ if (__tnHasNativeBigInt) {
414
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
415
+ }
416
+ const value = high * 4294967296 + low;
417
+ if (!Number.isSafeInteger(value)) {
418
+ __tnWarnOnce(
419
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
420
+ );
421
+ }
422
+ return (value as unknown) as bigint;
423
+ }
424
+
425
+ function __tnPolyfillWriteUint64(
426
+ view: DataView,
427
+ offset: number,
428
+ value: bigint,
429
+ littleEndian: boolean
430
+ ): void {
431
+ const parts = __tnSplitUint64(value);
432
+ if (littleEndian) {
433
+ view.setUint32(offset, parts.low, true);
434
+ view.setUint32(offset + 4, parts.high, true);
435
+ } else {
436
+ view.setUint32(offset, parts.high, false);
437
+ view.setUint32(offset + 4, parts.low, false);
438
+ }
439
+ }
440
+
441
+ function __tnPolyfillWriteInt64(
442
+ view: DataView,
443
+ offset: number,
444
+ value: bigint,
445
+ littleEndian: boolean
446
+ ): void {
447
+ const parts = __tnSplitInt64(value);
448
+ if (littleEndian) {
449
+ view.setUint32(offset, parts.low >>> 0, true);
450
+ view.setInt32(offset + 4, parts.high | 0, true);
451
+ } else {
452
+ view.setInt32(offset, parts.high | 0, false);
453
+ view.setUint32(offset + 4, parts.low >>> 0, false);
454
+ }
455
+ }
456
+
457
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
458
+ const proto = DataView.prototype as unknown as Record<string, unknown>;
459
+ if (typeof proto.getBigUint64 !== "function") {
460
+ (proto as any).getBigUint64 = function (
461
+ offset: number,
462
+ littleEndian?: boolean
463
+ ): bigint {
464
+ __tnWarnOnce(
465
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
466
+ );
467
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
468
+ };
469
+ }
470
+ if (typeof proto.getBigInt64 !== "function") {
471
+ (proto as any).getBigInt64 = function (
472
+ offset: number,
473
+ littleEndian?: boolean
474
+ ): bigint {
475
+ __tnWarnOnce(
476
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
477
+ );
478
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
479
+ };
480
+ }
481
+ if (typeof proto.setBigUint64 !== "function") {
482
+ (proto as any).setBigUint64 = function (
483
+ offset: number,
484
+ value: bigint,
485
+ littleEndian?: boolean
486
+ ): void {
487
+ __tnWarnOnce(
488
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
489
+ );
490
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
491
+ };
492
+ }
493
+ if (typeof proto.setBigInt64 !== "function") {
494
+ (proto as any).setBigInt64 = function (
495
+ offset: number,
496
+ value: bigint,
497
+ littleEndian?: boolean
498
+ ): void {
499
+ __tnWarnOnce(
500
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
501
+ );
502
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
503
+ };
504
+ }
505
+ if (!__tnHasNativeBigInt) {
506
+ __tnWarnOnce(
507
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
508
+ );
509
+ }
510
+ }
511
+
512
+ const __tnFootprintRegistry: Record<
513
+ string,
514
+ (params: Record<string, bigint>) => bigint
515
+ > = {};
516
+ const __tnValidateRegistry: Record<
517
+ string,
518
+ (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
519
+ > = {};
520
+
521
+ function __tnRegisterFootprint(
522
+ typeName: string,
523
+ fn: (params: Record<string, bigint>) => bigint
524
+ ): void {
525
+ __tnFootprintRegistry[typeName] = fn;
526
+ }
527
+
528
+ function __tnRegisterValidate(
529
+ typeName: string,
530
+ fn: (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
531
+ ): void {
532
+ __tnValidateRegistry[typeName] = fn;
533
+ }
534
+
535
+ function __tnInvokeFootprint(
536
+ typeName: string,
537
+ params: Record<string, bigint>
538
+ ): bigint {
539
+ const fn = __tnFootprintRegistry[typeName];
540
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
541
+ return fn(params);
542
+ }
543
+
544
+ function __tnInvokeValidate(
545
+ typeName: string,
546
+ buffer: Uint8Array,
547
+ params: Record<string, bigint>
548
+ ): __TnValidateResult {
549
+ const fn = __tnValidateRegistry[typeName];
550
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
551
+ return fn(buffer, params);
552
+ }
553
+
554
+ function __tnEvalFootprint(node: __TnIrNode, ctx: __TnIrContext): bigint {
555
+ return __tnEvalIrNode(node, ctx);
556
+ }
557
+
558
+ function __tnTryEvalFootprint(
559
+ node: __TnIrNode,
560
+ ctx: __TnIrContext
561
+ ): __TnEvalResult {
562
+ return __tnTryEvalIr(node, ctx);
563
+ }
564
+
565
+ function __tnTryEvalIr(
566
+ node: __TnIrNode,
567
+ ctx: __TnIrContext
568
+ ): __TnEvalResult {
569
+ try {
570
+ return { ok: true, value: __tnEvalIrNode(node, ctx) };
571
+ } catch (err) {
572
+ return { ok: false, code: __tnNormalizeIrError(err) };
573
+ }
574
+ }
575
+
576
+ function __tnIsEvalError(result: __TnEvalResult): result is { ok: false; code: string } {
577
+ return result.ok === false;
578
+ }
579
+
580
+ function __tnValidateIrTree(
581
+ ir: { readonly typeName: string; readonly root: __TnIrNode },
582
+ buffer: Uint8Array,
583
+ params: Record<string, bigint>
584
+ ): __TnValidateResult {
585
+ const evalResult = __tnTryEvalIr(ir.root, {
586
+ params,
587
+ buffer,
588
+ typeName: ir.typeName,
589
+ });
590
+ if (__tnIsEvalError(evalResult)) {
591
+ return { ok: false, code: evalResult.code };
592
+ }
593
+ const required = evalResult.value;
594
+ const available = __tnToBigInt(buffer.length);
595
+ if (__tnBigIntGreaterThan(required, available)) {
596
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
597
+ }
598
+ return { ok: true, consumed: required };
599
+ }
600
+
601
+ function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
602
+ switch (node.op) {
603
+ case "zero":
604
+ return __tnToBigInt(0);
605
+ case "const":
606
+ return node.value;
607
+ case "field": {
608
+ const val = ctx.params[node.param];
609
+ if (val === undefined) {
610
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
611
+ __tnRaiseIrError(
612
+ "tn.ir.missing_param",
613
+ `${prefix}Missing IR parameter '${node.param}'`
614
+ );
615
+ }
616
+ return val;
617
+ }
618
+ case "add":
619
+ return __tnCheckedAdd(
620
+ __tnEvalIrNode(node.left, ctx),
621
+ __tnEvalIrNode(node.right, ctx)
622
+ );
623
+ case "mul":
624
+ return __tnCheckedMul(
625
+ __tnEvalIrNode(node.left, ctx),
626
+ __tnEvalIrNode(node.right, ctx)
627
+ );
628
+ case "align":
629
+ return __tnAlign(__tnEvalIrNode(node.node, ctx), node.alignment);
630
+ case "switch": {
631
+ const tagVal = ctx.params[node.tag];
632
+ if (tagVal === undefined) {
633
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
634
+ __tnRaiseIrError(
635
+ "tn.ir.missing_param",
636
+ `${prefix}Missing IR switch tag '${node.tag}'`
637
+ );
638
+ }
639
+ const tagNumber = Number(tagVal);
640
+ for (const caseNode of node.cases) {
641
+ if (caseNode.value === tagNumber) {
642
+ return __tnEvalIrNode(caseNode.node, ctx);
643
+ }
644
+ }
645
+ if (node.default) return __tnEvalIrNode(node.default, ctx);
646
+ __tnRaiseIrError(
647
+ "tn.ir.invalid_tag",
648
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
649
+ );
650
+ }
651
+ case "call": {
652
+ const nestedParams: Record<string, bigint> = Object.create(null);
653
+ for (const arg of node.args) {
654
+ const val = ctx.params[arg.source];
655
+ if (val === undefined) {
656
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
657
+ __tnRaiseIrError(
658
+ "tn.ir.missing_param",
659
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
660
+ );
661
+ }
662
+ nestedParams[arg.name] = val;
663
+ }
664
+ if (ctx.buffer) {
665
+ const nestedResult = __tnInvokeValidate(
666
+ node.typeName,
667
+ ctx.buffer,
668
+ nestedParams
669
+ );
670
+ if (!nestedResult.ok) {
671
+ const nestedCode =
672
+ nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
673
+ const prefixed = nestedCode.startsWith("tn.")
674
+ ? nestedCode
675
+ : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
676
+ __tnRaiseIrError(
677
+ prefixed,
678
+ `Nested validator ${node.typeName} failed`
679
+ );
680
+ }
681
+ if (nestedResult.consumed !== undefined) {
682
+ return nestedResult.consumed;
683
+ }
684
+ }
685
+ return __tnInvokeFootprint(node.typeName, nestedParams);
686
+ }
687
+ default:
688
+ __tnRaiseIrError(
689
+ "tn.ir.runtime_error",
690
+ `Unsupported IR node ${(node as { op: string }).op}`
691
+ );
692
+ }
693
+ }
694
+
695
+ function __tnNormalizeIrError(err: unknown): string {
696
+ if (err && typeof err === "object" && "code" in err) {
697
+ const maybeCode = (err as { code?: string }).code;
698
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
699
+ return maybeCode;
700
+ }
701
+ }
702
+ const message =
703
+ err && typeof err === "object" && "message" in err
704
+ ? String((err as { message?: unknown }).message ?? "")
705
+ : typeof err === "string"
706
+ ? err
707
+ : "";
708
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
709
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
710
+ if (
711
+ message.includes("invalid") ||
712
+ message.includes("overflow") ||
713
+ message.includes("negative size")
714
+ ) {
715
+ return "tn.ir.overflow";
716
+ }
717
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
718
+ return "tn.ir.runtime_error";
719
+ }
720
+
721
+ /* ----- TYPE DEFINITION FOR StateProofHeader ----- */
722
+
723
+ const __tn_ir_StateProofHeader = {
724
+ typeName: "StateProofHeader",
725
+ root: { op: "const", value: 40n }
726
+ } as const;
727
+
728
+ export class StateProofHeader {
729
+ private view: DataView;
730
+
731
+ private constructor(private buffer: Uint8Array) {
732
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
733
+ }
734
+
735
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): StateProofHeader {
736
+ if (!buffer || buffer.length === undefined) throw new Error("StateProofHeader.__tnCreateView requires a Uint8Array");
737
+ return new StateProofHeader(new Uint8Array(buffer));
738
+ }
739
+
740
+ static builder(): StateProofHeaderBuilder {
741
+ return new StateProofHeaderBuilder();
742
+ }
743
+
744
+ static fromBuilder(builder: StateProofHeaderBuilder): StateProofHeader | null {
745
+ const buffer = builder.build();
746
+ return StateProofHeader.from_array(buffer);
747
+ }
748
+
749
+ get_type_slot(): bigint {
750
+ const offset = 0;
751
+ return this.view.getBigUint64(offset, true); /* little-endian */
752
+ }
753
+
754
+ set_type_slot(value: bigint): void {
755
+ const offset = 0;
756
+ this.view.setBigUint64(offset, value, true); /* little-endian */
757
+ }
758
+
759
+ get type_slot(): bigint {
760
+ return this.get_type_slot();
761
+ }
762
+
763
+ set type_slot(value: bigint) {
764
+ this.set_type_slot(value);
765
+ }
766
+
767
+ get_path_bitset(): Hash {
768
+ const offset = 8;
769
+ const slice = this.buffer.subarray(offset, offset + 32);
770
+ return Hash.from_array(slice)!;
771
+ }
772
+
773
+ set_path_bitset(value: Hash): void {
774
+ /* Copy bytes from source struct to this field */
775
+ const sourceBytes = (value as any).buffer as Uint8Array;
776
+ const offset = 8;
777
+ this.buffer.set(sourceBytes, offset);
778
+ }
779
+
780
+ get path_bitset(): Hash {
781
+ return this.get_path_bitset();
782
+ }
783
+
784
+ set path_bitset(value: Hash) {
785
+ this.set_path_bitset(value);
786
+ }
787
+
788
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
789
+ return __tnEvalFootprint(__tn_ir_StateProofHeader.root, { params: __tnParams });
790
+ }
791
+
792
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
793
+ return __tnValidateIrTree(__tn_ir_StateProofHeader, buffer, __tnParams);
794
+ }
795
+
796
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
797
+ return this.__tnFootprintInternal(__tnParams);
798
+ }
799
+
800
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
801
+ return this.__tnValidateInternal(buffer, __tnParams);
802
+ }
803
+
804
+ static footprintIr(): bigint {
805
+ return this.__tnFootprintInternal(Object.create(null));
806
+ }
807
+
808
+ static footprint(): number {
809
+ const irResult = this.footprintIr();
810
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
811
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
812
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for StateProofHeader');
813
+ }
814
+ return __tnBigIntToNumber(irResult, 'StateProofHeader::footprint');
815
+ }
816
+
817
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
818
+ if (buffer.length < 40) return { ok: false, code: "tn.buffer_too_small", consumed: 40 };
819
+ return { ok: true, consumed: 40 };
820
+ }
821
+
822
+ static from_array(buffer: Uint8Array): StateProofHeader | null {
823
+ if (!buffer || buffer.length === undefined) {
824
+ return null;
825
+ }
826
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
827
+ const validation = this.validate(buffer);
828
+ if (!validation.ok) {
829
+ return null;
830
+ }
831
+ return new StateProofHeader(buffer);
832
+ }
833
+
834
+ }
835
+
836
+ __tnRegisterFootprint("StateProofHeader", (params) => StateProofHeader.__tnInvokeFootprint(params));
837
+ __tnRegisterValidate("StateProofHeader", (buffer, params) => StateProofHeader.__tnInvokeValidate(buffer, params));
838
+
839
+ export class StateProofHeaderBuilder {
840
+ private buffer: Uint8Array;
841
+ private view: DataView;
842
+
843
+ constructor() {
844
+ this.buffer = new Uint8Array(40);
845
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
846
+ }
847
+
848
+ set_type_slot(value: number): this {
849
+ const cast = __tnToBigInt(value);
850
+ this.view.setBigUint64(0, cast, true);
851
+ return this;
852
+ }
853
+
854
+ set_path_bitset(value: Uint8Array): this {
855
+ if (value.length !== 32) throw new Error("path_bitset expects 32 bytes");
856
+ this.buffer.set(value, 8);
857
+ return this;
858
+ }
859
+
860
+ build(): Uint8Array {
861
+ return this.buffer.slice();
862
+ }
863
+
864
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
865
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
866
+ target.set(this.buffer, offset);
867
+ return target;
868
+ }
869
+
870
+ finish(): StateProofHeader {
871
+ const view = StateProofHeader.from_array(this.buffer.slice());
872
+ if (!view) throw new Error("failed to build StateProofHeader");
873
+ return view;
874
+ }
875
+ }
876
+
877
+ /* ----- TYPE DEFINITION FOR StateProof ----- */
878
+
879
+ const __tn_ir_StateProof = {
880
+ typeName: "StateProof",
881
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 1, node: { op: "const", value: 40n } }, right: { op: "align", alignment: 1, node: { op: "field", param: "proof_body.payload_size" } } } }
882
+ } as const;
883
+
884
+ export class StateProof_proof_body_existing_Inner {
885
+ private view: DataView;
886
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
887
+
888
+ private constructor(private buffer: Uint8Array, fieldContext?: Record<string, number | bigint>) {
889
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
890
+ this.__tnFieldContext = fieldContext ?? null;
891
+ }
892
+
893
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): StateProof_proof_body_existing_Inner {
894
+ if (!buffer || buffer.length === undefined) throw new Error("StateProof_proof_body_existing_Inner.__tnCreateView requires a Uint8Array");
895
+ return new StateProof_proof_body_existing_Inner(new Uint8Array(buffer), opts?.fieldContext);
896
+ }
897
+
898
+ withFieldContext(context: Record<string, number | bigint>): this {
899
+ this.__tnFieldContext = context;
900
+ return this;
901
+ }
902
+
903
+ private __tnResolveFieldRef(path: string): number {
904
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
905
+ const getter = (this as any)[getterName];
906
+ if (typeof getter === "function") {
907
+ const value = getter.call(this);
908
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "StateProof_proof_body_existing_Inner::__tnResolveFieldRef") : value;
909
+ }
910
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
911
+ const contextValue = this.__tnFieldContext[path];
912
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "StateProof_proof_body_existing_Inner::__tnResolveFieldRef") : contextValue;
913
+ }
914
+ throw new Error("StateProof_proof_body_existing_Inner: field reference '" + path + "' is not available; provide fieldContext when creating this view");
915
+ }
916
+
917
+ get_sibling_hashes_length(): number {
918
+ return ((__tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.0")) + __tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.1"))) + (__tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.2")) + __tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.3"))));
919
+ }
920
+
921
+ get_sibling_hashes_at(index: number): Hash {
922
+ const offset = 0;
923
+ const slice = this.buffer.subarray((offset + index * 32), (offset + (index + 1) * 32));
924
+ return Hash.from_array(slice)!;
925
+ }
926
+
927
+ get_sibling_hashes(): Hash[] {
928
+ const len = this.get_sibling_hashes_length();
929
+ const result: Hash[] = [];
930
+ for (let i = 0; i < len; i++) {
931
+ result.push(this.get_sibling_hashes_at(i));
932
+ }
933
+ return result;
934
+ }
935
+
936
+ set_sibling_hashes_at(index: number, value: Hash): void {
937
+ const offset = 0;
938
+ const slice = this.buffer.subarray(offset + index * 32, offset + (index + 1) * 32);
939
+ slice.set(value['buffer']);
940
+ }
941
+
942
+ set_sibling_hashes(value: Hash[]): void {
943
+ const len = Math.min(this.get_sibling_hashes_length(), value.length);
944
+ for (let i = 0; i < len; i++) {
945
+ this.set_sibling_hashes_at(i, value[i]);
946
+ }
947
+ }
948
+
949
+ get sibling_hashes(): Hash[] {
950
+ return this.get_sibling_hashes();
951
+ }
952
+
953
+ set sibling_hashes(value: Hash[]) {
954
+ this.set_sibling_hashes(value);
955
+ }
956
+
957
+ }
958
+
959
+ export class StateProof_proof_body_updating_Inner {
960
+ private view: DataView;
961
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
962
+
963
+ private constructor(private buffer: Uint8Array, fieldContext?: Record<string, number | bigint>) {
964
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
965
+ this.__tnFieldContext = fieldContext ?? null;
966
+ }
967
+
968
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): StateProof_proof_body_updating_Inner {
969
+ if (!buffer || buffer.length === undefined) throw new Error("StateProof_proof_body_updating_Inner.__tnCreateView requires a Uint8Array");
970
+ return new StateProof_proof_body_updating_Inner(new Uint8Array(buffer), opts?.fieldContext);
971
+ }
972
+
973
+ withFieldContext(context: Record<string, number | bigint>): this {
974
+ this.__tnFieldContext = context;
975
+ return this;
976
+ }
977
+
978
+ private __tnResolveFieldRef(path: string): number {
979
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
980
+ const getter = (this as any)[getterName];
981
+ if (typeof getter === "function") {
982
+ const value = getter.call(this);
983
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "StateProof_proof_body_updating_Inner::__tnResolveFieldRef") : value;
984
+ }
985
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
986
+ const contextValue = this.__tnFieldContext[path];
987
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "StateProof_proof_body_updating_Inner::__tnResolveFieldRef") : contextValue;
988
+ }
989
+ throw new Error("StateProof_proof_body_updating_Inner: field reference '" + path + "' is not available; provide fieldContext when creating this view");
990
+ }
991
+
992
+ get_existing_leaf_hash(): Hash {
993
+ const offset = 0;
994
+ const slice = this.buffer.subarray(offset, offset + 32);
995
+ return Hash.from_array(slice)!;
996
+ }
997
+
998
+ set_existing_leaf_hash(value: Hash): void {
999
+ /* Copy bytes from source struct to this field */
1000
+ const sourceBytes = (value as any).buffer as Uint8Array;
1001
+ const offset = 0;
1002
+ this.buffer.set(sourceBytes, offset);
1003
+ }
1004
+
1005
+ get existing_leaf_hash(): Hash {
1006
+ return this.get_existing_leaf_hash();
1007
+ }
1008
+
1009
+ set existing_leaf_hash(value: Hash) {
1010
+ this.set_existing_leaf_hash(value);
1011
+ }
1012
+
1013
+ get_sibling_hashes_length(): number {
1014
+ return ((__tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.0")) + __tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.1"))) + (__tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.2")) + __tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.3"))));
1015
+ }
1016
+
1017
+ get_sibling_hashes_at(index: number): Hash {
1018
+ const offset = 32;
1019
+ const slice = this.buffer.subarray((offset + index * 32), (offset + (index + 1) * 32));
1020
+ return Hash.from_array(slice)!;
1021
+ }
1022
+
1023
+ get_sibling_hashes(): Hash[] {
1024
+ const len = this.get_sibling_hashes_length();
1025
+ const result: Hash[] = [];
1026
+ for (let i = 0; i < len; i++) {
1027
+ result.push(this.get_sibling_hashes_at(i));
1028
+ }
1029
+ return result;
1030
+ }
1031
+
1032
+ set_sibling_hashes_at(index: number, value: Hash): void {
1033
+ const offset = 32;
1034
+ const slice = this.buffer.subarray(offset + index * 32, offset + (index + 1) * 32);
1035
+ slice.set(value['buffer']);
1036
+ }
1037
+
1038
+ set_sibling_hashes(value: Hash[]): void {
1039
+ const len = Math.min(this.get_sibling_hashes_length(), value.length);
1040
+ for (let i = 0; i < len; i++) {
1041
+ this.set_sibling_hashes_at(i, value[i]);
1042
+ }
1043
+ }
1044
+
1045
+ get sibling_hashes(): Hash[] {
1046
+ return this.get_sibling_hashes();
1047
+ }
1048
+
1049
+ set sibling_hashes(value: Hash[]) {
1050
+ this.set_sibling_hashes(value);
1051
+ }
1052
+
1053
+ }
1054
+
1055
+ export class StateProof_proof_body_creation_Inner {
1056
+ private view: DataView;
1057
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1058
+
1059
+ private constructor(private buffer: Uint8Array, fieldContext?: Record<string, number | bigint>) {
1060
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1061
+ this.__tnFieldContext = fieldContext ?? null;
1062
+ }
1063
+
1064
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): StateProof_proof_body_creation_Inner {
1065
+ if (!buffer || buffer.length === undefined) throw new Error("StateProof_proof_body_creation_Inner.__tnCreateView requires a Uint8Array");
1066
+ return new StateProof_proof_body_creation_Inner(new Uint8Array(buffer), opts?.fieldContext);
1067
+ }
1068
+
1069
+ withFieldContext(context: Record<string, number | bigint>): this {
1070
+ this.__tnFieldContext = context;
1071
+ return this;
1072
+ }
1073
+
1074
+ private __tnResolveFieldRef(path: string): number {
1075
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1076
+ const getter = (this as any)[getterName];
1077
+ if (typeof getter === "function") {
1078
+ const value = getter.call(this);
1079
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "StateProof_proof_body_creation_Inner::__tnResolveFieldRef") : value;
1080
+ }
1081
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1082
+ const contextValue = this.__tnFieldContext[path];
1083
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "StateProof_proof_body_creation_Inner::__tnResolveFieldRef") : contextValue;
1084
+ }
1085
+ throw new Error("StateProof_proof_body_creation_Inner: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1086
+ }
1087
+
1088
+ get_existing_leaf_pubkey(): Pubkey {
1089
+ const offset = 0;
1090
+ const slice = this.buffer.subarray(offset, offset + 32);
1091
+ return Pubkey.from_array(slice)!;
1092
+ }
1093
+
1094
+ set_existing_leaf_pubkey(value: Pubkey): void {
1095
+ /* Copy bytes from source struct to this field */
1096
+ const sourceBytes = (value as any).buffer as Uint8Array;
1097
+ const offset = 0;
1098
+ this.buffer.set(sourceBytes, offset);
1099
+ }
1100
+
1101
+ get existing_leaf_pubkey(): Pubkey {
1102
+ return this.get_existing_leaf_pubkey();
1103
+ }
1104
+
1105
+ set existing_leaf_pubkey(value: Pubkey) {
1106
+ this.set_existing_leaf_pubkey(value);
1107
+ }
1108
+
1109
+ get_existing_leaf_hash(): Hash {
1110
+ const offset = 32;
1111
+ const slice = this.buffer.subarray(offset, offset + 32);
1112
+ return Hash.from_array(slice)!;
1113
+ }
1114
+
1115
+ set_existing_leaf_hash(value: Hash): void {
1116
+ /* Copy bytes from source struct to this field */
1117
+ const sourceBytes = (value as any).buffer as Uint8Array;
1118
+ const offset = 32;
1119
+ this.buffer.set(sourceBytes, offset);
1120
+ }
1121
+
1122
+ get existing_leaf_hash(): Hash {
1123
+ return this.get_existing_leaf_hash();
1124
+ }
1125
+
1126
+ set existing_leaf_hash(value: Hash) {
1127
+ this.set_existing_leaf_hash(value);
1128
+ }
1129
+
1130
+ get_sibling_hashes_length(): number {
1131
+ return ((__tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.0")) + __tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.1"))) + (__tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.2")) + __tnPopcount(this.__tnResolveFieldRef("hdr.path_bitset.bytes.3"))));
1132
+ }
1133
+
1134
+ get_sibling_hashes_at(index: number): Hash {
1135
+ const offset = 64;
1136
+ const slice = this.buffer.subarray((offset + index * 32), (offset + (index + 1) * 32));
1137
+ return Hash.from_array(slice)!;
1138
+ }
1139
+
1140
+ get_sibling_hashes(): Hash[] {
1141
+ const len = this.get_sibling_hashes_length();
1142
+ const result: Hash[] = [];
1143
+ for (let i = 0; i < len; i++) {
1144
+ result.push(this.get_sibling_hashes_at(i));
1145
+ }
1146
+ return result;
1147
+ }
1148
+
1149
+ set_sibling_hashes_at(index: number, value: Hash): void {
1150
+ const offset = 64;
1151
+ const slice = this.buffer.subarray(offset + index * 32, offset + (index + 1) * 32);
1152
+ slice.set(value['buffer']);
1153
+ }
1154
+
1155
+ set_sibling_hashes(value: Hash[]): void {
1156
+ const len = Math.min(this.get_sibling_hashes_length(), value.length);
1157
+ for (let i = 0; i < len; i++) {
1158
+ this.set_sibling_hashes_at(i, value[i]);
1159
+ }
1160
+ }
1161
+
1162
+ get sibling_hashes(): Hash[] {
1163
+ return this.get_sibling_hashes();
1164
+ }
1165
+
1166
+ set sibling_hashes(value: Hash[]) {
1167
+ this.set_sibling_hashes(value);
1168
+ }
1169
+
1170
+ }
1171
+
1172
+ export class StateProof_proof_body_Inner {
1173
+ private view: DataView;
1174
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1175
+ private constructor(private buffer: Uint8Array, private descriptor: __TnVariantDescriptor | null, fieldContext?: Record<string, number | bigint>) {
1176
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1177
+ this.__tnFieldContext = fieldContext ?? null;
1178
+ }
1179
+
1180
+ static __tnCreate(payload: Uint8Array, descriptor: __TnVariantDescriptor | null, fieldContext?: Record<string, number | bigint>): StateProof_proof_body_Inner {
1181
+ return new StateProof_proof_body_Inner(new Uint8Array(payload), descriptor, fieldContext);
1182
+ }
1183
+
1184
+ bytes(): Uint8Array {
1185
+ return new Uint8Array(this.buffer);
1186
+ }
1187
+
1188
+ variant(): __TnVariantDescriptor | null {
1189
+ return this.descriptor;
1190
+ }
1191
+
1192
+ asExisting(): StateProof_proof_body_existing_Inner | null {
1193
+ if (!this.descriptor || this.descriptor.tag !== 0) return null;
1194
+ return StateProof_proof_body_existing_Inner.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
1195
+ }
1196
+
1197
+ asUpdating(): StateProof_proof_body_updating_Inner | null {
1198
+ if (!this.descriptor || this.descriptor.tag !== 1) return null;
1199
+ return StateProof_proof_body_updating_Inner.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
1200
+ }
1201
+
1202
+ asCreation(): StateProof_proof_body_creation_Inner | null {
1203
+ if (!this.descriptor || this.descriptor.tag !== 2) return null;
1204
+ return StateProof_proof_body_creation_Inner.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
1205
+ }
1206
+
1207
+ }
1208
+
1209
+ export class StateProof {
1210
+ private view: DataView;
1211
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1212
+ private static readonly __tnFieldOffset_proof_body = 40;
1213
+ private __tnParams: StateProof.Params;
1214
+ private __tnDerivedParams: Record<string, bigint> | null = null;
1215
+
1216
+ private constructor(private buffer: Uint8Array, params?: StateProof.Params, fieldContext?: Record<string, number | bigint>) {
1217
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1218
+ this.__tnFieldContext = fieldContext ?? null;
1219
+ if (params) {
1220
+ this.__tnParams = params;
1221
+ } else {
1222
+ const derived = StateProof.__tnExtractParams(this.view, buffer);
1223
+ if (!derived) {
1224
+ throw new Error("StateProof: failed to derive dynamic parameters");
1225
+ }
1226
+ this.__tnParams = derived.params;
1227
+ this.__tnDerivedParams = derived.derived;
1228
+ }
1229
+ }
1230
+
1231
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: StateProof.Params, fieldContext?: Record<string, number | bigint> }): StateProof {
1232
+ if (!buffer || buffer.length === undefined) throw new Error("StateProof.__tnCreateView requires a Uint8Array");
1233
+ let params = opts?.params ?? null;
1234
+ let derivedRecord: Record<string, bigint> | null = null;
1235
+ if (!params) {
1236
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1237
+ const derived = StateProof.__tnExtractParams(view, buffer);
1238
+ if (!derived) throw new Error("StateProof.__tnCreateView: failed to derive params");
1239
+ params = derived.params;
1240
+ derivedRecord = derived.derived;
1241
+ }
1242
+ const instance = new StateProof(new Uint8Array(buffer), params, opts?.fieldContext);
1243
+ if (derivedRecord) instance.__tnDerivedParams = derivedRecord;
1244
+ return instance;
1245
+ }
1246
+
1247
+ dynamicParams(): StateProof.Params {
1248
+ return this.__tnParams;
1249
+ }
1250
+
1251
+ withFieldContext(context: Record<string, number | bigint>): this {
1252
+ this.__tnFieldContext = context;
1253
+ return this;
1254
+ }
1255
+
1256
+ private __tnResolveFieldRef(path: string): number {
1257
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1258
+ const getter = (this as any)[getterName];
1259
+ if (typeof getter === "function") {
1260
+ const value = getter.call(this);
1261
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "StateProof::__tnResolveFieldRef") : value;
1262
+ }
1263
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1264
+ const contextValue = this.__tnFieldContext[path];
1265
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "StateProof::__tnResolveFieldRef") : contextValue;
1266
+ }
1267
+ throw new Error("StateProof: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1268
+ }
1269
+
1270
+ static builder(): StateProofBuilder {
1271
+ return new StateProofBuilder();
1272
+ }
1273
+
1274
+ static fromBuilder(builder: StateProofBuilder): StateProof | null {
1275
+ const buffer = builder.build();
1276
+ const params = builder.dynamicParams();
1277
+ return StateProof.from_array(buffer, { params });
1278
+ }
1279
+
1280
+ static readonly proof_bodyVariantDescriptors = Object.freeze([
1281
+ {
1282
+ name: "existing",
1283
+ tag: 0,
1284
+ payloadSize: null,
1285
+ payloadType: "StateProof::proof_body::existing",
1286
+ createPayloadBuilder: () => null,
1287
+ },
1288
+ {
1289
+ name: "updating",
1290
+ tag: 1,
1291
+ payloadSize: null,
1292
+ payloadType: "StateProof::proof_body::updating",
1293
+ createPayloadBuilder: () => null,
1294
+ },
1295
+ {
1296
+ name: "creation",
1297
+ tag: 2,
1298
+ payloadSize: null,
1299
+ payloadType: "StateProof::proof_body::creation",
1300
+ createPayloadBuilder: () => null,
1301
+ },
1302
+ ] as const);
1303
+
1304
+ static __tnComputeSequentialLayout(view: DataView, buffer: Uint8Array): { params: Record<string, bigint> | null; offsets: Record<string, number> | null; derived: Record<string, bigint> | null } | null {
1305
+ const derived: Record<string, bigint> = Object.create(null);
1306
+ const __tnLength = buffer.length;
1307
+ let __tnParamSeq_proof_body_payload_size: bigint | null = null;
1308
+ let __tnCursorMutable = 0;
1309
+ if (__tnLength < 8) return null;
1310
+ const __tnRef_hdr_type_slot = view.getBigUint64(0, true);
1311
+ if (__tnCursorMutable + 40 > __tnLength) return null;
1312
+ __tnCursorMutable += 40;
1313
+ const __tnEnumTagValue_proof_body = Math.trunc(Number(((__tnRef_hdr_type_slot >> 62n) & 3n)));
1314
+ if (!Number.isFinite(__tnEnumTagValue_proof_body)) return null;
1315
+ let __tnEnumSize_proof_body = 0;
1316
+ switch (Number(__tnEnumTagValue_proof_body)) {
1317
+ case 0: break;
1318
+ case 1: break;
1319
+ case 2: break;
1320
+ default: return null;
1321
+ }
1322
+ if (__tnCursorMutable > __tnLength) return null;
1323
+ __tnEnumSize_proof_body = __tnLength - __tnCursorMutable;
1324
+ __tnCursorMutable = __tnLength;
1325
+ derived["StateProof__proof_body_computed_tag"] = __tnToBigInt(__tnEnumTagValue_proof_body);
1326
+ __tnParamSeq_proof_body_payload_size = __tnToBigInt(__tnEnumSize_proof_body);
1327
+ const params: Record<string, bigint> = Object.create(null);
1328
+ if (__tnParamSeq_proof_body_payload_size === null) return null;
1329
+ params["proof_body_payload_size"] = __tnParamSeq_proof_body_payload_size as bigint;
1330
+ return { params, offsets: null, derived: derived };
1331
+ }
1332
+
1333
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: StateProof.Params; derived: Record<string, bigint> | null } | null {
1334
+ if (buffer.length < 8) {
1335
+ return null;
1336
+ }
1337
+ const __tnParam_proof_body_hdr_type_slot = __tnToBigInt(view.getBigUint64(0, true));
1338
+ const __tnLayout = StateProof.__tnComputeSequentialLayout(view, buffer);
1339
+ if (!__tnLayout || !__tnLayout.params) return null;
1340
+ const __tnSeqParams = __tnLayout.params;
1341
+ const __tnParamSeq_proof_body_payload_size = __tnSeqParams["proof_body_payload_size"];
1342
+ if (__tnParamSeq_proof_body_payload_size === undefined) return null;
1343
+ const __tnExtractedParams = StateProof.Params.fromValues({
1344
+ proof_body_hdr_type_slot: __tnParam_proof_body_hdr_type_slot,
1345
+ proof_body_payload_size: __tnParamSeq_proof_body_payload_size as bigint,
1346
+ });
1347
+ return { params: __tnExtractedParams, derived: (__tnLayout && __tnLayout.derived ? __tnLayout.derived : null) };
1348
+ }
1349
+
1350
+ private __tnEnsureDerivedParams(): Record<string, bigint> | null {
1351
+ if (this.__tnDerivedParams) return this.__tnDerivedParams;
1352
+ const layout = StateProof.__tnComputeSequentialLayout(this.view, this.buffer);
1353
+ if (!layout || !layout.derived) return null;
1354
+ this.__tnDerivedParams = layout.derived;
1355
+ return this.__tnDerivedParams;
1356
+ }
1357
+
1358
+ private __tnReadDerivedParam(key: string): number | null {
1359
+ const params = this.__tnEnsureDerivedParams();
1360
+ if (!params) return null;
1361
+ const value = params[key];
1362
+ if (value === undefined) return null;
1363
+ return __tnBigIntToNumber(value, "StateProof::__tnReadDerivedParam");
1364
+ }
1365
+
1366
+ get_hdr(): StateProofHeader {
1367
+ const offset = 0;
1368
+ const slice = this.buffer.subarray(offset, offset + 40);
1369
+ return StateProofHeader.from_array(slice)!;
1370
+ }
1371
+
1372
+ set_hdr(value: StateProofHeader): void {
1373
+ /* Copy bytes from source struct to this field */
1374
+ const sourceBytes = (value as any).buffer as Uint8Array;
1375
+ const offset = 0;
1376
+ this.buffer.set(sourceBytes, offset);
1377
+ }
1378
+
1379
+ get hdr(): StateProofHeader {
1380
+ return this.get_hdr();
1381
+ }
1382
+
1383
+ set hdr(value: StateProofHeader) {
1384
+ this.set_hdr(value);
1385
+ }
1386
+
1387
+ get_proof_body_computed_tag(): number {
1388
+ let tag = this.__tnReadDerivedParam("StateProof__proof_body_computed_tag");
1389
+ if (tag === null) {
1390
+ tag = (((this.__tnResolveFieldRef("hdr.type_slot") >> 62) & 3));
1391
+ }
1392
+ return tag;
1393
+ }
1394
+
1395
+ proofBodyVariant(): typeof StateProof.proof_bodyVariantDescriptors[number] | null {
1396
+ const tag = this.get_proof_body_computed_tag();
1397
+ return StateProof.proof_bodyVariantDescriptors.find((variant) => variant.tag === tag) ?? null;
1398
+ }
1399
+
1400
+ proof_body(): StateProof_proof_body_Inner {
1401
+ const descriptor = this.proofBodyVariant();
1402
+ if (!descriptor) throw new Error("StateProof: unknown proof_body variant");
1403
+ const offset = StateProof.__tnFieldOffset_proof_body;
1404
+ const remaining = this.buffer.length - offset;
1405
+ const payloadLength = descriptor.payloadSize ?? remaining;
1406
+ if (payloadLength < 0 || offset + payloadLength > this.buffer.length) throw new Error("StateProof: payload exceeds buffer bounds");
1407
+ const slice = this.buffer.subarray(offset, offset + payloadLength);
1408
+ const __tnAutoContext: Record<string, number | bigint> = {
1409
+ "hdr.path_bitset.bytes.0": this.view.getUint8(8),
1410
+ "hdr.path_bitset.bytes.1": this.view.getUint8(9),
1411
+ "hdr.path_bitset.bytes.2": this.view.getUint8(10),
1412
+ "hdr.path_bitset.bytes.3": this.view.getUint8(11),
1413
+ };
1414
+ const __tnMergedContext = this.__tnFieldContext ? { ...__tnAutoContext, ...this.__tnFieldContext } : __tnAutoContext;
1415
+ return StateProof_proof_body_Inner.__tnCreate(slice, descriptor, __tnMergedContext);
1416
+ }
1417
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1418
+ return __tnEvalFootprint(__tn_ir_StateProof.root, { params: __tnParams });
1419
+ }
1420
+
1421
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1422
+ return __tnValidateIrTree(__tn_ir_StateProof, buffer, __tnParams);
1423
+ }
1424
+
1425
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1426
+ return this.__tnFootprintInternal(__tnParams);
1427
+ }
1428
+
1429
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1430
+ return this.__tnValidateInternal(buffer, __tnParams);
1431
+ }
1432
+
1433
+ static footprintIr(proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint): bigint {
1434
+ const params = StateProof.Params.fromValues({
1435
+ proof_body_hdr_type_slot: proof_body_hdr_type_slot,
1436
+ proof_body_payload_size: proof_body_payload_size,
1437
+ });
1438
+ return this.footprintIrFromParams(params);
1439
+ }
1440
+
1441
+ private static __tnPackParams(params: StateProof.Params): Record<string, bigint> {
1442
+ const record: Record<string, bigint> = Object.create(null);
1443
+ record["proof_body.hdr.type_slot"] = params.proof_body_hdr_type_slot;
1444
+ record["proof_body.payload_size"] = params.proof_body_payload_size;
1445
+ return record;
1446
+ }
1447
+
1448
+ static footprintIrFromParams(params: StateProof.Params): bigint {
1449
+ const __tnParams = this.__tnPackParams(params);
1450
+ return this.__tnFootprintInternal(__tnParams);
1451
+ }
1452
+
1453
+ static footprintFromParams(params: StateProof.Params): number {
1454
+ const irResult = this.footprintIrFromParams(params);
1455
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1456
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for StateProof');
1457
+ return __tnBigIntToNumber(irResult, 'StateProof::footprintFromParams');
1458
+ }
1459
+
1460
+ static footprintFromValues(input: { proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint }): number {
1461
+ const params = StateProof.params(input);
1462
+ return this.footprintFromParams(params);
1463
+ }
1464
+
1465
+ static footprint(params: StateProof.Params): number {
1466
+ return this.footprintFromParams(params);
1467
+ }
1468
+
1469
+ static validate(buffer: Uint8Array, opts?: { params?: StateProof.Params }): { ok: boolean; code?: string; consumed?: number; params?: StateProof.Params } {
1470
+ if (!buffer || buffer.length === undefined) {
1471
+ return { ok: false, code: "tn.invalid_buffer" };
1472
+ }
1473
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1474
+ let params = opts?.params ?? null;
1475
+ if (!params) {
1476
+ const extracted = this.__tnExtractParams(view, buffer);
1477
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1478
+ params = extracted.params;
1479
+ }
1480
+ const __tnParamsRec = this.__tnPackParams(params);
1481
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1482
+ if (!irResult.ok) {
1483
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'StateProof::validate') : undefined, params };
1484
+ }
1485
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'StateProof::validate') : undefined;
1486
+ return { ok: true, consumed, params };
1487
+ }
1488
+
1489
+ static from_array(buffer: Uint8Array, opts?: { params?: StateProof.Params }): StateProof | null {
1490
+ if (!buffer || buffer.length === undefined) {
1491
+ return null;
1492
+ }
1493
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1494
+ let params = opts?.params ?? null;
1495
+ let derivedRecord: Record<string, bigint> | null = null;
1496
+ if (!params) {
1497
+ const derived = this.__tnExtractParams(view, buffer);
1498
+ if (!derived) return null;
1499
+ params = derived.params;
1500
+ derivedRecord = derived.derived;
1501
+ }
1502
+ const validation = this.validate(buffer, { params });
1503
+ if (!validation.ok) {
1504
+ return null;
1505
+ }
1506
+ const cached = validation.params ?? params;
1507
+ const state = new StateProof(buffer, cached);
1508
+ if (derivedRecord) state.__tnDerivedParams = derivedRecord;
1509
+ return state;
1510
+ }
1511
+
1512
+
1513
+ }
1514
+
1515
+ export namespace StateProof {
1516
+ export type Params = {
1517
+ /** ABI path: proof_body.hdr.type_slot */
1518
+ readonly proof_body_hdr_type_slot: bigint;
1519
+ /** ABI path: proof_body.payload_size */
1520
+ readonly proof_body_payload_size: bigint;
1521
+ };
1522
+
1523
+ export const ParamKeys = Object.freeze({
1524
+ proof_body_hdr_type_slot: "proof_body.hdr.type_slot",
1525
+ proof_body_payload_size: "proof_body.payload_size",
1526
+ } as const);
1527
+
1528
+ export const Params = {
1529
+ fromValues(input: { proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint }): Params {
1530
+ return {
1531
+ proof_body_hdr_type_slot: __tnToBigInt(input.proof_body_hdr_type_slot),
1532
+ proof_body_payload_size: __tnToBigInt(input.proof_body_payload_size),
1533
+ };
1534
+ },
1535
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
1536
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
1537
+ return (source as { dynamicParams(): Params }).dynamicParams();
1538
+ }
1539
+ if ((source as { params?: Params }).params) {
1540
+ return (source as { params: Params }).params;
1541
+ }
1542
+ return source as Params;
1543
+ }
1544
+ };
1545
+
1546
+ export function params(input: { proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint }): Params {
1547
+ return Params.fromValues(input);
1548
+ }
1549
+ }
1550
+
1551
+ __tnRegisterFootprint("StateProof", (params) => StateProof.__tnInvokeFootprint(params));
1552
+ __tnRegisterValidate("StateProof", (buffer, params) => StateProof.__tnInvokeValidate(buffer, params));
1553
+
1554
+ export class StateProofBuilder {
1555
+ private __tnPrefixBuffer: Uint8Array;
1556
+ private __tnPrefixView: DataView;
1557
+ private __tnPayload_proof_body: { descriptor: typeof StateProof.proof_bodyVariantDescriptors[number]; bytes: Uint8Array } | null = null;
1558
+ private __tnCachedParams: StateProof.Params | null = null;
1559
+ private __tnLastBuffer: Uint8Array | null = null;
1560
+ private __tnLastParams: StateProof.Params | null = null;
1561
+ private __tnVariantSelector_proof_body?: __TnVariantSelectorResult<StateProofBuilder>;
1562
+
1563
+ constructor() {
1564
+ this.__tnPrefixBuffer = new Uint8Array(40);
1565
+ this.__tnPrefixView = new DataView(this.__tnPrefixBuffer.buffer, this.__tnPrefixBuffer.byteOffset, this.__tnPrefixBuffer.byteLength);
1566
+ }
1567
+
1568
+ set_hdr(value: Uint8Array): this {
1569
+ if (value.length !== 40) throw new Error("hdr expects 40 bytes");
1570
+ this.__tnPrefixBuffer.set(value, 0);
1571
+ this.__tnInvalidate();
1572
+ return this;
1573
+ }
1574
+
1575
+ private __tnInvalidate(): void {
1576
+ this.__tnCachedParams = null;
1577
+ this.__tnLastBuffer = null;
1578
+ this.__tnLastParams = null;
1579
+ }
1580
+
1581
+ proof_body(): __TnVariantSelectorResult<StateProofBuilder> {
1582
+ if (!this.__tnVariantSelector_proof_body) {
1583
+ this.__tnVariantSelector_proof_body = __tnCreateVariantSelector(this, StateProof.proof_bodyVariantDescriptors, (descriptor, payload) => {
1584
+ this.__tnPayload_proof_body = { descriptor, bytes: new Uint8Array(payload) };
1585
+ this.__tnInvalidate();
1586
+ });
1587
+ }
1588
+ return this.__tnVariantSelector_proof_body!;
1589
+ }
1590
+
1591
+ build(): Uint8Array {
1592
+ const params = this.__tnComputeParams();
1593
+ if (!this.__tnPayload_proof_body) throw new Error("StateProofBuilder: payload variant not selected");
1594
+ const payloadLength = this.__tnPayload_proof_body.bytes.length;
1595
+ const requiredSize = 40 + payloadLength;
1596
+ const footprintSize = StateProof.footprintFromParams(params);
1597
+ const size = Math.max(requiredSize, footprintSize);
1598
+ const buffer = new Uint8Array(size);
1599
+ this.__tnWriteInto(buffer);
1600
+ this.__tnValidateOrThrow(buffer, params);
1601
+ return buffer;
1602
+ }
1603
+
1604
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1605
+ const params = this.__tnComputeParams();
1606
+ if (!this.__tnPayload_proof_body) throw new Error("StateProofBuilder: payload variant not selected");
1607
+ const payloadLength = this.__tnPayload_proof_body.bytes.length;
1608
+ const requiredSize = 40 + payloadLength;
1609
+ const footprintSize = StateProof.footprintFromParams(params);
1610
+ const size = Math.max(requiredSize, footprintSize);
1611
+ if (target.length - offset < size) throw new Error("StateProofBuilder: target buffer too small");
1612
+ const slice = target.subarray(offset, offset + size);
1613
+ this.__tnWriteInto(slice);
1614
+ this.__tnValidateOrThrow(slice, params);
1615
+ return target;
1616
+ }
1617
+
1618
+ finish(): StateProof {
1619
+ const buffer = this.build();
1620
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1621
+ const view = StateProof.from_array(buffer, { params });
1622
+ if (!view) throw new Error("StateProofBuilder: failed to finalize view");
1623
+ return view;
1624
+ }
1625
+
1626
+ finishView(): StateProof {
1627
+ return this.finish();
1628
+ }
1629
+
1630
+ dynamicParams(): StateProof.Params {
1631
+ return this.__tnComputeParams();
1632
+ }
1633
+
1634
+ private __tnComputeParams(): StateProof.Params {
1635
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1636
+ const params = StateProof.Params.fromValues({
1637
+ proof_body_hdr_type_slot: (() => { const slice = this.__tnPrefixBuffer.subarray(0, 40); const header = StateProofHeader.from_array(slice); if (!header) throw new Error("StateProofBuilder: field 'hdr' must be set before build"); return __tnToBigInt(header.get_type_slot()); })(),
1638
+ proof_body_payload_size: (() => { if (!this.__tnPayload_proof_body) throw new Error("StateProofBuilder: payload 'proof_body' must be selected before build"); return __tnToBigInt(this.__tnPayload_proof_body.bytes.length); })(),
1639
+ });
1640
+ this.__tnCachedParams = params;
1641
+ return params;
1642
+ }
1643
+
1644
+ private __tnWriteInto(target: Uint8Array): void {
1645
+ if (!this.__tnPayload_proof_body) throw new Error("StateProofBuilder: payload variant not selected");
1646
+ const view = new DataView(target.buffer, target.byteOffset, target.byteLength);
1647
+ target.set(this.__tnPrefixBuffer, 0);
1648
+ target.set(this.__tnPayload_proof_body.bytes, 40);
1649
+ const __tnLayout = StateProof.__tnComputeSequentialLayout(view, target);
1650
+ if (!__tnLayout || !__tnLayout.derived) throw new Error("StateProofBuilder: failed to derive enum tag");
1651
+ const __tnDerivedTagValue = __tnLayout.derived["StateProof__proof_body_computed_tag"];
1652
+ if (__tnDerivedTagValue === undefined) throw new Error("StateProofBuilder: computed enum tag missing");
1653
+ const __tnDerivedTag = __tnBigIntToNumber(__tnDerivedTagValue, "StateProofBuilder::__tnWriteInto");
1654
+ const __tnExpectedTag = this.__tnPayload_proof_body!.descriptor.tag;
1655
+ if (__tnDerivedTag !== __tnExpectedTag) throw new Error("StateProofBuilder: computed enum tag does not match selected variant");
1656
+ }
1657
+
1658
+ private __tnValidateOrThrow(buffer: Uint8Array, params: StateProof.Params): void {
1659
+ const result = StateProof.validate(buffer, { params });
1660
+ if (!result.ok) {
1661
+ throw new Error(`${ StateProof }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1662
+ }
1663
+ this.__tnLastParams = result.params ?? params;
1664
+ this.__tnLastBuffer = buffer;
1665
+ }
1666
+ }
1667
+