@charter-agreement-protocol/verifier 0.1.2 → 0.2.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/core.d.ts CHANGED
@@ -93,10 +93,41 @@ type Result<T> = {
93
93
  ok: false;
94
94
  code: string;
95
95
  };
96
+ type AnyRecord = Record<string, any>;
96
97
  export declare function canonical(value: CanonicalValue): string;
97
98
  export declare function decodeJsonText(text: string): Result<CanonicalValue>;
98
99
  export declare function jsonProjection(value: any): Projection;
99
100
  export declare function loadCorpus(root: string): LoadedCorpus;
100
101
  export declare function reportFor(root: string): ReportOutput;
101
102
  export declare function selfChecks(): void;
103
+ export type AlgRow = {
104
+ name: string;
105
+ minProtocolRevision: number;
106
+ keyAlgorithm: string;
107
+ publicKeyBytes: number;
108
+ signatureBytes: number;
109
+ };
110
+ export type VerifyResult = {
111
+ ok: true;
112
+ facts: AnyRecord;
113
+ } | {
114
+ ok: false;
115
+ code: string;
116
+ };
117
+ export declare function algorithmRegistry(): AlgRow[];
118
+ export declare function emissions(): Record<string, number>;
119
+ export declare function encodeBase64url(bytes: Buffer): string;
120
+ export declare function taggedDigest(domain: string, bytes: Buffer): string;
121
+ export declare function defaultEmissionName(): string;
122
+ export declare function decodeArtifact(compact: string): VerifyResult;
123
+ export declare function verifySignature(message: Buffer, signature: Buffer, publicKeyBase64url: string, alg: string): boolean;
124
+ export declare function verifyDescriptor(compact: string, predecessor?: {
125
+ digest: string;
126
+ claims: AnyRecord;
127
+ } | null): VerifyResult;
128
+ export declare function verifyDescriptorChain(compacts: string[]): VerifyResult;
129
+ export declare function verifyAcceptance(compact: string, revisionText: string, descriptorCompacts: string[]): VerifyResult;
130
+ export declare function verifyTermination(compact: string, revisionText: string, descriptorCompacts: string[]): VerifyResult;
131
+ export declare function verifyChain(chainInput: AnyRecord): VerifyResult;
132
+ export declare function verifyReceipt(compact: string, chainInput: AnyRecord): VerifyResult;
102
133
  export {};
package/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createHash, createPublicKey, verify as verifySignature } from "node:crypto";
1
+ import { createHash, createPublicKey, verify as nodeVerifySignature } from "node:crypto";
2
2
  import { lstatSync, readFileSync, readdirSync } from "node:fs";
3
3
  import { join, relative, sep } from "node:path";
4
4
  const INDEX_FORMAT = "charter-agreement-protocol-conformance-corpus-index";
@@ -442,7 +442,7 @@ function ed25519(rawKey, message, signature) {
442
442
  return false;
443
443
  const prefix = Buffer.from("302a300506032b6570032100", "hex");
444
444
  const spki = createPublicKey({ key: Buffer.concat([prefix, key]), format: "der", type: "spki" });
445
- return verifySignature(null, message, spki, signature);
445
+ return nodeVerifySignature(null, message, spki, signature);
446
446
  }
447
447
  catch (_error) {
448
448
  return false;
@@ -461,7 +461,7 @@ function mldsa(keyAlgorithm, rawKey, message, signature) {
461
461
  if (!prefix || !signature || signature.length === 0)
462
462
  return false;
463
463
  const spki = createPublicKey({ key: Buffer.concat([prefix, key]), format: "der", type: "spki" });
464
- return verifySignature(null, message, spki, signature);
464
+ return nodeVerifySignature(null, message, spki, signature);
465
465
  }
466
466
  catch (_error) {
467
467
  return false;
@@ -1294,3 +1294,106 @@ export function selfChecks() {
1294
1294
  throw new Error("compiled limit maximums drifted");
1295
1295
  }
1296
1296
  }
1297
+ export function algorithmRegistry() {
1298
+ return ALG_ROWS.map((row) => ({ ...row }));
1299
+ }
1300
+ export function emissions() {
1301
+ return { Ed25519: 2, "ML-DSA-65": 3 };
1302
+ }
1303
+ export function encodeBase64url(bytes) {
1304
+ return bytes.toString("base64url");
1305
+ }
1306
+ export function taggedDigest(domain, bytes) {
1307
+ return taggedHash(domain, bytes);
1308
+ }
1309
+ export function defaultEmissionName() {
1310
+ return "Ed25519";
1311
+ }
1312
+ // Framing-level decode: canonical protected header and payload, registry
1313
+ // binding, per-row signature length — everything about an artifact except
1314
+ // its cryptographic verification. Holder-side producers use this as the
1315
+ // provisional check on a zero-signature framing before any key is touched.
1316
+ export function decodeArtifact(compact) {
1317
+ const decoded = decodeJws(compact);
1318
+ if (!decoded.ok)
1319
+ return { ok: false, code: decoded.code };
1320
+ const { header, payload } = decoded.value;
1321
+ return { ok: true, facts: { alg: header.alg, kid: header.kid, typ: header.typ, payload } };
1322
+ }
1323
+ // Strict signature verification over exact bytes with a base64url public
1324
+ // key under the registry row for `alg` — the wrong-key guard primitive.
1325
+ export function verifySignature(message, signature, publicKeyBase64url, alg) {
1326
+ const row = ALG_ROWS.find((one) => one.name === alg);
1327
+ if (!row)
1328
+ return false;
1329
+ const key = Buffer.from(publicKeyBase64url, "base64url");
1330
+ if (key.length !== row.publicKeyBytes)
1331
+ return false;
1332
+ if (row.keyAlgorithm === "Ed25519")
1333
+ return ed25519(publicKeyBase64url, message, signature);
1334
+ return mldsa(row.keyAlgorithm, publicKeyBase64url, message, signature);
1335
+ }
1336
+ export function verifyDescriptor(compact, predecessor = null) {
1337
+ const verified = descriptorFromCompact(compact, predecessor ? { digest: predecessor.digest, payload: predecessor.claims } : null);
1338
+ if (!verified.ok)
1339
+ return { ok: false, code: verified.code };
1340
+ const one = verified.value;
1341
+ return {
1342
+ ok: true,
1343
+ facts: {
1344
+ descriptor_digest: one.digest,
1345
+ party_id: one.digest,
1346
+ descriptor_number: one.payload.descriptor_number,
1347
+ protocol_revision: one.payload.protocol_revision,
1348
+ },
1349
+ };
1350
+ }
1351
+ export function verifyDescriptorChain(compacts) {
1352
+ const verified = descriptorChain(compacts);
1353
+ if (!verified.ok)
1354
+ return { ok: false, code: verified.code };
1355
+ return { ok: true, facts: verified.value };
1356
+ }
1357
+ export function verifyAcceptance(compact, revisionText, descriptorCompacts) {
1358
+ const revision = revisionFromText(revisionText);
1359
+ const chain = descriptorChain(descriptorCompacts);
1360
+ if (!revision.ok || !chain.ok)
1361
+ return { ok: false, code: "acceptance_invalid" };
1362
+ const verified = acceptanceFromCompact(compact, revision.value, chain.value);
1363
+ if (!verified.ok)
1364
+ return { ok: false, code: verified.code };
1365
+ return { ok: true, facts: { acceptance_digest: verified.value.digest, claims: verified.value.claims, descriptor_position: verified.value.descriptorPosition } };
1366
+ }
1367
+ export function verifyTermination(compact, revisionText, descriptorCompacts) {
1368
+ const revision = revisionFromText(revisionText);
1369
+ const chain = descriptorChain(descriptorCompacts);
1370
+ if (!revision.ok || !chain.ok)
1371
+ return { ok: false, code: "termination_invalid" };
1372
+ const verified = terminationFromCompact(compact, revision.value, chain.value);
1373
+ if (!verified.ok)
1374
+ return { ok: false, code: verified.code };
1375
+ return { ok: true, facts: { termination_digest: verified.value.digest, claims: verified.value.claims, descriptor_position: verified.value.descriptorPosition } };
1376
+ }
1377
+ export function verifyChain(chainInput) {
1378
+ const verified = chainFromInput(chainInput);
1379
+ if (!verified.ok)
1380
+ return { ok: false, code: verified.code };
1381
+ return { ok: true, facts: verified.value };
1382
+ }
1383
+ export function verifyReceipt(compact, chainInput) {
1384
+ const chain = chainFromInput(chainInput);
1385
+ if (!chain.ok)
1386
+ return { ok: false, code: "receipt_invalid" };
1387
+ const verified = receiptFromCompact(compact, chain.value);
1388
+ if (!verified.ok)
1389
+ return { ok: false, code: verified.code };
1390
+ return {
1391
+ ok: true,
1392
+ facts: {
1393
+ receipt_digest: verified.value.digest,
1394
+ claims: verified.value.claims,
1395
+ governing_match: verified.value.governingMatch,
1396
+ chain_conflict: verified.value.chainConflict,
1397
+ },
1398
+ };
1399
+ }
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 } 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, type AlgRow, type VerifyResult, } from "./core.ts";
package/dist/index.js CHANGED
@@ -5,4 +5,4 @@
5
5
  // and the self-check battery. Every verdict traces to corpus agreement with
6
6
  // the Elixir reference implementation, recomputed from raw bytes.
7
7
  export { canonical, loadCorpus, reportFor, selfChecks, decodeJsonText, jsonProjection, } from "./core.js";
8
- export { CERTIFIED_INDEX_SHA256_BASE64URL, CERTIFIED_REGISTRY_DIGEST } 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, } from "./core.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charter-agreement-protocol/verifier",
3
- "version": "0.1.2",
3
+ "version": "0.2.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",
@@ -31,7 +31,7 @@
31
31
  "build": "tsc -p tsconfig.build.json",
32
32
  "typecheck": "tsc --noEmit",
33
33
  "self-checks": "node --experimental-strip-types --no-warnings self-checks.ts",
34
- "test": "node --test --experimental-strip-types --no-warnings verifier.test.ts",
34
+ "test": "node --test --experimental-strip-types --no-warnings verifier.test.ts api.test.ts",
35
35
  "conformance": "node --experimental-strip-types --no-warnings cli.ts",
36
36
  "prepack": "npm run build"
37
37
  },