@private.me/xcontinuity 2.1.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/AGENTS.md +123 -0
- package/LICENSE.md +26 -0
- package/MIGRATING.md +77 -0
- package/README.md +601 -0
- package/dist/adjudicator.d.ts +75 -0
- package/dist/adjudicator.js +184 -0
- package/dist/cascade.d.ts +157 -0
- package/dist/cascade.js +323 -0
- package/dist/chronicle.d.ts +76 -0
- package/dist/chronicle.js +173 -0
- package/dist/cjs/adjudicator.js +189 -0
- package/dist/cjs/cascade.js +328 -0
- package/dist/cjs/chronicle.js +178 -0
- package/dist/cjs/enforcement.js +108 -0
- package/dist/cjs/errors.js +72 -0
- package/dist/cjs/index.js +108 -0
- package/dist/cjs/memory-runtime.js +129 -0
- package/dist/cjs/memory-session.js +134 -0
- package/dist/cjs/mission.js +178 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/provenance.js +192 -0
- package/dist/cjs/ratification.js +322 -0
- package/dist/cjs/reverse-xorida.js +506 -0
- package/dist/cjs/session.js +273 -0
- package/dist/cjs/state-serializer.js +300 -0
- package/dist/cjs/store-memory.js +33 -0
- package/dist/cjs/trust.js +133 -0
- package/dist/cjs/types.js +59 -0
- package/dist/enforcement.d.ts +40 -0
- package/dist/enforcement.js +104 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.js +68 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +43 -0
- package/dist/memory-runtime.d.ts +36 -0
- package/dist/memory-runtime.js +125 -0
- package/dist/memory-session.d.ts +38 -0
- package/dist/memory-session.js +97 -0
- package/dist/mission.d.ts +68 -0
- package/dist/mission.js +172 -0
- package/dist/provenance.d.ts +54 -0
- package/dist/provenance.js +182 -0
- package/dist/ratification.d.ts +113 -0
- package/dist/ratification.js +317 -0
- package/dist/reverse-xorida.d.ts +174 -0
- package/dist/reverse-xorida.js +490 -0
- package/dist/session.d.ts +102 -0
- package/dist/session.js +269 -0
- package/dist/state-serializer.d.ts +37 -0
- package/dist/state-serializer.js +294 -0
- package/dist/store-memory.d.ts +18 -0
- package/dist/store-memory.js +29 -0
- package/dist/trust.d.ts +76 -0
- package/dist/trust.js +121 -0
- package/dist/types.d.ts +320 -0
- package/dist/types.js +56 -0
- package/llms.txt +43 -0
- package/package.json +125 -0
- package/share1.dat +0 -0
package/dist/trust.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private.me/xcontinuity — Trust Tier Management
|
|
3
|
+
*
|
|
4
|
+
* Assigns and manages trust tiers for memory entries based on
|
|
5
|
+
* provenance verification, contradiction history, and temporal decay.
|
|
6
|
+
*
|
|
7
|
+
* Three tiers:
|
|
8
|
+
* ratified (3) — signed + verified by a known author
|
|
9
|
+
* inherited (2) — unsigned from a trusted source, or decayed from ratified
|
|
10
|
+
* quarantined (1) — unverified, contradicted, or failed verification
|
|
11
|
+
*/
|
|
12
|
+
import type { MemoryEntry, ProvenanceRecord, TrustTier } from './types.js';
|
|
13
|
+
import { TRUST_TIER_RANK, DEFAULT_MAX_AGE } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Determine the baseline trust tier for an entry based on its provenance.
|
|
16
|
+
*
|
|
17
|
+
* @param provenance - The provenance record (if present)
|
|
18
|
+
* @param signatureVerified - Whether the Ed25519 signature was verified
|
|
19
|
+
* @returns The baseline trust tier
|
|
20
|
+
*/
|
|
21
|
+
export declare function baselineTier(provenance: ProvenanceRecord | undefined, signatureVerified: boolean): TrustTier;
|
|
22
|
+
/**
|
|
23
|
+
* Apply contradiction-based downgrade to a trust tier.
|
|
24
|
+
*
|
|
25
|
+
* Rules:
|
|
26
|
+
* - 0 contradictions: no change
|
|
27
|
+
* - 1+ contradictions on inherited: downgrade to quarantined
|
|
28
|
+
* - 1+ contradictions on ratified: downgrade to inherited
|
|
29
|
+
* - quarantined stays quarantined regardless
|
|
30
|
+
*
|
|
31
|
+
* @param currentTier - The current trust tier
|
|
32
|
+
* @param contradictionCount - Number of active contradictions
|
|
33
|
+
* @returns The adjusted trust tier
|
|
34
|
+
*/
|
|
35
|
+
export declare function applyContradictionDowngrade(currentTier: TrustTier, contradictionCount: number): TrustTier;
|
|
36
|
+
/**
|
|
37
|
+
* Check whether a trust tier has decayed past its maxAge TTL.
|
|
38
|
+
*
|
|
39
|
+
* A ratified entry past its maxAge downgrades to inherited.
|
|
40
|
+
* Inherited and quarantined entries are not affected by decay.
|
|
41
|
+
*
|
|
42
|
+
* @param entry - The memory entry to check
|
|
43
|
+
* @param now - Current timestamp (ms). Defaults to Date.now().
|
|
44
|
+
* @returns true if the entry has expired and should be downgraded
|
|
45
|
+
*/
|
|
46
|
+
export declare function isDecayed(entry: MemoryEntry, now?: number): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Apply temporal decay to a trust tier.
|
|
49
|
+
*
|
|
50
|
+
* @param entry - The memory entry to evaluate
|
|
51
|
+
* @param now - Current timestamp (ms). Defaults to Date.now().
|
|
52
|
+
* @returns The effective trust tier after decay
|
|
53
|
+
*/
|
|
54
|
+
export declare function applyDecay(entry: MemoryEntry, now?: number): TrustTier;
|
|
55
|
+
/**
|
|
56
|
+
* Get the effective trust tier for an entry, considering both
|
|
57
|
+
* contradictions and temporal decay.
|
|
58
|
+
*
|
|
59
|
+
* @param entry - The memory entry
|
|
60
|
+
* @param now - Current timestamp (ms). Defaults to Date.now().
|
|
61
|
+
* @returns The effective trust tier
|
|
62
|
+
*/
|
|
63
|
+
export declare function effectiveTier(entry: MemoryEntry, now?: number): TrustTier;
|
|
64
|
+
/**
|
|
65
|
+
* Compare two trust tiers. Returns positive if a > b, negative if a < b, 0 if equal.
|
|
66
|
+
*/
|
|
67
|
+
export declare function compareTiers(a: TrustTier, b: TrustTier): number;
|
|
68
|
+
/**
|
|
69
|
+
* Check if tier `a` is strictly more trusted than tier `b`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isMoreTrusted(a: TrustTier, b: TrustTier): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get the least trusted tier from a list.
|
|
74
|
+
*/
|
|
75
|
+
export declare function leastTrusted(...tiers: TrustTier[]): TrustTier;
|
|
76
|
+
export { TRUST_TIER_RANK, DEFAULT_MAX_AGE };
|
package/dist/trust.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private.me/xcontinuity — Trust Tier Management
|
|
3
|
+
*
|
|
4
|
+
* Assigns and manages trust tiers for memory entries based on
|
|
5
|
+
* provenance verification, contradiction history, and temporal decay.
|
|
6
|
+
*
|
|
7
|
+
* Three tiers:
|
|
8
|
+
* ratified (3) — signed + verified by a known author
|
|
9
|
+
* inherited (2) — unsigned from a trusted source, or decayed from ratified
|
|
10
|
+
* quarantined (1) — unverified, contradicted, or failed verification
|
|
11
|
+
*/
|
|
12
|
+
import { TRUST_TIER_RANK, DEFAULT_MAX_AGE } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Determine the baseline trust tier for an entry based on its provenance.
|
|
15
|
+
*
|
|
16
|
+
* @param provenance - The provenance record (if present)
|
|
17
|
+
* @param signatureVerified - Whether the Ed25519 signature was verified
|
|
18
|
+
* @returns The baseline trust tier
|
|
19
|
+
*/
|
|
20
|
+
export function baselineTier(provenance, signatureVerified) {
|
|
21
|
+
if (!provenance)
|
|
22
|
+
return 'inherited';
|
|
23
|
+
if (signatureVerified)
|
|
24
|
+
return 'ratified';
|
|
25
|
+
return 'quarantined';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Apply contradiction-based downgrade to a trust tier.
|
|
29
|
+
*
|
|
30
|
+
* Rules:
|
|
31
|
+
* - 0 contradictions: no change
|
|
32
|
+
* - 1+ contradictions on inherited: downgrade to quarantined
|
|
33
|
+
* - 1+ contradictions on ratified: downgrade to inherited
|
|
34
|
+
* - quarantined stays quarantined regardless
|
|
35
|
+
*
|
|
36
|
+
* @param currentTier - The current trust tier
|
|
37
|
+
* @param contradictionCount - Number of active contradictions
|
|
38
|
+
* @returns The adjusted trust tier
|
|
39
|
+
*/
|
|
40
|
+
export function applyContradictionDowngrade(currentTier, contradictionCount) {
|
|
41
|
+
if (contradictionCount <= 0)
|
|
42
|
+
return currentTier;
|
|
43
|
+
switch (currentTier) {
|
|
44
|
+
case 'ratified':
|
|
45
|
+
return 'inherited';
|
|
46
|
+
case 'inherited':
|
|
47
|
+
return 'quarantined';
|
|
48
|
+
case 'quarantined':
|
|
49
|
+
return 'quarantined';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check whether a trust tier has decayed past its maxAge TTL.
|
|
54
|
+
*
|
|
55
|
+
* A ratified entry past its maxAge downgrades to inherited.
|
|
56
|
+
* Inherited and quarantined entries are not affected by decay.
|
|
57
|
+
*
|
|
58
|
+
* @param entry - The memory entry to check
|
|
59
|
+
* @param now - Current timestamp (ms). Defaults to Date.now().
|
|
60
|
+
* @returns true if the entry has expired and should be downgraded
|
|
61
|
+
*/
|
|
62
|
+
export function isDecayed(entry, now) {
|
|
63
|
+
if (entry.tier !== 'ratified')
|
|
64
|
+
return false;
|
|
65
|
+
if (entry.maxAge === undefined)
|
|
66
|
+
return false;
|
|
67
|
+
if (!Number.isFinite(entry.maxAge))
|
|
68
|
+
return false; // Infinity = no decay
|
|
69
|
+
const ratifiedAt = entry.ratifiedAt ?? entry.provenance?.timestamp ?? 0;
|
|
70
|
+
const elapsed = (now ?? Date.now()) - ratifiedAt;
|
|
71
|
+
return elapsed > entry.maxAge;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Apply temporal decay to a trust tier.
|
|
75
|
+
*
|
|
76
|
+
* @param entry - The memory entry to evaluate
|
|
77
|
+
* @param now - Current timestamp (ms). Defaults to Date.now().
|
|
78
|
+
* @returns The effective trust tier after decay
|
|
79
|
+
*/
|
|
80
|
+
export function applyDecay(entry, now) {
|
|
81
|
+
if (isDecayed(entry, now))
|
|
82
|
+
return 'inherited';
|
|
83
|
+
return entry.tier;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the effective trust tier for an entry, considering both
|
|
87
|
+
* contradictions and temporal decay.
|
|
88
|
+
*
|
|
89
|
+
* @param entry - The memory entry
|
|
90
|
+
* @param now - Current timestamp (ms). Defaults to Date.now().
|
|
91
|
+
* @returns The effective trust tier
|
|
92
|
+
*/
|
|
93
|
+
export function effectiveTier(entry, now) {
|
|
94
|
+
const afterDecay = applyDecay(entry, now);
|
|
95
|
+
return applyContradictionDowngrade(afterDecay, entry.contradictions.length);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Compare two trust tiers. Returns positive if a > b, negative if a < b, 0 if equal.
|
|
99
|
+
*/
|
|
100
|
+
export function compareTiers(a, b) {
|
|
101
|
+
return TRUST_TIER_RANK[a] - TRUST_TIER_RANK[b];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if tier `a` is strictly more trusted than tier `b`.
|
|
105
|
+
*/
|
|
106
|
+
export function isMoreTrusted(a, b) {
|
|
107
|
+
return TRUST_TIER_RANK[a] > TRUST_TIER_RANK[b];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the least trusted tier from a list.
|
|
111
|
+
*/
|
|
112
|
+
export function leastTrusted(...tiers) {
|
|
113
|
+
let min = 'ratified';
|
|
114
|
+
for (const t of tiers) {
|
|
115
|
+
if (TRUST_TIER_RANK[t] < TRUST_TIER_RANK[min]) {
|
|
116
|
+
min = t;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return min;
|
|
120
|
+
}
|
|
121
|
+
export { TRUST_TIER_RANK, DEFAULT_MAX_AGE };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private.me/xcontinuity — Type definitions and constants
|
|
3
|
+
*
|
|
4
|
+
* All types, interfaces, TLV type codes, and constants for the
|
|
5
|
+
* cryptographic state continuity substrate.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CONTINUITY_TLV: {
|
|
8
|
+
/** State metadata header */
|
|
9
|
+
readonly STATE_METADATA: 128;
|
|
10
|
+
/** Agent identifier */
|
|
11
|
+
readonly AGENT_ID: 129;
|
|
12
|
+
/** Session identifier */
|
|
13
|
+
readonly SESSION_ID: 130;
|
|
14
|
+
/** Sequence number (uint32) */
|
|
15
|
+
readonly SEQUENCE_NUMBER: 131;
|
|
16
|
+
/** Timestamp (float64 ms) */
|
|
17
|
+
readonly TIMESTAMP: 132;
|
|
18
|
+
/** Tag string */
|
|
19
|
+
readonly TAG: 133;
|
|
20
|
+
/** State key-value entry */
|
|
21
|
+
readonly STATE_ENTRY: 134;
|
|
22
|
+
/** Key name (UTF-8) */
|
|
23
|
+
readonly ENTRY_KEY: 135;
|
|
24
|
+
/** Entry value (typed) */
|
|
25
|
+
readonly ENTRY_VALUE: 136;
|
|
26
|
+
/** Description string */
|
|
27
|
+
readonly DESCRIPTION: 137;
|
|
28
|
+
/** Checksum (SHA-256) */
|
|
29
|
+
readonly CHECKSUM: 138;
|
|
30
|
+
};
|
|
31
|
+
export type ContinuityTlvType = (typeof CONTINUITY_TLV)[keyof typeof CONTINUITY_TLV];
|
|
32
|
+
export declare const VALUE_TYPE: {
|
|
33
|
+
readonly STRING: 1;
|
|
34
|
+
readonly NUMBER: 2;
|
|
35
|
+
readonly BOOLEAN: 3;
|
|
36
|
+
readonly BYTES: 4;
|
|
37
|
+
readonly NULL: 5;
|
|
38
|
+
readonly JSON: 6;
|
|
39
|
+
};
|
|
40
|
+
export type ValueTypeCode = (typeof VALUE_TYPE)[keyof typeof VALUE_TYPE];
|
|
41
|
+
/** Primitive and structured values storable in agent state. */
|
|
42
|
+
export type StateValue = string | number | boolean | Uint8Array | null | Record<string, unknown>;
|
|
43
|
+
/** Flat key-value map representing agent state at a point in time. */
|
|
44
|
+
export type AgentState = Record<string, StateValue>;
|
|
45
|
+
/** Metadata attached to a state snapshot. */
|
|
46
|
+
export interface StateMetadata {
|
|
47
|
+
readonly agentId: string;
|
|
48
|
+
readonly sessionId: string;
|
|
49
|
+
readonly sequenceNumber: number;
|
|
50
|
+
readonly createdAt: number;
|
|
51
|
+
readonly description?: string;
|
|
52
|
+
readonly tags: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
/** A serialized state snapshot with integrity checksum. */
|
|
55
|
+
export interface StateSnapshot {
|
|
56
|
+
readonly stateId: string;
|
|
57
|
+
readonly metadata: StateMetadata;
|
|
58
|
+
readonly serializedBytes: Uint8Array;
|
|
59
|
+
readonly checksum: Uint8Array;
|
|
60
|
+
}
|
|
61
|
+
/** Configuration for XorIDA threshold splitting. */
|
|
62
|
+
export interface SplitConfig {
|
|
63
|
+
/** Total number of shares to produce. Default: 3. */
|
|
64
|
+
readonly n: number;
|
|
65
|
+
/** Minimum shares needed for reconstruction. Default: 2. */
|
|
66
|
+
readonly k: number;
|
|
67
|
+
}
|
|
68
|
+
/** Default split configuration: 3-of-2 threshold. */
|
|
69
|
+
export declare const DEFAULT_SPLIT_CONFIG: SplitConfig;
|
|
70
|
+
/** A single XorIDA share of a state snapshot. */
|
|
71
|
+
export interface StateShare {
|
|
72
|
+
readonly stateId: string;
|
|
73
|
+
readonly index: number;
|
|
74
|
+
readonly n: number;
|
|
75
|
+
readonly k: number;
|
|
76
|
+
readonly data: Uint8Array;
|
|
77
|
+
readonly hmacKey: Uint8Array;
|
|
78
|
+
readonly hmacSignature: Uint8Array;
|
|
79
|
+
}
|
|
80
|
+
/** The complete split result containing all shares and metadata. */
|
|
81
|
+
export interface SplitState {
|
|
82
|
+
readonly stateId: string;
|
|
83
|
+
readonly metadata: StateMetadata;
|
|
84
|
+
readonly shares: readonly StateShare[];
|
|
85
|
+
readonly n: number;
|
|
86
|
+
readonly k: number;
|
|
87
|
+
/** The padded byte length used for this split (needed for incremental updates). */
|
|
88
|
+
readonly paddedLength: number;
|
|
89
|
+
}
|
|
90
|
+
/** A byte-level delta between two padded state snapshots. */
|
|
91
|
+
export interface StateDelta {
|
|
92
|
+
readonly fromStateId: string;
|
|
93
|
+
readonly toStateId: string;
|
|
94
|
+
readonly deltaBytes: Uint8Array;
|
|
95
|
+
readonly fromChecksum: Uint8Array;
|
|
96
|
+
readonly toChecksum: Uint8Array;
|
|
97
|
+
}
|
|
98
|
+
/** Session status lifecycle: active -> suspended -> active (resume), active -> closed (terminal). */
|
|
99
|
+
export type SessionStatus = 'active' | 'suspended' | 'closed';
|
|
100
|
+
/** A continuity session tracking agent state across time. */
|
|
101
|
+
export interface ContinuitySession {
|
|
102
|
+
readonly sessionId: string;
|
|
103
|
+
readonly agentId: string;
|
|
104
|
+
readonly status: SessionStatus;
|
|
105
|
+
readonly splitConfig: SplitConfig;
|
|
106
|
+
readonly createdAt: number;
|
|
107
|
+
readonly updatedAt: number;
|
|
108
|
+
readonly snapshotCount: number;
|
|
109
|
+
}
|
|
110
|
+
/** Configuration for creating a new session. */
|
|
111
|
+
export interface SessionConfig {
|
|
112
|
+
readonly agentId: string;
|
|
113
|
+
readonly store: StateStore;
|
|
114
|
+
readonly splitConfig?: SplitConfig;
|
|
115
|
+
}
|
|
116
|
+
/** An entry in the ordered state history. */
|
|
117
|
+
export interface ChronicleEntry {
|
|
118
|
+
readonly stateId: string;
|
|
119
|
+
readonly sessionId: string;
|
|
120
|
+
readonly sequence: number;
|
|
121
|
+
readonly timestamp: number;
|
|
122
|
+
readonly description?: string;
|
|
123
|
+
readonly tags: readonly string[];
|
|
124
|
+
readonly parentStateId?: string;
|
|
125
|
+
}
|
|
126
|
+
/** Query filters for chronicle entries. */
|
|
127
|
+
export interface ChronicleQuery {
|
|
128
|
+
readonly sessionId?: string;
|
|
129
|
+
readonly after?: number;
|
|
130
|
+
readonly before?: number;
|
|
131
|
+
readonly tags?: readonly string[];
|
|
132
|
+
readonly limit?: number;
|
|
133
|
+
readonly offset?: number;
|
|
134
|
+
}
|
|
135
|
+
/** Async storage backend for XorIDA-split state. */
|
|
136
|
+
export interface StateStore {
|
|
137
|
+
putShares(splitState: SplitState): Promise<void>;
|
|
138
|
+
getShares(stateId: string): Promise<SplitState | null>;
|
|
139
|
+
deleteShares(stateId: string): Promise<void>;
|
|
140
|
+
listStateIds(): Promise<string[]>;
|
|
141
|
+
}
|
|
142
|
+
/** A single entry in the runtime memory layer. */
|
|
143
|
+
export interface RuntimeEntry {
|
|
144
|
+
readonly key: string;
|
|
145
|
+
readonly value: StateValue;
|
|
146
|
+
readonly accessCount: number;
|
|
147
|
+
readonly createdAt: number;
|
|
148
|
+
readonly updatedAt: number;
|
|
149
|
+
}
|
|
150
|
+
/** Configuration for the runtime memory layer. */
|
|
151
|
+
export interface RuntimeMemoryConfig {
|
|
152
|
+
/** Maximum number of entries before LRU eviction. Default: 1000. */
|
|
153
|
+
readonly maxEntries: number;
|
|
154
|
+
}
|
|
155
|
+
export declare const DEFAULT_RUNTIME_MEMORY_CONFIG: RuntimeMemoryConfig;
|
|
156
|
+
/**
|
|
157
|
+
* Ed25519 public key identifier for an agent or authority.
|
|
158
|
+
* Encoded as base64url string of the 32-byte public key.
|
|
159
|
+
*/
|
|
160
|
+
export type AuthorRef = string;
|
|
161
|
+
/** Trust classification for a memory entry. */
|
|
162
|
+
export type TrustTier = 'ratified' | 'inherited' | 'quarantined';
|
|
163
|
+
/** Numeric ranking for trust tier comparison (higher = more trusted). */
|
|
164
|
+
export declare const TRUST_TIER_RANK: Record<TrustTier, number>;
|
|
165
|
+
/** Cryptographic provenance record attached to a memory entry. */
|
|
166
|
+
export interface ProvenanceRecord {
|
|
167
|
+
/** Author who created/signed this entry. */
|
|
168
|
+
readonly author: AuthorRef;
|
|
169
|
+
/** Timestamp of creation (ms since epoch). */
|
|
170
|
+
readonly timestamp: number;
|
|
171
|
+
/** Ed25519 signature over canonical entry bytes. */
|
|
172
|
+
readonly signature: Uint8Array;
|
|
173
|
+
/** SHA-256 hash of the parent entry (chain integrity). */
|
|
174
|
+
readonly parentHash?: Uint8Array;
|
|
175
|
+
}
|
|
176
|
+
/** A memory entry with trust metadata. */
|
|
177
|
+
export interface MemoryEntry {
|
|
178
|
+
/** Entry key. */
|
|
179
|
+
readonly key: string;
|
|
180
|
+
/** Entry value. */
|
|
181
|
+
readonly value: StateValue;
|
|
182
|
+
/** Cryptographic provenance (present if signed). */
|
|
183
|
+
readonly provenance?: ProvenanceRecord;
|
|
184
|
+
/** Current trust tier. */
|
|
185
|
+
readonly tier: TrustTier;
|
|
186
|
+
/** Keys of contradicting entries detected by chronicle. */
|
|
187
|
+
readonly contradictions: readonly string[];
|
|
188
|
+
/** Optional TTL — entry auto-downgrades to inherited after maxAge ms. */
|
|
189
|
+
readonly maxAge?: number;
|
|
190
|
+
/** Timestamp when this entry was last verified/ratified. */
|
|
191
|
+
readonly ratifiedAt?: number;
|
|
192
|
+
}
|
|
193
|
+
/** A tracked belief with confidence and sourcing. */
|
|
194
|
+
export interface TrackedBelief {
|
|
195
|
+
/** The claim being tracked. */
|
|
196
|
+
readonly claim: string;
|
|
197
|
+
/** Confidence level 0.0–1.0. */
|
|
198
|
+
readonly confidence: number;
|
|
199
|
+
/** AuthorRef of the source agent. */
|
|
200
|
+
readonly source: AuthorRef;
|
|
201
|
+
/** Current trust tier. */
|
|
202
|
+
readonly tier: TrustTier;
|
|
203
|
+
}
|
|
204
|
+
/** Default TTL for trust tier decay (30 days in ms). */
|
|
205
|
+
export declare const DEFAULT_MAX_AGE: number;
|
|
206
|
+
/** Resolution result from an adjudicator. */
|
|
207
|
+
export interface AdjudicatorResult {
|
|
208
|
+
/** The winning entry. */
|
|
209
|
+
readonly winner: MemoryEntry;
|
|
210
|
+
/** Reason for the resolution. */
|
|
211
|
+
readonly reason: string;
|
|
212
|
+
}
|
|
213
|
+
/** View from a single agent for consensus adjudication. */
|
|
214
|
+
export interface AgentView {
|
|
215
|
+
/** The agent providing this view. */
|
|
216
|
+
readonly author: AuthorRef;
|
|
217
|
+
/** The entry this agent holds for the contested key. */
|
|
218
|
+
readonly entry: MemoryEntry;
|
|
219
|
+
}
|
|
220
|
+
/** A human-anchored mission record with crypto-gated authority. */
|
|
221
|
+
export interface MissionRecord {
|
|
222
|
+
/** Unique mission identifier. */
|
|
223
|
+
readonly missionId: string;
|
|
224
|
+
/** Human-readable goal description. */
|
|
225
|
+
readonly goal: string;
|
|
226
|
+
/** AuthorRef of the human authority who signed this mission. */
|
|
227
|
+
readonly authority: AuthorRef;
|
|
228
|
+
/** Ed25519 signature over canonical mission bytes. */
|
|
229
|
+
readonly signature: Uint8Array;
|
|
230
|
+
/** Mission creation timestamp (ms since epoch). */
|
|
231
|
+
readonly issuedAt: number;
|
|
232
|
+
/** Mission expiry timestamp (ms since epoch). Undefined = no expiry. */
|
|
233
|
+
readonly expiresAt?: number;
|
|
234
|
+
/** Scope tags limiting what this mission authorizes. */
|
|
235
|
+
readonly scopes: readonly string[];
|
|
236
|
+
}
|
|
237
|
+
/** A hard constraint that evaluates actions against mission boundaries. */
|
|
238
|
+
export interface HardConstraint {
|
|
239
|
+
/** Unique constraint identifier. */
|
|
240
|
+
readonly constraintId: string;
|
|
241
|
+
/** Human-readable description of the constraint. */
|
|
242
|
+
readonly description: string;
|
|
243
|
+
/** Evaluate whether an action violates this constraint. */
|
|
244
|
+
evaluate(action: ProposedAction): ConstraintResult;
|
|
245
|
+
}
|
|
246
|
+
/** An action proposed by an agent, subject to constraint evaluation. */
|
|
247
|
+
export interface ProposedAction {
|
|
248
|
+
/** The agent proposing the action. */
|
|
249
|
+
readonly author: AuthorRef;
|
|
250
|
+
/** Action type (write, delete, ratify, etc.). */
|
|
251
|
+
readonly type: string;
|
|
252
|
+
/** Target key being acted on. */
|
|
253
|
+
readonly key: string;
|
|
254
|
+
/** Proposed value (for write actions). */
|
|
255
|
+
readonly value?: StateValue;
|
|
256
|
+
/** Additional metadata. */
|
|
257
|
+
readonly metadata?: Record<string, unknown>;
|
|
258
|
+
}
|
|
259
|
+
/** Result of constraint evaluation. */
|
|
260
|
+
export interface ConstraintResult {
|
|
261
|
+
/** Whether the action is allowed. */
|
|
262
|
+
readonly allowed: boolean;
|
|
263
|
+
/** Reason for denial (when allowed=false). */
|
|
264
|
+
readonly reason?: string;
|
|
265
|
+
/** Suggested alternative action (for rewrite). */
|
|
266
|
+
readonly suggestion?: ProposedAction;
|
|
267
|
+
}
|
|
268
|
+
/** Enforcement decision for a proposed action. */
|
|
269
|
+
export type EnforcementDecision = 'allow' | 'reject' | 'rewrite' | 'escalate';
|
|
270
|
+
/** Result from the enforcement loop. */
|
|
271
|
+
export interface EnforcementResult {
|
|
272
|
+
/** The decision. */
|
|
273
|
+
readonly decision: EnforcementDecision;
|
|
274
|
+
/** The original action. */
|
|
275
|
+
readonly action: ProposedAction;
|
|
276
|
+
/** Reason for the decision (when not 'allow'). */
|
|
277
|
+
readonly reason?: string;
|
|
278
|
+
/** Rewritten action (when decision is 'rewrite'). */
|
|
279
|
+
readonly rewrittenAction?: ProposedAction;
|
|
280
|
+
/** Cumulative violation count for this agent (when decision is 'escalate'). */
|
|
281
|
+
readonly violationCount?: number;
|
|
282
|
+
}
|
|
283
|
+
/** Configuration for the enforcement loop. */
|
|
284
|
+
export interface EnforcementConfig {
|
|
285
|
+
/** Number of violations before escalation. Default: 3. */
|
|
286
|
+
readonly escalationThreshold: number;
|
|
287
|
+
/** Callback invoked on escalation. */
|
|
288
|
+
readonly onEscalate?: (result: EnforcementResult) => void;
|
|
289
|
+
}
|
|
290
|
+
export declare const DEFAULT_ENFORCEMENT_CONFIG: EnforcementConfig;
|
|
291
|
+
/** Event types emitted by TrustStore. */
|
|
292
|
+
export type TrustStoreEventType = 'change' | 'contradiction' | 'tierChange' | 'escalation';
|
|
293
|
+
/** Payload for a 'change' event. */
|
|
294
|
+
export interface ChangeEvent {
|
|
295
|
+
readonly key: string;
|
|
296
|
+
readonly oldEntry?: MemoryEntry;
|
|
297
|
+
readonly newEntry: MemoryEntry;
|
|
298
|
+
}
|
|
299
|
+
/** Payload for a 'contradiction' event. */
|
|
300
|
+
export interface ContradictionEvent {
|
|
301
|
+
readonly key: string;
|
|
302
|
+
readonly existing: MemoryEntry;
|
|
303
|
+
readonly incoming: MemoryEntry;
|
|
304
|
+
}
|
|
305
|
+
/** Payload for a 'tierChange' event. */
|
|
306
|
+
export interface TierChangeEvent {
|
|
307
|
+
readonly key: string;
|
|
308
|
+
readonly oldTier: TrustTier;
|
|
309
|
+
readonly newTier: TrustTier;
|
|
310
|
+
readonly reason: string;
|
|
311
|
+
}
|
|
312
|
+
/** Payload for an 'escalation' event. */
|
|
313
|
+
export interface EscalationEvent {
|
|
314
|
+
readonly action: ProposedAction;
|
|
315
|
+
readonly violationCount: number;
|
|
316
|
+
}
|
|
317
|
+
/** Union of all TrustStore event payloads. */
|
|
318
|
+
export type TrustStoreEvent = ChangeEvent | ContradictionEvent | TierChangeEvent | EscalationEvent;
|
|
319
|
+
/** TrustStore event listener callback. */
|
|
320
|
+
export type TrustStoreListener<T extends TrustStoreEvent = TrustStoreEvent> = (event: T) => void;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private.me/xcontinuity — Type definitions and constants
|
|
3
|
+
*
|
|
4
|
+
* All types, interfaces, TLV type codes, and constants for the
|
|
5
|
+
* cryptographic state continuity substrate.
|
|
6
|
+
*/
|
|
7
|
+
/* ── TLV Type Codes (0x80+ to avoid collision with shared TLV_TYPE 0x01-0x0d) ── */
|
|
8
|
+
export const CONTINUITY_TLV = {
|
|
9
|
+
/** State metadata header */
|
|
10
|
+
STATE_METADATA: 0x80,
|
|
11
|
+
/** Agent identifier */
|
|
12
|
+
AGENT_ID: 0x81,
|
|
13
|
+
/** Session identifier */
|
|
14
|
+
SESSION_ID: 0x82,
|
|
15
|
+
/** Sequence number (uint32) */
|
|
16
|
+
SEQUENCE_NUMBER: 0x83,
|
|
17
|
+
/** Timestamp (float64 ms) */
|
|
18
|
+
TIMESTAMP: 0x84,
|
|
19
|
+
/** Tag string */
|
|
20
|
+
TAG: 0x85,
|
|
21
|
+
/** State key-value entry */
|
|
22
|
+
STATE_ENTRY: 0x86,
|
|
23
|
+
/** Key name (UTF-8) */
|
|
24
|
+
ENTRY_KEY: 0x87,
|
|
25
|
+
/** Entry value (typed) */
|
|
26
|
+
ENTRY_VALUE: 0x88,
|
|
27
|
+
/** Description string */
|
|
28
|
+
DESCRIPTION: 0x89,
|
|
29
|
+
/** Checksum (SHA-256) */
|
|
30
|
+
CHECKSUM: 0x8a,
|
|
31
|
+
};
|
|
32
|
+
/* ── Value Type Markers ── */
|
|
33
|
+
export const VALUE_TYPE = {
|
|
34
|
+
STRING: 0x01,
|
|
35
|
+
NUMBER: 0x02,
|
|
36
|
+
BOOLEAN: 0x03,
|
|
37
|
+
BYTES: 0x04,
|
|
38
|
+
NULL: 0x05,
|
|
39
|
+
JSON: 0x06,
|
|
40
|
+
};
|
|
41
|
+
/** Default split configuration: 3-of-2 threshold. */
|
|
42
|
+
export const DEFAULT_SPLIT_CONFIG = { n: 3, k: 2 };
|
|
43
|
+
export const DEFAULT_RUNTIME_MEMORY_CONFIG = {
|
|
44
|
+
maxEntries: 1000,
|
|
45
|
+
};
|
|
46
|
+
/** Numeric ranking for trust tier comparison (higher = more trusted). */
|
|
47
|
+
export const TRUST_TIER_RANK = {
|
|
48
|
+
ratified: 3,
|
|
49
|
+
inherited: 2,
|
|
50
|
+
quarantined: 1,
|
|
51
|
+
};
|
|
52
|
+
/** Default TTL for trust tier decay (30 days in ms). */
|
|
53
|
+
export const DEFAULT_MAX_AGE = 30 * 24 * 60 * 60 * 1000;
|
|
54
|
+
export const DEFAULT_ENFORCEMENT_CONFIG = {
|
|
55
|
+
escalationThreshold: 3,
|
|
56
|
+
};
|
package/llms.txt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @private.me/xcontinuity — LLM Context
|
|
2
|
+
|
|
3
|
+
> Cryptographic state continuity for AI agents — Reverse-XorIDA with trust substrate, provenance, and enforcement
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
xcontinuity v2.0.0 provides cryptographic state continuity with a trust substrate for AI agents. Core primitive: Reverse-XorIDA exploits GF(2) linearity for O(delta) incremental state updates. Trust substrate adds Ed25519 provenance, trust tiers with TTL decay, conflict adjudication, mission-anchored enforcement, and ratification.
|
|
8
|
+
|
|
9
|
+
## Key APIs
|
|
10
|
+
|
|
11
|
+
- `SessionManager.create(config)` — Create session (optional trust substrate integration)
|
|
12
|
+
- `session.updateState(patch)` — Merge patch (routes through enforcement + trust store if configured)
|
|
13
|
+
- `session.snapshot(description?, tags?)` — Persist state as XorIDA shares
|
|
14
|
+
- `session.restore(stateId)` — Reconstruct state from shares
|
|
15
|
+
- `session.suspend()` / `session.resume()` — Pause and resume sessions
|
|
16
|
+
- `TrustStore` — Trust-annotated entries with write/ratify/restore/hypothesisMode
|
|
17
|
+
- `generateSigningKeyPair()` / `signEntry()` / `verifyEntry()` — Ed25519 provenance
|
|
18
|
+
- `MissionGuard` — Human-anchored constraint evaluation
|
|
19
|
+
- `EnforcementLoop` — Reject/rewrite/escalate with violation tracking
|
|
20
|
+
- `PolicyAdjudicator` / `ConsensusAdjudicator` — Deterministic conflict resolution
|
|
21
|
+
- `undoDelta` / `branchState` / `squashDeltas` — Algebraic extensions over GF(2)
|
|
22
|
+
- `blindUpdateShare` / `refreshShares` / `blindEqual` — Zero-knowledge share operations
|
|
23
|
+
- `Chronicle` — Ordered state history with contradiction detection
|
|
24
|
+
|
|
25
|
+
## Trust Tiers
|
|
26
|
+
|
|
27
|
+
ratified (signed + verified) → inherited (unsigned or decayed) → quarantined (invalid signature)
|
|
28
|
+
TTL decay: ratified entries auto-downgrade to inherited after configurable maxAge (default 30 days)
|
|
29
|
+
|
|
30
|
+
## Dependencies
|
|
31
|
+
|
|
32
|
+
- @private.me/shared (Result<T,E>, ok(), err())
|
|
33
|
+
- @private.me/crypto (XorIDA, HMAC, padding, UUID, base64)
|
|
34
|
+
- Web Crypto API (Ed25519 — zero external crypto dependencies)
|
|
35
|
+
|
|
36
|
+
## Error Handling
|
|
37
|
+
|
|
38
|
+
All fallible functions return `Result<T, ContinuityError>`. Check `result.ok` before accessing `result.value`. 23 structured error codes across 7 families.
|
|
39
|
+
|
|
40
|
+
## Resources
|
|
41
|
+
|
|
42
|
+
- npm: https://npmjs.com/package/@private.me/xcontinuity
|
|
43
|
+
- GitHub: https://github.com/xail-io/xail/tree/main/packages/xcontinuity
|