@agentguard-run/spend 0.15.8 → 0.15.10

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/README.md CHANGED
@@ -251,6 +251,41 @@ Note: full Bitcoin-attestation verification requires the `opentimestamps` npm pa
251
251
 
252
252
  Each signed entry carries a monotonic per-tenant sequence number. `agentguard verify` and the `agentguard serve` integrity badge flag missing sequence numbers as `possible omitted actions: sequence gap at N` — evidence that an action may have been taken around the SDK and not logged, or that a logged entry was deleted. This is detection and reporting only; it never changes spend-cap enforcement.
253
253
 
254
+ ## Multi-agent DAG trust attestation
255
+
256
+ Single receipts prove one agent's action. Real workflows are graphs: agents fan out, fan in, and hand capabilities to each other. A DAG Trust Attestation Token (TAT) is a signed receipt node that also records its parents, so a terminal agent can verify the whole causal chain before it acts. Each node carries version, timestamp, a truncated msg_hash of the screened payload, a trust score, a blocked flag, the screener id, the inferred topology (`linear` | `fan_in` | `fan_out` | `diamond`), the SHA-256 hashes of its parents, and an Ed25519 signature over the canonical serialization. It reuses the exact same signing and canonical-JSON hashing as the decision log, and it is metadata-only: no prompt, completion, key, or PII ever enters a node.
257
+
258
+ `verifyReceiptDag` checks every signature, runs Kahn's algorithm to reject any cycle (the circular-dependency-injection defense), confirms diamond branches correlate to a shared uncorrupted ancestor, and returns the minimum-of-chain trust score with the DAG depth. `gateCapability` then turns that into an authorization: higher tiers (`READ_ONLY` < `TRANSACT` < `ADMIN` < `ORCHESTRATE`) require both higher min-of-chain trust and greater depth, so an agent cannot escalate on a shallow or low-trust chain.
259
+
260
+ ```ts
261
+ import { signDagNode, verifyReceiptDag, gateCapability } from '@agentguard-run/spend';
262
+ // or the subpath: '@agentguard-run/spend/receipts/dag'
263
+
264
+ // Canonical diamond: A fans out to B and C, both fan in to terminal D.
265
+ const a = await signDagNode({ sequence: 0, privateKey, publicKey, capability: 'READ_ONLY', trustScore: 0.96,
266
+ decision: { action: 'allow', agent: 'A', step: 'ingest_invoice' } });
267
+ const b = await signDagNode({ sequence: 1, privateKey, publicKey, parents: [a], trustScore: 0.93,
268
+ decision: { action: 'allow', agent: 'B', step: 'analytics_score', ancestor: a.msgHash } });
269
+ const c = await signDagNode({ sequence: 2, privateKey, publicKey, parents: [a], trustScore: 0.88,
270
+ decision: { action: 'allow', agent: 'C', step: 'validate_payment', ancestor: a.msgHash } });
271
+ const d = await signDagNode({ sequence: 3, privateKey, publicKey, parents: [b, c], topology: 'diamond', trustScore: 0.91,
272
+ decision: { action: 'allow', agent: 'D', step: 'settle_invoice', capabilityClaim: 'payment_initiate' } });
273
+
274
+ const result = await verifyReceiptDag([a, b, c, d], publicKey);
275
+ // { valid: true, compositeTrust: 0.88, depth: 3, topologySummary: { diamond: 1, ... } }
276
+
277
+ gateCapability('TRANSACT', result).granted; // true — trust + depth clear the bar
278
+ gateCapability('ORCHESTRATE', result).granted; // false — TRUST_BELOW_THRESHOLD
279
+ ```
280
+
281
+ See it end-to-end (builds the diamond, verifies it, gates capabilities, and rejects an injected cycle):
282
+
283
+ ```bash
284
+ agentguard dag-demo
285
+ ```
286
+
287
+ For large agent swarms, `merkleRoot` / `compressReceiptDag` / `merkleInclusionProof` / `verifyInclusion` compress a DAG to a single root with per-node inclusion proofs. As with everything here, this is detection, verification, and reporting only: it never touches spend-cap enforcement.
288
+
254
289
  ## No proxy
255
290
 
256
291
  AgentGuard Spend is a library, not a gateway. It does not proxy traffic, store prompts, hold provider keys, or host policy state. The signed log lives in your storage.
@@ -13,8 +13,8 @@ import type { SignedDecisionLogEntry } from '../types';
13
13
  import type { TimestampAnchor } from './types';
14
14
  import { type OpenTimestampsAnchorOptions } from './opentimestamps';
15
15
  export type { AnchorProof, AnchorStatus, AnchorVerification, TimestampAnchor } from './types';
16
- export { OpenTimestampsAnchor, DEFAULT_OTS_CALENDARS, type OtsSubmit, type OpenTimestampsAnchorOptions } from './opentimestamps';
17
- export { writeAnchorProof, readAnchorIndex, readAnchorIndexAt, findAnchorForHead, anchorIndexPath, anchorProofPath, anchorDir, } from './store';
16
+ export { OpenTimestampsAnchor, DEFAULT_OTS_CALENDARS, defaultOtsLib, type OtsSubmit, type OtsLib, type OtsBitcoinAttestation, type OpenTimestampsAnchorOptions, } from './opentimestamps';
17
+ export { writeAnchorProof, replaceAnchorIndex, readAnchorIndex, readAnchorIndexAt, findAnchorForHead, anchorIndexPath, anchorProofPath, anchorDir, } from './store';
18
18
  /** Build a named anchor. Extend the switch as adapters are added. */
19
19
  export declare function createAnchor(type: string, options?: OpenTimestampsAnchorOptions): TimestampAnchor | null;
20
20
  /** Resolve the configured anchor from AGENTGUARD_ANCHOR, or null when unset. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/anchor/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAwB,KAAK,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE1F,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,KAAK,SAAS,EAAE,KAAK,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AACjI,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,SAAS,GACV,MAAM,SAAS,CAAC;AAEjB,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,eAAe,GAAG,IAAI,CAG5G;AAED,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,2BAAgC,GAAG,eAAe,GAAG,IAAI,CAIrG;AAED;;;;;GAKG;AACH,wBAAg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,WAAW,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAKhI;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAa9G"}
@@ -11,7 +11,7 @@
11
11
  * 64/071,781; 64/071,789).
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.anchorDir = exports.anchorProofPath = exports.anchorIndexPath = exports.findAnchorForHead = exports.readAnchorIndexAt = exports.readAnchorIndex = exports.writeAnchorProof = exports.DEFAULT_OTS_CALENDARS = exports.OpenTimestampsAnchor = void 0;
14
+ exports.anchorDir = exports.anchorProofPath = exports.anchorIndexPath = exports.findAnchorForHead = exports.readAnchorIndexAt = exports.readAnchorIndex = exports.replaceAnchorIndex = exports.writeAnchorProof = exports.defaultOtsLib = exports.DEFAULT_OTS_CALENDARS = exports.OpenTimestampsAnchor = void 0;
15
15
  exports.createAnchor = createAnchor;
16
16
  exports.createAnchorFromEnv = createAnchorFromEnv;
17
17
  exports.chainHeadDigestHex = chainHeadDigestHex;
@@ -21,8 +21,10 @@ const opentimestamps_1 = require("./opentimestamps");
21
21
  var opentimestamps_2 = require("./opentimestamps");
22
22
  Object.defineProperty(exports, "OpenTimestampsAnchor", { enumerable: true, get: function () { return opentimestamps_2.OpenTimestampsAnchor; } });
23
23
  Object.defineProperty(exports, "DEFAULT_OTS_CALENDARS", { enumerable: true, get: function () { return opentimestamps_2.DEFAULT_OTS_CALENDARS; } });
24
+ Object.defineProperty(exports, "defaultOtsLib", { enumerable: true, get: function () { return opentimestamps_2.defaultOtsLib; } });
24
25
  var store_1 = require("./store");
25
26
  Object.defineProperty(exports, "writeAnchorProof", { enumerable: true, get: function () { return store_1.writeAnchorProof; } });
27
+ Object.defineProperty(exports, "replaceAnchorIndex", { enumerable: true, get: function () { return store_1.replaceAnchorIndex; } });
26
28
  Object.defineProperty(exports, "readAnchorIndex", { enumerable: true, get: function () { return store_1.readAnchorIndex; } });
27
29
  Object.defineProperty(exports, "readAnchorIndexAt", { enumerable: true, get: function () { return store_1.readAnchorIndexAt; } });
28
30
  Object.defineProperty(exports, "findAnchorForHead", { enumerable: true, get: function () { return store_1.findAnchorForHead; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/anchor/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAoBH,oCAGC;AAGD,kDAIC;AAQD,gDAKC;AAOD,sCAaC;AA7DD,mCAAoC;AAGpC,qDAA0F;AAG1F,mDAAiI;AAAxH,sHAAA,oBAAoB,OAAA;AAAE,uHAAA,qBAAqB,OAAA;AACpD,iCAQiB;AAPf,yGAAA,gBAAgB,OAAA;AAChB,wGAAA,eAAe,OAAA;AACf,0GAAA,iBAAiB,OAAA;AACjB,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AACf,wGAAA,eAAe,OAAA;AACf,kGAAA,SAAS,OAAA;AAGX,qEAAqE;AACrE,SAAgB,YAAY,CAAC,IAAY,EAAE,UAAuC,EAAE;IAClF,IAAI,IAAI,KAAK,gBAAgB;QAAE,OAAO,IAAI,qCAAoB,CAAC,OAAO,CAAC,CAAC;IACxE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gFAAgF;AAChF,SAAgB,mBAAmB,CAAC,UAAuC,EAAE;IAC3E,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACxE,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAC5E,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB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AM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAChG,CAAC;QACD,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC"}
@@ -2,26 +2,21 @@
2
2
  * OpenTimestamps anchor adapter.
3
3
  *
4
4
  * Submits ONLY the 32-byte SHA-256 of the chain head to one or more public
5
- * OpenTimestamps calendar servers and stores the returned commitment. Nothing
6
- * else leaves the process (zero data plane): a hash is submitted, a proof comes
7
- * back.
5
+ * OpenTimestamps calendar servers, stores the returned `.ots` proof, and can
6
+ * later upgrade that proof to a Bitcoin block attestation. Nothing else leaves
7
+ * the process (zero data plane): a hash is submitted, an `.ots` proof comes
8
+ * back. No decision content, policy, scope, amount, model identity, or key
9
+ * material is ever transmitted.
8
10
  *
9
- * IMPORTANT HONESTY NOTE (read before relying on this in production):
10
- * The canonical OpenTimestamps `.ots` serialization and the Bitcoin-attestation
11
- * *upgrade + verification* require the `opentimestamps` npm package, which is
12
- * NOT a dependency of this package today. Without it, this adapter:
13
- * - DOES perform a real calendar submission (POST <calendar>/digest) and
14
- * store the raw calendar response bytes, and
15
- * - DOES bind the proof to the exact head hash it anchored,
16
- * but it does NOT parse the .ots structure or confirm the Bitcoin attestation.
17
- * Such proofs are therefore reported as `status: 'pending'` with
18
- * `attested: false`. The OTS wire/verification protocol is STUBBED pending the
19
- * `opentimestamps` dependency. We never fabricate an attested time.
20
- *
21
- * To complete the chain to Bitcoin: add `opentimestamps` and upgrade the stored
22
- * proof (`ots upgrade`), then `attestedAt` can be populated from the real
23
- * Bitcoin block time. This adapter reads `attestedAt` if present but never sets
24
- * it without a real upgrade.
11
+ * This adapter uses the real `opentimestamps` npm library through an injectable
12
+ * boundary (`OtsLib`), so:
13
+ * - `anchor()` builds a `DetachedTimestampFile` from the raw digest, stamps it
14
+ * against public calendars, and stores the serialized `.ots` bytes,
15
+ * - `upgrade()` fetches the Bitcoin attestation when the calendars have it and
16
+ * persists the upgraded `.ots` (idempotent),
17
+ * - `verify()` reports `attested: true` with a real `when` ONLY when the `.ots`
18
+ * proof actually carries a Bitcoin block-header attestation. A pending proof
19
+ * stays pending. An attested time is NEVER fabricated.
25
20
  *
26
21
  * Patent notice: Protected by U.S. patent-pending technology
27
22
  * (App. Nos. 63/983,615; 63/983,621; 63/983,843; 63/984,626;
@@ -31,25 +26,61 @@ import type { AnchorProof, AnchorVerification, TimestampAnchor } from './types';
31
26
  /** Public OpenTimestamps calendar servers (aggregators). */
32
27
  export declare const DEFAULT_OTS_CALENDARS: string[];
33
28
  /**
34
- * Transport hook: submit a digest to one calendar, return the raw response
35
- * bytes (the calendar's commitment). Injectable for tests / private mirrors.
36
- * Should reject on network/HTTP failure.
29
+ * Result of inspecting an `.ots` proof for a Bitcoin attestation.
30
+ * `bitcoinAttested` is true iff the timestamp carries a Bitcoin block-header
31
+ * attestation; `attestedTimeSec` is the confirmed block time (unix seconds),
32
+ * only present when the attestation resolves to a real time.
33
+ */
34
+ export interface OtsBitcoinAttestation {
35
+ bitcoinAttested: boolean;
36
+ attestedTimeSec?: number;
37
+ height?: number;
38
+ }
39
+ /**
40
+ * The `opentimestamps` library boundary. Injectable so tests are deterministic
41
+ * and never touch the network. Every method receives/returns raw bytes and the
42
+ * 32-byte digest only — zero data plane.
43
+ */
44
+ export interface OtsLib {
45
+ /** Stamp a 32-byte SHA-256 digest against calendars; return the `.ots` bytes. */
46
+ stamp(sha256Digest: Uint8Array, calendars: string[]): Promise<Uint8Array>;
47
+ /** Upgrade stored `.ots` bytes (fetch Bitcoin attestation if available). Idempotent; returns the possibly-upgraded `.ots` bytes. */
48
+ upgrade(otsBytes: Uint8Array): Promise<Uint8Array>;
49
+ /** Inspect `.ots` bytes for the given digest. MUST throw if the proof's embedded file hash does not equal `sha256Digest`. */
50
+ verify(sha256Digest: Uint8Array, otsBytes: Uint8Array): Promise<OtsBitcoinAttestation>;
51
+ }
52
+ /**
53
+ * @deprecated Legacy calendar-POST transport hook. Superseded by the `OtsLib`
54
+ * boundary now that the real `opentimestamps` library is a dependency. Retained
55
+ * only so existing type imports keep compiling.
37
56
  */
38
57
  export type OtsSubmit = (calendarUrl: string, digest: Uint8Array) => Promise<Uint8Array>;
39
58
  export interface OpenTimestampsAnchorOptions {
40
59
  calendars?: string[];
41
- /** Override the calendar transport (defaults to a real https POST). */
42
- submit?: OtsSubmit;
43
- /** Require at least one calendar to succeed. Defaults to true. */
44
- requireCalendar?: boolean;
60
+ /** Override the OpenTimestamps library boundary (defaults to the real npm lib). */
61
+ lib?: OtsLib;
45
62
  }
63
+ /**
64
+ * Default `OtsLib` backed by the real `opentimestamps` npm package. Lazily
65
+ * required so the SDK never pulls the library (or node:https) at import time in
66
+ * bundlers — only when an anchor is actually exercised.
67
+ */
68
+ export declare function defaultOtsLib(): OtsLib;
46
69
  export declare class OpenTimestampsAnchor implements TimestampAnchor {
47
70
  readonly type = "opentimestamps";
48
71
  private readonly calendars;
49
- private readonly submit;
50
- private readonly requireCalendar;
72
+ private lazyLib;
51
73
  constructor(options?: OpenTimestampsAnchorOptions);
74
+ private lib;
75
+ private digestOf;
52
76
  anchor(headHashHex: string): Promise<AnchorProof>;
77
+ /**
78
+ * Fetch the Bitcoin attestation for a stored proof, if the calendars now have
79
+ * it, and return an updated proof. Idempotent: safe to call repeatedly. If the
80
+ * attestation is confirmable, `attestedAt` is set to the real Bitcoin block
81
+ * time and status becomes `complete`; otherwise the proof stays `pending`.
82
+ */
83
+ upgrade(proof: AnchorProof): Promise<AnchorProof>;
53
84
  verify(headHashHex: string, proof: AnchorProof): Promise<AnchorVerification>;
54
85
  }
55
86
  //# sourceMappingURL=opentimestamps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"opentimestamps.d.ts","sourceRoot":"","sources":["../../src/an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kB,CAAC;CA2DnF"}
@@ -3,26 +3,21 @@
3
3
  * OpenTimestamps anchor adapter.
4
4
  *
5
5
  * Submits ONLY the 32-byte SHA-256 of the chain head to one or more public
6
- * OpenTimestamps calendar servers and stores the returned commitment. Nothing
7
- * else leaves the process (zero data plane): a hash is submitted, a proof comes
8
- * back.
6
+ * OpenTimestamps calendar servers, stores the returned `.ots` proof, and can
7
+ * later upgrade that proof to a Bitcoin block attestation. Nothing else leaves
8
+ * the process (zero data plane): a hash is submitted, an `.ots` proof comes
9
+ * back. No decision content, policy, scope, amount, model identity, or key
10
+ * material is ever transmitted.
9
11
  *
10
- * IMPORTANT HONESTY NOTE (read before relying on this in production):
11
- * The canonical OpenTimestamps `.ots` serialization and the Bitcoin-attestation
12
- * *upgrade + verification* require the `opentimestamps` npm package, which is
13
- * NOT a dependency of this package today. Without it, this adapter:
14
- * - DOES perform a real calendar submission (POST <calendar>/digest) and
15
- * store the raw calendar response bytes, and
16
- * - DOES bind the proof to the exact head hash it anchored,
17
- * but it does NOT parse the .ots structure or confirm the Bitcoin attestation.
18
- * Such proofs are therefore reported as `status: 'pending'` with
19
- * `attested: false`. The OTS wire/verification protocol is STUBBED pending the
20
- * `opentimestamps` dependency. We never fabricate an attested time.
21
- *
22
- * To complete the chain to Bitcoin: add `opentimestamps` and upgrade the stored
23
- * proof (`ots upgrade`), then `attestedAt` can be populated from the real
24
- * Bitcoin block time. This adapter reads `attestedAt` if present but never sets
25
- * it without a real upgrade.
12
+ * This adapter uses the real `opentimestamps` npm library through an injectable
13
+ * boundary (`OtsLib`), so:
14
+ * - `anchor()` builds a `DetachedTimestampFile` from the raw digest, stamps it
15
+ * against public calendars, and stores the serialized `.ots` bytes,
16
+ * - `upgrade()` fetches the Bitcoin attestation when the calendars have it and
17
+ * persists the upgraded `.ots` (idempotent),
18
+ * - `verify()` reports `attested: true` with a real `when` ONLY when the `.ots`
19
+ * proof actually carries a Bitcoin block-header attestation. A pending proof
20
+ * stays pending. An attested time is NEVER fabricated.
26
21
  *
27
22
  * Patent notice: Protected by U.S. patent-pending technology
28
23
  * (App. Nos. 63/983,615; 63/983,621; 63/983,843; 63/984,626;
@@ -30,6 +25,7 @@
30
25
  */
31
26
  Object.defineProperty(exports, "__esModule", { value: true });
32
27
  exports.OpenTimestampsAnchor = exports.DEFAULT_OTS_CALENDARS = void 0;
28
+ exports.defaultOtsLib = defaultOtsLib;
33
29
  /** Public OpenTimestamps calendar servers (aggregators). */
34
30
  exports.DEFAULT_OTS_CALENDARS = [
35
31
  'https://alice.btc.calendar.opentimestamps.org',
@@ -45,88 +41,141 @@ function hexToBytes(hex) {
45
41
  out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
46
42
  return out;
47
43
  }
48
- /** Default transport: POST the raw digest bytes to <calendar>/digest over https. */
49
- const defaultSubmit = (calendarUrl, digest) => new Promise((resolve, reject) => {
50
- // Lazy require so the SDK never pulls node:https at import time in bundlers.
51
- // eslint-disable-next-line @typescript-eslint/no-var-requires
52
- const https = require('https');
53
- const url = new URL(calendarUrl.replace(/\/+$/, '') + '/digest');
54
- const req = https.request({
55
- hostname: url.hostname,
56
- port: url.port || 443,
57
- path: url.pathname,
58
- method: 'POST',
59
- headers: {
60
- 'Content-Type': 'application/octet-stream',
61
- 'Accept': 'application/vnd.opentimestamps.v1',
62
- 'Content-Length': digest.length,
63
- 'User-Agent': 'agentguard-spend',
44
+ function bytesEqual(a, b) {
45
+ if (a.length !== b.length)
46
+ return false;
47
+ for (let i = 0; i < a.length; i++)
48
+ if (a[i] !== b[i])
49
+ return false;
50
+ return true;
51
+ }
52
+ /**
53
+ * Default `OtsLib` backed by the real `opentimestamps` npm package. Lazily
54
+ * required so the SDK never pulls the library (or node:https) at import time in
55
+ * bundlers — only when an anchor is actually exercised.
56
+ */
57
+ function defaultOtsLib() {
58
+ let OTS;
59
+ try {
60
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
61
+ OTS = require('opentimestamps');
62
+ }
63
+ catch {
64
+ throw new Error("Bitcoin timestamp anchoring requires the optional 'opentimestamps' package. " +
65
+ 'Install it to enable this feature: npm i opentimestamps');
66
+ }
67
+ const { DetachedTimestampFile, Ops, Notary } = OTS;
68
+ const detachedFromHash = (digest) => DetachedTimestampFile.fromHash(new Ops.OpSHA256(), Array.from(digest));
69
+ const detachedFromOts = (otsBytes) => DetachedTimestampFile.deserialize(Array.from(otsBytes));
70
+ const toBytes = (detached) => Uint8Array.from(detached.serializeToBytes());
71
+ const hasBitcoinAttestation = (detached) => {
72
+ let found = false;
73
+ detached.timestamp.allAttestations().forEach((attestation) => {
74
+ if (attestation instanceof Notary.BitcoinBlockHeaderAttestation)
75
+ found = true;
76
+ });
77
+ return found;
78
+ };
79
+ return {
80
+ async stamp(sha256Digest, calendars) {
81
+ const detached = detachedFromHash(sha256Digest);
82
+ await OTS.stamp(detached, { calendars, m: calendars.length >= 2 ? 2 : 1 });
83
+ return toBytes(detached);
84
+ },
85
+ async upgrade(otsBytes) {
86
+ const detached = detachedFromOts(otsBytes);
87
+ await OTS.upgrade(detached);
88
+ return toBytes(detached);
64
89
  },
65
- }, (res) => {
66
- const chunks = [];
67
- res.on('data', (c) => chunks.push(c));
68
- res.on('end', () => {
69
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
70
- resolve(new Uint8Array(Buffer.concat(chunks)));
90
+ async verify(sha256Digest, otsBytes) {
91
+ const detached = detachedFromOts(otsBytes);
92
+ // Bind the proof to the supplied digest: the .ots embeds the file hash it
93
+ // was built from. A mismatch means this proof is not for this head.
94
+ if (!bytesEqual(Uint8Array.from(detached.fileDigest()), sha256Digest)) {
95
+ throw new Error('OTS proof file hash does not match the supplied digest');
71
96
  }
72
- else {
73
- reject(new Error(`OTS calendar ${calendarUrl} returned HTTP ${res.statusCode}`));
97
+ if (!hasBitcoinAttestation(detached)) {
98
+ return { bitcoinAttested: false };
74
99
  }
75
- });
76
- });
77
- req.on('error', reject);
78
- req.write(Buffer.from(digest));
79
- req.end();
80
- });
100
+ // A Bitcoin attestation is present; resolve its block time. verifyTimestamp
101
+ // checks completed attestations only (no re-stamp) and returns
102
+ // { bitcoin: { timestamp, height } } when confirmable.
103
+ const result = await OTS.verifyTimestamp(detached.timestamp, {});
104
+ const btc = result && (result.bitcoin || result.Bitcoin);
105
+ if (btc && typeof btc.timestamp === 'number') {
106
+ return { bitcoinAttested: true, attestedTimeSec: btc.timestamp, height: btc.height };
107
+ }
108
+ // Attestation present but time not resolvable right now (e.g. explorer
109
+ // unreachable). Report attested-but-timeless; callers keep it pending
110
+ // rather than inventing a time.
111
+ return { bitcoinAttested: true };
112
+ },
113
+ };
114
+ }
81
115
  class OpenTimestampsAnchor {
82
116
  type = 'opentimestamps';
83
117
  calendars;
84
- submit;
85
- requireCalendar;
118
+ lazyLib;
86
119
  constructor(options = {}) {
87
120
  this.calendars = options.calendars ?? exports.DEFAULT_OTS_CALENDARS;
88
- this.submit = options.submit ?? defaultSubmit;
89
- this.requireCalendar = options.requireCalendar ?? true;
121
+ this.lazyLib = options.lib;
90
122
  }
91
- async anchor(headHashHex) {
123
+ lib() {
124
+ if (!this.lazyLib)
125
+ this.lazyLib = defaultOtsLib();
126
+ return this.lazyLib;
127
+ }
128
+ digestOf(headHashHex) {
92
129
  const digest = hexToBytes(headHashHex);
93
130
  if (digest.length !== 32) {
94
131
  throw new Error('OpenTimestampsAnchor: chain head digest must be SHA-256 (32 bytes)');
95
132
  }
96
- const responses = [];
97
- const used = [];
98
- const errors = [];
99
- for (const calendar of this.calendars) {
100
- try {
101
- const bytes = await this.submit(calendar, digest);
102
- responses.push(bytes);
103
- used.push(calendar);
104
- }
105
- catch (err) {
106
- errors.push(`${calendar}: ${err instanceof Error ? err.message : String(err)}`);
107
- }
108
- }
109
- if (responses.length === 0 && this.requireCalendar) {
110
- throw new Error('OpenTimestampsAnchor: no calendar accepted the digest: ' + errors.join('; '));
111
- }
112
- // Concatenate raw calendar commitments length-prefixed so verify can bind
113
- // them back to the head. This is NOT a canonical .ots file — see the module
114
- // note. It is a real, non-fabricated record of what each calendar returned.
115
- const proofBytes = concatLengthPrefixed(responses);
133
+ return digest;
134
+ }
135
+ async anchor(headHashHex) {
136
+ const digest = this.digestOf(headHashHex);
137
+ const otsBytes = await this.lib().stamp(digest, this.calendars);
116
138
  return {
117
139
  version: 1,
118
140
  anchorType: this.type,
119
141
  headHashHex: headHashHex.trim().toLowerCase(),
120
142
  submittedAt: new Date().toISOString(),
121
- proof: Buffer.from(proofBytes).toString('base64'),
143
+ proof: Buffer.from(otsBytes).toString('base64'),
122
144
  status: 'pending',
123
- calendars: used,
145
+ calendars: this.calendars.slice(),
124
146
  attestedAt: null,
125
- note: 'Calendar commitment stored. Bitcoin attestation upgrade + verification ' +
126
- 'require the `opentimestamps` npm package (not bundled); OTS .ots ' +
127
- 'serialization is stubbed pending that dependency. Only a SHA-256 hash was sent.',
147
+ note: 'OpenTimestamps .ots proof stored. Bitcoin attestation not yet confirmed; ' +
148
+ "run 'agentguard anchor --upgrade' once the calendars have committed the " +
149
+ 'digest to a Bitcoin block. Only a 32-byte SHA-256 hash was transmitted.',
128
150
  };
129
151
  }
152
+ /**
153
+ * Fetch the Bitcoin attestation for a stored proof, if the calendars now have
154
+ * it, and return an updated proof. Idempotent: safe to call repeatedly. If the
155
+ * attestation is confirmable, `attestedAt` is set to the real Bitcoin block
156
+ * time and status becomes `complete`; otherwise the proof stays `pending`.
157
+ */
158
+ async upgrade(proof) {
159
+ if (proof.anchorType !== this.type)
160
+ return proof;
161
+ const digest = this.digestOf(proof.headHashHex);
162
+ const current = Uint8Array.from(Buffer.from(proof.proof, 'base64'));
163
+ const upgraded = await this.lib().upgrade(current);
164
+ const next = { ...proof, proof: Buffer.from(upgraded).toString('base64') };
165
+ const info = await this.lib().verify(digest, upgraded);
166
+ if (info.bitcoinAttested && typeof info.attestedTimeSec === 'number') {
167
+ next.attestedAt = new Date(info.attestedTimeSec * 1000).toISOString();
168
+ next.status = 'complete';
169
+ next.note =
170
+ 'OpenTimestamps .ots proof upgraded: chain head committed to Bitcoin' +
171
+ (typeof info.height === 'number' ? ` block ${info.height}` : '') + '.';
172
+ }
173
+ else {
174
+ next.attestedAt = proof.attestedAt ?? null;
175
+ next.status = 'pending';
176
+ }
177
+ return next;
178
+ }
130
179
  async verify(headHashHex, proof) {
131
180
  const head = headHashHex.trim().toLowerCase();
132
181
  if (proof.anchorType !== this.type) {
@@ -141,39 +190,50 @@ class OpenTimestampsAnchor {
141
190
  detail: 'proof does not bind the supplied chain head hash',
142
191
  };
143
192
  }
144
- // A real Bitcoin-attested upgrade populates attestedAt; we trust it only if
145
- // present (never synthesised here).
193
+ let digest;
194
+ try {
195
+ digest = this.digestOf(head);
196
+ }
197
+ catch (err) {
198
+ return { ok: false, status: 'invalid', when: null, attested: false, detail: err instanceof Error ? err.message : String(err) };
199
+ }
200
+ const hasProofBytes = typeof proof.proof === 'string' && proof.proof.length > 0;
201
+ if (!hasProofBytes) {
202
+ return { ok: false, status: 'invalid', when: null, attested: false, detail: 'proof carries no .ots commitment' };
203
+ }
204
+ let info;
205
+ try {
206
+ const otsBytes = Uint8Array.from(Buffer.from(proof.proof, 'base64'));
207
+ info = await this.lib().verify(digest, otsBytes);
208
+ }
209
+ catch (err) {
210
+ return {
211
+ ok: false,
212
+ status: 'invalid',
213
+ when: null,
214
+ attested: false,
215
+ detail: `OTS proof did not verify against this head: ${err instanceof Error ? err.message : String(err)}`,
216
+ };
217
+ }
218
+ // attested:true is gated SOLELY on the .ots carrying a Bitcoin block
219
+ // attestation that resolves to a real block time. Never fabricated.
220
+ if (info.bitcoinAttested && typeof info.attestedTimeSec === 'number') {
221
+ return { ok: true, status: 'complete', when: new Date(info.attestedTimeSec * 1000).toISOString(), attested: true };
222
+ }
223
+ // A previously-recorded, real upgrade may have persisted attestedAt; trust it
224
+ // (we only ever set it from a genuine Bitcoin block time).
146
225
  if (proof.attestedAt) {
147
226
  return { ok: true, status: 'complete', when: proof.attestedAt, attested: true };
148
227
  }
149
- const hasCommitment = typeof proof.proof === 'string' && proof.proof.length > 0;
150
- if (!hasCommitment && !(proof.calendars && proof.calendars.length > 0)) {
151
- return { ok: false, status: 'invalid', when: null, attested: false, detail: 'proof carries no calendar commitment' };
152
- }
153
228
  return {
154
229
  ok: true,
155
230
  status: 'pending',
156
231
  when: proof.submittedAt ?? null,
157
232
  attested: false,
158
- detail: 'Calendar commitment present for this head hash; Bitcoin attestation not yet ' +
159
- 'confirmed (requires `opentimestamps` upgrade). `when` is the submission time, not an attested time.',
233
+ detail: 'OpenTimestamps .ots commitment present for this head hash; Bitcoin attestation ' +
234
+ 'not yet confirmed (run `anchor --upgrade`). `when` is the submission time, not an attested time.',
160
235
  };
161
236
  }
162
237
  }
163
238
  exports.OpenTimestampsAnchor = OpenTimestampsAnchor;
164
- function concatLengthPrefixed(chunks) {
165
- let total = 0;
166
- for (const c of chunks)
167
- total += 4 + c.length;
168
- const out = new Uint8Array(total);
169
- const view = new DataView(out.buffer);
170
- let offset = 0;
171
- for (const c of chunks) {
172
- view.setUint32(offset, c.length, false);
173
- offset += 4;
174
- out.set(c, offset);
175
- offset += c.length;
176
- }
177
- return out;
178
- }
179
239
  //# sourceMappingURL=opentimestamps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"opentimestamps.js","sourceRoot":"","sources":["../../src/anchor/opentimestamps.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAIH,4DAA4D;AAC/C,QAAA,qBAAqB,GAAG;IACnC,+CAA+C;IAC/C,6CAA6C;CAC9C,CAAC;AAiBF,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAA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CAAC,WAAW,IAAI,IAAI;YAC/B,QAAQ,EAAE,KAAK;YACf,MAAM,EACJ,iFAAiF;gBACjF,kGAAkG;SACrG,CAAC;IACJ,CAAC;CACF;AA/HD,oDA+HC"}
@@ -17,6 +17,10 @@ export declare function anchorIndexPath(tenant: string, home?: string): string;
17
17
  export declare function anchorProofPath(tenant: string, home?: string): string;
18
18
  /** Append a proof to the tenant index and write its raw bytes to anchor.ots. */
19
19
  export declare function writeAnchorProof(tenant: string, proof: AnchorProof, home?: string): void;
20
+ /** Overwrite the tenant index with `proofs` and refresh the raw .ots sidecar
21
+ * from the most recent proof. Used by `anchor --upgrade` to update proofs in
22
+ * place (idempotent) rather than appending duplicates. */
23
+ export declare function replaceAnchorIndex(tenant: string, proofs: AnchorProof[], home?: string): void;
20
24
  export declare function readAnchorIndex(tenant: string, home?: string): AnchorProof[];
21
25
  /** Read an anchor index directly from a path (used by verify beside a trace). */
22
26
  export declare function readAnchorIndexAt(indexPath: string): AnchorProof[];
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/anchor/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAsB,GAAG,MAAM,CAG9E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAWxF;AAED,wBA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