@bounded-sh/client 0.0.27 → 0.0.29

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.
@@ -3596,10 +3596,15 @@ class GuestAuthProvider {
3596
3596
 
3597
3597
  // Web uses localStorage (WebSessionManager); React Native uses the configured
3598
3598
  // ReactNativeSessionManager. getActiveSessionManager() picks the right one by
3599
- // whether the RN manager was configured.
3599
+ // whether the RN manager was configured (NOT `typeof window`, which is truthy on
3600
+ // RN too and would wrongly route to localStorage). Same selector the core
3601
+ // request path uses, so headless email OTP persists + authenticates on BOTH.
3600
3602
  const sessionManager$1 = core.getActiveSessionManager;
3601
- const NO_WALLET = 'Email login is offchain - it has no Solana wallet and cannot sign/submit ' +
3603
+ const NO_WALLET = 'Email login is offchain — it has no Solana wallet and cannot sign/submit ' +
3602
3604
  'transactions. Use a wallet provider for onchain actions, or link a wallet later.';
3605
+ // ---------------------------------------------------------------------------
3606
+ // token / session helpers
3607
+ // ---------------------------------------------------------------------------
3603
3608
  function decodeJwt$1(token) {
3604
3609
  try {
3605
3610
  let b64 = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
@@ -3608,6 +3613,7 @@ function decodeJwt$1(token) {
3608
3613
  b64 += '==';
3609
3614
  else if (pad === 3)
3610
3615
  b64 += '=';
3616
+ // getPlatform().atob is RN-safe (global atob is undefined on Hermes/JSC).
3611
3617
  return JSON.parse(getPlatform().atob(b64));
3612
3618
  }
3613
3619
  catch (_a) {
@@ -3618,12 +3624,194 @@ function userFromIdToken$1(idToken, fallbackEmail) {
3618
3624
  const c = decodeJwt$1(idToken);
3619
3625
  const id = c['custom:userId'] || c.sub || c['custom:walletAddress'] || '';
3620
3626
  const email = (c.email || fallbackEmail || null);
3627
+ // Email logins have no wallet — address is null (the User type allows it).
3621
3628
  return { id, address: (c['custom:walletAddress'] || null), email, provider: emailProviderSingleton };
3622
3629
  }
3630
+ async function humanAuthBase() {
3631
+ const cfg = await core.getConfig();
3632
+ const base = cfg.humanAuthApiUrl || 'https://auth.bounded.sh';
3633
+ return base.replace(/\/$/, '');
3634
+ }
3635
+ async function post(path, body) {
3636
+ const base = await humanAuthBase();
3637
+ let res;
3638
+ try {
3639
+ // Credential-free + no custom header: /email and /verify are open-CORS
3640
+ // (ACAO:*) public OTP routes, so this works inline from ANY app origin (no
3641
+ // popup, no redirect). The OTP is the body secret; the token returns in the
3642
+ // body. Adding credentials or a custom header would break the open-CORS
3643
+ // preflight — keep this a simple JSON POST.
3644
+ res = await fetch(base + path, {
3645
+ method: 'POST',
3646
+ headers: { 'content-type': 'application/json' },
3647
+ body: JSON.stringify(body),
3648
+ });
3649
+ }
3650
+ catch (err) {
3651
+ throw new Error(`Bounded auth request to ${path} failed: ${(err === null || err === void 0 ? void 0 : err.message) || err}`);
3652
+ }
3653
+ let data = null;
3654
+ try {
3655
+ data = await res.json();
3656
+ }
3657
+ catch ( /* non-JSON */_a) { /* non-JSON */ }
3658
+ if (!res.ok) {
3659
+ const msg = (data && (data.error || data.message)) || `HTTP ${res.status}`;
3660
+ throw new Error(String(msg));
3661
+ }
3662
+ return data || {};
3663
+ }
3664
+ // ---------------------------------------------------------------------------
3665
+ // headless primitives (used by the modal AND exported for custom UIs)
3666
+ // ---------------------------------------------------------------------------
3667
+ function normalizePhoneNumber(value) {
3668
+ const compact = String(value || '').trim().replace(/[()\s.-]/g, '');
3669
+ return compact.startsWith('00') ? `+${compact.slice(2)}` : compact;
3670
+ }
3671
+ function assertPhoneNumber(value) {
3672
+ const phoneNumber = normalizePhoneNumber(value);
3673
+ if (!/^\+[1-9]\d{7,14}$/.test(phoneNumber)) {
3674
+ throw new Error('phoneNumber must be in E.164 format, e.g. +14155550132');
3675
+ }
3676
+ return phoneNumber;
3677
+ }
3678
+ /** Send a login code to `email`. Step 1 of the inline email-OTP flow. */
3679
+ async function sendEmailOtp$1(email) {
3680
+ const cfg = await core.getConfig();
3681
+ const e = (email || '').trim().toLowerCase();
3682
+ if (!e)
3683
+ throw new Error('email is required');
3684
+ const data = await post('/email', { email: e, appId: cfg.appId });
3685
+ return { ok: true, expiresInSeconds: data === null || data === void 0 ? void 0 : data.expiresInSeconds };
3686
+ }
3687
+ /** Send a login code by text message. Requires the Bounded issuer to have text OTP explicitly enabled and SMS configured. */
3688
+ async function sendTextOtp$1(phoneNumber) {
3689
+ const cfg = await core.getConfig();
3690
+ const phone = assertPhoneNumber(phoneNumber);
3691
+ const data = await post('/text', { phoneNumber: phone, appId: cfg.appId });
3692
+ return { ok: true, expiresInSeconds: data === null || data === void 0 ? void 0 : data.expiresInSeconds };
3693
+ }
3694
+ /**
3695
+ * Verify the code for `email` and establish the session. Step 2 of the flow.
3696
+ * Stores the Bounded id token (the realtime bearer) and sets the current user.
3697
+ */
3698
+ async function verifyEmailOtp$1(email, otp) {
3699
+ setAuthLoading(true);
3700
+ try {
3701
+ const cfg = await core.getConfig();
3702
+ const e = (email || '').trim().toLowerCase();
3703
+ const code = (otp || '').trim();
3704
+ if (!e || !code)
3705
+ throw new Error('email and code are required');
3706
+ const data = await post('/verify', { email: e, appId: cfg.appId, otp: code });
3707
+ const idToken = data === null || data === void 0 ? void 0 : data.idToken;
3708
+ if (!idToken)
3709
+ throw new Error('No token returned from verification.');
3710
+ const user = userFromIdToken$1(idToken, e);
3711
+ // Store the idToken as BOTH id + access (it is the JWT the realtime worker
3712
+ // verifies and carries `exp`, so the session-manager expiry check works).
3713
+ // address is "" for email (no wallet); the realtime bearer is the idToken.
3714
+ // Persist the rotating refresh token + the issuer base (humanAuthApiUrl) so the
3715
+ // session manager can silently renew via {issuer}/session/refresh — sessions now
3716
+ // live as long as the 30d refresh token instead of dying at the access TTL.
3717
+ const refreshToken = typeof (data === null || data === void 0 ? void 0 : data.refreshToken) === 'string' ? data.refreshToken : '';
3718
+ const issuer = (cfg.humanAuthApiUrl || '').replace(/\/$/, '');
3719
+ await sessionManager$1().storeSession(String(user.address || ''), idToken, idToken, refreshToken, issuer);
3720
+ setCurrentUser(user);
3721
+ return user;
3722
+ }
3723
+ finally {
3724
+ setAuthLoading(false);
3725
+ }
3726
+ }
3727
+ /**
3728
+ * Verify the text-message code for `phoneNumber` and establish the session.
3729
+ * Phone-only users have `user.email === null`; use `user.id` for ownership.
3730
+ */
3731
+ async function verifyTextOtp$1(phoneNumber, otp) {
3732
+ setAuthLoading(true);
3733
+ try {
3734
+ const cfg = await core.getConfig();
3735
+ const phone = assertPhoneNumber(phoneNumber);
3736
+ const code = (otp || '').trim();
3737
+ if (!code)
3738
+ throw new Error('code is required');
3739
+ const data = await post('/text/verify', { phoneNumber: phone, appId: cfg.appId, otp: code });
3740
+ const idToken = data === null || data === void 0 ? void 0 : data.idToken;
3741
+ if (!idToken)
3742
+ throw new Error('No token returned from verification.');
3743
+ const user = userFromIdToken$1(idToken);
3744
+ const refreshToken = typeof (data === null || data === void 0 ? void 0 : data.refreshToken) === 'string' ? data.refreshToken : '';
3745
+ const issuer = (cfg.humanAuthApiUrl || '').replace(/\/$/, '');
3746
+ await sessionManager$1().storeSession(String(user.address || ''), idToken, idToken, refreshToken, issuer);
3747
+ setCurrentUser(user);
3748
+ return user;
3749
+ }
3750
+ finally {
3751
+ setAuthLoading(false);
3752
+ }
3753
+ }
3754
+ /**
3755
+ * UPGRADE an anonymous (guest) session by LINKING an email credential — Firebase
3756
+ * `linkWithCredential` parity. The guest's `guestToken` is sent to the auth issuer
3757
+ * which, IF the email is brand-new, makes the new account ADOPT the guest's id so
3758
+ * `@user.id` is preserved and the guest's data carries over. If the email already
3759
+ * exists, the user just signs into it (stays separate; `linked:false`). On success
3760
+ * the upgraded session replaces the guest session and the user is no longer
3761
+ * anonymous. `guestToken` is captured by the caller BEFORE switching auth methods.
3762
+ */
3763
+ async function linkEmailWithGuest(email, otp, guestToken) {
3764
+ var _a;
3765
+ setAuthLoading(true);
3766
+ try {
3767
+ const cfg = await core.getConfig();
3768
+ const e = (email || '').trim().toLowerCase();
3769
+ const code = (otp || '').trim();
3770
+ if (!e || !code)
3771
+ throw new Error('email and code are required');
3772
+ if (!guestToken)
3773
+ throw new Error('an active anonymous session is required to link an email');
3774
+ // Capture the OLD guest session's refresh token + issuer BEFORE it's overwritten,
3775
+ // so we can revoke the guest refresh family after the upgrade. Otherwise a stolen
3776
+ // guest refresh token would keep minting access to the now-upgraded identity.
3777
+ const oldRefreshToken = sessionManager$1().getRefreshToken();
3778
+ const oldIssuer = (_a = sessionManager$1().getIssuer()) !== null && _a !== void 0 ? _a : undefined;
3779
+ const data = await post('/link/email', { email: e, appId: cfg.appId, otp: code, guestToken });
3780
+ const idToken = data === null || data === void 0 ? void 0 : data.idToken;
3781
+ if (!idToken)
3782
+ throw new Error('No token returned from link.');
3783
+ const user = userFromIdToken$1(idToken, e);
3784
+ // Persist the REAL rotating refresh token + human issuer so the upgraded session
3785
+ // silently renews (was previously stored as '' -> upgraded users couldn't refresh).
3786
+ const refreshToken = typeof (data === null || data === void 0 ? void 0 : data.refreshToken) === 'string' ? data.refreshToken : '';
3787
+ const issuer = (cfg.humanAuthApiUrl || '').replace(/\/$/, '');
3788
+ await sessionManager$1().storeSession(String(user.address || ''), idToken, idToken, refreshToken, issuer);
3789
+ setCurrentUser(user);
3790
+ // Best-effort revoke of the old guest refresh family (upgrade is already committed;
3791
+ // a revoke failure must not break the new session).
3792
+ if (oldRefreshToken && oldRefreshToken !== refreshToken) {
3793
+ try {
3794
+ await core.revokeSession(oldRefreshToken, oldIssuer);
3795
+ }
3796
+ catch ( /* best-effort */_b) { /* best-effort */ }
3797
+ }
3798
+ return { user, linked: !!(data === null || data === void 0 ? void 0 : data.linked), isNewAccount: !!(data === null || data === void 0 ? void 0 : data.isNewAccount) };
3799
+ }
3800
+ finally {
3801
+ setAuthLoading(false);
3802
+ }
3803
+ }
3804
+ // ---------------------------------------------------------------------------
3805
+ // provider
3806
+ // ---------------------------------------------------------------------------
3623
3807
  class EmailAuthProvider {
3624
3808
  async login() {
3625
- throw new Error('login() no longer opens inline email OTP. Use loginWithRedirect({ redirectUri, methods: ["email"] }) ' +
3626
- 'or loginWithPopup({ methods: ["email"] }) instead.');
3809
+ if (!getPlatform().hasDOM) {
3810
+ throw new Error('Email login on this platform (e.g. React Native) is headless: call ' +
3811
+ "sendEmailOtp(email) then verifyEmailOtp(email, code), or, when text OTP is enabled, " +
3812
+ "sendTextOtp(phone) then verifyTextOtp(phone, code). Render your own OTP inputs. The built-in modal is web-only.");
3813
+ }
3814
+ return openEmailModal();
3627
3815
  }
3628
3816
  async restoreSession() {
3629
3817
  const sm = sessionManager$1();
@@ -3641,23 +3829,290 @@ class EmailAuthProvider {
3641
3829
  sessionManager$1().clearSession();
3642
3830
  setCurrentUser(null);
3643
3831
  }
3644
- async signMessage(_message) {
3645
- throw new Error(NO_WALLET);
3646
- }
3647
- async runTransaction(_evm, _sol, _options) {
3648
- throw new Error(NO_WALLET);
3649
- }
3650
- async signTransaction(_transaction) {
3651
- throw new Error(NO_WALLET);
3652
- }
3653
- async signAndSubmitTransaction() {
3654
- throw new Error(NO_WALLET);
3655
- }
3656
- async getNativeMethods() {
3657
- return {};
3658
- }
3832
+ async signMessage(_message) { throw new Error(NO_WALLET); }
3833
+ async runTransaction(_evm, _sol, _options) { throw new Error(NO_WALLET); }
3834
+ async signTransaction(_t) { throw new Error(NO_WALLET); }
3835
+ async signAndSubmitTransaction() { throw new Error(NO_WALLET); }
3836
+ async getNativeMethods() { return {}; }
3659
3837
  }
3660
3838
  const emailProviderSingleton = new EmailAuthProvider();
3839
+ // ---------------------------------------------------------------------------
3840
+ // inline modal (web only) — mobile-first, no popup, no redirect
3841
+ // ---------------------------------------------------------------------------
3842
+ function openEmailModal() {
3843
+ return new Promise((resolve) => {
3844
+ var _a;
3845
+ const root = createEmailModalTree();
3846
+ const style = document.createElement('style');
3847
+ style.textContent = MODAL_CSS;
3848
+ root.appendChild(style);
3849
+ document.body.appendChild(root);
3850
+ const $ = (id) => root.querySelector('#' + id);
3851
+ const emailStep = $('ba-email-step');
3852
+ const otpStep = $('ba-otp-step');
3853
+ const emailInput = $('ba-email');
3854
+ const otpInput = $('ba-otp');
3855
+ const sentTo = $('ba-sent-to');
3856
+ const msg = $('ba-msg');
3857
+ const emailBtn = $('ba-email-btn');
3858
+ const otpBtn = $('ba-otp-btn');
3859
+ let email = '';
3860
+ let done = false;
3861
+ const setMsg = (t, err = false) => { msg.textContent = t; msg.className = 'ba-msg' + (err ? ' err' : ''); };
3862
+ const close = (user) => {
3863
+ var _a;
3864
+ if (done)
3865
+ return;
3866
+ done = true;
3867
+ document.removeEventListener('keydown', onEsc);
3868
+ (_a = root.querySelector('.ba-overlay')) === null || _a === void 0 ? void 0 : _a.classList.add('out');
3869
+ setTimeout(() => root.remove(), 160);
3870
+ resolve(user);
3871
+ };
3872
+ const onEsc = (e) => { if (e.key === 'Escape')
3873
+ close(null); };
3874
+ document.addEventListener('keydown', onEsc);
3875
+ (_a = root.querySelector('.ba-overlay')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', (e) => {
3876
+ if (e.target.classList.contains('ba-overlay'))
3877
+ close(null);
3878
+ });
3879
+ $('ba-close').addEventListener('click', () => close(null));
3880
+ requestAnimationFrame(() => emailInput.focus());
3881
+ emailBtn.addEventListener('click', async () => {
3882
+ email = emailInput.value.trim();
3883
+ if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
3884
+ setMsg('Enter a valid email.', true);
3885
+ return;
3886
+ }
3887
+ emailBtn.disabled = true;
3888
+ setMsg('Sending code…');
3889
+ try {
3890
+ await sendEmailOtp$1(email);
3891
+ sentTo.textContent = email;
3892
+ emailStep.classList.add('hidden');
3893
+ otpStep.classList.remove('hidden');
3894
+ setMsg('');
3895
+ otpInput.focus();
3896
+ }
3897
+ catch (err) {
3898
+ setMsg((err === null || err === void 0 ? void 0 : err.message) || 'Could not send the code.', true);
3899
+ }
3900
+ finally {
3901
+ emailBtn.disabled = false;
3902
+ }
3903
+ });
3904
+ emailInput.addEventListener('keydown', (e) => { if (e.key === 'Enter')
3905
+ emailBtn.click(); });
3906
+ otpBtn.addEventListener('click', async () => {
3907
+ const code = otpInput.value.trim();
3908
+ if (!/^\d{4,8}$/.test(code)) {
3909
+ setMsg('Enter the code from your email.', true);
3910
+ return;
3911
+ }
3912
+ otpBtn.disabled = true;
3913
+ setMsg('Verifying…');
3914
+ try {
3915
+ const user = await verifyEmailOtp$1(email, code);
3916
+ close(user);
3917
+ }
3918
+ catch (err) {
3919
+ setMsg((err === null || err === void 0 ? void 0 : err.message) || 'That code did not work.', true);
3920
+ otpBtn.disabled = false;
3921
+ }
3922
+ });
3923
+ otpInput.addEventListener('keydown', (e) => { if (e.key === 'Enter')
3924
+ otpBtn.click(); });
3925
+ $('ba-back').addEventListener('click', () => {
3926
+ otpStep.classList.add('hidden');
3927
+ emailStep.classList.remove('hidden');
3928
+ setMsg('');
3929
+ emailInput.focus();
3930
+ });
3931
+ });
3932
+ }
3933
+ function createEmailModalTree() {
3934
+ const root = document.createElement('div');
3935
+ root.id = 'bounded-auth-modal';
3936
+ const overlay = document.createElement('div');
3937
+ overlay.className = 'ba-overlay';
3938
+ root.appendChild(overlay);
3939
+ const card = document.createElement('div');
3940
+ card.className = 'ba-card';
3941
+ card.setAttribute('role', 'dialog');
3942
+ card.setAttribute('aria-modal', 'true');
3943
+ card.setAttribute('aria-label', 'Sign in');
3944
+ overlay.appendChild(card);
3945
+ const close = document.createElement('button');
3946
+ close.id = 'ba-close';
3947
+ close.className = 'ba-x';
3948
+ close.setAttribute('aria-label', 'Close');
3949
+ close.type = 'button';
3950
+ close.textContent = '×';
3951
+ card.appendChild(close);
3952
+ // Brand row — the real Bounded mark (same geometry as bounded.sh) + wordmark.
3953
+ const brand = document.createElement('div');
3954
+ brand.className = 'ba-brand';
3955
+ const mark = document.createElement('span');
3956
+ mark.className = 'ba-mark';
3957
+ mark.setAttribute('aria-hidden', 'true');
3958
+ const svgNs = 'http://www.w3.org/2000/svg';
3959
+ const markSvg = document.createElementNS(svgNs, 'svg');
3960
+ markSvg.setAttribute('width', '24');
3961
+ markSvg.setAttribute('height', '24');
3962
+ markSvg.setAttribute('viewBox', '0 0 32 32');
3963
+ markSvg.setAttribute('fill', 'none');
3964
+ for (const [className, d] of [
3965
+ ['ba-c ba-c1', 'M16 5 H5 V16'],
3966
+ ['ba-c ba-c2', 'M16 5 H27 V16'],
3967
+ ['ba-c ba-c3', 'M5 16 V27 H16'],
3968
+ ['ba-c ba-c4', 'M27 16 V27 H16'],
3969
+ ]) {
3970
+ const path = document.createElementNS(svgNs, 'path');
3971
+ path.setAttribute('class', className);
3972
+ path.setAttribute('d', d);
3973
+ markSvg.appendChild(path);
3974
+ }
3975
+ mark.appendChild(markSvg);
3976
+ brand.appendChild(mark);
3977
+ const word = document.createElement('span');
3978
+ word.className = 'ba-word';
3979
+ word.textContent = 'bounded';
3980
+ brand.appendChild(word);
3981
+ card.appendChild(brand);
3982
+ const title = document.createElement('h1');
3983
+ title.className = 'ba-title';
3984
+ title.textContent = 'Sign in';
3985
+ card.appendChild(title);
3986
+ const sub = document.createElement('p');
3987
+ sub.className = 'ba-subtitle';
3988
+ sub.textContent = 'Continue with your email — no wallet needed.';
3989
+ card.appendChild(sub);
3990
+ const emailStep = document.createElement('div');
3991
+ emailStep.id = 'ba-email-step';
3992
+ card.appendChild(emailStep);
3993
+ const emailLabel = document.createElement('label');
3994
+ emailLabel.className = 'ba-label';
3995
+ emailLabel.htmlFor = 'ba-email';
3996
+ emailLabel.textContent = 'Email';
3997
+ emailStep.appendChild(emailLabel);
3998
+ const emailInput = document.createElement('input');
3999
+ emailInput.id = 'ba-email';
4000
+ emailInput.className = 'ba-input';
4001
+ emailInput.type = 'email';
4002
+ emailInput.inputMode = 'email';
4003
+ emailInput.autocomplete = 'email';
4004
+ emailInput.placeholder = 'you@example.com';
4005
+ emailStep.appendChild(emailInput);
4006
+ const emailButton = document.createElement('button');
4007
+ emailButton.id = 'ba-email-btn';
4008
+ emailButton.className = 'ba-btn';
4009
+ emailButton.type = 'button';
4010
+ emailButton.textContent = 'Continue with email';
4011
+ emailStep.appendChild(emailButton);
4012
+ const otpStep = document.createElement('div');
4013
+ otpStep.id = 'ba-otp-step';
4014
+ otpStep.className = 'hidden';
4015
+ card.appendChild(otpStep);
4016
+ const otpLabel = document.createElement('label');
4017
+ otpLabel.className = 'ba-label';
4018
+ otpLabel.htmlFor = 'ba-otp';
4019
+ otpLabel.appendChild(document.createTextNode('Enter the code sent to '));
4020
+ const sentTo = document.createElement('span');
4021
+ sentTo.id = 'ba-sent-to';
4022
+ sentTo.className = 'ba-em';
4023
+ otpLabel.appendChild(sentTo);
4024
+ otpStep.appendChild(otpLabel);
4025
+ const otpInput = document.createElement('input');
4026
+ otpInput.id = 'ba-otp';
4027
+ otpInput.className = 'ba-input ba-code';
4028
+ otpInput.inputMode = 'numeric';
4029
+ otpInput.autocomplete = 'one-time-code';
4030
+ otpInput.maxLength = 8;
4031
+ otpInput.placeholder = '······';
4032
+ otpStep.appendChild(otpInput);
4033
+ const otpButton = document.createElement('button');
4034
+ otpButton.id = 'ba-otp-btn';
4035
+ otpButton.className = 'ba-btn';
4036
+ otpButton.type = 'button';
4037
+ otpButton.textContent = 'Verify & continue';
4038
+ otpStep.appendChild(otpButton);
4039
+ const backButton = document.createElement('button');
4040
+ backButton.id = 'ba-back';
4041
+ backButton.className = 'ba-link';
4042
+ backButton.type = 'button';
4043
+ backButton.textContent = 'Use a different email';
4044
+ otpStep.appendChild(backButton);
4045
+ const msg = document.createElement('div');
4046
+ msg.id = 'ba-msg';
4047
+ msg.className = 'ba-msg';
4048
+ card.appendChild(msg);
4049
+ const foot = document.createElement('div');
4050
+ foot.className = 'ba-foot';
4051
+ foot.textContent = 'Secured by Bounded';
4052
+ card.appendChild(foot);
4053
+ return root;
4054
+ }
4055
+ // Design language matches the hosted Bounded login (auth.bounded.sh) and bounded.sh:
4056
+ // dark editorial panel, green accent, Schibsted Grotesk / Newsreader / JetBrains Mono,
4057
+ // the Bounded mark drawing itself in. Fonts load best-effort (scoped @import); every
4058
+ // rule has a system fallback so the modal looks right even if Google Fonts is blocked.
4059
+ // All selectors are scoped under #bounded-auth-modal so we never leak into the host page.
4060
+ const MODAL_CSS = `
4061
+ @import url('https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,400;6..72,500&family=Schibsted+Grotesk:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');
4062
+ #bounded-auth-modal{--ba-bg:#0a0a0b;--ba-panel:#0e0f11;--ba-inset:#060607;--ba-raise:#131416;
4063
+ --ba-line:rgba(232,230,222,.08);--ba-line-strong:rgba(232,230,222,.16);
4064
+ --ba-text:#e8e6de;--ba-dim:#9b9991;--ba-faint:#85837c;--ba-green:#58c98f;
4065
+ --ba-green-bg:rgba(88,201,143,.09);--ba-green-line:rgba(88,201,143,.28);--ba-red:#ec8488;
4066
+ --ba-body:'Schibsted Grotesk',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
4067
+ --ba-display:'Newsreader','Iowan Old Style',Georgia,serif;
4068
+ --ba-mono:'JetBrains Mono',ui-monospace,'SF Mono',Menlo,monospace;}
4069
+ #bounded-auth-modal .ba-overlay{position:fixed;inset:0;background:rgba(6,6,7,.66);backdrop-filter:blur(4px);
4070
+ display:flex;align-items:center;justify-content:center;z-index:2147483000;opacity:1;transition:opacity .16s ease;
4071
+ font-family:var(--ba-body);padding:16px;}
4072
+ #bounded-auth-modal .ba-overlay.out{opacity:0;}
4073
+ #bounded-auth-modal *{box-sizing:border-box;}
4074
+ #bounded-auth-modal .ba-card{width:100%;max-width:372px;background:var(--ba-panel);color:var(--ba-text);
4075
+ border:1px solid var(--ba-line);border-radius:12px;padding:28px 28px 22px;position:relative;
4076
+ box-shadow:0 1px 0 rgba(232,230,222,.03) inset,0 30px 80px -40px rgba(0,0,0,.8);animation:ba-in .18s ease;}
4077
+ @keyframes ba-in{from{transform:translateY(8px);opacity:.5}to{transform:translateY(0);opacity:1}}
4078
+ #bounded-auth-modal .ba-x{position:absolute;top:14px;right:14px;width:28px;height:28px;border:1px solid var(--ba-line);
4079
+ background:var(--ba-raise);color:var(--ba-faint);border-radius:7px;font-size:18px;line-height:1;cursor:pointer;
4080
+ transition:color .15s,border-color .15s;}
4081
+ #bounded-auth-modal .ba-x:hover{color:var(--ba-text);border-color:var(--ba-faint);}
4082
+ #bounded-auth-modal .ba-brand{display:flex;align-items:center;gap:10px;margin:0 0 24px;}
4083
+ #bounded-auth-modal .ba-mark{display:flex;color:var(--ba-text);}
4084
+ #bounded-auth-modal .ba-mark svg{overflow:visible;display:block;}
4085
+ #bounded-auth-modal .ba-c{stroke:currentColor;stroke-width:2.4;fill:none;}
4086
+ @media (prefers-reduced-motion:no-preference){
4087
+ #bounded-auth-modal .ba-c{stroke-dasharray:23;stroke-dashoffset:23;animation:ba-draw .4s cubic-bezier(.45,0,.2,1) forwards;}
4088
+ #bounded-auth-modal .ba-c1{animation-delay:.1s}#bounded-auth-modal .ba-c2{animation-delay:.38s}
4089
+ #bounded-auth-modal .ba-c3{animation-delay:.66s}#bounded-auth-modal .ba-c4{animation-delay:.94s}}
4090
+ @keyframes ba-draw{to{stroke-dashoffset:0}}
4091
+ #bounded-auth-modal .ba-word{font-family:var(--ba-body);font-weight:500;font-size:15px;letter-spacing:.2px;color:var(--ba-text);}
4092
+ #bounded-auth-modal .ba-title{font-family:var(--ba-display);font-weight:400;font-size:25px;letter-spacing:-.01em;margin:0 0 5px;}
4093
+ #bounded-auth-modal .ba-subtitle{color:var(--ba-dim);font-size:14px;margin:0 0 22px;}
4094
+ #bounded-auth-modal .ba-label{display:block;font-size:12px;color:var(--ba-dim);margin:0 0 7px;}
4095
+ #bounded-auth-modal .ba-em{color:var(--ba-text);font-weight:600;}
4096
+ #bounded-auth-modal .ba-input{width:100%;background:var(--ba-inset);border:1px solid var(--ba-line-strong);color:var(--ba-text);
4097
+ border-radius:6px;padding:11px 13px;font-family:var(--ba-body);font-size:15px;outline:none;transition:border-color .15s,box-shadow .15s;}
4098
+ #bounded-auth-modal .ba-input::placeholder{color:var(--ba-faint);}
4099
+ #bounded-auth-modal .ba-input:focus{border-color:var(--ba-green-line);box-shadow:0 0 0 3px var(--ba-green-bg);}
4100
+ #bounded-auth-modal .ba-code{font-family:var(--ba-mono);letter-spacing:8px;text-align:center;font-size:21px;padding-left:8px;}
4101
+ #bounded-auth-modal .ba-btn{width:100%;margin-top:16px;background:var(--ba-text);color:var(--ba-bg);
4102
+ border:0;border-radius:6px;padding:12px;font-family:var(--ba-body);font-size:14px;font-weight:600;cursor:pointer;
4103
+ transition:opacity .15s,transform .04s;}
4104
+ #bounded-auth-modal .ba-btn:hover{opacity:.9;}
4105
+ #bounded-auth-modal .ba-btn:active{transform:translateY(.5px);}
4106
+ #bounded-auth-modal .ba-btn:disabled{opacity:.45;cursor:default;}
4107
+ #bounded-auth-modal .ba-link{width:100%;margin-top:14px;background:none;border:none;color:var(--ba-dim);
4108
+ font-family:var(--ba-body);font-size:12.5px;cursor:pointer;}
4109
+ #bounded-auth-modal .ba-link:hover{color:var(--ba-text);}
4110
+ #bounded-auth-modal .ba-msg{min-height:16px;margin-top:16px;font-size:12.5px;color:var(--ba-dim);text-align:center;}
4111
+ #bounded-auth-modal .ba-msg.err{color:var(--ba-red);}
4112
+ #bounded-auth-modal .ba-foot{margin-top:26px;padding-top:16px;border-top:1px solid var(--ba-line);
4113
+ text-align:center;font-size:11px;color:var(--ba-faint);}
4114
+ #bounded-auth-modal .hidden{display:none;}
4115
+ @media (max-width:480px){#bounded-auth-modal .ba-card{max-width:none;}}`;
3661
4116
 
3662
4117
  const SURFNET_RPC_URL = "https://surfpool.fly.dev";
3663
4118
  const SUPPORTED_SOLANA_NETWORKS = new Set([
@@ -4359,43 +4814,77 @@ async function loginWithPrivy(options) {
4359
4814
  const result = await provider.login();
4360
4815
  return result ? Object.assign(Object.assign({}, result), { provider }) : null;
4361
4816
  }
4817
+ // Activate the inline email provider (method=email so reload-restore + logout work),
4818
+ // mirroring signInAnonymously. Used by verifyEmailOtp/verifyTextOtp/linkEmail.
4819
+ async function activateEmailProvider() {
4820
+ const provider = new EmailAuthProvider();
4821
+ currentAuthProvider = provider;
4822
+ currentAuthMethod = 'email';
4823
+ currentAuthProviderConfigKey = 'direct:email';
4824
+ const coreConfig = await core.getConfig();
4825
+ coreConfig.authProvider = provider;
4826
+ coreConfig.authMethod = 'email';
4827
+ setAuthProviderInstance(provider);
4828
+ setStoredAuthMethod('email');
4829
+ return provider;
4830
+ }
4362
4831
  /**
4363
- * @deprecated Inline app-origin OTP is retired. Use
4364
- * `loginWithRedirect({ redirectUri, methods: ["email"] })` so the credential is
4365
- * entered on the Bounded hosted issuer.
4832
+ * Send a 6-digit login code to `email` (Bounded Better Auth). Step 1 of the
4833
+ * inline email flow — build your own email/code UI for full control over the
4834
+ * look, or just call `login()` for the built-in modal. Works on web AND React
4835
+ * Native (no DOM needed). Prefer `loginWithRedirect()`/`loginWithPopup()` if you
4836
+ * want the credential entered on Bounded's hosted page instead.
4366
4837
  */
4367
4838
  async function sendEmailOtp(email) {
4368
- throw new Error('sendEmailOtp is retired. Use loginWithRedirect({ redirectUri, methods: ["email"] }) instead.');
4839
+ assertBrowserAuthEnv('sendEmailOtp');
4840
+ return sendEmailOtp$1(email);
4369
4841
  }
4370
4842
  /**
4371
- * @deprecated Inline app-origin text OTP is retired. Use hosted login with
4372
- * `provider: "text"` or `methods: ["text"]` when text OTP is enabled.
4843
+ * Send a 6-digit login code by text message. Requires the configured Bounded
4844
+ * auth issuer to have text OTP explicitly enabled and SMS delivery configured.
4845
+ * Works on web AND React Native.
4373
4846
  */
4374
4847
  async function sendTextOtp(phoneNumber) {
4375
- throw new Error('sendTextOtp is retired. Use loginWithRedirect({ redirectUri, provider: "text" }) instead.');
4848
+ assertBrowserAuthEnv('sendTextOtp');
4849
+ return sendTextOtp$1(phoneNumber);
4376
4850
  }
4377
4851
  /**
4378
- * @deprecated Inline app-origin OTP is retired. Finish hosted login with
4379
- * `completeLoginFromRedirect()` on web; React Native `loginWithRedirect()`
4380
- * resolves inline.
4852
+ * Verify the `code` for `email`, establish the session, and return the user.
4853
+ * Step 2 of the inline email flow. Coexists with signInAnonymously()/wallets.
4381
4854
  */
4382
4855
  async function verifyEmailOtp(email, code) {
4383
- throw new Error('verifyEmailOtp is retired. Use hosted loginWithRedirect instead.');
4856
+ assertBrowserAuthEnv('verifyEmailOtp');
4857
+ await activateEmailProvider();
4858
+ return verifyEmailOtp$1(email, code);
4384
4859
  }
4385
4860
  /**
4386
- * @deprecated Inline app-origin text OTP is retired. Finish hosted login with
4387
- * `completeLoginFromRedirect()` on web; React Native `loginWithRedirect()`
4388
- * resolves inline.
4861
+ * Verify the text-message `code`, establish the session, and return the user.
4862
+ * Phone-only users have no `user.email`; use `user.id` for app identity.
4389
4863
  */
4390
4864
  async function verifyTextOtp(phoneNumber, code) {
4391
- throw new Error('verifyTextOtp is retired. Use hosted loginWithRedirect instead.');
4865
+ assertBrowserAuthEnv('verifyTextOtp');
4866
+ await activateEmailProvider();
4867
+ return verifyTextOtp$1(phoneNumber, code);
4392
4868
  }
4393
4869
  /**
4394
- * @deprecated Inline app-origin guest upgrade is retired. Send the user through
4395
- * hosted login and transfer guest-owned data explicitly.
4870
+ * UPGRADE the current anonymous (guest) session by linking an email — Firebase
4871
+ * `linkWithCredential` parity. Send the code first with `sendEmailOtp(email)`,
4872
+ * then call `linkEmail(email, code)`. If the email is brand-new the guest's
4873
+ * `@user.id` (and its data) is preserved; if the email already exists the user
4874
+ * just signs into it (no merge). Requires an active guest session, and the issuer
4875
+ * refuses if the wallet is already linked. Browser/React-Native only.
4396
4876
  */
4397
4877
  async function linkEmail(email, code) {
4398
- throw new Error('linkEmail is retired. Use hosted login and transfer guest-owned data explicitly.');
4878
+ assertBrowserAuthEnv('linkEmail');
4879
+ // Capture the GUEST token BEFORE switching auth methods — the issuer needs it
4880
+ // to prove guest ownership and adopt its id into the new email account.
4881
+ const guestToken = core.getActiveSessionManager().getIdToken();
4882
+ if (!guestToken) {
4883
+ throw new Error('linkEmail requires an active anonymous session — call signInAnonymously() first.');
4884
+ }
4885
+ await activateEmailProvider(); // method=email so the upgraded user is no longer anonymous
4886
+ const { user } = await linkEmailWithGuest(email, code, guestToken);
4887
+ return user;
4399
4888
  }
4400
4889
  async function login$1(options) {
4401
4890
  // Re-initialize provider if it was cleared by logout