@openfort/openfort-js 0.10.30 → 0.10.32
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/sdk/src/core/config/config.js +1 -1
- package/dist/cjs/sdk/src/utils/debug.js +1 -1
- package/dist/cjs/sdk/src/version.js +1 -1
- package/dist/cjs/sdk/src/wallets/evm/evmProvider.js +1 -1
- package/dist/index.d.ts +25 -18
- package/dist/sdk/src/core/config/config.js +1 -1
- package/dist/sdk/src/utils/debug.js +1 -1
- package/dist/sdk/src/version.js +1 -1
- package/dist/sdk/src/wallets/evm/evmProvider.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../../utils/crypto.js");class i{baseConfiguration;shieldConfiguration;thirdPartyAuth;shieldUrl;iframeUrl;backendUrl;storage;passkeyRpId;passkeyRpName;nativeAppIdentifier;static instance=null;constructor({baseConfiguration:s,shieldConfiguration:t,overrides:r,thirdPartyAuth:a}){this.shieldConfiguration=t,this.baseConfiguration=s,this.backendUrl=r?.backendUrl||"https://api.openfort.io",this.iframeUrl=r?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,t?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=r?.shieldUrl||"https://shield.openfort.io",this.storage=r?.storage,this.thirdPartyAuth=a,this.passkeyRpId=t?.passkeyRpId,this.passkeyRpName=t?.passkeyRpName,this.nativeAppIdentifier=s.nativeAppIdentifier,r?.crypto?.digest&&e.setCryptoDigestOverride(r.crypto.digest),i.instance=this}static getInstance(){return i.instance}}exports.OpenfortConfiguration=class{publishableKey;nativeAppIdentifier;constructor(e){this.publishableKey=e.publishableKey,this.nativeAppIdentifier=e.nativeAppIdentifier}},exports.SDKConfiguration=i,exports.ShieldConfiguration=class{shieldPublishableKey;shieldEncryptionKey;debug=!1;passkeyRpId;passkeyRpName;constructor(e){this.shieldPublishableKey=e.shieldPublishableKey,this.debug=e.shieldDebug||!1,this.passkeyRpId=e.passkeyRpId,this.passkeyRpName=e.passkeyRpName}};
|
|
1
|
+
"use strict";var e=require("../../utils/crypto.js");class i{baseConfiguration;shieldConfiguration;thirdPartyAuth;shieldUrl;iframeUrl;backendUrl;storage;passkeyRpId;passkeyRpName;nativeAppIdentifier;debug;static instance=null;constructor({baseConfiguration:s,shieldConfiguration:t,overrides:r,thirdPartyAuth:a,debug:p}){this.shieldConfiguration=t,this.baseConfiguration=s,this.backendUrl=r?.backendUrl||"https://api.openfort.io",this.iframeUrl=r?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,this.debug=p,t?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=r?.shieldUrl||"https://shield.openfort.io",this.storage=r?.storage,this.thirdPartyAuth=a,this.passkeyRpId=t?.passkeyRpId,this.passkeyRpName=t?.passkeyRpName,this.nativeAppIdentifier=s.nativeAppIdentifier,r?.crypto?.digest&&e.setCryptoDigestOverride(r.crypto.digest),i.instance=this}static getInstance(){return i.instance}}exports.OpenfortConfiguration=class{publishableKey;nativeAppIdentifier;constructor(e){this.publishableKey=e.publishableKey,this.nativeAppIdentifier=e.nativeAppIdentifier}},exports.SDKConfiguration=i,exports.ShieldConfiguration=class{shieldPublishableKey;shieldEncryptionKey;debug=!1;passkeyRpId;passkeyRpName;constructor(e){this.shieldPublishableKey=e.shieldPublishableKey,this.debug=e.shieldDebug||!1,this.passkeyRpId=e.passkeyRpId,this.passkeyRpName=e.passkeyRpName}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var o=require("../core/config/config.js");exports.debugLog=function(...
|
|
1
|
+
"use strict";var o=require("../core/config/config.js");exports.debugLog=function(...e){const n=o.SDKConfiguration.getInstance();n?.debug&&console.log(`${(new Date).toISOString()} [SDK]`,...e)};
|
|
@@ -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.32";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("../../core/configuration/account.js"),e=require("../../core/configuration/authentication.js"),r=require("../../types/types.js"),a=require("../../utils/chains/index.js"),
|
|
1
|
+
"use strict";var t=require("../../core/configuration/account.js"),e=require("../../core/configuration/authentication.js"),r=require("../../types/types.js"),a=require("../../utils/chains/index.js"),i=require("../../utils/crypto.js"),s=require("../../utils/typedEventEmitter.js"),o=require("./addEthereumChain.js"),n=require("./estimateGas.js"),c=require("./getCallsStatus.js"),h=require("./JsonRpcError.js"),d=require("./personalSign.js"),u=require("./registerSession.js"),p=require("./revokeSession.js"),l=require("./sendCallSync.js"),w=require("./sendCalls.js"),g=require("./signTypedDataV4.js"),m=require("./types.js"),E=require("./walletHelpers.js");exports.EvmProvider=class{#t;#e;#r;#a;updatePolicy(t){this.#e=t}#i;#s;#o=null;#n;isOpenfort=!0;#c;constructor({storage:t,backendApiClients:e,openfortEventEmitter:a,policyId:i,ensureSigner:o,chains:n,validateAndRefreshSession:c}){this.#c=o,this.#t=t,this.#r=n,this.#e=i,this.#i=c,this.#n=e,this.#s=new s,a.on(r.OpenfortEvents.ON_LOGOUT,this.#h),a.on(r.OpenfortEvents.ON_SWITCH_ACCOUNT,this.#d)}#u=async()=>(this.#a||(this.#a=await this.#c()),this.#a);#h=async()=>{this.#a=void 0,this.#s.emit(m.ProviderEvent.ACCOUNTS_CHANGED,[])};#d=async t=>{this.#s.emit(m.ProviderEvent.ACCOUNTS_CHANGED,[t])};async getRpcProvider(){if(!this.#o){const e=await t.Account.fromStorage(this.#t),r=e?.chainId||8453;await import("@ethersproject/providers").then(t=>{const e=this.#r?this.#r[r]:void 0;this.#o=new t.StaticJsonRpcProvider(e??a.defaultChainRpcs[r])})}if(!this.#o)throw new Error("RPC provider not initialized");return this.#o}async#p(s){switch(s.method){case"eth_accounts":{const e=await t.Account.fromStorage(this.#t);return e?[e.address]:[]}case"eth_requestAccounts":{const e=await t.Account.fromStorage(this.#t);if(e)return this.#s.emit(m.ProviderEvent.ACCOUNTS_CONNECT,{chainId:String(e.chainId)}),[e.address];throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer.")}case"eth_signTransaction":{const r=await t.Account.fromStorage(this.#t),a=await this.#u(),i=await e.Authentication.fromStorage(this.#t);if(!r||!i)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const o=await this.getRpcProvider(),{chainId:n}=await o.detectNetwork(),[c]=s.params||[];c.chainId||(c.chainId=n.toString());const d=E.parseTransactionRequest(c),{serialize:u}=await import("@ethersproject/transactions"),p=t=>({legacy:0,eip2930:1,eip1559:2}[t]),{gas:l,...w}=d,g={...w,gasLimit:l,to:d.to??void 0,type:p(d.type)},m=u(g),{keccak256:A}=await import("@ethersproject/keccak256"),R=A(m);await this.#i();const f=await a.sign(R,!1,!1),{splitSignature:S}=await import("@ethersproject/bytes");return u(g,S(f))}case"eth_sendTransaction":{const a=await t.Account.fromStorage(this.#t),i=await this.#u(),o=await e.Authentication.fromStorage(this.#t);if(!a||!o)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(await this.#i(),a?.accountType===r.AccountTypeEnum.EOA){const[t]=s.params||[],e=await this.getRpcProvider(),r=await E.prepareEOATransaction(t,e,a.address),i=await this.#p({method:"eth_signTransaction",params:[r]});return this.#p({method:"eth_sendRawTransaction",params:[i]})}return(await l.sendCallsSync({params:s.params||[],signer:i,account:a,authentication:o,backendClient:this.#n,policyId:this.#e})).receipt.transactionHash}case"eth_sendRawTransactionSync":{const a=await t.Account.fromStorage(this.#t),i=await this.#u(),o=await e.Authentication.fromStorage(this.#t);if(!a||!o)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(a?.accountType===r.AccountTypeEnum.EOA)throw new h.JsonRpcError(h.ProviderErrorCode.UNSUPPORTED_METHOD,`${s.method}: Method not supported`);return await this.#i(),await l.sendCallsSync({params:s.params||[],signer:i,account:a,authentication:o,backendClient:this.#n,policyId:this.#e})}case"eth_estimateGas":{const r=await t.Account.fromStorage(this.#t),a=await e.Authentication.fromStorage(this.#t);if(!r||!a)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await n.estimateGas({params:s.params||[],account:r,authentication:a,backendClient:this.#n,policyId:this.#e})}case"eth_signTypedData":case"eth_signTypedData_v4":{const e=await t.Account.fromStorage(this.#t),r=await this.#u();if(!e)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#i();const a=await this.getRpcProvider();return await g.signTypedDataV4({method:s.method,params:s.params||[],signer:r,implementationType:e.implementationType||e.type,rpcProvider:a,account:e})}case"personal_sign":{const e=await t.Account.fromStorage(this.#t);if(!e)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const r=await this.#u();return await this.#i(),await d.personalSign({params:s.params||[],signer:r,account:e})}case"eth_chainId":{const t=await this.getRpcProvider(),{chainId:e}=await t.detectNetwork();return i.numberToHex(e)}case"wallet_switchEthereumChain":{const t=await this.#u();if(!s.params||!Array.isArray(s.params)||0===s.params.length)throw new h.JsonRpcError(h.RpcErrorCode.INVALID_PARAMS,"Invalid parameters for wallet_switchEthereumChain");await this.#i();try{const e=parseInt(s.params[0].chainId,16);await t.switchChain({chainId:e}),await import("@ethersproject/providers").then(t=>{const r=this.#r?this.#r[e]:void 0;this.#o=new t.StaticJsonRpcProvider(r??a.defaultChainRpcs[e])})}catch(t){const e=t;throw new h.JsonRpcError(h.RpcErrorCode.INTERNAL_ERROR,`Failed to switch chain: ${e.message}`)}return null}case"wallet_addEthereumChain":{await this.#u();const t=await this.getRpcProvider();return await o.addEthereumChain({params:s.params||[],rpcProvider:t,storage:this.#t})}case"wallet_showCallsStatus":return null;case"wallet_getCallsStatus":{const a=await t.Account.fromStorage(this.#t);if(a?.accountType===r.AccountTypeEnum.EOA)throw new h.JsonRpcError(h.ProviderErrorCode.UNSUPPORTED_METHOD,`${s.method}: Method not supported`);const i=await e.Authentication.fromStorage(this.#t);if(!a||!i)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await c.getCallStatus({params:s.params||{},authentication:i,backendClient:this.#n})}case"wallet_sendCalls":{const a=await t.Account.fromStorage(this.#t);if(a?.accountType===r.AccountTypeEnum.EOA)throw new h.JsonRpcError(h.ProviderErrorCode.UNSUPPORTED_METHOD,`${s.method}: Method not supported`);const i=await this.#u(),o=await e.Authentication.fromStorage(this.#t);if(!a||!o)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#i();return await w.sendCalls({params:s.params?s.params[0].calls:[],signer:i,account:a,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_grantPermissions":{const a=await t.Account.fromStorage(this.#t);if(a?.accountType===r.AccountTypeEnum.EOA)throw new h.JsonRpcError(h.ProviderErrorCode.UNSUPPORTED_METHOD,`${s.method}: Method not supported`);const i=await this.#u(),o=await e.Authentication.fromStorage(this.#t);if(!a||!o)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await u.registerSession({params:s.params||[],signer:i,account:a,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_revokePermissions":{const r=await t.Account.fromStorage(this.#t),a=await this.#u(),i=await e.Authentication.fromStorage(this.#t);if(!r||!i)throw new h.JsonRpcError(h.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#i(),await p.revokeSession({params:s.params||[],signer:a,account:r,authentication:i,backendClient:this.#n,policyId:this.#e})}case"wallet_getCapabilities":{const e=await t.Account.fromStorage(this.#t);if(e?.accountType===r.AccountTypeEnum.EOA)throw new h.JsonRpcError(h.ProviderErrorCode.UNSUPPORTED_METHOD,`${s.method}: Method not supported`);const a=await this.getRpcProvider(),{chainId:o}=await a.detectNetwork();return{[i.numberToHex(o)]:{permissions:{supported:!0,signerTypes:["account","key"],keyTypes:["secp256k1"],permissionTypes:["contract-calls"]},paymasterService:{supported:!0},atomicBatch:{supported:!0}}}}case"eth_gasPrice":case"eth_getBalance":case"eth_sendRawTransaction":case"eth_getCode":case"eth_getStorageAt":case"eth_call":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":case"eth_getTransactionCount":return(await this.getRpcProvider()).send(s.method,s.params||[]);default:throw new h.JsonRpcError(h.ProviderErrorCode.UNSUPPORTED_METHOD,`${s.method}: Method not supported`)}}async request(t){try{return this.#p(t)}catch(t){if(t instanceof h.JsonRpcError)throw t;if(t instanceof Error)throw new h.JsonRpcError(h.RpcErrorCode.INTERNAL_ERROR,t.message);throw new h.JsonRpcError(h.RpcErrorCode.INTERNAL_ERROR,"Internal error")}}on(t,e){this.#s.on(t,e)}removeListener(t,e){this.#s.off(t,e)}};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PasskeyHandler as PasskeyHandler$1 } from 'core/configuration/passkey';
|
|
2
2
|
import { ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1 } from 'types';
|
|
3
|
+
import { Hex } from 'wallets/evm/types';
|
|
3
4
|
|
|
4
5
|
declare class TypedEventEmitter<T extends Record<string, any[]>> {
|
|
5
6
|
private emitter;
|
|
@@ -7286,6 +7287,7 @@ type OpenfortSDKConfiguration = {
|
|
|
7286
7287
|
shieldConfiguration?: ShieldConfiguration;
|
|
7287
7288
|
overrides?: SDKOverrides;
|
|
7288
7289
|
thirdPartyAuth?: ThirdPartyAuthConfiguration;
|
|
7290
|
+
debug?: boolean;
|
|
7289
7291
|
};
|
|
7290
7292
|
declare class SDKConfiguration {
|
|
7291
7293
|
readonly baseConfiguration: OpenfortConfiguration;
|
|
@@ -7298,8 +7300,9 @@ declare class SDKConfiguration {
|
|
|
7298
7300
|
readonly passkeyRpId?: string;
|
|
7299
7301
|
readonly passkeyRpName?: string;
|
|
7300
7302
|
readonly nativeAppIdentifier?: string;
|
|
7303
|
+
readonly debug?: boolean;
|
|
7301
7304
|
static instance: SDKConfiguration | null;
|
|
7302
|
-
constructor({ baseConfiguration, shieldConfiguration, overrides, thirdPartyAuth }: OpenfortSDKConfiguration);
|
|
7305
|
+
constructor({ baseConfiguration, shieldConfiguration, overrides, thirdPartyAuth, debug }: OpenfortSDKConfiguration);
|
|
7303
7306
|
static getInstance(): SDKConfiguration | null;
|
|
7304
7307
|
}
|
|
7305
7308
|
|
|
@@ -7491,6 +7494,26 @@ declare class OpenfortInternal {
|
|
|
7491
7494
|
validateAndRefreshToken(forceRefresh?: boolean): Promise<void>;
|
|
7492
7495
|
}
|
|
7493
7496
|
|
|
7497
|
+
declare class MissingRecoveryPasswordError extends Error {
|
|
7498
|
+
constructor();
|
|
7499
|
+
}
|
|
7500
|
+
declare class MissingProjectEntropyError extends Error {
|
|
7501
|
+
constructor();
|
|
7502
|
+
}
|
|
7503
|
+
declare class WrongRecoveryPasswordError extends Error {
|
|
7504
|
+
constructor();
|
|
7505
|
+
}
|
|
7506
|
+
declare class NotConfiguredError extends Error {
|
|
7507
|
+
constructor();
|
|
7508
|
+
}
|
|
7509
|
+
declare class OTPRequiredError extends Error {
|
|
7510
|
+
constructor();
|
|
7511
|
+
}
|
|
7512
|
+
|
|
7513
|
+
type RevokePermissionsRequestParams = {
|
|
7514
|
+
permissionContext: Hex;
|
|
7515
|
+
};
|
|
7516
|
+
|
|
7494
7517
|
/**
|
|
7495
7518
|
* Utility type for creating union types where only one property can be set at a time.
|
|
7496
7519
|
* This is useful for creating mutually exclusive options.
|
|
@@ -7667,22 +7690,6 @@ type GrantPermissionsReturnType = {
|
|
|
7667
7690
|
} | undefined;
|
|
7668
7691
|
};
|
|
7669
7692
|
|
|
7670
|
-
declare class MissingRecoveryPasswordError extends Error {
|
|
7671
|
-
constructor();
|
|
7672
|
-
}
|
|
7673
|
-
declare class MissingProjectEntropyError extends Error {
|
|
7674
|
-
constructor();
|
|
7675
|
-
}
|
|
7676
|
-
declare class WrongRecoveryPasswordError extends Error {
|
|
7677
|
-
constructor();
|
|
7678
|
-
}
|
|
7679
|
-
declare class NotConfiguredError extends Error {
|
|
7680
|
-
constructor();
|
|
7681
|
-
}
|
|
7682
|
-
declare class OTPRequiredError extends Error {
|
|
7683
|
-
constructor();
|
|
7684
|
-
}
|
|
7685
|
-
|
|
7686
7693
|
/**
|
|
7687
7694
|
* Global event emitter for subscribing to Openfort SDK events
|
|
7688
7695
|
*
|
|
@@ -7701,4 +7708,4 @@ declare class OTPRequiredError extends Error {
|
|
|
7701
7708
|
*/
|
|
7702
7709
|
declare const openfortEvents: TypedEventEmitter<OpenfortEventMap>;
|
|
7703
7710
|
|
|
7704
|
-
export { AccountTypeEnum, AuthActionRequiredActions, AuthActionRequiredResponse, AuthApi, AuthInitPayload, AuthPlayerResponse, AuthResponse, AuthType, BasicAuthProvider, ChainTypeEnum, EmbeddedAccount, EmbeddedState, EmbeddedWalletApi, GrantPermissionsParameters, GrantPermissionsReturnType, InitAuthResponse, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthProvider, OTPRequiredError, Openfort, OpenfortConfiguration, OpenfortError, OpenfortErrorType, OpenfortEventMap, OpenfortEvents, OpenfortInternal, OpenfortSDKConfiguration, Permission, Policy, Provider, ProxyApi, RecoveryMethod, RecoveryParams, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldConfiguration, ShieldOptions, SignedMessagePayload, Signer, IStorage as Storage, ThirdPartyAuthConfiguration, ThirdPartyAuthProvider as ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, UserApi, WrongRecoveryPasswordError, openfortEvents };
|
|
7711
|
+
export { AccountTypeEnum, AuthActionRequiredActions, AuthActionRequiredResponse, AuthApi, AuthInitPayload, AuthPlayerResponse, AuthResponse, AuthType, BasicAuthProvider, ChainTypeEnum, EmbeddedAccount, EmbeddedState, EmbeddedWalletApi, GrantPermissionsParameters, GrantPermissionsReturnType, InitAuthResponse, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthProvider, OTPRequiredError, Openfort, OpenfortConfiguration, OpenfortError, OpenfortErrorType, OpenfortEventMap, OpenfortEvents, OpenfortInternal, OpenfortSDKConfiguration, Permission, Policy, Provider, ProxyApi, RecoveryMethod, RecoveryParams, RevokePermissionsRequestParams, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldConfiguration, ShieldOptions, SignedMessagePayload, Signer, IStorage as Storage, ThirdPartyAuthConfiguration, ThirdPartyAuthProvider as ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, UserApi, WrongRecoveryPasswordError, openfortEvents };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{setCryptoDigestOverride as e}from"../../utils/crypto.js";class i{publishableKey;nativeAppIdentifier;constructor(e){this.publishableKey=e.publishableKey,this.nativeAppIdentifier=e.nativeAppIdentifier}}class s{shieldPublishableKey;shieldEncryptionKey;debug=!1;passkeyRpId;passkeyRpName;constructor(e){this.shieldPublishableKey=e.shieldPublishableKey,this.debug=e.shieldDebug||!1,this.passkeyRpId=e.passkeyRpId,this.passkeyRpName=e.passkeyRpName}}class t{baseConfiguration;shieldConfiguration;thirdPartyAuth;shieldUrl;iframeUrl;backendUrl;storage;passkeyRpId;passkeyRpName;nativeAppIdentifier;static instance=null;constructor({baseConfiguration:i,shieldConfiguration:s,overrides:a,thirdPartyAuth:r}){this.shieldConfiguration=s,this.baseConfiguration=i,this.backendUrl=a?.backendUrl||"https://api.openfort.io",this.iframeUrl=a?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,s?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=a?.shieldUrl||"https://shield.openfort.io",this.storage=a?.storage,this.thirdPartyAuth=r,this.passkeyRpId=s?.passkeyRpId,this.passkeyRpName=s?.passkeyRpName,this.nativeAppIdentifier=i.nativeAppIdentifier,a?.crypto?.digest&&e(a.crypto.digest),t.instance=this}static getInstance(){return t.instance}}export{i as OpenfortConfiguration,t as SDKConfiguration,s as ShieldConfiguration};
|
|
1
|
+
import{setCryptoDigestOverride as e}from"../../utils/crypto.js";class i{publishableKey;nativeAppIdentifier;constructor(e){this.publishableKey=e.publishableKey,this.nativeAppIdentifier=e.nativeAppIdentifier}}class s{shieldPublishableKey;shieldEncryptionKey;debug=!1;passkeyRpId;passkeyRpName;constructor(e){this.shieldPublishableKey=e.shieldPublishableKey,this.debug=e.shieldDebug||!1,this.passkeyRpId=e.passkeyRpId,this.passkeyRpName=e.passkeyRpName}}class t{baseConfiguration;shieldConfiguration;thirdPartyAuth;shieldUrl;iframeUrl;backendUrl;storage;passkeyRpId;passkeyRpName;nativeAppIdentifier;debug;static instance=null;constructor({baseConfiguration:i,shieldConfiguration:s,overrides:a,thirdPartyAuth:r,debug:p}){this.shieldConfiguration=s,this.baseConfiguration=i,this.backendUrl=a?.backendUrl||"https://api.openfort.io",this.iframeUrl=a?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,this.debug=p,s?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=a?.shieldUrl||"https://shield.openfort.io",this.storage=a?.storage,this.thirdPartyAuth=r,this.passkeyRpId=s?.passkeyRpId,this.passkeyRpName=s?.passkeyRpName,this.nativeAppIdentifier=i.nativeAppIdentifier,a?.crypto?.digest&&e(a.crypto.digest),t.instance=this}static getInstance(){return t.instance}}export{i as OpenfortConfiguration,t as SDKConfiguration,s as ShieldConfiguration};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SDKConfiguration as o}from"../core/config/config.js";function n(...n){const t=o.getInstance();t?.
|
|
1
|
+
import{SDKConfiguration as o}from"../core/config/config.js";function n(...n){const t=o.getInstance();t?.debug&&console.log(`${(new Date).toISOString()} [SDK]`,...n)}export{n as debugLog};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.10.
|
|
1
|
+
const o="0.10.32",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Account as t}from"../../core/configuration/account.js";import{Authentication as e}from"../../core/configuration/authentication.js";import{OpenfortEvents as a,AccountTypeEnum as
|
|
1
|
+
import{Account as t}from"../../core/configuration/account.js";import{Authentication as e}from"../../core/configuration/authentication.js";import{OpenfortEvents as a,AccountTypeEnum as i}from"../../types/types.js";import{defaultChainRpcs as s}from"../../utils/chains/index.js";import{numberToHex as r}from"../../utils/crypto.js";import o from"../../utils/typedEventEmitter.js";import{addEthereumChain as n}from"./addEthereumChain.js";import{estimateGas as c}from"./estimateGas.js";import{getCallStatus as h}from"./getCallsStatus.js";import{JsonRpcError as d,ProviderErrorCode as p,RpcErrorCode as m}from"./JsonRpcError.js";import{personalSign as w}from"./personalSign.js";import{registerSession as u}from"./registerSession.js";import{revokeSession as l}from"./revokeSession.js";import{sendCallsSync as g}from"./sendCallSync.js";import{sendCalls as f}from"./sendCalls.js";import{signTypedDataV4 as S}from"./signTypedDataV4.js";import{ProviderEvent as A}from"./types.js";import{prepareEOATransaction as R,parseTransactionRequest as _}from"./walletHelpers.js";class y{#t;#e;#a;#i;updatePolicy(t){this.#e=t}#s;#r;#o=null;#n;isOpenfort=!0;#c;constructor({storage:t,backendApiClients:e,openfortEventEmitter:i,policyId:s,ensureSigner:r,chains:n,validateAndRefreshSession:c}){this.#c=r,this.#t=t,this.#a=n,this.#e=s,this.#s=c,this.#n=e,this.#r=new o,i.on(a.ON_LOGOUT,this.#h),i.on(a.ON_SWITCH_ACCOUNT,this.#d)}#p=async()=>(this.#i||(this.#i=await this.#c()),this.#i);#h=async()=>{this.#i=void 0,this.#r.emit(A.ACCOUNTS_CHANGED,[])};#d=async t=>{this.#r.emit(A.ACCOUNTS_CHANGED,[t])};async getRpcProvider(){if(!this.#o){const e=await t.fromStorage(this.#t),a=e?.chainId||8453;await import("@ethersproject/providers").then(t=>{const e=this.#a?this.#a[a]:void 0;this.#o=new t.StaticJsonRpcProvider(e??s[a])})}if(!this.#o)throw new Error("RPC provider not initialized");return this.#o}async#m(a){switch(a.method){case"eth_accounts":{const e=await t.fromStorage(this.#t);return e?[e.address]:[]}case"eth_requestAccounts":{const e=await t.fromStorage(this.#t);if(e)return this.#r.emit(A.ACCOUNTS_CONNECT,{chainId:String(e.chainId)}),[e.address];throw new d(p.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer.")}case"eth_signTransaction":{const i=await t.fromStorage(this.#t),s=await this.#p(),r=await e.fromStorage(this.#t);if(!i||!r)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const o=await this.getRpcProvider(),{chainId:n}=await o.detectNetwork(),[c]=a.params||[];c.chainId||(c.chainId=n.toString());const h=_(c),{serialize:m}=await import("@ethersproject/transactions"),w=t=>({legacy:0,eip2930:1,eip1559:2}[t]),{gas:u,...l}=h,g={...l,gasLimit:u,to:h.to??void 0,type:w(h.type)},f=m(g),{keccak256:S}=await import("@ethersproject/keccak256"),A=S(f);await this.#s();const R=await s.sign(A,!1,!1),{splitSignature:y}=await import("@ethersproject/bytes");return m(g,y(R))}case"eth_sendTransaction":{const s=await t.fromStorage(this.#t),r=await this.#p(),o=await e.fromStorage(this.#t);if(!s||!o)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(await this.#s(),s?.accountType===i.EOA){const[t]=a.params||[],e=await this.getRpcProvider(),i=await R(t,e,s.address),r=await this.#m({method:"eth_signTransaction",params:[i]});return this.#m({method:"eth_sendRawTransaction",params:[r]})}return(await g({params:a.params||[],signer:r,account:s,authentication:o,backendClient:this.#n,policyId:this.#e})).receipt.transactionHash}case"eth_sendRawTransactionSync":{const s=await t.fromStorage(this.#t),r=await this.#p(),o=await e.fromStorage(this.#t);if(!s||!o)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");if(s?.accountType===i.EOA)throw new d(p.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);return await this.#s(),await g({params:a.params||[],signer:r,account:s,authentication:o,backendClient:this.#n,policyId:this.#e})}case"eth_estimateGas":{const i=await t.fromStorage(this.#t),s=await e.fromStorage(this.#t);if(!i||!s)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await c({params:a.params||[],account:i,authentication:s,backendClient:this.#n,policyId:this.#e})}case"eth_signTypedData":case"eth_signTypedData_v4":{const e=await t.fromStorage(this.#t),i=await this.#p();if(!e)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#s();const s=await this.getRpcProvider();return await S({method:a.method,params:a.params||[],signer:i,implementationType:e.implementationType||e.type,rpcProvider:s,account:e})}case"personal_sign":{const e=await t.fromStorage(this.#t);if(!e)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");const i=await this.#p();return await this.#s(),await w({params:a.params||[],signer:i,account:e})}case"eth_chainId":{const t=await this.getRpcProvider(),{chainId:e}=await t.detectNetwork();return r(e)}case"wallet_switchEthereumChain":{const t=await this.#p();if(!a.params||!Array.isArray(a.params)||0===a.params.length)throw new d(m.INVALID_PARAMS,"Invalid parameters for wallet_switchEthereumChain");await this.#s();try{const e=parseInt(a.params[0].chainId,16);await t.switchChain({chainId:e}),await import("@ethersproject/providers").then(t=>{const a=this.#a?this.#a[e]:void 0;this.#o=new t.StaticJsonRpcProvider(a??s[e])})}catch(t){const e=t;throw new d(m.INTERNAL_ERROR,`Failed to switch chain: ${e.message}`)}return null}case"wallet_addEthereumChain":{await this.#p();const t=await this.getRpcProvider();return await n({params:a.params||[],rpcProvider:t,storage:this.#t})}case"wallet_showCallsStatus":return null;case"wallet_getCallsStatus":{const s=await t.fromStorage(this.#t);if(s?.accountType===i.EOA)throw new d(p.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await e.fromStorage(this.#t);if(!s||!r)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await h({params:a.params||{},authentication:r,backendClient:this.#n})}case"wallet_sendCalls":{const s=await t.fromStorage(this.#t);if(s?.accountType===i.EOA)throw new d(p.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await this.#p(),o=await e.fromStorage(this.#t);if(!s||!o)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");await this.#s();return await f({params:a.params?a.params[0].calls:[],signer:r,account:s,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_grantPermissions":{const s=await t.fromStorage(this.#t);if(s?.accountType===i.EOA)throw new d(p.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const r=await this.#p(),o=await e.fromStorage(this.#t);if(!s||!o)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await u({params:a.params||[],signer:r,account:s,authentication:o,backendClient:this.#n,policyId:this.#e})}case"wallet_revokePermissions":{const i=await t.fromStorage(this.#t),s=await this.#p(),r=await e.fromStorage(this.#t);if(!i||!r)throw new d(p.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return await this.#s(),await l({params:a.params||[],signer:s,account:i,authentication:r,backendClient:this.#n,policyId:this.#e})}case"wallet_getCapabilities":{const e=await t.fromStorage(this.#t);if(e?.accountType===i.EOA)throw new d(p.UNSUPPORTED_METHOD,`${a.method}: Method not supported`);const s=await this.getRpcProvider(),{chainId:o}=await s.detectNetwork();return{[r(o)]:{permissions:{supported:!0,signerTypes:["account","key"],keyTypes:["secp256k1"],permissionTypes:["contract-calls"]},paymasterService:{supported:!0},atomicBatch:{supported:!0}}}}case"eth_gasPrice":case"eth_getBalance":case"eth_sendRawTransaction":case"eth_getCode":case"eth_getStorageAt":case"eth_call":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":case"eth_getTransactionCount":return(await this.getRpcProvider()).send(a.method,a.params||[]);default:throw new d(p.UNSUPPORTED_METHOD,`${a.method}: Method not supported`)}}async request(t){try{return this.#m(t)}catch(t){if(t instanceof d)throw t;if(t instanceof Error)throw new d(m.INTERNAL_ERROR,t.message);throw new d(m.INTERNAL_ERROR,"Internal error")}}on(t,e){this.#r.on(t,e)}removeListener(t,e){this.#r.off(t,e)}}export{y as EvmProvider};
|
package/package.json
CHANGED