@nomosprotocol/sdk 1.4.0 → 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/README.md CHANGED
@@ -14,6 +14,83 @@ Give `can()` an authority, an action, and the relevant facts. NOMOS verifies the
14
14
  npm install @nomosprotocol/sdk
15
15
  ```
16
16
 
17
+ ## Acts: your first verified, committed change in five minutes
18
+
19
+ An **Act** carries an exact change together with its proof: the sealed rules it acts under, facts
20
+ signed by the systems that know them, and the approvals of the people who must approve. The system
21
+ that makes the change verifies all of it itself, locally, and commits exactly that change or
22
+ nothing (NOMOS-SPEC-008, NOMOS-SPEC-009).
23
+
24
+ **1. Start a complete local world.** It includes a shop, a purchasing policy, a finance system that
25
+ states budgets, and a manager who approves. Every key is a labelled test key.
26
+
27
+ ```bash
28
+ npx @nomosprotocol/cli dev
29
+ ```
30
+
31
+ **2. Act as an agent.** One call discovers the shop, gathers the signed budget from finance,
32
+ submits, and returns the shop's verdict:
33
+
34
+ ```ts
35
+ import { act } from '@nomosprotocol/sdk';
36
+
37
+ const r = await act({
38
+ to: 'http://localhost:4747',
39
+ action: { type: 'purchase', subject: 'DEPT-17', params: { amount: 500, vendor: 'paperco' } },
40
+ });
41
+ console.log(r.status, r.summary); // committed Committed by shop.local.
42
+ ```
43
+
44
+ Try `amount: 2000`: the manager must approve, and the approval link prints in the sandbox window.
45
+ Try `amount: 9000` (over budget), `vendor: 'shadyco'` (blocked), or `subject: 'DEPT-99'` (finance
46
+ knows nothing). `r.missing` then names exactly the fact that is missing, and why.
47
+
48
+ **3. Be the system that makes the change.** Wrap your existing handler with `accept()`. It runs the
49
+ verifier locally and then, in one transaction, records the nonce, re-reads your own facts, hands
50
+ `commit` exactly the verified action, and stores the receipt:
51
+
52
+ ```ts
53
+ import { accept } from '@nomosprotocol/sdk';
54
+
55
+ const rp = accept({
56
+ relyingPartyId: 'orders.acme.example',
57
+ root: ACME_ROOT_PEM, // the root you pin; there is no default
58
+ actEndpoint: 'https://orders.acme.example/nomos/acts',
59
+ authorities: [{ artifactId: 'acme-purchasing', issuer: 'https://policy.acme.example',
60
+ actions: ['purchase'], currencyPolicy: 'record', inForceSealHash: POLICY_SEAL_HASH }],
61
+ localFacts: async (act) => ({ vendor_blocked: await isBlocked(act.action.params.vendor) }),
62
+ commit: async (action, { tx }) => createOrder(tx, action), // your existing code
63
+ store: myPostgresStore, // nonces and receipts; memoryStore() for development
64
+ });
65
+
66
+ app.use(rp.express()); // Express, Connect, node:http
67
+ // or: export default { fetch: rp.fetch } — Hono, Next.js, Cloudflare Workers, Deno, Bun
68
+ ```
69
+
70
+ `accept()` serves your discovery document at `/.well-known/nomos-relying-party`, generated from this
71
+ same configuration, and answers every Act with the status NOMOS-SPEC-009 assigns.
72
+
73
+ | Verdict | Status |
74
+ |---|---|
75
+ | AUTHORIZED, committed | 201 |
76
+ | ESCALATED | 202 |
77
+ | INCOMPLETE | 422 |
78
+ | DENIED | 403 |
79
+ | REPLAYED | 409, with the original receipt |
80
+ | any other refusal | 400 |
81
+
82
+ **The other roles** are one call each:
83
+ - `issuer()` publishes your sealed policies and certificates;
84
+ - `witness()` turns an existing lookup into signed statements;
85
+ - `approver()` shows a person the exact change and signs their consent.
86
+
87
+ Keys are `Signer`s, so they can live in your KMS or HSM.
88
+
89
+ **Any MCP agent** can carry Acts with no code: the `nomos-mcp` server has an `act` tool.
90
+
91
+ Verification is `@nomosprotocol/verify`, re-exported here as `verifyAct`, `verifyArtifact` and
92
+ `verifySeal`. It runs entirely offline, in Node, browsers and edge runtimes.
93
+
17
94
  ## `can()` — one function for authority
18
95
 
19
96
  `can()` is the primary query interface to NOMOS.
@@ -434,7 +511,7 @@ The long-term goal is simple:
434
511
 
435
512
  ## Requirements
436
513
 
437
- * Node.js 18+
514
+ * Node.js 20+
438
515
  * TypeScript supported
439
516
  * ESM and CommonJS builds
440
517
  * Full TypeScript declarations