@fystack/sdk 0.1.7 → 0.1.8

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
@@ -182,7 +182,7 @@ exports.WalletRole = void 0;
182
182
  WalletRole["Viewer"] = "wallet_viewer";
183
183
  })(exports.WalletRole || (exports.WalletRole = {}));
184
184
 
185
- async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
185
+ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
186
186
  if (!credentials.apiSecret || credentials.apiSecret === '') {
187
187
  // If APISecret is not provided, use authToken
188
188
  if (credentials.authToken) {
@@ -204,12 +204,13 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
204
204
  body: Object.keys(body).length ? JSON.stringify(body) : ''
205
205
  };
206
206
  const digest = await computeHMAC(credentials.apiSecret, params);
207
- const headers = {
207
+ const combinedHeaders = {
208
208
  'ACCESS-API-KEY': credentials.apiKey,
209
209
  'ACCESS-TIMESTAMP': String(currentTimestampInSeconds),
210
- 'ACCESS-SIGN': btoa(digest) // convert to base64
210
+ 'ACCESS-SIGN': btoa(digest),
211
+ ...headers ?? {}
211
212
  };
212
- return headers;
213
+ return combinedHeaders;
213
214
  }
214
215
  class APIService {
215
216
  async getWallets(workspaceId) {
@@ -225,9 +226,9 @@ class APIService {
225
226
  const resp = await get(endpoint + `?address_type=${addressType}`, headers);
226
227
  return transformWalletDetail(resp.data);
227
228
  }
228
- async requestSign(walletId, params) {
229
+ async requestSign(walletId, params, options) {
229
230
  const endpoint = this.API.endpoints.requestSign(walletId);
230
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params);
231
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params, options);
231
232
  const response = await post(endpoint, params, headers);
232
233
  return response.data;
233
234
  }
@@ -237,10 +238,10 @@ class APIService {
237
238
  const response = await get(endpoint, headers);
238
239
  return response.data;
239
240
  }
240
- async signTransaction(walletId, body) {
241
+ async signTransaction(walletId, body, options) {
241
242
  const startTime = Date.now();
242
243
  const endpoint = this.API.endpoints.signTransaction(walletId);
243
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body);
244
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body, options);
244
245
  const response = await post(endpoint, body, headers);
245
246
  const elapsedTime = Date.now() - startTime;
246
247
  console.log(`[WalletSDK] Sign transaction completed in ${elapsedTime}ms`);
@@ -677,14 +678,14 @@ class EtherSigner extends ethers.AbstractSigner {
677
678
  }
678
679
  return result.status === exports.TxStatus.Rejected;
679
680
  });
680
- console.log('reulst', result);
681
+ console.log('result', result);
681
682
  if (!result.hash) {
682
683
  throw new TransactionError('Transaction hash not found in successful response', 'TRANSACTION_HASH_MISSING', result.transaction_id);
683
684
  }
684
685
  return result.hash;
685
686
  }
686
687
  // Copied and editted from ethers.js -> Wallet -> BaseWallet
687
- async signTransaction(tx) {
688
+ async signTransaction(tx, options) {
688
689
  const startTime = new Date();
689
690
  console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`);
690
691
  if (!this.address) {
@@ -724,7 +725,7 @@ class EtherSigner extends ethers.AbstractSigner {
724
725
  accessList: btx.accessList
725
726
  };
726
727
  // return unseralized as API signTransaction is an asynchoronous action
727
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data);
728
+ const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data, options);
728
729
  const txHash = await this.waitForTransactonStatus(response.transaction_id);
729
730
  const endTime = new Date();
730
731
  const elapsedTimeMs = endTime.getTime() - startTime.getTime();
@@ -733,7 +734,7 @@ class EtherSigner extends ethers.AbstractSigner {
733
734
  console.log('[WalletSDK] Transaction succeed!');
734
735
  return txHash;
735
736
  }
736
- async sendTransaction(tx) {
737
+ async sendTransaction(tx, options) {
737
738
  const startTime = new Date();
738
739
  console.log(`[WalletSDK] sendTransaction started at: ${startTime.toLocaleString()}`);
739
740
  if (!this.address) {
@@ -761,7 +762,7 @@ class EtherSigner extends ethers.AbstractSigner {
761
762
  const resolvedTx = await ethers.resolveProperties(populatedTx);
762
763
  const txObj = ethers.Transaction.from(resolvedTx);
763
764
  console.log('[WalletSDK] Tx Data', txObj);
764
- const txHash = await this.signTransaction(txObj);
765
+ const txHash = await this.signTransaction(txObj, options);
765
766
  // Instead of creating a mock response, get the actual transaction from the provider
766
767
  const endTime = new Date();
767
768
  const totalElapsedMs = endTime.getTime() - startTime.getTime();
@@ -810,7 +811,7 @@ class EtherSigner extends ethers.AbstractSigner {
810
811
  // Let the provider create the TransactionResponse using the txHash
811
812
  return new ethers.TransactionResponse(txResponse, this.provider);
812
813
  }
813
- async signMessage(message) {
814
+ async signMessage(message, options) {
814
815
  if (!this.provider) {
815
816
  throw new Error('Provider is required for signing operations');
816
817
  }
@@ -826,10 +827,10 @@ class EtherSigner extends ethers.AbstractSigner {
826
827
  method: 'eth_sign',
827
828
  message: messageStr,
828
829
  chain_id: chainId
829
- });
830
+ }, options);
830
831
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id);
831
832
  }
832
- async signTypedData(domain, types, value) {
833
+ async signTypedData(domain, types, value, options) {
833
834
  if (!this.provider) {
834
835
  throw new Error('Provider is required for signing operations');
835
836
  }
@@ -850,7 +851,7 @@ class EtherSigner extends ethers.AbstractSigner {
850
851
  message: '',
851
852
  chain_id: chainId,
852
853
  typed_data: typedData
853
- });
854
+ }, options);
854
855
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id);
855
856
  }
856
857
  constructor(credentials, environment, provider, pollerOptions){
@@ -929,7 +930,7 @@ class SolanaSigner {
929
930
  * Signs a Solana transaction
930
931
  * @param transaction Base64 encoded serialized transaction
931
932
  * @returns Signature as a base58 encoded string
932
- */ async signTransaction(transaction) {
933
+ */ async signTransaction(transaction, options) {
933
934
  if (!this.address) {
934
935
  await this.getAddress();
935
936
  }
@@ -944,7 +945,7 @@ class SolanaSigner {
944
945
  tx_method: 'solana_signTransaction'
945
946
  },
946
947
  chainId: '1399811149'
947
- });
948
+ }, options);
948
949
  // Wait for the signature
949
950
  return this.waitForTransactionStatus(response.transaction_id);
950
951
  }
@@ -952,7 +953,7 @@ class SolanaSigner {
952
953
  * Signs a Solana message
953
954
  * @param message The message to sign (string or Uint8Array)
954
955
  * @returns Signature as a base58 encoded string
955
- */ async signMessage(message) {
956
+ */ async signMessage(message, options) {
956
957
  if (!this.address) {
957
958
  await this.getAddress();
958
959
  }
@@ -961,14 +962,14 @@ class SolanaSigner {
961
962
  method: 'solana_signMessage',
962
963
  message: messageStr,
963
964
  chain_id: 0 // Not used for Solana but required by API
964
- });
965
+ }, options);
965
966
  return this.waitForTransactionStatus(response.transaction_id);
966
967
  }
967
968
  /**
968
969
  * Signs and sends a Solana transaction
969
970
  * @param transaction Base64 encoded serialized transaction
970
971
  * @returns Transaction signature
971
- */ async signAndSendTransaction(transaction) {
972
+ */ async signAndSendTransaction(transaction, options) {
972
973
  if (!this.address) {
973
974
  await this.getAddress();
974
975
  }
@@ -977,7 +978,7 @@ class SolanaSigner {
977
978
  from: this.address,
978
979
  method: 'solana_signAndSendTransaction'
979
980
  };
980
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data);
981
+ const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data, options);
981
982
  const txHash = await this.waitForTransactionStatus(response.transaction_id);
982
983
  console.log('transaction succeed!');
983
984
  return txHash;
@@ -986,14 +987,14 @@ class SolanaSigner {
986
987
  * Signs multiple Solana transactions
987
988
  * @param transactions Array of base64 encoded serialized transactions
988
989
  * @returns Array of signatures as base58 encoded strings
989
- */ async signAllTransactions(transactions) {
990
+ */ async signAllTransactions(transactions, options) {
990
991
  if (!this.address) {
991
992
  await this.getAddress();
992
993
  }
993
994
  // We need to get the signatures and then incorporate them into the transactions
994
995
  const signaturePromises = transactions.map(async (transaction)=>{
995
996
  // Get the signature
996
- const signature = await this.signTransaction(transaction);
997
+ const signature = await this.signTransaction(transaction, options);
997
998
  // Here you would need to incorporate the signature into the transaction
998
999
  // This is a placeholder - you'll need to implement actual signature incorporation
999
1000
  // based on your Solana transaction structure
package/dist/index.d.cts CHANGED
@@ -361,9 +361,9 @@ declare class APIService {
361
361
  constructor(credentials: APICredentials, environment: Environment);
362
362
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
363
363
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
364
- requestSign(walletId: string, params: SignRequestParams): Promise<SignResponse>;
364
+ requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
365
365
  getSignStatus(walletId: string, transactionId: string): Promise<SignatureStatusResponse>;
366
- signTransaction(walletId: string, body: Record<string, any>): Promise<SignResponse>;
366
+ signTransaction(walletId: string, body: Record<string, any>, options?: Record<string, string>): Promise<SignResponse>;
367
367
  getTransactionStatus(walletId: string, transactionId: string): Promise<TransactionStatusResponse>;
368
368
  createWallet(payload: CreateWalletPayload): Promise<CreateWalletResponse>;
369
369
  createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse>;
@@ -646,10 +646,18 @@ declare class EtherSigner extends AbstractSigner {
646
646
  connect(provider: null | Provider): EtherSigner;
647
647
  private waitForSignature;
648
648
  private waitForTransactonStatus;
649
- signTransaction(tx: TransactionRequest): Promise<string>;
650
- sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
651
- signMessage(message: string | Uint8Array): Promise<string>;
652
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
649
+ signTransaction(tx: TransactionRequest, options?: {
650
+ idempotencyKey?: string;
651
+ }): Promise<string>;
652
+ sendTransaction(tx: TransactionRequest, options?: {
653
+ idempotencyKey?: string;
654
+ }): Promise<TransactionResponse>;
655
+ signMessage(message: string | Uint8Array, options?: {
656
+ idempotencyKey?: string;
657
+ }): Promise<string>;
658
+ signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, options?: {
659
+ idempotencyKey?: string;
660
+ }): Promise<string>;
653
661
  }
654
662
 
655
663
  declare class SolanaSigner {
@@ -668,25 +676,33 @@ declare class SolanaSigner {
668
676
  * @param transaction Base64 encoded serialized transaction
669
677
  * @returns Signature as a base58 encoded string
670
678
  */
671
- signTransaction(transaction: string): Promise<string>;
679
+ signTransaction(transaction: string, options?: {
680
+ idempotencyKey?: string;
681
+ }): Promise<string>;
672
682
  /**
673
683
  * Signs a Solana message
674
684
  * @param message The message to sign (string or Uint8Array)
675
685
  * @returns Signature as a base58 encoded string
676
686
  */
677
- signMessage(message: string | Uint8Array): Promise<string>;
687
+ signMessage(message: string | Uint8Array, options?: {
688
+ idempotencyKey?: string;
689
+ }): Promise<string>;
678
690
  /**
679
691
  * Signs and sends a Solana transaction
680
692
  * @param transaction Base64 encoded serialized transaction
681
693
  * @returns Transaction signature
682
694
  */
683
- signAndSendTransaction(transaction: string): Promise<string>;
695
+ signAndSendTransaction(transaction: string, options?: {
696
+ idempotencyKey?: string;
697
+ }): Promise<string>;
684
698
  /**
685
699
  * Signs multiple Solana transactions
686
700
  * @param transactions Array of base64 encoded serialized transactions
687
701
  * @returns Array of signatures as base58 encoded strings
688
702
  */
689
- signAllTransactions(transactions: string[]): Promise<{
703
+ signAllTransactions(transactions: string[], options?: {
704
+ idempotencyKey?: string;
705
+ }): Promise<{
690
706
  transactions: string[];
691
707
  }>;
692
708
  private incorporateSignatureIntoTransaction;
package/dist/index.d.mts CHANGED
@@ -361,9 +361,9 @@ declare class APIService {
361
361
  constructor(credentials: APICredentials, environment: Environment);
362
362
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
363
363
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
364
- requestSign(walletId: string, params: SignRequestParams): Promise<SignResponse>;
364
+ requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
365
365
  getSignStatus(walletId: string, transactionId: string): Promise<SignatureStatusResponse>;
366
- signTransaction(walletId: string, body: Record<string, any>): Promise<SignResponse>;
366
+ signTransaction(walletId: string, body: Record<string, any>, options?: Record<string, string>): Promise<SignResponse>;
367
367
  getTransactionStatus(walletId: string, transactionId: string): Promise<TransactionStatusResponse>;
368
368
  createWallet(payload: CreateWalletPayload): Promise<CreateWalletResponse>;
369
369
  createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse>;
@@ -646,10 +646,18 @@ declare class EtherSigner extends AbstractSigner {
646
646
  connect(provider: null | Provider): EtherSigner;
647
647
  private waitForSignature;
648
648
  private waitForTransactonStatus;
649
- signTransaction(tx: TransactionRequest): Promise<string>;
650
- sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
651
- signMessage(message: string | Uint8Array): Promise<string>;
652
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
649
+ signTransaction(tx: TransactionRequest, options?: {
650
+ idempotencyKey?: string;
651
+ }): Promise<string>;
652
+ sendTransaction(tx: TransactionRequest, options?: {
653
+ idempotencyKey?: string;
654
+ }): Promise<TransactionResponse>;
655
+ signMessage(message: string | Uint8Array, options?: {
656
+ idempotencyKey?: string;
657
+ }): Promise<string>;
658
+ signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, options?: {
659
+ idempotencyKey?: string;
660
+ }): Promise<string>;
653
661
  }
654
662
 
655
663
  declare class SolanaSigner {
@@ -668,25 +676,33 @@ declare class SolanaSigner {
668
676
  * @param transaction Base64 encoded serialized transaction
669
677
  * @returns Signature as a base58 encoded string
670
678
  */
671
- signTransaction(transaction: string): Promise<string>;
679
+ signTransaction(transaction: string, options?: {
680
+ idempotencyKey?: string;
681
+ }): Promise<string>;
672
682
  /**
673
683
  * Signs a Solana message
674
684
  * @param message The message to sign (string or Uint8Array)
675
685
  * @returns Signature as a base58 encoded string
676
686
  */
677
- signMessage(message: string | Uint8Array): Promise<string>;
687
+ signMessage(message: string | Uint8Array, options?: {
688
+ idempotencyKey?: string;
689
+ }): Promise<string>;
678
690
  /**
679
691
  * Signs and sends a Solana transaction
680
692
  * @param transaction Base64 encoded serialized transaction
681
693
  * @returns Transaction signature
682
694
  */
683
- signAndSendTransaction(transaction: string): Promise<string>;
695
+ signAndSendTransaction(transaction: string, options?: {
696
+ idempotencyKey?: string;
697
+ }): Promise<string>;
684
698
  /**
685
699
  * Signs multiple Solana transactions
686
700
  * @param transactions Array of base64 encoded serialized transactions
687
701
  * @returns Array of signatures as base58 encoded strings
688
702
  */
689
- signAllTransactions(transactions: string[]): Promise<{
703
+ signAllTransactions(transactions: string[], options?: {
704
+ idempotencyKey?: string;
705
+ }): Promise<{
690
706
  transactions: string[];
691
707
  }>;
692
708
  private incorporateSignatureIntoTransaction;
@@ -361,9 +361,9 @@ declare class APIService {
361
361
  constructor(credentials: APICredentials, environment: Environment);
362
362
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
363
363
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
364
- requestSign(walletId: string, params: SignRequestParams): Promise<SignResponse>;
364
+ requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
365
365
  getSignStatus(walletId: string, transactionId: string): Promise<SignatureStatusResponse>;
366
- signTransaction(walletId: string, body: Record<string, any>): Promise<SignResponse>;
366
+ signTransaction(walletId: string, body: Record<string, any>, options?: Record<string, string>): Promise<SignResponse>;
367
367
  getTransactionStatus(walletId: string, transactionId: string): Promise<TransactionStatusResponse>;
368
368
  createWallet(payload: CreateWalletPayload): Promise<CreateWalletResponse>;
369
369
  createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse>;
@@ -646,10 +646,18 @@ declare class EtherSigner extends AbstractSigner {
646
646
  connect(provider: null | Provider): EtherSigner;
647
647
  private waitForSignature;
648
648
  private waitForTransactonStatus;
649
- signTransaction(tx: TransactionRequest): Promise<string>;
650
- sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
651
- signMessage(message: string | Uint8Array): Promise<string>;
652
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
649
+ signTransaction(tx: TransactionRequest, options?: {
650
+ idempotencyKey?: string;
651
+ }): Promise<string>;
652
+ sendTransaction(tx: TransactionRequest, options?: {
653
+ idempotencyKey?: string;
654
+ }): Promise<TransactionResponse>;
655
+ signMessage(message: string | Uint8Array, options?: {
656
+ idempotencyKey?: string;
657
+ }): Promise<string>;
658
+ signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, options?: {
659
+ idempotencyKey?: string;
660
+ }): Promise<string>;
653
661
  }
654
662
 
655
663
  declare class SolanaSigner {
@@ -668,25 +676,33 @@ declare class SolanaSigner {
668
676
  * @param transaction Base64 encoded serialized transaction
669
677
  * @returns Signature as a base58 encoded string
670
678
  */
671
- signTransaction(transaction: string): Promise<string>;
679
+ signTransaction(transaction: string, options?: {
680
+ idempotencyKey?: string;
681
+ }): Promise<string>;
672
682
  /**
673
683
  * Signs a Solana message
674
684
  * @param message The message to sign (string or Uint8Array)
675
685
  * @returns Signature as a base58 encoded string
676
686
  */
677
- signMessage(message: string | Uint8Array): Promise<string>;
687
+ signMessage(message: string | Uint8Array, options?: {
688
+ idempotencyKey?: string;
689
+ }): Promise<string>;
678
690
  /**
679
691
  * Signs and sends a Solana transaction
680
692
  * @param transaction Base64 encoded serialized transaction
681
693
  * @returns Transaction signature
682
694
  */
683
- signAndSendTransaction(transaction: string): Promise<string>;
695
+ signAndSendTransaction(transaction: string, options?: {
696
+ idempotencyKey?: string;
697
+ }): Promise<string>;
684
698
  /**
685
699
  * Signs multiple Solana transactions
686
700
  * @param transactions Array of base64 encoded serialized transactions
687
701
  * @returns Array of signatures as base58 encoded strings
688
702
  */
689
- signAllTransactions(transactions: string[]): Promise<{
703
+ signAllTransactions(transactions: string[], options?: {
704
+ idempotencyKey?: string;
705
+ }): Promise<{
690
706
  transactions: string[];
691
707
  }>;
692
708
  private incorporateSignatureIntoTransaction;
package/dist/index.esm.js CHANGED
@@ -174,7 +174,7 @@ var WalletRole;
174
174
  WalletRole["Viewer"] = "wallet_viewer";
175
175
  })(WalletRole || (WalletRole = {}));
176
176
 
177
- async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
177
+ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
178
178
  if (!credentials.apiSecret || credentials.apiSecret === '') {
179
179
  // If APISecret is not provided, use authToken
180
180
  if (credentials.authToken) {
@@ -196,12 +196,13 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
196
196
  body: Object.keys(body).length ? JSON.stringify(body) : ''
197
197
  };
198
198
  const digest = await computeHMAC(credentials.apiSecret, params);
199
- const headers = {
199
+ const combinedHeaders = {
200
200
  'ACCESS-API-KEY': credentials.apiKey,
201
201
  'ACCESS-TIMESTAMP': String(currentTimestampInSeconds),
202
- 'ACCESS-SIGN': btoa(digest) // convert to base64
202
+ 'ACCESS-SIGN': btoa(digest),
203
+ ...headers ?? {}
203
204
  };
204
- return headers;
205
+ return combinedHeaders;
205
206
  }
206
207
  class APIService {
207
208
  async getWallets(workspaceId) {
@@ -217,9 +218,9 @@ class APIService {
217
218
  const resp = await get(endpoint + `?address_type=${addressType}`, headers);
218
219
  return transformWalletDetail(resp.data);
219
220
  }
220
- async requestSign(walletId, params) {
221
+ async requestSign(walletId, params, options) {
221
222
  const endpoint = this.API.endpoints.requestSign(walletId);
222
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params);
223
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params, options);
223
224
  const response = await post(endpoint, params, headers);
224
225
  return response.data;
225
226
  }
@@ -229,10 +230,10 @@ class APIService {
229
230
  const response = await get(endpoint, headers);
230
231
  return response.data;
231
232
  }
232
- async signTransaction(walletId, body) {
233
+ async signTransaction(walletId, body, options) {
233
234
  const startTime = Date.now();
234
235
  const endpoint = this.API.endpoints.signTransaction(walletId);
235
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body);
236
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body, options);
236
237
  const response = await post(endpoint, body, headers);
237
238
  const elapsedTime = Date.now() - startTime;
238
239
  console.log(`[WalletSDK] Sign transaction completed in ${elapsedTime}ms`);
@@ -669,14 +670,14 @@ class EtherSigner extends AbstractSigner {
669
670
  }
670
671
  return result.status === TxStatus.Rejected;
671
672
  });
672
- console.log('reulst', result);
673
+ console.log('result', result);
673
674
  if (!result.hash) {
674
675
  throw new TransactionError('Transaction hash not found in successful response', 'TRANSACTION_HASH_MISSING', result.transaction_id);
675
676
  }
676
677
  return result.hash;
677
678
  }
678
679
  // Copied and editted from ethers.js -> Wallet -> BaseWallet
679
- async signTransaction(tx) {
680
+ async signTransaction(tx, options) {
680
681
  const startTime = new Date();
681
682
  console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`);
682
683
  if (!this.address) {
@@ -716,7 +717,7 @@ class EtherSigner extends AbstractSigner {
716
717
  accessList: btx.accessList
717
718
  };
718
719
  // return unseralized as API signTransaction is an asynchoronous action
719
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data);
720
+ const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data, options);
720
721
  const txHash = await this.waitForTransactonStatus(response.transaction_id);
721
722
  const endTime = new Date();
722
723
  const elapsedTimeMs = endTime.getTime() - startTime.getTime();
@@ -725,7 +726,7 @@ class EtherSigner extends AbstractSigner {
725
726
  console.log('[WalletSDK] Transaction succeed!');
726
727
  return txHash;
727
728
  }
728
- async sendTransaction(tx) {
729
+ async sendTransaction(tx, options) {
729
730
  const startTime = new Date();
730
731
  console.log(`[WalletSDK] sendTransaction started at: ${startTime.toLocaleString()}`);
731
732
  if (!this.address) {
@@ -753,7 +754,7 @@ class EtherSigner extends AbstractSigner {
753
754
  const resolvedTx = await resolveProperties(populatedTx);
754
755
  const txObj = Transaction.from(resolvedTx);
755
756
  console.log('[WalletSDK] Tx Data', txObj);
756
- const txHash = await this.signTransaction(txObj);
757
+ const txHash = await this.signTransaction(txObj, options);
757
758
  // Instead of creating a mock response, get the actual transaction from the provider
758
759
  const endTime = new Date();
759
760
  const totalElapsedMs = endTime.getTime() - startTime.getTime();
@@ -802,7 +803,7 @@ class EtherSigner extends AbstractSigner {
802
803
  // Let the provider create the TransactionResponse using the txHash
803
804
  return new TransactionResponse(txResponse, this.provider);
804
805
  }
805
- async signMessage(message) {
806
+ async signMessage(message, options) {
806
807
  if (!this.provider) {
807
808
  throw new Error('Provider is required for signing operations');
808
809
  }
@@ -818,10 +819,10 @@ class EtherSigner extends AbstractSigner {
818
819
  method: 'eth_sign',
819
820
  message: messageStr,
820
821
  chain_id: chainId
821
- });
822
+ }, options);
822
823
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id);
823
824
  }
824
- async signTypedData(domain, types, value) {
825
+ async signTypedData(domain, types, value, options) {
825
826
  if (!this.provider) {
826
827
  throw new Error('Provider is required for signing operations');
827
828
  }
@@ -842,7 +843,7 @@ class EtherSigner extends AbstractSigner {
842
843
  message: '',
843
844
  chain_id: chainId,
844
845
  typed_data: typedData
845
- });
846
+ }, options);
846
847
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id);
847
848
  }
848
849
  constructor(credentials, environment, provider, pollerOptions){
@@ -921,7 +922,7 @@ class SolanaSigner {
921
922
  * Signs a Solana transaction
922
923
  * @param transaction Base64 encoded serialized transaction
923
924
  * @returns Signature as a base58 encoded string
924
- */ async signTransaction(transaction) {
925
+ */ async signTransaction(transaction, options) {
925
926
  if (!this.address) {
926
927
  await this.getAddress();
927
928
  }
@@ -936,7 +937,7 @@ class SolanaSigner {
936
937
  tx_method: 'solana_signTransaction'
937
938
  },
938
939
  chainId: '1399811149'
939
- });
940
+ }, options);
940
941
  // Wait for the signature
941
942
  return this.waitForTransactionStatus(response.transaction_id);
942
943
  }
@@ -944,7 +945,7 @@ class SolanaSigner {
944
945
  * Signs a Solana message
945
946
  * @param message The message to sign (string or Uint8Array)
946
947
  * @returns Signature as a base58 encoded string
947
- */ async signMessage(message) {
948
+ */ async signMessage(message, options) {
948
949
  if (!this.address) {
949
950
  await this.getAddress();
950
951
  }
@@ -953,14 +954,14 @@ class SolanaSigner {
953
954
  method: 'solana_signMessage',
954
955
  message: messageStr,
955
956
  chain_id: 0 // Not used for Solana but required by API
956
- });
957
+ }, options);
957
958
  return this.waitForTransactionStatus(response.transaction_id);
958
959
  }
959
960
  /**
960
961
  * Signs and sends a Solana transaction
961
962
  * @param transaction Base64 encoded serialized transaction
962
963
  * @returns Transaction signature
963
- */ async signAndSendTransaction(transaction) {
964
+ */ async signAndSendTransaction(transaction, options) {
964
965
  if (!this.address) {
965
966
  await this.getAddress();
966
967
  }
@@ -969,7 +970,7 @@ class SolanaSigner {
969
970
  from: this.address,
970
971
  method: 'solana_signAndSendTransaction'
971
972
  };
972
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data);
973
+ const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data, options);
973
974
  const txHash = await this.waitForTransactionStatus(response.transaction_id);
974
975
  console.log('transaction succeed!');
975
976
  return txHash;
@@ -978,14 +979,14 @@ class SolanaSigner {
978
979
  * Signs multiple Solana transactions
979
980
  * @param transactions Array of base64 encoded serialized transactions
980
981
  * @returns Array of signatures as base58 encoded strings
981
- */ async signAllTransactions(transactions) {
982
+ */ async signAllTransactions(transactions, options) {
982
983
  if (!this.address) {
983
984
  await this.getAddress();
984
985
  }
985
986
  // We need to get the signatures and then incorporate them into the transactions
986
987
  const signaturePromises = transactions.map(async (transaction)=>{
987
988
  // Get the signature
988
- const signature = await this.signTransaction(transaction);
989
+ const signature = await this.signTransaction(transaction, options);
989
990
  // Here you would need to incorporate the signature into the transaction
990
991
  // This is a placeholder - you'll need to implement actual signature incorporation
991
992
  // based on your Solana transaction structure
package/dist/index.mjs CHANGED
@@ -174,7 +174,7 @@ var WalletRole;
174
174
  WalletRole["Viewer"] = "wallet_viewer";
175
175
  })(WalletRole || (WalletRole = {}));
176
176
 
177
- async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}) {
177
+ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
178
178
  if (!credentials.apiSecret || credentials.apiSecret === '') {
179
179
  // If APISecret is not provided, use authToken
180
180
  if (credentials.authToken) {
@@ -196,12 +196,13 @@ async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}
196
196
  body: Object.keys(body).length ? JSON.stringify(body) : ''
197
197
  };
198
198
  const digest = await computeHMAC(credentials.apiSecret, params);
199
- const headers = {
199
+ const combinedHeaders = {
200
200
  'ACCESS-API-KEY': credentials.apiKey,
201
201
  'ACCESS-TIMESTAMP': String(currentTimestampInSeconds),
202
- 'ACCESS-SIGN': btoa(digest) // convert to base64
202
+ 'ACCESS-SIGN': btoa(digest),
203
+ ...headers ?? {}
203
204
  };
204
- return headers;
205
+ return combinedHeaders;
205
206
  }
206
207
  class APIService {
207
208
  async getWallets(workspaceId) {
@@ -217,9 +218,9 @@ class APIService {
217
218
  const resp = await get(endpoint + `?address_type=${addressType}`, headers);
218
219
  return transformWalletDetail(resp.data);
219
220
  }
220
- async requestSign(walletId, params) {
221
+ async requestSign(walletId, params, options) {
221
222
  const endpoint = this.API.endpoints.requestSign(walletId);
222
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params);
223
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params, options);
223
224
  const response = await post(endpoint, params, headers);
224
225
  return response.data;
225
226
  }
@@ -229,10 +230,10 @@ class APIService {
229
230
  const response = await get(endpoint, headers);
230
231
  return response.data;
231
232
  }
232
- async signTransaction(walletId, body) {
233
+ async signTransaction(walletId, body, options) {
233
234
  const startTime = Date.now();
234
235
  const endpoint = this.API.endpoints.signTransaction(walletId);
235
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body);
236
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body, options);
236
237
  const response = await post(endpoint, body, headers);
237
238
  const elapsedTime = Date.now() - startTime;
238
239
  console.log(`[WalletSDK] Sign transaction completed in ${elapsedTime}ms`);
@@ -669,14 +670,14 @@ class EtherSigner extends AbstractSigner {
669
670
  }
670
671
  return result.status === TxStatus.Rejected;
671
672
  });
672
- console.log('reulst', result);
673
+ console.log('result', result);
673
674
  if (!result.hash) {
674
675
  throw new TransactionError('Transaction hash not found in successful response', 'TRANSACTION_HASH_MISSING', result.transaction_id);
675
676
  }
676
677
  return result.hash;
677
678
  }
678
679
  // Copied and editted from ethers.js -> Wallet -> BaseWallet
679
- async signTransaction(tx) {
680
+ async signTransaction(tx, options) {
680
681
  const startTime = new Date();
681
682
  console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`);
682
683
  if (!this.address) {
@@ -716,7 +717,7 @@ class EtherSigner extends AbstractSigner {
716
717
  accessList: btx.accessList
717
718
  };
718
719
  // return unseralized as API signTransaction is an asynchoronous action
719
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data);
720
+ const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data, options);
720
721
  const txHash = await this.waitForTransactonStatus(response.transaction_id);
721
722
  const endTime = new Date();
722
723
  const elapsedTimeMs = endTime.getTime() - startTime.getTime();
@@ -725,7 +726,7 @@ class EtherSigner extends AbstractSigner {
725
726
  console.log('[WalletSDK] Transaction succeed!');
726
727
  return txHash;
727
728
  }
728
- async sendTransaction(tx) {
729
+ async sendTransaction(tx, options) {
729
730
  const startTime = new Date();
730
731
  console.log(`[WalletSDK] sendTransaction started at: ${startTime.toLocaleString()}`);
731
732
  if (!this.address) {
@@ -753,7 +754,7 @@ class EtherSigner extends AbstractSigner {
753
754
  const resolvedTx = await resolveProperties(populatedTx);
754
755
  const txObj = Transaction.from(resolvedTx);
755
756
  console.log('[WalletSDK] Tx Data', txObj);
756
- const txHash = await this.signTransaction(txObj);
757
+ const txHash = await this.signTransaction(txObj, options);
757
758
  // Instead of creating a mock response, get the actual transaction from the provider
758
759
  const endTime = new Date();
759
760
  const totalElapsedMs = endTime.getTime() - startTime.getTime();
@@ -802,7 +803,7 @@ class EtherSigner extends AbstractSigner {
802
803
  // Let the provider create the TransactionResponse using the txHash
803
804
  return new TransactionResponse(txResponse, this.provider);
804
805
  }
805
- async signMessage(message) {
806
+ async signMessage(message, options) {
806
807
  if (!this.provider) {
807
808
  throw new Error('Provider is required for signing operations');
808
809
  }
@@ -818,10 +819,10 @@ class EtherSigner extends AbstractSigner {
818
819
  method: 'eth_sign',
819
820
  message: messageStr,
820
821
  chain_id: chainId
821
- });
822
+ }, options);
822
823
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id);
823
824
  }
824
- async signTypedData(domain, types, value) {
825
+ async signTypedData(domain, types, value, options) {
825
826
  if (!this.provider) {
826
827
  throw new Error('Provider is required for signing operations');
827
828
  }
@@ -842,7 +843,7 @@ class EtherSigner extends AbstractSigner {
842
843
  message: '',
843
844
  chain_id: chainId,
844
845
  typed_data: typedData
845
- });
846
+ }, options);
846
847
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id);
847
848
  }
848
849
  constructor(credentials, environment, provider, pollerOptions){
@@ -921,7 +922,7 @@ class SolanaSigner {
921
922
  * Signs a Solana transaction
922
923
  * @param transaction Base64 encoded serialized transaction
923
924
  * @returns Signature as a base58 encoded string
924
- */ async signTransaction(transaction) {
925
+ */ async signTransaction(transaction, options) {
925
926
  if (!this.address) {
926
927
  await this.getAddress();
927
928
  }
@@ -936,7 +937,7 @@ class SolanaSigner {
936
937
  tx_method: 'solana_signTransaction'
937
938
  },
938
939
  chainId: '1399811149'
939
- });
940
+ }, options);
940
941
  // Wait for the signature
941
942
  return this.waitForTransactionStatus(response.transaction_id);
942
943
  }
@@ -944,7 +945,7 @@ class SolanaSigner {
944
945
  * Signs a Solana message
945
946
  * @param message The message to sign (string or Uint8Array)
946
947
  * @returns Signature as a base58 encoded string
947
- */ async signMessage(message) {
948
+ */ async signMessage(message, options) {
948
949
  if (!this.address) {
949
950
  await this.getAddress();
950
951
  }
@@ -953,14 +954,14 @@ class SolanaSigner {
953
954
  method: 'solana_signMessage',
954
955
  message: messageStr,
955
956
  chain_id: 0 // Not used for Solana but required by API
956
- });
957
+ }, options);
957
958
  return this.waitForTransactionStatus(response.transaction_id);
958
959
  }
959
960
  /**
960
961
  * Signs and sends a Solana transaction
961
962
  * @param transaction Base64 encoded serialized transaction
962
963
  * @returns Transaction signature
963
- */ async signAndSendTransaction(transaction) {
964
+ */ async signAndSendTransaction(transaction, options) {
964
965
  if (!this.address) {
965
966
  await this.getAddress();
966
967
  }
@@ -969,7 +970,7 @@ class SolanaSigner {
969
970
  from: this.address,
970
971
  method: 'solana_signAndSendTransaction'
971
972
  };
972
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data);
973
+ const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data, options);
973
974
  const txHash = await this.waitForTransactionStatus(response.transaction_id);
974
975
  console.log('transaction succeed!');
975
976
  return txHash;
@@ -978,14 +979,14 @@ class SolanaSigner {
978
979
  * Signs multiple Solana transactions
979
980
  * @param transactions Array of base64 encoded serialized transactions
980
981
  * @returns Array of signatures as base58 encoded strings
981
- */ async signAllTransactions(transactions) {
982
+ */ async signAllTransactions(transactions, options) {
982
983
  if (!this.address) {
983
984
  await this.getAddress();
984
985
  }
985
986
  // We need to get the signatures and then incorporate them into the transactions
986
987
  const signaturePromises = transactions.map(async (transaction)=>{
987
988
  // Get the signature
988
- const signature = await this.signTransaction(transaction);
989
+ const signature = await this.signTransaction(transaction, options);
989
990
  // Here you would need to incorporate the signature into the transaction
990
991
  // This is a placeholder - you'll need to implement actual signature incorporation
991
992
  // based on your Solana transaction structure
@@ -361,9 +361,9 @@ declare class APIService {
361
361
  constructor(credentials: APICredentials, environment: Environment);
362
362
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
363
363
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
364
- requestSign(walletId: string, params: SignRequestParams): Promise<SignResponse>;
364
+ requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
365
365
  getSignStatus(walletId: string, transactionId: string): Promise<SignatureStatusResponse>;
366
- signTransaction(walletId: string, body: Record<string, any>): Promise<SignResponse>;
366
+ signTransaction(walletId: string, body: Record<string, any>, options?: Record<string, string>): Promise<SignResponse>;
367
367
  getTransactionStatus(walletId: string, transactionId: string): Promise<TransactionStatusResponse>;
368
368
  createWallet(payload: CreateWalletPayload): Promise<CreateWalletResponse>;
369
369
  createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse>;
@@ -646,10 +646,18 @@ declare class EtherSigner extends AbstractSigner {
646
646
  connect(provider: null | Provider): EtherSigner;
647
647
  private waitForSignature;
648
648
  private waitForTransactonStatus;
649
- signTransaction(tx: TransactionRequest): Promise<string>;
650
- sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
651
- signMessage(message: string | Uint8Array): Promise<string>;
652
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
649
+ signTransaction(tx: TransactionRequest, options?: {
650
+ idempotencyKey?: string;
651
+ }): Promise<string>;
652
+ sendTransaction(tx: TransactionRequest, options?: {
653
+ idempotencyKey?: string;
654
+ }): Promise<TransactionResponse>;
655
+ signMessage(message: string | Uint8Array, options?: {
656
+ idempotencyKey?: string;
657
+ }): Promise<string>;
658
+ signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, options?: {
659
+ idempotencyKey?: string;
660
+ }): Promise<string>;
653
661
  }
654
662
 
655
663
  declare class SolanaSigner {
@@ -668,25 +676,33 @@ declare class SolanaSigner {
668
676
  * @param transaction Base64 encoded serialized transaction
669
677
  * @returns Signature as a base58 encoded string
670
678
  */
671
- signTransaction(transaction: string): Promise<string>;
679
+ signTransaction(transaction: string, options?: {
680
+ idempotencyKey?: string;
681
+ }): Promise<string>;
672
682
  /**
673
683
  * Signs a Solana message
674
684
  * @param message The message to sign (string or Uint8Array)
675
685
  * @returns Signature as a base58 encoded string
676
686
  */
677
- signMessage(message: string | Uint8Array): Promise<string>;
687
+ signMessage(message: string | Uint8Array, options?: {
688
+ idempotencyKey?: string;
689
+ }): Promise<string>;
678
690
  /**
679
691
  * Signs and sends a Solana transaction
680
692
  * @param transaction Base64 encoded serialized transaction
681
693
  * @returns Transaction signature
682
694
  */
683
- signAndSendTransaction(transaction: string): Promise<string>;
695
+ signAndSendTransaction(transaction: string, options?: {
696
+ idempotencyKey?: string;
697
+ }): Promise<string>;
684
698
  /**
685
699
  * Signs multiple Solana transactions
686
700
  * @param transactions Array of base64 encoded serialized transactions
687
701
  * @returns Array of signatures as base58 encoded strings
688
702
  */
689
- signAllTransactions(transactions: string[]): Promise<{
703
+ signAllTransactions(transactions: string[], options?: {
704
+ idempotencyKey?: string;
705
+ }): Promise<{
690
706
  transactions: string[];
691
707
  }>;
692
708
  private incorporateSignatureIntoTransaction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fystack/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Wallet SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/types/index.d.ts",
package/src/api.ts CHANGED
@@ -69,7 +69,8 @@ async function composeAPIHeaders(
69
69
  credentials: APICredentials,
70
70
  httpMethod: string,
71
71
  apiEndpoint: string,
72
- body: Record<string, any> = {}
72
+ body: Record<string, any> = {},
73
+ headers?: Record<string, string>
73
74
  ): Promise<Record<string, string>> {
74
75
  if (!credentials.apiSecret || credentials.apiSecret === '') {
75
76
  // If APISecret is not provided, use authToken
@@ -94,13 +95,14 @@ async function composeAPIHeaders(
94
95
 
95
96
  const digest = await computeHMAC(credentials.apiSecret, params as Record<string, any>)
96
97
 
97
- const headers = {
98
+ const combinedHeaders = {
98
99
  'ACCESS-API-KEY': credentials.apiKey,
99
100
  'ACCESS-TIMESTAMP': String(currentTimestampInSeconds),
100
- 'ACCESS-SIGN': btoa(digest) // convert to base64
101
+ 'ACCESS-SIGN': btoa(digest), // convert to base64
102
+ ...(headers ?? {})
101
103
  }
102
104
 
103
- return headers
105
+ return combinedHeaders
104
106
  }
105
107
 
106
108
  export class APIService {
@@ -129,9 +131,13 @@ export class APIService {
129
131
  return transformWalletDetail(resp.data)
130
132
  }
131
133
 
132
- async requestSign(walletId: string, params: SignRequestParams): Promise<SignResponse> {
134
+ async requestSign(
135
+ walletId: string,
136
+ params: SignRequestParams,
137
+ options?: Record<string, string>
138
+ ): Promise<SignResponse> {
133
139
  const endpoint = this.API.endpoints.requestSign(walletId)
134
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params)
140
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, params, options)
135
141
  const response = await post(endpoint, params, headers)
136
142
  return response.data
137
143
  }
@@ -143,10 +149,14 @@ export class APIService {
143
149
  return response.data
144
150
  }
145
151
 
146
- async signTransaction(walletId: string, body: Record<string, any>): Promise<SignResponse> {
152
+ async signTransaction(
153
+ walletId: string,
154
+ body: Record<string, any>,
155
+ options?: Record<string, string>
156
+ ): Promise<SignResponse> {
147
157
  const startTime = Date.now()
148
158
  const endpoint = this.API.endpoints.signTransaction(walletId)
149
- const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body)
159
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, body, options)
150
160
  const response = await post(endpoint, body, headers)
151
161
  const elapsedTime = Date.now() - startTime
152
162
 
package/src/signer.ts CHANGED
@@ -151,7 +151,7 @@ export class EtherSigner extends AbstractSigner {
151
151
  return result.status === TxStatus.Rejected
152
152
  }
153
153
  )
154
- console.log('reulst', result)
154
+ console.log('result', result)
155
155
 
156
156
  if (!result.hash) {
157
157
  throw new TransactionError(
@@ -165,7 +165,10 @@ export class EtherSigner extends AbstractSigner {
165
165
  }
166
166
 
167
167
  // Copied and editted from ethers.js -> Wallet -> BaseWallet
168
- async signTransaction(tx: TransactionRequest): Promise<string> {
168
+ async signTransaction(
169
+ tx: TransactionRequest,
170
+ options?: { idempotencyKey?: string }
171
+ ): Promise<string> {
169
172
  const startTime = new Date()
170
173
  console.log(`[WalletSDK] Transaction started at: ${startTime.toLocaleString()}`)
171
174
 
@@ -216,7 +219,11 @@ export class EtherSigner extends AbstractSigner {
216
219
  accessList: btx.accessList
217
220
  }
218
221
  // return unseralized as API signTransaction is an asynchoronous action
219
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data)
222
+ const response = await this.APIService.signTransaction(
223
+ this.walletDetail.WalletID,
224
+ data,
225
+ options
226
+ )
220
227
  const txHash = await this.waitForTransactonStatus(response.transaction_id)
221
228
 
222
229
  const endTime = new Date()
@@ -230,7 +237,10 @@ export class EtherSigner extends AbstractSigner {
230
237
  return txHash
231
238
  }
232
239
 
233
- async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
240
+ async sendTransaction(
241
+ tx: TransactionRequest,
242
+ options?: { idempotencyKey?: string }
243
+ ): Promise<TransactionResponse> {
234
244
  const startTime = new Date()
235
245
  console.log(`[WalletSDK] sendTransaction started at: ${startTime.toLocaleString()}`)
236
246
 
@@ -272,7 +282,7 @@ export class EtherSigner extends AbstractSigner {
272
282
 
273
283
  console.log('[WalletSDK] Tx Data', txObj)
274
284
 
275
- const txHash = await this.signTransaction(txObj)
285
+ const txHash = await this.signTransaction(txObj, options)
276
286
 
277
287
  // Instead of creating a mock response, get the actual transaction from the provider
278
288
  const endTime = new Date()
@@ -341,7 +351,10 @@ export class EtherSigner extends AbstractSigner {
341
351
  return new TransactionResponse(txResponse, this.provider as Provider)
342
352
  }
343
353
 
344
- async signMessage(message: string | Uint8Array): Promise<string> {
354
+ async signMessage(
355
+ message: string | Uint8Array,
356
+ options?: { idempotencyKey?: string }
357
+ ): Promise<string> {
345
358
  if (!this.provider) {
346
359
  throw new Error('Provider is required for signing operations')
347
360
  }
@@ -357,11 +370,15 @@ export class EtherSigner extends AbstractSigner {
357
370
  const chainId = await this.getChainId()
358
371
  const messageStr = typeof message === 'string' ? message : Buffer.from(message).toString('hex')
359
372
 
360
- const response = await this.APIService.requestSign(this.walletDetail.WalletID, {
361
- method: 'eth_sign',
362
- message: messageStr,
363
- chain_id: chainId
364
- })
373
+ const response = await this.APIService.requestSign(
374
+ this.walletDetail.WalletID,
375
+ {
376
+ method: 'eth_sign',
377
+ message: messageStr,
378
+ chain_id: chainId
379
+ },
380
+ options
381
+ )
365
382
 
366
383
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id)
367
384
  }
@@ -369,7 +386,8 @@ export class EtherSigner extends AbstractSigner {
369
386
  async signTypedData(
370
387
  domain: TypedDataDomain,
371
388
  types: Record<string, Array<TypedDataField>>,
372
- value: Record<string, any>
389
+ value: Record<string, any>,
390
+ options?: { idempotencyKey?: string }
373
391
  ): Promise<string> {
374
392
  if (!this.provider) {
375
393
  throw new Error('Provider is required for signing operations')
@@ -390,12 +408,16 @@ export class EtherSigner extends AbstractSigner {
390
408
  message: value
391
409
  })
392
410
 
393
- const response = await this.APIService.requestSign(this.walletDetail.WalletID, {
394
- method: 'eth_signTypedData_v4',
395
- message: '',
396
- chain_id: chainId,
397
- typed_data: typedData
398
- })
411
+ const response = await this.APIService.requestSign(
412
+ this.walletDetail.WalletID,
413
+ {
414
+ method: 'eth_signTypedData_v4',
415
+ message: '',
416
+ chain_id: chainId,
417
+ typed_data: typedData
418
+ },
419
+ options
420
+ )
399
421
 
400
422
  return this.waitForSignature(this.walletDetail.WalletID, response.transaction_id)
401
423
  }
@@ -117,7 +117,10 @@ export class SolanaSigner {
117
117
  * @param transaction Base64 encoded serialized transaction
118
118
  * @returns Signature as a base58 encoded string
119
119
  */
120
- async signTransaction(transaction: string): Promise<string> {
120
+ async signTransaction(
121
+ transaction: string,
122
+ options?: { idempotencyKey?: string }
123
+ ): Promise<string> {
121
124
  if (!this.address) {
122
125
  await this.getAddress()
123
126
  }
@@ -128,13 +131,17 @@ export class SolanaSigner {
128
131
  }
129
132
 
130
133
  // Call the signRaw API similar to EtherSigner
131
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
132
- ...data,
133
- meta: {
134
- tx_method: 'solana_signTransaction'
134
+ const response = await this.APIService.signTransaction(
135
+ this.walletDetail.WalletID,
136
+ {
137
+ ...data,
138
+ meta: {
139
+ tx_method: 'solana_signTransaction'
140
+ },
141
+ chainId: '1399811149'
135
142
  },
136
- chainId: '1399811149'
137
- })
143
+ options
144
+ )
138
145
 
139
146
  // Wait for the signature
140
147
  return this.waitForTransactionStatus(response.transaction_id)
@@ -145,7 +152,10 @@ export class SolanaSigner {
145
152
  * @param message The message to sign (string or Uint8Array)
146
153
  * @returns Signature as a base58 encoded string
147
154
  */
148
- async signMessage(message: string | Uint8Array): Promise<string> {
155
+ async signMessage(
156
+ message: string | Uint8Array,
157
+ options?: { idempotencyKey?: string }
158
+ ): Promise<string> {
149
159
  if (!this.address) {
150
160
  await this.getAddress()
151
161
  }
@@ -153,11 +163,15 @@ export class SolanaSigner {
153
163
  const messageStr =
154
164
  typeof message === 'string' ? message : Buffer.from(message).toString('base64')
155
165
 
156
- const response = await this.APIService.requestSign(this.walletDetail.WalletID, {
157
- method: 'solana_signMessage',
158
- message: messageStr,
159
- chain_id: 0 // Not used for Solana but required by API
160
- })
166
+ const response = await this.APIService.requestSign(
167
+ this.walletDetail.WalletID,
168
+ {
169
+ method: 'solana_signMessage',
170
+ message: messageStr,
171
+ chain_id: 0 // Not used for Solana but required by API
172
+ },
173
+ options
174
+ )
161
175
 
162
176
  return this.waitForTransactionStatus(response.transaction_id)
163
177
  }
@@ -167,7 +181,10 @@ export class SolanaSigner {
167
181
  * @param transaction Base64 encoded serialized transaction
168
182
  * @returns Transaction signature
169
183
  */
170
- async signAndSendTransaction(transaction: string): Promise<string> {
184
+ async signAndSendTransaction(
185
+ transaction: string,
186
+ options?: { idempotencyKey?: string }
187
+ ): Promise<string> {
171
188
  if (!this.address) {
172
189
  await this.getAddress()
173
190
  }
@@ -178,7 +195,11 @@ export class SolanaSigner {
178
195
  method: 'solana_signAndSendTransaction'
179
196
  }
180
197
 
181
- const response = await this.APIService.signTransaction(this.walletDetail.WalletID, data)
198
+ const response = await this.APIService.signTransaction(
199
+ this.walletDetail.WalletID,
200
+ data,
201
+ options
202
+ )
182
203
  const txHash = await this.waitForTransactionStatus(response.transaction_id)
183
204
  console.log('transaction succeed!')
184
205
 
@@ -190,7 +211,10 @@ export class SolanaSigner {
190
211
  * @param transactions Array of base64 encoded serialized transactions
191
212
  * @returns Array of signatures as base58 encoded strings
192
213
  */
193
- async signAllTransactions(transactions: string[]): Promise<{ transactions: string[] }> {
214
+ async signAllTransactions(
215
+ transactions: string[],
216
+ options?: { idempotencyKey?: string }
217
+ ): Promise<{ transactions: string[] }> {
194
218
  if (!this.address) {
195
219
  await this.getAddress()
196
220
  }
@@ -198,7 +222,7 @@ export class SolanaSigner {
198
222
  // We need to get the signatures and then incorporate them into the transactions
199
223
  const signaturePromises = transactions.map(async (transaction) => {
200
224
  // Get the signature
201
- const signature = await this.signTransaction(transaction)
225
+ const signature = await this.signTransaction(transaction, options)
202
226
 
203
227
  // Here you would need to incorporate the signature into the transaction
204
228
  // This is a placeholder - you'll need to implement actual signature incorporation
package/src/types.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import { SweepTaskParams } from './api'
2
- import { TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType } from './enum'
2
+ import {
3
+ TxApprovalStatus,
4
+ TxStatus,
5
+ WalletCreationStatus,
6
+ WalletPurpose,
7
+ WalletRole,
8
+ WalletType
9
+ } from './enum'
3
10
 
4
11
  export class TransactionError extends Error {
5
12
  constructor(