@otskit/mcp 0.2.1 → 0.3.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 +106 -106
- package/package.json +49 -49
- package/dist/chunk-4ZDPWS7C.js +0 -123
- package/dist/chunk-OMNHFTJW.js +0 -265
- package/dist/chunk-YFSUDT24.js +0 -24
- package/dist/claude-QTEB3Z5V.js +0 -54
- package/dist/claude-code-THJIWEHG.js +0 -48
- package/dist/cli-D7G2H6UT.js +0 -98
- package/dist/codex-P7EDO5GY.js +0 -41
- package/dist/index.js +0 -77
- package/dist/install-BUSOMBB2.js +0 -37
- package/dist/install-claude-UKSS65BW.js +0 -44
- package/dist/remove-BGFQRDX3.js +0 -17
- package/dist/scheduler-MTE6OUSV.js +0 -27
- package/dist/server-IDRHOKL7.js +0 -221
- package/dist/status-M6A2RG7G.js +0 -17
- package/dist/watch-7NPUWR6I.js +0 -41
package/README.md
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/OTSkit/OTSkit-MCP/master/docs/header.png" alt="OTSkit.ts MCP" width="480" />
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
# @otskit/mcp
|
|
6
|
-
|
|
7
|
-
[](https://github.com/OTSkit/OTSkit-MCP/actions/workflows/ci.yml)
|
|
8
|
-
[](https://www.npmjs.com/package/@otskit/mcp)
|
|
9
|
-
[](https://www.npmjs.com/package/@otskit/mcp)
|
|
10
|
-
[](https://www.typescriptlang.org/)
|
|
11
|
-
[](https://nodejs.org)
|
|
12
|
-
[](LICENSE)
|
|
13
|
-
|
|
14
|
-
OpenTimestamps MCP server — stamp, upgrade, and verify Bitcoin timestamps via AI agents.
|
|
15
|
-
|
|
16
|
-
Exposes a set of tools to any MCP-compatible agent so it can timestamp documents, monitor confirmation status, and verify proofs against the Bitcoin blockchain — all from a conversation.
|
|
17
|
-
|
|
18
|
-
> **Note on confirmation times:** After stamping, a proof is `pending` until Bitcoin confirms it. This typically takes **10–60 minutes** but can take **several hours** during network congestion. Use `ots-mcp watch` or `upgrade_timestamp` to monitor. A pending status is not an error.
|
|
19
|
-
|
|
20
|
-
## Install
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install -g @otskit/mcp
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Agent setup
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
ots-mcp setup claude # Claude Desktop
|
|
30
|
-
ots-mcp setup claude-code # Claude Code CLI
|
|
31
|
-
ots-mcp setup codex # Codex CLI
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Each command writes the MCP entry into the agent's config file, makes a `.bak` backup if the file already exists, and skips if `ots-mcp` is already configured. Restart the agent afterwards to apply the changes.
|
|
35
|
-
|
|
36
|
-
## CLI commands
|
|
37
|
-
|
|
38
|
-
| Command | Description |
|
|
39
|
-
|---|---|
|
|
40
|
-
| `ots-mcp serve` | Start the MCP server (stdio transport) |
|
|
41
|
-
| `ots-mcp stamp <sha256>` | Stamp a SHA-256 hash against Bitcoin calendars |
|
|
42
|
-
| `ots-mcp upgrade <id>` | Check if a pending stamp has been confirmed |
|
|
43
|
-
| `ots-mcp verify <id>` | Verify a stamp against Bitcoin |
|
|
44
|
-
| `ots-mcp list [status]` | List stamps (`pending` / `confirmed` / `failed`) |
|
|
45
|
-
| `ots-mcp watch [minutes]` | Poll pending stamps in real-time (default: 5 min) |
|
|
46
|
-
| `ots-mcp check-pending` | Run one upgrade pass over all pending stamps |
|
|
47
|
-
| `ots-mcp scheduler install\|remove\|status` | Manage OS-level scheduler for auto-upgrades |
|
|
48
|
-
| `ots-mcp backup [dest]` | Backup the SQLite database |
|
|
49
|
-
| `ots-mcp setup <claude\|claude-code\|codex>` | Configure MCP for an agent |
|
|
50
|
-
|
|
51
|
-
## MCP tools exposed to agents
|
|
52
|
-
|
|
53
|
-
| Tool | Description |
|
|
54
|
-
|---|---|
|
|
55
|
-
| `create_timestamp` | Stamp a SHA-256 hash against 4 public OTS calendars |
|
|
56
|
-
| `upgrade_timestamp` | Check if a pending stamp has been confirmed in Bitcoin |
|
|
57
|
-
| `verify_timestamp` | Verify a stamp — proves hash existed before a given Bitcoin block |
|
|
58
|
-
| `inspect_timestamp` | Inspect a stored proof file without network calls |
|
|
59
|
-
| `list_pending` | List stamps with status, retry count, and filters |
|
|
60
|
-
| `watch` | Open a terminal window monitoring pending stamps in real-time |
|
|
61
|
-
|
|
62
|
-
## Data directory
|
|
63
|
-
|
|
64
|
-
All data is stored in `~/.ots-mcp/`:
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
~/.ots-mcp/
|
|
68
|
-
ots-mcp.db # SQLite database (stamps, proof files)
|
|
69
|
-
config.json # Optional config overrides
|
|
70
|
-
ots-mcp.log # Log file
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Configuration
|
|
74
|
-
|
|
75
|
-
Create `~/.ots-mcp/config.json` to override defaults:
|
|
76
|
-
|
|
77
|
-
```json
|
|
78
|
-
{
|
|
79
|
-
"stamp_enabled": true,
|
|
80
|
-
"scheduler_interval_minutes": 30,
|
|
81
|
-
"retry_max_attempts": 20,
|
|
82
|
-
"calendar_timeout_ms": 10000,
|
|
83
|
-
"esplora_url": "https://blockstream.info/api",
|
|
84
|
-
"calendars": [
|
|
85
|
-
"https://alice.btc.calendar.opentimestamps.org",
|
|
86
|
-
"https://bob.btc.calendar.opentimestamps.org",
|
|
87
|
-
"https://finney.calendar.eternitywall.com",
|
|
88
|
-
"https://btc.calendar.catallaxy.com"
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Development
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
npm run build # production build
|
|
97
|
-
npm run dev # watch mode
|
|
98
|
-
npm test # run tests
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Dependencies
|
|
102
|
-
|
|
103
|
-
- [`@otskit/core`](https://github.com/AlexAlves87/otskit-core) — OpenTimestamps core logic
|
|
104
|
-
- [`@otskit/client`](https://github.com/AlexAlves87/otskit-client) — OTS calendar client
|
|
105
|
-
- [`@modelcontextprotocol/sdk`](https://github.com/modelcontextprotocol/typescript-sdk) — MCP SDK
|
|
106
|
-
- `better-sqlite3` — local database
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/OTSkit/OTSkit-MCP/master/docs/header.png" alt="OTSkit.ts MCP" width="480" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @otskit/mcp
|
|
6
|
+
|
|
7
|
+
[](https://github.com/OTSkit/OTSkit-MCP/actions/workflows/ci.yml)
|
|
8
|
+
[](https://www.npmjs.com/package/@otskit/mcp)
|
|
9
|
+
[](https://www.npmjs.com/package/@otskit/mcp)
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
[](https://nodejs.org)
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
|
|
14
|
+
OpenTimestamps MCP server — stamp, upgrade, and verify Bitcoin timestamps via AI agents.
|
|
15
|
+
|
|
16
|
+
Exposes a set of tools to any MCP-compatible agent so it can timestamp documents, monitor confirmation status, and verify proofs against the Bitcoin blockchain — all from a conversation.
|
|
17
|
+
|
|
18
|
+
> **Note on confirmation times:** After stamping, a proof is `pending` until Bitcoin confirms it. This typically takes **10–60 minutes** but can take **several hours** during network congestion. Use `ots-mcp watch` or `upgrade_timestamp` to monitor. A pending status is not an error.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g @otskit/mcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Agent setup
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
ots-mcp setup claude # Claude Desktop
|
|
30
|
+
ots-mcp setup claude-code # Claude Code CLI
|
|
31
|
+
ots-mcp setup codex # Codex CLI
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Each command writes the MCP entry into the agent's config file, makes a `.bak` backup if the file already exists, and skips if `ots-mcp` is already configured. Restart the agent afterwards to apply the changes.
|
|
35
|
+
|
|
36
|
+
## CLI commands
|
|
37
|
+
|
|
38
|
+
| Command | Description |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `ots-mcp serve` | Start the MCP server (stdio transport) |
|
|
41
|
+
| `ots-mcp stamp <sha256>` | Stamp a SHA-256 hash against Bitcoin calendars |
|
|
42
|
+
| `ots-mcp upgrade <id>` | Check if a pending stamp has been confirmed |
|
|
43
|
+
| `ots-mcp verify <id>` | Verify a stamp against Bitcoin |
|
|
44
|
+
| `ots-mcp list [status]` | List stamps (`pending` / `confirmed` / `failed`) |
|
|
45
|
+
| `ots-mcp watch [minutes]` | Poll pending stamps in real-time (default: 5 min) |
|
|
46
|
+
| `ots-mcp check-pending` | Run one upgrade pass over all pending stamps |
|
|
47
|
+
| `ots-mcp scheduler install\|remove\|status` | Manage OS-level scheduler for auto-upgrades |
|
|
48
|
+
| `ots-mcp backup [dest]` | Backup the SQLite database |
|
|
49
|
+
| `ots-mcp setup <claude\|claude-code\|codex>` | Configure MCP for an agent |
|
|
50
|
+
|
|
51
|
+
## MCP tools exposed to agents
|
|
52
|
+
|
|
53
|
+
| Tool | Description |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `create_timestamp` | Stamp a SHA-256 hash against 4 public OTS calendars |
|
|
56
|
+
| `upgrade_timestamp` | Check if a pending stamp has been confirmed in Bitcoin |
|
|
57
|
+
| `verify_timestamp` | Verify a stamp — proves hash existed before a given Bitcoin block |
|
|
58
|
+
| `inspect_timestamp` | Inspect a stored proof file without network calls |
|
|
59
|
+
| `list_pending` | List stamps with status, retry count, and filters |
|
|
60
|
+
| `watch` | Open a terminal window monitoring pending stamps in real-time |
|
|
61
|
+
|
|
62
|
+
## Data directory
|
|
63
|
+
|
|
64
|
+
All data is stored in `~/.ots-mcp/`:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
~/.ots-mcp/
|
|
68
|
+
ots-mcp.db # SQLite database (stamps, proof files)
|
|
69
|
+
config.json # Optional config overrides
|
|
70
|
+
ots-mcp.log # Log file
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
Create `~/.ots-mcp/config.json` to override defaults:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"stamp_enabled": true,
|
|
80
|
+
"scheduler_interval_minutes": 30,
|
|
81
|
+
"retry_max_attempts": 20,
|
|
82
|
+
"calendar_timeout_ms": 10000,
|
|
83
|
+
"esplora_url": "https://blockstream.info/api",
|
|
84
|
+
"calendars": [
|
|
85
|
+
"https://alice.btc.calendar.opentimestamps.org",
|
|
86
|
+
"https://bob.btc.calendar.opentimestamps.org",
|
|
87
|
+
"https://finney.calendar.eternitywall.com",
|
|
88
|
+
"https://btc.calendar.catallaxy.com"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm run build # production build
|
|
97
|
+
npm run dev # watch mode
|
|
98
|
+
npm test # run tests
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Dependencies
|
|
102
|
+
|
|
103
|
+
- [`@otskit/core`](https://github.com/AlexAlves87/otskit-core) — OpenTimestamps core logic
|
|
104
|
+
- [`@otskit/client`](https://github.com/AlexAlves87/otskit-client) — OTS calendar client
|
|
105
|
+
- [`@modelcontextprotocol/sdk`](https://github.com/modelcontextprotocol/typescript-sdk) — MCP SDK
|
|
106
|
+
- `better-sqlite3` — local database
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@otskit/mcp",
|
|
3
|
-
"mcpName": "io.github.
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "OpenTimestamps MCP server — stamp, upgrade, verify via AI agents",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"engines": {
|
|
8
|
-
"node": ">=18"
|
|
9
|
-
},
|
|
10
|
-
"bin": {
|
|
11
|
-
"ots-mcp": "dist/index.js"
|
|
12
|
-
},
|
|
13
|
-
"exports": "./dist/index.js",
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "tsup src/index.ts --format esm --clean",
|
|
19
|
-
"dev": "tsup src/index.ts --format esm --watch",
|
|
20
|
-
"test": "vitest run",
|
|
21
|
-
"test:watch": "vitest"
|
|
22
|
-
},
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
25
|
-
"@otskit/client": "^0.1.1",
|
|
26
|
-
"@otskit/core": "^0.1.0",
|
|
27
|
-
"better-sqlite3": "^12.10.0"
|
|
28
|
-
},
|
|
29
|
-
"pnpm": {
|
|
30
|
-
"onlyBuiltDependencies": [
|
|
31
|
-
"better-sqlite3",
|
|
32
|
-
"esbuild"
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@semantic-release/changelog": "^6",
|
|
37
|
-
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
38
|
-
"@semantic-release/git": "^10",
|
|
39
|
-
"@semantic-release/github": "^12.0.8",
|
|
40
|
-
"@semantic-release/npm": "^13.1.5",
|
|
41
|
-
"@semantic-release/release-notes-generator": "^14.0.0",
|
|
42
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
43
|
-
"@types/node": "^25.9.1",
|
|
44
|
-
"semantic-release": "^25.0.3",
|
|
45
|
-
"tsup": "^8.3.5",
|
|
46
|
-
"typescript": "^6.0.3",
|
|
47
|
-
"vitest": "^2.1.4"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@otskit/mcp",
|
|
3
|
+
"mcpName": "io.github.otskit/otskit-mcp",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"description": "OpenTimestamps MCP server — stamp, upgrade, verify via AI agents",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"ots-mcp": "dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"exports": "./dist/index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup src/index.ts --format esm --clean",
|
|
19
|
+
"dev": "tsup src/index.ts --format esm --watch",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
25
|
+
"@otskit/client": "^0.1.1",
|
|
26
|
+
"@otskit/core": "^0.1.0",
|
|
27
|
+
"better-sqlite3": "^12.10.0"
|
|
28
|
+
},
|
|
29
|
+
"pnpm": {
|
|
30
|
+
"onlyBuiltDependencies": [
|
|
31
|
+
"better-sqlite3",
|
|
32
|
+
"esbuild"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@semantic-release/changelog": "^6",
|
|
37
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
38
|
+
"@semantic-release/git": "^10",
|
|
39
|
+
"@semantic-release/github": "^12.0.8",
|
|
40
|
+
"@semantic-release/npm": "^13.1.5",
|
|
41
|
+
"@semantic-release/release-notes-generator": "^14.0.0",
|
|
42
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
43
|
+
"@types/node": "^25.9.1",
|
|
44
|
+
"semantic-release": "^25.0.3",
|
|
45
|
+
"tsup": "^8.3.5",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"vitest": "^2.1.4"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/chunk-4ZDPWS7C.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// src/config.ts
|
|
2
|
-
import { readFileSync, existsSync, mkdirSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { homedir } from "os";
|
|
5
|
-
function getDataDir() {
|
|
6
|
-
return process.env.OTS_MCP_DATA_DIR ?? join(homedir(), ".ots-mcp");
|
|
7
|
-
}
|
|
8
|
-
var DEFAULTS = {
|
|
9
|
-
stamp_enabled: true,
|
|
10
|
-
preserve_enabled: true,
|
|
11
|
-
preserve_whitelist: [],
|
|
12
|
-
preserve_max_bytes: 104857600,
|
|
13
|
-
preserve_max_files: 1e4,
|
|
14
|
-
scheduler_interval_minutes: 30,
|
|
15
|
-
calendar_timeout_ms: 1e4,
|
|
16
|
-
calendar_max_response_bytes: 1048576,
|
|
17
|
-
retry_max_attempts: 20,
|
|
18
|
-
log_file: join(getDataDir(), "ots-mcp.log"),
|
|
19
|
-
calendars: [
|
|
20
|
-
"https://alice.btc.calendar.opentimestamps.org",
|
|
21
|
-
"https://bob.btc.calendar.opentimestamps.org",
|
|
22
|
-
"https://finney.calendar.eternitywall.com",
|
|
23
|
-
"https://btc.calendar.catallaxy.com"
|
|
24
|
-
],
|
|
25
|
-
esplora_url: "https://blockstream.info/api"
|
|
26
|
-
};
|
|
27
|
-
function loadConfig() {
|
|
28
|
-
const dir = getDataDir();
|
|
29
|
-
mkdirSync(dir, { recursive: true });
|
|
30
|
-
const configPath = join(dir, "config.json");
|
|
31
|
-
if (!existsSync(configPath)) return { ...DEFAULTS };
|
|
32
|
-
const raw = JSON.parse(readFileSync(configPath, "utf8"));
|
|
33
|
-
return { ...DEFAULTS, ...raw };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/db/index.ts
|
|
37
|
-
import DatabaseConstructor from "better-sqlite3";
|
|
38
|
-
import { join as join2 } from "path";
|
|
39
|
-
import { mkdirSync as mkdirSync2, statSync } from "fs";
|
|
40
|
-
|
|
41
|
-
// src/db/schema.ts
|
|
42
|
-
function initDb(db) {
|
|
43
|
-
db.pragma("journal_mode = WAL");
|
|
44
|
-
db.pragma("busy_timeout = 5000");
|
|
45
|
-
db.pragma("foreign_keys = ON");
|
|
46
|
-
runMigrations(db);
|
|
47
|
-
}
|
|
48
|
-
function runMigrations(db) {
|
|
49
|
-
const version = db.pragma("user_version", { simple: true });
|
|
50
|
-
if (version < 1) migrateTo1(db);
|
|
51
|
-
}
|
|
52
|
-
function migrateTo1(db) {
|
|
53
|
-
db.transaction(() => {
|
|
54
|
-
db.exec(`
|
|
55
|
-
CREATE TABLE IF NOT EXISTS stamps (
|
|
56
|
-
id TEXT PRIMARY KEY,
|
|
57
|
-
hash TEXT NOT NULL,
|
|
58
|
-
status TEXT NOT NULL,
|
|
59
|
-
created_at TEXT NOT NULL,
|
|
60
|
-
confirmed_at TEXT,
|
|
61
|
-
bitcoin_block INTEGER,
|
|
62
|
-
bitcoin_time TEXT,
|
|
63
|
-
proof_path TEXT,
|
|
64
|
-
archive_path TEXT,
|
|
65
|
-
last_attempt_at TEXT,
|
|
66
|
-
attempt_count INTEGER NOT NULL DEFAULT 0,
|
|
67
|
-
last_error TEXT,
|
|
68
|
-
next_retry_at TEXT,
|
|
69
|
-
metadata TEXT
|
|
70
|
-
);
|
|
71
|
-
CREATE INDEX IF NOT EXISTS idx_stamps_hash ON stamps(hash);
|
|
72
|
-
CREATE INDEX IF NOT EXISTS idx_stamps_status ON stamps(status);
|
|
73
|
-
|
|
74
|
-
CREATE TABLE IF NOT EXISTS operations_log (
|
|
75
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
76
|
-
stamp_id TEXT NOT NULL REFERENCES stamps(id),
|
|
77
|
-
action TEXT NOT NULL,
|
|
78
|
-
result TEXT NOT NULL,
|
|
79
|
-
error_msg TEXT,
|
|
80
|
-
calendar_uri TEXT,
|
|
81
|
-
response_time_ms INTEGER,
|
|
82
|
-
created_at TEXT NOT NULL
|
|
83
|
-
);
|
|
84
|
-
CREATE INDEX IF NOT EXISTS idx_oplog_stamp_id ON operations_log(stamp_id);
|
|
85
|
-
CREATE INDEX IF NOT EXISTS idx_oplog_created ON operations_log(created_at);
|
|
86
|
-
`);
|
|
87
|
-
db.pragma("user_version = 1");
|
|
88
|
-
})();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/db/index.ts
|
|
92
|
-
var _db = null;
|
|
93
|
-
function getDb() {
|
|
94
|
-
if (_db) return _db;
|
|
95
|
-
const dir = getDataDir();
|
|
96
|
-
mkdirSync2(dir, { recursive: true });
|
|
97
|
-
_db = new DatabaseConstructor(join2(dir, "db.sqlite"));
|
|
98
|
-
initDb(_db);
|
|
99
|
-
reconcileOrphans(_db);
|
|
100
|
-
return _db;
|
|
101
|
-
}
|
|
102
|
-
function backupDb(destPath) {
|
|
103
|
-
getDb().backup(destPath);
|
|
104
|
-
}
|
|
105
|
-
function reconcileOrphans(db) {
|
|
106
|
-
const pending = db.prepare(
|
|
107
|
-
`SELECT id, proof_path FROM stamps WHERE status = 'pending' AND proof_path IS NOT NULL`
|
|
108
|
-
).all();
|
|
109
|
-
for (const row of pending) {
|
|
110
|
-
try {
|
|
111
|
-
statSync(row.proof_path);
|
|
112
|
-
} catch {
|
|
113
|
-
db.prepare(`UPDATE stamps SET status = 'failed', last_error = ? WHERE id = ?`).run("proof file missing on disk", row.id);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export {
|
|
119
|
-
getDataDir,
|
|
120
|
-
loadConfig,
|
|
121
|
-
getDb,
|
|
122
|
-
backupDb
|
|
123
|
-
};
|