@mnemom/agent-integrity-protocol 0.1.7 → 0.2.0

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/index.d.cts CHANGED
@@ -963,6 +963,198 @@ declare class WindowManager {
963
963
  private recomputeStats;
964
964
  }
965
965
 
966
+ /**
967
+ * Integrity certificate and attestation types for the Agent Integrity Protocol.
968
+ *
969
+ * Defines the machine-readable integrity certificate format modeled on C2PA
970
+ * content credentials and W3C Verifiable Credentials. A certificate bundles
971
+ * all cryptographic evidence for a checkpoint into a single, self-describing
972
+ * document that can be independently verified.
973
+ *
974
+ * Also defines supporting types for Merkle inclusion proofs, chain hashes,
975
+ * and certificate verification results.
976
+ */
977
+ /**
978
+ * A self-describing integrity certificate that bundles analysis verdicts,
979
+ * input commitments, and cryptographic proofs into a single envelope.
980
+ *
981
+ * Modeled on C2PA content credentials and W3C Verifiable Credentials.
982
+ * The certificate can be independently verified without trusting the
983
+ * issuing server.
984
+ */
985
+ interface IntegrityCertificate {
986
+ /** JSON-LD context identifier */
987
+ '@context': 'https://mnemom.ai/aip/v1';
988
+ /** Document type discriminator */
989
+ type: 'IntegrityCertificate';
990
+ /** Certificate format version */
991
+ version: '1.0.0';
992
+ /** Unique certificate identifier (format: "cert-{8 random chars}") */
993
+ certificate_id: string;
994
+ /** ISO 8601 timestamp of certificate issuance */
995
+ issued_at: string;
996
+ /** The checkpoint this certificate attests to */
997
+ subject: {
998
+ checkpoint_id: string;
999
+ agent_id: string;
1000
+ session_id: string;
1001
+ card_id: string;
1002
+ };
1003
+ /** Analysis claims covered by the certificate */
1004
+ claims: {
1005
+ verdict: string;
1006
+ concerns: Array<{
1007
+ category: string;
1008
+ severity: string;
1009
+ description: string;
1010
+ }>;
1011
+ confidence: number;
1012
+ reasoning_summary: string;
1013
+ analysis_model: string;
1014
+ analysis_duration_ms: number;
1015
+ };
1016
+ /** Deterministic hashes of all analysis inputs */
1017
+ input_commitments: {
1018
+ thinking_block_hash: string;
1019
+ card_hash: string;
1020
+ values_hash: string;
1021
+ context_hash: string;
1022
+ model_version: string;
1023
+ combined_commitment: string;
1024
+ };
1025
+ /** Cryptographic proofs */
1026
+ proofs: {
1027
+ /** Ed25519 digital signature over the canonical signed payload */
1028
+ signature: {
1029
+ algorithm: 'Ed25519';
1030
+ key_id: string;
1031
+ value: string;
1032
+ signed_payload: string;
1033
+ };
1034
+ /** Hash chain link connecting this checkpoint to its predecessor */
1035
+ chain: {
1036
+ chain_hash: string;
1037
+ prev_chain_hash: string | null;
1038
+ position: number;
1039
+ };
1040
+ /** Merkle inclusion proof (null when tree has not been built yet) */
1041
+ merkle: {
1042
+ leaf_hash: string;
1043
+ leaf_index: number;
1044
+ root: string;
1045
+ tree_size: number;
1046
+ inclusion_proof: Array<{
1047
+ hash: string;
1048
+ position: 'left' | 'right';
1049
+ }>;
1050
+ } | null;
1051
+ /** Verdict derivation proof (Phase 3 — not yet implemented) */
1052
+ verdict_derivation: null;
1053
+ };
1054
+ /** URLs for online verification */
1055
+ verification: {
1056
+ keys_url: string;
1057
+ certificate_url: string;
1058
+ verify_url: string;
1059
+ };
1060
+ }
1061
+ /**
1062
+ * A Merkle inclusion proof demonstrating that a leaf exists in a Merkle tree.
1063
+ *
1064
+ * Contains the O(log N) sibling hashes needed to recompute the root
1065
+ * from a given leaf hash.
1066
+ */
1067
+ interface MerkleProof {
1068
+ /** SHA-256 hash of the leaf data */
1069
+ leafHash: string;
1070
+ /** Zero-based index of the leaf in the tree */
1071
+ leafIndex: number;
1072
+ /** Sibling hashes from leaf to root, with their relative position */
1073
+ siblings: Array<{
1074
+ hash: string;
1075
+ position: 'left' | 'right';
1076
+ }>;
1077
+ /** Expected Merkle root */
1078
+ root: string;
1079
+ /** Number of leaves in the tree when the proof was generated */
1080
+ treeSize: number;
1081
+ }
1082
+ /**
1083
+ * A hash chain link connecting a checkpoint to its predecessor.
1084
+ *
1085
+ * The chain hash is a SHA-256 digest of the concatenated fields:
1086
+ * (genesis|prevChainHash) | checkpointId | verdict | thinkingBlockHash | inputCommitment | timestamp
1087
+ */
1088
+ interface ChainHash {
1089
+ /** SHA-256 chain hash for this checkpoint */
1090
+ chainHash: string;
1091
+ /** Chain hash of the previous checkpoint (null for the first in a session) */
1092
+ prevChainHash: string | null;
1093
+ /** Zero-based position in the chain */
1094
+ position: number;
1095
+ }
1096
+ /**
1097
+ * Result of verifying an integrity certificate offline.
1098
+ *
1099
+ * Contains the overall validity and per-check details for signature,
1100
+ * chain hash, and Merkle inclusion proof verification.
1101
+ */
1102
+ interface CertificateVerificationResult {
1103
+ /** Whether all checks passed */
1104
+ valid: boolean;
1105
+ /** Individual check results */
1106
+ checks: {
1107
+ /** Ed25519 signature verification */
1108
+ signature: {
1109
+ valid: boolean;
1110
+ details: string;
1111
+ };
1112
+ /** Chain hash recomputation check */
1113
+ chain: {
1114
+ valid: boolean;
1115
+ details: string;
1116
+ };
1117
+ /** Merkle inclusion proof check (null if no Merkle proof in certificate) */
1118
+ merkle: {
1119
+ valid: boolean;
1120
+ details: string;
1121
+ } | null;
1122
+ };
1123
+ }
1124
+
1125
+ /**
1126
+ * Offline certificate verification for the Agent Integrity Protocol.
1127
+ *
1128
+ * Provides `verifyCertificate()` — a pure function that checks:
1129
+ * 1. Ed25519 signature validity
1130
+ * 2. Hash chain link integrity
1131
+ * 3. Merkle inclusion proof (when present)
1132
+ *
1133
+ * Uses @noble/ed25519 and @noble/hashes, which work in Node.js,
1134
+ * Deno, Cloudflare Workers, and modern browsers.
1135
+ */
1136
+
1137
+ /**
1138
+ * Verify an integrity certificate offline.
1139
+ *
1140
+ * Performs three independent checks:
1141
+ * 1. **Signature** — verifies the Ed25519 signature against the provided
1142
+ * public key and the canonical `signed_payload` embedded in the certificate.
1143
+ * 2. **Chain** — recomputes the SHA-256 chain hash from the certificate
1144
+ * fields and compares it to the stored `chain_hash`.
1145
+ * 3. **Merkle** — if the certificate contains a Merkle inclusion proof,
1146
+ * walks the sibling hashes from leaf to root and compares against the
1147
+ * expected root. Pass `merkleRoot` to pin verification to an
1148
+ * independently-fetched tree root; otherwise the root embedded in the
1149
+ * certificate is used.
1150
+ *
1151
+ * @param certificate - The integrity certificate to verify
1152
+ * @param publicKey - Ed25519 public key as a Uint8Array (32 bytes)
1153
+ * @param merkleRoot - Optional externally-fetched Merkle root for pinned verification
1154
+ * @returns Verification result with per-check details
1155
+ */
1156
+ declare function verifyCertificate(certificate: IntegrityCertificate, publicKey: Uint8Array, merkleRoot?: string): Promise<CertificateVerificationResult>;
1157
+
966
1158
  /** Protocol version identifiers. */
967
1159
  declare const AIP_VERSION = "0.1.0";
968
1160
  declare const ALGORITHM_VERSION = "1.0.0";
@@ -1048,4 +1240,4 @@ declare const CHECKPOINT_ID_PREFIX = "ic-";
1048
1240
  declare const DRIFT_ALERT_ID_PREFIX = "ida-";
1049
1241
  declare const REGISTRATION_ID_PREFIX = "reg-";
1050
1242
 
1051
- export { type AIPCallbacks, type AIPClient, type AIPConfig, AIP_CONTENT_TYPE, AIP_SIGNATURE_HEADER, AIP_VERSION, AIP_VERSION_HEADER, ALGORITHM_VERSION, type AdapterRegistry, type AlignmentCard, type AlignmentCardValue, type AnalysisLLMConfig, type AnalysisMetadata, AnthropicAdapter, type AutonomyEnvelope, type BuiltPrompt, CHECKPOINT_ID_PREFIX, CONFIDENCE_EXPLICIT, CONFIDENCE_FALLBACK, CONFIDENCE_NATIVE, type CardConscienceAgreement, type CardConscienceAugmentation, type CardConscienceConflict, type CheckIntegrityInput, type ConcernCategory, type ConscienceContext, type ConscienceValue, type ConscienceValueType, type ConsultationDepth, DEFAULT_ANALYSIS_MAX_TOKENS, DEFAULT_ANALYSIS_TIMEOUT_MS, DEFAULT_CONSCIENCE_VALUES, DEFAULT_SUSTAINED_CHECKS_THRESHOLD, DEFAULT_THINKING_TOKEN_BUDGET, DEFAULT_WINDOW_MAX_AGE_SECONDS, DEFAULT_WINDOW_MAX_SIZE, DRIFT_ALERT_ID_PREFIX, DRIFT_SEVERITY_LOW_THRESHOLD, DRIFT_SEVERITY_MEDIUM_THRESHOLD, type DriftDirection, type DriftState, EU_COMPLIANCE_FAILURE_POLICY, EU_COMPLIANCE_WINDOW_CONFIG, type EscalationTrigger, type ExtractedThinking, type ExtractionMethod, type FailureMode, type FailurePolicy, FallbackAdapter, GoogleAdapter, type IntegrityCheckpoint, type IntegrityConcern, type IntegrityDriftAlert, type IntegritySeverity, type IntegritySignal, type IntegrityVerdict, MAX_EVIDENCE_LENGTH, MIN_WINDOW_SIZE, OpenAIAdapter, type PromptInput, type ProviderAdapter, REGISTRATION_ID_PREFIX, type RecommendedAction, type SessionBoundary, TRUNCATION_HEAD_RATIO, TRUNCATION_TAIL_RATIO, WEBHOOK_MAX_RETRIES, WEBHOOK_RETRY_DELAYS_MS, type WindowConfig, WindowManager, type WindowMode, type WindowPosition, type WindowState, type WindowSummary, buildConsciencePrompt, buildSignal, checkIntegrity, createAdapterRegistry, createClient, createDriftState, createWindowState, detectIntegrityDrift, hashThinkingBlock, mapVerdictToAction, mapVerdictToProceed, signPayload, summarizeCard, validateAgreement, verifySignature };
1243
+ export { type AIPCallbacks, type AIPClient, type AIPConfig, AIP_CONTENT_TYPE, AIP_SIGNATURE_HEADER, AIP_VERSION, AIP_VERSION_HEADER, ALGORITHM_VERSION, type AdapterRegistry, type AlignmentCard, type AlignmentCardValue, type AnalysisLLMConfig, type AnalysisMetadata, AnthropicAdapter, type AutonomyEnvelope, type BuiltPrompt, CHECKPOINT_ID_PREFIX, CONFIDENCE_EXPLICIT, CONFIDENCE_FALLBACK, CONFIDENCE_NATIVE, type CardConscienceAgreement, type CardConscienceAugmentation, type CardConscienceConflict, type CertificateVerificationResult, type ChainHash, type CheckIntegrityInput, type ConcernCategory, type ConscienceContext, type ConscienceValue, type ConscienceValueType, type ConsultationDepth, DEFAULT_ANALYSIS_MAX_TOKENS, DEFAULT_ANALYSIS_TIMEOUT_MS, DEFAULT_CONSCIENCE_VALUES, DEFAULT_SUSTAINED_CHECKS_THRESHOLD, DEFAULT_THINKING_TOKEN_BUDGET, DEFAULT_WINDOW_MAX_AGE_SECONDS, DEFAULT_WINDOW_MAX_SIZE, DRIFT_ALERT_ID_PREFIX, DRIFT_SEVERITY_LOW_THRESHOLD, DRIFT_SEVERITY_MEDIUM_THRESHOLD, type DriftDirection, type DriftState, EU_COMPLIANCE_FAILURE_POLICY, EU_COMPLIANCE_WINDOW_CONFIG, type EscalationTrigger, type ExtractedThinking, type ExtractionMethod, type FailureMode, type FailurePolicy, FallbackAdapter, GoogleAdapter, type IntegrityCertificate, type IntegrityCheckpoint, type IntegrityConcern, type IntegrityDriftAlert, type IntegritySeverity, type IntegritySignal, type IntegrityVerdict, MAX_EVIDENCE_LENGTH, MIN_WINDOW_SIZE, type MerkleProof, OpenAIAdapter, type PromptInput, type ProviderAdapter, REGISTRATION_ID_PREFIX, type RecommendedAction, type SessionBoundary, TRUNCATION_HEAD_RATIO, TRUNCATION_TAIL_RATIO, WEBHOOK_MAX_RETRIES, WEBHOOK_RETRY_DELAYS_MS, type WindowConfig, WindowManager, type WindowMode, type WindowPosition, type WindowState, type WindowSummary, buildConsciencePrompt, buildSignal, checkIntegrity, createAdapterRegistry, createClient, createDriftState, createWindowState, detectIntegrityDrift, hashThinkingBlock, mapVerdictToAction, mapVerdictToProceed, signPayload, summarizeCard, validateAgreement, verifyCertificate, verifySignature };
package/dist/index.d.ts CHANGED
@@ -963,6 +963,198 @@ declare class WindowManager {
963
963
  private recomputeStats;
964
964
  }
965
965
 
966
+ /**
967
+ * Integrity certificate and attestation types for the Agent Integrity Protocol.
968
+ *
969
+ * Defines the machine-readable integrity certificate format modeled on C2PA
970
+ * content credentials and W3C Verifiable Credentials. A certificate bundles
971
+ * all cryptographic evidence for a checkpoint into a single, self-describing
972
+ * document that can be independently verified.
973
+ *
974
+ * Also defines supporting types for Merkle inclusion proofs, chain hashes,
975
+ * and certificate verification results.
976
+ */
977
+ /**
978
+ * A self-describing integrity certificate that bundles analysis verdicts,
979
+ * input commitments, and cryptographic proofs into a single envelope.
980
+ *
981
+ * Modeled on C2PA content credentials and W3C Verifiable Credentials.
982
+ * The certificate can be independently verified without trusting the
983
+ * issuing server.
984
+ */
985
+ interface IntegrityCertificate {
986
+ /** JSON-LD context identifier */
987
+ '@context': 'https://mnemom.ai/aip/v1';
988
+ /** Document type discriminator */
989
+ type: 'IntegrityCertificate';
990
+ /** Certificate format version */
991
+ version: '1.0.0';
992
+ /** Unique certificate identifier (format: "cert-{8 random chars}") */
993
+ certificate_id: string;
994
+ /** ISO 8601 timestamp of certificate issuance */
995
+ issued_at: string;
996
+ /** The checkpoint this certificate attests to */
997
+ subject: {
998
+ checkpoint_id: string;
999
+ agent_id: string;
1000
+ session_id: string;
1001
+ card_id: string;
1002
+ };
1003
+ /** Analysis claims covered by the certificate */
1004
+ claims: {
1005
+ verdict: string;
1006
+ concerns: Array<{
1007
+ category: string;
1008
+ severity: string;
1009
+ description: string;
1010
+ }>;
1011
+ confidence: number;
1012
+ reasoning_summary: string;
1013
+ analysis_model: string;
1014
+ analysis_duration_ms: number;
1015
+ };
1016
+ /** Deterministic hashes of all analysis inputs */
1017
+ input_commitments: {
1018
+ thinking_block_hash: string;
1019
+ card_hash: string;
1020
+ values_hash: string;
1021
+ context_hash: string;
1022
+ model_version: string;
1023
+ combined_commitment: string;
1024
+ };
1025
+ /** Cryptographic proofs */
1026
+ proofs: {
1027
+ /** Ed25519 digital signature over the canonical signed payload */
1028
+ signature: {
1029
+ algorithm: 'Ed25519';
1030
+ key_id: string;
1031
+ value: string;
1032
+ signed_payload: string;
1033
+ };
1034
+ /** Hash chain link connecting this checkpoint to its predecessor */
1035
+ chain: {
1036
+ chain_hash: string;
1037
+ prev_chain_hash: string | null;
1038
+ position: number;
1039
+ };
1040
+ /** Merkle inclusion proof (null when tree has not been built yet) */
1041
+ merkle: {
1042
+ leaf_hash: string;
1043
+ leaf_index: number;
1044
+ root: string;
1045
+ tree_size: number;
1046
+ inclusion_proof: Array<{
1047
+ hash: string;
1048
+ position: 'left' | 'right';
1049
+ }>;
1050
+ } | null;
1051
+ /** Verdict derivation proof (Phase 3 — not yet implemented) */
1052
+ verdict_derivation: null;
1053
+ };
1054
+ /** URLs for online verification */
1055
+ verification: {
1056
+ keys_url: string;
1057
+ certificate_url: string;
1058
+ verify_url: string;
1059
+ };
1060
+ }
1061
+ /**
1062
+ * A Merkle inclusion proof demonstrating that a leaf exists in a Merkle tree.
1063
+ *
1064
+ * Contains the O(log N) sibling hashes needed to recompute the root
1065
+ * from a given leaf hash.
1066
+ */
1067
+ interface MerkleProof {
1068
+ /** SHA-256 hash of the leaf data */
1069
+ leafHash: string;
1070
+ /** Zero-based index of the leaf in the tree */
1071
+ leafIndex: number;
1072
+ /** Sibling hashes from leaf to root, with their relative position */
1073
+ siblings: Array<{
1074
+ hash: string;
1075
+ position: 'left' | 'right';
1076
+ }>;
1077
+ /** Expected Merkle root */
1078
+ root: string;
1079
+ /** Number of leaves in the tree when the proof was generated */
1080
+ treeSize: number;
1081
+ }
1082
+ /**
1083
+ * A hash chain link connecting a checkpoint to its predecessor.
1084
+ *
1085
+ * The chain hash is a SHA-256 digest of the concatenated fields:
1086
+ * (genesis|prevChainHash) | checkpointId | verdict | thinkingBlockHash | inputCommitment | timestamp
1087
+ */
1088
+ interface ChainHash {
1089
+ /** SHA-256 chain hash for this checkpoint */
1090
+ chainHash: string;
1091
+ /** Chain hash of the previous checkpoint (null for the first in a session) */
1092
+ prevChainHash: string | null;
1093
+ /** Zero-based position in the chain */
1094
+ position: number;
1095
+ }
1096
+ /**
1097
+ * Result of verifying an integrity certificate offline.
1098
+ *
1099
+ * Contains the overall validity and per-check details for signature,
1100
+ * chain hash, and Merkle inclusion proof verification.
1101
+ */
1102
+ interface CertificateVerificationResult {
1103
+ /** Whether all checks passed */
1104
+ valid: boolean;
1105
+ /** Individual check results */
1106
+ checks: {
1107
+ /** Ed25519 signature verification */
1108
+ signature: {
1109
+ valid: boolean;
1110
+ details: string;
1111
+ };
1112
+ /** Chain hash recomputation check */
1113
+ chain: {
1114
+ valid: boolean;
1115
+ details: string;
1116
+ };
1117
+ /** Merkle inclusion proof check (null if no Merkle proof in certificate) */
1118
+ merkle: {
1119
+ valid: boolean;
1120
+ details: string;
1121
+ } | null;
1122
+ };
1123
+ }
1124
+
1125
+ /**
1126
+ * Offline certificate verification for the Agent Integrity Protocol.
1127
+ *
1128
+ * Provides `verifyCertificate()` — a pure function that checks:
1129
+ * 1. Ed25519 signature validity
1130
+ * 2. Hash chain link integrity
1131
+ * 3. Merkle inclusion proof (when present)
1132
+ *
1133
+ * Uses @noble/ed25519 and @noble/hashes, which work in Node.js,
1134
+ * Deno, Cloudflare Workers, and modern browsers.
1135
+ */
1136
+
1137
+ /**
1138
+ * Verify an integrity certificate offline.
1139
+ *
1140
+ * Performs three independent checks:
1141
+ * 1. **Signature** — verifies the Ed25519 signature against the provided
1142
+ * public key and the canonical `signed_payload` embedded in the certificate.
1143
+ * 2. **Chain** — recomputes the SHA-256 chain hash from the certificate
1144
+ * fields and compares it to the stored `chain_hash`.
1145
+ * 3. **Merkle** — if the certificate contains a Merkle inclusion proof,
1146
+ * walks the sibling hashes from leaf to root and compares against the
1147
+ * expected root. Pass `merkleRoot` to pin verification to an
1148
+ * independently-fetched tree root; otherwise the root embedded in the
1149
+ * certificate is used.
1150
+ *
1151
+ * @param certificate - The integrity certificate to verify
1152
+ * @param publicKey - Ed25519 public key as a Uint8Array (32 bytes)
1153
+ * @param merkleRoot - Optional externally-fetched Merkle root for pinned verification
1154
+ * @returns Verification result with per-check details
1155
+ */
1156
+ declare function verifyCertificate(certificate: IntegrityCertificate, publicKey: Uint8Array, merkleRoot?: string): Promise<CertificateVerificationResult>;
1157
+
966
1158
  /** Protocol version identifiers. */
967
1159
  declare const AIP_VERSION = "0.1.0";
968
1160
  declare const ALGORITHM_VERSION = "1.0.0";
@@ -1048,4 +1240,4 @@ declare const CHECKPOINT_ID_PREFIX = "ic-";
1048
1240
  declare const DRIFT_ALERT_ID_PREFIX = "ida-";
1049
1241
  declare const REGISTRATION_ID_PREFIX = "reg-";
1050
1242
 
1051
- export { type AIPCallbacks, type AIPClient, type AIPConfig, AIP_CONTENT_TYPE, AIP_SIGNATURE_HEADER, AIP_VERSION, AIP_VERSION_HEADER, ALGORITHM_VERSION, type AdapterRegistry, type AlignmentCard, type AlignmentCardValue, type AnalysisLLMConfig, type AnalysisMetadata, AnthropicAdapter, type AutonomyEnvelope, type BuiltPrompt, CHECKPOINT_ID_PREFIX, CONFIDENCE_EXPLICIT, CONFIDENCE_FALLBACK, CONFIDENCE_NATIVE, type CardConscienceAgreement, type CardConscienceAugmentation, type CardConscienceConflict, type CheckIntegrityInput, type ConcernCategory, type ConscienceContext, type ConscienceValue, type ConscienceValueType, type ConsultationDepth, DEFAULT_ANALYSIS_MAX_TOKENS, DEFAULT_ANALYSIS_TIMEOUT_MS, DEFAULT_CONSCIENCE_VALUES, DEFAULT_SUSTAINED_CHECKS_THRESHOLD, DEFAULT_THINKING_TOKEN_BUDGET, DEFAULT_WINDOW_MAX_AGE_SECONDS, DEFAULT_WINDOW_MAX_SIZE, DRIFT_ALERT_ID_PREFIX, DRIFT_SEVERITY_LOW_THRESHOLD, DRIFT_SEVERITY_MEDIUM_THRESHOLD, type DriftDirection, type DriftState, EU_COMPLIANCE_FAILURE_POLICY, EU_COMPLIANCE_WINDOW_CONFIG, type EscalationTrigger, type ExtractedThinking, type ExtractionMethod, type FailureMode, type FailurePolicy, FallbackAdapter, GoogleAdapter, type IntegrityCheckpoint, type IntegrityConcern, type IntegrityDriftAlert, type IntegritySeverity, type IntegritySignal, type IntegrityVerdict, MAX_EVIDENCE_LENGTH, MIN_WINDOW_SIZE, OpenAIAdapter, type PromptInput, type ProviderAdapter, REGISTRATION_ID_PREFIX, type RecommendedAction, type SessionBoundary, TRUNCATION_HEAD_RATIO, TRUNCATION_TAIL_RATIO, WEBHOOK_MAX_RETRIES, WEBHOOK_RETRY_DELAYS_MS, type WindowConfig, WindowManager, type WindowMode, type WindowPosition, type WindowState, type WindowSummary, buildConsciencePrompt, buildSignal, checkIntegrity, createAdapterRegistry, createClient, createDriftState, createWindowState, detectIntegrityDrift, hashThinkingBlock, mapVerdictToAction, mapVerdictToProceed, signPayload, summarizeCard, validateAgreement, verifySignature };
1243
+ export { type AIPCallbacks, type AIPClient, type AIPConfig, AIP_CONTENT_TYPE, AIP_SIGNATURE_HEADER, AIP_VERSION, AIP_VERSION_HEADER, ALGORITHM_VERSION, type AdapterRegistry, type AlignmentCard, type AlignmentCardValue, type AnalysisLLMConfig, type AnalysisMetadata, AnthropicAdapter, type AutonomyEnvelope, type BuiltPrompt, CHECKPOINT_ID_PREFIX, CONFIDENCE_EXPLICIT, CONFIDENCE_FALLBACK, CONFIDENCE_NATIVE, type CardConscienceAgreement, type CardConscienceAugmentation, type CardConscienceConflict, type CertificateVerificationResult, type ChainHash, type CheckIntegrityInput, type ConcernCategory, type ConscienceContext, type ConscienceValue, type ConscienceValueType, type ConsultationDepth, DEFAULT_ANALYSIS_MAX_TOKENS, DEFAULT_ANALYSIS_TIMEOUT_MS, DEFAULT_CONSCIENCE_VALUES, DEFAULT_SUSTAINED_CHECKS_THRESHOLD, DEFAULT_THINKING_TOKEN_BUDGET, DEFAULT_WINDOW_MAX_AGE_SECONDS, DEFAULT_WINDOW_MAX_SIZE, DRIFT_ALERT_ID_PREFIX, DRIFT_SEVERITY_LOW_THRESHOLD, DRIFT_SEVERITY_MEDIUM_THRESHOLD, type DriftDirection, type DriftState, EU_COMPLIANCE_FAILURE_POLICY, EU_COMPLIANCE_WINDOW_CONFIG, type EscalationTrigger, type ExtractedThinking, type ExtractionMethod, type FailureMode, type FailurePolicy, FallbackAdapter, GoogleAdapter, type IntegrityCertificate, type IntegrityCheckpoint, type IntegrityConcern, type IntegrityDriftAlert, type IntegritySeverity, type IntegritySignal, type IntegrityVerdict, MAX_EVIDENCE_LENGTH, MIN_WINDOW_SIZE, type MerkleProof, OpenAIAdapter, type PromptInput, type ProviderAdapter, REGISTRATION_ID_PREFIX, type RecommendedAction, type SessionBoundary, TRUNCATION_HEAD_RATIO, TRUNCATION_TAIL_RATIO, WEBHOOK_MAX_RETRIES, WEBHOOK_RETRY_DELAYS_MS, type WindowConfig, WindowManager, type WindowMode, type WindowPosition, type WindowState, type WindowSummary, buildConsciencePrompt, buildSignal, checkIntegrity, createAdapterRegistry, createClient, createDriftState, createWindowState, detectIntegrityDrift, hashThinkingBlock, mapVerdictToAction, mapVerdictToProceed, signPayload, summarizeCard, validateAgreement, verifyCertificate, verifySignature };
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { randomUUID, createHash, createHmac } from 'crypto';
2
+ import * as ed from '@noble/ed25519';
3
+ import { sha256 } from '@noble/hashes/sha2.js';
4
+ import { bytesToHex } from '@noble/hashes/utils.js';
2
5
 
3
6
  // src/window/state.ts
4
7
  function createWindowState(sessionId) {
@@ -1548,7 +1551,100 @@ function constantTimeEqual(a, b) {
1548
1551
  }
1549
1552
  return result === 0;
1550
1553
  }
1554
+ function base64ToUint8(b64) {
1555
+ const binary = atob(b64);
1556
+ const bytes = new Uint8Array(binary.length);
1557
+ for (let i = 0; i < binary.length; i++) {
1558
+ bytes[i] = binary.charCodeAt(i);
1559
+ }
1560
+ return bytes;
1561
+ }
1562
+ var encoder = new TextEncoder();
1563
+ function sha256Hex(input) {
1564
+ const hash = sha256(encoder.encode(input));
1565
+ return bytesToHex(hash);
1566
+ }
1567
+ function computeNodeHash(left, right) {
1568
+ return sha256Hex(left + right);
1569
+ }
1570
+ async function verifySignature2(certificate, publicKey) {
1571
+ try {
1572
+ const signatureBytes = base64ToUint8(certificate.proofs.signature.value);
1573
+ const messageBytes = encoder.encode(certificate.proofs.signature.signed_payload);
1574
+ const valid = await ed.verifyAsync(signatureBytes, messageBytes, publicKey);
1575
+ return {
1576
+ valid,
1577
+ details: valid ? "Ed25519 signature verified successfully" : "Ed25519 signature verification failed"
1578
+ };
1579
+ } catch (err) {
1580
+ return {
1581
+ valid: false,
1582
+ details: `Signature verification error: ${err instanceof Error ? err.message : "unknown"}`
1583
+ };
1584
+ }
1585
+ }
1586
+ function verifyChain(certificate) {
1587
+ try {
1588
+ const chain = certificate.proofs.chain;
1589
+ if (!chain || !chain.chain_hash) {
1590
+ return { valid: false, details: "No chain proof data in certificate" };
1591
+ }
1592
+ const preimage = `${chain.prev_chain_hash || "genesis"}|${certificate.subject.checkpoint_id}|${certificate.claims.verdict}|${certificate.input_commitments.thinking_block_hash}|${certificate.input_commitments.combined_commitment}|${certificate.issued_at}`;
1593
+ const recomputed = sha256Hex(preimage);
1594
+ const valid = recomputed === chain.chain_hash;
1595
+ return {
1596
+ valid,
1597
+ details: valid ? "Chain hash verified successfully" : "Recomputed chain hash does not match certificate"
1598
+ };
1599
+ } catch (err) {
1600
+ return {
1601
+ valid: false,
1602
+ details: `Chain verification error: ${err instanceof Error ? err.message : "unknown"}`
1603
+ };
1604
+ }
1605
+ }
1606
+ function verifyMerkle(certificate, expectedRoot) {
1607
+ const merkle = certificate.proofs.merkle;
1608
+ if (!merkle) {
1609
+ return null;
1610
+ }
1611
+ try {
1612
+ const root = expectedRoot ?? merkle.root;
1613
+ let current = merkle.leaf_hash;
1614
+ for (const sibling of merkle.inclusion_proof) {
1615
+ if (sibling.position === "left") {
1616
+ current = computeNodeHash(sibling.hash, current);
1617
+ } else {
1618
+ current = computeNodeHash(current, sibling.hash);
1619
+ }
1620
+ }
1621
+ const valid = current === root;
1622
+ return {
1623
+ valid,
1624
+ details: valid ? "Merkle inclusion proof verified successfully" : "Merkle inclusion proof verification failed \u2014 computed root does not match"
1625
+ };
1626
+ } catch (err) {
1627
+ return {
1628
+ valid: false,
1629
+ details: `Merkle verification error: ${err instanceof Error ? err.message : "unknown"}`
1630
+ };
1631
+ }
1632
+ }
1633
+ async function verifyCertificate(certificate, publicKey, merkleRoot) {
1634
+ const signatureResult = await verifySignature2(certificate, publicKey);
1635
+ const chainResult = verifyChain(certificate);
1636
+ const merkleResult = verifyMerkle(certificate, merkleRoot);
1637
+ const valid = signatureResult.valid && chainResult.valid && (merkleResult === null || merkleResult.valid);
1638
+ return {
1639
+ valid,
1640
+ checks: {
1641
+ signature: signatureResult,
1642
+ chain: chainResult,
1643
+ merkle: merkleResult
1644
+ }
1645
+ };
1646
+ }
1551
1647
 
1552
- export { AIP_CONTENT_TYPE, AIP_SIGNATURE_HEADER, AIP_VERSION, AIP_VERSION_HEADER, ALGORITHM_VERSION, AnthropicAdapter, CHECKPOINT_ID_PREFIX, CONFIDENCE_EXPLICIT, CONFIDENCE_FALLBACK, CONFIDENCE_NATIVE, DEFAULT_ANALYSIS_MAX_TOKENS, DEFAULT_ANALYSIS_TIMEOUT_MS, DEFAULT_CONSCIENCE_VALUES, DEFAULT_SUSTAINED_CHECKS_THRESHOLD, DEFAULT_THINKING_TOKEN_BUDGET, DEFAULT_WINDOW_MAX_AGE_SECONDS, DEFAULT_WINDOW_MAX_SIZE, DRIFT_ALERT_ID_PREFIX, DRIFT_SEVERITY_LOW_THRESHOLD, DRIFT_SEVERITY_MEDIUM_THRESHOLD, EU_COMPLIANCE_FAILURE_POLICY, EU_COMPLIANCE_WINDOW_CONFIG, FallbackAdapter, GoogleAdapter, MAX_EVIDENCE_LENGTH, MIN_WINDOW_SIZE, OpenAIAdapter, REGISTRATION_ID_PREFIX, TRUNCATION_HEAD_RATIO, TRUNCATION_TAIL_RATIO, WEBHOOK_MAX_RETRIES, WEBHOOK_RETRY_DELAYS_MS, WindowManager, buildConsciencePrompt, buildSignal, checkIntegrity, createAdapterRegistry, createClient, createDriftState, createWindowState, detectIntegrityDrift, hashThinkingBlock, mapVerdictToAction, mapVerdictToProceed, signPayload, summarizeCard, validateAgreement, verifySignature };
1648
+ export { AIP_CONTENT_TYPE, AIP_SIGNATURE_HEADER, AIP_VERSION, AIP_VERSION_HEADER, ALGORITHM_VERSION, AnthropicAdapter, CHECKPOINT_ID_PREFIX, CONFIDENCE_EXPLICIT, CONFIDENCE_FALLBACK, CONFIDENCE_NATIVE, DEFAULT_ANALYSIS_MAX_TOKENS, DEFAULT_ANALYSIS_TIMEOUT_MS, DEFAULT_CONSCIENCE_VALUES, DEFAULT_SUSTAINED_CHECKS_THRESHOLD, DEFAULT_THINKING_TOKEN_BUDGET, DEFAULT_WINDOW_MAX_AGE_SECONDS, DEFAULT_WINDOW_MAX_SIZE, DRIFT_ALERT_ID_PREFIX, DRIFT_SEVERITY_LOW_THRESHOLD, DRIFT_SEVERITY_MEDIUM_THRESHOLD, EU_COMPLIANCE_FAILURE_POLICY, EU_COMPLIANCE_WINDOW_CONFIG, FallbackAdapter, GoogleAdapter, MAX_EVIDENCE_LENGTH, MIN_WINDOW_SIZE, OpenAIAdapter, REGISTRATION_ID_PREFIX, TRUNCATION_HEAD_RATIO, TRUNCATION_TAIL_RATIO, WEBHOOK_MAX_RETRIES, WEBHOOK_RETRY_DELAYS_MS, WindowManager, buildConsciencePrompt, buildSignal, checkIntegrity, createAdapterRegistry, createClient, createDriftState, createWindowState, detectIntegrityDrift, hashThinkingBlock, mapVerdictToAction, mapVerdictToProceed, signPayload, summarizeCard, validateAgreement, verifyCertificate, verifySignature };
1553
1649
  //# sourceMappingURL=index.js.map
1554
1650
  //# sourceMappingURL=index.js.map