@agent-custody/receipts 0.16.10 → 0.16.12
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 +32 -12
- package/dist/approval-requests.d.ts +114 -0
- package/dist/approval-requests.js +198 -0
- package/dist/approval.d.ts +8 -0
- package/dist/approval.js +10 -3
- package/dist/check.js +14 -0
- package/dist/cli.js +184 -5
- package/dist/completeness.d.ts +11 -2
- package/dist/completeness.js +45 -9
- package/dist/config.d.ts +6 -0
- package/dist/config.js +19 -1
- package/dist/console-page.js +87 -2
- package/dist/console.js +72 -0
- package/dist/crypto.d.ts +2 -0
- package/dist/crypto.js +2 -1
- package/dist/delegation.d.ts +1 -1
- package/dist/delegation.js +19 -2
- package/dist/did-key.d.ts +2 -0
- package/dist/did-key.js +21 -1
- package/dist/door-app.js +1 -1
- package/dist/door-core.d.ts +385 -0
- package/dist/door-core.js +757 -0
- package/dist/door-error-rates.d.ts +102 -0
- package/dist/door-error-rates.js +178 -0
- package/dist/door-form.d.ts +7 -2
- package/dist/door-form.js +52 -4
- package/dist/door-measure.d.ts +153 -0
- package/dist/door-measure.js +325 -0
- package/dist/door-signals.d.ts +414 -0
- package/dist/door-signals.js +555 -0
- package/dist/door-test-set.d.ts +43 -0
- package/dist/door-test-set.js +117 -0
- package/dist/door-worker.d.ts +148 -0
- package/dist/door-worker.js +283 -0
- package/dist/door.d.ts +11 -293
- package/dist/door.js +45 -755
- package/dist/gateway-http.d.ts +1 -6
- package/dist/gateway-http.js +2 -19
- package/dist/gateway.js +24 -3
- package/dist/grant-header.d.ts +8 -0
- package/dist/grant-header.js +19 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +6 -1
- package/dist/issue.d.ts +2 -16
- package/dist/issue.js +2 -12
- package/dist/lock.d.ts +5 -0
- package/dist/lock.js +1 -1
- package/dist/log-http.d.ts +37 -0
- package/dist/log-http.js +74 -0
- package/dist/log-sink.d.ts +3 -37
- package/dist/log-sink.js +5 -71
- package/dist/log.d.ts +2 -27
- package/dist/log.js +2 -173
- package/dist/merkle.d.ts +27 -0
- package/dist/merkle.js +175 -0
- package/dist/object-issuer.d.ts +29 -0
- package/dist/object-issuer.js +172 -0
- package/dist/receipt-pending.d.ts +16 -0
- package/dist/receipt-pending.js +14 -0
- package/dist/web-bot-auth.d.ts +26 -6
- package/dist/web-bot-auth.js +116 -56
- package/docs/approvals.md +33 -0
- package/docs/completeness.md +44 -5
- package/docs/console.md +11 -4
- package/docs/door-error-rates.md +490 -0
- package/docs/door-languages.md +3 -1
- package/docs/door-middleware.md +6 -1
- package/docs/door-quickstart.md +53 -17
- package/docs/door-signals.md +117 -7
- package/docs/door-worker.md +94 -0
- package/docs/door.md +41 -12
- package/docs/github-action.md +2 -2
- package/docs/tutorials.md +6 -0
- package/docs/verification.md +1 -1
- package/package.json +4 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1645 -1549
package/dist/gateway-http.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { type IncomingMessage } from "node:http";
|
|
2
|
-
import type { Envelope } from "./crypto.ts";
|
|
3
1
|
import { type GatewayHost } from "./gateway.ts";
|
|
4
|
-
export
|
|
5
|
-
/** The header value that presents a grant: the DSSE envelope as base64url JSON. Send it as `Authorization: Bearer <value>` or as `X-Agent-Custody-Grant`. */
|
|
6
|
-
export declare function grantHeader(envelope: Envelope): string;
|
|
7
|
-
export declare function parseGrantHeader(req: Pick<IncomingMessage, "headers">): Envelope | null;
|
|
2
|
+
export { GRANT_HEADER, grantHeader, parseGrantHeader } from "./grant-header.ts";
|
|
8
3
|
export interface HttpGatewayOptions {
|
|
9
4
|
port: number;
|
|
10
5
|
host?: string;
|
package/dist/gateway-http.js
CHANGED
|
@@ -12,25 +12,8 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
12
12
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
13
13
|
import { CallToolRequestSchema, isInitializeRequest, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
14
14
|
import { GATEWAY_VERSION } from "./gateway.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export function grantHeader(envelope) {
|
|
18
|
-
return Buffer.from(JSON.stringify(envelope)).toString("base64url");
|
|
19
|
-
}
|
|
20
|
-
export function parseGrantHeader(req) {
|
|
21
|
-
const explicit = req.headers[GRANT_HEADER];
|
|
22
|
-
const auth = req.headers.authorization ?? "";
|
|
23
|
-
const raw = typeof explicit === "string" && explicit ? explicit : auth.startsWith("Bearer ") ? auth.slice(7) : "";
|
|
24
|
-
if (!raw)
|
|
25
|
-
return null;
|
|
26
|
-
try {
|
|
27
|
-
const parsed = JSON.parse(Buffer.from(raw, "base64url").toString("utf8"));
|
|
28
|
-
return parsed && typeof parsed === "object" && typeof parsed.payload === "string" && Array.isArray(parsed.signatures) ? parsed : null;
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
15
|
+
import { GRANT_HEADER, parseGrantHeader } from "./grant-header.js";
|
|
16
|
+
export { GRANT_HEADER, grantHeader, parseGrantHeader } from "./grant-header.js";
|
|
34
17
|
/** Serves a gateway host as an MCP server over Streamable HTTP, a session per grant. */
|
|
35
18
|
export async function serveHttp(host, opts) {
|
|
36
19
|
const bind = opts.host ?? "127.0.0.1";
|
package/dist/gateway.js
CHANGED
|
@@ -13,6 +13,7 @@ import { strictRefusals } from "./config.js";
|
|
|
13
13
|
import { digestOf, dsseVerifiers, dsseVerify, loadPrivateKey, loadPublicKey } from "./crypto.js";
|
|
14
14
|
import { delegationValidAt, grantChainDigests, verifyDelegation } from "./delegation.js";
|
|
15
15
|
import { APPROVAL_META_KEY, DEFAULT_APPROVAL_LIFETIME_SECONDS, consumeApproval, verifyApproval, verifyApprovalStatement } from "./approval.js";
|
|
16
|
+
import { APPROVAL_REQUEST_META_KEY, pickupApproval } from "./approval-requests.js";
|
|
16
17
|
import { createIssuer, ReceiptPending } from "./issue.js";
|
|
17
18
|
import { openLog } from "./log-sink.js";
|
|
18
19
|
import { openExporter } from "./otel.js";
|
|
@@ -452,6 +453,23 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
452
453
|
let approvedWindow;
|
|
453
454
|
const rule = approvalRule(tool);
|
|
454
455
|
const approvalBinding = { principal: delegation.principal, agent: delegation.agent, tool, args, ...(rule?.fields ? { fields: rule.fields } : {}) };
|
|
456
|
+
// Human in the loop: a protected call without an approval either takes the envelope an approver signed for
|
|
457
|
+
// this exact call, or leaves a request for one. The envelope is then checked below like one sent in `_meta`.
|
|
458
|
+
let requested;
|
|
459
|
+
// Only for a call the grant allows: nobody is asked to approve a call that would be refused regardless.
|
|
460
|
+
if (rule && cfg.approvals?.requests && approvalEnvelope === undefined && !grantProblem(timestamp) && delegation.scopes.includes(tool)) {
|
|
461
|
+
try {
|
|
462
|
+
const maxLifetimeSeconds = cfg.approvals.maxLifetimeSeconds ?? DEFAULT_APPROVAL_LIFETIME_SECONDS;
|
|
463
|
+
const pickup = pickupApproval(cfg.approvals.requests.dir, cfg.approvals.usedDir, approvalBinding, rule.minApprovers, receiptId, timestamp, (env) => verifyApproval(env, approvalKeys, approvalBinding, { at: timestamp, minApprovers: rule.minApprovers, maxLifetimeSeconds }));
|
|
464
|
+
if ("envelope" in pickup)
|
|
465
|
+
approvalEnvelope = pickup.envelope;
|
|
466
|
+
else
|
|
467
|
+
requested = pickup;
|
|
468
|
+
}
|
|
469
|
+
catch (e) {
|
|
470
|
+
console.error(`agent-custody gateway: approval request not recorded: ${e instanceof Error ? e.message : String(e)}`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
455
473
|
// Only an authenticated statement is embedded in the approval record. Untrusted or malformed metadata is never
|
|
456
474
|
// copied there: it could carry arbitrary text from withheld arguments. Under a private rule the issuer then
|
|
457
475
|
// withholds the embedded envelope as a commitment (see CLEAR_IN.approval in capture.ts), because even an
|
|
@@ -469,7 +487,10 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
469
487
|
return checked;
|
|
470
488
|
};
|
|
471
489
|
const initialApproval = checkApproval(timestamp);
|
|
472
|
-
const approvalProblem = initialApproval
|
|
490
|
+
const approvalProblem = !initialApproval || initialApproval.ok ? undefined
|
|
491
|
+
: requested?.status === "denied" ? `an approver denied request ${requested.requestId}`
|
|
492
|
+
: requested ? `approval required: request ${requested.requestId} is waiting for an approver${requested.previous ? ` (the last approval for this call ${requested.previous})` : ""}; send the same call again once it is approved`
|
|
493
|
+
: initialApproval.error;
|
|
473
494
|
let operation;
|
|
474
495
|
let createdOperation = false;
|
|
475
496
|
let attemptedOperation = false;
|
|
@@ -484,7 +505,7 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
484
505
|
policy = { decision: "deny", reasons: [], errors: [`tool "${tool}" is not in the delegation scopes`], policyDigest: pDigest };
|
|
485
506
|
}
|
|
486
507
|
else if (approvalProblem) {
|
|
487
|
-
policy = { decision: "deny", reasons: [], errors: [`approval rejected: ${approvalProblem}`], policyDigest: pDigest };
|
|
508
|
+
policy = { decision: "deny", reasons: [], errors: [requested ? approvalProblem : `approval rejected: ${approvalProblem}`], policyDigest: pDigest };
|
|
488
509
|
}
|
|
489
510
|
else {
|
|
490
511
|
try {
|
|
@@ -689,7 +710,7 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
689
710
|
}
|
|
690
711
|
if (operation && createdOperation && attemptedOperation)
|
|
691
712
|
operations.update(operation.id, { original: issued });
|
|
692
|
-
const meta = { [RECEIPT_META_KEY]: receiptId, ...(head.operation ? { [OPERATION_META_KEY]: head.operation } : {}), ...(logPending ? { [LOG_PENDING_META_KEY]: true } : {}) };
|
|
713
|
+
const meta = { [RECEIPT_META_KEY]: receiptId, ...(head.operation ? { [OPERATION_META_KEY]: head.operation } : {}), ...(logPending ? { [LOG_PENDING_META_KEY]: true } : {}), ...(requested ? { [APPROVAL_REQUEST_META_KEY]: { requestId: requested.requestId, status: requested.status } } : {}) };
|
|
693
714
|
const refuse = (text) => ({ isError: true, content: [{ type: "text", text: `${text} (receipt ${receiptId})` }], _meta: meta });
|
|
694
715
|
switch (execution.status) {
|
|
695
716
|
// the agent gets the real result, the real reason, and the real error: what is withheld is withheld from the receipt
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
+
import type { Envelope } from "./crypto.ts";
|
|
3
|
+
export declare const GRANT_HEADER = "x-agent-custody-grant";
|
|
4
|
+
/** The header value that presents a grant: the DSSE envelope as base64url JSON. Send it as `Authorization: Bearer <value>` or as `X-Agent-Custody-Grant`. */
|
|
5
|
+
export declare function grantHeader(envelope: Envelope): string;
|
|
6
|
+
export declare function parseGrantHeader(req: {
|
|
7
|
+
headers: IncomingHttpHeaders;
|
|
8
|
+
}): Envelope | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const GRANT_HEADER = "x-agent-custody-grant";
|
|
2
|
+
/** The header value that presents a grant: the DSSE envelope as base64url JSON. Send it as `Authorization: Bearer <value>` or as `X-Agent-Custody-Grant`. */
|
|
3
|
+
export function grantHeader(envelope) {
|
|
4
|
+
return Buffer.from(JSON.stringify(envelope)).toString("base64url");
|
|
5
|
+
}
|
|
6
|
+
export function parseGrantHeader(req) {
|
|
7
|
+
const explicit = req.headers[GRANT_HEADER];
|
|
8
|
+
const auth = req.headers.authorization ?? "";
|
|
9
|
+
const raw = typeof explicit === "string" && explicit ? explicit : auth.startsWith("Bearer ") ? auth.slice(7) : "";
|
|
10
|
+
if (!raw)
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const parsed = JSON.parse(Buffer.from(raw, "base64url").toString("utf8"));
|
|
14
|
+
return parsed && typeof parsed === "object" && typeof parsed.payload === "string" && Array.isArray(parsed.signatures) ? parsed : null;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { serveConsole, type ConsoleOptions, type RunningConsole } from "./consol
|
|
|
8
8
|
export { checkConfig, formatFindings, type CheckFinding, type CheckOptions } from "./check.ts";
|
|
9
9
|
export { GRANT_HEADER, grantHeader, parseGrantHeader, serveHttp } from "./gateway-http.ts";
|
|
10
10
|
export { AGENT_HEADER, ARRIVAL_FACT, CLASS_HEADER, DOOR_DEFAULT_CAPTURE, DOOR_VERSION, MAX_CHALLENGE_TOKEN, RECEIPT_HEADER, RATE_BURST_MS, RATE_MINUTE_MS, cedarArgs, classifyArrival, createDoorHost, createRateTracker, matchRoute, normalizePath, remoteOf, serveDoor, signedRequestOf, verifyChallengeToken } from "./door.ts";
|
|
11
|
-
export { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, WEB_BOT_AUTH_TAG, agentOrigin, createWebBotAuthVerifier, jwkThumbprint, normalizeAuthority, parseDictionary, signatureBase } from "./web-bot-auth.ts";
|
|
11
|
+
export { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, WEB_BOT_AUTH_TAG, agentOrigin, createMemoryNonceStore, createWebBotAuthVerifier, jwkThumbprint, normalizeAuthority, parseDictionary, signatureBase } from "./web-bot-auth.ts";
|
|
12
12
|
export { DESTINATION_FACT, EGRESS_VERSION, PROXY_REALM, checkProxyCredential, createEgressHost, destinationName, normalizeHost, parseAuthority, publicOnlyLookup, serveEgress } from "./egress.ts";
|
|
13
13
|
export { internalAddress } from "./addresses.ts";
|
|
14
14
|
export { DRAFT_WARNING, draftEgressPolicy } from "./egress-draft.ts";
|
|
@@ -21,8 +21,16 @@ export type { PerathosCheck, PerathosOptions, PerathosReport } from "./perathos.
|
|
|
21
21
|
export { loadAcsGuardianConfig } from "./config.ts";
|
|
22
22
|
export type { AcsGuardianConfig } from "./config.ts";
|
|
23
23
|
export { FORM_SCRIPT_PATH, formScript } from "./door-form.ts";
|
|
24
|
+
export { FLAG_SIGNALS, FORM_REPORT_HEADER, createHistoryTracker, flagOf, observationOf, signalsOf } from "./door-signals.ts";
|
|
25
|
+
export type { ArrivalBehaviour, ArrivalFingerprint, FlagSignal, FormSignals, HeaderFingerprint, HistoryTracker, NavigationSignals, Observation, Signals, SourceHistory, TimingSignals, TlsFingerprint, TlsObservation } from "./door-signals.ts";
|
|
26
|
+
export { LABELS, LABEL_QUESTIONS, LABEL_USES, createMeasure, flagValues, formatMeasure, formatRate, intervalText, isName, labelsFromReceipts, measure, parseLabelledRecord, percent, rateOf, ratePercent, thresholds } from "./door-measure.ts";
|
|
27
|
+
export type { FlagMeasure, FlagValues, Label, LabelExport, LabelQuestion, LabelUse, LabelledRecord, Measure, MeasureResult, Rate, SetMeasure, SideMeasure } from "./door-measure.ts";
|
|
28
|
+
export { challengeLabels, DOOR_QUESTIONS, DoorLabelSchema, doorErrorRates, formatErrorRates, LABEL_SOURCES, parseLabels, readDoorArrivals, wilson } from "./door-error-rates.ts";
|
|
29
|
+
export type { DoorArrivals, DoorLabel, DoorQuestion, ErrorRateRow, LabelSource } from "./door-error-rates.ts";
|
|
30
|
+
export { buildDoorTestSet, DOOR_TEST_KINDS, formatTestKinds } from "./door-test-set.ts";
|
|
31
|
+
export type { DoorTestSet, TestKind } from "./door-test-set.ts";
|
|
24
32
|
export type { Arrival, ArrivalChallenge, ArrivalClass, ArrivalRate, ChallengeCheck, Classified, DoorHost, DoorOptions, DoorRequest, DoorServerOptions, RateTracker, RateTrackerLimits, RunningDoor } from "./door.ts";
|
|
25
|
-
export type { SignatureCheck, SignedRequest, WebBotAuthOptions, WebBotAuthVerifier } from "./web-bot-auth.ts";
|
|
33
|
+
export type { NonceState, NonceStore, SignatureCheck, SignedRequest, WebBotAuthOptions, WebBotAuthVerifier } from "./web-bot-auth.ts";
|
|
26
34
|
export * from "./capture.ts";
|
|
27
35
|
export { A2A_CARD_PATH, A2A_RECEIPT_METADATA_KEY, A2A_STREAM_META_KEY, a2aUpstream, fetchAgentCard, serveA2a, textOf } from "./a2a.ts";
|
|
28
36
|
export { deliverMail, founderNote, PortalStore, portalHandler, readSession, readSessionVia, sendFollowUps, servePortal, signSession, SsoRefusedError, stripeRequest, verifyStripeSignature } from "./portal.ts";
|
|
@@ -64,6 +72,7 @@ export * from "./crypto.ts";
|
|
|
64
72
|
export * from "./delegation.ts";
|
|
65
73
|
export { base58btcDecode, base58btcEncode, DID_KEY_PREFIX, didKeyOf, publicKeyFromDidKey } from "./did-key.ts";
|
|
66
74
|
export * from "./approval.ts";
|
|
75
|
+
export * from "./approval-requests.ts";
|
|
67
76
|
export * from "./gateway.ts";
|
|
68
77
|
export * from "./issue.ts";
|
|
69
78
|
export * from "./log.ts";
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { serveConsole } from "./console.js";
|
|
|
7
7
|
export { checkConfig, formatFindings } from "./check.js";
|
|
8
8
|
export { GRANT_HEADER, grantHeader, parseGrantHeader, serveHttp } from "./gateway-http.js";
|
|
9
9
|
export { AGENT_HEADER, ARRIVAL_FACT, CLASS_HEADER, DOOR_DEFAULT_CAPTURE, DOOR_VERSION, MAX_CHALLENGE_TOKEN, RECEIPT_HEADER, RATE_BURST_MS, RATE_MINUTE_MS, cedarArgs, classifyArrival, createDoorHost, createRateTracker, matchRoute, normalizePath, remoteOf, serveDoor, signedRequestOf, verifyChallengeToken } from "./door.js";
|
|
10
|
-
export { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, WEB_BOT_AUTH_TAG, agentOrigin, createWebBotAuthVerifier, jwkThumbprint, normalizeAuthority, parseDictionary, signatureBase } from "./web-bot-auth.js";
|
|
10
|
+
export { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, WEB_BOT_AUTH_TAG, agentOrigin, createMemoryNonceStore, createWebBotAuthVerifier, jwkThumbprint, normalizeAuthority, parseDictionary, signatureBase } from "./web-bot-auth.js";
|
|
11
11
|
export { DESTINATION_FACT, EGRESS_VERSION, PROXY_REALM, checkProxyCredential, createEgressHost, destinationName, normalizeHost, parseAuthority, publicOnlyLookup, serveEgress } from "./egress.js";
|
|
12
12
|
export { internalAddress } from "./addresses.js";
|
|
13
13
|
export { DRAFT_WARNING, draftEgressPolicy } from "./egress-draft.js";
|
|
@@ -15,6 +15,10 @@ export { ACS_ERROR, ACS_GUARDIAN_VERSION, ACS_METHODS, ACS_RECEIPT_KEY, ACS_STEP
|
|
|
15
15
|
export { formatPerathosReport, PERATHOS_RECEIPT_V1, perathosHead, perathosReceiptHash, verifyPerathosLog } from "./perathos.js";
|
|
16
16
|
export { loadAcsGuardianConfig } from "./config.js";
|
|
17
17
|
export { FORM_SCRIPT_PATH, formScript } from "./door-form.js";
|
|
18
|
+
export { FLAG_SIGNALS, FORM_REPORT_HEADER, createHistoryTracker, flagOf, observationOf, signalsOf } from "./door-signals.js";
|
|
19
|
+
export { LABELS, LABEL_QUESTIONS, LABEL_USES, createMeasure, flagValues, formatMeasure, formatRate, intervalText, isName, labelsFromReceipts, measure, parseLabelledRecord, percent, rateOf, ratePercent, thresholds } from "./door-measure.js";
|
|
20
|
+
export { challengeLabels, DOOR_QUESTIONS, DoorLabelSchema, doorErrorRates, formatErrorRates, LABEL_SOURCES, parseLabels, readDoorArrivals, wilson } from "./door-error-rates.js";
|
|
21
|
+
export { buildDoorTestSet, DOOR_TEST_KINDS, formatTestKinds } from "./door-test-set.js";
|
|
18
22
|
export * from "./capture.js";
|
|
19
23
|
export { A2A_CARD_PATH, A2A_RECEIPT_METADATA_KEY, A2A_STREAM_META_KEY, a2aUpstream, fetchAgentCard, serveA2a, textOf } from "./a2a.js";
|
|
20
24
|
export { deliverMail, founderNote, PortalStore, portalHandler, readSession, readSessionVia, sendFollowUps, servePortal, signSession, SsoRefusedError, stripeRequest, verifyStripeSignature } from "./portal.js";
|
|
@@ -36,6 +40,7 @@ export * from "./crypto.js";
|
|
|
36
40
|
export * from "./delegation.js";
|
|
37
41
|
export { base58btcDecode, base58btcEncode, DID_KEY_PREFIX, didKeyOf, publicKeyFromDidKey } from "./did-key.js";
|
|
38
42
|
export * from "./approval.js";
|
|
43
|
+
export * from "./approval-requests.js";
|
|
39
44
|
export * from "./gateway.js";
|
|
40
45
|
export * from "./issue.js";
|
|
41
46
|
export * from "./log.js";
|
package/dist/issue.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { type CaptureConfig, type CaptureContext, type PrivateView } from "./cap
|
|
|
2
2
|
import { type Envelope, type KeyPair } from "./crypto.ts";
|
|
3
3
|
import { type LogSink } from "./log-sink.ts";
|
|
4
4
|
import type { ReceiptExporter } from "./otel.ts";
|
|
5
|
+
import { type FlushResult } from "./receipt-pending.ts";
|
|
5
6
|
import { type AuthorizationBundle, type AuthorizationPredicate, type ReceiptBundle, type ReceiptPredicate } from "./receipt.ts";
|
|
7
|
+
export { ReceiptPending, type FlushResult } from "./receipt-pending.ts";
|
|
6
8
|
/** Private recovery data: includes commitment salts. Persist only in an owner-only store, never in a receipt or export. */
|
|
7
9
|
export interface PreparedReceipt {
|
|
8
10
|
envelope: Envelope;
|
|
@@ -10,22 +12,6 @@ export interface PreparedReceipt {
|
|
|
10
12
|
}
|
|
11
13
|
/** The receipts whose log append failed wait here, signed, until `flushOutbox` appends them. */
|
|
12
14
|
export declare const OUTBOX_DIR = "outbox";
|
|
13
|
-
/** What one `flushOutbox` did. `foreign` entries are signed by another key and stay in the outbox. */
|
|
14
|
-
export interface FlushResult {
|
|
15
|
-
sent: number;
|
|
16
|
-
pending: number;
|
|
17
|
-
setAside: number;
|
|
18
|
-
foreign: number;
|
|
19
|
-
error?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Thrown by `issue` with `deferLog` when the log did not take the receipt. The signed receipt is kept in the outbox and
|
|
23
|
-
* no bundle is written yet: `flushOutbox` appends it later and then writes the bundle.
|
|
24
|
-
*/
|
|
25
|
-
export declare class ReceiptPending extends Error {
|
|
26
|
-
readonly receiptId: string;
|
|
27
|
-
constructor(receiptId: string, cause: unknown);
|
|
28
|
-
}
|
|
29
15
|
export interface Issuer {
|
|
30
16
|
keyid: string;
|
|
31
17
|
log: LogSink;
|
package/dist/issue.js
CHANGED
|
@@ -6,21 +6,11 @@ import { effectiveRule, getAt, privateView } from "./capture.js";
|
|
|
6
6
|
import { canonicalize, dsseSign, dsseVerify } from "./crypto.js";
|
|
7
7
|
import { fileLog } from "./log-sink.js";
|
|
8
8
|
import { takeLock } from "./lock.js";
|
|
9
|
+
import { ReceiptPending } from "./receipt-pending.js";
|
|
9
10
|
import { buildAuthorizationStatement, buildStatement, RECEIPT_TYPE } from "./receipt.js";
|
|
11
|
+
export { ReceiptPending } from "./receipt-pending.js";
|
|
10
12
|
/** The receipts whose log append failed wait here, signed, until `flushOutbox` appends them. */
|
|
11
13
|
export const OUTBOX_DIR = "outbox";
|
|
12
|
-
/**
|
|
13
|
-
* Thrown by `issue` with `deferLog` when the log did not take the receipt. The signed receipt is kept in the outbox and
|
|
14
|
-
* no bundle is written yet: `flushOutbox` appends it later and then writes the bundle.
|
|
15
|
-
*/
|
|
16
|
-
export class ReceiptPending extends Error {
|
|
17
|
-
receiptId;
|
|
18
|
-
constructor(receiptId, cause) {
|
|
19
|
-
super(`receipt ${receiptId} is kept in the outbox; its log append is pending: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
20
|
-
this.name = "ReceiptPending";
|
|
21
|
-
this.receiptId = receiptId;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
14
|
/** `log` is a sink, or a file path for the local log with tree heads signed by the issuer's key. */
|
|
25
15
|
export function createIssuer(key, receiptsDir, log, opts = {}) {
|
|
26
16
|
const sink = typeof log === "string" ? fileLog(log, key) : log;
|
package/dist/lock.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/** Moves the lock away only if it is still the file that was judged stale. One breaker at a time holds `<lock>.break`. */
|
|
2
|
+
export declare function breakLock(lockFile: string, judged: {
|
|
3
|
+
token: string | undefined;
|
|
4
|
+
ino: number;
|
|
5
|
+
}): void;
|
|
1
6
|
/**
|
|
2
7
|
* Takes the lock with an exclusive create, and returns its release. The release removes the file only when it still
|
|
3
8
|
* holds this call's token, so a holder whose lock was broken never removes the lock of the next holder. Returns
|
package/dist/lock.js
CHANGED
|
@@ -38,7 +38,7 @@ function judge(lockFile, staleMs) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
/** Moves the lock away only if it is still the file that was judged stale. One breaker at a time holds `<lock>.break`. */
|
|
41
|
-
function breakLock(lockFile, judged) {
|
|
41
|
+
export function breakLock(lockFile, judged) {
|
|
42
42
|
const breaker = `${lockFile}.break`;
|
|
43
43
|
try {
|
|
44
44
|
closeSync(openSync(breaker, "wx", 0o600));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Envelope, type PublicKeyRef } from "./crypto.ts";
|
|
2
|
+
import { type InclusionProof } from "./merkle.ts";
|
|
3
|
+
export interface LogAppend {
|
|
4
|
+
inclusion: InclusionProof;
|
|
5
|
+
/** signed TreeHead; the signature's keyid says who runs the log */
|
|
6
|
+
treeHead: Envelope;
|
|
7
|
+
}
|
|
8
|
+
export interface LogSink {
|
|
9
|
+
readonly kind: "file" | "http";
|
|
10
|
+
/** the file path or the URL, for reports */
|
|
11
|
+
readonly where: string;
|
|
12
|
+
append(leaf: string): Promise<LogAppend>;
|
|
13
|
+
}
|
|
14
|
+
export interface HttpLogOptions {
|
|
15
|
+
/** sent as a bearer token; the log decides what it is worth */
|
|
16
|
+
token?: string;
|
|
17
|
+
/** send only the leaf hash; the log then commits to the receipt without ever holding it. Use it for any log run by someone else. */
|
|
18
|
+
hashOnly?: boolean;
|
|
19
|
+
/** attempts on 429 and 5xx; default 3 */
|
|
20
|
+
retries?: number;
|
|
21
|
+
/** how long one append may take before it counts as unreachable; default 10000. A log that accepts and never answers must not hold a call forever. */
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
/** the log's public keys, pinned: the tree head in every append's answer must be signed by one of them. Without them, the key document at the log's /.well-known/agent-custody-log.json is fetched on first use and pinned for the life of the sink. */
|
|
24
|
+
keys?: PublicKeyRef[];
|
|
25
|
+
/** the id the log must write into every tree head; an answer naming another log, or none, is refused */
|
|
26
|
+
logId?: string;
|
|
27
|
+
fetch?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A log reached over HTTP: POST <url>/append with {leaf} or {leafHash}, expecting a LogAppend back. A 429 or a 5xx
|
|
31
|
+
* is retried a few times with backoff, honouring Retry-After; anything else, or the last failure, is the caller's.
|
|
32
|
+
*
|
|
33
|
+
* The answer is not taken on trust. Before it is returned, and so before a pre-committed call is forwarded, the tree
|
|
34
|
+
* head must verify against the log's pinned keys, name the expected log, match the proof's size, and the inclusion
|
|
35
|
+
* proof must place this very leaf under the signed root. A log that answers with anything else has refused the append.
|
|
36
|
+
*/
|
|
37
|
+
export declare function httpLog(url: string, opts?: HttpLogOptions): LogSink;
|
package/dist/log-http.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// A log reached over HTTP, and the sink interface every log satisfies. Kept apart from the local file log and the log
|
|
2
|
+
// server so that a producer running outside Node (a Worker) can append to a remote log without loading either.
|
|
3
|
+
import { dsseVerify } from "./crypto.js";
|
|
4
|
+
import { leafHash, verifyInclusion } from "./merkle.js";
|
|
5
|
+
import { TREEHEAD_TYPE } from "./receipt.js";
|
|
6
|
+
import { fetchLogKeys, shownUrl } from "./signer.js";
|
|
7
|
+
/**
|
|
8
|
+
* A log reached over HTTP: POST <url>/append with {leaf} or {leafHash}, expecting a LogAppend back. A 429 or a 5xx
|
|
9
|
+
* is retried a few times with backoff, honouring Retry-After; anything else, or the last failure, is the caller's.
|
|
10
|
+
*
|
|
11
|
+
* The answer is not taken on trust. Before it is returned, and so before a pre-committed call is forwarded, the tree
|
|
12
|
+
* head must verify against the log's pinned keys, name the expected log, match the proof's size, and the inclusion
|
|
13
|
+
* proof must place this very leaf under the signed root. A log that answers with anything else has refused the append.
|
|
14
|
+
*/
|
|
15
|
+
export function httpLog(url, opts = {}) {
|
|
16
|
+
const f = opts.fetch ?? fetch;
|
|
17
|
+
const shown = shownUrl(url);
|
|
18
|
+
const base = url.endsWith("/") ? url : `${url}/`;
|
|
19
|
+
const attempts = opts.retries ?? 3;
|
|
20
|
+
const timeoutMs = opts.timeoutMs ?? 10_000;
|
|
21
|
+
let pinned = opts.keys?.length ? Promise.resolve(opts.keys) : null;
|
|
22
|
+
const keys = () => (pinned ??= fetchLogKeys(base, f).then((r) => r.keys).catch((e) => { pinned = null; throw new Error(`log ${shown}: its keys could not be fetched to check the append, and none are configured: ${e instanceof Error ? e.message : String(e)}`); }));
|
|
23
|
+
const checked = async (entry, leaf) => {
|
|
24
|
+
const th = dsseVerify(entry.treeHead, await keys());
|
|
25
|
+
if (!th.ok || entry.treeHead.payloadType !== TREEHEAD_TYPE)
|
|
26
|
+
throw new Error(`log ${shown} answered with a tree head that does not verify against its keys${th.ok ? " (wrong payload type)" : `: ${th.error}`}`);
|
|
27
|
+
const head = th.payload;
|
|
28
|
+
if (opts.logId !== undefined && head.log !== opts.logId)
|
|
29
|
+
throw new Error(`log ${shown} signed a tree head for log "${head.log ?? ""}", not "${opts.logId}"`);
|
|
30
|
+
if (head.treeSize !== entry.inclusion.treeSize)
|
|
31
|
+
throw new Error(`log ${shown} answered with a tree head of size ${head.treeSize} and a proof for size ${entry.inclusion.treeSize}`);
|
|
32
|
+
if (!verifyInclusion(leafHash(leaf), entry.inclusion, head.rootHash))
|
|
33
|
+
throw new Error(`log ${shown} answered with an inclusion proof that does not place this leaf under the signed root`);
|
|
34
|
+
return entry;
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
kind: "http",
|
|
38
|
+
where: url,
|
|
39
|
+
async append(leaf) {
|
|
40
|
+
let last = "";
|
|
41
|
+
for (let i = 0; i < attempts; i++) {
|
|
42
|
+
let res;
|
|
43
|
+
try {
|
|
44
|
+
res = await f(new URL("append", base), {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "content-type": "application/json", ...(opts.token ? { authorization: `Bearer ${opts.token}` } : {}) },
|
|
47
|
+
body: JSON.stringify(opts.hashOnly ? { leafHash: leafHash(leaf).toString("hex") } : { leaf }),
|
|
48
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
last = `log ${shown} unreachable: ${e instanceof Error ? e.message : String(e)}`;
|
|
53
|
+
if (i + 1 < attempts)
|
|
54
|
+
await new Promise((r) => setTimeout(r, 200 * 2 ** i));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (res.ok) {
|
|
58
|
+
const body = (await res.json());
|
|
59
|
+
if (!body.inclusion || !body.treeHead)
|
|
60
|
+
throw new Error(`log ${shown} returned a malformed append result`);
|
|
61
|
+
return checked(body, leaf);
|
|
62
|
+
}
|
|
63
|
+
last = `log ${shown} refused the append: ${res.status} ${(await res.text()).slice(0, 200)}`;
|
|
64
|
+
if (res.status !== 429 && res.status < 500)
|
|
65
|
+
break;
|
|
66
|
+
if (i + 1 < attempts) {
|
|
67
|
+
const after = Number(res.headers.get("retry-after"));
|
|
68
|
+
await new Promise((r) => setTimeout(r, Number.isFinite(after) && after > 0 ? Math.min(after, 5) * 1000 : 200 * 2 ** i));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw new Error(last);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
package/dist/log-sink.d.ts
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
1
|
import { type IncomingMessage, type ServerResponse } from "node:http";
|
|
2
|
-
import { type
|
|
3
|
-
import { type InclusionProof } from "./log.ts";
|
|
2
|
+
import { type KeyPair } from "./crypto.ts";
|
|
4
3
|
import { type AuditEntry, type QuotaState, type LogBackend, type PostgresTenancy, type RateLimitOptions, type PolicyRecord } from "./log-store.ts";
|
|
5
4
|
import { type Signer } from "./signer.ts";
|
|
6
5
|
import type { Checkpoint, CheckpointStore } from "./checkpoints.ts";
|
|
7
6
|
import { type AdminOptions } from "./log-admin.ts";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/** signed TreeHead; the signature's keyid says who runs the log */
|
|
11
|
-
treeHead: Envelope;
|
|
12
|
-
}
|
|
13
|
-
export interface LogSink {
|
|
14
|
-
readonly kind: "file" | "http";
|
|
15
|
-
/** the file path or the URL, for reports */
|
|
16
|
-
readonly where: string;
|
|
17
|
-
append(leaf: string): Promise<LogAppend>;
|
|
18
|
-
}
|
|
7
|
+
import { type LogSink } from "./log-http.ts";
|
|
8
|
+
export { httpLog, type HttpLogOptions, type LogAppend, type LogSink } from "./log-http.ts";
|
|
19
9
|
/** A local JSONL Merkle log. Tree heads are signed with the given key, normally the issuer's own. */
|
|
20
10
|
export declare function fileLog(file: string, key: KeyPair): LogSink;
|
|
21
|
-
export interface HttpLogOptions {
|
|
22
|
-
/** sent as a bearer token; the log decides what it is worth */
|
|
23
|
-
token?: string;
|
|
24
|
-
/** send only the leaf hash; the log then commits to the receipt without ever holding it. Use it for any log run by someone else. */
|
|
25
|
-
hashOnly?: boolean;
|
|
26
|
-
/** attempts on 429 and 5xx; default 3 */
|
|
27
|
-
retries?: number;
|
|
28
|
-
/** how long one append may take before it counts as unreachable; default 10000. A log that accepts and never answers must not hold a call forever. */
|
|
29
|
-
timeoutMs?: number;
|
|
30
|
-
/** the log's public keys, pinned: the tree head in every append's answer must be signed by one of them. Without them, the key document at the log's /.well-known/agent-custody-log.json is fetched on first use and pinned for the life of the sink. */
|
|
31
|
-
keys?: PublicKeyRef[];
|
|
32
|
-
/** the id the log must write into every tree head; an answer naming another log, or none, is refused */
|
|
33
|
-
logId?: string;
|
|
34
|
-
fetch?: typeof fetch;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A log reached over HTTP: POST <url>/append with {leaf} or {leafHash}, expecting a LogAppend back. A 429 or a 5xx
|
|
38
|
-
* is retried a few times with backoff, honouring Retry-After; anything else, or the last failure, is the caller's.
|
|
39
|
-
*
|
|
40
|
-
* The answer is not taken on trust. Before it is returned, and so before a pre-committed call is forwarded, the tree
|
|
41
|
-
* head must verify against the log's pinned keys, name the expected log, match the proof's size, and the inclusion
|
|
42
|
-
* proof must place this very leaf under the signed root. A log that answers with anything else has refused the append.
|
|
43
|
-
*/
|
|
44
|
-
export declare function httpLog(url: string, opts?: HttpLogOptions): LogSink;
|
|
45
11
|
export interface LogConfig {
|
|
46
12
|
logFile?: string | undefined;
|
|
47
13
|
log?: {
|
package/dist/log-sink.js
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
// logHandler and serveLog are the other side: a reference log server over node:http, the same code a hosted log runs.
|
|
6
6
|
import { timingSafeEqual } from "node:crypto";
|
|
7
7
|
import { createServer } from "node:http";
|
|
8
|
-
import { dsseSign,
|
|
8
|
+
import { dsseSign, loadPublicKey } from "./crypto.js";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
|
-
import {
|
|
10
|
+
import { MerkleLog } from "./log.js";
|
|
11
11
|
import { fileBackend, RateLimiter } from "./log-store.js";
|
|
12
|
-
import {
|
|
12
|
+
import { localSigner } from "./signer.js";
|
|
13
13
|
import { adminRoutes } from "./log-admin.js";
|
|
14
14
|
import { TREEHEAD_TYPE } from "./receipt.js";
|
|
15
|
+
import { httpLog } from "./log-http.js";
|
|
16
|
+
export { httpLog } from "./log-http.js";
|
|
15
17
|
function signedHead(e, key, logId) {
|
|
16
18
|
const head = { treeSize: e.treeSize, rootHash: e.rootHash, timestamp: new Date().toISOString(), ...(logId ? { log: logId } : {}) };
|
|
17
19
|
return dsseSign(TREEHEAD_TYPE, head, key);
|
|
@@ -36,74 +38,6 @@ export function fileLog(file, key) {
|
|
|
36
38
|
},
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
|
-
/**
|
|
40
|
-
* A log reached over HTTP: POST <url>/append with {leaf} or {leafHash}, expecting a LogAppend back. A 429 or a 5xx
|
|
41
|
-
* is retried a few times with backoff, honouring Retry-After; anything else, or the last failure, is the caller's.
|
|
42
|
-
*
|
|
43
|
-
* The answer is not taken on trust. Before it is returned, and so before a pre-committed call is forwarded, the tree
|
|
44
|
-
* head must verify against the log's pinned keys, name the expected log, match the proof's size, and the inclusion
|
|
45
|
-
* proof must place this very leaf under the signed root. A log that answers with anything else has refused the append.
|
|
46
|
-
*/
|
|
47
|
-
export function httpLog(url, opts = {}) {
|
|
48
|
-
const f = opts.fetch ?? fetch;
|
|
49
|
-
const shown = shownUrl(url);
|
|
50
|
-
const base = url.endsWith("/") ? url : `${url}/`;
|
|
51
|
-
const attempts = opts.retries ?? 3;
|
|
52
|
-
const timeoutMs = opts.timeoutMs ?? 10_000;
|
|
53
|
-
let pinned = opts.keys?.length ? Promise.resolve(opts.keys) : null;
|
|
54
|
-
const keys = () => (pinned ??= fetchLogKeys(base, f).then((r) => r.keys).catch((e) => { pinned = null; throw new Error(`log ${shown}: its keys could not be fetched to check the append, and none are configured: ${e instanceof Error ? e.message : String(e)}`); }));
|
|
55
|
-
const checked = async (entry, leaf) => {
|
|
56
|
-
const th = dsseVerify(entry.treeHead, await keys());
|
|
57
|
-
if (!th.ok || entry.treeHead.payloadType !== TREEHEAD_TYPE)
|
|
58
|
-
throw new Error(`log ${shown} answered with a tree head that does not verify against its keys${th.ok ? " (wrong payload type)" : `: ${th.error}`}`);
|
|
59
|
-
const head = th.payload;
|
|
60
|
-
if (opts.logId !== undefined && head.log !== opts.logId)
|
|
61
|
-
throw new Error(`log ${shown} signed a tree head for log "${head.log ?? ""}", not "${opts.logId}"`);
|
|
62
|
-
if (head.treeSize !== entry.inclusion.treeSize)
|
|
63
|
-
throw new Error(`log ${shown} answered with a tree head of size ${head.treeSize} and a proof for size ${entry.inclusion.treeSize}`);
|
|
64
|
-
if (!verifyInclusion(leafHash(leaf), entry.inclusion, head.rootHash))
|
|
65
|
-
throw new Error(`log ${shown} answered with an inclusion proof that does not place this leaf under the signed root`);
|
|
66
|
-
return entry;
|
|
67
|
-
};
|
|
68
|
-
return {
|
|
69
|
-
kind: "http",
|
|
70
|
-
where: url,
|
|
71
|
-
async append(leaf) {
|
|
72
|
-
let last = "";
|
|
73
|
-
for (let i = 0; i < attempts; i++) {
|
|
74
|
-
let res;
|
|
75
|
-
try {
|
|
76
|
-
res = await f(new URL("append", base), {
|
|
77
|
-
method: "POST",
|
|
78
|
-
headers: { "content-type": "application/json", ...(opts.token ? { authorization: `Bearer ${opts.token}` } : {}) },
|
|
79
|
-
body: JSON.stringify(opts.hashOnly ? { leafHash: leafHash(leaf).toString("hex") } : { leaf }),
|
|
80
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
last = `log ${shown} unreachable: ${e instanceof Error ? e.message : String(e)}`;
|
|
85
|
-
if (i + 1 < attempts)
|
|
86
|
-
await new Promise((r) => setTimeout(r, 200 * 2 ** i));
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (res.ok) {
|
|
90
|
-
const body = (await res.json());
|
|
91
|
-
if (!body.inclusion || !body.treeHead)
|
|
92
|
-
throw new Error(`log ${shown} returned a malformed append result`);
|
|
93
|
-
return checked(body, leaf);
|
|
94
|
-
}
|
|
95
|
-
last = `log ${shown} refused the append: ${res.status} ${(await res.text()).slice(0, 200)}`;
|
|
96
|
-
if (res.status !== 429 && res.status < 500)
|
|
97
|
-
break;
|
|
98
|
-
if (i + 1 < attempts) {
|
|
99
|
-
const after = Number(res.headers.get("retry-after"));
|
|
100
|
-
await new Promise((r) => setTimeout(r, Number.isFinite(after) && after > 0 ? Math.min(after, 5) * 1000 : 200 * 2 ** i));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
throw new Error(last);
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
41
|
/** The sink a config asks for: a remote log when `log` is set, otherwise the local file. */
|
|
108
42
|
export function openLog(cfg, key) {
|
|
109
43
|
if (cfg.log) {
|
package/dist/log.d.ts
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
treeSize: number;
|
|
4
|
-
hashes: string[];
|
|
5
|
-
}
|
|
6
|
-
export declare function leafHash(data: string): Buffer;
|
|
7
|
-
/**
|
|
8
|
-
* Subtree hashes over a growing list of leaves. A subtree over an aligned, complete, power-of-two range never changes
|
|
9
|
-
* once its leaves exist, so those are cached; everything else is recomputed from at most log(n) cached parts. That
|
|
10
|
-
* makes appends, roots, and proofs O(log n) instead of O(n), which is what keeps a long session's receipts cheap.
|
|
11
|
-
*/
|
|
12
|
-
export declare class SubtreeCache {
|
|
13
|
-
private readonly perfect;
|
|
14
|
-
private readonly leaves;
|
|
15
|
-
constructor(leaves: Buffer[]);
|
|
16
|
-
mth(lo: number, hi: number): Buffer;
|
|
17
|
-
path(m: number, lo: number, hi: number): Buffer[];
|
|
18
|
-
subproof(m: number, lo: number, hi: number, b: boolean): Buffer[];
|
|
19
|
-
}
|
|
20
|
-
/** Proof that the tree of size newSize extends the tree of size oldSize. Empty when oldSize is 0 or equal to newSize. */
|
|
21
|
-
export declare function consistencyProof(leafHashes: Buffer[], oldSize: number, newSize?: number): string[];
|
|
22
|
-
/** RFC 9162 section 2.1.4.2. Pure: needs only the two sizes, the two roots, and the proof. */
|
|
23
|
-
export declare function verifyConsistency(oldSize: number, oldRoot: string, newSize: number, newRoot: string, proofHex: string[]): boolean;
|
|
24
|
-
export declare function rootOf(leafHashes: Buffer[], size?: number): string;
|
|
25
|
-
export declare function inclusionProof(leafHashes: Buffer[], leafIndex: number, treeSize?: number): InclusionProof;
|
|
26
|
-
/** RFC 9162 section 2.1.3.2 verification. Pure function: needs only the leaf hash, proof and claimed root. */
|
|
27
|
-
export declare function verifyInclusion(leaf: Buffer, proof: InclusionProof, rootHex: string): boolean;
|
|
1
|
+
import { type InclusionProof } from "./merkle.ts";
|
|
2
|
+
export * from "./merkle.ts";
|
|
28
3
|
/** Each hook of a coding agent is its own process, so appends overlap: one writer at a time holds `<file>.lock`. */
|
|
29
4
|
export declare function logLocked<T>(file: string, fn: () => T): T;
|
|
30
5
|
export declare class MerkleLog {
|