mppx 0.6.30 → 0.6.31

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.
@@ -285,7 +285,8 @@ export function session<const parameters extends session.Parameters>(
285
285
  if (
286
286
  envelope &&
287
287
  isSessionContentRequest(envelope.capturedRequest) &&
288
- (payload.action === 'open' || payload.action === 'voucher')
288
+ (payload.action === 'open' ||
289
+ (payload.action === 'voucher' && !isSseNegotiationRequest(envelope.capturedRequest)))
289
290
  ) {
290
291
  const charged = await charge(
291
292
  store,
@@ -315,17 +316,23 @@ export function session<const parameters extends session.Parameters>(
315
316
  // updates; billable requests fall through to the application handler.
316
317
  respond({ credential, envelope, input }) {
317
318
  const { payload } = credential as Credential.Credential<SessionCredentialPayload>
319
+ const request = envelope?.capturedRequest ?? captureRequestBodyProbe(input)
318
320
 
319
321
  if (payload.action === 'close') return new Response(null, { status: 204 })
320
322
  if (payload.action === 'topUp') return new Response(null, { status: 204 })
323
+ if (parameters.sse && payload.action === 'voucher' && isSseNegotiationRequest(request))
324
+ return new Response(null, { status: 204 })
321
325
 
322
- const request = envelope?.capturedRequest ?? captureRequestBodyProbe(input)
323
326
  if (isSessionContentRequest(request)) return undefined
324
327
  return new Response(null, { status: 204 })
325
328
  },
326
329
  })
327
330
  }
328
331
 
332
+ function isSseNegotiationRequest(input: Pick<Method.CapturedRequest, 'headers'>): boolean {
333
+ return input.headers.get('Accept')?.includes('text/event-stream') ?? false
334
+ }
335
+
329
336
  export declare namespace session {
330
337
  type Defaults = LooseOmit<
331
338
  Method.RequestDefaults<typeof Methods.session>,
@@ -553,7 +560,7 @@ async function verifyAndAcceptVoucher(parameters: {
553
560
 
554
561
  if (voucher.cumulativeAmount <= onChain.settled) {
555
562
  throw new VerificationFailedError({
556
- reason: 'voucher cumulativeAmount is below on-chain settled amount',
563
+ reason: 'voucher cumulativeAmount is at or below on-chain settled amount',
557
564
  })
558
565
  }
559
566
 
@@ -561,12 +568,6 @@ async function verifyAndAcceptVoucher(parameters: {
561
568
  throw new AmountExceedsDepositError({ reason: 'voucher amount exceeds on-chain deposit' })
562
569
  }
563
570
 
564
- if (voucher.cumulativeAmount < channel.highestVoucherAmount) {
565
- throw new VerificationFailedError({
566
- reason: 'voucher cumulativeAmount must be strictly greater than highest accepted voucher',
567
- })
568
- }
569
-
570
571
  const isValid = await verifyVoucher(
571
572
  channel.escrowContract,
572
573
  channel.chainId,
@@ -578,9 +579,11 @@ async function verifyAndAcceptVoucher(parameters: {
578
579
  throw new InvalidSignatureError({ reason: 'invalid voucher signature' })
579
580
  }
580
581
 
581
- // Idempotent replay: equal cumulative voucher is accepted without
582
- // advancing channel state or charging additional value.
583
- if (voucher.cumulativeAmount === channel.highestVoucherAmount) {
582
+ // Idempotent replay: a non-advancing voucher (at or below the highest
583
+ // accepted amount, but above the on-chain settled amount checked above)
584
+ // returns 200 OK with the current highest amount without advancing state,
585
+ // per the session spec's idempotency requirement.
586
+ if (voucher.cumulativeAmount <= channel.highestVoucherAmount) {
584
587
  return createSessionReceipt({
585
588
  challengeId: challenge.id,
586
589
  channelId,
@@ -660,7 +663,7 @@ async function handleOpen(
660
663
 
661
664
  if (voucher.cumulativeAmount <= onChain.settled) {
662
665
  throw new VerificationFailedError({
663
- reason: 'voucher cumulativeAmount is below on-chain settled amount',
666
+ reason: 'voucher cumulativeAmount is at or below on-chain settled amount',
664
667
  })
665
668
  }
666
669
 
@@ -701,7 +704,7 @@ async function handleOpen(
701
704
  if (existing) {
702
705
  if (voucher.cumulativeAmount <= existing.settledOnChain) {
703
706
  throw new VerificationFailedError({
704
- reason: 'voucher amount is below settled on-chain amount',
707
+ reason: 'voucher amount is at or below settled on-chain amount',
705
708
  })
706
709
  }
707
710
 
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "accounts": "0.10.2",
6
+ "accounts": "0.14.6",
7
7
  "mppx": "workspace:*",
8
8
  "viem": "2.50.4"
9
9
  }