@thru/programs 0.2.30 → 0.2.32

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 (42) hide show
  1. package/dist/amm/index.cjs +6424 -0
  2. package/dist/amm/index.cjs.map +1 -0
  3. package/dist/amm/index.d.cts +1424 -0
  4. package/dist/amm/index.d.ts +1424 -0
  5. package/dist/amm/index.js +6360 -0
  6. package/dist/amm/index.js.map +1 -0
  7. package/dist/chunk-P5OABVJI.js +28 -0
  8. package/dist/chunk-P5OABVJI.js.map +1 -0
  9. package/dist/multicall/index.cjs +1 -1
  10. package/dist/multicall/index.cjs.map +1 -1
  11. package/dist/multicall/index.d.cts +2 -2
  12. package/dist/multicall/index.d.ts +2 -2
  13. package/dist/multicall/index.js +1 -1
  14. package/dist/multicall/index.js.map +1 -1
  15. package/dist/passkey-manager/index.cjs +33 -27
  16. package/dist/passkey-manager/index.cjs.map +1 -1
  17. package/dist/passkey-manager/index.d.cts +4 -3
  18. package/dist/passkey-manager/index.d.ts +4 -3
  19. package/dist/passkey-manager/index.js +9 -28
  20. package/dist/passkey-manager/index.js.map +1 -1
  21. package/dist/token/index.cjs +1760 -275
  22. package/dist/token/index.cjs.map +1 -1
  23. package/dist/token/index.d.cts +124 -20
  24. package/dist/token/index.d.ts +124 -20
  25. package/dist/token/index.js +1760 -275
  26. package/dist/token/index.js.map +1 -1
  27. package/package.json +9 -2
  28. package/src/amm/abi/thru/common/primitives/types.ts +2269 -0
  29. package/src/amm/abi/thru/program/amm/types.ts +5621 -0
  30. package/src/amm/index.test.ts +255 -0
  31. package/src/amm/index.ts +434 -0
  32. package/src/helpers/bytes.ts +25 -0
  33. package/src/multicall/abi/thru/common/primitives/types.ts +5 -6
  34. package/src/multicall/abi/thru/program/multicall/types.ts +1 -2
  35. package/src/passkey-manager/abi/thru/blockchain/state_proof/types.ts +0 -1
  36. package/src/passkey-manager/abi/thru/common/primitives/types.ts +0 -1
  37. package/src/passkey-manager/abi/thru/program/passkey_manager/types.ts +4 -5
  38. package/src/passkey-manager/encoding.ts +2 -26
  39. package/src/token/abi/thru/blockchain/state_proof/types.ts +101 -21
  40. package/src/token/abi/thru/common/primitives/types.ts +1295 -167
  41. package/src/token/abi/thru/program/token/types.ts +647 -237
  42. package/tsup.config.ts +1 -0
@@ -30,6 +30,12 @@ type __TnIrNode =
30
30
  readonly op: "call";
31
31
  readonly typeName: string;
32
32
  readonly args: readonly { readonly name: string; readonly source: string }[];
33
+ }
34
+ | {
35
+ readonly op: "sumOverArray";
36
+ readonly count: __TnIrNode;
37
+ readonly elementTypeName: string;
38
+ readonly fieldName: string;
33
39
  };
34
40
 
35
41
  type __TnIrContext = {
@@ -38,7 +44,12 @@ type __TnIrContext = {
38
44
  typeName?: string;
39
45
  };
40
46
 
41
- type __TnValidateResult = { ok: boolean; code?: string; consumed?: bigint };
47
+ type __TnValidateResult = {
48
+ ok: boolean;
49
+ code?: string;
50
+ consumed?: bigint;
51
+ params?: Record<string, bigint>;
52
+ };
42
53
  type __TnEvalResult =
43
54
  | { ok: true; value: bigint }
44
55
  | { ok: false; code: string };
@@ -515,6 +526,10 @@ const __tnValidateRegistry: Record<
515
526
  string,
516
527
  (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
517
528
  > = {};
529
+ const __tnDynamicValidateRegistry: Record<
530
+ string,
531
+ (buffer: Uint8Array) => __TnValidateResult
532
+ > = {};
518
533
 
519
534
  function __tnRegisterFootprint(
520
535
  typeName: string,
@@ -530,6 +545,13 @@ function __tnRegisterValidate(
530
545
  __tnValidateRegistry[typeName] = fn;
531
546
  }
532
547
 
548
+ function __tnRegisterDynamicValidate(
549
+ typeName: string,
550
+ fn: (buffer: Uint8Array) => __TnValidateResult
551
+ ): void {
552
+ __tnDynamicValidateRegistry[typeName] = fn;
553
+ }
554
+
533
555
  function __tnInvokeFootprint(
534
556
  typeName: string,
535
557
  params: Record<string, bigint>
@@ -549,8 +571,17 @@ function __tnInvokeValidate(
549
571
  return fn(buffer, params);
550
572
  }
551
573
 
574
+ function __tnInvokeDynamicValidate(
575
+ typeName: string,
576
+ buffer: Uint8Array
577
+ ): __TnValidateResult {
578
+ const fn = __tnDynamicValidateRegistry[typeName];
579
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
580
+ return fn(buffer);
581
+ }
582
+
552
583
  function __tnEvalFootprint(node: __TnIrNode, ctx: __TnIrContext): bigint {
553
- return __tnEvalIrNode(node, ctx);
584
+ return __tnEvalIrNode(node, ctx, __tnToBigInt(0));
554
585
  }
555
586
 
556
587
  function __tnTryEvalFootprint(
@@ -565,7 +596,7 @@ function __tnTryEvalIr(
565
596
  ctx: __TnIrContext
566
597
  ): __TnEvalResult {
567
598
  try {
568
- return { ok: true, value: __tnEvalIrNode(node, ctx) };
599
+ return { ok: true, value: __tnEvalIrNode(node, ctx, __tnToBigInt(0)) };
569
600
  } catch (err) {
570
601
  return { ok: false, code: __tnNormalizeIrError(err) };
571
602
  }
@@ -596,7 +627,11 @@ function __tnValidateIrTree(
596
627
  return { ok: true, consumed: required };
597
628
  }
598
629
 
599
- function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
630
+ function __tnEvalIrNode(
631
+ node: __TnIrNode,
632
+ ctx: __TnIrContext,
633
+ baseOffset: bigint
634
+ ): bigint {
600
635
  switch (node.op) {
601
636
  case "zero":
602
637
  return __tnToBigInt(0);
@@ -614,17 +649,22 @@ function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
614
649
  return val;
615
650
  }
616
651
  case "add":
617
- return __tnCheckedAdd(
618
- __tnEvalIrNode(node.left, ctx),
619
- __tnEvalIrNode(node.right, ctx)
620
- );
652
+ {
653
+ const left = __tnEvalIrNode(node.left, ctx, baseOffset);
654
+ const right = __tnEvalIrNode(
655
+ node.right,
656
+ ctx,
657
+ __tnCheckedAdd(baseOffset, left)
658
+ );
659
+ return __tnCheckedAdd(left, right);
660
+ }
621
661
  case "mul":
622
662
  return __tnCheckedMul(
623
- __tnEvalIrNode(node.left, ctx),
624
- __tnEvalIrNode(node.right, ctx)
663
+ __tnEvalIrNode(node.left, ctx, baseOffset),
664
+ __tnEvalIrNode(node.right, ctx, baseOffset)
625
665
  );
626
666
  case "align":
627
- return __tnAlign(__tnEvalIrNode(node.node, ctx), node.alignment);
667
+ return __tnAlign(__tnEvalIrNode(node.node, ctx, baseOffset), node.alignment);
628
668
  case "switch": {
629
669
  const tagVal = ctx.params[node.tag];
630
670
  if (tagVal === undefined) {
@@ -637,10 +677,10 @@ function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
637
677
  const tagNumber = Number(tagVal);
638
678
  for (const caseNode of node.cases) {
639
679
  if (caseNode.value === tagNumber) {
640
- return __tnEvalIrNode(caseNode.node, ctx);
680
+ return __tnEvalIrNode(caseNode.node, ctx, baseOffset);
641
681
  }
642
682
  }
643
- if (node.default) return __tnEvalIrNode(node.default, ctx);
683
+ if (node.default) return __tnEvalIrNode(node.default, ctx, baseOffset);
644
684
  __tnRaiseIrError(
645
685
  "tn.ir.invalid_tag",
646
686
  `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
@@ -660,9 +700,10 @@ function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
660
700
  nestedParams[arg.name] = val;
661
701
  }
662
702
  if (ctx.buffer) {
703
+ const nestedOffset = __tnBigIntToNumber(baseOffset, "IR nested offset");
663
704
  const nestedResult = __tnInvokeValidate(
664
705
  node.typeName,
665
- ctx.buffer,
706
+ ctx.buffer.subarray(nestedOffset),
666
707
  nestedParams
667
708
  );
668
709
  if (!nestedResult.ok) {
@@ -682,6 +723,36 @@ function __tnEvalIrNode(node: __TnIrNode, ctx: __TnIrContext): bigint {
682
723
  }
683
724
  return __tnInvokeFootprint(node.typeName, nestedParams);
684
725
  }
726
+ case "sumOverArray": {
727
+ if (!ctx.buffer) {
728
+ __tnRaiseIrError(
729
+ "tn.ir.missing_buffer",
730
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
731
+ );
732
+ }
733
+ const count = __tnBigIntToNumber(
734
+ __tnEvalIrNode(node.count, ctx, baseOffset),
735
+ `Jagged array '${node.fieldName}' count`
736
+ );
737
+ let cursor = __tnBigIntToNumber(baseOffset, "IR jagged array offset");
738
+ let total = __tnToBigInt(0);
739
+ for (let i = 0; i < count; i++) {
740
+ const result = __tnInvokeDynamicValidate(
741
+ node.elementTypeName,
742
+ ctx.buffer.subarray(cursor)
743
+ );
744
+ if (!result.ok || result.consumed === undefined) {
745
+ const code = result.code ?? "tn.ir.runtime_error";
746
+ __tnRaiseIrError(
747
+ code,
748
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
749
+ );
750
+ }
751
+ cursor += __tnBigIntToNumber(result.consumed, "IR jagged element size");
752
+ total = __tnCheckedAdd(total, result.consumed);
753
+ }
754
+ return total;
755
+ }
685
756
  default:
686
757
  __tnRaiseIrError(
687
758
  "tn.ir.runtime_error",
@@ -716,67 +787,94 @@ function __tnNormalizeIrError(err: unknown): string {
716
787
  return "tn.ir.runtime_error";
717
788
  }
718
789
 
719
- /* ----- TYPE DEFINITION FOR Hash ----- */
790
+ /* ----- TYPE DEFINITION FOR Date ----- */
720
791
 
721
- const __tn_ir_Hash = {
722
- typeName: "Hash",
723
- root: { op: "const", value: 32n }
792
+ const __tn_ir_Date = {
793
+ typeName: "Date",
794
+ root: { op: "const", value: 6n }
724
795
  } as const;
725
796
 
726
- export class Hash {
797
+ export class Date {
727
798
  private view: DataView;
728
799
 
729
800
  private constructor(private buffer: Uint8Array) {
730
801
  this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
731
802
  }
732
803
 
733
- static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Hash {
734
- if (!buffer || buffer.length === undefined) throw new Error("Hash.__tnCreateView requires a Uint8Array");
735
- return new Hash(new Uint8Array(buffer));
804
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Date {
805
+ if (!buffer || buffer.length === undefined) throw new Error("Date.__tnCreateView requires a Uint8Array");
806
+ return new Date(new Uint8Array(buffer));
736
807
  }
737
808
 
738
- static builder(): HashBuilder {
739
- return new HashBuilder();
809
+ static builder(): DateBuilder {
810
+ return new DateBuilder();
740
811
  }
741
812
 
742
- static fromBuilder(builder: HashBuilder): Hash | null {
813
+ static fromBuilder(builder: DateBuilder): Date | null {
743
814
  const buffer = builder.build();
744
- return Hash.from_array(buffer);
815
+ return Date.from_array(buffer);
745
816
  }
746
817
 
747
- get_bytes(): number[] {
818
+ get_year(): number {
748
819
  const offset = 0;
749
- const result: number[] = [];
750
- for (let i = 0; i < 32; i++) {
751
- result.push(this.view.getUint8((offset + i * 1)));
752
- }
753
- return result;
820
+ return this.view.getInt32(offset, true); /* little-endian */
754
821
  }
755
822
 
756
- set_bytes(value: number[]): void {
823
+ set_year(value: number): void {
757
824
  const offset = 0;
758
- if (value.length !== 32) {
759
- throw new Error('Array length must be 32');
760
- }
761
- for (let i = 0; i < 32; i++) {
762
- this.view.setUint8((offset + i * 1), value[i]);
763
- }
825
+ this.view.setInt32(offset, value, true); /* little-endian */
764
826
  }
765
827
 
766
- get bytes(): number[] {
767
- return this.get_bytes();
828
+ get year(): number {
829
+ return this.get_year();
768
830
  }
769
831
 
770
- set bytes(value: number[]) {
771
- this.set_bytes(value);
832
+ set year(value: number) {
833
+ this.set_year(value);
834
+ }
835
+
836
+ get_month(): number {
837
+ const offset = 4;
838
+ return this.view.getUint8(offset);
839
+ }
840
+
841
+ set_month(value: number): void {
842
+ const offset = 4;
843
+ this.view.setUint8(offset, value);
844
+ }
845
+
846
+ get month(): number {
847
+ return this.get_month();
848
+ }
849
+
850
+ set month(value: number) {
851
+ this.set_month(value);
852
+ }
853
+
854
+ get_day(): number {
855
+ const offset = 5;
856
+ return this.view.getUint8(offset);
857
+ }
858
+
859
+ set_day(value: number): void {
860
+ const offset = 5;
861
+ this.view.setUint8(offset, value);
862
+ }
863
+
864
+ get day(): number {
865
+ return this.get_day();
866
+ }
867
+
868
+ set day(value: number) {
869
+ this.set_day(value);
772
870
  }
773
871
 
774
872
  private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
775
- return __tnEvalFootprint(__tn_ir_Hash.root, { params: __tnParams });
873
+ return __tnEvalFootprint(__tn_ir_Date.root, { params: __tnParams });
776
874
  }
777
875
 
778
876
  private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
779
- return __tnValidateIrTree(__tn_ir_Hash, buffer, __tnParams);
877
+ return __tnValidateIrTree(__tn_ir_Date, buffer, __tnParams);
780
878
  }
781
879
 
782
880
  static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
@@ -795,17 +893,29 @@ export class Hash {
795
893
  const irResult = this.footprintIr();
796
894
  const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
797
895
  if (__tnBigIntGreaterThan(irResult, maxSafe)) {
798
- throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Hash');
896
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Date');
799
897
  }
800
- return __tnBigIntToNumber(irResult, 'Hash::footprint');
898
+ return __tnBigIntToNumber(irResult, 'Date::footprint');
801
899
  }
802
900
 
803
901
  static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
804
- if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
805
- return { ok: true, consumed: 32 };
902
+ if (buffer.length < 6) return { ok: false, code: "tn.buffer_too_small", consumed: 6 };
903
+ return { ok: true, consumed: 6 };
806
904
  }
807
905
 
808
- static from_array(buffer: Uint8Array): Hash | null {
906
+ static new(year: number, month: number, day: number): Date {
907
+ const buffer = new Uint8Array(6);
908
+ const view = new DataView(buffer.buffer);
909
+
910
+ let offset = 0;
911
+ view.setInt32(0, year, true); /* year (little-endian) */
912
+ view.setUint8(4, month); /* month */
913
+ view.setUint8(5, day); /* day */
914
+
915
+ return new Date(buffer);
916
+ }
917
+
918
+ static from_array(buffer: Uint8Array): Date | null {
809
919
  if (!buffer || buffer.length === undefined) {
810
920
  return null;
811
921
  }
@@ -814,29 +924,32 @@ export class Hash {
814
924
  if (!validation.ok) {
815
925
  return null;
816
926
  }
817
- return new Hash(buffer);
927
+ return new Date(buffer);
818
928
  }
819
929
 
820
930
  }
821
931
 
822
- __tnRegisterFootprint("Hash", (params) => Hash.__tnInvokeFootprint(params));
823
- __tnRegisterValidate("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
824
-
825
- export class HashBuilder {
932
+ export class DateBuilder {
826
933
  private buffer: Uint8Array;
827
934
  private view: DataView;
828
935
 
829
936
  constructor() {
830
- this.buffer = new Uint8Array(32);
937
+ this.buffer = new Uint8Array(6);
831
938
  this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
832
939
  }
833
940
 
834
- set_bytes(values: number[]): this {
835
- if (values.length !== 32) throw new Error("bytes expects 32 elements");
836
- for (let i = 0; i < values.length; i++) {
837
- const byteOffset = 0 + i * 1;
838
- this.view.setUint8(byteOffset, values[i]);
839
- }
941
+ set_year(value: number): this {
942
+ this.view.setInt32(0, value, true);
943
+ return this;
944
+ }
945
+
946
+ set_month(value: number): this {
947
+ this.view.setUint8(4, value);
948
+ return this;
949
+ }
950
+
951
+ set_day(value: number): this {
952
+ this.view.setUint8(5, value);
840
953
  return this;
841
954
  }
842
955
 
@@ -850,74 +963,87 @@ export class HashBuilder {
850
963
  return target;
851
964
  }
852
965
 
853
- finish(): Hash {
854
- const view = Hash.from_array(this.buffer.slice());
855
- if (!view) throw new Error("failed to build Hash");
966
+ finish(): Date {
967
+ const view = Date.from_array(this.buffer.slice());
968
+ if (!view) throw new Error("failed to build Date");
856
969
  return view;
857
970
  }
858
971
  }
859
972
 
860
- /* ----- TYPE DEFINITION FOR Pubkey ----- */
973
+ __tnRegisterFootprint("Date", (params) => Date.__tnInvokeFootprint(params));
974
+ __tnRegisterValidate("Date", (buffer, params) => Date.__tnInvokeValidate(buffer, params));
975
+ __tnRegisterDynamicValidate("Date", (buffer) => { const result = Date.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
861
976
 
862
- const __tn_ir_Pubkey = {
863
- typeName: "Pubkey",
864
- root: { op: "const", value: 32n }
977
+ /* ----- TYPE DEFINITION FOR Duration ----- */
978
+
979
+ const __tn_ir_Duration = {
980
+ typeName: "Duration",
981
+ root: { op: "const", value: 12n }
865
982
  } as const;
866
983
 
867
- export class Pubkey {
984
+ export class Duration {
868
985
  private view: DataView;
869
986
 
870
987
  private constructor(private buffer: Uint8Array) {
871
988
  this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
872
989
  }
873
990
 
874
- static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Pubkey {
875
- if (!buffer || buffer.length === undefined) throw new Error("Pubkey.__tnCreateView requires a Uint8Array");
876
- return new Pubkey(new Uint8Array(buffer));
991
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Duration {
992
+ if (!buffer || buffer.length === undefined) throw new Error("Duration.__tnCreateView requires a Uint8Array");
993
+ return new Duration(new Uint8Array(buffer));
877
994
  }
878
995
 
879
- static builder(): PubkeyBuilder {
880
- return new PubkeyBuilder();
996
+ static builder(): DurationBuilder {
997
+ return new DurationBuilder();
881
998
  }
882
999
 
883
- static fromBuilder(builder: PubkeyBuilder): Pubkey | null {
1000
+ static fromBuilder(builder: DurationBuilder): Duration | null {
884
1001
  const buffer = builder.build();
885
- return Pubkey.from_array(buffer);
1002
+ return Duration.from_array(buffer);
886
1003
  }
887
1004
 
888
- get_bytes(): number[] {
1005
+ get_seconds(): bigint {
889
1006
  const offset = 0;
890
- const result: number[] = [];
891
- for (let i = 0; i < 32; i++) {
892
- result.push(this.view.getUint8((offset + i * 1)));
893
- }
894
- return result;
1007
+ return this.view.getBigInt64(offset, true); /* little-endian */
895
1008
  }
896
1009
 
897
- set_bytes(value: number[]): void {
1010
+ set_seconds(value: bigint): void {
898
1011
  const offset = 0;
899
- if (value.length !== 32) {
900
- throw new Error('Array length must be 32');
901
- }
902
- for (let i = 0; i < 32; i++) {
903
- this.view.setUint8((offset + i * 1), value[i]);
904
- }
1012
+ this.view.setBigInt64(offset, value, true); /* little-endian */
905
1013
  }
906
1014
 
907
- get bytes(): number[] {
908
- return this.get_bytes();
1015
+ get seconds(): bigint {
1016
+ return this.get_seconds();
909
1017
  }
910
1018
 
911
- set bytes(value: number[]) {
912
- this.set_bytes(value);
1019
+ set seconds(value: bigint) {
1020
+ this.set_seconds(value);
1021
+ }
1022
+
1023
+ get_nanos(): number {
1024
+ const offset = 8;
1025
+ return this.view.getInt32(offset, true); /* little-endian */
1026
+ }
1027
+
1028
+ set_nanos(value: number): void {
1029
+ const offset = 8;
1030
+ this.view.setInt32(offset, value, true); /* little-endian */
1031
+ }
1032
+
1033
+ get nanos(): number {
1034
+ return this.get_nanos();
1035
+ }
1036
+
1037
+ set nanos(value: number) {
1038
+ this.set_nanos(value);
913
1039
  }
914
1040
 
915
1041
  private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
916
- return __tnEvalFootprint(__tn_ir_Pubkey.root, { params: __tnParams });
1042
+ return __tnEvalFootprint(__tn_ir_Duration.root, { params: __tnParams });
917
1043
  }
918
1044
 
919
1045
  private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
920
- return __tnValidateIrTree(__tn_ir_Pubkey, buffer, __tnParams);
1046
+ return __tnValidateIrTree(__tn_ir_Duration, buffer, __tnParams);
921
1047
  }
922
1048
 
923
1049
  static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
@@ -936,17 +1062,28 @@ export class Pubkey {
936
1062
  const irResult = this.footprintIr();
937
1063
  const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
938
1064
  if (__tnBigIntGreaterThan(irResult, maxSafe)) {
939
- throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Pubkey');
1065
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Duration');
940
1066
  }
941
- return __tnBigIntToNumber(irResult, 'Pubkey::footprint');
1067
+ return __tnBigIntToNumber(irResult, 'Duration::footprint');
942
1068
  }
943
1069
 
944
1070
  static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
945
- if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
946
- return { ok: true, consumed: 32 };
1071
+ if (buffer.length < 12) return { ok: false, code: "tn.buffer_too_small", consumed: 12 };
1072
+ return { ok: true, consumed: 12 };
947
1073
  }
948
1074
 
949
- static from_array(buffer: Uint8Array): Pubkey | null {
1075
+ static new(seconds: bigint, nanos: number): Duration {
1076
+ const buffer = new Uint8Array(12);
1077
+ const view = new DataView(buffer.buffer);
1078
+
1079
+ let offset = 0;
1080
+ view.setBigInt64(0, seconds, true); /* seconds (little-endian) */
1081
+ view.setInt32(8, nanos, true); /* nanos (little-endian) */
1082
+
1083
+ return new Duration(buffer);
1084
+ }
1085
+
1086
+ static from_array(buffer: Uint8Array): Duration | null {
950
1087
  if (!buffer || buffer.length === undefined) {
951
1088
  return null;
952
1089
  }
@@ -955,29 +1092,28 @@ export class Pubkey {
955
1092
  if (!validation.ok) {
956
1093
  return null;
957
1094
  }
958
- return new Pubkey(buffer);
1095
+ return new Duration(buffer);
959
1096
  }
960
1097
 
961
1098
  }
962
1099
 
963
- __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
964
- __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
965
-
966
- export class PubkeyBuilder {
1100
+ export class DurationBuilder {
967
1101
  private buffer: Uint8Array;
968
1102
  private view: DataView;
969
1103
 
970
1104
  constructor() {
971
- this.buffer = new Uint8Array(32);
1105
+ this.buffer = new Uint8Array(12);
972
1106
  this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
973
1107
  }
974
1108
 
975
- set_bytes(values: number[]): this {
976
- if (values.length !== 32) throw new Error("bytes expects 32 elements");
977
- for (let i = 0; i < values.length; i++) {
978
- const byteOffset = 0 + i * 1;
979
- this.view.setUint8(byteOffset, values[i]);
980
- }
1109
+ set_seconds(value: bigint): this {
1110
+ const cast = __tnToBigInt(value);
1111
+ this.view.setBigInt64(0, cast, true);
1112
+ return this;
1113
+ }
1114
+
1115
+ set_nanos(value: number): this {
1116
+ this.view.setInt32(8, value, true);
981
1117
  return this;
982
1118
  }
983
1119
 
@@ -991,74 +1127,87 @@ export class PubkeyBuilder {
991
1127
  return target;
992
1128
  }
993
1129
 
994
- finish(): Pubkey {
995
- const view = Pubkey.from_array(this.buffer.slice());
996
- if (!view) throw new Error("failed to build Pubkey");
1130
+ finish(): Duration {
1131
+ const view = Duration.from_array(this.buffer.slice());
1132
+ if (!view) throw new Error("failed to build Duration");
997
1133
  return view;
998
1134
  }
999
1135
  }
1000
1136
 
1001
- /* ----- TYPE DEFINITION FOR Signature ----- */
1137
+ __tnRegisterFootprint("Duration", (params) => Duration.__tnInvokeFootprint(params));
1138
+ __tnRegisterValidate("Duration", (buffer, params) => Duration.__tnInvokeValidate(buffer, params));
1139
+ __tnRegisterDynamicValidate("Duration", (buffer) => { const result = Duration.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1002
1140
 
1003
- const __tn_ir_Signature = {
1004
- typeName: "Signature",
1005
- root: { op: "const", value: 64n }
1141
+ /* ----- TYPE DEFINITION FOR FixedPoint ----- */
1142
+
1143
+ const __tn_ir_FixedPoint = {
1144
+ typeName: "FixedPoint",
1145
+ root: { op: "const", value: 9n }
1006
1146
  } as const;
1007
1147
 
1008
- export class Signature {
1148
+ export class FixedPoint {
1009
1149
  private view: DataView;
1010
1150
 
1011
1151
  private constructor(private buffer: Uint8Array) {
1012
1152
  this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1013
1153
  }
1014
1154
 
1015
- static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Signature {
1016
- if (!buffer || buffer.length === undefined) throw new Error("Signature.__tnCreateView requires a Uint8Array");
1017
- return new Signature(new Uint8Array(buffer));
1155
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): FixedPoint {
1156
+ if (!buffer || buffer.length === undefined) throw new Error("FixedPoint.__tnCreateView requires a Uint8Array");
1157
+ return new FixedPoint(new Uint8Array(buffer));
1018
1158
  }
1019
1159
 
1020
- static builder(): SignatureBuilder {
1021
- return new SignatureBuilder();
1160
+ static builder(): FixedPointBuilder {
1161
+ return new FixedPointBuilder();
1022
1162
  }
1023
1163
 
1024
- static fromBuilder(builder: SignatureBuilder): Signature | null {
1164
+ static fromBuilder(builder: FixedPointBuilder): FixedPoint | null {
1025
1165
  const buffer = builder.build();
1026
- return Signature.from_array(buffer);
1166
+ return FixedPoint.from_array(buffer);
1027
1167
  }
1028
1168
 
1029
- get_bytes(): number[] {
1169
+ get_mantissa(): bigint {
1030
1170
  const offset = 0;
1031
- const result: number[] = [];
1032
- for (let i = 0; i < 64; i++) {
1033
- result.push(this.view.getUint8((offset + i * 1)));
1034
- }
1035
- return result;
1171
+ return this.view.getBigInt64(offset, true); /* little-endian */
1036
1172
  }
1037
1173
 
1038
- set_bytes(value: number[]): void {
1174
+ set_mantissa(value: bigint): void {
1039
1175
  const offset = 0;
1040
- if (value.length !== 64) {
1041
- throw new Error('Array length must be 64');
1042
- }
1043
- for (let i = 0; i < 64; i++) {
1044
- this.view.setUint8((offset + i * 1), value[i]);
1045
- }
1176
+ this.view.setBigInt64(offset, value, true); /* little-endian */
1046
1177
  }
1047
1178
 
1048
- get bytes(): number[] {
1049
- return this.get_bytes();
1179
+ get mantissa(): bigint {
1180
+ return this.get_mantissa();
1050
1181
  }
1051
1182
 
1052
- set bytes(value: number[]) {
1053
- this.set_bytes(value);
1183
+ set mantissa(value: bigint) {
1184
+ this.set_mantissa(value);
1185
+ }
1186
+
1187
+ get_scale(): number {
1188
+ const offset = 8;
1189
+ return this.view.getUint8(offset);
1190
+ }
1191
+
1192
+ set_scale(value: number): void {
1193
+ const offset = 8;
1194
+ this.view.setUint8(offset, value);
1195
+ }
1196
+
1197
+ get scale(): number {
1198
+ return this.get_scale();
1199
+ }
1200
+
1201
+ set scale(value: number) {
1202
+ this.set_scale(value);
1054
1203
  }
1055
1204
 
1056
1205
  private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1057
- return __tnEvalFootprint(__tn_ir_Signature.root, { params: __tnParams });
1206
+ return __tnEvalFootprint(__tn_ir_FixedPoint.root, { params: __tnParams });
1058
1207
  }
1059
1208
 
1060
1209
  private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1061
- return __tnValidateIrTree(__tn_ir_Signature, buffer, __tnParams);
1210
+ return __tnValidateIrTree(__tn_ir_FixedPoint, buffer, __tnParams);
1062
1211
  }
1063
1212
 
1064
1213
  static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
@@ -1077,17 +1226,28 @@ export class Signature {
1077
1226
  const irResult = this.footprintIr();
1078
1227
  const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1079
1228
  if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1080
- throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Signature');
1229
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for FixedPoint');
1081
1230
  }
1082
- return __tnBigIntToNumber(irResult, 'Signature::footprint');
1231
+ return __tnBigIntToNumber(irResult, 'FixedPoint::footprint');
1083
1232
  }
1084
1233
 
1085
1234
  static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1086
- if (buffer.length < 64) return { ok: false, code: "tn.buffer_too_small", consumed: 64 };
1087
- return { ok: true, consumed: 64 };
1235
+ if (buffer.length < 9) return { ok: false, code: "tn.buffer_too_small", consumed: 9 };
1236
+ return { ok: true, consumed: 9 };
1088
1237
  }
1089
1238
 
1090
- static from_array(buffer: Uint8Array): Signature | null {
1239
+ static new(mantissa: bigint, scale: number): FixedPoint {
1240
+ const buffer = new Uint8Array(9);
1241
+ const view = new DataView(buffer.buffer);
1242
+
1243
+ let offset = 0;
1244
+ view.setBigInt64(0, mantissa, true); /* mantissa (little-endian) */
1245
+ view.setUint8(8, scale); /* scale */
1246
+
1247
+ return new FixedPoint(buffer);
1248
+ }
1249
+
1250
+ static from_array(buffer: Uint8Array): FixedPoint | null {
1091
1251
  if (!buffer || buffer.length === undefined) {
1092
1252
  return null;
1093
1253
  }
@@ -1096,29 +1256,28 @@ export class Signature {
1096
1256
  if (!validation.ok) {
1097
1257
  return null;
1098
1258
  }
1099
- return new Signature(buffer);
1259
+ return new FixedPoint(buffer);
1100
1260
  }
1101
1261
 
1102
1262
  }
1103
1263
 
1104
- __tnRegisterFootprint("Signature", (params) => Signature.__tnInvokeFootprint(params));
1105
- __tnRegisterValidate("Signature", (buffer, params) => Signature.__tnInvokeValidate(buffer, params));
1106
-
1107
- export class SignatureBuilder {
1264
+ export class FixedPointBuilder {
1108
1265
  private buffer: Uint8Array;
1109
1266
  private view: DataView;
1110
1267
 
1111
1268
  constructor() {
1112
- this.buffer = new Uint8Array(64);
1269
+ this.buffer = new Uint8Array(9);
1113
1270
  this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1114
1271
  }
1115
1272
 
1116
- set_bytes(values: number[]): this {
1117
- if (values.length !== 64) throw new Error("bytes expects 64 elements");
1118
- for (let i = 0; i < values.length; i++) {
1119
- const byteOffset = 0 + i * 1;
1120
- this.view.setUint8(byteOffset, values[i]);
1121
- }
1273
+ set_mantissa(value: bigint): this {
1274
+ const cast = __tnToBigInt(value);
1275
+ this.view.setBigInt64(0, cast, true);
1276
+ return this;
1277
+ }
1278
+
1279
+ set_scale(value: number): this {
1280
+ this.view.setUint8(8, value);
1122
1281
  return this;
1123
1282
  }
1124
1283
 
@@ -1132,10 +1291,979 @@ export class SignatureBuilder {
1132
1291
  return target;
1133
1292
  }
1134
1293
 
1135
- finish(): Signature {
1136
- const view = Signature.from_array(this.buffer.slice());
1137
- if (!view) throw new Error("failed to build Signature");
1294
+ finish(): FixedPoint {
1295
+ const view = FixedPoint.from_array(this.buffer.slice());
1296
+ if (!view) throw new Error("failed to build FixedPoint");
1297
+ return view;
1298
+ }
1299
+ }
1300
+
1301
+ __tnRegisterFootprint("FixedPoint", (params) => FixedPoint.__tnInvokeFootprint(params));
1302
+ __tnRegisterValidate("FixedPoint", (buffer, params) => FixedPoint.__tnInvokeValidate(buffer, params));
1303
+ __tnRegisterDynamicValidate("FixedPoint", (buffer) => { const result = FixedPoint.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1304
+
1305
+ /* ----- TYPE DEFINITION FOR Hash ----- */
1306
+
1307
+ const __tn_ir_Hash = {
1308
+ typeName: "Hash",
1309
+ root: { op: "const", value: 32n }
1310
+ } as const;
1311
+
1312
+ export class Hash {
1313
+ private view: DataView;
1314
+
1315
+ private constructor(private buffer: Uint8Array) {
1316
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1317
+ }
1318
+
1319
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Hash {
1320
+ if (!buffer || buffer.length === undefined) throw new Error("Hash.__tnCreateView requires a Uint8Array");
1321
+ return new Hash(new Uint8Array(buffer));
1322
+ }
1323
+
1324
+ static builder(): HashBuilder {
1325
+ return new HashBuilder();
1326
+ }
1327
+
1328
+ static fromBuilder(builder: HashBuilder): Hash | null {
1329
+ const buffer = builder.build();
1330
+ return Hash.from_array(buffer);
1331
+ }
1332
+
1333
+ get_bytes(): number[] {
1334
+ const offset = 0;
1335
+ const result: number[] = [];
1336
+ for (let i = 0; i < 32; i++) {
1337
+ result.push(this.view.getUint8((offset + i * 1)));
1338
+ }
1339
+ return result;
1340
+ }
1341
+
1342
+ set_bytes(value: number[]): void {
1343
+ const offset = 0;
1344
+ if (value.length !== 32) {
1345
+ throw new Error('Array length must be 32');
1346
+ }
1347
+ for (let i = 0; i < 32; i++) {
1348
+ this.view.setUint8((offset + i * 1), value[i]);
1349
+ }
1350
+ }
1351
+
1352
+ get bytes(): number[] {
1353
+ return this.get_bytes();
1354
+ }
1355
+
1356
+ set bytes(value: number[]) {
1357
+ this.set_bytes(value);
1358
+ }
1359
+
1360
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1361
+ return __tnEvalFootprint(__tn_ir_Hash.root, { params: __tnParams });
1362
+ }
1363
+
1364
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1365
+ return __tnValidateIrTree(__tn_ir_Hash, buffer, __tnParams);
1366
+ }
1367
+
1368
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1369
+ return this.__tnFootprintInternal(__tnParams);
1370
+ }
1371
+
1372
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1373
+ return this.__tnValidateInternal(buffer, __tnParams);
1374
+ }
1375
+
1376
+ static footprintIr(): bigint {
1377
+ return this.__tnFootprintInternal(Object.create(null));
1378
+ }
1379
+
1380
+ static footprint(): number {
1381
+ const irResult = this.footprintIr();
1382
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1383
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1384
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Hash');
1385
+ }
1386
+ return __tnBigIntToNumber(irResult, 'Hash::footprint');
1387
+ }
1388
+
1389
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1390
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1391
+ return { ok: true, consumed: 32 };
1392
+ }
1393
+
1394
+ static from_array(buffer: Uint8Array): Hash | null {
1395
+ if (!buffer || buffer.length === undefined) {
1396
+ return null;
1397
+ }
1398
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1399
+ const validation = this.validate(buffer);
1400
+ if (!validation.ok) {
1401
+ return null;
1402
+ }
1403
+ return new Hash(buffer);
1404
+ }
1405
+
1406
+ }
1407
+
1408
+ export class HashBuilder {
1409
+ private buffer: Uint8Array;
1410
+ private view: DataView;
1411
+
1412
+ constructor() {
1413
+ this.buffer = new Uint8Array(32);
1414
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1415
+ }
1416
+
1417
+ set_bytes(values: number[]): this {
1418
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1419
+ for (let i = 0; i < values.length; i++) {
1420
+ const byteOffset = 0 + i * 1;
1421
+ this.view.setUint8(byteOffset, values[i]);
1422
+ }
1423
+ return this;
1424
+ }
1425
+
1426
+ build(): Uint8Array {
1427
+ return this.buffer.slice();
1428
+ }
1429
+
1430
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1431
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1432
+ target.set(this.buffer, offset);
1433
+ return target;
1434
+ }
1435
+
1436
+ finish(): Hash {
1437
+ const view = Hash.from_array(this.buffer.slice());
1438
+ if (!view) throw new Error("failed to build Hash");
1439
+ return view;
1440
+ }
1441
+ }
1442
+
1443
+ __tnRegisterFootprint("Hash", (params) => Hash.__tnInvokeFootprint(params));
1444
+ __tnRegisterValidate("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
1445
+ __tnRegisterDynamicValidate("Hash", (buffer) => { const result = Hash.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1446
+
1447
+ /* ----- TYPE DEFINITION FOR InstructionData ----- */
1448
+
1449
+ const __tn_ir_InstructionData = {
1450
+ typeName: "InstructionData",
1451
+ 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 } } } } }
1452
+ } as const;
1453
+
1454
+ export class InstructionData {
1455
+ private view: DataView;
1456
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1457
+ private __tnParams: InstructionData.Params;
1458
+
1459
+ private constructor(private buffer: Uint8Array, params?: InstructionData.Params, fieldContext?: Record<string, number | bigint>) {
1460
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1461
+ this.__tnFieldContext = fieldContext ?? null;
1462
+ if (params) {
1463
+ this.__tnParams = params;
1464
+ } else {
1465
+ const derived = InstructionData.__tnExtractParams(this.view, buffer);
1466
+ if (!derived) {
1467
+ throw new Error("InstructionData: failed to derive dynamic parameters");
1468
+ }
1469
+ this.__tnParams = derived.params;
1470
+ }
1471
+ }
1472
+
1473
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: InstructionData.Params, fieldContext?: Record<string, number | bigint> }): InstructionData {
1474
+ if (!buffer || buffer.length === undefined) throw new Error("InstructionData.__tnCreateView requires a Uint8Array");
1475
+ let params = opts?.params ?? null;
1476
+ if (!params) {
1477
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1478
+ const derived = InstructionData.__tnExtractParams(view, buffer);
1479
+ if (!derived) throw new Error("InstructionData.__tnCreateView: failed to derive params");
1480
+ params = derived.params;
1481
+ }
1482
+ const instance = new InstructionData(new Uint8Array(buffer), params, opts?.fieldContext);
1483
+ return instance;
1484
+ }
1485
+
1486
+ dynamicParams(): InstructionData.Params {
1487
+ return this.__tnParams;
1488
+ }
1489
+
1490
+ withFieldContext(context: Record<string, number | bigint>): this {
1491
+ this.__tnFieldContext = context;
1492
+ return this;
1493
+ }
1494
+
1495
+ private __tnResolveFieldRef(path: string): number {
1496
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1497
+ const getter = (this as any)[getterName];
1498
+ if (typeof getter === "function") {
1499
+ const value = getter.call(this);
1500
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "InstructionData::__tnResolveFieldRef") : value;
1501
+ }
1502
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1503
+ const contextValue = this.__tnFieldContext[path];
1504
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "InstructionData::__tnResolveFieldRef") : contextValue;
1505
+ }
1506
+ throw new Error("InstructionData: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1507
+ }
1508
+
1509
+ static builder(): InstructionDataBuilder {
1510
+ return new InstructionDataBuilder();
1511
+ }
1512
+
1513
+ static fromBuilder(builder: InstructionDataBuilder): InstructionData | null {
1514
+ const buffer = builder.build();
1515
+ const params = builder.dynamicParams();
1516
+ return InstructionData.from_array(buffer, { params });
1517
+ }
1518
+
1519
+ static readonly flexibleArrayWriters = Object.freeze([
1520
+ { field: "data", method: "data", sizeField: "data_size", paramKey: "data_size", elementSize: 1 },
1521
+ ] as const);
1522
+
1523
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: InstructionData.Params; derived: Record<string, bigint> | null } | null {
1524
+ if (buffer.length < 10) {
1525
+ return null;
1526
+ }
1527
+ const __tnParam_data_data_size = __tnToBigInt(view.getBigUint64(2, true));
1528
+ const __tnExtractedParams = InstructionData.Params.fromValues({
1529
+ data_data_size: __tnParam_data_data_size,
1530
+ });
1531
+ return { params: __tnExtractedParams, derived: null };
1532
+ }
1533
+
1534
+ get_program_idx(): number {
1535
+ const offset = 0;
1536
+ return this.view.getUint16(offset, true); /* little-endian */
1537
+ }
1538
+
1539
+ set_program_idx(value: number): void {
1540
+ const offset = 0;
1541
+ this.view.setUint16(offset, value, true); /* little-endian */
1542
+ }
1543
+
1544
+ get program_idx(): number {
1545
+ return this.get_program_idx();
1546
+ }
1547
+
1548
+ set program_idx(value: number) {
1549
+ this.set_program_idx(value);
1550
+ }
1551
+
1552
+ get_data_size(): bigint {
1553
+ const offset = 2;
1554
+ return this.view.getBigUint64(offset, true); /* little-endian */
1555
+ }
1556
+
1557
+ set_data_size(value: bigint): void {
1558
+ const offset = 2;
1559
+ this.view.setBigUint64(offset, value, true); /* little-endian */
1560
+ }
1561
+
1562
+ get data_size(): bigint {
1563
+ return this.get_data_size();
1564
+ }
1565
+
1566
+ set data_size(value: bigint) {
1567
+ this.set_data_size(value);
1568
+ }
1569
+
1570
+ get_data_length(): number {
1571
+ return this.__tnResolveFieldRef("data_size");
1572
+ }
1573
+
1574
+ get_data_at(index: number): number {
1575
+ const offset = 10;
1576
+ return this.view.getUint8(offset + index * 1);
1577
+ }
1578
+
1579
+ get_data(): number[] {
1580
+ const len = this.get_data_length();
1581
+ const result: number[] = [];
1582
+ for (let i = 0; i < len; i++) {
1583
+ result.push(this.get_data_at(i));
1584
+ }
1585
+ return result;
1586
+ }
1587
+
1588
+ set_data_at(index: number, value: number): void {
1589
+ const offset = 10;
1590
+ this.view.setUint8((offset + index * 1), value);
1591
+ }
1592
+
1593
+ set_data(value: number[]): void {
1594
+ const len = Math.min(this.get_data_length(), value.length);
1595
+ for (let i = 0; i < len; i++) {
1596
+ this.set_data_at(i, value[i]);
1597
+ }
1598
+ }
1599
+
1600
+ get data(): number[] {
1601
+ return this.get_data();
1602
+ }
1603
+
1604
+ set data(value: number[]) {
1605
+ this.set_data(value);
1606
+ }
1607
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1608
+ return __tnEvalFootprint(__tn_ir_InstructionData.root, { params: __tnParams });
1609
+ }
1610
+
1611
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1612
+ return __tnValidateIrTree(__tn_ir_InstructionData, buffer, __tnParams);
1613
+ }
1614
+
1615
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1616
+ return this.__tnFootprintInternal(__tnParams);
1617
+ }
1618
+
1619
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1620
+ return this.__tnValidateInternal(buffer, __tnParams);
1621
+ }
1622
+
1623
+ static footprintIr(data_data_size: number | bigint): bigint {
1624
+ const params = InstructionData.Params.fromValues({
1625
+ data_data_size: data_data_size,
1626
+ });
1627
+ return this.footprintIrFromParams(params);
1628
+ }
1629
+
1630
+ private static __tnPackParams(params: InstructionData.Params): Record<string, bigint> {
1631
+ const record: Record<string, bigint> = Object.create(null);
1632
+ record["data.data_size"] = params.data_data_size;
1633
+ return record;
1634
+ }
1635
+
1636
+ static footprintIrFromParams(params: InstructionData.Params): bigint {
1637
+ const __tnParams = this.__tnPackParams(params);
1638
+ return this.__tnFootprintInternal(__tnParams);
1639
+ }
1640
+
1641
+ static footprintFromParams(params: InstructionData.Params): number {
1642
+ const irResult = this.footprintIrFromParams(params);
1643
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1644
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for InstructionData');
1645
+ return __tnBigIntToNumber(irResult, 'InstructionData::footprintFromParams');
1646
+ }
1647
+
1648
+ static footprintFromValues(input: { data_data_size: number | bigint }): number {
1649
+ const params = InstructionData.params(input);
1650
+ return this.footprintFromParams(params);
1651
+ }
1652
+
1653
+ static footprint(params: InstructionData.Params): number {
1654
+ return this.footprintFromParams(params);
1655
+ }
1656
+
1657
+ static validate(buffer: Uint8Array, opts?: { params?: InstructionData.Params }): { ok: boolean; code?: string; consumed?: number; params?: InstructionData.Params } {
1658
+ if (!buffer || buffer.length === undefined) {
1659
+ return { ok: false, code: "tn.invalid_buffer" };
1660
+ }
1661
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1662
+ let params = opts?.params ?? null;
1663
+ if (!params) {
1664
+ const extracted = this.__tnExtractParams(view, buffer);
1665
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1666
+ params = extracted.params;
1667
+ }
1668
+ const __tnParamsRec = this.__tnPackParams(params);
1669
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1670
+ if (!irResult.ok) {
1671
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'InstructionData::validate') : undefined, params };
1672
+ }
1673
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'InstructionData::validate') : undefined;
1674
+ return { ok: true, consumed, params };
1675
+ }
1676
+
1677
+ static from_array(buffer: Uint8Array, opts?: { params?: InstructionData.Params }): InstructionData | null {
1678
+ if (!buffer || buffer.length === undefined) {
1679
+ return null;
1680
+ }
1681
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1682
+ let params = opts?.params ?? null;
1683
+ if (!params) {
1684
+ const derived = this.__tnExtractParams(view, buffer);
1685
+ if (!derived) return null;
1686
+ params = derived.params;
1687
+ }
1688
+ const validation = this.validate(buffer, { params });
1689
+ if (!validation.ok) {
1690
+ return null;
1691
+ }
1692
+ const cached = validation.params ?? params;
1693
+ const state = new InstructionData(buffer, cached);
1694
+ return state;
1695
+ }
1696
+
1697
+
1698
+ }
1699
+
1700
+ export namespace InstructionData {
1701
+ export type Params = {
1702
+ /** ABI path: data.data_size */
1703
+ readonly data_data_size: bigint;
1704
+ };
1705
+
1706
+ export const ParamKeys = Object.freeze({
1707
+ data_data_size: "data.data_size",
1708
+ } as const);
1709
+
1710
+ export const Params = {
1711
+ fromValues(input: { data_data_size: number | bigint }): Params {
1712
+ return {
1713
+ data_data_size: __tnToBigInt(input.data_data_size),
1714
+ };
1715
+ },
1716
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
1717
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
1718
+ return (source as { dynamicParams(): Params }).dynamicParams();
1719
+ }
1720
+ if ((source as { params?: Params }).params) {
1721
+ return (source as { params: Params }).params;
1722
+ }
1723
+ return source as Params;
1724
+ }
1725
+ };
1726
+
1727
+ export function params(input: { data_data_size: number | bigint }): Params {
1728
+ return Params.fromValues(input);
1729
+ }
1730
+ }
1731
+
1732
+ export class InstructionDataBuilder {
1733
+ private buffer: Uint8Array;
1734
+ private view: DataView;
1735
+ private __tnCachedParams: InstructionData.Params | null = null;
1736
+ private __tnLastBuffer: Uint8Array | null = null;
1737
+ private __tnLastParams: InstructionData.Params | null = null;
1738
+ private __tnFam_data: Uint8Array | null = null;
1739
+ private __tnFam_dataCount: number | null = null;
1740
+ private __tnFamWriter_data?: __TnFamWriterResult<InstructionDataBuilder>;
1741
+
1742
+ constructor() {
1743
+ this.buffer = new Uint8Array(10);
1744
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1745
+ }
1746
+
1747
+ private __tnInvalidate(): void {
1748
+ this.__tnCachedParams = null;
1749
+ this.__tnLastBuffer = null;
1750
+ this.__tnLastParams = null;
1751
+ }
1752
+
1753
+ set_program_idx(value: number): this {
1754
+ this.view.setUint16(0, value, true);
1755
+ this.__tnInvalidate();
1756
+ return this;
1757
+ }
1758
+
1759
+ set_data_size(value: bigint): this {
1760
+ const cast = __tnToBigInt(value);
1761
+ this.view.setBigUint64(2, cast, true);
1762
+ this.__tnInvalidate();
1763
+ return this;
1764
+ }
1765
+
1766
+ data(): __TnFamWriterResult<InstructionDataBuilder> {
1767
+ if (!this.__tnFamWriter_data) {
1768
+ this.__tnFamWriter_data = __tnCreateFamWriter(this, "data", (payload) => {
1769
+ const bytes = new Uint8Array(payload);
1770
+ const elementCount = bytes.length;
1771
+ this.__tnFam_data = bytes;
1772
+ this.__tnFam_dataCount = elementCount;
1773
+ this.set_data_size(__tnToBigInt(elementCount));
1774
+ this.__tnInvalidate();
1775
+ });
1776
+ }
1777
+ return this.__tnFamWriter_data!;
1778
+ }
1779
+
1780
+ build(): Uint8Array {
1781
+ const params = this.__tnComputeParams();
1782
+ const size = InstructionData.footprintFromParams(params);
1783
+ const buffer = new Uint8Array(size);
1784
+ this.__tnWriteInto(buffer);
1785
+ this.__tnValidateOrThrow(buffer, params);
1786
+ return buffer;
1787
+ }
1788
+
1789
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1790
+ const params = this.__tnComputeParams();
1791
+ const size = InstructionData.footprintFromParams(params);
1792
+ if (target.length - offset < size) throw new Error("InstructionDataBuilder: target buffer too small");
1793
+ const slice = target.subarray(offset, offset + size);
1794
+ this.__tnWriteInto(slice);
1795
+ this.__tnValidateOrThrow(slice, params);
1796
+ return target;
1797
+ }
1798
+
1799
+ finish(): InstructionData {
1800
+ const buffer = this.build();
1801
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1802
+ const view = InstructionData.from_array(buffer, { params });
1803
+ if (!view) throw new Error("InstructionDataBuilder: failed to finalize view");
1804
+ return view;
1805
+ }
1806
+
1807
+ finishView(): InstructionData {
1808
+ return this.finish();
1809
+ }
1810
+
1811
+ dynamicParams(): InstructionData.Params {
1812
+ return this.__tnComputeParams();
1813
+ }
1814
+
1815
+ private __tnComputeParams(): InstructionData.Params {
1816
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1817
+ const params = InstructionData.Params.fromValues({
1818
+ 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); })(),
1819
+ });
1820
+ this.__tnCachedParams = params;
1821
+ return params;
1822
+ }
1823
+
1824
+ private __tnWriteInto(target: Uint8Array): void {
1825
+ target.set(this.buffer, 0);
1826
+ let cursor = this.buffer.length;
1827
+ const __tnLocal_data_bytes = this.__tnFam_data;
1828
+ if (!__tnLocal_data_bytes) throw new Error("InstructionDataBuilder: field 'data' must be written before build");
1829
+ target.set(__tnLocal_data_bytes, cursor);
1830
+ cursor += __tnLocal_data_bytes.length;
1831
+ }
1832
+
1833
+ private __tnValidateOrThrow(buffer: Uint8Array, params: InstructionData.Params): void {
1834
+ const result = InstructionData.validate(buffer, { params });
1835
+ if (!result.ok) {
1836
+ throw new Error(`${ InstructionData }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1837
+ }
1838
+ this.__tnLastParams = result.params ?? params;
1839
+ this.__tnLastBuffer = buffer;
1840
+ }
1841
+ }
1842
+
1843
+ __tnRegisterFootprint("InstructionData", (params) => InstructionData.__tnInvokeFootprint(params));
1844
+ __tnRegisterValidate("InstructionData", (buffer, params) => InstructionData.__tnInvokeValidate(buffer, params));
1845
+ __tnRegisterDynamicValidate("InstructionData", (buffer) => { const result = InstructionData.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1846
+
1847
+ /* ----- TYPE DEFINITION FOR Pubkey ----- */
1848
+
1849
+ const __tn_ir_Pubkey = {
1850
+ typeName: "Pubkey",
1851
+ root: { op: "const", value: 32n }
1852
+ } as const;
1853
+
1854
+ export class Pubkey {
1855
+ private view: DataView;
1856
+
1857
+ private constructor(private buffer: Uint8Array) {
1858
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1859
+ }
1860
+
1861
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Pubkey {
1862
+ if (!buffer || buffer.length === undefined) throw new Error("Pubkey.__tnCreateView requires a Uint8Array");
1863
+ return new Pubkey(new Uint8Array(buffer));
1864
+ }
1865
+
1866
+ static builder(): PubkeyBuilder {
1867
+ return new PubkeyBuilder();
1868
+ }
1869
+
1870
+ static fromBuilder(builder: PubkeyBuilder): Pubkey | null {
1871
+ const buffer = builder.build();
1872
+ return Pubkey.from_array(buffer);
1873
+ }
1874
+
1875
+ get_bytes(): number[] {
1876
+ const offset = 0;
1877
+ const result: number[] = [];
1878
+ for (let i = 0; i < 32; i++) {
1879
+ result.push(this.view.getUint8((offset + i * 1)));
1880
+ }
1881
+ return result;
1882
+ }
1883
+
1884
+ set_bytes(value: number[]): void {
1885
+ const offset = 0;
1886
+ if (value.length !== 32) {
1887
+ throw new Error('Array length must be 32');
1888
+ }
1889
+ for (let i = 0; i < 32; i++) {
1890
+ this.view.setUint8((offset + i * 1), value[i]);
1891
+ }
1892
+ }
1893
+
1894
+ get bytes(): number[] {
1895
+ return this.get_bytes();
1896
+ }
1897
+
1898
+ set bytes(value: number[]) {
1899
+ this.set_bytes(value);
1900
+ }
1901
+
1902
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1903
+ return __tnEvalFootprint(__tn_ir_Pubkey.root, { params: __tnParams });
1904
+ }
1905
+
1906
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1907
+ return __tnValidateIrTree(__tn_ir_Pubkey, buffer, __tnParams);
1908
+ }
1909
+
1910
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1911
+ return this.__tnFootprintInternal(__tnParams);
1912
+ }
1913
+
1914
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1915
+ return this.__tnValidateInternal(buffer, __tnParams);
1916
+ }
1917
+
1918
+ static footprintIr(): bigint {
1919
+ return this.__tnFootprintInternal(Object.create(null));
1920
+ }
1921
+
1922
+ static footprint(): number {
1923
+ const irResult = this.footprintIr();
1924
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1925
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1926
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Pubkey');
1927
+ }
1928
+ return __tnBigIntToNumber(irResult, 'Pubkey::footprint');
1929
+ }
1930
+
1931
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1932
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1933
+ return { ok: true, consumed: 32 };
1934
+ }
1935
+
1936
+ static from_array(buffer: Uint8Array): Pubkey | null {
1937
+ if (!buffer || buffer.length === undefined) {
1938
+ return null;
1939
+ }
1940
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1941
+ const validation = this.validate(buffer);
1942
+ if (!validation.ok) {
1943
+ return null;
1944
+ }
1945
+ return new Pubkey(buffer);
1946
+ }
1947
+
1948
+ }
1949
+
1950
+ export class PubkeyBuilder {
1951
+ private buffer: Uint8Array;
1952
+ private view: DataView;
1953
+
1954
+ constructor() {
1955
+ this.buffer = new Uint8Array(32);
1956
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1957
+ }
1958
+
1959
+ set_bytes(values: number[]): this {
1960
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1961
+ for (let i = 0; i < values.length; i++) {
1962
+ const byteOffset = 0 + i * 1;
1963
+ this.view.setUint8(byteOffset, values[i]);
1964
+ }
1965
+ return this;
1966
+ }
1967
+
1968
+ build(): Uint8Array {
1969
+ return this.buffer.slice();
1970
+ }
1971
+
1972
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1973
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1974
+ target.set(this.buffer, offset);
1975
+ return target;
1976
+ }
1977
+
1978
+ finish(): Pubkey {
1979
+ const view = Pubkey.from_array(this.buffer.slice());
1980
+ if (!view) throw new Error("failed to build Pubkey");
1981
+ return view;
1982
+ }
1983
+ }
1984
+
1985
+ __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
1986
+ __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
1987
+ __tnRegisterDynamicValidate("Pubkey", (buffer) => { const result = Pubkey.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1988
+
1989
+ /* ----- TYPE DEFINITION FOR Signature ----- */
1990
+
1991
+ const __tn_ir_Signature = {
1992
+ typeName: "Signature",
1993
+ root: { op: "const", value: 64n }
1994
+ } as const;
1995
+
1996
+ export class Signature {
1997
+ private view: DataView;
1998
+
1999
+ private constructor(private buffer: Uint8Array) {
2000
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2001
+ }
2002
+
2003
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Signature {
2004
+ if (!buffer || buffer.length === undefined) throw new Error("Signature.__tnCreateView requires a Uint8Array");
2005
+ return new Signature(new Uint8Array(buffer));
2006
+ }
2007
+
2008
+ static builder(): SignatureBuilder {
2009
+ return new SignatureBuilder();
2010
+ }
2011
+
2012
+ static fromBuilder(builder: SignatureBuilder): Signature | null {
2013
+ const buffer = builder.build();
2014
+ return Signature.from_array(buffer);
2015
+ }
2016
+
2017
+ get_bytes(): number[] {
2018
+ const offset = 0;
2019
+ const result: number[] = [];
2020
+ for (let i = 0; i < 64; i++) {
2021
+ result.push(this.view.getUint8((offset + i * 1)));
2022
+ }
2023
+ return result;
2024
+ }
2025
+
2026
+ set_bytes(value: number[]): void {
2027
+ const offset = 0;
2028
+ if (value.length !== 64) {
2029
+ throw new Error('Array length must be 64');
2030
+ }
2031
+ for (let i = 0; i < 64; i++) {
2032
+ this.view.setUint8((offset + i * 1), value[i]);
2033
+ }
2034
+ }
2035
+
2036
+ get bytes(): number[] {
2037
+ return this.get_bytes();
2038
+ }
2039
+
2040
+ set bytes(value: number[]) {
2041
+ this.set_bytes(value);
2042
+ }
2043
+
2044
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2045
+ return __tnEvalFootprint(__tn_ir_Signature.root, { params: __tnParams });
2046
+ }
2047
+
2048
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2049
+ return __tnValidateIrTree(__tn_ir_Signature, buffer, __tnParams);
2050
+ }
2051
+
2052
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2053
+ return this.__tnFootprintInternal(__tnParams);
2054
+ }
2055
+
2056
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2057
+ return this.__tnValidateInternal(buffer, __tnParams);
2058
+ }
2059
+
2060
+ static footprintIr(): bigint {
2061
+ return this.__tnFootprintInternal(Object.create(null));
2062
+ }
2063
+
2064
+ static footprint(): number {
2065
+ const irResult = this.footprintIr();
2066
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2067
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2068
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Signature');
2069
+ }
2070
+ return __tnBigIntToNumber(irResult, 'Signature::footprint');
2071
+ }
2072
+
2073
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2074
+ if (buffer.length < 64) return { ok: false, code: "tn.buffer_too_small", consumed: 64 };
2075
+ return { ok: true, consumed: 64 };
2076
+ }
2077
+
2078
+ static from_array(buffer: Uint8Array): Signature | null {
2079
+ if (!buffer || buffer.length === undefined) {
2080
+ return null;
2081
+ }
2082
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2083
+ const validation = this.validate(buffer);
2084
+ if (!validation.ok) {
2085
+ return null;
2086
+ }
2087
+ return new Signature(buffer);
2088
+ }
2089
+
2090
+ }
2091
+
2092
+ export class SignatureBuilder {
2093
+ private buffer: Uint8Array;
2094
+ private view: DataView;
2095
+
2096
+ constructor() {
2097
+ this.buffer = new Uint8Array(64);
2098
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2099
+ }
2100
+
2101
+ set_bytes(values: number[]): this {
2102
+ if (values.length !== 64) throw new Error("bytes expects 64 elements");
2103
+ for (let i = 0; i < values.length; i++) {
2104
+ const byteOffset = 0 + i * 1;
2105
+ this.view.setUint8(byteOffset, values[i]);
2106
+ }
2107
+ return this;
2108
+ }
2109
+
2110
+ build(): Uint8Array {
2111
+ return this.buffer.slice();
2112
+ }
2113
+
2114
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2115
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2116
+ target.set(this.buffer, offset);
2117
+ return target;
2118
+ }
2119
+
2120
+ finish(): Signature {
2121
+ const view = Signature.from_array(this.buffer.slice());
2122
+ if (!view) throw new Error("failed to build Signature");
2123
+ return view;
2124
+ }
2125
+ }
2126
+
2127
+ __tnRegisterFootprint("Signature", (params) => Signature.__tnInvokeFootprint(params));
2128
+ __tnRegisterValidate("Signature", (buffer, params) => Signature.__tnInvokeValidate(buffer, params));
2129
+ __tnRegisterDynamicValidate("Signature", (buffer) => { const result = Signature.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
2130
+
2131
+ /* ----- TYPE DEFINITION FOR Timestamp ----- */
2132
+
2133
+ const __tn_ir_Timestamp = {
2134
+ typeName: "Timestamp",
2135
+ root: { op: "const", value: 8n }
2136
+ } as const;
2137
+
2138
+ export class Timestamp {
2139
+ private view: DataView;
2140
+
2141
+ private constructor(private buffer: Uint8Array) {
2142
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2143
+ }
2144
+
2145
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): Timestamp {
2146
+ if (!buffer || buffer.length === undefined) throw new Error("Timestamp.__tnCreateView requires a Uint8Array");
2147
+ return new Timestamp(new Uint8Array(buffer));
2148
+ }
2149
+
2150
+ static builder(): TimestampBuilder {
2151
+ return new TimestampBuilder();
2152
+ }
2153
+
2154
+ static fromBuilder(builder: TimestampBuilder): Timestamp | null {
2155
+ const buffer = builder.build();
2156
+ return Timestamp.from_array(buffer);
2157
+ }
2158
+
2159
+ get_seconds(): bigint {
2160
+ const offset = 0;
2161
+ return this.view.getBigInt64(offset, true); /* little-endian */
2162
+ }
2163
+
2164
+ set_seconds(value: bigint): void {
2165
+ const offset = 0;
2166
+ this.view.setBigInt64(offset, value, true); /* little-endian */
2167
+ }
2168
+
2169
+ get seconds(): bigint {
2170
+ return this.get_seconds();
2171
+ }
2172
+
2173
+ set seconds(value: bigint) {
2174
+ this.set_seconds(value);
2175
+ }
2176
+
2177
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2178
+ return __tnEvalFootprint(__tn_ir_Timestamp.root, { params: __tnParams });
2179
+ }
2180
+
2181
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2182
+ return __tnValidateIrTree(__tn_ir_Timestamp, buffer, __tnParams);
2183
+ }
2184
+
2185
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2186
+ return this.__tnFootprintInternal(__tnParams);
2187
+ }
2188
+
2189
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2190
+ return this.__tnValidateInternal(buffer, __tnParams);
2191
+ }
2192
+
2193
+ static footprintIr(): bigint {
2194
+ return this.__tnFootprintInternal(Object.create(null));
2195
+ }
2196
+
2197
+ static footprint(): number {
2198
+ const irResult = this.footprintIr();
2199
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2200
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2201
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for Timestamp');
2202
+ }
2203
+ return __tnBigIntToNumber(irResult, 'Timestamp::footprint');
2204
+ }
2205
+
2206
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2207
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
2208
+ return { ok: true, consumed: 8 };
2209
+ }
2210
+
2211
+ static new(seconds: bigint): Timestamp {
2212
+ const buffer = new Uint8Array(8);
2213
+ const view = new DataView(buffer.buffer);
2214
+
2215
+ let offset = 0;
2216
+ view.setBigInt64(0, seconds, true); /* seconds (little-endian) */
2217
+
2218
+ return new Timestamp(buffer);
2219
+ }
2220
+
2221
+ static from_array(buffer: Uint8Array): Timestamp | null {
2222
+ if (!buffer || buffer.length === undefined) {
2223
+ return null;
2224
+ }
2225
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2226
+ const validation = this.validate(buffer);
2227
+ if (!validation.ok) {
2228
+ return null;
2229
+ }
2230
+ return new Timestamp(buffer);
2231
+ }
2232
+
2233
+ }
2234
+
2235
+ export class TimestampBuilder {
2236
+ private buffer: Uint8Array;
2237
+ private view: DataView;
2238
+
2239
+ constructor() {
2240
+ this.buffer = new Uint8Array(8);
2241
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2242
+ }
2243
+
2244
+ set_seconds(value: bigint): this {
2245
+ const cast = __tnToBigInt(value);
2246
+ this.view.setBigInt64(0, cast, true);
2247
+ return this;
2248
+ }
2249
+
2250
+ build(): Uint8Array {
2251
+ return this.buffer.slice();
2252
+ }
2253
+
2254
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2255
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2256
+ target.set(this.buffer, offset);
2257
+ return target;
2258
+ }
2259
+
2260
+ finish(): Timestamp {
2261
+ const view = Timestamp.from_array(this.buffer.slice());
2262
+ if (!view) throw new Error("failed to build Timestamp");
1138
2263
  return view;
1139
2264
  }
1140
2265
  }
1141
2266
 
2267
+ __tnRegisterFootprint("Timestamp", (params) => Timestamp.__tnInvokeFootprint(params));
2268
+ __tnRegisterValidate("Timestamp", (buffer, params) => Timestamp.__tnInvokeValidate(buffer, params));
2269
+ __tnRegisterDynamicValidate("Timestamp", (buffer) => { const result = Timestamp.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });