@openfort/openfort-js 0.8.26 → 0.8.27

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/README.md CHANGED
@@ -12,8 +12,8 @@
12
12
  API Docs
13
13
  </a>
14
14
  <span> | </span>
15
- <a href="https://twitter.com/openfortxyz">
16
- Twitter
15
+ <a href="https://x.com/openfortxyz">
16
+ X
17
17
  </a>
18
18
  </h4>
19
19
  </div>
@@ -48,7 +48,7 @@ The Session Signer allows you to use external signing keys, without needing to p
48
48
  ```typescript
49
49
  const sessionKey = sdk.configureSessionKey();
50
50
  ```
51
- - **Register Key and Send Signature Session Request**: If `sessionKey.isRegistered` boolean is false, register the key from the backend. Refer to the documentation for [session management](https://www.openfort.xyz/docs/guides/accounts/smart/session-keys).
51
+ - **Register Key and Send Signature Session Request**: If `sessionKey.isRegistered` boolean is false, register the key from the backend. Refer to the documentation for [session keys](https://www.openfort.xyz/docs/guides/javascript/smart-wallet/advanced/session-keys).
52
52
  - **Send Signature Transaction Intent Request**: When calling sendSignatureTransactionIntentRequest, pass the transaction intent ID and the user operation hash. The session signer will handle the signing.
53
53
 
54
54
  ### 2. External Sign
@@ -75,7 +75,7 @@ The Embedded Signer uses SSS to manage the private key on the client side. To le
75
75
  // using automatic recovery
76
76
  await sdk.configureEmbeddedSigner(chainId, shieldAuth);
77
77
  ```
78
- For now the only two recovery method available are the `PasswordRecovery` and `AutomaticRecovery`. Learn more about the [recovery methods](https://www.openfort.xyz/docs/guides/auth/embedded-signer/recovery).
78
+ For now the only two recovery method available are the `PasswordRecovery` and `AutomaticRecovery`. Learn more about the [recovery methods](https://www.openfort.xyz/docs/guides/javascript/embedded-signer/recovery).
79
79
  - **Send Signature Transaction Intent Request**: Similar to the session signer, pass the transaction intent ID and the user operation hash. The embedded signer reconstructs the key and signs the transaction.
80
80
  ```typescript
81
81
  const response = await sdk.sendSignatureTransactionIntentRequest("transactionIntentId", "userOp");
package/dist/index.cjs CHANGED
@@ -3492,7 +3492,7 @@ class KeyPair extends signingKey.SigningKey {
3492
3492
  }
3493
3493
  }
3494
3494
 
3495
- const VERSION = '0.8.26';
3495
+ const VERSION = '0.8.27';
3496
3496
 
3497
3497
  var Event;
3498
3498
  (function (Event) {
@@ -4157,15 +4157,8 @@ const withOpenfortError = async (fn, customErrorType) => {
4157
4157
  const statusCode = error.response?.status;
4158
4158
  errorType = statusCode ? customErrorType[statusCode] || customErrorType.default : customErrorType.default;
4159
4159
  if (error.response?.data && error.response.data.error) {
4160
- const jsonData = JSON.parse(JSON.stringify(error.response.data.error));
4161
- // eslint-disable-next-line no-restricted-syntax
4162
- for (const key in jsonData) {
4163
- if (key !== 'message' && key !== 'type') {
4164
- data[key] = jsonData[key];
4165
- }
4166
- }
4167
- if (isAPIError(error.response.data)) {
4168
- errorMessage = error.response.data.message;
4160
+ if (isAPIError(error.response.data.error)) {
4161
+ errorMessage = error.response.data.error.message;
4169
4162
  }
4170
4163
  else {
4171
4164
  errorMessage = error.message;
@@ -5077,69 +5070,6 @@ class JsonRpcError extends Error {
5077
5070
  }
5078
5071
  }
5079
5072
 
5080
- const buildOpenfortTransactions$4 = async (transactionRequest, backendApiClients, account, authentication, policyId) => {
5081
- const interactions = transactionRequest.map((tx) => {
5082
- if (!tx.to) {
5083
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
5084
- }
5085
- return {
5086
- to: String(tx.to),
5087
- data: tx.data ? String(tx.data) : undefined,
5088
- value: tx.value ? String(tx.value) : undefined,
5089
- };
5090
- });
5091
- const transactionResponse = await backendApiClients.transactionIntentsApi.createTransactionIntent({
5092
- createTransactionIntentRequest: {
5093
- policy: policyId,
5094
- chainId: account.chainId,
5095
- interactions,
5096
- },
5097
- }, {
5098
- headers: {
5099
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
5100
- // eslint-disable-next-line @typescript-eslint/naming-convention
5101
- 'x-player-token': authentication.token,
5102
- // eslint-disable-next-line @typescript-eslint/naming-convention
5103
- 'x-auth-provider': authentication.thirdPartyProvider,
5104
- // eslint-disable-next-line @typescript-eslint/naming-convention
5105
- 'x-token-type': authentication.thirdPartyTokenType,
5106
- },
5107
- });
5108
- return transactionResponse.data;
5109
- };
5110
- const sendTransaction = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
5111
- const openfortTransaction = await buildOpenfortTransactions$4(params, backendClient, account, authentication, policyId);
5112
- let response;
5113
- if (openfortTransaction?.nextAction?.payload?.signableHash) {
5114
- let signature;
5115
- // zkSync based chains need a different signature
5116
- if ([300, 531050104, 324, 50104, 2741, 11124].includes(account.chainId)) {
5117
- signature = await signer.sign(openfortTransaction.nextAction.payload.signableHash, false, false);
5118
- }
5119
- else {
5120
- signature = await signer.sign(openfortTransaction.nextAction.payload.signableHash);
5121
- }
5122
- const openfortSignatureResponse = (await backendClient.transactionIntentsApi.signature({
5123
- id: openfortTransaction.id,
5124
- signatureRequest: { signature },
5125
- })).data.response;
5126
- if (!openfortSignatureResponse) {
5127
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
5128
- }
5129
- response = openfortSignatureResponse;
5130
- }
5131
- else if (openfortTransaction.response) {
5132
- response = openfortTransaction.response;
5133
- }
5134
- else {
5135
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
5136
- }
5137
- if (response.status === 0 && !response.transactionHash) {
5138
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.error.reason);
5139
- }
5140
- return response.transactionHash;
5141
- };
5142
-
5143
5073
  const REQUIRED_TYPED_DATA_PROPERTIES = ['types', 'domain', 'primaryType', 'message'];
5144
5074
  const isValidTypedDataPayload = (typedData) => (REQUIRED_TYPED_DATA_PROPERTIES.every((key) => key in typedData));
5145
5075
  const transformTypedData = (typedData, chainId) => {
@@ -6712,20 +6642,23 @@ const buildOpenfortTransactions$3 = async (params, backendApiClients, account, a
6712
6642
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'Failed to request permissions - missing session address');
6713
6643
  }
6714
6644
  const sessionRequest = formatSessionRequest$1(sessionAddress, account.chainId, now, expiry, policyId, false, whitelist, authentication.player, limit);
6715
- const transactionResponse = await backendApiClients.sessionsApi.createSession({
6716
- createSessionRequest: sessionRequest,
6717
- }, {
6718
- headers: {
6719
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6720
- // eslint-disable-next-line @typescript-eslint/naming-convention
6721
- 'x-player-token': authentication.token,
6722
- // eslint-disable-next-line @typescript-eslint/naming-convention
6723
- 'x-auth-provider': authentication.thirdPartyProvider,
6724
- // eslint-disable-next-line @typescript-eslint/naming-convention
6725
- 'x-token-type': authentication.thirdPartyTokenType,
6726
- },
6727
- });
6728
- return transactionResponse.data;
6645
+ return withOpenfortError(async () => {
6646
+ const response = await backendApiClients.sessionsApi.createSession({
6647
+ createSessionRequest: sessionRequest,
6648
+ }, {
6649
+ headers: {
6650
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6651
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6652
+ 'x-player-token': authentication.token,
6653
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6654
+ 'x-auth-provider': authentication.thirdPartyProvider,
6655
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6656
+ 'x-token-type': authentication.thirdPartyTokenType,
6657
+ },
6658
+ });
6659
+ return response.data;
6660
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6661
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
6729
6662
  };
6730
6663
  function formatRequest(result) {
6731
6664
  return {
@@ -6747,8 +6680,9 @@ function formatRequest(result) {
6747
6680
  };
6748
6681
  }
6749
6682
  const registerSession = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6750
- const openfortTransaction = await buildOpenfortTransactions$3(params, backendClient, account, authentication, policyId);
6751
- let response;
6683
+ const openfortTransaction = await buildOpenfortTransactions$3(params, backendClient, account, authentication, policyId).catch((error) => {
6684
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6685
+ });
6752
6686
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
6753
6687
  let signature;
6754
6688
  // zkSync based chains need a different signature
@@ -6761,19 +6695,15 @@ const registerSession = async ({ params, signer, account, authentication, backen
6761
6695
  const openfortSignatureResponse = await backendClient.sessionsApi.signatureSession({
6762
6696
  id: openfortTransaction.id,
6763
6697
  signatureRequest: { signature },
6698
+ }).catch((error) => {
6699
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6764
6700
  });
6765
- if (!openfortSignatureResponse) {
6766
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6767
- }
6768
- response = openfortSignatureResponse.data;
6701
+ return formatRequest(openfortSignatureResponse.data);
6769
6702
  }
6770
- else {
6771
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6772
- }
6773
- if (response.isActive === false) {
6774
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Failed to request permissions');
6703
+ if (openfortTransaction.isActive === false) {
6704
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Failed to grant permissions');
6775
6705
  }
6776
- return formatRequest(response);
6706
+ return formatRequest(openfortTransaction);
6777
6707
  };
6778
6708
 
6779
6709
  const formatSessionRequest = (address, chainId, player, policyId) => {
@@ -6788,20 +6718,23 @@ const formatSessionRequest = (address, chainId, player, policyId) => {
6788
6718
  };
6789
6719
  const buildOpenfortTransactions$2 = async (params, backendApiClients, account, authentication, policyId) => {
6790
6720
  const sessionRequest = formatSessionRequest(params.permissionContext, account.chainId, authentication.player, policyId);
6791
- const transactionResponse = await backendApiClients.sessionsApi.revokeSession({
6792
- revokeSessionRequest: sessionRequest,
6793
- }, {
6794
- headers: {
6795
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6796
- // eslint-disable-next-line @typescript-eslint/naming-convention
6797
- 'x-player-token': authentication.token,
6798
- // eslint-disable-next-line @typescript-eslint/naming-convention
6799
- 'x-auth-provider': authentication.thirdPartyProvider,
6800
- // eslint-disable-next-line @typescript-eslint/naming-convention
6801
- 'x-token-type': authentication.thirdPartyTokenType,
6802
- },
6803
- });
6804
- return transactionResponse.data;
6721
+ return withOpenfortError(async () => {
6722
+ const response = await backendApiClients.sessionsApi.revokeSession({
6723
+ revokeSessionRequest: sessionRequest,
6724
+ }, {
6725
+ headers: {
6726
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6727
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6728
+ 'x-player-token': authentication.token,
6729
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6730
+ 'x-auth-provider': authentication.thirdPartyProvider,
6731
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6732
+ 'x-token-type': authentication.thirdPartyTokenType,
6733
+ },
6734
+ });
6735
+ return response.data;
6736
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6737
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
6805
6738
  };
6806
6739
  const revokeSession = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6807
6740
  const param = params[0];
@@ -6809,8 +6742,9 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6809
6742
  await signer.logout();
6810
6743
  return {};
6811
6744
  }
6812
- const openfortTransaction = await buildOpenfortTransactions$2(param, backendClient, account, authentication, policyId);
6813
- let response;
6745
+ const openfortTransaction = await buildOpenfortTransactions$2(param, backendClient, account, authentication, policyId).catch((error) => {
6746
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6747
+ });
6814
6748
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
6815
6749
  let signature;
6816
6750
  // zkSync based chains need a different signature
@@ -6823,19 +6757,12 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6823
6757
  const openfortSignatureResponse = await backendClient.sessionsApi.signatureSession({
6824
6758
  id: openfortTransaction.id,
6825
6759
  signatureRequest: { signature },
6760
+ }).catch((error) => {
6761
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6826
6762
  });
6827
- if (!openfortSignatureResponse) {
6828
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6829
- }
6830
- response = openfortSignatureResponse.data;
6763
+ return openfortSignatureResponse.data;
6831
6764
  }
6832
- else {
6833
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6834
- }
6835
- if (response.isActive === false) {
6836
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Failed to request permissions');
6837
- }
6838
- return {};
6765
+ return openfortTransaction;
6839
6766
  };
6840
6767
 
6841
6768
  const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, authentication, policyId) => {
@@ -6849,29 +6776,33 @@ const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, au
6849
6776
  value: call.value ? String(call.value) : undefined,
6850
6777
  };
6851
6778
  });
6852
- const transactionResponse = await backendApiClients.transactionIntentsApi.createTransactionIntent({
6853
- createTransactionIntentRequest: {
6854
- policy: policyId,
6855
- chainId: account.chainId,
6856
- interactions,
6857
- },
6858
- }, {
6859
- headers: {
6860
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6861
- // eslint-disable-next-line @typescript-eslint/naming-convention
6862
- 'x-player-token': authentication.token,
6863
- // eslint-disable-next-line @typescript-eslint/naming-convention
6864
- 'x-auth-provider': authentication.thirdPartyProvider,
6865
- // eslint-disable-next-line @typescript-eslint/naming-convention
6866
- 'x-token-type': authentication.thirdPartyTokenType,
6867
- },
6868
- });
6869
- return transactionResponse.data;
6779
+ return withOpenfortError(async () => {
6780
+ const response = await backendApiClients.transactionIntentsApi.createTransactionIntent({
6781
+ createTransactionIntentRequest: {
6782
+ policy: policyId,
6783
+ chainId: account.chainId,
6784
+ interactions,
6785
+ },
6786
+ }, {
6787
+ headers: {
6788
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6789
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6790
+ 'x-player-token': authentication.token,
6791
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6792
+ 'x-auth-provider': authentication.thirdPartyProvider,
6793
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6794
+ 'x-token-type': authentication.thirdPartyTokenType,
6795
+ },
6796
+ });
6797
+ return response.data;
6798
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6799
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
6870
6800
  };
6871
6801
  const sendCalls = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6872
6802
  const policy = params[0]?.capabilities?.paymasterService?.policy ?? policyId;
6873
- const openfortTransaction = await buildOpenfortTransactions$1(params[0].calls, backendClient, account, authentication, policy);
6874
- let response;
6803
+ const openfortTransaction = await buildOpenfortTransactions$1(params, backendClient, account, authentication, policy).catch((error) => {
6804
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6805
+ });
6875
6806
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
6876
6807
  let signature;
6877
6808
  // zkSync based chains need a different signature
@@ -6881,29 +6812,25 @@ const sendCalls = async ({ params, signer, account, authentication, backendClien
6881
6812
  else {
6882
6813
  signature = await signer.sign(openfortTransaction.nextAction.payload.signableHash);
6883
6814
  }
6884
- const openfortSignatureResponse = (await backendClient.transactionIntentsApi.signature({
6815
+ const response = await backendClient.transactionIntentsApi.signature({
6885
6816
  id: openfortTransaction.id,
6886
6817
  signatureRequest: { signature },
6887
- })).data.response;
6888
- if (!openfortSignatureResponse) {
6889
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6818
+ }).catch((error) => {
6819
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6820
+ });
6821
+ if (response.data.response?.error) {
6822
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, response.data.response.error.reason);
6890
6823
  }
6891
- response = openfortSignatureResponse;
6892
- }
6893
- else if (openfortTransaction.response) {
6894
- response = openfortTransaction.response;
6895
- }
6896
- else {
6897
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6898
- }
6899
- if (response.status === 0 && !response.transactionHash) {
6900
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.error.reason);
6824
+ if (response.data.response?.status === 0) {
6825
+ throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.data.response?.error.reason);
6826
+ }
6827
+ return response.data.response?.transactionHash;
6901
6828
  }
6902
- return response.transactionHash;
6829
+ return openfortTransaction.response?.transactionHash;
6903
6830
  };
6904
6831
 
6905
- const buildOpenfortTransactions = async (transactionIntentId, backendApiClients, authentication) => {
6906
- const transactionResponse = await backendApiClients.transactionIntentsApi.getTransactionIntent({
6832
+ const buildOpenfortTransactions = async (transactionIntentId, backendApiClients, authentication) => withOpenfortError(async () => {
6833
+ const response = await backendApiClients.transactionIntentsApi.getTransactionIntent({
6907
6834
  id: transactionIntentId,
6908
6835
  }, {
6909
6836
  headers: {
@@ -6916,10 +6843,13 @@ const buildOpenfortTransactions = async (transactionIntentId, backendApiClients,
6916
6843
  'x-token-type': authentication.thirdPartyTokenType,
6917
6844
  },
6918
6845
  });
6919
- return transactionResponse.data;
6920
- };
6846
+ return response.data;
6847
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6848
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
6921
6849
  const getCallStatus = async ({ params, authentication, backendClient, }) => {
6922
- const transactionIntent = await buildOpenfortTransactions(params[0], backendClient, authentication);
6850
+ const transactionIntent = await buildOpenfortTransactions(params[0], backendClient, authentication).catch((error) => {
6851
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6852
+ });
6923
6853
  return {
6924
6854
  status: !transactionIntent.response ? 'PENDING' : 'CONFIRMED',
6925
6855
  receipts: transactionIntent.response
@@ -7023,7 +6953,7 @@ class EvmProvider {
7023
6953
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
7024
6954
  }
7025
6955
  this.#validateAndRefreshSession();
7026
- return await sendTransaction({
6956
+ return await sendCalls({
7027
6957
  params: request.params || [],
7028
6958
  signer,
7029
6959
  account,
@@ -7128,7 +7058,7 @@ class EvmProvider {
7128
7058
  }
7129
7059
  this.#validateAndRefreshSession();
7130
7060
  return await sendCalls({
7131
- params: request.params || [],
7061
+ params: request.params ? request.params[0].calls : [],
7132
7062
  signer,
7133
7063
  account,
7134
7064
  authentication,
package/dist/index.js CHANGED
@@ -3469,7 +3469,7 @@ class KeyPair extends SigningKey {
3469
3469
  }
3470
3470
  }
3471
3471
 
3472
- const VERSION = '0.8.26';
3472
+ const VERSION = '0.8.27';
3473
3473
 
3474
3474
  var Event;
3475
3475
  (function (Event) {
@@ -4134,15 +4134,8 @@ const withOpenfortError = async (fn, customErrorType) => {
4134
4134
  const statusCode = error.response?.status;
4135
4135
  errorType = statusCode ? customErrorType[statusCode] || customErrorType.default : customErrorType.default;
4136
4136
  if (error.response?.data && error.response.data.error) {
4137
- const jsonData = JSON.parse(JSON.stringify(error.response.data.error));
4138
- // eslint-disable-next-line no-restricted-syntax
4139
- for (const key in jsonData) {
4140
- if (key !== 'message' && key !== 'type') {
4141
- data[key] = jsonData[key];
4142
- }
4143
- }
4144
- if (isAPIError(error.response.data)) {
4145
- errorMessage = error.response.data.message;
4137
+ if (isAPIError(error.response.data.error)) {
4138
+ errorMessage = error.response.data.error.message;
4146
4139
  }
4147
4140
  else {
4148
4141
  errorMessage = error.message;
@@ -5054,69 +5047,6 @@ class JsonRpcError extends Error {
5054
5047
  }
5055
5048
  }
5056
5049
 
5057
- const buildOpenfortTransactions$4 = async (transactionRequest, backendApiClients, account, authentication, policyId) => {
5058
- const interactions = transactionRequest.map((tx) => {
5059
- if (!tx.to) {
5060
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
5061
- }
5062
- return {
5063
- to: String(tx.to),
5064
- data: tx.data ? String(tx.data) : undefined,
5065
- value: tx.value ? String(tx.value) : undefined,
5066
- };
5067
- });
5068
- const transactionResponse = await backendApiClients.transactionIntentsApi.createTransactionIntent({
5069
- createTransactionIntentRequest: {
5070
- policy: policyId,
5071
- chainId: account.chainId,
5072
- interactions,
5073
- },
5074
- }, {
5075
- headers: {
5076
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
5077
- // eslint-disable-next-line @typescript-eslint/naming-convention
5078
- 'x-player-token': authentication.token,
5079
- // eslint-disable-next-line @typescript-eslint/naming-convention
5080
- 'x-auth-provider': authentication.thirdPartyProvider,
5081
- // eslint-disable-next-line @typescript-eslint/naming-convention
5082
- 'x-token-type': authentication.thirdPartyTokenType,
5083
- },
5084
- });
5085
- return transactionResponse.data;
5086
- };
5087
- const sendTransaction = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
5088
- const openfortTransaction = await buildOpenfortTransactions$4(params, backendClient, account, authentication, policyId);
5089
- let response;
5090
- if (openfortTransaction?.nextAction?.payload?.signableHash) {
5091
- let signature;
5092
- // zkSync based chains need a different signature
5093
- if ([300, 531050104, 324, 50104, 2741, 11124].includes(account.chainId)) {
5094
- signature = await signer.sign(openfortTransaction.nextAction.payload.signableHash, false, false);
5095
- }
5096
- else {
5097
- signature = await signer.sign(openfortTransaction.nextAction.payload.signableHash);
5098
- }
5099
- const openfortSignatureResponse = (await backendClient.transactionIntentsApi.signature({
5100
- id: openfortTransaction.id,
5101
- signatureRequest: { signature },
5102
- })).data.response;
5103
- if (!openfortSignatureResponse) {
5104
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
5105
- }
5106
- response = openfortSignatureResponse;
5107
- }
5108
- else if (openfortTransaction.response) {
5109
- response = openfortTransaction.response;
5110
- }
5111
- else {
5112
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
5113
- }
5114
- if (response.status === 0 && !response.transactionHash) {
5115
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.error.reason);
5116
- }
5117
- return response.transactionHash;
5118
- };
5119
-
5120
5050
  const REQUIRED_TYPED_DATA_PROPERTIES = ['types', 'domain', 'primaryType', 'message'];
5121
5051
  const isValidTypedDataPayload = (typedData) => (REQUIRED_TYPED_DATA_PROPERTIES.every((key) => key in typedData));
5122
5052
  const transformTypedData = (typedData, chainId) => {
@@ -6689,20 +6619,23 @@ const buildOpenfortTransactions$3 = async (params, backendApiClients, account, a
6689
6619
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'Failed to request permissions - missing session address');
6690
6620
  }
6691
6621
  const sessionRequest = formatSessionRequest$1(sessionAddress, account.chainId, now, expiry, policyId, false, whitelist, authentication.player, limit);
6692
- const transactionResponse = await backendApiClients.sessionsApi.createSession({
6693
- createSessionRequest: sessionRequest,
6694
- }, {
6695
- headers: {
6696
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6697
- // eslint-disable-next-line @typescript-eslint/naming-convention
6698
- 'x-player-token': authentication.token,
6699
- // eslint-disable-next-line @typescript-eslint/naming-convention
6700
- 'x-auth-provider': authentication.thirdPartyProvider,
6701
- // eslint-disable-next-line @typescript-eslint/naming-convention
6702
- 'x-token-type': authentication.thirdPartyTokenType,
6703
- },
6704
- });
6705
- return transactionResponse.data;
6622
+ return withOpenfortError(async () => {
6623
+ const response = await backendApiClients.sessionsApi.createSession({
6624
+ createSessionRequest: sessionRequest,
6625
+ }, {
6626
+ headers: {
6627
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6628
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6629
+ 'x-player-token': authentication.token,
6630
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6631
+ 'x-auth-provider': authentication.thirdPartyProvider,
6632
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6633
+ 'x-token-type': authentication.thirdPartyTokenType,
6634
+ },
6635
+ });
6636
+ return response.data;
6637
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6638
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
6706
6639
  };
6707
6640
  function formatRequest(result) {
6708
6641
  return {
@@ -6724,8 +6657,9 @@ function formatRequest(result) {
6724
6657
  };
6725
6658
  }
6726
6659
  const registerSession = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6727
- const openfortTransaction = await buildOpenfortTransactions$3(params, backendClient, account, authentication, policyId);
6728
- let response;
6660
+ const openfortTransaction = await buildOpenfortTransactions$3(params, backendClient, account, authentication, policyId).catch((error) => {
6661
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6662
+ });
6729
6663
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
6730
6664
  let signature;
6731
6665
  // zkSync based chains need a different signature
@@ -6738,19 +6672,15 @@ const registerSession = async ({ params, signer, account, authentication, backen
6738
6672
  const openfortSignatureResponse = await backendClient.sessionsApi.signatureSession({
6739
6673
  id: openfortTransaction.id,
6740
6674
  signatureRequest: { signature },
6675
+ }).catch((error) => {
6676
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6741
6677
  });
6742
- if (!openfortSignatureResponse) {
6743
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6744
- }
6745
- response = openfortSignatureResponse.data;
6678
+ return formatRequest(openfortSignatureResponse.data);
6746
6679
  }
6747
- else {
6748
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6749
- }
6750
- if (response.isActive === false) {
6751
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Failed to request permissions');
6680
+ if (openfortTransaction.isActive === false) {
6681
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Failed to grant permissions');
6752
6682
  }
6753
- return formatRequest(response);
6683
+ return formatRequest(openfortTransaction);
6754
6684
  };
6755
6685
 
6756
6686
  const formatSessionRequest = (address, chainId, player, policyId) => {
@@ -6765,20 +6695,23 @@ const formatSessionRequest = (address, chainId, player, policyId) => {
6765
6695
  };
6766
6696
  const buildOpenfortTransactions$2 = async (params, backendApiClients, account, authentication, policyId) => {
6767
6697
  const sessionRequest = formatSessionRequest(params.permissionContext, account.chainId, authentication.player, policyId);
6768
- const transactionResponse = await backendApiClients.sessionsApi.revokeSession({
6769
- revokeSessionRequest: sessionRequest,
6770
- }, {
6771
- headers: {
6772
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6773
- // eslint-disable-next-line @typescript-eslint/naming-convention
6774
- 'x-player-token': authentication.token,
6775
- // eslint-disable-next-line @typescript-eslint/naming-convention
6776
- 'x-auth-provider': authentication.thirdPartyProvider,
6777
- // eslint-disable-next-line @typescript-eslint/naming-convention
6778
- 'x-token-type': authentication.thirdPartyTokenType,
6779
- },
6780
- });
6781
- return transactionResponse.data;
6698
+ return withOpenfortError(async () => {
6699
+ const response = await backendApiClients.sessionsApi.revokeSession({
6700
+ revokeSessionRequest: sessionRequest,
6701
+ }, {
6702
+ headers: {
6703
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6704
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6705
+ 'x-player-token': authentication.token,
6706
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6707
+ 'x-auth-provider': authentication.thirdPartyProvider,
6708
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6709
+ 'x-token-type': authentication.thirdPartyTokenType,
6710
+ },
6711
+ });
6712
+ return response.data;
6713
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6714
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
6782
6715
  };
6783
6716
  const revokeSession = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6784
6717
  const param = params[0];
@@ -6786,8 +6719,9 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6786
6719
  await signer.logout();
6787
6720
  return {};
6788
6721
  }
6789
- const openfortTransaction = await buildOpenfortTransactions$2(param, backendClient, account, authentication, policyId);
6790
- let response;
6722
+ const openfortTransaction = await buildOpenfortTransactions$2(param, backendClient, account, authentication, policyId).catch((error) => {
6723
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6724
+ });
6791
6725
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
6792
6726
  let signature;
6793
6727
  // zkSync based chains need a different signature
@@ -6800,19 +6734,12 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6800
6734
  const openfortSignatureResponse = await backendClient.sessionsApi.signatureSession({
6801
6735
  id: openfortTransaction.id,
6802
6736
  signatureRequest: { signature },
6737
+ }).catch((error) => {
6738
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6803
6739
  });
6804
- if (!openfortSignatureResponse) {
6805
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6806
- }
6807
- response = openfortSignatureResponse.data;
6740
+ return openfortSignatureResponse.data;
6808
6741
  }
6809
- else {
6810
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6811
- }
6812
- if (response.isActive === false) {
6813
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Failed to request permissions');
6814
- }
6815
- return {};
6742
+ return openfortTransaction;
6816
6743
  };
6817
6744
 
6818
6745
  const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, authentication, policyId) => {
@@ -6826,29 +6753,33 @@ const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, au
6826
6753
  value: call.value ? String(call.value) : undefined,
6827
6754
  };
6828
6755
  });
6829
- const transactionResponse = await backendApiClients.transactionIntentsApi.createTransactionIntent({
6830
- createTransactionIntentRequest: {
6831
- policy: policyId,
6832
- chainId: account.chainId,
6833
- interactions,
6834
- },
6835
- }, {
6836
- headers: {
6837
- authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6838
- // eslint-disable-next-line @typescript-eslint/naming-convention
6839
- 'x-player-token': authentication.token,
6840
- // eslint-disable-next-line @typescript-eslint/naming-convention
6841
- 'x-auth-provider': authentication.thirdPartyProvider,
6842
- // eslint-disable-next-line @typescript-eslint/naming-convention
6843
- 'x-token-type': authentication.thirdPartyTokenType,
6844
- },
6845
- });
6846
- return transactionResponse.data;
6756
+ return withOpenfortError(async () => {
6757
+ const response = await backendApiClients.transactionIntentsApi.createTransactionIntent({
6758
+ createTransactionIntentRequest: {
6759
+ policy: policyId,
6760
+ chainId: account.chainId,
6761
+ interactions,
6762
+ },
6763
+ }, {
6764
+ headers: {
6765
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6766
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6767
+ 'x-player-token': authentication.token,
6768
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6769
+ 'x-auth-provider': authentication.thirdPartyProvider,
6770
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6771
+ 'x-token-type': authentication.thirdPartyTokenType,
6772
+ },
6773
+ });
6774
+ return response.data;
6775
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6776
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
6847
6777
  };
6848
6778
  const sendCalls = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6849
6779
  const policy = params[0]?.capabilities?.paymasterService?.policy ?? policyId;
6850
- const openfortTransaction = await buildOpenfortTransactions$1(params[0].calls, backendClient, account, authentication, policy);
6851
- let response;
6780
+ const openfortTransaction = await buildOpenfortTransactions$1(params, backendClient, account, authentication, policy).catch((error) => {
6781
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6782
+ });
6852
6783
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
6853
6784
  let signature;
6854
6785
  // zkSync based chains need a different signature
@@ -6858,29 +6789,25 @@ const sendCalls = async ({ params, signer, account, authentication, backendClien
6858
6789
  else {
6859
6790
  signature = await signer.sign(openfortTransaction.nextAction.payload.signableHash);
6860
6791
  }
6861
- const openfortSignatureResponse = (await backendClient.transactionIntentsApi.signature({
6792
+ const response = await backendClient.transactionIntentsApi.signature({
6862
6793
  id: openfortTransaction.id,
6863
6794
  signatureRequest: { signature },
6864
- })).data.response;
6865
- if (!openfortSignatureResponse) {
6866
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6795
+ }).catch((error) => {
6796
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6797
+ });
6798
+ if (response.data.response?.error) {
6799
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, response.data.response.error.reason);
6867
6800
  }
6868
- response = openfortSignatureResponse;
6869
- }
6870
- else if (openfortTransaction.response) {
6871
- response = openfortTransaction.response;
6872
- }
6873
- else {
6874
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
6875
- }
6876
- if (response.status === 0 && !response.transactionHash) {
6877
- throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.error.reason);
6801
+ if (response.data.response?.status === 0) {
6802
+ throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.data.response?.error.reason);
6803
+ }
6804
+ return response.data.response?.transactionHash;
6878
6805
  }
6879
- return response.transactionHash;
6806
+ return openfortTransaction.response?.transactionHash;
6880
6807
  };
6881
6808
 
6882
- const buildOpenfortTransactions = async (transactionIntentId, backendApiClients, authentication) => {
6883
- const transactionResponse = await backendApiClients.transactionIntentsApi.getTransactionIntent({
6809
+ const buildOpenfortTransactions = async (transactionIntentId, backendApiClients, authentication) => withOpenfortError(async () => {
6810
+ const response = await backendApiClients.transactionIntentsApi.getTransactionIntent({
6884
6811
  id: transactionIntentId,
6885
6812
  }, {
6886
6813
  headers: {
@@ -6893,10 +6820,13 @@ const buildOpenfortTransactions = async (transactionIntentId, backendApiClients,
6893
6820
  'x-token-type': authentication.thirdPartyTokenType,
6894
6821
  },
6895
6822
  });
6896
- return transactionResponse.data;
6897
- };
6823
+ return response.data;
6824
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6825
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
6898
6826
  const getCallStatus = async ({ params, authentication, backendClient, }) => {
6899
- const transactionIntent = await buildOpenfortTransactions(params[0], backendClient, authentication);
6827
+ const transactionIntent = await buildOpenfortTransactions(params[0], backendClient, authentication).catch((error) => {
6828
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6829
+ });
6900
6830
  return {
6901
6831
  status: !transactionIntent.response ? 'PENDING' : 'CONFIRMED',
6902
6832
  receipts: transactionIntent.response
@@ -7000,7 +6930,7 @@ class EvmProvider {
7000
6930
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
7001
6931
  }
7002
6932
  this.#validateAndRefreshSession();
7003
- return await sendTransaction({
6933
+ return await sendCalls({
7004
6934
  params: request.params || [],
7005
6935
  signer,
7006
6936
  account,
@@ -7105,7 +7035,7 @@ class EvmProvider {
7105
7035
  }
7106
7036
  this.#validateAndRefreshSession();
7107
7037
  return await sendCalls({
7108
- params: request.params || [],
7038
+ params: request.params ? request.params[0].calls : [],
7109
7039
  signer,
7110
7040
  account,
7111
7041
  authentication,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.8.26",
3
+ "version": "0.8.27",
4
4
  "author": "Openfort (https://www.openfort.xyz)",
5
5
  "bugs": "https://github.com/openfort-xyz/openfort-js/issues",
6
6
  "repository": "openfort-xyz/openfort-js.git",