@privy-io/js-sdk-core
Advanced tools
Comparing version 0.26.7 to 0.27.0
@@ -1,2 +0,2 @@ | ||
const t={id:137,name:"Polygon Mainnet",network:"matic",nativeCurrency:{name:"MATIC",symbol:"MATIC",decimals:18},rpcUrls:{privy:{http:["https://polygon-mainnet.rpc.privy.systems"]},alchemy:{http:["https://polygon-mainnet.g.alchemy.com/v2"],webSocket:["wss://polygon-mainnet.g.alchemy.com/v2"]},infura:{http:["https://polygon-mainnet.infura.io/v3"],webSocket:["wss://polygon-mainnet.infura.io/ws/v3"]},default:{http:["https://polygon-rpc.com"]},public:{http:["https://polygon-rpc.com"]}},blockExplorers:{etherscan:{name:"PolygonScan",url:"https://polygonscan.com"},default:{name:"PolygonScan",url:"https://polygonscan.com"}}};export{t as polygon}; | ||
const o={id:137,name:"Polygon Mainnet",network:"polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{privy:{http:["https://polygon-mainnet.rpc.privy.systems"]},alchemy:{http:["https://polygon-mainnet.g.alchemy.com/v2"],webSocket:["wss://polygon-mainnet.g.alchemy.com/v2"]},infura:{http:["https://polygon-mainnet.infura.io/v3"],webSocket:["wss://polygon-mainnet.infura.io/ws/v3"]},default:{http:["https://polygon-rpc.com"]},public:{http:["https://polygon-rpc.com"]}},blockExplorers:{etherscan:{name:"PolygonScan",url:"https://polygonscan.com"},default:{name:"PolygonScan",url:"https://polygonscan.com"}}};export{o as polygon}; | ||
//# sourceMappingURL=polygon.js.map |
@@ -1,2 +0,2 @@ | ||
const o={id:80002,name:"Polygon Amoy",nativeCurrency:{name:"MATIC",symbol:"MATIC",decimals:18},rpcUrls:{privy:{http:["https://polygon-amoy.rpc.privy.systems"]},infura:{http:["https://polygon-amoy.infura.io/v3"],webSocket:["wss://polygon-amoy.infura.io/ws/v3"]},default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"OK LINK",url:"https://www.oklink.com/amoy"}},testnet:!0};export{o as polygonAmoy}; | ||
const o={id:80002,name:"Polygon Amoy",network:"polygon-amoy",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{privy:{http:["https://polygon-amoy.rpc.privy.systems"]},infura:{http:["https://polygon-amoy.infura.io/v3"],webSocket:["wss://polygon-amoy.infura.io/ws/v3"]},default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"OK LINK",url:"https://www.oklink.com/amoy"}},testnet:!0};export{o as polygonAmoy}; | ||
//# sourceMappingURL=polygonAmoy.js.map |
@@ -14,4 +14,5 @@ export default class EmailApi { | ||
* @param code The one time code | ||
* @param mode Optional Whether or not to block sign ups (only allow existing users to log in). | ||
*/ | ||
loginWithCode(email: string, code: string): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
loginWithCode(email: string, code: string, mode?: 'login-or-sign-up' | 'no-signup'): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
/** | ||
@@ -59,2 +60,12 @@ * Links an email adress to an existing user | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -257,2 +268,12 @@ fid: number; | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -259,0 +280,0 @@ fid: number; |
@@ -19,3 +19,3 @@ export default class FarcasterApi { | ||
*/ | ||
authenticate({ channel_token, message, signature, fid, }: { | ||
authenticate({ channel_token, message, signature, fid, mode, }: { | ||
channel_token: string; | ||
@@ -25,2 +25,3 @@ message: string; | ||
fid: number; | ||
mode?: 'login-or-sign-up' | 'no-signup'; | ||
}): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
@@ -71,2 +72,12 @@ /** | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -274,2 +285,12 @@ fid: number; | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -276,0 +297,0 @@ fid: number; |
@@ -16,4 +16,7 @@ import type { OAuthProviderType } from '@privy-io/public-api'; | ||
* @param returnedStateCode The state value initially set in the request by Privy to the authorization server | ||
* @param provider The OAuth provider (e.g. google, apple) | ||
* @param codeType The string literal `raw` indicating this the authorizationCode is unhashed, from a native sign in flow. | ||
* @param mode Optional Whether or not to block sign ups (only allow existing users to log in). | ||
*/ | ||
loginWithCode(authorizationCode: string, returnedStateCode: string, provider?: OAuthProviderType, codeType?: 'raw'): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
loginWithCode(authorizationCode: string, returnedStateCode: string, provider?: OAuthProviderType, codeType?: 'raw', mode?: 'login-or-sign-up' | 'no-signup'): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
/** | ||
@@ -61,2 +64,12 @@ * Links an OAuth account to an existing user | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -265,2 +278,12 @@ fid: number; | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -267,0 +290,0 @@ fid: number; |
@@ -14,4 +14,5 @@ export default class PhoneApi { | ||
* @param code The one time code | ||
* @param mode Optional Whether or not to block sign ups (only allow existing users to log in). | ||
*/ | ||
loginWithCode(phoneNumber: string, code: string): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
loginWithCode(phoneNumber: string, code: string, mode?: 'login-or-sign-up' | 'no-signup'): Promise<import("@privy-io/public-api").PrivyAuthenticatedUser>; | ||
/** | ||
@@ -59,2 +60,12 @@ * Links a phone number to an existing user | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -257,2 +268,12 @@ fid: number; | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -259,0 +280,0 @@ fid: number; |
@@ -55,4 +55,8 @@ import { type PrivyUser, type PrivyAuthenticatedUser } from '@privy-io/public-api'; | ||
*/ | ||
messageOverride?: string): Promise<PrivyAuthenticatedUser>; | ||
messageOverride?: string, | ||
/** | ||
* Optional Whether or not to block sign ups (only allow existing users to log in). | ||
*/ | ||
mode?: 'login-or-sign-up' | 'no-signup'): Promise<PrivyAuthenticatedUser>; | ||
/** | ||
* Begin a login or link flow according to the [Sign-In With Ethereum](https://eips.ethereum.org/EIPS/eip-4361) spec. | ||
@@ -59,0 +63,0 @@ * |
@@ -42,2 +42,12 @@ export default class UserApi { | ||
} | { | ||
type: "wallet"; | ||
address: string; | ||
chain_type: "solana"; | ||
verified_at: number; | ||
first_verified_at: number | null; | ||
latest_verified_at: number | null; | ||
wallet_client: "unknown"; | ||
wallet_client_type?: string | undefined; | ||
connector_type?: string | undefined; | ||
} | { | ||
type: "farcaster"; | ||
@@ -44,0 +54,0 @@ fid: number; |
@@ -1,2 +0,2 @@ | ||
import{PasswordlessInit as e,PasswordlessAuthenticate as t,PasswordlessLink as r,PasswordlessUnlink as n}from"@privy-io/public-api";class i{_privyInternal;constructor(e){this._privyInternal=e}async sendCode(t,r){return this._privyInternal.fetch(e,{body:{email:t,token:r}})}async loginWithCode(e,r){const n=await this._privyInternal.fetch(t,{body:{email:e,code:r}});return await Promise.all([this._privyInternal.session.storeToken(n.token),this._privyInternal.session.storeRefreshToken(n.refresh_token),this._privyInternal.session.storeIdentityToken(n.identity_token)]),this._privyInternal.callbacks?.setUser?.(n.user),n}async linkWithCode(e,t){await this._privyInternal.fetch(r,{body:{email:e,code:t}});return(await this._privyInternal.refreshSession()).user}async unlink(e){await this._privyInternal.fetch(n,{body:{address:e}});return(await this._privyInternal.refreshSession()).user}}export{i as default}; | ||
import{PasswordlessInit as e,PasswordlessAuthenticate as t,PasswordlessLink as r,PasswordlessUnlink as n}from"@privy-io/public-api";class i{_privyInternal;constructor(e){this._privyInternal=e}async sendCode(t,r){return this._privyInternal.fetch(e,{body:{email:t,token:r}})}async loginWithCode(e,r,n){const i=await this._privyInternal.fetch(t,{body:{email:e,code:r,mode:n}});return await Promise.all([this._privyInternal.session.storeToken(i.token),this._privyInternal.session.storeRefreshToken(i.refresh_token),this._privyInternal.session.storeIdentityToken(i.identity_token)]),this._privyInternal.callbacks?.setUser?.(i.user),i}async linkWithCode(e,t){await this._privyInternal.fetch(r,{body:{email:e,code:t}});return(await this._privyInternal.refreshSession()).user}async unlink(e){await this._privyInternal.fetch(n,{body:{address:e}});return(await this._privyInternal.refreshSession()).user}}export{i as default}; | ||
//# sourceMappingURL=EmailApi.js.map |
@@ -1,2 +0,2 @@ | ||
import{FarcasterInit as e,FarcasterStatus as t,FarcasterAuthenticate as n,FarcasterLink as r,FarcasterUnlink as i}from"@privy-io/public-api";class a{_privyInternal;constructor(e){this._privyInternal=e}async initializeAuth({relyingParty:t,redirectUrl:n,token:r}){return await this._privyInternal.fetch(e,{body:{relying_party:t,redirect_url:n,token:r}})}async getFarcasterStatus({channel_token:e}){return await this._privyInternal.fetch(t,{headers:{"farcaster-channel-token":e}})}async authenticate({channel_token:e,message:t,signature:r,fid:i}){const a=await this._privyInternal.fetch(n,{body:{channel_token:e,message:t,signature:r,fid:i}});return await Promise.all([this._privyInternal.session.storeToken(a.token),this._privyInternal.session.storeRefreshToken(a.refresh_token),this._privyInternal.session.storeIdentityToken(a.identity_token)]),this._privyInternal.callbacks?.setUser?.(a.user),a}async link({channel_token:e,message:t,signature:n,fid:i}){await this._privyInternal.fetch(r,{body:{channel_token:e,message:t,signature:n,fid:i}});return(await this._privyInternal.refreshSession()).user}async unlink({fid:e}){await this._privyInternal.fetch(i,{body:{fid:e}});return(await this._privyInternal.refreshSession()).user}}export{a as default}; | ||
import{FarcasterInit as e,FarcasterStatus as t,FarcasterAuthenticate as n,FarcasterLink as r,FarcasterUnlink as i}from"@privy-io/public-api";class a{_privyInternal;constructor(e){this._privyInternal=e}async initializeAuth({relyingParty:t,redirectUrl:n,token:r}){return await this._privyInternal.fetch(e,{body:{relying_party:t,redirect_url:n,token:r}})}async getFarcasterStatus({channel_token:e}){return await this._privyInternal.fetch(t,{headers:{"farcaster-channel-token":e}})}async authenticate({channel_token:e,message:t,signature:r,fid:i,mode:a}){const s=await this._privyInternal.fetch(n,{body:{channel_token:e,message:t,signature:r,fid:i,mode:a}});return await Promise.all([this._privyInternal.session.storeToken(s.token),this._privyInternal.session.storeRefreshToken(s.refresh_token),this._privyInternal.session.storeIdentityToken(s.identity_token)]),this._privyInternal.callbacks?.setUser?.(s.user),s}async link({channel_token:e,message:t,signature:n,fid:i}){await this._privyInternal.fetch(r,{body:{channel_token:e,message:t,signature:n,fid:i}});return(await this._privyInternal.refreshSession()).user}async unlink({fid:e}){await this._privyInternal.fetch(i,{body:{fid:e}});return(await this._privyInternal.refreshSession()).user}}export{a as default}; | ||
//# sourceMappingURL=FarcasterApi.js.map |
@@ -1,2 +0,2 @@ | ||
import{OAuthInit as t,OAuthAuthenticate as e,OAuthLink as r,OAuthUnlink as i}from"@privy-io/public-api";import{PrivyClientError as s}from"./Error.js";import{createCodeVerifier as o,createStateCode as a,deriveCodeChallengeFromCodeVerifier as n,CODE_VERIFIER_KEY as h,STATE_CODE_KEY as _}from"./pkce.js";import"jose";class c{_privyInternal;_storage;_crypto;constructor(t,e,r){this._privyInternal=t,this._storage=e,this._crypto=r}async generateURL(e,r){const i=o(),s=a(),c=await n({codeVerifier:i,digest:this._crypto?.digest});return await Promise.all([this._storage.put(h,i),this._storage.put(_,s)]),this._privyInternal.fetch(t,{body:{redirect_to:r,provider:e,code_challenge:c,state_code:s}})}async loginWithCode(t,r,i,o){const[a,n]=await Promise.all([this._storage.get(h),this._storage.get(_)]);if(n!==r)throw this._privyInternal.createAnalyticsEvent("possible_phishing_attempt",{flow:"oauth",provider:i,storedStateCode:n??"",returnedStateCode:r??""}),new s({code:"pkce_state_code_mismatch",error:"Unexpected auth flow. This may be a phishing attempt."});const c=await this._privyInternal.fetch(e,{body:{authorization_code:t,code_type:o,state_code:n,code_verifier:a}});return await Promise.all([this._privyInternal.session.storeToken(c.token),this._privyInternal.session.storeRefreshToken(c.refresh_token),this._privyInternal.session.storeIdentityToken(c.identity_token)]),this._privyInternal.callbacks?.setUser?.(c.user),await Promise.all([this._storage.del(h),this._storage.del(_)]),c}async linkWithCode(t,e,i,o){const[a,n]=await Promise.all([this._storage.get(h),this._storage.get(_)]);if(n!==e)throw this._privyInternal.createAnalyticsEvent("possible_phishing_attempt",{flow:"oauth",provider:i,storedStateCode:n??"",returnedStateCode:e??""}),new s({code:"pkce_state_code_mismatch",error:"Unexpected auth flow. This may be a phishing attempt."});await this._privyInternal.fetch(r,{body:{authorization_code:t,code_type:o,state_code:n,code_verifier:a}});const c=await this._privyInternal.refreshSession();return await Promise.all([this._storage.del(h),this._storage.del(_)]),c.user}async unlink(t,e){await this._privyInternal.fetch(i,{body:{provider:t,subject:e}});return(await this._privyInternal.refreshSession()).user}}export{c as default}; | ||
import{OAuthInit as t,OAuthAuthenticate as e,OAuthLink as r,OAuthUnlink as i}from"@privy-io/public-api";import{PrivyClientError as s}from"./Error.js";import{createCodeVerifier as o,createStateCode as a,deriveCodeChallengeFromCodeVerifier as n,CODE_VERIFIER_KEY as h,STATE_CODE_KEY as _}from"./pkce.js";import"jose";class c{_privyInternal;_storage;_crypto;constructor(t,e,r){this._privyInternal=t,this._storage=e,this._crypto=r}async generateURL(e,r){const i=o(),s=a(),c=await n({codeVerifier:i,digest:this._crypto?.digest});return await Promise.all([this._storage.put(h,i),this._storage.put(_,s)]),this._privyInternal.fetch(t,{body:{redirect_to:r,provider:e,code_challenge:c,state_code:s}})}async loginWithCode(t,r,i,o,a){const[n,c]=await Promise.all([this._storage.get(h),this._storage.get(_)]);if(c!==r)throw this._privyInternal.createAnalyticsEvent("possible_phishing_attempt",{flow:"oauth",provider:i,storedStateCode:c??"",returnedStateCode:r??""}),new s({code:"pkce_state_code_mismatch",error:"Unexpected auth flow. This may be a phishing attempt."});const l=await this._privyInternal.fetch(e,{body:{authorization_code:t,code_type:o,state_code:c,code_verifier:n,mode:a}});return await Promise.all([this._privyInternal.session.storeToken(l.token),this._privyInternal.session.storeRefreshToken(l.refresh_token),this._privyInternal.session.storeIdentityToken(l.identity_token)]),this._privyInternal.callbacks?.setUser?.(l.user),await Promise.all([this._storage.del(h),this._storage.del(_)]),l}async linkWithCode(t,e,i,o){const[a,n]=await Promise.all([this._storage.get(h),this._storage.get(_)]);if(n!==e)throw this._privyInternal.createAnalyticsEvent("possible_phishing_attempt",{flow:"oauth",provider:i,storedStateCode:n??"",returnedStateCode:e??""}),new s({code:"pkce_state_code_mismatch",error:"Unexpected auth flow. This may be a phishing attempt."});await this._privyInternal.fetch(r,{body:{authorization_code:t,code_type:o,state_code:n,code_verifier:a}});const c=await this._privyInternal.refreshSession();return await Promise.all([this._storage.del(h),this._storage.del(_)]),c.user}async unlink(t,e){await this._privyInternal.fetch(i,{body:{provider:t,subject:e}});return(await this._privyInternal.refreshSession()).user}}export{c as default}; | ||
//# sourceMappingURL=OAuthApi.js.map |
@@ -1,2 +0,2 @@ | ||
import{PasswordlessSmsInit as e,PasswordlessSmsAuthenticate as n,PasswordlessSmsLink as r,PasswordlessSmsUnlink as t}from"@privy-io/public-api";class i{_privyInternal;constructor(e){this._privyInternal=e}async sendCode(n,r){return this._privyInternal.fetch(e,{body:{phoneNumber:n,token:r}})}async loginWithCode(e,r){const t=await this._privyInternal.fetch(n,{body:{phoneNumber:e,code:r}});return await Promise.all([this._privyInternal.session.storeToken(t.token),this._privyInternal.session.storeRefreshToken(t.refresh_token),this._privyInternal.session.storeIdentityToken(t.identity_token)]),this._privyInternal.callbacks?.setUser?.(t.user),t}async linkWithCode(e,n){await this._privyInternal.fetch(r,{body:{phoneNumber:e,code:n}});return(await this._privyInternal.refreshSession()).user}async unlink(e){await this._privyInternal.fetch(t,{body:{phoneNumber:e}});return(await this._privyInternal.refreshSession()).user}}export{i as default}; | ||
import{PasswordlessSmsInit as e,PasswordlessSmsAuthenticate as n,PasswordlessSmsLink as r,PasswordlessSmsUnlink as t}from"@privy-io/public-api";class i{_privyInternal;constructor(e){this._privyInternal=e}async sendCode(n,r){return this._privyInternal.fetch(e,{body:{phoneNumber:n,token:r}})}async loginWithCode(e,r,t){const i=await this._privyInternal.fetch(n,{body:{phoneNumber:e,code:r,mode:t}});return await Promise.all([this._privyInternal.session.storeToken(i.token),this._privyInternal.session.storeRefreshToken(i.refresh_token),this._privyInternal.session.storeIdentityToken(i.identity_token)]),this._privyInternal.callbacks?.setUser?.(i.user),i}async linkWithCode(e,n){await this._privyInternal.fetch(r,{body:{phoneNumber:e,code:n}});return(await this._privyInternal.refreshSession()).user}async unlink(e){await this._privyInternal.fetch(t,{body:{phoneNumber:e}});return(await this._privyInternal.refreshSession()).user}}export{i as default}; | ||
//# sourceMappingURL=PhoneApi.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"fetch-retry";import{v4 as e}from"uuid";import{PrivyErrorCode as s}from"@privy-io/api-base";import{getPathWithParams as i,AppConfig as n,AnalyticsEvent as a,RefreshSession as o}from"@privy-io/public-api";import{PrivyApiError as r}from"./Error.js";import{Session as h}from"./Session.js";import c from"./toAbortSignalTimeout.js";import"eventemitter3";import"js-cookie";import"./Token.js";import"jose";const l="privy:caid";class d{baseUrl;_config;appId;appClientId;_storage;_analyticsId;_sdkVersion="js-sdk-core:0.26.7";_fetch;nativeAppIdentifier;callbacks;_cache=new Map;session;constructor(e){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,"undefined"==typeof document&&(this.nativeAppIdentifier=e.nativeAppIdentifier),this.session=new h({storage:this._storage,isUsingServerCookies:!1}),this._fetch=t(fetch,{retries:3,retryDelay:500})}get isReady(){return Boolean(this._config)}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){this.isReady||(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.createAnalyticsEvent("sdk_initialize",{}))}async fetch(t,{body:e,params:s,headers:n,options:a={onRequest:this._beforeRequest.bind(this)}}){const o=`${this.baseUrl}${i(t.path,s)}`,h=new Request(o,{method:t.method,body:JSON.stringify(e),headers:n}),c=await a.onRequest(h),l=await this._fetch(h,c),d=await l.json();if(l.status>299)throw new r(d);return d}async _beforeRequestWithoutInitialize(t){const e=await this.session.getToken(),s=new Headers(t.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),s.set("Authorization",`Bearer ${e}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");const 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(t){return await this._initialize(),this._beforeRequestWithoutInitialize(t)}async _beforeRequest(t){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(t)}async getAppConfig(){return await this.fetch(n,{params:{app_id:this.appId},options:{onRequest:this._beforeRequestWithoutInitialize.bind(this)}})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{const t=await this._storage.get(l);if("string"==typeof t&&t.length>0)return this._analyticsId=t,t}catch(t){console.error("Unable to load clientId",t)}try{this._analyticsId=e()}catch(t){console.error("Unable to generate uuidv4",t)}if(!this._analyticsId)return null;try{await this._storage.put(l,this._analyticsId)}catch(t){console.error(`Unable to store clientId: ${this._analyticsId}`,t)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(l)}catch(t){console.error("Unable to delete clientId",t)}}async createAnalyticsEvent(t,e){try{await this.fetch(a,{body:{event_name:t,client_id:await this._getOrGenerateClientAnalyticsId(),payload:e},options:{onRequest:this.beforeRequestWithoutRefresh.bind(this)}})}catch(t){}}async refreshSession(){const t=await this.session.getRefreshToken()??void 0,e=t??"key",s=this._cache.get(e);if(s)return await s;const i=this._refreshSession(t);this._cache.set(e,i);try{return await i}catch(t){throw t}finally{this._cache.delete(e)}}async _refreshSession(t){const e=await this.session.getToken();if(!this.session.hasRefreshCredentials(e,t??null))throw await this._initialize(),new Error("missing_or_invalid_token");try{const{session_update_action:e,...s}=await this.fetch(o,{body:{refresh_token:t},options:{onRequest:this.beforeRequestWithoutRefresh.bind(this)}});return this.callbacks?.setUser?.(s.user),"set"===e&&await Promise.all([this.session.storeToken(s.token),this.session.storeRefreshToken(s.refresh_token),this.session.storeIdentityToken(s.identity_token)]),"clear"===e&&(await this.session.destroyLocalState(),this.callbacks?.setUser?.(null)),"ignore"===e&&s.token&&(await this.session.storeToken(s.token),s.identity_token&&await this.session.storeIdentityToken(s.identity_token)),s}catch(t){throw(t instanceof r&&t.code===s.MISSING_OR_INVALID_TOKEN||t instanceof Error&&"missing_or_invalid_token"===t.message)&&(await this.session.destroyLocalState(),this.callbacks?.setUser?.(null)),t}}async getAccessToken(){const[t,e]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(t)&&this.session.hasRefreshCredentials(t,e))try{return await this.refreshSession(),await this.session.getToken()}catch(t){return null}return t}async getIdentityToken(){return await this.session.getIdentityToken()}}export{d as PrivyInternal}; | ||
import t from"fetch-retry";import{v4 as e}from"uuid";import{PrivyErrorCode as s}from"@privy-io/api-base";import{getPathWithParams as i,AppConfig as n,AnalyticsEvent as a,RefreshSession as o}from"@privy-io/public-api";import{PrivyApiError as r}from"./Error.js";import{Session as h}from"./Session.js";import c from"./toAbortSignalTimeout.js";import"eventemitter3";import"js-cookie";import"./Token.js";import"jose";const l="privy:caid";class d{baseUrl;_config;appId;appClientId;_storage;_analyticsId;_sdkVersion="js-sdk-core:0.27.0";_fetch;nativeAppIdentifier;callbacks;_cache=new Map;session;constructor(e){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,"undefined"==typeof document&&(this.nativeAppIdentifier=e.nativeAppIdentifier),this.session=new h({storage:this._storage,isUsingServerCookies:!1}),this._fetch=t(fetch,{retries:3,retryDelay:500})}get isReady(){return Boolean(this._config)}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){this.isReady||(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.createAnalyticsEvent("sdk_initialize",{}))}async fetch(t,{body:e,params:s,headers:n,options:a={onRequest:this._beforeRequest.bind(this)}}){const o=`${this.baseUrl}${i(t.path,s)}`,h=new Request(o,{method:t.method,body:JSON.stringify(e),headers:n}),c=await a.onRequest(h),l=await this._fetch(h,c),d=await l.json();if(l.status>299)throw new r(d);return d}async _beforeRequestWithoutInitialize(t){const e=await this.session.getToken(),s=new Headers(t.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),s.set("Authorization",`Bearer ${e}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");const 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(t){return await this._initialize(),this._beforeRequestWithoutInitialize(t)}async _beforeRequest(t){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(t)}async getAppConfig(){return await this.fetch(n,{params:{app_id:this.appId},options:{onRequest:this._beforeRequestWithoutInitialize.bind(this)}})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{const t=await this._storage.get(l);if("string"==typeof t&&t.length>0)return this._analyticsId=t,t}catch(t){console.error("Unable to load clientId",t)}try{this._analyticsId=e()}catch(t){console.error("Unable to generate uuidv4",t)}if(!this._analyticsId)return null;try{await this._storage.put(l,this._analyticsId)}catch(t){console.error(`Unable to store clientId: ${this._analyticsId}`,t)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(l)}catch(t){console.error("Unable to delete clientId",t)}}async createAnalyticsEvent(t,e){try{await this.fetch(a,{body:{event_name:t,client_id:await this._getOrGenerateClientAnalyticsId(),payload:e},options:{onRequest:this.beforeRequestWithoutRefresh.bind(this)}})}catch(t){}}async refreshSession(){const t=await this.session.getRefreshToken()??void 0,e=t??"key",s=this._cache.get(e);if(s)return await s;const i=this._refreshSession(t);this._cache.set(e,i);try{return await i}catch(t){throw t}finally{this._cache.delete(e)}}async _refreshSession(t){const e=await this.session.getToken();if(!this.session.hasRefreshCredentials(e,t??null))throw await this._initialize(),new Error("missing_or_invalid_token");try{const{session_update_action:e,...s}=await this.fetch(o,{body:{refresh_token:t},options:{onRequest:this.beforeRequestWithoutRefresh.bind(this)}});return this.callbacks?.setUser?.(s.user),"set"===e&&await Promise.all([this.session.storeToken(s.token),this.session.storeRefreshToken(s.refresh_token),this.session.storeIdentityToken(s.identity_token)]),"clear"===e&&(await this.session.destroyLocalState(),this.callbacks?.setUser?.(null)),"ignore"===e&&s.token&&(await this.session.storeToken(s.token),s.identity_token&&await this.session.storeIdentityToken(s.identity_token)),s}catch(t){throw(t instanceof r&&t.code===s.MISSING_OR_INVALID_TOKEN||t instanceof Error&&"missing_or_invalid_token"===t.message)&&(await this.session.destroyLocalState(),this.callbacks?.setUser?.(null)),t}}async getAccessToken(){const[t,e]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(t)&&this.session.hasRefreshCredentials(t,e))try{return await this.refreshSession(),await this.session.getToken()}catch(t){return null}return t}async getIdentityToken(){return await this.session.getIdentityToken()}}export{d as PrivyInternal}; | ||
//# sourceMappingURL=PrivyInternal.js.map |
@@ -1,2 +0,2 @@ | ||
import{SiweUnlink as e,SiweLink as t,SiweAuthenticate as n,SiweInit as i}from"@privy-io/public-api";class r{_privyInternal;_wallet=void 0;_preparedMessage;constructor(e){this._privyInternal=e}async unlinkWallet(t){try{await this._privyInternal.fetch(e,{body:{address:t}});return(await this._privyInternal.refreshSession()).user}catch(e){throw e}}async linkWithSiwe(e,n,i){const r=n||this._wallet,s=i||this._preparedMessage;if(!r)throw new Error("A wallet must be provided in the init step or as an argument to linkWithSiwe");if(!s)throw new Error("A message must be generated and signed before being used to link a wallet to privy");try{await this._privyInternal.fetch(t,{body:{message:s,signature:e,chainId:r.chainId,walletClientType:r.walletClientType,connectorType:r.connectorType}});return(await this._privyInternal.refreshSession()).user}catch(e){throw e}}async loginWithSiwe(e,t,i){const r=t||this._wallet,s=i||this._preparedMessage;if(!r)throw new Error("A wallet must be provided in the init step or as an argument to loginWithSiwe");if(!s)throw new Error("A message must be generated and signed before being used to login to privy with a wallet");try{const t=await this._privyInternal.fetch(n,{body:{signature:e,message:s,chainId:r.chainId,walletClientType:r.walletClientType,connectorType:r.connectorType}});return await Promise.all([this._privyInternal.session.storeToken(t.token),this._privyInternal.session.storeRefreshToken(t.refresh_token),this._privyInternal.session.storeIdentityToken(t.identity_token)]),this._privyInternal.callbacks?.setUser?.(t.user),t}catch(e){throw e}}async init(e,t,n){this._wallet=e;const r=await this._privyInternal.fetch(i,{body:{address:e.address}}),{nonce:s}=r,a=`${(o={chainId:e.chainId.toString().replace("eip155:",""),address:e.address,issuedAt:(new Date).toISOString(),statement:"By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",domain:t,nonce:s,uri:n}).domain} wants you to sign in with your Ethereum account:\n${o.address}\n\n${o.statement}\n\nURI: ${o.uri}\nVersion: 1\nChain ID: ${o.chainId}\nNonce: ${o.nonce}\nIssued At: ${o.issuedAt}\nResources:\n- https://privy.io`;var o;return this._preparedMessage=a,{nonce:s,message:a}}}export{r as default}; | ||
import{SiweUnlink as e,SiweLink as t,SiweAuthenticate as n,SiweInit as i}from"@privy-io/public-api";class r{_privyInternal;_wallet=void 0;_preparedMessage;constructor(e){this._privyInternal=e}async unlinkWallet(t){try{await this._privyInternal.fetch(e,{body:{address:t}});return(await this._privyInternal.refreshSession()).user}catch(e){throw e}}async linkWithSiwe(e,n,i){const r=n||this._wallet,s=i||this._preparedMessage;if(!r)throw new Error("A wallet must be provided in the init step or as an argument to linkWithSiwe");if(!s)throw new Error("A message must be generated and signed before being used to link a wallet to privy");try{await this._privyInternal.fetch(t,{body:{message:s,signature:e,chainId:r.chainId,walletClientType:r.walletClientType,connectorType:r.connectorType}});return(await this._privyInternal.refreshSession()).user}catch(e){throw e}}async loginWithSiwe(e,t,i,r){const s=t||this._wallet,a=i||this._preparedMessage;if(!s)throw new Error("A wallet must be provided in the init step or as an argument to loginWithSiwe");if(!a)throw new Error("A message must be generated and signed before being used to login to privy with a wallet");try{const t=await this._privyInternal.fetch(n,{body:{signature:e,message:a,chainId:s.chainId,walletClientType:s.walletClientType,connectorType:s.connectorType,mode:r}});return await Promise.all([this._privyInternal.session.storeToken(t.token),this._privyInternal.session.storeRefreshToken(t.refresh_token),this._privyInternal.session.storeIdentityToken(t.identity_token)]),this._privyInternal.callbacks?.setUser?.(t.user),t}catch(e){throw e}}async init(e,t,n){this._wallet=e;const r=await this._privyInternal.fetch(i,{body:{address:e.address}}),{nonce:s}=r,a=`${(o={chainId:e.chainId.toString().replace("eip155:",""),address:e.address,issuedAt:(new Date).toISOString(),statement:"By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",domain:t,nonce:s,uri:n}).domain} wants you to sign in with your Ethereum account:\n${o.address}\n\n${o.statement}\n\nURI: ${o.uri}\nVersion: 1\nChain ID: ${o.chainId}\nNonce: ${o.nonce}\nIssued At: ${o.issuedAt}\nResources:\n- https://privy.io`;var o;return this._preparedMessage=a,{nonce:s,message:a}}}export{r as default}; | ||
//# sourceMappingURL=SiweApi.js.map |
{ | ||
"name": "@privy-io/js-sdk-core", | ||
"version": "0.26.7", | ||
"version": "0.27.0", | ||
"description": "Vanilla JS client for the Privy Auth API", | ||
@@ -69,3 +69,3 @@ "sideEffects": false, | ||
"@privy-io/api-base": "^1.2.3", | ||
"@privy-io/public-api": "2.9.3", | ||
"@privy-io/public-api": "2.9.4", | ||
"eventemitter3": "^5.0.1", | ||
@@ -72,0 +72,0 @@ "fetch-retry": "^5.0.6", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
483387
4602
+ Added@privy-io/public-api@2.9.4(transitive)
+ Addedbase-x@4.0.0(transitive)
+ Addedbs58@5.0.0(transitive)
- Removed@privy-io/public-api@2.9.3(transitive)
Updated@privy-io/public-api@2.9.4