@openfort/openfort-js 0.10.16 → 0.10.17

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="0.10.16";
1
+ "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.10.17";
@@ -1 +1 @@
1
- "use strict";var e=require("../../core/errors/openfortError.js"),t=require("./JsonRpcError.js");function r(e){return{data:"token-allowance"===e.type?{allowance:e.data.allowance.toString()}:"gas-limit"===e.type?{limit:e.data.limit.toString()}:e.data,type:"string"==typeof e.type?e.type:e.type.custom}}function i(e){return{...e,policies:e.policies.map(r),required:e.required??!1,type:"string"==typeof e.type?e.type:e.type.custom}}function a(e){return{expiry:e.validUntil?Number(e.validUntil):0,grantedPermissions:e.whitelist?e.whitelist.map(t=>({type:"contract-call",data:{address:t,calls:[]},policies:[{data:{limit:e.limit},type:{custom:"usage-limit"}}]})):[],permissionsContext:e.id}}exports.registerSession=async({params:r,signer:s,account:n,authentication:o,backendClient:c,policyId:p})=>{const l=await(async(r,a,s,n,o)=>{const c=r[0],p=Math.floor((new Date).getTime()/1e3),l=Math.floor(new Date(Date.now()+1e3*c.expiry).getTime()/1e3),d=c.permissions.map(i),y=d.filter(e=>"contract-call"===e.type||"erc20-token-transfer"===e.type).map(e=>e.data.address),u=d[0].policies.find(e=>"usage-limit"===e.type)?.data?.limit;let g;if("signer"in c&&c.signer){if("keys"===c.signer.type)throw new t.JsonRpcError(t.RpcErrorCode.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==c.signer.type&&"account"!==c.signer.type||(g=c.signer.data.id)}else"account"in c&&c.account&&(g=c.account);if(!g)throw new t.JsonRpcError(t.RpcErrorCode.INVALID_PARAMS,"Failed to request permissions - missing session address");const m=((e,t,r,i,a,s=!1,n,o,c,p)=>{const l={address:e,chainId:t,validAfter:r,validUntil:i,optimistic:s,whitelist:n,player:o,account:p};return a&&(l.policy=a),c&&(l.limit=c),l})(g,s.chainId,p,l,o,!1,y,n.player,u,s.id);return e.withOpenfortError(async()=>(await a.sessionsApi.createSession({createSessionRequest:m},{headers:{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}})).data,{default:e.OpenfortErrorType.AUTHENTICATION_ERROR})})(r,c,n,o,p).catch(e=>{throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,e.message)});if(l?.nextAction?.payload?.signableHash){let r;r=[300,531050104,324,50104,2741,11124].includes(n.chainId)?await s.sign(l.nextAction.payload.signableHash,!1,!1):await s.sign(l.nextAction.payload.signableHash);return a(await e.withOpenfortError(async()=>(await c.sessionsApi.signatureSession({id:l.id,signatureRequest:{signature:r}})).data,{default:e.OpenfortErrorType.AUTHENTICATION_ERROR}).catch(e=>{throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,e.message)}))}if(!1===l.isActive)throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,"Failed to grant permissions");return a(l)};
1
+ "use strict";var t=require("../../core/errors/openfortError.js"),e=require("./JsonRpcError.js");function r(t){return{data:(()=>{if("token-allowance"===t.type)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"token-allowance policy is not supported with this account implementation.");if("gas-limit"===t.type)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"gas-limit policy is not supported with this account implementation.");if("rate-limit"===t.type)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"rate-limit policy is not supported with this account implementation.");return t.data})(),type:t.type.custom}}function i(t){if("native-token-transfer"===t.type)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"native-token-transfer permission is not supported with this account implementation.");if("rate-limit"===t.type)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"rate-limit permission is not supported with this account implementation.");if("gas-limit"===t.type)throw new e.JsonRpcError(e.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 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}}exports.registerSession=async({params:r,signer:n,account:s,authentication:a,backendClient:p,policyId:c})=>{const l=await(async(r,o,n,s,a)=>{const p=r[0],c=Math.floor((new Date).getTime()/1e3),l=Math.floor(new Date(Date.now()+1e3*p.expiry).getTime()/1e3),d=p.permissions.map(i),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 p&&p.signer){if("keys"===p.signer.type)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==p.signer.type&&"account"!==p.signer.type||(m=p.signer.data.id)}else"account"in p&&p.account&&(m=p.account);if(!m)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"Failed to request permissions - missing session address");const R=((t,e,r,i,o,n=!1,s,a,p,c)=>{const l={address:t,chainId:e,validAfter:r,validUntil:i,optimistic:n,whitelist:s,player:a,account:c};return o&&(l.policy=o),p&&(l.limit=p),l})(m,n.chainId,c,l,a,!1,u,s.player,y,n.id);return t.withOpenfortError(async()=>(await o.sessionsApi.createSession({createSessionRequest:R},{headers:{authorization:`Bearer ${o.config.backend.accessToken}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}})).data,{default:t.OpenfortErrorType.AUTHENTICATION_ERROR})})(r,p,s,a,c).catch(t=>{throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,t.message)});if(l?.nextAction?.payload?.signableHash){let r;r=[300,531050104,324,50104,2741,11124].includes(s.chainId)?await n.sign(l.nextAction.payload.signableHash,!1,!1):await n.sign(l.nextAction.payload.signableHash);return o(await t.withOpenfortError(async()=>(await p.sessionsApi.signatureSession({id:l.id,signatureRequest:{signature:r}})).data,{default:t.OpenfortErrorType.AUTHENTICATION_ERROR}).catch(t=>{throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,t.message)}))}if(!1===l.isActive)throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,"Failed to grant permissions");return o(l)};
package/dist/index.d.ts CHANGED
@@ -636,6 +636,27 @@ type CustomPermission<data = unknown, type = {
636
636
  type: type;
637
637
  };
638
638
  /** @internal */
639
+ type GasLimitPermission = {
640
+ type: 'gas-limit';
641
+ data: {
642
+ limit: `0x${string}`;
643
+ };
644
+ };
645
+ /** @internal */
646
+ type CallLimitPermission = {
647
+ type: 'call-limit';
648
+ data: {
649
+ count: number;
650
+ };
651
+ };
652
+ type RateLimitPermission = {
653
+ type: 'rate-limit';
654
+ data: {
655
+ count: number;
656
+ interval: number;
657
+ };
658
+ };
659
+ /** @internal */
639
660
  type NativeTokenTransferPermission = {
640
661
  type: 'native-token-transfer';
641
662
  data: {
@@ -644,6 +665,24 @@ type NativeTokenTransferPermission = {
644
665
  };
645
666
  };
646
667
  /** @internal */
668
+ type ERC721TokenTransferPermission = {
669
+ type: 'erc721-token-transfer';
670
+ data: {
671
+ address: `0x${string}`;
672
+ tokenIds: `0x${string}`[];
673
+ };
674
+ };
675
+ /** @internal */
676
+ type ERC1155TokenTransferPermission = {
677
+ type: 'erc1155-token-transfer';
678
+ data: {
679
+ address: `0x${string}`;
680
+ allowances: {
681
+ [tokenId: string]: `0x${string}`;
682
+ };
683
+ };
684
+ };
685
+ /** @internal */
647
686
  type Erc20TokenTransferPermission = {
648
687
  type: 'erc20-token-transfer';
649
688
  data: {
@@ -663,9 +702,9 @@ type ContractCallPermission = {
663
702
  calls: string[];
664
703
  };
665
704
  };
666
- type Permission<uint256 = bigint> = OneOf<NativeTokenTransferPermission | Erc20TokenTransferPermission | ContractCallPermission | CustomPermission> & {
667
- /** Set of policies for the permission. */
668
- policies: readonly Policy<uint256>[];
705
+ type Permission<uint256 = bigint> = OneOf<NativeTokenTransferPermission | Erc20TokenTransferPermission | ERC721TokenTransferPermission | ERC1155TokenTransferPermission | GasLimitPermission | CallLimitPermission | RateLimitPermission | ContractCallPermission | CustomPermission> & {
706
+ /** Set of policies for the permission. No longer in the 7715 spec but required by viem */
707
+ policies?: readonly Policy<uint256>[];
669
708
  /** Whether or not the wallet must grant the permission. */
670
709
  required?: boolean | undefined;
671
710
  };
@@ -1 +1 @@
1
- const o="0.10.16",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
1
+ const o="0.10.17",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
@@ -1 +1 @@
1
- import{withOpenfortError as e,OpenfortErrorType as t}from"../../core/errors/openfortError.js";import{JsonRpcError as i,RpcErrorCode as a}from"./JsonRpcError.js";function n(e){return{data:"token-allowance"===e.type?{allowance:e.data.allowance.toString()}:"gas-limit"===e.type?{limit:e.data.limit.toString()}:e.data,type:"string"==typeof e.type?e.type:e.type.custom}}function s(e){return{...e,policies:e.policies.map(n),required:e.required??!1,type:"string"==typeof e.type?e.type:e.type.custom}}function r(e){return{expiry:e.validUntil?Number(e.validUntil):0,grantedPermissions:e.whitelist?e.whitelist.map(t=>({type:"contract-call",data:{address:t,calls:[]},policies:[{data:{limit:e.limit},type:{custom:"usage-limit"}}]})):[],permissionsContext:e.id}}const o=async({params:n,signer:o,account:c,authentication:l,backendClient:p,policyId:d})=>{const y=await(async(n,r,o,c,l)=>{const p=n[0],d=Math.floor((new Date).getTime()/1e3),y=Math.floor(new Date(Date.now()+1e3*p.expiry).getTime()/1e3),u=p.permissions.map(s),m=u.filter(e=>"contract-call"===e.type||"erc20-token-transfer"===e.type).map(e=>e.data.address),g=u[0].policies.find(e=>"usage-limit"===e.type)?.data?.limit;let w;if("signer"in p&&p.signer){if("keys"===p.signer.type)throw new i(a.INVALID_PARAMS,"Multi-key signers are not supported for session creation");"key"!==p.signer.type&&"account"!==p.signer.type||(w=p.signer.data.id)}else"account"in p&&p.account&&(w=p.account);if(!w)throw new i(a.INVALID_PARAMS,"Failed to request permissions - missing session address");const h=((e,t,i,a,n,s=!1,r,o,c,l)=>{const p={address:e,chainId:t,validAfter:i,validUntil:a,optimistic:s,whitelist:r,player:o,account:l};return n&&(p.policy=n),c&&(p.limit=c),p})(w,o.chainId,d,y,l,!1,m,c.player,g,o.id);return e(async()=>(await r.sessionsApi.createSession({createSessionRequest:h},{headers:{authorization:`Bearer ${r.config.backend.accessToken}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}})).data,{default:t.AUTHENTICATION_ERROR})})(n,p,c,l,d).catch(e=>{throw new i(a.TRANSACTION_REJECTED,e.message)});if(y?.nextAction?.payload?.signableHash){let n;n=[300,531050104,324,50104,2741,11124].includes(c.chainId)?await o.sign(y.nextAction.payload.signableHash,!1,!1):await o.sign(y.nextAction.payload.signableHash);return r(await e(async()=>(await p.sessionsApi.signatureSession({id:y.id,signatureRequest:{signature:n}})).data,{default:t.AUTHENTICATION_ERROR}).catch(e=>{throw new i(a.TRANSACTION_REJECTED,e.message)}))}if(!1===y.isActive)throw new i(a.TRANSACTION_REJECTED,"Failed to grant permissions");return r(y)};export{o as registerSession};
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((new Date).getTime()/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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.10.16",
3
+ "version": "0.10.17",
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",