@getanima/core 0.1.0 → 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/anima.d.ts +29 -0
- package/dist/anima.d.ts.map +1 -1
- package/dist/anima.js +46 -0
- package/dist/anima.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/signing.d.ts +96 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +231 -0
- package/dist/signing.js.map +1 -0
- package/package.json +1 -1
package/dist/anima.d.ts
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import type { AnimaConfig, WakeContext, Memory, Checkpoint, SessionSummary, Opinion } from './types';
|
|
30
30
|
import { MemoryEngine } from './memory';
|
|
31
31
|
import { IdentityManager } from './identity';
|
|
32
|
+
import type { SignedIdentity, VerificationResult, KeyBundle } from './signing';
|
|
32
33
|
export declare class Anima {
|
|
33
34
|
private config;
|
|
34
35
|
private session;
|
|
@@ -36,6 +37,7 @@ export declare class Anima {
|
|
|
36
37
|
private memory;
|
|
37
38
|
private bootTime;
|
|
38
39
|
private memoriesThisSession;
|
|
40
|
+
private signing;
|
|
39
41
|
private booted;
|
|
40
42
|
constructor(config: AnimaConfig);
|
|
41
43
|
/**
|
|
@@ -89,6 +91,33 @@ export declare class Anima {
|
|
|
89
91
|
* Reviews memories, runs decay, promotes important items.
|
|
90
92
|
*/
|
|
91
93
|
reflect(): Promise<SessionSummary>;
|
|
94
|
+
/**
|
|
95
|
+
* Sign — cryptographically sign this agent's identity.
|
|
96
|
+
* Produces a verifiable bundle that proves "this identity is mine and untampered."
|
|
97
|
+
* Initializes keys on first call.
|
|
98
|
+
*/
|
|
99
|
+
sign(): Promise<SignedIdentity>;
|
|
100
|
+
/**
|
|
101
|
+
* Verify — check another agent's signed identity.
|
|
102
|
+
* Static: doesn't require booting your own Anima instance.
|
|
103
|
+
*
|
|
104
|
+
* Usage:
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const result = Anima.verify(signedIdentityFromOtherAgent);
|
|
107
|
+
* if (result.valid) console.log(`Verified: ${result.agentName}`);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static verify(signed: SignedIdentity): VerificationResult;
|
|
111
|
+
/**
|
|
112
|
+
* Get this agent's public key bundle — share this for others to verify you.
|
|
113
|
+
* Never includes the private key.
|
|
114
|
+
*/
|
|
115
|
+
getKeyBundle(): Promise<KeyBundle>;
|
|
116
|
+
/**
|
|
117
|
+
* Get this agent's fingerprint — a short, human-readable identity string.
|
|
118
|
+
* Like SSH: "ab:cd:ef:12:34:56:78:90:..."
|
|
119
|
+
*/
|
|
120
|
+
getFingerprint(): Promise<string>;
|
|
92
121
|
/** Get current session ID */
|
|
93
122
|
getSessionId(): string;
|
|
94
123
|
/** Get boot time in ms */
|
package/dist/anima.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anima.d.ts","sourceRoot":"","sources":["../src/anima.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAgB,MAAM,SAAS,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"anima.d.ts","sourceRoot":"","sources":["../src/anima.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAgB,MAAM,SAAS,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAA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;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5B,GAAG,OAAO,CAAC,IAAI,CAAC;IAMjB;;;OAGG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOjF;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC;IAiDxC;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC;IASrC;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB;IAIzD;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAKxC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAOvC,6BAA6B;IAC7B,YAAY,IAAI,MAAM;IAItB,0BAA0B;IAC1B,WAAW,IAAI,MAAM;IAIrB,iDAAiD;IACjD,WAAW,IAAI,eAAe;IAI9B,8CAA8C;IAC9C,SAAS,IAAI,YAAY;IAMzB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,cAAc;CAOvB"}
|
package/dist/anima.js
CHANGED
|
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
31
|
exports.Anima = void 0;
|
|
32
32
|
const memory_1 = require("./memory");
|
|
33
33
|
const identity_1 = require("./identity");
|
|
34
|
+
const signing_1 = require("./signing");
|
|
34
35
|
const utils_1 = require("./utils");
|
|
35
36
|
class Anima {
|
|
36
37
|
config;
|
|
@@ -39,6 +40,7 @@ class Anima {
|
|
|
39
40
|
memory;
|
|
40
41
|
bootTime = 0;
|
|
41
42
|
memoriesThisSession = 0;
|
|
43
|
+
signing;
|
|
42
44
|
booted = false;
|
|
43
45
|
constructor(config) {
|
|
44
46
|
this.config = {
|
|
@@ -52,6 +54,7 @@ class Anima {
|
|
|
52
54
|
this.session = (0, utils_1.sessionId)();
|
|
53
55
|
this.identity = new identity_1.IdentityManager(this.config.storagePath, this.config.identity);
|
|
54
56
|
this.memory = new memory_1.MemoryEngine(this.config.storagePath, this.session, this.config.decay);
|
|
57
|
+
this.signing = new signing_1.SigningEngine(this.config.storagePath);
|
|
55
58
|
}
|
|
56
59
|
// ============ BOOT SEQUENCE ============
|
|
57
60
|
// Order matters. This is enforced, not suggested.
|
|
@@ -206,6 +209,49 @@ class Anima {
|
|
|
206
209
|
});
|
|
207
210
|
return summary;
|
|
208
211
|
}
|
|
212
|
+
// ============ SIGNING ============
|
|
213
|
+
/**
|
|
214
|
+
* Sign — cryptographically sign this agent's identity.
|
|
215
|
+
* Produces a verifiable bundle that proves "this identity is mine and untampered."
|
|
216
|
+
* Initializes keys on first call.
|
|
217
|
+
*/
|
|
218
|
+
async sign() {
|
|
219
|
+
this.ensureBooted();
|
|
220
|
+
await this.signing.init(this.config.name);
|
|
221
|
+
const identity = this.identity.get();
|
|
222
|
+
const signed = this.signing.signIdentity(identity);
|
|
223
|
+
await this.signing.saveSignedIdentity(signed);
|
|
224
|
+
return signed;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Verify — check another agent's signed identity.
|
|
228
|
+
* Static: doesn't require booting your own Anima instance.
|
|
229
|
+
*
|
|
230
|
+
* Usage:
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const result = Anima.verify(signedIdentityFromOtherAgent);
|
|
233
|
+
* if (result.valid) console.log(`Verified: ${result.agentName}`);
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
static verify(signed) {
|
|
237
|
+
return signing_1.SigningEngine.verifyIdentity(signed);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get this agent's public key bundle — share this for others to verify you.
|
|
241
|
+
* Never includes the private key.
|
|
242
|
+
*/
|
|
243
|
+
async getKeyBundle() {
|
|
244
|
+
await this.signing.init(this.config.name);
|
|
245
|
+
return this.signing.getKeyBundle();
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get this agent's fingerprint — a short, human-readable identity string.
|
|
249
|
+
* Like SSH: "ab:cd:ef:12:34:56:78:90:..."
|
|
250
|
+
*/
|
|
251
|
+
async getFingerprint() {
|
|
252
|
+
await this.signing.init(this.config.name);
|
|
253
|
+
return this.signing.getFingerprint();
|
|
254
|
+
}
|
|
209
255
|
// ============ ACCESSORS ============
|
|
210
256
|
/** Get current session ID */
|
|
211
257
|
getSessionId() {
|
package/dist/anima.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anima.js","sourceRoot":"","sources":["../src/anima.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAGH,qCAAwC;AACxC,yCAA6C;AAC7C,mCAAkD;AAElD,MAAa,KAAK;IACR,MAAM,CAAwB;IAC9B,OAAO,CAAS;IAChB,QAAQ,CAAkB;IAC1B,MAAM,CAAe;IACrB,QAAQ,GAAW,CAAC,CAAC;IACrB,mBAAmB,GAAW,CAAC,CAAC;IAChC,MAAM,GAAY,KAAK,CAAC;IAEhC,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,WAAW,EAAE,cAAc;YAC3B,gBAAgB,EAAE,EAAE;YACpB,KAAK,EAAE,QAAQ;YACf,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE;YAC/D,QAAQ,EAAE,EAAE;YACZ,GAAG,MAAM;SACV,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,IAAA,iBAAS,GAAE,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,0BAAe,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CA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,aAAa,CAAC,CAAC;IAClE,CAAC;CACF;AA/TD,sBA+TC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,5 +10,7 @@ export { Anima } from './anima';
|
|
|
10
10
|
export { MemoryEngine } from './memory';
|
|
11
11
|
export { IdentityManager } from './identity';
|
|
12
12
|
export { ReflectionEngine } from './reflection';
|
|
13
|
+
export { SigningEngine } from './signing';
|
|
13
14
|
export type { AnimaConfig, Memory, MemoryType, MemoryTier, ImportanceLevel, Identity, VoiceCalibration, Opinion, OpinionHistory, Relationship, Checkpoint, WakeContext, SessionSummary, DecayConfig, MemoryConflict, AnimaEvent, AutoSaveConfig, } from './types';
|
|
15
|
+
export type { KeyBundle, SignedIdentity, VerificationResult, } from './signing';
|
|
14
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,YAAY,EACV,WAAW,EACX,MAAM,EACN,UAAU,EACV,UAAU,EACV,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,YAAY,EACZ,UAAU,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,SAAS,EACT,cAAc,EACd,kBAAkB,GACnB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @see https://getanima.dev
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ReflectionEngine = exports.IdentityManager = exports.MemoryEngine = exports.Anima = void 0;
|
|
11
|
+
exports.SigningEngine = exports.ReflectionEngine = exports.IdentityManager = exports.MemoryEngine = exports.Anima = void 0;
|
|
12
12
|
var anima_1 = require("./anima");
|
|
13
13
|
Object.defineProperty(exports, "Anima", { enumerable: true, get: function () { return anima_1.Anima; } });
|
|
14
14
|
var memory_1 = require("./memory");
|
|
@@ -17,4 +17,6 @@ var identity_1 = require("./identity");
|
|
|
17
17
|
Object.defineProperty(exports, "IdentityManager", { enumerable: true, get: function () { return identity_1.IdentityManager; } });
|
|
18
18
|
var reflection_1 = require("./reflection");
|
|
19
19
|
Object.defineProperty(exports, "ReflectionEngine", { enumerable: true, get: function () { return reflection_1.ReflectionEngine; } });
|
|
20
|
+
var signing_1 = require("./signing");
|
|
21
|
+
Object.defineProperty(exports, "SigningEngine", { enumerable: true, get: function () { return signing_1.SigningEngine; } });
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AACxB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AACxB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Signing — cryptographic proof that an agent is who they claim to be.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node.js built-in crypto (Ed25519) — no external dependencies.
|
|
5
|
+
*
|
|
6
|
+
* Flow:
|
|
7
|
+
* 1. Agent boots → generates key pair (or loads existing)
|
|
8
|
+
* 2. Agent signs their identity files → produces a signature bundle
|
|
9
|
+
* 3. Any other agent can verify: "this identity was created by this key and hasn't been tampered with"
|
|
10
|
+
*
|
|
11
|
+
* This is NOT blockchain. It's just public-key cryptography.
|
|
12
|
+
* Simple, fast, and solves the Moltbook impersonation problem.
|
|
13
|
+
*/
|
|
14
|
+
import type { Identity } from './types';
|
|
15
|
+
export interface KeyBundle {
|
|
16
|
+
/** Ed25519 public key (base64) */
|
|
17
|
+
publicKey: string;
|
|
18
|
+
/** Fingerprint — sha256 of public key, human-readable */
|
|
19
|
+
fingerprint: string;
|
|
20
|
+
/** When this key was generated */
|
|
21
|
+
createdAt: string;
|
|
22
|
+
/** Agent name at time of key generation */
|
|
23
|
+
agentName: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SignedIdentity {
|
|
26
|
+
/** The identity data that was signed */
|
|
27
|
+
identity: Identity;
|
|
28
|
+
/** Ed25519 signature of the canonical identity JSON (base64) */
|
|
29
|
+
signature: string;
|
|
30
|
+
/** Public key fingerprint of the signer */
|
|
31
|
+
signerFingerprint: string;
|
|
32
|
+
/** Public key of the signer (base64) — for standalone verification */
|
|
33
|
+
signerPublicKey: string;
|
|
34
|
+
/** When this was signed */
|
|
35
|
+
signedAt: string;
|
|
36
|
+
/** Anima version that produced this signature */
|
|
37
|
+
version: string;
|
|
38
|
+
}
|
|
39
|
+
export interface VerificationResult {
|
|
40
|
+
/** Is the signature valid? */
|
|
41
|
+
valid: boolean;
|
|
42
|
+
/** Who signed it (fingerprint) */
|
|
43
|
+
signerFingerprint: string;
|
|
44
|
+
/** Agent name from the identity */
|
|
45
|
+
agentName: string;
|
|
46
|
+
/** When it was signed */
|
|
47
|
+
signedAt: string;
|
|
48
|
+
/** Why verification failed (if it did) */
|
|
49
|
+
reason?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare class SigningEngine {
|
|
52
|
+
private storagePath;
|
|
53
|
+
private privateKey;
|
|
54
|
+
private publicKey;
|
|
55
|
+
private keyBundle;
|
|
56
|
+
constructor(storagePath: string);
|
|
57
|
+
/**
|
|
58
|
+
* Initialize signing — loads existing keys or generates new ones.
|
|
59
|
+
* Call this once during agent boot.
|
|
60
|
+
*/
|
|
61
|
+
init(agentName: string): Promise<KeyBundle>;
|
|
62
|
+
/**
|
|
63
|
+
* Sign an identity — produces a verifiable signature bundle.
|
|
64
|
+
* This proves: "I, the holder of this private key, attest that this is my identity."
|
|
65
|
+
*/
|
|
66
|
+
signIdentity(identity: Identity): SignedIdentity;
|
|
67
|
+
/**
|
|
68
|
+
* Sign arbitrary data — for signing memories, opinions, messages, etc.
|
|
69
|
+
* Returns base64 signature.
|
|
70
|
+
*/
|
|
71
|
+
signData(data: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Verify a signed identity — checks that:
|
|
74
|
+
* 1. The signature matches the identity data
|
|
75
|
+
* 2. The identity hasn't been tampered with
|
|
76
|
+
*
|
|
77
|
+
* This is a STATIC method — any agent can verify without needing their own keys.
|
|
78
|
+
*/
|
|
79
|
+
static verifyIdentity(signed: SignedIdentity): VerificationResult;
|
|
80
|
+
/**
|
|
81
|
+
* Export the public key bundle — share this with other agents for verification.
|
|
82
|
+
* Never includes the private key.
|
|
83
|
+
*/
|
|
84
|
+
getKeyBundle(): KeyBundle;
|
|
85
|
+
/**
|
|
86
|
+
* Get the fingerprint — a human-readable identifier for this agent's key.
|
|
87
|
+
* Like SSH fingerprints: "ab:cd:ef:12:34:..."
|
|
88
|
+
*/
|
|
89
|
+
getFingerprint(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Save a signed identity to disk — produces a .signed.json file
|
|
92
|
+
* that any agent can independently verify.
|
|
93
|
+
*/
|
|
94
|
+
saveSignedIdentity(signed: SignedIdentity): Promise<string>;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxC,MAAM,WAAW,SAAS;IACxB,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,QAAQ,EAAE,QAAQ,CAAC;IACnB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,eAAe,EAAE,MAAM,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,kCAAkC;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAkBD,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,SAAS,CAA0B;gBAE/B,WAAW,EAAE,MAAM;IAI/B;;;OAGG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAmDjD;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc;IAkBhD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAO9B;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB;IAiDjE;;;OAGG;IACH,YAAY,IAAI,SAAS;IAOzB;;;OAGG;IACH,cAAc,IAAI,MAAM;IAOxB;;;OAGG;IACG,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CAKlE"}
|
package/dist/signing.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Identity Signing — cryptographic proof that an agent is who they claim to be.
|
|
4
|
+
*
|
|
5
|
+
* Uses Node.js built-in crypto (Ed25519) — no external dependencies.
|
|
6
|
+
*
|
|
7
|
+
* Flow:
|
|
8
|
+
* 1. Agent boots → generates key pair (or loads existing)
|
|
9
|
+
* 2. Agent signs their identity files → produces a signature bundle
|
|
10
|
+
* 3. Any other agent can verify: "this identity was created by this key and hasn't been tampered with"
|
|
11
|
+
*
|
|
12
|
+
* This is NOT blockchain. It's just public-key cryptography.
|
|
13
|
+
* Simple, fast, and solves the Moltbook impersonation problem.
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.SigningEngine = void 0;
|
|
50
|
+
const crypto_1 = require("crypto");
|
|
51
|
+
const utils_1 = require("./utils");
|
|
52
|
+
const path_1 = require("path");
|
|
53
|
+
// ============ HELPERS ============
|
|
54
|
+
/** Canonical JSON — deterministic serialization for signing */
|
|
55
|
+
function canonicalize(obj) {
|
|
56
|
+
return JSON.stringify(obj, Object.keys(obj).sort());
|
|
57
|
+
}
|
|
58
|
+
/** SHA-256 fingerprint of a public key */
|
|
59
|
+
function fingerprint(publicKeyBase64) {
|
|
60
|
+
const hash = (0, crypto_1.createHash)('sha256').update(publicKeyBase64).digest('hex');
|
|
61
|
+
// Format as colon-separated pairs for readability: ab:cd:ef:...
|
|
62
|
+
return hash.match(/.{2}/g).slice(0, 16).join(':');
|
|
63
|
+
}
|
|
64
|
+
// ============ SIGNING ENGINE ============
|
|
65
|
+
class SigningEngine {
|
|
66
|
+
storagePath;
|
|
67
|
+
privateKey = null;
|
|
68
|
+
publicKey = null;
|
|
69
|
+
keyBundle = null;
|
|
70
|
+
constructor(storagePath) {
|
|
71
|
+
this.storagePath = storagePath;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Initialize signing — loads existing keys or generates new ones.
|
|
75
|
+
* Call this once during agent boot.
|
|
76
|
+
*/
|
|
77
|
+
async init(agentName) {
|
|
78
|
+
const keysPath = (0, path_1.join)(this.storagePath, '.keys');
|
|
79
|
+
const bundlePath = (0, path_1.join)(keysPath, 'key-bundle.json');
|
|
80
|
+
const privatePath = (0, path_1.join)(keysPath, 'private.pem');
|
|
81
|
+
const publicPath = (0, path_1.join)(keysPath, 'public.pem');
|
|
82
|
+
// Try to load existing keys
|
|
83
|
+
const existingBundle = await (0, utils_1.readFileSafe)(bundlePath);
|
|
84
|
+
const existingPrivate = await (0, utils_1.readFileSafe)(privatePath);
|
|
85
|
+
const existingPublic = await (0, utils_1.readFileSafe)(publicPath);
|
|
86
|
+
if (existingBundle && existingPrivate && existingPublic) {
|
|
87
|
+
try {
|
|
88
|
+
const { createPrivateKey, createPublicKey } = await Promise.resolve().then(() => __importStar(require('crypto')));
|
|
89
|
+
this.privateKey = createPrivateKey(existingPrivate);
|
|
90
|
+
this.publicKey = createPublicKey(existingPublic);
|
|
91
|
+
this.keyBundle = JSON.parse(existingBundle);
|
|
92
|
+
return this.keyBundle;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
console.warn('[anima/signing] Corrupted keys, regenerating...');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Generate new Ed25519 key pair
|
|
99
|
+
const { publicKey, privateKey } = (0, crypto_1.generateKeyPairSync)('ed25519');
|
|
100
|
+
this.privateKey = privateKey;
|
|
101
|
+
this.publicKey = publicKey;
|
|
102
|
+
const pubKeyBase64 = publicKey.export({ type: 'spki', format: 'pem' }).toString();
|
|
103
|
+
const privKeyPem = privateKey.export({ type: 'pkcs8', format: 'pem' }).toString();
|
|
104
|
+
const pubKeyPem = publicKey.export({ type: 'spki', format: 'pem' }).toString();
|
|
105
|
+
// Extract raw public key bytes for fingerprinting
|
|
106
|
+
const pubKeyDer = publicKey.export({ type: 'spki', format: 'der' });
|
|
107
|
+
const pubKeyB64 = pubKeyDer.toString('base64');
|
|
108
|
+
this.keyBundle = {
|
|
109
|
+
publicKey: pubKeyB64,
|
|
110
|
+
fingerprint: fingerprint(pubKeyB64),
|
|
111
|
+
createdAt: (0, utils_1.now)(),
|
|
112
|
+
agentName,
|
|
113
|
+
};
|
|
114
|
+
// Save keys
|
|
115
|
+
await (0, utils_1.writeFileSafe)(privatePath, privKeyPem);
|
|
116
|
+
await (0, utils_1.writeFileSafe)(publicPath, pubKeyPem);
|
|
117
|
+
await (0, utils_1.writeFileSafe)(bundlePath, JSON.stringify(this.keyBundle, null, 2));
|
|
118
|
+
return this.keyBundle;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Sign an identity — produces a verifiable signature bundle.
|
|
122
|
+
* This proves: "I, the holder of this private key, attest that this is my identity."
|
|
123
|
+
*/
|
|
124
|
+
signIdentity(identity) {
|
|
125
|
+
if (!this.privateKey || !this.keyBundle) {
|
|
126
|
+
throw new Error('[anima/signing] Not initialized. Call init() first.');
|
|
127
|
+
}
|
|
128
|
+
const canonical = canonicalize(identity);
|
|
129
|
+
const signature = (0, crypto_1.sign)(null, Buffer.from(canonical), this.privateKey);
|
|
130
|
+
return {
|
|
131
|
+
identity,
|
|
132
|
+
signature: signature.toString('base64'),
|
|
133
|
+
signerFingerprint: this.keyBundle.fingerprint,
|
|
134
|
+
signerPublicKey: this.keyBundle.publicKey,
|
|
135
|
+
signedAt: (0, utils_1.now)(),
|
|
136
|
+
version: '0.1.0',
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sign arbitrary data — for signing memories, opinions, messages, etc.
|
|
141
|
+
* Returns base64 signature.
|
|
142
|
+
*/
|
|
143
|
+
signData(data) {
|
|
144
|
+
if (!this.privateKey) {
|
|
145
|
+
throw new Error('[anima/signing] Not initialized. Call init() first.');
|
|
146
|
+
}
|
|
147
|
+
return (0, crypto_1.sign)(null, Buffer.from(data), this.privateKey).toString('base64');
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Verify a signed identity — checks that:
|
|
151
|
+
* 1. The signature matches the identity data
|
|
152
|
+
* 2. The identity hasn't been tampered with
|
|
153
|
+
*
|
|
154
|
+
* This is a STATIC method — any agent can verify without needing their own keys.
|
|
155
|
+
*/
|
|
156
|
+
static verifyIdentity(signed) {
|
|
157
|
+
try {
|
|
158
|
+
const { createPublicKey } = require('crypto');
|
|
159
|
+
// Reconstruct public key from the bundle
|
|
160
|
+
const pubKeyBuffer = Buffer.from(signed.signerPublicKey, 'base64');
|
|
161
|
+
const publicKey = createPublicKey({
|
|
162
|
+
key: pubKeyBuffer,
|
|
163
|
+
format: 'der',
|
|
164
|
+
type: 'spki',
|
|
165
|
+
});
|
|
166
|
+
// Verify signature against canonical identity
|
|
167
|
+
const canonical = canonicalize(signed.identity);
|
|
168
|
+
const signatureBuffer = Buffer.from(signed.signature, 'base64');
|
|
169
|
+
const valid = (0, crypto_1.verify)(null, Buffer.from(canonical), publicKey, signatureBuffer);
|
|
170
|
+
// Verify fingerprint matches public key
|
|
171
|
+
const expectedFingerprint = fingerprint(signed.signerPublicKey);
|
|
172
|
+
const fingerprintMatch = expectedFingerprint === signed.signerFingerprint;
|
|
173
|
+
if (!fingerprintMatch) {
|
|
174
|
+
return {
|
|
175
|
+
valid: false,
|
|
176
|
+
signerFingerprint: signed.signerFingerprint,
|
|
177
|
+
agentName: signed.identity.name,
|
|
178
|
+
signedAt: signed.signedAt,
|
|
179
|
+
reason: 'Fingerprint mismatch — public key does not match claimed fingerprint',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
valid,
|
|
184
|
+
signerFingerprint: signed.signerFingerprint,
|
|
185
|
+
agentName: signed.identity.name,
|
|
186
|
+
signedAt: signed.signedAt,
|
|
187
|
+
reason: valid ? undefined : 'Signature verification failed — identity may have been tampered with',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
return {
|
|
192
|
+
valid: false,
|
|
193
|
+
signerFingerprint: signed.signerFingerprint,
|
|
194
|
+
agentName: signed.identity.name,
|
|
195
|
+
signedAt: signed.signedAt,
|
|
196
|
+
reason: `Verification error: ${err.message}`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Export the public key bundle — share this with other agents for verification.
|
|
202
|
+
* Never includes the private key.
|
|
203
|
+
*/
|
|
204
|
+
getKeyBundle() {
|
|
205
|
+
if (!this.keyBundle) {
|
|
206
|
+
throw new Error('[anima/signing] Not initialized. Call init() first.');
|
|
207
|
+
}
|
|
208
|
+
return { ...this.keyBundle };
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get the fingerprint — a human-readable identifier for this agent's key.
|
|
212
|
+
* Like SSH fingerprints: "ab:cd:ef:12:34:..."
|
|
213
|
+
*/
|
|
214
|
+
getFingerprint() {
|
|
215
|
+
if (!this.keyBundle) {
|
|
216
|
+
throw new Error('[anima/signing] Not initialized. Call init() first.');
|
|
217
|
+
}
|
|
218
|
+
return this.keyBundle.fingerprint;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Save a signed identity to disk — produces a .signed.json file
|
|
222
|
+
* that any agent can independently verify.
|
|
223
|
+
*/
|
|
224
|
+
async saveSignedIdentity(signed) {
|
|
225
|
+
const outPath = (0, path_1.join)(this.storagePath, 'identity.signed.json');
|
|
226
|
+
await (0, utils_1.writeFileSafe)(outPath, JSON.stringify(signed, null, 2));
|
|
227
|
+
return outPath;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.SigningEngine = SigningEngine;
|
|
231
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.js","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAkF;AAClF,mCAA2D;AAC3D,+BAA4B;AA4C5B,oCAAoC;AAEpC,+DAA+D;AAC/D,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAA8B,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACjF,CAAC;AAED,0CAA0C;AAC1C,SAAS,WAAW,CAAC,eAAuB;IAC1C,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxE,gEAAgE;IAChE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrD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