@privy-io/js-sdk-core 0.53.2 → 0.53.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.53.2",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.3",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})}))}};
@@ -1080,6 +1080,7 @@ declare class EmbeddedWalletApi {
1080
1080
  latest_verified_at: number | null;
1081
1081
  credential_id: string;
1082
1082
  enrolled_in_mfa: boolean;
1083
+ public_key?: string | undefined;
1083
1084
  created_with_browser?: string | undefined;
1084
1085
  created_with_os?: string | undefined;
1085
1086
  created_with_device?: string | undefined;
@@ -1519,6 +1520,7 @@ declare class UserApi {
1519
1520
  latest_verified_at: number | null;
1520
1521
  credential_id: string;
1521
1522
  enrolled_in_mfa: boolean;
1523
+ public_key?: string | undefined;
1522
1524
  created_with_browser?: string | undefined;
1523
1525
  created_with_os?: string | undefined;
1524
1526
  created_with_device?: string | undefined;
@@ -1855,6 +1857,7 @@ declare class EmailApi {
1855
1857
  latest_verified_at: number | null;
1856
1858
  credential_id: string;
1857
1859
  enrolled_in_mfa: boolean;
1860
+ public_key?: string | undefined;
1858
1861
  created_with_browser?: string | undefined;
1859
1862
  created_with_os?: string | undefined;
1860
1863
  created_with_device?: string | undefined;
@@ -2156,6 +2159,7 @@ declare class EmailApi {
2156
2159
  latest_verified_at: number | null;
2157
2160
  credential_id: string;
2158
2161
  enrolled_in_mfa: boolean;
2162
+ public_key?: string | undefined;
2159
2163
  created_with_browser?: string | undefined;
2160
2164
  created_with_os?: string | undefined;
2161
2165
  created_with_device?: string | undefined;
@@ -2446,6 +2450,7 @@ declare class EmailApi {
2446
2450
  latest_verified_at: number | null;
2447
2451
  credential_id: string;
2448
2452
  enrolled_in_mfa: boolean;
2453
+ public_key?: string | undefined;
2449
2454
  created_with_browser?: string | undefined;
2450
2455
  created_with_os?: string | undefined;
2451
2456
  created_with_device?: string | undefined;
@@ -2771,6 +2776,7 @@ declare class FarcasterApi {
2771
2776
  latest_verified_at: number | null;
2772
2777
  credential_id: string;
2773
2778
  enrolled_in_mfa: boolean;
2779
+ public_key?: string | undefined;
2774
2780
  created_with_browser?: string | undefined;
2775
2781
  created_with_os?: string | undefined;
2776
2782
  created_with_device?: string | undefined;
@@ -3066,6 +3072,7 @@ declare class FarcasterApi {
3066
3072
  latest_verified_at: number | null;
3067
3073
  credential_id: string;
3068
3074
  enrolled_in_mfa: boolean;
3075
+ public_key?: string | undefined;
3069
3076
  created_with_browser?: string | undefined;
3070
3077
  created_with_os?: string | undefined;
3071
3078
  created_with_device?: string | undefined;
@@ -3409,6 +3416,7 @@ declare class OAuthApi {
3409
3416
  latest_verified_at: number | null;
3410
3417
  credential_id: string;
3411
3418
  enrolled_in_mfa: boolean;
3419
+ public_key?: string | undefined;
3412
3420
  created_with_browser?: string | undefined;
3413
3421
  created_with_os?: string | undefined;
3414
3422
  created_with_device?: string | undefined;
@@ -3705,6 +3713,7 @@ declare class OAuthApi {
3705
3713
  latest_verified_at: number | null;
3706
3714
  credential_id: string;
3707
3715
  enrolled_in_mfa: boolean;
3716
+ public_key?: string | undefined;
3708
3717
  created_with_browser?: string | undefined;
3709
3718
  created_with_os?: string | undefined;
3710
3719
  created_with_device?: string | undefined;
@@ -4121,6 +4130,7 @@ declare class PasskeyApi {
4121
4130
  latest_verified_at: number | null;
4122
4131
  credential_id: string;
4123
4132
  enrolled_in_mfa: boolean;
4133
+ public_key?: string | undefined;
4124
4134
  created_with_browser?: string | undefined;
4125
4135
  created_with_os?: string | undefined;
4126
4136
  created_with_device?: string | undefined;
@@ -4437,6 +4447,7 @@ declare class PhoneApi {
4437
4447
  latest_verified_at: number | null;
4438
4448
  credential_id: string;
4439
4449
  enrolled_in_mfa: boolean;
4450
+ public_key?: string | undefined;
4440
4451
  created_with_browser?: string | undefined;
4441
4452
  created_with_os?: string | undefined;
4442
4453
  created_with_device?: string | undefined;
@@ -4738,6 +4749,7 @@ declare class PhoneApi {
4738
4749
  latest_verified_at: number | null;
4739
4750
  credential_id: string;
4740
4751
  enrolled_in_mfa: boolean;
4752
+ public_key?: string | undefined;
4741
4753
  created_with_browser?: string | undefined;
4742
4754
  created_with_os?: string | undefined;
4743
4755
  created_with_device?: string | undefined;
@@ -5028,6 +5040,7 @@ declare class PhoneApi {
5028
5040
  latest_verified_at: number | null;
5029
5041
  credential_id: string;
5030
5042
  enrolled_in_mfa: boolean;
5043
+ public_key?: string | undefined;
5031
5044
  created_with_browser?: string | undefined;
5032
5045
  created_with_os?: string | undefined;
5033
5046
  created_with_device?: string | undefined;
@@ -5389,6 +5402,7 @@ declare class SiweApi {
5389
5402
  latest_verified_at: number | null;
5390
5403
  credential_id: string;
5391
5404
  enrolled_in_mfa: boolean;
5405
+ public_key?: string | undefined;
5392
5406
  created_with_browser?: string | undefined;
5393
5407
  created_with_os?: string | undefined;
5394
5408
  created_with_device?: string | undefined;
@@ -5696,6 +5710,7 @@ declare class SiweApi {
5696
5710
  latest_verified_at: number | null;
5697
5711
  credential_id: string;
5698
5712
  enrolled_in_mfa: boolean;
5713
+ public_key?: string | undefined;
5699
5714
  created_with_browser?: string | undefined;
5700
5715
  created_with_os?: string | undefined;
5701
5716
  created_with_device?: string | undefined;
@@ -6036,6 +6051,7 @@ declare class SiwsApi {
6036
6051
  latest_verified_at: number | null;
6037
6052
  credential_id: string;
6038
6053
  enrolled_in_mfa: boolean;
6054
+ public_key?: string | undefined;
6039
6055
  created_with_browser?: string | undefined;
6040
6056
  created_with_os?: string | undefined;
6041
6057
  created_with_device?: string | undefined;
@@ -6348,6 +6364,7 @@ declare class SiwsApi {
6348
6364
  latest_verified_at: number | null;
6349
6365
  credential_id: string;
6350
6366
  enrolled_in_mfa: boolean;
6367
+ public_key?: string | undefined;
6351
6368
  created_with_browser?: string | undefined;
6352
6369
  created_with_os?: string | undefined;
6353
6370
  created_with_device?: string | undefined;
@@ -6695,6 +6712,7 @@ declare class SmartWalletApi {
6695
6712
  latest_verified_at: number | null;
6696
6713
  credential_id: string;
6697
6714
  enrolled_in_mfa: boolean;
6715
+ public_key?: string | undefined;
6698
6716
  created_with_browser?: string | undefined;
6699
6717
  created_with_os?: string | undefined;
6700
6718
  created_with_device?: string | undefined;
@@ -7728,6 +7746,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7728
7746
  latest_verified_at: number | null;
7729
7747
  credential_id: string;
7730
7748
  enrolled_in_mfa: boolean;
7749
+ public_key?: string | undefined;
7731
7750
  created_with_browser?: string | undefined;
7732
7751
  created_with_os?: string | undefined;
7733
7752
  created_with_device?: string | undefined;
@@ -8026,6 +8045,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
8026
8045
  latest_verified_at: number | null;
8027
8046
  credential_id: string;
8028
8047
  enrolled_in_mfa: boolean;
8048
+ public_key?: string | undefined;
8029
8049
  created_with_browser?: string | undefined;
8030
8050
  created_with_os?: string | undefined;
8031
8051
  created_with_device?: string | undefined;
@@ -1080,6 +1080,7 @@ declare class EmbeddedWalletApi {
1080
1080
  latest_verified_at: number | null;
1081
1081
  credential_id: string;
1082
1082
  enrolled_in_mfa: boolean;
1083
+ public_key?: string | undefined;
1083
1084
  created_with_browser?: string | undefined;
1084
1085
  created_with_os?: string | undefined;
1085
1086
  created_with_device?: string | undefined;
@@ -1519,6 +1520,7 @@ declare class UserApi {
1519
1520
  latest_verified_at: number | null;
1520
1521
  credential_id: string;
1521
1522
  enrolled_in_mfa: boolean;
1523
+ public_key?: string | undefined;
1522
1524
  created_with_browser?: string | undefined;
1523
1525
  created_with_os?: string | undefined;
1524
1526
  created_with_device?: string | undefined;
@@ -1855,6 +1857,7 @@ declare class EmailApi {
1855
1857
  latest_verified_at: number | null;
1856
1858
  credential_id: string;
1857
1859
  enrolled_in_mfa: boolean;
1860
+ public_key?: string | undefined;
1858
1861
  created_with_browser?: string | undefined;
1859
1862
  created_with_os?: string | undefined;
1860
1863
  created_with_device?: string | undefined;
@@ -2156,6 +2159,7 @@ declare class EmailApi {
2156
2159
  latest_verified_at: number | null;
2157
2160
  credential_id: string;
2158
2161
  enrolled_in_mfa: boolean;
2162
+ public_key?: string | undefined;
2159
2163
  created_with_browser?: string | undefined;
2160
2164
  created_with_os?: string | undefined;
2161
2165
  created_with_device?: string | undefined;
@@ -2446,6 +2450,7 @@ declare class EmailApi {
2446
2450
  latest_verified_at: number | null;
2447
2451
  credential_id: string;
2448
2452
  enrolled_in_mfa: boolean;
2453
+ public_key?: string | undefined;
2449
2454
  created_with_browser?: string | undefined;
2450
2455
  created_with_os?: string | undefined;
2451
2456
  created_with_device?: string | undefined;
@@ -2771,6 +2776,7 @@ declare class FarcasterApi {
2771
2776
  latest_verified_at: number | null;
2772
2777
  credential_id: string;
2773
2778
  enrolled_in_mfa: boolean;
2779
+ public_key?: string | undefined;
2774
2780
  created_with_browser?: string | undefined;
2775
2781
  created_with_os?: string | undefined;
2776
2782
  created_with_device?: string | undefined;
@@ -3066,6 +3072,7 @@ declare class FarcasterApi {
3066
3072
  latest_verified_at: number | null;
3067
3073
  credential_id: string;
3068
3074
  enrolled_in_mfa: boolean;
3075
+ public_key?: string | undefined;
3069
3076
  created_with_browser?: string | undefined;
3070
3077
  created_with_os?: string | undefined;
3071
3078
  created_with_device?: string | undefined;
@@ -3409,6 +3416,7 @@ declare class OAuthApi {
3409
3416
  latest_verified_at: number | null;
3410
3417
  credential_id: string;
3411
3418
  enrolled_in_mfa: boolean;
3419
+ public_key?: string | undefined;
3412
3420
  created_with_browser?: string | undefined;
3413
3421
  created_with_os?: string | undefined;
3414
3422
  created_with_device?: string | undefined;
@@ -3705,6 +3713,7 @@ declare class OAuthApi {
3705
3713
  latest_verified_at: number | null;
3706
3714
  credential_id: string;
3707
3715
  enrolled_in_mfa: boolean;
3716
+ public_key?: string | undefined;
3708
3717
  created_with_browser?: string | undefined;
3709
3718
  created_with_os?: string | undefined;
3710
3719
  created_with_device?: string | undefined;
@@ -4121,6 +4130,7 @@ declare class PasskeyApi {
4121
4130
  latest_verified_at: number | null;
4122
4131
  credential_id: string;
4123
4132
  enrolled_in_mfa: boolean;
4133
+ public_key?: string | undefined;
4124
4134
  created_with_browser?: string | undefined;
4125
4135
  created_with_os?: string | undefined;
4126
4136
  created_with_device?: string | undefined;
@@ -4437,6 +4447,7 @@ declare class PhoneApi {
4437
4447
  latest_verified_at: number | null;
4438
4448
  credential_id: string;
4439
4449
  enrolled_in_mfa: boolean;
4450
+ public_key?: string | undefined;
4440
4451
  created_with_browser?: string | undefined;
4441
4452
  created_with_os?: string | undefined;
4442
4453
  created_with_device?: string | undefined;
@@ -4738,6 +4749,7 @@ declare class PhoneApi {
4738
4749
  latest_verified_at: number | null;
4739
4750
  credential_id: string;
4740
4751
  enrolled_in_mfa: boolean;
4752
+ public_key?: string | undefined;
4741
4753
  created_with_browser?: string | undefined;
4742
4754
  created_with_os?: string | undefined;
4743
4755
  created_with_device?: string | undefined;
@@ -5028,6 +5040,7 @@ declare class PhoneApi {
5028
5040
  latest_verified_at: number | null;
5029
5041
  credential_id: string;
5030
5042
  enrolled_in_mfa: boolean;
5043
+ public_key?: string | undefined;
5031
5044
  created_with_browser?: string | undefined;
5032
5045
  created_with_os?: string | undefined;
5033
5046
  created_with_device?: string | undefined;
@@ -5389,6 +5402,7 @@ declare class SiweApi {
5389
5402
  latest_verified_at: number | null;
5390
5403
  credential_id: string;
5391
5404
  enrolled_in_mfa: boolean;
5405
+ public_key?: string | undefined;
5392
5406
  created_with_browser?: string | undefined;
5393
5407
  created_with_os?: string | undefined;
5394
5408
  created_with_device?: string | undefined;
@@ -5696,6 +5710,7 @@ declare class SiweApi {
5696
5710
  latest_verified_at: number | null;
5697
5711
  credential_id: string;
5698
5712
  enrolled_in_mfa: boolean;
5713
+ public_key?: string | undefined;
5699
5714
  created_with_browser?: string | undefined;
5700
5715
  created_with_os?: string | undefined;
5701
5716
  created_with_device?: string | undefined;
@@ -6036,6 +6051,7 @@ declare class SiwsApi {
6036
6051
  latest_verified_at: number | null;
6037
6052
  credential_id: string;
6038
6053
  enrolled_in_mfa: boolean;
6054
+ public_key?: string | undefined;
6039
6055
  created_with_browser?: string | undefined;
6040
6056
  created_with_os?: string | undefined;
6041
6057
  created_with_device?: string | undefined;
@@ -6348,6 +6364,7 @@ declare class SiwsApi {
6348
6364
  latest_verified_at: number | null;
6349
6365
  credential_id: string;
6350
6366
  enrolled_in_mfa: boolean;
6367
+ public_key?: string | undefined;
6351
6368
  created_with_browser?: string | undefined;
6352
6369
  created_with_os?: string | undefined;
6353
6370
  created_with_device?: string | undefined;
@@ -6695,6 +6712,7 @@ declare class SmartWalletApi {
6695
6712
  latest_verified_at: number | null;
6696
6713
  credential_id: string;
6697
6714
  enrolled_in_mfa: boolean;
6715
+ public_key?: string | undefined;
6698
6716
  created_with_browser?: string | undefined;
6699
6717
  created_with_os?: string | undefined;
6700
6718
  created_with_device?: string | undefined;
@@ -7728,6 +7746,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7728
7746
  latest_verified_at: number | null;
7729
7747
  credential_id: string;
7730
7748
  enrolled_in_mfa: boolean;
7749
+ public_key?: string | undefined;
7731
7750
  created_with_browser?: string | undefined;
7732
7751
  created_with_os?: string | undefined;
7733
7752
  created_with_device?: string | undefined;
@@ -8026,6 +8045,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
8026
8045
  latest_verified_at: number | null;
8027
8046
  credential_id: string;
8028
8047
  enrolled_in_mfa: boolean;
8048
+ public_key?: string | undefined;
8029
8049
  created_with_browser?: string | undefined;
8030
8050
  created_with_os?: string | undefined;
8031
8051
  created_with_device?: string | undefined;
@@ -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.53.2",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.3",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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/js-sdk-core",
3
- "version": "0.53.2",
3
+ "version": "0.53.3",
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.42.0",
72
+ "@privy-io/public-api": "2.43.0",
73
73
  "canonicalize": "^2.0.0",
74
74
  "@privy-io/chains": "0.0.2",
75
75
  "eventemitter3": "^5.0.1",