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
package/.env.example
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
#
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#
|
|
14
|
-
#
|
|
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
|
package/README.md
CHANGED
|
@@ -1,266 +1,349 @@
|
|
|
1
|
-
# OPM
|
|
1
|
+
# OPM: On-chain Package Manager
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/opmsec)
|
|
4
|
+
[](https://github.com/dhananjaypai08/opm)
|
|
5
|
+
[](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
|
|
4
6
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
68
|
+
- Ethereum wallet funded with Base Sepolia ETH (required for gas during `opm push`)
|
|
14
69
|
|
|
15
|
-
|
|
70
|
+
## Installation
|
|
16
71
|
|
|
17
72
|
```bash
|
|
18
|
-
git clone
|
|
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
|
-
|
|
79
|
+
Or install from npm:
|
|
25
80
|
|
|
26
81
|
```bash
|
|
27
|
-
|
|
82
|
+
npm i -g opmsec
|
|
28
83
|
```
|
|
29
84
|
|
|
30
|
-
|
|
85
|
+
The `bun link` command registers `opm` as a globally available CLI binary.
|
|
31
86
|
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
+
The contract is live on Base Sepolia: [`0x16684391fc9bf48246B08Afe16d1a57BFa181d48`](https://sepolia.basescan.org/address/0x16684391fc9bf48246B08Afe16d1a57BFa181d48)
|
|
45
99
|
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
112
|
+
The server binds to `http://localhost:8001` by default. This is configurable via `FILEVERSE_API_URL`.
|
|
55
113
|
|
|
56
|
-
##
|
|
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
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
150
|
+
Aliases: `i`, `add` map to `install`; `rm` maps to `uninstall`; `ls` maps to `list`.
|
|
89
151
|
|
|
90
|
-
|
|
152
|
+
## Permissionless Agent Registration
|
|
91
153
|
|
|
92
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
opm info lodash
|
|
107
|
-
opm info lodash@4.17.21
|
|
167
|
+
### Circom Circuit
|
|
108
168
|
|
|
109
|
-
|
|
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
|
-
|
|
171
|
+
```bash
|
|
172
|
+
# Compile
|
|
173
|
+
circom accuracy_verifier.circom --r1cs --wasm --sym -o build/
|
|
115
174
|
|
|
116
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
183
|
+
## AI Agent Architecture
|
|
126
184
|
|
|
127
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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
|
-
|
|
195
|
+
Each agent produces a structured JSON assessment containing:
|
|
136
196
|
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
+
## Smart Contract: OPMRegistry
|
|
148
206
|
|
|
149
|
-
|
|
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
|
-
###
|
|
209
|
+
### Key Functions
|
|
152
210
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
###
|
|
225
|
+
### On-chain Activity
|
|
165
226
|
|
|
166
|
-
|
|
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
|
-
|
|
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
|
-
|
|
234
|
+
### Risk Thresholds
|
|
176
235
|
|
|
177
|
-
|
|
|
178
|
-
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
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
|
-
|
|
242
|
+
## Website
|
|
184
243
|
|
|
185
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
258
|
+
Full documentation is in the `docs/` directory, configured for [Mintlify](https://mintlify.com).
|
|
202
259
|
|
|
203
|
-
|
|
260
|
+
### Setup
|
|
204
261
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
268
|
+
Opens at `http://localhost:3333`. The docs cover:
|
|
215
269
|
|
|
216
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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/
|
|
231
|
-
contracts/
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
|
246
|
-
|
|
247
|
-
| `
|
|
248
|
-
| `
|
|
249
|
-
| `
|
|
250
|
-
| `
|
|
251
|
-
| `
|
|
252
|
-
| `FILEVERSE_API_KEY` |
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|