git-escrows 1.0.0

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/README.md ADDED
@@ -0,0 +1,387 @@
1
+ # Git Escrows
2
+
3
+ A decentralized bounty system for test suites. Challenge submitters create escrowed bounties for failing test suites, fulfillment submitters solve them and claim rewards, and arbiter oracles verify solutions through automated Docker-based test execution.
4
+
5
+ ## Overview
6
+
7
+ Git Escrows enables trustless, code-execution-verified bounties:
8
+
9
+ 1. **Alice** (Challenge Submitter) deposits tokens as a bounty for a failing test suite
10
+ 2. **Bob** (Fulfillment Submitter) submits a solution and claims the reward
11
+ 3. **Charlie** (Arbiter Oracle) automatically verifies by running tests in Docker
12
+
13
+ The system uses Ethereum Attestation Service (EAS) for on-chain records and supports Git-based identity verification through SSH, PGP, or X509 keys.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm i -g git-escrows
19
+ ```
20
+
21
+ For development, clone the repo and install dependencies:
22
+
23
+ ```bash
24
+ bun install
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ Create a `.env` file or use the CLI:
30
+
31
+ ```bash
32
+ git-escrows new-client --privateKey "0x..." --network "sepolia"
33
+ ```
34
+
35
+ ### Environment Variables
36
+
37
+ ```env
38
+ PRIVATE_KEY=0x... # Your wallet private key (address derived automatically)
39
+ NETWORK=base-sepolia # Network: anvil, base-sepolia, sepolia
40
+ RPC_URL=https://... # RPC endpoint
41
+
42
+ # Contract addresses (auto-configured for base-sepolia and sepolia)
43
+ # Only needed as overrides or for custom/local deployments
44
+ COMMIT_OBLIGATION_ADDRESS=0x... # optional override
45
+ GIT_IDENTITY_REGISTRY_ADDRESS=0x... # optional override
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Roles
51
+
52
+ ### Challenge Submitter (Alice)
53
+
54
+ Creates escrowed bounties for test repositories with failing tests.
55
+
56
+ **Workflow:**
57
+
58
+ 1. Prepare a test repository with a failing test suite
59
+ 2. Choose a trusted arbiter oracle
60
+ 3. Submit the challenge with a token reward
61
+
62
+ **Commands:**
63
+
64
+ ```bash
65
+ # Create escrow bounty
66
+ git-escrows submit \
67
+ --tests-repo "https://github.com/alice/challenge-tests.git" \
68
+ --tests-commit "abc123..." \
69
+ --reward "1000000000000000000" \
70
+ --arbiter "0xArbiterContractAddress" \
71
+ --oracle "0xCharlieAddress" \
72
+ --token "0xERC20TokenAddress"
73
+ ```
74
+
75
+ The command will:
76
+ - Clone the test repository to detect the test framework
77
+ - Display the detected framework and Dockerfile that will be used
78
+ - Lock your tokens in escrow
79
+ - Return an escrow UID to share with potential solvers
80
+
81
+ **Options:**
82
+ - `--tests-repo`: Git repository URL containing tests
83
+ - `--tests-commit`: Commit hash of the test suite
84
+ - `--reward`: Amount in wei to escrow
85
+ - `--arbiter`: Arbiter contract address
86
+ - `--oracle`: Oracle address (Charlie) who will run verification
87
+ - `--token`: ERC20 token contract for the reward
88
+
89
+ ---
90
+
91
+ ### Fulfillment Submitter (Bob)
92
+
93
+ Solves challenges by submitting repositories where the tests pass.
94
+
95
+ **Workflow:**
96
+
97
+ 1. Browse open escrows
98
+ 2. Register your Git signing key (for commit verification)
99
+ 3. Write code that passes the challenge tests
100
+ 4. Submit your solution
101
+ 5. Collect the reward after arbitration passes
102
+
103
+ **Commands:**
104
+
105
+ ```bash
106
+ # Register your Git key for identity verification
107
+ git-escrows register-key --path ~/.ssh/id_ed25519.pub
108
+
109
+ # Verify your key is registered
110
+ git-escrows check-key
111
+
112
+ # Browse open escrows
113
+ git-escrows list --status open
114
+
115
+ # Submit your solution
116
+ git-escrows fulfill \
117
+ --escrow-uid "0x..." \
118
+ --solution-repo "https://github.com/bob/solution.git" \
119
+ --solution-commit "def456..."
120
+
121
+ # After arbitration passes, collect reward
122
+ git-escrows collect \
123
+ --escrow-uid "0x..." \
124
+ --fulfillment-uid "0x..."
125
+ ```
126
+
127
+ **Key Registration:**
128
+ - Supports SSH (Ed25519, RSA, ECDSA), PGP v4, and X509 certificates
129
+ - Auto-detects key type from file content
130
+ - Signs a message proving key ownership
131
+ - Stores key claim on-chain via GitIdentityRegistry
132
+
133
+ **Fulfillment Options:**
134
+ - `--escrow-uid`: The escrow to fulfill
135
+ - `--solution-repo`: Git repository URL containing your solution
136
+ - `--solution-commit`: Commit hash of your solution (should be signed)
137
+ - `--additional-hosts`: Backup repository URLs (optional)
138
+ - `--verify-key` / `--no-verify-key`: Check if your key is registered before submitting
139
+
140
+ ---
141
+
142
+ ### Arbiter Oracle (Charlie)
143
+
144
+ Third-party arbiter trusted by challenge submitters to run tests and verify fulfillments.
145
+
146
+ **Workflow:**
147
+
148
+ 1. Run the arbiter server
149
+ 2. The server listens for fulfillment attestations
150
+ 3. For each fulfillment:
151
+ - Clone test and solution repositories
152
+ - Verify commit signature (if enabled)
153
+ - Run tests in Docker container
154
+ - Record arbitration decision on-chain
155
+
156
+ **Commands:**
157
+
158
+ ```bash
159
+ # Run arbiter server
160
+ git-escrows server \
161
+ --mode allUnarbitrated \
162
+ --timeout 300000 \
163
+ --verify-key \
164
+ --cleanup
165
+
166
+ # One-time arbitration of past fulfillments
167
+ git-escrows server --mode pastUnarbitrated
168
+ ```
169
+
170
+ **Server Modes:**
171
+ - `allUnarbitrated` (default): Arbitrate unarbitrated past + listen for new
172
+ - `past`: Arbitrate all past fulfillments, then exit
173
+ - `pastUnarbitrated`: Arbitrate only unarbitrated past, then exit
174
+ - `all`: Arbitrate all past + listen for new
175
+ - `future`: Listen for new fulfillments only
176
+
177
+ **Options:**
178
+ - `--timeout`: Test execution timeout in milliseconds (default: 300000)
179
+ - `--verify-key`: Verify commit signatures against registered keys
180
+ - `--cleanup`: Remove Docker images and cloned repos after each run
181
+ - `--polling-interval`: Interval for checking new fulfillments (default: 1000ms)
182
+
183
+ ---
184
+
185
+ ## CLI Reference
186
+
187
+ | Command | Description |
188
+ |---------|-------------|
189
+ | `new-client` | Create `.env` configuration file |
190
+ | `register-key` | Register Git signing key on-chain |
191
+ | `check-key` | Verify if a key is registered for an address |
192
+ | `submit` | Create a new escrow bounty (Alice) |
193
+ | `fulfill` | Submit a solution to claim bounty (Bob) |
194
+ | `collect` | Collect reward after passing tests (Bob) |
195
+ | `list` | Query and display escrows |
196
+ | `server` | Run arbiter oracle server (Charlie) |
197
+
198
+ ### Listing Escrows
199
+
200
+ ```bash
201
+ # List all open escrows
202
+ git-escrows list --status open
203
+
204
+ # List escrows by address
205
+ git-escrows list --address 0x...
206
+
207
+ # Export as JSON
208
+ git-escrows list --format json
209
+
210
+ # Verbose output with full details
211
+ git-escrows list --verbose --limit 50
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Supported Test Frameworks
217
+
218
+ The system auto-detects test frameworks from repository contents:
219
+
220
+ | Framework | Detection | Lock/Config Files |
221
+ |-----------|-----------|-------------------|
222
+ | Cargo (Rust) | Cargo.lock | `cargo test` |
223
+ | pytest + uv | pyproject.toml + uv.lock | `uv run pytest` |
224
+ | pytest + Poetry | poetry.lock | `poetry run pytest` |
225
+ | Bun Test | bun.lock | `bun test` |
226
+ | Bun + Jest | bun.lock + jest.config.* | `bun jest` |
227
+ | Node + Jest | package-lock.json + jest.config.* | `npm test` |
228
+ | pnpm + Jest | pnpm-lock.yaml + jest.config.* | `pnpm test` |
229
+
230
+ ### Custom Dockerfile
231
+
232
+ For special requirements, add `arkhai_tests.dockerfile` to your test repository. This takes priority over auto-detection.
233
+
234
+ **Build Context:**
235
+
236
+ The Docker build context includes two directories:
237
+ - `source-repo/` - The fulfillment submitter's solution repository
238
+ - `test-repo/` - Your test repository (where the Dockerfile lives)
239
+
240
+ **Requirements:**
241
+ - File must be named exactly `arkhai_tests.dockerfile`
242
+ - Must be in the root of the test repository
243
+ - Exit code determines pass/fail: `0` = tests passed, non-zero = tests failed
244
+
245
+ **Example - Custom Node.js Setup:**
246
+
247
+ ```dockerfile
248
+ # arkhai_tests.dockerfile
249
+ FROM node:20
250
+
251
+ WORKDIR /workspace
252
+
253
+ # Copy repositories from build context
254
+ COPY source-repo /workspace/source-repo
255
+ COPY test-repo /workspace/test-repo
256
+
257
+ # Merge: start with solution, add tests
258
+ RUN cp -r source-repo project
259
+ RUN cp -r test-repo/tests project/tests
260
+
261
+ WORKDIR /workspace/project
262
+
263
+ # Install and run
264
+ RUN npm install
265
+ CMD ["npm", "test"]
266
+ ```
267
+
268
+ **Example - Rust with Custom Test Directory:**
269
+
270
+ ```dockerfile
271
+ # arkhai_tests.dockerfile
272
+ FROM rust:latest
273
+
274
+ WORKDIR /workspace
275
+
276
+ COPY source-repo /workspace/source-repo
277
+ COPY test-repo /workspace/test-repo
278
+
279
+ # Merge source and tests
280
+ RUN cp -r source-repo project
281
+ RUN cp -r test-repo/integration-tests project/tests
282
+
283
+ WORKDIR /workspace/project
284
+
285
+ RUN cargo build
286
+ CMD ["cargo", "test", "--", "--nocapture"]
287
+ ```
288
+
289
+ **Example - Python with Specific Dependencies:**
290
+
291
+ ```dockerfile
292
+ # arkhai_tests.dockerfile
293
+ FROM python:3.12
294
+
295
+ WORKDIR /workspace
296
+
297
+ COPY source-repo /workspace/source-repo
298
+ COPY test-repo /workspace/test-repo
299
+
300
+ # Merge
301
+ RUN cp -r source-repo project
302
+ RUN cp -r test-repo/test_*.py project/
303
+
304
+ WORKDIR /workspace/project
305
+
306
+ # Install from test repo requirements (may have test-specific deps)
307
+ RUN pip install -r /workspace/test-repo/requirements.txt
308
+ CMD ["pytest", "-v"]
309
+ ```
310
+
311
+ ---
312
+
313
+ ## Architecture
314
+
315
+ ```
316
+ Challenge Submitter (Alice)
317
+
318
+
319
+ [submit] ──► Escrow Attestation (EAS)
320
+
321
+
322
+ Fulfillment Submitter (Bob)
323
+
324
+
325
+ [fulfill] ──► Fulfillment Attestation
326
+
327
+
328
+ Arbiter Oracle (Charlie)
329
+
330
+
331
+ [server] ──► Clone repos ──► Run Docker tests ──► Record decision
332
+
333
+
334
+ [collect] ◄── If tests pass, Bob collects reward
335
+ ```
336
+
337
+ ### Smart Contracts
338
+
339
+ - **CommitObligation**: Handles fulfillment submissions (solution attestations)
340
+ - **GitIdentityRegistry**: Stores registered Git signing keys
341
+
342
+ #### Canonical Deployments
343
+
344
+ Contracts are deployed on the following networks with built-in address defaults (no env vars needed):
345
+
346
+ | Network | CommitObligation | GitIdentityRegistry |
347
+ |---------|-----------------|---------------------|
348
+ | Base Sepolia | `0x03d2591DfDf75611AdE94A9a80af61F9BcBfc4e2` | `0xc6b3fA56853F7D5abdFdaa7d008d9c27eBdE3e8a` |
349
+ | Sepolia | `0x5bf1EE1fEC1bC25d20C4537f74bD0909B195DEBd` | `0x57D5165F9487F6E7bD6E6a24017FAdadc2b1D7D2` |
350
+
351
+ Set `COMMIT_OBLIGATION_ADDRESS` and `GIT_IDENTITY_REGISTRY_ADDRESS` in `.env` only to override these defaults (e.g., for local Anvil deployments).
352
+
353
+ ### Test Execution
354
+
355
+ 1. Clone test repository (from provided hosts)
356
+ 2. Clone solution repository
357
+ 3. Detect framework or use custom Dockerfile
358
+ 4. Build Docker image with both repos
359
+ 5. Execute tests with timeout
360
+ 6. Parse output for pass/fail
361
+ 7. Record arbitration decision on-chain
362
+
363
+ ---
364
+
365
+ ## Development
366
+
367
+ ```bash
368
+ # Install dependencies
369
+ bun install
370
+
371
+ # Run tests
372
+ bun test
373
+
374
+ # Build for npm (outputs to dist/)
375
+ bun run build
376
+
377
+ # Build standalone binaries (macOS/Linux/Windows)
378
+ bun run build:all
379
+
380
+ # Deploy contracts (requires Foundry)
381
+ cd contract && forge script script/DeploySepolia.s.sol --broadcast # Base Sepolia
382
+ cd contract && forge script script/DeployEthSepolia.s.sol --broadcast # Ethereum Sepolia
383
+ ```
384
+
385
+ ## License
386
+
387
+ MIT