@charter-agreement-protocol/verifier 0.3.0 → 0.4.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/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # Changelog
2
+
3
+ All notable public changes to `@charter-agreement-protocol/verifier` are
4
+ documented here.
5
+
6
+ ## [0.4.0] — 2026-09-17
7
+
8
+ ### Added
9
+
10
+ - The producer surface (the Elixir reference `SigningInput`, now fully
11
+ aligned): `descriptorSigningInput` / `receiptSigningInput` (build-only),
12
+ `acceptanceSigningInput` / `terminationSigningInput` (set-aware: build
13
+ first, then the R1–R3 refusal checks at the reference ordering), and
14
+ `assembleCompact` (registry-row length, framing re-decode, size gate).
15
+ Holder-side signers sign through these — exactly one producer
16
+ implementation.
17
+ - `governingRevision(chainInput, at)` — the certified governing semantics
18
+ as a public query (a digest, or `contested`/`none`).
19
+ - `decodeCharterRevision` / `revisionDigest` and
20
+ `decodePartyDescriptor` / `descriptorDigest` — the decode/digest pairs
21
+ over the certified internals.
22
+
23
+ ### Fixed
24
+
25
+ - Never-throw hardening across the new surface: non-JSON claims values
26
+ (the reference `tagged/1` walk) and non-object views return typed codes;
27
+ `assembleCompact` validates the signing-input struct (message must be
28
+ the exact protected/payload framing); `decodePartyDescriptor` binds the
29
+ `cap+party` typ.
30
+
31
+ ## [0.3.0] — 2026-09-17
32
+
33
+ ### Added
34
+
35
+ - The honest-signer refusal checks as a public surface:
36
+ `acceptanceRefusal` / `terminationRefusal` (R1 claims-truth, R2
37
+ no-equivocation, R3 ancestry/governing coverage) over the caller's own
38
+ verified view, and `checkSigningClaims` — the producer build gate's
39
+ claims half (the reference `decode_for_signing`), shared with the verify
40
+ paths. `verifyChain` facts grow the verified `acceptances`.
41
+
42
+ ## [0.2.0] — 2026-09-16
43
+
44
+ ### Added
45
+
46
+ - The artifact-level verification API: `verifyDescriptor`,
47
+ `verifyDescriptorChain`, `verifyAcceptance`, `verifyTermination`,
48
+ `verifyChain`, `verifyReceipt`, `decodeArtifact`, `verifySignature`,
49
+ plus the registry/emission/digest primitives.
50
+
51
+ ## [0.1.x] — 2026-09-15
52
+
53
+ - Initial public releases under the `charter-agreement-protocol` npm
54
+ organization: corpus report machinery, canonical JSON, strict I-JSON
55
+ decode, self-check battery, the `cap-verifier` CLI, and the
56
+ `./package.json` export for consumer corpus-path resolution.
package/NOTICE CHANGED
@@ -1,4 +1,10 @@
1
- charter_agreement_protocol
1
+ Charter Agreement Protocol Verifier (TypeScript)
2
2
  Copyright 2026 BaseLabs
3
3
 
4
- This product includes software developed by BaseLabs.
4
+ This product includes software developed by BaseLabs
5
+ (https://github.com/baselabs).
6
+
7
+ The certified conformance corpus vendored in this package is certified
8
+ against the Elixir reference implementation, charter_agreement_protocol
9
+ (https://github.com/baselabs/charter_agreement_protocol); no Elixir code
10
+ is included or required at runtime.
package/README.md CHANGED
@@ -66,6 +66,12 @@ cannot verify green.
66
66
  | `verifyChain(chainInput)` / `verifyReceipt(compact, chainInput)` | Full chain-view verification (facts include the accepted/superseded topology and the verified acceptances); receipt verification against the verified chain |
67
67
  | `checkSigningClaims(kind, claims)` | The producer build gate's claims half (the reference `decode_for_signing`): the claims-only schema checks per kind — `descriptor \| acceptance \| termination \| receipt` — shared with the verify paths; holder-side signers run it before any key is used |
68
68
  | `decodeArtifact(compact)` / `verifySignature(message, signature, publicKey, alg)` | Framing-level decode (the holder-side provisional check) and the strict wrong-key guard primitive |
69
+ | `descriptorSigningInput(kid, claims, alg?)` / `receiptSigningInput(kid, claims, alg?)` | The build-only producers: the exact RFC 7515 signing input per kind (emission pair gated, claims schema gated, provisional decode) — no key, no signature |
70
+ | `acceptanceSigningInput(kid, claims, chainInput, alg?)` / `terminationSigningInput(kid, claims, chainInput, alg?)` | The set-aware producers: build first, then the R1–R3 refusal checks at the reference ordering |
71
+ | `assembleCompact(signingInput, signature)` | Assemble a validated signing input and its exact raw signature (registry-row length, framing re-decode, size gate) |
72
+ | `governingRevision(chainInput, at)` | The unique governing revision at one UTC instant — a digest, or `contested`/`none`, over the certified chain semantics |
73
+ | `decodeCharterRevision(text)` / `revisionDigest(text)` | Decode one canonical unsigned Charter Revision (claims + content digest over the exact text bytes) |
74
+ | `decodePartyDescriptor(compact)` / `descriptorDigest(compact)` | Decode one Party Descriptor's claims and digest without verifying its signature |
69
75
  | `acceptanceRefusal(claims, chainInput)` / `terminationRefusal(claims, chainInput)` | The honest-signer refusal checks (R1–R3: claims-truth, no-equivocation, ancestry/governing coverage) over the caller's own view — `{ok: true}`, or `signing_refused` / `chain_invalid` / `signing_input_invalid`. Holder-side signers run these before any key is used; the rule that fired is deliberately not surfaced |
70
76
 
71
77
  ## Evidence
@@ -81,12 +87,23 @@ cannot verify green.
81
87
  - **This package never publishes verdict claims that were not recomputed
82
88
  from raw bytes.**
83
89
 
84
- ## Organization namespace
90
+ ## The sibling signer
85
91
 
86
- The `charter-agreement-protocol` npm organization hosts this protocol family's
87
- TypeScript packages: `@charter-agreement-protocol/verifier` (this package) and
88
- `@charter-agreement-protocol/signer` (reserved for the holder-side companion
89
- signer's TypeScript package).
92
+ The `charter-agreement-protocol` npm organization hosts this protocol
93
+ family's two independent TypeScript packages — no Elixir code or dependency
94
+ at runtime; the Elixir reference is the certification oracle (this
95
+ package's vendored corpus is certified against it, and its CI
96
+ cross-verifies TypeScript-signed artifacts from raw bytes):
97
+
98
+ - **This package** — `@charter-agreement-protocol/verifier`: verification
99
+ and the pure producer surface (signing inputs, refusal guards, assembly).
100
+ - [`@charter-agreement-protocol/signer`](https://www.npmjs.com/package/@charter-agreement-protocol/signer)
101
+ — the holder-side companion: key custody, the wrong-key guard, and
102
+ post-sign verification, delegating all protocol logic here.
103
+
104
+ The pair releases together: the signer depends on this package, so a
105
+ verifier release stages first and the signer locks and releases against
106
+ the published version immediately after.
90
107
 
91
108
  ## SemVer
92
109
 
package/dist/core.d.ts CHANGED
@@ -136,6 +136,67 @@ export declare function checkSigningClaims(kind: "descriptor" | "acceptance" | "
136
136
  ok: false;
137
137
  code: string;
138
138
  };
139
+ export declare function governingRevision(chainInput: AnyRecord, at: string): {
140
+ ok: true;
141
+ governing: string;
142
+ } | {
143
+ ok: false;
144
+ code: string;
145
+ };
146
+ export declare function decodeCharterRevision(text: unknown): {
147
+ ok: true;
148
+ revision: AnyRecord;
149
+ digest: string;
150
+ } | {
151
+ ok: false;
152
+ code: string;
153
+ };
154
+ export declare function revisionDigest(text: unknown): {
155
+ ok: true;
156
+ digest: string;
157
+ } | {
158
+ ok: false;
159
+ code: string;
160
+ };
161
+ export declare function decodePartyDescriptor(compact: unknown): {
162
+ ok: true;
163
+ claims: AnyRecord;
164
+ digest: string;
165
+ } | {
166
+ ok: false;
167
+ code: string;
168
+ };
169
+ export declare function descriptorDigest(compact: unknown): {
170
+ ok: true;
171
+ digest: string;
172
+ } | {
173
+ ok: false;
174
+ code: string;
175
+ };
176
+ export type SigningInput = {
177
+ alg: string;
178
+ protectedSegment: string;
179
+ payloadSegment: string;
180
+ message: Buffer;
181
+ };
182
+ export type ProducerResult = {
183
+ ok: true;
184
+ input: SigningInput;
185
+ } | {
186
+ ok: false;
187
+ code: string;
188
+ };
189
+ export declare function descriptorSigningInput(kid: string, claims: AnyRecord, algorithm?: string): ProducerResult;
190
+ export declare function receiptSigningInput(kid: string, claims: AnyRecord, algorithm?: string): ProducerResult;
191
+ export declare function acceptanceSigningInput(kid: string, claims: AnyRecord, chainInput: AnyRecord, algorithm?: string): ProducerResult;
192
+ export declare function terminationSigningInput(kid: string, claims: AnyRecord, chainInput: AnyRecord, algorithm?: string): ProducerResult;
193
+ export declare function assembleCompact(input: SigningInput, signature: Buffer): {
194
+ ok: true;
195
+ compact: string;
196
+ } | {
197
+ ok: false;
198
+ code: string;
199
+ };
139
200
  export type RefusalResult = {
140
201
  ok: true;
141
202
  } | {
package/dist/core.js CHANGED
@@ -1456,6 +1456,184 @@ function descriptorClaimsError(payload) {
1456
1456
  return "descriptor_invalid";
1457
1457
  return null;
1458
1458
  }
1459
+ // ---------------------------------------------------------------------------
1460
+ // The query/decode surface: the reference's governing-revision computation
1461
+ // and the revision/descriptor decode+digest pairs, over the same certified
1462
+ // internals the verify paths use. Every export fails closed with typed
1463
+ // codes; none of them verifies signatures.
1464
+ // ---------------------------------------------------------------------------
1465
+ // The unique governing revision in a verified view at one UTC instant -
1466
+ // a digest, or "contested"/"none" (never silently resolved).
1467
+ export function governingRevision(chainInput, at) {
1468
+ const instant = typeof at === "string" ? parseTimestamp(at) : null;
1469
+ if (!instant)
1470
+ return { ok: false, code: "invalid_type" };
1471
+ if (!chainInput || typeof chainInput !== "object" || Array.isArray(chainInput)) {
1472
+ return { ok: false, code: "signing_input_invalid" };
1473
+ }
1474
+ const chain = chainFromInput(chainInput);
1475
+ if (!chain.ok)
1476
+ return { ok: false, code: "chain_invalid" };
1477
+ return { ok: true, governing: governing(chain.value, instant) };
1478
+ }
1479
+ // Decode one canonical unsigned Charter Revision: the parsed claims plus
1480
+ // its content digest, computed over the exact text bytes.
1481
+ export function decodeCharterRevision(text) {
1482
+ const revision = revisionFromText(text);
1483
+ if (!revision.ok)
1484
+ return { ok: false, code: revision.code };
1485
+ return { ok: true, revision: revision.value.value, digest: revision.value.digest };
1486
+ }
1487
+ export function revisionDigest(text) {
1488
+ const revision = decodeCharterRevision(text);
1489
+ if (!revision.ok)
1490
+ return revision;
1491
+ return { ok: true, digest: revision.digest };
1492
+ }
1493
+ // Decode one Party Descriptor's claims without verifying its signature -
1494
+ // the framing, the descriptor schema, and the content digest.
1495
+ export function decodePartyDescriptor(compact) {
1496
+ const decoded = decodeJws(compact);
1497
+ if (!decoded.ok)
1498
+ return { ok: false, code: decoded.code };
1499
+ if (decoded.value.header.typ !== "cap+party")
1500
+ return { ok: false, code: "descriptor_invalid" };
1501
+ const claimsError = descriptorClaimsError(decoded.value.payload);
1502
+ if (claimsError)
1503
+ return { ok: false, code: claimsError };
1504
+ return { ok: true, claims: decoded.value.payload, digest: taggedHash("party_descriptor_content", decoded.value.payloadBytes) };
1505
+ }
1506
+ export function descriptorDigest(compact) {
1507
+ const decoded = decodePartyDescriptor(compact);
1508
+ if (!decoded.ok)
1509
+ return decoded;
1510
+ return { ok: true, digest: decoded.digest };
1511
+ }
1512
+ const PRODUCER_TYPES = {
1513
+ descriptor: "cap+party",
1514
+ acceptance: "cap+acceptance",
1515
+ termination: "cap+termination",
1516
+ receipt: "cap+receipt",
1517
+ };
1518
+ // The reference producer's tagged/1: claims must be pure JSON values -
1519
+ // undefined, functions, symbols, bigints, and non-finite numbers get the
1520
+ // typed producer code, never a canonicalization throw.
1521
+ function jsonValueError(value) {
1522
+ if (value === null)
1523
+ return false;
1524
+ const type = typeof value;
1525
+ if (type === "string" || type === "boolean")
1526
+ return false;
1527
+ if (type === "number")
1528
+ return !Number.isFinite(value);
1529
+ if (type !== "object")
1530
+ return true;
1531
+ if (Array.isArray(value))
1532
+ return value.some(jsonValueError);
1533
+ if (Buffer.isBuffer(value))
1534
+ return true;
1535
+ return Object.values(value).some(jsonValueError);
1536
+ }
1537
+ // The shared build path: algorithm -> claims shape/JSON values -> emission
1538
+ // binding -> kid -> framing -> size gate -> claims schema -> provisional
1539
+ // decode (the reference producer's exact ordering, so error precedence
1540
+ // matches too).
1541
+ function buildSigningInput(kind, kid, claims, algorithm) {
1542
+ if (typeof algorithm === "undefined" || algorithm === null)
1543
+ algorithm = defaultEmissionName();
1544
+ if (typeof algorithm !== "string" || !(algorithm in emissions())) {
1545
+ return { ok: false, code: "algorithm_unsupported" };
1546
+ }
1547
+ if (!claims || typeof claims !== "object" || Array.isArray(claims)) {
1548
+ return { ok: false, code: "invalid_type" };
1549
+ }
1550
+ const record = claims;
1551
+ if (jsonValueError(record))
1552
+ return { ok: false, code: "signing_input_invalid" };
1553
+ const revision = record.protocol_revision;
1554
+ if (typeof revision !== "number" || !Number.isInteger(revision) || revision !== emissions()[algorithm]) {
1555
+ return { ok: false, code: "signing_input_invalid" };
1556
+ }
1557
+ if (typeof kid !== "string" || kid.length === 0 || kid.length > 128 || !/^[A-Za-z0-9._~-]+$/.test(kid)) {
1558
+ return { ok: false, code: "signing_input_invalid" };
1559
+ }
1560
+ const row = ALG_ROWS.find((one) => one.name === algorithm);
1561
+ if (!row)
1562
+ return { ok: false, code: "algorithm_unsupported" };
1563
+ const payloadSegment = encodeBase64url(Buffer.from(canonical(record), "utf8"));
1564
+ const protectedSegment = encodeBase64url(Buffer.from(canonical({ alg: algorithm, kid, typ: PRODUCER_TYPES[kind] }), "utf8"));
1565
+ const message = Buffer.from(`${protectedSegment}.${payloadSegment}`, "utf8");
1566
+ const signatureSegmentLength = Math.ceil((row.signatureBytes * 4) / 3);
1567
+ if (message.length + 1 + signatureSegmentLength > JSON_DEFAULT_LIMITS.max_bytes) {
1568
+ return { ok: false, code: "signing_input_invalid" };
1569
+ }
1570
+ // The reference build's decode step: the claims schema gate runs inside
1571
+ // the producer, after framing and size - the same precedence as
1572
+ // decode_for_signing inside the Elixir build pipeline.
1573
+ const claimsGate = checkSigningClaims(kind, record);
1574
+ if (!claimsGate.ok)
1575
+ return { ok: false, code: claimsGate.code };
1576
+ // The provisional check: a zero signature at the row's exact length must
1577
+ // frame and bind.
1578
+ const zeroSignature = Buffer.alloc(row.signatureBytes);
1579
+ const provisional = `${protectedSegment}.${payloadSegment}.${encodeBase64url(zeroSignature)}`;
1580
+ const decoded = decodeArtifact(provisional);
1581
+ if (!decoded.ok)
1582
+ return { ok: false, code: "signing_input_invalid" };
1583
+ return { ok: true, input: { alg: algorithm, protectedSegment, payloadSegment, message } };
1584
+ }
1585
+ export function descriptorSigningInput(kid, claims, algorithm) {
1586
+ return buildSigningInput("descriptor", kid, claims, algorithm);
1587
+ }
1588
+ export function receiptSigningInput(kid, claims, algorithm) {
1589
+ return buildSigningInput("receipt", kid, claims, algorithm);
1590
+ }
1591
+ // The reference producer ordering: build (shape, emission binding, framing,
1592
+ // claims schema) FIRST, then the set-aware R1-R3 refusal checks - so a
1593
+ // claims defect reports the producer code even when the view is also bad.
1594
+ export function acceptanceSigningInput(kid, claims, chainInput, algorithm) {
1595
+ const built = buildSigningInput("acceptance", kid, claims, algorithm);
1596
+ if (!built.ok)
1597
+ return built;
1598
+ const refusal = acceptanceRefusal(claims, chainInput);
1599
+ if (!refusal.ok)
1600
+ return { ok: false, code: refusal.code };
1601
+ return built;
1602
+ }
1603
+ export function terminationSigningInput(kid, claims, chainInput, algorithm) {
1604
+ const built = buildSigningInput("termination", kid, claims, algorithm);
1605
+ if (!built.ok)
1606
+ return built;
1607
+ const refusal = terminationRefusal(claims, chainInput);
1608
+ if (!refusal.ok)
1609
+ return { ok: false, code: refusal.code };
1610
+ return built;
1611
+ }
1612
+ // Assemble a validated signing input and its exact raw signature (the
1613
+ // reference assemble): registry-row length, framing re-decode, size gate.
1614
+ export function assembleCompact(input, signature) {
1615
+ if (!input || typeof input !== "object" || !Buffer.isBuffer(signature))
1616
+ return { ok: false, code: "invalid_type" };
1617
+ // The input is a struct the producer minted: the message must BE the
1618
+ // protected/payload framing (a caller-modified copy is invalid, never
1619
+ // silently assembled).
1620
+ if (typeof input.protectedSegment !== "string" || typeof input.payloadSegment !== "string" ||
1621
+ !Buffer.isBuffer(input.message) || input.message.toString("utf8") !== `${input.protectedSegment}.${input.payloadSegment}`) {
1622
+ return { ok: false, code: "signing_input_invalid" };
1623
+ }
1624
+ const row = ALG_ROWS.find((one) => one.name === input.alg);
1625
+ if (!row)
1626
+ return { ok: false, code: "algorithm_unsupported" };
1627
+ if (signature.length !== row.signatureBytes)
1628
+ return { ok: false, code: "signature_invalid" };
1629
+ const compact = `${input.message.toString("utf8")}.${encodeBase64url(signature)}`;
1630
+ if (Buffer.byteLength(compact) > JSON_DEFAULT_LIMITS.max_bytes)
1631
+ return { ok: false, code: "signing_input_invalid" };
1632
+ const decoded = decodeArtifact(compact);
1633
+ if (!decoded.ok)
1634
+ return { ok: false, code: "signing_input_invalid" };
1635
+ return { ok: true, compact };
1636
+ }
1459
1637
  function refused() {
1460
1638
  return { ok: false, code: "signing_refused" };
1461
1639
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { canonical, loadCorpus, reportFor, selfChecks, decodeJsonText, jsonProjection, type CanonicalValue, type Projection, type DecodeResult, type CaseResult, type CorpusFile, type CorpusIndex, type ConformanceCase, type LoadedCorpus, type CaseOutcome, type ConformanceReport, type ReportOutput, } from "./core.ts";
2
- export { CERTIFIED_INDEX_SHA256_BASE64URL, CERTIFIED_REGISTRY_DIGEST, algorithmRegistry, emissions, defaultEmissionName, encodeBase64url, taggedDigest, decodeArtifact, verifySignature, verifyDescriptor, verifyDescriptorChain, verifyAcceptance, verifyTermination, verifyChain, verifyReceipt, acceptanceRefusal, checkSigningClaims, terminationRefusal, type AlgRow, type VerifyResult, type RefusalResult, } from "./core.ts";
2
+ export { CERTIFIED_INDEX_SHA256_BASE64URL, CERTIFIED_REGISTRY_DIGEST, algorithmRegistry, emissions, defaultEmissionName, encodeBase64url, taggedDigest, decodeArtifact, verifySignature, verifyDescriptor, verifyDescriptorChain, verifyAcceptance, verifyTermination, verifyChain, verifyReceipt, acceptanceRefusal, checkSigningClaims, terminationRefusal, descriptorSigningInput, receiptSigningInput, acceptanceSigningInput, terminationSigningInput, assembleCompact, governingRevision, decodeCharterRevision, revisionDigest, decodePartyDescriptor, descriptorDigest, type SigningInput, type ProducerResult, type AlgRow, type VerifyResult, type RefusalResult, } from "./core.ts";
package/dist/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  // CAP never authorizes.
2
2
  //
3
- // The public surface of the independent TypeScript verifier: report over a
4
- // certified conformance corpus, canonical JSON, the strict I-JSON decoder,
5
- // and the self-check battery. Every verdict traces to corpus agreement with
6
- // the Elixir reference implementation, recomputed from raw bytes.
3
+ // The public surface of the independent TypeScript verifier: the corpus
4
+ // report machinery (canonical JSON, the strict I-JSON decoder, the
5
+ // self-check battery), artifact-level verification (descriptor, chain,
6
+ // acceptance, termination, receipt, full chain views), the governing/
7
+ // decode/ digest queries, the honest-signer refusal checks, and the pure
8
+ // producer surface (signing inputs per kind, assembly). Every verdict
9
+ // traces to corpus agreement with the Elixir reference implementation,
10
+ // recomputed from raw bytes.
7
11
  export { canonical, loadCorpus, reportFor, selfChecks, decodeJsonText, jsonProjection, } from "./core.js";
8
- export { CERTIFIED_INDEX_SHA256_BASE64URL, CERTIFIED_REGISTRY_DIGEST, algorithmRegistry, emissions, defaultEmissionName, encodeBase64url, taggedDigest, decodeArtifact, verifySignature, verifyDescriptor, verifyDescriptorChain, verifyAcceptance, verifyTermination, verifyChain, verifyReceipt, acceptanceRefusal, checkSigningClaims, terminationRefusal, } from "./core.js";
12
+ export { CERTIFIED_INDEX_SHA256_BASE64URL, CERTIFIED_REGISTRY_DIGEST, algorithmRegistry, emissions, defaultEmissionName, encodeBase64url, taggedDigest, decodeArtifact, verifySignature, verifyDescriptor, verifyDescriptorChain, verifyAcceptance, verifyTermination, verifyChain, verifyReceipt, acceptanceRefusal, checkSigningClaims, terminationRefusal, descriptorSigningInput, receiptSigningInput, acceptanceSigningInput, terminationSigningInput, assembleCompact, governingRevision, decodeCharterRevision, revisionDigest, decodePartyDescriptor, descriptorDigest, } from "./core.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charter-agreement-protocol/verifier",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Independent TypeScript verifier for the Charter Agreement Protocol (CAP) — byte-exact, offline re-verification of signed charter evidence. CAP verifies; it never authorizes.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "files": [
21
21
  "dist",
22
+ "CHANGELOG.md",
22
23
  "conformance",
23
24
  "LICENSE",
24
25
  "NOTICE",