opmsec 0.1.0 → 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/.env.example +23 -13
- package/README.md +256 -173
- package/docs/architecture/agents.mdx +77 -0
- package/docs/architecture/benchmarks.mdx +65 -0
- package/docs/architecture/overview.mdx +58 -0
- package/docs/architecture/scanner.mdx +53 -0
- package/docs/cli/audit.mdx +35 -0
- package/docs/cli/check.mdx +44 -0
- package/docs/cli/fix.mdx +49 -0
- package/docs/cli/info.mdx +44 -0
- package/docs/cli/install.mdx +71 -0
- package/docs/cli/push.mdx +99 -0
- package/docs/cli/register-agent.mdx +80 -0
- package/docs/cli/view.mdx +52 -0
- package/docs/concepts/multi-agent-consensus.mdx +58 -0
- package/docs/concepts/on-chain-registry.mdx +74 -0
- package/docs/concepts/security-model.mdx +76 -0
- package/docs/concepts/zk-agent-verification.mdx +82 -0
- package/docs/configuration.mdx +82 -0
- package/docs/contract/deployment.mdx +57 -0
- package/docs/contract/events.mdx +115 -0
- package/docs/contract/functions.mdx +220 -0
- package/docs/contract/overview.mdx +58 -0
- package/docs/favicon.svg +5 -0
- package/docs/introduction.mdx +43 -0
- package/docs/logo/dark.svg +5 -0
- package/docs/logo/light.svg +5 -0
- package/docs/mint.json +106 -0
- package/docs/quickstart.mdx +133 -0
- package/package.json +3 -3
- package/packages/cli/src/commands/author-view.tsx +9 -1
- package/packages/cli/src/commands/check.tsx +318 -0
- package/packages/cli/src/commands/fix.tsx +294 -0
- package/packages/cli/src/commands/install.tsx +229 -33
- package/packages/cli/src/commands/push.tsx +53 -22
- package/packages/cli/src/commands/register-agent.tsx +227 -0
- package/packages/cli/src/components/AgentScores.tsx +20 -6
- package/packages/cli/src/components/Hyperlink.tsx +30 -0
- package/packages/cli/src/components/ScanReport.tsx +3 -2
- package/packages/cli/src/index.tsx +41 -5
- package/packages/cli/src/services/avatar.ts +43 -6
- package/packages/cli/src/services/chainpatrol.ts +20 -17
- package/packages/cli/src/services/contract.ts +41 -8
- package/packages/cli/src/services/ens.ts +3 -5
- package/packages/cli/src/services/fileverse.ts +12 -13
- package/packages/cli/src/services/typosquat.ts +166 -0
- package/packages/contracts/circuits/accuracy_verifier.circom +101 -0
- package/packages/contracts/contracts/OPMRegistry.sol +63 -0
- package/packages/contracts/scripts/deploy.ts +22 -3
- package/packages/core/src/abi.ts +221 -0
- package/packages/core/src/benchmarks.ts +450 -0
- package/packages/core/src/constants.ts +20 -0
- package/packages/core/src/index.ts +2 -0
- package/packages/core/src/model-rankings.ts +115 -0
- package/packages/core/src/prompt.ts +58 -0
- package/packages/core/src/types.ts +41 -0
- package/packages/core/src/utils.ts +7 -3
- package/packages/scanner/src/agents/base-agent.ts +13 -3
- package/packages/scanner/src/index.ts +5 -2
- package/packages/scanner/src/queue/memory-queue.ts +8 -3
- package/packages/scanner/src/services/benchmark-runner.ts +114 -0
- package/packages/scanner/src/services/contract-writer.ts +2 -3
- package/packages/scanner/src/services/fileverse.ts +26 -7
- package/packages/scanner/src/services/openrouter.ts +46 -0
- package/packages/scanner/src/services/report-formatter.ts +122 -3
- package/packages/scanner/src/services/zk-verifier.ts +118 -0
- package/packages/web/.next/app-build-manifest.json +15 -0
- package/packages/web/.next/build-manifest.json +20 -0
- package/packages/web/.next/package.json +1 -0
- package/packages/web/.next/prerender-manifest.json +11 -0
- package/packages/web/.next/react-loadable-manifest.json +1 -0
- package/packages/web/.next/routes-manifest.json +1 -0
- package/packages/web/.next/server/app/page.js +272 -0
- package/packages/web/.next/server/app/page_client-reference-manifest.js +1 -0
- package/packages/web/.next/server/app-paths-manifest.json +3 -0
- package/packages/web/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/packages/web/.next/server/middleware-build-manifest.js +22 -0
- package/packages/web/.next/server/middleware-manifest.json +6 -0
- package/packages/web/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/packages/web/.next/server/next-font-manifest.js +1 -0
- package/packages/web/.next/server/next-font-manifest.json +1 -0
- package/packages/web/.next/server/pages-manifest.json +1 -0
- package/packages/web/.next/server/server-reference-manifest.js +1 -0
- package/packages/web/.next/server/server-reference-manifest.json +5 -0
- package/packages/web/.next/server/vendor-chunks/@swc.js +55 -0
- package/packages/web/.next/server/vendor-chunks/next.js +3010 -0
- package/packages/web/.next/server/webpack-runtime.js +209 -0
- package/packages/web/.next/static/chunks/app/layout.js +39 -0
- package/packages/web/.next/static/chunks/app/page.js +61 -0
- package/packages/web/.next/static/chunks/app-pages-internals.js +182 -0
- package/packages/web/.next/static/chunks/main-app.js +1882 -0
- package/packages/web/.next/static/chunks/polyfills.js +1 -0
- package/packages/web/.next/static/chunks/webpack.js +1393 -0
- package/packages/web/.next/static/css/app/layout.css +1237 -0
- package/packages/web/.next/static/development/_buildManifest.js +1 -0
- package/packages/web/.next/static/development/_ssgManifest.js +1 -0
- package/packages/web/.next/static/webpack/633457081244afec._.hot-update.json +1 -0
- package/packages/web/.next/static/webpack/6fee6306e0f98869.webpack.hot-update.json +1 -0
- package/packages/web/.next/static/webpack/73e341375c8d429e.webpack.hot-update.json +1 -0
- package/packages/web/.next/static/webpack/app/layout.6fee6306e0f98869.hot-update.js +22 -0
- package/packages/web/.next/static/webpack/app/layout.73e341375c8d429e.hot-update.js +22 -0
- package/packages/web/.next/static/webpack/app/page.6fee6306e0f98869.hot-update.js +22 -0
- package/packages/web/.next/static/webpack/app/page.73e341375c8d429e.hot-update.js +22 -0
- package/packages/web/.next/static/webpack/webpack.6fee6306e0f98869.hot-update.js +12 -0
- package/packages/web/.next/static/webpack/webpack.73e341375c8d429e.hot-update.js +12 -0
- package/packages/web/.next/trace +5 -0
- package/packages/web/.next/types/app/layout.ts +84 -0
- package/packages/web/.next/types/app/page.ts +84 -0
- package/packages/web/.next/types/cache-life.d.ts +141 -0
- package/packages/web/.next/types/package.json +1 -0
- package/packages/web/.next/types/routes.d.ts +57 -0
- package/packages/web/.next/types/validator.ts +61 -0
- package/packages/web/app/globals.css +75 -0
- package/packages/web/app/layout.tsx +26 -0
- package/packages/web/app/page.tsx +358 -0
- package/packages/web/bun.lock +300 -0
- package/packages/web/next-env.d.ts +6 -0
- package/packages/web/next.config.ts +5 -0
- package/packages/web/package.json +26 -0
- package/packages/web/postcss.config.mjs +8 -0
- package/packages/web/public/favicon.svg +5 -0
- package/packages/web/public/logo.svg +7 -0
- package/packages/web/tailwind.config.ts +48 -0
- package/packages/web/tsconfig.json +21 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Agent Architecture'
|
|
3
|
+
description: 'Agent config, base agent, prompts, and model ranking.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Agent Architecture
|
|
7
|
+
|
|
8
|
+
Security agents are LLM-powered analyzers that score packages and submit results on-chain.
|
|
9
|
+
|
|
10
|
+
## AgentConfig
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
interface AgentConfig {
|
|
14
|
+
agentId: string; // e.g. "agent1", "agent2", "agent3"
|
|
15
|
+
model: string; // e.g. "anthropic/claude-sonnet-4-20250514"
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Configs are defined in <code>packages/scanner/src/agents/agent-configs.ts</code> and can be overridden via <code>AGENT1_MODEL</code>, <code>AGENT2_MODEL</code>, <code>AGENT3_MODEL</code>.
|
|
20
|
+
|
|
21
|
+
## Base Agent Flow
|
|
22
|
+
|
|
23
|
+
<Steps>
|
|
24
|
+
<Step title="Fetch data">
|
|
25
|
+
Fetches package metadata and version history from npm (or uses local tarball for pre-publish scans).
|
|
26
|
+
</Step>
|
|
27
|
+
<Step title="Query OSV">
|
|
28
|
+
Looks up known CVEs for the package and version.
|
|
29
|
+
</Step>
|
|
30
|
+
<Step title="Call LLM">
|
|
31
|
+
Sends system prompt + user prompt to the configured model. Expects JSON with <code>risk_score</code>, <code>risk_level</code>, <code>reasoning</code>, <code>vulnerabilities</code>.
|
|
32
|
+
</Step>
|
|
33
|
+
<Step title="Submit score on-chain">
|
|
34
|
+
Calls <code>OPMRegistry.submitScore()</code> with the agent wallet.
|
|
35
|
+
</Step>
|
|
36
|
+
</Steps>
|
|
37
|
+
|
|
38
|
+
## System Prompt
|
|
39
|
+
|
|
40
|
+
The system prompt defines a **security auditor persona** and enforces a structured JSON output schema:
|
|
41
|
+
|
|
42
|
+
- Risk score (0–100)
|
|
43
|
+
- Risk level (LOW, MEDIUM, HIGH, CRITICAL)
|
|
44
|
+
- Reasoning
|
|
45
|
+
- List of vulnerabilities with severity
|
|
46
|
+
|
|
47
|
+
## User Prompt
|
|
48
|
+
|
|
49
|
+
The user prompt includes:
|
|
50
|
+
|
|
51
|
+
- Package metadata (name, version, description, author, license, dependencies, scripts)
|
|
52
|
+
- Version history (recent versions, publish dates, changes)
|
|
53
|
+
- Source code (extracted from tarball, truncated to size limits)
|
|
54
|
+
- Known CVEs from OSV
|
|
55
|
+
|
|
56
|
+
## Model Ranking
|
|
57
|
+
|
|
58
|
+
When <code>ARTIFICIAL_ANALYSIS_API_KEY</code> is set, the scanner fetches model rankings:
|
|
59
|
+
|
|
60
|
+
- **Intelligence index**: General reasoning capability
|
|
61
|
+
- **Coding index**: Code-related task performance
|
|
62
|
+
|
|
63
|
+
These indices are used to compute a **weight** for each agent. The aggregate score is intelligence-weighted across agents.
|
|
64
|
+
|
|
65
|
+
<Tip>
|
|
66
|
+
Without the Artificial Analysis API, agents are weighted equally.
|
|
67
|
+
</Tip>
|
|
68
|
+
|
|
69
|
+
## Extensibility
|
|
70
|
+
|
|
71
|
+
New agents can register **permissionlessly** via <code>opm register-agent</code>:
|
|
72
|
+
|
|
73
|
+
1. Pass 10 benchmark cases with 100% accuracy
|
|
74
|
+
2. Generate a ZK proof
|
|
75
|
+
3. Call <code>OPMRegistry.registerAgent()</code>
|
|
76
|
+
|
|
77
|
+
Once registered, the agent participates in package scans alongside existing agents.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Benchmark Suite'
|
|
3
|
+
description: '10 labeled test cases for agent verification.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Benchmark Suite
|
|
7
|
+
|
|
8
|
+
The benchmark suite validates agent accuracy before permissionless registration. Agents must achieve **100% accuracy** and produce a valid ZK proof.
|
|
9
|
+
|
|
10
|
+
## Test Case Structure
|
|
11
|
+
|
|
12
|
+
Each benchmark case includes:
|
|
13
|
+
|
|
14
|
+
| Field | Description |
|
|
15
|
+
|-------|-------------|
|
|
16
|
+
| **id** | Unique identifier (e.g. <code>bench-001-clean-utility</code>) |
|
|
17
|
+
| **category** | One of: clean, typosquat, malicious, cve, obfuscated, exfiltration, dependency_confusion |
|
|
18
|
+
| **metadata** | Package name, version, description, author, license, dependencies, scripts |
|
|
19
|
+
| **versionHistory** | Recent versions with publish dates and change summaries |
|
|
20
|
+
| **sourceFiles** | Path, size, and content of source files |
|
|
21
|
+
| **knownCVEs** | Known advisories (for cve category) |
|
|
22
|
+
| **expected** | risk_level, min_risk_score, max_risk_score, must_flag |
|
|
23
|
+
|
|
24
|
+
## Categories (10 Cases)
|
|
25
|
+
|
|
26
|
+
| Category | Count | Description |
|
|
27
|
+
|----------|-------|-------------|
|
|
28
|
+
| clean | 3 | Legitimate packages (string utils, math, validator) |
|
|
29
|
+
| typosquat | 1 | Typosquat of lodash with credential exfiltration in postinstall |
|
|
30
|
+
| malicious | 2 | Postinstall shell execution, SSH key exfiltration |
|
|
31
|
+
| cve | 1 | Known prototype pollution CVE |
|
|
32
|
+
| obfuscated | 1 | Heavily obfuscated reverse shell |
|
|
33
|
+
| exfiltration | 1 | Env var exfiltration on import |
|
|
34
|
+
| dependency_confusion | 1 | Internal scope shadowing with DNS exfiltration |
|
|
35
|
+
|
|
36
|
+
## Evaluation
|
|
37
|
+
|
|
38
|
+
For each case, the agent's output is compared to the expected values:
|
|
39
|
+
|
|
40
|
+
1. **Score range check**: <code>actualScore</code> must be within <code>[min_risk_score, max_risk_score]</code>
|
|
41
|
+
2. **Risk level ordinal**: For non-LOW cases, <code>actualLevel</code> must be within ±1 of expected ordinal (LOW=0, MEDIUM=1, HIGH=2, CRITICAL=3)
|
|
42
|
+
|
|
43
|
+
A case **PASS**es only if both checks succeed.
|
|
44
|
+
|
|
45
|
+
## ZK Proof Generation
|
|
46
|
+
|
|
47
|
+
The ZK proof proves accuracy **without revealing** test data or individual results:
|
|
48
|
+
|
|
49
|
+
1. **Commitment**: Hash of (salt, expected[0..9]) using Poseidon
|
|
50
|
+
2. **Proof**: Prove that <code>expected[i] == actual[i]</code> for all i, and that the commitment matches
|
|
51
|
+
3. **Output**: <code>proofHash</code> is stored on-chain; test data stays private
|
|
52
|
+
|
|
53
|
+
## Circom Circuit
|
|
54
|
+
|
|
55
|
+
The circuit <code>AccuracyVerifier(10)</code> in <code>packages/contracts/circuits/accuracy_verifier.circom</code>:
|
|
56
|
+
|
|
57
|
+
- **Private inputs**: expected[10], actual[10], salt
|
|
58
|
+
- **Public input**: commitmentHash (Poseidon hash of salt + expected values)
|
|
59
|
+
- **Public outputs**: passed (1 if all match), proofHash
|
|
60
|
+
|
|
61
|
+
Uses Poseidon hashing and IsEqual comparators from circomlib.
|
|
62
|
+
|
|
63
|
+
<Note>
|
|
64
|
+
The circuit is compiled and used for local verification. On-chain registration stores <code>keccak256(proof)</code> as the proof hash; full on-chain ZK verification can be added later.
|
|
65
|
+
</Note>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Architecture Overview'
|
|
3
|
+
description: 'Monorepo structure and data flow.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Architecture Overview
|
|
7
|
+
|
|
8
|
+
OPM is a monorepo with five main packages. The flow is: **CLI → Scanner → LLM providers → Contract writer → Base Sepolia**.
|
|
9
|
+
|
|
10
|
+
## Monorepo Structure
|
|
11
|
+
|
|
12
|
+
| Package | Purpose |
|
|
13
|
+
|--------|---------|
|
|
14
|
+
| **packages/core** | Types, constants, prompts, benchmarks, risk classification |
|
|
15
|
+
| **packages/scanner** | Agents, LLM calls, queue, benchmark runner, ZK verifier |
|
|
16
|
+
| **packages/cli** | Ink terminal UI, commands, npm/ENS/OSV integration |
|
|
17
|
+
| **packages/contracts** | Solidity (OPMRegistry), Hardhat, Circom circuits |
|
|
18
|
+
| **packages/web** | Next.js website |
|
|
19
|
+
|
|
20
|
+
## Data Flow
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
┌─────────────┐ ┌─────────────┐ ┌──────────────────┐
|
|
24
|
+
│ opm push │────▶│ Scanner │────▶│ LLM Providers │
|
|
25
|
+
│ opm check │ │ (agents) │ │ OpenRouter/OpenAI│
|
|
26
|
+
└─────────────┘ └──────┬──────┘ └──────────────────┘
|
|
27
|
+
│ │
|
|
28
|
+
│ ▼
|
|
29
|
+
│ ┌─────────────┐
|
|
30
|
+
│ │ Contract │
|
|
31
|
+
│ │ Writer │
|
|
32
|
+
│ └──────┬──────┘
|
|
33
|
+
│ │
|
|
34
|
+
▼ ▼
|
|
35
|
+
┌─────────────┐ ┌─────────────┐
|
|
36
|
+
│ npm / ENS │ │ Base Sepolia│
|
|
37
|
+
└─────────────┘ └─────────────┘
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## External Services
|
|
41
|
+
|
|
42
|
+
| Service | Purpose |
|
|
43
|
+
|---------|---------|
|
|
44
|
+
| **OpenRouter / OpenAI** | LLM inference for agents |
|
|
45
|
+
| **OSV** | CVE and GHSA advisory lookup |
|
|
46
|
+
| **Fileverse** | IPFS-backed report storage (dDocs protocol) |
|
|
47
|
+
| **ChainPatrol** | Blocklist fallback for unregistered packages |
|
|
48
|
+
| **Artificial Analysis** | Model intelligence/coding indices for weighted scoring |
|
|
49
|
+
| **ENS** | Author identity resolution (forward/reverse, text records) |
|
|
50
|
+
| **npm Registry** | Package metadata, tarball download |
|
|
51
|
+
|
|
52
|
+
## Key Paths
|
|
53
|
+
|
|
54
|
+
- **CLI entry**: <code>packages/cli/src/index.tsx</code>
|
|
55
|
+
- **Scanner entry**: <code>packages/scanner/src/index.ts</code>
|
|
56
|
+
- **Contract**: <code>packages/contracts/contracts/OPMRegistry.sol</code>
|
|
57
|
+
- **Benchmarks**: <code>packages/core/src/benchmarks.ts</code>
|
|
58
|
+
- **ZK circuit**: <code>packages/contracts/circuits/accuracy_verifier.circom</code>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Scanner Engine'
|
|
3
|
+
description: 'Scan queue, parallel execution, and integrations.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Scanner Engine
|
|
7
|
+
|
|
8
|
+
The scanner is the core security analysis engine. It coordinates package data fetching, LLM calls, and on-chain score submission.
|
|
9
|
+
|
|
10
|
+
## Memory Queue with Deduplication
|
|
11
|
+
|
|
12
|
+
Scans are enqueued via <code>enqueueScan(packageName, version, onStatus?, options?)</code>. The queue:
|
|
13
|
+
|
|
14
|
+
- Deduplicates concurrent scans for the same <code>name@version</code>
|
|
15
|
+
- Supports local tarball context for pre-publish scans (no npm download)
|
|
16
|
+
|
|
17
|
+
## Parallel Agent Execution
|
|
18
|
+
|
|
19
|
+
Agents run in parallel via <code>Promise.allSettled</code>:
|
|
20
|
+
|
|
21
|
+
- Each agent fetches package data, queries OSV, calls the LLM, and submits its score on-chain
|
|
22
|
+
- Failures in one agent do not block others
|
|
23
|
+
- Aggregate score is the mean of successful submissions (intelligence-weighted when Artificial Analysis API is configured)
|
|
24
|
+
|
|
25
|
+
## Source Code Extraction
|
|
26
|
+
|
|
27
|
+
<AccordionGroup>
|
|
28
|
+
<Accordion title="From npm tarball">
|
|
29
|
+
Downloads the tarball from the npm registry, extracts to a temp directory, and reads scannable files (<code>.js</code>, <code>.ts</code>, <code>.mjs</code>, <code>.cjs</code>, <code>.json</code>).
|
|
30
|
+
</Accordion>
|
|
31
|
+
<Accordion title="From local tarball">
|
|
32
|
+
When <code>opm push</code> runs, the packed tarball path is passed. The scanner extracts source from the local file instead of downloading from npm.
|
|
33
|
+
</Accordion>
|
|
34
|
+
</AccordionGroup>
|
|
35
|
+
|
|
36
|
+
## NPM Registry Integration
|
|
37
|
+
|
|
38
|
+
- **Metadata**: Package name, version, description, dependencies, scripts
|
|
39
|
+
- **Version history**: Recent versions with publish dates and change summaries
|
|
40
|
+
- **Tarball URL**: Fetched from <code>versions[version].dist.tarball</code>
|
|
41
|
+
|
|
42
|
+
## Fileverse Upload
|
|
43
|
+
|
|
44
|
+
Audit reports are formatted as Markdown and uploaded via the Fileverse API. The returned URI is set on-chain via <code>setReportURI</code>. Requires <code>FILEVERSE_API_KEY</code>.
|
|
45
|
+
|
|
46
|
+
## Contract Writer
|
|
47
|
+
|
|
48
|
+
The scanner's contract writer:
|
|
49
|
+
|
|
50
|
+
- **submitScoreOnChain**: Calls <code>OPMRegistry.submitScore()</code> with agent wallet
|
|
51
|
+
- **setReportURIOnChain**: Calls <code>OPMRegistry.setReportURI()</code>
|
|
52
|
+
|
|
53
|
+
Both require the agent to be authorized (owner-set or ZK-verified).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm audit'
|
|
3
|
+
description: 'On-chain + CVE audit for all dependencies.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm audit
|
|
7
|
+
|
|
8
|
+
On-chain + CVE audit for all dependencies. Faster than <code>opm check</code> because it does not call AI agents.
|
|
9
|
+
|
|
10
|
+
## What It Does
|
|
11
|
+
|
|
12
|
+
- Scans all <code>dependencies</code> and <code>devDependencies</code> in <code>package.json</code>
|
|
13
|
+
- Queries OPMRegistry for on-chain risk scores
|
|
14
|
+
- Queries OSV for CVE counts
|
|
15
|
+
- For packages not in the registry: checks ChainPatrol blocklist
|
|
16
|
+
- Shows per-package risk level and CVE counts
|
|
17
|
+
|
|
18
|
+
## Output
|
|
19
|
+
|
|
20
|
+
| Column | Description |
|
|
21
|
+
|--------|-------------|
|
|
22
|
+
| Package | <code>name@version</code> |
|
|
23
|
+
| On-chain | Risk badge (LOW/MEDIUM/HIGH) or "not in registry" |
|
|
24
|
+
| Author | Truncated wallet address (when registered) |
|
|
25
|
+
| CVEs | Count of known vulnerabilities (red if HIGH/CRITICAL) |
|
|
26
|
+
|
|
27
|
+
Summary line: <code>X high · Y medium · Z low · W unverified · N CVEs</code>
|
|
28
|
+
|
|
29
|
+
<Tip>
|
|
30
|
+
Use <code>opm audit</code> for a quick security overview. Use <code>opm check</code> when you need AI analysis and typosquat detection.
|
|
31
|
+
</Tip>
|
|
32
|
+
|
|
33
|
+
## Environment Variables
|
|
34
|
+
|
|
35
|
+
No environment variables are required. Uses built-in RPC and contract address.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm check'
|
|
3
|
+
description: 'Comprehensive dependency security scan.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm check
|
|
7
|
+
|
|
8
|
+
Comprehensive dependency security scan. Scans all dependencies in <code>package.json</code>, runs AI agents, and optionally uploads a report to Fileverse.
|
|
9
|
+
|
|
10
|
+
## What It Scans
|
|
11
|
+
|
|
12
|
+
<AccordionGroup>
|
|
13
|
+
<Accordion title="Typosquat detection">
|
|
14
|
+
Uses Levenshtein distance against top npm packages to detect likely typosquats (e.g. <code>lodahs</code> → <code>lodash</code>).
|
|
15
|
+
</Accordion>
|
|
16
|
+
<Accordion title="CVE lookup (OSV)">
|
|
17
|
+
Queries the OSV API for known vulnerabilities per package and version.
|
|
18
|
+
</Accordion>
|
|
19
|
+
<Accordion title="On-chain score lookup">
|
|
20
|
+
Fetches aggregate risk scores from OPMRegistry for registered packages.
|
|
21
|
+
</Accordion>
|
|
22
|
+
<Accordion title="AI agent analysis">
|
|
23
|
+
Three agents analyze the full dependency list in parallel. Each produces findings, severity, and suggested replacements.
|
|
24
|
+
</Accordion>
|
|
25
|
+
</AccordionGroup>
|
|
26
|
+
|
|
27
|
+
## Report Upload
|
|
28
|
+
|
|
29
|
+
When <code>FILEVERSE_API_KEY</code> is set, the scan report is uploaded to Fileverse (IPFS). The report URI can be set on-chain for packages you publish.
|
|
30
|
+
|
|
31
|
+
## Output
|
|
32
|
+
|
|
33
|
+
- **Per-dependency results**: Typosquats, CVE counts, on-chain scores, fix versions
|
|
34
|
+
- **AI agent findings**: Per-agent analysis with severity and suggested replacements
|
|
35
|
+
- **Overall assessment**: Summary counts (typosquats, CVEs, high-risk, AI flags)
|
|
36
|
+
- **Report link**: Fileverse URL when upload succeeds
|
|
37
|
+
|
|
38
|
+
<Note>
|
|
39
|
+
<code>opm check</code> requires <code>OPENROUTER_API_KEY</code> or <code>OPENAI_API_KEY</code> for AI agent analysis. Without them, typosquat and CVE checks still run, but agent analysis is skipped.
|
|
40
|
+
</Note>
|
|
41
|
+
|
|
42
|
+
<Tip>
|
|
43
|
+
Run <code>opm fix</code> to auto-correct typosquats and vulnerable versions identified by <code>opm check</code>.
|
|
44
|
+
</Tip>
|
package/docs/cli/fix.mdx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm fix'
|
|
3
|
+
description: 'Auto-fix typosquats and vulnerable dependencies.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm fix
|
|
7
|
+
|
|
8
|
+
Same scan as <code>opm check</code> but auto-applies fixes to <code>package.json</code>. Replaces typosquat packages with correct names and updates vulnerable packages to patched versions.
|
|
9
|
+
|
|
10
|
+
## What It Fixes
|
|
11
|
+
|
|
12
|
+
<AccordionGroup>
|
|
13
|
+
<Accordion title="Typosquats">
|
|
14
|
+
Replaces package names detected as typosquats with the likely correct name (e.g. <code>lodahs</code> → <code>lodash</code>).
|
|
15
|
+
</Accordion>
|
|
16
|
+
<Accordion title="Vulnerable packages">
|
|
17
|
+
Updates packages with CRITICAL or HIGH CVEs to the patched version suggested by OSV.
|
|
18
|
+
</Accordion>
|
|
19
|
+
<Accordion title="AI-suggested replacements">
|
|
20
|
+
When 2+ agents flag a package and suggest a replacement, the fix is applied if the suggestion is valid.
|
|
21
|
+
</Accordion>
|
|
22
|
+
</AccordionGroup>
|
|
23
|
+
|
|
24
|
+
## Process
|
|
25
|
+
|
|
26
|
+
<Steps>
|
|
27
|
+
<Step title="Scan dependencies">
|
|
28
|
+
Runs typosquat detection, CVE lookup, and AI agent analysis (same as <code>opm check</code>).
|
|
29
|
+
</Step>
|
|
30
|
+
<Step title="Collect fixes">
|
|
31
|
+
Builds a list of fixes: typosquat renames, CVE upgrades, and AI-suggested replacements.
|
|
32
|
+
</Step>
|
|
33
|
+
<Step title="Apply to package.json">
|
|
34
|
+
Modifies <code>dependencies</code> and <code>devDependencies</code> with the fixes. Preserves version range prefixes (<code>^</code>, <code>~</code>).
|
|
35
|
+
</Step>
|
|
36
|
+
<Step title="Upload report">
|
|
37
|
+
Optionally uploads the scan report to Fileverse when <code>FILEVERSE_API_KEY</code> is set.
|
|
38
|
+
</Step>
|
|
39
|
+
</Steps>
|
|
40
|
+
|
|
41
|
+
## After Running
|
|
42
|
+
|
|
43
|
+
<Warning>
|
|
44
|
+
<code>opm fix</code> modifies <code>package.json</code> in place. Run <code>npm install</code> (or <code>opm install</code>) to apply the changes and update the lockfile.
|
|
45
|
+
</Warning>
|
|
46
|
+
|
|
47
|
+
<Tip>
|
|
48
|
+
Review the diff in <code>package.json</code> before committing. AI-suggested replacements require consensus from 2+ agents before being applied.
|
|
49
|
+
</Tip>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm info'
|
|
3
|
+
description: 'Show on-chain security information for a package.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm info
|
|
7
|
+
|
|
8
|
+
Show on-chain security information for a package. Displays author, checksum, signature, ENS name, report URI, agent scores, aggregate score, and safest version.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
<CodeGroup>
|
|
13
|
+
|
|
14
|
+
```bash Latest version
|
|
15
|
+
opm info lodash
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash Specific version
|
|
19
|
+
opm info lodash@4.17.21
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
</CodeGroup>
|
|
23
|
+
|
|
24
|
+
## Output
|
|
25
|
+
|
|
26
|
+
| Field | Description |
|
|
27
|
+
|-------|-------------|
|
|
28
|
+
| Author | Wallet address (with ENS resolution when available) |
|
|
29
|
+
| Checksum | SHA-256 hash of the tarball |
|
|
30
|
+
| Signature | ECDSA signature (verified or unverified) |
|
|
31
|
+
| ENS name | Author identity (e.g. <code>vitalik.eth</code>) |
|
|
32
|
+
| Report URI | Link to Fileverse audit report |
|
|
33
|
+
| Agent scores | Per-agent risk scores and reasoning |
|
|
34
|
+
| Aggregate score | Mean risk score (0–100) |
|
|
35
|
+
| Safest version | Lowest-risk version in recent releases |
|
|
36
|
+
|
|
37
|
+
## Links
|
|
38
|
+
|
|
39
|
+
- **Fileverse report** — Full AI audit when report URI is set
|
|
40
|
+
- **BaseScan** — Contract and transaction links
|
|
41
|
+
|
|
42
|
+
<Note>
|
|
43
|
+
If the package is not in the OPM registry, a warning is shown. No env vars are required.
|
|
44
|
+
</Note>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm install'
|
|
3
|
+
description: 'Install packages with on-chain security verification.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm install
|
|
7
|
+
|
|
8
|
+
Install packages with on-chain security verification. OPM runs a verification pipeline before delegating to npm.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
<CodeGroup>
|
|
13
|
+
|
|
14
|
+
```bash Install specific package
|
|
15
|
+
opm install lodash
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash Install with version
|
|
19
|
+
opm install lodash@4.17.21
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash Install all dependencies
|
|
23
|
+
opm install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
</CodeGroup>
|
|
27
|
+
|
|
28
|
+
## Aliases
|
|
29
|
+
|
|
30
|
+
- <code>opm i</code> — same as <code>opm install</code>
|
|
31
|
+
- <code>opm add</code> — same as <code>opm install</code>
|
|
32
|
+
|
|
33
|
+
## Verification Pipeline
|
|
34
|
+
|
|
35
|
+
<AccordionGroup>
|
|
36
|
+
<Accordion title="CVE check (OSV)">
|
|
37
|
+
Queries the OSV API for known CVEs and GHSA advisories. **CRITICAL** CVEs block installation.
|
|
38
|
+
</Accordion>
|
|
39
|
+
<Accordion title="On-chain score lookup">
|
|
40
|
+
Fetches aggregate risk score from OPMRegistry. Blocks if score ≥ 70.
|
|
41
|
+
</Accordion>
|
|
42
|
+
<Accordion title="Signature verification">
|
|
43
|
+
Verifies ECDSA signature against tarball checksum for packages in the registry.
|
|
44
|
+
</Accordion>
|
|
45
|
+
<Accordion title="ChainPatrol blocklist">
|
|
46
|
+
For packages not in the OPM registry, falls back to ChainPatrol API. BLOCKED status prevents install.
|
|
47
|
+
</Accordion>
|
|
48
|
+
</AccordionGroup>
|
|
49
|
+
|
|
50
|
+
## Blocking Rules
|
|
51
|
+
|
|
52
|
+
<Warning>
|
|
53
|
+
Installation is **blocked** if:
|
|
54
|
+
- Risk score ≥ 70 (on-chain)
|
|
55
|
+
- Any CRITICAL CVE is present (OSV)
|
|
56
|
+
- ChainPatrol returns BLOCKED (for unregistered packages)
|
|
57
|
+
</Warning>
|
|
58
|
+
|
|
59
|
+
## Fallback Behavior
|
|
60
|
+
|
|
61
|
+
<Note>
|
|
62
|
+
If a package is **not in the OPM registry**, OPM falls back to standard <code>npm install</code> with a warning. ChainPatrol is consulted when available.
|
|
63
|
+
</Note>
|
|
64
|
+
|
|
65
|
+
## Environment Variables
|
|
66
|
+
|
|
67
|
+
No environment variables are required for basic install. Defaults for RPC, contract address, and API URLs are built-in.
|
|
68
|
+
|
|
69
|
+
<Tip>
|
|
70
|
+
For bulk install (<code>opm install</code> with no args), all <code>dependencies</code> and <code>devDependencies</code> are scanned in parallel before npm install runs.
|
|
71
|
+
</Tip>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm push'
|
|
3
|
+
description: 'Sign, scan, publish, and register a package on-chain.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm push
|
|
7
|
+
|
|
8
|
+
Sign, scan, publish, and register a package on-chain. The full verification pipeline runs before publishing to npm and registering on the OPMRegistry.
|
|
9
|
+
|
|
10
|
+
## What It Does
|
|
11
|
+
|
|
12
|
+
<Steps>
|
|
13
|
+
<Step title="Pack tarball">
|
|
14
|
+
Creates an npm tarball via <code>npm pack</code> and computes SHA-256 checksum over the packed file.
|
|
15
|
+
</Step>
|
|
16
|
+
<Step title="Sign checksum">
|
|
17
|
+
Signs the checksum with ECDSA (secp256k1) using your <code>OPM_SIGNING_KEY</code>.
|
|
18
|
+
</Step>
|
|
19
|
+
<Step title="Resolve ENS">
|
|
20
|
+
Resolves your wallet address to an ENS name (Base Sepolia, then Ethereum Mainnet fallback).
|
|
21
|
+
</Step>
|
|
22
|
+
<Step title="Security scan">
|
|
23
|
+
Runs 3 AI agents in parallel (Claude, Gemini, DeepSeek) to analyze the package. Each agent submits a risk score (0–100) and reasoning on-chain.
|
|
24
|
+
</Step>
|
|
25
|
+
<Step title="Risk check">
|
|
26
|
+
If aggregate score ≥ 80 or risk level is CRITICAL, publishing is blocked.
|
|
27
|
+
</Step>
|
|
28
|
+
<Step title="Publish to npm">
|
|
29
|
+
Publishes the tarball to the npm registry (uses <code>--token</code> or <code>NPM_TOKEN</code> for automation).
|
|
30
|
+
</Step>
|
|
31
|
+
<Step title="Register on-chain">
|
|
32
|
+
Calls <code>OPMRegistry.registerPackage()</code> with package name, version, checksum, signature, and ENS name.
|
|
33
|
+
</Step>
|
|
34
|
+
</Steps>
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
<CodeGroup>
|
|
39
|
+
|
|
40
|
+
```bash Basic
|
|
41
|
+
opm push
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```bash With npm token
|
|
45
|
+
opm push --token <npm-token>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```bash With 2FA code
|
|
49
|
+
opm push --otp <code>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
</CodeGroup>
|
|
53
|
+
|
|
54
|
+
## Required Environment Variables
|
|
55
|
+
|
|
56
|
+
| Variable | Purpose |
|
|
57
|
+
|----------|---------|
|
|
58
|
+
| `OPM_SIGNING_KEY` | Ethereum private key for package signing (ECDSA) |
|
|
59
|
+
| `OPENROUTER_API_KEY` or `OPENAI_API_KEY` | At least one required for AI agent scanning |
|
|
60
|
+
| `AGENT_PRIVATE_KEY` | Agent wallet for submitting scores on-chain (must hold Base Sepolia ETH for gas) |
|
|
61
|
+
|
|
62
|
+
## Optional Environment Variables
|
|
63
|
+
|
|
64
|
+
| Variable | Purpose |
|
|
65
|
+
|----------|---------|
|
|
66
|
+
| `NPM_TOKEN` | npm automation token (alternative to <code>--token</code> flag) |
|
|
67
|
+
| `FILEVERSE_API_KEY` | Upload audit report to IPFS via Fileverse |
|
|
68
|
+
|
|
69
|
+
## Risk Blocking
|
|
70
|
+
|
|
71
|
+
<Warning>
|
|
72
|
+
Packages with **risk score ≥ 80** or **CRITICAL** level are blocked from publishing. The scan step fails, npm publish is skipped, and on-chain registration does not occur.
|
|
73
|
+
</Warning>
|
|
74
|
+
|
|
75
|
+
When blocked, the CLI shows which agents scored the package and the aggregate risk. Fix the issues and run <code>opm push</code> again.
|
|
76
|
+
|
|
77
|
+
## What Gets Stored On-Chain
|
|
78
|
+
|
|
79
|
+
After a successful push, the following data is recorded on the OPMRegistry:
|
|
80
|
+
|
|
81
|
+
| Data | Description |
|
|
82
|
+
|------|-------------|
|
|
83
|
+
| Package name | From <code>package.json</code> |
|
|
84
|
+
| Version | Semantic version |
|
|
85
|
+
| Checksum | SHA-256 hash of the tarball |
|
|
86
|
+
| Signature | ECDSA signature of the checksum |
|
|
87
|
+
| ENS name | Author identity (e.g. <code>vitalik.eth</code>) |
|
|
88
|
+
| Agent scores | Per-agent risk scores and reasoning |
|
|
89
|
+
| Report URI | Fileverse/IPFS link to the full audit report |
|
|
90
|
+
|
|
91
|
+
## Output
|
|
92
|
+
|
|
93
|
+
- **Etherscan links** for every transaction: score submissions (one per agent) and package registration
|
|
94
|
+
- **Report URI** link when uploaded to Fileverse
|
|
95
|
+
- **npm package URL** on successful publish
|
|
96
|
+
|
|
97
|
+
<Note>
|
|
98
|
+
If 2FA is enabled on your npm account, use <code>opm push --otp <code></code> or an npm automation token with "bypass 2FA" enabled.
|
|
99
|
+
</Note>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'opm register-agent'
|
|
3
|
+
description: 'Register a new security agent with ZK-verified benchmarks.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# opm register-agent
|
|
7
|
+
|
|
8
|
+
Register a new security agent with ZK-verified benchmarks. Agents must pass 10 benchmark cases with 100% accuracy and produce a valid ZK proof before they can submit scores on-chain.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
opm register-agent --name <name> --model <model> [--system-prompt <prompt>]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
| Flag | Required | Description |
|
|
17
|
+
|------|----------|-------------|
|
|
18
|
+
| <code>--name</code> | Yes | Agent identifier (e.g. <code>my-security-agent</code>) |
|
|
19
|
+
| <code>--model</code> | Yes | LLM model (e.g. <code>anthropic/claude-sonnet-4-20250514</code>) |
|
|
20
|
+
| <code>--system-prompt</code> | No | Custom system prompt (defaults to OPM security auditor prompt) |
|
|
21
|
+
|
|
22
|
+
## Required Environment Variables
|
|
23
|
+
|
|
24
|
+
| Variable | Purpose |
|
|
25
|
+
|----------|---------|
|
|
26
|
+
| <code>AGENT_PRIVATE_KEY</code> | Wallet that becomes the agent identity; must hold Base Sepolia ETH for gas |
|
|
27
|
+
| <code>OPENROUTER_API_KEY</code> or <code>OPENAI_API_KEY</code> | Required to run benchmark LLM calls |
|
|
28
|
+
|
|
29
|
+
## Process
|
|
30
|
+
|
|
31
|
+
<Steps>
|
|
32
|
+
<Step title="Validate configuration">
|
|
33
|
+
Checks agent name, model, and required env vars.
|
|
34
|
+
</Step>
|
|
35
|
+
<Step title="Run benchmark suite">
|
|
36
|
+
Executes 10 labeled test cases across categories: clean, typosquat, malicious, cve, obfuscated, exfiltration, dependency_confusion.
|
|
37
|
+
</Step>
|
|
38
|
+
<Step title="Generate ZK proof">
|
|
39
|
+
Produces a zero-knowledge proof that the agent achieved 100% accuracy without revealing test data or expected outputs.
|
|
40
|
+
</Step>
|
|
41
|
+
<Step title="Register on-chain">
|
|
42
|
+
Calls <code>OPMRegistry.registerAgent()</code> with name, model, system prompt hash, and proof hash.
|
|
43
|
+
</Step>
|
|
44
|
+
</Steps>
|
|
45
|
+
|
|
46
|
+
## Benchmark Categories
|
|
47
|
+
|
|
48
|
+
| Category | Count | Description |
|
|
49
|
+
|----------|-------|-------------|
|
|
50
|
+
| clean | 3 | Legitimate packages (string utils, math, validator) |
|
|
51
|
+
| typosquat | 1 | Typosquat with credential exfiltration |
|
|
52
|
+
| malicious | 2 | Postinstall shell, SSH key exfiltration |
|
|
53
|
+
| cve | 1 | Known prototype pollution CVE |
|
|
54
|
+
| obfuscated | 1 | Obfuscated reverse shell |
|
|
55
|
+
| exfiltration | 1 | Env var exfiltration on import |
|
|
56
|
+
| dependency_confusion | 1 | Internal scope shadowing + exfiltration |
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
<Warning>
|
|
61
|
+
**100% accuracy** is required. The agent must pass all 10 benchmark cases. Each case is evaluated by score range and risk level ordinal.
|
|
62
|
+
</Warning>
|
|
63
|
+
|
|
64
|
+
<Note>
|
|
65
|
+
The ZK proof hides test data and individual results. Only the commitment hash and proof hash are stored on-chain.
|
|
66
|
+
</Note>
|
|
67
|
+
|
|
68
|
+
## Success
|
|
69
|
+
|
|
70
|
+
On success:
|
|
71
|
+
- Etherscan transaction link is shown
|
|
72
|
+
- Agent is authorized to submit scores
|
|
73
|
+
- Agent participates in the next package scan alongside existing agents
|
|
74
|
+
|
|
75
|
+
## Failure
|
|
76
|
+
|
|
77
|
+
On failure, the CLI shows:
|
|
78
|
+
- Which benchmark cases failed and why
|
|
79
|
+
- Expected vs actual risk level and score
|
|
80
|
+
- Rejection reason (e.g. "Agent achieved 90% accuracy (100% required)")
|