@vleap/warps-adapter-fastset 0.1.0-alpha.9 → 0.1.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,3026 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+
32
+ // src/index.ts
33
+ var index_exports = {};
34
+ __export(index_exports, {
35
+ NativeTokenSet: () => NativeTokenSet,
36
+ WarpFastsetExecutor: () => WarpFastsetExecutor,
37
+ WarpFastsetWallet: () => WarpFastsetWallet,
38
+ getFastsetAdapter: () => getFastsetAdapter
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/main.ts
43
+ var import_warps6 = require("@vleap/warps");
44
+
45
+ // src/helpers/encode.ts
46
+ var encoder = new TextEncoder();
47
+ var decoder = new TextDecoder();
48
+ function uint8ArrayToHex(uint8Array) {
49
+ return Buffer.from(uint8Array).toString("hex");
50
+ }
51
+ function hexToUint8Array(hex) {
52
+ return new Uint8Array(Buffer.from(hex, "hex"));
53
+ }
54
+ function stringToUint8Array(str) {
55
+ return new Uint8Array(Buffer.from(str, "utf8"));
56
+ }
57
+
58
+ // src/helpers/general.ts
59
+ var import_warps = require("@vleap/warps");
60
+
61
+ // src/sdk/FastsetClient.ts
62
+ var bech32 = __toESM(require("bech32"), 1);
63
+
64
+ // ../../node_modules/@scure/base/lib/esm/index.js
65
+ function isBytes(a) {
66
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
67
+ }
68
+ function isArrayOf(isString, arr) {
69
+ if (!Array.isArray(arr))
70
+ return false;
71
+ if (arr.length === 0)
72
+ return true;
73
+ if (isString) {
74
+ return arr.every((item) => typeof item === "string");
75
+ } else {
76
+ return arr.every((item) => Number.isSafeInteger(item));
77
+ }
78
+ }
79
+ function astr(label, input) {
80
+ if (typeof input !== "string")
81
+ throw new Error(`${label}: string expected`);
82
+ return true;
83
+ }
84
+ function anumber(n) {
85
+ if (!Number.isSafeInteger(n))
86
+ throw new Error(`invalid integer: ${n}`);
87
+ }
88
+ function aArr(input) {
89
+ if (!Array.isArray(input))
90
+ throw new Error("array expected");
91
+ }
92
+ function astrArr(label, input) {
93
+ if (!isArrayOf(true, input))
94
+ throw new Error(`${label}: array of strings expected`);
95
+ }
96
+ function anumArr(label, input) {
97
+ if (!isArrayOf(false, input))
98
+ throw new Error(`${label}: array of numbers expected`);
99
+ }
100
+ // @__NO_SIDE_EFFECTS__
101
+ function chain(...args) {
102
+ const id2 = (a) => a;
103
+ const wrap = (a, b) => (c) => a(b(c));
104
+ const encode = args.map((x) => x.encode).reduceRight(wrap, id2);
105
+ const decode = args.map((x) => x.decode).reduce(wrap, id2);
106
+ return { encode, decode };
107
+ }
108
+ // @__NO_SIDE_EFFECTS__
109
+ function alphabet(letters) {
110
+ const lettersA = typeof letters === "string" ? letters.split("") : letters;
111
+ const len = lettersA.length;
112
+ astrArr("alphabet", lettersA);
113
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
114
+ return {
115
+ encode: (digits) => {
116
+ aArr(digits);
117
+ return digits.map((i) => {
118
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len)
119
+ throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
120
+ return lettersA[i];
121
+ });
122
+ },
123
+ decode: (input) => {
124
+ aArr(input);
125
+ return input.map((letter) => {
126
+ astr("alphabet.decode", letter);
127
+ const i = indexes.get(letter);
128
+ if (i === void 0)
129
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
130
+ return i;
131
+ });
132
+ }
133
+ };
134
+ }
135
+ // @__NO_SIDE_EFFECTS__
136
+ function join(separator = "") {
137
+ astr("join", separator);
138
+ return {
139
+ encode: (from) => {
140
+ astrArr("join.decode", from);
141
+ return from.join(separator);
142
+ },
143
+ decode: (to) => {
144
+ astr("join.decode", to);
145
+ return to.split(separator);
146
+ }
147
+ };
148
+ }
149
+ function convertRadix(data, from, to) {
150
+ if (from < 2)
151
+ throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
152
+ if (to < 2)
153
+ throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
154
+ aArr(data);
155
+ if (!data.length)
156
+ return [];
157
+ let pos = 0;
158
+ const res = [];
159
+ const digits = Array.from(data, (d) => {
160
+ anumber(d);
161
+ if (d < 0 || d >= from)
162
+ throw new Error(`invalid integer: ${d}`);
163
+ return d;
164
+ });
165
+ const dlen = digits.length;
166
+ while (true) {
167
+ let carry = 0;
168
+ let done = true;
169
+ for (let i = pos; i < dlen; i++) {
170
+ const digit = digits[i];
171
+ const fromCarry = from * carry;
172
+ const digitBase = fromCarry + digit;
173
+ if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
174
+ throw new Error("convertRadix: carry overflow");
175
+ }
176
+ const div = digitBase / to;
177
+ carry = digitBase % to;
178
+ const rounded = Math.floor(div);
179
+ digits[i] = rounded;
180
+ if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
181
+ throw new Error("convertRadix: carry overflow");
182
+ if (!done)
183
+ continue;
184
+ else if (!rounded)
185
+ pos = i;
186
+ else
187
+ done = false;
188
+ }
189
+ res.push(carry);
190
+ if (done)
191
+ break;
192
+ }
193
+ for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
194
+ res.push(0);
195
+ return res.reverse();
196
+ }
197
+ // @__NO_SIDE_EFFECTS__
198
+ function radix(num) {
199
+ anumber(num);
200
+ const _256 = 2 ** 8;
201
+ return {
202
+ encode: (bytes) => {
203
+ if (!isBytes(bytes))
204
+ throw new Error("radix.encode input should be Uint8Array");
205
+ return convertRadix(Array.from(bytes), _256, num);
206
+ },
207
+ decode: (digits) => {
208
+ anumArr("radix.decode", digits);
209
+ return Uint8Array.from(convertRadix(digits, num, _256));
210
+ }
211
+ };
212
+ }
213
+ var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
214
+ var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
215
+
216
+ // ../../node_modules/@mysten/utils/dist/esm/b58.js
217
+ var toBase58 = (buffer) => base58.encode(buffer);
218
+ var fromBase58 = (str) => base58.decode(str);
219
+
220
+ // ../../node_modules/@mysten/utils/dist/esm/b64.js
221
+ function fromBase64(base64String) {
222
+ return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
223
+ }
224
+ var CHUNK_SIZE = 8192;
225
+ function toBase64(bytes) {
226
+ if (bytes.length < CHUNK_SIZE) {
227
+ return btoa(String.fromCharCode(...bytes));
228
+ }
229
+ let output = "";
230
+ for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
231
+ const chunk = bytes.slice(i, i + CHUNK_SIZE);
232
+ output += String.fromCharCode(...chunk);
233
+ }
234
+ return btoa(output);
235
+ }
236
+
237
+ // ../../node_modules/@mysten/utils/dist/esm/hex.js
238
+ function fromHex(hexStr) {
239
+ const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
240
+ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;
241
+ const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];
242
+ if (intArr.length !== padded.length / 2) {
243
+ throw new Error(`Invalid hex string ${hexStr}`);
244
+ }
245
+ return Uint8Array.from(intArr);
246
+ }
247
+ function toHex(bytes) {
248
+ return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
249
+ }
250
+
251
+ // ../../node_modules/@mysten/bcs/dist/esm/uleb.js
252
+ function ulebEncode(num) {
253
+ let bigNum = BigInt(num);
254
+ const arr = [];
255
+ let len = 0;
256
+ if (bigNum === 0n) {
257
+ return [0];
258
+ }
259
+ while (bigNum > 0) {
260
+ arr[len] = Number(bigNum & 0x7fn);
261
+ bigNum >>= 7n;
262
+ if (bigNum > 0n) {
263
+ arr[len] |= 128;
264
+ }
265
+ len += 1;
266
+ }
267
+ return arr;
268
+ }
269
+ function ulebDecode(arr) {
270
+ let total = 0n;
271
+ let shift = 0n;
272
+ let len = 0;
273
+ while (true) {
274
+ if (len >= arr.length) {
275
+ throw new Error("ULEB decode error: buffer overflow");
276
+ }
277
+ const byte = arr[len];
278
+ len += 1;
279
+ total += BigInt(byte & 127) << shift;
280
+ if ((byte & 128) === 0) {
281
+ break;
282
+ }
283
+ shift += 7n;
284
+ }
285
+ if (total > BigInt(Number.MAX_SAFE_INTEGER)) {
286
+ throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
287
+ }
288
+ return {
289
+ value: Number(total),
290
+ length: len
291
+ };
292
+ }
293
+
294
+ // ../../node_modules/@mysten/bcs/dist/esm/reader.js
295
+ var BcsReader = class {
296
+ /**
297
+ * @param {Uint8Array} data Data to use as a buffer.
298
+ */
299
+ constructor(data) {
300
+ this.bytePosition = 0;
301
+ this.dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
302
+ }
303
+ /**
304
+ * Shift current cursor position by `bytes`.
305
+ *
306
+ * @param {Number} bytes Number of bytes to
307
+ * @returns {this} Self for possible chaining.
308
+ */
309
+ shift(bytes) {
310
+ this.bytePosition += bytes;
311
+ return this;
312
+ }
313
+ /**
314
+ * Read U8 value from the buffer and shift cursor by 1.
315
+ * @returns
316
+ */
317
+ read8() {
318
+ const value = this.dataView.getUint8(this.bytePosition);
319
+ this.shift(1);
320
+ return value;
321
+ }
322
+ /**
323
+ * Read U16 value from the buffer and shift cursor by 2.
324
+ * @returns
325
+ */
326
+ read16() {
327
+ const value = this.dataView.getUint16(this.bytePosition, true);
328
+ this.shift(2);
329
+ return value;
330
+ }
331
+ /**
332
+ * Read U32 value from the buffer and shift cursor by 4.
333
+ * @returns
334
+ */
335
+ read32() {
336
+ const value = this.dataView.getUint32(this.bytePosition, true);
337
+ this.shift(4);
338
+ return value;
339
+ }
340
+ /**
341
+ * Read U64 value from the buffer and shift cursor by 8.
342
+ * @returns
343
+ */
344
+ read64() {
345
+ const value1 = this.read32();
346
+ const value2 = this.read32();
347
+ const result = value2.toString(16) + value1.toString(16).padStart(8, "0");
348
+ return BigInt("0x" + result).toString(10);
349
+ }
350
+ /**
351
+ * Read U128 value from the buffer and shift cursor by 16.
352
+ */
353
+ read128() {
354
+ const value1 = BigInt(this.read64());
355
+ const value2 = BigInt(this.read64());
356
+ const result = value2.toString(16) + value1.toString(16).padStart(16, "0");
357
+ return BigInt("0x" + result).toString(10);
358
+ }
359
+ /**
360
+ * Read U128 value from the buffer and shift cursor by 32.
361
+ * @returns
362
+ */
363
+ read256() {
364
+ const value1 = BigInt(this.read128());
365
+ const value2 = BigInt(this.read128());
366
+ const result = value2.toString(16) + value1.toString(16).padStart(32, "0");
367
+ return BigInt("0x" + result).toString(10);
368
+ }
369
+ /**
370
+ * Read `num` number of bytes from the buffer and shift cursor by `num`.
371
+ * @param num Number of bytes to read.
372
+ */
373
+ readBytes(num) {
374
+ const start = this.bytePosition + this.dataView.byteOffset;
375
+ const value = new Uint8Array(this.dataView.buffer, start, num);
376
+ this.shift(num);
377
+ return value;
378
+ }
379
+ /**
380
+ * Read ULEB value - an integer of varying size. Used for enum indexes and
381
+ * vector lengths.
382
+ * @returns {Number} The ULEB value.
383
+ */
384
+ readULEB() {
385
+ const start = this.bytePosition + this.dataView.byteOffset;
386
+ const buffer = new Uint8Array(this.dataView.buffer, start);
387
+ const { value, length } = ulebDecode(buffer);
388
+ this.shift(length);
389
+ return value;
390
+ }
391
+ /**
392
+ * Read a BCS vector: read a length and then apply function `cb` X times
393
+ * where X is the length of the vector, defined as ULEB in BCS bytes.
394
+ * @param cb Callback to process elements of vector.
395
+ * @returns {Array<Any>} Array of the resulting values, returned by callback.
396
+ */
397
+ readVec(cb) {
398
+ const length = this.readULEB();
399
+ const result = [];
400
+ for (let i = 0; i < length; i++) {
401
+ result.push(cb(this, i, length));
402
+ }
403
+ return result;
404
+ }
405
+ };
406
+
407
+ // ../../node_modules/@mysten/bcs/dist/esm/utils.js
408
+ function encodeStr(data, encoding) {
409
+ switch (encoding) {
410
+ case "base58":
411
+ return toBase58(data);
412
+ case "base64":
413
+ return toBase64(data);
414
+ case "hex":
415
+ return toHex(data);
416
+ default:
417
+ throw new Error("Unsupported encoding, supported values are: base64, hex");
418
+ }
419
+ }
420
+
421
+ // ../../node_modules/@mysten/bcs/dist/esm/writer.js
422
+ var BcsWriter = class {
423
+ constructor({
424
+ initialSize = 1024,
425
+ maxSize = Infinity,
426
+ allocateSize = 1024
427
+ } = {}) {
428
+ this.bytePosition = 0;
429
+ this.size = initialSize;
430
+ this.maxSize = maxSize;
431
+ this.allocateSize = allocateSize;
432
+ this.dataView = new DataView(new ArrayBuffer(initialSize));
433
+ }
434
+ ensureSizeOrGrow(bytes) {
435
+ const requiredSize = this.bytePosition + bytes;
436
+ if (requiredSize > this.size) {
437
+ const nextSize = Math.min(
438
+ this.maxSize,
439
+ Math.max(this.size + requiredSize, this.size + this.allocateSize)
440
+ );
441
+ if (requiredSize > nextSize) {
442
+ throw new Error(
443
+ `Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${requiredSize}`
444
+ );
445
+ }
446
+ this.size = nextSize;
447
+ const nextBuffer = new ArrayBuffer(this.size);
448
+ new Uint8Array(nextBuffer).set(new Uint8Array(this.dataView.buffer));
449
+ this.dataView = new DataView(nextBuffer);
450
+ }
451
+ }
452
+ /**
453
+ * Shift current cursor position by `bytes`.
454
+ *
455
+ * @param {Number} bytes Number of bytes to
456
+ * @returns {this} Self for possible chaining.
457
+ */
458
+ shift(bytes) {
459
+ this.bytePosition += bytes;
460
+ return this;
461
+ }
462
+ /**
463
+ * Write a U8 value into a buffer and shift cursor position by 1.
464
+ * @param {Number} value Value to write.
465
+ * @returns {this}
466
+ */
467
+ write8(value) {
468
+ this.ensureSizeOrGrow(1);
469
+ this.dataView.setUint8(this.bytePosition, Number(value));
470
+ return this.shift(1);
471
+ }
472
+ /**
473
+ * Write a U8 value into a buffer and shift cursor position by 1.
474
+ * @param {Number} value Value to write.
475
+ * @returns {this}
476
+ */
477
+ writeBytes(bytes) {
478
+ this.ensureSizeOrGrow(bytes.length);
479
+ for (let i = 0; i < bytes.length; i++) {
480
+ this.dataView.setUint8(this.bytePosition + i, bytes[i]);
481
+ }
482
+ return this.shift(bytes.length);
483
+ }
484
+ /**
485
+ * Write a U16 value into a buffer and shift cursor position by 2.
486
+ * @param {Number} value Value to write.
487
+ * @returns {this}
488
+ */
489
+ write16(value) {
490
+ this.ensureSizeOrGrow(2);
491
+ this.dataView.setUint16(this.bytePosition, Number(value), true);
492
+ return this.shift(2);
493
+ }
494
+ /**
495
+ * Write a U32 value into a buffer and shift cursor position by 4.
496
+ * @param {Number} value Value to write.
497
+ * @returns {this}
498
+ */
499
+ write32(value) {
500
+ this.ensureSizeOrGrow(4);
501
+ this.dataView.setUint32(this.bytePosition, Number(value), true);
502
+ return this.shift(4);
503
+ }
504
+ /**
505
+ * Write a U64 value into a buffer and shift cursor position by 8.
506
+ * @param {bigint} value Value to write.
507
+ * @returns {this}
508
+ */
509
+ write64(value) {
510
+ toLittleEndian(BigInt(value), 8).forEach((el) => this.write8(el));
511
+ return this;
512
+ }
513
+ /**
514
+ * Write a U128 value into a buffer and shift cursor position by 16.
515
+ *
516
+ * @param {bigint} value Value to write.
517
+ * @returns {this}
518
+ */
519
+ write128(value) {
520
+ toLittleEndian(BigInt(value), 16).forEach((el) => this.write8(el));
521
+ return this;
522
+ }
523
+ /**
524
+ * Write a U256 value into a buffer and shift cursor position by 16.
525
+ *
526
+ * @param {bigint} value Value to write.
527
+ * @returns {this}
528
+ */
529
+ write256(value) {
530
+ toLittleEndian(BigInt(value), 32).forEach((el) => this.write8(el));
531
+ return this;
532
+ }
533
+ /**
534
+ * Write a ULEB value into a buffer and shift cursor position by number of bytes
535
+ * written.
536
+ * @param {Number} value Value to write.
537
+ * @returns {this}
538
+ */
539
+ writeULEB(value) {
540
+ ulebEncode(value).forEach((el) => this.write8(el));
541
+ return this;
542
+ }
543
+ /**
544
+ * Write a vector into a buffer by first writing the vector length and then calling
545
+ * a callback on each passed value.
546
+ *
547
+ * @param {Array<Any>} vector Array of elements to write.
548
+ * @param {WriteVecCb} cb Callback to call on each element of the vector.
549
+ * @returns {this}
550
+ */
551
+ writeVec(vector2, cb) {
552
+ this.writeULEB(vector2.length);
553
+ Array.from(vector2).forEach((el, i) => cb(this, el, i, vector2.length));
554
+ return this;
555
+ }
556
+ /**
557
+ * Adds support for iterations over the object.
558
+ * @returns {Uint8Array}
559
+ */
560
+ // oxlint-disable-next-line require-yields
561
+ *[Symbol.iterator]() {
562
+ for (let i = 0; i < this.bytePosition; i++) {
563
+ yield this.dataView.getUint8(i);
564
+ }
565
+ return this.toBytes();
566
+ }
567
+ /**
568
+ * Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
569
+ * @returns {Uint8Array} Resulting bcs.
570
+ */
571
+ toBytes() {
572
+ return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
573
+ }
574
+ /**
575
+ * Represent data as 'hex' or 'base64'
576
+ * @param encoding Encoding to use: 'base64' or 'hex'
577
+ */
578
+ toString(encoding) {
579
+ return encodeStr(this.toBytes(), encoding);
580
+ }
581
+ };
582
+ function toLittleEndian(bigint, size) {
583
+ const result = new Uint8Array(size);
584
+ let i = 0;
585
+ while (bigint > 0) {
586
+ result[i] = Number(bigint % BigInt(256));
587
+ bigint = bigint / BigInt(256);
588
+ i += 1;
589
+ }
590
+ return result;
591
+ }
592
+
593
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs-type.js
594
+ var __typeError = (msg) => {
595
+ throw TypeError(msg);
596
+ };
597
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
598
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
599
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
600
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
601
+ var _write;
602
+ var _serialize;
603
+ var _schema;
604
+ var _bytes;
605
+ var _BcsType = class _BcsType2 {
606
+ constructor(options) {
607
+ __privateAdd(this, _write);
608
+ __privateAdd(this, _serialize);
609
+ this.name = options.name;
610
+ this.read = options.read;
611
+ this.serializedSize = options.serializedSize ?? (() => null);
612
+ __privateSet(this, _write, options.write);
613
+ __privateSet(this, _serialize, options.serialize ?? ((value, options2) => {
614
+ const writer = new BcsWriter({
615
+ initialSize: this.serializedSize(value) ?? void 0,
616
+ ...options2
617
+ });
618
+ __privateGet(this, _write).call(this, value, writer);
619
+ return writer.toBytes();
620
+ }));
621
+ this.validate = options.validate ?? (() => {
622
+ });
623
+ }
624
+ write(value, writer) {
625
+ this.validate(value);
626
+ __privateGet(this, _write).call(this, value, writer);
627
+ }
628
+ serialize(value, options) {
629
+ this.validate(value);
630
+ return new SerializedBcs(this, __privateGet(this, _serialize).call(this, value, options));
631
+ }
632
+ parse(bytes) {
633
+ const reader = new BcsReader(bytes);
634
+ return this.read(reader);
635
+ }
636
+ fromHex(hex) {
637
+ return this.parse(fromHex(hex));
638
+ }
639
+ fromBase58(b64) {
640
+ return this.parse(fromBase58(b64));
641
+ }
642
+ fromBase64(b64) {
643
+ return this.parse(fromBase64(b64));
644
+ }
645
+ transform({
646
+ name,
647
+ input,
648
+ output,
649
+ validate
650
+ }) {
651
+ return new _BcsType2({
652
+ name: name ?? this.name,
653
+ read: (reader) => output ? output(this.read(reader)) : this.read(reader),
654
+ write: (value, writer) => __privateGet(this, _write).call(this, input ? input(value) : value, writer),
655
+ serializedSize: (value) => this.serializedSize(input ? input(value) : value),
656
+ serialize: (value, options) => __privateGet(this, _serialize).call(this, input ? input(value) : value, options),
657
+ validate: (value) => {
658
+ validate?.(value);
659
+ this.validate(input ? input(value) : value);
660
+ }
661
+ });
662
+ }
663
+ };
664
+ _write = /* @__PURE__ */ new WeakMap();
665
+ _serialize = /* @__PURE__ */ new WeakMap();
666
+ var BcsType = _BcsType;
667
+ var SERIALIZED_BCS_BRAND = Symbol.for("@mysten/serialized-bcs");
668
+ var SerializedBcs = class {
669
+ constructor(schema, bytes) {
670
+ __privateAdd(this, _schema);
671
+ __privateAdd(this, _bytes);
672
+ __privateSet(this, _schema, schema);
673
+ __privateSet(this, _bytes, bytes);
674
+ }
675
+ // Used to brand SerializedBcs so that they can be identified, even between multiple copies
676
+ // of the @mysten/bcs package are installed
677
+ get [SERIALIZED_BCS_BRAND]() {
678
+ return true;
679
+ }
680
+ toBytes() {
681
+ return __privateGet(this, _bytes);
682
+ }
683
+ toHex() {
684
+ return toHex(__privateGet(this, _bytes));
685
+ }
686
+ toBase64() {
687
+ return toBase64(__privateGet(this, _bytes));
688
+ }
689
+ toBase58() {
690
+ return toBase58(__privateGet(this, _bytes));
691
+ }
692
+ parse() {
693
+ return __privateGet(this, _schema).parse(__privateGet(this, _bytes));
694
+ }
695
+ };
696
+ _schema = /* @__PURE__ */ new WeakMap();
697
+ _bytes = /* @__PURE__ */ new WeakMap();
698
+ function fixedSizeBcsType({
699
+ size,
700
+ ...options
701
+ }) {
702
+ return new BcsType({
703
+ ...options,
704
+ serializedSize: () => size
705
+ });
706
+ }
707
+ function uIntBcsType({
708
+ readMethod,
709
+ writeMethod,
710
+ ...options
711
+ }) {
712
+ return fixedSizeBcsType({
713
+ ...options,
714
+ read: (reader) => reader[readMethod](),
715
+ write: (value, writer) => writer[writeMethod](value),
716
+ validate: (value) => {
717
+ if (value < 0 || value > options.maxValue) {
718
+ throw new TypeError(
719
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
720
+ );
721
+ }
722
+ options.validate?.(value);
723
+ }
724
+ });
725
+ }
726
+ function bigUIntBcsType({
727
+ readMethod,
728
+ writeMethod,
729
+ ...options
730
+ }) {
731
+ return fixedSizeBcsType({
732
+ ...options,
733
+ read: (reader) => reader[readMethod](),
734
+ write: (value, writer) => writer[writeMethod](BigInt(value)),
735
+ validate: (val) => {
736
+ const value = BigInt(val);
737
+ if (value < 0 || value > options.maxValue) {
738
+ throw new TypeError(
739
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
740
+ );
741
+ }
742
+ options.validate?.(value);
743
+ }
744
+ });
745
+ }
746
+ function dynamicSizeBcsType({
747
+ serialize,
748
+ ...options
749
+ }) {
750
+ const type = new BcsType({
751
+ ...options,
752
+ serialize,
753
+ write: (value, writer) => {
754
+ for (const byte of type.serialize(value).toBytes()) {
755
+ writer.write8(byte);
756
+ }
757
+ }
758
+ });
759
+ return type;
760
+ }
761
+ function stringLikeBcsType({
762
+ toBytes,
763
+ fromBytes,
764
+ ...options
765
+ }) {
766
+ return new BcsType({
767
+ ...options,
768
+ read: (reader) => {
769
+ const length = reader.readULEB();
770
+ const bytes = reader.readBytes(length);
771
+ return fromBytes(bytes);
772
+ },
773
+ write: (hex, writer) => {
774
+ const bytes = toBytes(hex);
775
+ writer.writeULEB(bytes.length);
776
+ for (let i = 0; i < bytes.length; i++) {
777
+ writer.write8(bytes[i]);
778
+ }
779
+ },
780
+ serialize: (value) => {
781
+ const bytes = toBytes(value);
782
+ const size = ulebEncode(bytes.length);
783
+ const result = new Uint8Array(size.length + bytes.length);
784
+ result.set(size, 0);
785
+ result.set(bytes, size.length);
786
+ return result;
787
+ },
788
+ validate: (value) => {
789
+ if (typeof value !== "string") {
790
+ throw new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);
791
+ }
792
+ options.validate?.(value);
793
+ }
794
+ });
795
+ }
796
+ function lazyBcsType(cb) {
797
+ let lazyType = null;
798
+ function getType() {
799
+ if (!lazyType) {
800
+ lazyType = cb();
801
+ }
802
+ return lazyType;
803
+ }
804
+ return new BcsType({
805
+ name: "lazy",
806
+ read: (data) => getType().read(data),
807
+ serializedSize: (value) => getType().serializedSize(value),
808
+ write: (value, writer) => getType().write(value, writer),
809
+ serialize: (value, options) => getType().serialize(value, options).toBytes()
810
+ });
811
+ }
812
+ var BcsStruct = class extends BcsType {
813
+ constructor({ name, fields, ...options }) {
814
+ const canonicalOrder = Object.entries(fields);
815
+ super({
816
+ name,
817
+ serializedSize: (values) => {
818
+ let total = 0;
819
+ for (const [field, type] of canonicalOrder) {
820
+ const size = type.serializedSize(values[field]);
821
+ if (size == null) {
822
+ return null;
823
+ }
824
+ total += size;
825
+ }
826
+ return total;
827
+ },
828
+ read: (reader) => {
829
+ const result = {};
830
+ for (const [field, type] of canonicalOrder) {
831
+ result[field] = type.read(reader);
832
+ }
833
+ return result;
834
+ },
835
+ write: (value, writer) => {
836
+ for (const [field, type] of canonicalOrder) {
837
+ type.write(value[field], writer);
838
+ }
839
+ },
840
+ ...options,
841
+ validate: (value) => {
842
+ options?.validate?.(value);
843
+ if (typeof value !== "object" || value == null) {
844
+ throw new TypeError(`Expected object, found ${typeof value}`);
845
+ }
846
+ }
847
+ });
848
+ }
849
+ };
850
+ var BcsEnum = class extends BcsType {
851
+ constructor({ fields, ...options }) {
852
+ const canonicalOrder = Object.entries(fields);
853
+ super({
854
+ read: (reader) => {
855
+ const index = reader.readULEB();
856
+ const enumEntry = canonicalOrder[index];
857
+ if (!enumEntry) {
858
+ throw new TypeError(`Unknown value ${index} for enum ${options.name}`);
859
+ }
860
+ const [kind, type] = enumEntry;
861
+ return {
862
+ [kind]: type?.read(reader) ?? true,
863
+ $kind: kind
864
+ };
865
+ },
866
+ write: (value, writer) => {
867
+ const [name, val] = Object.entries(value).filter(
868
+ ([name2]) => Object.hasOwn(fields, name2)
869
+ )[0];
870
+ for (let i = 0; i < canonicalOrder.length; i++) {
871
+ const [optionName, optionType] = canonicalOrder[i];
872
+ if (optionName === name) {
873
+ writer.writeULEB(i);
874
+ optionType?.write(val, writer);
875
+ return;
876
+ }
877
+ }
878
+ },
879
+ ...options,
880
+ validate: (value) => {
881
+ options?.validate?.(value);
882
+ if (typeof value !== "object" || value == null) {
883
+ throw new TypeError(`Expected object, found ${typeof value}`);
884
+ }
885
+ const keys = Object.keys(value).filter(
886
+ (k) => value[k] !== void 0 && Object.hasOwn(fields, k)
887
+ );
888
+ if (keys.length !== 1) {
889
+ throw new TypeError(
890
+ `Expected object with one key, but found ${keys.length} for type ${options.name}}`
891
+ );
892
+ }
893
+ const [variant] = keys;
894
+ if (!Object.hasOwn(fields, variant)) {
895
+ throw new TypeError(`Invalid enum variant ${variant}`);
896
+ }
897
+ }
898
+ });
899
+ }
900
+ };
901
+ var BcsTuple = class extends BcsType {
902
+ constructor({ fields, name, ...options }) {
903
+ super({
904
+ name: name ?? `(${fields.map((t) => t.name).join(", ")})`,
905
+ serializedSize: (values) => {
906
+ let total = 0;
907
+ for (let i = 0; i < fields.length; i++) {
908
+ const size = fields[i].serializedSize(values[i]);
909
+ if (size == null) {
910
+ return null;
911
+ }
912
+ total += size;
913
+ }
914
+ return total;
915
+ },
916
+ read: (reader) => {
917
+ const result = [];
918
+ for (const field of fields) {
919
+ result.push(field.read(reader));
920
+ }
921
+ return result;
922
+ },
923
+ write: (value, writer) => {
924
+ for (let i = 0; i < fields.length; i++) {
925
+ fields[i].write(value[i], writer);
926
+ }
927
+ },
928
+ ...options,
929
+ validate: (value) => {
930
+ options?.validate?.(value);
931
+ if (!Array.isArray(value)) {
932
+ throw new TypeError(`Expected array, found ${typeof value}`);
933
+ }
934
+ if (value.length !== fields.length) {
935
+ throw new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);
936
+ }
937
+ }
938
+ });
939
+ }
940
+ };
941
+
942
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs.js
943
+ function fixedArray(size, type, options) {
944
+ return new BcsType({
945
+ read: (reader) => {
946
+ const result = new Array(size);
947
+ for (let i = 0; i < size; i++) {
948
+ result[i] = type.read(reader);
949
+ }
950
+ return result;
951
+ },
952
+ write: (value, writer) => {
953
+ for (const item of value) {
954
+ type.write(item, writer);
955
+ }
956
+ },
957
+ ...options,
958
+ name: options?.name ?? `${type.name}[${size}]`,
959
+ validate: (value) => {
960
+ options?.validate?.(value);
961
+ if (!value || typeof value !== "object" || !("length" in value)) {
962
+ throw new TypeError(`Expected array, found ${typeof value}`);
963
+ }
964
+ if (value.length !== size) {
965
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
966
+ }
967
+ }
968
+ });
969
+ }
970
+ function option(type) {
971
+ return bcs.enum(`Option<${type.name}>`, {
972
+ None: null,
973
+ Some: type
974
+ }).transform({
975
+ input: (value) => {
976
+ if (value == null) {
977
+ return { None: true };
978
+ }
979
+ return { Some: value };
980
+ },
981
+ output: (value) => {
982
+ if (value.$kind === "Some") {
983
+ return value.Some;
984
+ }
985
+ return null;
986
+ }
987
+ });
988
+ }
989
+ function vector(type, options) {
990
+ return new BcsType({
991
+ read: (reader) => {
992
+ const length = reader.readULEB();
993
+ const result = new Array(length);
994
+ for (let i = 0; i < length; i++) {
995
+ result[i] = type.read(reader);
996
+ }
997
+ return result;
998
+ },
999
+ write: (value, writer) => {
1000
+ writer.writeULEB(value.length);
1001
+ for (const item of value) {
1002
+ type.write(item, writer);
1003
+ }
1004
+ },
1005
+ ...options,
1006
+ name: options?.name ?? `vector<${type.name}>`,
1007
+ validate: (value) => {
1008
+ options?.validate?.(value);
1009
+ if (!value || typeof value !== "object" || !("length" in value)) {
1010
+ throw new TypeError(`Expected array, found ${typeof value}`);
1011
+ }
1012
+ }
1013
+ });
1014
+ }
1015
+ function map(keyType, valueType) {
1016
+ return bcs.vector(bcs.tuple([keyType, valueType])).transform({
1017
+ name: `Map<${keyType.name}, ${valueType.name}>`,
1018
+ input: (value) => {
1019
+ return [...value.entries()];
1020
+ },
1021
+ output: (value) => {
1022
+ const result = /* @__PURE__ */ new Map();
1023
+ for (const [key, val] of value) {
1024
+ result.set(key, val);
1025
+ }
1026
+ return result;
1027
+ }
1028
+ });
1029
+ }
1030
+ var bcs = {
1031
+ /**
1032
+ * Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
1033
+ * @example
1034
+ * bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
1035
+ */
1036
+ u8(options) {
1037
+ return uIntBcsType({
1038
+ readMethod: "read8",
1039
+ writeMethod: "write8",
1040
+ size: 1,
1041
+ maxValue: 2 ** 8 - 1,
1042
+ ...options,
1043
+ name: options?.name ?? "u8"
1044
+ });
1045
+ },
1046
+ /**
1047
+ * Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
1048
+ * @example
1049
+ * bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
1050
+ */
1051
+ u16(options) {
1052
+ return uIntBcsType({
1053
+ readMethod: "read16",
1054
+ writeMethod: "write16",
1055
+ size: 2,
1056
+ maxValue: 2 ** 16 - 1,
1057
+ ...options,
1058
+ name: options?.name ?? "u16"
1059
+ });
1060
+ },
1061
+ /**
1062
+ * Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
1063
+ * @example
1064
+ * bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
1065
+ */
1066
+ u32(options) {
1067
+ return uIntBcsType({
1068
+ readMethod: "read32",
1069
+ writeMethod: "write32",
1070
+ size: 4,
1071
+ maxValue: 2 ** 32 - 1,
1072
+ ...options,
1073
+ name: options?.name ?? "u32"
1074
+ });
1075
+ },
1076
+ /**
1077
+ * Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
1078
+ * @example
1079
+ * bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
1080
+ */
1081
+ u64(options) {
1082
+ return bigUIntBcsType({
1083
+ readMethod: "read64",
1084
+ writeMethod: "write64",
1085
+ size: 8,
1086
+ maxValue: 2n ** 64n - 1n,
1087
+ ...options,
1088
+ name: options?.name ?? "u64"
1089
+ });
1090
+ },
1091
+ /**
1092
+ * Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
1093
+ * @example
1094
+ * bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
1095
+ */
1096
+ u128(options) {
1097
+ return bigUIntBcsType({
1098
+ readMethod: "read128",
1099
+ writeMethod: "write128",
1100
+ size: 16,
1101
+ maxValue: 2n ** 128n - 1n,
1102
+ ...options,
1103
+ name: options?.name ?? "u128"
1104
+ });
1105
+ },
1106
+ /**
1107
+ * Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
1108
+ * @example
1109
+ * bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
1110
+ */
1111
+ u256(options) {
1112
+ return bigUIntBcsType({
1113
+ readMethod: "read256",
1114
+ writeMethod: "write256",
1115
+ size: 32,
1116
+ maxValue: 2n ** 256n - 1n,
1117
+ ...options,
1118
+ name: options?.name ?? "u256"
1119
+ });
1120
+ },
1121
+ /**
1122
+ * Creates a BcsType that can be used to read and write boolean values.
1123
+ * @example
1124
+ * bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
1125
+ */
1126
+ bool(options) {
1127
+ return fixedSizeBcsType({
1128
+ size: 1,
1129
+ read: (reader) => reader.read8() === 1,
1130
+ write: (value, writer) => writer.write8(value ? 1 : 0),
1131
+ ...options,
1132
+ name: options?.name ?? "bool",
1133
+ validate: (value) => {
1134
+ options?.validate?.(value);
1135
+ if (typeof value !== "boolean") {
1136
+ throw new TypeError(`Expected boolean, found ${typeof value}`);
1137
+ }
1138
+ }
1139
+ });
1140
+ },
1141
+ /**
1142
+ * Creates a BcsType that can be used to read and write unsigned LEB encoded integers
1143
+ * @example
1144
+ *
1145
+ */
1146
+ uleb128(options) {
1147
+ return dynamicSizeBcsType({
1148
+ read: (reader) => reader.readULEB(),
1149
+ serialize: (value) => {
1150
+ return Uint8Array.from(ulebEncode(value));
1151
+ },
1152
+ ...options,
1153
+ name: options?.name ?? "uleb128"
1154
+ });
1155
+ },
1156
+ /**
1157
+ * Creates a BcsType representing a fixed length byte array
1158
+ * @param size The number of bytes this types represents
1159
+ * @example
1160
+ * bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
1161
+ */
1162
+ bytes(size, options) {
1163
+ return fixedSizeBcsType({
1164
+ size,
1165
+ read: (reader) => reader.readBytes(size),
1166
+ write: (value, writer) => {
1167
+ writer.writeBytes(new Uint8Array(value));
1168
+ },
1169
+ ...options,
1170
+ name: options?.name ?? `bytes[${size}]`,
1171
+ validate: (value) => {
1172
+ options?.validate?.(value);
1173
+ if (!value || typeof value !== "object" || !("length" in value)) {
1174
+ throw new TypeError(`Expected array, found ${typeof value}`);
1175
+ }
1176
+ if (value.length !== size) {
1177
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
1178
+ }
1179
+ }
1180
+ });
1181
+ },
1182
+ /**
1183
+ * Creates a BcsType representing a variable length byte array
1184
+ *
1185
+ * @example
1186
+ * bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 1, 2, 3]
1187
+ */
1188
+ byteVector(options) {
1189
+ return new BcsType({
1190
+ read: (reader) => {
1191
+ const length = reader.readULEB();
1192
+ return reader.readBytes(length);
1193
+ },
1194
+ write: (value, writer) => {
1195
+ const array = new Uint8Array(value);
1196
+ writer.writeULEB(array.length);
1197
+ writer.writeBytes(array);
1198
+ },
1199
+ ...options,
1200
+ name: options?.name ?? "vector<u8>",
1201
+ serializedSize: (value) => {
1202
+ const length = "length" in value ? value.length : null;
1203
+ return length == null ? null : ulebEncode(length).length + length;
1204
+ },
1205
+ validate: (value) => {
1206
+ options?.validate?.(value);
1207
+ if (!value || typeof value !== "object" || !("length" in value)) {
1208
+ throw new TypeError(`Expected array, found ${typeof value}`);
1209
+ }
1210
+ }
1211
+ });
1212
+ },
1213
+ /**
1214
+ * Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
1215
+ * @example
1216
+ * bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
1217
+ */
1218
+ string(options) {
1219
+ return stringLikeBcsType({
1220
+ toBytes: (value) => new TextEncoder().encode(value),
1221
+ fromBytes: (bytes) => new TextDecoder().decode(bytes),
1222
+ ...options,
1223
+ name: options?.name ?? "string"
1224
+ });
1225
+ },
1226
+ /**
1227
+ * Creates a BcsType that represents a fixed length array of a given type
1228
+ * @param size The number of elements in the array
1229
+ * @param type The BcsType of each element in the array
1230
+ * @example
1231
+ * bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
1232
+ */
1233
+ fixedArray,
1234
+ /**
1235
+ * Creates a BcsType representing an optional value
1236
+ * @param type The BcsType of the optional value
1237
+ * @example
1238
+ * bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
1239
+ * bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
1240
+ */
1241
+ option,
1242
+ /**
1243
+ * Creates a BcsType representing a variable length vector of a given type
1244
+ * @param type The BcsType of each element in the vector
1245
+ *
1246
+ * @example
1247
+ * bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
1248
+ */
1249
+ vector,
1250
+ /**
1251
+ * Creates a BcsType representing a tuple of a given set of types
1252
+ * @param types The BcsTypes for each element in the tuple
1253
+ *
1254
+ * @example
1255
+ * const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
1256
+ * tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
1257
+ */
1258
+ tuple(fields, options) {
1259
+ return new BcsTuple({
1260
+ fields,
1261
+ ...options
1262
+ });
1263
+ },
1264
+ /**
1265
+ * Creates a BcsType representing a struct of a given set of fields
1266
+ * @param name The name of the struct
1267
+ * @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
1268
+ *
1269
+ * @example
1270
+ * const struct = bcs.struct('MyStruct', {
1271
+ * a: bcs.u8(),
1272
+ * b: bcs.string(),
1273
+ * })
1274
+ * struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
1275
+ */
1276
+ struct(name, fields, options) {
1277
+ return new BcsStruct({
1278
+ name,
1279
+ fields,
1280
+ ...options
1281
+ });
1282
+ },
1283
+ /**
1284
+ * Creates a BcsType representing an enum of a given set of options
1285
+ * @param name The name of the enum
1286
+ * @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
1287
+ * null can be used to represent a variant with no data.
1288
+ *
1289
+ * @example
1290
+ * const enum = bcs.enum('MyEnum', {
1291
+ * A: bcs.u8(),
1292
+ * B: bcs.string(),
1293
+ * C: null,
1294
+ * })
1295
+ * enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
1296
+ * enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
1297
+ * enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
1298
+ */
1299
+ enum(name, fields, options) {
1300
+ return new BcsEnum({
1301
+ name,
1302
+ fields,
1303
+ ...options
1304
+ });
1305
+ },
1306
+ /**
1307
+ * Creates a BcsType representing a map of a given key and value type
1308
+ * @param keyType The BcsType of the key
1309
+ * @param valueType The BcsType of the value
1310
+ * @example
1311
+ * const map = bcs.map(bcs.u8(), bcs.string())
1312
+ * map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
1313
+ */
1314
+ map,
1315
+ /**
1316
+ * Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
1317
+ * @param cb A callback that returns the BcsType
1318
+ */
1319
+ lazy(cb) {
1320
+ return lazyBcsType(cb);
1321
+ }
1322
+ };
1323
+
1324
+ // src/sdk/types.ts
1325
+ BigInt.prototype.toJSON = function() {
1326
+ return Number(this);
1327
+ };
1328
+ var Bytes32 = bcs.fixedArray(32, bcs.u8());
1329
+ var Bytes64 = bcs.fixedArray(64, bcs.u8());
1330
+ var PublicKey = Bytes32;
1331
+ var Signature = Bytes64;
1332
+ var Address = bcs.enum("Address", {
1333
+ External: PublicKey,
1334
+ FastSet: PublicKey
1335
+ });
1336
+ var Amount = bcs.u256().transform({
1337
+ // CAUTION: When we build a transaction object, we must use a hex encoded string because the
1338
+ // validator expects amounts to be in hex. However, bcs.u256() by default expects a decimal
1339
+ // string. Therefore, we must transform the input amount from hex to decimal here.
1340
+ input: (val) => hexToDecimal(val.toString()),
1341
+ output: (value) => value
1342
+ });
1343
+ var Balance = bcs.string().transform({
1344
+ input: (val) => val,
1345
+ output: (value) => value
1346
+ });
1347
+ var UserData = bcs.option(Bytes32);
1348
+ var Nonce = bcs.u64();
1349
+ var Quorum = bcs.u64();
1350
+ var TokenId = Bytes32;
1351
+ var Transfer = bcs.struct("Transfer", {
1352
+ amount: Amount,
1353
+ user_data: UserData
1354
+ });
1355
+ var TokenTransfer = bcs.struct("TokenTransfer", {
1356
+ token_id: TokenId,
1357
+ amount: Amount,
1358
+ user_data: UserData
1359
+ });
1360
+ var TokenCreation = bcs.struct("TokenCreation", {
1361
+ token_name: bcs.string(),
1362
+ decimals: bcs.u8(),
1363
+ initial_amount: Amount,
1364
+ mints: bcs.vector(PublicKey),
1365
+ user_data: UserData
1366
+ });
1367
+ var AddressChange = bcs.enum("AddressChange", {
1368
+ Add: PublicKey,
1369
+ Remove: PublicKey
1370
+ });
1371
+ var TokenManagement = bcs.struct("TokenManagement", {
1372
+ token_id: TokenId,
1373
+ update_id: Nonce,
1374
+ new_admin: bcs.option(PublicKey),
1375
+ mints: bcs.vector(bcs.tuple([AddressChange, PublicKey])),
1376
+ user_data: UserData
1377
+ });
1378
+ var Mint = bcs.struct("Mint", {
1379
+ token_id: TokenId,
1380
+ amount: Amount
1381
+ });
1382
+ var ClaimData = bcs.vector(bcs.u8());
1383
+ var ExternalClaimBody = bcs.struct("ExternalClaimBody", {
1384
+ verifier_committee: bcs.vector(PublicKey),
1385
+ verifier_quorum: Quorum,
1386
+ claim_data: ClaimData
1387
+ });
1388
+ var ExternalClaim = bcs.struct("ExternalClaim", {
1389
+ claim: ExternalClaimBody,
1390
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
1391
+ });
1392
+ var ClaimType = bcs.enum("ClaimType", {
1393
+ Transfer,
1394
+ TokenTransfer,
1395
+ TokenCreation,
1396
+ TokenManagement,
1397
+ Mint,
1398
+ ExternalClaim
1399
+ });
1400
+ var Transaction = bcs.struct("Transaction", {
1401
+ sender: PublicKey,
1402
+ recipient: Address,
1403
+ nonce: Nonce,
1404
+ timestamp_nanos: bcs.u128(),
1405
+ claim: ClaimType
1406
+ });
1407
+ var SubmitTransactionResponse = bcs.struct("SubmitTransactionResponse", {
1408
+ validator: PublicKey,
1409
+ signature: Signature,
1410
+ next_nonce: Nonce,
1411
+ transaction_hash: bcs.vector(bcs.u8())
1412
+ });
1413
+ var TransactionEnvelope = bcs.struct("TransactionEnvelope", {
1414
+ transaction: Transaction,
1415
+ signature: Signature
1416
+ });
1417
+ var TransactionCertificate = bcs.struct("TransactionCertificate", {
1418
+ envelope: TransactionEnvelope,
1419
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
1420
+ });
1421
+ function hexToDecimal(hex) {
1422
+ return BigInt(`0x${hex}`).toString();
1423
+ }
1424
+
1425
+ // src/sdk/FastsetClient.ts
1426
+ BigInt.prototype.toJSON = function() {
1427
+ return Number(this);
1428
+ };
1429
+ var id = 0;
1430
+ var FastsetClient = class {
1431
+ constructor(proxyUrl) {
1432
+ this.proxyUrl = proxyUrl;
1433
+ }
1434
+ async request(url, method, params) {
1435
+ const request = this.buildJsonRpcRequest(id++, method, params);
1436
+ const headers = { "Content-Type": "application/json" };
1437
+ const body = this.jsonSerialize(request);
1438
+ const response = await fetch(url, { method: "POST", headers, body });
1439
+ const json = await response.json();
1440
+ return json;
1441
+ }
1442
+ buildJsonRpcRequest(id2, method, params) {
1443
+ return { jsonrpc: "2.0", id: id2, method, params };
1444
+ }
1445
+ jsonSerialize(data) {
1446
+ return JSON.stringify(data, (k, v) => {
1447
+ if (v instanceof Uint8Array) {
1448
+ return Array.from(v);
1449
+ }
1450
+ return v;
1451
+ });
1452
+ }
1453
+ async getAccountInfo(address) {
1454
+ return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address, token_balances_filter: [] });
1455
+ }
1456
+ async getTokenInfo(tokenIds) {
1457
+ return this.request(this.proxyUrl, "set_proxy_getTokenInfo", { tokenIds: [Array.from(tokenIds)] });
1458
+ }
1459
+ async getNextNonce(address) {
1460
+ const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
1461
+ const accountInfoRes = await this.getAccountInfo(addressBytes);
1462
+ return accountInfoRes.result?.next_nonce ?? 0;
1463
+ }
1464
+ async submitTransaction(tx, signature) {
1465
+ const submitTxReq = { transaction: tx, signature };
1466
+ const response = await this.request(this.proxyUrl, "set_proxy_submitTransaction", submitTxReq);
1467
+ const proxyCert = this.parse_TransactionCertificate(response.result);
1468
+ console.log("FastSet Transaction Certificate:", proxyCert);
1469
+ return proxyCert;
1470
+ }
1471
+ parse_TransactionCertificate(res) {
1472
+ let bcs_bytes = TransactionCertificate.serialize(res).toBytes();
1473
+ let bcs_value = TransactionCertificate.parse(bcs_bytes);
1474
+ return bcs_value;
1475
+ }
1476
+ addressToBytes(address) {
1477
+ try {
1478
+ const decoded = bech32.bech32m.decode(address);
1479
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
1480
+ } catch {
1481
+ const decoded = bech32.bech32.decode(address);
1482
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
1483
+ }
1484
+ }
1485
+ static decodeBech32Address(address) {
1486
+ try {
1487
+ const decoded = bech32.bech32m.decode(address);
1488
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
1489
+ } catch {
1490
+ const decoded = bech32.bech32.decode(address);
1491
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
1492
+ }
1493
+ }
1494
+ static encodeBech32Address(publicKey) {
1495
+ const words = bech32.bech32m.toWords(publicKey);
1496
+ return bech32.bech32m.encode("set", words);
1497
+ }
1498
+ };
1499
+
1500
+ // src/helpers/general.ts
1501
+ var getConfiguredFastsetClient = (config, chain2) => {
1502
+ const providerConfig = (0, import_warps.getProviderConfig)(config, chain2.name, config.env, chain2.defaultApiUrl);
1503
+ return new FastsetClient(providerConfig.url);
1504
+ };
1505
+
1506
+ // src/tokens/fastset.ts
1507
+ var FastsetTokens = [
1508
+ {
1509
+ chain: "fastset",
1510
+ identifier: "08413efc81f99e5b8e03b852b3756674083110c6b65e6b7836b39a26e3908d3c",
1511
+ name: "Ethereum",
1512
+ symbol: "ETH",
1513
+ decimals: 18,
1514
+ logoUrl: "https://assets.coingecko.com/coins/images/279/small/ethereum.png",
1515
+ amount: 0n
1516
+ },
1517
+ {
1518
+ chain: "fastset",
1519
+ identifier: "0ee63eaa3ff9bf6e1c84a70133c5461e6e06d3787ed93200b924a6b82f0f35ff",
1520
+ name: "Bitcoin",
1521
+ symbol: "BTC",
1522
+ decimals: 8,
1523
+ logoUrl: "https://assets.coingecko.com/coins/images/1/small/bitcoin.png",
1524
+ amount: 0n
1525
+ },
1526
+ {
1527
+ chain: "fastset",
1528
+ identifier: "b69f0d3a4d7609367bd893ee3191e48b3047f2c4ccd21728c2441bcc2154f70c",
1529
+ name: "Solana",
1530
+ symbol: "SOL",
1531
+ decimals: 9,
1532
+ logoUrl: "https://assets.coingecko.com/coins/images/4128/small/solana.png",
1533
+ amount: 0n
1534
+ },
1535
+ {
1536
+ chain: "fastset",
1537
+ identifier: "c83166ed4e5e3ca88f7b2cf0ce2d310fa8c4d2ee2fc90d741f7b2040279b2687",
1538
+ name: "USD Coin",
1539
+ symbol: "USDC",
1540
+ decimals: 6,
1541
+ logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png",
1542
+ amount: 0n
1543
+ }
1544
+ ];
1545
+
1546
+ // src/tokens.ts
1547
+ var KnownTokens = {
1548
+ mainnet: FastsetTokens,
1549
+ testnet: FastsetTokens,
1550
+ devnet: FastsetTokens
1551
+ };
1552
+ var findKnownTokenBySymbol = (symbol, env = "mainnet") => {
1553
+ const tokens = KnownTokens[env] || [];
1554
+ return tokens.find((token) => token.symbol === symbol) || null;
1555
+ };
1556
+ var findKnownTokenById = (id2, env = "mainnet") => {
1557
+ const tokens = KnownTokens[env] || [];
1558
+ return tokens.find((token) => token.identifier === id2) || null;
1559
+ };
1560
+
1561
+ // src/WarpFastsetDataLoader.ts
1562
+ var WarpFastsetDataLoader = class {
1563
+ constructor(config, chain2) {
1564
+ this.config = config;
1565
+ this.chain = chain2;
1566
+ this.client = getConfiguredFastsetClient(config, chain2);
1567
+ }
1568
+ async getAccount(address) {
1569
+ const addressBytes = FastsetClient.decodeBech32Address(address);
1570
+ const accountInfo = await this.client.getAccountInfo(addressBytes);
1571
+ return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
1572
+ }
1573
+ async getAccountAssets(address) {
1574
+ const addressBytes = FastsetClient.decodeBech32Address(address);
1575
+ const accountInfo = await this.client.getAccountInfo(addressBytes);
1576
+ const assets = [];
1577
+ const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
1578
+ if (balance > 0n) {
1579
+ assets.push({ ...this.chain.nativeToken, amount: balance });
1580
+ }
1581
+ for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
1582
+ const amount = BigInt(parseInt(tokenBalance, 16));
1583
+ if (amount > 0n) {
1584
+ const assetInfo = await this.getAssetInfo(Buffer.from(tokenId).toString("hex"));
1585
+ if (!assetInfo) continue;
1586
+ assets.push({
1587
+ chain: this.chain.name,
1588
+ identifier: Buffer.from(tokenId).toString("hex"),
1589
+ symbol: assetInfo.symbol,
1590
+ name: assetInfo.name,
1591
+ decimals: assetInfo.decimals,
1592
+ logoUrl: assetInfo.logoUrl || "",
1593
+ amount
1594
+ });
1595
+ }
1596
+ }
1597
+ return assets;
1598
+ }
1599
+ async getAsset(identifier) {
1600
+ if (identifier === this.chain.nativeToken.identifier) {
1601
+ return this.chain.nativeToken;
1602
+ }
1603
+ const assetInfo = await this.getAssetInfo(identifier);
1604
+ if (!assetInfo) {
1605
+ return null;
1606
+ }
1607
+ return {
1608
+ chain: this.chain.name,
1609
+ identifier,
1610
+ symbol: assetInfo.symbol,
1611
+ name: assetInfo.name,
1612
+ decimals: assetInfo.decimals,
1613
+ logoUrl: assetInfo.logoUrl || null,
1614
+ amount: 0n
1615
+ };
1616
+ }
1617
+ async getAction(identifier, awaitCompleted = false) {
1618
+ return null;
1619
+ }
1620
+ async getAccountActions(address, options) {
1621
+ return [];
1622
+ }
1623
+ async getAssetInfo(identifier) {
1624
+ const knownToken = findKnownTokenById(identifier, this.config.env) || findKnownTokenBySymbol(identifier, this.config.env);
1625
+ if (knownToken) {
1626
+ return knownToken;
1627
+ }
1628
+ const tokenInfo = await this.client.getTokenInfo(hexToUint8Array(identifier));
1629
+ const metadata = tokenInfo.result?.requested_token_metadata[0]?.[1];
1630
+ if (metadata) {
1631
+ return {
1632
+ chain: this.chain.name,
1633
+ identifier,
1634
+ symbol: metadata.token_name,
1635
+ name: metadata.token_name,
1636
+ decimals: metadata.decimals,
1637
+ logoUrl: null
1638
+ };
1639
+ }
1640
+ return null;
1641
+ }
1642
+ };
1643
+
1644
+ // src/WarpFastsetExecutor.ts
1645
+ var import_warps2 = require("@vleap/warps");
1646
+ var WarpFastsetExecutor = class {
1647
+ constructor(config, chain2) {
1648
+ this.config = config;
1649
+ this.chain = chain2;
1650
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
1651
+ }
1652
+ async createTransaction(executable) {
1653
+ const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
1654
+ if (action.type === "transfer") return this.createTransferTransaction(executable);
1655
+ if (action.type === "contract") return this.createContractCallTransaction(executable);
1656
+ if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
1657
+ if (action.type === "collect")
1658
+ throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
1659
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
1660
+ }
1661
+ async createTransferTransaction(executable) {
1662
+ if (!executable.destination) throw new Error("WarpFastsetExecutor: createTransfer - destination not set");
1663
+ const userWallet = (0, import_warps2.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
1664
+ if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
1665
+ const senderPubKey = FastsetClient.decodeBech32Address(userWallet);
1666
+ const recipientPubKey = FastsetClient.decodeBech32Address(executable.destination);
1667
+ const nonce = await this.client.getNextNonce(userWallet);
1668
+ const isSingleNativeTransfer = executable.transfers.length === 1 && executable.transfers[0].identifier === this.chain.nativeToken?.identifier;
1669
+ const nativeAmountInTransfers = isSingleNativeTransfer ? executable.transfers[0].amount : 0n;
1670
+ const nativeAmountTotal = nativeAmountInTransfers + executable.value;
1671
+ if (nativeAmountTotal > 0n) {
1672
+ return {
1673
+ sender: senderPubKey,
1674
+ recipient: { FastSet: recipientPubKey },
1675
+ nonce,
1676
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
1677
+ claim: { Transfer: { amount: nativeAmountTotal.toString(16), user_data: null } }
1678
+ };
1679
+ } else if (executable.transfers.length === 1) {
1680
+ return {
1681
+ sender: senderPubKey,
1682
+ recipient: { FastSet: recipientPubKey },
1683
+ nonce,
1684
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
1685
+ claim: {
1686
+ TokenTransfer: {
1687
+ token_id: hexToUint8Array(executable.transfers[0].identifier),
1688
+ amount: executable.transfers[0].amount.toString(16),
1689
+ user_data: null
1690
+ }
1691
+ }
1692
+ };
1693
+ } else {
1694
+ throw new Error("WarpFastsetExecutor: No valid transfers provided (maximum 1 transfer allowed)");
1695
+ }
1696
+ }
1697
+ async createContractCallTransaction(executable) {
1698
+ throw new Error("WarpFastsetExecutor: Not implemented");
1699
+ }
1700
+ async executeQuery(executable) {
1701
+ throw new Error("WarpFastsetExecutor: Not implemented");
1702
+ }
1703
+ };
1704
+
1705
+ // src/WarpFastsetExplorer.ts
1706
+ var HEX_PREFIX = "0x";
1707
+ var WarpFastsetExplorer = class {
1708
+ constructor(_chainInfo, _config) {
1709
+ this._chainInfo = _chainInfo;
1710
+ this._config = _config;
1711
+ this.explorerUrl = "https://explorer.fastset.xyz";
1712
+ }
1713
+ getAccountUrl(address) {
1714
+ return `${this.explorerUrl}/account/${address}`;
1715
+ }
1716
+ getTransactionUrl(hash2) {
1717
+ return `${this.explorerUrl}/txs/${HEX_PREFIX}${hash2}`;
1718
+ }
1719
+ getAssetUrl(identifier) {
1720
+ return `${this.explorerUrl}/asset/${HEX_PREFIX}${identifier}`;
1721
+ }
1722
+ getContractUrl(address) {
1723
+ return `${this.explorerUrl}/account/${address}`;
1724
+ }
1725
+ };
1726
+
1727
+ // src/WarpFastsetOutput.ts
1728
+ var import_warps4 = require("@vleap/warps");
1729
+
1730
+ // src/WarpFastsetSerializer.ts
1731
+ var import_warps3 = require("@vleap/warps");
1732
+ var WarpFastsetSerializer = class {
1733
+ constructor() {
1734
+ this.coreSerializer = new import_warps3.WarpSerializer();
1735
+ }
1736
+ typedToString(value) {
1737
+ if (typeof value === "string") {
1738
+ return `string:${value}`;
1739
+ }
1740
+ if (typeof value === "number") {
1741
+ return `number:${value}`;
1742
+ }
1743
+ if (typeof value === "boolean") {
1744
+ return `boolean:${value}`;
1745
+ }
1746
+ if (typeof value === "bigint") {
1747
+ return `biguint:${value.toString()}`;
1748
+ }
1749
+ if (Array.isArray(value)) {
1750
+ const items = value.map((item) => this.typedToString(item)).join(",");
1751
+ return `array:${items}`;
1752
+ }
1753
+ if (value === null) {
1754
+ return "null:null";
1755
+ }
1756
+ if (value === void 0) {
1757
+ return "undefined:undefined";
1758
+ }
1759
+ return `string:${String(value)}`;
1760
+ }
1761
+ typedToNative(value) {
1762
+ if (typeof value === "string") {
1763
+ return ["string", value];
1764
+ }
1765
+ if (typeof value === "number") {
1766
+ return ["number", value];
1767
+ }
1768
+ if (typeof value === "boolean") {
1769
+ return ["boolean", value];
1770
+ }
1771
+ if (typeof value === "bigint") {
1772
+ return ["biguint", value.toString()];
1773
+ }
1774
+ return ["string", String(value)];
1775
+ }
1776
+ nativeToTyped(type, value) {
1777
+ switch (type) {
1778
+ case "string":
1779
+ return String(value);
1780
+ case "number":
1781
+ return Number(value);
1782
+ case "boolean":
1783
+ return Boolean(value);
1784
+ case "biguint":
1785
+ return BigInt(value);
1786
+ case "address":
1787
+ return String(value);
1788
+ case "hex":
1789
+ return String(value);
1790
+ default:
1791
+ return String(value);
1792
+ }
1793
+ }
1794
+ nativeToType(type) {
1795
+ switch (type) {
1796
+ case "string":
1797
+ return "string";
1798
+ case "number":
1799
+ return "number";
1800
+ case "boolean":
1801
+ return "boolean";
1802
+ case "biguint":
1803
+ return "biguint";
1804
+ case "address":
1805
+ return "address";
1806
+ case "hex":
1807
+ return "hex";
1808
+ default:
1809
+ return "string";
1810
+ }
1811
+ }
1812
+ stringToTyped(value) {
1813
+ const colonIndex = value.indexOf(":");
1814
+ if (colonIndex === -1) {
1815
+ return value;
1816
+ }
1817
+ const type = value.substring(0, colonIndex);
1818
+ const stringValue = value.substring(colonIndex + 1);
1819
+ switch (type) {
1820
+ case "string":
1821
+ return stringValue;
1822
+ case "number":
1823
+ return Number(stringValue);
1824
+ case "boolean":
1825
+ return stringValue === "true";
1826
+ case "biguint":
1827
+ return BigInt(stringValue);
1828
+ case "array":
1829
+ return stringValue.split(",").map((item) => this.stringToTyped(item));
1830
+ case "null":
1831
+ return null;
1832
+ case "undefined":
1833
+ return void 0;
1834
+ default:
1835
+ return stringValue;
1836
+ }
1837
+ }
1838
+ };
1839
+
1840
+ // src/WarpFastsetOutput.ts
1841
+ var WarpFastsetOutput = class {
1842
+ constructor(config, chain2) {
1843
+ this.config = config;
1844
+ this.chain = chain2;
1845
+ this.serializer = new WarpFastsetSerializer();
1846
+ }
1847
+ async getActionExecution(warp, actionIndex, tx) {
1848
+ const success = this.isTransactionSuccessful(tx);
1849
+ const transactionHash = this.extractTransactionHash(tx);
1850
+ const blockNumber = this.extractBlockNumber(tx);
1851
+ const timestamp = this.extractTimestamp(tx);
1852
+ const rawValues = [transactionHash, blockNumber, timestamp];
1853
+ const stringValues = rawValues.map((v) => String(v));
1854
+ return {
1855
+ status: success ? "success" : "error",
1856
+ warp,
1857
+ action: 0,
1858
+ user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
1859
+ txHash: transactionHash,
1860
+ tx,
1861
+ next: null,
1862
+ values: { string: stringValues, native: rawValues },
1863
+ output: {},
1864
+ messages: {},
1865
+ destination: null
1866
+ };
1867
+ }
1868
+ async extractQueryOutput(warp, typedValues, actionIndex, inputs) {
1869
+ const stringValues = typedValues.map((t) => this.serializer.typedToString(t));
1870
+ const nativeValues = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
1871
+ const values = { string: stringValues, native: nativeValues };
1872
+ let output = {};
1873
+ if (!warp.output) return { values, output };
1874
+ const getNestedValue = (path) => {
1875
+ const match = path.match(/^out\[(\d+)\]$/);
1876
+ if (match) {
1877
+ const index = parseInt(match[1]) - 1;
1878
+ return nativeValues[index];
1879
+ }
1880
+ const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
1881
+ if (indices.length === 0) return void 0;
1882
+ let value = nativeValues[indices[0]];
1883
+ for (let i = 1; i < indices.length; i++) {
1884
+ if (value === void 0 || value === null) return void 0;
1885
+ value = value[indices[i]];
1886
+ }
1887
+ return value;
1888
+ };
1889
+ for (const [key, path] of Object.entries(warp.output)) {
1890
+ if (path.startsWith(import_warps4.WarpConstants.Transform.Prefix)) continue;
1891
+ const currentActionIndex = (0, import_warps4.parseOutputOutIndex)(path);
1892
+ if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
1893
+ output[key] = null;
1894
+ continue;
1895
+ }
1896
+ if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
1897
+ const value = getNestedValue(path);
1898
+ output[key] = value || null;
1899
+ } else {
1900
+ output[key] = path;
1901
+ }
1902
+ }
1903
+ return {
1904
+ values,
1905
+ output: await (0, import_warps4.evaluateOutputCommon)(
1906
+ warp,
1907
+ output,
1908
+ actionIndex,
1909
+ inputs,
1910
+ this.serializer.coreSerializer,
1911
+ this.config
1912
+ )
1913
+ };
1914
+ }
1915
+ isTransactionSuccessful(tx) {
1916
+ if (!tx) return false;
1917
+ if (tx.success === false) return false;
1918
+ if (tx.success === true) return true;
1919
+ if (tx.status === "success") return true;
1920
+ if (tx.status === 1) return true;
1921
+ if (tx.result && tx.result.success === true) return true;
1922
+ return false;
1923
+ }
1924
+ extractTransactionHash(tx) {
1925
+ if (!tx) return "";
1926
+ return tx.transaction_hash || tx.transactionHash || tx.hash || tx.result && tx.result.transaction_hash || "";
1927
+ }
1928
+ extractBlockNumber(tx) {
1929
+ if (!tx) return "0";
1930
+ return tx.block_number?.toString() || tx.blockNumber?.toString() || tx.result && tx.result.block_number?.toString() || "0";
1931
+ }
1932
+ extractTimestamp(tx) {
1933
+ if (!tx) return "0";
1934
+ return tx.timestamp?.toString() || tx.timestamp_nanos?.toString() || tx.result && tx.result.timestamp?.toString() || Date.now().toString();
1935
+ }
1936
+ };
1937
+
1938
+ // src/WarpFastsetWallet.ts
1939
+ var bip39 = __toESM(require("@scure/bip39"), 1);
1940
+ var import_warps5 = require("@vleap/warps");
1941
+
1942
+ // ../../node_modules/@noble/ed25519/index.js
1943
+ var ed25519_exports = {};
1944
+ __export(ed25519_exports, {
1945
+ Point: () => Point,
1946
+ etc: () => etc,
1947
+ getPublicKey: () => getPublicKey,
1948
+ getPublicKeyAsync: () => getPublicKeyAsync,
1949
+ hash: () => hash,
1950
+ hashes: () => hashes,
1951
+ keygen: () => keygen,
1952
+ keygenAsync: () => keygenAsync,
1953
+ sign: () => sign,
1954
+ signAsync: () => signAsync,
1955
+ utils: () => utils,
1956
+ verify: () => verify,
1957
+ verifyAsync: () => verifyAsync
1958
+ });
1959
+ var ed25519_CURVE = {
1960
+ p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
1961
+ n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
1962
+ h: 8n,
1963
+ a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
1964
+ d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
1965
+ Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
1966
+ Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
1967
+ };
1968
+ var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
1969
+ var L = 32;
1970
+ var L2 = 64;
1971
+ var captureTrace = (...args) => {
1972
+ if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
1973
+ Error.captureStackTrace(...args);
1974
+ }
1975
+ };
1976
+ var err = (message = "") => {
1977
+ const e = new Error(message);
1978
+ captureTrace(e, err);
1979
+ throw e;
1980
+ };
1981
+ var isBig = (n) => typeof n === "bigint";
1982
+ var isStr = (s) => typeof s === "string";
1983
+ var isBytes2 = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
1984
+ var abytes = (value, length, title = "") => {
1985
+ const bytes = isBytes2(value);
1986
+ const len = value?.length;
1987
+ const needsLen = length !== void 0;
1988
+ if (!bytes || needsLen && len !== length) {
1989
+ const prefix = title && `"${title}" `;
1990
+ const ofLen = needsLen ? ` of length ${length}` : "";
1991
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
1992
+ err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
1993
+ }
1994
+ return value;
1995
+ };
1996
+ var u8n = (len) => new Uint8Array(len);
1997
+ var u8fr = (buf) => Uint8Array.from(buf);
1998
+ var padh = (n, pad) => n.toString(16).padStart(pad, "0");
1999
+ var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
2000
+ var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
2001
+ var _ch = (ch) => {
2002
+ if (ch >= C._0 && ch <= C._9)
2003
+ return ch - C._0;
2004
+ if (ch >= C.A && ch <= C.F)
2005
+ return ch - (C.A - 10);
2006
+ if (ch >= C.a && ch <= C.f)
2007
+ return ch - (C.a - 10);
2008
+ return;
2009
+ };
2010
+ var hexToBytes = (hex) => {
2011
+ const e = "hex invalid";
2012
+ if (!isStr(hex))
2013
+ return err(e);
2014
+ const hl = hex.length;
2015
+ const al = hl / 2;
2016
+ if (hl % 2)
2017
+ return err(e);
2018
+ const array = u8n(al);
2019
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
2020
+ const n1 = _ch(hex.charCodeAt(hi));
2021
+ const n2 = _ch(hex.charCodeAt(hi + 1));
2022
+ if (n1 === void 0 || n2 === void 0)
2023
+ return err(e);
2024
+ array[ai] = n1 * 16 + n2;
2025
+ }
2026
+ return array;
2027
+ };
2028
+ var cr = () => globalThis?.crypto;
2029
+ var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
2030
+ var concatBytes = (...arrs) => {
2031
+ const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
2032
+ let pad = 0;
2033
+ arrs.forEach((a) => {
2034
+ r.set(a, pad);
2035
+ pad += a.length;
2036
+ });
2037
+ return r;
2038
+ };
2039
+ var randomBytes = (len = L) => {
2040
+ const c = cr();
2041
+ return c.getRandomValues(u8n(len));
2042
+ };
2043
+ var big = BigInt;
2044
+ var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
2045
+ var M = (a, b = P) => {
2046
+ const r = a % b;
2047
+ return r >= 0n ? r : b + r;
2048
+ };
2049
+ var modN = (a) => M(a, N);
2050
+ var invert = (num, md) => {
2051
+ if (num === 0n || md <= 0n)
2052
+ err("no inverse n=" + num + " mod=" + md);
2053
+ let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
2054
+ while (a !== 0n) {
2055
+ const q = b / a, r = b % a;
2056
+ const m = x - u * q, n = y - v * q;
2057
+ b = a, a = r, x = u, y = v, u = m, v = n;
2058
+ }
2059
+ return b === 1n ? M(x, md) : err("no inverse");
2060
+ };
2061
+ var callHash = (name) => {
2062
+ const fn = hashes[name];
2063
+ if (typeof fn !== "function")
2064
+ err("hashes." + name + " not set");
2065
+ return fn;
2066
+ };
2067
+ var hash = (msg) => callHash("sha512")(msg);
2068
+ var apoint = (p) => p instanceof Point ? p : err("Point expected");
2069
+ var B256 = 2n ** 256n;
2070
+ var _Point = class _Point {
2071
+ constructor(X, Y, Z, T) {
2072
+ __publicField(this, "X");
2073
+ __publicField(this, "Y");
2074
+ __publicField(this, "Z");
2075
+ __publicField(this, "T");
2076
+ const max = B256;
2077
+ this.X = assertRange(X, 0n, max);
2078
+ this.Y = assertRange(Y, 0n, max);
2079
+ this.Z = assertRange(Z, 1n, max);
2080
+ this.T = assertRange(T, 0n, max);
2081
+ Object.freeze(this);
2082
+ }
2083
+ static CURVE() {
2084
+ return ed25519_CURVE;
2085
+ }
2086
+ static fromAffine(p) {
2087
+ return new _Point(p.x, p.y, 1n, M(p.x * p.y));
2088
+ }
2089
+ /** RFC8032 5.1.3: Uint8Array to Point. */
2090
+ static fromBytes(hex, zip215 = false) {
2091
+ const d = _d;
2092
+ const normed = u8fr(abytes(hex, L));
2093
+ const lastByte = hex[31];
2094
+ normed[31] = lastByte & ~128;
2095
+ const y = bytesToNumLE(normed);
2096
+ const max = zip215 ? B256 : P;
2097
+ assertRange(y, 0n, max);
2098
+ const y2 = M(y * y);
2099
+ const u = M(y2 - 1n);
2100
+ const v = M(d * y2 + 1n);
2101
+ let { isValid, value: x } = uvRatio(u, v);
2102
+ if (!isValid)
2103
+ err("bad point: y not sqrt");
2104
+ const isXOdd = (x & 1n) === 1n;
2105
+ const isLastByteOdd = (lastByte & 128) !== 0;
2106
+ if (!zip215 && x === 0n && isLastByteOdd)
2107
+ err("bad point: x==0, isLastByteOdd");
2108
+ if (isLastByteOdd !== isXOdd)
2109
+ x = M(-x);
2110
+ return new _Point(x, y, 1n, M(x * y));
2111
+ }
2112
+ static fromHex(hex, zip215) {
2113
+ return _Point.fromBytes(hexToBytes(hex), zip215);
2114
+ }
2115
+ get x() {
2116
+ return this.toAffine().x;
2117
+ }
2118
+ get y() {
2119
+ return this.toAffine().y;
2120
+ }
2121
+ /** Checks if the point is valid and on-curve. */
2122
+ assertValidity() {
2123
+ const a = _a;
2124
+ const d = _d;
2125
+ const p = this;
2126
+ if (p.is0())
2127
+ return err("bad point: ZERO");
2128
+ const { X, Y, Z, T } = p;
2129
+ const X2 = M(X * X);
2130
+ const Y2 = M(Y * Y);
2131
+ const Z2 = M(Z * Z);
2132
+ const Z4 = M(Z2 * Z2);
2133
+ const aX2 = M(X2 * a);
2134
+ const left = M(Z2 * M(aX2 + Y2));
2135
+ const right = M(Z4 + M(d * M(X2 * Y2)));
2136
+ if (left !== right)
2137
+ return err("bad point: equation left != right (1)");
2138
+ const XY = M(X * Y);
2139
+ const ZT = M(Z * T);
2140
+ if (XY !== ZT)
2141
+ return err("bad point: equation left != right (2)");
2142
+ return this;
2143
+ }
2144
+ /** Equality check: compare points P&Q. */
2145
+ equals(other) {
2146
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2147
+ const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
2148
+ const X1Z2 = M(X1 * Z2);
2149
+ const X2Z1 = M(X2 * Z1);
2150
+ const Y1Z2 = M(Y1 * Z2);
2151
+ const Y2Z1 = M(Y2 * Z1);
2152
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
2153
+ }
2154
+ is0() {
2155
+ return this.equals(I);
2156
+ }
2157
+ /** Flip point over y coordinate. */
2158
+ negate() {
2159
+ return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
2160
+ }
2161
+ /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
2162
+ double() {
2163
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2164
+ const a = _a;
2165
+ const A = M(X1 * X1);
2166
+ const B = M(Y1 * Y1);
2167
+ const C2 = M(2n * M(Z1 * Z1));
2168
+ const D = M(a * A);
2169
+ const x1y1 = X1 + Y1;
2170
+ const E = M(M(x1y1 * x1y1) - A - B);
2171
+ const G2 = D + B;
2172
+ const F = G2 - C2;
2173
+ const H = D - B;
2174
+ const X3 = M(E * F);
2175
+ const Y3 = M(G2 * H);
2176
+ const T3 = M(E * H);
2177
+ const Z3 = M(F * G2);
2178
+ return new _Point(X3, Y3, Z3, T3);
2179
+ }
2180
+ /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
2181
+ add(other) {
2182
+ const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
2183
+ const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
2184
+ const a = _a;
2185
+ const d = _d;
2186
+ const A = M(X1 * X2);
2187
+ const B = M(Y1 * Y2);
2188
+ const C2 = M(T1 * d * T2);
2189
+ const D = M(Z1 * Z2);
2190
+ const E = M((X1 + Y1) * (X2 + Y2) - A - B);
2191
+ const F = M(D - C2);
2192
+ const G2 = M(D + C2);
2193
+ const H = M(B - a * A);
2194
+ const X3 = M(E * F);
2195
+ const Y3 = M(G2 * H);
2196
+ const T3 = M(E * H);
2197
+ const Z3 = M(F * G2);
2198
+ return new _Point(X3, Y3, Z3, T3);
2199
+ }
2200
+ subtract(other) {
2201
+ return this.add(apoint(other).negate());
2202
+ }
2203
+ /**
2204
+ * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
2205
+ * Uses {@link wNAF} for base point.
2206
+ * Uses fake point to mitigate side-channel leakage.
2207
+ * @param n scalar by which point is multiplied
2208
+ * @param safe safe mode guards against timing attacks; unsafe mode is faster
2209
+ */
2210
+ multiply(n, safe = true) {
2211
+ if (!safe && (n === 0n || this.is0()))
2212
+ return I;
2213
+ assertRange(n, 1n, N);
2214
+ if (n === 1n)
2215
+ return this;
2216
+ if (this.equals(G))
2217
+ return wNAF(n).p;
2218
+ let p = I;
2219
+ let f = G;
2220
+ for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
2221
+ if (n & 1n)
2222
+ p = p.add(d);
2223
+ else if (safe)
2224
+ f = f.add(d);
2225
+ }
2226
+ return p;
2227
+ }
2228
+ multiplyUnsafe(scalar) {
2229
+ return this.multiply(scalar, false);
2230
+ }
2231
+ /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
2232
+ toAffine() {
2233
+ const { X, Y, Z } = this;
2234
+ if (this.equals(I))
2235
+ return { x: 0n, y: 1n };
2236
+ const iz = invert(Z, P);
2237
+ if (M(Z * iz) !== 1n)
2238
+ err("invalid inverse");
2239
+ const x = M(X * iz);
2240
+ const y = M(Y * iz);
2241
+ return { x, y };
2242
+ }
2243
+ toBytes() {
2244
+ const { x, y } = this.assertValidity().toAffine();
2245
+ const b = numTo32bLE(y);
2246
+ b[31] |= x & 1n ? 128 : 0;
2247
+ return b;
2248
+ }
2249
+ toHex() {
2250
+ return bytesToHex(this.toBytes());
2251
+ }
2252
+ clearCofactor() {
2253
+ return this.multiply(big(h), false);
2254
+ }
2255
+ isSmallOrder() {
2256
+ return this.clearCofactor().is0();
2257
+ }
2258
+ isTorsionFree() {
2259
+ let p = this.multiply(N / 2n, false).double();
2260
+ if (N % 2n)
2261
+ p = p.add(this);
2262
+ return p.is0();
2263
+ }
2264
+ };
2265
+ __publicField(_Point, "BASE");
2266
+ __publicField(_Point, "ZERO");
2267
+ var Point = _Point;
2268
+ var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
2269
+ var I = new Point(0n, 1n, 1n, 0n);
2270
+ Point.BASE = G;
2271
+ Point.ZERO = I;
2272
+ var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
2273
+ var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
2274
+ var pow2 = (x, power) => {
2275
+ let r = x;
2276
+ while (power-- > 0n) {
2277
+ r *= r;
2278
+ r %= P;
2279
+ }
2280
+ return r;
2281
+ };
2282
+ var pow_2_252_3 = (x) => {
2283
+ const x2 = x * x % P;
2284
+ const b2 = x2 * x % P;
2285
+ const b4 = pow2(b2, 2n) * b2 % P;
2286
+ const b5 = pow2(b4, 1n) * x % P;
2287
+ const b10 = pow2(b5, 5n) * b5 % P;
2288
+ const b20 = pow2(b10, 10n) * b10 % P;
2289
+ const b40 = pow2(b20, 20n) * b20 % P;
2290
+ const b80 = pow2(b40, 40n) * b40 % P;
2291
+ const b160 = pow2(b80, 80n) * b80 % P;
2292
+ const b240 = pow2(b160, 80n) * b80 % P;
2293
+ const b250 = pow2(b240, 10n) * b10 % P;
2294
+ const pow_p_5_8 = pow2(b250, 2n) * x % P;
2295
+ return { pow_p_5_8, b2 };
2296
+ };
2297
+ var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
2298
+ var uvRatio = (u, v) => {
2299
+ const v3 = M(v * v * v);
2300
+ const v7 = M(v3 * v3 * v);
2301
+ const pow = pow_2_252_3(u * v7).pow_p_5_8;
2302
+ let x = M(u * v3 * pow);
2303
+ const vx2 = M(v * x * x);
2304
+ const root1 = x;
2305
+ const root2 = M(x * RM1);
2306
+ const useRoot1 = vx2 === u;
2307
+ const useRoot2 = vx2 === M(-u);
2308
+ const noRoot = vx2 === M(-u * RM1);
2309
+ if (useRoot1)
2310
+ x = root1;
2311
+ if (useRoot2 || noRoot)
2312
+ x = root2;
2313
+ if ((M(x) & 1n) === 1n)
2314
+ x = M(-x);
2315
+ return { isValid: useRoot1 || useRoot2, value: x };
2316
+ };
2317
+ var modL_LE = (hash2) => modN(bytesToNumLE(hash2));
2318
+ var sha512a = (...m) => hashes.sha512Async(concatBytes(...m));
2319
+ var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
2320
+ var hash2extK = (hashed) => {
2321
+ const head = hashed.slice(0, L);
2322
+ head[0] &= 248;
2323
+ head[31] &= 127;
2324
+ head[31] |= 64;
2325
+ const prefix = hashed.slice(L, L2);
2326
+ const scalar = modL_LE(head);
2327
+ const point = G.multiply(scalar);
2328
+ const pointBytes = point.toBytes();
2329
+ return { head, prefix, scalar, point, pointBytes };
2330
+ };
2331
+ var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
2332
+ var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
2333
+ var getPublicKeyAsync = (secretKey) => getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
2334
+ var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
2335
+ var hashFinishA = (res) => sha512a(res.hashable).then(res.finish);
2336
+ var hashFinishS = (res) => res.finish(sha512s(res.hashable));
2337
+ var _sign = (e, rBytes, msg) => {
2338
+ const { pointBytes: P2, scalar: s } = e;
2339
+ const r = modL_LE(rBytes);
2340
+ const R = G.multiply(r).toBytes();
2341
+ const hashable = concatBytes(R, P2, msg);
2342
+ const finish = (hashed) => {
2343
+ const S = modN(r + modL_LE(hashed) * s);
2344
+ return abytes(concatBytes(R, numTo32bLE(S)), L2);
2345
+ };
2346
+ return { hashable, finish };
2347
+ };
2348
+ var signAsync = async (message, secretKey) => {
2349
+ const m = abytes(message);
2350
+ const e = await getExtendedPublicKeyAsync(secretKey);
2351
+ const rBytes = await sha512a(e.prefix, m);
2352
+ return hashFinishA(_sign(e, rBytes, m));
2353
+ };
2354
+ var sign = (message, secretKey) => {
2355
+ const m = abytes(message);
2356
+ const e = getExtendedPublicKey(secretKey);
2357
+ const rBytes = sha512s(e.prefix, m);
2358
+ return hashFinishS(_sign(e, rBytes, m));
2359
+ };
2360
+ var defaultVerifyOpts = { zip215: true };
2361
+ var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
2362
+ sig = abytes(sig, L2);
2363
+ msg = abytes(msg);
2364
+ pub = abytes(pub, L);
2365
+ const { zip215 } = opts;
2366
+ let A;
2367
+ let R;
2368
+ let s;
2369
+ let SB;
2370
+ let hashable = Uint8Array.of();
2371
+ try {
2372
+ A = Point.fromBytes(pub, zip215);
2373
+ R = Point.fromBytes(sig.slice(0, L), zip215);
2374
+ s = bytesToNumLE(sig.slice(L, L2));
2375
+ SB = G.multiply(s, false);
2376
+ hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
2377
+ } catch (error) {
2378
+ }
2379
+ const finish = (hashed) => {
2380
+ if (SB == null)
2381
+ return false;
2382
+ if (!zip215 && A.isSmallOrder())
2383
+ return false;
2384
+ const k = modL_LE(hashed);
2385
+ const RkA = R.add(A.multiply(k, false));
2386
+ return RkA.add(SB.negate()).clearCofactor().is0();
2387
+ };
2388
+ return { hashable, finish };
2389
+ };
2390
+ var verifyAsync = async (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishA(_verify(signature, message, publicKey, opts));
2391
+ var verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
2392
+ var etc = {
2393
+ bytesToHex,
2394
+ hexToBytes,
2395
+ concatBytes,
2396
+ mod: M,
2397
+ invert,
2398
+ randomBytes
2399
+ };
2400
+ var hashes = {
2401
+ sha512Async: async (message) => {
2402
+ const s = subtle();
2403
+ const m = concatBytes(message);
2404
+ return u8n(await s.digest("SHA-512", m.buffer));
2405
+ },
2406
+ sha512: void 0
2407
+ };
2408
+ var randomSecretKey = (seed = randomBytes(L)) => seed;
2409
+ var keygen = (seed) => {
2410
+ const secretKey = randomSecretKey(seed);
2411
+ const publicKey = getPublicKey(secretKey);
2412
+ return { secretKey, publicKey };
2413
+ };
2414
+ var keygenAsync = async (seed) => {
2415
+ const secretKey = randomSecretKey(seed);
2416
+ const publicKey = await getPublicKeyAsync(secretKey);
2417
+ return { secretKey, publicKey };
2418
+ };
2419
+ var utils = {
2420
+ getExtendedPublicKeyAsync,
2421
+ getExtendedPublicKey,
2422
+ randomSecretKey
2423
+ };
2424
+ var W = 8;
2425
+ var scalarBits = 256;
2426
+ var pwindows = Math.ceil(scalarBits / W) + 1;
2427
+ var pwindowSize = 2 ** (W - 1);
2428
+ var precompute = () => {
2429
+ const points = [];
2430
+ let p = G;
2431
+ let b = p;
2432
+ for (let w = 0; w < pwindows; w++) {
2433
+ b = p;
2434
+ points.push(b);
2435
+ for (let i = 1; i < pwindowSize; i++) {
2436
+ b = b.add(p);
2437
+ points.push(b);
2438
+ }
2439
+ p = b.double();
2440
+ }
2441
+ return points;
2442
+ };
2443
+ var Gpows = void 0;
2444
+ var ctneg = (cnd, p) => {
2445
+ const n = p.negate();
2446
+ return cnd ? n : p;
2447
+ };
2448
+ var wNAF = (n) => {
2449
+ const comp = Gpows || (Gpows = precompute());
2450
+ let p = I;
2451
+ let f = G;
2452
+ const pow_2_w = 2 ** W;
2453
+ const maxNum = pow_2_w;
2454
+ const mask = big(pow_2_w - 1);
2455
+ const shiftBy = big(W);
2456
+ for (let w = 0; w < pwindows; w++) {
2457
+ let wbits = Number(n & mask);
2458
+ n >>= shiftBy;
2459
+ if (wbits > pwindowSize) {
2460
+ wbits -= maxNum;
2461
+ n += 1n;
2462
+ }
2463
+ const off = w * pwindowSize;
2464
+ const offF = off;
2465
+ const offP = off + Math.abs(wbits) - 1;
2466
+ const isEven = w % 2 !== 0;
2467
+ const isNeg = wbits < 0;
2468
+ if (wbits === 0) {
2469
+ f = f.add(ctneg(isEven, comp[offF]));
2470
+ } else {
2471
+ p = p.add(ctneg(isNeg, comp[offP]));
2472
+ }
2473
+ }
2474
+ if (n !== 0n)
2475
+ err("invalid wnaf");
2476
+ return { p, f };
2477
+ };
2478
+
2479
+ // node_modules/@noble/hashes/utils.js
2480
+ function isBytes3(a) {
2481
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
2482
+ }
2483
+ function abytes2(value, length, title = "") {
2484
+ const bytes = isBytes3(value);
2485
+ const len = value?.length;
2486
+ const needsLen = length !== void 0;
2487
+ if (!bytes || needsLen && len !== length) {
2488
+ const prefix = title && `"${title}" `;
2489
+ const ofLen = needsLen ? ` of length ${length}` : "";
2490
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
2491
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
2492
+ }
2493
+ return value;
2494
+ }
2495
+ function aexists(instance, checkFinished = true) {
2496
+ if (instance.destroyed)
2497
+ throw new Error("Hash instance has been destroyed");
2498
+ if (checkFinished && instance.finished)
2499
+ throw new Error("Hash#digest() has already been called");
2500
+ }
2501
+ function aoutput(out, instance) {
2502
+ abytes2(out, void 0, "digestInto() output");
2503
+ const min = instance.outputLen;
2504
+ if (out.length < min) {
2505
+ throw new Error('"digestInto() output" expected to be of length >=' + min);
2506
+ }
2507
+ }
2508
+ function clean(...arrays) {
2509
+ for (let i = 0; i < arrays.length; i++) {
2510
+ arrays[i].fill(0);
2511
+ }
2512
+ }
2513
+ function createView(arr) {
2514
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2515
+ }
2516
+ function createHasher(hashCons, info = {}) {
2517
+ const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
2518
+ const tmp = hashCons(void 0);
2519
+ hashC.outputLen = tmp.outputLen;
2520
+ hashC.blockLen = tmp.blockLen;
2521
+ hashC.create = (opts) => hashCons(opts);
2522
+ Object.assign(hashC, info);
2523
+ return Object.freeze(hashC);
2524
+ }
2525
+ var oidNist = (suffix) => ({
2526
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
2527
+ });
2528
+
2529
+ // node_modules/@noble/hashes/_md.js
2530
+ var HashMD = class {
2531
+ constructor(blockLen, outputLen, padOffset, isLE) {
2532
+ __publicField(this, "blockLen");
2533
+ __publicField(this, "outputLen");
2534
+ __publicField(this, "padOffset");
2535
+ __publicField(this, "isLE");
2536
+ // For partial updates less than block size
2537
+ __publicField(this, "buffer");
2538
+ __publicField(this, "view");
2539
+ __publicField(this, "finished", false);
2540
+ __publicField(this, "length", 0);
2541
+ __publicField(this, "pos", 0);
2542
+ __publicField(this, "destroyed", false);
2543
+ this.blockLen = blockLen;
2544
+ this.outputLen = outputLen;
2545
+ this.padOffset = padOffset;
2546
+ this.isLE = isLE;
2547
+ this.buffer = new Uint8Array(blockLen);
2548
+ this.view = createView(this.buffer);
2549
+ }
2550
+ update(data) {
2551
+ aexists(this);
2552
+ abytes2(data);
2553
+ const { view, buffer, blockLen } = this;
2554
+ const len = data.length;
2555
+ for (let pos = 0; pos < len; ) {
2556
+ const take = Math.min(blockLen - this.pos, len - pos);
2557
+ if (take === blockLen) {
2558
+ const dataView = createView(data);
2559
+ for (; blockLen <= len - pos; pos += blockLen)
2560
+ this.process(dataView, pos);
2561
+ continue;
2562
+ }
2563
+ buffer.set(data.subarray(pos, pos + take), this.pos);
2564
+ this.pos += take;
2565
+ pos += take;
2566
+ if (this.pos === blockLen) {
2567
+ this.process(view, 0);
2568
+ this.pos = 0;
2569
+ }
2570
+ }
2571
+ this.length += data.length;
2572
+ this.roundClean();
2573
+ return this;
2574
+ }
2575
+ digestInto(out) {
2576
+ aexists(this);
2577
+ aoutput(out, this);
2578
+ this.finished = true;
2579
+ const { buffer, view, blockLen, isLE } = this;
2580
+ let { pos } = this;
2581
+ buffer[pos++] = 128;
2582
+ clean(this.buffer.subarray(pos));
2583
+ if (this.padOffset > blockLen - pos) {
2584
+ this.process(view, 0);
2585
+ pos = 0;
2586
+ }
2587
+ for (let i = pos; i < blockLen; i++)
2588
+ buffer[i] = 0;
2589
+ view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
2590
+ this.process(view, 0);
2591
+ const oview = createView(out);
2592
+ const len = this.outputLen;
2593
+ if (len % 4)
2594
+ throw new Error("_sha2: outputLen must be aligned to 32bit");
2595
+ const outLen = len / 4;
2596
+ const state = this.get();
2597
+ if (outLen > state.length)
2598
+ throw new Error("_sha2: outputLen bigger than state");
2599
+ for (let i = 0; i < outLen; i++)
2600
+ oview.setUint32(4 * i, state[i], isLE);
2601
+ }
2602
+ digest() {
2603
+ const { buffer, outputLen } = this;
2604
+ this.digestInto(buffer);
2605
+ const res = buffer.slice(0, outputLen);
2606
+ this.destroy();
2607
+ return res;
2608
+ }
2609
+ _cloneInto(to) {
2610
+ to || (to = new this.constructor());
2611
+ to.set(...this.get());
2612
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
2613
+ to.destroyed = destroyed;
2614
+ to.finished = finished;
2615
+ to.length = length;
2616
+ to.pos = pos;
2617
+ if (length % blockLen)
2618
+ to.buffer.set(buffer);
2619
+ return to;
2620
+ }
2621
+ clone() {
2622
+ return this._cloneInto();
2623
+ }
2624
+ };
2625
+ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
2626
+ 1779033703,
2627
+ 4089235720,
2628
+ 3144134277,
2629
+ 2227873595,
2630
+ 1013904242,
2631
+ 4271175723,
2632
+ 2773480762,
2633
+ 1595750129,
2634
+ 1359893119,
2635
+ 2917565137,
2636
+ 2600822924,
2637
+ 725511199,
2638
+ 528734635,
2639
+ 4215389547,
2640
+ 1541459225,
2641
+ 327033209
2642
+ ]);
2643
+
2644
+ // node_modules/@noble/hashes/_u64.js
2645
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
2646
+ var _32n = /* @__PURE__ */ BigInt(32);
2647
+ function fromBig(n, le = false) {
2648
+ if (le)
2649
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
2650
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
2651
+ }
2652
+ function split(lst, le = false) {
2653
+ const len = lst.length;
2654
+ let Ah = new Uint32Array(len);
2655
+ let Al = new Uint32Array(len);
2656
+ for (let i = 0; i < len; i++) {
2657
+ const { h: h2, l } = fromBig(lst[i], le);
2658
+ [Ah[i], Al[i]] = [h2, l];
2659
+ }
2660
+ return [Ah, Al];
2661
+ }
2662
+ var shrSH = (h2, _l, s) => h2 >>> s;
2663
+ var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
2664
+ var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
2665
+ var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
2666
+ var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
2667
+ var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
2668
+ function add(Ah, Al, Bh, Bl) {
2669
+ const l = (Al >>> 0) + (Bl >>> 0);
2670
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
2671
+ }
2672
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
2673
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
2674
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
2675
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
2676
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
2677
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
2678
+
2679
+ // node_modules/@noble/hashes/sha2.js
2680
+ var K512 = /* @__PURE__ */ (() => split([
2681
+ "0x428a2f98d728ae22",
2682
+ "0x7137449123ef65cd",
2683
+ "0xb5c0fbcfec4d3b2f",
2684
+ "0xe9b5dba58189dbbc",
2685
+ "0x3956c25bf348b538",
2686
+ "0x59f111f1b605d019",
2687
+ "0x923f82a4af194f9b",
2688
+ "0xab1c5ed5da6d8118",
2689
+ "0xd807aa98a3030242",
2690
+ "0x12835b0145706fbe",
2691
+ "0x243185be4ee4b28c",
2692
+ "0x550c7dc3d5ffb4e2",
2693
+ "0x72be5d74f27b896f",
2694
+ "0x80deb1fe3b1696b1",
2695
+ "0x9bdc06a725c71235",
2696
+ "0xc19bf174cf692694",
2697
+ "0xe49b69c19ef14ad2",
2698
+ "0xefbe4786384f25e3",
2699
+ "0x0fc19dc68b8cd5b5",
2700
+ "0x240ca1cc77ac9c65",
2701
+ "0x2de92c6f592b0275",
2702
+ "0x4a7484aa6ea6e483",
2703
+ "0x5cb0a9dcbd41fbd4",
2704
+ "0x76f988da831153b5",
2705
+ "0x983e5152ee66dfab",
2706
+ "0xa831c66d2db43210",
2707
+ "0xb00327c898fb213f",
2708
+ "0xbf597fc7beef0ee4",
2709
+ "0xc6e00bf33da88fc2",
2710
+ "0xd5a79147930aa725",
2711
+ "0x06ca6351e003826f",
2712
+ "0x142929670a0e6e70",
2713
+ "0x27b70a8546d22ffc",
2714
+ "0x2e1b21385c26c926",
2715
+ "0x4d2c6dfc5ac42aed",
2716
+ "0x53380d139d95b3df",
2717
+ "0x650a73548baf63de",
2718
+ "0x766a0abb3c77b2a8",
2719
+ "0x81c2c92e47edaee6",
2720
+ "0x92722c851482353b",
2721
+ "0xa2bfe8a14cf10364",
2722
+ "0xa81a664bbc423001",
2723
+ "0xc24b8b70d0f89791",
2724
+ "0xc76c51a30654be30",
2725
+ "0xd192e819d6ef5218",
2726
+ "0xd69906245565a910",
2727
+ "0xf40e35855771202a",
2728
+ "0x106aa07032bbd1b8",
2729
+ "0x19a4c116b8d2d0c8",
2730
+ "0x1e376c085141ab53",
2731
+ "0x2748774cdf8eeb99",
2732
+ "0x34b0bcb5e19b48a8",
2733
+ "0x391c0cb3c5c95a63",
2734
+ "0x4ed8aa4ae3418acb",
2735
+ "0x5b9cca4f7763e373",
2736
+ "0x682e6ff3d6b2b8a3",
2737
+ "0x748f82ee5defb2fc",
2738
+ "0x78a5636f43172f60",
2739
+ "0x84c87814a1f0ab72",
2740
+ "0x8cc702081a6439ec",
2741
+ "0x90befffa23631e28",
2742
+ "0xa4506cebde82bde9",
2743
+ "0xbef9a3f7b2c67915",
2744
+ "0xc67178f2e372532b",
2745
+ "0xca273eceea26619c",
2746
+ "0xd186b8c721c0c207",
2747
+ "0xeada7dd6cde0eb1e",
2748
+ "0xf57d4f7fee6ed178",
2749
+ "0x06f067aa72176fba",
2750
+ "0x0a637dc5a2c898a6",
2751
+ "0x113f9804bef90dae",
2752
+ "0x1b710b35131c471b",
2753
+ "0x28db77f523047d84",
2754
+ "0x32caab7b40c72493",
2755
+ "0x3c9ebe0a15c9bebc",
2756
+ "0x431d67c49c100d4c",
2757
+ "0x4cc5d4becb3e42b6",
2758
+ "0x597f299cfc657e2a",
2759
+ "0x5fcb6fab3ad6faec",
2760
+ "0x6c44198c4a475817"
2761
+ ].map((n) => BigInt(n))))();
2762
+ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
2763
+ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
2764
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
2765
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
2766
+ var SHA2_64B = class extends HashMD {
2767
+ constructor(outputLen) {
2768
+ super(128, outputLen, 16, false);
2769
+ }
2770
+ // prettier-ignore
2771
+ get() {
2772
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
2773
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
2774
+ }
2775
+ // prettier-ignore
2776
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
2777
+ this.Ah = Ah | 0;
2778
+ this.Al = Al | 0;
2779
+ this.Bh = Bh | 0;
2780
+ this.Bl = Bl | 0;
2781
+ this.Ch = Ch | 0;
2782
+ this.Cl = Cl | 0;
2783
+ this.Dh = Dh | 0;
2784
+ this.Dl = Dl | 0;
2785
+ this.Eh = Eh | 0;
2786
+ this.El = El | 0;
2787
+ this.Fh = Fh | 0;
2788
+ this.Fl = Fl | 0;
2789
+ this.Gh = Gh | 0;
2790
+ this.Gl = Gl | 0;
2791
+ this.Hh = Hh | 0;
2792
+ this.Hl = Hl | 0;
2793
+ }
2794
+ process(view, offset) {
2795
+ for (let i = 0; i < 16; i++, offset += 4) {
2796
+ SHA512_W_H[i] = view.getUint32(offset);
2797
+ SHA512_W_L[i] = view.getUint32(offset += 4);
2798
+ }
2799
+ for (let i = 16; i < 80; i++) {
2800
+ const W15h = SHA512_W_H[i - 15] | 0;
2801
+ const W15l = SHA512_W_L[i - 15] | 0;
2802
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
2803
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
2804
+ const W2h = SHA512_W_H[i - 2] | 0;
2805
+ const W2l = SHA512_W_L[i - 2] | 0;
2806
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
2807
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
2808
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
2809
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
2810
+ SHA512_W_H[i] = SUMh | 0;
2811
+ SHA512_W_L[i] = SUMl | 0;
2812
+ }
2813
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
2814
+ for (let i = 0; i < 80; i++) {
2815
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
2816
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
2817
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
2818
+ const CHIl = El & Fl ^ ~El & Gl;
2819
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
2820
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
2821
+ const T1l = T1ll | 0;
2822
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
2823
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
2824
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
2825
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
2826
+ Hh = Gh | 0;
2827
+ Hl = Gl | 0;
2828
+ Gh = Fh | 0;
2829
+ Gl = Fl | 0;
2830
+ Fh = Eh | 0;
2831
+ Fl = El | 0;
2832
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
2833
+ Dh = Ch | 0;
2834
+ Dl = Cl | 0;
2835
+ Ch = Bh | 0;
2836
+ Cl = Bl | 0;
2837
+ Bh = Ah | 0;
2838
+ Bl = Al | 0;
2839
+ const All = add3L(T1l, sigma0l, MAJl);
2840
+ Ah = add3H(All, T1h, sigma0h, MAJh);
2841
+ Al = All | 0;
2842
+ }
2843
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
2844
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
2845
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
2846
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
2847
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
2848
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
2849
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
2850
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
2851
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
2852
+ }
2853
+ roundClean() {
2854
+ clean(SHA512_W_H, SHA512_W_L);
2855
+ }
2856
+ destroy() {
2857
+ clean(this.buffer);
2858
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2859
+ }
2860
+ };
2861
+ var _SHA512 = class extends SHA2_64B {
2862
+ constructor() {
2863
+ super(64);
2864
+ __publicField(this, "Ah", SHA512_IV[0] | 0);
2865
+ __publicField(this, "Al", SHA512_IV[1] | 0);
2866
+ __publicField(this, "Bh", SHA512_IV[2] | 0);
2867
+ __publicField(this, "Bl", SHA512_IV[3] | 0);
2868
+ __publicField(this, "Ch", SHA512_IV[4] | 0);
2869
+ __publicField(this, "Cl", SHA512_IV[5] | 0);
2870
+ __publicField(this, "Dh", SHA512_IV[6] | 0);
2871
+ __publicField(this, "Dl", SHA512_IV[7] | 0);
2872
+ __publicField(this, "Eh", SHA512_IV[8] | 0);
2873
+ __publicField(this, "El", SHA512_IV[9] | 0);
2874
+ __publicField(this, "Fh", SHA512_IV[10] | 0);
2875
+ __publicField(this, "Fl", SHA512_IV[11] | 0);
2876
+ __publicField(this, "Gh", SHA512_IV[12] | 0);
2877
+ __publicField(this, "Gl", SHA512_IV[13] | 0);
2878
+ __publicField(this, "Hh", SHA512_IV[14] | 0);
2879
+ __publicField(this, "Hl", SHA512_IV[15] | 0);
2880
+ }
2881
+ };
2882
+ var sha512 = /* @__PURE__ */ createHasher(
2883
+ () => new _SHA512(),
2884
+ /* @__PURE__ */ oidNist(3)
2885
+ );
2886
+
2887
+ // src/sdk/ed25519-setup.ts
2888
+ hashes.sha512 = sha512;
2889
+
2890
+ // src/WarpFastsetWallet.ts
2891
+ var WarpFastsetWallet = class {
2892
+ constructor(config, chain2) {
2893
+ this.config = config;
2894
+ this.chain = chain2;
2895
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
2896
+ }
2897
+ async signTransaction(tx) {
2898
+ const msg = Transaction.serialize(tx);
2899
+ const msgBytes = msg.toBytes();
2900
+ const prefix = new TextEncoder().encode("Transaction::");
2901
+ const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
2902
+ dataToSign.set(prefix, 0);
2903
+ dataToSign.set(msgBytes, prefix.length);
2904
+ const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
2905
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
2906
+ const privateKeyBytes = hexToUint8Array(privateKey);
2907
+ const signature = ed25519_exports.sign(dataToSign, privateKeyBytes);
2908
+ return { ...tx, signature };
2909
+ }
2910
+ async signMessage(message) {
2911
+ const messageBytes = stringToUint8Array(message);
2912
+ const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
2913
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
2914
+ const privateKeyBytes = hexToUint8Array(privateKey);
2915
+ const signature = ed25519_exports.sign(messageBytes, privateKeyBytes);
2916
+ return uint8ArrayToHex(signature);
2917
+ }
2918
+ async signTransactions(txs) {
2919
+ return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
2920
+ }
2921
+ async sendTransaction(tx) {
2922
+ const { signature, ...transactionWithoutSignature } = tx;
2923
+ const _cert = await this.client.submitTransaction(transactionWithoutSignature, signature ?? null);
2924
+ return "TODO";
2925
+ }
2926
+ async sendTransactions(txs) {
2927
+ return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
2928
+ }
2929
+ create(mnemonic) {
2930
+ const seed = bip39.mnemonicToSeedSync(mnemonic);
2931
+ const privateKey = seed.slice(0, 32);
2932
+ const publicKey = ed25519_exports.getPublicKey(privateKey);
2933
+ const address = FastsetClient.encodeBech32Address(publicKey);
2934
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
2935
+ }
2936
+ generate() {
2937
+ const privateKey = ed25519_exports.utils.randomSecretKey();
2938
+ const publicKey = ed25519_exports.getPublicKey(privateKey);
2939
+ const address = FastsetClient.encodeBech32Address(publicKey);
2940
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
2941
+ }
2942
+ getAddress() {
2943
+ return (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
2944
+ }
2945
+ };
2946
+
2947
+ // src/main.ts
2948
+ var NativeTokenSet = {
2949
+ chain: import_warps6.WarpChainName.Fastset,
2950
+ identifier: "SET",
2951
+ name: "SET",
2952
+ symbol: "SET",
2953
+ decimals: 0,
2954
+ logoUrl: "https://vleap.ai/images/tokens/set.svg"
2955
+ };
2956
+ function createFastsetAdapter(chainName, chainInfos) {
2957
+ return (config, fallback) => {
2958
+ const chainInfo = chainInfos[config.env];
2959
+ if (!chainInfo) throw new Error(`FastsetAdapter: chain info not found for chain ${chainName}`);
2960
+ if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
2961
+ return {
2962
+ chainInfo,
2963
+ builder: () => fallback.builder(),
2964
+ executor: new WarpFastsetExecutor(config, chainInfo),
2965
+ output: new WarpFastsetOutput(config, chainInfo),
2966
+ serializer: new WarpFastsetSerializer(),
2967
+ registry: fallback.registry,
2968
+ explorer: new WarpFastsetExplorer(chainInfo, config),
2969
+ abiBuilder: () => fallback.abiBuilder(),
2970
+ brandBuilder: () => fallback.brandBuilder(),
2971
+ dataLoader: new WarpFastsetDataLoader(config, chainInfo),
2972
+ wallet: new WarpFastsetWallet(config, chainInfo)
2973
+ };
2974
+ };
2975
+ }
2976
+ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset, {
2977
+ mainnet: {
2978
+ name: import_warps6.WarpChainName.Fastset,
2979
+ displayName: "FastSet",
2980
+ chainId: "1",
2981
+ blockTime: 1e3,
2982
+ addressHrp: "set",
2983
+ defaultApiUrl: "https://proxy.fastset.xyz",
2984
+ logoUrl: "https://vleap.ai/images/chains/fastset.svg",
2985
+ nativeToken: NativeTokenSet
2986
+ },
2987
+ testnet: {
2988
+ name: import_warps6.WarpChainName.Fastset,
2989
+ displayName: "FastSet Testnet",
2990
+ chainId: "testnet",
2991
+ blockTime: 1e3,
2992
+ addressHrp: "set",
2993
+ defaultApiUrl: "https://proxy.fastset.xyz",
2994
+ logoUrl: "https://vleap.ai/images/chains/fastset.svg",
2995
+ nativeToken: NativeTokenSet
2996
+ },
2997
+ devnet: {
2998
+ name: import_warps6.WarpChainName.Fastset,
2999
+ displayName: "FastSet Devnet",
3000
+ chainId: "devnet",
3001
+ blockTime: 1e3,
3002
+ addressHrp: "set",
3003
+ defaultApiUrl: "https://proxy.fastset.xyz",
3004
+ logoUrl: "https://vleap.ai/images/chains/fastset.svg",
3005
+ nativeToken: NativeTokenSet
3006
+ }
3007
+ });
3008
+ // Annotate the CommonJS export names for ESM import in node:
3009
+ 0 && (module.exports = {
3010
+ NativeTokenSet,
3011
+ WarpFastsetExecutor,
3012
+ WarpFastsetWallet,
3013
+ getFastsetAdapter
3014
+ });
3015
+ /*! Bundled license information:
3016
+
3017
+ @scure/base/lib/esm/index.js:
3018
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
3019
+
3020
+ @noble/ed25519/index.js:
3021
+ (*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
3022
+
3023
+ @noble/hashes/utils.js:
3024
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
3025
+ */
3026
+ //# sourceMappingURL=index.js.map