@vleap/warps-adapter-fastset 0.1.0-alpha.20 → 0.1.0-alpha.21

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,7 +1,173 @@
1
- // src/constants.ts
2
- var WarpFastsetConstants = {
3
- // Placeholder for future FastSet-specific constants
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;
4
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
+ });
5
171
 
6
172
  // src/main.ts
7
173
  import { WarpChainName } from "@vleap/warps";
@@ -9,152 +175,12 @@ import { WarpChainName } from "@vleap/warps";
9
175
  // src/WarpFastsetDataLoader.ts
10
176
  import * as bech323 from "bech32";
11
177
 
12
- // src/sdk/FastsetClient.ts
13
- import { bcs } from "@mysten/bcs";
14
- import * as bech32 from "bech32";
15
- var bcsTransaction = bcs.struct("Transaction", {
16
- sender: bcs.fixedArray(32, bcs.u8()),
17
- recipient: bcs.enum("Address", {
18
- External: bcs.fixedArray(32, bcs.u8()),
19
- FastSet: bcs.fixedArray(32, bcs.u8())
20
- }),
21
- nonce: bcs.u64(),
22
- timestamp_nanos: bcs.u128(),
23
- claim: bcs.enum("ClaimType", {
24
- Transfer: bcs.struct("Transfer", {
25
- recipient: bcs.enum("Address", {
26
- External: bcs.fixedArray(32, bcs.u8()),
27
- FastSet: bcs.fixedArray(32, bcs.u8())
28
- }),
29
- amount: bcs.string(),
30
- user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
31
- }),
32
- TokenTransfer: bcs.struct("TokenTransfer", {
33
- token_id: bcs.fixedArray(32, bcs.u8()),
34
- amount: bcs.string(),
35
- user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
36
- }),
37
- TokenCreation: bcs.struct("TokenCreation", {
38
- token_name: bcs.string(),
39
- decimals: bcs.u8(),
40
- initial_amount: bcs.string(),
41
- mints: bcs.vector(bcs.fixedArray(32, bcs.u8())),
42
- user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
43
- }),
44
- TokenManagement: bcs.struct("TokenManagement", {
45
- token_id: bcs.fixedArray(32, bcs.u8()),
46
- update_id: bcs.u64(),
47
- new_admin: bcs.option(bcs.fixedArray(32, bcs.u8())),
48
- mints: bcs.vector(
49
- bcs.tuple([
50
- bcs.enum("AddressChange", {
51
- Add: bcs.fixedArray(32, bcs.u8()),
52
- Remove: bcs.fixedArray(32, bcs.u8())
53
- }),
54
- bcs.fixedArray(32, bcs.u8())
55
- ])
56
- ),
57
- user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
58
- }),
59
- Mint: bcs.struct("Mint", {
60
- token_id: bcs.fixedArray(32, bcs.u8()),
61
- amount: bcs.string()
62
- }),
63
- ExternalClaim: bcs.struct("ExternalClaim", {
64
- claim: bcs.struct("ExternalClaimBody", {
65
- verifier_committee: bcs.vector(bcs.fixedArray(32, bcs.u8())),
66
- verifier_quorum: bcs.u64(),
67
- claim_data: bcs.vector(bcs.u8())
68
- }),
69
- signatures: bcs.vector(bcs.tuple([bcs.fixedArray(32, bcs.u8()), bcs.fixedArray(64, bcs.u8())]))
70
- })
71
- })
72
- });
73
- var FastsetClient = class {
74
- constructor(config, chain) {
75
- if (config && "proxyUrl" in config) {
76
- this.apiUrl = config.proxyUrl;
77
- } else if (config && chain) {
78
- this.apiUrl = chain.defaultApiUrl;
79
- } else {
80
- this.apiUrl = "https://rpc.fastset.xyz";
81
- }
82
- }
83
- async makeRequest(method, params = {}) {
84
- const response = await fetch(this.apiUrl, {
85
- method: "POST",
86
- headers: {
87
- "Content-Type": "application/json"
88
- },
89
- body: JSON.stringify({
90
- jsonrpc: "2.0",
91
- method,
92
- params,
93
- id: Date.now()
94
- })
95
- });
96
- if (!response.ok) {
97
- throw new Error(`HTTP error! status: ${response.status}`);
98
- }
99
- const jsonResponse = await response.json();
100
- if (jsonResponse.error) {
101
- throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
102
- }
103
- return jsonResponse.result;
104
- }
105
- async getAccountInfo(address, token_balance_filter, certificate_by_nonce) {
106
- return this.makeRequest("set_getAccountInfo", {
107
- address,
108
- token_balance_filter,
109
- certificate_by_nonce
110
- });
111
- }
112
- async getTokenInfo(token_ids) {
113
- return this.makeRequest("set_getTokenInfo", {
114
- token_ids
115
- });
116
- }
117
- async getTransfers(page) {
118
- return this.makeRequest("set_getTransfers", { page });
119
- }
120
- async getClaims(confirmed, page) {
121
- return this.makeRequest("set_getClaims", { confirmed, page });
122
- }
123
- async getClaimsByAddress(address, page) {
124
- return this.makeRequest("set_getClaimsByAddress", {
125
- address,
126
- page
127
- });
128
- }
129
- async getNextNonce(address) {
130
- if (typeof address === "string") {
131
- const addressBytes = this.addressToBytes(address);
132
- const accountInfo2 = await this.getAccountInfo(addressBytes);
133
- return accountInfo2.next_nonce;
134
- }
135
- const accountInfo = await this.getAccountInfo(address);
136
- return accountInfo.next_nonce;
137
- }
138
- async submitTransaction(transaction, signature) {
139
- const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
140
- return this.makeRequest("set_submitTransaction", {
141
- transaction,
142
- signature: signatureArray
143
- });
144
- }
145
- addressToBytes(address) {
146
- try {
147
- const decoded = bech32.bech32m.decode(address);
148
- return Array.from(bech32.bech32m.fromWords(decoded.words));
149
- } catch {
150
- try {
151
- const decoded = bech32.bech32.decode(address);
152
- return Array.from(bech32.bech32.fromWords(decoded.words));
153
- } catch {
154
- throw new Error(`Invalid FastSet address: ${address}`);
155
- }
156
- }
157
- }
178
+ // src/helpers/general.ts
179
+ init_sdk();
180
+ import { getProviderUrl } from "@vleap/warps";
181
+ var getConfiguredFastsetClient = (config, chain) => {
182
+ const proxyUrl = getProviderUrl(config, chain.name, config.env, chain.defaultApiUrl);
183
+ return new FastsetClient({ proxyUrl });
158
184
  };
159
185
 
160
186
  // src/WarpFastsetDataLoader.ts
@@ -162,36 +188,23 @@ var WarpFastsetDataLoader = class {
162
188
  constructor(config, chain) {
163
189
  this.config = config;
164
190
  this.chain = chain;
165
- this.client = new FastsetClient(config, chain);
166
- }
167
- addressToBytes(address) {
168
- try {
169
- const decoded = bech323.bech32m.decode(address);
170
- return Array.from(bech323.bech32m.fromWords(decoded.words));
171
- } catch {
172
- try {
173
- const decoded = bech323.bech32.decode(address);
174
- return Array.from(bech323.bech32.fromWords(decoded.words));
175
- } catch {
176
- throw new Error(`Invalid FastSet address: ${address}`);
177
- }
178
- }
191
+ this.client = getConfiguredFastsetClient(config, chain);
179
192
  }
180
193
  async getAccount(address) {
181
194
  const addressBytes = this.addressToBytes(address);
182
195
  const accountInfo = await this.client.getAccountInfo(addressBytes);
183
- return { chain: this.chain.name, address, balance: BigInt(accountInfo.balance) };
196
+ return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.balance, 16)) };
184
197
  }
185
198
  async getAccountAssets(address) {
186
199
  const addressBytes = this.addressToBytes(address);
187
200
  const accountInfo = await this.client.getAccountInfo(addressBytes);
188
201
  const assets = [];
189
- const balance = BigInt(accountInfo.balance);
202
+ const balance = BigInt(parseInt(accountInfo.balance, 16));
190
203
  if (balance > 0n) {
191
204
  assets.push({ ...this.chain.nativeToken, amount: balance });
192
205
  }
193
206
  for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
194
- const amount = BigInt(tokenBalance);
207
+ const amount = BigInt(parseInt(tokenBalance, 16));
195
208
  if (amount > 0n) {
196
209
  const tokenInfo = await this.client.getTokenInfo([tokenId]);
197
210
  const metadata = tokenInfo.requested_token_metadata[0]?.[1];
@@ -209,12 +222,13 @@ var WarpFastsetDataLoader = class {
209
222
  return assets;
210
223
  }
211
224
  async getAsset(identifier) {
225
+ if (identifier === this.chain.nativeToken.identifier) {
226
+ return this.chain.nativeToken;
227
+ }
212
228
  const tokenId = Buffer.from(identifier, "hex");
213
229
  const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
214
230
  const metadata = tokenInfo.requested_token_metadata[0]?.[1];
215
- if (!metadata) {
216
- return null;
217
- }
231
+ if (!metadata) return null;
218
232
  return {
219
233
  chain: this.chain.name,
220
234
  identifier,
@@ -231,127 +245,150 @@ var WarpFastsetDataLoader = class {
231
245
  async getAccountActions(address, options) {
232
246
  return [];
233
247
  }
248
+ addressToBytes(address) {
249
+ try {
250
+ const decoded = bech323.bech32m.decode(address);
251
+ return Array.from(bech323.bech32m.fromWords(decoded.words));
252
+ } catch {
253
+ try {
254
+ const decoded = bech323.bech32.decode(address);
255
+ return Array.from(bech323.bech32.fromWords(decoded.words));
256
+ } catch {
257
+ throw new Error(`Invalid FastSet address: ${address}`);
258
+ }
259
+ }
260
+ }
234
261
  };
235
262
 
236
263
  // src/WarpFastsetExecutor.ts
237
- import * as ed25519 from "@noble/ed25519";
264
+ init_sdk();
238
265
  import {
239
- getProviderUrl,
240
- getWarpActionByIndex
266
+ getWarpActionByIndex,
267
+ getWarpWalletAddressFromConfig
241
268
  } from "@vleap/warps";
242
-
243
- // src/sdk/Wallet.ts
244
- import * as bech325 from "bech32";
245
-
246
- // src/sdk/ed25519-setup.ts
247
- import * as ed from "@noble/ed25519";
248
- import { sha512 } from "@noble/hashes/sha512";
249
- if (ed.etc) {
250
- ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
251
- }
252
-
253
- // src/sdk/Transaction.ts
254
- var Transaction = class _Transaction {
255
- constructor(sender, recipient, nonce, claim, options = {}) {
256
- this.sender = sender;
257
- this.recipient = recipient;
258
- this.nonce = nonce;
259
- this.claim = claim;
260
- this.timestamp = options.timestamp ?? BigInt(Date.now()) * 1000000n;
261
- }
262
- toTransaction() {
269
+ var WarpFastsetExecutor = class {
270
+ constructor(config, chain) {
271
+ this.config = config;
272
+ this.chain = chain;
273
+ this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
274
+ }
275
+ async createTransaction(executable) {
276
+ const action = getWarpActionByIndex(executable.warp, executable.action);
277
+ if (action.type === "transfer") return this.createTransferTransaction(executable);
278
+ 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})`);
282
+ }
283
+ async createTransferTransaction(executable) {
284
+ 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");
263
299
  return {
264
- sender: this.sender,
265
- recipient: this.recipient,
266
- nonce: this.nonce,
267
- timestamp_nanos: this.timestamp,
268
- claim: this.claim
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
269
306
  };
270
307
  }
271
- getSender() {
272
- return this.sender;
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
+ }
273
317
  }
274
- getRecipient() {
275
- return this.recipient;
318
+ async executeTransfer(executable) {
319
+ const transaction = await this.createTransferTransaction(executable);
320
+ return { success: true, transaction, chain: executable.chain.name };
276
321
  }
277
- getNonce() {
278
- return this.nonce;
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))),
329
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
330
+ claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
331
+ };
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 };
279
335
  }
280
- getClaim() {
281
- return this.claim;
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));
282
339
  }
283
- getTimestamp() {
284
- return this.timestamp;
340
+ serializeTransaction(tx) {
341
+ const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
342
+ return new TextEncoder().encode(serialized);
285
343
  }
286
- static fromTransaction(transaction) {
287
- return new _Transaction(transaction.sender, transaction.recipient, transaction.nonce, transaction.claim, {
288
- timestamp: transaction.timestamp_nanos
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
+ })
289
354
  });
355
+ if (!response.ok) throw new Error(`Query failed: ${response.statusText}`);
356
+ return response.json();
357
+ }
358
+ fromBase64(base64) {
359
+ return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
290
360
  }
291
361
  };
292
362
 
293
- // src/sdk/Wallet.ts
294
- var Wallet = class _Wallet {
295
- constructor(privateKeyHex) {
296
- const cleanPrivateKey = privateKeyHex.replace(/^0x/, "");
297
- this.privateKey = Buffer.from(cleanPrivateKey, "hex");
298
- this.publicKey = ed.getPublicKey(this.privateKey);
299
- this.publicKeyHex = Buffer.from(this.publicKey).toString("hex");
300
- }
301
- toBech32() {
302
- const words = bech325.bech32m.toWords(this.publicKey);
303
- return bech325.bech32m.encode("set", words);
304
- }
305
- getWalletInfo() {
306
- return {
307
- publicKeyHex: this.publicKeyHex,
308
- address: this.toBech32()
309
- };
310
- }
311
- createTransferClaim(recipientAddress, amount, assetType) {
312
- const recipientBytes = _Wallet.decodeBech32Address(recipientAddress);
313
- const assetTypeBytes = new TextEncoder().encode(assetType);
314
- const userData = new Uint8Array(32);
315
- userData.set(assetTypeBytes.slice(0, 32));
316
- return {
317
- Transfer: {
318
- recipient: { FastSet: recipientBytes },
319
- amount: amount.toString(),
320
- user_data: userData
321
- }
322
- };
323
- }
324
- createTransaction(nonce, recipient, claim) {
325
- return new Transaction(this.publicKey, recipient, nonce, claim);
326
- }
327
- static decodeBech32Address(address) {
328
- try {
329
- const decoded = bech325.bech32m.decode(address);
330
- return new Uint8Array(bech325.bech32m.fromWords(decoded.words));
331
- } catch (error) {
332
- const decoded = bech325.bech32.decode(address);
333
- return new Uint8Array(bech325.bech32.fromWords(decoded.words));
334
- }
363
+ // src/WarpFastsetExplorer.ts
364
+ var WarpFastsetExplorer = class {
365
+ constructor(_chainInfo, _config) {
366
+ this._chainInfo = _chainInfo;
367
+ this._config = _config;
368
+ this.explorerUrl = "https://explorer.fastset.xyz";
335
369
  }
336
- static encodeBech32Address(publicKey) {
337
- const words = bech325.bech32m.toWords(publicKey);
338
- return bech325.bech32m.encode("set", words);
370
+ getAccountUrl(address) {
371
+ return `${this.explorerUrl}/account/${address}`;
339
372
  }
340
- static fromPrivateKey(privateKeyHex) {
341
- return new _Wallet(privateKeyHex);
373
+ getTransactionUrl(hash) {
374
+ return `${this.explorerUrl}/transaction/${hash}`;
342
375
  }
343
- static generateNew() {
344
- const privateKey = ed.utils.randomPrivateKey();
345
- const privateKeyHex = Buffer.from(privateKey).toString("hex");
346
- return new _Wallet(privateKeyHex);
376
+ getAssetUrl(identifier) {
377
+ return `${this.explorerUrl}/asset/${identifier}`;
347
378
  }
348
- static async fromPrivateKeyFile(filePath) {
349
- const fs = await import("fs/promises");
350
- const privateKeyHex = (await fs.readFile(filePath, "utf8")).trim();
351
- return new _Wallet(privateKeyHex);
379
+ getContractUrl(address) {
380
+ return `${this.explorerUrl}/account/${address}`;
352
381
  }
353
382
  };
354
383
 
384
+ // src/WarpFastsetResults.ts
385
+ import {
386
+ evaluateResultsCommon,
387
+ getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig2,
388
+ parseResultsOutIndex,
389
+ WarpConstants
390
+ } from "@vleap/warps";
391
+
355
392
  // src/WarpFastsetSerializer.ts
356
393
  import {
357
394
  WarpSerializer
@@ -464,232 +501,7 @@ var WarpFastsetSerializer = class {
464
501
  }
465
502
  };
466
503
 
467
- // src/WarpFastsetExecutor.ts
468
- var WarpFastsetExecutor = class {
469
- constructor(config, chain) {
470
- this.config = config;
471
- this.chain = chain;
472
- this.serializer = new WarpFastsetSerializer();
473
- const proxyUrl = getProviderUrl(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
474
- this.fastsetClient = new FastsetClient({
475
- proxyUrl
476
- });
477
- }
478
- async createTransaction(executable) {
479
- const action = getWarpActionByIndex(executable.warp, executable.action);
480
- switch (action.type) {
481
- case "transfer":
482
- return this.createTransferTransaction(executable);
483
- case "contract":
484
- return this.createContractCallTransaction(executable);
485
- case "query":
486
- throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
487
- case "collect":
488
- throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
489
- default:
490
- throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
491
- }
492
- }
493
- async createTransferTransaction(executable) {
494
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
495
- if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
496
- if (!this.isValidFastsetAddress(executable.destination)) {
497
- throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
498
- }
499
- if (executable.value < 0) {
500
- throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
501
- }
502
- const recipientAddress = this.fromBase64(executable.destination);
503
- const amount = this.normalizeAmount(executable.value.toString());
504
- const userData = executable.data ? this.fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
505
- return {
506
- type: "fastset-transfer",
507
- recipient: recipientAddress,
508
- amount,
509
- userData,
510
- chain: executable.chain
511
- };
512
- }
513
- async createContractCallTransaction(executable) {
514
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
515
- if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
516
- const action = getWarpActionByIndex(executable.warp, executable.action);
517
- if (!action || !("func" in action) || !action.func) {
518
- throw new Error("WarpFastsetExecutor: Contract action must have a function name");
519
- }
520
- if (!this.isValidFastsetAddress(executable.destination)) {
521
- throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
522
- }
523
- if (executable.value < 0) {
524
- throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
525
- }
526
- try {
527
- const contractAddress = this.fromBase64(executable.destination);
528
- const encodedData = this.encodeFunctionData(action.func, executable.args);
529
- return {
530
- type: "fastset-contract-call",
531
- contract: contractAddress,
532
- function: action.func,
533
- data: encodedData,
534
- value: executable.value,
535
- chain: executable.chain
536
- };
537
- } catch (error) {
538
- throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
539
- }
540
- }
541
- async executeQuery(executable) {
542
- const action = getWarpActionByIndex(executable.warp, executable.action);
543
- if (action.type !== "query") {
544
- throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
545
- }
546
- if (!action.func) {
547
- throw new Error("WarpFastsetExecutor: Query action must have a function name");
548
- }
549
- if (!this.isValidFastsetAddress(executable.destination)) {
550
- throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
551
- }
552
- try {
553
- const contractAddress = this.fromBase64(executable.destination);
554
- const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
555
- return {
556
- success: true,
557
- result,
558
- chain: executable.chain
559
- };
560
- } catch (error) {
561
- return {
562
- success: false,
563
- error: error instanceof Error ? error.message : String(error),
564
- chain: executable.chain
565
- };
566
- }
567
- }
568
- async signMessage(message, privateKey) {
569
- throw new Error("Not implemented");
570
- }
571
- async signTransaction(transaction, privateKey) {
572
- const transactionJson = JSON.stringify(transaction, (key, value) => {
573
- if (value instanceof Uint8Array) {
574
- return Array.from(value);
575
- }
576
- return value;
577
- });
578
- const prefix = "Transaction::";
579
- const dataToSign = new TextEncoder().encode(prefix + transactionJson);
580
- return await ed25519.sign(dataToSign, privateKey);
581
- }
582
- async executeTransfer(executable) {
583
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
584
- if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
585
- const transaction = await this.createTransferTransaction(executable);
586
- return {
587
- success: true,
588
- transaction,
589
- chain: executable.chain.name,
590
- message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
591
- };
592
- }
593
- async executeTransferWithKey(executable, privateKey) {
594
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
595
- if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
596
- const transaction = await this.createTransferTransaction(executable);
597
- const privateKeyBytes = this.fromBase64(privateKey);
598
- const transactionData = {
599
- sender: Array.from(privateKeyBytes.slice(0, 32)),
600
- // First 32 bytes as public key
601
- recipient: { FastSet: transaction.recipient },
602
- nonce: await this.fastsetClient.getNextNonce(Wallet.encodeBech32Address(privateKeyBytes.slice(0, 32))),
603
- timestamp_nanos: (BigInt(Date.now()) * 1000000n).toString(),
604
- claim: {
605
- Transfer: {
606
- recipient: { FastSet: transaction.recipient },
607
- amount: transaction.amount,
608
- user_data: transaction.userData ? Array.from(transaction.userData) : null
609
- }
610
- }
611
- };
612
- const signature = await this.signTransaction(transactionData, privateKeyBytes);
613
- const transactionHash = await this.fastsetClient.submitTransaction(transactionData, signature);
614
- return {
615
- success: true,
616
- transactionHash: Array.from(transactionHash),
617
- chain: executable.chain.name
618
- };
619
- }
620
- encodeFunctionData(functionName, args) {
621
- return JSON.stringify({
622
- function: functionName,
623
- arguments: args
624
- });
625
- }
626
- async executeFastsetQuery(contractAddress, functionName, args) {
627
- const validatorUrl = getProviderUrl(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
628
- const response = await fetch(`${validatorUrl}/query`, {
629
- method: "POST",
630
- headers: {
631
- "Content-Type": "application/json"
632
- },
633
- body: JSON.stringify({
634
- contract: Array.from(contractAddress),
635
- function: functionName,
636
- arguments: args
637
- })
638
- });
639
- if (!response.ok) {
640
- throw new Error(`Fastset query failed: ${response.statusText}`);
641
- }
642
- return response.json();
643
- }
644
- isValidFastsetAddress(address) {
645
- if (typeof address !== "string" || address.length === 0) {
646
- return false;
647
- }
648
- if (address.startsWith("fs") || address.startsWith("pi")) {
649
- return true;
650
- }
651
- try {
652
- const decoded = this.fromBase64(address);
653
- return decoded.length === 32;
654
- } catch {
655
- return false;
656
- }
657
- }
658
- fromBase64(base64) {
659
- return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
660
- }
661
- normalizeAmount(amount) {
662
- return amount.startsWith("0x") ? amount.slice(2) : amount;
663
- }
664
- };
665
-
666
- // src/WarpFastsetExplorer.ts
667
- var WarpFastsetExplorer = class {
668
- constructor(_chainInfo, _config) {
669
- this._chainInfo = _chainInfo;
670
- this._config = _config;
671
- this.explorerUrl = "https://explorer.fastset.xyz";
672
- }
673
- getAccountUrl(address) {
674
- return `${this.explorerUrl}/account/${address}`;
675
- }
676
- getTransactionUrl(hash) {
677
- return `${this.explorerUrl}/transaction/${hash}`;
678
- }
679
- getAssetUrl(identifier) {
680
- return `${this.explorerUrl}/asset/${identifier}`;
681
- }
682
- getContractUrl(address) {
683
- return `${this.explorerUrl}/account/${address}`;
684
- }
685
- };
686
-
687
504
  // src/WarpFastsetResults.ts
688
- import {
689
- evaluateResultsCommon,
690
- parseResultsOutIndex,
691
- WarpConstants
692
- } from "@vleap/warps";
693
505
  var WarpFastsetResults = class {
694
506
  constructor(config, chain) {
695
507
  this.config = config;
@@ -705,7 +517,7 @@ var WarpFastsetResults = class {
705
517
  success,
706
518
  warp,
707
519
  action: 0,
708
- user: this.config.user?.wallets?.[this.chain.name] || null,
520
+ user: getWarpWalletAddressFromConfig2(this.config, this.chain.name),
709
521
  txHash: transactionHash,
710
522
  tx,
711
523
  next: null,
@@ -774,6 +586,70 @@ var WarpFastsetResults = class {
774
586
  }
775
587
  };
776
588
 
589
+ // src/WarpFastsetWallet.ts
590
+ init_sdk();
591
+ init_ed25519_setup();
592
+ import {
593
+ getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3
594
+ } from "@vleap/warps";
595
+ var WarpFastsetWallet = class {
596
+ constructor(config, chain) {
597
+ this.config = config;
598
+ this.chain = chain;
599
+ this.wallet = null;
600
+ this.initializeWallet();
601
+ }
602
+ initializeWallet() {
603
+ const walletConfig = this.config.user?.wallets?.[this.chain.name];
604
+ if (walletConfig && typeof walletConfig === "object" && "privateKey" in walletConfig && walletConfig.privateKey) {
605
+ this.wallet = new Wallet(walletConfig.privateKey);
606
+ }
607
+ }
608
+ async signTransaction(tx) {
609
+ if (!this.wallet) throw new Error("Wallet not initialized");
610
+ const transaction = tx;
611
+ const serializedTx = this.serializeTransaction(transaction.toTransaction());
612
+ const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
613
+ return Object.assign(transaction, { signature });
614
+ }
615
+ async signMessage(message) {
616
+ if (!this.wallet) throw new Error("Wallet not initialized");
617
+ const signature = await ed.sign(new TextEncoder().encode(message), this.wallet.getPrivateKey());
618
+ return Buffer.from(signature).toString("hex");
619
+ }
620
+ async sendTransaction(tx) {
621
+ if (!this.wallet) throw new Error("Wallet not initialized");
622
+ const transaction = tx;
623
+ const fastsetTx = transaction.toTransaction();
624
+ const transactionData = {
625
+ sender: fastsetTx.sender,
626
+ recipient: fastsetTx.recipient,
627
+ nonce: fastsetTx.nonce,
628
+ timestamp_nanos: fastsetTx.timestamp_nanos,
629
+ claim: fastsetTx.claim
630
+ };
631
+ const signature = tx.signature ? new Uint8Array(Buffer.from(tx.signature, "hex")) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
632
+ const client = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
633
+ return await client.submitTransaction(transactionData, signature);
634
+ }
635
+ create(mnemonic) {
636
+ const wallet = new Wallet(mnemonic);
637
+ return { address: wallet.toBech32(), privateKey: Buffer.from(wallet.getPrivateKey()).toString("hex"), mnemonic };
638
+ }
639
+ generate() {
640
+ 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 };
643
+ }
644
+ getAddress() {
645
+ return getWarpWalletAddressFromConfig3(this.config, this.chain.name);
646
+ }
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
+ };
652
+
777
653
  // src/main.ts
778
654
  var NativeTokenSet = {
779
655
  chain: WarpChainName.Fastset,
@@ -800,7 +676,8 @@ function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
800
676
  explorer: new WarpFastsetExplorer(chainInfo, config),
801
677
  abiBuilder: () => fallback.abiBuilder(),
802
678
  brandBuilder: () => fallback.brandBuilder(),
803
- dataLoader: new WarpFastsetDataLoader(config, chainInfo)
679
+ dataLoader: new WarpFastsetDataLoader(config, chainInfo),
680
+ wallet: new WarpFastsetWallet(config, chainInfo)
804
681
  };
805
682
  };
806
683
  }
@@ -811,7 +688,7 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, "fastset", {
811
688
  chainId: "1",
812
689
  blockTime: 1e3,
813
690
  addressHrp: "set",
814
- defaultApiUrl: "https://rpc.fastset.xyz",
691
+ defaultApiUrl: "https://proxy.fastset.xyz",
815
692
  nativeToken: NativeTokenSet
816
693
  },
817
694
  testnet: {
@@ -820,7 +697,7 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, "fastset", {
820
697
  chainId: "testnet",
821
698
  blockTime: 1e3,
822
699
  addressHrp: "set",
823
- defaultApiUrl: "https://rpc.fastset.xyz",
700
+ defaultApiUrl: "https://proxy.fastset.xyz",
824
701
  nativeToken: NativeTokenSet
825
702
  },
826
703
  devnet: {
@@ -829,19 +706,20 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, "fastset", {
829
706
  chainId: "devnet",
830
707
  blockTime: 1e3,
831
708
  addressHrp: "set",
832
- defaultApiUrl: "https://rpc.fastset.xyz",
709
+ defaultApiUrl: "https://proxy.fastset.xyz",
833
710
  nativeToken: NativeTokenSet
834
711
  }
835
712
  });
713
+
714
+ // src/index.ts
715
+ init_sdk();
836
716
  export {
837
717
  FastsetClient,
838
718
  NativeTokenSet,
839
- WarpFastsetConstants,
840
- WarpFastsetDataLoader,
719
+ Transaction,
720
+ Wallet,
841
721
  WarpFastsetExecutor,
842
- WarpFastsetExplorer,
843
- WarpFastsetResults,
844
- WarpFastsetSerializer,
722
+ WarpFastsetWallet,
845
723
  getFastsetAdapter
846
724
  };
847
725
  //# sourceMappingURL=index.mjs.map