@haven_ai/signer 0.1.22-alpha.0 → 0.1.23-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/cli.cjs CHANGED
@@ -393,11 +393,13 @@ async function fetchX402SignContext(identity, paymentId, fetchImpl = fetch) {
393
393
  "The Haven sign-context response is missing sign_data.typed_data or x402_expected \u2014 the backend may predate #1263. Pass typed_data_b64 from the quote result instead."
394
394
  );
395
395
  }
396
+ const paymentRequired = body.payment_required;
396
397
  return {
397
398
  paymentId: String(body.payment_id ?? paymentId),
398
399
  payloadHash: signData.hash,
399
400
  typedData: signData.typed_data,
400
- x402Expected
401
+ x402Expected,
402
+ paymentRequired: paymentRequired && typeof paymentRequired === "object" && !Array.isArray(paymentRequired) ? paymentRequired : null
401
403
  };
402
404
  }
403
405
 
@@ -496,7 +498,11 @@ var toolSchemas = {
496
498
  // Both optional when payment_id is supplied (the fetch carries them).
497
499
  payload_hash: v3.z.string().regex(/^0x[0-9a-fA-F]+$/, "payload_hash must be a 0x-prefixed hex string").optional(),
498
500
  x402_expected: x402ExpectedSchema.optional(),
499
- payment_required: v3.z.record(v3.z.string(), v3.z.unknown()),
501
+ // #1355: optional when payment_id is supplied — the signer's context fetch
502
+ // carries the stored 402 PaymentRequired, so `{ payment_id }` alone is the
503
+ // preferred call. Still required (via the runtime check in the handler)
504
+ // for the quote-based fallback path without a payment_id.
505
+ payment_required: v3.z.record(v3.z.string(), v3.z.unknown()).optional(),
500
506
  // #1138: delegation-rail intents sign THIS, not payload_hash. Object-typed
501
507
  // (not z.unknown()) so MCP clients embed it as JSON rather than a string.
502
508
  typed_data: v3.z.record(v3.z.string(), v3.z.unknown()).optional(),
@@ -532,8 +538,10 @@ var SIGN_X402_DESCRIPTION = [
532
538
  "One-shot x402 signing for the fast 3-call flow: sign the funding hash AND build the EIP-3009",
533
539
  "X-PAYMENT header in a single local call (equivalent to haven_sign followed by",
534
540
  "haven_x402_sign_header). The delegate key never leaves this process. From the haven_pay_mcp_tool",
535
- "result pass payment_id and payment_required \u2014 PREFERRED (#1263): this signer fetches the exact",
536
- "signing payload and expected context from Haven itself, so nothing bulky crosses your context.",
541
+ "result pass JUST payment_id \u2014 PREFERRED (#1263, #1355): this signer fetches the exact signing",
542
+ "payload, expected context, and merchant payment_required from Haven itself, so nothing bulky",
543
+ "crosses your context. If the signer reports the context carried no payment_required (older",
544
+ "backend), re-call with payment_id plus payment_required verbatim from the pay result.",
537
545
  "Fallback for older backends: pass payload_hash, x402_expected (the nested x402.expected object \u2014",
538
546
  "passing the whole x402 object is also accepted and unwrapped for you), and typed_data_b64",
539
547
  "through UNCHANGED; the signer",
@@ -686,12 +694,18 @@ function createToolHandlers(signer, options = {}) {
686
694
  payloadHash,
687
695
  fetched?.typedData ?? resolveTypedData(args)
688
696
  );
697
+ const paymentRequired = fetched?.paymentRequired ?? args.payment_required;
698
+ if (!paymentRequired) {
699
+ throw new sdk.HavenSigningError(
700
+ fetched ? "The Haven sign-context for this payment_id carried no payment_required (backend predates #1355). Pass payment_required from the pay result explicitly, verbatim." : "payment_required is required on the quote-based path (no payment_id to fetch it by). Pass it verbatim from the quote result."
701
+ );
702
+ }
689
703
  const header = await signer.buildX402PaymentHeader(
690
- args.payment_required,
704
+ paymentRequired,
691
705
  funding.x402Binding
692
706
  );
693
707
  await auditSigning("haven_sign_x402", payloadHash);
694
- await auditSigning("haven_sign_x402", hashPayloadForAudit(args.payment_required));
708
+ await auditSigning("haven_sign_x402", hashPayloadForAudit(paymentRequired));
695
709
  return {
696
710
  signature: funding.signature,
697
711
  x402_binding: funding.x402Binding,
@@ -1020,7 +1034,7 @@ async function warnIfCredentialFilePermissive(path, log = (message) => process.s
1020
1034
 
1021
1035
  // src/server.ts
1022
1036
  var SIGNER_NAME = "@haven_ai/signer";
1023
- var SIGNER_VERSION = "0.1.22-alpha.0";
1037
+ var SIGNER_VERSION = "0.1.23-alpha.0";
1024
1038
  async function resolveSignerRuntime(options = {}) {
1025
1039
  assertSupportedNodeVersion(options.nodeVersion);
1026
1040
  if (options.delegateKey) {