@bounded-sh/client 0.0.57 → 0.0.59
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/auth/index.d.ts +1 -1
- package/dist/{email-auth-provider-BlJI-8w9.js → email-auth-provider-BSw9FRjg.js} +3 -3
- package/dist/email-auth-provider-BSw9FRjg.js.map +1 -0
- package/dist/{email-auth-provider-Bmah1GWS.mjs → email-auth-provider-DhAMOILG.mjs} +3 -3
- package/dist/email-auth-provider-DhAMOILG.mjs.map +1 -0
- package/dist/{email-auth-provider-8k8iBIQL.js → email-auth-provider-N-dfsNnE.js} +3 -3
- package/dist/email-auth-provider-N-dfsNnE.js.map +1 -0
- package/dist/{email-auth-provider-CfNSS8Du.mjs → email-auth-provider-deB_ADc5.mjs} +3 -3
- package/dist/email-auth-provider-deB_ADc5.mjs.map +1 -0
- package/dist/{guest-auth-provider-D6h4eAtx.mjs → guest-auth-provider-B78Ugfar.mjs} +7 -7
- package/dist/guest-auth-provider-B78Ugfar.mjs.map +1 -0
- package/dist/{guest-auth-provider-BjfjrpdW.js → guest-auth-provider-BFodq9Rc.js} +7 -7
- package/dist/guest-auth-provider-BFodq9Rc.js.map +1 -0
- package/dist/{guest-auth-provider-BRjJV8Zq.js → guest-auth-provider-Czl48mOP.js} +7 -7
- package/dist/guest-auth-provider-Czl48mOP.js.map +1 -0
- package/dist/{guest-auth-provider-DxhZ5sWN.mjs → guest-auth-provider-D9wbogwi.mjs} +7 -7
- package/dist/guest-auth-provider-D9wbogwi.mjs.map +1 -0
- package/dist/{index-C7rOe6B2.mjs → index-SHt4VZZV.mjs} +181 -40
- package/dist/index-SHt4VZZV.mjs.map +1 -0
- package/dist/{index-CnObYQhV.js → index-uu8hKP-p.js} +180 -38
- package/dist/index-uu8hKP-p.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{index.native-CQiw9baS.mjs → index.native-D-8IAEy-.mjs} +162 -24
- package/dist/index.native-D-8IAEy-.mjs.map +1 -0
- package/dist/{index.native-hu3o3zXU.js → index.native-D48QQ0-q.js} +161 -22
- package/dist/index.native-D48QQ0-q.js.map +1 -0
- package/dist/index.native.d.ts +2 -0
- package/dist/index.native.js +2 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +1 -1
- package/dist/{injected-evm-wallet-provider-CcwS6p3o.js → injected-evm-wallet-provider-CItxws1D.js} +4 -4
- package/dist/injected-evm-wallet-provider-CItxws1D.js.map +1 -0
- package/dist/{injected-evm-wallet-provider-DCGnUedJ.mjs → injected-evm-wallet-provider-CJsLX16m.mjs} +4 -4
- package/dist/injected-evm-wallet-provider-CJsLX16m.mjs.map +1 -0
- package/dist/{injected-evm-wallet-provider-Xbt2CUPi.js → injected-evm-wallet-provider-HQMOL_mZ.js} +4 -4
- package/dist/injected-evm-wallet-provider-HQMOL_mZ.js.map +1 -0
- package/dist/{injected-evm-wallet-provider-DIWeWiAN.mjs → injected-evm-wallet-provider-UWvcy-LO.mjs} +4 -4
- package/dist/injected-evm-wallet-provider-UWvcy-LO.mjs.map +1 -0
- package/dist/{injected-wallet-provider-CFnqSsHy.mjs → injected-wallet-provider-BihII94U.mjs} +3 -3
- package/dist/injected-wallet-provider-BihII94U.mjs.map +1 -0
- package/dist/{injected-wallet-provider-Bps6a9IP.mjs → injected-wallet-provider-CNYAynIB.mjs} +3 -3
- package/dist/injected-wallet-provider-CNYAynIB.mjs.map +1 -0
- package/dist/{injected-wallet-provider-B_jQFifE.js → injected-wallet-provider-CVeZgfEt.js} +3 -3
- package/dist/injected-wallet-provider-CVeZgfEt.js.map +1 -0
- package/dist/{injected-wallet-provider-7ep-jcal.js → injected-wallet-provider-CmXqreEE.js} +3 -3
- package/dist/injected-wallet-provider-CmXqreEE.js.map +1 -0
- package/dist/onramp.d.ts +30 -0
- package/package.json +2 -2
- package/dist/email-auth-provider-8k8iBIQL.js.map +0 -1
- package/dist/email-auth-provider-BlJI-8w9.js.map +0 -1
- package/dist/email-auth-provider-Bmah1GWS.mjs.map +0 -1
- package/dist/email-auth-provider-CfNSS8Du.mjs.map +0 -1
- package/dist/guest-auth-provider-BRjJV8Zq.js.map +0 -1
- package/dist/guest-auth-provider-BjfjrpdW.js.map +0 -1
- package/dist/guest-auth-provider-D6h4eAtx.mjs.map +0 -1
- package/dist/guest-auth-provider-DxhZ5sWN.mjs.map +0 -1
- package/dist/index-C7rOe6B2.mjs.map +0 -1
- package/dist/index-CnObYQhV.js.map +0 -1
- package/dist/index.native-CQiw9baS.mjs.map +0 -1
- package/dist/index.native-hu3o3zXU.js.map +0 -1
- package/dist/injected-evm-wallet-provider-CcwS6p3o.js.map +0 -1
- package/dist/injected-evm-wallet-provider-DCGnUedJ.mjs.map +0 -1
- package/dist/injected-evm-wallet-provider-DIWeWiAN.mjs.map +0 -1
- package/dist/injected-evm-wallet-provider-Xbt2CUPi.js.map +0 -1
- package/dist/injected-wallet-provider-7ep-jcal.js.map +0 -1
- package/dist/injected-wallet-provider-B_jQFifE.js.map +0 -1
- package/dist/injected-wallet-provider-Bps6a9IP.mjs.map +0 -1
- package/dist/injected-wallet-provider-CFnqSsHy.mjs.map +0 -1
|
@@ -3475,7 +3475,7 @@ const EMBEDDED_WALLET_UNSUPPORTED = 'Unsupported for embedded smart wallets —
|
|
|
3475
3475
|
const NO_EMBEDDED_WALLET = 'This login has no embedded wallet. Enable `"auth": { "wallets": true }` in ' +
|
|
3476
3476
|
'the app policy so email logins get a non-custodial wallet (@user.address), ' +
|
|
3477
3477
|
'then sign from a user gesture.';
|
|
3478
|
-
function hasDOM$
|
|
3478
|
+
function hasDOM$2() {
|
|
3479
3479
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
3480
3480
|
}
|
|
3481
3481
|
function decodeJwt$1(token) {
|
|
@@ -3535,7 +3535,7 @@ let requestSeq = 0;
|
|
|
3535
3535
|
* wallet's owner, and validates that the wallet address matches the account.
|
|
3536
3536
|
*/
|
|
3537
3537
|
async function signViaSignerPopup(action) {
|
|
3538
|
-
if (!hasDOM$
|
|
3538
|
+
if (!hasDOM$2()) {
|
|
3539
3539
|
throw new Error('Embedded-wallet signing is only available in the browser (popup-based).');
|
|
3540
3540
|
}
|
|
3541
3541
|
const isEvm = action.kind === 'evmTransaction';
|
|
@@ -3711,7 +3711,7 @@ const STORED_AUTH_METHOD_KEY$1 = 'bounded_last_auth_method';
|
|
|
3711
3711
|
// not by `typeof window` (truthy on RN). OIDC redirect/popup is web-only, but the
|
|
3712
3712
|
// session it mints is read back through this same selector everywhere.
|
|
3713
3713
|
const sessionManager = core.getActiveSessionManager;
|
|
3714
|
-
function hasDOM() {
|
|
3714
|
+
function hasDOM$1() {
|
|
3715
3715
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
3716
3716
|
}
|
|
3717
3717
|
function decodeJwt(token) {
|
|
@@ -3742,7 +3742,7 @@ const oidcProviderSingleton = {
|
|
|
3742
3742
|
const idToken = sessionManager().getIdToken();
|
|
3743
3743
|
return idToken ? userFromIdToken(idToken) : null;
|
|
3744
3744
|
},
|
|
3745
|
-
async logout() { sessionManager().clearSession(); },
|
|
3745
|
+
async logout() { await sessionManager().clearSession(); },
|
|
3746
3746
|
async signMessage(_message) {
|
|
3747
3747
|
throw new Error(hasEmbeddedWallet() ? EMBEDDED_WALLET_UNSUPPORTED : OIDC_NO_WALLET);
|
|
3748
3748
|
},
|
|
@@ -3851,7 +3851,7 @@ async function buildAuthorize(opts) {
|
|
|
3851
3851
|
throw new Error('appId is not configured (init the SDK with your appId)');
|
|
3852
3852
|
// Web: default to the current page so callers don't have to pass redirectUri. Native has no
|
|
3853
3853
|
// window — it MUST pass an https universal link (the system auth session needs a real URL).
|
|
3854
|
-
const redirectUri = opts.redirectUri || (hasDOM() ? window.location.origin + window.location.pathname : undefined);
|
|
3854
|
+
const redirectUri = opts.redirectUri || (hasDOM$1() ? window.location.origin + window.location.pathname : undefined);
|
|
3855
3855
|
if (!redirectUri)
|
|
3856
3856
|
throw new Error('redirectUri is required on React Native — pass the https universal link the app owner registered.');
|
|
3857
3857
|
const { verifier, challenge } = await makePkce();
|
|
@@ -3959,7 +3959,7 @@ async function runNativeLogin(opts) {
|
|
|
3959
3959
|
async function loginWithRedirect(opts) {
|
|
3960
3960
|
if (isNative())
|
|
3961
3961
|
return runNativeLogin(opts);
|
|
3962
|
-
if (!hasDOM())
|
|
3962
|
+
if (!hasDOM$1())
|
|
3963
3963
|
throw new Error('loginWithRedirect requires a browser or a configured React Native platform');
|
|
3964
3964
|
const { url, pkce } = await buildAuthorize(opts);
|
|
3965
3965
|
// Stash the verifier + state so the redirect_uri page can finish the exchange. sessionStorage
|
|
@@ -3975,7 +3975,7 @@ async function loginWithRedirect(opts) {
|
|
|
3975
3975
|
* loginWithRedirect() (which resolves with the User), so there is no separate redirect
|
|
3976
3976
|
* page to finish from. Calling it on RN is harmless. */
|
|
3977
3977
|
async function completeLoginFromRedirect() {
|
|
3978
|
-
if (!hasDOM())
|
|
3978
|
+
if (!hasDOM$1())
|
|
3979
3979
|
return null;
|
|
3980
3980
|
const url = new URL(window.location.href);
|
|
3981
3981
|
const code = url.searchParams.get('code');
|
|
@@ -4021,7 +4021,7 @@ async function completeLoginFromRedirect() {
|
|
|
4021
4021
|
* redirect_uri page posts the code back. The redirect_uri page just calls the usual
|
|
4022
4022
|
* completeLoginFromRedirect() (which auto-detects the popup) — no separate call needed. */
|
|
4023
4023
|
async function loginWithPopup(opts) {
|
|
4024
|
-
if (!hasDOM())
|
|
4024
|
+
if (!hasDOM$1())
|
|
4025
4025
|
throw new Error('loginWithPopup is web-only — on React Native use loginWithRedirect()');
|
|
4026
4026
|
// Open synchronously, before PKCE/config awaits consume the click's user-
|
|
4027
4027
|
// activation window. Opening only after buildAuthorize() intermittently
|
|
@@ -4161,7 +4161,7 @@ async function loginWithPopup(opts) {
|
|
|
4161
4161
|
/** Call this on the redirect_uri page when login was opened via loginWithPopup(): posts the
|
|
4162
4162
|
* code back to the opener and closes. (For the redirect variant use completeLoginFromRedirect.) */
|
|
4163
4163
|
function completeLoginInPopup(openerOrigin) {
|
|
4164
|
-
if (!hasDOM() || !window.opener)
|
|
4164
|
+
if (!hasDOM$1() || !window.opener)
|
|
4165
4165
|
return;
|
|
4166
4166
|
const url = new URL(window.location.href);
|
|
4167
4167
|
const code = url.searchParams.get('code');
|
|
@@ -4362,15 +4362,20 @@ function authProviderConfigKey(config) {
|
|
|
4362
4362
|
* so both web (WebSessionManager) and RN (ReactNativeSessionManager) sessions
|
|
4363
4363
|
* are properly cleared.
|
|
4364
4364
|
*/
|
|
4365
|
-
function clearIncompatibleSession() {
|
|
4365
|
+
async function clearIncompatibleSession() {
|
|
4366
4366
|
if (getStoredAuthMethod() === currentAuthMethod) {
|
|
4367
4367
|
return false;
|
|
4368
4368
|
}
|
|
4369
4369
|
// Clear both managers: on web the RN manager is a no-op (not configured),
|
|
4370
4370
|
// and on RN the web manager is a no-op (no localStorage).
|
|
4371
|
-
|
|
4371
|
+
//
|
|
4372
|
+
// AWAITED. Session removal is serialized through a cross-tab lock now, so a
|
|
4373
|
+
// fire-and-forget call would let init() reach setCurrentUser while the old
|
|
4374
|
+
// credential was still readable — and a request issued in that gap would
|
|
4375
|
+
// authenticate as the session we are in the middle of discarding.
|
|
4376
|
+
await core.WebSessionManager.clearSession();
|
|
4372
4377
|
try {
|
|
4373
|
-
core.ReactNativeSessionManager.clearSession();
|
|
4378
|
+
await core.ReactNativeSessionManager.clearSession();
|
|
4374
4379
|
}
|
|
4375
4380
|
catch ( /* not configured on web */_a) { /* not configured on web */ }
|
|
4376
4381
|
setStoredAuthMethod(null);
|
|
@@ -4469,7 +4474,7 @@ async function getAuthProvider(config) {
|
|
|
4469
4474
|
// manager as legacy email sessions. Human login should be started
|
|
4470
4475
|
// with loginWithRedirect(); this provider is kept as the restore and
|
|
4471
4476
|
// logout surface for those sessions.
|
|
4472
|
-
currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-
|
|
4477
|
+
currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-BSw9FRjg.js'); })).EmailAuthProvider();
|
|
4473
4478
|
break;
|
|
4474
4479
|
case "wallet":
|
|
4475
4480
|
case "phantom": {
|
|
@@ -4488,7 +4493,7 @@ async function getAuthProvider(config) {
|
|
|
4488
4493
|
if (!isWalletLoginEnabled(config)) {
|
|
4489
4494
|
throw walletLoginNotEnabledError(authMethod);
|
|
4490
4495
|
}
|
|
4491
|
-
const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-
|
|
4496
|
+
const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-CmXqreEE.js'); });
|
|
4492
4497
|
currentAuthProvider = new InjectedWalletProvider(resolveInjectedWalletConfig(config), rpcUrl, configuredNetwork);
|
|
4493
4498
|
break;
|
|
4494
4499
|
}
|
|
@@ -4501,7 +4506,7 @@ async function getAuthProvider(config) {
|
|
|
4501
4506
|
// Selecting authMethod:'evm-wallet' IS the opt-in — pass evmWalletConfig
|
|
4502
4507
|
// to point at a specific wallet or set chainId/domain.
|
|
4503
4508
|
const evmWalletConfig = ((_a = config.evmWalletConfig) !== null && _a !== void 0 ? _a : {});
|
|
4504
|
-
const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-
|
|
4509
|
+
const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-HQMOL_mZ.js'); });
|
|
4505
4510
|
currentAuthProvider = new InjectedEvmWalletProvider(evmWalletConfig);
|
|
4506
4511
|
break;
|
|
4507
4512
|
}
|
|
@@ -4529,7 +4534,7 @@ async function getAuthProvider(config) {
|
|
|
4529
4534
|
break;
|
|
4530
4535
|
case "guest":
|
|
4531
4536
|
// Anonymous auth: a device-local ed25519 keypair signs the challenge.
|
|
4532
|
-
currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-
|
|
4537
|
+
currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-Czl48mOP.js'); })).GuestAuthProvider();
|
|
4533
4538
|
break;
|
|
4534
4539
|
}
|
|
4535
4540
|
if (!currentAuthProvider) {
|
|
@@ -4585,7 +4590,7 @@ async function signInAnonymously() {
|
|
|
4585
4590
|
// Lazy-load the guest provider so its ed25519/web3 dependencies stay out of
|
|
4586
4591
|
// the main bundle for data-only apps. Specifier is a static string literal
|
|
4587
4592
|
// so bundle-splitting can see it.
|
|
4588
|
-
const provider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-
|
|
4593
|
+
const provider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-Czl48mOP.js'); })).GuestAuthProvider();
|
|
4589
4594
|
setAuthLoading(true); // reflect "signing in…" while the guest keypair session is minted
|
|
4590
4595
|
const commit = (user) => {
|
|
4591
4596
|
// No await/interleaving inside this block: provider/method/config/marker
|
|
@@ -4627,7 +4632,7 @@ async function signInAnonymously() {
|
|
|
4627
4632
|
}
|
|
4628
4633
|
catch (_b) {
|
|
4629
4634
|
try {
|
|
4630
|
-
core.getActiveSessionManager().clearSession();
|
|
4635
|
+
await core.getActiveSessionManager().clearSession();
|
|
4631
4636
|
}
|
|
4632
4637
|
catch ( /* fail closed below */_c) { /* fail closed below */ }
|
|
4633
4638
|
}
|
|
@@ -4851,6 +4856,22 @@ async function logout$1(options) {
|
|
|
4851
4856
|
}
|
|
4852
4857
|
}
|
|
4853
4858
|
|
|
4859
|
+
/**
|
|
4860
|
+
* Subscribed once per process, not per init(): re-registering on every init would
|
|
4861
|
+
* stack duplicate handlers on repeated initialization.
|
|
4862
|
+
*/
|
|
4863
|
+
let sessionClearedBridgeRegistered = false;
|
|
4864
|
+
function registerSessionClearedBridge() {
|
|
4865
|
+
if (sessionClearedBridgeRegistered)
|
|
4866
|
+
return;
|
|
4867
|
+
sessionClearedBridgeRegistered = true;
|
|
4868
|
+
core.onSessionCleared(() => {
|
|
4869
|
+
// Core fires this only when storage was ACTUALLY cleared, never on a
|
|
4870
|
+
// transient refresh failure that preserved the session — so this cannot
|
|
4871
|
+
// sign anyone out over a network blip.
|
|
4872
|
+
setCurrentUser(null);
|
|
4873
|
+
});
|
|
4874
|
+
}
|
|
4854
4875
|
/**
|
|
4855
4876
|
* Read the active session's idToken synchronously from whichever store is live
|
|
4856
4877
|
* for this runtime (WebSessionManager on web, ReactNativeSessionManager on RN —
|
|
@@ -4908,6 +4929,15 @@ async function init(newConfig) {
|
|
|
4908
4929
|
// setting it here makes "no flash" the SDK's default behavior for every consumer.
|
|
4909
4930
|
setAuthLoading(true);
|
|
4910
4931
|
try {
|
|
4932
|
+
// Bridge core's "the stored session is gone" signal into SDK auth state.
|
|
4933
|
+
//
|
|
4934
|
+
// Core cannot import this package, and a session can die deep inside a
|
|
4935
|
+
// session manager (dead refresh token, rejected refresh, app-id mismatch).
|
|
4936
|
+
// Before this, setCurrentUser(null) was only ever called by logout() and
|
|
4937
|
+
// init(), so storage could be wiped while `currentUser` stayed populated —
|
|
4938
|
+
// onAuthStateChanged never fired, and every consumer UI went on showing a
|
|
4939
|
+
// connected wallet for a session the server no longer knew about.
|
|
4940
|
+
registerSessionClearedBridge();
|
|
4911
4941
|
// Get auth provider first
|
|
4912
4942
|
authProviderInstance = await getAuthProvider(newConfig);
|
|
4913
4943
|
// Initialize config with auth provider
|
|
@@ -4924,7 +4954,12 @@ async function init(newConfig) {
|
|
|
4924
4954
|
let user = await authProviderInstance.restoreSession();
|
|
4925
4955
|
// If a session exists but was created before auth method tracking (legacy session),
|
|
4926
4956
|
// clear it to avoid mismatches when the app switches auth methods (e.g. email → phantom)
|
|
4927
|
-
|
|
4957
|
+
//
|
|
4958
|
+
// AWAITED: the clear is serialized through a cross-tab lock now, and an
|
|
4959
|
+
// unawaited call would return a Promise (always truthy) — nulling the user
|
|
4960
|
+
// unconditionally AND letting setCurrentUser run while the old credential
|
|
4961
|
+
// was still in storage.
|
|
4962
|
+
if (user && await clearIncompatibleSession()) {
|
|
4928
4963
|
user = null;
|
|
4929
4964
|
}
|
|
4930
4965
|
setCurrentUser(user);
|
|
@@ -5787,6 +5822,109 @@ async function deserializeTransaction(tx) {
|
|
|
5787
5822
|
}
|
|
5788
5823
|
}
|
|
5789
5824
|
|
|
5825
|
+
// bounded.onramp() - fund the signed-in user's wallet with Coinbase Onramp.
|
|
5826
|
+
//
|
|
5827
|
+
// Web-only. Opens Coinbase's hosted checkout (pay.coinbase.com) in a popup
|
|
5828
|
+
// (new-tab fallback) using a single-use session token minted by the Bounded
|
|
5829
|
+
// platform at POST <origin>/__bounded/onramp/session on the app's own origin.
|
|
5830
|
+
// The platform holds the Coinbase credential; the app never sees it. The
|
|
5831
|
+
// session is bound server-side to the caller's verified Bounded JWT, and the
|
|
5832
|
+
// destination defaults to that user's embedded wallet.
|
|
5833
|
+
//
|
|
5834
|
+
// Works on Bounded-served origins (<app>.bounded.page / custom domains). On a
|
|
5835
|
+
// local dev origin the session endpoint does not exist; we fail with a clear
|
|
5836
|
+
// error rather than guessing a host.
|
|
5837
|
+
function hasDOM() {
|
|
5838
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
5839
|
+
}
|
|
5840
|
+
/**
|
|
5841
|
+
* Open Coinbase Onramp for the signed-in user. Resolves when the popup closes.
|
|
5842
|
+
* Call from a click handler - popup blockers require user activation.
|
|
5843
|
+
*/
|
|
5844
|
+
async function onramp(options = {}) {
|
|
5845
|
+
var _a, _b, _c;
|
|
5846
|
+
if (!hasDOM())
|
|
5847
|
+
throw new Error('onramp() is web-only');
|
|
5848
|
+
const user = getCurrentUser();
|
|
5849
|
+
const address = (_b = (_a = options.address) !== null && _a !== void 0 ? _a : user === null || user === void 0 ? void 0 : user.address) !== null && _b !== void 0 ? _b : undefined;
|
|
5850
|
+
if (!address) {
|
|
5851
|
+
throw new Error(user
|
|
5852
|
+
? 'onramp(): the signed-in account has no wallet address - pass { address } explicitly'
|
|
5853
|
+
: 'onramp(): no signed-in user - call login() first or pass { address }');
|
|
5854
|
+
}
|
|
5855
|
+
const idToken = await getIdToken();
|
|
5856
|
+
if (!idToken)
|
|
5857
|
+
throw new Error('onramp(): no active session - call login() first');
|
|
5858
|
+
// Open the window synchronously so the click's user-activation window is not
|
|
5859
|
+
// consumed by the fetch below (same hard-won pattern as loginWithPopup).
|
|
5860
|
+
let popup = null;
|
|
5861
|
+
if (!options.newTab) {
|
|
5862
|
+
const w = options.width || 460;
|
|
5863
|
+
const h = options.height || 720;
|
|
5864
|
+
const left = window.screenX + (window.outerWidth - w) / 2;
|
|
5865
|
+
const top = window.screenY + (window.outerHeight - h) / 2;
|
|
5866
|
+
popup = window.open('', 'bounded-onramp', `width=${w},height=${h},left=${left},top=${top}`);
|
|
5867
|
+
}
|
|
5868
|
+
let session;
|
|
5869
|
+
try {
|
|
5870
|
+
const res = await fetch(`${window.location.origin}/__bounded/onramp/session`, {
|
|
5871
|
+
method: 'POST',
|
|
5872
|
+
headers: { Authorization: `Bearer ${idToken}`, 'content-type': 'application/json' },
|
|
5873
|
+
body: JSON.stringify(Object.assign(Object.assign(Object.assign({}, (options.asset ? { asset: options.asset } : {})), (options.address ? { address: options.address } : {})), (options.amountUsd !== undefined ? { amountUsd: options.amountUsd } : {}))),
|
|
5874
|
+
});
|
|
5875
|
+
if (!res.ok) {
|
|
5876
|
+
let detail = '';
|
|
5877
|
+
try {
|
|
5878
|
+
detail = (_c = (await res.json()).error) !== null && _c !== void 0 ? _c : '';
|
|
5879
|
+
}
|
|
5880
|
+
catch ( /* keep status only */_d) { /* keep status only */ }
|
|
5881
|
+
if (res.status === 404) {
|
|
5882
|
+
throw new Error('onramp(): session endpoint not found - onramp works on Bounded-served origins (your deployed app URL), not local dev servers');
|
|
5883
|
+
}
|
|
5884
|
+
throw new Error(`onramp(): session mint failed (${res.status}${detail ? `: ${detail}` : ''})`);
|
|
5885
|
+
}
|
|
5886
|
+
session = (await res.json());
|
|
5887
|
+
}
|
|
5888
|
+
catch (error) {
|
|
5889
|
+
try {
|
|
5890
|
+
popup === null || popup === void 0 ? void 0 : popup.close();
|
|
5891
|
+
}
|
|
5892
|
+
catch ( /* ignore */_e) { /* ignore */ }
|
|
5893
|
+
throw error;
|
|
5894
|
+
}
|
|
5895
|
+
if (popup) {
|
|
5896
|
+
try {
|
|
5897
|
+
popup.location.replace(session.url);
|
|
5898
|
+
}
|
|
5899
|
+
catch (_f) {
|
|
5900
|
+
try {
|
|
5901
|
+
popup.location.href = session.url;
|
|
5902
|
+
}
|
|
5903
|
+
catch (_g) {
|
|
5904
|
+
try {
|
|
5905
|
+
popup.close();
|
|
5906
|
+
}
|
|
5907
|
+
catch ( /* ignore */_h) { /* ignore */ }
|
|
5908
|
+
throw new Error('onramp(): popup failed to navigate - retry with { newTab: true }');
|
|
5909
|
+
}
|
|
5910
|
+
}
|
|
5911
|
+
return await new Promise((resolve) => {
|
|
5912
|
+
const timer = setInterval(() => {
|
|
5913
|
+
if (popup.closed) {
|
|
5914
|
+
clearInterval(timer);
|
|
5915
|
+
resolve({ status: 'closed', address: session.address, asset: session.asset });
|
|
5916
|
+
}
|
|
5917
|
+
}, 500);
|
|
5918
|
+
});
|
|
5919
|
+
}
|
|
5920
|
+
// New-tab path (popup was blocked or explicitly requested): cross-origin tab
|
|
5921
|
+
// close is not observable, so resolve immediately.
|
|
5922
|
+
const tab = window.open(session.url, '_blank');
|
|
5923
|
+
if (!tab)
|
|
5924
|
+
throw new Error('onramp(): window.open was blocked - call onramp() from a click handler');
|
|
5925
|
+
return { status: 'opened', address: session.address, asset: session.asset };
|
|
5926
|
+
}
|
|
5927
|
+
|
|
5790
5928
|
/**
|
|
5791
5929
|
* Extracts a human-readable error message from Solana transaction logs.
|
|
5792
5930
|
*/
|
|
@@ -5916,7 +6054,7 @@ class PrivyExpoProvider {
|
|
|
5916
6054
|
return { provider: this, address: session.address };
|
|
5917
6055
|
}
|
|
5918
6056
|
// Stale session — clear and continue to fresh login flow
|
|
5919
|
-
core.getActiveSessionManager().clearSession();
|
|
6057
|
+
await core.getActiveSessionManager().clearSession();
|
|
5920
6058
|
}
|
|
5921
6059
|
// Trigger Privy login
|
|
5922
6060
|
const privyUser = await this.privyMethods.login();
|
|
@@ -6097,7 +6235,7 @@ class PrivyExpoProvider {
|
|
|
6097
6235
|
if ((_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.isAuthenticated) {
|
|
6098
6236
|
await this.privyMethods.logout();
|
|
6099
6237
|
}
|
|
6100
|
-
core.getActiveSessionManager().clearSession();
|
|
6238
|
+
await core.getActiveSessionManager().clearSession();
|
|
6101
6239
|
}
|
|
6102
6240
|
async getNativeMethods() {
|
|
6103
6241
|
return this.privyMethods;
|
|
@@ -6208,6 +6346,7 @@ exports.logout = logout;
|
|
|
6208
6346
|
exports.normalizeSolanaRpcUrl = normalizeSolanaRpcUrl;
|
|
6209
6347
|
exports.onAuthLoadingChanged = onAuthLoadingChanged;
|
|
6210
6348
|
exports.onAuthStateChanged = onAuthStateChanged;
|
|
6349
|
+
exports.onramp = onramp;
|
|
6211
6350
|
exports.resolveSolanaRpcUrl = resolveSolanaRpcUrl;
|
|
6212
6351
|
exports.setAuthLoading = setAuthLoading;
|
|
6213
6352
|
exports.setCurrentUser = setCurrentUser;
|
|
@@ -6216,4 +6355,4 @@ exports.signInAnonymously = signInAnonymously;
|
|
|
6216
6355
|
exports.useAuth = useAuth;
|
|
6217
6356
|
exports.useBuildRun = useBuildRun;
|
|
6218
6357
|
exports.useQuery = useQuery;
|
|
6219
|
-
//# sourceMappingURL=index.native-
|
|
6358
|
+
//# sourceMappingURL=index.native-D48QQ0-q.js.map
|