@fystack/sdk 0.1.1 → 0.1.3

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.cjs CHANGED
@@ -24,7 +24,7 @@ const getBaseURL = (env)=>{
24
24
  case "local":
25
25
  return 'http://localhost:8150';
26
26
  case "sandbox":
27
- return 'https://apex.void.exchange';
27
+ return 'https://api-dev.fystack.io';
28
28
  case "production":
29
29
  return 'https://api.fystack.io';
30
30
  }
@@ -48,7 +48,8 @@ const createAPI = (env)=>{
48
48
  getTransactionStatus: (walletId, transactionId)=>withBaseURL(`/web3/transaction/${walletId}/${transactionId}`),
49
49
  getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
50
50
  getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
51
- getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`)
51
+ getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
52
+ rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
52
53
  }
53
54
  };
54
55
  };
@@ -126,14 +127,63 @@ async function computeHMACForWebhook(apiSecret, event) {
126
127
  }
127
128
  }
128
129
 
129
- exports.WalletAddressType = void 0;
130
- (function(WalletAddressType) {
131
- WalletAddressType["Evm"] = "evm";
132
- WalletAddressType["Sol"] = "sol";
133
- })(exports.WalletAddressType || (exports.WalletAddressType = {}));
130
+ // Wallets
131
+ exports.WalletType = void 0;
132
+ (function(WalletType) {
133
+ WalletType["Standard"] = "standard";
134
+ WalletType["MPC"] = "mpc";
135
+ })(exports.WalletType || (exports.WalletType = {}));
136
+ exports.WalletPurpose = void 0;
137
+ (function(WalletPurpose) {
138
+ WalletPurpose["General"] = "general";
139
+ WalletPurpose["Gastank"] = "gas_tank";
140
+ WalletPurpose["Deployment"] = "deployment";
141
+ WalletPurpose["Custody"] = "custody";
142
+ WalletPurpose["User"] = "user";
143
+ WalletPurpose["Payment"] = "payment";
144
+ })(exports.WalletPurpose || (exports.WalletPurpose = {}));
145
+ exports.WalletCreationStatus = void 0;
146
+ (function(WalletCreationStatus) {
147
+ WalletCreationStatus["Pending"] = "pending";
148
+ WalletCreationStatus["Success"] = "success";
149
+ WalletCreationStatus["Error"] = "error";
150
+ })(exports.WalletCreationStatus || (exports.WalletCreationStatus = {}));
151
+ exports.AddressType = void 0;
152
+ (function(AddressType) {
153
+ AddressType["Evm"] = "evm";
154
+ AddressType["Solana"] = "sol";
155
+ AddressType["Tron"] = "tron";
156
+ })(exports.AddressType || (exports.AddressType = {}));
157
+ exports.DestinationType = void 0;
158
+ (function(DestinationType) {
159
+ DestinationType["InternalWallet"] = "internal_wallet";
160
+ DestinationType["AddressBook"] = "address_book";
161
+ })(exports.DestinationType || (exports.DestinationType = {}));
162
+ exports.TxStatus = void 0;
163
+ (function(TxStatus) {
164
+ TxStatus["Pending"] = "pending";
165
+ TxStatus["Completed"] = "completed";
166
+ TxStatus["Confirmed"] = "confirmed";
167
+ TxStatus["Failed"] = "failed";
168
+ TxStatus["PendingApproval"] = "pending_approval";
169
+ TxStatus["Rejected"] = "rejected";
170
+ })(exports.TxStatus || (exports.TxStatus = {}));
171
+ exports.TxApprovalStatus = void 0;
172
+ (function(TxApprovalStatus) {
173
+ TxApprovalStatus["Pending"] = "pending";
174
+ TxApprovalStatus["Approved"] = "approved";
175
+ TxApprovalStatus["Rejected"] = "rejected";
176
+ })(exports.TxApprovalStatus || (exports.TxApprovalStatus = {}));
177
+
134
178
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
135
179
  if (credentials.apiSecret == '') {
136
- // If APISecret is not provided, fallback to cookie mode with no headers
180
+ // If APISecret is not provided, use authToken
181
+ if (credentials.authToken) {
182
+ return {
183
+ Authorization: credentials.authToken
184
+ };
185
+ }
186
+ // fallback to cookie mode with no headers
137
187
  return {};
138
188
  }
139
189
  const currentTimestampInSeconds = Math.floor(Date.now() / 1000);
@@ -155,7 +205,7 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
155
205
  return headers;
156
206
  }
157
207
  class APIService {
158
- async getWalletDetail(addressType = "evm", walletId) {
208
+ async getWalletDetail(addressType = exports.AddressType.Evm, walletId) {
159
209
  const endpoint = this.API.endpoints.getWalletDetail(walletId);
160
210
  const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
161
211
  console.info('headers', headers);
@@ -226,6 +276,16 @@ class APIService {
226
276
  const response = await get(endpoint, headers);
227
277
  return response.data;
228
278
  }
279
+ /**
280
+ * Rescans a transaction on a specific network
281
+ * @param params Transaction hash and network ID
282
+ * @returns API response
283
+ */ async rescanTransaction(params) {
284
+ const endpoint = this.API.endpoints.rescanTransaction();
285
+ const transformedParams = transformRescanTransactionParams(params);
286
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
287
+ await post(endpoint, transformedParams, headers);
288
+ }
229
289
  constructor(credentials, environment){
230
290
  this.credentials = credentials;
231
291
  this.Webhook = new WebhookService(credentials);
@@ -327,7 +387,26 @@ function transformWalletDetail(data) {
327
387
  function transformCreateWalletPayload(data) {
328
388
  return {
329
389
  name: data.name,
330
- wallet_type: data.walletType
390
+ wallet_type: data.walletType,
391
+ ...data.walletPurpose !== undefined && {
392
+ wallet_purpose: data.walletPurpose
393
+ },
394
+ ...data.sweepTaskParams !== undefined && {
395
+ sweep_task_params: {
396
+ min_trigger_value_usd: data.sweepTaskParams?.minTriggerValueUsd,
397
+ destination_wallet_id: data.sweepTaskParams?.destinationWalletId,
398
+ destination_type: data.sweepTaskParams?.destinationType
399
+ }
400
+ },
401
+ ...data.sweepTaskId !== undefined && {
402
+ sweep_task_id: data.sweepTaskId
403
+ }
404
+ };
405
+ }
406
+ function transformRescanTransactionParams(data) {
407
+ return {
408
+ tx_hash: data.txHash,
409
+ network_id: data.networkId
331
410
  };
332
411
  }
333
412
  BigInt.prototype.toJSON = function() {
@@ -388,47 +467,6 @@ class StatusPoller {
388
467
  }
389
468
  }
390
469
 
391
- class TransactionError extends Error {
392
- constructor(message, code, transactionId, originalError){
393
- super(message);
394
- this.code = code;
395
- this.transactionId = transactionId;
396
- this.originalError = originalError;
397
- this.name = 'TransactionError';
398
- }
399
- }
400
- exports.TxStatus = void 0;
401
- (function(TxStatus) {
402
- TxStatus["Pending"] = "pending";
403
- TxStatus["Completed"] = "completed";
404
- TxStatus["Confirmed"] = "confirmed";
405
- TxStatus["Failed"] = "failed";
406
- TxStatus["PendingApproval"] = "pending_approval";
407
- TxStatus["Rejected"] = "rejected";
408
- })(exports.TxStatus || (exports.TxStatus = {}));
409
- exports.TxApprovalStatus = void 0;
410
- (function(TxApprovalStatus) {
411
- TxApprovalStatus["Pending"] = "pending";
412
- TxApprovalStatus["Approved"] = "approved";
413
- TxApprovalStatus["Rejected"] = "rejected";
414
- })(exports.TxApprovalStatus || (exports.TxApprovalStatus = {}));
415
- exports.WalletType = void 0;
416
- (function(WalletType) {
417
- WalletType["Standard"] = "standard";
418
- WalletType["MPC"] = "mpc";
419
- })(exports.WalletType || (exports.WalletType = {}));
420
- exports.WalletCreationStatus = void 0;
421
- (function(WalletCreationStatus) {
422
- WalletCreationStatus["Pending"] = "pending";
423
- WalletCreationStatus["Success"] = "success";
424
- WalletCreationStatus["Error"] = "error";
425
- })(exports.WalletCreationStatus || (exports.WalletCreationStatus = {}));
426
- exports.AddressType = void 0;
427
- (function(AddressType) {
428
- AddressType["Evm"] = "evm";
429
- AddressType["Solana"] = "sol";
430
- })(exports.AddressType || (exports.AddressType = {}));
431
-
432
470
  class FystackSDK {
433
471
  log(message) {
434
472
  if (this.enableLogging) {
@@ -441,10 +479,13 @@ class FystackSDK {
441
479
  * @param waitForCompletion Whether to wait for the wallet creation to complete
442
480
  * @returns Promise with wallet ID and status
443
481
  */ async createWallet(options, waitForCompletion = true) {
444
- const { name, walletType = exports.WalletType.Standard } = options;
482
+ const { name, walletType = exports.WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
445
483
  const response = await this.apiService.createWallet({
446
484
  name,
447
- walletType
485
+ walletType,
486
+ walletPurpose,
487
+ sweepTaskParams,
488
+ sweepTaskId
448
489
  });
449
490
  if (waitForCompletion && response.status === exports.WalletCreationStatus.Pending) {
450
491
  return this.waitForWalletCreation(response.wallet_id);
@@ -507,6 +548,17 @@ class FystackSDK {
507
548
  const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
508
549
  return depositAddressInfo;
509
550
  }
551
+ /**
552
+ * Rescans a transaction on a specific network
553
+ * @param params Transaction hash and network ID
554
+ * @returns Promise that resolves when the rescan is initiated
555
+ */ async rescanTransaction(params) {
556
+ validateUUID(params.networkId, 'networkId');
557
+ if (!params.txHash || params.txHash.trim() === '') {
558
+ throw new Error('Invalid transaction hash provided');
559
+ }
560
+ await this.apiService.rescanTransaction(params);
561
+ }
510
562
  constructor(options){
511
563
  const { credentials, environment = exports.Environment.Production, logger = false } = options;
512
564
  this.apiService = new APIService(credentials, environment);
@@ -514,6 +566,16 @@ class FystackSDK {
514
566
  }
515
567
  }
516
568
 
569
+ class TransactionError extends Error {
570
+ constructor(message, code, transactionId, originalError){
571
+ super(message);
572
+ this.code = code;
573
+ this.transactionId = transactionId;
574
+ this.originalError = originalError;
575
+ this.name = 'TransactionError';
576
+ }
577
+ }
578
+
517
579
  class EtherSigner extends ethers.AbstractSigner {
518
580
  setWallet(walletId) {
519
581
  if (!walletId || walletId.trim() === '') {
@@ -534,10 +596,10 @@ class EtherSigner extends ethers.AbstractSigner {
534
596
  if (this.address) {
535
597
  return this.address;
536
598
  }
537
- if (!this.APICredentials.apiKey && !this.walletDetail.WalletID) {
599
+ if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
538
600
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
539
601
  }
540
- const detail = await this.APIService.getWalletDetail(exports.WalletAddressType.Evm, this.walletDetail?.WalletID);
602
+ const detail = await this.APIService.getWalletDetail(exports.AddressType.Evm, this.walletDetail?.WalletID);
541
603
  this.walletDetail = detail;
542
604
  if (detail?.Address) {
543
605
  // cache the address
@@ -795,10 +857,10 @@ class SolanaSigner {
795
857
  if (this.address) {
796
858
  return this.address;
797
859
  }
798
- if (!this.APIKey && !this.walletDetail?.WalletID) {
860
+ if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
799
861
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
800
862
  }
801
- const detail = await this.APIService.getWalletDetail(exports.WalletAddressType.Sol, this.walletDetail?.WalletID);
863
+ const detail = await this.APIService.getWalletDetail(exports.AddressType.Solana, this.walletDetail?.WalletID);
802
864
  this.walletDetail = detail;
803
865
  if (detail?.Address) {
804
866
  // cache the address
@@ -938,6 +1000,7 @@ class SolanaSigner {
938
1000
  }
939
1001
  }
940
1002
  constructor(credentials, environment, pollerOptions){
1003
+ this.APICredentials = credentials;
941
1004
  this.APIKey = credentials.apiKey;
942
1005
  this.APIService = new APIService(credentials, environment);
943
1006
  this.pollerOptions = pollerOptions;
@@ -957,4 +1020,5 @@ exports.createAPI = createAPI;
957
1020
  exports.get = get;
958
1021
  exports.post = post;
959
1022
  exports.transformCreateWalletPayload = transformCreateWalletPayload;
1023
+ exports.transformRescanTransactionParams = transformRescanTransactionParams;
960
1024
  exports.transformWalletDetail = transformWalletDetail;