@fystack/sdk 0.1.2 → 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 +111 -54
- package/dist/index.d.cts +318 -269
- package/dist/index.d.mts +318 -269
- package/dist/index.esm.d.ts +318 -269
- package/dist/index.esm.js +111 -55
- package/dist/index.mjs +111 -55
- package/dist/types/index.d.ts +318 -269
- package/package.json +1 -1
- package/readme.md +7 -1
- package/src/api.ts +42 -13
- package/src/config.ts +4 -2
- package/src/enum.ts +46 -0
- package/src/index.ts +1 -0
- package/src/sdk.ts +31 -7
- package/src/signer.ts +4 -3
- package/src/solanaSigner.ts +4 -3
- package/src/types.ts +11 -30
- package/test.js +0 -76
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://
|
|
19
|
+
return 'https://api-dev.fystack.io';
|
|
20
20
|
case "production":
|
|
21
21
|
return 'https://api.fystack.io';
|
|
22
22
|
}
|
|
@@ -40,7 +40,8 @@ const createAPI = (env)=>{
|
|
|
40
40
|
getTransactionStatus: (walletId, transactionId)=>withBaseURL(`/web3/transaction/${walletId}/${transactionId}`),
|
|
41
41
|
getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
|
|
42
42
|
getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
|
|
43
|
-
getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`)
|
|
43
|
+
getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
|
|
44
|
+
rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
};
|
|
@@ -118,11 +119,54 @@ async function computeHMACForWebhook(apiSecret, event) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
// Wallets
|
|
123
|
+
var WalletType;
|
|
124
|
+
(function(WalletType) {
|
|
125
|
+
WalletType["Standard"] = "standard";
|
|
126
|
+
WalletType["MPC"] = "mpc";
|
|
127
|
+
})(WalletType || (WalletType = {}));
|
|
128
|
+
var WalletPurpose;
|
|
129
|
+
(function(WalletPurpose) {
|
|
130
|
+
WalletPurpose["General"] = "general";
|
|
131
|
+
WalletPurpose["Gastank"] = "gas_tank";
|
|
132
|
+
WalletPurpose["Deployment"] = "deployment";
|
|
133
|
+
WalletPurpose["Custody"] = "custody";
|
|
134
|
+
WalletPurpose["User"] = "user";
|
|
135
|
+
WalletPurpose["Payment"] = "payment";
|
|
136
|
+
})(WalletPurpose || (WalletPurpose = {}));
|
|
137
|
+
var WalletCreationStatus;
|
|
138
|
+
(function(WalletCreationStatus) {
|
|
139
|
+
WalletCreationStatus["Pending"] = "pending";
|
|
140
|
+
WalletCreationStatus["Success"] = "success";
|
|
141
|
+
WalletCreationStatus["Error"] = "error";
|
|
142
|
+
})(WalletCreationStatus || (WalletCreationStatus = {}));
|
|
143
|
+
var AddressType;
|
|
144
|
+
(function(AddressType) {
|
|
145
|
+
AddressType["Evm"] = "evm";
|
|
146
|
+
AddressType["Solana"] = "sol";
|
|
147
|
+
AddressType["Tron"] = "tron";
|
|
148
|
+
})(AddressType || (AddressType = {}));
|
|
149
|
+
var DestinationType;
|
|
150
|
+
(function(DestinationType) {
|
|
151
|
+
DestinationType["InternalWallet"] = "internal_wallet";
|
|
152
|
+
DestinationType["AddressBook"] = "address_book";
|
|
153
|
+
})(DestinationType || (DestinationType = {}));
|
|
154
|
+
var TxStatus;
|
|
155
|
+
(function(TxStatus) {
|
|
156
|
+
TxStatus["Pending"] = "pending";
|
|
157
|
+
TxStatus["Completed"] = "completed";
|
|
158
|
+
TxStatus["Confirmed"] = "confirmed";
|
|
159
|
+
TxStatus["Failed"] = "failed";
|
|
160
|
+
TxStatus["PendingApproval"] = "pending_approval";
|
|
161
|
+
TxStatus["Rejected"] = "rejected";
|
|
162
|
+
})(TxStatus || (TxStatus = {}));
|
|
163
|
+
var TxApprovalStatus;
|
|
164
|
+
(function(TxApprovalStatus) {
|
|
165
|
+
TxApprovalStatus["Pending"] = "pending";
|
|
166
|
+
TxApprovalStatus["Approved"] = "approved";
|
|
167
|
+
TxApprovalStatus["Rejected"] = "rejected";
|
|
168
|
+
})(TxApprovalStatus || (TxApprovalStatus = {}));
|
|
169
|
+
|
|
126
170
|
async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
|
|
127
171
|
if (credentials.apiSecret == '') {
|
|
128
172
|
// If APISecret is not provided, use authToken
|
|
@@ -153,7 +197,7 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
|
|
|
153
197
|
return headers;
|
|
154
198
|
}
|
|
155
199
|
class APIService {
|
|
156
|
-
async getWalletDetail(addressType =
|
|
200
|
+
async getWalletDetail(addressType = AddressType.Evm, walletId) {
|
|
157
201
|
const endpoint = this.API.endpoints.getWalletDetail(walletId);
|
|
158
202
|
const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
|
|
159
203
|
console.info('headers', headers);
|
|
@@ -224,6 +268,16 @@ class APIService {
|
|
|
224
268
|
const response = await get(endpoint, headers);
|
|
225
269
|
return response.data;
|
|
226
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Rescans a transaction on a specific network
|
|
273
|
+
* @param params Transaction hash and network ID
|
|
274
|
+
* @returns API response
|
|
275
|
+
*/ async rescanTransaction(params) {
|
|
276
|
+
const endpoint = this.API.endpoints.rescanTransaction();
|
|
277
|
+
const transformedParams = transformRescanTransactionParams(params);
|
|
278
|
+
const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
|
|
279
|
+
await post(endpoint, transformedParams, headers);
|
|
280
|
+
}
|
|
227
281
|
constructor(credentials, environment){
|
|
228
282
|
this.credentials = credentials;
|
|
229
283
|
this.Webhook = new WebhookService(credentials);
|
|
@@ -325,7 +379,26 @@ function transformWalletDetail(data) {
|
|
|
325
379
|
function transformCreateWalletPayload(data) {
|
|
326
380
|
return {
|
|
327
381
|
name: data.name,
|
|
328
|
-
wallet_type: data.walletType
|
|
382
|
+
wallet_type: data.walletType,
|
|
383
|
+
...data.walletPurpose !== undefined && {
|
|
384
|
+
wallet_purpose: data.walletPurpose
|
|
385
|
+
},
|
|
386
|
+
...data.sweepTaskParams !== undefined && {
|
|
387
|
+
sweep_task_params: {
|
|
388
|
+
min_trigger_value_usd: data.sweepTaskParams?.minTriggerValueUsd,
|
|
389
|
+
destination_wallet_id: data.sweepTaskParams?.destinationWalletId,
|
|
390
|
+
destination_type: data.sweepTaskParams?.destinationType
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
...data.sweepTaskId !== undefined && {
|
|
394
|
+
sweep_task_id: data.sweepTaskId
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function transformRescanTransactionParams(data) {
|
|
399
|
+
return {
|
|
400
|
+
tx_hash: data.txHash,
|
|
401
|
+
network_id: data.networkId
|
|
329
402
|
};
|
|
330
403
|
}
|
|
331
404
|
BigInt.prototype.toJSON = function() {
|
|
@@ -386,47 +459,6 @@ class StatusPoller {
|
|
|
386
459
|
}
|
|
387
460
|
}
|
|
388
461
|
|
|
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
462
|
class FystackSDK {
|
|
431
463
|
log(message) {
|
|
432
464
|
if (this.enableLogging) {
|
|
@@ -439,10 +471,13 @@ class FystackSDK {
|
|
|
439
471
|
* @param waitForCompletion Whether to wait for the wallet creation to complete
|
|
440
472
|
* @returns Promise with wallet ID and status
|
|
441
473
|
*/ async createWallet(options, waitForCompletion = true) {
|
|
442
|
-
const { name, walletType = WalletType.Standard } = options;
|
|
474
|
+
const { name, walletType = WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
|
|
443
475
|
const response = await this.apiService.createWallet({
|
|
444
476
|
name,
|
|
445
|
-
walletType
|
|
477
|
+
walletType,
|
|
478
|
+
walletPurpose,
|
|
479
|
+
sweepTaskParams,
|
|
480
|
+
sweepTaskId
|
|
446
481
|
});
|
|
447
482
|
if (waitForCompletion && response.status === WalletCreationStatus.Pending) {
|
|
448
483
|
return this.waitForWalletCreation(response.wallet_id);
|
|
@@ -505,6 +540,17 @@ class FystackSDK {
|
|
|
505
540
|
const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
|
|
506
541
|
return depositAddressInfo;
|
|
507
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Rescans a transaction on a specific network
|
|
545
|
+
* @param params Transaction hash and network ID
|
|
546
|
+
* @returns Promise that resolves when the rescan is initiated
|
|
547
|
+
*/ async rescanTransaction(params) {
|
|
548
|
+
validateUUID(params.networkId, 'networkId');
|
|
549
|
+
if (!params.txHash || params.txHash.trim() === '') {
|
|
550
|
+
throw new Error('Invalid transaction hash provided');
|
|
551
|
+
}
|
|
552
|
+
await this.apiService.rescanTransaction(params);
|
|
553
|
+
}
|
|
508
554
|
constructor(options){
|
|
509
555
|
const { credentials, environment = Environment.Production, logger = false } = options;
|
|
510
556
|
this.apiService = new APIService(credentials, environment);
|
|
@@ -512,6 +558,16 @@ class FystackSDK {
|
|
|
512
558
|
}
|
|
513
559
|
}
|
|
514
560
|
|
|
561
|
+
class TransactionError extends Error {
|
|
562
|
+
constructor(message, code, transactionId, originalError){
|
|
563
|
+
super(message);
|
|
564
|
+
this.code = code;
|
|
565
|
+
this.transactionId = transactionId;
|
|
566
|
+
this.originalError = originalError;
|
|
567
|
+
this.name = 'TransactionError';
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
515
571
|
class EtherSigner extends AbstractSigner {
|
|
516
572
|
setWallet(walletId) {
|
|
517
573
|
if (!walletId || walletId.trim() === '') {
|
|
@@ -535,7 +591,7 @@ class EtherSigner extends AbstractSigner {
|
|
|
535
591
|
if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
|
|
536
592
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
537
593
|
}
|
|
538
|
-
const detail = await this.APIService.getWalletDetail(
|
|
594
|
+
const detail = await this.APIService.getWalletDetail(AddressType.Evm, this.walletDetail?.WalletID);
|
|
539
595
|
this.walletDetail = detail;
|
|
540
596
|
if (detail?.Address) {
|
|
541
597
|
// cache the address
|
|
@@ -796,7 +852,7 @@ class SolanaSigner {
|
|
|
796
852
|
if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
|
|
797
853
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
798
854
|
}
|
|
799
|
-
const detail = await this.APIService.getWalletDetail(
|
|
855
|
+
const detail = await this.APIService.getWalletDetail(AddressType.Solana, this.walletDetail?.WalletID);
|
|
800
856
|
this.walletDetail = detail;
|
|
801
857
|
if (detail?.Address) {
|
|
802
858
|
// cache the address
|
|
@@ -943,4 +999,4 @@ class SolanaSigner {
|
|
|
943
999
|
}
|
|
944
1000
|
}
|
|
945
1001
|
|
|
946
|
-
export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus,
|
|
1002
|
+
export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, 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://
|
|
19
|
+
return 'https://api-dev.fystack.io';
|
|
20
20
|
case "production":
|
|
21
21
|
return 'https://api.fystack.io';
|
|
22
22
|
}
|
|
@@ -40,7 +40,8 @@ const createAPI = (env)=>{
|
|
|
40
40
|
getTransactionStatus: (walletId, transactionId)=>withBaseURL(`/web3/transaction/${walletId}/${transactionId}`),
|
|
41
41
|
getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
|
|
42
42
|
getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
|
|
43
|
-
getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`)
|
|
43
|
+
getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
|
|
44
|
+
rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
};
|
|
@@ -118,11 +119,54 @@ async function computeHMACForWebhook(apiSecret, event) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
// Wallets
|
|
123
|
+
var WalletType;
|
|
124
|
+
(function(WalletType) {
|
|
125
|
+
WalletType["Standard"] = "standard";
|
|
126
|
+
WalletType["MPC"] = "mpc";
|
|
127
|
+
})(WalletType || (WalletType = {}));
|
|
128
|
+
var WalletPurpose;
|
|
129
|
+
(function(WalletPurpose) {
|
|
130
|
+
WalletPurpose["General"] = "general";
|
|
131
|
+
WalletPurpose["Gastank"] = "gas_tank";
|
|
132
|
+
WalletPurpose["Deployment"] = "deployment";
|
|
133
|
+
WalletPurpose["Custody"] = "custody";
|
|
134
|
+
WalletPurpose["User"] = "user";
|
|
135
|
+
WalletPurpose["Payment"] = "payment";
|
|
136
|
+
})(WalletPurpose || (WalletPurpose = {}));
|
|
137
|
+
var WalletCreationStatus;
|
|
138
|
+
(function(WalletCreationStatus) {
|
|
139
|
+
WalletCreationStatus["Pending"] = "pending";
|
|
140
|
+
WalletCreationStatus["Success"] = "success";
|
|
141
|
+
WalletCreationStatus["Error"] = "error";
|
|
142
|
+
})(WalletCreationStatus || (WalletCreationStatus = {}));
|
|
143
|
+
var AddressType;
|
|
144
|
+
(function(AddressType) {
|
|
145
|
+
AddressType["Evm"] = "evm";
|
|
146
|
+
AddressType["Solana"] = "sol";
|
|
147
|
+
AddressType["Tron"] = "tron";
|
|
148
|
+
})(AddressType || (AddressType = {}));
|
|
149
|
+
var DestinationType;
|
|
150
|
+
(function(DestinationType) {
|
|
151
|
+
DestinationType["InternalWallet"] = "internal_wallet";
|
|
152
|
+
DestinationType["AddressBook"] = "address_book";
|
|
153
|
+
})(DestinationType || (DestinationType = {}));
|
|
154
|
+
var TxStatus;
|
|
155
|
+
(function(TxStatus) {
|
|
156
|
+
TxStatus["Pending"] = "pending";
|
|
157
|
+
TxStatus["Completed"] = "completed";
|
|
158
|
+
TxStatus["Confirmed"] = "confirmed";
|
|
159
|
+
TxStatus["Failed"] = "failed";
|
|
160
|
+
TxStatus["PendingApproval"] = "pending_approval";
|
|
161
|
+
TxStatus["Rejected"] = "rejected";
|
|
162
|
+
})(TxStatus || (TxStatus = {}));
|
|
163
|
+
var TxApprovalStatus;
|
|
164
|
+
(function(TxApprovalStatus) {
|
|
165
|
+
TxApprovalStatus["Pending"] = "pending";
|
|
166
|
+
TxApprovalStatus["Approved"] = "approved";
|
|
167
|
+
TxApprovalStatus["Rejected"] = "rejected";
|
|
168
|
+
})(TxApprovalStatus || (TxApprovalStatus = {}));
|
|
169
|
+
|
|
126
170
|
async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
|
|
127
171
|
if (credentials.apiSecret == '') {
|
|
128
172
|
// If APISecret is not provided, use authToken
|
|
@@ -153,7 +197,7 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
|
|
|
153
197
|
return headers;
|
|
154
198
|
}
|
|
155
199
|
class APIService {
|
|
156
|
-
async getWalletDetail(addressType =
|
|
200
|
+
async getWalletDetail(addressType = AddressType.Evm, walletId) {
|
|
157
201
|
const endpoint = this.API.endpoints.getWalletDetail(walletId);
|
|
158
202
|
const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
|
|
159
203
|
console.info('headers', headers);
|
|
@@ -224,6 +268,16 @@ class APIService {
|
|
|
224
268
|
const response = await get(endpoint, headers);
|
|
225
269
|
return response.data;
|
|
226
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Rescans a transaction on a specific network
|
|
273
|
+
* @param params Transaction hash and network ID
|
|
274
|
+
* @returns API response
|
|
275
|
+
*/ async rescanTransaction(params) {
|
|
276
|
+
const endpoint = this.API.endpoints.rescanTransaction();
|
|
277
|
+
const transformedParams = transformRescanTransactionParams(params);
|
|
278
|
+
const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
|
|
279
|
+
await post(endpoint, transformedParams, headers);
|
|
280
|
+
}
|
|
227
281
|
constructor(credentials, environment){
|
|
228
282
|
this.credentials = credentials;
|
|
229
283
|
this.Webhook = new WebhookService(credentials);
|
|
@@ -325,7 +379,26 @@ function transformWalletDetail(data) {
|
|
|
325
379
|
function transformCreateWalletPayload(data) {
|
|
326
380
|
return {
|
|
327
381
|
name: data.name,
|
|
328
|
-
wallet_type: data.walletType
|
|
382
|
+
wallet_type: data.walletType,
|
|
383
|
+
...data.walletPurpose !== undefined && {
|
|
384
|
+
wallet_purpose: data.walletPurpose
|
|
385
|
+
},
|
|
386
|
+
...data.sweepTaskParams !== undefined && {
|
|
387
|
+
sweep_task_params: {
|
|
388
|
+
min_trigger_value_usd: data.sweepTaskParams?.minTriggerValueUsd,
|
|
389
|
+
destination_wallet_id: data.sweepTaskParams?.destinationWalletId,
|
|
390
|
+
destination_type: data.sweepTaskParams?.destinationType
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
...data.sweepTaskId !== undefined && {
|
|
394
|
+
sweep_task_id: data.sweepTaskId
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function transformRescanTransactionParams(data) {
|
|
399
|
+
return {
|
|
400
|
+
tx_hash: data.txHash,
|
|
401
|
+
network_id: data.networkId
|
|
329
402
|
};
|
|
330
403
|
}
|
|
331
404
|
BigInt.prototype.toJSON = function() {
|
|
@@ -386,47 +459,6 @@ class StatusPoller {
|
|
|
386
459
|
}
|
|
387
460
|
}
|
|
388
461
|
|
|
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
462
|
class FystackSDK {
|
|
431
463
|
log(message) {
|
|
432
464
|
if (this.enableLogging) {
|
|
@@ -439,10 +471,13 @@ class FystackSDK {
|
|
|
439
471
|
* @param waitForCompletion Whether to wait for the wallet creation to complete
|
|
440
472
|
* @returns Promise with wallet ID and status
|
|
441
473
|
*/ async createWallet(options, waitForCompletion = true) {
|
|
442
|
-
const { name, walletType = WalletType.Standard } = options;
|
|
474
|
+
const { name, walletType = WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
|
|
443
475
|
const response = await this.apiService.createWallet({
|
|
444
476
|
name,
|
|
445
|
-
walletType
|
|
477
|
+
walletType,
|
|
478
|
+
walletPurpose,
|
|
479
|
+
sweepTaskParams,
|
|
480
|
+
sweepTaskId
|
|
446
481
|
});
|
|
447
482
|
if (waitForCompletion && response.status === WalletCreationStatus.Pending) {
|
|
448
483
|
return this.waitForWalletCreation(response.wallet_id);
|
|
@@ -505,6 +540,17 @@ class FystackSDK {
|
|
|
505
540
|
const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
|
|
506
541
|
return depositAddressInfo;
|
|
507
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Rescans a transaction on a specific network
|
|
545
|
+
* @param params Transaction hash and network ID
|
|
546
|
+
* @returns Promise that resolves when the rescan is initiated
|
|
547
|
+
*/ async rescanTransaction(params) {
|
|
548
|
+
validateUUID(params.networkId, 'networkId');
|
|
549
|
+
if (!params.txHash || params.txHash.trim() === '') {
|
|
550
|
+
throw new Error('Invalid transaction hash provided');
|
|
551
|
+
}
|
|
552
|
+
await this.apiService.rescanTransaction(params);
|
|
553
|
+
}
|
|
508
554
|
constructor(options){
|
|
509
555
|
const { credentials, environment = Environment.Production, logger = false } = options;
|
|
510
556
|
this.apiService = new APIService(credentials, environment);
|
|
@@ -512,6 +558,16 @@ class FystackSDK {
|
|
|
512
558
|
}
|
|
513
559
|
}
|
|
514
560
|
|
|
561
|
+
class TransactionError extends Error {
|
|
562
|
+
constructor(message, code, transactionId, originalError){
|
|
563
|
+
super(message);
|
|
564
|
+
this.code = code;
|
|
565
|
+
this.transactionId = transactionId;
|
|
566
|
+
this.originalError = originalError;
|
|
567
|
+
this.name = 'TransactionError';
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
515
571
|
class EtherSigner extends AbstractSigner {
|
|
516
572
|
setWallet(walletId) {
|
|
517
573
|
if (!walletId || walletId.trim() === '') {
|
|
@@ -535,7 +591,7 @@ class EtherSigner extends AbstractSigner {
|
|
|
535
591
|
if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
|
|
536
592
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
537
593
|
}
|
|
538
|
-
const detail = await this.APIService.getWalletDetail(
|
|
594
|
+
const detail = await this.APIService.getWalletDetail(AddressType.Evm, this.walletDetail?.WalletID);
|
|
539
595
|
this.walletDetail = detail;
|
|
540
596
|
if (detail?.Address) {
|
|
541
597
|
// cache the address
|
|
@@ -796,7 +852,7 @@ class SolanaSigner {
|
|
|
796
852
|
if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
|
|
797
853
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
798
854
|
}
|
|
799
|
-
const detail = await this.APIService.getWalletDetail(
|
|
855
|
+
const detail = await this.APIService.getWalletDetail(AddressType.Solana, this.walletDetail?.WalletID);
|
|
800
856
|
this.walletDetail = detail;
|
|
801
857
|
if (detail?.Address) {
|
|
802
858
|
// cache the address
|
|
@@ -943,4 +999,4 @@ class SolanaSigner {
|
|
|
943
999
|
}
|
|
944
1000
|
}
|
|
945
1001
|
|
|
946
|
-
export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus,
|
|
1002
|
+
export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformRescanTransactionParams, transformWalletDetail };
|