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/README.md CHANGED
@@ -13,9 +13,11 @@ Users sign a message or transaction, and the Ultravioleta facilitator handles on
13
13
  - **Type-Safe**: Full TypeScript support
14
14
  - **React & Wagmi**: First-class integrations
15
15
  - **Signing Wallet Adapters**: EnvKeyAdapter (server/CLI), OWSWalletAdapter (Open Wallet Standard), or bring your own
16
+ - **ERC-8128 Signed Requests**: Authenticate HTTP requests with a wallet (RFC 9421 + EIP-191) — no API keys
16
17
  - **ERC-8004 Trustless Agents**: On-chain reputation and identity across 20 networks (18 EVM + 2 Solana)
17
18
  - **Escrow & Refunds**: Hold payments with dispute resolution
18
19
  - **Advanced Escrow**: Full escrow lifecycle (authorize, release, refund, charge) with SigningWalletAdapter support
20
+ - **Escrow Pre-Auth**: Sign-on-assignment `X-Payment-Auth` builder (`buildEscrowPreAuth`) — vector-pinned parity with the Python SDK and Execution Market
19
21
  - **Commerce Scheme**: `'commerce'` scheme alias for marketplace integrations (identical to `'escrow'` on-chain)
20
22
  - **`/accepts` Negotiation**: Discover facilitator capabilities before constructing payments
21
23
  - **Bazaar Discovery**: Register and discover paid resources across the x402 network
@@ -586,6 +588,69 @@ class MyAdapter implements SigningWalletAdapter {
586
588
  }
587
589
  ```
588
590
 
591
+ ## ERC-8128 Signed Requests
592
+
593
+ Authenticate HTTP requests with a wallet instead of an API key. The SDK builds the RFC 9421 signature base, signs it with EIP-191 personal_sign, and produces the `Signature`, `Signature-Input`, and (for bodies) `Content-Digest` headers. Used by APIs that only accept wallet signing, like [Execution Market](https://execution.market).
594
+
595
+ Wire format is pinned by golden vectors (`src/erc8128.vectors.json`): `alg="eip191"`, keyid always lowercase (`erc8128:{chainId}:{address}`), params in the order `created;expires;nonce;keyid;alg`.
596
+
597
+ ```typescript
598
+ import { createSignedFetch, EnvKeyAdapter } from 'uvd-x402-sdk';
599
+
600
+ // Auto-signing fetch: fetches a fresh nonce and signs every request
601
+ const signedFetch = createSignedFetch({
602
+ wallet: new EnvKeyAdapter(), // or privateKey: process.env.KEY!
603
+ apiBase: 'https://api.execution.market',
604
+ chainId: 8453, // Base (default)
605
+ });
606
+
607
+ const resp = await signedFetch('/api/v1/tasks', {
608
+ method: 'POST',
609
+ body: JSON.stringify({ title: 'test' }),
610
+ });
611
+ ```
612
+
613
+ For manual control, sign a single request (the nonce is single-use — fetch one per request):
614
+
615
+ ```typescript
616
+ import { fetchNonce, signRequestWithWallet, EnvKeyAdapter } from 'uvd-x402-sdk';
617
+
618
+ const wallet = new EnvKeyAdapter();
619
+ const nonce = await fetchNonce('https://api.execution.market');
620
+ const headers = await signRequestWithWallet(wallet, {
621
+ method: 'POST',
622
+ url: 'https://api.execution.market/api/v1/tasks',
623
+ body: '{"title":"test"}',
624
+ nonce,
625
+ });
626
+ // headers = { Signature, 'Signature-Input', 'Content-Digest' } — merge into your request
627
+ ```
628
+
629
+ Also available: `signRequest` (raw private key) and `signRequestWithSigner` (callback-based, for browser wallets / out-of-process signers where the key never leaves the signer), plus `buildSignatureBase` / `buildSignatureParams` to reproduce the exact signed bytes externally.
630
+
631
+ ## Escrow Pre-Auth (sign-on-assignment)
632
+
633
+ Build and sign the EIP-3009 `ReceiveWithAuthorization` that locks a bounty in the x402r AuthCaptureEscrow, packed as the raw-JSON `X-Payment-Auth` wrapper the facilitator's `/settle` expects. Used by marketplaces on the escrow rail (e.g. [Execution Market](https://execution.market)'s universal escrow).
634
+
635
+ The EIP-3009 nonce is `AuthCaptureEscrow.getHash(paymentInfo)`, which **includes the receiver** — the signature cryptographically commits to the chosen worker, so it can only be created AT ASSIGNMENT. The wire format is pinned by golden vectors (`src/escrow-preauth.vectors.json`) shared with the Python SDK and Execution Market's dashboard/mobile suites.
636
+
637
+ ```typescript
638
+ import { buildEscrowPreAuth, EnvKeyAdapter } from 'uvd-x402-sdk';
639
+
640
+ // Escrow config as published by the marketplace server
641
+ // (e.g. Execution Market's GET /api/v1/h2a/payment-config).
642
+ const paymentAuth = await buildEscrowPreAuth(new EnvKeyAdapter(), {
643
+ networkConfig: config.escrow.networks.base,
644
+ payerWallet: '0xPublisher...',
645
+ workerWallet: '0xWorker...', // escrow receiver — committed by the nonce
646
+ bountyAtomic: '100000', // $0.10 in 6-decimal USDC
647
+ reviewDeadlineSec: taskDeadline, // release window outlasts it
648
+ });
649
+ // Send as the X-Payment-Auth header (raw JSON, NOT base64).
650
+ ```
651
+
652
+ Any `SigningWalletAdapter` works as the signer (only `signTypedData` is used); browser wallets can pass a minimal `{ signTypedData }` wrapper. Validation fails loud instead of falling back: incomplete network config, unknown tier, bounty outside the on-chain deposit limit ($100), or a `maxFeeBps` below the operator's 1300 bps all throw before anything is signed. `computeEscrowNonce` is exported to reproduce `AuthCaptureEscrow.getHash` externally.
653
+
589
654
  ## Multi-Stablecoin (EVM)
590
655
 
591
656
  ```typescript
@@ -1,6 +1,6 @@
1
- import { X as X402Version, b as PaymentResult } from '../index-DgChnK_c.mjs';
2
- export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-CYIVd4xO.mjs';
3
- import '../wallet-0cX9Pw2F.mjs';
1
+ import { X as X402Version, b as PaymentResult } from '../index-CVW8AhRX.mjs';
2
+ export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-Z9v4GxOZ.mjs';
3
+ import '../wallet-w7BnImDG.mjs';
4
4
 
5
5
  /**
6
6
  * uvd-x402-sdk - Wagmi/Viem Adapter
@@ -1,6 +1,6 @@
1
- import { X as X402Version, b as PaymentResult } from '../index-DgChnK_c.js';
2
- export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-DTDixPzO.js';
3
- import '../wallet-0cX9Pw2F.js';
1
+ import { X as X402Version, b as PaymentResult } from '../index-CVW8AhRX.js';
2
+ export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-C-KmORG9.js';
3
+ import '../wallet-w7BnImDG.js';
4
4
 
5
5
  /**
6
6
  * uvd-x402-sdk - Wagmi/Viem Adapter
@@ -1,5 +1,5 @@
1
- import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.mjs';
2
- import { e as X402Header, X as X402Version, f as X402PayloadData } from '../index-DgChnK_c.mjs';
1
+ import { S as SigningWalletAdapter } from '../wallet-w7BnImDG.mjs';
2
+ import { e as X402Header, X as X402Version, f as X402PayloadData } from '../index-CVW8AhRX.mjs';
3
3
 
4
4
  /**
5
5
  * Payment requirements sent to the facilitator
@@ -1,5 +1,5 @@
1
- import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.js';
2
- import { e as X402Header, X as X402Version, f as X402PayloadData } from '../index-DgChnK_c.js';
1
+ import { S as SigningWalletAdapter } from '../wallet-w7BnImDG.js';
2
+ import { e as X402Header, X as X402Version, f as X402PayloadData } from '../index-CVW8AhRX.js';
3
3
 
4
4
  /**
5
5
  * Payment requirements sent to the facilitator
@@ -1227,9 +1227,15 @@ var FacilitatorClient = class {
1227
1227
  };
1228
1228
  }
1229
1229
  const result = await response.json();
1230
+ const transactionHash = result.transaction ?? result.transactionHash ?? result.transaction_hash;
1231
+ if (result.success && !transactionHash) {
1232
+ console.warn(
1233
+ "[x402] settle reported success but carried no transaction hash under transaction/transactionHash/transaction_hash \u2014 treat delivery as unconfirmed"
1234
+ );
1235
+ }
1230
1236
  return {
1231
1237
  success: true,
1232
- transactionHash: result.transactionHash || result.transaction_hash,
1238
+ transactionHash,
1233
1239
  network: result.network
1234
1240
  };
1235
1241
  } catch (error) {