@peac/protocol 0.12.5 → 0.12.6
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 +61 -37
- package/package.json +18 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @peac/protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Receipt issuance and verification for the PEAC protocol.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,54 +10,77 @@ pnpm add @peac/protocol
|
|
|
10
10
|
|
|
11
11
|
## What It Does
|
|
12
12
|
|
|
13
|
-
`@peac/protocol` is Layer 3 of the PEAC stack. It provides `issue()`
|
|
13
|
+
`@peac/protocol` is Layer 3 of the PEAC protocol stack. It provides the high-level `issue()` and `verifyLocal()` APIs for creating and verifying signed interaction receipts in the Interaction Record format. It handles schema validation, kernel constraint enforcement, JOSE hardening, strictness profiles, policy binding, and structured error reporting.
|
|
14
14
|
|
|
15
|
-
## How Do I
|
|
15
|
+
## How Do I Use It?
|
|
16
|
+
|
|
17
|
+
### Issue a signed receipt
|
|
16
18
|
|
|
17
19
|
```typescript
|
|
18
|
-
import { generateKeypair } from '@peac/
|
|
19
|
-
import { issue } from '@peac/protocol';
|
|
20
|
+
import { issue, generateKeypair } from '@peac/protocol';
|
|
20
21
|
|
|
21
|
-
const {
|
|
22
|
+
const { privateKey, publicKey } = await generateKeypair();
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
iss: 'https://
|
|
24
|
+
const result = await issue({
|
|
25
|
+
iss: 'https://example.com',
|
|
25
26
|
kind: 'evidence',
|
|
26
|
-
type: 'org.peacprotocol/
|
|
27
|
+
type: 'org.peacprotocol/commerce',
|
|
28
|
+
privateKey,
|
|
29
|
+
kid: 'key-1',
|
|
27
30
|
pillars: ['commerce'],
|
|
28
31
|
extensions: {
|
|
29
32
|
'org.peacprotocol/commerce': {
|
|
30
|
-
|
|
31
|
-
amount_minor: '
|
|
33
|
+
rail: 'stripe',
|
|
34
|
+
amount_minor: '1000',
|
|
32
35
|
currency: 'USD',
|
|
36
|
+
event: 'authorization',
|
|
33
37
|
},
|
|
34
38
|
},
|
|
35
|
-
privateKey,
|
|
36
|
-
kid: 'key-2026-02',
|
|
37
39
|
});
|
|
40
|
+
|
|
41
|
+
console.log(result.jws); // compact JWS string
|
|
38
42
|
```
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
### Verify a receipt locally
|
|
41
45
|
|
|
42
46
|
```typescript
|
|
43
47
|
import { verifyLocal } from '@peac/protocol';
|
|
44
48
|
|
|
45
|
-
const result = await verifyLocal(jws, publicKey
|
|
49
|
+
const result = await verifyLocal(jws, publicKey, {
|
|
50
|
+
issuer: 'https://example.com',
|
|
51
|
+
strictness: 'strict',
|
|
52
|
+
});
|
|
46
53
|
|
|
47
|
-
if (result.valid
|
|
48
|
-
console.log(result.claims.
|
|
49
|
-
console.log(result.claims.kind); // evidence
|
|
50
|
-
console.log(result.
|
|
51
|
-
|
|
52
|
-
console.log(result.
|
|
54
|
+
if (result.valid) {
|
|
55
|
+
console.log(result.claims.type); // 'org.peacprotocol/commerce'
|
|
56
|
+
console.log(result.claims.kind); // 'evidence'
|
|
57
|
+
console.log(result.kid); // 'key-1'
|
|
58
|
+
console.log(result.warnings); // VerificationWarning[]
|
|
59
|
+
console.log(result.policy_binding); // 'unavailable' | 'verified'
|
|
60
|
+
} else {
|
|
61
|
+
console.log(result.code); // e.g., 'E_INVALID_SIGNATURE'
|
|
62
|
+
console.log(result.message);
|
|
53
63
|
}
|
|
54
64
|
```
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
### Verify with policy binding
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { verifyLocal, computePolicyDigestJcs } from '@peac/protocol';
|
|
70
|
+
|
|
71
|
+
const policyDoc = { rules: [{ action: 'allow', resource: '/api/*' }] };
|
|
72
|
+
const digest = await computePolicyDigestJcs(policyDoc);
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
const result = await verifyLocal(jws, publicKey, {
|
|
75
|
+
policyDigest: digest,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (result.valid) {
|
|
79
|
+
console.log(result.policy_binding); // 'verified' if receipt policy matches
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Verify with JWKS discovery
|
|
61
84
|
|
|
62
85
|
```typescript
|
|
63
86
|
import { verifyLocal } from '@peac/protocol';
|
|
@@ -69,25 +92,26 @@ const result = await verifyLocal(jws, resolvedPublicKey, {
|
|
|
69
92
|
});
|
|
70
93
|
|
|
71
94
|
if (result.valid) {
|
|
72
|
-
console.log(
|
|
73
|
-
} else {
|
|
74
|
-
console.log(result.code, result.message);
|
|
95
|
+
console.log(result.claims.iss);
|
|
75
96
|
}
|
|
76
97
|
```
|
|
77
98
|
|
|
78
99
|
## Integrates With
|
|
79
100
|
|
|
80
|
-
- `@peac/
|
|
81
|
-
- `@peac/
|
|
82
|
-
- `@peac/
|
|
83
|
-
- `@peac/mcp-server` (Layer 5): MCP tool server
|
|
84
|
-
- `@peac/
|
|
101
|
+
- `@peac/kernel` (Layer 0): Constants, types, and error codes
|
|
102
|
+
- `@peac/schema` (Layer 1): Zod schemas and claim validation
|
|
103
|
+
- `@peac/crypto` (Layer 2): Ed25519 signing and JWS creation (re-exported for convenience)
|
|
104
|
+
- `@peac/mcp-server` (Layer 5): MCP tool server built on this package
|
|
105
|
+
- All `@peac/adapter-*` and `@peac/mappings-*` packages (Layer 4)
|
|
106
|
+
|
|
107
|
+
## For Agent Developers
|
|
85
108
|
|
|
86
|
-
|
|
109
|
+
If you are building an AI agent or MCP server that needs signed interaction receipts:
|
|
87
110
|
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
111
|
+
- Start with [`@peac/mcp-server`](https://www.npmjs.com/package/@peac/mcp-server) for a ready-to-use MCP tool server
|
|
112
|
+
- Use `issue()` to create receipts and `verifyLocal()` to verify them when you have the public key
|
|
113
|
+
- Common crypto utilities (`generateKeypair`, `base64urlEncode`, `sha256Hex`, `verify`) are re-exported from `@peac/crypto` so a single import is sufficient for most workflows
|
|
114
|
+
- See the [llms.txt](https://github.com/peacprotocol/peac/blob/main/llms.txt) for a concise overview
|
|
91
115
|
|
|
92
116
|
## License
|
|
93
117
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peac/protocol",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.6",
|
|
4
4
|
"description": "PEAC protocol implementation - receipt issuance and verification",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "https://github.com/peacprotocol/peac.git",
|
|
23
|
+
"url": "git+https://github.com/peacprotocol/peac.git",
|
|
24
24
|
"directory": "packages/protocol"
|
|
25
25
|
},
|
|
26
|
-
"author": "
|
|
26
|
+
"author": "PEAC Protocol Contributors",
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/peacprotocol/peac/issues"
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"uuidv7": "^0.6.3",
|
|
41
41
|
"zod": "^4.3.6",
|
|
42
|
-
"@peac/kernel": "0.12.
|
|
43
|
-
"@peac/schema": "0.12.
|
|
44
|
-
"@peac/crypto": "0.12.
|
|
42
|
+
"@peac/kernel": "0.12.6",
|
|
43
|
+
"@peac/schema": "0.12.6",
|
|
44
|
+
"@peac/crypto": "0.12.6"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^22.19.11",
|
|
@@ -49,6 +49,18 @@
|
|
|
49
49
|
"vitest": "^4.0.0",
|
|
50
50
|
"tsup": "^8.0.0"
|
|
51
51
|
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"peac",
|
|
54
|
+
"peacprotocol",
|
|
55
|
+
"interaction-records",
|
|
56
|
+
"signed-records",
|
|
57
|
+
"receipts",
|
|
58
|
+
"originary",
|
|
59
|
+
"verification",
|
|
60
|
+
"issuance",
|
|
61
|
+
"receipt-verification",
|
|
62
|
+
"policy-binding"
|
|
63
|
+
],
|
|
52
64
|
"scripts": {
|
|
53
65
|
"prebuild": "rm -rf dist",
|
|
54
66
|
"build": "pnpm run build:js && pnpm run build:types",
|