@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.js CHANGED
@@ -5,9 +5,6 @@ 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
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -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
@@ -211,12 +43,118 @@ var import_warps6 = require("@vleap/warps");
211
43
  // src/WarpFastsetDataLoader.ts
212
44
  var bech323 = __toESM(require("bech32"), 1);
213
45
 
46
+ // src/helpers/encode.ts
47
+ var encoder = new TextEncoder();
48
+ var decoder = new TextDecoder();
49
+ function uint8ArrayToHex(uint8Array) {
50
+ return Buffer.from(uint8Array).toString("hex");
51
+ }
52
+ function stringToUint8Array(str) {
53
+ return new Uint8Array(Buffer.from(str, "utf8"));
54
+ }
55
+
214
56
  // src/helpers/general.ts
215
57
  var import_warps = require("@vleap/warps");
216
- init_sdk();
58
+
59
+ // src/sdk/FastsetClient.ts
60
+ var import_bcs = require("@mysten/bcs");
61
+ var bech32 = __toESM(require("bech32"), 1);
62
+ BigInt.prototype.toJSON = function() {
63
+ return Number(this);
64
+ };
65
+ var bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
66
+ bcs.registerStructType("FastSetAddress", {
67
+ bytes: "vector<u8>"
68
+ });
69
+ bcs.registerStructType("ExternalAddress", {
70
+ bytes: "vector<u8>"
71
+ });
72
+ bcs.registerEnumType("Address", {
73
+ FastSet: "FastSetAddress",
74
+ External: "ExternalAddress"
75
+ });
76
+ bcs.registerEnumType("UserDataOption", {
77
+ Some: "vector<u8>",
78
+ None: "bool"
79
+ // Use bool for None variant (false = None)
80
+ });
81
+ bcs.registerStructType("TransferClaim", {
82
+ amount: "u256",
83
+ // 256-bit unsigned integer
84
+ user_data: "UserDataOption"
85
+ // Use our custom option type
86
+ });
87
+ bcs.registerStructType("ClaimType", {
88
+ Transfer: "TransferClaim"
89
+ });
90
+ bcs.registerStructType("Transaction", {
91
+ sender: "vector<u8>",
92
+ // 32 bytes
93
+ recipient: "Address",
94
+ nonce: "u64",
95
+ timestamp_nanos: "u128",
96
+ claim: "ClaimType"
97
+ });
98
+ var id = 0;
99
+ var FastsetClient = class {
100
+ constructor(proxyUrl) {
101
+ this.proxyUrl = proxyUrl;
102
+ }
103
+ async request(url, method, params) {
104
+ const request = this.buildJsonRpcRequest(id++, method, params);
105
+ const headers = { "Content-Type": "application/json" };
106
+ const body = this.jsonSerialize(request);
107
+ const response = await fetch(url, { method: "POST", headers, body });
108
+ const json = await response.json();
109
+ return json;
110
+ }
111
+ buildJsonRpcRequest(id2, method, params) {
112
+ return { jsonrpc: "2.0", id: id2, method, params };
113
+ }
114
+ jsonSerialize(data) {
115
+ return JSON.stringify(data, (k, v) => {
116
+ if (v instanceof Uint8Array) {
117
+ return Array.from(v);
118
+ }
119
+ return v;
120
+ });
121
+ }
122
+ async getAccountInfo(address) {
123
+ return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
124
+ }
125
+ async getNextNonce(address) {
126
+ const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
127
+ const accountInfoRes = await this.getAccountInfo(addressBytes);
128
+ return accountInfoRes.result?.next_nonce ?? 0;
129
+ }
130
+ addressToBytes(address) {
131
+ try {
132
+ const decoded = bech32.bech32m.decode(address);
133
+ return Array.from(bech32.bech32m.fromWords(decoded.words));
134
+ } catch {
135
+ const decoded = bech32.bech32.decode(address);
136
+ return Array.from(bech32.bech32.fromWords(decoded.words));
137
+ }
138
+ }
139
+ static decodeBech32Address(address) {
140
+ try {
141
+ const decoded = bech32.bech32m.decode(address);
142
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
143
+ } catch {
144
+ const decoded = bech32.bech32.decode(address);
145
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
146
+ }
147
+ }
148
+ static encodeBech32Address(publicKey) {
149
+ const words = bech32.bech32m.toWords(publicKey);
150
+ return bech32.bech32m.encode("set", words);
151
+ }
152
+ };
153
+
154
+ // src/helpers/general.ts
217
155
  var getConfiguredFastsetClient = (config, chain) => {
218
156
  const proxyUrl = (0, import_warps.getProviderUrl)(config, chain.name, config.env, chain.defaultApiUrl);
219
- return new FastsetClient({ proxyUrl });
157
+ return new FastsetClient(proxyUrl);
220
158
  };
221
159
 
222
160
  // src/WarpFastsetDataLoader.ts
@@ -229,17 +167,18 @@ var WarpFastsetDataLoader = class {
229
167
  async getAccount(address) {
230
168
  const addressBytes = this.addressToBytes(address);
231
169
  const accountInfo = await this.client.getAccountInfo(addressBytes);
232
- return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.balance, 16)) };
170
+ return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
233
171
  }
234
172
  async getAccountAssets(address) {
235
173
  const addressBytes = this.addressToBytes(address);
236
174
  const accountInfo = await this.client.getAccountInfo(addressBytes);
237
175
  const assets = [];
238
- const balance = BigInt(parseInt(accountInfo.balance, 16));
176
+ console.log("accountInfo", accountInfo);
177
+ const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
239
178
  if (balance > 0n) {
240
179
  assets.push({ ...this.chain.nativeToken, amount: balance });
241
180
  }
242
- for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
181
+ for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
243
182
  const amount = BigInt(parseInt(tokenBalance, 16));
244
183
  if (amount > 0n) {
245
184
  const tokenInfo = await this.client.getTokenInfo([tokenId]);
@@ -298,98 +237,43 @@ var WarpFastsetDataLoader = class {
298
237
 
299
238
  // src/WarpFastsetExecutor.ts
300
239
  var import_warps2 = require("@vleap/warps");
301
- init_sdk();
302
240
  var WarpFastsetExecutor = class {
303
241
  constructor(config, chain) {
304
242
  this.config = config;
305
243
  this.chain = chain;
306
- this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
244
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
307
245
  }
308
246
  async createTransaction(executable) {
309
247
  const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
310
248
  if (action.type === "transfer") return this.createTransferTransaction(executable);
311
249
  if (action.type === "contract") return this.createContractCallTransaction(executable);
312
- if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid type for createTransaction; Use executeQuery instead");
313
- if (action.type === "collect") throw new Error("WarpFastsetExecutor: Invalid type for createTransaction; Use executeCollect instead");
314
- throw new Error(`WarpFastsetExecutor: Invalid type (${action.type})`);
250
+ if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
251
+ if (action.type === "collect")
252
+ throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
253
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
315
254
  }
316
255
  async createTransferTransaction(executable) {
317
256
  const userWallet = (0, import_warps2.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
318
- if (!userWallet) throw new Error("WarpFastsetExecutor: User address not set");
319
- const senderAddress = FastsetClient.decodeBech32Address(userWallet);
320
- const recipientAddress = FastsetClient.decodeBech32Address(executable.destination);
321
- const nonce = await this.fastsetClient.getNextNonce(userWallet);
322
- const amount = executable.transfers?.[0]?.amount ? "0x" + executable.transfers[0].amount.toString(16) : executable.value.toString();
323
- const userData = executable.data ? this.fromBase64(executable.data) : null;
324
- const claim = { Transfer: { amount, user_data: userData } };
325
- return new Transaction(senderAddress, { FastSet: recipientAddress }, nonce, claim);
326
- }
327
- async createContractCallTransaction(executable) {
328
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
329
- if (!userWallet) throw new Error("WarpFastsetExecutor: User address not set");
330
- const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
331
- if (!action || !("func" in action) || !action.func) throw new Error("Contract action must have function name");
257
+ if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
258
+ const senderPubKey = FastsetClient.decodeBech32Address(userWallet);
259
+ const recipientPubKey = FastsetClient.decodeBech32Address(executable.destination);
260
+ const nonce = await this.client.getNextNonce(userWallet);
261
+ const nativeAmountInTransfers = executable.transfers.find((transfer) => transfer.identifier === this.chain.nativeToken?.identifier)?.amount || 0n;
262
+ const nativeAmountTotal = nativeAmountInTransfers + executable.value;
263
+ const amountHex = BigInt(nativeAmountTotal).toString(16);
332
264
  return {
333
- type: "fastset-contract-call",
334
- contract: this.fromBase64(executable.destination),
335
- function: action.func,
336
- data: JSON.stringify({ function: action.func, arguments: executable.args }),
337
- value: executable.value,
338
- chain: executable.chain
339
- };
340
- }
341
- async executeQuery(executable) {
342
- const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
343
- if (action.type !== "query") throw new Error(`Invalid action type for executeQuery: ${action.type}`);
344
- try {
345
- const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
346
- return { success: true, result, chain: executable.chain };
347
- } catch (error) {
348
- return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
349
- }
350
- }
351
- async executeTransfer(executable) {
352
- const transaction = await this.createTransferTransaction(executable);
353
- return { success: true, transaction, chain: executable.chain.name };
354
- }
355
- async executeTransferWithKey(executable, privateKey) {
356
- const transaction = await this.createTransferTransaction(executable);
357
- const privateKeyBytes = this.fromBase64(privateKey);
358
- const transactionData = {
359
- sender: privateKeyBytes.slice(0, 32),
360
- recipient: transaction.getRecipientAddress(),
361
- nonce: await this.fastsetClient.getNextNonce(FastsetClient.encodeBech32Address(privateKeyBytes.slice(0, 32))),
265
+ sender: senderPubKey,
266
+ recipient: { FastSet: recipientPubKey },
267
+ nonce,
362
268
  timestamp_nanos: BigInt(Date.now()) * 1000000n,
363
- claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
269
+ claim: { Transfer: { amount: amountHex, user_data: null } }
364
270
  };
365
- const signature = await this.signTransaction(transactionData, privateKeyBytes);
366
- const result = await this.fastsetClient.submitTransaction(transactionData, signature);
367
- return { success: true, result, message: "Transaction submitted successfully", chain: executable.chain.name };
368
- }
369
- async signTransaction(transaction, privateKey) {
370
- const wallet = new (await Promise.resolve().then(() => (init_sdk(), sdk_exports))).Wallet(Buffer.from(privateKey).toString("hex"));
371
- return wallet.signTransactionRaw(this.serializeTransaction(transaction));
372
- }
373
- serializeTransaction(tx) {
374
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
375
- return new TextEncoder().encode(serialized);
376
- }
377
- async executeFastsetQuery(contractAddress, functionName, args) {
378
- const response = await fetch("https://proxy.fastset.xyz", {
379
- method: "POST",
380
- headers: { "Content-Type": "application/json" },
381
- body: JSON.stringify({
382
- jsonrpc: "2.0",
383
- method: "set_proxy_query",
384
- params: { contract: Array.from(contractAddress), function: functionName, arguments: args },
385
- id: 1
386
- })
387
- });
388
- if (!response.ok) throw new Error(`Query failed: ${response.statusText}`);
389
- return response.json();
390
271
  }
391
- fromBase64(base64) {
392
- return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
272
+ async createContractCallTransaction(executable) {
273
+ throw new Error("WarpFastsetExecutor: Not implemented");
274
+ }
275
+ async executeQuery(executable) {
276
+ throw new Error("WarpFastsetExecutor: Not implemented");
393
277
  }
394
278
  };
395
279
 
@@ -613,65 +497,171 @@ var WarpFastsetResults = class {
613
497
  };
614
498
 
615
499
  // src/WarpFastsetWallet.ts
500
+ var bip39 = __toESM(require("@scure/bip39"), 1);
616
501
  var import_warps5 = require("@vleap/warps");
617
- init_sdk();
618
- init_ed25519_setup();
502
+
503
+ // src/sdk/ed25519-setup.ts
504
+ var ed = __toESM(require("@noble/ed25519"), 1);
505
+ var import_sha512 = require("@noble/hashes/sha512");
506
+ if (ed.etc) {
507
+ ed.etc.sha512Sync = (...m) => (0, import_sha512.sha512)(ed.etc.concatBytes(...m));
508
+ }
509
+
510
+ // src/sdk/types.ts
511
+ var import_bcs2 = require("@mysten/bcs");
512
+ BigInt.prototype.toJSON = function() {
513
+ return Number(this);
514
+ };
515
+ var Bytes32 = import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8());
516
+ var Bytes64 = import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8());
517
+ var PublicKey = Bytes32;
518
+ var Signature = Bytes64;
519
+ var Address = import_bcs2.bcs.enum("Address", {
520
+ External: PublicKey,
521
+ FastSet: PublicKey
522
+ });
523
+ var Amount = import_bcs2.bcs.u256().transform({
524
+ // CAUTION: When we build a transaction object, we must use a hex encoded string because the
525
+ // validator expects amounts to be in hex. However, bcs.u256() by default expects a decimal
526
+ // string. Therefore, we must transform the input amount from hex to decimal here.
527
+ input: (val) => hexToDecimal(val.toString()),
528
+ output: (value) => value
529
+ });
530
+ var Balance = import_bcs2.bcs.string().transform({
531
+ input: (val) => val,
532
+ output: (value) => value
533
+ });
534
+ var UserData = import_bcs2.bcs.option(Bytes32);
535
+ var Nonce = import_bcs2.bcs.u64();
536
+ var Quorum = import_bcs2.bcs.u64();
537
+ var TokenId = Bytes32;
538
+ var Transfer = import_bcs2.bcs.struct("Transfer", {
539
+ amount: Amount,
540
+ user_data: UserData
541
+ });
542
+ var TokenTransfer = import_bcs2.bcs.struct("TokenTransfer", {
543
+ token_id: TokenId,
544
+ amount: Amount,
545
+ user_data: UserData
546
+ });
547
+ var TokenCreation = import_bcs2.bcs.struct("TokenCreation", {
548
+ token_name: import_bcs2.bcs.string(),
549
+ decimals: import_bcs2.bcs.u8(),
550
+ initial_amount: Amount,
551
+ mints: import_bcs2.bcs.vector(PublicKey),
552
+ user_data: UserData
553
+ });
554
+ var AddressChange = import_bcs2.bcs.enum("AddressChange", {
555
+ Add: PublicKey,
556
+ Remove: PublicKey
557
+ });
558
+ var TokenManagement = import_bcs2.bcs.struct("TokenManagement", {
559
+ token_id: TokenId,
560
+ update_id: Nonce,
561
+ new_admin: import_bcs2.bcs.option(PublicKey),
562
+ mints: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([AddressChange, PublicKey])),
563
+ user_data: UserData
564
+ });
565
+ var Mint = import_bcs2.bcs.struct("Mint", {
566
+ token_id: TokenId,
567
+ amount: Amount
568
+ });
569
+ var ClaimData = import_bcs2.bcs.vector(import_bcs2.bcs.u8());
570
+ var ExternalClaimBody = import_bcs2.bcs.struct("ExternalClaimBody", {
571
+ verifier_committee: import_bcs2.bcs.vector(PublicKey),
572
+ verifier_quorum: Quorum,
573
+ claim_data: ClaimData
574
+ });
575
+ var ExternalClaim = import_bcs2.bcs.struct("ExternalClaim", {
576
+ claim: ExternalClaimBody,
577
+ signatures: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([PublicKey, Signature]))
578
+ });
579
+ var ClaimType = import_bcs2.bcs.enum("ClaimType", {
580
+ Transfer,
581
+ TokenTransfer,
582
+ TokenCreation,
583
+ TokenManagement,
584
+ Mint,
585
+ ExternalClaim
586
+ });
587
+ var Transaction = import_bcs2.bcs.struct("Transaction", {
588
+ sender: PublicKey,
589
+ recipient: Address,
590
+ nonce: Nonce,
591
+ timestamp_nanos: import_bcs2.bcs.u128(),
592
+ claim: ClaimType
593
+ });
594
+ var SubmitTransactionResponse = import_bcs2.bcs.struct("SubmitTransactionResponse", {
595
+ validator: PublicKey,
596
+ signature: Signature,
597
+ next_nonce: Nonce,
598
+ transaction_hash: import_bcs2.bcs.vector(import_bcs2.bcs.u8())
599
+ });
600
+ var TransactionEnvelope = import_bcs2.bcs.struct("TransactionEnvelope", {
601
+ transaction: Transaction,
602
+ signature: Signature
603
+ });
604
+ var TransactionCertificate = import_bcs2.bcs.struct("TransactionCertificate", {
605
+ envelope: TransactionEnvelope,
606
+ signatures: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([PublicKey, Signature]))
607
+ });
608
+ function hexToDecimal(hex) {
609
+ return BigInt(`0x${hex}`).toString();
610
+ }
611
+
612
+ // src/WarpFastsetWallet.ts
619
613
  var WarpFastsetWallet = class {
620
614
  constructor(config, chain) {
621
615
  this.config = config;
622
616
  this.chain = chain;
623
- this.wallet = null;
624
- this.initializeWallet();
625
617
  this.client = getConfiguredFastsetClient(this.config, this.chain);
626
- }
627
- initializeWallet() {
628
- const walletConfig = this.config.user?.wallets?.[this.chain.name];
629
- if (walletConfig && typeof walletConfig === "object" && "privateKey" in walletConfig && walletConfig.privateKey) {
630
- this.wallet = new Wallet(walletConfig.privateKey);
631
- }
618
+ const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
619
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
620
+ this.privateKey = privateKey;
632
621
  }
633
622
  async signTransaction(tx) {
634
- if (!this.wallet) throw new Error("Wallet not initialized");
635
- const transaction = tx;
636
- const serializedTx = this.serializeTransaction(transaction.toTransaction());
637
- const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
638
- return Object.assign(transaction, { signature });
623
+ const msg = Transaction.serialize(tx);
624
+ const msgBytes = msg.toBytes();
625
+ const prefix = new TextEncoder().encode("Transaction::");
626
+ const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
627
+ dataToSign.set(prefix, 0);
628
+ dataToSign.set(msgBytes, prefix.length);
629
+ const signature = ed.sign(dataToSign, this.privateKey);
630
+ return { ...tx, signature };
639
631
  }
640
632
  async signMessage(message) {
641
- if (!this.wallet) throw new Error("Wallet not initialized");
642
- const signature = await ed.sign(new TextEncoder().encode(message), this.wallet.getPrivateKey());
643
- return Buffer.from(signature).toString("hex");
633
+ const messageBytes = stringToUint8Array(message);
634
+ const signature = ed.sign(messageBytes, this.privateKey);
635
+ return uint8ArrayToHex(signature);
644
636
  }
645
637
  async sendTransaction(tx) {
646
- if (!this.wallet) throw new Error("Wallet not initialized");
647
- const transaction = tx;
648
- const fastsetTx = transaction.toTransaction();
649
- const transactionData = {
650
- sender: fastsetTx.sender,
651
- recipient: fastsetTx.recipient,
652
- nonce: fastsetTx.nonce,
653
- timestamp_nanos: fastsetTx.timestamp_nanos,
654
- claim: fastsetTx.claim
638
+ const { signature, ...transactionWithoutSignature } = tx;
639
+ const submitTxReq = {
640
+ transaction: transactionWithoutSignature,
641
+ signature
655
642
  };
656
- const signature = tx.signature ? new Uint8Array(Buffer.from(tx.signature, "hex")) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
657
- return await this.client.submitTransaction(transactionData, signature);
643
+ const proxyUrl = (0, import_warps5.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
644
+ const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
645
+ if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
646
+ console.log("submitTransaction response", response.result);
647
+ return "TODO";
658
648
  }
659
649
  create(mnemonic) {
660
- const wallet = new Wallet(mnemonic);
661
- return { address: wallet.toBech32(), privateKey: Buffer.from(wallet.getPrivateKey()).toString("hex"), mnemonic };
650
+ const seed = bip39.mnemonicToSeedSync(mnemonic);
651
+ const privateKey = seed.slice(0, 32);
652
+ const publicKey = ed.getPublicKey(privateKey);
653
+ const address = FastsetClient.encodeBech32Address(publicKey);
654
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
662
655
  }
663
656
  generate() {
664
657
  const privateKey = ed.utils.randomPrivateKey();
665
- const wallet = new Wallet(Buffer.from(privateKey).toString("hex"));
666
- return { address: wallet.toBech32(), privateKey: Buffer.from(privateKey).toString("hex"), mnemonic: null };
658
+ const publicKey = ed.getPublicKey(privateKey);
659
+ const address = FastsetClient.encodeBech32Address(publicKey);
660
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
667
661
  }
668
662
  getAddress() {
669
663
  return (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
670
664
  }
671
- serializeTransaction(tx) {
672
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
673
- return new TextEncoder().encode(serialized);
674
- }
675
665
  };
676
666
 
677
667
  // src/main.ts
@@ -680,7 +670,7 @@ var NativeTokenSet = {
680
670
  identifier: "SET",
681
671
  name: "SET",
682
672
  symbol: "SET",
683
- decimals: 6,
673
+ decimals: 0,
684
674
  logoUrl: "https://vleap.ai/images/tokens/set.svg"
685
675
  };
686
676
  function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
@@ -737,15 +727,9 @@ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset
737
727
  nativeToken: NativeTokenSet
738
728
  }
739
729
  });
740
-
741
- // src/index.ts
742
- init_sdk();
743
730
  // Annotate the CommonJS export names for ESM import in node:
744
731
  0 && (module.exports = {
745
- FastsetClient,
746
732
  NativeTokenSet,
747
- Transaction,
748
- Wallet,
749
733
  WarpFastsetExecutor,
750
734
  WarpFastsetWallet,
751
735
  getFastsetAdapter