@block-auth.io/core 0.9.0 → 0.10.0

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.cjs CHANGED
@@ -8,6 +8,7 @@ var connectors = require('@wagmi/connectors');
8
8
  var chains = require('viem/chains');
9
9
  var msalBrowser = require('@azure/msal-browser');
10
10
  var bs58 = require('bs58');
11
+ var min = require('libphonenumber-js/min');
11
12
  var QRCode = require('qrcode');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -993,6 +994,7 @@ var initial2 = {
993
994
  isSigned: false,
994
995
  isSigningLoader: false,
995
996
  isAcceptingTxn: false,
997
+ acceptTxnError: null,
996
998
  waitingForSuccessLogInSince: 0,
997
999
  isOtpRequired: false,
998
1000
  isOnDeletion: false,
@@ -1011,6 +1013,7 @@ var setIsSigning = (v) => $ui.setKey("isSigning", v);
1011
1013
  var setIsSigned = (v) => $ui.setKey("isSigned", v);
1012
1014
  var setIsSigningLoader = (v) => $ui.setKey("isSigningLoader", v);
1013
1015
  var setIsAcceptingTxn = (v) => $ui.setKey("isAcceptingTxn", v);
1016
+ var setAcceptTxnError = (v) => $ui.setKey("acceptTxnError", v);
1014
1017
  var setWaitingForSuccessLogInSince = (v) => $ui.setKey("waitingForSuccessLogInSince", v);
1015
1018
  var setIsOtpRequired = (v) => $ui.setKey("isOtpRequired", v);
1016
1019
  var setIsOnDeletion = (v) => $ui.setKey("isOnDeletion", v);
@@ -1540,6 +1543,26 @@ async function emitOauthSignup(deps) {
1540
1543
  }
1541
1544
 
1542
1545
  // src/auth/txns.ts
1546
+ var TXN_DATA_TIMEOUT_MS = 3e3;
1547
+ var TXN_DATA_ERROR_KEY = "txn_data_required";
1548
+ var TXN_DATA_MODES = ["required", "optional"];
1549
+ var TXN_DATA_STATUSES = [
1550
+ "shared",
1551
+ "granted",
1552
+ "consent",
1553
+ "missing"
1554
+ ];
1555
+ var toTxnDataParam = (raw) => {
1556
+ if (!raw || typeof raw.slug !== "string") return null;
1557
+ if (!TXN_DATA_MODES.includes(raw.mode)) return null;
1558
+ if (!TXN_DATA_STATUSES.includes(raw.status)) return null;
1559
+ return {
1560
+ slug: raw.slug,
1561
+ mode: raw.mode,
1562
+ status: raw.status,
1563
+ value: typeof raw.value === "string" ? raw.value : null
1564
+ };
1565
+ };
1543
1566
  function requestSignin(args) {
1544
1567
  const { wsc, token, url, service, apiKey, sessionId } = args;
1545
1568
  wsc.emit("user:txns:create", { token, url, service, apiKey, sessionId });
@@ -1551,16 +1574,53 @@ function rejectTxn(args) {
1551
1574
  args.wsc.emit("user:txns:update", { token: args.token, state: "cancelled" });
1552
1575
  }
1553
1576
  function acceptTxn(args) {
1554
- const { wsc, token, lifetime, providerSlug, userParams, sessionId } = args;
1577
+ const {
1578
+ wsc,
1579
+ token,
1580
+ lifetime,
1581
+ providerSlug,
1582
+ userParams,
1583
+ grantedParams,
1584
+ revokedParams,
1585
+ sessionId
1586
+ } = args;
1555
1587
  wsc.emit("provider:signin", {
1556
1588
  token,
1557
1589
  lifetime,
1558
1590
  state: "approved",
1559
1591
  providerSlug,
1560
1592
  userParams: userParams ?? {},
1593
+ grantedParams: grantedParams ?? [],
1594
+ revokedParams: revokedParams ?? [],
1561
1595
  sessionId
1562
1596
  });
1563
1597
  }
1598
+ function requestTxnData(args) {
1599
+ const { wsc, token, txnId, timeoutMs = TXN_DATA_TIMEOUT_MS } = args;
1600
+ const ws = wsc?.ws;
1601
+ if (!ws?.connected) return Promise.resolve(null);
1602
+ return new Promise((resolve) => {
1603
+ const finish = (result) => {
1604
+ clearTimeout(timer);
1605
+ ws.off("user:txns:data", onData);
1606
+ resolve(result);
1607
+ };
1608
+ const onData = (data) => {
1609
+ if (!data?.success) {
1610
+ if (data?.txnId === void 0 || String(data.txnId) === String(txnId))
1611
+ finish(null);
1612
+ return;
1613
+ }
1614
+ const item = data.message?.items?.[0];
1615
+ if (!item || String(item.txnId) !== String(txnId)) return;
1616
+ const params = (Array.isArray(item.params) ? item.params : []).map(toTxnDataParam).filter((param) => !!param);
1617
+ finish({ txnId: item.txnId, params });
1618
+ };
1619
+ const timer = setTimeout(() => finish(null), timeoutMs);
1620
+ ws.on("user:txns:data", onData);
1621
+ ws.emit("user:txns:data", { token, txnId });
1622
+ });
1623
+ }
1564
1624
  function reportTxn(args) {
1565
1625
  args.wsc.emit("ext:report", { token: args.token, report: args.report });
1566
1626
  }
@@ -2394,8 +2454,15 @@ function createBlockAuthClient(config3) {
2394
2454
  lifetime: opts.lifetime,
2395
2455
  providerSlug: $ui.get().serviceName ?? "blockauth",
2396
2456
  userParams: opts.userParams,
2457
+ grantedParams: opts.grantedParams,
2458
+ revokedParams: opts.revokedParams,
2397
2459
  sessionId: browserBase.getDeviceSessionId()
2398
2460
  }),
2461
+ dataRequest: (txnId) => requestTxnData({
2462
+ wsc: provider.wsc,
2463
+ token: userToken(),
2464
+ txnId
2465
+ }),
2399
2466
  report: (slug) => reportTxn({
2400
2467
  wsc: provider.wsc,
2401
2468
  token: userToken(),
@@ -2430,6 +2497,369 @@ function createBlockAuthClient(config3) {
2430
2497
  provider
2431
2498
  };
2432
2499
  }
2500
+ var DEFAULT_PHONE_COUNTRY = "ES";
2501
+ var LEGACY_PHONE_PATTERN = /^(\d{1,4})_(\d{4,14})_([a-z]{2})$/i;
2502
+ var NATIONAL_SEPARATORS = /[\s\-().]/g;
2503
+ var SUPPORTED_COUNTRIES = new Set(min.getCountries());
2504
+ var MAIN_COUNTRY_BY_CALLING_CODE = {
2505
+ "1": "US",
2506
+ "7": "RU",
2507
+ "39": "IT",
2508
+ "44": "GB",
2509
+ "47": "NO",
2510
+ "61": "AU",
2511
+ "212": "MA",
2512
+ "262": "RE",
2513
+ "290": "SH",
2514
+ "358": "FI",
2515
+ "590": "GP",
2516
+ "599": "CW"
2517
+ };
2518
+ var getCallingCodeCountry = (callingCode, fallbackCountry) => min.getCountryCallingCode(fallbackCountry) === callingCode ? fallbackCountry : MAIN_COUNTRY_BY_CALLING_CODE[callingCode] ?? min.getCountries().find(
2519
+ (country) => min.getCountryCallingCode(country) === callingCode
2520
+ ) ?? fallbackCountry;
2521
+ var isPhoneCountry = (value) => !!value && SUPPORTED_COUNTRIES.has(value);
2522
+ var toPhoneCountry = (value) => {
2523
+ const upper = (value ?? "").toUpperCase();
2524
+ return isPhoneCountry(upper) ? upper : null;
2525
+ };
2526
+ function getPhoneCountryFlag(iso2) {
2527
+ const code = iso2.toUpperCase();
2528
+ if (!/^[A-Z]{2}$/.test(code)) return "";
2529
+ return String.fromCodePoint(
2530
+ ...[...code].map((char) => 127462 + char.charCodeAt(0) - 65)
2531
+ );
2532
+ }
2533
+ function getPhoneDialCode(iso2) {
2534
+ return `+${min.getCountryCallingCode(iso2)}`;
2535
+ }
2536
+ var getRegionNames = (locale) => {
2537
+ try {
2538
+ return typeof Intl !== "undefined" && "DisplayNames" in Intl ? new Intl.DisplayNames([locale], { type: "region" }) : null;
2539
+ } catch {
2540
+ return null;
2541
+ }
2542
+ };
2543
+ function getPhoneCountries(locale = "en") {
2544
+ const names = getRegionNames(locale);
2545
+ return min.getCountries().map((iso2) => {
2546
+ let name = iso2;
2547
+ try {
2548
+ name = names?.of(iso2) ?? iso2;
2549
+ } catch {
2550
+ name = iso2;
2551
+ }
2552
+ return {
2553
+ iso2,
2554
+ dialCode: getPhoneDialCode(iso2),
2555
+ flag: getPhoneCountryFlag(iso2),
2556
+ name
2557
+ };
2558
+ }).sort((a, b) => a.name.localeCompare(b.name, locale));
2559
+ }
2560
+ var normalizeSearch = (value) => value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().trim();
2561
+ function searchPhoneCountries(countries, query) {
2562
+ const term = normalizeSearch(query);
2563
+ if (!term) return countries;
2564
+ const digits = term.replace(/^\+/, "");
2565
+ return countries.filter(
2566
+ (country) => normalizeSearch(country.name).includes(term) || country.iso2.toLowerCase() === term || /^\d+$/.test(digits) && country.dialCode.slice(1).startsWith(digits)
2567
+ );
2568
+ }
2569
+ var fromLegacy = (raw) => {
2570
+ const legacy = raw.match(LEGACY_PHONE_PATTERN);
2571
+ return legacy ? `+${legacy[1]}${legacy[2]}` : raw;
2572
+ };
2573
+ var parsePhone = (value, country) => {
2574
+ const raw = (value ?? "").trim();
2575
+ if (!raw) return void 0;
2576
+ try {
2577
+ return min.parsePhoneNumberFromString(fromLegacy(raw), country);
2578
+ } catch {
2579
+ return void 0;
2580
+ }
2581
+ };
2582
+ function isValidPhoneValue(value) {
2583
+ return !!parsePhone(value)?.isValid();
2584
+ }
2585
+ function toPhoneE164(value) {
2586
+ const phone = parsePhone(value);
2587
+ return phone?.isValid() ? phone.number : null;
2588
+ }
2589
+ function formatPhoneForDisplay(value) {
2590
+ const raw = (value ?? "").trim();
2591
+ const phone = parsePhone(raw);
2592
+ return phone?.isValid() ? phone.formatInternational() : raw;
2593
+ }
2594
+ function getDefaultPhoneCountry(languages) {
2595
+ const candidates = languages ?? (typeof navigator !== "undefined" ? [...navigator.languages ?? [], navigator.language] : []);
2596
+ for (const language of candidates) {
2597
+ if (!language) continue;
2598
+ let region;
2599
+ try {
2600
+ region = new Intl.Locale(language).region;
2601
+ } catch {
2602
+ region = language.split(/[-_]/)[1];
2603
+ }
2604
+ const country = toPhoneCountry(region);
2605
+ if (country) return country;
2606
+ }
2607
+ return DEFAULT_PHONE_COUNTRY;
2608
+ }
2609
+ function parsePhoneValue(value, fallbackCountry = getDefaultPhoneCountry()) {
2610
+ const raw = (value ?? "").trim();
2611
+ if (!raw) return { country: fallbackCountry, nationalNumber: "" };
2612
+ const legacy = raw.match(LEGACY_PHONE_PATTERN);
2613
+ const legacyCountry = legacy ? toPhoneCountry(legacy[3]) : null;
2614
+ const phone = parsePhone(raw);
2615
+ if (!phone) {
2616
+ if (!legacy && /^\+\d+$/.test(raw.replace(NATIONAL_SEPARATORS, ""))) {
2617
+ const typer = new min.AsYouType();
2618
+ typer.input(raw);
2619
+ const callingCode = typer.getCallingCode();
2620
+ if (callingCode) {
2621
+ return {
2622
+ country: typer.getCountry() ?? getCallingCodeCountry(callingCode, fallbackCountry),
2623
+ nationalNumber: raw.replace(/\D/g, "").slice(callingCode.length)
2624
+ };
2625
+ }
2626
+ }
2627
+ return {
2628
+ country: legacyCountry ?? fallbackCountry,
2629
+ nationalNumber: raw
2630
+ };
2631
+ }
2632
+ const country = legacyCountry ?? phone.country ?? getCallingCodeCountry(String(phone.countryCallingCode), fallbackCountry);
2633
+ return {
2634
+ country,
2635
+ nationalNumber: phone.isValid() ? phone.formatNational() : String(phone.nationalNumber)
2636
+ };
2637
+ }
2638
+ function buildPhoneE164(country, nationalNumber) {
2639
+ const raw = nationalNumber.trim();
2640
+ if (!raw) return null;
2641
+ const phone = parsePhone(raw, country);
2642
+ return phone?.isValid() ? phone.number : null;
2643
+ }
2644
+ function buildPhoneValue(country, nationalNumber) {
2645
+ const raw = nationalNumber.trim();
2646
+ if (!raw) return "";
2647
+ const e164 = buildPhoneE164(country, raw);
2648
+ if (e164) return e164;
2649
+ const compact = raw.replace(NATIONAL_SEPARATORS, "");
2650
+ return compact.startsWith("+") ? compact : `${getPhoneDialCode(country)}${compact}`;
2651
+ }
2652
+ function updatePhoneDraft(country, nationalNumber) {
2653
+ const raw = nationalNumber.trim();
2654
+ if (raw.startsWith("+")) {
2655
+ const phone = parsePhone(raw);
2656
+ if (phone?.isValid() && phone.country) {
2657
+ return {
2658
+ country: phone.country,
2659
+ nationalNumber: phone.formatNational(),
2660
+ value: phone.number
2661
+ };
2662
+ }
2663
+ }
2664
+ return {
2665
+ country,
2666
+ nationalNumber,
2667
+ value: buildPhoneValue(country, nationalNumber)
2668
+ };
2669
+ }
2670
+ function resolvePhoneDraft(value, draft, fallbackCountry) {
2671
+ const current = value ?? "";
2672
+ if (draft && draft.value === current) return draft;
2673
+ const country = draft?.country ?? fallbackCountry ?? getDefaultPhoneCountry();
2674
+ const parsed = parsePhoneValue(current, country);
2675
+ const keepCountry = !!draft && min.getCountryCallingCode(draft.country) === min.getCountryCallingCode(parsed.country);
2676
+ return {
2677
+ value: current,
2678
+ country: keepCountry ? country : parsed.country,
2679
+ nationalNumber: parsed.nationalNumber
2680
+ };
2681
+ }
2682
+
2683
+ // src/auth/solicitedData.ts
2684
+ var PARAM_LABEL_KEYS = {
2685
+ "users-firstname": "firstName",
2686
+ "users-lastname": "lastName",
2687
+ "users-secondlastname": "secondLastName",
2688
+ "users-email": "email",
2689
+ "users-phone": "phone"
2690
+ };
2691
+ var PARAM_DISPLAY_ORDER = [
2692
+ "users-firstname",
2693
+ "users-lastname",
2694
+ "users-secondlastname",
2695
+ "users-email",
2696
+ "users-phone"
2697
+ ];
2698
+ var PARAM_INPUT_TYPE = {
2699
+ "users-firstname": "text",
2700
+ "users-lastname": "text",
2701
+ "users-secondlastname": "text",
2702
+ "users-email": "email",
2703
+ "users-phone": "tel"
2704
+ };
2705
+ var NAME_PATTERN = /^[A-Za-zÀ-ÖØ-öø-ÿ\s'-]{1,50}$/;
2706
+ var PARAM_VALIDATORS = {
2707
+ "users-firstname": (v) => NAME_PATTERN.test(v.trim()),
2708
+ "users-lastname": (v) => NAME_PATTERN.test(v.trim()),
2709
+ "users-secondlastname": (v) => NAME_PATTERN.test(v.trim()),
2710
+ "users-email": (v) => v.trim().length <= 100 && /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(v.trim()),
2711
+ "users-phone": (v) => isValidPhoneValue(v)
2712
+ };
2713
+ var PARAM_NORMALIZERS = {
2714
+ "users-phone": (v) => toPhoneE164(v) ?? v.trim()
2715
+ };
2716
+ var PARAM_DISPLAY_FORMATTERS = {
2717
+ "users-phone": (v) => formatPhoneForDisplay(v)
2718
+ };
2719
+ var formatParamValue = (slug, value) => {
2720
+ const format = PARAM_DISPLAY_FORMATTERS[slug];
2721
+ return !format ? value : format(value);
2722
+ };
2723
+ var normalizeParamValue = (slug, value) => {
2724
+ const trimmed = value.trim();
2725
+ const normalize = PARAM_NORMALIZERS[slug];
2726
+ return !normalize || !trimmed ? trimmed : normalize(trimmed);
2727
+ };
2728
+ var PARAM_ERROR_KEYS = {
2729
+ "users-firstname": "onlyLettersAllowed",
2730
+ "users-lastname": "onlyLettersAllowed",
2731
+ "users-secondlastname": "onlyLettersAllowed",
2732
+ "users-email": "enterValidEmail",
2733
+ "users-phone": "enterValidPhone"
2734
+ };
2735
+ var EMPTY_SOLICITED_DATA_FORM = {
2736
+ values: {},
2737
+ shared: {},
2738
+ saved: {}
2739
+ };
2740
+ var omitKey = (record, key) => Object.fromEntries(
2741
+ Object.entries(record).filter(([entryKey]) => entryKey !== key)
2742
+ );
2743
+ var isValidParamValue = (slug, value) => {
2744
+ const trimmed = value.trim();
2745
+ if (!trimmed) return false;
2746
+ const validate = PARAM_VALIDATORS[slug];
2747
+ return !validate || validate(trimmed);
2748
+ };
2749
+ function getSolicitedParams({
2750
+ params,
2751
+ requiredParams = [],
2752
+ optionalParams = []
2753
+ }) {
2754
+ const items = params ?? [
2755
+ ...requiredParams.map((slug) => ({
2756
+ slug,
2757
+ mode: "required",
2758
+ status: "missing",
2759
+ value: null
2760
+ })),
2761
+ ...optionalParams.map((slug) => ({
2762
+ slug,
2763
+ mode: "optional",
2764
+ status: "missing",
2765
+ value: null
2766
+ }))
2767
+ ];
2768
+ return PARAM_DISPLAY_ORDER.flatMap((slug) => {
2769
+ const item = items.find((param) => param.slug === slug);
2770
+ return item ? [item] : [];
2771
+ });
2772
+ }
2773
+ function getSolicitedFields(items, form = EMPTY_SOLICITED_DATA_FORM, withConsent = true) {
2774
+ return items.map((item) => {
2775
+ const profileValue = item.value ?? "";
2776
+ const inputValue = form.values[item.slug] ?? profileValue;
2777
+ const trimmed = inputValue.trim();
2778
+ const isEmpty = !trimmed;
2779
+ const isValid = isValidParamValue(item.slug, inputValue);
2780
+ if (!withConsent) {
2781
+ return {
2782
+ ...item,
2783
+ profileValue,
2784
+ inputValue,
2785
+ isEmpty,
2786
+ isShared: !!trimmed,
2787
+ isChanged: !!trimmed,
2788
+ isSaved: !!trimmed,
2789
+ isValid,
2790
+ isComplete: trimmed ? isValid : item.mode !== "required"
2791
+ };
2792
+ }
2793
+ const isChanged = normalizeParamValue(item.slug, trimmed) !== normalizeParamValue(item.slug, profileValue);
2794
+ const savedValue = form.saved[item.slug];
2795
+ const isSaved = isChanged && (isValid || isEmpty) && savedValue === trimmed;
2796
+ const isShared = !isEmpty && (form.shared[item.slug] ?? (item.status === "granted" || item.status === "shared" || isValid && (!profileValue.trim() || savedValue === "")));
2797
+ const isComplete = isShared ? isValid && (!isChanged || isSaved) : item.mode !== "required";
2798
+ return {
2799
+ ...item,
2800
+ profileValue,
2801
+ inputValue,
2802
+ isEmpty,
2803
+ isShared,
2804
+ isChanged,
2805
+ isSaved,
2806
+ isValid,
2807
+ isComplete
2808
+ };
2809
+ });
2810
+ }
2811
+ function getSolicitedHintKey(field, withConsent = true) {
2812
+ if (!withConsent || !field.isChanged) return null;
2813
+ if (!field.isSaved) return "pendingChangeHint";
2814
+ return field.isShared ? "savedToProfileHint" : "notSharedHint";
2815
+ }
2816
+ var isSolicitedHintSuccess = (field) => field.isSaved && field.isShared;
2817
+ var isSolicitedDataComplete = (fields) => fields.every((field) => field.isComplete);
2818
+ function getSolicitedAcceptParams(fields) {
2819
+ const userParams = {};
2820
+ const grantedParams = [];
2821
+ const revokedParams = [];
2822
+ fields.forEach((field) => {
2823
+ if (!field.isShared) {
2824
+ if ((field.status === "granted" || field.status === "shared") && field.mode === "optional")
2825
+ revokedParams.push(field.slug);
2826
+ return;
2827
+ }
2828
+ if (!field.isValid) return;
2829
+ if (field.isChanged) {
2830
+ if (field.isSaved)
2831
+ userParams[field.slug] = normalizeParamValue(
2832
+ field.slug,
2833
+ field.inputValue
2834
+ );
2835
+ return;
2836
+ }
2837
+ if (field.status === "consent" || field.status === "granted")
2838
+ grantedParams.push(field.slug);
2839
+ });
2840
+ return { userParams, grantedParams, revokedParams };
2841
+ }
2842
+ var setSolicitedValue = (form, item, value) => ({
2843
+ ...form,
2844
+ values: { ...form.values, [item.slug]: value }
2845
+ });
2846
+ var setSolicitedShared = (form, slug, shared) => ({
2847
+ ...form,
2848
+ shared: { ...form.shared, [slug]: shared }
2849
+ });
2850
+ var saveSolicitedValue = (form, slug) => {
2851
+ const value = (form.values[slug] ?? "").trim();
2852
+ return {
2853
+ ...form,
2854
+ saved: { ...form.saved, [slug]: value },
2855
+ shared: value ? { ...form.shared, [slug]: true } : form.shared
2856
+ };
2857
+ };
2858
+ var undoSolicitedValue = (form, item) => ({
2859
+ values: omitKey(form.values, item.slug),
2860
+ saved: omitKey(form.saved, item.slug),
2861
+ shared: (item.value ?? "").trim() ? form.shared : omitKey(form.shared, item.slug)
2862
+ });
2433
2863
 
2434
2864
  // src/runtime/authRuntime.ts
2435
2865
  var SIGNIN_TIMEOUT_MS = 12e4;
@@ -2438,6 +2868,9 @@ function createAuthRuntime(client, callbacks = {}) {
2438
2868
  const provider = client.provider;
2439
2869
  const hookState = {
2440
2870
  isUnsignTimeoutSet: false,
2871
+ // When the current L1 signature expires (epoch ms), set with the unsign
2872
+ // timeout; 0 when unknown. Read only while isUnsignTimeoutSet holds.
2873
+ signedExpiresAtMs: 0,
2441
2874
  isSigned: false,
2442
2875
  isSigning: false,
2443
2876
  isLoggingOut: false,
@@ -2691,17 +3124,35 @@ function createAuthRuntime(client, callbacks = {}) {
2691
3124
  const currentDate = new Date(getUTCDateString(/* @__PURE__ */ new Date()));
2692
3125
  const signedExpiredAt = new Date(signedExpiredAtDateString);
2693
3126
  const timeDifference = signedExpiredAt.getTime() - currentDate.getTime();
3127
+ hookState.signedExpiresAtMs = Number.isFinite(timeDifference) ? Date.now() + timeDifference : 0;
2694
3128
  unsignTimeout = setTimeout(() => {
2695
3129
  emitSdkSign(wsc().accessToken, did);
2696
3130
  }, timeDifference);
2697
3131
  };
3132
+ const rearmUnsignTimeout = (signedExpiredAtDateString, did = "") => {
3133
+ const currentDate = new Date(getUTCDateString(/* @__PURE__ */ new Date()));
3134
+ const timeDifference = new Date(signedExpiredAtDateString).getTime() - currentDate.getTime();
3135
+ if (!Number.isFinite(timeDifference)) return;
3136
+ const expiresAtMs = Date.now() + timeDifference;
3137
+ if (Math.abs(expiresAtMs - hookState.signedExpiresAtMs) <= 1e3) return;
3138
+ if (unsignTimeout) {
3139
+ clearTimeout(unsignTimeout);
3140
+ unsignTimeout = null;
3141
+ }
3142
+ setUnsignTimeout(signedExpiredAtDateString, did);
3143
+ };
2698
3144
  const signinUnsigned = async () => {
2699
3145
  setIsSignedFirstCheck(true);
2700
3146
  if (hookState.isSigning) return;
2701
3147
  if (!hookState.isSigned) {
2702
3148
  await _onError();
3149
+ return;
3150
+ }
3151
+ if (signatureExpired()) {
3152
+ await _onError();
2703
3153
  }
2704
3154
  };
3155
+ const signatureExpired = () => hookState.isUnsignTimeoutSet && hookState.signedExpiresAtMs > 0 && Date.now() >= hookState.signedExpiresAtMs;
2705
3156
  const onProviderSignup = (data) => {
2706
3157
  const { success, message } = data;
2707
3158
  if (!success) {
@@ -2722,7 +3173,12 @@ function createAuthRuntime(client, callbacks = {}) {
2722
3173
  }
2723
3174
  };
2724
3175
  const onProviderSignin = (data) => {
2725
- const { success, message } = data;
3176
+ const { success, message, translationKey } = data;
3177
+ if (!success && translationKey === TXN_DATA_ERROR_KEY) {
3178
+ setIsAcceptingTxn(false);
3179
+ setAcceptTxnError(message);
3180
+ return;
3181
+ }
2726
3182
  if (!success) {
2727
3183
  void _onError();
2728
3184
  return;
@@ -2846,6 +3302,9 @@ function createAuthRuntime(client, callbacks = {}) {
2846
3302
  setToken(_token);
2847
3303
  setIsSigned(success);
2848
3304
  hookState.isSigned = success;
3305
+ if (success && hookState.isUnsignTimeoutSet && message?.signedExpiredAt) {
3306
+ rearmUnsignTimeout(message.signedExpiredAt, _did);
3307
+ }
2849
3308
  if (success && !hookState.isUnsignTimeoutSet) {
2850
3309
  if (typeof localStorage !== "undefined") {
2851
3310
  localStorage.removeItem("blockauth-logged-out");
@@ -3212,6 +3671,31 @@ var TEXTS = {
3212
3671
  es: "Completa los campos requeridos para continuar",
3213
3672
  en: "Fill required fields to continue"
3214
3673
  },
3674
+ completeRequiredData: {
3675
+ es: "Autoriza o completa los datos obligatorios para continuar",
3676
+ en: "Authorize or fill in the required data to continue"
3677
+ },
3678
+ requiredDataError: {
3679
+ es: "No se pudo aceptar: faltan datos obligatorios o no son v\xE1lidos. Rev\xEDsalos e int\xE9ntalo de nuevo.",
3680
+ en: "Could not accept: required data is missing or invalid. Please review it and try again."
3681
+ },
3682
+ shareData: { es: "Ceder", en: "Share" },
3683
+ saveData: { es: "Guardar", en: "Save" },
3684
+ undoChange: { es: "Deshacer", en: "Undo" },
3685
+ savedToProfileHint: {
3686
+ es: "Se guardar\xE1 en tu perfil al aceptar",
3687
+ en: "It will be saved to your profile on accept"
3688
+ },
3689
+ pendingChangeHint: {
3690
+ es: "Guarda o deshaz el cambio",
3691
+ en: "Save or undo the change"
3692
+ },
3693
+ notSharedHint: {
3694
+ es: "Este dato no se ceder\xE1",
3695
+ en: "This data will not be shared"
3696
+ },
3697
+ clearField: { es: "Limpiar campo", en: "Clear field" },
3698
+ acceptData: { es: "Aceptar", en: "Accept" },
3215
3699
  noTransactionsFound: {
3216
3700
  es: "No se encontraron transacciones",
3217
3701
  en: "No transactions found"
@@ -3267,6 +3751,12 @@ var TEXTS = {
3267
3751
  es: "Introduce un n\xFAmero de tel\xE9fono v\xE1lido",
3268
3752
  en: "Enter a valid phone number"
3269
3753
  },
3754
+ phoneCountry: { es: "Pa\xEDs", en: "Country" },
3755
+ searchPhoneCountry: { es: "Buscar pa\xEDs o prefijo", en: "Search country or code" },
3756
+ noPhoneCountryResults: {
3757
+ es: "No hay pa\xEDses que coincidan",
3758
+ en: "No matching countries"
3759
+ },
3270
3760
  helpUsReport: {
3271
3761
  es: "Ay\xFAdanos a mejorar y reporta el error aqu\xED",
3272
3762
  en: "Help us get better and report the error here"
@@ -3296,13 +3786,24 @@ exports.$wallet = $wallet;
3296
3786
  exports.$web3 = $web3;
3297
3787
  exports.$ws = $ws;
3298
3788
  exports.BlockAuthProvider = BlockAuthProvider;
3789
+ exports.DEFAULT_PHONE_COUNTRY = DEFAULT_PHONE_COUNTRY;
3299
3790
  exports.DISCOVERY_TIMEOUT_MS = DISCOVERY_TIMEOUT_MS;
3791
+ exports.EMPTY_SOLICITED_DATA_FORM = EMPTY_SOLICITED_DATA_FORM;
3792
+ exports.PARAM_DISPLAY_FORMATTERS = PARAM_DISPLAY_FORMATTERS;
3793
+ exports.PARAM_DISPLAY_ORDER = PARAM_DISPLAY_ORDER;
3794
+ exports.PARAM_ERROR_KEYS = PARAM_ERROR_KEYS;
3795
+ exports.PARAM_INPUT_TYPE = PARAM_INPUT_TYPE;
3796
+ exports.PARAM_LABEL_KEYS = PARAM_LABEL_KEYS;
3797
+ exports.PARAM_NORMALIZERS = PARAM_NORMALIZERS;
3798
+ exports.PARAM_VALIDATORS = PARAM_VALIDATORS;
3300
3799
  exports.RpcClient = RpcClient;
3301
3800
  exports.SDK_PAGE_MARKER = SDK_PAGE_MARKER;
3302
3801
  exports.SYNC_TIMEOUT_MS = SYNC_TIMEOUT_MS;
3303
3802
  exports.TEXTS = TEXTS;
3304
3803
  exports.WsClient = WsClient;
3305
3804
  exports.appearsExtensionInstalled = appearsExtensionInstalled;
3805
+ exports.buildPhoneE164 = buildPhoneE164;
3806
+ exports.buildPhoneValue = buildPhoneValue;
3306
3807
  exports.clearExtensionDomMarkers = clearExtensionDomMarkers;
3307
3808
  exports.clearRemainingAuthData = clearRemainingAuthData;
3308
3809
  exports.clearSdkPresence = clearSdkPresence;
@@ -3318,7 +3819,17 @@ exports.deepLinkFor = deepLinkFor;
3318
3819
  exports.discoverExtensionOnce = discoverExtensionOnce;
3319
3820
  exports.fetchUserProfile = fetchUserProfile;
3320
3821
  exports.finalizeAfterRestorationExpired = finalizeAfterRestorationExpired;
3822
+ exports.formatParamValue = formatParamValue;
3823
+ exports.formatPhoneForDisplay = formatPhoneForDisplay;
3824
+ exports.getDefaultPhoneCountry = getDefaultPhoneCountry;
3321
3825
  exports.getExtensionStoreUrl = getExtensionStoreUrl;
3826
+ exports.getPhoneCountries = getPhoneCountries;
3827
+ exports.getPhoneCountryFlag = getPhoneCountryFlag;
3828
+ exports.getPhoneDialCode = getPhoneDialCode;
3829
+ exports.getSolicitedAcceptParams = getSolicitedAcceptParams;
3830
+ exports.getSolicitedFields = getSolicitedFields;
3831
+ exports.getSolicitedHintKey = getSolicitedHintKey;
3832
+ exports.getSolicitedParams = getSolicitedParams;
3322
3833
  exports.getUserRoleNames = getUserRoleNames;
3323
3834
  exports.getUserRoleSlugs = getUserRoleSlugs;
3324
3835
  exports.getUserRoles = getUserRoles;
@@ -3332,17 +3843,24 @@ exports.isExtensionPresent = isExtensionPresent;
3332
3843
  exports.isExtensionStateComplete = isExtensionStateComplete;
3333
3844
  exports.isFirefox = isFirefox;
3334
3845
  exports.isModalOpen = isModalOpen;
3846
+ exports.isPhoneCountry = isPhoneCountry;
3335
3847
  exports.isRestorationExpiredMessage = isRestorationExpiredMessage;
3336
3848
  exports.isSdkPage = isSdkPage;
3337
3849
  exports.isShowSignin = isShowSignin;
3850
+ exports.isSolicitedDataComplete = isSolicitedDataComplete;
3851
+ exports.isSolicitedHintSuccess = isSolicitedHintSuccess;
3852
+ exports.isValidParamValue = isValidParamValue;
3853
+ exports.isValidPhoneValue = isValidPhoneValue;
3338
3854
  exports.loadUserProfile = loadUserProfile;
3339
3855
  exports.makeQrDataUrl = makeQrDataUrl;
3340
3856
  exports.markSdkPresence = markSdkPresence;
3857
+ exports.normalizeParamValue = normalizeParamValue;
3341
3858
  exports.oauth = oauth_exports;
3342
3859
  exports.onExtensionRemoved = onExtensionRemoved;
3343
3860
  exports.onExtensionStatePublished = onExtensionStatePublished;
3344
3861
  exports.openExtensionOnTxn = openExtensionOnTxn;
3345
3862
  exports.openModal = openModal;
3863
+ exports.parsePhoneValue = parsePhoneValue;
3346
3864
  exports.probeExtensionPresence = probeExtensionPresence;
3347
3865
  exports.reconcileExtensionState = reconcileExtensionState;
3348
3866
  exports.requestExtensionRefresh = requestExtensionRefresh;
@@ -3356,6 +3874,10 @@ exports.resetUser = resetUser;
3356
3874
  exports.resetWallet = resetWallet;
3357
3875
  exports.resetWeb3 = resetWeb3;
3358
3876
  exports.resetWs = resetWs;
3877
+ exports.resolvePhoneDraft = resolvePhoneDraft;
3878
+ exports.saveSolicitedValue = saveSolicitedValue;
3879
+ exports.searchPhoneCountries = searchPhoneCountries;
3880
+ exports.setAcceptTxnError = setAcceptTxnError;
3359
3881
  exports.setApiKey = setApiKey;
3360
3882
  exports.setBackendMessage = setBackendMessage;
3361
3883
  exports.setDeletionAddress = setDeletionAddress;
@@ -3383,6 +3905,8 @@ exports.setServiceIcon = setServiceIcon;
3383
3905
  exports.setServiceName = setServiceName;
3384
3906
  exports.setSignature = setSignature;
3385
3907
  exports.setSignedBy = setSignedBy;
3908
+ exports.setSolicitedShared = setSolicitedShared;
3909
+ exports.setSolicitedValue = setSolicitedValue;
3386
3910
  exports.setToken = setToken;
3387
3911
  exports.setUiConfig = setUiConfig;
3388
3912
  exports.setUser = setUser;
@@ -3390,6 +3914,9 @@ exports.setWaitingForSuccessLogInSince = setWaitingForSuccessLogInSince;
3390
3914
  exports.startExtensionSync = startExtensionSync;
3391
3915
  exports.syncExtensionStateFromStorage = syncExtensionStateFromStorage;
3392
3916
  exports.t = t;
3917
+ exports.toPhoneE164 = toPhoneE164;
3918
+ exports.undoSolicitedValue = undoSolicitedValue;
3919
+ exports.updatePhoneDraft = updatePhoneDraft;
3393
3920
  exports.utils = utils_exports;
3394
3921
  //# sourceMappingURL=index.cjs.map
3395
3922
  //# sourceMappingURL=index.cjs.map