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