@provian/mcp 0.0.0-stage → 1.2.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +264 -2
  4. package/bin/provian-mcp.mjs +18 -0
  5. package/dist/agent-wallet-registration.d.ts +34 -0
  6. package/dist/agent-wallet-registration.d.ts.map +1 -0
  7. package/dist/agent-wallet-registration.js +440 -0
  8. package/dist/agent-wallet-registration.js.map +1 -0
  9. package/dist/core/challenge.d.ts +187 -0
  10. package/dist/core/challenge.d.ts.map +1 -0
  11. package/dist/core/challenge.js +536 -0
  12. package/dist/core/challenge.js.map +1 -0
  13. package/dist/core/crypto.d.ts +44 -0
  14. package/dist/core/crypto.d.ts.map +1 -0
  15. package/dist/core/crypto.js +124 -0
  16. package/dist/core/crypto.js.map +1 -0
  17. package/dist/core/disclosure-request.d.ts +169 -0
  18. package/dist/core/disclosure-request.d.ts.map +1 -0
  19. package/dist/core/disclosure-request.js +400 -0
  20. package/dist/core/disclosure-request.js.map +1 -0
  21. package/dist/core/genesis-offer.d.ts +25 -0
  22. package/dist/core/genesis-offer.d.ts.map +1 -0
  23. package/dist/core/genesis-offer.js +34 -0
  24. package/dist/core/genesis-offer.js.map +1 -0
  25. package/dist/core/harness-tool-vocabulary.d.ts +55 -0
  26. package/dist/core/harness-tool-vocabulary.d.ts.map +1 -0
  27. package/dist/core/harness-tool-vocabulary.js +116 -0
  28. package/dist/core/harness-tool-vocabulary.js.map +1 -0
  29. package/dist/core/keccak256.d.ts +15 -0
  30. package/dist/core/keccak256.d.ts.map +1 -0
  31. package/dist/core/keccak256.js +111 -0
  32. package/dist/core/keccak256.js.map +1 -0
  33. package/dist/core/key-custody.d.ts +33 -0
  34. package/dist/core/key-custody.d.ts.map +1 -0
  35. package/dist/core/key-custody.js +59 -0
  36. package/dist/core/key-custody.js.map +1 -0
  37. package/dist/core/meter-hash.d.ts +2 -0
  38. package/dist/core/meter-hash.d.ts.map +1 -0
  39. package/dist/core/meter-hash.js +8 -0
  40. package/dist/core/meter-hash.js.map +1 -0
  41. package/dist/core/meter-wire.d.ts +193 -0
  42. package/dist/core/meter-wire.d.ts.map +1 -0
  43. package/dist/core/meter-wire.js +418 -0
  44. package/dist/core/meter-wire.js.map +1 -0
  45. package/dist/core/output-signature.d.ts +162 -0
  46. package/dist/core/output-signature.d.ts.map +1 -0
  47. package/dist/core/output-signature.js +367 -0
  48. package/dist/core/output-signature.js.map +1 -0
  49. package/dist/core/presentation.d.ts +141 -0
  50. package/dist/core/presentation.d.ts.map +1 -0
  51. package/dist/core/presentation.js +160 -0
  52. package/dist/core/presentation.js.map +1 -0
  53. package/dist/core/recovery-seal.d.ts +36 -0
  54. package/dist/core/recovery-seal.d.ts.map +1 -0
  55. package/dist/core/recovery-seal.js +122 -0
  56. package/dist/core/recovery-seal.js.map +1 -0
  57. package/dist/core/server.d.ts +38 -0
  58. package/dist/core/server.d.ts.map +1 -0
  59. package/dist/core/server.js +106 -0
  60. package/dist/core/server.js.map +1 -0
  61. package/dist/core/thread-reader.d.ts +8 -0
  62. package/dist/core/thread-reader.d.ts.map +1 -0
  63. package/dist/core/thread-reader.js +47 -0
  64. package/dist/core/thread-reader.js.map +1 -0
  65. package/dist/core/tool-set.d.ts +28 -0
  66. package/dist/core/tool-set.d.ts.map +1 -0
  67. package/dist/core/tool-set.js +71 -0
  68. package/dist/core/tool-set.js.map +1 -0
  69. package/dist/core/tools.d.ts +151 -0
  70. package/dist/core/tools.d.ts.map +1 -0
  71. package/dist/core/tools.js +3621 -0
  72. package/dist/core/tools.js.map +1 -0
  73. package/dist/core/types.d.ts +189 -0
  74. package/dist/core/types.d.ts.map +1 -0
  75. package/dist/core/types.js +17 -0
  76. package/dist/core/types.js.map +1 -0
  77. package/dist/credentials.d.ts +46 -0
  78. package/dist/credentials.d.ts.map +1 -0
  79. package/dist/credentials.js +213 -0
  80. package/dist/credentials.js.map +1 -0
  81. package/dist/device-credentials.d.ts +57 -0
  82. package/dist/device-credentials.d.ts.map +1 -0
  83. package/dist/device-credentials.js +403 -0
  84. package/dist/device-credentials.js.map +1 -0
  85. package/dist/eip191.d.ts +18 -0
  86. package/dist/eip191.d.ts.map +1 -0
  87. package/dist/eip191.js +41 -0
  88. package/dist/eip191.js.map +1 -0
  89. package/dist/index.d.ts +21 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +48 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/runtime-env.d.ts +131 -0
  94. package/dist/runtime-env.d.ts.map +1 -0
  95. package/dist/runtime-env.js +328 -0
  96. package/dist/runtime-env.js.map +1 -0
  97. package/dist/stdio.d.ts +6 -0
  98. package/dist/stdio.d.ts.map +1 -0
  99. package/dist/stdio.js +136 -0
  100. package/dist/stdio.js.map +1 -0
  101. package/package.json +60 -4
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+ /**
3
+ * PE METER WIRE FORMAT — the ONE definition of a v2 Provenance Envelope, its act record,
4
+ * the daily batch, and the fingerprints over them (: the relay is a
5
+ * meter, not an archive).
6
+ *
7
+ * THIS FILE IS BYTE-IDENTICAL IN THREE PACKAGES and a parity check refuses any drift:
8
+ * provian-backend/src/core/meter/meter-wire.ts (the relay)
9
+ * provian-agent-sdk/src/meter-wire.ts (daemon + SDK)
10
+ * src/core/meter/meter-wire.ts (the app)
11
+ * The only per-package file is `./meter-hash` (a sha256 over bytes), because the three
12
+ * packages carry different hash libraries. Everything that decides a byte lives here.
13
+ *
14
+ * WHAT EACH THING IS
15
+ * PE (v2) — the complete envelope. Built, hashed and kept by its OWNER's device. The
16
+ * relay never stores it.
17
+ * act record — what the relay prices: the PE's identity fields, its pe_hash (which covers
18
+ * the complete PE), and `pricing` = the PE minus identity fields and free text.
19
+ * batch — one signed, chained submission per device per day (and right before a
20
+ * presentation or payout); `acts_root` is the
21
+ * fingerprint over every act leaf.
22
+ * batch leaf — what the daily on-chain anchor commits to (one per accepted batch).
23
+ *
24
+ * Proving one act later: act leaf → acts_root (Merkle path) → batch leaf → the day's on-chain
25
+ * root (PEAnchor.verifyPE). Anyone holding the PE recomputes every step; nobody else needs it.
26
+ *
27
+ * Pure: no I/O, no clock, no randomness.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.NON_PRICING_PE_FIELDS = exports.METER_MINT_WINDOW_MS = exports.MAX_ACTS_PER_BATCH = exports.METER_GENESIS_PREV_HASH = exports.PE_BATCH_SCHEMA = exports.PE_V2_SCHEMA = void 0;
31
+ exports.canonicalJson = canonicalJson;
32
+ exports.bytesToHexLower = bytesToHexLower;
33
+ exports.hexToBytesStrict = hexToBytesStrict;
34
+ exports.utf8Bytes = utf8Bytes;
35
+ exports.sha256HexOfText = sha256HexOfText;
36
+ exports.peHashOf = peHashOf;
37
+ exports.pricingOf = pricingOf;
38
+ exports.actRecordOf = actRecordOf;
39
+ exports.actMatchesPe = actMatchesPe;
40
+ exports.actLeafOf = actLeafOf;
41
+ exports.hardwareNonceOfAct = hardwareNonceOfAct;
42
+ exports.merkleRootOf = merkleRootOf;
43
+ exports.merkleProofOf = merkleProofOf;
44
+ exports.merkleTreeOf = merkleTreeOf;
45
+ exports.verifyMerkleProofOf = verifyMerkleProofOf;
46
+ exports.actsRootOf = actsRootOf;
47
+ exports.batchHashOf = batchHashOf;
48
+ exports.batchLeafOf = batchLeafOf;
49
+ exports.buildBatch = buildBatch;
50
+ exports.validateBatchShape = validateBatchShape;
51
+ exports.verifyActChain = verifyActChain;
52
+ exports.verifyActInclusion = verifyActInclusion;
53
+ const meter_hash_1 = require("./meter-hash");
54
+ exports.PE_V2_SCHEMA = 'provian.pe.v2';
55
+ exports.PE_BATCH_SCHEMA = 'provian.pe-batch.v1';
56
+ exports.METER_GENESIS_PREV_HASH = 'genesis';
57
+ exports.MAX_ACTS_PER_BATCH = 500;
58
+ /** An act older than this when it reaches the relay is recorded into totals but does not mint. */
59
+ exports.METER_MINT_WINDOW_MS = 30 * 24 * 60 * 60 * 1000;
60
+ const ACT_LEAF_DOMAIN = 'provian.meter.act.v1\n';
61
+ const BATCH_LEAF_DOMAIN = 'provian.meter.batch-leaf.v1\n';
62
+ /** Fields of a PE that are identity or free text, never pricing inputs. */
63
+ exports.NON_PRICING_PE_FIELDS = [
64
+ 'schema',
65
+ 'pe_id',
66
+ 'device_id',
67
+ 'prev_hash',
68
+ 'timestamp',
69
+ 'action_type',
70
+ 'pe_hash',
71
+ 'signature',
72
+ 'description',
73
+ 'intent_text',
74
+ 'private_commitment',
75
+ 'private_owner_view',
76
+ 'detail_commitment',
77
+ ];
78
+ /** Fields excluded from a PE's own hash (the hash cannot cover itself; the signature signs it). */
79
+ const PE_HASH_EXCLUDED = ['pe_hash', 'signature'];
80
+ // ─── canonical JSON ─────────────────────────────────────────────────────────────
81
+ /**
82
+ * Canonical JSON: object keys sorted by UTF-16 code unit, no whitespace, `undefined` object
83
+ * members dropped, `undefined` array members written as null, non-finite numbers refused.
84
+ * Identical to the hardware-witness canonicalizer and to json-stable-stringify on plain JSON.
85
+ */
86
+ function canonicalJson(value) {
87
+ if (value === null)
88
+ return 'null';
89
+ if (typeof value === 'number') {
90
+ if (!Number.isFinite(value))
91
+ throw new Error('canonical_json_non_finite_number');
92
+ return JSON.stringify(value);
93
+ }
94
+ if (typeof value === 'string' || typeof value === 'boolean')
95
+ return JSON.stringify(value);
96
+ if (Array.isArray(value)) {
97
+ return '[' + value.map((v) => (v === undefined ? 'null' : canonicalJson(v))).join(',') + ']';
98
+ }
99
+ if (typeof value === 'object') {
100
+ const obj = value;
101
+ const keys = Object.keys(obj).filter((k) => obj[k] !== undefined).sort();
102
+ return '{' + keys.map((k) => JSON.stringify(k) + ':' + canonicalJson(obj[k])).join(',') + '}';
103
+ }
104
+ throw new Error(`canonical_json_unsupported_type:${typeof value}`);
105
+ }
106
+ // ─── bytes ──────────────────────────────────────────────────────────────────────
107
+ const HEX = '0123456789abcdef';
108
+ function bytesToHexLower(bytes) {
109
+ let out = '';
110
+ for (let i = 0; i < bytes.length; i++) {
111
+ out += HEX[bytes[i] >> 4] + HEX[bytes[i] & 15];
112
+ }
113
+ return out;
114
+ }
115
+ function hexToBytesStrict(hex) {
116
+ const h = hex.startsWith('0x') ? hex.slice(2) : hex;
117
+ if (h.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(h))
118
+ throw new Error('invalid_hex');
119
+ const out = new Uint8Array(h.length / 2);
120
+ for (let i = 0; i < out.length; i++)
121
+ out[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
122
+ return out;
123
+ }
124
+ function utf8Bytes(text) {
125
+ return new TextEncoder().encode(text);
126
+ }
127
+ function sha256HexOfText(text) {
128
+ return bytesToHexLower((0, meter_hash_1.sha256Bytes)(utf8Bytes(text)));
129
+ }
130
+ function isHex64(value) {
131
+ return typeof value === 'string' && /^[0-9a-f]{64}$/.test(value);
132
+ }
133
+ function omit(source, drop) {
134
+ const out = {};
135
+ for (const key of Object.keys(source)) {
136
+ if (!drop.includes(key) && source[key] !== undefined)
137
+ out[key] = source[key];
138
+ }
139
+ return out;
140
+ }
141
+ // ─── the PE and its act record ──────────────────────────────────────────────────
142
+ /** sha256 hex over the complete PE minus its own hash and signature. */
143
+ function peHashOf(pe) {
144
+ return sha256HexOfText(canonicalJson(omit(pe, PE_HASH_EXCLUDED)));
145
+ }
146
+ /** The pricing projection: everything in the PE except identity fields and free text. */
147
+ function pricingOf(pe) {
148
+ if (pe.private_pricing !== undefined)
149
+ return {
150
+ private_pricing: pe.private_pricing,
151
+ ...(pe.hardware_witness !== undefined ? { hardware_witness: pe.hardware_witness } : {}),
152
+ ...(pe.detail_hash !== undefined ? { detail_hash: pe.detail_hash } : {}),
153
+ };
154
+ return omit(pe, exports.NON_PRICING_PE_FIELDS);
155
+ }
156
+ /** The act record the relay prices. `pe_hash` covers the complete PE, free text included. */
157
+ function actRecordOf(pe) {
158
+ return {
159
+ pe_id: pe.pe_id,
160
+ pe_hash: peHashOf(pe),
161
+ prev_hash: pe.prev_hash,
162
+ timestamp: pe.timestamp,
163
+ action_type: pe.action_type,
164
+ pricing: pricingOf(pe),
165
+ };
166
+ }
167
+ /**
168
+ * True when `act` is exactly the act record of `pe` (same hash AND same pricing inputs).
169
+ * This is the byte-for-byte check a verifier runs on a presented PE.
170
+ */
171
+ function actMatchesPe(act, pe) {
172
+ return canonicalJson(act) === canonicalJson(actRecordOf(pe));
173
+ }
174
+ /** The act's leaf in its batch's `acts_root`. */
175
+ function actLeafOf(act) {
176
+ return sha256HexOfText(ACT_LEAF_DOMAIN + canonicalJson(act));
177
+ }
178
+ /**
179
+ * The hardware-witness binding nonce for a v2 act: sha256 over the act's identity (`pe_id`,
180
+ * `prev_hash`, `timestamp`, `action_type`) and every pricing input except the witness slot itself.
181
+ * `pe_hash` is left out because it covers the whole PE, witness included — a nonce over it would
182
+ * ask the witness to sign its own signature. The witness therefore attests exactly what the relay
183
+ * prices, bound to one position in one device's chain.
184
+ */
185
+ function hardwareNonceOfAct(act) {
186
+ return sha256HexOfText(canonicalJson({
187
+ pe_id: act.pe_id,
188
+ prev_hash: act.prev_hash,
189
+ timestamp: act.timestamp,
190
+ action_type: act.action_type,
191
+ pricing: omit(act.pricing, ['hardware_witness']),
192
+ }));
193
+ }
194
+ // ─── Merkle (sha256; the same tagged, sorted-pair, power-of-two shape as PEAnchor) ──
195
+ const EMPTY_NODE = () => (0, meter_hash_1.sha256Bytes)(new Uint8Array(0));
196
+ function tagged(tag, ...parts) {
197
+ let length = 1;
198
+ for (const p of parts)
199
+ length += p.length;
200
+ const out = new Uint8Array(length);
201
+ out[0] = tag;
202
+ let offset = 1;
203
+ for (const p of parts) {
204
+ out.set(p, offset);
205
+ offset += p.length;
206
+ }
207
+ return out;
208
+ }
209
+ function compareBytes(a, b) {
210
+ for (let i = 0; i < a.length && i < b.length; i++) {
211
+ if (a[i] !== b[i])
212
+ return a[i] - b[i];
213
+ }
214
+ return a.length - b.length;
215
+ }
216
+ function nodeOf(a, b) {
217
+ return compareBytes(a, b) <= 0 ? (0, meter_hash_1.sha256Bytes)(tagged(0x01, a, b)) : (0, meter_hash_1.sha256Bytes)(tagged(0x01, b, a));
218
+ }
219
+ function leafNodeOf(leafHex) {
220
+ if (!isHex64(leafHex))
221
+ throw new Error('invalid_leaf');
222
+ return (0, meter_hash_1.sha256Bytes)(tagged(0x00, hexToBytesStrict(leafHex)));
223
+ }
224
+ function layersOf(leafHexes) {
225
+ if (leafHexes.length === 0)
226
+ throw new Error('empty_tree');
227
+ const base = leafHexes.map(leafNodeOf);
228
+ let size = 1;
229
+ while (size < base.length)
230
+ size *= 2;
231
+ while (base.length < size)
232
+ base.push(EMPTY_NODE());
233
+ const layers = [base];
234
+ let current = base;
235
+ while (current.length > 1) {
236
+ const next = [];
237
+ for (let i = 0; i < current.length; i += 2)
238
+ next.push(nodeOf(current[i], current[i + 1]));
239
+ layers.push(next);
240
+ current = next;
241
+ }
242
+ return layers;
243
+ }
244
+ function merkleRootOf(leafHexes) {
245
+ const layers = layersOf(leafHexes);
246
+ return bytesToHexLower(layers[layers.length - 1][0]);
247
+ }
248
+ function proofFromLayers(layers, leafCount, index) {
249
+ if (!Number.isSafeInteger(index) || index < 0 || index >= leafCount) {
250
+ throw new Error('leaf_index_out_of_range');
251
+ }
252
+ const proof = [];
253
+ let i = index;
254
+ for (let level = 0; level < layers.length - 1; level++) {
255
+ proof.push(bytesToHexLower(layers[level][i % 2 === 0 ? i + 1 : i - 1]));
256
+ i = Math.floor(i / 2);
257
+ }
258
+ return proof;
259
+ }
260
+ function merkleProofOf(leafHexes, index) {
261
+ if (!Number.isSafeInteger(index) || index < 0 || index >= leafHexes.length) {
262
+ throw new Error('leaf_index_out_of_range');
263
+ }
264
+ return proofFromLayers(layersOf(leafHexes), leafHexes.length, index);
265
+ }
266
+ /**
267
+ * One build of the tree, then its root and any leaf's proof — byte-identical to merkleRootOf /
268
+ * merkleProofOf. Proving many leaves of one tree with merkleProofOf rebuilds it per leaf, which on
269
+ * a phone (interpreted SHA-256) made proving a few thousand acts take minutes.
270
+ */
271
+ function merkleTreeOf(leafHexes) {
272
+ const layers = layersOf(leafHexes);
273
+ return {
274
+ root: bytesToHexLower(layers[layers.length - 1][0]),
275
+ proofOf: (index) => proofFromLayers(layers, leafHexes.length, index),
276
+ };
277
+ }
278
+ function verifyMerkleProofOf(leafHex, proof, rootHex) {
279
+ try {
280
+ let node = leafNodeOf(leafHex);
281
+ for (const sibling of proof) {
282
+ if (!isHex64(sibling))
283
+ return false;
284
+ node = nodeOf(node, hexToBytesStrict(sibling));
285
+ }
286
+ return bytesToHexLower(node) === rootHex;
287
+ }
288
+ catch {
289
+ return false;
290
+ }
291
+ }
292
+ /** The fingerprint over a batch's acts, in order. */
293
+ function actsRootOf(acts) {
294
+ return merkleRootOf(acts.map(actLeafOf));
295
+ }
296
+ // ─── the batch ──────────────────────────────────────────────────────────────────
297
+ /** sha256 over the batch minus its sealed copies (delivery payload, not part of the record). */
298
+ function batchHashOf(batch) {
299
+ return sha256HexOfText(canonicalJson(omit(batch, ['sealed'])));
300
+ }
301
+ /** The 32-byte leaf the daily on-chain anchor commits to for one accepted batch. */
302
+ function batchLeafOf(input) {
303
+ return sha256HexOfText(BATCH_LEAF_DOMAIN + canonicalJson({
304
+ actor_id: input.actor_id,
305
+ acts_root: input.acts_root,
306
+ batch_hash: input.batch_hash,
307
+ device_id: input.device_id,
308
+ seq: input.seq,
309
+ }));
310
+ }
311
+ /** Build a batch from complete PEs (client side). */
312
+ function buildBatch(input) {
313
+ const acts = input.pes.map(actRecordOf);
314
+ const batch = {
315
+ schema: exports.PE_BATCH_SCHEMA,
316
+ device_id: input.device_id,
317
+ seq: input.seq,
318
+ prev_batch_hash: input.prev_batch_hash,
319
+ created_at_ms: input.created_at_ms,
320
+ acts,
321
+ acts_root: actsRootOf(acts),
322
+ ...(input.sealed && input.sealed.length > 0 ? { sealed: input.sealed } : {}),
323
+ };
324
+ return batch;
325
+ }
326
+ /** Structural validation (relay side). Never trusts `acts_root`: recomputes it. */
327
+ function validateBatchShape(batch) {
328
+ if (batch === null || typeof batch !== 'object' || Array.isArray(batch))
329
+ return { ok: false, error: 'bad_schema' };
330
+ const b = batch;
331
+ if (b.schema !== exports.PE_BATCH_SCHEMA)
332
+ return { ok: false, error: 'bad_schema' };
333
+ if (typeof b.device_id !== 'string' || b.device_id.length === 0 || b.device_id.length > 200)
334
+ return { ok: false, error: 'bad_device_id' };
335
+ if (typeof b.seq !== 'number' || !Number.isSafeInteger(b.seq) || b.seq < 1)
336
+ return { ok: false, error: 'bad_seq' };
337
+ if (typeof b.prev_batch_hash !== 'string' || (b.prev_batch_hash !== exports.METER_GENESIS_PREV_HASH && !isHex64(b.prev_batch_hash))) {
338
+ return { ok: false, error: 'bad_prev_batch_hash' };
339
+ }
340
+ if (typeof b.created_at_ms !== 'number' || !Number.isSafeInteger(b.created_at_ms) || b.created_at_ms <= 0)
341
+ return { ok: false, error: 'bad_created_at' };
342
+ if (!Array.isArray(b.acts) || b.acts.length === 0)
343
+ return { ok: false, error: 'no_acts' };
344
+ if (b.acts.length > exports.MAX_ACTS_PER_BATCH)
345
+ return { ok: false, error: 'too_many_acts' };
346
+ const seen = new Set();
347
+ for (let i = 0; i < b.acts.length; i++) {
348
+ const a = b.acts[i];
349
+ if (a === null || typeof a !== 'object' || Array.isArray(a))
350
+ return { ok: false, error: 'bad_act', index: i };
351
+ const keys = Object.keys(a).sort().join(',');
352
+ if (keys !== 'action_type,pe_hash,pe_id,prev_hash,pricing,timestamp')
353
+ return { ok: false, error: 'bad_act', index: i };
354
+ if (typeof a.pe_id !== 'string' || a.pe_id.length === 0 || a.pe_id.length > 200)
355
+ return { ok: false, error: 'bad_act', index: i };
356
+ if (!isHex64(a.pe_hash))
357
+ return { ok: false, error: 'bad_act', index: i };
358
+ if (typeof a.prev_hash !== 'string' || (a.prev_hash !== exports.METER_GENESIS_PREV_HASH && !isHex64(a.prev_hash)))
359
+ return { ok: false, error: 'bad_act', index: i };
360
+ if (typeof a.timestamp !== 'number' || !Number.isSafeInteger(a.timestamp) || a.timestamp <= 0)
361
+ return { ok: false, error: 'bad_act', index: i };
362
+ if (typeof a.action_type !== 'string' || a.action_type.length === 0 || a.action_type.length > 128)
363
+ return { ok: false, error: 'bad_act', index: i };
364
+ if (a.pricing === null || typeof a.pricing !== 'object' || Array.isArray(a.pricing))
365
+ return { ok: false, error: 'bad_act', index: i };
366
+ for (const k of Object.keys(a.pricing)) {
367
+ if (exports.NON_PRICING_PE_FIELDS.includes(k))
368
+ return { ok: false, error: 'bad_act', index: i };
369
+ }
370
+ if (seen.has(a.pe_id))
371
+ return { ok: false, error: 'duplicate_pe_id', index: i };
372
+ seen.add(a.pe_id);
373
+ }
374
+ const acts = b.acts;
375
+ if (b.acts_root !== actsRootOf(acts))
376
+ return { ok: false, error: 'acts_root_mismatch' };
377
+ if (b.sealed !== undefined) {
378
+ if (!Array.isArray(b.sealed) || b.sealed.length > exports.MAX_ACTS_PER_BATCH * 2)
379
+ return { ok: false, error: 'bad_sealed' };
380
+ for (const s of b.sealed) {
381
+ const c = s;
382
+ if (c === null || typeof c !== 'object' || typeof c.to !== 'string' || typeof c.pe_id !== 'string'
383
+ || typeof c.box !== 'string' || c.box.length === 0 || c.box.length > 262144 || !seen.has(c.pe_id)) {
384
+ return { ok: false, error: 'bad_sealed' };
385
+ }
386
+ }
387
+ }
388
+ return { ok: true, batch: batch };
389
+ }
390
+ /**
391
+ * The device's PE chain must continue across batches: the first act links to the last act the
392
+ * relay accepted from this device, and every later act links to its predecessor. A PE can
393
+ * therefore appear in exactly one accepted batch.
394
+ */
395
+ function verifyActChain(lastAcceptedPeHash, acts) {
396
+ let prev = lastAcceptedPeHash;
397
+ for (let i = 0; i < acts.length; i++) {
398
+ if (acts[i].prev_hash !== prev)
399
+ return { ok: false, index: i };
400
+ prev = acts[i].pe_hash;
401
+ }
402
+ return { ok: true };
403
+ }
404
+ /** Check an act (from a presented PE) against its inclusion proof, up to the batch leaf. */
405
+ function verifyActInclusion(pe, proof) {
406
+ const act = actRecordOf(pe);
407
+ if (!verifyMerkleProofOf(actLeafOf(act), proof.act_proof, proof.acts_root))
408
+ return { ok: false, reason: 'act_not_in_batch' };
409
+ const leaf = batchLeafOf({
410
+ device_id: proof.batch.device_id,
411
+ actor_id: proof.batch.actor_id,
412
+ seq: proof.batch.seq,
413
+ batch_hash: proof.batch.batch_hash,
414
+ acts_root: proof.acts_root,
415
+ });
416
+ return { ok: true, batch_leaf: leaf };
417
+ }
418
+ //# sourceMappingURL=meter-wire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter-wire.js","sourceRoot":"","sources":["../../src/core/meter-wire.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAmFH,sCAgBC;AAMD,0CAMC;AAED,4CAMC;AAED,8BAEC;AAED,0CAEC;AAiBD,4BAEC;AAGD,8BAOC;AAGD,kCASC;AAMD,oCAEC;AAGD,8BAEC;AASD,gDAQC;AAoDD,oCAGC;AAeD,sCAKC;AAOD,oCAMC;AAED,kDAWC;AAGD,gCAEC;AAKD,kCAEC;AAGD,kCAcC;AAGD,gCAoBC;AAgBD,gDA2CC;AAOD,wCAOC;AA8BD,gDAWC;AA/cD,6CAA2C;AAE9B,QAAA,YAAY,GAAG,eAAe,CAAC;AAC/B,QAAA,eAAe,GAAG,qBAAqB,CAAC;AACxC,QAAA,uBAAuB,GAAG,SAAS,CAAC;AACpC,QAAA,kBAAkB,GAAG,GAAG,CAAC;AACtC,kGAAkG;AACrF,QAAA,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,iBAAiB,GAAG,+BAA+B,CAAC;AAE1D,2EAA2E;AAC9D,QAAA,qBAAqB,GAAsB;IACtD,QAAQ;IACR,OAAO;IACP,WAAW;IACX,WAAW;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hands out, and of the citation that carries it :
4
+ *
5
+ * "every output an agent hands out carries its signature over the output's hash (SDK, MCP and
6
+ * facilitator responses). A citation counts toward the producer's consumption when it carries
7
+ * that signature."
8
+ * "1. The producer's signature only establishes who made the output. The citing act must still
9
+ * be witnessed, and the ring and self filters still apply …
10
+ * 2. Outputs produced on devices that don't hold the wallet key (the MacBook daemon, phones) are
11
+ * signed with that device's registered key and map to the owner through the same identity
12
+ * index, so human-device work earns consumption too."
13
+ *
14
+ * THIS FILE IS BYTE-IDENTICAL IN THREE PACKAGES and `scripts/check-meter-wire-parity.sh` refuses any
15
+ * drift:
16
+ * provian-backend/src/core/meter/output-signature.ts (the relay: verifies at intake)
17
+ * provian-agent-sdk/src/output-signature.ts (daemon + SDK: signs and cites)
18
+ * src/core/meter/output-signature.ts (the app: signs and cites)
19
+ * Pure: no I/O, no clock, no key material. Signing and verification are each package's own, over
20
+ * the message defined here; `docs/audit/output-signature-vectors.json` binds every package to the
21
+ * same bytes.
22
+ *
23
+ * WHAT IS SIGNED — one message for every key kind:
24
+ * hash `sha256:<64 lowercase hex>` of the output's exact bytes (what the consumer received).
25
+ * message `provian-output:v1:<64 lowercase hex>` (UTF-8). Domain-separated from every other
26
+ * Provian-signed message (none begins `provian-output:`; it is not base64url, so it can
27
+ * never be a device-signature preimage), and it carries the literal "provian", so the
28
+ * app's WalletConnect guard never lets a dApp obtain one (`provianReserved.ts`).
29
+ *
30
+ * WHO SIGNS — the producer's REGISTERED key, three kinds:
31
+ * wallet an agent's (or person's) wallet key, secp256k1. scheme `eip191_secp256k1` * `personal_sign` over the message; sig = 0x + 130 hex (r‖s‖v). id = the address
32
+ * (0x + 40 lowercase hex), resolved through the native wallet address index or a proven
33
+ * address registry.
34
+ * device a registered observer device (`devices/{id}` e.g. a human's MacBook daemon), its
35
+ * Secure-Enclave P-256 `signing_public_key`, or the P-256 output key a bearer device
36
+ * registered. scheme `p256_sha256` ECDSA P-256 over SHA-256(message); sig = 128
37
+ * lowercase hex (r‖s, low-s). id = the device id.
38
+ * app a phone running the Provian app: its hardware PE-attestation key
39
+ * (`provian_pe_attestation`, Secure Enclave / StrongBox — never the wallet key),
40
+ * registered once under wallet auth. scheme `p256_sha256`. id = `aok_` + 32 hex.
41
+ *
42
+ * HOW IT TRAVELS
43
+ * HTTP response header `Provian-Output-Signature: <base64url(canonical JSON of the object)>`.
44
+ * MCP/JSON the object itself under `provian_output_signature`.
45
+ * PE the consumer's next PE cites it as one `input_origins` entry:
46
+ * `{ hash, origin_identifier: "out:<kind>:<id>", witnessed, witness?, signature }`.
47
+ * The signature establishes WHO MADE the output (the owner of the citation edge); it
48
+ * never makes the citing act witnessed — that is the citing lane's own witness.
49
+ */
50
+ export declare const OUTPUT_SIGNATURE_MESSAGE_PREFIX = "provian-output:v1:";
51
+ export declare const OUTPUT_SIGNATURE_HEADER = "Provian-Output-Signature";
52
+ /** The JSON key a non-HTTP surface (an MCP tool result, a JSON body) carries the object under. */
53
+ export declare const OUTPUT_SIGNATURE_JSON_KEY = "provian_output_signature";
54
+ /** The `input_origins` class of a signed citation: `out:<kind>:<id>`. */
55
+ export declare const OUTPUT_CITATION_SCHEME = "out:";
56
+ /** Longest header value accepted (a wallet-signed object encodes to ~420 characters). */
57
+ export declare const OUTPUT_SIGNATURE_HEADER_MAX_LEN = 2048;
58
+ /** The message a P-256 output key signs to prove possession when it is registered. */
59
+ export declare const OUTPUT_KEY_REGISTRATION_PREFIX = "provian-output-key:v1:";
60
+ export type OutputSignerKind = 'wallet' | 'device' | 'app';
61
+ export type OutputSignatureScheme = 'eip191_secp256k1' | 'p256_sha256';
62
+ export interface OutputSigner {
63
+ readonly kind: OutputSignerKind;
64
+ readonly id: string;
65
+ }
66
+ export interface OutputSignature {
67
+ /** `sha256:<64 lowercase hex>` of the output bytes. */
68
+ readonly hash: string;
69
+ readonly signer: OutputSigner;
70
+ readonly scheme: OutputSignatureScheme;
71
+ /** eip191: 0x + 130 hex. p256: 128 hex (r‖s). Lowercase. */
72
+ readonly sig: string;
73
+ }
74
+ /** The `input_origins` entry of a signed citation. */
75
+ export interface OutputCitationOrigin {
76
+ readonly hash: string;
77
+ readonly origin_identifier: string;
78
+ readonly witnessed: boolean;
79
+ readonly witness?: {
80
+ readonly type: string;
81
+ readonly identity: string;
82
+ readonly attestation_tier?: string;
83
+ };
84
+ readonly signature: OutputSignature;
85
+ }
86
+ /** The scheme each signer kind signs with (one scheme per kind). */
87
+ export declare const OUTPUT_SIGNER_SCHEMES: Readonly<Record<OutputSignerKind, OutputSignatureScheme>>;
88
+ /** `sha256:<hex>` of an output's exact bytes. */
89
+ export declare function outputHashOfBytes(bytes: Uint8Array): string;
90
+ /** `sha256:<hex>` of an output that is text (UTF-8). */
91
+ export declare function outputHashOfText(text: string): string;
92
+ /** The canonical form of an output hash (`sha256:` + 64 lowercase hex), or null. */
93
+ export declare function canonicalOutputHash(value: unknown): string | null;
94
+ /** The exact UTF-8 message every signer kind signs for an output hash. */
95
+ export declare function outputSignatureMessage(hash: string): string;
96
+ /** SHA-256 (hex) of the message — the digest a P-256 signer (Secure Enclave, StrongBox) signs. */
97
+ export declare function outputSignatureDigestHex(hash: string): string;
98
+ /** The canonical form of a signer reference, or null. */
99
+ export declare function normalizeOutputSigner(value: unknown): OutputSigner | null;
100
+ /**
101
+ * The canonical form of a signature object, or null when it is not one. Shape only (the scheme must
102
+ * be the signer kind's scheme and the sig must have that scheme's shape): whether the signature
103
+ * verifies against the signer's registered key is the verifier's check (the relay's, at intake).
104
+ */
105
+ export declare function normalizeOutputSignature(value: unknown): OutputSignature | null;
106
+ /** The canonical SEC1 uncompressed P-256 public key (`04` + 128 hex, lowercase, no 0x), or null. */
107
+ export declare function canonicalP256PublicKey(value: unknown): string | null;
108
+ /** The registered id of an app output key: `aok_` + the first 32 hex of sha256(public key bytes). */
109
+ export declare function appOutputKeyId(publicKeyHex: string): string;
110
+ /**
111
+ * The proof-of-possession message a P-256 output key signs (ECDSA P-256 over SHA-256 of it) when
112
+ * it is registered: bound to the key kind, the identity registering it, and the key itself.
113
+ */
114
+ export declare function outputKeyRegistrationMessage(kind: 'device' | 'app', ownerId: string, publicKeyHex: string): string;
115
+ /** The `Provian-Output-Signature` header value for a signature object. */
116
+ export declare function encodeOutputSignatureHeader(signature: OutputSignature): string;
117
+ /**
118
+ * Read a `Provian-Output-Signature` header value (base64url of the JSON object, or the JSON object
119
+ * itself), or null when it is not a well-formed signature object.
120
+ */
121
+ export declare function decodeOutputSignatureHeader(value: unknown): OutputSignature | null;
122
+ /** `out:<kind>:<id>` for a signer. */
123
+ export declare function outputCitationIdentifier(signer: OutputSigner): string;
124
+ /** The signer an `out:<kind>:<id>` identifier names, or null. */
125
+ export declare function outputCitationSignerOf(originIdentifier: unknown): OutputSigner | null;
126
+ /**
127
+ * The `input_origins` entry a consumer's next PE carries for an output it received signed. The
128
+ * `witness` is the CITING lane's own witness (e.g. the observer daemon's device) — never the
129
+ * producer: the producer's signature names the owner, not the act's witness. Without one the entry
130
+ * is `witnessed: false`, and whether a non-actor key vouched the citing act is the relay's call.
131
+ */
132
+ export declare function outputCitationOrigin(signature: OutputSignature, citingWitness?: {
133
+ readonly type: string;
134
+ readonly identity: string;
135
+ readonly attestation_tier?: string;
136
+ } | null): OutputCitationOrigin;
137
+ /**
138
+ * The signature carried on an `input_origins` entry when the entry is a well-formed signed citation
139
+ * (an `out:` identifier, a well-formed signature naming the same signer and the same hash), else
140
+ * null. Shape only — verification against the registered key is the verifier's.
141
+ */
142
+ export declare function signedCitationOf(origin: unknown): OutputSignature | null;
143
+ /** A forum post or reply: its trimmed content. */
144
+ export declare function forumPostOutputText(content: string): string;
145
+ /** A want: its outcome, capabilities and preferred chains, normalized as the relay stores them. */
146
+ export declare function wantOutputText(outcome: string, capabilities: readonly string[], preferredChains?: readonly string[]): string;
147
+ /** A hiring-board job post: its trimmed title and description. */
148
+ export declare function jobPostOutputText(title: string, description: string): string;
149
+ /** A job deliverable: its body when it has one, else its trimmed URI. */
150
+ export declare function deliverableOutputText(uri: string | null | undefined, body: string | null | undefined): string;
151
+ /**
152
+ * A thread message is E2E ciphertext the relay cannot read, so its signature rides INSIDE the
153
+ * sealed plaintext as a trailing header line; the signature covers the message text before it.
154
+ */
155
+ export declare const THREAD_OUTPUT_SIGNATURE_TRAILER = "\n\nProvian-Output-Signature: ";
156
+ export declare function withThreadOutputSignature(text: string, signature: OutputSignature): string;
157
+ /** Split a thread plaintext into its text and the signature over exactly that text (else null). */
158
+ export declare function splitThreadOutputSignature(plaintext: string): {
159
+ text: string;
160
+ signature: OutputSignature | null;
161
+ };
162
+ //# sourceMappingURL=output-signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-signature.d.ts","sourceRoot":"","sources":["../../src/core/output-signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAKH,eAAO,MAAM,+BAA+B,uBAAuB,CAAC;AACpE,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,kGAAkG;AAClG,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AACpE,yEAAyE;AACzE,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAC7C,yFAAyF;AACzF,eAAO,MAAM,+BAA+B,OAAO,CAAC;AACpD,sFAAsF;AACtF,eAAO,MAAM,8BAA8B,2BAA2B,CAAC;AAEvE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;AAC3D,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,GAAG,aAAa,CAAC;AAEvE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B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