@vleap/warps-adapter-fastset 0.1.0-alpha.23 → 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,186 +1,121 @@
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
- };
1
+ // src/main.ts
2
+ import { WarpChainName } from "@vleap/warps";
10
3
 
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
- });
4
+ // src/WarpFastsetDataLoader.ts
5
+ import * as bech323 from "bech32";
6
+
7
+ // src/helpers/encode.ts
8
+ var encoder = new TextEncoder();
9
+ var decoder = new TextDecoder();
10
+ function uint8ArrayToHex(uint8Array) {
11
+ return Buffer.from(uint8Array).toString("hex");
12
+ }
13
+ function stringToUint8Array(str) {
14
+ return new Uint8Array(Buffer.from(str, "utf8"));
15
+ }
16
+
17
+ // src/helpers/general.ts
18
+ import { getProviderUrl } from "@vleap/warps";
22
19
 
23
20
  // src/sdk/FastsetClient.ts
21
+ import { BCS, getSuiMoveConfig } from "@mysten/bcs";
24
22
  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
- }
23
+ BigInt.prototype.toJSON = function() {
24
+ return Number(this);
25
+ };
26
+ var bcs = new BCS(getSuiMoveConfig());
27
+ bcs.registerStructType("FastSetAddress", {
28
+ bytes: "vector<u8>"
156
29
  });
157
-
158
- // src/sdk/index.ts
159
- var sdk_exports = {};
160
- __export(sdk_exports, {
161
- FastsetClient: () => FastsetClient,
162
- Transaction: () => Transaction,
163
- Wallet: () => Wallet
30
+ bcs.registerStructType("ExternalAddress", {
31
+ bytes: "vector<u8>"
164
32
  });
165
- var init_sdk = __esm({
166
- "src/sdk/index.ts"() {
167
- "use strict";
168
- init_FastsetClient();
169
- }
33
+ bcs.registerEnumType("Address", {
34
+ FastSet: "FastSetAddress",
35
+ External: "ExternalAddress"
170
36
  });
171
-
172
- // src/main.ts
173
- import { WarpChainName } from "@vleap/warps";
174
-
175
- // src/WarpFastsetDataLoader.ts
176
- import * as bech323 from "bech32";
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
+ };
177
114
 
178
115
  // src/helpers/general.ts
179
- init_sdk();
180
- import { getProviderUrl } from "@vleap/warps";
181
116
  var getConfiguredFastsetClient = (config, chain) => {
182
117
  const proxyUrl = getProviderUrl(config, chain.name, config.env, chain.defaultApiUrl);
183
- return new FastsetClient({ proxyUrl });
118
+ return new FastsetClient(proxyUrl);
184
119
  };
185
120
 
186
121
  // src/WarpFastsetDataLoader.ts
@@ -193,17 +128,18 @@ var WarpFastsetDataLoader = class {
193
128
  async getAccount(address) {
194
129
  const addressBytes = this.addressToBytes(address);
195
130
  const accountInfo = await this.client.getAccountInfo(addressBytes);
196
- 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)) };
197
132
  }
198
133
  async getAccountAssets(address) {
199
134
  const addressBytes = this.addressToBytes(address);
200
135
  const accountInfo = await this.client.getAccountInfo(addressBytes);
201
136
  const assets = [];
202
- const balance = BigInt(parseInt(accountInfo.balance, 16));
137
+ console.log("accountInfo", accountInfo);
138
+ const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
203
139
  if (balance > 0n) {
204
140
  assets.push({ ...this.chain.nativeToken, amount: balance });
205
141
  }
206
- for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
142
+ for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
207
143
  const amount = BigInt(parseInt(tokenBalance, 16));
208
144
  if (amount > 0n) {
209
145
  const tokenInfo = await this.client.getTokenInfo([tokenId]);
@@ -261,7 +197,6 @@ var WarpFastsetDataLoader = class {
261
197
  };
262
198
 
263
199
  // src/WarpFastsetExecutor.ts
264
- init_sdk();
265
200
  import {
266
201
  getWarpActionByIndex,
267
202
  getWarpWalletAddressFromConfig
@@ -270,93 +205,39 @@ var WarpFastsetExecutor = class {
270
205
  constructor(config, chain) {
271
206
  this.config = config;
272
207
  this.chain = chain;
273
- this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
208
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
274
209
  }
275
210
  async createTransaction(executable) {
276
211
  const action = getWarpActionByIndex(executable.warp, executable.action);
277
212
  if (action.type === "transfer") return this.createTransferTransaction(executable);
278
213
  if (action.type === "contract") return this.createContractCallTransaction(executable);
279
- if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid type for createTransaction; Use executeQuery instead");
280
- if (action.type === "collect") throw new Error("WarpFastsetExecutor: Invalid type for createTransaction; Use executeCollect instead");
281
- throw new Error(`WarpFastsetExecutor: Invalid type (${action.type})`);
214
+ if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
215
+ if (action.type === "collect")
216
+ throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
217
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
282
218
  }
283
219
  async createTransferTransaction(executable) {
284
220
  const userWallet = getWarpWalletAddressFromConfig(this.config, executable.chain.name);
285
- if (!userWallet) throw new Error("WarpFastsetExecutor: User address not set");
286
- const senderAddress = FastsetClient.decodeBech32Address(userWallet);
287
- const recipientAddress = FastsetClient.decodeBech32Address(executable.destination);
288
- const nonce = await this.fastsetClient.getNextNonce(userWallet);
289
- const amount = executable.transfers?.[0]?.amount ? "0x" + executable.transfers[0].amount.toString(16) : executable.value.toString();
290
- const userData = executable.data ? this.fromBase64(executable.data) : null;
291
- const claim = { Transfer: { amount, user_data: userData } };
292
- return new Transaction(senderAddress, { FastSet: recipientAddress }, nonce, claim);
293
- }
294
- async createContractCallTransaction(executable) {
295
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
296
- if (!userWallet) throw new Error("WarpFastsetExecutor: User address not set");
297
- const action = getWarpActionByIndex(executable.warp, executable.action);
298
- if (!action || !("func" in action) || !action.func) throw new Error("Contract action must have function name");
221
+ if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
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);
299
228
  return {
300
- type: "fastset-contract-call",
301
- contract: this.fromBase64(executable.destination),
302
- function: action.func,
303
- data: JSON.stringify({ function: action.func, arguments: executable.args }),
304
- value: executable.value,
305
- chain: executable.chain
306
- };
307
- }
308
- async executeQuery(executable) {
309
- const action = getWarpActionByIndex(executable.warp, executable.action);
310
- if (action.type !== "query") throw new Error(`Invalid action type for executeQuery: ${action.type}`);
311
- try {
312
- const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
313
- return { success: true, result, chain: executable.chain };
314
- } catch (error) {
315
- return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
316
- }
317
- }
318
- async executeTransfer(executable) {
319
- const transaction = await this.createTransferTransaction(executable);
320
- return { success: true, transaction, chain: executable.chain.name };
321
- }
322
- async executeTransferWithKey(executable, privateKey) {
323
- const transaction = await this.createTransferTransaction(executable);
324
- const privateKeyBytes = this.fromBase64(privateKey);
325
- const transactionData = {
326
- sender: privateKeyBytes.slice(0, 32),
327
- recipient: transaction.getRecipientAddress(),
328
- nonce: await this.fastsetClient.getNextNonce(FastsetClient.encodeBech32Address(privateKeyBytes.slice(0, 32))),
229
+ sender: senderPubKey,
230
+ recipient: { FastSet: recipientPubKey },
231
+ nonce,
329
232
  timestamp_nanos: BigInt(Date.now()) * 1000000n,
330
- claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
233
+ claim: { Transfer: { amount: amountHex, user_data: null } }
331
234
  };
332
- const signature = await this.signTransaction(transactionData, privateKeyBytes);
333
- const result = await this.fastsetClient.submitTransaction(transactionData, signature);
334
- return { success: true, result, message: "Transaction submitted successfully", chain: executable.chain.name };
335
- }
336
- async signTransaction(transaction, privateKey) {
337
- const wallet = new (await Promise.resolve().then(() => (init_sdk(), sdk_exports))).Wallet(Buffer.from(privateKey).toString("hex"));
338
- return wallet.signTransactionRaw(this.serializeTransaction(transaction));
339
- }
340
- serializeTransaction(tx) {
341
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
342
- return new TextEncoder().encode(serialized);
343
- }
344
- async executeFastsetQuery(contractAddress, functionName, args) {
345
- const response = await fetch("https://proxy.fastset.xyz", {
346
- method: "POST",
347
- headers: { "Content-Type": "application/json" },
348
- body: JSON.stringify({
349
- jsonrpc: "2.0",
350
- method: "set_proxy_query",
351
- params: { contract: Array.from(contractAddress), function: functionName, arguments: args },
352
- id: 1
353
- })
354
- });
355
- if (!response.ok) throw new Error(`Query failed: ${response.statusText}`);
356
- return response.json();
357
235
  }
358
- fromBase64(base64) {
359
- 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");
360
241
  }
361
242
  };
362
243
 
@@ -587,67 +468,175 @@ var WarpFastsetResults = class {
587
468
  };
588
469
 
589
470
  // src/WarpFastsetWallet.ts
471
+ import * as bip39 from "@scure/bip39";
590
472
  import {
591
- getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3
473
+ getProviderUrl as getProviderUrl2,
474
+ getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3,
475
+ getWarpWalletPrivateKeyFromConfig
592
476
  } from "@vleap/warps";
593
- init_sdk();
594
- 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
595
588
  var WarpFastsetWallet = class {
596
589
  constructor(config, chain) {
597
590
  this.config = config;
598
591
  this.chain = chain;
599
- this.wallet = null;
600
- this.initializeWallet();
601
592
  this.client = getConfiguredFastsetClient(this.config, this.chain);
602
- }
603
- initializeWallet() {
604
- const walletConfig = this.config.user?.wallets?.[this.chain.name];
605
- if (walletConfig && typeof walletConfig === "object" && "privateKey" in walletConfig && walletConfig.privateKey) {
606
- this.wallet = new Wallet(walletConfig.privateKey);
607
- }
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;
608
596
  }
609
597
  async signTransaction(tx) {
610
- if (!this.wallet) throw new Error("Wallet not initialized");
611
- const transaction = tx;
612
- const serializedTx = this.serializeTransaction(transaction.toTransaction());
613
- const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
614
- return Object.assign(transaction, { 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 };
615
606
  }
616
607
  async signMessage(message) {
617
- if (!this.wallet) throw new Error("Wallet not initialized");
618
- const signature = await ed.sign(new TextEncoder().encode(message), this.wallet.getPrivateKey());
619
- return Buffer.from(signature).toString("hex");
608
+ const messageBytes = stringToUint8Array(message);
609
+ const signature = ed.sign(messageBytes, this.privateKey);
610
+ return uint8ArrayToHex(signature);
620
611
  }
621
612
  async sendTransaction(tx) {
622
- if (!this.wallet) throw new Error("Wallet not initialized");
623
- const transaction = tx;
624
- const fastsetTx = transaction.toTransaction();
625
- const transactionData = {
626
- sender: fastsetTx.sender,
627
- recipient: fastsetTx.recipient,
628
- nonce: fastsetTx.nonce,
629
- timestamp_nanos: fastsetTx.timestamp_nanos,
630
- claim: fastsetTx.claim
613
+ const { signature, ...transactionWithoutSignature } = tx;
614
+ const submitTxReq = {
615
+ transaction: transactionWithoutSignature,
616
+ signature
631
617
  };
632
- const signature = tx.signature ? new Uint8Array(Buffer.from(tx.signature, "hex")) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
633
- 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";
634
623
  }
635
624
  create(mnemonic) {
636
- const wallet = new Wallet(mnemonic);
637
- return { address: wallet.toBech32(), privateKey: Buffer.from(wallet.getPrivateKey()).toString("hex"), mnemonic };
625
+ const seed = bip39.mnemonicToSeedSync(mnemonic);
626
+ const privateKey = seed.slice(0, 32);
627
+ const publicKey = ed.getPublicKey(privateKey);
628
+ const address = FastsetClient.encodeBech32Address(publicKey);
629
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
638
630
  }
639
631
  generate() {
640
632
  const privateKey = ed.utils.randomPrivateKey();
641
- const wallet = new Wallet(Buffer.from(privateKey).toString("hex"));
642
- return { address: wallet.toBech32(), privateKey: Buffer.from(privateKey).toString("hex"), mnemonic: null };
633
+ const publicKey = ed.getPublicKey(privateKey);
634
+ const address = FastsetClient.encodeBech32Address(publicKey);
635
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
643
636
  }
644
637
  getAddress() {
645
638
  return getWarpWalletAddressFromConfig3(this.config, this.chain.name);
646
639
  }
647
- serializeTransaction(tx) {
648
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
649
- return new TextEncoder().encode(serialized);
650
- }
651
640
  };
652
641
 
653
642
  // src/main.ts
@@ -656,7 +645,7 @@ var NativeTokenSet = {
656
645
  identifier: "SET",
657
646
  name: "SET",
658
647
  symbol: "SET",
659
- decimals: 6,
648
+ decimals: 0,
660
649
  logoUrl: "https://vleap.ai/images/tokens/set.svg"
661
650
  };
662
651
  function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
@@ -713,14 +702,8 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, "fastset", {
713
702
  nativeToken: NativeTokenSet
714
703
  }
715
704
  });
716
-
717
- // src/index.ts
718
- init_sdk();
719
705
  export {
720
- FastsetClient,
721
706
  NativeTokenSet,
722
- Transaction,
723
- Wallet,
724
707
  WarpFastsetExecutor,
725
708
  WarpFastsetWallet,
726
709
  getFastsetAdapter