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