Initial commit

This commit is contained in:
defiQUG
2026-01-01 08:04:06 -08:00
commit d0bc005be1
75 changed files with 15082 additions and 0 deletions

43
packages/x402/README.md Normal file
View File

@@ -0,0 +1,43 @@
# @dbis-thirdweb/x402
x402 payment primitives and pay-to-access flows for Chain 138.
## Usage
### Pay-to-Access Flow
```typescript
import { PayToAccessFlow, InMemoryReplayProtectionStore } from '@dbis-thirdweb/x402';
import { ThirdwebSDK } from '@thirdweb-dev/sdk';
import { chain138 } from '@dbis-thirdweb/chain';
// Server-side: Create request
const sdk = new ThirdwebSDK(chain138);
const provider = sdk.getProvider();
const replayStore = new InMemoryReplayProtectionStore();
const flow = new PayToAccessFlow(provider, replayStore);
const request = await flow.createRequest({
amount: ethers.utils.parseEther('0.01'),
recipient: '0x...',
expiresInSeconds: 3600,
});
const challenge = flow.generateChallenge(request);
// Client-side: Fulfill payment
const signer = await wallet.getSigner();
const receipt = await flow.fulfillPayment(challenge, signer);
// Server-side: Verify payment
const isValid = await flow.verifyPayment(receipt, request);
```
## Features
- Payment request creation and validation
- Replay protection via request ID tracking
- Receipt verification on-chain
- Pay-to-access flow implementation
- Expiration handling