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