@riddledc/riddle-proof 0.7.159 → 0.7.160

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
@@ -8782,6 +8782,7 @@ var RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES = [
8782
8782
  "fill",
8783
8783
  "set_input_value",
8784
8784
  "set_range_value",
8785
+ "canvas_signature",
8785
8786
  "assert_text_visible",
8786
8787
  "assert_text_absent",
8787
8788
  "assert_selector_count",
@@ -9283,6 +9284,26 @@ function profileSetupRangeValueReceipts(results) {
9283
9284
  reason: result.reason ?? result.error ?? null
9284
9285
  }));
9285
9286
  }
9287
+ function profileSetupCanvasSignatureReceipts(results) {
9288
+ return results.filter((result) => profileSetupResultAction(result) === "canvas_signature").map((result) => ({
9289
+ ordinal: result.ordinal ?? null,
9290
+ ok: result.ok !== false,
9291
+ selector: result.selector ?? null,
9292
+ frame_selector: result.frame_selector ?? null,
9293
+ label: result.label ?? null,
9294
+ hash: result.hash ?? null,
9295
+ data_length: result.data_length ?? null,
9296
+ width: result.width ?? null,
9297
+ height: result.height ?? null,
9298
+ css_width: result.css_width ?? null,
9299
+ css_height: result.css_height ?? null,
9300
+ compare_to: result.compare_to ?? null,
9301
+ previous_hash: result.previous_hash ?? null,
9302
+ changed: result.changed ?? null,
9303
+ return_stored_to: result.return_stored_to ?? null,
9304
+ reason: result.reason ?? result.error ?? null
9305
+ }));
9306
+ }
9286
9307
  function sampleProfileSetupSummaryItems(items, limit) {
9287
9308
  if (items.length <= limit) return items;
9288
9309
  const firstCount = Math.floor(limit / 2);
@@ -9327,6 +9348,8 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
9327
9348
  const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
9328
9349
  const rangeValueReceipts = profileSetupRangeValueReceipts(results);
9329
9350
  const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
9351
+ const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
9352
+ const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
9330
9353
  const clickedItems = results.filter((result) => profileSetupResultAction(result) === "click" && result.ok !== false).map((result) => {
9331
9354
  const clickCount = typeof result.click_count === "number" && Number.isFinite(result.click_count) && result.click_count > 1 ? result.click_count : void 0;
9332
9355
  return {
@@ -9378,6 +9401,9 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
9378
9401
  set_range_value_total: rangeValueReceipts.length,
9379
9402
  set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
9380
9403
  set_range_value: sampledRangeValueReceipts,
9404
+ canvas_signature_total: canvasSignatureReceipts.length,
9405
+ canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
9406
+ canvas_signature: sampledCanvasSignatureReceipts,
9381
9407
  clicked,
9382
9408
  text_samples,
9383
9409
  failed: failed.map((result) => ({
@@ -9430,7 +9456,7 @@ function isSupportedCheckType(value) {
9430
9456
  }
9431
9457
  function normalizeSetupActionType(value, index) {
9432
9458
  const normalizedInput = String(value || "").trim().replace(/-/g, "_");
9433
- const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
9459
+ const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "canvas_hash" || normalizedInput === "capture_canvas_hash" || normalizedInput === "capture_canvas_signature" || normalizedInput === "canvas_state_signature" ? "canvas_signature" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
9434
9460
  if (RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES.includes(normalized)) {
9435
9461
  return normalized;
9436
9462
  }
@@ -9559,7 +9585,7 @@ function normalizeSetupAction(input, index) {
9559
9585
  if (frameIndex !== void 0 && (!Number.isInteger(frameIndex) || frameIndex < 0)) {
9560
9586
  throw new Error(`target.setup_actions[${index}].frame_index must be a non-negative integer.`);
9561
9587
  }
9562
- if ((type === "click" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
9588
+ if ((type === "click" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "canvas_signature" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
9563
9589
  throw new Error(`target.setup_actions[${index}] ${type} requires selector.`);
9564
9590
  }
9565
9591
  const fromX = numberValue3(valueFromOwn(input, "from_x", "fromX", "start_x", "startX", "x1"));
@@ -9653,7 +9679,11 @@ function normalizeSetupAction(input, index) {
9653
9679
  "assign_return_to",
9654
9680
  "assignReturnTo",
9655
9681
  "return_state_path",
9656
- "returnStatePath"
9682
+ "returnStatePath",
9683
+ "store_signature_to",
9684
+ "storeSignatureTo",
9685
+ "signature_path",
9686
+ "signaturePath"
9657
9687
  );
9658
9688
  const captureReturn = input.capture_return === false || input.captureReturn === false || input.include_return === false || input.includeReturn === false || input.omit_return === true || input.omitReturn === true ? false : void 0;
9659
9689
  const untilPath = stringFromOwn(input, "until_path", "untilPath", "until_state_path", "untilStatePath", "until_window_path", "untilWindowPath", "until");
@@ -9705,6 +9735,8 @@ function normalizeSetupAction(input, index) {
9705
9735
  store_return_to: storeReturnTo,
9706
9736
  capture_return: captureReturn,
9707
9737
  return_summary_fields: normalizeReturnSummaryFields(input, index),
9738
+ compare_to: stringFromOwn(input, "compare_to", "compareTo", "previous_signature_path", "previousSignaturePath", "previous_path", "previousPath", "changed_from", "changedFrom"),
9739
+ expect_changed: booleanValue(valueFromOwn(input, "expect_changed", "expectChanged", "should_change", "shouldChange", "changed")),
9708
9740
  until_path: untilPath,
9709
9741
  until_expected_value: hasUntilExpectedValue ? toJsonValue(valueFromOwn(input, "until_expected_value", "untilExpectedValue", "until_expected", "untilExpected", "until_value", "untilValue", "expected_value", "expectedValue", "expected")) : void 0,
9710
9742
  max_calls: maxCalls,
@@ -12831,6 +12863,28 @@ function profileSetupRangeValueReceipts(results) {
12831
12863
  reason: result.reason || result.error || null,
12832
12864
  }));
12833
12865
  }
12866
+ function profileSetupCanvasSignatureReceipts(results) {
12867
+ return (results || [])
12868
+ .filter((result) => result && profileSetupResultAction(result) === "canvas_signature")
12869
+ .map((result) => ({
12870
+ ordinal: result.ordinal ?? null,
12871
+ ok: result.ok !== false,
12872
+ selector: result.selector ?? null,
12873
+ frame_selector: result.frame_selector ?? null,
12874
+ label: result.label ?? null,
12875
+ hash: result.hash ?? null,
12876
+ data_length: result.data_length ?? null,
12877
+ width: result.width ?? null,
12878
+ height: result.height ?? null,
12879
+ css_width: result.css_width ?? null,
12880
+ css_height: result.css_height ?? null,
12881
+ compare_to: result.compare_to ?? null,
12882
+ previous_hash: result.previous_hash ?? null,
12883
+ changed: result.changed ?? null,
12884
+ return_stored_to: result.return_stored_to ?? null,
12885
+ reason: result.reason || result.error || null,
12886
+ }));
12887
+ }
12834
12888
  function sampleProfileSetupSummaryItems(items, limit) {
12835
12889
  if ((items || []).length <= limit) return items || [];
12836
12890
  const firstCount = Math.floor(limit / 2);
@@ -12889,6 +12943,8 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
12889
12943
  const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
12890
12944
  const rangeValueReceipts = profileSetupRangeValueReceipts(results);
12891
12945
  const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
12946
+ const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
12947
+ const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
12892
12948
  const clickedItems = results
12893
12949
  .filter((result) => result && profileSetupResultAction(result) === "click" && result.ok !== false)
12894
12950
  .map((result) => {
@@ -12950,6 +13006,9 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
12950
13006
  set_range_value_total: rangeValueReceipts.length,
12951
13007
  set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
12952
13008
  set_range_value: sampledRangeValueReceipts,
13009
+ canvas_signature_total: canvasSignatureReceipts.length,
13010
+ canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
13011
+ canvas_signature: sampledCanvasSignatureReceipts,
12953
13012
  clicked,
12954
13013
  text_samples: textSamples,
12955
13014
  failed: failed.map((result) => ({
@@ -14965,6 +15024,156 @@ async function executeSetupAction(action, ordinal, viewport) {
14965
15024
  reason: rangeResult && rangeResult.ok === true ? undefined : rangeResult?.reason || "range_value_not_set",
14966
15025
  };
14967
15026
  }
15027
+ if (type === "canvas_signature") {
15028
+ const scope = await setupActionScope(action, timeout);
15029
+ if (!scope.ok) return setupScopeFailure(base, scope);
15030
+ const locator = scope.context.locator(action.selector);
15031
+ const count = await locator.count();
15032
+ if (!count) return { ...base, ...setupScopeEvidence(scope), reason: "selector_not_found", count };
15033
+ const targetIndex = Number.isInteger(action.index) ? action.index : 0;
15034
+ if (targetIndex < 0 || targetIndex >= count) return { ...base, ...setupScopeEvidence(scope), reason: "index_out_of_range", count, target_index: targetIndex };
15035
+ const target = locator.nth(targetIndex);
15036
+ await target.waitFor({ state: "visible", timeout });
15037
+ const storeReturnTo = String(action.store_return_to || action.storeReturnTo || action.save_return_to || action.saveReturnTo || action.store_signature_to || action.storeSignatureTo || action.signature_path || action.signaturePath || "").trim();
15038
+ const compareTo = String(action.compare_to || action.compareTo || action.previous_signature_path || action.previousSignaturePath || action.previous_path || action.previousPath || action.changed_from || action.changedFrom || "").trim();
15039
+ const expectChanged = action.expect_changed === true || action.expectChanged === true || action.should_change === true || action.shouldChange === true || action.changed === true
15040
+ ? true
15041
+ : action.expect_changed === false || action.expectChanged === false || action.should_change === false || action.shouldChange === false || action.changed === false
15042
+ ? false
15043
+ : undefined;
15044
+ const signatureResult = await target.evaluate((element, payload) => {
15045
+ const toJsonValue = (value) => {
15046
+ if (value === null || value === undefined) return null;
15047
+ if (typeof value === "string" || typeof value === "boolean") return value;
15048
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
15049
+ if (Array.isArray(value)) return value.map(toJsonValue);
15050
+ if (typeof value === "object") {
15051
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toJsonValue(child)]));
15052
+ }
15053
+ return String(value);
15054
+ };
15055
+ const pathParts = (path) => String(path || "").split(".").map((part) => part.trim()).filter(Boolean);
15056
+ const readWindowPath = (path) => {
15057
+ const parts = pathParts(path);
15058
+ if (parts[0] === "window") parts.shift();
15059
+ if (!parts.length) return { ok: false, reason: "missing_path" };
15060
+ let current = window;
15061
+ for (const part of parts) {
15062
+ if (current === null || current === undefined) return { ok: false, reason: "path_not_found", missing_part: part };
15063
+ current = current[part];
15064
+ if (current === undefined) return { ok: false, reason: "path_not_found", missing_part: part };
15065
+ }
15066
+ return { ok: true, value: toJsonValue(current) };
15067
+ };
15068
+ const storeWindowValue = (path, value) => {
15069
+ const parts = pathParts(path);
15070
+ if (parts[0] === "window") parts.shift();
15071
+ if (!parts.length) return { ok: false, reason: "missing_store_path" };
15072
+ let target = window;
15073
+ for (let index = 0; index < parts.length - 1; index += 1) {
15074
+ const part = parts[index];
15075
+ if (target[part] === null || typeof target[part] !== "object") target[part] = {};
15076
+ target = target[part];
15077
+ }
15078
+ target[parts[parts.length - 1]] = value;
15079
+ return { ok: true, path: parts.join(".") };
15080
+ };
15081
+ const hashText = (text) => {
15082
+ let hash = 2166136261;
15083
+ const step = Math.max(1, Math.floor((text.length || 1) / 4000));
15084
+ for (let index = 0; index < text.length; index += step) {
15085
+ hash ^= text.charCodeAt(index);
15086
+ hash = Math.imul(hash, 16777619) >>> 0;
15087
+ }
15088
+ return String(hash);
15089
+ };
15090
+ const tag = String(element && element.tagName ? element.tagName : "").toLowerCase();
15091
+ if (tag !== "canvas") return { ok: false, reason: "not_canvas_element", tag };
15092
+ const rect = element.getBoundingClientRect();
15093
+ let data = "";
15094
+ try {
15095
+ data = element.toDataURL("image/png");
15096
+ } catch (error) {
15097
+ return {
15098
+ ok: false,
15099
+ reason: "canvas_read_failed",
15100
+ error: String(error && error.message ? error.message : error).slice(0, 1000),
15101
+ width: element.width || 0,
15102
+ height: element.height || 0,
15103
+ css_width: Math.round(rect.width || 0),
15104
+ css_height: Math.round(rect.height || 0),
15105
+ };
15106
+ }
15107
+ const result = {
15108
+ ok: Boolean(element.width > 0 && element.height > 0 && data.length > 0),
15109
+ reason: element.width > 0 && element.height > 0 && data.length > 0 ? undefined : "empty_canvas_signature",
15110
+ hash: hashText(data),
15111
+ data_length: data.length,
15112
+ width: element.width || 0,
15113
+ height: element.height || 0,
15114
+ css_width: Math.round(rect.width || 0),
15115
+ css_height: Math.round(rect.height || 0),
15116
+ compare_to: payload.compareTo || undefined,
15117
+ previous_hash: null,
15118
+ changed: null,
15119
+ };
15120
+ if (payload.compareTo) {
15121
+ const previous = readWindowPath(payload.compareTo);
15122
+ if (!previous.ok) {
15123
+ result.ok = false;
15124
+ result.reason = previous.reason || "compare_path_not_found";
15125
+ result.missing_part = previous.missing_part || undefined;
15126
+ } else {
15127
+ const previousValue = previous.value;
15128
+ const previousHash = previousValue && typeof previousValue === "object" && !Array.isArray(previousValue)
15129
+ ? previousValue.hash || previousValue.signature || previousValue.canvas_hash || null
15130
+ : typeof previousValue === "string"
15131
+ ? previousValue
15132
+ : null;
15133
+ result.previous_hash = previousHash === null || previousHash === undefined ? null : String(previousHash);
15134
+ result.changed = result.previous_hash === null ? null : result.previous_hash !== result.hash;
15135
+ if (payload.expectChanged === true && result.changed !== true) {
15136
+ result.ok = false;
15137
+ result.reason = "canvas_signature_unchanged";
15138
+ } else if (payload.expectChanged === false && result.changed !== false) {
15139
+ result.ok = false;
15140
+ result.reason = "canvas_signature_changed";
15141
+ }
15142
+ }
15143
+ }
15144
+ if (payload.storeReturnTo) {
15145
+ const stored = storeWindowValue(payload.storeReturnTo, result);
15146
+ if (!stored.ok) {
15147
+ return { ...result, ok: false, reason: "signature_store_failed", store_reason: stored.reason };
15148
+ }
15149
+ return { ...result, return_stored_to: stored.path };
15150
+ }
15151
+ return result;
15152
+ }, { compareTo, expectChanged, storeReturnTo });
15153
+ return {
15154
+ ...base,
15155
+ ...setupScopeEvidence(scope),
15156
+ ok: signatureResult && signatureResult.ok === true,
15157
+ count,
15158
+ target_index: targetIndex,
15159
+ label: action.label || action.name || undefined,
15160
+ hash: signatureResult?.hash,
15161
+ data_length: signatureResult?.data_length,
15162
+ width: signatureResult?.width,
15163
+ height: signatureResult?.height,
15164
+ css_width: signatureResult?.css_width,
15165
+ css_height: signatureResult?.css_height,
15166
+ compare_to: signatureResult?.compare_to || compareTo || undefined,
15167
+ previous_hash: signatureResult?.previous_hash,
15168
+ changed: signatureResult?.changed,
15169
+ return_stored_to: signatureResult?.return_stored_to || storeReturnTo || undefined,
15170
+ missing_part: signatureResult?.missing_part || undefined,
15171
+ store_reason: signatureResult?.store_reason || undefined,
15172
+ tag: signatureResult?.tag,
15173
+ reason: signatureResult && signatureResult.ok === true ? undefined : signatureResult?.reason || "canvas_signature_failed",
15174
+ error: signatureResult?.error || undefined,
15175
+ };
15176
+ }
14968
15177
  if (type === "assert_selector_count") {
14969
15178
  const scope = await setupActionScope(action, timeout);
14970
15179
  if (!scope.ok) return setupScopeFailure(base, scope);
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ import {
62
62
  resolveRiddleProofProfileTimeoutSec,
63
63
  slugifyRiddleProofProfileName,
64
64
  summarizeRiddleProofProfileResult
65
- } from "./chunk-TBTMD5WV.js";
65
+ } from "./chunk-MV7UM4EV.js";
66
66
  import {
67
67
  DEFAULT_RIDDLE_API_BASE_URL,
68
68
  DEFAULT_RIDDLE_API_KEY_FILE,
package/dist/profile.cjs CHANGED
@@ -96,6 +96,7 @@ var RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES = [
96
96
  "fill",
97
97
  "set_input_value",
98
98
  "set_range_value",
99
+ "canvas_signature",
99
100
  "assert_text_visible",
100
101
  "assert_text_absent",
101
102
  "assert_selector_count",
@@ -597,6 +598,26 @@ function profileSetupRangeValueReceipts(results) {
597
598
  reason: result.reason ?? result.error ?? null
598
599
  }));
599
600
  }
601
+ function profileSetupCanvasSignatureReceipts(results) {
602
+ return results.filter((result) => profileSetupResultAction(result) === "canvas_signature").map((result) => ({
603
+ ordinal: result.ordinal ?? null,
604
+ ok: result.ok !== false,
605
+ selector: result.selector ?? null,
606
+ frame_selector: result.frame_selector ?? null,
607
+ label: result.label ?? null,
608
+ hash: result.hash ?? null,
609
+ data_length: result.data_length ?? null,
610
+ width: result.width ?? null,
611
+ height: result.height ?? null,
612
+ css_width: result.css_width ?? null,
613
+ css_height: result.css_height ?? null,
614
+ compare_to: result.compare_to ?? null,
615
+ previous_hash: result.previous_hash ?? null,
616
+ changed: result.changed ?? null,
617
+ return_stored_to: result.return_stored_to ?? null,
618
+ reason: result.reason ?? result.error ?? null
619
+ }));
620
+ }
600
621
  function sampleProfileSetupSummaryItems(items, limit) {
601
622
  if (items.length <= limit) return items;
602
623
  const firstCount = Math.floor(limit / 2);
@@ -641,6 +662,8 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
641
662
  const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
642
663
  const rangeValueReceipts = profileSetupRangeValueReceipts(results);
643
664
  const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
665
+ const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
666
+ const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
644
667
  const clickedItems = results.filter((result) => profileSetupResultAction(result) === "click" && result.ok !== false).map((result) => {
645
668
  const clickCount = typeof result.click_count === "number" && Number.isFinite(result.click_count) && result.click_count > 1 ? result.click_count : void 0;
646
669
  return {
@@ -692,6 +715,9 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
692
715
  set_range_value_total: rangeValueReceipts.length,
693
716
  set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
694
717
  set_range_value: sampledRangeValueReceipts,
718
+ canvas_signature_total: canvasSignatureReceipts.length,
719
+ canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
720
+ canvas_signature: sampledCanvasSignatureReceipts,
695
721
  clicked,
696
722
  text_samples,
697
723
  failed: failed.map((result) => ({
@@ -744,7 +770,7 @@ function isSupportedCheckType(value) {
744
770
  }
745
771
  function normalizeSetupActionType(value, index) {
746
772
  const normalizedInput = String(value || "").trim().replace(/-/g, "_");
747
- const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
773
+ const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "canvas_hash" || normalizedInput === "capture_canvas_hash" || normalizedInput === "capture_canvas_signature" || normalizedInput === "canvas_state_signature" ? "canvas_signature" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
748
774
  if (RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES.includes(normalized)) {
749
775
  return normalized;
750
776
  }
@@ -873,7 +899,7 @@ function normalizeSetupAction(input, index) {
873
899
  if (frameIndex !== void 0 && (!Number.isInteger(frameIndex) || frameIndex < 0)) {
874
900
  throw new Error(`target.setup_actions[${index}].frame_index must be a non-negative integer.`);
875
901
  }
876
- if ((type === "click" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
902
+ if ((type === "click" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "canvas_signature" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
877
903
  throw new Error(`target.setup_actions[${index}] ${type} requires selector.`);
878
904
  }
879
905
  const fromX = numberValue(valueFromOwn(input, "from_x", "fromX", "start_x", "startX", "x1"));
@@ -967,7 +993,11 @@ function normalizeSetupAction(input, index) {
967
993
  "assign_return_to",
968
994
  "assignReturnTo",
969
995
  "return_state_path",
970
- "returnStatePath"
996
+ "returnStatePath",
997
+ "store_signature_to",
998
+ "storeSignatureTo",
999
+ "signature_path",
1000
+ "signaturePath"
971
1001
  );
972
1002
  const captureReturn = input.capture_return === false || input.captureReturn === false || input.include_return === false || input.includeReturn === false || input.omit_return === true || input.omitReturn === true ? false : void 0;
973
1003
  const untilPath = stringFromOwn(input, "until_path", "untilPath", "until_state_path", "untilStatePath", "until_window_path", "untilWindowPath", "until");
@@ -1019,6 +1049,8 @@ function normalizeSetupAction(input, index) {
1019
1049
  store_return_to: storeReturnTo,
1020
1050
  capture_return: captureReturn,
1021
1051
  return_summary_fields: normalizeReturnSummaryFields(input, index),
1052
+ compare_to: stringFromOwn(input, "compare_to", "compareTo", "previous_signature_path", "previousSignaturePath", "previous_path", "previousPath", "changed_from", "changedFrom"),
1053
+ expect_changed: booleanValue(valueFromOwn(input, "expect_changed", "expectChanged", "should_change", "shouldChange", "changed")),
1022
1054
  until_path: untilPath,
1023
1055
  until_expected_value: hasUntilExpectedValue ? toJsonValue(valueFromOwn(input, "until_expected_value", "untilExpectedValue", "until_expected", "untilExpected", "until_value", "untilValue", "expected_value", "expectedValue", "expected")) : void 0,
1024
1056
  max_calls: maxCalls,
@@ -4145,6 +4177,28 @@ function profileSetupRangeValueReceipts(results) {
4145
4177
  reason: result.reason || result.error || null,
4146
4178
  }));
4147
4179
  }
4180
+ function profileSetupCanvasSignatureReceipts(results) {
4181
+ return (results || [])
4182
+ .filter((result) => result && profileSetupResultAction(result) === "canvas_signature")
4183
+ .map((result) => ({
4184
+ ordinal: result.ordinal ?? null,
4185
+ ok: result.ok !== false,
4186
+ selector: result.selector ?? null,
4187
+ frame_selector: result.frame_selector ?? null,
4188
+ label: result.label ?? null,
4189
+ hash: result.hash ?? null,
4190
+ data_length: result.data_length ?? null,
4191
+ width: result.width ?? null,
4192
+ height: result.height ?? null,
4193
+ css_width: result.css_width ?? null,
4194
+ css_height: result.css_height ?? null,
4195
+ compare_to: result.compare_to ?? null,
4196
+ previous_hash: result.previous_hash ?? null,
4197
+ changed: result.changed ?? null,
4198
+ return_stored_to: result.return_stored_to ?? null,
4199
+ reason: result.reason || result.error || null,
4200
+ }));
4201
+ }
4148
4202
  function sampleProfileSetupSummaryItems(items, limit) {
4149
4203
  if ((items || []).length <= limit) return items || [];
4150
4204
  const firstCount = Math.floor(limit / 2);
@@ -4203,6 +4257,8 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
4203
4257
  const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
4204
4258
  const rangeValueReceipts = profileSetupRangeValueReceipts(results);
4205
4259
  const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
4260
+ const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
4261
+ const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
4206
4262
  const clickedItems = results
4207
4263
  .filter((result) => result && profileSetupResultAction(result) === "click" && result.ok !== false)
4208
4264
  .map((result) => {
@@ -4264,6 +4320,9 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
4264
4320
  set_range_value_total: rangeValueReceipts.length,
4265
4321
  set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
4266
4322
  set_range_value: sampledRangeValueReceipts,
4323
+ canvas_signature_total: canvasSignatureReceipts.length,
4324
+ canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
4325
+ canvas_signature: sampledCanvasSignatureReceipts,
4267
4326
  clicked,
4268
4327
  text_samples: textSamples,
4269
4328
  failed: failed.map((result) => ({
@@ -6279,6 +6338,156 @@ async function executeSetupAction(action, ordinal, viewport) {
6279
6338
  reason: rangeResult && rangeResult.ok === true ? undefined : rangeResult?.reason || "range_value_not_set",
6280
6339
  };
6281
6340
  }
6341
+ if (type === "canvas_signature") {
6342
+ const scope = await setupActionScope(action, timeout);
6343
+ if (!scope.ok) return setupScopeFailure(base, scope);
6344
+ const locator = scope.context.locator(action.selector);
6345
+ const count = await locator.count();
6346
+ if (!count) return { ...base, ...setupScopeEvidence(scope), reason: "selector_not_found", count };
6347
+ const targetIndex = Number.isInteger(action.index) ? action.index : 0;
6348
+ if (targetIndex < 0 || targetIndex >= count) return { ...base, ...setupScopeEvidence(scope), reason: "index_out_of_range", count, target_index: targetIndex };
6349
+ const target = locator.nth(targetIndex);
6350
+ await target.waitFor({ state: "visible", timeout });
6351
+ const storeReturnTo = String(action.store_return_to || action.storeReturnTo || action.save_return_to || action.saveReturnTo || action.store_signature_to || action.storeSignatureTo || action.signature_path || action.signaturePath || "").trim();
6352
+ const compareTo = String(action.compare_to || action.compareTo || action.previous_signature_path || action.previousSignaturePath || action.previous_path || action.previousPath || action.changed_from || action.changedFrom || "").trim();
6353
+ const expectChanged = action.expect_changed === true || action.expectChanged === true || action.should_change === true || action.shouldChange === true || action.changed === true
6354
+ ? true
6355
+ : action.expect_changed === false || action.expectChanged === false || action.should_change === false || action.shouldChange === false || action.changed === false
6356
+ ? false
6357
+ : undefined;
6358
+ const signatureResult = await target.evaluate((element, payload) => {
6359
+ const toJsonValue = (value) => {
6360
+ if (value === null || value === undefined) return null;
6361
+ if (typeof value === "string" || typeof value === "boolean") return value;
6362
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
6363
+ if (Array.isArray(value)) return value.map(toJsonValue);
6364
+ if (typeof value === "object") {
6365
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toJsonValue(child)]));
6366
+ }
6367
+ return String(value);
6368
+ };
6369
+ const pathParts = (path) => String(path || "").split(".").map((part) => part.trim()).filter(Boolean);
6370
+ const readWindowPath = (path) => {
6371
+ const parts = pathParts(path);
6372
+ if (parts[0] === "window") parts.shift();
6373
+ if (!parts.length) return { ok: false, reason: "missing_path" };
6374
+ let current = window;
6375
+ for (const part of parts) {
6376
+ if (current === null || current === undefined) return { ok: false, reason: "path_not_found", missing_part: part };
6377
+ current = current[part];
6378
+ if (current === undefined) return { ok: false, reason: "path_not_found", missing_part: part };
6379
+ }
6380
+ return { ok: true, value: toJsonValue(current) };
6381
+ };
6382
+ const storeWindowValue = (path, value) => {
6383
+ const parts = pathParts(path);
6384
+ if (parts[0] === "window") parts.shift();
6385
+ if (!parts.length) return { ok: false, reason: "missing_store_path" };
6386
+ let target = window;
6387
+ for (let index = 0; index < parts.length - 1; index += 1) {
6388
+ const part = parts[index];
6389
+ if (target[part] === null || typeof target[part] !== "object") target[part] = {};
6390
+ target = target[part];
6391
+ }
6392
+ target[parts[parts.length - 1]] = value;
6393
+ return { ok: true, path: parts.join(".") };
6394
+ };
6395
+ const hashText = (text) => {
6396
+ let hash = 2166136261;
6397
+ const step = Math.max(1, Math.floor((text.length || 1) / 4000));
6398
+ for (let index = 0; index < text.length; index += step) {
6399
+ hash ^= text.charCodeAt(index);
6400
+ hash = Math.imul(hash, 16777619) >>> 0;
6401
+ }
6402
+ return String(hash);
6403
+ };
6404
+ const tag = String(element && element.tagName ? element.tagName : "").toLowerCase();
6405
+ if (tag !== "canvas") return { ok: false, reason: "not_canvas_element", tag };
6406
+ const rect = element.getBoundingClientRect();
6407
+ let data = "";
6408
+ try {
6409
+ data = element.toDataURL("image/png");
6410
+ } catch (error) {
6411
+ return {
6412
+ ok: false,
6413
+ reason: "canvas_read_failed",
6414
+ error: String(error && error.message ? error.message : error).slice(0, 1000),
6415
+ width: element.width || 0,
6416
+ height: element.height || 0,
6417
+ css_width: Math.round(rect.width || 0),
6418
+ css_height: Math.round(rect.height || 0),
6419
+ };
6420
+ }
6421
+ const result = {
6422
+ ok: Boolean(element.width > 0 && element.height > 0 && data.length > 0),
6423
+ reason: element.width > 0 && element.height > 0 && data.length > 0 ? undefined : "empty_canvas_signature",
6424
+ hash: hashText(data),
6425
+ data_length: data.length,
6426
+ width: element.width || 0,
6427
+ height: element.height || 0,
6428
+ css_width: Math.round(rect.width || 0),
6429
+ css_height: Math.round(rect.height || 0),
6430
+ compare_to: payload.compareTo || undefined,
6431
+ previous_hash: null,
6432
+ changed: null,
6433
+ };
6434
+ if (payload.compareTo) {
6435
+ const previous = readWindowPath(payload.compareTo);
6436
+ if (!previous.ok) {
6437
+ result.ok = false;
6438
+ result.reason = previous.reason || "compare_path_not_found";
6439
+ result.missing_part = previous.missing_part || undefined;
6440
+ } else {
6441
+ const previousValue = previous.value;
6442
+ const previousHash = previousValue && typeof previousValue === "object" && !Array.isArray(previousValue)
6443
+ ? previousValue.hash || previousValue.signature || previousValue.canvas_hash || null
6444
+ : typeof previousValue === "string"
6445
+ ? previousValue
6446
+ : null;
6447
+ result.previous_hash = previousHash === null || previousHash === undefined ? null : String(previousHash);
6448
+ result.changed = result.previous_hash === null ? null : result.previous_hash !== result.hash;
6449
+ if (payload.expectChanged === true && result.changed !== true) {
6450
+ result.ok = false;
6451
+ result.reason = "canvas_signature_unchanged";
6452
+ } else if (payload.expectChanged === false && result.changed !== false) {
6453
+ result.ok = false;
6454
+ result.reason = "canvas_signature_changed";
6455
+ }
6456
+ }
6457
+ }
6458
+ if (payload.storeReturnTo) {
6459
+ const stored = storeWindowValue(payload.storeReturnTo, result);
6460
+ if (!stored.ok) {
6461
+ return { ...result, ok: false, reason: "signature_store_failed", store_reason: stored.reason };
6462
+ }
6463
+ return { ...result, return_stored_to: stored.path };
6464
+ }
6465
+ return result;
6466
+ }, { compareTo, expectChanged, storeReturnTo });
6467
+ return {
6468
+ ...base,
6469
+ ...setupScopeEvidence(scope),
6470
+ ok: signatureResult && signatureResult.ok === true,
6471
+ count,
6472
+ target_index: targetIndex,
6473
+ label: action.label || action.name || undefined,
6474
+ hash: signatureResult?.hash,
6475
+ data_length: signatureResult?.data_length,
6476
+ width: signatureResult?.width,
6477
+ height: signatureResult?.height,
6478
+ css_width: signatureResult?.css_width,
6479
+ css_height: signatureResult?.css_height,
6480
+ compare_to: signatureResult?.compare_to || compareTo || undefined,
6481
+ previous_hash: signatureResult?.previous_hash,
6482
+ changed: signatureResult?.changed,
6483
+ return_stored_to: signatureResult?.return_stored_to || storeReturnTo || undefined,
6484
+ missing_part: signatureResult?.missing_part || undefined,
6485
+ store_reason: signatureResult?.store_reason || undefined,
6486
+ tag: signatureResult?.tag,
6487
+ reason: signatureResult && signatureResult.ok === true ? undefined : signatureResult?.reason || "canvas_signature_failed",
6488
+ error: signatureResult?.error || undefined,
6489
+ };
6490
+ }
6282
6491
  if (type === "assert_selector_count") {
6283
6492
  const scope = await setupActionScope(action, timeout);
6284
6493
  if (!scope.ok) return setupScopeFailure(base, scope);
@@ -5,7 +5,7 @@ declare const RIDDLE_PROOF_PROFILE_EVIDENCE_VERSION: "riddle-proof.profile-evide
5
5
  declare const RIDDLE_PROOF_PROFILE_RESULT_VERSION: "riddle-proof.profile-result.v1";
6
6
  declare const RIDDLE_PROOF_PROFILE_STATUSES: readonly ["passed", "product_regression", "proof_insufficient", "environment_blocked", "configuration_error", "needs_human_review"];
7
7
  declare const RIDDLE_PROOF_PROFILE_CHECK_TYPES: readonly ["route_loaded", "url_search_param_equals", "url_search_param_absent", "selector_visible", "selector_absent", "selector_count_at_least", "selector_count_equals", "selector_count_equal", "selector_count_eq", "dialog_count_equals", "dialog_accept_count_equals", "dialog_dismiss_count_equals", "selector_text_visible", "selector_text_absent", "selector_text_order", "observe_within", "frame_text_visible", "frame_url_equals", "frame_url_matches", "frame_no_horizontal_overflow", "text_visible", "text_absent", "http_status", "link_status", "artifact_link_status", "route_inventory", "no_horizontal_overflow", "no_mobile_horizontal_overflow", "no_fatal_console_errors", "no_console_warnings"];
8
- declare const RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES: readonly ["click", "drag", "press", "fill", "set_input_value", "set_range_value", "assert_text_visible", "assert_text_absent", "assert_selector_count", "assert_window_value", "assert_window_number", "local_storage", "session_storage", "clear_storage", "clear_console", "dialog_response", "screenshot", "wait", "wait_for_selector", "wait_for_text", "window_eval", "window_call", "window_call_until"];
8
+ declare const RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES: readonly ["click", "drag", "press", "fill", "set_input_value", "set_range_value", "canvas_signature", "assert_text_visible", "assert_text_absent", "assert_selector_count", "assert_window_value", "assert_window_number", "local_storage", "session_storage", "clear_storage", "clear_console", "dialog_response", "screenshot", "wait", "wait_for_selector", "wait_for_text", "window_eval", "window_call", "window_call_until"];
9
9
  type RiddleProofProfileStatus = typeof RIDDLE_PROOF_PROFILE_STATUSES[number];
10
10
  type RiddleProofProfileCheckType = typeof RIDDLE_PROOF_PROFILE_CHECK_TYPES[number];
11
11
  type RiddleProofProfileSetupActionType = typeof RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES[number];
@@ -134,6 +134,8 @@ interface RiddleProofProfileSetupAction {
134
134
  store_return_to?: string;
135
135
  capture_return?: boolean;
136
136
  return_summary_fields?: RiddleProofProfileReturnSummaryField[];
137
+ compare_to?: string;
138
+ expect_changed?: boolean;
137
139
  until_path?: string;
138
140
  until_expected_value?: JsonValue;
139
141
  max_calls?: number;