mppx 0.21.0 → 0.21.2
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/CHANGELOG.md +19 -0
- package/dist/Errors.d.ts +55 -0
- package/dist/Errors.js +48 -0
- package/dist/Html.d.ts +1 -1
- package/dist/Html.js +2 -2
- package/dist/Method.d.ts +1 -1
- package/dist/cli/cli.js +138 -138
- package/dist/cli/internal.js +1 -1
- package/dist/cli/plugins/evm.js +1 -1
- package/dist/cli/plugins/index.js +13 -13
- package/dist/cli/plugins/x402.js +1 -1
- package/dist/cli/utils.d.ts +2 -45
- package/dist/cli/utils.js +2 -79
- package/dist/cli/validate/index.js +5 -2
- package/dist/cli/validate/payment.d.ts +1 -1
- package/dist/cli/validate/payment.js +3 -3
- package/dist/cli/validate/print.d.ts +12 -0
- package/dist/cli/validate/print.js +35 -0
- package/dist/client/core.d.ts +6 -0
- package/dist/client/core.js +6 -0
- package/dist/client/index.d.ts +2 -8
- package/dist/client/index.js +2 -6
- package/dist/client/internal/protocols/Shared.js +1 -1
- package/dist/client/internal/protocols/X402.js +3 -3
- package/dist/evm/client/Charge.js +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/server/Charge.js +1 -1
- package/dist/integrations/x402/Evm.js +1 -1
- package/dist/integrations/x402/Negotiator.js +1 -1
- package/dist/internal/AcceptPayment.js +1 -1
- package/dist/internal/CredentialExpiry.js +1 -1
- package/dist/{mcp/internal/Credential.d.ts → internal/McpCredential.d.ts} +2 -2
- package/dist/{mcp/internal/Credential.js → internal/McpCredential.js} +2 -2
- package/dist/{server/internal → internal}/challengeMeta.js +1 -1
- package/dist/{server/internal → internal}/html/config.d.ts +2 -2
- package/dist/internal/pc.d.ts +46 -0
- package/dist/internal/pc.js +80 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/{x402 → internal/x402}/Header.js +1 -1
- package/dist/{x402 → internal/x402}/Siwx.d.ts +2 -2
- package/dist/{x402 → internal/x402}/Siwx.js +2 -2
- package/dist/{x402 → internal/x402}/Types.d.ts +1 -1
- package/dist/{x402 → internal/x402}/Types.js +1 -1
- package/dist/mcp/server/index.d.ts +1 -1
- package/dist/mcp/server/index.js +1 -1
- package/dist/server/Mppx.d.ts +1 -1
- package/dist/server/Mppx.js +6 -6
- package/dist/server/Transport.d.ts +2 -2
- package/dist/server/Transport.js +4 -4
- package/dist/server/index.d.ts +1 -8
- package/dist/server/index.js +1 -8
- package/dist/{mcp/server/Transport.d.ts → server/internal/mcpSdk.d.ts} +2 -2
- package/dist/{mcp/server/Transport.js → server/internal/mcpSdk.js} +3 -3
- package/dist/stripe/server/Charge.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/Methods.d.ts +3 -0
- package/dist/tempo/Methods.js +3 -1
- package/dist/tempo/client/Charge.js +1 -1
- package/dist/tempo/client/Methods.d.ts +3 -0
- package/dist/tempo/client/index.d.ts +3 -0
- package/dist/tempo/client/index.js +1 -0
- package/dist/tempo/internal/configurable-account.d.ts +26 -0
- package/dist/tempo/internal/configurable-account.js +77 -0
- package/dist/tempo/internal/signature.d.ts +15 -0
- package/dist/tempo/internal/signature.js +43 -0
- package/dist/tempo/server/Charge.d.ts +1 -1
- package/dist/tempo/server/Charge.js +1 -1
- package/dist/tempo/server/Methods.d.ts +139 -4
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/ChannelOps.d.ts +29 -0
- package/dist/tempo/session/client/ChannelOps.js +108 -3
- package/dist/tempo/session/client/CredentialState.d.ts +6 -0
- package/dist/tempo/session/client/CredentialState.js +29 -4
- package/dist/tempo/session/client/Session.d.ts +3 -0
- package/dist/tempo/session/client/SessionManager.js +4 -0
- package/dist/tempo/session/precompile/Chain.d.ts +35 -1
- package/dist/tempo/session/precompile/Chain.js +52 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +46 -5
- package/dist/tempo/session/precompile/Voucher.js +78 -29
- package/dist/tempo/session/precompile/escrow.abi.d.ts +79 -0
- package/dist/tempo/session/precompile/escrow.abi.js +38 -0
- package/dist/tempo/session/server/ChannelStore.d.ts +27 -0
- package/dist/tempo/session/server/ChannelStore.js +24 -3
- package/dist/tempo/session/server/CredentialVerification.d.ts +7 -1
- package/dist/tempo/session/server/CredentialVerification.js +91 -12
- package/dist/tempo/session/server/RequestState.d.ts +2 -0
- package/dist/tempo/session/server/RequestState.js +1 -0
- package/dist/tempo/session/server/Session.d.ts +11 -0
- package/dist/tempo/session/server/Session.js +10 -2
- package/dist/tempo/session/server/SponsorshipLimit.d.ts +11 -3
- package/dist/tempo/session/server/SponsorshipLimit.js +36 -4
- package/dist/tempo/subscription/KeyAuthorization.js +6 -2
- package/dist/{cli/validate → validation}/challenge.d.ts +1 -1
- package/dist/{cli/validate → validation}/challenge.js +4 -4
- package/dist/validation/core.d.ts +29 -2
- package/dist/validation/core.js +41 -10
- package/dist/{cli/validate → validation}/helpers.d.ts +0 -10
- package/dist/{cli/validate → validation}/helpers.js +1 -35
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +1 -1
- package/dist/x402/Assets.d.ts +1 -1
- package/dist/x402/client/Exact.d.ts +1 -1
- package/dist/x402/client/Exact.js +2 -2
- package/dist/x402/index.d.ts +4 -4
- package/dist/x402/index.js +4 -4
- package/dist/x402/internal/RouteBinding.d.ts +1 -1
- package/dist/x402/mcp.js +2 -2
- package/dist/x402/server/EvmCharge.d.ts +2 -2
- package/dist/x402/server/EvmCharge.js +4 -4
- package/dist/x402/server/Facilitator.d.ts +1 -1
- package/dist/x402/server/Facilitator.js +1 -1
- package/dist/x402/tempo.d.ts +48 -0
- package/dist/x402/tempo.js +68 -0
- package/package.json +21 -1
- /package/dist/{server/internal → internal}/challengeMeta.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.js +0 -0
- /package/dist/{server/internal → internal}/html/config.js +0 -0
- /package/dist/{server/internal → internal}/html/constants.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/constants.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.js +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.d.ts +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.js +0 -0
- /package/dist/{x402 → internal/x402}/Header.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.js +0 -0
- /package/dist/{cli/validate → validation}/messages.d.ts +0 -0
- /package/dist/{cli/validate → validation}/messages.js +0 -0
|
@@ -2,6 +2,7 @@ import { TxEnvelopeTempo } from 'ox/tempo';
|
|
|
2
2
|
import { isAddress, isAddressEqual, zeroAddress, } from 'viem';
|
|
3
3
|
import { Actions } from 'viem/tempo';
|
|
4
4
|
import { AmountExceedsDepositError, ChannelClosedError, ChannelNotFoundError, DeltaTooSmallError, InsufficientBalanceError, InvalidSignatureError, VerificationFailedError, } from '../../../Errors.js';
|
|
5
|
+
import * as ConfigurableAccount from '../../internal/configurable-account.js';
|
|
5
6
|
import * as Chain from '../precompile/Chain.js';
|
|
6
7
|
import { readChannelClosedReceiptFields } from '../precompile/Chain.js';
|
|
7
8
|
import * as Channel from '../precompile/Channel.js';
|
|
@@ -17,6 +18,22 @@ export function authorizedSigner(descriptor) {
|
|
|
17
18
|
? descriptor.payer
|
|
18
19
|
: descriptor.authorizedSigner;
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Verifies an open credential's initial voucher before its open lands, when the TIP-1166 signer
|
|
23
|
+
* opening commitment is not known yet: the escrow records `descriptor.salt` as the opening
|
|
24
|
+
* commitment when the signer has a config commitment, and none otherwise. After the open, the
|
|
25
|
+
* voucher is verified again against the opening commitment from the receipt.
|
|
26
|
+
*/
|
|
27
|
+
function verifyOpenVoucher(escrow, chainId, voucher, descriptor, configurableVouchers) {
|
|
28
|
+
const signer = authorizedSigner(descriptor);
|
|
29
|
+
if (!configurableVouchers)
|
|
30
|
+
return Voucher.verifyVoucher(escrow, chainId, voucher, signer);
|
|
31
|
+
return (Voucher.verifyVoucher(escrow, chainId, voucher, signer, { configurable: true }) ||
|
|
32
|
+
Voucher.verifyVoucher(escrow, chainId, voucher, signer, {
|
|
33
|
+
configurable: true,
|
|
34
|
+
openingCommitment: descriptor.salt,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
20
37
|
/** Asserts that a credential payload includes a TIP-1034 descriptor. */
|
|
21
38
|
export function assertDescriptor(payload) {
|
|
22
39
|
if (!payload.descriptor)
|
|
@@ -108,9 +125,11 @@ export async function assertCredentialSourceIsPayer(source, chainId, payer, seri
|
|
|
108
125
|
});
|
|
109
126
|
let valid = false;
|
|
110
127
|
try {
|
|
111
|
-
const signer = verifiedPayer(serializedTransaction);
|
|
112
128
|
const { signature, keyAuthorization } = TxEnvelopeTempo.deserialize(serializedTransaction);
|
|
113
|
-
|
|
129
|
+
const signer = signature?.type === 'configurable' ? null : verifiedPayer(serializedTransaction);
|
|
130
|
+
if (signature?.type === 'configurable')
|
|
131
|
+
valid = await verifyConfigurableTransactionPayer(serializedTransaction, payer, client);
|
|
132
|
+
else if (signer && signature?.type !== 'keychain')
|
|
114
133
|
valid = isAddressEqual(signer, payer);
|
|
115
134
|
else if (signer &&
|
|
116
135
|
signature?.type === 'keychain' &&
|
|
@@ -137,6 +156,28 @@ export async function assertCredentialSourceIsPayer(source, chainId, payer, seri
|
|
|
137
156
|
reason: 'credential source is not authenticated by transaction signature',
|
|
138
157
|
});
|
|
139
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Authenticates a TIP-1107 configurable account transaction signature as `payer`: the envelope must
|
|
161
|
+
* name `payer`, its config must match the payer's on-chain commitment (or, when the payer has none,
|
|
162
|
+
* be the version-zero config that derives its address, which the transaction registers), and its
|
|
163
|
+
* owner approvals over the transaction's sign payload must reach the threshold.
|
|
164
|
+
*/
|
|
165
|
+
async function verifyConfigurableTransactionPayer(serializedTransaction, payer, client) {
|
|
166
|
+
if (!/^0x7[68][0-9a-fA-F]+$/.test(serializedTransaction))
|
|
167
|
+
return false;
|
|
168
|
+
const { from: _claimedSender, ...fields } = TxEnvelopeTempo.deserialize(serializedTransaction);
|
|
169
|
+
const { signature } = fields;
|
|
170
|
+
if (signature?.type !== 'configurable')
|
|
171
|
+
return false;
|
|
172
|
+
if (!isAddressEqual(signature.account, payer))
|
|
173
|
+
return false;
|
|
174
|
+
const commitment = await Actions.accounts.getConfigCommitment(client, { account: payer });
|
|
175
|
+
return ConfigurableAccount.verify(signature, {
|
|
176
|
+
account: payer,
|
|
177
|
+
commitment,
|
|
178
|
+
payload: TxEnvelopeTempo.getSignPayload(TxEnvelopeTempo.from(fields)),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
140
181
|
function readCredentialSourceAddress(source, chainId) {
|
|
141
182
|
const prefix = `did:pkh:eip155:${chainId}:`;
|
|
142
183
|
if (!source?.startsWith(prefix))
|
|
@@ -346,7 +387,7 @@ async function validateOpenCredential(parameters, payload) {
|
|
|
346
387
|
await assertCredentialSourceIsPayer(parameters.credentialSource, chainId, transaction.descriptor.payer, payload.transaction, client);
|
|
347
388
|
if (cumulativeAmount > transaction.openDeposit)
|
|
348
389
|
throw new AmountExceedsDepositError({ reason: 'voucher amount exceeds open deposit' });
|
|
349
|
-
const valid =
|
|
390
|
+
const valid = verifyOpenVoucher(escrow, chainId, { channelId, cumulativeAmount, signature: payload.signature }, transaction.descriptor, parameters.configurableVouchers);
|
|
350
391
|
if (!valid)
|
|
351
392
|
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
352
393
|
await Chain.simulateCredentialTransaction({
|
|
@@ -432,6 +473,7 @@ async function validateVoucherCredential(parameters, payload) {
|
|
|
432
473
|
channel,
|
|
433
474
|
channelState,
|
|
434
475
|
methodDetails: { chainId, escrowContract: escrow },
|
|
476
|
+
configurableVouchers: parameters.configurableVouchers,
|
|
435
477
|
minVoucherDelta,
|
|
436
478
|
voucher,
|
|
437
479
|
});
|
|
@@ -484,7 +526,10 @@ async function validateCloseCredential(parameters, payload) {
|
|
|
484
526
|
escrow,
|
|
485
527
|
store,
|
|
486
528
|
});
|
|
487
|
-
const closeAuthorized = Voucher.verifyCloseAuthorization(escrow, chainId, { channelId, cumulativeAmount, signature: payload.closeSignature }, [channel.payer, channel.authorizedSigner]
|
|
529
|
+
const closeAuthorized = Voucher.verifyCloseAuthorization(escrow, chainId, { channelId, cumulativeAmount, signature: payload.closeSignature }, [channel.payer, channel.authorizedSigner], {
|
|
530
|
+
...ChannelStore.resolveVoucherOptions(channel, parameters.configurableVouchers),
|
|
531
|
+
voucherSigner: channel.authorizedSigner,
|
|
532
|
+
});
|
|
488
533
|
if (!closeAuthorized)
|
|
489
534
|
throw new InvalidSignatureError({ reason: 'invalid close authorization signature' });
|
|
490
535
|
if (channel.finalized)
|
|
@@ -502,7 +547,7 @@ async function validateCloseCredential(parameters, payload) {
|
|
|
502
547
|
throw new VerificationFailedError({
|
|
503
548
|
reason: `close voucher amount must be >= ${state.settled} (on-chain settled)`,
|
|
504
549
|
});
|
|
505
|
-
const valid = await Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount, signature: payload.signature }, channel.authorizedSigner);
|
|
550
|
+
const valid = await Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount, signature: payload.signature }, channel.authorizedSigner, ChannelStore.resolveVoucherOptions(channel, parameters.configurableVouchers));
|
|
506
551
|
if (!valid)
|
|
507
552
|
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
508
553
|
const captureAmount = uint96(channel.spent > state.settled ? channel.spent : state.settled);
|
|
@@ -583,14 +628,23 @@ async function handleOpenCredential(parameters) {
|
|
|
583
628
|
await assertCredentialSourceIsPayer(parameters.credentialSource, chainId, prepared.descriptor.payer, payload.transaction, client);
|
|
584
629
|
if (cumulativeAmount > prepared.openDeposit)
|
|
585
630
|
throw new AmountExceedsDepositError({ reason: 'voucher amount exceeds open deposit' });
|
|
586
|
-
const valid =
|
|
631
|
+
const valid = verifyOpenVoucher(escrow, chainId, { channelId, cumulativeAmount: cumulativeAmount, signature: payload.signature }, prepared.descriptor, parameters.configurableVouchers);
|
|
587
632
|
if (!valid)
|
|
588
633
|
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
589
634
|
},
|
|
590
635
|
});
|
|
591
|
-
const { descriptor, state } = result;
|
|
636
|
+
const { descriptor, openingCommitment, state } = result;
|
|
592
637
|
assertSameDescriptor(descriptor, payload.descriptor);
|
|
593
638
|
validateChannelState(state, request.amount);
|
|
639
|
+
// The open voucher was checked against both possible opening commitments before broadcast; always check it
|
|
640
|
+
// again against the one the escrow recorded. With none (no OpeningCommitmentRecorded in the receipt),
|
|
641
|
+
// this applies the zero-commitment rules: a primitive signature recovering to the signer, or a
|
|
642
|
+
// configurable signature whose version-zero config derives the signer's address.
|
|
643
|
+
if (!Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount, signature: payload.signature }, authorizedSigner(descriptor), {
|
|
644
|
+
configurable: parameters.configurableVouchers,
|
|
645
|
+
...(openingCommitment ? { openingCommitment } : {}),
|
|
646
|
+
}))
|
|
647
|
+
throw new InvalidSignatureError({ reason: 'invalid voucher signature for opening commitment' });
|
|
594
648
|
const updated = await store.updateChannel(channelId, (current) => {
|
|
595
649
|
if (parameters.requireVoucherAdvance &&
|
|
596
650
|
current !== null &&
|
|
@@ -606,6 +660,7 @@ async function handleOpenCredential(parameters) {
|
|
|
606
660
|
descriptor,
|
|
607
661
|
escrow,
|
|
608
662
|
expiringNonceHash: result.expiringNonceHash,
|
|
663
|
+
...(openingCommitment ? { openingCommitment } : {}),
|
|
609
664
|
cumulativeAmount,
|
|
610
665
|
signature: payload.signature,
|
|
611
666
|
state,
|
|
@@ -741,6 +796,7 @@ async function handleVoucherCredential(parameters) {
|
|
|
741
796
|
voucher,
|
|
742
797
|
channelState: storedChannelState(channel),
|
|
743
798
|
methodDetails: { chainId, escrowContract: escrow },
|
|
799
|
+
configurableVouchers: parameters.configurableVouchers,
|
|
744
800
|
chargeAmount,
|
|
745
801
|
prepaidRefundKey: parameters.prepaidRefundKey,
|
|
746
802
|
onCharged,
|
|
@@ -768,6 +824,7 @@ async function handleVoucherCredential(parameters) {
|
|
|
768
824
|
voucher,
|
|
769
825
|
channelState,
|
|
770
826
|
methodDetails: { chainId, escrowContract: escrow },
|
|
827
|
+
configurableVouchers: parameters.configurableVouchers,
|
|
771
828
|
verifiedAt: startedAt,
|
|
772
829
|
chargeAmount,
|
|
773
830
|
prepaidRefundKey: parameters.prepaidRefundKey,
|
|
@@ -782,9 +839,25 @@ async function handleVoucherCredential(parameters) {
|
|
|
782
839
|
async function acceptVoucherInOneUpdate(parameters, voucher, descriptor) {
|
|
783
840
|
const { challenge, chainId, chargeAmount, credentialSource, escrow, lastOnChainVerified, minVoucherDelta, requireVoucherAdvance, store, } = parameters;
|
|
784
841
|
const voucherStateMaxAge = parameters.voucherStateMaxAge ?? 0;
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
842
|
+
// Configurable account vouchers depend on the stored TIP-1166 opening commitment, so they are
|
|
843
|
+
// verified inside the update, against the stored channel.
|
|
844
|
+
if (!parameters.configurableVouchers) {
|
|
845
|
+
const valid = await Voucher.verifyVoucher(escrow, chainId, voucher, authorizedSigner(descriptor));
|
|
846
|
+
if (!valid)
|
|
847
|
+
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
848
|
+
}
|
|
849
|
+
// Compare-and-swap stores rerun the update after a conflicting write, so verify each distinct
|
|
850
|
+
// signer and options once per request.
|
|
851
|
+
const verified = new Map();
|
|
852
|
+
const verifyStoredVoucher = (signer, options) => {
|
|
853
|
+
const key = `${signer.toLowerCase()}:${options.configurable ? 1 : 0}:${options.openingCommitment ?? ''}`;
|
|
854
|
+
let valid = verified.get(key);
|
|
855
|
+
if (valid === undefined) {
|
|
856
|
+
valid = Voucher.verifyVoucher(escrow, chainId, voucher, signer, options);
|
|
857
|
+
verified.set(key, valid);
|
|
858
|
+
}
|
|
859
|
+
return valid;
|
|
860
|
+
};
|
|
788
861
|
const outcome = await store.updateChannelResult(voucher.channelId, (current) => {
|
|
789
862
|
if (!current)
|
|
790
863
|
throw new ChannelNotFoundError({ reason: 'channel not found' });
|
|
@@ -795,6 +868,9 @@ async function acceptVoucherInOneUpdate(parameters, voucher, descriptor) {
|
|
|
795
868
|
assertCredentialSourceCanSpend({ chainId, channel: current, source: credentialSource });
|
|
796
869
|
if (current.finalized)
|
|
797
870
|
throw new ChannelClosedError({ reason: 'channel is finalized' });
|
|
871
|
+
if ((parameters.configurableVouchers || ChannelStore.resolveOpeningCommitment(current)) &&
|
|
872
|
+
!verifyStoredVoucher(current.authorizedSigner, ChannelStore.resolveVoucherOptions(current, parameters.configurableVouchers)))
|
|
873
|
+
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
798
874
|
if (!canUseStoredChannelState({
|
|
799
875
|
channel: current,
|
|
800
876
|
channelId: voucher.channelId,
|
|
@@ -895,7 +971,10 @@ async function handleCloseCredential(parameters) {
|
|
|
895
971
|
escrow,
|
|
896
972
|
store,
|
|
897
973
|
});
|
|
898
|
-
const closeAuthorized = Voucher.verifyCloseAuthorization(escrow, chainId, { channelId, cumulativeAmount, signature: payload.closeSignature }, [channel.payer, channel.authorizedSigner]
|
|
974
|
+
const closeAuthorized = Voucher.verifyCloseAuthorization(escrow, chainId, { channelId, cumulativeAmount, signature: payload.closeSignature }, [channel.payer, channel.authorizedSigner], {
|
|
975
|
+
...ChannelStore.resolveVoucherOptions(channel, parameters.configurableVouchers),
|
|
976
|
+
voucherSigner: channel.authorizedSigner,
|
|
977
|
+
});
|
|
899
978
|
if (!closeAuthorized)
|
|
900
979
|
throw new InvalidSignatureError({ reason: 'invalid close authorization signature' });
|
|
901
980
|
if (channel.finalized)
|
|
@@ -913,7 +992,7 @@ async function handleCloseCredential(parameters) {
|
|
|
913
992
|
throw new VerificationFailedError({
|
|
914
993
|
reason: `close voucher amount must be >= ${state.settled} (on-chain settled)`,
|
|
915
994
|
});
|
|
916
|
-
const valid = await Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount: cumulativeAmount, signature: payload.signature }, channel.authorizedSigner);
|
|
995
|
+
const valid = await Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount: cumulativeAmount, signature: payload.signature }, channel.authorizedSigner, ChannelStore.resolveVoucherOptions(channel, parameters.configurableVouchers));
|
|
917
996
|
if (!valid)
|
|
918
997
|
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
919
998
|
let captureAmount = uint96(channel.spent > state.settled ? channel.spent : state.settled);
|
|
@@ -135,6 +135,8 @@ export type SessionMethodDetails = {
|
|
|
135
135
|
minVoucherDelta?: string | undefined;
|
|
136
136
|
/** Channel operator address the client should encode in new open transactions. */
|
|
137
137
|
operator?: Address | undefined;
|
|
138
|
+
/** Whether the server accepts TIP-1166 configurable account (`0x05`) vouchers. */
|
|
139
|
+
configurableVouchers?: boolean | undefined;
|
|
138
140
|
/** Tempo session protocol version for this challenge. */
|
|
139
141
|
sessionProtocol?: Constants.SessionProtocol | undefined;
|
|
140
142
|
};
|
|
@@ -124,6 +124,7 @@ function isCanonicalSessionMethodDetails(value) {
|
|
|
124
124
|
(value.minVoucherDelta === undefined || typeof value.minVoucherDelta === 'string') &&
|
|
125
125
|
(value.operator === undefined ||
|
|
126
126
|
(typeof value.operator === 'string' && isAddress(value.operator, { strict: false }))) &&
|
|
127
|
+
(value.configurableVouchers === undefined || typeof value.configurableVouchers === 'boolean') &&
|
|
127
128
|
(value.sessionProtocol === undefined || value.sessionProtocol === Constants.SessionProtocols.v2));
|
|
128
129
|
}
|
|
129
130
|
function isVerifiedSessionPaymentRequest(request) {
|
|
@@ -72,6 +72,7 @@ export declare function session<const parameters extends session.Parameters>(p?:
|
|
|
72
72
|
amount: import("zod/mini").ZodMiniString<string>;
|
|
73
73
|
chainId: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniNumber<number>>;
|
|
74
74
|
channelId: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
75
|
+
configurableVouchers: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniBoolean<boolean>>;
|
|
75
76
|
currency: import("zod/mini").ZodMiniString<string>;
|
|
76
77
|
decimals: import("zod/mini").ZodMiniNumber<number>;
|
|
77
78
|
escrowContract: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
@@ -101,6 +102,7 @@ export declare function session<const parameters extends session.Parameters>(p?:
|
|
|
101
102
|
feePayer?: boolean | undefined;
|
|
102
103
|
feeToken?: string | undefined;
|
|
103
104
|
operator?: string | undefined;
|
|
105
|
+
configurableVouchers?: boolean | undefined;
|
|
104
106
|
sessionProtocol?: "v1" | "v2" | undefined;
|
|
105
107
|
sessionSnapshot?: import("../Snapshot.js").SessionSnapshot | undefined;
|
|
106
108
|
};
|
|
@@ -108,6 +110,7 @@ export declare function session<const parameters extends session.Parameters>(p?:
|
|
|
108
110
|
amount: string;
|
|
109
111
|
chainId?: number | undefined;
|
|
110
112
|
channelId?: string | undefined;
|
|
113
|
+
configurableVouchers?: boolean | undefined;
|
|
111
114
|
currency: string;
|
|
112
115
|
decimals: number;
|
|
113
116
|
escrowContract?: string | undefined;
|
|
@@ -159,6 +162,14 @@ export declare namespace session {
|
|
|
159
162
|
feePayerPolicy?: FeePayerPolicy | undefined;
|
|
160
163
|
/** Minimum voucher delta to accept (numeric string, default: "0"). */
|
|
161
164
|
minVoucherDelta?: string | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Accepts TIP-1166 configurable account (`0x05`) vouchers and close authorizations, and
|
|
167
|
+
* advertises `methodDetails.configurableVouchers` in the challenge so configurable account
|
|
168
|
+
* clients may open channels. Each voucher is checked against the signer config commitment the
|
|
169
|
+
* escrow recorded at open (`OpeningCommitmentRecorded`). Enable once the chain runs T15.
|
|
170
|
+
* @default false
|
|
171
|
+
*/
|
|
172
|
+
configurableVouchers?: boolean | undefined;
|
|
162
173
|
/**
|
|
163
174
|
* Maps authenticated application identity and payment scope to an existing channel ID.
|
|
164
175
|
* Called only when the request does not already supply a channel ID. MPPx then loads that
|
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { isAddress } from 'viem';
|
|
9
9
|
import { tempo as tempo_chain } from 'viem/chains';
|
|
10
|
+
import { Actions } from 'viem/tempo';
|
|
10
11
|
import * as Challenge from '../../../Challenge.js';
|
|
11
12
|
import * as Constants from '../../../Constants.js';
|
|
12
13
|
import * as Errors from '../../../Errors.js';
|
|
13
14
|
import * as Expires from '../../../Expires.js';
|
|
15
|
+
import * as ChallengeMeta from '../../../internal/challengeMeta.js';
|
|
14
16
|
import * as Method from '../../../Method.js';
|
|
15
|
-
import * as ChallengeMeta from '../../../server/internal/challengeMeta.js';
|
|
16
17
|
import * as Client from '../../../viem/Client.js';
|
|
17
18
|
import * as Account from '../../internal/account.js';
|
|
18
19
|
import * as defaults from '../../internal/defaults.js';
|
|
@@ -331,6 +332,7 @@ export function session(p) {
|
|
|
331
332
|
channelStateTtl,
|
|
332
333
|
chainId: context.chainId,
|
|
333
334
|
client: context.client,
|
|
335
|
+
configurableVouchers: parameters.configurableVouchers,
|
|
334
336
|
credentialSource: credential.source,
|
|
335
337
|
escrow: context.escrow,
|
|
336
338
|
expectedOperator: context.methodDetails.operator,
|
|
@@ -397,6 +399,7 @@ export function session(p) {
|
|
|
397
399
|
channelStateTtl,
|
|
398
400
|
chainId: context.chainId,
|
|
399
401
|
client: context.client,
|
|
402
|
+
configurableVouchers: parameters.configurableVouchers,
|
|
400
403
|
credentialSource: credential.source,
|
|
401
404
|
escrow: context.escrow,
|
|
402
405
|
expectedOperator: context.methodDetails.operator,
|
|
@@ -405,6 +408,7 @@ export function session(p) {
|
|
|
405
408
|
feePayer: context.feePayer,
|
|
406
409
|
limit: parameters.sponsorshipLimit,
|
|
407
410
|
payload,
|
|
411
|
+
readConfigCommitment: (account) => Actions.accounts.getConfigCommitment(context.client, { account }),
|
|
408
412
|
}),
|
|
409
413
|
feePayerPolicy: parameters.feePayerPolicy,
|
|
410
414
|
feeToken: context.methodDetails.feeToken,
|
|
@@ -495,8 +499,12 @@ export function session(p) {
|
|
|
495
499
|
sseEnabled: Boolean(parameters.sse),
|
|
496
500
|
store,
|
|
497
501
|
});
|
|
502
|
+
// Verification honors only the server option, so a route cannot advertise TIP-1166
|
|
503
|
+
// vouchers the server would reject.
|
|
504
|
+
const { configurableVouchers: _routeConfigurableVouchers, ...routeRequest } = resolvedRequest;
|
|
498
505
|
return {
|
|
499
|
-
...
|
|
506
|
+
...routeRequest,
|
|
507
|
+
...(parameters.configurableVouchers ? { configurableVouchers: true } : {}),
|
|
500
508
|
feeToken: parameters.feeToken,
|
|
501
509
|
sessionProtocol: Constants.SessionProtocols.v2,
|
|
502
510
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address } from 'ox';
|
|
1
|
+
import { Address, type Hex } from 'ox';
|
|
2
2
|
import type * as Store from '../../../Store.js';
|
|
3
3
|
import type { SessionCredentialPayload } from '../precompile/Protocol.js';
|
|
4
4
|
/**
|
|
@@ -24,9 +24,15 @@ export declare function assertParameters(parameters: Parameters | undefined): vo
|
|
|
24
24
|
* - a direct signature: its signer;
|
|
25
25
|
* - an access key authorized in the same transaction: the account that signed the authorization,
|
|
26
26
|
* so fresh keys do not get a fresh quota;
|
|
27
|
-
* - an access key authorized earlier: the key itself (its account link is only checked on chain)
|
|
27
|
+
* - an access key authorized earlier: the key itself (its account link is only checked on chain);
|
|
28
|
+
* - a configurable account signature: its account, only against `options.configCommitment`, the
|
|
29
|
+
* account's on-chain config commitment (zero for an unregistered account, whose version-zero
|
|
30
|
+
* config must derive it). Without it, a configurable signature proves no payer, since a
|
|
31
|
+
* version-zero config's owners may have been rotated out.
|
|
28
32
|
*/
|
|
29
|
-
export declare function verifiedPayer(serializedTransaction: string
|
|
33
|
+
export declare function verifiedPayer(serializedTransaction: string, options?: {
|
|
34
|
+
configCommitment?: Hex.Hex | undefined;
|
|
35
|
+
}): Address.Address | null;
|
|
30
36
|
/**
|
|
31
37
|
* Records one sponsored `action` for `payer` on the current UTC day. Returns false, recording
|
|
32
38
|
* nothing, once the payer has used `perDay` of them.
|
|
@@ -48,5 +54,7 @@ export declare function limitFeePayer<feePayer>(parameters: {
|
|
|
48
54
|
feePayer: feePayer | undefined;
|
|
49
55
|
limit: Parameters | undefined;
|
|
50
56
|
payload: SessionCredentialPayload;
|
|
57
|
+
/** Reads an account's on-chain TIP-1107 config commitment, to verify a configurable payer. */
|
|
58
|
+
readConfigCommitment?: ((account: Address.Address) => Promise<Hex.Hex>) | undefined;
|
|
51
59
|
}): Promise<feePayer | undefined>;
|
|
52
60
|
//# sourceMappingURL=SponsorshipLimit.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Address } from 'ox';
|
|
2
2
|
import { KeyAuthorization, SignatureEnvelope, TxEnvelopeTempo } from 'ox/tempo';
|
|
3
|
+
import * as ConfigurableAccount from '../../internal/configurable-account.js';
|
|
3
4
|
/**
|
|
4
5
|
* Sponsored opens, and separately sponsored top-ups, each verified payer may make per UTC day. It is
|
|
5
6
|
* tempoxyz/mpp-proxy's `DAILY_CHANNEL_OPEN_LIMIT`, the limit its proxy applied to sponsored channel
|
|
@@ -36,9 +37,13 @@ function verifiedSigner(payload, signature) {
|
|
|
36
37
|
* - a direct signature: its signer;
|
|
37
38
|
* - an access key authorized in the same transaction: the account that signed the authorization,
|
|
38
39
|
* so fresh keys do not get a fresh quota;
|
|
39
|
-
* - an access key authorized earlier: the key itself (its account link is only checked on chain)
|
|
40
|
+
* - an access key authorized earlier: the key itself (its account link is only checked on chain);
|
|
41
|
+
* - a configurable account signature: its account, only against `options.configCommitment`, the
|
|
42
|
+
* account's on-chain config commitment (zero for an unregistered account, whose version-zero
|
|
43
|
+
* config must derive it). Without it, a configurable signature proves no payer, since a
|
|
44
|
+
* version-zero config's owners may have been rotated out.
|
|
40
45
|
*/
|
|
41
|
-
export function verifiedPayer(serializedTransaction) {
|
|
46
|
+
export function verifiedPayer(serializedTransaction, options = {}) {
|
|
42
47
|
if (!/^0x7[68][0-9a-fA-F]+$/.test(serializedTransaction))
|
|
43
48
|
return null;
|
|
44
49
|
try {
|
|
@@ -47,6 +52,17 @@ export function verifiedPayer(serializedTransaction) {
|
|
|
47
52
|
if (!signature)
|
|
48
53
|
return null;
|
|
49
54
|
const envelope = TxEnvelopeTempo.from(fields);
|
|
55
|
+
// A configurable account signature proves its account only against the account's on-chain
|
|
56
|
+
// commitment.
|
|
57
|
+
if (signature.type === 'configurable')
|
|
58
|
+
return options.configCommitment !== undefined &&
|
|
59
|
+
ConfigurableAccount.verify(signature, {
|
|
60
|
+
account: signature.account,
|
|
61
|
+
commitment: options.configCommitment,
|
|
62
|
+
payload: TxEnvelopeTempo.getSignPayload(envelope),
|
|
63
|
+
})
|
|
64
|
+
? lower(signature.account)
|
|
65
|
+
: null;
|
|
50
66
|
if (signature.type !== 'keychain')
|
|
51
67
|
return lower(verifiedSigner(TxEnvelopeTempo.getSignPayload(envelope), signature));
|
|
52
68
|
// Keychain V2 signs over the account too: keccak256(0x04 || sigHash || userAddress).
|
|
@@ -64,6 +80,18 @@ export function verifiedPayer(serializedTransaction) {
|
|
|
64
80
|
return null;
|
|
65
81
|
}
|
|
66
82
|
}
|
|
83
|
+
/** Returns the account a transaction's configurable account signature names, or null. */
|
|
84
|
+
function configurableAccount(serializedTransaction) {
|
|
85
|
+
if (!/^0x7[68][0-9a-fA-F]+$/.test(serializedTransaction))
|
|
86
|
+
return null;
|
|
87
|
+
try {
|
|
88
|
+
const { signature } = TxEnvelopeTempo.deserialize(serializedTransaction);
|
|
89
|
+
return signature?.type === 'configurable' ? signature.account : null;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
67
95
|
function lower(address) {
|
|
68
96
|
return address ? address.toLowerCase() : null;
|
|
69
97
|
}
|
|
@@ -88,12 +116,16 @@ export async function reserve(store, parameters) {
|
|
|
88
116
|
* The transaction is then broadcast as the payer signed it, paying its own fees.
|
|
89
117
|
*/
|
|
90
118
|
export async function limitFeePayer(parameters) {
|
|
91
|
-
const { chainId, feePayer, limit, payload } = parameters;
|
|
119
|
+
const { chainId, feePayer, limit, payload, readConfigCommitment } = parameters;
|
|
92
120
|
if (!feePayer || !limit)
|
|
93
121
|
return feePayer;
|
|
94
122
|
if (payload.action !== 'open' && payload.action !== 'topUp')
|
|
95
123
|
return feePayer;
|
|
96
|
-
const
|
|
124
|
+
const account = configurableAccount(payload.transaction);
|
|
125
|
+
const configCommitment = account && readConfigCommitment
|
|
126
|
+
? await readConfigCommitment(account).catch(() => undefined)
|
|
127
|
+
: undefined;
|
|
128
|
+
const payer = verifiedPayer(payload.transaction, { configCommitment });
|
|
97
129
|
if (!payer)
|
|
98
130
|
return undefined;
|
|
99
131
|
const allowed = await reserve(limit.store, {
|
|
@@ -2,6 +2,7 @@ import { Base64, Hex } from 'ox';
|
|
|
2
2
|
import { KeyAuthorization, SignatureEnvelope } from 'ox/tempo';
|
|
3
3
|
import { isAddress, isAddressEqual } from 'viem';
|
|
4
4
|
import { VerificationFailedError } from '../../Errors.js';
|
|
5
|
+
import { isLowS, toLowS } from '../internal/signature.js';
|
|
5
6
|
/** 4-byte selector for TIP-20 `transfer(address,uint256)`. */
|
|
6
7
|
export const transferSelector = '0xa9059cbb';
|
|
7
8
|
/** 4-byte selector for TIP-20 `transferWithMemo(address,uint256,bytes32)`. */
|
|
@@ -141,7 +142,8 @@ export async function signSubscriptionKeyAuthorization(parameters) {
|
|
|
141
142
|
});
|
|
142
143
|
}
|
|
143
144
|
return KeyAuthorization.from(authorization, {
|
|
144
|
-
|
|
145
|
+
// Tempo accepts only low-s signatures; some signers (KMS, HSM) return either form.
|
|
146
|
+
signature: SignatureEnvelope.serialize(toLowS(signatureEnvelope)),
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
149
|
/**
|
|
@@ -292,7 +294,9 @@ function recoverAuthorizationSource(authorization, signature) {
|
|
|
292
294
|
payload: signPayload,
|
|
293
295
|
signature,
|
|
294
296
|
});
|
|
295
|
-
|
|
297
|
+
// Tempo rejects high-s key authorization signatures, so the subscription could never be charged.
|
|
298
|
+
if (!isLowS(signature) ||
|
|
299
|
+
!SignatureEnvelope.verify(signature, { address: source, payload: signPayload })) {
|
|
296
300
|
throw new VerificationFailedError({ reason: 'keyAuthorization signature is invalid' });
|
|
297
301
|
}
|
|
298
302
|
return source;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Challenge from '
|
|
1
|
+
import * as Challenge from '../Challenge.js';
|
|
2
2
|
import type { CheckResult, EndpointSpec } from './helpers.js';
|
|
3
3
|
export declare function validateChallenge(baseUrl: string, endpoint: EndpointSpec, verbose: boolean, options?: {
|
|
4
4
|
body?: string | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as viemChains from 'viem/chains';
|
|
2
|
-
import * as Challenge from '
|
|
3
|
-
import * as Constants from '
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import * as Challenge from '../Challenge.js';
|
|
3
|
+
import * as Constants from '../Constants.js';
|
|
4
|
+
import { pc } from '../internal/pc.js';
|
|
5
|
+
import * as x402Header from '../internal/x402/Header.js';
|
|
6
6
|
import { buildUrl, extractRequestBodyFromDiscovery } from './discovery.js';
|
|
7
7
|
import { check, fail, fetchWithTimeout, isValidAddress, isValidIntegerAmount, parseHeaders, skip, warn, } from './helpers.js';
|
|
8
8
|
const allChains = Object.values(viemChains);
|
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
import { buildUrl } from '
|
|
2
|
-
import type { CheckResult, EndpointSpec, PathParameter } from '
|
|
1
|
+
import { buildUrl } from './discovery.js';
|
|
2
|
+
import type { CheckResult, EndpointSpec, PathParameter } from './helpers.js';
|
|
3
3
|
export { buildUrl };
|
|
4
4
|
export type { CheckResult, EndpointSpec, PathParameter };
|
|
5
|
+
/** Label of the passing check that marks a payment as successful when a validator returns only checks. */
|
|
6
|
+
export declare const paymentSuccessLabel = "Payment: successful";
|
|
7
|
+
/** What a {@link PaymentValidator} returns: its checks, and optionally whether the payment succeeded. */
|
|
8
|
+
export type PaymentValidation = CheckResult[] | {
|
|
9
|
+
results: CheckResult[];
|
|
10
|
+
succeeded: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Pays an endpoint and checks the receipt. `mppx validate` supplies one that signs with the
|
|
14
|
+
* CLI's configured account; library callers can pass their own.
|
|
15
|
+
*
|
|
16
|
+
* Return `{ results, succeeded }` to report the outcome directly. A plain array of checks
|
|
17
|
+
* counts as succeeded when it holds a passing check labelled {@link paymentSuccessLabel}.
|
|
18
|
+
*/
|
|
19
|
+
export type PaymentValidator = (baseUrl: string, endpoint: EndpointSpec, verbose: boolean, options: {
|
|
20
|
+
body?: string | undefined;
|
|
21
|
+
query?: string[] | undefined;
|
|
22
|
+
extraHeaders?: string[] | undefined;
|
|
23
|
+
yes?: boolean | undefined;
|
|
24
|
+
silent?: boolean | undefined;
|
|
25
|
+
interactive?: boolean | undefined;
|
|
26
|
+
onResults?: (results: CheckResult[]) => void;
|
|
27
|
+
}) => Promise<PaymentValidation>;
|
|
5
28
|
export type ValidateOptions = {
|
|
6
29
|
url: string;
|
|
7
30
|
endpoint?: string | undefined;
|
|
@@ -14,6 +37,8 @@ export type ValidateOptions = {
|
|
|
14
37
|
interactive?: boolean | undefined;
|
|
15
38
|
discoveryPath?: string | undefined;
|
|
16
39
|
onPaymentResults?: (results: CheckResult[]) => void;
|
|
40
|
+
/** Runs the payment phase. Without it, payment checks are reported as skipped. */
|
|
41
|
+
payment?: PaymentValidator | undefined;
|
|
17
42
|
};
|
|
18
43
|
export type DiscoveryResult = {
|
|
19
44
|
found: boolean;
|
|
@@ -28,6 +53,8 @@ export type EndpointValidationResult = {
|
|
|
28
53
|
challenge: CheckResult[];
|
|
29
54
|
errorHandling: CheckResult[];
|
|
30
55
|
payment: CheckResult[];
|
|
56
|
+
/** Whether the payment succeeded. Absent when the payment phase did not run. */
|
|
57
|
+
paymentSucceeded?: boolean | undefined;
|
|
31
58
|
};
|
|
32
59
|
export type ValidateResult = {
|
|
33
60
|
url: string;
|
package/dist/validation/core.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as viemChains from 'viem/chains';
|
|
2
|
-
import { validateChallenge, validateErrorHandling } from '../cli/validate/challenge.js';
|
|
3
|
-
import { buildUrl, extractEndpointsFromDiscovery, extractRequestBodyFromDiscovery, fetchDiscoveryDoc, validateLlmsDoc, } from '../cli/validate/discovery.js';
|
|
4
|
-
import { isValidIntegerAmount, parseEndpointArg, resolveBodyForEndpoint, } from '../cli/validate/helpers.js';
|
|
5
|
-
import { missingDiscoverySuggestion } from '../cli/validate/messages.js';
|
|
6
|
-
import { validatePaymentFlow } from '../cli/validate/payment.js';
|
|
7
2
|
import { validate as validateDiscoveryDoc } from '../discovery/Validate.js';
|
|
3
|
+
import { validateChallenge, validateErrorHandling } from './challenge.js';
|
|
4
|
+
import { buildUrl, extractEndpointsFromDiscovery, extractRequestBodyFromDiscovery, fetchDiscoveryDoc, validateLlmsDoc, } from './discovery.js';
|
|
5
|
+
import { fail, isValidIntegerAmount, parseEndpointArg, resolveBodyForEndpoint, skip, } from './helpers.js';
|
|
6
|
+
import { missingDiscoverySuggestion } from './messages.js';
|
|
8
7
|
export { buildUrl };
|
|
8
|
+
/** Label of the passing check that marks a payment as successful when a validator returns only checks. */
|
|
9
|
+
export const paymentSuccessLabel = 'Payment: successful';
|
|
9
10
|
/** Streams validation results as each phase completes. */
|
|
10
11
|
export async function* validateStream(options) {
|
|
11
12
|
const baseUrl = options.url.replace(/\/$/, '').replace(/\/openapi\.json$/i, '');
|
|
@@ -68,7 +69,15 @@ export async function* validateStream(options) {
|
|
|
68
69
|
yield { phase: 'errorHandling', endpoint, results: errorResults };
|
|
69
70
|
if (!options.skipPayment && challengeIsValid) {
|
|
70
71
|
const onResults = options.onPaymentResults;
|
|
71
|
-
|
|
72
|
+
if (!options.payment) {
|
|
73
|
+
const results = [
|
|
74
|
+
skip('Payment: not tested', 'no payment validator configured', 'Run `mppx validate` to test payment, or pass `payment` to validate().'),
|
|
75
|
+
];
|
|
76
|
+
onResults?.(results);
|
|
77
|
+
yield { phase: 'payment', endpoint, results, succeeded: false };
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const validation = await options.payment(baseUrl, endpoint, verbose, {
|
|
72
81
|
body: effectiveBody,
|
|
73
82
|
query: options.query,
|
|
74
83
|
extraHeaders: options.headers,
|
|
@@ -77,7 +86,19 @@ export async function* validateStream(options) {
|
|
|
77
86
|
interactive: options.interactive,
|
|
78
87
|
...(onResults && { onResults }),
|
|
79
88
|
});
|
|
80
|
-
|
|
89
|
+
let paymentResults = Array.isArray(validation) ? validation : validation.results;
|
|
90
|
+
const succeeded = Array.isArray(validation)
|
|
91
|
+
? validation.some((r) => r.severity === 'pass' && r.label === paymentSuccessLabel)
|
|
92
|
+
: validation.succeeded;
|
|
93
|
+
// A validator that reports failure without a failing check still fails the run.
|
|
94
|
+
if (!Array.isArray(validation) &&
|
|
95
|
+
!succeeded &&
|
|
96
|
+
!paymentResults.some((r) => r.severity === 'fail')) {
|
|
97
|
+
const failed = fail('Payment: failed', 'the payment validator reported that the payment did not succeed');
|
|
98
|
+
paymentResults = [...paymentResults, failed];
|
|
99
|
+
// Hand the callback its own copy so it cannot change the yielded check.
|
|
100
|
+
onResults?.([{ ...failed }]);
|
|
101
|
+
}
|
|
81
102
|
yield { phase: 'payment', endpoint, results: paymentResults, succeeded };
|
|
82
103
|
}
|
|
83
104
|
}
|
|
@@ -121,8 +142,11 @@ export async function validate(options) {
|
|
|
121
142
|
current.errorHandling = event.results;
|
|
122
143
|
break;
|
|
123
144
|
case 'payment':
|
|
124
|
-
if (current)
|
|
145
|
+
if (current) {
|
|
125
146
|
current.payment = event.results;
|
|
147
|
+
if (options.payment)
|
|
148
|
+
current.paymentSucceeded = event.succeeded;
|
|
149
|
+
}
|
|
126
150
|
break;
|
|
127
151
|
}
|
|
128
152
|
}
|
|
@@ -157,7 +181,11 @@ export async function validate(options) {
|
|
|
157
181
|
}
|
|
158
182
|
if (!discovery)
|
|
159
183
|
throw new Error('Discovery phase did not complete');
|
|
160
|
-
const suggestions = computeSuggestions(endpointResults, discovery, {
|
|
184
|
+
const suggestions = computeSuggestions(endpointResults, discovery, {
|
|
185
|
+
sawTestnet,
|
|
186
|
+
sawMainnet,
|
|
187
|
+
hasPaymentValidator: !!options.payment,
|
|
188
|
+
});
|
|
161
189
|
return {
|
|
162
190
|
url: baseUrl,
|
|
163
191
|
discovery,
|
|
@@ -176,7 +204,10 @@ function computeSuggestions(endpoints, discovery, flags) {
|
|
|
176
204
|
const sawCryptoTestnet = flags.sawTestnet;
|
|
177
205
|
const sawStripeLive = allResults.some((r) => r.label.includes('[stripe]') && r.label.includes('livemode'));
|
|
178
206
|
if (sawCryptoMainnet && !sawCryptoTestnet) {
|
|
179
|
-
|
|
207
|
+
// Only a payment validator (such as the one `mppx validate` injects) provisions a wallet.
|
|
208
|
+
steps.push(flags.hasPaymentValidator
|
|
209
|
+
? 'Validate your testnet server to test without real funds (Tempo wallets are automatically provisioned).'
|
|
210
|
+
: 'Validate your testnet server to test without real funds. Run `mppx validate` to test payment with an automatically provisioned Tempo wallet.');
|
|
180
211
|
}
|
|
181
212
|
else if (sawCryptoTestnet && !sawCryptoMainnet) {
|
|
182
213
|
steps.push('Validate your mainnet server to confirm real payments work end-to-end.');
|