@openfort/openfort-js 0.8.27 → 0.8.28

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
@@ -3492,7 +3492,7 @@ class KeyPair extends signingKey.SigningKey {
3492
3492
  }
3493
3493
  }
3494
3494
 
3495
- const VERSION = '0.8.27';
3495
+ const VERSION = '0.8.28';
3496
3496
 
3497
3497
  var Event;
3498
3498
  (function (Event) {
@@ -6626,7 +6626,7 @@ const formatSessionRequest$1 = (address, chainId, validAfter, validUntil, policy
6626
6626
  request.limit = limit;
6627
6627
  return request;
6628
6628
  };
6629
- const buildOpenfortTransactions$3 = async (params, backendApiClients, account, authentication, policyId) => {
6629
+ const buildOpenfortTransactions$4 = async (params, backendApiClients, account, authentication, policyId) => {
6630
6630
  const param = params[0];
6631
6631
  const now = Math.floor(new Date().getTime() / 1000);
6632
6632
  const expiry = Math.floor(new Date(Date.now() + param.expiry * 1000).getTime() / 1000);
@@ -6680,7 +6680,7 @@ function formatRequest(result) {
6680
6680
  };
6681
6681
  }
6682
6682
  const registerSession = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6683
- const openfortTransaction = await buildOpenfortTransactions$3(params, backendClient, account, authentication, policyId).catch((error) => {
6683
+ const openfortTransaction = await buildOpenfortTransactions$4(params, backendClient, account, authentication, policyId).catch((error) => {
6684
6684
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6685
6685
  });
6686
6686
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
@@ -6716,7 +6716,7 @@ const formatSessionRequest = (address, chainId, player, policyId) => {
6716
6716
  request.policy = policyId;
6717
6717
  return request;
6718
6718
  };
6719
- const buildOpenfortTransactions$2 = async (params, backendApiClients, account, authentication, policyId) => {
6719
+ const buildOpenfortTransactions$3 = async (params, backendApiClients, account, authentication, policyId) => {
6720
6720
  const sessionRequest = formatSessionRequest(params.permissionContext, account.chainId, authentication.player, policyId);
6721
6721
  return withOpenfortError(async () => {
6722
6722
  const response = await backendApiClients.sessionsApi.revokeSession({
@@ -6742,7 +6742,7 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6742
6742
  await signer.logout();
6743
6743
  return {};
6744
6744
  }
6745
- const openfortTransaction = await buildOpenfortTransactions$2(param, backendClient, account, authentication, policyId).catch((error) => {
6745
+ const openfortTransaction = await buildOpenfortTransactions$3(param, backendClient, account, authentication, policyId).catch((error) => {
6746
6746
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6747
6747
  });
6748
6748
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
@@ -6765,7 +6765,7 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6765
6765
  return openfortTransaction;
6766
6766
  };
6767
6767
 
6768
- const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, authentication, policyId) => {
6768
+ const buildOpenfortTransactions$2 = async (calls, backendApiClients, account, authentication, policyId) => {
6769
6769
  const interactions = calls.map((call) => {
6770
6770
  if (!call.to) {
6771
6771
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'wallet_sendCalls requires a "to" field');
@@ -6800,7 +6800,7 @@ const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, au
6800
6800
  };
6801
6801
  const sendCalls = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6802
6802
  const policy = params[0]?.capabilities?.paymasterService?.policy ?? policyId;
6803
- const openfortTransaction = await buildOpenfortTransactions$1(params, backendClient, account, authentication, policy).catch((error) => {
6803
+ const openfortTransaction = await buildOpenfortTransactions$2(params, backendClient, account, authentication, policy).catch((error) => {
6804
6804
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6805
6805
  });
6806
6806
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
@@ -6829,7 +6829,7 @@ const sendCalls = async ({ params, signer, account, authentication, backendClien
6829
6829
  return openfortTransaction.response?.transactionHash;
6830
6830
  };
6831
6831
 
6832
- const buildOpenfortTransactions = async (transactionIntentId, backendApiClients, authentication) => withOpenfortError(async () => {
6832
+ const buildOpenfortTransactions$1 = async (transactionIntentId, backendApiClients, authentication) => withOpenfortError(async () => {
6833
6833
  const response = await backendApiClients.transactionIntentsApi.getTransactionIntent({
6834
6834
  id: transactionIntentId,
6835
6835
  }, {
@@ -6847,7 +6847,7 @@ const buildOpenfortTransactions = async (transactionIntentId, backendApiClients,
6847
6847
  // eslint-disable-next-line @typescript-eslint/naming-convention
6848
6848
  }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
6849
6849
  const getCallStatus = async ({ params, authentication, backendClient, }) => {
6850
- const transactionIntent = await buildOpenfortTransactions(params[0], backendClient, authentication).catch((error) => {
6850
+ const transactionIntent = await buildOpenfortTransactions$1(params[0], backendClient, authentication).catch((error) => {
6851
6851
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6852
6852
  });
6853
6853
  return {
@@ -6882,6 +6882,46 @@ const personalSign = async ({ params, signer, account, }) => {
6882
6882
  return signature;
6883
6883
  };
6884
6884
 
6885
+ const buildOpenfortTransactions = async (calls, backendApiClients, account, authentication, policyId) => {
6886
+ const interactions = calls.map((call) => {
6887
+ if (!call.to) {
6888
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_estimateGas requires a "to" field');
6889
+ }
6890
+ return {
6891
+ to: String(call.to),
6892
+ data: call.data ? String(call.data) : undefined,
6893
+ value: call.value ? String(call.value) : undefined,
6894
+ };
6895
+ });
6896
+ return withOpenfortError(async () => {
6897
+ const response = await backendApiClients.transactionIntentsApi.estimateTransactionIntentCost({
6898
+ createTransactionIntentRequest: {
6899
+ policy: policyId,
6900
+ chainId: account.chainId,
6901
+ interactions,
6902
+ },
6903
+ }, {
6904
+ headers: {
6905
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6906
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6907
+ 'x-player-token': authentication.token,
6908
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6909
+ 'x-auth-provider': authentication.thirdPartyProvider,
6910
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6911
+ 'x-token-type': authentication.thirdPartyTokenType,
6912
+ },
6913
+ });
6914
+ return response.data;
6915
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6916
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
6917
+ };
6918
+ const estimateGas = async ({ params, account, authentication, backendClient, policyId, }) => {
6919
+ const openfortTransaction = await buildOpenfortTransactions(params, backendClient, account, authentication, policyId).catch((error) => {
6920
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6921
+ });
6922
+ return openfortTransaction.estimatedTXGas;
6923
+ };
6924
+
6885
6925
  class EvmProvider {
6886
6926
  #storage;
6887
6927
  #policyId;
@@ -6962,6 +7002,21 @@ class EvmProvider {
6962
7002
  policyId: this.#policyId,
6963
7003
  });
6964
7004
  }
7005
+ case 'eth_estimateGas': {
7006
+ const account = Account.fromStorage(this.#storage);
7007
+ const authentication = Authentication.fromStorage(this.#storage);
7008
+ if (!account || !authentication) {
7009
+ throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
7010
+ }
7011
+ this.#validateAndRefreshSession();
7012
+ return await estimateGas({
7013
+ params: request.params || [],
7014
+ account,
7015
+ authentication,
7016
+ backendClient: this.#backendApiClients,
7017
+ policyId: this.#policyId,
7018
+ });
7019
+ }
6965
7020
  case 'eth_signTypedData':
6966
7021
  case 'eth_signTypedData_v4': {
6967
7022
  const account = Account.fromStorage(this.#storage);
@@ -7125,7 +7180,6 @@ class EvmProvider {
7125
7180
  case 'eth_getBalance':
7126
7181
  case 'eth_getCode':
7127
7182
  case 'eth_getStorageAt':
7128
- case 'eth_estimateGas':
7129
7183
  case 'eth_call':
7130
7184
  case 'eth_blockNumber':
7131
7185
  case 'eth_getBlockByHash':
package/dist/index.js CHANGED
@@ -3469,7 +3469,7 @@ class KeyPair extends SigningKey {
3469
3469
  }
3470
3470
  }
3471
3471
 
3472
- const VERSION = '0.8.27';
3472
+ const VERSION = '0.8.28';
3473
3473
 
3474
3474
  var Event;
3475
3475
  (function (Event) {
@@ -6603,7 +6603,7 @@ const formatSessionRequest$1 = (address, chainId, validAfter, validUntil, policy
6603
6603
  request.limit = limit;
6604
6604
  return request;
6605
6605
  };
6606
- const buildOpenfortTransactions$3 = async (params, backendApiClients, account, authentication, policyId) => {
6606
+ const buildOpenfortTransactions$4 = async (params, backendApiClients, account, authentication, policyId) => {
6607
6607
  const param = params[0];
6608
6608
  const now = Math.floor(new Date().getTime() / 1000);
6609
6609
  const expiry = Math.floor(new Date(Date.now() + param.expiry * 1000).getTime() / 1000);
@@ -6657,7 +6657,7 @@ function formatRequest(result) {
6657
6657
  };
6658
6658
  }
6659
6659
  const registerSession = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6660
- const openfortTransaction = await buildOpenfortTransactions$3(params, backendClient, account, authentication, policyId).catch((error) => {
6660
+ const openfortTransaction = await buildOpenfortTransactions$4(params, backendClient, account, authentication, policyId).catch((error) => {
6661
6661
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6662
6662
  });
6663
6663
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
@@ -6693,7 +6693,7 @@ const formatSessionRequest = (address, chainId, player, policyId) => {
6693
6693
  request.policy = policyId;
6694
6694
  return request;
6695
6695
  };
6696
- const buildOpenfortTransactions$2 = async (params, backendApiClients, account, authentication, policyId) => {
6696
+ const buildOpenfortTransactions$3 = async (params, backendApiClients, account, authentication, policyId) => {
6697
6697
  const sessionRequest = formatSessionRequest(params.permissionContext, account.chainId, authentication.player, policyId);
6698
6698
  return withOpenfortError(async () => {
6699
6699
  const response = await backendApiClients.sessionsApi.revokeSession({
@@ -6719,7 +6719,7 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6719
6719
  await signer.logout();
6720
6720
  return {};
6721
6721
  }
6722
- const openfortTransaction = await buildOpenfortTransactions$2(param, backendClient, account, authentication, policyId).catch((error) => {
6722
+ const openfortTransaction = await buildOpenfortTransactions$3(param, backendClient, account, authentication, policyId).catch((error) => {
6723
6723
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6724
6724
  });
6725
6725
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
@@ -6742,7 +6742,7 @@ const revokeSession = async ({ params, signer, account, authentication, backendC
6742
6742
  return openfortTransaction;
6743
6743
  };
6744
6744
 
6745
- const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, authentication, policyId) => {
6745
+ const buildOpenfortTransactions$2 = async (calls, backendApiClients, account, authentication, policyId) => {
6746
6746
  const interactions = calls.map((call) => {
6747
6747
  if (!call.to) {
6748
6748
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'wallet_sendCalls requires a "to" field');
@@ -6777,7 +6777,7 @@ const buildOpenfortTransactions$1 = async (calls, backendApiClients, account, au
6777
6777
  };
6778
6778
  const sendCalls = async ({ params, signer, account, authentication, backendClient, policyId, }) => {
6779
6779
  const policy = params[0]?.capabilities?.paymasterService?.policy ?? policyId;
6780
- const openfortTransaction = await buildOpenfortTransactions$1(params, backendClient, account, authentication, policy).catch((error) => {
6780
+ const openfortTransaction = await buildOpenfortTransactions$2(params, backendClient, account, authentication, policy).catch((error) => {
6781
6781
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6782
6782
  });
6783
6783
  if (openfortTransaction?.nextAction?.payload?.signableHash) {
@@ -6806,7 +6806,7 @@ const sendCalls = async ({ params, signer, account, authentication, backendClien
6806
6806
  return openfortTransaction.response?.transactionHash;
6807
6807
  };
6808
6808
 
6809
- const buildOpenfortTransactions = async (transactionIntentId, backendApiClients, authentication) => withOpenfortError(async () => {
6809
+ const buildOpenfortTransactions$1 = async (transactionIntentId, backendApiClients, authentication) => withOpenfortError(async () => {
6810
6810
  const response = await backendApiClients.transactionIntentsApi.getTransactionIntent({
6811
6811
  id: transactionIntentId,
6812
6812
  }, {
@@ -6824,7 +6824,7 @@ const buildOpenfortTransactions = async (transactionIntentId, backendApiClients,
6824
6824
  // eslint-disable-next-line @typescript-eslint/naming-convention
6825
6825
  }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
6826
6826
  const getCallStatus = async ({ params, authentication, backendClient, }) => {
6827
- const transactionIntent = await buildOpenfortTransactions(params[0], backendClient, authentication).catch((error) => {
6827
+ const transactionIntent = await buildOpenfortTransactions$1(params[0], backendClient, authentication).catch((error) => {
6828
6828
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6829
6829
  });
6830
6830
  return {
@@ -6859,6 +6859,46 @@ const personalSign = async ({ params, signer, account, }) => {
6859
6859
  return signature;
6860
6860
  };
6861
6861
 
6862
+ const buildOpenfortTransactions = async (calls, backendApiClients, account, authentication, policyId) => {
6863
+ const interactions = calls.map((call) => {
6864
+ if (!call.to) {
6865
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_estimateGas requires a "to" field');
6866
+ }
6867
+ return {
6868
+ to: String(call.to),
6869
+ data: call.data ? String(call.data) : undefined,
6870
+ value: call.value ? String(call.value) : undefined,
6871
+ };
6872
+ });
6873
+ return withOpenfortError(async () => {
6874
+ const response = await backendApiClients.transactionIntentsApi.estimateTransactionIntentCost({
6875
+ createTransactionIntentRequest: {
6876
+ policy: policyId,
6877
+ chainId: account.chainId,
6878
+ interactions,
6879
+ },
6880
+ }, {
6881
+ headers: {
6882
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
6883
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6884
+ 'x-player-token': authentication.token,
6885
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6886
+ 'x-auth-provider': authentication.thirdPartyProvider,
6887
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6888
+ 'x-token-type': authentication.thirdPartyTokenType,
6889
+ },
6890
+ });
6891
+ return response.data;
6892
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6893
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
6894
+ };
6895
+ const estimateGas = async ({ params, account, authentication, backendClient, policyId, }) => {
6896
+ const openfortTransaction = await buildOpenfortTransactions(params, backendClient, account, authentication, policyId).catch((error) => {
6897
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, error.message);
6898
+ });
6899
+ return openfortTransaction.estimatedTXGas;
6900
+ };
6901
+
6862
6902
  class EvmProvider {
6863
6903
  #storage;
6864
6904
  #policyId;
@@ -6939,6 +6979,21 @@ class EvmProvider {
6939
6979
  policyId: this.#policyId,
6940
6980
  });
6941
6981
  }
6982
+ case 'eth_estimateGas': {
6983
+ const account = Account.fromStorage(this.#storage);
6984
+ const authentication = Authentication.fromStorage(this.#storage);
6985
+ if (!account || !authentication) {
6986
+ throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
6987
+ }
6988
+ this.#validateAndRefreshSession();
6989
+ return await estimateGas({
6990
+ params: request.params || [],
6991
+ account,
6992
+ authentication,
6993
+ backendClient: this.#backendApiClients,
6994
+ policyId: this.#policyId,
6995
+ });
6996
+ }
6942
6997
  case 'eth_signTypedData':
6943
6998
  case 'eth_signTypedData_v4': {
6944
6999
  const account = Account.fromStorage(this.#storage);
@@ -7102,7 +7157,6 @@ class EvmProvider {
7102
7157
  case 'eth_getBalance':
7103
7158
  case 'eth_getCode':
7104
7159
  case 'eth_getStorageAt':
7105
- case 'eth_estimateGas':
7106
7160
  case 'eth_call':
7107
7161
  case 'eth_blockNumber':
7108
7162
  case 'eth_getBlockByHash':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.8.27",
3
+ "version": "0.8.28",
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",