@forestrie/forestrie-cli 0.8.1 → 0.9.1

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/cli.js CHANGED
@@ -913,6 +913,17 @@ async function readStdinBytes() {
913
913
  }
914
914
  var init_fsio = () => {};
915
915
 
916
+ // node_modules/@forestrie/encoding/dist/canonical-key-order.js
917
+ function compareCanonicalKeys(a, b) {
918
+ if (a.length !== b.length)
919
+ return a.length - b.length;
920
+ for (let i = 0;i < a.length; i++) {
921
+ if (a[i] !== b[i])
922
+ return a[i] - b[i];
923
+ }
924
+ return 0;
925
+ }
926
+
916
927
  // node_modules/@forestrie/encoding/dist/encode-cbor-bstr.js
917
928
  function encodeCborBstr(bytes) {
918
929
  const len = bytes.length;
@@ -1043,9 +1054,9 @@ function encodeMap(entries, depth) {
1043
1054
  valueBytes: encodeValue(v, depth + 1)
1044
1055
  };
1045
1056
  });
1046
- encoded.sort((a, b) => compareBytes(a.keyBytes, b.keyBytes));
1057
+ encoded.sort((a, b) => compareCanonicalKeys(a.keyBytes, b.keyBytes));
1047
1058
  for (let i = 1;i < encoded.length; i++) {
1048
- if (compareBytes(encoded[i - 1].keyBytes, encoded[i].keyBytes) === 0) {
1059
+ if (compareCanonicalKeys(encoded[i - 1].keyBytes, encoded[i].keyBytes) === 0) {
1049
1060
  throw new Error("encodeCborDeterministic: duplicate map key");
1050
1061
  }
1051
1062
  }
@@ -1054,15 +1065,8 @@ function encodeMap(entries, depth) {
1054
1065
  chunks.push(e.keyBytes, e.valueBytes);
1055
1066
  return concat(chunks);
1056
1067
  }
1057
- function compareBytes(a, b) {
1058
- const n = Math.min(a.length, b.length);
1059
- for (let i = 0;i < n; i++) {
1060
- if (a[i] !== b[i])
1061
- return a[i] - b[i];
1062
- }
1063
- return a.length - b.length;
1064
- }
1065
1068
  var MAJOR_UINT = 0, MAJOR_NINT = 1, MAJOR_BSTR = 2, MAJOR_TSTR = 3, MAJOR_ARRAY = 4, MAJOR_MAP = 5, MAX_DEPTH = 64;
1069
+ var init_encode_cbor_deterministic = () => {};
1066
1070
 
1067
1071
  // node_modules/@forestrie/encoding/dist/decode-cbor-deterministic.js
1068
1072
  class CborTag {
@@ -1074,11 +1078,27 @@ class CborTag {
1074
1078
  }
1075
1079
  }
1076
1080
 
1081
+ class CborSimple {
1082
+ value;
1083
+ constructor(value) {
1084
+ this.value = value;
1085
+ }
1086
+ }
1087
+
1088
+ class CborFloat {
1089
+ value;
1090
+ constructor(value) {
1091
+ this.value = value;
1092
+ }
1093
+ }
1094
+
1077
1095
  class Reader {
1078
1096
  buf;
1097
+ rejectTags;
1079
1098
  pos = 0;
1080
- constructor(buf) {
1099
+ constructor(buf, rejectTags) {
1081
1100
  this.buf = buf;
1101
+ this.rejectTags = rejectTags;
1082
1102
  }
1083
1103
  need(n) {
1084
1104
  if (this.pos + n > this.buf.length) {
@@ -1098,18 +1118,26 @@ class Reader {
1098
1118
  argument(ai) {
1099
1119
  if (ai < 24)
1100
1120
  return ai;
1101
- if (ai === 24)
1102
- return this.u8();
1121
+ if (ai === 24) {
1122
+ const v = this.u8();
1123
+ if (v < 24)
1124
+ throw this.notShortest(v);
1125
+ return v;
1126
+ }
1103
1127
  if (ai === 25) {
1104
1128
  this.need(2);
1105
1129
  const v = this.buf[this.pos] << 8 | this.buf[this.pos + 1];
1106
1130
  this.pos += 2;
1131
+ if (v < 256)
1132
+ throw this.notShortest(v);
1107
1133
  return v;
1108
1134
  }
1109
1135
  if (ai === 26) {
1110
1136
  this.need(4);
1111
1137
  const v = this.buf[this.pos] * 16777216 + (this.buf[this.pos + 1] << 16) + (this.buf[this.pos + 2] << 8) + this.buf[this.pos + 3];
1112
1138
  this.pos += 4;
1139
+ if (v < 65536)
1140
+ throw this.notShortest(v);
1113
1141
  return v;
1114
1142
  }
1115
1143
  if (ai === 27) {
@@ -1118,9 +1146,55 @@ class Reader {
1118
1146
  for (let i = 0;i < 8; i++)
1119
1147
  v = v << 8n | BigInt(this.buf[this.pos + i]);
1120
1148
  this.pos += 8;
1149
+ if (v < 0x100000000n)
1150
+ throw this.notShortest(v);
1121
1151
  return v <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(v) : v;
1122
1152
  }
1123
- throw new Error(`decodeCbor: unsupported additional info ${ai}`);
1153
+ throw new Error(`decodeCbor: malformed additional info ${ai}`);
1154
+ }
1155
+ notShortest(v) {
1156
+ return new Error(`decodeCbor: argument ${v} is not in shortest form (RFC 8949 4.2.1)`);
1157
+ }
1158
+ checkDeclaredLength(declared, itemsEach, what) {
1159
+ const remaining = BigInt(this.buf.length - this.pos);
1160
+ if (BigInt(declared) * BigInt(itemsEach) > remaining) {
1161
+ throw new Error(`decodeCbor: ${what} declares ${declared} but only ${remaining} byte(s) remain`);
1162
+ }
1163
+ return Number(declared);
1164
+ }
1165
+ float16() {
1166
+ const b = this.bytes(2);
1167
+ const half = b[0] << 8 | b[1];
1168
+ const exponent = half >> 10 & 31;
1169
+ const fraction = half & 1023;
1170
+ if (exponent === 31 && fraction !== 0 && half !== 32256) {
1171
+ throw notPreferredFloat(`NaN payload f9${half.toString(16).padStart(4, "0")}`, "f97e00");
1172
+ }
1173
+ const sign = half & 32768 ? -1 : 1;
1174
+ if (exponent === 0)
1175
+ return sign * fraction * 2 ** -24;
1176
+ if (exponent === 31)
1177
+ return fraction ? NaN : sign * Infinity;
1178
+ return sign * (fraction + 1024) * 2 ** (exponent - 25);
1179
+ }
1180
+ float32() {
1181
+ const v = new DataView(this.bytes(4).buffer).getFloat32(0);
1182
+ if (Number.isNaN(v))
1183
+ throw notPreferredFloat("NaN as fa", "f97e00");
1184
+ if (isFloat16Exact(v))
1185
+ throw notPreferredFloat(`single ${v}`, "half (f9)");
1186
+ return v;
1187
+ }
1188
+ float64() {
1189
+ const v = new DataView(this.bytes(8).buffer).getFloat64(0);
1190
+ if (Number.isNaN(v))
1191
+ throw notPreferredFloat("NaN as fb", "f97e00");
1192
+ if (isFloat16Exact(v))
1193
+ throw notPreferredFloat(`double ${v}`, "half (f9)");
1194
+ if (Math.fround(v) === v) {
1195
+ throw notPreferredFloat(`double ${v}`, "single (fa)");
1196
+ }
1197
+ return v;
1124
1198
  }
1125
1199
  value(depth) {
1126
1200
  if (depth > 64)
@@ -1128,8 +1202,9 @@ class Reader {
1128
1202
  const ib = this.u8();
1129
1203
  const major = ib >> 5;
1130
1204
  const ai = ib & 31;
1131
- if (ai === 31)
1132
- throw new Error("decodeCbor: indefinite lengths not allowed");
1205
+ if (ai === 31) {
1206
+ throw new Error(major === 7 ? "decodeCbor: break code (0xff) is not a well-formed item" : "decodeCbor: indefinite lengths not allowed");
1207
+ }
1133
1208
  switch (major) {
1134
1209
  case 0:
1135
1210
  return this.argument(ai);
@@ -1149,27 +1224,24 @@ class Reader {
1149
1224
  }).decode(this.bytes(len));
1150
1225
  }
1151
1226
  case 4: {
1152
- const len = Number(this.argument(ai));
1227
+ const len = this.checkDeclaredLength(this.argument(ai), 1, "array");
1153
1228
  const out = new Array(len);
1154
1229
  for (let i = 0;i < len; i++)
1155
1230
  out[i] = this.value(depth + 1);
1156
1231
  return out;
1157
1232
  }
1158
- case 5: {
1159
- const len = Number(this.argument(ai));
1160
- const m = new Map;
1161
- for (let i = 0;i < len; i++) {
1162
- const k = this.value(depth + 1);
1163
- const v = this.value(depth + 1);
1164
- m.set(k, v);
1165
- }
1166
- return m;
1167
- }
1233
+ case 5:
1234
+ return this.map(ai, depth);
1168
1235
  case 6: {
1169
1236
  const tag = Number(this.argument(ai));
1237
+ if (this.rejectTags) {
1238
+ throw new Error(`decodeCbor: tag ${tag} is not allowed here`);
1239
+ }
1170
1240
  return new CborTag(tag, this.value(depth + 1));
1171
1241
  }
1172
1242
  case 7: {
1243
+ if (ai < 20)
1244
+ return new CborSimple(ai);
1173
1245
  switch (ai) {
1174
1246
  case 20:
1175
1247
  return false;
@@ -1178,30 +1250,102 @@ class Reader {
1178
1250
  case 22:
1179
1251
  return null;
1180
1252
  case 23:
1181
- return;
1253
+ throw new Error("decodeCbor: undefined (0xf7) is not allowed; it re-encodes as null");
1254
+ case 24: {
1255
+ const v = this.u8();
1256
+ if (v < 32) {
1257
+ throw new Error(`decodeCbor: two-byte simple value ${v} below 32 is malformed`);
1258
+ }
1259
+ return new CborSimple(v);
1260
+ }
1261
+ case 25:
1262
+ return new CborFloat(this.float16());
1263
+ case 26:
1264
+ return new CborFloat(this.float32());
1265
+ case 27:
1266
+ return new CborFloat(this.float64());
1182
1267
  default:
1183
- throw new Error(`decodeCbor: unsupported simple/float value (ai=${ai})`);
1268
+ throw new Error(`decodeCbor: malformed additional info ${ai} (major type 7)`);
1184
1269
  }
1185
1270
  }
1186
1271
  default:
1187
1272
  throw new Error(`decodeCbor: unsupported major type ${major}`);
1188
1273
  }
1189
1274
  }
1275
+ map(ai, depth) {
1276
+ const pairs = this.checkDeclaredLength(this.argument(ai), 2, "map");
1277
+ const m = new Map;
1278
+ let previousKey = null;
1279
+ for (let i = 0;i < pairs; i++) {
1280
+ const keyStart = this.pos;
1281
+ const key = this.value(depth + 1);
1282
+ const keyBytes = this.buf.subarray(keyStart, this.pos);
1283
+ checkKeyMagnitude(key);
1284
+ if (previousKey !== null) {
1285
+ const order = compareCanonicalKeys(previousKey, keyBytes);
1286
+ if (order === 0) {
1287
+ throw new Error(`decodeCbor: duplicate map key ${describeKey(key)}`);
1288
+ }
1289
+ if (order > 0) {
1290
+ throw new Error(`decodeCbor: map key ${describeKey(key)} is out of canonical order`);
1291
+ }
1292
+ }
1293
+ previousKey = keyBytes;
1294
+ m.set(key, this.value(depth + 1));
1295
+ }
1296
+ return m;
1297
+ }
1298
+ }
1299
+ function checkKeyMagnitude(key) {
1300
+ if (typeof key !== "bigint")
1301
+ return;
1302
+ if (key > INT64_MAX || key < INT64_MIN) {
1303
+ throw new Error(`decodeCbor: integer map key ${key} exceeds int64 magnitude`);
1304
+ }
1305
+ }
1306
+ function notPreferredFloat(got, want) {
1307
+ return new Error(`decodeCbor: float ${got} is not in shortest form; it re-encodes as ${want} (RFC 8949 4.2.2)`);
1308
+ }
1309
+ function isFloat16Exact(v) {
1310
+ if (v === 0)
1311
+ return true;
1312
+ if (!Number.isFinite(v))
1313
+ return true;
1314
+ const a = Math.abs(v);
1315
+ if (a > 65504)
1316
+ return false;
1317
+ if (a < 2 ** -24)
1318
+ return false;
1319
+ const view = new DataView(new ArrayBuffer(8));
1320
+ view.setFloat64(0, a);
1321
+ const exponent = (view.getUint32(0) >>> 20 & 2047) - 1023;
1322
+ const step = exponent >= -14 ? 2 ** (exponent - 10) : 2 ** -24;
1323
+ return a % step === 0;
1190
1324
  }
1191
- function decodeCborDeterministic(bytes) {
1192
- const r = new Reader(bytes);
1325
+ function describeKey(key) {
1326
+ return typeof key === "string" ? JSON.stringify(key) : String(key);
1327
+ }
1328
+ function decodeCborDeterministic(bytes, options) {
1329
+ const r = new Reader(bytes, options?.tags === "reject");
1193
1330
  const v = r.value(0);
1194
1331
  if (r.pos !== bytes.length) {
1195
1332
  throw new Error(`decodeCbor: ${bytes.length - r.pos} trailing byte(s) after item`);
1196
1333
  }
1197
1334
  return v;
1198
1335
  }
1336
+ function decodeCborDeterministicStrict(bytes) {
1337
+ return decodeCborDeterministic(bytes, { tags: "reject" });
1338
+ }
1199
1339
  function decodeCborUnwrapCose(bytes) {
1200
1340
  const v = decodeCborDeterministic(bytes);
1201
1341
  if (v instanceof CborTag && (v.tag === 18 || v.tag === 98))
1202
1342
  return v.value;
1203
1343
  return v;
1204
1344
  }
1345
+ var INT64_MAX = 9223372036854775807n, INT64_MIN;
1346
+ var init_decode_cbor_deterministic = __esm(() => {
1347
+ INT64_MIN = -9223372036854775808n;
1348
+ });
1205
1349
 
1206
1350
  // node_modules/@forestrie/encoding/dist/encode-sig-structure.js
1207
1351
  function encodeCborTstr(s) {
@@ -1241,7 +1385,12 @@ var init_encode_sig_structure = () => {};
1241
1385
  var init_encode_grant_request = () => {};
1242
1386
 
1243
1387
  // node_modules/@forestrie/encoding/dist/problem-details.js
1244
- var init_problem_details = () => {};
1388
+ var init_problem_details = __esm(() => {
1389
+ init_encode_cbor_deterministic();
1390
+ });
1391
+
1392
+ // node_modules/@forestrie/encoding/dist/cose-labels.js
1393
+ var COSE_LABEL_ALG = 1, COSE_LABEL_VDP = 396, VDP_CONSISTENCY_PROOF_KEY = -2, COSE_LABEL_PEAK_RECEIPTS = -65931, COSE_LABEL_TREE_SIZE_2 = -65933;
1245
1394
 
1246
1395
  // node_modules/@forestrie/encoding/dist/uuid-bytes.js
1247
1396
  function uuidToBytes(uuid) {
@@ -1365,6 +1514,37 @@ function appendCborInt(out, v) {
1365
1514
  else
1366
1515
  out.push(58, n >>> 24 & 255, n >> 16 & 255, n >> 8 & 255, n & 255);
1367
1516
  }
1517
+ function appendCborUint64(out, v) {
1518
+ let n;
1519
+ if (typeof v === "bigint") {
1520
+ n = v;
1521
+ } else {
1522
+ if (!Number.isInteger(v)) {
1523
+ throw new Error(`COSE header uint value must be an integer, got ${v}`);
1524
+ }
1525
+ n = BigInt(v);
1526
+ }
1527
+ if (n < 0n) {
1528
+ throw new Error(`COSE header uint value must not be negative: ${n}`);
1529
+ }
1530
+ if (n > MAX_UINT64) {
1531
+ throw new Error(`COSE header uint value exceeds uint64 range: ${n}`);
1532
+ }
1533
+ if (n < 24n) {
1534
+ out.push(Number(n));
1535
+ } else if (n <= 0xffn) {
1536
+ out.push(24, Number(n));
1537
+ } else if (n <= 0xffffn) {
1538
+ out.push(25, Number(n >> 8n & 0xffn), Number(n & 0xffn));
1539
+ } else if (n <= 0xffffffffn) {
1540
+ out.push(26, Number(n >> 24n & 0xffn), Number(n >> 16n & 0xffn), Number(n >> 8n & 0xffn), Number(n & 0xffn));
1541
+ } else {
1542
+ out.push(27);
1543
+ for (let shift = 56n;shift >= 0n; shift -= 8n) {
1544
+ out.push(Number(n >> shift & 0xffn));
1545
+ }
1546
+ }
1547
+ }
1368
1548
  function appendBoundedCborText(out, s) {
1369
1549
  const byteLength = new TextEncoder().encode(s).length;
1370
1550
  if (byteLength > 65535) {
@@ -1405,15 +1585,7 @@ function appendCwtClaimsMap(out, claims) {
1405
1585
  appendCborInt(bytes, k);
1406
1586
  return { k, bytes };
1407
1587
  });
1408
- encodedKeys.sort((a, b) => {
1409
- const n = Math.min(a.bytes.length, b.bytes.length);
1410
- for (let i = 0;i < n; i++) {
1411
- const d = a.bytes[i] - b.bytes[i];
1412
- if (d !== 0)
1413
- return d;
1414
- }
1415
- return a.bytes.length - b.bytes.length;
1416
- });
1588
+ encodedKeys.sort((a, b) => compareCanonicalKeys(new Uint8Array(a.bytes), new Uint8Array(b.bytes)));
1417
1589
  out.push(160 | entries.size);
1418
1590
  for (const { k, bytes } of encodedKeys) {
1419
1591
  out.push(...bytes);
@@ -1424,7 +1596,8 @@ function encodeCoseProtectedMapBytes(kid, options) {
1424
1596
  const hasAlg = options?.alg !== undefined;
1425
1597
  const hasCty = options?.cty !== undefined;
1426
1598
  const hasClaims = options?.cwtClaims !== undefined;
1427
- const size = 1 + (hasAlg ? 1 : 0) + (hasCty ? 1 : 0) + (hasClaims ? 1 : 0);
1599
+ const hasTreeSize2 = options?.treeSize2 !== undefined;
1600
+ const size = 1 + (hasAlg ? 1 : 0) + (hasCty ? 1 : 0) + (hasClaims ? 1 : 0) + (hasTreeSize2 ? 1 : 0);
1428
1601
  const out = [160 | size];
1429
1602
  if (hasAlg) {
1430
1603
  appendCborUint(out, COSE_ALG);
@@ -1444,14 +1617,84 @@ function encodeCoseProtectedMapBytes(kid, options) {
1444
1617
  appendCborUint(out, COSE_CWT_CLAIMS);
1445
1618
  appendCwtClaimsMap(out, options.cwtClaims);
1446
1619
  }
1620
+ if (hasTreeSize2) {
1621
+ appendCborInt(out, COSE_LABEL_TREE_SIZE_2);
1622
+ appendCborUint64(out, options.treeSize2);
1623
+ }
1447
1624
  return new Uint8Array(out);
1448
1625
  }
1449
1626
  function encodeCoseProtectedWithKid(kid, options) {
1450
1627
  return encodeCborBstr(encodeCoseProtectedMapBytes(kid, options));
1451
1628
  }
1452
- var COSE_ALG = 1, COSE_CTY = 3, COSE_KID = 4, COSE_CWT_CLAIMS = 15, CWT_ISS = 1, CWT_SUB = 2, CWT_IAT = 6;
1629
+ var COSE_ALG, COSE_CTY = 3, COSE_KID = 4, COSE_CWT_CLAIMS = 15, CWT_ISS = 1, CWT_SUB = 2, CWT_IAT = 6, MAX_UINT64;
1453
1630
  var init_encode_cose_protected = __esm(() => {
1454
1631
  init_grant_payload_canonical();
1632
+ COSE_ALG = COSE_LABEL_ALG;
1633
+ MAX_UINT64 = (1n << 64n) - 1n;
1634
+ });
1635
+
1636
+ // node_modules/@forestrie/encoding/dist/cose-protected-tree-size.js
1637
+ function isAllowedHeaderValue(value) {
1638
+ if (typeof value === "number" || typeof value === "bigint")
1639
+ return true;
1640
+ if (typeof value === "string")
1641
+ return true;
1642
+ if (typeof value === "boolean" || value === null)
1643
+ return true;
1644
+ if (value instanceof Uint8Array)
1645
+ return true;
1646
+ if (value instanceof CborFloat)
1647
+ return true;
1648
+ return false;
1649
+ }
1650
+ function readProtectedTreeSize2(protectedMapBytes) {
1651
+ const decoded = decodeCborDeterministicStrict(protectedMapBytes);
1652
+ if (!(decoded instanceof Map)) {
1653
+ throw new Error("readProtectedTreeSize2: protected header is not a CBOR map");
1654
+ }
1655
+ for (const [label, value] of decoded) {
1656
+ if (typeof label !== "number" && typeof label !== "bigint") {
1657
+ throw new Error(`readProtectedTreeSize2: protected header label is not an integer (got ${describeValue(label)})`);
1658
+ }
1659
+ if (!isAllowedHeaderValue(value)) {
1660
+ throw new Error(`readProtectedTreeSize2: protected header label ${label} carries an excluded value type (got ${describeValue(value)})`);
1661
+ }
1662
+ }
1663
+ if (!decoded.has(COSE_LABEL_TREE_SIZE_2))
1664
+ return null;
1665
+ const raw = decoded.get(COSE_LABEL_TREE_SIZE_2);
1666
+ if (typeof raw === "bigint") {
1667
+ if (raw < 0n) {
1668
+ throw new Error(`readProtectedTreeSize2: tree-size-2 is not an unsigned integer (bigint ${raw})`);
1669
+ }
1670
+ return raw;
1671
+ }
1672
+ if (typeof raw === "number" && Number.isInteger(raw) && raw >= 0) {
1673
+ return BigInt(raw);
1674
+ }
1675
+ throw new Error(`readProtectedTreeSize2: tree-size-2 is not an unsigned integer (got ${describeValue(raw)})`);
1676
+ }
1677
+ function describeValue(raw) {
1678
+ if (raw === null)
1679
+ return "null";
1680
+ if (raw instanceof CborFloat)
1681
+ return `float ${raw.value}`;
1682
+ if (raw instanceof CborSimple)
1683
+ return `simple value ${raw.value}`;
1684
+ if (raw instanceof CborTag)
1685
+ return `tag ${raw.tag}`;
1686
+ if (typeof raw === "string")
1687
+ return `text string ${JSON.stringify(raw)}`;
1688
+ if (raw instanceof Uint8Array)
1689
+ return "byte string";
1690
+ if (raw instanceof Map)
1691
+ return "map";
1692
+ if (Array.isArray(raw))
1693
+ return "array";
1694
+ return typeof raw;
1695
+ }
1696
+ var init_cose_protected_tree_size = __esm(() => {
1697
+ init_decode_cbor_deterministic();
1455
1698
  });
1456
1699
 
1457
1700
  // node_modules/@forestrie/encoding/dist/encode-cose-sign1-statement.js
@@ -1765,6 +2008,7 @@ function decodeCoseSign1(coseSign1Bytes) {
1765
2008
  var COSE_ALG_ES256 = -7, COSE_ALG_KS256 = -65799, COSE_ALG_ES256_WEBAUTHN = -65800, WEBAUTHN_ENVELOPE_LABEL, AUTH_FLAG_UP = 1, AUTH_FLAG_UV = 4, AUTH_FLAG_BE = 8, AUTH_FLAG_BS = 16, AUTH_DATA_MIN_BYTES = 37, P256_N, P256_HALF_N;
1766
2009
  var init_verify_cose_sign1 = __esm(() => {
1767
2010
  init_base64url();
2011
+ init_decode_cbor_deterministic();
1768
2012
  init_encode_sig_structure();
1769
2013
  WEBAUTHN_ENVELOPE_LABEL = COSE_ALG_ES256_WEBAUTHN;
1770
2014
  P256_N = BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
@@ -1773,6 +2017,7 @@ var init_verify_cose_sign1 = __esm(() => {
1773
2017
 
1774
2018
  // node_modules/@forestrie/encoding/dist/verify-delegate-key-voucher.js
1775
2019
  var init_verify_delegate_key_voucher = __esm(() => {
2020
+ init_decode_cbor_deterministic();
1776
2021
  init_verify_cose_sign1();
1777
2022
  });
1778
2023
 
@@ -1812,7 +2057,9 @@ function encodeCoseSign1Raw(protectedBstr, unprotected, payloadBstr, signature)
1812
2057
  const tuple = [protectedBstr, unprotected, payloadBstr, signature];
1813
2058
  return encodeCborDeterministic(tuple);
1814
2059
  }
1815
- var init_encode_cose_sign1_raw = () => {};
2060
+ var init_encode_cose_sign1_raw = __esm(() => {
2061
+ init_encode_cbor_deterministic();
2062
+ });
1816
2063
 
1817
2064
  // node_modules/@forestrie/encoding/dist/merge-cose-sign1-unprotected.js
1818
2065
  function mergeUnprotectedIntoCoseSign1(coseSign1Bytes, additions) {
@@ -1832,14 +2079,20 @@ var init_merge_cose_sign1_unprotected = __esm(() => {
1832
2079
  });
1833
2080
 
1834
2081
  // node_modules/@forestrie/encoding/dist/grant-codec.js
1835
- var init_grant_codec = () => {};
2082
+ var init_grant_codec = __esm(() => {
2083
+ init_encode_cbor_deterministic();
2084
+ init_decode_cbor_deterministic();
2085
+ });
1836
2086
 
1837
2087
  // node_modules/@forestrie/encoding/dist/index.js
1838
2088
  var init_dist3 = __esm(() => {
2089
+ init_encode_cbor_deterministic();
2090
+ init_decode_cbor_deterministic();
1839
2091
  init_encode_sig_structure();
1840
2092
  init_encode_grant_request();
1841
2093
  init_problem_details();
1842
2094
  init_encode_cose_protected();
2095
+ init_cose_protected_tree_size();
1843
2096
  init_encode_cose_sign1_statement();
1844
2097
  init_sign_cose_sign1_statement();
1845
2098
  init_base64url();
@@ -24383,14 +24636,363 @@ var init_sign_statement3 = __esm(() => {
24383
24636
  run: defineCommandRunner(parseSignStatementOptions, runSignStatement)
24384
24637
  });
24385
24638
  });
24639
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/encode-cbor-deterministic.js
24640
+ function concat5(chunks) {
24641
+ let total = 0;
24642
+ for (const c of chunks)
24643
+ total += c.length;
24644
+ const out = new Uint8Array(total);
24645
+ let off = 0;
24646
+ for (const c of chunks) {
24647
+ out.set(c, off);
24648
+ off += c.length;
24649
+ }
24650
+ return out;
24651
+ }
24652
+ function encodeHead2(major, argument) {
24653
+ const mt = major << 5;
24654
+ const n = typeof argument === "bigint" ? argument : BigInt(argument);
24655
+ if (n < 0n)
24656
+ throw new Error("encodeHead: argument must be non-negative");
24657
+ if (n < 24n)
24658
+ return new Uint8Array([mt | Number(n)]);
24659
+ if (n < 0x100n)
24660
+ return new Uint8Array([mt | 24, Number(n)]);
24661
+ if (n < 0x10000n) {
24662
+ return new Uint8Array([mt | 25, Number(n >> 8n) & 255, Number(n) & 255]);
24663
+ }
24664
+ if (n < 0x100000000n) {
24665
+ return new Uint8Array([
24666
+ mt | 26,
24667
+ Number(n >> 24n & 0xffn),
24668
+ Number(n >> 16n & 0xffn),
24669
+ Number(n >> 8n & 0xffn),
24670
+ Number(n & 0xffn)
24671
+ ]);
24672
+ }
24673
+ if (n < 0x10000000000000000n) {
24674
+ const out = new Uint8Array(9);
24675
+ out[0] = mt | 27;
24676
+ let v = n;
24677
+ for (let i = 8;i >= 1; i--) {
24678
+ out[i] = Number(v & 0xffn);
24679
+ v >>= 8n;
24680
+ }
24681
+ return out;
24682
+ }
24683
+ throw new Error("encodeHead: argument exceeds 64-bit range");
24684
+ }
24685
+ function encodeInteger2(v) {
24686
+ if (typeof v === "number" && !Number.isInteger(v)) {
24687
+ throw new Error(`encodeCborDeterministic: non-integer number ${v}`);
24688
+ }
24689
+ const n = typeof v === "bigint" ? v : BigInt(v);
24690
+ if (n >= 0n)
24691
+ return encodeHead2(MAJOR_UINT2, n);
24692
+ return encodeHead2(MAJOR_NINT2, -1n - n);
24693
+ }
24694
+ function encodeCborDeterministic2(value) {
24695
+ return encodeValue2(value, 0);
24696
+ }
24697
+ function encodeValue2(value, depth) {
24698
+ if (depth > MAX_DEPTH2) {
24699
+ throw new Error(`encodeCborDeterministic: nesting exceeds ${MAX_DEPTH2}`);
24700
+ }
24701
+ if (typeof value === "number" || typeof value === "bigint") {
24702
+ return encodeInteger2(value);
24703
+ }
24704
+ if (typeof value === "boolean") {
24705
+ return new Uint8Array([value ? 245 : 244]);
24706
+ }
24707
+ if (value === null) {
24708
+ return new Uint8Array([246]);
24709
+ }
24710
+ if (value instanceof Uint8Array) {
24711
+ return concat5([encodeHead2(MAJOR_BSTR2, value.length), value]);
24712
+ }
24713
+ if (value instanceof ArrayBuffer) {
24714
+ const bytes = new Uint8Array(value);
24715
+ return concat5([encodeHead2(MAJOR_BSTR2, bytes.length), bytes]);
24716
+ }
24717
+ if (typeof value === "string") {
24718
+ const bytes = new TextEncoder().encode(value);
24719
+ return concat5([encodeHead2(MAJOR_TSTR2, bytes.length), bytes]);
24720
+ }
24721
+ if (Array.isArray(value)) {
24722
+ const items = value.map((v) => encodeValue2(v, depth + 1));
24723
+ return concat5([encodeHead2(MAJOR_ARRAY2, value.length), ...items]);
24724
+ }
24725
+ if (value instanceof Map) {
24726
+ return encodeMap2(value.entries(), depth);
24727
+ }
24728
+ if (typeof value === "object") {
24729
+ const entries = Object.entries(value).filter(([, v]) => v !== undefined);
24730
+ return encodeMap2(entries[Symbol.iterator](), depth);
24731
+ }
24732
+ throw new Error(`encodeCborDeterministic: unsupported value type ${typeof value}`);
24733
+ }
24734
+ function encodeMap2(entries, depth) {
24735
+ const encoded = Array.from(entries).map(([k, v]) => {
24736
+ if (typeof k !== "number" && typeof k !== "bigint" && typeof k !== "string") {
24737
+ throw new Error(`encodeCborDeterministic: unsupported map key type ${typeof k}`);
24738
+ }
24739
+ return {
24740
+ keyBytes: encodeValue2(k, depth + 1),
24741
+ valueBytes: encodeValue2(v, depth + 1)
24742
+ };
24743
+ });
24744
+ encoded.sort((a, b) => compareBytes(a.keyBytes, b.keyBytes));
24745
+ for (let i = 1;i < encoded.length; i++) {
24746
+ if (compareBytes(encoded[i - 1].keyBytes, encoded[i].keyBytes) === 0) {
24747
+ throw new Error("encodeCborDeterministic: duplicate map key");
24748
+ }
24749
+ }
24750
+ const chunks = [encodeHead2(MAJOR_MAP2, encoded.length)];
24751
+ for (const e of encoded)
24752
+ chunks.push(e.keyBytes, e.valueBytes);
24753
+ return concat5(chunks);
24754
+ }
24755
+ function compareBytes(a, b) {
24756
+ const n = Math.min(a.length, b.length);
24757
+ for (let i = 0;i < n; i++) {
24758
+ if (a[i] !== b[i])
24759
+ return a[i] - b[i];
24760
+ }
24761
+ return a.length - b.length;
24762
+ }
24763
+ var MAJOR_UINT2 = 0, MAJOR_NINT2 = 1, MAJOR_BSTR2 = 2, MAJOR_TSTR2 = 3, MAJOR_ARRAY2 = 4, MAJOR_MAP2 = 5, MAX_DEPTH2 = 64;
24764
+
24765
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/decode-cbor-deterministic.js
24766
+ class CborTag2 {
24767
+ tag;
24768
+ value;
24769
+ constructor(tag, value) {
24770
+ this.tag = tag;
24771
+ this.value = value;
24772
+ }
24773
+ }
24774
+
24775
+ class Reader2 {
24776
+ buf;
24777
+ pos = 0;
24778
+ constructor(buf) {
24779
+ this.buf = buf;
24780
+ }
24781
+ need(n) {
24782
+ if (this.pos + n > this.buf.length) {
24783
+ throw new Error("decodeCbor: unexpected end of input");
24784
+ }
24785
+ }
24786
+ u8() {
24787
+ this.need(1);
24788
+ return this.buf[this.pos++];
24789
+ }
24790
+ bytes(n) {
24791
+ this.need(n);
24792
+ const out = this.buf.subarray(this.pos, this.pos + n);
24793
+ this.pos += n;
24794
+ return out.slice();
24795
+ }
24796
+ argument(ai) {
24797
+ if (ai < 24)
24798
+ return ai;
24799
+ if (ai === 24)
24800
+ return this.u8();
24801
+ if (ai === 25) {
24802
+ this.need(2);
24803
+ const v = this.buf[this.pos] << 8 | this.buf[this.pos + 1];
24804
+ this.pos += 2;
24805
+ return v;
24806
+ }
24807
+ if (ai === 26) {
24808
+ this.need(4);
24809
+ const v = this.buf[this.pos] * 16777216 + (this.buf[this.pos + 1] << 16) + (this.buf[this.pos + 2] << 8) + this.buf[this.pos + 3];
24810
+ this.pos += 4;
24811
+ return v;
24812
+ }
24813
+ if (ai === 27) {
24814
+ this.need(8);
24815
+ let v = 0n;
24816
+ for (let i = 0;i < 8; i++)
24817
+ v = v << 8n | BigInt(this.buf[this.pos + i]);
24818
+ this.pos += 8;
24819
+ return v <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(v) : v;
24820
+ }
24821
+ throw new Error(`decodeCbor: unsupported additional info ${ai}`);
24822
+ }
24823
+ value(depth) {
24824
+ if (depth > 64)
24825
+ throw new Error("decodeCbor: nesting too deep");
24826
+ const ib = this.u8();
24827
+ const major = ib >> 5;
24828
+ const ai = ib & 31;
24829
+ if (ai === 31)
24830
+ throw new Error("decodeCbor: indefinite lengths not allowed");
24831
+ switch (major) {
24832
+ case 0:
24833
+ return this.argument(ai);
24834
+ case 1: {
24835
+ const n = this.argument(ai);
24836
+ return typeof n === "bigint" ? -1n - n : -1 - n;
24837
+ }
24838
+ case 2: {
24839
+ const len = Number(this.argument(ai));
24840
+ return this.bytes(len);
24841
+ }
24842
+ case 3: {
24843
+ const len = Number(this.argument(ai));
24844
+ return new TextDecoder("utf-8", {
24845
+ fatal: true,
24846
+ ignoreBOM: false
24847
+ }).decode(this.bytes(len));
24848
+ }
24849
+ case 4: {
24850
+ const len = Number(this.argument(ai));
24851
+ const out = new Array(len);
24852
+ for (let i = 0;i < len; i++)
24853
+ out[i] = this.value(depth + 1);
24854
+ return out;
24855
+ }
24856
+ case 5: {
24857
+ const len = Number(this.argument(ai));
24858
+ const m = new Map;
24859
+ for (let i = 0;i < len; i++) {
24860
+ const k = this.value(depth + 1);
24861
+ const v = this.value(depth + 1);
24862
+ m.set(k, v);
24863
+ }
24864
+ return m;
24865
+ }
24866
+ case 6: {
24867
+ const tag = Number(this.argument(ai));
24868
+ return new CborTag2(tag, this.value(depth + 1));
24869
+ }
24870
+ case 7: {
24871
+ switch (ai) {
24872
+ case 20:
24873
+ return false;
24874
+ case 21:
24875
+ return true;
24876
+ case 22:
24877
+ return null;
24878
+ case 23:
24879
+ return;
24880
+ default:
24881
+ throw new Error(`decodeCbor: unsupported simple/float value (ai=${ai})`);
24882
+ }
24883
+ }
24884
+ default:
24885
+ throw new Error(`decodeCbor: unsupported major type ${major}`);
24886
+ }
24887
+ }
24888
+ }
24889
+ function decodeCborDeterministic2(bytes) {
24890
+ const r = new Reader2(bytes);
24891
+ const v = r.value(0);
24892
+ if (r.pos !== bytes.length) {
24893
+ throw new Error(`decodeCbor: ${bytes.length - r.pos} trailing byte(s) after item`);
24894
+ }
24895
+ return v;
24896
+ }
24897
+
24898
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/encode-sig-structure.js
24899
+ var init_encode_sig_structure2 = () => {};
24900
+
24901
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/encode-grant-request.js
24902
+ var init_encode_grant_request2 = () => {};
24903
+
24904
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/problem-details.js
24905
+ var init_problem_details2 = () => {};
24906
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/grant-payload-canonical.js
24907
+ var init_grant_payload_canonical2 = () => {};
24908
+
24909
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/encode-cose-protected.js
24910
+ var init_encode_cose_protected2 = __esm(() => {
24911
+ init_grant_payload_canonical2();
24912
+ });
24913
+
24914
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/encode-cose-sign1-statement.js
24915
+ var init_encode_cose_sign1_statement2 = __esm(() => {
24916
+ init_encode_cose_protected2();
24917
+ });
24918
+
24919
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/sign-cose-sign1-statement.js
24920
+ var init_sign_cose_sign1_statement2 = __esm(() => {
24921
+ init_encode_cose_protected2();
24922
+ init_encode_cose_sign1_statement2();
24923
+ init_encode_sig_structure2();
24924
+ });
24925
+
24926
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/base64url.js
24927
+ var ALPHABET2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", REVERSE2;
24928
+ var init_base64url2 = __esm(() => {
24929
+ REVERSE2 = (() => {
24930
+ const out = new Int8Array(128).fill(-1);
24931
+ for (let i = 0;i < ALPHABET2.length; i++) {
24932
+ out[ALPHABET2.charCodeAt(i)] = i;
24933
+ }
24934
+ return out;
24935
+ })();
24936
+ });
24937
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/verify-cose-sign1.js
24938
+ var P256_N2, P256_HALF_N2;
24939
+ var init_verify_cose_sign12 = __esm(() => {
24940
+ init_base64url2();
24941
+ init_encode_sig_structure2();
24942
+ P256_N2 = BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
24943
+ P256_HALF_N2 = P256_N2 >> 1n;
24944
+ });
24945
+
24946
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/verify-delegate-key-voucher.js
24947
+ var init_verify_delegate_key_voucher2 = __esm(() => {
24948
+ init_verify_cose_sign12();
24949
+ });
24950
+
24951
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/cose-key-thumbprint.js
24952
+ var init_cose_key_thumbprint2 = __esm(() => {
24953
+ init_base64url2();
24954
+ });
24955
+
24956
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/encode-cose-sign1-raw.js
24957
+ var init_encode_cose_sign1_raw2 = () => {};
24958
+
24959
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/merge-cose-sign1-unprotected.js
24960
+ var init_merge_cose_sign1_unprotected2 = __esm(() => {
24961
+ init_verify_cose_sign12();
24962
+ init_encode_cose_sign1_raw2();
24963
+ });
24964
+
24965
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/grant-codec.js
24966
+ var init_grant_codec2 = () => {};
24967
+
24968
+ // node_modules/@forestrie/scrapi-client/node_modules/@forestrie/encoding/dist/index.js
24969
+ var init_dist5 = __esm(() => {
24970
+ init_encode_sig_structure2();
24971
+ init_encode_grant_request2();
24972
+ init_problem_details2();
24973
+ init_encode_cose_protected2();
24974
+ init_encode_cose_sign1_statement2();
24975
+ init_sign_cose_sign1_statement2();
24976
+ init_base64url2();
24977
+ init_verify_cose_sign12();
24978
+ init_verify_delegate_key_voucher2();
24979
+ init_cose_key_thumbprint2();
24980
+ init_encode_cose_sign1_raw2();
24981
+ init_merge_cose_sign1_unprotected2();
24982
+ init_grant_codec2();
24983
+ init_grant_payload_canonical2();
24984
+ });
24386
24985
 
24387
24986
  // node_modules/@forestrie/scrapi-client/dist/problem-details.js
24388
- function decodeProblemDetailsBytes(body) {
24987
+ function decodeProblemDetailsBytes(body, contentType) {
24389
24988
  if (!body || body.length === 0) {
24390
24989
  return;
24391
24990
  }
24991
+ if (contentType !== undefined && !contentType.toLowerCase().includes(PROBLEM_DETAILS_CONTENT_TYPE)) {
24992
+ return;
24993
+ }
24392
24994
  try {
24393
- const decoded = decodeCborDeterministic(body);
24995
+ const decoded = decodeCborDeterministic2(body);
24394
24996
  if (!(decoded instanceof Map)) {
24395
24997
  return;
24396
24998
  }
@@ -24399,10 +25001,27 @@ function decodeProblemDetailsBytes(body) {
24399
25001
  return;
24400
25002
  }
24401
25003
  }
24402
- var init_problem_details2 = __esm(() => {
24403
- init_dist3();
25004
+ var PROBLEM_DETAILS_CONTENT_TYPE = "application/problem+cbor";
25005
+ var init_problem_details3 = __esm(() => {
25006
+ init_dist5();
24404
25007
  });
24405
25008
 
25009
+ // node_modules/@forestrie/scrapi-client/dist/raw-response.js
25010
+ async function toRawResponse(url, res) {
25011
+ const headers = {};
25012
+ res.headers.forEach((value, key) => {
25013
+ headers[key.toLowerCase()] = value;
25014
+ });
25015
+ const body = new Uint8Array(await res.arrayBuffer());
25016
+ return {
25017
+ url,
25018
+ status: res.status,
25019
+ headers,
25020
+ body,
25021
+ at: new Date().toISOString()
25022
+ };
25023
+ }
25024
+
24406
25025
  // node_modules/@forestrie/scrapi-client/dist/scrapi-url.js
24407
25026
  function toAbsoluteScrapiUrl(baseUrl, location) {
24408
25027
  if (location.startsWith("http"))
@@ -24417,7 +25036,7 @@ function forestrieGrantAuthorization(grantBase64) {
24417
25036
  }
24418
25037
  function interpretRegisterRedirect(view, baseUrl) {
24419
25038
  if (view.status !== 303) {
24420
- const problem = decodeProblemDetailsBytes(view.body);
25039
+ const problem = decodeProblemDetailsBytes(view.body, view.contentType);
24421
25040
  const bodyText = view.body?.length ? new TextDecoder().decode(view.body) : "";
24422
25041
  const detail = problem?.detail ?? (bodyText.slice(0, 200) || "(empty body)");
24423
25042
  throw new ScrapiRegistrationError(`register: expected 303, got ${view.status} (${detail})`, view.status, detail, problem);
@@ -24427,7 +25046,7 @@ function interpretRegisterRedirect(view, baseUrl) {
24427
25046
  }
24428
25047
  return { statusUrl: toAbsoluteScrapiUrl(baseUrl, view.location) };
24429
25048
  }
24430
- async function registerGrant(opts) {
25049
+ async function registerGrantRaw(opts) {
24431
25050
  const doFetch = opts.fetchImpl ?? fetch;
24432
25051
  const headers = {
24433
25052
  Authorization: forestrieGrantAuthorization(opts.grantBase64)
@@ -24435,21 +25054,27 @@ async function registerGrant(opts) {
24435
25054
  let body;
24436
25055
  if (opts.parentGrantBase64) {
24437
25056
  headers["Content-Type"] = "application/cbor";
24438
- body = encodeCborDeterministic({
25057
+ body = encodeCborDeterministic2({
24439
25058
  parentGrant: base64ToBytes2(opts.parentGrantBase64)
24440
25059
  });
24441
25060
  }
24442
- const res = await doFetch(`${opts.baseUrl.replace(/\/$/, "")}/register/${opts.bootstrapLogId}/grants`, {
25061
+ const url = `${opts.baseUrl.replace(/\/$/, "")}/register/${opts.bootstrapLogId}/grants`;
25062
+ const res = await doFetch(url, {
24443
25063
  method: "POST",
24444
25064
  headers,
24445
25065
  body,
24446
25066
  redirect: "manual"
24447
25067
  });
24448
- return interpretRegisterRedirect(await toResponseView(res), opts.baseUrl);
25068
+ return toRawResponse(url, res);
24449
25069
  }
24450
- async function registerSignedStatement(opts) {
25070
+ async function registerGrant(opts) {
25071
+ const raw = await registerGrantRaw(opts);
25072
+ return interpretRegisterRedirect(rawToView(raw), opts.baseUrl);
25073
+ }
25074
+ async function registerSignedStatementRaw(opts) {
24451
25075
  const doFetch = opts.fetchImpl ?? fetch;
24452
- const res = await doFetch(`${opts.baseUrl.replace(/\/$/, "")}/register/${opts.bootstrapLogId}/entries`, {
25076
+ const url = `${opts.baseUrl.replace(/\/$/, "")}/register/${opts.bootstrapLogId}/entries`;
25077
+ const res = await doFetch(url, {
24453
25078
  method: "POST",
24454
25079
  headers: {
24455
25080
  Authorization: forestrieGrantAuthorization(opts.grantBase64),
@@ -24458,13 +25083,18 @@ async function registerSignedStatement(opts) {
24458
25083
  body: opts.statement,
24459
25084
  redirect: "manual"
24460
25085
  });
24461
- return interpretRegisterRedirect(await toResponseView(res), opts.baseUrl);
25086
+ return toRawResponse(url, res);
24462
25087
  }
24463
- async function toResponseView(res) {
25088
+ async function registerSignedStatement(opts) {
25089
+ const raw = await registerSignedStatementRaw(opts);
25090
+ return interpretRegisterRedirect(rawToView(raw), opts.baseUrl);
25091
+ }
25092
+ function rawToView(raw) {
24464
25093
  return {
24465
- status: res.status,
24466
- location: res.headers.get("location") ?? undefined,
24467
- body: new Uint8Array(await res.arrayBuffer())
25094
+ status: raw.status,
25095
+ location: raw.headers["location"],
25096
+ body: raw.body,
25097
+ contentType: raw.headers["content-type"]
24468
25098
  };
24469
25099
  }
24470
25100
  function base64ToBytes2(b64) {
@@ -24477,8 +25107,8 @@ function base64ToBytes2(b64) {
24477
25107
  }
24478
25108
  var COSE_SIGN1_CONTENT_TYPE = 'application/cose; cose-type="cose-sign1"', ScrapiRegistrationError;
24479
25109
  var init_register = __esm(() => {
24480
- init_dist3();
24481
- init_problem_details2();
25110
+ init_dist5();
25111
+ init_problem_details3();
24482
25112
  ScrapiRegistrationError = class ScrapiRegistrationError extends Error {
24483
25113
  httpStatus;
24484
25114
  problem;
@@ -24501,23 +25131,26 @@ function parseEntryIdFromReceiptLocation(location) {
24501
25131
  }
24502
25132
  return m[1].toLowerCase();
24503
25133
  }
24504
- async function queryRegistrationOnce(opts) {
25134
+ async function queryRegistrationRaw(opts) {
24505
25135
  const doFetch = opts.fetchImpl ?? fetch;
24506
25136
  const res = await doFetch(opts.statusUrl, {
24507
25137
  headers: { Accept: opts.accept ?? "application/cbor" },
24508
25138
  redirect: "manual"
24509
25139
  });
24510
- if (res.status !== 303) {
24511
- const body = new Uint8Array(await res.arrayBuffer());
24512
- const problem = decodeProblemDetailsBytes(body);
25140
+ return toRawResponse(opts.statusUrl, res);
25141
+ }
25142
+ async function queryRegistrationOnce(opts) {
25143
+ const raw = await queryRegistrationRaw(opts);
25144
+ if (raw.status !== 303) {
25145
+ const problem = decodeProblemDetailsBytes(raw.body, raw.headers["content-type"]);
24513
25146
  return {
24514
25147
  status: "error",
24515
- httpStatus: res.status,
25148
+ httpStatus: raw.status,
24516
25149
  problem,
24517
- detail: problem?.detail ?? `expected 303, got ${res.status}`
25150
+ detail: problem?.detail ?? `expected 303, got ${raw.status}`
24518
25151
  };
24519
25152
  }
24520
- const location = res.headers.get("location");
25153
+ const location = raw.headers["location"];
24521
25154
  if (!location) {
24522
25155
  return {
24523
25156
  status: "error",
@@ -24532,7 +25165,7 @@ async function queryRegistrationOnce(opts) {
24532
25165
  entryIdHex: parseEntryIdFromReceiptLocation(location)
24533
25166
  };
24534
25167
  }
24535
- const retryAfterSec = Number.parseInt(res.headers.get("retry-after") ?? "0", 10);
25168
+ const retryAfterSec = Number.parseInt(raw.headers["retry-after"] ?? "0", 10);
24536
25169
  return {
24537
25170
  status: "pending",
24538
25171
  location,
@@ -24541,39 +25174,46 @@ async function queryRegistrationOnce(opts) {
24541
25174
  }
24542
25175
  var RECEIPT_LOCATION_RE;
24543
25176
  var init_query_registration = __esm(() => {
24544
- init_problem_details2();
25177
+ init_problem_details3();
24545
25178
  RECEIPT_LOCATION_RE = /\/logs\/[^/]+\/[^/]+\/\d+\/entries\/[0-9a-f]{32}\/receipt(?:\?|$)/i;
24546
25179
  });
24547
25180
 
24548
25181
  // node_modules/@forestrie/scrapi-client/dist/resolve-receipt.js
24549
- async function resolveReceiptOnce(opts) {
25182
+ async function resolveReceiptRaw(opts) {
24550
25183
  const doFetch = opts.fetchImpl ?? fetch;
24551
25184
  const res = await doFetch(opts.receiptUrl, {
24552
- headers: { Accept: opts.accept ?? "application/cbor" }
25185
+ headers: { Accept: opts.accept ?? SCITT_RECEIPT_COSE_CONTENT_TYPE },
25186
+ redirect: "manual"
24553
25187
  });
24554
- if (res.status === 200) {
24555
- const headers = {};
24556
- res.headers.forEach((v, k) => {
24557
- headers[k] = v;
24558
- });
25188
+ return toRawResponse(opts.receiptUrl, res);
25189
+ }
25190
+ async function resolveReceiptOnce(opts) {
25191
+ const raw = await resolveReceiptRaw(opts);
25192
+ if (raw.status === 200) {
24559
25193
  return {
24560
25194
  status: "receipt",
24561
- httpStatus: res.status,
24562
- headers,
24563
- body: new Uint8Array(await res.arrayBuffer())
25195
+ httpStatus: raw.status,
25196
+ headers: raw.headers,
25197
+ body: raw.body
24564
25198
  };
24565
25199
  }
24566
- if (res.status === 404) {
24567
- return { status: "pending" };
25200
+ const problem = decodeProblemDetailsBytes(raw.body, raw.headers["content-type"]);
25201
+ if (raw.status === 404) {
25202
+ return { status: "not_found", problem };
24568
25203
  }
24569
- return { status: "error", httpStatus: res.status };
25204
+ return { status: "error", httpStatus: raw.status, problem };
24570
25205
  }
25206
+ var SCITT_RECEIPT_COSE_CONTENT_TYPE = "application/scitt.receipt+cose";
25207
+ var init_resolve_receipt = __esm(() => {
25208
+ init_problem_details3();
25209
+ });
24571
25210
 
24572
25211
  // node_modules/@forestrie/scrapi-client/dist/index.js
24573
- var init_dist5 = __esm(() => {
25212
+ var init_dist6 = __esm(() => {
24574
25213
  init_register();
24575
25214
  init_query_registration();
24576
- init_problem_details2();
25215
+ init_resolve_receipt();
25216
+ init_problem_details3();
24577
25217
  });
24578
25218
 
24579
25219
  // src/lib/register-flow.ts
@@ -24698,7 +25338,7 @@ async function runRegisterFlow(params, deps = {}) {
24698
25338
  }
24699
25339
  var RegisterFlowError, defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
24700
25340
  var init_register_flow = __esm(() => {
24701
- init_dist5();
25341
+ init_dist6();
24702
25342
  RegisterFlowError = class RegisterFlowError extends Error {
24703
25343
  stage;
24704
25344
  httpStatus;
@@ -25020,10 +25660,10 @@ function signGrantPayloadWithEs256Pem(grantPayloadBytes, es256PrivateKeyPem) {
25020
25660
  const out = [132];
25021
25661
  appendCborBstr(out, ES256_PROTECTED_HEADER);
25022
25662
  out.push(162);
25023
- out.push(...CBOR_KEY_FORESTRIE_GRANT_V0);
25024
- appendCborBstr(out, grantPayloadBytes);
25025
25663
  out.push(...CBOR_KEY_IDTIMESTAMP);
25026
25664
  appendCborBstr(out, new Uint8Array(IDTIMESTAMP_BYTES));
25665
+ out.push(...CBOR_KEY_FORESTRIE_GRANT_V0);
25666
+ appendCborBstr(out, grantPayloadBytes);
25027
25667
  appendCborBstr(out, payload);
25028
25668
  appendCborBstr(out, signature);
25029
25669
  return new Uint8Array(out);
@@ -25060,7 +25700,7 @@ var init_ks256_wallet_grant = __esm(() => {
25060
25700
  });
25061
25701
 
25062
25702
  // node_modules/@forestrie/grant-builder/dist/index.js
25063
- var init_dist6 = __esm(() => {
25703
+ var init_dist7 = __esm(() => {
25064
25704
  init_dist3();
25065
25705
  init_dist3();
25066
25706
  init_dist3();
@@ -25143,7 +25783,7 @@ function buildGrantStatement(params) {
25143
25783
  var RegisterGrantBuildError, ES256_XY_BYTES = 64;
25144
25784
  var init_register_grant_build = __esm(() => {
25145
25785
  init_openssl_error_queue();
25146
- init_dist6();
25786
+ init_dist7();
25147
25787
  init_dist3();
25148
25788
  RegisterGrantBuildError = class RegisterGrantBuildError extends Error {
25149
25789
  constructor(message) {
@@ -25208,7 +25848,7 @@ function buildCreateLogGrant(params) {
25208
25848
  };
25209
25849
  }
25210
25850
  var init_create_log_build = __esm(() => {
25211
- init_dist6();
25851
+ init_dist7();
25212
25852
  init_dist3();
25213
25853
  init_register_grant_build();
25214
25854
  });
@@ -25229,7 +25869,7 @@ function completeGrantBase64(grantBase64, receiptBytes, entryIdHex) {
25229
25869
  }
25230
25870
  var ENTRY_ID_HEX_RE;
25231
25871
  var init_register_grant_complete = __esm(() => {
25232
- init_dist6();
25872
+ init_dist7();
25233
25873
  init_dist3();
25234
25874
  ENTRY_ID_HEX_RE = /^[0-9a-f]{32}$/i;
25235
25875
  });
@@ -25396,7 +26036,7 @@ async function runRegisterGrantFlow(params, deps = {}) {
25396
26036
  }
25397
26037
  var defaultSleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
25398
26038
  var init_register_grant_flow = __esm(() => {
25399
- init_dist5();
26039
+ init_dist6();
25400
26040
  init_register_flow();
25401
26041
  });
25402
26042
 
@@ -26018,7 +26658,7 @@ var init_register_grant3 = __esm(() => {
26018
26658
  var DELEGATION_CONTENT_TYPE = "application/forestrie.delegation+cbor";
26019
26659
 
26020
26660
  // node_modules/@forestrie/delegation-cose/dist/payload-labels.js
26021
- var COSE_HEADER_ALG = 1, COSE_HEADER_CTY = 3, COSE_HEADER_KID = 4, PAYLOAD_LOG_ID = 1, PAYLOAD_MMR_START = 3, PAYLOAD_MMR_END = 4, PAYLOAD_DELEGATED_KEY = 5, PAYLOAD_CONSTRAINTS = 6, PAYLOAD_SCHEMA_VER = 7, PAYLOAD_ISSUED_AT = 8, PAYLOAD_EXPIRES_AT = 9, PAYLOAD_DELEGATION_ID = 10, COSE_KTY = 1, COSE_CRV = -1, COSE_X = -2, COSE_Y = -3, COSE_KTY_EC2 = 2, COSE_CRV_P256 = 1, COSE_ALG_ES2562 = -7, KS256_EOA_SIG_BYTES = 65, ES256_SIG_BYTES = 64;
26661
+ var COSE_HEADER_ALG = 1, COSE_HEADER_CTY = 3, COSE_HEADER_KID = 4, PAYLOAD_LOG_ID = 1, PAYLOAD_MMR_START = 3, PAYLOAD_MMR_END = 4, PAYLOAD_DELEGATED_KEY = 5, PAYLOAD_CONSTRAINTS = 6, PAYLOAD_SCHEMA_VER = 7, PAYLOAD_ISSUED_AT = 8, PAYLOAD_EXPIRES_AT = 9, PAYLOAD_DELEGATION_ID = 10, COSE_KTY = 1, COSE_CRV = -1, COSE_X = -2, COSE_Y = -3, COSE_KTY_EC2 = 2, COSE_CRV_P256 = 1, COSE_ALG_ES2563 = -7, KS256_EOA_SIG_BYTES = 65, ES256_SIG_BYTES = 64;
26022
26662
 
26023
26663
  // node_modules/@forestrie/delegation-cose/dist/bytes-utils.js
26024
26664
  function bytesFromUnknown(value, label) {
@@ -26042,7 +26682,7 @@ var init_encode_int_map = __esm(() => {
26042
26682
  });
26043
26683
 
26044
26684
  // node_modules/@forestrie/delegation-cose/dist/encode-cbor-bstr.js
26045
- function encodeCborBstr2(bytes) {
26685
+ function encodeCborBstr3(bytes) {
26046
26686
  const len = bytes.length;
26047
26687
  let header;
26048
26688
  if (len < 24) {
@@ -26083,7 +26723,7 @@ function encodeCborTstr2(s) {
26083
26723
  out.set(bytes, header.length);
26084
26724
  return out;
26085
26725
  }
26086
- function concat5(...arrays) {
26726
+ function concat6(...arrays) {
26087
26727
  const total = arrays.reduce((sum, a) => sum + a.length, 0);
26088
26728
  const out = new Uint8Array(total);
26089
26729
  let off = 0;
@@ -26093,12 +26733,12 @@ function concat5(...arrays) {
26093
26733
  }
26094
26734
  return out;
26095
26735
  }
26096
- function encodeSigStructure2(protectedHeaderMapBytes, externalAad, payloadBstr) {
26736
+ function encodeSigStructure3(protectedHeaderMapBytes, externalAad, payloadBstr) {
26097
26737
  const arrayHeader = new Uint8Array([132]);
26098
26738
  const label = encodeCborTstr2("Signature1");
26099
- return concat5(arrayHeader, label, encodeCborBstr2(protectedHeaderMapBytes), encodeCborBstr2(externalAad), encodeCborBstr2(payloadBstr));
26739
+ return concat6(arrayHeader, label, encodeCborBstr3(protectedHeaderMapBytes), encodeCborBstr3(externalAad), encodeCborBstr3(payloadBstr));
26100
26740
  }
26101
- var init_encode_sig_structure2 = () => {};
26741
+ var init_encode_sig_structure3 = () => {};
26102
26742
 
26103
26743
  // node_modules/@forestrie/delegation-cose/dist/webauthn-assertion.js
26104
26744
  var TYPE_MARKER, CHALLENGE_MARKER;
@@ -26156,11 +26796,11 @@ function buildOnchainDelegationToBeSignedWithAlg(input, alg) {
26156
26796
  return {
26157
26797
  protectedHeader,
26158
26798
  delegationKey,
26159
- sigStructureBytes: encodeSigStructure2(protectedHeader, new Uint8Array, payload)
26799
+ sigStructureBytes: encodeSigStructure3(protectedHeader, new Uint8Array, payload)
26160
26800
  };
26161
26801
  }
26162
26802
  function buildOnchainDelegationToBeSignedEs256(input) {
26163
- return buildOnchainDelegationToBeSignedWithAlg(input, COSE_ALG_ES2562);
26803
+ return buildOnchainDelegationToBeSignedWithAlg(input, COSE_ALG_ES2563);
26164
26804
  }
26165
26805
  function normalizeEs256SignatureLowS(signature) {
26166
26806
  if (signature.length !== ES256_SIG_BYTES) {
@@ -26170,10 +26810,10 @@ function normalizeEs256SignatureLowS(signature) {
26170
26810
  for (let i = 32;i < 64; i++) {
26171
26811
  s = s << 8n | BigInt(signature[i]);
26172
26812
  }
26173
- if (s <= P256_HALF_N2) {
26813
+ if (s <= P256_HALF_N3) {
26174
26814
  return signature;
26175
26815
  }
26176
- s = P256_N2 - s;
26816
+ s = P256_N3 - s;
26177
26817
  const out = new Uint8Array(64);
26178
26818
  out.set(signature.slice(0, 32), 0);
26179
26819
  for (let i = 0;i < 32; i++) {
@@ -26196,14 +26836,14 @@ async function signOnchainDelegationEs256(input, rootKeyPair) {
26196
26836
  algData: []
26197
26837
  };
26198
26838
  }
26199
- var ONCHAIN_DELEGATION_DOMAIN = "forestrie.univocity.delegation.v1", P256_N2, P256_HALF_N2;
26839
+ var ONCHAIN_DELEGATION_DOMAIN = "forestrie.univocity.delegation.v1", P256_N3, P256_HALF_N3;
26200
26840
  var init_build_onchain_delegation = __esm(() => {
26201
26841
  init_dist3();
26202
26842
  init_encode_int_map();
26203
- init_encode_sig_structure2();
26843
+ init_encode_sig_structure3();
26204
26844
  init_webauthn_assertion();
26205
- P256_N2 = BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
26206
- P256_HALF_N2 = P256_N2 >> 1n;
26845
+ P256_N3 = BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
26846
+ P256_HALF_N3 = P256_N3 >> 1n;
26207
26847
  });
26208
26848
 
26209
26849
  // node_modules/@forestrie/delegation-cose/dist/assemble-certificate.js
@@ -26318,11 +26958,11 @@ function buildDelegationPayloadBytes(input) {
26318
26958
  ]));
26319
26959
  }
26320
26960
  function buildDelegationToBeSigned(protectedBytes, payloadBytes) {
26321
- const sigStructureBytes = encodeSigStructure2(protectedBytes, new Uint8Array, payloadBytes);
26961
+ const sigStructureBytes = encodeSigStructure3(protectedBytes, new Uint8Array, payloadBytes);
26322
26962
  return { protectedBytes, payloadBytes, sigStructureBytes };
26323
26963
  }
26324
26964
  var init_build_delegation_payload = __esm(() => {
26325
- init_encode_sig_structure2();
26965
+ init_encode_sig_structure3();
26326
26966
  init_parse_delegated_cose_key();
26327
26967
  init_encode_int_map();
26328
26968
  });
@@ -26350,7 +26990,7 @@ function buildDelegationToBeSignedEs256(input, rootKid) {
26350
26990
  throw new Error("ES256 root kid must be 16 bytes");
26351
26991
  }
26352
26992
  const protectedBytes = encodeIntKeyCbor(new Map([
26353
- [COSE_HEADER_ALG, COSE_ALG_ES2562],
26993
+ [COSE_HEADER_ALG, COSE_ALG_ES2563],
26354
26994
  [COSE_HEADER_CTY, DELEGATION_CONTENT_TYPE],
26355
26995
  [COSE_HEADER_KID, rootKid]
26356
26996
  ]));
@@ -26414,18 +27054,18 @@ var init_parse_certificate = __esm(() => {
26414
27054
 
26415
27055
  // node_modules/@forestrie/delegation-cose/dist/verify-es256.js
26416
27056
  var init_verify_es256 = __esm(() => {
26417
- init_encode_sig_structure2();
27057
+ init_encode_sig_structure3();
26418
27058
  init_parse_delegated_cose_key();
26419
27059
  });
26420
27060
 
26421
27061
  // node_modules/@forestrie/delegation-cose/dist/verify-ks256.js
26422
27062
  var init_verify_ks256 = __esm(() => {
26423
- init_encode_sig_structure2();
27063
+ init_encode_sig_structure3();
26424
27064
  init_parse_delegated_cose_key();
26425
27065
  });
26426
27066
 
26427
27067
  // node_modules/@forestrie/delegation-cose/dist/index.js
26428
- var init_dist7 = __esm(() => {
27068
+ var init_dist8 = __esm(() => {
26429
27069
  init_build_onchain_delegation();
26430
27070
  init_webauthn_assertion();
26431
27071
  init_assemble_certificate();
@@ -26443,7 +27083,7 @@ var init_dist7 = __esm(() => {
26443
27083
  });
26444
27084
 
26445
27085
  // src/lib/delegate-voucher.ts
26446
- function parseRegistrarKeyXY2(raw) {
27086
+ function parseRegistrarKeyXY3(raw) {
26447
27087
  if (raw.length !== REGISTRAR_KEY_XY_BYTES)
26448
27088
  return null;
26449
27089
  return {
@@ -26470,7 +27110,7 @@ function toBigIntOrNull(value) {
26470
27110
  return BigInt(value);
26471
27111
  return null;
26472
27112
  }
26473
- async function verifyDelegateKeyVoucher2(voucherBytes, pinnedKey, expect) {
27113
+ async function verifyDelegateKeyVoucher3(voucherBytes, pinnedKey, expect) {
26474
27114
  const sigOk = await verifyCoseSign1WithParsedKey(voucherBytes, pinnedKey);
26475
27115
  if (!sigOk)
26476
27116
  return { ok: false, reason: "signature" };
@@ -26548,11 +27188,11 @@ async function runDelegateFlow(params, deps = {}) {
26548
27188
  if (standing.voucher === undefined || standing.sealerId === undefined || standing.epoch === undefined) {
26549
27189
  throw new DelegateFlowError("standing entry is missing its registrar voucher — refusing to bind");
26550
27190
  }
26551
- const pinned = parseRegistrarKeyXY2(b64ToBytes(params.knownSealerKey));
27191
+ const pinned = parseRegistrarKeyXY3(b64ToBytes(params.knownSealerKey));
26552
27192
  if (pinned === null) {
26553
27193
  throw new DelegateFlowError("known-sealer-key must be base64 x||y (64 bytes)");
26554
27194
  }
26555
- const voucherResult = await verifyDelegateKeyVoucher2(b64ToBytes(standing.voucher), pinned, {
27195
+ const voucherResult = await verifyDelegateKeyVoucher3(b64ToBytes(standing.voucher), pinned, {
26556
27196
  sealerId: standing.sealerId,
26557
27197
  epoch: standing.epoch,
26558
27198
  publicKey: b64ToBytes(standing.delegatedPublicKey)
@@ -26614,7 +27254,7 @@ async function runDelegateFlow(params, deps = {}) {
26614
27254
  }
26615
27255
  var MMR_START = 0, DelegateFlowError;
26616
27256
  var init_delegate_flow = __esm(() => {
26617
- init_dist7();
27257
+ init_dist8();
26618
27258
  init_dist3();
26619
27259
  init_delegate_voucher();
26620
27260
  DelegateFlowError = class DelegateFlowError extends Error {
@@ -26848,7 +27488,7 @@ function buildEs256GenesisBody(opts) {
26848
27488
  [LABEL_GENESIS_VERSION, SCHEMA_V2],
26849
27489
  [LABEL_UNIVOCITY_ADDR, hexToBytes20(opts.univocityAddress)],
26850
27490
  [LABEL_CHAIN_ID, opts.chainId],
26851
- [LABEL_GENESIS_ALG, COSE_ALG_ES2563],
27491
+ [LABEL_GENESIS_ALG, COSE_ALG_ES2564],
26852
27492
  [LABEL_BOOTSTRAP_KEY, opts.bootstrapKeyXy]
26853
27493
  ]));
26854
27494
  }
@@ -26859,7 +27499,7 @@ function genesisPostUrl(baseUrl, logId, webhookUrl) {
26859
27499
  function coordinatorSigningRouteUrl(coordinatorUrl, logId) {
26860
27500
  return `${coordinatorUrl.replace(/\/$/, "")}/api/logs/${logId}/signing-route`;
26861
27501
  }
26862
- var LABEL_GENESIS_VERSION = -68009, LABEL_UNIVOCITY_ADDR = -68011, LABEL_CHAIN_ID = -68013, LABEL_GENESIS_ALG = -68014, LABEL_BOOTSTRAP_KEY = -68015, SCHEMA_V2 = 2, COSE_ALG_ES2563 = -7;
27502
+ var LABEL_GENESIS_VERSION = -68009, LABEL_UNIVOCITY_ADDR = -68011, LABEL_CHAIN_ID = -68013, LABEL_GENESIS_ALG = -68014, LABEL_BOOTSTRAP_KEY = -68015, SCHEMA_V2 = 2, COSE_ALG_ES2564 = -7;
26863
27503
  var init_onboard_genesis_body = __esm(() => {
26864
27504
  init_dist3();
26865
27505
  });
@@ -27111,14 +27751,14 @@ function assemble(prot, payload, signature) {
27111
27751
  return encodeCborDeterministic([prot, new Map, payload, signature]);
27112
27752
  }
27113
27753
  async function buildOnboardAttestationEs256(key, input) {
27114
- const prot = protectedBytes(COSE_ALG_ES2564);
27754
+ const prot = protectedBytes(COSE_ALG_ES2565);
27115
27755
  const payload = claimsBytes(input);
27116
27756
  const sigStructure = encodeSigStructure(prot, new Uint8Array(0), payload);
27117
27757
  const signature = new Uint8Array(await crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, key.privateKey, sigStructure));
27118
27758
  return assemble(prot, payload, signature);
27119
27759
  }
27120
27760
  async function buildOnboardAttestationKs256(privateKeyHex, input) {
27121
- const prot = protectedBytes(COSE_ALG_KS2563);
27761
+ const prot = protectedBytes(COSE_ALG_KS2564);
27122
27762
  const payload = claimsBytes(input);
27123
27763
  const sigStructure = encodeSigStructure(prot, new Uint8Array(0), payload);
27124
27764
  const hash3 = keccak256(sigStructure);
@@ -27129,7 +27769,7 @@ async function buildOnboardAttestationKs256(privateKeyHex, input) {
27129
27769
  }
27130
27770
  return assemble(prot, payload, sig);
27131
27771
  }
27132
- var ONBOARD_ATTESTATION_CONTENT_TYPE = "application/forestrie-onboard-attestation+cwt", COSE_ALG_ES2564 = -7, COSE_ALG_KS2563 = -65799, CLAIM_CHAIN_BINDING = -70000, DEFAULT_ATTESTATION_WINDOW_SEC = 3600;
27772
+ var ONBOARD_ATTESTATION_CONTENT_TYPE = "application/forestrie-onboard-attestation+cwt", COSE_ALG_ES2565 = -7, COSE_ALG_KS2564 = -65799, CLAIM_CHAIN_BINDING = -70000, DEFAULT_ATTESTATION_WINDOW_SEC = 3600;
27133
27773
  var init_onboard_attestation = __esm(() => {
27134
27774
  init_accounts();
27135
27775
  init__esm();
@@ -27578,7 +28218,7 @@ function parseReceipt(receiptBytes) {
27578
28218
  throw new Error("Receipt payload must be nil (detached) or 32-byte peak hash");
27579
28219
  }
27580
28220
  const unprotected = toHeaderMap(coseSign1[1]);
27581
- const proofsRaw = unprotected.get(VDS_COSE_RECEIPT_PROOFS_TAG);
28221
+ const proofsRaw = unprotected.get(COSE_LABEL_VDP);
27582
28222
  if (!proofsRaw || typeof proofsRaw !== "object") {
27583
28223
  throw new Error("Receipt missing header 396 (inclusion proof)");
27584
28224
  }
@@ -27607,7 +28247,6 @@ function parseReceipt(receiptBytes) {
27607
28247
  coseSign1
27608
28248
  };
27609
28249
  }
27610
- var VDS_COSE_RECEIPT_PROOFS_TAG = 396;
27611
28250
  var init_parse_receipt = __esm(() => {
27612
28251
  init_dist3();
27613
28252
  });
@@ -28066,6 +28705,9 @@ function peaksBitmap(mmrSize) {
28066
28705
  }
28067
28706
  return peakMap;
28068
28707
  }
28708
+ function mmrSizeForLeafCount(leaves) {
28709
+ return 2n * leaves - BigInt(popcount(leaves));
28710
+ }
28069
28711
  function popcount(x) {
28070
28712
  let count = 0;
28071
28713
  let v = x;
@@ -28306,6 +28948,65 @@ function bitLength2(value) {
28306
28948
  }
28307
28949
  var init_math = () => {};
28308
28950
 
28951
+ // node_modules/@forestrie/merklelog/dist/mmr/errors.js
28952
+ var ConsistencyShapeError, IncompleteTreeSize, ConsistencyPeakCountMismatch, ConsistencyPathLengthMismatch, ConsistencyRootMismatch, SizeMustIncrease;
28953
+ var init_errors4 = __esm(() => {
28954
+ ConsistencyShapeError = class ConsistencyShapeError extends Error {
28955
+ constructor(message) {
28956
+ super(message);
28957
+ this.name = "ConsistencyShapeError";
28958
+ }
28959
+ };
28960
+ IncompleteTreeSize = class IncompleteTreeSize extends ConsistencyShapeError {
28961
+ size;
28962
+ constructor(size5) {
28963
+ super(`size ${size5} is not a complete MMR size`);
28964
+ this.size = size5;
28965
+ this.name = "IncompleteTreeSize";
28966
+ }
28967
+ };
28968
+ ConsistencyPeakCountMismatch = class ConsistencyPeakCountMismatch extends ConsistencyShapeError {
28969
+ expected;
28970
+ actual;
28971
+ constructor(expected, actual) {
28972
+ super(`expected ${expected} entries for the origin peaks, got ${actual}`);
28973
+ this.expected = expected;
28974
+ this.actual = actual;
28975
+ this.name = "ConsistencyPeakCountMismatch";
28976
+ }
28977
+ };
28978
+ ConsistencyPathLengthMismatch = class ConsistencyPathLengthMismatch extends ConsistencyShapeError {
28979
+ index;
28980
+ expected;
28981
+ actual;
28982
+ constructor(index2, expected, actual) {
28983
+ super(`path ${index2}: expected length ${expected}, got ${actual}`);
28984
+ this.index = index2;
28985
+ this.expected = expected;
28986
+ this.actual = actual;
28987
+ this.name = "ConsistencyPathLengthMismatch";
28988
+ }
28989
+ };
28990
+ ConsistencyRootMismatch = class ConsistencyRootMismatch extends ConsistencyShapeError {
28991
+ index;
28992
+ constructor(index2) {
28993
+ super(`path ${index2} proves a different root from the paths before it`);
28994
+ this.index = index2;
28995
+ this.name = "ConsistencyRootMismatch";
28996
+ }
28997
+ };
28998
+ SizeMustIncrease = class SizeMustIncrease extends ConsistencyShapeError {
28999
+ sizeFrom;
29000
+ sizeTo;
29001
+ constructor(sizeFrom, sizeTo) {
29002
+ super(`sizeTo (${sizeTo}) must exceed sizeFrom (${sizeFrom})`);
29003
+ this.sizeFrom = sizeFrom;
29004
+ this.sizeTo = sizeTo;
29005
+ this.name = "SizeMustIncrease";
29006
+ }
29007
+ };
29008
+ });
29009
+
28309
29010
  // node_modules/@forestrie/merklelog/dist/utils/arrays.js
28310
29011
  function arraysEqual(a, b) {
28311
29012
  if (a.length !== b.length) {
@@ -28362,33 +29063,72 @@ async function verifyInclusion(hasher, leafHash, proof, root) {
28362
29063
  const calculatedRoot = await calculateRoot(hasher, leafHash, proof, leafIdx);
28363
29064
  return arraysEqual(calculatedRoot, root);
28364
29065
  }
28365
- async function consistentRoots(hasher, ifrom, accumulatorFrom, paths) {
28366
- const fromPeaks = peakMMRIndexes(ifrom);
28367
- if (fromPeaks.length !== paths.length) {
28368
- throw new Error(`a proof for each accumulator peak is required: ${fromPeaks.length} peaks, ${paths.length} paths`);
29066
+ async function consistentRootsForSizes(hasher, sizeFrom, sizeTo, accumulatorFrom, paths) {
29067
+ if (sizeTo <= sizeFrom) {
29068
+ throw new SizeMustIncrease(sizeFrom, sizeTo);
28369
29069
  }
28370
- if (accumulatorFrom.length !== fromPeaks.length) {
28371
- throw new Error(`accumulator length mismatch: ${accumulatorFrom.length} values for ${fromPeaks.length} peaks`);
29070
+ const to = peaksBitmap(sizeTo);
29071
+ if (mmrSizeForLeafCount(to) !== sizeTo) {
29072
+ throw new IncompleteTreeSize(sizeTo);
28372
29073
  }
29074
+ const from15 = peaksBitmap(sizeFrom);
29075
+ const n = popcount(from15);
29076
+ if (accumulatorFrom.length !== n) {
29077
+ throw new ConsistencyPeakCountMismatch(n, accumulatorFrom.length);
29078
+ }
29079
+ if (paths.length !== n) {
29080
+ throw new ConsistencyPeakCountMismatch(n, paths.length);
29081
+ }
29082
+ const nto = popcount(to);
29083
+ if (n === 0) {
29084
+ return { roots: [], expectedRight: nto };
29085
+ }
29086
+ const split2 = bitLength(from15 ^ to) - 1;
28373
29087
  const roots = [];
28374
- for (let i = 0;i < accumulatorFrom.length; i++) {
28375
- const root = await calculateRoot(hasher, accumulatorFrom[i], { path: paths[i], mmrIndex: fromPeaks[i] }, fromPeaks[i]);
28376
- if (roots.length > 0 && arraysEqual(roots[roots.length - 1], root)) {
29088
+ let offset = 0n;
29089
+ let i = 0;
29090
+ for (let h = bitLength(from15) - 1;h > split2; h--) {
29091
+ if ((from15 >> BigInt(h) & 1n) === 0n)
28377
29092
  continue;
29093
+ if (paths[i].length !== 0) {
29094
+ throw new ConsistencyPathLengthMismatch(i, 0, paths[i].length);
28378
29095
  }
29096
+ roots.push(accumulatorFrom[i]);
29097
+ offset += (1n << BigInt(h + 1)) - 1n;
29098
+ i += 1;
29099
+ }
29100
+ const above = roots.length;
29101
+ let root;
29102
+ for (let h = split2 - 1;h >= 0; h--) {
29103
+ if ((from15 >> BigInt(h) & 1n) === 0n)
29104
+ continue;
29105
+ const expected = split2 - h;
29106
+ if (paths[i].length !== expected) {
29107
+ throw new ConsistencyPathLengthMismatch(i, expected, paths[i].length);
29108
+ }
29109
+ const subtree = (1n << BigInt(h + 1)) - 1n;
29110
+ const peakMMRIndex = offset + subtree - 1n;
29111
+ const proven = await calculateRoot(hasher, accumulatorFrom[i], { path: paths[i], mmrIndex: peakMMRIndex }, peakMMRIndex);
29112
+ if (i === above) {
29113
+ root = proven;
29114
+ } else if (!arraysEqual(proven, root)) {
29115
+ throw new ConsistencyRootMismatch(i);
29116
+ }
29117
+ offset += subtree;
29118
+ i += 1;
29119
+ }
29120
+ if (n > above) {
28379
29121
  roots.push(root);
28380
29122
  }
28381
- return roots;
29123
+ return { roots, expectedRight: nto - roots.length };
28382
29124
  }
28383
- async function verifyConsistency(hasher, proof, peaksFrom, peaksTo) {
28384
- const proven = await consistentRoots(hasher, proof.mmrSizeA - 1n, peaksFrom, proof.paths);
28385
- let ito = 0;
28386
- for (const root of proven) {
28387
- if (ito < peaksTo.length && arraysEqual(peaksTo[ito], root)) {
28388
- continue;
28389
- }
28390
- ito += 1;
28391
- if (ito >= peaksTo.length || !arraysEqual(peaksTo[ito], root)) {
29125
+ async function verifyConsistency(hasher, sizeFrom, sizeTo, peaksFrom, paths, peaksTo) {
29126
+ const { roots, expectedRight } = await consistentRootsForSizes(hasher, sizeFrom, sizeTo, peaksFrom, paths);
29127
+ if (peaksTo.length !== roots.length + expectedRight) {
29128
+ return { ok: false, accumulator: [] };
29129
+ }
29130
+ for (let i = 0;i < roots.length; i++) {
29131
+ if (!arraysEqual(peaksTo[i], roots[i])) {
28392
29132
  return { ok: false, accumulator: [] };
28393
29133
  }
28394
29134
  }
@@ -28402,6 +29142,7 @@ function indexConsistencyProof(get, mmrIndexA, mmrIndexB) {
28402
29142
  return { mmrSizeA: mmrIndexA + 1n, mmrSizeB: mmrIndexB + 1n, paths };
28403
29143
  }
28404
29144
  var init_algorithms = __esm(() => {
29145
+ init_errors4();
28405
29146
  init_math();
28406
29147
  });
28407
29148
 
@@ -28437,7 +29178,7 @@ async function createSyncHasher() {
28437
29178
  }
28438
29179
 
28439
29180
  // node_modules/@forestrie/merklelog/dist/index.js
28440
- var init_dist8 = __esm(() => {
29181
+ var init_dist9 = __esm(() => {
28441
29182
  init_massif();
28442
29183
  init_types();
28443
29184
  init_types();
@@ -28445,6 +29186,75 @@ var init_dist8 = __esm(() => {
28445
29186
  init_leafindex();
28446
29187
  init_math();
28447
29188
  init_algorithms();
29189
+ init_errors4();
29190
+ });
29191
+
29192
+ // node_modules/@forestrie/receipt-verify/dist/decode-checkpoint-consistency-proof.js
29193
+ function asBigint(v, what) {
29194
+ if (typeof v === "bigint") {
29195
+ if (v < 0n) {
29196
+ throw new Error(`${what}: must be an unsigned integer, got ${v}`);
29197
+ }
29198
+ return v;
29199
+ }
29200
+ if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0) {
29201
+ return BigInt(v);
29202
+ }
29203
+ throw new Error(`${what}: expected an unsigned integer`);
29204
+ }
29205
+ function asBytesArray(v, what) {
29206
+ if (!Array.isArray(v) || v.some((e) => !(e instanceof Uint8Array) || e.length !== 32)) {
29207
+ throw new Error(`${what}: expected an array of 32-byte strings`);
29208
+ }
29209
+ return v;
29210
+ }
29211
+ function decodeConsistencyProofFromUnprotected(unprotected) {
29212
+ const vdpRaw = unprotected.get(COSE_LABEL_VDP);
29213
+ if (vdpRaw === undefined || vdpRaw === null)
29214
+ return null;
29215
+ if (!(vdpRaw instanceof Map)) {
29216
+ throw new Error("checkpoint carries no verifiable-proofs header (396)");
29217
+ }
29218
+ const proofBstr = vdpRaw.get(VDP_CONSISTENCY_PROOF_KEY);
29219
+ if (proofBstr === undefined || proofBstr === null)
29220
+ return null;
29221
+ if (!(proofBstr instanceof Uint8Array)) {
29222
+ throw new Error("checkpoint carries no consistency proof (vdp key -2)");
29223
+ }
29224
+ const proof = decodeCborDeterministic(proofBstr);
29225
+ if (!Array.isArray(proof) || proof.length < 4) {
29226
+ throw new Error("consistency proof must be [tree-size-1, tree-size-2, paths, right-peaks]");
29227
+ }
29228
+ const pathsRaw = proof[2];
29229
+ if (!Array.isArray(pathsRaw)) {
29230
+ throw new Error("consistency paths must be arrays of 32-byte strings");
29231
+ }
29232
+ for (let i = 0;i < pathsRaw.length; i++) {
29233
+ const path2 = pathsRaw[i];
29234
+ if (!Array.isArray(path2)) {
29235
+ throw new Error(`consistency path ${i}: expected an array of 32-byte strings`);
29236
+ }
29237
+ for (let j = 0;j < path2.length; j++) {
29238
+ const node = path2[j];
29239
+ if (!(node instanceof Uint8Array) || node.length !== 32) {
29240
+ throw new Error(`consistency path ${i} element ${j}: expected a 32-byte string`);
29241
+ }
29242
+ }
29243
+ }
29244
+ const treeSize1 = asBigint(proof[0], "tree-size-1");
29245
+ const treeSize2 = asBigint(proof[1], "tree-size-2");
29246
+ if (treeSize2 <= treeSize1) {
29247
+ throw new Error(`consistency proof must grow the tree: tree-size-1 ${treeSize1} < tree-size-2 ${treeSize2}`);
29248
+ }
29249
+ return {
29250
+ treeSize1,
29251
+ treeSize2,
29252
+ paths: pathsRaw,
29253
+ rightPeaks: asBytesArray(proof[3], "right-peaks")
29254
+ };
29255
+ }
29256
+ var init_decode_checkpoint_consistency_proof = __esm(() => {
29257
+ init_dist3();
28448
29258
  });
28449
29259
 
28450
29260
  // node_modules/@forestrie/receipt-verify/dist/subtle-hasher.js
@@ -28474,7 +29284,7 @@ function parseCheckpoint(checkpointBytes) {
28474
29284
  const decoded = decodeCborDeterministic(checkpointBytes);
28475
29285
  const coseSign1 = requireCoseSign1(unwrapCoseSign1Tag(decoded));
28476
29286
  const unprotected = toHeaderMap(coseSign1[1]);
28477
- const peakReceiptsRaw = unprotected.get(SEAL_PEAK_RECEIPTS_LABEL);
29287
+ const peakReceiptsRaw = unprotected.get(COSE_LABEL_PEAK_RECEIPTS);
28478
29288
  const peakReceipts = Array.isArray(peakReceiptsRaw) ? peakReceiptsRaw : null;
28479
29289
  const delegationCertRaw = unprotected.get(DELEGATION_CERT_LABEL);
28480
29290
  const delegationCert = delegationCertRaw instanceof Uint8Array && delegationCertRaw.length > 0 ? delegationCertRaw : null;
@@ -28482,7 +29292,7 @@ function parseCheckpoint(checkpointBytes) {
28482
29292
  coseSign1,
28483
29293
  unprotected,
28484
29294
  peakReceipts,
28485
- mmrSize: sealedSizeFromCheckpoint(unprotected),
29295
+ mmrSize: sealedSizeFromCheckpoint(coseSign1, unprotected),
28486
29296
  delegationCert
28487
29297
  };
28488
29298
  }
@@ -28535,7 +29345,7 @@ function assembleReceiptFromProof(checkpoint, mmrIndex2, proof) {
28535
29345
  const verifiableProofs = new Map([
28536
29346
  [-1, [inclusionProofEntry]]
28537
29347
  ]);
28538
- receiptUnprotected.set(VDS_COSE_RECEIPT_PROOFS_TAG2, verifiableProofs);
29348
+ receiptUnprotected.set(COSE_LABEL_VDP, verifiableProofs);
28539
29349
  const assembled = [
28540
29350
  receiptSign1[0],
28541
29351
  receiptUnprotected,
@@ -28564,89 +29374,66 @@ async function computeAccumulatorPeak(opts) {
28564
29374
  function cborBytes(value) {
28565
29375
  return encodeCborDeterministic(value);
28566
29376
  }
28567
- function sealedSizeFromCheckpoint(unprotected) {
28568
- const vdpRaw = unprotected.get(VDS_COSE_RECEIPT_PROOFS_TAG2);
28569
- if (vdpRaw === undefined || vdpRaw === null)
29377
+ function sealedSizeFromCheckpoint(coseSign1, unprotected) {
29378
+ let declared;
29379
+ try {
29380
+ declared = decodeConsistencyProofFromUnprotected(unprotected);
29381
+ } catch {
28570
29382
  return null;
28571
- const vdp = toHeaderMap(vdpRaw);
28572
- const proofBstr = vdp.get(VDP_CONSISTENCY_PROOF_KEY);
28573
- if (!(proofBstr instanceof Uint8Array))
29383
+ }
29384
+ if (declared === null)
28574
29385
  return null;
28575
- const proof = decodeCborDeterministic(proofBstr);
28576
- if (!Array.isArray(proof) || proof.length < 2)
29386
+ try {
29387
+ return readProtectedTreeSize2(coseSign1[0]);
29388
+ } catch {
28577
29389
  return null;
28578
- const treeSize2 = proof[1];
28579
- if (typeof treeSize2 === "bigint")
28580
- return treeSize2;
28581
- if (typeof treeSize2 === "number" && Number.isSafeInteger(treeSize2)) {
28582
- return BigInt(treeSize2);
28583
29390
  }
28584
- return null;
28585
29391
  }
28586
- var VDS_COSE_RECEIPT_PROOFS_TAG2 = 396, SEAL_PEAK_RECEIPTS_LABEL = -65931, DELEGATION_CERT_LABEL = 1000, VDP_CONSISTENCY_PROOF_KEY = -2;
29392
+ var DELEGATION_CERT_LABEL = 1000;
28587
29393
  var init_build_receipt_offline = __esm(() => {
28588
29394
  init_dist3();
28589
- init_dist8();
29395
+ init_dist9();
28590
29396
  init_parse_receipt();
29397
+ init_decode_checkpoint_consistency_proof();
28591
29398
  });
28592
29399
 
28593
29400
  // node_modules/@forestrie/receipt-verify/dist/checkpoint-chain.js
28594
- function asBigint(v, what) {
28595
- if (typeof v === "bigint") {
28596
- if (v < 0n)
28597
- throw new Error(`${what}: must be an unsigned integer, got ${v}`);
28598
- return v;
28599
- }
28600
- if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0) {
28601
- return BigInt(v);
28602
- }
28603
- throw new Error(`${what}: expected an unsigned integer`);
28604
- }
28605
- function asBytesArray(v, what) {
28606
- if (!Array.isArray(v) || v.some((e) => !(e instanceof Uint8Array) || e.length !== 32)) {
28607
- throw new Error(`${what}: expected an array of 32-byte strings`);
28608
- }
28609
- return v;
28610
- }
28611
29401
  function checkpointConsistencyProof(checkpointBytes) {
28612
- const { unprotected } = parseCheckpoint(checkpointBytes);
28613
- const vdpRaw = unprotected.get(VDS_COSE_RECEIPT_PROOFS_TAG3);
28614
- if (!(vdpRaw instanceof Map)) {
28615
- throw new Error("checkpoint carries no verifiable-proofs header (396)");
28616
- }
28617
- const proofBstr = vdpRaw.get(VDP_CONSISTENCY_PROOF_KEY2);
28618
- if (!(proofBstr instanceof Uint8Array)) {
29402
+ const { coseSign1, unprotected } = parseCheckpoint(checkpointBytes);
29403
+ const alg = extractAlgFromProtected(coseSign1[0]);
29404
+ const signature = coseSign1[3];
29405
+ if (alg === COSE_ALG_ES256 && signature.length === 64 && !isLowS(signature)) {
29406
+ throw new CheckpointHighSSignatureError("checkpoint ES256 signature is not low-s canonical (s > n/2); rejected " + "to match the univocity contract's P-256 verifier and go-merklelog");
29407
+ }
29408
+ const declared = decodeConsistencyProofFromUnprotected(unprotected);
29409
+ if (declared === null) {
28619
29410
  throw new Error("checkpoint carries no consistency proof (vdp key -2)");
28620
29411
  }
28621
- const proof = decodeCborDeterministic(proofBstr);
28622
- if (!Array.isArray(proof) || proof.length < 4) {
28623
- throw new Error("consistency proof must be [tree-size-1, tree-size-2, paths, right-peaks]");
28624
- }
28625
- const pathsRaw = proof[2];
28626
- if (!Array.isArray(pathsRaw) || pathsRaw.some((p) => !Array.isArray(p) || p.some((n) => !(n instanceof Uint8Array)))) {
28627
- throw new Error("consistency paths must be arrays of byte strings");
29412
+ const signedTreeSize2 = readProtectedTreeSize2(coseSign1[0]);
29413
+ if (signedTreeSize2 === null) {
29414
+ throw new Error("checkpoint protected header carries no signed tree-size-2 (-65933)");
28628
29415
  }
28629
- const treeSize1 = asBigint(proof[0], "tree-size-1");
28630
- const treeSize2 = asBigint(proof[1], "tree-size-2");
28631
- if (treeSize2 <= treeSize1) {
28632
- throw new Error(`consistency proof must grow the tree: tree-size-1 ${treeSize1} < tree-size-2 ${treeSize2}`);
29416
+ if (signedTreeSize2 !== declared.treeSize2) {
29417
+ throw new CheckpointSignedSizeMismatchError(`signed tree-size-2 (-65933) ${signedTreeSize2} != declared consistency-proof tree-size-2 ${declared.treeSize2}`);
28633
29418
  }
28634
29419
  return {
28635
- treeSize1,
28636
- treeSize2,
28637
- paths: pathsRaw,
28638
- rightPeaks: asBytesArray(proof[3], "right-peaks")
29420
+ treeSize1: declared.treeSize1,
29421
+ treeSize2: declared.treeSize2,
29422
+ signedTreeSize2,
29423
+ paths: declared.paths,
29424
+ rightPeaks: declared.rightPeaks
28639
29425
  };
28640
29426
  }
28641
- async function computeCheckpointAccumulator(proof, accumulatorFrom) {
29427
+ async function computeCheckpointAccumulator(proof, accumulatorFrom, sizeFrom) {
29428
+ if (proof.treeSize1 !== sizeFrom) {
29429
+ throw new Error(`consistency proof base tree-size-1 ${proof.treeSize1} does not match the trusted size ${sizeFrom}`);
29430
+ }
28642
29431
  const hasher = new SubtleHasher;
28643
- const proven = proof.treeSize1 === 0n ? [] : await consistentRoots(hasher, proof.treeSize1 - 1n, accumulatorFrom, proof.paths);
28644
- const accumulator = [...proven, ...proof.rightPeaks];
28645
- const expected = peakMMRIndexes(proof.treeSize2 - 1n).length;
28646
- if (accumulator.length !== expected) {
28647
- throw new Error(`computed accumulator has ${accumulator.length} peaks; size ${proof.treeSize2} requires ${expected}`);
29432
+ const { roots, expectedRight } = await consistentRootsForSizes(hasher, sizeFrom, proof.treeSize2, accumulatorFrom, proof.paths);
29433
+ if (proof.rightPeaks.length !== expectedRight) {
29434
+ throw new Error(`checkpoint supplies ${proof.rightPeaks.length} right-peaks; size ${proof.treeSize2} requires ${expectedRight}`);
28648
29435
  }
28649
- return accumulator;
29436
+ return [...roots, ...proof.rightPeaks];
28650
29437
  }
28651
29438
  function accumulatorPayload(accumulator) {
28652
29439
  const out = new Uint8Array(accumulator.reduce((s, p) => s + p.length, 0));
@@ -28668,56 +29455,66 @@ async function verifyCheckpointChain(opts) {
28668
29455
  links
28669
29456
  };
28670
29457
  }
28671
- let accumulator = opts.accumulatorFrom ?? [];
28672
- let expectedBase = null;
29458
+ const trustedBase = opts.trustedBase;
29459
+ if (trustedBase !== undefined) {
29460
+ if (trustedBase.size < 0n || mmrSizeForLeafCount(peaksBitmap(trustedBase.size)) !== trustedBase.size) {
29461
+ return {
29462
+ ok: false,
29463
+ reason: "proof_malformed",
29464
+ at: 0,
29465
+ detail: `trusted base size ${trustedBase.size} is not a complete MMR size`,
29466
+ links
29467
+ };
29468
+ }
29469
+ const basePeaks = trustedBase.size === 0n ? 0 : peakMMRIndexes(trustedBase.size - 1n).length;
29470
+ if (trustedBase.accumulator.length !== basePeaks) {
29471
+ return {
29472
+ ok: false,
29473
+ reason: "proof_malformed",
29474
+ at: 0,
29475
+ detail: `trusted base accumulator has ${trustedBase.accumulator.length} peaks; size ${trustedBase.size} has ${basePeaks}`,
29476
+ links
29477
+ };
29478
+ }
29479
+ }
29480
+ let accumulator = trustedBase?.accumulator ?? [];
29481
+ let expectedBase = trustedBase?.size ?? 0n;
28673
29482
  for (let i = 0;i < opts.checkpoints.length; i++) {
28674
29483
  const bytes = opts.checkpoints[i];
28675
29484
  let proof;
28676
29485
  try {
28677
29486
  proof = checkpointConsistencyProof(bytes);
28678
29487
  } catch (err) {
29488
+ const reason = err instanceof CheckpointSignedSizeMismatchError ? "size_mismatch" : err instanceof CheckpointHighSSignatureError ? "signature_malleable" : "proof_malformed";
28679
29489
  return {
28680
29490
  ok: false,
28681
- reason: "proof_malformed",
29491
+ reason,
28682
29492
  at: i,
28683
29493
  detail: err instanceof Error ? err.message : String(err),
28684
29494
  links
28685
29495
  };
28686
29496
  }
28687
- if (expectedBase === null) {
28688
- if (proof.treeSize1 !== 0n) {
28689
- const wanted = peakMMRIndexes(proof.treeSize1 - 1n).length;
28690
- if (opts.accumulatorFrom === undefined) {
28691
- return {
28692
- ok: false,
28693
- reason: "legacy_chain_break",
28694
- at: i,
28695
- detail: `first checkpoint base ${proof.treeSize1} != 0 and no trusted base accumulator was supplied`,
28696
- links
28697
- };
28698
- }
28699
- if (accumulator.length !== wanted) {
28700
- return {
28701
- ok: false,
28702
- reason: "proof_malformed",
28703
- at: i,
28704
- detail: `trusted base accumulator has ${accumulator.length} peaks; base size ${proof.treeSize1} requires ${wanted}`,
28705
- links
28706
- };
28707
- }
29497
+ if (proof.treeSize1 !== expectedBase) {
29498
+ if (i === 0) {
29499
+ return {
29500
+ ok: false,
29501
+ reason: "size_mismatch",
29502
+ at: i,
29503
+ detail: trustedBase === undefined ? `first checkpoint declared tree-size-1 ${proof.treeSize1} != whole-log base size ${expectedBase} and no trusted base was supplied` : `first checkpoint declared tree-size-1 ${proof.treeSize1} != trusted base size ${expectedBase}`,
29504
+ links
29505
+ };
28708
29506
  }
28709
- } else if (proof.treeSize1 !== expectedBase) {
28710
29507
  return {
28711
29508
  ok: false,
28712
- reason: "legacy_chain_break",
29509
+ reason: "size_mismatch",
28713
29510
  at: i,
28714
- detail: `checkpoint ${i} base ${proof.treeSize1} != previous sealed size ${expectedBase} — ` + "pre-FOR-410 drifted chain (permanent for this log); fall back to the event scan, tile extension, or a holder cache",
29511
+ detail: `checkpoint ${i} declared tree-size-1 ${proof.treeSize1} != the previous link's tree-size-2 ${expectedBase} — ` + "the declared origin is unsigned, so the chain is treated as not continuous",
28715
29512
  links
28716
29513
  };
28717
29514
  }
28718
29515
  let computed;
28719
29516
  try {
28720
- computed = await computeCheckpointAccumulator(proof, accumulator);
29517
+ computed = await computeCheckpointAccumulator(proof, accumulator, expectedBase);
28721
29518
  } catch (err) {
28722
29519
  return {
28723
29520
  ok: false,
@@ -28728,12 +29525,6 @@ async function verifyCheckpointChain(opts) {
28728
29525
  };
28729
29526
  }
28730
29527
  const signatureOk = await opts.verifySignature(bytes, accumulatorPayload(computed));
28731
- links.push({
28732
- treeSize1: proof.treeSize1,
28733
- treeSize2: proof.treeSize2,
28734
- accumulator: computed,
28735
- signatureOk
28736
- });
28737
29528
  if (!signatureOk) {
28738
29529
  return {
28739
29530
  ok: false,
@@ -28743,16 +29534,36 @@ async function verifyCheckpointChain(opts) {
28743
29534
  links
28744
29535
  };
28745
29536
  }
29537
+ links.push({
29538
+ treeSize1: proof.treeSize1,
29539
+ treeSize2: proof.treeSize2,
29540
+ signedTreeSize2: proof.signedTreeSize2,
29541
+ accumulator: computed,
29542
+ signatureOk
29543
+ });
28746
29544
  accumulator = computed;
28747
29545
  expectedBase = proof.treeSize2;
28748
29546
  }
28749
29547
  return { ok: true, links, accumulator };
28750
29548
  }
28751
- var VDS_COSE_RECEIPT_PROOFS_TAG3 = 396, VDP_CONSISTENCY_PROOF_KEY2 = -2;
29549
+ var CheckpointSignedSizeMismatchError, CheckpointHighSSignatureError;
28752
29550
  var init_checkpoint_chain = __esm(() => {
28753
29551
  init_dist3();
28754
- init_dist8();
29552
+ init_dist9();
28755
29553
  init_build_receipt_offline();
29554
+ init_decode_checkpoint_consistency_proof();
29555
+ CheckpointSignedSizeMismatchError = class CheckpointSignedSizeMismatchError extends Error {
29556
+ constructor(message) {
29557
+ super(message);
29558
+ this.name = "CheckpointSignedSizeMismatchError";
29559
+ }
29560
+ };
29561
+ CheckpointHighSSignatureError = class CheckpointHighSSignatureError extends Error {
29562
+ constructor(message) {
29563
+ super(message);
29564
+ this.name = "CheckpointHighSSignatureError";
29565
+ }
29566
+ };
28756
29567
  });
28757
29568
 
28758
29569
  // node_modules/@forestrie/receipt-verify/dist/freshen-receipt.js
@@ -28784,16 +29595,17 @@ async function freshenReceipt(input) {
28784
29595
  throw new Error("freshen requires at least one consistency proof linking the receipt's era to the checkpoint");
28785
29596
  }
28786
29597
  const firstLink = links[0];
28787
- const baseCount = input.accumulatorFrom?.length ?? 0;
28788
- if (firstLink.treeSize1 === 0n) {
28789
- if (baseCount !== 0) {
28790
- throw new Error("base-0 consistency chain must start from an empty accumulator seed");
28791
- }
28792
- } else {
28793
- const wanted = peakMMRIndexes(firstLink.treeSize1 - 1n).length;
28794
- if (baseCount !== wanted) {
28795
- throw new Error(`base accumulator has ${baseCount} peaks; first link size ${firstLink.treeSize1} requires ${wanted}`);
28796
- }
29598
+ const baseSize = input.trustedBase?.size ?? 0n;
29599
+ const baseAccumulator = input.trustedBase?.accumulator ?? [];
29600
+ if (baseSize < 0n || mmrSizeForLeafCount(peaksBitmap(baseSize)) !== baseSize) {
29601
+ throw new Error(`trusted base size ${baseSize} is not a complete MMR size`);
29602
+ }
29603
+ const basePeaks = baseSize === 0n ? 0 : peakMMRIndexes(baseSize - 1n).length;
29604
+ if (baseAccumulator.length !== basePeaks) {
29605
+ throw new Error(`base accumulator has ${baseAccumulator.length} peaks; trusted base size ${baseSize} has ${basePeaks}`);
29606
+ }
29607
+ if (firstLink.treeSize1 !== baseSize) {
29608
+ throw new Error(`first consistency proof declares tree-size-1 ${firstLink.treeSize1}; the trusted base size is ${baseSize}`);
28797
29609
  }
28798
29610
  for (let i = 1;i < links.length; i++) {
28799
29611
  if (links[i].treeSize1 !== links[i - 1].treeSize2) {
@@ -28804,9 +29616,11 @@ async function freshenReceipt(input) {
28804
29616
  if (lastLink.treeSize2 !== sealedSize) {
28805
29617
  throw new Error(`consistency chain ends at size ${lastLink.treeSize2} but the checkpoint sealed size ${sealedSize}`);
28806
29618
  }
28807
- let accumulator = input.accumulatorFrom ?? [];
29619
+ let accumulator = baseAccumulator;
29620
+ let sizeFrom = baseSize;
28808
29621
  for (const p of links) {
28809
- accumulator = await computeCheckpointAccumulator(p, accumulator);
29622
+ accumulator = await computeCheckpointAccumulator(p, accumulator, sizeFrom);
29623
+ sizeFrom = p.treeSize2;
28810
29624
  }
28811
29625
  const aLatest = accumulator;
28812
29626
  const structuralPeaks = peakMMRIndexes(sealedSize - 1n).length;
@@ -28860,14 +29674,14 @@ async function freshenReceipt(input) {
28860
29674
  return { receipt, sealedSize };
28861
29675
  }
28862
29676
  var init_freshen_receipt = __esm(() => {
28863
- init_dist8();
29677
+ init_dist9();
28864
29678
  init_build_receipt_offline();
28865
29679
  init_checkpoint_chain();
28866
29680
  init_parse_receipt();
28867
29681
  });
28868
29682
 
28869
29683
  // node_modules/@forestrie/receipt-verify/dist/cose-key.js
28870
- var COSE_ALG_ES2565 = -7, COSE_KEY_KTY = 1, COSE_KEY_ALG = 3, COSE_EC2_CRV = -1, COSE_EC2_X = -2, COSE_EC2_Y = -3, COSE_KTY_EC22 = 2, COSE_CRV_P2562 = 1;
29684
+ var COSE_ALG_ES2566 = -7, COSE_KEY_KTY = 1, COSE_KEY_ALG = 3, COSE_EC2_CRV = -1, COSE_EC2_X = -2, COSE_EC2_Y = -3, COSE_KTY_EC22 = 2, COSE_CRV_P2562 = 1;
28871
29685
 
28872
29686
  // node_modules/@forestrie/receipt-verify/dist/forest-genesis-labels.js
28873
29687
  var FOREST_GENESIS_LABEL_GENESIS_VERSION = -68009, FOREST_GENESIS_LABEL_GENESIS_ALG = -68014, FOREST_GENESIS_LABEL_BOOTSTRAP_KEY = -68015, FOREST_GENESIS_SCHEMA_V2 = 2, FOREST_GENESIS_SCHEMA_V1 = 1, HEADER_IDTIMESTAMP2 = -65537, HEADER_FORESTRIE_GRANT_V02 = -65538;
@@ -28965,8 +29779,8 @@ var init_decode_trust_root_cbor = __esm(() => {
28965
29779
  init_dist3();
28966
29780
  });
28967
29781
 
28968
- // node_modules/@forestrie/receipt-verify/dist/decode-trust-root-from-genesis.js
28969
- function decodeBodyAsIntKeyMap(raw) {
29782
+ // node_modules/@forestrie/receipt-verify/dist/decode-genesis-cbor-map.js
29783
+ function decodeGenesisBodyAsIntKeyMap(raw) {
28970
29784
  if (raw instanceof Map)
28971
29785
  return raw;
28972
29786
  if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
@@ -28983,14 +29797,16 @@ function decodeBodyAsIntKeyMap(raw) {
28983
29797
  function asGenesisUint8Array(v) {
28984
29798
  return v instanceof Uint8Array ? v : null;
28985
29799
  }
28986
- async function decodeTrustRootFromGenesis(genesisCbor) {
29800
+
29801
+ // node_modules/@forestrie/receipt-verify/dist/decode-trust-root-from-genesis.js
29802
+ async function decodeTrustRootDetailsFromGenesis(genesisCbor) {
28987
29803
  let raw;
28988
29804
  try {
28989
29805
  raw = decodeCborDeterministic(genesisCbor);
28990
29806
  } catch {
28991
29807
  throw new Error("genesis CBOR decode failed");
28992
29808
  }
28993
- const m = decodeBodyAsIntKeyMap(raw);
29809
+ const m = decodeGenesisBodyAsIntKeyMap(raw);
28994
29810
  if (!m)
28995
29811
  throw new Error("genesis document must be a CBOR map");
28996
29812
  const versionRaw = m.get(FOREST_GENESIS_LABEL_GENESIS_VERSION);
@@ -29000,7 +29816,11 @@ async function decodeTrustRootFromGenesis(genesisCbor) {
29000
29816
  if (bootstrapKey === null) {
29001
29817
  throw new Error("v2 genesis missing bootstrapKey");
29002
29818
  }
29003
- return decodeTrustRootCbor({ alg, key: bootstrapKey });
29819
+ const key = await decodeTrustRootCbor({ alg, key: bootstrapKey });
29820
+ return {
29821
+ key,
29822
+ bootstrapKeyXy: isParsedKs256RootKey(key) ? undefined : bootstrapKey
29823
+ };
29004
29824
  }
29005
29825
  const kty = m.get(COSE_KEY_KTY);
29006
29826
  const crv = m.get(COSE_EC2_CRV);
@@ -29008,45 +29828,54 @@ async function decodeTrustRootFromGenesis(genesisCbor) {
29008
29828
  const y = asGenesisUint8Array(m.get(COSE_EC2_Y));
29009
29829
  if (kty === COSE_KTY_EC22 && crv === COSE_CRV_P2562 && x && y) {
29010
29830
  const alg = m.get(COSE_KEY_ALG);
29011
- if (alg !== undefined && alg !== COSE_ALG_ES2565) {
29831
+ if (alg !== undefined && alg !== COSE_ALG_ES2566) {
29012
29832
  throw new Error("genesis EC2 key must be ES256");
29013
29833
  }
29014
29834
  const xy = new Uint8Array(64);
29015
29835
  xy.set(x, 0);
29016
29836
  xy.set(y, 32);
29017
- return decodeTrustRootCbor({ alg: COSE_ALG_ES2565, key: xy });
29837
+ const key = await decodeTrustRootCbor({ alg: COSE_ALG_ES2566, key: xy });
29838
+ return { key, bootstrapKeyXy: xy };
29018
29839
  }
29019
29840
  if (versionRaw === FOREST_GENESIS_SCHEMA_V1 || versionRaw === undefined) {
29020
29841
  throw new Error("unsupported or invalid genesis schema for trust root");
29021
29842
  }
29022
29843
  throw new Error("unsupported genesis document");
29023
29844
  }
29845
+ async function decodeTrustRootFromGenesis(genesisCbor) {
29846
+ return (await decodeTrustRootDetailsFromGenesis(genesisCbor)).key;
29847
+ }
29024
29848
  var init_decode_trust_root_from_genesis = __esm(() => {
29025
29849
  init_dist3();
29026
29850
  init_decode_trust_root_cbor();
29027
29851
  });
29028
29852
 
29853
+ // node_modules/@forestrie/receipt-verify/dist/decode-chain-binding-from-genesis.js
29854
+ var init_decode_chain_binding_from_genesis = __esm(() => {
29855
+ init_dist3();
29856
+ });
29857
+
29029
29858
  // node_modules/@forestrie/receipt-verify/dist/uuid-bytes.js
29030
- function toPaddedWire322(bytes) {
29031
- if (bytes.length === WIRE_LOG_ID_BYTES2)
29859
+ function toPaddedWire323(bytes) {
29860
+ if (bytes.length === WIRE_LOG_ID_BYTES3)
29032
29861
  return bytes;
29033
- const out = new Uint8Array(WIRE_LOG_ID_BYTES2);
29034
- if (bytes.length >= WIRE_LOG_ID_BYTES2) {
29035
- out.set(bytes.slice(-WIRE_LOG_ID_BYTES2));
29862
+ const out = new Uint8Array(WIRE_LOG_ID_BYTES3);
29863
+ if (bytes.length >= WIRE_LOG_ID_BYTES3) {
29864
+ out.set(bytes.slice(-WIRE_LOG_ID_BYTES3));
29036
29865
  } else {
29037
- out.set(bytes, WIRE_LOG_ID_BYTES2 - bytes.length);
29866
+ out.set(bytes, WIRE_LOG_ID_BYTES3 - bytes.length);
29038
29867
  }
29039
29868
  return out;
29040
29869
  }
29041
- function fromPaddedWire322(wire) {
29870
+ function fromPaddedWire323(wire) {
29042
29871
  if (wire.length === 16)
29043
29872
  return wire;
29044
- if (wire.length !== WIRE_LOG_ID_BYTES2) {
29045
- throw new Error(`Expected ${WIRE_LOG_ID_BYTES2}-byte wire log id`);
29873
+ if (wire.length !== WIRE_LOG_ID_BYTES3) {
29874
+ throw new Error(`Expected ${WIRE_LOG_ID_BYTES3}-byte wire log id`);
29046
29875
  }
29047
29876
  return wire.slice(-16);
29048
29877
  }
29049
- var WIRE_LOG_ID_BYTES2 = 32;
29878
+ var WIRE_LOG_ID_BYTES3 = 32;
29050
29879
 
29051
29880
  // node_modules/@forestrie/receipt-verify/dist/grant-commitment.js
29052
29881
  function u64Be(n) {
@@ -29068,11 +29897,11 @@ function grantFlags32(flags) {
29068
29897
  return out;
29069
29898
  }
29070
29899
  function grantCommitmentPreimage(grant) {
29071
- const logId = toPaddedWire322(grant.logId);
29900
+ const logId = toPaddedWire323(grant.logId);
29072
29901
  const flags32 = grantFlags32(grant.grant);
29073
29902
  const maxHeight = grant.maxHeight ?? 0;
29074
29903
  const minGrowth = grant.minGrowth ?? 0;
29075
- const ownerLogId = toPaddedWire322(grant.ownerLogId);
29904
+ const ownerLogId = toPaddedWire323(grant.ownerLogId);
29076
29905
  const grantData = grantDataToBytes(grant.grantData ?? new Uint8Array(0));
29077
29906
  const total = logId.length + flags32.length + U64_BYTES * 2 + ownerLogId.length + grantData.length;
29078
29907
  const out = new Uint8Array(total);
@@ -29411,7 +30240,7 @@ async function verifyReceiptOfflineWithLeafInnerKeys(input) {
29411
30240
  }
29412
30241
  var init_verify_grant_receipt_offline = __esm(() => {
29413
30242
  init_dist3();
29414
- init_dist8();
30243
+ init_dist9();
29415
30244
  init_grant_commitment();
29416
30245
  init_decode_trust_root_from_genesis();
29417
30246
  init_decode_trust_root_cbor();
@@ -29462,15 +30291,15 @@ function mapToGrant(m) {
29462
30291
  throw new Error("Grant payload: expected uint");
29463
30292
  };
29464
30293
  return {
29465
- logId: fromPaddedWire322(requireBstr(get(CBOR_KEY_LOG_ID))),
29466
- ownerLogId: fromPaddedWire322(requireBstr(get(CBOR_KEY_OWNER_LOG_ID))),
30294
+ logId: fromPaddedWire323(requireBstr(get(CBOR_KEY_LOG_ID))),
30295
+ ownerLogId: fromPaddedWire323(requireBstr(get(CBOR_KEY_OWNER_LOG_ID))),
29467
30296
  grant: leftPad(requireBstr(get(CBOR_KEY_GRANT_FLAGS)), WIRE_GRANT_FLAGS_BYTES2),
29468
30297
  maxHeight: requireUint(get(CBOR_KEY_MAX_HEIGHT)),
29469
30298
  minGrowth: requireUint(get(CBOR_KEY_MIN_GROWTH)),
29470
30299
  grantData: get(CBOR_KEY_GRANT_DATA) instanceof Uint8Array ? get(CBOR_KEY_GRANT_DATA) : new Uint8Array(0)
29471
30300
  };
29472
30301
  }
29473
- function decodeGrantPayload2(bytes) {
30302
+ function decodeGrantPayload3(bytes) {
29474
30303
  if (!bytes?.length)
29475
30304
  throw new Error("Grant payload is empty");
29476
30305
  const raw = decodeCborDeterministic(bytes);
@@ -29480,7 +30309,7 @@ function decodeGrantPayload2(bytes) {
29480
30309
  return mapToGrant(raw);
29481
30310
  }
29482
30311
  var CBOR_KEY_LOG_ID = 1, CBOR_KEY_OWNER_LOG_ID = 2, CBOR_KEY_GRANT_FLAGS = 3, CBOR_KEY_MAX_HEIGHT = 4, CBOR_KEY_MIN_GROWTH = 5, CBOR_KEY_GRANT_DATA = 6, WIRE_GRANT_FLAGS_BYTES2 = 8;
29483
- var init_grant_codec2 = __esm(() => {
30312
+ var init_grant_codec3 = __esm(() => {
29484
30313
  init_dist3();
29485
30314
  init_dist3();
29486
30315
  });
@@ -29529,7 +30358,7 @@ function decodeForestrieGrantCose(bytes) {
29529
30358
  const idtimestampVal = unprotected.get(HEADER_IDTIMESTAMP2);
29530
30359
  const idtimestampBe8 = idtimestampVal instanceof Uint8Array && idtimestampVal.length >= IDTIMESTAMP_BYTES3 ? idtimestampVal.length === IDTIMESTAMP_BYTES3 ? idtimestampVal : idtimestampVal.slice(-IDTIMESTAMP_BYTES3) : new Uint8Array(IDTIMESTAMP_BYTES3);
29531
30360
  return {
29532
- grant: decodeGrantPayload2(embedded),
30361
+ grant: decodeGrantPayload3(embedded),
29533
30362
  idtimestampBe8: new Uint8Array(idtimestampBe8)
29534
30363
  };
29535
30364
  }
@@ -29537,7 +30366,7 @@ var IDTIMESTAMP_BYTES3 = 8;
29537
30366
  var init_decode_forestrie_grant_cose = __esm(() => {
29538
30367
  init_sha256();
29539
30368
  init_dist3();
29540
- init_grant_codec2();
30369
+ init_grant_codec3();
29541
30370
  });
29542
30371
 
29543
30372
  // node_modules/@forestrie/receipt-verify/dist/attach-transparent-statement-receipt.js
@@ -29585,7 +30414,7 @@ async function findGrantLeafInMassif(massifBytes, grant) {
29585
30414
  return index2.findLeafByContentHash(inner);
29586
30415
  }
29587
30416
  var init_find_grant_leaf = __esm(() => {
29588
- init_dist8();
30417
+ init_dist9();
29589
30418
  init_grant_commitment();
29590
30419
  });
29591
30420
 
@@ -29606,10 +30435,11 @@ function defaultTimeoutMs(options) {
29606
30435
  }
29607
30436
  async function ethRpc(rpcUrl, method, params, options = {}) {
29608
30437
  const timeoutMs = defaultTimeoutMs(options);
30438
+ const fetch2 = options.fetchImpl ?? globalThis.fetch;
29609
30439
  const controller = new AbortController;
29610
30440
  const timer = setTimeout(() => controller.abort(), timeoutMs);
29611
30441
  try {
29612
- const res = await fetch(rpcUrl, {
30442
+ const res = await fetch2(rpcUrl, {
29613
30443
  method: "POST",
29614
30444
  headers: { "Content-Type": "application/json" },
29615
30445
  body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
@@ -29659,7 +30489,7 @@ var init_erc1271_verify_hooks = __esm(() => {
29659
30489
  });
29660
30490
 
29661
30491
  // node_modules/@forestrie/chain-rpc/dist/index.js
29662
- var init_dist9 = __esm(() => {
30492
+ var init_dist10 = __esm(() => {
29663
30493
  init_substitute_env_templates();
29664
30494
  init_supported_chains_config();
29665
30495
  init_erc1271_verify_hooks();
@@ -29750,18 +30580,19 @@ function assertSnapshotBinding(snapshot, opts) {
29750
30580
  var LABEL_VERSION = 1, LABEL_CHAIN_ID2 = 2, LABEL_UNIVOCITY = 3, LABEL_LOG_ID = 4, LABEL_SIZE = 5, LABEL_ACCUMULATOR = 6, LABEL_BLOCK_NUMBER = 7, LABEL_BLOCK_HASH = 8, SNAPSHOT_VERSION = 1;
29751
30581
  var init_known_accumulator = __esm(() => {
29752
30582
  init_dist3();
29753
- init_dist8();
29754
30583
  init_dist9();
30584
+ init_dist10();
29755
30585
  init_parse_receipt();
29756
30586
  });
29757
30587
 
29758
30588
  // node_modules/@forestrie/receipt-verify/dist/index.js
29759
- var init_dist10 = __esm(() => {
30589
+ var init_dist11 = __esm(() => {
29760
30590
  init_parse_receipt();
29761
30591
  init_build_receipt_offline();
29762
30592
  init_freshen_receipt();
29763
- init_dist8();
30593
+ init_dist9();
29764
30594
  init_decode_trust_root_from_genesis();
30595
+ init_decode_chain_binding_from_genesis();
29765
30596
  init_verify_grant_receipt_offline();
29766
30597
  init_verify_grant_receipt_offline();
29767
30598
  init_verify_grant_receipt_offline();
@@ -29770,11 +30601,11 @@ var init_dist10 = __esm(() => {
29770
30601
  init_session_key_endorsement();
29771
30602
  init_verify_endorsed_leaf();
29772
30603
  init_decode_forestrie_grant_cose();
29773
- init_grant_codec2();
30604
+ init_grant_codec3();
29774
30605
  init_attach_transparent_statement_receipt();
29775
30606
  init_grant_commitment();
29776
30607
  init_find_grant_leaf();
29777
- init_dist8();
30608
+ init_dist9();
29778
30609
  init_checkpoint_chain();
29779
30610
  init_known_accumulator();
29780
30611
  });
@@ -29853,7 +30684,7 @@ async function deriveCheckpointReceipt(input) {
29853
30684
  }
29854
30685
  var CreateReceiptFailure;
29855
30686
  var init_create_receipt_derive = __esm(() => {
29856
- init_dist10();
30687
+ init_dist11();
29857
30688
  CreateReceiptFailure = class CreateReceiptFailure extends Error {
29858
30689
  stage;
29859
30690
  reason;
@@ -29951,8 +30782,8 @@ function errorMessage3(err) {
29951
30782
  }
29952
30783
  var CompleteGrantFailure;
29953
30784
  var init_complete_grant_derive = __esm(() => {
29954
- init_dist10();
29955
- init_dist6();
30785
+ init_dist11();
30786
+ init_dist7();
29956
30787
  init_register_grant_complete();
29957
30788
  init_create_receipt_derive();
29958
30789
  CompleteGrantFailure = class CompleteGrantFailure extends Error {
@@ -30210,7 +31041,7 @@ function loadCreateReceiptArtifacts(options) {
30210
31041
  return { massifBytes, checkpointBytes, leaf };
30211
31042
  }
30212
31043
  var init_create_receipt_inputs = __esm(() => {
30213
- init_dist10();
31044
+ init_dist11();
30214
31045
  });
30215
31046
 
30216
31047
  // src/lib/verify-inputs.ts
@@ -30246,7 +31077,7 @@ function decodeGrantBytes(bytes, entryId, source) {
30246
31077
  idtimestampBe8: entryId !== undefined ? entryIdHexToIdtimestampBe82(entryId) : decoded.idtimestampBe8
30247
31078
  };
30248
31079
  } catch {}
30249
- const grant = decodeGrantPayload2(bytes);
31080
+ const grant = decodeGrantPayload3(bytes);
30250
31081
  if (entryId === undefined) {
30251
31082
  throw new Error(`${source} is a raw grant payload (no embedded idtimestamp) — pass --entry-id`);
30252
31083
  }
@@ -30270,7 +31101,7 @@ function loadVerifyArtifacts(options) {
30270
31101
  return { genesisCbor, receiptCbor, grant, idtimestampBe8 };
30271
31102
  }
30272
31103
  var init_verify_inputs = __esm(() => {
30273
- init_dist10();
31104
+ init_dist11();
30274
31105
  });
30275
31106
 
30276
31107
  // src/lib/bytes.ts
@@ -30363,7 +31194,7 @@ function checkReceiptAnchoredToCheckpointChain(opts) {
30363
31194
  }
30364
31195
  var init_verify_checkpoint_chain = __esm(() => {
30365
31196
  init_dist3();
30366
- init_dist10();
31197
+ init_dist11();
30367
31198
  });
30368
31199
 
30369
31200
  // src/lib/verify-known-accumulator.ts
@@ -30442,7 +31273,7 @@ async function checkReceiptAnchoredToSnapshot(opts) {
30442
31273
  };
30443
31274
  }
30444
31275
  var init_verify_known_accumulator = __esm(() => {
30445
- init_dist10();
31276
+ init_dist11();
30446
31277
  });
30447
31278
 
30448
31279
  // src/lib/verify-anchored.ts
@@ -30604,10 +31435,10 @@ async function checkReceiptAnchored(opts) {
30604
31435
  }
30605
31436
  var LOG_STATE_SELECTOR = "0xeecac1b7";
30606
31437
  var init_verify_anchored = __esm(() => {
30607
- init_dist9();
30608
- init_dist3();
30609
- init_dist8();
30610
31438
  init_dist10();
31439
+ init_dist3();
31440
+ init_dist9();
31441
+ init_dist11();
30611
31442
  });
30612
31443
 
30613
31444
  // src/lib/verify-eventscan.ts
@@ -30708,7 +31539,7 @@ function selectPublishedAtBlock(published, atBlock) {
30708
31539
  }
30709
31540
  var CHECKPOINT_PUBLISHED_TOPIC0 = "0x156942b408823cb05a16027962ea485fa7171d99779ee04094280b2569482426";
30710
31541
  var init_verify_eventscan = __esm(() => {
30711
- init_dist9();
31542
+ init_dist10();
30712
31543
  init_verify_anchored();
30713
31544
  });
30714
31545
 
@@ -30751,7 +31582,8 @@ function decodePublishCheckpointCalldata(inputHex) {
30751
31582
  delegationKey: hexToBytes7(receipt.delegationProof.delegationKey),
30752
31583
  mmrStart: receipt.delegationProof.mmrStart,
30753
31584
  mmrEnd: receipt.delegationProof.mmrEnd,
30754
- signature: hexToBytes7(receipt.delegationProof.signature)
31585
+ signature: hexToBytes7(receipt.delegationProof.signature),
31586
+ algData: receipt.delegationProof.algData.map(hexToBytes7)
30755
31587
  }
30756
31588
  };
30757
31589
  }
@@ -30791,7 +31623,7 @@ var init_decode_checkpoint_calldata = __esm(() => {
30791
31623
  init__esm();
30792
31624
  PUBLISH_CHECKPOINT_ABI = parseAbi([
30793
31625
  "struct ConsistencyProof { uint64 treeSize1; uint64 treeSize2; bytes32[][] paths; bytes32[] rightPeaks; }",
30794
- "struct DelegationProof { bytes protectedHeader; bytes delegationKey; uint64 mmrStart; uint64 mmrEnd; bytes signature; }",
31626
+ "struct DelegationProof { bytes protectedHeader; bytes delegationKey; uint64 mmrStart; uint64 mmrEnd; bytes signature; bytes[] algData; }",
30795
31627
  "struct ConsistencyReceipt { bytes protectedHeader; bytes signature; ConsistencyProof[] consistencyProofs; DelegationProof delegationProof; }",
30796
31628
  "struct InclusionProof { uint64 index; bytes32[] path; }",
30797
31629
  "struct PublishGrant { bytes32 logId; uint256 grant; uint256 request; uint64 maxHeight; uint64 minGrowth; bytes32 ownerLogId; bytes grantData; }",
@@ -30817,7 +31649,7 @@ async function foldProofChain(proofs, opts = {}) {
30817
31649
  if (p.treeSize1 !== expectedBase) {
30818
31650
  throw new Error(`checkpoint chain is not contiguous at link ${i}: base ${p.treeSize1} != expected ${expectedBase}`);
30819
31651
  }
30820
- accumulator = await computeCheckpointAccumulator(p, accumulator);
31652
+ accumulator = await computeCheckpointAccumulator({ ...p, signedTreeSize2: p.treeSize2 }, accumulator, expectedBase);
30821
31653
  const link = {
30822
31654
  treeSize1: p.treeSize1,
30823
31655
  treeSize2: p.treeSize2,
@@ -30925,7 +31757,7 @@ async function calldataCheckpointChain(opts) {
30925
31757
  return links;
30926
31758
  }
30927
31759
  var init_checkpoint_provider = __esm(() => {
30928
- init_dist10();
31760
+ init_dist11();
30929
31761
  init_verify_eventscan();
30930
31762
  init_decode_checkpoint_calldata();
30931
31763
  });
@@ -30943,7 +31775,10 @@ async function emitFreshened(opts) {
30943
31775
  const result = await freshenReceipt({
30944
31776
  oldReceiptBytes: opts.oldReceiptBytes,
30945
31777
  leafValue: opts.leafValue,
30946
- consistencyProofs: opts.links.map((l) => l.proof),
31778
+ consistencyProofs: opts.links.map((l) => ({
31779
+ ...l.proof,
31780
+ signedTreeSize2: l.proof.treeSize2
31781
+ })),
30947
31782
  latestCheckpointBytes: opts.latestCheckpointBytes
30948
31783
  });
30949
31784
  let knownAccumulatorMatched;
@@ -31007,7 +31842,7 @@ async function freshenFromCalldataChain(opts) {
31007
31842
  });
31008
31843
  }
31009
31844
  var init_resolve_receipt_freshen = __esm(() => {
31010
- init_dist10();
31845
+ init_dist11();
31011
31846
  init_checkpoint_provider();
31012
31847
  init_verify_anchored();
31013
31848
  });
@@ -31095,7 +31930,7 @@ async function verifyChainAnchored(input, deps = defaultDeps) {
31095
31930
  }
31096
31931
  var ChainVerifyFailure, defaultDeps;
31097
31932
  var init_create_receipt_chain_verify = __esm(() => {
31098
- init_dist10();
31933
+ init_dist11();
31099
31934
  init_verify_anchored();
31100
31935
  ChainVerifyFailure = class ChainVerifyFailure extends Error {
31101
31936
  stage;
@@ -31441,7 +32276,7 @@ var CHAIN_EXIT_CODE, ERROR_CODES2, CHAIN_OUTCOME_NARRATION;
31441
32276
  var init_create_receipt = __esm(() => {
31442
32277
  init_create_receipt_derive();
31443
32278
  init_create_receipt_inputs();
31444
- init_dist10();
32279
+ init_dist11();
31445
32280
  init_verify_inputs();
31446
32281
  init_verify_checkpoint_chain();
31447
32282
  init_verify_known_accumulator();
@@ -31597,7 +32432,7 @@ __export(exports_resolve_receipt, {
31597
32432
  default: () => resolve_receipt_default
31598
32433
  });
31599
32434
  var resolve_receipt_default;
31600
- var init_resolve_receipt = __esm(() => {
32435
+ var init_resolve_receipt2 = __esm(() => {
31601
32436
  init_commoncli2();
31602
32437
  init_create_receipt();
31603
32438
  init_create_receipt2();
@@ -31854,7 +32689,7 @@ var init_decode_receipt_cbor = __esm(() => {
31854
32689
  function headerLabelInfo(label) {
31855
32690
  return HEADER_LABELS.get(label) ?? null;
31856
32691
  }
31857
- var COSE_SIGN1_TAG = 18, VERIFIABLE_PROOFS_LABEL = 396, VDS_LABEL = 395, CWT_CLAIMS_LABEL = 15, DELEGATION_CERT_LABEL3 = 1000, SEAL_PEAK_RECEIPTS_LABEL2 = -65931, PROOFS_INCLUSION_KEY = -1, PROOFS_CONSISTENCY_KEY = -2, HEADER_LABELS, ALG_NAMES, VDS_NAMES, CWT_CLAIM_NAMES, COSE_KEY_PARAM_NAMES, PROOF_KIND_NAMES;
32692
+ var COSE_SIGN1_TAG = 18, VERIFIABLE_PROOFS_LABEL = 396, VDS_LABEL = 395, CWT_CLAIMS_LABEL = 15, DELEGATION_CERT_LABEL3 = 1000, SEAL_PEAK_RECEIPTS_LABEL = -65931, TREE_SIZE_2_LABEL = -65933, PROOFS_INCLUSION_KEY = -1, PROOFS_CONSISTENCY_KEY = -2, HEADER_LABELS, ALG_NAMES, VDS_NAMES, CWT_CLAIM_NAMES, COSE_KEY_PARAM_NAMES, PROOF_KIND_NAMES;
31858
32693
  var init_decode_receipt_labels = __esm(() => {
31859
32694
  HEADER_LABELS = new Map([
31860
32695
  [1, { name: "alg" }],
@@ -31896,12 +32731,19 @@ var init_decode_receipt_labels = __esm(() => {
31896
32731
  }
31897
32732
  ],
31898
32733
  [
31899
- SEAL_PEAK_RECEIPTS_LABEL2,
32734
+ SEAL_PEAK_RECEIPTS_LABEL,
31900
32735
  {
31901
32736
  name: "pre-signed peak receipts",
31902
32737
  note: "forestrie SealPeakReceiptsLabel (checkpoint header)"
31903
32738
  }
31904
32739
  ],
32740
+ [
32741
+ TREE_SIZE_2_LABEL,
32742
+ {
32743
+ name: "tree-size-2",
32744
+ note: "forestrie: signed sealed size (ADR-0066 D1 as amended, checkpoint " + "protected header)"
32745
+ }
32746
+ ],
31905
32747
  [
31906
32748
  -66535,
31907
32749
  {
@@ -32101,7 +32943,7 @@ function decodeReceipt(receiptBytes) {
32101
32943
  byteLength: value.length,
32102
32944
  nestedCoseSign1: decodeCoseSign1(value) !== null
32103
32945
  };
32104
- } else if (label === SEAL_PEAK_RECEIPTS_LABEL2 && Array.isArray(value)) {
32946
+ } else if (label === SEAL_PEAK_RECEIPTS_LABEL && Array.isArray(value)) {
32105
32947
  peakReceipts = { count: value.length };
32106
32948
  }
32107
32949
  }
@@ -32136,7 +32978,7 @@ function decodeReceipt(receiptBytes) {
32136
32978
  }
32137
32979
  var DecodeReceiptError, HEX;
32138
32980
  var init_decode_receipt_decode = __esm(() => {
32139
- init_dist10();
32981
+ init_dist11();
32140
32982
  init_dist3();
32141
32983
  init_decode_receipt_cbor();
32142
32984
  init_decode_receipt_labels();
@@ -32227,7 +33069,7 @@ function unprotectedLines(entry, receipt, depth) {
32227
33069
  }
32228
33070
  ];
32229
33071
  }
32230
- if (entry.label === SEAL_PEAK_RECEIPTS_LABEL2 && receipt.unprotected.peakReceipts) {
33072
+ if (entry.label === SEAL_PEAK_RECEIPTS_LABEL && receipt.unprotected.peakReceipts) {
32231
33073
  return [
32232
33074
  {
32233
33075
  depth,
@@ -32530,7 +33372,7 @@ async function buildConsistencyProofArtifact(opts) {
32530
33372
  const proof = indexConsistencyProof(opts.get, opts.fromSize - 1n, opts.toSize - 1n);
32531
33373
  const accumulatorTo = peakMMRIndexes(opts.toSize - 1n).map(opts.get);
32532
33374
  const hasher = await createSyncHasher();
32533
- const check = await verifyConsistency(hasher, proof, accumulatorFrom, accumulatorTo);
33375
+ const check = await verifyConsistency(hasher, opts.fromSize, opts.toSize, accumulatorFrom, proof.paths, accumulatorTo);
32534
33376
  if (!check.ok) {
32535
33377
  throw new Error("self-verification failed: supplied massifs do not consistently cover the requested range");
32536
33378
  }
@@ -32573,11 +33415,7 @@ async function checkReceiptAnchoredViaConsistencyProof(opts) {
32573
33415
  };
32574
33416
  }
32575
33417
  const hasher = await createSyncHasher();
32576
- const check = await verifyConsistency(hasher, {
32577
- mmrSizeA: artifact.fromSize,
32578
- mmrSizeB: artifact.toSize,
32579
- paths: artifact.paths
32580
- }, artifact.accumulatorFrom, opts.trustedAccumulator);
33418
+ const check = await verifyConsistency(hasher, artifact.fromSize, artifact.toSize, artifact.accumulatorFrom, artifact.paths, opts.trustedAccumulator);
32581
33419
  if (!check.ok) {
32582
33420
  return {
32583
33421
  anchored: false,
@@ -32590,7 +33428,7 @@ async function checkReceiptAnchoredViaConsistencyProof(opts) {
32590
33428
  var LABEL_VERSION2 = 1, LABEL_FROM_SIZE = 2, LABEL_TO_SIZE = 3, LABEL_ACCUMULATOR_FROM = 4, LABEL_PATHS = 5, ARTIFACT_VERSION = 1;
32591
33429
  var init_consistency_proof = __esm(() => {
32592
33430
  init_dist3();
32593
- init_dist8();
33431
+ init_dist9();
32594
33432
  });
32595
33433
 
32596
33434
  // src/lib/verify-report.ts
@@ -33092,7 +33930,7 @@ async function runVerifyGrant(out, options) {
33092
33930
  }
33093
33931
  var VERIFY_ERROR_CODES;
33094
33932
  var init_verify = __esm(() => {
33095
- init_dist10();
33933
+ init_dist11();
33096
33934
  init_verify_eventscan();
33097
33935
  init_verify_anchored();
33098
33936
  init_verify_checkpoint_chain();
@@ -33500,7 +34338,7 @@ async function runFetchAccumulator(out, options) {
33500
34338
  }
33501
34339
  var LOG_STATE_SELECTOR2 = "0xeecac1b7";
33502
34340
  var init_fetch_accumulator = __esm(() => {
33503
- init_dist9();
34341
+ init_dist10();
33504
34342
  init_verify_anchored();
33505
34343
  init_verify_known_accumulator();
33506
34344
  init_verify_eventscan();
@@ -33721,7 +34559,7 @@ init_dist();
33721
34559
  // package.json
33722
34560
  var package_default = {
33723
34561
  name: "@forestrie/forestrie-cli",
33724
- version: "0.8.1",
34562
+ version: "0.9.1",
33725
34563
  description: "forestrie — participant CLI for forestrie transparency logs (SCITT / COSE receipts)",
33726
34564
  keywords: [
33727
34565
  "forestrie",
@@ -33785,15 +34623,15 @@ var package_default = {
33785
34623
  prepack: "bun run build"
33786
34624
  },
33787
34625
  dependencies: {
33788
- "@forestrie/chain-rpc": "^0.2.0",
34626
+ "@forestrie/chain-rpc": "^0.3.0",
33789
34627
  "@forestrie/cli-kit": "^0.1.1",
33790
- "@forestrie/delegation-cose": "^0.3.1",
34628
+ "@forestrie/delegation-cose": "^0.3.2",
33791
34629
  "@forestrie/deploy-core": "^0.7.1",
33792
- "@forestrie/encoding": "^0.7.0",
33793
- "@forestrie/grant-builder": "^0.4.1",
33794
- "@forestrie/merklelog": "^0.3.0",
33795
- "@forestrie/receipt-verify": "^1.0.0",
33796
- "@forestrie/scrapi-client": "^0.1.4",
34630
+ "@forestrie/encoding": "^0.8.0",
34631
+ "@forestrie/grant-builder": "^0.5.0",
34632
+ "@forestrie/merklelog": "^0.4.0",
34633
+ "@forestrie/receipt-verify": "^2.0.0",
34634
+ "@forestrie/scrapi-client": "^0.2.2",
33797
34635
  citty: "^0.2.2",
33798
34636
  viem: "^2.31.0"
33799
34637
  },
@@ -33822,8 +34660,8 @@ var command_default = defineForestrieCommand({
33822
34660
  "onboard-genesis": () => Promise.resolve().then(() => (init_onboard_genesis3(), exports_onboard_genesis)).then((m) => m.default),
33823
34661
  "onboard-request": () => Promise.resolve().then(() => (init_onboard_request3(), exports_onboard_request)).then((m) => m.default),
33824
34662
  "complete-grant": () => Promise.resolve().then(() => (init_complete_grant3(), exports_complete_grant)).then((m) => m.default),
33825
- "resolve-receipt": () => Promise.resolve().then(() => (init_resolve_receipt(), exports_resolve_receipt)).then((m) => m.default),
33826
- "create-receipt": () => Promise.resolve().then(() => (init_resolve_receipt(), exports_resolve_receipt)).then((m) => m.default),
34663
+ "resolve-receipt": () => Promise.resolve().then(() => (init_resolve_receipt2(), exports_resolve_receipt)).then((m) => m.default),
34664
+ "create-receipt": () => Promise.resolve().then(() => (init_resolve_receipt2(), exports_resolve_receipt)).then((m) => m.default),
33827
34665
  "decode-receipt": () => Promise.resolve().then(() => (init_decode_receipt3(), exports_decode_receipt)).then((m) => m.default),
33828
34666
  verify: () => Promise.resolve().then(() => (init_verify3(), exports_verify)).then((m) => m.default),
33829
34667
  "verify-grant": () => Promise.resolve().then(() => (init_verify_grant(), exports_verify_grant)).then((m) => m.default),