@privy-io/js-sdk-core 0.52.9 → 0.53.0

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";var e=require("fetch-retry"),t=require("uuid"),s=require("@privy-io/api-base"),i=require("@privy-io/public-api"),r=require("../Error.js"),a=require("../Session.js"),n=require("../toAbortSignalTimeout.js"),o=require("../utils/toSearchParams.js"),h=require("./logger.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("eventemitter3"),require("jose"),require("js-cookie"),require("../Token.js"),require("../utils/allSettled.js"),require("../utils/noop.js");var c=/*#__PURE__*/l(e);let g="privy:caid";exports.PrivyInternal=class{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i.getPathWithParams(e.path,t)}${o.toSearchParams(s)}`}async fetch(e,{body:t,params:s,query:i,headers:a,onRequest:n=this._beforeRequest.bind(this)}){let o=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:a}),h=await n(o),l=await this._fetch(o,h),c=await l.json();if(l.status>299)throw new r.PrivyApiError(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:n.default(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(i.AppConfig,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(g);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t.v4()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(g,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(g)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(i.AnalyticsEvent,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let a=this._refreshSession(t,e);this._cache.set(s,a);try{return await a}finally{this._cache.delete(s)}}async _refreshSession(e,t){let a=await this.session.getToken();if(!this.session.hasRefreshCredentials(a,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new r.PrivyApiError({code:s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${i.RefreshSession.path}`);let s=await this.fetch(i.RefreshSession,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),r=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${r}`),t||this.callbacks?.setUser?.(s.user),"set"===r&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===r&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===r&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof r.PrivyApiError&&e.code===s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t.v4()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(e){this._sdkVersion="js-sdk-core:0.52.9",this._cache=new Map,this.logger=h.toConsoleLogger({level:e.logLevel??"ERROR"}),this._storage=e.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=e.baseUrl??"https://auth.privy.io",this.appId=e.appId,this.appClientId=e.appClientId,this._sdkVersion=e.sdkVersion??this._sdkVersion,this.callbacks=e.callbacks,this.nativeAppIdentifier=e.nativeAppIdentifier,this.session=new a.Session({storage:this._storage,isUsingServerCookies:!1,appId:e.appId}),this._fetch=c.default(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}};
1
+ "use strict";var e=require("fetch-retry"),t=require("uuid"),s=require("@privy-io/api-base"),i=require("@privy-io/public-api"),r=require("../Error.js"),a=require("../Session.js"),n=require("../toAbortSignalTimeout.js"),o=require("../utils/toSearchParams.js"),h=require("./logger.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("eventemitter3"),require("jose"),require("js-cookie"),require("../Token.js"),require("../utils/allSettled.js"),require("../utils/noop.js");var c=/*#__PURE__*/l(e);let g="privy:caid";exports.PrivyInternal=class{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i.getPathWithParams(e.path,t)}${o.toSearchParams(s)}`}async fetch(e,{body:t,params:s,query:i,headers:a,onRequest:n=this._beforeRequest.bind(this)}){let o=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:a}),h=await n(o),l=await this._fetch(o,h),c=await l.json();if(l.status>299)throw new r.PrivyApiError(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:n.default(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(i.AppConfig,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(g);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t.v4()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(g,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(g)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(i.AnalyticsEvent,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let a=this._refreshSession(t,e);this._cache.set(s,a);try{return await a}finally{this._cache.delete(s)}}async _refreshSession(e,t){let a=await this.session.getToken();if(!this.session.hasRefreshCredentials(a,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new r.PrivyApiError({code:s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${i.RefreshSession.path}`);let s=await this.fetch(i.RefreshSession,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),r=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${r}`),t||this.callbacks?.setUser?.(s.user),"set"===r&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===r&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===r&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof r.PrivyApiError&&e.code===s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t.v4()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(e){this._sdkVersion="js-sdk-core:0.53.0",this._cache=new Map,this.logger=h.toConsoleLogger({level:e.logLevel??"ERROR"}),this._storage=e.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=e.baseUrl??"https://auth.privy.io",this.appId=e.appId,this.appClientId=e.appClientId,this._sdkVersion=e.sdkVersion??this._sdkVersion,this.callbacks=e.callbacks,this.nativeAppIdentifier=e.nativeAppIdentifier,this.session=new a.Session({storage:this._storage,isUsingServerCookies:!1,appId:e.appId}),this._fetch=c.default(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}};
@@ -1 +1 @@
1
- "use strict";var e,t=require("../utils/sleep.js"),i=require("./EventCallbackQueue.js"),r=require("./errors.js"),a=require("./withMfa.js");require("./types.js");let s=(e=0,()=>"id-"+e++),o=(e,t)=>"bigint"==typeof t?t.toString():t,n=(e,{ms:i,msg:r})=>Promise.race([e,t.sleep(i??15e3).then((()=>Promise.reject(Error(r))))]),l=new i.EventCallbacksQueue;exports.DEFAULT_WALLET_PROXY_TIMEOUT_MS=15e3,exports.EmbeddedWalletProxy=class{invokeWithMfa(e,t){return n(a.withMfa((i=>n(this.waitForReady().then((()=>e(i))),{msg:t.timeoutMsg,ms:t.timeoutMs})),this.mfa.rootPromise,this.mfa.submitPromise,(()=>this.mfa.emit("mfaRequired")),t.mfaAlwaysRequired??!1,4,3e5),{msg:"Operation reached timeout: MFA verification",ms:126e4})}reload(){return this.ready=!1,this._embeddedWalletMessagePoster.reload()}ping(e=15e3){return n(this.invoke("privy:iframe:ready",{}),{msg:"Ping reached timeout",ms:e})}create(e){return n(this.waitForReady().then((()=>this.invoke("privy:wallet:create",e))),{msg:"Operation reached timeout: create"})}rpc(e){return this.invokeWithMfa((t=>this.invoke("privy:wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: rpc"})}createSolana(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}createAdditionalSolana(e){return n(this.waitForReady().then((()=>this.invoke("privy:solana-wallet:create-additional",e))),{msg:"Operation reached timeout: create"})}solanaRpc(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: solana-rpc"})}delegateWallets(e){return n(this.waitForReady().then((()=>this.invoke("privy:delegated-actions:consent",e))),{msg:"Operation reached timeout: delegated-actions:consent"})}verifyMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:verify",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:verify",mfaAlwaysRequired:!0})}initEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:init-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:init-enrollment"})}submitEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:submit-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:submit-enrollment"})}unenrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:unenroll",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:unenroll",mfaAlwaysRequired:!0})}clearMfa(e){return n(this.waitForReady().then((()=>this.invoke("privy:mfa:clear",e))),{msg:"Operation reached timeout: mfa:clear"})}createWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}signWithUserSigner(e){return this.invokeWithMfa((t=>this.invoke("privy:user-signer:sign",{...t,...e})),{timeoutMsg:"Operation reached timeout: user-signer:sign"})}addWallet(e){return n(this.waitForReady().then((()=>this.invoke("privy:wallets:add",e))),{msg:"Operation reached timeout: wallets:add"})}setRecovery(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:set-recovery",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:set-recovery",timeoutMs:6e4})}connect(e){return n(this.waitForReady().then((()=>this.invoke("privy:wallets:connect",e))),{msg:"Operation reached timeout: wallets:connect"})}recover(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:recover",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:recover",timeoutMs:6e4})}rpcWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:rpc"})}handleEmbeddedWalletMessages(e){let{reject:t,resolve:i}=l.dequeue(e.event,e.id);return void 0!==e.error?t(new r.PrivyIframeError(e.error.type,e.error.message)):i(e.data)}waitForReady(){return this.ready?Promise.resolve():new Promise((async(e,i)=>{for(;!this.ready;)this.invoke("privy:iframe:ready",{}).then((()=>{this.ready=!0,e()})).catch(i),await t.sleep(150)}))}invoke(e,t){let i=((e,t)=>`${e}${JSON.stringify(t,o)}`)(e,t);if("privy:wallet:create"===e||"privy:solana-wallet:create"===e){let e=this.cache.get(i);if(e)return e}let r=new Promise(((i,r)=>{let a=s();l.enqueue(a,{resolve:i,reject:r}),this._embeddedWalletMessagePoster.postMessage(JSON.stringify({id:a,event:e,data:t}),"*")})).finally((()=>{this.cache.delete(i)}));return this.cache.set(i,r),r}constructor(e,t){this.ready=!1,this.cache=new Map,this._embeddedWalletMessagePoster=e,this.mfa=t}};
1
+ "use strict";var e,t=require("../utils/sleep.js"),i=require("./EventCallbackQueue.js"),r=require("./errors.js"),a=require("./withMfa.js");require("./types.js");let s=(e=0,()=>"id-"+e++),o=(e,t)=>"bigint"==typeof t?t.toString():t,n=(e,{ms:i,msg:r})=>Promise.race([e,t.sleep(i??15e3).then((()=>Promise.reject(Error(r))))]),l=new i.EventCallbacksQueue;exports.DEFAULT_WALLET_PROXY_TIMEOUT_MS=15e3,exports.EmbeddedWalletProxy=class{invokeWithMfa(e,t){return n(a.withMfa((i=>n(this.waitForReady().then((()=>e(i))),{msg:t.timeoutMsg,ms:t.timeoutMs})),this.mfa.rootPromise,this.mfa.submitPromise,(()=>this.mfa.emit("mfaRequired")),t.mfaAlwaysRequired??!1,4,3e5),{msg:"Operation reached timeout: MFA verification",ms:126e4})}reload(){return this.ready=!1,this._embeddedWalletMessagePoster.reload()}ping(e=15e3){return n(this.invoke("privy:iframe:ready",{}),{msg:"Ping reached timeout",ms:e})}create(e){return n(this.waitForReady().then((()=>this.invoke("privy:wallet:create",e))),{msg:"Operation reached timeout: create"})}rpc(e){return this.invokeWithMfa((t=>this.invoke("privy:wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: rpc"})}createSolana(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}createAdditionalSolana(e){return n(this.waitForReady().then((()=>this.invoke("privy:solana-wallet:create-additional",e))),{msg:"Operation reached timeout: create"})}solanaRpc(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: solana-rpc"})}delegateWallets(e){return this.invokeWithMfa((t=>this.invoke("privy:delegated-actions:consent",{...t,...e})),{timeoutMsg:"Operation reached timeout: delegated-actions:consent"})}verifyMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:verify",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:verify",mfaAlwaysRequired:!0})}initEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:init-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:init-enrollment"})}submitEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:submit-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:submit-enrollment"})}unenrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:unenroll",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:unenroll",mfaAlwaysRequired:!0})}clearMfa(e){return n(this.waitForReady().then((()=>this.invoke("privy:mfa:clear",e))),{msg:"Operation reached timeout: mfa:clear"})}createWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}signWithUserSigner(e){return this.invokeWithMfa((t=>this.invoke("privy:user-signer:sign",{...t,...e})),{timeoutMsg:"Operation reached timeout: user-signer:sign"})}addWallet(e){return n(this.waitForReady().then((()=>this.invoke("privy:wallets:add",e))),{msg:"Operation reached timeout: wallets:add"})}setRecovery(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:set-recovery",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:set-recovery",timeoutMs:6e4})}connect(e){return n(this.waitForReady().then((()=>this.invoke("privy:wallets:connect",e))),{msg:"Operation reached timeout: wallets:connect"})}recover(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:recover",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:recover",timeoutMs:6e4})}rpcWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:rpc"})}handleEmbeddedWalletMessages(e){let{reject:t,resolve:i}=l.dequeue(e.event,e.id);return void 0!==e.error?t(new r.PrivyIframeError(e.error.type,e.error.message)):i(e.data)}waitForReady(){return this.ready?Promise.resolve():new Promise((async(e,i)=>{for(;!this.ready;)this.invoke("privy:iframe:ready",{}).then((()=>{this.ready=!0,e()})).catch(i),await t.sleep(150)}))}invoke(e,t){let i=((e,t)=>`${e}${JSON.stringify(t,o)}`)(e,t);if("privy:wallet:create"===e||"privy:solana-wallet:create"===e){let e=this.cache.get(i);if(e)return e}let r=new Promise(((i,r)=>{let a=s();l.enqueue(a,{resolve:i,reject:r}),this._embeddedWalletMessagePoster.postMessage(JSON.stringify({id:a,event:e,data:t}),"*")})).finally((()=>{this.cache.delete(i)}));return this.cache.set(i,r),r}constructor(e,t){this.ready=!1,this.cache=new Map,this._embeddedWalletMessagePoster=e,this.mfa=t}};
@@ -1 +1 @@
1
- "use strict";var e=require("permissionless"),t=require("permissionless/accounts"),r=require("permissionless/clients/pimlico"),n=require("viem"),i=require("viem/account-abstraction"),a=require("@privy-io/public-api");let o={address:i.entryPoint06Address,version:"0.6"},s={address:i.entryPoint07Address,version:"0.7"},c=({owner:e,smartWalletType:r,publicClient:n})=>{switch(r){case a.SAFE:return t.toSafeSmartAccount({client:n,entryPoint:s,owners:[e],version:"1.4.1"});case a.KERNEL:return t.toKernelSmartAccount({client:n,version:"0.3.1",entryPoint:s,useMetaFactory:"optional",owners:[e]});case a.BICONOMY:return t.toBiconomySmartAccount({client:n,owners:[e],entryPoint:o});case a.LIGHT_ACCOUNT:return t.toLightSmartAccount({client:n,entryPoint:o,owner:e,version:"1.1.0"});case a.COINBASE_SMART_WALLET:return async function({client:e,owner:t}){let[r]=await t.request({method:"eth_accounts"});if(!r)throw Error("Unable to request embedded owner for eth_accounts");return await i.toCoinbaseSmartAccount({client:e,version:"1",owners:[{type:"local",source:"privy",address:r,sign:async({hash:e})=>await t.request({method:"secp256k1_sign",params:[e]})}]})}({client:n,owner:e});case a.THIRDWEB:return t.toThirdwebSmartAccount({client:n,entryPoint:s,owner:e});default:throw Error(`Invalid smart account type: ${r}.`)}};exports.signerToSmartAccountClient=async({owner:t,smartWalletType:i,chain:a,publicClient:o,bundlerUrl:s,paymasterUrl:l,paymasterContext:u})=>{let m=await c({owner:t,smartWalletType:i,publicClient:o}),p=r.createPimlicoClient({transport:n.http(s),entryPoint:m.entryPoint}),y=l?r.createPimlicoClient({transport:n.http(l),entryPoint:m.entryPoint}):void 0;return e.createSmartAccountClient({account:m,chain:a,paymaster:y,paymasterContext:u,bundlerTransport:n.http(s),userOperation:{estimateFeesPerGas:async()=>{if(["public.pimlico.io","api.pimlico.io"].some((e=>s.includes(e))))return await p.getUserOperationGasPrice().then((e=>e.fast));if(["rpc.zerodev.app"].some((e=>s.includes(e))))return(await p.request({method:"zd_getUserOperationGasPrice",params:[]})).fast;if(["g.alchemy.com"].some((e=>s.includes(e)))){let[e,t]=await Promise.all([o.getBlock({blockTag:"latest"}),p.request({method:"rundler_maxPriorityFeePerGas",params:[]})]);if(!e.baseFeePerGas||!t)throw Error("Failed to get block or maxPriorityFeePerGasEstimate");return{maxFeePerGas:150n*e.baseFeePerGas/100n+BigInt(t.toString()),maxPriorityFeePerGas:BigInt(t.toString())}}{let e=await o.estimateFeesPerGas(),t=s.includes("api.developer.coinbase.com")?175n:150n;return{...e,maxFeePerGas:e.maxFeePerGas*t/100n,maxPriorityFeePerGas:e.maxPriorityFeePerGas*t/100n}}}}})};
1
+ "use strict";var e=require("permissionless"),t=require("permissionless/accounts"),r=require("permissionless/clients/pimlico"),n=require("viem"),a=require("viem/account-abstraction"),i=require("@privy-io/public-api");let s={address:a.entryPoint06Address,version:"0.6"},o={address:a.entryPoint07Address,version:"0.7"},c=({owner:e,smartWalletType:r,smartWalletVersion:n,publicClient:c})=>{switch(r){case i.SAFE:return t.toSafeSmartAccount({client:c,entryPoint:o,owners:[e],version:"1.4.1"});case i.KERNEL:return t.toKernelSmartAccount({client:c,version:"0.3.1",entryPoint:o,useMetaFactory:"optional",owners:[e]});case i.BICONOMY:return t.toBiconomySmartAccount({client:c,owners:[e],entryPoint:s});case i.LIGHT_ACCOUNT:return t.toLightSmartAccount({client:c,entryPoint:s,owner:e,version:"1.1.0"});case i.COINBASE_SMART_WALLET:return async function({client:e,owner:t,version:r}){let[n]=await t.request({method:"eth_accounts"});if(!n)throw Error("Unable to request embedded owner for eth_accounts");return await a.toCoinbaseSmartAccount({client:e,owners:[{type:"local",source:"privy",address:n,sign:async({hash:e})=>await t.request({method:"secp256k1_sign",params:[e]})}],version:r})}({client:c,owner:e,version:n??"1"});case i.THIRDWEB:return t.toThirdwebSmartAccount({client:c,entryPoint:o,owner:e});default:throw Error(`Invalid smart account type: ${r}.`)}};exports.signerToSmartAccountClient=async({owner:t,smartWalletType:a,smartWalletVersion:i,chain:s,publicClient:o,bundlerUrl:l,paymasterUrl:m,paymasterContext:u})=>{let p=await c({owner:t,smartWalletType:a,smartWalletVersion:i,publicClient:o}),y=r.createPimlicoClient({transport:n.http(l),entryPoint:p.entryPoint}),P=m?r.createPimlicoClient({transport:n.http(m),entryPoint:p.entryPoint}):void 0;return e.createSmartAccountClient({account:p,chain:s,paymaster:P,paymasterContext:u,bundlerTransport:n.http(l),userOperation:{estimateFeesPerGas:async()=>{if(["public.pimlico.io","api.pimlico.io"].some((e=>l.includes(e))))return await y.getUserOperationGasPrice().then((e=>e.fast));if(["rpc.zerodev.app"].some((e=>l.includes(e))))return(await y.request({method:"zd_getUserOperationGasPrice",params:[]})).fast;if(["g.alchemy.com"].some((e=>l.includes(e)))){let[e,t]=await Promise.all([o.getBlock({blockTag:"latest"}),y.request({method:"rundler_maxPriorityFeePerGas",params:[]})]);if(!e.baseFeePerGas||!t)throw Error("Failed to get block or maxPriorityFeePerGasEstimate");return{maxFeePerGas:150n*e.baseFeePerGas/100n+BigInt(t.toString()),maxPriorityFeePerGas:BigInt(t.toString())}}{let e=await o.estimateFeesPerGas(),t=l.includes("api.developer.coinbase.com")?175n:150n;return{...e,maxFeePerGas:e.maxFeePerGas*t/100n,maxPriorityFeePerGas:e.maxPriorityFeePerGas*t/100n}}}}})};
@@ -1048,6 +1048,7 @@ declare class EmbeddedWalletApi {
1048
1048
  verified_at: number;
1049
1049
  first_verified_at: number | null;
1050
1050
  latest_verified_at: number | null;
1051
+ smart_wallet_version?: string | undefined;
1051
1052
  } | {
1052
1053
  type: "wallet";
1053
1054
  address: string;
@@ -1486,6 +1487,7 @@ declare class UserApi {
1486
1487
  verified_at: number;
1487
1488
  first_verified_at: number | null;
1488
1489
  latest_verified_at: number | null;
1490
+ smart_wallet_version?: string | undefined;
1489
1491
  } | {
1490
1492
  type: "wallet";
1491
1493
  address: string;
@@ -1821,6 +1823,7 @@ declare class EmailApi {
1821
1823
  verified_at: number;
1822
1824
  first_verified_at: number | null;
1823
1825
  latest_verified_at: number | null;
1826
+ smart_wallet_version?: string | undefined;
1824
1827
  } | {
1825
1828
  type: "wallet";
1826
1829
  address: string;
@@ -2121,6 +2124,7 @@ declare class EmailApi {
2121
2124
  verified_at: number;
2122
2125
  first_verified_at: number | null;
2123
2126
  latest_verified_at: number | null;
2127
+ smart_wallet_version?: string | undefined;
2124
2128
  } | {
2125
2129
  type: "wallet";
2126
2130
  address: string;
@@ -2410,6 +2414,7 @@ declare class EmailApi {
2410
2414
  verified_at: number;
2411
2415
  first_verified_at: number | null;
2412
2416
  latest_verified_at: number | null;
2417
+ smart_wallet_version?: string | undefined;
2413
2418
  } | {
2414
2419
  type: "wallet";
2415
2420
  address: string;
@@ -2734,6 +2739,7 @@ declare class FarcasterApi {
2734
2739
  verified_at: number;
2735
2740
  first_verified_at: number | null;
2736
2741
  latest_verified_at: number | null;
2742
+ smart_wallet_version?: string | undefined;
2737
2743
  } | {
2738
2744
  type: "wallet";
2739
2745
  address: string;
@@ -3028,6 +3034,7 @@ declare class FarcasterApi {
3028
3034
  verified_at: number;
3029
3035
  first_verified_at: number | null;
3030
3036
  latest_verified_at: number | null;
3037
+ smart_wallet_version?: string | undefined;
3031
3038
  } | {
3032
3039
  type: "wallet";
3033
3040
  address: string;
@@ -3370,6 +3377,7 @@ declare class OAuthApi {
3370
3377
  verified_at: number;
3371
3378
  first_verified_at: number | null;
3372
3379
  latest_verified_at: number | null;
3380
+ smart_wallet_version?: string | undefined;
3373
3381
  } | {
3374
3382
  type: "wallet";
3375
3383
  address: string;
@@ -3665,6 +3673,7 @@ declare class OAuthApi {
3665
3673
  verified_at: number;
3666
3674
  first_verified_at: number | null;
3667
3675
  latest_verified_at: number | null;
3676
+ smart_wallet_version?: string | undefined;
3668
3677
  } | {
3669
3678
  type: "wallet";
3670
3679
  address: string;
@@ -4080,6 +4089,7 @@ declare class PasskeyApi {
4080
4089
  verified_at: number;
4081
4090
  first_verified_at: number | null;
4082
4091
  latest_verified_at: number | null;
4092
+ smart_wallet_version?: string | undefined;
4083
4093
  } | {
4084
4094
  type: "wallet";
4085
4095
  address: string;
@@ -4395,6 +4405,7 @@ declare class PhoneApi {
4395
4405
  verified_at: number;
4396
4406
  first_verified_at: number | null;
4397
4407
  latest_verified_at: number | null;
4408
+ smart_wallet_version?: string | undefined;
4398
4409
  } | {
4399
4410
  type: "wallet";
4400
4411
  address: string;
@@ -4695,6 +4706,7 @@ declare class PhoneApi {
4695
4706
  verified_at: number;
4696
4707
  first_verified_at: number | null;
4697
4708
  latest_verified_at: number | null;
4709
+ smart_wallet_version?: string | undefined;
4698
4710
  } | {
4699
4711
  type: "wallet";
4700
4712
  address: string;
@@ -4984,6 +4996,7 @@ declare class PhoneApi {
4984
4996
  verified_at: number;
4985
4997
  first_verified_at: number | null;
4986
4998
  latest_verified_at: number | null;
4999
+ smart_wallet_version?: string | undefined;
4987
5000
  } | {
4988
5001
  type: "wallet";
4989
5002
  address: string;
@@ -5344,6 +5357,7 @@ declare class SiweApi {
5344
5357
  verified_at: number;
5345
5358
  first_verified_at: number | null;
5346
5359
  latest_verified_at: number | null;
5360
+ smart_wallet_version?: string | undefined;
5347
5361
  } | {
5348
5362
  type: "wallet";
5349
5363
  address: string;
@@ -5650,6 +5664,7 @@ declare class SiweApi {
5650
5664
  verified_at: number;
5651
5665
  first_verified_at: number | null;
5652
5666
  latest_verified_at: number | null;
5667
+ smart_wallet_version?: string | undefined;
5653
5668
  } | {
5654
5669
  type: "wallet";
5655
5670
  address: string;
@@ -5989,6 +6004,7 @@ declare class SiwsApi {
5989
6004
  verified_at: number;
5990
6005
  first_verified_at: number | null;
5991
6006
  latest_verified_at: number | null;
6007
+ smart_wallet_version?: string | undefined;
5992
6008
  } | {
5993
6009
  type: "wallet";
5994
6010
  address: string;
@@ -6300,6 +6316,7 @@ declare class SiwsApi {
6300
6316
  verified_at: number;
6301
6317
  first_verified_at: number | null;
6302
6318
  latest_verified_at: number | null;
6319
+ smart_wallet_version?: string | undefined;
6303
6320
  } | {
6304
6321
  type: "wallet";
6305
6322
  address: string;
@@ -6646,6 +6663,7 @@ declare class SmartWalletApi {
6646
6663
  verified_at: number;
6647
6664
  first_verified_at: number | null;
6648
6665
  latest_verified_at: number | null;
6666
+ smart_wallet_version?: string | undefined;
6649
6667
  } | {
6650
6668
  type: "wallet";
6651
6669
  address: string;
@@ -7678,6 +7696,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7678
7696
  verified_at: number;
7679
7697
  first_verified_at: number | null;
7680
7698
  latest_verified_at: number | null;
7699
+ smart_wallet_version?: string | undefined;
7681
7700
  } | {
7682
7701
  type: "wallet";
7683
7702
  address: string;
@@ -7975,6 +7994,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
7975
7994
  verified_at: number;
7976
7995
  first_verified_at: number | null;
7977
7996
  latest_verified_at: number | null;
7997
+ smart_wallet_version?: string | undefined;
7978
7998
  } | {
7979
7999
  type: "wallet";
7980
8000
  address: string;
@@ -1048,6 +1048,7 @@ declare class EmbeddedWalletApi {
1048
1048
  verified_at: number;
1049
1049
  first_verified_at: number | null;
1050
1050
  latest_verified_at: number | null;
1051
+ smart_wallet_version?: string | undefined;
1051
1052
  } | {
1052
1053
  type: "wallet";
1053
1054
  address: string;
@@ -1486,6 +1487,7 @@ declare class UserApi {
1486
1487
  verified_at: number;
1487
1488
  first_verified_at: number | null;
1488
1489
  latest_verified_at: number | null;
1490
+ smart_wallet_version?: string | undefined;
1489
1491
  } | {
1490
1492
  type: "wallet";
1491
1493
  address: string;
@@ -1821,6 +1823,7 @@ declare class EmailApi {
1821
1823
  verified_at: number;
1822
1824
  first_verified_at: number | null;
1823
1825
  latest_verified_at: number | null;
1826
+ smart_wallet_version?: string | undefined;
1824
1827
  } | {
1825
1828
  type: "wallet";
1826
1829
  address: string;
@@ -2121,6 +2124,7 @@ declare class EmailApi {
2121
2124
  verified_at: number;
2122
2125
  first_verified_at: number | null;
2123
2126
  latest_verified_at: number | null;
2127
+ smart_wallet_version?: string | undefined;
2124
2128
  } | {
2125
2129
  type: "wallet";
2126
2130
  address: string;
@@ -2410,6 +2414,7 @@ declare class EmailApi {
2410
2414
  verified_at: number;
2411
2415
  first_verified_at: number | null;
2412
2416
  latest_verified_at: number | null;
2417
+ smart_wallet_version?: string | undefined;
2413
2418
  } | {
2414
2419
  type: "wallet";
2415
2420
  address: string;
@@ -2734,6 +2739,7 @@ declare class FarcasterApi {
2734
2739
  verified_at: number;
2735
2740
  first_verified_at: number | null;
2736
2741
  latest_verified_at: number | null;
2742
+ smart_wallet_version?: string | undefined;
2737
2743
  } | {
2738
2744
  type: "wallet";
2739
2745
  address: string;
@@ -3028,6 +3034,7 @@ declare class FarcasterApi {
3028
3034
  verified_at: number;
3029
3035
  first_verified_at: number | null;
3030
3036
  latest_verified_at: number | null;
3037
+ smart_wallet_version?: string | undefined;
3031
3038
  } | {
3032
3039
  type: "wallet";
3033
3040
  address: string;
@@ -3370,6 +3377,7 @@ declare class OAuthApi {
3370
3377
  verified_at: number;
3371
3378
  first_verified_at: number | null;
3372
3379
  latest_verified_at: number | null;
3380
+ smart_wallet_version?: string | undefined;
3373
3381
  } | {
3374
3382
  type: "wallet";
3375
3383
  address: string;
@@ -3665,6 +3673,7 @@ declare class OAuthApi {
3665
3673
  verified_at: number;
3666
3674
  first_verified_at: number | null;
3667
3675
  latest_verified_at: number | null;
3676
+ smart_wallet_version?: string | undefined;
3668
3677
  } | {
3669
3678
  type: "wallet";
3670
3679
  address: string;
@@ -4080,6 +4089,7 @@ declare class PasskeyApi {
4080
4089
  verified_at: number;
4081
4090
  first_verified_at: number | null;
4082
4091
  latest_verified_at: number | null;
4092
+ smart_wallet_version?: string | undefined;
4083
4093
  } | {
4084
4094
  type: "wallet";
4085
4095
  address: string;
@@ -4395,6 +4405,7 @@ declare class PhoneApi {
4395
4405
  verified_at: number;
4396
4406
  first_verified_at: number | null;
4397
4407
  latest_verified_at: number | null;
4408
+ smart_wallet_version?: string | undefined;
4398
4409
  } | {
4399
4410
  type: "wallet";
4400
4411
  address: string;
@@ -4695,6 +4706,7 @@ declare class PhoneApi {
4695
4706
  verified_at: number;
4696
4707
  first_verified_at: number | null;
4697
4708
  latest_verified_at: number | null;
4709
+ smart_wallet_version?: string | undefined;
4698
4710
  } | {
4699
4711
  type: "wallet";
4700
4712
  address: string;
@@ -4984,6 +4996,7 @@ declare class PhoneApi {
4984
4996
  verified_at: number;
4985
4997
  first_verified_at: number | null;
4986
4998
  latest_verified_at: number | null;
4999
+ smart_wallet_version?: string | undefined;
4987
5000
  } | {
4988
5001
  type: "wallet";
4989
5002
  address: string;
@@ -5344,6 +5357,7 @@ declare class SiweApi {
5344
5357
  verified_at: number;
5345
5358
  first_verified_at: number | null;
5346
5359
  latest_verified_at: number | null;
5360
+ smart_wallet_version?: string | undefined;
5347
5361
  } | {
5348
5362
  type: "wallet";
5349
5363
  address: string;
@@ -5650,6 +5664,7 @@ declare class SiweApi {
5650
5664
  verified_at: number;
5651
5665
  first_verified_at: number | null;
5652
5666
  latest_verified_at: number | null;
5667
+ smart_wallet_version?: string | undefined;
5653
5668
  } | {
5654
5669
  type: "wallet";
5655
5670
  address: string;
@@ -5989,6 +6004,7 @@ declare class SiwsApi {
5989
6004
  verified_at: number;
5990
6005
  first_verified_at: number | null;
5991
6006
  latest_verified_at: number | null;
6007
+ smart_wallet_version?: string | undefined;
5992
6008
  } | {
5993
6009
  type: "wallet";
5994
6010
  address: string;
@@ -6300,6 +6316,7 @@ declare class SiwsApi {
6300
6316
  verified_at: number;
6301
6317
  first_verified_at: number | null;
6302
6318
  latest_verified_at: number | null;
6319
+ smart_wallet_version?: string | undefined;
6303
6320
  } | {
6304
6321
  type: "wallet";
6305
6322
  address: string;
@@ -6646,6 +6663,7 @@ declare class SmartWalletApi {
6646
6663
  verified_at: number;
6647
6664
  first_verified_at: number | null;
6648
6665
  latest_verified_at: number | null;
6666
+ smart_wallet_version?: string | undefined;
6649
6667
  } | {
6650
6668
  type: "wallet";
6651
6669
  address: string;
@@ -7678,6 +7696,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7678
7696
  verified_at: number;
7679
7697
  first_verified_at: number | null;
7680
7698
  latest_verified_at: number | null;
7699
+ smart_wallet_version?: string | undefined;
7681
7700
  } | {
7682
7701
  type: "wallet";
7683
7702
  address: string;
@@ -7975,6 +7994,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
7975
7994
  verified_at: number;
7976
7995
  first_verified_at: number | null;
7977
7996
  latest_verified_at: number | null;
7997
+ smart_wallet_version?: string | undefined;
7978
7998
  } | {
7979
7999
  type: "wallet";
7980
8000
  address: string;
@@ -8,9 +8,10 @@ type Call = {
8
8
  readonly value?: any;
9
9
  readonly data?: any;
10
10
  };
11
- declare const signerToSmartAccountClient: <chain extends Chain>({ owner, smartWalletType, chain, publicClient, bundlerUrl, paymasterUrl, paymasterContext, }: {
11
+ declare const signerToSmartAccountClient: <chain extends Chain>({ owner, smartWalletType, smartWalletVersion, chain, publicClient, bundlerUrl, paymasterUrl, paymasterContext, }: {
12
12
  owner: EIP1193Provider;
13
13
  smartWalletType: SmartWalletType;
14
+ smartWalletVersion?: string;
14
15
  chain: chain;
15
16
  publicClient: PublicClient;
16
17
  bundlerUrl: string;
@@ -8,9 +8,10 @@ type Call = {
8
8
  readonly value?: any;
9
9
  readonly data?: any;
10
10
  };
11
- declare const signerToSmartAccountClient: <chain extends Chain>({ owner, smartWalletType, chain, publicClient, bundlerUrl, paymasterUrl, paymasterContext, }: {
11
+ declare const signerToSmartAccountClient: <chain extends Chain>({ owner, smartWalletType, smartWalletVersion, chain, publicClient, bundlerUrl, paymasterUrl, paymasterContext, }: {
12
12
  owner: EIP1193Provider;
13
13
  smartWalletType: SmartWalletType;
14
+ smartWalletVersion?: string;
14
15
  chain: chain;
15
16
  publicClient: PublicClient;
16
17
  bundlerUrl: string;
@@ -1 +1 @@
1
- import e from"fetch-retry";import{v4 as t}from"uuid";import{PrivyErrorCode as s}from"@privy-io/api-base";import{getPathWithParams as i,AppConfig as r,AnalyticsEvent as a,RefreshSession as n}from"@privy-io/public-api";import{PrivyClientError as o,PrivyApiError as h}from"../Error.mjs";import{Session as l}from"../Session.mjs";import c from"../toAbortSignalTimeout.mjs";import{toSearchParams as g}from"../utils/toSearchParams.mjs";import{toConsoleLogger as d}from"./logger.mjs";import"eventemitter3";import"jose";import"js-cookie";import"../Token.mjs";import"../utils/allSettled.mjs";import"../utils/noop.mjs";let p="privy:caid";class u{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i(e.path,t)}${g(s)}`}async fetch(e,{body:t,params:s,query:i,headers:r,onRequest:a=this._beforeRequest.bind(this)}){let n=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:r}),o=await a(n),l=await this._fetch(n,o),c=await l.json();if(l.status>299)throw new h(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:c(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(r,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(p);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(p,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(p)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(a,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let r=this._refreshSession(t,e);this._cache.set(s,r);try{return await r}finally{this._cache.delete(s)}}async _refreshSession(e,t){let i=await this.session.getToken();if(!this.session.hasRefreshCredentials(i,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new h({code:s.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${n.path}`);let s=await this.fetch(n,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),i=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${i}`),t||this.callbacks?.setUser?.(s.user),"set"===i&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===i&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===i&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof h&&e.code===s.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(t){this._sdkVersion="js-sdk-core:0.52.9",this._cache=new Map,this.logger=d({level:t.logLevel??"ERROR"}),this._storage=t.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=t.baseUrl??"https://auth.privy.io",this.appId=t.appId,this.appClientId=t.appClientId,this._sdkVersion=t.sdkVersion??this._sdkVersion,this.callbacks=t.callbacks,this.nativeAppIdentifier=t.nativeAppIdentifier,this.session=new l({storage:this._storage,isUsingServerCookies:!1,appId:t.appId}),this._fetch=e(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}}export{u as PrivyInternal};
1
+ import e from"fetch-retry";import{v4 as t}from"uuid";import{PrivyErrorCode as s}from"@privy-io/api-base";import{getPathWithParams as i,AppConfig as r,AnalyticsEvent as a,RefreshSession as n}from"@privy-io/public-api";import{PrivyClientError as o,PrivyApiError as h}from"../Error.mjs";import{Session as l}from"../Session.mjs";import c from"../toAbortSignalTimeout.mjs";import{toSearchParams as g}from"../utils/toSearchParams.mjs";import{toConsoleLogger as d}from"./logger.mjs";import"eventemitter3";import"jose";import"js-cookie";import"../Token.mjs";import"../utils/allSettled.mjs";import"../utils/noop.mjs";let p="privy:caid";class u{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i(e.path,t)}${g(s)}`}async fetch(e,{body:t,params:s,query:i,headers:r,onRequest:a=this._beforeRequest.bind(this)}){let n=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:r}),o=await a(n),l=await this._fetch(n,o),c=await l.json();if(l.status>299)throw new h(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:c(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(r,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(p);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(p,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(p)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(a,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let r=this._refreshSession(t,e);this._cache.set(s,r);try{return await r}finally{this._cache.delete(s)}}async _refreshSession(e,t){let i=await this.session.getToken();if(!this.session.hasRefreshCredentials(i,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new h({code:s.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${n.path}`);let s=await this.fetch(n,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),i=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${i}`),t||this.callbacks?.setUser?.(s.user),"set"===i&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===i&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===i&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof h&&e.code===s.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(t){this._sdkVersion="js-sdk-core:0.53.0",this._cache=new Map,this.logger=d({level:t.logLevel??"ERROR"}),this._storage=t.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=t.baseUrl??"https://auth.privy.io",this.appId=t.appId,this.appClientId=t.appClientId,this._sdkVersion=t.sdkVersion??this._sdkVersion,this.callbacks=t.callbacks,this.nativeAppIdentifier=t.nativeAppIdentifier,this.session=new l({storage:this._storage,isUsingServerCookies:!1,appId:t.appId}),this._fetch=e(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}}export{u as PrivyInternal};
@@ -1 +1 @@
1
- import{sleep as e}from"../utils/sleep.mjs";import{EventCallbacksQueue as t}from"./EventCallbackQueue.mjs";import{PrivyIframeError as i}from"./errors.mjs";import{withMfa as r}from"./withMfa.mjs";import"./types.mjs";var a;const o=15e3;let s=(a=0,()=>"id-"+a++),n=(e,t)=>"bigint"==typeof t?t.toString():t,l=(t,{ms:i,msg:r})=>Promise.race([t,e(i??15e3).then((()=>Promise.reject(Error(r))))]),m=new t;class h{invokeWithMfa(e,t){return l(r((i=>l(this.waitForReady().then((()=>e(i))),{msg:t.timeoutMsg,ms:t.timeoutMs})),this.mfa.rootPromise,this.mfa.submitPromise,(()=>this.mfa.emit("mfaRequired")),t.mfaAlwaysRequired??!1,4,3e5),{msg:"Operation reached timeout: MFA verification",ms:126e4})}reload(){return this.ready=!1,this._embeddedWalletMessagePoster.reload()}ping(e=15e3){return l(this.invoke("privy:iframe:ready",{}),{msg:"Ping reached timeout",ms:e})}create(e){return l(this.waitForReady().then((()=>this.invoke("privy:wallet:create",e))),{msg:"Operation reached timeout: create"})}rpc(e){return this.invokeWithMfa((t=>this.invoke("privy:wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: rpc"})}createSolana(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}createAdditionalSolana(e){return l(this.waitForReady().then((()=>this.invoke("privy:solana-wallet:create-additional",e))),{msg:"Operation reached timeout: create"})}solanaRpc(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: solana-rpc"})}delegateWallets(e){return l(this.waitForReady().then((()=>this.invoke("privy:delegated-actions:consent",e))),{msg:"Operation reached timeout: delegated-actions:consent"})}verifyMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:verify",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:verify",mfaAlwaysRequired:!0})}initEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:init-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:init-enrollment"})}submitEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:submit-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:submit-enrollment"})}unenrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:unenroll",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:unenroll",mfaAlwaysRequired:!0})}clearMfa(e){return l(this.waitForReady().then((()=>this.invoke("privy:mfa:clear",e))),{msg:"Operation reached timeout: mfa:clear"})}createWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}signWithUserSigner(e){return this.invokeWithMfa((t=>this.invoke("privy:user-signer:sign",{...t,...e})),{timeoutMsg:"Operation reached timeout: user-signer:sign"})}addWallet(e){return l(this.waitForReady().then((()=>this.invoke("privy:wallets:add",e))),{msg:"Operation reached timeout: wallets:add"})}setRecovery(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:set-recovery",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:set-recovery",timeoutMs:6e4})}connect(e){return l(this.waitForReady().then((()=>this.invoke("privy:wallets:connect",e))),{msg:"Operation reached timeout: wallets:connect"})}recover(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:recover",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:recover",timeoutMs:6e4})}rpcWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:rpc"})}handleEmbeddedWalletMessages(e){let{reject:t,resolve:r}=m.dequeue(e.event,e.id);return void 0!==e.error?t(new i(e.error.type,e.error.message)):r(e.data)}waitForReady(){return this.ready?Promise.resolve():new Promise((async(t,i)=>{for(;!this.ready;)this.invoke("privy:iframe:ready",{}).then((()=>{this.ready=!0,t()})).catch(i),await e(150)}))}invoke(e,t){let i=((e,t)=>`${e}${JSON.stringify(t,n)}`)(e,t);if("privy:wallet:create"===e||"privy:solana-wallet:create"===e){let e=this.cache.get(i);if(e)return e}let r=new Promise(((i,r)=>{let a=s();m.enqueue(a,{resolve:i,reject:r}),this._embeddedWalletMessagePoster.postMessage(JSON.stringify({id:a,event:e,data:t}),"*")})).finally((()=>{this.cache.delete(i)}));return this.cache.set(i,r),r}constructor(e,t){this.ready=!1,this.cache=new Map,this._embeddedWalletMessagePoster=e,this.mfa=t}}export{o as DEFAULT_WALLET_PROXY_TIMEOUT_MS,h as EmbeddedWalletProxy};
1
+ import{sleep as e}from"../utils/sleep.mjs";import{EventCallbacksQueue as t}from"./EventCallbackQueue.mjs";import{PrivyIframeError as i}from"./errors.mjs";import{withMfa as r}from"./withMfa.mjs";import"./types.mjs";var a;const o=15e3;let s=(a=0,()=>"id-"+a++),n=(e,t)=>"bigint"==typeof t?t.toString():t,l=(t,{ms:i,msg:r})=>Promise.race([t,e(i??15e3).then((()=>Promise.reject(Error(r))))]),m=new t;class h{invokeWithMfa(e,t){return l(r((i=>l(this.waitForReady().then((()=>e(i))),{msg:t.timeoutMsg,ms:t.timeoutMs})),this.mfa.rootPromise,this.mfa.submitPromise,(()=>this.mfa.emit("mfaRequired")),t.mfaAlwaysRequired??!1,4,3e5),{msg:"Operation reached timeout: MFA verification",ms:126e4})}reload(){return this.ready=!1,this._embeddedWalletMessagePoster.reload()}ping(e=15e3){return l(this.invoke("privy:iframe:ready",{}),{msg:"Ping reached timeout",ms:e})}create(e){return l(this.waitForReady().then((()=>this.invoke("privy:wallet:create",e))),{msg:"Operation reached timeout: create"})}rpc(e){return this.invokeWithMfa((t=>this.invoke("privy:wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: rpc"})}createSolana(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}createAdditionalSolana(e){return l(this.waitForReady().then((()=>this.invoke("privy:solana-wallet:create-additional",e))),{msg:"Operation reached timeout: create"})}solanaRpc(e){return this.invokeWithMfa((t=>this.invoke("privy:solana-wallet:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: solana-rpc"})}delegateWallets(e){return this.invokeWithMfa((t=>this.invoke("privy:delegated-actions:consent",{...t,...e})),{timeoutMsg:"Operation reached timeout: delegated-actions:consent"})}verifyMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:verify",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:verify",mfaAlwaysRequired:!0})}initEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:init-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:init-enrollment"})}submitEnrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:submit-enrollment",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:submit-enrollment"})}unenrollMfa(e){return this.invokeWithMfa((t=>this.invoke("privy:mfa:unenroll",{...t,...e})),{timeoutMsg:"Operation reached timeout: mfa:unenroll",mfaAlwaysRequired:!0})}clearMfa(e){return l(this.waitForReady().then((()=>this.invoke("privy:mfa:clear",e))),{msg:"Operation reached timeout: mfa:clear"})}createWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:create",{...t,...e})),{timeoutMsg:"Operation reached timeout: create",timeoutMs:6e4})}signWithUserSigner(e){return this.invokeWithMfa((t=>this.invoke("privy:user-signer:sign",{...t,...e})),{timeoutMsg:"Operation reached timeout: user-signer:sign"})}addWallet(e){return l(this.waitForReady().then((()=>this.invoke("privy:wallets:add",e))),{msg:"Operation reached timeout: wallets:add"})}setRecovery(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:set-recovery",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:set-recovery",timeoutMs:6e4})}connect(e){return l(this.waitForReady().then((()=>this.invoke("privy:wallets:connect",e))),{msg:"Operation reached timeout: wallets:connect"})}recover(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:recover",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:recover",timeoutMs:6e4})}rpcWallet(e){return this.invokeWithMfa((t=>this.invoke("privy:wallets:rpc",{...t,...e})),{timeoutMsg:"Operation reached timeout: wallets:rpc"})}handleEmbeddedWalletMessages(e){let{reject:t,resolve:r}=m.dequeue(e.event,e.id);return void 0!==e.error?t(new i(e.error.type,e.error.message)):r(e.data)}waitForReady(){return this.ready?Promise.resolve():new Promise((async(t,i)=>{for(;!this.ready;)this.invoke("privy:iframe:ready",{}).then((()=>{this.ready=!0,t()})).catch(i),await e(150)}))}invoke(e,t){let i=((e,t)=>`${e}${JSON.stringify(t,n)}`)(e,t);if("privy:wallet:create"===e||"privy:solana-wallet:create"===e){let e=this.cache.get(i);if(e)return e}let r=new Promise(((i,r)=>{let a=s();m.enqueue(a,{resolve:i,reject:r}),this._embeddedWalletMessagePoster.postMessage(JSON.stringify({id:a,event:e,data:t}),"*")})).finally((()=>{this.cache.delete(i)}));return this.cache.set(i,r),r}constructor(e,t){this.ready=!1,this.cache=new Map,this._embeddedWalletMessagePoster=e,this.mfa=t}}export{o as DEFAULT_WALLET_PROXY_TIMEOUT_MS,h as EmbeddedWalletProxy};
@@ -1 +1 @@
1
- import{createSmartAccountClient as e}from"permissionless";import{toThirdwebSmartAccount as r,toLightSmartAccount as t,toBiconomySmartAccount as a,toKernelSmartAccount as i,toSafeSmartAccount as n}from"permissionless/accounts";import{createPimlicoClient as s}from"permissionless/clients/pimlico";import{http as o}from"viem";import{toCoinbaseSmartAccount as c,entryPoint06Address as l,entryPoint07Address as m}from"viem/account-abstraction";import{THIRDWEB as p,COINBASE_SMART_WALLET as u,LIGHT_ACCOUNT as y,BICONOMY as P,KERNEL as d,SAFE as w}from"@privy-io/public-api";let f={address:l,version:"0.6"},h={address:m,version:"0.7"},b=({owner:e,smartWalletType:s,publicClient:o})=>{switch(s){case w:return n({client:o,entryPoint:h,owners:[e],version:"1.4.1"});case d:return i({client:o,version:"0.3.1",entryPoint:h,useMetaFactory:"optional",owners:[e]});case P:return a({client:o,owners:[e],entryPoint:f});case y:return t({client:o,entryPoint:f,owner:e,version:"1.1.0"});case u:return async function({client:e,owner:r}){let[t]=await r.request({method:"eth_accounts"});if(!t)throw Error("Unable to request embedded owner for eth_accounts");return await c({client:e,version:"1",owners:[{type:"local",source:"privy",address:t,sign:async({hash:e})=>await r.request({method:"secp256k1_sign",params:[e]})}]})}({client:o,owner:e});case p:return r({client:o,entryPoint:h,owner:e});default:throw Error(`Invalid smart account type: ${s}.`)}};const v=async({owner:r,smartWalletType:t,chain:a,publicClient:i,bundlerUrl:n,paymasterUrl:c,paymasterContext:l})=>{let m=await b({owner:r,smartWalletType:t,publicClient:i}),p=s({transport:o(n),entryPoint:m.entryPoint}),u=c?s({transport:o(c),entryPoint:m.entryPoint}):void 0;return e({account:m,chain:a,paymaster:u,paymasterContext:l,bundlerTransport:o(n),userOperation:{estimateFeesPerGas:async()=>{if(["public.pimlico.io","api.pimlico.io"].some((e=>n.includes(e))))return await p.getUserOperationGasPrice().then((e=>e.fast));if(["rpc.zerodev.app"].some((e=>n.includes(e))))return(await p.request({method:"zd_getUserOperationGasPrice",params:[]})).fast;if(["g.alchemy.com"].some((e=>n.includes(e)))){let[e,r]=await Promise.all([i.getBlock({blockTag:"latest"}),p.request({method:"rundler_maxPriorityFeePerGas",params:[]})]);if(!e.baseFeePerGas||!r)throw Error("Failed to get block or maxPriorityFeePerGasEstimate");return{maxFeePerGas:150n*e.baseFeePerGas/100n+BigInt(r.toString()),maxPriorityFeePerGas:BigInt(r.toString())}}{let e=await i.estimateFeesPerGas(),r=n.includes("api.developer.coinbase.com")?175n:150n;return{...e,maxFeePerGas:e.maxFeePerGas*r/100n,maxPriorityFeePerGas:e.maxPriorityFeePerGas*r/100n}}}}})};export{v as signerToSmartAccountClient};
1
+ import{createSmartAccountClient as e}from"permissionless";import{toThirdwebSmartAccount as r,toLightSmartAccount as t,toBiconomySmartAccount as a,toKernelSmartAccount as i,toSafeSmartAccount as n}from"permissionless/accounts";import{createPimlicoClient as s}from"permissionless/clients/pimlico";import{http as o}from"viem";import{toCoinbaseSmartAccount as l,entryPoint06Address as c,entryPoint07Address as m}from"viem/account-abstraction";import{THIRDWEB as p,COINBASE_SMART_WALLET as u,LIGHT_ACCOUNT as y,BICONOMY as P,KERNEL as d,SAFE as w}from"@privy-io/public-api";let f={address:c,version:"0.6"},h={address:m,version:"0.7"},v=({owner:e,smartWalletType:s,smartWalletVersion:o,publicClient:c})=>{switch(s){case w:return n({client:c,entryPoint:h,owners:[e],version:"1.4.1"});case d:return i({client:c,version:"0.3.1",entryPoint:h,useMetaFactory:"optional",owners:[e]});case P:return a({client:c,owners:[e],entryPoint:f});case y:return t({client:c,entryPoint:f,owner:e,version:"1.1.0"});case u:return async function({client:e,owner:r,version:t}){let[a]=await r.request({method:"eth_accounts"});if(!a)throw Error("Unable to request embedded owner for eth_accounts");return await l({client:e,owners:[{type:"local",source:"privy",address:a,sign:async({hash:e})=>await r.request({method:"secp256k1_sign",params:[e]})}],version:t})}({client:c,owner:e,version:o??"1"});case p:return r({client:c,entryPoint:h,owner:e});default:throw Error(`Invalid smart account type: ${s}.`)}};const b=async({owner:r,smartWalletType:t,smartWalletVersion:a,chain:i,publicClient:n,bundlerUrl:l,paymasterUrl:c,paymasterContext:m})=>{let p=await v({owner:r,smartWalletType:t,smartWalletVersion:a,publicClient:n}),u=s({transport:o(l),entryPoint:p.entryPoint}),y=c?s({transport:o(c),entryPoint:p.entryPoint}):void 0;return e({account:p,chain:i,paymaster:y,paymasterContext:m,bundlerTransport:o(l),userOperation:{estimateFeesPerGas:async()=>{if(["public.pimlico.io","api.pimlico.io"].some((e=>l.includes(e))))return await u.getUserOperationGasPrice().then((e=>e.fast));if(["rpc.zerodev.app"].some((e=>l.includes(e))))return(await u.request({method:"zd_getUserOperationGasPrice",params:[]})).fast;if(["g.alchemy.com"].some((e=>l.includes(e)))){let[e,r]=await Promise.all([n.getBlock({blockTag:"latest"}),u.request({method:"rundler_maxPriorityFeePerGas",params:[]})]);if(!e.baseFeePerGas||!r)throw Error("Failed to get block or maxPriorityFeePerGasEstimate");return{maxFeePerGas:150n*e.baseFeePerGas/100n+BigInt(r.toString()),maxPriorityFeePerGas:BigInt(r.toString())}}{let e=await n.estimateFeesPerGas(),r=l.includes("api.developer.coinbase.com")?175n:150n;return{...e,maxFeePerGas:e.maxFeePerGas*r/100n,maxPriorityFeePerGas:e.maxPriorityFeePerGas*r/100n}}}}})};export{b as signerToSmartAccountClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/js-sdk-core",
3
- "version": "0.52.9",
3
+ "version": "0.53.0",
4
4
  "description": "Vanilla JS client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",
@@ -69,7 +69,7 @@
69
69
  "@ethersproject/transactions": "^5.7.0",
70
70
  "@ethersproject/units": "^5.7.0",
71
71
  "@privy-io/api-base": "1.5.2",
72
- "@privy-io/public-api": "2.40.0",
72
+ "@privy-io/public-api": "2.40.1",
73
73
  "canonicalize": "^2.0.0",
74
74
  "@privy-io/chains": "0.0.2",
75
75
  "eventemitter3": "^5.0.1",