@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.
|
|
1
|
+
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.10.17";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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
|
|
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
|
};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.10.
|
|
1
|
+
const o="0.10.17",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withOpenfortError as
|
|
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