@hol-org/cigar 0.9.4

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.
Files changed (78) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +68 -0
  4. package/dist/client.d.ts +16 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +839 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/digest.d.ts +21 -0
  9. package/dist/digest.d.ts.map +1 -0
  10. package/dist/digest.js +406 -0
  11. package/dist/digest.js.map +1 -0
  12. package/dist/errors.d.ts +35 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +54 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/examples/quickstart.d.ts +2 -0
  17. package/dist/examples/quickstart.d.ts.map +1 -0
  18. package/dist/examples/quickstart.js +32 -0
  19. package/dist/examples/quickstart.js.map +1 -0
  20. package/dist/examples/two-agent-observer.d.ts +9 -0
  21. package/dist/examples/two-agent-observer.d.ts.map +1 -0
  22. package/dist/examples/two-agent-observer.js +59 -0
  23. package/dist/examples/two-agent-observer.js.map +1 -0
  24. package/dist/examples/verify-shared-bundle.d.ts +2 -0
  25. package/dist/examples/verify-shared-bundle.d.ts.map +1 -0
  26. package/dist/examples/verify-shared-bundle.js +13 -0
  27. package/dist/examples/verify-shared-bundle.js.map +1 -0
  28. package/dist/generated/cigar_service_pb.d.ts +642 -0
  29. package/dist/generated/cigar_service_pb.d.ts.map +1 -0
  30. package/dist/generated/cigar_service_pb.js +55 -0
  31. package/dist/generated/cigar_service_pb.js.map +1 -0
  32. package/dist/generated/context_abi_pb.d.ts +3429 -0
  33. package/dist/generated/context_abi_pb.d.ts.map +1 -0
  34. package/dist/generated/context_abi_pb.js +1386 -0
  35. package/dist/generated/context_abi_pb.js.map +1 -0
  36. package/dist/generated/errors.d.ts +242 -0
  37. package/dist/generated/errors.d.ts.map +1 -0
  38. package/dist/generated/errors.js +38 -0
  39. package/dist/generated/errors.js.map +1 -0
  40. package/dist/generated/generated/error_codes_pb.d.ts +188 -0
  41. package/dist/generated/generated/error_codes_pb.d.ts.map +1 -0
  42. package/dist/generated/generated/error_codes_pb.js +191 -0
  43. package/dist/generated/generated/error_codes_pb.js.map +1 -0
  44. package/dist/generated/models.d.ts +472 -0
  45. package/dist/generated/models.d.ts.map +1 -0
  46. package/dist/generated/models.js +314 -0
  47. package/dist/generated/models.js.map +1 -0
  48. package/dist/generated/operations.d.ts +912 -0
  49. package/dist/generated/operations.d.ts.map +1 -0
  50. package/dist/generated/operations.js +50 -0
  51. package/dist/generated/operations.js.map +1 -0
  52. package/dist/idempotency.d.ts +3 -0
  53. package/dist/idempotency.d.ts.map +1 -0
  54. package/dist/idempotency.js +16 -0
  55. package/dist/idempotency.js.map +1 -0
  56. package/dist/index.d.ts +13 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +13 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/release.json +6 -0
  61. package/dist/types.d.ts +115 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +3 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/verify-replay.d.ts +3 -0
  66. package/dist/verify-replay.d.ts.map +1 -0
  67. package/dist/verify-replay.js +391 -0
  68. package/dist/verify-replay.js.map +1 -0
  69. package/dist/verify-vectors.d.ts +3 -0
  70. package/dist/verify-vectors.d.ts.map +1 -0
  71. package/dist/verify-vectors.js +383 -0
  72. package/dist/verify-vectors.js.map +1 -0
  73. package/dist/workflow-session.d.ts +93 -0
  74. package/dist/workflow-session.d.ts.map +1 -0
  75. package/dist/workflow-session.js +550 -0
  76. package/dist/workflow-session.js.map +1 -0
  77. package/fixtures/semantic-bundle-v1.json +13 -0
  78. package/package.json +60 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-replay.js","sourceRoot":"","sources":["../src/verify-replay.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,E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CAAC;IACF,MAAM,mBAAmB,GAAG,WAAW,CAAC,UAAU,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,EAAE,CAAC,CAAC;IAC7G,YAAY,CAAC,mBAAmB,EAAE,gCAAgC,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7C,MAAM,aAAa,GAAG,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,KAAK,mBAAmB,CAAC;IACxF,IAAI,aAAa,KAAK,YAAY,CAAC,UAAU,EAAE,mBAAmB,EAAE,+BAA+B,CAAC,EAAE,CAAC;QACrG,IAAI,CAAC,kDAAkD,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;QACrC,cAAc,EAAE,qCAAqC;QACrD,uBAAuB,EAAE,YAAY;QACrC,2BAA2B,EAAE,gBAAgB;QAC7C,4BAA4B,EAAE,iBAAiB;QAC/C,QAAQ;QACR,oBAAoB,EAAE,YAAY,CAAC,OAAO;QAC1C,sBAAsB,EAAE;YACtB,QAAQ,EAAE,eAAe;YACzB,oBAAoB,EAAE,mBAAmB,CAAC,OAAO;SAClD;QACD,uBAAuB,EAAE;YACvB,QAAQ,EAAE,cAAc;YACxB,oBAAoB,EAAE,oBAAoB,CAAC,OAAO;SACnD;QACD,6BAA6B,EAAE;YAC7B,QAAQ,EAAE,aAAa;YACvB,gBAAgB,EAAE,WAAW;SAC9B;KACF,CAAC,IAAI,CAAC,CAAC;AACV,CAAC;AAED,IAAI,EAAE,CAAC","sourcesContent":["/** Independently verifies the bounded CIGAR replay reproduction vector. */\n\nimport { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\n\nconst MAX_FIXTURE_BYTES = 1_048_576;\nconst MAX_RETAINED_BYTES = 1_048_576;\nconst MAX_ENCODED_RETAINED_BYTES = 1_398_104;\nconst MAX_ARTIFACTS = 64;\nconst MAX_OBSERVATIONS = 1_024;\nconst MAX_JSON_DEPTH = 64;\nconst DEPENDENCY_ORDER = [\n \"source\",\n \"blob\",\n \"policy\",\n \"index\",\n \"manifest\",\n \"bundle\",\n \"tokenizer\",\n \"adapter\",\n \"consumer\",\n \"tool_schema\",\n \"environment\",\n] as const;\n\ntype JsonObject = Record<string, unknown>;\ntype RetainedArtifact = {\n kind: string;\n bytesBase64url: string;\n digestMultihash: string;\n};\ntype ArtifactVerification = {\n verifiedBytes: Map<string, Buffer>;\n missing: string[];\n};\n\nfunction fail(message: string): never {\n throw new Error(`replay vector verification failed: ${message}`);\n}\n\nfunction strictObject(value: unknown, keys: readonly string[], context: string): JsonObject {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n fail(`${context} must be an object`);\n }\n const record = value as JsonObject;\n const actual = Object.keys(record).sort();\n const expected = [...keys].sort();\n if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {\n fail(`${context} has unknown or missing fields`);\n }\n return record;\n}\n\nfunction stringField(\n record: JsonObject,\n key: string,\n context: string,\n maximum = 256,\n allowEmpty = false,\n): string {\n const value = record[key];\n if (typeof value !== \"string\" || (!allowEmpty && value.length === 0) || value.length > maximum) {\n fail(`${context}.${key} must be a bounded string`);\n }\n return value;\n}\n\nfunction booleanField(record: JsonObject, key: string, context: string): boolean {\n const value = record[key];\n if (typeof value !== \"boolean\") fail(`${context}.${key} must be a boolean`);\n return value;\n}\n\nfunction stringArray(value: unknown, context: string, maximum = 64): string[] {\n if (!Array.isArray(value) || value.length > maximum) fail(`${context} must be a bounded array`);\n return value.map((item, index) => {\n if (typeof item !== \"string\" || item.length === 0 || item.length > 256) {\n fail(`${context}[${index}] must be a bounded string`);\n }\n return item;\n });\n}\n\nfunction sameStrings(actual: readonly string[], expected: readonly string[], context: string): void {\n if (actual.length !== expected.length || actual.some((value, index) => value !== expected[index])) {\n fail(`${context} differs`);\n }\n}\n\nfunction decodeExactBase64url(value: string, context: string, allowEmpty: boolean): Buffer {\n if (value.length === 0) {\n if (allowEmpty) return Buffer.alloc(0);\n fail(`${context} must not be empty`);\n }\n if (value.length > MAX_ENCODED_RETAINED_BYTES || !/^[A-Za-z0-9_-]+$/u.test(value)) {\n fail(`${context} is not bounded unpadded base64url`);\n }\n const decoded = Buffer.from(value, \"base64url\");\n if (decoded.length > MAX_RETAINED_BYTES || decoded.toString(\"base64url\") !== value) {\n fail(`${context} is non-canonical or exceeds its bound`);\n }\n return decoded;\n}\n\nfunction multihash(bytes: Uint8Array): string {\n return `1220${createHash(\"sha256\").update(bytes).digest(\"hex\")}`;\n}\n\nfunction observationMultihash(observations: readonly Buffer[]): string {\n const hash = createHash(\"sha256\");\n for (const observation of observations) {\n if (observation.length > 0xffff_ffff) fail(\"recorded observation exceeds u32 framing\");\n const length = Buffer.alloc(4);\n length.writeUInt32BE(observation.length);\n hash.update(length);\n hash.update(observation);\n }\n return `1220${hash.digest(\"hex\")}`;\n}\n\nfunction verifyDigest(value: string, context: string): void {\n if (!/^1220[0-9a-f]{64}$/u.test(value)) fail(`${context} is not a lowercase SHA-256 multihash`);\n}\n\nfunction parseArtifacts(required: readonly string[], value: unknown): RetainedArtifact[] {\n if (!Array.isArray(value) || value.length > MAX_ARTIFACTS) {\n fail(\"retained artifact table must be a bounded array\");\n }\n const seen = new Set<string>();\n return value.map((raw, index) => {\n const entry = strictObject(\n raw,\n [\"kind\", \"bytes_base64url\", \"digest_multihash\"],\n `retained artifact ${index}`,\n );\n const kind = stringField(entry, \"kind\", `retained artifact ${index}`);\n if (!required.includes(kind) || seen.has(kind)) fail(\"retained artifact kind is unknown or duplicated\");\n seen.add(kind);\n const bytesBase64url = stringField(\n entry,\n \"bytes_base64url\",\n `retained artifact ${index}`,\n MAX_ENCODED_RETAINED_BYTES,\n );\n const digestMultihash = stringField(entry, \"digest_multihash\", `retained artifact ${index}`, 68);\n verifyDigest(digestMultihash, `retained artifact ${index} digest`);\n return { kind, bytesBase64url, digestMultihash };\n });\n}\n\nfunction verifyArtifacts(required: readonly string[], artifacts: readonly RetainedArtifact[]): ArtifactVerification {\n const verifiedBytes = new Map<string, Buffer>();\n for (const artifact of artifacts) {\n const bytes = decodeExactBase64url(artifact.bytesBase64url, `${artifact.kind} artifact`, false);\n if (multihash(bytes) === artifact.digestMultihash) verifiedBytes.set(artifact.kind, bytes);\n }\n return {\n verifiedBytes,\n missing: required.filter((kind) => !verifiedBytes.has(kind)),\n };\n}\n\nfunction rejectDuplicateJsonKeys(source: string): void {\n let offset = 0;\n\n function whitespace(): void {\n while (offset < source.length && /[\\u0009\\u000a\\u000d\\u0020]/u.test(source[offset] ?? \"\")) offset += 1;\n }\n\n function parseString(): string {\n if (source[offset] !== '\"') fail(\"invalid JSON string\");\n const start = offset;\n offset += 1;\n while (offset < source.length) {\n const character = source[offset];\n if (character === '\"') {\n offset += 1;\n const decoded = JSON.parse(source.slice(start, offset)) as unknown;\n if (typeof decoded !== \"string\") fail(\"invalid JSON string\");\n return decoded;\n }\n if (character === \"\\\\\") {\n offset += 1;\n const escape = source[offset];\n if (escape === \"u\") {\n if (!/^[0-9a-fA-F]{4}$/u.test(source.slice(offset + 1, offset + 5))) fail(\"invalid JSON escape\");\n offset += 5;\n continue;\n }\n if (escape === undefined || !'\"\\\\/bfnrt'.includes(escape)) fail(\"invalid JSON escape\");\n offset += 1;\n continue;\n }\n if (character === undefined || character.charCodeAt(0) < 0x20) fail(\"invalid JSON string character\");\n offset += 1;\n }\n fail(\"unterminated JSON string\");\n }\n\n function parseValue(depth: number): void {\n if (depth > MAX_JSON_DEPTH) fail(\"JSON nesting exceeds its bound\");\n whitespace();\n const character = source[offset];\n if (character === \"{\") {\n offset += 1;\n whitespace();\n const keys = new Set<string>();\n if (source[offset] === \"}\") {\n offset += 1;\n return;\n }\n while (true) {\n whitespace();\n const key = parseString();\n if (keys.has(key)) fail(\"duplicate JSON object key\");\n keys.add(key);\n whitespace();\n if (source[offset] !== \":\") fail(\"JSON object key lacks a value\");\n offset += 1;\n parseValue(depth + 1);\n whitespace();\n if (source[offset] === \"}\") {\n offset += 1;\n return;\n }\n if (source[offset] !== \",\") fail(\"invalid JSON object separator\");\n offset += 1;\n }\n }\n if (character === \"[\") {\n offset += 1;\n whitespace();\n if (source[offset] === \"]\") {\n offset += 1;\n return;\n }\n while (true) {\n parseValue(depth + 1);\n whitespace();\n if (source[offset] === \"]\") {\n offset += 1;\n return;\n }\n if (source[offset] !== \",\") fail(\"invalid JSON array separator\");\n offset += 1;\n }\n }\n if (character === '\"') {\n parseString();\n return;\n }\n for (const literal of [\"true\", \"false\", \"null\"] as const) {\n if (source.startsWith(literal, offset)) {\n offset += literal.length;\n return;\n }\n }\n const number = /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/u.exec(source.slice(offset));\n if (number === null) fail(\"invalid JSON value\");\n offset += number[0].length;\n }\n\n parseValue(0);\n whitespace();\n if (offset !== source.length) fail(\"fixture contains trailing JSON\");\n}\n\nfunction main(): void {\n const path = process.argv[2] ?? \"schemas/vectors/replay-v1.json\";\n const source = readFileSync(path);\n if (source.length === 0 || source.length > MAX_FIXTURE_BYTES) fail(\"fixture size is invalid\");\n let text: string;\n try {\n text = new TextDecoder(\"utf-8\", { fatal: true }).decode(source);\n } catch {\n fail(\"fixture is not valid UTF-8\");\n }\n rejectDuplicateJsonKeys(text);\n const root = strictObject(JSON.parse(text) as unknown, [\n \"schema_version\",\n \"digest_algorithm\",\n \"observation_framing\",\n \"retained\",\n \"required_dependencies\",\n \"retained_artifacts\",\n \"missing_artifact_probe\",\n \"tampered_artifact_probe\",\n \"empty_recorded_response_probe\",\n \"expected\",\n ], \"fixture\");\n if (stringField(root, \"schema_version\", \"fixture\") !== \"cigar.replay-vector.v1\"\n || stringField(root, \"digest_algorithm\", \"fixture\") !== \"sha256-multihash-raw-v1\"\n || stringField(root, \"observation_framing\", \"fixture\") !== \"u32be-length-prefixed-v1\") {\n fail(\"fixture declares an unsupported profile\");\n }\n\n const retained = strictObject(root.retained, [\n \"bundle_bytes_base64url\",\n \"invocation_bytes_base64url\",\n \"recorded_observation_bytes_base64url\",\n ], \"retained\");\n const bundle = decodeExactBase64url(\n stringField(retained, \"bundle_bytes_base64url\", \"retained\", MAX_ENCODED_RETAINED_BYTES),\n \"bundle\",\n false,\n );\n const invocation = decodeExactBase64url(\n stringField(retained, \"invocation_bytes_base64url\", \"retained\", MAX_ENCODED_RETAINED_BYTES),\n \"invocation\",\n false,\n );\n const encodedObservations = stringArray(\n retained.recorded_observation_bytes_base64url,\n \"recorded observations\",\n MAX_OBSERVATIONS,\n );\n if (encodedObservations.length === 0) fail(\"recorded observations must not be empty\");\n const observations = encodedObservations.map((value, index) =>\n decodeExactBase64url(value, `recorded observation ${index}`, true));\n\n const required = stringArray(root.required_dependencies, \"required dependencies\");\n sameStrings(required, DEPENDENCY_ORDER, \"required dependency order\");\n const artifacts = parseArtifacts(required, root.retained_artifacts);\n\n const expected = strictObject(root.expected, [\n \"bundle_digest_multihash\",\n \"invocation_digest_multihash\",\n \"observation_digest_multihash\",\n \"complete\",\n \"missing_dependencies\",\n ], \"expected\");\n const expectedBundle = stringField(expected, \"bundle_digest_multihash\", \"expected\", 68);\n const expectedInvocation = stringField(expected, \"invocation_digest_multihash\", \"expected\", 68);\n const expectedObservations = stringField(expected, \"observation_digest_multihash\", \"expected\", 68);\n for (const [context, value] of [\n [\"bundle digest\", expectedBundle],\n [\"invocation digest\", expectedInvocation],\n [\"observation digest\", expectedObservations],\n ] as const) verifyDigest(value, context);\n const bundleDigest = multihash(bundle);\n const invocationDigest = multihash(invocation);\n const observationDigest = observationMultihash(observations);\n if (bundleDigest !== expectedBundle || invocationDigest !== expectedInvocation\n || observationDigest !== expectedObservations) fail(\"retained replay digest mismatch\");\n\n const verification = verifyArtifacts(required, artifacts);\n const complete = verification.missing.length === 0;\n if (complete !== booleanField(expected, \"complete\", \"expected\")) fail(\"completeness mismatch\");\n sameStrings(\n verification.missing,\n stringArray(expected.missing_dependencies, \"expected missing dependencies\"),\n \"missing dependencies\",\n );\n const artifactBundle = verification.verifiedBytes.get(\"bundle\");\n if (artifactBundle === undefined || !artifactBundle.equals(bundle)) {\n fail(\"retained bundle and bundle dependency artifact differ\");\n }\n\n const missingProbe = strictObject(root.missing_artifact_probe, [\n \"kind\",\n \"expected_complete\",\n \"expected_missing_dependencies\",\n ], \"missing artifact probe\");\n const missingKind = stringField(missingProbe, \"kind\", \"missing artifact probe\");\n if (!required.includes(missingKind)) fail(\"missing artifact probe names an unknown dependency\");\n const missingVerification = verifyArtifacts(\n required,\n artifacts.filter((artifact) => artifact.kind !== missingKind),\n );\n const missingComplete = missingVerification.missing.length === 0;\n if (missingComplete !== booleanField(missingProbe, \"expected_complete\", \"missing artifact probe\")) {\n fail(\"missing artifact probe completeness differs\");\n }\n sameStrings(\n missingVerification.missing,\n stringArray(missingProbe.expected_missing_dependencies, \"missing artifact probe dependencies\"),\n \"missing artifact probe dependencies\",\n );\n\n const tamperProbe = strictObject(root.tampered_artifact_probe, [\n \"kind\",\n \"replacement_bytes_base64url\",\n \"expected_accepted\",\n \"expected_missing_dependencies\",\n ], \"tampered artifact probe\");\n const tamperKind = stringField(tamperProbe, \"kind\", \"tampered artifact probe\");\n if (!required.includes(tamperKind)) fail(\"tampered artifact probe names an unknown dependency\");\n const replacement = stringField(\n tamperProbe,\n \"replacement_bytes_base64url\",\n \"tampered artifact probe\",\n MAX_ENCODED_RETAINED_BYTES,\n );\n let replacements = 0;\n const tampered = artifacts.map((artifact) => {\n if (artifact.kind !== tamperKind) return artifact;\n replacements += 1;\n return { ...artifact, bytesBase64url: replacement };\n });\n if (replacements !== 1) fail(\"tampered artifact probe must identify exactly one artifact\");\n const tamperedVerification = verifyArtifacts(required, tampered);\n const tamperAccepted = tamperedVerification.missing.length === 0;\n if (tamperAccepted !== booleanField(tamperProbe, \"expected_accepted\", \"tampered artifact probe\")) {\n fail(\"tampered artifact probe acceptance differs\");\n }\n sameStrings(\n tamperedVerification.missing,\n stringArray(tamperProbe.expected_missing_dependencies, \"tampered artifact probe dependencies\"),\n \"tampered artifact probe dependencies\",\n );\n\n const emptyProbe = strictObject(root.empty_recorded_response_probe, [\n \"bytes_base64url\",\n \"digest_multihash\",\n \"expected_accepted\",\n ], \"empty recorded response probe\");\n const emptyResponse = decodeExactBase64url(\n stringField(\n emptyProbe,\n \"bytes_base64url\",\n \"empty recorded response probe\",\n MAX_ENCODED_RETAINED_BYTES,\n true,\n ),\n \"empty recorded response\",\n true,\n );\n const expectedEmptyDigest = stringField(emptyProbe, \"digest_multihash\", \"empty recorded response probe\", 68);\n verifyDigest(expectedEmptyDigest, \"empty recorded response digest\");\n const emptyDigest = multihash(emptyResponse);\n const emptyAccepted = emptyResponse.length === 0 && emptyDigest === expectedEmptyDigest;\n if (emptyAccepted !== booleanField(emptyProbe, \"expected_accepted\", \"empty recorded response probe\")) {\n fail(\"empty recorded response probe acceptance differs\");\n }\n\n process.stdout.write(`${JSON.stringify({\n schema_version: \"cigar.replay-reproduction-result.v1\",\n bundle_digest_multihash: bundleDigest,\n invocation_digest_multihash: invocationDigest,\n observation_digest_multihash: observationDigest,\n complete,\n missing_dependencies: verification.missing,\n missing_artifact_probe: {\n complete: missingComplete,\n missing_dependencies: missingVerification.missing,\n },\n tampered_artifact_probe: {\n accepted: tamperAccepted,\n missing_dependencies: tamperedVerification.missing,\n },\n empty_recorded_response_probe: {\n accepted: emptyAccepted,\n digest_multihash: emptyDigest,\n },\n })}\\n`);\n}\n\nmain();\n"]}
@@ -0,0 +1,3 @@
1
+ /** Independent TypeScript verifier for CIGAR canonicalization vectors. */
2
+ export {};
3
+ //# sourceMappingURL=verify-vectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-vectors.d.ts","sourceRoot":"","sources":["../src/verify-vectors.ts"],"names":[],"mappings":"AAAA,0EAA0E","sourcesContent":["/** Independent TypeScript verifier for CIGAR canonicalization vectors. */\n\nimport { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\n\ntype CanonicalNode = boolean | bigint | string | Uint8Array | CanonicalNode[] | Map<string, CanonicalNode>;\n\nclass CanonicalFailure extends Error {\n readonly code: string;\n\n constructor(code: string) {\n super(code);\n this.code = code;\n }\n}\n\nclass JsonParser {\n private position = 0;\n private readonly source: string;\n\n constructor(source: string) {\n this.source = source;\n }\n\n parse(): CanonicalNode {\n const value = this.value();\n this.whitespace();\n if (this.position !== this.source.length) throw new CanonicalFailure(\"invalid_input\");\n return value;\n }\n\n private whitespace(): void {\n while (/[ \\t\\r\\n]/u.test(this.source[this.position] ?? \"\")) this.position += 1;\n }\n\n private value(): CanonicalNode {\n this.whitespace();\n const current = this.source[this.position];\n if (current === '\"') return this.string();\n if (current === \"[\") return this.array();\n if (current === \"{\") return this.object();\n if (this.source.startsWith(\"true\", this.position)) {\n this.position += 4;\n return true;\n }\n if (this.source.startsWith(\"false\", this.position)) {\n this.position += 5;\n return false;\n }\n if (this.source.startsWith(\"null\", this.position)) throw new CanonicalFailure(\"null_forbidden\");\n return this.number();\n }\n\n private string(): string {\n const start = this.position;\n this.position += 1;\n let escaped = false;\n while (this.position < this.source.length) {\n const current = this.source[this.position];\n this.position += 1;\n if (escaped) {\n escaped = false;\n } else if (current === \"\\\\\") {\n escaped = true;\n } else if (current === '\"') {\n try {\n const parsed: unknown = JSON.parse(this.source.slice(start, this.position));\n if (typeof parsed !== \"string\") throw new CanonicalFailure(\"invalid_input\");\n return parsed;\n } catch (error) {\n if (error instanceof CanonicalFailure) throw error;\n throw new CanonicalFailure(\"invalid_input\");\n }\n }\n }\n throw new CanonicalFailure(\"invalid_input\");\n }\n\n private array(): CanonicalNode[] {\n this.position += 1;\n const result: CanonicalNode[] = [];\n this.whitespace();\n if (this.source[this.position] === \"]\") {\n this.position += 1;\n return result;\n }\n for (;;) {\n result.push(this.value());\n this.whitespace();\n const current = this.source[this.position];\n this.position += 1;\n if (current === \"]\") return result;\n if (current !== \",\") throw new CanonicalFailure(\"invalid_input\");\n }\n }\n\n private object(): Map<string, CanonicalNode> {\n this.position += 1;\n const result = new Map<string, CanonicalNode>();\n this.whitespace();\n if (this.source[this.position] === \"}\") {\n this.position += 1;\n return result;\n }\n for (;;) {\n this.whitespace();\n if (this.source[this.position] !== '\"') throw new CanonicalFailure(\"invalid_input\");\n const key = this.string();\n if (result.has(key)) throw new CanonicalFailure(\"duplicate_key\");\n this.whitespace();\n if (this.source[this.position] !== \":\") throw new CanonicalFailure(\"invalid_input\");\n this.position += 1;\n result.set(key, this.value());\n this.whitespace();\n const current = this.source[this.position];\n this.position += 1;\n if (current === \"}\") return result;\n if (current !== \",\") throw new CanonicalFailure(\"invalid_input\");\n }\n }\n\n private number(): bigint {\n const match = /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/u.exec(this.source.slice(this.position));\n if (match === null) throw new CanonicalFailure(\"invalid_input\");\n this.position += match[0].length;\n if (/[.eE]/u.test(match[0])) throw new CanonicalFailure(\"float_forbidden\");\n const value = BigInt(match[0]);\n if (value < -(1n << 63n) || value > (1n << 64n) - 1n) throw new CanonicalFailure(\"float_forbidden\");\n return value;\n }\n}\n\nfunction parseStrictJson(source: string): CanonicalNode {\n return new JsonParser(source).parse();\n}\n\nfunction normalizedJson(value: CanonicalNode): string {\n if (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value === \"string\") return JSON.stringify(value);\n if (value instanceof Uint8Array) throw new CanonicalFailure(\"bytes_not_json\");\n if (Array.isArray(value)) return `[${value.map(normalizedJson).join(\",\")}]`;\n const encoder = new TextEncoder();\n const entries = [...value.entries()].sort(([first], [second]) =>\n Buffer.compare(encoder.encode(first), encoder.encode(second)),\n );\n return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${normalizedJson(child)}`).join(\",\")}}`;\n}\n\nfunction head(major: number, argument: bigint): Uint8Array {\n const prefix = major << 5;\n if (argument < 24n) return Uint8Array.of(prefix | Number(argument));\n const sizes: Array<[bigint, number, number]> = [\n [0xffn, 24, 1], [0xffffn, 25, 2], [0xffffffffn, 26, 4], [0xffffffffffffffffn, 27, 8],\n ];\n for (const [maximum, additional, size] of sizes) {\n if (argument <= maximum) {\n const output = new Uint8Array(size + 1);\n output[0] = prefix | additional;\n let remainder = argument;\n for (let index = size; index > 0; index -= 1) {\n output[index] = Number(remainder & 0xffn);\n remainder >>= 8n;\n }\n return output;\n }\n }\n throw new CanonicalFailure(\"limit_exceeded\");\n}\n\nfunction concatenate(parts: Uint8Array[]): Uint8Array {\n const output = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));\n let offset = 0;\n for (const part of parts) {\n output.set(part, offset);\n offset += part.length;\n }\n return output;\n}\n\nfunction deterministicCbor(value: CanonicalNode): Uint8Array {\n if (value === false) return Uint8Array.of(0xf4);\n if (value === true) return Uint8Array.of(0xf5);\n if (typeof value === \"bigint\") return value >= 0n ? head(0, value) : head(1, -1n - value);\n if (value instanceof Uint8Array) return concatenate([head(2, BigInt(value.length)), value]);\n if (typeof value === \"string\") {\n const encoded = new TextEncoder().encode(value);\n return concatenate([head(3, BigInt(encoded.length)), encoded]);\n }\n if (Array.isArray(value)) return concatenate([head(4, BigInt(value.length)), ...value.map(deterministicCbor)]);\n const entries = [...value.entries()].map(([key, child]) => ({ key: deterministicCbor(key), child }));\n entries.sort((first, second) => Buffer.compare(first.key, second.key));\n return concatenate([head(5, BigInt(entries.length)), ...entries.flatMap(({ key, child }) => [key, deterministicCbor(child)])]);\n}\n\nclass CborParser {\n position = 0;\n private readonly source: Uint8Array;\n\n constructor(source: Uint8Array) {\n this.source = source;\n }\n\n private exact(length: number): Uint8Array {\n const end = this.position + length;\n if (!Number.isSafeInteger(length) || end > this.source.length) throw new CanonicalFailure(\"invalid_input\");\n const value = this.source.slice(this.position, end);\n this.position = end;\n return value;\n }\n\n private byte(): number {\n const value = this.exact(1)[0];\n if (value === undefined) throw new CanonicalFailure(\"invalid_input\");\n return value;\n }\n\n private argument(additional: number): bigint {\n if (additional < 24) return BigInt(additional);\n const sizes = new Map([[24, 1], [25, 2], [26, 4], [27, 8]]);\n const size = sizes.get(additional);\n if (size === undefined) throw new CanonicalFailure(\"non_canonical\");\n let value = 0n;\n for (const current of this.exact(size)) value = (value << 8n) | BigInt(current);\n const minimum = new Map([[1, 24n], [2, 0x100n], [4, 0x10000n], [8, 0x100000000n]]).get(size);\n if (minimum === undefined || value < minimum) throw new CanonicalFailure(\"non_canonical\");\n return value;\n }\n\n parse(): CanonicalNode {\n const initial = this.byte();\n const major = initial >> 5;\n const additional = initial & 31;\n if (major === 0) return this.argument(additional);\n if (major === 1) {\n const value = -1n - this.argument(additional);\n if (value < -(1n << 63n)) throw new CanonicalFailure(\"limit_exceeded\");\n return value;\n }\n if (major === 2 || major === 3) {\n const length = Number(this.argument(additional));\n const data = this.exact(length);\n if (major === 2) return data;\n try {\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(data);\n } catch {\n throw new CanonicalFailure(\"invalid_input\");\n }\n }\n if (major === 4) {\n const length = Number(this.argument(additional));\n return Array.from({ length }, () => this.parse());\n }\n if (major === 5) {\n const length = Number(this.argument(additional));\n const result = new Map<string, CanonicalNode>();\n let previous: Uint8Array | undefined;\n for (let index = 0; index < length; index += 1) {\n const start = this.position;\n const key = this.parse();\n const encoded = this.source.slice(start, this.position);\n if (typeof key !== \"string\" || (previous !== undefined && Buffer.compare(previous, encoded) >= 0)) {\n throw new CanonicalFailure(\"non_canonical\");\n }\n previous = encoded;\n if (result.has(key)) throw new CanonicalFailure(\"duplicate_key\");\n result.set(key, this.parse());\n }\n return result;\n }\n if (major === 6) throw new CanonicalFailure(\"non_canonical\");\n if (major === 7 && additional === 20) return false;\n if (major === 7 && additional === 21) return true;\n if (major === 7 && additional === 22) throw new CanonicalFailure(\"null_forbidden\");\n if (major === 7 && additional >= 25 && additional <= 27) throw new CanonicalFailure(\"float_forbidden\");\n throw new CanonicalFailure(\"non_canonical\");\n }\n}\n\nfunction strictCbor(source: Uint8Array): CanonicalNode {\n const parser = new CborParser(source);\n const value = parser.parse();\n if (parser.position !== source.length || Buffer.compare(deterministicCbor(value), source) !== 0) {\n throw new CanonicalFailure(\"non_canonical\");\n }\n return value;\n}\n\nconst domains = new Map([\n [\"atom\", \"CIGAR-ATOM\"], [\"bundle\", \"CIGAR-BUNDLE\"], [\"manifest\", \"CIGAR-MANIFEST\"],\n [\"handoff\", \"CIGAR-HANDOFF\"], [\"effect\", \"CIGAR-EFFECT\"], [\"receipt\", \"CIGAR-RECEIPT\"],\n [\"extension_manifest\", \"CIGAR-EXTENSION-MANIFEST\"],\n]);\n\nfunction digest(domain: string, cbor: Uint8Array): Buffer {\n const separator = domains.get(domain);\n if (separator === undefined) throw new Error(`unknown digest domain ${domain}`);\n return createHash(\"sha256\").update(separator).update(Uint8Array.of(0)).update(\"v1\").update(Uint8Array.of(0)).update(cbor).digest();\n}\n\ninterface ValidVector {\n id: string; domain: string; normalization: string; json_input: string; normalized_json: string; cbor_hex: string;\n digest_hex: string; multihash: string; signature_input_hex: string;\n}\ninterface InvalidVector { id: string; encoding: string; input: string; error: string }\ninterface DifferentialVector { algorithm: string; count: number; domain: string; digest_accumulator_hex: string }\ninterface Manifest {\n schema_version: number; profile: string; valid_count: number; invalid_count: number;\n valid: ValidVector[]; invalid: InvalidVector[]; differential: DifferentialVector;\n}\n\nfunction check(condition: boolean, message: string): void {\n if (!condition) throw new Error(message);\n}\n\nfunction differentialRecord(index: number): Map<string, CanonicalNode> {\n const entries: Array<[string, CanonicalNode]> = [\n [\"active\", index % 2 === 0], [\"index\", BigInt(index)], [\"label\", `record-${index % 997}`],\n [\"values\", [BigInt(index % 17), BigInt(-(index % 19) - 1)]],\n ];\n return new Map(entries);\n}\n\nfunction verify(path: string): [number, number] {\n const manifest = JSON.parse(readFileSync(path, \"utf8\")) as Manifest;\n check(manifest.schema_version === 1 && manifest.profile === \"cigar-canonical-v1\", \"invalid manifest profile\");\n check(manifest.valid_count === manifest.valid.length && manifest.invalid_count === manifest.invalid.length && manifest.valid.length >= 200, \"invalid manifest counts\");\n for (const vector of manifest.valid) {\n const value = parseStrictJson(vector.json_input);\n if (vector.normalization === \"nfc:/human_text\") {\n if (!(value instanceof Map) || typeof value.get(\"human_text\") !== \"string\") throw new Error(`${vector.id}: invalid NFC target`);\n value.set(\"human_text\", (value.get(\"human_text\") as string).normalize(\"NFC\"));\n } else if (vector.normalization !== \"none\") {\n throw new Error(`${vector.id}: unknown normalization profile`);\n }\n const cbor = deterministicCbor(value);\n const expectedDigest = digest(vector.domain, cbor);\n check(normalizedJson(value) === vector.normalized_json, `${vector.id}: normalized JSON mismatch`);\n check(Buffer.from(cbor).toString(\"hex\") === vector.cbor_hex, `${vector.id}: CBOR mismatch`);\n strictCbor(cbor);\n check(expectedDigest.toString(\"hex\") === vector.digest_hex && `1220${expectedDigest.toString(\"hex\")}` === vector.multihash, `${vector.id}: digest mismatch`);\n check(Buffer.concat([Buffer.from(\"CIGAR-SIGNATURE\\0v1\\0\"), cbor]).toString(\"hex\") === vector.signature_input_hex, `${vector.id}: signature input mismatch`);\n }\n for (const vector of manifest.invalid) {\n let actual: string | undefined;\n try {\n if (vector.encoding === \"json\") parseStrictJson(vector.input);\n else if (vector.encoding === \"cbor_hex\") strictCbor(Buffer.from(vector.input, \"hex\"));\n else if (vector.encoding === \"semantic\") throw new CanonicalFailure(\"invalid_argument\");\n else if (vector.encoding === \"signature_hex\" && Buffer.from(vector.input, \"hex\").length !== 64) throw new CanonicalFailure(\"invalid_argument\");\n } catch (error) {\n if (error instanceof CanonicalFailure) actual = error.code;\n else throw error;\n }\n check(actual === vector.error, `${vector.id}: expected ${vector.error}, found ${actual ?? \"accepted\"}`);\n }\n const differential = manifest.differential;\n check(differential.algorithm === \"cigar-differential-record-v1\" && differential.count >= 100_000, \"invalid differential metadata\");\n const accumulator = createHash(\"sha256\");\n for (let index = 0; index < differential.count; index += 1) accumulator.update(digest(differential.domain, deterministicCbor(differentialRecord(index))));\n check(accumulator.digest(\"hex\") === differential.digest_accumulator_hex, \"100,000-record differential accumulator mismatch\");\n return [manifest.valid.length + manifest.invalid.length, differential.count];\n}\n\nconst path = process.argv[2] ?? \"schemas/vectors/canonical-v1.json\";\nconst [vectorCount, differentialCount] = verify(path);\nconsole.log(`verified ${vectorCount} canonical vectors and ${differentialCount} differential records`);\n"]}
@@ -0,0 +1,383 @@
1
+ /** Independent TypeScript verifier for CIGAR canonicalization vectors. */
2
+ import { createHash } from "node:crypto";
3
+ import { readFileSync } from "node:fs";
4
+ class CanonicalFailure extends Error {
5
+ code;
6
+ constructor(code) {
7
+ super(code);
8
+ this.code = code;
9
+ }
10
+ }
11
+ class JsonParser {
12
+ position = 0;
13
+ source;
14
+ constructor(source) {
15
+ this.source = source;
16
+ }
17
+ parse() {
18
+ const value = this.value();
19
+ this.whitespace();
20
+ if (this.position !== this.source.length)
21
+ throw new CanonicalFailure("invalid_input");
22
+ return value;
23
+ }
24
+ whitespace() {
25
+ while (/[ \t\r\n]/u.test(this.source[this.position] ?? ""))
26
+ this.position += 1;
27
+ }
28
+ value() {
29
+ this.whitespace();
30
+ const current = this.source[this.position];
31
+ if (current === '"')
32
+ return this.string();
33
+ if (current === "[")
34
+ return this.array();
35
+ if (current === "{")
36
+ return this.object();
37
+ if (this.source.startsWith("true", this.position)) {
38
+ this.position += 4;
39
+ return true;
40
+ }
41
+ if (this.source.startsWith("false", this.position)) {
42
+ this.position += 5;
43
+ return false;
44
+ }
45
+ if (this.source.startsWith("null", this.position))
46
+ throw new CanonicalFailure("null_forbidden");
47
+ return this.number();
48
+ }
49
+ string() {
50
+ const start = this.position;
51
+ this.position += 1;
52
+ let escaped = false;
53
+ while (this.position < this.source.length) {
54
+ const current = this.source[this.position];
55
+ this.position += 1;
56
+ if (escaped) {
57
+ escaped = false;
58
+ }
59
+ else if (current === "\\") {
60
+ escaped = true;
61
+ }
62
+ else if (current === '"') {
63
+ try {
64
+ const parsed = JSON.parse(this.source.slice(start, this.position));
65
+ if (typeof parsed !== "string")
66
+ throw new CanonicalFailure("invalid_input");
67
+ return parsed;
68
+ }
69
+ catch (error) {
70
+ if (error instanceof CanonicalFailure)
71
+ throw error;
72
+ throw new CanonicalFailure("invalid_input");
73
+ }
74
+ }
75
+ }
76
+ throw new CanonicalFailure("invalid_input");
77
+ }
78
+ array() {
79
+ this.position += 1;
80
+ const result = [];
81
+ this.whitespace();
82
+ if (this.source[this.position] === "]") {
83
+ this.position += 1;
84
+ return result;
85
+ }
86
+ for (;;) {
87
+ result.push(this.value());
88
+ this.whitespace();
89
+ const current = this.source[this.position];
90
+ this.position += 1;
91
+ if (current === "]")
92
+ return result;
93
+ if (current !== ",")
94
+ throw new CanonicalFailure("invalid_input");
95
+ }
96
+ }
97
+ object() {
98
+ this.position += 1;
99
+ const result = new Map();
100
+ this.whitespace();
101
+ if (this.source[this.position] === "}") {
102
+ this.position += 1;
103
+ return result;
104
+ }
105
+ for (;;) {
106
+ this.whitespace();
107
+ if (this.source[this.position] !== '"')
108
+ throw new CanonicalFailure("invalid_input");
109
+ const key = this.string();
110
+ if (result.has(key))
111
+ throw new CanonicalFailure("duplicate_key");
112
+ this.whitespace();
113
+ if (this.source[this.position] !== ":")
114
+ throw new CanonicalFailure("invalid_input");
115
+ this.position += 1;
116
+ result.set(key, this.value());
117
+ this.whitespace();
118
+ const current = this.source[this.position];
119
+ this.position += 1;
120
+ if (current === "}")
121
+ return result;
122
+ if (current !== ",")
123
+ throw new CanonicalFailure("invalid_input");
124
+ }
125
+ }
126
+ number() {
127
+ const match = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/u.exec(this.source.slice(this.position));
128
+ if (match === null)
129
+ throw new CanonicalFailure("invalid_input");
130
+ this.position += match[0].length;
131
+ if (/[.eE]/u.test(match[0]))
132
+ throw new CanonicalFailure("float_forbidden");
133
+ const value = BigInt(match[0]);
134
+ if (value < -(1n << 63n) || value > (1n << 64n) - 1n)
135
+ throw new CanonicalFailure("float_forbidden");
136
+ return value;
137
+ }
138
+ }
139
+ function parseStrictJson(source) {
140
+ return new JsonParser(source).parse();
141
+ }
142
+ function normalizedJson(value) {
143
+ if (typeof value === "boolean")
144
+ return value ? "true" : "false";
145
+ if (typeof value === "bigint")
146
+ return value.toString();
147
+ if (typeof value === "string")
148
+ return JSON.stringify(value);
149
+ if (value instanceof Uint8Array)
150
+ throw new CanonicalFailure("bytes_not_json");
151
+ if (Array.isArray(value))
152
+ return `[${value.map(normalizedJson).join(",")}]`;
153
+ const encoder = new TextEncoder();
154
+ const entries = [...value.entries()].sort(([first], [second]) => Buffer.compare(encoder.encode(first), encoder.encode(second)));
155
+ return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${normalizedJson(child)}`).join(",")}}`;
156
+ }
157
+ function head(major, argument) {
158
+ const prefix = major << 5;
159
+ if (argument < 24n)
160
+ return Uint8Array.of(prefix | Number(argument));
161
+ const sizes = [
162
+ [0xffn, 24, 1], [0xffffn, 25, 2], [0xffffffffn, 26, 4], [0xffffffffffffffffn, 27, 8],
163
+ ];
164
+ for (const [maximum, additional, size] of sizes) {
165
+ if (argument <= maximum) {
166
+ const output = new Uint8Array(size + 1);
167
+ output[0] = prefix | additional;
168
+ let remainder = argument;
169
+ for (let index = size; index > 0; index -= 1) {
170
+ output[index] = Number(remainder & 0xffn);
171
+ remainder >>= 8n;
172
+ }
173
+ return output;
174
+ }
175
+ }
176
+ throw new CanonicalFailure("limit_exceeded");
177
+ }
178
+ function concatenate(parts) {
179
+ const output = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
180
+ let offset = 0;
181
+ for (const part of parts) {
182
+ output.set(part, offset);
183
+ offset += part.length;
184
+ }
185
+ return output;
186
+ }
187
+ function deterministicCbor(value) {
188
+ if (value === false)
189
+ return Uint8Array.of(0xf4);
190
+ if (value === true)
191
+ return Uint8Array.of(0xf5);
192
+ if (typeof value === "bigint")
193
+ return value >= 0n ? head(0, value) : head(1, -1n - value);
194
+ if (value instanceof Uint8Array)
195
+ return concatenate([head(2, BigInt(value.length)), value]);
196
+ if (typeof value === "string") {
197
+ const encoded = new TextEncoder().encode(value);
198
+ return concatenate([head(3, BigInt(encoded.length)), encoded]);
199
+ }
200
+ if (Array.isArray(value))
201
+ return concatenate([head(4, BigInt(value.length)), ...value.map(deterministicCbor)]);
202
+ const entries = [...value.entries()].map(([key, child]) => ({ key: deterministicCbor(key), child }));
203
+ entries.sort((first, second) => Buffer.compare(first.key, second.key));
204
+ return concatenate([head(5, BigInt(entries.length)), ...entries.flatMap(({ key, child }) => [key, deterministicCbor(child)])]);
205
+ }
206
+ class CborParser {
207
+ position = 0;
208
+ source;
209
+ constructor(source) {
210
+ this.source = source;
211
+ }
212
+ exact(length) {
213
+ const end = this.position + length;
214
+ if (!Number.isSafeInteger(length) || end > this.source.length)
215
+ throw new CanonicalFailure("invalid_input");
216
+ const value = this.source.slice(this.position, end);
217
+ this.position = end;
218
+ return value;
219
+ }
220
+ byte() {
221
+ const value = this.exact(1)[0];
222
+ if (value === undefined)
223
+ throw new CanonicalFailure("invalid_input");
224
+ return value;
225
+ }
226
+ argument(additional) {
227
+ if (additional < 24)
228
+ return BigInt(additional);
229
+ const sizes = new Map([[24, 1], [25, 2], [26, 4], [27, 8]]);
230
+ const size = sizes.get(additional);
231
+ if (size === undefined)
232
+ throw new CanonicalFailure("non_canonical");
233
+ let value = 0n;
234
+ for (const current of this.exact(size))
235
+ value = (value << 8n) | BigInt(current);
236
+ const minimum = new Map([[1, 24n], [2, 0x100n], [4, 0x10000n], [8, 0x100000000n]]).get(size);
237
+ if (minimum === undefined || value < minimum)
238
+ throw new CanonicalFailure("non_canonical");
239
+ return value;
240
+ }
241
+ parse() {
242
+ const initial = this.byte();
243
+ const major = initial >> 5;
244
+ const additional = initial & 31;
245
+ if (major === 0)
246
+ return this.argument(additional);
247
+ if (major === 1) {
248
+ const value = -1n - this.argument(additional);
249
+ if (value < -(1n << 63n))
250
+ throw new CanonicalFailure("limit_exceeded");
251
+ return value;
252
+ }
253
+ if (major === 2 || major === 3) {
254
+ const length = Number(this.argument(additional));
255
+ const data = this.exact(length);
256
+ if (major === 2)
257
+ return data;
258
+ try {
259
+ return new TextDecoder("utf-8", { fatal: true }).decode(data);
260
+ }
261
+ catch {
262
+ throw new CanonicalFailure("invalid_input");
263
+ }
264
+ }
265
+ if (major === 4) {
266
+ const length = Number(this.argument(additional));
267
+ return Array.from({ length }, () => this.parse());
268
+ }
269
+ if (major === 5) {
270
+ const length = Number(this.argument(additional));
271
+ const result = new Map();
272
+ let previous;
273
+ for (let index = 0; index < length; index += 1) {
274
+ const start = this.position;
275
+ const key = this.parse();
276
+ const encoded = this.source.slice(start, this.position);
277
+ if (typeof key !== "string" || (previous !== undefined && Buffer.compare(previous, encoded) >= 0)) {
278
+ throw new CanonicalFailure("non_canonical");
279
+ }
280
+ previous = encoded;
281
+ if (result.has(key))
282
+ throw new CanonicalFailure("duplicate_key");
283
+ result.set(key, this.parse());
284
+ }
285
+ return result;
286
+ }
287
+ if (major === 6)
288
+ throw new CanonicalFailure("non_canonical");
289
+ if (major === 7 && additional === 20)
290
+ return false;
291
+ if (major === 7 && additional === 21)
292
+ return true;
293
+ if (major === 7 && additional === 22)
294
+ throw new CanonicalFailure("null_forbidden");
295
+ if (major === 7 && additional >= 25 && additional <= 27)
296
+ throw new CanonicalFailure("float_forbidden");
297
+ throw new CanonicalFailure("non_canonical");
298
+ }
299
+ }
300
+ function strictCbor(source) {
301
+ const parser = new CborParser(source);
302
+ const value = parser.parse();
303
+ if (parser.position !== source.length || Buffer.compare(deterministicCbor(value), source) !== 0) {
304
+ throw new CanonicalFailure("non_canonical");
305
+ }
306
+ return value;
307
+ }
308
+ const domains = new Map([
309
+ ["atom", "CIGAR-ATOM"], ["bundle", "CIGAR-BUNDLE"], ["manifest", "CIGAR-MANIFEST"],
310
+ ["handoff", "CIGAR-HANDOFF"], ["effect", "CIGAR-EFFECT"], ["receipt", "CIGAR-RECEIPT"],
311
+ ["extension_manifest", "CIGAR-EXTENSION-MANIFEST"],
312
+ ]);
313
+ function digest(domain, cbor) {
314
+ const separator = domains.get(domain);
315
+ if (separator === undefined)
316
+ throw new Error(`unknown digest domain ${domain}`);
317
+ return createHash("sha256").update(separator).update(Uint8Array.of(0)).update("v1").update(Uint8Array.of(0)).update(cbor).digest();
318
+ }
319
+ function check(condition, message) {
320
+ if (!condition)
321
+ throw new Error(message);
322
+ }
323
+ function differentialRecord(index) {
324
+ const entries = [
325
+ ["active", index % 2 === 0], ["index", BigInt(index)], ["label", `record-${index % 997}`],
326
+ ["values", [BigInt(index % 17), BigInt(-(index % 19) - 1)]],
327
+ ];
328
+ return new Map(entries);
329
+ }
330
+ function verify(path) {
331
+ const manifest = JSON.parse(readFileSync(path, "utf8"));
332
+ check(manifest.schema_version === 1 && manifest.profile === "cigar-canonical-v1", "invalid manifest profile");
333
+ check(manifest.valid_count === manifest.valid.length && manifest.invalid_count === manifest.invalid.length && manifest.valid.length >= 200, "invalid manifest counts");
334
+ for (const vector of manifest.valid) {
335
+ const value = parseStrictJson(vector.json_input);
336
+ if (vector.normalization === "nfc:/human_text") {
337
+ if (!(value instanceof Map) || typeof value.get("human_text") !== "string")
338
+ throw new Error(`${vector.id}: invalid NFC target`);
339
+ value.set("human_text", value.get("human_text").normalize("NFC"));
340
+ }
341
+ else if (vector.normalization !== "none") {
342
+ throw new Error(`${vector.id}: unknown normalization profile`);
343
+ }
344
+ const cbor = deterministicCbor(value);
345
+ const expectedDigest = digest(vector.domain, cbor);
346
+ check(normalizedJson(value) === vector.normalized_json, `${vector.id}: normalized JSON mismatch`);
347
+ check(Buffer.from(cbor).toString("hex") === vector.cbor_hex, `${vector.id}: CBOR mismatch`);
348
+ strictCbor(cbor);
349
+ check(expectedDigest.toString("hex") === vector.digest_hex && `1220${expectedDigest.toString("hex")}` === vector.multihash, `${vector.id}: digest mismatch`);
350
+ check(Buffer.concat([Buffer.from("CIGAR-SIGNATURE\0v1\0"), cbor]).toString("hex") === vector.signature_input_hex, `${vector.id}: signature input mismatch`);
351
+ }
352
+ for (const vector of manifest.invalid) {
353
+ let actual;
354
+ try {
355
+ if (vector.encoding === "json")
356
+ parseStrictJson(vector.input);
357
+ else if (vector.encoding === "cbor_hex")
358
+ strictCbor(Buffer.from(vector.input, "hex"));
359
+ else if (vector.encoding === "semantic")
360
+ throw new CanonicalFailure("invalid_argument");
361
+ else if (vector.encoding === "signature_hex" && Buffer.from(vector.input, "hex").length !== 64)
362
+ throw new CanonicalFailure("invalid_argument");
363
+ }
364
+ catch (error) {
365
+ if (error instanceof CanonicalFailure)
366
+ actual = error.code;
367
+ else
368
+ throw error;
369
+ }
370
+ check(actual === vector.error, `${vector.id}: expected ${vector.error}, found ${actual ?? "accepted"}`);
371
+ }
372
+ const differential = manifest.differential;
373
+ check(differential.algorithm === "cigar-differential-record-v1" && differential.count >= 100_000, "invalid differential metadata");
374
+ const accumulator = createHash("sha256");
375
+ for (let index = 0; index < differential.count; index += 1)
376
+ accumulator.update(digest(differential.domain, deterministicCbor(differentialRecord(index))));
377
+ check(accumulator.digest("hex") === differential.digest_accumulator_hex, "100,000-record differential accumulator mismatch");
378
+ return [manifest.valid.length + manifest.invalid.length, differential.count];
379
+ }
380
+ const path = process.argv[2] ?? "schemas/vectors/canonical-v1.json";
381
+ const [vectorCount, differentialCount] = verify(path);
382
+ console.log(`verified ${vectorCount} canonical vectors and ${differentialCount} differential records`);
383
+ //# sourceMappingURL=verify-vectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-vectors.js","sourceRoot":"","sources":["../src/verify-vectors.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,MAAM,gBAAiB,SAAQ,KAAK;IACzB,IAAI,CAAS;IAEtB,YAAY,IAAY;QACtB,KAAK,CAAC,IAAI,CAAC,CAAC;Q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CAAmC,CAAC;AACpE,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AACtD,OAAO,CAAC,GAAG,CAAC,YAAY,WAAW,0BAA0B,iBAAiB,uBAAuB,CAAC,CAAC","sourcesContent":["/** Independent TypeScript verifier for CIGAR canonicalization vectors. */\n\nimport { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\n\ntype CanonicalNode = boolean | bigint | string | Uint8Array | CanonicalNode[] | Map<string, CanonicalNode>;\n\nclass CanonicalFailure extends Error {\n readonly code: string;\n\n constructor(code: string) {\n super(code);\n this.code = code;\n }\n}\n\nclass JsonParser {\n private position = 0;\n private readonly source: string;\n\n constructor(source: string) {\n this.source = source;\n }\n\n parse(): CanonicalNode {\n const value = this.value();\n this.whitespace();\n if (this.position !== this.source.length) throw new CanonicalFailure(\"invalid_input\");\n return value;\n }\n\n private whitespace(): void {\n while (/[ \\t\\r\\n]/u.test(this.source[this.position] ?? \"\")) this.position += 1;\n }\n\n private value(): CanonicalNode {\n this.whitespace();\n const current = this.source[this.position];\n if (current === '\"') return this.string();\n if (current === \"[\") return this.array();\n if (current === \"{\") return this.object();\n if (this.source.startsWith(\"true\", this.position)) {\n this.position += 4;\n return true;\n }\n if (this.source.startsWith(\"false\", this.position)) {\n this.position += 5;\n return false;\n }\n if (this.source.startsWith(\"null\", this.position)) throw new CanonicalFailure(\"null_forbidden\");\n return this.number();\n }\n\n private string(): string {\n const start = this.position;\n this.position += 1;\n let escaped = false;\n while (this.position < this.source.length) {\n const current = this.source[this.position];\n this.position += 1;\n if (escaped) {\n escaped = false;\n } else if (current === \"\\\\\") {\n escaped = true;\n } else if (current === '\"') {\n try {\n const parsed: unknown = JSON.parse(this.source.slice(start, this.position));\n if (typeof parsed !== \"string\") throw new CanonicalFailure(\"invalid_input\");\n return parsed;\n } catch (error) {\n if (error instanceof CanonicalFailure) throw error;\n throw new CanonicalFailure(\"invalid_input\");\n }\n }\n }\n throw new CanonicalFailure(\"invalid_input\");\n }\n\n private array(): CanonicalNode[] {\n this.position += 1;\n const result: CanonicalNode[] = [];\n this.whitespace();\n if (this.source[this.position] === \"]\") {\n this.position += 1;\n return result;\n }\n for (;;) {\n result.push(this.value());\n this.whitespace();\n const current = this.source[this.position];\n this.position += 1;\n if (current === \"]\") return result;\n if (current !== \",\") throw new CanonicalFailure(\"invalid_input\");\n }\n }\n\n private object(): Map<string, CanonicalNode> {\n this.position += 1;\n const result = new Map<string, CanonicalNode>();\n this.whitespace();\n if (this.source[this.position] === \"}\") {\n this.position += 1;\n return result;\n }\n for (;;) {\n this.whitespace();\n if (this.source[this.position] !== '\"') throw new CanonicalFailure(\"invalid_input\");\n const key = this.string();\n if (result.has(key)) throw new CanonicalFailure(\"duplicate_key\");\n this.whitespace();\n if (this.source[this.position] !== \":\") throw new CanonicalFailure(\"invalid_input\");\n this.position += 1;\n result.set(key, this.value());\n this.whitespace();\n const current = this.source[this.position];\n this.position += 1;\n if (current === \"}\") return result;\n if (current !== \",\") throw new CanonicalFailure(\"invalid_input\");\n }\n }\n\n private number(): bigint {\n const match = /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/u.exec(this.source.slice(this.position));\n if (match === null) throw new CanonicalFailure(\"invalid_input\");\n this.position += match[0].length;\n if (/[.eE]/u.test(match[0])) throw new CanonicalFailure(\"float_forbidden\");\n const value = BigInt(match[0]);\n if (value < -(1n << 63n) || value > (1n << 64n) - 1n) throw new CanonicalFailure(\"float_forbidden\");\n return value;\n }\n}\n\nfunction parseStrictJson(source: string): CanonicalNode {\n return new JsonParser(source).parse();\n}\n\nfunction normalizedJson(value: CanonicalNode): string {\n if (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value === \"string\") return JSON.stringify(value);\n if (value instanceof Uint8Array) throw new CanonicalFailure(\"bytes_not_json\");\n if (Array.isArray(value)) return `[${value.map(normalizedJson).join(\",\")}]`;\n const encoder = new TextEncoder();\n const entries = [...value.entries()].sort(([first], [second]) =>\n Buffer.compare(encoder.encode(first), encoder.encode(second)),\n );\n return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${normalizedJson(child)}`).join(\",\")}}`;\n}\n\nfunction head(major: number, argument: bigint): Uint8Array {\n const prefix = major << 5;\n if (argument < 24n) return Uint8Array.of(prefix | Number(argument));\n const sizes: Array<[bigint, number, number]> = [\n [0xffn, 24, 1], [0xffffn, 25, 2], [0xffffffffn, 26, 4], [0xffffffffffffffffn, 27, 8],\n ];\n for (const [maximum, additional, size] of sizes) {\n if (argument <= maximum) {\n const output = new Uint8Array(size + 1);\n output[0] = prefix | additional;\n let remainder = argument;\n for (let index = size; index > 0; index -= 1) {\n output[index] = Number(remainder & 0xffn);\n remainder >>= 8n;\n }\n return output;\n }\n }\n throw new CanonicalFailure(\"limit_exceeded\");\n}\n\nfunction concatenate(parts: Uint8Array[]): Uint8Array {\n const output = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));\n let offset = 0;\n for (const part of parts) {\n output.set(part, offset);\n offset += part.length;\n }\n return output;\n}\n\nfunction deterministicCbor(value: CanonicalNode): Uint8Array {\n if (value === false) return Uint8Array.of(0xf4);\n if (value === true) return Uint8Array.of(0xf5);\n if (typeof value === \"bigint\") return value >= 0n ? head(0, value) : head(1, -1n - value);\n if (value instanceof Uint8Array) return concatenate([head(2, BigInt(value.length)), value]);\n if (typeof value === \"string\") {\n const encoded = new TextEncoder().encode(value);\n return concatenate([head(3, BigInt(encoded.length)), encoded]);\n }\n if (Array.isArray(value)) return concatenate([head(4, BigInt(value.length)), ...value.map(deterministicCbor)]);\n const entries = [...value.entries()].map(([key, child]) => ({ key: deterministicCbor(key), child }));\n entries.sort((first, second) => Buffer.compare(first.key, second.key));\n return concatenate([head(5, BigInt(entries.length)), ...entries.flatMap(({ key, child }) => [key, deterministicCbor(child)])]);\n}\n\nclass CborParser {\n position = 0;\n private readonly source: Uint8Array;\n\n constructor(source: Uint8Array) {\n this.source = source;\n }\n\n private exact(length: number): Uint8Array {\n const end = this.position + length;\n if (!Number.isSafeInteger(length) || end > this.source.length) throw new CanonicalFailure(\"invalid_input\");\n const value = this.source.slice(this.position, end);\n this.position = end;\n return value;\n }\n\n private byte(): number {\n const value = this.exact(1)[0];\n if (value === undefined) throw new CanonicalFailure(\"invalid_input\");\n return value;\n }\n\n private argument(additional: number): bigint {\n if (additional < 24) return BigInt(additional);\n const sizes = new Map([[24, 1], [25, 2], [26, 4], [27, 8]]);\n const size = sizes.get(additional);\n if (size === undefined) throw new CanonicalFailure(\"non_canonical\");\n let value = 0n;\n for (const current of this.exact(size)) value = (value << 8n) | BigInt(current);\n const minimum = new Map([[1, 24n], [2, 0x100n], [4, 0x10000n], [8, 0x100000000n]]).get(size);\n if (minimum === undefined || value < minimum) throw new CanonicalFailure(\"non_canonical\");\n return value;\n }\n\n parse(): CanonicalNode {\n const initial = this.byte();\n const major = initial >> 5;\n const additional = initial & 31;\n if (major === 0) return this.argument(additional);\n if (major === 1) {\n const value = -1n - this.argument(additional);\n if (value < -(1n << 63n)) throw new CanonicalFailure(\"limit_exceeded\");\n return value;\n }\n if (major === 2 || major === 3) {\n const length = Number(this.argument(additional));\n const data = this.exact(length);\n if (major === 2) return data;\n try {\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(data);\n } catch {\n throw new CanonicalFailure(\"invalid_input\");\n }\n }\n if (major === 4) {\n const length = Number(this.argument(additional));\n return Array.from({ length }, () => this.parse());\n }\n if (major === 5) {\n const length = Number(this.argument(additional));\n const result = new Map<string, CanonicalNode>();\n let previous: Uint8Array | undefined;\n for (let index = 0; index < length; index += 1) {\n const start = this.position;\n const key = this.parse();\n const encoded = this.source.slice(start, this.position);\n if (typeof key !== \"string\" || (previous !== undefined && Buffer.compare(previous, encoded) >= 0)) {\n throw new CanonicalFailure(\"non_canonical\");\n }\n previous = encoded;\n if (result.has(key)) throw new CanonicalFailure(\"duplicate_key\");\n result.set(key, this.parse());\n }\n return result;\n }\n if (major === 6) throw new CanonicalFailure(\"non_canonical\");\n if (major === 7 && additional === 20) return false;\n if (major === 7 && additional === 21) return true;\n if (major === 7 && additional === 22) throw new CanonicalFailure(\"null_forbidden\");\n if (major === 7 && additional >= 25 && additional <= 27) throw new CanonicalFailure(\"float_forbidden\");\n throw new CanonicalFailure(\"non_canonical\");\n }\n}\n\nfunction strictCbor(source: Uint8Array): CanonicalNode {\n const parser = new CborParser(source);\n const value = parser.parse();\n if (parser.position !== source.length || Buffer.compare(deterministicCbor(value), source) !== 0) {\n throw new CanonicalFailure(\"non_canonical\");\n }\n return value;\n}\n\nconst domains = new Map([\n [\"atom\", \"CIGAR-ATOM\"], [\"bundle\", \"CIGAR-BUNDLE\"], [\"manifest\", \"CIGAR-MANIFEST\"],\n [\"handoff\", \"CIGAR-HANDOFF\"], [\"effect\", \"CIGAR-EFFECT\"], [\"receipt\", \"CIGAR-RECEIPT\"],\n [\"extension_manifest\", \"CIGAR-EXTENSION-MANIFEST\"],\n]);\n\nfunction digest(domain: string, cbor: Uint8Array): Buffer {\n const separator = domains.get(domain);\n if (separator === undefined) throw new Error(`unknown digest domain ${domain}`);\n return createHash(\"sha256\").update(separator).update(Uint8Array.of(0)).update(\"v1\").update(Uint8Array.of(0)).update(cbor).digest();\n}\n\ninterface ValidVector {\n id: string; domain: string; normalization: string; json_input: string; normalized_json: string; cbor_hex: string;\n digest_hex: string; multihash: string; signature_input_hex: string;\n}\ninterface InvalidVector { id: string; encoding: string; input: string; error: string }\ninterface DifferentialVector { algorithm: string; count: number; domain: string; digest_accumulator_hex: string }\ninterface Manifest {\n schema_version: number; profile: string; valid_count: number; invalid_count: number;\n valid: ValidVector[]; invalid: InvalidVector[]; differential: DifferentialVector;\n}\n\nfunction check(condition: boolean, message: string): void {\n if (!condition) throw new Error(message);\n}\n\nfunction differentialRecord(index: number): Map<string, CanonicalNode> {\n const entries: Array<[string, CanonicalNode]> = [\n [\"active\", index % 2 === 0], [\"index\", BigInt(index)], [\"label\", `record-${index % 997}`],\n [\"values\", [BigInt(index % 17), BigInt(-(index % 19) - 1)]],\n ];\n return new Map(entries);\n}\n\nfunction verify(path: string): [number, number] {\n const manifest = JSON.parse(readFileSync(path, \"utf8\")) as Manifest;\n check(manifest.schema_version === 1 && manifest.profile === \"cigar-canonical-v1\", \"invalid manifest profile\");\n check(manifest.valid_count === manifest.valid.length && manifest.invalid_count === manifest.invalid.length && manifest.valid.length >= 200, \"invalid manifest counts\");\n for (const vector of manifest.valid) {\n const value = parseStrictJson(vector.json_input);\n if (vector.normalization === \"nfc:/human_text\") {\n if (!(value instanceof Map) || typeof value.get(\"human_text\") !== \"string\") throw new Error(`${vector.id}: invalid NFC target`);\n value.set(\"human_text\", (value.get(\"human_text\") as string).normalize(\"NFC\"));\n } else if (vector.normalization !== \"none\") {\n throw new Error(`${vector.id}: unknown normalization profile`);\n }\n const cbor = deterministicCbor(value);\n const expectedDigest = digest(vector.domain, cbor);\n check(normalizedJson(value) === vector.normalized_json, `${vector.id}: normalized JSON mismatch`);\n check(Buffer.from(cbor).toString(\"hex\") === vector.cbor_hex, `${vector.id}: CBOR mismatch`);\n strictCbor(cbor);\n check(expectedDigest.toString(\"hex\") === vector.digest_hex && `1220${expectedDigest.toString(\"hex\")}` === vector.multihash, `${vector.id}: digest mismatch`);\n check(Buffer.concat([Buffer.from(\"CIGAR-SIGNATURE\\0v1\\0\"), cbor]).toString(\"hex\") === vector.signature_input_hex, `${vector.id}: signature input mismatch`);\n }\n for (const vector of manifest.invalid) {\n let actual: string | undefined;\n try {\n if (vector.encoding === \"json\") parseStrictJson(vector.input);\n else if (vector.encoding === \"cbor_hex\") strictCbor(Buffer.from(vector.input, \"hex\"));\n else if (vector.encoding === \"semantic\") throw new CanonicalFailure(\"invalid_argument\");\n else if (vector.encoding === \"signature_hex\" && Buffer.from(vector.input, \"hex\").length !== 64) throw new CanonicalFailure(\"invalid_argument\");\n } catch (error) {\n if (error instanceof CanonicalFailure) actual = error.code;\n else throw error;\n }\n check(actual === vector.error, `${vector.id}: expected ${vector.error}, found ${actual ?? \"accepted\"}`);\n }\n const differential = manifest.differential;\n check(differential.algorithm === \"cigar-differential-record-v1\" && differential.count >= 100_000, \"invalid differential metadata\");\n const accumulator = createHash(\"sha256\");\n for (let index = 0; index < differential.count; index += 1) accumulator.update(digest(differential.domain, deterministicCbor(differentialRecord(index))));\n check(accumulator.digest(\"hex\") === differential.digest_accumulator_hex, \"100,000-record differential accumulator mismatch\");\n return [manifest.valid.length + manifest.invalid.length, differential.count];\n}\n\nconst path = process.argv[2] ?? \"schemas/vectors/canonical-v1.json\";\nconst [vectorCount, differentialCount] = verify(path);\nconsole.log(`verified ${vectorCount} canonical vectors and ${differentialCount} differential records`);\n"]}