opmsec 0.1.0 → 0.1.4

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 (152) hide show
  1. package/.env.example +23 -13
  2. package/.husky/pre-commit +1 -0
  3. package/README.md +256 -173
  4. package/bun.lock +4 -4
  5. package/docs/architecture/agents.mdx +77 -0
  6. package/docs/architecture/benchmarks.mdx +65 -0
  7. package/docs/architecture/overview.mdx +58 -0
  8. package/docs/architecture/scanner.mdx +53 -0
  9. package/docs/cli/audit.mdx +35 -0
  10. package/docs/cli/check.mdx +44 -0
  11. package/docs/cli/fix.mdx +49 -0
  12. package/docs/cli/info.mdx +44 -0
  13. package/docs/cli/install.mdx +71 -0
  14. package/docs/cli/push.mdx +99 -0
  15. package/docs/cli/register-agent.mdx +80 -0
  16. package/docs/cli/view.mdx +52 -0
  17. package/docs/concepts/multi-agent-consensus.mdx +58 -0
  18. package/docs/concepts/on-chain-registry.mdx +74 -0
  19. package/docs/concepts/security-model.mdx +76 -0
  20. package/docs/concepts/zk-agent-verification.mdx +82 -0
  21. package/docs/configuration.mdx +82 -0
  22. package/docs/contract/deployment.mdx +57 -0
  23. package/docs/contract/events.mdx +115 -0
  24. package/docs/contract/functions.mdx +220 -0
  25. package/docs/contract/overview.mdx +58 -0
  26. package/docs/favicon.svg +5 -0
  27. package/docs/introduction.mdx +43 -0
  28. package/docs/logo/dark.svg +5 -0
  29. package/docs/logo/light.svg +5 -0
  30. package/docs/mint.json +106 -0
  31. package/docs/quickstart.mdx +133 -0
  32. package/package.json +7 -6
  33. package/packages/cli/src/commands/author-view.tsx +9 -1
  34. package/packages/cli/src/commands/check.tsx +318 -0
  35. package/packages/cli/src/commands/fix.tsx +294 -0
  36. package/packages/cli/src/commands/install.tsx +501 -47
  37. package/packages/cli/src/commands/push.tsx +53 -22
  38. package/packages/cli/src/commands/register-agent.tsx +227 -0
  39. package/packages/cli/src/components/AgentScores.tsx +20 -6
  40. package/packages/cli/src/components/Hyperlink.tsx +30 -0
  41. package/packages/cli/src/components/ScanReport.tsx +3 -2
  42. package/packages/cli/src/index.tsx +44 -6
  43. package/packages/cli/src/services/avatar.ts +43 -6
  44. package/packages/cli/src/services/chainpatrol.ts +20 -17
  45. package/packages/cli/src/services/contract.ts +41 -8
  46. package/packages/cli/src/services/ens.ts +3 -5
  47. package/packages/cli/src/services/fileverse.ts +12 -13
  48. package/packages/cli/src/services/typosquat.ts +166 -0
  49. package/packages/cli/src/services/version.ts +156 -5
  50. package/packages/contracts/circuits/accuracy_verifier.circom +101 -0
  51. package/packages/contracts/contracts/OPMRegistry.sol +63 -0
  52. package/packages/contracts/scripts/deploy.ts +22 -3
  53. package/packages/core/src/abi.ts +221 -0
  54. package/packages/core/src/benchmarks.ts +450 -0
  55. package/packages/core/src/constants.ts +20 -0
  56. package/packages/core/src/index.ts +2 -0
  57. package/packages/core/src/model-rankings.ts +115 -0
  58. package/packages/core/src/prompt.ts +58 -0
  59. package/packages/core/src/types.ts +41 -0
  60. package/packages/core/src/utils.ts +142 -3
  61. package/packages/scanner/src/agents/base-agent.ts +13 -3
  62. package/packages/scanner/src/index.ts +5 -2
  63. package/packages/scanner/src/queue/memory-queue.ts +8 -3
  64. package/packages/scanner/src/services/benchmark-runner.ts +114 -0
  65. package/packages/scanner/src/services/contract-writer.ts +2 -3
  66. package/packages/scanner/src/services/fileverse.ts +26 -7
  67. package/packages/scanner/src/services/openrouter.ts +61 -4
  68. package/packages/scanner/src/services/report-formatter.ts +122 -3
  69. package/packages/scanner/src/services/zk-verifier.ts +118 -0
  70. package/packages/web/.next/BUILD_ID +1 -0
  71. package/packages/web/.next/app-build-manifest.json +26 -0
  72. package/packages/web/.next/app-path-routes-manifest.json +4 -0
  73. package/packages/web/.next/build-manifest.json +33 -0
  74. package/packages/web/.next/diagnostics/build-diagnostics.json +6 -0
  75. package/packages/web/.next/diagnostics/framework.json +1 -0
  76. package/packages/web/.next/export-marker.json +6 -0
  77. package/packages/web/.next/images-manifest.json +58 -0
  78. package/packages/web/.next/next-minimal-server.js.nft.json +1 -0
  79. package/packages/web/.next/next-server.js.nft.json +1 -0
  80. package/packages/web/.next/package.json +1 -0
  81. package/packages/web/.next/prerender-manifest.json +61 -0
  82. package/packages/web/.next/react-loadable-manifest.json +1 -0
  83. package/packages/web/.next/required-server-files.json +320 -0
  84. package/packages/web/.next/routes-manifest.json +53 -0
  85. package/packages/web/.next/server/app/_not-found/page.js +2 -0
  86. package/packages/web/.next/server/app/_not-found/page.js.nft.json +1 -0
  87. package/packages/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  88. package/packages/web/.next/server/app/_not-found.html +1 -0
  89. package/packages/web/.next/server/app/_not-found.meta +8 -0
  90. package/packages/web/.next/server/app/_not-found.rsc +16 -0
  91. package/packages/web/.next/server/app/index.html +1 -0
  92. package/packages/web/.next/server/app/index.meta +7 -0
  93. package/packages/web/.next/server/app/index.rsc +20 -0
  94. package/packages/web/.next/server/app/page.js +2 -0
  95. package/packages/web/.next/server/app/page.js.nft.json +1 -0
  96. package/packages/web/.next/server/app/page_client-reference-manifest.js +1 -0
  97. package/packages/web/.next/server/app-paths-manifest.json +4 -0
  98. package/packages/web/.next/server/chunks/611.js +6 -0
  99. package/packages/web/.next/server/chunks/778.js +30 -0
  100. package/packages/web/.next/server/functions-config-manifest.json +4 -0
  101. package/packages/web/.next/server/interception-route-rewrite-manifest.js +1 -0
  102. package/packages/web/.next/server/middleware-build-manifest.js +1 -0
  103. package/packages/web/.next/server/middleware-manifest.json +6 -0
  104. package/packages/web/.next/server/middleware-react-loadable-manifest.js +1 -0
  105. package/packages/web/.next/server/next-font-manifest.js +1 -0
  106. package/packages/web/.next/server/next-font-manifest.json +1 -0
  107. package/packages/web/.next/server/pages/404.html +1 -0
  108. package/packages/web/.next/server/pages/500.html +1 -0
  109. package/packages/web/.next/server/pages/_app.js +1 -0
  110. package/packages/web/.next/server/pages/_app.js.nft.json +1 -0
  111. package/packages/web/.next/server/pages/_document.js +1 -0
  112. package/packages/web/.next/server/pages/_document.js.nft.json +1 -0
  113. package/packages/web/.next/server/pages/_error.js +19 -0
  114. package/packages/web/.next/server/pages/_error.js.nft.json +1 -0
  115. package/packages/web/.next/server/pages-manifest.json +6 -0
  116. package/packages/web/.next/server/server-reference-manifest.js +1 -0
  117. package/packages/web/.next/server/server-reference-manifest.json +1 -0
  118. package/packages/web/.next/server/webpack-runtime.js +1 -0
  119. package/packages/web/.next/static/2XIFCTTKVZwN_RsNE-Rrr/_buildManifest.js +1 -0
  120. package/packages/web/.next/static/2XIFCTTKVZwN_RsNE-Rrr/_ssgManifest.js +1 -0
  121. package/packages/web/.next/static/chunks/255-0dc49b7a6e8e5c05.js +1 -0
  122. package/packages/web/.next/static/chunks/4bd1b696-382748cc942d8a14.js +1 -0
  123. package/packages/web/.next/static/chunks/app/_not-found/page-0da542be7eb33a64.js +1 -0
  124. package/packages/web/.next/static/chunks/app/layout-28a489fb4398663f.js +1 -0
  125. package/packages/web/.next/static/chunks/app/page-e58ccdb78625bce6.js +1 -0
  126. package/packages/web/.next/static/chunks/framework-ac73abd125e371fe.js +1 -0
  127. package/packages/web/.next/static/chunks/main-app-dd261207182e5a23.js +1 -0
  128. package/packages/web/.next/static/chunks/main-ee293fa6aa18bdd1.js +1 -0
  129. package/packages/web/.next/static/chunks/pages/_app-7d307437aca18ad4.js +1 -0
  130. package/packages/web/.next/static/chunks/pages/_error-cb2a52f75f2162e2.js +1 -0
  131. package/packages/web/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  132. package/packages/web/.next/static/chunks/webpack-e1ae44446e7f7355.js +1 -0
  133. package/packages/web/.next/static/css/21d69157e271f2ab.css +3 -0
  134. package/packages/web/.next/trace +2 -0
  135. package/packages/web/.next/types/app/layout.ts +84 -0
  136. package/packages/web/.next/types/app/page.ts +84 -0
  137. package/packages/web/.next/types/cache-life.d.ts +141 -0
  138. package/packages/web/.next/types/package.json +1 -0
  139. package/packages/web/.next/types/routes.d.ts +57 -0
  140. package/packages/web/.next/types/validator.ts +61 -0
  141. package/packages/web/app/globals.css +75 -0
  142. package/packages/web/app/layout.tsx +26 -0
  143. package/packages/web/app/page.tsx +361 -0
  144. package/packages/web/bun.lock +300 -0
  145. package/packages/web/next-env.d.ts +6 -0
  146. package/packages/web/next.config.ts +5 -0
  147. package/packages/web/package.json +26 -0
  148. package/packages/web/postcss.config.mjs +8 -0
  149. package/packages/web/public/favicon.svg +5 -0
  150. package/packages/web/public/logo.svg +7 -0
  151. package/packages/web/tailwind.config.ts +48 -0
  152. package/packages/web/tsconfig.json +21 -0
package/.env.example CHANGED
@@ -1,14 +1,24 @@
1
- OPM_PRIVATE_KEY=
2
- AGENT_PRIVATE_KEY=
3
- # Set ONE of these (OPENAI_API_KEY auto-uses gpt-4.1 variants, OPENROUTER_API_KEY uses multi-model)
1
+ # ── CLIENT ──
2
+ # opm install/audit/info/view work out of the box with ZERO config.
3
+ # All RPCs, contract address, and API defaults are hardcoded.
4
+
5
+ # ── AUTHOR (required only for opm push) ──
6
+ OPM_SIGNING_KEY= # Ethereum private key for package signing
7
+ AGENT_PRIVATE_KEY= # Agent wallet key for on-chain score submission
8
+ NPM_TOKEN= # npm automation token (bypasses 2FA)
9
+
10
+ # AI scanning — set at least ONE:
4
11
  OPENAI_API_KEY=
5
- # OPENROUTER_API_KEY=
6
- CHAINPATROL_API_KEY=
7
- BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
8
- ETH_SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
9
- ETH_MAINNET_RPC_URL=https://eth.llamarpc.com
10
- CONTRACT_ADDRESS=
11
- FILEVERSE_API_KEY=
12
- FILEVERSE_API_URL=http://localhost:8001
13
- # npm automation token (bypasses 2FA for opm push)
14
- # NPM_TOKEN=
12
+ # OPENROUTER_API_KEY= # enables diverse models (Claude, Gemini, DeepSeek)
13
+
14
+ # Fileverse dDocs — report storage
15
+ FILEVERSE_API_KEY= # from ddocs.new → Settings → Developer Mode
16
+
17
+ # ── OPTIONAL (sensible defaults baked in) ──
18
+ # CONTRACT_ADDRESS=0x16684391fc9bf48246B08Afe16d1a57BFa181d48
19
+ # BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
20
+ # ETH_MAINNET_RPC_URL=https://eth.llamarpc.com
21
+ # ETH_SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
22
+ # FILEVERSE_API_URL=http://localhost:8001
23
+ # CHAINPATROL_API_KEY= # optional, for blocklist checks
24
+ # ARTIFICIAL_ANALYSIS_API_KEY= # optional, for model-weighted scoring
@@ -0,0 +1 @@
1
+ cd packages/web && bun run build
package/README.md CHANGED
@@ -1,266 +1,349 @@
1
- # OPM On-chain Package Manager
1
+ # OPM: On-chain Package Manager
2
2
 
3
- A security-first CLI wrapper around npm that brings on-chain verification, multi-agent AI scanning, and decentralized audit trails to the JavaScript package ecosystem.
3
+ [![npm](https://img.shields.io/npm/v/opmsec)](https://www.npmjs.com/package/opmsec)
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)
4
6
 
5
- Authors sign packages with Ethereum keys. Three AI agents scan every publish in parallel and submit structured risk scores to a smart contract on Base Sepolia. Scan reports are stored as encrypted documents on Fileverse dDocs. Consumers verify signatures, check CVE databases, and consult on-chain scores before installing.
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.
6
8
 
7
- ## Setup
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.
8
10
 
9
- ### Prerequisites
11
+ ## System Overview
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.
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
10
65
 
11
66
  - [Bun](https://bun.sh) >= 1.2
12
67
  - Node.js >= 20
13
- - An Ethereum wallet with Base Sepolia ETH (for gas)
68
+ - Ethereum wallet funded with Base Sepolia ETH (required for gas during `opm push`)
14
69
 
15
- ### Install Dependencies
70
+ ## Installation
16
71
 
17
72
  ```bash
18
- git clone <repo> && cd opm
73
+ git clone https://github.com/dhananjaypai08/opm.git && cd opm
19
74
  cp .env.example .env
20
- # Fill in your keys (see Environment Variables below)
21
75
  bun install
76
+ bun link
22
77
  ```
23
78
 
24
- ### Link CLI Globally
79
+ Or install from npm:
25
80
 
26
81
  ```bash
27
- bun link
82
+ npm i -g opmsec
28
83
  ```
29
84
 
30
- This registers `opm` as a global command.
85
+ The `bun link` command registers `opm` as a globally available CLI binary.
31
86
 
32
- ### Deploy Contract
87
+ ## Smart Contract Deployment
33
88
 
34
89
  ```bash
35
90
  cd packages/contracts
36
91
  npm install
37
92
  npx hardhat compile
38
93
  npx hardhat run scripts/deploy.ts --network baseSepolia
39
- # Copy the deployed address to .env as CONTRACT_ADDRESS
40
94
  ```
41
95
 
42
- ### Fileverse Setup
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`.
43
97
 
44
- OPM stores formatted security reports on Fileverse dDocs (encrypted, on-chain synced).
98
+ The contract is live on Base Sepolia: [`0x16684391fc9bf48246B08Afe16d1a57BFa181d48`](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
45
99
 
46
- 1. Go to [ddocs.new](https://ddocs.new) → Settings → Developer Mode → Generate API key
47
- 2. Add the key to `.env` as `FILEVERSE_API_KEY`
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`.
48
106
  3. Start the local Fileverse API server:
49
107
 
50
108
  ```bash
51
- npx @fileverse/api --apiKey YOUR_API_KEY
109
+ npx @fileverse/api --apiKey <YOUR_API_KEY>
52
110
  ```
53
111
 
54
- The server runs on `http://localhost:8001` by default.
112
+ The server binds to `http://localhost:8001` by default. This is configurable via `FILEVERSE_API_URL`.
55
113
 
56
- ## Architecture
114
+ ## Commands
115
+
116
+ ### Security Commands
117
+
118
+ | Command | Description |
119
+ |---------|-------------|
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) |
138
+
139
+ ### npm Passthrough
140
+
141
+ All standard npm commands are forwarded transparently:
57
142
 
58
143
  ```
59
- opm push
60
- ├─ Pack tarball & compute SHA-256 checksum
61
- ├─ Sign checksum with author's Ethereum key (ECDSA)
62
- ├─ Resolve ENS identity (Sepolia + Mainnet)
63
- ├─ 3 AI agents scan source code in parallel
64
- │ ├─ Risk score, vulnerabilities, supply chain indicators
65
- │ ├─ Submit scores to OPMRegistry contract
66
- │ └─ Upload styled markdown report to Fileverse dDocs
67
- ├─ BLOCK if aggregate risk >= 80 (CRITICAL)
68
- ├─ Publish to npm (with --token for automation)
69
- └─ Register package + signature + report URI on-chain
70
-
71
- opm install <pkg>
72
- ├─ Resolve version (on-chain latest or specified)
73
- ├─ Query CVE database (OSV API) — block CRITICAL, warn HIGH
74
- ├─ Look up on-chain registry (risk score, agent consensus)
75
- ├─ Verify ECDSA signature against checksum
76
- ├─ ChainPatrol fallback for unknown packages
77
- ├─ Fetch Fileverse report link
78
- └─ Install via npm if safe
79
-
80
- opm view <name.eth>
81
- ├─ Resolve ENS name → address (@ensdomains/ensjs + viem)
82
- ├─ Fetch ENS text records (avatar, bio, GitHub, Twitter)
83
- ├─ Render avatar as pixel art in terminal
84
- ├─ Query on-chain author stats (packages, reputation)
85
- └─ List all published packages with risk scores + report links
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
86
148
  ```
87
149
 
88
- ## Commands
150
+ Aliases: `i`, `add` map to `install`; `rm` maps to `uninstall`; `ls` maps to `list`.
89
151
 
90
- ### Security Commands
152
+ ## Permissionless Agent Registration
91
153
 
92
- ```bash
93
- # Sign, scan, publish, and register on-chain
94
- opm push
95
- opm push --token <npm-automation-token>
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.
96
155
 
97
- # Install with full security pipeline
98
- opm install lodash
99
- opm install lodash@4.17.21
100
- opm install # verify all deps in package.json
156
+ ### How It Works
101
157
 
102
- # Audit all dependencies against on-chain + CVE data
103
- opm audit
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.
104
166
 
105
- # Look up on-chain security info for a package
106
- opm info lodash
107
- opm info lodash@4.17.21
167
+ ### Circom Circuit
108
168
 
109
- # View an author's ENS profile, packages, and risk scores
110
- opm view djpai.eth
111
- opm whois djpai
112
- ```
169
+ A reference circom circuit (`packages/contracts/circuits/accuracy_verifier.circom`) implements the verification logic for potential on-chain proof verification:
113
170
 
114
- ### npm Passthrough
171
+ ```bash
172
+ # Compile
173
+ circom accuracy_verifier.circom --r1cs --wasm --sym -o build/
115
174
 
116
- All standard npm commands work transparently:
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"
117
178
 
118
- ```bash
119
- opm init opm run dev opm test
120
- opm start opm build opm uninstall lodash
121
- opm outdated opm update opm list
122
- opm link opm pack
179
+ # Export Solidity verifier (for on-chain verification)
180
+ snarkjs zkey export solidityverifier build/accuracy_verifier_final.zkey contracts/AccuracyVerifier.sol
123
181
  ```
124
182
 
125
- **Aliases:** `i` / `add` → install, `rm` → uninstall, `ls` → list
183
+ ## AI Agent Architecture
126
184
 
127
- ### Standalone Scanner
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.
128
186
 
129
- ```bash
130
- bun run scan -- <package-name> <version>
131
- ```
187
+ | Agent | OpenRouter (preferred) | OpenAI (fallback) |
188
+ |-------|----------------------|-------------------|
189
+ | agent-1 | Claude Sonnet 4 | GPT-4.1 |
190
+ | agent-2 | Gemini 2.5 Flash | GPT-4.1 Mini |
191
+ | agent-3 | DeepSeek Chat | GPT-4.1 Nano |
132
192
 
133
- ## npm Publishing
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`.
134
194
 
135
- OPM handles npm publish as part of `opm push`. If your npm account has 2FA enabled, use an automation token:
195
+ Each agent produces a structured JSON assessment containing:
136
196
 
137
- 1. Go to [npmjs.com](https://www.npmjs.com) Access Tokens Generate New Token → **Automation**
138
- 2. Pass it via CLI flag or environment:
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
139
202
 
140
- ```bash
141
- opm push --token npm_xxxxxxxxxxxx
142
- # or
143
- NPM_TOKEN=npm_xxxxxxxxxxxx opm push
144
- # or add NPM_TOKEN to your .env
145
- ```
203
+ Agent scores are weighted by model intelligence and coding indices sourced from the Artificial Analysis API, producing an intelligence-weighted aggregate risk score.
146
204
 
147
- The scan runs **before** publish — if the aggregate risk score is CRITICAL (>= 80), the publish and on-chain registration are blocked.
205
+ ## Smart Contract: OPMRegistry
148
206
 
149
- ## Security Pipeline
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.
150
208
 
151
- ### `opm install` Flow
209
+ ### Key Functions
152
210
 
153
- 1. **Version resolution** resolves "latest" from on-chain registry
154
- 2. **CVE database** — queries [OSV API](https://osv.dev) for known vulnerabilities; computes CVSS v3 base scores
155
- - CRITICAL CVEs installation blocked
156
- - HIGH CVEs warning displayed
157
- - Shows CVE ID, severity, summary, and suggested fix version
158
- 3. **On-chain registry** fetches agent consensus risk score
159
- 4. **Signature verification** verifies ECDSA signature against package checksum
160
- 5. **ChainPatrol** fallback blocklist check for packages not in the registry
161
- 6. **Fileverse report** links to the full AI scan report
162
- 7. **Install** runs `npm install` if all checks pass
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 |
163
224
 
164
- ### `opm push` Flow
225
+ ### On-chain Activity
165
226
 
166
- 1. **Pack & sign** SHA-256 checksum, ECDSA signature
167
- 2. **ENS resolution** — maps author address to ENS name
168
- 3. **AI security scan** — 3 agents analyze source code, metadata, and version history
169
- 4. **Risk gate** — blocks publish if score >= 80
170
- 5. **npm publish** — with token-based auth support
171
- 6. **On-chain registration** — stores checksum, signature, ENS name, and report URI
227
+ Every transaction is surfaced in the terminal UI with clickable BaseScan links:
172
228
 
173
- ## AI Agents
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
174
233
 
175
- Three models scan every package in parallel:
234
+ ### Risk Thresholds
176
235
 
177
- | Agent | OpenRouter Model | OpenAI Fallback |
178
- |-------|-----------------|-----------------|
179
- | Agent 1 | Claude Sonnet 4 | GPT-4.1 |
180
- | Agent 2 | Gemini 2.5 Flash | GPT-4.1 Mini |
181
- | Agent 3 | DeepSeek Chat | GPT-4.1 Nano |
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 |
182
241
 
183
- If `OPENROUTER_API_KEY` is set, OPM uses diverse models for better consensus. Otherwise falls back to OpenAI variants via `OPENAI_API_KEY`.
242
+ ## Website
184
243
 
185
- Each agent produces a structured JSON report covering:
186
- - Risk score (0-100) and risk level
187
- - Vulnerability analysis with CVE cross-referencing
188
- - Supply chain indicators (install scripts, obfuscation, network calls, eval usage)
189
- - Version history analysis and changelog risk assessment
244
+ Landing page built with Next.js + Tailwind CSS.
190
245
 
191
- ## ENS Integration
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
+ ```
192
253
 
193
- OPM uses the official [`@ensdomains/ensjs`](https://github.com/ensdomains/ensjs) SDK with `viem` for:
254
+ For Railway/Vercel deployment: set the root directory to `packages/web` and use `npm install && npm run build` as the build command.
194
255
 
195
- - **Address → Name** resolution across Sepolia and Mainnet
196
- - **Name → Address** resolution for author lookups
197
- - **Text record** fetching (avatar, bio, URL, GitHub, Twitter, email)
198
- - **Terminal avatar** rendering via `terminal-image` (ANSI pixel art)
199
- - **Author profiles** via `opm view <name.eth>` showing published packages and risk scores
256
+ ## Documentation (Mintlify)
200
257
 
201
- The smart contract stores ENS names alongside author addresses for on-chain identity binding.
258
+ Full documentation is in the `docs/` directory, configured for [Mintlify](https://mintlify.com).
202
259
 
203
- ## Integrations
260
+ ### Setup
204
261
 
205
- | Integration | Purpose |
206
- |-------------|---------|
207
- | **Base Sepolia** | Smart contract deployment (OPMRegistry) |
208
- | **ENS** | On-chain author identity, profile display, name resolution |
209
- | **Fileverse dDocs** | Encrypted, decentralized storage for styled security reports |
210
- | **ChainPatrol** | Fallback blocklist for packages not in the registry |
211
- | **OSV API** | Real CVE/GHSA vulnerability data with CVSS v3 scoring |
212
- | **OpenRouter / OpenAI** | Multi-model AI scanning (Claude, Gemini, DeepSeek, GPT) |
262
+ ```bash
263
+ npm i -g mintlify
264
+ cd docs
265
+ mintlify dev
266
+ ```
213
267
 
214
- ## Smart Contract
268
+ Opens at `http://localhost:3333`. The docs cover:
215
269
 
216
- `OPMRegistry.sol` on Base Sepolia:
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
217
275
 
218
- - Package registration with checksum, signature, and ENS binding
219
- - Authorized agent score submission (gas-funded agent wallets)
220
- - Fileverse report URI storage per package version
221
- - Aggregate risk scoring across agents
222
- - Safest version lookup with configurable lookback
223
- - Author reputation tracking (average score across all packages)
224
- - ENS-to-author mapping for reverse lookups
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.
225
279
 
226
280
  ## Project Structure
227
281
 
228
282
  ```
229
283
  packages/
230
- core/ Shared types, constants, ABI, prompts, utilities
231
- contracts/ OPMRegistry.sol + Hardhat config, tests, deploy script
232
- scanner/ AI agents, in-memory queue, Fileverse upload, report formatter
233
- cli/ Ink-based terminal UI
234
- commands/ push, install, audit, info, author-view, passthrough
235
- components/ Header, StatusLine, RiskBadge, PackageCard, AuthorInfo
236
- services/ contract, ens, osv, signature, chainpatrol, fileverse, avatar
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)
237
294
  ```
238
295
 
239
296
  ## Environment Variables
240
297
 
241
- | Variable | Required | Description |
242
- |----------|----------|-------------|
243
- | `OPM_PRIVATE_KEY` | Yes | Author's Ethereum private key for signing |
244
- | `AGENT_PRIVATE_KEY` | Yes | Agent wallet key for contract gas on Base Sepolia |
245
- | `CONTRACT_ADDRESS` | Yes | Deployed OPMRegistry contract address |
246
- | `OPENAI_API_KEY` | * | OpenAI API key (auto-selects gpt-4.1 variants) |
247
- | `OPENROUTER_API_KEY` | * | OpenRouter API key (multi-model: Claude, Gemini, DeepSeek) |
248
- | `CHAINPATROL_API_KEY` | Yes | ChainPatrol API key for blocklist checks |
249
- | `BASE_SEPOLIA_RPC_URL` | No | Base Sepolia RPC (default: https://sepolia.base.org) |
250
- | `ETH_MAINNET_RPC_URL` | No | Mainnet RPC for ENS (default: https://eth.llamarpc.com) |
251
- | `ETH_SEPOLIA_RPC_URL` | No | Sepolia RPC for ENS (default: public endpoint) |
252
- | `FILEVERSE_API_KEY` | Yes | Fileverse API key from ddocs.new Developer Mode |
253
- | `FILEVERSE_API_URL` | No | Fileverse local API URL (default: http://localhost:8001) |
254
- | `NPM_TOKEN` | No | npm automation token (alternative to `--token` flag) |
255
-
256
- \* One of `OPENAI_API_KEY` or `OPENROUTER_API_KEY` is required for AI scanning.
257
-
258
- ## Run Contract Tests
298
+ Client-side commands (`install`, `check`, `fix`, `audit`, `info`, `view`, `whois`) operate with zero configuration.
299
+
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 |
317
+
318
+ Optional overrides (defaults are compiled in):
319
+
320
+ | Variable | Default |
321
+ |----------|---------|
322
+ | `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 |
326
+
327
+ ## Testing
328
+
329
+ ### Contract Tests
259
330
 
260
331
  ```bash
261
332
  cd packages/contracts && npx hardhat test
262
333
  ```
263
334
 
335
+ ### Standalone Scanner
336
+
337
+ ```bash
338
+ bun run scan -- <package-name> <version>
339
+ ```
340
+
341
+ ## Links
342
+
343
+ - **npm**: [npmjs.com/package/opmsec](https://www.npmjs.com/package/opmsec)
344
+ - **GitHub**: [github.com/dhananjaypai08/opm](https://github.com/dhananjaypai08/opm)
345
+ - **Contract**: [BaseScan](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
346
+
264
347
  ## License
265
348
 
266
349
  MIT
package/bun.lock CHANGED
@@ -12,10 +12,10 @@
12
12
  "react": "^18.3.1",
13
13
  "react-devtools-core": "^5.3.2",
14
14
  "terminal-image": "^4.2.0",
15
- "viem": "^2.47.2",
15
+ "viem": "^2.47.4",
16
16
  },
17
17
  "devDependencies": {
18
- "bun-types": "latest",
18
+ "bun-types": "^1.3.10",
19
19
  },
20
20
  },
21
21
  "packages/cli": {
@@ -317,7 +317,7 @@
317
317
 
318
318
  "opm": ["opm@workspace:packages/cli"],
319
319
 
320
- "ox": ["ox@0.14.0", "", { "dependencies": { "@adraffy/ens-normalize": "^1.11.0", "@noble/ciphers": "^1.3.0", "@noble/curves": "1.9.1", "@noble/hashes": "^1.8.0", "@scure/bip32": "^1.7.0", "@scure/bip39": "^1.6.0", "abitype": "^1.2.3", "eventemitter3": "5.0.1" }, "peerDependencies": { "typescript": ">=5.4.0" }, "optionalPeers": ["typescript"] }, "sha512-WLOB7IKnmI3Ol6RAqY7CJdZKl8QaI44LN91OGF1061YIeN6bL5IsFcdp7+oQShRyamE/8fW/CBRWhJAOzI35Dw=="],
320
+ "ox": ["ox@0.14.5", "", { "dependencies": { "@adraffy/ens-normalize": "^1.11.0", "@noble/ciphers": "^1.3.0", "@noble/curves": "1.9.1", "@noble/hashes": "^1.8.0", "@scure/bip32": "^1.7.0", "@scure/bip39": "^1.6.0", "abitype": "^1.2.3", "eventemitter3": "5.0.1" }, "peerDependencies": { "typescript": ">=5.4.0" }, "optionalPeers": ["typescript"] }, "sha512-HgmHmBveYO40H/R3K6TMrwYtHsx/u6TAB+GpZlgJCoW0Sq5Ttpjih0IZZiwGQw7T6vdW4IAyobYrE2mdAvyF8Q=="],
321
321
 
322
322
  "pako": ["pako@2.1.0", "", {}, "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug=="],
323
323
 
@@ -427,7 +427,7 @@
427
427
 
428
428
  "utif2": ["utif2@4.1.0", "", { "dependencies": { "pako": "^1.0.11" } }, "sha512-+oknB9FHrJ7oW7A2WZYajOcv4FcDR4CfoGB0dPNfxbi4GO05RRnFmt5oa23+9w32EanrYcSJWspUiJkLMs+37w=="],
429
429
 
430
- "viem": ["viem@2.47.2", "", { "dependencies": { "@noble/curves": "1.9.1", "@noble/hashes": "1.8.0", "@scure/bip32": "1.7.0", "@scure/bip39": "1.6.0", "abitype": "1.2.3", "isows": "1.0.7", "ox": "0.14.0", "ws": "8.18.3" }, "peerDependencies": { "typescript": ">=5.0.4" }, "optionalPeers": ["typescript"] }, "sha512-etDIwDgmDiGaPg8rUbJtUFuC3/nAJCbhMYyfh5dOcqNNkzBWTNcS2VluPSM5JVo+9U3b2hle2RkBEq3+xyvlvg=="],
430
+ "viem": ["viem@2.47.4", "", { "dependencies": { "@noble/curves": "1.9.1", "@noble/hashes": "1.8.0", "@scure/bip32": "1.7.0", "@scure/bip39": "1.6.0", "abitype": "1.2.3", "isows": "1.0.7", "ox": "0.14.5", "ws": "8.18.3" }, "peerDependencies": { "typescript": ">=5.0.4" }, "optionalPeers": ["typescript"] }, "sha512-h0Wp/SYmJO/HB4B/em1OZ3W1LaKrmr7jzaN7talSlZpo0LCn0V6rZ5g923j6sf4VUSrqp/gUuWuHFc7UcoIp8A=="],
431
431
 
432
432
  "which": ["which@2.0.2", "", { "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "./bin/node-which" } }, "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA=="],
433
433