@vleap/warps-adapter-fastset 0.1.0-alpha.24 → 0.1.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,12 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
8
  var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
14
11
  };
15
12
  var __copyProps = (to, from, except, desc) => {
16
13
  if (from && typeof from === "object" || typeof from === "function") {
@@ -30,175 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
33
- // src/sdk/ed25519-setup.ts
34
- var ed, import_sha512;
35
- var init_ed25519_setup = __esm({
36
- "src/sdk/ed25519-setup.ts"() {
37
- "use strict";
38
- ed = __toESM(require("@noble/ed25519"), 1);
39
- import_sha512 = require("@noble/hashes/sha512");
40
- if (ed.etc) {
41
- ed.etc.sha512Sync = (...m) => (0, import_sha512.sha512)(ed.etc.concatBytes(...m));
42
- }
43
- }
44
- });
45
-
46
- // src/sdk/FastsetClient.ts
47
- var bech32, Transaction, FastsetClient, Wallet;
48
- var init_FastsetClient = __esm({
49
- "src/sdk/FastsetClient.ts"() {
50
- "use strict";
51
- bech32 = __toESM(require("bech32"), 1);
52
- init_ed25519_setup();
53
- BigInt.prototype.toJSON = function() {
54
- return Number(this);
55
- };
56
- Transaction = class {
57
- constructor(sender, recipient, nonce, claim, timestamp = BigInt(Date.now()) * 1000000n) {
58
- this.sender = sender;
59
- this.recipient = recipient;
60
- this.nonce = nonce;
61
- this.claim = claim;
62
- this.timestamp = timestamp;
63
- if (claim?.Transfer?.amount?.startsWith("0x")) {
64
- claim = { ...claim, Transfer: { ...claim.Transfer, amount: claim.Transfer.amount.slice(2) } };
65
- }
66
- }
67
- toTransaction() {
68
- return { sender: this.sender, recipient: this.recipient, nonce: this.nonce, timestamp_nanos: this.timestamp, claim: this.claim };
69
- }
70
- getRecipientAddress() {
71
- return this.recipient;
72
- }
73
- getAmount() {
74
- return this.claim?.Transfer?.amount || "";
75
- }
76
- getUserData() {
77
- return this.claim?.Transfer?.user_data || null;
78
- }
79
- };
80
- FastsetClient = class {
81
- constructor(config, chain) {
82
- this.proxyUrl = config && "proxyUrl" in config ? config.proxyUrl : config && chain ? chain.defaultApiUrl : "https://proxy.fastset.xyz";
83
- }
84
- async makeRequest(method, params = {}) {
85
- const response = await fetch(this.proxyUrl, {
86
- method: "POST",
87
- headers: { "Content-Type": "application/json" },
88
- body: JSON.stringify({ jsonrpc: "2.0", method, params, id: Date.now() }, (k, v) => v instanceof Uint8Array ? Array.from(v) : v)
89
- });
90
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
91
- const jsonResponse = await response.json();
92
- if (jsonResponse.error) throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
93
- return jsonResponse.result;
94
- }
95
- async getAccountInfo(address) {
96
- return this.makeRequest("set_proxy_getAccountInfo", { address });
97
- }
98
- async getNextNonce(address) {
99
- const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
100
- const accountInfo = await this.getAccountInfo(addressBytes);
101
- return accountInfo.next_nonce;
102
- }
103
- async submitTransaction(transaction, signature) {
104
- const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
105
- const submitTxReq = {
106
- transaction: {
107
- sender: transaction.sender instanceof Uint8Array ? transaction.sender : new Uint8Array(transaction.sender),
108
- recipient: transaction.recipient,
109
- nonce: transaction.nonce,
110
- timestamp_nanos: transaction.timestamp_nanos,
111
- claim: transaction.claim
112
- },
113
- signature: new Uint8Array(signatureArray)
114
- };
115
- const response = await fetch(this.proxyUrl, {
116
- method: "POST",
117
- headers: { "Content-Type": "application/json" },
118
- body: JSON.stringify(
119
- { jsonrpc: "2.0", method: "set_proxy_submitTransaction", params: submitTxReq, id: 1 },
120
- (k, v) => v instanceof Uint8Array ? Array.from(v) : v
121
- )
122
- });
123
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
124
- const jsonResponse = await response.json();
125
- if (jsonResponse.error) throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
126
- return jsonResponse.result;
127
- }
128
- async faucetDrip(recipient, amount) {
129
- const recipientArray = Array.isArray(recipient) ? recipient : Array.from(recipient);
130
- return this.makeRequest("set_proxy_faucetDrip", { recipient: recipientArray, amount });
131
- }
132
- addressToBytes(address) {
133
- try {
134
- const decoded = bech32.bech32m.decode(address);
135
- return Array.from(bech32.bech32m.fromWords(decoded.words));
136
- } catch {
137
- const decoded = bech32.bech32.decode(address);
138
- return Array.from(bech32.bech32.fromWords(decoded.words));
139
- }
140
- }
141
- // Wallet utilities
142
- generateNewWallet() {
143
- const privateKey = ed.utils.randomPrivateKey();
144
- return new Wallet(Buffer.from(privateKey).toString("hex"));
145
- }
146
- createWallet(privateKeyHex) {
147
- return new Wallet(privateKeyHex);
148
- }
149
- static decodeBech32Address(address) {
150
- try {
151
- const decoded = bech32.bech32m.decode(address);
152
- return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
153
- } catch {
154
- const decoded = bech32.bech32.decode(address);
155
- return new Uint8Array(bech32.bech32.fromWords(decoded.words));
156
- }
157
- }
158
- static encodeBech32Address(publicKey) {
159
- const words = bech32.bech32m.toWords(publicKey);
160
- return bech32.bech32m.encode("set", words);
161
- }
162
- };
163
- Wallet = class {
164
- constructor(privateKeyHex) {
165
- this.privateKey = new Uint8Array(Buffer.from(privateKeyHex.replace(/^0x/, ""), "hex"));
166
- this.publicKey = ed.getPublicKey(this.privateKey);
167
- }
168
- toBech32() {
169
- return bech32.bech32m.encode("set", bech32.bech32m.toWords(this.publicKey));
170
- }
171
- signTransactionRaw(data) {
172
- return ed.sign(data, this.privateKey);
173
- }
174
- getPrivateKey() {
175
- return this.privateKey;
176
- }
177
- };
178
- }
179
- });
180
-
181
- // src/sdk/index.ts
182
- var sdk_exports = {};
183
- __export(sdk_exports, {
184
- FastsetClient: () => FastsetClient,
185
- Transaction: () => Transaction,
186
- Wallet: () => Wallet
187
- });
188
- var init_sdk = __esm({
189
- "src/sdk/index.ts"() {
190
- "use strict";
191
- init_FastsetClient();
192
- }
193
- });
194
-
195
30
  // src/index.ts
196
31
  var index_exports = {};
197
32
  __export(index_exports, {
198
- FastsetClient: () => FastsetClient,
199
33
  NativeTokenSet: () => NativeTokenSet,
200
- Transaction: () => Transaction,
201
- Wallet: () => Wallet,
202
34
  WarpFastsetExecutor: () => WarpFastsetExecutor,
203
35
  WarpFastsetWallet: () => WarpFastsetWallet,
204
36
  getFastsetAdapter: () => getFastsetAdapter
@@ -226,33 +58,96 @@ function stringToUint8Array(str) {
226
58
 
227
59
  // src/helpers/general.ts
228
60
  var import_warps = require("@vleap/warps");
229
- init_sdk();
230
- var getConfiguredFastsetClient = (config, chain) => {
231
- const proxyUrl = (0, import_warps.getProviderUrl)(config, chain.name, config.env, chain.defaultApiUrl);
232
- return new FastsetClient({ proxyUrl });
61
+
62
+ // src/sdk/FastsetClient.ts
63
+ var bech32 = __toESM(require("bech32"), 1);
64
+ BigInt.prototype.toJSON = function() {
65
+ return Number(this);
66
+ };
67
+ var id = 0;
68
+ var FastsetClient = class {
69
+ constructor(proxyUrl) {
70
+ this.proxyUrl = proxyUrl;
71
+ }
72
+ async request(url, method, params) {
73
+ const request = this.buildJsonRpcRequest(id++, method, params);
74
+ const headers = { "Content-Type": "application/json" };
75
+ const body = this.jsonSerialize(request);
76
+ const response = await fetch(url, { method: "POST", headers, body });
77
+ const json = await response.json();
78
+ return json;
79
+ }
80
+ buildJsonRpcRequest(id2, method, params) {
81
+ return { jsonrpc: "2.0", id: id2, method, params };
82
+ }
83
+ jsonSerialize(data) {
84
+ return JSON.stringify(data, (k, v) => {
85
+ if (v instanceof Uint8Array) {
86
+ return Array.from(v);
87
+ }
88
+ return v;
89
+ });
90
+ }
91
+ async getAccountInfo(address) {
92
+ return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
93
+ }
94
+ async getNextNonce(address) {
95
+ const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
96
+ const accountInfoRes = await this.getAccountInfo(addressBytes);
97
+ return accountInfoRes.result?.next_nonce ?? 0;
98
+ }
99
+ addressToBytes(address) {
100
+ try {
101
+ const decoded = bech32.bech32m.decode(address);
102
+ return Array.from(bech32.bech32m.fromWords(decoded.words));
103
+ } catch {
104
+ const decoded = bech32.bech32.decode(address);
105
+ return Array.from(bech32.bech32.fromWords(decoded.words));
106
+ }
107
+ }
108
+ static decodeBech32Address(address) {
109
+ try {
110
+ const decoded = bech32.bech32m.decode(address);
111
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
112
+ } catch {
113
+ const decoded = bech32.bech32.decode(address);
114
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
115
+ }
116
+ }
117
+ static encodeBech32Address(publicKey) {
118
+ const words = bech32.bech32m.toWords(publicKey);
119
+ return bech32.bech32m.encode("set", words);
120
+ }
121
+ };
122
+
123
+ // src/helpers/general.ts
124
+ var getConfiguredFastsetClient = (config, chain2) => {
125
+ const proxyUrl = (0, import_warps.getProviderUrl)(config, chain2.name, config.env, chain2.defaultApiUrl);
126
+ return new FastsetClient(proxyUrl);
233
127
  };
234
128
 
235
129
  // src/WarpFastsetDataLoader.ts
236
130
  var WarpFastsetDataLoader = class {
237
- constructor(config, chain) {
131
+ constructor(config, chain2) {
238
132
  this.config = config;
239
- this.chain = chain;
240
- this.client = getConfiguredFastsetClient(config, chain);
133
+ this.chain = chain2;
134
+ this.client = getConfiguredFastsetClient(config, chain2);
241
135
  }
242
136
  async getAccount(address) {
243
137
  const addressBytes = this.addressToBytes(address);
244
138
  const accountInfo = await this.client.getAccountInfo(addressBytes);
245
- return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.balance, 16)) };
139
+ return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
246
140
  }
247
141
  async getAccountAssets(address) {
248
142
  const addressBytes = this.addressToBytes(address);
249
143
  const accountInfo = await this.client.getAccountInfo(addressBytes);
250
144
  const assets = [];
251
- const balance = BigInt(parseInt(accountInfo.balance, 16));
145
+ console.log("accountInfo", accountInfo);
146
+ const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
252
147
  if (balance > 0n) {
253
148
  assets.push({ ...this.chain.nativeToken, amount: balance });
254
149
  }
255
- for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
150
+ for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
256
151
  const amount = BigInt(parseInt(tokenBalance, 16));
257
152
  if (amount > 0n) {
258
153
  const tokenInfo = await this.client.getTokenInfo([tokenId]);
@@ -311,12 +206,11 @@ var WarpFastsetDataLoader = class {
311
206
 
312
207
  // src/WarpFastsetExecutor.ts
313
208
  var import_warps2 = require("@vleap/warps");
314
- init_sdk();
315
209
  var WarpFastsetExecutor = class {
316
- constructor(config, chain) {
210
+ constructor(config, chain2) {
317
211
  this.config = config;
318
- this.chain = chain;
319
- this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
212
+ this.chain = chain2;
213
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
320
214
  }
321
215
  async createTransaction(executable) {
322
216
  const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
@@ -325,99 +219,30 @@ var WarpFastsetExecutor = class {
325
219
  if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
326
220
  if (action.type === "collect")
327
221
  throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
328
- throw new Error(`WarpFastsetExecutor: Invalid action type (unknown)`);
222
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
329
223
  }
330
224
  async createTransferTransaction(executable) {
331
225
  const userWallet = (0, import_warps2.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
332
226
  if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
333
- const senderAddress = FastsetClient.decodeBech32Address(userWallet);
334
- let recipientAddress;
335
- try {
336
- recipientAddress = FastsetClient.decodeBech32Address(executable.destination);
337
- } catch (error) {
338
- throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
339
- }
340
- const nonce = await this.fastsetClient.getNextNonce(userWallet);
341
- const transferValue = executable.transfers?.[0]?.amount || executable.value;
342
- if (transferValue < 0) throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${transferValue}`);
343
- const amount = "0x" + transferValue.toString(16);
344
- const userData = executable.data ? this.fromBase64(executable.data) : null;
345
- const claim = { Transfer: { amount, user_data: userData } };
346
- return new Transaction(senderAddress, { FastSet: recipientAddress }, nonce, claim);
347
- }
348
- async createContractCallTransaction(executable) {
349
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
350
- if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
351
- const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
352
- if (!action || !("func" in action) || !action.func) throw new Error("WarpFastsetExecutor: Contract action must have a function name");
353
- let contractAddress;
354
- try {
355
- contractAddress = this.fromBase64(executable.destination);
356
- } catch (error) {
357
- throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
358
- }
227
+ const senderPubKey = FastsetClient.decodeBech32Address(userWallet);
228
+ const recipientPubKey = FastsetClient.decodeBech32Address(executable.destination);
229
+ const nonce = await this.client.getNextNonce(userWallet);
230
+ const nativeAmountInTransfers = executable.transfers.find((transfer) => transfer.identifier === this.chain.nativeToken?.identifier)?.amount || 0n;
231
+ const nativeAmountTotal = nativeAmountInTransfers + executable.value;
232
+ const amountHex = BigInt(nativeAmountTotal).toString(16);
359
233
  return {
360
- type: "fastset-contract-call",
361
- contract: contractAddress,
362
- function: action.func,
363
- data: JSON.stringify({ function: action.func, arguments: executable.args }),
364
- value: executable.value,
365
- chain: executable.chain
366
- };
367
- }
368
- async executeQuery(executable) {
369
- const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
370
- if (action.type !== "query") throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
371
- if (!action.func) throw new Error("WarpFastsetExecutor: Query action must have a function name");
372
- try {
373
- const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
374
- return { success: true, result, chain: executable.chain };
375
- } catch (error) {
376
- return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
377
- }
378
- }
379
- async executeTransfer(executable) {
380
- const transaction = await this.createTransferTransaction(executable);
381
- return { success: true, transaction, chain: executable.chain.name };
382
- }
383
- async executeTransferWithKey(executable, privateKey) {
384
- const transaction = await this.createTransferTransaction(executable);
385
- const privateKeyBytes = this.fromBase64(privateKey);
386
- const transactionData = {
387
- sender: privateKeyBytes.slice(0, 32),
388
- recipient: transaction.getRecipientAddress(),
389
- nonce: await this.fastsetClient.getNextNonce(FastsetClient.encodeBech32Address(privateKeyBytes.slice(0, 32))),
234
+ sender: senderPubKey,
235
+ recipient: { FastSet: recipientPubKey },
236
+ nonce,
390
237
  timestamp_nanos: BigInt(Date.now()) * 1000000n,
391
- claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
238
+ claim: { Transfer: { amount: amountHex, user_data: null } }
392
239
  };
393
- const signature = await this.signTransaction(transactionData, privateKeyBytes);
394
- const result = await this.fastsetClient.submitTransaction(transactionData, signature);
395
- return { success: true, result, message: "Transaction submitted successfully", chain: executable.chain.name };
396
- }
397
- async signTransaction(transaction, privateKey) {
398
- const wallet = new (await Promise.resolve().then(() => (init_sdk(), sdk_exports))).Wallet(Buffer.from(privateKey).toString("hex"));
399
- return wallet.signTransactionRaw(this.serializeTransaction(transaction));
400
- }
401
- serializeTransaction(tx) {
402
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
403
- return new TextEncoder().encode(serialized);
404
- }
405
- async executeFastsetQuery(contractAddress, functionName, args) {
406
- const response = await fetch("https://proxy.fastset.xyz", {
407
- method: "POST",
408
- headers: { "Content-Type": "application/json" },
409
- body: JSON.stringify({
410
- jsonrpc: "2.0",
411
- method: "set_proxy_query",
412
- params: { contract: Array.from(contractAddress), function: functionName, arguments: args },
413
- id: 1
414
- })
415
- });
416
- if (!response.ok) throw new Error(`Fastset query failed: ${response.statusText}`);
417
- return response.json();
418
240
  }
419
- fromBase64(base64) {
420
- return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
241
+ async createContractCallTransaction(executable) {
242
+ throw new Error("WarpFastsetExecutor: Not implemented");
243
+ }
244
+ async executeQuery(executable) {
245
+ throw new Error("WarpFastsetExecutor: Not implemented");
421
246
  }
422
247
  };
423
248
 
@@ -557,9 +382,9 @@ var WarpFastsetSerializer = class {
557
382
 
558
383
  // src/WarpFastsetResults.ts
559
384
  var WarpFastsetResults = class {
560
- constructor(config, chain) {
385
+ constructor(config, chain2) {
561
386
  this.config = config;
562
- this.chain = chain;
387
+ this.chain = chain2;
563
388
  this.serializer = new WarpFastsetSerializer();
564
389
  }
565
390
  async getTransactionExecutionResults(warp, tx) {
@@ -643,68 +468,1820 @@ var WarpFastsetResults = class {
643
468
  // src/WarpFastsetWallet.ts
644
469
  var bip39 = __toESM(require("@scure/bip39"), 1);
645
470
  var import_warps5 = require("@vleap/warps");
646
- init_sdk();
647
- init_ed25519_setup();
471
+
472
+ // src/sdk/ed25519-setup.ts
473
+ var ed = __toESM(require("@noble/ed25519"), 1);
474
+
475
+ // ../../node_modules/@noble/hashes/esm/utils.js
476
+ function isBytes(a) {
477
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
478
+ }
479
+ function abytes(b, ...lengths) {
480
+ if (!isBytes(b))
481
+ throw new Error("Uint8Array expected");
482
+ if (lengths.length > 0 && !lengths.includes(b.length))
483
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
484
+ }
485
+ function aexists(instance, checkFinished = true) {
486
+ if (instance.destroyed)
487
+ throw new Error("Hash instance has been destroyed");
488
+ if (checkFinished && instance.finished)
489
+ throw new Error("Hash#digest() has already been called");
490
+ }
491
+ function aoutput(out, instance) {
492
+ abytes(out);
493
+ const min = instance.outputLen;
494
+ if (out.length < min) {
495
+ throw new Error("digestInto() expects output buffer of length at least " + min);
496
+ }
497
+ }
498
+ function clean(...arrays) {
499
+ for (let i = 0; i < arrays.length; i++) {
500
+ arrays[i].fill(0);
501
+ }
502
+ }
503
+ function createView(arr) {
504
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
505
+ }
506
+ function utf8ToBytes(str) {
507
+ if (typeof str !== "string")
508
+ throw new Error("string expected");
509
+ return new Uint8Array(new TextEncoder().encode(str));
510
+ }
511
+ function toBytes(data) {
512
+ if (typeof data === "string")
513
+ data = utf8ToBytes(data);
514
+ abytes(data);
515
+ return data;
516
+ }
517
+ var Hash = class {
518
+ };
519
+ function createHasher(hashCons) {
520
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
521
+ const tmp = hashCons();
522
+ hashC.outputLen = tmp.outputLen;
523
+ hashC.blockLen = tmp.blockLen;
524
+ hashC.create = () => hashCons();
525
+ return hashC;
526
+ }
527
+
528
+ // ../../node_modules/@noble/hashes/esm/_md.js
529
+ function setBigUint64(view, byteOffset, value, isLE) {
530
+ if (typeof view.setBigUint64 === "function")
531
+ return view.setBigUint64(byteOffset, value, isLE);
532
+ const _32n2 = BigInt(32);
533
+ const _u32_max = BigInt(4294967295);
534
+ const wh = Number(value >> _32n2 & _u32_max);
535
+ const wl = Number(value & _u32_max);
536
+ const h = isLE ? 4 : 0;
537
+ const l = isLE ? 0 : 4;
538
+ view.setUint32(byteOffset + h, wh, isLE);
539
+ view.setUint32(byteOffset + l, wl, isLE);
540
+ }
541
+ var HashMD = class extends Hash {
542
+ constructor(blockLen, outputLen, padOffset, isLE) {
543
+ super();
544
+ this.finished = false;
545
+ this.length = 0;
546
+ this.pos = 0;
547
+ this.destroyed = false;
548
+ this.blockLen = blockLen;
549
+ this.outputLen = outputLen;
550
+ this.padOffset = padOffset;
551
+ this.isLE = isLE;
552
+ this.buffer = new Uint8Array(blockLen);
553
+ this.view = createView(this.buffer);
554
+ }
555
+ update(data) {
556
+ aexists(this);
557
+ data = toBytes(data);
558
+ abytes(data);
559
+ const { view, buffer, blockLen } = this;
560
+ const len = data.length;
561
+ for (let pos = 0; pos < len; ) {
562
+ const take = Math.min(blockLen - this.pos, len - pos);
563
+ if (take === blockLen) {
564
+ const dataView = createView(data);
565
+ for (; blockLen <= len - pos; pos += blockLen)
566
+ this.process(dataView, pos);
567
+ continue;
568
+ }
569
+ buffer.set(data.subarray(pos, pos + take), this.pos);
570
+ this.pos += take;
571
+ pos += take;
572
+ if (this.pos === blockLen) {
573
+ this.process(view, 0);
574
+ this.pos = 0;
575
+ }
576
+ }
577
+ this.length += data.length;
578
+ this.roundClean();
579
+ return this;
580
+ }
581
+ digestInto(out) {
582
+ aexists(this);
583
+ aoutput(out, this);
584
+ this.finished = true;
585
+ const { buffer, view, blockLen, isLE } = this;
586
+ let { pos } = this;
587
+ buffer[pos++] = 128;
588
+ clean(this.buffer.subarray(pos));
589
+ if (this.padOffset > blockLen - pos) {
590
+ this.process(view, 0);
591
+ pos = 0;
592
+ }
593
+ for (let i = pos; i < blockLen; i++)
594
+ buffer[i] = 0;
595
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
596
+ this.process(view, 0);
597
+ const oview = createView(out);
598
+ const len = this.outputLen;
599
+ if (len % 4)
600
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
601
+ const outLen = len / 4;
602
+ const state = this.get();
603
+ if (outLen > state.length)
604
+ throw new Error("_sha2: outputLen bigger than state");
605
+ for (let i = 0; i < outLen; i++)
606
+ oview.setUint32(4 * i, state[i], isLE);
607
+ }
608
+ digest() {
609
+ const { buffer, outputLen } = this;
610
+ this.digestInto(buffer);
611
+ const res = buffer.slice(0, outputLen);
612
+ this.destroy();
613
+ return res;
614
+ }
615
+ _cloneInto(to) {
616
+ to || (to = new this.constructor());
617
+ to.set(...this.get());
618
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
619
+ to.destroyed = destroyed;
620
+ to.finished = finished;
621
+ to.length = length;
622
+ to.pos = pos;
623
+ if (length % blockLen)
624
+ to.buffer.set(buffer);
625
+ return to;
626
+ }
627
+ clone() {
628
+ return this._cloneInto();
629
+ }
630
+ };
631
+ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
632
+ 1779033703,
633
+ 4089235720,
634
+ 3144134277,
635
+ 2227873595,
636
+ 1013904242,
637
+ 4271175723,
638
+ 2773480762,
639
+ 1595750129,
640
+ 1359893119,
641
+ 2917565137,
642
+ 2600822924,
643
+ 725511199,
644
+ 528734635,
645
+ 4215389547,
646
+ 1541459225,
647
+ 327033209
648
+ ]);
649
+
650
+ // ../../node_modules/@noble/hashes/esm/_u64.js
651
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
652
+ var _32n = /* @__PURE__ */ BigInt(32);
653
+ function fromBig(n, le = false) {
654
+ if (le)
655
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
656
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
657
+ }
658
+ function split(lst, le = false) {
659
+ const len = lst.length;
660
+ let Ah = new Uint32Array(len);
661
+ let Al = new Uint32Array(len);
662
+ for (let i = 0; i < len; i++) {
663
+ const { h, l } = fromBig(lst[i], le);
664
+ [Ah[i], Al[i]] = [h, l];
665
+ }
666
+ return [Ah, Al];
667
+ }
668
+ var shrSH = (h, _l, s) => h >>> s;
669
+ var shrSL = (h, l, s) => h << 32 - s | l >>> s;
670
+ var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
671
+ var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
672
+ var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
673
+ var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
674
+ function add(Ah, Al, Bh, Bl) {
675
+ const l = (Al >>> 0) + (Bl >>> 0);
676
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
677
+ }
678
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
679
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
680
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
681
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
682
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
683
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
684
+
685
+ // ../../node_modules/@noble/hashes/esm/sha2.js
686
+ var K512 = /* @__PURE__ */ (() => split([
687
+ "0x428a2f98d728ae22",
688
+ "0x7137449123ef65cd",
689
+ "0xb5c0fbcfec4d3b2f",
690
+ "0xe9b5dba58189dbbc",
691
+ "0x3956c25bf348b538",
692
+ "0x59f111f1b605d019",
693
+ "0x923f82a4af194f9b",
694
+ "0xab1c5ed5da6d8118",
695
+ "0xd807aa98a3030242",
696
+ "0x12835b0145706fbe",
697
+ "0x243185be4ee4b28c",
698
+ "0x550c7dc3d5ffb4e2",
699
+ "0x72be5d74f27b896f",
700
+ "0x80deb1fe3b1696b1",
701
+ "0x9bdc06a725c71235",
702
+ "0xc19bf174cf692694",
703
+ "0xe49b69c19ef14ad2",
704
+ "0xefbe4786384f25e3",
705
+ "0x0fc19dc68b8cd5b5",
706
+ "0x240ca1cc77ac9c65",
707
+ "0x2de92c6f592b0275",
708
+ "0x4a7484aa6ea6e483",
709
+ "0x5cb0a9dcbd41fbd4",
710
+ "0x76f988da831153b5",
711
+ "0x983e5152ee66dfab",
712
+ "0xa831c66d2db43210",
713
+ "0xb00327c898fb213f",
714
+ "0xbf597fc7beef0ee4",
715
+ "0xc6e00bf33da88fc2",
716
+ "0xd5a79147930aa725",
717
+ "0x06ca6351e003826f",
718
+ "0x142929670a0e6e70",
719
+ "0x27b70a8546d22ffc",
720
+ "0x2e1b21385c26c926",
721
+ "0x4d2c6dfc5ac42aed",
722
+ "0x53380d139d95b3df",
723
+ "0x650a73548baf63de",
724
+ "0x766a0abb3c77b2a8",
725
+ "0x81c2c92e47edaee6",
726
+ "0x92722c851482353b",
727
+ "0xa2bfe8a14cf10364",
728
+ "0xa81a664bbc423001",
729
+ "0xc24b8b70d0f89791",
730
+ "0xc76c51a30654be30",
731
+ "0xd192e819d6ef5218",
732
+ "0xd69906245565a910",
733
+ "0xf40e35855771202a",
734
+ "0x106aa07032bbd1b8",
735
+ "0x19a4c116b8d2d0c8",
736
+ "0x1e376c085141ab53",
737
+ "0x2748774cdf8eeb99",
738
+ "0x34b0bcb5e19b48a8",
739
+ "0x391c0cb3c5c95a63",
740
+ "0x4ed8aa4ae3418acb",
741
+ "0x5b9cca4f7763e373",
742
+ "0x682e6ff3d6b2b8a3",
743
+ "0x748f82ee5defb2fc",
744
+ "0x78a5636f43172f60",
745
+ "0x84c87814a1f0ab72",
746
+ "0x8cc702081a6439ec",
747
+ "0x90befffa23631e28",
748
+ "0xa4506cebde82bde9",
749
+ "0xbef9a3f7b2c67915",
750
+ "0xc67178f2e372532b",
751
+ "0xca273eceea26619c",
752
+ "0xd186b8c721c0c207",
753
+ "0xeada7dd6cde0eb1e",
754
+ "0xf57d4f7fee6ed178",
755
+ "0x06f067aa72176fba",
756
+ "0x0a637dc5a2c898a6",
757
+ "0x113f9804bef90dae",
758
+ "0x1b710b35131c471b",
759
+ "0x28db77f523047d84",
760
+ "0x32caab7b40c72493",
761
+ "0x3c9ebe0a15c9bebc",
762
+ "0x431d67c49c100d4c",
763
+ "0x4cc5d4becb3e42b6",
764
+ "0x597f299cfc657e2a",
765
+ "0x5fcb6fab3ad6faec",
766
+ "0x6c44198c4a475817"
767
+ ].map((n) => BigInt(n))))();
768
+ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
769
+ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
770
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
771
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
772
+ var SHA512 = class extends HashMD {
773
+ constructor(outputLen = 64) {
774
+ super(128, outputLen, 16, false);
775
+ this.Ah = SHA512_IV[0] | 0;
776
+ this.Al = SHA512_IV[1] | 0;
777
+ this.Bh = SHA512_IV[2] | 0;
778
+ this.Bl = SHA512_IV[3] | 0;
779
+ this.Ch = SHA512_IV[4] | 0;
780
+ this.Cl = SHA512_IV[5] | 0;
781
+ this.Dh = SHA512_IV[6] | 0;
782
+ this.Dl = SHA512_IV[7] | 0;
783
+ this.Eh = SHA512_IV[8] | 0;
784
+ this.El = SHA512_IV[9] | 0;
785
+ this.Fh = SHA512_IV[10] | 0;
786
+ this.Fl = SHA512_IV[11] | 0;
787
+ this.Gh = SHA512_IV[12] | 0;
788
+ this.Gl = SHA512_IV[13] | 0;
789
+ this.Hh = SHA512_IV[14] | 0;
790
+ this.Hl = SHA512_IV[15] | 0;
791
+ }
792
+ // prettier-ignore
793
+ get() {
794
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
795
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
796
+ }
797
+ // prettier-ignore
798
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
799
+ this.Ah = Ah | 0;
800
+ this.Al = Al | 0;
801
+ this.Bh = Bh | 0;
802
+ this.Bl = Bl | 0;
803
+ this.Ch = Ch | 0;
804
+ this.Cl = Cl | 0;
805
+ this.Dh = Dh | 0;
806
+ this.Dl = Dl | 0;
807
+ this.Eh = Eh | 0;
808
+ this.El = El | 0;
809
+ this.Fh = Fh | 0;
810
+ this.Fl = Fl | 0;
811
+ this.Gh = Gh | 0;
812
+ this.Gl = Gl | 0;
813
+ this.Hh = Hh | 0;
814
+ this.Hl = Hl | 0;
815
+ }
816
+ process(view, offset) {
817
+ for (let i = 0; i < 16; i++, offset += 4) {
818
+ SHA512_W_H[i] = view.getUint32(offset);
819
+ SHA512_W_L[i] = view.getUint32(offset += 4);
820
+ }
821
+ for (let i = 16; i < 80; i++) {
822
+ const W15h = SHA512_W_H[i - 15] | 0;
823
+ const W15l = SHA512_W_L[i - 15] | 0;
824
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
825
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
826
+ const W2h = SHA512_W_H[i - 2] | 0;
827
+ const W2l = SHA512_W_L[i - 2] | 0;
828
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
829
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
830
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
831
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
832
+ SHA512_W_H[i] = SUMh | 0;
833
+ SHA512_W_L[i] = SUMl | 0;
834
+ }
835
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
836
+ for (let i = 0; i < 80; i++) {
837
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
838
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
839
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
840
+ const CHIl = El & Fl ^ ~El & Gl;
841
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
842
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
843
+ const T1l = T1ll | 0;
844
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
845
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
846
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
847
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
848
+ Hh = Gh | 0;
849
+ Hl = Gl | 0;
850
+ Gh = Fh | 0;
851
+ Gl = Fl | 0;
852
+ Fh = Eh | 0;
853
+ Fl = El | 0;
854
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
855
+ Dh = Ch | 0;
856
+ Dl = Cl | 0;
857
+ Ch = Bh | 0;
858
+ Cl = Bl | 0;
859
+ Bh = Ah | 0;
860
+ Bl = Al | 0;
861
+ const All = add3L(T1l, sigma0l, MAJl);
862
+ Ah = add3H(All, T1h, sigma0h, MAJh);
863
+ Al = All | 0;
864
+ }
865
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
866
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
867
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
868
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
869
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
870
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
871
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
872
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
873
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
874
+ }
875
+ roundClean() {
876
+ clean(SHA512_W_H, SHA512_W_L);
877
+ }
878
+ destroy() {
879
+ clean(this.buffer);
880
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
881
+ }
882
+ };
883
+ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
884
+
885
+ // ../../node_modules/@noble/hashes/esm/sha512.js
886
+ var sha5122 = sha512;
887
+
888
+ // src/sdk/ed25519-setup.ts
889
+ ed.hashes.sha512 = sha5122;
890
+
891
+ // ../../node_modules/@scure/base/lib/esm/index.js
892
+ function isBytes2(a) {
893
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
894
+ }
895
+ function isArrayOf(isString, arr) {
896
+ if (!Array.isArray(arr))
897
+ return false;
898
+ if (arr.length === 0)
899
+ return true;
900
+ if (isString) {
901
+ return arr.every((item) => typeof item === "string");
902
+ } else {
903
+ return arr.every((item) => Number.isSafeInteger(item));
904
+ }
905
+ }
906
+ function astr(label, input) {
907
+ if (typeof input !== "string")
908
+ throw new Error(`${label}: string expected`);
909
+ return true;
910
+ }
911
+ function anumber(n) {
912
+ if (!Number.isSafeInteger(n))
913
+ throw new Error(`invalid integer: ${n}`);
914
+ }
915
+ function aArr(input) {
916
+ if (!Array.isArray(input))
917
+ throw new Error("array expected");
918
+ }
919
+ function astrArr(label, input) {
920
+ if (!isArrayOf(true, input))
921
+ throw new Error(`${label}: array of strings expected`);
922
+ }
923
+ function anumArr(label, input) {
924
+ if (!isArrayOf(false, input))
925
+ throw new Error(`${label}: array of numbers expected`);
926
+ }
927
+ // @__NO_SIDE_EFFECTS__
928
+ function chain(...args) {
929
+ const id2 = (a) => a;
930
+ const wrap = (a, b) => (c) => a(b(c));
931
+ const encode = args.map((x) => x.encode).reduceRight(wrap, id2);
932
+ const decode = args.map((x) => x.decode).reduce(wrap, id2);
933
+ return { encode, decode };
934
+ }
935
+ // @__NO_SIDE_EFFECTS__
936
+ function alphabet(letters) {
937
+ const lettersA = typeof letters === "string" ? letters.split("") : letters;
938
+ const len = lettersA.length;
939
+ astrArr("alphabet", lettersA);
940
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
941
+ return {
942
+ encode: (digits) => {
943
+ aArr(digits);
944
+ return digits.map((i) => {
945
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len)
946
+ throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
947
+ return lettersA[i];
948
+ });
949
+ },
950
+ decode: (input) => {
951
+ aArr(input);
952
+ return input.map((letter) => {
953
+ astr("alphabet.decode", letter);
954
+ const i = indexes.get(letter);
955
+ if (i === void 0)
956
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
957
+ return i;
958
+ });
959
+ }
960
+ };
961
+ }
962
+ // @__NO_SIDE_EFFECTS__
963
+ function join(separator = "") {
964
+ astr("join", separator);
965
+ return {
966
+ encode: (from) => {
967
+ astrArr("join.decode", from);
968
+ return from.join(separator);
969
+ },
970
+ decode: (to) => {
971
+ astr("join.decode", to);
972
+ return to.split(separator);
973
+ }
974
+ };
975
+ }
976
+ function convertRadix(data, from, to) {
977
+ if (from < 2)
978
+ throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
979
+ if (to < 2)
980
+ throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
981
+ aArr(data);
982
+ if (!data.length)
983
+ return [];
984
+ let pos = 0;
985
+ const res = [];
986
+ const digits = Array.from(data, (d) => {
987
+ anumber(d);
988
+ if (d < 0 || d >= from)
989
+ throw new Error(`invalid integer: ${d}`);
990
+ return d;
991
+ });
992
+ const dlen = digits.length;
993
+ while (true) {
994
+ let carry = 0;
995
+ let done = true;
996
+ for (let i = pos; i < dlen; i++) {
997
+ const digit = digits[i];
998
+ const fromCarry = from * carry;
999
+ const digitBase = fromCarry + digit;
1000
+ if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
1001
+ throw new Error("convertRadix: carry overflow");
1002
+ }
1003
+ const div = digitBase / to;
1004
+ carry = digitBase % to;
1005
+ const rounded = Math.floor(div);
1006
+ digits[i] = rounded;
1007
+ if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
1008
+ throw new Error("convertRadix: carry overflow");
1009
+ if (!done)
1010
+ continue;
1011
+ else if (!rounded)
1012
+ pos = i;
1013
+ else
1014
+ done = false;
1015
+ }
1016
+ res.push(carry);
1017
+ if (done)
1018
+ break;
1019
+ }
1020
+ for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
1021
+ res.push(0);
1022
+ return res.reverse();
1023
+ }
1024
+ // @__NO_SIDE_EFFECTS__
1025
+ function radix(num) {
1026
+ anumber(num);
1027
+ const _256 = 2 ** 8;
1028
+ return {
1029
+ encode: (bytes) => {
1030
+ if (!isBytes2(bytes))
1031
+ throw new Error("radix.encode input should be Uint8Array");
1032
+ return convertRadix(Array.from(bytes), _256, num);
1033
+ },
1034
+ decode: (digits) => {
1035
+ anumArr("radix.decode", digits);
1036
+ return Uint8Array.from(convertRadix(digits, num, _256));
1037
+ }
1038
+ };
1039
+ }
1040
+ var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
1041
+ var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1042
+
1043
+ // ../../node_modules/@mysten/utils/dist/esm/b58.js
1044
+ var toBase58 = (buffer) => base58.encode(buffer);
1045
+ var fromBase58 = (str) => base58.decode(str);
1046
+
1047
+ // ../../node_modules/@mysten/utils/dist/esm/b64.js
1048
+ function fromBase64(base64String) {
1049
+ return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
1050
+ }
1051
+ var CHUNK_SIZE = 8192;
1052
+ function toBase64(bytes) {
1053
+ if (bytes.length < CHUNK_SIZE) {
1054
+ return btoa(String.fromCharCode(...bytes));
1055
+ }
1056
+ let output = "";
1057
+ for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
1058
+ const chunk = bytes.slice(i, i + CHUNK_SIZE);
1059
+ output += String.fromCharCode(...chunk);
1060
+ }
1061
+ return btoa(output);
1062
+ }
1063
+
1064
+ // ../../node_modules/@mysten/utils/dist/esm/hex.js
1065
+ function fromHex(hexStr) {
1066
+ const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
1067
+ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;
1068
+ const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];
1069
+ if (intArr.length !== padded.length / 2) {
1070
+ throw new Error(`Invalid hex string ${hexStr}`);
1071
+ }
1072
+ return Uint8Array.from(intArr);
1073
+ }
1074
+ function toHex(bytes) {
1075
+ return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
1076
+ }
1077
+
1078
+ // ../../node_modules/@mysten/bcs/dist/esm/uleb.js
1079
+ function ulebEncode(num) {
1080
+ const arr = [];
1081
+ let len = 0;
1082
+ if (num === 0) {
1083
+ return [0];
1084
+ }
1085
+ while (num > 0) {
1086
+ arr[len] = num & 127;
1087
+ if (num >>= 7) {
1088
+ arr[len] |= 128;
1089
+ }
1090
+ len += 1;
1091
+ }
1092
+ return arr;
1093
+ }
1094
+ function ulebDecode(arr) {
1095
+ let total = 0;
1096
+ let shift = 0;
1097
+ let len = 0;
1098
+ while (true) {
1099
+ const byte = arr[len];
1100
+ len += 1;
1101
+ total |= (byte & 127) << shift;
1102
+ if ((byte & 128) === 0) {
1103
+ break;
1104
+ }
1105
+ shift += 7;
1106
+ }
1107
+ return {
1108
+ value: total,
1109
+ length: len
1110
+ };
1111
+ }
1112
+
1113
+ // ../../node_modules/@mysten/bcs/dist/esm/reader.js
1114
+ var BcsReader = class {
1115
+ /**
1116
+ * @param {Uint8Array} data Data to use as a buffer.
1117
+ */
1118
+ constructor(data) {
1119
+ this.bytePosition = 0;
1120
+ this.dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
1121
+ }
1122
+ /**
1123
+ * Shift current cursor position by `bytes`.
1124
+ *
1125
+ * @param {Number} bytes Number of bytes to
1126
+ * @returns {this} Self for possible chaining.
1127
+ */
1128
+ shift(bytes) {
1129
+ this.bytePosition += bytes;
1130
+ return this;
1131
+ }
1132
+ /**
1133
+ * Read U8 value from the buffer and shift cursor by 1.
1134
+ * @returns
1135
+ */
1136
+ read8() {
1137
+ const value = this.dataView.getUint8(this.bytePosition);
1138
+ this.shift(1);
1139
+ return value;
1140
+ }
1141
+ /**
1142
+ * Read U16 value from the buffer and shift cursor by 2.
1143
+ * @returns
1144
+ */
1145
+ read16() {
1146
+ const value = this.dataView.getUint16(this.bytePosition, true);
1147
+ this.shift(2);
1148
+ return value;
1149
+ }
1150
+ /**
1151
+ * Read U32 value from the buffer and shift cursor by 4.
1152
+ * @returns
1153
+ */
1154
+ read32() {
1155
+ const value = this.dataView.getUint32(this.bytePosition, true);
1156
+ this.shift(4);
1157
+ return value;
1158
+ }
1159
+ /**
1160
+ * Read U64 value from the buffer and shift cursor by 8.
1161
+ * @returns
1162
+ */
1163
+ read64() {
1164
+ const value1 = this.read32();
1165
+ const value2 = this.read32();
1166
+ const result = value2.toString(16) + value1.toString(16).padStart(8, "0");
1167
+ return BigInt("0x" + result).toString(10);
1168
+ }
1169
+ /**
1170
+ * Read U128 value from the buffer and shift cursor by 16.
1171
+ */
1172
+ read128() {
1173
+ const value1 = BigInt(this.read64());
1174
+ const value2 = BigInt(this.read64());
1175
+ const result = value2.toString(16) + value1.toString(16).padStart(16, "0");
1176
+ return BigInt("0x" + result).toString(10);
1177
+ }
1178
+ /**
1179
+ * Read U128 value from the buffer and shift cursor by 32.
1180
+ * @returns
1181
+ */
1182
+ read256() {
1183
+ const value1 = BigInt(this.read128());
1184
+ const value2 = BigInt(this.read128());
1185
+ const result = value2.toString(16) + value1.toString(16).padStart(32, "0");
1186
+ return BigInt("0x" + result).toString(10);
1187
+ }
1188
+ /**
1189
+ * Read `num` number of bytes from the buffer and shift cursor by `num`.
1190
+ * @param num Number of bytes to read.
1191
+ */
1192
+ readBytes(num) {
1193
+ const start = this.bytePosition + this.dataView.byteOffset;
1194
+ const value = new Uint8Array(this.dataView.buffer, start, num);
1195
+ this.shift(num);
1196
+ return value;
1197
+ }
1198
+ /**
1199
+ * Read ULEB value - an integer of varying size. Used for enum indexes and
1200
+ * vector lengths.
1201
+ * @returns {Number} The ULEB value.
1202
+ */
1203
+ readULEB() {
1204
+ const start = this.bytePosition + this.dataView.byteOffset;
1205
+ const buffer = new Uint8Array(this.dataView.buffer, start);
1206
+ const { value, length } = ulebDecode(buffer);
1207
+ this.shift(length);
1208
+ return value;
1209
+ }
1210
+ /**
1211
+ * Read a BCS vector: read a length and then apply function `cb` X times
1212
+ * where X is the length of the vector, defined as ULEB in BCS bytes.
1213
+ * @param cb Callback to process elements of vector.
1214
+ * @returns {Array<Any>} Array of the resulting values, returned by callback.
1215
+ */
1216
+ readVec(cb) {
1217
+ const length = this.readULEB();
1218
+ const result = [];
1219
+ for (let i = 0; i < length; i++) {
1220
+ result.push(cb(this, i, length));
1221
+ }
1222
+ return result;
1223
+ }
1224
+ };
1225
+
1226
+ // ../../node_modules/@mysten/bcs/dist/esm/utils.js
1227
+ function encodeStr(data, encoding) {
1228
+ switch (encoding) {
1229
+ case "base58":
1230
+ return toBase58(data);
1231
+ case "base64":
1232
+ return toBase64(data);
1233
+ case "hex":
1234
+ return toHex(data);
1235
+ default:
1236
+ throw new Error("Unsupported encoding, supported values are: base64, hex");
1237
+ }
1238
+ }
1239
+
1240
+ // ../../node_modules/@mysten/bcs/dist/esm/writer.js
1241
+ var BcsWriter = class {
1242
+ constructor({
1243
+ initialSize = 1024,
1244
+ maxSize = Infinity,
1245
+ allocateSize = 1024
1246
+ } = {}) {
1247
+ this.bytePosition = 0;
1248
+ this.size = initialSize;
1249
+ this.maxSize = maxSize;
1250
+ this.allocateSize = allocateSize;
1251
+ this.dataView = new DataView(new ArrayBuffer(initialSize));
1252
+ }
1253
+ ensureSizeOrGrow(bytes) {
1254
+ const requiredSize = this.bytePosition + bytes;
1255
+ if (requiredSize > this.size) {
1256
+ const nextSize = Math.min(this.maxSize, this.size + this.allocateSize);
1257
+ if (requiredSize > nextSize) {
1258
+ throw new Error(
1259
+ `Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${requiredSize}`
1260
+ );
1261
+ }
1262
+ this.size = nextSize;
1263
+ const nextBuffer = new ArrayBuffer(this.size);
1264
+ new Uint8Array(nextBuffer).set(new Uint8Array(this.dataView.buffer));
1265
+ this.dataView = new DataView(nextBuffer);
1266
+ }
1267
+ }
1268
+ /**
1269
+ * Shift current cursor position by `bytes`.
1270
+ *
1271
+ * @param {Number} bytes Number of bytes to
1272
+ * @returns {this} Self for possible chaining.
1273
+ */
1274
+ shift(bytes) {
1275
+ this.bytePosition += bytes;
1276
+ return this;
1277
+ }
1278
+ /**
1279
+ * Write a U8 value into a buffer and shift cursor position by 1.
1280
+ * @param {Number} value Value to write.
1281
+ * @returns {this}
1282
+ */
1283
+ write8(value) {
1284
+ this.ensureSizeOrGrow(1);
1285
+ this.dataView.setUint8(this.bytePosition, Number(value));
1286
+ return this.shift(1);
1287
+ }
1288
+ /**
1289
+ * Write a U16 value into a buffer and shift cursor position by 2.
1290
+ * @param {Number} value Value to write.
1291
+ * @returns {this}
1292
+ */
1293
+ write16(value) {
1294
+ this.ensureSizeOrGrow(2);
1295
+ this.dataView.setUint16(this.bytePosition, Number(value), true);
1296
+ return this.shift(2);
1297
+ }
1298
+ /**
1299
+ * Write a U32 value into a buffer and shift cursor position by 4.
1300
+ * @param {Number} value Value to write.
1301
+ * @returns {this}
1302
+ */
1303
+ write32(value) {
1304
+ this.ensureSizeOrGrow(4);
1305
+ this.dataView.setUint32(this.bytePosition, Number(value), true);
1306
+ return this.shift(4);
1307
+ }
1308
+ /**
1309
+ * Write a U64 value into a buffer and shift cursor position by 8.
1310
+ * @param {bigint} value Value to write.
1311
+ * @returns {this}
1312
+ */
1313
+ write64(value) {
1314
+ toLittleEndian(BigInt(value), 8).forEach((el) => this.write8(el));
1315
+ return this;
1316
+ }
1317
+ /**
1318
+ * Write a U128 value into a buffer and shift cursor position by 16.
1319
+ *
1320
+ * @param {bigint} value Value to write.
1321
+ * @returns {this}
1322
+ */
1323
+ write128(value) {
1324
+ toLittleEndian(BigInt(value), 16).forEach((el) => this.write8(el));
1325
+ return this;
1326
+ }
1327
+ /**
1328
+ * Write a U256 value into a buffer and shift cursor position by 16.
1329
+ *
1330
+ * @param {bigint} value Value to write.
1331
+ * @returns {this}
1332
+ */
1333
+ write256(value) {
1334
+ toLittleEndian(BigInt(value), 32).forEach((el) => this.write8(el));
1335
+ return this;
1336
+ }
1337
+ /**
1338
+ * Write a ULEB value into a buffer and shift cursor position by number of bytes
1339
+ * written.
1340
+ * @param {Number} value Value to write.
1341
+ * @returns {this}
1342
+ */
1343
+ writeULEB(value) {
1344
+ ulebEncode(value).forEach((el) => this.write8(el));
1345
+ return this;
1346
+ }
1347
+ /**
1348
+ * Write a vector into a buffer by first writing the vector length and then calling
1349
+ * a callback on each passed value.
1350
+ *
1351
+ * @param {Array<Any>} vector Array of elements to write.
1352
+ * @param {WriteVecCb} cb Callback to call on each element of the vector.
1353
+ * @returns {this}
1354
+ */
1355
+ writeVec(vector2, cb) {
1356
+ this.writeULEB(vector2.length);
1357
+ Array.from(vector2).forEach((el, i) => cb(this, el, i, vector2.length));
1358
+ return this;
1359
+ }
1360
+ /**
1361
+ * Adds support for iterations over the object.
1362
+ * @returns {Uint8Array}
1363
+ */
1364
+ *[Symbol.iterator]() {
1365
+ for (let i = 0; i < this.bytePosition; i++) {
1366
+ yield this.dataView.getUint8(i);
1367
+ }
1368
+ return this.toBytes();
1369
+ }
1370
+ /**
1371
+ * Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
1372
+ * @returns {Uint8Array} Resulting bcs.
1373
+ */
1374
+ toBytes() {
1375
+ return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
1376
+ }
1377
+ /**
1378
+ * Represent data as 'hex' or 'base64'
1379
+ * @param encoding Encoding to use: 'base64' or 'hex'
1380
+ */
1381
+ toString(encoding) {
1382
+ return encodeStr(this.toBytes(), encoding);
1383
+ }
1384
+ };
1385
+ function toLittleEndian(bigint, size) {
1386
+ const result = new Uint8Array(size);
1387
+ let i = 0;
1388
+ while (bigint > 0) {
1389
+ result[i] = Number(bigint % BigInt(256));
1390
+ bigint = bigint / BigInt(256);
1391
+ i += 1;
1392
+ }
1393
+ return result;
1394
+ }
1395
+
1396
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs-type.js
1397
+ var __typeError = (msg) => {
1398
+ throw TypeError(msg);
1399
+ };
1400
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1401
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1402
+ 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);
1403
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1404
+ var _write;
1405
+ var _serialize;
1406
+ var _schema;
1407
+ var _bytes;
1408
+ var _BcsType = class _BcsType2 {
1409
+ constructor(options) {
1410
+ __privateAdd(this, _write);
1411
+ __privateAdd(this, _serialize);
1412
+ this.name = options.name;
1413
+ this.read = options.read;
1414
+ this.serializedSize = options.serializedSize ?? (() => null);
1415
+ __privateSet(this, _write, options.write);
1416
+ __privateSet(this, _serialize, options.serialize ?? ((value, options2) => {
1417
+ const writer = new BcsWriter({
1418
+ initialSize: this.serializedSize(value) ?? void 0,
1419
+ ...options2
1420
+ });
1421
+ __privateGet(this, _write).call(this, value, writer);
1422
+ return writer.toBytes();
1423
+ }));
1424
+ this.validate = options.validate ?? (() => {
1425
+ });
1426
+ }
1427
+ write(value, writer) {
1428
+ this.validate(value);
1429
+ __privateGet(this, _write).call(this, value, writer);
1430
+ }
1431
+ serialize(value, options) {
1432
+ this.validate(value);
1433
+ return new SerializedBcs(this, __privateGet(this, _serialize).call(this, value, options));
1434
+ }
1435
+ parse(bytes) {
1436
+ const reader = new BcsReader(bytes);
1437
+ return this.read(reader);
1438
+ }
1439
+ fromHex(hex) {
1440
+ return this.parse(fromHex(hex));
1441
+ }
1442
+ fromBase58(b64) {
1443
+ return this.parse(fromBase58(b64));
1444
+ }
1445
+ fromBase64(b64) {
1446
+ return this.parse(fromBase64(b64));
1447
+ }
1448
+ transform({
1449
+ name: name2,
1450
+ input,
1451
+ output,
1452
+ validate
1453
+ }) {
1454
+ return new _BcsType2({
1455
+ name: name2 ?? this.name,
1456
+ read: (reader) => output ? output(this.read(reader)) : this.read(reader),
1457
+ write: (value, writer) => __privateGet(this, _write).call(this, input ? input(value) : value, writer),
1458
+ serializedSize: (value) => this.serializedSize(input ? input(value) : value),
1459
+ serialize: (value, options) => __privateGet(this, _serialize).call(this, input ? input(value) : value, options),
1460
+ validate: (value) => {
1461
+ validate?.(value);
1462
+ this.validate(input ? input(value) : value);
1463
+ }
1464
+ });
1465
+ }
1466
+ };
1467
+ _write = /* @__PURE__ */ new WeakMap();
1468
+ _serialize = /* @__PURE__ */ new WeakMap();
1469
+ var BcsType = _BcsType;
1470
+ var SERIALIZED_BCS_BRAND = Symbol.for("@mysten/serialized-bcs");
1471
+ var SerializedBcs = class {
1472
+ constructor(schema, bytes) {
1473
+ __privateAdd(this, _schema);
1474
+ __privateAdd(this, _bytes);
1475
+ __privateSet(this, _schema, schema);
1476
+ __privateSet(this, _bytes, bytes);
1477
+ }
1478
+ // Used to brand SerializedBcs so that they can be identified, even between multiple copies
1479
+ // of the @mysten/bcs package are installed
1480
+ get [SERIALIZED_BCS_BRAND]() {
1481
+ return true;
1482
+ }
1483
+ toBytes() {
1484
+ return __privateGet(this, _bytes);
1485
+ }
1486
+ toHex() {
1487
+ return toHex(__privateGet(this, _bytes));
1488
+ }
1489
+ toBase64() {
1490
+ return toBase64(__privateGet(this, _bytes));
1491
+ }
1492
+ toBase58() {
1493
+ return toBase58(__privateGet(this, _bytes));
1494
+ }
1495
+ parse() {
1496
+ return __privateGet(this, _schema).parse(__privateGet(this, _bytes));
1497
+ }
1498
+ };
1499
+ _schema = /* @__PURE__ */ new WeakMap();
1500
+ _bytes = /* @__PURE__ */ new WeakMap();
1501
+ function fixedSizeBcsType({
1502
+ size,
1503
+ ...options
1504
+ }) {
1505
+ return new BcsType({
1506
+ ...options,
1507
+ serializedSize: () => size
1508
+ });
1509
+ }
1510
+ function uIntBcsType({
1511
+ readMethod,
1512
+ writeMethod,
1513
+ ...options
1514
+ }) {
1515
+ return fixedSizeBcsType({
1516
+ ...options,
1517
+ read: (reader) => reader[readMethod](),
1518
+ write: (value, writer) => writer[writeMethod](value),
1519
+ validate: (value) => {
1520
+ if (value < 0 || value > options.maxValue) {
1521
+ throw new TypeError(
1522
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
1523
+ );
1524
+ }
1525
+ options.validate?.(value);
1526
+ }
1527
+ });
1528
+ }
1529
+ function bigUIntBcsType({
1530
+ readMethod,
1531
+ writeMethod,
1532
+ ...options
1533
+ }) {
1534
+ return fixedSizeBcsType({
1535
+ ...options,
1536
+ read: (reader) => reader[readMethod](),
1537
+ write: (value, writer) => writer[writeMethod](BigInt(value)),
1538
+ validate: (val) => {
1539
+ const value = BigInt(val);
1540
+ if (value < 0 || value > options.maxValue) {
1541
+ throw new TypeError(
1542
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
1543
+ );
1544
+ }
1545
+ options.validate?.(value);
1546
+ }
1547
+ });
1548
+ }
1549
+ function dynamicSizeBcsType({
1550
+ serialize,
1551
+ ...options
1552
+ }) {
1553
+ const type = new BcsType({
1554
+ ...options,
1555
+ serialize,
1556
+ write: (value, writer) => {
1557
+ for (const byte of type.serialize(value).toBytes()) {
1558
+ writer.write8(byte);
1559
+ }
1560
+ }
1561
+ });
1562
+ return type;
1563
+ }
1564
+ function stringLikeBcsType({
1565
+ toBytes: toBytes2,
1566
+ fromBytes,
1567
+ ...options
1568
+ }) {
1569
+ return new BcsType({
1570
+ ...options,
1571
+ read: (reader) => {
1572
+ const length = reader.readULEB();
1573
+ const bytes = reader.readBytes(length);
1574
+ return fromBytes(bytes);
1575
+ },
1576
+ write: (hex, writer) => {
1577
+ const bytes = toBytes2(hex);
1578
+ writer.writeULEB(bytes.length);
1579
+ for (let i = 0; i < bytes.length; i++) {
1580
+ writer.write8(bytes[i]);
1581
+ }
1582
+ },
1583
+ serialize: (value) => {
1584
+ const bytes = toBytes2(value);
1585
+ const size = ulebEncode(bytes.length);
1586
+ const result = new Uint8Array(size.length + bytes.length);
1587
+ result.set(size, 0);
1588
+ result.set(bytes, size.length);
1589
+ return result;
1590
+ },
1591
+ validate: (value) => {
1592
+ if (typeof value !== "string") {
1593
+ throw new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);
1594
+ }
1595
+ options.validate?.(value);
1596
+ }
1597
+ });
1598
+ }
1599
+ function lazyBcsType(cb) {
1600
+ let lazyType = null;
1601
+ function getType() {
1602
+ if (!lazyType) {
1603
+ lazyType = cb();
1604
+ }
1605
+ return lazyType;
1606
+ }
1607
+ return new BcsType({
1608
+ name: "lazy",
1609
+ read: (data) => getType().read(data),
1610
+ serializedSize: (value) => getType().serializedSize(value),
1611
+ write: (value, writer) => getType().write(value, writer),
1612
+ serialize: (value, options) => getType().serialize(value, options).toBytes()
1613
+ });
1614
+ }
1615
+ var BcsStruct = class extends BcsType {
1616
+ constructor({ name: name2, fields, ...options }) {
1617
+ const canonicalOrder = Object.entries(fields);
1618
+ super({
1619
+ name: name2,
1620
+ serializedSize: (values) => {
1621
+ let total = 0;
1622
+ for (const [field, type] of canonicalOrder) {
1623
+ const size = type.serializedSize(values[field]);
1624
+ if (size == null) {
1625
+ return null;
1626
+ }
1627
+ total += size;
1628
+ }
1629
+ return total;
1630
+ },
1631
+ read: (reader) => {
1632
+ const result = {};
1633
+ for (const [field, type] of canonicalOrder) {
1634
+ result[field] = type.read(reader);
1635
+ }
1636
+ return result;
1637
+ },
1638
+ write: (value, writer) => {
1639
+ for (const [field, type] of canonicalOrder) {
1640
+ type.write(value[field], writer);
1641
+ }
1642
+ },
1643
+ ...options,
1644
+ validate: (value) => {
1645
+ options?.validate?.(value);
1646
+ if (typeof value !== "object" || value == null) {
1647
+ throw new TypeError(`Expected object, found ${typeof value}`);
1648
+ }
1649
+ }
1650
+ });
1651
+ }
1652
+ };
1653
+ var BcsEnum = class extends BcsType {
1654
+ constructor({ fields, ...options }) {
1655
+ const canonicalOrder = Object.entries(fields);
1656
+ super({
1657
+ read: (reader) => {
1658
+ const index = reader.readULEB();
1659
+ const enumEntry = canonicalOrder[index];
1660
+ if (!enumEntry) {
1661
+ throw new TypeError(`Unknown value ${index} for enum ${name}`);
1662
+ }
1663
+ const [kind, type] = enumEntry;
1664
+ return {
1665
+ [kind]: type?.read(reader) ?? true,
1666
+ $kind: kind
1667
+ };
1668
+ },
1669
+ write: (value, writer) => {
1670
+ const [name2, val] = Object.entries(value).filter(
1671
+ ([name3]) => Object.hasOwn(fields, name3)
1672
+ )[0];
1673
+ for (let i = 0; i < canonicalOrder.length; i++) {
1674
+ const [optionName, optionType] = canonicalOrder[i];
1675
+ if (optionName === name2) {
1676
+ writer.writeULEB(i);
1677
+ optionType?.write(val, writer);
1678
+ return;
1679
+ }
1680
+ }
1681
+ },
1682
+ ...options,
1683
+ validate: (value) => {
1684
+ options?.validate?.(value);
1685
+ if (typeof value !== "object" || value == null) {
1686
+ throw new TypeError(`Expected object, found ${typeof value}`);
1687
+ }
1688
+ const keys = Object.keys(value).filter(
1689
+ (k) => value[k] !== void 0 && Object.hasOwn(fields, k)
1690
+ );
1691
+ if (keys.length !== 1) {
1692
+ throw new TypeError(
1693
+ `Expected object with one key, but found ${keys.length} for type ${name}}`
1694
+ );
1695
+ }
1696
+ const [variant] = keys;
1697
+ if (!Object.hasOwn(fields, variant)) {
1698
+ throw new TypeError(`Invalid enum variant ${variant}`);
1699
+ }
1700
+ }
1701
+ });
1702
+ }
1703
+ };
1704
+ var BcsTuple = class extends BcsType {
1705
+ constructor({ fields, name: name2, ...options }) {
1706
+ super({
1707
+ name: name2 ?? `(${fields.map((t) => t.name).join(", ")})`,
1708
+ serializedSize: (values) => {
1709
+ let total = 0;
1710
+ for (let i = 0; i < fields.length; i++) {
1711
+ const size = fields[i].serializedSize(values[i]);
1712
+ if (size == null) {
1713
+ return null;
1714
+ }
1715
+ total += size;
1716
+ }
1717
+ return total;
1718
+ },
1719
+ read: (reader) => {
1720
+ const result = [];
1721
+ for (const field of fields) {
1722
+ result.push(field.read(reader));
1723
+ }
1724
+ return result;
1725
+ },
1726
+ write: (value, writer) => {
1727
+ for (let i = 0; i < fields.length; i++) {
1728
+ fields[i].write(value[i], writer);
1729
+ }
1730
+ },
1731
+ ...options,
1732
+ validate: (value) => {
1733
+ options?.validate?.(value);
1734
+ if (!Array.isArray(value)) {
1735
+ throw new TypeError(`Expected array, found ${typeof value}`);
1736
+ }
1737
+ if (value.length !== fields.length) {
1738
+ throw new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);
1739
+ }
1740
+ }
1741
+ });
1742
+ }
1743
+ };
1744
+
1745
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs.js
1746
+ function fixedArray(size, type, options) {
1747
+ return new BcsType({
1748
+ read: (reader) => {
1749
+ const result = new Array(size);
1750
+ for (let i = 0; i < size; i++) {
1751
+ result[i] = type.read(reader);
1752
+ }
1753
+ return result;
1754
+ },
1755
+ write: (value, writer) => {
1756
+ for (const item of value) {
1757
+ type.write(item, writer);
1758
+ }
1759
+ },
1760
+ ...options,
1761
+ name: options?.name ?? `${type.name}[${size}]`,
1762
+ validate: (value) => {
1763
+ options?.validate?.(value);
1764
+ if (!value || typeof value !== "object" || !("length" in value)) {
1765
+ throw new TypeError(`Expected array, found ${typeof value}`);
1766
+ }
1767
+ if (value.length !== size) {
1768
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
1769
+ }
1770
+ }
1771
+ });
1772
+ }
1773
+ function option(type) {
1774
+ return bcs.enum(`Option<${type.name}>`, {
1775
+ None: null,
1776
+ Some: type
1777
+ }).transform({
1778
+ input: (value) => {
1779
+ if (value == null) {
1780
+ return { None: true };
1781
+ }
1782
+ return { Some: value };
1783
+ },
1784
+ output: (value) => {
1785
+ if (value.$kind === "Some") {
1786
+ return value.Some;
1787
+ }
1788
+ return null;
1789
+ }
1790
+ });
1791
+ }
1792
+ function vector(type, options) {
1793
+ return new BcsType({
1794
+ read: (reader) => {
1795
+ const length = reader.readULEB();
1796
+ const result = new Array(length);
1797
+ for (let i = 0; i < length; i++) {
1798
+ result[i] = type.read(reader);
1799
+ }
1800
+ return result;
1801
+ },
1802
+ write: (value, writer) => {
1803
+ writer.writeULEB(value.length);
1804
+ for (const item of value) {
1805
+ type.write(item, writer);
1806
+ }
1807
+ },
1808
+ ...options,
1809
+ name: options?.name ?? `vector<${type.name}>`,
1810
+ validate: (value) => {
1811
+ options?.validate?.(value);
1812
+ if (!value || typeof value !== "object" || !("length" in value)) {
1813
+ throw new TypeError(`Expected array, found ${typeof value}`);
1814
+ }
1815
+ }
1816
+ });
1817
+ }
1818
+ function map(keyType, valueType) {
1819
+ return bcs.vector(bcs.tuple([keyType, valueType])).transform({
1820
+ name: `Map<${keyType.name}, ${valueType.name}>`,
1821
+ input: (value) => {
1822
+ return [...value.entries()];
1823
+ },
1824
+ output: (value) => {
1825
+ const result = /* @__PURE__ */ new Map();
1826
+ for (const [key, val] of value) {
1827
+ result.set(key, val);
1828
+ }
1829
+ return result;
1830
+ }
1831
+ });
1832
+ }
1833
+ var bcs = {
1834
+ /**
1835
+ * Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
1836
+ * @example
1837
+ * bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
1838
+ */
1839
+ u8(options) {
1840
+ return uIntBcsType({
1841
+ readMethod: "read8",
1842
+ writeMethod: "write8",
1843
+ size: 1,
1844
+ maxValue: 2 ** 8 - 1,
1845
+ ...options,
1846
+ name: options?.name ?? "u8"
1847
+ });
1848
+ },
1849
+ /**
1850
+ * Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
1851
+ * @example
1852
+ * bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
1853
+ */
1854
+ u16(options) {
1855
+ return uIntBcsType({
1856
+ readMethod: "read16",
1857
+ writeMethod: "write16",
1858
+ size: 2,
1859
+ maxValue: 2 ** 16 - 1,
1860
+ ...options,
1861
+ name: options?.name ?? "u16"
1862
+ });
1863
+ },
1864
+ /**
1865
+ * Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
1866
+ * @example
1867
+ * bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
1868
+ */
1869
+ u32(options) {
1870
+ return uIntBcsType({
1871
+ readMethod: "read32",
1872
+ writeMethod: "write32",
1873
+ size: 4,
1874
+ maxValue: 2 ** 32 - 1,
1875
+ ...options,
1876
+ name: options?.name ?? "u32"
1877
+ });
1878
+ },
1879
+ /**
1880
+ * Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
1881
+ * @example
1882
+ * bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
1883
+ */
1884
+ u64(options) {
1885
+ return bigUIntBcsType({
1886
+ readMethod: "read64",
1887
+ writeMethod: "write64",
1888
+ size: 8,
1889
+ maxValue: 2n ** 64n - 1n,
1890
+ ...options,
1891
+ name: options?.name ?? "u64"
1892
+ });
1893
+ },
1894
+ /**
1895
+ * Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
1896
+ * @example
1897
+ * bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
1898
+ */
1899
+ u128(options) {
1900
+ return bigUIntBcsType({
1901
+ readMethod: "read128",
1902
+ writeMethod: "write128",
1903
+ size: 16,
1904
+ maxValue: 2n ** 128n - 1n,
1905
+ ...options,
1906
+ name: options?.name ?? "u128"
1907
+ });
1908
+ },
1909
+ /**
1910
+ * Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
1911
+ * @example
1912
+ * bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
1913
+ */
1914
+ u256(options) {
1915
+ return bigUIntBcsType({
1916
+ readMethod: "read256",
1917
+ writeMethod: "write256",
1918
+ size: 32,
1919
+ maxValue: 2n ** 256n - 1n,
1920
+ ...options,
1921
+ name: options?.name ?? "u256"
1922
+ });
1923
+ },
1924
+ /**
1925
+ * Creates a BcsType that can be used to read and write boolean values.
1926
+ * @example
1927
+ * bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
1928
+ */
1929
+ bool(options) {
1930
+ return fixedSizeBcsType({
1931
+ size: 1,
1932
+ read: (reader) => reader.read8() === 1,
1933
+ write: (value, writer) => writer.write8(value ? 1 : 0),
1934
+ ...options,
1935
+ name: options?.name ?? "bool",
1936
+ validate: (value) => {
1937
+ options?.validate?.(value);
1938
+ if (typeof value !== "boolean") {
1939
+ throw new TypeError(`Expected boolean, found ${typeof value}`);
1940
+ }
1941
+ }
1942
+ });
1943
+ },
1944
+ /**
1945
+ * Creates a BcsType that can be used to read and write unsigned LEB encoded integers
1946
+ * @example
1947
+ *
1948
+ */
1949
+ uleb128(options) {
1950
+ return dynamicSizeBcsType({
1951
+ read: (reader) => reader.readULEB(),
1952
+ serialize: (value) => {
1953
+ return Uint8Array.from(ulebEncode(value));
1954
+ },
1955
+ ...options,
1956
+ name: options?.name ?? "uleb128"
1957
+ });
1958
+ },
1959
+ /**
1960
+ * Creates a BcsType representing a fixed length byte array
1961
+ * @param size The number of bytes this types represents
1962
+ * @example
1963
+ * bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
1964
+ */
1965
+ bytes(size, options) {
1966
+ return fixedSizeBcsType({
1967
+ size,
1968
+ read: (reader) => reader.readBytes(size),
1969
+ write: (value, writer) => {
1970
+ const array = new Uint8Array(value);
1971
+ for (let i = 0; i < size; i++) {
1972
+ writer.write8(array[i] ?? 0);
1973
+ }
1974
+ },
1975
+ ...options,
1976
+ name: options?.name ?? `bytes[${size}]`,
1977
+ validate: (value) => {
1978
+ options?.validate?.(value);
1979
+ if (!value || typeof value !== "object" || !("length" in value)) {
1980
+ throw new TypeError(`Expected array, found ${typeof value}`);
1981
+ }
1982
+ if (value.length !== size) {
1983
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
1984
+ }
1985
+ }
1986
+ });
1987
+ },
1988
+ /**
1989
+ * Creates a BcsType representing a variable length byte array
1990
+ *
1991
+ * @example
1992
+ * bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 1, 2, 3]
1993
+ */
1994
+ byteVector(options) {
1995
+ return new BcsType({
1996
+ read: (reader) => {
1997
+ const length = reader.readULEB();
1998
+ return reader.readBytes(length);
1999
+ },
2000
+ write: (value, writer) => {
2001
+ const array = new Uint8Array(value);
2002
+ writer.writeULEB(array.length);
2003
+ for (let i = 0; i < array.length; i++) {
2004
+ writer.write8(array[i] ?? 0);
2005
+ }
2006
+ },
2007
+ ...options,
2008
+ name: options?.name ?? "vector<u8>",
2009
+ serializedSize: (value) => {
2010
+ const length = "length" in value ? value.length : null;
2011
+ return length == null ? null : ulebEncode(length).length + length;
2012
+ },
2013
+ validate: (value) => {
2014
+ options?.validate?.(value);
2015
+ if (!value || typeof value !== "object" || !("length" in value)) {
2016
+ throw new TypeError(`Expected array, found ${typeof value}`);
2017
+ }
2018
+ }
2019
+ });
2020
+ },
2021
+ /**
2022
+ * Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
2023
+ * @example
2024
+ * bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
2025
+ */
2026
+ string(options) {
2027
+ return stringLikeBcsType({
2028
+ toBytes: (value) => new TextEncoder().encode(value),
2029
+ fromBytes: (bytes) => new TextDecoder().decode(bytes),
2030
+ ...options,
2031
+ name: options?.name ?? "string"
2032
+ });
2033
+ },
2034
+ /**
2035
+ * Creates a BcsType that represents a fixed length array of a given type
2036
+ * @param size The number of elements in the array
2037
+ * @param type The BcsType of each element in the array
2038
+ * @example
2039
+ * bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
2040
+ */
2041
+ fixedArray,
2042
+ /**
2043
+ * Creates a BcsType representing an optional value
2044
+ * @param type The BcsType of the optional value
2045
+ * @example
2046
+ * bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
2047
+ * bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
2048
+ */
2049
+ option,
2050
+ /**
2051
+ * Creates a BcsType representing a variable length vector of a given type
2052
+ * @param type The BcsType of each element in the vector
2053
+ *
2054
+ * @example
2055
+ * bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
2056
+ */
2057
+ vector,
2058
+ /**
2059
+ * Creates a BcsType representing a tuple of a given set of types
2060
+ * @param types The BcsTypes for each element in the tuple
2061
+ *
2062
+ * @example
2063
+ * const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
2064
+ * tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
2065
+ */
2066
+ tuple(fields, options) {
2067
+ return new BcsTuple({
2068
+ fields,
2069
+ ...options
2070
+ });
2071
+ },
2072
+ /**
2073
+ * Creates a BcsType representing a struct of a given set of fields
2074
+ * @param name The name of the struct
2075
+ * @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
2076
+ *
2077
+ * @example
2078
+ * const struct = bcs.struct('MyStruct', {
2079
+ * a: bcs.u8(),
2080
+ * b: bcs.string(),
2081
+ * })
2082
+ * struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
2083
+ */
2084
+ struct(name2, fields, options) {
2085
+ return new BcsStruct({
2086
+ name: name2,
2087
+ fields,
2088
+ ...options
2089
+ });
2090
+ },
2091
+ /**
2092
+ * Creates a BcsType representing an enum of a given set of options
2093
+ * @param name The name of the enum
2094
+ * @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
2095
+ * null can be used to represent a variant with no data.
2096
+ *
2097
+ * @example
2098
+ * const enum = bcs.enum('MyEnum', {
2099
+ * A: bcs.u8(),
2100
+ * B: bcs.string(),
2101
+ * C: null,
2102
+ * })
2103
+ * enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
2104
+ * enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
2105
+ * enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
2106
+ */
2107
+ enum(name2, fields, options) {
2108
+ return new BcsEnum({
2109
+ name: name2,
2110
+ fields,
2111
+ ...options
2112
+ });
2113
+ },
2114
+ /**
2115
+ * Creates a BcsType representing a map of a given key and value type
2116
+ * @param keyType The BcsType of the key
2117
+ * @param valueType The BcsType of the value
2118
+ * @example
2119
+ * const map = bcs.map(bcs.u8(), bcs.string())
2120
+ * map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
2121
+ */
2122
+ map,
2123
+ /**
2124
+ * Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
2125
+ * @param cb A callback that returns the BcsType
2126
+ */
2127
+ lazy(cb) {
2128
+ return lazyBcsType(cb);
2129
+ }
2130
+ };
2131
+
2132
+ // src/sdk/types.ts
2133
+ BigInt.prototype.toJSON = function() {
2134
+ return Number(this);
2135
+ };
2136
+ var Bytes32 = bcs.fixedArray(32, bcs.u8());
2137
+ var Bytes64 = bcs.fixedArray(64, bcs.u8());
2138
+ var PublicKey = Bytes32;
2139
+ var Signature = Bytes64;
2140
+ var Address = bcs.enum("Address", {
2141
+ External: PublicKey,
2142
+ FastSet: PublicKey
2143
+ });
2144
+ var Amount = bcs.u256().transform({
2145
+ // CAUTION: When we build a transaction object, we must use a hex encoded string because the
2146
+ // validator expects amounts to be in hex. However, bcs.u256() by default expects a decimal
2147
+ // string. Therefore, we must transform the input amount from hex to decimal here.
2148
+ input: (val) => hexToDecimal(val.toString()),
2149
+ output: (value) => value
2150
+ });
2151
+ var Balance = bcs.string().transform({
2152
+ input: (val) => val,
2153
+ output: (value) => value
2154
+ });
2155
+ var UserData = bcs.option(Bytes32);
2156
+ var Nonce = bcs.u64();
2157
+ var Quorum = bcs.u64();
2158
+ var TokenId = Bytes32;
2159
+ var Transfer = bcs.struct("Transfer", {
2160
+ amount: Amount,
2161
+ user_data: UserData
2162
+ });
2163
+ var TokenTransfer = bcs.struct("TokenTransfer", {
2164
+ token_id: TokenId,
2165
+ amount: Amount,
2166
+ user_data: UserData
2167
+ });
2168
+ var TokenCreation = bcs.struct("TokenCreation", {
2169
+ token_name: bcs.string(),
2170
+ decimals: bcs.u8(),
2171
+ initial_amount: Amount,
2172
+ mints: bcs.vector(PublicKey),
2173
+ user_data: UserData
2174
+ });
2175
+ var AddressChange = bcs.enum("AddressChange", {
2176
+ Add: PublicKey,
2177
+ Remove: PublicKey
2178
+ });
2179
+ var TokenManagement = bcs.struct("TokenManagement", {
2180
+ token_id: TokenId,
2181
+ update_id: Nonce,
2182
+ new_admin: bcs.option(PublicKey),
2183
+ mints: bcs.vector(bcs.tuple([AddressChange, PublicKey])),
2184
+ user_data: UserData
2185
+ });
2186
+ var Mint = bcs.struct("Mint", {
2187
+ token_id: TokenId,
2188
+ amount: Amount
2189
+ });
2190
+ var ClaimData = bcs.vector(bcs.u8());
2191
+ var ExternalClaimBody = bcs.struct("ExternalClaimBody", {
2192
+ verifier_committee: bcs.vector(PublicKey),
2193
+ verifier_quorum: Quorum,
2194
+ claim_data: ClaimData
2195
+ });
2196
+ var ExternalClaim = bcs.struct("ExternalClaim", {
2197
+ claim: ExternalClaimBody,
2198
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
2199
+ });
2200
+ var ClaimType = bcs.enum("ClaimType", {
2201
+ Transfer,
2202
+ TokenTransfer,
2203
+ TokenCreation,
2204
+ TokenManagement,
2205
+ Mint,
2206
+ ExternalClaim
2207
+ });
2208
+ var Transaction = bcs.struct("Transaction", {
2209
+ sender: PublicKey,
2210
+ recipient: Address,
2211
+ nonce: Nonce,
2212
+ timestamp_nanos: bcs.u128(),
2213
+ claim: ClaimType
2214
+ });
2215
+ var SubmitTransactionResponse = bcs.struct("SubmitTransactionResponse", {
2216
+ validator: PublicKey,
2217
+ signature: Signature,
2218
+ next_nonce: Nonce,
2219
+ transaction_hash: bcs.vector(bcs.u8())
2220
+ });
2221
+ var TransactionEnvelope = bcs.struct("TransactionEnvelope", {
2222
+ transaction: Transaction,
2223
+ signature: Signature
2224
+ });
2225
+ var TransactionCertificate = bcs.struct("TransactionCertificate", {
2226
+ envelope: TransactionEnvelope,
2227
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
2228
+ });
2229
+ function hexToDecimal(hex) {
2230
+ return BigInt(`0x${hex}`).toString();
2231
+ }
2232
+
2233
+ // src/WarpFastsetWallet.ts
648
2234
  var WarpFastsetWallet = class {
649
- constructor(config, chain) {
2235
+ constructor(config, chain2) {
650
2236
  this.config = config;
651
- this.chain = chain;
652
- this.wallet = null;
653
- const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
654
- if (privateKey) {
655
- this.wallet = new Wallet(privateKey);
656
- }
2237
+ this.chain = chain2;
657
2238
  this.client = getConfiguredFastsetClient(this.config, this.chain);
2239
+ const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
2240
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
2241
+ this.privateKey = privateKey;
658
2242
  }
659
2243
  async signTransaction(tx) {
660
- if (!this.wallet) throw new Error("Wallet not initialized");
661
- const transaction = tx;
662
- const serializedTx = this.serializeTransaction(transaction.toTransaction());
663
- const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
664
- return Object.assign(transaction, { signature: uint8ArrayToHex(signature) });
2244
+ const msg = Transaction.serialize(tx);
2245
+ const msgBytes = msg.toBytes();
2246
+ const prefix = new TextEncoder().encode("Transaction::");
2247
+ const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
2248
+ dataToSign.set(prefix, 0);
2249
+ dataToSign.set(msgBytes, prefix.length);
2250
+ const privateKeyBytes = hexToUint8Array(this.privateKey);
2251
+ const signature = ed.sign(dataToSign, privateKeyBytes);
2252
+ return { ...tx, signature };
665
2253
  }
666
2254
  async signMessage(message) {
667
- if (!this.wallet) throw new Error("Wallet not initialized");
668
2255
  const messageBytes = stringToUint8Array(message);
669
- const signature = await ed.sign(messageBytes, this.wallet.getPrivateKey());
2256
+ const privateKeyBytes = hexToUint8Array(this.privateKey);
2257
+ const signature = ed.sign(messageBytes, privateKeyBytes);
670
2258
  return uint8ArrayToHex(signature);
671
2259
  }
672
2260
  async sendTransaction(tx) {
673
- if (!this.wallet) throw new Error("Wallet not initialized");
674
- const transaction = tx;
675
- const fastsetTx = transaction.toTransaction();
676
- const transactionData = {
677
- sender: fastsetTx.sender,
678
- recipient: fastsetTx.recipient,
679
- nonce: fastsetTx.nonce,
680
- timestamp_nanos: fastsetTx.timestamp_nanos,
681
- claim: fastsetTx.claim
682
- };
683
- const signature = tx.signature ? hexToUint8Array(tx.signature) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
684
- return await this.client.submitTransaction(transactionData, signature);
2261
+ const { signature, ...transactionWithoutSignature } = tx;
2262
+ const submitTxReq = { transaction: transactionWithoutSignature, signature };
2263
+ const proxyUrl = (0, import_warps5.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
2264
+ const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
2265
+ if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
2266
+ console.log("submitTransaction response", response.result);
2267
+ return "TODO";
685
2268
  }
686
2269
  create(mnemonic) {
687
2270
  const seed = bip39.mnemonicToSeedSync(mnemonic);
688
2271
  const privateKey = seed.slice(0, 32);
689
- const wallet = new Wallet(uint8ArrayToHex(privateKey));
690
- return { address: wallet.toBech32(), privateKey: uint8ArrayToHex(wallet.getPrivateKey()), mnemonic };
2272
+ const publicKey = ed.getPublicKey(privateKey);
2273
+ const address = FastsetClient.encodeBech32Address(publicKey);
2274
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
691
2275
  }
692
2276
  generate() {
693
2277
  const privateKey = ed.utils.randomPrivateKey();
694
- const wallet = new Wallet(uint8ArrayToHex(privateKey));
695
- return { address: wallet.toBech32(), privateKey: uint8ArrayToHex(wallet.getPrivateKey()), mnemonic: null };
2278
+ const publicKey = ed.getPublicKey(privateKey);
2279
+ const address = FastsetClient.encodeBech32Address(publicKey);
2280
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
696
2281
  }
697
2282
  getAddress() {
698
2283
  return (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
699
2284
  }
700
- serializeTransaction(tx) {
701
- const serialized = JSON.stringify(tx, (k, v) => {
702
- if (v instanceof Uint8Array) return Array.from(v);
703
- if (typeof v === "bigint") return v.toString();
704
- return v;
705
- });
706
- return encoder.encode(serialized);
707
- }
708
2285
  };
709
2286
 
710
2287
  // src/main.ts
@@ -713,7 +2290,7 @@ var NativeTokenSet = {
713
2290
  identifier: "SET",
714
2291
  name: "SET",
715
2292
  symbol: "SET",
716
- decimals: 6,
2293
+ decimals: 0,
717
2294
  logoUrl: "https://vleap.ai/images/tokens/set.svg"
718
2295
  };
719
2296
  function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
@@ -770,17 +2347,19 @@ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset
770
2347
  nativeToken: NativeTokenSet
771
2348
  }
772
2349
  });
773
-
774
- // src/index.ts
775
- init_sdk();
776
2350
  // Annotate the CommonJS export names for ESM import in node:
777
2351
  0 && (module.exports = {
778
- FastsetClient,
779
2352
  NativeTokenSet,
780
- Transaction,
781
- Wallet,
782
2353
  WarpFastsetExecutor,
783
2354
  WarpFastsetWallet,
784
2355
  getFastsetAdapter
785
2356
  });
2357
+ /*! Bundled license information:
2358
+
2359
+ @noble/hashes/esm/utils.js:
2360
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2361
+
2362
+ @scure/base/lib/esm/index.js:
2363
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2364
+ */
786
2365
  //# sourceMappingURL=index.js.map