@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,2191 @@
1
+ /* Auto-generated TypeScript code */
2
+ /* WARNING: Do not modify this file directly. It is generated from ABI definitions. */
3
+
4
+ type __TnIrNode =
5
+ | { readonly op: "zero" }
6
+ | { readonly op: "const"; readonly value: bigint }
7
+ | { readonly op: "field"; readonly param: string }
8
+ | {
9
+ readonly op: "add";
10
+ readonly left: __TnIrNode;
11
+ readonly right: __TnIrNode;
12
+ }
13
+ | {
14
+ readonly op: "mul";
15
+ readonly left: __TnIrNode;
16
+ readonly right: __TnIrNode;
17
+ }
18
+ | {
19
+ readonly op: "align";
20
+ readonly alignment: number;
21
+ readonly node: __TnIrNode;
22
+ }
23
+ | {
24
+ readonly op: "switch";
25
+ readonly tag: string;
26
+ readonly cases: readonly { readonly value: number; readonly node: __TnIrNode }[];
27
+ readonly default?: __TnIrNode;
28
+ }
29
+ | {
30
+ readonly op: "call";
31
+ readonly typeName: string;
32
+ readonly args: readonly { readonly name: string; readonly source: string }[];
33
+ };
34
+
35
+ type __TnIrContext = {
36
+ params: Record<string, bigint>;
37
+ buffer?: Uint8Array;
38
+ typeName?: string;
39
+ };
40
+
41
+ type __TnValidateResult = { ok: boolean; code?: string; consumed?: bigint };
42
+ type __TnEvalResult =
43
+ | { ok: true; value: bigint }
44
+ | { ok: false; code: string };
45
+ type __TnBuilderLike = { build(): Uint8Array };
46
+ type __TnStructFieldInput =
47
+ | Uint8Array
48
+ | __TnBuilderLike
49
+ | { buffer?: Uint8Array }
50
+ | { asUint8Array?: () => Uint8Array }
51
+ | { bytes?: () => Uint8Array };
52
+ type __TnVariantDescriptor = {
53
+ readonly name: string;
54
+ readonly tag: number;
55
+ readonly payloadSize: number | null;
56
+ readonly payloadType?: string;
57
+ readonly createPayloadBuilder?: () => unknown | null;
58
+ };
59
+ type __TnVariantSelectorResult<Parent> = {
60
+ select(
61
+ name: string
62
+ ): { writePayload(payload: Uint8Array | __TnBuilderLike): { finish(): Parent } };
63
+ finish(): Parent;
64
+ };
65
+ type __TnFamWriterResult<Parent> = {
66
+ write(payload: Uint8Array | __TnBuilderLike): { finish(): Parent };
67
+ finish(): Parent;
68
+ };
69
+ type __TnConsole = { warn?: (...args: unknown[]) => void };
70
+
71
+ const __tnWarnings = new Set<string>();
72
+ const __tnHasNativeBigInt = typeof BigInt === "function";
73
+ const __tnHasBigIntDataView =
74
+ typeof DataView !== "undefined" &&
75
+ typeof DataView.prototype.getBigInt64 === "function" &&
76
+ typeof DataView.prototype.getBigUint64 === "function" &&
77
+ typeof DataView.prototype.setBigInt64 === "function" &&
78
+ typeof DataView.prototype.setBigUint64 === "function";
79
+ const __tnConsole: __TnConsole | undefined =
80
+ typeof globalThis !== "undefined"
81
+ ? (globalThis as { console?: __TnConsole }).console
82
+ : undefined;
83
+
84
+ function __tnLogWarn(message: string): void {
85
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
86
+ __tnConsole.warn(message);
87
+ }
88
+ }
89
+
90
+ function __tnWarnOnce(message: string): void {
91
+ if (!__tnWarnings.has(message)) {
92
+ __tnWarnings.add(message);
93
+ __tnLogWarn(message);
94
+ }
95
+ }
96
+
97
+ function __tnResolveBuilderInput(
98
+ input: Uint8Array | __TnBuilderLike,
99
+ context: string
100
+ ): Uint8Array {
101
+ if (input instanceof Uint8Array) {
102
+ return new Uint8Array(input);
103
+ }
104
+ if (input && typeof (input as __TnBuilderLike).build === "function") {
105
+ const built = (input as __TnBuilderLike).build();
106
+ if (!(built instanceof Uint8Array)) {
107
+ throw new Error(`${context}: builder did not return Uint8Array`);
108
+ }
109
+ return new Uint8Array(built);
110
+ }
111
+ throw new Error(`${context}: expected Uint8Array or builder`);
112
+ }
113
+
114
+ function __tnResolveStructFieldInput(
115
+ input: __TnStructFieldInput,
116
+ context: string
117
+ ): Uint8Array {
118
+ if (
119
+ input instanceof Uint8Array ||
120
+ (input && typeof (input as __TnBuilderLike).build === "function")
121
+ ) {
122
+ return __tnResolveBuilderInput(input as Uint8Array | __TnBuilderLike, context);
123
+ }
124
+ if (input && typeof (input as { asUint8Array?: () => Uint8Array }).asUint8Array === "function") {
125
+ const bytes = (input as { asUint8Array: () => Uint8Array }).asUint8Array();
126
+ return new Uint8Array(bytes);
127
+ }
128
+ if (input && typeof (input as { bytes?: () => Uint8Array }).bytes === "function") {
129
+ const bytes = (input as { bytes: () => Uint8Array }).bytes();
130
+ return new Uint8Array(bytes);
131
+ }
132
+ if (input && (input as { buffer?: unknown }).buffer instanceof Uint8Array) {
133
+ return new Uint8Array((input as { buffer: Uint8Array }).buffer);
134
+ }
135
+ throw new Error(`${context}: expected Uint8Array, builder, or view-like value`);
136
+ }
137
+
138
+ function __tnMaybeCallBuilder(ctor: unknown): unknown | null {
139
+ if (!ctor) {
140
+ return null;
141
+ }
142
+ const builderFn = (ctor as { builder?: () => unknown }).builder;
143
+ return typeof builderFn === "function" ? builderFn() : null;
144
+ }
145
+
146
+ function __tnCreateVariantSelector<Parent, Descriptor extends __TnVariantDescriptor>(
147
+ parent: Parent,
148
+ descriptors: readonly Descriptor[],
149
+ assign: (descriptor: Descriptor, payload: Uint8Array) => void
150
+ ): __TnVariantSelectorResult<Parent> {
151
+ return {
152
+ select(name: string) {
153
+ const descriptor = descriptors.find((variant) => variant.name === name);
154
+ if (!descriptor) {
155
+ throw new Error(`Unknown variant '${name}'`);
156
+ }
157
+ return {
158
+ writePayload(payload: Uint8Array | __TnBuilderLike) {
159
+ const bytes = __tnResolveBuilderInput(
160
+ payload,
161
+ `variant ${descriptor.name}`
162
+ );
163
+ if (
164
+ descriptor.payloadSize !== null &&
165
+ bytes.length !== descriptor.payloadSize
166
+ ) {
167
+ throw new Error(
168
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
169
+ );
170
+ }
171
+ assign(descriptor, bytes);
172
+ return {
173
+ finish(): Parent {
174
+ return parent;
175
+ },
176
+ };
177
+ },
178
+ };
179
+ },
180
+ finish(): Parent {
181
+ return parent;
182
+ },
183
+ };
184
+ }
185
+
186
+ function __tnCreateFamWriter<Parent>(
187
+ parent: Parent,
188
+ fieldName: string,
189
+ assign: (bytes: Uint8Array) => void
190
+ ): __TnFamWriterResult<Parent> {
191
+ let hasWritten = false;
192
+ return {
193
+ write(payload: Uint8Array | __TnBuilderLike) {
194
+ const bytes = __tnResolveBuilderInput(
195
+ payload,
196
+ `flexible array '${fieldName}'`
197
+ );
198
+ const copy = new Uint8Array(bytes);
199
+ assign(copy);
200
+ hasWritten = true;
201
+ return {
202
+ finish(): Parent {
203
+ return parent;
204
+ },
205
+ };
206
+ },
207
+ finish(): Parent {
208
+ if (!hasWritten) {
209
+ throw new Error(
210
+ `flexible array '${fieldName}' requires write() before finish()`
211
+ );
212
+ }
213
+ return parent;
214
+ },
215
+ };
216
+ }
217
+
218
+ const __tnMask32 = __tnHasNativeBigInt
219
+ ? (BigInt(1) << BigInt(32)) - BigInt(1)
220
+ : 0xffffffff;
221
+ const __tnSignBit32 = __tnHasNativeBigInt
222
+ ? BigInt(1) << BigInt(31)
223
+ : 0x80000000;
224
+
225
+ function __tnToBigInt(value: number | bigint): bigint {
226
+ if (__tnHasNativeBigInt) {
227
+ return typeof value === "bigint" ? value : BigInt(value);
228
+ }
229
+ if (typeof value === "bigint") return value;
230
+ if (!Number.isFinite(value)) {
231
+ throw new Error("IR runtime received non-finite numeric input");
232
+ }
233
+ if (!Number.isSafeInteger(value)) {
234
+ __tnWarnOnce(
235
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
236
+ );
237
+ }
238
+ return (value as unknown) as bigint;
239
+ }
240
+
241
+ function __tnBigIntToNumber(value: bigint, context: string): number {
242
+ if (__tnHasNativeBigInt) {
243
+ const converted = Number(value);
244
+ if (!Number.isFinite(converted)) {
245
+ throw new Error(`${context} overflowed Number range`);
246
+ }
247
+ return converted;
248
+ }
249
+ return value as unknown as number;
250
+ }
251
+
252
+ function __tnBigIntEquals(lhs: bigint, rhs: bigint): boolean {
253
+ if (__tnHasNativeBigInt) return lhs === rhs;
254
+ return (lhs as unknown as number) === (rhs as unknown as number);
255
+ }
256
+
257
+ function __tnBigIntGreaterThan(lhs: bigint, rhs: bigint): boolean {
258
+ if (__tnHasNativeBigInt) return lhs > rhs;
259
+ return (lhs as unknown as number) > (rhs as unknown as number);
260
+ }
261
+
262
+ function __tnPopcount(value: number | bigint): number {
263
+ let v =
264
+ typeof value === "bigint"
265
+ ? Number(value & BigInt(0xffffffff))
266
+ : Number(value) >>> 0;
267
+ v = v - ((v >>> 1) & 0x55555555);
268
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
269
+ return (((v + (v >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
270
+ }
271
+
272
+ function __tnRaiseIrError(code: string, message: string): never {
273
+ const err = new Error(message);
274
+ (err as { code?: string }).code = code;
275
+ throw err;
276
+ }
277
+
278
+ function __tnCheckedAdd(lhs: bigint, rhs: bigint): bigint {
279
+ if (__tnHasNativeBigInt) {
280
+ const result = (lhs as bigint) + (rhs as bigint);
281
+ if (result < BigInt(0)) {
282
+ __tnRaiseIrError(
283
+ "tn.ir.overflow",
284
+ "IR runtime detected negative size via addition"
285
+ );
286
+ }
287
+ return result;
288
+ }
289
+ const left = lhs as unknown as number;
290
+ const right = rhs as unknown as number;
291
+ const sum = left + right;
292
+ if (sum < 0 || !Number.isFinite(sum)) {
293
+ __tnRaiseIrError(
294
+ "tn.ir.overflow",
295
+ "IR runtime detected invalid addition result"
296
+ );
297
+ }
298
+ if (!Number.isSafeInteger(sum)) {
299
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
300
+ }
301
+ return (sum as unknown) as bigint;
302
+ }
303
+
304
+ function __tnCheckedMul(lhs: bigint, rhs: bigint): bigint {
305
+ if (__tnHasNativeBigInt) {
306
+ const result = (lhs as bigint) * (rhs as bigint);
307
+ if (result < BigInt(0)) {
308
+ __tnRaiseIrError(
309
+ "tn.ir.overflow",
310
+ "IR runtime detected negative size via multiplication"
311
+ );
312
+ }
313
+ return result;
314
+ }
315
+ const left = lhs as unknown as number;
316
+ const right = rhs as unknown as number;
317
+ const product = left * right;
318
+ if (product < 0 || !Number.isFinite(product)) {
319
+ __tnRaiseIrError(
320
+ "tn.ir.overflow",
321
+ "IR runtime detected invalid multiplication result"
322
+ );
323
+ }
324
+ if (!Number.isSafeInteger(product)) {
325
+ __tnWarnOnce(
326
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
327
+ );
328
+ }
329
+ return (product as unknown) as bigint;
330
+ }
331
+
332
+ function __tnAlign(value: bigint, alignment: number): bigint {
333
+ if (alignment <= 1) return value;
334
+ const alignBig = __tnToBigInt(alignment);
335
+ if (__tnHasNativeBigInt) {
336
+ const remainder = value % alignBig;
337
+ if (__tnBigIntEquals(remainder, __tnToBigInt(0))) {
338
+ return value;
339
+ }
340
+ const delta = alignBig - remainder;
341
+ return __tnCheckedAdd(value, delta);
342
+ }
343
+ const current = __tnBigIntToNumber(value, "IR align");
344
+ const alignNum = alignment >>> 0;
345
+ const remainder = current % alignNum;
346
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
347
+ return __tnToBigInt(next);
348
+ }
349
+
350
+ function __tnSplitUint64(value: bigint): { high: number; low: number } {
351
+ if (__tnHasNativeBigInt) {
352
+ const low = Number(value & (__tnMask32 as bigint));
353
+ const high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
354
+ return { high, low };
355
+ }
356
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
357
+ const low = num >>> 0;
358
+ const high = Math.floor(num / 4294967296) >>> 0;
359
+ return { high, low };
360
+ }
361
+
362
+ function __tnSplitInt64(value: bigint): { high: number; low: number } {
363
+ if (__tnHasNativeBigInt) {
364
+ const low = Number(value & (__tnMask32 as bigint));
365
+ let high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
366
+ if ((BigInt(high) & (__tnSignBit32 as bigint)) !== BigInt(0)) {
367
+ high -= 0x100000000;
368
+ }
369
+ return { high, low };
370
+ }
371
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
372
+ const low = num >>> 0;
373
+ const high = Math.floor(num / 4294967296);
374
+ return { high, low };
375
+ }
376
+
377
+ function __tnPolyfillReadUint64(
378
+ view: DataView,
379
+ offset: number,
380
+ littleEndian: boolean
381
+ ): bigint {
382
+ const low = littleEndian
383
+ ? view.getUint32(offset, true)
384
+ : view.getUint32(offset + 4, false);
385
+ const high = littleEndian
386
+ ? view.getUint32(offset + 4, true)
387
+ : view.getUint32(offset, false);
388
+ if (__tnHasNativeBigInt) {
389
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
390
+ }
391
+ const value = high * 4294967296 + low;
392
+ if (!Number.isSafeInteger(value)) {
393
+ __tnWarnOnce(
394
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
395
+ );
396
+ }
397
+ return (value as unknown) as bigint;
398
+ }
399
+
400
+ function __tnPolyfillReadInt64(
401
+ view: DataView,
402
+ offset: number,
403
+ littleEndian: boolean
404
+ ): bigint {
405
+ const low = littleEndian
406
+ ? view.getUint32(offset, true)
407
+ : view.getUint32(offset + 4, false);
408
+ const high = littleEndian
409
+ ? view.getInt32(offset + 4, true)
410
+ : view.getInt32(offset, false);
411
+ if (__tnHasNativeBigInt) {
412
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
413
+ }
414
+ const value = high * 4294967296 + low;
415
+ if (!Number.isSafeInteger(value)) {
416
+ __tnWarnOnce(
417
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
418
+ );
419
+ }
420
+ return (value as unknown) as bigint;
421
+ }
422
+
423
+ function __tnPolyfillWriteUint64(
424
+ view: DataView,
425
+ offset: number,
426
+ value: bigint,
427
+ littleEndian: boolean
428
+ ): void {
429
+ const parts = __tnSplitUint64(value);
430
+ if (littleEndian) {
431
+ view.setUint32(offset, parts.low, true);
432
+ view.setUint32(offset + 4, parts.high, true);
433
+ } else {
434
+ view.setUint32(offset, parts.high, false);
435
+ view.setUint32(offset + 4, parts.low, false);
436
+ }
437
+ }
438
+
439
+ function __tnPolyfillWriteInt64(
440
+ view: DataView,
441
+ offset: number,
442
+ value: bigint,
443
+ littleEndian: boolean
444
+ ): void {
445
+ const parts = __tnSplitInt64(value);
446
+ if (littleEndian) {
447
+ view.setUint32(offset, parts.low >>> 0, true);
448
+ view.setInt32(offset + 4, parts.high | 0, true);
449
+ } else {
450
+ view.setInt32(offset, parts.high | 0, false);
451
+ view.setUint32(offset + 4, parts.low >>> 0, false);
452
+ }
453
+ }
454
+
455
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
456
+ const proto = DataView.prototype as unknown as Record<string, unknown>;
457
+ if (typeof proto.getBigUint64 !== "function") {
458
+ (proto as any).getBigUint64 = function (
459
+ offset: number,
460
+ littleEndian?: boolean
461
+ ): bigint {
462
+ __tnWarnOnce(
463
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
464
+ );
465
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
466
+ };
467
+ }
468
+ if (typeof proto.getBigInt64 !== "function") {
469
+ (proto as any).getBigInt64 = function (
470
+ offset: number,
471
+ littleEndian?: boolean
472
+ ): bigint {
473
+ __tnWarnOnce(
474
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
475
+ );
476
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
477
+ };
478
+ }
479
+ if (typeof proto.setBigUint64 !== "function") {
480
+ (proto as any).setBigUint64 = function (
481
+ offset: number,
482
+ value: bigint,
483
+ littleEndian?: boolean
484
+ ): void {
485
+ __tnWarnOnce(
486
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
487
+ );
488
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
489
+ };
490
+ }
491
+ if (typeof proto.setBigInt64 !== "function") {
492
+ (proto as any).setBigInt64 = function (
493
+ offset: number,
494
+ value: bigint,
495
+ littleEndian?: boolean
496
+ ): void {
497
+ __tnWarnOnce(
498
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
499
+ );
500
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
501
+ };
502
+ }
503
+ if (!__tnHasNativeBigInt) {
504
+ __tnWarnOnce(
505
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
506
+ );
507
+ }
508
+ }
509
+
510
+ const __tnFootprintRegistry: Record<
511
+ string,
512
+ (params: Record<string, bigint>) => bigint
513
+ > = {};
514
+ const __tnValidateRegistry: Record<
515
+ string,
516
+ (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
517
+ > = {};
518
+
519
+ function __tnRegisterFootprint(
520
+ typeName: string,
521
+ fn: (params: Record<string, bigint>) => bigint
522
+ ): void {
523
+ __tnFootprintRegistry[typeName] = fn;
524
+ }
525
+
526
+ function __tnRegisterValidate(
527
+ typeName: string,
528
+ fn: (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
529
+ ): void {
530
+ __tnValidateRegistry[typeName] = fn;
531
+ }
532
+
533
+ function __tnInvokeFootprint(
534
+ typeName: string,
535
+ params: Record<string, bigint>
536
+ ): bigint {
537
+ const fn = __tnFootprintRegistry[typeName];
538
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
539
+ return fn(params);
540
+ }
541
+
542
+ function __tnInvokeValidate(
543
+ typeName: string,
544
+ buffer: Uint8Array,
545
+ params: Record<string, bigint>
546
+ ): __TnValidateResult {
547
+ const fn = __tnValidateRegistry[typeName];
548
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
549
+ return fn(buffer, params);
550
+ }
551
+
552
+ function __tnEvalFootprint(node: __TnIrNode, ctx: __TnIrContext): bigint {
553
+ return __tnEvalIrNode(node, ctx);
554
+ }
555
+
556
+ function __tnTryEvalFootprint(
557
+ node: __TnIrNode,
558
+ ctx: __TnIrContext
559
+ ): __TnEvalResult {
560
+ return __tnTryEvalIr(node, ctx);
561
+ }
562
+
563
+ function __tnTryEvalIr(
564
+ node: __TnIrNode,
565
+ ctx: __TnIrContext
566
+ ): __TnEvalResult {
567
+ try {
568
+ return { ok: true, value: __tnEvalIrNode(node, ctx) };
569
+ } catch (err) {
570
+ return { ok: false, code: __tnNormalizeIrError(err) };
571
+ }
572
+ }
573
+
574
+ function __tnIsEvalError(result: __TnEvalResult): result is { ok: false; code: string } {
575
+ return result.ok === false;
576
+ }
577
+
578
+ function __tnValidateIrTree(
579
+ ir: { readonly typeName: string; readonly root: __TnIrNode },
580
+ buffer: Uint8Array,
581
+ params: Record<string, bigint>
582
+ ): __TnValidateResult {
583
+ const evalResult = __tnTryEvalIr(ir.root, {
584
+ params,
585
+ buffer,
586
+ typeName: ir.typeName,
587
+ });
588
+ if (__tnIsEvalError(evalResult)) {
589
+ return { ok: false, code: evalResult.code };
590
+ }
591
+ const required = evalResult.value;
592
+ const available = __tnToBigInt(buffer.length);
593
+ if (__tnBigIntGreaterThan(required, available)) {
594
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
595
+ }
596
+ return { ok: true, consumed: required };
597
+ }
598
+
599
+ function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
600
+ switch (node.op) {
601
+ case "zero":
602
+ return __tnToBigInt(0);
603
+ case "const":
604
+ return node.value;
605
+ case "field": {
606
+ const val = ctx.params[node.param];
607
+ if (val === undefined) {
608
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
609
+ __tnRaiseIrError(
610
+ "tn.ir.missing_param",
611
+ `${prefix}Missing IR parameter '${node.param}'`
612
+ );
613
+ }
614
+ return val;
615
+ }
616
+ case "add":
617
+ return __tnCheckedAdd(
618
+ __tnEvalIrNode(node.left, ctx),
619
+ __tnEvalIrNode(node.right, ctx)
620
+ );
621
+ case "mul":
622
+ return __tnCheckedMul(
623
+ __tnEvalIrNode(node.left, ctx),
624
+ __tnEvalIrNode(node.right, ctx)
625
+ );
626
+ case "align":
627
+ return __tnAlign(__tnEvalIrNode(node.node, ctx), node.alignment);
628
+ case "switch": {
629
+ const tagVal = ctx.params[node.tag];
630
+ if (tagVal === undefined) {
631
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
632
+ __tnRaiseIrError(
633
+ "tn.ir.missing_param",
634
+ `${prefix}Missing IR switch tag '${node.tag}'`
635
+ );
636
+ }
637
+ const tagNumber = Number(tagVal);
638
+ for (const caseNode of node.cases) {
639
+ if (caseNode.value === tagNumber) {
640
+ return __tnEvalIrNode(caseNode.node, ctx);
641
+ }
642
+ }
643
+ if (node.default) return __tnEvalIrNode(node.default, ctx);
644
+ __tnRaiseIrError(
645
+ "tn.ir.invalid_tag",
646
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
647
+ );
648
+ }
649
+ case "call": {
650
+ const nestedParams: Record<string, bigint> = Object.create(null);
651
+ for (const arg of node.args) {
652
+ const val = ctx.params[arg.source];
653
+ if (val === undefined) {
654
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
655
+ __tnRaiseIrError(
656
+ "tn.ir.missing_param",
657
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
658
+ );
659
+ }
660
+ nestedParams[arg.name] = val;
661
+ }
662
+ if (ctx.buffer) {
663
+ const nestedResult = __tnInvokeValidate(
664
+ node.typeName,
665
+ ctx.buffer,
666
+ nestedParams
667
+ );
668
+ if (!nestedResult.ok) {
669
+ const nestedCode =
670
+ nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
671
+ const prefixed = nestedCode.startsWith("tn.")
672
+ ? nestedCode
673
+ : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
674
+ __tnRaiseIrError(
675
+ prefixed,
676
+ `Nested validator ${node.typeName} failed`
677
+ );
678
+ }
679
+ if (nestedResult.consumed !== undefined) {
680
+ return nestedResult.consumed;
681
+ }
682
+ }
683
+ return __tnInvokeFootprint(node.typeName, nestedParams);
684
+ }
685
+ default:
686
+ __tnRaiseIrError(
687
+ "tn.ir.runtime_error",
688
+ `Unsupported IR node ${(node as { op: string }).op}`
689
+ );
690
+ }
691
+ }
692
+
693
+ function __tnNormalizeIrError(err: unknown): string {
694
+ if (err && typeof err === "object" && "code" in err) {
695
+ const maybeCode = (err as { code?: string }).code;
696
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
697
+ return maybeCode;
698
+ }
699
+ }
700
+ const message =
701
+ err && typeof err === "object" && "message" in err
702
+ ? String((err as { message?: unknown }).message ?? "")
703
+ : typeof err === "string"
704
+ ? err
705
+ : "";
706
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
707
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
708
+ if (
709
+ message.includes("invalid") ||
710
+ message.includes("overflow") ||
711
+ message.includes("negative size")
712
+ ) {
713
+ return "tn.ir.overflow";
714
+ }
715
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
716
+ return "tn.ir.runtime_error";
717
+ }
718
+
719
+ /* ----- TYPE DEFINITION FOR Date ----- */
720
+
721
+ const __tn_ir_Date = {
722
+ typeName: "Date",
723
+ root: { op: "const", value: 6n }
724
+ } as const;
725
+
726
+ export class Date {
727
+ private view: DataView;
728
+
729
+ private constructor(private buffer: Uint8Array) {
730
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
731
+ }
732
+
733
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Date {
734
+ if (!buffer || buffer.length === undefined) throw new Error("Date.__tnCreateView requires a Uint8Array");
735
+ return new Date(new Uint8Array(buffer));
736
+ }
737
+
738
+ static builder(): DateBuilder {
739
+ return new DateBuilder();
740
+ }
741
+
742
+ static fromBuilder(builder: DateBuilder): Date | null {
743
+ const buffer = builder.build();
744
+ return Date.from_array(buffer);
745
+ }
746
+
747
+ get_year(): number {
748
+ const offset = 0;
749
+ return this.view.getInt32(offset, true); /* little-endian */
750
+ }
751
+
752
+ set_year(value: number): void {
753
+ const offset = 0;
754
+ this.view.setInt32(offset, value, true); /* little-endian */
755
+ }
756
+
757
+ get year(): number {
758
+ return this.get_year();
759
+ }
760
+
761
+ set year(value: number) {
762
+ this.set_year(value);
763
+ }
764
+
765
+ get_month(): number {
766
+ const offset = 4;
767
+ return this.view.getUint8(offset);
768
+ }
769
+
770
+ set_month(value: number): void {
771
+ const offset = 4;
772
+ this.view.setUint8(offset, value);
773
+ }
774
+
775
+ get month(): number {
776
+ return this.get_month();
777
+ }
778
+
779
+ set month(value: number) {
780
+ this.set_month(value);
781
+ }
782
+
783
+ get_day(): number {
784
+ const offset = 5;
785
+ return this.view.getUint8(offset);
786
+ }
787
+
788
+ set_day(value: number): void {
789
+ const offset = 5;
790
+ this.view.setUint8(offset, value);
791
+ }
792
+
793
+ get day(): number {
794
+ return this.get_day();
795
+ }
796
+
797
+ set day(value: number) {
798
+ this.set_day(value);
799
+ }
800
+
801
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
802
+ return __tnEvalFootprint(__tn_ir_Date.root, { params: __tnParams });
803
+ }
804
+
805
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
806
+ return __tnValidateIrTree(__tn_ir_Date, buffer, __tnParams);
807
+ }
808
+
809
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
810
+ return this.__tnFootprintInternal(__tnParams);
811
+ }
812
+
813
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
814
+ return this.__tnValidateInternal(buffer, __tnParams);
815
+ }
816
+
817
+ static footprintIr(): bigint {
818
+ return this.__tnFootprintInternal(Object.create(null));
819
+ }
820
+
821
+ static footprint(): number {
822
+ const irResult = this.footprintIr();
823
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
824
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
825
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Date');
826
+ }
827
+ return __tnBigIntToNumber(irResult, 'Date::footprint');
828
+ }
829
+
830
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
831
+ if (buffer.length < 6) return { ok: false, code: "tn.buffer_too_small", consumed: 6 };
832
+ return { ok: true, consumed: 6 };
833
+ }
834
+
835
+ static new(year: number, month: number, day: number): Date {
836
+ const buffer = new Uint8Array(6);
837
+ const view = new DataView(buffer.buffer);
838
+
839
+ let offset = 0;
840
+ view.setInt32(0, year, true); /* year (little-endian) */
841
+ view.setUint8(4, month); /* month */
842
+ view.setUint8(5, day); /* day */
843
+
844
+ return new Date(buffer);
845
+ }
846
+
847
+ static from_array(buffer: Uint8Array): Date | null {
848
+ if (!buffer || buffer.length === undefined) {
849
+ return null;
850
+ }
851
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
852
+ const validation = this.validate(buffer);
853
+ if (!validation.ok) {
854
+ return null;
855
+ }
856
+ return new Date(buffer);
857
+ }
858
+
859
+ }
860
+
861
+ __tnRegisterFootprint("Date", (params) => Date.__tnInvokeFootprint(params));
862
+ __tnRegisterValidate("Date", (buffer, params) => Date.__tnInvokeValidate(buffer, params));
863
+
864
+ export class DateBuilder {
865
+ private buffer: Uint8Array;
866
+ private view: DataView;
867
+
868
+ constructor() {
869
+ this.buffer = new Uint8Array(6);
870
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
871
+ }
872
+
873
+ set_year(value: number): this {
874
+ this.view.setInt32(0, value, true);
875
+ return this;
876
+ }
877
+
878
+ set_month(value: number): this {
879
+ this.view.setUint8(4, value);
880
+ return this;
881
+ }
882
+
883
+ set_day(value: number): this {
884
+ this.view.setUint8(5, value);
885
+ return this;
886
+ }
887
+
888
+ build(): Uint8Array {
889
+ return this.buffer.slice();
890
+ }
891
+
892
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
893
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
894
+ target.set(this.buffer, offset);
895
+ return target;
896
+ }
897
+
898
+ finish(): Date {
899
+ const view = Date.from_array(this.buffer.slice());
900
+ if (!view) throw new Error("failed to build Date");
901
+ return view;
902
+ }
903
+ }
904
+
905
+ /* ----- TYPE DEFINITION FOR Duration ----- */
906
+
907
+ const __tn_ir_Duration = {
908
+ typeName: "Duration",
909
+ root: { op: "const", value: 12n }
910
+ } as const;
911
+
912
+ export class Duration {
913
+ private view: DataView;
914
+
915
+ private constructor(private buffer: Uint8Array) {
916
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
917
+ }
918
+
919
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Duration {
920
+ if (!buffer || buffer.length === undefined) throw new Error("Duration.__tnCreateView requires a Uint8Array");
921
+ return new Duration(new Uint8Array(buffer));
922
+ }
923
+
924
+ static builder(): DurationBuilder {
925
+ return new DurationBuilder();
926
+ }
927
+
928
+ static fromBuilder(builder: DurationBuilder): Duration | null {
929
+ const buffer = builder.build();
930
+ return Duration.from_array(buffer);
931
+ }
932
+
933
+ get_seconds(): bigint {
934
+ const offset = 0;
935
+ return this.view.getBigInt64(offset, true); /* little-endian */
936
+ }
937
+
938
+ set_seconds(value: bigint): void {
939
+ const offset = 0;
940
+ this.view.setBigInt64(offset, value, true); /* little-endian */
941
+ }
942
+
943
+ get seconds(): bigint {
944
+ return this.get_seconds();
945
+ }
946
+
947
+ set seconds(value: bigint) {
948
+ this.set_seconds(value);
949
+ }
950
+
951
+ get_nanos(): number {
952
+ const offset = 8;
953
+ return this.view.getInt32(offset, true); /* little-endian */
954
+ }
955
+
956
+ set_nanos(value: number): void {
957
+ const offset = 8;
958
+ this.view.setInt32(offset, value, true); /* little-endian */
959
+ }
960
+
961
+ get nanos(): number {
962
+ return this.get_nanos();
963
+ }
964
+
965
+ set nanos(value: number) {
966
+ this.set_nanos(value);
967
+ }
968
+
969
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
970
+ return __tnEvalFootprint(__tn_ir_Duration.root, { params: __tnParams });
971
+ }
972
+
973
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
974
+ return __tnValidateIrTree(__tn_ir_Duration, buffer, __tnParams);
975
+ }
976
+
977
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
978
+ return this.__tnFootprintInternal(__tnParams);
979
+ }
980
+
981
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
982
+ return this.__tnValidateInternal(buffer, __tnParams);
983
+ }
984
+
985
+ static footprintIr(): bigint {
986
+ return this.__tnFootprintInternal(Object.create(null));
987
+ }
988
+
989
+ static footprint(): number {
990
+ const irResult = this.footprintIr();
991
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
992
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
993
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Duration');
994
+ }
995
+ return __tnBigIntToNumber(irResult, 'Duration::footprint');
996
+ }
997
+
998
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
999
+ if (buffer.length < 12) return { ok: false, code: "tn.buffer_too_small", consumed: 12 };
1000
+ return { ok: true, consumed: 12 };
1001
+ }
1002
+
1003
+ static new(seconds: bigint, nanos: number): Duration {
1004
+ const buffer = new Uint8Array(12);
1005
+ const view = new DataView(buffer.buffer);
1006
+
1007
+ let offset = 0;
1008
+ view.setBigInt64(0, seconds, true); /* seconds (little-endian) */
1009
+ view.setInt32(8, nanos, true); /* nanos (little-endian) */
1010
+
1011
+ return new Duration(buffer);
1012
+ }
1013
+
1014
+ static from_array(buffer: Uint8Array): Duration | null {
1015
+ if (!buffer || buffer.length === undefined) {
1016
+ return null;
1017
+ }
1018
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1019
+ const validation = this.validate(buffer);
1020
+ if (!validation.ok) {
1021
+ return null;
1022
+ }
1023
+ return new Duration(buffer);
1024
+ }
1025
+
1026
+ }
1027
+
1028
+ __tnRegisterFootprint("Duration", (params) => Duration.__tnInvokeFootprint(params));
1029
+ __tnRegisterValidate("Duration", (buffer, params) => Duration.__tnInvokeValidate(buffer, params));
1030
+
1031
+ export class DurationBuilder {
1032
+ private buffer: Uint8Array;
1033
+ private view: DataView;
1034
+
1035
+ constructor() {
1036
+ this.buffer = new Uint8Array(12);
1037
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1038
+ }
1039
+
1040
+ set_seconds(value: number): this {
1041
+ const cast = __tnToBigInt(value);
1042
+ this.view.setBigInt64(0, cast, true);
1043
+ return this;
1044
+ }
1045
+
1046
+ set_nanos(value: number): this {
1047
+ this.view.setInt32(8, value, true);
1048
+ return this;
1049
+ }
1050
+
1051
+ build(): Uint8Array {
1052
+ return this.buffer.slice();
1053
+ }
1054
+
1055
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1056
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1057
+ target.set(this.buffer, offset);
1058
+ return target;
1059
+ }
1060
+
1061
+ finish(): Duration {
1062
+ const view = Duration.from_array(this.buffer.slice());
1063
+ if (!view) throw new Error("failed to build Duration");
1064
+ return view;
1065
+ }
1066
+ }
1067
+
1068
+ /* ----- TYPE DEFINITION FOR FixedPoint ----- */
1069
+
1070
+ const __tn_ir_FixedPoint = {
1071
+ typeName: "FixedPoint",
1072
+ root: { op: "const", value: 9n }
1073
+ } as const;
1074
+
1075
+ export class FixedPoint {
1076
+ private view: DataView;
1077
+
1078
+ private constructor(private buffer: Uint8Array) {
1079
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1080
+ }
1081
+
1082
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): FixedPoint {
1083
+ if (!buffer || buffer.length === undefined) throw new Error("FixedPoint.__tnCreateView requires a Uint8Array");
1084
+ return new FixedPoint(new Uint8Array(buffer));
1085
+ }
1086
+
1087
+ static builder(): FixedPointBuilder {
1088
+ return new FixedPointBuilder();
1089
+ }
1090
+
1091
+ static fromBuilder(builder: FixedPointBuilder): FixedPoint | null {
1092
+ const buffer = builder.build();
1093
+ return FixedPoint.from_array(buffer);
1094
+ }
1095
+
1096
+ get_mantissa(): bigint {
1097
+ const offset = 0;
1098
+ return this.view.getBigInt64(offset, true); /* little-endian */
1099
+ }
1100
+
1101
+ set_mantissa(value: bigint): void {
1102
+ const offset = 0;
1103
+ this.view.setBigInt64(offset, value, true); /* little-endian */
1104
+ }
1105
+
1106
+ get mantissa(): bigint {
1107
+ return this.get_mantissa();
1108
+ }
1109
+
1110
+ set mantissa(value: bigint) {
1111
+ this.set_mantissa(value);
1112
+ }
1113
+
1114
+ get_scale(): number {
1115
+ const offset = 8;
1116
+ return this.view.getUint8(offset);
1117
+ }
1118
+
1119
+ set_scale(value: number): void {
1120
+ const offset = 8;
1121
+ this.view.setUint8(offset, value);
1122
+ }
1123
+
1124
+ get scale(): number {
1125
+ return this.get_scale();
1126
+ }
1127
+
1128
+ set scale(value: number) {
1129
+ this.set_scale(value);
1130
+ }
1131
+
1132
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1133
+ return __tnEvalFootprint(__tn_ir_FixedPoint.root, { params: __tnParams });
1134
+ }
1135
+
1136
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1137
+ return __tnValidateIrTree(__tn_ir_FixedPoint, buffer, __tnParams);
1138
+ }
1139
+
1140
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1141
+ return this.__tnFootprintInternal(__tnParams);
1142
+ }
1143
+
1144
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1145
+ return this.__tnValidateInternal(buffer, __tnParams);
1146
+ }
1147
+
1148
+ static footprintIr(): bigint {
1149
+ return this.__tnFootprintInternal(Object.create(null));
1150
+ }
1151
+
1152
+ static footprint(): number {
1153
+ const irResult = this.footprintIr();
1154
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1155
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1156
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for FixedPoint');
1157
+ }
1158
+ return __tnBigIntToNumber(irResult, 'FixedPoint::footprint');
1159
+ }
1160
+
1161
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1162
+ if (buffer.length < 9) return { ok: false, code: "tn.buffer_too_small", consumed: 9 };
1163
+ return { ok: true, consumed: 9 };
1164
+ }
1165
+
1166
+ static new(mantissa: bigint, scale: number): FixedPoint {
1167
+ const buffer = new Uint8Array(9);
1168
+ const view = new DataView(buffer.buffer);
1169
+
1170
+ let offset = 0;
1171
+ view.setBigInt64(0, mantissa, true); /* mantissa (little-endian) */
1172
+ view.setUint8(8, scale); /* scale */
1173
+
1174
+ return new FixedPoint(buffer);
1175
+ }
1176
+
1177
+ static from_array(buffer: Uint8Array): FixedPoint | null {
1178
+ if (!buffer || buffer.length === undefined) {
1179
+ return null;
1180
+ }
1181
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1182
+ const validation = this.validate(buffer);
1183
+ if (!validation.ok) {
1184
+ return null;
1185
+ }
1186
+ return new FixedPoint(buffer);
1187
+ }
1188
+
1189
+ }
1190
+
1191
+ __tnRegisterFootprint("FixedPoint", (params) => FixedPoint.__tnInvokeFootprint(params));
1192
+ __tnRegisterValidate("FixedPoint", (buffer, params) => FixedPoint.__tnInvokeValidate(buffer, params));
1193
+
1194
+ export class FixedPointBuilder {
1195
+ private buffer: Uint8Array;
1196
+ private view: DataView;
1197
+
1198
+ constructor() {
1199
+ this.buffer = new Uint8Array(9);
1200
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1201
+ }
1202
+
1203
+ set_mantissa(value: number): this {
1204
+ const cast = __tnToBigInt(value);
1205
+ this.view.setBigInt64(0, cast, true);
1206
+ return this;
1207
+ }
1208
+
1209
+ set_scale(value: number): this {
1210
+ this.view.setUint8(8, value);
1211
+ return this;
1212
+ }
1213
+
1214
+ build(): Uint8Array {
1215
+ return this.buffer.slice();
1216
+ }
1217
+
1218
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1219
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1220
+ target.set(this.buffer, offset);
1221
+ return target;
1222
+ }
1223
+
1224
+ finish(): FixedPoint {
1225
+ const view = FixedPoint.from_array(this.buffer.slice());
1226
+ if (!view) throw new Error("failed to build FixedPoint");
1227
+ return view;
1228
+ }
1229
+ }
1230
+
1231
+ /* ----- TYPE DEFINITION FOR Hash ----- */
1232
+
1233
+ const __tn_ir_Hash = {
1234
+ typeName: "Hash",
1235
+ root: { op: "const", value: 32n }
1236
+ } as const;
1237
+
1238
+ export class Hash {
1239
+ private view: DataView;
1240
+
1241
+ private constructor(private buffer: Uint8Array) {
1242
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1243
+ }
1244
+
1245
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Hash {
1246
+ if (!buffer || buffer.length === undefined) throw new Error("Hash.__tnCreateView requires a Uint8Array");
1247
+ return new Hash(new Uint8Array(buffer));
1248
+ }
1249
+
1250
+ static builder(): HashBuilder {
1251
+ return new HashBuilder();
1252
+ }
1253
+
1254
+ static fromBuilder(builder: HashBuilder): Hash | null {
1255
+ const buffer = builder.build();
1256
+ return Hash.from_array(buffer);
1257
+ }
1258
+
1259
+ get_bytes(): number[] {
1260
+ const offset = 0;
1261
+ const result: number[] = [];
1262
+ for (let i = 0; i < 32; i++) {
1263
+ result.push(this.view.getUint8((offset + i * 1)));
1264
+ }
1265
+ return result;
1266
+ }
1267
+
1268
+ set_bytes(value: number[]): void {
1269
+ const offset = 0;
1270
+ if (value.length !== 32) {
1271
+ throw new Error('Array length must be 32');
1272
+ }
1273
+ for (let i = 0; i < 32; i++) {
1274
+ this.view.setUint8((offset + i * 1), value[i]);
1275
+ }
1276
+ }
1277
+
1278
+ get bytes(): number[] {
1279
+ return this.get_bytes();
1280
+ }
1281
+
1282
+ set bytes(value: number[]) {
1283
+ this.set_bytes(value);
1284
+ }
1285
+
1286
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1287
+ return __tnEvalFootprint(__tn_ir_Hash.root, { params: __tnParams });
1288
+ }
1289
+
1290
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1291
+ return __tnValidateIrTree(__tn_ir_Hash, buffer, __tnParams);
1292
+ }
1293
+
1294
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1295
+ return this.__tnFootprintInternal(__tnParams);
1296
+ }
1297
+
1298
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1299
+ return this.__tnValidateInternal(buffer, __tnParams);
1300
+ }
1301
+
1302
+ static footprintIr(): bigint {
1303
+ return this.__tnFootprintInternal(Object.create(null));
1304
+ }
1305
+
1306
+ static footprint(): number {
1307
+ const irResult = this.footprintIr();
1308
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1309
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1310
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Hash');
1311
+ }
1312
+ return __tnBigIntToNumber(irResult, 'Hash::footprint');
1313
+ }
1314
+
1315
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1316
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1317
+ return { ok: true, consumed: 32 };
1318
+ }
1319
+
1320
+ static from_array(buffer: Uint8Array): Hash | null {
1321
+ if (!buffer || buffer.length === undefined) {
1322
+ return null;
1323
+ }
1324
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1325
+ const validation = this.validate(buffer);
1326
+ if (!validation.ok) {
1327
+ return null;
1328
+ }
1329
+ return new Hash(buffer);
1330
+ }
1331
+
1332
+ }
1333
+
1334
+ __tnRegisterFootprint("Hash", (params) => Hash.__tnInvokeFootprint(params));
1335
+ __tnRegisterValidate("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
1336
+
1337
+ export class HashBuilder {
1338
+ private buffer: Uint8Array;
1339
+ private view: DataView;
1340
+
1341
+ constructor() {
1342
+ this.buffer = new Uint8Array(32);
1343
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1344
+ }
1345
+
1346
+ set_bytes(values: number[]): this {
1347
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1348
+ for (let i = 0; i < values.length; i++) {
1349
+ const byteOffset = 0 + i * 1;
1350
+ this.view.setUint8(byteOffset, values[i]);
1351
+ }
1352
+ return this;
1353
+ }
1354
+
1355
+ build(): Uint8Array {
1356
+ return this.buffer.slice();
1357
+ }
1358
+
1359
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1360
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1361
+ target.set(this.buffer, offset);
1362
+ return target;
1363
+ }
1364
+
1365
+ finish(): Hash {
1366
+ const view = Hash.from_array(this.buffer.slice());
1367
+ if (!view) throw new Error("failed to build Hash");
1368
+ return view;
1369
+ }
1370
+ }
1371
+
1372
+ /* ----- TYPE DEFINITION FOR InstructionData ----- */
1373
+
1374
+ const __tn_ir_InstructionData = {
1375
+ typeName: "InstructionData",
1376
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 8, node: { op: "const", value: 8n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "data.data_size" }, right: { op: "const", value: 1n } } } } }
1377
+ } as const;
1378
+
1379
+ export class InstructionData {
1380
+ private view: DataView;
1381
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1382
+ private __tnParams: InstructionData.Params;
1383
+
1384
+ private constructor(private buffer: Uint8Array, params?: InstructionData.Params, fieldContext?: Record<string, number | bigint>) {
1385
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1386
+ this.__tnFieldContext = fieldContext ?? null;
1387
+ if (params) {
1388
+ this.__tnParams = params;
1389
+ } else {
1390
+ const derived = InstructionData.__tnExtractParams(this.view, buffer);
1391
+ if (!derived) {
1392
+ throw new Error("InstructionData: failed to derive dynamic parameters");
1393
+ }
1394
+ this.__tnParams = derived.params;
1395
+ }
1396
+ }
1397
+
1398
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: InstructionData.Params, fieldContext?: Record<string, number | bigint> }): InstructionData {
1399
+ if (!buffer || buffer.length === undefined) throw new Error("InstructionData.__tnCreateView requires a Uint8Array");
1400
+ let params = opts?.params ?? null;
1401
+ if (!params) {
1402
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1403
+ const derived = InstructionData.__tnExtractParams(view, buffer);
1404
+ if (!derived) throw new Error("InstructionData.__tnCreateView: failed to derive params");
1405
+ params = derived.params;
1406
+ }
1407
+ const instance = new InstructionData(new Uint8Array(buffer), params, opts?.fieldContext);
1408
+ return instance;
1409
+ }
1410
+
1411
+ dynamicParams(): InstructionData.Params {
1412
+ return this.__tnParams;
1413
+ }
1414
+
1415
+ withFieldContext(context: Record<string, number | bigint>): this {
1416
+ this.__tnFieldContext = context;
1417
+ return this;
1418
+ }
1419
+
1420
+ private __tnResolveFieldRef(path: string): number {
1421
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1422
+ const getter = (this as any)[getterName];
1423
+ if (typeof getter === "function") {
1424
+ const value = getter.call(this);
1425
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "InstructionData::__tnResolveFieldRef") : value;
1426
+ }
1427
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1428
+ const contextValue = this.__tnFieldContext[path];
1429
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "InstructionData::__tnResolveFieldRef") : contextValue;
1430
+ }
1431
+ throw new Error("InstructionData: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1432
+ }
1433
+
1434
+ static builder(): InstructionDataBuilder {
1435
+ return new InstructionDataBuilder();
1436
+ }
1437
+
1438
+ static fromBuilder(builder: InstructionDataBuilder): InstructionData | null {
1439
+ const buffer = builder.build();
1440
+ const params = builder.dynamicParams();
1441
+ return InstructionData.from_array(buffer, { params });
1442
+ }
1443
+
1444
+ static readonly flexibleArrayWriters = Object.freeze([
1445
+ { field: "data", method: "data", sizeField: "data_size", paramKey: "data_size", elementSize: 1 },
1446
+ ] as const);
1447
+
1448
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: InstructionData.Params; derived: Record<string, bigint> | null } | null {
1449
+ if (buffer.length < 10) {
1450
+ return null;
1451
+ }
1452
+ const __tnParam_data_data_size = __tnToBigInt(view.getBigUint64(2, true));
1453
+ const __tnExtractedParams = InstructionData.Params.fromValues({
1454
+ data_data_size: __tnParam_data_data_size,
1455
+ });
1456
+ return { params: __tnExtractedParams, derived: null };
1457
+ }
1458
+
1459
+ get_program_idx(): number {
1460
+ const offset = 0;
1461
+ return this.view.getUint16(offset, true); /* little-endian */
1462
+ }
1463
+
1464
+ set_program_idx(value: number): void {
1465
+ const offset = 0;
1466
+ this.view.setUint16(offset, value, true); /* little-endian */
1467
+ }
1468
+
1469
+ get program_idx(): number {
1470
+ return this.get_program_idx();
1471
+ }
1472
+
1473
+ set program_idx(value: number) {
1474
+ this.set_program_idx(value);
1475
+ }
1476
+
1477
+ get_data_size(): bigint {
1478
+ const offset = 2;
1479
+ return this.view.getBigUint64(offset, true); /* little-endian */
1480
+ }
1481
+
1482
+ set_data_size(value: bigint): void {
1483
+ const offset = 2;
1484
+ this.view.setBigUint64(offset, value, true); /* little-endian */
1485
+ }
1486
+
1487
+ get data_size(): bigint {
1488
+ return this.get_data_size();
1489
+ }
1490
+
1491
+ set data_size(value: bigint) {
1492
+ this.set_data_size(value);
1493
+ }
1494
+
1495
+ get_data_length(): number {
1496
+ return this.__tnResolveFieldRef("data_size");
1497
+ }
1498
+
1499
+ get_data_at(index: number): number {
1500
+ const offset = 10;
1501
+ return this.view.getUint8(offset + index * 1);
1502
+ }
1503
+
1504
+ get_data(): number[] {
1505
+ const len = this.get_data_length();
1506
+ const result: number[] = [];
1507
+ for (let i = 0; i < len; i++) {
1508
+ result.push(this.get_data_at(i));
1509
+ }
1510
+ return result;
1511
+ }
1512
+
1513
+ set_data_at(index: number, value: number): void {
1514
+ const offset = 10;
1515
+ this.view.setUint8((offset + index * 1), value);
1516
+ }
1517
+
1518
+ set_data(value: number[]): void {
1519
+ const len = Math.min(this.get_data_length(), value.length);
1520
+ for (let i = 0; i < len; i++) {
1521
+ this.set_data_at(i, value[i]);
1522
+ }
1523
+ }
1524
+
1525
+ get data(): number[] {
1526
+ return this.get_data();
1527
+ }
1528
+
1529
+ set data(value: number[]) {
1530
+ this.set_data(value);
1531
+ }
1532
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1533
+ return __tnEvalFootprint(__tn_ir_InstructionData.root, { params: __tnParams });
1534
+ }
1535
+
1536
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1537
+ return __tnValidateIrTree(__tn_ir_InstructionData, buffer, __tnParams);
1538
+ }
1539
+
1540
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1541
+ return this.__tnFootprintInternal(__tnParams);
1542
+ }
1543
+
1544
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1545
+ return this.__tnValidateInternal(buffer, __tnParams);
1546
+ }
1547
+
1548
+ static footprintIr(data_data_size: number | bigint): bigint {
1549
+ const params = InstructionData.Params.fromValues({
1550
+ data_data_size: data_data_size,
1551
+ });
1552
+ return this.footprintIrFromParams(params);
1553
+ }
1554
+
1555
+ private static __tnPackParams(params: InstructionData.Params): Record<string, bigint> {
1556
+ const record: Record<string, bigint> = Object.create(null);
1557
+ record["data.data_size"] = params.data_data_size;
1558
+ return record;
1559
+ }
1560
+
1561
+ static footprintIrFromParams(params: InstructionData.Params): bigint {
1562
+ const __tnParams = this.__tnPackParams(params);
1563
+ return this.__tnFootprintInternal(__tnParams);
1564
+ }
1565
+
1566
+ static footprintFromParams(params: InstructionData.Params): number {
1567
+ const irResult = this.footprintIrFromParams(params);
1568
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1569
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for InstructionData');
1570
+ return __tnBigIntToNumber(irResult, 'InstructionData::footprintFromParams');
1571
+ }
1572
+
1573
+ static footprintFromValues(input: { data_data_size: number | bigint }): number {
1574
+ const params = InstructionData.params(input);
1575
+ return this.footprintFromParams(params);
1576
+ }
1577
+
1578
+ static footprint(params: InstructionData.Params): number {
1579
+ return this.footprintFromParams(params);
1580
+ }
1581
+
1582
+ static validate(buffer: Uint8Array, opts?: { params?: InstructionData.Params }): { ok: boolean; code?: string; consumed?: number; params?: InstructionData.Params } {
1583
+ if (!buffer || buffer.length === undefined) {
1584
+ return { ok: false, code: "tn.invalid_buffer" };
1585
+ }
1586
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1587
+ let params = opts?.params ?? null;
1588
+ if (!params) {
1589
+ const extracted = this.__tnExtractParams(view, buffer);
1590
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1591
+ params = extracted.params;
1592
+ }
1593
+ const __tnParamsRec = this.__tnPackParams(params);
1594
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1595
+ if (!irResult.ok) {
1596
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'InstructionData::validate') : undefined, params };
1597
+ }
1598
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'InstructionData::validate') : undefined;
1599
+ return { ok: true, consumed, params };
1600
+ }
1601
+
1602
+ static from_array(buffer: Uint8Array, opts?: { params?: InstructionData.Params }): InstructionData | null {
1603
+ if (!buffer || buffer.length === undefined) {
1604
+ return null;
1605
+ }
1606
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1607
+ let params = opts?.params ?? null;
1608
+ if (!params) {
1609
+ const derived = this.__tnExtractParams(view, buffer);
1610
+ if (!derived) return null;
1611
+ params = derived.params;
1612
+ }
1613
+ const validation = this.validate(buffer, { params });
1614
+ if (!validation.ok) {
1615
+ return null;
1616
+ }
1617
+ const cached = validation.params ?? params;
1618
+ const state = new InstructionData(buffer, cached);
1619
+ return state;
1620
+ }
1621
+
1622
+
1623
+ }
1624
+
1625
+ export namespace InstructionData {
1626
+ export type Params = {
1627
+ /** ABI path: data.data_size */
1628
+ readonly data_data_size: bigint;
1629
+ };
1630
+
1631
+ export const ParamKeys = Object.freeze({
1632
+ data_data_size: "data.data_size",
1633
+ } as const);
1634
+
1635
+ export const Params = {
1636
+ fromValues(input: { data_data_size: number | bigint }): Params {
1637
+ return {
1638
+ data_data_size: __tnToBigInt(input.data_data_size),
1639
+ };
1640
+ },
1641
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
1642
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
1643
+ return (source as { dynamicParams(): Params }).dynamicParams();
1644
+ }
1645
+ if ((source as { params?: Params }).params) {
1646
+ return (source as { params: Params }).params;
1647
+ }
1648
+ return source as Params;
1649
+ }
1650
+ };
1651
+
1652
+ export function params(input: { data_data_size: number | bigint }): Params {
1653
+ return Params.fromValues(input);
1654
+ }
1655
+ }
1656
+
1657
+ __tnRegisterFootprint("InstructionData", (params) => InstructionData.__tnInvokeFootprint(params));
1658
+ __tnRegisterValidate("InstructionData", (buffer, params) => InstructionData.__tnInvokeValidate(buffer, params));
1659
+
1660
+ export class InstructionDataBuilder {
1661
+ private buffer: Uint8Array;
1662
+ private view: DataView;
1663
+ private __tnCachedParams: InstructionData.Params | null = null;
1664
+ private __tnLastBuffer: Uint8Array | null = null;
1665
+ private __tnLastParams: InstructionData.Params | null = null;
1666
+ private __tnFam_data: Uint8Array | null = null;
1667
+ private __tnFam_dataCount: number | null = null;
1668
+ private __tnFamWriter_data?: __TnFamWriterResult<InstructionDataBuilder>;
1669
+
1670
+ constructor() {
1671
+ this.buffer = new Uint8Array(10);
1672
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1673
+ }
1674
+
1675
+ private __tnInvalidate(): void {
1676
+ this.__tnCachedParams = null;
1677
+ this.__tnLastBuffer = null;
1678
+ this.__tnLastParams = null;
1679
+ }
1680
+
1681
+ set_program_idx(value: number): this {
1682
+ this.view.setUint16(0, value, true);
1683
+ this.__tnInvalidate();
1684
+ return this;
1685
+ }
1686
+
1687
+ set_data_size(value: number): this {
1688
+ const cast = __tnToBigInt(value);
1689
+ this.view.setBigUint64(2, cast, true);
1690
+ this.__tnInvalidate();
1691
+ return this;
1692
+ }
1693
+
1694
+ data(): __TnFamWriterResult<InstructionDataBuilder> {
1695
+ if (!this.__tnFamWriter_data) {
1696
+ this.__tnFamWriter_data = __tnCreateFamWriter(this, "data", (payload) => {
1697
+ const bytes = new Uint8Array(payload);
1698
+ const elementCount = bytes.length;
1699
+ this.__tnFam_data = bytes;
1700
+ this.__tnFam_dataCount = elementCount;
1701
+ this.set_data_size(elementCount);
1702
+ this.__tnInvalidate();
1703
+ });
1704
+ }
1705
+ return this.__tnFamWriter_data!;
1706
+ }
1707
+
1708
+ build(): Uint8Array {
1709
+ const params = this.__tnComputeParams();
1710
+ const size = InstructionData.footprintFromParams(params);
1711
+ const buffer = new Uint8Array(size);
1712
+ this.__tnWriteInto(buffer);
1713
+ this.__tnValidateOrThrow(buffer, params);
1714
+ return buffer;
1715
+ }
1716
+
1717
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1718
+ const params = this.__tnComputeParams();
1719
+ const size = InstructionData.footprintFromParams(params);
1720
+ if (target.length - offset < size) throw new Error("InstructionDataBuilder: target buffer too small");
1721
+ const slice = target.subarray(offset, offset + size);
1722
+ this.__tnWriteInto(slice);
1723
+ this.__tnValidateOrThrow(slice, params);
1724
+ return target;
1725
+ }
1726
+
1727
+ finish(): InstructionData {
1728
+ const buffer = this.build();
1729
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1730
+ const view = InstructionData.from_array(buffer, { params });
1731
+ if (!view) throw new Error("InstructionDataBuilder: failed to finalize view");
1732
+ return view;
1733
+ }
1734
+
1735
+ finishView(): InstructionData {
1736
+ return this.finish();
1737
+ }
1738
+
1739
+ dynamicParams(): InstructionData.Params {
1740
+ return this.__tnComputeParams();
1741
+ }
1742
+
1743
+ private __tnComputeParams(): InstructionData.Params {
1744
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1745
+ const params = InstructionData.Params.fromValues({
1746
+ data_data_size: (() => { if (this.__tnFam_dataCount === null) throw new Error("InstructionDataBuilder: field 'data' must be written before computing params"); return __tnToBigInt(this.__tnFam_dataCount); })(),
1747
+ });
1748
+ this.__tnCachedParams = params;
1749
+ return params;
1750
+ }
1751
+
1752
+ private __tnWriteInto(target: Uint8Array): void {
1753
+ target.set(this.buffer, 0);
1754
+ let cursor = this.buffer.length;
1755
+ const __tnLocal_data_bytes = this.__tnFam_data;
1756
+ if (!__tnLocal_data_bytes) throw new Error("InstructionDataBuilder: field 'data' must be written before build");
1757
+ target.set(__tnLocal_data_bytes, cursor);
1758
+ cursor += __tnLocal_data_bytes.length;
1759
+ }
1760
+
1761
+ private __tnValidateOrThrow(buffer: Uint8Array, params: InstructionData.Params): void {
1762
+ const result = InstructionData.validate(buffer, { params });
1763
+ if (!result.ok) {
1764
+ throw new Error(`${ InstructionData }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1765
+ }
1766
+ this.__tnLastParams = result.params ?? params;
1767
+ this.__tnLastBuffer = buffer;
1768
+ }
1769
+ }
1770
+
1771
+ /* ----- TYPE DEFINITION FOR Pubkey ----- */
1772
+
1773
+ const __tn_ir_Pubkey = {
1774
+ typeName: "Pubkey",
1775
+ root: { op: "const", value: 32n }
1776
+ } as const;
1777
+
1778
+ export class Pubkey {
1779
+ private view: DataView;
1780
+
1781
+ private constructor(private buffer: Uint8Array) {
1782
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1783
+ }
1784
+
1785
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Pubkey {
1786
+ if (!buffer || buffer.length === undefined) throw new Error("Pubkey.__tnCreateView requires a Uint8Array");
1787
+ return new Pubkey(new Uint8Array(buffer));
1788
+ }
1789
+
1790
+ static builder(): PubkeyBuilder {
1791
+ return new PubkeyBuilder();
1792
+ }
1793
+
1794
+ static fromBuilder(builder: PubkeyBuilder): Pubkey | null {
1795
+ const buffer = builder.build();
1796
+ return Pubkey.from_array(buffer);
1797
+ }
1798
+
1799
+ get_bytes(): number[] {
1800
+ const offset = 0;
1801
+ const result: number[] = [];
1802
+ for (let i = 0; i < 32; i++) {
1803
+ result.push(this.view.getUint8((offset + i * 1)));
1804
+ }
1805
+ return result;
1806
+ }
1807
+
1808
+ set_bytes(value: number[]): void {
1809
+ const offset = 0;
1810
+ if (value.length !== 32) {
1811
+ throw new Error('Array length must be 32');
1812
+ }
1813
+ for (let i = 0; i < 32; i++) {
1814
+ this.view.setUint8((offset + i * 1), value[i]);
1815
+ }
1816
+ }
1817
+
1818
+ get bytes(): number[] {
1819
+ return this.get_bytes();
1820
+ }
1821
+
1822
+ set bytes(value: number[]) {
1823
+ this.set_bytes(value);
1824
+ }
1825
+
1826
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1827
+ return __tnEvalFootprint(__tn_ir_Pubkey.root, { params: __tnParams });
1828
+ }
1829
+
1830
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1831
+ return __tnValidateIrTree(__tn_ir_Pubkey, buffer, __tnParams);
1832
+ }
1833
+
1834
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1835
+ return this.__tnFootprintInternal(__tnParams);
1836
+ }
1837
+
1838
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1839
+ return this.__tnValidateInternal(buffer, __tnParams);
1840
+ }
1841
+
1842
+ static footprintIr(): bigint {
1843
+ return this.__tnFootprintInternal(Object.create(null));
1844
+ }
1845
+
1846
+ static footprint(): number {
1847
+ const irResult = this.footprintIr();
1848
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1849
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1850
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Pubkey');
1851
+ }
1852
+ return __tnBigIntToNumber(irResult, 'Pubkey::footprint');
1853
+ }
1854
+
1855
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1856
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1857
+ return { ok: true, consumed: 32 };
1858
+ }
1859
+
1860
+ static from_array(buffer: Uint8Array): Pubkey | null {
1861
+ if (!buffer || buffer.length === undefined) {
1862
+ return null;
1863
+ }
1864
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1865
+ const validation = this.validate(buffer);
1866
+ if (!validation.ok) {
1867
+ return null;
1868
+ }
1869
+ return new Pubkey(buffer);
1870
+ }
1871
+
1872
+ }
1873
+
1874
+ __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
1875
+ __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
1876
+
1877
+ export class PubkeyBuilder {
1878
+ private buffer: Uint8Array;
1879
+ private view: DataView;
1880
+
1881
+ constructor() {
1882
+ this.buffer = new Uint8Array(32);
1883
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1884
+ }
1885
+
1886
+ set_bytes(values: number[]): this {
1887
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1888
+ for (let i = 0; i < values.length; i++) {
1889
+ const byteOffset = 0 + i * 1;
1890
+ this.view.setUint8(byteOffset, values[i]);
1891
+ }
1892
+ return this;
1893
+ }
1894
+
1895
+ build(): Uint8Array {
1896
+ return this.buffer.slice();
1897
+ }
1898
+
1899
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1900
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1901
+ target.set(this.buffer, offset);
1902
+ return target;
1903
+ }
1904
+
1905
+ finish(): Pubkey {
1906
+ const view = Pubkey.from_array(this.buffer.slice());
1907
+ if (!view) throw new Error("failed to build Pubkey");
1908
+ return view;
1909
+ }
1910
+ }
1911
+
1912
+ /* ----- TYPE DEFINITION FOR Signature ----- */
1913
+
1914
+ const __tn_ir_Signature = {
1915
+ typeName: "Signature",
1916
+ root: { op: "const", value: 64n }
1917
+ } as const;
1918
+
1919
+ export class Signature {
1920
+ private view: DataView;
1921
+
1922
+ private constructor(private buffer: Uint8Array) {
1923
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1924
+ }
1925
+
1926
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Signature {
1927
+ if (!buffer || buffer.length === undefined) throw new Error("Signature.__tnCreateView requires a Uint8Array");
1928
+ return new Signature(new Uint8Array(buffer));
1929
+ }
1930
+
1931
+ static builder(): SignatureBuilder {
1932
+ return new SignatureBuilder();
1933
+ }
1934
+
1935
+ static fromBuilder(builder: SignatureBuilder): Signature | null {
1936
+ const buffer = builder.build();
1937
+ return Signature.from_array(buffer);
1938
+ }
1939
+
1940
+ get_bytes(): number[] {
1941
+ const offset = 0;
1942
+ const result: number[] = [];
1943
+ for (let i = 0; i < 64; i++) {
1944
+ result.push(this.view.getUint8((offset + i * 1)));
1945
+ }
1946
+ return result;
1947
+ }
1948
+
1949
+ set_bytes(value: number[]): void {
1950
+ const offset = 0;
1951
+ if (value.length !== 64) {
1952
+ throw new Error('Array length must be 64');
1953
+ }
1954
+ for (let i = 0; i < 64; i++) {
1955
+ this.view.setUint8((offset + i * 1), value[i]);
1956
+ }
1957
+ }
1958
+
1959
+ get bytes(): number[] {
1960
+ return this.get_bytes();
1961
+ }
1962
+
1963
+ set bytes(value: number[]) {
1964
+ this.set_bytes(value);
1965
+ }
1966
+
1967
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1968
+ return __tnEvalFootprint(__tn_ir_Signature.root, { params: __tnParams });
1969
+ }
1970
+
1971
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1972
+ return __tnValidateIrTree(__tn_ir_Signature, buffer, __tnParams);
1973
+ }
1974
+
1975
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1976
+ return this.__tnFootprintInternal(__tnParams);
1977
+ }
1978
+
1979
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1980
+ return this.__tnValidateInternal(buffer, __tnParams);
1981
+ }
1982
+
1983
+ static footprintIr(): bigint {
1984
+ return this.__tnFootprintInternal(Object.create(null));
1985
+ }
1986
+
1987
+ static footprint(): number {
1988
+ const irResult = this.footprintIr();
1989
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1990
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1991
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Signature');
1992
+ }
1993
+ return __tnBigIntToNumber(irResult, 'Signature::footprint');
1994
+ }
1995
+
1996
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1997
+ if (buffer.length < 64) return { ok: false, code: "tn.buffer_too_small", consumed: 64 };
1998
+ return { ok: true, consumed: 64 };
1999
+ }
2000
+
2001
+ static from_array(buffer: Uint8Array): Signature | null {
2002
+ if (!buffer || buffer.length === undefined) {
2003
+ return null;
2004
+ }
2005
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2006
+ const validation = this.validate(buffer);
2007
+ if (!validation.ok) {
2008
+ return null;
2009
+ }
2010
+ return new Signature(buffer);
2011
+ }
2012
+
2013
+ }
2014
+
2015
+ __tnRegisterFootprint("Signature", (params) => Signature.__tnInvokeFootprint(params));
2016
+ __tnRegisterValidate("Signature", (buffer, params) => Signature.__tnInvokeValidate(buffer, params));
2017
+
2018
+ export class SignatureBuilder {
2019
+ private buffer: Uint8Array;
2020
+ private view: DataView;
2021
+
2022
+ constructor() {
2023
+ this.buffer = new Uint8Array(64);
2024
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2025
+ }
2026
+
2027
+ set_bytes(values: number[]): this {
2028
+ if (values.length !== 64) throw new Error("bytes expects 64 elements");
2029
+ for (let i = 0; i < values.length; i++) {
2030
+ const byteOffset = 0 + i * 1;
2031
+ this.view.setUint8(byteOffset, values[i]);
2032
+ }
2033
+ return this;
2034
+ }
2035
+
2036
+ build(): Uint8Array {
2037
+ return this.buffer.slice();
2038
+ }
2039
+
2040
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2041
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2042
+ target.set(this.buffer, offset);
2043
+ return target;
2044
+ }
2045
+
2046
+ finish(): Signature {
2047
+ const view = Signature.from_array(this.buffer.slice());
2048
+ if (!view) throw new Error("failed to build Signature");
2049
+ return view;
2050
+ }
2051
+ }
2052
+
2053
+ /* ----- TYPE DEFINITION FOR Timestamp ----- */
2054
+
2055
+ const __tn_ir_Timestamp = {
2056
+ typeName: "Timestamp",
2057
+ root: { op: "const", value: 8n }
2058
+ } as const;
2059
+
2060
+ export class Timestamp {
2061
+ private view: DataView;
2062
+
2063
+ private constructor(private buffer: Uint8Array) {
2064
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2065
+ }
2066
+
2067
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Timestamp {
2068
+ if (!buffer || buffer.length === undefined) throw new Error("Timestamp.__tnCreateView requires a Uint8Array");
2069
+ return new Timestamp(new Uint8Array(buffer));
2070
+ }
2071
+
2072
+ static builder(): TimestampBuilder {
2073
+ return new TimestampBuilder();
2074
+ }
2075
+
2076
+ static fromBuilder(builder: TimestampBuilder): Timestamp | null {
2077
+ const buffer = builder.build();
2078
+ return Timestamp.from_array(buffer);
2079
+ }
2080
+
2081
+ get_seconds(): bigint {
2082
+ const offset = 0;
2083
+ return this.view.getBigInt64(offset, true); /* little-endian */
2084
+ }
2085
+
2086
+ set_seconds(value: bigint): void {
2087
+ const offset = 0;
2088
+ this.view.setBigInt64(offset, value, true); /* little-endian */
2089
+ }
2090
+
2091
+ get seconds(): bigint {
2092
+ return this.get_seconds();
2093
+ }
2094
+
2095
+ set seconds(value: bigint) {
2096
+ this.set_seconds(value);
2097
+ }
2098
+
2099
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2100
+ return __tnEvalFootprint(__tn_ir_Timestamp.root, { params: __tnParams });
2101
+ }
2102
+
2103
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2104
+ return __tnValidateIrTree(__tn_ir_Timestamp, buffer, __tnParams);
2105
+ }
2106
+
2107
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2108
+ return this.__tnFootprintInternal(__tnParams);
2109
+ }
2110
+
2111
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2112
+ return this.__tnValidateInternal(buffer, __tnParams);
2113
+ }
2114
+
2115
+ static footprintIr(): bigint {
2116
+ return this.__tnFootprintInternal(Object.create(null));
2117
+ }
2118
+
2119
+ static footprint(): number {
2120
+ const irResult = this.footprintIr();
2121
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2122
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2123
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Timestamp');
2124
+ }
2125
+ return __tnBigIntToNumber(irResult, 'Timestamp::footprint');
2126
+ }
2127
+
2128
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2129
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
2130
+ return { ok: true, consumed: 8 };
2131
+ }
2132
+
2133
+ static new(seconds: bigint): Timestamp {
2134
+ const buffer = new Uint8Array(8);
2135
+ const view = new DataView(buffer.buffer);
2136
+
2137
+ let offset = 0;
2138
+ view.setBigInt64(0, seconds, true); /* seconds (little-endian) */
2139
+
2140
+ return new Timestamp(buffer);
2141
+ }
2142
+
2143
+ static from_array(buffer: Uint8Array): Timestamp | null {
2144
+ if (!buffer || buffer.length === undefined) {
2145
+ return null;
2146
+ }
2147
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2148
+ const validation = this.validate(buffer);
2149
+ if (!validation.ok) {
2150
+ return null;
2151
+ }
2152
+ return new Timestamp(buffer);
2153
+ }
2154
+
2155
+ }
2156
+
2157
+ __tnRegisterFootprint("Timestamp", (params) => Timestamp.__tnInvokeFootprint(params));
2158
+ __tnRegisterValidate("Timestamp", (buffer, params) => Timestamp.__tnInvokeValidate(buffer, params));
2159
+
2160
+ export class TimestampBuilder {
2161
+ private buffer: Uint8Array;
2162
+ private view: DataView;
2163
+
2164
+ constructor() {
2165
+ this.buffer = new Uint8Array(8);
2166
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2167
+ }
2168
+
2169
+ set_seconds(value: number): this {
2170
+ const cast = __tnToBigInt(value);
2171
+ this.view.setBigInt64(0, cast, true);
2172
+ return this;
2173
+ }
2174
+
2175
+ build(): Uint8Array {
2176
+ return this.buffer.slice();
2177
+ }
2178
+
2179
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2180
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2181
+ target.set(this.buffer, offset);
2182
+ return target;
2183
+ }
2184
+
2185
+ finish(): Timestamp {
2186
+ const view = Timestamp.from_array(this.buffer.slice());
2187
+ if (!view) throw new Error("failed to build Timestamp");
2188
+ return view;
2189
+ }
2190
+ }
2191
+