@peac/protocol 0.12.0-preview.2 → 0.12.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.md +25 -13
- package/dist/index.cjs +7 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -4
- package/dist/index.mjs.map +1 -1
- package/dist/issue.d.ts +36 -12
- package/dist/issue.d.ts.map +1 -1
- package/dist/verify-local.cjs +1 -1
- package/dist/verify-local.cjs.map +1 -1
- package/dist/verify-local.d.ts +1 -1
- package/dist/verify-local.mjs +1 -1
- package/dist/verify-local.mjs.map +1 -1
- package/dist/verify.d.ts +11 -4
- package/dist/verify.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -22,11 +22,16 @@ const { publicKey, privateKey } = await generateKeypair();
|
|
|
22
22
|
|
|
23
23
|
const { jws } = await issue({
|
|
24
24
|
iss: 'https://api.example.com',
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
kind: 'evidence',
|
|
26
|
+
type: 'org.peacprotocol/payment',
|
|
27
|
+
pillars: ['commerce'],
|
|
28
|
+
extensions: {
|
|
29
|
+
'org.peacprotocol/commerce': {
|
|
30
|
+
payment_rail: 'stripe',
|
|
31
|
+
amount_minor: '10000',
|
|
32
|
+
currency: 'USD',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
30
35
|
privateKey,
|
|
31
36
|
kid: 'key-2026-02',
|
|
32
37
|
});
|
|
@@ -39,10 +44,10 @@ import { verifyLocal } from '@peac/protocol';
|
|
|
39
44
|
|
|
40
45
|
const result = await verifyLocal(jws, publicKey);
|
|
41
46
|
|
|
42
|
-
if (result.valid && result.
|
|
47
|
+
if (result.valid && result.wireVersion === '0.2') {
|
|
43
48
|
console.log(result.claims.iss); // issuer
|
|
44
|
-
console.log(result.claims.
|
|
45
|
-
console.log(result.claims.
|
|
49
|
+
console.log(result.claims.kind); // evidence
|
|
50
|
+
console.log(result.claims.type); // org.peacprotocol/payment
|
|
46
51
|
} else if (!result.valid) {
|
|
47
52
|
console.log(result.code, result.message);
|
|
48
53
|
}
|
|
@@ -50,16 +55,23 @@ if (result.valid && result.variant === 'commerce') {
|
|
|
50
55
|
|
|
51
56
|
## How Do I Verify with JWKS Discovery?
|
|
52
57
|
|
|
58
|
+
> **Note:** `verifyReceipt()` is deprecated (Wire 0.1 only). For Wire 0.2 receipts,
|
|
59
|
+
> resolve the issuer's JWKS manually and pass the public key to `verifyLocal()`.
|
|
60
|
+
> Automated JWKS discovery for Wire 0.2 is planned for a future release.
|
|
61
|
+
|
|
53
62
|
```typescript
|
|
54
|
-
import {
|
|
63
|
+
import { verifyLocal } from '@peac/protocol';
|
|
55
64
|
|
|
56
|
-
//
|
|
57
|
-
|
|
65
|
+
// 1. Resolve issuer's /.well-known/peac-issuer.json -> jwks_uri -> public key
|
|
66
|
+
// 2. Pass the resolved key to verifyLocal()
|
|
67
|
+
const result = await verifyLocal(jws, resolvedPublicKey, {
|
|
68
|
+
issuer: 'https://api.example.com',
|
|
69
|
+
});
|
|
58
70
|
|
|
59
|
-
if (result.
|
|
71
|
+
if (result.valid) {
|
|
60
72
|
console.log('Issuer:', result.claims.iss);
|
|
61
73
|
} else {
|
|
62
|
-
console.log(result.
|
|
74
|
+
console.log(result.code, result.message);
|
|
63
75
|
}
|
|
64
76
|
```
|
|
65
77
|
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var IssueError = class extends Error {
|
|
|
35
35
|
this.peacError = peacError;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
async function
|
|
38
|
+
async function issueWire01(options) {
|
|
39
39
|
if (!options.iss.startsWith("https://")) {
|
|
40
40
|
throw new Error("Issuer URL must start with https://");
|
|
41
41
|
}
|
|
@@ -176,9 +176,12 @@ async function issue(options) {
|
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
async function issueJws(options) {
|
|
179
|
-
const result = await
|
|
179
|
+
const result = await issueWire01(options);
|
|
180
180
|
return result.jws;
|
|
181
181
|
}
|
|
182
|
+
async function issue(options) {
|
|
183
|
+
return issueWire02(options);
|
|
184
|
+
}
|
|
182
185
|
async function issueWire02(options) {
|
|
183
186
|
if (!schema.isCanonicalIss(options.iss)) {
|
|
184
187
|
throw new IssueError({
|
|
@@ -1550,7 +1553,7 @@ async function verifyLocal(jws, publicKey, options = {}) {
|
|
|
1550
1553
|
return {
|
|
1551
1554
|
valid: false,
|
|
1552
1555
|
code: "E_UNSUPPORTED_WIRE_VERSION",
|
|
1553
|
-
message: "Wire 0.1 receipts are not supported. Re-issue as Wire 0.2 using
|
|
1556
|
+
message: "Wire 0.1 receipts are not supported. Re-issue as Wire 0.2 using issue()."
|
|
1554
1557
|
};
|
|
1555
1558
|
} catch (err) {
|
|
1556
1559
|
if (isCryptoError(err)) {
|
|
@@ -3000,6 +3003,7 @@ exports.isCommerceResult = isCommerceResult;
|
|
|
3000
3003
|
exports.isWire02Result = isWire02Result;
|
|
3001
3004
|
exports.issue = issue;
|
|
3002
3005
|
exports.issueJws = issueJws;
|
|
3006
|
+
exports.issueWire01 = issueWire01;
|
|
3003
3007
|
exports.issueWire02 = issueWire02;
|
|
3004
3008
|
exports.parseBodyProfile = parseBodyProfile;
|
|
3005
3009
|
exports.parseDiscovery = parseDiscovery;
|