@fystack/sdk 0.1.2 → 0.1.4

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.esm.js CHANGED
@@ -16,7 +16,7 @@ const getBaseURL = (env)=>{
16
16
  case "local":
17
17
  return 'http://localhost:8150';
18
18
  case "sandbox":
19
- return 'https://apex.void.exchange';
19
+ return 'https://api-dev.fystack.io';
20
20
  case "production":
21
21
  return 'https://api.fystack.io';
22
22
  }
@@ -29,6 +29,7 @@ const createAPI = (env)=>{
29
29
  endpoints: {
30
30
  signTransaction: (walletId)=>withBaseURL(`/web3/transaction/${walletId}/signRaw`),
31
31
  getWalletDetail: (walletId)=>walletId ? withBaseURL(`/web3/wallet-detail/${walletId}`) : withBaseURL('/web3/wallet-detail'),
32
+ getWallets: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/wallets`),
32
33
  createWallet: ()=>withBaseURL('/wallets'),
33
34
  createCheckout: ()=>withBaseURL('/checkouts'),
34
35
  getCheckout: (checkoutId)=>withBaseURL(`/checkouts/${checkoutId}`),
@@ -40,7 +41,8 @@ const createAPI = (env)=>{
40
41
  getTransactionStatus: (walletId, transactionId)=>withBaseURL(`/web3/transaction/${walletId}/${transactionId}`),
41
42
  getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
42
43
  getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
43
- getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`)
44
+ getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
45
+ rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
44
46
  }
45
47
  };
46
48
  };
@@ -118,11 +120,60 @@ async function computeHMACForWebhook(apiSecret, event) {
118
120
  }
119
121
  }
120
122
 
121
- var WalletAddressType;
122
- (function(WalletAddressType) {
123
- WalletAddressType["Evm"] = "evm";
124
- WalletAddressType["Sol"] = "sol";
125
- })(WalletAddressType || (WalletAddressType = {}));
123
+ // Wallets
124
+ var WalletType;
125
+ (function(WalletType) {
126
+ WalletType["Standard"] = "standard";
127
+ WalletType["MPC"] = "mpc";
128
+ })(WalletType || (WalletType = {}));
129
+ var WalletPurpose;
130
+ (function(WalletPurpose) {
131
+ WalletPurpose["General"] = "general";
132
+ WalletPurpose["Gastank"] = "gas_tank";
133
+ WalletPurpose["Deployment"] = "deployment";
134
+ WalletPurpose["Custody"] = "custody";
135
+ WalletPurpose["User"] = "user";
136
+ WalletPurpose["Payment"] = "payment";
137
+ })(WalletPurpose || (WalletPurpose = {}));
138
+ var WalletCreationStatus;
139
+ (function(WalletCreationStatus) {
140
+ WalletCreationStatus["Pending"] = "pending";
141
+ WalletCreationStatus["Success"] = "success";
142
+ WalletCreationStatus["Error"] = "error";
143
+ })(WalletCreationStatus || (WalletCreationStatus = {}));
144
+ var AddressType;
145
+ (function(AddressType) {
146
+ AddressType["Evm"] = "evm";
147
+ AddressType["Solana"] = "sol";
148
+ AddressType["Tron"] = "tron";
149
+ })(AddressType || (AddressType = {}));
150
+ var DestinationType;
151
+ (function(DestinationType) {
152
+ DestinationType["InternalWallet"] = "internal_wallet";
153
+ DestinationType["AddressBook"] = "address_book";
154
+ })(DestinationType || (DestinationType = {}));
155
+ var TxStatus;
156
+ (function(TxStatus) {
157
+ TxStatus["Pending"] = "pending";
158
+ TxStatus["Completed"] = "completed";
159
+ TxStatus["Confirmed"] = "confirmed";
160
+ TxStatus["Failed"] = "failed";
161
+ TxStatus["PendingApproval"] = "pending_approval";
162
+ TxStatus["Rejected"] = "rejected";
163
+ })(TxStatus || (TxStatus = {}));
164
+ var TxApprovalStatus;
165
+ (function(TxApprovalStatus) {
166
+ TxApprovalStatus["Pending"] = "pending";
167
+ TxApprovalStatus["Approved"] = "approved";
168
+ TxApprovalStatus["Rejected"] = "rejected";
169
+ })(TxApprovalStatus || (TxApprovalStatus = {}));
170
+ var WalletRole;
171
+ (function(WalletRole) {
172
+ WalletRole["Admin"] = "wallet_admin";
173
+ WalletRole["Signer"] = "wallet_signer";
174
+ WalletRole["Viewer"] = "wallet_viewer";
175
+ })(WalletRole || (WalletRole = {}));
176
+
126
177
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
127
178
  if (credentials.apiSecret == '') {
128
179
  // If APISecret is not provided, use authToken
@@ -153,7 +204,13 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
153
204
  return headers;
154
205
  }
155
206
  class APIService {
156
- async getWalletDetail(addressType = "evm", walletId) {
207
+ async getWallets(workspaceId) {
208
+ const endpoint = this.API.endpoints.getWallets(workspaceId);
209
+ const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
210
+ const response = await get(endpoint, headers);
211
+ return response.data;
212
+ }
213
+ async getWalletDetail(addressType = AddressType.Evm, walletId) {
157
214
  const endpoint = this.API.endpoints.getWalletDetail(walletId);
158
215
  const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
159
216
  console.info('headers', headers);
@@ -224,6 +281,16 @@ class APIService {
224
281
  const response = await get(endpoint, headers);
225
282
  return response.data;
226
283
  }
284
+ /**
285
+ * Rescans a transaction on a specific network
286
+ * @param params Transaction hash and network ID
287
+ * @returns API response
288
+ */ async rescanTransaction(params) {
289
+ const endpoint = this.API.endpoints.rescanTransaction();
290
+ const transformedParams = transformRescanTransactionParams(params);
291
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
292
+ await post(endpoint, transformedParams, headers);
293
+ }
227
294
  constructor(credentials, environment){
228
295
  this.credentials = credentials;
229
296
  this.Webhook = new WebhookService(credentials);
@@ -325,7 +392,26 @@ function transformWalletDetail(data) {
325
392
  function transformCreateWalletPayload(data) {
326
393
  return {
327
394
  name: data.name,
328
- wallet_type: data.walletType
395
+ wallet_type: data.walletType,
396
+ ...data.walletPurpose !== undefined && {
397
+ wallet_purpose: data.walletPurpose
398
+ },
399
+ ...data.sweepTaskParams !== undefined && {
400
+ sweep_task_params: {
401
+ min_trigger_value_usd: data.sweepTaskParams?.minTriggerValueUsd,
402
+ destination_wallet_id: data.sweepTaskParams?.destinationWalletId,
403
+ destination_type: data.sweepTaskParams?.destinationType
404
+ }
405
+ },
406
+ ...data.sweepTaskId !== undefined && {
407
+ sweep_task_id: data.sweepTaskId
408
+ }
409
+ };
410
+ }
411
+ function transformRescanTransactionParams(data) {
412
+ return {
413
+ tx_hash: data.txHash,
414
+ network_id: data.networkId
329
415
  };
330
416
  }
331
417
  BigInt.prototype.toJSON = function() {
@@ -386,47 +472,6 @@ class StatusPoller {
386
472
  }
387
473
  }
388
474
 
389
- class TransactionError extends Error {
390
- constructor(message, code, transactionId, originalError){
391
- super(message);
392
- this.code = code;
393
- this.transactionId = transactionId;
394
- this.originalError = originalError;
395
- this.name = 'TransactionError';
396
- }
397
- }
398
- var TxStatus;
399
- (function(TxStatus) {
400
- TxStatus["Pending"] = "pending";
401
- TxStatus["Completed"] = "completed";
402
- TxStatus["Confirmed"] = "confirmed";
403
- TxStatus["Failed"] = "failed";
404
- TxStatus["PendingApproval"] = "pending_approval";
405
- TxStatus["Rejected"] = "rejected";
406
- })(TxStatus || (TxStatus = {}));
407
- var TxApprovalStatus;
408
- (function(TxApprovalStatus) {
409
- TxApprovalStatus["Pending"] = "pending";
410
- TxApprovalStatus["Approved"] = "approved";
411
- TxApprovalStatus["Rejected"] = "rejected";
412
- })(TxApprovalStatus || (TxApprovalStatus = {}));
413
- var WalletType;
414
- (function(WalletType) {
415
- WalletType["Standard"] = "standard";
416
- WalletType["MPC"] = "mpc";
417
- })(WalletType || (WalletType = {}));
418
- var WalletCreationStatus;
419
- (function(WalletCreationStatus) {
420
- WalletCreationStatus["Pending"] = "pending";
421
- WalletCreationStatus["Success"] = "success";
422
- WalletCreationStatus["Error"] = "error";
423
- })(WalletCreationStatus || (WalletCreationStatus = {}));
424
- var AddressType;
425
- (function(AddressType) {
426
- AddressType["Evm"] = "evm";
427
- AddressType["Solana"] = "sol";
428
- })(AddressType || (AddressType = {}));
429
-
430
475
  class FystackSDK {
431
476
  log(message) {
432
477
  if (this.enableLogging) {
@@ -439,10 +484,13 @@ class FystackSDK {
439
484
  * @param waitForCompletion Whether to wait for the wallet creation to complete
440
485
  * @returns Promise with wallet ID and status
441
486
  */ async createWallet(options, waitForCompletion = true) {
442
- const { name, walletType = WalletType.Standard } = options;
487
+ const { name, walletType = WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
443
488
  const response = await this.apiService.createWallet({
444
489
  name,
445
- walletType
490
+ walletType,
491
+ walletPurpose,
492
+ sweepTaskParams,
493
+ sweepTaskId
446
494
  });
447
495
  if (waitForCompletion && response.status === WalletCreationStatus.Pending) {
448
496
  return this.waitForWalletCreation(response.wallet_id);
@@ -450,6 +498,16 @@ class FystackSDK {
450
498
  return response;
451
499
  }
452
500
  /**
501
+ * Gets all wallets for the workspace
502
+ * @returns Promise with list of wallets
503
+ */ async getWallets() {
504
+ if (!this.workspaceId) {
505
+ throw new Error('Workspace ID is required. Please set workspaceId in the constructor.');
506
+ }
507
+ const wallets = await this.apiService.getWallets(this.workspaceId);
508
+ return wallets;
509
+ }
510
+ /**
453
511
  * Gets the current status of a wallet creation process
454
512
  * @param walletId The ID of the wallet being created
455
513
  * @returns Promise with wallet creation status details
@@ -505,10 +563,32 @@ class FystackSDK {
505
563
  const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
506
564
  return depositAddressInfo;
507
565
  }
566
+ /**
567
+ * Rescans a transaction on a specific network
568
+ * @param params Transaction hash and network ID
569
+ * @returns Promise that resolves when the rescan is initiated
570
+ */ async rescanTransaction(params) {
571
+ validateUUID(params.networkId, 'networkId');
572
+ if (!params.txHash || params.txHash.trim() === '') {
573
+ throw new Error('Invalid transaction hash provided');
574
+ }
575
+ await this.apiService.rescanTransaction(params);
576
+ }
508
577
  constructor(options){
509
- const { credentials, environment = Environment.Production, logger = false } = options;
578
+ const { credentials, workspaceId, environment = Environment.Production, logger = false } = options;
510
579
  this.apiService = new APIService(credentials, environment);
511
580
  this.enableLogging = logger;
581
+ this.workspaceId = workspaceId;
582
+ }
583
+ }
584
+
585
+ class TransactionError extends Error {
586
+ constructor(message, code, transactionId, originalError){
587
+ super(message);
588
+ this.code = code;
589
+ this.transactionId = transactionId;
590
+ this.originalError = originalError;
591
+ this.name = 'TransactionError';
512
592
  }
513
593
  }
514
594
 
@@ -535,7 +615,7 @@ class EtherSigner extends AbstractSigner {
535
615
  if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
536
616
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
537
617
  }
538
- const detail = await this.APIService.getWalletDetail(WalletAddressType.Evm, this.walletDetail?.WalletID);
618
+ const detail = await this.APIService.getWalletDetail(AddressType.Evm, this.walletDetail?.WalletID);
539
619
  this.walletDetail = detail;
540
620
  if (detail?.Address) {
541
621
  // cache the address
@@ -599,6 +679,12 @@ class EtherSigner extends AbstractSigner {
599
679
  async signTransaction(tx) {
600
680
  const startTime = new Date();
601
681
  console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`);
682
+ if (!this.address) {
683
+ await this.getAddress();
684
+ }
685
+ if (!this.walletDetail) {
686
+ this.walletDetail = await this.APIService.getWalletDetail();
687
+ }
602
688
  // Replace any Addressable or ENS name with an address
603
689
  const { to, from } = await resolveProperties({
604
690
  to: tx.to ? resolveAddress(tx.to, this.provider) : undefined,
@@ -645,6 +731,9 @@ class EtherSigner extends AbstractSigner {
645
731
  if (!this.address) {
646
732
  await this.getAddress();
647
733
  }
734
+ if (!this.walletDetail) {
735
+ this.walletDetail = await this.APIService.getWalletDetail();
736
+ }
648
737
  checkProvider(this, 'sendTransaction');
649
738
  // Only populate if gas fees are not set
650
739
  const hasGasFees = tx.gasPrice != null || tx.maxFeePerGas != null && tx.maxPriorityFeePerGas != null;
@@ -796,7 +885,7 @@ class SolanaSigner {
796
885
  if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
797
886
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
798
887
  }
799
- const detail = await this.APIService.getWalletDetail(WalletAddressType.Sol, this.walletDetail?.WalletID);
888
+ const detail = await this.APIService.getWalletDetail(AddressType.Solana, this.walletDetail?.WalletID);
800
889
  this.walletDetail = detail;
801
890
  if (detail?.Address) {
802
891
  // cache the address
@@ -943,4 +1032,4 @@ class SolanaSigner {
943
1032
  }
944
1033
  }
945
1034
 
946
- export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletAddressType, WalletCreationStatus, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
1035
+ export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformRescanTransactionParams, transformWalletDetail };
package/dist/index.mjs CHANGED
@@ -16,7 +16,7 @@ const getBaseURL = (env)=>{
16
16
  case "local":
17
17
  return 'http://localhost:8150';
18
18
  case "sandbox":
19
- return 'https://apex.void.exchange';
19
+ return 'https://api-dev.fystack.io';
20
20
  case "production":
21
21
  return 'https://api.fystack.io';
22
22
  }
@@ -29,6 +29,7 @@ const createAPI = (env)=>{
29
29
  endpoints: {
30
30
  signTransaction: (walletId)=>withBaseURL(`/web3/transaction/${walletId}/signRaw`),
31
31
  getWalletDetail: (walletId)=>walletId ? withBaseURL(`/web3/wallet-detail/${walletId}`) : withBaseURL('/web3/wallet-detail'),
32
+ getWallets: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/wallets`),
32
33
  createWallet: ()=>withBaseURL('/wallets'),
33
34
  createCheckout: ()=>withBaseURL('/checkouts'),
34
35
  getCheckout: (checkoutId)=>withBaseURL(`/checkouts/${checkoutId}`),
@@ -40,7 +41,8 @@ const createAPI = (env)=>{
40
41
  getTransactionStatus: (walletId, transactionId)=>withBaseURL(`/web3/transaction/${walletId}/${transactionId}`),
41
42
  getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
42
43
  getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
43
- getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`)
44
+ getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
45
+ rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
44
46
  }
45
47
  };
46
48
  };
@@ -118,11 +120,60 @@ async function computeHMACForWebhook(apiSecret, event) {
118
120
  }
119
121
  }
120
122
 
121
- var WalletAddressType;
122
- (function(WalletAddressType) {
123
- WalletAddressType["Evm"] = "evm";
124
- WalletAddressType["Sol"] = "sol";
125
- })(WalletAddressType || (WalletAddressType = {}));
123
+ // Wallets
124
+ var WalletType;
125
+ (function(WalletType) {
126
+ WalletType["Standard"] = "standard";
127
+ WalletType["MPC"] = "mpc";
128
+ })(WalletType || (WalletType = {}));
129
+ var WalletPurpose;
130
+ (function(WalletPurpose) {
131
+ WalletPurpose["General"] = "general";
132
+ WalletPurpose["Gastank"] = "gas_tank";
133
+ WalletPurpose["Deployment"] = "deployment";
134
+ WalletPurpose["Custody"] = "custody";
135
+ WalletPurpose["User"] = "user";
136
+ WalletPurpose["Payment"] = "payment";
137
+ })(WalletPurpose || (WalletPurpose = {}));
138
+ var WalletCreationStatus;
139
+ (function(WalletCreationStatus) {
140
+ WalletCreationStatus["Pending"] = "pending";
141
+ WalletCreationStatus["Success"] = "success";
142
+ WalletCreationStatus["Error"] = "error";
143
+ })(WalletCreationStatus || (WalletCreationStatus = {}));
144
+ var AddressType;
145
+ (function(AddressType) {
146
+ AddressType["Evm"] = "evm";
147
+ AddressType["Solana"] = "sol";
148
+ AddressType["Tron"] = "tron";
149
+ })(AddressType || (AddressType = {}));
150
+ var DestinationType;
151
+ (function(DestinationType) {
152
+ DestinationType["InternalWallet"] = "internal_wallet";
153
+ DestinationType["AddressBook"] = "address_book";
154
+ })(DestinationType || (DestinationType = {}));
155
+ var TxStatus;
156
+ (function(TxStatus) {
157
+ TxStatus["Pending"] = "pending";
158
+ TxStatus["Completed"] = "completed";
159
+ TxStatus["Confirmed"] = "confirmed";
160
+ TxStatus["Failed"] = "failed";
161
+ TxStatus["PendingApproval"] = "pending_approval";
162
+ TxStatus["Rejected"] = "rejected";
163
+ })(TxStatus || (TxStatus = {}));
164
+ var TxApprovalStatus;
165
+ (function(TxApprovalStatus) {
166
+ TxApprovalStatus["Pending"] = "pending";
167
+ TxApprovalStatus["Approved"] = "approved";
168
+ TxApprovalStatus["Rejected"] = "rejected";
169
+ })(TxApprovalStatus || (TxApprovalStatus = {}));
170
+ var WalletRole;
171
+ (function(WalletRole) {
172
+ WalletRole["Admin"] = "wallet_admin";
173
+ WalletRole["Signer"] = "wallet_signer";
174
+ WalletRole["Viewer"] = "wallet_viewer";
175
+ })(WalletRole || (WalletRole = {}));
176
+
126
177
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
127
178
  if (credentials.apiSecret == '') {
128
179
  // If APISecret is not provided, use authToken
@@ -153,7 +204,13 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
153
204
  return headers;
154
205
  }
155
206
  class APIService {
156
- async getWalletDetail(addressType = "evm", walletId) {
207
+ async getWallets(workspaceId) {
208
+ const endpoint = this.API.endpoints.getWallets(workspaceId);
209
+ const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
210
+ const response = await get(endpoint, headers);
211
+ return response.data;
212
+ }
213
+ async getWalletDetail(addressType = AddressType.Evm, walletId) {
157
214
  const endpoint = this.API.endpoints.getWalletDetail(walletId);
158
215
  const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
159
216
  console.info('headers', headers);
@@ -224,6 +281,16 @@ class APIService {
224
281
  const response = await get(endpoint, headers);
225
282
  return response.data;
226
283
  }
284
+ /**
285
+ * Rescans a transaction on a specific network
286
+ * @param params Transaction hash and network ID
287
+ * @returns API response
288
+ */ async rescanTransaction(params) {
289
+ const endpoint = this.API.endpoints.rescanTransaction();
290
+ const transformedParams = transformRescanTransactionParams(params);
291
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
292
+ await post(endpoint, transformedParams, headers);
293
+ }
227
294
  constructor(credentials, environment){
228
295
  this.credentials = credentials;
229
296
  this.Webhook = new WebhookService(credentials);
@@ -325,7 +392,26 @@ function transformWalletDetail(data) {
325
392
  function transformCreateWalletPayload(data) {
326
393
  return {
327
394
  name: data.name,
328
- wallet_type: data.walletType
395
+ wallet_type: data.walletType,
396
+ ...data.walletPurpose !== undefined && {
397
+ wallet_purpose: data.walletPurpose
398
+ },
399
+ ...data.sweepTaskParams !== undefined && {
400
+ sweep_task_params: {
401
+ min_trigger_value_usd: data.sweepTaskParams?.minTriggerValueUsd,
402
+ destination_wallet_id: data.sweepTaskParams?.destinationWalletId,
403
+ destination_type: data.sweepTaskParams?.destinationType
404
+ }
405
+ },
406
+ ...data.sweepTaskId !== undefined && {
407
+ sweep_task_id: data.sweepTaskId
408
+ }
409
+ };
410
+ }
411
+ function transformRescanTransactionParams(data) {
412
+ return {
413
+ tx_hash: data.txHash,
414
+ network_id: data.networkId
329
415
  };
330
416
  }
331
417
  BigInt.prototype.toJSON = function() {
@@ -386,47 +472,6 @@ class StatusPoller {
386
472
  }
387
473
  }
388
474
 
389
- class TransactionError extends Error {
390
- constructor(message, code, transactionId, originalError){
391
- super(message);
392
- this.code = code;
393
- this.transactionId = transactionId;
394
- this.originalError = originalError;
395
- this.name = 'TransactionError';
396
- }
397
- }
398
- var TxStatus;
399
- (function(TxStatus) {
400
- TxStatus["Pending"] = "pending";
401
- TxStatus["Completed"] = "completed";
402
- TxStatus["Confirmed"] = "confirmed";
403
- TxStatus["Failed"] = "failed";
404
- TxStatus["PendingApproval"] = "pending_approval";
405
- TxStatus["Rejected"] = "rejected";
406
- })(TxStatus || (TxStatus = {}));
407
- var TxApprovalStatus;
408
- (function(TxApprovalStatus) {
409
- TxApprovalStatus["Pending"] = "pending";
410
- TxApprovalStatus["Approved"] = "approved";
411
- TxApprovalStatus["Rejected"] = "rejected";
412
- })(TxApprovalStatus || (TxApprovalStatus = {}));
413
- var WalletType;
414
- (function(WalletType) {
415
- WalletType["Standard"] = "standard";
416
- WalletType["MPC"] = "mpc";
417
- })(WalletType || (WalletType = {}));
418
- var WalletCreationStatus;
419
- (function(WalletCreationStatus) {
420
- WalletCreationStatus["Pending"] = "pending";
421
- WalletCreationStatus["Success"] = "success";
422
- WalletCreationStatus["Error"] = "error";
423
- })(WalletCreationStatus || (WalletCreationStatus = {}));
424
- var AddressType;
425
- (function(AddressType) {
426
- AddressType["Evm"] = "evm";
427
- AddressType["Solana"] = "sol";
428
- })(AddressType || (AddressType = {}));
429
-
430
475
  class FystackSDK {
431
476
  log(message) {
432
477
  if (this.enableLogging) {
@@ -439,10 +484,13 @@ class FystackSDK {
439
484
  * @param waitForCompletion Whether to wait for the wallet creation to complete
440
485
  * @returns Promise with wallet ID and status
441
486
  */ async createWallet(options, waitForCompletion = true) {
442
- const { name, walletType = WalletType.Standard } = options;
487
+ const { name, walletType = WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
443
488
  const response = await this.apiService.createWallet({
444
489
  name,
445
- walletType
490
+ walletType,
491
+ walletPurpose,
492
+ sweepTaskParams,
493
+ sweepTaskId
446
494
  });
447
495
  if (waitForCompletion && response.status === WalletCreationStatus.Pending) {
448
496
  return this.waitForWalletCreation(response.wallet_id);
@@ -450,6 +498,16 @@ class FystackSDK {
450
498
  return response;
451
499
  }
452
500
  /**
501
+ * Gets all wallets for the workspace
502
+ * @returns Promise with list of wallets
503
+ */ async getWallets() {
504
+ if (!this.workspaceId) {
505
+ throw new Error('Workspace ID is required. Please set workspaceId in the constructor.');
506
+ }
507
+ const wallets = await this.apiService.getWallets(this.workspaceId);
508
+ return wallets;
509
+ }
510
+ /**
453
511
  * Gets the current status of a wallet creation process
454
512
  * @param walletId The ID of the wallet being created
455
513
  * @returns Promise with wallet creation status details
@@ -505,10 +563,32 @@ class FystackSDK {
505
563
  const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
506
564
  return depositAddressInfo;
507
565
  }
566
+ /**
567
+ * Rescans a transaction on a specific network
568
+ * @param params Transaction hash and network ID
569
+ * @returns Promise that resolves when the rescan is initiated
570
+ */ async rescanTransaction(params) {
571
+ validateUUID(params.networkId, 'networkId');
572
+ if (!params.txHash || params.txHash.trim() === '') {
573
+ throw new Error('Invalid transaction hash provided');
574
+ }
575
+ await this.apiService.rescanTransaction(params);
576
+ }
508
577
  constructor(options){
509
- const { credentials, environment = Environment.Production, logger = false } = options;
578
+ const { credentials, workspaceId, environment = Environment.Production, logger = false } = options;
510
579
  this.apiService = new APIService(credentials, environment);
511
580
  this.enableLogging = logger;
581
+ this.workspaceId = workspaceId;
582
+ }
583
+ }
584
+
585
+ class TransactionError extends Error {
586
+ constructor(message, code, transactionId, originalError){
587
+ super(message);
588
+ this.code = code;
589
+ this.transactionId = transactionId;
590
+ this.originalError = originalError;
591
+ this.name = 'TransactionError';
512
592
  }
513
593
  }
514
594
 
@@ -535,7 +615,7 @@ class EtherSigner extends AbstractSigner {
535
615
  if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
536
616
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
537
617
  }
538
- const detail = await this.APIService.getWalletDetail(WalletAddressType.Evm, this.walletDetail?.WalletID);
618
+ const detail = await this.APIService.getWalletDetail(AddressType.Evm, this.walletDetail?.WalletID);
539
619
  this.walletDetail = detail;
540
620
  if (detail?.Address) {
541
621
  // cache the address
@@ -599,6 +679,12 @@ class EtherSigner extends AbstractSigner {
599
679
  async signTransaction(tx) {
600
680
  const startTime = new Date();
601
681
  console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`);
682
+ if (!this.address) {
683
+ await this.getAddress();
684
+ }
685
+ if (!this.walletDetail) {
686
+ this.walletDetail = await this.APIService.getWalletDetail();
687
+ }
602
688
  // Replace any Addressable or ENS name with an address
603
689
  const { to, from } = await resolveProperties({
604
690
  to: tx.to ? resolveAddress(tx.to, this.provider) : undefined,
@@ -645,6 +731,9 @@ class EtherSigner extends AbstractSigner {
645
731
  if (!this.address) {
646
732
  await this.getAddress();
647
733
  }
734
+ if (!this.walletDetail) {
735
+ this.walletDetail = await this.APIService.getWalletDetail();
736
+ }
648
737
  checkProvider(this, 'sendTransaction');
649
738
  // Only populate if gas fees are not set
650
739
  const hasGasFees = tx.gasPrice != null || tx.maxFeePerGas != null && tx.maxPriorityFeePerGas != null;
@@ -796,7 +885,7 @@ class SolanaSigner {
796
885
  if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
797
886
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
798
887
  }
799
- const detail = await this.APIService.getWalletDetail(WalletAddressType.Sol, this.walletDetail?.WalletID);
888
+ const detail = await this.APIService.getWalletDetail(AddressType.Solana, this.walletDetail?.WalletID);
800
889
  this.walletDetail = detail;
801
890
  if (detail?.Address) {
802
891
  // cache the address
@@ -943,4 +1032,4 @@ class SolanaSigner {
943
1032
  }
944
1033
  }
945
1034
 
946
- export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletAddressType, WalletCreationStatus, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
1035
+ export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformRescanTransactionParams, transformWalletDetail };