@action-state-group/capsule-viewer 0.27.1 → 0.27.2

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.
@@ -13391,6 +13391,158 @@ ${body}
13391
13391
  };
13392
13392
  }
13393
13393
 
13394
+ // src/deal-standalone-report.ts
13395
+ var DEAL_V0 = "x-deal-v0";
13396
+ var DEAL_V1 = "x-deal-v1";
13397
+ var STANDALONE = "x-deal-report/v0";
13398
+ var POINTER = "sealed_report";
13399
+ var REPORT_ACTION = "capsulectl-deal-report";
13400
+ var STEP_TYPES = /* @__PURE__ */ new Set(["deal_step", "step_completed", "step_failed"]);
13401
+ var COPY_AUDIENCES = /* @__PURE__ */ new Set(["counterparty", "adjudicator", "keep"]);
13402
+ var isObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
13403
+ var obj = (value) => isObj(value) ? value : {};
13404
+ async function dealStandaloneReport(bundle) {
13405
+ const value = obj(bundle);
13406
+ const extensions2 = obj(value["extensions"]);
13407
+ if (!(STANDALONE in extensions2) || DEAL_V1 in extensions2) return null;
13408
+ if (!ed25519Available()) return null;
13409
+ return await standaloneReportHolds(value, extensions2) ? "pass" : "fail";
13410
+ }
13411
+ async function standaloneReportHolds(value, extensions2) {
13412
+ const section = extensions2[DEAL_V0];
13413
+ if (!isObj(section) || Object.keys(section).length !== 1) return false;
13414
+ const id = section[POINTER];
13415
+ const x = extensions2[STANDALONE];
13416
+ if (typeof id !== "string" || !isObj(x) || Object.keys(x).length !== 2)
13417
+ return false;
13418
+ const record = x["record"];
13419
+ const input = x["agent_input"];
13420
+ if (!isObj(record) || !isObj(input) || record["capsule_id"] !== id || record["action_id"] !== REPORT_ACTION)
13421
+ return false;
13422
+ const reportKey = await verifiedProducerKey(record);
13423
+ if (reportKey === void 0) return false;
13424
+ const last = await lastStepRecord(value);
13425
+ if (last === void 0) return false;
13426
+ if (await verifiedProducerKey(last) !== reportKey) return false;
13427
+ const capsule = {};
13428
+ for (const [k, v] of Object.entries(record))
13429
+ if (k !== "signature" && k !== "key_id") capsule[k] = v;
13430
+ const disclosed = await verifyDisclosureEnvelope({
13431
+ capsule,
13432
+ disclosures: { agent_input: input }
13433
+ });
13434
+ if (!disclosed.ok || disclosed.disclosuresMatched !== 1) return false;
13435
+ const logId = obj(value["completeness_certificate"])["log_id"];
13436
+ if (typeof logId !== "string" || !logId.startsWith("deal/")) return false;
13437
+ const audience = input["audience"];
13438
+ if (input["type"] !== "deal_report" || input["profile"] !== DEAL_V0 || typeof audience !== "string" || !COPY_AUDIENCES.has(audience) || input["deal_id"] !== logId.slice("deal/".length))
13439
+ return false;
13440
+ const checkpoint = obj(value["checkpoint"]);
13441
+ const bound = input["deal_checkpoint"];
13442
+ if (!isObj(bound) || Object.keys(bound).length !== 3) return false;
13443
+ const boundSize = jsonUint(bound["mmr_size"]);
13444
+ const size = jsonUint(checkpoint["mmr_size"]);
13445
+ if (bound["log_id"] !== logId || boundSize === void 0 || size === void 0 || boundSize !== size || bound["root"] !== checkpoint["root"])
13446
+ return false;
13447
+ const records = Array.isArray(value["records"]) ? value["records"] : [];
13448
+ if (records.some((r) => obj(r)["action_id"] === REPORT_ACTION)) return false;
13449
+ const asOf = instant(obj(obj(input["report"])["lifecycle"])["as_of"]);
13450
+ const signed = instant(checkpoint["timestamp"]);
13451
+ return asOf !== void 0 && signed !== void 0 && asOf === signed;
13452
+ }
13453
+ async function verifiedProducerKey(record) {
13454
+ const id = record["capsule_id"];
13455
+ const signature2 = hexBytes2(record["signature"]);
13456
+ const key = record["key_id"];
13457
+ if (typeof id !== "string" || id === "" || signature2 === void 0)
13458
+ return void 0;
13459
+ if (typeof key !== "string" || hexBytes2(key) === void 0) return void 0;
13460
+ const result3 = await verifyProducerEnvelope(id, signature2);
13461
+ if (!result3.ok || result3.publicKey === void 0) return void 0;
13462
+ const verified = Array.from(
13463
+ result3.publicKey,
13464
+ (b) => b.toString(16).padStart(2, "0")
13465
+ ).join("");
13466
+ return verified === key.toLowerCase() ? key : void 0;
13467
+ }
13468
+ async function lastStepRecord(value) {
13469
+ const memberships2 = obj(
13470
+ obj(value["completeness_certificate"])["memberships"]
13471
+ );
13472
+ const records = Array.isArray(value["records"]) ? value["records"] : [];
13473
+ let last;
13474
+ let lastSeq = 0n;
13475
+ for (const raw of records) {
13476
+ const record = obj(raw);
13477
+ const type = (await recordHeader(value, record))?.["record_type"];
13478
+ if (typeof type !== "string" || !STEP_TYPES.has(type)) continue;
13479
+ const id = record["capsule_id"];
13480
+ if (typeof id !== "string") continue;
13481
+ const seq = jsonUint(obj(obj(memberships2[id])["log_coordinates"])["seq"]);
13482
+ if (seq !== void 0 && seq > lastSeq) {
13483
+ last = record;
13484
+ lastSeq = seq;
13485
+ }
13486
+ }
13487
+ return last;
13488
+ }
13489
+ async function recordHeader(value, record) {
13490
+ const embedded = record["evidence_record_header"];
13491
+ if (isObj(embedded)) return embedded;
13492
+ const id = record["capsule_id"];
13493
+ if (typeof id !== "string" || id === "") return void 0;
13494
+ const disclosed = obj(obj(value["disclosures"])[id])["agent_input"];
13495
+ if (!isObj(disclosed)) return void 0;
13496
+ const capsule = {};
13497
+ for (const [k, v] of Object.entries(record))
13498
+ if (k !== "signature" && k !== "key_id") capsule[k] = v;
13499
+ const checked = await verifyDisclosureEnvelope({
13500
+ capsule,
13501
+ disclosures: { agent_input: disclosed }
13502
+ });
13503
+ return checked.ok && checked.disclosuresMatched === 1 ? disclosed : void 0;
13504
+ }
13505
+ function jsonUint(value) {
13506
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && !Object.is(value, -0) ? BigInt(value) : void 0;
13507
+ }
13508
+ function hexBytes2(value) {
13509
+ if (typeof value !== "string" || value.length % 2 !== 0 || !/^[0-9a-fA-F]*$/u.test(value))
13510
+ return void 0;
13511
+ const out = new Uint8Array(value.length / 2);
13512
+ for (let i = 0; i < out.length; i++)
13513
+ out[i] = parseInt(value.slice(2 * i, 2 * i + 2), 16);
13514
+ return out;
13515
+ }
13516
+ function instant(value) {
13517
+ if (typeof value !== "string") return void 0;
13518
+ const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:(Z)|([+-])(\d{2}):(\d{2}))$/u.exec(
13519
+ value
13520
+ );
13521
+ if (m === null) return void 0;
13522
+ const [, y, mo, d, h, mi, s, frac, z, sign, oh, om] = m;
13523
+ const fields2 = [y, mo, d, h, mi, s].map(Number);
13524
+ const [year, month, day, hour, minute, second] = fields2;
13525
+ if (month < 1 || month > 12 || day < 1 || day > civil(year, month + 1, 0).getUTCDate() || hour > 23 || minute > 59 || second > 59)
13526
+ return void 0;
13527
+ let offset = 0;
13528
+ if (z === void 0) {
13529
+ const offHour = Number(oh);
13530
+ const offMinute = Number(om);
13531
+ if (offHour > 23 || offMinute > 59) return void 0;
13532
+ offset = (sign === "-" ? -1 : 1) * (offHour * 60 + offMinute) * 60;
13533
+ }
13534
+ const at = civil(year, month, day);
13535
+ at.setUTCHours(hour, minute, second, 0);
13536
+ const seconds = BigInt(at.getTime() / 1e3) - BigInt(offset);
13537
+ const nanos = (frac ?? "").slice(0, 9).padEnd(9, "0");
13538
+ return `${seconds}.${nanos}`;
13539
+ }
13540
+ function civil(year, month, day) {
13541
+ const at = /* @__PURE__ */ new Date(0);
13542
+ at.setUTCFullYear(year, month - 1, day);
13543
+ return at;
13544
+ }
13545
+
13394
13546
  // src/builtin-manifests.ts
13395
13547
  var BUILTIN_MANIFEST_REPORT_ROWS = Object.freeze(
13396
13548
  {
@@ -13553,7 +13705,7 @@ ${body}
13553
13705
  var BUILTIN_SECTION_MANIFESTS = Object.freeze([BUILTIN_MANIFEST_COMPOSED]);
13554
13706
 
13555
13707
  // src/chart-spec.ts
13556
- var isObj = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
13708
+ var isObj2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
13557
13709
  var ChartRefusal = class extends Error {
13558
13710
  reason;
13559
13711
  pointer;
@@ -13603,7 +13755,7 @@ ${body}
13603
13755
  );
13604
13756
  }
13605
13757
  function readDay(value, at) {
13606
- if (isObj(value)) {
13758
+ if (isObj2(value)) {
13607
13759
  onlyKeys(value, ["year", "month", "date", "utc"], at);
13608
13760
  const { year, month, date, utc } = value;
13609
13761
  if (utc === true && Number.isInteger(year) && Number.isInteger(month) && Number.isInteger(date)) {
@@ -13619,7 +13771,7 @@ ${body}
13619
13771
  );
13620
13772
  }
13621
13773
  function readPredicate(value, at) {
13622
- need(isObj(value), void 0, at, "a predicate object");
13774
+ need(isObj2(value), void 0, at, "a predicate object");
13623
13775
  const p = value;
13624
13776
  for (const kind of ["and", "or"])
13625
13777
  if (Object.hasOwn(p, kind)) {
@@ -13705,7 +13857,7 @@ ${body}
13705
13857
  function resolveField(header, path2) {
13706
13858
  let at = header;
13707
13859
  for (const name of path2.split(".")) {
13708
- if (!isObj(at) || !Object.hasOwn(at, name)) return MISSING;
13860
+ if (!isObj2(at) || !Object.hasOwn(at, name)) return MISSING;
13709
13861
  at = at[name];
13710
13862
  }
13711
13863
  return at;
@@ -13744,7 +13896,7 @@ ${body}
13744
13896
  }
13745
13897
  }
13746
13898
  function readChannel(value, at) {
13747
- need(isObj(value), void 0, at, "an encoding object");
13899
+ need(isObj2(value), void 0, at, "an encoding object");
13748
13900
  const c = value;
13749
13901
  onlyKeys(c, ["field", "type", "aggregate", "timeUnit", "title"], at);
13750
13902
  const type = need(
@@ -13797,7 +13949,7 @@ ${body}
13797
13949
  return out;
13798
13950
  }
13799
13951
  function readWindow(value, at) {
13800
- need(isObj(value), void 0, at, "{field, from, to}");
13952
+ need(isObj2(value), void 0, at, "{field, from, to}");
13801
13953
  const w = value;
13802
13954
  onlyKeys(w, ["field", "from", "to"], at);
13803
13955
  const field = readField(w.field, pointerOf(at, "field"));
@@ -13822,11 +13974,11 @@ ${body}
13822
13974
  return { field, from, to };
13823
13975
  }
13824
13976
  function readStatement(value, at) {
13825
- need(isObj(value), void 0, at, "an object");
13977
+ need(isObj2(value), void 0, at, "an object");
13826
13978
  const s = value;
13827
13979
  onlyKeys(s, ["population", "window", "runs", "values"], at);
13828
13980
  const pop = s.population;
13829
- need(isObj(pop), void 0, pointerOf(at, "population"), "{count}");
13981
+ need(isObj2(pop), void 0, pointerOf(at, "population"), "{count}");
13830
13982
  onlyKeys(pop, ["count"], pointerOf(at, "population"));
13831
13983
  const count2 = pop.count;
13832
13984
  need(
@@ -13841,7 +13993,7 @@ ${body}
13841
13993
  if (Object.hasOwn(s, "runs")) {
13842
13994
  const r = s.runs;
13843
13995
  const rat = pointerOf(at, "runs");
13844
- need(isObj(r), void 0, rat, "{filter, field}");
13996
+ need(isObj2(r), void 0, rat, "{filter, field}");
13845
13997
  onlyKeys(r, ["filter", "field"], rat);
13846
13998
  out.runs = {
13847
13999
  filter: readPredicate(r.filter, pointerOf(rat, "filter")),
@@ -13857,7 +14009,7 @@ ${body}
13857
14009
  );
13858
14010
  values.forEach((v, i) => {
13859
14011
  const vat = pointerOf(pointerOf(at, "values"), i);
13860
- need(isObj(v), void 0, vat, "a group object");
14012
+ need(isObj2(v), void 0, vat, "a group object");
13861
14013
  onlyKeys(v, [...CHANNELS, "not_run"], vat);
13862
14014
  if (Object.hasOwn(v, "not_run"))
13863
14015
  need(
@@ -13880,7 +14032,7 @@ ${body}
13880
14032
  }
13881
14033
  return void 0;
13882
14034
  }
13883
- if (isObj(value))
14035
+ if (isObj2(value))
13884
14036
  for (const [k, v] of Object.entries(value)) {
13885
14037
  const found = inexactNumber(v, pointerOf(at, k));
13886
14038
  if (found !== void 0) return found;
@@ -13888,7 +14040,7 @@ ${body}
13888
14040
  return void 0;
13889
14041
  }
13890
14042
  function readChartSpec(value) {
13891
- need(isObj(value), void 0, "", "a Vega-Lite object");
14043
+ need(isObj2(value), void 0, "", "a Vega-Lite object");
13892
14044
  const inexact = inexactNumber(value, "");
13893
14045
  if (inexact !== void 0)
13894
14046
  refuse(
@@ -13913,11 +14065,11 @@ ${body}
13913
14065
  );
13914
14066
  need(spec.$schema === SCHEMA, void 0, "/$schema", SCHEMA);
13915
14067
  const data = spec.data;
13916
- need(isObj(data), void 0, "/data", '{"name": "dataset"}');
14068
+ need(isObj2(data), void 0, "/data", '{"name": "dataset"}');
13917
14069
  onlyKeys(data, ["name"], "/data");
13918
14070
  need(data.name === "dataset", void 0, "/data/name", '"dataset"');
13919
14071
  let mark;
13920
- if (isObj(spec.mark)) {
14072
+ if (isObj2(spec.mark)) {
13921
14073
  onlyKeys(spec.mark, ["type"], "/mark");
13922
14074
  mark = need(
13923
14075
  MARKS.includes(spec.mark.type),
@@ -13942,7 +14094,7 @@ ${body}
13942
14094
  );
13943
14095
  spec.transform.forEach((t, i) => {
13944
14096
  const at = pointerOf("/transform", i);
13945
- need(isObj(t), void 0, at, "{filter: predicate}");
14097
+ need(isObj2(t), void 0, at, "{filter: predicate}");
13946
14098
  onlyKeys(t, ["filter"], at);
13947
14099
  need(
13948
14100
  Object.hasOwn(t, "filter"),
@@ -13954,7 +14106,7 @@ ${body}
13954
14106
  });
13955
14107
  }
13956
14108
  const encoding = spec.encoding;
13957
- need(isObj(encoding), void 0, "/encoding", "an object");
14109
+ need(isObj2(encoding), void 0, "/encoding", "an object");
13958
14110
  onlyKeys(encoding, CHANNELS, "/encoding");
13959
14111
  const channels = {};
13960
14112
  for (const name of CHANNELS)
@@ -13964,7 +14116,7 @@ ${body}
13964
14116
  pointerOf("/encoding", name)
13965
14117
  );
13966
14118
  const usermeta = spec.usermeta;
13967
- need(isObj(usermeta), void 0, "/usermeta", "{capsule: statement}");
14119
+ need(isObj2(usermeta), void 0, "/usermeta", "{capsule: statement}");
13968
14120
  onlyKeys(usermeta, ["capsule"], "/usermeta");
13969
14121
  const statement = readStatement(
13970
14122
  usermeta.capsule,
@@ -14041,9 +14193,9 @@ ${body}
14041
14193
  refuse("chart-dataset-invalid", "the dataset plan has no nodes");
14042
14194
  const out = [];
14043
14195
  for (const node of nodes) {
14044
- if (!isObj(node) || node.operator !== "traditional.window") continue;
14196
+ if (!isObj2(node) || node.operator !== "traditional.window") continue;
14045
14197
  const p = node.params;
14046
- if (!isObj(p) || typeof p.field !== "string" || !isCalendarDate(p.from) || !isCalendarDate(p.to))
14198
+ if (!isObj2(p) || typeof p.field !== "string" || !isCalendarDate(p.from) || !isCalendarDate(p.to))
14047
14199
  refuse(
14048
14200
  "chart-dataset-invalid",
14049
14201
  "a window node of the dataset plan has no {field, from, to}"
@@ -14329,12 +14481,12 @@ ${body}
14329
14481
  }
14330
14482
 
14331
14483
  // src/report-view.ts
14332
- var isObj2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14484
+ var isObj3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14333
14485
  var refuse2 = (reason, message, pointer) => {
14334
14486
  throw new ChartRefusal(reason, message, pointer);
14335
14487
  };
14336
14488
  var ID = /^[a-z][a-z0-9_]{0,31}$/u;
14337
- var isView = (value) => isObj2(value) && Object.hasOwn(value, "view");
14489
+ var isView = (value) => isObj3(value) && Object.hasOwn(value, "view");
14338
14490
  var keyChannel = (chart) => chart.keys.find((k) => k !== "x");
14339
14491
  function onlyKeys2(value, allowed, at) {
14340
14492
  for (const key of Object.keys(value))
@@ -14348,7 +14500,7 @@ ${body}
14348
14500
  var ROLES = ["activity", "judgment", "adjudication"];
14349
14501
  var CLASSES = ["good", "bad", "open"];
14350
14502
  function readEntry(value, at, seen, lane = false) {
14351
- if (!isObj2(value))
14503
+ if (!isObj3(value))
14352
14504
  return refuse2("view-unsupported-member", `${at} must be an object`, at);
14353
14505
  onlyKeys2(
14354
14506
  value,
@@ -14388,7 +14540,7 @@ ${body}
14388
14540
  }
14389
14541
  if (value.classes !== void 0) {
14390
14542
  const c = value.classes;
14391
- if (!isObj2(c) || Object.keys(c).length === 0)
14543
+ if (!isObj3(c) || Object.keys(c).length === 0)
14392
14544
  refuse2(
14393
14545
  "view-unsupported-member",
14394
14546
  `${at}/classes must be a non-empty object`,
@@ -14566,7 +14718,7 @@ ${body}
14566
14718
  };
14567
14719
  }
14568
14720
  function checkView(value, dataset) {
14569
- if (!isObj2(value))
14721
+ if (!isObj3(value))
14570
14722
  return refuse2("view-unsupported-member", "a view must be an object", "");
14571
14723
  const kind = value.view;
14572
14724
  const checkOne = (id, spec, at) => {
@@ -14741,7 +14893,7 @@ ${body}
14741
14893
  }
14742
14894
 
14743
14895
  // src/chart-dataset.ts
14744
- var isObj3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14896
+ var isObj4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14745
14897
  var RECORD_HEADER_MEMBER = "evidence_record_header";
14746
14898
  var DATASET_VERSION = "evidence-dataset-v0";
14747
14899
  var HEX642 = /^[0-9a-f]{64}$/u;
@@ -14750,15 +14902,15 @@ ${body}
14750
14902
  };
14751
14903
  function digestRef(value, what) {
14752
14904
  if (value === void 0) return void 0;
14753
- if (!isObj3(value) || value.digest_alg !== "SHA-256" || typeof value.digest !== "string" || !HEX642.test(value.digest))
14905
+ if (!isObj4(value) || value.digest_alg !== "SHA-256" || typeof value.digest !== "string" || !HEX642.test(value.digest))
14754
14906
  return invalid(`${what} is not {digest_alg: "SHA-256", digest: <64-hex>}`);
14755
14907
  return value.digest;
14756
14908
  }
14757
14909
  function resultDocument2(context, result3) {
14758
14910
  const member = disclosureOf(context, result3.capsuleId, result3.member);
14759
- if (member.state !== "disclosed" || !isObj3(member.payload)) return void 0;
14911
+ if (member.state !== "disclosed" || !isObj4(member.payload)) return void 0;
14760
14912
  const document2 = result3.form === "book" ? member.payload.statement : member.payload;
14761
- return isObj3(document2) ? document2 : void 0;
14913
+ return isObj4(document2) ? document2 : void 0;
14762
14914
  }
14763
14915
  async function digestOf(value) {
14764
14916
  try {
@@ -14772,7 +14924,7 @@ ${body}
14772
14924
  async function documentsByDigest(context) {
14773
14925
  const found = /* @__PURE__ */ new Map();
14774
14926
  const consider = async (value) => {
14775
- if (!isObj3(value) || value.dataset_version === void 0 && !(isObj3(value.header) && value.header.ir_version !== void 0))
14927
+ if (!isObj4(value) || value.dataset_version === void 0 && !(isObj4(value.header) && value.header.ir_version !== void 0))
14776
14928
  return;
14777
14929
  const digest2 = await digestOf(value);
14778
14930
  if (digest2 !== void 0) found.set(digest2, value);
@@ -14782,10 +14934,10 @@ ${body}
14782
14934
  const disclosed = disclosureOf(context, record.capsule_id, member);
14783
14935
  if (disclosed.state !== "disclosed") continue;
14784
14936
  await consider(disclosed.payload);
14785
- if (isObj3(disclosed.payload)) await consider(disclosed.payload.statement);
14937
+ if (isObj4(disclosed.payload)) await consider(disclosed.payload.statement);
14786
14938
  }
14787
14939
  const inline = record[RECORD_HEADER_MEMBER];
14788
- if (isObj3(inline)) await consider(inline.statement);
14940
+ if (isObj4(inline)) await consider(inline.statement);
14789
14941
  }
14790
14942
  return found;
14791
14943
  }
@@ -14793,7 +14945,7 @@ ${body}
14793
14945
  const found = /* @__PURE__ */ new Map();
14794
14946
  for (const record of context.records) {
14795
14947
  const inline = record[RECORD_HEADER_MEMBER];
14796
- if (isObj3(inline)) {
14948
+ if (isObj4(inline)) {
14797
14949
  const digest3 = await digestOf(inline);
14798
14950
  if (digest3 !== void 0)
14799
14951
  found.set(digest3, { header: inline, recordId: record.capsule_id });
@@ -14801,7 +14953,7 @@ ${body}
14801
14953
  }
14802
14954
  const digest2 = committedDigest(record, "agent_input");
14803
14955
  const disclosed = disclosureOf(context, record.capsule_id, "agent_input");
14804
- if (digest2 !== void 0 && disclosed.state === "disclosed" && isObj3(disclosed.payload))
14956
+ if (digest2 !== void 0 && disclosed.state === "disclosed" && isObj4(disclosed.payload))
14805
14957
  found.set(digest2, {
14806
14958
  header: disclosed.payload,
14807
14959
  recordId: record.capsule_id
@@ -14832,7 +14984,7 @@ ${body}
14832
14984
  const rows = [];
14833
14985
  let last = -1;
14834
14986
  for (const raw of dataset.rows) {
14835
- if (!isObj3(raw) || Object.keys(raw).sort().join(",") !== "digest,digest_alg,record_type,seq" || !Number.isSafeInteger(raw.seq) || raw.seq <= last || typeof raw.record_type !== "string" || raw.digest_alg !== "SHA-256" || typeof raw.digest !== "string" || !HEX642.test(raw.digest))
14987
+ if (!isObj4(raw) || Object.keys(raw).sort().join(",") !== "digest,digest_alg,record_type,seq" || !Number.isSafeInteger(raw.seq) || raw.seq <= last || typeof raw.record_type !== "string" || raw.digest_alg !== "SHA-256" || typeof raw.digest !== "string" || !HEX642.test(raw.digest))
14836
14988
  return invalid(
14837
14989
  "a dataset row is not {seq, record_type, digest_alg, digest}, in seq order"
14838
14990
  );
@@ -17216,12 +17368,12 @@ ${s} .check .steps{margin:12px 0 0;padding-left:20px;font-size:14px;line-height:
17216
17368
  var MAX_LABELS = 8;
17217
17369
  var MAX_LABEL = 60;
17218
17370
  var EXTENSION = /^x-[a-z0-9][a-z0-9._-]*$/u;
17219
- var isObj4 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
17371
+ var isObj5 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
17220
17372
  function str(value, max) {
17221
17373
  return typeof value === "string" && value.length > 0 && value.length <= max ? value : void 0;
17222
17374
  }
17223
17375
  function readScope(value) {
17224
- if (!isObj4(value)) return void 0;
17376
+ if (!isObj5(value)) return void 0;
17225
17377
  const pack = str(value.pack, 120);
17226
17378
  const salting = str(value.salting, 60);
17227
17379
  const saltId = str(value.salt_id, 120);
@@ -17230,7 +17382,7 @@ ${s} .check .steps{margin:12px 0 0;padding-left:20px;font-size:14px;line-height:
17230
17382
  return { pack, tier: value.tier, salting, saltId };
17231
17383
  }
17232
17384
  function readEntry2(value, grouped) {
17233
- if (!isObj4(value)) return void 0;
17385
+ if (!isObj5(value)) return void 0;
17234
17386
  const labels = value.request_labels;
17235
17387
  if (!Array.isArray(labels) || labels.length > MAX_LABELS || labels.some((l) => str(l, MAX_LABEL) === void 0))
17236
17388
  return void 0;
@@ -17243,7 +17395,7 @@ ${s} .check .steps{margin:12px 0 0;padding-left:20px;font-size:14px;line-height:
17243
17395
  let halves;
17244
17396
  if (value.halves !== void 0) {
17245
17397
  const h = value.halves;
17246
- if (!isObj4(h) || !Number.isSafeInteger(h.present) || !Number.isSafeInteger(h.of) || h.present < 0 || h.of < 1 || h.present > h.of)
17398
+ if (!isObj5(h) || !Number.isSafeInteger(h.present) || !Number.isSafeInteger(h.of) || h.present < 0 || h.of < 1 || h.present > h.of)
17247
17399
  return void 0;
17248
17400
  halves = { present: h.present, of: h.of };
17249
17401
  }
@@ -17269,13 +17421,13 @@ ${s} .check .steps{margin:12px 0 0;padding-left:20px;font-size:14px;line-height:
17269
17421
  };
17270
17422
  }
17271
17423
  function readSubjectHistory(document2) {
17272
- if (!isObj4(document2)) return void 0;
17424
+ if (!isObj5(document2)) return void 0;
17273
17425
  const found = Object.entries(document2).filter(
17274
- ([key, member]) => EXTENSION.test(key) && isObj4(member) && isObj4(member.subject_history)
17426
+ ([key, member]) => EXTENSION.test(key) && isObj5(member) && isObj5(member.subject_history)
17275
17427
  );
17276
17428
  if (found.length !== 1) return void 0;
17277
17429
  const block = found[0][1].subject_history;
17278
- if (!isObj4(block.conversations)) return void 0;
17430
+ if (!isObj5(block.conversations)) return void 0;
17279
17431
  const scope = readScope(block.handle_scope);
17280
17432
  const operator = scope?.tier === "operator";
17281
17433
  const grouped = operator || scope?.tier === "shared" && scope.salting === "per-share";
@@ -17866,13 +18018,13 @@ ${s} .check .steps{margin:12px 0 0;padding-left:20px;font-size:14px;line-height:
17866
18018
  }
17867
18019
  function builtCommit() {
17868
18020
  if (false) return void 0;
17869
- return commitPrefix("3897a3681a97fd4d0ada231384d2b77d0f7e24e0");
18021
+ return commitPrefix("c6bb35516b0733b9cd070c632bf6d7efc05c83b9");
17870
18022
  }
17871
18023
  var commit = builtCommit();
17872
18024
  var unreleased = false;
17873
18025
  var VIEWER_BUILD = {
17874
18026
  viewer: "@action-state-group/capsule-viewer",
17875
- viewerVersion: "0.27.1",
18027
+ viewerVersion: "0.27.2",
17876
18028
  verifier: "@action-state-group/agent-action-capsule",
17877
18029
  verifierVersion: "0.16.0",
17878
18030
  cllVersion: "0.4.0",
@@ -28817,6 +28969,7 @@ ${pad.repeat(depth)}`;
28817
28969
  return "unreadable";
28818
28970
  }
28819
28971
  const context = await buildVerifiedBundleContext(bundle);
28972
+ if (await dealStandaloneReport(bundle) === "fail") return "unverified";
28820
28973
  const registry = options.registry ?? defaultRegistry;
28821
28974
  const resolution = await registry.resolve(
28822
28975
  context,
@@ -29742,158 +29895,6 @@ ${pad.repeat(depth)}`;
29742
29895
  }
29743
29896
  }
29744
29897
 
29745
- // src/deal-standalone-report.ts
29746
- var DEAL_V0 = "x-deal-v0";
29747
- var DEAL_V1 = "x-deal-v1";
29748
- var STANDALONE = "x-deal-report/v0";
29749
- var POINTER = "sealed_report";
29750
- var REPORT_ACTION = "capsulectl-deal-report";
29751
- var STEP_TYPES = /* @__PURE__ */ new Set(["deal_step", "step_completed", "step_failed"]);
29752
- var COPY_AUDIENCES = /* @__PURE__ */ new Set(["counterparty", "adjudicator", "keep"]);
29753
- var isObj5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29754
- var obj = (value) => isObj5(value) ? value : {};
29755
- async function dealStandaloneReport(bundle) {
29756
- const value = obj(bundle);
29757
- const extensions2 = obj(value["extensions"]);
29758
- if (!(STANDALONE in extensions2) || DEAL_V1 in extensions2) return null;
29759
- if (!ed25519Available()) return null;
29760
- return await standaloneReportHolds(value, extensions2) ? "pass" : "fail";
29761
- }
29762
- async function standaloneReportHolds(value, extensions2) {
29763
- const section = extensions2[DEAL_V0];
29764
- if (!isObj5(section) || Object.keys(section).length !== 1) return false;
29765
- const id = section[POINTER];
29766
- const x = extensions2[STANDALONE];
29767
- if (typeof id !== "string" || !isObj5(x) || Object.keys(x).length !== 2)
29768
- return false;
29769
- const record = x["record"];
29770
- const input = x["agent_input"];
29771
- if (!isObj5(record) || !isObj5(input) || record["capsule_id"] !== id || record["action_id"] !== REPORT_ACTION)
29772
- return false;
29773
- const reportKey = await verifiedProducerKey(record);
29774
- if (reportKey === void 0) return false;
29775
- const last = await lastStepRecord(value);
29776
- if (last === void 0) return false;
29777
- if (await verifiedProducerKey(last) !== reportKey) return false;
29778
- const capsule = {};
29779
- for (const [k, v] of Object.entries(record))
29780
- if (k !== "signature" && k !== "key_id") capsule[k] = v;
29781
- const disclosed = await verifyDisclosureEnvelope({
29782
- capsule,
29783
- disclosures: { agent_input: input }
29784
- });
29785
- if (!disclosed.ok || disclosed.disclosuresMatched !== 1) return false;
29786
- const logId = obj(value["completeness_certificate"])["log_id"];
29787
- if (typeof logId !== "string" || !logId.startsWith("deal/")) return false;
29788
- const audience = input["audience"];
29789
- if (input["type"] !== "deal_report" || input["profile"] !== DEAL_V0 || typeof audience !== "string" || !COPY_AUDIENCES.has(audience) || input["deal_id"] !== logId.slice("deal/".length))
29790
- return false;
29791
- const checkpoint = obj(value["checkpoint"]);
29792
- const bound = input["deal_checkpoint"];
29793
- if (!isObj5(bound) || Object.keys(bound).length !== 3) return false;
29794
- const boundSize = jsonUint(bound["mmr_size"]);
29795
- const size = jsonUint(checkpoint["mmr_size"]);
29796
- if (bound["log_id"] !== logId || boundSize === void 0 || size === void 0 || boundSize !== size || bound["root"] !== checkpoint["root"])
29797
- return false;
29798
- const records = Array.isArray(value["records"]) ? value["records"] : [];
29799
- if (records.some((r) => obj(r)["action_id"] === REPORT_ACTION)) return false;
29800
- const asOf = instant(obj(obj(input["report"])["lifecycle"])["as_of"]);
29801
- const signed = instant(checkpoint["timestamp"]);
29802
- return asOf !== void 0 && signed !== void 0 && asOf === signed;
29803
- }
29804
- async function verifiedProducerKey(record) {
29805
- const id = record["capsule_id"];
29806
- const signature2 = hexBytes2(record["signature"]);
29807
- const key = record["key_id"];
29808
- if (typeof id !== "string" || id === "" || signature2 === void 0)
29809
- return void 0;
29810
- if (typeof key !== "string" || hexBytes2(key) === void 0) return void 0;
29811
- const result3 = await verifyProducerEnvelope(id, signature2);
29812
- if (!result3.ok || result3.publicKey === void 0) return void 0;
29813
- const verified = Array.from(
29814
- result3.publicKey,
29815
- (b) => b.toString(16).padStart(2, "0")
29816
- ).join("");
29817
- return verified === key.toLowerCase() ? key : void 0;
29818
- }
29819
- async function lastStepRecord(value) {
29820
- const memberships2 = obj(
29821
- obj(value["completeness_certificate"])["memberships"]
29822
- );
29823
- const records = Array.isArray(value["records"]) ? value["records"] : [];
29824
- let last;
29825
- let lastSeq = 0n;
29826
- for (const raw of records) {
29827
- const record = obj(raw);
29828
- const type = (await recordHeader(value, record))?.["record_type"];
29829
- if (typeof type !== "string" || !STEP_TYPES.has(type)) continue;
29830
- const id = record["capsule_id"];
29831
- if (typeof id !== "string") continue;
29832
- const seq = jsonUint(obj(obj(memberships2[id])["log_coordinates"])["seq"]);
29833
- if (seq !== void 0 && seq > lastSeq) {
29834
- last = record;
29835
- lastSeq = seq;
29836
- }
29837
- }
29838
- return last;
29839
- }
29840
- async function recordHeader(value, record) {
29841
- const embedded = record["evidence_record_header"];
29842
- if (isObj5(embedded)) return embedded;
29843
- const id = record["capsule_id"];
29844
- if (typeof id !== "string" || id === "") return void 0;
29845
- const disclosed = obj(obj(value["disclosures"])[id])["agent_input"];
29846
- if (!isObj5(disclosed)) return void 0;
29847
- const capsule = {};
29848
- for (const [k, v] of Object.entries(record))
29849
- if (k !== "signature" && k !== "key_id") capsule[k] = v;
29850
- const checked = await verifyDisclosureEnvelope({
29851
- capsule,
29852
- disclosures: { agent_input: disclosed }
29853
- });
29854
- return checked.ok && checked.disclosuresMatched === 1 ? disclosed : void 0;
29855
- }
29856
- function jsonUint(value) {
29857
- return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && !Object.is(value, -0) ? BigInt(value) : void 0;
29858
- }
29859
- function hexBytes2(value) {
29860
- if (typeof value !== "string" || value.length % 2 !== 0 || !/^[0-9a-fA-F]*$/u.test(value))
29861
- return void 0;
29862
- const out = new Uint8Array(value.length / 2);
29863
- for (let i = 0; i < out.length; i++)
29864
- out[i] = parseInt(value.slice(2 * i, 2 * i + 2), 16);
29865
- return out;
29866
- }
29867
- function instant(value) {
29868
- if (typeof value !== "string") return void 0;
29869
- const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:(Z)|([+-])(\d{2}):(\d{2}))$/u.exec(
29870
- value
29871
- );
29872
- if (m === null) return void 0;
29873
- const [, y, mo, d, h, mi, s, frac, z, sign, oh, om] = m;
29874
- const fields2 = [y, mo, d, h, mi, s].map(Number);
29875
- const [year, month, day, hour, minute, second] = fields2;
29876
- if (month < 1 || month > 12 || day < 1 || day > civil(year, month + 1, 0).getUTCDate() || hour > 23 || minute > 59 || second > 59)
29877
- return void 0;
29878
- let offset = 0;
29879
- if (z === void 0) {
29880
- const offHour = Number(oh);
29881
- const offMinute = Number(om);
29882
- if (offHour > 23 || offMinute > 59) return void 0;
29883
- offset = (sign === "-" ? -1 : 1) * (offHour * 60 + offMinute) * 60;
29884
- }
29885
- const at = civil(year, month, day);
29886
- at.setUTCHours(hour, minute, second, 0);
29887
- const seconds = BigInt(at.getTime() / 1e3) - BigInt(offset);
29888
- const nanos = (frac ?? "").slice(0, 9).padEnd(9, "0");
29889
- return `${seconds}.${nanos}`;
29890
- }
29891
- function civil(year, month, day) {
29892
- const at = /* @__PURE__ */ new Date(0);
29893
- at.setUTCFullYear(year, month - 1, day);
29894
- return at;
29895
- }
29896
-
29897
29898
  // src/wording/history-view.en.json
29898
29899
  var history_view_en_default = {
29899
29900
  wording_pack_version: "0",
@@ -29946,8 +29947,8 @@ ${pad.repeat(depth)}`;
29946
29947
  "hero.unreadable": "This page could not read the answer, so it shows none of it.",
29947
29948
  "hero.deals.one": "{n} deal, newest first",
29948
29949
  "hero.deals.other": "{n} deals, newest first",
29949
- "hero.deals.picked.one": "1 deal {name} picked \xB7 steps recorded, not outcomes",
29950
- "hero.deals.picked.other": "{n} deals {name} picked \xB7 steps recorded, not outcomes",
29950
+ "hero.deals.picked.one": "1 deal {name} picked \xB7 this side's record, not confirmed outcomes",
29951
+ "hero.deals.picked.other": "{n} deals {name} picked \xB7 this side's record, not confirmed outcomes",
29951
29952
  "hero.none.deals": "There are no deals in this store yet.",
29952
29953
  "chip.signatures.pass": "Checkpoint signatures check",
29953
29954
  "chip.signatures.pass.all": "Every signature checks",
@@ -29988,8 +29989,9 @@ ${pad.repeat(depth)}`;
29988
29989
  "callout.heading": "What this does not show",
29989
29990
  "callout.checkpoints": "These checkpoints show when this node's log was cut and how much it holds. They don't show what any exchange said or how it went, and this is not a judgment of the node.",
29990
29991
  "callout.checkpoints.time": "The exact time of each exchange. Checkpoint times are rounded to the minute, and each side of an exchange gets its own checkpoint, so two can share a time.",
29991
- "callout.deals": "\u201CSteps recorded\u201D is this side's record of each deal, not a confirmed outcome.",
29992
- "callout.deals.picked": "{name} picked these; it isn't every deal. \u201CSteps recorded\u201D is {name}'s side's record, not a confirmed outcome.",
29992
+ "callout.deals": "Each deal's outcome here is what this side recorded, not a confirmed outcome.",
29993
+ "callout.deals.named": "Each deal's outcome here is what {name} recorded, not a confirmed outcome.",
29994
+ "callout.deals.picked": "{name} picked these; it isn't every deal. Each outcome is what {name}'s side recorded, not a confirmed outcome.",
29993
29995
  "shares.heading": "What this node shares",
29994
29996
  "shares.summary": "With anyone who asks: a summary of its checkpoints, meaning how much it has recorded and when, and nothing about any exchange.",
29995
29997
  "shares.standard.on": "With anyone: the Service History.",
@@ -30582,6 +30584,8 @@ ${pad.repeat(depth)}`;
30582
30584
  r.refuse(`${path2}.id`, "is listed twice");
30583
30585
  if (id && status2) checks.push({ id, status: status2, unregistered });
30584
30586
  });
30587
+ if (kind === "deal" && !checks.some((x) => x.id === "deal_report"))
30588
+ checks.push({ id: "deal_report", status: "not_run" });
30585
30589
  } else r.refuse("input.checks", "is not a list");
30586
30590
  const periods = [];
30587
30591
  if ("periods" in o) {
@@ -30744,6 +30748,7 @@ ${pad.repeat(depth)}`;
30744
30748
  const witnessFailed = statusOf("witness") === "fail";
30745
30749
  const secondFailed = statusOf("second_signature") === "fail";
30746
30750
  const lockChecked = kind === "checkpoint" ? statusOf("checkpoint_signatures") === "pass" && statusOf("checkpoint_chain") === "pass" && statusOf("consistency") === "pass" : dealRecorded;
30751
+ const personTitle = kind !== "checkpoint" && reader !== "owner" && audienceKind !== "shared";
30747
30752
  let title;
30748
30753
  if (kind === "checkpoint")
30749
30754
  title = stream !== void 0 ? say("header.title.stream", { node: short2(node ?? ""), stream }) : say("header.title.node", { node: short2(node ?? "") });
@@ -30931,12 +30936,7 @@ ${pad.repeat(depth)}`;
30931
30936
  el13(
30932
30937
  "ul",
30933
30938
  { class: "cvh-stamps" },
30934
- dealRecorded ? stamp("stamp.recorded", true, "passed", null) : stamp(
30935
- "stamp.recorded",
30936
- false,
30937
- "not_checked",
30938
- say("slot.unchecked")
30939
- ),
30939
+ dealRecorded ? stamp("stamp.recorded", true, "passed", null) : null,
30940
30940
  ...slotStamps(x)
30941
30941
  )
30942
30942
  );
@@ -30995,7 +30995,7 @@ ${pad.repeat(depth)}`;
30995
30995
  el13(
30996
30996
  "p",
30997
30997
  null,
30998
- kind === "checkpoint" ? say("callout.checkpoints") : picked ? say("callout.deals.picked", { name: name ?? "" }) : say("callout.deals")
30998
+ kind === "checkpoint" ? say("callout.checkpoints") : picked ? say("callout.deals.picked", { name: name ?? "" }) : personTitle ? say("callout.deals.named", { name: name ?? "" }) : say("callout.deals")
30999
30999
  ),
31000
31000
  kind === "checkpoint" && rows.length > 0 ? el13("p", null, say("callout.checkpoints.time")) : null
31001
31001
  ) : null;