@privy-io/js-sdk-core 0.50.3 → 0.50.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/action/delegatedActions/delegateWallet.js +1 -1
- package/dist/cjs/action/delegatedActions/index.js +1 -1
- package/dist/cjs/action/delegatedActions/revokeWallets.js +1 -1
- package/dist/cjs/action/index.js +1 -1
- package/dist/cjs/client/PrivyInternal.js +1 -1
- package/dist/cjs/funding/coinbase.js +1 -1
- package/dist/dts/index.d.mts +3 -2
- package/dist/dts/index.d.ts +3 -2
- package/dist/esm/action/delegatedActions/delegateWallet.mjs +1 -1
- package/dist/esm/action/delegatedActions/index.mjs +1 -1
- package/dist/esm/action/delegatedActions/revokeWallets.mjs +1 -1
- package/dist/esm/action/index.mjs +1 -1
- package/dist/esm/client/PrivyInternal.mjs +1 -1
- package/dist/esm/funding/coinbase.mjs +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../../Error.js"),t=require("./utils.js");require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js");exports.delegateWallet=
|
|
1
|
+
"use strict";var e=require("../../Error.js"),r=require("../../wallet-api/unified-wallet.js"),t=require("./utils.js");require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js");exports.delegateWallet=l=>async({address:s,chainType:a})=>{let{user:d}=await l.user.get();if(!d)throw new e.PrivyClientError({code:"delegated_actions_before_logged_in",error:"Must be logged in to delegate wallets"});if("solana"!==a&&"ethereum"!==a)throw new e.PrivyClientError({code:"unsupported_chain_type",error:"Only Solana and Ethereum embedded wallets are supported for delegation and revocation."});let i=t.getUserValidDelegateWallets(d).find((e=>e.chain_type===a&&e.address===s));if(!i)throw new e.PrivyClientError({code:"delegated_actions_wallet_not_found",error:"Address to delegate is not associated with current user."});if(r.isUnifiedWallet(i))throw new e.PrivyClientError({code:"unsupported_wallet_type",error:"useDelegatedActions is only supported for device reassembled embedded wallets and this app uses enclave embedded wallets. Use the useSessionSigners hook to provision server side access on behalf of your users. Learn more at https://docs.privy.io/recipes/enclave-wallet-migration-guide"});if(i.delegated)return{user:d};let o=t.getRootWalletForDelegation(i,d);if(!o)throw new e.PrivyClientError({code:"delegated_actions_wallet_not_found",error:"Address to delegate is not associated with current user."});await l.embeddedWallet.delegateWallets({rootWallet:{address:o.address,chainType:o.chain_type,imported:o.imported},delegatedWallets:[{address:i.address,chainType:i.chain_type,walletIndex:i.wallet_index}]});let{user:n}=await l.user.get();return{user:n}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./delegateWallet.js"),l=require("./revokeWallets.js");require("../../Error.js"),require("./utils.js"),require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js"),exports.delegateWallet=e.delegateWallet,exports.revokeWallets=l.revokeWallets;
|
|
1
|
+
"use strict";var e=require("./delegateWallet.js"),l=require("./revokeWallets.js");require("../../Error.js"),require("../../wallet-api/unified-wallet.js"),require("./utils.js"),require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js"),exports.delegateWallet=e.delegateWallet,exports.revokeWallets=l.revokeWallets;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../../Error.js"),r=require("./utils.js");require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js");exports.revokeWallets=
|
|
1
|
+
"use strict";var e=require("../../Error.js"),r=require("../../wallet-api/unified-wallet.js"),t=require("./utils.js");require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js");exports.revokeWallets=l=>async()=>{let{user:s}=await l.user.get();if(!s)throw new e.PrivyClientError({code:"delegated_actions_before_logged_in",error:"Must be logged in to revoke delegated wallets"});let a=t.getUserValidDelegateWallets(s);if(a.some(r.isUnifiedWallet))throw new e.PrivyClientError({code:"unsupported_wallet_type",error:"revokeWallets is only supported for device reassembled embedded wallets and this app uses enclave embedded wallets. Use the useSessionSigners hook to manage server side access on behalf of your users. Learn more at https://docs.privy.io/recipes/enclave-wallet-migration-guide"});if(a.every((e=>!e.delegated)))throw new e.PrivyClientError({code:"delegated_actions_no_wallet_to_revoke",error:"User has no delegated wallets to revoke."});await l.delegated.revoke();let{user:i}=await l.user.get();return{user:i}};
|
package/dist/cjs/action/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../index-BDWdfIuK.js"),s=require("../index-DzfqDJJ9.js");require("./delegatedActions/delegateWallet.js"),require("../Error.js"),require("./delegatedActions/utils.js"),require("../utils/getAllUserEmbeddedEthereumWallets.js"),require("../utils/getAllUserEmbeddedSolanaWallets.js"),require("../utils/getUserEmbeddedEthereumWallet.js"),require("../utils/getUserEmbeddedSolanaWallet.js"),require("./delegatedActions/revokeWallets.js"),require("./crossApp/loginWithCrossAppAuth.js"),require("./crossApp/linkWithCrossAppAuth.js"),require("../index-CARkJvRM.js"),require("./crossApp/wallet/signMessage.js"),require("./crossApp/wallet/utils/isCrossAppWalletSmart.js"),require("./crossApp/wallet/utils/sendCrossAppRequest.js"),require("./crossApp/wallet/utils/getCrossAppAccountByWalletAddress.js"),require("./crossApp/wallet/utils/getProviderAccessTokenOrRelink.js"),require("./crossApp/wallet/utils/throwIfNotLoggedIn.js"),require("./crossApp/wallet/signTypedData.js"),require("../utils/typedData/generateDomainType.js"),require("./crossApp/wallet/sendTransaction.js"),exports.delegatedActions=e.index,exports.crossApp=s.index;
|
|
1
|
+
"use strict";var e=require("../index-BDWdfIuK.js"),s=require("../index-DzfqDJJ9.js");require("./delegatedActions/delegateWallet.js"),require("../Error.js"),require("../wallet-api/unified-wallet.js"),require("./delegatedActions/utils.js"),require("../utils/getAllUserEmbeddedEthereumWallets.js"),require("../utils/getAllUserEmbeddedSolanaWallets.js"),require("../utils/getUserEmbeddedEthereumWallet.js"),require("../utils/getUserEmbeddedSolanaWallet.js"),require("./delegatedActions/revokeWallets.js"),require("./crossApp/loginWithCrossAppAuth.js"),require("./crossApp/linkWithCrossAppAuth.js"),require("../index-CARkJvRM.js"),require("./crossApp/wallet/signMessage.js"),require("./crossApp/wallet/utils/isCrossAppWalletSmart.js"),require("./crossApp/wallet/utils/sendCrossAppRequest.js"),require("./crossApp/wallet/utils/getCrossAppAccountByWalletAddress.js"),require("./crossApp/wallet/utils/getProviderAccessTokenOrRelink.js"),require("./crossApp/wallet/utils/throwIfNotLoggedIn.js"),require("./crossApp/wallet/signTypedData.js"),require("../utils/typedData/generateDomainType.js"),require("./crossApp/wallet/sendTransaction.js"),exports.delegatedActions=e.index,exports.crossApp=s.index;
|
|
@@ -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.50.
|
|
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.50.5",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=require("@privy-io/chains");let a=new Set([e.mainnet.id,e.base.id,e.optimism.id,e.polygon.id,e.arbitrum.id]),s=new Set([e.mainnet.id,e.base.id,e.polygon.id,e.optimism.id]),t={buy:"CARD",send:"CRYPTO_ACCOUNT"},r={USDC:"2b92315d-eab7-5bef-84fa-089a131333f5",ETH:"d85dce9b-5b73-5c3c-8978-522ce1d1c1b4",BTC:"5b71fc48-3dd3-540c-809b-f8c94d0e68b5",SOL:"4f039497-3af8-5bb3-951c-6df9afa9be1c",POL:"026bcc1e-9163-591c-a709-34dd18b2e7a1"},n={[e.mainnet.id]:"ethereum",[e.base.id]:"base",[e.optimism.id]:"optimism",[e.polygon.id]:"polygon",[e.arbitrum.id]:"arbitrum"};exports.getCoinbaseOnRampUrl=function({
|
|
1
|
+
"use strict";var e=require("@privy-io/chains");let a=new Set([e.mainnet.id,e.base.id,e.optimism.id,e.polygon.id,e.arbitrum.id]),s=new Set([e.mainnet.id,e.base.id,e.polygon.id,e.optimism.id]),t={buy:"CARD",send:"CRYPTO_ACCOUNT"},r={USDC:"2b92315d-eab7-5bef-84fa-089a131333f5",ETH:"d85dce9b-5b73-5c3c-8978-522ce1d1c1b4",BTC:"5b71fc48-3dd3-540c-809b-f8c94d0e68b5",SOL:"4f039497-3af8-5bb3-951c-6df9afa9be1c",POL:"026bcc1e-9163-591c-a709-34dd18b2e7a1"},n={[e.mainnet.id]:"ethereum",[e.base.id]:"base",[e.optimism.id]:"optimism",[e.polygon.id]:"polygon",[e.arbitrum.id]:"arbitrum"};exports.getCoinbaseOnRampUrl=function({appId:e,input:a,amount:s,blockchain:n,asset:i,experience:o}){let d=new URL("https://pay.coinbase.com/buy/select-asset");return d.searchParams.set("appId",a.app_id),d.searchParams.set("sessionToken",a.session_token),d.searchParams.set("endPartnerName",`privy:${e}`),d.searchParams.set("defaultExperience",o),d.searchParams.set("presetCryptoAmount",s.startsWith(".")?`0${s}`:s),d.searchParams.set("defaultNetwork",n),d.searchParams.set("defaultPaymentMethod",t[o]),d.searchParams.set("defaultAsset",r[i]),d.searchParams.set("partnerUserId",a.partner_user_id),{url:d}},exports.isSupportedChainIdForCoinbaseOnramp=(e,t)=>{switch(t){case"native-currency":return a.has(e);case"USDC":return s.has(e);default:return console.warn("Unknown asset passed to Coinbase Onramp"),!1}},exports.toCoinbaseAssetId=function(a,s){return"USDC"===s?"USDC":a===e.polygon.id?"POL":"ETH"},exports.toCoinbaseBlockchainFromChainId=function(e){return n[e]};
|
package/dist/dts/index.d.mts
CHANGED
|
@@ -335,7 +335,7 @@ declare class EmbeddedWalletProvider extends EventEmitter implements EIP1193Prov
|
|
|
335
335
|
|
|
336
336
|
type AuthAction = 'login' | 'link';
|
|
337
337
|
type Method = 'email' | 'sms' | 'oauth' | 'siwe' | 'passkey' | 'farcaster' | 'siws';
|
|
338
|
-
type ClientErrorCode = `failed_to_complete_${AuthAction}_with_oauth` | `${AuthAction}_with_oauth_returned_with_invalid_credentials` | `${AuthAction}_with_oauth_was_cancelled_by_user` | 'attempted_rpc_call_before_logged_in' | 'attempted_submit_otp_before_sending' | 'attempted_to_set_password_before_connected' | 'attempted_to_set_password_but_password_already_set' | `attempted_login_with_${Method}_while_already_logged_in` | `attempted_link_${Method}_before_logged_in` | 'attempted_link_cross_app_before_logged_in' | 'attempted_login_with_cross_app_while_already_logged_in' | 'attempted_cross_app_request_before_logged_in' | 'attempted_update_before_logged_in' | 'attempted_update_email_without_a_linked_email' | 'attempted_update_phone_without_a_linked_phone' | 'cross_app_invalid_app' | 'cross_app_read_only' | 'cross_app_invalid_wallet' | 'cross_app_request_error' | `attempted_unlink_siwe_before_logged_in` | 'oauth_session_failed' | 'oauth_session_timeout' | 'user_signer_sign_error' | 'embedded_wallet_needs_recovery' | 'embedded_wallet_creation_error' | 'embedded_wallet_recovery_error' | 'embedded_wallet_set_password_error' | 'embedded_wallet_set_recovery_error' | 'unknown_embedded_wallet_error' | 'embedded_wallet_does_not_exist' | 'embedded_wallet_already_exists' | 'embedded_wallet_webview_not_loaded' | 'embedded_wallet_request_error' | 'delegated_actions_before_logged_in' | 'delegated_actions_wallet_not_found' | 'delegated_actions_no_wallet_to_revoke' | 'no_passkey_found_for_challenge' | 'pkce_state_code_mismatch' | 'failed_to_create_passkey' | 'failed_to_generate_farcaster_uri' | 'failed_to_generate_farcaster_channel_token' | 'farcaster_polling_timeout' | 'farcaster_polling_canceled' | 'unsupported_recovery_method' | 'attempted_to_create_guest_account_for_logged_in_user' | 'attempted_to_read_storage_before_client_initialized' | 'third_party_auth_error' | 'invalid_native_app_id' | 'unsupported_mfa_method' | 'unsupported_chain_type' | 'invalid_mfa_code' | 'invalid_passkey_response' | 'storage_error' | 'smart_wallet_client_error' | 'chain_not_supported' | 'mfa_canceled' | 'configuration_error' | 'failed_to_fetch_moonpay_transaction_status';
|
|
338
|
+
type ClientErrorCode = `failed_to_complete_${AuthAction}_with_oauth` | `${AuthAction}_with_oauth_returned_with_invalid_credentials` | `${AuthAction}_with_oauth_was_cancelled_by_user` | 'attempted_rpc_call_before_logged_in' | 'attempted_submit_otp_before_sending' | 'attempted_to_set_password_before_connected' | 'attempted_to_set_password_but_password_already_set' | `attempted_login_with_${Method}_while_already_logged_in` | `attempted_link_${Method}_before_logged_in` | 'attempted_link_cross_app_before_logged_in' | 'attempted_login_with_cross_app_while_already_logged_in' | 'attempted_cross_app_request_before_logged_in' | 'attempted_update_before_logged_in' | 'attempted_update_email_without_a_linked_email' | 'attempted_update_phone_without_a_linked_phone' | 'cross_app_invalid_app' | 'cross_app_read_only' | 'cross_app_invalid_wallet' | 'cross_app_request_error' | `attempted_unlink_siwe_before_logged_in` | 'oauth_session_failed' | 'oauth_session_timeout' | 'user_signer_sign_error' | 'embedded_wallet_needs_recovery' | 'embedded_wallet_creation_error' | 'embedded_wallet_recovery_error' | 'embedded_wallet_set_password_error' | 'embedded_wallet_set_recovery_error' | 'unknown_embedded_wallet_error' | 'embedded_wallet_does_not_exist' | 'embedded_wallet_already_exists' | 'embedded_wallet_webview_not_loaded' | 'embedded_wallet_request_error' | 'delegated_actions_before_logged_in' | 'delegated_actions_wallet_not_found' | 'delegated_actions_no_wallet_to_revoke' | 'no_passkey_found_for_challenge' | 'pkce_state_code_mismatch' | 'failed_to_create_passkey' | 'failed_to_generate_farcaster_uri' | 'failed_to_generate_farcaster_channel_token' | 'farcaster_polling_timeout' | 'farcaster_polling_canceled' | 'unsupported_recovery_method' | 'attempted_to_create_guest_account_for_logged_in_user' | 'attempted_to_read_storage_before_client_initialized' | 'third_party_auth_error' | 'invalid_native_app_id' | 'unsupported_mfa_method' | 'unsupported_chain_type' | 'invalid_mfa_code' | 'invalid_passkey_response' | 'storage_error' | 'smart_wallet_client_error' | 'chain_not_supported' | 'mfa_canceled' | 'configuration_error' | 'failed_to_fetch_moonpay_transaction_status' | 'unsupported_wallet_type';
|
|
339
339
|
type ErrorBody<T extends PrivyErrorCode | ClientErrorCode> = {
|
|
340
340
|
error: string;
|
|
341
341
|
code: T;
|
|
@@ -7055,7 +7055,8 @@ declare const ASSET_ID_MAP: {
|
|
|
7055
7055
|
};
|
|
7056
7056
|
type CoinbaseAssetId = keyof typeof ASSET_ID_MAP;
|
|
7057
7057
|
type SupportedBlockchains = PrivyCoinbaseOnRampInitInput['addresses'][0]['blockchains'][0];
|
|
7058
|
-
declare function getCoinbaseOnRampUrl({ input, amount, blockchain, asset, experience, }: {
|
|
7058
|
+
declare function getCoinbaseOnRampUrl({ appId, input, amount, blockchain, asset, experience, }: {
|
|
7059
|
+
appId: string;
|
|
7059
7060
|
input: PrivyCoinbaseOnRampInitResponse;
|
|
7060
7061
|
amount: string;
|
|
7061
7062
|
blockchain: SupportedBlockchains;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -335,7 +335,7 @@ declare class EmbeddedWalletProvider extends EventEmitter implements EIP1193Prov
|
|
|
335
335
|
|
|
336
336
|
type AuthAction = 'login' | 'link';
|
|
337
337
|
type Method = 'email' | 'sms' | 'oauth' | 'siwe' | 'passkey' | 'farcaster' | 'siws';
|
|
338
|
-
type ClientErrorCode = `failed_to_complete_${AuthAction}_with_oauth` | `${AuthAction}_with_oauth_returned_with_invalid_credentials` | `${AuthAction}_with_oauth_was_cancelled_by_user` | 'attempted_rpc_call_before_logged_in' | 'attempted_submit_otp_before_sending' | 'attempted_to_set_password_before_connected' | 'attempted_to_set_password_but_password_already_set' | `attempted_login_with_${Method}_while_already_logged_in` | `attempted_link_${Method}_before_logged_in` | 'attempted_link_cross_app_before_logged_in' | 'attempted_login_with_cross_app_while_already_logged_in' | 'attempted_cross_app_request_before_logged_in' | 'attempted_update_before_logged_in' | 'attempted_update_email_without_a_linked_email' | 'attempted_update_phone_without_a_linked_phone' | 'cross_app_invalid_app' | 'cross_app_read_only' | 'cross_app_invalid_wallet' | 'cross_app_request_error' | `attempted_unlink_siwe_before_logged_in` | 'oauth_session_failed' | 'oauth_session_timeout' | 'user_signer_sign_error' | 'embedded_wallet_needs_recovery' | 'embedded_wallet_creation_error' | 'embedded_wallet_recovery_error' | 'embedded_wallet_set_password_error' | 'embedded_wallet_set_recovery_error' | 'unknown_embedded_wallet_error' | 'embedded_wallet_does_not_exist' | 'embedded_wallet_already_exists' | 'embedded_wallet_webview_not_loaded' | 'embedded_wallet_request_error' | 'delegated_actions_before_logged_in' | 'delegated_actions_wallet_not_found' | 'delegated_actions_no_wallet_to_revoke' | 'no_passkey_found_for_challenge' | 'pkce_state_code_mismatch' | 'failed_to_create_passkey' | 'failed_to_generate_farcaster_uri' | 'failed_to_generate_farcaster_channel_token' | 'farcaster_polling_timeout' | 'farcaster_polling_canceled' | 'unsupported_recovery_method' | 'attempted_to_create_guest_account_for_logged_in_user' | 'attempted_to_read_storage_before_client_initialized' | 'third_party_auth_error' | 'invalid_native_app_id' | 'unsupported_mfa_method' | 'unsupported_chain_type' | 'invalid_mfa_code' | 'invalid_passkey_response' | 'storage_error' | 'smart_wallet_client_error' | 'chain_not_supported' | 'mfa_canceled' | 'configuration_error' | 'failed_to_fetch_moonpay_transaction_status';
|
|
338
|
+
type ClientErrorCode = `failed_to_complete_${AuthAction}_with_oauth` | `${AuthAction}_with_oauth_returned_with_invalid_credentials` | `${AuthAction}_with_oauth_was_cancelled_by_user` | 'attempted_rpc_call_before_logged_in' | 'attempted_submit_otp_before_sending' | 'attempted_to_set_password_before_connected' | 'attempted_to_set_password_but_password_already_set' | `attempted_login_with_${Method}_while_already_logged_in` | `attempted_link_${Method}_before_logged_in` | 'attempted_link_cross_app_before_logged_in' | 'attempted_login_with_cross_app_while_already_logged_in' | 'attempted_cross_app_request_before_logged_in' | 'attempted_update_before_logged_in' | 'attempted_update_email_without_a_linked_email' | 'attempted_update_phone_without_a_linked_phone' | 'cross_app_invalid_app' | 'cross_app_read_only' | 'cross_app_invalid_wallet' | 'cross_app_request_error' | `attempted_unlink_siwe_before_logged_in` | 'oauth_session_failed' | 'oauth_session_timeout' | 'user_signer_sign_error' | 'embedded_wallet_needs_recovery' | 'embedded_wallet_creation_error' | 'embedded_wallet_recovery_error' | 'embedded_wallet_set_password_error' | 'embedded_wallet_set_recovery_error' | 'unknown_embedded_wallet_error' | 'embedded_wallet_does_not_exist' | 'embedded_wallet_already_exists' | 'embedded_wallet_webview_not_loaded' | 'embedded_wallet_request_error' | 'delegated_actions_before_logged_in' | 'delegated_actions_wallet_not_found' | 'delegated_actions_no_wallet_to_revoke' | 'no_passkey_found_for_challenge' | 'pkce_state_code_mismatch' | 'failed_to_create_passkey' | 'failed_to_generate_farcaster_uri' | 'failed_to_generate_farcaster_channel_token' | 'farcaster_polling_timeout' | 'farcaster_polling_canceled' | 'unsupported_recovery_method' | 'attempted_to_create_guest_account_for_logged_in_user' | 'attempted_to_read_storage_before_client_initialized' | 'third_party_auth_error' | 'invalid_native_app_id' | 'unsupported_mfa_method' | 'unsupported_chain_type' | 'invalid_mfa_code' | 'invalid_passkey_response' | 'storage_error' | 'smart_wallet_client_error' | 'chain_not_supported' | 'mfa_canceled' | 'configuration_error' | 'failed_to_fetch_moonpay_transaction_status' | 'unsupported_wallet_type';
|
|
339
339
|
type ErrorBody<T extends PrivyErrorCode | ClientErrorCode> = {
|
|
340
340
|
error: string;
|
|
341
341
|
code: T;
|
|
@@ -7055,7 +7055,8 @@ declare const ASSET_ID_MAP: {
|
|
|
7055
7055
|
};
|
|
7056
7056
|
type CoinbaseAssetId = keyof typeof ASSET_ID_MAP;
|
|
7057
7057
|
type SupportedBlockchains = PrivyCoinbaseOnRampInitInput['addresses'][0]['blockchains'][0];
|
|
7058
|
-
declare function getCoinbaseOnRampUrl({ input, amount, blockchain, asset, experience, }: {
|
|
7058
|
+
declare function getCoinbaseOnRampUrl({ appId, input, amount, blockchain, asset, experience, }: {
|
|
7059
|
+
appId: string;
|
|
7059
7060
|
input: PrivyCoinbaseOnRampInitResponse;
|
|
7060
7061
|
amount: string;
|
|
7061
7062
|
blockchain: SupportedBlockchains;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PrivyClientError as e}from"../../Error.mjs";import{getUserValidDelegateWallets as
|
|
1
|
+
import{PrivyClientError as e}from"../../Error.mjs";import{isUnifiedWallet as t}from"../../wallet-api/unified-wallet.mjs";import{getUserValidDelegateWallets as r,getRootWalletForDelegation as s}from"./utils.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";const d=d=>async({address:a,chainType:o})=>{let{user:l}=await d.user.get();if(!l)throw new e({code:"delegated_actions_before_logged_in",error:"Must be logged in to delegate wallets"});if("solana"!==o&&"ethereum"!==o)throw new e({code:"unsupported_chain_type",error:"Only Solana and Ethereum embedded wallets are supported for delegation and revocation."});let i=r(l).find((e=>e.chain_type===o&&e.address===a));if(!i)throw new e({code:"delegated_actions_wallet_not_found",error:"Address to delegate is not associated with current user."});if(t(i))throw new e({code:"unsupported_wallet_type",error:"useDelegatedActions is only supported for device reassembled embedded wallets and this app uses enclave embedded wallets. Use the useSessionSigners hook to provision server side access on behalf of your users. Learn more at https://docs.privy.io/recipes/enclave-wallet-migration-guide"});if(i.delegated)return{user:l};let n=s(i,l);if(!n)throw new e({code:"delegated_actions_wallet_not_found",error:"Address to delegate is not associated with current user."});await d.embeddedWallet.delegateWallets({rootWallet:{address:n.address,chainType:n.chain_type,imported:n.imported},delegatedWallets:[{address:i.address,chainType:i.chain_type,walletIndex:i.wallet_index}]});let{user:u}=await d.user.get();return{user:u}};export{d as delegateWallet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{delegateWallet}from"./delegateWallet.mjs";export{revokeWallets}from"./revokeWallets.mjs";import"../../Error.mjs";import"./utils.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";
|
|
1
|
+
export{delegateWallet}from"./delegateWallet.mjs";export{revokeWallets}from"./revokeWallets.mjs";import"../../Error.mjs";import"../../wallet-api/unified-wallet.mjs";import"./utils.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PrivyClientError as e}from"../../Error.mjs";import{
|
|
1
|
+
import{PrivyClientError as e}from"../../Error.mjs";import{isUnifiedWallet as t}from"../../wallet-api/unified-wallet.mjs";import{getUserValidDelegateWallets as r}from"./utils.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";const s=s=>async()=>{let{user:l}=await s.user.get();if(!l)throw new e({code:"delegated_actions_before_logged_in",error:"Must be logged in to revoke delegated wallets"});let o=r(l);if(o.some(t))throw new e({code:"unsupported_wallet_type",error:"revokeWallets is only supported for device reassembled embedded wallets and this app uses enclave embedded wallets. Use the useSessionSigners hook to manage server side access on behalf of your users. Learn more at https://docs.privy.io/recipes/enclave-wallet-migration-guide"});if(o.every((e=>!e.delegated)))throw new e({code:"delegated_actions_no_wallet_to_revoke",error:"User has no delegated wallets to revoke."});await s.delegated.revoke();let{user:a}=await s.user.get();return{user:a}};export{s as revokeWallets};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{i as delegatedActions}from"../index-g0cxoRWQ.mjs";export{i as crossApp}from"../index-Bu3ySxLM.mjs";import"./delegatedActions/delegateWallet.mjs";import"../Error.mjs";import"./delegatedActions/utils.mjs";import"../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../utils/getUserEmbeddedEthereumWallet.mjs";import"../utils/getUserEmbeddedSolanaWallet.mjs";import"./delegatedActions/revokeWallets.mjs";import"./crossApp/loginWithCrossAppAuth.mjs";import"./crossApp/linkWithCrossAppAuth.mjs";import"../index-DTAjYY8z.mjs";import"./crossApp/wallet/signMessage.mjs";import"./crossApp/wallet/utils/isCrossAppWalletSmart.mjs";import"./crossApp/wallet/utils/sendCrossAppRequest.mjs";import"./crossApp/wallet/utils/getCrossAppAccountByWalletAddress.mjs";import"./crossApp/wallet/utils/getProviderAccessTokenOrRelink.mjs";import"./crossApp/wallet/utils/throwIfNotLoggedIn.mjs";import"./crossApp/wallet/signTypedData.mjs";import"../utils/typedData/generateDomainType.mjs";import"./crossApp/wallet/sendTransaction.mjs";
|
|
1
|
+
export{i as delegatedActions}from"../index-g0cxoRWQ.mjs";export{i as crossApp}from"../index-Bu3ySxLM.mjs";import"./delegatedActions/delegateWallet.mjs";import"../Error.mjs";import"../wallet-api/unified-wallet.mjs";import"./delegatedActions/utils.mjs";import"../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../utils/getUserEmbeddedEthereumWallet.mjs";import"../utils/getUserEmbeddedSolanaWallet.mjs";import"./delegatedActions/revokeWallets.mjs";import"./crossApp/loginWithCrossAppAuth.mjs";import"./crossApp/linkWithCrossAppAuth.mjs";import"../index-DTAjYY8z.mjs";import"./crossApp/wallet/signMessage.mjs";import"./crossApp/wallet/utils/isCrossAppWalletSmart.mjs";import"./crossApp/wallet/utils/sendCrossAppRequest.mjs";import"./crossApp/wallet/utils/getCrossAppAccountByWalletAddress.mjs";import"./crossApp/wallet/utils/getProviderAccessTokenOrRelink.mjs";import"./crossApp/wallet/utils/throwIfNotLoggedIn.mjs";import"./crossApp/wallet/signTypedData.mjs";import"../utils/typedData/generateDomainType.mjs";import"./crossApp/wallet/sendTransaction.mjs";
|
|
@@ -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.50.
|
|
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.50.5",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{mainnet as e,base as a,optimism as s,polygon as t,arbitrum as r}from"@privy-io/chains";let n=new Set([e.id,a.id,s.id,t.id,r.id]),c=new Set([e.id,a.id,t.id,s.id]),
|
|
1
|
+
import{mainnet as e,base as a,optimism as s,polygon as t,arbitrum as r}from"@privy-io/chains";let n=new Set([e.id,a.id,s.id,t.id,r.id]),c=new Set([e.id,a.id,t.id,s.id]),d={buy:"CARD",send:"CRYPTO_ACCOUNT"},i={USDC:"2b92315d-eab7-5bef-84fa-089a131333f5",ETH:"d85dce9b-5b73-5c3c-8978-522ce1d1c1b4",BTC:"5b71fc48-3dd3-540c-809b-f8c94d0e68b5",SOL:"4f039497-3af8-5bb3-951c-6df9afa9be1c",POL:"026bcc1e-9163-591c-a709-34dd18b2e7a1"},o={[e.id]:"ethereum",[a.id]:"base",[s.id]:"optimism",[t.id]:"polygon",[r.id]:"arbitrum"};function u({appId:e,input:a,amount:s,blockchain:t,asset:r,experience:n}){let c=new URL("https://pay.coinbase.com/buy/select-asset");return c.searchParams.set("appId",a.app_id),c.searchParams.set("sessionToken",a.session_token),c.searchParams.set("endPartnerName",`privy:${e}`),c.searchParams.set("defaultExperience",n),c.searchParams.set("presetCryptoAmount",s.startsWith(".")?`0${s}`:s),c.searchParams.set("defaultNetwork",t),c.searchParams.set("defaultPaymentMethod",d[n]),c.searchParams.set("defaultAsset",i[r]),c.searchParams.set("partnerUserId",a.partner_user_id),{url:c}}const p=(e,a)=>{switch(a){case"native-currency":return n.has(e);case"USDC":return c.has(e);default:return console.warn("Unknown asset passed to Coinbase Onramp"),!1}};function b(e){return o[e]}function m(e,a){return"USDC"===a?"USDC":e===t.id?"POL":"ETH"}export{u as getCoinbaseOnRampUrl,p as isSupportedChainIdForCoinbaseOnramp,m as toCoinbaseAssetId,b as toCoinbaseBlockchainFromChainId};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privy-io/js-sdk-core",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.5",
|
|
4
4
|
"description": "Vanilla JS client for the Privy Auth API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@ethersproject/transactions": "^5.7.0",
|
|
69
69
|
"@ethersproject/units": "^5.7.0",
|
|
70
70
|
"@privy-io/api-base": "1.5.1",
|
|
71
|
-
"@privy-io/public-api": "2.
|
|
71
|
+
"@privy-io/public-api": "2.29.0",
|
|
72
72
|
"canonicalize": "^2.0.0",
|
|
73
73
|
"@privy-io/chains": "0.0.1",
|
|
74
74
|
"eventemitter3": "^5.0.1",
|