@block-auth.io/core 0.4.0 → 0.4.1

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/index.d.cts CHANGED
@@ -1691,6 +1691,142 @@ declare const TEXTS: {
1691
1691
  readonly es: "Di adiós a las contraseñas";
1692
1692
  readonly en: "Say goodbye to passwords";
1693
1693
  };
1694
+ readonly permissionsRequired: {
1695
+ readonly es: "Permisos requeridos";
1696
+ readonly en: "Permissions required";
1697
+ };
1698
+ readonly solicitedData: {
1699
+ readonly es: "Datos solicitados";
1700
+ readonly en: "Solicited data";
1701
+ };
1702
+ readonly reject: {
1703
+ readonly es: "RECHAZAR";
1704
+ readonly en: "REJECT";
1705
+ };
1706
+ readonly accept: {
1707
+ readonly es: "ACEPTAR";
1708
+ readonly en: "ACCEPT";
1709
+ };
1710
+ readonly iAuthorizeThe: {
1711
+ readonly es: "Autorizo la";
1712
+ readonly en: "I authorize the";
1713
+ };
1714
+ readonly privacyPolicy: {
1715
+ readonly es: "Política de Privacidad";
1716
+ readonly en: "Privacy Policy";
1717
+ };
1718
+ readonly andThe: {
1719
+ readonly es: "y los";
1720
+ readonly en: "and the";
1721
+ };
1722
+ readonly termsAndConditions: {
1723
+ readonly es: "Términos y Condiciones";
1724
+ readonly en: "Terms and Conditions";
1725
+ };
1726
+ readonly configureSessionTime: {
1727
+ readonly es: "Quiero configurar el tiempo de mi sesión";
1728
+ readonly en: "I want to configure my session time";
1729
+ };
1730
+ readonly solicitsTo: {
1731
+ readonly es: "solicita a";
1732
+ readonly en: "solicits to";
1733
+ };
1734
+ readonly required: {
1735
+ readonly es: "Requerido";
1736
+ readonly en: "Required";
1737
+ };
1738
+ readonly optional: {
1739
+ readonly es: "Opcional";
1740
+ readonly en: "Optional";
1741
+ };
1742
+ readonly fillRequiredFields: {
1743
+ readonly es: "Completa los campos requeridos para continuar";
1744
+ readonly en: "Fill required fields to continue";
1745
+ };
1746
+ readonly noTransactionsFound: {
1747
+ readonly es: "No se encontraron transacciones";
1748
+ readonly en: "No transactions found";
1749
+ };
1750
+ readonly noAppKeyFound: {
1751
+ readonly es: "No se encontró la clave de la aplicación";
1752
+ readonly en: "No application key found";
1753
+ };
1754
+ readonly noContractAddressFound: {
1755
+ readonly es: "No se encontró la dirección del contrato";
1756
+ readonly en: "No contract address found";
1757
+ };
1758
+ readonly noTransactionsParamsFound: {
1759
+ readonly es: "No se encontraron parámetros de la transacción";
1760
+ readonly en: "No transaction params found";
1761
+ };
1762
+ readonly somethingWentWrong: {
1763
+ readonly es: "Algo salió mal";
1764
+ readonly en: "Something went wrong";
1765
+ };
1766
+ readonly permTemporalIdentity: {
1767
+ readonly es: "Acceso temporal a tu identidad";
1768
+ readonly en: "Temporal access to identity";
1769
+ };
1770
+ readonly permAuthorisedApps: {
1771
+ readonly es: "Acceso a la lista de aplicaciones autorizadas";
1772
+ readonly en: "Access to the list of authorised apps";
1773
+ };
1774
+ readonly permOnlyThisTxn: {
1775
+ readonly es: "Solo se firmará esta transacción";
1776
+ readonly en: "Only this transaction will be signed";
1777
+ };
1778
+ readonly firstName: {
1779
+ readonly es: "Nombre";
1780
+ readonly en: "First Name";
1781
+ };
1782
+ readonly lastName: {
1783
+ readonly es: "Apellido";
1784
+ readonly en: "Last Name";
1785
+ };
1786
+ readonly secondLastName: {
1787
+ readonly es: "Segundo apellido";
1788
+ readonly en: "Second Last Name";
1789
+ };
1790
+ readonly email: {
1791
+ readonly es: "Correo electrónico";
1792
+ readonly en: "Email";
1793
+ };
1794
+ readonly phone: {
1795
+ readonly es: "Teléfono";
1796
+ readonly en: "Phone";
1797
+ };
1798
+ readonly onlyLettersAllowed: {
1799
+ readonly es: "Solo se permiten letras y espacios";
1800
+ readonly en: "Only letters and spaces allowed";
1801
+ };
1802
+ readonly enterValidEmail: {
1803
+ readonly es: "Introduce un correo electrónico válido (ej. nombre@dominio.com)";
1804
+ readonly en: "Enter a valid email (e.g. name@domain.com)";
1805
+ };
1806
+ readonly enterValidPhone: {
1807
+ readonly es: "Introduce un número de teléfono válido";
1808
+ readonly en: "Enter a valid phone number";
1809
+ };
1810
+ readonly helpUsReport: {
1811
+ readonly es: "Ayúdanos a mejorar y reporta el error aquí";
1812
+ readonly en: "Help us get better and report the error here";
1813
+ };
1814
+ readonly thanksForReport: {
1815
+ readonly es: "¡Gracias por reportar el error!";
1816
+ readonly en: "Thanks for reporting the error!";
1817
+ };
1818
+ readonly report: {
1819
+ readonly es: "REPORTAR";
1820
+ readonly en: "REPORT";
1821
+ };
1822
+ readonly close: {
1823
+ readonly es: "Cerrar";
1824
+ readonly en: "Close";
1825
+ };
1826
+ readonly modalWillCloseIn: {
1827
+ readonly es: "Este modal se cerrará en...";
1828
+ readonly en: "This modal will close in...";
1829
+ };
1694
1830
  };
1695
1831
  type TextKey = keyof typeof TEXTS;
1696
1832
  declare function t(key: TextKey, locale?: Locale): string;
package/dist/index.d.ts CHANGED
@@ -1691,6 +1691,142 @@ declare const TEXTS: {
1691
1691
  readonly es: "Di adiós a las contraseñas";
1692
1692
  readonly en: "Say goodbye to passwords";
1693
1693
  };
1694
+ readonly permissionsRequired: {
1695
+ readonly es: "Permisos requeridos";
1696
+ readonly en: "Permissions required";
1697
+ };
1698
+ readonly solicitedData: {
1699
+ readonly es: "Datos solicitados";
1700
+ readonly en: "Solicited data";
1701
+ };
1702
+ readonly reject: {
1703
+ readonly es: "RECHAZAR";
1704
+ readonly en: "REJECT";
1705
+ };
1706
+ readonly accept: {
1707
+ readonly es: "ACEPTAR";
1708
+ readonly en: "ACCEPT";
1709
+ };
1710
+ readonly iAuthorizeThe: {
1711
+ readonly es: "Autorizo la";
1712
+ readonly en: "I authorize the";
1713
+ };
1714
+ readonly privacyPolicy: {
1715
+ readonly es: "Política de Privacidad";
1716
+ readonly en: "Privacy Policy";
1717
+ };
1718
+ readonly andThe: {
1719
+ readonly es: "y los";
1720
+ readonly en: "and the";
1721
+ };
1722
+ readonly termsAndConditions: {
1723
+ readonly es: "Términos y Condiciones";
1724
+ readonly en: "Terms and Conditions";
1725
+ };
1726
+ readonly configureSessionTime: {
1727
+ readonly es: "Quiero configurar el tiempo de mi sesión";
1728
+ readonly en: "I want to configure my session time";
1729
+ };
1730
+ readonly solicitsTo: {
1731
+ readonly es: "solicita a";
1732
+ readonly en: "solicits to";
1733
+ };
1734
+ readonly required: {
1735
+ readonly es: "Requerido";
1736
+ readonly en: "Required";
1737
+ };
1738
+ readonly optional: {
1739
+ readonly es: "Opcional";
1740
+ readonly en: "Optional";
1741
+ };
1742
+ readonly fillRequiredFields: {
1743
+ readonly es: "Completa los campos requeridos para continuar";
1744
+ readonly en: "Fill required fields to continue";
1745
+ };
1746
+ readonly noTransactionsFound: {
1747
+ readonly es: "No se encontraron transacciones";
1748
+ readonly en: "No transactions found";
1749
+ };
1750
+ readonly noAppKeyFound: {
1751
+ readonly es: "No se encontró la clave de la aplicación";
1752
+ readonly en: "No application key found";
1753
+ };
1754
+ readonly noContractAddressFound: {
1755
+ readonly es: "No se encontró la dirección del contrato";
1756
+ readonly en: "No contract address found";
1757
+ };
1758
+ readonly noTransactionsParamsFound: {
1759
+ readonly es: "No se encontraron parámetros de la transacción";
1760
+ readonly en: "No transaction params found";
1761
+ };
1762
+ readonly somethingWentWrong: {
1763
+ readonly es: "Algo salió mal";
1764
+ readonly en: "Something went wrong";
1765
+ };
1766
+ readonly permTemporalIdentity: {
1767
+ readonly es: "Acceso temporal a tu identidad";
1768
+ readonly en: "Temporal access to identity";
1769
+ };
1770
+ readonly permAuthorisedApps: {
1771
+ readonly es: "Acceso a la lista de aplicaciones autorizadas";
1772
+ readonly en: "Access to the list of authorised apps";
1773
+ };
1774
+ readonly permOnlyThisTxn: {
1775
+ readonly es: "Solo se firmará esta transacción";
1776
+ readonly en: "Only this transaction will be signed";
1777
+ };
1778
+ readonly firstName: {
1779
+ readonly es: "Nombre";
1780
+ readonly en: "First Name";
1781
+ };
1782
+ readonly lastName: {
1783
+ readonly es: "Apellido";
1784
+ readonly en: "Last Name";
1785
+ };
1786
+ readonly secondLastName: {
1787
+ readonly es: "Segundo apellido";
1788
+ readonly en: "Second Last Name";
1789
+ };
1790
+ readonly email: {
1791
+ readonly es: "Correo electrónico";
1792
+ readonly en: "Email";
1793
+ };
1794
+ readonly phone: {
1795
+ readonly es: "Teléfono";
1796
+ readonly en: "Phone";
1797
+ };
1798
+ readonly onlyLettersAllowed: {
1799
+ readonly es: "Solo se permiten letras y espacios";
1800
+ readonly en: "Only letters and spaces allowed";
1801
+ };
1802
+ readonly enterValidEmail: {
1803
+ readonly es: "Introduce un correo electrónico válido (ej. nombre@dominio.com)";
1804
+ readonly en: "Enter a valid email (e.g. name@domain.com)";
1805
+ };
1806
+ readonly enterValidPhone: {
1807
+ readonly es: "Introduce un número de teléfono válido";
1808
+ readonly en: "Enter a valid phone number";
1809
+ };
1810
+ readonly helpUsReport: {
1811
+ readonly es: "Ayúdanos a mejorar y reporta el error aquí";
1812
+ readonly en: "Help us get better and report the error here";
1813
+ };
1814
+ readonly thanksForReport: {
1815
+ readonly es: "¡Gracias por reportar el error!";
1816
+ readonly en: "Thanks for reporting the error!";
1817
+ };
1818
+ readonly report: {
1819
+ readonly es: "REPORTAR";
1820
+ readonly en: "REPORT";
1821
+ };
1822
+ readonly close: {
1823
+ readonly es: "Cerrar";
1824
+ readonly en: "Close";
1825
+ };
1826
+ readonly modalWillCloseIn: {
1827
+ readonly es: "Este modal se cerrará en...";
1828
+ readonly en: "This modal will close in...";
1829
+ };
1694
1830
  };
1695
1831
  type TextKey = keyof typeof TEXTS;
1696
1832
  declare function t(key: TextKey, locale?: Locale): string;
package/dist/index.js CHANGED
@@ -1071,7 +1071,8 @@ var BrowserBase = class {
1071
1071
  const storage = getStorage();
1072
1072
  if (!storage) return { ...EXTERNAL_SERVICE_CONFIG };
1073
1073
  const currentConfig = storage.getItem(EXTERNAL_SERVICE);
1074
- if (currentConfig) return JSON.parse(currentConfig);
1074
+ if (currentConfig)
1075
+ return JSON.parse(currentConfig);
1075
1076
  storage.setItem(EXTERNAL_SERVICE, JSON.stringify(EXTERNAL_SERVICE_CONFIG));
1076
1077
  return JSON.parse(
1077
1078
  storage.getItem(EXTERNAL_SERVICE)
@@ -1161,8 +1162,10 @@ var BrowserBase = class {
1161
1162
  if (!storage) return "en";
1162
1163
  const lang = storage.getItem("lang");
1163
1164
  if (lang) return lang;
1164
- storage.setItem("lang", "en");
1165
- return "en";
1165
+ const nav = typeof navigator !== "undefined" ? navigator.language : "";
1166
+ const detected = (nav || "").toLowerCase().startsWith("es") ? "es" : "en";
1167
+ storage.setItem("lang", detected);
1168
+ return detected;
1166
1169
  }
1167
1170
  setLang(lang) {
1168
1171
  getStorage()?.setItem("lang", lang);
@@ -1794,7 +1797,6 @@ async function performLogout(args) {
1794
1797
  if (typeof localStorage !== "undefined") {
1795
1798
  localStorage.setItem("blockauth-logged-out", "true");
1796
1799
  }
1797
- browserBase.reset("all");
1798
1800
  resetWs();
1799
1801
  resetUi();
1800
1802
  resetWallet();
@@ -2149,16 +2151,19 @@ function createBlockAuthClient(config3) {
2149
2151
  }
2150
2152
 
2151
2153
  // src/runtime/authRuntime.ts
2154
+ var SIGNIN_TIMEOUT_MS = 15e3;
2152
2155
  function createAuthRuntime(client, callbacks = {}) {
2153
2156
  const provider = client.provider;
2154
2157
  const hookState = {
2155
2158
  isUnsignTimeoutSet: false,
2156
2159
  isSigned: false,
2157
2160
  isSigning: false,
2158
- lastCheckedDid: null
2161
+ lastCheckedDid: null,
2162
+ signinAttemptId: 0
2159
2163
  };
2160
2164
  let getUserTxnsInterval = null;
2161
2165
  let unsignTimeout = null;
2166
+ let signinTimeout = null;
2162
2167
  const wsc = () => provider.wsc;
2163
2168
  const onSuccess = callbacks.onSuccess ?? (async (_address) => {
2164
2169
  });
@@ -2304,7 +2309,7 @@ function createAuthRuntime(client, callbacks = {}) {
2304
2309
  };
2305
2310
  const signinUnsigned = async () => {
2306
2311
  setIsSignedFirstCheck(true);
2307
- if (!hookState.isSigned && !hookState.isSigning) {
2312
+ if (!hookState.isSigned) {
2308
2313
  const ext = browserBase.getExternalService();
2309
2314
  if (ext.connected && typeof localStorage !== "undefined") {
2310
2315
  localStorage.setItem("blockauth-logged-out", "true");
@@ -2325,11 +2330,18 @@ function createAuthRuntime(client, callbacks = {}) {
2325
2330
  browserBase.clearBrowserState({ keepExtensionInstalled: keepInstalled });
2326
2331
  const result = message.items.at(0);
2327
2332
  onSignup(result);
2328
- void isUserSignedIn();
2333
+ if (result?.isNewAccount) {
2334
+ setIsSignedFirstCheck(true);
2335
+ } else {
2336
+ void isUserSignedIn();
2337
+ }
2329
2338
  };
2330
2339
  const onProviderSignin = (data) => {
2331
2340
  const { success, message } = data;
2332
- if (!success) return;
2341
+ if (!success) {
2342
+ void _onError();
2343
+ return;
2344
+ }
2333
2345
  if (message.items.length <= 0) return;
2334
2346
  if (typeof localStorage !== "undefined") {
2335
2347
  localStorage.removeItem("blockauth-logged-out");
@@ -2356,6 +2368,14 @@ function createAuthRuntime(client, callbacks = {}) {
2356
2368
  if (success) {
2357
2369
  setIsSigning(true);
2358
2370
  hookState.isSigning = true;
2371
+ const attemptId = ++hookState.signinAttemptId;
2372
+ if (signinTimeout) clearTimeout(signinTimeout);
2373
+ signinTimeout = setTimeout(() => {
2374
+ signinTimeout = null;
2375
+ if (hookState.isSigning && hookState.signinAttemptId === attemptId) {
2376
+ void signinUnsigned();
2377
+ }
2378
+ }, SIGNIN_TIMEOUT_MS);
2359
2379
  const s = browserBase.getSession();
2360
2380
  const externalService = browserBase.getExternalService();
2361
2381
  let token = s.token;
@@ -2493,7 +2513,9 @@ function createAuthRuntime(client, callbacks = {}) {
2493
2513
  if (data.message?.session) {
2494
2514
  const session = data.message.session;
2495
2515
  const keepInstalled = browserBase.getUI().installed;
2496
- browserBase.clearBrowserState({ keepExtensionInstalled: keepInstalled });
2516
+ browserBase.clearBrowserState({
2517
+ keepExtensionInstalled: keepInstalled
2518
+ });
2497
2519
  browserBase.setSession({
2498
2520
  did: session.did,
2499
2521
  token: session.token,
@@ -2532,7 +2554,11 @@ function createAuthRuntime(client, callbacks = {}) {
2532
2554
  setIsServiceConnected(externalService.connected);
2533
2555
  setServiceName(externalService.service);
2534
2556
  setServiceIcon(imgUrlByService(externalService.service));
2535
- await provider.connect(client.wsConnectTimeout ?? 300, "", client.wsConnectRetries ?? 3);
2557
+ await provider.connect(
2558
+ client.wsConnectTimeout ?? 300,
2559
+ "",
2560
+ client.wsConnectRetries ?? 3
2561
+ );
2536
2562
  const isConnected = await provider.isConnected();
2537
2563
  if (!isConnected) {
2538
2564
  setIsCheckingAppActive(false);
@@ -2576,6 +2602,11 @@ function createAuthRuntime(client, callbacks = {}) {
2576
2602
  unsignTimeout = null;
2577
2603
  }
2578
2604
  hookState.isUnsignTimeoutSet = false;
2605
+ if (signinTimeout) {
2606
+ clearTimeout(signinTimeout);
2607
+ signinTimeout = null;
2608
+ }
2609
+ hookState.isSigning = false;
2579
2610
  if (getUserTxnsInterval) {
2580
2611
  clearInterval(getUserTxnsInterval);
2581
2612
  getUserTxnsInterval = null;
@@ -2646,8 +2677,99 @@ var TEXTS = {
2646
2677
  webTypeAll: { es: "Todos", en: "All" },
2647
2678
  login: { es: "Iniciar sesi\xF3n", en: "Log In" },
2648
2679
  lastStep: { es: "Completa el \xFAltimo paso", en: "Complete the last step" },
2649
- footerFirst: { es: "\xBFEsperando un registro aburrido?", en: "Expecting a boring signup?" },
2650
- footerSecond: { es: "Di adi\xF3s a las contrase\xF1as", en: "Say goodbye to passwords" }
2680
+ footerFirst: {
2681
+ es: "\xBFEsperando un registro aburrido?",
2682
+ en: "Expecting a boring signup?"
2683
+ },
2684
+ footerSecond: {
2685
+ es: "Di adi\xF3s a las contrase\xF1as",
2686
+ en: "Say goodbye to passwords"
2687
+ },
2688
+ permissionsRequired: {
2689
+ es: "Permisos requeridos",
2690
+ en: "Permissions required"
2691
+ },
2692
+ solicitedData: { es: "Datos solicitados", en: "Solicited data" },
2693
+ reject: { es: "RECHAZAR", en: "REJECT" },
2694
+ accept: { es: "ACEPTAR", en: "ACCEPT" },
2695
+ iAuthorizeThe: { es: "Autorizo la", en: "I authorize the" },
2696
+ privacyPolicy: { es: "Pol\xEDtica de Privacidad", en: "Privacy Policy" },
2697
+ andThe: { es: "y los", en: "and the" },
2698
+ termsAndConditions: {
2699
+ es: "T\xE9rminos y Condiciones",
2700
+ en: "Terms and Conditions"
2701
+ },
2702
+ configureSessionTime: {
2703
+ es: "Quiero configurar el tiempo de mi sesi\xF3n",
2704
+ en: "I want to configure my session time"
2705
+ },
2706
+ solicitsTo: { es: "solicita a", en: "solicits to" },
2707
+ required: { es: "Requerido", en: "Required" },
2708
+ optional: { es: "Opcional", en: "Optional" },
2709
+ fillRequiredFields: {
2710
+ es: "Completa los campos requeridos para continuar",
2711
+ en: "Fill required fields to continue"
2712
+ },
2713
+ noTransactionsFound: {
2714
+ es: "No se encontraron transacciones",
2715
+ en: "No transactions found"
2716
+ },
2717
+ noAppKeyFound: {
2718
+ es: "No se encontr\xF3 la clave de la aplicaci\xF3n",
2719
+ en: "No application key found"
2720
+ },
2721
+ noContractAddressFound: {
2722
+ es: "No se encontr\xF3 la direcci\xF3n del contrato",
2723
+ en: "No contract address found"
2724
+ },
2725
+ noTransactionsParamsFound: {
2726
+ es: "No se encontraron par\xE1metros de la transacci\xF3n",
2727
+ en: "No transaction params found"
2728
+ },
2729
+ somethingWentWrong: { es: "Algo sali\xF3 mal", en: "Something went wrong" },
2730
+ permTemporalIdentity: {
2731
+ es: "Acceso temporal a tu identidad",
2732
+ en: "Temporal access to identity"
2733
+ },
2734
+ permAuthorisedApps: {
2735
+ es: "Acceso a la lista de aplicaciones autorizadas",
2736
+ en: "Access to the list of authorised apps"
2737
+ },
2738
+ permOnlyThisTxn: {
2739
+ es: "Solo se firmar\xE1 esta transacci\xF3n",
2740
+ en: "Only this transaction will be signed"
2741
+ },
2742
+ firstName: { es: "Nombre", en: "First Name" },
2743
+ lastName: { es: "Apellido", en: "Last Name" },
2744
+ secondLastName: { es: "Segundo apellido", en: "Second Last Name" },
2745
+ email: { es: "Correo electr\xF3nico", en: "Email" },
2746
+ phone: { es: "Tel\xE9fono", en: "Phone" },
2747
+ onlyLettersAllowed: {
2748
+ es: "Solo se permiten letras y espacios",
2749
+ en: "Only letters and spaces allowed"
2750
+ },
2751
+ enterValidEmail: {
2752
+ es: "Introduce un correo electr\xF3nico v\xE1lido (ej. nombre@dominio.com)",
2753
+ en: "Enter a valid email (e.g. name@domain.com)"
2754
+ },
2755
+ enterValidPhone: {
2756
+ es: "Introduce un n\xFAmero de tel\xE9fono v\xE1lido",
2757
+ en: "Enter a valid phone number"
2758
+ },
2759
+ helpUsReport: {
2760
+ es: "Ay\xFAdanos a mejorar y reporta el error aqu\xED",
2761
+ en: "Help us get better and report the error here"
2762
+ },
2763
+ thanksForReport: {
2764
+ es: "\xA1Gracias por reportar el error!",
2765
+ en: "Thanks for reporting the error!"
2766
+ },
2767
+ report: { es: "REPORTAR", en: "REPORT" },
2768
+ close: { es: "Cerrar", en: "Close" },
2769
+ modalWillCloseIn: {
2770
+ es: "Este modal se cerrar\xE1 en...",
2771
+ en: "This modal will close in..."
2772
+ }
2651
2773
  };
2652
2774
  function t(key, locale = "en") {
2653
2775
  const entry = TEXTS[key];