{
  "about": "Known-answer tests for the Clasig receipt algorithm. An implementation is correct when it reproduces every canonical string and hash, accepts the valid record, returns the expected result for every tampered record and reproduces the root.",
  "note": "The records here replay real hourly prices: not a live record. Modelled result in R after spread and fee under each scenario's published evaluation version. Not an execution, not a forecast. Bound for an unresolved scenario, if counted as a loss; null when no bound is established, including publication overlap.",
  "algorithm": [
    "A record is {scenario, events}. Each event has exactly the fields scenarioId, seq, type, at, data, prevHash and hash.",
    "canonicalJson(value) is the JSON Canonicalization Scheme, RFC 8785 (JCS), so any JCS library computes it: JSON with no whitespace; object keys sorted by UTF-16 code unit order (keys whose value is undefined are dropped); strings escaped exactly as JavaScript JSON.stringify (ES2019) escapes them; numbers read as IEEE-754 doubles and written as JavaScript writes them: the shortest digits that round-trip, plain decimal when 1e-6 <= |x| < 1e21 (0.00007, 5, never 5.0), otherwise exponent form (1e-7, 1e+21); -0 is written 0. Non-finite numbers are invalid.",
    "sha256hex(text): SHA-256 of the UTF-8 bytes of text, as 64 lowercase hex characters.",
    "Every event: hash = sha256hex(canonicalJson({scenarioId, seq, type, at, data, prevHash})), and scenarioId = scenario.id.",
    "Event 0 has type \"published\", prevHash = 64 zeros and data.scenarioHash = sha256hex(canonicalJson(scenario)), which binds the whole scenario (text, plan, reasons, evaluation and data basis) to the receipt.",
    "Event n > 0 has seq = n and prevHash = the hash of event n-1.",
    "The receipt is the hash of the last event.",
    "Checks run in this order and the first failure is reported with the failing event's own seq field: the first event is not \"published\" (seq 0); then, event by event, scenarioId differs from scenario.id (\"event belongs to another scenario\"), seq differs from its position (\"sequence gap\"), prevHash differs (\"chain broken\"), the recomputed hash differs (\"event altered\"), and for event 0 the scenarioHash differs (\"scenario content altered after publication\").",
    "archiveRoot = sha256hex(canonicalJson([[scenarioId, receipt], ...])) over every record, pairs sorted by scenarioId in UTF-16 code unit order, ids unique. root.json lists the heads as [scenarioId, receipt, eventCount].",
    "Store the receipts, root and heads you read. Later, each stored head [scenarioId, receipt, eventCount] must still be the hash of event eventCount-1 of that scenario: a missing scenario or a different hash means history was rewritten. A chain cut back to an earlier event still verifies on its own, so only a stored receipt or head catches a removed newest event.",
    "Python: use an RFC 8785 library (pip install jcs, then sha256 of jcs.canonicalize(value)). A plain json.dumps(sort_keys=True, separators=(\",\", \":\"), ensure_ascii=False) is wrong for floats: Python writes 7e-05 where JavaScript writes 0.00007 (every EURUSD and GBPUSD scenario has fee 0.00007) and 1e-07 where JavaScript writes 1e-7. Check any implementation against the test vectors.",
    "A valid receipt verifies internal consistency. Comparison with an earlier held receipt or head can detect a later rewrite. This does not establish independent publication time, scenario quality or an executed trade."
  ],
  "canonicalJson": [
    {
      "name": "keys sorted, no whitespace",
      "input": {
        "b": 1,
        "a": [
          true,
          null,
          "x"
        ],
        "c": {
          "z": 0,
          "y": "q"
        }
      },
      "canonical": "{\"a\":[true,null,\"x\"],\"b\":1,\"c\":{\"y\":\"q\",\"z\":0}}",
      "sha256": "de70d971ce7de3640e69da512985a43a03776579bed82b10a3a5eed1e9630e1a"
    },
    {
      "name": "keys sorted by UTF-16 code unit: uppercase before lowercase",
      "input": {
        "0": 4,
        "a": 1,
        "B": 2,
        "_": 3
      },
      "canonical": "{\"0\":4,\"B\":2,\"_\":3,\"a\":1}",
      "sha256": "900568b10451a3e2088be929cacd82f5be4385f0f16503b42892b5d45eca42c0"
    },
    {
      "name": "JavaScript number output: a plain Python json.dumps gets fee and small wrong",
      "input": {
        "fee": 0.00007,
        "small": 1e-7,
        "frac": 0.30000000000000004,
        "big": 1e+21,
        "tiny": 5e-324
      },
      "canonical": "{\"big\":1e+21,\"fee\":0.00007,\"frac\":0.30000000000000004,\"small\":1e-7,\"tiny\":5e-324}",
      "sha256": "e773ad7d1348407c5209e32abbfba05a0030abee9720ecffa2d2f46c2abe218a"
    },
    {
      "name": "integers and negative decimals as written by JSON.stringify",
      "input": {
        "at": 1785621660000,
        "r": -1.0270022,
        "zero": 0
      },
      "canonical": "{\"at\":1785621660000,\"r\":-1.0270022,\"zero\":0}",
      "sha256": "24440e6d3654af9223a14268fff4800dd9c5539be321dead45cdd16b6fb3a236"
    },
    {
      "name": "strings escaped as JSON.stringify does; non-ASCII kept as UTF-8",
      "input": {
        "s": "line\nbreak\t\"quoted\" \\ slash / é – 📈"
      },
      "canonical": "{\"s\":\"line\\nbreak\\t\\\"quoted\\\" \\\\ slash / é – 📈\"}",
      "sha256": "812bd40be03eb2d2e691b399b13b3bd4fd4e1c756bbc5a212145c54decba924e"
    }
  ],
  "validRecord": {
    "record": {
      "scenario": {
        "id": "1fe5519caeed9a4a",
        "instrumentId": "GBPUSD",
        "timeframe": "H1",
        "detector": {
          "id": "sweep-reclaim",
          "version": 1,
          "name": "Sweep and reclaim"
        },
        "publishedAt": 1792609260000,
        "signalBarClose": 1792609200000,
        "plan": {
          "direction": "short",
          "trigger": 1.33851,
          "invalidateOnClose": 1.34021,
          "stop": 1.34033,
          "target": 1.33487
        },
        "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it.",
        "conditions": [
          "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
          "Invalidated before trigger: any bar closing above 1.34021.",
          "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
          "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
        ],
        "changeTriggers": [
          "A close above 1.34021 before the trigger invalidates the scenario.",
          "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
          "A close beyond the sweep extreme 1.34021 would show the level failed."
        ],
        "reasons": [
          {
            "key": "swing.level_held",
            "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
            "values": {
              "swing_price": 1.34013,
              "bars_since_swing": 10
            }
          },
          {
            "key": "sweep.reclaim",
            "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
            "values": {
              "sweep_depth": 0.00007999999999985796,
              "close": 1.33853,
              "atr14": 0.0011893793478544696
            }
          }
        ],
        "riskFactors": [
          {
            "key": "data.unlicensed",
            "severity": "caution",
            "text": "Reference data without a confirmed display grant."
          }
        ],
        "evaluation": {
          "id": "eval.v1",
          "spread": 0.00015,
          "fee": 0.00007,
          "ambiguousIntrabar": "unresolved",
          "maxHoldBars": 36,
          "triggerWindowBars": 4
        },
        "dataBasis": {
          "sourceId": "market-data-hub-h1-replay",
          "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
          "sourceKind": "reference",
          "delaySeconds": 60,
          "rightsProfile": "hub-display-grant-unrecorded",
          "barCount": 69,
          "firstBarOpen": 1792360800000,
          "lastBarClose": 1792609200000,
          "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
        }
      },
      "events": [
        {
          "scenarioId": "1fe5519caeed9a4a",
          "seq": 0,
          "type": "published",
          "at": 1792609260000,
          "data": {
            "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
          },
          "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
          "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
        },
        {
          "scenarioId": "1fe5519caeed9a4a",
          "seq": 1,
          "type": "triggered",
          "at": 1792612800000,
          "data": {
            "level": 1.33851,
            "fill": 1.338435,
            "gapped": false
          },
          "prevHash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
          "hash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2"
        },
        {
          "scenarioId": "1fe5519caeed9a4a",
          "seq": 2,
          "type": "stopped",
          "at": 1792641600000,
          "data": {
            "fill": 1.340405,
            "netR": -1.12087912
          },
          "prevHash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
          "hash": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
        }
      ]
    },
    "expected": {
      "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8",
      "eventHashes": [
        "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
        "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
        "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
      ],
      "receipt": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
    }
  },
  "tampered": [
    {
      "description": "the objective (plan.target) was moved after publication",
      "record": {
        "scenario": {
          "id": "1fe5519caeed9a4a",
          "instrumentId": "GBPUSD",
          "timeframe": "H1",
          "detector": {
            "id": "sweep-reclaim",
            "version": 1,
            "name": "Sweep and reclaim"
          },
          "publishedAt": 1792609260000,
          "signalBarClose": 1792609200000,
          "plan": {
            "direction": "short",
            "trigger": 1.33851,
            "invalidateOnClose": 1.34021,
            "stop": 1.34033,
            "target": 2.33487
          },
          "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it.",
          "conditions": [
            "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
            "Invalidated before trigger: any bar closing above 1.34021.",
            "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
            "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
          ],
          "changeTriggers": [
            "A close above 1.34021 before the trigger invalidates the scenario.",
            "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
            "A close beyond the sweep extreme 1.34021 would show the level failed."
          ],
          "reasons": [
            {
              "key": "swing.level_held",
              "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
              "values": {
                "swing_price": 1.34013,
                "bars_since_swing": 10
              }
            },
            {
              "key": "sweep.reclaim",
              "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
              "values": {
                "sweep_depth": 0.00007999999999985796,
                "close": 1.33853,
                "atr14": 0.0011893793478544696
              }
            }
          ],
          "riskFactors": [
            {
              "key": "data.unlicensed",
              "severity": "caution",
              "text": "Reference data without a confirmed display grant."
            }
          ],
          "evaluation": {
            "id": "eval.v1",
            "spread": 0.00015,
            "fee": 0.00007,
            "ambiguousIntrabar": "unresolved",
            "maxHoldBars": 36,
            "triggerWindowBars": 4
          },
          "dataBasis": {
            "sourceId": "market-data-hub-h1-replay",
            "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
            "sourceKind": "reference",
            "delaySeconds": 60,
            "rightsProfile": "hub-display-grant-unrecorded",
            "barCount": 69,
            "firstBarOpen": 1792360800000,
            "lastBarClose": 1792609200000,
            "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
          }
        },
        "events": [
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 0,
            "type": "published",
            "at": 1792609260000,
            "data": {
              "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
            },
            "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
            "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 1,
            "type": "triggered",
            "at": 1792612800000,
            "data": {
              "level": 1.33851,
              "fill": 1.338435,
              "gapped": false
            },
            "prevHash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
            "hash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 2,
            "type": "stopped",
            "at": 1792641600000,
            "data": {
              "fill": 1.340405,
              "netR": -1.12087912
            },
            "prevHash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
            "hash": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
          }
        ]
      },
      "expected": {
        "ok": false,
        "failure": {
          "seq": 0,
          "problem": "scenario content altered after publication"
        }
      }
    },
    {
      "description": "the summary text was edited after publication",
      "record": {
        "scenario": {
          "id": "1fe5519caeed9a4a",
          "instrumentId": "GBPUSD",
          "timeframe": "H1",
          "detector": {
            "id": "sweep-reclaim",
            "version": 1,
            "name": "Sweep and reclaim"
          },
          "publishedAt": 1792609260000,
          "signalBarClose": 1792609200000,
          "plan": {
            "direction": "short",
            "trigger": 1.33851,
            "invalidateOnClose": 1.34021,
            "stop": 1.34033,
            "target": 1.33487
          },
          "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it. (edited)",
          "conditions": [
            "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
            "Invalidated before trigger: any bar closing above 1.34021.",
            "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
            "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
          ],
          "changeTriggers": [
            "A close above 1.34021 before the trigger invalidates the scenario.",
            "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
            "A close beyond the sweep extreme 1.34021 would show the level failed."
          ],
          "reasons": [
            {
              "key": "swing.level_held",
              "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
              "values": {
                "swing_price": 1.34013,
                "bars_since_swing": 10
              }
            },
            {
              "key": "sweep.reclaim",
              "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
              "values": {
                "sweep_depth": 0.00007999999999985796,
                "close": 1.33853,
                "atr14": 0.0011893793478544696
              }
            }
          ],
          "riskFactors": [
            {
              "key": "data.unlicensed",
              "severity": "caution",
              "text": "Reference data without a confirmed display grant."
            }
          ],
          "evaluation": {
            "id": "eval.v1",
            "spread": 0.00015,
            "fee": 0.00007,
            "ambiguousIntrabar": "unresolved",
            "maxHoldBars": 36,
            "triggerWindowBars": 4
          },
          "dataBasis": {
            "sourceId": "market-data-hub-h1-replay",
            "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
            "sourceKind": "reference",
            "delaySeconds": 60,
            "rightsProfile": "hub-display-grant-unrecorded",
            "barCount": 69,
            "firstBarOpen": 1792360800000,
            "lastBarClose": 1792609200000,
            "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
          }
        },
        "events": [
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 0,
            "type": "published",
            "at": 1792609260000,
            "data": {
              "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
            },
            "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
            "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 1,
            "type": "triggered",
            "at": 1792612800000,
            "data": {
              "level": 1.33851,
              "fill": 1.338435,
              "gapped": false
            },
            "prevHash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
            "hash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 2,
            "type": "stopped",
            "at": 1792641600000,
            "data": {
              "fill": 1.340405,
              "netR": -1.12087912
            },
            "prevHash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
            "hash": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
          }
        ]
      },
      "expected": {
        "ok": false,
        "failure": {
          "seq": 0,
          "problem": "scenario content altered after publication"
        }
      }
    },
    {
      "description": "an event result was edited in place",
      "record": {
        "scenario": {
          "id": "1fe5519caeed9a4a",
          "instrumentId": "GBPUSD",
          "timeframe": "H1",
          "detector": {
            "id": "sweep-reclaim",
            "version": 1,
            "name": "Sweep and reclaim"
          },
          "publishedAt": 1792609260000,
          "signalBarClose": 1792609200000,
          "plan": {
            "direction": "short",
            "trigger": 1.33851,
            "invalidateOnClose": 1.34021,
            "stop": 1.34033,
            "target": 1.33487
          },
          "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it.",
          "conditions": [
            "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
            "Invalidated before trigger: any bar closing above 1.34021.",
            "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
            "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
          ],
          "changeTriggers": [
            "A close above 1.34021 before the trigger invalidates the scenario.",
            "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
            "A close beyond the sweep extreme 1.34021 would show the level failed."
          ],
          "reasons": [
            {
              "key": "swing.level_held",
              "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
              "values": {
                "swing_price": 1.34013,
                "bars_since_swing": 10
              }
            },
            {
              "key": "sweep.reclaim",
              "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
              "values": {
                "sweep_depth": 0.00007999999999985796,
                "close": 1.33853,
                "atr14": 0.0011893793478544696
              }
            }
          ],
          "riskFactors": [
            {
              "key": "data.unlicensed",
              "severity": "caution",
              "text": "Reference data without a confirmed display grant."
            }
          ],
          "evaluation": {
            "id": "eval.v1",
            "spread": 0.00015,
            "fee": 0.00007,
            "ambiguousIntrabar": "unresolved",
            "maxHoldBars": 36,
            "triggerWindowBars": 4
          },
          "dataBasis": {
            "sourceId": "market-data-hub-h1-replay",
            "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
            "sourceKind": "reference",
            "delaySeconds": 60,
            "rightsProfile": "hub-display-grant-unrecorded",
            "barCount": 69,
            "firstBarOpen": 1792360800000,
            "lastBarClose": 1792609200000,
            "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
          }
        },
        "events": [
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 0,
            "type": "published",
            "at": 1792609260000,
            "data": {
              "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
            },
            "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
            "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 1,
            "type": "triggered",
            "at": 1792612800000,
            "data": {
              "level": 1.33851,
              "fill": 2.338435,
              "gapped": false
            },
            "prevHash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
            "hash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 2,
            "type": "stopped",
            "at": 1792641600000,
            "data": {
              "fill": 1.340405,
              "netR": -1.12087912
            },
            "prevHash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
            "hash": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
          }
        ]
      },
      "expected": {
        "ok": false,
        "failure": {
          "seq": 1,
          "problem": "event altered"
        }
      }
    },
    {
      "description": "an event was edited and its own hash recomputed",
      "record": {
        "scenario": {
          "id": "1fe5519caeed9a4a",
          "instrumentId": "GBPUSD",
          "timeframe": "H1",
          "detector": {
            "id": "sweep-reclaim",
            "version": 1,
            "name": "Sweep and reclaim"
          },
          "publishedAt": 1792609260000,
          "signalBarClose": 1792609200000,
          "plan": {
            "direction": "short",
            "trigger": 1.33851,
            "invalidateOnClose": 1.34021,
            "stop": 1.34033,
            "target": 1.33487
          },
          "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it.",
          "conditions": [
            "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
            "Invalidated before trigger: any bar closing above 1.34021.",
            "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
            "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
          ],
          "changeTriggers": [
            "A close above 1.34021 before the trigger invalidates the scenario.",
            "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
            "A close beyond the sweep extreme 1.34021 would show the level failed."
          ],
          "reasons": [
            {
              "key": "swing.level_held",
              "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
              "values": {
                "swing_price": 1.34013,
                "bars_since_swing": 10
              }
            },
            {
              "key": "sweep.reclaim",
              "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
              "values": {
                "sweep_depth": 0.00007999999999985796,
                "close": 1.33853,
                "atr14": 0.0011893793478544696
              }
            }
          ],
          "riskFactors": [
            {
              "key": "data.unlicensed",
              "severity": "caution",
              "text": "Reference data without a confirmed display grant."
            }
          ],
          "evaluation": {
            "id": "eval.v1",
            "spread": 0.00015,
            "fee": 0.00007,
            "ambiguousIntrabar": "unresolved",
            "maxHoldBars": 36,
            "triggerWindowBars": 4
          },
          "dataBasis": {
            "sourceId": "market-data-hub-h1-replay",
            "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
            "sourceKind": "reference",
            "delaySeconds": 60,
            "rightsProfile": "hub-display-grant-unrecorded",
            "barCount": 69,
            "firstBarOpen": 1792360800000,
            "lastBarClose": 1792609200000,
            "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
          }
        },
        "events": [
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 0,
            "type": "published",
            "at": 1792609260000,
            "data": {
              "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
            },
            "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
            "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 1,
            "type": "triggered",
            "at": 1792612800000,
            "data": {
              "level": 1.33851,
              "fill": 2.338435,
              "gapped": false
            },
            "prevHash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
            "hash": "5cbe5a02ce0fb545397fa2964e97a30394809edd44b2345d4c09f2b87660162a"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 2,
            "type": "stopped",
            "at": 1792641600000,
            "data": {
              "fill": 1.340405,
              "netR": -1.12087912
            },
            "prevHash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
            "hash": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
          }
        ]
      },
      "expected": {
        "ok": false,
        "failure": {
          "seq": 2,
          "problem": "chain broken"
        }
      }
    },
    {
      "description": "an event was removed from the middle of the chain",
      "record": {
        "scenario": {
          "id": "1fe5519caeed9a4a",
          "instrumentId": "GBPUSD",
          "timeframe": "H1",
          "detector": {
            "id": "sweep-reclaim",
            "version": 1,
            "name": "Sweep and reclaim"
          },
          "publishedAt": 1792609260000,
          "signalBarClose": 1792609200000,
          "plan": {
            "direction": "short",
            "trigger": 1.33851,
            "invalidateOnClose": 1.34021,
            "stop": 1.34033,
            "target": 1.33487
          },
          "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it.",
          "conditions": [
            "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
            "Invalidated before trigger: any bar closing above 1.34021.",
            "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
            "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
          ],
          "changeTriggers": [
            "A close above 1.34021 before the trigger invalidates the scenario.",
            "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
            "A close beyond the sweep extreme 1.34021 would show the level failed."
          ],
          "reasons": [
            {
              "key": "swing.level_held",
              "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
              "values": {
                "swing_price": 1.34013,
                "bars_since_swing": 10
              }
            },
            {
              "key": "sweep.reclaim",
              "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
              "values": {
                "sweep_depth": 0.00007999999999985796,
                "close": 1.33853,
                "atr14": 0.0011893793478544696
              }
            }
          ],
          "riskFactors": [
            {
              "key": "data.unlicensed",
              "severity": "caution",
              "text": "Reference data without a confirmed display grant."
            }
          ],
          "evaluation": {
            "id": "eval.v1",
            "spread": 0.00015,
            "fee": 0.00007,
            "ambiguousIntrabar": "unresolved",
            "maxHoldBars": 36,
            "triggerWindowBars": 4
          },
          "dataBasis": {
            "sourceId": "market-data-hub-h1-replay",
            "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
            "sourceKind": "reference",
            "delaySeconds": 60,
            "rightsProfile": "hub-display-grant-unrecorded",
            "barCount": 69,
            "firstBarOpen": 1792360800000,
            "lastBarClose": 1792609200000,
            "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
          }
        },
        "events": [
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 0,
            "type": "published",
            "at": 1792609260000,
            "data": {
              "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
            },
            "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
            "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 2,
            "type": "stopped",
            "at": 1792641600000,
            "data": {
              "fill": 1.340405,
              "netR": -1.12087912
            },
            "prevHash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2",
            "hash": "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
          }
        ]
      },
      "expected": {
        "ok": false,
        "failure": {
          "seq": 2,
          "problem": "sequence gap"
        }
      }
    },
    {
      "description": "the newest event was removed: the chain still verifies, so only a receipt or root you stored earlier catches this",
      "record": {
        "scenario": {
          "id": "1fe5519caeed9a4a",
          "instrumentId": "GBPUSD",
          "timeframe": "H1",
          "detector": {
            "id": "sweep-reclaim",
            "version": 1,
            "name": "Sweep and reclaim"
          },
          "publishedAt": 1792609260000,
          "signalBarClose": 1792609200000,
          "plan": {
            "direction": "short",
            "trigger": 1.33851,
            "invalidateOnClose": 1.34021,
            "stop": 1.34033,
            "target": 1.33487
          },
          "summary": "Bearish sweep and reclaim scenario on GBPUSD H1: it triggers only if price trades at or below 1.33851 within 4 bars. A close above 1.34021 first invalidates it.",
          "conditions": [
            "Trigger: a trade at or below 1.33851 by 2026-10-21 23:00 UTC (4 bars).",
            "Invalidated before trigger: any bar closing above 1.34021.",
            "After trigger: protective level 1.34033, objective 1.33487, time limit 36 bars.",
            "Evaluation eval.v1: mid prices, assumed spread 0.00015 and fee 0.00007 per round trip; a bar touching both sides is unresolved; a bar that opens beyond the objective assumes no entry and expires the scenario."
          ],
          "changeTriggers": [
            "A close above 1.34021 before the trigger invalidates the scenario.",
            "No trade through 1.33851 by 2026-10-21 23:00 UTC expires it, as does an opening gap beyond 1.33487.",
            "A close beyond the sweep extreme 1.34021 would show the level failed."
          ],
          "reasons": [
            {
              "key": "swing.level_held",
              "text": "Swing high 1.34013 formed 10 bars earlier (confirmed 7 bars earlier) and held on every close since.",
              "values": {
                "swing_price": 1.34013,
                "bars_since_swing": 10
              }
            },
            {
              "key": "sweep.reclaim",
              "text": "The signal bar traded 0.00008 beyond it, then closed back at 1.33853 (sweep depth at most 1 ATR).",
              "values": {
                "sweep_depth": 0.00007999999999985796,
                "close": 1.33853,
                "atr14": 0.0011893793478544696
              }
            }
          ],
          "riskFactors": [
            {
              "key": "data.unlicensed",
              "severity": "caution",
              "text": "Reference data without a confirmed display grant."
            }
          ],
          "evaluation": {
            "id": "eval.v1",
            "spread": 0.00015,
            "fee": 0.00007,
            "ambiguousIntrabar": "unresolved",
            "maxHoldBars": 36,
            "triggerWindowBars": 4
          },
          "dataBasis": {
            "sourceId": "market-data-hub-h1-replay",
            "sourceLabel": "Real hourly prices (Twelve Data; Bitcoin from OKX), replayed",
            "sourceKind": "reference",
            "delaySeconds": 60,
            "rightsProfile": "hub-display-grant-unrecorded",
            "barCount": 69,
            "firstBarOpen": 1792360800000,
            "lastBarClose": 1792609200000,
            "inputHash": "d1854a66f5d59ccabfa35dfd78e5e182fa6a44c97af10ae6366e923dc8afa3d6"
          }
        },
        "events": [
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 0,
            "type": "published",
            "at": 1792609260000,
            "data": {
              "scenarioHash": "83062297ff215d082abf69ef8e2bbe9b7f9aab4c1c64b42430f1c4c96aa9f8c8"
            },
            "prevHash": "0000000000000000000000000000000000000000000000000000000000000000",
            "hash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec"
          },
          {
            "scenarioId": "1fe5519caeed9a4a",
            "seq": 1,
            "type": "triggered",
            "at": 1792612800000,
            "data": {
              "level": 1.33851,
              "fill": 1.338435,
              "gapped": false
            },
            "prevHash": "36696a6dcd3f4006ebc43d6b8c9a26c6532ec3bbf0e0790f9cdc91d9345ec9ec",
            "hash": "f1a512dcc545f014a80118723338faa3cedfda183be4adbc259bb1c03a9875e2"
          }
        ]
      },
      "expected": {
        "ok": true,
        "failure": null
      }
    }
  ],
  "archiveRoot": {
    "heads": [
      [
        "4930a151fb094014",
        "324befdf9697a4cead2df6e1eb27d270b833a1b04c83ed9fbc6ba4e7193e576d"
      ],
      [
        "1fe5519caeed9a4a",
        "dd817cefef1a4ff586186cba7aa8edaf95b8bf24fe3e76eb2f7b8e5d428c7df5"
      ],
      [
        "0f33b0c9cddef986",
        "ec7f1de83c1af0afeda60632d45181605f97063021f5466d9c093b0501f19ad1"
      ]
    ],
    "root": "6c060ab45c4f6f42f4fe8e3cfef64da098ecac6a23fddd07bc7d091c72b48854"
  }
}
