uvd-x402-sdk 2.46.0 → 2.47.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.
Files changed (46) hide show
  1. package/README.md +65 -0
  2. package/dist/adapters/index.d.mts +3 -3
  3. package/dist/adapters/index.d.ts +3 -3
  4. package/dist/backend/index.d.mts +2 -2
  5. package/dist/backend/index.d.ts +2 -2
  6. package/dist/backend/index.js +7 -1
  7. package/dist/backend/index.js.map +1 -1
  8. package/dist/backend/index.mjs +7 -1
  9. package/dist/backend/index.mjs.map +1 -1
  10. package/dist/{index-DgChnK_c.d.mts → index-CVW8AhRX.d.mts} +1 -1
  11. package/dist/{index-DgChnK_c.d.ts → index-CVW8AhRX.d.ts} +1 -1
  12. package/dist/{index-BidnFGw_.d.mts → index-Cic-RnwJ.d.mts} +1 -1
  13. package/dist/{index-H64xdjKh.d.ts → index-DVJ9S8lP.d.ts} +1 -1
  14. package/dist/index.d.mts +387 -5
  15. package/dist/index.d.ts +387 -5
  16. package/dist/index.js +375 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +364 -2
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{ows-DTDixPzO.d.ts → ows-C-KmORG9.d.ts} +1 -1
  21. package/dist/{ows-CYIVd4xO.d.mts → ows-Z9v4GxOZ.d.mts} +1 -1
  22. package/dist/providers/algorand/index.d.mts +1 -1
  23. package/dist/providers/algorand/index.d.ts +1 -1
  24. package/dist/providers/evm/index.d.mts +1 -1
  25. package/dist/providers/evm/index.d.ts +1 -1
  26. package/dist/providers/near/index.d.mts +1 -1
  27. package/dist/providers/near/index.d.ts +1 -1
  28. package/dist/providers/solana/index.d.mts +1 -1
  29. package/dist/providers/solana/index.d.ts +1 -1
  30. package/dist/providers/stellar/index.d.mts +1 -1
  31. package/dist/providers/stellar/index.d.ts +1 -1
  32. package/dist/providers/sui/index.d.mts +1 -1
  33. package/dist/providers/sui/index.d.ts +1 -1
  34. package/dist/providers/xrpl/index.d.mts +1 -1
  35. package/dist/providers/xrpl/index.d.ts +1 -1
  36. package/dist/react/index.d.mts +3 -3
  37. package/dist/react/index.d.ts +3 -3
  38. package/dist/utils/index.d.mts +1 -1
  39. package/dist/utils/index.d.ts +1 -1
  40. package/dist/{wallet-0cX9Pw2F.d.mts → wallet-w7BnImDG.d.mts} +1 -1
  41. package/dist/{wallet-0cX9Pw2F.d.ts → wallet-w7BnImDG.d.ts} +1 -1
  42. package/package.json +38 -13
  43. package/src/backend/index.ts +22 -1
  44. package/src/erc8128.ts +443 -0
  45. package/src/escrow-preauth.ts +416 -0
  46. package/src/index.ts +36 -0
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export { D as DEFAULT_CHAIN, a as DEFAULT_FACILITATOR_URL, S as SUPPORTED_CHAINS, X as X402Client, b as getAlgorandChains, c as getChainById, g as getChainByName, d as getChainsByNetworkType, e as getChainsByToken, f as getEVMChainIds, h as getEnabledChains, i as getExplorerAddressUrl, j as getExplorerTxUrl, k as getNetworkType, l as getSVMChains, m as getSuiChains, n as getSupportedTokens, o as getTokenConfig, p as getXRPLChains, q as isAlgorandChain, r as isChainSupported, s as isSVMChain, t as isSuiChain, u as isTokenSupported, v as isXRPLChain } from './index-H64xdjKh.js';
1
+ export { D as DEFAULT_CHAIN, a as DEFAULT_FACILITATOR_URL, S as SUPPORTED_CHAINS, X as X402Client, b as getAlgorandChains, c as getChainById, g as getChainByName, d as getChainsByNetworkType, e as getChainsByToken, f as getEVMChainIds, h as getEnabledChains, i as getExplorerAddressUrl, j as getExplorerTxUrl, k as getNetworkType, l as getSVMChains, m as getSuiChains, n as getSupportedTokens, o as getTokenConfig, p as getXRPLChains, q as isAlgorandChain, r as isChainSupported, s as isSVMChain, t as isSuiChain, u as isTokenSupported, v as isXRPLChain } from './index-DVJ9S8lP.js';
2
2
  export { DEFAULT_PAYMENT_HEADER, PAYMENT_HEADER_NAMES, caip2ToChain, chainToCAIP2, convertX402Header, createPaymentHeaders, createX402Header, createX402V1Header, createX402V2Header, decodeX402Header, detectX402Version, encodeX402Header, generatePaymentOptions, getPaymentHeader, isCAIP2Format, parseNetworkIdentifier, validateAmount, validateRecipient } from './utils/index.js';
3
- export { A as AlgorandPaymentPayload, g as CAIP2_IDENTIFIERS, h as CAIP2_TO_CHAIN, C as ChainConfig, D as DEFAULT_CONFIG, E as EIP712Domain, i as EIP712Types, j as EVMPaymentPayload, M as MultiPaymentConfig, k as NEARPaymentPayload, l as NativeCurrency, N as NetworkBalance, c as NetworkType, m as PaymentHeaders, P as PaymentInfo, n as PaymentPayload, o as PaymentRequest, b as PaymentResult, S as SolanaPaymentPayload, p as StellarPaymentPayload, q as SuiPaymentPayload, r as TokenConfig, T as TokenType, U as USDCConfig, W as WalletAdapter, d as WalletState, s as X402AlgorandPayload, a as X402ClientConfig, t as X402EVMPayload, u as X402Error, v as X402ErrorCode, w as X402Event, x as X402EventData, y as X402EventHandler, e as X402Header, z as X402HeaderName, B as X402HeaderV1, F as X402HeaderV2, G as X402NEARPayload, f as X402PayloadData, H as X402PaymentOption, I as X402Scheme, J as X402SettlementAccountPayload, K as X402SolanaPayload, L as X402StellarPayload, O as X402SuiPayload, X as X402Version, Q as X402XRPLPayload, R as XRPLPaymentPayload } from './index-DgChnK_c.js';
4
- export { E as EIP3009Authorization, a as EIP3009Params, S as SigningWalletAdapter } from './wallet-0cX9Pw2F.js';
5
- export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-DTDixPzO.js';
3
+ export { A as AlgorandPaymentPayload, j as CAIP2_IDENTIFIERS, k as CAIP2_TO_CHAIN, C as ChainConfig, D as DEFAULT_CONFIG, E as EIP712Domain, l as EIP712Types, m as EVMPaymentPayload, M as MultiPaymentConfig, n as NEARPaymentPayload, o as NativeCurrency, N as NetworkBalance, c as NetworkType, p as PaymentHeaders, P as PaymentInfo, q as PaymentPayload, r as PaymentRequest, b as PaymentResult, S as SolanaPaymentPayload, s as StellarPaymentPayload, t as SuiPaymentPayload, i as TokenConfig, T as TokenType, U as USDCConfig, W as WalletAdapter, d as WalletState, u as X402AlgorandPayload, a as X402ClientConfig, v as X402EVMPayload, w as X402Error, x as X402ErrorCode, g as X402Event, y as X402EventData, h as X402EventHandler, e as X402Header, z as X402HeaderName, B as X402HeaderV1, F as X402HeaderV2, G as X402NEARPayload, f as X402PayloadData, H as X402PaymentOption, I as X402Scheme, J as X402SettlementAccountPayload, K as X402SolanaPayload, L as X402StellarPayload, O as X402SuiPayload, X as X402Version, Q as X402XRPLPayload, R as XRPLPaymentPayload } from './index-CVW8AhRX.js';
4
+ import { S as SigningWalletAdapter } from './wallet-w7BnImDG.js';
5
+ export { a as EIP3009Authorization, E as EIP3009Params } from './wallet-w7BnImDG.js';
6
+ export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-C-KmORG9.js';
6
7
  export { FacilitatorClient, FacilitatorClientOptions, HonoMiddlewareOptions, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, ResourceInfoV2, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, getCorsHeaders } from './backend/index.js';
7
8
 
8
9
  /**
@@ -271,4 +272,385 @@ declare function matchesFilters(event: TrafficEvent, options: Pick<StreamTraffic
271
272
  */
272
273
  declare function streamTrafficEvents(options?: StreamTrafficEventsOptions): AsyncGenerator<TrafficEvent, void, undefined>;
273
274
 
274
- export { EVENT_KINDS, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, type SSEFrame, SSEParser, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, getFacilitatorAddress, matchesFilters, parseTrafficEvent, streamTrafficEvents };
275
+ /**
276
+ * uvd-x402-sdk - ERC-8128 HTTP Message Signature Signer
277
+ *
278
+ * Signs HTTP requests per ERC-8128 (Signed HTTP Requests with Ethereum,
279
+ * RFC 9421 profile) so agents can authenticate against APIs that reject
280
+ * API keys and only accept wallet signing (e.g. Execution Market, where
281
+ * `EM_API_KEYS_ENABLED=false` in production).
282
+ *
283
+ * Flow:
284
+ * 1. Fetch a fresh single-use nonce from the server (`fetchNonce`)
285
+ * 2. Build the RFC 9421 signature base from request components
286
+ * 3. Sign with EIP-191 personal_sign
287
+ * 4. Produce `Signature` + `Signature-Input` (+ `Content-Digest`) headers
288
+ *
289
+ * Wire format: pinned by the F3-1 golden vectors (`src/erc8128.vectors.json`)
290
+ * — `alg="eip191"` always emitted, keyid ALWAYS lowercase, params in the
291
+ * order `created;expires;nonce;keyid;alg`. Byte-equality against the vectors
292
+ * is enforced in `src/erc8128.test.ts`.
293
+ *
294
+ * Three signing entry points:
295
+ * - {@link signRequest} — raw private key (ethers Wallet), for scripts /
296
+ * bots that hold the key in env.
297
+ * - {@link signRequestWithWallet} — any {@link SigningWalletAdapter}
298
+ * (EnvKeyAdapter, OWSWalletAdapter, custom); only `getAddress()` and
299
+ * `signMessage()` are used, the key never leaves the adapter.
300
+ * - {@link signRequestWithSigner} — callback-based, for browser wallets or
301
+ * out-of-process signers that expose a bare EIP-191 personal_sign.
302
+ *
303
+ * @example Sign a single request
304
+ * ```typescript
305
+ * import { signRequest, fetchNonce } from 'uvd-x402-sdk';
306
+ *
307
+ * const nonce = await fetchNonce('https://api.execution.market');
308
+ * const headers = await signRequest({
309
+ * privateKey: process.env.WALLET_PRIVATE_KEY!,
310
+ * method: 'POST',
311
+ * url: 'https://api.execution.market/api/v1/tasks',
312
+ * body: '{"title": "test"}',
313
+ * nonce,
314
+ * chainId: 8453,
315
+ * });
316
+ * // headers = { Signature: '...', 'Signature-Input': '...', 'Content-Digest': '...' }
317
+ * ```
318
+ *
319
+ * @example Auto-signing fetch wrapper
320
+ * ```typescript
321
+ * import { createSignedFetch, EnvKeyAdapter } from 'uvd-x402-sdk';
322
+ *
323
+ * const signedFetch = createSignedFetch({
324
+ * wallet: new EnvKeyAdapter(), // or privateKey: '...'
325
+ * apiBase: 'https://api.execution.market',
326
+ * });
327
+ *
328
+ * const resp = await signedFetch('/api/v1/tasks', {
329
+ * method: 'POST',
330
+ * body: JSON.stringify({ title: 'test' }),
331
+ * });
332
+ * ```
333
+ *
334
+ * Reference:
335
+ * - ERC-8128: https://eip.tools/eip/8128
336
+ * - RFC 9421: https://www.rfc-editor.org/rfc/rfc9421
337
+ * - ERC-191: https://eips.ethereum.org/EIPS/eip-191
338
+ */
339
+
340
+ /**
341
+ * Request components shared by every ERC-8128 signing entry point.
342
+ */
343
+ interface ERC8128RequestOptions {
344
+ /** HTTP method (GET, POST, etc.) */
345
+ method: string;
346
+ /** Full URL of the request (authority + path + query are covered) */
347
+ url: string;
348
+ /**
349
+ * Request body (for POST/PUT/PATCH). Omit for bodyless requests.
350
+ * Must be byte-identical to what is sent on the wire — the
351
+ * `Content-Digest` covers it.
352
+ */
353
+ body?: string;
354
+ /** Single-use nonce from the server. Required by most servers. */
355
+ nonce?: string;
356
+ /** EVM chain ID for the keyid (default: 8453 = Base) */
357
+ chainId?: number;
358
+ /** Signature label (default: "eth") */
359
+ label?: string;
360
+ /** Signature validity window in seconds (default: 300) */
361
+ validitySec?: number;
362
+ }
363
+ interface SignRequestOptions extends ERC8128RequestOptions {
364
+ /** Hex-encoded private key (with or without 0x prefix) */
365
+ privateKey: string;
366
+ }
367
+ interface SignRequestWithSignerOptions extends ERC8128RequestOptions {
368
+ /** Signer address (any case — lowercased for the keyid per F3-1) */
369
+ address: string;
370
+ /**
371
+ * EIP-191 personal_sign callback over the RFC 9421 signature base.
372
+ * Must return the 65-byte signature (r||s||v) as 0x-prefixed hex.
373
+ * The private key never leaves the signer (OWS vault, browser wallet).
374
+ */
375
+ signMessage: (signatureBase: string) => Promise<string> | string;
376
+ }
377
+ interface SignatureHeaders {
378
+ Signature: string;
379
+ 'Signature-Input': string;
380
+ 'Content-Digest'?: string;
381
+ }
382
+ /**
383
+ * Configuration for {@link createSignedFetch}. Provide exactly one signer:
384
+ * a raw `privateKey` or a `wallet` adapter.
385
+ */
386
+ interface CreateSignedFetchConfig {
387
+ /** Origin of the API (e.g. "https://api.execution.market") */
388
+ apiBase: string;
389
+ /** EVM chain ID for the keyid (default: 8453 = Base) */
390
+ chainId?: number;
391
+ /** Hex-encoded private key (with or without 0x prefix) */
392
+ privateKey?: string;
393
+ /** SigningWalletAdapter — the key never leaves the adapter */
394
+ wallet?: SigningWalletAdapter;
395
+ }
396
+ /**
397
+ * Sign an HTTP request per ERC-8128 with a raw private key.
398
+ *
399
+ * Thin wrapper over {@link signRequestWithSigner} using an ethers Wallet.
400
+ *
401
+ * @returns Headers to merge into the request (Signature, Signature-Input, Content-Digest).
402
+ */
403
+ declare function signRequest(options: SignRequestOptions): Promise<SignatureHeaders>;
404
+ /**
405
+ * Sign an HTTP request per ERC-8128 with a {@link SigningWalletAdapter}.
406
+ *
407
+ * Only `getAddress()` and `signMessage()` (EIP-191 personal_sign) are used —
408
+ * the private key never leaves the adapter. Works with EnvKeyAdapter,
409
+ * OWSWalletAdapter, or any custom adapter.
410
+ *
411
+ * @returns Headers to merge into the request (Signature, Signature-Input, Content-Digest).
412
+ */
413
+ declare function signRequestWithWallet(wallet: SigningWalletAdapter, options: ERC8128RequestOptions): Promise<SignatureHeaders>;
414
+ /**
415
+ * Sign an HTTP request per ERC-8128 with a signing callback.
416
+ *
417
+ * For signers that never expose the raw key (OWS vault, browser wallets):
418
+ * the callback receives the RFC 9421 signature base and returns the EIP-191
419
+ * personal_sign signature as 0x-hex.
420
+ *
421
+ * @returns Headers to merge into the request (Signature, Signature-Input, Content-Digest).
422
+ */
423
+ declare function signRequestWithSigner(options: SignRequestWithSignerOptions): Promise<SignatureHeaders>;
424
+ /**
425
+ * Fetch a fresh single-use nonce from the server.
426
+ *
427
+ * @param apiBase - Origin of the API (e.g. "https://api.execution.market")
428
+ * — the `/api/v1/auth/erc8128/nonce` path is appended here.
429
+ * @param timeoutMs - Request timeout in milliseconds (default: 10000).
430
+ * @returns The nonce value (single-use, short TTL — fetch one per request).
431
+ */
432
+ declare function fetchNonce(apiBase: string, timeoutMs?: number): Promise<string>;
433
+ /**
434
+ * Create a fetch wrapper that auto-signs requests with ERC-8128
435
+ * (nonce fetch + signature headers on every call).
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * const signedFetch = createSignedFetch({
440
+ * wallet: new EnvKeyAdapter(), // or privateKey: '...'
441
+ * apiBase: 'https://api.execution.market',
442
+ * chainId: 8453,
443
+ * });
444
+ *
445
+ * const resp = await signedFetch('/api/v1/tasks', {
446
+ * method: 'POST',
447
+ * body: JSON.stringify({ title: 'test' }),
448
+ * });
449
+ * ```
450
+ */
451
+ declare function createSignedFetch(config: CreateSignedFetchConfig): (path: string, init?: RequestInit) => Promise<Response>;
452
+ interface SignatureBaseParams {
453
+ method: string;
454
+ authority: string;
455
+ path: string;
456
+ query?: string;
457
+ contentDigest?: string;
458
+ covered: string[];
459
+ created: number;
460
+ expires: number;
461
+ nonce?: string;
462
+ keyid: string;
463
+ }
464
+ /**
465
+ * Build the RFC 9421 signature base — the exact string that gets EIP-191
466
+ * personal_signed. Exported so external signers (OWS, browser) can reproduce
467
+ * it byte-for-byte; pinned by the F3-1 golden vectors.
468
+ */
469
+ declare function buildSignatureBase(params: SignatureBaseParams): string;
470
+ interface SignatureParamsInput {
471
+ covered: string[];
472
+ created: number;
473
+ expires: number;
474
+ nonce?: string;
475
+ keyid: string;
476
+ }
477
+ /**
478
+ * Build the `@signature-params` value per RFC 9421, in the pinned order
479
+ * `created;expires;nonce;keyid;alg` (F3-1).
480
+ */
481
+ declare function buildSignatureParams(params: SignatureParamsInput): string;
482
+
483
+ /**
484
+ * uvd-x402-sdk - Escrow Pre-Auth Builder (sign-on-assignment)
485
+ *
486
+ * Builds and signs the EIP-3009 `ReceiveWithAuthorization` that locks a
487
+ * bounty in the x402r AuthCaptureEscrow, and packs it into the raw-JSON
488
+ * `X-Payment-Auth` wrapper the Ultravioleta Facilitator's `/settle` expects.
489
+ * Used by marketplaces built on the escrow rail (e.g. Execution Market's
490
+ * universal escrow, ADR-002).
491
+ *
492
+ * >>> PROTOCOL CONSTRAINT <<<
493
+ * The EIP-3009 nonce is `AuthCaptureEscrow.getHash(paymentInfo)` which
494
+ * INCLUDES the receiver — the escrow signature can only be created AT
495
+ * ASSIGNMENT, when the worker/payee is known. Never design flows that sign
496
+ * an escrow auth before the receiver is chosen ("stored pre-auth with late
497
+ * receiver fill" is on-chain unsound).
498
+ *
499
+ * Fail-loud policy: an incomplete network config, an unknown tier, a bounty
500
+ * outside the on-chain deposit limit, or a `maxFeeBps` that cannot cover the
501
+ * operator's static fee all throw instead of falling back — a silent
502
+ * fallback would sign an EIP-3009 authorization with the WRONG EIP-712
503
+ * domain (chainId + verifyingContract): a mismatched, wallet-draining auth.
504
+ *
505
+ * Wire format is pinned by golden vectors (`src/escrow-preauth.vectors.json`):
506
+ * payer-zeroed raw-keccak nonce (`keccak(chainId, escrow,
507
+ * keccak(PAYMENT_INFO_TYPEHASH, paymentInfo tuple with payer=0))`),
508
+ * `ReceiveWithAuthorization` typed data, raw JSON (NOT base64) wrapper.
509
+ * Byte-parity with the production references is enforced in
510
+ * `src/escrow-preauth.test.ts`.
511
+ *
512
+ * @example Sign the escrow lock at assignment time
513
+ * ```typescript
514
+ * import { buildEscrowPreAuth, EnvKeyAdapter } from 'uvd-x402-sdk';
515
+ *
516
+ * // Server-published escrow config (e.g. GET /api/v1/h2a/payment-config
517
+ * // on Execution Market — escrow_networks[network]).
518
+ * const paymentAuth = await buildEscrowPreAuth(new EnvKeyAdapter(), {
519
+ * networkConfig: config.escrow.networks.base,
520
+ * payerWallet: '0xPublisher...',
521
+ * workerWallet: '0xWorker...', // committed by the nonce
522
+ * bountyAtomic: '100000', // $0.10 in 6-decimal USDC
523
+ * reviewDeadlineSec: taskDeadlineEpoch,
524
+ * });
525
+ * // Send as the X-Payment-Auth header (raw JSON, NOT base64).
526
+ * ```
527
+ *
528
+ * Reference implementations (kept in byte-parity via the shared vectors):
529
+ * - Python: `em_plugin_sdk.escrow_signing.build_escrow_pre_auth`
530
+ * (production reference, derived from `uvd_x402_sdk.advanced_escrow`)
531
+ * - Browser (viem): Execution Market `dashboard/src/services/h2aSigning.ts`
532
+ */
533
+ /** AuthCaptureEscrow deposit condition: $100 max per deposit. */
534
+ declare const ESCROW_DEPOSIT_LIMIT_USD = 100;
535
+ /**
536
+ * StaticFeeCalculator: canonical 13% flat fee. The signed maxFeeBps MUST
537
+ * cover it or the on-chain release reverts.
538
+ */
539
+ declare const OPERATOR_FEE_BPS = 1300;
540
+ /** Per-tier expiry windows in seconds, relative to now() at signing. */
541
+ interface EscrowTierWindows {
542
+ pre: number;
543
+ auth: number;
544
+ refund: number;
545
+ }
546
+ /** Canonical fallback — mirrors uvd_x402_sdk TIER_TIMINGS. */
547
+ declare const ESCROW_TIER_WINDOWS: Record<string, EscrowTierWindows>;
548
+ /**
549
+ * One network's escrow parameters, as published by the marketplace server
550
+ * (e.g. Execution Market's `GET /api/v1/h2a/payment-config` →
551
+ * `escrow_networks[network]`). Snake_case on purpose: pass the server's
552
+ * JSON straight through so the SDK builds the paymentInfo EXACTLY like the
553
+ * production reference.
554
+ */
555
+ interface EscrowNetworkConfig {
556
+ chain_id: number;
557
+ operator: string;
558
+ escrow: string;
559
+ token_collector: string;
560
+ usdc: string;
561
+ usdc_domain_name: string;
562
+ usdc_domain_version: string;
563
+ /** 32-byte hex PAYMENT_INFO_TYPEHASH (with or without 0x prefix). */
564
+ payment_info_typehash: string;
565
+ /** Server-published tier windows; falls back to ESCROW_TIER_WINDOWS. */
566
+ tiers?: Record<string, EscrowTierWindows>;
567
+ min_fee_bps?: number;
568
+ max_fee_bps?: number;
569
+ }
570
+ /** paymentInfo exactly as serialized in the X-Payment-Auth wrapper. */
571
+ interface EscrowPaymentInfo {
572
+ operator: string;
573
+ receiver: string;
574
+ token: string;
575
+ /** Atomic units, as string (uint120 on-chain). */
576
+ maxAmount: string;
577
+ preApprovalExpiry: number;
578
+ authorizationExpiry: number;
579
+ refundExpiry: number;
580
+ minFeeBps: number;
581
+ maxFeeBps: number;
582
+ feeReceiver: string;
583
+ /** 32-byte hex. */
584
+ salt: string;
585
+ }
586
+ /**
587
+ * Compute the escrow EIP-3009 nonce = `AuthCaptureEscrow.getHash(paymentInfo)`.
588
+ *
589
+ * `keccak(chainId, escrow, keccak(PAYMENT_INFO_TYPEHASH, paymentInfo tuple
590
+ * with payer=0))` — the payer slot is zeroed for the payer-agnostic hash;
591
+ * the RECEIVER is part of the hash, which is why the signature commits to
592
+ * the chosen worker. Port of `AdvancedEscrowClient._compute_nonce` /
593
+ * `em_plugin_sdk.escrow_signing.compute_escrow_nonce`.
594
+ *
595
+ * @param chainId - EVM chain id.
596
+ * @param escrowAddress - AuthCaptureEscrow contract on that chain.
597
+ * @param paymentInfoTypehash - 32-byte hex typehash from the server config.
598
+ * @param pi - paymentInfo exactly as serialized on the wire.
599
+ * @returns 32-byte hex nonce (0x-prefixed, lowercase).
600
+ */
601
+ declare function computeEscrowNonce(chainId: number, escrowAddress: string, paymentInfoTypehash: string, pi: EscrowPaymentInfo): string;
602
+ /**
603
+ * Minimal signer for {@link buildEscrowPreAuth}: EIP-712 typed-data signing
604
+ * over the full typed-data JSON string (`domain`, `types`, `primaryType`,
605
+ * `message`) — the same contract as `SigningWalletAdapter.signTypedData`,
606
+ * so every adapter (EnvKeyAdapter, OWSWalletAdapter, custom) satisfies it
607
+ * structurally. Browser wallets can wrap their own signTypedData in this
608
+ * shape; the key never leaves the signer.
609
+ */
610
+ interface EscrowPreAuthSigner {
611
+ signTypedData(typedData: string): Promise<{
612
+ signature: string;
613
+ }>;
614
+ }
615
+ interface EscrowPreAuthParams {
616
+ /** Network escrow config as published by the marketplace server. */
617
+ networkConfig: EscrowNetworkConfig;
618
+ /**
619
+ * Publisher wallet (payer). Not checked against the signer's address —
620
+ * payer binding is enforced on-chain and by the backend, not here.
621
+ */
622
+ payerWallet: string;
623
+ /** Chosen worker's wallet (escrow receiver — committed by the nonce). */
624
+ workerWallet: string;
625
+ /** Bounty in atomic units (6-decimal USDC). */
626
+ bountyAtomic: string | bigint;
627
+ /** Expiry tier; windows come from config when present. Default 'micro'. */
628
+ tier?: string;
629
+ /**
630
+ * Task deadline (epoch seconds). The release/refund windows are extended
631
+ * to outlast it + a review buffer so a human publisher can still approve
632
+ * after the worker delivers. When omitted, falls back to now()-based
633
+ * windows.
634
+ */
635
+ reviewDeadlineSec?: number;
636
+ /**
637
+ * On-chain deposit limit in USD (AuthCaptureEscrow deposit condition).
638
+ * Default {@link ESCROW_DEPOSIT_LIMIT_USD}; override only when the server
639
+ * publishes a different limit.
640
+ */
641
+ depositLimitUsd?: number;
642
+ }
643
+ /**
644
+ * Build + sign the escrow lock authorization AT ASSIGNMENT time and return
645
+ * the raw JSON string for the `X-Payment-Auth` header (NOT base64 — the
646
+ * backend relays it verbatim to the Facilitator `/settle`). Mirror of
647
+ * `AdvancedEscrowClient.authorize()`'s /settle payload and of
648
+ * `em_plugin_sdk.escrow_signing.build_escrow_pre_auth`.
649
+ *
650
+ * @throws {X402Error} `INVALID_CONFIG` on an incomplete network config,
651
+ * unknown tier, or a `maxFeeBps` that cannot cover the operator's static
652
+ * fee; `INVALID_AMOUNT` on a bounty outside (0, deposit limit].
653
+ */
654
+ declare function buildEscrowPreAuth(wallet: EscrowPreAuthSigner, params: EscrowPreAuthParams): Promise<string>;
655
+
656
+ export { type CreateSignedFetchConfig, type ERC8128RequestOptions, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, type EscrowNetworkConfig, type EscrowPaymentInfo, type EscrowPreAuthParams, type EscrowPreAuthSigner, type EscrowTierWindows, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, OPERATOR_FEE_BPS, type SSEFrame, SSEParser, type SignRequestOptions, type SignRequestWithSignerOptions, type SignatureBaseParams, type SignatureHeaders, type SignatureParamsInput, SigningWalletAdapter, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, buildEscrowPreAuth, buildSignatureBase, buildSignatureParams, computeEscrowNonce, createSignedFetch, fetchNonce, getFacilitatorAddress, matchesFilters, parseTrafficEvent, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents };