@rohankumar4179/engram-sdk 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/anchor.d.ts +101 -0
- package/dist/anchor.js +215 -0
- package/dist/anchor.js.map +1 -0
- package/dist/audit.d.ts +48 -0
- package/dist/audit.js +93 -0
- package/dist/audit.js.map +1 -0
- package/dist/consolidator.d.ts +62 -0
- package/dist/consolidator.js +141 -0
- package/dist/consolidator.js.map +1 -0
- package/dist/crypto.d.ts +26 -0
- package/dist/crypto.js +72 -0
- package/dist/crypto.js.map +1 -0
- package/dist/engram.d.ts +253 -0
- package/dist/engram.js +660 -0
- package/dist/engram.js.map +1 -0
- package/dist/env.d.ts +28 -0
- package/dist/env.js +81 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect.d.ts +19 -0
- package/dist/inspect.js +61 -0
- package/dist/inspect.js.map +1 -0
- package/dist/llm.d.ts +60 -0
- package/dist/llm.js +188 -0
- package/dist/llm.js.map +1 -0
- package/dist/memwal-account.d.ts +39 -0
- package/dist/memwal-account.js +75 -0
- package/dist/memwal-account.js.map +1 -0
- package/dist/merkle.d.ts +14 -0
- package/dist/merkle.js +69 -0
- package/dist/merkle.js.map +1 -0
- package/dist/mind.d.ts +130 -0
- package/dist/mind.js +156 -0
- package/dist/mind.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +46 -0
- package/dist/proof.js.map +1 -0
- package/dist/remote.d.ts +112 -0
- package/dist/remote.js +232 -0
- package/dist/remote.js.map +1 -0
- package/dist/store.d.ts +28 -0
- package/dist/store.js +72 -0
- package/dist/store.js.map +1 -0
- package/dist/tatum.d.ts +83 -0
- package/dist/tatum.js +148 -0
- package/dist/tatum.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vault.d.ts +31 -0
- package/dist/vault.js +45 -0
- package/dist/vault.js.map +1 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rohan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rohankumar4179/engram-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Git for agent memory: episodes → beliefs (LLM), signed commits on Walrus Memory anchored on Sui,
|
|
4
|
+
decision receipts with Merkle proofs, `verify`, and provable `forget`.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { engram } from "@rohankumar4179/engram-sdk";
|
|
8
|
+
|
|
9
|
+
const mind = engram({ agent: "money-ops" }); // keys from .env (Walrus Memory, Tatum, Gemini)
|
|
10
|
+
const agent = mind.wrap(myAgent, { used: (out) => out.beliefIds });
|
|
11
|
+
|
|
12
|
+
mind.observe({ source: "tatum", data: tx }); // encrypted episode
|
|
13
|
+
await mind.sleep(); // episodes → beliefs
|
|
14
|
+
await mind.commit("weekly"); // Merkle root → Walrus → Sui
|
|
15
|
+
await mind.beliefs({ about: "rent" });
|
|
16
|
+
mind.at("2026-10-25"); // time travel
|
|
17
|
+
mind.forget("ep_…"); // provable forgetting
|
|
18
|
+
await mind.verify(agent.lastReceipt!.id); // proof check
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Audit bundles: `exportAudit(mind.core)` / `verifyAudit(bundle, { anchorer })`.
|
|
22
|
+
Full docs: https://github.com/rohan911438/Engram
|
package/dist/anchor.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
|
+
import { type TatumSui } from "./tatum.js";
|
|
3
|
+
import type { Anchor, Commit } from "./types.js";
|
|
4
|
+
export interface AnchorCheck {
|
|
5
|
+
ok: boolean;
|
|
6
|
+
detail: string;
|
|
7
|
+
timestampMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/** Finds and re-checks the on-chain record of a stored manifest. */
|
|
10
|
+
export interface Anchorer {
|
|
11
|
+
/** Locates the Sui record for a Walrus blob. Null if it isn't visible yet. */
|
|
12
|
+
find(blobId: string): Promise<Anchor | null>;
|
|
13
|
+
/** Independently re-reads the chain to confirm an anchor. */
|
|
14
|
+
check(anchor: Anchor, blobId: string, commit: Commit): Promise<AnchorCheck>;
|
|
15
|
+
/** Anchorers that write to chain themselves (option B) implement this instead of relying on `find`. */
|
|
16
|
+
publish?(commit: Commit): Promise<Anchor | null>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Option A anchoring: every Walrus Memory write registers a Walrus `Blob`
|
|
20
|
+
* object on Sui, owned by the account owner. The commit manifest's blob is
|
|
21
|
+
* that anchor — its certifying transaction fixes the time on-chain.
|
|
22
|
+
* All reads go through Tatum's Sui RPC.
|
|
23
|
+
*/
|
|
24
|
+
export declare class WalrusBlobAnchorer implements Anchorer {
|
|
25
|
+
readonly tatum: TatumSui;
|
|
26
|
+
private memwalAccountId;
|
|
27
|
+
private opts;
|
|
28
|
+
private owner?;
|
|
29
|
+
constructor(tatum: TatumSui, memwalAccountId: string, opts?: {
|
|
30
|
+
retries?: number;
|
|
31
|
+
delayMs?: number;
|
|
32
|
+
});
|
|
33
|
+
ownerAddress(): Promise<string>;
|
|
34
|
+
find(blobId: string): Promise<Anchor | null>;
|
|
35
|
+
check(anchor: Anchor, blobId: string, commit: Commit): Promise<AnchorCheck>;
|
|
36
|
+
}
|
|
37
|
+
/** Offline anchorer for tests: pretends every blob is on-chain. */
|
|
38
|
+
export declare class FakeAnchorer implements Anchorer {
|
|
39
|
+
readonly anchored: Map<string, Anchor>;
|
|
40
|
+
find(blobId: string): Promise<Anchor | null>;
|
|
41
|
+
check(anchor: Anchor, blobId: string): Promise<AnchorCheck>;
|
|
42
|
+
}
|
|
43
|
+
export type SuiNetwork = "mainnet" | "testnet";
|
|
44
|
+
export interface MoveAnchorerOptions {
|
|
45
|
+
/** Published `engram_anchor` package ID. */
|
|
46
|
+
packageId: string;
|
|
47
|
+
/** Wallet that pays gas (BIP-39 phrase). */
|
|
48
|
+
mnemonic: string;
|
|
49
|
+
/** Default mainnet. Mainnet sends and re-reads through Tatum (gRPC); testnet uses the public Sui gRPC node. */
|
|
50
|
+
network?: SuiNetwork;
|
|
51
|
+
/** Required on mainnet. */
|
|
52
|
+
tatum?: TatumSui;
|
|
53
|
+
tatumApiKey?: string;
|
|
54
|
+
/** Checks older commits that were anchored as Walrus Blobs. */
|
|
55
|
+
blobAnchorer?: Anchorer;
|
|
56
|
+
}
|
|
57
|
+
/** The fields of one `Anchored` event, hex-encoded. */
|
|
58
|
+
interface AnchoredRead {
|
|
59
|
+
checkpoint?: string;
|
|
60
|
+
timestampMs?: number;
|
|
61
|
+
event?: {
|
|
62
|
+
commitId: string;
|
|
63
|
+
merkleRoot: string;
|
|
64
|
+
agentPubKey: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Reads the `Anchored` event of a transaction from some Sui endpoint. */
|
|
68
|
+
export interface AnchoredEventReader {
|
|
69
|
+
readAnchored(digest: string, eventType: string): Promise<AnchoredRead>;
|
|
70
|
+
}
|
|
71
|
+
export declare function suiGrpc(network: SuiNetwork): SuiGrpcClient;
|
|
72
|
+
/** Reads anchors over gRPC: a public Sui full node by network name, or any client (e.g. Tatum's). */
|
|
73
|
+
export declare class GrpcEventReader implements AnchoredEventReader {
|
|
74
|
+
private client;
|
|
75
|
+
constructor(source: SuiNetwork | SuiGrpcClient);
|
|
76
|
+
readAnchored(digest: string, eventType: string): Promise<AnchoredRead>;
|
|
77
|
+
}
|
|
78
|
+
/** Reads anchors through Tatum's Sui Mainnet gRPC gateway. */
|
|
79
|
+
export declare function tatumEventReader(tatum: TatumSui): AnchoredEventReader;
|
|
80
|
+
/**
|
|
81
|
+
* Option B anchoring: each commit calls `engram_anchor::anchor::anchor`, which
|
|
82
|
+
* emits an `Anchored` event with the commit ID and Merkle root in the clear.
|
|
83
|
+
* Mainnet transactions are sent and re-read through Tatum's Sui gRPC gateway.
|
|
84
|
+
*/
|
|
85
|
+
export declare class MoveAnchorer implements Anchorer {
|
|
86
|
+
private opts;
|
|
87
|
+
private keypair;
|
|
88
|
+
readonly network: SuiNetwork;
|
|
89
|
+
private reader;
|
|
90
|
+
constructor(opts: MoveAnchorerOptions);
|
|
91
|
+
get address(): string;
|
|
92
|
+
get eventType(): string;
|
|
93
|
+
private buildTx;
|
|
94
|
+
private send;
|
|
95
|
+
publish(c: Commit): Promise<Anchor | null>;
|
|
96
|
+
find(): Promise<Anchor | null>;
|
|
97
|
+
check(anchor: Anchor, blobId: string, c: Commit): Promise<AnchorCheck>;
|
|
98
|
+
}
|
|
99
|
+
/** Re-reads an `Anchored` event and compares it with the commit. Accepts a Tatum client (mainnet) or any reader. */
|
|
100
|
+
export declare function checkMoveAnchor(source: TatumSui | AnchoredEventReader, anchor: Anchor, c: Commit): Promise<AnchorCheck>;
|
|
101
|
+
export {};
|
package/dist/anchor.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
2
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
3
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
4
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
5
|
+
import { hexToBytes } from "./crypto.js";
|
|
6
|
+
import { blobIdFromU256 } from "./tatum.js";
|
|
7
|
+
/**
|
|
8
|
+
* Option A anchoring: every Walrus Memory write registers a Walrus `Blob`
|
|
9
|
+
* object on Sui, owned by the account owner. The commit manifest's blob is
|
|
10
|
+
* that anchor — its certifying transaction fixes the time on-chain.
|
|
11
|
+
* All reads go through Tatum's Sui RPC.
|
|
12
|
+
*/
|
|
13
|
+
export class WalrusBlobAnchorer {
|
|
14
|
+
tatum;
|
|
15
|
+
memwalAccountId;
|
|
16
|
+
opts;
|
|
17
|
+
owner;
|
|
18
|
+
constructor(tatum, memwalAccountId, opts = {}) {
|
|
19
|
+
this.tatum = tatum;
|
|
20
|
+
this.memwalAccountId = memwalAccountId;
|
|
21
|
+
this.opts = opts;
|
|
22
|
+
}
|
|
23
|
+
async ownerAddress() {
|
|
24
|
+
this.owner ??= await this.tatum.memwalAccountOwner(this.memwalAccountId);
|
|
25
|
+
return this.owner;
|
|
26
|
+
}
|
|
27
|
+
async find(blobId) {
|
|
28
|
+
const owner = await this.ownerAddress();
|
|
29
|
+
const retries = this.opts.retries ?? 4;
|
|
30
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
31
|
+
for await (const b of this.tatum.ownedBlobs(owner)) {
|
|
32
|
+
if (b.blobId !== blobId)
|
|
33
|
+
continue;
|
|
34
|
+
const tx = await this.tatum.getTransaction(b.previousTransaction);
|
|
35
|
+
return { method: "walrus-blob", objectId: b.objectId, txDigest: tx.digest, checkpoint: tx.checkpoint, timestampMs: tx.timestampMs };
|
|
36
|
+
}
|
|
37
|
+
if (attempt < retries)
|
|
38
|
+
await new Promise((r) => setTimeout(r, this.opts.delayMs ?? 4000));
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
async check(anchor, blobId, commit) {
|
|
43
|
+
if (anchor.method === "move-event")
|
|
44
|
+
return checkMoveAnchor(anchor.network === "testnet" ? new GrpcEventReader("testnet") : this.tatum, anchor, commit);
|
|
45
|
+
const obj = await this.tatum.getObject(anchor.objectId);
|
|
46
|
+
if (!obj)
|
|
47
|
+
return { ok: false, detail: `Sui object ${anchor.objectId} not found` };
|
|
48
|
+
const fields = obj.content?.fields;
|
|
49
|
+
if (!obj.type?.endsWith("::blob::Blob") || !fields?.blob_id)
|
|
50
|
+
return { ok: false, detail: `object is not a Walrus Blob (${obj.type})` };
|
|
51
|
+
if (blobIdFromU256(fields.blob_id) !== blobId)
|
|
52
|
+
return { ok: false, detail: "on-chain blob_id does not match the manifest blob" };
|
|
53
|
+
if (fields.certified_epoch == null)
|
|
54
|
+
return { ok: false, detail: "blob is registered but not certified" };
|
|
55
|
+
const owner = obj.owner?.AddressOwner;
|
|
56
|
+
if (owner && owner !== (await this.ownerAddress()))
|
|
57
|
+
return { ok: false, detail: `blob owned by ${owner}, not the Walrus Memory account owner` };
|
|
58
|
+
const tx = await this.tatum.getTransaction(anchor.txDigest);
|
|
59
|
+
if (!tx.checkpoint)
|
|
60
|
+
return { ok: false, detail: `transaction ${anchor.txDigest} not found` };
|
|
61
|
+
if (anchor.checkpoint && tx.checkpoint !== anchor.checkpoint)
|
|
62
|
+
return { ok: false, detail: `checkpoint mismatch (${tx.checkpoint} vs ${anchor.checkpoint})` };
|
|
63
|
+
return { ok: true, detail: `Walrus Blob ${short(anchor.objectId)} certified, tx ${short(tx.digest)} in checkpoint ${tx.checkpoint}`, timestampMs: tx.timestampMs };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const short = (s) => (s.length > 14 ? `${s.slice(0, 8)}…${s.slice(-4)}` : s);
|
|
67
|
+
/** Offline anchorer for tests: pretends every blob is on-chain. */
|
|
68
|
+
export class FakeAnchorer {
|
|
69
|
+
anchored = new Map();
|
|
70
|
+
async find(blobId) {
|
|
71
|
+
let a = this.anchored.get(blobId);
|
|
72
|
+
if (!a) {
|
|
73
|
+
a = { method: "walrus-blob", objectId: `0xobj_${blobId.slice(0, 8)}`, txDigest: `tx_${blobId.slice(0, 8)}`, checkpoint: String(this.anchored.size + 1), timestampMs: Date.now() };
|
|
74
|
+
this.anchored.set(blobId, a);
|
|
75
|
+
}
|
|
76
|
+
return a;
|
|
77
|
+
}
|
|
78
|
+
async check(anchor, blobId) {
|
|
79
|
+
const a = this.anchored.get(blobId);
|
|
80
|
+
return a && a.txDigest === anchor.txDigest && a.objectId === anchor.objectId
|
|
81
|
+
? { ok: true, detail: `fake anchor ${a.txDigest}`, timestampMs: a.timestampMs }
|
|
82
|
+
: { ok: false, detail: "no such anchor" };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const AnchoredBcs = bcs.struct("Anchored", {
|
|
86
|
+
sender: bcs.Address,
|
|
87
|
+
agent_pubkey: bcs.vector(bcs.u8()),
|
|
88
|
+
commit_id: bcs.vector(bcs.u8()),
|
|
89
|
+
merkle_root: bcs.vector(bcs.u8()),
|
|
90
|
+
parent: bcs.vector(bcs.u8()),
|
|
91
|
+
manifest_blob: bcs.vector(bcs.u8()),
|
|
92
|
+
timestamp_ms: bcs.u64(),
|
|
93
|
+
});
|
|
94
|
+
const toHex = (b) => Buffer.from([...b]).toString("hex");
|
|
95
|
+
const grpcClients = new Map();
|
|
96
|
+
export function suiGrpc(network) {
|
|
97
|
+
let c = grpcClients.get(network);
|
|
98
|
+
if (!c)
|
|
99
|
+
grpcClients.set(network, (c = new SuiGrpcClient({ network, baseUrl: `https://fullnode.${network}.sui.io:443` })));
|
|
100
|
+
return c;
|
|
101
|
+
}
|
|
102
|
+
/** Reads anchors over gRPC: a public Sui full node by network name, or any client (e.g. Tatum's). */
|
|
103
|
+
export class GrpcEventReader {
|
|
104
|
+
client;
|
|
105
|
+
constructor(source) {
|
|
106
|
+
this.client = typeof source === "string" ? suiGrpc(source) : source;
|
|
107
|
+
}
|
|
108
|
+
async readAnchored(digest, eventType) {
|
|
109
|
+
const res = await this.client.getTransaction({ digest, include: { events: true } });
|
|
110
|
+
const t = res.Transaction ?? res.FailedTransaction;
|
|
111
|
+
const ev = t?.events?.find((e) => e.eventType === eventType);
|
|
112
|
+
const out = { checkpoint: t?.checkpoint ?? undefined, timestampMs: t?.timestampMs ?? undefined };
|
|
113
|
+
if (ev && res.$kind === "Transaction") {
|
|
114
|
+
const p = AnchoredBcs.parse(ev.bcs);
|
|
115
|
+
out.event = { commitId: toHex(p.commit_id), merkleRoot: toHex(p.merkle_root), agentPubKey: toHex(p.agent_pubkey) };
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Reads anchors through Tatum's Sui Mainnet gRPC gateway. */
|
|
121
|
+
export function tatumEventReader(tatum) {
|
|
122
|
+
return new GrpcEventReader(tatum.client);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Option B anchoring: each commit calls `engram_anchor::anchor::anchor`, which
|
|
126
|
+
* emits an `Anchored` event with the commit ID and Merkle root in the clear.
|
|
127
|
+
* Mainnet transactions are sent and re-read through Tatum's Sui gRPC gateway.
|
|
128
|
+
*/
|
|
129
|
+
export class MoveAnchorer {
|
|
130
|
+
opts;
|
|
131
|
+
keypair;
|
|
132
|
+
network;
|
|
133
|
+
reader;
|
|
134
|
+
constructor(opts) {
|
|
135
|
+
this.opts = opts;
|
|
136
|
+
this.keypair = Ed25519Keypair.deriveKeypair(opts.mnemonic.trim());
|
|
137
|
+
this.network = opts.network ?? "mainnet";
|
|
138
|
+
if (this.network === "mainnet" && !opts.tatum)
|
|
139
|
+
throw new Error("mainnet anchoring needs a Tatum API key");
|
|
140
|
+
this.reader = this.network === "mainnet" ? tatumEventReader(opts.tatum) : new GrpcEventReader(this.network);
|
|
141
|
+
}
|
|
142
|
+
get address() {
|
|
143
|
+
return this.keypair.toSuiAddress();
|
|
144
|
+
}
|
|
145
|
+
get eventType() {
|
|
146
|
+
return `${this.opts.packageId}::anchor::Anchored`;
|
|
147
|
+
}
|
|
148
|
+
buildTx(c) {
|
|
149
|
+
const tx = new Transaction();
|
|
150
|
+
tx.moveCall({
|
|
151
|
+
target: `${this.opts.packageId}::anchor::anchor`,
|
|
152
|
+
arguments: [
|
|
153
|
+
tx.pure.vector("u8", hexToBytes(c.manifest.agentPubKey)),
|
|
154
|
+
tx.pure.vector("u8", hexToBytes(c.id)),
|
|
155
|
+
tx.pure.vector("u8", hexToBytes(c.manifest.merkleRoot)),
|
|
156
|
+
tx.pure.vector("u8", c.manifest.parent ? hexToBytes(c.manifest.parent) : new Uint8Array()),
|
|
157
|
+
tx.pure.vector("u8", new TextEncoder().encode(c.manifestBlobId ?? "")),
|
|
158
|
+
tx.object.clock(),
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
return tx;
|
|
162
|
+
}
|
|
163
|
+
async send(c) {
|
|
164
|
+
const client = this.network === "mainnet" ? this.opts.tatum.client : suiGrpc(this.network);
|
|
165
|
+
const res = await client.signAndExecuteTransaction({ transaction: this.buildTx(c), signer: this.keypair });
|
|
166
|
+
if (res.$kind !== "Transaction")
|
|
167
|
+
throw new Error(`anchor transaction failed: ${JSON.stringify(res.FailedTransaction?.status)}`);
|
|
168
|
+
await client.waitForTransaction({ digest: res.Transaction.digest });
|
|
169
|
+
return res.Transaction.digest;
|
|
170
|
+
}
|
|
171
|
+
async publish(c) {
|
|
172
|
+
const digest = await this.send(c);
|
|
173
|
+
// The checkpoint can lag execution by a moment; retry briefly.
|
|
174
|
+
let t = {};
|
|
175
|
+
for (let i = 0; i < 6 && !t.checkpoint; i++) {
|
|
176
|
+
t = await this.reader.readAnchored(digest, this.eventType);
|
|
177
|
+
if (!t.checkpoint)
|
|
178
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
179
|
+
}
|
|
180
|
+
const anchor = { method: "move-event", objectId: this.opts.packageId, txDigest: digest, checkpoint: t.checkpoint, timestampMs: t.timestampMs };
|
|
181
|
+
if (this.network !== "mainnet")
|
|
182
|
+
anchor.network = this.network;
|
|
183
|
+
return anchor;
|
|
184
|
+
}
|
|
185
|
+
async find() {
|
|
186
|
+
return null; // option B anchors are published, not discovered
|
|
187
|
+
}
|
|
188
|
+
async check(anchor, blobId, c) {
|
|
189
|
+
if (anchor.method === "walrus-blob") {
|
|
190
|
+
return this.opts.blobAnchorer ? this.opts.blobAnchorer.check(anchor, blobId, c) : { ok: false, detail: "Walrus Blob anchor but no Walrus Memory account configured" };
|
|
191
|
+
}
|
|
192
|
+
const net = anchor.network ?? "mainnet";
|
|
193
|
+
if (net === this.network)
|
|
194
|
+
return checkMoveAnchor(this.reader, anchor, c);
|
|
195
|
+
if (net === "mainnet" && !this.opts.tatum)
|
|
196
|
+
return { ok: false, detail: "mainnet anchor but no Tatum key configured" };
|
|
197
|
+
return checkMoveAnchor(net === "mainnet" ? this.opts.tatum : new GrpcEventReader(net), anchor, c);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Re-reads an `Anchored` event and compares it with the commit. Accepts a Tatum client (mainnet) or any reader. */
|
|
201
|
+
export async function checkMoveAnchor(source, anchor, c) {
|
|
202
|
+
const reader = "readAnchored" in source ? source : tatumEventReader(source);
|
|
203
|
+
const r = await reader.readAnchored(anchor.txDigest, `${anchor.objectId}::anchor::Anchored`);
|
|
204
|
+
const net = anchor.network && anchor.network !== "mainnet" ? ` (${anchor.network})` : "";
|
|
205
|
+
if (!r.event)
|
|
206
|
+
return { ok: false, detail: `no Anchored event in tx ${anchor.txDigest}${net}` };
|
|
207
|
+
if (r.event.commitId !== c.id)
|
|
208
|
+
return { ok: false, detail: "event commit_id differs from this commit" };
|
|
209
|
+
if (r.event.merkleRoot !== c.manifest.merkleRoot)
|
|
210
|
+
return { ok: false, detail: "event merkle_root differs from this commit" };
|
|
211
|
+
if (r.event.agentPubKey !== c.manifest.agentPubKey)
|
|
212
|
+
return { ok: false, detail: "event names a different agent key" };
|
|
213
|
+
return { ok: true, detail: `Anchored event: root ${c.manifest.merkleRoot.slice(0, 10)}… public in checkpoint ${r.checkpoint}${net}`, timestampMs: r.timestampMs };
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.js","sourceRoot":"","sources":["../src/anchor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAC;AAmB3D;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAIlB;IACD;IACA;IALF,KAAK,CAAU;IAEvB,YACW,KAAe,EAChB,eAAuB,EACvB,OAA+C,EAAE;QAFhD,UAAK,GAAL,KAAK,CAAU;QAChB,oBAAe,GAAf,eAAe,CAAQ;QACvB,SAAI,GAAJ,IAAI,CAA6C;IACxD,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,KAAK,KAAK,MAA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AAC"}
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Anchorer } from "./anchor.js";
|
|
2
|
+
import { type Engram } from "./engram.js";
|
|
3
|
+
import type { Belief, Commit, Receipt } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* A self-contained audit file: the agent's commit history, every belief
|
|
6
|
+
* version those commits reference, and its decision receipts. Anyone can
|
|
7
|
+
* re-check it without the agent's repo (`verifyAudit`). Raw episodes are not
|
|
8
|
+
* included — they stay encrypted; beliefs cite them by ID and Walrus blob.
|
|
9
|
+
*/
|
|
10
|
+
export interface AuditBundle {
|
|
11
|
+
engram: "audit";
|
|
12
|
+
v: 1;
|
|
13
|
+
agent: string;
|
|
14
|
+
agentPubKey: string;
|
|
15
|
+
exportedAt: number;
|
|
16
|
+
head: string | null;
|
|
17
|
+
/** Newest first, back to the first commit. */
|
|
18
|
+
commits: Commit[];
|
|
19
|
+
beliefs: Belief[];
|
|
20
|
+
receipts: Receipt[];
|
|
21
|
+
}
|
|
22
|
+
export declare function exportAudit(e: Engram, opts?: {
|
|
23
|
+
receipts?: boolean;
|
|
24
|
+
}): AuditBundle;
|
|
25
|
+
export interface AuditCheck {
|
|
26
|
+
subject: string;
|
|
27
|
+
ok: boolean;
|
|
28
|
+
detail: string;
|
|
29
|
+
skipped?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface AuditReport {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
checks: AuditCheck[];
|
|
34
|
+
summary: {
|
|
35
|
+
commits: number;
|
|
36
|
+
receipts: number;
|
|
37
|
+
anchored: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Re-checks an audit bundle from scratch: each commit's ID, signature,
|
|
42
|
+
* Merkle root (rebuilt from the included beliefs) and parent link; each
|
|
43
|
+
* receipt's signature and Merkle proofs. With an `anchorer`, also re-reads
|
|
44
|
+
* every commit's anchor on Sui.
|
|
45
|
+
*/
|
|
46
|
+
export declare function verifyAudit(bundle: AuditBundle, opts?: {
|
|
47
|
+
anchorer?: Anchorer;
|
|
48
|
+
}): Promise<AuditReport>;
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { canonical, verifySignature } from "./crypto.js";
|
|
2
|
+
import { beliefKey } from "./engram.js";
|
|
3
|
+
import { buildCommitTree, commitId, verifyBeliefProof, verifyManifestSignature } from "./proof.js";
|
|
4
|
+
export function exportAudit(e, opts = {}) {
|
|
5
|
+
const head = e.head();
|
|
6
|
+
const commits = head ? e.log() : [];
|
|
7
|
+
const keys = new Set(commits.flatMap((c) => c.manifest.beliefs));
|
|
8
|
+
const beliefs = [...keys].map((k) => e.belief(k)).filter((b) => !!b);
|
|
9
|
+
return {
|
|
10
|
+
engram: "audit",
|
|
11
|
+
v: 1,
|
|
12
|
+
agent: e.agent,
|
|
13
|
+
agentPubKey: e.publicKey,
|
|
14
|
+
exportedAt: Date.now(),
|
|
15
|
+
head,
|
|
16
|
+
commits,
|
|
17
|
+
beliefs,
|
|
18
|
+
receipts: opts.receipts === false ? [] : e.receipts().filter((r) => commits.some((c) => c.id === r.commitId)),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Re-checks an audit bundle from scratch: each commit's ID, signature,
|
|
23
|
+
* Merkle root (rebuilt from the included beliefs) and parent link; each
|
|
24
|
+
* receipt's signature and Merkle proofs. With an `anchorer`, also re-reads
|
|
25
|
+
* every commit's anchor on Sui.
|
|
26
|
+
*/
|
|
27
|
+
export async function verifyAudit(bundle, opts = {}) {
|
|
28
|
+
const checks = [];
|
|
29
|
+
const add = (subject, ok, detail, skipped = false) => checks.push({ subject, ok, detail, skipped });
|
|
30
|
+
if (bundle.engram !== "audit" || bundle.v !== 1)
|
|
31
|
+
throw new Error("not an Engram audit bundle (v1)");
|
|
32
|
+
const beliefs = new Map(bundle.beliefs.map((b) => [beliefKey(b), b]));
|
|
33
|
+
const commits = new Map(bundle.commits.map((c) => [c.id, c]));
|
|
34
|
+
let anchored = 0;
|
|
35
|
+
for (const c of bundle.commits) {
|
|
36
|
+
const m = c.manifest;
|
|
37
|
+
const s = `commit ${c.id.slice(0, 8)}`;
|
|
38
|
+
const problems = [];
|
|
39
|
+
if (commitId(m) !== c.id)
|
|
40
|
+
problems.push("ID is not the hash of its manifest");
|
|
41
|
+
if (m.agentPubKey !== bundle.agentPubKey)
|
|
42
|
+
problems.push("signed by a different agent key");
|
|
43
|
+
if (!verifyManifestSignature(m, c.signature))
|
|
44
|
+
problems.push("bad signature");
|
|
45
|
+
const missing = m.beliefs.filter((k) => !beliefs.has(k));
|
|
46
|
+
if (missing.length)
|
|
47
|
+
problems.push(`missing beliefs ${missing.join(", ")}`);
|
|
48
|
+
else if (buildCommitTree(m.beliefs.map((k) => beliefs.get(k)), m.tombstones).tree.root !== m.merkleRoot)
|
|
49
|
+
problems.push("beliefs don't rebuild the Merkle root");
|
|
50
|
+
if (m.parent && !commits.has(m.parent))
|
|
51
|
+
problems.push(`parent ${m.parent.slice(0, 8)} not in the bundle`);
|
|
52
|
+
else if (m.parent && commits.get(m.parent).manifest.ts > m.ts)
|
|
53
|
+
problems.push("parent is newer than the commit");
|
|
54
|
+
add(s, problems.length === 0, problems.length ? problems.join("; ") : `signed, ${m.beliefs.length} beliefs + ${m.tombstones.length} tombstones → root ${m.merkleRoot.slice(0, 10)}…`);
|
|
55
|
+
if (!opts.anchorer)
|
|
56
|
+
continue;
|
|
57
|
+
if (!c.anchor || !c.manifestBlobId) {
|
|
58
|
+
add(`${s} anchor`, false, "no Sui anchor");
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const r = await opts.anchorer.check(c.anchor, c.manifestBlobId, c);
|
|
63
|
+
if (r.ok)
|
|
64
|
+
anchored++;
|
|
65
|
+
add(`${s} anchor`, r.ok, r.detail);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
add(`${s} anchor`, true, `could not reach Sui: ${err.message}`, true);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (bundle.head && bundle.commits[0]?.id !== bundle.head)
|
|
72
|
+
add("head", false, "the newest commit is not the bundle's head");
|
|
73
|
+
for (const r of bundle.receipts) {
|
|
74
|
+
const s = `receipt ${r.id}`;
|
|
75
|
+
const { signature, blobId: _b, ...body } = r;
|
|
76
|
+
const c = commits.get(r.commitId);
|
|
77
|
+
const problems = [];
|
|
78
|
+
if (r.agentPubKey !== bundle.agentPubKey || !verifySignature(canonical(body), signature, r.agentPubKey))
|
|
79
|
+
problems.push("bad signature");
|
|
80
|
+
if (!c)
|
|
81
|
+
problems.push(`points at commit ${r.commitId.slice(0, 8)}, not in the bundle`);
|
|
82
|
+
else {
|
|
83
|
+
const bad = r.beliefs.filter((k) => !beliefs.has(k) || !r.proofs[k] || !verifyBeliefProof(beliefs.get(k), r.proofs[k], c.manifest.merkleRoot));
|
|
84
|
+
if (bad.length)
|
|
85
|
+
problems.push(`invalid proof for ${bad.join(", ")}`);
|
|
86
|
+
if (r.ts < c.manifest.ts)
|
|
87
|
+
problems.push("decided before its commit existed");
|
|
88
|
+
}
|
|
89
|
+
add(s, problems.length === 0, problems.length ? problems.join("; ") : `"${r.action.slice(0, 60)}" — ${r.beliefs.length} belief(s) proven in ${r.commitId.slice(0, 8)}`);
|
|
90
|
+
}
|
|
91
|
+
return { ok: checks.every((x) => x.ok), checks, summary: { commits: bundle.commits.length, receipts: bundle.receipts.length, anchored } };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,SAAS,EAAe,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,QAAQ,EA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AAE,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,wBAAwB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1K,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;AAC5I,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { LLM } from "./llm.js";
|
|
2
|
+
import type { Belief, EpisodeContent } from "./types.js";
|
|
3
|
+
/** One change the consolidator wants to make to the belief set. */
|
|
4
|
+
export type BeliefOp = {
|
|
5
|
+
op: "create";
|
|
6
|
+
key: string;
|
|
7
|
+
statement: string;
|
|
8
|
+
confidence: number;
|
|
9
|
+
evidence: string[];
|
|
10
|
+
tags: string[];
|
|
11
|
+
reason: string;
|
|
12
|
+
} | {
|
|
13
|
+
op: "revise";
|
|
14
|
+
belief: string;
|
|
15
|
+
statement: string;
|
|
16
|
+
confidence: number;
|
|
17
|
+
evidence: string[];
|
|
18
|
+
tags?: string[];
|
|
19
|
+
reason: string;
|
|
20
|
+
} | {
|
|
21
|
+
op: "retract";
|
|
22
|
+
belief: string;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
export interface ConsolidationInput {
|
|
26
|
+
episodes: {
|
|
27
|
+
id: string;
|
|
28
|
+
content: EpisodeContent;
|
|
29
|
+
summary?: string;
|
|
30
|
+
}[];
|
|
31
|
+
beliefs: Belief[];
|
|
32
|
+
/** Optional domain hint, e.g. "You manage a crypto wallet for one owner." */
|
|
33
|
+
context?: string;
|
|
34
|
+
}
|
|
35
|
+
interface RawOp {
|
|
36
|
+
op?: string;
|
|
37
|
+
key?: string;
|
|
38
|
+
belief?: string;
|
|
39
|
+
statement?: string;
|
|
40
|
+
confidence?: number;
|
|
41
|
+
evidence?: string[];
|
|
42
|
+
tags?: string[];
|
|
43
|
+
reason?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare function buildPrompt(input: ConsolidationInput): string;
|
|
46
|
+
/** Asks the LLM for belief changes and drops anything malformed or ungrounded. */
|
|
47
|
+
export declare function proposeOps(llm: LLM, input: ConsolidationInput): Promise<{
|
|
48
|
+
ops: BeliefOp[];
|
|
49
|
+
rejected: {
|
|
50
|
+
op: unknown;
|
|
51
|
+
why: string;
|
|
52
|
+
}[];
|
|
53
|
+
}>;
|
|
54
|
+
export declare function validateOps(rawOps: RawOp[], input: ConsolidationInput): {
|
|
55
|
+
ops: BeliefOp[];
|
|
56
|
+
rejected: {
|
|
57
|
+
op: unknown;
|
|
58
|
+
why: string;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
export declare function slug(s: string): string;
|
|
62
|
+
export {};
|