mppx 0.19.1 → 0.20.1

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cli/cli.js +3 -3
  3. package/dist/cli/plugins/index.js +1 -1
  4. package/dist/evm/server/Charge.js +104 -0
  5. package/dist/extensions/identity/attestation/Issuer.d.ts +91 -0
  6. package/dist/extensions/identity/attestation/Issuer.js +159 -0
  7. package/dist/extensions/identity/attestation/Token.js +7 -0
  8. package/dist/extensions/identity/attestation/Types.d.ts +31 -3
  9. package/dist/extensions/identity/attestation/index.d.ts +3 -1
  10. package/dist/extensions/identity/attestation/index.js +3 -1
  11. package/dist/extensions/identity/erc8004/Constants.d.ts +20 -0
  12. package/dist/extensions/identity/erc8004/Constants.js +20 -0
  13. package/dist/extensions/identity/erc8004/Types.d.ts +11 -0
  14. package/dist/extensions/identity/erc8004/Types.js +2 -0
  15. package/dist/extensions/identity/erc8004/client/index.d.ts +33 -0
  16. package/dist/extensions/identity/erc8004/client/index.js +33 -0
  17. package/dist/extensions/identity/erc8004/index.d.ts +5 -0
  18. package/dist/extensions/identity/erc8004/index.js +4 -0
  19. package/dist/extensions/identity/erc8004/internal/Agent.d.ts +21 -0
  20. package/dist/extensions/identity/erc8004/internal/Agent.js +24 -0
  21. package/dist/extensions/identity/erc8004/server/index.d.ts +44 -0
  22. package/dist/extensions/identity/erc8004/server/index.js +178 -0
  23. package/dist/extensions/identity/index.d.ts +2 -0
  24. package/dist/extensions/identity/index.js +2 -0
  25. package/dist/extensions/identity/tempo/Constants.d.ts +4 -0
  26. package/dist/extensions/identity/tempo/Constants.js +4 -0
  27. package/dist/extensions/identity/tempo/client/index.d.ts +63 -0
  28. package/dist/extensions/identity/tempo/client/index.js +151 -0
  29. package/dist/extensions/identity/tempo/index.d.ts +1 -0
  30. package/dist/extensions/identity/tempo/index.js +1 -0
  31. package/dist/extensions/identity/tempo/issuer/index.d.ts +83 -0
  32. package/dist/extensions/identity/tempo/issuer/index.js +183 -0
  33. package/dist/identity/Headers.d.ts +1 -1
  34. package/dist/identity/Headers.js +2 -0
  35. package/dist/internal/version.d.ts +2 -2
  36. package/dist/internal/version.js +1 -1
  37. package/dist/proxy/Proxy.js +47 -9
  38. package/dist/proxy/internal/Headers.js +1 -0
  39. package/dist/server/Mppx.js +28 -1
  40. package/dist/tempo/server/internal/html.gen.js +1 -1
  41. package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
  42. package/dist/tempo/session/server/CredentialVerification.js +44 -0
  43. package/dist/tempo/session/server/MeteredStream.d.ts +2 -0
  44. package/dist/tempo/session/server/MeteredStream.js +11 -0
  45. package/dist/tempo/session/server/Sse.js +9 -4
  46. package/dist/x402/Siwx.d.ts +270 -0
  47. package/dist/x402/Siwx.js +458 -0
  48. package/dist/x402/Types.d.ts +6 -6
  49. package/dist/x402/Types.js +1 -1
  50. package/dist/x402/index.d.ts +1 -0
  51. package/dist/x402/index.js +1 -0
  52. package/dist/x402/server/EvmCharge.d.ts +7 -0
  53. package/dist/x402/server/EvmCharge.js +14 -1
  54. package/package.json +5 -1
@@ -34,6 +34,8 @@ export declare function assertCredentialSourceCanSpend(parameters: {
34
34
  channel: Pick<ChannelStore.State, 'authorizedSigner' | 'payer'>;
35
35
  source?: string | undefined;
36
36
  }): void;
37
+ /** Binds an opening payment to the payer authenticated by its signed transaction. */
38
+ export declare function assertCredentialSourceIsPayer(source: string | undefined, chainId: number, payer: Address, serializedTransaction: Hex, client: Chain.TransactionClient): Promise<void>;
37
39
  /** Shared action and channel fields required on every session credential payload. */
38
40
  export type SessionCredentialPayloadHeader = {
39
41
  /** Credential action discriminator. */
@@ -1,4 +1,6 @@
1
+ import { TxEnvelopeTempo } from 'ox/tempo';
1
2
  import { isAddress, isAddressEqual, zeroAddress, } from 'viem';
3
+ import { Actions } from 'viem/tempo';
2
4
  import { AmountExceedsDepositError, ChannelClosedError, ChannelNotFoundError, DeltaTooSmallError, InsufficientBalanceError, InvalidSignatureError, VerificationFailedError, } from '../../../Errors.js';
3
5
  import * as Chain from '../precompile/Chain.js';
4
6
  import { readChannelClosedReceiptFields } from '../precompile/Chain.js';
@@ -8,6 +10,7 @@ import * as Voucher from '../precompile/Voucher.js';
8
10
  import * as ChannelStore from './ChannelStore.js';
9
11
  import { getChallengePaymentFields } from './RequestState.js';
10
12
  import { assertSettlementSender, getClientAccount, maybeSettleScheduled, reportSessionSettlementFailure, trackSendAttempts, } from './Settlement.js';
13
+ import { verifiedPayer } from './SponsorshipLimit.js';
11
14
  /** Returns the effective voucher signer for a TIP-1034 descriptor. */
12
15
  export function authorizedSigner(descriptor) {
13
16
  return isAddressEqual(descriptor.authorizedSigner, zeroAddress)
@@ -96,6 +99,45 @@ export function assertCredentialSourceCanSpend(parameters) {
96
99
  reason: 'credential source does not match channel payer or authorized signer',
97
100
  });
98
101
  }
102
+ /** Binds an opening payment to the payer authenticated by its signed transaction. */
103
+ export async function assertCredentialSourceIsPayer(source, chainId, payer, serializedTransaction, client) {
104
+ if (source === undefined)
105
+ return;
106
+ if (!isAddressEqual(readCredentialSourceAddress(source, chainId), payer))
107
+ throw new VerificationFailedError({
108
+ reason: 'credential source does not match transaction payer',
109
+ });
110
+ let valid = false;
111
+ try {
112
+ const signer = verifiedPayer(serializedTransaction);
113
+ const { signature, keyAuthorization } = TxEnvelopeTempo.deserialize(serializedTransaction);
114
+ if (signer && signature?.type !== 'keychain')
115
+ valid = isAddressEqual(signer, payer);
116
+ else if (signer &&
117
+ signature?.type === 'keychain' &&
118
+ isAddressEqual(signature.userAddress, payer)) {
119
+ if (keyAuthorization)
120
+ valid =
121
+ isAddressEqual(signer, payer) &&
122
+ (keyAuthorization.chainId === 0n || keyAuthorization.chainId === BigInt(chainId)) &&
123
+ (keyAuthorization.expiry == null || keyAuthorization.expiry > Date.now() / 1_000);
124
+ else {
125
+ const metadata = await Actions.accessKey.getMetadata(client, {
126
+ account: payer,
127
+ accessKey: signer,
128
+ });
129
+ valid = !metadata.isRevoked && metadata.expiry > BigInt(Math.floor(Date.now() / 1_000));
130
+ }
131
+ }
132
+ }
133
+ catch {
134
+ // Unavailable authorization state cannot authenticate a claimed identity.
135
+ }
136
+ if (!valid)
137
+ throw new VerificationFailedError({
138
+ reason: 'credential source is not authenticated by transaction signature',
139
+ });
140
+ }
99
141
  function readCredentialSourceAddress(source, chainId) {
100
142
  const prefix = `did:pkh:eip155:${chainId}:`;
101
143
  if (!source?.startsWith(prefix))
@@ -302,6 +344,7 @@ async function validateOpenCredential(parameters, payload) {
302
344
  requestAmount: request.amount,
303
345
  });
304
346
  assertSameDescriptor(transaction.descriptor, payload.descriptor);
347
+ await assertCredentialSourceIsPayer(parameters.credentialSource, chainId, transaction.descriptor.payer, payload.transaction, client);
305
348
  if (cumulativeAmount > transaction.openDeposit)
306
349
  throw new AmountExceedsDepositError({ reason: 'voucher amount exceeds open deposit' });
307
350
  const valid = await Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount, signature: payload.signature }, authorizedSigner(transaction.descriptor));
@@ -538,6 +581,7 @@ async function handleOpenCredential(parameters) {
538
581
  requestAmount: request.amount,
539
582
  });
540
583
  assertSameDescriptor(prepared.descriptor, payload.descriptor);
584
+ await assertCredentialSourceIsPayer(parameters.credentialSource, chainId, prepared.descriptor.payer, payload.transaction, client);
541
585
  if (cumulativeAmount > prepared.openDeposit)
542
586
  throw new AmountExceedsDepositError({ reason: 'voucher amount exceeds open deposit' });
543
587
  const valid = await Voucher.verifyVoucher(escrow, chainId, { channelId, cumulativeAmount: cumulativeAmount, signature: payload.signature }, authorizedSigner(prepared.descriptor));
@@ -52,4 +52,6 @@ export type MeteredStreamOptions = {
52
52
  };
53
53
  /** Applies voucher reservation and spend commits to an async session stream. */
54
54
  export declare function meterIterable(options: MeteredStreamOptions): AsyncGenerator<string>;
55
+ /** Whether an automatic source would start billable per-item work before a manual charge. */
56
+ export declare function requiresManualCharge(options: Pick<MeteredStreamOptions, 'generate' | 'tickCost' | 'chargeOnce'>): boolean;
55
57
  //# sourceMappingURL=MeteredStream.d.ts.map
@@ -2,6 +2,8 @@ import { commitReservedCharges, releaseReservedCharges, reserveChargeOrWait } fr
2
2
  /** Applies voucher reservation and spend commits to an async session stream. */
3
3
  export async function* meterIterable(options) {
4
4
  const manual = typeof options.generate === 'function';
5
+ if (requiresManualCharge(options))
6
+ throw new TypeError('Billable per-item streams require a generator that calls stream.charge() before starting work.');
5
7
  let prepaidUnits = options.prepaidUnits ?? 0;
6
8
  const signal = options.signal ?? new AbortController().signal;
7
9
  const reservation = {
@@ -56,6 +58,11 @@ export async function* meterIterable(options) {
56
58
  await options.onChargeCommitted?.(channel);
57
59
  };
58
60
  try {
61
+ if (!manual && options.chargeOnce) {
62
+ await charge();
63
+ await commit();
64
+ charged = true;
65
+ }
59
66
  const iterable = typeof options.generate === 'function'
60
67
  ? options.generate({ charge, signal })
61
68
  : options.generate;
@@ -88,4 +95,8 @@ export async function* meterIterable(options) {
88
95
  await releaseReservedCharges(reservation);
89
96
  }
90
97
  }
98
+ /** Whether an automatic source would start billable per-item work before a manual charge. */
99
+ export function requiresManualCharge(options) {
100
+ return typeof options.generate !== 'function' && options.tickCost > 0n && !options.chargeOnce;
101
+ }
91
102
  //# sourceMappingURL=MeteredStream.js.map
@@ -2,7 +2,7 @@ import * as Constants from '../../../Constants.js';
2
2
  import * as Credential from '../../../Credential.js';
3
3
  import { createSessionReceipt, extractData, formatMessageEvent, formatNeedVoucherEvent, formatReceiptEvent, readSessionChallengeAmount, requireSessionCredentialContext, } from '../precompile/Protocol.js';
4
4
  import * as ChannelStore from './ChannelStore.js';
5
- import { meterIterable, } from './MeteredStream.js';
5
+ import { meterIterable, requiresManualCharge, } from './MeteredStream.js';
6
6
  /** Exposes durable retry information when no refund hook is configured or it fails. */
7
7
  export class PrepaidRefundError extends Error {
8
8
  refund;
@@ -110,10 +110,15 @@ export function serve(options) {
110
110
  throw new Error('prepaidUnits must be a non-negative safe integer');
111
111
  const refundIdempotencyKey = options.refundIdempotencyKey ?? `stream:${globalThis.crypto.randomUUID()}`;
112
112
  ChannelStore.assertIdempotencyOptions({ idempotencyKey: refundIdempotencyKey });
113
- const refundOptions = { ...options, refundIdempotencyKey };
113
+ const rejectedAutomatic = requiresManualCharge(options);
114
+ const refundOptions = {
115
+ ...options,
116
+ autoCreditPrepaid: options.autoCreditPrepaid || rejectedAutomatic,
117
+ refundIdempotencyKey,
118
+ };
114
119
  const clearObligation = () => clearPrepaidRefund(store, channelId, refundIdempotencyKey);
115
120
  const creditFailedDelivery = async () => {
116
- if (!options.autoCreditPrepaid)
121
+ if (!refundOptions.autoCreditPrepaid)
117
122
  return clearObligation();
118
123
  if (undeliveredPrepaidUnits === 0 || tickCost === 0n) {
119
124
  await clearObligation();
@@ -206,7 +211,7 @@ export function serve(options) {
206
211
  .catch(() => { });
207
212
  termination = preparation
208
213
  .catch(() => { })
209
- .then(clearObligation)
214
+ .then(rejectedAutomatic ? creditFailedDelivery : clearObligation)
210
215
  .finally(() => {
211
216
  try {
212
217
  streamController?.close();
@@ -0,0 +1,270 @@
1
+ import { type Account, type Address, type Client } from 'viem';
2
+ import * as Store from '../Store.js';
3
+ import * as z from '../zod.js';
4
+ /** Key of the x402 `sign-in-with-x` (SIWX) extension in a 402's `extensions`. */
5
+ export declare const extensionKey = "sign-in-with-x";
6
+ /** Request header that carries a signed SIWX proof as base64-encoded JSON. */
7
+ export declare const header = "SIGN-IN-WITH-X";
8
+ /** How long a SIWX challenge stays valid, in milliseconds. */
9
+ export declare const ttl: number;
10
+ /**
11
+ * Machine-readable codes for a rejected proof, as the x402 SIWX spec names them.
12
+ *
13
+ * @see https://github.com/coinbase/x402/blob/main/specs/extensions/sign-in-with-x.md
14
+ */
15
+ export type ErrorCode = 'invalid_siwx_payload' | 'invalid_siwx_domain_mismatch' | 'invalid_siwx_uri_mismatch' | 'invalid_siwx_issued_at' | 'invalid_siwx_issued_at_too_old' | 'invalid_siwx_issued_at_in_future' | 'invalid_siwx_expiration_time' | 'invalid_siwx_expired' | 'invalid_siwx_not_before' | 'invalid_siwx_not_yet_valid' | 'invalid_siwx_nonce' | 'invalid_siwx_signature' | 'invalid_siwx_chain_id' | 'invalid_siwx_unsupported_chain' | 'invalid_siwx_verifier_error';
16
+ /** A signing method a server accepts. */
17
+ export declare const ChainSchema: z.ZodMiniObject<{
18
+ chainId: z.ZodMiniString<string>;
19
+ signatureScheme: z.ZodMiniOptional<z.ZodMiniString<string>>;
20
+ type: z.ZodMiniString<string>;
21
+ }, z.core.$strip>;
22
+ /** A signing method a server accepts. */
23
+ export type Chain = z.infer<typeof ChainSchema>;
24
+ /** Message fields a server declares in its 402. */
25
+ export declare const InfoSchema: z.ZodMiniObject<{
26
+ domain: z.ZodMiniString<string>;
27
+ expirationTime: z.ZodMiniOptional<z.ZodMiniString<string>>;
28
+ issuedAt: z.ZodMiniString<string>;
29
+ nonce: z.ZodMiniString<string>;
30
+ notBefore: z.ZodMiniOptional<z.ZodMiniString<string>>;
31
+ requestId: z.ZodMiniOptional<z.ZodMiniString<string>>;
32
+ resources: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
33
+ statement: z.ZodMiniOptional<z.ZodMiniString<string>>;
34
+ uri: z.ZodMiniString<string>;
35
+ version: z.ZodMiniString<string>;
36
+ }, z.core.$strip>;
37
+ /** Message fields a server declares in its 402. */
38
+ export type Info = z.infer<typeof InfoSchema>;
39
+ /** The extension's value in a 402's `extensions`. */
40
+ export declare const ExtensionSchema: z.ZodMiniObject<{
41
+ info: z.ZodMiniObject<{
42
+ domain: z.ZodMiniString<string>;
43
+ expirationTime: z.ZodMiniOptional<z.ZodMiniString<string>>;
44
+ issuedAt: z.ZodMiniString<string>;
45
+ nonce: z.ZodMiniString<string>;
46
+ notBefore: z.ZodMiniOptional<z.ZodMiniString<string>>;
47
+ requestId: z.ZodMiniOptional<z.ZodMiniString<string>>;
48
+ resources: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
49
+ statement: z.ZodMiniOptional<z.ZodMiniString<string>>;
50
+ uri: z.ZodMiniString<string>;
51
+ version: z.ZodMiniString<string>;
52
+ }, z.core.$strip>;
53
+ schema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
54
+ supportedChains: z.ZodMiniArray<z.ZodMiniObject<{
55
+ chainId: z.ZodMiniString<string>;
56
+ signatureScheme: z.ZodMiniOptional<z.ZodMiniString<string>>;
57
+ type: z.ZodMiniString<string>;
58
+ }, z.core.$strip>>;
59
+ }, z.core.$strip>;
60
+ /** The extension's value in a 402's `extensions`. */
61
+ export type Extension = z.infer<typeof ExtensionSchema>;
62
+ /** The signed proof a client sends in the {@link header}. */
63
+ export declare const PayloadSchema: z.ZodMiniObject<{
64
+ domain: z.ZodMiniString<string>;
65
+ expirationTime: z.ZodMiniOptional<z.ZodMiniString<string>>;
66
+ issuedAt: z.ZodMiniString<string>;
67
+ nonce: z.ZodMiniString<string>;
68
+ notBefore: z.ZodMiniOptional<z.ZodMiniString<string>>;
69
+ requestId: z.ZodMiniOptional<z.ZodMiniString<string>>;
70
+ resources: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
71
+ statement: z.ZodMiniOptional<z.ZodMiniString<string>>;
72
+ uri: z.ZodMiniString<string>;
73
+ version: z.ZodMiniString<string>;
74
+ address: z.ZodMiniString<string>;
75
+ chainId: z.ZodMiniString<string>;
76
+ signature: z.ZodMiniString<string>;
77
+ signatureScheme: z.ZodMiniOptional<z.ZodMiniString<string>>;
78
+ type: z.ZodMiniString<string>;
79
+ }, z.core.$strip>;
80
+ /** The signed proof a client sends in the {@link header}. */
81
+ export type Payload = z.infer<typeof PayloadSchema>;
82
+ /** JSON Schema of a {@link Payload}, advertised in the 402 as the spec requires. */
83
+ export declare const payloadJsonSchema: {
84
+ readonly $schema: 'https://json-schema.org/draft/2020-12/schema';
85
+ readonly properties: {
86
+ readonly address: {
87
+ readonly type: 'string';
88
+ };
89
+ readonly chainId: {
90
+ readonly type: 'string';
91
+ };
92
+ readonly domain: {
93
+ readonly type: 'string';
94
+ };
95
+ readonly expirationTime: {
96
+ readonly format: 'date-time';
97
+ readonly type: 'string';
98
+ };
99
+ readonly issuedAt: {
100
+ readonly format: 'date-time';
101
+ readonly type: 'string';
102
+ };
103
+ readonly nonce: {
104
+ readonly type: 'string';
105
+ };
106
+ readonly notBefore: {
107
+ readonly format: 'date-time';
108
+ readonly type: 'string';
109
+ };
110
+ readonly requestId: {
111
+ readonly type: 'string';
112
+ };
113
+ readonly resources: {
114
+ readonly items: {
115
+ readonly format: 'uri';
116
+ readonly type: 'string';
117
+ };
118
+ readonly type: 'array';
119
+ };
120
+ readonly signature: {
121
+ readonly type: 'string';
122
+ };
123
+ readonly statement: {
124
+ readonly type: 'string';
125
+ };
126
+ readonly type: {
127
+ readonly type: 'string';
128
+ };
129
+ readonly uri: {
130
+ readonly format: 'uri';
131
+ readonly type: 'string';
132
+ };
133
+ readonly version: {
134
+ readonly type: 'string';
135
+ };
136
+ };
137
+ readonly required: readonly ['domain', 'address', 'uri', 'version', 'chainId', 'type', 'nonce', 'issuedAt', 'signature'];
138
+ readonly type: 'object';
139
+ };
140
+ /** Error for a proof the server rejects. Its message is the spec's {@link ErrorCode}. */
141
+ export declare class InvalidProofError extends Error {
142
+ readonly name = "Siwx.InvalidProofError";
143
+ /** The spec's machine-readable code for the failed check. */
144
+ readonly code: ErrorCode;
145
+ constructor(code: ErrorCode);
146
+ }
147
+ /**
148
+ * Builds the EIP-4361 (SIWE) message a payload signs.
149
+ *
150
+ * The layout is viem's `createSiweMessage`, which also validates the fields, but timestamps
151
+ * are signed exactly as the payload carries them, as the x402 reference does, so a proof
152
+ * with any RFC 3339 timestamp verifies across implementations.
153
+ */
154
+ export declare function toMessage(payload: Omit<Payload, 'signature'>): string;
155
+ /** Encodes a payload as a {@link header} value. */
156
+ export declare function encode(payload: Payload): string;
157
+ /** Decodes a {@link header} value. Throws {@link InvalidProofError} when it is malformed. */
158
+ export declare function decode(value: string): Payload;
159
+ /** Reads the SIWX extension from a decoded x402 402 body, if it offers one. */
160
+ export declare function fromPaymentRequired(paymentRequired: {
161
+ extensions?: Record<string, unknown> | undefined;
162
+ }): Extension | undefined;
163
+ /** Builds the extension a server adds to a 402, with a fresh nonce. */
164
+ export declare function createExtension(parameters: {
165
+ /** EVM chain ID the server accepts signatures for. */
166
+ chainId: number;
167
+ /** The server's public origin. */
168
+ origin: string;
169
+ /** URL of the requested resource. */
170
+ url: string;
171
+ }): Extension;
172
+ /** Server options for accepting SIWX proofs on an x402 route. */
173
+ export type ServerOptions = {
174
+ /**
175
+ * Client for verifying smart-wallet (EIP-1271 and EIP-6492) signatures with an RPC call.
176
+ * It must serve the offer's chain: proofs for another chain are rejected.
177
+ * Without it, only EOA signatures verify.
178
+ */
179
+ client?: Client | undefined;
180
+ /**
181
+ * Decides whether a wallet that proved its address gets the resource without paying.
182
+ * Return `false` to answer 402 so it pays.
183
+ */
184
+ grant: (parameters: {
185
+ /** Address the proof recovered. */
186
+ address: Address;
187
+ /** EVM chain ID the proof was signed for. */
188
+ chainId: number;
189
+ /** The request being authorized. */
190
+ request: Request;
191
+ }) => boolean | Promise<boolean>;
192
+ /**
193
+ * Public origin of the server as clients see it, such as `https://api.example.com`.
194
+ * Proofs must name it. It is never taken from request headers such as `Host`,
195
+ * which a caller controls.
196
+ */
197
+ origin: string;
198
+ /**
199
+ * Atomic store that records used nonces, so each proof is accepted once. In a composed
200
+ * route, give offers that share a backend the same store object: each store object
201
+ * records the nonce on its own, so two objects over one backend refuse a later offer.
202
+ */
203
+ store: Store.AtomicStore;
204
+ };
205
+ /**
206
+ * Verifies a SIWX proof against the server's origin and chain. It does not record the
207
+ * nonce: call {@link claim} once the proof is used, so a check that declines the wallet
208
+ * leaves the proof for another.
209
+ * Throws {@link InvalidProofError} with the spec's code when the proof is rejected.
210
+ */
211
+ export declare function verify(parameters: {
212
+ /** EVM chain ID the server accepts signatures for. */
213
+ chainId: number;
214
+ /** The server's SIWX options. */
215
+ options: Pick<ServerOptions, 'client' | 'origin'>;
216
+ /** The decoded proof. */
217
+ payload: Payload;
218
+ }): Promise<{
219
+ address: Address;
220
+ chainId: number;
221
+ }>;
222
+ /**
223
+ * Records a verified proof's nonce so it is accepted once.
224
+ * Throws {@link InvalidProofError} with `invalid_siwx_nonce` when it was already used.
225
+ */
226
+ export declare function claim(parameters: {
227
+ /** The verified proof. */
228
+ payload: Pick<Payload, 'issuedAt' | 'nonce'>;
229
+ /** Atomic store that records used nonces. */
230
+ store: Store.AtomicStore;
231
+ }): Promise<void>;
232
+ /**
233
+ * Releases a nonce {@link claim} recorded, so the proof can be accepted again. Call it
234
+ * only for a claim this request made, such as when `grant` declines the wallet.
235
+ * Does nothing once that claim has expired, since another request may hold the nonce by then.
236
+ */
237
+ export declare function release(parameters: {
238
+ /** The claimed proof. */
239
+ payload: Pick<Payload, 'issuedAt' | 'nonce'>;
240
+ /** The store `claim` recorded the nonce in. */
241
+ store: Store.AtomicStore;
242
+ }): Promise<void>;
243
+ /**
244
+ * Wraps `fetch` so a 402 that offers SIWX is answered once with a proof signed by
245
+ * `account`, before any payment. Pass the result as the `fetch` of an mppx client:
246
+ * when the server still answers 402 because it doesn't grant this wallet, mppx pays
247
+ * from that response as usual.
248
+ *
249
+ * It signs only when the challenge's `domain` and `uri` origin match the URL that
250
+ * returned the 402, and only for `eip155` chains.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * import { Fetch, evm } from 'mppx/client'
255
+ * import { Siwx } from 'mppx/x402'
256
+ *
257
+ * const fetch = Fetch.from({
258
+ * fetch: Siwx.wrapFetch(globalThis.fetch, { account }),
259
+ * methods: [evm({ account })],
260
+ * })
261
+ * ```
262
+ */
263
+ export declare function wrapFetch(fetch: typeof globalThis.fetch, parameters: wrapFetch.Parameters): typeof globalThis.fetch;
264
+ export declare namespace wrapFetch {
265
+ type Parameters = {
266
+ /** Account that signs SIWX challenges. Must be able to sign messages. */
267
+ account: Account;
268
+ };
269
+ }
270
+ //# sourceMappingURL=Siwx.d.ts.map