@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.cjs +145 -55
- package/dist/index.d.cts +352 -270
- package/dist/index.d.mts +352 -270
- package/dist/index.esm.d.ts +352 -270
- package/dist/index.esm.js +145 -56
- package/dist/index.mjs +145 -56
- package/dist/types/index.d.ts +352 -270
- package/package.json +1 -1
- package/readme.md +7 -1
- package/src/api.ts +50 -13
- package/src/config.ts +6 -2
- package/src/enum.ts +52 -0
- package/src/index.ts +1 -0
- package/src/sdk.ts +54 -8
- package/src/signer.ts +16 -3
- package/src/solanaSigner.ts +4 -3
- package/src/types.ts +33 -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
|
}
|
|
@@ -37,6 +37,7 @@ const createAPI = (env)=>{
|
|
|
37
37
|
endpoints: {
|
|
38
38
|
signTransaction: (walletId)=>withBaseURL(`/web3/transaction/${walletId}/signRaw`),
|
|
39
39
|
getWalletDetail: (walletId)=>walletId ? withBaseURL(`/web3/wallet-detail/${walletId}`) : withBaseURL('/web3/wallet-detail'),
|
|
40
|
+
getWallets: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/wallets`),
|
|
40
41
|
createWallet: ()=>withBaseURL('/wallets'),
|
|
41
42
|
createCheckout: ()=>withBaseURL('/checkouts'),
|
|
42
43
|
getCheckout: (checkoutId)=>withBaseURL(`/checkouts/${checkoutId}`),
|
|
@@ -48,7 +49,8 @@ const createAPI = (env)=>{
|
|
|
48
49
|
getTransactionStatus: (walletId, transactionId)=>withBaseURL(`/web3/transaction/${walletId}/${transactionId}`),
|
|
49
50
|
getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
|
|
50
51
|
getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
|
|
51
|
-
getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`)
|
|
52
|
+
getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
|
|
53
|
+
rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
|
|
52
54
|
}
|
|
53
55
|
};
|
|
54
56
|
};
|
|
@@ -126,11 +128,60 @@ async function computeHMACForWebhook(apiSecret, event) {
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
// Wallets
|
|
132
|
+
exports.WalletType = void 0;
|
|
133
|
+
(function(WalletType) {
|
|
134
|
+
WalletType["Standard"] = "standard";
|
|
135
|
+
WalletType["MPC"] = "mpc";
|
|
136
|
+
})(exports.WalletType || (exports.WalletType = {}));
|
|
137
|
+
exports.WalletPurpose = void 0;
|
|
138
|
+
(function(WalletPurpose) {
|
|
139
|
+
WalletPurpose["General"] = "general";
|
|
140
|
+
WalletPurpose["Gastank"] = "gas_tank";
|
|
141
|
+
WalletPurpose["Deployment"] = "deployment";
|
|
142
|
+
WalletPurpose["Custody"] = "custody";
|
|
143
|
+
WalletPurpose["User"] = "user";
|
|
144
|
+
WalletPurpose["Payment"] = "payment";
|
|
145
|
+
})(exports.WalletPurpose || (exports.WalletPurpose = {}));
|
|
146
|
+
exports.WalletCreationStatus = void 0;
|
|
147
|
+
(function(WalletCreationStatus) {
|
|
148
|
+
WalletCreationStatus["Pending"] = "pending";
|
|
149
|
+
WalletCreationStatus["Success"] = "success";
|
|
150
|
+
WalletCreationStatus["Error"] = "error";
|
|
151
|
+
})(exports.WalletCreationStatus || (exports.WalletCreationStatus = {}));
|
|
152
|
+
exports.AddressType = void 0;
|
|
153
|
+
(function(AddressType) {
|
|
154
|
+
AddressType["Evm"] = "evm";
|
|
155
|
+
AddressType["Solana"] = "sol";
|
|
156
|
+
AddressType["Tron"] = "tron";
|
|
157
|
+
})(exports.AddressType || (exports.AddressType = {}));
|
|
158
|
+
exports.DestinationType = void 0;
|
|
159
|
+
(function(DestinationType) {
|
|
160
|
+
DestinationType["InternalWallet"] = "internal_wallet";
|
|
161
|
+
DestinationType["AddressBook"] = "address_book";
|
|
162
|
+
})(exports.DestinationType || (exports.DestinationType = {}));
|
|
163
|
+
exports.TxStatus = void 0;
|
|
164
|
+
(function(TxStatus) {
|
|
165
|
+
TxStatus["Pending"] = "pending";
|
|
166
|
+
TxStatus["Completed"] = "completed";
|
|
167
|
+
TxStatus["Confirmed"] = "confirmed";
|
|
168
|
+
TxStatus["Failed"] = "failed";
|
|
169
|
+
TxStatus["PendingApproval"] = "pending_approval";
|
|
170
|
+
TxStatus["Rejected"] = "rejected";
|
|
171
|
+
})(exports.TxStatus || (exports.TxStatus = {}));
|
|
172
|
+
exports.TxApprovalStatus = void 0;
|
|
173
|
+
(function(TxApprovalStatus) {
|
|
174
|
+
TxApprovalStatus["Pending"] = "pending";
|
|
175
|
+
TxApprovalStatus["Approved"] = "approved";
|
|
176
|
+
TxApprovalStatus["Rejected"] = "rejected";
|
|
177
|
+
})(exports.TxApprovalStatus || (exports.TxApprovalStatus = {}));
|
|
178
|
+
exports.WalletRole = void 0;
|
|
179
|
+
(function(WalletRole) {
|
|
180
|
+
WalletRole["Admin"] = "wallet_admin";
|
|
181
|
+
WalletRole["Signer"] = "wallet_signer";
|
|
182
|
+
WalletRole["Viewer"] = "wallet_viewer";
|
|
183
|
+
})(exports.WalletRole || (exports.WalletRole = {}));
|
|
184
|
+
|
|
134
185
|
async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
|
|
135
186
|
if (credentials.apiSecret == '') {
|
|
136
187
|
// If APISecret is not provided, use authToken
|
|
@@ -161,7 +212,13 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
|
|
|
161
212
|
return headers;
|
|
162
213
|
}
|
|
163
214
|
class APIService {
|
|
164
|
-
async
|
|
215
|
+
async getWallets(workspaceId) {
|
|
216
|
+
const endpoint = this.API.endpoints.getWallets(workspaceId);
|
|
217
|
+
const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
|
|
218
|
+
const response = await get(endpoint, headers);
|
|
219
|
+
return response.data;
|
|
220
|
+
}
|
|
221
|
+
async getWalletDetail(addressType = exports.AddressType.Evm, walletId) {
|
|
165
222
|
const endpoint = this.API.endpoints.getWalletDetail(walletId);
|
|
166
223
|
const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
|
|
167
224
|
console.info('headers', headers);
|
|
@@ -232,6 +289,16 @@ class APIService {
|
|
|
232
289
|
const response = await get(endpoint, headers);
|
|
233
290
|
return response.data;
|
|
234
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Rescans a transaction on a specific network
|
|
294
|
+
* @param params Transaction hash and network ID
|
|
295
|
+
* @returns API response
|
|
296
|
+
*/ async rescanTransaction(params) {
|
|
297
|
+
const endpoint = this.API.endpoints.rescanTransaction();
|
|
298
|
+
const transformedParams = transformRescanTransactionParams(params);
|
|
299
|
+
const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
|
|
300
|
+
await post(endpoint, transformedParams, headers);
|
|
301
|
+
}
|
|
235
302
|
constructor(credentials, environment){
|
|
236
303
|
this.credentials = credentials;
|
|
237
304
|
this.Webhook = new WebhookService(credentials);
|
|
@@ -333,7 +400,26 @@ function transformWalletDetail(data) {
|
|
|
333
400
|
function transformCreateWalletPayload(data) {
|
|
334
401
|
return {
|
|
335
402
|
name: data.name,
|
|
336
|
-
wallet_type: data.walletType
|
|
403
|
+
wallet_type: data.walletType,
|
|
404
|
+
...data.walletPurpose !== undefined && {
|
|
405
|
+
wallet_purpose: data.walletPurpose
|
|
406
|
+
},
|
|
407
|
+
...data.sweepTaskParams !== undefined && {
|
|
408
|
+
sweep_task_params: {
|
|
409
|
+
min_trigger_value_usd: data.sweepTaskParams?.minTriggerValueUsd,
|
|
410
|
+
destination_wallet_id: data.sweepTaskParams?.destinationWalletId,
|
|
411
|
+
destination_type: data.sweepTaskParams?.destinationType
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
...data.sweepTaskId !== undefined && {
|
|
415
|
+
sweep_task_id: data.sweepTaskId
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function transformRescanTransactionParams(data) {
|
|
420
|
+
return {
|
|
421
|
+
tx_hash: data.txHash,
|
|
422
|
+
network_id: data.networkId
|
|
337
423
|
};
|
|
338
424
|
}
|
|
339
425
|
BigInt.prototype.toJSON = function() {
|
|
@@ -394,47 +480,6 @@ class StatusPoller {
|
|
|
394
480
|
}
|
|
395
481
|
}
|
|
396
482
|
|
|
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
483
|
class FystackSDK {
|
|
439
484
|
log(message) {
|
|
440
485
|
if (this.enableLogging) {
|
|
@@ -447,10 +492,13 @@ class FystackSDK {
|
|
|
447
492
|
* @param waitForCompletion Whether to wait for the wallet creation to complete
|
|
448
493
|
* @returns Promise with wallet ID and status
|
|
449
494
|
*/ async createWallet(options, waitForCompletion = true) {
|
|
450
|
-
const { name, walletType = exports.WalletType.Standard } = options;
|
|
495
|
+
const { name, walletType = exports.WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
|
|
451
496
|
const response = await this.apiService.createWallet({
|
|
452
497
|
name,
|
|
453
|
-
walletType
|
|
498
|
+
walletType,
|
|
499
|
+
walletPurpose,
|
|
500
|
+
sweepTaskParams,
|
|
501
|
+
sweepTaskId
|
|
454
502
|
});
|
|
455
503
|
if (waitForCompletion && response.status === exports.WalletCreationStatus.Pending) {
|
|
456
504
|
return this.waitForWalletCreation(response.wallet_id);
|
|
@@ -458,6 +506,16 @@ class FystackSDK {
|
|
|
458
506
|
return response;
|
|
459
507
|
}
|
|
460
508
|
/**
|
|
509
|
+
* Gets all wallets for the workspace
|
|
510
|
+
* @returns Promise with list of wallets
|
|
511
|
+
*/ async getWallets() {
|
|
512
|
+
if (!this.workspaceId) {
|
|
513
|
+
throw new Error('Workspace ID is required. Please set workspaceId in the constructor.');
|
|
514
|
+
}
|
|
515
|
+
const wallets = await this.apiService.getWallets(this.workspaceId);
|
|
516
|
+
return wallets;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
461
519
|
* Gets the current status of a wallet creation process
|
|
462
520
|
* @param walletId The ID of the wallet being created
|
|
463
521
|
* @returns Promise with wallet creation status details
|
|
@@ -513,10 +571,32 @@ class FystackSDK {
|
|
|
513
571
|
const depositAddressInfo = await this.apiService.getDepositAddress(walletId, addressType);
|
|
514
572
|
return depositAddressInfo;
|
|
515
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Rescans a transaction on a specific network
|
|
576
|
+
* @param params Transaction hash and network ID
|
|
577
|
+
* @returns Promise that resolves when the rescan is initiated
|
|
578
|
+
*/ async rescanTransaction(params) {
|
|
579
|
+
validateUUID(params.networkId, 'networkId');
|
|
580
|
+
if (!params.txHash || params.txHash.trim() === '') {
|
|
581
|
+
throw new Error('Invalid transaction hash provided');
|
|
582
|
+
}
|
|
583
|
+
await this.apiService.rescanTransaction(params);
|
|
584
|
+
}
|
|
516
585
|
constructor(options){
|
|
517
|
-
const { credentials, environment = exports.Environment.Production, logger = false } = options;
|
|
586
|
+
const { credentials, workspaceId, environment = exports.Environment.Production, logger = false } = options;
|
|
518
587
|
this.apiService = new APIService(credentials, environment);
|
|
519
588
|
this.enableLogging = logger;
|
|
589
|
+
this.workspaceId = workspaceId;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
class TransactionError extends Error {
|
|
594
|
+
constructor(message, code, transactionId, originalError){
|
|
595
|
+
super(message);
|
|
596
|
+
this.code = code;
|
|
597
|
+
this.transactionId = transactionId;
|
|
598
|
+
this.originalError = originalError;
|
|
599
|
+
this.name = 'TransactionError';
|
|
520
600
|
}
|
|
521
601
|
}
|
|
522
602
|
|
|
@@ -543,7 +623,7 @@ class EtherSigner extends ethers.AbstractSigner {
|
|
|
543
623
|
if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
|
|
544
624
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
545
625
|
}
|
|
546
|
-
const detail = await this.APIService.getWalletDetail(exports.
|
|
626
|
+
const detail = await this.APIService.getWalletDetail(exports.AddressType.Evm, this.walletDetail?.WalletID);
|
|
547
627
|
this.walletDetail = detail;
|
|
548
628
|
if (detail?.Address) {
|
|
549
629
|
// cache the address
|
|
@@ -607,6 +687,12 @@ class EtherSigner extends ethers.AbstractSigner {
|
|
|
607
687
|
async signTransaction(tx) {
|
|
608
688
|
const startTime = new Date();
|
|
609
689
|
console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`);
|
|
690
|
+
if (!this.address) {
|
|
691
|
+
await this.getAddress();
|
|
692
|
+
}
|
|
693
|
+
if (!this.walletDetail) {
|
|
694
|
+
this.walletDetail = await this.APIService.getWalletDetail();
|
|
695
|
+
}
|
|
610
696
|
// Replace any Addressable or ENS name with an address
|
|
611
697
|
const { to, from } = await ethers.resolveProperties({
|
|
612
698
|
to: tx.to ? ethers.resolveAddress(tx.to, this.provider) : undefined,
|
|
@@ -653,6 +739,9 @@ class EtherSigner extends ethers.AbstractSigner {
|
|
|
653
739
|
if (!this.address) {
|
|
654
740
|
await this.getAddress();
|
|
655
741
|
}
|
|
742
|
+
if (!this.walletDetail) {
|
|
743
|
+
this.walletDetail = await this.APIService.getWalletDetail();
|
|
744
|
+
}
|
|
656
745
|
checkProvider(this, 'sendTransaction');
|
|
657
746
|
// Only populate if gas fees are not set
|
|
658
747
|
const hasGasFees = tx.gasPrice != null || tx.maxFeePerGas != null && tx.maxPriorityFeePerGas != null;
|
|
@@ -804,7 +893,7 @@ class SolanaSigner {
|
|
|
804
893
|
if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
|
|
805
894
|
throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
|
|
806
895
|
}
|
|
807
|
-
const detail = await this.APIService.getWalletDetail(exports.
|
|
896
|
+
const detail = await this.APIService.getWalletDetail(exports.AddressType.Solana, this.walletDetail?.WalletID);
|
|
808
897
|
this.walletDetail = detail;
|
|
809
898
|
if (detail?.Address) {
|
|
810
899
|
// cache the address
|
|
@@ -964,4 +1053,5 @@ exports.createAPI = createAPI;
|
|
|
964
1053
|
exports.get = get;
|
|
965
1054
|
exports.post = post;
|
|
966
1055
|
exports.transformCreateWalletPayload = transformCreateWalletPayload;
|
|
1056
|
+
exports.transformRescanTransactionParams = transformRescanTransactionParams;
|
|
967
1057
|
exports.transformWalletDetail = transformWalletDetail;
|