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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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
@@ -217,19 +49,112 @@ var decoder = new TextDecoder();
217
49
  function uint8ArrayToHex(uint8Array) {
218
50
  return Buffer.from(uint8Array).toString("hex");
219
51
  }
220
- function hexToUint8Array(hex) {
221
- return new Uint8Array(Buffer.from(hex, "hex"));
222
- }
223
52
  function stringToUint8Array(str) {
224
53
  return new Uint8Array(Buffer.from(str, "utf8"));
225
54
  }
226
55
 
227
56
  // src/helpers/general.ts
228
57
  var import_warps = require("@vleap/warps");
229
- 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
230
155
  var getConfiguredFastsetClient = (config, chain) => {
231
156
  const proxyUrl = (0, import_warps.getProviderUrl)(config, chain.name, config.env, chain.defaultApiUrl);
232
- return new FastsetClient({ proxyUrl });
157
+ return new FastsetClient(proxyUrl);
233
158
  };
234
159
 
235
160
  // src/WarpFastsetDataLoader.ts
@@ -242,17 +167,18 @@ var WarpFastsetDataLoader = class {
242
167
  async getAccount(address) {
243
168
  const addressBytes = this.addressToBytes(address);
244
169
  const accountInfo = await this.client.getAccountInfo(addressBytes);
245
- 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)) };
246
171
  }
247
172
  async getAccountAssets(address) {
248
173
  const addressBytes = this.addressToBytes(address);
249
174
  const accountInfo = await this.client.getAccountInfo(addressBytes);
250
175
  const assets = [];
251
- const balance = BigInt(parseInt(accountInfo.balance, 16));
176
+ console.log("accountInfo", accountInfo);
177
+ const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
252
178
  if (balance > 0n) {
253
179
  assets.push({ ...this.chain.nativeToken, amount: balance });
254
180
  }
255
- for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
181
+ for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
256
182
  const amount = BigInt(parseInt(tokenBalance, 16));
257
183
  if (amount > 0n) {
258
184
  const tokenInfo = await this.client.getTokenInfo([tokenId]);
@@ -311,12 +237,11 @@ var WarpFastsetDataLoader = class {
311
237
 
312
238
  // src/WarpFastsetExecutor.ts
313
239
  var import_warps2 = require("@vleap/warps");
314
- init_sdk();
315
240
  var WarpFastsetExecutor = class {
316
241
  constructor(config, chain) {
317
242
  this.config = config;
318
243
  this.chain = chain;
319
- this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
244
+ this.client = getConfiguredFastsetClient(this.config, this.chain);
320
245
  }
321
246
  async createTransaction(executable) {
322
247
  const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
@@ -325,99 +250,30 @@ var WarpFastsetExecutor = class {
325
250
  if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
326
251
  if (action.type === "collect")
327
252
  throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
328
- throw new Error(`WarpFastsetExecutor: Invalid action type (unknown)`);
253
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
329
254
  }
330
255
  async createTransferTransaction(executable) {
331
256
  const userWallet = (0, import_warps2.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
332
257
  if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
333
- const senderAddress = FastsetClient.decodeBech32Address(userWallet);
334
- let recipientAddress;
335
- try {
336
- recipientAddress = FastsetClient.decodeBech32Address(executable.destination);
337
- } catch (error) {
338
- throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
339
- }
340
- const nonce = await this.fastsetClient.getNextNonce(userWallet);
341
- const transferValue = executable.transfers?.[0]?.amount || executable.value;
342
- if (transferValue < 0) throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${transferValue}`);
343
- const amount = "0x" + transferValue.toString(16);
344
- const userData = executable.data ? this.fromBase64(executable.data) : null;
345
- const claim = { Transfer: { amount, user_data: userData } };
346
- return new Transaction(senderAddress, { FastSet: recipientAddress }, nonce, claim);
347
- }
348
- async createContractCallTransaction(executable) {
349
- const userWallet = this.config.user?.wallets?.[executable.chain.name];
350
- if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
351
- const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
352
- if (!action || !("func" in action) || !action.func) throw new Error("WarpFastsetExecutor: Contract action must have a function name");
353
- let contractAddress;
354
- try {
355
- contractAddress = this.fromBase64(executable.destination);
356
- } catch (error) {
357
- throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
358
- }
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);
359
264
  return {
360
- type: "fastset-contract-call",
361
- contract: contractAddress,
362
- function: action.func,
363
- data: JSON.stringify({ function: action.func, arguments: executable.args }),
364
- value: executable.value,
365
- chain: executable.chain
366
- };
367
- }
368
- async executeQuery(executable) {
369
- const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
370
- if (action.type !== "query") throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
371
- if (!action.func) throw new Error("WarpFastsetExecutor: Query action must have a function name");
372
- try {
373
- const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
374
- return { success: true, result, chain: executable.chain };
375
- } catch (error) {
376
- return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
377
- }
378
- }
379
- async executeTransfer(executable) {
380
- const transaction = await this.createTransferTransaction(executable);
381
- return { success: true, transaction, chain: executable.chain.name };
382
- }
383
- async executeTransferWithKey(executable, privateKey) {
384
- const transaction = await this.createTransferTransaction(executable);
385
- const privateKeyBytes = this.fromBase64(privateKey);
386
- const transactionData = {
387
- sender: privateKeyBytes.slice(0, 32),
388
- recipient: transaction.getRecipientAddress(),
389
- nonce: await this.fastsetClient.getNextNonce(FastsetClient.encodeBech32Address(privateKeyBytes.slice(0, 32))),
265
+ sender: senderPubKey,
266
+ recipient: { FastSet: recipientPubKey },
267
+ nonce,
390
268
  timestamp_nanos: BigInt(Date.now()) * 1000000n,
391
- claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
269
+ claim: { Transfer: { amount: amountHex, user_data: null } }
392
270
  };
393
- const signature = await this.signTransaction(transactionData, privateKeyBytes);
394
- const result = await this.fastsetClient.submitTransaction(transactionData, signature);
395
- return { success: true, result, message: "Transaction submitted successfully", chain: executable.chain.name };
396
- }
397
- async signTransaction(transaction, privateKey) {
398
- const wallet = new (await Promise.resolve().then(() => (init_sdk(), sdk_exports))).Wallet(Buffer.from(privateKey).toString("hex"));
399
- return wallet.signTransactionRaw(this.serializeTransaction(transaction));
400
- }
401
- serializeTransaction(tx) {
402
- const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
403
- return new TextEncoder().encode(serialized);
404
- }
405
- async executeFastsetQuery(contractAddress, functionName, args) {
406
- const response = await fetch("https://proxy.fastset.xyz", {
407
- method: "POST",
408
- headers: { "Content-Type": "application/json" },
409
- body: JSON.stringify({
410
- jsonrpc: "2.0",
411
- method: "set_proxy_query",
412
- params: { contract: Array.from(contractAddress), function: functionName, arguments: args },
413
- id: 1
414
- })
415
- });
416
- if (!response.ok) throw new Error(`Fastset query failed: ${response.statusText}`);
417
- return response.json();
418
271
  }
419
- fromBase64(base64) {
420
- 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");
421
277
  }
422
278
  };
423
279
 
@@ -643,68 +499,169 @@ var WarpFastsetResults = class {
643
499
  // src/WarpFastsetWallet.ts
644
500
  var bip39 = __toESM(require("@scure/bip39"), 1);
645
501
  var import_warps5 = require("@vleap/warps");
646
- init_sdk();
647
- 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
648
613
  var WarpFastsetWallet = class {
649
614
  constructor(config, chain) {
650
615
  this.config = config;
651
616
  this.chain = chain;
652
- this.wallet = null;
653
- const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
654
- if (privateKey) {
655
- this.wallet = new Wallet(privateKey);
656
- }
657
617
  this.client = getConfiguredFastsetClient(this.config, this.chain);
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;
658
621
  }
659
622
  async signTransaction(tx) {
660
- if (!this.wallet) throw new Error("Wallet not initialized");
661
- const transaction = tx;
662
- const serializedTx = this.serializeTransaction(transaction.toTransaction());
663
- const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
664
- return Object.assign(transaction, { signature: uint8ArrayToHex(signature) });
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 };
665
631
  }
666
632
  async signMessage(message) {
667
- if (!this.wallet) throw new Error("Wallet not initialized");
668
633
  const messageBytes = stringToUint8Array(message);
669
- const signature = await ed.sign(messageBytes, this.wallet.getPrivateKey());
634
+ const signature = ed.sign(messageBytes, this.privateKey);
670
635
  return uint8ArrayToHex(signature);
671
636
  }
672
637
  async sendTransaction(tx) {
673
- if (!this.wallet) throw new Error("Wallet not initialized");
674
- const transaction = tx;
675
- const fastsetTx = transaction.toTransaction();
676
- const transactionData = {
677
- sender: fastsetTx.sender,
678
- recipient: fastsetTx.recipient,
679
- nonce: fastsetTx.nonce,
680
- timestamp_nanos: fastsetTx.timestamp_nanos,
681
- claim: fastsetTx.claim
638
+ const { signature, ...transactionWithoutSignature } = tx;
639
+ const submitTxReq = {
640
+ transaction: transactionWithoutSignature,
641
+ signature
682
642
  };
683
- const signature = tx.signature ? hexToUint8Array(tx.signature) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
684
- return await this.client.submitTransaction(transactionData, signature);
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";
685
648
  }
686
649
  create(mnemonic) {
687
650
  const seed = bip39.mnemonicToSeedSync(mnemonic);
688
651
  const privateKey = seed.slice(0, 32);
689
- const wallet = new Wallet(uint8ArrayToHex(privateKey));
690
- return { address: wallet.toBech32(), privateKey: uint8ArrayToHex(wallet.getPrivateKey()), mnemonic };
652
+ const publicKey = ed.getPublicKey(privateKey);
653
+ const address = FastsetClient.encodeBech32Address(publicKey);
654
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
691
655
  }
692
656
  generate() {
693
657
  const privateKey = ed.utils.randomPrivateKey();
694
- const wallet = new Wallet(uint8ArrayToHex(privateKey));
695
- return { address: wallet.toBech32(), privateKey: uint8ArrayToHex(wallet.getPrivateKey()), mnemonic: null };
658
+ const publicKey = ed.getPublicKey(privateKey);
659
+ const address = FastsetClient.encodeBech32Address(publicKey);
660
+ return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
696
661
  }
697
662
  getAddress() {
698
663
  return (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
699
664
  }
700
- serializeTransaction(tx) {
701
- const serialized = JSON.stringify(tx, (k, v) => {
702
- if (v instanceof Uint8Array) return Array.from(v);
703
- if (typeof v === "bigint") return v.toString();
704
- return v;
705
- });
706
- return encoder.encode(serialized);
707
- }
708
665
  };
709
666
 
710
667
  // src/main.ts
@@ -713,7 +670,7 @@ var NativeTokenSet = {
713
670
  identifier: "SET",
714
671
  name: "SET",
715
672
  symbol: "SET",
716
- decimals: 6,
673
+ decimals: 0,
717
674
  logoUrl: "https://vleap.ai/images/tokens/set.svg"
718
675
  };
719
676
  function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
@@ -770,15 +727,9 @@ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset
770
727
  nativeToken: NativeTokenSet
771
728
  }
772
729
  });
773
-
774
- // src/index.ts
775
- init_sdk();
776
730
  // Annotate the CommonJS export names for ESM import in node:
777
731
  0 && (module.exports = {
778
- FastsetClient,
779
732
  NativeTokenSet,
780
- Transaction,
781
- Wallet,
782
733
  WarpFastsetExecutor,
783
734
  WarpFastsetWallet,
784
735
  getFastsetAdapter