@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.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://
|
|
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,11 +127,54 @@ async function computeHMACForWebhook(apiSecret, event) {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
180
|
// If APISecret is not provided, use authToken
|
|
@@ -161,7 +205,7 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
|
|
|
161
205
|
return headers;
|
|
162
206
|
}
|
|
163
207
|
class APIService {
|
|
164
|
-
async getWalletDetail(addressType =
|
|
208
|
+
async getWalletDetail(addressType = exports.AddressType.Evm, walletId) {
|
|
165
209
|
const endpoint = this.API.endpoints.getWalletDetail(walletId);
|
|
166
210
|
const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
|
|
167
211
|
console.info('headers', headers);
|
|
@@ -232,6 +276,16 @@ class APIService {
|
|
|
232
276
|
const response = await get(endpoint, headers);
|
|
233
277
|
return response.data;
|
|
234
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
|
+
}
|
|
235
289
|
constructor(credentials, environment){
|
|
236
290
|
this.credentials = credentials;
|
|
237
291
|
this.Webhook = new WebhookService(credentials);
|
|
@@ -333,7 +387,26 @@ function transformWalletDetail(data) {
|
|
|
333
387
|
function transformCreateWalletPayload(data) {
|
|
334
388
|
return {
|
|
335
389
|
name: data.name,
|
|
336
|
-
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
|
|
337
410
|
};
|
|
338
411
|
}
|
|
339
412
|
BigInt.prototype.toJSON = function() {
|
|
@@ -394,47 +467,6 @@ class StatusPoller {
|
|
|
394
467
|
}
|
|
395
468
|
}
|
|
396
469
|
|
|
397
|
-
class TransactionError extends Error {
|
|
398
|
-
constructor(message, code, transactionId, originalError){
|
|
399
|
-
super(message);
|
|
400
|
-
this.code = code;
|
|
401
|
-
this.transactionId = transactionId;
|
|
402
|
-
this.originalError = originalError;
|
|
403
|
-
this.name = 'TransactionError';
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
exports.TxStatus = void 0;
|
|
407
|
-
(function(TxStatus) {
|
|
408
|
-
TxStatus["Pending"] = "pending";
|
|
409
|
-
TxStatus["Completed"] = "completed";
|
|
410
|
-
TxStatus["Confirmed"] = "confirmed";
|
|
411
|
-
TxStatus["Failed"] = "failed";
|
|
412
|
-
TxStatus["PendingApproval"] = "pending_approval";
|
|
413
|
-
TxStatus["Rejected"] = "rejected";
|
|
414
|
-
})(exports.TxStatus || (exports.TxStatus = {}));
|
|
415
|
-
exports.TxApprovalStatus = void 0;
|
|
416
|
-
(function(TxApprovalStatus) {
|
|
417
|
-
TxApprovalStatus["Pending"] = "pending";
|
|
418
|
-
TxApprovalStatus["Approved"] = "approved";
|
|
419
|
-
TxApprovalStatus["Rejected"] = "rejected";
|
|
420
|
-
})(exports.TxApprovalStatus || (exports.TxApprovalStatus = {}));
|
|
421
|
-
exports.WalletType = void 0;
|
|
422
|
-
(function(WalletType) {
|
|
423
|
-
WalletType["Standard"] = "standard";
|
|
424
|
-
WalletType["MPC"] = "mpc";
|
|
425
|
-
})(exports.WalletType || (exports.WalletType = {}));
|
|
426
|
-
exports.WalletCreationStatus = void 0;
|
|
427
|
-
(function(WalletCreationStatus) {
|
|
428
|
-
WalletCreationStatus["Pending"] = "pending";
|
|
429
|
-
WalletCreationStatus["Success"] = "success";
|
|
430
|
-
WalletCreationStatus["Error"] = "error";
|
|
431
|
-
})(exports.WalletCreationStatus || (exports.WalletCreationStatus = {}));
|
|
432
|
-
exports.AddressType = void 0;
|
|
433
|
-
(function(AddressType) {
|
|
434
|
-
AddressType["Evm"] = "evm";
|
|
435
|
-
AddressType["Solana"] = "sol";
|
|
436
|
-
})(exports.AddressType || (exports.AddressType = {}));
|
|
437
|
-
|
|
438
470
|
class FystackSDK {
|
|
439
471
|
log(message) {
|
|
440
472
|
if (this.enableLogging) {
|
|
@@ -447,10 +479,13 @@ class FystackSDK {
|
|
|
447
479
|
* @param waitForCompletion Whether to wait for the wallet creation to complete
|
|
448
480
|
* @returns Promise with wallet ID and status
|
|
449
481
|
*/ async createWallet(options, waitForCompletion = true) {
|
|
450
|
-
const { name, walletType = exports.WalletType.Standard } = options;
|
|
482
|
+
const { name, walletType = exports.WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
|
|
451
483
|
const response = await this.apiService.createWallet({
|
|
452
484
|
name,
|
|
453
|
-
walletType
|
|
485
|
+
walletType,
|
|
486
|
+
walletPurpose,
|
|
487
|
+
sweepTaskParams,
|
|
488
|
+
sweepTaskId
|
|
454
489
|
});
|
|
455
490
|
if (waitForCompletion && response.status === exports.WalletCreationStatus.Pending) {
|
|
456
491
|
return this.waitForWalletCreation(response.wallet_id);
|
|
@@ -513,6 +548,17 @@ class FystackSDK {
|
|
|
513
548
|
const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
|
|
514
549
|
return depositAddressInfo;
|
|
515
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
|
+
}
|
|
516
562
|
constructor(options){
|
|
517
563
|
const { credentials, environment = exports.Environment.Production, logger = false } = options;
|
|
518
564
|
this.apiService = new APIService(credentials, environment);
|
|
@@ -520,6 +566,16 @@ class FystackSDK {
|
|
|
520
566
|
}
|
|
521
567
|
}
|
|
522
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
|
+
|
|
523
579
|
class EtherSigner extends ethers.AbstractSigner {
|
|
524
580
|
setWallet(walletId) {
|
|
525
581
|
if (!walletId || walletId.trim() === '') {
|
|
@@ -543,7 +599,7 @@ class EtherSigner extends ethers.AbstractSigner {
|
|
|
543
599
|
if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
|
|
544
600
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
545
601
|
}
|
|
546
|
-
const detail = await this.APIService.getWalletDetail(exports.
|
|
602
|
+
const detail = await this.APIService.getWalletDetail(exports.AddressType.Evm, this.walletDetail?.WalletID);
|
|
547
603
|
this.walletDetail = detail;
|
|
548
604
|
if (detail?.Address) {
|
|
549
605
|
// cache the address
|
|
@@ -804,7 +860,7 @@ class SolanaSigner {
|
|
|
804
860
|
if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
|
|
805
861
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
806
862
|
}
|
|
807
|
-
const detail = await this.APIService.getWalletDetail(exports.
|
|
863
|
+
const detail = await this.APIService.getWalletDetail(exports.AddressType.Solana, this.walletDetail?.WalletID);
|
|
808
864
|
this.walletDetail = detail;
|
|
809
865
|
if (detail?.Address) {
|
|
810
866
|
// cache the address
|
|
@@ -964,4 +1020,5 @@ exports.createAPI = createAPI;
|
|
|
964
1020
|
exports.get = get;
|
|
965
1021
|
exports.post = post;
|
|
966
1022
|
exports.transformCreateWalletPayload = transformCreateWalletPayload;
|
|
1023
|
+
exports.transformRescanTransactionParams = transformRescanTransactionParams;
|
|
967
1024
|
exports.transformWalletDetail = transformWalletDetail;
|