newton-cli 0.1.33

newton protocol cli
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# Newton CLI

The Newton CLI (`newton-cli`) is the command-line interface for the Newton Policy Protocol AVS. It provides tools for the full policy lifecycle: uploading policy files to IPFS, deploying policy data and policy contracts, managing policy client registration, configuring runtime parameters, submitting evaluation requests, checking version compatibility, and running local Rego simulations.

## Installation

Build from source:

```bash
cargo build --bin newton-cli --release
```

The binary is placed at `target/release/newton-cli`.

## Global Flags

Every command accepts these top-level flags:

| Flag                   | Env Var    | Description                                                    |
|------------------------|------------|----------------------------------------------------------------|
| `--chain-id <ID>`      | `CHAIN_ID` | Target chain ID (e.g., `11155111` for Sepolia)                 |
| `--config-path <PATH>` | -          | Path to CLI config file (default: `~/.newton/newton-cli.toml`) |
| `--log-format <FMT>`   | -          | Log format: `full`, `compact`, `pretty`, `json`, or `minimal`  |
| `--quiet`              | -          | Suppress all log output                                        |

## Configuration

### Config File

The CLI loads configuration from `~/.newton/newton-cli.toml` (or the path given by `--config-path`). The config file provides:

- `eth_rpc_url` - Default Ethereum RPC endpoint
- `gateway_url` - Newton Gateway URL for task submission
- `signer` - ECDSA signing key configuration

Some commands (`policy-files`, `policy-client`, `regorus`) work without a config file. Commands that interact with the protocol (`task`, `policy`, `policy-data`) require one.

### Environment Variables

Most commands support configuration via environment variables. Create a `.env` file in your working directory:

```bash
CHAIN_ID=11155111
PRIVATE_KEY="0x..."
RPC_URL="https://eth-sepolia.g.alchemy.com/v2/your-api-key"
PINATA_JWT="your-pinata-jwt"
PINATA_GATEWAY="your-gateway.mypinata.cloud"
DEPLOYMENT_ENV="stagef"   # "stagef" or "prod" (default: "prod")
```

CLI arguments always take precedence over environment variables.

---

## Commands

### policy-files

Manages policy file uploads to IPFS via Pinata. This is typically the first step in setting up a new policy.

#### generate-cids

Uploads all policy files to Pinata IPFS and writes a `policy_cids.json` manifest containing the resulting CIDs.

**Files uploaded** (from `--directory`):

- `policy.wasm` - Compiled WASM data provider
- `policy.rego` - Rego policy rules
- `params_schema.json` - Policy parameter schema
- `policy_metadata.json` - Policy metadata
- `policy_data_metadata.json` - Policy data metadata

```bash
newton-cli --chain-id 11155111 policy-files generate-cids \
    --directory policy-files \
    --output policy-files/policy_cids.json \
    --pinata-jwt "$PINATA_JWT" \
    --pinata-gateway "$PINATA_GATEWAY" \
    --entrypoint "max_gas_price.allow"
```

| Argument           | Required | Default                         | Description                                        |
|--------------------|----------|---------------------------------|----------------------------------------------------|
| `--directory`      | No       | `policy-files`                  | Directory containing policy files                  |
| `--entrypoint`     | Yes      | -                               | Rego entrypoint rule (e.g., `max_gas_price.allow`) |
| `--pinata-jwt`     | Yes      | env `PINATA_JWT`                | Pinata API JWT token                               |
| `--pinata-gateway` | Yes      | env `PINATA_GATEWAY`            | Pinata gateway domain                              |
| `--output`         | No       | `policy-files/policy_cids.json` | Output path for CID manifest                       |

The output `policy_cids.json` is used as input to `policy-data deploy` and `policy deploy`.

---

### policy-data

Manages policy data contracts that store WASM CIDs, attestation configuration, and expiration settings on-chain.

#### deploy

Deploys a new policy data contract. Reads CIDs from `policy_cids.json`, deploys the contract, and sets attestation info (ECDSA type with configured attesters including all known task generator addresses).

The `expire_after` value is automatically converted from 300 seconds to blocks based on the target chain's block time.

```bash
newton-cli --chain-id 11155111 policy-data deploy \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL" \
    --policy-cids policy-files/policy_cids.json
```

| Argument        | Required | Default                         | Description          |
|-----------------|----------|---------------------------------|----------------------|
| `--private-key` | Yes      | env `PRIVATE_KEY`               | Deployer private key |
| `--rpc-url`     | Yes      | env `RPC_URL`                   | RPC endpoint URL     |
| `--policy-cids` | No       | `policy-files/policy_cids.json` | Path to CID manifest |

#### simulate

Executes the WASM data provider locally without deploying to the blockchain. Useful for testing WASM logic before deployment.

```bash
newton-cli --chain-id 11155111 policy-data simulate \
    --wasm-file policy-files/policy.wasm \
    --input-json '{}'
```

| Argument       | Required | Description                          |
|----------------|----------|--------------------------------------|
| `--wasm-file`  | Yes      | Path to WASM component file          |
| `--input-json` | Yes      | Input JSON string for WASM execution |

---

### policy

Manages policy contracts that define authorization rules via Rego policies.

#### deploy

Deploys a new policy contract referencing a previously deployed policy data contract. Reads policy CIDs from the manifest and links to the specified policy data address.

```bash
newton-cli --chain-id 11155111 policy deploy \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL" \
    --policy-cids policy-files/policy_cids.json \
    --policy-data-address "0xdB9578b6c719122ECd30667D84D1fb483c789BC8"
```

| Argument                | Required | Default           | Description                           |
|-------------------------|----------|-------------------|---------------------------------------|
| `--private-key`         | Yes      | env `PRIVATE_KEY` | Deployer private key                  |
| `--rpc-url`             | Yes      | env `RPC_URL`     | RPC endpoint URL                      |
| `--policy-cids`         | Yes      | -                 | Path to CID manifest                  |
| `--policy-data-address` | Yes      | -                 | Deployed policy data contract address |

#### simulate

Runs a full local policy evaluation: executes the WASM data provider, then evaluates the Rego policy against a provided intent. No blockchain interaction required.

```bash
newton-cli --chain-id 11155111 policy simulate \
    --wasm-file policy-files/policy.wasm \
    --rego-file policy-files/policy.rego \
    --intent-json policy-files/intent.json \
    --entrypoint "max_gas_price.allow" \
    --wasm-args policy-files/wasm_args.json \
    --policy-params-data policy-files/policy_params_data.json
```

| Argument               | Required | Default | Description                               |
|------------------------|----------|---------|-------------------------------------------|
| `--wasm-file`          | Yes      | -       | Path to WASM component file               |
| `--rego-file`          | Yes      | -       | Path to Rego policy file                  |
| `--intent-json`        | Yes      | -       | Path to intent JSON file                  |
| `--entrypoint`         | No       | `allow` | Rego entrypoint rule                      |
| `--wasm-args`          | No       | `{}`    | Path to JSON arguments for WASM execution |
| `--policy-params-data` | No       | `{}`    | Path to JSON policy parameters            |

**Notes:**

- The `data.` prefix is automatically added to the entrypoint if not present.
- Intent fields `value` and `chainId` are normalized to decimal number strings (hex and numeric formats accepted).

---

### policy-client

Manages policy client contracts and their registration in the `PolicyClientRegistry`. Policy clients must be registered before they can be used with the `IdentityRegistry`.

#### register

Registers a policy client with the `PolicyClientRegistry`. The caller becomes the registered owner. The contract validates ERC-165 interface conformance at registration time.

```bash
newton-cli policy-client register \
    --registry "0x..." \
    --client "0x..." \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL"
```

#### deactivate

Deactivates a registered policy client. Only callable by the registered owner. Deactivated clients are rejected by `IdentityRegistry._linkIdentity()`.

```bash
newton-cli policy-client deactivate \
    --registry "0x..." \
    --client "0x..." \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL"
```

#### activate

Reactivates a previously deactivated policy client. Only callable by the registered owner.

```bash
newton-cli policy-client activate \
    --registry "0x..." \
    --client "0x..." \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL"
```

#### transfer-ownership

Transfers the registry ownership record of a policy client to a new address. Only callable by the current owner.

```bash
newton-cli policy-client transfer-ownership \
    --registry "0x..." \
    --client "0x..." \
    --new-owner "0x..." \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL"
```

#### status

Queries the registration status and record for a policy client. Read-only (no private key required).

```bash
newton-cli policy-client status \
    --registry "0x..." \
    --client "0x..." \
    --rpc-url "$RPC_URL"
```

Output:

```
Client: 0x...
  Owner: 0x...
  Active: true
  Registered At: 1234567890 (unix timestamp)
  isRegisteredClient: true
```

#### list

Lists all policy clients owned by an address. Read-only.

```bash
newton-cli policy-client list \
    --registry "0x..." \
    --owner "0x..." \
    --rpc-url "$RPC_URL"
```

#### set-policy

Sets the policy contract address on a policy client. This is the owner-only `setPolicyAddress()` function used to point a policy client at a new or migrated policy.

```bash
newton-cli policy-client set-policy \
    --client "0x..." \
    --policy "0x..." \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL"
```

#### set-policy-params

Sets runtime policy parameters and expiration on a policy client contract.

```bash
newton-cli policy-client set-policy-params \
    --policy-client "0x..." \
    --policy-params policy-files/policy_params_data.json \
    --expire-after 1000 \
    --private-key "$PRIVATE_KEY" \
    --rpc-url "$RPC_URL"
```

| Argument          | Required | Description                                    |
|-------------------|----------|------------------------------------------------|
| `--policy-client` | Yes      | Policy client contract address                 |
| `--policy-params` | Yes      | Path to JSON file containing policy parameters |
| `--expire-after`  | Yes      | Expiration period in blocks                    |
| `--private-key`   | Yes      | Owner private key (env: `PRIVATE_KEY`)         |
| `--rpc-url`       | Yes      | RPC endpoint URL (env: `RPC_URL`)              |

**Registry subcommand arguments:**

All registry write operations (`register`, `deactivate`, `activate`) share:

| Argument        | Required | Description                                 |
|-----------------|----------|---------------------------------------------|
| `--registry`    | Yes      | PolicyClientRegistry contract address       |
| `--client`      | Yes      | Policy client contract address              |
| `--private-key` | Yes      | Transaction signer key (env: `PRIVATE_KEY`) |
| `--rpc-url`     | Yes      | RPC endpoint URL (env: `RPC_URL`)           |

---

### task

Commands for submitting policy evaluation requests to the Newton Prover AVS.

#### submit-evaluation-request

Signs and submits a task for policy evaluation. The command normalizes the intent (converts `value`/`chainId` to hex), signs the task with the provided private key, and submits it to the gateway via JSON-RPC (`newt_createTask`).

```bash
newton-cli --chain-id 11155111 task submit-evaluation-request \
    --task-json path/to/task.json \
    --private-key "$PRIVATE_KEY"
```

| Argument        | Required | Default           | Description                        |
|-----------------|----------|-------------------|------------------------------------|
| `--task-json`   | Yes      | -                 | Path to task JSON file             |
| `--private-key` | Yes      | env `PRIVATE_KEY` | Signer private key                 |
| `--api-key`     | No       | -                 | API key for gateway authentication |

**Task JSON format:**

```json
{
  "policyClient": "0x...",
  "intent": {
    "sender": "0x...",
    "to": "0x...",
    "value": "1000000000000000000",
    "chainId": "11155111",
    "data": "0x..."
  },
  "quorumNumber": 0,
  "quorumThresholdPercentage": 67,
  "wasmArgs": {},
  "timeout": 30
}
```

Fields `quorumNumber`, `quorumThresholdPercentage`, `wasmArgs` are optional.

**Gateway URL resolution:** The gateway URL is determined by `DEPLOYMENT_ENV` (default: `prod`) and the chain ID. Valid values for `DEPLOYMENT_ENV` are `stagef` and `prod`.

---

### version

Commands for checking protocol version compatibility and migrating policy clients to newer factory versions.

#### check-compatibility

Checks whether a policy client's policy and policy data contracts were deployed by compatible factory versions. Outputs a JSON compatibility report.

```bash
newton-cli version check-compatibility \
    --policy-client "0x..." \
    --chain-id 11155111 \
    --rpc-url "$RPC_URL"
```

| Argument          | Required | Description                         |
|-------------------|----------|-------------------------------------|
| `--policy-client` | Yes      | Policy client contract address      |
| `--chain-id`      | Yes      | Target chain ID                     |
| `--rpc-url`       | No       | RPC endpoint (falls back to config) |

Exits with code 1 if migration is required.

#### migrate

Automatically migrates a policy client to the latest compatible factory version. The migration:

1. Checks current compatibility (unless `--skip-check`)
2. Reads current policy configuration from chain
3. Redeploys incompatible policy data contracts with the latest factory
4. Deploys a new policy with the latest factory, reusing compatible policy data
5. Updates the policy client to point to the new policy via `setPolicyAddress()`
6. Verifies the migration succeeded

```bash
newton-cli version migrate \
    --policy-client "0x..." \
    --private-key "$PRIVATE_KEY" \
    --chain-id 11155111 \
    --rpc-url "$RPC_URL"
```

| Argument          | Required | Default           | Description                         |
|-------------------|----------|-------------------|-------------------------------------|
| `--policy-client` | Yes      | -                 | Policy client to migrate            |
| `--private-key`   | Yes      | env `PRIVATE_KEY` | Owner private key                   |
| `--chain-id`      | Yes      | -                 | Target chain ID                     |
| `--rpc-url`       | No       | from config       | RPC endpoint URL                    |
| `--skip-check`    | No       | `false`           | Skip initial compatibility check    |
| `--dry-run`       | No       | `false`           | Preview migration without executing |

Use `--dry-run` first to preview what changes will be made.

#### info

Displays protocol version information including the current version and minimum compatible version.

```bash
newton-cli version info
```

---

### regorus

Wraps the Regorus Rego policy engine with Newton-specific crypto extensions (`newton.crypto.*` builtins). Useful for local policy development and debugging.

#### eval

Evaluates a Rego query with Newton extensions enabled.

```bash
newton-cli regorus eval \
    -b ./policies \
    -d data.json \
    -i input.json \
    "data.auth.allowed"
```

| Argument          | Required | Description                                      |
|-------------------|----------|--------------------------------------------------|
| `-b/--bundles`    | No       | Directories containing Rego files                |
| `-d/--data`       | No       | Policy or data files (`.rego`, `.json`, `.yaml`) |
| `-i/--input`      | No       | Input file (`.json` or `.yaml`)                  |
| `query`           | Yes      | Rego query expression                            |
| `-t/--trace`      | No       | Enable execution tracing                         |
| `-n/--non-strict` | No       | Non-strict mode (OPA-compatible)                 |
| `-c/--coverage`   | No       | Display coverage information                     |

#### lex

Tokenizes a Rego policy file.

```bash
newton-cli regorus lex policy.rego [-v]
```

#### parse

Parses a Rego policy file and prints the parsed structure.

```bash
newton-cli regorus parse policy.rego
```

#### ast

Parses a Rego policy and dumps the AST as JSON.

```bash
newton-cli regorus ast policy.rego
```

---

## Typical Workflow

A complete policy deployment workflow follows these steps:

```
1. Upload policy files to IPFS
   newton-cli policy-files generate-cids ...

2. Deploy policy data contract
   newton-cli policy-data deploy ...

3. Deploy policy contract (referencing policy data)
   newton-cli policy deploy ...

4. Register the policy client with the registry
   newton-cli policy-client register ...

5. Set the policy address on the policy client
   newton-cli policy-client set-policy ...

6. Configure runtime parameters
   newton-cli policy-client set-policy-params ...

7. Submit evaluation requests
   newton-cli task submit-evaluation-request ...
```

## Testing Policies Locally

Before deploying, test your policy logic locally:

```bash
# Test WASM data provider in isolation
newton-cli policy-data simulate \
    --wasm-file policy-files/policy.wasm \
    --input-json '{}'

# Test full policy evaluation (WASM + Rego)
newton-cli policy simulate \
    --wasm-file policy-files/policy.wasm \
    --rego-file policy-files/policy.rego \
    --intent-json policy-files/intent.json \
    --entrypoint "max_gas_price.allow"

# Debug Rego rules with the regorus engine
newton-cli regorus eval \
    -d policy-files/policy.rego \
    -i input.json \
    "data.max_gas_price.allow"
```

## Related Documentation

- [Policy Client Integration Guide]../../docs/POLICY_CLIENT_GUIDE.md
- [Version Management]../../docs/VERSIONING.md
- [Regorus Extensions]../../docs/REGORUS_DEVELOPMENT.md
- [Architecture Overview]../../docs/ARCHITECTURE.md
- [Commands Overview]src/commands/README.md
- [Test Suite]tests/README.md