@openfort/openfort-js 0.10.34 → 0.10.36

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.
Files changed (30) hide show
  1. package/dist/cjs/packages/internal/openapi-clients/dist/index.js +1 -1
  2. package/dist/cjs/sdk/src/api/embeddedWallet.js +1 -1
  3. package/dist/cjs/sdk/src/core/configuration/account.js +1 -1
  4. package/dist/cjs/sdk/src/core/openfortInternal.js +1 -1
  5. package/dist/cjs/sdk/src/index.js +1 -1
  6. package/dist/cjs/sdk/src/types/types.js +1 -1
  7. package/dist/cjs/sdk/src/utils/authorization.js +1 -0
  8. package/dist/cjs/sdk/src/version.js +1 -1
  9. package/dist/cjs/sdk/src/wallets/embedded.js +1 -1
  10. package/dist/cjs/sdk/src/wallets/evm/evmProvider.js +1 -1
  11. package/dist/cjs/sdk/src/wallets/evm/registerSession.js +1 -1
  12. package/dist/cjs/sdk/src/wallets/evm/revokeSession.js +1 -1
  13. package/dist/cjs/sdk/src/wallets/evm/sendCallSync.js +1 -1
  14. package/dist/cjs/sdk/src/wallets/evm/sendCalls.js +1 -1
  15. package/dist/index.d.ts +183 -2
  16. package/dist/packages/internal/openapi-clients/dist/index.js +1 -1
  17. package/dist/sdk/src/api/embeddedWallet.js +1 -1
  18. package/dist/sdk/src/core/configuration/account.js +1 -1
  19. package/dist/sdk/src/core/openfortInternal.js +1 -1
  20. package/dist/sdk/src/index.js +1 -1
  21. package/dist/sdk/src/types/types.js +1 -1
  22. package/dist/sdk/src/utils/authorization.js +1 -0
  23. package/dist/sdk/src/version.js +1 -1
  24. package/dist/sdk/src/wallets/embedded.js +1 -1
  25. package/dist/sdk/src/wallets/evm/evmProvider.js +1 -1
  26. package/dist/sdk/src/wallets/evm/registerSession.js +1 -1
  27. package/dist/sdk/src/wallets/evm/revokeSession.js +1 -1
  28. package/dist/sdk/src/wallets/evm/sendCallSync.js +1 -1
  29. package/dist/sdk/src/wallets/evm/sendCalls.js +1 -1
  30. package/package.json +1 -1
@@ -1 +1 @@
1
- import{Account as t}from"../../core/configuration/account.js";import{Authentication as e}from"../../core/configuration/authentication.js";import{OpenfortEvents as a,AccountTypeEnum as s}from"../../types/types.js";import{defaultChainRpcs as i}from"../../utils/chains/index.js";import{numberToHex as r}from"../../utils/crypto.js";import o from"../../utils/typedEventEmitter.js";import{addEthereumChain as n}from"./addEthereumChain.js";import{estimateGas as c}from"./estimateGas.js";import{getAssets as h}from"./getAssets.js";import{getCallStatus as d}from"./getCallsStatus.js";import{JsonRpcError as p,ProviderErrorCode as m,RpcErrorCode as w}from"./JsonRpcError.js";import{personalSign as u}from"./personalSign.js";import{registerSession as l}from"./registerSession.js";import{revokeSession as g}from"./revokeSession.js";import{sendCallsSync as f}from"./sendCallSync.js";import{sendCalls as S}from"./sendCalls.js";import{signTypedDataV4 as A}from"./signTypedDataV4.js";import{ProviderEvent as R}from"./types.js";import{prepareEOATransaction as _,parseTransactionRequest as y}from"./walletHelpers.js";class E{#t;#e;#a;#s;updatePolicy(t){this.#e=t}#i;#r;#o=null;#n;isOpenfort=!0;#c;constructor({storage:t,backendApiClients:e,openfortEventEmitter:s,policyId:i,ensureSigner:r,chains:n,validateAndRefreshSession:c}){this.#c=r,this.#t=t,this.#a=n,this.#e=i,this.#i=c,this.#n=e,this.#r=new o,s.on(a.ON_LOGOUT,this.#h),s.on(a.ON_SWITCH_ACCOUNT,this.#d)}#p=async()=>(this.#s||(this.#s=await this.#c()),this.#s);#h=async()=>{this.#s=void 0,this.#r.emit(R.ACCOUNTS_CHANGED,[])};#d=async t=>{this.#r.emit(R.ACCOUNTS_CHANGED,[t])};async getRpcProvider(){if(!this.#o){const e=await t.fromStorage(this.#t),a=e?.chainId||8453;await import("@ethersproject/providers").then(t=>{const e=this.#a?this.#a[a]:void 0;this.#o=new t.StaticJsonRpcProvider(e??i[a])})}if(!this.#o)throw new Error("RPC provider not initialized");return this.#o}async#m(a){switch(a.method){case"eth_accounts":{const e=await t.fromStorage(this.#t);return e?[e.address]:[]}case"eth_requestAccounts":{const e=await t.fromStorage(this.#t);if(e)return this.#r.emit(R.ACCOUNTS_CONNECT,{chainId:String(e.chainId)}),[e.address];throw new p(m.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer.")}case"eth_signTransaction":{const s=await t.fromStorage(this.#t),i=await this.#p(),r=await e.fromStorage(this.#t);if(!s||!r)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const o=await this.getRpcProvider(),{chainId:n}=await o.detectNetwork(),[c]=a.params||[];c.chainId||(c.chainId=n.toString());const h=y(c),{serialize:d}=await import("@ethersproject/transactions"),w=t=>({legacy:0,eip2930:1,eip1559:2}[t]),{gas:u,...l}=h,g={...l,gasLimit:u,to:h.to??void 0,type:w(h.type)},f=d(g),{keccak256:S}=await import("@ethersproject/keccak256"),A=S(f);await this.#i();const R=await i.sign(A,!1,!1),{splitSignature:_}=await import("@ethersproject/bytes");return d(g,_(R))}case"eth_sendTransaction":{const i=await t.fromStorage(this.#t),r=await this.#p(),o=await e.fromStorage(this.#t);if(!i||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(await this.#i(),i?.accountType===s.EOA){const[t]=a.params||[],e=await this.getRpcProvider(),s=await _(t,e,i.address),r=await this.#m({method:"eth_signTransaction",params:[s]});return this.#m({method:"eth_sendRawTransaction",params:[r]})}return(await f({params:a.params||[],signer:r,account:i,authentication:o,backendClient:this.#n,policyId:this.#e})).receipt.transactionHash}case"eth_sendRawTransactionSync":{const i=await t.fromStorage(this.#t),r=await this.#p(),o=await e.fromStorage(this.#t);if(!i||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(i?.accountType===s.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);return await this.#i(),await f({params:a.params||[],signer:r,account:i,authentication:o,backendClient:this.#n,policyId:this.#e})}case"eth_estimateGas":{const s=await t.fromStorage(this.#t),i=await e.fromStorage(this.#t);if(!s||!i)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await c({params:a.params||[],account:s,authentication:i,backendClient:this.#n,policyId:this.#e})}case"eth_signTypedData":case"eth_signTypedData_v4":{const e=await t.fromStorage(this.#t),s=await this.#p();if(!e)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#i();const i=await this.getRpcProvider();return await A({method:a.method,params:a.params||[],signer:s,implementationType:e.implementationType||e.type,rpcProvider:i,account:e})}case"personal_sign":{const e=await t.fromStorage(this.#t);if(!e)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const s=await this.#p();return await this.#i(),await u({params:a.params||[],signer:s,account:e})}case"eth_chainId":{const t=await this.getRpcProvider(),{chainId:e}=await t.detectNetwork();return r(e)}case"wallet_switchEthereumChain":{const t=await this.#p();if(!a.params||!Array.isArray(a.params)||0===a.params.length)throw new p(w.INVALID_PARAMS,"Invalid parameters for wallet_switchEthereumChain");await this.#i();try{const e=parseInt(a.params[0].chainId,16);await t.switchChain({chainId:e}),await import("@ethersproject/providers").then(t=>{const a=this.#a?this.#a[e]:void 0;this.#o=new t.StaticJsonRpcProvider(a??i[e])})}catch(t){const e=t;throw new p(w.INTERNAL_ERROR,`Failed to switch chain: ${e.message}`)}return null}case"wallet_addEthereumChain":{await this.#p();const t=await this.getRpcProvider();return await n({params:a.params||[],rpcProvider:t,storage:this.#t})}case"wallet_showCallsStatus":return null;case"wallet_getCallsStatus":{const i=await t.fromStorage(this.#t);if(i?.accountType===s.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await e.fromStorage(this.#t);if(!i||!r)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await d({params:a.params||{},authentication:r,backendClient:this.#n})}case"wallet_sendCalls":{const i=await t.fromStorage(this.#t);if(i?.accountType===s.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await this.#p(),o=await e.fromStorage(this.#t);if(!i||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#i();return await S({params:a.params?a.params[0].calls:[],signer:r,account:i,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_grantPermissions":{const i=await t.fromStorage(this.#t);if(i?.accountType===s.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await this.#p(),o=await e.fromStorage(this.#t);if(!i||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await l({params:a.params||[],signer:r,account:i,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_revokePermissions":{const s=await t.fromStorage(this.#t),i=await this.#p(),r=await e.fromStorage(this.#t);if(!s||!r)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await g({params:a.params||[],signer:i,account:s,authentication:r,backendClient:this.#n,policyId:this.#e})}case"wallet_getCapabilities":{const e=await t.fromStorage(this.#t);if(e?.accountType===s.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const i=await this.getRpcProvider(),{chainId:o}=await i.detectNetwork();return{[r(o)]:{permissions:{supported:!0,signerTypes:["account","key"],keyTypes:["secp256k1"],permissionTypes:["contract-calls"]},paymasterService:{supported:!0},atomicBatch:{supported:!0}}}}case"wallet_getAssets":{const s=await t.fromStorage(this.#t),i=await e.fromStorage(this.#t);if(!s||!i)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await h({params:a.params?.[0],account:s,authentication:i,backendClient:this.#n})}case"eth_gasPrice":case"eth_getBalance":case"eth_sendRawTransaction":case"eth_getCode":case"eth_getStorageAt":case"eth_call":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":case"eth_getTransactionCount":return(await this.getRpcProvider()).send(a.method,a.params||[]);default:throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`)}}async request(t){try{return this.#m(t)}catch(t){if(t instanceof p)throw t;if(t instanceof Error)throw new p(w.INTERNAL_ERROR,t.message);throw new p(w.INTERNAL_ERROR,"Internal error")}}on(t,e){this.#r.on(t,e)}removeListener(t,e){this.#r.off(t,e)}}export{E as EvmProvider};
1
+ import{Account as t}from"../../core/configuration/account.js";import{Authentication as e}from"../../core/configuration/authentication.js";import{OpenfortEvents as a,AccountTypeEnum as i}from"../../types/types.js";import{defaultChainRpcs as s}from"../../utils/chains/index.js";import{numberToHex as r}from"../../utils/crypto.js";import o from"../../utils/typedEventEmitter.js";import{addEthereumChain as n}from"./addEthereumChain.js";import{estimateGas as c}from"./estimateGas.js";import{getAssets as h}from"./getAssets.js";import{getCallStatus as d}from"./getCallsStatus.js";import{JsonRpcError as p,ProviderErrorCode as m,RpcErrorCode as l}from"./JsonRpcError.js";import{personalSign as w}from"./personalSign.js";import{registerSession as u}from"./registerSession.js";import{revokeSession as g}from"./revokeSession.js";import{sendCallsSync as f}from"./sendCallSync.js";import{sendCalls as S}from"./sendCalls.js";import{signTypedDataV4 as A}from"./signTypedDataV4.js";import{ProviderEvent as R}from"./types.js";import{prepareEOATransaction as _,parseTransactionRequest as v}from"./walletHelpers.js";class y{#t;#e;#a;#i;updatePolicy(t){this.#e=t}#s;#r;#o=null;#n;isOpenfort=!0;#c;constructor({storage:t,backendApiClients:e,openfortEventEmitter:i,policyId:s,ensureSigner:r,chains:n,validateAndRefreshSession:c}){this.#c=r,this.#t=t,this.#a=n,this.#e=s,this.#s=c,this.#n=e,this.#r=new o,i.on(a.ON_LOGOUT,this.#h),i.on(a.ON_SWITCH_ACCOUNT,this.#d)}#p=async()=>(this.#i||(this.#i=await this.#c()),this.#i);#h=async()=>{this.#i=void 0,this.#r.emit(R.ACCOUNTS_CHANGED,[])};#d=async t=>{this.#r.emit(R.ACCOUNTS_CHANGED,[t])};async getRpcProvider(){if(!this.#o){const e=await t.fromStorage(this.#t),a=e?.chainId||8453;await import("@ethersproject/providers").then(t=>{const e=this.#a?this.#a[a]:void 0;this.#o=new t.StaticJsonRpcProvider(e??s[a])})}if(!this.#o)throw new Error("RPC provider not initialized");return this.#o}async#m(a){switch(a.method){case"eth_accounts":{const e=await t.fromStorage(this.#t);return e?[e.address]:[]}case"eth_requestAccounts":{const e=await t.fromStorage(this.#t);if(e)return this.#r.emit(R.ACCOUNTS_CONNECT,{chainId:String(e.chainId)}),[e.address];throw new p(m.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer.")}case"eth_signTransaction":{const i=await t.fromStorage(this.#t),s=await this.#p(),r=await e.fromStorage(this.#t);if(!i||!r)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const o=await this.getRpcProvider(),{chainId:n}=await o.detectNetwork(),[c]=a.params||[];c.chainId||(c.chainId=n.toString());const h=v(c),{serialize:d}=await import("@ethersproject/transactions"),l=t=>({legacy:0,eip2930:1,eip1559:2}[t]),{gas:w,...u}=h,g={...u,gasLimit:w,to:h.to??void 0,type:l(h.type)},f=d(g),{keccak256:S}=await import("@ethersproject/keccak256"),A=S(f);await this.#s();const R=await s.sign(A,!1,!1),{splitSignature:_}=await import("@ethersproject/bytes");return d(g,_(R))}case"eth_sendTransaction":{const[s,r,o]=await Promise.all([t.fromStorage(this.#t),this.#p(),e.fromStorage(this.#t)]);if(!s||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(await this.#s(),s?.accountType===i.EOA){const[t]=a.params||[],e=await this.getRpcProvider(),i=await _(t,e,s.address),r=await this.#m({method:"eth_signTransaction",params:[i]});return this.#m({method:"eth_sendRawTransaction",params:[r]})}return(await f({params:a.params||[],signer:r,account:s,authentication:o,backendClient:this.#n,rpcProvider:await this.getRpcProvider(),policyId:this.#e})).receipt.transactionHash}case"eth_sendRawTransactionSync":{const[s,r,o]=await Promise.all([t.fromStorage(this.#t),this.#p(),e.fromStorage(this.#t)]);if(!s||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(s?.accountType===i.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);return await this.#s(),await f({params:a.params||[],signer:r,account:s,authentication:o,backendClient:this.#n,rpcProvider:await this.getRpcProvider(),policyId:this.#e})}case"eth_estimateGas":{const i=await t.fromStorage(this.#t),s=await e.fromStorage(this.#t);if(!i||!s)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await c({params:a.params||[],account:i,authentication:s,backendClient:this.#n,policyId:this.#e})}case"eth_signTypedData":case"eth_signTypedData_v4":{const e=await t.fromStorage(this.#t),i=await this.#p();if(!e)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#s();const s=await this.getRpcProvider();return await A({method:a.method,params:a.params||[],signer:i,implementationType:e.implementationType||e.type,rpcProvider:s,account:e})}case"personal_sign":{const e=await t.fromStorage(this.#t);if(!e)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const i=await this.#p();return await this.#s(),await w({params:a.params||[],signer:i,account:e})}case"eth_chainId":{const t=await this.getRpcProvider(),{chainId:e}=await t.detectNetwork();return r(e)}case"wallet_switchEthereumChain":{const t=await this.#p();if(!a.params||!Array.isArray(a.params)||0===a.params.length)throw new p(l.INVALID_PARAMS,"Invalid parameters for wallet_switchEthereumChain");await this.#s();try{const e=parseInt(a.params[0].chainId,16);await t.switchChain({chainId:e}),await import("@ethersproject/providers").then(t=>{const a=this.#a?this.#a[e]:void 0;this.#o=new t.StaticJsonRpcProvider(a??s[e])})}catch(t){const e=t;throw new p(l.INTERNAL_ERROR,`Failed to switch chain: ${e.message}`)}return null}case"wallet_addEthereumChain":{await this.#p();const t=await this.getRpcProvider();return await n({params:a.params||[],rpcProvider:t,storage:this.#t})}case"wallet_showCallsStatus":return null;case"wallet_getCallsStatus":{const s=await t.fromStorage(this.#t);if(s?.accountType===i.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await e.fromStorage(this.#t);if(!s||!r)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await d({params:a.params||{},authentication:r,backendClient:this.#n})}case"wallet_sendCalls":{const[s,r,o]=await Promise.all([t.fromStorage(this.#t),this.#p(),e.fromStorage(this.#t)]);if(s?.accountType===i.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);if(!s||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#s();return await S({params:a.params?a.params[0].calls:[],signer:r,account:s,authentication:o,backendClient:this.#n,rpcProvider:await this.getRpcProvider(),policyId:this.#e})}case"wallet_grantPermissions":{const s=await t.fromStorage(this.#t);if(s?.accountType===i.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await this.#p(),o=await e.fromStorage(this.#t);if(!s||!o)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await u({params:a.params||[],signer:r,account:s,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_revokePermissions":{const i=await t.fromStorage(this.#t),s=await this.#p(),r=await e.fromStorage(this.#t);if(!i||!r)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await g({params:a.params||[],signer:s,account:i,authentication:r,backendClient:this.#n,policyId:this.#e})}case"wallet_getCapabilities":{const e=await t.fromStorage(this.#t);if(e?.accountType===i.EOA)throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const s=await this.getRpcProvider(),{chainId:o}=await s.detectNetwork();return{[r(o)]:{permissions:{supported:!0,signerTypes:["account","key"],keyTypes:["secp256k1"],permissionTypes:["contract-calls"]},paymasterService:{supported:!0},atomicBatch:{supported:!0}}}}case"wallet_getAssets":{const i=await t.fromStorage(this.#t),s=await e.fromStorage(this.#t);if(!i||!s)throw new p(m.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await h({params:a.params?.[0],account:i,authentication:s,backendClient:this.#n})}case"eth_gasPrice":case"eth_getBalance":case"eth_sendRawTransaction":case"eth_getCode":case"eth_getStorageAt":case"eth_call":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":case"eth_getTransactionCount":return(await this.getRpcProvider()).send(a.method,a.params||[]);default:throw new p(m.UNSUPPORTED_METHOD,`${a.method}: Method not supported`)}}async request(t){try{return this.#m(t)}catch(t){if(t instanceof p)throw t;if(t instanceof Error)throw new p(l.INTERNAL_ERROR,t.message);throw new p(l.INTERNAL_ERROR,"Internal error")}}on(t,e){this.#r.on(t,e)}removeListener(t,e){this.#r.off(t,e)}}export{y as EvmProvider};
@@ -1 +1 @@
1
- import{withOpenfortError as t,OpenfortErrorType as e}from"../../core/errors/openfortError.js";import{JsonRpcError as i,RpcErrorCode as n}from"./JsonRpcError.js";function a(t){return{data:(()=>{if("token-allowance"===t.type)throw new i(n.INVALID_PARAMS,"token-allowance policy is not supported with this account implementation.");if("gas-limit"===t.type)throw new i(n.INVALID_PARAMS,"gas-limit policy is not supported with this account implementation.");if("rate-limit"===t.type)throw new i(n.INVALID_PARAMS,"rate-limit policy is not supported with this account implementation.");return t.data})(),type:t.type.custom}}function s(t){if("native-token-transfer"===t.type)throw new i(n.INVALID_PARAMS,"native-token-transfer permission is not supported with this account implementation.");if("rate-limit"===t.type)throw new i(n.INVALID_PARAMS,"rate-limit permission is not supported with this account implementation.");if("gas-limit"===t.type)throw new i(n.INVALID_PARAMS,"gas-limit permission is not supported with this account implementation.");return{...t,policies:t?.policies?.map(a),required:t.required??!1,type:"string"==typeof t.type?t.type:t.type.custom}}function o(t){return{expiry:t.validUntil?Number(t.validUntil):0,grantedPermissions:t.whitelist?t.whitelist.map(e=>({type:"contract-call",data:{address:e,calls:[]},policies:[{data:{limit:t.limit},type:{custom:"usage-limit"}}]})):[],permissionsContext:t.id}}const r=async({params:a,signer:r,account:c,authentication:p,backendClient:l,policyId:d})=>{const m=await(async(a,o,r,c,p)=>{const l=a[0],d=Math.floor(Date.now()/1e3),m=Math.floor(new Date(Date.now()+1e3*l.expiry).getTime()/1e3),u=l.permissions.map(s),y=u.filter(t=>"contract-call"===t.type||"erc20-token-transfer"===t.type||"erc721-token-transfer"===t.type||"erc1155-token-transfer"===t.type).map(t=>t.data.address);let h,w=u.find(t=>"call-limit"===t.type)?.data;if(w=u[0]?.policies?.find(t=>"call-limit"===t.type)?.data?.limit,"signer"in l&&l.signer){if("keys"===l.signer.type)throw new i(n.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==l.signer.type&&"account"!==l.signer.type||(h=l.signer.data.id)}else"account"in l&&l.account&&(h=l.account);if(!h)throw new i(n.INVALID_PARAMS,"Failed to request permissions - missing session address");const A=((t,e,i,n,a,s=!1,o,r,c,p)=>{const l={address:t,chainId:e,validAfter:i,validUntil:n,optimistic:s,whitelist:o,player:r,account:p};return a&&(l.policy=a),c&&(l.limit=c),l})(h,r.chainId,d,m,p,!1,y,c.player,w,r.id);return t(async()=>(await o.sessionsApi.createSession({createSessionRequest:A},{headers:{authorization:`Bearer ${o.config.backend.accessToken}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}})).data,{default:e.AUTHENTICATION_ERROR})})(a,l,c,p,d).catch(t=>{throw new i(n.TRANSACTION_REJECTED,t.message)});if(m?.nextAction?.payload?.signableHash){let a;a=[300,531050104,324,50104,2741,11124].includes(c.chainId)?await r.sign(m.nextAction.payload.signableHash,!1,!1):await r.sign(m.nextAction.payload.signableHash);return o(await t(async()=>(await l.sessionsApi.signatureSession({id:m.id,signatureRequest:{signature:a}})).data,{default:e.AUTHENTICATION_ERROR}).catch(t=>{throw new i(n.TRANSACTION_REJECTED,t.message)}))}if(!1===m.isActive)throw new i(n.TRANSACTION_REJECTED,"Failed to grant permissions");return o(m)};export{r as registerSession};
1
+ import{withOpenfortError as t,OpenfortErrorType as e}from"../../core/errors/openfortError.js";import{AccountType as i}from"../../types/types.js";import{JsonRpcError as n,RpcErrorCode as a}from"./JsonRpcError.js";function s(t){return{data:(()=>{if("token-allowance"===t.type)throw new n(a.INVALID_PARAMS,"token-allowance policy is not supported with this account implementation.");if("gas-limit"===t.type)throw new n(a.INVALID_PARAMS,"gas-limit policy is not supported with this account implementation.");if("rate-limit"===t.type)throw new n(a.INVALID_PARAMS,"rate-limit policy is not supported with this account implementation.");return t.data})(),type:t.type.custom}}function o(t){if("native-token-transfer"===t.type)throw new n(a.INVALID_PARAMS,"native-token-transfer permission is not supported with this account implementation.");if("rate-limit"===t.type)throw new n(a.INVALID_PARAMS,"rate-limit permission is not supported with this account implementation.");if("gas-limit"===t.type)throw new n(a.INVALID_PARAMS,"gas-limit permission is not supported with this account implementation.");return{...t,policies:t?.policies?.map(s),required:t.required??!1,type:"string"==typeof t.type?t.type:t.type.custom}}function r(t){return{expiry:t.validUntil?Number(t.validUntil):0,grantedPermissions:t.whitelist?t.whitelist.map(e=>({type:"contract-call",data:{address:e,calls:[]},policies:[{data:{limit:t.limit},type:{custom:"usage-limit"}}]})):[],permissionsContext:t.id}}const p=async({params:s,signer:p,account:c,authentication:l,backendClient:d,policyId:m})=>{const y=await(async(i,s,r,p,c)=>{const l=i[0],d=Math.floor(Date.now()/1e3),m=Math.floor(new Date(Date.now()+1e3*l.expiry).getTime()/1e3),y=l.permissions.map(o),u=y.filter(t=>"contract-call"===t.type||"erc20-token-transfer"===t.type||"erc721-token-transfer"===t.type||"erc1155-token-transfer"===t.type).map(t=>t.data.address);let h,w=y.find(t=>"call-limit"===t.type)?.data;if(w=y[0]?.policies?.find(t=>"call-limit"===t.type)?.data?.limit,"signer"in l&&l.signer){if("keys"===l.signer.type)throw new n(a.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==l.signer.type&&"account"!==l.signer.type||(h=l.signer.data.id)}else"account"in l&&l.account&&(h=l.account);if(!h)throw new n(a.INVALID_PARAMS,"Failed to request permissions - missing session address");const A=((t,e,i,n,a,s=!1,o,r,p,c)=>{const l={address:t,chainId:e,validAfter:i,validUntil:n,optimistic:s,whitelist:o,player:r,account:c};return a&&(l.policy=a),p&&(l.limit=p),l})(h,r.chainId,d,m,c,!1,u,p.player,w,r.id);return t(async()=>(await s.sessionsApi.createSession({createSessionRequest:A},{headers:{authorization:`Bearer ${s.config.backend.accessToken}`,"x-player-token":p.token,"x-auth-provider":p.thirdPartyProvider,"x-token-type":p.thirdPartyTokenType}})).data,{default:e.AUTHENTICATION_ERROR})})(s,d,c,l,m).catch(t=>{throw new n(a.TRANSACTION_REJECTED,t.message)});if(y?.nextAction?.payload?.signableHash){let s;s=[300,531050104,324,50104,2741,11124].includes(c.chainId)||c.implementationType&&[i.CALIBUR].includes(c.implementationType)?await p.sign(y.nextAction.payload.signableHash,!1,!1):await p.sign(y.nextAction.payload.signableHash);return r(await t(async()=>(await d.sessionsApi.signatureSession({id:y.id,signatureRequest:{signature:s}})).data,{default:e.AUTHENTICATION_ERROR}).catch(t=>{throw new n(a.TRANSACTION_REJECTED,t.message)}))}if(!1===y.isActive)throw new n(a.TRANSACTION_REJECTED,"Failed to grant permissions");return r(y)};export{p as registerSession};
@@ -1 +1 @@
1
- import{withOpenfortError as e,OpenfortErrorType as a}from"../../core/errors/openfortError.js";import{JsonRpcError as n,RpcErrorCode as t}from"./JsonRpcError.js";const s=async({params:s,signer:i,account:r,authentication:o,backendClient:c,policyId:d})=>{const p=s[0];if(!p.permissionContext)return await i.disconnect(),{};const u=await(async(n,t,s,i,r)=>{const o=((e,a,n,t,s)=>{const i={address:e,chainId:a,player:n,account:s};return t&&(i.policy=t),i})(n.permissionContext,s.chainId,i.player,r,s.id);return e(async()=>(await t.sessionsApi.revokeSession({revokeSessionRequest:o},{headers:{authorization:`Bearer ${t.config.backend.accessToken}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}})).data,{default:a.AUTHENTICATION_ERROR})})(p,c,r,o,d).catch(e=>{throw new n(t.TRANSACTION_REJECTED,e.message)});if(u?.nextAction?.payload?.signableHash){let e;e=[300,531050104,324,50104,2741,11124].includes(r.chainId)?await i.sign(u.nextAction.payload.signableHash,!1,!1):await i.sign(u.nextAction.payload.signableHash);return(await c.sessionsApi.signatureSession({id:u.id,signatureRequest:{signature:e}}).catch(e=>{throw new n(t.TRANSACTION_REJECTED,e.message)})).data}return u};export{s as revokeSession};
1
+ import{withOpenfortError as e,OpenfortErrorType as t}from"../../core/errors/openfortError.js";import{AccountType as n}from"../../types/types.js";import{JsonRpcError as a,RpcErrorCode as s}from"./JsonRpcError.js";const i=async({params:i,signer:o,account:r,authentication:c,backendClient:p,policyId:d})=>{const y=i[0];if(!y.permissionContext)return await o.disconnect(),{};const l=await(async(n,a,s,i,o)=>{const r=((e,t,n,a,s)=>{const i={address:e,chainId:t,player:n,account:s};return a&&(i.policy=a),i})(n.permissionContext,s.chainId,i.player,o,s.id);return e(async()=>(await a.sessionsApi.revokeSession({revokeSessionRequest:r},{headers:{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}})).data,{default:t.AUTHENTICATION_ERROR})})(y,p,r,c,d).catch(e=>{throw new a(s.TRANSACTION_REJECTED,e.message)});if(l?.nextAction?.payload?.signableHash){let e;e=[300,531050104,324,50104,2741,11124].includes(r.chainId)||r.implementationType&&[n.CALIBUR].includes(r.implementationType)?await o.sign(l.nextAction.payload.signableHash,!1,!1):await o.sign(l.nextAction.payload.signableHash);return(await p.sessionsApi.signatureSession({id:l.id,signatureRequest:{signature:e}}).catch(e=>{throw new a(s.TRANSACTION_REJECTED,e.message)})).data}return l};export{i as revokeSession};
@@ -1 +1 @@
1
- import{withOpenfortError as e,OpenfortErrorType as t}from"../../core/errors/openfortError.js";import{JsonRpcError as a,RpcErrorCode as s}from"./JsonRpcError.js";const r=e=>{const t=e?.logs?.[0];return{blockHash:t?.blockHash,blockNumber:e?.blockNumber?.toString(),contractAddress:void 0,cumulativeGasUsed:e?.gasUsed,effectiveGasPrice:e?.gasFee,from:void 0,gasUsed:e?.gasUsed,logs:e?.logs||[],logsBloom:void 0,status:1===e?.status?"success":0===e?.status?"reverted":void 0,to:e?.to,transactionHash:e?.transactionHash,transactionIndex:t?.transactionIndex,type:"eip1559",blobGasPrice:void 0,blobGasUsed:void 0,root:void 0}},n=async({params:n,signer:o,account:i,authentication:c,backendClient:d,policyId:l})=>{const p=n[0]?.capabilities?.paymasterService?.policy??l,u=await(async(r,n,o,i,c)=>{const d=r.map(e=>{if(!e.to)throw new a(s.INVALID_PARAMS,'wallet_sendCalls requires a "to" field');return{to:String(e.to),data:e.data?String(e.data):void 0,value:e.value?String(e.value):void 0}});return e(async()=>(await n.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{account:o.id,policy:c,chainId:o.chainId,interactions:d}},{headers:{authorization:`Bearer ${n.config.backend.accessToken}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}})).data,{default:t.AUTHENTICATION_ERROR})})(n,d,i,c,p).catch(e=>{throw new a(s.TRANSACTION_REJECTED,e.message)});if(u.response?.error.reason)throw new a(s.TRANSACTION_REJECTED,u.response?.error.reason);if(u?.nextAction?.payload?.signableHash){let n;n=[300,531050104,324,50104,2741,11124].includes(i.chainId)?await o.sign(u.nextAction.payload.signableHash,!1,!1):await o.sign(u.nextAction.payload.signableHash);const c=await e(async()=>await d.transactionIntentsApi.signature({id:u.id,signatureRequest:{signature:n}}),{default:t.AUTHENTICATION_ERROR}).catch(e=>{throw new a(s.TRANSACTION_REJECTED,e.message)});if(0===c.data.response?.status)throw new a(s.TRANSACTION_REJECTED,c.data.response?.error.reason);if(!c.data.response)throw new a(s.TRANSACTION_REJECTED,"No transaction response received");return{id:u.id,receipt:r(c.data.response)}}if(!u.response)throw new a(s.TRANSACTION_REJECTED,"No transaction response received");return{id:u.id,receipt:r(u.response)}};export{n as sendCallsSync};
1
+ import{withOpenfortError as e,OpenfortErrorType as t}from"../../core/errors/openfortError.js";import{AccountTypeEnum as a,AccountType as n}from"../../types/types.js";import{prepareAndSignAuthorization as s,serializeSignedAuthorization as o}from"../../utils/authorization.js";import{JsonRpcError as r,RpcErrorCode as i}from"./JsonRpcError.js";const c=e=>{const t=e?.logs?.[0];return{blockHash:t?.blockHash,blockNumber:e?.blockNumber?.toString(),contractAddress:void 0,cumulativeGasUsed:e?.gasUsed,effectiveGasPrice:e?.gasFee,from:void 0,gasUsed:e?.gasUsed,logs:e?.logs||[],logsBloom:void 0,status:1===e?.status?"success":0===e?.status?"reverted":void 0,to:e?.to,transactionHash:e?.transactionHash,transactionIndex:t?.transactionIndex,type:"eip1559",blobGasPrice:void 0,blobGasUsed:void 0,root:void 0}};async function d(e,t){try{const a=await e.getCode(t);return"0x"!==a&&a.length>2}catch{return!1}}const p=async({params:p,signer:l,account:u,authentication:T,backendClient:A,rpcProvider:h,policyId:g})=>{const E=p[0]?.capabilities?.paymasterService?.policy??g;let m;if(u.accountType===a.DELEGATED_ACCOUNT){const[e,t]=await Promise.all([d(h,u.address),h.getTransactionCount(u.address)]);if(!e){const e=await s({signer:l,accountAddress:u.address,contractAddress:u.implementationAddress,chainId:u.chainId,nonce:t});m=o(e)}}const I=await(async(a,n,s,o,c,d)=>{const p=a.map(e=>{if(!e.to)throw new r(i.INVALID_PARAMS,'wallet_sendCalls requires a "to" field');return{to:String(e.to),data:e.data?String(e.data):void 0,value:e.value?String(e.value):void 0}});return e(async()=>(await n.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{account:s.id,policy:c,signedAuthorization:d,chainId:s.chainId,interactions:p}},{headers:{authorization:`Bearer ${n.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}})).data,{default:t.AUTHENTICATION_ERROR})})(p,A,u,T,E,m).catch(e=>{throw new r(i.TRANSACTION_REJECTED,e.message)});if(I.response?.error.reason)throw new r(i.TRANSACTION_REJECTED,I.response?.error.reason);if(I?.nextAction?.payload?.signableHash){let a;a=[300,531050104,324,50104,2741,11124].includes(u.chainId)||u.implementationType&&[n.CALIBUR].includes(u.implementationType)?await l.sign(I.nextAction.payload.signableHash,!1,!1):await l.sign(I.nextAction.payload.signableHash);const s=await e(async()=>await A.transactionIntentsApi.signature({id:I.id,signatureRequest:{signature:a}}),{default:t.AUTHENTICATION_ERROR}).catch(e=>{throw new r(i.TRANSACTION_REJECTED,e.message)});if(0===s.data.response?.status)throw new r(i.TRANSACTION_REJECTED,s.data.response?.error.reason);if(!s.data.response)throw new r(i.TRANSACTION_REJECTED,"No transaction response received");return{id:I.id,receipt:c(s.data.response)}}if(!I.response)throw new r(i.TRANSACTION_REJECTED,"No transaction response received");return{id:I.id,receipt:c(I.response)}};export{p as sendCallsSync};
@@ -1 +1 @@
1
- import{sendCallsSync as a}from"./sendCallSync.js";const n=async({params:n,signer:t,account:c,authentication:i,backendClient:e,policyId:o})=>(await a({params:n,signer:t,account:c,authentication:i,backendClient:e,policyId:o})).id;export{n as sendCalls};
1
+ import{sendCallsSync as a}from"./sendCallSync.js";const n=async({params:n,signer:c,account:i,authentication:t,backendClient:r,rpcProvider:e,policyId:o})=>(await a({params:n,signer:c,account:i,authentication:t,backendClient:r,rpcProvider:e,policyId:o})).id;export{n as sendCalls};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.10.34",
3
+ "version": "0.10.36",
4
4
  "author": "Openfort (https://www.openfort.io)",
5
5
  "bugs": "https://github.com/openfort-xyz/openfort-js/issues",
6
6
  "repository": "openfort-xyz/openfort-js.git",