@vleap/warps-adapter-fastset 0.1.0-alpha.3 → 0.1.0-alpha.31

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