pactium 0.2.0 → 0.2.1

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.zh-CN.md CHANGED
@@ -1,15 +1,91 @@
1
- # Pactium
1
+ <p align="center">
2
+ <img src="docs/logo.svg" alt="Pactium" width="120" />
3
+ </p>
2
4
 
3
- Pactium 是 LicoLite 的 proof-first protocol substrate,用于证明系统状态是可记录、可回溯、可管理的。
5
+ <h1 align="center">Pactium</h1>
4
6
 
5
- ## 当前状态
7
+ <p align="center">
8
+ 证明优先的协议基底,提供可验证的操作事实、仅追加的恢复历史和密码学状态验证。
9
+ </p>
6
10
 
7
- - package root 只导出 proof-first API。
8
- - `pactium/licolite` 是 first-class LicoLite Aspect。
9
- - 数据目录采用 latest schema only;不会执行历史数据迁移。
10
- - Operation Intent / Operation Outcome 是 append-only 生命周期事实。
11
- - Workspace Projection 默认服务 LicoLite,并与 Ledger commit 同步更新。
12
- - Proof Envelope Proof Bundle 是主要 receipt/export 形状。
11
+ <p align="center">
12
+ <a href="https://github.com/Unka-Malloc/Pactium/actions/workflows/ci.yml"><img src="https://github.com/Unka-Malloc/Pactium/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
13
+ <a href="https://www.npmjs.com/package/pactium"><img src="https://img.shields.io/npm/v/pactium.svg" alt="npm version" /></a>
14
+ <a href="https://www.npmjs.com/package/pactium"><img src="https://img.shields.io/npm/dm/pactium.svg" alt="npm downloads" /></a>
15
+ <a href="https://github.com/Unka-Malloc/Pactium/blob/stable/LICENSE"><img src="https://img.shields.io/npm/l/pactium.svg" alt="license" /></a>
16
+ <a href="https://img.shields.io/node/v/pactium"><img src="https://img.shields.io/node/v/pactium.svg" alt="node version" /></a>
17
+ <img src="https://img.shields.io/badge/types-included-blue.svg" alt="TypeScript types" />
18
+ </p>
19
+
20
+ <p align="center">
21
+ <a href="./README.md">English</a> |
22
+ <a href="./docs/API.md">API 参考</a> |
23
+ <a href="./docs/protocols/PROTOCOLS.md">协议规范</a> |
24
+ <a href="https://github.com/Unka-Malloc/Pactium/blob/stable/CONTRIBUTING.md">贡献指南</a>
25
+ </p>
26
+
27
+ ---
28
+
29
+ ## 目录
30
+
31
+ - [为什么选择 Pactium](#为什么选择-pactium)
32
+ - [设计哲学](#设计哲学)
33
+ - [特性](#特性)
34
+ - [安装](#安装)
35
+ - [快速开始](#快速开始)
36
+ - [API 概览](#api-概览)
37
+ - [CLI 命令行](#cli-命令行)
38
+ - [架构](#架构)
39
+ - [适用场景](#适用场景)
40
+ - [文档](#文档)
41
+ - [运行环境](#运行环境)
42
+ - [验证](#验证)
43
+ - [贡献](#贡献)
44
+ - [许可证](#许可证)
45
+
46
+ ## 为什么选择 Pactium
47
+
48
+ 大多数系统将操作记录到可变数据库中,期望数据保持一致。当出现问题时——写入中途崩溃、静默损坏、争议操作——没有密码学证据证明发生了什么或没有发生什么。
49
+
50
+ Pactium 通过使**每个操作成为可验证事实**来解决这个问题:
51
+
52
+ - **仅追加账本** -- 操作不能被静默改写或删除
53
+ - **密码学证明** -- 每次写入都返回可独立验证的证明信封
54
+ - **可移植验证** -- 证明包可以在无需访问原始存储的情况下离线验证
55
+ - **工作空间隔离** -- 工作空间范围的投影,支持可验证的成员证明
56
+
57
+ Pactium 是一个零依赖的纯 ESM Node.js 包,提供密码学可验证的协议基底。它将操作事实记录到仅追加的透明日志中,维护工作空间范围的可验证索引投影,并生成可移植的证明信封和证明包,支持在无需访问原始存储的情况下独立验证。
58
+
59
+ Pactium 是 [LicoLite](https://github.com/Unka-Malloc) 的协议基底,通过 `pactium/licolite` 暴露一等集成界面。
60
+
61
+ ## 设计哲学
62
+
63
+ | 原则 | 含义 |
64
+ | --- | --- |
65
+ | **证明优先** | 写操作返回可验证的证明信封,而非存储确认。证明就是 API 响应。 |
66
+ | **仅追加事实** | 操作被记录为不可变的 Intent 和 Outcome 事实。修正创建带有因果引用的新事实,而非修改历史。 |
67
+ | **唯一排序权威** | Operation Ledger 是唯一的全局排序权威,所有其他结构从中派生排序。 |
68
+ | **可验证索引** | 每个索引(状态、工作空间、生命周期)使用相同的 Canonical Prolly Tree 引擎,支持成员和非成员证明。 |
69
+ | **宿主边界** | Pactium 拥有协议事实和证明,宿主系统拥有策略决策、副作用、授权和持久证据存储。 |
70
+ | **零依赖** | 无运行时依赖。直接发布源码。可预测的供应链。 |
71
+ | **协议,非配置** | 哈希算法、编码格式和分块参数是协议常量,不是宿主选项。更改需要新的协议版本。 |
72
+
73
+ ## 特性
74
+
75
+ | 能力 | 描述 |
76
+ | --- | --- |
77
+ | **Operation Ledger** | RFC 6962 风格透明日志,支持包含证明和一致性证明 |
78
+ | **仅追加生命周期** | Operation Intent / Outcome 事实,支持幂等重放 |
79
+ | **可验证索引引擎** | Canonical Prolly Tree,支持成员、非成员证明和高效差异比对 |
80
+ | **工作空间投影** | 可验证的工作空间范围顺序和成员索引 |
81
+ | **Merkle 状态** | 内容寻址的状态提交,绑定到操作结果 |
82
+ | **检查点树** | 可验证的恢复和进度结构 |
83
+ | **证明信封** | 跨证明收据,绑定账本、索引、状态和检查点证据 |
84
+ | **证明包** | 可移植的 CAR 格式导出,支持离线验证 |
85
+ | **签名头** | 可选的 Ed25519 账本头签名,配合验证者清单 |
86
+ | **LicoLite Aspect** | 一等集成界面,默认启用工作空间投影和签名 |
87
+ | **修复规划** | 从结构化验证失败中确定性地生成修复任务 |
88
+ | **零依赖** | 纯 ESM,无运行时依赖,直接发布源码 |
13
89
 
14
90
  ## 安装
15
91
 
@@ -17,74 +93,260 @@ Pactium 是 LicoLite 的 proof-first protocol substrate,用于证明系统状
17
93
  npm install pactium
18
94
  ```
19
95
 
20
- ## Root API
96
+ ```bash
97
+ pnpm add pactium
98
+ ```
99
+
100
+ ```bash
101
+ yarn add pactium
102
+ ```
103
+
104
+ ### 运行环境要求
105
+
106
+ - Node.js 22+ 或 Node.js 24+
107
+ - 仅 ESM(你的 `package.json` 中需要 `"type": "module"`)
108
+
109
+ ## 快速开始
110
+
111
+ ### 记录操作并获取完整证明
21
112
 
22
113
  ```js
23
114
  import { createPactium } from "pactium";
24
115
 
25
116
  const pactium = createPactium({ dataDir: "./.pactium" });
26
117
 
118
+ // 记录操作,返回可验证的证明信封
27
119
  const envelope = await pactium.recordOperation({
28
120
  operationId: "workspace.file.write",
29
121
  workspaceId: "workspace-a",
30
- idempotencyKey: "intent-a",
31
- outcomeIdempotencyKey: "outcome-a",
32
- input: { path: "docs/a.md" },
122
+ idempotencyKey: "intent-001",
123
+ outcomeIdempotencyKey: "outcome-001",
124
+ input: { path: "docs/readme.md" },
33
125
  stateMutations: [
34
- { key: "docs/a.md", value: { text: "hello" } }
126
+ { key: "docs/readme.md", value: { content: "hello world" } }
35
127
  ]
36
128
  });
37
129
 
38
- console.log(envelope.envelopeId);
39
- console.log(await pactium.verifyEnvelope(envelope));
130
+ // 验证信封
131
+ const result = await pactium.verifyEnvelope(envelope);
132
+ console.log(result.ok); // true
40
133
  ```
41
134
 
42
- ## LicoLite Aspect
135
+ ### 使用 LicoLite Aspect
43
136
 
44
137
  ```js
45
138
  import { createLicoLiteAspect, createLicoLiteSigner } from "pactium/licolite";
46
139
 
47
- const signingSecret = process.env.LICOLITE_SIGNING_SECRET;
48
- if (!signingSecret) throw new Error("LICOLITE_SIGNING_SECRET is required.");
49
-
50
140
  const licolite = createLicoLiteAspect({
51
141
  evidencePolicy: "production",
52
142
  signer: createLicoLiteSigner({
53
- signerId: "host-managed-signer",
54
- secret: signingSecret
143
+ signerId: "host-signer",
144
+ secret: process.env.LICOLITE_SIGNING_SECRET
55
145
  })
56
146
  });
57
147
 
58
148
  const envelope = await licolite.recordWorkspaceOperation({
59
- operationId: "workspace.effect",
149
+ operationId: "workspace.asset.upload",
60
150
  workspaceId: "workspace-a",
61
- policyEvidence: { decision: "allow" },
62
- workspaceEffectEvidence: { durableRef: "host:asset:a" }
151
+ policyEvidence: { decision: "allow", rule: "upload-permitted" },
152
+ workspaceEffectEvidence: { durableRef: "host:asset:image-001" }
63
153
  });
64
154
 
65
- console.log(await licolite.verifyEnvelope(envelope));
155
+ // LicoLite 级别验证:检查签名 + 关键扩展
156
+ const result = await licolite.verifyEnvelope(envelope);
157
+ console.log(result.ok); // true
158
+ ```
159
+
160
+ ### 导出和验证可移植证明包
161
+
162
+ ```js
163
+ import { createPactium, verifyProofBundle } from "pactium";
164
+
165
+ const pactium = createPactium({ dataDir: "./.pactium" });
166
+
167
+ // 将信封导出为可移植的证明包
168
+ const bundle = await pactium.exportProofBundle(envelope);
169
+
170
+ // 无需本地存储即可验证
171
+ const result = await verifyProofBundle(bundle);
172
+ console.log(result.ok); // true
173
+ ```
174
+
175
+ ## API 概览
176
+
177
+ Pactium 暴露两个包入口点:
178
+
179
+ | 导出 | 入口 | 描述 |
180
+ | --- | --- | --- |
181
+ | `pactium` | `./src/index.js` | 核心证明优先协议 API |
182
+ | `pactium/licolite` | `./src/aspects/licolite/index.js` | LicoLite 集成 Aspect |
183
+
184
+ ### TypeScript
185
+
186
+ Pactium 附带手工编写的 TypeScript 声明。所有公共类型均可从包入口点导入:
187
+
188
+ ```ts
189
+ import type {
190
+ PactiumCore,
191
+ PactiumProofEnvelope,
192
+ PactiumVerificationResult,
193
+ PactiumProofBundle,
194
+ PactiumLedgerHead,
195
+ PactiumVerificationFailure
196
+ } from "pactium";
197
+
198
+ import type {
199
+ LicoLiteAspect,
200
+ LicoLiteSigner
201
+ } from "pactium/licolite";
66
202
  ```
67
203
 
204
+ 完整 API 参考见 [docs/API.md](./docs/API.md)。
205
+
206
+ ## CLI 命令行
207
+
208
+ Pactium 提供 CLI 用于本地操作记录和验证:
209
+
210
+ ```bash
211
+ # 检查数据目录健康状态
212
+ pactium doctor --data-dir ./.pactium
213
+
214
+ # 启动 HTTP 验证服务器
215
+ pactium serve --port 7288
216
+
217
+ # 记录操作
218
+ pactium operation record --body '{"operationId":"test","workspaceId":"ws"}'
219
+
220
+ # 验证证明信封
221
+ pactium envelope verify --body-file ./envelope.json
222
+
223
+ # 验证证明包
224
+ pactium bundle verify --body-file ./bundle.json
225
+
226
+ # LicoLite 工作空间操作
227
+ pactium licolite record --body '{"operationId":"ws.op","workspaceId":"ws"}'
228
+ pactium licolite verify --body-file ./licolite-envelope.json
229
+ ```
230
+
231
+ CLI 从 `--body`、`--body-file` 或标准输入读取 JSON。
232
+
233
+ ## 架构
234
+
235
+ ```
236
+ 宿主系统 (LicoLite)
237
+ |
238
+ pactium/licolite
239
+ |
240
+ +--------------+---------------+
241
+ | Pactium 核心 |
242
+ | |
243
+ | +------------------------+ |
244
+ | | Canonical Value + Hash | |
245
+ | +------------------------+ |
246
+ | | Storage Port (CAS) | |
247
+ | +------------------------+ |
248
+ | | Operation Ledger | | <- 全局排序权威
249
+ | | (Transparency Log) | |
250
+ | +------------------------+ |
251
+ | | Verifiable Index Engine| | <- 共享 Prolly Tree
252
+ | +------------------------+ |
253
+ | | Workspace Projection | |
254
+ | | Merkle State | |
255
+ | | Checkpoint Tree | |
256
+ | | Lifecycle Indexes | |
257
+ | +------------------------+ |
258
+ | | Proof Envelopes | |
259
+ | | Proof Bundles | |
260
+ | +------------------------+ |
261
+ | | Repair Planner | |
262
+ | | Maintenance Engine | |
263
+ | +------------------------+ |
264
+ +------------------------------+
265
+ ```
266
+
267
+ **核心设计原则:**
268
+
269
+ - Operation Ledger 是唯一的全局排序权威
270
+ - 所有索引共享同一个可验证索引引擎(Canonical Prolly Tree)
271
+ - 写操作返回可验证的证明信封,而非存储记录
272
+ - 证明包支持无需原始存储的独立验证
273
+ - 宿主系统拥有策略、副作用和持久证据存储的所有权
274
+
275
+ 详细架构文档见 [docs/architecture/ARCHITECTURE.md](./docs/architecture/ARCHITECTURE.md)。
276
+
277
+ ## 适用场景
278
+
279
+ **适合使用 Pactium 的场景:**
280
+
281
+ - 需要操作被记录且账本一致的密码学证明
282
+ - 需要可移植的证明包,可在无需原始系统的情况下验证
283
+ - 需要工作空间范围的操作隔离及可验证的成员证明
284
+ - 需要仅追加的操作历史及确定性恢复
285
+ - 需要幂等操作记录及重放检测
286
+ - 需要可验证的状态根及高效差异比对
287
+
288
+ **Pactium 不适合:**
289
+
290
+ - 通用数据库存储(请使用数据库)
291
+ - 分布式节点间的网络共识(Pactium 是本地协议基底)
292
+ - 授权或访问控制(宿主系统拥有策略)
293
+ - 文件存储或 Blob 管理(Pactium 存储操作元数据和证明)
294
+
295
+ ## 文档
296
+
297
+ | 文档 | 描述 |
298
+ | --- | --- |
299
+ | [API 参考](./docs/API.md) | 完整的公共 API 文档 |
300
+ | [架构](./docs/architecture/ARCHITECTURE.md) | 系统架构和模块结构 |
301
+ | [协议规范](./docs/protocols/PROTOCOLS.md) | 协议行为和数据流 |
302
+ | [协议参数矩阵](./docs/protocols/PROFILE.md) | 协议参数矩阵 |
303
+ | [LicoLite Aspect](./docs/LICOLITE-ASPECT.md) | LicoLite 集成界面 |
304
+ | [术语表](./docs/TERM.md) | 协议词汇表 |
305
+ | [常见问题](./docs/FAQ.md) | 常见问题与故障排除 |
306
+ | [迁移指南](./docs/MIGRATION.md) | 版本兼容性与升级指导 |
307
+ | [示例指南](./examples/README.md) | 带注释的使用示例 |
308
+ | [质量门](https://github.com/Unka-Malloc/Pactium/blob/stable/docs/QUALITY-GATES.md) | 发布验证要求 |
309
+ | [ADR](https://github.com/Unka-Malloc/Pactium/tree/stable/docs/adr) | 架构决策记录(55 项决策) |
310
+
311
+ ## 运行环境
312
+
313
+ | 要求 | 版本 |
314
+ | --- | --- |
315
+ | Node.js | `^22.0.0 \|\| ^24.0.0` |
316
+ | 模块系统 | 仅 ESM (`"type": "module"`) |
317
+ | 运行时依赖 | 无 |
318
+
319
+ Pactium 是纯 ESM 包,不能从 CommonJS 模块中 `require()`。如需 CJS 互操作,请使用动态 `import()`。
320
+
68
321
  ## 验证
69
322
 
323
+ 本地运行完整发布门:
324
+
70
325
  ```bash
71
326
  npm run verify:release
72
327
  ```
73
328
 
74
- 完整压力 profile 可通过以下命令显式开启:
329
+ 这将运行覆盖率强制测试、协议证明向量、回归快照、种子属性测试、缩放公共 API 压力测试、卫生检查、包内容检查、打包干燥运行和发布干燥运行。
330
+
331
+ 完整计数压力测试(显式发布审查):
75
332
 
76
333
  ```bash
77
334
  PACTIUM_FULL_PRESSURE=1 npm run verify:protocol:gates
78
335
  ```
79
336
 
80
- ## 文档
337
+ ## 生态系统
338
+
339
+ | 包 | 描述 |
340
+ | --- | --- |
341
+ | [`pactium`](https://www.npmjs.com/package/pactium) | 核心协议基底(本包) |
342
+ | `pactium/licolite` | 一等 LicoLite 集成 Aspect(已包含) |
343
+
344
+ Pactium 是 [LicoLite](https://github.com/Unka-Malloc) 的协议基底。`pactium/licolite` Aspect 是一等包导出,而非外部插件。
345
+
346
+ ## 贡献
81
347
 
82
- - [Terms](./docs/TERM.md)
83
- - [Protocol Profile](./docs/protocols/PROFILE.md)
84
- - [Protocol Overview](./docs/protocols/PROTOCOLS.md)
85
- - [Architecture](./docs/architecture/ARCHITECTURE.md)
86
- - [LicoLite Aspect](./docs/LICOLITE-ASPECT.md)
348
+ 参见 [CONTRIBUTING.md](https://github.com/Unka-Malloc/Pactium/blob/stable/CONTRIBUTING.md) 了解开发环境设置、编码规范和提交指南。
87
349
 
88
350
  ## 许可证
89
351
 
90
- 本项目基于 [GNU General Public License v3.0 or later](LICENSE) 发布。
352
+ [GPL-3.0-or-later](./LICENSE) -- Copyright (c) Unka Y.Y.
package/SECURITY.md CHANGED
@@ -1,7 +1,90 @@
1
- # Security
1
+ # Security Policy
2
2
 
3
- Pactium records operation metadata and redacts common sensitive fields before writing ledger inputs.
3
+ ## Supported Versions
4
4
 
5
- Host systems remain responsible for authentication, authorization, network exposure, tenant isolation, and secret storage. Pactium should be embedded behind the host system's security boundary.
5
+ | Version | Supported |
6
+ | --- | --- |
7
+ | 0.2.x | Yes |
8
+ | < 0.2.0 | No |
6
9
 
7
- Please report security issues privately through the repository owner rather than opening a public issue with exploit details.
10
+ Only the latest released version receives security updates.
11
+
12
+ ## Scope
13
+
14
+ Pactium is a protocol substrate that records operation metadata and produces cryptographic proofs. Its security boundary includes:
15
+
16
+ - Canonical Value encoding and Protocol Hash integrity
17
+ - Ledger Transparency Log append-only guarantees
18
+ - Proof Envelope and Proof Bundle tamper detection
19
+ - Content-addressed storage integrity
20
+ - Signed Ledger Head verification
21
+ - Critical extension binding verification
22
+
23
+ ### Out of Scope
24
+
25
+ Host systems are responsible for:
26
+
27
+ - Authentication and authorization
28
+ - Network exposure and TLS termination
29
+ - Tenant isolation
30
+ - Secret management and key rotation
31
+ - Side-effect execution security
32
+ - Durable Host Evidence storage security
33
+
34
+ Pactium should be embedded behind the host system's security boundary.
35
+
36
+ ## Reporting a Vulnerability
37
+
38
+ **Do not open a public GitHub issue for security vulnerabilities.**
39
+
40
+ ### Preferred method
41
+
42
+ Report security issues privately through [GitHub Security Advisories](https://github.com/Unka-Malloc/Pactium/security/advisories/new).
43
+
44
+ ### Alternative method
45
+
46
+ If you cannot use GitHub Security Advisories, email the repository owner directly. Include:
47
+
48
+ 1. Description of the vulnerability
49
+ 2. Steps to reproduce
50
+ 3. Affected versions
51
+ 4. Potential impact assessment
52
+ 5. Suggested fix (if any)
53
+
54
+ ### What to expect
55
+
56
+ - **Acknowledgment**: within 72 hours of receipt
57
+ - **Initial assessment**: within 7 days
58
+ - **Fix timeline**: critical vulnerabilities targeted within 14 days; others within 30 days
59
+ - **Disclosure**: coordinated disclosure after a fix is available
60
+
61
+ ### What qualifies
62
+
63
+ - Proof forgery or proof bypass without detection
64
+ - Ledger append-only violation
65
+ - Hash collision exploitation in Protocol Hash
66
+ - Content-addressed storage integrity bypass
67
+ - Signed head signature bypass
68
+ - Critical extension binding circumvention
69
+ - Information disclosure through proof material
70
+
71
+ ### What does not qualify
72
+
73
+ - Denial of service through large inputs (Pactium is not a network service)
74
+ - Side-channel timing attacks on non-constant-time operations that are not signing verification
75
+ - Issues requiring physical access to the machine running Pactium
76
+ - Social engineering of host system users
77
+
78
+ ## Security Design
79
+
80
+ Pactium's proof model is designed so that:
81
+
82
+ - Every write operation produces a verifiable receipt (Proof Envelope)
83
+ - Ledger history cannot be silently rewritten (consistency proofs detect divergence)
84
+ - Proof material is content-addressed (tampering is detectable)
85
+ - Critical extensions must be understood by verifiers (unknown extensions fail verification)
86
+ - Repair operations are explicit ledger facts, not silent mutations
87
+
88
+ ## Acknowledgments
89
+
90
+ We appreciate responsible disclosure. Contributors who report valid security vulnerabilities will be acknowledged in the release notes (unless they prefer anonymity).