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
|
@@ -5436,7 +5436,7 @@
|
|
|
5436
5436
|
var root$1 = /* @__PURE__ */ from_html(`<!> <div><!> <!> <div class="altcha-popover-content"><!></div></div>`, 1);
|
|
5437
5437
|
function Popover($$anchor, $$props) {
|
|
5438
5438
|
push($$props, true);
|
|
5439
|
-
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, [
|
|
5439
|
+
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, [
|
|
5440
5440
|
"$$slots",
|
|
5441
5441
|
"$$events",
|
|
5442
5442
|
"$$legacy",
|
|
@@ -5448,12 +5448,18 @@
|
|
|
5448
5448
|
"onClickOutside",
|
|
5449
5449
|
"onClickOutsideDelay",
|
|
5450
5450
|
"onClose",
|
|
5451
|
+
"placement",
|
|
5451
5452
|
"variant"
|
|
5452
5453
|
]);
|
|
5453
5454
|
let el = /* @__PURE__ */ state(void 0);
|
|
5454
5455
|
let elBackdrop = /* @__PURE__ */ state(void 0);
|
|
5455
5456
|
let top = /* @__PURE__ */ state(false);
|
|
5456
5457
|
let mountedAt = /* @__PURE__ */ state(0);
|
|
5458
|
+
user_effect(() => {
|
|
5459
|
+
if (placement() !== "auto") {
|
|
5460
|
+
set(top, placement() === "top");
|
|
5461
|
+
}
|
|
5462
|
+
});
|
|
5457
5463
|
onMount(() => {
|
|
5458
5464
|
const moveToBody = display() === "bottomsheet" || display() === "overlay";
|
|
5459
5465
|
if (moveToBody) {
|
|
@@ -5487,7 +5493,7 @@
|
|
|
5487
5493
|
reposition();
|
|
5488
5494
|
}
|
|
5489
5495
|
function reposition() {
|
|
5490
|
-
if (anchor() && get(el)) {
|
|
5496
|
+
if (anchor() && placement() === "auto" && get(el)) {
|
|
5491
5497
|
const boundary2 = anchor().getBoundingClientRect();
|
|
5492
5498
|
const bottomGap = document.documentElement.clientHeight - (boundary2.top + boundary2.height);
|
|
5493
5499
|
const newTop = bottomGap < get(el).clientHeight;
|
|
@@ -5546,6 +5552,13 @@
|
|
|
5546
5552
|
onClose($$value);
|
|
5547
5553
|
flushSync();
|
|
5548
5554
|
},
|
|
5555
|
+
get placement() {
|
|
5556
|
+
return placement();
|
|
5557
|
+
},
|
|
5558
|
+
set placement($$value = "auto") {
|
|
5559
|
+
placement($$value);
|
|
5560
|
+
flushSync();
|
|
5561
|
+
},
|
|
5549
5562
|
get variant() {
|
|
5550
5563
|
return variant();
|
|
5551
5564
|
},
|
|
@@ -5619,6 +5632,7 @@
|
|
|
5619
5632
|
onClickOutside: {},
|
|
5620
5633
|
onClickOutsideDelay: {},
|
|
5621
5634
|
onClose: {},
|
|
5635
|
+
placement: {},
|
|
5622
5636
|
variant: {}
|
|
5623
5637
|
},
|
|
5624
5638
|
[],
|
|
@@ -5635,7 +5649,8 @@
|
|
|
5635
5649
|
controller = new AbortController(),
|
|
5636
5650
|
createWorker,
|
|
5637
5651
|
onOutOfMemory = (c) => c > 1 ? Math.floor(c / 2) : 0,
|
|
5638
|
-
counterMode
|
|
5652
|
+
counterMode,
|
|
5653
|
+
timeout = 9e4
|
|
5639
5654
|
} = options;
|
|
5640
5655
|
const workersConcurrency = Math.min(16, Math.max(1, concurrency));
|
|
5641
5656
|
const workersInstances = [];
|
|
@@ -5676,6 +5691,7 @@
|
|
|
5676
5691
|
counterMode,
|
|
5677
5692
|
counterStart: i,
|
|
5678
5693
|
counterStep: workersConcurrency,
|
|
5694
|
+
timeout,
|
|
5679
5695
|
type: "work"
|
|
5680
5696
|
});
|
|
5681
5697
|
});
|
|
@@ -5707,6 +5723,147 @@
|
|
|
5707
5723
|
}
|
|
5708
5724
|
return solution || null;
|
|
5709
5725
|
}
|
|
5726
|
+
class Collector {
|
|
5727
|
+
TAG_CODES = {
|
|
5728
|
+
INPUT: 1,
|
|
5729
|
+
TEXTAREA: 2,
|
|
5730
|
+
SELECT: 3,
|
|
5731
|
+
BUTTON: 4,
|
|
5732
|
+
A: 5,
|
|
5733
|
+
DETAILS: 6,
|
|
5734
|
+
SUMMARY: 7,
|
|
5735
|
+
IFRAME: 8,
|
|
5736
|
+
VIDEO: 9,
|
|
5737
|
+
AUDIO: 10
|
|
5738
|
+
};
|
|
5739
|
+
maxSamples;
|
|
5740
|
+
sampleInterval;
|
|
5741
|
+
target;
|
|
5742
|
+
focusStartTime = 0;
|
|
5743
|
+
focusInteraction = 0;
|
|
5744
|
+
focusInteractionTimer = null;
|
|
5745
|
+
lastPointerSample = 0;
|
|
5746
|
+
lastTouchSample = 0;
|
|
5747
|
+
lastScrollSample = 0;
|
|
5748
|
+
pendingPointer = null;
|
|
5749
|
+
pendingTouch = null;
|
|
5750
|
+
focus = [];
|
|
5751
|
+
pointer = [];
|
|
5752
|
+
scroll = [];
|
|
5753
|
+
touch = [];
|
|
5754
|
+
constructor(options = {}) {
|
|
5755
|
+
const { maxSamples = 60, sampleInterval = 50, target = window } = options;
|
|
5756
|
+
this.maxSamples = maxSamples;
|
|
5757
|
+
this.sampleInterval = sampleInterval;
|
|
5758
|
+
this.target = target;
|
|
5759
|
+
this.attach();
|
|
5760
|
+
}
|
|
5761
|
+
destroy() {
|
|
5762
|
+
const o = { capture: true };
|
|
5763
|
+
this.target.removeEventListener("focusin", this.onFocus, o);
|
|
5764
|
+
this.target.removeEventListener("keydown", this.onInteraction, o);
|
|
5765
|
+
this.target.removeEventListener("pointerdown", this.onInteraction, o);
|
|
5766
|
+
this.target.removeEventListener("pointermove", this.onPointer, o);
|
|
5767
|
+
this.target.removeEventListener("scroll", this.onScroll, o);
|
|
5768
|
+
this.target.removeEventListener("touchmove", this.onTouchMove, o);
|
|
5769
|
+
}
|
|
5770
|
+
export() {
|
|
5771
|
+
return {
|
|
5772
|
+
focus: this.focus,
|
|
5773
|
+
maxTouchPoints: navigator.maxTouchPoints || 0,
|
|
5774
|
+
pointer: this.pointer,
|
|
5775
|
+
scroll: this.scroll,
|
|
5776
|
+
time: Date.now(),
|
|
5777
|
+
touch: this.touch
|
|
5778
|
+
};
|
|
5779
|
+
}
|
|
5780
|
+
attach() {
|
|
5781
|
+
const o = { passive: true, capture: true };
|
|
5782
|
+
this.target.addEventListener("focusin", this.onFocus, o);
|
|
5783
|
+
this.target.addEventListener("keydown", this.onInteraction, o);
|
|
5784
|
+
this.target.addEventListener("pointerdown", this.onInteraction, o);
|
|
5785
|
+
this.target.addEventListener("pointermove", this.onPointer, o);
|
|
5786
|
+
this.target.addEventListener("scroll", this.onScroll, o);
|
|
5787
|
+
this.target.addEventListener("touchmove", this.onTouchMove, o);
|
|
5788
|
+
}
|
|
5789
|
+
evict(buffer) {
|
|
5790
|
+
if (buffer.length > this.maxSamples) {
|
|
5791
|
+
buffer.splice(0, buffer.length - this.maxSamples);
|
|
5792
|
+
}
|
|
5793
|
+
}
|
|
5794
|
+
onFocus = (e) => {
|
|
5795
|
+
if (this.focusInteraction === 2) {
|
|
5796
|
+
return;
|
|
5797
|
+
}
|
|
5798
|
+
const el = e.target;
|
|
5799
|
+
if (!(el instanceof Element)) {
|
|
5800
|
+
return;
|
|
5801
|
+
}
|
|
5802
|
+
const now = performance.now();
|
|
5803
|
+
if (this.focusStartTime === 0) {
|
|
5804
|
+
this.focusStartTime = now;
|
|
5805
|
+
}
|
|
5806
|
+
this.focus.push([
|
|
5807
|
+
Math.round(now - this.focusStartTime),
|
|
5808
|
+
el.tabIndex,
|
|
5809
|
+
this.TAG_CODES[el.tagName] ?? 0,
|
|
5810
|
+
this.focusInteraction ? 1 : 0
|
|
5811
|
+
]);
|
|
5812
|
+
this.evict(this.focus);
|
|
5813
|
+
};
|
|
5814
|
+
onInteraction = (e) => {
|
|
5815
|
+
this.focusInteraction = "keyCode" in e ? 1 : 2;
|
|
5816
|
+
if (this.focusInteractionTimer) {
|
|
5817
|
+
clearTimeout(this.focusInteractionTimer);
|
|
5818
|
+
}
|
|
5819
|
+
this.focusInteractionTimer = setTimeout(() => {
|
|
5820
|
+
this.focusInteraction = 0;
|
|
5821
|
+
}, 100);
|
|
5822
|
+
};
|
|
5823
|
+
onPointer = (e) => {
|
|
5824
|
+
if (e.pointerType === "touch") {
|
|
5825
|
+
return;
|
|
5826
|
+
}
|
|
5827
|
+
const now = e.timeStamp || performance.now();
|
|
5828
|
+
this.pendingPointer = [Math.round(e.clientX), Math.round(e.clientY), Math.round(now)];
|
|
5829
|
+
if (now - this.lastPointerSample >= this.sampleInterval) {
|
|
5830
|
+
this.pointer.push(this.pendingPointer);
|
|
5831
|
+
this.lastPointerSample = now;
|
|
5832
|
+
this.pendingPointer = null;
|
|
5833
|
+
this.evict(this.pointer);
|
|
5834
|
+
}
|
|
5835
|
+
};
|
|
5836
|
+
onScroll = () => {
|
|
5837
|
+
const now = performance.now();
|
|
5838
|
+
if (now - this.lastScrollSample < this.sampleInterval) {
|
|
5839
|
+
return;
|
|
5840
|
+
}
|
|
5841
|
+
this.scroll.push([Math.round(window.scrollY), Math.round(now)]);
|
|
5842
|
+
this.lastScrollSample = now;
|
|
5843
|
+
this.evict(this.scroll);
|
|
5844
|
+
};
|
|
5845
|
+
onTouchMove = (e) => {
|
|
5846
|
+
const now = e.timeStamp || performance.now();
|
|
5847
|
+
const t = e.touches[0];
|
|
5848
|
+
if (!t) {
|
|
5849
|
+
return;
|
|
5850
|
+
}
|
|
5851
|
+
this.pendingTouch = [
|
|
5852
|
+
Math.round(t.clientX),
|
|
5853
|
+
Math.round(t.clientY),
|
|
5854
|
+
Math.round(now),
|
|
5855
|
+
Math.round(t.force * 1e3) / 1e3,
|
|
5856
|
+
Math.round(t.radiusX || 0),
|
|
5857
|
+
Math.round(t.radiusY || 0)
|
|
5858
|
+
];
|
|
5859
|
+
if (now - this.lastTouchSample >= this.sampleInterval) {
|
|
5860
|
+
this.touch.push(this.pendingTouch);
|
|
5861
|
+
this.lastTouchSample = now;
|
|
5862
|
+
this.pendingTouch = null;
|
|
5863
|
+
this.evict(this.touch);
|
|
5864
|
+
}
|
|
5865
|
+
};
|
|
5866
|
+
}
|
|
5710
5867
|
var root_1 = /* @__PURE__ */ from_html(`<div class="altcha-overlay-backdrop" data-backdrop=""></div>`);
|
|
5711
5868
|
var root_3 = /* @__PURE__ */ from_html(`<div class="altcha-overlay-content"></div>`);
|
|
5712
5869
|
var root_2 = /* @__PURE__ */ from_html(`<div role="button" class="altcha-overlay-close">×</div> <!>`, 1);
|
|
@@ -5737,6 +5894,7 @@
|
|
|
5737
5894
|
instance?.dispatchEvent(new CustomEvent(event2, { detail }));
|
|
5738
5895
|
});
|
|
5739
5896
|
};
|
|
5897
|
+
let hisCollector = null;
|
|
5740
5898
|
let baseUrl = /* @__PURE__ */ state(proxy(new URL(location.origin)));
|
|
5741
5899
|
let checked = /* @__PURE__ */ state(false);
|
|
5742
5900
|
let codeChallenge = /* @__PURE__ */ state(null);
|
|
@@ -5771,16 +5929,19 @@
|
|
|
5771
5929
|
floatingPlacement: "auto",
|
|
5772
5930
|
hideFooter: false,
|
|
5773
5931
|
hideLogo: false,
|
|
5932
|
+
humanInteractionSignature: true,
|
|
5774
5933
|
language: "",
|
|
5775
5934
|
mockError: false,
|
|
5776
5935
|
minDuration: 500,
|
|
5777
5936
|
overlayContent: "",
|
|
5778
5937
|
name: "altcha",
|
|
5938
|
+
popoverPlacement: "auto",
|
|
5779
5939
|
retryOnOutOfMemoryError: true,
|
|
5780
5940
|
setCookie: null,
|
|
5781
5941
|
serverVerificationFields: false,
|
|
5782
5942
|
serverVerificationTimeZone: false,
|
|
5783
5943
|
test: false,
|
|
5944
|
+
timeout: 9e4,
|
|
5784
5945
|
type: "checkbox",
|
|
5785
5946
|
validationMessage: "",
|
|
5786
5947
|
verifyFunction: null,
|
|
@@ -5791,6 +5952,7 @@
|
|
|
5791
5952
|
}));
|
|
5792
5953
|
const checkboxId = /* @__PURE__ */ user_derived(() => `altcha-checkbox-${$$props.id || Math.floor(Math.random() * 1e12).toString(16)}`);
|
|
5793
5954
|
const CheckboxComponent = /* @__PURE__ */ user_derived(() => getCheckboxComponent(get(config).type));
|
|
5955
|
+
const auto = /* @__PURE__ */ user_derived(() => get(config).auto);
|
|
5794
5956
|
const loading = /* @__PURE__ */ user_derived(() => get(currentState) === State.VERIFYING);
|
|
5795
5957
|
const showFooter = /* @__PURE__ */ user_derived(() => !get(config).hideFooter);
|
|
5796
5958
|
const showLogo = /* @__PURE__ */ user_derived(() => !get(config).hideLogo && get(config).display !== "bar");
|
|
@@ -5852,7 +6014,7 @@
|
|
|
5852
6014
|
}
|
|
5853
6015
|
});
|
|
5854
6016
|
user_effect(() => {
|
|
5855
|
-
if (get(
|
|
6017
|
+
if (get(auto) === "onload") {
|
|
5856
6018
|
const tm = setTimeout(
|
|
5857
6019
|
() => {
|
|
5858
6020
|
verify();
|
|
@@ -5877,15 +6039,19 @@
|
|
|
5877
6039
|
}
|
|
5878
6040
|
});
|
|
5879
6041
|
onMount(() => {
|
|
5880
|
-
log("mounted", "3.0.0-beta.
|
|
6042
|
+
log("mounted", "3.0.0-beta.3");
|
|
5881
6043
|
if (instance) {
|
|
5882
6044
|
globalThis.$altcha.instances.add(instance);
|
|
5883
6045
|
}
|
|
5884
6046
|
set(elForm, get(elRoot)?.closest("form"), true);
|
|
5885
6047
|
get(elForm)?.addEventListener("reset", onFormReset);
|
|
5886
|
-
get(elForm)?.addEventListener("submit", onFormSubmit);
|
|
6048
|
+
get(elForm)?.addEventListener("submit", onFormSubmit, { capture: true });
|
|
5887
6049
|
get(elForm)?.addEventListener("focusin", onFormFocusIn);
|
|
5888
6050
|
activatePlugins();
|
|
6051
|
+
if (get(config).humanInteractionSignature) {
|
|
6052
|
+
log("human interaction signature enabled");
|
|
6053
|
+
hisCollector = new Collector();
|
|
6054
|
+
}
|
|
5889
6055
|
dispatch("load");
|
|
5890
6056
|
if (!isSecureContext) {
|
|
5891
6057
|
log("secure context (HTTPS) required");
|
|
@@ -5899,8 +6065,9 @@
|
|
|
5899
6065
|
clearTimeout(get(expirationTimeout));
|
|
5900
6066
|
}
|
|
5901
6067
|
get(elForm)?.removeEventListener("reset", onFormReset);
|
|
5902
|
-
get(elForm)?.removeEventListener("submit", onFormSubmit);
|
|
6068
|
+
get(elForm)?.removeEventListener("submit", onFormSubmit, { capture: true });
|
|
5903
6069
|
get(elForm)?.removeEventListener("focusin", onFormFocusIn);
|
|
6070
|
+
hisCollector?.destroy();
|
|
5904
6071
|
};
|
|
5905
6072
|
});
|
|
5906
6073
|
function activatePlugins() {
|
|
@@ -5964,23 +6131,41 @@
|
|
|
5964
6131
|
async function delay(ms) {
|
|
5965
6132
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
5966
6133
|
}
|
|
5967
|
-
async function fetchChallenge(source2 = get(config).challenge) {
|
|
6134
|
+
async function fetchChallenge(source2 = get(config).challenge, requestOptions) {
|
|
5968
6135
|
const hook = await callHook("onFetchChallenge", source2);
|
|
6136
|
+
let challenge = null;
|
|
5969
6137
|
if (hook !== void 0) {
|
|
5970
6138
|
return hook;
|
|
5971
6139
|
}
|
|
5972
6140
|
if (typeof source2 === "string") {
|
|
5973
|
-
let challenge = null;
|
|
5974
6141
|
if (source2.match(/^(https?:)?\//)) {
|
|
5975
|
-
log("fetching challenge from", source2);
|
|
6142
|
+
log("fetching challenge from", requestOptions?.method || "GET", source2);
|
|
5976
6143
|
set(baseUrl, new URL(source2, location.origin), true);
|
|
5977
|
-
const resp = await get(config).fetch(source2, {
|
|
5978
|
-
|
|
6144
|
+
const resp = await get(config).fetch(source2, {
|
|
6145
|
+
credentials: get(config).credentials || void 0,
|
|
6146
|
+
...requestOptions
|
|
6147
|
+
});
|
|
6148
|
+
await validateResponse(resp);
|
|
5979
6149
|
const configHeader = resp.headers.get("x-altcha-config");
|
|
5980
6150
|
if (configHeader) {
|
|
5981
6151
|
processConfigHeader(configHeader);
|
|
5982
6152
|
}
|
|
5983
|
-
|
|
6153
|
+
const json = await resp.json();
|
|
6154
|
+
if (json && "his" in json && json.his) {
|
|
6155
|
+
log("requested HIS");
|
|
6156
|
+
if (!hisCollector) {
|
|
6157
|
+
throw new Error("Server requested HIS data but collector is disabled.");
|
|
6158
|
+
}
|
|
6159
|
+
return fetchChallenge(getUrl(json.his.url, get(baseUrl)), {
|
|
6160
|
+
body: JSON.stringify({ his: hisCollector.export() }),
|
|
6161
|
+
headers: { "content-type": "application/json" },
|
|
6162
|
+
method: "POST"
|
|
6163
|
+
});
|
|
6164
|
+
}
|
|
6165
|
+
if (json && "hisResult" in json && json.hisResult) {
|
|
6166
|
+
log("HIS result", json.hisResult);
|
|
6167
|
+
}
|
|
6168
|
+
challenge = json;
|
|
5984
6169
|
} else {
|
|
5985
6170
|
log("parsing JSON challenge");
|
|
5986
6171
|
try {
|
|
@@ -5989,20 +6174,26 @@
|
|
|
5989
6174
|
throw new Error(`Unable to parse JSON challenge.`);
|
|
5990
6175
|
}
|
|
5991
6176
|
}
|
|
5992
|
-
if (typeof challenge === "object" && "challenge" in challenge) {
|
|
5993
|
-
challenge = createChallengeFromV1(challenge);
|
|
5994
|
-
}
|
|
5995
|
-
if (!isChallengeValid(challenge)) {
|
|
5996
|
-
throw new Error(`Challenge validation failed.`);
|
|
5997
|
-
}
|
|
5998
|
-
return challenge;
|
|
5999
6177
|
} else if (source2 && typeof source2 === "object") {
|
|
6000
|
-
|
|
6178
|
+
try {
|
|
6179
|
+
challenge = JSON.parse(JSON.stringify(source2));
|
|
6180
|
+
} catch {
|
|
6181
|
+
throw new Error(`Unable to parse JSON challenge.`);
|
|
6182
|
+
}
|
|
6001
6183
|
}
|
|
6002
|
-
|
|
6184
|
+
if (isChallengeV1(challenge)) {
|
|
6185
|
+
challenge = createChallengeFromV1(challenge);
|
|
6186
|
+
}
|
|
6187
|
+
if (!isChallengeValid(challenge)) {
|
|
6188
|
+
throw new Error(`Challenge validation failed.`);
|
|
6189
|
+
}
|
|
6190
|
+
return challenge;
|
|
6191
|
+
}
|
|
6192
|
+
function isChallengeV1(challenge) {
|
|
6193
|
+
return typeof challenge === "object" && "challenge" in challenge;
|
|
6003
6194
|
}
|
|
6004
6195
|
function isChallengeValid(challenge) {
|
|
6005
|
-
return !!challenge && typeof challenge === "object" && "parameters" in challenge &&
|
|
6196
|
+
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;
|
|
6006
6197
|
}
|
|
6007
6198
|
function getCheckboxElement() {
|
|
6008
6199
|
return document.getElementById(get(checkboxId));
|
|
@@ -6115,7 +6306,7 @@
|
|
|
6115
6306
|
}
|
|
6116
6307
|
}
|
|
6117
6308
|
function onFormFocusIn(ev) {
|
|
6118
|
-
if (get(
|
|
6309
|
+
if (get(auto) === "onfocus" && get(currentState) === State.UNVERIFIED) {
|
|
6119
6310
|
verify();
|
|
6120
6311
|
}
|
|
6121
6312
|
}
|
|
@@ -6128,7 +6319,7 @@
|
|
|
6128
6319
|
}
|
|
6129
6320
|
function onFormSubmit(ev) {
|
|
6130
6321
|
set(elSubmitter, ev.submitter, true);
|
|
6131
|
-
if (get(
|
|
6322
|
+
if (get(auto) === "onsubmit" && get(currentState) === State.UNVERIFIED) {
|
|
6132
6323
|
ev.preventDefault();
|
|
6133
6324
|
ev.stopPropagation();
|
|
6134
6325
|
show();
|
|
@@ -6214,7 +6405,7 @@
|
|
|
6214
6405
|
headers: { "Content-Type": "application/json" },
|
|
6215
6406
|
method: "POST"
|
|
6216
6407
|
});
|
|
6217
|
-
validateResponse(resp);
|
|
6408
|
+
await validateResponse(resp);
|
|
6218
6409
|
const json = await resp.json();
|
|
6219
6410
|
if (json && typeof json === "object" && "payload" in json && !!json.payload) {
|
|
6220
6411
|
dispatch("serververification", json);
|
|
@@ -6255,7 +6446,7 @@
|
|
|
6255
6446
|
case "floating":
|
|
6256
6447
|
case "overlay":
|
|
6257
6448
|
hide();
|
|
6258
|
-
if (!get(
|
|
6449
|
+
if (!get(auto) || get(auto) === "off") {
|
|
6259
6450
|
get(userConfig).auto = "onsubmit";
|
|
6260
6451
|
}
|
|
6261
6452
|
break;
|
|
@@ -6283,8 +6474,18 @@
|
|
|
6283
6474
|
onExpired();
|
|
6284
6475
|
}
|
|
6285
6476
|
}
|
|
6286
|
-
function validateResponse(resp) {
|
|
6477
|
+
async function validateResponse(resp) {
|
|
6287
6478
|
if (resp.status >= 400) {
|
|
6479
|
+
if (resp.headers.get("content-type")?.includes("/json")) {
|
|
6480
|
+
let json;
|
|
6481
|
+
try {
|
|
6482
|
+
json = await resp.json();
|
|
6483
|
+
} catch {
|
|
6484
|
+
}
|
|
6485
|
+
if (json && "error" in json) {
|
|
6486
|
+
throw new Error(`Server responded with ${resp.status} - ${json.error}`);
|
|
6487
|
+
}
|
|
6488
|
+
}
|
|
6288
6489
|
throw new Error(`Server responded with ${resp.status}.`);
|
|
6289
6490
|
}
|
|
6290
6491
|
const contentType = resp.headers.get("content-type");
|
|
@@ -6315,7 +6516,7 @@
|
|
|
6315
6516
|
log("verified");
|
|
6316
6517
|
setState(State.VERIFIED);
|
|
6317
6518
|
dispatch("verified", { payload: get(payload) });
|
|
6318
|
-
if (get(
|
|
6519
|
+
if (get(auto) === "onsubmit") {
|
|
6319
6520
|
tick().then(() => {
|
|
6320
6521
|
requestSubmit(get(elSubmitter));
|
|
6321
6522
|
});
|
|
@@ -6382,7 +6583,7 @@
|
|
|
6382
6583
|
const start = performance.now();
|
|
6383
6584
|
let challenge = null;
|
|
6384
6585
|
let solution = null;
|
|
6385
|
-
let
|
|
6586
|
+
let isChallengeV12 = false;
|
|
6386
6587
|
const hook = await callHook("onVerify", options);
|
|
6387
6588
|
if (hook !== void 0) {
|
|
6388
6589
|
return hook;
|
|
@@ -6417,7 +6618,7 @@
|
|
|
6417
6618
|
if (challenge.parameters.expiresAt) {
|
|
6418
6619
|
setChallengeExpiration(challenge.parameters.expiresAt);
|
|
6419
6620
|
}
|
|
6420
|
-
|
|
6621
|
+
isChallengeV12 = "_version" in challenge && challenge._version === 1;
|
|
6421
6622
|
const createWorker = globalThis.$altcha.algorithms.get(challenge.parameters.algorithm);
|
|
6422
6623
|
if (!createWorker) {
|
|
6423
6624
|
throw new Error(`Unsupported algorithm ${challenge.parameters.algorithm}.`);
|
|
@@ -6427,7 +6628,7 @@
|
|
|
6427
6628
|
concurrency,
|
|
6428
6629
|
controller,
|
|
6429
6630
|
createWorker,
|
|
6430
|
-
counterMode:
|
|
6631
|
+
counterMode: isChallengeV12 ? "string" : "uint32",
|
|
6431
6632
|
onOutOfMemory: (c) => {
|
|
6432
6633
|
log("out of memory error received");
|
|
6433
6634
|
dispatch("outofmemory");
|
|
@@ -6436,7 +6637,8 @@
|
|
|
6436
6637
|
log(`retrying with ${retryConcurrency} workers...`);
|
|
6437
6638
|
return retryConcurrency;
|
|
6438
6639
|
}
|
|
6439
|
-
}
|
|
6640
|
+
},
|
|
6641
|
+
timeout: get(config).timeout
|
|
6440
6642
|
});
|
|
6441
6643
|
if (get(currentController)?.signal.aborted) {
|
|
6442
6644
|
reset$1();
|
|
@@ -6448,13 +6650,16 @@
|
|
|
6448
6650
|
log("solution", solution);
|
|
6449
6651
|
await delay(Math.max(0, minDuration - (performance.now() - start)));
|
|
6450
6652
|
set(codeChallenge, challenge.codeChallenge || get(config).codeChallenge || null, true);
|
|
6451
|
-
if (
|
|
6653
|
+
if (isChallengeV12) {
|
|
6452
6654
|
set(payload, btoa(JSON.stringify(createPayloadV1(challenge, solution))), true);
|
|
6453
6655
|
} else {
|
|
6454
6656
|
set(
|
|
6455
6657
|
payload,
|
|
6456
6658
|
btoa(JSON.stringify({
|
|
6457
|
-
challenge: {
|
|
6659
|
+
challenge: {
|
|
6660
|
+
parameters: challenge.parameters,
|
|
6661
|
+
signature: challenge.signature
|
|
6662
|
+
},
|
|
6458
6663
|
solution
|
|
6459
6664
|
})),
|
|
6460
6665
|
true
|
|
@@ -6537,7 +6742,7 @@
|
|
|
6537
6742
|
var div_6 = child(div_5);
|
|
6538
6743
|
var node_3 = child(div_6);
|
|
6539
6744
|
{
|
|
6540
|
-
let $0 = /* @__PURE__ */ user_derived(() => get(config).display === "standard" && get(
|
|
6745
|
+
let $0 = /* @__PURE__ */ user_derived(() => get(config).display === "standard" && get(auto) !== "onsubmit" || get(currentState) === State.VERIFYING);
|
|
6541
6746
|
component(node_3, () => get(CheckboxComponent), ($$anchor2, CheckboxComponent_1) => {
|
|
6542
6747
|
CheckboxComponent_1($$anchor2, {
|
|
6543
6748
|
get id() {
|
|
@@ -6662,6 +6867,9 @@
|
|
|
6662
6867
|
reset$1();
|
|
6663
6868
|
}
|
|
6664
6869
|
},
|
|
6870
|
+
get placement() {
|
|
6871
|
+
return get(config).popoverPlacement;
|
|
6872
|
+
},
|
|
6665
6873
|
role: "alert",
|
|
6666
6874
|
variant: "error",
|
|
6667
6875
|
get dir() {
|
|
@@ -6722,6 +6930,9 @@
|
|
|
6722
6930
|
onClose: () => {
|
|
6723
6931
|
reset$1();
|
|
6724
6932
|
},
|
|
6933
|
+
get placement() {
|
|
6934
|
+
return get(config).popoverPlacement;
|
|
6935
|
+
},
|
|
6725
6936
|
role: "dialog",
|
|
6726
6937
|
get "aria-label"() {
|
|
6727
6938
|
return get(strings).verificationRequired;
|