@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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Block-Auth (block-auth.io)
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/dist/index.cjs CHANGED
@@ -1079,7 +1079,8 @@ var BrowserBase = class {
1079
1079
  const storage = getStorage();
1080
1080
  if (!storage) return { ...EXTERNAL_SERVICE_CONFIG };
1081
1081
  const currentConfig = storage.getItem(EXTERNAL_SERVICE);
1082
- if (currentConfig) return JSON.parse(currentConfig);
1082
+ if (currentConfig)
1083
+ return JSON.parse(currentConfig);
1083
1084
  storage.setItem(EXTERNAL_SERVICE, JSON.stringify(EXTERNAL_SERVICE_CONFIG));
1084
1085
  return JSON.parse(
1085
1086
  storage.getItem(EXTERNAL_SERVICE)
@@ -1169,8 +1170,10 @@ var BrowserBase = class {
1169
1170
  if (!storage) return "en";
1170
1171
  const lang = storage.getItem("lang");
1171
1172
  if (lang) return lang;
1172
- storage.setItem("lang", "en");
1173
- return "en";
1173
+ const nav = typeof navigator !== "undefined" ? navigator.language : "";
1174
+ const detected = (nav || "").toLowerCase().startsWith("es") ? "es" : "en";
1175
+ storage.setItem("lang", detected);
1176
+ return detected;
1174
1177
  }
1175
1178
  setLang(lang) {
1176
1179
  getStorage()?.setItem("lang", lang);
@@ -1802,7 +1805,6 @@ async function performLogout(args) {
1802
1805
  if (typeof localStorage !== "undefined") {
1803
1806
  localStorage.setItem("blockauth-logged-out", "true");
1804
1807
  }
1805
- browserBase.reset("all");
1806
1808
  resetWs();
1807
1809
  resetUi();
1808
1810
  resetWallet();
@@ -2157,16 +2159,19 @@ function createBlockAuthClient(config3) {
2157
2159
  }
2158
2160
 
2159
2161
  // src/runtime/authRuntime.ts
2162
+ var SIGNIN_TIMEOUT_MS = 15e3;
2160
2163
  function createAuthRuntime(client, callbacks = {}) {
2161
2164
  const provider = client.provider;
2162
2165
  const hookState = {
2163
2166
  isUnsignTimeoutSet: false,
2164
2167
  isSigned: false,
2165
2168
  isSigning: false,
2166
- lastCheckedDid: null
2169
+ lastCheckedDid: null,
2170
+ signinAttemptId: 0
2167
2171
  };
2168
2172
  let getUserTxnsInterval = null;
2169
2173
  let unsignTimeout = null;
2174
+ let signinTimeout = null;
2170
2175
  const wsc = () => provider.wsc;
2171
2176
  const onSuccess = callbacks.onSuccess ?? (async (_address) => {
2172
2177
  });
@@ -2312,7 +2317,7 @@ function createAuthRuntime(client, callbacks = {}) {
2312
2317
  };
2313
2318
  const signinUnsigned = async () => {
2314
2319
  setIsSignedFirstCheck(true);
2315
- if (!hookState.isSigned && !hookState.isSigning) {
2320
+ if (!hookState.isSigned) {
2316
2321
  const ext = browserBase.getExternalService();
2317
2322
  if (ext.connected && typeof localStorage !== "undefined") {
2318
2323
  localStorage.setItem("blockauth-logged-out", "true");
@@ -2333,11 +2338,18 @@ function createAuthRuntime(client, callbacks = {}) {
2333
2338
  browserBase.clearBrowserState({ keepExtensionInstalled: keepInstalled });
2334
2339
  const result = message.items.at(0);
2335
2340
  onSignup(result);
2336
- void isUserSignedIn();
2341
+ if (result?.isNewAccount) {
2342
+ setIsSignedFirstCheck(true);
2343
+ } else {
2344
+ void isUserSignedIn();
2345
+ }
2337
2346
  };
2338
2347
  const onProviderSignin = (data) => {
2339
2348
  const { success, message } = data;
2340
- if (!success) return;
2349
+ if (!success) {
2350
+ void _onError();
2351
+ return;
2352
+ }
2341
2353
  if (message.items.length <= 0) return;
2342
2354
  if (typeof localStorage !== "undefined") {
2343
2355
  localStorage.removeItem("blockauth-logged-out");
@@ -2364,6 +2376,14 @@ function createAuthRuntime(client, callbacks = {}) {
2364
2376
  if (success) {
2365
2377
  setIsSigning(true);
2366
2378
  hookState.isSigning = true;
2379
+ const attemptId = ++hookState.signinAttemptId;
2380
+ if (signinTimeout) clearTimeout(signinTimeout);
2381
+ signinTimeout = setTimeout(() => {
2382
+ signinTimeout = null;
2383
+ if (hookState.isSigning && hookState.signinAttemptId === attemptId) {
2384
+ void signinUnsigned();
2385
+ }
2386
+ }, SIGNIN_TIMEOUT_MS);
2367
2387
  const s = browserBase.getSession();
2368
2388
  const externalService = browserBase.getExternalService();
2369
2389
  let token = s.token;
@@ -2501,7 +2521,9 @@ function createAuthRuntime(client, callbacks = {}) {
2501
2521
  if (data.message?.session) {
2502
2522
  const session = data.message.session;
2503
2523
  const keepInstalled = browserBase.getUI().installed;
2504
- browserBase.clearBrowserState({ keepExtensionInstalled: keepInstalled });
2524
+ browserBase.clearBrowserState({
2525
+ keepExtensionInstalled: keepInstalled
2526
+ });
2505
2527
  browserBase.setSession({
2506
2528
  did: session.did,
2507
2529
  token: session.token,
@@ -2540,7 +2562,11 @@ function createAuthRuntime(client, callbacks = {}) {
2540
2562
  setIsServiceConnected(externalService.connected);
2541
2563
  setServiceName(externalService.service);
2542
2564
  setServiceIcon(imgUrlByService(externalService.service));
2543
- await provider.connect(client.wsConnectTimeout ?? 300, "", client.wsConnectRetries ?? 3);
2565
+ await provider.connect(
2566
+ client.wsConnectTimeout ?? 300,
2567
+ "",
2568
+ client.wsConnectRetries ?? 3
2569
+ );
2544
2570
  const isConnected = await provider.isConnected();
2545
2571
  if (!isConnected) {
2546
2572
  setIsCheckingAppActive(false);
@@ -2584,6 +2610,11 @@ function createAuthRuntime(client, callbacks = {}) {
2584
2610
  unsignTimeout = null;
2585
2611
  }
2586
2612
  hookState.isUnsignTimeoutSet = false;
2613
+ if (signinTimeout) {
2614
+ clearTimeout(signinTimeout);
2615
+ signinTimeout = null;
2616
+ }
2617
+ hookState.isSigning = false;
2587
2618
  if (getUserTxnsInterval) {
2588
2619
  clearInterval(getUserTxnsInterval);
2589
2620
  getUserTxnsInterval = null;
@@ -2654,8 +2685,99 @@ var TEXTS = {
2654
2685
  webTypeAll: { es: "Todos", en: "All" },
2655
2686
  login: { es: "Iniciar sesi\xF3n", en: "Log In" },
2656
2687
  lastStep: { es: "Completa el \xFAltimo paso", en: "Complete the last step" },
2657
- footerFirst: { es: "\xBFEsperando un registro aburrido?", en: "Expecting a boring signup?" },
2658
- footerSecond: { es: "Di adi\xF3s a las contrase\xF1as", en: "Say goodbye to passwords" }
2688
+ footerFirst: {
2689
+ es: "\xBFEsperando un registro aburrido?",
2690
+ en: "Expecting a boring signup?"
2691
+ },
2692
+ footerSecond: {
2693
+ es: "Di adi\xF3s a las contrase\xF1as",
2694
+ en: "Say goodbye to passwords"
2695
+ },
2696
+ permissionsRequired: {
2697
+ es: "Permisos requeridos",
2698
+ en: "Permissions required"
2699
+ },
2700
+ solicitedData: { es: "Datos solicitados", en: "Solicited data" },
2701
+ reject: { es: "RECHAZAR", en: "REJECT" },
2702
+ accept: { es: "ACEPTAR", en: "ACCEPT" },
2703
+ iAuthorizeThe: { es: "Autorizo la", en: "I authorize the" },
2704
+ privacyPolicy: { es: "Pol\xEDtica de Privacidad", en: "Privacy Policy" },
2705
+ andThe: { es: "y los", en: "and the" },
2706
+ termsAndConditions: {
2707
+ es: "T\xE9rminos y Condiciones",
2708
+ en: "Terms and Conditions"
2709
+ },
2710
+ configureSessionTime: {
2711
+ es: "Quiero configurar el tiempo de mi sesi\xF3n",
2712
+ en: "I want to configure my session time"
2713
+ },
2714
+ solicitsTo: { es: "solicita a", en: "solicits to" },
2715
+ required: { es: "Requerido", en: "Required" },
2716
+ optional: { es: "Opcional", en: "Optional" },
2717
+ fillRequiredFields: {
2718
+ es: "Completa los campos requeridos para continuar",
2719
+ en: "Fill required fields to continue"
2720
+ },
2721
+ noTransactionsFound: {
2722
+ es: "No se encontraron transacciones",
2723
+ en: "No transactions found"
2724
+ },
2725
+ noAppKeyFound: {
2726
+ es: "No se encontr\xF3 la clave de la aplicaci\xF3n",
2727
+ en: "No application key found"
2728
+ },
2729
+ noContractAddressFound: {
2730
+ es: "No se encontr\xF3 la direcci\xF3n del contrato",
2731
+ en: "No contract address found"
2732
+ },
2733
+ noTransactionsParamsFound: {
2734
+ es: "No se encontraron par\xE1metros de la transacci\xF3n",
2735
+ en: "No transaction params found"
2736
+ },
2737
+ somethingWentWrong: { es: "Algo sali\xF3 mal", en: "Something went wrong" },
2738
+ permTemporalIdentity: {
2739
+ es: "Acceso temporal a tu identidad",
2740
+ en: "Temporal access to identity"
2741
+ },
2742
+ permAuthorisedApps: {
2743
+ es: "Acceso a la lista de aplicaciones autorizadas",
2744
+ en: "Access to the list of authorised apps"
2745
+ },
2746
+ permOnlyThisTxn: {
2747
+ es: "Solo se firmar\xE1 esta transacci\xF3n",
2748
+ en: "Only this transaction will be signed"
2749
+ },
2750
+ firstName: { es: "Nombre", en: "First Name" },
2751
+ lastName: { es: "Apellido", en: "Last Name" },
2752
+ secondLastName: { es: "Segundo apellido", en: "Second Last Name" },
2753
+ email: { es: "Correo electr\xF3nico", en: "Email" },
2754
+ phone: { es: "Tel\xE9fono", en: "Phone" },
2755
+ onlyLettersAllowed: {
2756
+ es: "Solo se permiten letras y espacios",
2757
+ en: "Only letters and spaces allowed"
2758
+ },
2759
+ enterValidEmail: {
2760
+ es: "Introduce un correo electr\xF3nico v\xE1lido (ej. nombre@dominio.com)",
2761
+ en: "Enter a valid email (e.g. name@domain.com)"
2762
+ },
2763
+ enterValidPhone: {
2764
+ es: "Introduce un n\xFAmero de tel\xE9fono v\xE1lido",
2765
+ en: "Enter a valid phone number"
2766
+ },
2767
+ helpUsReport: {
2768
+ es: "Ay\xFAdanos a mejorar y reporta el error aqu\xED",
2769
+ en: "Help us get better and report the error here"
2770
+ },
2771
+ thanksForReport: {
2772
+ es: "\xA1Gracias por reportar el error!",
2773
+ en: "Thanks for reporting the error!"
2774
+ },
2775
+ report: { es: "REPORTAR", en: "REPORT" },
2776
+ close: { es: "Cerrar", en: "Close" },
2777
+ modalWillCloseIn: {
2778
+ es: "Este modal se cerrar\xE1 en...",
2779
+ en: "This modal will close in..."
2780
+ }
2659
2781
  };
2660
2782
  function t(key, locale = "en") {
2661
2783
  const entry = TEXTS[key];