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