@openfort/openfort-js 0.10.36-beta.1 → 0.10.36-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/packages/internal/openapi-clients/dist/index.js +1 -1
- package/dist/cjs/sdk/src/api/auth.js +1 -1
- package/dist/cjs/sdk/src/api/embeddedWallet.js +1 -1
- package/dist/cjs/sdk/src/auth/authManager.js +1 -1
- package/dist/cjs/sdk/src/core/configuration/account.js +1 -1
- package/dist/cjs/sdk/src/core/errors/sentry.js +1 -1
- package/dist/cjs/sdk/src/core/openfort.js +1 -1
- package/dist/cjs/sdk/src/core/openfortInternal.js +1 -1
- package/dist/cjs/sdk/src/storage/lazyStorage.js +1 -1
- package/dist/cjs/sdk/src/storage/scopedStorage.js +1 -0
- package/dist/cjs/sdk/src/utils/chains/index.js +1 -1
- package/dist/cjs/sdk/src/version.js +1 -1
- package/dist/cjs/sdk/src/wallets/embedded.js +1 -1
- package/dist/cjs/sdk/src/wallets/evm/getAssets.js +1 -1
- package/dist/cjs/sdk/src/wallets/evm/registerSession.js +1 -1
- package/dist/cjs/sdk/src/wallets/evm/revokeSession.js +1 -1
- package/dist/cjs/sdk/src/wallets/evm/sendCallSync.js +1 -1
- package/dist/index.d.ts +320 -59
- package/dist/packages/internal/openapi-clients/dist/index.js +1 -1
- package/dist/sdk/src/api/auth.js +1 -1
- package/dist/sdk/src/api/embeddedWallet.js +1 -1
- package/dist/sdk/src/auth/authManager.js +1 -1
- package/dist/sdk/src/core/configuration/account.js +1 -1
- package/dist/sdk/src/core/errors/sentry.js +1 -1
- package/dist/sdk/src/core/openfort.js +1 -1
- package/dist/sdk/src/core/openfortInternal.js +1 -1
- package/dist/sdk/src/storage/lazyStorage.js +1 -1
- package/dist/sdk/src/storage/scopedStorage.js +1 -0
- package/dist/sdk/src/utils/chains/index.js +1 -1
- package/dist/sdk/src/version.js +1 -1
- package/dist/sdk/src/wallets/embedded.js +1 -1
- package/dist/sdk/src/wallets/evm/getAssets.js +1 -1
- package/dist/sdk/src/wallets/evm/registerSession.js +1 -1
- package/dist/sdk/src/wallets/evm/revokeSession.js +1 -1
- package/dist/sdk/src/wallets/evm/sendCallSync.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{debugLog as t}from"../utils/debug.js";import{singlePromise as e}from"../utils/promiseUtils.js";import{OpenfortEvents as r}from"../types/types.js";import{SDKConfiguration as o}from"./config/config.js";import{Authentication as i}from"./configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as a}from"./errors/authErrorCodes.js";import{RequestError as n,ConfigurationError as s,AuthenticationError as h,SessionError as d}from"./errors/openfortError.js";class u{storage;authManager;eventEmitter;constructor(t,e,r){this.storage=t,this.authManager=e,this.eventEmitter=r}async getThirdPartyAuthToken(){const t=o.getInstance();if(!t?.thirdPartyAuth)throw new n("No third party configuration found");const{getAccessToken:e,provider:r}=t.thirdPartyAuth;if(!e||!r)throw new s("Third party is not configured. Please configure getAccessToken and thirdPartyAuthProvider in your Openfort instance");const d=await e();if(!d)throw new h(a.INVALID_TOKEN,"Could not get access token");let u=(await i.fromStorage(this.storage))?.userId;if(!u){u=(await this.authManager.authenticateThirdParty(r,d)).userId}return new i("third_party",d,u,r).save(this.storage),d}async getAccessToken(){if(o.getInstance()?.thirdPartyAuth)return this.getThirdPartyAuthToken();return(await i.fromStorage(this.storage))?.token??null}async validateAndRefreshToken(s){return e(async()=>{if(o.getInstance()?.thirdPartyAuth)return void await this.getThirdPartyAuthToken();const e=await i.fromStorage(this.storage);if(!e)throw new d(a.NOT_LOGGED_IN,"Must be logged in to validate and refresh token");let h;t("validating credentials...");try{h=await this.authManager.validateCredentials(e,s)}catch(t){throw i.clear(this.storage),this.eventEmitter.emit(r.ON_LOGOUT),t}if(!h.user?.id)throw new n("No user found in credentials");h.token!==e.token&&(t("tokens refreshed"),new i("session",h.token,h.user.id).save(this.storage))},"openfort.validateAndRefreshToken")}}export{u as OpenfortInternal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConfigurationError as e}from"../core/errors/openfortError.js";import{
|
|
1
|
+
import{ConfigurationError as e}from"../core/errors/openfortError.js";import{ScopedStorage as t}from"./scopedStorage.js";import{StorageImplementation as o}from"./storage.js";class r{realStorage=null;customStorage;publishableKey;constructor(e,t){this.publishableKey=e,this.customStorage=t}getRealStorage(){if(!this.realStorage){let r;if(this.customStorage)r=this.customStorage;else{if("undefined"==typeof window||"undefined"==typeof localStorage)throw new e("Storage not available. Please provide custom storage or use in browser environment.");r=new o(localStorage)}this.realStorage=new t(r,this.publishableKey)}return this.realStorage}async get(e){return this.getRealStorage().get(e)}save(e,t){this.getRealStorage().save(e,t)}remove(e){this.getRealStorage().remove(e)}flush(){this.getRealStorage().flush()}}export{r as LazyStorage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{StorageKeys as e}from"./istorage.js";class s{storage;scope;constructor(e,s){this.storage=e,this.scope=this.createScope(s)}createScope(e){return e.substring(8).substring(0,8)}scopeKey(e){return`${this.scope}.${e}`}async get(e){return this.storage.get(this.scopeKey(e))}save(e,s){this.storage.save(this.scopeKey(e),s)}remove(e){this.storage.remove(this.scopeKey(e))}flush(){for(const s of Object.values(e))this.storage.remove(this.scopeKey(s))}}export{s as ScopedStorage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",
|
|
1
|
+
const t={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",1946:"https://rpc.minato.soneium.org",3008:"https://kl1-testnet.kiooverse.xyz/rpc",4337:"https://build.onbeam.com/rpc",5611:"https://opbnb-testnet-rpc.bnbchain.org",8453:"https://mainnet.base.org",10143:"https://testnet-rpc.monad.xyz",13337:"https://build.onbeam.com/rpc/testnet",42161:"https://arb1.arbitrum.io/rpc",42170:"https://nova.arbitrum.io/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",43114:"https://api.avax.network/ext/bc/C/rpc",80002:"https://polygon-amoy-bor-rpc.publicnode.com",84358:"https://subnets.avax.network/titan/mainnet/rpc",84532:"https://sepolia.base.org",421614:"https://sepolia-rollup.arbitrum.io/rpc",510525:"https://rpc.clankermon.com",510530:"https://open-loot.rpc.syndicate.io",510531:"https://open-loot.rpc.testnet.syndicate.io",7225878:"https://rpc.saakuru.network",7777777:"https://rpc.zora.energy",11155111:"https://ethereum-sepolia-rpc.publicnode.com",11155420:"https://optimism-sepolia-rpc.publicnode.com",28122024:"https://rpcv2-testnet.ancient8.gg",666666666:"https://rpc.degen.tips",888888888:"https://rpc.ancient8.gg",999999999:"https://sepolia.rpc.zora.energy"};export{t as defaultChainRpcs};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.10.36-beta.
|
|
1
|
+
const o="0.10.36-beta.3",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Authentication as e}from"../core/configuration/authentication.js";import{PasskeyHandler as t}from"../core/configuration/passkey.js";import{OPENFORT_AUTH_ERROR_CODES as a}from"../core/errors/authErrorCodes.js";import{SessionError as r,ConfigurationError as o}from"../core/errors/openfortError.js";import{withApiError as s}from"../core/errors/withApiError.js";import{
|
|
1
|
+
import{Authentication as e}from"../core/configuration/authentication.js";import{PasskeyHandler as t}from"../core/configuration/passkey.js";import{OPENFORT_AUTH_ERROR_CODES as a}from"../core/errors/authErrorCodes.js";import{SessionError as r,ConfigurationError as o}from"../core/errors/openfortError.js";import{withApiError as s}from"../core/errors/withApiError.js";import{SDKConfiguration as n}from"../core/config/config.js";import{Account as i}from"../core/configuration/account.js";import{StorageKeys as c}from"../storage/istorage.js";import{OpenfortEvents as d,AccountTypeEnum as y}from"../types/types.js";class p{iframeManager;storage;backendApiClients;passkeyHandler;eventEmitter;constructor(e,t,a,r,o){this.iframeManager=e,this.storage=t,this.backendApiClients=a,this.passkeyHandler=r,this.eventEmitter=o}async createPasskey(e){const a=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:e});return{id:a.id,key:a.key}}async configure(t){const c=await e.fromStorage(this.storage);if(!c)throw new r(a.NOT_LOGGED_IN,"No access token found");const y=n.getInstance();if(!y)throw new o("Configuration not found");const p=await i.fromStorage(this.storage);let h;if(p){const e={account:p.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===p.recoveryMethod&&{passkey:{id:p.recoveryMethodDetails?.passkeyId,env:p.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(p.recoveryMethodDetails?.passkeyId??"")}}}}},a=await this.iframeManager.recover(e);h=a.account}else{const e=await this.backendApiClients.accountsApi.getAccountsV2({user:c.userId,accountType:t.accountType,chainType:t.chainType},{headers:c.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}:{authorization:`Bearer ${c.token}`,"x-project-key":y.baseConfiguration.publishableKey}});if(0===e.data.data.length){const e=t.entropy?.passkey?await this.createPasskey(c.userId):void 0,a={accountType:t.accountType,chainType:t.chainType,chainId:t.chainId,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},...t.entropy.passkey&&{passkey:e}}}},r=await this.iframeManager.create(a);h=r.account}else{const a=e.data.data,r=a.find(e=>e.chainId===t.chainId),o=r||a[0],s={account:o.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===o.recoveryMethod&&{passkey:{id:o.recoveryMethodDetails?.passkeyId,env:o.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(o.recoveryMethodDetails?.passkeyId??"")}}}}},n=await this.iframeManager.recover(s);if(h=n.account,!r){const e=await this.iframeManager.switchChain(t.chainId);h=e.account}}}return s(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:h},{headers:c.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}:{authorization:`Bearer ${c.token}`,"x-project-key":y.baseConfiguration.publishableKey}}),t=new i({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:i.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(d.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"configure"})}async sign(e,t,a,r){const o=await this.iframeManager.sign(e,t,a,r);return this.eventEmitter.emit(d.ON_SIGNED_MESSAGE,{message:e,signature:o}),o}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await i.fromStorage(this.storage);if(t?.accountType===y.EOA)new i({...t,chainId:e}).save(this.storage);else{const a=await this.iframeManager.switchChain(e);new i({...t,id:a.account,chainId:e}).save(this.storage)}}async create(t){const c=await this.iframeManager.create(t),y=await e.fromStorage(this.storage);if(!y)throw new r(a.NOT_LOGGED_IN,"No access token found");const p=n.getInstance();if(!p)throw new o("Configuration not found");return s(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:c.account},{headers:y.thirdPartyProvider?{authorization:`Bearer ${p.baseConfiguration.publishableKey}`,"x-player-token":y.token,"x-auth-provider":y.thirdPartyProvider,"x-token-type":y.thirdPartyTokenType}:{authorization:`Bearer ${y.token}`,"x-project-key":p.baseConfiguration.publishableKey}}),t=new i({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,implementationAddress:e.data.smartAccount?.implementationAddress,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:i.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(d.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"create"})}async recover(t){const c=await this.iframeManager.recover(t),y=await e.fromStorage(this.storage);if(!y)throw new r(a.NOT_LOGGED_IN,"No access token found");const p=n.getInstance();if(!p)throw new o("Configuration not found");return s(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:c.account},{headers:y.thirdPartyProvider?{authorization:`Bearer ${p.baseConfiguration.publishableKey}`,"x-player-token":y.token,"x-auth-provider":y.thirdPartyProvider,"x-token-type":y.thirdPartyTokenType}:{authorization:`Bearer ${y.token}`,"x-project-key":p.baseConfiguration.publishableKey}}),t=new i({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:i.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(d.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"recover"})}async setRecoveryMethod({recoveryMethod:e,recoveryPassword:t,encryptionSession:a,passkeyInfo:r}){await this.iframeManager.setRecoveryMethod(e,t,a,r?.passkeyKey,r?.passkeyId)}async disconnect(){await this.iframeManager.disconnect(),this.storage.remove(c.ACCOUNT)}}export{p as EmbeddedSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withApiError as e}from"../../core/errors/withApiError.js";import{JsonRpcError as t,RpcErrorCode as r}from"./JsonRpcError.js";const a=async({params:a,account:o,authentication:s,backendClient:
|
|
1
|
+
import{withApiError as e}from"../../core/errors/withApiError.js";import{JsonRpcError as t,RpcErrorCode as r}from"./JsonRpcError.js";const a=async({params:a,account:o,authentication:s,backendClient:i})=>{const n=await(async(t,r,a,o)=>e(async()=>(await t.rpcApi.handleRpcRequest({jsonRpcRequest:{method:"wallet_getAssets",params:{account:r.address,chainFilter:o?.chainFilter,assetFilter:o?.assetFilter,assetTypeFilter:o?.assetTypeFilter},id:1,jsonrpc:"2.0"}},{headers:a.thirdPartyProvider?{authorization:`Bearer ${t.config.backend.accessToken}`,"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"}))(i,o,s,a).catch(e=>{throw new t(r.INTERNAL_ERROR,e.message)});return n.result};export{a as getAssets};
|
|
@@ -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,policyId: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,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})(u,o.chainId,l,d,c,!1,y,r.userId,h,o.id);return t(async()=>(await a.sessionsApi.createSession({createSessionRequest:w},{headers:r.thirdPartyProvider?{authorization:`Bearer ${a.config.backend.accessToken}`,"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,
|
|
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,policyId: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,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})(u,o.chainId,l,d,c,!1,y,r.userId,h,o.id);return t(async()=>(await a.sessionsApi.createSession({createSessionRequest:w},{headers:r.thirdPartyProvider?{authorization:`Bearer ${a.config.backend.accessToken}`,"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 +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:r,account:s,authentication:o,backendClient:c,policyId:d})=>{const p=i[0];if(!p.permissionContext)return await r.disconnect(),{};const h=await(async(t,n,a,i,r)=>{const s=((e,t,n,a,i)=>{const r={address:e,chainId:t,player:n,account:i};return a&&(r.policy=a),r})(t.permissionContext,a.chainId,i.userId,r,a.id);return e(async()=>(await n.sessionsApi.revokeSession({revokeSessionRequest:s},{headers:i.thirdPartyProvider?{authorization:`Bearer ${n.config.backend.accessToken}`,"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,c,s,o,d).catch(e=>{throw new n(a.TRANSACTION_REJECTED,e.message)});if(h?.nextAction?.payload?.signableHash){let e;e=[300,
|
|
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:r,account:s,authentication:o,backendClient:c,policyId:d})=>{const p=i[0];if(!p.permissionContext)return await r.disconnect(),{};const h=await(async(t,n,a,i,r)=>{const s=((e,t,n,a,i)=>{const r={address:e,chainId:t,player:n,account:i};return a&&(r.policy=a),r})(t.permissionContext,a.chainId,i.userId,r,a.id);return e(async()=>(await n.sessionsApi.revokeSession({revokeSessionRequest:s},{headers:i.thirdPartyProvider?{authorization:`Bearer ${n.config.backend.accessToken}`,"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,c,s,o,d).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 r.sign(h.nextAction.payload.signableHash,!1,!1):await r.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 +1 @@
|
|
|
1
|
-
import{withApiError as t}from"../../core/errors/withApiError.js";import{AccountTypeEnum as e,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=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){try{const a=await t.getCode(e);return"0x"!==a&&a.length>2}catch{return!1}}const d=async({params:d,signer:p,account:l,authentication:u,backendClient:h,rpcProvider:g,policyId:T})=>{const A=d[0]?.capabilities?.paymasterService?.policy??T;let m;if(l.accountType===e.DELEGATED_ACCOUNT){const[t,e]=await Promise.all([c(g,l.address),g.getTransactionCount(l.address)]);if(!t){const t=await n({signer:p,accountAddress:l.address,contractAddress:l.implementationAddress,chainId:l.chainId,nonce:e});m=o(t)}}const w=await(async(e,a,n,o,i,c)=>{const d=e.map(t=>{if(!t.to)throw new r(s.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-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(t=>{throw new r(s.TRANSACTION_REJECTED,t.message)});if(w.response?.error.reason)throw new r(s.TRANSACTION_REJECTED,w.response?.error.reason);if(w?.nextAction?.payload?.signableHash){let e;e=[300,
|
|
1
|
+
import{withApiError as t}from"../../core/errors/withApiError.js";import{AccountTypeEnum as e,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=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){try{const a=await t.getCode(e);return"0x"!==a&&a.length>2}catch{return!1}}const d=async({params:d,signer:p,account:l,authentication:u,backendClient:h,rpcProvider:g,policyId:T})=>{const A=d[0]?.capabilities?.paymasterService?.policy??T;let m;if(l.accountType===e.DELEGATED_ACCOUNT){const[t,e]=await Promise.all([c(g,l.address),g.getTransactionCount(l.address)]);if(!t){const t=await n({signer:p,accountAddress:l.address,contractAddress:l.implementationAddress,chainId:l.chainId,nonce:e});m=o(t)}}const w=await(async(e,a,n,o,i,c)=>{const d=e.map(t=>{if(!t.to)throw new r(s.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-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(t=>{throw new r(s.TRANSACTION_REJECTED,t.message)});if(w.response?.error.reason)throw new r(s.TRANSACTION_REJECTED,w.response?.error.reason);if(w?.nextAction?.payload?.signableHash){let e;e=[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 t(async()=>await h.transactionIntentsApi.signature({id:w.id,signatureRequest:{signature:e}}),{context:"operation"}).catch(t=>{throw new r(s.TRANSACTION_REJECTED,t.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};
|
package/package.json
CHANGED