@coreguard/agent-commerce 0.1.1 → 0.1.3
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 +275 -11
- package/aer1.mjs +258 -0
- package/anchor.mjs +278 -0
- package/bin/mcp.mjs +0 -0
- package/composition.mjs +150 -0
- package/consumption-store.mjs +114 -38
- package/control-plane-cli.mjs +246 -0
- package/control-plane-http.mjs +275 -0
- package/control-plane.mjs +923 -0
- package/decision.mjs +152 -0
- package/firewall.mjs +1 -1
- package/identity.mjs +205 -0
- package/index.d.ts +848 -1
- package/index.mjs +189 -3
- package/mcp.mjs +476 -21
- package/outcomes-bridge.mjs +169 -0
- package/outcomes.mjs +220 -0
- package/package.json +42 -14
- package/profile-ref.mjs +130 -0
- package/reference.mjs +350 -0
- package/risk-cli.mjs +10 -2
- package/risk.mjs +49 -2
- package/spend.mjs +291 -0
- package/trust.mjs +322 -0
package/index.mjs
CHANGED
|
@@ -37,6 +37,56 @@ import { assessRisk, AGR_VERSION } from "./risk.mjs";
|
|
|
37
37
|
|
|
38
38
|
export { assessRisk, AGR_VERSION };
|
|
39
39
|
|
|
40
|
+
// CG-OUT/1 — the outcome layer above the reject codes: five outcomes over
|
|
41
|
+
// three layers, with ABSENT and NOT_CHECKED structurally unable to travel as a
|
|
42
|
+
// block. The bridges map what the existing surfaces already print onto it, and
|
|
43
|
+
// `authorizationDecision` is the one function that turns a vocabulary into
|
|
44
|
+
// behaviour (absent and not-checked yield NONE, never PASS and never BLOCK).
|
|
45
|
+
export {
|
|
46
|
+
OUTCOME_VERSION,
|
|
47
|
+
OUTCOMES,
|
|
48
|
+
OUTCOME_CODES,
|
|
49
|
+
NON_BLOCKING_OUTCOMES,
|
|
50
|
+
BLOCKING_OUTCOMES,
|
|
51
|
+
decideOutcome,
|
|
52
|
+
assertNotRenderedAsBlock,
|
|
53
|
+
selfCheck as outcomeSelfCheck,
|
|
54
|
+
} from "./outcomes.mjs";
|
|
55
|
+
|
|
56
|
+
// CG-ID/1 — identity split: recordId (who the record is) kept apart from
|
|
57
|
+
// contentDigest (what these bytes are) so an anchorRef can ride alongside.
|
|
58
|
+
export {
|
|
59
|
+
IDENTITY_VERSION,
|
|
60
|
+
IDENTITY_SCHEMA,
|
|
61
|
+
ANCHOR_KINDS,
|
|
62
|
+
recordIdFor,
|
|
63
|
+
splitIdentity,
|
|
64
|
+
normalizeAnchor,
|
|
65
|
+
compareIdentities,
|
|
66
|
+
anchorFacts,
|
|
67
|
+
selfCheck as identitySelfCheck,
|
|
68
|
+
} from "./identity.mjs";
|
|
69
|
+
|
|
70
|
+
// CG-OUT/1 profile reference — the three fields a protocol would carry
|
|
71
|
+
// (receipt_id, profile, profile_version), with the version checked on arrival.
|
|
72
|
+
export {
|
|
73
|
+
PROFILE_ID,
|
|
74
|
+
PROFILE_VERSION,
|
|
75
|
+
PROFILE_REFERENCE_SCHEMA,
|
|
76
|
+
REFERENCE_FIELDS,
|
|
77
|
+
makeProfileReference,
|
|
78
|
+
parseProfileReference,
|
|
79
|
+
selfCheck as profileSelfCheck,
|
|
80
|
+
} from "./profile-ref.mjs";
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
BRIDGE_VERSION,
|
|
84
|
+
outcomeForVerificationReport,
|
|
85
|
+
outcomeForPsarResult,
|
|
86
|
+
authorizationDecision,
|
|
87
|
+
profileReferenceFor,
|
|
88
|
+
} from "./outcomes-bridge.mjs";
|
|
89
|
+
|
|
40
90
|
// AC-CS/1 — durable single-use consumption store adapter (file-backed,
|
|
41
91
|
// Set-compatible; cross-process on host). NOT a distributed ledger, NOT an
|
|
42
92
|
// on-chain marker (on-chain anchoring OWNER-GATED / NOT_BUILT).
|
|
@@ -213,7 +263,10 @@ export async function verifyConsent(consent) {
|
|
|
213
263
|
export async function verifyExecution(consent, trace, { consumedSet } = {}) {
|
|
214
264
|
requireConsent(consent);
|
|
215
265
|
const ledger = consumedSet ?? processConsumed;
|
|
216
|
-
|
|
266
|
+
// Ledger reads/writes are awaited so an asynchronous adapter (a shared or
|
|
267
|
+
// remote consumption store) is a first-class injection. A plain Set still
|
|
268
|
+
// works unchanged: awaiting a non-promise is the value itself.
|
|
269
|
+
const alreadyConsumed = (await ledger.has(consent.receiptId)) === true;
|
|
217
270
|
|
|
218
271
|
const verification = await verifyReceipt(consent.receipt, null, consent.intent, consent.policy, trace);
|
|
219
272
|
const risk = assessRisk({ intent: consent.intent, policy: consent.policy, trace, consumed: alreadyConsumed });
|
|
@@ -222,7 +275,7 @@ export async function verifyExecution(consent, trace, { consumedSet } = {}) {
|
|
|
222
275
|
const drift = nameDrift(consent.intent, trace);
|
|
223
276
|
const verified = verification.result === "VERIFIED" && !hardFail && risk.classification === "CLEAN";
|
|
224
277
|
|
|
225
|
-
if (verified && consent.intent.singleUse) ledger.add(consent.receiptId);
|
|
278
|
+
if (verified && consent.intent.singleUse) await ledger.add(consent.receiptId);
|
|
226
279
|
|
|
227
280
|
return {
|
|
228
281
|
spec: AGENT_COMMERCE_VERSION,
|
|
@@ -232,8 +285,141 @@ export async function verifyExecution(consent, trace, { consumedSet } = {}) {
|
|
|
232
285
|
risk,
|
|
233
286
|
driftNamed: drift,
|
|
234
287
|
consumed: alreadyConsumed || verified,
|
|
235
|
-
consumedLedger:
|
|
288
|
+
consumedLedger: consumedSet
|
|
289
|
+
? "caller-supplied ledger — process-local Set, AC-CS/1 file store (cross-process on this host), or an asynchronous shared store; a global register and on-chain anchoring are NOT_BUILT"
|
|
290
|
+
: "process-local — pass an AC-CS/1 store for cross-process anchoring on this host; cross-host reconciliation is CG-SPEND/1; a global register and on-chain anchoring are NOT_BUILT",
|
|
236
291
|
boundary:
|
|
237
292
|
"execution verification never decides delivery conformity (DDE/1); VERIFIED ≠ SAFE; the actor is declared, never detected",
|
|
238
293
|
};
|
|
239
294
|
}
|
|
295
|
+
|
|
296
|
+
// CG-AER1/1 — a parser for AER-1 (draft-zambo-aer1-26) receipts. The committed
|
|
297
|
+
// payload and the receipt id are kept apart, because the format keeps them
|
|
298
|
+
// apart: the digest is recomputed, the id is bound only against something
|
|
299
|
+
// external (an expected id, or a resolved record that must agree on the digest).
|
|
300
|
+
export {
|
|
301
|
+
AER1_PARSER_VERSION,
|
|
302
|
+
SUPPORTED_RECEIPT_SCHEMAS,
|
|
303
|
+
parseAer1Record,
|
|
304
|
+
aer1Outcome,
|
|
305
|
+
selfCheck as aer1SelfCheck,
|
|
306
|
+
} from "./aer1.mjs";
|
|
307
|
+
|
|
308
|
+
// CG-ANCHOR/1 — the anchor service we run ourselves: Ed25519 attestations that
|
|
309
|
+
// verify offline, an append-only hash-chained log, one Merkle root over it, and
|
|
310
|
+
// a chain adapter that prepares a 32-byte memo and refuses mainnet by name.
|
|
311
|
+
// No broadcast path exists in the module.
|
|
312
|
+
export {
|
|
313
|
+
ANCHOR_VERSION,
|
|
314
|
+
ANCHOR_SCHEMA,
|
|
315
|
+
normalizeSubject,
|
|
316
|
+
generateIssuerKey,
|
|
317
|
+
keyIdFor,
|
|
318
|
+
signAttestation,
|
|
319
|
+
verifyAttestation as verifyAnchorAttestation,
|
|
320
|
+
leafHash,
|
|
321
|
+
merkleRoot,
|
|
322
|
+
createLog,
|
|
323
|
+
appendAnchor,
|
|
324
|
+
verifyLog,
|
|
325
|
+
resolveAnchor,
|
|
326
|
+
prepareChainAnchor,
|
|
327
|
+
selfCheck as anchorSelfCheck,
|
|
328
|
+
} from "./anchor.mjs";
|
|
329
|
+
|
|
330
|
+
// CG-COMPOSE/1 — one composition rule, two defensible answers. "composed"
|
|
331
|
+
// lets an unresolvable anchor block the headline (best for a commerce consumer
|
|
332
|
+
// that needs one answer now); "layered" keeps the record verdict fixed and
|
|
333
|
+
// reports the rejection on the anchor layer (best for a record that outlives
|
|
334
|
+
// any single anchor). The difference is a mode, not an argument.
|
|
335
|
+
export {
|
|
336
|
+
COMPOSITION_VERSION,
|
|
337
|
+
COMPOSITION_MODES,
|
|
338
|
+
composeOutcome,
|
|
339
|
+
compareModes,
|
|
340
|
+
selfCheck as compositionSelfCheck,
|
|
341
|
+
} from "./composition.mjs";
|
|
342
|
+
|
|
343
|
+
// CG-REF/1 — the procedure behind a receipt_id. A name proves nothing on its
|
|
344
|
+
// own: resolution produces bytes, the bytes are hashed against an expectation,
|
|
345
|
+
// and "no expectation" is unresolvable rather than resolved.
|
|
346
|
+
export {
|
|
347
|
+
REFERENCE_VERSION,
|
|
348
|
+
REFERENCE_SCHEMA,
|
|
349
|
+
ID_FORMS,
|
|
350
|
+
digestOf,
|
|
351
|
+
classifyReceiptId,
|
|
352
|
+
deriveLocatorCandidates,
|
|
353
|
+
planResolution,
|
|
354
|
+
resolveReceipt,
|
|
355
|
+
resolutionOutcome,
|
|
356
|
+
selfCheck as referenceSelfCheck,
|
|
357
|
+
} from "./reference.mjs";
|
|
358
|
+
|
|
359
|
+
// CG-KEYS/1 — pinned trust, signed rotation chains and time-aware revocation.
|
|
360
|
+
// An unknown key is NOT_CHECKED, never forged; retroactive revocation is a
|
|
361
|
+
// distinct statement from a routine retirement.
|
|
362
|
+
export {
|
|
363
|
+
KEYS_VERSION,
|
|
364
|
+
KEYS_SCHEMA,
|
|
365
|
+
KEY_STATUSES,
|
|
366
|
+
createKeyring,
|
|
367
|
+
pinKey,
|
|
368
|
+
rotateKey,
|
|
369
|
+
revokeKey,
|
|
370
|
+
checkKey,
|
|
371
|
+
verifyWithTrust,
|
|
372
|
+
selfCheck as keysSelfCheck,
|
|
373
|
+
} from "./trust.mjs";
|
|
374
|
+
|
|
375
|
+
// CG-SPEND/1 — single use as an append-only, signed, lock-guarded log rather
|
|
376
|
+
// than a process-local boolean. Two systems that spent the same approval under
|
|
377
|
+
// different nonces produce a `conflict`, which is the only honest way to say
|
|
378
|
+
// "both of us thought we were first".
|
|
379
|
+
export {
|
|
380
|
+
SPEND_VERSION,
|
|
381
|
+
SPEND_SCHEMA,
|
|
382
|
+
SPEND_STATES,
|
|
383
|
+
spendKeyFor,
|
|
384
|
+
createSpendLog,
|
|
385
|
+
makeSpendEntry,
|
|
386
|
+
verifySpendEntry,
|
|
387
|
+
checkSpent,
|
|
388
|
+
readSpendLog,
|
|
389
|
+
claimSpend,
|
|
390
|
+
mergeLogs,
|
|
391
|
+
selfCheck as spendSelfCheck,
|
|
392
|
+
} from "./spend.mjs";
|
|
393
|
+
|
|
394
|
+
// CG-DECIDE/1 — outcome to authorisation. Four decisions, not two, so missing
|
|
395
|
+
// evidence can neither decline a sale nor masquerade as a pass.
|
|
396
|
+
export {
|
|
397
|
+
DECISION_VERSION,
|
|
398
|
+
DECISION_SCHEMA,
|
|
399
|
+
DECISIONS,
|
|
400
|
+
POLICIES,
|
|
401
|
+
decidePayment,
|
|
402
|
+
explainDecision,
|
|
403
|
+
decisionMatrix,
|
|
404
|
+
assertDecisionInvariants,
|
|
405
|
+
selfCheck as decisionSelfCheck,
|
|
406
|
+
} from "./decision.mjs";
|
|
407
|
+
|
|
408
|
+
// CGCP/1 — self-hosted Policy & Evidence Control Plane: versioned policies,
|
|
409
|
+
// approvals, spend windows, execution/verification ledgers, revocation, a
|
|
410
|
+
// hash-chained audit trail, an authenticated HTTP API and a CLI. Single host,
|
|
411
|
+
// single API key; multi-tenant RBAC/SSO, distributed HA and KMS are NOT_BUILT.
|
|
412
|
+
export {
|
|
413
|
+
CONTROL_PLANE_VERSION,
|
|
414
|
+
CONTROL_PLANE_SCHEMA,
|
|
415
|
+
CONTROL_PLANE_BOUNDARY,
|
|
416
|
+
CONTROL_PLANE_DECISION_REASONS,
|
|
417
|
+
createControlPlane,
|
|
418
|
+
verifyAuditChain,
|
|
419
|
+
} from "./control-plane.mjs";
|
|
420
|
+
|
|
421
|
+
export {
|
|
422
|
+
createControlPlaneHandler,
|
|
423
|
+
createControlPlaneServer,
|
|
424
|
+
startControlPlaneServer,
|
|
425
|
+
} from "./control-plane-http.mjs";
|