mppx 0.16.0 → 0.17.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.
@@ -445,8 +445,8 @@ export function assertRemainingValidity(parameters) {
445
445
  return fail('fee-sponsored transaction must declare validBefore for the expiring nonce');
446
446
  if (validBefore <= Math.floor(now.getTime() / 1_000))
447
447
  fail('fee-sponsored transaction has already expired');
448
- if (validBefore < Math.ceil(now.getTime() / 1_000) + 15)
449
- fail('fee-sponsored transaction needs at least 15 seconds of remaining validity');
448
+ if (validBefore < Math.ceil(now.getTime() / 1_000) + defaults.minRemainingValiditySeconds)
449
+ fail(`fee-sponsored transaction needs at least ${defaults.minRemainingValiditySeconds} seconds of remaining validity`);
450
450
  }
451
451
  /** Validates sponsor fee policy limits for a fee-payer transaction. */
452
452
  export function assertTransactionPolicy(parameters) {
@@ -350,7 +350,7 @@ export function charge(parameters = {}) {
350
350
  }
351
351
  : undefined,
352
352
  // TODO: dedupe `{charge,session}.request`
353
- async request({ credential, request }) {
353
+ async request({ credential, expires, request }) {
354
354
  const chainId = await (async () => {
355
355
  if (request.chainId)
356
356
  return request.chainId;
@@ -385,6 +385,17 @@ export function charge(parameters = {}) {
385
385
  return account ?? (remoteFeePayer ? true : undefined);
386
386
  return account || remoteFeePayer ? true : undefined;
387
387
  })();
388
+ // Issued sponsored challenges must leave room for the fee payer's
389
+ // minimum remaining validity, or every credential for them is rejected.
390
+ // Zero-amount proofs and push-only routes never use the fee payer.
391
+ const modes = (request.supportedModes ?? supportedModes);
392
+ if (!credential &&
393
+ resolvedFeePayer &&
394
+ Number(request.amount) > 0 &&
395
+ (modes === undefined || modes.includes('pull')) &&
396
+ expires !== undefined &&
397
+ !(Date.parse(expires) - Date.now() >= defaults.minRemainingValiditySeconds * 1000))
398
+ throw new Error(`Sponsored charge challenges must expire at least ${defaults.minRemainingValiditySeconds} seconds after issuance.`);
388
399
  return {
389
400
  ...request,
390
401
  machineTokenEnabled: request.machineTokenEnabled || undefined,