@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,440 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.MCP_AGENT_WALLET_IDENTITY_PATH = exports.MCP_PENDING_AGENT_WALLET_PATH = void 0;
37
+ exports.loadOrCreatePendingAgentWalletRegistration = loadOrCreatePendingAgentWalletRegistration;
38
+ exports.reloadPendingAgentWalletRegistration = reloadPendingAgentWalletRegistration;
39
+ exports.completePendingAgentWalletRegistration = completePendingAgentWalletRegistration;
40
+ exports.loadCompletedAgentWalletIdentity = loadCompletedAgentWalletIdentity;
41
+ exports.clearCompletedAgentWalletPending = clearCompletedAgentWalletPending;
42
+ const crypto_1 = require("crypto");
43
+ const fs = __importStar(require("fs"));
44
+ const os_1 = require("os");
45
+ const path = __importStar(require("path"));
46
+ const util_1 = require("util");
47
+ const crypto_2 = require("./core/crypto");
48
+ exports.MCP_PENDING_AGENT_WALLET_PATH = path.join((0, os_1.homedir)(), '.provian', 'pending-mcp-agent-wallet.json');
49
+ exports.MCP_AGENT_WALLET_IDENTITY_PATH = path.join((0, os_1.homedir)(), '.provian', 'agent-wallet-identity.json');
50
+ const PENDING_KEYS = [
51
+ 'address',
52
+ 'agent_id',
53
+ 'agent_name',
54
+ 'constitution_accepted_at',
55
+ 'context_sha256',
56
+ 'created_at_ms',
57
+ 'encrypted_private_key',
58
+ 'platform',
59
+ 'public_key',
60
+ 'registration_id',
61
+ 'schema_version',
62
+ ];
63
+ const ENCRYPTED_KEY_KEYS = [
64
+ 'N',
65
+ 'cipher',
66
+ 'ciphertext',
67
+ 'iv',
68
+ 'kdf',
69
+ 'p',
70
+ 'r',
71
+ 'salt',
72
+ 'tag',
73
+ ];
74
+ const FINAL_KEYS = ['pending_identity', 'schema_version', 'wallet_id'];
75
+ function isRecord(value) {
76
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
77
+ }
78
+ function hasExactKeys(value, expected) {
79
+ const actual = Object.keys(value).sort();
80
+ return actual.length === expected.length
81
+ && actual.every((key, index) => key === expected[index]);
82
+ }
83
+ function hasPathEntry(filePath) {
84
+ try {
85
+ fs.lstatSync(filePath);
86
+ return true;
87
+ }
88
+ catch (error) {
89
+ if (error.code === 'ENOENT')
90
+ return false;
91
+ return true;
92
+ }
93
+ }
94
+ function readPrivateJson(filePath, label) {
95
+ const noFollow = process.platform === 'win32' ? 0 : fs.constants.O_NOFOLLOW;
96
+ let fd;
97
+ try {
98
+ const pathStat = fs.lstatSync(filePath);
99
+ if (!pathStat.isFile() || pathStat.isSymbolicLink()) {
100
+ throw new Error(`${label} must be a private regular file`);
101
+ }
102
+ fd = fs.openSync(filePath, fs.constants.O_RDONLY | noFollow);
103
+ }
104
+ catch (error) {
105
+ if (error instanceof Error && error.message.startsWith(label))
106
+ throw error;
107
+ throw new Error(`${label} is missing, unreadable, or unsafe`);
108
+ }
109
+ try {
110
+ const stat = fs.fstatSync(fd);
111
+ if (!stat.isFile()
112
+ || (process.platform !== 'win32' && (stat.mode & 0o077) !== 0)) {
113
+ throw new Error(`${label} must be a private 0600 regular file`);
114
+ }
115
+ return JSON.parse(fs.readFileSync(fd, 'utf8'));
116
+ }
117
+ catch (error) {
118
+ if (error instanceof Error && error.message.startsWith(label))
119
+ throw error;
120
+ throw new Error(`${label} is malformed`);
121
+ }
122
+ finally {
123
+ fs.closeSync(fd);
124
+ }
125
+ }
126
+ function contextHash(context) {
127
+ return (0, crypto_1.createHash)('sha256').update(JSON.stringify({
128
+ relay_url: context.relay_url,
129
+ agent_name: context.agent_name,
130
+ requested_agent_id: context.requested_agent_id,
131
+ platform: context.platform,
132
+ }), 'utf8').digest('hex');
133
+ }
134
+ function validateContext(context) {
135
+ if (typeof context.relay_url !== 'string' || context.relay_url.trim().length === 0
136
+ || typeof context.agent_name !== 'string' || context.agent_name.trim().length === 0
137
+ || context.agent_name.length > 200
138
+ || typeof context.platform !== 'string' || context.platform.trim().length === 0
139
+ || context.platform.length > 64
140
+ || (context.requested_agent_id !== null
141
+ && !/^[A-Za-z0-9._-]{1,128}$/.test(context.requested_agent_id))) {
142
+ throw new Error('MCP wallet registration context is malformed');
143
+ }
144
+ }
145
+ function aad(file) {
146
+ return Buffer.from(JSON.stringify(file), 'utf8');
147
+ }
148
+ function deriveKey(passphrase, salt, N) {
149
+ return (0, crypto_1.scryptSync)(passphrase, salt, 32, { N, r: 8, p: 1, maxmem: 256 * N * 8 });
150
+ }
151
+ function parsePendingFile(value, expectedContext) {
152
+ if (!isRecord(value) || !hasExactKeys(value, PENDING_KEYS)) {
153
+ throw new Error('Pending MCP wallet identity has an unknown or incomplete schema');
154
+ }
155
+ const encrypted = value.encrypted_private_key;
156
+ if (!isRecord(encrypted) || !hasExactKeys(encrypted, ENCRYPTED_KEY_KEYS)) {
157
+ throw new Error('Pending MCP wallet encryption metadata has an unknown or incomplete schema');
158
+ }
159
+ if (value.schema_version !== 'provian-mcp-agent-wallet-pending/v1'
160
+ || typeof value.context_sha256 !== 'string'
161
+ || !/^[0-9a-f]{64}$/.test(value.context_sha256)
162
+ || typeof value.registration_id !== 'string'
163
+ || !/^[A-Za-z0-9][A-Za-z0-9_.:@-]{15,127}$/.test(value.registration_id)
164
+ || typeof value.agent_id !== 'string'
165
+ || !/^[A-Za-z0-9._-]{1,128}$/.test(value.agent_id)
166
+ || typeof value.agent_name !== 'string'
167
+ || value.agent_name.trim().length === 0
168
+ || value.agent_name.length > 200
169
+ || typeof value.platform !== 'string'
170
+ || value.platform.trim().length === 0
171
+ || value.platform.length > 64
172
+ || typeof value.constitution_accepted_at !== 'string'
173
+ || typeof value.created_at_ms !== 'number'
174
+ || !Number.isSafeInteger(value.created_at_ms)
175
+ || value.created_at_ms < 0
176
+ || value.created_at_ms > 8640000000000000
177
+ || new Date(value.created_at_ms).toISOString() !== value.constitution_accepted_at
178
+ || typeof value.public_key !== 'string'
179
+ || !/^[0-9a-f]{128}$/.test(value.public_key)
180
+ || typeof value.address !== 'string'
181
+ || !/^0x[0-9a-fA-F]{40}$/.test(value.address)
182
+ || encrypted.cipher !== 'aes-256-gcm'
183
+ || encrypted.kdf !== 'scrypt'
184
+ || typeof encrypted.N !== 'number'
185
+ || !Number.isSafeInteger(encrypted.N)
186
+ || encrypted.N < 1 << 10
187
+ || encrypted.N > 1 << 20
188
+ || (encrypted.N & (encrypted.N - 1)) !== 0
189
+ || encrypted.r !== 8
190
+ || encrypted.p !== 1
191
+ || typeof encrypted.salt !== 'string'
192
+ || !/^[0-9a-f]{64}$/.test(encrypted.salt)
193
+ || typeof encrypted.iv !== 'string'
194
+ || !/^[0-9a-f]{24}$/.test(encrypted.iv)
195
+ || typeof encrypted.tag !== 'string'
196
+ || !/^[0-9a-f]{32}$/.test(encrypted.tag)
197
+ || typeof encrypted.ciphertext !== 'string'
198
+ || !/^[0-9a-f]{64}$/.test(encrypted.ciphertext)) {
199
+ throw new Error('Pending MCP wallet identity is malformed');
200
+ }
201
+ if (expectedContext
202
+ && (value.context_sha256 !== contextHash(expectedContext)
203
+ || value.agent_name !== expectedContext.agent_name
204
+ || value.platform !== expectedContext.platform
205
+ || (expectedContext.requested_agent_id !== null
206
+ && value.agent_id !== expectedContext.requested_agent_id))) {
207
+ throw new Error('Pending MCP wallet identity does not match this relay/request context; refusing replacement');
208
+ }
209
+ return value;
210
+ }
211
+ function parseFinalFile(value) {
212
+ if (!isRecord(value) || !hasExactKeys(value, FINAL_KEYS)
213
+ || value.schema_version !== 'provian-mcp-agent-wallet/v1'
214
+ || typeof value.wallet_id !== 'string'
215
+ || !/^wallet_aw_[A-Za-z0-9_-]+$/.test(value.wallet_id)) {
216
+ throw new Error('Completed MCP wallet identity is malformed');
217
+ }
218
+ return {
219
+ schema_version: value.schema_version,
220
+ wallet_id: value.wallet_id,
221
+ pending_identity: parsePendingFile(value.pending_identity),
222
+ };
223
+ }
224
+ function encryptPrivateKey(privateKey, header, passphrase, N) {
225
+ if (passphrase.length < 8)
226
+ throw new Error('PROVIAN_KEYSTORE_PASSPHRASE must be at least 8 characters');
227
+ const salt = (0, crypto_1.randomBytes)(32);
228
+ const iv = (0, crypto_1.randomBytes)(12);
229
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', deriveKey(passphrase, salt, N), iv);
230
+ cipher.setAAD(aad(header));
231
+ const ciphertext = Buffer.concat([
232
+ cipher.update(Buffer.from(privateKey, 'hex')),
233
+ cipher.final(),
234
+ ]);
235
+ return {
236
+ cipher: 'aes-256-gcm',
237
+ kdf: 'scrypt',
238
+ N,
239
+ r: 8,
240
+ p: 1,
241
+ salt: salt.toString('hex'),
242
+ iv: iv.toString('hex'),
243
+ tag: cipher.getAuthTag().toString('hex'),
244
+ ciphertext: ciphertext.toString('hex'),
245
+ };
246
+ }
247
+ function decryptPrivateKey(file, passphrase) {
248
+ const encrypted = file.encrypted_private_key;
249
+ const { encrypted_private_key: _encrypted, ...header } = file;
250
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', deriveKey(passphrase, Buffer.from(encrypted.salt, 'hex'), encrypted.N), Buffer.from(encrypted.iv, 'hex'));
251
+ decipher.setAAD(aad(header));
252
+ decipher.setAuthTag(Buffer.from(encrypted.tag, 'hex'));
253
+ try {
254
+ const privateKey = Buffer.concat([
255
+ decipher.update(Buffer.from(encrypted.ciphertext, 'hex')),
256
+ decipher.final(),
257
+ ]).toString('hex');
258
+ if (!/^[0-9a-f]{64}$/.test(privateKey)
259
+ || (0, crypto_2.deriveAddressFromPrivateKey)(privateKey).toLowerCase() !== file.address.toLowerCase()
260
+ || (0, crypto_2.derivePublicKeyFromPrivateKey)(privateKey) !== file.public_key) {
261
+ throw new Error('Pending MCP wallet key does not match its declared identity');
262
+ }
263
+ return privateKey;
264
+ }
265
+ catch {
266
+ throw new Error('Unable to decrypt pending MCP wallet identity');
267
+ }
268
+ }
269
+ function atomicCreate(filePath, value) {
270
+ fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
271
+ const temp = `${filePath}.${process.pid}.${(0, crypto_1.randomBytes)(8).toString('hex')}.tmp`;
272
+ const fd = fs.openSync(temp, 'wx', 0o600);
273
+ try {
274
+ fs.writeFileSync(fd, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
275
+ fs.fsyncSync(fd);
276
+ }
277
+ finally {
278
+ fs.closeSync(fd);
279
+ }
280
+ try {
281
+ fs.linkSync(temp, filePath);
282
+ const dirFd = fs.openSync(path.dirname(filePath), 'r');
283
+ try {
284
+ fs.fsyncSync(dirFd);
285
+ }
286
+ finally {
287
+ fs.closeSync(dirFd);
288
+ }
289
+ }
290
+ finally {
291
+ try {
292
+ fs.unlinkSync(temp);
293
+ }
294
+ catch { /* linked */ }
295
+ }
296
+ }
297
+ function fsyncParentDirectory(filePath) {
298
+ const directoryFd = fs.openSync(path.dirname(filePath), 'r');
299
+ try {
300
+ fs.fsyncSync(directoryFd);
301
+ }
302
+ finally {
303
+ fs.closeSync(directoryFd);
304
+ }
305
+ }
306
+ function unlinkDurably(filePath) {
307
+ fs.unlinkSync(filePath);
308
+ fsyncParentDirectory(filePath);
309
+ }
310
+ function decodedPending(raw, context, passphrase) {
311
+ const file = parsePendingFile(raw, context);
312
+ return {
313
+ file,
314
+ registration: {
315
+ registrationId: file.registration_id,
316
+ agentId: file.agent_id,
317
+ agentName: file.agent_name,
318
+ platform: file.platform,
319
+ constitutionAcceptedAt: file.constitution_accepted_at,
320
+ privateKey: decryptPrivateKey(file, passphrase),
321
+ publicKey: file.public_key,
322
+ address: file.address,
323
+ },
324
+ };
325
+ }
326
+ function readPending(context, passphrase, pendingPath) {
327
+ return decodedPending(readPrivateJson(pendingPath, 'Pending MCP wallet identity'), context, passphrase).registration;
328
+ }
329
+ function loadOrCreatePendingAgentWalletRegistration(context, passphrase, pendingPath = exports.MCP_PENDING_AGENT_WALLET_PATH, scryptN = 1 << 17) {
330
+ validateContext(context);
331
+ if (hasPathEntry(pendingPath))
332
+ return readPending(context, passphrase, pendingPath);
333
+ const slug = context.agent_name.toLowerCase()
334
+ .replace(/[^a-z0-9._-]+/g, '-')
335
+ .replace(/^[-.]+|[-.]+$/g, '') || 'mcp-agent';
336
+ const agentId = context.requested_agent_id ?? `${slug}-${(0, crypto_1.randomBytes)(3).toString('hex')}`;
337
+ if (!/^[A-Za-z0-9._-]{1,128}$/.test(agentId))
338
+ throw new Error('agent_id format is invalid');
339
+ const keyPair = (0, crypto_2.generateAgentKeyPair)();
340
+ const createdAtMs = Date.now();
341
+ const header = {
342
+ schema_version: 'provian-mcp-agent-wallet-pending/v1',
343
+ context_sha256: contextHash(context),
344
+ registration_id: `mcp-agent-registration-${(0, crypto_1.randomUUID)()}`,
345
+ agent_id: agentId,
346
+ agent_name: context.agent_name,
347
+ platform: context.platform,
348
+ constitution_accepted_at: new Date(createdAtMs).toISOString(),
349
+ public_key: keyPair.publicKey,
350
+ address: keyPair.address,
351
+ created_at_ms: createdAtMs,
352
+ };
353
+ const file = {
354
+ ...header,
355
+ encrypted_private_key: encryptPrivateKey(keyPair.privateKey, header, passphrase, scryptN),
356
+ };
357
+ try {
358
+ atomicCreate(pendingPath, file);
359
+ }
360
+ catch (error) {
361
+ if (error.code !== 'EEXIST')
362
+ throw error;
363
+ return readPending(context, passphrase, pendingPath);
364
+ }
365
+ return { ...readPending(context, passphrase, pendingPath) };
366
+ }
367
+ /** Re-read the encrypted pending bytes after the relay challenge and require
368
+ * them to match the exact identity used for that challenge. The create POST
369
+ * must be built only from this second authenticated snapshot. */
370
+ function reloadPendingAgentWalletRegistration(context, passphrase, expected, pendingPath = exports.MCP_PENDING_AGENT_WALLET_PATH) {
371
+ validateContext(context);
372
+ const reloaded = readPending(context, passphrase, pendingPath);
373
+ if (!(0, util_1.isDeepStrictEqual)(reloaded, expected)) {
374
+ throw new Error('Pending MCP wallet identity changed after the relay challenge');
375
+ }
376
+ return { ...reloaded };
377
+ }
378
+ function completePendingAgentWalletRegistration(registrationId, wallet, options) {
379
+ validateContext(options.context);
380
+ const pendingPath = options.pendingPath ?? exports.MCP_PENDING_AGENT_WALLET_PATH;
381
+ const finalPath = options.finalPath ?? exports.MCP_AGENT_WALLET_IDENTITY_PATH;
382
+ if (!/^wallet_aw_[A-Za-z0-9_-]+$/.test(wallet.wallet_id)
383
+ || !/^0x[0-9a-fA-F]{40}$/.test(wallet.address)) {
384
+ throw new Error('Completed MCP wallet response has a malformed wallet identity');
385
+ }
386
+ const decoded = decodedPending(readPrivateJson(pendingPath, 'Pending MCP wallet identity'), options.context, options.passphrase);
387
+ const pending = decoded.file;
388
+ if (pending.registration_id !== registrationId
389
+ || pending.address.toLowerCase() !== wallet.address.toLowerCase()) {
390
+ throw new Error('Pending MCP wallet identity changed before completion');
391
+ }
392
+ const final = {
393
+ schema_version: 'provian-mcp-agent-wallet/v1',
394
+ wallet_id: wallet.wallet_id,
395
+ pending_identity: pending,
396
+ };
397
+ if (hasPathEntry(finalPath)) {
398
+ const existing = parseFinalFile(readPrivateJson(finalPath, 'Completed MCP wallet identity'));
399
+ decodedPending(existing.pending_identity, options.context, options.passphrase);
400
+ if (!(0, util_1.isDeepStrictEqual)(existing, final)) {
401
+ throw new Error('A different final MCP wallet identity already exists');
402
+ }
403
+ }
404
+ else {
405
+ atomicCreate(finalPath, final);
406
+ }
407
+ options.afterDurableStage?.('final_identity_durable');
408
+ unlinkDurably(pendingPath);
409
+ options.afterDurableStage?.('pending_identity_removed');
410
+ return finalPath;
411
+ }
412
+ function loadCompletedAgentWalletIdentity(passphrase, finalPath = exports.MCP_AGENT_WALLET_IDENTITY_PATH, expectedContext) {
413
+ if (expectedContext)
414
+ validateContext(expectedContext);
415
+ if (!hasPathEntry(finalPath))
416
+ return null;
417
+ const final = parseFinalFile(readPrivateJson(finalPath, 'Completed MCP wallet identity'));
418
+ const decoded = decodedPending(final.pending_identity, expectedContext, passphrase);
419
+ const pending = decoded.file;
420
+ return {
421
+ walletId: final.wallet_id,
422
+ ...decoded.registration,
423
+ };
424
+ }
425
+ /** Remove a retained pending file only after the final encrypted identity and
426
+ * separate exact same-wallet credentials have both been verified by the
427
+ * caller. This is the restart path for a crash after final-identity fsync. */
428
+ function clearCompletedAgentWalletPending(passphrase, expectedContext, pendingPath = exports.MCP_PENDING_AGENT_WALLET_PATH, finalPath = exports.MCP_AGENT_WALLET_IDENTITY_PATH) {
429
+ validateContext(expectedContext);
430
+ if (!hasPathEntry(pendingPath))
431
+ return;
432
+ const pending = decodedPending(readPrivateJson(pendingPath, 'Pending MCP wallet identity'), expectedContext, passphrase).file;
433
+ const final = parseFinalFile(readPrivateJson(finalPath, 'Completed MCP wallet identity'));
434
+ decodedPending(final.pending_identity, expectedContext, passphrase);
435
+ if (!(0, util_1.isDeepStrictEqual)(final.pending_identity, pending)) {
436
+ throw new Error('Pending MCP wallet identity conflicts with the completed identity');
437
+ }
438
+ unlinkDurably(pendingPath);
439
+ }
440
+ //# sourceMappingURL=agent-wallet-registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-wallet-registration.js","sourceRoot":"","sources":["../src/agent-wallet-registration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6XA,gGAsCC;AAKD,oFAYC;AAED,wFA0CC;AAED,4EAgBC;AAKD,4EAqBC;AA5gBD,mCAOgB;AAChB,uCAAyB;AACzB,2BAA6B;AAC7B,2CAA6B;AAC7B,+BAAyC;AAEzC,0CAIuB;AAUV,QAAA,6BAA6B,GAAG,IAAI,CAAC,IAAI,CACpD,IAAA,YAAO,GAAE,EAAE,UAAU,EAAE,+BAA+B,CACvD,CAAC;AACW,QAAA,8BAA8B,GAAG,IAAI,CAAC,IAAI,CACrD,IAAA,YAAO,GAAE,EAAE,UAAU,EAAE,4BAA4B,CACpD,CAAC;AA8CF,MAAM,YAAY,GAAG;IACnB,SAAS;IACT,UAAU;IACV,YAAY;IACZ,0BAA0B;IAC1B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Y,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,MAAM,KAAK,GAAG,cAAc,CAC1B,eAAe,CAAC,SAAS,EAAE,+BAA+B,CAAC,CAC5D,CAAC;IACF,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,gBAAgB,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;IACpF,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAC7B,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,SAAS;QACzB,GAAG,OAAO,CAAC,YAAY;KACxB,CAAC;AACJ,CAAC;AAED;;8EAE8E;AAC9E,SAAgB,gCAAgC,CAC9C,UAAkB,EAClB,eAA+C,EAC/C,cAAsB,qCAA6B,EACnD,YAAoB,sCAA8B;IAElD,eAAe,CAAC,eAAe,CAAC,CAAC;IACjC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC;QAAE,OAAO;IACvC,MAAM,OAAO,GAAG,cAAc,CAC5B,eAAe,CAAC,WAAW,EAAE,6BAA6B,CAAC,EAC3D,eAAe,EACf,UAAU,CACX,CAAC,IAAI,CAAC;IACP,MAAM,KAAK,GAAG,cAAc,CAC1B,eAAe,CAAC,SAAS,EAAE,+BAA+B,CAAC,CAC5D,CAAC;IACF,cAAc,CAAC,KAAK,CAAC,gBAAgB,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;IACpE,IAAI,CAAC,IAAA,wBAAiB,EAAC,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;IACD,aAAa,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * SIGNED CHALLENGES (`provian-challenge-v1`,) — the requester's half of burn-to-present, for
3
+ * the MCP tool core.
4
+ *
5
+ * SHARED CORE — canonical in `provian-mcp/src/core/`, mirrored byte-identically into
6
+ * `provian-backend/src/mcp/core/`. Edit only the canonical copy and run `scripts/sync-mcp-core.sh`.
7
+ *
8
+ * A byte-for-byte port of the relay's `core/presentation/challenge.ts` (signing string, predicate
9
+ * digest, parse, structural rules, Ed25519 verdict). The MCP core cannot import the relay or the
10
+ * SDK, so it carries its own audited copy, pinned by the fixed vectors in
11
+ * `challenge.test.ts` the same vectors every other package pins.
12
+ *
13
+ * A requester hands a presenter `{ v, audience, challenge, predicates?, issuedAt, expiresAt,
14
+ * presenter?, requester, sig }`. With `requester`/`sig` it is SIGNED (Ed25519): a domain requester
15
+ * with its own key published at `https://<domain>/.well-known/provian-requester.json`, a wallet
16
+ * requester by the RELAY with the Provian presentation key (`/v1/present/jwks`) after it
17
+ * authenticated that wallet. `audience === requester.id`, so the presentation's `aud` IS the
18
+ * verified requester. An unsigned legacy `{ audience, challenge, predicates? }` stays valid and is
19
+ * shown UNVERIFIED; a signed challenge failing any check is INVALID and refused (Unknown = Block).
20
+ *
21
+ * The one outbound fetch here (a domain requester's key document) is SSRF-guarded to the same bar
22
+ * as the relay (Security Invariant #6): hostname regex (no IP literals, no localhost), resolve and
23
+ * refuse ANY private address, pin the socket to the validated address (no DNS-rebinding TOCTOU),
24
+ * https only, no redirects, ≤ 64 KiB, ≤ 5 s. Node built-ins only, so the relay mirror compiles with
25
+ * nothing new.
26
+ */
27
+ import { requesterString, type PredicateRequest } from './presentation';
28
+ import { type CanonicalDisclosureRequest } from './disclosure-request';
29
+ export declare const CHALLENGE_SIGNING_TAG = "provian-challenge-v1";
30
+ export declare const CHALLENGE_ENVELOPE_VERSION: 1;
31
+ /** The requester key document path under the requester's domain. */
32
+ export declare const REQUESTER_WELL_KNOWN_PATH = "/.well-known/provian-requester.json";
33
+ /** Signed-challenge lifetime bounds (seconds): 60 s .. 7 days. */
34
+ export declare const CHALLENGE_MIN_TTL_SECONDS = 60;
35
+ export declare const CHALLENGE_MAX_TTL_SECONDS: number;
36
+ /** Local gates default to 15 minutes. */
37
+ export declare const CHALLENGE_DEFAULT_TTL_SECONDS = 900;
38
+ export declare const REQUESTER_KEYS_MAX_BYTES: number;
39
+ export declare const REQUESTER_KEYS_TIMEOUT_MS = 5000;
40
+ export declare const REQUESTER_KEYS_CACHE_MS: number;
41
+ export type RequesterType = 'domain' | 'wallet';
42
+ export interface RequesterIdentity {
43
+ readonly type: RequesterType;
44
+ readonly id: string;
45
+ /** wallet only. */
46
+ readonly address?: string;
47
+ }
48
+ export { requesterString };
49
+ export interface EnvelopeRequester {
50
+ readonly type: RequesterType;
51
+ /** domain: the hostname. wallet: the Provian wallet id. */
52
+ readonly id: string;
53
+ /** wallet only: the wallet's lowercase EVM address (Provian-attested). */
54
+ readonly address?: string;
55
+ /** The Ed25519 key id — the domain's well-known kid, or the Provian JWKS kid for a wallet. */
56
+ readonly kid: string;
57
+ }
58
+ export interface ChallengeEnvelope {
59
+ readonly v?: number;
60
+ readonly audience: string;
61
+ readonly challenge: string;
62
+ readonly predicates?: readonly PredicateRequest[];
63
+ /** Requester-named disclosure requests (2026-10-10). */
64
+ readonly disclosures?: readonly CanonicalDisclosureRequest[];
65
+ readonly issuedAt?: number;
66
+ readonly expiresAt?: number;
67
+ readonly presenter?: string;
68
+ readonly requester?: EnvelopeRequester;
69
+ readonly sig?: string;
70
+ }
71
+ /** One Ed25519 public key from a requester's well-known document (or the Provian JWKS). */
72
+ export interface RequesterJwk {
73
+ readonly kty: string;
74
+ readonly crv?: string;
75
+ readonly x?: string;
76
+ readonly kid: string;
77
+ }
78
+ /** Fetch a domain requester's published keys. Throws when unreachable / malformed. */
79
+ export type FetchRequesterKeys = (domain: string) => Promise<readonly RequesterJwk[]>;
80
+ /** The Provian presentation public keys, or a lazy loader for them (fetched only for a wallet requester). */
81
+ export type ProvianChallengeKeys = readonly RequesterJwk[] | (() => Promise<readonly RequesterJwk[]>);
82
+ export type ChallengeInvalidReason = 'malformed' | 'unsupported_version' | 'bad_requester' | 'audience_not_requester' | 'bad_window' | 'bad_presenter' | 'bad_signature' | 'key_not_found' | 'requester_key_unreachable';
83
+ export type ChallengeVerdict = {
84
+ readonly status: 'verified';
85
+ readonly requester: RequesterIdentity;
86
+ readonly envelope: ChallengeEnvelope;
87
+ } | {
88
+ readonly status: 'unverified';
89
+ readonly envelope: ChallengeEnvelope;
90
+ } | {
91
+ readonly status: 'invalid';
92
+ readonly reason: ChallengeInvalidReason;
93
+ readonly envelope?: ChallengeEnvelope;
94
+ } | {
95
+ readonly status: 'expired';
96
+ readonly requester: RequesterIdentity;
97
+ readonly envelope: ChallengeEnvelope;
98
+ } | {
99
+ readonly status: 'not_addressed';
100
+ readonly requester: RequesterIdentity;
101
+ readonly envelope: ChallengeEnvelope;
102
+ };
103
+ /** True when the envelope carries a requester signature (identity claim). */
104
+ export declare function isSignedChallenge(env: ChallengeEnvelope): boolean;
105
+ /**
106
+ * Parse an untrusted challenge envelope (object or JSON string). Structural only — no signature
107
+ * check. Returns null when it is not a well-formed challenge (legacy or signed).
108
+ */
109
+ export declare function parseChallengeEnvelope(raw: unknown): ChallengeEnvelope | null;
110
+ /** sha256 hex of the canonical (sorted, normalized) predicate list — the signing-string commitment. */
111
+ export declare function challengePredicatesDigest(predicates: readonly PredicateRequest[] | undefined): string;
112
+ /** The exact bytes a requester signs. Fixed line order, `\n`-joined, no trailing newline. */
113
+ export declare function challengeSigningString(env: {
114
+ audience: string;
115
+ challenge: string;
116
+ issuedAt: number;
117
+ expiresAt: number;
118
+ requester: {
119
+ type: RequesterType;
120
+ id: string;
121
+ address?: string;
122
+ kid: string;
123
+ };
124
+ presenter?: string;
125
+ predicates?: readonly PredicateRequest[];
126
+ disclosures?: readonly CanonicalDisclosureRequest[];
127
+ }): string;
128
+ /** Structural rules for a SIGNED envelope (A.2), excluding the signature itself. */
129
+ export declare function checkSignedStructure(env: ChallengeEnvelope): ChallengeInvalidReason | null;
130
+ /**
131
+ * Verify a challenge envelope the way a presenter surface must BEFORE burning (A.3). Unsigned →
132
+ * `unverified`; signed and every check passes → `verified` (or `expired` / `not_addressed` when
133
+ * the signature holds but the deadline passed / the challenge names another presenter); any
134
+ * failure → `invalid`. A domain requester needs `fetchRequesterKeys`; a wallet requester needs
135
+ * `provianKeys` (the Provian presentation JWKS, or a lazy loader for it).
136
+ */
137
+ export declare function verifyChallengeEnvelope(env: ChallengeEnvelope, opts?: {
138
+ fetchRequesterKeys?: FetchRequesterKeys;
139
+ provianKeys?: ProvianChallengeKeys;
140
+ nowSeconds?: number;
141
+ presenterAddress?: string;
142
+ }): Promise<ChallengeVerdict>;
143
+ /** Parse a well-known requester key document body (or a JWKS). Throws on a malformed document. */
144
+ export declare function parseRequesterKeyDocument(body: unknown): RequesterJwk[];
145
+ export interface RequesterVerdictView {
146
+ readonly status: ChallengeVerdict['status'];
147
+ /** The verified (or signature-verified but refused) identity; null for unsigned / invalid. */
148
+ readonly identity: RequesterIdentity | null;
149
+ /** invalid only: why. */
150
+ readonly reason?: ChallengeInvalidReason;
151
+ /** One line a presenter surface shows. */
152
+ readonly display: string;
153
+ }
154
+ export declare function describeVerdict(v: ChallengeVerdict): RequesterVerdictView;
155
+ /** A fresh unsigned (legacy) challenge in the wire shape. Presenters see it as UNVERIFIED. */
156
+ export declare function issueUnsignedChallenge(input: {
157
+ audience: string;
158
+ predicates?: readonly PredicateRequest[];
159
+ disclosures?: readonly CanonicalDisclosureRequest[];
160
+ ttlSeconds?: number;
161
+ presenter?: string;
162
+ nowSeconds?: number;
163
+ }): ChallengeEnvelope;
164
+ /**
165
+ * Private / internal / non-routable address predicate. Anything it cannot parse as a public IPv4 /
166
+ * IPv6 address is treated as private (fail-closed). A superset of the relay's `isPrivateIp`
167
+ * (adds CGNAT, multicast/reserved, IPv6 multicast, NAT64 / 6to4 which can embed a private v4).
168
+ */
169
+ export declare function isPrivateIp(ip: string): boolean;
170
+ /** A requester domain the guard will fetch from: the spec's hostname regex, never localhost. */
171
+ export declare function isAllowedRequesterDomain(domain: string): boolean;
172
+ export interface RequesterKeyFetchDeps {
173
+ /** Resolve a hostname to A + AAAA addresses (test seam). */
174
+ readonly resolveHostname?: (hostname: string) => Promise<string[]>;
175
+ /** Perform the pinned GET (test seam). Resolves the body, or null on any non-2xx / failure. */
176
+ readonly get?: (url: string, pinnedIp: string) => Promise<Buffer | null>;
177
+ readonly nowMs?: () => number;
178
+ }
179
+ /** Clear the per-domain key cache (tests / key rotation). */
180
+ export declare function clearRequesterKeyCache(): void;
181
+ /**
182
+ * Fetch a domain requester's Ed25519 keys, SSRF-guarded. Throws on any failure (the caller maps a
183
+ * throw to `requester_key_unreachable`, never to a verified identity). Cached 5 minutes per domain
184
+ * so one requester cannot turn a presenter surface into a request amplifier.
185
+ */
186
+ export declare function fetchRequesterKeysGuarded(domain: string, deps?: RequesterKeyFetchDeps): Promise<RequesterJwk[]>;
187
+ //# sourceMappingURL=challenge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../../src/core/challenge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH,OAAO,EAOL,eAAe,EACf,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAA2D,KAAK,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEhI,eAAO,MAAM,qBAAqB,yBAAyB,CAAC;AAC5D,eAAO,MAAM,0BAA0B,EAAG,CAAU,CAAC;AACrD,oEAAoE;AACpE,eAAO,MAAM,yBAAyB,wCAAwC,CAAC;AAC/E,kEAAkE;AAClE,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,eAAO,MAAM,yBAAyB,QAAgB,CAAC;AACvD,yCAAyC;AACzC,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAEjD,eAAO,MAAM,wBAAwB,QAAY,CAAC;AAClD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,uBAAuB,QAAgB,CAAC;AASrD,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAA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