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