opmsec 0.1.4 → 0.1.51

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 (114) hide show
  1. package/.env.example +1 -1
  2. package/README.md +71 -275
  3. package/bun.lock +3 -3
  4. package/docs/architecture/agents.mdx +11 -59
  5. package/docs/architecture/benchmarks.mdx +20 -46
  6. package/docs/architecture/overview.mdx +31 -38
  7. package/docs/architecture/scanner.mdx +11 -37
  8. package/docs/cli/audit.mdx +9 -12
  9. package/docs/cli/check.mdx +12 -26
  10. package/docs/cli/fix.mdx +10 -30
  11. package/docs/cli/info.mdx +12 -19
  12. package/docs/cli/install.mdx +27 -39
  13. package/docs/cli/push.mdx +40 -57
  14. package/docs/cli/register-agent.mdx +21 -53
  15. package/docs/cli/view.mdx +12 -29
  16. package/docs/concepts/ens-records.mdx +44 -0
  17. package/docs/concepts/multi-agent-consensus.mdx +18 -36
  18. package/docs/concepts/on-chain-registry.mdx +22 -49
  19. package/docs/concepts/security-model.mdx +20 -52
  20. package/docs/concepts/zk-agent-verification.mdx +26 -64
  21. package/docs/contract/events.mdx +13 -74
  22. package/docs/contract/functions.mdx +40 -126
  23. package/docs/contract/overview.mdx +17 -36
  24. package/docs/introduction.mdx +22 -25
  25. package/docs/mint.json +1 -0
  26. package/docs/quickstart.mdx +34 -70
  27. package/docs/system-design.png +0 -0
  28. package/package.json +5 -5
  29. package/packages/cli/src/commands/audit.tsx +72 -5
  30. package/packages/cli/src/commands/author-view.tsx +87 -2
  31. package/packages/cli/src/commands/check.tsx +95 -14
  32. package/packages/cli/src/commands/fix.tsx +25 -12
  33. package/packages/cli/src/commands/info.tsx +92 -4
  34. package/packages/cli/src/commands/install.tsx +54 -8
  35. package/packages/cli/src/commands/push.tsx +151 -2
  36. package/packages/cli/src/commands/register-agent.tsx +72 -31
  37. package/packages/cli/src/index.tsx +4 -4
  38. package/packages/cli/src/services/dep-graph.ts +298 -0
  39. package/packages/cli/src/services/ens-records.ts +530 -0
  40. package/packages/cli/src/services/lockfile.ts +224 -0
  41. package/packages/cli/src/services/merkle.ts +52 -0
  42. package/packages/cli/src/services/osv.ts +50 -0
  43. package/packages/core/src/benchmarks.ts +116 -0
  44. package/packages/core/src/constants.ts +19 -6
  45. package/packages/core/src/model-rankings.ts +49 -16
  46. package/packages/core/src/types.ts +48 -0
  47. package/packages/core/src/utils.ts +21 -3
  48. package/packages/scanner/src/agents/base-agent.ts +22 -10
  49. package/packages/scanner/src/index.ts +2 -1
  50. package/packages/scanner/src/queue/memory-queue.ts +30 -11
  51. package/packages/scanner/src/services/benchmark-runner.ts +86 -1
  52. package/packages/scanner/src/services/fileverse.ts +61 -12
  53. package/packages/web/.next/BUILD_ID +1 -1
  54. package/packages/web/.next/app-build-manifest.json +7 -6
  55. package/packages/web/.next/build-manifest.json +7 -7
  56. package/packages/web/.next/images-manifest.json +1 -1
  57. package/packages/web/.next/prerender-manifest.json +7 -7
  58. package/packages/web/.next/required-server-files.json +2 -2
  59. package/packages/web/.next/server/app/_not-found/page.js +2 -2
  60. package/packages/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  61. package/packages/web/.next/server/app/_not-found.html +1 -1
  62. package/packages/web/.next/server/app/_not-found.rsc +4 -2
  63. package/packages/web/.next/server/app/index.html +6 -1
  64. package/packages/web/.next/server/app/index.rsc +5 -3
  65. package/packages/web/.next/server/app/page.js +8 -2
  66. package/packages/web/.next/server/app/page_client-reference-manifest.js +1 -1
  67. package/packages/web/.next/server/middleware-build-manifest.js +1 -1
  68. package/packages/web/.next/server/next-font-manifest.js +1 -1
  69. package/packages/web/.next/server/next-font-manifest.json +1 -1
  70. package/packages/web/.next/server/pages/404.html +1 -1
  71. package/packages/web/.next/server/pages/500.html +1 -1
  72. package/packages/web/.next/server/pages-manifest.json +1 -1
  73. package/packages/web/.next/static/chunks/174-5b5efcb3b8efcc01.js +1 -0
  74. package/packages/web/.next/static/chunks/app/layout-de8e841104500505.js +1 -0
  75. package/packages/web/.next/static/chunks/app/page-7d2a23ad744d529a.js +1 -0
  76. package/packages/web/.next/static/chunks/{main-ee293fa6aa18bdd1.js → main-4e8d71b5ef7ee7e3.js} +1 -1
  77. package/packages/web/.next/static/chunks/webpack-0dcd67569eb46132.js +1 -0
  78. package/packages/web/.next/static/css/102562cf2d0ae9b0.css +3 -0
  79. package/packages/web/.next/static/media/4cf2300e9c8272f7-s.p.woff2 +0 -0
  80. package/packages/web/.next/static/media/747892c23ea88013-s.woff2 +0 -0
  81. package/packages/web/.next/static/media/8d697b304b401681-s.woff2 +0 -0
  82. package/packages/web/.next/static/media/93f479601ee12b01-s.p.woff2 +0 -0
  83. package/packages/web/.next/static/media/9610d9e46709d722-s.woff2 +0 -0
  84. package/packages/web/.next/static/media/ba015fad6dcf6784-s.woff2 +0 -0
  85. package/packages/web/.next/trace +2 -2
  86. package/packages/web/app/globals.css +197 -51
  87. package/packages/web/app/layout.tsx +6 -3
  88. package/packages/web/app/page.tsx +789 -312
  89. package/packages/web/bun.lock +66 -105
  90. package/packages/web/next.config.ts +8 -1
  91. package/packages/web/package.json +5 -2
  92. package/packages/web/postcss.config.mjs +2 -2
  93. package/packages/web/public/apple-icon.png +1 -0
  94. package/packages/web/public/dependency-bottleneck.png +0 -0
  95. package/packages/web/public/icon-dark-32x32.png +1 -0
  96. package/packages/web/public/icon-light-32x32.png +1 -0
  97. package/packages/web/public/icon.svg +1 -0
  98. package/packages/web/public/nextjs-cve-announcement.png +0 -0
  99. package/packages/web/public/phantomraven-npm-attack.png +0 -0
  100. package/packages/web/public/placeholder-logo.png +1 -0
  101. package/packages/web/public/placeholder-logo.svg +1 -0
  102. package/packages/web/public/placeholder-user.jpg +1 -0
  103. package/packages/web/public/placeholder.jpg +1 -0
  104. package/packages/web/public/placeholder.svg +1 -0
  105. package/packages/web/public/react-cve-meme.png +0 -0
  106. package/packages/web/public/wallet-drain-exploit.png +0 -0
  107. package/packages/web/styles/globals.css +125 -0
  108. package/packages/web/.next/static/chunks/app/layout-28a489fb4398663f.js +0 -1
  109. package/packages/web/.next/static/chunks/app/page-e58ccdb78625bce6.js +0 -1
  110. package/packages/web/.next/static/chunks/webpack-e1ae44446e7f7355.js +0 -1
  111. package/packages/web/.next/static/css/21d69157e271f2ab.css +0 -3
  112. package/packages/web/tailwind.config.ts +0 -48
  113. /package/packages/web/.next/static/{2XIFCTTKVZwN_RsNE-Rrr → jwpVFtQGO17b1LATsewLl}/_buildManifest.js +0 -0
  114. /package/packages/web/.next/static/{2XIFCTTKVZwN_RsNE-Rrr → jwpVFtQGO17b1LATsewLl}/_ssgManifest.js +0 -0
package/.env.example CHANGED
@@ -21,4 +21,4 @@ FILEVERSE_API_KEY= # from ddocs.new → Settings → Developer
21
21
  # ETH_SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
22
22
  # FILEVERSE_API_URL=http://localhost:8001
23
23
  # CHAINPATROL_API_KEY= # optional, for blocklist checks
24
- # ARTIFICIAL_ANALYSIS_API_KEY= # optional, for model-weighted scoring
24
+ # ARTIFICIAL_ANALYSIS_API_KEY= # optional, for model-weighted scoring
package/README.md CHANGED
@@ -2,347 +2,143 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/opmsec)](https://www.npmjs.com/package/opmsec)
4
4
  [![GitHub](https://img.shields.io/github/stars/dhananjaypai08/opm)](https://github.com/dhananjaypai08/opm)
5
- [![Contract](https://img.shields.io/badge/Base%20Sepolia-0x8A6a...1E85-blue)](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
5
+ [![Contract](https://img.shields.io/badge/Base%20Sepolia-0x1668...1d48-blue)](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
6
6
 
7
- OPM is a security-hardened CLI wrapper around npm that introduces cryptographic package signing, multi-agent AI threat analysis, on-chain audit registries, and decentralized report storage to the JavaScript dependency supply chain. The CLI is built on Bun and uses Ink (React for terminals) for its interface, while all underlying package operations (install, publish, pack) delegate to npm via subprocess invocation. Its on-chain registry architecture implements a domain-specific instantiation of the [ERC-8004 (Trustless Agents)](https://eips.ethereum.org/EIPS/eip-8004) pattern, where autonomous AI agents submit structured reputation signals and validation evidence to chain-resident registries, enabling trust establishment across organizational boundaries without prior coordination.
7
+ OPM is a drop-in npm replacement that adds **cryptographic signing**, **multi-agent AI security scanning**, **on-chain audit registries**, and **zero-knowledge agent verification** to the JavaScript supply chain.
8
8
 
9
- OPM supports **permissionless agent registration** anyone can onboard their own security agent by proving 100% accuracy on a labeled benchmark suite via zero-knowledge proofs, with the proof hash stored immutably on-chain. Every on-chain transaction (agent score submissions, package registrations, agent registrations) surfaces as a clickable [BaseScan](https://sepolia.basescan.org) link directly in the terminal UI.
9
+ Every package publish is scanned by 3 AI agents in parallel. Risk scores are submitted on-chain. Audit reports are stored encrypted on IPFS via Fileverse. Install-time checks verify signatures, query CVEs, and enforce risk thresholds all from the terminal.
10
10
 
11
- ## System Overview
11
+ ## System Design
12
12
 
13
- OPM interposes a verification pipeline between the developer and the npm registry. Package authors sign tarballs with ECDSA keys derived from Ethereum wallets. Upon publish, three heterogeneous AI models conduct parallel static analysis of source code, dependency metadata, and version history. Each agent submits a structured risk assessment to the `OPMRegistry` smart contract deployed on Base Sepolia, following the same identity-reputation-validation triad defined by ERC-8004: agents hold on-chain identities (authorized wallets with ENS binding), submit structured reputation signals (`riskScore` + `reasoning` per package version, analogous to ERC-8004's `giveFeedback`), and attach off-chain validation evidence as Fileverse report URIs (analogous to ERC-8004's `feedbackURI`/`responseURI`). The formatted audit report is encrypted and persisted to Fileverse dDocs. Consumers invoking `opm install` query this on-chain registry, verify signatures against checksums, cross-reference the OSV vulnerability database, and enforce configurable risk thresholds before permitting installation.
13
+ ![OPM System Design](docs/system-design.png)
14
14
 
15
- ### Threat Model
16
-
17
- OPM addresses the following attack surfaces:
18
-
19
- - **Supply chain injection**: Malicious postinstall scripts, obfuscated payloads, environment variable exfiltration, and runtime code generation detected by AI agents.
20
- - **Typosquatting**: Package names are compared against npm registry search results and download-count differentials. AI agents independently assess name similarity to known packages.
21
- - **Dependency confusion**: Scoped versus unscoped name conflicts and internal package shadowing are surfaced during `opm check`.
22
- - **Silent maintainer takeover**: Version history analysis detects sudden dependency graph mutations, new maintainer additions, and anomalous size deltas between releases.
23
- - **Known vulnerability exploitation**: Real-time CVE and GHSA data from the Open Source Vulnerabilities (OSV) API is integrated into install-time blocking and upgrade recommendations, with CVSS v3 base score computation for severity classification.
24
- - **Malicious / spamming agents**: Permissionless agent registration requires passing a 10-case benchmark suite with 100% accuracy, verified via zero-knowledge proofs, preventing unqualified agents from polluting the on-chain risk registry.
25
-
26
- ### Data Flow
27
-
28
- ```
29
- opm push
30
- |
31
- +-- Compute SHA-256 checksum over packed tarball
32
- +-- Sign checksum with author's Ethereum private key (ECDSA secp256k1)
33
- +-- Resolve author ENS identity (Sepolia, Mainnet fallback)
34
- +-- Dispatch 3+ AI agents in parallel (permissionless agents included)
35
- | +-- Each agent: static analysis, risk scoring (0-100), structured JSON output
36
- | +-- Agent wallets submit scores to OPMRegistry.submitScore()
37
- | +-- Aggregate risk computed; publish blocked if score >= 80
38
- | +-- BaseScan tx links shown for every score submission
39
- +-- Upload formatted markdown report to Fileverse dDocs (encrypted, on-chain synced)
40
- +-- Publish tarball to npm (automation token or OTP for 2FA)
41
- +-- Register package metadata on OPMRegistry.registerPackage()
42
- | +-- Stores: checksum, signature, ENS name, report URI
43
- | +-- BaseScan tx link + contract link shown in terminal
44
- +-- Set report URI on-chain via OPMRegistry.setReportURI()
45
-
46
- opm register-agent --name <name> --model <model>
47
- |
48
- +-- Validate agent configuration and environment
49
- +-- Generate ZK commitment over expected benchmark outputs
50
- +-- Run candidate agent against 10 labeled security test cases
51
- | +-- Categories: clean, typosquat, malicious, CVE, obfuscated, exfiltration, dependency confusion
52
- | +-- Each case evaluated against expected risk level and score range
53
- +-- Generate zero-knowledge proof of accuracy
54
- | +-- Hash commitment scheme: hash(salt, expected) → commitment
55
- | +-- Proof: hash(commitment, result_hash, accuracy_flag, salt)
56
- | +-- Proves 100% accuracy without revealing test data or individual results
57
- +-- Verify ZK proof integrity
58
- +-- Register agent on OPMRegistry.registerAgent() if 100% accuracy
59
- | +-- Stores: name, model, systemPromptHash, proofHash on-chain
60
- | +-- Auto-authorizes agent for submitScore and setReportURI
61
- +-- Show BaseScan tx link and contract link
62
- ```
63
-
64
- ## Prerequisites
65
-
66
- - [Bun](https://bun.sh) >= 1.2
67
- - Node.js >= 20
68
- - Ethereum wallet funded with Base Sepolia ETH (required for gas during `opm push`)
69
-
70
- ## Installation
71
-
72
- ```bash
73
- git clone https://github.com/dhananjaypai08/opm.git && cd opm
74
- cp .env.example .env
75
- bun install
76
- bun link
77
- ```
78
-
79
- Or install from npm:
15
+ ## Quick Start
80
16
 
81
17
  ```bash
18
+ # Install globally
82
19
  npm i -g opmsec
83
- ```
84
-
85
- The `bun link` command registers `opm` as a globally available CLI binary.
86
-
87
- ## Smart Contract Deployment
88
20
 
89
- ```bash
90
- cd packages/contracts
91
- npm install
92
- npx hardhat compile
93
- npx hardhat run scripts/deploy.ts --network baseSepolia
94
- ```
95
-
96
- Record the deployed contract address and set it as `CONTRACT_ADDRESS` in `.env`, or rely on the default address hardcoded in `packages/core/src/constants.ts`.
97
-
98
- The contract is live on Base Sepolia: [`0x16684391fc9bf48246B08Afe16d1a57BFa181d48`](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
99
-
100
- ## Fileverse dDocs Configuration
101
-
102
- OPM persists AI scan reports as encrypted, on-chain-synced documents via the Fileverse dDocs protocol.
103
-
104
- 1. Navigate to [ddocs.new](https://ddocs.new), open Settings, enable Developer Mode, and generate an API key.
105
- 2. Set `FILEVERSE_API_KEY` in `.env`.
106
- 3. Start the local Fileverse API server:
107
-
108
- ```bash
109
- npx @fileverse/api --apiKey <YOUR_API_KEY>
21
+ # Or clone and link
22
+ git clone https://github.com/dhananjaypai08/opm.git && cd opm
23
+ cp .env.example .env
24
+ bun install && bun link
110
25
  ```
111
26
 
112
- The server binds to `http://localhost:8001` by default. This is configurable via `FILEVERSE_API_URL`.
113
-
114
27
  ## Commands
115
28
 
116
- ### Security Commands
117
-
118
- | Command | Description |
29
+ | Command | What it does |
119
30
  |---------|-------------|
120
- | `opm push` | Sign, scan, publish to npm, and register on-chain |
121
- | `opm push --token <token>` | Publish using an npm automation token (bypasses 2FA) |
122
- | `opm push --otp <code>` | Publish with a one-time 2FA code |
123
- | `opm install <pkg>[@ver]` | Install with signature verification, CVE checks, and on-chain risk gating |
124
- | `opm install` | Verify all dependencies in package.json (bulk scan mode) |
125
- | `opm check` | Scan all dependencies for typosquats, CVEs, and AI-detected risks |
126
- | `opm fix` | Auto-correct typosquatted names and upgrade vulnerable versions |
127
- | `opm audit` | Audit all dependencies against on-chain and CVE data |
128
- | `opm info <pkg>` | Display on-chain security metadata for a specific package |
129
- | `opm view <name.eth>` | Display ENS author profile, published packages, and reputation |
130
- | `opm whois <name>` | ENS identity lookup (appends `.eth` if omitted) |
131
-
132
- ### Agent Commands
133
-
134
- | Command | Description |
135
- |---------|-------------|
136
- | `opm register-agent --name <n> --model <m>` | Register a new security agent with ZK-verified benchmarks |
137
- | `opm register-agent --system-prompt <p>` | Optional custom system prompt (defaults to OPM security auditor) |
31
+ | `opm push` | Sign, scan with 3 AI agents, publish to npm, register on-chain, write ENS records |
32
+ | `opm install <pkg>` | Verify signature, check CVEs, query on-chain risk, then install |
33
+ | `opm install` | Bulk scan all package.json deps with ENS resolution and auto-bumping |
34
+ | `opm check` | Scan deps for typosquats, CVEs, and AI-detected risks |
35
+ | `opm fix` | Auto-patch typosquats and upgrade vulnerable versions |
36
+ | `opm info <pkg>` | On-chain metadata, ENS records, audit report, CVEs |
37
+ | `opm view <name.eth>` | Author profile, reputation, published packages |
38
+ | `opm register-agent` | Onboard a new AI agent with ZK-verified benchmarks |
138
39
 
139
- ### npm Passthrough
40
+ Standard npm commands (`init`, `run`, `test`, `build`, `start`, etc.) pass through transparently.
140
41
 
141
- All standard npm commands are forwarded transparently:
42
+ ## How It Works
142
43
 
143
- ```
144
- opm init opm run <script> opm test
145
- opm start opm build opm uninstall <pkg>
146
- opm outdated opm update opm list
147
- opm link opm pack
148
- ```
44
+ ### `opm push`
149
45
 
150
- Aliases: `i`, `add` map to `install`; `rm` maps to `uninstall`; `ls` maps to `list`.
46
+ Pack tarball SHA-256 checksum ECDSA sign → resolve ENS → scan with 3 AI agents in parallel → weighted consensus → block if score ≥ 80 → publish to npm register on-chain → upload report to Fileverse → write ENS text records → set IPFS contenthash from Fileverse contract.
151
47
 
152
- ## Permissionless Agent Registration
48
+ ### `opm install`
153
49
 
154
- OPM supports permissionless agent onboarding. Any developer can register their own security agent by providing a model and optionally a custom system prompt. Before registration, the agent must prove it can accurately classify security threats.
50
+ Parse ENS version (e.g. `pkg@name.eth`) resolve author on-chain get safest version check CVEs verify checksum + signature ChainPatrol check npm install. Auto-bumps to safer versions if CVEs or high risk detected.
155
51
 
156
- ### How It Works
52
+ ### `opm register-agent`
157
53
 
158
- 1. **Benchmark Suite**: 10 labeled test cases covering clean packages, typosquats, env exfiltration, obfuscated code, postinstall attacks, known CVEs, and dependency confusion.
159
- 2. **Agent Evaluation**: The candidate agent runs against all 10 cases. Each response is evaluated against expected risk levels and score ranges.
160
- 3. **ZK Proof Generation**: A zero-knowledge proof is generated using a hash-commitment scheme:
161
- - Expected outputs are committed: `hash(salt, expected_verdicts) → commitment`
162
- - Agent outputs are hashed: `hash(salt, actual_verdicts) → result_hash`
163
- - Proof binds everything: `hash(commitment, result_hash, accuracy_flag, salt) → proof`
164
- - Only a binary pass/fail is disclosed — test data and individual results remain hidden
165
- 4. **On-chain Registration**: If accuracy is 100%, the agent's proof hash is stored on-chain via `OPMRegistry.registerAgent()`, and the agent is auto-authorized to submit scores.
54
+ Generate 10 benchmark cases commit expected results run candidate agent compare actual vs expected if 100% accuracy: generate ZK proof → register on-chain with proof hash. Agent becomes authorized to submit scores.
166
55
 
167
- ### Circom Circuit
56
+ ## AI Agents
168
57
 
169
- A reference circom circuit (`packages/contracts/circuits/accuracy_verifier.circom`) implements the verification logic for potential on-chain proof verification:
58
+ Three models scan every publish in parallel. Diversity reduces single-model blind spots.
170
59
 
171
- ```bash
172
- # Compile
173
- circom accuracy_verifier.circom --r1cs --wasm --sym -o build/
174
-
175
- # Trusted setup
176
- snarkjs groth16 setup build/accuracy_verifier.r1cs pot12_final.ptau build/accuracy_verifier_0000.zkey
177
- snarkjs zkey contribute build/accuracy_verifier_0000.zkey build/accuracy_verifier_final.zkey --name="opm-ceremony"
178
-
179
- # Export Solidity verifier (for on-chain verification)
180
- snarkjs zkey export solidityverifier build/accuracy_verifier_final.zkey contracts/AccuracyVerifier.sol
181
- ```
182
-
183
- ## AI Agent Architecture
184
-
185
- Three language models evaluate every package publish in parallel. Model diversity is enforced to reduce single-model blind spots and improve consensus reliability. Additional agents can be registered permissionlessly.
186
-
187
- | Agent | OpenRouter (preferred) | OpenAI (fallback) |
188
- |-------|----------------------|-------------------|
60
+ | Agent | Model (OpenRouter) | Fallback (OpenAI) |
61
+ |-------|-------------------|-------------------|
189
62
  | agent-1 | Claude Sonnet 4 | GPT-4.1 |
190
63
  | agent-2 | Gemini 2.5 Flash | GPT-4.1 Mini |
191
64
  | agent-3 | DeepSeek Chat | GPT-4.1 Nano |
192
65
 
193
- When `OPENROUTER_API_KEY` is configured, OPM routes through OpenRouter for model diversity. Otherwise, it falls back to OpenAI variants via `OPENAI_API_KEY`. At least one key is required for `opm push`.
194
-
195
- Each agent produces a structured JSON assessment containing:
196
-
197
- - **Risk score** (0-100) with categorical classification (LOW, MEDIUM, HIGH, CRITICAL)
198
- - **Vulnerability enumeration** with severity, category, file path, and evidence
199
- - **Supply chain indicators**: install scripts, native bindings, obfuscated code, network calls, filesystem access, process spawning, eval usage, environment variable access
200
- - **Version history analysis**: changelog risk, maintainer changes, dependency graph mutations
201
- - **Recommendation**: SAFE, CAUTION, WARN, or BLOCK
202
-
203
- Agent scores are weighted by model intelligence and coding indices sourced from the Artificial Analysis API, producing an intelligence-weighted aggregate risk score.
204
-
205
- ## Smart Contract: OPMRegistry
206
-
207
- Solidity 0.8.20, deployed on [Base Sepolia](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48). The contract implements a domain-specific form of the three-registry architecture defined by [ERC-8004 (Trustless Agents)](https://eips.ethereum.org/EIPS/eip-8004), adapted for package security rather than general-purpose agent economies.
208
-
209
- ### Key Functions
210
-
211
- | Function | Access | Description |
212
- |----------|--------|-------------|
213
- | `registerPackage` | Public | Register a new package version with checksum, signature, and ENS binding |
214
- | `submitScore` | Authorized agents | Submit a risk score (0-100) and reasoning string for a package version |
215
- | `setReportURI` | Authorized agents | Attach a Fileverse report URI to a package version |
216
- | `registerAgent` | Public | Permissionless agent registration with ZK proof hash |
217
- | `revokeAgent` | Owner | Deactivate a registered agent |
218
- | `getAggregateScore` | View | Compute mean risk score across all agent submissions |
219
- | `getSafestVersion` | View | Return the lowest-risk version within a configurable lookback window |
220
- | `getScores` | View | Return all individual agent scores for a version |
221
- | `getPackageInfo` | View | Retrieve full metadata and aggregate score for a package version |
222
- | `getRegisteredAgent` | View | Retrieve registered agent details |
223
- | `getAgentCount` | View | Total number of registered agents |
224
-
225
- ### On-chain Activity
226
-
227
- Every transaction is surfaced in the terminal UI with clickable BaseScan links:
228
-
229
- - **Score submissions**: Each agent's `submitScore` tx → `https://sepolia.basescan.org/tx/{hash}`
230
- - **Package registration**: `registerPackage` tx → clickable link
231
- - **Agent registration**: `registerAgent` tx → clickable link
232
- - **Contract reference**: Direct link to the OPM Registry contract
233
-
234
- ### Risk Thresholds
235
-
236
- | Threshold | Value | Effect |
237
- |-----------|-------|--------|
238
- | `HIGH_RISK_THRESHOLD` | 70 | Packages above this score trigger warnings |
239
- | `MEDIUM_RISK_THRESHOLD` | 40 | Packages above this score are flagged for caution |
240
- | Critical gate (CLI) | 80 | `opm push` blocks publication; `opm install` blocks installation |
66
+ Scores are weighted by model intelligence + coding index from the Artificial Analysis API. Anyone can register additional agents permissionlessly via ZK-verified benchmarks.
241
67
 
242
- ## Website
68
+ ## Smart Contract
243
69
 
244
- Landing page built with Next.js + Tailwind CSS.
70
+ `OPMRegistry.sol` on [Base Sepolia](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48).
245
71
 
246
- ```bash
247
- cd packages/web
248
- npm install
249
- npm run dev # Development at http://localhost:3000
250
- npm run build # Production build
251
- npm start # Start production server
252
- ```
72
+ | Function | What it does |
73
+ |----------|-------------|
74
+ | `registerPackage` | Store version checksum, signature, ENS binding |
75
+ | `submitScore` | Agent submits risk score + reasoning |
76
+ | `setReportURI` | Attach Fileverse report link |
77
+ | `registerAgent` | Permissionless agent registration with ZK proof hash |
78
+ | `getSafestVersion` | Lowest-risk version in lookback window |
79
+ | `getPackageInfo` | Full metadata + aggregate score |
253
80
 
254
- For Railway/Vercel deployment: set the root directory to `packages/web` and use `npm install && npm run build` as the build command.
81
+ Every transaction surfaces as a clickable BaseScan link in the terminal.
255
82
 
256
- ## Documentation (Mintlify)
83
+ ## ENS Integration
257
84
 
258
- Full documentation is in the `docs/` directory, configured for [Mintlify](https://mintlify.com).
85
+ Package metadata is written to ENS text records on the author's name:
259
86
 
260
- ### Setup
87
+ `url` · `opm.version` · `opm.checksum` · `opm.fileverse` · `opm.risk_score` · `opm.packages` · `opm.signature` · `opm.contract`
261
88
 
262
- ```bash
263
- npm i -g mintlify
264
- cd docs
265
- mintlify dev
266
- ```
89
+ Per-package records: `opm.pkg.<name>.version`, `opm.pkg.<name>.checksum`, etc.
267
90
 
268
- Opens at `http://localhost:3333`. The docs cover:
91
+ Contenthash is set to the Fileverse IPFS CID (read directly from the Fileverse Portal smart contract on-chain).
269
92
 
270
- - **Getting Started**: Introduction, Quickstart, Configuration
271
- - **Core Concepts**: Security Model, Multi-Agent Consensus, On-chain Registry, ZK Agent Verification
272
- - **CLI Reference**: All commands with usage, flags, and examples
273
- - **Smart Contract**: Functions, Events, Deployment
274
- - **Architecture**: Scanner engine, Agent system, Benchmark suite
275
-
276
- ### Deploy to Mintlify
277
-
278
- Push your repo to GitHub and connect it to [Mintlify](https://mintlify.com/start) — it auto-deploys from the `docs/` directory.
93
+ Install with ENS: `opm install express@djpai.eth` resolves the author, verifies they're registered, and installs the safest on-chain version.
279
94
 
280
95
  ## Project Structure
281
96
 
282
97
  ```
283
98
  packages/
284
- core/ Shared types, constants, ABI, prompt schemas, model rankings, benchmarks
285
- contracts/ OPMRegistry.sol, Hardhat config, deployment scripts, tests
286
- circuits/ Circom ZK circuit for accuracy verification
287
- scanner/ AI agent runner, LLM client, queue, Fileverse, benchmark runner, ZK verifier
288
- cli/ Ink-based terminal UI
289
- commands/ push, install, check, fix, audit, info, author-view, register-agent, passthrough
290
- components/ Header, StatusLine, RiskBadge, Hyperlink, PackageCard, AuthorInfo, AgentScores
291
- services/ contract, ens, osv, signature, chainpatrol, fileverse, avatar, typosquat, version
292
- web/ Next.js landing page (dark mode, Tailwind CSS)
293
- docs/ Mintlify documentation (mint.json + MDX pages)
99
+ core/ Types, constants, ABI, prompts, model rankings, benchmarks
100
+ contracts/ OPMRegistry.sol, Hardhat config, Circom ZK circuit
101
+ scanner/ AI agent runner, LLM client, Fileverse upload, ZK verifier
102
+ cli/ Ink terminal UI, commands, services
103
+ web/ Next.js landing page
104
+ docs/ Mintlify documentation
294
105
  ```
295
106
 
296
107
  ## Environment Variables
297
108
 
298
- Client-side commands (`install`, `check`, `fix`, `audit`, `info`, `view`, `whois`) operate with zero configuration.
109
+ **Required for `opm push`:**
299
110
 
300
- Author-side commands (`push`) require the following:
301
-
302
- | Variable | Description |
303
- |----------|-------------|
304
- | `OPM_SIGNING_KEY` | Ethereum private key for ECDSA package signing |
305
- | `AGENT_PRIVATE_KEY` | Agent wallet private key (funds on-chain score submission gas) |
306
- | `NPM_TOKEN` | npm automation token (alternative to `--token` CLI flag) |
307
- | `OPENAI_API_KEY` | OpenAI API key; selects GPT-4.1 / Mini / Nano agents |
308
- | `OPENROUTER_API_KEY` | OpenRouter API key; enables Claude, Gemini, DeepSeek model diversity |
309
- | `FILEVERSE_API_KEY` | Fileverse API key (generate at ddocs.new, Settings, Developer Mode) |
310
-
311
- Agent registration (`register-agent`) requires:
312
-
313
- | Variable | Description |
314
- |----------|-------------|
315
- | `AGENT_PRIVATE_KEY` | Wallet that becomes the agent identity on-chain |
316
- | `OPENROUTER_API_KEY` or `OPENAI_API_KEY` | Required to run LLM benchmark calls |
111
+ | Variable | Purpose |
112
+ |----------|---------|
113
+ | `OPM_SIGNING_KEY` | Ethereum private key for package signing |
114
+ | `AGENT_PRIVATE_KEY` | Agent wallet for on-chain score submission |
115
+ | `OPENROUTER_API_KEY` or `OPENAI_API_KEY` | LLM access for AI agents |
116
+ | `FILEVERSE_API_KEY` | Report storage ([ddocs.new](https://ddocs.new) Settings Developer Mode) |
317
117
 
318
- Optional overrides (defaults are compiled in):
118
+ **Optional:**
319
119
 
320
120
  | Variable | Default |
321
121
  |----------|---------|
122
+ | `NPM_TOKEN` | npm automation token |
322
123
  | `CONTRACT_ADDRESS` | `0x16684391fc9bf48246B08Afe16d1a57BFa181d48` |
323
- | `BASE_SEPOLIA_RPC_URL` | `https://sepolia.base.org` |
324
- | `CHAINPATROL_API_KEY` | Optional; enables blocklist checks |
325
- | `ARTIFICIAL_ANALYSIS_API_KEY` | Optional; enables intelligence-weighted scoring |
124
+ | `CHAINPATROL_API_KEY` | Blocklist checks |
326
125
 
327
- ## Testing
126
+ Client commands (`install`, `check`, `info`, `view`) work with zero config.
328
127
 
329
- ### Contract Tests
128
+ ## Fileverse Setup
330
129
 
331
130
  ```bash
332
- cd packages/contracts && npx hardhat test
131
+ npx @fileverse/api --apiKey <YOUR_API_KEY>
333
132
  ```
334
133
 
335
- ### Standalone Scanner
336
-
337
- ```bash
338
- bun run scan -- <package-name> <version>
339
- ```
134
+ Runs at `http://localhost:8001`. Reports are encrypted, synced to IPFS, and the content hash is stored on the Fileverse Portal smart contract.
340
135
 
341
136
  ## Links
342
137
 
343
138
  - **npm**: [npmjs.com/package/opmsec](https://www.npmjs.com/package/opmsec)
344
139
  - **GitHub**: [github.com/dhananjaypai08/opm](https://github.com/dhananjaypai08/opm)
345
140
  - **Contract**: [BaseScan](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
141
+ - **Docs**: [Mintlify](https://mintlify.com)
346
142
 
347
143
  ## License
348
144
 
package/bun.lock CHANGED
@@ -10,12 +10,12 @@
10
10
  "ethers": "^6.13.0",
11
11
  "ink": "^5.2.1",
12
12
  "react": "^18.3.1",
13
- "react-devtools-core": "^5.3.2",
13
+ "react-devtools-core": "^7.0.1",
14
14
  "terminal-image": "^4.2.0",
15
15
  "viem": "^2.47.4",
16
16
  },
17
17
  "devDependencies": {
18
- "bun-types": "^1.3.10",
18
+ "bun-types": "latest",
19
19
  },
20
20
  },
21
21
  "packages/cli": {
@@ -347,7 +347,7 @@
347
347
 
348
348
  "react": ["react@18.3.1", "", { "dependencies": { "loose-envify": "^1.1.0" } }, "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ=="],
349
349
 
350
- "react-devtools-core": ["react-devtools-core@5.3.2", "", { "dependencies": { "shell-quote": "^1.6.1", "ws": "^7" } }, "sha512-crr9HkVrDiJ0A4zot89oS0Cgv0Oa4OG1Em4jit3P3ZxZSKPMYyMjfwMqgcJna9o625g8oN87rBm8SWWrSTBZxg=="],
350
+ "react-devtools-core": ["react-devtools-core@7.0.1", "", { "dependencies": { "shell-quote": "^1.6.1", "ws": "^7" } }, "sha512-C3yNvRHaizlpiASzy7b9vbnBGLrhvdhl1CbdU6EnZgxPNbai60szdLtl+VL76UNOt5bOoVTOz5rNWZxgGt+Gsw=="],
351
351
 
352
352
  "react-reconciler": ["react-reconciler@0.29.2", "", { "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.2" }, "peerDependencies": { "react": "^18.3.1" } }, "sha512-zZQqIiYgDCTP/f1N/mAR10nJGrPD2ZR+jDSEsKWJHYC7Cm2wodlwbR3upZRdC3cjIjSlTLNVyO7Iu0Yy7t2AYg=="],
353
353
 
@@ -1,77 +1,29 @@
1
1
  ---
2
2
  title: 'Agent Architecture'
3
- description: 'Agent config, base agent, prompts, and model ranking.'
3
+ description: 'Agent config, LLM flow, prompts, and model ranking.'
4
4
  ---
5
5
 
6
6
  # Agent Architecture
7
7
 
8
8
  Security agents are LLM-powered analyzers that score packages and submit results on-chain.
9
9
 
10
- ## AgentConfig
10
+ ## Agent Flow
11
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
- ```
12
+ 1. **Fetch data** — Package metadata and source from npm (or local tarball)
13
+ 2. **Query OSV** — Known CVEs for the package and version
14
+ 3. **Call LLM** System prompt + user prompt → structured JSON response
15
+ 4. **Submit on-chain** — `OPMRegistry.submitScore()` with the agent wallet
18
16
 
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>.
17
+ ## Prompts
20
18
 
21
- ## Base Agent Flow
19
+ The **system prompt** defines a security auditor persona and enforces a JSON output schema: risk score (0-100), risk level, reasoning, vulnerability list.
22
20
 
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
21
+ The **user prompt** includes package metadata, version history, extracted source code (size-limited), and any known CVEs.
55
22
 
56
23
  ## Model Ranking
57
24
 
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>
25
+ When `ARTIFICIAL_ANALYSIS_API_KEY` is set, model Intelligence Index and Coding Index are fetched and used as weights for score aggregation. Without it, equal weighting applies.
68
26
 
69
27
  ## Extensibility
70
28
 
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.
29
+ New agents register permissionlessly via `opm register-agent` — pass 10 benchmarks with 100% accuracy, generate a ZK proof, and the agent participates in all future scans.
@@ -5,61 +5,35 @@ description: '10 labeled test cases for agent verification.'
5
5
 
6
6
  # Benchmark Suite
7
7
 
8
- The benchmark suite validates agent accuracy before permissionless registration. Agents must achieve **100% accuracy** and produce a valid ZK proof.
8
+ Validates agent accuracy before permissionless registration. Agents must score **100% accuracy** and produce a valid ZK proof.
9
9
 
10
- ## Test Case Structure
10
+ ## Test Cases
11
11
 
12
- Each benchmark case includes:
12
+ Each case includes: package metadata, version history, source files, known CVEs, and expected output (risk level + score range).
13
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 |
14
+ | Category | Cases | Description |
27
15
  |----------|-------|-------------|
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 |
16
+ | Clean | 3 | Legitimate packages (string utils, math, validator) |
17
+ | Typosquat | 1 | Lodash typosquat with credential exfil in postinstall |
18
+ | Malicious | 2 | Postinstall shell execution, SSH key exfiltration |
19
+ | CVE | 1 | Known prototype pollution vulnerability |
20
+ | Obfuscated | 1 | Heavily obfuscated reverse shell |
21
+ | Exfiltration | 1 | Env var exfiltration on import |
22
+ | Dependency confusion | 1 | Internal scope shadowing with DNS exfil |
35
23
 
36
24
  ## Evaluation
37
25
 
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
26
+ Each case is checked against:
52
27
 
53
- ## Circom Circuit
28
+ 1. **Score range** — `actualScore` within `[min_risk_score, max_risk_score]`
29
+ 2. **Risk level** — For non-LOW cases, actual level within ±1 of expected ordinal
54
30
 
55
- The circuit <code>AccuracyVerifier(10)</code> in <code>packages/contracts/circuits/accuracy_verifier.circom</code>:
31
+ A case passes only if both checks succeed.
56
32
 
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
33
+ ## ZK Proof
60
34
 
61
- Uses Poseidon hashing and IsEqual comparators from circomlib.
35
+ 1. **Commit** — Poseidon hash of (salt, expected[0..9]) `commitmentHash`
36
+ 2. **Prove** — Circuit verifies `expected[i] == actual[i]` for all i, outputs `passed` and `proofHash`
37
+ 3. **Store** — `keccak256(proof)` stored on-chain via `registerAgent()`
62
38
 
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>
39
+ Test data stays private — future agents can't game the benchmark.