-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
Description
Problem
There's no official way for clients to integrate with MicroAI-Paygate. Users need a TypeScript SDK to sign payments and verify receipts.
Architecture
flowchart LR
subgraph Client
A[User App] --> B[Paygate SDK]
B --> C[ethers.js]
end
subgraph Server
D[Gateway]
E[Verifier]
end
B -->|1. Sign Payment| D
D -->|2. Verify| E
E -->|3. Valid| D
D -->|4. Receipt + Response| B
B -->|5. Verify Receipt| B
SDK Flow
sequenceDiagram
participant App
participant SDK
participant Gateway
App->>SDK: request("/api/ai/summarize", body)
SDK->>Gateway: POST (no signature)
Gateway-->>SDK: 402 + PaymentContext
SDK->>SDK: Sign with ethers.js
SDK->>Gateway: POST + X-402-Signature
Gateway-->>SDK: 200 + Receipt
SDK->>SDK: Verify receipt signature
SDK-->>App: Response + verified receipt
Implementation
New directory: sdk/typescript/
// sdk/typescript/src/index.ts
export class PaygateClient {
constructor(private serverUrl: string, private signer: ethers.Signer) {}
async signPayment(context: PaymentContext): Promise<string>
async verifyReceipt(receipt: SignedReceipt): Promise<boolean>
async request<T>(endpoint: string, body: any): Promise<T>
}Acceptance Criteria
- Package structure with
package.json -
signPayment()creates valid EIP-712 signatures -
verifyReceipt()validates server signatures (Keccak256) - Works with receipts from Go gateway
- Unit tests with real receipt fixtures
- Example usage in README
Testing
cd sdk/typescript && bun testMust test against actual receipts from running server
Reactions are currently unavailable