@openfort/openfort-js 1.3.4 → 1.3.5

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.
@@ -1 +1 @@
1
- "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.3.4";
1
+ "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.3.5";
@@ -0,0 +1 @@
1
+ "use strict";const t="0xef0100";exports.isDelegatedTo=function(e,n){return!!n&&function(e){if(!e)return null;const n=e.toLowerCase();return 48!==n.length?null:n.startsWith(t)?`0x${n.slice(8)}`:null}(e)===n.toLowerCase()};
@@ -1 +1 @@
1
- "use strict";var t=require("../../core/errors/withApiError.cjs"),e=require("../../types/types.cjs"),i=require("./JsonRpcError.cjs");function r(t){return{data:(()=>{if("token-allowance"===t.type)throw new i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"token-allowance policy is not supported with this account implementation.");if("gas-limit"===t.type)throw new i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"gas-limit policy is not supported with this account implementation.");if("rate-limit"===t.type)throw new i.JsonRpcError(i.RpcErrorCode.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 i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"native-token-transfer permission is not supported with this account implementation.");if("rate-limit"===t.type)throw new i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"rate-limit permission is not supported with this account implementation.");if("gas-limit"===t.type)throw new i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"gas-limit permission is not supported with this account implementation.");return{...t,policies:t?.policies?.map(r),required:t.required??!1,type:"string"==typeof t.type?t.type:t.type.custom}}function n(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}}exports.registerSession=async({params:r,signer:s,account:a,authentication:c,backendClient:p,feeSponsorshipId:l})=>{const d=await(async(e,r,n,s,a)=>{const c=e[0],p=Math.floor(Date.now()/1e3),l=Math.floor(new Date(Date.now()+1e3*c.expiry).getTime()/1e3),d=c.permissions.map(o),u=d.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 m,y=d.find(t=>"call-limit"===t.type)?.data;if(y=d[0]?.policies?.find(t=>"call-limit"===t.type)?.data?.limit,"signer"in c&&c.signer){if("keys"===c.signer.type)throw new i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==c.signer.type&&"account"!==c.signer.type||(m=c.signer.data.id)}else"account"in c&&c.account&&(m=c.account);if(!m)throw new i.JsonRpcError(i.RpcErrorCode.INVALID_PARAMS,"Failed to request permissions - missing session address");const h=((t,e,i,r,o,n=!1,s,a,c)=>{const p={address:t,chainId:e,validAfter:i,validUntil:r,optimistic:n,whitelist:s,account:c};return o&&(p.policy=o),a&&(p.limit=a),p})(m,n.chainId,p,l,a,!1,u,y,n.id);return t.withApiError(async()=>(await r.sessionsApi.createSession({createSessionRequest:h},{headers:s.thirdPartyProvider?{authorization:`Bearer ${r.config.backend.accessToken}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}:{authorization:`Bearer ${s.token}`,"x-project-key":String(r.config.backend.accessToken)}})).data,{context:"operation"})})(r,p,a,c,l).catch(t=>{throw new i.JsonRpcError(i.RpcErrorCode.TRANSACTION_REJECTED,t.message)});if(d?.nextAction?.payload?.signableHash){let r;r=[300,324].includes(a.chainId)||a.implementationType&&[e.AccountType.CALIBUR].includes(a.implementationType)?await s.sign(d.nextAction.payload.signableHash,!1,!1):await s.sign(d.nextAction.payload.signableHash);return n(await t.withApiError(async()=>(await p.sessionsApi.signatureSession({id:d.id,signatureRequest:{signature:r}})).data,{context:"operation"}).catch(t=>{throw new i.JsonRpcError(i.RpcErrorCode.TRANSACTION_REJECTED,t.message)}))}if(!1===d.isActive)throw new i.JsonRpcError(i.RpcErrorCode.TRANSACTION_REJECTED,"Failed to grant permissions");return n(d)};
1
+ "use strict";var t=require("../../core/errors/withApiError.cjs"),e=require("../../types/types.cjs"),r=require("./JsonRpcError.cjs");function i(t){return{data:(()=>{if("token-allowance"===t.type)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"token-allowance policy is not supported with this account implementation.");if("gas-limit"===t.type)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"gas-limit policy is not supported with this account implementation.");if("rate-limit"===t.type)throw new r.JsonRpcError(r.RpcErrorCode.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 r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"native-token-transfer permission is not supported with this account implementation.");if("rate-limit"===t.type)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"rate-limit permission is not supported with this account implementation.");if("gas-limit"===t.type)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"gas-limit permission is not supported with this account implementation.");return{...t,policies:t?.policies?.map(i),required:t.required??!1,type:"string"==typeof t.type?t.type:t.type.custom}}function n(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}}exports.registerSession=async({params:i,signer:s,account:a,authentication:c,backendClient:p,feeSponsorshipId:l})=>{const d=await(async(e,i,n,s,a)=>{const c=e[0],p=Math.floor(Date.now()/1e3),l=Math.floor(new Date(Date.now()+1e3*c.expiry).getTime()/1e3),d=c.permissions.map(o),u=d.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 y,m=d.find(t=>"call-limit"===t.type)?.data;if(m=d[0]?.policies?.find(t=>"call-limit"===t.type)?.data?.limit,"signer"in c&&c.signer){if("keys"===c.signer.type)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==c.signer.type&&"account"!==c.signer.type||(y=c.signer.data.id)}else"account"in c&&c.account&&(y=c.account);if(!y)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"Failed to request permissions - missing session address");const h=((t,e,r,i,o,n=!1,s,a,c)=>{const p={address:t,chainId:e,validAfter:r,validUntil:i,optimistic:n,whitelist:s,account:c};return o&&(p.policy=o),a&&(p.limit=a),p})(y,n.chainId,p,l,a,!1,u,m,n.id);return t.withApiError(async()=>(await i.sessionsApi.createSession({createSessionRequest:h},{headers:s.thirdPartyProvider?{authorization:`Bearer ${i.config.backend.accessToken}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}:{authorization:`Bearer ${s.token}`,"x-project-key":String(i.config.backend.accessToken)}})).data,{context:"operation"})})(i,p,a,c,l).catch(t=>{throw new r.JsonRpcError(r.RpcErrorCode.TRANSACTION_REJECTED,t.message)});if(d?.nextAction?.payload?.signableHash){let i;i=[300,324].includes(a.chainId)||a.accountType===e.AccountTypeEnum.DELEGATED_ACCOUNT?await s.sign(d.nextAction.payload.signableHash,!1,!1):await s.sign(d.nextAction.payload.signableHash);return n(await t.withApiError(async()=>(await p.sessionsApi.signatureSession({id:d.id,signatureRequest:{signature:i}})).data,{context:"operation"}).catch(t=>{throw new r.JsonRpcError(r.RpcErrorCode.TRANSACTION_REJECTED,t.message)}))}if(!1===d.isActive)throw new r.JsonRpcError(r.RpcErrorCode.TRANSACTION_REJECTED,"Failed to grant permissions");return n(d)};
@@ -1 +1 @@
1
- "use strict";var e=require("../../core/errors/withApiError.cjs"),r=require("../../types/types.cjs"),n=require("./JsonRpcError.cjs");exports.revokeSession=async({params:t,signer:i,account:o,authentication:s,backendClient:a,feeSponsorshipId:c})=>{const p=t[0];if(!p.permissionContext)return await i.disconnect(),{};const d=await(async(r,n,t,i,o)=>{const s=((e,r,n,t)=>{const i={address:e,chainId:r,account:t};return n&&(i.policy=n),i})(r.permissionContext,t.chainId,o,t.id);return e.withApiError(async()=>(await n.sessionsApi.revokeSession({revokeSessionRequest:s},{headers:i.thirdPartyProvider?{authorization:`Bearer ${n.config.backend.accessToken}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":String(n.config.backend.accessToken)}})).data,{context:"operation"})})(p,a,o,s,c).catch(e=>{throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(d?.nextAction?.payload?.signableHash){let e;e=[300,324].includes(o.chainId)||o.implementationType&&[r.AccountType.CALIBUR].includes(o.implementationType)?await i.sign(d.nextAction.payload.signableHash,!1,!1):await i.sign(d.nextAction.payload.signableHash);return(await a.sessionsApi.signatureSession({id:d.id,signatureRequest:{signature:e}}).catch(e=>{throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,e.message)})).data}return d};
1
+ "use strict";var e=require("../../core/errors/withApiError.cjs"),r=require("../../types/types.cjs"),n=require("./JsonRpcError.cjs");exports.revokeSession=async({params:t,signer:o,account:s,authentication:a,backendClient:i,feeSponsorshipId:c})=>{const p=t[0];if(!p.permissionContext)return await o.disconnect(),{};const d=await(async(r,n,t,o,s)=>{const a=((e,r,n,t)=>{const o={address:e,chainId:r,account:t};return n&&(o.policy=n),o})(r.permissionContext,t.chainId,s,t.id);return e.withApiError(async()=>(await n.sessionsApi.revokeSession({revokeSessionRequest:a},{headers:o.thirdPartyProvider?{authorization:`Bearer ${n.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:{authorization:`Bearer ${o.token}`,"x-project-key":String(n.config.backend.accessToken)}})).data,{context:"operation"})})(p,i,s,a,c).catch(e=>{throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(d?.nextAction?.payload?.signableHash){let e;e=[300,324].includes(s.chainId)||s.accountType===r.AccountTypeEnum.DELEGATED_ACCOUNT?await o.sign(d.nextAction.payload.signableHash,!1,!1):await o.sign(d.nextAction.payload.signableHash);return(await i.sessionsApi.signatureSession({id:d.id,signatureRequest:{signature:e}}).catch(e=>{throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,e.message)})).data}return d};
@@ -1 +1 @@
1
- "use strict";var e=require("../../core/errors/withApiError.cjs"),r=require("../../types/types.cjs"),t=require("../../utils/authorization.cjs"),o=require("./JsonRpcError.cjs");const a=e=>{const r=e?.logs?.[0];return{blockHash:r?.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:r?.transactionIndex,type:"eip1559",blobGasPrice:void 0,blobGasUsed:void 0,root:void 0}};async function n(e,r){try{const t=await e.getCode(r);return"0x"!==t&&t.length>2}catch{return!1}}exports.sendCallsSync=async({params:s,signer:i,account:c,authentication:d,backendClient:p,rpcProvider:u,feeSponsorshipId:l})=>{const E=s[0]?.capabilities?.paymasterService?.policy??l;let h;if(c.accountType===r.AccountTypeEnum.DELEGATED_ACCOUNT){const[e,r]=await Promise.all([n(u,c.address),u.getTransactionCount(c.address)]);if(!e){const e=await t.prepareAndSignAuthorization({signer:i,accountAddress:c.address,contractAddress:c.implementationAddress,chainId:c.chainId,nonce:r});h=t.serializeSignedAuthorization(e)}}const A=await(async(r,t,a,n,s,i)=>{const c=r.map(e=>{if(!e.to)throw new o.JsonRpcError(o.RpcErrorCode.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.withApiError(async()=>(await t.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{account:a.id,policy:s,signedAuthorization:i,chainId:a.chainId,interactions:c}},{headers:n.thirdPartyProvider?{authorization:`Bearer ${t.config.backend.accessToken}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}:{authorization:`Bearer ${n.token}`,"x-project-key":String(t.config.backend.accessToken)}})).data,{context:"operation"})})(s,p,c,d,E,h).catch(e=>{throw new o.JsonRpcError(o.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(A.response?.error?.reason)throw new o.JsonRpcError(o.RpcErrorCode.TRANSACTION_REJECTED,A.response.error.reason);if(A?.nextAction?.payload?.signableHash){let t;t=[300,324].includes(c.chainId)||c.implementationType&&[r.AccountType.CALIBUR].includes(c.implementationType)?await i.sign(A.nextAction.payload.signableHash,!1,!1):await i.sign(A.nextAction.payload.signableHash);const n=await e.withApiError(async()=>await p.transactionIntentsApi.signature({id:A.id,signatureRequest:{signature:t}}),{context:"operation"}).catch(e=>{throw new o.JsonRpcError(o.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(0===n.data.response?.status)throw new o.JsonRpcError(o.RpcErrorCode.TRANSACTION_REJECTED,n.data.response?.error?.reason??"");if(!n.data.response)throw new o.JsonRpcError(o.RpcErrorCode.TRANSACTION_REJECTED,"No transaction response received");return{id:A.id,receipt:a(n.data.response)}}if(!A.response)throw new o.JsonRpcError(o.RpcErrorCode.TRANSACTION_REJECTED,"No transaction response received");return{id:A.id,receipt:a(A.response)}};
1
+ "use strict";var e=require("../../core/errors/withApiError.cjs"),r=require("../../types/types.cjs"),t=require("../../utils/authorization.cjs"),o=require("./delegation.cjs"),n=require("./JsonRpcError.cjs");const a=e=>{const r=e?.logs?.[0];return{blockHash:r?.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:r?.transactionIndex,type:"eip1559",blobGasPrice:void 0,blobGasUsed:void 0,root:void 0}};async function s(e,r,t){try{const n=await e.getCode(r);return o.isDelegatedTo(n,t)}catch{return!1}}exports.sendCallsSync=async({params:o,signer:i,account:c,authentication:d,backendClient:p,rpcProvider:u,feeSponsorshipId:E})=>{const l=o[0]?.capabilities?.paymasterService?.policy??E;let A;if(c.accountType===r.AccountTypeEnum.DELEGATED_ACCOUNT){const{implementationAddress:e,chainId:r}=c;if(!e)throw new n.JsonRpcError(n.RpcErrorCode.INVALID_PARAMS,`Delegated account ${c.id} is missing an implementationAddress; cannot authorize its EIP-7702 delegation`);if(void 0===r)throw new n.JsonRpcError(n.RpcErrorCode.INVALID_PARAMS,`Delegated account ${c.id} is missing a chainId; cannot authorize its EIP-7702 delegation`);const[o,a]=await Promise.all([s(u,c.address,e),u.getTransactionCount(c.address)]);if(!o){const o=await t.prepareAndSignAuthorization({signer:i,accountAddress:c.address,contractAddress:e,chainId:r,nonce:a});A=t.serializeSignedAuthorization(o)}}const h=await(async(r,t,o,a,s,i)=>{const c=r.map(e=>{if(!e.to)throw new n.JsonRpcError(n.RpcErrorCode.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.withApiError(async()=>(await t.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{account:o.id,policy:s,signedAuthorization:i,chainId:o.chainId,interactions:c}},{headers:a.thirdPartyProvider?{authorization:`Bearer ${t.config.backend.accessToken}`,"x-player-token":a.token,"x-auth-provider":a.thirdPartyProvider,"x-token-type":a.thirdPartyTokenType}:{authorization:`Bearer ${a.token}`,"x-project-key":String(t.config.backend.accessToken)}})).data,{context:"operation"})})(o,p,c,d,l,A).catch(e=>{throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(h.response?.error?.reason)throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,h.response.error.reason);if(h?.nextAction?.payload?.signableHash){let t;t=[300,324].includes(c.chainId)||c.accountType===r.AccountTypeEnum.DELEGATED_ACCOUNT?await i.sign(h.nextAction.payload.signableHash,!1,!1):await i.sign(h.nextAction.payload.signableHash);const o=await e.withApiError(async()=>await p.transactionIntentsApi.signature({id:h.id,signatureRequest:{signature:t}}),{context:"operation"}).catch(e=>{throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(0===o.data.response?.status)throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,o.data.response?.error?.reason??"");if(!o.data.response)throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,"No transaction response received");return{id:h.id,receipt:a(o.data.response)}}if(!h.response)throw new n.JsonRpcError(n.RpcErrorCode.TRANSACTION_REJECTED,"No transaction response received");return{id:h.id,receipt:a(h.response)}};
@@ -1 +1 @@
1
- const o="1.3.4",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
1
+ const o="1.3.5",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
@@ -0,0 +1 @@
1
+ const t="0xef0100";function n(n,e){return!!e&&function(n){if(!n)return null;const e=n.toLowerCase();return 48!==e.length?null:e.startsWith(t)?`0x${e.slice(8)}`:null}(n)===e.toLowerCase()}export{n as isDelegatedTo};
@@ -1 +1 @@
1
- import{withApiError as t}from"../../core/errors/withApiError.js";import{AccountType as e}from"../../types/types.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,feeSponsorshipId:d})=>{const m=await(async(e,a,o,r,c)=>{const p=e[0],l=Math.floor(Date.now()/1e3),d=Math.floor(new Date(Date.now()+1e3*p.expiry).getTime()/1e3),m=p.permissions.map(s),y=m.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 u,h=m.find(t=>"call-limit"===t.type)?.data;if(h=m[0]?.policies?.find(t=>"call-limit"===t.type)?.data?.limit,"signer"in p&&p.signer){if("keys"===p.signer.type)throw new i(n.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==p.signer.type&&"account"!==p.signer.type||(u=p.signer.data.id)}else"account"in p&&p.account&&(u=p.account);if(!u)throw new i(n.INVALID_PARAMS,"Failed to request permissions - missing session address");const w=((t,e,i,n,a,s=!1,o,r,c)=>{const p={address:t,chainId:e,validAfter:i,validUntil:n,optimistic:s,whitelist:o,account:c};return a&&(p.policy=a),r&&(p.limit=r),p})(u,o.chainId,l,d,c,!1,y,h,o.id);return t(async()=>(await a.sessionsApi.createSession({createSessionRequest:w},{headers:r.thirdPartyProvider?{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":r.token,"x-auth-provider":r.thirdPartyProvider,"x-token-type":r.thirdPartyTokenType}:{authorization:`Bearer ${r.token}`,"x-project-key":String(a.config.backend.accessToken)}})).data,{context:"operation"})})(a,l,c,p,d).catch(t=>{throw new i(n.TRANSACTION_REJECTED,t.message)});if(m?.nextAction?.payload?.signableHash){let a;a=[300,324].includes(c.chainId)||c.implementationType&&[e.CALIBUR].includes(c.implementationType)?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,{context:"operation"}).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{withApiError as t}from"../../core/errors/withApiError.js";import{AccountTypeEnum as e}from"../../types/types.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,feeSponsorshipId:d})=>{const m=await(async(e,a,o,r,c)=>{const p=e[0],l=Math.floor(Date.now()/1e3),d=Math.floor(new Date(Date.now()+1e3*p.expiry).getTime()/1e3),m=p.permissions.map(s),u=m.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 y,h=m.find(t=>"call-limit"===t.type)?.data;if(h=m[0]?.policies?.find(t=>"call-limit"===t.type)?.data?.limit,"signer"in p&&p.signer){if("keys"===p.signer.type)throw new i(n.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==p.signer.type&&"account"!==p.signer.type||(y=p.signer.data.id)}else"account"in p&&p.account&&(y=p.account);if(!y)throw new i(n.INVALID_PARAMS,"Failed to request permissions - missing session address");const w=((t,e,i,n,a,s=!1,o,r,c)=>{const p={address:t,chainId:e,validAfter:i,validUntil:n,optimistic:s,whitelist:o,account:c};return a&&(p.policy=a),r&&(p.limit=r),p})(y,o.chainId,l,d,c,!1,u,h,o.id);return t(async()=>(await a.sessionsApi.createSession({createSessionRequest:w},{headers:r.thirdPartyProvider?{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":r.token,"x-auth-provider":r.thirdPartyProvider,"x-token-type":r.thirdPartyTokenType}:{authorization:`Bearer ${r.token}`,"x-project-key":String(a.config.backend.accessToken)}})).data,{context:"operation"})})(a,l,c,p,d).catch(t=>{throw new i(n.TRANSACTION_REJECTED,t.message)});if(m?.nextAction?.payload?.signableHash){let a;a=[300,324].includes(c.chainId)||c.accountType===e.DELEGATED_ACCOUNT?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,{context:"operation"}).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 +1 @@
1
- import{withApiError as e}from"../../core/errors/withApiError.js";import{AccountType as t}from"../../types/types.js";import{JsonRpcError as n,RpcErrorCode as a}from"./JsonRpcError.js";const i=async({params:i,signer:o,account:s,authentication:r,backendClient:c,feeSponsorshipId:p})=>{const d=i[0];if(!d.permissionContext)return await o.disconnect(),{};const h=await(async(t,n,a,i,o)=>{const s=((e,t,n,a)=>{const i={address:e,chainId:t,account:a};return n&&(i.policy=n),i})(t.permissionContext,a.chainId,o,a.id);return e(async()=>(await n.sessionsApi.revokeSession({revokeSessionRequest:s},{headers:i.thirdPartyProvider?{authorization:`Bearer ${n.config.backend.accessToken}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":String(n.config.backend.accessToken)}})).data,{context:"operation"})})(d,c,s,r,p).catch(e=>{throw new n(a.TRANSACTION_REJECTED,e.message)});if(h?.nextAction?.payload?.signableHash){let e;e=[300,324].includes(s.chainId)||s.implementationType&&[t.CALIBUR].includes(s.implementationType)?await o.sign(h.nextAction.payload.signableHash,!1,!1):await o.sign(h.nextAction.payload.signableHash);return(await c.sessionsApi.signatureSession({id:h.id,signatureRequest:{signature:e}}).catch(e=>{throw new n(a.TRANSACTION_REJECTED,e.message)})).data}return h};export{i as revokeSession};
1
+ import{withApiError as e}from"../../core/errors/withApiError.js";import{AccountTypeEnum as t}from"../../types/types.js";import{JsonRpcError as n,RpcErrorCode as a}from"./JsonRpcError.js";const o=async({params:o,signer:i,account:r,authentication:s,backendClient:c,feeSponsorshipId:d})=>{const p=o[0];if(!p.permissionContext)return await i.disconnect(),{};const h=await(async(t,n,a,o,i)=>{const r=((e,t,n,a)=>{const o={address:e,chainId:t,account:a};return n&&(o.policy=n),o})(t.permissionContext,a.chainId,i,a.id);return e(async()=>(await n.sessionsApi.revokeSession({revokeSessionRequest:r},{headers:o.thirdPartyProvider?{authorization:`Bearer ${n.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:{authorization:`Bearer ${o.token}`,"x-project-key":String(n.config.backend.accessToken)}})).data,{context:"operation"})})(p,c,r,s,d).catch(e=>{throw new n(a.TRANSACTION_REJECTED,e.message)});if(h?.nextAction?.payload?.signableHash){let e;e=[300,324].includes(r.chainId)||r.accountType===t.DELEGATED_ACCOUNT?await i.sign(h.nextAction.payload.signableHash,!1,!1):await i.sign(h.nextAction.payload.signableHash);return(await c.sessionsApi.signatureSession({id:h.id,signatureRequest:{signature:e}}).catch(e=>{throw new n(a.TRANSACTION_REJECTED,e.message)})).data}return h};export{o as revokeSession};
@@ -1 +1 @@
1
- import{withApiError as e}from"../../core/errors/withApiError.js";import{AccountTypeEnum as t,AccountType as a}from"../../types/types.js";import{prepareAndSignAuthorization as n,serializeSignedAuthorization as o}from"../../utils/authorization.js";import{JsonRpcError as r,RpcErrorCode as s}from"./JsonRpcError.js";const i=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 c(e,t){try{const a=await e.getCode(t);return"0x"!==a&&a.length>2}catch{return!1}}const d=async({params:d,signer:p,account:l,authentication:u,backendClient:h,rpcProvider:g,feeSponsorshipId:T})=>{const A=d[0]?.capabilities?.paymasterService?.policy??T;let m;if(l.accountType===t.DELEGATED_ACCOUNT){const[e,t]=await Promise.all([c(g,l.address),g.getTransactionCount(l.address)]);if(!e){const e=await n({signer:p,accountAddress:l.address,contractAddress:l.implementationAddress,chainId:l.chainId,nonce:t});m=o(e)}}const w=await(async(t,a,n,o,i,c)=>{const d=t.map(e=>{if(!e.to)throw new r(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 a.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{account:n.id,policy:i,signedAuthorization:c,chainId:n.chainId,interactions:d}},{headers:o.thirdPartyProvider?{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:{authorization:`Bearer ${o.token}`,"x-project-key":String(a.config.backend.accessToken)}})).data,{context:"operation"})})(d,h,l,u,A,m).catch(e=>{throw new r(s.TRANSACTION_REJECTED,e.message)});if(w.response?.error?.reason)throw new r(s.TRANSACTION_REJECTED,w.response.error.reason);if(w?.nextAction?.payload?.signableHash){let t;t=[300,324].includes(l.chainId)||l.implementationType&&[a.CALIBUR].includes(l.implementationType)?await p.sign(w.nextAction.payload.signableHash,!1,!1):await p.sign(w.nextAction.payload.signableHash);const n=await e(async()=>await h.transactionIntentsApi.signature({id:w.id,signatureRequest:{signature:t}}),{context:"operation"}).catch(e=>{throw new r(s.TRANSACTION_REJECTED,e.message)});if(0===n.data.response?.status)throw new r(s.TRANSACTION_REJECTED,n.data.response?.error?.reason??"");if(!n.data.response)throw new r(s.TRANSACTION_REJECTED,"No transaction response received");return{id:w.id,receipt:i(n.data.response)}}if(!w.response)throw new r(s.TRANSACTION_REJECTED,"No transaction response received");return{id:w.id,receipt:i(w.response)}};export{d as sendCallsSync};
1
+ import{withApiError as t}from"../../core/errors/withApiError.js";import{AccountTypeEnum as e}from"../../types/types.js";import{prepareAndSignAuthorization as a,serializeSignedAuthorization as n}from"../../utils/authorization.js";import{isDelegatedTo as o}from"./delegation.js";import{JsonRpcError as s,RpcErrorCode as r}from"./JsonRpcError.js";const i=t=>{const e=t?.logs?.[0];return{blockHash:e?.blockHash,blockNumber:t?.blockNumber?.toString(),contractAddress:void 0,cumulativeGasUsed:t?.gasUsed,effectiveGasPrice:t?.gasFee,from:void 0,gasUsed:t?.gasUsed,logs:t?.logs||[],logsBloom:void 0,status:1===t?.status?"success":0===t?.status?"reverted":void 0,to:t?.to,transactionHash:t?.transactionHash,transactionIndex:e?.transactionIndex,type:"eip1559",blobGasPrice:void 0,blobGasUsed:void 0,root:void 0}};async function c(t,e,a){try{const n=await t.getCode(e);return o(n,a)}catch{return!1}}const d=async({params:o,signer:d,account:p,authentication:l,backendClient:u,rpcProvider:h,feeSponsorshipId:g})=>{const A=o[0]?.capabilities?.paymasterService?.policy??g;let T;if(p.accountType===e.DELEGATED_ACCOUNT){const{implementationAddress:t,chainId:e}=p;if(!t)throw new s(r.INVALID_PARAMS,`Delegated account ${p.id} is missing an implementationAddress; cannot authorize its EIP-7702 delegation`);if(void 0===e)throw new s(r.INVALID_PARAMS,`Delegated account ${p.id} is missing a chainId; cannot authorize its EIP-7702 delegation`);const[o,i]=await Promise.all([c(h,p.address,t),h.getTransactionCount(p.address)]);if(!o){const o=await a({signer:d,accountAddress:p.address,contractAddress:t,chainId:e,nonce:i});T=n(o)}}const w=await(async(e,a,n,o,i,c)=>{const d=e.map(t=>{if(!t.to)throw new s(r.INVALID_PARAMS,'wallet_sendCalls requires a "to" field');return{to:String(t.to),data:t.data?String(t.data):void 0,value:t.value?String(t.value):void 0}});return t(async()=>(await a.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{account:n.id,policy:i,signedAuthorization:c,chainId:n.chainId,interactions:d}},{headers:o.thirdPartyProvider?{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:{authorization:`Bearer ${o.token}`,"x-project-key":String(a.config.backend.accessToken)}})).data,{context:"operation"})})(o,u,p,l,A,T).catch(t=>{throw new s(r.TRANSACTION_REJECTED,t.message)});if(w.response?.error?.reason)throw new s(r.TRANSACTION_REJECTED,w.response.error.reason);if(w?.nextAction?.payload?.signableHash){let a;a=[300,324].includes(p.chainId)||p.accountType===e.DELEGATED_ACCOUNT?await d.sign(w.nextAction.payload.signableHash,!1,!1):await d.sign(w.nextAction.payload.signableHash);const n=await t(async()=>await u.transactionIntentsApi.signature({id:w.id,signatureRequest:{signature:a}}),{context:"operation"}).catch(t=>{throw new s(r.TRANSACTION_REJECTED,t.message)});if(0===n.data.response?.status)throw new s(r.TRANSACTION_REJECTED,n.data.response?.error?.reason??"");if(!n.data.response)throw new s(r.TRANSACTION_REJECTED,"No transaction response received");return{id:w.id,receipt:i(n.data.response)}}if(!w.response)throw new s(r.TRANSACTION_REJECTED,"No transaction response received");return{id:w.id,receipt:i(w.response)}};export{d as sendCallsSync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
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",
@@ -53,13 +53,13 @@
53
53
  "@rollup/plugin-terser": "^0.4.4",
54
54
  "@rollup/plugin-typescript": "^11.1.6",
55
55
  "@types/node": "^22.19.17",
56
- "@vitest/coverage-v8": "^2.1.9",
56
+ "@vitest/coverage-v8": "^4.1.8",
57
57
  "jsdom": "^25.0.1",
58
58
  "rollup": "^4.60.1",
59
59
  "rollup-plugin-dts": "^5.3.1",
60
60
  "rollup-plugin-visualizer": "^5.14.0",
61
61
  "typescript": "^5.9.3",
62
- "vitest": "^2.1.9",
62
+ "vitest": "^4.1.8",
63
63
  "@openfort/openapi-clients": "0.0.1"
64
64
  },
65
65
  "main": "./dist/cjs/sdk/src/index.cjs",