mppx 0.18.0 → 0.19.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/CHANGELOG.md +39 -0
- package/dist/Currency.d.ts +59 -0
- package/dist/Currency.js +60 -0
- package/dist/Errors.d.ts +24 -4
- package/dist/Errors.js +28 -10
- package/dist/cli/cli.js +135 -135
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/plugins/tempo.js +13 -1
- package/dist/client/internal/Fetch.d.ts +5 -0
- package/dist/client/internal/Fetch.js +7 -0
- package/dist/cloudflare/ChannelStore.d.ts +1 -2
- package/dist/cloudflare/ChannelStore.js +14 -20
- package/dist/cloudflare/Channels.d.ts +20 -2
- package/dist/cloudflare/Channels.js +47 -4
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/discovery/Discovery.d.ts +116 -9
- package/dist/discovery/Discovery.js +169 -0
- package/dist/evm/server/Charge.js +2 -3
- package/dist/evm/server/Methods.d.ts +1 -1
- package/dist/evm/server/Methods.js +3 -2
- package/dist/extensions/identity/Types.d.ts +26 -0
- package/dist/extensions/identity/attestation/Token.d.ts +6 -4
- package/dist/extensions/identity/attestation/Token.js +11 -5
- package/dist/extensions/identity/email-otp/client/index.js +4 -4
- package/dist/extensions/identity/index.d.ts +6 -0
- package/dist/extensions/identity/index.js +6 -0
- package/dist/extensions/identity/internal/HttpMessageSignature.d.ts +2 -2
- package/dist/extensions/identity/internal/HttpMessageSignature.js +13 -10
- package/dist/extensions/identity/{web-bot-auth/internal → internal}/JwkThumbprint.js +1 -1
- package/dist/extensions/identity/internal/Signer.d.ts +20 -0
- package/dist/extensions/identity/internal/Signer.js +94 -0
- package/dist/extensions/identity/link/Constants.d.ts +102 -0
- package/dist/extensions/identity/link/Constants.js +16 -0
- package/dist/extensions/identity/link/client/index.d.ts +80 -0
- package/dist/extensions/identity/link/client/index.js +211 -0
- package/dist/extensions/identity/link/index.d.ts +12 -0
- package/dist/extensions/identity/link/index.js +12 -0
- package/dist/extensions/identity/link/server/index.d.ts +124 -0
- package/dist/extensions/identity/link/server/index.js +518 -0
- package/dist/extensions/identity/persona/Constants.d.ts +24 -0
- package/dist/extensions/identity/persona/Constants.js +24 -0
- package/dist/extensions/identity/persona/Did.d.ts +24 -0
- package/dist/extensions/identity/persona/Did.js +24 -0
- package/dist/extensions/identity/persona/Types.d.ts +21 -0
- package/dist/extensions/identity/persona/Types.js +2 -0
- package/dist/extensions/identity/persona/index.d.ts +10 -0
- package/dist/extensions/identity/persona/index.js +9 -0
- package/dist/extensions/identity/persona/server/index.d.ts +152 -0
- package/dist/extensions/identity/persona/server/index.js +263 -0
- package/dist/extensions/identity/tap/client/index.d.ts +6 -2
- package/dist/extensions/identity/tap/client/index.js +2 -0
- package/dist/extensions/identity/tempo/Constants.d.ts +14 -0
- package/dist/extensions/identity/tempo/Constants.js +14 -0
- package/dist/extensions/identity/tempo/Types.d.ts +31 -0
- package/dist/extensions/identity/tempo/Types.js +2 -0
- package/dist/extensions/identity/tempo/client/index.d.ts +34 -0
- package/dist/extensions/identity/tempo/client/index.js +60 -0
- package/dist/extensions/identity/tempo/index.d.ts +5 -0
- package/dist/extensions/identity/tempo/index.js +4 -0
- package/dist/extensions/identity/tempo/internal/Jwt.d.ts +36 -0
- package/dist/extensions/identity/tempo/internal/Jwt.js +114 -0
- package/dist/extensions/identity/tempo/server/index.d.ts +65 -0
- package/dist/extensions/identity/tempo/server/index.js +247 -0
- package/dist/extensions/identity/web-bot-auth/client/index.d.ts +6 -4
- package/dist/extensions/identity/web-bot-auth/client/index.js +7 -5
- package/dist/extensions/identity/web-bot-auth/server/index.js +1 -1
- package/dist/extensions/identity/world/Constants.d.ts +50 -0
- package/dist/extensions/identity/world/Constants.js +50 -0
- package/dist/extensions/identity/world/Types.d.ts +52 -0
- package/dist/extensions/identity/world/Types.js +2 -0
- package/dist/extensions/identity/world/client/index.d.ts +103 -0
- package/dist/extensions/identity/world/client/index.js +208 -0
- package/dist/extensions/identity/world/index.d.ts +6 -0
- package/dist/extensions/identity/world/index.js +5 -0
- package/dist/extensions/identity/world/internal/Idp.d.ts +50 -0
- package/dist/extensions/identity/world/internal/Idp.js +265 -0
- package/dist/extensions/identity/world/issuer/index.d.ts +120 -0
- package/dist/extensions/identity/world/issuer/index.js +520 -0
- package/dist/extensions/identity/world/server/index.d.ts +49 -0
- package/dist/extensions/identity/world/server/index.js +63 -0
- package/dist/identity/Headers.d.ts +6 -1
- package/dist/identity/Headers.js +11 -1
- package/dist/identity/Server.js +2 -0
- package/dist/identity/Types.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/proxy/internal/Headers.js +4 -4
- package/dist/server/Mppx.js +6 -2
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/client/Charge.d.ts +11 -8
- package/dist/tempo/client/Charge.js +85 -18
- package/dist/tempo/index.d.ts +4 -0
- package/dist/tempo/index.js +4 -0
- package/dist/tempo/internal/auto-swap.d.ts +6 -5
- package/dist/tempo/internal/auto-swap.js +17 -2
- package/dist/tempo/internal/currencies.d.ts +5 -4
- package/dist/tempo/internal/currencies.js +13 -9
- package/dist/tempo/internal/defaults.d.ts +7 -0
- package/dist/tempo/internal/defaults.js +7 -0
- package/dist/tempo/internal/fee-payer.js +8 -2
- package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
- package/dist/tempo/internal/machine-token-charge.js +82 -1
- package/dist/tempo/internal/zone.d.ts +27 -0
- package/dist/tempo/internal/zone.js +54 -7
- package/dist/tempo/server/Charge.js +59 -2
- package/dist/tempo/server/Methods.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/transport.d.ts +1 -1
- package/dist/tempo/server/internal/transport.js +9 -16
- package/dist/tempo/session/client/CredentialState.js +31 -0
- package/dist/tempo/session/client/Session.d.ts +12 -6
- package/dist/tempo/session/client/Session.js +64 -18
- package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
- package/dist/tempo/session/server/ChannelStore.js +58 -8
- package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
- package/dist/tempo/session/server/CloseSupervisor.js +110 -12
- package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
- package/dist/tempo/session/server/CredentialVerification.js +6 -32
- package/dist/tempo/session/server/Session.js +6 -3
- package/dist/tempo/session/server/Settlement.d.ts +7 -0
- package/dist/tempo/session/server/Settlement.js +36 -6
- package/dist/tempo/session/server/Sse.d.ts +2 -0
- package/dist/tempo/session/server/Sse.js +12 -12
- package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
- package/dist/tempo/subscription/KeyAuthorization.js +1 -1
- package/dist/x402/Assets.d.ts +14 -5
- package/dist/x402/Assets.js +11 -16
- package/package.json +23 -3
- /package/dist/extensions/identity/{web-bot-auth/internal → internal}/JwkThumbprint.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# mppx
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f2c69d5: Added remote signers (a cloud KMS, an HSM or Turnkey) to the Web Bot Auth and TAP client provers, `Attestation.sign` and the World ID issuer, through one `SigningKey` type: a `CryptoKeyPair` or a `Signer` (`{ publicKey, sign({ payload }) }`). mppx checks each remote signature against `publicKey` before it uses it.
|
|
8
|
+
|
|
9
|
+
Breaking: these take a key pair instead of a private key alone. `WebBotAuth.Client.prover` no longer takes `keyId`: it derives the keyid from the public key. `Attestation.sign`'s `keyId` is optional and defaults to the public key's RFC 7638 thumbprint.
|
|
10
|
+
|
|
11
|
+
```diff
|
|
12
|
+
- WebBotAuth.Client.prover({ key: keys.privateKey, keyId, scope, signatureAgent })
|
|
13
|
+
+ WebBotAuth.Client.prover({ key: keys, scope, signatureAgent })
|
|
14
|
+
- Tap.Client.prover({ key: keys.privateKey, keyId, intent, scope })
|
|
15
|
+
+ Tap.Client.prover({ key: keys, keyId, intent, scope })
|
|
16
|
+
- Attestation.sign(claims, { key: keys.privateKey, keyId })
|
|
17
|
+
+ Attestation.sign(claims, { key: keys })
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 602682c: Fixed HTTP message signing to check a request's signature labels, the new label and a consumed body before it calls a remote signer, so a request it refuses no longer spends a signing operation.
|
|
23
|
+
- f253219: Added `mppx/extensions/identity/tempo`: `TempoId.Server.create` verifies Tempo ID access tokens offline, with DPoP proofs, and returns a payment check that requires a `tempo` payment from a Tempo Account the token grants to the app. Without `clientId` it accepts any app's token. Its `allow` option decides by the user's ID, app, accounts, compliance states, and the email address of an ID token the client sends. `TempoId.Client.prover` sends the access token, a DPoP proof per request, and the optional ID token.
|
|
24
|
+
- 7645703: Added `mppx/extensions/identity/world`: `World.Server.verifier` requires a human verified with World ID, as an `Identity-Attestation` of type `world-id` from a World ID issuer, `World.Issuer` runs that issuer as a shared service or inside an app, and `World.Client.prover` runs the issuer's device flow, shows the human World IdP's approval link and sends the attestation.
|
|
25
|
+
- 3233543: Fixed paying from a Zone whose RPC redacts the outbox's `WithdrawalRequested` event from receipts. The client now derives the sender tag from the outbox's `lastFallbackNonce` and matches the portal's `WithdrawalProcessed` event on Tempo. A failed read of the sender tag is retried with the Challenge, without withdrawing again, and `ZoneSettlementPendingError` has `senderTags`, every candidate tag, with `senderTag` `undefined` when more than one remains.
|
|
26
|
+
|
|
27
|
+
## 0.18.1
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 7663d93: Fixed Cloudflare settlement recovery for vouchers larger than recorded usage, capturing only the amount owed. Added a settlement backfill for channels left unscheduled before upgrading.
|
|
32
|
+
- 2a00add: Fixed automatic session settlement retries and preserved prepaid stream delivery during channel closure. Fixed mixed-case channel IDs in settlement backfills.
|
|
33
|
+
- e86c670: Added `listOperations` to `mppx/discovery`, which lists a discovery document's operations with typed offers and JSON request schemas. Typed the offers `PaymentInfo` returns.
|
|
34
|
+
- 066a75b: Added `mppx/extensions/identity/link`: server verifiers and client provers for Link agent identity attestations and Link-signed claims, such as a verified email. Added `Identity.Verifier.authorization`, which makes a route refuse a server without `requiresAuth: true`, and stopped proxies from forwarding `Identity-Presentation` headers and upstream identity challenges.
|
|
35
|
+
- 4071a6c: Added MACH onramp links to insufficient-balance errors. `Tempo.machineTokenFundingUrl` builds the Tempo Wallet link that buys MACH, and `PaymentError` gained an optional `fundingUrl`, serialized as a Problem Details extension member. On Tempo mainnet, the `tempo.charge` client now throws `InsufficientBalanceError` with the link when a MACH-enabled charge can't be paid from MACH or the charge currency, the session client does the same for a MACH channel deposit, servers link MACH payments rejected for a low MACH balance, and the `mppx` CLI treats a MACH-enabled charge as payable from a MACH balance.
|
|
36
|
+
- ee48ef6: Removed the package size limits from the package check; it still reports the sizes.
|
|
37
|
+
- 40b9535: Prevented automatic payments during email OTP requests through identity-wrapped fetch clients. Added `Fetch.withoutPayment` to explicitly disable payments for a request.
|
|
38
|
+
- dd571b3: Added `mppx/extensions/identity/persona`: `Persona.Server.create` starts Persona inquiries and returns a payment check and a request-stage verifier that require an approved inquiry, with an onboarding link on rejection and an optional approval cache. `Persona.Server.verifyWallet` links a wallet to a person before KYC, and `Persona.did` builds a wallet's reference ID.
|
|
39
|
+
- 6e32317: Fixed composed subscription routes retaining request-derived dispatch state and accepting overlapping identity policies.
|
|
40
|
+
- 75aee4b: Added the `Currency` module and accepted `viem/tokens` tokens, chain-indexed (`ousd`) or resolved to one chain (`ousd(4217)`), everywhere a currency is configured: Tempo charge and session client `currencies`, `autoSwap.tokenIn`, Tempo server `currencies`, and EVM and x402 `currencies`, with token decimals used for `maxAmount`, `maxDeposit` and `topUpAmount`.
|
|
41
|
+
|
|
3
42
|
## 0.18.0
|
|
4
43
|
|
|
5
44
|
### Minor Changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Address, ResolvedToken } from 'viem';
|
|
2
|
+
import type { Token } from 'viem/tokens';
|
|
3
|
+
/**
|
|
4
|
+
* A currency accepted anywhere mppx takes one: a token address, a chain-indexed token from
|
|
5
|
+
* `viem/tokens` (such as `ousd`), or a token resolved to one chain (such as `ousd(4217)`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { ousd, usdc } from 'viem/tokens'
|
|
10
|
+
*
|
|
11
|
+
* const currencies = [ousd, usdc(8453), '0x20c0000000000000000000000000000000000000']
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Currency = Address | Token | ResolvedToken;
|
|
15
|
+
/** A currency resolved to one chain. `decimals` is `undefined` for an address configured without decimals. */
|
|
16
|
+
export type Resolved = Omit<ResolvedToken, 'decimals'> & {
|
|
17
|
+
decimals: number | undefined;
|
|
18
|
+
};
|
|
19
|
+
/** Returns true when a value is a chain-indexed token from `viem/tokens`. */
|
|
20
|
+
export declare function isToken(value: unknown): value is Token;
|
|
21
|
+
/** Returns true when a value is a token resolved to one chain, such as `ousd(4217)`. */
|
|
22
|
+
export declare function isResolvedToken(value: unknown): value is ResolvedToken;
|
|
23
|
+
/** Returns the chain a currency is bound to: a resolved token's `chainId`, otherwise `undefined`. */
|
|
24
|
+
export declare function chainIdOf(currency: Currency): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a currency for `chainId`: a token by its addresses, a resolved token only on its own
|
|
27
|
+
* chain, and an address on any chain with `decimals`. Returns `undefined` when the currency has no
|
|
28
|
+
* address on `chainId`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolve(currency: Currency, options: resolve.Options): Resolved | undefined;
|
|
31
|
+
export declare namespace resolve {
|
|
32
|
+
type Options = {
|
|
33
|
+
/** Chain to resolve the currency for. */
|
|
34
|
+
chainId: number;
|
|
35
|
+
/** Decimals of an address currency. Tokens carry their own. */
|
|
36
|
+
decimals?: number | undefined;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the first currency in `currencies` that is `address`, compared case-insensitively, with
|
|
41
|
+
* its decimals: an address as is, and a token on `chainId`, or on any chain it lists when
|
|
42
|
+
* `chainId` is omitted.
|
|
43
|
+
*/
|
|
44
|
+
export declare function find(currencies: readonly Currency[], address: string, options?: find.Options): find.ReturnType | undefined;
|
|
45
|
+
export declare namespace find {
|
|
46
|
+
type Options = {
|
|
47
|
+
/** Chain the address is on. When omitted, tokens match on any chain they list. */
|
|
48
|
+
chainId?: number | undefined;
|
|
49
|
+
/** Decimals of an address currency. Tokens carry their own. */
|
|
50
|
+
decimals?: number | undefined;
|
|
51
|
+
};
|
|
52
|
+
type ReturnType = {
|
|
53
|
+
/** The matching currency. */
|
|
54
|
+
currency: Currency;
|
|
55
|
+
/** Its decimals: the token's, or the configured `decimals` for an address. */
|
|
56
|
+
decimals: number | undefined;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=Currency.d.ts.map
|
package/dist/Currency.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Returns true when a value is a chain-indexed token from `viem/tokens`. */
|
|
2
|
+
export function isToken(value) {
|
|
3
|
+
return (typeof value === 'function' &&
|
|
4
|
+
typeof value.addresses === 'object' &&
|
|
5
|
+
typeof value.decimals === 'number');
|
|
6
|
+
}
|
|
7
|
+
/** Returns true when a value is a token resolved to one chain, such as `ousd(4217)`. */
|
|
8
|
+
export function isResolvedToken(value) {
|
|
9
|
+
if (typeof value !== 'object' || value === null)
|
|
10
|
+
return false;
|
|
11
|
+
const { address, chainId, decimals } = value;
|
|
12
|
+
return typeof address === 'string' && typeof chainId === 'number' && typeof decimals === 'number';
|
|
13
|
+
}
|
|
14
|
+
/** Returns the chain a currency is bound to: a resolved token's `chainId`, otherwise `undefined`. */
|
|
15
|
+
export function chainIdOf(currency) {
|
|
16
|
+
return isResolvedToken(currency) ? currency.chainId : undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a currency for `chainId`: a token by its addresses, a resolved token only on its own
|
|
20
|
+
* chain, and an address on any chain with `decimals`. Returns `undefined` when the currency has no
|
|
21
|
+
* address on `chainId`.
|
|
22
|
+
*/
|
|
23
|
+
export function resolve(currency, options) {
|
|
24
|
+
const { chainId, decimals } = options;
|
|
25
|
+
if (typeof currency === 'string')
|
|
26
|
+
return { address: currency, chainId, decimals };
|
|
27
|
+
if (isToken(currency)) {
|
|
28
|
+
if (!currency.addresses[chainId])
|
|
29
|
+
return undefined;
|
|
30
|
+
return currency(chainId);
|
|
31
|
+
}
|
|
32
|
+
if (currency.chainId !== chainId)
|
|
33
|
+
return undefined;
|
|
34
|
+
return currency;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the first currency in `currencies` that is `address`, compared case-insensitively, with
|
|
38
|
+
* its decimals: an address as is, and a token on `chainId`, or on any chain it lists when
|
|
39
|
+
* `chainId` is omitted.
|
|
40
|
+
*/
|
|
41
|
+
export function find(currencies, address, options = {}) {
|
|
42
|
+
const { chainId, decimals } = options;
|
|
43
|
+
const matches = (value) => value.toLowerCase() === address.toLowerCase();
|
|
44
|
+
for (const currency of currencies) {
|
|
45
|
+
if (typeof currency === 'string') {
|
|
46
|
+
if (matches(currency))
|
|
47
|
+
return { currency, decimals };
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const candidates = chainId !== undefined
|
|
51
|
+
? [resolve(currency, { chainId })]
|
|
52
|
+
: isToken(currency)
|
|
53
|
+
? Object.keys(currency.addresses).map((id) => resolve(currency, { chainId: Number(id) }))
|
|
54
|
+
: [currency];
|
|
55
|
+
if (candidates.some((candidate) => candidate && matches(candidate.address)))
|
|
56
|
+
return { currency, decimals: currency.decimals };
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=Currency.js.map
|
package/dist/Errors.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export declare abstract class PaymentError extends Error {
|
|
|
19
19
|
readonly status: number;
|
|
20
20
|
/** Actionable hint for resolving the error (RFC 9457 extension member). */
|
|
21
21
|
readonly hint: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Page where the payer can get the funds this payment needs, such as the MACH onramp
|
|
24
|
+
* (RFC 9457 extension member).
|
|
25
|
+
*/
|
|
26
|
+
readonly fundingUrl: string | undefined;
|
|
22
27
|
protected constructor(message: string, options?: PaymentError.Options);
|
|
23
28
|
/** Converts the error to RFC 9457 Problem Details format. */
|
|
24
29
|
toProblemDetails(challengeId?: string): PaymentError.ProblemDetails;
|
|
@@ -28,6 +33,8 @@ export declare namespace PaymentError {
|
|
|
28
33
|
/** Underlying error. Never serialized into Problem Details. */
|
|
29
34
|
cause?: unknown;
|
|
30
35
|
details?: Record<string, unknown> | undefined;
|
|
36
|
+
/** Page where the payer can get the funds this payment needs. */
|
|
37
|
+
fundingUrl?: string | undefined;
|
|
31
38
|
};
|
|
32
39
|
type ProblemDetails = {
|
|
33
40
|
/** RFC 9457 Problem Details type URI. */
|
|
@@ -42,6 +49,8 @@ export declare namespace PaymentError {
|
|
|
42
49
|
details?: Readonly<Record<string, unknown>>;
|
|
43
50
|
/** Actionable hint for resolving the error (RFC 9457 extension member). */
|
|
44
51
|
hint?: string;
|
|
52
|
+
/** Page where the payer can get the funds this payment needs (RFC 9457 extension member). */
|
|
53
|
+
fundingUrl?: string;
|
|
45
54
|
/** Associated challenge ID, if applicable. */
|
|
46
55
|
challengeId?: string;
|
|
47
56
|
};
|
|
@@ -94,6 +103,8 @@ export declare namespace VerificationFailedError {
|
|
|
94
103
|
type Options = {
|
|
95
104
|
/** Safe method-specific diagnostic context. */
|
|
96
105
|
details?: Record<string, unknown> | undefined;
|
|
106
|
+
/** Page where the payer can get the funds the payment lacked. */
|
|
107
|
+
fundingUrl?: string | undefined;
|
|
97
108
|
/** Reason verification failed (e.g., "invalid signature", "insufficient amount"). */
|
|
98
109
|
reason?: string;
|
|
99
110
|
};
|
|
@@ -266,14 +277,19 @@ export declare namespace PaymentSimulationError {
|
|
|
266
277
|
* before the client stopped waiting. The withdrawal cannot be undone and may still settle.
|
|
267
278
|
*
|
|
268
279
|
* Retry the same challenge with the same `tempo.charge` client to resume waiting without
|
|
269
|
-
* withdrawing again, or find the settlement with `senderTag` on the Zone's portal.
|
|
280
|
+
* withdrawing again, or find the settlement with `senderTag` (or one of `senderTags`) on the Zone's portal.
|
|
270
281
|
*/
|
|
271
282
|
export declare class ZoneSettlementPendingError extends Error {
|
|
272
283
|
readonly name = "ZoneSettlementPendingError";
|
|
273
284
|
/** ID of the challenge the withdrawal pays. */
|
|
274
285
|
readonly challengeId: string;
|
|
275
|
-
/**
|
|
276
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Sender tag of the withdrawal, as the portal's `WithdrawalProcessed` event carries it.
|
|
288
|
+
* `undefined` when a Zone RPC hid it and more than one candidate remains: see `senderTags`.
|
|
289
|
+
*/
|
|
290
|
+
readonly senderTag: `0x${string}` | undefined;
|
|
291
|
+
/** Sender tags the withdrawal may carry: its tag alone when known, else every candidate. */
|
|
292
|
+
readonly senderTags: readonly `0x${string}`[];
|
|
277
293
|
/** ID of the Zone the withdrawal left. */
|
|
278
294
|
readonly zoneId: number;
|
|
279
295
|
constructor(options: ZoneSettlementPendingError.Options);
|
|
@@ -285,7 +301,9 @@ export declare namespace ZoneSettlementPendingError {
|
|
|
285
301
|
/** ID of the challenge the withdrawal pays. */
|
|
286
302
|
challengeId: string;
|
|
287
303
|
/** Sender tag of the withdrawal. */
|
|
288
|
-
senderTag
|
|
304
|
+
senderTag?: `0x${string}` | undefined;
|
|
305
|
+
/** Sender tags the withdrawal may carry, when a Zone RPC hid its tag. */
|
|
306
|
+
senderTags?: readonly `0x${string}`[] | undefined;
|
|
289
307
|
/** ID of the Zone the withdrawal left. */
|
|
290
308
|
zoneId: number;
|
|
291
309
|
};
|
|
@@ -381,6 +399,8 @@ export declare class InsufficientBalanceError extends PaymentError {
|
|
|
381
399
|
}
|
|
382
400
|
export declare namespace InsufficientBalanceError {
|
|
383
401
|
type Options = {
|
|
402
|
+
/** Page where the payer can get the funds, such as the MACH onramp. */
|
|
403
|
+
fundingUrl?: string | undefined;
|
|
384
404
|
/** Reason for insufficient balance. */
|
|
385
405
|
reason?: string;
|
|
386
406
|
};
|
package/dist/Errors.js
CHANGED
|
@@ -4,6 +4,10 @@ export const Hints = {
|
|
|
4
4
|
malformedCredential: 'Use a supported wallet to construct valid credentials for one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md',
|
|
5
5
|
methodUnsupported: 'Use a supported wallet to pay for this resource using one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md',
|
|
6
6
|
};
|
|
7
|
+
/** Appends where to get funds to an error message. */
|
|
8
|
+
function withFundingUrl(message, fundingUrl) {
|
|
9
|
+
return fundingUrl ? `${message} Add funds at ${fundingUrl}` : message;
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Base class for all payment-related errors.
|
|
9
13
|
*/
|
|
@@ -14,9 +18,15 @@ export class PaymentError extends Error {
|
|
|
14
18
|
status = 402;
|
|
15
19
|
/** Actionable hint for resolving the error (RFC 9457 extension member). */
|
|
16
20
|
hint;
|
|
21
|
+
/**
|
|
22
|
+
* Page where the payer can get the funds this payment needs, such as the MACH onramp
|
|
23
|
+
* (RFC 9457 extension member).
|
|
24
|
+
*/
|
|
25
|
+
fundingUrl;
|
|
17
26
|
constructor(message, options = {}) {
|
|
18
27
|
super(message);
|
|
19
28
|
this.details = options.details;
|
|
29
|
+
this.fundingUrl = options.fundingUrl;
|
|
20
30
|
// Defined manually (non-enumerable, like native `cause`) so consumers on pre-ES2022 libs still typecheck.
|
|
21
31
|
if (options.cause !== undefined)
|
|
22
32
|
Object.defineProperty(this, 'cause', {
|
|
@@ -34,6 +44,7 @@ export class PaymentError extends Error {
|
|
|
34
44
|
detail: this.message,
|
|
35
45
|
...(this.details && Object.keys(this.details).length > 0 && { details: this.details }),
|
|
36
46
|
...(this.hint && { hint: this.hint }),
|
|
47
|
+
...(this.fundingUrl && { fundingUrl: this.fundingUrl }),
|
|
37
48
|
...(challengeId && { challengeId }),
|
|
38
49
|
};
|
|
39
50
|
}
|
|
@@ -75,10 +86,8 @@ export class VerificationFailedError extends PaymentError {
|
|
|
75
86
|
title = 'Verification Failed';
|
|
76
87
|
type = 'https://paymentauth.org/problems/verification-failed';
|
|
77
88
|
constructor(options = {}) {
|
|
78
|
-
const { details, reason } = options;
|
|
79
|
-
super(reason ? `Payment verification failed: ${reason}.` : 'Payment verification failed.', {
|
|
80
|
-
details,
|
|
81
|
-
});
|
|
89
|
+
const { details, fundingUrl, reason } = options;
|
|
90
|
+
super(withFundingUrl(reason ? `Payment verification failed: ${reason}.` : 'Payment verification failed.', fundingUrl), { details, fundingUrl });
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
/**
|
|
@@ -222,21 +231,30 @@ export class PaymentSimulationError extends Error {
|
|
|
222
231
|
* before the client stopped waiting. The withdrawal cannot be undone and may still settle.
|
|
223
232
|
*
|
|
224
233
|
* Retry the same challenge with the same `tempo.charge` client to resume waiting without
|
|
225
|
-
* withdrawing again, or find the settlement with `senderTag` on the Zone's portal.
|
|
234
|
+
* withdrawing again, or find the settlement with `senderTag` (or one of `senderTags`) on the Zone's portal.
|
|
226
235
|
*/
|
|
227
236
|
export class ZoneSettlementPendingError extends Error {
|
|
228
237
|
name = 'ZoneSettlementPendingError';
|
|
229
238
|
/** ID of the challenge the withdrawal pays. */
|
|
230
239
|
challengeId;
|
|
231
|
-
/**
|
|
240
|
+
/**
|
|
241
|
+
* Sender tag of the withdrawal, as the portal's `WithdrawalProcessed` event carries it.
|
|
242
|
+
* `undefined` when a Zone RPC hid it and more than one candidate remains: see `senderTags`.
|
|
243
|
+
*/
|
|
232
244
|
senderTag;
|
|
245
|
+
/** Sender tags the withdrawal may carry: its tag alone when known, else every candidate. */
|
|
246
|
+
senderTags;
|
|
233
247
|
/** ID of the Zone the withdrawal left. */
|
|
234
248
|
zoneId;
|
|
235
249
|
constructor(options) {
|
|
236
|
-
const { cause, challengeId,
|
|
237
|
-
|
|
250
|
+
const { cause, challengeId, zoneId } = options;
|
|
251
|
+
const senderTags = options.senderTags ?? (options.senderTag ? [options.senderTag] : []);
|
|
252
|
+
const senderTag = senderTags.length === 1 ? senderTags[0] : undefined;
|
|
253
|
+
const withdrawal = senderTag ?? `with sender tag ${senderTags.join(' or ')}`;
|
|
254
|
+
super(`Zone ${zoneId} withdrawal ${withdrawal} for challenge "${challengeId}" has not settled on Tempo yet. Retry the challenge to resume waiting instead of paying again.`);
|
|
238
255
|
this.challengeId = challengeId;
|
|
239
256
|
this.senderTag = senderTag;
|
|
257
|
+
this.senderTags = senderTags;
|
|
240
258
|
this.zoneId = zoneId;
|
|
241
259
|
// Defined manually (non-enumerable, like native `cause`) so consumers on pre-ES2022 libs still typecheck.
|
|
242
260
|
if (cause !== undefined)
|
|
@@ -319,8 +337,8 @@ export class InsufficientBalanceError extends PaymentError {
|
|
|
319
337
|
status = 402;
|
|
320
338
|
type = 'https://paymentauth.org/problems/session/insufficient-balance';
|
|
321
339
|
constructor(options = {}) {
|
|
322
|
-
const { reason } = options;
|
|
323
|
-
super(reason ? `Insufficient balance: ${reason}.` : 'Insufficient balance.');
|
|
340
|
+
const { fundingUrl, reason } = options;
|
|
341
|
+
super(withFundingUrl(reason ? `Insufficient balance: ${reason}.` : 'Insufficient balance.', fundingUrl), { fundingUrl });
|
|
324
342
|
}
|
|
325
343
|
}
|
|
326
344
|
/**
|