@bolyra/receipts 0.10.0 → 0.11.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/dist/instance.d.ts +12 -3
- package/dist/instance.js +11 -0
- package/dist/verify-cli.js +16 -0
- package/package.json +4 -3
- package/src/instance.ts +24 -2
- package/src/verify-cli.ts +17 -0
package/dist/instance.d.ts
CHANGED
|
@@ -29,7 +29,11 @@ export interface InstancePreimage {
|
|
|
29
29
|
audience: string;
|
|
30
30
|
/** Binding program discriminator (e.g. "x402", "mpp"). */
|
|
31
31
|
program: string;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Capability tokens the decision was evaluated over, order as presented
|
|
34
|
+
* (order is significant): the granted set on allow; on deny, the tokens
|
|
35
|
+
* the request was evaluated against.
|
|
36
|
+
*/
|
|
33
37
|
capabilities: string[];
|
|
34
38
|
/** Decimal string, exactly as decided. */
|
|
35
39
|
amountUsd: string;
|
|
@@ -45,7 +49,7 @@ export interface ReceiptInstanceFields {
|
|
|
45
49
|
ref: string;
|
|
46
50
|
preimage: InstancePreimage;
|
|
47
51
|
}
|
|
48
|
-
export type InstanceBindingCode = 'absent' | 'ok' | 'wrong_kind' | 'malformed_ref' | 'out_of_domain' | 'ref_mismatch';
|
|
52
|
+
export type InstanceBindingCode = 'absent' | 'ok' | 'malformed_receipt' | 'wrong_kind' | 'malformed_ref' | 'out_of_domain' | 'ref_mismatch';
|
|
49
53
|
export type InstanceBindingResult = {
|
|
50
54
|
ok: true;
|
|
51
55
|
present: false;
|
|
@@ -54,10 +58,15 @@ export type InstanceBindingResult = {
|
|
|
54
58
|
ok: true;
|
|
55
59
|
present: true;
|
|
56
60
|
code: 'ok';
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
present: false;
|
|
64
|
+
code: 'malformed_receipt';
|
|
65
|
+
detail: string;
|
|
57
66
|
} | {
|
|
58
67
|
ok: false;
|
|
59
68
|
present: true;
|
|
60
|
-
code: Exclude<InstanceBindingCode, 'absent' | 'ok'>;
|
|
69
|
+
code: Exclude<InstanceBindingCode, 'absent' | 'ok' | 'malformed_receipt'>;
|
|
61
70
|
detail: string;
|
|
62
71
|
};
|
|
63
72
|
export type PreimageValidation = {
|
package/dist/instance.js
CHANGED
|
@@ -126,6 +126,17 @@ function computeInstanceRef(preimage) {
|
|
|
126
126
|
* receipt carries no instance block (the block is optional).
|
|
127
127
|
*/
|
|
128
128
|
function verifyInstanceBinding(receipt) {
|
|
129
|
+
// Parsed JSON can hand this function anything — a log line that is not a
|
|
130
|
+
// receipt at all must fail deterministically, never throw.
|
|
131
|
+
const payload = receipt?.payload;
|
|
132
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {
|
|
133
|
+
return {
|
|
134
|
+
ok: false,
|
|
135
|
+
present: false,
|
|
136
|
+
code: 'malformed_receipt',
|
|
137
|
+
detail: 'input has no receipt payload object',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
129
140
|
const instance = receipt.payload.instance;
|
|
130
141
|
if (instance === undefined) {
|
|
131
142
|
return { ok: true, present: false, code: 'absent' };
|
package/dist/verify-cli.js
CHANGED
|
@@ -37,6 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const process = __importStar(require("process"));
|
|
39
39
|
const sign_1 = require("./sign");
|
|
40
|
+
const instance_1 = require("./instance");
|
|
40
41
|
// --- Helpers ---
|
|
41
42
|
function usage() {
|
|
42
43
|
return `Usage: bolyra-receipt-verify <receipt.json> [options]
|
|
@@ -273,12 +274,27 @@ function validateSignature() {
|
|
|
273
274
|
}
|
|
274
275
|
pass(`Signature valid (signer: ${truncate(receipt.signature.signer)})`);
|
|
275
276
|
}
|
|
277
|
+
// 6. Instance binding (spec/receipt-instance-binding-v1.md §4): signature
|
|
278
|
+
// validity and instance-binding validity are different claims — a
|
|
279
|
+
// signer-issued receipt with a forged instance.ref passes verifyReceipt()
|
|
280
|
+
// in check 5 and MUST still fail here.
|
|
281
|
+
function validateInstance() {
|
|
282
|
+
const result = (0, instance_1.verifyInstanceBinding)(receipt);
|
|
283
|
+
if (!result.ok) {
|
|
284
|
+
failCheck(`Instance binding invalid [${result.code}] ${result.detail}`);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (result.present) {
|
|
288
|
+
pass(`Instance binding valid (${receipt.payload.instance.ref})`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
276
291
|
// --- Run checks ---
|
|
277
292
|
if (validateSchema()) {
|
|
278
293
|
validateTimestamp();
|
|
279
294
|
if (validateHash()) {
|
|
280
295
|
validateId();
|
|
281
296
|
validateSignature();
|
|
297
|
+
validateInstance();
|
|
282
298
|
}
|
|
283
299
|
}
|
|
284
300
|
// --- Output ---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolyra/receipts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Signed auth receipts for Bolyra ZKP verification decisions — canonical JSON, secp256k1 sign/verify, EVM-compatible r||s||v signatures.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
"@noble/hashes": "^1.7.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"
|
|
21
|
+
"@types/jest": "^30.0.0",
|
|
22
22
|
"@types/node": "^25.9.1",
|
|
23
23
|
"jest": "^30.4.2",
|
|
24
24
|
"ts-jest": "^29.2.0",
|
|
25
|
-
"
|
|
25
|
+
"tsx": "^4.20.0",
|
|
26
|
+
"typescript": "^5.5.0"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"dist/",
|
package/src/instance.ts
CHANGED
|
@@ -48,7 +48,11 @@ export interface InstancePreimage {
|
|
|
48
48
|
audience: string;
|
|
49
49
|
/** Binding program discriminator (e.g. "x402", "mpp"). */
|
|
50
50
|
program: string;
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Capability tokens the decision was evaluated over, order as presented
|
|
53
|
+
* (order is significant): the granted set on allow; on deny, the tokens
|
|
54
|
+
* the request was evaluated against.
|
|
55
|
+
*/
|
|
52
56
|
capabilities: string[];
|
|
53
57
|
/** Decimal string, exactly as decided. */
|
|
54
58
|
amountUsd: string;
|
|
@@ -69,6 +73,7 @@ export interface ReceiptInstanceFields {
|
|
|
69
73
|
export type InstanceBindingCode =
|
|
70
74
|
| 'absent'
|
|
71
75
|
| 'ok'
|
|
76
|
+
| 'malformed_receipt'
|
|
72
77
|
| 'wrong_kind'
|
|
73
78
|
| 'malformed_ref'
|
|
74
79
|
| 'out_of_domain'
|
|
@@ -77,7 +82,13 @@ export type InstanceBindingCode =
|
|
|
77
82
|
export type InstanceBindingResult =
|
|
78
83
|
| { ok: true; present: false; code: 'absent' }
|
|
79
84
|
| { ok: true; present: true; code: 'ok' }
|
|
80
|
-
| { ok: false; present:
|
|
85
|
+
| { ok: false; present: false; code: 'malformed_receipt'; detail: string }
|
|
86
|
+
| {
|
|
87
|
+
ok: false;
|
|
88
|
+
present: true;
|
|
89
|
+
code: Exclude<InstanceBindingCode, 'absent' | 'ok' | 'malformed_receipt'>;
|
|
90
|
+
detail: string;
|
|
91
|
+
};
|
|
81
92
|
|
|
82
93
|
export type PreimageValidation = { ok: true } | { ok: false; detail: string };
|
|
83
94
|
|
|
@@ -175,6 +186,17 @@ export function computeInstanceRef(preimage: InstancePreimage): string {
|
|
|
175
186
|
* receipt carries no instance block (the block is optional).
|
|
176
187
|
*/
|
|
177
188
|
export function verifyInstanceBinding(receipt: SignedReceipt): InstanceBindingResult {
|
|
189
|
+
// Parsed JSON can hand this function anything — a log line that is not a
|
|
190
|
+
// receipt at all must fail deterministically, never throw.
|
|
191
|
+
const payload = (receipt as { payload?: unknown } | null | undefined)?.payload;
|
|
192
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {
|
|
193
|
+
return {
|
|
194
|
+
ok: false,
|
|
195
|
+
present: false,
|
|
196
|
+
code: 'malformed_receipt',
|
|
197
|
+
detail: 'input has no receipt payload object',
|
|
198
|
+
};
|
|
199
|
+
}
|
|
178
200
|
const instance = receipt.payload.instance;
|
|
179
201
|
if (instance === undefined) {
|
|
180
202
|
return { ok: true, present: false, code: 'absent' };
|
package/src/verify-cli.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as process from 'process';
|
|
5
5
|
import { verifyReceipt, hashPayload } from './sign';
|
|
6
|
+
import { verifyInstanceBinding } from './instance';
|
|
6
7
|
import type { SignedReceipt } from './types';
|
|
7
8
|
|
|
8
9
|
// --- Helpers ---
|
|
@@ -233,6 +234,21 @@ function validateSignature(): void {
|
|
|
233
234
|
pass(`Signature valid (signer: ${truncate(receipt.signature.signer)})`);
|
|
234
235
|
}
|
|
235
236
|
|
|
237
|
+
// 6. Instance binding (spec/receipt-instance-binding-v1.md §4): signature
|
|
238
|
+
// validity and instance-binding validity are different claims — a
|
|
239
|
+
// signer-issued receipt with a forged instance.ref passes verifyReceipt()
|
|
240
|
+
// in check 5 and MUST still fail here.
|
|
241
|
+
function validateInstance(): void {
|
|
242
|
+
const result = verifyInstanceBinding(receipt);
|
|
243
|
+
if (!result.ok) {
|
|
244
|
+
failCheck(`Instance binding invalid [${result.code}] ${result.detail}`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (result.present) {
|
|
248
|
+
pass(`Instance binding valid (${receipt.payload.instance!.ref})`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
236
252
|
// --- Run checks ---
|
|
237
253
|
|
|
238
254
|
if (validateSchema()) {
|
|
@@ -240,6 +256,7 @@ if (validateSchema()) {
|
|
|
240
256
|
if (validateHash()) {
|
|
241
257
|
validateId();
|
|
242
258
|
validateSignature();
|
|
259
|
+
validateInstance();
|
|
243
260
|
}
|
|
244
261
|
}
|
|
245
262
|
|