@thru/programs 0.2.22 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/multicall/index.cjs +2579 -0
  2. package/dist/multicall/index.cjs.map +1 -0
  3. package/dist/multicall/index.d.cts +253 -0
  4. package/dist/multicall/index.d.ts +253 -0
  5. package/dist/multicall/index.js +2573 -0
  6. package/dist/multicall/index.js.map +1 -0
  7. package/dist/passkey-manager/index.cjs +582 -706
  8. package/dist/passkey-manager/index.cjs.map +1 -1
  9. package/dist/passkey-manager/index.d.cts +20 -14
  10. package/dist/passkey-manager/index.d.ts +20 -14
  11. package/dist/passkey-manager/index.js +551 -673
  12. package/dist/passkey-manager/index.js.map +1 -1
  13. package/package.json +7 -2
  14. package/src/multicall/abi/thru/common/primitives/types.ts +2265 -0
  15. package/src/multicall/abi/thru/program/multicall/types.ts +1232 -0
  16. package/src/multicall/index.test.ts +46 -0
  17. package/src/multicall/index.ts +81 -0
  18. package/src/passkey-manager/abi/thru/blockchain/state_proof/types.ts +95 -19
  19. package/src/passkey-manager/abi/thru/common/primitives/types.ts +111 -37
  20. package/src/passkey-manager/abi/thru/program/passkey_manager/types.ts +248 -660
  21. package/src/passkey-manager/challenge.ts +52 -12
  22. package/src/passkey-manager/constants.ts +0 -1
  23. package/src/passkey-manager/index.ts +4 -4
  24. package/src/passkey-manager/instructions/add-authority.ts +8 -2
  25. package/src/passkey-manager/instructions/remove-authority.ts +9 -2
  26. package/src/passkey-manager/instructions/validate.ts +60 -14
  27. package/src/passkey-manager/target-instruction.ts +29 -0
  28. package/src/passkey-manager/types.ts +16 -0
  29. package/src/passkey-manager/validate.test.ts +173 -0
  30. package/tsup.config.ts +1 -0
  31. package/src/passkey-manager/instructions/invoke.ts +0 -25
  32. package/src/passkey-manager/instructions/shared.ts +0 -12
@@ -0,0 +1,1232 @@
1
+ /* Auto-generated TypeScript code */
2
+ /* WARNING: Do not modify this file directly. It is generated from ABI definitions. */
3
+
4
+ import { InstructionData } 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
+ readonly op: "sumOverArray";
38
+ readonly count: __TnIrNode;
39
+ readonly elementTypeName: string;
40
+ readonly fieldName: string;
41
+ };
42
+
43
+ type __TnIrContext = {
44
+ params: Record<string, bigint>;
45
+ buffer?: Uint8Array;
46
+ typeName?: string;
47
+ };
48
+
49
+ type __TnValidateResult = { ok: boolean; code?: string; consumed?: bigint };
50
+ type __TnEvalResult =
51
+ | { ok: true; value: bigint }
52
+ | { ok: false; code: string };
53
+ type __TnBuilderLike = { build(): Uint8Array };
54
+ type __TnStructFieldInput =
55
+ | Uint8Array
56
+ | __TnBuilderLike
57
+ | { buffer?: Uint8Array }
58
+ | { asUint8Array?: () => Uint8Array }
59
+ | { bytes?: () => Uint8Array };
60
+ type __TnVariantDescriptor = {
61
+ readonly name: string;
62
+ readonly tag: number;
63
+ readonly payloadSize: number | null;
64
+ readonly payloadType?: string;
65
+ readonly createPayloadBuilder?: () => unknown | null;
66
+ };
67
+ type __TnVariantSelectorResult<Parent> = {
68
+ select(
69
+ name: string
70
+ ): { writePayload(payload: Uint8Array | __TnBuilderLike): { finish(): Parent } };
71
+ finish(): Parent;
72
+ };
73
+ type __TnFamWriterResult<Parent> = {
74
+ write(payload: Uint8Array | __TnBuilderLike): { finish(): Parent };
75
+ finish(): Parent;
76
+ };
77
+ type __TnConsole = { warn?: (...args: unknown[]) => void };
78
+
79
+ const __tnWarnings = new Set<string>();
80
+ const __tnHasNativeBigInt = typeof BigInt === "function";
81
+ const __tnHasBigIntDataView =
82
+ typeof DataView !== "undefined" &&
83
+ typeof DataView.prototype.getBigInt64 === "function" &&
84
+ typeof DataView.prototype.getBigUint64 === "function" &&
85
+ typeof DataView.prototype.setBigInt64 === "function" &&
86
+ typeof DataView.prototype.setBigUint64 === "function";
87
+ const __tnConsole: __TnConsole | undefined =
88
+ typeof globalThis !== "undefined"
89
+ ? (globalThis as { console?: __TnConsole }).console
90
+ : undefined;
91
+
92
+ function __tnLogWarn(message: string): void {
93
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
94
+ __tnConsole.warn(message);
95
+ }
96
+ }
97
+
98
+ function __tnWarnOnce(message: string): void {
99
+ if (!__tnWarnings.has(message)) {
100
+ __tnWarnings.add(message);
101
+ __tnLogWarn(message);
102
+ }
103
+ }
104
+
105
+ function __tnResolveBuilderInput(
106
+ input: Uint8Array | __TnBuilderLike,
107
+ context: string
108
+ ): Uint8Array {
109
+ if (input instanceof Uint8Array) {
110
+ return new Uint8Array(input);
111
+ }
112
+ if (input && typeof (input as __TnBuilderLike).build === "function") {
113
+ const built = (input as __TnBuilderLike).build();
114
+ if (!(built instanceof Uint8Array)) {
115
+ throw new Error(`${context}: builder did not return Uint8Array`);
116
+ }
117
+ return new Uint8Array(built);
118
+ }
119
+ throw new Error(`${context}: expected Uint8Array or builder`);
120
+ }
121
+
122
+ function __tnResolveStructFieldInput(
123
+ input: __TnStructFieldInput,
124
+ context: string
125
+ ): Uint8Array {
126
+ if (
127
+ input instanceof Uint8Array ||
128
+ (input && typeof (input as __TnBuilderLike).build === "function")
129
+ ) {
130
+ return __tnResolveBuilderInput(input as Uint8Array | __TnBuilderLike, context);
131
+ }
132
+ if (input && typeof (input as { asUint8Array?: () => Uint8Array }).asUint8Array === "function") {
133
+ const bytes = (input as { asUint8Array: () => Uint8Array }).asUint8Array();
134
+ return new Uint8Array(bytes);
135
+ }
136
+ if (input && typeof (input as { bytes?: () => Uint8Array }).bytes === "function") {
137
+ const bytes = (input as { bytes: () => Uint8Array }).bytes();
138
+ return new Uint8Array(bytes);
139
+ }
140
+ if (input && (input as { buffer?: unknown }).buffer instanceof Uint8Array) {
141
+ return new Uint8Array((input as { buffer: Uint8Array }).buffer);
142
+ }
143
+ throw new Error(`${context}: expected Uint8Array, builder, or view-like value`);
144
+ }
145
+
146
+ function __tnMaybeCallBuilder(ctor: unknown): unknown | null {
147
+ if (!ctor) {
148
+ return null;
149
+ }
150
+ const builderFn = (ctor as { builder?: () => unknown }).builder;
151
+ return typeof builderFn === "function" ? builderFn() : null;
152
+ }
153
+
154
+ function __tnCreateVariantSelector<Parent, Descriptor extends __TnVariantDescriptor>(
155
+ parent: Parent,
156
+ descriptors: readonly Descriptor[],
157
+ assign: (descriptor: Descriptor, payload: Uint8Array) => void
158
+ ): __TnVariantSelectorResult<Parent> {
159
+ return {
160
+ select(name: string) {
161
+ const descriptor = descriptors.find((variant) => variant.name === name);
162
+ if (!descriptor) {
163
+ throw new Error(`Unknown variant '${name}'`);
164
+ }
165
+ return {
166
+ writePayload(payload: Uint8Array | __TnBuilderLike) {
167
+ const bytes = __tnResolveBuilderInput(
168
+ payload,
169
+ `variant ${descriptor.name}`
170
+ );
171
+ if (
172
+ descriptor.payloadSize !== null &&
173
+ bytes.length !== descriptor.payloadSize
174
+ ) {
175
+ throw new Error(
176
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
177
+ );
178
+ }
179
+ assign(descriptor, bytes);
180
+ return {
181
+ finish(): Parent {
182
+ return parent;
183
+ },
184
+ };
185
+ },
186
+ };
187
+ },
188
+ finish(): Parent {
189
+ return parent;
190
+ },
191
+ };
192
+ }
193
+
194
+ function __tnCreateFamWriter<Parent>(
195
+ parent: Parent,
196
+ fieldName: string,
197
+ assign: (bytes: Uint8Array) => void
198
+ ): __TnFamWriterResult<Parent> {
199
+ let hasWritten = false;
200
+ return {
201
+ write(payload: Uint8Array | __TnBuilderLike) {
202
+ const bytes = __tnResolveBuilderInput(
203
+ payload,
204
+ `flexible array '${fieldName}'`
205
+ );
206
+ const copy = new Uint8Array(bytes);
207
+ assign(copy);
208
+ hasWritten = true;
209
+ return {
210
+ finish(): Parent {
211
+ return parent;
212
+ },
213
+ };
214
+ },
215
+ finish(): Parent {
216
+ if (!hasWritten) {
217
+ throw new Error(
218
+ `flexible array '${fieldName}' requires write() before finish()`
219
+ );
220
+ }
221
+ return parent;
222
+ },
223
+ };
224
+ }
225
+
226
+ const __tnMask32 = __tnHasNativeBigInt
227
+ ? (BigInt(1) << BigInt(32)) - BigInt(1)
228
+ : 0xffffffff;
229
+ const __tnSignBit32 = __tnHasNativeBigInt
230
+ ? BigInt(1) << BigInt(31)
231
+ : 0x80000000;
232
+
233
+ function __tnToBigInt(value: number | bigint): bigint {
234
+ if (__tnHasNativeBigInt) {
235
+ return typeof value === "bigint" ? value : BigInt(value);
236
+ }
237
+ if (typeof value === "bigint") return value;
238
+ if (!Number.isFinite(value)) {
239
+ throw new Error("IR runtime received non-finite numeric input");
240
+ }
241
+ if (!Number.isSafeInteger(value)) {
242
+ __tnWarnOnce(
243
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
244
+ );
245
+ }
246
+ return (value as unknown) as bigint;
247
+ }
248
+
249
+ function __tnBigIntToNumber(value: bigint, context: string): number {
250
+ if (__tnHasNativeBigInt) {
251
+ const converted = Number(value);
252
+ if (!Number.isFinite(converted)) {
253
+ throw new Error(`${context} overflowed Number range`);
254
+ }
255
+ return converted;
256
+ }
257
+ return value as unknown as number;
258
+ }
259
+
260
+ function __tnBigIntEquals(lhs: bigint, rhs: bigint): boolean {
261
+ if (__tnHasNativeBigInt) return lhs === rhs;
262
+ return (lhs as unknown as number) === (rhs as unknown as number);
263
+ }
264
+
265
+ function __tnBigIntGreaterThan(lhs: bigint, rhs: bigint): boolean {
266
+ if (__tnHasNativeBigInt) return lhs > rhs;
267
+ return (lhs as unknown as number) > (rhs as unknown as number);
268
+ }
269
+
270
+ function __tnPopcount(value: number | bigint): number {
271
+ let v =
272
+ typeof value === "bigint"
273
+ ? Number(value & BigInt(0xffffffff))
274
+ : Number(value) >>> 0;
275
+ v = v - ((v >>> 1) & 0x55555555);
276
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
277
+ return (((v + (v >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
278
+ }
279
+
280
+ function __tnRaiseIrError(code: string, message: string): never {
281
+ const err = new Error(message);
282
+ (err as { code?: string }).code = code;
283
+ throw err;
284
+ }
285
+
286
+ function __tnCheckedAdd(lhs: bigint, rhs: bigint): bigint {
287
+ if (__tnHasNativeBigInt) {
288
+ const result = (lhs as bigint) + (rhs as bigint);
289
+ if (result < BigInt(0)) {
290
+ __tnRaiseIrError(
291
+ "tn.ir.overflow",
292
+ "IR runtime detected negative size via addition"
293
+ );
294
+ }
295
+ return result;
296
+ }
297
+ const left = lhs as unknown as number;
298
+ const right = rhs as unknown as number;
299
+ const sum = left + right;
300
+ if (sum < 0 || !Number.isFinite(sum)) {
301
+ __tnRaiseIrError(
302
+ "tn.ir.overflow",
303
+ "IR runtime detected invalid addition result"
304
+ );
305
+ }
306
+ if (!Number.isSafeInteger(sum)) {
307
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
308
+ }
309
+ return (sum as unknown) as bigint;
310
+ }
311
+
312
+ function __tnCheckedMul(lhs: bigint, rhs: bigint): bigint {
313
+ if (__tnHasNativeBigInt) {
314
+ const result = (lhs as bigint) * (rhs as bigint);
315
+ if (result < BigInt(0)) {
316
+ __tnRaiseIrError(
317
+ "tn.ir.overflow",
318
+ "IR runtime detected negative size via multiplication"
319
+ );
320
+ }
321
+ return result;
322
+ }
323
+ const left = lhs as unknown as number;
324
+ const right = rhs as unknown as number;
325
+ const product = left * right;
326
+ if (product < 0 || !Number.isFinite(product)) {
327
+ __tnRaiseIrError(
328
+ "tn.ir.overflow",
329
+ "IR runtime detected invalid multiplication result"
330
+ );
331
+ }
332
+ if (!Number.isSafeInteger(product)) {
333
+ __tnWarnOnce(
334
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
335
+ );
336
+ }
337
+ return (product as unknown) as bigint;
338
+ }
339
+
340
+ function __tnAlign(value: bigint, alignment: number): bigint {
341
+ if (alignment <= 1) return value;
342
+ const alignBig = __tnToBigInt(alignment);
343
+ if (__tnHasNativeBigInt) {
344
+ const remainder = value % alignBig;
345
+ if (__tnBigIntEquals(remainder, __tnToBigInt(0))) {
346
+ return value;
347
+ }
348
+ const delta = alignBig - remainder;
349
+ return __tnCheckedAdd(value, delta);
350
+ }
351
+ const current = __tnBigIntToNumber(value, "IR align");
352
+ const alignNum = alignment >>> 0;
353
+ const remainder = current % alignNum;
354
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
355
+ return __tnToBigInt(next);
356
+ }
357
+
358
+ function __tnSplitUint64(value: bigint): { high: number; low: number } {
359
+ if (__tnHasNativeBigInt) {
360
+ const low = Number(value & (__tnMask32 as bigint));
361
+ const high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
362
+ return { high, low };
363
+ }
364
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
365
+ const low = num >>> 0;
366
+ const high = Math.floor(num / 4294967296) >>> 0;
367
+ return { high, low };
368
+ }
369
+
370
+ function __tnSplitInt64(value: bigint): { high: number; low: number } {
371
+ if (__tnHasNativeBigInt) {
372
+ const low = Number(value & (__tnMask32 as bigint));
373
+ let high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
374
+ if ((BigInt(high) & (__tnSignBit32 as bigint)) !== BigInt(0)) {
375
+ high -= 0x100000000;
376
+ }
377
+ return { high, low };
378
+ }
379
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
380
+ const low = num >>> 0;
381
+ const high = Math.floor(num / 4294967296);
382
+ return { high, low };
383
+ }
384
+
385
+ function __tnPolyfillReadUint64(
386
+ view: DataView,
387
+ offset: number,
388
+ littleEndian: boolean
389
+ ): bigint {
390
+ const low = littleEndian
391
+ ? view.getUint32(offset, true)
392
+ : view.getUint32(offset + 4, false);
393
+ const high = littleEndian
394
+ ? view.getUint32(offset + 4, true)
395
+ : view.getUint32(offset, false);
396
+ if (__tnHasNativeBigInt) {
397
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
398
+ }
399
+ const value = high * 4294967296 + low;
400
+ if (!Number.isSafeInteger(value)) {
401
+ __tnWarnOnce(
402
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
403
+ );
404
+ }
405
+ return (value as unknown) as bigint;
406
+ }
407
+
408
+ function __tnPolyfillReadInt64(
409
+ view: DataView,
410
+ offset: number,
411
+ littleEndian: boolean
412
+ ): bigint {
413
+ const low = littleEndian
414
+ ? view.getUint32(offset, true)
415
+ : view.getUint32(offset + 4, false);
416
+ const high = littleEndian
417
+ ? view.getInt32(offset + 4, true)
418
+ : view.getInt32(offset, false);
419
+ if (__tnHasNativeBigInt) {
420
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
421
+ }
422
+ const value = high * 4294967296 + low;
423
+ if (!Number.isSafeInteger(value)) {
424
+ __tnWarnOnce(
425
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
426
+ );
427
+ }
428
+ return (value as unknown) as bigint;
429
+ }
430
+
431
+ function __tnPolyfillWriteUint64(
432
+ view: DataView,
433
+ offset: number,
434
+ value: bigint,
435
+ littleEndian: boolean
436
+ ): void {
437
+ const parts = __tnSplitUint64(value);
438
+ if (littleEndian) {
439
+ view.setUint32(offset, parts.low, true);
440
+ view.setUint32(offset + 4, parts.high, true);
441
+ } else {
442
+ view.setUint32(offset, parts.high, false);
443
+ view.setUint32(offset + 4, parts.low, false);
444
+ }
445
+ }
446
+
447
+ function __tnPolyfillWriteInt64(
448
+ view: DataView,
449
+ offset: number,
450
+ value: bigint,
451
+ littleEndian: boolean
452
+ ): void {
453
+ const parts = __tnSplitInt64(value);
454
+ if (littleEndian) {
455
+ view.setUint32(offset, parts.low >>> 0, true);
456
+ view.setInt32(offset + 4, parts.high | 0, true);
457
+ } else {
458
+ view.setInt32(offset, parts.high | 0, false);
459
+ view.setUint32(offset + 4, parts.low >>> 0, false);
460
+ }
461
+ }
462
+
463
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
464
+ const proto = DataView.prototype as unknown as Record<string, unknown>;
465
+ if (typeof proto.getBigUint64 !== "function") {
466
+ (proto as any).getBigUint64 = function (
467
+ offset: number,
468
+ littleEndian?: boolean
469
+ ): bigint {
470
+ __tnWarnOnce(
471
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
472
+ );
473
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
474
+ };
475
+ }
476
+ if (typeof proto.getBigInt64 !== "function") {
477
+ (proto as any).getBigInt64 = function (
478
+ offset: number,
479
+ littleEndian?: boolean
480
+ ): bigint {
481
+ __tnWarnOnce(
482
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
483
+ );
484
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
485
+ };
486
+ }
487
+ if (typeof proto.setBigUint64 !== "function") {
488
+ (proto as any).setBigUint64 = function (
489
+ offset: number,
490
+ value: bigint,
491
+ littleEndian?: boolean
492
+ ): void {
493
+ __tnWarnOnce(
494
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
495
+ );
496
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
497
+ };
498
+ }
499
+ if (typeof proto.setBigInt64 !== "function") {
500
+ (proto as any).setBigInt64 = function (
501
+ offset: number,
502
+ value: bigint,
503
+ littleEndian?: boolean
504
+ ): void {
505
+ __tnWarnOnce(
506
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
507
+ );
508
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
509
+ };
510
+ }
511
+ if (!__tnHasNativeBigInt) {
512
+ __tnWarnOnce(
513
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
514
+ );
515
+ }
516
+ }
517
+
518
+ const __tnFootprintRegistry: Record<
519
+ string,
520
+ (params: Record<string, bigint>) => bigint
521
+ > = {};
522
+ const __tnValidateRegistry: Record<
523
+ string,
524
+ (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
525
+ > = {};
526
+ const __tnDynamicValidateRegistry: Record<
527
+ string,
528
+ (buffer: Uint8Array) => __TnValidateResult
529
+ > = {};
530
+
531
+ function __tnRegisterFootprint(
532
+ typeName: string,
533
+ fn: (params: Record<string, bigint>) => bigint
534
+ ): void {
535
+ __tnFootprintRegistry[typeName] = fn;
536
+ }
537
+
538
+ function __tnRegisterValidate(
539
+ typeName: string,
540
+ fn: (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
541
+ ): void {
542
+ __tnValidateRegistry[typeName] = fn;
543
+ }
544
+
545
+ function __tnRegisterDynamicValidate(
546
+ typeName: string,
547
+ fn: (buffer: Uint8Array) => __TnValidateResult
548
+ ): void {
549
+ __tnDynamicValidateRegistry[typeName] = fn;
550
+ }
551
+
552
+ function __tnInvokeFootprint(
553
+ typeName: string,
554
+ params: Record<string, bigint>
555
+ ): bigint {
556
+ const fn = __tnFootprintRegistry[typeName];
557
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
558
+ return fn(params);
559
+ }
560
+
561
+ function __tnInvokeValidate(
562
+ typeName: string,
563
+ buffer: Uint8Array,
564
+ params: Record<string, bigint>
565
+ ): __TnValidateResult {
566
+ const fn = __tnValidateRegistry[typeName];
567
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
568
+ return fn(buffer, params);
569
+ }
570
+
571
+ function __tnInvokeDynamicValidate(
572
+ typeName: string,
573
+ buffer: Uint8Array
574
+ ): __TnValidateResult {
575
+ const fn = __tnDynamicValidateRegistry[typeName];
576
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
577
+ return fn(buffer);
578
+ }
579
+
580
+ function __tnEvalFootprint(node: __TnIrNode, ctx: __TnIrContext): bigint {
581
+ return __tnEvalIrNode(node, ctx, __tnToBigInt(0));
582
+ }
583
+
584
+ function __tnTryEvalFootprint(
585
+ node: __TnIrNode,
586
+ ctx: __TnIrContext
587
+ ): __TnEvalResult {
588
+ return __tnTryEvalIr(node, ctx);
589
+ }
590
+
591
+ function __tnTryEvalIr(
592
+ node: __TnIrNode,
593
+ ctx: __TnIrContext
594
+ ): __TnEvalResult {
595
+ try {
596
+ return { ok: true, value: __tnEvalIrNode(node, ctx, __tnToBigInt(0)) };
597
+ } catch (err) {
598
+ return { ok: false, code: __tnNormalizeIrError(err) };
599
+ }
600
+ }
601
+
602
+ function __tnIsEvalError(result: __TnEvalResult): result is { ok: false; code: string } {
603
+ return result.ok === false;
604
+ }
605
+
606
+ function __tnValidateIrTree(
607
+ ir: { readonly typeName: string; readonly root: __TnIrNode },
608
+ buffer: Uint8Array,
609
+ params: Record<string, bigint>
610
+ ): __TnValidateResult {
611
+ const evalResult = __tnTryEvalIr(ir.root, {
612
+ params,
613
+ buffer,
614
+ typeName: ir.typeName,
615
+ });
616
+ if (__tnIsEvalError(evalResult)) {
617
+ return { ok: false, code: evalResult.code };
618
+ }
619
+ const required = evalResult.value;
620
+ const available = __tnToBigInt(buffer.length);
621
+ if (__tnBigIntGreaterThan(required, available)) {
622
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
623
+ }
624
+ return { ok: true, consumed: required };
625
+ }
626
+
627
+ function __tnEvalIrNode(
628
+ node: __TnIrNode,
629
+ ctx: __TnIrContext,
630
+ baseOffset: bigint
631
+ ): bigint {
632
+ switch (node.op) {
633
+ case "zero":
634
+ return __tnToBigInt(0);
635
+ case "const":
636
+ return node.value;
637
+ case "field": {
638
+ const val = ctx.params[node.param];
639
+ if (val === undefined) {
640
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
641
+ __tnRaiseIrError(
642
+ "tn.ir.missing_param",
643
+ `${prefix}Missing IR parameter '${node.param}'`
644
+ );
645
+ }
646
+ return val;
647
+ }
648
+ case "add":
649
+ {
650
+ const left = __tnEvalIrNode(node.left, ctx, baseOffset);
651
+ const right = __tnEvalIrNode(
652
+ node.right,
653
+ ctx,
654
+ __tnCheckedAdd(baseOffset, left)
655
+ );
656
+ return __tnCheckedAdd(left, right);
657
+ }
658
+ case "mul":
659
+ return __tnCheckedMul(
660
+ __tnEvalIrNode(node.left, ctx, baseOffset),
661
+ __tnEvalIrNode(node.right, ctx, baseOffset)
662
+ );
663
+ case "align":
664
+ return __tnAlign(__tnEvalIrNode(node.node, ctx, baseOffset), node.alignment);
665
+ case "switch": {
666
+ const tagVal = ctx.params[node.tag];
667
+ if (tagVal === undefined) {
668
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
669
+ __tnRaiseIrError(
670
+ "tn.ir.missing_param",
671
+ `${prefix}Missing IR switch tag '${node.tag}'`
672
+ );
673
+ }
674
+ const tagNumber = Number(tagVal);
675
+ for (const caseNode of node.cases) {
676
+ if (caseNode.value === tagNumber) {
677
+ return __tnEvalIrNode(caseNode.node, ctx, baseOffset);
678
+ }
679
+ }
680
+ if (node.default) return __tnEvalIrNode(node.default, ctx, baseOffset);
681
+ __tnRaiseIrError(
682
+ "tn.ir.invalid_tag",
683
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
684
+ );
685
+ }
686
+ case "call": {
687
+ const nestedParams: Record<string, bigint> = Object.create(null);
688
+ for (const arg of node.args) {
689
+ const val = ctx.params[arg.source];
690
+ if (val === undefined) {
691
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
692
+ __tnRaiseIrError(
693
+ "tn.ir.missing_param",
694
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
695
+ );
696
+ }
697
+ nestedParams[arg.name] = val;
698
+ }
699
+ if (ctx.buffer) {
700
+ const nestedOffset = __tnBigIntToNumber(baseOffset, "IR nested offset");
701
+ const nestedResult = __tnInvokeValidate(
702
+ node.typeName,
703
+ ctx.buffer.subarray(nestedOffset),
704
+ nestedParams
705
+ );
706
+ if (!nestedResult.ok) {
707
+ const nestedCode =
708
+ nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
709
+ const prefixed = nestedCode.startsWith("tn.")
710
+ ? nestedCode
711
+ : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
712
+ __tnRaiseIrError(
713
+ prefixed,
714
+ `Nested validator ${node.typeName} failed`
715
+ );
716
+ }
717
+ if (nestedResult.consumed !== undefined) {
718
+ return nestedResult.consumed;
719
+ }
720
+ }
721
+ return __tnInvokeFootprint(node.typeName, nestedParams);
722
+ }
723
+ case "sumOverArray": {
724
+ if (!ctx.buffer) {
725
+ __tnRaiseIrError(
726
+ "tn.ir.missing_buffer",
727
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
728
+ );
729
+ }
730
+ const count = __tnBigIntToNumber(
731
+ __tnEvalIrNode(node.count, ctx, baseOffset),
732
+ `Jagged array '${node.fieldName}' count`
733
+ );
734
+ let cursor = __tnBigIntToNumber(baseOffset, "IR jagged array offset");
735
+ let total = __tnToBigInt(0);
736
+ for (let i = 0; i < count; i++) {
737
+ const result = __tnInvokeDynamicValidate(
738
+ node.elementTypeName,
739
+ ctx.buffer.subarray(cursor)
740
+ );
741
+ if (!result.ok || result.consumed === undefined) {
742
+ const code = result.code ?? "tn.ir.runtime_error";
743
+ __tnRaiseIrError(
744
+ code,
745
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
746
+ );
747
+ }
748
+ cursor += __tnBigIntToNumber(result.consumed, "IR jagged element size");
749
+ total = __tnCheckedAdd(total, result.consumed);
750
+ }
751
+ return total;
752
+ }
753
+ default:
754
+ __tnRaiseIrError(
755
+ "tn.ir.runtime_error",
756
+ `Unsupported IR node ${(node as { op: string }).op}`
757
+ );
758
+ }
759
+ }
760
+
761
+ function __tnNormalizeIrError(err: unknown): string {
762
+ if (err && typeof err === "object" && "code" in err) {
763
+ const maybeCode = (err as { code?: string }).code;
764
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
765
+ return maybeCode;
766
+ }
767
+ }
768
+ const message =
769
+ err && typeof err === "object" && "message" in err
770
+ ? String((err as { message?: unknown }).message ?? "")
771
+ : typeof err === "string"
772
+ ? err
773
+ : "";
774
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
775
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
776
+ if (
777
+ message.includes("invalid") ||
778
+ message.includes("overflow") ||
779
+ message.includes("negative size")
780
+ ) {
781
+ return "tn.ir.overflow";
782
+ }
783
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
784
+ return "tn.ir.runtime_error";
785
+ }
786
+
787
+ __tnRegisterFootprint("InstructionData", (params) => InstructionData.__tnInvokeFootprint(params));
788
+ __tnRegisterValidate("InstructionData", (buffer, params) => InstructionData.__tnInvokeValidate(buffer, params));
789
+ __tnRegisterDynamicValidate("InstructionData", (buffer) => { const result = InstructionData.validate(buffer); return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed) }; });
790
+
791
+ /* ----- TYPE DEFINITION FOR MulticallArgs ----- */
792
+
793
+ const __tn_ir_MulticallArgs = {
794
+ typeName: "MulticallArgs",
795
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 1, node: { op: "sumOverArray", count: { op: "field", param: "calls.calls_count" }, elementTypeName: "InstructionData", fieldName: "calls" } } } }
796
+ } as const;
797
+
798
+ export class MulticallArgs {
799
+ private view: DataView;
800
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
801
+ private __tnParams: MulticallArgs.Params;
802
+
803
+ private constructor(private buffer: Uint8Array, params?: MulticallArgs.Params, fieldContext?: Record<string, number | bigint>) {
804
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
805
+ this.__tnFieldContext = fieldContext ?? null;
806
+ if (params) {
807
+ this.__tnParams = params;
808
+ } else {
809
+ const derived = MulticallArgs.__tnExtractParams(this.view, buffer);
810
+ if (!derived) {
811
+ throw new Error("MulticallArgs: failed to derive dynamic parameters");
812
+ }
813
+ this.__tnParams = derived.params;
814
+ }
815
+ }
816
+
817
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: MulticallArgs.Params, fieldContext?: Record<string, number | bigint> }): MulticallArgs {
818
+ if (!buffer || buffer.length === undefined) throw new Error("MulticallArgs.__tnCreateView requires a Uint8Array");
819
+ let params = opts?.params ?? null;
820
+ if (!params) {
821
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
822
+ const derived = MulticallArgs.__tnExtractParams(view, buffer);
823
+ if (!derived) throw new Error("MulticallArgs.__tnCreateView: failed to derive params");
824
+ params = derived.params;
825
+ }
826
+ const instance = new MulticallArgs(new Uint8Array(buffer), params, opts?.fieldContext);
827
+ return instance;
828
+ }
829
+
830
+ dynamicParams(): MulticallArgs.Params {
831
+ return this.__tnParams;
832
+ }
833
+
834
+ withFieldContext(context: Record<string, number | bigint>): this {
835
+ this.__tnFieldContext = context;
836
+ return this;
837
+ }
838
+
839
+ private __tnResolveFieldRef(path: string): number {
840
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
841
+ const getter = (this as any)[getterName];
842
+ if (typeof getter === "function") {
843
+ const value = getter.call(this);
844
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "MulticallArgs::__tnResolveFieldRef") : value;
845
+ }
846
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
847
+ const contextValue = this.__tnFieldContext[path];
848
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "MulticallArgs::__tnResolveFieldRef") : contextValue;
849
+ }
850
+ throw new Error("MulticallArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
851
+ }
852
+
853
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: MulticallArgs.Params; derived: Record<string, bigint> | null } | null {
854
+ if (buffer.length < 2) {
855
+ return null;
856
+ }
857
+ const __tnParam_calls_calls_count = __tnToBigInt(view.getUint16(0, true));
858
+ const __tnExtractedParams = MulticallArgs.Params.fromValues({
859
+ calls_calls_count: __tnParam_calls_calls_count,
860
+ });
861
+ return { params: __tnExtractedParams, derived: null };
862
+ }
863
+
864
+ get_calls_count(): number {
865
+ const offset = 0;
866
+ return this.view.getUint16(offset, true); /* little-endian */
867
+ }
868
+
869
+ set_calls_count(value: number): void {
870
+ const offset = 0;
871
+ this.view.setUint16(offset, value, true); /* little-endian */
872
+ }
873
+
874
+ get calls_count(): number {
875
+ return this.get_calls_count();
876
+ }
877
+
878
+ set calls_count(value: number) {
879
+ this.set_calls_count(value);
880
+ }
881
+
882
+ /** Returns the number of elements in the jagged array. */
883
+ get_calls_length(): number {
884
+ return this.__tnResolveFieldRef("calls_count");
885
+ }
886
+
887
+ /** Returns the element at the given index, or null if out of bounds.
888
+ * Note: This is O(n) as jagged arrays require sequential traversal. */
889
+ get_calls_at(index: number): InstructionData | null {
890
+ const count = this.get_calls_length();
891
+ if (index < 0 || index >= count) {
892
+ return null;
893
+ }
894
+ const offset = 2;
895
+ let cursor = offset;
896
+ for (let i = 0; i < index; i++) {
897
+ const elem = InstructionData.from_array(this.buffer.subarray(cursor));
898
+ if (!elem) {
899
+ throw new Error("MulticallArgs: invalid element at index " + i + " in jagged array 'calls'");
900
+ }
901
+ const validation = InstructionData.validate(this.buffer.subarray(cursor));
902
+ if (!validation.ok || validation.consumed === undefined) {
903
+ throw new Error("MulticallArgs: failed to get footprint for element at index " + i);
904
+ }
905
+ cursor += validation.consumed;
906
+ }
907
+ return InstructionData.from_array(this.buffer.subarray(cursor));
908
+ }
909
+
910
+ /** Returns a generator over the jagged array elements.
911
+ * This is more efficient than repeated calls to `get_calls_at()` for sequential access. */
912
+ *callsIter(): Generator<InstructionData, void, unknown> {
913
+ const count = this.get_calls_length();
914
+ const offset = 2;
915
+ let cursor = offset;
916
+ for (let i = 0; i < count; i++) {
917
+ const elem = InstructionData.from_array(this.buffer.subarray(cursor));
918
+ if (!elem) {
919
+ throw new Error("MulticallArgs: invalid element at index " + i + " in jagged array 'calls'");
920
+ }
921
+ yield elem;
922
+ const validation = InstructionData.validate(this.buffer.subarray(cursor));
923
+ if (!validation.ok || validation.consumed === undefined) {
924
+ throw new Error("MulticallArgs: failed to get footprint for element at index " + i);
925
+ }
926
+ cursor += validation.consumed;
927
+ }
928
+ }
929
+
930
+ get_calls(): InstructionData[] {
931
+ return Array.from(this.callsIter());
932
+ }
933
+
934
+ set_calls(_value: InstructionData[]): void {
935
+ throw new Error("MulticallArgs: jagged array 'calls' cannot be set in-place");
936
+ }
937
+
938
+ /** Returns the total byte size of all elements in the jagged array. */
939
+ get_calls_size(): number {
940
+ const count = this.get_calls_length();
941
+ const offset = 2;
942
+ let cursor = offset;
943
+ for (let i = 0; i < count; i++) {
944
+ const elem = InstructionData.from_array(this.buffer.subarray(cursor));
945
+ if (!elem) {
946
+ throw new Error("MulticallArgs: invalid element at index " + i + " in jagged array 'calls'");
947
+ }
948
+ const validation = InstructionData.validate(this.buffer.subarray(cursor));
949
+ if (!validation.ok || validation.consumed === undefined) {
950
+ throw new Error("MulticallArgs: failed to get footprint for element at index " + i);
951
+ }
952
+ cursor += validation.consumed;
953
+ }
954
+ return cursor - offset;
955
+ }
956
+
957
+ get calls(): InstructionData[] {
958
+ return this.get_calls();
959
+ }
960
+
961
+ set calls(value: InstructionData[]) {
962
+ this.set_calls(value);
963
+ }
964
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
965
+ return __tnEvalFootprint(__tn_ir_MulticallArgs.root, { params: __tnParams });
966
+ }
967
+
968
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
969
+ return __tnValidateIrTree(__tn_ir_MulticallArgs, buffer, __tnParams);
970
+ }
971
+
972
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
973
+ return this.__tnFootprintInternal(__tnParams);
974
+ }
975
+
976
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
977
+ return this.__tnValidateInternal(buffer, __tnParams);
978
+ }
979
+
980
+ static footprintIr(calls_calls_count: number | bigint): bigint {
981
+ const params = MulticallArgs.Params.fromValues({
982
+ calls_calls_count: calls_calls_count,
983
+ });
984
+ return this.footprintIrFromParams(params);
985
+ }
986
+
987
+ private static __tnPackParams(params: MulticallArgs.Params): Record<string, bigint> {
988
+ const record: Record<string, bigint> = Object.create(null);
989
+ record["calls.calls_count"] = params.calls_calls_count;
990
+ return record;
991
+ }
992
+
993
+ static footprintIrFromParams(params: MulticallArgs.Params): bigint {
994
+ const __tnParams = this.__tnPackParams(params);
995
+ return this.__tnFootprintInternal(__tnParams);
996
+ }
997
+
998
+ static footprintFromParams(params: MulticallArgs.Params): number {
999
+ const irResult = this.footprintIrFromParams(params);
1000
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1001
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for MulticallArgs');
1002
+ return __tnBigIntToNumber(irResult, 'MulticallArgs::footprintFromParams');
1003
+ }
1004
+
1005
+ static footprintFromValues(input: { calls_calls_count: number | bigint }): number {
1006
+ const params = MulticallArgs.params(input);
1007
+ return this.footprintFromParams(params);
1008
+ }
1009
+
1010
+ static footprint(params: MulticallArgs.Params): number {
1011
+ return this.footprintFromParams(params);
1012
+ }
1013
+
1014
+ static validate(buffer: Uint8Array, opts?: { params?: MulticallArgs.Params }): { ok: boolean; code?: string; consumed?: number; params?: MulticallArgs.Params } {
1015
+ if (!buffer || buffer.length === undefined) {
1016
+ return { ok: false, code: "tn.invalid_buffer" };
1017
+ }
1018
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1019
+ let params = opts?.params ?? null;
1020
+ if (!params) {
1021
+ const extracted = this.__tnExtractParams(view, buffer);
1022
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1023
+ params = extracted.params;
1024
+ }
1025
+ const __tnParamsRec = this.__tnPackParams(params);
1026
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1027
+ if (!irResult.ok) {
1028
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'MulticallArgs::validate') : undefined, params };
1029
+ }
1030
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'MulticallArgs::validate') : undefined;
1031
+ return { ok: true, consumed, params };
1032
+ }
1033
+
1034
+ static from_array(buffer: Uint8Array, opts?: { params?: MulticallArgs.Params }): MulticallArgs | null {
1035
+ if (!buffer || buffer.length === undefined) {
1036
+ return null;
1037
+ }
1038
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1039
+ let params = opts?.params ?? null;
1040
+ if (!params) {
1041
+ const derived = this.__tnExtractParams(view, buffer);
1042
+ if (!derived) return null;
1043
+ params = derived.params;
1044
+ }
1045
+ const validation = this.validate(buffer, { params });
1046
+ if (!validation.ok) {
1047
+ return null;
1048
+ }
1049
+ const cached = validation.params ?? params;
1050
+ const state = new MulticallArgs(buffer, cached);
1051
+ return state;
1052
+ }
1053
+
1054
+
1055
+ }
1056
+
1057
+ export namespace MulticallArgs {
1058
+ export type Params = {
1059
+ /** ABI path: calls.calls_count */
1060
+ readonly calls_calls_count: bigint;
1061
+ };
1062
+
1063
+ export const ParamKeys = Object.freeze({
1064
+ calls_calls_count: "calls.calls_count",
1065
+ } as const);
1066
+
1067
+ export const Params = {
1068
+ fromValues(input: { calls_calls_count: number | bigint }): Params {
1069
+ return {
1070
+ calls_calls_count: __tnToBigInt(input.calls_calls_count),
1071
+ };
1072
+ },
1073
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
1074
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
1075
+ return (source as { dynamicParams(): Params }).dynamicParams();
1076
+ }
1077
+ if ((source as { params?: Params }).params) {
1078
+ return (source as { params: Params }).params;
1079
+ }
1080
+ return source as Params;
1081
+ }
1082
+ };
1083
+
1084
+ export function params(input: { calls_calls_count: number | bigint }): Params {
1085
+ return Params.fromValues(input);
1086
+ }
1087
+ }
1088
+
1089
+ __tnRegisterFootprint("MulticallArgs", (params) => MulticallArgs.__tnInvokeFootprint(params));
1090
+ __tnRegisterValidate("MulticallArgs", (buffer, params) => MulticallArgs.__tnInvokeValidate(buffer, params));
1091
+ __tnRegisterDynamicValidate("MulticallArgs", (buffer) => { const result = MulticallArgs.validate(buffer); return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed) }; });
1092
+
1093
+ /* ----- TYPE DEFINITION FOR MulticallError ----- */
1094
+
1095
+ const __tn_ir_MulticallError = {
1096
+ typeName: "MulticallError",
1097
+ root: { op: "const", value: 8n }
1098
+ } as const;
1099
+
1100
+ export class MulticallError {
1101
+ private view: DataView;
1102
+
1103
+ private constructor(private buffer: Uint8Array) {
1104
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1105
+ }
1106
+
1107
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): MulticallError {
1108
+ if (!buffer || buffer.length === undefined) throw new Error("MulticallError.__tnCreateView requires a Uint8Array");
1109
+ return new MulticallError(new Uint8Array(buffer));
1110
+ }
1111
+
1112
+ static builder(): MulticallErrorBuilder {
1113
+ return new MulticallErrorBuilder();
1114
+ }
1115
+
1116
+ static fromBuilder(builder: MulticallErrorBuilder): MulticallError | null {
1117
+ const buffer = builder.build();
1118
+ return MulticallError.from_array(buffer);
1119
+ }
1120
+
1121
+ get_code(): bigint {
1122
+ const offset = 0;
1123
+ return this.view.getBigUint64(offset, true); /* little-endian */
1124
+ }
1125
+
1126
+ set_code(value: bigint): void {
1127
+ const offset = 0;
1128
+ this.view.setBigUint64(offset, value, true); /* little-endian */
1129
+ }
1130
+
1131
+ get code(): bigint {
1132
+ return this.get_code();
1133
+ }
1134
+
1135
+ set code(value: bigint) {
1136
+ this.set_code(value);
1137
+ }
1138
+
1139
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1140
+ return __tnEvalFootprint(__tn_ir_MulticallError.root, { params: __tnParams });
1141
+ }
1142
+
1143
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1144
+ return __tnValidateIrTree(__tn_ir_MulticallError, buffer, __tnParams);
1145
+ }
1146
+
1147
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1148
+ return this.__tnFootprintInternal(__tnParams);
1149
+ }
1150
+
1151
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1152
+ return this.__tnValidateInternal(buffer, __tnParams);
1153
+ }
1154
+
1155
+ static footprintIr(): bigint {
1156
+ return this.__tnFootprintInternal(Object.create(null));
1157
+ }
1158
+
1159
+ static footprint(): number {
1160
+ const irResult = this.footprintIr();
1161
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1162
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1163
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for MulticallError');
1164
+ }
1165
+ return __tnBigIntToNumber(irResult, 'MulticallError::footprint');
1166
+ }
1167
+
1168
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1169
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
1170
+ return { ok: true, consumed: 8 };
1171
+ }
1172
+
1173
+ static new(code: bigint): MulticallError {
1174
+ const buffer = new Uint8Array(8);
1175
+ const view = new DataView(buffer.buffer);
1176
+
1177
+ let offset = 0;
1178
+ view.setBigUint64(0, code, true); /* code (little-endian) */
1179
+
1180
+ return new MulticallError(buffer);
1181
+ }
1182
+
1183
+ static from_array(buffer: Uint8Array): MulticallError | null {
1184
+ if (!buffer || buffer.length === undefined) {
1185
+ return null;
1186
+ }
1187
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1188
+ const validation = this.validate(buffer);
1189
+ if (!validation.ok) {
1190
+ return null;
1191
+ }
1192
+ return new MulticallError(buffer);
1193
+ }
1194
+
1195
+ }
1196
+
1197
+ export class MulticallErrorBuilder {
1198
+ private buffer: Uint8Array;
1199
+ private view: DataView;
1200
+
1201
+ constructor() {
1202
+ this.buffer = new Uint8Array(8);
1203
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1204
+ }
1205
+
1206
+ set_code(value: number): this {
1207
+ const cast = __tnToBigInt(value);
1208
+ this.view.setBigUint64(0, cast, true);
1209
+ return this;
1210
+ }
1211
+
1212
+ build(): Uint8Array {
1213
+ return this.buffer.slice();
1214
+ }
1215
+
1216
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1217
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1218
+ target.set(this.buffer, offset);
1219
+ return target;
1220
+ }
1221
+
1222
+ finish(): MulticallError {
1223
+ const view = MulticallError.from_array(this.buffer.slice());
1224
+ if (!view) throw new Error("failed to build MulticallError");
1225
+ return view;
1226
+ }
1227
+ }
1228
+
1229
+ __tnRegisterFootprint("MulticallError", (params) => MulticallError.__tnInvokeFootprint(params));
1230
+ __tnRegisterValidate("MulticallError", (buffer, params) => MulticallError.__tnInvokeValidate(buffer, params));
1231
+ __tnRegisterDynamicValidate("MulticallError", (buffer) => { const result = MulticallError.validate(buffer); return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed) }; });
1232
+