@conarium-ai/core 0.1.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/CHANGELOG.md +131 -0
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/SECURITY.md +226 -0
- package/bin/conarium-anchor-service.mjs +77 -0
- package/bin/conarium-anchor-upgrade.mjs +108 -0
- package/bin/conarium-coverage.mjs +425 -0
- package/bin/conarium-doctor.mjs +480 -0
- package/bin/conarium-init.mjs +184 -0
- package/bin/conarium-reconcile.mjs +441 -0
- package/bin/conarium-stamp.mjs +161 -0
- package/bin/conarium-verify.mjs +610 -0
- package/conarium.config.json +43 -0
- package/deploy/anchor-service/README.md +79 -0
- package/deploy/anchor-service/conarium-anchor.service +21 -0
- package/deploy/anchor-service/dry-run.mjs +122 -0
- package/deploy/anchor-service/ecosystem.config.cjs +21 -0
- package/deploy/anchor-service/env.example +11 -0
- package/dist/anchor-service.d.ts +39 -0
- package/dist/anchor-service.d.ts.map +1 -0
- package/dist/anchor-service.js +278 -0
- package/dist/anchor-service.js.map +1 -0
- package/dist/anchor.d.ts +123 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +246 -0
- package/dist/anchor.js.map +1 -0
- package/dist/audit-hash.d.ts +4 -0
- package/dist/audit-hash.d.ts.map +1 -0
- package/dist/audit-hash.js +12 -0
- package/dist/audit-hash.js.map +1 -0
- package/dist/audit.d.ts +104 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +391 -0
- package/dist/audit.js.map +1 -0
- package/dist/config.d.ts +273 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/connectors/docs.d.ts +23 -0
- package/dist/connectors/docs.d.ts.map +1 -0
- package/dist/connectors/docs.js +140 -0
- package/dist/connectors/docs.js.map +1 -0
- package/dist/connectors/index.d.ts +10 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +37 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/jira.d.ts +16 -0
- package/dist/connectors/jira.d.ts.map +1 -0
- package/dist/connectors/jira.js +67 -0
- package/dist/connectors/jira.js.map +1 -0
- package/dist/connectors/openapi.d.ts +28 -0
- package/dist/connectors/openapi.d.ts.map +1 -0
- package/dist/connectors/openapi.js +447 -0
- package/dist/connectors/openapi.js.map +1 -0
- package/dist/connectors/postgres.d.ts +17 -0
- package/dist/connectors/postgres.d.ts.map +1 -0
- package/dist/connectors/postgres.js +131 -0
- package/dist/connectors/postgres.js.map +1 -0
- package/dist/connectors/slack.d.ts +16 -0
- package/dist/connectors/slack.d.ts.map +1 -0
- package/dist/connectors/slack.js +65 -0
- package/dist/connectors/slack.js.map +1 -0
- package/dist/connectors/supabase_rest.d.ts +35 -0
- package/dist/connectors/supabase_rest.d.ts.map +1 -0
- package/dist/connectors/supabase_rest.js +153 -0
- package/dist/connectors/supabase_rest.js.map +1 -0
- package/dist/connectors/zion.d.ts +24 -0
- package/dist/connectors/zion.d.ts.map +1 -0
- package/dist/connectors/zion.js +76 -0
- package/dist/connectors/zion.js.map +1 -0
- package/dist/console.d.ts +30 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +257 -0
- package/dist/console.js.map +1 -0
- package/dist/coverage.d.ts +100 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +175 -0
- package/dist/coverage.js.map +1 -0
- package/dist/executor.d.ts +12 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +77 -0
- package/dist/executor.js.map +1 -0
- package/dist/governance.d.ts +124 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +977 -0
- package/dist/governance.js.map +1 -0
- package/dist/http.d.ts +48 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +221 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +174 -0
- package/dist/keys.js.map +1 -0
- package/dist/license.d.ts +35 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +122 -0
- package/dist/license.js.map +1 -0
- package/dist/llm-gate.d.ts +17 -0
- package/dist/llm-gate.d.ts.map +1 -0
- package/dist/llm-gate.js +19 -0
- package/dist/llm-gate.js.map +1 -0
- package/dist/openapi_connector.d.ts +6 -0
- package/dist/openapi_connector.d.ts.map +1 -0
- package/dist/openapi_connector.js +145 -0
- package/dist/openapi_connector.js.map +1 -0
- package/dist/pseudonymize.d.ts +19 -0
- package/dist/pseudonymize.d.ts.map +1 -0
- package/dist/pseudonymize.js +25 -0
- package/dist/pseudonymize.js.map +1 -0
- package/dist/rate_limit.d.ts +41 -0
- package/dist/rate_limit.d.ts.map +1 -0
- package/dist/rate_limit.js +66 -0
- package/dist/rate_limit.js.map +1 -0
- package/dist/receipt.d.ts +161 -0
- package/dist/receipt.d.ts.map +1 -0
- package/dist/receipt.js +210 -0
- package/dist/receipt.js.map +1 -0
- package/dist/scripts/discover_schema.d.ts +2 -0
- package/dist/scripts/discover_schema.d.ts.map +1 -0
- package/dist/scripts/discover_schema.js +75 -0
- package/dist/scripts/discover_schema.js.map +1 -0
- package/dist/scripts/dogfood_prove.d.ts +2 -0
- package/dist/scripts/dogfood_prove.d.ts.map +1 -0
- package/dist/scripts/dogfood_prove.js +41 -0
- package/dist/scripts/dogfood_prove.js.map +1 -0
- package/dist/search_policy.d.ts +23 -0
- package/dist/search_policy.d.ts.map +1 -0
- package/dist/search_policy.js +79 -0
- package/dist/search_policy.js.map +1 -0
- package/dist/server.d.ts +29 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +379 -0
- package/dist/server.js.map +1 -0
- package/dist/tokens.d.ts +14 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +58 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/ARCHITECTURE.md +42 -0
- package/docs/CONSENT-BINDING-SPEC.md +136 -0
- package/docs/CONSENT-BINDING-SPEC.md.anchors.jsonl +1 -0
- package/docs/PRIOR-ART.md +213 -0
- package/docs/PRIOR-ART.md.anchors.jsonl +3 -0
- package/docs/RECEIPT-SPEC.md +301 -0
- package/docs/RECEIPT-SPEC.md.anchors.jsonl +1 -0
- package/docs/dogfood/2026-07-31-anchor.anchors.jsonl +1 -0
- package/docs/dogfood/2026-08-06-reconcile.md +140 -0
- package/docs/plans/2026-07-02-redteam-harness.md +416 -0
- package/docs/specs/2026-07-02-redteam-harness-design.md +90 -0
- package/docs/superpowers/TODO-gate1-f4.md +23 -0
- package/docs/superpowers/plans/2026-07-29-conarium-receipt-plan.md +200 -0
- package/docs/superpowers/plans/2026-07-29-katman0-kapanis-plan.md +231 -0
- package/docs/superpowers/plans/2026-07-31-per-user-identity.md +667 -0
- package/docs/superpowers/specs/2026-07-29-conarium-receipt-design.md +202 -0
- package/docs/superpowers/specs/2026-07-31-per-user-identity-design.md +144 -0
- package/docs/superpowers/specs/2026-08-01-coverage-proof-design.md +139 -0
- package/docs/superpowers/specs/2026-08-05-receipt-meta-provenance-design.md +116 -0
- package/examples/claude-desktop-config.json +9 -0
- package/examples/cursor-mcp-settings.json +10 -0
- package/package.json +99 -0
- package/scripts/audit-chain-check.mjs +119 -0
- package/scripts/conarium_sabah_brief.mjs +107 -0
- package/scripts/gen-test-vectors.mjs +193 -0
- package/scripts/pg-snapshot.sql +27 -0
- package/scripts/start-mcp-c1.mjs +70 -0
- package/test-vectors/001-single-receipt/receipts.jsonl +1 -0
- package/test-vectors/002-chain-of-three/receipts.jsonl +3 -0
- package/test-vectors/003-tampered-field/receipts.jsonl +1 -0
- package/test-vectors/004-prevhash-break/receipts.jsonl +2 -0
- package/test-vectors/005-seq-gap/receipts.jsonl +2 -0
- package/test-vectors/006-bad-signature/receipts.jsonl +1 -0
- package/test-vectors/007-schema-invalid/receipts.jsonl +1 -0
- package/test-vectors/008-unsigned-no-pubkey/receipts.jsonl +1 -0
- package/test-vectors/009-unsigned-but-pubkey-given/receipts.jsonl +1 -0
- package/test-vectors/README.md +92 -0
- package/test-vectors/expected-hashes.json +24 -0
- package/test-vectors/keys/vector-key.SECRET-TEST-ONLY.pem +6 -0
- package/test-vectors/keys/vector-key.pub.pem +3 -0
- package/test-vectors/keys/vector-key.pub.pem.keyid +1 -0
- package/test-vectors/manifest.json +95 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Conarium anchoring service — deploy pack
|
|
2
|
+
|
|
3
|
+
This directory is the operator pack for self-hosting
|
|
4
|
+
`bin/conarium-anchor-service.mjs`. **Nobody has deployed this to Hetzner from
|
|
5
|
+
this tree.** Copy the files, fill `.env`, start it yourself.
|
|
6
|
+
|
|
7
|
+
Conarium is not the timestamp authority. The OpenTimestamps calendars and
|
|
8
|
+
Bitcoin are. This process is retention, a stable URL, and the upgrade job
|
|
9
|
+
nobody remembers to run.
|
|
10
|
+
|
|
11
|
+
## What must be set
|
|
12
|
+
|
|
13
|
+
See `env.example`. The process **refuses to start** if either of these is
|
|
14
|
+
missing, and names the variable:
|
|
15
|
+
|
|
16
|
+
- `CONARIUM_ANCHOR_TOKENS` — path to a JSON map `{"token":"owner-id"}`
|
|
17
|
+
- `CONARIUM_ANCHOR_BASE_URL` — public origin used in verify URLs
|
|
18
|
+
|
|
19
|
+
An anchoring endpoint anyone can write to is a disk filling up, not a service.
|
|
20
|
+
|
|
21
|
+
## Ports and health
|
|
22
|
+
|
|
23
|
+
| | default |
|
|
24
|
+
|---|---|
|
|
25
|
+
| listen | `127.0.0.1:8797` (`CONARIUM_ANCHOR_HOST` / `CONARIUM_ANCHOR_PORT`) |
|
|
26
|
+
| health | `GET /healthz` → `200` `{ ok: true, service: "conarium-anchor", anchors: N }` |
|
|
27
|
+
|
|
28
|
+
Put a TLS proxy in front. The process binds loopback on purpose.
|
|
29
|
+
|
|
30
|
+
`pm2 status` saying `online` is not proof it is listening. This box has already
|
|
31
|
+
had a process look healthy while binding nothing. Probe `/healthz`.
|
|
32
|
+
|
|
33
|
+
## Local dry-run (no calendars, no Hetzner)
|
|
34
|
+
|
|
35
|
+
From the repository root, after `npm run build`:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
node deploy/anchor-service/dry-run.mjs
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
It asserts:
|
|
42
|
+
|
|
43
|
+
1. missing env → exit 2, the variable is named
|
|
44
|
+
2. with a throwaway tokens file, `GET /healthz` returns 200
|
|
45
|
+
3. the process is then killed
|
|
46
|
+
|
|
47
|
+
`CONARIUM_ANCHOR_UPGRADE_MINUTES=0` so the dry-run never talks to a calendar.
|
|
48
|
+
|
|
49
|
+
## systemd
|
|
50
|
+
|
|
51
|
+
1. Copy `conarium-anchor.service` to `/etc/systemd/system/`
|
|
52
|
+
2. Edit `WorkingDirectory`, `User`, and `EnvironmentFile`
|
|
53
|
+
3. Copy `env.example` to `.env` and fill it
|
|
54
|
+
4. `systemctl daemon-reload && systemctl enable --now conarium-anchor`
|
|
55
|
+
|
|
56
|
+
## pm2
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pm2 start deploy/anchor-service/ecosystem.config.cjs
|
|
60
|
+
pm2 save
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then: `curl -fsS http://127.0.0.1:8797/healthz`
|
|
64
|
+
|
|
65
|
+
## Rollback
|
|
66
|
+
|
|
67
|
+
1. Stop the unit / `pm2 stop conarium-anchor`
|
|
68
|
+
2. The store is append-only JSONL (`CONARIUM_ANCHOR_STORE`). Keep the file.
|
|
69
|
+
Starting an older binary against the same store is safe: records are
|
|
70
|
+
`{id,hash,owner,log,ots,state,...}` and unknown fields are ignored on read.
|
|
71
|
+
3. Do not rewrite the store to "fix" a proof. A store that can be rewritten
|
|
72
|
+
is not an anchoring log.
|
|
73
|
+
|
|
74
|
+
## Peer dependency
|
|
75
|
+
|
|
76
|
+
`javascript-opentimestamps` is optional in the npm package. A live anchoring
|
|
77
|
+
service needs it installed, or `POST /anchor` returns 502. `/healthz` does
|
|
78
|
+
not load it — that is deliberate, so a health probe does not depend on a
|
|
79
|
+
calendar library.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Conarium OpenTimestamps anchoring service
|
|
3
|
+
Documentation=https://github.com/dogrucanemek-alt/conarium/blob/main/deploy/anchor-service/README.md
|
|
4
|
+
After=network-online.target
|
|
5
|
+
Wants=network-online.target
|
|
6
|
+
|
|
7
|
+
[Service]
|
|
8
|
+
Type=simple
|
|
9
|
+
User=conarium
|
|
10
|
+
Group=conarium
|
|
11
|
+
WorkingDirectory=/opt/conarium
|
|
12
|
+
EnvironmentFile=/opt/conarium/deploy/anchor-service/.env
|
|
13
|
+
ExecStart=/usr/bin/node /opt/conarium/bin/conarium-anchor-service.mjs
|
|
14
|
+
Restart=on-failure
|
|
15
|
+
RestartSec=5
|
|
16
|
+
# The process binds loopback. TLS belongs on the proxy in front.
|
|
17
|
+
NoNewPrivileges=true
|
|
18
|
+
PrivateTmp=true
|
|
19
|
+
|
|
20
|
+
[Install]
|
|
21
|
+
WantedBy=multi-user.target
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Local dry-run for the anchoring service. Does not talk to calendars or
|
|
4
|
+
* Hetzner. Proves two things the operator will hit:
|
|
5
|
+
* 1. missing env refuses to start and names the variable
|
|
6
|
+
* 2. with env present, GET /healthz returns 200 (pm2 "online" is not this)
|
|
7
|
+
*/
|
|
8
|
+
import { spawn } from 'node:child_process'
|
|
9
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs'
|
|
10
|
+
import { tmpdir } from 'node:os'
|
|
11
|
+
import { dirname, join } from 'node:path'
|
|
12
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
import { createServer } from 'node:net'
|
|
14
|
+
|
|
15
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
|
|
16
|
+
const BIN = join(ROOT, 'bin', 'conarium-anchor-service.mjs')
|
|
17
|
+
|
|
18
|
+
function runOnce(env) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const child = spawn(process.execPath, [BIN], {
|
|
21
|
+
env: { ...process.env, ...env },
|
|
22
|
+
encoding: 'utf-8',
|
|
23
|
+
})
|
|
24
|
+
let out = ''
|
|
25
|
+
child.stdout.on('data', (d) => { out += d })
|
|
26
|
+
child.stderr.on('data', (d) => { out += d })
|
|
27
|
+
child.on('exit', (status) => resolve({ status, out }))
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function freePort() {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const s = createServer()
|
|
34
|
+
s.listen(0, '127.0.0.1', () => {
|
|
35
|
+
const { port } = s.address()
|
|
36
|
+
s.close((err) => (err ? reject(err) : resolve(port)))
|
|
37
|
+
})
|
|
38
|
+
s.on('error', reject)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function waitExit(child, ms) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const t = setTimeout(() => resolve(null), ms)
|
|
45
|
+
child.on('exit', (code) => {
|
|
46
|
+
clearTimeout(t)
|
|
47
|
+
resolve(code)
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const missing = await runOnce({
|
|
53
|
+
CONARIUM_ANCHOR_TOKENS: '',
|
|
54
|
+
CONARIUM_ANCHOR_BASE_URL: '',
|
|
55
|
+
})
|
|
56
|
+
if (missing.status !== 2) {
|
|
57
|
+
console.error(`expected exit 2 on missing env, got ${missing.status}\n${missing.out}`)
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
if (!/CONARIUM_ANCHOR_TOKENS/.test(missing.out)) {
|
|
61
|
+
console.error(`missing-env refusal did not name CONARIUM_ANCHOR_TOKENS:\n${missing.out}`)
|
|
62
|
+
process.exit(1)
|
|
63
|
+
}
|
|
64
|
+
console.log('ok missing env refuses start and names CONARIUM_ANCHOR_TOKENS')
|
|
65
|
+
|
|
66
|
+
const dir = mkdtempSync(join(tmpdir(), 'conarium-anchor-dry-'))
|
|
67
|
+
const tokensPath = join(dir, 'tokens.json')
|
|
68
|
+
const storePath = join(dir, 'store.jsonl')
|
|
69
|
+
writeFileSync(tokensPath, JSON.stringify({ 'dry-run-token': 'dry-run-owner' }) + '\n')
|
|
70
|
+
const port = await freePort()
|
|
71
|
+
|
|
72
|
+
const child = spawn(process.execPath, [BIN], {
|
|
73
|
+
env: {
|
|
74
|
+
...process.env,
|
|
75
|
+
CONARIUM_ANCHOR_TOKENS: tokensPath,
|
|
76
|
+
CONARIUM_ANCHOR_BASE_URL: 'http://127.0.0.1:' + port,
|
|
77
|
+
CONARIUM_ANCHOR_STORE: storePath,
|
|
78
|
+
CONARIUM_ANCHOR_HOST: '127.0.0.1',
|
|
79
|
+
CONARIUM_ANCHOR_PORT: String(port),
|
|
80
|
+
CONARIUM_ANCHOR_UPGRADE_MINUTES: '0',
|
|
81
|
+
},
|
|
82
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
let started = ''
|
|
86
|
+
child.stdout.on('data', (d) => { started += d })
|
|
87
|
+
child.stderr.on('data', (d) => { started += d })
|
|
88
|
+
|
|
89
|
+
const early = await waitExit(child, 4000)
|
|
90
|
+
if (early !== null) {
|
|
91
|
+
console.error(`service exited before listen: ${early}\n${started}`)
|
|
92
|
+
rmSync(dir, { recursive: true, force: true })
|
|
93
|
+
process.exit(1)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let health
|
|
97
|
+
try {
|
|
98
|
+
const res = await fetch(`http://127.0.0.1:${port}/healthz`)
|
|
99
|
+
health = { status: res.status, body: await res.text() }
|
|
100
|
+
} catch (e) {
|
|
101
|
+
child.kill('SIGTERM')
|
|
102
|
+
console.error(`healthz request failed: ${e.message}\n${started}`)
|
|
103
|
+
rmSync(dir, { recursive: true, force: true })
|
|
104
|
+
process.exit(1)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
child.kill('SIGTERM')
|
|
108
|
+
await waitExit(child, 2000)
|
|
109
|
+
try { child.kill('SIGKILL') } catch { /* already gone */ }
|
|
110
|
+
rmSync(dir, { recursive: true, force: true })
|
|
111
|
+
|
|
112
|
+
if (health.status !== 200) {
|
|
113
|
+
console.error(`healthz expected 200, got ${health.status}: ${health.body}`)
|
|
114
|
+
process.exit(1)
|
|
115
|
+
}
|
|
116
|
+
if (!/"ok"\s*:\s*true/.test(health.body) && !/"ok":true/.test(health.body)) {
|
|
117
|
+
console.error(`healthz body missing ok:true: ${health.body}`)
|
|
118
|
+
process.exit(1)
|
|
119
|
+
}
|
|
120
|
+
console.log(`ok GET /healthz → ${health.status} ${health.body}`)
|
|
121
|
+
console.log('dry-run passed')
|
|
122
|
+
process.exit(0)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* pm2 ecosystem for the anchoring service.
|
|
5
|
+
* `pm2 status` saying online is not a health check — probe GET /healthz.
|
|
6
|
+
*/
|
|
7
|
+
module.exports = {
|
|
8
|
+
apps: [
|
|
9
|
+
{
|
|
10
|
+
name: 'conarium-anchor',
|
|
11
|
+
script: 'bin/conarium-anchor-service.mjs',
|
|
12
|
+
cwd: process.cwd(),
|
|
13
|
+
interpreter: 'node',
|
|
14
|
+
env: {
|
|
15
|
+
CONARIUM_ANCHOR_HOST: '127.0.0.1',
|
|
16
|
+
CONARIUM_ANCHOR_PORT: '8797',
|
|
17
|
+
},
|
|
18
|
+
// Real secrets live in the process environment / EnvironmentFile, not here.
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Copy to .env and fill. Never commit the filled file.
|
|
2
|
+
# The process refuses to start if TOKENS or BASE_URL is missing.
|
|
3
|
+
|
|
4
|
+
CONARIUM_ANCHOR_TOKENS=./anchor.tokens.json
|
|
5
|
+
CONARIUM_ANCHOR_BASE_URL=https://anchor.example.invalid
|
|
6
|
+
CONARIUM_ANCHOR_STORE=./anchor-store.jsonl
|
|
7
|
+
CONARIUM_ANCHOR_HOST=127.0.0.1
|
|
8
|
+
CONARIUM_ANCHOR_PORT=8797
|
|
9
|
+
CONARIUM_ANCHOR_RATE=60
|
|
10
|
+
# 0 disables the background Bitcoin-upgrade pass (use for dry-run).
|
|
11
|
+
CONARIUM_ANCHOR_UPGRADE_MINUTES=60
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface AnchorRecord {
|
|
2
|
+
id: string;
|
|
3
|
+
hash: string;
|
|
4
|
+
owner: string;
|
|
5
|
+
log: 'opentimestamps';
|
|
6
|
+
ots: string;
|
|
7
|
+
state: 'pending' | 'bitcoin';
|
|
8
|
+
bitcoinBlock?: number;
|
|
9
|
+
submittedAt: string;
|
|
10
|
+
upgradedAt?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AnchorServiceOptions {
|
|
13
|
+
/** JSONL store. Append-only: an anchoring log that can be rewritten is not one. */
|
|
14
|
+
storePath: string;
|
|
15
|
+
/** token -> owner id. Anonymous writes would let anyone fill the disk. */
|
|
16
|
+
tokens: Map<string, string>;
|
|
17
|
+
/** Public base URL, used to build the permanent verification address. */
|
|
18
|
+
publicBaseUrl: string;
|
|
19
|
+
submitsPerMinute?: number;
|
|
20
|
+
/** Injected in tests so the suite never touches a calendar server. */
|
|
21
|
+
stamp?: (digest: Buffer) => Promise<string>;
|
|
22
|
+
upgrade?: (otsBase64: string) => Promise<{
|
|
23
|
+
upgraded: boolean;
|
|
24
|
+
block?: number;
|
|
25
|
+
ots?: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/** Reads every record. The store is small by design — one line per anchor. */
|
|
29
|
+
export declare function readStore(path: string): AnchorRecord[];
|
|
30
|
+
export declare function loadTokensFile(path: string): Map<string, string>;
|
|
31
|
+
export declare function createAnchorService(opts: AnchorServiceOptions): {
|
|
32
|
+
app: import("express-serve-static-core").Express;
|
|
33
|
+
runUpgrade: () => Promise<{
|
|
34
|
+
checked: number;
|
|
35
|
+
upgraded: number;
|
|
36
|
+
}>;
|
|
37
|
+
readStore: () => AnchorRecord[];
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=anchor-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor-service.d.ts","sourceRoot":"","sources":["../src/anchor-service.ts"],"names":[],"mappings":"AAgCA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,gBAAgB,CAAA;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,SAAS,GAAG,SAAS,CAAA;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAA;IACjB,0EAA0E;IAC1E,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3B,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,sEAAsE;IACtE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC9F;AAqCD,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAKtD;AAUD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAUhE;AAaD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB;;sBA4H/B,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;;EA0B5E"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosted anchoring endpoint.
|
|
3
|
+
*
|
|
4
|
+
* What it does: takes a hash, submits it to the OpenTimestamps calendars, keeps
|
|
5
|
+
* the resulting proof, and serves it forever at a stable URL. A background pass
|
|
6
|
+
* upgrades each proof from `pending` to a Bitcoin block height once the block
|
|
7
|
+
* lands.
|
|
8
|
+
*
|
|
9
|
+
* What it is NOT — and this must never be blurred in the copy: Conarium is not
|
|
10
|
+
* the timestamp authority. The calendars and Bitcoin are. This service is
|
|
11
|
+
* retention, a permanent public address, and the upgrade job nobody remembers
|
|
12
|
+
* to run. It sells convenience and durability, never trust.
|
|
13
|
+
*
|
|
14
|
+
* The proof is served raw at `/anchor/:id/ots`, so a third party can verify with
|
|
15
|
+
* the reference OpenTimestamps client and ignore this service entirely. An
|
|
16
|
+
* anchoring service you have to trust would defeat the point of anchoring.
|
|
17
|
+
*
|
|
18
|
+
* The code is MIT like the rest — self-host it if you prefer. What is sold is
|
|
19
|
+
* someone else keeping it alive.
|
|
20
|
+
*/
|
|
21
|
+
import express from 'express';
|
|
22
|
+
import { randomBytes, timingSafeEqual } from 'crypto';
|
|
23
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
24
|
+
import { dirname } from 'path';
|
|
25
|
+
import { createRequire } from 'module';
|
|
26
|
+
import { hashPrefixToBuffer } from './anchor.js';
|
|
27
|
+
// Same trick anchor.ts uses: createRequire, because the OTS package is CJS and
|
|
28
|
+
// Vite/vitest resolve it wrongly through import analysis.
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
// Matches conarium-stamp. One slow calendar out of four is normal; 20s was not
|
|
31
|
+
// enough in practice and produced a 502 for a submission that would have landed.
|
|
32
|
+
const OTS_TIMEOUT_MS = 30_000;
|
|
33
|
+
function loadOts() {
|
|
34
|
+
const mod = require('javascript-opentimestamps');
|
|
35
|
+
return mod?.default ?? mod;
|
|
36
|
+
}
|
|
37
|
+
async function defaultStamp(digest) {
|
|
38
|
+
const mod = loadOts();
|
|
39
|
+
const detached = mod.DetachedTimestampFile.fromHash(new mod.Ops.OpSHA256(), digest);
|
|
40
|
+
await Promise.race([
|
|
41
|
+
mod.stamp(detached),
|
|
42
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(`stamp timed out after ${OTS_TIMEOUT_MS}ms`)), OTS_TIMEOUT_MS)),
|
|
43
|
+
]);
|
|
44
|
+
return Buffer.from(detached.serializeToBytes()).toString('base64');
|
|
45
|
+
}
|
|
46
|
+
async function defaultUpgrade(otsBase64) {
|
|
47
|
+
const mod = loadOts();
|
|
48
|
+
const detached = mod.DetachedTimestampFile.deserialize(Array.from(Buffer.from(otsBase64, 'base64')));
|
|
49
|
+
const changed = await mod.upgrade(detached);
|
|
50
|
+
if (!changed)
|
|
51
|
+
return { upgraded: false };
|
|
52
|
+
let block;
|
|
53
|
+
for (const [, attestation] of detached.timestamp.allAttestations()) {
|
|
54
|
+
const height = attestation?.height;
|
|
55
|
+
if (typeof height === 'number')
|
|
56
|
+
block = height;
|
|
57
|
+
else if (height && typeof height.toNumber === 'function')
|
|
58
|
+
block = height.toNumber();
|
|
59
|
+
}
|
|
60
|
+
return { upgraded: true, block, ots: Buffer.from(detached.serializeToBytes()).toString('base64') };
|
|
61
|
+
}
|
|
62
|
+
/** Reads every record. The store is small by design — one line per anchor. */
|
|
63
|
+
export function readStore(path) {
|
|
64
|
+
if (!existsSync(path))
|
|
65
|
+
return [];
|
|
66
|
+
const raw = readFileSync(path, 'utf-8').trim();
|
|
67
|
+
if (!raw)
|
|
68
|
+
return [];
|
|
69
|
+
return raw.split('\n').filter(Boolean).map((l) => JSON.parse(l));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* An upgrade is the one legitimate reason to rewrite a line, so the whole file
|
|
73
|
+
* is rewritten rather than appended to. Everything else is append-only.
|
|
74
|
+
*/
|
|
75
|
+
function rewriteStore(path, rows) {
|
|
76
|
+
writeFileSync(path, rows.map((r) => JSON.stringify(r)).join('\n') + (rows.length ? '\n' : ''));
|
|
77
|
+
}
|
|
78
|
+
export function loadTokensFile(path) {
|
|
79
|
+
const tokens = new Map();
|
|
80
|
+
if (!existsSync(path))
|
|
81
|
+
return tokens;
|
|
82
|
+
const parsed = JSON.parse(readFileSync(path, 'utf-8'));
|
|
83
|
+
for (const [token, owner] of Object.entries(parsed)) {
|
|
84
|
+
if (typeof token === 'string' && typeof owner === 'string' && token && owner) {
|
|
85
|
+
tokens.set(token, owner);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return tokens;
|
|
89
|
+
}
|
|
90
|
+
/** Constant-time lookup: a token map compared with === leaks length by timing. */
|
|
91
|
+
function resolveOwner(tokens, presented) {
|
|
92
|
+
const presentedBuf = Buffer.from(presented);
|
|
93
|
+
let found = null;
|
|
94
|
+
for (const [token, owner] of tokens) {
|
|
95
|
+
const known = Buffer.from(token);
|
|
96
|
+
if (known.length === presentedBuf.length && timingSafeEqual(known, presentedBuf))
|
|
97
|
+
found = owner;
|
|
98
|
+
}
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
export function createAnchorService(opts) {
|
|
102
|
+
const stamp = opts.stamp ?? defaultStamp;
|
|
103
|
+
const upgrade = opts.upgrade ?? defaultUpgrade;
|
|
104
|
+
const perMinute = opts.submitsPerMinute ?? 60;
|
|
105
|
+
const base = opts.publicBaseUrl.replace(/\/+$/, '');
|
|
106
|
+
mkdirSync(dirname(opts.storePath), { recursive: true });
|
|
107
|
+
const buckets = new Map();
|
|
108
|
+
function overLimit(owner) {
|
|
109
|
+
const now = Date.now();
|
|
110
|
+
const b = buckets.get(owner);
|
|
111
|
+
if (!b || now >= b.resetAt) {
|
|
112
|
+
buckets.set(owner, { count: 1, resetAt: now + 60_000 });
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
b.count += 1;
|
|
116
|
+
return b.count > perMinute;
|
|
117
|
+
}
|
|
118
|
+
const app = express();
|
|
119
|
+
app.use(express.json({ limit: '16kb' }));
|
|
120
|
+
function auth(req, res) {
|
|
121
|
+
const header = req.header('authorization') ?? '';
|
|
122
|
+
const token = header.startsWith('Bearer ') ? header.slice(7).trim() : '';
|
|
123
|
+
if (!token) {
|
|
124
|
+
res.status(401).json({ error: 'missing bearer token' });
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const owner = resolveOwner(opts.tokens, token);
|
|
128
|
+
if (!owner) {
|
|
129
|
+
res.status(401).json({ error: 'unknown token' });
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return owner;
|
|
133
|
+
}
|
|
134
|
+
app.get('/healthz', (_req, res) => {
|
|
135
|
+
res.json({ ok: true, service: 'conarium-anchor', anchors: readStore(opts.storePath).length });
|
|
136
|
+
});
|
|
137
|
+
app.post('/anchor', async (req, res) => {
|
|
138
|
+
const owner = auth(req, res);
|
|
139
|
+
if (!owner)
|
|
140
|
+
return;
|
|
141
|
+
const hash = typeof req.body?.hash === 'string' ? req.body.hash : '';
|
|
142
|
+
let digest;
|
|
143
|
+
try {
|
|
144
|
+
digest = hashPrefixToBuffer(hash);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
res.status(400).json({ error: err.message });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (overLimit(owner)) {
|
|
151
|
+
res.status(429).json({ error: 'rate limit exceeded', retryAfterSeconds: 60 });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// Same content, same owner, same answer. Re-anchoring an identical hash
|
|
155
|
+
// wastes a calendar submission and produces a second id for one fact.
|
|
156
|
+
const existing = readStore(opts.storePath).find((r) => r.hash === hash && r.owner === owner);
|
|
157
|
+
if (existing) {
|
|
158
|
+
res.status(200).json({ ...publicView(existing, base), deduplicated: true });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let ots;
|
|
162
|
+
try {
|
|
163
|
+
ots = await stamp(digest);
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
// Fail loudly. A silent 200 here would mean the customer believes their
|
|
167
|
+
// chain is anchored when nothing was submitted.
|
|
168
|
+
res.status(502).json({ error: `calendar submission failed: ${err.message}` });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const record = {
|
|
172
|
+
id: randomBytes(9).toString('base64url'),
|
|
173
|
+
hash,
|
|
174
|
+
owner,
|
|
175
|
+
log: 'opentimestamps',
|
|
176
|
+
ots,
|
|
177
|
+
state: 'pending',
|
|
178
|
+
submittedAt: new Date().toISOString(),
|
|
179
|
+
};
|
|
180
|
+
appendFileSync(opts.storePath, JSON.stringify(record) + '\n');
|
|
181
|
+
res.status(201).json(publicView(record, base));
|
|
182
|
+
});
|
|
183
|
+
app.get('/anchor/:id', (req, res) => {
|
|
184
|
+
const record = readStore(opts.storePath).find((r) => r.id === req.params.id);
|
|
185
|
+
if (!record) {
|
|
186
|
+
res.status(404).json({ error: 'no such anchor' });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
// Public on purpose: a verification URL only a token holder can open is not
|
|
190
|
+
// a verification URL. It carries a hash and a proof, never content.
|
|
191
|
+
res.setHeader('Vary', 'Accept');
|
|
192
|
+
if (req.accepts(['json', 'html']) === 'html') {
|
|
193
|
+
res.type('html').send(humanPage(record, base));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
res.json(publicView(record, base));
|
|
197
|
+
});
|
|
198
|
+
app.get('/anchor/:id/ots', (req, res) => {
|
|
199
|
+
const record = readStore(opts.storePath).find((r) => r.id === req.params.id);
|
|
200
|
+
if (!record) {
|
|
201
|
+
res.status(404).json({ error: 'no such anchor' });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
res.type('application/octet-stream').send(Buffer.from(record.ots, 'base64'));
|
|
205
|
+
});
|
|
206
|
+
/** Upgrade pass. Idempotent, safe to run from cron as often as you like. */
|
|
207
|
+
app.post('/upgrade', async (req, res) => {
|
|
208
|
+
const owner = auth(req, res);
|
|
209
|
+
if (!owner)
|
|
210
|
+
return;
|
|
211
|
+
const result = await runUpgrade();
|
|
212
|
+
res.json(result);
|
|
213
|
+
});
|
|
214
|
+
async function runUpgrade() {
|
|
215
|
+
const rows = readStore(opts.storePath);
|
|
216
|
+
let upgraded = 0;
|
|
217
|
+
let checked = 0;
|
|
218
|
+
for (const row of rows) {
|
|
219
|
+
if (row.state !== 'pending')
|
|
220
|
+
continue;
|
|
221
|
+
checked += 1;
|
|
222
|
+
try {
|
|
223
|
+
const out = await upgrade(row.ots);
|
|
224
|
+
if (out.upgraded) {
|
|
225
|
+
row.state = 'bitcoin';
|
|
226
|
+
row.ots = out.ots ?? row.ots;
|
|
227
|
+
if (typeof out.block === 'number')
|
|
228
|
+
row.bitcoinBlock = out.block;
|
|
229
|
+
row.upgradedAt = new Date().toISOString();
|
|
230
|
+
upgraded += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// A calendar being unreachable is not a reason to lose the record.
|
|
235
|
+
// It stays pending and the next pass tries again.
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (upgraded)
|
|
239
|
+
rewriteStore(opts.storePath, rows);
|
|
240
|
+
return { checked, upgraded };
|
|
241
|
+
}
|
|
242
|
+
return { app, runUpgrade, readStore: () => readStore(opts.storePath) };
|
|
243
|
+
}
|
|
244
|
+
function publicView(r, base) {
|
|
245
|
+
return {
|
|
246
|
+
id: r.id,
|
|
247
|
+
hash: r.hash,
|
|
248
|
+
log: r.log,
|
|
249
|
+
state: r.state,
|
|
250
|
+
...(r.bitcoinBlock !== undefined ? { bitcoinBlock: r.bitcoinBlock } : {}),
|
|
251
|
+
submittedAt: r.submittedAt,
|
|
252
|
+
...(r.upgradedAt ? { upgradedAt: r.upgradedAt } : {}),
|
|
253
|
+
verify: `${base}/anchor/${r.id}/ots`,
|
|
254
|
+
claim: r.state === 'bitcoin'
|
|
255
|
+
? 'This hash existed no later than the Bitcoin block below. Conarium is not the time source — the OpenTimestamps calendars and Bitcoin are, and the proof above can be checked without us.'
|
|
256
|
+
: 'Submitted to the OpenTimestamps calendars. Until a Bitcoin block confirms it, this is a calendar promise and nothing stronger.',
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function esc(s) {
|
|
260
|
+
return s.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
261
|
+
}
|
|
262
|
+
function humanPage(r, base) {
|
|
263
|
+
const v = publicView(r, base);
|
|
264
|
+
return `<!doctype html><meta charset="utf-8"><title>Conarium anchor ${esc(r.id)}</title>
|
|
265
|
+
<body style="font:15px/1.6 system-ui,sans-serif;max-width:44rem;margin:3rem auto;padding:0 1rem">
|
|
266
|
+
<h1 style="font-size:1.3rem">Anchor ${esc(r.id)}</h1>
|
|
267
|
+
<table style="border-collapse:collapse">
|
|
268
|
+
<tr><td style="padding:.3rem 1rem .3rem 0;opacity:.7">hash</td><td><code>${esc(r.hash)}</code></td></tr>
|
|
269
|
+
<tr><td style="padding:.3rem 1rem .3rem 0;opacity:.7">state</td><td><code>${esc(r.state)}</code></td></tr>
|
|
270
|
+
${r.bitcoinBlock !== undefined ? `<tr><td style="padding:.3rem 1rem .3rem 0;opacity:.7">bitcoin block</td><td><code>${r.bitcoinBlock}</code></td></tr>` : ''}
|
|
271
|
+
<tr><td style="padding:.3rem 1rem .3rem 0;opacity:.7">submitted</td><td><code>${esc(r.submittedAt)}</code></td></tr>
|
|
272
|
+
</table>
|
|
273
|
+
<p>${esc(v.claim)}</p>
|
|
274
|
+
<p>Raw proof: <a href="${esc(v.verify)}">${esc(v.verify)}</a> — verify it with the reference
|
|
275
|
+
OpenTimestamps client if you would rather not take our word for anything.</p>
|
|
276
|
+
</body>`;
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=anchor-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor-service.js","sourceRoot":"","sources":["../src/anchor-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,+EAA+E;AAC/E,0DAA0D;AAC1D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AA2B9C,+EAA+E;AAC/E,iFAAiF;AACjF,MAAM,cAAc,GAAG,MAAM,CAAA;AAE7B,SAAS,OAAO;IACd,MAAM,GAAG,GAAG,OAAO,CAAC,2BAA2B,CAAQ,CAAA;IACvD,OAAO,GAAG,EAAE,OAAO,IAAI,GAAG,CAAA;AAC5B,CAAC;AAED,KAAK,UAA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