@fystack/sdk 0.1.8 → 0.1.10

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
@@ -42,7 +42,9 @@ const createAPI = (env)=>{
42
42
  getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
43
43
  getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
44
44
  getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
45
- rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
45
+ rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction'),
46
+ requestWithdrawal: (walletId)=>withBaseURL(`/wallets/${walletId}/request-withdrawal`),
47
+ getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`)
46
48
  }
47
49
  };
48
50
  };
@@ -123,7 +125,7 @@ async function computeHMACForWebhook(apiSecret, event) {
123
125
  // Wallets
124
126
  var WalletType;
125
127
  (function(WalletType) {
126
- WalletType["Standard"] = "standard";
128
+ WalletType["Hyper"] = "standard";
127
129
  WalletType["MPC"] = "mpc";
128
130
  })(WalletType || (WalletType = {}));
129
131
  var WalletPurpose;
@@ -173,6 +175,16 @@ var WalletRole;
173
175
  WalletRole["Signer"] = "wallet_signer";
174
176
  WalletRole["Viewer"] = "wallet_viewer";
175
177
  })(WalletRole || (WalletRole = {}));
178
+ var WithdrawalStatus;
179
+ (function(WithdrawalStatus) {
180
+ WithdrawalStatus["Pending"] = "pending";
181
+ WithdrawalStatus["PendingApproval"] = "pending_approval";
182
+ WithdrawalStatus["Approved"] = "approved";
183
+ WithdrawalStatus["Rejected"] = "rejected";
184
+ WithdrawalStatus["Processing"] = "processing";
185
+ WithdrawalStatus["Completed"] = "completed";
186
+ WithdrawalStatus["Failed"] = "failed";
187
+ })(WithdrawalStatus || (WithdrawalStatus = {}));
176
188
 
177
189
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
178
190
  if (!credentials.apiSecret || credentials.apiSecret === '') {
@@ -292,6 +304,28 @@ class APIService {
292
304
  const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
293
305
  await post(endpoint, transformedParams, headers);
294
306
  }
307
+ /**
308
+ * Requests a withdrawal from a wallet
309
+ * @param walletId The wallet ID
310
+ * @param params Withdrawal parameters
311
+ * @returns Withdrawal response with auto_approved status and withdrawal details
312
+ */ async requestWithdrawal(walletId, params) {
313
+ const endpoint = this.API.endpoints.requestWithdrawal(walletId);
314
+ const transformedParams = transformRequestWithdrawalParams(params);
315
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
316
+ const response = await post(endpoint, transformedParams, headers);
317
+ return response.data;
318
+ }
319
+ /**
320
+ * Gets the webhook public key for a workspace
321
+ * @param workspaceId The workspace ID
322
+ * @returns Webhook public key response with base64 encoded ed25519 public key
323
+ */ async getWebhookPublicKey(workspaceId) {
324
+ const endpoint = this.API.endpoints.getWebhookPublicKey(workspaceId);
325
+ const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
326
+ const response = await get(endpoint, headers);
327
+ return response.data;
328
+ }
295
329
  constructor(credentials, environment){
296
330
  this.credentials = credentials;
297
331
  this.Webhook = new WebhookService(credentials);
@@ -415,6 +449,19 @@ function transformRescanTransactionParams(data) {
415
449
  network_id: data.networkId
416
450
  };
417
451
  }
452
+ function transformRequestWithdrawalParams(data) {
453
+ return {
454
+ asset_id: data.assetId,
455
+ amount: data.amount,
456
+ recipient_address: data.recipientAddress,
457
+ ...data.notes !== undefined && {
458
+ notes: data.notes
459
+ },
460
+ ...data.skipBalanceCheck !== undefined && {
461
+ skip_balance_check: data.skipBalanceCheck
462
+ }
463
+ };
464
+ }
418
465
  BigInt.prototype.toJSON = function() {
419
466
  return this.toString();
420
467
  };
@@ -485,7 +532,7 @@ class FystackSDK {
485
532
  * @param waitForCompletion Whether to wait for the wallet creation to complete
486
533
  * @returns Promise with wallet ID and status
487
534
  */ async createWallet(options, waitForCompletion = true) {
488
- const { name, walletType = WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
535
+ const { name, walletType = WalletType.Hyper, sweepTaskParams, walletPurpose, sweepTaskId } = options;
489
536
  const response = await this.apiService.createWallet({
490
537
  name,
491
538
  walletType,
@@ -575,6 +622,41 @@ class FystackSDK {
575
622
  }
576
623
  await this.apiService.rescanTransaction(params);
577
624
  }
625
+ /**
626
+ * Requests a withdrawal from a wallet
627
+ * @param walletId The ID of the wallet to withdraw from
628
+ * @param params Withdrawal parameters including asset, amount, and recipient
629
+ * @returns Promise with withdrawal response including auto_approved status and withdrawal details
630
+ */ async requestWithdrawal(walletId, params) {
631
+ validateUUID(walletId, 'walletId');
632
+ validateUUID(params.assetId, 'assetId');
633
+ if (!params.amount || params.amount.trim() === '') {
634
+ throw new Error('Invalid amount provided');
635
+ }
636
+ if (!params.recipientAddress || params.recipientAddress.trim() === '') {
637
+ throw new Error('Invalid recipient address provided');
638
+ }
639
+ if (params.recipientAddress.length > 256) {
640
+ throw new Error('Recipient address exceeds maximum length of 256 characters');
641
+ }
642
+ if (params.notes && params.notes.length > 500) {
643
+ throw new Error('Notes exceed maximum length of 500 characters');
644
+ }
645
+ this.log(`Requesting withdrawal from wallet ${walletId}`);
646
+ const response = await this.apiService.requestWithdrawal(walletId, params);
647
+ this.log(`Withdrawal request completed, auto_approved: ${response.auto_approved}`);
648
+ return response;
649
+ }
650
+ /**
651
+ * Gets the webhook public key for a workspace
652
+ * @param workspaceId The workspace ID
653
+ * @returns Promise with webhook public key (base64 encoded ed25519 public key)
654
+ */ async getWebhookPublicKey(workspaceId) {
655
+ validateUUID(workspaceId, 'workspaceId');
656
+ this.log(`Getting webhook public key for workspace ${workspaceId}`);
657
+ const response = await this.apiService.getWebhookPublicKey(workspaceId);
658
+ return response;
659
+ }
578
660
  constructor(options){
579
661
  const { credentials, workspaceId, environment = Environment.Production, logger = false } = options;
580
662
  this.apiService = new APIService(credentials, environment);
@@ -1033,4 +1115,4 @@ class SolanaSigner {
1033
1115
  }
1034
1116
  }
1035
1117
 
1036
- 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 };
1118
+ export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, WithdrawalStatus, createAPI, get, post, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };
package/dist/index.mjs CHANGED
@@ -42,7 +42,9 @@ const createAPI = (env)=>{
42
42
  getWalletCreationStatus: (walletId)=>withBaseURL(`/wallets/creation-status/${walletId}`),
43
43
  getWalletAssets: (walletId)=>withBaseURL(`/wallets/${walletId}/assets`),
44
44
  getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
45
- rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction')
45
+ rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction'),
46
+ requestWithdrawal: (walletId)=>withBaseURL(`/wallets/${walletId}/request-withdrawal`),
47
+ getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`)
46
48
  }
47
49
  };
48
50
  };
@@ -123,7 +125,7 @@ async function computeHMACForWebhook(apiSecret, event) {
123
125
  // Wallets
124
126
  var WalletType;
125
127
  (function(WalletType) {
126
- WalletType["Standard"] = "standard";
128
+ WalletType["Hyper"] = "standard";
127
129
  WalletType["MPC"] = "mpc";
128
130
  })(WalletType || (WalletType = {}));
129
131
  var WalletPurpose;
@@ -173,6 +175,16 @@ var WalletRole;
173
175
  WalletRole["Signer"] = "wallet_signer";
174
176
  WalletRole["Viewer"] = "wallet_viewer";
175
177
  })(WalletRole || (WalletRole = {}));
178
+ var WithdrawalStatus;
179
+ (function(WithdrawalStatus) {
180
+ WithdrawalStatus["Pending"] = "pending";
181
+ WithdrawalStatus["PendingApproval"] = "pending_approval";
182
+ WithdrawalStatus["Approved"] = "approved";
183
+ WithdrawalStatus["Rejected"] = "rejected";
184
+ WithdrawalStatus["Processing"] = "processing";
185
+ WithdrawalStatus["Completed"] = "completed";
186
+ WithdrawalStatus["Failed"] = "failed";
187
+ })(WithdrawalStatus || (WithdrawalStatus = {}));
176
188
 
177
189
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
178
190
  if (!credentials.apiSecret || credentials.apiSecret === '') {
@@ -292,6 +304,28 @@ class APIService {
292
304
  const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
293
305
  await post(endpoint, transformedParams, headers);
294
306
  }
307
+ /**
308
+ * Requests a withdrawal from a wallet
309
+ * @param walletId The wallet ID
310
+ * @param params Withdrawal parameters
311
+ * @returns Withdrawal response with auto_approved status and withdrawal details
312
+ */ async requestWithdrawal(walletId, params) {
313
+ const endpoint = this.API.endpoints.requestWithdrawal(walletId);
314
+ const transformedParams = transformRequestWithdrawalParams(params);
315
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
316
+ const response = await post(endpoint, transformedParams, headers);
317
+ return response.data;
318
+ }
319
+ /**
320
+ * Gets the webhook public key for a workspace
321
+ * @param workspaceId The workspace ID
322
+ * @returns Webhook public key response with base64 encoded ed25519 public key
323
+ */ async getWebhookPublicKey(workspaceId) {
324
+ const endpoint = this.API.endpoints.getWebhookPublicKey(workspaceId);
325
+ const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint);
326
+ const response = await get(endpoint, headers);
327
+ return response.data;
328
+ }
295
329
  constructor(credentials, environment){
296
330
  this.credentials = credentials;
297
331
  this.Webhook = new WebhookService(credentials);
@@ -415,6 +449,19 @@ function transformRescanTransactionParams(data) {
415
449
  network_id: data.networkId
416
450
  };
417
451
  }
452
+ function transformRequestWithdrawalParams(data) {
453
+ return {
454
+ asset_id: data.assetId,
455
+ amount: data.amount,
456
+ recipient_address: data.recipientAddress,
457
+ ...data.notes !== undefined && {
458
+ notes: data.notes
459
+ },
460
+ ...data.skipBalanceCheck !== undefined && {
461
+ skip_balance_check: data.skipBalanceCheck
462
+ }
463
+ };
464
+ }
418
465
  BigInt.prototype.toJSON = function() {
419
466
  return this.toString();
420
467
  };
@@ -485,7 +532,7 @@ class FystackSDK {
485
532
  * @param waitForCompletion Whether to wait for the wallet creation to complete
486
533
  * @returns Promise with wallet ID and status
487
534
  */ async createWallet(options, waitForCompletion = true) {
488
- const { name, walletType = WalletType.Standard, sweepTaskParams, walletPurpose, sweepTaskId } = options;
535
+ const { name, walletType = WalletType.Hyper, sweepTaskParams, walletPurpose, sweepTaskId } = options;
489
536
  const response = await this.apiService.createWallet({
490
537
  name,
491
538
  walletType,
@@ -575,6 +622,41 @@ class FystackSDK {
575
622
  }
576
623
  await this.apiService.rescanTransaction(params);
577
624
  }
625
+ /**
626
+ * Requests a withdrawal from a wallet
627
+ * @param walletId The ID of the wallet to withdraw from
628
+ * @param params Withdrawal parameters including asset, amount, and recipient
629
+ * @returns Promise with withdrawal response including auto_approved status and withdrawal details
630
+ */ async requestWithdrawal(walletId, params) {
631
+ validateUUID(walletId, 'walletId');
632
+ validateUUID(params.assetId, 'assetId');
633
+ if (!params.amount || params.amount.trim() === '') {
634
+ throw new Error('Invalid amount provided');
635
+ }
636
+ if (!params.recipientAddress || params.recipientAddress.trim() === '') {
637
+ throw new Error('Invalid recipient address provided');
638
+ }
639
+ if (params.recipientAddress.length > 256) {
640
+ throw new Error('Recipient address exceeds maximum length of 256 characters');
641
+ }
642
+ if (params.notes && params.notes.length > 500) {
643
+ throw new Error('Notes exceed maximum length of 500 characters');
644
+ }
645
+ this.log(`Requesting withdrawal from wallet ${walletId}`);
646
+ const response = await this.apiService.requestWithdrawal(walletId, params);
647
+ this.log(`Withdrawal request completed, auto_approved: ${response.auto_approved}`);
648
+ return response;
649
+ }
650
+ /**
651
+ * Gets the webhook public key for a workspace
652
+ * @param workspaceId The workspace ID
653
+ * @returns Promise with webhook public key (base64 encoded ed25519 public key)
654
+ */ async getWebhookPublicKey(workspaceId) {
655
+ validateUUID(workspaceId, 'workspaceId');
656
+ this.log(`Getting webhook public key for workspace ${workspaceId}`);
657
+ const response = await this.apiService.getWebhookPublicKey(workspaceId);
658
+ return response;
659
+ }
578
660
  constructor(options){
579
661
  const { credentials, workspaceId, environment = Environment.Production, logger = false } = options;
580
662
  this.apiService = new APIService(credentials, environment);
@@ -1033,4 +1115,4 @@ class SolanaSigner {
1033
1115
  }
1034
1116
  }
1035
1117
 
1036
- 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 };
1118
+ export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, WithdrawalStatus, createAPI, get, post, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };
@@ -22,6 +22,8 @@ interface APIEndpoints {
22
22
  getWalletAssets: (walletId: string) => string;
23
23
  getDepositAddress: (walletId: string, addressType: string) => string;
24
24
  rescanTransaction: () => string;
25
+ requestWithdrawal: (walletId: string) => string;
26
+ getWebhookPublicKey: (workspaceId: string) => string;
25
27
  }
26
28
  interface APIConfig {
27
29
  baseURL: string;
@@ -276,7 +278,7 @@ interface GetCheckoutPaymentResponse {
276
278
  }
277
279
 
278
280
  declare enum WalletType {
279
- Standard = "standard",
281
+ Hyper = "standard",
280
282
  MPC = "mpc"
281
283
  }
282
284
  declare enum WalletPurpose {
@@ -319,6 +321,15 @@ declare enum WalletRole {
319
321
  Signer = "wallet_signer",
320
322
  Viewer = "wallet_viewer"
321
323
  }
324
+ declare enum WithdrawalStatus {
325
+ Pending = "pending",
326
+ PendingApproval = "pending_approval",
327
+ Approved = "approved",
328
+ Rejected = "rejected",
329
+ Processing = "processing",
330
+ Completed = "completed",
331
+ Failed = "failed"
332
+ }
322
333
 
323
334
  interface APIResponse {
324
335
  data: any;
@@ -382,6 +393,19 @@ declare class APIService {
382
393
  * @returns API response
383
394
  */
384
395
  rescanTransaction(params: RescanTransactionParams): Promise<void>;
396
+ /**
397
+ * Requests a withdrawal from a wallet
398
+ * @param walletId The wallet ID
399
+ * @param params Withdrawal parameters
400
+ * @returns Withdrawal response with auto_approved status and withdrawal details
401
+ */
402
+ requestWithdrawal(walletId: string, params: RequestWithdrawalParams): Promise<RequestWithdrawalResponse>;
403
+ /**
404
+ * Gets the webhook public key for a workspace
405
+ * @param workspaceId The workspace ID
406
+ * @returns Webhook public key response with base64 encoded ed25519 public key
407
+ */
408
+ getWebhookPublicKey(workspaceId: string): Promise<WebhookPublicKeyResponse>;
385
409
  }
386
410
  declare class PaymentService {
387
411
  private apiKey;
@@ -415,6 +439,13 @@ declare function transformRescanTransactionParams(data: RescanTransactionParams)
415
439
  tx_hash: string;
416
440
  network_id: string;
417
441
  };
442
+ declare function transformRequestWithdrawalParams(data: RequestWithdrawalParams): {
443
+ skip_balance_check?: boolean | undefined;
444
+ notes?: string | undefined;
445
+ asset_id: string;
446
+ amount: string;
447
+ recipient_address: string;
448
+ };
418
449
 
419
450
  declare class TransactionError extends Error {
420
451
  readonly code: string;
@@ -555,6 +586,57 @@ interface WalletByWorkspaceResponse {
555
586
  top_assets: TopAssets[];
556
587
  wallet_purpose: string;
557
588
  }
589
+ interface RequestWithdrawalParams {
590
+ assetId: string;
591
+ amount: string;
592
+ recipientAddress: string;
593
+ notes?: string;
594
+ skipBalanceCheck?: boolean;
595
+ }
596
+ interface WithdrawalApproval {
597
+ id: string;
598
+ user_id: string;
599
+ status: string;
600
+ created_at: string;
601
+ updated_at: string;
602
+ }
603
+ interface WithdrawalTransaction {
604
+ id: string;
605
+ hash?: string;
606
+ status: string;
607
+ created_at: string;
608
+ updated_at: string;
609
+ }
610
+ interface TxCategory {
611
+ id: string;
612
+ name: string;
613
+ }
614
+ interface Withdrawal {
615
+ id: string;
616
+ created_at: string;
617
+ updated_at: string;
618
+ amount: string;
619
+ status: WithdrawalStatus;
620
+ recipient_address: string;
621
+ notes?: string;
622
+ withdrawal_approvals: WithdrawalApproval[];
623
+ creator_id: string;
624
+ asset_id: string;
625
+ asset?: WalletAssetDetail;
626
+ wallet_id: string;
627
+ transaction_id?: string;
628
+ transaction?: WithdrawalTransaction;
629
+ asset_hold_id: string;
630
+ error_reason?: string;
631
+ categories?: TxCategory[];
632
+ }
633
+ interface RequestWithdrawalResponse {
634
+ auto_approved: boolean;
635
+ withdrawal: Withdrawal;
636
+ }
637
+ interface WebhookPublicKeyResponse {
638
+ public_key: string;
639
+ }
558
640
 
559
641
  interface SDKOptions {
560
642
  credentials: APICredentials;
@@ -611,6 +693,19 @@ declare class FystackSDK {
611
693
  * @returns Promise that resolves when the rescan is initiated
612
694
  */
613
695
  rescanTransaction(params: RescanTransactionParams): Promise<void>;
696
+ /**
697
+ * Requests a withdrawal from a wallet
698
+ * @param walletId The ID of the wallet to withdraw from
699
+ * @param params Withdrawal parameters including asset, amount, and recipient
700
+ * @returns Promise with withdrawal response including auto_approved status and withdrawal details
701
+ */
702
+ requestWithdrawal(walletId: string, params: RequestWithdrawalParams): Promise<RequestWithdrawalResponse>;
703
+ /**
704
+ * Gets the webhook public key for a workspace
705
+ * @param workspaceId The workspace ID
706
+ * @returns Promise with webhook public key (base64 encoded ed25519 public key)
707
+ */
708
+ getWebhookPublicKey(workspaceId: string): Promise<WebhookPublicKeyResponse>;
614
709
  }
615
710
 
616
711
  interface StatusPollerOptions {
@@ -708,4 +803,4 @@ declare class SolanaSigner {
708
803
  private incorporateSignatureIntoTransaction;
709
804
  }
710
805
 
711
- export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, DestinationType, Environment, EtherSigner, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type RescanTransactionParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, type SweepTaskParams, type TopAssets, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, type WalletByWorkspaceResponse, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletPurpose, type WalletResponse, WalletRole, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformRescanTransactionParams, transformWalletDetail };
806
+ export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, DestinationType, Environment, EtherSigner, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type RequestWithdrawalParams, type RequestWithdrawalResponse, type RescanTransactionParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, type SweepTaskParams, type TopAssets, TransactionError, type TransactionStatusResponse, TxApprovalStatus, type TxCategory, TxStatus, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, type WalletByWorkspaceResponse, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletPurpose, type WalletResponse, WalletRole, WalletType, type WebhookEvent, type WebhookPublicKeyResponse, WebhookService, type Withdrawal, type WithdrawalApproval, WithdrawalStatus, type WithdrawalTransaction, createAPI, get, post, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fystack/sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Wallet SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/types/index.d.ts",
package/src/api.ts CHANGED
@@ -13,7 +13,10 @@ import {
13
13
  WalletAsset,
14
14
  DepositAddressResponse,
15
15
  RescanTransactionParams,
16
- WalletByWorkspaceResponse
16
+ WalletByWorkspaceResponse,
17
+ RequestWithdrawalParams,
18
+ RequestWithdrawalResponse,
19
+ WebhookPublicKeyResponse
17
20
  } from './types'
18
21
  import {
19
22
  CreateCheckoutPayload,
@@ -232,6 +235,35 @@ export class APIService {
232
235
  const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams)
233
236
  await post(endpoint, transformedParams, headers)
234
237
  }
238
+
239
+ /**
240
+ * Requests a withdrawal from a wallet
241
+ * @param walletId The wallet ID
242
+ * @param params Withdrawal parameters
243
+ * @returns Withdrawal response with auto_approved status and withdrawal details
244
+ */
245
+ async requestWithdrawal(
246
+ walletId: string,
247
+ params: RequestWithdrawalParams
248
+ ): Promise<RequestWithdrawalResponse> {
249
+ const endpoint = this.API.endpoints.requestWithdrawal(walletId)
250
+ const transformedParams = transformRequestWithdrawalParams(params)
251
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams)
252
+ const response = await post(endpoint, transformedParams, headers)
253
+ return response.data
254
+ }
255
+
256
+ /**
257
+ * Gets the webhook public key for a workspace
258
+ * @param workspaceId The workspace ID
259
+ * @returns Webhook public key response with base64 encoded ed25519 public key
260
+ */
261
+ async getWebhookPublicKey(workspaceId: string): Promise<WebhookPublicKeyResponse> {
262
+ const endpoint = this.API.endpoints.getWebhookPublicKey(workspaceId)
263
+ const headers = await composeAPIHeaders(this.credentials, 'GET', endpoint)
264
+ const response = await get(endpoint, headers)
265
+ return response.data
266
+ }
235
267
  }
236
268
 
237
269
  export class PaymentService {
@@ -380,6 +412,16 @@ export function transformRescanTransactionParams(data: RescanTransactionParams)
380
412
  }
381
413
  }
382
414
 
415
+ export function transformRequestWithdrawalParams(data: RequestWithdrawalParams) {
416
+ return {
417
+ asset_id: data.assetId,
418
+ amount: data.amount,
419
+ recipient_address: data.recipientAddress,
420
+ ...(data.notes !== undefined && { notes: data.notes }),
421
+ ...(data.skipBalanceCheck !== undefined && { skip_balance_check: data.skipBalanceCheck })
422
+ }
423
+ }
424
+
383
425
  ;(BigInt.prototype as any).toJSON = function () {
384
426
  return this.toString()
385
427
  }
package/src/config.ts CHANGED
@@ -21,6 +21,8 @@ export interface APIEndpoints {
21
21
  getWalletAssets: (walletId: string) => string
22
22
  getDepositAddress: (walletId: string, addressType: string) => string
23
23
  rescanTransaction: () => string
24
+ requestWithdrawal: (walletId: string) => string
25
+ getWebhookPublicKey: (workspaceId: string) => string
24
26
  }
25
27
 
26
28
  const getBaseURL = (env: Environment): string => {
@@ -71,7 +73,9 @@ const createAPI = (env: Environment): APIConfig => {
71
73
  getWalletAssets: (walletId: string) => withBaseURL(`/wallets/${walletId}/assets`),
72
74
  getDepositAddress: (walletId: string, addressType: string) =>
73
75
  withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
74
- rescanTransaction: () => withBaseURL('/networks/rescan-transaction')
76
+ rescanTransaction: () => withBaseURL('/networks/rescan-transaction'),
77
+ requestWithdrawal: (walletId: string) => withBaseURL(`/wallets/${walletId}/request-withdrawal`),
78
+ getWebhookPublicKey: (workspaceId: string) => withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`)
75
79
  }
76
80
  }
77
81
  }
package/src/enum.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Wallets
2
2
  export enum WalletType {
3
- Standard = 'standard',
3
+ Hyper = 'standard',
4
4
  MPC = 'mpc'
5
5
  }
6
6
 
@@ -50,3 +50,13 @@ export enum WalletRole {
50
50
  Signer = 'wallet_signer',
51
51
  Viewer = 'wallet_viewer'
52
52
  }
53
+
54
+ export enum WithdrawalStatus {
55
+ Pending = 'pending',
56
+ PendingApproval = 'pending_approval',
57
+ Approved = 'approved',
58
+ Rejected = 'rejected',
59
+ Processing = 'processing',
60
+ Completed = 'completed',
61
+ Failed = 'failed'
62
+ }
package/src/sdk.ts CHANGED
@@ -9,7 +9,10 @@ import {
9
9
  APICredentials,
10
10
  CreateWalletOptions,
11
11
  RescanTransactionParams,
12
- WalletByWorkspaceResponse
12
+ WalletByWorkspaceResponse,
13
+ RequestWithdrawalParams,
14
+ RequestWithdrawalResponse,
15
+ WebhookPublicKeyResponse
13
16
  } from './types'
14
17
  import { validateUUID } from './utils'
15
18
  import { AddressType, WalletCreationStatus, WalletType } from './enum'
@@ -56,7 +59,7 @@ export class FystackSDK {
56
59
  ): Promise<CreateWalletResponse> {
57
60
  const {
58
61
  name,
59
- walletType = WalletType.Standard,
62
+ walletType = WalletType.Hyper,
60
63
  sweepTaskParams,
61
64
  walletPurpose,
62
65
  sweepTaskId
@@ -183,4 +186,53 @@ export class FystackSDK {
183
186
 
184
187
  await this.apiService.rescanTransaction(params)
185
188
  }
189
+
190
+ /**
191
+ * Requests a withdrawal from a wallet
192
+ * @param walletId The ID of the wallet to withdraw from
193
+ * @param params Withdrawal parameters including asset, amount, and recipient
194
+ * @returns Promise with withdrawal response including auto_approved status and withdrawal details
195
+ */
196
+ async requestWithdrawal(
197
+ walletId: string,
198
+ params: RequestWithdrawalParams
199
+ ): Promise<RequestWithdrawalResponse> {
200
+ validateUUID(walletId, 'walletId')
201
+ validateUUID(params.assetId, 'assetId')
202
+
203
+ if (!params.amount || params.amount.trim() === '') {
204
+ throw new Error('Invalid amount provided')
205
+ }
206
+
207
+ if (!params.recipientAddress || params.recipientAddress.trim() === '') {
208
+ throw new Error('Invalid recipient address provided')
209
+ }
210
+
211
+ if (params.recipientAddress.length > 256) {
212
+ throw new Error('Recipient address exceeds maximum length of 256 characters')
213
+ }
214
+
215
+ if (params.notes && params.notes.length > 500) {
216
+ throw new Error('Notes exceed maximum length of 500 characters')
217
+ }
218
+
219
+ this.log(`Requesting withdrawal from wallet ${walletId}`)
220
+ const response = await this.apiService.requestWithdrawal(walletId, params)
221
+ this.log(`Withdrawal request completed, auto_approved: ${response.auto_approved}`)
222
+
223
+ return response
224
+ }
225
+
226
+ /**
227
+ * Gets the webhook public key for a workspace
228
+ * @param workspaceId The workspace ID
229
+ * @returns Promise with webhook public key (base64 encoded ed25519 public key)
230
+ */
231
+ async getWebhookPublicKey(workspaceId: string): Promise<WebhookPublicKeyResponse> {
232
+ validateUUID(workspaceId, 'workspaceId')
233
+
234
+ this.log(`Getting webhook public key for workspace ${workspaceId}`)
235
+ const response = await this.apiService.getWebhookPublicKey(workspaceId)
236
+ return response
237
+ }
186
238
  }