@thru/programs 0.3.3 → 0.3.5

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 (122) hide show
  1. package/README.md +123 -37
  2. package/dist/abi-manager/index.cjs +9568 -0
  3. package/dist/abi-manager/index.cjs.map +1 -0
  4. package/dist/abi-manager/index.d.cts +2169 -0
  5. package/dist/abi-manager/index.d.ts +2169 -0
  6. package/dist/abi-manager/index.js +4 -0
  7. package/dist/abi-manager/index.js.map +1 -0
  8. package/dist/amm/index.cjs +1 -3
  9. package/dist/amm/index.cjs.map +1 -1
  10. package/dist/amm/index.d.cts +1 -1
  11. package/dist/amm/index.d.ts +1 -1
  12. package/dist/amm/index.js +2 -2
  13. package/dist/amm/index.js.map +1 -1
  14. package/dist/chunk-6IC6CO5S.js +9443 -0
  15. package/dist/chunk-6IC6CO5S.js.map +1 -0
  16. package/dist/chunk-7DRJVAYI.js +8587 -0
  17. package/dist/chunk-7DRJVAYI.js.map +1 -0
  18. package/dist/chunk-7FBCBZIY.js +41 -0
  19. package/dist/chunk-7FBCBZIY.js.map +1 -0
  20. package/dist/chunk-BNYDH4ZP.js +4351 -0
  21. package/dist/chunk-BNYDH4ZP.js.map +1 -0
  22. package/dist/chunk-OODN6LJA.js +6567 -0
  23. package/dist/chunk-OODN6LJA.js.map +1 -0
  24. package/dist/chunk-YX7BLFQZ.js +81 -0
  25. package/dist/chunk-YX7BLFQZ.js.map +1 -0
  26. package/dist/clob/index.cjs +19361 -6851
  27. package/dist/clob/index.cjs.map +1 -1
  28. package/dist/clob/index.d.cts +1243 -63
  29. package/dist/clob/index.d.ts +1243 -63
  30. package/dist/clob/index.js +6826 -2818
  31. package/dist/clob/index.js.map +1 -1
  32. package/dist/deploy/index.cjs +24734 -0
  33. package/dist/deploy/index.cjs.map +1 -0
  34. package/dist/deploy/index.d.cts +180 -0
  35. package/dist/deploy/index.d.ts +180 -0
  36. package/dist/deploy/index.js +1846 -0
  37. package/dist/deploy/index.js.map +1 -0
  38. package/dist/helpers-DD7q61nr.d.cts +7 -0
  39. package/dist/helpers-DD7q61nr.d.ts +7 -0
  40. package/dist/manager/index.cjs +6680 -0
  41. package/dist/manager/index.cjs.map +1 -0
  42. package/dist/manager/index.d.cts +1279 -0
  43. package/dist/manager/index.d.ts +1279 -0
  44. package/dist/manager/index.js +4 -0
  45. package/dist/manager/index.js.map +1 -0
  46. package/dist/passkey-manager/index.cjs +4 -5
  47. package/dist/passkey-manager/index.cjs.map +1 -1
  48. package/dist/passkey-manager/index.js +2 -2
  49. package/dist/token/index.js +1 -8585
  50. package/dist/token/index.js.map +1 -1
  51. package/dist/uploader/index.cjs +4442 -0
  52. package/dist/uploader/index.cjs.map +1 -0
  53. package/dist/uploader/index.d.cts +761 -0
  54. package/dist/uploader/index.d.ts +761 -0
  55. package/dist/uploader/index.js +4 -0
  56. package/dist/uploader/index.js.map +1 -0
  57. package/package.json +22 -2
  58. package/src/abi-manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
  59. package/src/abi-manager/abi/thru/common/primitives/types.ts +2428 -0
  60. package/src/abi-manager/abi/thru/program/abi_manager/types.ts +7037 -0
  61. package/src/abi-manager/accounts.ts +91 -0
  62. package/src/abi-manager/constants.ts +19 -0
  63. package/src/abi-manager/derivation.ts +86 -0
  64. package/src/abi-manager/errors.ts +48 -0
  65. package/src/abi-manager/index.test.ts +136 -0
  66. package/src/abi-manager/index.ts +56 -0
  67. package/src/abi-manager/instructions.ts +573 -0
  68. package/src/abi-manager/types.ts +150 -0
  69. package/src/amm/index.test.ts +8 -2
  70. package/src/amm/index.ts +1 -1
  71. package/src/clob/abi/thru/program/clob/types.ts +6981 -3070
  72. package/src/clob/exchange-client.test.ts +592 -0
  73. package/src/clob/exchange-client.ts +953 -0
  74. package/src/clob/exchange.test.ts +18 -16
  75. package/src/clob/exchange.ts +4 -0
  76. package/src/clob/index.test.ts +134 -7
  77. package/src/clob/index.ts +303 -10
  78. package/src/clob/price.test.ts +32 -0
  79. package/src/clob/price.ts +77 -0
  80. package/src/deploy/accounts.ts +208 -0
  81. package/src/deploy/chain.ts +163 -0
  82. package/src/deploy/constants.ts +25 -0
  83. package/src/deploy/deploy.test.ts +349 -0
  84. package/src/deploy/errors.ts +72 -0
  85. package/src/deploy/index.ts +44 -0
  86. package/src/deploy/inspection.ts +146 -0
  87. package/src/deploy/seeds.ts +29 -0
  88. package/src/deploy/types.ts +178 -0
  89. package/src/deploy/uploader.test.ts +326 -0
  90. package/src/deploy/uploader.ts +558 -0
  91. package/src/deploy/validation-imports.test.ts +55 -0
  92. package/src/deploy/validation.ts +183 -0
  93. package/src/deploy/workflows.test.ts +422 -0
  94. package/src/deploy/workflows.ts +1088 -0
  95. package/src/helpers/bytes.test.ts +58 -0
  96. package/src/helpers/bytes.ts +28 -3
  97. package/src/manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
  98. package/src/manager/abi/thru/common/primitives/types.ts +2428 -0
  99. package/src/manager/abi/thru/program/manager/types.ts +3814 -0
  100. package/src/manager/accounts.ts +44 -0
  101. package/src/manager/constants.ts +16 -0
  102. package/src/manager/derivation.ts +32 -0
  103. package/src/manager/errors.ts +47 -0
  104. package/src/manager/index.test.ts +108 -0
  105. package/src/manager/index.ts +68 -0
  106. package/src/manager/instructions.ts +281 -0
  107. package/src/manager/types.ts +95 -0
  108. package/src/manager/validation.ts +35 -0
  109. package/src/uploader/abi/thru/common/primitives/types.ts +2428 -0
  110. package/src/uploader/abi/thru/program/uploader/types.ts +3022 -0
  111. package/src/uploader/accounts.ts +38 -0
  112. package/src/uploader/constants.ts +14 -0
  113. package/src/uploader/derivation.ts +34 -0
  114. package/src/uploader/errors.ts +25 -0
  115. package/src/uploader/index.test.ts +107 -0
  116. package/src/uploader/index.ts +34 -0
  117. package/src/uploader/instructions.ts +163 -0
  118. package/src/uploader/types.ts +67 -0
  119. package/src/utils/helpers.ts +121 -0
  120. package/tsup.config.ts +4 -0
  121. package/dist/chunk-P5OABVJI.js +0 -28
  122. package/dist/chunk-P5OABVJI.js.map +0 -1
@@ -0,0 +1,4351 @@
1
+ import { systemProgramPubkey, pubkeyBytes, padSeed, accountData, pubkeyAddress, exactBytes, assertU32, assertU16, normalizeSeed, accountIndex } from './chunk-YX7BLFQZ.js';
2
+ import { encodeAddress } from '@thru/sdk/helpers';
3
+ import { deriveProgramAddress } from '@thru/sdk';
4
+
5
+ var UPLOADER_PROGRAM_PUBKEY = systemProgramPubkey(2);
6
+ var UPLOADER_PROGRAM_ADDRESS = encodeAddress(UPLOADER_PROGRAM_PUBKEY);
7
+ var UPLOADER_META_SIZE = 65;
8
+ var UPLOADER_STATE_OPEN = 1;
9
+ var UPLOADER_STATE_FINALIZED = 2;
10
+ var UPLOADER_DEFAULT_CHUNK_SIZE = 30720;
11
+ var UPLOADER_MIN_CHUNK_SIZE = 1024;
12
+ var UPLOADER_MAX_CHUNK_SIZE = 31e3;
13
+ function deriveUploadAddresses(seed, uploaderProgramAddress = UPLOADER_PROGRAM_ADDRESS) {
14
+ const uploader = pubkeyBytes(
15
+ uploaderProgramAddress,
16
+ "uploader program address"
17
+ );
18
+ const meta = deriveProgramAddress({
19
+ programAddress: uploader,
20
+ seed: padSeed(seed),
21
+ ephemeral: true
22
+ });
23
+ const buffer = deriveProgramAddress({
24
+ programAddress: uploader,
25
+ seed: meta.bytes,
26
+ ephemeral: true
27
+ });
28
+ return {
29
+ metaAccountAddress: meta.address,
30
+ metaAccountBytes: meta.bytes,
31
+ bufferAccountAddress: buffer.address,
32
+ bufferAccountBytes: buffer.bytes
33
+ };
34
+ }
35
+
36
+ // src/uploader/abi/thru/common/primitives/types.ts
37
+ var __tnWarnings = /* @__PURE__ */ new Set();
38
+ var __tnHasNativeBigInt = typeof BigInt === "function";
39
+ var __tnHasBigIntDataView = typeof DataView !== "undefined" && typeof DataView.prototype.getBigInt64 === "function" && typeof DataView.prototype.getBigUint64 === "function" && typeof DataView.prototype.setBigInt64 === "function" && typeof DataView.prototype.setBigUint64 === "function";
40
+ var __tnConsole = typeof globalThis !== "undefined" ? globalThis.console : void 0;
41
+ function __tnLogWarn(message) {
42
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
43
+ __tnConsole.warn(message);
44
+ }
45
+ }
46
+ function __tnWarnOnce(message) {
47
+ if (!__tnWarnings.has(message)) {
48
+ __tnWarnings.add(message);
49
+ __tnLogWarn(message);
50
+ }
51
+ }
52
+ function __tnResolveBuilderInput(input, context) {
53
+ if (input instanceof Uint8Array) {
54
+ return new Uint8Array(input);
55
+ }
56
+ if (input && typeof input.build === "function") {
57
+ const built = input.build();
58
+ if (!(built instanceof Uint8Array)) {
59
+ throw new Error(`${context}: builder did not return Uint8Array`);
60
+ }
61
+ return new Uint8Array(built);
62
+ }
63
+ throw new Error(`${context}: expected Uint8Array or builder`);
64
+ }
65
+ function __tnCreateFamWriter(parent, fieldName, assign) {
66
+ let hasWritten = false;
67
+ return {
68
+ write(payload) {
69
+ const bytes = __tnResolveBuilderInput(
70
+ payload,
71
+ `flexible array '${fieldName}'`
72
+ );
73
+ const copy = new Uint8Array(bytes);
74
+ assign(copy);
75
+ hasWritten = true;
76
+ return {
77
+ finish() {
78
+ return parent;
79
+ }
80
+ };
81
+ },
82
+ finish() {
83
+ if (!hasWritten) {
84
+ throw new Error(
85
+ `flexible array '${fieldName}' requires write() before finish()`
86
+ );
87
+ }
88
+ return parent;
89
+ }
90
+ };
91
+ }
92
+ var __tnMask32 = __tnHasNativeBigInt ? (BigInt(1) << BigInt(32)) - BigInt(1) : 4294967295;
93
+ var __tnSignBit32 = __tnHasNativeBigInt ? BigInt(1) << BigInt(31) : 2147483648;
94
+ function __tnToBigInt(value) {
95
+ if (__tnHasNativeBigInt) {
96
+ return typeof value === "bigint" ? value : BigInt(value);
97
+ }
98
+ if (typeof value === "bigint") return value;
99
+ if (!Number.isFinite(value)) {
100
+ throw new Error("IR runtime received non-finite numeric input");
101
+ }
102
+ if (!Number.isSafeInteger(value)) {
103
+ __tnWarnOnce(
104
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
105
+ );
106
+ }
107
+ return value;
108
+ }
109
+ function __tnBigIntToNumber(value, context) {
110
+ if (__tnHasNativeBigInt) {
111
+ const converted = Number(value);
112
+ if (!Number.isFinite(converted)) {
113
+ throw new Error(`${context} overflowed Number range`);
114
+ }
115
+ return converted;
116
+ }
117
+ return value;
118
+ }
119
+ function __tnBigIntEquals(lhs, rhs) {
120
+ if (__tnHasNativeBigInt) return lhs === rhs;
121
+ return lhs === rhs;
122
+ }
123
+ function __tnBigIntGreaterThan(lhs, rhs) {
124
+ if (__tnHasNativeBigInt) return lhs > rhs;
125
+ return lhs > rhs;
126
+ }
127
+ function __tnRaiseIrError(code, message) {
128
+ const err = new Error(message);
129
+ err.code = code;
130
+ throw err;
131
+ }
132
+ function __tnCheckedAdd(lhs, rhs) {
133
+ if (__tnHasNativeBigInt) {
134
+ const result = lhs + rhs;
135
+ if (result < BigInt(0)) {
136
+ __tnRaiseIrError(
137
+ "tn.ir.overflow",
138
+ "IR runtime detected negative size via addition"
139
+ );
140
+ }
141
+ return result;
142
+ }
143
+ const left = lhs;
144
+ const right = rhs;
145
+ const sum = left + right;
146
+ if (sum < 0 || !Number.isFinite(sum)) {
147
+ __tnRaiseIrError(
148
+ "tn.ir.overflow",
149
+ "IR runtime detected invalid addition result"
150
+ );
151
+ }
152
+ if (!Number.isSafeInteger(sum)) {
153
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
154
+ }
155
+ return sum;
156
+ }
157
+ function __tnCheckedSub(lhs, rhs) {
158
+ if (__tnHasNativeBigInt) {
159
+ const result = lhs - rhs;
160
+ if (result < BigInt(0)) {
161
+ __tnRaiseIrError(
162
+ "tn.ir.overflow",
163
+ "IR runtime detected negative size via subtraction"
164
+ );
165
+ }
166
+ return result;
167
+ }
168
+ const left = lhs;
169
+ const right = rhs;
170
+ const diff = left - right;
171
+ if (diff < 0 || !Number.isFinite(diff)) {
172
+ __tnRaiseIrError(
173
+ "tn.ir.overflow",
174
+ "IR runtime detected invalid subtraction result"
175
+ );
176
+ }
177
+ if (!Number.isSafeInteger(diff)) {
178
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt subtraction");
179
+ }
180
+ return diff;
181
+ }
182
+ function __tnCheckedMul(lhs, rhs) {
183
+ if (__tnHasNativeBigInt) {
184
+ const result = lhs * rhs;
185
+ if (result < BigInt(0)) {
186
+ __tnRaiseIrError(
187
+ "tn.ir.overflow",
188
+ "IR runtime detected negative size via multiplication"
189
+ );
190
+ }
191
+ return result;
192
+ }
193
+ const left = lhs;
194
+ const right = rhs;
195
+ const product = left * right;
196
+ if (product < 0 || !Number.isFinite(product)) {
197
+ __tnRaiseIrError(
198
+ "tn.ir.overflow",
199
+ "IR runtime detected invalid multiplication result"
200
+ );
201
+ }
202
+ if (!Number.isSafeInteger(product)) {
203
+ __tnWarnOnce(
204
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
205
+ );
206
+ }
207
+ return product;
208
+ }
209
+ function __tnCheckedDiv(lhs, rhs) {
210
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
211
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime division by zero");
212
+ }
213
+ if (__tnHasNativeBigInt) return lhs / rhs;
214
+ const quotient = Math.floor(lhs / rhs);
215
+ return quotient;
216
+ }
217
+ function __tnCheckedMod(lhs, rhs) {
218
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
219
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime modulo by zero");
220
+ }
221
+ if (__tnHasNativeBigInt) return lhs % rhs;
222
+ return lhs % rhs;
223
+ }
224
+ function __tnBitwise(lhs, rhs, op) {
225
+ if (__tnHasNativeBigInt) {
226
+ if (op === "and") return lhs & rhs;
227
+ if (op === "or") return lhs | rhs;
228
+ return lhs ^ rhs;
229
+ }
230
+ const left = lhs;
231
+ const right = rhs;
232
+ const maxU32 = 4294967295;
233
+ if (!Number.isInteger(left) || !Number.isInteger(right) || left < 0 || right < 0 || left > maxU32 || right > maxU32) {
234
+ __tnRaiseIrError(
235
+ "tn.ir.overflow",
236
+ "IR runtime bitwise operation requires BigInt for values outside u32 range"
237
+ );
238
+ }
239
+ const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
240
+ return result >>> 0;
241
+ }
242
+ function __tnCheckedShift(lhs, rhs, direction) {
243
+ const amount = __tnBigIntToNumber(rhs, "IR shift amount");
244
+ if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
245
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime invalid shift amount");
246
+ }
247
+ if (__tnHasNativeBigInt) {
248
+ const shift = BigInt(amount);
249
+ return direction === "left" ? lhs << shift : lhs >> shift;
250
+ }
251
+ const value = lhs;
252
+ const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
253
+ if (!Number.isSafeInteger(result)) {
254
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt shift");
255
+ }
256
+ return result;
257
+ }
258
+ function __tnAlign(value, alignment) {
259
+ if (alignment <= 1) return value;
260
+ const alignBig = __tnToBigInt(alignment);
261
+ if (__tnHasNativeBigInt) {
262
+ const remainder2 = value % alignBig;
263
+ if (__tnBigIntEquals(remainder2, __tnToBigInt(0))) {
264
+ return value;
265
+ }
266
+ const delta = alignBig - remainder2;
267
+ return __tnCheckedAdd(value, delta);
268
+ }
269
+ const current = __tnBigIntToNumber(value, "IR align");
270
+ const alignNum = alignment >>> 0;
271
+ const remainder = current % alignNum;
272
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
273
+ return __tnToBigInt(next);
274
+ }
275
+ function __tnSplitUint64(value) {
276
+ if (__tnHasNativeBigInt) {
277
+ const low2 = Number(value & __tnMask32);
278
+ const high2 = Number(value >> BigInt(32) & __tnMask32);
279
+ return { high: high2, low: low2 };
280
+ }
281
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
282
+ const low = num >>> 0;
283
+ const high = Math.floor(num / 4294967296) >>> 0;
284
+ return { high, low };
285
+ }
286
+ function __tnSplitInt64(value) {
287
+ if (__tnHasNativeBigInt) {
288
+ const low2 = Number(value & __tnMask32);
289
+ let high2 = Number(value >> BigInt(32) & __tnMask32);
290
+ if ((BigInt(high2) & __tnSignBit32) !== BigInt(0)) {
291
+ high2 -= 4294967296;
292
+ }
293
+ return { high: high2, low: low2 };
294
+ }
295
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
296
+ const low = num >>> 0;
297
+ const high = Math.floor(num / 4294967296);
298
+ return { high, low };
299
+ }
300
+ function __tnPolyfillReadUint64(view, offset, littleEndian) {
301
+ const low = littleEndian ? view.getUint32(offset, true) : view.getUint32(offset + 4, false);
302
+ const high = littleEndian ? view.getUint32(offset + 4, true) : view.getUint32(offset, false);
303
+ if (__tnHasNativeBigInt) {
304
+ return BigInt(high) << BigInt(32) | BigInt(low);
305
+ }
306
+ const value = high * 4294967296 + low;
307
+ if (!Number.isSafeInteger(value)) {
308
+ __tnWarnOnce(
309
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
310
+ );
311
+ }
312
+ return value;
313
+ }
314
+ function __tnPolyfillReadInt64(view, offset, littleEndian) {
315
+ const low = littleEndian ? view.getUint32(offset, true) : view.getUint32(offset + 4, false);
316
+ const high = littleEndian ? view.getInt32(offset + 4, true) : view.getInt32(offset, false);
317
+ if (__tnHasNativeBigInt) {
318
+ return BigInt(high) << BigInt(32) | BigInt(low);
319
+ }
320
+ const value = high * 4294967296 + low;
321
+ if (!Number.isSafeInteger(value)) {
322
+ __tnWarnOnce(
323
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
324
+ );
325
+ }
326
+ return value;
327
+ }
328
+ function __tnPolyfillWriteUint64(view, offset, value, littleEndian) {
329
+ const parts = __tnSplitUint64(value);
330
+ if (littleEndian) {
331
+ view.setUint32(offset, parts.low, true);
332
+ view.setUint32(offset + 4, parts.high, true);
333
+ } else {
334
+ view.setUint32(offset, parts.high, false);
335
+ view.setUint32(offset + 4, parts.low, false);
336
+ }
337
+ }
338
+ function __tnPolyfillWriteInt64(view, offset, value, littleEndian) {
339
+ const parts = __tnSplitInt64(value);
340
+ if (littleEndian) {
341
+ view.setUint32(offset, parts.low >>> 0, true);
342
+ view.setInt32(offset + 4, parts.high | 0, true);
343
+ } else {
344
+ view.setInt32(offset, parts.high | 0, false);
345
+ view.setUint32(offset + 4, parts.low >>> 0, false);
346
+ }
347
+ }
348
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
349
+ const proto = DataView.prototype;
350
+ if (typeof proto.getBigUint64 !== "function") {
351
+ proto.getBigUint64 = function(offset, littleEndian) {
352
+ __tnWarnOnce(
353
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
354
+ );
355
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
356
+ };
357
+ }
358
+ if (typeof proto.getBigInt64 !== "function") {
359
+ proto.getBigInt64 = function(offset, littleEndian) {
360
+ __tnWarnOnce(
361
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
362
+ );
363
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
364
+ };
365
+ }
366
+ if (typeof proto.setBigUint64 !== "function") {
367
+ proto.setBigUint64 = function(offset, value, littleEndian) {
368
+ __tnWarnOnce(
369
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
370
+ );
371
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
372
+ };
373
+ }
374
+ if (typeof proto.setBigInt64 !== "function") {
375
+ proto.setBigInt64 = function(offset, value, littleEndian) {
376
+ __tnWarnOnce(
377
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
378
+ );
379
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
380
+ };
381
+ }
382
+ if (!__tnHasNativeBigInt) {
383
+ __tnWarnOnce(
384
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
385
+ );
386
+ }
387
+ }
388
+ var __tnFootprintRegistry = {};
389
+ var __tnValidateRegistry = {};
390
+ var __tnDynamicValidateRegistry = {};
391
+ function __tnRegisterFootprint(typeName, fn) {
392
+ __tnFootprintRegistry[typeName] = fn;
393
+ }
394
+ function __tnRegisterValidate(typeName, fn) {
395
+ __tnValidateRegistry[typeName] = fn;
396
+ }
397
+ function __tnRegisterDynamicValidate(typeName, fn) {
398
+ __tnDynamicValidateRegistry[typeName] = fn;
399
+ }
400
+ function __tnInvokeFootprint(typeName, params) {
401
+ const fn = __tnFootprintRegistry[typeName];
402
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
403
+ return fn(params);
404
+ }
405
+ function __tnInvokeValidate(typeName, buffer, params) {
406
+ const fn = __tnValidateRegistry[typeName];
407
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
408
+ return fn(buffer, params);
409
+ }
410
+ function __tnInvokeDynamicValidate(typeName, buffer) {
411
+ const fn = __tnDynamicValidateRegistry[typeName];
412
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
413
+ return fn(buffer);
414
+ }
415
+ function __tnEvalFootprint(node, ctx) {
416
+ return __tnEvalIrNode(node, ctx, __tnToBigInt(0));
417
+ }
418
+ function __tnTryEvalIr(node, ctx) {
419
+ try {
420
+ return { ok: true, value: __tnEvalIrNode(node, ctx, __tnToBigInt(0)) };
421
+ } catch (err) {
422
+ return { ok: false, code: __tnNormalizeIrError(err) };
423
+ }
424
+ }
425
+ function __tnIsEvalError(result) {
426
+ return result.ok === false;
427
+ }
428
+ function __tnValidateIrTree(ir, buffer, params) {
429
+ const evalResult = __tnTryEvalIr(ir.root, {
430
+ params,
431
+ buffer,
432
+ typeName: ir.typeName
433
+ });
434
+ if (__tnIsEvalError(evalResult)) {
435
+ return { ok: false, code: evalResult.code };
436
+ }
437
+ const required = evalResult.value;
438
+ const available = __tnToBigInt(buffer.length);
439
+ if (__tnBigIntGreaterThan(required, available)) {
440
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
441
+ }
442
+ return { ok: true, consumed: required };
443
+ }
444
+ function __tnEvalIrNode(node, ctx, baseOffset) {
445
+ switch (node.op) {
446
+ case "zero":
447
+ return __tnToBigInt(0);
448
+ case "const":
449
+ return node.value;
450
+ case "field": {
451
+ if (node.param === "__buffer_size" && ctx.buffer) {
452
+ return __tnToBigInt(ctx.buffer.length);
453
+ }
454
+ const val = ctx.params[node.param];
455
+ if (val === void 0) {
456
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
457
+ __tnRaiseIrError(
458
+ "tn.ir.missing_param",
459
+ `${prefix}Missing IR parameter '${node.param}'`
460
+ );
461
+ }
462
+ return val;
463
+ }
464
+ case "add": {
465
+ const left = __tnEvalIrNode(node.left, ctx, baseOffset);
466
+ const right = __tnEvalIrNode(
467
+ node.right,
468
+ ctx,
469
+ __tnCheckedAdd(baseOffset, left)
470
+ );
471
+ return __tnCheckedAdd(left, right);
472
+ }
473
+ case "sub":
474
+ return __tnCheckedSub(
475
+ __tnEvalIrNode(node.left, ctx, baseOffset),
476
+ __tnEvalIrNode(node.right, ctx, baseOffset)
477
+ );
478
+ case "mul":
479
+ return __tnCheckedMul(
480
+ __tnEvalIrNode(node.left, ctx, baseOffset),
481
+ __tnEvalIrNode(node.right, ctx, baseOffset)
482
+ );
483
+ case "div":
484
+ return __tnCheckedDiv(
485
+ __tnEvalIrNode(node.left, ctx, baseOffset),
486
+ __tnEvalIrNode(node.right, ctx, baseOffset)
487
+ );
488
+ case "mod":
489
+ return __tnCheckedMod(
490
+ __tnEvalIrNode(node.left, ctx, baseOffset),
491
+ __tnEvalIrNode(node.right, ctx, baseOffset)
492
+ );
493
+ case "bitAnd":
494
+ return __tnBitwise(
495
+ __tnEvalIrNode(node.left, ctx, baseOffset),
496
+ __tnEvalIrNode(node.right, ctx, baseOffset),
497
+ "and"
498
+ );
499
+ case "bitOr":
500
+ return __tnBitwise(
501
+ __tnEvalIrNode(node.left, ctx, baseOffset),
502
+ __tnEvalIrNode(node.right, ctx, baseOffset),
503
+ "or"
504
+ );
505
+ case "bitXor":
506
+ return __tnBitwise(
507
+ __tnEvalIrNode(node.left, ctx, baseOffset),
508
+ __tnEvalIrNode(node.right, ctx, baseOffset),
509
+ "xor"
510
+ );
511
+ case "leftShift":
512
+ return __tnCheckedShift(
513
+ __tnEvalIrNode(node.left, ctx, baseOffset),
514
+ __tnEvalIrNode(node.right, ctx, baseOffset),
515
+ "left"
516
+ );
517
+ case "rightShift":
518
+ return __tnCheckedShift(
519
+ __tnEvalIrNode(node.left, ctx, baseOffset),
520
+ __tnEvalIrNode(node.right, ctx, baseOffset),
521
+ "right"
522
+ );
523
+ case "align":
524
+ return __tnAlign(__tnEvalIrNode(node.node, ctx, baseOffset), node.alignment);
525
+ case "switch": {
526
+ const tagVal = ctx.params[node.tag];
527
+ if (tagVal === void 0) {
528
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
529
+ __tnRaiseIrError(
530
+ "tn.ir.missing_param",
531
+ `${prefix}Missing IR switch tag '${node.tag}'`
532
+ );
533
+ }
534
+ const tagNumber = Number(tagVal);
535
+ for (const caseNode of node.cases) {
536
+ if (caseNode.value === tagNumber) {
537
+ return __tnEvalIrNode(caseNode.node, ctx, baseOffset);
538
+ }
539
+ }
540
+ if (node.default) return __tnEvalIrNode(node.default, ctx, baseOffset);
541
+ __tnRaiseIrError(
542
+ "tn.ir.invalid_tag",
543
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
544
+ );
545
+ }
546
+ case "call": {
547
+ const nestedParams = /* @__PURE__ */ Object.create(null);
548
+ for (const arg of node.args) {
549
+ const val = ctx.params[arg.source];
550
+ if (val === void 0) {
551
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
552
+ __tnRaiseIrError(
553
+ "tn.ir.missing_param",
554
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
555
+ );
556
+ }
557
+ nestedParams[arg.name] = val;
558
+ }
559
+ if (ctx.buffer) {
560
+ const nestedOffset = __tnBigIntToNumber(baseOffset, "IR nested offset");
561
+ const nestedResult = __tnInvokeValidate(
562
+ node.typeName,
563
+ ctx.buffer.subarray(nestedOffset),
564
+ nestedParams
565
+ );
566
+ if (!nestedResult.ok) {
567
+ const nestedCode = nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
568
+ const prefixed = nestedCode.startsWith("tn.") ? nestedCode : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
569
+ __tnRaiseIrError(
570
+ prefixed,
571
+ `Nested validator ${node.typeName} failed`
572
+ );
573
+ }
574
+ if (nestedResult.consumed !== void 0) {
575
+ return nestedResult.consumed;
576
+ }
577
+ }
578
+ return __tnInvokeFootprint(node.typeName, nestedParams);
579
+ }
580
+ case "sumOverArray": {
581
+ if (!ctx.buffer) {
582
+ __tnRaiseIrError(
583
+ "tn.ir.missing_buffer",
584
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
585
+ );
586
+ }
587
+ const count = __tnBigIntToNumber(
588
+ __tnEvalIrNode(node.count, ctx, baseOffset),
589
+ `Jagged array '${node.fieldName}' count`
590
+ );
591
+ let cursor = __tnBigIntToNumber(baseOffset, "IR jagged array offset");
592
+ let total = __tnToBigInt(0);
593
+ for (let i = 0; i < count; i++) {
594
+ const result = __tnInvokeDynamicValidate(
595
+ node.elementTypeName,
596
+ ctx.buffer.subarray(cursor)
597
+ );
598
+ if (!result.ok || result.consumed === void 0) {
599
+ const code = result.code ?? "tn.ir.runtime_error";
600
+ __tnRaiseIrError(
601
+ code,
602
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
603
+ );
604
+ }
605
+ cursor += __tnBigIntToNumber(result.consumed, "IR jagged element size");
606
+ total = __tnCheckedAdd(total, result.consumed);
607
+ }
608
+ return total;
609
+ }
610
+ default:
611
+ __tnRaiseIrError(
612
+ "tn.ir.runtime_error",
613
+ `Unsupported IR node ${node.op}`
614
+ );
615
+ }
616
+ }
617
+ function __tnNormalizeIrError(err) {
618
+ if (err && typeof err === "object" && "code" in err) {
619
+ const maybeCode = err.code;
620
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
621
+ return maybeCode;
622
+ }
623
+ }
624
+ const message = err && typeof err === "object" && "message" in err ? String(err.message ?? "") : typeof err === "string" ? err : "";
625
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
626
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
627
+ if (message.includes("invalid") || message.includes("overflow") || message.includes("negative size")) {
628
+ return "tn.ir.overflow";
629
+ }
630
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
631
+ return "tn.ir.runtime_error";
632
+ }
633
+ var __tn_ir_Date = {
634
+ typeName: "Date",
635
+ root: { op: "const", value: 6n }
636
+ };
637
+ var Date = class _Date {
638
+ constructor(buffer) {
639
+ this.buffer = buffer;
640
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
641
+ }
642
+ static __tnCreateView(buffer, opts) {
643
+ if (!buffer || buffer.length === void 0) throw new Error("Date.__tnCreateView requires a Uint8Array");
644
+ return new _Date(new Uint8Array(buffer));
645
+ }
646
+ static builder() {
647
+ return new DateBuilder();
648
+ }
649
+ static fromBuilder(builder) {
650
+ const buffer = builder.build();
651
+ return _Date.from_array(buffer);
652
+ }
653
+ get_year() {
654
+ const offset = 0;
655
+ return this.view.getInt32(offset, true);
656
+ }
657
+ set_year(value) {
658
+ const offset = 0;
659
+ this.view.setInt32(offset, value, true);
660
+ }
661
+ get year() {
662
+ return this.get_year();
663
+ }
664
+ set year(value) {
665
+ this.set_year(value);
666
+ }
667
+ get_month() {
668
+ const offset = 4;
669
+ return this.view.getUint8(offset);
670
+ }
671
+ set_month(value) {
672
+ const offset = 4;
673
+ this.view.setUint8(offset, value);
674
+ }
675
+ get month() {
676
+ return this.get_month();
677
+ }
678
+ set month(value) {
679
+ this.set_month(value);
680
+ }
681
+ get_day() {
682
+ const offset = 5;
683
+ return this.view.getUint8(offset);
684
+ }
685
+ set_day(value) {
686
+ const offset = 5;
687
+ this.view.setUint8(offset, value);
688
+ }
689
+ get day() {
690
+ return this.get_day();
691
+ }
692
+ set day(value) {
693
+ this.set_day(value);
694
+ }
695
+ static __tnFootprintInternal(__tnParams) {
696
+ return __tnEvalFootprint(__tn_ir_Date.root, { params: __tnParams });
697
+ }
698
+ static __tnValidateInternal(buffer, __tnParams) {
699
+ return __tnValidateIrTree(__tn_ir_Date, buffer, __tnParams);
700
+ }
701
+ static __tnInvokeFootprint(__tnParams) {
702
+ return this.__tnFootprintInternal(__tnParams);
703
+ }
704
+ static __tnInvokeValidate(buffer, __tnParams) {
705
+ return this.__tnValidateInternal(buffer, __tnParams);
706
+ }
707
+ static footprintIr() {
708
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
709
+ }
710
+ static footprint() {
711
+ const irResult = this.footprintIr();
712
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
713
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
714
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Date");
715
+ }
716
+ return __tnBigIntToNumber(irResult, "Date::footprint");
717
+ }
718
+ static validate(buffer, _opts) {
719
+ if (buffer.length < 6) return { ok: false, code: "tn.buffer_too_small", consumed: 6 };
720
+ return { ok: true, consumed: 6 };
721
+ }
722
+ static new(year, month, day) {
723
+ const buffer = new Uint8Array(6);
724
+ const view = new DataView(buffer.buffer);
725
+ view.setInt32(0, year, true);
726
+ view.setUint8(4, month);
727
+ view.setUint8(5, day);
728
+ return new _Date(buffer);
729
+ }
730
+ static from_array(buffer) {
731
+ if (!buffer || buffer.length === void 0) {
732
+ return null;
733
+ }
734
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
735
+ const validation = this.validate(buffer);
736
+ if (!validation.ok) {
737
+ return null;
738
+ }
739
+ return new _Date(buffer);
740
+ }
741
+ };
742
+ var DateBuilder = class {
743
+ constructor() {
744
+ this.buffer = new Uint8Array(6);
745
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
746
+ }
747
+ set_year(value) {
748
+ this.view.setInt32(0, value, true);
749
+ return this;
750
+ }
751
+ set_month(value) {
752
+ this.view.setUint8(4, value);
753
+ return this;
754
+ }
755
+ set_day(value) {
756
+ this.view.setUint8(5, value);
757
+ return this;
758
+ }
759
+ build() {
760
+ return this.buffer.slice();
761
+ }
762
+ buildInto(target, offset = 0) {
763
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
764
+ target.set(this.buffer, offset);
765
+ return target;
766
+ }
767
+ finish() {
768
+ const view = Date.from_array(this.buffer.slice());
769
+ if (!view) throw new Error("failed to build Date");
770
+ return view;
771
+ }
772
+ };
773
+ __tnRegisterFootprint("Date", (params) => Date.__tnInvokeFootprint(params));
774
+ __tnRegisterValidate("Date", (buffer, params) => Date.__tnInvokeValidate(buffer, params));
775
+ __tnRegisterDynamicValidate("Date", (buffer) => {
776
+ const result = Date.validate(buffer);
777
+ const params = result.params;
778
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
779
+ });
780
+ var __tn_ir_Duration = {
781
+ typeName: "Duration",
782
+ root: { op: "const", value: 12n }
783
+ };
784
+ var Duration = class _Duration {
785
+ constructor(buffer) {
786
+ this.buffer = buffer;
787
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
788
+ }
789
+ static __tnCreateView(buffer, opts) {
790
+ if (!buffer || buffer.length === void 0) throw new Error("Duration.__tnCreateView requires a Uint8Array");
791
+ return new _Duration(new Uint8Array(buffer));
792
+ }
793
+ static builder() {
794
+ return new DurationBuilder();
795
+ }
796
+ static fromBuilder(builder) {
797
+ const buffer = builder.build();
798
+ return _Duration.from_array(buffer);
799
+ }
800
+ get_seconds() {
801
+ const offset = 0;
802
+ return this.view.getBigInt64(offset, true);
803
+ }
804
+ set_seconds(value) {
805
+ const offset = 0;
806
+ this.view.setBigInt64(offset, value, true);
807
+ }
808
+ get seconds() {
809
+ return this.get_seconds();
810
+ }
811
+ set seconds(value) {
812
+ this.set_seconds(value);
813
+ }
814
+ get_nanos() {
815
+ const offset = 8;
816
+ return this.view.getInt32(offset, true);
817
+ }
818
+ set_nanos(value) {
819
+ const offset = 8;
820
+ this.view.setInt32(offset, value, true);
821
+ }
822
+ get nanos() {
823
+ return this.get_nanos();
824
+ }
825
+ set nanos(value) {
826
+ this.set_nanos(value);
827
+ }
828
+ static __tnFootprintInternal(__tnParams) {
829
+ return __tnEvalFootprint(__tn_ir_Duration.root, { params: __tnParams });
830
+ }
831
+ static __tnValidateInternal(buffer, __tnParams) {
832
+ return __tnValidateIrTree(__tn_ir_Duration, buffer, __tnParams);
833
+ }
834
+ static __tnInvokeFootprint(__tnParams) {
835
+ return this.__tnFootprintInternal(__tnParams);
836
+ }
837
+ static __tnInvokeValidate(buffer, __tnParams) {
838
+ return this.__tnValidateInternal(buffer, __tnParams);
839
+ }
840
+ static footprintIr() {
841
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
842
+ }
843
+ static footprint() {
844
+ const irResult = this.footprintIr();
845
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
846
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
847
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Duration");
848
+ }
849
+ return __tnBigIntToNumber(irResult, "Duration::footprint");
850
+ }
851
+ static validate(buffer, _opts) {
852
+ if (buffer.length < 12) return { ok: false, code: "tn.buffer_too_small", consumed: 12 };
853
+ return { ok: true, consumed: 12 };
854
+ }
855
+ static new(seconds, nanos) {
856
+ const buffer = new Uint8Array(12);
857
+ const view = new DataView(buffer.buffer);
858
+ view.setBigInt64(0, seconds, true);
859
+ view.setInt32(8, nanos, true);
860
+ return new _Duration(buffer);
861
+ }
862
+ static from_array(buffer) {
863
+ if (!buffer || buffer.length === void 0) {
864
+ return null;
865
+ }
866
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
867
+ const validation = this.validate(buffer);
868
+ if (!validation.ok) {
869
+ return null;
870
+ }
871
+ return new _Duration(buffer);
872
+ }
873
+ };
874
+ var DurationBuilder = class {
875
+ constructor() {
876
+ this.buffer = new Uint8Array(12);
877
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
878
+ }
879
+ set_seconds(value) {
880
+ const cast = __tnToBigInt(value);
881
+ this.view.setBigInt64(0, cast, true);
882
+ return this;
883
+ }
884
+ set_nanos(value) {
885
+ this.view.setInt32(8, value, true);
886
+ return this;
887
+ }
888
+ build() {
889
+ return this.buffer.slice();
890
+ }
891
+ buildInto(target, offset = 0) {
892
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
893
+ target.set(this.buffer, offset);
894
+ return target;
895
+ }
896
+ finish() {
897
+ const view = Duration.from_array(this.buffer.slice());
898
+ if (!view) throw new Error("failed to build Duration");
899
+ return view;
900
+ }
901
+ };
902
+ __tnRegisterFootprint("Duration", (params) => Duration.__tnInvokeFootprint(params));
903
+ __tnRegisterValidate("Duration", (buffer, params) => Duration.__tnInvokeValidate(buffer, params));
904
+ __tnRegisterDynamicValidate("Duration", (buffer) => {
905
+ const result = Duration.validate(buffer);
906
+ const params = result.params;
907
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
908
+ });
909
+ var __tn_ir_FixedPoint = {
910
+ typeName: "FixedPoint",
911
+ root: { op: "const", value: 9n }
912
+ };
913
+ var FixedPoint = class _FixedPoint {
914
+ constructor(buffer) {
915
+ this.buffer = buffer;
916
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
917
+ }
918
+ static __tnCreateView(buffer, opts) {
919
+ if (!buffer || buffer.length === void 0) throw new Error("FixedPoint.__tnCreateView requires a Uint8Array");
920
+ return new _FixedPoint(new Uint8Array(buffer));
921
+ }
922
+ static builder() {
923
+ return new FixedPointBuilder();
924
+ }
925
+ static fromBuilder(builder) {
926
+ const buffer = builder.build();
927
+ return _FixedPoint.from_array(buffer);
928
+ }
929
+ get_mantissa() {
930
+ const offset = 0;
931
+ return this.view.getBigInt64(offset, true);
932
+ }
933
+ set_mantissa(value) {
934
+ const offset = 0;
935
+ this.view.setBigInt64(offset, value, true);
936
+ }
937
+ get mantissa() {
938
+ return this.get_mantissa();
939
+ }
940
+ set mantissa(value) {
941
+ this.set_mantissa(value);
942
+ }
943
+ get_scale() {
944
+ const offset = 8;
945
+ return this.view.getUint8(offset);
946
+ }
947
+ set_scale(value) {
948
+ const offset = 8;
949
+ this.view.setUint8(offset, value);
950
+ }
951
+ get scale() {
952
+ return this.get_scale();
953
+ }
954
+ set scale(value) {
955
+ this.set_scale(value);
956
+ }
957
+ static __tnFootprintInternal(__tnParams) {
958
+ return __tnEvalFootprint(__tn_ir_FixedPoint.root, { params: __tnParams });
959
+ }
960
+ static __tnValidateInternal(buffer, __tnParams) {
961
+ return __tnValidateIrTree(__tn_ir_FixedPoint, buffer, __tnParams);
962
+ }
963
+ static __tnInvokeFootprint(__tnParams) {
964
+ return this.__tnFootprintInternal(__tnParams);
965
+ }
966
+ static __tnInvokeValidate(buffer, __tnParams) {
967
+ return this.__tnValidateInternal(buffer, __tnParams);
968
+ }
969
+ static footprintIr() {
970
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
971
+ }
972
+ static footprint() {
973
+ const irResult = this.footprintIr();
974
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
975
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
976
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for FixedPoint");
977
+ }
978
+ return __tnBigIntToNumber(irResult, "FixedPoint::footprint");
979
+ }
980
+ static validate(buffer, _opts) {
981
+ if (buffer.length < 9) return { ok: false, code: "tn.buffer_too_small", consumed: 9 };
982
+ return { ok: true, consumed: 9 };
983
+ }
984
+ static new(mantissa, scale) {
985
+ const buffer = new Uint8Array(9);
986
+ const view = new DataView(buffer.buffer);
987
+ view.setBigInt64(0, mantissa, true);
988
+ view.setUint8(8, scale);
989
+ return new _FixedPoint(buffer);
990
+ }
991
+ static from_array(buffer) {
992
+ if (!buffer || buffer.length === void 0) {
993
+ return null;
994
+ }
995
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
996
+ const validation = this.validate(buffer);
997
+ if (!validation.ok) {
998
+ return null;
999
+ }
1000
+ return new _FixedPoint(buffer);
1001
+ }
1002
+ };
1003
+ var FixedPointBuilder = class {
1004
+ constructor() {
1005
+ this.buffer = new Uint8Array(9);
1006
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1007
+ }
1008
+ set_mantissa(value) {
1009
+ const cast = __tnToBigInt(value);
1010
+ this.view.setBigInt64(0, cast, true);
1011
+ return this;
1012
+ }
1013
+ set_scale(value) {
1014
+ this.view.setUint8(8, value);
1015
+ return this;
1016
+ }
1017
+ build() {
1018
+ return this.buffer.slice();
1019
+ }
1020
+ buildInto(target, offset = 0) {
1021
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1022
+ target.set(this.buffer, offset);
1023
+ return target;
1024
+ }
1025
+ finish() {
1026
+ const view = FixedPoint.from_array(this.buffer.slice());
1027
+ if (!view) throw new Error("failed to build FixedPoint");
1028
+ return view;
1029
+ }
1030
+ };
1031
+ __tnRegisterFootprint("FixedPoint", (params) => FixedPoint.__tnInvokeFootprint(params));
1032
+ __tnRegisterValidate("FixedPoint", (buffer, params) => FixedPoint.__tnInvokeValidate(buffer, params));
1033
+ __tnRegisterDynamicValidate("FixedPoint", (buffer) => {
1034
+ const result = FixedPoint.validate(buffer);
1035
+ const params = result.params;
1036
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1037
+ });
1038
+ var __tn_ir_Hash = {
1039
+ typeName: "Hash",
1040
+ root: { op: "const", value: 32n }
1041
+ };
1042
+ var Hash = class _Hash {
1043
+ constructor(buffer) {
1044
+ this.buffer = buffer;
1045
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1046
+ }
1047
+ static __tnCreateView(buffer, opts) {
1048
+ if (!buffer || buffer.length === void 0) throw new Error("Hash.__tnCreateView requires a Uint8Array");
1049
+ return new _Hash(new Uint8Array(buffer));
1050
+ }
1051
+ static builder() {
1052
+ return new HashBuilder();
1053
+ }
1054
+ static fromBuilder(builder) {
1055
+ const buffer = builder.build();
1056
+ return _Hash.from_array(buffer);
1057
+ }
1058
+ get_bytes() {
1059
+ const offset = 0;
1060
+ const result = [];
1061
+ for (let i = 0; i < 32; i++) {
1062
+ result.push(this.view.getUint8(offset + i * 1));
1063
+ }
1064
+ return result;
1065
+ }
1066
+ set_bytes(value) {
1067
+ const offset = 0;
1068
+ if (value.length !== 32) {
1069
+ throw new Error("Array length must be 32");
1070
+ }
1071
+ for (let i = 0; i < 32; i++) {
1072
+ this.view.setUint8(offset + i * 1, value[i]);
1073
+ }
1074
+ }
1075
+ get bytes() {
1076
+ return this.get_bytes();
1077
+ }
1078
+ set bytes(value) {
1079
+ this.set_bytes(value);
1080
+ }
1081
+ static __tnFootprintInternal(__tnParams) {
1082
+ return __tnEvalFootprint(__tn_ir_Hash.root, { params: __tnParams });
1083
+ }
1084
+ static __tnValidateInternal(buffer, __tnParams) {
1085
+ return __tnValidateIrTree(__tn_ir_Hash, buffer, __tnParams);
1086
+ }
1087
+ static __tnInvokeFootprint(__tnParams) {
1088
+ return this.__tnFootprintInternal(__tnParams);
1089
+ }
1090
+ static __tnInvokeValidate(buffer, __tnParams) {
1091
+ return this.__tnValidateInternal(buffer, __tnParams);
1092
+ }
1093
+ static footprintIr() {
1094
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1095
+ }
1096
+ static footprint() {
1097
+ const irResult = this.footprintIr();
1098
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1099
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1100
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Hash");
1101
+ }
1102
+ return __tnBigIntToNumber(irResult, "Hash::footprint");
1103
+ }
1104
+ static validate(buffer, _opts) {
1105
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1106
+ return { ok: true, consumed: 32 };
1107
+ }
1108
+ static from_array(buffer) {
1109
+ if (!buffer || buffer.length === void 0) {
1110
+ return null;
1111
+ }
1112
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1113
+ const validation = this.validate(buffer);
1114
+ if (!validation.ok) {
1115
+ return null;
1116
+ }
1117
+ return new _Hash(buffer);
1118
+ }
1119
+ };
1120
+ var HashBuilder = class {
1121
+ constructor() {
1122
+ this.buffer = new Uint8Array(32);
1123
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1124
+ }
1125
+ set_bytes(values) {
1126
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1127
+ for (let i = 0; i < values.length; i++) {
1128
+ const byteOffset = 0 + i * 1;
1129
+ this.view.setUint8(byteOffset, values[i]);
1130
+ }
1131
+ return this;
1132
+ }
1133
+ build() {
1134
+ return this.buffer.slice();
1135
+ }
1136
+ buildInto(target, offset = 0) {
1137
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1138
+ target.set(this.buffer, offset);
1139
+ return target;
1140
+ }
1141
+ finish() {
1142
+ const view = Hash.from_array(this.buffer.slice());
1143
+ if (!view) throw new Error("failed to build Hash");
1144
+ return view;
1145
+ }
1146
+ };
1147
+ __tnRegisterFootprint("Hash", (params) => Hash.__tnInvokeFootprint(params));
1148
+ __tnRegisterValidate("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
1149
+ __tnRegisterDynamicValidate("Hash", (buffer) => {
1150
+ const result = Hash.validate(buffer);
1151
+ const params = result.params;
1152
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1153
+ });
1154
+ var __tn_ir_InstructionData = {
1155
+ typeName: "InstructionData",
1156
+ 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 } } } } }
1157
+ };
1158
+ var _InstructionData = class _InstructionData {
1159
+ constructor(buffer, params, fieldContext) {
1160
+ this.buffer = buffer;
1161
+ this.__tnFieldContext = null;
1162
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1163
+ this.__tnFieldContext = fieldContext ?? null;
1164
+ if (params) {
1165
+ this.__tnParams = params;
1166
+ } else {
1167
+ const derived = _InstructionData.__tnExtractParams(this.view, buffer);
1168
+ if (!derived) {
1169
+ throw new Error("InstructionData: failed to derive dynamic parameters");
1170
+ }
1171
+ this.__tnParams = derived.params;
1172
+ }
1173
+ }
1174
+ static __tnCreateView(buffer, opts) {
1175
+ if (!buffer || buffer.length === void 0) throw new Error("InstructionData.__tnCreateView requires a Uint8Array");
1176
+ let params = opts?.params ?? null;
1177
+ if (!params) {
1178
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1179
+ const derived = _InstructionData.__tnExtractParams(view, buffer);
1180
+ if (!derived) throw new Error("InstructionData.__tnCreateView: failed to derive params");
1181
+ params = derived.params;
1182
+ }
1183
+ const instance = new _InstructionData(new Uint8Array(buffer), params, opts?.fieldContext);
1184
+ return instance;
1185
+ }
1186
+ dynamicParams() {
1187
+ return this.__tnParams;
1188
+ }
1189
+ withFieldContext(context) {
1190
+ this.__tnFieldContext = context;
1191
+ return this;
1192
+ }
1193
+ __tnResolveFieldRef(path) {
1194
+ const getterName = `get_${path.replace(/[.]/g, "_")}`;
1195
+ const getter = this[getterName];
1196
+ if (typeof getter === "function") {
1197
+ const value = getter.call(this);
1198
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "InstructionData::__tnResolveFieldRef") : value;
1199
+ }
1200
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1201
+ const contextValue = this.__tnFieldContext[path];
1202
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "InstructionData::__tnResolveFieldRef") : contextValue;
1203
+ }
1204
+ throw new Error("InstructionData: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1205
+ }
1206
+ static builder() {
1207
+ return new InstructionDataBuilder();
1208
+ }
1209
+ static fromBuilder(builder) {
1210
+ const buffer = builder.build();
1211
+ const params = builder.dynamicParams();
1212
+ return _InstructionData.from_array(buffer, { params });
1213
+ }
1214
+ static __tnExtractParams(view, buffer) {
1215
+ if (buffer.length < 10) {
1216
+ return null;
1217
+ }
1218
+ const __tnParam_data_data_size = __tnToBigInt(view.getBigUint64(2, true));
1219
+ const __tnExtractedParams = _InstructionData.Params.fromValues({
1220
+ data_data_size: __tnParam_data_data_size
1221
+ });
1222
+ return { params: __tnExtractedParams, derived: null };
1223
+ }
1224
+ get_program_idx() {
1225
+ const offset = 0;
1226
+ return this.view.getUint16(offset, true);
1227
+ }
1228
+ set_program_idx(value) {
1229
+ const offset = 0;
1230
+ this.view.setUint16(offset, value, true);
1231
+ }
1232
+ get program_idx() {
1233
+ return this.get_program_idx();
1234
+ }
1235
+ set program_idx(value) {
1236
+ this.set_program_idx(value);
1237
+ }
1238
+ get_data_size() {
1239
+ const offset = 2;
1240
+ return this.view.getBigUint64(offset, true);
1241
+ }
1242
+ set_data_size(value) {
1243
+ const offset = 2;
1244
+ this.view.setBigUint64(offset, value, true);
1245
+ }
1246
+ get data_size() {
1247
+ return this.get_data_size();
1248
+ }
1249
+ set data_size(value) {
1250
+ this.set_data_size(value);
1251
+ }
1252
+ get_data_length() {
1253
+ return this.__tnResolveFieldRef("data_size");
1254
+ }
1255
+ get_data_at(index) {
1256
+ const offset = 10;
1257
+ return this.view.getUint8(offset + index * 1);
1258
+ }
1259
+ get_data() {
1260
+ const len = this.get_data_length();
1261
+ const result = [];
1262
+ for (let i = 0; i < len; i++) {
1263
+ result.push(this.get_data_at(i));
1264
+ }
1265
+ return result;
1266
+ }
1267
+ set_data_at(index, value) {
1268
+ const offset = 10;
1269
+ this.view.setUint8(offset + index * 1, value);
1270
+ }
1271
+ set_data(value) {
1272
+ const len = Math.min(this.get_data_length(), value.length);
1273
+ for (let i = 0; i < len; i++) {
1274
+ this.set_data_at(i, value[i]);
1275
+ }
1276
+ }
1277
+ get data() {
1278
+ return this.get_data();
1279
+ }
1280
+ set data(value) {
1281
+ this.set_data(value);
1282
+ }
1283
+ static __tnFootprintInternal(__tnParams) {
1284
+ return __tnEvalFootprint(__tn_ir_InstructionData.root, { params: __tnParams });
1285
+ }
1286
+ static __tnValidateInternal(buffer, __tnParams) {
1287
+ return __tnValidateIrTree(__tn_ir_InstructionData, buffer, __tnParams);
1288
+ }
1289
+ static __tnInvokeFootprint(__tnParams) {
1290
+ return this.__tnFootprintInternal(__tnParams);
1291
+ }
1292
+ static __tnInvokeValidate(buffer, __tnParams) {
1293
+ return this.__tnValidateInternal(buffer, __tnParams);
1294
+ }
1295
+ static footprintIr(data_data_size) {
1296
+ const params = _InstructionData.Params.fromValues({
1297
+ data_data_size
1298
+ });
1299
+ return this.footprintIrFromParams(params);
1300
+ }
1301
+ static __tnPackParams(params) {
1302
+ const record = /* @__PURE__ */ Object.create(null);
1303
+ record["data.data_size"] = params.data_data_size;
1304
+ return record;
1305
+ }
1306
+ static footprintIrFromParams(params) {
1307
+ const __tnParams = this.__tnPackParams(params);
1308
+ return this.__tnFootprintInternal(__tnParams);
1309
+ }
1310
+ static footprintFromParams(params) {
1311
+ const irResult = this.footprintIrFromParams(params);
1312
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1313
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for InstructionData");
1314
+ return __tnBigIntToNumber(irResult, "InstructionData::footprintFromParams");
1315
+ }
1316
+ static footprintFromValues(input) {
1317
+ const params = _InstructionData.params(input);
1318
+ return this.footprintFromParams(params);
1319
+ }
1320
+ static footprint(params) {
1321
+ return this.footprintFromParams(params);
1322
+ }
1323
+ static validate(buffer, opts) {
1324
+ if (!buffer || buffer.length === void 0) {
1325
+ return { ok: false, code: "tn.invalid_buffer" };
1326
+ }
1327
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1328
+ let params = opts?.params ?? null;
1329
+ if (!params) {
1330
+ const extracted = this.__tnExtractParams(view, buffer);
1331
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1332
+ params = extracted.params;
1333
+ }
1334
+ const __tnParamsRec = this.__tnPackParams(params);
1335
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1336
+ if (!irResult.ok) {
1337
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "InstructionData::validate") : void 0, params };
1338
+ }
1339
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "InstructionData::validate") : void 0;
1340
+ return { ok: true, consumed, params };
1341
+ }
1342
+ static from_array(buffer, opts) {
1343
+ if (!buffer || buffer.length === void 0) {
1344
+ return null;
1345
+ }
1346
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1347
+ let params = opts?.params ?? null;
1348
+ if (!params) {
1349
+ const derived = this.__tnExtractParams(view, buffer);
1350
+ if (!derived) return null;
1351
+ params = derived.params;
1352
+ }
1353
+ const validation = this.validate(buffer, { params });
1354
+ if (!validation.ok) {
1355
+ return null;
1356
+ }
1357
+ const cached = validation.params ?? params;
1358
+ const state = new _InstructionData(buffer, cached);
1359
+ return state;
1360
+ }
1361
+ };
1362
+ _InstructionData.flexibleArrayWriters = Object.freeze([
1363
+ { field: "data", method: "data", sizeField: "data_size", paramKey: "data_size", elementSize: 1 }
1364
+ ]);
1365
+ var InstructionData = _InstructionData;
1366
+ ((InstructionData2) => {
1367
+ InstructionData2.ParamKeys = Object.freeze({
1368
+ data_data_size: "data.data_size"
1369
+ });
1370
+ InstructionData2.Params = {
1371
+ fromValues(input) {
1372
+ return {
1373
+ data_data_size: __tnToBigInt(input.data_data_size)
1374
+ };
1375
+ },
1376
+ fromBuilder(source) {
1377
+ if (source.dynamicParams) {
1378
+ return source.dynamicParams();
1379
+ }
1380
+ if (source.params) {
1381
+ return source.params;
1382
+ }
1383
+ return source;
1384
+ }
1385
+ };
1386
+ function params(input) {
1387
+ return InstructionData2.Params.fromValues(input);
1388
+ }
1389
+ InstructionData2.params = params;
1390
+ })(InstructionData || (InstructionData = {}));
1391
+ var InstructionDataBuilder = class {
1392
+ constructor() {
1393
+ this.__tnCachedParams = null;
1394
+ this.__tnLastBuffer = null;
1395
+ this.__tnLastParams = null;
1396
+ this.__tnFam_data = null;
1397
+ this.__tnFam_dataCount = null;
1398
+ this.buffer = new Uint8Array(10);
1399
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1400
+ }
1401
+ __tnInvalidate() {
1402
+ this.__tnCachedParams = null;
1403
+ this.__tnLastBuffer = null;
1404
+ this.__tnLastParams = null;
1405
+ }
1406
+ set_program_idx(value) {
1407
+ this.view.setUint16(0, value, true);
1408
+ this.__tnInvalidate();
1409
+ return this;
1410
+ }
1411
+ set_data_size(value) {
1412
+ const cast = __tnToBigInt(value);
1413
+ this.view.setBigUint64(2, cast, true);
1414
+ this.__tnInvalidate();
1415
+ return this;
1416
+ }
1417
+ data() {
1418
+ if (!this.__tnFamWriter_data) {
1419
+ this.__tnFamWriter_data = __tnCreateFamWriter(this, "data", (payload) => {
1420
+ const bytes = new Uint8Array(payload);
1421
+ const elementCount = bytes.length;
1422
+ this.__tnFam_data = bytes;
1423
+ this.__tnFam_dataCount = elementCount;
1424
+ this.set_data_size(__tnToBigInt(elementCount));
1425
+ this.__tnInvalidate();
1426
+ });
1427
+ }
1428
+ return this.__tnFamWriter_data;
1429
+ }
1430
+ build() {
1431
+ const params = this.__tnComputeParams();
1432
+ const size = InstructionData.footprintFromParams(params);
1433
+ const buffer = new Uint8Array(size);
1434
+ this.__tnWriteInto(buffer);
1435
+ this.__tnValidateOrThrow(buffer, params);
1436
+ return buffer;
1437
+ }
1438
+ buildInto(target, offset = 0) {
1439
+ const params = this.__tnComputeParams();
1440
+ const size = InstructionData.footprintFromParams(params);
1441
+ if (target.length - offset < size) throw new Error("InstructionDataBuilder: target buffer too small");
1442
+ const slice = target.subarray(offset, offset + size);
1443
+ this.__tnWriteInto(slice);
1444
+ this.__tnValidateOrThrow(slice, params);
1445
+ return target;
1446
+ }
1447
+ finish() {
1448
+ const buffer = this.build();
1449
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1450
+ const view = InstructionData.from_array(buffer, { params });
1451
+ if (!view) throw new Error("InstructionDataBuilder: failed to finalize view");
1452
+ return view;
1453
+ }
1454
+ finishView() {
1455
+ return this.finish();
1456
+ }
1457
+ dynamicParams() {
1458
+ return this.__tnComputeParams();
1459
+ }
1460
+ __tnComputeParams() {
1461
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1462
+ const params = InstructionData.Params.fromValues({
1463
+ data_data_size: (() => {
1464
+ if (this.__tnFam_dataCount === null) throw new Error("InstructionDataBuilder: field 'data' must be written before computing params");
1465
+ return __tnToBigInt(this.__tnFam_dataCount);
1466
+ })()
1467
+ });
1468
+ this.__tnCachedParams = params;
1469
+ return params;
1470
+ }
1471
+ __tnWriteInto(target) {
1472
+ target.set(this.buffer, 0);
1473
+ let cursor = this.buffer.length;
1474
+ const __tnLocal_data_bytes = this.__tnFam_data;
1475
+ if (!__tnLocal_data_bytes) throw new Error("InstructionDataBuilder: field 'data' must be written before build");
1476
+ target.set(__tnLocal_data_bytes, cursor);
1477
+ cursor += __tnLocal_data_bytes.length;
1478
+ }
1479
+ __tnValidateOrThrow(buffer, params) {
1480
+ const result = InstructionData.validate(buffer, { params });
1481
+ if (!result.ok) {
1482
+ throw new Error(`${InstructionData}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1483
+ }
1484
+ this.__tnLastParams = result.params ?? params;
1485
+ this.__tnLastBuffer = buffer;
1486
+ }
1487
+ };
1488
+ __tnRegisterFootprint("InstructionData", (params) => InstructionData.__tnInvokeFootprint(params));
1489
+ __tnRegisterValidate("InstructionData", (buffer, params) => InstructionData.__tnInvokeValidate(buffer, params));
1490
+ __tnRegisterDynamicValidate("InstructionData", (buffer) => {
1491
+ const result = InstructionData.validate(buffer);
1492
+ const params = result.params;
1493
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1494
+ });
1495
+ var __tn_ir_Pubkey = {
1496
+ typeName: "Pubkey",
1497
+ root: { op: "const", value: 32n }
1498
+ };
1499
+ var Pubkey = class _Pubkey {
1500
+ constructor(buffer) {
1501
+ this.buffer = buffer;
1502
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1503
+ }
1504
+ static __tnCreateView(buffer, opts) {
1505
+ if (!buffer || buffer.length === void 0) throw new Error("Pubkey.__tnCreateView requires a Uint8Array");
1506
+ return new _Pubkey(new Uint8Array(buffer));
1507
+ }
1508
+ static builder() {
1509
+ return new PubkeyBuilder();
1510
+ }
1511
+ static fromBuilder(builder) {
1512
+ const buffer = builder.build();
1513
+ return _Pubkey.from_array(buffer);
1514
+ }
1515
+ get_bytes() {
1516
+ const offset = 0;
1517
+ const result = [];
1518
+ for (let i = 0; i < 32; i++) {
1519
+ result.push(this.view.getUint8(offset + i * 1));
1520
+ }
1521
+ return result;
1522
+ }
1523
+ set_bytes(value) {
1524
+ const offset = 0;
1525
+ if (value.length !== 32) {
1526
+ throw new Error("Array length must be 32");
1527
+ }
1528
+ for (let i = 0; i < 32; i++) {
1529
+ this.view.setUint8(offset + i * 1, value[i]);
1530
+ }
1531
+ }
1532
+ get bytes() {
1533
+ return this.get_bytes();
1534
+ }
1535
+ set bytes(value) {
1536
+ this.set_bytes(value);
1537
+ }
1538
+ static __tnFootprintInternal(__tnParams) {
1539
+ return __tnEvalFootprint(__tn_ir_Pubkey.root, { params: __tnParams });
1540
+ }
1541
+ static __tnValidateInternal(buffer, __tnParams) {
1542
+ return __tnValidateIrTree(__tn_ir_Pubkey, buffer, __tnParams);
1543
+ }
1544
+ static __tnInvokeFootprint(__tnParams) {
1545
+ return this.__tnFootprintInternal(__tnParams);
1546
+ }
1547
+ static __tnInvokeValidate(buffer, __tnParams) {
1548
+ return this.__tnValidateInternal(buffer, __tnParams);
1549
+ }
1550
+ static footprintIr() {
1551
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1552
+ }
1553
+ static footprint() {
1554
+ const irResult = this.footprintIr();
1555
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1556
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1557
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Pubkey");
1558
+ }
1559
+ return __tnBigIntToNumber(irResult, "Pubkey::footprint");
1560
+ }
1561
+ static validate(buffer, _opts) {
1562
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1563
+ return { ok: true, consumed: 32 };
1564
+ }
1565
+ static from_array(buffer) {
1566
+ if (!buffer || buffer.length === void 0) {
1567
+ return null;
1568
+ }
1569
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1570
+ const validation = this.validate(buffer);
1571
+ if (!validation.ok) {
1572
+ return null;
1573
+ }
1574
+ return new _Pubkey(buffer);
1575
+ }
1576
+ };
1577
+ var PubkeyBuilder = class {
1578
+ constructor() {
1579
+ this.buffer = new Uint8Array(32);
1580
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1581
+ }
1582
+ set_bytes(values) {
1583
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1584
+ for (let i = 0; i < values.length; i++) {
1585
+ const byteOffset = 0 + i * 1;
1586
+ this.view.setUint8(byteOffset, values[i]);
1587
+ }
1588
+ return this;
1589
+ }
1590
+ build() {
1591
+ return this.buffer.slice();
1592
+ }
1593
+ buildInto(target, offset = 0) {
1594
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1595
+ target.set(this.buffer, offset);
1596
+ return target;
1597
+ }
1598
+ finish() {
1599
+ const view = Pubkey.from_array(this.buffer.slice());
1600
+ if (!view) throw new Error("failed to build Pubkey");
1601
+ return view;
1602
+ }
1603
+ };
1604
+ __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
1605
+ __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
1606
+ __tnRegisterDynamicValidate("Pubkey", (buffer) => {
1607
+ const result = Pubkey.validate(buffer);
1608
+ const params = result.params;
1609
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1610
+ });
1611
+ var __tn_ir_Signature = {
1612
+ typeName: "Signature",
1613
+ root: { op: "const", value: 64n }
1614
+ };
1615
+ var Signature = class _Signature {
1616
+ constructor(buffer) {
1617
+ this.buffer = buffer;
1618
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1619
+ }
1620
+ static __tnCreateView(buffer, opts) {
1621
+ if (!buffer || buffer.length === void 0) throw new Error("Signature.__tnCreateView requires a Uint8Array");
1622
+ return new _Signature(new Uint8Array(buffer));
1623
+ }
1624
+ static builder() {
1625
+ return new SignatureBuilder();
1626
+ }
1627
+ static fromBuilder(builder) {
1628
+ const buffer = builder.build();
1629
+ return _Signature.from_array(buffer);
1630
+ }
1631
+ get_bytes() {
1632
+ const offset = 0;
1633
+ const result = [];
1634
+ for (let i = 0; i < 64; i++) {
1635
+ result.push(this.view.getUint8(offset + i * 1));
1636
+ }
1637
+ return result;
1638
+ }
1639
+ set_bytes(value) {
1640
+ const offset = 0;
1641
+ if (value.length !== 64) {
1642
+ throw new Error("Array length must be 64");
1643
+ }
1644
+ for (let i = 0; i < 64; i++) {
1645
+ this.view.setUint8(offset + i * 1, value[i]);
1646
+ }
1647
+ }
1648
+ get bytes() {
1649
+ return this.get_bytes();
1650
+ }
1651
+ set bytes(value) {
1652
+ this.set_bytes(value);
1653
+ }
1654
+ static __tnFootprintInternal(__tnParams) {
1655
+ return __tnEvalFootprint(__tn_ir_Signature.root, { params: __tnParams });
1656
+ }
1657
+ static __tnValidateInternal(buffer, __tnParams) {
1658
+ return __tnValidateIrTree(__tn_ir_Signature, buffer, __tnParams);
1659
+ }
1660
+ static __tnInvokeFootprint(__tnParams) {
1661
+ return this.__tnFootprintInternal(__tnParams);
1662
+ }
1663
+ static __tnInvokeValidate(buffer, __tnParams) {
1664
+ return this.__tnValidateInternal(buffer, __tnParams);
1665
+ }
1666
+ static footprintIr() {
1667
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1668
+ }
1669
+ static footprint() {
1670
+ const irResult = this.footprintIr();
1671
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1672
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1673
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Signature");
1674
+ }
1675
+ return __tnBigIntToNumber(irResult, "Signature::footprint");
1676
+ }
1677
+ static validate(buffer, _opts) {
1678
+ if (buffer.length < 64) return { ok: false, code: "tn.buffer_too_small", consumed: 64 };
1679
+ return { ok: true, consumed: 64 };
1680
+ }
1681
+ static from_array(buffer) {
1682
+ if (!buffer || buffer.length === void 0) {
1683
+ return null;
1684
+ }
1685
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1686
+ const validation = this.validate(buffer);
1687
+ if (!validation.ok) {
1688
+ return null;
1689
+ }
1690
+ return new _Signature(buffer);
1691
+ }
1692
+ };
1693
+ var SignatureBuilder = class {
1694
+ constructor() {
1695
+ this.buffer = new Uint8Array(64);
1696
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1697
+ }
1698
+ set_bytes(values) {
1699
+ if (values.length !== 64) throw new Error("bytes expects 64 elements");
1700
+ for (let i = 0; i < values.length; i++) {
1701
+ const byteOffset = 0 + i * 1;
1702
+ this.view.setUint8(byteOffset, values[i]);
1703
+ }
1704
+ return this;
1705
+ }
1706
+ build() {
1707
+ return this.buffer.slice();
1708
+ }
1709
+ buildInto(target, offset = 0) {
1710
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1711
+ target.set(this.buffer, offset);
1712
+ return target;
1713
+ }
1714
+ finish() {
1715
+ const view = Signature.from_array(this.buffer.slice());
1716
+ if (!view) throw new Error("failed to build Signature");
1717
+ return view;
1718
+ }
1719
+ };
1720
+ __tnRegisterFootprint("Signature", (params) => Signature.__tnInvokeFootprint(params));
1721
+ __tnRegisterValidate("Signature", (buffer, params) => Signature.__tnInvokeValidate(buffer, params));
1722
+ __tnRegisterDynamicValidate("Signature", (buffer) => {
1723
+ const result = Signature.validate(buffer);
1724
+ const params = result.params;
1725
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1726
+ });
1727
+ var __tn_ir_Timestamp = {
1728
+ typeName: "Timestamp",
1729
+ root: { op: "const", value: 8n }
1730
+ };
1731
+ var Timestamp = class _Timestamp {
1732
+ constructor(buffer) {
1733
+ this.buffer = buffer;
1734
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1735
+ }
1736
+ static __tnCreateView(buffer, opts) {
1737
+ if (!buffer || buffer.length === void 0) throw new Error("Timestamp.__tnCreateView requires a Uint8Array");
1738
+ return new _Timestamp(new Uint8Array(buffer));
1739
+ }
1740
+ static builder() {
1741
+ return new TimestampBuilder();
1742
+ }
1743
+ static fromBuilder(builder) {
1744
+ const buffer = builder.build();
1745
+ return _Timestamp.from_array(buffer);
1746
+ }
1747
+ get_seconds() {
1748
+ const offset = 0;
1749
+ return this.view.getBigInt64(offset, true);
1750
+ }
1751
+ set_seconds(value) {
1752
+ const offset = 0;
1753
+ this.view.setBigInt64(offset, value, true);
1754
+ }
1755
+ get seconds() {
1756
+ return this.get_seconds();
1757
+ }
1758
+ set seconds(value) {
1759
+ this.set_seconds(value);
1760
+ }
1761
+ static __tnFootprintInternal(__tnParams) {
1762
+ return __tnEvalFootprint(__tn_ir_Timestamp.root, { params: __tnParams });
1763
+ }
1764
+ static __tnValidateInternal(buffer, __tnParams) {
1765
+ return __tnValidateIrTree(__tn_ir_Timestamp, buffer, __tnParams);
1766
+ }
1767
+ static __tnInvokeFootprint(__tnParams) {
1768
+ return this.__tnFootprintInternal(__tnParams);
1769
+ }
1770
+ static __tnInvokeValidate(buffer, __tnParams) {
1771
+ return this.__tnValidateInternal(buffer, __tnParams);
1772
+ }
1773
+ static footprintIr() {
1774
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1775
+ }
1776
+ static footprint() {
1777
+ const irResult = this.footprintIr();
1778
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1779
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1780
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Timestamp");
1781
+ }
1782
+ return __tnBigIntToNumber(irResult, "Timestamp::footprint");
1783
+ }
1784
+ static validate(buffer, _opts) {
1785
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
1786
+ return { ok: true, consumed: 8 };
1787
+ }
1788
+ static new(seconds) {
1789
+ const buffer = new Uint8Array(8);
1790
+ const view = new DataView(buffer.buffer);
1791
+ view.setBigInt64(0, seconds, true);
1792
+ return new _Timestamp(buffer);
1793
+ }
1794
+ static from_array(buffer) {
1795
+ if (!buffer || buffer.length === void 0) {
1796
+ return null;
1797
+ }
1798
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1799
+ const validation = this.validate(buffer);
1800
+ if (!validation.ok) {
1801
+ return null;
1802
+ }
1803
+ return new _Timestamp(buffer);
1804
+ }
1805
+ };
1806
+ var TimestampBuilder = class {
1807
+ constructor() {
1808
+ this.buffer = new Uint8Array(8);
1809
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1810
+ }
1811
+ set_seconds(value) {
1812
+ const cast = __tnToBigInt(value);
1813
+ this.view.setBigInt64(0, cast, true);
1814
+ return this;
1815
+ }
1816
+ build() {
1817
+ return this.buffer.slice();
1818
+ }
1819
+ buildInto(target, offset = 0) {
1820
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1821
+ target.set(this.buffer, offset);
1822
+ return target;
1823
+ }
1824
+ finish() {
1825
+ const view = Timestamp.from_array(this.buffer.slice());
1826
+ if (!view) throw new Error("failed to build Timestamp");
1827
+ return view;
1828
+ }
1829
+ };
1830
+ __tnRegisterFootprint("Timestamp", (params) => Timestamp.__tnInvokeFootprint(params));
1831
+ __tnRegisterValidate("Timestamp", (buffer, params) => Timestamp.__tnInvokeValidate(buffer, params));
1832
+ __tnRegisterDynamicValidate("Timestamp", (buffer) => {
1833
+ const result = Timestamp.validate(buffer);
1834
+ const params = result.params;
1835
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1836
+ });
1837
+
1838
+ // src/uploader/abi/thru/program/uploader/types.ts
1839
+ var __tnWarnings2 = /* @__PURE__ */ new Set();
1840
+ var __tnHasNativeBigInt2 = typeof BigInt === "function";
1841
+ var __tnHasBigIntDataView2 = typeof DataView !== "undefined" && typeof DataView.prototype.getBigInt64 === "function" && typeof DataView.prototype.getBigUint64 === "function" && typeof DataView.prototype.setBigInt64 === "function" && typeof DataView.prototype.setBigUint64 === "function";
1842
+ var __tnConsole2 = typeof globalThis !== "undefined" ? globalThis.console : void 0;
1843
+ function __tnLogWarn2(message) {
1844
+ if (__tnConsole2 && typeof __tnConsole2.warn === "function") {
1845
+ __tnConsole2.warn(message);
1846
+ }
1847
+ }
1848
+ function __tnWarnOnce2(message) {
1849
+ if (!__tnWarnings2.has(message)) {
1850
+ __tnWarnings2.add(message);
1851
+ __tnLogWarn2(message);
1852
+ }
1853
+ }
1854
+ function __tnResolveBuilderInput2(input, context) {
1855
+ if (input instanceof Uint8Array) {
1856
+ return new Uint8Array(input);
1857
+ }
1858
+ if (input && typeof input.build === "function") {
1859
+ const built = input.build();
1860
+ if (!(built instanceof Uint8Array)) {
1861
+ throw new Error(`${context}: builder did not return Uint8Array`);
1862
+ }
1863
+ return new Uint8Array(built);
1864
+ }
1865
+ throw new Error(`${context}: expected Uint8Array or builder`);
1866
+ }
1867
+ function __tnMaybeCallBuilder(ctor) {
1868
+ if (!ctor) {
1869
+ return null;
1870
+ }
1871
+ const builderFn = ctor.builder;
1872
+ return typeof builderFn === "function" ? builderFn() : null;
1873
+ }
1874
+ function __tnCreateVariantSelector(parent, descriptors, assign) {
1875
+ return {
1876
+ select(name) {
1877
+ const descriptor = descriptors.find((variant) => variant.name === name);
1878
+ if (!descriptor) {
1879
+ throw new Error(`Unknown variant '${name}'`);
1880
+ }
1881
+ return {
1882
+ writePayload(payload) {
1883
+ const bytes = __tnResolveBuilderInput2(
1884
+ payload,
1885
+ `variant ${descriptor.name}`
1886
+ );
1887
+ if (descriptor.payloadSize !== null && bytes.length !== descriptor.payloadSize) {
1888
+ throw new Error(
1889
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
1890
+ );
1891
+ }
1892
+ assign(descriptor, bytes);
1893
+ return {
1894
+ finish() {
1895
+ return parent;
1896
+ }
1897
+ };
1898
+ }
1899
+ };
1900
+ },
1901
+ finish() {
1902
+ return parent;
1903
+ }
1904
+ };
1905
+ }
1906
+ function __tnCreateFamWriter2(parent, fieldName, assign) {
1907
+ let hasWritten = false;
1908
+ return {
1909
+ write(payload) {
1910
+ const bytes = __tnResolveBuilderInput2(
1911
+ payload,
1912
+ `flexible array '${fieldName}'`
1913
+ );
1914
+ const copy = new Uint8Array(bytes);
1915
+ assign(copy);
1916
+ hasWritten = true;
1917
+ return {
1918
+ finish() {
1919
+ return parent;
1920
+ }
1921
+ };
1922
+ },
1923
+ finish() {
1924
+ if (!hasWritten) {
1925
+ throw new Error(
1926
+ `flexible array '${fieldName}' requires write() before finish()`
1927
+ );
1928
+ }
1929
+ return parent;
1930
+ }
1931
+ };
1932
+ }
1933
+ var __tnMask322 = __tnHasNativeBigInt2 ? (BigInt(1) << BigInt(32)) - BigInt(1) : 4294967295;
1934
+ var __tnSignBit322 = __tnHasNativeBigInt2 ? BigInt(1) << BigInt(31) : 2147483648;
1935
+ function __tnToBigInt2(value) {
1936
+ if (__tnHasNativeBigInt2) {
1937
+ return typeof value === "bigint" ? value : BigInt(value);
1938
+ }
1939
+ if (typeof value === "bigint") return value;
1940
+ if (!Number.isFinite(value)) {
1941
+ throw new Error("IR runtime received non-finite numeric input");
1942
+ }
1943
+ if (!Number.isSafeInteger(value)) {
1944
+ __tnWarnOnce2(
1945
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
1946
+ );
1947
+ }
1948
+ return value;
1949
+ }
1950
+ function __tnBigIntToNumber2(value, context) {
1951
+ if (__tnHasNativeBigInt2) {
1952
+ const converted = Number(value);
1953
+ if (!Number.isFinite(converted)) {
1954
+ throw new Error(`${context} overflowed Number range`);
1955
+ }
1956
+ return converted;
1957
+ }
1958
+ return value;
1959
+ }
1960
+ function __tnBigIntEquals2(lhs, rhs) {
1961
+ if (__tnHasNativeBigInt2) return lhs === rhs;
1962
+ return lhs === rhs;
1963
+ }
1964
+ function __tnBigIntGreaterThan2(lhs, rhs) {
1965
+ if (__tnHasNativeBigInt2) return lhs > rhs;
1966
+ return lhs > rhs;
1967
+ }
1968
+ function __tnRaiseIrError2(code, message) {
1969
+ const err = new Error(message);
1970
+ err.code = code;
1971
+ throw err;
1972
+ }
1973
+ function __tnCheckedAdd2(lhs, rhs) {
1974
+ if (__tnHasNativeBigInt2) {
1975
+ const result = lhs + rhs;
1976
+ if (result < BigInt(0)) {
1977
+ __tnRaiseIrError2(
1978
+ "tn.ir.overflow",
1979
+ "IR runtime detected negative size via addition"
1980
+ );
1981
+ }
1982
+ return result;
1983
+ }
1984
+ const left = lhs;
1985
+ const right = rhs;
1986
+ const sum = left + right;
1987
+ if (sum < 0 || !Number.isFinite(sum)) {
1988
+ __tnRaiseIrError2(
1989
+ "tn.ir.overflow",
1990
+ "IR runtime detected invalid addition result"
1991
+ );
1992
+ }
1993
+ if (!Number.isSafeInteger(sum)) {
1994
+ __tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt addition");
1995
+ }
1996
+ return sum;
1997
+ }
1998
+ function __tnCheckedSub2(lhs, rhs) {
1999
+ if (__tnHasNativeBigInt2) {
2000
+ const result = lhs - rhs;
2001
+ if (result < BigInt(0)) {
2002
+ __tnRaiseIrError2(
2003
+ "tn.ir.overflow",
2004
+ "IR runtime detected negative size via subtraction"
2005
+ );
2006
+ }
2007
+ return result;
2008
+ }
2009
+ const left = lhs;
2010
+ const right = rhs;
2011
+ const diff = left - right;
2012
+ if (diff < 0 || !Number.isFinite(diff)) {
2013
+ __tnRaiseIrError2(
2014
+ "tn.ir.overflow",
2015
+ "IR runtime detected invalid subtraction result"
2016
+ );
2017
+ }
2018
+ if (!Number.isSafeInteger(diff)) {
2019
+ __tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt subtraction");
2020
+ }
2021
+ return diff;
2022
+ }
2023
+ function __tnCheckedMul2(lhs, rhs) {
2024
+ if (__tnHasNativeBigInt2) {
2025
+ const result = lhs * rhs;
2026
+ if (result < BigInt(0)) {
2027
+ __tnRaiseIrError2(
2028
+ "tn.ir.overflow",
2029
+ "IR runtime detected negative size via multiplication"
2030
+ );
2031
+ }
2032
+ return result;
2033
+ }
2034
+ const left = lhs;
2035
+ const right = rhs;
2036
+ const product = left * right;
2037
+ if (product < 0 || !Number.isFinite(product)) {
2038
+ __tnRaiseIrError2(
2039
+ "tn.ir.overflow",
2040
+ "IR runtime detected invalid multiplication result"
2041
+ );
2042
+ }
2043
+ if (!Number.isSafeInteger(product)) {
2044
+ __tnWarnOnce2(
2045
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
2046
+ );
2047
+ }
2048
+ return product;
2049
+ }
2050
+ function __tnCheckedDiv2(lhs, rhs) {
2051
+ if (__tnBigIntEquals2(rhs, __tnToBigInt2(0))) {
2052
+ __tnRaiseIrError2("tn.ir.overflow", "IR runtime division by zero");
2053
+ }
2054
+ if (__tnHasNativeBigInt2) return lhs / rhs;
2055
+ const quotient = Math.floor(lhs / rhs);
2056
+ return quotient;
2057
+ }
2058
+ function __tnCheckedMod2(lhs, rhs) {
2059
+ if (__tnBigIntEquals2(rhs, __tnToBigInt2(0))) {
2060
+ __tnRaiseIrError2("tn.ir.overflow", "IR runtime modulo by zero");
2061
+ }
2062
+ if (__tnHasNativeBigInt2) return lhs % rhs;
2063
+ return lhs % rhs;
2064
+ }
2065
+ function __tnBitwise2(lhs, rhs, op) {
2066
+ if (__tnHasNativeBigInt2) {
2067
+ if (op === "and") return lhs & rhs;
2068
+ if (op === "or") return lhs | rhs;
2069
+ return lhs ^ rhs;
2070
+ }
2071
+ const left = lhs;
2072
+ const right = rhs;
2073
+ const maxU32 = 4294967295;
2074
+ if (!Number.isInteger(left) || !Number.isInteger(right) || left < 0 || right < 0 || left > maxU32 || right > maxU32) {
2075
+ __tnRaiseIrError2(
2076
+ "tn.ir.overflow",
2077
+ "IR runtime bitwise operation requires BigInt for values outside u32 range"
2078
+ );
2079
+ }
2080
+ const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
2081
+ return result >>> 0;
2082
+ }
2083
+ function __tnCheckedShift2(lhs, rhs, direction) {
2084
+ const amount = __tnBigIntToNumber2(rhs, "IR shift amount");
2085
+ if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
2086
+ __tnRaiseIrError2("tn.ir.overflow", "IR runtime invalid shift amount");
2087
+ }
2088
+ if (__tnHasNativeBigInt2) {
2089
+ const shift = BigInt(amount);
2090
+ return direction === "left" ? lhs << shift : lhs >> shift;
2091
+ }
2092
+ const value = lhs;
2093
+ const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
2094
+ if (!Number.isSafeInteger(result)) {
2095
+ __tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt shift");
2096
+ }
2097
+ return result;
2098
+ }
2099
+ function __tnAlign2(value, alignment) {
2100
+ if (alignment <= 1) return value;
2101
+ const alignBig = __tnToBigInt2(alignment);
2102
+ if (__tnHasNativeBigInt2) {
2103
+ const remainder2 = value % alignBig;
2104
+ if (__tnBigIntEquals2(remainder2, __tnToBigInt2(0))) {
2105
+ return value;
2106
+ }
2107
+ const delta = alignBig - remainder2;
2108
+ return __tnCheckedAdd2(value, delta);
2109
+ }
2110
+ const current = __tnBigIntToNumber2(value, "IR align");
2111
+ const alignNum = alignment >>> 0;
2112
+ const remainder = current % alignNum;
2113
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
2114
+ return __tnToBigInt2(next);
2115
+ }
2116
+ function __tnSplitUint642(value) {
2117
+ if (__tnHasNativeBigInt2) {
2118
+ const low2 = Number(value & __tnMask322);
2119
+ const high2 = Number(value >> BigInt(32) & __tnMask322);
2120
+ return { high: high2, low: low2 };
2121
+ }
2122
+ const num = __tnBigIntToNumber2(value, "DataView.setBigUint64");
2123
+ const low = num >>> 0;
2124
+ const high = Math.floor(num / 4294967296) >>> 0;
2125
+ return { high, low };
2126
+ }
2127
+ function __tnSplitInt642(value) {
2128
+ if (__tnHasNativeBigInt2) {
2129
+ const low2 = Number(value & __tnMask322);
2130
+ let high2 = Number(value >> BigInt(32) & __tnMask322);
2131
+ if ((BigInt(high2) & __tnSignBit322) !== BigInt(0)) {
2132
+ high2 -= 4294967296;
2133
+ }
2134
+ return { high: high2, low: low2 };
2135
+ }
2136
+ const num = __tnBigIntToNumber2(value, "DataView.setBigInt64");
2137
+ const low = num >>> 0;
2138
+ const high = Math.floor(num / 4294967296);
2139
+ return { high, low };
2140
+ }
2141
+ function __tnPolyfillReadUint642(view, offset, littleEndian) {
2142
+ const low = littleEndian ? view.getUint32(offset, true) : view.getUint32(offset + 4, false);
2143
+ const high = littleEndian ? view.getUint32(offset + 4, true) : view.getUint32(offset, false);
2144
+ if (__tnHasNativeBigInt2) {
2145
+ return BigInt(high) << BigInt(32) | BigInt(low);
2146
+ }
2147
+ const value = high * 4294967296 + low;
2148
+ if (!Number.isSafeInteger(value)) {
2149
+ __tnWarnOnce2(
2150
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
2151
+ );
2152
+ }
2153
+ return value;
2154
+ }
2155
+ function __tnPolyfillReadInt642(view, offset, littleEndian) {
2156
+ const low = littleEndian ? view.getUint32(offset, true) : view.getUint32(offset + 4, false);
2157
+ const high = littleEndian ? view.getInt32(offset + 4, true) : view.getInt32(offset, false);
2158
+ if (__tnHasNativeBigInt2) {
2159
+ return BigInt(high) << BigInt(32) | BigInt(low);
2160
+ }
2161
+ const value = high * 4294967296 + low;
2162
+ if (!Number.isSafeInteger(value)) {
2163
+ __tnWarnOnce2(
2164
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
2165
+ );
2166
+ }
2167
+ return value;
2168
+ }
2169
+ function __tnPolyfillWriteUint642(view, offset, value, littleEndian) {
2170
+ const parts = __tnSplitUint642(value);
2171
+ if (littleEndian) {
2172
+ view.setUint32(offset, parts.low, true);
2173
+ view.setUint32(offset + 4, parts.high, true);
2174
+ } else {
2175
+ view.setUint32(offset, parts.high, false);
2176
+ view.setUint32(offset + 4, parts.low, false);
2177
+ }
2178
+ }
2179
+ function __tnPolyfillWriteInt642(view, offset, value, littleEndian) {
2180
+ const parts = __tnSplitInt642(value);
2181
+ if (littleEndian) {
2182
+ view.setUint32(offset, parts.low >>> 0, true);
2183
+ view.setInt32(offset + 4, parts.high | 0, true);
2184
+ } else {
2185
+ view.setInt32(offset, parts.high | 0, false);
2186
+ view.setUint32(offset + 4, parts.low >>> 0, false);
2187
+ }
2188
+ }
2189
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView2) {
2190
+ const proto = DataView.prototype;
2191
+ if (typeof proto.getBigUint64 !== "function") {
2192
+ proto.getBigUint64 = function(offset, littleEndian) {
2193
+ __tnWarnOnce2(
2194
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
2195
+ );
2196
+ return __tnPolyfillReadUint642(this, offset, !!littleEndian);
2197
+ };
2198
+ }
2199
+ if (typeof proto.getBigInt64 !== "function") {
2200
+ proto.getBigInt64 = function(offset, littleEndian) {
2201
+ __tnWarnOnce2(
2202
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
2203
+ );
2204
+ return __tnPolyfillReadInt642(this, offset, !!littleEndian);
2205
+ };
2206
+ }
2207
+ if (typeof proto.setBigUint64 !== "function") {
2208
+ proto.setBigUint64 = function(offset, value, littleEndian) {
2209
+ __tnWarnOnce2(
2210
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
2211
+ );
2212
+ __tnPolyfillWriteUint642(this, offset, value, !!littleEndian);
2213
+ };
2214
+ }
2215
+ if (typeof proto.setBigInt64 !== "function") {
2216
+ proto.setBigInt64 = function(offset, value, littleEndian) {
2217
+ __tnWarnOnce2(
2218
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
2219
+ );
2220
+ __tnPolyfillWriteInt642(this, offset, value, !!littleEndian);
2221
+ };
2222
+ }
2223
+ if (!__tnHasNativeBigInt2) {
2224
+ __tnWarnOnce2(
2225
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
2226
+ );
2227
+ }
2228
+ }
2229
+ var __tnFootprintRegistry2 = {};
2230
+ var __tnValidateRegistry2 = {};
2231
+ var __tnDynamicValidateRegistry2 = {};
2232
+ function __tnRegisterFootprint2(typeName, fn) {
2233
+ __tnFootprintRegistry2[typeName] = fn;
2234
+ }
2235
+ function __tnRegisterValidate2(typeName, fn) {
2236
+ __tnValidateRegistry2[typeName] = fn;
2237
+ }
2238
+ function __tnRegisterDynamicValidate2(typeName, fn) {
2239
+ __tnDynamicValidateRegistry2[typeName] = fn;
2240
+ }
2241
+ function __tnInvokeFootprint2(typeName, params) {
2242
+ const fn = __tnFootprintRegistry2[typeName];
2243
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
2244
+ return fn(params);
2245
+ }
2246
+ function __tnInvokeValidate2(typeName, buffer, params) {
2247
+ const fn = __tnValidateRegistry2[typeName];
2248
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
2249
+ return fn(buffer, params);
2250
+ }
2251
+ function __tnInvokeDynamicValidate2(typeName, buffer) {
2252
+ const fn = __tnDynamicValidateRegistry2[typeName];
2253
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
2254
+ return fn(buffer);
2255
+ }
2256
+ function __tnEvalFootprint2(node, ctx) {
2257
+ return __tnEvalIrNode2(node, ctx, __tnToBigInt2(0));
2258
+ }
2259
+ function __tnTryEvalIr2(node, ctx) {
2260
+ try {
2261
+ return { ok: true, value: __tnEvalIrNode2(node, ctx, __tnToBigInt2(0)) };
2262
+ } catch (err) {
2263
+ return { ok: false, code: __tnNormalizeIrError2(err) };
2264
+ }
2265
+ }
2266
+ function __tnIsEvalError2(result) {
2267
+ return result.ok === false;
2268
+ }
2269
+ function __tnValidateIrTree2(ir, buffer, params) {
2270
+ const evalResult = __tnTryEvalIr2(ir.root, {
2271
+ params,
2272
+ buffer,
2273
+ typeName: ir.typeName
2274
+ });
2275
+ if (__tnIsEvalError2(evalResult)) {
2276
+ return { ok: false, code: evalResult.code };
2277
+ }
2278
+ const required = evalResult.value;
2279
+ const available = __tnToBigInt2(buffer.length);
2280
+ if (__tnBigIntGreaterThan2(required, available)) {
2281
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
2282
+ }
2283
+ return { ok: true, consumed: required };
2284
+ }
2285
+ function __tnEvalIrNode2(node, ctx, baseOffset) {
2286
+ switch (node.op) {
2287
+ case "zero":
2288
+ return __tnToBigInt2(0);
2289
+ case "const":
2290
+ return node.value;
2291
+ case "field": {
2292
+ if (node.param === "__buffer_size" && ctx.buffer) {
2293
+ return __tnToBigInt2(ctx.buffer.length);
2294
+ }
2295
+ const val = ctx.params[node.param];
2296
+ if (val === void 0) {
2297
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
2298
+ __tnRaiseIrError2(
2299
+ "tn.ir.missing_param",
2300
+ `${prefix}Missing IR parameter '${node.param}'`
2301
+ );
2302
+ }
2303
+ return val;
2304
+ }
2305
+ case "add": {
2306
+ const left = __tnEvalIrNode2(node.left, ctx, baseOffset);
2307
+ const right = __tnEvalIrNode2(
2308
+ node.right,
2309
+ ctx,
2310
+ __tnCheckedAdd2(baseOffset, left)
2311
+ );
2312
+ return __tnCheckedAdd2(left, right);
2313
+ }
2314
+ case "sub":
2315
+ return __tnCheckedSub2(
2316
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2317
+ __tnEvalIrNode2(node.right, ctx, baseOffset)
2318
+ );
2319
+ case "mul":
2320
+ return __tnCheckedMul2(
2321
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2322
+ __tnEvalIrNode2(node.right, ctx, baseOffset)
2323
+ );
2324
+ case "div":
2325
+ return __tnCheckedDiv2(
2326
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2327
+ __tnEvalIrNode2(node.right, ctx, baseOffset)
2328
+ );
2329
+ case "mod":
2330
+ return __tnCheckedMod2(
2331
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2332
+ __tnEvalIrNode2(node.right, ctx, baseOffset)
2333
+ );
2334
+ case "bitAnd":
2335
+ return __tnBitwise2(
2336
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2337
+ __tnEvalIrNode2(node.right, ctx, baseOffset),
2338
+ "and"
2339
+ );
2340
+ case "bitOr":
2341
+ return __tnBitwise2(
2342
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2343
+ __tnEvalIrNode2(node.right, ctx, baseOffset),
2344
+ "or"
2345
+ );
2346
+ case "bitXor":
2347
+ return __tnBitwise2(
2348
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2349
+ __tnEvalIrNode2(node.right, ctx, baseOffset),
2350
+ "xor"
2351
+ );
2352
+ case "leftShift":
2353
+ return __tnCheckedShift2(
2354
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2355
+ __tnEvalIrNode2(node.right, ctx, baseOffset),
2356
+ "left"
2357
+ );
2358
+ case "rightShift":
2359
+ return __tnCheckedShift2(
2360
+ __tnEvalIrNode2(node.left, ctx, baseOffset),
2361
+ __tnEvalIrNode2(node.right, ctx, baseOffset),
2362
+ "right"
2363
+ );
2364
+ case "align":
2365
+ return __tnAlign2(__tnEvalIrNode2(node.node, ctx, baseOffset), node.alignment);
2366
+ case "switch": {
2367
+ const tagVal = ctx.params[node.tag];
2368
+ if (tagVal === void 0) {
2369
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
2370
+ __tnRaiseIrError2(
2371
+ "tn.ir.missing_param",
2372
+ `${prefix}Missing IR switch tag '${node.tag}'`
2373
+ );
2374
+ }
2375
+ const tagNumber = Number(tagVal);
2376
+ for (const caseNode of node.cases) {
2377
+ if (caseNode.value === tagNumber) {
2378
+ return __tnEvalIrNode2(caseNode.node, ctx, baseOffset);
2379
+ }
2380
+ }
2381
+ if (node.default) return __tnEvalIrNode2(node.default, ctx, baseOffset);
2382
+ __tnRaiseIrError2(
2383
+ "tn.ir.invalid_tag",
2384
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
2385
+ );
2386
+ }
2387
+ case "call": {
2388
+ const nestedParams = /* @__PURE__ */ Object.create(null);
2389
+ for (const arg of node.args) {
2390
+ const val = ctx.params[arg.source];
2391
+ if (val === void 0) {
2392
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
2393
+ __tnRaiseIrError2(
2394
+ "tn.ir.missing_param",
2395
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
2396
+ );
2397
+ }
2398
+ nestedParams[arg.name] = val;
2399
+ }
2400
+ if (ctx.buffer) {
2401
+ const nestedOffset = __tnBigIntToNumber2(baseOffset, "IR nested offset");
2402
+ const nestedResult = __tnInvokeValidate2(
2403
+ node.typeName,
2404
+ ctx.buffer.subarray(nestedOffset),
2405
+ nestedParams
2406
+ );
2407
+ if (!nestedResult.ok) {
2408
+ const nestedCode = nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
2409
+ const prefixed = nestedCode.startsWith("tn.") ? nestedCode : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
2410
+ __tnRaiseIrError2(
2411
+ prefixed,
2412
+ `Nested validator ${node.typeName} failed`
2413
+ );
2414
+ }
2415
+ if (nestedResult.consumed !== void 0) {
2416
+ return nestedResult.consumed;
2417
+ }
2418
+ }
2419
+ return __tnInvokeFootprint2(node.typeName, nestedParams);
2420
+ }
2421
+ case "sumOverArray": {
2422
+ if (!ctx.buffer) {
2423
+ __tnRaiseIrError2(
2424
+ "tn.ir.missing_buffer",
2425
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
2426
+ );
2427
+ }
2428
+ const count = __tnBigIntToNumber2(
2429
+ __tnEvalIrNode2(node.count, ctx, baseOffset),
2430
+ `Jagged array '${node.fieldName}' count`
2431
+ );
2432
+ let cursor = __tnBigIntToNumber2(baseOffset, "IR jagged array offset");
2433
+ let total = __tnToBigInt2(0);
2434
+ for (let i = 0; i < count; i++) {
2435
+ const result = __tnInvokeDynamicValidate2(
2436
+ node.elementTypeName,
2437
+ ctx.buffer.subarray(cursor)
2438
+ );
2439
+ if (!result.ok || result.consumed === void 0) {
2440
+ const code = result.code ?? "tn.ir.runtime_error";
2441
+ __tnRaiseIrError2(
2442
+ code,
2443
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
2444
+ );
2445
+ }
2446
+ cursor += __tnBigIntToNumber2(result.consumed, "IR jagged element size");
2447
+ total = __tnCheckedAdd2(total, result.consumed);
2448
+ }
2449
+ return total;
2450
+ }
2451
+ default:
2452
+ __tnRaiseIrError2(
2453
+ "tn.ir.runtime_error",
2454
+ `Unsupported IR node ${node.op}`
2455
+ );
2456
+ }
2457
+ }
2458
+ function __tnNormalizeIrError2(err) {
2459
+ if (err && typeof err === "object" && "code" in err) {
2460
+ const maybeCode = err.code;
2461
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
2462
+ return maybeCode;
2463
+ }
2464
+ }
2465
+ const message = err && typeof err === "object" && "message" in err ? String(err.message ?? "") : typeof err === "string" ? err : "";
2466
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
2467
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
2468
+ if (message.includes("invalid") || message.includes("overflow") || message.includes("negative size")) {
2469
+ return "tn.ir.overflow";
2470
+ }
2471
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
2472
+ return "tn.ir.runtime_error";
2473
+ }
2474
+ __tnRegisterFootprint2("Hash", (params) => Hash.__tnInvokeFootprint(params));
2475
+ __tnRegisterValidate2("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
2476
+ __tnRegisterDynamicValidate2("Hash", (buffer) => {
2477
+ const result = Hash.validate(buffer);
2478
+ const params = result.params;
2479
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
2480
+ });
2481
+ __tnRegisterFootprint2("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
2482
+ __tnRegisterValidate2("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
2483
+ __tnRegisterDynamicValidate2("Pubkey", (buffer) => {
2484
+ const result = Pubkey.validate(buffer);
2485
+ const params = result.params;
2486
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
2487
+ });
2488
+ var __tn_ir_DestroyArgs = {
2489
+ typeName: "DestroyArgs",
2490
+ root: { op: "const", value: 4n }
2491
+ };
2492
+ var DestroyArgs = class _DestroyArgs {
2493
+ constructor(buffer) {
2494
+ this.buffer = buffer;
2495
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2496
+ }
2497
+ static __tnCreateView(buffer, opts) {
2498
+ if (!buffer || buffer.length === void 0) throw new Error("DestroyArgs.__tnCreateView requires a Uint8Array");
2499
+ return new _DestroyArgs(new Uint8Array(buffer));
2500
+ }
2501
+ static builder() {
2502
+ return new DestroyArgsBuilder();
2503
+ }
2504
+ static fromBuilder(builder) {
2505
+ const buffer = builder.build();
2506
+ return _DestroyArgs.from_array(buffer);
2507
+ }
2508
+ get_buffer_account_idx() {
2509
+ const offset = 0;
2510
+ return this.view.getUint16(offset, true);
2511
+ }
2512
+ set_buffer_account_idx(value) {
2513
+ const offset = 0;
2514
+ this.view.setUint16(offset, value, true);
2515
+ }
2516
+ get buffer_account_idx() {
2517
+ return this.get_buffer_account_idx();
2518
+ }
2519
+ set buffer_account_idx(value) {
2520
+ this.set_buffer_account_idx(value);
2521
+ }
2522
+ get_meta_account_idx() {
2523
+ const offset = 2;
2524
+ return this.view.getUint16(offset, true);
2525
+ }
2526
+ set_meta_account_idx(value) {
2527
+ const offset = 2;
2528
+ this.view.setUint16(offset, value, true);
2529
+ }
2530
+ get meta_account_idx() {
2531
+ return this.get_meta_account_idx();
2532
+ }
2533
+ set meta_account_idx(value) {
2534
+ this.set_meta_account_idx(value);
2535
+ }
2536
+ static __tnFootprintInternal(__tnParams) {
2537
+ return __tnEvalFootprint2(__tn_ir_DestroyArgs.root, { params: __tnParams });
2538
+ }
2539
+ static __tnValidateInternal(buffer, __tnParams) {
2540
+ return __tnValidateIrTree2(__tn_ir_DestroyArgs, buffer, __tnParams);
2541
+ }
2542
+ static __tnInvokeFootprint(__tnParams) {
2543
+ return this.__tnFootprintInternal(__tnParams);
2544
+ }
2545
+ static __tnInvokeValidate(buffer, __tnParams) {
2546
+ return this.__tnValidateInternal(buffer, __tnParams);
2547
+ }
2548
+ static footprintIr() {
2549
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2550
+ }
2551
+ static footprint() {
2552
+ const irResult = this.footprintIr();
2553
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
2554
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) {
2555
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for DestroyArgs");
2556
+ }
2557
+ return __tnBigIntToNumber2(irResult, "DestroyArgs::footprint");
2558
+ }
2559
+ static validate(buffer, _opts) {
2560
+ if (buffer.length < 4) return { ok: false, code: "tn.buffer_too_small", consumed: 4 };
2561
+ return { ok: true, consumed: 4 };
2562
+ }
2563
+ static new(buffer_account_idx, meta_account_idx) {
2564
+ const buffer = new Uint8Array(4);
2565
+ const view = new DataView(buffer.buffer);
2566
+ view.setUint16(0, buffer_account_idx, true);
2567
+ view.setUint16(2, meta_account_idx, true);
2568
+ return new _DestroyArgs(buffer);
2569
+ }
2570
+ static from_array(buffer) {
2571
+ if (!buffer || buffer.length === void 0) {
2572
+ return null;
2573
+ }
2574
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2575
+ const validation = this.validate(buffer);
2576
+ if (!validation.ok) {
2577
+ return null;
2578
+ }
2579
+ return new _DestroyArgs(buffer);
2580
+ }
2581
+ };
2582
+ var DestroyArgsBuilder = class {
2583
+ constructor() {
2584
+ this.buffer = new Uint8Array(4);
2585
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2586
+ }
2587
+ set_buffer_account_idx(value) {
2588
+ this.view.setUint16(0, value, true);
2589
+ return this;
2590
+ }
2591
+ set_meta_account_idx(value) {
2592
+ this.view.setUint16(2, value, true);
2593
+ return this;
2594
+ }
2595
+ build() {
2596
+ return this.buffer.slice();
2597
+ }
2598
+ buildInto(target, offset = 0) {
2599
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2600
+ target.set(this.buffer, offset);
2601
+ return target;
2602
+ }
2603
+ finish() {
2604
+ const view = DestroyArgs.from_array(this.buffer.slice());
2605
+ if (!view) throw new Error("failed to build DestroyArgs");
2606
+ return view;
2607
+ }
2608
+ };
2609
+ __tnRegisterFootprint2("DestroyArgs", (params) => DestroyArgs.__tnInvokeFootprint(params));
2610
+ __tnRegisterValidate2("DestroyArgs", (buffer, params) => DestroyArgs.__tnInvokeValidate(buffer, params));
2611
+ __tnRegisterDynamicValidate2("DestroyArgs", (buffer) => {
2612
+ const result = DestroyArgs.validate(buffer);
2613
+ const params = result.params;
2614
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
2615
+ });
2616
+ var __tn_ir_UploaderError = {
2617
+ typeName: "UploaderError",
2618
+ root: { op: "const", value: 8n }
2619
+ };
2620
+ var UploaderError = class _UploaderError {
2621
+ constructor(buffer) {
2622
+ this.buffer = buffer;
2623
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2624
+ }
2625
+ static __tnCreateView(buffer, opts) {
2626
+ if (!buffer || buffer.length === void 0) throw new Error("UploaderError.__tnCreateView requires a Uint8Array");
2627
+ return new _UploaderError(new Uint8Array(buffer));
2628
+ }
2629
+ static builder() {
2630
+ return new UploaderErrorBuilder();
2631
+ }
2632
+ static fromBuilder(builder) {
2633
+ const buffer = builder.build();
2634
+ return _UploaderError.from_array(buffer);
2635
+ }
2636
+ get_code() {
2637
+ const offset = 0;
2638
+ return this.view.getBigUint64(offset, true);
2639
+ }
2640
+ set_code(value) {
2641
+ const offset = 0;
2642
+ this.view.setBigUint64(offset, value, true);
2643
+ }
2644
+ get code() {
2645
+ return this.get_code();
2646
+ }
2647
+ set code(value) {
2648
+ this.set_code(value);
2649
+ }
2650
+ static __tnFootprintInternal(__tnParams) {
2651
+ return __tnEvalFootprint2(__tn_ir_UploaderError.root, { params: __tnParams });
2652
+ }
2653
+ static __tnValidateInternal(buffer, __tnParams) {
2654
+ return __tnValidateIrTree2(__tn_ir_UploaderError, buffer, __tnParams);
2655
+ }
2656
+ static __tnInvokeFootprint(__tnParams) {
2657
+ return this.__tnFootprintInternal(__tnParams);
2658
+ }
2659
+ static __tnInvokeValidate(buffer, __tnParams) {
2660
+ return this.__tnValidateInternal(buffer, __tnParams);
2661
+ }
2662
+ static footprintIr() {
2663
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2664
+ }
2665
+ static footprint() {
2666
+ const irResult = this.footprintIr();
2667
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
2668
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) {
2669
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for UploaderError");
2670
+ }
2671
+ return __tnBigIntToNumber2(irResult, "UploaderError::footprint");
2672
+ }
2673
+ static validate(buffer, _opts) {
2674
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
2675
+ return { ok: true, consumed: 8 };
2676
+ }
2677
+ static new(code) {
2678
+ const buffer = new Uint8Array(8);
2679
+ const view = new DataView(buffer.buffer);
2680
+ view.setBigUint64(0, code, true);
2681
+ return new _UploaderError(buffer);
2682
+ }
2683
+ static from_array(buffer) {
2684
+ if (!buffer || buffer.length === void 0) {
2685
+ return null;
2686
+ }
2687
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2688
+ const validation = this.validate(buffer);
2689
+ if (!validation.ok) {
2690
+ return null;
2691
+ }
2692
+ return new _UploaderError(buffer);
2693
+ }
2694
+ };
2695
+ var UploaderErrorBuilder = class {
2696
+ constructor() {
2697
+ this.buffer = new Uint8Array(8);
2698
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2699
+ }
2700
+ set_code(value) {
2701
+ const cast = __tnToBigInt2(value);
2702
+ this.view.setBigUint64(0, cast, true);
2703
+ return this;
2704
+ }
2705
+ build() {
2706
+ return this.buffer.slice();
2707
+ }
2708
+ buildInto(target, offset = 0) {
2709
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2710
+ target.set(this.buffer, offset);
2711
+ return target;
2712
+ }
2713
+ finish() {
2714
+ const view = UploaderError.from_array(this.buffer.slice());
2715
+ if (!view) throw new Error("failed to build UploaderError");
2716
+ return view;
2717
+ }
2718
+ };
2719
+ __tnRegisterFootprint2("UploaderError", (params) => UploaderError.__tnInvokeFootprint(params));
2720
+ __tnRegisterValidate2("UploaderError", (buffer, params) => UploaderError.__tnInvokeValidate(buffer, params));
2721
+ __tnRegisterDynamicValidate2("UploaderError", (buffer) => {
2722
+ const result = UploaderError.validate(buffer);
2723
+ const params = result.params;
2724
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
2725
+ });
2726
+ var __tn_ir_UploaderProgramMeta = {
2727
+ typeName: "UploaderProgramMeta",
2728
+ root: { op: "const", value: 65n }
2729
+ };
2730
+ var UploaderProgramMeta = class _UploaderProgramMeta {
2731
+ constructor(buffer) {
2732
+ this.buffer = buffer;
2733
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2734
+ }
2735
+ static __tnCreateView(buffer, opts) {
2736
+ if (!buffer || buffer.length === void 0) throw new Error("UploaderProgramMeta.__tnCreateView requires a Uint8Array");
2737
+ return new _UploaderProgramMeta(new Uint8Array(buffer));
2738
+ }
2739
+ static builder() {
2740
+ return new UploaderProgramMetaBuilder();
2741
+ }
2742
+ static fromBuilder(builder) {
2743
+ const buffer = builder.build();
2744
+ return _UploaderProgramMeta.from_array(buffer);
2745
+ }
2746
+ get_authority() {
2747
+ const offset = 0;
2748
+ const slice = this.buffer.subarray(offset, offset + 32);
2749
+ return Pubkey.from_array(slice);
2750
+ }
2751
+ set_authority(value) {
2752
+ const sourceBytes = value.buffer;
2753
+ const offset = 0;
2754
+ this.buffer.set(sourceBytes, offset);
2755
+ }
2756
+ get authority() {
2757
+ return this.get_authority();
2758
+ }
2759
+ set authority(value) {
2760
+ this.set_authority(value);
2761
+ }
2762
+ get_expected_account_hash() {
2763
+ const offset = 32;
2764
+ const slice = this.buffer.subarray(offset, offset + 32);
2765
+ return Hash.from_array(slice);
2766
+ }
2767
+ set_expected_account_hash(value) {
2768
+ const sourceBytes = value.buffer;
2769
+ const offset = 32;
2770
+ this.buffer.set(sourceBytes, offset);
2771
+ }
2772
+ get expected_account_hash() {
2773
+ return this.get_expected_account_hash();
2774
+ }
2775
+ set expected_account_hash(value) {
2776
+ this.set_expected_account_hash(value);
2777
+ }
2778
+ get_state() {
2779
+ const offset = 64;
2780
+ return this.view.getUint8(offset);
2781
+ }
2782
+ set_state(value) {
2783
+ const offset = 64;
2784
+ this.view.setUint8(offset, value);
2785
+ }
2786
+ get state() {
2787
+ return this.get_state();
2788
+ }
2789
+ set state(value) {
2790
+ this.set_state(value);
2791
+ }
2792
+ static __tnFootprintInternal(__tnParams) {
2793
+ return __tnEvalFootprint2(__tn_ir_UploaderProgramMeta.root, { params: __tnParams });
2794
+ }
2795
+ static __tnValidateInternal(buffer, __tnParams) {
2796
+ return __tnValidateIrTree2(__tn_ir_UploaderProgramMeta, buffer, __tnParams);
2797
+ }
2798
+ static __tnInvokeFootprint(__tnParams) {
2799
+ return this.__tnFootprintInternal(__tnParams);
2800
+ }
2801
+ static __tnInvokeValidate(buffer, __tnParams) {
2802
+ return this.__tnValidateInternal(buffer, __tnParams);
2803
+ }
2804
+ static footprintIr() {
2805
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2806
+ }
2807
+ static footprint() {
2808
+ const irResult = this.footprintIr();
2809
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
2810
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) {
2811
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for UploaderProgramMeta");
2812
+ }
2813
+ return __tnBigIntToNumber2(irResult, "UploaderProgramMeta::footprint");
2814
+ }
2815
+ static validate(buffer, _opts) {
2816
+ if (buffer.length < 65) return { ok: false, code: "tn.buffer_too_small", consumed: 65 };
2817
+ return { ok: true, consumed: 65 };
2818
+ }
2819
+ static from_array(buffer) {
2820
+ if (!buffer || buffer.length === void 0) {
2821
+ return null;
2822
+ }
2823
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2824
+ const validation = this.validate(buffer);
2825
+ if (!validation.ok) {
2826
+ return null;
2827
+ }
2828
+ return new _UploaderProgramMeta(buffer);
2829
+ }
2830
+ };
2831
+ var UploaderProgramMetaBuilder = class {
2832
+ constructor() {
2833
+ this.buffer = new Uint8Array(65);
2834
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2835
+ }
2836
+ set_authority(value) {
2837
+ if (value.length !== 32) throw new Error("authority expects 32 bytes");
2838
+ this.buffer.set(value, 0);
2839
+ return this;
2840
+ }
2841
+ set_expected_account_hash(value) {
2842
+ if (value.length !== 32) throw new Error("expected_account_hash expects 32 bytes");
2843
+ this.buffer.set(value, 32);
2844
+ return this;
2845
+ }
2846
+ set_state(value) {
2847
+ this.view.setUint8(64, value);
2848
+ return this;
2849
+ }
2850
+ build() {
2851
+ return this.buffer.slice();
2852
+ }
2853
+ buildInto(target, offset = 0) {
2854
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2855
+ target.set(this.buffer, offset);
2856
+ return target;
2857
+ }
2858
+ finish() {
2859
+ const view = UploaderProgramMeta.from_array(this.buffer.slice());
2860
+ if (!view) throw new Error("failed to build UploaderProgramMeta");
2861
+ return view;
2862
+ }
2863
+ };
2864
+ __tnRegisterFootprint2("UploaderProgramMeta", (params) => UploaderProgramMeta.__tnInvokeFootprint(params));
2865
+ __tnRegisterValidate2("UploaderProgramMeta", (buffer, params) => UploaderProgramMeta.__tnInvokeValidate(buffer, params));
2866
+ __tnRegisterDynamicValidate2("UploaderProgramMeta", (buffer) => {
2867
+ const result = UploaderProgramMeta.validate(buffer);
2868
+ const params = result.params;
2869
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
2870
+ });
2871
+ var __tn_ir_WriteArgs = {
2872
+ typeName: "WriteArgs",
2873
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "data.data_len" }, right: { op: "const", value: 1n } } } } }
2874
+ };
2875
+ var _WriteArgs = class _WriteArgs {
2876
+ constructor(buffer, params, fieldContext) {
2877
+ this.buffer = buffer;
2878
+ this.__tnFieldContext = null;
2879
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2880
+ this.__tnFieldContext = fieldContext ?? null;
2881
+ if (params) {
2882
+ this.__tnParams = params;
2883
+ } else {
2884
+ const derived = _WriteArgs.__tnExtractParams(this.view, buffer);
2885
+ if (!derived) {
2886
+ throw new Error("WriteArgs: failed to derive dynamic parameters");
2887
+ }
2888
+ this.__tnParams = derived.params;
2889
+ }
2890
+ }
2891
+ static __tnCreateView(buffer, opts) {
2892
+ if (!buffer || buffer.length === void 0) throw new Error("WriteArgs.__tnCreateView requires a Uint8Array");
2893
+ let params = opts?.params ?? null;
2894
+ if (!params) {
2895
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2896
+ const derived = _WriteArgs.__tnExtractParams(view, buffer);
2897
+ if (!derived) throw new Error("WriteArgs.__tnCreateView: failed to derive params");
2898
+ params = derived.params;
2899
+ }
2900
+ const instance = new _WriteArgs(new Uint8Array(buffer), params, opts?.fieldContext);
2901
+ return instance;
2902
+ }
2903
+ dynamicParams() {
2904
+ return this.__tnParams;
2905
+ }
2906
+ withFieldContext(context) {
2907
+ this.__tnFieldContext = context;
2908
+ return this;
2909
+ }
2910
+ __tnResolveFieldRef(path) {
2911
+ const getterName = `get_${path.replace(/[.]/g, "_")}`;
2912
+ const getter = this[getterName];
2913
+ if (typeof getter === "function") {
2914
+ const value = getter.call(this);
2915
+ return typeof value === "bigint" ? __tnBigIntToNumber2(value, "WriteArgs::__tnResolveFieldRef") : value;
2916
+ }
2917
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
2918
+ const contextValue = this.__tnFieldContext[path];
2919
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber2(contextValue, "WriteArgs::__tnResolveFieldRef") : contextValue;
2920
+ }
2921
+ throw new Error("WriteArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
2922
+ }
2923
+ static builder() {
2924
+ return new WriteArgsBuilder();
2925
+ }
2926
+ static fromBuilder(builder) {
2927
+ const buffer = builder.build();
2928
+ const params = builder.dynamicParams();
2929
+ return _WriteArgs.from_array(buffer, { params });
2930
+ }
2931
+ static __tnExtractParams(view, buffer) {
2932
+ if (buffer.length < 8) {
2933
+ return null;
2934
+ }
2935
+ const __tnParam_data_data_len = __tnToBigInt2(view.getUint32(4, true));
2936
+ const __tnExtractedParams = _WriteArgs.Params.fromValues({
2937
+ data_data_len: __tnParam_data_data_len
2938
+ });
2939
+ return { params: __tnExtractedParams, derived: null };
2940
+ }
2941
+ get_buffer_account_idx() {
2942
+ const offset = 0;
2943
+ return this.view.getUint16(offset, true);
2944
+ }
2945
+ set_buffer_account_idx(value) {
2946
+ const offset = 0;
2947
+ this.view.setUint16(offset, value, true);
2948
+ }
2949
+ get buffer_account_idx() {
2950
+ return this.get_buffer_account_idx();
2951
+ }
2952
+ set buffer_account_idx(value) {
2953
+ this.set_buffer_account_idx(value);
2954
+ }
2955
+ get_meta_account_idx() {
2956
+ const offset = 2;
2957
+ return this.view.getUint16(offset, true);
2958
+ }
2959
+ set_meta_account_idx(value) {
2960
+ const offset = 2;
2961
+ this.view.setUint16(offset, value, true);
2962
+ }
2963
+ get meta_account_idx() {
2964
+ return this.get_meta_account_idx();
2965
+ }
2966
+ set meta_account_idx(value) {
2967
+ this.set_meta_account_idx(value);
2968
+ }
2969
+ get_data_len() {
2970
+ const offset = 4;
2971
+ return this.view.getUint32(offset, true);
2972
+ }
2973
+ set_data_len(value) {
2974
+ const offset = 4;
2975
+ this.view.setUint32(offset, value, true);
2976
+ }
2977
+ get data_len() {
2978
+ return this.get_data_len();
2979
+ }
2980
+ set data_len(value) {
2981
+ this.set_data_len(value);
2982
+ }
2983
+ get_data_offset() {
2984
+ const offset = 8;
2985
+ return this.view.getUint32(offset, true);
2986
+ }
2987
+ set_data_offset(value) {
2988
+ const offset = 8;
2989
+ this.view.setUint32(offset, value, true);
2990
+ }
2991
+ get data_offset() {
2992
+ return this.get_data_offset();
2993
+ }
2994
+ set data_offset(value) {
2995
+ this.set_data_offset(value);
2996
+ }
2997
+ get_data_length() {
2998
+ return this.__tnResolveFieldRef("data_len");
2999
+ }
3000
+ get_data_at(index) {
3001
+ const offset = 12;
3002
+ return this.view.getUint8(offset + index * 1);
3003
+ }
3004
+ get_data() {
3005
+ const len = this.get_data_length();
3006
+ const result = [];
3007
+ for (let i = 0; i < len; i++) {
3008
+ result.push(this.get_data_at(i));
3009
+ }
3010
+ return result;
3011
+ }
3012
+ set_data_at(index, value) {
3013
+ const offset = 12;
3014
+ this.view.setUint8(offset + index * 1, value);
3015
+ }
3016
+ set_data(value) {
3017
+ const len = Math.min(this.get_data_length(), value.length);
3018
+ for (let i = 0; i < len; i++) {
3019
+ this.set_data_at(i, value[i]);
3020
+ }
3021
+ }
3022
+ get data() {
3023
+ return this.get_data();
3024
+ }
3025
+ set data(value) {
3026
+ this.set_data(value);
3027
+ }
3028
+ static __tnFootprintInternal(__tnParams) {
3029
+ return __tnEvalFootprint2(__tn_ir_WriteArgs.root, { params: __tnParams });
3030
+ }
3031
+ static __tnValidateInternal(buffer, __tnParams) {
3032
+ return __tnValidateIrTree2(__tn_ir_WriteArgs, buffer, __tnParams);
3033
+ }
3034
+ static __tnInvokeFootprint(__tnParams) {
3035
+ return this.__tnFootprintInternal(__tnParams);
3036
+ }
3037
+ static __tnInvokeValidate(buffer, __tnParams) {
3038
+ return this.__tnValidateInternal(buffer, __tnParams);
3039
+ }
3040
+ static footprintIr(data_data_len) {
3041
+ const params = _WriteArgs.Params.fromValues({
3042
+ data_data_len
3043
+ });
3044
+ return this.footprintIrFromParams(params);
3045
+ }
3046
+ static __tnPackParams(params) {
3047
+ const record = /* @__PURE__ */ Object.create(null);
3048
+ record["data.data_len"] = params.data_data_len;
3049
+ return record;
3050
+ }
3051
+ static footprintIrFromParams(params) {
3052
+ const __tnParams = this.__tnPackParams(params);
3053
+ return this.__tnFootprintInternal(__tnParams);
3054
+ }
3055
+ static footprintFromParams(params) {
3056
+ const irResult = this.footprintIrFromParams(params);
3057
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
3058
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for WriteArgs");
3059
+ return __tnBigIntToNumber2(irResult, "WriteArgs::footprintFromParams");
3060
+ }
3061
+ static footprintFromValues(input) {
3062
+ const params = _WriteArgs.params(input);
3063
+ return this.footprintFromParams(params);
3064
+ }
3065
+ static footprint(params) {
3066
+ return this.footprintFromParams(params);
3067
+ }
3068
+ static validate(buffer, opts) {
3069
+ if (!buffer || buffer.length === void 0) {
3070
+ return { ok: false, code: "tn.invalid_buffer" };
3071
+ }
3072
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3073
+ let params = opts?.params ?? null;
3074
+ if (!params) {
3075
+ const extracted = this.__tnExtractParams(view, buffer);
3076
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
3077
+ params = extracted.params;
3078
+ }
3079
+ const __tnParamsRec = this.__tnPackParams(params);
3080
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
3081
+ if (!irResult.ok) {
3082
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber2(irResult.consumed, "WriteArgs::validate") : void 0, params };
3083
+ }
3084
+ const consumed = irResult.consumed ? __tnBigIntToNumber2(irResult.consumed, "WriteArgs::validate") : void 0;
3085
+ return { ok: true, consumed, params };
3086
+ }
3087
+ static from_array(buffer, opts) {
3088
+ if (!buffer || buffer.length === void 0) {
3089
+ return null;
3090
+ }
3091
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3092
+ let params = opts?.params ?? null;
3093
+ if (!params) {
3094
+ const derived = this.__tnExtractParams(view, buffer);
3095
+ if (!derived) return null;
3096
+ params = derived.params;
3097
+ }
3098
+ const validation = this.validate(buffer, { params });
3099
+ if (!validation.ok) {
3100
+ return null;
3101
+ }
3102
+ const cached = validation.params ?? params;
3103
+ const state = new _WriteArgs(buffer, cached);
3104
+ return state;
3105
+ }
3106
+ };
3107
+ _WriteArgs.flexibleArrayWriters = Object.freeze([
3108
+ { field: "data", method: "data", sizeField: "data_len", paramKey: "data_len", elementSize: 1 }
3109
+ ]);
3110
+ var WriteArgs = _WriteArgs;
3111
+ ((WriteArgs2) => {
3112
+ WriteArgs2.ParamKeys = Object.freeze({
3113
+ data_data_len: "data.data_len"
3114
+ });
3115
+ WriteArgs2.Params = {
3116
+ fromValues(input) {
3117
+ return {
3118
+ data_data_len: __tnToBigInt2(input.data_data_len)
3119
+ };
3120
+ },
3121
+ fromBuilder(source) {
3122
+ if (source.dynamicParams) {
3123
+ return source.dynamicParams();
3124
+ }
3125
+ if (source.params) {
3126
+ return source.params;
3127
+ }
3128
+ return source;
3129
+ }
3130
+ };
3131
+ function params(input) {
3132
+ return WriteArgs2.Params.fromValues(input);
3133
+ }
3134
+ WriteArgs2.params = params;
3135
+ })(WriteArgs || (WriteArgs = {}));
3136
+ var WriteArgsBuilder = class {
3137
+ constructor() {
3138
+ this.__tnCachedParams = null;
3139
+ this.__tnLastBuffer = null;
3140
+ this.__tnLastParams = null;
3141
+ this.__tnFam_data = null;
3142
+ this.__tnFam_dataCount = null;
3143
+ this.buffer = new Uint8Array(12);
3144
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3145
+ }
3146
+ __tnInvalidate() {
3147
+ this.__tnCachedParams = null;
3148
+ this.__tnLastBuffer = null;
3149
+ this.__tnLastParams = null;
3150
+ }
3151
+ set_buffer_account_idx(value) {
3152
+ this.view.setUint16(0, value, true);
3153
+ this.__tnInvalidate();
3154
+ return this;
3155
+ }
3156
+ set_meta_account_idx(value) {
3157
+ this.view.setUint16(2, value, true);
3158
+ this.__tnInvalidate();
3159
+ return this;
3160
+ }
3161
+ set_data_len(value) {
3162
+ this.view.setUint32(4, value, true);
3163
+ this.__tnInvalidate();
3164
+ return this;
3165
+ }
3166
+ set_data_offset(value) {
3167
+ this.view.setUint32(8, value, true);
3168
+ this.__tnInvalidate();
3169
+ return this;
3170
+ }
3171
+ data() {
3172
+ if (!this.__tnFamWriter_data) {
3173
+ this.__tnFamWriter_data = __tnCreateFamWriter2(this, "data", (payload) => {
3174
+ const bytes = new Uint8Array(payload);
3175
+ const elementCount = bytes.length;
3176
+ this.__tnFam_data = bytes;
3177
+ this.__tnFam_dataCount = elementCount;
3178
+ this.set_data_len(elementCount);
3179
+ this.__tnInvalidate();
3180
+ });
3181
+ }
3182
+ return this.__tnFamWriter_data;
3183
+ }
3184
+ build() {
3185
+ const params = this.__tnComputeParams();
3186
+ const size = WriteArgs.footprintFromParams(params);
3187
+ const buffer = new Uint8Array(size);
3188
+ this.__tnWriteInto(buffer);
3189
+ this.__tnValidateOrThrow(buffer, params);
3190
+ return buffer;
3191
+ }
3192
+ buildInto(target, offset = 0) {
3193
+ const params = this.__tnComputeParams();
3194
+ const size = WriteArgs.footprintFromParams(params);
3195
+ if (target.length - offset < size) throw new Error("WriteArgsBuilder: target buffer too small");
3196
+ const slice = target.subarray(offset, offset + size);
3197
+ this.__tnWriteInto(slice);
3198
+ this.__tnValidateOrThrow(slice, params);
3199
+ return target;
3200
+ }
3201
+ finish() {
3202
+ const buffer = this.build();
3203
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
3204
+ const view = WriteArgs.from_array(buffer, { params });
3205
+ if (!view) throw new Error("WriteArgsBuilder: failed to finalize view");
3206
+ return view;
3207
+ }
3208
+ finishView() {
3209
+ return this.finish();
3210
+ }
3211
+ dynamicParams() {
3212
+ return this.__tnComputeParams();
3213
+ }
3214
+ __tnComputeParams() {
3215
+ if (this.__tnCachedParams) return this.__tnCachedParams;
3216
+ const params = WriteArgs.Params.fromValues({
3217
+ data_data_len: (() => {
3218
+ if (this.__tnFam_dataCount === null) throw new Error("WriteArgsBuilder: field 'data' must be written before computing params");
3219
+ return __tnToBigInt2(this.__tnFam_dataCount);
3220
+ })()
3221
+ });
3222
+ this.__tnCachedParams = params;
3223
+ return params;
3224
+ }
3225
+ __tnWriteInto(target) {
3226
+ target.set(this.buffer, 0);
3227
+ let cursor = this.buffer.length;
3228
+ const __tnLocal_data_bytes = this.__tnFam_data;
3229
+ if (!__tnLocal_data_bytes) throw new Error("WriteArgsBuilder: field 'data' must be written before build");
3230
+ target.set(__tnLocal_data_bytes, cursor);
3231
+ cursor += __tnLocal_data_bytes.length;
3232
+ }
3233
+ __tnValidateOrThrow(buffer, params) {
3234
+ const result = WriteArgs.validate(buffer, { params });
3235
+ if (!result.ok) {
3236
+ throw new Error(`${WriteArgs}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
3237
+ }
3238
+ this.__tnLastParams = result.params ?? params;
3239
+ this.__tnLastBuffer = buffer;
3240
+ }
3241
+ };
3242
+ __tnRegisterFootprint2("WriteArgs", (params) => WriteArgs.__tnInvokeFootprint(params));
3243
+ __tnRegisterValidate2("WriteArgs", (buffer, params) => WriteArgs.__tnInvokeValidate(buffer, params));
3244
+ __tnRegisterDynamicValidate2("WriteArgs", (buffer) => {
3245
+ const result = WriteArgs.validate(buffer);
3246
+ const params = result.params;
3247
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
3248
+ });
3249
+ var __tn_ir_CreateArgs = {
3250
+ typeName: "CreateArgs",
3251
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 1, node: { op: "const", value: 32n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "seed.seed_len" }, right: { op: "const", value: 1n } } } } }
3252
+ };
3253
+ var _CreateArgs = class _CreateArgs {
3254
+ constructor(buffer, params, fieldContext) {
3255
+ this.buffer = buffer;
3256
+ this.__tnFieldContext = null;
3257
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3258
+ this.__tnFieldContext = fieldContext ?? null;
3259
+ if (params) {
3260
+ this.__tnParams = params;
3261
+ } else {
3262
+ const derived = _CreateArgs.__tnExtractParams(this.view, buffer);
3263
+ if (!derived) {
3264
+ throw new Error("CreateArgs: failed to derive dynamic parameters");
3265
+ }
3266
+ this.__tnParams = derived.params;
3267
+ }
3268
+ }
3269
+ static __tnCreateView(buffer, opts) {
3270
+ if (!buffer || buffer.length === void 0) throw new Error("CreateArgs.__tnCreateView requires a Uint8Array");
3271
+ let params = opts?.params ?? null;
3272
+ if (!params) {
3273
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3274
+ const derived = _CreateArgs.__tnExtractParams(view, buffer);
3275
+ if (!derived) throw new Error("CreateArgs.__tnCreateView: failed to derive params");
3276
+ params = derived.params;
3277
+ }
3278
+ const instance = new _CreateArgs(new Uint8Array(buffer), params, opts?.fieldContext);
3279
+ return instance;
3280
+ }
3281
+ dynamicParams() {
3282
+ return this.__tnParams;
3283
+ }
3284
+ withFieldContext(context) {
3285
+ this.__tnFieldContext = context;
3286
+ return this;
3287
+ }
3288
+ __tnResolveFieldRef(path) {
3289
+ const getterName = `get_${path.replace(/[.]/g, "_")}`;
3290
+ const getter = this[getterName];
3291
+ if (typeof getter === "function") {
3292
+ const value = getter.call(this);
3293
+ return typeof value === "bigint" ? __tnBigIntToNumber2(value, "CreateArgs::__tnResolveFieldRef") : value;
3294
+ }
3295
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
3296
+ const contextValue = this.__tnFieldContext[path];
3297
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber2(contextValue, "CreateArgs::__tnResolveFieldRef") : contextValue;
3298
+ }
3299
+ throw new Error("CreateArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
3300
+ }
3301
+ static builder() {
3302
+ return new CreateArgsBuilder();
3303
+ }
3304
+ static fromBuilder(builder) {
3305
+ const buffer = builder.build();
3306
+ const params = builder.dynamicParams();
3307
+ return _CreateArgs.from_array(buffer, { params });
3308
+ }
3309
+ static __tnExtractParams(view, buffer) {
3310
+ if (buffer.length < 46) {
3311
+ return null;
3312
+ }
3313
+ const __tnParam_seed_seed_len = __tnToBigInt2(view.getUint32(42, true));
3314
+ const __tnExtractedParams = _CreateArgs.Params.fromValues({
3315
+ seed_seed_len: __tnParam_seed_seed_len
3316
+ });
3317
+ return { params: __tnExtractedParams, derived: null };
3318
+ }
3319
+ get_buffer_account_idx() {
3320
+ const offset = 0;
3321
+ return this.view.getUint16(offset, true);
3322
+ }
3323
+ set_buffer_account_idx(value) {
3324
+ const offset = 0;
3325
+ this.view.setUint16(offset, value, true);
3326
+ }
3327
+ get buffer_account_idx() {
3328
+ return this.get_buffer_account_idx();
3329
+ }
3330
+ set buffer_account_idx(value) {
3331
+ this.set_buffer_account_idx(value);
3332
+ }
3333
+ get_meta_account_idx() {
3334
+ const offset = 2;
3335
+ return this.view.getUint16(offset, true);
3336
+ }
3337
+ set_meta_account_idx(value) {
3338
+ const offset = 2;
3339
+ this.view.setUint16(offset, value, true);
3340
+ }
3341
+ get meta_account_idx() {
3342
+ return this.get_meta_account_idx();
3343
+ }
3344
+ set meta_account_idx(value) {
3345
+ this.set_meta_account_idx(value);
3346
+ }
3347
+ get_authority_account_idx() {
3348
+ const offset = 4;
3349
+ return this.view.getUint16(offset, true);
3350
+ }
3351
+ set_authority_account_idx(value) {
3352
+ const offset = 4;
3353
+ this.view.setUint16(offset, value, true);
3354
+ }
3355
+ get authority_account_idx() {
3356
+ return this.get_authority_account_idx();
3357
+ }
3358
+ set authority_account_idx(value) {
3359
+ this.set_authority_account_idx(value);
3360
+ }
3361
+ get_buffer_account_sz() {
3362
+ const offset = 6;
3363
+ return this.view.getUint32(offset, true);
3364
+ }
3365
+ set_buffer_account_sz(value) {
3366
+ const offset = 6;
3367
+ this.view.setUint32(offset, value, true);
3368
+ }
3369
+ get buffer_account_sz() {
3370
+ return this.get_buffer_account_sz();
3371
+ }
3372
+ set buffer_account_sz(value) {
3373
+ this.set_buffer_account_sz(value);
3374
+ }
3375
+ get_expected_account_hash() {
3376
+ const offset = 10;
3377
+ const slice = this.buffer.subarray(offset, offset + 32);
3378
+ return Hash.from_array(slice);
3379
+ }
3380
+ set_expected_account_hash(value) {
3381
+ const sourceBytes = value.buffer;
3382
+ const offset = 10;
3383
+ this.buffer.set(sourceBytes, offset);
3384
+ }
3385
+ get expected_account_hash() {
3386
+ return this.get_expected_account_hash();
3387
+ }
3388
+ set expected_account_hash(value) {
3389
+ this.set_expected_account_hash(value);
3390
+ }
3391
+ get_seed_len() {
3392
+ const offset = 42;
3393
+ return this.view.getUint32(offset, true);
3394
+ }
3395
+ set_seed_len(value) {
3396
+ const offset = 42;
3397
+ this.view.setUint32(offset, value, true);
3398
+ }
3399
+ get seed_len() {
3400
+ return this.get_seed_len();
3401
+ }
3402
+ set seed_len(value) {
3403
+ this.set_seed_len(value);
3404
+ }
3405
+ get_seed_length() {
3406
+ return this.__tnResolveFieldRef("seed_len");
3407
+ }
3408
+ get_seed_at(index) {
3409
+ const offset = 46;
3410
+ return this.view.getUint8(offset + index * 1);
3411
+ }
3412
+ get_seed() {
3413
+ const len = this.get_seed_length();
3414
+ const result = [];
3415
+ for (let i = 0; i < len; i++) {
3416
+ result.push(this.get_seed_at(i));
3417
+ }
3418
+ return result;
3419
+ }
3420
+ set_seed_at(index, value) {
3421
+ const offset = 46;
3422
+ this.view.setUint8(offset + index * 1, value);
3423
+ }
3424
+ set_seed(value) {
3425
+ const len = Math.min(this.get_seed_length(), value.length);
3426
+ for (let i = 0; i < len; i++) {
3427
+ this.set_seed_at(i, value[i]);
3428
+ }
3429
+ }
3430
+ get seed() {
3431
+ return this.get_seed();
3432
+ }
3433
+ set seed(value) {
3434
+ this.set_seed(value);
3435
+ }
3436
+ static __tnFootprintInternal(__tnParams) {
3437
+ return __tnEvalFootprint2(__tn_ir_CreateArgs.root, { params: __tnParams });
3438
+ }
3439
+ static __tnValidateInternal(buffer, __tnParams) {
3440
+ return __tnValidateIrTree2(__tn_ir_CreateArgs, buffer, __tnParams);
3441
+ }
3442
+ static __tnInvokeFootprint(__tnParams) {
3443
+ return this.__tnFootprintInternal(__tnParams);
3444
+ }
3445
+ static __tnInvokeValidate(buffer, __tnParams) {
3446
+ return this.__tnValidateInternal(buffer, __tnParams);
3447
+ }
3448
+ static footprintIr(seed_seed_len) {
3449
+ const params = _CreateArgs.Params.fromValues({
3450
+ seed_seed_len
3451
+ });
3452
+ return this.footprintIrFromParams(params);
3453
+ }
3454
+ static __tnPackParams(params) {
3455
+ const record = /* @__PURE__ */ Object.create(null);
3456
+ record["seed.seed_len"] = params.seed_seed_len;
3457
+ return record;
3458
+ }
3459
+ static footprintIrFromParams(params) {
3460
+ const __tnParams = this.__tnPackParams(params);
3461
+ return this.__tnFootprintInternal(__tnParams);
3462
+ }
3463
+ static footprintFromParams(params) {
3464
+ const irResult = this.footprintIrFromParams(params);
3465
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
3466
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CreateArgs");
3467
+ return __tnBigIntToNumber2(irResult, "CreateArgs::footprintFromParams");
3468
+ }
3469
+ static footprintFromValues(input) {
3470
+ const params = _CreateArgs.params(input);
3471
+ return this.footprintFromParams(params);
3472
+ }
3473
+ static footprint(params) {
3474
+ return this.footprintFromParams(params);
3475
+ }
3476
+ static validate(buffer, opts) {
3477
+ if (!buffer || buffer.length === void 0) {
3478
+ return { ok: false, code: "tn.invalid_buffer" };
3479
+ }
3480
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3481
+ let params = opts?.params ?? null;
3482
+ if (!params) {
3483
+ const extracted = this.__tnExtractParams(view, buffer);
3484
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
3485
+ params = extracted.params;
3486
+ }
3487
+ const __tnParamsRec = this.__tnPackParams(params);
3488
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
3489
+ if (!irResult.ok) {
3490
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber2(irResult.consumed, "CreateArgs::validate") : void 0, params };
3491
+ }
3492
+ const consumed = irResult.consumed ? __tnBigIntToNumber2(irResult.consumed, "CreateArgs::validate") : void 0;
3493
+ return { ok: true, consumed, params };
3494
+ }
3495
+ static from_array(buffer, opts) {
3496
+ if (!buffer || buffer.length === void 0) {
3497
+ return null;
3498
+ }
3499
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3500
+ let params = opts?.params ?? null;
3501
+ if (!params) {
3502
+ const derived = this.__tnExtractParams(view, buffer);
3503
+ if (!derived) return null;
3504
+ params = derived.params;
3505
+ }
3506
+ const validation = this.validate(buffer, { params });
3507
+ if (!validation.ok) {
3508
+ return null;
3509
+ }
3510
+ const cached = validation.params ?? params;
3511
+ const state = new _CreateArgs(buffer, cached);
3512
+ return state;
3513
+ }
3514
+ };
3515
+ _CreateArgs.flexibleArrayWriters = Object.freeze([
3516
+ { field: "seed", method: "seed", sizeField: "seed_len", paramKey: "seed_len", elementSize: 1 }
3517
+ ]);
3518
+ var CreateArgs = _CreateArgs;
3519
+ ((CreateArgs2) => {
3520
+ CreateArgs2.ParamKeys = Object.freeze({
3521
+ seed_seed_len: "seed.seed_len"
3522
+ });
3523
+ CreateArgs2.Params = {
3524
+ fromValues(input) {
3525
+ return {
3526
+ seed_seed_len: __tnToBigInt2(input.seed_seed_len)
3527
+ };
3528
+ },
3529
+ fromBuilder(source) {
3530
+ if (source.dynamicParams) {
3531
+ return source.dynamicParams();
3532
+ }
3533
+ if (source.params) {
3534
+ return source.params;
3535
+ }
3536
+ return source;
3537
+ }
3538
+ };
3539
+ function params(input) {
3540
+ return CreateArgs2.Params.fromValues(input);
3541
+ }
3542
+ CreateArgs2.params = params;
3543
+ })(CreateArgs || (CreateArgs = {}));
3544
+ var CreateArgsBuilder = class {
3545
+ constructor() {
3546
+ this.__tnCachedParams = null;
3547
+ this.__tnLastBuffer = null;
3548
+ this.__tnLastParams = null;
3549
+ this.__tnFam_seed = null;
3550
+ this.__tnFam_seedCount = null;
3551
+ this.buffer = new Uint8Array(46);
3552
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3553
+ }
3554
+ __tnInvalidate() {
3555
+ this.__tnCachedParams = null;
3556
+ this.__tnLastBuffer = null;
3557
+ this.__tnLastParams = null;
3558
+ }
3559
+ set_buffer_account_idx(value) {
3560
+ this.view.setUint16(0, value, true);
3561
+ this.__tnInvalidate();
3562
+ return this;
3563
+ }
3564
+ set_meta_account_idx(value) {
3565
+ this.view.setUint16(2, value, true);
3566
+ this.__tnInvalidate();
3567
+ return this;
3568
+ }
3569
+ set_authority_account_idx(value) {
3570
+ this.view.setUint16(4, value, true);
3571
+ this.__tnInvalidate();
3572
+ return this;
3573
+ }
3574
+ set_buffer_account_sz(value) {
3575
+ this.view.setUint32(6, value, true);
3576
+ this.__tnInvalidate();
3577
+ return this;
3578
+ }
3579
+ set_expected_account_hash(value) {
3580
+ if (value.length !== 32) throw new Error("expected_account_hash expects 32 bytes");
3581
+ this.buffer.set(value, 10);
3582
+ this.__tnInvalidate();
3583
+ return this;
3584
+ }
3585
+ set_seed_len(value) {
3586
+ this.view.setUint32(42, value, true);
3587
+ this.__tnInvalidate();
3588
+ return this;
3589
+ }
3590
+ seed() {
3591
+ if (!this.__tnFamWriter_seed) {
3592
+ this.__tnFamWriter_seed = __tnCreateFamWriter2(this, "seed", (payload) => {
3593
+ const bytes = new Uint8Array(payload);
3594
+ const elementCount = bytes.length;
3595
+ this.__tnFam_seed = bytes;
3596
+ this.__tnFam_seedCount = elementCount;
3597
+ this.set_seed_len(elementCount);
3598
+ this.__tnInvalidate();
3599
+ });
3600
+ }
3601
+ return this.__tnFamWriter_seed;
3602
+ }
3603
+ build() {
3604
+ const params = this.__tnComputeParams();
3605
+ const size = CreateArgs.footprintFromParams(params);
3606
+ const buffer = new Uint8Array(size);
3607
+ this.__tnWriteInto(buffer);
3608
+ this.__tnValidateOrThrow(buffer, params);
3609
+ return buffer;
3610
+ }
3611
+ buildInto(target, offset = 0) {
3612
+ const params = this.__tnComputeParams();
3613
+ const size = CreateArgs.footprintFromParams(params);
3614
+ if (target.length - offset < size) throw new Error("CreateArgsBuilder: target buffer too small");
3615
+ const slice = target.subarray(offset, offset + size);
3616
+ this.__tnWriteInto(slice);
3617
+ this.__tnValidateOrThrow(slice, params);
3618
+ return target;
3619
+ }
3620
+ finish() {
3621
+ const buffer = this.build();
3622
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
3623
+ const view = CreateArgs.from_array(buffer, { params });
3624
+ if (!view) throw new Error("CreateArgsBuilder: failed to finalize view");
3625
+ return view;
3626
+ }
3627
+ finishView() {
3628
+ return this.finish();
3629
+ }
3630
+ dynamicParams() {
3631
+ return this.__tnComputeParams();
3632
+ }
3633
+ __tnComputeParams() {
3634
+ if (this.__tnCachedParams) return this.__tnCachedParams;
3635
+ const params = CreateArgs.Params.fromValues({
3636
+ seed_seed_len: (() => {
3637
+ if (this.__tnFam_seedCount === null) throw new Error("CreateArgsBuilder: field 'seed' must be written before computing params");
3638
+ return __tnToBigInt2(this.__tnFam_seedCount);
3639
+ })()
3640
+ });
3641
+ this.__tnCachedParams = params;
3642
+ return params;
3643
+ }
3644
+ __tnWriteInto(target) {
3645
+ target.set(this.buffer, 0);
3646
+ let cursor = this.buffer.length;
3647
+ const __tnLocal_seed_bytes = this.__tnFam_seed;
3648
+ if (!__tnLocal_seed_bytes) throw new Error("CreateArgsBuilder: field 'seed' must be written before build");
3649
+ target.set(__tnLocal_seed_bytes, cursor);
3650
+ cursor += __tnLocal_seed_bytes.length;
3651
+ }
3652
+ __tnValidateOrThrow(buffer, params) {
3653
+ const result = CreateArgs.validate(buffer, { params });
3654
+ if (!result.ok) {
3655
+ throw new Error(`${CreateArgs}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
3656
+ }
3657
+ this.__tnLastParams = result.params ?? params;
3658
+ this.__tnLastBuffer = buffer;
3659
+ }
3660
+ };
3661
+ __tnRegisterFootprint2("CreateArgs", (params) => CreateArgs.__tnInvokeFootprint(params));
3662
+ __tnRegisterValidate2("CreateArgs", (buffer, params) => CreateArgs.__tnInvokeValidate(buffer, params));
3663
+ __tnRegisterDynamicValidate2("CreateArgs", (buffer) => {
3664
+ const result = CreateArgs.validate(buffer);
3665
+ const params = result.params;
3666
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
3667
+ });
3668
+ var __tn_ir_FinalizeArgs = {
3669
+ typeName: "FinalizeArgs",
3670
+ root: { op: "const", value: 36n }
3671
+ };
3672
+ var FinalizeArgs = class _FinalizeArgs {
3673
+ constructor(buffer) {
3674
+ this.buffer = buffer;
3675
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3676
+ }
3677
+ static __tnCreateView(buffer, opts) {
3678
+ if (!buffer || buffer.length === void 0) throw new Error("FinalizeArgs.__tnCreateView requires a Uint8Array");
3679
+ return new _FinalizeArgs(new Uint8Array(buffer));
3680
+ }
3681
+ static builder() {
3682
+ return new FinalizeArgsBuilder();
3683
+ }
3684
+ static fromBuilder(builder) {
3685
+ const buffer = builder.build();
3686
+ return _FinalizeArgs.from_array(buffer);
3687
+ }
3688
+ get_buffer_account_idx() {
3689
+ const offset = 0;
3690
+ return this.view.getUint16(offset, true);
3691
+ }
3692
+ set_buffer_account_idx(value) {
3693
+ const offset = 0;
3694
+ this.view.setUint16(offset, value, true);
3695
+ }
3696
+ get buffer_account_idx() {
3697
+ return this.get_buffer_account_idx();
3698
+ }
3699
+ set buffer_account_idx(value) {
3700
+ this.set_buffer_account_idx(value);
3701
+ }
3702
+ get_meta_account_idx() {
3703
+ const offset = 2;
3704
+ return this.view.getUint16(offset, true);
3705
+ }
3706
+ set_meta_account_idx(value) {
3707
+ const offset = 2;
3708
+ this.view.setUint16(offset, value, true);
3709
+ }
3710
+ get meta_account_idx() {
3711
+ return this.get_meta_account_idx();
3712
+ }
3713
+ set meta_account_idx(value) {
3714
+ this.set_meta_account_idx(value);
3715
+ }
3716
+ get_expected_account_hash() {
3717
+ const offset = 4;
3718
+ const slice = this.buffer.subarray(offset, offset + 32);
3719
+ return Hash.from_array(slice);
3720
+ }
3721
+ set_expected_account_hash(value) {
3722
+ const sourceBytes = value.buffer;
3723
+ const offset = 4;
3724
+ this.buffer.set(sourceBytes, offset);
3725
+ }
3726
+ get expected_account_hash() {
3727
+ return this.get_expected_account_hash();
3728
+ }
3729
+ set expected_account_hash(value) {
3730
+ this.set_expected_account_hash(value);
3731
+ }
3732
+ static __tnFootprintInternal(__tnParams) {
3733
+ return __tnEvalFootprint2(__tn_ir_FinalizeArgs.root, { params: __tnParams });
3734
+ }
3735
+ static __tnValidateInternal(buffer, __tnParams) {
3736
+ return __tnValidateIrTree2(__tn_ir_FinalizeArgs, buffer, __tnParams);
3737
+ }
3738
+ static __tnInvokeFootprint(__tnParams) {
3739
+ return this.__tnFootprintInternal(__tnParams);
3740
+ }
3741
+ static __tnInvokeValidate(buffer, __tnParams) {
3742
+ return this.__tnValidateInternal(buffer, __tnParams);
3743
+ }
3744
+ static footprintIr() {
3745
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
3746
+ }
3747
+ static footprint() {
3748
+ const irResult = this.footprintIr();
3749
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
3750
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) {
3751
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for FinalizeArgs");
3752
+ }
3753
+ return __tnBigIntToNumber2(irResult, "FinalizeArgs::footprint");
3754
+ }
3755
+ static validate(buffer, _opts) {
3756
+ if (buffer.length < 36) return { ok: false, code: "tn.buffer_too_small", consumed: 36 };
3757
+ return { ok: true, consumed: 36 };
3758
+ }
3759
+ static from_array(buffer) {
3760
+ if (!buffer || buffer.length === void 0) {
3761
+ return null;
3762
+ }
3763
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3764
+ const validation = this.validate(buffer);
3765
+ if (!validation.ok) {
3766
+ return null;
3767
+ }
3768
+ return new _FinalizeArgs(buffer);
3769
+ }
3770
+ };
3771
+ var FinalizeArgsBuilder = class {
3772
+ constructor() {
3773
+ this.buffer = new Uint8Array(36);
3774
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3775
+ }
3776
+ set_buffer_account_idx(value) {
3777
+ this.view.setUint16(0, value, true);
3778
+ return this;
3779
+ }
3780
+ set_meta_account_idx(value) {
3781
+ this.view.setUint16(2, value, true);
3782
+ return this;
3783
+ }
3784
+ set_expected_account_hash(value) {
3785
+ if (value.length !== 32) throw new Error("expected_account_hash expects 32 bytes");
3786
+ this.buffer.set(value, 4);
3787
+ return this;
3788
+ }
3789
+ build() {
3790
+ return this.buffer.slice();
3791
+ }
3792
+ buildInto(target, offset = 0) {
3793
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
3794
+ target.set(this.buffer, offset);
3795
+ return target;
3796
+ }
3797
+ finish() {
3798
+ const view = FinalizeArgs.from_array(this.buffer.slice());
3799
+ if (!view) throw new Error("failed to build FinalizeArgs");
3800
+ return view;
3801
+ }
3802
+ };
3803
+ __tnRegisterFootprint2("FinalizeArgs", (params) => FinalizeArgs.__tnInvokeFootprint(params));
3804
+ __tnRegisterValidate2("FinalizeArgs", (buffer, params) => FinalizeArgs.__tnInvokeValidate(buffer, params));
3805
+ __tnRegisterDynamicValidate2("FinalizeArgs", (buffer) => {
3806
+ const result = FinalizeArgs.validate(buffer);
3807
+ const params = result.params;
3808
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
3809
+ });
3810
+ var __tn_ir_UploaderInstruction = {
3811
+ typeName: "UploaderInstruction",
3812
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 4, node: { op: "const", value: 4n } }, right: { op: "align", alignment: 1, node: { op: "field", param: "payload.payload_size" } } } }
3813
+ };
3814
+ var UploaderInstruction_payload_Inner = class _UploaderInstruction_payload_Inner {
3815
+ constructor(buffer, descriptor, fieldContext) {
3816
+ this.buffer = buffer;
3817
+ this.descriptor = descriptor;
3818
+ this.__tnFieldContext = null;
3819
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3820
+ this.__tnFieldContext = fieldContext ?? null;
3821
+ }
3822
+ static __tnCreate(payload, descriptor, fieldContext) {
3823
+ return new _UploaderInstruction_payload_Inner(new Uint8Array(payload), descriptor, fieldContext);
3824
+ }
3825
+ bytes() {
3826
+ return new Uint8Array(this.buffer);
3827
+ }
3828
+ variant() {
3829
+ return this.descriptor;
3830
+ }
3831
+ asCreate() {
3832
+ if (!this.descriptor || this.descriptor.tag !== 0) return null;
3833
+ return CreateArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
3834
+ }
3835
+ asWrite() {
3836
+ if (!this.descriptor || this.descriptor.tag !== 1) return null;
3837
+ return WriteArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
3838
+ }
3839
+ asDestroy() {
3840
+ if (!this.descriptor || this.descriptor.tag !== 2) return null;
3841
+ return DestroyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
3842
+ }
3843
+ asFinalize() {
3844
+ if (!this.descriptor || this.descriptor.tag !== 3) return null;
3845
+ return FinalizeArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
3846
+ }
3847
+ };
3848
+ var _UploaderInstruction = class _UploaderInstruction {
3849
+ constructor(buffer, params) {
3850
+ this.buffer = buffer;
3851
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3852
+ if (params) {
3853
+ this.__tnParams = params;
3854
+ } else {
3855
+ const derived = _UploaderInstruction.__tnExtractParams(this.view, buffer);
3856
+ if (!derived) {
3857
+ throw new Error("UploaderInstruction: failed to derive dynamic parameters");
3858
+ }
3859
+ this.__tnParams = derived.params;
3860
+ }
3861
+ }
3862
+ static __tnCreateView(buffer, opts) {
3863
+ if (!buffer || buffer.length === void 0) throw new Error("UploaderInstruction.__tnCreateView requires a Uint8Array");
3864
+ let params = opts?.params ?? null;
3865
+ if (!params) {
3866
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3867
+ const derived = _UploaderInstruction.__tnExtractParams(view, buffer);
3868
+ if (!derived) throw new Error("UploaderInstruction.__tnCreateView: failed to derive params");
3869
+ params = derived.params;
3870
+ }
3871
+ const instance = new _UploaderInstruction(new Uint8Array(buffer), params);
3872
+ return instance;
3873
+ }
3874
+ dynamicParams() {
3875
+ return this.__tnParams;
3876
+ }
3877
+ static builder() {
3878
+ return new UploaderInstructionBuilder();
3879
+ }
3880
+ static fromBuilder(builder) {
3881
+ const buffer = builder.build();
3882
+ const params = builder.dynamicParams();
3883
+ return _UploaderInstruction.from_array(buffer, { params });
3884
+ }
3885
+ static __tnComputeSequentialLayout(view, buffer) {
3886
+ const __tnLength = buffer.length;
3887
+ let __tnParamSeq_payload_payload_size = null;
3888
+ let __tnFieldValue_tag = null;
3889
+ let __tnCursorMutable = 0;
3890
+ if (__tnCursorMutable + 4 > __tnLength) return null;
3891
+ const __tnRead_tag = view.getUint32(__tnCursorMutable, true);
3892
+ __tnFieldValue_tag = __tnRead_tag;
3893
+ __tnCursorMutable += 4;
3894
+ const __tnEnumTagValue_payload = __tnFieldValue_tag;
3895
+ if (__tnEnumTagValue_payload === null) return null;
3896
+ let __tnEnumSize_payload = 0;
3897
+ switch (Number(__tnEnumTagValue_payload)) {
3898
+ case 0:
3899
+ break;
3900
+ case 1:
3901
+ break;
3902
+ case 2:
3903
+ break;
3904
+ case 3:
3905
+ break;
3906
+ default:
3907
+ return null;
3908
+ }
3909
+ if (__tnCursorMutable > __tnLength) return null;
3910
+ __tnEnumSize_payload = __tnLength - __tnCursorMutable;
3911
+ __tnCursorMutable = __tnLength;
3912
+ __tnParamSeq_payload_payload_size = __tnToBigInt2(__tnEnumSize_payload);
3913
+ const params = /* @__PURE__ */ Object.create(null);
3914
+ if (__tnParamSeq_payload_payload_size === null) return null;
3915
+ params["payload_payload_size"] = __tnParamSeq_payload_payload_size;
3916
+ return { params, offsets: null, derived: null };
3917
+ }
3918
+ static __tnExtractParams(view, buffer) {
3919
+ if (buffer.length < 4) {
3920
+ return null;
3921
+ }
3922
+ const __tnParam_payload_tag = __tnToBigInt2(view.getUint32(0, true));
3923
+ const __tnLayout = _UploaderInstruction.__tnComputeSequentialLayout(view, buffer);
3924
+ if (!__tnLayout || !__tnLayout.params) return null;
3925
+ const __tnSeqParams = __tnLayout.params;
3926
+ const __tnParamSeq_payload_payload_size = __tnSeqParams["payload_payload_size"];
3927
+ if (__tnParamSeq_payload_payload_size === void 0) return null;
3928
+ const __tnExtractedParams = _UploaderInstruction.Params.fromValues({
3929
+ payload_payload_size: __tnParamSeq_payload_payload_size,
3930
+ payload_tag: __tnParam_payload_tag
3931
+ });
3932
+ return { params: __tnExtractedParams, derived: null };
3933
+ }
3934
+ get_tag() {
3935
+ const offset = 0;
3936
+ return this.view.getUint32(offset, true);
3937
+ }
3938
+ set_tag(value) {
3939
+ const offset = 0;
3940
+ this.view.setUint32(offset, value, true);
3941
+ }
3942
+ get tag() {
3943
+ return this.get_tag();
3944
+ }
3945
+ set tag(value) {
3946
+ this.set_tag(value);
3947
+ }
3948
+ payloadVariant() {
3949
+ const tag = this.view.getUint8(0);
3950
+ return _UploaderInstruction.payloadVariantDescriptors.find((variant) => variant.tag === tag) ?? null;
3951
+ }
3952
+ payload() {
3953
+ const descriptor = this.payloadVariant();
3954
+ if (!descriptor) throw new Error("UploaderInstruction: unknown payload variant");
3955
+ const offset = _UploaderInstruction.__tnFieldOffset_payload;
3956
+ const remaining = this.buffer.length - offset;
3957
+ const payloadLength = descriptor.payloadSize ?? remaining;
3958
+ if (payloadLength < 0 || offset + payloadLength > this.buffer.length) throw new Error("UploaderInstruction: payload exceeds buffer bounds");
3959
+ const slice = this.buffer.subarray(offset, offset + payloadLength);
3960
+ return UploaderInstruction_payload_Inner.__tnCreate(slice, descriptor, void 0);
3961
+ }
3962
+ static __tnFootprintInternal(__tnParams) {
3963
+ return __tnEvalFootprint2(__tn_ir_UploaderInstruction.root, { params: __tnParams });
3964
+ }
3965
+ static __tnValidateInternal(buffer, __tnParams) {
3966
+ return __tnValidateIrTree2(__tn_ir_UploaderInstruction, buffer, __tnParams);
3967
+ }
3968
+ static __tnInvokeFootprint(__tnParams) {
3969
+ return this.__tnFootprintInternal(__tnParams);
3970
+ }
3971
+ static __tnInvokeValidate(buffer, __tnParams) {
3972
+ return this.__tnValidateInternal(buffer, __tnParams);
3973
+ }
3974
+ static footprintIr(payload_payload_size, payload_tag) {
3975
+ const params = _UploaderInstruction.Params.fromValues({
3976
+ payload_payload_size,
3977
+ payload_tag
3978
+ });
3979
+ return this.footprintIrFromParams(params);
3980
+ }
3981
+ static __tnPackParams(params) {
3982
+ const record = /* @__PURE__ */ Object.create(null);
3983
+ record["payload.payload_size"] = params.payload_payload_size;
3984
+ record["payload.tag"] = params.payload_tag;
3985
+ return record;
3986
+ }
3987
+ static footprintIrFromParams(params) {
3988
+ const __tnParams = this.__tnPackParams(params);
3989
+ return this.__tnFootprintInternal(__tnParams);
3990
+ }
3991
+ static footprintFromParams(params) {
3992
+ const irResult = this.footprintIrFromParams(params);
3993
+ const maxSafe = __tnToBigInt2(Number.MAX_SAFE_INTEGER);
3994
+ if (__tnBigIntGreaterThan2(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for UploaderInstruction");
3995
+ return __tnBigIntToNumber2(irResult, "UploaderInstruction::footprintFromParams");
3996
+ }
3997
+ static footprintFromValues(input) {
3998
+ const params = _UploaderInstruction.params(input);
3999
+ return this.footprintFromParams(params);
4000
+ }
4001
+ static footprint(params) {
4002
+ return this.footprintFromParams(params);
4003
+ }
4004
+ static validate(buffer, opts) {
4005
+ if (!buffer || buffer.length === void 0) {
4006
+ return { ok: false, code: "tn.invalid_buffer" };
4007
+ }
4008
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4009
+ let params = opts?.params ?? null;
4010
+ if (!params) {
4011
+ const extracted = this.__tnExtractParams(view, buffer);
4012
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
4013
+ params = extracted.params;
4014
+ }
4015
+ const __tnParamsRec = this.__tnPackParams(params);
4016
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
4017
+ if (!irResult.ok) {
4018
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber2(irResult.consumed, "UploaderInstruction::validate") : void 0, params };
4019
+ }
4020
+ const consumed = irResult.consumed ? __tnBigIntToNumber2(irResult.consumed, "UploaderInstruction::validate") : void 0;
4021
+ return { ok: true, consumed, params };
4022
+ }
4023
+ static from_array(buffer, opts) {
4024
+ if (!buffer || buffer.length === void 0) {
4025
+ return null;
4026
+ }
4027
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4028
+ let params = opts?.params ?? null;
4029
+ if (!params) {
4030
+ const derived = this.__tnExtractParams(view, buffer);
4031
+ if (!derived) return null;
4032
+ params = derived.params;
4033
+ }
4034
+ const validation = this.validate(buffer, { params });
4035
+ if (!validation.ok) {
4036
+ return null;
4037
+ }
4038
+ const cached = validation.params ?? params;
4039
+ const state = new _UploaderInstruction(buffer, cached);
4040
+ return state;
4041
+ }
4042
+ };
4043
+ _UploaderInstruction.__tnFieldOffset_payload = 4;
4044
+ _UploaderInstruction.payloadVariantDescriptors = Object.freeze([
4045
+ {
4046
+ name: "create",
4047
+ tag: 0,
4048
+ payloadSize: null,
4049
+ payloadType: "UploaderInstruction::payload::create",
4050
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CreateArgs)
4051
+ },
4052
+ {
4053
+ name: "write",
4054
+ tag: 1,
4055
+ payloadSize: null,
4056
+ payloadType: "UploaderInstruction::payload::write",
4057
+ createPayloadBuilder: () => __tnMaybeCallBuilder(WriteArgs)
4058
+ },
4059
+ {
4060
+ name: "destroy",
4061
+ tag: 2,
4062
+ payloadSize: 4,
4063
+ payloadType: "UploaderInstruction::payload::destroy",
4064
+ createPayloadBuilder: () => __tnMaybeCallBuilder(DestroyArgs)
4065
+ },
4066
+ {
4067
+ name: "finalize",
4068
+ tag: 3,
4069
+ payloadSize: 36,
4070
+ payloadType: "UploaderInstruction::payload::finalize",
4071
+ createPayloadBuilder: () => __tnMaybeCallBuilder(FinalizeArgs)
4072
+ }
4073
+ ]);
4074
+ var UploaderInstruction = _UploaderInstruction;
4075
+ ((UploaderInstruction3) => {
4076
+ UploaderInstruction3.ParamKeys = Object.freeze({
4077
+ payload_payload_size: "payload.payload_size",
4078
+ payload_tag: "payload.tag"
4079
+ });
4080
+ UploaderInstruction3.Params = {
4081
+ fromValues(input) {
4082
+ return {
4083
+ payload_payload_size: __tnToBigInt2(input.payload_payload_size),
4084
+ payload_tag: __tnToBigInt2(input.payload_tag)
4085
+ };
4086
+ },
4087
+ fromBuilder(source) {
4088
+ if (source.dynamicParams) {
4089
+ return source.dynamicParams();
4090
+ }
4091
+ if (source.params) {
4092
+ return source.params;
4093
+ }
4094
+ return source;
4095
+ }
4096
+ };
4097
+ function params(input) {
4098
+ return UploaderInstruction3.Params.fromValues(input);
4099
+ }
4100
+ UploaderInstruction3.params = params;
4101
+ })(UploaderInstruction || (UploaderInstruction = {}));
4102
+ var UploaderInstructionBuilder = class {
4103
+ constructor() {
4104
+ this.__tnField_tag = null;
4105
+ this.__tnPayload_payload = null;
4106
+ this.__tnCachedParams = null;
4107
+ this.__tnLastBuffer = null;
4108
+ this.__tnLastParams = null;
4109
+ this.__tnPrefixBuffer = new Uint8Array(4);
4110
+ this.__tnPrefixView = new DataView(this.__tnPrefixBuffer.buffer, this.__tnPrefixBuffer.byteOffset, this.__tnPrefixBuffer.byteLength);
4111
+ }
4112
+ __tnInvalidate() {
4113
+ this.__tnCachedParams = null;
4114
+ this.__tnLastBuffer = null;
4115
+ this.__tnLastParams = null;
4116
+ }
4117
+ __tnAssign_tag(value) {
4118
+ this.__tnField_tag = value;
4119
+ this.__tnInvalidate();
4120
+ }
4121
+ set_tag(value) {
4122
+ this.__tnAssign_tag(value);
4123
+ return this;
4124
+ }
4125
+ payload() {
4126
+ if (!this.__tnVariantSelector_payload) {
4127
+ this.__tnVariantSelector_payload = __tnCreateVariantSelector(this, UploaderInstruction.payloadVariantDescriptors, (descriptor, payload) => {
4128
+ this.__tnPayload_payload = { descriptor, bytes: new Uint8Array(payload) };
4129
+ this.__tnAssign_tag(descriptor.tag);
4130
+ });
4131
+ }
4132
+ return this.__tnVariantSelector_payload;
4133
+ }
4134
+ build() {
4135
+ const params = this.__tnComputeParams();
4136
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: field 'tag' must be set before build");
4137
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload variant not selected");
4138
+ const payloadLength = this.__tnPayload_payload.bytes.length;
4139
+ const requiredSize = 4 + payloadLength;
4140
+ const footprintSize = UploaderInstruction.footprintFromParams(params);
4141
+ const size = Math.max(requiredSize, footprintSize);
4142
+ const buffer = new Uint8Array(size);
4143
+ this.__tnWriteInto(buffer);
4144
+ this.__tnValidateOrThrow(buffer, params);
4145
+ return buffer;
4146
+ }
4147
+ buildInto(target, offset = 0) {
4148
+ const params = this.__tnComputeParams();
4149
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: field 'tag' must be set before build");
4150
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload variant not selected");
4151
+ const payloadLength = this.__tnPayload_payload.bytes.length;
4152
+ const requiredSize = 4 + payloadLength;
4153
+ const footprintSize = UploaderInstruction.footprintFromParams(params);
4154
+ const size = Math.max(requiredSize, footprintSize);
4155
+ if (target.length - offset < size) throw new Error("UploaderInstructionBuilder: target buffer too small");
4156
+ const slice = target.subarray(offset, offset + size);
4157
+ this.__tnWriteInto(slice);
4158
+ this.__tnValidateOrThrow(slice, params);
4159
+ return target;
4160
+ }
4161
+ finish() {
4162
+ const buffer = this.build();
4163
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
4164
+ const view = UploaderInstruction.from_array(buffer, { params });
4165
+ if (!view) throw new Error("UploaderInstructionBuilder: failed to finalize view");
4166
+ return view;
4167
+ }
4168
+ finishView() {
4169
+ return this.finish();
4170
+ }
4171
+ dynamicParams() {
4172
+ return this.__tnComputeParams();
4173
+ }
4174
+ __tnComputeParams() {
4175
+ if (this.__tnCachedParams) return this.__tnCachedParams;
4176
+ const params = UploaderInstruction.Params.fromValues({
4177
+ payload_payload_size: (() => {
4178
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload 'payload' must be selected before build");
4179
+ return __tnToBigInt2(this.__tnPayload_payload.bytes.length);
4180
+ })(),
4181
+ payload_tag: (() => {
4182
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: missing enum tag");
4183
+ return __tnToBigInt2(this.__tnField_tag);
4184
+ })()
4185
+ });
4186
+ this.__tnCachedParams = params;
4187
+ return params;
4188
+ }
4189
+ __tnWriteInto(target) {
4190
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: field 'tag' must be set before build");
4191
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload variant not selected");
4192
+ const view = new DataView(target.buffer, target.byteOffset, target.byteLength);
4193
+ target.set(this.__tnPrefixBuffer, 0);
4194
+ view.setUint32(0, this.__tnField_tag, true);
4195
+ target.set(this.__tnPayload_payload.bytes, 4);
4196
+ }
4197
+ __tnValidateOrThrow(buffer, params) {
4198
+ const result = UploaderInstruction.validate(buffer, { params });
4199
+ if (!result.ok) {
4200
+ throw new Error(`${UploaderInstruction}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
4201
+ }
4202
+ this.__tnLastParams = result.params ?? params;
4203
+ this.__tnLastBuffer = buffer;
4204
+ }
4205
+ };
4206
+ __tnRegisterFootprint2("UploaderInstruction", (params) => UploaderInstruction.__tnInvokeFootprint(params));
4207
+ __tnRegisterValidate2("UploaderInstruction", (buffer, params) => UploaderInstruction.__tnInvokeValidate(buffer, params));
4208
+ __tnRegisterDynamicValidate2("UploaderInstruction", (buffer) => {
4209
+ const result = UploaderInstruction.validate(buffer);
4210
+ const params = result.params;
4211
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
4212
+ });
4213
+
4214
+ // src/uploader/accounts.ts
4215
+ function parseUploaderProgramMeta(account) {
4216
+ const data = accountData(account, "uploader metadata account");
4217
+ if (data.length !== UPLOADER_META_SIZE) {
4218
+ throw new Error(
4219
+ `uploader metadata account must be ${UPLOADER_META_SIZE} bytes, got ${data.length}`
4220
+ );
4221
+ }
4222
+ const parsed = UploaderProgramMeta.from_array(data);
4223
+ if (!parsed) throw new Error("uploader metadata account is malformed");
4224
+ const state = parsed.get_state();
4225
+ if (state !== UPLOADER_STATE_OPEN && state !== UPLOADER_STATE_FINALIZED) {
4226
+ throw new Error(`uploader metadata account has invalid state ${state}`);
4227
+ }
4228
+ return {
4229
+ authorityAddress: pubkeyAddress(
4230
+ Uint8Array.from(parsed.get_authority().get_bytes())
4231
+ ),
4232
+ expectedHash: Uint8Array.from(
4233
+ parsed.get_expected_account_hash().get_bytes()
4234
+ ),
4235
+ state
4236
+ };
4237
+ }
4238
+
4239
+ // src/uploader/instructions.ts
4240
+ function envelope(variant, payload) {
4241
+ return new UploaderInstructionBuilder().payload().select(variant).writePayload(payload).finish().build();
4242
+ }
4243
+ function validateIndices(args) {
4244
+ assertU16(args.bufferAccountIdx, "bufferAccountIdx");
4245
+ assertU16(args.metaAccountIdx, "metaAccountIdx");
4246
+ }
4247
+ function buildUploaderInstructionBytes(args) {
4248
+ validateIndices(args);
4249
+ switch (args.kind) {
4250
+ case "create": {
4251
+ assertU16(args.authorityAccountIdx, "authorityAccountIdx");
4252
+ assertU32(args.bufferSize, "bufferSize");
4253
+ const builder = new CreateArgsBuilder().set_buffer_account_idx(args.bufferAccountIdx).set_meta_account_idx(args.metaAccountIdx).set_authority_account_idx(args.authorityAccountIdx).set_buffer_account_sz(args.bufferSize).set_expected_account_hash(
4254
+ exactBytes(args.expectedHash, 32, "expectedHash")
4255
+ );
4256
+ builder.seed().write(normalizeSeed(args.seed)).finish();
4257
+ return envelope("create", builder.build());
4258
+ }
4259
+ case "write": {
4260
+ assertU32(args.offset, "offset");
4261
+ assertU32(args.data.length, "data length");
4262
+ const builder = new WriteArgsBuilder().set_buffer_account_idx(args.bufferAccountIdx).set_meta_account_idx(args.metaAccountIdx).set_data_offset(args.offset);
4263
+ builder.data().write(args.data).finish();
4264
+ return envelope("write", builder.build());
4265
+ }
4266
+ case "destroy":
4267
+ return envelope(
4268
+ "destroy",
4269
+ new DestroyArgsBuilder().set_buffer_account_idx(args.bufferAccountIdx).set_meta_account_idx(args.metaAccountIdx).build()
4270
+ );
4271
+ case "finalize":
4272
+ return envelope(
4273
+ "finalize",
4274
+ new FinalizeArgsBuilder().set_buffer_account_idx(args.bufferAccountIdx).set_meta_account_idx(args.metaAccountIdx).set_expected_account_hash(
4275
+ exactBytes(args.expectedHash, 32, "expectedHash")
4276
+ ).build()
4277
+ );
4278
+ }
4279
+ }
4280
+ function indices(context, args) {
4281
+ return {
4282
+ bufferAccountIdx: accountIndex(
4283
+ context,
4284
+ args.bufferAccount,
4285
+ "bufferAccount"
4286
+ ),
4287
+ metaAccountIdx: accountIndex(context, args.metaAccount, "metaAccount")
4288
+ };
4289
+ }
4290
+ function createUploadBufferInstruction(args) {
4291
+ return async (context) => buildUploaderInstructionBytes({
4292
+ kind: "create",
4293
+ ...indices(context, args),
4294
+ authorityAccountIdx: accountIndex(
4295
+ context,
4296
+ args.authorityAccount,
4297
+ "authorityAccount"
4298
+ ),
4299
+ bufferSize: args.bufferSize,
4300
+ expectedHash: args.expectedHash,
4301
+ seed: args.seed
4302
+ });
4303
+ }
4304
+ function createWriteUploadInstruction(args) {
4305
+ return async (context) => buildUploaderInstructionBytes({
4306
+ kind: "write",
4307
+ ...indices(context, args),
4308
+ data: args.data,
4309
+ offset: args.offset
4310
+ });
4311
+ }
4312
+ function createDestroyUploadInstruction(args) {
4313
+ return async (context) => buildUploaderInstructionBytes({
4314
+ kind: "destroy",
4315
+ ...indices(context, args)
4316
+ });
4317
+ }
4318
+ function createFinalizeUploadInstruction(args) {
4319
+ return async (context) => buildUploaderInstructionBytes({
4320
+ kind: "finalize",
4321
+ ...indices(context, args),
4322
+ expectedHash: args.expectedHash
4323
+ });
4324
+ }
4325
+
4326
+ // src/uploader/errors.ts
4327
+ var UPLOADER_ERRORS = {
4328
+ 1: "NOT_AUTHORIZED",
4329
+ 2: "INVALID_ARGS",
4330
+ 3: "META_ACCOUNT_MISSING",
4331
+ 4: "BUFFER_ACCOUNT_MISSING",
4332
+ 5: "ACCOUNT_NOT_OPEN",
4333
+ 6: "HASH_MISMATCH",
4334
+ 7: "WRITE_OVERFLOW",
4335
+ 8: "WRITE_OUT_OF_BOUNDS",
4336
+ 9: "INVALID_ACCOUNT_INDEX",
4337
+ 10: "INVALID_META_SIZE",
4338
+ 11: "ACCOUNT_RELATIONSHIP",
4339
+ 12: "INVALID_INSTRUCTION"
4340
+ };
4341
+ function uploaderErrorName(code) {
4342
+ const normalized = typeof code === "bigint" ? Number(code) : code;
4343
+ if (!Number.isSafeInteger(normalized) || normalized < 0) {
4344
+ throw new Error("uploader error code must be a non-negative integer");
4345
+ }
4346
+ return UPLOADER_ERRORS[normalized];
4347
+ }
4348
+
4349
+ export { CreateArgs, CreateArgsBuilder, DestroyArgs, DestroyArgsBuilder, FinalizeArgs, FinalizeArgsBuilder, UPLOADER_DEFAULT_CHUNK_SIZE, UPLOADER_ERRORS, UPLOADER_MAX_CHUNK_SIZE, UPLOADER_META_SIZE, UPLOADER_MIN_CHUNK_SIZE, UPLOADER_PROGRAM_ADDRESS, UPLOADER_PROGRAM_PUBKEY, UPLOADER_STATE_FINALIZED, UPLOADER_STATE_OPEN, UploaderError, UploaderErrorBuilder, UploaderInstruction, UploaderInstructionBuilder, UploaderInstruction_payload_Inner, UploaderProgramMeta, UploaderProgramMetaBuilder, WriteArgs, WriteArgsBuilder, buildUploaderInstructionBytes, createDestroyUploadInstruction, createFinalizeUploadInstruction, createUploadBufferInstruction, createWriteUploadInstruction, deriveUploadAddresses, parseUploaderProgramMeta, uploaderErrorName };
4350
+ //# sourceMappingURL=chunk-BNYDH4ZP.js.map
4351
+ //# sourceMappingURL=chunk-BNYDH4ZP.js.map