@fystack/sdk 0.1.0 → 0.1.2

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 CHANGED
@@ -133,7 +133,13 @@ exports.WalletAddressType = void 0;
133
133
  })(exports.WalletAddressType || (exports.WalletAddressType = {}));
134
134
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
135
135
  if (credentials.apiSecret == '') {
136
- // If APISecret is not provided, fallback to cookie mode with no headers
136
+ // If APISecret is not provided, use authToken
137
+ if (credentials.authToken) {
138
+ return {
139
+ Authorization: credentials.authToken
140
+ };
141
+ }
142
+ // fallback to cookie mode with no headers
137
143
  return {};
138
144
  }
139
145
  const currentTimestampInSeconds = Math.floor(Date.now() / 1000);
@@ -514,7 +520,7 @@ class FystackSDK {
514
520
  }
515
521
  }
516
522
 
517
- class ApexSigner extends ethers.AbstractSigner {
523
+ class EtherSigner extends ethers.AbstractSigner {
518
524
  setWallet(walletId) {
519
525
  if (!walletId || walletId.trim() === '') {
520
526
  throw new Error('Invalid wallet ID provided');
@@ -534,7 +540,7 @@ class ApexSigner extends ethers.AbstractSigner {
534
540
  if (this.address) {
535
541
  return this.address;
536
542
  }
537
- if (!this.APICredentials.apiKey && !this.walletDetail.WalletID) {
543
+ if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
538
544
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
539
545
  }
540
546
  const detail = await this.APIService.getWalletDetail(exports.WalletAddressType.Evm, this.walletDetail?.WalletID);
@@ -560,7 +566,7 @@ class ApexSigner extends ethers.AbstractSigner {
560
566
  }
561
567
  }
562
568
  connect(provider) {
563
- return new ApexSigner(this.APICredentials, this.environment, provider);
569
+ return new EtherSigner(this.APICredentials, this.environment, provider);
564
570
  }
565
571
  async waitForSignature(walletId, transactionId) {
566
572
  const poller = new StatusPoller(this.pollerOptions);
@@ -665,7 +671,7 @@ class ApexSigner extends ethers.AbstractSigner {
665
671
  // Ensure all properties are properly resolved to their string representations
666
672
  const resolvedTx = await ethers.resolveProperties(populatedTx);
667
673
  const txObj = ethers.Transaction.from(resolvedTx);
668
- console.log('txObj', txObj);
674
+ console.log('[WalletSDK] Tx Data', txObj);
669
675
  const txHash = await this.signTransaction(txObj);
670
676
  // Instead of creating a mock response, get the actual transaction from the provider
671
677
  const endTime = new Date();
@@ -795,7 +801,7 @@ class SolanaSigner {
795
801
  if (this.address) {
796
802
  return this.address;
797
803
  }
798
- if (!this.APIKey && !this.walletDetail?.WalletID) {
804
+ if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
799
805
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
800
806
  }
801
807
  const detail = await this.APIService.getWalletDetail(exports.WalletAddressType.Sol, this.walletDetail?.WalletID);
@@ -842,7 +848,7 @@ class SolanaSigner {
842
848
  data: transaction,
843
849
  from: this.address
844
850
  };
845
- // Call the signRaw API similar to ApexSigner
851
+ // Call the signRaw API similar to EtherSigner
846
852
  const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
847
853
  ...data,
848
854
  meta: {
@@ -850,7 +856,6 @@ class SolanaSigner {
850
856
  },
851
857
  chainId: '1399811149'
852
858
  });
853
- console.log('respnpse', response);
854
859
  // Wait for the signature
855
860
  return this.waitForTransactionStatus(response.transaction_id);
856
861
  }
@@ -868,7 +873,6 @@ class SolanaSigner {
868
873
  message: messageStr,
869
874
  chain_id: 0 // Not used for Solana but required by API
870
875
  });
871
- console.log('Respnse', response);
872
876
  return this.waitForTransactionStatus(response.transaction_id);
873
877
  }
874
878
  /**
@@ -940,6 +944,7 @@ class SolanaSigner {
940
944
  }
941
945
  }
942
946
  constructor(credentials, environment, pollerOptions){
947
+ this.APICredentials = credentials;
943
948
  this.APIKey = credentials.apiKey;
944
949
  this.APIService = new APIService(credentials, environment);
945
950
  this.pollerOptions = pollerOptions;
@@ -947,8 +952,8 @@ class SolanaSigner {
947
952
  }
948
953
 
949
954
  exports.APIService = APIService;
950
- exports.ApexSigner = ApexSigner;
951
955
  exports.DEFAULT_POLLER_OPTIONS = DEFAULT_POLLER_OPTIONS;
956
+ exports.EtherSigner = EtherSigner;
952
957
  exports.FystackSDK = FystackSDK;
953
958
  exports.PaymentService = PaymentService;
954
959
  exports.SolanaSigner = SolanaSigner;
package/dist/index.d.cts CHANGED
@@ -23,6 +23,7 @@ declare enum TxApprovalStatus {
23
23
  interface APICredentials {
24
24
  apiKey: string;
25
25
  apiSecret: string;
26
+ authToken?: string;
26
27
  }
27
28
  interface WebhookEvent {
28
29
  webhook_id: string;
@@ -229,7 +230,7 @@ declare class StatusPoller {
229
230
  poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
230
231
  }
231
232
 
232
- declare class ApexSigner extends AbstractSigner {
233
+ declare class EtherSigner extends AbstractSigner {
233
234
  private address;
234
235
  private APICredentials;
235
236
  private APIService;
@@ -240,7 +241,7 @@ declare class ApexSigner extends AbstractSigner {
240
241
  setWallet(walletId: string): void;
241
242
  getAddress(): Promise<string>;
242
243
  private getChainId;
243
- connect(provider: null | Provider): ApexSigner;
244
+ connect(provider: null | Provider): EtherSigner;
244
245
  private waitForSignature;
245
246
  private waitForTransactonStatus;
246
247
  signTransaction(tx: TransactionRequest): Promise<string>;
@@ -255,6 +256,7 @@ declare class SolanaSigner {
255
256
  private APIKey;
256
257
  private walletDetail;
257
258
  private pollerOptions?;
259
+ private APICredentials;
258
260
  constructor(credentials: APICredentials, environment: Environment, pollerOptions?: StatusPollerOptions);
259
261
  setWallet(walletId: string): void;
260
262
  getAddress(): Promise<string>;
@@ -608,4 +610,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
608
610
  wallet_type: WalletType;
609
611
  };
610
612
 
611
- export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, ApexSigner, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
613
+ export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
package/dist/index.d.mts CHANGED
@@ -23,6 +23,7 @@ declare enum TxApprovalStatus {
23
23
  interface APICredentials {
24
24
  apiKey: string;
25
25
  apiSecret: string;
26
+ authToken?: string;
26
27
  }
27
28
  interface WebhookEvent {
28
29
  webhook_id: string;
@@ -229,7 +230,7 @@ declare class StatusPoller {
229
230
  poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
230
231
  }
231
232
 
232
- declare class ApexSigner extends AbstractSigner {
233
+ declare class EtherSigner extends AbstractSigner {
233
234
  private address;
234
235
  private APICredentials;
235
236
  private APIService;
@@ -240,7 +241,7 @@ declare class ApexSigner extends AbstractSigner {
240
241
  setWallet(walletId: string): void;
241
242
  getAddress(): Promise<string>;
242
243
  private getChainId;
243
- connect(provider: null | Provider): ApexSigner;
244
+ connect(provider: null | Provider): EtherSigner;
244
245
  private waitForSignature;
245
246
  private waitForTransactonStatus;
246
247
  signTransaction(tx: TransactionRequest): Promise<string>;
@@ -255,6 +256,7 @@ declare class SolanaSigner {
255
256
  private APIKey;
256
257
  private walletDetail;
257
258
  private pollerOptions?;
259
+ private APICredentials;
258
260
  constructor(credentials: APICredentials, environment: Environment, pollerOptions?: StatusPollerOptions);
259
261
  setWallet(walletId: string): void;
260
262
  getAddress(): Promise<string>;
@@ -608,4 +610,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
608
610
  wallet_type: WalletType;
609
611
  };
610
612
 
611
- export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, ApexSigner, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
613
+ export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
@@ -23,6 +23,7 @@ declare enum TxApprovalStatus {
23
23
  interface APICredentials {
24
24
  apiKey: string;
25
25
  apiSecret: string;
26
+ authToken?: string;
26
27
  }
27
28
  interface WebhookEvent {
28
29
  webhook_id: string;
@@ -229,7 +230,7 @@ declare class StatusPoller {
229
230
  poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
230
231
  }
231
232
 
232
- declare class ApexSigner extends AbstractSigner {
233
+ declare class EtherSigner extends AbstractSigner {
233
234
  private address;
234
235
  private APICredentials;
235
236
  private APIService;
@@ -240,7 +241,7 @@ declare class ApexSigner extends AbstractSigner {
240
241
  setWallet(walletId: string): void;
241
242
  getAddress(): Promise<string>;
242
243
  private getChainId;
243
- connect(provider: null | Provider): ApexSigner;
244
+ connect(provider: null | Provider): EtherSigner;
244
245
  private waitForSignature;
245
246
  private waitForTransactonStatus;
246
247
  signTransaction(tx: TransactionRequest): Promise<string>;
@@ -255,6 +256,7 @@ declare class SolanaSigner {
255
256
  private APIKey;
256
257
  private walletDetail;
257
258
  private pollerOptions?;
259
+ private APICredentials;
258
260
  constructor(credentials: APICredentials, environment: Environment, pollerOptions?: StatusPollerOptions);
259
261
  setWallet(walletId: string): void;
260
262
  getAddress(): Promise<string>;
@@ -608,4 +610,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
608
610
  wallet_type: WalletType;
609
611
  };
610
612
 
611
- export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, ApexSigner, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
613
+ export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
package/dist/index.esm.js CHANGED
@@ -125,7 +125,13 @@ var WalletAddressType;
125
125
  })(WalletAddressType || (WalletAddressType = {}));
126
126
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
127
127
  if (credentials.apiSecret == '') {
128
- // If APISecret is not provided, fallback to cookie mode with no headers
128
+ // If APISecret is not provided, use authToken
129
+ if (credentials.authToken) {
130
+ return {
131
+ Authorization: credentials.authToken
132
+ };
133
+ }
134
+ // fallback to cookie mode with no headers
129
135
  return {};
130
136
  }
131
137
  const currentTimestampInSeconds = Math.floor(Date.now() / 1000);
@@ -506,7 +512,7 @@ class FystackSDK {
506
512
  }
507
513
  }
508
514
 
509
- class ApexSigner extends AbstractSigner {
515
+ class EtherSigner extends AbstractSigner {
510
516
  setWallet(walletId) {
511
517
  if (!walletId || walletId.trim() === '') {
512
518
  throw new Error('Invalid wallet ID provided');
@@ -526,7 +532,7 @@ class ApexSigner extends AbstractSigner {
526
532
  if (this.address) {
527
533
  return this.address;
528
534
  }
529
- if (!this.APICredentials.apiKey && !this.walletDetail.WalletID) {
535
+ if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
530
536
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
531
537
  }
532
538
  const detail = await this.APIService.getWalletDetail(WalletAddressType.Evm, this.walletDetail?.WalletID);
@@ -552,7 +558,7 @@ class ApexSigner extends AbstractSigner {
552
558
  }
553
559
  }
554
560
  connect(provider) {
555
- return new ApexSigner(this.APICredentials, this.environment, provider);
561
+ return new EtherSigner(this.APICredentials, this.environment, provider);
556
562
  }
557
563
  async waitForSignature(walletId, transactionId) {
558
564
  const poller = new StatusPoller(this.pollerOptions);
@@ -657,7 +663,7 @@ class ApexSigner extends AbstractSigner {
657
663
  // Ensure all properties are properly resolved to their string representations
658
664
  const resolvedTx = await resolveProperties(populatedTx);
659
665
  const txObj = Transaction.from(resolvedTx);
660
- console.log('txObj', txObj);
666
+ console.log('[WalletSDK] Tx Data', txObj);
661
667
  const txHash = await this.signTransaction(txObj);
662
668
  // Instead of creating a mock response, get the actual transaction from the provider
663
669
  const endTime = new Date();
@@ -787,7 +793,7 @@ class SolanaSigner {
787
793
  if (this.address) {
788
794
  return this.address;
789
795
  }
790
- if (!this.APIKey && !this.walletDetail?.WalletID) {
796
+ if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
791
797
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
792
798
  }
793
799
  const detail = await this.APIService.getWalletDetail(WalletAddressType.Sol, this.walletDetail?.WalletID);
@@ -834,7 +840,7 @@ class SolanaSigner {
834
840
  data: transaction,
835
841
  from: this.address
836
842
  };
837
- // Call the signRaw API similar to ApexSigner
843
+ // Call the signRaw API similar to EtherSigner
838
844
  const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
839
845
  ...data,
840
846
  meta: {
@@ -842,7 +848,6 @@ class SolanaSigner {
842
848
  },
843
849
  chainId: '1399811149'
844
850
  });
845
- console.log('respnpse', response);
846
851
  // Wait for the signature
847
852
  return this.waitForTransactionStatus(response.transaction_id);
848
853
  }
@@ -860,7 +865,6 @@ class SolanaSigner {
860
865
  message: messageStr,
861
866
  chain_id: 0 // Not used for Solana but required by API
862
867
  });
863
- console.log('Respnse', response);
864
868
  return this.waitForTransactionStatus(response.transaction_id);
865
869
  }
866
870
  /**
@@ -932,10 +936,11 @@ class SolanaSigner {
932
936
  }
933
937
  }
934
938
  constructor(credentials, environment, pollerOptions){
939
+ this.APICredentials = credentials;
935
940
  this.APIKey = credentials.apiKey;
936
941
  this.APIService = new APIService(credentials, environment);
937
942
  this.pollerOptions = pollerOptions;
938
943
  }
939
944
  }
940
945
 
941
- export { APIService, AddressType, ApexSigner, DEFAULT_POLLER_OPTIONS, Environment, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletAddressType, WalletCreationStatus, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
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 };
package/dist/index.mjs CHANGED
@@ -125,7 +125,13 @@ var WalletAddressType;
125
125
  })(WalletAddressType || (WalletAddressType = {}));
126
126
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
127
127
  if (credentials.apiSecret == '') {
128
- // If APISecret is not provided, fallback to cookie mode with no headers
128
+ // If APISecret is not provided, use authToken
129
+ if (credentials.authToken) {
130
+ return {
131
+ Authorization: credentials.authToken
132
+ };
133
+ }
134
+ // fallback to cookie mode with no headers
129
135
  return {};
130
136
  }
131
137
  const currentTimestampInSeconds = Math.floor(Date.now() / 1000);
@@ -506,7 +512,7 @@ class FystackSDK {
506
512
  }
507
513
  }
508
514
 
509
- class ApexSigner extends AbstractSigner {
515
+ class EtherSigner extends AbstractSigner {
510
516
  setWallet(walletId) {
511
517
  if (!walletId || walletId.trim() === '') {
512
518
  throw new Error('Invalid wallet ID provided');
@@ -526,7 +532,7 @@ class ApexSigner extends AbstractSigner {
526
532
  if (this.address) {
527
533
  return this.address;
528
534
  }
529
- if (!this.APICredentials.apiKey && !this.walletDetail.WalletID) {
535
+ if (!this.APICredentials.apiKey && !this.APICredentials.authToken && !this.walletDetail.WalletID) {
530
536
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
531
537
  }
532
538
  const detail = await this.APIService.getWalletDetail(WalletAddressType.Evm, this.walletDetail?.WalletID);
@@ -552,7 +558,7 @@ class ApexSigner extends AbstractSigner {
552
558
  }
553
559
  }
554
560
  connect(provider) {
555
- return new ApexSigner(this.APICredentials, this.environment, provider);
561
+ return new EtherSigner(this.APICredentials, this.environment, provider);
556
562
  }
557
563
  async waitForSignature(walletId, transactionId) {
558
564
  const poller = new StatusPoller(this.pollerOptions);
@@ -657,7 +663,7 @@ class ApexSigner extends AbstractSigner {
657
663
  // Ensure all properties are properly resolved to their string representations
658
664
  const resolvedTx = await resolveProperties(populatedTx);
659
665
  const txObj = Transaction.from(resolvedTx);
660
- console.log('txObj', txObj);
666
+ console.log('[WalletSDK] Tx Data', txObj);
661
667
  const txHash = await this.signTransaction(txObj);
662
668
  // Instead of creating a mock response, get the actual transaction from the provider
663
669
  const endTime = new Date();
@@ -787,7 +793,7 @@ class SolanaSigner {
787
793
  if (this.address) {
788
794
  return this.address;
789
795
  }
790
- if (!this.APIKey && !this.walletDetail?.WalletID) {
796
+ if (!this.APICredentials.apiKey && !this.APICredentials.apiSecret && !this.walletDetail?.WalletID) {
791
797
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!');
792
798
  }
793
799
  const detail = await this.APIService.getWalletDetail(WalletAddressType.Sol, this.walletDetail?.WalletID);
@@ -834,7 +840,7 @@ class SolanaSigner {
834
840
  data: transaction,
835
841
  from: this.address
836
842
  };
837
- // Call the signRaw API similar to ApexSigner
843
+ // Call the signRaw API similar to EtherSigner
838
844
  const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
839
845
  ...data,
840
846
  meta: {
@@ -842,7 +848,6 @@ class SolanaSigner {
842
848
  },
843
849
  chainId: '1399811149'
844
850
  });
845
- console.log('respnpse', response);
846
851
  // Wait for the signature
847
852
  return this.waitForTransactionStatus(response.transaction_id);
848
853
  }
@@ -860,7 +865,6 @@ class SolanaSigner {
860
865
  message: messageStr,
861
866
  chain_id: 0 // Not used for Solana but required by API
862
867
  });
863
- console.log('Respnse', response);
864
868
  return this.waitForTransactionStatus(response.transaction_id);
865
869
  }
866
870
  /**
@@ -932,10 +936,11 @@ class SolanaSigner {
932
936
  }
933
937
  }
934
938
  constructor(credentials, environment, pollerOptions){
939
+ this.APICredentials = credentials;
935
940
  this.APIKey = credentials.apiKey;
936
941
  this.APIService = new APIService(credentials, environment);
937
942
  this.pollerOptions = pollerOptions;
938
943
  }
939
944
  }
940
945
 
941
- export { APIService, AddressType, ApexSigner, DEFAULT_POLLER_OPTIONS, Environment, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletAddressType, WalletCreationStatus, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
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 };
@@ -23,6 +23,7 @@ declare enum TxApprovalStatus {
23
23
  interface APICredentials {
24
24
  apiKey: string;
25
25
  apiSecret: string;
26
+ authToken?: string;
26
27
  }
27
28
  interface WebhookEvent {
28
29
  webhook_id: string;
@@ -229,7 +230,7 @@ declare class StatusPoller {
229
230
  poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
230
231
  }
231
232
 
232
- declare class ApexSigner extends AbstractSigner {
233
+ declare class EtherSigner extends AbstractSigner {
233
234
  private address;
234
235
  private APICredentials;
235
236
  private APIService;
@@ -240,7 +241,7 @@ declare class ApexSigner extends AbstractSigner {
240
241
  setWallet(walletId: string): void;
241
242
  getAddress(): Promise<string>;
242
243
  private getChainId;
243
- connect(provider: null | Provider): ApexSigner;
244
+ connect(provider: null | Provider): EtherSigner;
244
245
  private waitForSignature;
245
246
  private waitForTransactonStatus;
246
247
  signTransaction(tx: TransactionRequest): Promise<string>;
@@ -255,6 +256,7 @@ declare class SolanaSigner {
255
256
  private APIKey;
256
257
  private walletDetail;
257
258
  private pollerOptions?;
259
+ private APICredentials;
258
260
  constructor(credentials: APICredentials, environment: Environment, pollerOptions?: StatusPollerOptions);
259
261
  setWallet(walletId: string): void;
260
262
  getAddress(): Promise<string>;
@@ -608,4 +610,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
608
610
  wallet_type: WalletType;
609
611
  };
610
612
 
611
- export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, ApexSigner, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
613
+ export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fystack/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Wallet SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/types/index.d.ts",
package/readme.md ADDED
@@ -0,0 +1,200 @@
1
+ # Fystack Platform SDK
2
+
3
+ A Typescript SDK for Fystack's wallet and payment services, providing seamless integration with both EVM and Solana blockchains.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @fystack/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Wallet Management
14
+
15
+ Create and manage blockchain wallets with minimal code.
16
+
17
+ ```typescript
18
+ import { FystackSDK } from '@fystack/sdk'
19
+ import { Environment, WalletType } from '@fystack/sdk'
20
+
21
+ // Initialize the SDK
22
+ const sdk = new FystackSDK({
23
+ credentials: {
24
+ apiKey: 'YOUR_API_KEY',
25
+ apiSecret: 'YOUR_API_SECRET'
26
+ },
27
+ environment: Environment.Production,
28
+ logger: true // Enable logging
29
+ })
30
+
31
+ const response = await sdk.createWallet({
32
+ name: 'My Blockchain Wallet',
33
+ walletType: WalletType.MPC // Multi-Party Computation wallet
34
+ })
35
+
36
+ console.log('Wallet ID:', response.wallet_id)
37
+ console.log('Status:', response.status)
38
+
39
+ // Check wallet creation status
40
+ const statusResponse = await sdk.getWalletCreationStatus(response.wallet_id)
41
+ console.log('WalletID:', statusResponse.wallet_id)
42
+ ```
43
+
44
+ ### Solana Transaction Signing
45
+
46
+ ```typescript
47
+ import { SolanaSigner } from '@fystack/sdk'
48
+ import { Connection, PublicKey, SystemProgram, Transaction } from '@solana/web3.js'
49
+
50
+ async function signSolanaTransaction() {
51
+ // Initialize the signer
52
+ const signer = new SolanaSigner(
53
+ {
54
+ apiKey: 'YOUR_API_KEY',
55
+ apiSecret: 'YOUR_API_SECRET'
56
+ },
57
+ Environment.Production
58
+ )
59
+
60
+ // Get signer's address
61
+ const fromAddress = await signer.getAddress()
62
+ const fromPubkey = new PublicKey(fromAddress)
63
+
64
+ // Set recipient address
65
+ const toAddress = 'RECIPIENT_SOLANA_ADDRESS'
66
+ const toPubkey = new PublicKey(toAddress)
67
+
68
+ // Connect to Solana network
69
+ const connection = new Connection('https://api.mainnet-beta.solana.com/')
70
+
71
+ // Get recent blockhash
72
+ const { blockhash } = await connection.getLatestBlockhash({
73
+ commitment: 'finalized'
74
+ })
75
+
76
+ // Create transfer instruction
77
+ const transferInstruction = SystemProgram.transfer({
78
+ fromPubkey,
79
+ toPubkey,
80
+ lamports: 1000 // 0.000001 SOL
81
+ })
82
+
83
+ // Create and setup transaction
84
+ const transaction = new Transaction().add(transferInstruction)
85
+ transaction.recentBlockhash = blockhash
86
+ transaction.feePayer = fromPubkey
87
+
88
+ // Serialize the transaction to base64
89
+ const serializedTransaction = transaction
90
+ .serialize({
91
+ requireAllSignatures: false,
92
+ verifySignatures: false
93
+ })
94
+ .toString('base64')
95
+
96
+ // Sign the transaction
97
+ const signature = await signer.signTransaction(serializedTransaction)
98
+ console.log('Transaction signature:', signature)
99
+
100
+ return signature
101
+ }
102
+ ```
103
+
104
+ ### Ethereum Transaction Signing
105
+
106
+ ```typescript
107
+ import { EtherSigner } from '@fystack/sdk'
108
+ import { JsonRpcProvider, ethers } from 'ethers'
109
+
110
+ async function signEthereumTransaction() {
111
+ const address = await signer.getAddress()
112
+ console.log('Wallet address:', address)
113
+
114
+ // Connect to a provider
115
+ const provider = new JsonRpcProvider('YOUR_RPC_ENDPOINT')
116
+ const signerWithProvider = signer.connect(provider)
117
+
118
+ // Send a transaction
119
+ const tx = await signerWithProvider.sendTransaction({
120
+ to: '0xRecipientAddress',
121
+ value: ethers.parseEther('0.0001') // Amount in ETH
122
+ })
123
+
124
+ console.log('Transaction hash:', tx.hash)
125
+ return tx.hash
126
+ }
127
+ ```
128
+
129
+ ### Payment Processing
130
+
131
+ Create checkouts and process payments.
132
+
133
+ ```typescript
134
+ import { PaymentService } from '@fystack/sdk'
135
+ import { Environment } from '@fystack/sdk'
136
+
137
+ async function createPaymentCheckout() {
138
+ const paymentService = new PaymentService({
139
+ apiKey: 'YOUR_API_KEY',
140
+ environment: Environment.Production
141
+ })
142
+
143
+ // Create a checkout
144
+ const response = await paymentService.createCheckout({
145
+ price: '10.50',
146
+ currency: 'USD',
147
+ supported_assets: [
148
+ 'SOL:1399811149', // Format: "ASSET:CHAIN_ID"
149
+ 'USDC:1399811149'
150
+ ],
151
+ description: 'Premium subscription package',
152
+ success_url: 'https://yourapp.com/payment/success',
153
+ cancel_url: 'https://yourapp.com/payment/cancel',
154
+ product_id: 'YOUR_PRODUCT_ID',
155
+ customer_id: 'YOUR_CUSTOMER_ID',
156
+ order_id: 'YOUR_ORDER_ID',
157
+ enable_localization: false,
158
+ destination_wallet_id: 'YOUR_DESTINATION_WALLET_ID',
159
+ expiry_duration_seconds: 3600 // 1 hour
160
+ })
161
+
162
+ console.log('Checkout created:', response.id)
163
+
164
+ // Get checkout details
165
+ const checkout = await paymentService.getCheckout(response.id)
166
+
167
+ // Create payment using the first supported asset
168
+ const payment = await paymentService.createCheckoutPayment(response.id, {
169
+ pay_asset_id: checkout.supported_assets[0].id
170
+ })
171
+
172
+ console.log('Payment created:', payment.id)
173
+ console.log('Send payment to:', payment.deposit_address)
174
+
175
+ // Get payment status
176
+ const paymentStatus = await paymentService.getCheckoutPayment(payment.id)
177
+ console.log('Payment status:', paymentStatus)
178
+
179
+ return payment
180
+ }
181
+ ```
182
+
183
+ ### Webhook Verification
184
+
185
+ ```typescript
186
+ import { APIService } from '@fystack/sdk'
187
+
188
+ function verifyWebhook(event, signature) {
189
+ const apiService = new APIService(
190
+ {
191
+ apiKey: 'YOUR_API_KEY',
192
+ apiSecret: 'YOUR_API_SECRET'
193
+ },
194
+ Environment.Production
195
+ )
196
+
197
+ const isValid = apiService.Webhook.verifyEvent(event, signature)
198
+ return isValid
199
+ }
200
+ ```
package/src/api.ts CHANGED
@@ -67,7 +67,13 @@ async function composeAPIHeaders(
67
67
  body: Record<string, any> = {}
68
68
  ): Promise<Record<string, string>> {
69
69
  if (credentials.apiSecret == '') {
70
- // If APISecret is not provided, fallback to cookie mode with no headers
70
+ // If APISecret is not provided, use authToken
71
+ if (credentials.authToken) {
72
+ return {
73
+ Authorization: credentials.authToken
74
+ }
75
+ }
76
+ // fallback to cookie mode with no headers
71
77
  return {}
72
78
  }
73
79
 
package/src/signer.ts CHANGED
@@ -20,7 +20,7 @@ import { APICredentials, TransactionStatusResponse, TxStatus, TransactionError }
20
20
  import { Environment } from './config'
21
21
  import { StatusPoller, StatusPollerOptions } from './utils/statusPoller'
22
22
 
23
- export class ApexSigner extends AbstractSigner {
23
+ export class EtherSigner extends AbstractSigner {
24
24
  private address!: string
25
25
  private APICredentials!: APICredentials
26
26
  private APIService: APIService
@@ -64,7 +64,11 @@ export class ApexSigner extends AbstractSigner {
64
64
  return this.address
65
65
  }
66
66
 
67
- if (!this.APICredentials.apiKey && !this.walletDetail.WalletID) {
67
+ if (
68
+ !this.APICredentials.apiKey &&
69
+ !this.APICredentials.authToken &&
70
+ !this.walletDetail.WalletID
71
+ ) {
68
72
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!')
69
73
  }
70
74
 
@@ -99,8 +103,8 @@ export class ApexSigner extends AbstractSigner {
99
103
  }
100
104
  }
101
105
 
102
- connect(provider: null | Provider): ApexSigner {
103
- return new ApexSigner(this.APICredentials, this.environment, provider)
106
+ connect(provider: null | Provider): EtherSigner {
107
+ return new EtherSigner(this.APICredentials, this.environment, provider)
104
108
  }
105
109
 
106
110
  private async waitForSignature(walletId: string, transactionId: string): Promise<string> {
@@ -253,7 +257,7 @@ export class ApexSigner extends AbstractSigner {
253
257
  const resolvedTx = (await resolveProperties(populatedTx)) as TransactionLike<string>
254
258
  const txObj = Transaction.from(resolvedTx)
255
259
 
256
- console.log('txObj', txObj)
260
+ console.log('[WalletSDK] Tx Data', txObj)
257
261
 
258
262
  const txHash = await this.signTransaction(txObj)
259
263
 
@@ -12,12 +12,14 @@ export class SolanaSigner {
12
12
  private APIKey: string
13
13
  private walletDetail: WalletDetail
14
14
  private pollerOptions?: StatusPollerOptions
15
+ private APICredentials!: APICredentials
15
16
 
16
17
  constructor(
17
18
  credentials: APICredentials,
18
19
  environment: Environment,
19
20
  pollerOptions?: StatusPollerOptions
20
21
  ) {
22
+ this.APICredentials = credentials
21
23
  this.APIKey = credentials.apiKey
22
24
  this.APIService = new APIService(credentials, environment)
23
25
  this.pollerOptions = pollerOptions
@@ -45,7 +47,11 @@ export class SolanaSigner {
45
47
  return this.address
46
48
  }
47
49
 
48
- if (!this.APIKey && !this.walletDetail?.WalletID) {
50
+ if (
51
+ !this.APICredentials.apiKey &&
52
+ !this.APICredentials.apiSecret &&
53
+ !this.walletDetail?.WalletID
54
+ ) {
49
55
  throw new Error('Wallet detail not found, use setWallet(walletId) to set wallet first!')
50
56
  }
51
57
 
@@ -120,7 +126,7 @@ export class SolanaSigner {
120
126
  from: this.address
121
127
  }
122
128
 
123
- // Call the signRaw API similar to ApexSigner
129
+ // Call the signRaw API similar to EtherSigner
124
130
  const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
125
131
  ...data,
126
132
  meta: {
@@ -128,7 +134,6 @@ export class SolanaSigner {
128
134
  },
129
135
  chainId: '1399811149'
130
136
  })
131
- console.log('respnpse', response)
132
137
 
133
138
  // Wait for the signature
134
139
  return this.waitForTransactionStatus(response.transaction_id)
@@ -153,8 +158,6 @@ export class SolanaSigner {
153
158
  chain_id: 0 // Not used for Solana but required by API
154
159
  })
155
160
 
156
- console.log('Respnse', response)
157
-
158
161
  return this.waitForTransactionStatus(response.transaction_id)
159
162
  }
160
163
 
package/src/types.ts CHANGED
@@ -27,6 +27,9 @@ export enum TxApprovalStatus {
27
27
  export interface APICredentials {
28
28
  apiKey: string
29
29
  apiSecret: string
30
+
31
+ // Optional
32
+ authToken?: string
30
33
  }
31
34
 
32
35
  export interface WebhookEvent {