@agentauditai/mcp-server 0.0.0-stage → 2.0.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 +79 -2
- package/dist/deployments/phase7-arbitrumOne.json +15 -0
- package/dist/deployments/phase7-base.json +15 -0
- package/dist/deployments/phase7-mantle.json +15 -0
- package/dist/deployments/phase7-optimism.json +15 -0
- package/dist/deployments/phase7-polygon.json +15 -0
- package/dist/sdk/src/batch.d.ts +175 -0
- package/dist/sdk/src/batch.js +370 -0
- package/dist/sdk/src/index.d.ts +347 -0
- package/dist/sdk/src/index.js +557 -0
- package/dist/src/mcp-server.d.ts +19 -0
- package/dist/src/mcp-server.js +575 -0
- package/dist/tools/verify/src/evidence.d.ts +23 -0
- package/dist/tools/verify/src/evidence.js +152 -0
- package/dist/tools/verify/src/verify.d.ts +58 -0
- package/dist/tools/verify/src/verify.js +312 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 agentauditAI
|
|
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,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agentauditai/mcp-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP (Model Context Protocol) server for [AgentAudit](https://github.com/agentauditAI/AgentAudit): on-chain audit logging and incident reporting for AI agents under the EU AI Act. Works with Claude, Cursor and any MCP client over stdio.
|
|
4
|
+
|
|
5
|
+
| What | Where it is live |
|
|
6
|
+
|---|---|
|
|
7
|
+
| Audit logging: `audit_action`, `get_audit_log`, `verify_proof` (AuditVault v2, Art. 12, 19) | **Base only**: AuditVault v2 `0xCeE831070aa9081422f30df5559c125aa47A75DB` |
|
|
8
|
+
| Incident reporting: `report_incident` (IncidentRegistry v2, Art. 73) | **5 networks**: mantle, base, arbitrum, optimism, polygon |
|
|
9
|
+
| Compliance reads: `get_compliance_report`, `get_risk_score`, `check_conformity` (Art. 9, 43, 44, 73) | mantle, base, arbitrum, optimism, polygon |
|
|
10
|
+
|
|
11
|
+
## Install and run
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx -y @agentauditai/mcp-server # starts the stdio server (bin: agentaudit-mcp)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Until the package is on npm, run it from the repo: `git clone https://github.com/agentauditAI/AgentAudit && cd AgentAudit && npm install && npm run mcp`.
|
|
18
|
+
|
|
19
|
+
The package is compiled JavaScript and needs Node.js 18 or newer; it does not use ts-node at runtime.
|
|
20
|
+
|
|
21
|
+
Example MCP client config:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"mcpServers": {
|
|
26
|
+
"agentaudit": {
|
|
27
|
+
"command": "npx",
|
|
28
|
+
"args": ["-y", "@agentauditai/mcp-server"],
|
|
29
|
+
"env": { "PRIVATE_KEY": "0x…", "RPC_BASE": "https://…" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Environment variables
|
|
36
|
+
|
|
37
|
+
| Variable | Used by | Notes |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `PRIVATE_KEY` | `audit_action`, `report_incident` | Signer for write tools. Not needed for read tools. Never commit it. |
|
|
40
|
+
| `RPC_MANTLE`, `RPC_BASE`, `RPC_ARBITRUM`, `RPC_OPTIMISM`, `RPC_POLYGON` | all tools | Optional RPC overrides; public RPCs are used by default |
|
|
41
|
+
| `AUDIT_VAULT_<NETWORK>` | `audit_action`, `get_audit_log`, `verify_proof` | Points a network at an AuditVault v2 deployment. Without it, every network except Base returns an error. |
|
|
42
|
+
|
|
43
|
+
The server also loads a `.env` file from the working directory (dotenv). Variables already set in the environment take precedence.
|
|
44
|
+
|
|
45
|
+
## Tools
|
|
46
|
+
|
|
47
|
+
### `audit_action` (write, Base)
|
|
48
|
+
|
|
49
|
+
Anchors one or more agent actions in **one** `commitBatch` transaction on AuditVault v2. Each call commits immediately; nothing is buffered between calls, so a restart cannot lose entries.
|
|
50
|
+
|
|
51
|
+
- Input: `agent_id`, `entries[]` (`action_type`, `payload`, optional `risk_level` default `HIGH`, optional `timestamp_ms`), optional `agent_address` (defaults to the signer), `compliance_score` (0–100), `network` (default `base`).
|
|
52
|
+
- Payloads are SHA-256 hashed (JCS for objects). Raw content never leaves the process. Each entry becomes an Evidence Schema v1 preimage with scope `agent_action:mcp:record_hash:<sha256>`.
|
|
53
|
+
- Returns `txHash`, `batchIndex`, `merkle_root`, each entry's `action_ref` + `proof`, and the full evidence bundle. **Keep the bundle**: the batch payload is not stored anywhere else (`contentURI` is `memory://<root>`).
|
|
54
|
+
- Errors (never a silent skip): the network has no AuditVault v2, the vault has no code, or the transaction emitted no `LogBatchCommitted` for the root.
|
|
55
|
+
|
|
56
|
+
### `get_audit_log` (read, Base)
|
|
57
|
+
|
|
58
|
+
Reads committed batches, either by `tx_hash` or by `agent_address` + `batch_index`. Returns the root, contentURI, event count, compliance score, submitter, timestamp and block.
|
|
59
|
+
|
|
60
|
+
### `verify_proof` (read, Base)
|
|
61
|
+
|
|
62
|
+
Checks one entry's inclusion proof with AuditVault v2 `verifyLog`. The leaf is always recomputed from the preimage, never taken from the caller (KI-2). Returns `valid`, the batch `submitter` and per-check results. Pass `expected_submitter` to pin the submitter (see the caveat below).
|
|
63
|
+
|
|
64
|
+
### `report_incident` (write, 5 networks)
|
|
65
|
+
|
|
66
|
+
Registers a serious incident on IncidentRegistry v2 (Art. 73). Before sending, it checks the registry has code. After mining, it requires an `IncidentRegistered` event from the registry address; otherwise it returns an error and never reports success. The result includes the Art. 73§2 reporting deadline (2 / 10 / 15 days by severity).
|
|
67
|
+
|
|
68
|
+
### `get_compliance_report`, `get_risk_score`, `check_conformity` (read)
|
|
69
|
+
|
|
70
|
+
Read the Phase 7 contracts: ConformityAssessment (Art. 43, 44), RiskManagementSystem (Art. 9) and IncidentRegistry (Art. 73). If a contract has no code on the selected network, the tool returns an error naming the network and address.
|
|
71
|
+
|
|
72
|
+
## Caveat: AuditVault v2 does not authenticate submitters
|
|
73
|
+
|
|
74
|
+
`commitBatch` on AuditVault v2 has no access control. **Anyone can commit a batch under any agent address.** A batch existing under an agent address therefore does not prove that agent's operator committed it, and batch counts can be inflated by third parties ([THREAT_MODEL KI-1](https://github.com/agentauditAI/AgentAudit/blob/main/docs/THREAT_MODEL.md)).
|
|
75
|
+
|
|
76
|
+
When you verify, check the batch `submitter`: `get_audit_log` and `verify_proof` both return it, and `verify_proof` takes `expected_submitter` to enforce it. Accept a batch only if the submitter is an address you have authorized for that agent. For full bundles, the `agentaudit-verify` CLI in the repo does the same with `--submitter`.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "arbitrumOne",
|
|
3
|
+
"chainId": "42161",
|
|
4
|
+
"deployedAt": "2026-05-18T19:23:02.624Z",
|
|
5
|
+
"deployer": "0x218514Db9048AB350fA61Ef891ee20947c5Bbf8F",
|
|
6
|
+
"contracts": {
|
|
7
|
+
"AIBOMRegistry": "0x6B5BebC2f9172c6E17Df5ea59C1753D360866bDB",
|
|
8
|
+
"RiskManagementSystem": "0x9683C026434Ff9C0Ee036d655686Be5BD3F52331",
|
|
9
|
+
"HumanOversightRegistry": "0x291FE7352698CDBf6816A3F61CbF14b52D6a402b",
|
|
10
|
+
"IncidentRegistry": "0x6ad45a9B32e695e95492dC3796a5aC8543B2EA6F",
|
|
11
|
+
"ConformityAssessment": "0x976b03a2417cf7926813605F427ED499fdF61e10",
|
|
12
|
+
"DataGovernanceRegistry": "0xEb284d8aB1360082272FA9C860a0640B13af036E",
|
|
13
|
+
"QualityManagementSystem": "0xfCB684CDeC451Da0bA93B8F05215Ee49a9402210"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "base",
|
|
3
|
+
"chainId": "8453",
|
|
4
|
+
"deployedAt": "2026-05-18T19:22:22.838Z",
|
|
5
|
+
"deployer": "0x218514Db9048AB350fA61Ef891ee20947c5Bbf8F",
|
|
6
|
+
"contracts": {
|
|
7
|
+
"AIBOMRegistry": "0x6B5BebC2f9172c6E17Df5ea59C1753D360866bDB",
|
|
8
|
+
"RiskManagementSystem": "0x9683C026434Ff9C0Ee036d655686Be5BD3F52331",
|
|
9
|
+
"HumanOversightRegistry": "0x291FE7352698CDBf6816A3F61CbF14b52D6a402b",
|
|
10
|
+
"IncidentRegistry": "0x6ad45a9B32e695e95492dC3796a5aC8543B2EA6F",
|
|
11
|
+
"ConformityAssessment": "0x976b03a2417cf7926813605F427ED499fdF61e10",
|
|
12
|
+
"DataGovernanceRegistry": "0xEb284d8aB1360082272FA9C860a0640B13af036E",
|
|
13
|
+
"QualityManagementSystem": "0xfCB684CDeC451Da0bA93B8F05215Ee49a9402210"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "mantle",
|
|
3
|
+
"chainId": "5000",
|
|
4
|
+
"deployedAt": "2026-05-18T19:22:09.579Z",
|
|
5
|
+
"deployer": "0x218514Db9048AB350fA61Ef891ee20947c5Bbf8F",
|
|
6
|
+
"contracts": {
|
|
7
|
+
"AIBOMRegistry": "0x6B5BebC2f9172c6E17Df5ea59C1753D360866bDB",
|
|
8
|
+
"RiskManagementSystem": "0x9683C026434Ff9C0Ee036d655686Be5BD3F52331",
|
|
9
|
+
"HumanOversightRegistry": "0x291FE7352698CDBf6816A3F61CbF14b52D6a402b",
|
|
10
|
+
"IncidentRegistry": "0x6ad45a9B32e695e95492dC3796a5aC8543B2EA6F",
|
|
11
|
+
"ConformityAssessment": "0x976b03a2417cf7926813605F427ED499fdF61e10",
|
|
12
|
+
"DataGovernanceRegistry": "0xEb284d8aB1360082272FA9C860a0640B13af036E",
|
|
13
|
+
"QualityManagementSystem": "0xfCB684CDeC451Da0bA93B8F05215Ee49a9402210"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "optimism",
|
|
3
|
+
"chainId": "10",
|
|
4
|
+
"deployedAt": "2026-05-18T19:24:39.428Z",
|
|
5
|
+
"deployer": "0x218514Db9048AB350fA61Ef891ee20947c5Bbf8F",
|
|
6
|
+
"contracts": {
|
|
7
|
+
"AIBOMRegistry": "0x9683C026434Ff9C0Ee036d655686Be5BD3F52331",
|
|
8
|
+
"RiskManagementSystem": "0x291FE7352698CDBf6816A3F61CbF14b52D6a402b",
|
|
9
|
+
"HumanOversightRegistry": "0x6ad45a9B32e695e95492dC3796a5aC8543B2EA6F",
|
|
10
|
+
"IncidentRegistry": "0x976b03a2417cf7926813605F427ED499fdF61e10",
|
|
11
|
+
"ConformityAssessment": "0xEb284d8aB1360082272FA9C860a0640B13af036E",
|
|
12
|
+
"DataGovernanceRegistry": "0xfCB684CDeC451Da0bA93B8F05215Ee49a9402210",
|
|
13
|
+
"QualityManagementSystem": "0xCeE831070aa9081422f30df5559c125aa47A75DB"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "polygon",
|
|
3
|
+
"chainId": "137",
|
|
4
|
+
"deployedAt": "2026-05-18T19:24:57.683Z",
|
|
5
|
+
"deployer": "0x218514Db9048AB350fA61Ef891ee20947c5Bbf8F",
|
|
6
|
+
"contracts": {
|
|
7
|
+
"AIBOMRegistry": "0x6B5BebC2f9172c6E17Df5ea59C1753D360866bDB",
|
|
8
|
+
"RiskManagementSystem": "0x9683C026434Ff9C0Ee036d655686Be5BD3F52331",
|
|
9
|
+
"HumanOversightRegistry": "0x291FE7352698CDBf6816A3F61CbF14b52D6a402b",
|
|
10
|
+
"IncidentRegistry": "0x6ad45a9B32e695e95492dC3796a5aC8543B2EA6F",
|
|
11
|
+
"ConformityAssessment": "0x976b03a2417cf7926813605F427ED499fdF61e10",
|
|
12
|
+
"DataGovernanceRegistry": "0xEb284d8aB1360082272FA9C860a0640B13af036E",
|
|
13
|
+
"QualityManagementSystem": "0xfCB684CDeC451Da0bA93B8F05215Ee49a9402210"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 8785 JSON Canonicalization Scheme.
|
|
3
|
+
* Strings and numbers use ECMAScript JSON.stringify serialization (as RFC 8785
|
|
4
|
+
* specifies); object keys are sorted by UTF-16 code units (Array#sort default).
|
|
5
|
+
*/
|
|
6
|
+
export declare function canonicalize(value: unknown): string;
|
|
7
|
+
/** Lowercase hex SHA-256 of the UTF-8 bytes of `value`, no prefix */
|
|
8
|
+
export declare function sha256Hex(value: string): string;
|
|
9
|
+
export declare const EVIDENCE_SCHEMA = "agentaudit-evidence-v1";
|
|
10
|
+
export interface ActionPreimage {
|
|
11
|
+
action_type: string;
|
|
12
|
+
agent_id: string;
|
|
13
|
+
scope: string;
|
|
14
|
+
timestamp_ms: number;
|
|
15
|
+
}
|
|
16
|
+
/** action_ref = SHA-256(JCS(preimage)), as 0x-prefixed bytes32 hex */
|
|
17
|
+
export declare function computeActionRef(preimage: ActionPreimage): string;
|
|
18
|
+
/** Percent-encode the characters that would break a scope segment */
|
|
19
|
+
export declare function encodeScopeSegment(segment: string): string;
|
|
20
|
+
/** §2.1 — tool_call:<tool>:result_hash:<sha256> */
|
|
21
|
+
export declare function toolCallScope(tool: string, resultHash: string): string;
|
|
22
|
+
/** §2.2 — data_read:<endpoint>:<dataset_version>:<result_hash> */
|
|
23
|
+
export declare function dataReadScope(endpoint: string, datasetVersion: string, resultHash: string): string;
|
|
24
|
+
/** §2.3 — llm_call:<model>:record_hash:<sha256(JCS(record))> */
|
|
25
|
+
export declare function llmCallScope(model: string, record: object): string;
|
|
26
|
+
/** Preimage for an LLM decision logged by the SDK wrappers */
|
|
27
|
+
export declare function llmDecisionPreimage(agentId: number | string, model: string, record: object, timestampMs?: number): ActionPreimage;
|
|
28
|
+
export declare function hashPair(a: string, b: string): string;
|
|
29
|
+
/** All tree levels, leaves first, root level last */
|
|
30
|
+
export declare function buildMerkleLevels(leaves: string[]): string[][];
|
|
31
|
+
export declare function merkleRoot(leaves: string[]): string;
|
|
32
|
+
/** Sibling path for leaf `index`; levels where the node was promoted are skipped */
|
|
33
|
+
export declare function merkleProof(levels: string[][], index: number): string[];
|
|
34
|
+
/** Off-chain mirror of AuditVault._verifyMerkle */
|
|
35
|
+
export declare function verifyMerkleProof(leaf: string, proof: string[], root: string): boolean;
|
|
36
|
+
export interface BatchEntry {
|
|
37
|
+
action_ref: string;
|
|
38
|
+
preimage: ActionPreimage;
|
|
39
|
+
/** Hashed audit record the scope commits to — never raw prompt/response content */
|
|
40
|
+
record?: object;
|
|
41
|
+
}
|
|
42
|
+
export interface BatchRecord {
|
|
43
|
+
schema: typeof EVIDENCE_SCHEMA;
|
|
44
|
+
batch_id: string;
|
|
45
|
+
agent_address: string;
|
|
46
|
+
merkle_root: string;
|
|
47
|
+
leaf_hash: "sha256(jcs(preimage))";
|
|
48
|
+
node_hash: "keccak256(sorted_pair)";
|
|
49
|
+
odd_node: "promote";
|
|
50
|
+
created_at_ms: number;
|
|
51
|
+
entries: BatchEntry[];
|
|
52
|
+
}
|
|
53
|
+
export interface BatchStore {
|
|
54
|
+
/** Persist the batch and return the contentURI to anchor on-chain */
|
|
55
|
+
put(record: BatchRecord): Promise<string>;
|
|
56
|
+
get(batchId: string): Promise<BatchRecord | null>;
|
|
57
|
+
}
|
|
58
|
+
export declare class MemoryBatchStore implements BatchStore {
|
|
59
|
+
private readonly records;
|
|
60
|
+
put(record: BatchRecord): Promise<string>;
|
|
61
|
+
get(batchId: string): Promise<BatchRecord | null>;
|
|
62
|
+
}
|
|
63
|
+
/** Writes one JSON file per batch: <dir>/<batch_id>.json */
|
|
64
|
+
export declare class FileBatchStore implements BatchStore {
|
|
65
|
+
private readonly dir;
|
|
66
|
+
constructor(dir: string);
|
|
67
|
+
private file;
|
|
68
|
+
put(record: BatchRecord): Promise<string>;
|
|
69
|
+
get(batchId: string): Promise<BatchRecord | null>;
|
|
70
|
+
}
|
|
71
|
+
export interface CommitBatchParams {
|
|
72
|
+
agentAddress: string;
|
|
73
|
+
merkleRoot: string;
|
|
74
|
+
contentURI: string;
|
|
75
|
+
eventCount: number;
|
|
76
|
+
complianceScore: number;
|
|
77
|
+
}
|
|
78
|
+
export interface CommitBatchResult {
|
|
79
|
+
txHash: string;
|
|
80
|
+
/** Per-agent batch index from LogBatchCommitted; null if not found in receipt */
|
|
81
|
+
batchIndex: number | null;
|
|
82
|
+
}
|
|
83
|
+
/** Anything that can call AuditVault v2 commitBatch — AgentAudit implements it */
|
|
84
|
+
export interface BatchCommitter {
|
|
85
|
+
commitBatch(params: CommitBatchParams): Promise<CommitBatchResult>;
|
|
86
|
+
/** Optional fail-fast check, called before a buffer is built for this committer */
|
|
87
|
+
assertBatchAnchoring?(): void;
|
|
88
|
+
}
|
|
89
|
+
export interface BatchBufferConfig {
|
|
90
|
+
committer: BatchCommitter;
|
|
91
|
+
/** Agent address the batch is committed under (AuditVault v2 keys agents by address) */
|
|
92
|
+
agentAddress: string;
|
|
93
|
+
store?: BatchStore;
|
|
94
|
+
/** Flush when this many entries are buffered (default 50) */
|
|
95
|
+
maxEntries?: number;
|
|
96
|
+
/** Flush this many seconds after the first buffered entry (default 60) */
|
|
97
|
+
maxAgeSeconds?: number;
|
|
98
|
+
/** uint8 0–100 passed to commitBatch (default 0 = not assessed by SDK) */
|
|
99
|
+
complianceScore?: number;
|
|
100
|
+
/** Receives errors from timer-triggered flushes (default console.error) */
|
|
101
|
+
onError?: (err: Error) => void;
|
|
102
|
+
}
|
|
103
|
+
export interface FlushResult {
|
|
104
|
+
batchId: string;
|
|
105
|
+
merkleRoot: string;
|
|
106
|
+
contentURI: string;
|
|
107
|
+
eventCount: number;
|
|
108
|
+
txHash: string;
|
|
109
|
+
batchIndex: number | null;
|
|
110
|
+
}
|
|
111
|
+
export interface InclusionProof {
|
|
112
|
+
leaf: string;
|
|
113
|
+
proof: string[];
|
|
114
|
+
root: string;
|
|
115
|
+
batchId: string;
|
|
116
|
+
/** Pass to AuditVault.verifyLog(agentAddress, batchIndex, leaf, proof) */
|
|
117
|
+
batchIndex: number | null;
|
|
118
|
+
agentAddress: string;
|
|
119
|
+
txHash: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Collects action_refs and anchors them as one Merkle root per batch.
|
|
123
|
+
* Flushes on maxEntries, on maxAgeSeconds after the first entry, or on flush().
|
|
124
|
+
* Flushes are serialized; a failed flush re-queues its entries for retry.
|
|
125
|
+
*/
|
|
126
|
+
export declare class BatchBuffer {
|
|
127
|
+
readonly agentAddress: string;
|
|
128
|
+
private readonly committer;
|
|
129
|
+
private readonly store;
|
|
130
|
+
private readonly maxEntries;
|
|
131
|
+
private readonly maxAgeMs;
|
|
132
|
+
private readonly complianceScore;
|
|
133
|
+
private readonly onError;
|
|
134
|
+
private pending;
|
|
135
|
+
private timer?;
|
|
136
|
+
private flushChain;
|
|
137
|
+
private readonly index;
|
|
138
|
+
private readonly batches;
|
|
139
|
+
constructor(config: BatchBufferConfig);
|
|
140
|
+
/** Number of entries waiting for the next flush */
|
|
141
|
+
get size(): number;
|
|
142
|
+
/**
|
|
143
|
+
* Buffer one action. Resolves once buffered — or, if this entry fills the
|
|
144
|
+
* batch, once that flush completes (so commit errors reach the caller).
|
|
145
|
+
*/
|
|
146
|
+
add(preimage: ActionPreimage, record?: object): Promise<{
|
|
147
|
+
actionRef: string;
|
|
148
|
+
}>;
|
|
149
|
+
/** Anchor everything buffered now. Resolves null if there was nothing to flush. */
|
|
150
|
+
flush(): Promise<FlushResult | null>;
|
|
151
|
+
/** Stop the timer and flush whatever is left */
|
|
152
|
+
close(): Promise<FlushResult | null>;
|
|
153
|
+
/** Proof for a committed action_ref; null if unknown or still pending */
|
|
154
|
+
getInclusionProof(actionRef: string): InclusionProof | null;
|
|
155
|
+
private _flush;
|
|
156
|
+
private _armTimer;
|
|
157
|
+
private _clearTimer;
|
|
158
|
+
}
|
|
159
|
+
/** "batch" (default): buffer + commitBatch. "per_action": legacy one tx per call */
|
|
160
|
+
export type AuditMode = "batch" | "per_action";
|
|
161
|
+
export interface BatchOptions {
|
|
162
|
+
/** Share one buffer across several wrappers; other options are then ignored */
|
|
163
|
+
buffer?: BatchBuffer;
|
|
164
|
+
/** Defaults to the SDK signer's address */
|
|
165
|
+
agentAddress?: string;
|
|
166
|
+
store?: BatchStore;
|
|
167
|
+
maxEntries?: number;
|
|
168
|
+
maxAgeSeconds?: number;
|
|
169
|
+
complianceScore?: number;
|
|
170
|
+
onError?: (err: Error) => void;
|
|
171
|
+
}
|
|
172
|
+
/** Build (or reuse) the buffer a wrapper logs into */
|
|
173
|
+
export declare function resolveBatchBuffer(sdk: BatchCommitter & {
|
|
174
|
+
getAddress(): string;
|
|
175
|
+
}, options?: BatchOptions): BatchBuffer;
|