@haven_ai/signer 0.8.0-alpha.0 → 0.9.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -196,6 +196,10 @@ function createEdgeSigner(delegateKey, options = {}) {
196
196
  );
197
197
  }
198
198
  return { signature };
199
+ },
200
+ async signSiwxMessage(message) {
201
+ const account = accounts.privateKeyToAccount(delegateKey);
202
+ return account.signMessage({ message });
199
203
  }
200
204
  };
201
205
  }
@@ -912,7 +916,13 @@ function signerCompatibility() {
912
916
  function signerCapabilityAdvertisement() {
913
917
  return { experimental: { [SIGNER_CAPABILITY_KEY]: signerCompatibility() } };
914
918
  }
915
- function signerInstructions() {
919
+ function signerIdentityLines(identity) {
920
+ if (!identity?.agentId && !identity?.delegateAddress) return [];
921
+ const agent = identity.agentId ? `agent id ${identity.agentId}` : "no recorded agent id";
922
+ const delegate = identity.delegateAddress ? ` and delegate address ${identity.delegateAddress}` : "";
923
+ return [`This signer is bound to ${agent}${delegate}.`];
924
+ }
925
+ function signerInstructions(identity) {
916
926
  const compatibility = signerCompatibility();
917
927
  return [
918
928
  "Haven edge signer: sign-only tools bound to the local delegate key. It never emits the",
@@ -921,6 +931,16 @@ function signerInstructions() {
921
931
  "#3271, and delegation-rail x402) or haven_sign_x402 (x402 only) instead of relaying bulky",
922
932
  "typed-data payloads yourself.",
923
933
  "",
934
+ ...signerIdentityLines(identity),
935
+ "When more than one Haven pair is configured, you act as ONE agent per task: if the",
936
+ "user has not said which (in the request, or a project-level choice they stated), ask",
937
+ "before any payment tool. Sign only through the signer of the hosted server you called:",
938
+ "haven-<slug> with haven-signer-<slug>, bare haven with haven-signer, Codex haven with",
939
+ "haven_signer. Before signing, compare the identity this signer states with",
940
+ "haven_get_agent (its id and delegateAddress) from that hosted server \u2014 the delegate",
941
+ "address alone when this signer has no recorded agent id. If they differ, stop and sign",
942
+ "nothing \u2014 switch to the signer whose identity matches.",
943
+ "",
924
944
  "Version compatibility (check this BEFORE signing, not after):",
925
945
  `- x402 expected-context versions supported: ${compatibility.x402_expected_context_versions.join(", ")}`,
926
946
  `- sweep authorization binding versions supported: ${compatibility.sweep_binding_versions.join(", ")}`,
@@ -939,14 +959,22 @@ function signerInstructions() {
939
959
  "machine-readable, not just prose: it carries code, supported_versions, received_version, and",
940
960
  "fallback fields alongside the message, so you can branch on it directly. Every signer",
941
961
  "refusal also carries the next-step family: next_tool_name + next_tool_server_role when a",
942
- "hosted tool follows (resolve the role against your own server names), else",
962
+ "hosted tool follows (resolve the role against your own server names \u2014 with several",
963
+ "Haven pairs, the hosted server of THIS signer's pair), else",
943
964
  "next_tool_omitted_reason saying why not.",
944
965
  "",
945
966
  "An undeclared top-level argument is refused, not stripped: haven_sign answers",
946
967
  "UNSUPPORTED_ARGUMENT with unknown_arguments, signer_version and fallback (the update",
947
968
  "command) instead of dropping the key and answering the generic signing error \u2014 if you see",
948
969
  "that refusal, this signer predates the argument form you sent. Update the signer; nothing",
949
- "was signed, fetched or audited."
970
+ "was signed, fetched or audited.",
971
+ "",
972
+ "Sign-In-With-X (#3728): when a merchant 402 carries a sign-in-with-x extension (or the",
973
+ "merchant documents a CAIP-122 sign-in route), call haven_sign_siwx with { url, challenge }.",
974
+ "The signer composes the EIP-4361 message itself from the validated challenge and signs it with",
975
+ "the delegate key \u2014 it returns { sign_in_with_x_header }; retry the merchant with the",
976
+ "SIGN-IN-WITH-X header set to that value. This proves the delegate wallet paid the merchant; it",
977
+ "moves no funds and cannot approve any payment."
950
978
  ].join("\n");
951
979
  }
952
980
  var OWNER_ONLY_MODE = 384;
@@ -1132,6 +1160,8 @@ function createSigningAuditEntry(tool, payloadHash, context, now = /* @__PURE__
1132
1160
  };
1133
1161
  if (context.accountAddress) entry.safe_address = context.accountAddress;
1134
1162
  if (typeof context.chainId === "number") entry.chain_id = context.chainId;
1163
+ if (context.domain !== void 0) entry.domain = context.domain;
1164
+ if (context.nonce !== void 0) entry.nonce = context.nonce;
1135
1165
  return entry;
1136
1166
  }
1137
1167
  function hashPayloadForAudit(payload) {
@@ -1163,10 +1193,237 @@ var HavenBareHashRefusedError = class extends edge.HavenSigningError {
1163
1193
  });
1164
1194
  }
1165
1195
  };
1196
+ var SIWX_REFUSED = "SIWX_REFUSED";
1197
+ var HavenSiwxRefusedError = class extends edge.HavenSigningError {
1198
+ next_action = edge.AgentPaymentNextAction.StopAndTellUser;
1199
+ step;
1200
+ constructor(message) {
1201
+ super(message);
1202
+ this.code = SIWX_REFUSED;
1203
+ this.name = "HavenSiwxRefusedError";
1204
+ this.step = signerRefusalStep({
1205
+ nextAction: edge.AgentPaymentNextAction.StopAndTellUser,
1206
+ nextTool: null,
1207
+ nextToolOmittedReason: "check the 402 sign-in-with-x challenge and the URL against the refusal above, then call haven_sign_siwx again with corrected inputs \u2014 a challenge that fails validation is never signed"
1208
+ });
1209
+ }
1210
+ };
1211
+ var SIWX_MAX_AGE_SECONDS = 300;
1212
+ var SIWX_CLOCK_SKEW_SECONDS = 30;
1213
+ var SIWX_VERSION = "1";
1214
+ function refuse(message) {
1215
+ throw new HavenSiwxRefusedError(message);
1216
+ }
1217
+ function isPlainObject(value) {
1218
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1219
+ }
1220
+ function stringField2(info, name) {
1221
+ const value = info[name];
1222
+ if (value === void 0) return void 0;
1223
+ if (typeof value !== "string") {
1224
+ refuse(`The sign-in-with-x challenge field "${name}" must be a string.`);
1225
+ }
1226
+ return value;
1227
+ }
1228
+ function assertSingleLine(value, name) {
1229
+ if (/[\n\r]/.test(value)) {
1230
+ refuse(`The sign-in-with-x challenge field "${name}" contains a line break; EIP-4361 fields are single-line. Refusing \u2014 a line break could smuggle an attacker-chosen line into the signed message.`);
1231
+ }
1232
+ }
1233
+ function validateSiwxChallenge(input) {
1234
+ const { url, challenge, chainId } = input;
1235
+ const now = input.now ?? /* @__PURE__ */ new Date();
1236
+ if (typeof url !== "string" || url.length === 0) {
1237
+ refuse("url is required: the URL the agent is calling, so the signature is bound to that origin.");
1238
+ }
1239
+ let urlObj;
1240
+ try {
1241
+ urlObj = new URL(url);
1242
+ } catch {
1243
+ refuse("url is not a valid absolute URL.");
1244
+ }
1245
+ if (urlObj.protocol !== "https:") {
1246
+ refuse(
1247
+ `url must be https \u2014 this signer never signs a sign-in bound to a plain-HTTP origin (got '${urlObj.protocol}//').`
1248
+ );
1249
+ }
1250
+ if (!isPlainObject(challenge)) {
1251
+ refuse('challenge must be the sign-in-with-x object from the merchant 402 (extensions["sign-in-with-x"]).');
1252
+ }
1253
+ const hasWrapper = isPlainObject(challenge.info);
1254
+ const info = hasWrapper ? challenge.info : challenge;
1255
+ const supportedChains = hasWrapper ? challenge.supportedChains : challenge.supportedChains;
1256
+ const domain = stringField2(info, "domain");
1257
+ if (domain === void 0) refuse("The sign-in-with-x challenge carries no domain.");
1258
+ assertSingleLine(domain, "domain");
1259
+ if (/\s/.test(domain)) {
1260
+ refuse("The sign-in-with-x challenge domain is not a valid authority (contains whitespace).");
1261
+ }
1262
+ if (domain.toLowerCase() !== urlObj.host.toLowerCase()) {
1263
+ refuse(
1264
+ `The challenge domain '${domain}' does not match the host of the URL being called ('${urlObj.host}'). A sign-in is only valid for the origin that issued it.`
1265
+ );
1266
+ }
1267
+ const uri = stringField2(info, "uri");
1268
+ if (uri === void 0) refuse("The sign-in-with-x challenge carries no uri.");
1269
+ assertSingleLine(uri, "uri");
1270
+ let uriObj;
1271
+ try {
1272
+ uriObj = new URL(uri);
1273
+ } catch {
1274
+ refuse("The sign-in-with-x challenge uri is not a valid absolute URI.");
1275
+ }
1276
+ if (uriObj.protocol !== urlObj.protocol || uriObj.host.toLowerCase() !== urlObj.host.toLowerCase()) {
1277
+ refuse(
1278
+ `The challenge resource uri origin ('${uriObj.protocol}//${uriObj.host}') does not match the origin of the URL being called ('${urlObj.protocol}//${urlObj.host}').`
1279
+ );
1280
+ }
1281
+ const version = stringField2(info, "version");
1282
+ if (version === void 0) {
1283
+ refuse("The sign-in-with-x challenge carries no version; this signer composes CAIP-122 version 1 only.");
1284
+ }
1285
+ if (version !== SIWX_VERSION) {
1286
+ refuse(
1287
+ `The sign-in-with-x challenge version is '${version}'; this signer composes version '${SIWX_VERSION}' only. Update @haven_ai/signer if the spec has moved on.`
1288
+ );
1289
+ }
1290
+ const nonce = stringField2(info, "nonce");
1291
+ if (nonce === void 0) {
1292
+ refuse("The sign-in-with-x challenge carries no nonce \u2014 refusing: the nonce is what makes the sign-in single-use.");
1293
+ }
1294
+ if (!/^[A-Za-z0-9]{8,}$/.test(nonce)) {
1295
+ refuse("The sign-in-with-x challenge nonce fails the EIP-4361 grammar (alphanumeric, at least 8 characters).");
1296
+ }
1297
+ const issuedAt = stringField2(info, "issuedAt");
1298
+ if (issuedAt === void 0) refuse("The sign-in-with-x challenge carries no issuedAt timestamp.");
1299
+ assertSingleLine(issuedAt, "issuedAt");
1300
+ if (Number.isNaN(Date.parse(issuedAt))) {
1301
+ refuse("The sign-in-with-x challenge issuedAt is not a parseable timestamp.");
1302
+ }
1303
+ const expirationTime = stringField2(info, "expirationTime");
1304
+ if (expirationTime === void 0) {
1305
+ refuse(
1306
+ "The sign-in-with-x challenge carries no absolute expirationTime. A relative expirationSeconds is not accepted by this signer \u2014 only a challenge with an absolute expiry window the signer can bound is signed."
1307
+ );
1308
+ }
1309
+ assertSingleLine(expirationTime, "expirationTime");
1310
+ const expiresAtMs = Date.parse(expirationTime);
1311
+ if (Number.isNaN(expiresAtMs)) {
1312
+ refuse("The sign-in-with-x challenge expirationTime is not a parseable timestamp.");
1313
+ }
1314
+ if (expiresAtMs < now.getTime() - SIWX_CLOCK_SKEW_SECONDS * 1e3) {
1315
+ refuse("The sign-in-with-x challenge has already expired (expirationTime is in the past, beyond the clock-skew tolerance). Nothing was signed.");
1316
+ }
1317
+ if (expiresAtMs - now.getTime() > (SIWX_MAX_AGE_SECONDS + SIWX_CLOCK_SKEW_SECONDS) * 1e3) {
1318
+ refuse(
1319
+ `The sign-in-with-x challenge expiry window is longer than the spec's ${SIWX_MAX_AGE_SECONDS}-second max age (beyond the clock-skew tolerance). Refusing to sign a long-lived challenge.`
1320
+ );
1321
+ }
1322
+ const statement = stringField2(info, "statement");
1323
+ if (statement !== void 0) assertSingleLine(statement, "statement");
1324
+ const notBefore = stringField2(info, "notBefore");
1325
+ if (notBefore !== void 0) {
1326
+ assertSingleLine(notBefore, "notBefore");
1327
+ if (Number.isNaN(Date.parse(notBefore))) {
1328
+ refuse("The sign-in-with-x challenge notBefore is not a parseable timestamp.");
1329
+ }
1330
+ }
1331
+ const requestId = stringField2(info, "requestId");
1332
+ if (requestId !== void 0) assertSingleLine(requestId, "requestId");
1333
+ let resources;
1334
+ if (info.resources !== void 0) {
1335
+ if (!Array.isArray(info.resources) || info.resources.some((r) => typeof r !== "string")) {
1336
+ refuse("The sign-in-with-x challenge resources must be an array of URI strings.");
1337
+ }
1338
+ for (const resource of info.resources) {
1339
+ assertSingleLine(resource, "resources[]");
1340
+ try {
1341
+ new URL(resource);
1342
+ } catch {
1343
+ refuse(`The sign-in-with-x challenge resources entry '${resource}' is not a valid absolute URI.`);
1344
+ }
1345
+ }
1346
+ resources = info.resources;
1347
+ }
1348
+ if (typeof chainId !== "number" || !Number.isInteger(chainId) || chainId <= 0) {
1349
+ refuse(
1350
+ "This signer credential carries no chain id, so the signer cannot check the challenge against the chain its delegate key pays on. Re-run the connector to refresh the credential."
1351
+ );
1352
+ }
1353
+ const chainIdCaip2 = `eip155:${chainId}`;
1354
+ if (!Array.isArray(supportedChains) || supportedChains.length === 0) {
1355
+ refuse("The sign-in-with-x challenge carries no supportedChains array.");
1356
+ }
1357
+ const matched = supportedChains.some(
1358
+ (entry) => isPlainObject(entry) && typeof entry.chainId === "string" && entry.chainId.toLowerCase() === chainIdCaip2 && entry.type === "eip191"
1359
+ );
1360
+ if (!matched) {
1361
+ refuse(
1362
+ `The challenge's supportedChains does not offer the credential chain ${chainIdCaip2} with an eip191 signature type \u2014 the delegate EOA cannot answer this challenge.`
1363
+ );
1364
+ }
1365
+ return {
1366
+ domain,
1367
+ uri,
1368
+ version,
1369
+ nonce,
1370
+ issuedAt,
1371
+ expirationTime,
1372
+ statement,
1373
+ notBefore,
1374
+ requestId,
1375
+ resources,
1376
+ chainIdCaip2,
1377
+ numericChainId: chainId
1378
+ };
1379
+ }
1380
+ function composeSiwxMessage(fields, address) {
1381
+ const suffixLines = [
1382
+ `URI: ${fields.uri}`,
1383
+ `Version: ${fields.version ?? SIWX_VERSION}`,
1384
+ `Chain ID: ${fields.numericChainId}`,
1385
+ `Nonce: ${fields.nonce}`,
1386
+ `Issued At: ${fields.issuedAt}`
1387
+ ];
1388
+ if (fields.expirationTime !== void 0) suffixLines.push(`Expiration Time: ${fields.expirationTime}`);
1389
+ if (fields.notBefore !== void 0) suffixLines.push(`Not Before: ${fields.notBefore}`);
1390
+ if (fields.requestId !== void 0) suffixLines.push(`Request ID: ${fields.requestId}`);
1391
+ if (fields.resources !== void 0) {
1392
+ suffixLines.push(["Resources:", ...fields.resources.map((r) => `- ${r}`)].join("\n"));
1393
+ }
1394
+ let head = [`${fields.domain} wants you to sign in with your Ethereum account:`, address].join("\n");
1395
+ if (fields.statement === void 0) {
1396
+ head += "\n\n";
1397
+ } else {
1398
+ head = [head, fields.statement].join("\n\n") + "\n";
1399
+ }
1400
+ return [head, suffixLines.join("\n")].join("\n");
1401
+ }
1402
+ function buildSiwxPayload(fields, address, signature) {
1403
+ return {
1404
+ domain: fields.domain,
1405
+ address,
1406
+ statement: fields.statement,
1407
+ uri: fields.uri,
1408
+ version: fields.version ?? SIWX_VERSION,
1409
+ chainId: fields.chainIdCaip2,
1410
+ type: "eip191",
1411
+ nonce: fields.nonce,
1412
+ issuedAt: fields.issuedAt,
1413
+ expirationTime: fields.expirationTime,
1414
+ notBefore: fields.notBefore,
1415
+ requestId: fields.requestId,
1416
+ resources: fields.resources,
1417
+ signature
1418
+ };
1419
+ }
1420
+ function encodeSiwxHeader(payload) {
1421
+ return Buffer.from(JSON.stringify(payload), "utf8").toString("base64");
1422
+ }
1166
1423
 
1167
1424
  // src/tools.ts
1168
1425
  var SIGNER_NAME = "@haven_ai/signer";
1169
- var SIGNER_VERSION = "0.8.0-alpha.0";
1426
+ var SIGNER_VERSION = "0.9.0-alpha.0";
1170
1427
  var UNSUPPORTED_ARGUMENT_MARKER = "HavenSignerUnsupportedArgument:";
1171
1428
  var USEROP_BINDING_MISMATCH = "USEROP_BINDING_MISMATCH";
1172
1429
  var HavenUserOpBindingRefusedError = class extends edge.HavenSigningError {
@@ -1329,6 +1586,18 @@ var toolSchemas = {
1329
1586
  typed_data: v3.z.record(v3.z.string(), v3.z.unknown()).optional(),
1330
1587
  // #1255: see haven_sign.typed_data_b64 — the copy-through-safe form.
1331
1588
  typed_data_b64: v3.z.string().min(1).max(262144).optional()
1589
+ },
1590
+ haven_sign_siwx: {
1591
+ // #3728: the https URL the agent is calling — the challenge's domain and
1592
+ // resource uri are pinned to THIS origin before anything is signed.
1593
+ url: v3.z.string().min(1),
1594
+ // The merchant's sign-in-with-x challenge. Accepted as EITHER the 402
1595
+ // extension object (payment_required.extensions['sign-in-with-x'] —
1596
+ // { info, supportedChains, schema? }) or the flattened info object the
1597
+ // x402 reference client builds ({ ...info, chainId, type }). Validated
1598
+ // field by field in siwx.ts; the signer composes the EIP-4361 message
1599
+ // itself and never signs a caller-supplied message.
1600
+ challenge: v3.z.record(v3.z.string(), v3.z.unknown())
1332
1601
  }
1333
1602
  // #3101: keys survive on the type (see the hosted server's contracts.ts).
1334
1603
  };
@@ -1367,8 +1636,10 @@ var X402_SIGN_HEADER_DESCRIPTION = [
1367
1636
  "do not call this tool. The signer validates the merchant, amount, resource, asset, and",
1368
1637
  "network against the recorded funding context before signing, checks expires_at when present,",
1369
1638
  "and rejects mismatches or expired payment windows.",
1370
- "Returns { payment_header, accepted }. On your retry set BOTH PAYMENT-SIGNATURE (x402 v2) and",
1371
- "X-PAYMENT (v1) to <payment_header>; a strict v2 merchant reads only the first.",
1639
+ "Returns { payment_header, retry_headers, accepted }. On your retry set EVERY header named in",
1640
+ "retry_headers to <payment_header> \u2014 the names come from the same rule the wire uses (both",
1641
+ "PAYMENT-SIGNATURE (x402 v2) and X-PAYMENT (v1) on the EIP-3009 bridge; a strict v2 merchant reads",
1642
+ "only the first).",
1372
1643
  "Only call after haven_submit has confirmed the funding step (nextAction=none or",
1373
1644
  "the funding tx has a confirmed status). Next for paid MCP tools: call mcp__haven__haven_complete_mcp_tool."
1374
1645
  ].join(" ");
@@ -1394,8 +1665,8 @@ var SIGN_X402_DESCRIPTION = [
1394
1665
  "haven_sign, not to this one. payment_header IS the header to use.",
1395
1666
  "Next: for a paid MCP tool, call mcp__haven__haven_settle_mcp_tool. For a direct plain-HTTP x402",
1396
1667
  "merchant (the haven_pay_x402_quote path), relay signature via mcp__haven__haven_submit and then",
1397
- "retry the original merchant URL YOURSELF, setting BOTH PAYMENT-SIGNATURE (x402 v2) and",
1398
- "X-PAYMENT (v1) to payment_header \u2014 Haven never contacts that merchant."
1668
+ "retry the original merchant URL YOURSELF, setting EVERY header the result names in",
1669
+ "retry_headers to payment_header \u2014 Haven never sends that merchant the paid request."
1399
1670
  ].join(" ");
1400
1671
  var SIGN_SWEEP_DELEGATE_DESCRIPTION = [
1401
1672
  "Sign a Haven-prepared gasless USDC sweep that recovers stranded funds from the delegate",
@@ -1407,8 +1678,28 @@ var SIGN_SWEEP_DELEGATE_DESCRIPTION = [
1407
1678
  "when the credential carries one, and otherwise rests on Haven's binding signature. Then it",
1408
1679
  "returns { signature } to hand back to mcp__haven__haven_sweep_delegate to complete recovery."
1409
1680
  ].join(" ");
1681
+ var SIGN_SIWX_DESCRIPTION = [
1682
+ "Answer a merchant x402 Sign-In-With-X (SIWX) sign-in challenge with the local delegate key (#3728).",
1683
+ "Use it when a merchant 402 carries a sign-in-with-x extension, or when the merchant documents a",
1684
+ "sign-in route (CAIP-122): pass url \u2014 the FINAL URL the header will be sent to, i.e. after any",
1685
+ "redirects, not the originally requested one \u2014 and challenge, the sign-in-with-x object from the",
1686
+ "402 (extensions['sign-in-with-x'], or the flattened info object). NEVER follow a redirect with",
1687
+ "the SIGN-IN-WITH-X header (or a resulting session token) attached: re-sign for the final origin.",
1688
+ "This signer composes the EIP-4361 message ITSELF from the validated challenge fields and the",
1689
+ "delegate address read from the key \u2014 it never signs a caller-supplied message, and an address",
1690
+ "inside the challenge cannot change whose wallet signs in. It refuses (SIWX_REFUSED) unless the",
1691
+ "challenge domain matches the URL host, its resource uri origin matches the URL origin, the URL is",
1692
+ "https, the nonce is well-formed, the expiry window is at most 5 minutes (plus a small clock-skew",
1693
+ "tolerance), and supportedChains offers the credential chain with an eip191 signature type. This",
1694
+ "tool MOVES NO FUNDS and grants no spend authority: it only proves the delegate wallet is the one",
1695
+ "that paid the merchant. Returns { sign_in_with_x_header } \u2014 retry the merchant request with the",
1696
+ "SIGN-IN-WITH-X header set to that value. The merchant then recognises the delegate wallet as a",
1697
+ "paying customer (a session it mints typically outlives the 5-minute signature; what the session",
1698
+ "reaches is merchant-defined)."
1699
+ ].join(" ");
1410
1700
  var toolDescriptions = {
1411
1701
  haven_sign: SIGN_DESCRIPTION,
1702
+ haven_sign_siwx: SIGN_SIWX_DESCRIPTION,
1412
1703
  haven_x402_sign_header: X402_SIGN_HEADER_DESCRIPTION,
1413
1704
  haven_sign_x402: SIGN_X402_DESCRIPTION,
1414
1705
  haven_sign_sweep_delegate: SIGN_SWEEP_DELEGATE_DESCRIPTION
@@ -1736,7 +2027,13 @@ function createToolHandlers(signer, options = {}) {
1736
2027
  "haven_x402_sign_header",
1737
2028
  hashPayloadForAudit(args.payment_required)
1738
2029
  );
1739
- return { payment_header: result.paymentHeader, accepted: result.accepted };
2030
+ return {
2031
+ payment_header: result.paymentHeader,
2032
+ accepted: result.accepted,
2033
+ // #3727: the ready-made retry headers beside the prose — the names
2034
+ // come from the SDK's live rule, never re-derived here.
2035
+ retry_headers: edge.x402RetryHeadersFor(result.paymentHeader)
2036
+ };
1740
2037
  }),
1741
2038
  haven_sign_x402: async (input) => runTool(async () => {
1742
2039
  const args = parseStrictFor("haven_sign_x402", coerceX402Expected(coercePaymentRequired(input)));
@@ -1771,6 +2068,9 @@ function createToolHandlers(signer, options = {}) {
1771
2068
  x402_binding: funding.x402Binding,
1772
2069
  payment_header: header.paymentHeader,
1773
2070
  accepted: header.accepted,
2071
+ // #3727: the ready-made retry headers beside the prose — the names
2072
+ // come from the SDK's live rule, never re-derived here.
2073
+ retry_headers: edge.x402RetryHeadersFor(header.paymentHeader),
1774
2074
  ...clientUpdateField(resolved)
1775
2075
  };
1776
2076
  }),
@@ -1788,15 +2088,35 @@ function createToolHandlers(signer, options = {}) {
1788
2088
  hashPayloadForAudit(args.authorization)
1789
2089
  );
1790
2090
  return { signature: result.signature };
2091
+ }),
2092
+ haven_sign_siwx: async (input) => runTool(async () => {
2093
+ const args = parseStrictFor("haven_sign_siwx", input);
2094
+ const chainId = options.audit?.chainId;
2095
+ const fields = validateSiwxChallenge({
2096
+ url: args.url,
2097
+ challenge: args.challenge,
2098
+ chainId
2099
+ });
2100
+ const message = composeSiwxMessage(fields, signer.delegateAddress);
2101
+ const signature = await signer.signSiwxMessage(message);
2102
+ const header = encodeSiwxHeader(
2103
+ buildSiwxPayload(fields, signer.delegateAddress, signature)
2104
+ );
2105
+ await auditSigning("haven_sign_siwx", hashPayloadForAudit(message), {
2106
+ domain: fields.domain,
2107
+ nonce: fields.nonce
2108
+ });
2109
+ return { sign_in_with_x_header: header };
1791
2110
  })
1792
2111
  };
1793
- async function auditSigning(tool, payloadHash) {
2112
+ async function auditSigning(tool, payloadHash, extra = {}) {
1794
2113
  if (!options.audit) return;
1795
2114
  const { auditPath, ...context } = options.audit;
1796
2115
  try {
1797
2116
  await appendSigningAuditEntry(
1798
2117
  createSigningAuditEntry(tool, payloadHash, {
1799
2118
  ...context,
2119
+ ...extra,
1800
2120
  delegateAddress: signer.delegateAddress
1801
2121
  }),
1802
2122
  auditPath
@@ -1951,6 +2271,15 @@ function normalizeError(err) {
1951
2271
  ...err.next_tool_omitted_reason ? { next_tool_omitted_reason: err.next_tool_omitted_reason } : {}
1952
2272
  };
1953
2273
  }
2274
+ if (err instanceof HavenSiwxRefusedError) {
2275
+ return {
2276
+ success: false,
2277
+ code: err.code,
2278
+ message: err.message,
2279
+ next_action: err.next_action,
2280
+ ...nextStepWireFields(err.step)
2281
+ };
2282
+ }
1954
2283
  if (err instanceof edge.HavenSigningError) {
1955
2284
  return { success: false, code: err.code, message: err.message };
1956
2285
  }
@@ -1987,6 +2316,7 @@ function normalizeError(err) {
1987
2316
  // src/consent.ts
1988
2317
  var toolSummaries = {
1989
2318
  haven_sign: "signs a Haven-prepared payment, task-budget or sub-budget open or close (a UserOp from your own account redeeming a delegation made to it, directly or via a task-budget child; a sub-budget child narrowing your budget for another agent of yours; or an x402 funding intent against a Haven-signed context)",
2319
+ haven_sign_siwx: "signs a merchant x402 Sign-In-With-X sign-in challenge as the delegate wallet \u2014 proves the wallet paid that merchant, moves no funds and grants no spend authority",
1990
2320
  haven_x402_sign_header: "builds and signs the EIP-3009 merchant payment header for an x402 payment",
1991
2321
  haven_sign_x402: "the two above in one call: funding payload + merchant header",
1992
2322
  haven_sign_sweep_delegate: "signs a Haven-prepared gasless sweep of stranded funds back to your own account"
@@ -2026,13 +2356,16 @@ function renderSignerConsentBlock(input, hash) {
2026
2356
  if (input.network) lines.push(`Network: ${input.network}`);
2027
2357
  lines.push("");
2028
2358
  lines.push("This local signer holds the delegate key on this machine and signs");
2029
- lines.push("payment payloads or x402 merchant headers for the delegate address above.");
2359
+ lines.push("payment payloads, x402 merchant headers, or x402 Sign-In-With-X sign-in");
2360
+ lines.push("challenges for the delegate address above. A sign-in challenge proves to a");
2361
+ lines.push("merchant that this wallet paid it before; it moves no funds and grants no");
2362
+ lines.push("spend authority.");
2030
2363
  lines.push("Its one network use is a read-only fetch of a pending payment's signing");
2031
2364
  lines.push("payload from Haven, authenticated with the agent credential stored next to");
2032
2365
  lines.push("this signer's key file - it never sends the key, a signature, or anything");
2033
2366
  lines.push("else outbound, and it cannot show a live allowance summary.");
2034
2367
  lines.push("The agent's signed budget delegation is the real spend gate, and the wallet");
2035
- lines.push("owner can pause or revoke agent authority outside this signer.");
2368
+ lines.push("owner can stop the agent's budget or remove the agent outside this signer.");
2036
2369
  lines.push("");
2037
2370
  lines.push("Tools this signer will expose to your agent runtime (one line each; the");
2038
2371
  lines.push("full agent-facing descriptions are what the runtime sees):");
@@ -2042,7 +2375,7 @@ function renderSignerConsentBlock(input, hash) {
2042
2375
  lines.push("");
2043
2376
  lines.push("A local audit entry is appended for every signing operation. Audit entries");
2044
2377
  lines.push("record timestamp, tool, payload hash, and delegate address; never the key,");
2045
- lines.push("signature, or x402 payment header.");
2378
+ lines.push("signature, x402 payment header, or sign-in message.");
2046
2379
  lines.push("");
2047
2380
  lines.push(`Consent hash: ${hash}`);
2048
2381
  lines.push("");
@@ -2145,7 +2478,12 @@ function buildSignerMcpServer(signer, options = {}) {
2145
2478
  { name: SIGNER_NAME, version: SIGNER_VERSION },
2146
2479
  {
2147
2480
  capabilities: signerCapabilityAdvertisement(),
2148
- instructions: signerInstructions()
2481
+ // #3738: the identity line lets a model holding several Haven pairs
2482
+ // confirm this signer belongs to the hosted server it called.
2483
+ instructions: signerInstructions({
2484
+ agentId: options.credentials?.agentId,
2485
+ delegateAddress: signer.delegateAddress
2486
+ })
2149
2487
  }
2150
2488
  );
2151
2489
  const credentialsPath = options.credentials?.sourcePath;