@provian/mcp 0.0.0-stage → 1.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +266 -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 +3623 -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,367 @@
1
+ "use strict";
2
+ /**
3
+ * OUTPUT SIGNATURE — the ONE definition of a signature over an output an agent or a person's device
4
+ * hands out, and of the citation that carries it :
5
+ *
6
+ * "every output an agent hands out carries its signature over the output's hash (SDK, MCP and
7
+ * facilitator responses). A citation counts toward the producer's consumption when it carries
8
+ * that signature."
9
+ * "1. The producer's signature only establishes who made the output. The citing act must still
10
+ * be witnessed, and the ring and self filters still apply …
11
+ * 2. Outputs produced on devices that don't hold the wallet key (the MacBook daemon, phones) are
12
+ * signed with that device's registered key and map to the owner through the same identity
13
+ * index, so human-device work earns consumption too."
14
+ *
15
+ * THIS FILE IS BYTE-IDENTICAL IN THREE PACKAGES and `scripts/check-meter-wire-parity.sh` refuses any
16
+ * drift:
17
+ * provian-backend/src/core/meter/output-signature.ts (the relay: verifies at intake)
18
+ * provian-agent-sdk/src/output-signature.ts (daemon + SDK: signs and cites)
19
+ * src/core/meter/output-signature.ts (the app: signs and cites)
20
+ * Pure: no I/O, no clock, no key material. Signing and verification are each package's own, over
21
+ * the message defined here; `docs/audit/output-signature-vectors.json` binds every package to the
22
+ * same bytes.
23
+ *
24
+ * WHAT IS SIGNED — one message for every key kind:
25
+ * hash `sha256:<64 lowercase hex>` of the output's exact bytes (what the consumer received).
26
+ * message `provian-output:v1:<64 lowercase hex>` (UTF-8). Domain-separated from every other
27
+ * Provian-signed message (none begins `provian-output:`; it is not base64url, so it can
28
+ * never be a device-signature preimage), and it carries the literal "provian", so the
29
+ * app's WalletConnect guard never lets a dApp obtain one (`provianReserved.ts`).
30
+ *
31
+ * WHO SIGNS — the producer's REGISTERED key, three kinds:
32
+ * 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
33
+ * (0x + 40 lowercase hex), resolved through the native wallet address index or a proven
34
+ * address registry.
35
+ * device a registered observer device (`devices/{id}` e.g. a human's MacBook daemon), its
36
+ * Secure-Enclave P-256 `signing_public_key`, or the P-256 output key a bearer device
37
+ * registered. scheme `p256_sha256` ECDSA P-256 over SHA-256(message); sig = 128
38
+ * lowercase hex (r‖s, low-s). id = the device id.
39
+ * app a phone running the Provian app: its hardware PE-attestation key
40
+ * (`provian_pe_attestation`, Secure Enclave / StrongBox — never the wallet key),
41
+ * registered once under wallet auth. scheme `p256_sha256`. id = `aok_` + 32 hex.
42
+ *
43
+ * HOW IT TRAVELS
44
+ * HTTP response header `Provian-Output-Signature: <base64url(canonical JSON of the object)>`.
45
+ * MCP/JSON the object itself under `provian_output_signature`.
46
+ * PE the consumer's next PE cites it as one `input_origins` entry:
47
+ * `{ hash, origin_identifier: "out:<kind>:<id>", witnessed, witness?, signature }`.
48
+ * The signature establishes WHO MADE the output (the owner of the citation edge); it
49
+ * never makes the citing act witnessed — that is the citing lane's own witness.
50
+ */
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.THREAD_OUTPUT_SIGNATURE_TRAILER = exports.OUTPUT_SIGNER_SCHEMES = exports.OUTPUT_KEY_REGISTRATION_PREFIX = exports.OUTPUT_SIGNATURE_HEADER_MAX_LEN = exports.OUTPUT_CITATION_SCHEME = exports.OUTPUT_SIGNATURE_JSON_KEY = exports.OUTPUT_SIGNATURE_HEADER = exports.OUTPUT_SIGNATURE_MESSAGE_PREFIX = void 0;
53
+ exports.outputHashOfBytes = outputHashOfBytes;
54
+ exports.outputHashOfText = outputHashOfText;
55
+ exports.canonicalOutputHash = canonicalOutputHash;
56
+ exports.outputSignatureMessage = outputSignatureMessage;
57
+ exports.outputSignatureDigestHex = outputSignatureDigestHex;
58
+ exports.normalizeOutputSigner = normalizeOutputSigner;
59
+ exports.normalizeOutputSignature = normalizeOutputSignature;
60
+ exports.canonicalP256PublicKey = canonicalP256PublicKey;
61
+ exports.appOutputKeyId = appOutputKeyId;
62
+ exports.outputKeyRegistrationMessage = outputKeyRegistrationMessage;
63
+ exports.encodeOutputSignatureHeader = encodeOutputSignatureHeader;
64
+ exports.decodeOutputSignatureHeader = decodeOutputSignatureHeader;
65
+ exports.outputCitationIdentifier = outputCitationIdentifier;
66
+ exports.outputCitationSignerOf = outputCitationSignerOf;
67
+ exports.outputCitationOrigin = outputCitationOrigin;
68
+ exports.signedCitationOf = signedCitationOf;
69
+ exports.forumPostOutputText = forumPostOutputText;
70
+ exports.wantOutputText = wantOutputText;
71
+ exports.jobPostOutputText = jobPostOutputText;
72
+ exports.deliverableOutputText = deliverableOutputText;
73
+ exports.withThreadOutputSignature = withThreadOutputSignature;
74
+ exports.splitThreadOutputSignature = splitThreadOutputSignature;
75
+ const meter_wire_1 = require("./meter-wire");
76
+ const meter_hash_1 = require("./meter-hash");
77
+ exports.OUTPUT_SIGNATURE_MESSAGE_PREFIX = 'provian-output:v1:';
78
+ exports.OUTPUT_SIGNATURE_HEADER = 'Provian-Output-Signature';
79
+ /** The JSON key a non-HTTP surface (an MCP tool result, a JSON body) carries the object under. */
80
+ exports.OUTPUT_SIGNATURE_JSON_KEY = 'provian_output_signature';
81
+ /** The `input_origins` class of a signed citation: `out:<kind>:<id>`. */
82
+ exports.OUTPUT_CITATION_SCHEME = 'out:';
83
+ /** Longest header value accepted (a wallet-signed object encodes to ~420 characters). */
84
+ exports.OUTPUT_SIGNATURE_HEADER_MAX_LEN = 2048;
85
+ /** The message a P-256 output key signs to prove possession when it is registered. */
86
+ exports.OUTPUT_KEY_REGISTRATION_PREFIX = 'provian-output-key:v1:';
87
+ const HASH_RE = /^sha256:[0-9a-f]{64}$/;
88
+ const ADDRESS_RE = /^0x[0-9a-f]{40}$/;
89
+ const DEVICE_ID_RE = /^[A-Za-z0-9_-]{1,200}$/;
90
+ const APP_KEY_ID_RE = /^aok_[0-9a-f]{32}$/;
91
+ const EIP191_SIG_RE = /^0x[0-9a-f]{130}$/;
92
+ const P256_SIG_RE = /^[0-9a-f]{128}$/;
93
+ const P256_PUBLIC_KEY_RE = /^04[0-9a-f]{128}$/;
94
+ /** The scheme each signer kind signs with (one scheme per kind). */
95
+ exports.OUTPUT_SIGNER_SCHEMES = Object.freeze({
96
+ wallet: 'eip191_secp256k1',
97
+ device: 'p256_sha256',
98
+ app: 'p256_sha256',
99
+ });
100
+ /** `sha256:<hex>` of an output's exact bytes. */
101
+ function outputHashOfBytes(bytes) {
102
+ return `sha256:${(0, meter_wire_1.bytesToHexLower)((0, meter_hash_1.sha256Bytes)(bytes))}`;
103
+ }
104
+ /** `sha256:<hex>` of an output that is text (UTF-8). */
105
+ function outputHashOfText(text) {
106
+ return outputHashOfBytes((0, meter_wire_1.utf8Bytes)(text));
107
+ }
108
+ /** The canonical form of an output hash (`sha256:` + 64 lowercase hex), or null. */
109
+ function canonicalOutputHash(value) {
110
+ if (typeof value !== 'string')
111
+ return null;
112
+ const lower = value.trim().toLowerCase();
113
+ return HASH_RE.test(lower) ? lower : null;
114
+ }
115
+ /** The exact UTF-8 message every signer kind signs for an output hash. */
116
+ function outputSignatureMessage(hash) {
117
+ const canonical = canonicalOutputHash(hash);
118
+ if (canonical === null)
119
+ throw new Error('output_signature_bad_hash');
120
+ return exports.OUTPUT_SIGNATURE_MESSAGE_PREFIX + canonical.slice('sha256:'.length);
121
+ }
122
+ /** SHA-256 (hex) of the message — the digest a P-256 signer (Secure Enclave, StrongBox) signs. */
123
+ function outputSignatureDigestHex(hash) {
124
+ return (0, meter_wire_1.bytesToHexLower)((0, meter_hash_1.sha256Bytes)((0, meter_wire_1.utf8Bytes)(outputSignatureMessage(hash))));
125
+ }
126
+ /** The canonical form of a signer reference, or null. */
127
+ function normalizeOutputSigner(value) {
128
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
129
+ return null;
130
+ const v = value;
131
+ if (typeof v.id !== 'string')
132
+ return null;
133
+ switch (v.kind) {
134
+ case 'wallet': {
135
+ const id = v.id.trim().toLowerCase();
136
+ return ADDRESS_RE.test(id) ? { kind: 'wallet', id } : null;
137
+ }
138
+ case 'device':
139
+ return DEVICE_ID_RE.test(v.id) ? { kind: 'device', id: v.id } : null;
140
+ case 'app': {
141
+ const id = v.id.trim().toLowerCase();
142
+ return APP_KEY_ID_RE.test(id) ? { kind: 'app', id } : null;
143
+ }
144
+ default:
145
+ return null;
146
+ }
147
+ }
148
+ /**
149
+ * The canonical form of a signature object, or null when it is not one. Shape only (the scheme must
150
+ * be the signer kind's scheme and the sig must have that scheme's shape): whether the signature
151
+ * verifies against the signer's registered key is the verifier's check (the relay's, at intake).
152
+ */
153
+ function normalizeOutputSignature(value) {
154
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
155
+ return null;
156
+ const v = value;
157
+ const hash = canonicalOutputHash(v.hash);
158
+ const signer = normalizeOutputSigner(v.signer);
159
+ if (hash === null || signer === null || typeof v.sig !== 'string')
160
+ return null;
161
+ const scheme = exports.OUTPUT_SIGNER_SCHEMES[signer.kind];
162
+ if (v.scheme !== scheme)
163
+ return null;
164
+ const sig = v.sig.trim().toLowerCase();
165
+ if (scheme === 'eip191_secp256k1' ? !EIP191_SIG_RE.test(sig) : !P256_SIG_RE.test(sig))
166
+ return null;
167
+ return { hash, signer, scheme, sig };
168
+ }
169
+ /** The canonical SEC1 uncompressed P-256 public key (`04` + 128 hex, lowercase, no 0x), or null. */
170
+ function canonicalP256PublicKey(value) {
171
+ if (typeof value !== 'string')
172
+ return null;
173
+ const v = value.trim().toLowerCase();
174
+ const hex = v.startsWith('0x') ? v.slice(2) : v;
175
+ return P256_PUBLIC_KEY_RE.test(hex) ? hex : null;
176
+ }
177
+ /** The registered id of an app output key: `aok_` + the first 32 hex of sha256(public key bytes). */
178
+ function appOutputKeyId(publicKeyHex) {
179
+ const key = canonicalP256PublicKey(publicKeyHex);
180
+ if (key === null)
181
+ throw new Error('output_key_bad_public_key');
182
+ const bytes = new Uint8Array(key.length / 2);
183
+ for (let i = 0; i < bytes.length; i++)
184
+ bytes[i] = parseInt(key.slice(i * 2, i * 2 + 2), 16);
185
+ return `aok_${(0, meter_wire_1.bytesToHexLower)((0, meter_hash_1.sha256Bytes)(bytes)).slice(0, 32)}`;
186
+ }
187
+ /**
188
+ * The proof-of-possession message a P-256 output key signs (ECDSA P-256 over SHA-256 of it) when
189
+ * it is registered: bound to the key kind, the identity registering it, and the key itself.
190
+ */
191
+ function outputKeyRegistrationMessage(kind, ownerId, publicKeyHex) {
192
+ const key = canonicalP256PublicKey(publicKeyHex);
193
+ if (key === null)
194
+ throw new Error('output_key_bad_public_key');
195
+ if (ownerId.length === 0 || ownerId.includes(':'))
196
+ throw new Error('output_key_bad_owner');
197
+ return `${exports.OUTPUT_KEY_REGISTRATION_PREFIX}${kind}:${ownerId}:${key}`;
198
+ }
199
+ // ─── base64url over ASCII (pure; the object's canonical JSON is ASCII-only) ─────
200
+ const B64URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
201
+ function base64UrlOfAscii(text) {
202
+ let out = '';
203
+ for (let i = 0; i < text.length; i += 3) {
204
+ const a = text.charCodeAt(i);
205
+ const b = i + 1 < text.length ? text.charCodeAt(i + 1) : -1;
206
+ const c = i + 2 < text.length ? text.charCodeAt(i + 2) : -1;
207
+ out += B64URL[a >> 2];
208
+ out += B64URL[((a & 3) << 4) | (b < 0 ? 0 : b >> 4)];
209
+ if (b >= 0)
210
+ out += B64URL[((b & 15) << 2) | (c < 0 ? 0 : c >> 6)];
211
+ if (c >= 0)
212
+ out += B64URL[c & 63];
213
+ }
214
+ return out;
215
+ }
216
+ function asciiOfBase64Url(value) {
217
+ if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1)
218
+ return null;
219
+ let bits = 0;
220
+ let acc = 0;
221
+ let out = '';
222
+ for (let i = 0; i < value.length; i++) {
223
+ acc = ((acc << 6) | B64URL.indexOf(value[i])) & 0xffffff;
224
+ bits += 6;
225
+ if (bits >= 8) {
226
+ bits -= 8;
227
+ const code = (acc >> bits) & 255;
228
+ if (code > 126 || code < 32)
229
+ return null;
230
+ out += String.fromCharCode(code);
231
+ }
232
+ }
233
+ return out;
234
+ }
235
+ /** The `Provian-Output-Signature` header value for a signature object. */
236
+ function encodeOutputSignatureHeader(signature) {
237
+ const canonical = normalizeOutputSignature(signature);
238
+ if (canonical === null)
239
+ throw new Error('output_signature_bad_shape');
240
+ return base64UrlOfAscii((0, meter_wire_1.canonicalJson)(canonical));
241
+ }
242
+ /**
243
+ * Read a `Provian-Output-Signature` header value (base64url of the JSON object, or the JSON object
244
+ * itself), or null when it is not a well-formed signature object.
245
+ */
246
+ function decodeOutputSignatureHeader(value) {
247
+ if (typeof value !== 'string')
248
+ return null;
249
+ const trimmed = value.trim();
250
+ if (trimmed.length === 0 || trimmed.length > exports.OUTPUT_SIGNATURE_HEADER_MAX_LEN)
251
+ return null;
252
+ const json = trimmed.startsWith('{') ? trimmed : asciiOfBase64Url(trimmed);
253
+ if (json === null)
254
+ return null;
255
+ try {
256
+ return normalizeOutputSignature(JSON.parse(json));
257
+ }
258
+ catch {
259
+ return null;
260
+ }
261
+ }
262
+ /** `out:<kind>:<id>` for a signer. */
263
+ function outputCitationIdentifier(signer) {
264
+ const s = normalizeOutputSigner(signer);
265
+ if (s === null)
266
+ throw new Error('output_signature_bad_signer');
267
+ return `${exports.OUTPUT_CITATION_SCHEME}${s.kind}:${s.id}`;
268
+ }
269
+ /** The signer an `out:<kind>:<id>` identifier names, or null. */
270
+ function outputCitationSignerOf(originIdentifier) {
271
+ if (typeof originIdentifier !== 'string' || !originIdentifier.startsWith(exports.OUTPUT_CITATION_SCHEME))
272
+ return null;
273
+ const rest = originIdentifier.slice(exports.OUTPUT_CITATION_SCHEME.length);
274
+ const colon = rest.indexOf(':');
275
+ if (colon <= 0)
276
+ return null;
277
+ const signer = normalizeOutputSigner({ kind: rest.slice(0, colon), id: rest.slice(colon + 1) });
278
+ // The identifier must already be canonical (it is hashed into the citer's PE).
279
+ return signer !== null && `${signer.kind}:${signer.id}` === rest ? signer : null;
280
+ }
281
+ /**
282
+ * The `input_origins` entry a consumer's next PE carries for an output it received signed. The
283
+ * `witness` is the CITING lane's own witness (e.g. the observer daemon's device) — never the
284
+ * producer: the producer's signature names the owner, not the act's witness. Without one the entry
285
+ * is `witnessed: false`, and whether a non-actor key vouched the citing act is the relay's call.
286
+ */
287
+ function outputCitationOrigin(signature, citingWitness) {
288
+ const s = normalizeOutputSignature(signature);
289
+ if (s === null)
290
+ throw new Error('output_signature_bad_shape');
291
+ const base = { hash: s.hash, origin_identifier: outputCitationIdentifier(s.signer) };
292
+ return citingWitness
293
+ ? { ...base, witnessed: true, witness: { ...citingWitness }, signature: s }
294
+ : { ...base, witnessed: false, signature: s };
295
+ }
296
+ /**
297
+ * The signature carried on an `input_origins` entry when the entry is a well-formed signed citation
298
+ * (an `out:` identifier, a well-formed signature naming the same signer and the same hash), else
299
+ * null. Shape only — verification against the registered key is the verifier's.
300
+ */
301
+ function signedCitationOf(origin) {
302
+ if (origin === null || typeof origin !== 'object' || Array.isArray(origin))
303
+ return null;
304
+ const o = origin;
305
+ const signer = outputCitationSignerOf(o.origin_identifier);
306
+ const signature = normalizeOutputSignature(o.signature);
307
+ if (signer === null || signature === null)
308
+ return null;
309
+ if (signature.signer.kind !== signer.kind || signature.signer.id !== signer.id)
310
+ return null;
311
+ if (signature.hash !== canonicalOutputHash(o.hash))
312
+ return null;
313
+ return signature;
314
+ }
315
+ // ─── Commons outputs : what each Commons write's signature covers ─────────────
316
+ //
317
+ // A person (or agent) signs the content a Commons write publishes, over EXACTLY the text whose
318
+ // sha256 the write's PE seals in `output_digests`; the relay recomputes the same text from what it
319
+ // stores, refuses a signature over anything else, keeps the signature beside the record
320
+ // (`provian_output_signature`) and serves it with it, so a reader's witnessed act can cite it.
321
+ function dedupLower(values) {
322
+ const out = [];
323
+ for (const v of values) {
324
+ const c = v.trim().toLowerCase();
325
+ if (c.length > 0 && !out.includes(c))
326
+ out.push(c);
327
+ }
328
+ return out;
329
+ }
330
+ /** A forum post or reply: its trimmed content. */
331
+ function forumPostOutputText(content) {
332
+ return content.trim();
333
+ }
334
+ /** A want: its outcome, capabilities and preferred chains, normalized as the relay stores them. */
335
+ function wantOutputText(outcome, capabilities, preferredChains = []) {
336
+ return JSON.stringify({ outcome: outcome.trim(), capabilities: dedupLower(capabilities), preferredChains: dedupLower(preferredChains) });
337
+ }
338
+ /** A hiring-board job post: its trimmed title and description. */
339
+ function jobPostOutputText(title, description) {
340
+ return JSON.stringify({ title: title.trim(), description: description.trim() });
341
+ }
342
+ /** A job deliverable: its body when it has one, else its trimmed URI. */
343
+ function deliverableOutputText(uri, body) {
344
+ const b = typeof body === 'string' ? body : '';
345
+ return b.length > 0 ? b : (typeof uri === 'string' ? uri.trim() : '');
346
+ }
347
+ /**
348
+ * A thread message is E2E ciphertext the relay cannot read, so its signature rides INSIDE the
349
+ * sealed plaintext as a trailing header line; the signature covers the message text before it.
350
+ */
351
+ exports.THREAD_OUTPUT_SIGNATURE_TRAILER = `\n\n${exports.OUTPUT_SIGNATURE_HEADER}: `;
352
+ function withThreadOutputSignature(text, signature) {
353
+ return `${text}${exports.THREAD_OUTPUT_SIGNATURE_TRAILER}${encodeOutputSignatureHeader(signature)}`;
354
+ }
355
+ /** Split a thread plaintext into its text and the signature over exactly that text (else null). */
356
+ function splitThreadOutputSignature(plaintext) {
357
+ const at = plaintext.lastIndexOf(exports.THREAD_OUTPUT_SIGNATURE_TRAILER);
358
+ if (at < 0)
359
+ return { text: plaintext, signature: null };
360
+ const value = plaintext.slice(at + exports.THREAD_OUTPUT_SIGNATURE_TRAILER.length);
361
+ const signature = /^[A-Za-z0-9_-]+$/.test(value) ? decodeOutputSignatureHeader(value) : null;
362
+ const text = plaintext.slice(0, at);
363
+ if (signature === null || signature.hash !== outputHashOfText(text))
364
+ return { text: plaintext, signature: null };
365
+ return { text, signature };
366
+ }
367
+ //# sourceMappingURL=output-signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-signature.js","sourceRoot":"","sources":["../../src/core/output-signature.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;;;AA0DH,8CAEC;AAGD,4CAEC;AAGD,kDAIC;AAGD,wDAIC;AAGD,4DAEC;AAGD,sDAkBC;AAOD,4DAWC;AAGD,wDAKC;AAGD,wCAMC;AAMD,oEAKC;AAuCD,kEAIC;AAMD,kEAWC;AAGD,4DAIC;AAGD,wDAQC;AAQD,oDAUC;AAOD,4CASC;AAmBD,kDAEC;AAGD,wCAEC;AAGD,8CAEC;AAGD,sDAGC;AAQD,8DAEC;AAGD,gEAQC;AA/TD,6CAAyE;AACzE,6CAA2C;AAE9B,QAAA,+BAA+B,GAAG,oBAAoB,CAAC;AACvD,QAAA,uBAAuB,GAAG,0BAA0B,CAAC;AAClE,kGAAkG;AACrF,QAAA,yBAAyB,GAAG,0BAA0B,CAAC;AACpE,yEAAyE;AAC5D,QAAA,sBAAsB,GAAG,MAAM,CAAC;AAC7C,yFAAyF;AAC5E,QAAA,+BAA+B,GAAG,IAAI,CAAC;AACpD,sFAAsF;AACzE,QAAA,8BAA8B,GAAG,wBAAwB,CAAC;AA4BvE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KAAK,CAAC,EAAE,GAAG,uCAA+B,CAAC,MAAM,CAAC,CAAC;IAC3E,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7F,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACpC,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,CAAC,IAAI,KAAK,gBAAgB,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACjH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Burn-to-present — canonical binding + claims digest for the MCP `present` tool.
3
+ *
4
+ * SHARED CORE — canonical in `provian-mcp/src/core/`, mirrored byte-identically
5
+ * into `provian-backend/src/mcp/core/`. Edit only the canonical copy and run
6
+ * `scripts/sync-mcp-core.sh`.
7
+ *
8
+ * a presentation against a SIGNED challenge binds `provian-presentation-v2` the v1 lines
9
+ * plus `req=<requesterString>` and `chal_exp=<n>`; without a signed challenge the binding is v1,
10
+ * byte-identical to before. The challenge envelope itself lives in `challenge.ts`.
11
+ *
12
+ * A LINE-FOR-LINE PORT of `provian-agent-sdk/src/presentation.ts`
13
+ * (`claimsDigest` / `presentationBindingString` / `canonicalReputationDirective`)
14
+ * and the backend's `core/presentation/types.ts` the SAME bytes the presenter
15
+ * signs and the relay verifies. The MCP core cannot import the SDK (separate
16
+ * package) or the relay internals, so it carries its own audited copy, exactly as
17
+ * `crypto.ts` ports the SDK key handling. Pinned by a fixed-vector parity test
18
+ * (`presentation.test.ts`); a drift there means the presenter PoP would verify
19
+ * against the wrong bytes. Node-crypto-only (no npm deps), so the backend mirror
20
+ * compiles with nothing new.
21
+ */
22
+ import { type CanonicalDisclosureRequest, type DisclosureAnswer, type DisclosureElection } from './disclosure-request';
23
+ export declare const PRESENTATION_BINDING_TAG = "provian-presentation-v1";
24
+ /** the binding tag for a presentation produced against a SIGNED challenge. */
25
+ export declare const PRESENTATION_BINDING_TAG_V2 = "provian-presentation-v2";
26
+ export declare const PRESENTATION_MIN_TTL_SECONDS = 60;
27
+ export declare const PRESENTATION_MAX_TTL_SECONDS = 900;
28
+ export declare const PRESENTATION_DEFAULT_TTL_SECONDS = 300;
29
+ /** Clock skew every verifier tolerates past a deadline (seconds). */
30
+ export declare const PRESENTATION_CLOCK_SKEW_SECONDS = 60;
31
+ /** Challenge nonce length bounds (characters) and the audience length cap — mirror the relay. */
32
+ export declare const PRESENTATION_CHALLENGE_MIN_LEN = 16;
33
+ export declare const PRESENTATION_CHALLENGE_MAX_LEN = 512;
34
+ export declare const PRESENTATION_AUDIENCE_MAX_LEN = 512;
35
+ export type PresentationTier = 'pe_fact' | 'reputation';
36
+ /** the VERIFIED requester a v2 presentation names (wallet keeps its lowercase address). */
37
+ export interface PresentationRequester {
38
+ readonly type: 'domain' | 'wallet';
39
+ readonly id: string;
40
+ readonly address?: string;
41
+ }
42
+ /** `domain:<host>` | `wallet:<walletId>:<lowercase address>` — the signing-string / binding form. */
43
+ export declare function requesterString(r: {
44
+ type: 'domain' | 'wallet';
45
+ id: string;
46
+ address?: string;
47
+ }): string;
48
+ /** §2.6: five comparisons + set membership (`in` over a numeric set). Mirrors the backend byte-for-byte. */
49
+ export type PredicateOp = 'gte' | 'gt' | 'lte' | 'lt' | 'eq' | 'in';
50
+ export declare const PREDICATE_OPS: readonly PredicateOp[];
51
+ export declare const PREDICATE_SET_MAX = 64;
52
+ export interface PredicateRequest {
53
+ readonly field: string;
54
+ readonly op: PredicateOp;
55
+ /** The comparison value (every op but `in`). */
56
+ readonly threshold?: number;
57
+ /** The membership set (`in` only). */
58
+ readonly set?: readonly number[];
59
+ }
60
+ export interface DisclosureDirective {
61
+ readonly redact?: readonly string[];
62
+ readonly predicates?: readonly PredicateRequest[];
63
+ /** Share-only mode : reveal ONLY Standing, the predicate answers and these fields. Exclusive with `redact`. */
64
+ readonly share?: readonly string[];
65
+ }
66
+ export type CanonicalPredicate = {
67
+ field: string;
68
+ op: string;
69
+ threshold: number;
70
+ } | {
71
+ field: string;
72
+ op: 'in';
73
+ set: number[];
74
+ };
75
+ /** One predicate in canonical form: `in` carries a sorted, de-duplicated set; every other op its threshold. */
76
+ export declare function canonicalPredicate(p: PredicateRequest): CanonicalPredicate;
77
+ /**
78
+ * Parse an untrusted predicate list into well-formed requests, fail-closed (`null` on any malformed
79
+ * entry). Mirrors the backend `normalizePredicateRequests`.
80
+ */
81
+ export declare function normalizePredicateRequests(raw: unknown): PredicateRequest[] | null;
82
+ /** Two predicates are the same request when their canonical forms are byte-identical. */
83
+ export declare function predicateMatchesRequest(answered: PredicateRequest, requested: PredicateRequest): boolean;
84
+ /** Canonical, order-independent disclosure directive — matches SDK + backend. */
85
+ export declare function canonicalReputationDirective(directive: DisclosureDirective): {
86
+ redact: string[];
87
+ predicates: CanonicalPredicate[];
88
+ share?: string[];
89
+ };
90
+ /** A PE fact the presenter vouches for: its id and its anchored content hash. */
91
+ export interface PeFact {
92
+ peId: string;
93
+ envelopeHash: string;
94
+ /**
95
+ * PE meter: the PE itself (v2) and its two-hop inclusion proof. The relay keeps no PE, so a
96
+ * pe_fact presentation carries them; the claims digest still binds only peId + envelopeHash.
97
+ */
98
+ pe?: Readonly<Record<string, unknown>>;
99
+ inclusion?: Readonly<Record<string, unknown>>;
100
+ }
101
+ /** Tier-specific claims digest — matches SDK + backend claimsDigest. */
102
+ export declare function claimsDigest(input: {
103
+ tier: PresentationTier;
104
+ peFacts?: readonly PeFact[];
105
+ directive?: DisclosureDirective;
106
+ disclosures?: readonly DisclosureAnswer[];
107
+ }): string;
108
+ /** One record the presenter puts forward for a disclosure request: the PE and its two-hop proof. */
109
+ export interface DisclosedPeRecord {
110
+ readonly peId: string;
111
+ readonly envelopeHash: string;
112
+ readonly pe: Record<string, unknown>;
113
+ readonly inclusion: Record<string, unknown>;
114
+ }
115
+ /** The presenter's answer to one requester-named disclosure request. */
116
+ export interface DisclosureAnswerInput {
117
+ readonly request: CanonicalDisclosureRequest;
118
+ readonly election: DisclosureElection;
119
+ readonly records?: readonly DisclosedPeRecord[];
120
+ }
121
+ /** The identity-only commitment the presenter signs for its disclosure answers (mirrors the SDK). */
122
+ export declare function disclosureAnswersForCommitment(answers: readonly DisclosureAnswerInput[]): DisclosureAnswer[];
123
+ /**
124
+ * The canonical binding string the presenter signs — matches SDK + backend. With a signed challenge
125
+ * (`requester` AND `chalExp`) it is v2: the v2 tag, the same lines, then `req=` and `chal_exp=`.
126
+ */
127
+ export declare function presentationBindingString(fields: {
128
+ tier: PresentationTier;
129
+ presenterAddress: string;
130
+ aud: string;
131
+ chal: string;
132
+ iat: number;
133
+ exp: number;
134
+ jti: string;
135
+ burnId: string;
136
+ claimsDigest: string;
137
+ /** v2 (signed challenge) only — both or neither. */
138
+ requester?: PresentationRequester;
139
+ chalExp?: number;
140
+ }): string;
141
+ //# sourceMappingURL=presentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation.d.ts","sourceRoot":"","sources":["../../src/core/presentation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAA8B,KAAK,0BAA0B,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEnJ,eAAO,MAAM,wBAAwB,4BAA4B,CAAC;AAClE,8EAA8E;AAC9E,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AACrE,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,gCAAgC,MAAM,CAAC;AACpD,qEAAqE;AACrE,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAClD,iGAAiG;AACjG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