altcha 3.0.0-beta.2 → 3.0.0-beta.3
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/README.md +5 -2
- package/dist/external/altcha.js +247 -36
- package/dist/external/altcha.min.js +1 -1
- package/dist/external/altcha.umd.cjs +247 -36
- package/dist/external/altcha.umd.min.cjs +1 -1
- package/dist/lib/index.d.ts +18 -6
- package/dist/lib/index.js +3 -1
- package/dist/lib/index.min.js +1 -1
- package/dist/lib/index.umd.cjs +3 -1
- package/dist/lib/index.umd.min.cjs +1 -1
- package/dist/main/altcha.i18n.js +253 -40
- package/dist/main/altcha.i18n.min.js +1 -1
- package/dist/main/altcha.i18n.umd.cjs +253 -40
- package/dist/main/altcha.i18n.umd.min.cjs +1 -1
- package/dist/main/altcha.js +253 -40
- package/dist/main/altcha.min.js +1 -1
- package/dist/main/altcha.umd.cjs +253 -40
- package/dist/main/altcha.umd.min.cjs +1 -1
- package/dist/plugins/obfuscation.plugin.js +55 -14
- package/dist/plugins/obfuscation.plugin.min.js +1 -1
- package/dist/plugins/obfuscation.plugin.umd.cjs +55 -14
- package/dist/plugins/obfuscation.plugin.umd.min.cjs +1 -1
- package/dist/types/generic.d.ts +4 -1
- package/dist/types/index.d.ts +18 -6
- package/dist/workers/argon2id.js +3 -2
- package/dist/workers/pbkdf2.js +3 -2
- package/dist/workers/scrypt.js +3 -2
- package/dist/workers/sha.js +3 -2
- package/package.json +2 -2
- package/dist/external/index.d.ts +0 -1
|
@@ -5433,7 +5433,7 @@
|
|
|
5433
5433
|
var root$1 = /* @__PURE__ */ from_html(`<!> <div><!> <!> <div class="altcha-popover-content"><!></div></div>`, 1);
|
|
5434
5434
|
function Popover($$anchor, $$props) {
|
|
5435
5435
|
push($$props, true);
|
|
5436
|
-
let anchor = prop($$props, "anchor"), children = prop($$props, "children"), display = prop($$props, "display", 7, "standard"), backdrop = prop($$props, "backdrop", 7, false), onClickOutside = prop($$props, "onClickOutside"), onClickOutsideDelay = prop($$props, "onClickOutsideDelay", 7, 600), onClose = prop($$props, "onClose"), variant = prop($$props, "variant", 7, "neutral"), rest = /* @__PURE__ */ rest_props($$props, [
|
|
5436
|
+
let anchor = prop($$props, "anchor"), children = prop($$props, "children"), display = prop($$props, "display", 7, "standard"), backdrop = prop($$props, "backdrop", 7, false), onClickOutside = prop($$props, "onClickOutside"), onClickOutsideDelay = prop($$props, "onClickOutsideDelay", 7, 600), onClose = prop($$props, "onClose"), placement = prop($$props, "placement", 7, "auto"), variant = prop($$props, "variant", 7, "neutral"), rest = /* @__PURE__ */ rest_props($$props, [
|
|
5437
5437
|
"$$slots",
|
|
5438
5438
|
"$$events",
|
|
5439
5439
|
"$$legacy",
|
|
@@ -5445,12 +5445,18 @@
|
|
|
5445
5445
|
"onClickOutside",
|
|
5446
5446
|
"onClickOutsideDelay",
|
|
5447
5447
|
"onClose",
|
|
5448
|
+
"placement",
|
|
5448
5449
|
"variant"
|
|
5449
5450
|
]);
|
|
5450
5451
|
let el = /* @__PURE__ */ state(void 0);
|
|
5451
5452
|
let elBackdrop = /* @__PURE__ */ state(void 0);
|
|
5452
5453
|
let top = /* @__PURE__ */ state(false);
|
|
5453
5454
|
let mountedAt = /* @__PURE__ */ state(0);
|
|
5455
|
+
user_effect(() => {
|
|
5456
|
+
if (placement() !== "auto") {
|
|
5457
|
+
set(top, placement() === "top");
|
|
5458
|
+
}
|
|
5459
|
+
});
|
|
5454
5460
|
onMount(() => {
|
|
5455
5461
|
const moveToBody = display() === "bottomsheet" || display() === "overlay";
|
|
5456
5462
|
if (moveToBody) {
|
|
@@ -5484,7 +5490,7 @@
|
|
|
5484
5490
|
reposition();
|
|
5485
5491
|
}
|
|
5486
5492
|
function reposition() {
|
|
5487
|
-
if (anchor() && get(el)) {
|
|
5493
|
+
if (anchor() && placement() === "auto" && get(el)) {
|
|
5488
5494
|
const boundary2 = anchor().getBoundingClientRect();
|
|
5489
5495
|
const bottomGap = document.documentElement.clientHeight - (boundary2.top + boundary2.height);
|
|
5490
5496
|
const newTop = bottomGap < get(el).clientHeight;
|
|
@@ -5543,6 +5549,13 @@
|
|
|
5543
5549
|
onClose($$value);
|
|
5544
5550
|
flushSync();
|
|
5545
5551
|
},
|
|
5552
|
+
get placement() {
|
|
5553
|
+
return placement();
|
|
5554
|
+
},
|
|
5555
|
+
set placement($$value = "auto") {
|
|
5556
|
+
placement($$value);
|
|
5557
|
+
flushSync();
|
|
5558
|
+
},
|
|
5546
5559
|
get variant() {
|
|
5547
5560
|
return variant();
|
|
5548
5561
|
},
|
|
@@ -5616,6 +5629,7 @@
|
|
|
5616
5629
|
onClickOutside: {},
|
|
5617
5630
|
onClickOutsideDelay: {},
|
|
5618
5631
|
onClose: {},
|
|
5632
|
+
placement: {},
|
|
5619
5633
|
variant: {}
|
|
5620
5634
|
},
|
|
5621
5635
|
[],
|
|
@@ -5640,7 +5654,8 @@
|
|
|
5640
5654
|
controller = new AbortController(),
|
|
5641
5655
|
createWorker,
|
|
5642
5656
|
onOutOfMemory = (c) => c > 1 ? Math.floor(c / 2) : 0,
|
|
5643
|
-
counterMode
|
|
5657
|
+
counterMode,
|
|
5658
|
+
timeout = 9e4
|
|
5644
5659
|
} = options;
|
|
5645
5660
|
const workersConcurrency = Math.min(16, Math.max(1, concurrency));
|
|
5646
5661
|
const workersInstances = [];
|
|
@@ -5681,6 +5696,7 @@
|
|
|
5681
5696
|
counterMode,
|
|
5682
5697
|
counterStart: i,
|
|
5683
5698
|
counterStep: workersConcurrency,
|
|
5699
|
+
timeout,
|
|
5684
5700
|
type: "work"
|
|
5685
5701
|
});
|
|
5686
5702
|
});
|
|
@@ -5712,6 +5728,147 @@
|
|
|
5712
5728
|
}
|
|
5713
5729
|
return solution || null;
|
|
5714
5730
|
}
|
|
5731
|
+
class Collector {
|
|
5732
|
+
TAG_CODES = {
|
|
5733
|
+
INPUT: 1,
|
|
5734
|
+
TEXTAREA: 2,
|
|
5735
|
+
SELECT: 3,
|
|
5736
|
+
BUTTON: 4,
|
|
5737
|
+
A: 5,
|
|
5738
|
+
DETAILS: 6,
|
|
5739
|
+
SUMMARY: 7,
|
|
5740
|
+
IFRAME: 8,
|
|
5741
|
+
VIDEO: 9,
|
|
5742
|
+
AUDIO: 10
|
|
5743
|
+
};
|
|
5744
|
+
maxSamples;
|
|
5745
|
+
sampleInterval;
|
|
5746
|
+
target;
|
|
5747
|
+
focusStartTime = 0;
|
|
5748
|
+
focusInteraction = 0;
|
|
5749
|
+
focusInteractionTimer = null;
|
|
5750
|
+
lastPointerSample = 0;
|
|
5751
|
+
lastTouchSample = 0;
|
|
5752
|
+
lastScrollSample = 0;
|
|
5753
|
+
pendingPointer = null;
|
|
5754
|
+
pendingTouch = null;
|
|
5755
|
+
focus = [];
|
|
5756
|
+
pointer = [];
|
|
5757
|
+
scroll = [];
|
|
5758
|
+
touch = [];
|
|
5759
|
+
constructor(options = {}) {
|
|
5760
|
+
const { maxSamples = 60, sampleInterval = 50, target = window } = options;
|
|
5761
|
+
this.maxSamples = maxSamples;
|
|
5762
|
+
this.sampleInterval = sampleInterval;
|
|
5763
|
+
this.target = target;
|
|
5764
|
+
this.attach();
|
|
5765
|
+
}
|
|
5766
|
+
destroy() {
|
|
5767
|
+
const o = { capture: true };
|
|
5768
|
+
this.target.removeEventListener("focusin", this.onFocus, o);
|
|
5769
|
+
this.target.removeEventListener("keydown", this.onInteraction, o);
|
|
5770
|
+
this.target.removeEventListener("pointerdown", this.onInteraction, o);
|
|
5771
|
+
this.target.removeEventListener("pointermove", this.onPointer, o);
|
|
5772
|
+
this.target.removeEventListener("scroll", this.onScroll, o);
|
|
5773
|
+
this.target.removeEventListener("touchmove", this.onTouchMove, o);
|
|
5774
|
+
}
|
|
5775
|
+
export() {
|
|
5776
|
+
return {
|
|
5777
|
+
focus: this.focus,
|
|
5778
|
+
maxTouchPoints: navigator.maxTouchPoints || 0,
|
|
5779
|
+
pointer: this.pointer,
|
|
5780
|
+
scroll: this.scroll,
|
|
5781
|
+
time: Date.now(),
|
|
5782
|
+
touch: this.touch
|
|
5783
|
+
};
|
|
5784
|
+
}
|
|
5785
|
+
attach() {
|
|
5786
|
+
const o = { passive: true, capture: true };
|
|
5787
|
+
this.target.addEventListener("focusin", this.onFocus, o);
|
|
5788
|
+
this.target.addEventListener("keydown", this.onInteraction, o);
|
|
5789
|
+
this.target.addEventListener("pointerdown", this.onInteraction, o);
|
|
5790
|
+
this.target.addEventListener("pointermove", this.onPointer, o);
|
|
5791
|
+
this.target.addEventListener("scroll", this.onScroll, o);
|
|
5792
|
+
this.target.addEventListener("touchmove", this.onTouchMove, o);
|
|
5793
|
+
}
|
|
5794
|
+
evict(buffer) {
|
|
5795
|
+
if (buffer.length > this.maxSamples) {
|
|
5796
|
+
buffer.splice(0, buffer.length - this.maxSamples);
|
|
5797
|
+
}
|
|
5798
|
+
}
|
|
5799
|
+
onFocus = (e) => {
|
|
5800
|
+
if (this.focusInteraction === 2) {
|
|
5801
|
+
return;
|
|
5802
|
+
}
|
|
5803
|
+
const el = e.target;
|
|
5804
|
+
if (!(el instanceof Element)) {
|
|
5805
|
+
return;
|
|
5806
|
+
}
|
|
5807
|
+
const now = performance.now();
|
|
5808
|
+
if (this.focusStartTime === 0) {
|
|
5809
|
+
this.focusStartTime = now;
|
|
5810
|
+
}
|
|
5811
|
+
this.focus.push([
|
|
5812
|
+
Math.round(now - this.focusStartTime),
|
|
5813
|
+
el.tabIndex,
|
|
5814
|
+
this.TAG_CODES[el.tagName] ?? 0,
|
|
5815
|
+
this.focusInteraction ? 1 : 0
|
|
5816
|
+
]);
|
|
5817
|
+
this.evict(this.focus);
|
|
5818
|
+
};
|
|
5819
|
+
onInteraction = (e) => {
|
|
5820
|
+
this.focusInteraction = "keyCode" in e ? 1 : 2;
|
|
5821
|
+
if (this.focusInteractionTimer) {
|
|
5822
|
+
clearTimeout(this.focusInteractionTimer);
|
|
5823
|
+
}
|
|
5824
|
+
this.focusInteractionTimer = setTimeout(() => {
|
|
5825
|
+
this.focusInteraction = 0;
|
|
5826
|
+
}, 100);
|
|
5827
|
+
};
|
|
5828
|
+
onPointer = (e) => {
|
|
5829
|
+
if (e.pointerType === "touch") {
|
|
5830
|
+
return;
|
|
5831
|
+
}
|
|
5832
|
+
const now = e.timeStamp || performance.now();
|
|
5833
|
+
this.pendingPointer = [Math.round(e.clientX), Math.round(e.clientY), Math.round(now)];
|
|
5834
|
+
if (now - this.lastPointerSample >= this.sampleInterval) {
|
|
5835
|
+
this.pointer.push(this.pendingPointer);
|
|
5836
|
+
this.lastPointerSample = now;
|
|
5837
|
+
this.pendingPointer = null;
|
|
5838
|
+
this.evict(this.pointer);
|
|
5839
|
+
}
|
|
5840
|
+
};
|
|
5841
|
+
onScroll = () => {
|
|
5842
|
+
const now = performance.now();
|
|
5843
|
+
if (now - this.lastScrollSample < this.sampleInterval) {
|
|
5844
|
+
return;
|
|
5845
|
+
}
|
|
5846
|
+
this.scroll.push([Math.round(window.scrollY), Math.round(now)]);
|
|
5847
|
+
this.lastScrollSample = now;
|
|
5848
|
+
this.evict(this.scroll);
|
|
5849
|
+
};
|
|
5850
|
+
onTouchMove = (e) => {
|
|
5851
|
+
const now = e.timeStamp || performance.now();
|
|
5852
|
+
const t = e.touches[0];
|
|
5853
|
+
if (!t) {
|
|
5854
|
+
return;
|
|
5855
|
+
}
|
|
5856
|
+
this.pendingTouch = [
|
|
5857
|
+
Math.round(t.clientX),
|
|
5858
|
+
Math.round(t.clientY),
|
|
5859
|
+
Math.round(now),
|
|
5860
|
+
Math.round(t.force * 1e3) / 1e3,
|
|
5861
|
+
Math.round(t.radiusX || 0),
|
|
5862
|
+
Math.round(t.radiusY || 0)
|
|
5863
|
+
];
|
|
5864
|
+
if (now - this.lastTouchSample >= this.sampleInterval) {
|
|
5865
|
+
this.touch.push(this.pendingTouch);
|
|
5866
|
+
this.lastTouchSample = now;
|
|
5867
|
+
this.pendingTouch = null;
|
|
5868
|
+
this.evict(this.touch);
|
|
5869
|
+
}
|
|
5870
|
+
};
|
|
5871
|
+
}
|
|
5715
5872
|
var root_1 = /* @__PURE__ */ from_html(`<div class="altcha-overlay-backdrop" data-backdrop=""></div>`);
|
|
5716
5873
|
var root_3 = /* @__PURE__ */ from_html(`<div class="altcha-overlay-content"></div>`);
|
|
5717
5874
|
var root_2 = /* @__PURE__ */ from_html(`<div role="button" class="altcha-overlay-close">×</div> <!>`, 1);
|
|
@@ -5742,6 +5899,7 @@
|
|
|
5742
5899
|
instance?.dispatchEvent(new CustomEvent(event2, { detail }));
|
|
5743
5900
|
});
|
|
5744
5901
|
};
|
|
5902
|
+
let hisCollector = null;
|
|
5745
5903
|
let baseUrl = /* @__PURE__ */ state(proxy(new URL(location.origin)));
|
|
5746
5904
|
let checked = /* @__PURE__ */ state(false);
|
|
5747
5905
|
let codeChallenge = /* @__PURE__ */ state(null);
|
|
@@ -5776,16 +5934,19 @@
|
|
|
5776
5934
|
floatingPlacement: "auto",
|
|
5777
5935
|
hideFooter: false,
|
|
5778
5936
|
hideLogo: false,
|
|
5937
|
+
humanInteractionSignature: true,
|
|
5779
5938
|
language: "",
|
|
5780
5939
|
mockError: false,
|
|
5781
5940
|
minDuration: 500,
|
|
5782
5941
|
overlayContent: "",
|
|
5783
5942
|
name: "altcha",
|
|
5943
|
+
popoverPlacement: "auto",
|
|
5784
5944
|
retryOnOutOfMemoryError: true,
|
|
5785
5945
|
setCookie: null,
|
|
5786
5946
|
serverVerificationFields: false,
|
|
5787
5947
|
serverVerificationTimeZone: false,
|
|
5788
5948
|
test: false,
|
|
5949
|
+
timeout: 9e4,
|
|
5789
5950
|
type: "checkbox",
|
|
5790
5951
|
validationMessage: "",
|
|
5791
5952
|
verifyFunction: null,
|
|
@@ -5796,6 +5957,7 @@
|
|
|
5796
5957
|
}));
|
|
5797
5958
|
const checkboxId = /* @__PURE__ */ user_derived(() => `altcha-checkbox-${$$props.id || Math.floor(Math.random() * 1e12).toString(16)}`);
|
|
5798
5959
|
const CheckboxComponent = /* @__PURE__ */ user_derived(() => getCheckboxComponent(get(config).type));
|
|
5960
|
+
const auto = /* @__PURE__ */ user_derived(() => get(config).auto);
|
|
5799
5961
|
const loading = /* @__PURE__ */ user_derived(() => get(currentState) === State.VERIFYING);
|
|
5800
5962
|
const showFooter = /* @__PURE__ */ user_derived(() => !get(config).hideFooter);
|
|
5801
5963
|
const showLogo = /* @__PURE__ */ user_derived(() => !get(config).hideLogo && get(config).display !== "bar");
|
|
@@ -5857,7 +6019,7 @@
|
|
|
5857
6019
|
}
|
|
5858
6020
|
});
|
|
5859
6021
|
user_effect(() => {
|
|
5860
|
-
if (get(
|
|
6022
|
+
if (get(auto) === "onload") {
|
|
5861
6023
|
const tm = setTimeout(
|
|
5862
6024
|
() => {
|
|
5863
6025
|
verify();
|
|
@@ -5882,15 +6044,19 @@
|
|
|
5882
6044
|
}
|
|
5883
6045
|
});
|
|
5884
6046
|
onMount(() => {
|
|
5885
|
-
log("mounted", "3.0.0-beta.
|
|
6047
|
+
log("mounted", "3.0.0-beta.3");
|
|
5886
6048
|
if (instance) {
|
|
5887
6049
|
globalThis.$altcha.instances.add(instance);
|
|
5888
6050
|
}
|
|
5889
6051
|
set(elForm, get(elRoot)?.closest("form"), true);
|
|
5890
6052
|
get(elForm)?.addEventListener("reset", onFormReset);
|
|
5891
|
-
get(elForm)?.addEventListener("submit", onFormSubmit);
|
|
6053
|
+
get(elForm)?.addEventListener("submit", onFormSubmit, { capture: true });
|
|
5892
6054
|
get(elForm)?.addEventListener("focusin", onFormFocusIn);
|
|
5893
6055
|
activatePlugins();
|
|
6056
|
+
if (get(config).humanInteractionSignature) {
|
|
6057
|
+
log("human interaction signature enabled");
|
|
6058
|
+
hisCollector = new Collector();
|
|
6059
|
+
}
|
|
5894
6060
|
dispatch("load");
|
|
5895
6061
|
if (!isSecureContext) {
|
|
5896
6062
|
log("secure context (HTTPS) required");
|
|
@@ -5904,8 +6070,9 @@
|
|
|
5904
6070
|
clearTimeout(get(expirationTimeout));
|
|
5905
6071
|
}
|
|
5906
6072
|
get(elForm)?.removeEventListener("reset", onFormReset);
|
|
5907
|
-
get(elForm)?.removeEventListener("submit", onFormSubmit);
|
|
6073
|
+
get(elForm)?.removeEventListener("submit", onFormSubmit, { capture: true });
|
|
5908
6074
|
get(elForm)?.removeEventListener("focusin", onFormFocusIn);
|
|
6075
|
+
hisCollector?.destroy();
|
|
5909
6076
|
};
|
|
5910
6077
|
});
|
|
5911
6078
|
function activatePlugins() {
|
|
@@ -5969,23 +6136,41 @@
|
|
|
5969
6136
|
async function delay(ms) {
|
|
5970
6137
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
5971
6138
|
}
|
|
5972
|
-
async function fetchChallenge(source2 = get(config).challenge) {
|
|
6139
|
+
async function fetchChallenge(source2 = get(config).challenge, requestOptions) {
|
|
5973
6140
|
const hook = await callHook("onFetchChallenge", source2);
|
|
6141
|
+
let challenge = null;
|
|
5974
6142
|
if (hook !== void 0) {
|
|
5975
6143
|
return hook;
|
|
5976
6144
|
}
|
|
5977
6145
|
if (typeof source2 === "string") {
|
|
5978
|
-
let challenge = null;
|
|
5979
6146
|
if (source2.match(/^(https?:)?\//)) {
|
|
5980
|
-
log("fetching challenge from", source2);
|
|
6147
|
+
log("fetching challenge from", requestOptions?.method || "GET", source2);
|
|
5981
6148
|
set(baseUrl, new URL(source2, location.origin), true);
|
|
5982
|
-
const resp = await get(config).fetch(source2, {
|
|
5983
|
-
|
|
6149
|
+
const resp = await get(config).fetch(source2, {
|
|
6150
|
+
credentials: get(config).credentials || void 0,
|
|
6151
|
+
...requestOptions
|
|
6152
|
+
});
|
|
6153
|
+
await validateResponse(resp);
|
|
5984
6154
|
const configHeader = resp.headers.get("x-altcha-config");
|
|
5985
6155
|
if (configHeader) {
|
|
5986
6156
|
processConfigHeader(configHeader);
|
|
5987
6157
|
}
|
|
5988
|
-
|
|
6158
|
+
const json = await resp.json();
|
|
6159
|
+
if (json && "his" in json && json.his) {
|
|
6160
|
+
log("requested HIS");
|
|
6161
|
+
if (!hisCollector) {
|
|
6162
|
+
throw new Error("Server requested HIS data but collector is disabled.");
|
|
6163
|
+
}
|
|
6164
|
+
return fetchChallenge(getUrl(json.his.url, get(baseUrl)), {
|
|
6165
|
+
body: JSON.stringify({ his: hisCollector.export() }),
|
|
6166
|
+
headers: { "content-type": "application/json" },
|
|
6167
|
+
method: "POST"
|
|
6168
|
+
});
|
|
6169
|
+
}
|
|
6170
|
+
if (json && "hisResult" in json && json.hisResult) {
|
|
6171
|
+
log("HIS result", json.hisResult);
|
|
6172
|
+
}
|
|
6173
|
+
challenge = json;
|
|
5989
6174
|
} else {
|
|
5990
6175
|
log("parsing JSON challenge");
|
|
5991
6176
|
try {
|
|
@@ -5994,20 +6179,26 @@
|
|
|
5994
6179
|
throw new Error(`Unable to parse JSON challenge.`);
|
|
5995
6180
|
}
|
|
5996
6181
|
}
|
|
5997
|
-
if (typeof challenge === "object" && "challenge" in challenge) {
|
|
5998
|
-
challenge = createChallengeFromV1(challenge);
|
|
5999
|
-
}
|
|
6000
|
-
if (!isChallengeValid(challenge)) {
|
|
6001
|
-
throw new Error(`Challenge validation failed.`);
|
|
6002
|
-
}
|
|
6003
|
-
return challenge;
|
|
6004
6182
|
} else if (source2 && typeof source2 === "object") {
|
|
6005
|
-
|
|
6183
|
+
try {
|
|
6184
|
+
challenge = JSON.parse(JSON.stringify(source2));
|
|
6185
|
+
} catch {
|
|
6186
|
+
throw new Error(`Unable to parse JSON challenge.`);
|
|
6187
|
+
}
|
|
6006
6188
|
}
|
|
6007
|
-
|
|
6189
|
+
if (isChallengeV1(challenge)) {
|
|
6190
|
+
challenge = createChallengeFromV1(challenge);
|
|
6191
|
+
}
|
|
6192
|
+
if (!isChallengeValid(challenge)) {
|
|
6193
|
+
throw new Error(`Challenge validation failed.`);
|
|
6194
|
+
}
|
|
6195
|
+
return challenge;
|
|
6196
|
+
}
|
|
6197
|
+
function isChallengeV1(challenge) {
|
|
6198
|
+
return typeof challenge === "object" && "challenge" in challenge;
|
|
6008
6199
|
}
|
|
6009
6200
|
function isChallengeValid(challenge) {
|
|
6010
|
-
return !!challenge && typeof challenge === "object" && "parameters" in challenge &&
|
|
6201
|
+
return !!challenge && typeof challenge === "object" && "parameters" in challenge && !!challenge.parameters && typeof challenge.parameters === "object" && "algorithm" in challenge.parameters && "nonce" in challenge.parameters && "salt" in challenge.parameters && "keyPrefix" in challenge.parameters;
|
|
6011
6202
|
}
|
|
6012
6203
|
function getCheckboxElement() {
|
|
6013
6204
|
return document.getElementById(get(checkboxId));
|
|
@@ -6120,7 +6311,7 @@
|
|
|
6120
6311
|
}
|
|
6121
6312
|
}
|
|
6122
6313
|
function onFormFocusIn(ev) {
|
|
6123
|
-
if (get(
|
|
6314
|
+
if (get(auto) === "onfocus" && get(currentState) === State.UNVERIFIED) {
|
|
6124
6315
|
verify();
|
|
6125
6316
|
}
|
|
6126
6317
|
}
|
|
@@ -6133,7 +6324,7 @@
|
|
|
6133
6324
|
}
|
|
6134
6325
|
function onFormSubmit(ev) {
|
|
6135
6326
|
set(elSubmitter, ev.submitter, true);
|
|
6136
|
-
if (get(
|
|
6327
|
+
if (get(auto) === "onsubmit" && get(currentState) === State.UNVERIFIED) {
|
|
6137
6328
|
ev.preventDefault();
|
|
6138
6329
|
ev.stopPropagation();
|
|
6139
6330
|
show();
|
|
@@ -6219,7 +6410,7 @@
|
|
|
6219
6410
|
headers: { "Content-Type": "application/json" },
|
|
6220
6411
|
method: "POST"
|
|
6221
6412
|
});
|
|
6222
|
-
validateResponse(resp);
|
|
6413
|
+
await validateResponse(resp);
|
|
6223
6414
|
const json = await resp.json();
|
|
6224
6415
|
if (json && typeof json === "object" && "payload" in json && !!json.payload) {
|
|
6225
6416
|
dispatch("serververification", json);
|
|
@@ -6260,7 +6451,7 @@
|
|
|
6260
6451
|
case "floating":
|
|
6261
6452
|
case "overlay":
|
|
6262
6453
|
hide();
|
|
6263
|
-
if (!get(
|
|
6454
|
+
if (!get(auto) || get(auto) === "off") {
|
|
6264
6455
|
get(userConfig).auto = "onsubmit";
|
|
6265
6456
|
}
|
|
6266
6457
|
break;
|
|
@@ -6288,8 +6479,18 @@
|
|
|
6288
6479
|
onExpired();
|
|
6289
6480
|
}
|
|
6290
6481
|
}
|
|
6291
|
-
function validateResponse(resp) {
|
|
6482
|
+
async function validateResponse(resp) {
|
|
6292
6483
|
if (resp.status >= 400) {
|
|
6484
|
+
if (resp.headers.get("content-type")?.includes("/json")) {
|
|
6485
|
+
let json;
|
|
6486
|
+
try {
|
|
6487
|
+
json = await resp.json();
|
|
6488
|
+
} catch {
|
|
6489
|
+
}
|
|
6490
|
+
if (json && "error" in json) {
|
|
6491
|
+
throw new Error(`Server responded with ${resp.status} - ${json.error}`);
|
|
6492
|
+
}
|
|
6493
|
+
}
|
|
6293
6494
|
throw new Error(`Server responded with ${resp.status}.`);
|
|
6294
6495
|
}
|
|
6295
6496
|
const contentType = resp.headers.get("content-type");
|
|
@@ -6320,7 +6521,7 @@
|
|
|
6320
6521
|
log("verified");
|
|
6321
6522
|
setState(State.VERIFIED);
|
|
6322
6523
|
dispatch("verified", { payload: get(payload) });
|
|
6323
|
-
if (get(
|
|
6524
|
+
if (get(auto) === "onsubmit") {
|
|
6324
6525
|
tick().then(() => {
|
|
6325
6526
|
requestSubmit(get(elSubmitter));
|
|
6326
6527
|
});
|
|
@@ -6387,7 +6588,7 @@
|
|
|
6387
6588
|
const start = performance.now();
|
|
6388
6589
|
let challenge = null;
|
|
6389
6590
|
let solution = null;
|
|
6390
|
-
let
|
|
6591
|
+
let isChallengeV12 = false;
|
|
6391
6592
|
const hook = await callHook("onVerify", options);
|
|
6392
6593
|
if (hook !== void 0) {
|
|
6393
6594
|
return hook;
|
|
@@ -6422,7 +6623,7 @@
|
|
|
6422
6623
|
if (challenge.parameters.expiresAt) {
|
|
6423
6624
|
setChallengeExpiration(challenge.parameters.expiresAt);
|
|
6424
6625
|
}
|
|
6425
|
-
|
|
6626
|
+
isChallengeV12 = "_version" in challenge && challenge._version === 1;
|
|
6426
6627
|
const createWorker = globalThis.$altcha.algorithms.get(challenge.parameters.algorithm);
|
|
6427
6628
|
if (!createWorker) {
|
|
6428
6629
|
throw new Error(`Unsupported algorithm ${challenge.parameters.algorithm}.`);
|
|
@@ -6432,7 +6633,7 @@
|
|
|
6432
6633
|
concurrency,
|
|
6433
6634
|
controller,
|
|
6434
6635
|
createWorker,
|
|
6435
|
-
counterMode:
|
|
6636
|
+
counterMode: isChallengeV12 ? "string" : "uint32",
|
|
6436
6637
|
onOutOfMemory: (c) => {
|
|
6437
6638
|
log("out of memory error received");
|
|
6438
6639
|
dispatch("outofmemory");
|
|
@@ -6441,7 +6642,8 @@
|
|
|
6441
6642
|
log(`retrying with ${retryConcurrency} workers...`);
|
|
6442
6643
|
return retryConcurrency;
|
|
6443
6644
|
}
|
|
6444
|
-
}
|
|
6645
|
+
},
|
|
6646
|
+
timeout: get(config).timeout
|
|
6445
6647
|
});
|
|
6446
6648
|
if (get(currentController)?.signal.aborted) {
|
|
6447
6649
|
reset$1();
|
|
@@ -6453,13 +6655,16 @@
|
|
|
6453
6655
|
log("solution", solution);
|
|
6454
6656
|
await delay(Math.max(0, minDuration - (performance.now() - start)));
|
|
6455
6657
|
set(codeChallenge, challenge.codeChallenge || get(config).codeChallenge || null, true);
|
|
6456
|
-
if (
|
|
6658
|
+
if (isChallengeV12) {
|
|
6457
6659
|
set(payload, btoa(JSON.stringify(createPayloadV1(challenge, solution))), true);
|
|
6458
6660
|
} else {
|
|
6459
6661
|
set(
|
|
6460
6662
|
payload,
|
|
6461
6663
|
btoa(JSON.stringify({
|
|
6462
|
-
challenge: {
|
|
6664
|
+
challenge: {
|
|
6665
|
+
parameters: challenge.parameters,
|
|
6666
|
+
signature: challenge.signature
|
|
6667
|
+
},
|
|
6463
6668
|
solution
|
|
6464
6669
|
})),
|
|
6465
6670
|
true
|
|
@@ -6542,7 +6747,7 @@
|
|
|
6542
6747
|
var div_6 = child(div_5);
|
|
6543
6748
|
var node_3 = child(div_6);
|
|
6544
6749
|
{
|
|
6545
|
-
let $0 = /* @__PURE__ */ user_derived(() => get(config).display === "standard" && get(
|
|
6750
|
+
let $0 = /* @__PURE__ */ user_derived(() => get(config).display === "standard" && get(auto) !== "onsubmit" || get(currentState) === State.VERIFYING);
|
|
6546
6751
|
component(node_3, () => get(CheckboxComponent), ($$anchor2, CheckboxComponent_1) => {
|
|
6547
6752
|
CheckboxComponent_1($$anchor2, {
|
|
6548
6753
|
get id() {
|
|
@@ -6667,6 +6872,9 @@
|
|
|
6667
6872
|
reset$1();
|
|
6668
6873
|
}
|
|
6669
6874
|
},
|
|
6875
|
+
get placement() {
|
|
6876
|
+
return get(config).popoverPlacement;
|
|
6877
|
+
},
|
|
6670
6878
|
role: "alert",
|
|
6671
6879
|
variant: "error",
|
|
6672
6880
|
get dir() {
|
|
@@ -6727,6 +6935,9 @@
|
|
|
6727
6935
|
onClose: () => {
|
|
6728
6936
|
reset$1();
|
|
6729
6937
|
},
|
|
6938
|
+
get placement() {
|
|
6939
|
+
return get(config).popoverPlacement;
|
|
6940
|
+
},
|
|
6730
6941
|
role: "dialog",
|
|
6731
6942
|
get "aria-label"() {
|
|
6732
6943
|
return get(strings).verificationRequired;
|
|
@@ -6947,7 +7158,7 @@
|
|
|
6947
7158
|
const { deriveKey: deriveKey2 } = options;
|
|
6948
7159
|
let controller = void 0;
|
|
6949
7160
|
self.onmessage = async (message) => {
|
|
6950
|
-
const { challenge, counterMode, counterStart, counterStep, type } = message.data;
|
|
7161
|
+
const { challenge, counterMode, counterStart, counterStep, timeout, type } = message.data;
|
|
6951
7162
|
if (type === "abort") {
|
|
6952
7163
|
controller?.abort();
|
|
6953
7164
|
} else if (type === "work") {
|
|
@@ -6960,7 +7171,8 @@
|
|
|
6960
7171
|
counterStart,
|
|
6961
7172
|
counterStep,
|
|
6962
7173
|
deriveKey: deriveKey2,
|
|
6963
|
-
counterMode
|
|
7174
|
+
counterMode,
|
|
7175
|
+
timeout
|
|
6964
7176
|
});
|
|
6965
7177
|
} catch (err) {
|
|
6966
7178
|
return self.postMessage({ error: err });
|
|
@@ -7146,7 +7358,7 @@
|
|
|
7146
7358
|
const { deriveKey: deriveKey2 } = options;
|
|
7147
7359
|
let controller = void 0;
|
|
7148
7360
|
self.onmessage = async (message) => {
|
|
7149
|
-
const { challenge, counterMode, counterStart, counterStep, type } = message.data;
|
|
7361
|
+
const { challenge, counterMode, counterStart, counterStep, timeout, type } = message.data;
|
|
7150
7362
|
if (type === "abort") {
|
|
7151
7363
|
controller?.abort();
|
|
7152
7364
|
} else if (type === "work") {
|
|
@@ -7159,7 +7371,8 @@
|
|
|
7159
7371
|
counterStart,
|
|
7160
7372
|
counterStep,
|
|
7161
7373
|
deriveKey: deriveKey2,
|
|
7162
|
-
counterMode
|
|
7374
|
+
counterMode,
|
|
7375
|
+
timeout
|
|
7163
7376
|
});
|
|
7164
7377
|
} catch (err) {
|
|
7165
7378
|
return self.postMessage({ error: err });
|