@agent-custody/receipts 0.10.0 → 0.11.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/README.md +20 -10
- package/dist/anchor-evm.d.ts +19 -0
- package/dist/anchor-evm.js +49 -0
- package/dist/anchor.d.ts +167 -0
- package/dist/anchor.js +367 -0
- package/dist/check.js +8 -2
- package/dist/cli.js +68 -4
- package/dist/config.d.ts +9 -0
- package/dist/config.js +23 -1
- package/dist/gateway.d.ts +1 -1
- package/dist/gateway.js +23 -11
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/log-check.d.ts +15 -0
- package/dist/log-check.js +52 -0
- package/dist/receipt.d.ts +2 -0
- package/dist/verify.d.ts +2 -0
- package/dist/verify.js +7 -1
- package/docs/anchoring.md +115 -0
- package/docs/configuration.md +5 -1
- package/docs/threat-model.md +16 -2
- package/docs/tutorials.md +3 -0
- package/docs/usage.md +19 -1
- package/docs/verification.md +4 -2
- package/package.json +7 -2
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1176 -967
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Two producers, one receipt format, one verifier.
|
|
|
10
10
|
Anyone holding the public keys can verify a receipt offline. The agent is not trusted. The layer around it is, and the receipt says exactly how far that trust extends, starting with who issued it. What the receipt file carries of a call is a choice per tool: a field can be withheld as a commitment or encrypted under your key, and the verifier recomputes the digests when it is shown the values.
|
|
11
11
|
|
|
12
12
|
- [Reference](https://docs.agent-custody.dev/reference/): every function, endpoint, MCP tool, and command with its request and response
|
|
13
|
-
- [Tutorials](docs/tutorials.md): thirty-
|
|
13
|
+
- [Tutorials](docs/tutorials.md): thirty-four runnable examples, one per aspect of the code, all executed by the test suite
|
|
14
14
|
- [Financial operations](docs/financial-operations.md): durable operation ids, provider idempotency keys, atomic daily budget reservations, and reconciliation receipts for uncertain outcomes
|
|
15
15
|
- [The gateway console](docs/console.md): an admin service for the person who runs a gateway: config, tools, receipts with a verdict each, a policy editor that replays recorded calls before it saves, grant revocation, and an audit trail
|
|
16
16
|
- [Configuring the gateway](docs/configuration.md): who may use which tools and where the tools live, a worked example with two agents, the Docker image, and `agent-custody check` to validate a config before it starts
|
|
@@ -21,6 +21,7 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
|
|
|
21
21
|
- [Writing policies](docs/policies.md): how a tool call becomes a Cedar request, with tested examples, and replaying history against a proposed policy with `policy simulate`
|
|
22
22
|
- [Verifying a receipt](docs/verification.md): what each check means and what a verified receipt does and does not prove
|
|
23
23
|
- [What the evidence satisfies](docs/compliance.md): the receipts, packs, and certificates mapped to SOC 2, ISO 27001, the EU AI Act, and UK GDPR, with what none of them claims
|
|
24
|
+
- [Anchoring the log on a chain](docs/anchoring.md): the log's checkpoints committed to Ethereum mainnet, or another EVM chain the installation picks, from a published address, what that proves and what it does not, running the anchor, and `log-check` against the chain
|
|
24
25
|
- [Threat model](docs/threat-model.md): every party who could make a receipt false, the move, what stops it, and whether that is a property of the evidence or of the deployment; and what is not defended
|
|
25
26
|
|
|
26
27
|
## Getting started
|
|
@@ -189,7 +190,7 @@ Every field carries a provenance label. This is the design decision that matters
|
|
|
189
190
|
bun install # from the repository root, once for the workspace
|
|
190
191
|
cd packages/receipts
|
|
191
192
|
node scripts/demo.ts # gateway: keys, grant, policy, four tool calls, verification, a tampering attempt; then the SDK wrapping the same tool
|
|
192
|
-
node examples/01-keys-and-signing.ts # first of thirty-
|
|
193
|
+
node examples/01-keys-and-signing.ts # first of thirty-four step-by-step examples, see docs/tutorials.md
|
|
193
194
|
bun run test # this package; `bun run test` at the root runs every package
|
|
194
195
|
```
|
|
195
196
|
|
|
@@ -227,9 +228,9 @@ const refund = issuer.wrap("stripe.refund", async (args: { amount: number }) =>
|
|
|
227
228
|
| the principal really delegated this scope to this agent | anyone with the principal's key | operator, agent | grant signed by principal key, checked for scope and validity window | done |
|
|
228
229
|
| the policy decision was made against this exact policy | anyone | operator swapping policies | sha256 of policy text in the receipt | done |
|
|
229
230
|
| facts the policy relied on were not asserted by the agent | anyone reading the receipt | agent | facts fetched by the gateway, recorded with their own digests, labelled `observed` | done |
|
|
230
|
-
| the side effect was committed to the log before it happened | anyone with a log copy | operator, log outage | for tools in `precommit`, a signed authorization logged first, embedded in the receipt with its leaf position, checked to precede the receipt | done |
|
|
231
|
+
| the side effect was committed to the log before it happened | anyone with a log copy | operator, log outage | for tools in `precommit`, or every tool under `strict`, a signed authorization logged first, embedded in the receipt with its leaf position, checked to precede the receipt | done |
|
|
231
232
|
| the upstream system actually executed the action | anyone with the upstream's key or the provider's secret | operator | the upstream signs its result for the receipt, or the provider's own delivery signature (Stripe, GitHub) is embedded and checked | done, for upstreams that sign |
|
|
232
|
-
| the operator itself cannot mint a false receipt | regulator, counterparty | operator | needs a TEE-
|
|
233
|
+
| the operator itself cannot mint a false receipt | regulator, counterparty | operator | needs a TEE gateway with an attested build ([#179](https://github.com/svayatta/agent-custody/issues/179)), and the provider's own records to catch actions outside the gateway ([#178](https://github.com/svayatta/agent-custody/issues/178)) | **not done** |
|
|
233
234
|
| which model produced the call | anyone | operator | no hosted provider signs model identity | **not possible today**, labelled `claimed` |
|
|
234
235
|
| an SDK receipt reflects what the tool really did | anyone | agent's own process | none; the SDK shares a process with the agent | **by design not claimed**; issuer kind `sdk` says so |
|
|
235
236
|
|
|
@@ -241,11 +242,13 @@ If a vendor tells you their receipts prove more than the first five rows, ask th
|
|
|
241
242
|
src/config.ts gateway and SDK config schemas, path resolution
|
|
242
243
|
src/crypto.ts canonical JSON, sha256, Ed25519 keys, DSSE sign/verify
|
|
243
244
|
src/log.ts Merkle log: append, root, inclusion and consistency proofs, verify, JSONL persistence
|
|
244
|
-
src/log-check.ts the outside monitor: verifies the head, checkpoints, and
|
|
245
|
+
src/log-check.ts the outside monitor: verifies the head, checkpoints, witness, and anchor of a running log
|
|
245
246
|
src/portal.ts the tenant portal: register, first key, usage against plan, keys, Stripe billing, export, member roles, TOTP MFA, single sign-on, on the log's Postgres
|
|
246
247
|
src/sso.ts enterprise sign-in for the portal: OIDC (code and PKCE, id_token checked against the IdP's key set) and SAML 2.0 (signed assertions only, through @node-saml/node-saml)
|
|
247
248
|
src/log-export.ts a tenant's export of their own log, self-checked, as a log file the verifier reads
|
|
248
249
|
src/witness.ts the witness: countersigns the log's checkpoints from another operator's machine, or refuses with an alarm
|
|
250
|
+
src/anchor.ts the anchor: commits a Merkle root over new checkpoints to a chain, or refuses with an alarm; checks a record against JSON-RPC
|
|
251
|
+
src/anchor-evm.ts the anchor's transactions on Ethereum or another EVM chain, through the optional dependency viem
|
|
249
252
|
src/signer.ts the signer: the log's key in its own process, the key document verifiers fetch
|
|
250
253
|
src/checkpoints.ts signed heads published on a schedule, to files and to Postgres
|
|
251
254
|
src/log-store.ts the log server's backends: the file, and Postgres with tenants, hashed tokens, one writer per tenant, rate limits
|
|
@@ -276,7 +279,7 @@ src/retention.ts pruning the log: leaves become their hashes, bundles are remo
|
|
|
276
279
|
src/index.ts the package's public surface; adapters are exported on ./sdk/<framework> subpaths
|
|
277
280
|
tsconfig.build.json emits dist/ (JavaScript plus declarations) for consumers; the repo itself runs the .ts directly
|
|
278
281
|
scripts/ fake Stripe upstream (signs its results with --key), a second fake upstream, fixture builders for gateway and SDK, the replay builder (`replay.ts`: example 27 and state example 07 as a folder of receipts and public keys anyone can verify with the published packages), demo
|
|
279
|
-
examples/ thirty-
|
|
282
|
+
examples/ thirty-four runnable tutorials, plus examples/languages/: Python, Go, Java, and Rust clients of the sidecar, run by the test suite, one per aspect; each is run by the test suite
|
|
280
283
|
test/ unit tests per module, end-to-end gateway test, SDK and hook tests,
|
|
281
284
|
adapter tests against the real packages, and a test that runs every policy in docs/policies.md
|
|
282
285
|
docs/ tutorials, usage (gateway), codex-recovery (live demo), approvals, sdk, policies, verification
|
|
@@ -288,6 +291,7 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
288
291
|
|
|
289
292
|
**Done**
|
|
290
293
|
|
|
294
|
+
- Strict mode: `"strict": true` refuses a local log, a log that is not hash-only, and a log without pinned keys; precommits every tool, in observe mode too; and turns the outbox off. No call the agent makes is forwarded before its authorization is in a log the operator does not run, every receipt says `issuer.strict`, and `verify --require-strict` requires it ([usage](docs/usage.md#strict-mode), tutorial 34). [Issue #177](https://github.com/svayatta/agent-custody/issues/177).
|
|
291
295
|
- Policy reload: the gateway re-reads `policy.cedar` whenever it changes and applies it from the next call, with no restart and no dropped session; a policy that does not parse is refused and the one in force stays, and every change or refusal is recorded in `receipts/policy-reloads.jsonl` ([usage](docs/usage.md)).
|
|
292
296
|
- Live Codex support recovery demo: model-selected MCP calls, incorrect CRM memory, a reviewed recovery plan, simulated credit compensation, and verified evidence; [guide](docs/codex-recovery.md), with offline regression coverage.
|
|
293
297
|
- Payload-bound human approvals: short-lived signatures over the principal, agent, tool, full arguments, amount, currency, and beneficiary; configurable one- or two-key thresholds, enforced even in observe mode, a configurable lifetime cap, persistent atomic single-use consumption before forwarding, and independent approval-key verification. [Guide](docs/approvals.md), tutorial 30.
|
|
@@ -331,12 +335,18 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
331
335
|
- Enterprise identity for the hosted portal: member roles (`owner`, `admin`, `reviewer`, `readonly`) with invites, TOTP MFA with single-use codes and an operator reset (`log-admin user mfa-reset`), and single sign-on per tenant through the tenant's own IdP, OIDC or SAML 2.0, set by the operator (`log-admin sso set`), with an enforce mode that closes the password, GitHub, and Google paths to members. Revoking an agent's authority mid-session already shipped (`agent-custody revoke`, example 27); example 31 shows the enterprise sign-in and the roles.
|
|
332
336
|
- The [state review console](../state/README.md#explain-one-action): search receipts by transaction, customer, agent or time, read the ten answers, and hand over a portable HTML/JSON case whose signatures, authorizations and inclusion proofs can be verified offline.
|
|
333
337
|
- A log outage after an ordinary call (issue #149): the signed receipt waits in `receipts/outbox/` and the gateway appends it when the log is back, the agent gets the real outcome marked `log-pending`, `GET /health` counts the pending receipts, and `requirePrecommit` refuses a remote log with an empty `precommit`. The [failure table](docs/usage.md#when-the-log-fails) gives each case.
|
|
338
|
+
- The anchor (issue #176): `agent-custody anchor` proves each new checkpoint extends the last one it anchored, then commits a Merkle root over them in one transaction from its address to itself, on Ethereum by default or on Base, Arbitrum, Optimism, Polygon, or any EVM chain by id (`--chain`), with a fee cap sized per chain. It publishes each log's record and inclusion proof, sends nothing for an idle log, skips a run above a fee cap, and never has two transactions in flight. Every transaction covers every watched log, and a transaction counts only once its block is finalized, following reorgs. `log-check --anchor-url` checks the record against one or more JSON-RPC endpoints, requires the log id the verifier pinned and the address's newest transaction, and checks the log's head against the anchored checkpoint, so a rewritten or rolled-back tree is caught from the chain alone ([anchoring](docs/anchoring.md), example 33).
|
|
334
339
|
|
|
335
340
|
**Next, in the order it pays off**
|
|
336
341
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
342
|
+
The first three close the gap between a log the operator cannot rewrite and a record the operator cannot shape.
|
|
343
|
+
|
|
344
|
+
1. Run the anchor for log.agent-custody.dev on mainnet: a funded key held only by the anchor service on the host, its records served beside the checkpoints, its address and each tenant's log id published in the welcome sheet and on the security page, and the monitor checking it. The code is done. [Issue #176](https://github.com/svayatta/agent-custody/issues/176).
|
|
345
|
+
2. Completeness from the provider's side: an auditor's read-only key lists Stripe's refunds, then GitHub's actions, and matches each one to a receipt. That catches what no gateway can see, an action taken outside it. [Issue #178](https://github.com/svayatta/agent-custody/issues/178).
|
|
346
|
+
3. A TEE gateway: a confidential container with a reproducible, attested build, the signing key generated and kept in the enclave, TLS ending inside it, and both verifiers checking the path from the receipt key, through the attestation, to the release. It replaces the TEE-hosted signer planned before. [Issue #179](https://github.com/svayatta/agent-custody/issues/179).
|
|
347
|
+
4. Run the witness for log.agent-custody.dev on a machine and under an account that is not ours, and require it in the welcome sheet. The code is done; what it needs is a second operator. [Issue #116](https://github.com/svayatta/agent-custody/issues/116).
|
|
348
|
+
5. Post-quantum signatures: ML-DSA beside Ed25519 in the same DSSE envelope, hybrid by default when a PQ key is present, in every signed artefact and in the browser verifier. [Issue #11](https://github.com/svayatta/agent-custody/issues/11).
|
|
349
|
+
6. Receiver attestation for agent-to-agent calls: the delegate signs its answer for the receipt, as a signing upstream does today.
|
|
350
|
+
7. SD-JWT redaction, then ZK proofs of policy compliance. Not before.
|
|
341
351
|
|
|
342
352
|
A Python SDK follows the same shape once the TypeScript adapters have settled.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AnchorChain } from "./anchor.ts";
|
|
2
|
+
export interface EvmChainOptions {
|
|
3
|
+
/** a JSON-RPC endpoint; read from the environment by the CLI, since a provider's URL often carries its key */
|
|
4
|
+
rpcUrl: string;
|
|
5
|
+
/** the anchor key, 0x-prefixed hex; from the environment, never a flag */
|
|
6
|
+
privateKey: string;
|
|
7
|
+
/** 1, Ethereum mainnet, by default; `resolveAnchorChain` turns a name such as "base" into its id */
|
|
8
|
+
chainId?: number;
|
|
9
|
+
/** a run whose fees would exceed this many gwei per gas is skipped, not sent */
|
|
10
|
+
maxFeeGwei: number;
|
|
11
|
+
/** an EIP-1193 provider in place of `rpcUrl`, for tests */
|
|
12
|
+
provider?: {
|
|
13
|
+
request(args: {
|
|
14
|
+
method: string;
|
|
15
|
+
params?: unknown;
|
|
16
|
+
}): Promise<unknown>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare function evmChain(o: EvmChainOptions): Promise<AnchorChain>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export async function evmChain(o) {
|
|
2
|
+
let viem;
|
|
3
|
+
let accounts;
|
|
4
|
+
let known;
|
|
5
|
+
try {
|
|
6
|
+
viem = await import("viem");
|
|
7
|
+
accounts = await import("viem/accounts");
|
|
8
|
+
known = await import("viem/chains");
|
|
9
|
+
}
|
|
10
|
+
catch (cause) {
|
|
11
|
+
throw new Error("anchoring needs the optional package viem; install it beside @agent-custody/receipts", { cause });
|
|
12
|
+
}
|
|
13
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(o.privateKey))
|
|
14
|
+
throw new Error("the anchor key must be 32 bytes of 0x-prefixed hex");
|
|
15
|
+
if (!(o.maxFeeGwei > 0))
|
|
16
|
+
throw new Error("the fee cap must be a positive number of gwei");
|
|
17
|
+
const account = accounts.privateKeyToAccount(o.privateKey);
|
|
18
|
+
const chainId = o.chainId ?? 1;
|
|
19
|
+
// viem's own definition where it has one, for a chain's formatters (the OP Stack's, say); a bare one otherwise
|
|
20
|
+
const chain = Object.values(known).find((c) => typeof c === "object" && c !== null && c.id === chainId) ?? viem.defineChain({ id: chainId, name: `chain ${chainId}`, nativeCurrency: { name: "native", symbol: "NATIVE", decimals: 18 }, rpcUrls: { default: { http: [o.rpcUrl] } } });
|
|
21
|
+
const transport = o.provider ? viem.custom(o.provider) : viem.http(o.rpcUrl, { timeout: 30_000, retryCount: 2 });
|
|
22
|
+
const client = viem.createWalletClient({ account, chain, transport }).extend(viem.publicActions);
|
|
23
|
+
const remote = await client.getChainId();
|
|
24
|
+
if (remote !== chainId)
|
|
25
|
+
throw new Error(`the endpoint is chain ${remote}, expected ${chainId}`);
|
|
26
|
+
const cap = viem.parseGwei(String(o.maxFeeGwei));
|
|
27
|
+
return {
|
|
28
|
+
chainId,
|
|
29
|
+
address: account.address.toLowerCase(),
|
|
30
|
+
async send(data) {
|
|
31
|
+
const fees = await client.estimateFeesPerGas();
|
|
32
|
+
if (fees.maxFeePerGas > cap)
|
|
33
|
+
throw new Error(`fees are ${viem.formatGwei(fees.maxFeePerGas)} gwei per gas, above the cap of ${o.maxFeeGwei}`);
|
|
34
|
+
return client.sendTransaction({ to: account.address, value: 0n, data: data, maxFeePerGas: fees.maxFeePerGas, maxPriorityFeePerGas: fees.maxPriorityFeePerGas });
|
|
35
|
+
},
|
|
36
|
+
async included(txHash) {
|
|
37
|
+
try {
|
|
38
|
+
const r = await client.getTransactionReceipt({ hash: txHash });
|
|
39
|
+
const finalized = await client.getBlock({ blockTag: "finalized" });
|
|
40
|
+
return { blockNumber: Number(r.blockNumber), ok: r.status === "success", finalized: finalized.number >= r.blockNumber };
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e instanceof viem.TransactionReceiptNotFoundError)
|
|
44
|
+
return null;
|
|
45
|
+
throw e;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
package/dist/anchor.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type Envelope, type PublicKeyRef } from "./crypto.ts";
|
|
2
|
+
import { type InclusionProof } from "./log.ts";
|
|
3
|
+
/**
|
|
4
|
+
* EVM chains known by name, with the chain id and a default fee cap in gwei per gas, sized to what one anchor costs
|
|
5
|
+
* there. Any other EVM chain is named by its chain id and needs an explicit cap.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ANCHOR_CHAINS: Record<string, {
|
|
8
|
+
chainId: number;
|
|
9
|
+
maxFeeGwei: number;
|
|
10
|
+
}>;
|
|
11
|
+
/** A chain name from `ANCHOR_CHAINS`, or a decimal chain id; `maxFeeGwei` is undefined for an id with no known default. */
|
|
12
|
+
export declare function resolveAnchorChain(chain: string): {
|
|
13
|
+
name: string | undefined;
|
|
14
|
+
chainId: number;
|
|
15
|
+
maxFeeGwei: number | undefined;
|
|
16
|
+
};
|
|
17
|
+
/** The chain the anchor writes to. `evmChain` in `anchor-evm.ts` is the one this package ships. */
|
|
18
|
+
export interface AnchorChain {
|
|
19
|
+
chainId: number;
|
|
20
|
+
/** the anchor's address, lowercase hex; every anchor is a zero-value transaction from it to itself */
|
|
21
|
+
address: string;
|
|
22
|
+
/** sends `data` as calldata and resolves to the transaction hash; throws when fees are above the cap */
|
|
23
|
+
send(data: string): Promise<string>;
|
|
24
|
+
/** null while the transaction is not in a block; `finalized` once that block is finalized */
|
|
25
|
+
included(txHash: string): Promise<{
|
|
26
|
+
blockNumber: number;
|
|
27
|
+
ok: boolean;
|
|
28
|
+
finalized: boolean;
|
|
29
|
+
} | null>;
|
|
30
|
+
}
|
|
31
|
+
export interface AnchorOptions {
|
|
32
|
+
/** the log's API base; the key document and consistency proofs come from here */
|
|
33
|
+
logUrl: string;
|
|
34
|
+
/** where the log publishes checkpoints */
|
|
35
|
+
checkpointsUrl: string;
|
|
36
|
+
/** "default" for the root paths, else tenant names */
|
|
37
|
+
tenants: string[];
|
|
38
|
+
chain: AnchorChain;
|
|
39
|
+
/** where anchor records, alarms, the anchor's document, and its state go; serve it read-only */
|
|
40
|
+
outDir: string;
|
|
41
|
+
/** how long a run waits for its transaction to be finalized before leaving it to later runs; default ten minutes */
|
|
42
|
+
waitMs?: number;
|
|
43
|
+
pollMs?: number;
|
|
44
|
+
/** how long a transaction a reorg removed may stay out of every block before it is sent again; default thirty minutes */
|
|
45
|
+
resendAfterMs?: number;
|
|
46
|
+
fetch?: typeof fetch;
|
|
47
|
+
warn?: (message: string) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface AnchorRecord {
|
|
50
|
+
tenant: string;
|
|
51
|
+
logId: string | undefined;
|
|
52
|
+
treeSize: number;
|
|
53
|
+
rootHash: string;
|
|
54
|
+
/** the log's signed checkpoint, exactly as published */
|
|
55
|
+
checkpoint: Envelope;
|
|
56
|
+
anchor: {
|
|
57
|
+
chainId: number;
|
|
58
|
+
address: string;
|
|
59
|
+
txHash: string;
|
|
60
|
+
blockNumber: number;
|
|
61
|
+
root: string;
|
|
62
|
+
proof: InclusionProof;
|
|
63
|
+
sentAt: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export type AnchorTenantOutcome = {
|
|
67
|
+
tenant: string;
|
|
68
|
+
outcome: "moved";
|
|
69
|
+
treeSize: number;
|
|
70
|
+
} | {
|
|
71
|
+
tenant: string;
|
|
72
|
+
outcome: "unchanged";
|
|
73
|
+
treeSize: number;
|
|
74
|
+
} | {
|
|
75
|
+
tenant: string;
|
|
76
|
+
outcome: "refused";
|
|
77
|
+
reason: string;
|
|
78
|
+
} | {
|
|
79
|
+
tenant: string;
|
|
80
|
+
outcome: "unavailable";
|
|
81
|
+
reason: string;
|
|
82
|
+
};
|
|
83
|
+
export type AnchorTxOutcome = {
|
|
84
|
+
outcome: "anchored";
|
|
85
|
+
txHash: string;
|
|
86
|
+
blockNumber: number;
|
|
87
|
+
tenants: string[];
|
|
88
|
+
} | {
|
|
89
|
+
outcome: "included";
|
|
90
|
+
txHash: string;
|
|
91
|
+
blockNumber: number;
|
|
92
|
+
} | {
|
|
93
|
+
outcome: "pending";
|
|
94
|
+
txHash: string;
|
|
95
|
+
sentAt: string;
|
|
96
|
+
} | {
|
|
97
|
+
outcome: "none";
|
|
98
|
+
} | {
|
|
99
|
+
outcome: "failed";
|
|
100
|
+
reason: string;
|
|
101
|
+
};
|
|
102
|
+
export interface AnchorRun {
|
|
103
|
+
tenants: AnchorTenantOutcome[];
|
|
104
|
+
tx: AnchorTxOutcome;
|
|
105
|
+
}
|
|
106
|
+
/** The calldata of the anchor transaction for a Merkle root: a fixed tag, then the 32-byte root. */
|
|
107
|
+
export declare function anchorCalldata(rootHex: string): string;
|
|
108
|
+
/** The leaf of a checkpoint in the anchor's tree: the canonical bytes of the log's signed envelope. */
|
|
109
|
+
export declare const anchorLeaf: (checkpoint: Envelope) => Buffer;
|
|
110
|
+
export declare class Anchor {
|
|
111
|
+
private readonly o;
|
|
112
|
+
private readonly f;
|
|
113
|
+
private readonly warn;
|
|
114
|
+
private timers;
|
|
115
|
+
private running;
|
|
116
|
+
constructor(opts: AnchorOptions);
|
|
117
|
+
get address(): string;
|
|
118
|
+
private load;
|
|
119
|
+
private save;
|
|
120
|
+
private get;
|
|
121
|
+
private latest;
|
|
122
|
+
private proof;
|
|
123
|
+
/** True while a transaction is sent and not yet finalized. */
|
|
124
|
+
get pending(): boolean;
|
|
125
|
+
/** One pass. Never throws; runs that overlap share one pass, so two transactions are never in flight at once. */
|
|
126
|
+
runOnce(): Promise<AnchorRun>;
|
|
127
|
+
private pass;
|
|
128
|
+
private check;
|
|
129
|
+
/**
|
|
130
|
+
* Looks the pending transaction up once. Records are written as soon as it is in a block, and written again if a
|
|
131
|
+
* reorg moves it to another one; only a finalized block makes its checkpoints the ones later checkpoints must extend.
|
|
132
|
+
*/
|
|
133
|
+
private settle;
|
|
134
|
+
private write;
|
|
135
|
+
/** An alarm is written where the records would have gone, so whoever reads the anchor's host sees it. */
|
|
136
|
+
private refuse;
|
|
137
|
+
/** Runs every `everyMs`, and every `settleMs` while a transaction is pending, so a record is published soon after it lands. */
|
|
138
|
+
start(everyMs?: number, settleMs?: number): void;
|
|
139
|
+
stop(): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
export interface AnchorCheckOptions {
|
|
142
|
+
/** JSON-RPC endpoints of the chain; with more than one, they must all agree */
|
|
143
|
+
rpcUrls: string[];
|
|
144
|
+
/** the anchor's address, pinned from a source other than the anchor's host */
|
|
145
|
+
address: string;
|
|
146
|
+
chainId: number;
|
|
147
|
+
/** the log's published keys */
|
|
148
|
+
logKeys: PublicKeyRef[];
|
|
149
|
+
fetch?: typeof fetch;
|
|
150
|
+
}
|
|
151
|
+
export type AnchorCheck =
|
|
152
|
+
/** `newer`: transactions the address has sent since this one; 0 means this record is from its newest */
|
|
153
|
+
{
|
|
154
|
+
ok: true;
|
|
155
|
+
blockNumber: number;
|
|
156
|
+
blockTime: string;
|
|
157
|
+
finalized: boolean;
|
|
158
|
+
newer: number;
|
|
159
|
+
} | {
|
|
160
|
+
ok: false;
|
|
161
|
+
error: string;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Checks an anchor record against the chain: the checkpoint is the log's, it is a leaf under the anchored root, and a
|
|
165
|
+
* successful transaction from the pinned address to itself carries exactly that root. Needs no Ethereum library.
|
|
166
|
+
*/
|
|
167
|
+
export declare function checkAnchorRecord(record: AnchorRecord, o: AnchorCheckOptions): Promise<AnchorCheck>;
|