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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,174 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __esm = (fn, res) => function __init() {
4
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
- };
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
-
11
- // src/sdk/ed25519-setup.ts
12
- import * as ed from "@noble/ed25519";
13
- import { sha512 } from "@noble/hashes/sha512";
14
- var init_ed25519_setup = __esm({
15
- "src/sdk/ed25519-setup.ts"() {
16
- "use strict";
17
- if (ed.etc) {
18
- ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
19
- }
20
- }
21
- });
22
-
23
- // src/sdk/FastsetClient.ts
24
- import * as bech32 from "bech32";
25
- var Transaction, FastsetClient, Wallet;
26
- var init_FastsetClient = __esm({
27
- "src/sdk/FastsetClient.ts"() {
28
- "use strict";
29
- init_ed25519_setup();
30
- BigInt.prototype.toJSON = function() {
31
- return Number(this);
32
- };
33
- Transaction = class {
34
- constructor(sender, recipient, nonce, claim, timestamp = BigInt(Date.now()) * 1000000n) {
35
- this.sender = sender;
36
- this.recipient = recipient;
37
- this.nonce = nonce;
38
- this.claim = claim;
39
- this.timestamp = timestamp;
40
- if (claim?.Transfer?.amount?.startsWith("0x")) {
41
- claim = { ...claim, Transfer: { ...claim.Transfer, amount: claim.Transfer.amount.slice(2) } };
42
- }
43
- }
44
- toTransaction() {
45
- return { sender: this.sender, recipient: this.recipient, nonce: this.nonce, timestamp_nanos: this.timestamp, claim: this.claim };
46
- }
47
- getRecipientAddress() {
48
- return this.recipient;
49
- }
50
- getAmount() {
51
- return this.claim?.Transfer?.amount || "";
52
- }
53
- getUserData() {
54
- return this.claim?.Transfer?.user_data || null;
55
- }
56
- };
57
- FastsetClient = class {
58
- constructor(config, chain) {
59
- this.proxyUrl = config && "proxyUrl" in config ? config.proxyUrl : config && chain ? chain.defaultApiUrl : "https://proxy.fastset.xyz";
60
- }
61
- async makeRequest(method, params = {}) {
62
- const response = await fetch(this.proxyUrl, {
63
- method: "POST",
64
- headers: { "Content-Type": "application/json" },
65
- body: JSON.stringify({ jsonrpc: "2.0", method, params, id: Date.now() }, (k, v) => v instanceof Uint8Array ? Array.from(v) : v)
66
- });
67
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
68
- const jsonResponse = await response.json();
69
- if (jsonResponse.error) throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
70
- return jsonResponse.result;
71
- }
72
- async getAccountInfo(address) {
73
- return this.makeRequest("set_proxy_getAccountInfo", { address });
74
- }
75
- async getNextNonce(address) {
76
- const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
77
- const accountInfo = await this.getAccountInfo(addressBytes);
78
- return accountInfo.next_nonce;
79
- }
80
- async submitTransaction(transaction, signature) {
81
- const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
82
- const submitTxReq = {
83
- transaction: {
84
- sender: transaction.sender instanceof Uint8Array ? transaction.sender : new Uint8Array(transaction.sender),
85
- recipient: transaction.recipient,
86
- nonce: transaction.nonce,
87
- timestamp_nanos: transaction.timestamp_nanos,
88
- claim: transaction.claim
89
- },
90
- signature: new Uint8Array(signatureArray)
91
- };
92
- const response = await fetch(this.proxyUrl, {
93
- method: "POST",
94
- headers: { "Content-Type": "application/json" },
95
- body: JSON.stringify(
96
- { jsonrpc: "2.0", method: "set_proxy_submitTransaction", params: submitTxReq, id: 1 },
97
- (k, v) => v instanceof Uint8Array ? Array.from(v) : v
98
- )
99
- });
100
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
101
- const jsonResponse = await response.json();
102
- if (jsonResponse.error) throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
103
- return jsonResponse.result;
104
- }
105
- async faucetDrip(recipient, amount) {
106
- const recipientArray = Array.isArray(recipient) ? recipient : Array.from(recipient);
107
- return this.makeRequest("set_proxy_faucetDrip", { recipient: recipientArray, amount });
108
- }
109
- addressToBytes(address) {
110
- try {
111
- const decoded = bech32.bech32m.decode(address);
112
- return Array.from(bech32.bech32m.fromWords(decoded.words));
113
- } catch {
114
- const decoded = bech32.bech32.decode(address);
115
- return Array.from(bech32.bech32.fromWords(decoded.words));
116
- }
117
- }
118
- // Wallet utilities
119
- generateNewWallet() {
120
- const privateKey = ed.utils.randomPrivateKey();
121
- return new Wallet(Buffer.from(privateKey).toString("hex"));
122
- }
123
- createWallet(privateKeyHex) {
124
- return new Wallet(privateKeyHex);
125
- }
126
- static decodeBech32Address(address) {
127
- try {
128
- const decoded = bech32.bech32m.decode(address);
129
- return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
130
- } catch {
131
- const decoded = bech32.bech32.decode(address);
132
- return new Uint8Array(bech32.bech32.fromWords(decoded.words));
133
- }
134
- }
135
- static encodeBech32Address(publicKey) {
136
- const words = bech32.bech32m.toWords(publicKey);
137
- return bech32.bech32m.encode("set", words);
138
- }
139
- };
140
- Wallet = class {
141
- constructor(privateKeyHex) {
142
- this.privateKey = new Uint8Array(Buffer.from(privateKeyHex.replace(/^0x/, ""), "hex"));
143
- this.publicKey = ed.getPublicKey(this.privateKey);
144
- }
145
- toBech32() {
146
- return bech32.bech32m.encode("set", bech32.bech32m.toWords(this.publicKey));
147
- }
148
- signTransactionRaw(data) {
149
- return ed.sign(data, this.privateKey);
150
- }
151
- getPrivateKey() {
152
- return this.privateKey;
153
- }
154
- };
155
- }
156
- });
157
-
158
- // src/sdk/index.ts
159
- var sdk_exports = {};
160
- __export(sdk_exports, {
161
- FastsetClient: () => FastsetClient,
162
- Transaction: () => Transaction,
163
- Wallet: () => Wallet
164
- });
165
- var init_sdk = __esm({
166
- "src/sdk/index.ts"() {
167
- "use strict";
168
- init_FastsetClient();
169
- }
170
- });
171
-
172
1
  // src/main.ts
173
2
  import { WarpChainName } from "@vleap/warps";
174
3
 
@@ -181,19 +10,112 @@ var decoder = new TextDecoder();
181
10
  function uint8ArrayToHex(uint8Array) {
182
11
  return Buffer.from(uint8Array).toString("hex");
183
12
  }
184
- function hexToUint8Array(hex) {
185
- return new Uint8Array(Buffer.from(hex, "hex"));
186
- }
187
13
  function stringToUint8Array(str) {
188
14
  return new Uint8Array(Buffer.from(str, "utf8"));
189
15
  }
190
16
 
191
17
  // src/helpers/general.ts
192
- init_sdk();
193
18
  import { getProviderUrl } from "@vleap/warps";
19
+
20
+ // src/sdk/FastsetClient.ts
21
+ import { BCS, getSuiMoveConfig } from "@mysten/bcs";
22
+ import * as bech32 from "bech32";
23
+ BigInt.prototype.toJSON = function() {
24
+ return Number(this);
25
+ };
26
+ var bcs = new BCS(getSuiMoveConfig());
27
+ bcs.registerStructType("FastSetAddress", {
28
+ bytes: "vector<u8>"
29
+ });
30
+ bcs.registerStructType("ExternalAddress", {
31
+ bytes: "vector<u8>"
32
+ });
33
+ bcs.registerEnumType("Address", {
34
+ FastSet: "FastSetAddress",
35
+ External: "ExternalAddress"
36
+ });
37
+ bcs.registerEnumType("UserDataOption", {
38
+ Some: "vector<u8>",
39
+ None: "bool"
40
+ // Use bool for None variant (false = None)
41
+ });
42
+ bcs.registerStructType("TransferClaim", {
43
+ amount: "u256",
44
+ // 256-bit unsigned integer
45
+ user_data: "UserDataOption"
46
+ // Use our custom option type
47
+ });
48
+ bcs.registerStructType("ClaimType", {
49
+ Transfer: "TransferClaim"
50
+ });
51
+ bcs.registerStructType("Transaction", {
52
+ sender: "vector<u8>",
53
+ // 32 bytes
54
+ recipient: "Address",
55
+ nonce: "u64",
56
+ timestamp_nanos: "u128",
57
+ claim: "ClaimType"
58
+ });
59
+ var id = 0;
60
+ var FastsetClient = class {
61
+ constructor(proxyUrl) {
62
+ this.proxyUrl = proxyUrl;
63
+ }
64
+ async request(url, method, params) {
65
+ const request = this.buildJsonRpcRequest(id++, method, params);
66
+ const headers = { "Content-Type": "application/json" };
67
+ const body = this.jsonSerialize(request);
68
+ const response = await fetch(url, { method: "POST", headers, body });
69
+ const json = await response.json();
70
+ return json;
71
+ }
72
+ buildJsonRpcRequest(id2, method, params) {
73
+ return { jsonrpc: "2.0", id: id2, method, params };
74
+ }
75
+ jsonSerialize(data) {
76
+ return JSON.stringify(data, (k, v) => {
77
+ if (v instanceof Uint8Array) {
78
+ return Array.from(v);
79
+ }
80
+ return v;
81
+ });
82
+ }
83
+ async getAccountInfo(address) {
84
+ return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
85
+ }
86
+ async getNextNonce(address) {
87
+ const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
88
+ const accountInfoRes = await this.getAccountInfo(addressBytes);
89
+ return accountInfoRes.result?.next_nonce ?? 0;
90
+ }
91
+ addressToBytes(address) {
92
+ try {
93
+ const decoded = bech32.bech32m.decode(address);
94
+ return Array.from(bech32.bech32m.fromWords(decoded.words));
95
+ } catch {
96
+ const decoded = bech32.bech32.decode(address);
97
+ return Array.from(bech32.bech32.fromWords(decoded.words));
98
+ }
99
+ }
100
+ static decodeBech32Address(address) {
101
+ try {
102
+ const decoded = bech32.bech32m.decode(address);
103
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
104
+ } catch {
105
+ const decoded = bech32.bech32.decode(address);
106
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
107
+ }
108
+ }
109
+ static encodeBech32Address(publicKey) {
110
+ const words = bech32.bech32m.toWords(publicKey);
111
+ return bech32.bech32m.encode("set", words);
112
+ }
113
+ };
114
+
115
+ // src/helpers/general.ts
194
116
  var getConfiguredFastsetClient = (config, chain) => {
195
117
  const proxyUrl = getProviderUrl(config, chain.name, config.env, chain.defaultApiUrl);
196
- return new FastsetClient({ proxyUrl });
118
+ return new FastsetClient(proxyUrl);
197
119
  };
198
120
 
199
121
  // src/WarpFastsetDataLoader.ts
@@ -206,17 +128,18 @@ var WarpFastsetDataLoader = class {
206
128
  async getAccount(address) {
207
129
  const addressBytes = this.addressToBytes(address);
208
130
  const accountInfo = await this.client.getAccountInfo(addressBytes);
209
- return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.balance, 16)) };
131
+ return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
210
132
  }
211
133
  async getAccountAssets(address) {
212
134
  const addressBytes = this.addressToBytes(address);
213
135
  const accountInfo = await this.client.getAccountInfo(addressBytes);
214
136
  const assets = [];
215
- const balance = BigInt(parseInt(accountInfo.balance, 16));
137
+ console.log("accountInfo", accountInfo);
138
+ const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
216
139
  if (balance > 0n) {
217
140
  assets.push({ ...this.chain.nativeToken, amount: balance });
218
141
  }
219
- for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
142
+ for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
220
143
  const amount = BigInt(parseInt(tokenBalance, 16));
221
144
  if (amount > 0n) {
222
145
  const tokenInfo = await this.client.getTokenInfo([tokenId]);
@@ -274,7 +197,6 @@ var WarpFastsetDataLoader = class {
274
197
  };
275
198
 
276
199
  // src/WarpFastsetExecutor.ts
277
- init_sdk();
278
200
  import {
279
201
  getWarpActionByIndex,
280
202
  getWarpWalletAddressFromConfig
@@ -283,7 +205,7 @@ var WarpFastsetExecutor = class {
283
205
  constructor(config, chain) {
284
206
  this.config = config;
285
207
  this.chain = chain;
286
- this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
208
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
287
209
  }
288
210
  async createTransaction(executable) {
289
211
  const action = getWarpActionByIndex(executable.warp, executable.action);
@@ -292,99 +214,30 @@ var WarpFastsetExecutor = class {
292
214
  if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
293
215
  if (action.type === "collect")
294
216
  throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
295
- throw new Error(`WarpFastsetExecutor: Invalid action type (unknown)`);
217
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
296
218
  }
297
219
  async createTransferTransaction(executable) {
298
220
  const userWallet = getWarpWalletAddressFromConfig(this.config, executable.chain.name);
299
221
  if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
300
- const senderAddress = FastsetClient.decodeBech32Address(userWallet);
301
- let recipientAddress;
302
- try {
303
- recipientAddress = FastsetClient.decodeBech32Address(executable.destination);
304
- } catch (error) {
305
- throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
306
- }
307
- const nonce = await this.fastsetClient.getNextNonce(userWallet);
308
- const transferValue = executable.transfers?.[0]?.amount || executable.value;
309
- if (transferValue < 0) throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${transferValue}`);
310
- const amount = "0x" + transferValue.toString(16);
311
- const userData = executable.data ? this.fromBase64(executable.data) : null;
312
- const claim = { Transfer: { amount, user_data: userData } };
313
- return new Transaction(senderAddress, { FastSet: recipientAddress }, nonce, claim);
314
- }
315
- async createContractCallTransaction(executable) {
316
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
317
- if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
318
- const action = getWarpActionByIndex(executable.warp, executable.action);
319
- if (!action || !("func" in action) || !action.func) throw new Error("WarpFastsetExecutor: Contract action must have a function name");
320
- let contractAddress;
321
- try {
322
- contractAddress = this.fromBase64(executable.destination);
323
- } catch (error) {
324
- throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
325
- }
222
+ const senderPubKey = FastsetClient.decodeBech32Address(userWallet);
223
+ const recipientPubKey = FastsetClient.decodeBech32Address(executable.destination);
224
+ const nonce = await this.client.getNextNonce(userWallet);
225
+ const nativeAmountInTransfers = executable.transfers.find((transfer) => transfer.identifier === this.chain.nativeToken?.identifier)?.amount || 0n;
226
+ const nativeAmountTotal = nativeAmountInTransfers + executable.value;
227
+ const amountHex = BigInt(nativeAmountTotal).toString(16);
326
228
  return {
327
- type: "fastset-contract-call",
328
- contract: contractAddress,
329
- function: action.func,
330
- data: JSON.stringify({ function: action.func, arguments: executable.args }),
331
- value: executable.value,
332
- chain: executable.chain
333
- };
334
- }
335
- async executeQuery(executable) {
336
- const action = getWarpActionByIndex(executable.warp, executable.action);
337
- if (action.type !== "query") throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
338
- if (!action.func) throw new Error("WarpFastsetExecutor: Query action must have a function name");
339
- try {
340
- const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
341
- return { success: true, result, chain: executable.chain };
342
- } catch (error) {
343
- return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
344
- }
345
- }
346
- async executeTransfer(executable) {
347
- const transaction = await this.createTransferTransaction(executable);
348
- return { success: true, transaction, chain: executable.chain.name };
349
- }
350
- async executeTransferWithKey(executable, privateKey) {
351
- const transaction = await this.createTransferTransaction(executable);
352
- const privateKeyBytes = this.fromBase64(privateKey);
353
- const transactionData = {
354
- sender: privateKeyBytes.slice(0, 32),
355
- recipient: transaction.getRecipientAddress(),
356
- nonce: await this.fastsetClient.getNextNonce(FastsetClient.encodeBech32Address(privateKeyBytes.slice(0, 32))),
229
+ sender: senderPubKey,
230
+ recipient: { FastSet: recipientPubKey },
231
+ nonce,
357
232
  timestamp_nanos: BigInt(Date.now()) * 1000000n,
358
- claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
233
+ claim: { Transfer: { amount: amountHex, user_data: null } }
359
234
  };
360
- const signature = await this.signTransaction(transactionData, privateKeyBytes);
361
- const result = await this.fastsetClient.submitTransaction(transactionData, signature);
362
- return { success: true, result, message: "Transaction submitted successfully", chain: executable.chain.name };
363
- }
364
- async signTransaction(transaction, privateKey) {
365
- const wallet = new (await Promise.resolve().then(() => (init_sdk(), sdk_exports))).Wallet(Buffer.from(privateKey).toString("hex"));
366
- return wallet.signTransactionRaw(this.serializeTransaction(transaction));
367
- }
368
- serializeTransaction(tx) {
369
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
370
- return new TextEncoder().encode(serialized);
371
- }
372
- async executeFastsetQuery(contractAddress, functionName, args) {
373
- const response = await fetch("https://proxy.fastset.xyz", {
374
- method: "POST",
375
- headers: { "Content-Type": "application/json" },
376
- body: JSON.stringify({
377
- jsonrpc: "2.0",
378
- method: "set_proxy_query",
379
- params: { contract: Array.from(contractAddress), function: functionName, arguments: args },
380
- id: 1
381
- })
382
- });
383
- if (!response.ok) throw new Error(`Fastset query failed: ${response.statusText}`);
384
- return response.json();
385
235
  }
386
- fromBase64(base64) {
387
- return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
236
+ async createContractCallTransaction(executable) {
237
+ throw new Error("WarpFastsetExecutor: Not implemented");
238
+ }
239
+ async executeQuery(executable) {
240
+ throw new Error("WarpFastsetExecutor: Not implemented");
388
241
  }
389
242
  };
390
243
 
@@ -617,71 +470,173 @@ var WarpFastsetResults = class {
617
470
  // src/WarpFastsetWallet.ts
618
471
  import * as bip39 from "@scure/bip39";
619
472
  import {
473
+ getProviderUrl as getProviderUrl2,
620
474
  getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3,
621
475
  getWarpWalletPrivateKeyFromConfig
622
476
  } from "@vleap/warps";
623
- init_sdk();
624
- init_ed25519_setup();
477
+
478
+ // src/sdk/ed25519-setup.ts
479
+ import * as ed from "@noble/ed25519";
480
+ import { sha512 } from "@noble/hashes/sha512";
481
+ if (ed.etc) {
482
+ ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
483
+ }
484
+
485
+ // src/sdk/types.ts
486
+ import { bcs as bcs2 } from "@mysten/bcs";
487
+ BigInt.prototype.toJSON = function() {
488
+ return Number(this);
489
+ };
490
+ var Bytes32 = bcs2.fixedArray(32, bcs2.u8());
491
+ var Bytes64 = bcs2.fixedArray(64, bcs2.u8());
492
+ var PublicKey = Bytes32;
493
+ var Signature = Bytes64;
494
+ var Address = bcs2.enum("Address", {
495
+ External: PublicKey,
496
+ FastSet: PublicKey
497
+ });
498
+ var Amount = bcs2.u256().transform({
499
+ // CAUTION: When we build a transaction object, we must use a hex encoded string because the
500
+ // validator expects amounts to be in hex. However, bcs.u256() by default expects a decimal
501
+ // string. Therefore, we must transform the input amount from hex to decimal here.
502
+ input: (val) => hexToDecimal(val.toString()),
503
+ output: (value) => value
504
+ });
505
+ var Balance = bcs2.string().transform({
506
+ input: (val) => val,
507
+ output: (value) => value
508
+ });
509
+ var UserData = bcs2.option(Bytes32);
510
+ var Nonce = bcs2.u64();
511
+ var Quorum = bcs2.u64();
512
+ var TokenId = Bytes32;
513
+ var Transfer = bcs2.struct("Transfer", {
514
+ amount: Amount,
515
+ user_data: UserData
516
+ });
517
+ var TokenTransfer = bcs2.struct("TokenTransfer", {
518
+ token_id: TokenId,
519
+ amount: Amount,
520
+ user_data: UserData
521
+ });
522
+ var TokenCreation = bcs2.struct("TokenCreation", {
523
+ token_name: bcs2.string(),
524
+ decimals: bcs2.u8(),
525
+ initial_amount: Amount,
526
+ mints: bcs2.vector(PublicKey),
527
+ user_data: UserData
528
+ });
529
+ var AddressChange = bcs2.enum("AddressChange", {
530
+ Add: PublicKey,
531
+ Remove: PublicKey
532
+ });
533
+ var TokenManagement = bcs2.struct("TokenManagement", {
534
+ token_id: TokenId,
535
+ update_id: Nonce,
536
+ new_admin: bcs2.option(PublicKey),
537
+ mints: bcs2.vector(bcs2.tuple([AddressChange, PublicKey])),
538
+ user_data: UserData
539
+ });
540
+ var Mint = bcs2.struct("Mint", {
541
+ token_id: TokenId,
542
+ amount: Amount
543
+ });
544
+ var ClaimData = bcs2.vector(bcs2.u8());
545
+ var ExternalClaimBody = bcs2.struct("ExternalClaimBody", {
546
+ verifier_committee: bcs2.vector(PublicKey),
547
+ verifier_quorum: Quorum,
548
+ claim_data: ClaimData
549
+ });
550
+ var ExternalClaim = bcs2.struct("ExternalClaim", {
551
+ claim: ExternalClaimBody,
552
+ signatures: bcs2.vector(bcs2.tuple([PublicKey, Signature]))
553
+ });
554
+ var ClaimType = bcs2.enum("ClaimType", {
555
+ Transfer,
556
+ TokenTransfer,
557
+ TokenCreation,
558
+ TokenManagement,
559
+ Mint,
560
+ ExternalClaim
561
+ });
562
+ var Transaction = bcs2.struct("Transaction", {
563
+ sender: PublicKey,
564
+ recipient: Address,
565
+ nonce: Nonce,
566
+ timestamp_nanos: bcs2.u128(),
567
+ claim: ClaimType
568
+ });
569
+ var SubmitTransactionResponse = bcs2.struct("SubmitTransactionResponse", {
570
+ validator: PublicKey,
571
+ signature: Signature,
572
+ next_nonce: Nonce,
573
+ transaction_hash: bcs2.vector(bcs2.u8())
574
+ });
575
+ var TransactionEnvelope = bcs2.struct("TransactionEnvelope", {
576
+ transaction: Transaction,
577
+ signature: Signature
578
+ });
579
+ var TransactionCertificate = bcs2.struct("TransactionCertificate", {
580
+ envelope: TransactionEnvelope,
581
+ signatures: bcs2.vector(bcs2.tuple([PublicKey, Signature]))
582
+ });
583
+ function hexToDecimal(hex) {
584
+ return BigInt(`0x${hex}`).toString();
585
+ }
586
+
587
+ // src/WarpFastsetWallet.ts
625
588
  var WarpFastsetWallet = class {
626
589
  constructor(config, chain) {
627
590
  this.config = config;
628
591
  this.chain = chain;
629
- this.wallet = null;
630
- const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
631
- if (privateKey) {
632
- this.wallet = new Wallet(privateKey);
633
- }
634
592
  this.client = getConfiguredFastsetClient(this.config, this.chain);
593
+ const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
594
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
595
+ this.privateKey = privateKey;
635
596
  }
636
597
  async signTransaction(tx) {
637
- if (!this.wallet) throw new Error("Wallet not initialized");
638
- const transaction = tx;
639
- const serializedTx = this.serializeTransaction(transaction.toTransaction());
640
- const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
641
- return Object.assign(transaction, { signature: uint8ArrayToHex(signature) });
598
+ const msg = Transaction.serialize(tx);
599
+ const msgBytes = msg.toBytes();
600
+ const prefix = new TextEncoder().encode("Transaction::");
601
+ const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
602
+ dataToSign.set(prefix, 0);
603
+ dataToSign.set(msgBytes, prefix.length);
604
+ const signature = ed.sign(dataToSign, this.privateKey);
605
+ return { ...tx, signature };
642
606
  }
643
607
  async signMessage(message) {
644
- if (!this.wallet) throw new Error("Wallet not initialized");
645
608
  const messageBytes = stringToUint8Array(message);
646
- const signature = await ed.sign(messageBytes, this.wallet.getPrivateKey());
609
+ const signature = ed.sign(messageBytes, this.privateKey);
647
610
  return uint8ArrayToHex(signature);
648
611
  }
649
612
  async sendTransaction(tx) {
650
- if (!this.wallet) throw new Error("Wallet not initialized");
651
- const transaction = tx;
652
- const fastsetTx = transaction.toTransaction();
653
- const transactionData = {
654
- sender: fastsetTx.sender,
655
- recipient: fastsetTx.recipient,
656
- nonce: fastsetTx.nonce,
657
- timestamp_nanos: fastsetTx.timestamp_nanos,
658
- claim: fastsetTx.claim
613
+ const { signature, ...transactionWithoutSignature } = tx;
614
+ const submitTxReq = {
615
+ transaction: transactionWithoutSignature,
616
+ signature
659
617
  };
660
- const signature = tx.signature ? hexToUint8Array(tx.signature) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
661
- return await this.client.submitTransaction(transactionData, signature);
618
+ const proxyUrl = getProviderUrl2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
619
+ const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
620
+ if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
621
+ console.log("submitTransaction response", response.result);
622
+ return "TODO";
662
623
  }
663
624
  create(mnemonic) {
664
625
  const seed = bip39.mnemonicToSeedSync(mnemonic);
665
626
  const privateKey = seed.slice(0, 32);
666
- const wallet = new Wallet(uint8ArrayToHex(privateKey));
667
- return { address: wallet.toBech32(), privateKey: uint8ArrayToHex(wallet.getPrivateKey()), mnemonic };
627
+ const publicKey = ed.getPublicKey(privateKey);
628
+ const address = FastsetClient.encodeBech32Address(publicKey);
629
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
668
630
  }
669
631
  generate() {
670
632
  const privateKey = ed.utils.randomPrivateKey();
671
- const wallet = new Wallet(uint8ArrayToHex(privateKey));
672
- return { address: wallet.toBech32(), privateKey: uint8ArrayToHex(wallet.getPrivateKey()), mnemonic: null };
633
+ const publicKey = ed.getPublicKey(privateKey);
634
+ const address = FastsetClient.encodeBech32Address(publicKey);
635
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
673
636
  }
674
637
  getAddress() {
675
638
  return getWarpWalletAddressFromConfig3(this.config, this.chain.name);
676
639
  }
677
- serializeTransaction(tx) {
678
- const serialized = JSON.stringify(tx, (k, v) => {
679
- if (v instanceof Uint8Array) return Array.from(v);
680
- if (typeof v === "bigint") return v.toString();
681
- return v;
682
- });
683
- return encoder.encode(serialized);
684
- }
685
640
  };
686
641
 
687
642
  // src/main.ts
@@ -690,7 +645,7 @@ var NativeTokenSet = {
690
645
  identifier: "SET",
691
646
  name: "SET",
692
647
  symbol: "SET",
693
- decimals: 6,
648
+ decimals: 0,
694
649
  logoUrl: "https://vleap.ai/images/tokens/set.svg"
695
650
  };
696
651
  function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
@@ -747,14 +702,8 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, "fastset", {
747
702
  nativeToken: NativeTokenSet
748
703
  }
749
704
  });
750
-
751
- // src/index.ts
752
- init_sdk();
753
705
  export {
754
- FastsetClient,
755
706
  NativeTokenSet,
756
- Transaction,
757
- Wallet,
758
707
  WarpFastsetExecutor,
759
708
  WarpFastsetWallet,
760
709
  getFastsetAdapter