@crediolabs/policy-synth 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +84 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @crediolabs/policy-synth
2
+
3
+ Off-chain TypeScript synthesis core for the OpenZeppelin Accounts Policy Builder.
4
+
5
+ It records a Soroban transaction (from an on-chain hash or a raw envelope XDR),
6
+ synthesises the **minimal** policy that permits exactly that flow, and compiles it
7
+ through the OZ Accounts adapter into a proposed policy. On-chain verify, simulate,
8
+ and the unsigned install transaction are later phases.
9
+
10
+ The package is pure ESM, node-compatible, and has a single runtime dependency
11
+ (`@stellar/stellar-sdk`). MIT-licensed.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install @crediolabs/policy-synth
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ There are two front-ends, both co-equal:
22
+
23
+ - **Recording** — decode a real transaction, then infer the minimal policy.
24
+ - **Mandate** — a declarative spec that lowers deterministically (no inference).
25
+
26
+ ```ts
27
+ import {
28
+ recordTransaction,
29
+ synthesizeFromRecording,
30
+ synthesizeFromMandate,
31
+ placeholderOzConfig,
32
+ type MandateSpec,
33
+ } from '@crediolabs/policy-synth'
34
+
35
+ const oz = placeholderOzConfig('mainnet')
36
+
37
+ // --- Recording front-end -------------------------------------------------
38
+ const recorded = await recordTransaction({ network: 'mainnet', hash: '<tx-hash>' })
39
+ if (!recorded.ok) throw new Error(recorded.error.message)
40
+
41
+ const inferred = synthesizeFromRecording(recorded.data, { network: 'mainnet' }, oz)
42
+ if (inferred.ok) console.log(inferred.data)
43
+
44
+ // --- Mandate front-end (deterministic) -----------------------------------
45
+ const spec: MandateSpec = {
46
+ chain: 'stellar',
47
+ contract: 'CTOKEN',
48
+ method: 'transfer',
49
+ spendingLimit: { token: 'CTOKEN', limit: '5000000', windowSeconds: 2592000 },
50
+ }
51
+ const deterministic = synthesizeFromMandate(spec, oz)
52
+ if (deterministic.ok) console.log(deterministic.data)
53
+ ```
54
+
55
+ Every entry point returns a discriminated `ToolResponse<T>`:
56
+
57
+ ```ts
58
+ type ToolResponse<T> = { ok: true; data: T } | { ok: false; error: ToolError }
59
+ ```
60
+
61
+ `ToolError` carries a machine-readable `code`, a `message`, a `severity`, and a
62
+ `retryable` flag, so callers (and agents) can branch without parsing prose.
63
+
64
+ ### Recording modes and the confidence gate
65
+
66
+ - **On-chain** (`hash` set): fetched via the injected RPC fetcher (default: the
67
+ public Soroban RPC for the requested `network`). Pass your own `fetcher` to use
68
+ a custom endpoint or to test offline.
69
+ - **Simulation / XDR** (`xdr` set): the envelope XDR is decoded directly.
70
+
71
+ XDR/simulation mode has no raw on-chain events, so the recorder cannot run its
72
+ events cross-check and lowers `parseConfidence`. It therefore **fails closed** at
73
+ the default threshold; to accept a simulation-only recording, pass an explicit
74
+ `confidenceOverride` that clears the gate.
75
+
76
+ ## Status
77
+
78
+ The recorder, both synthesizer front-ends, and the OZ Accounts adapter (Path A)
79
+ are implemented and unit-test covered. Install, on-chain verify, simulate, and the
80
+ Rust interpreter (Path-B predicate enforcement) are later phases.
81
+
82
+ ## License
83
+
84
+ MIT.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crediolabs/policy-synth",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "description": "Off-chain TypeScript synthesis core for the OZ Accounts Policy Builder. Records Soroban transactions, synthesises the minimal policy that permits exactly that flow, verifies it, and returns an unsigned install transaction.",
6
6
  "type": "module",
@@ -12,7 +12,8 @@
12
12
  "bun": "./src/index.ts",
13
13
  "import": "./dist/index.js",
14
14
  "default": "./dist/index.js"
15
- }
15
+ },
16
+ "./package.json": "./package.json"
16
17
  },
17
18
  "files": [
18
19
  "dist",