@zkproofport-ai/sdk 0.1.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.
- package/README.md +437 -0
- package/dist/attestation.d.ts +60 -0
- package/dist/attestation.d.ts.map +1 -0
- package/dist/attestation.js +220 -0
- package/dist/attestation.js.map +1 -0
- package/dist/cdp.d.ts +44 -0
- package/dist/cdp.d.ts.map +1 -0
- package/dist/cdp.js +89 -0
- package/dist/cdp.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +25 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +29 -0
- package/dist/constants.js.map +1 -0
- package/dist/flow.d.ts +19 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +82 -0
- package/dist/flow.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs.d.ts +56 -0
- package/dist/inputs.d.ts.map +1 -0
- package/dist/inputs.js +204 -0
- package/dist/inputs.js.map +1 -0
- package/dist/merkle.d.ts +34 -0
- package/dist/merkle.d.ts.map +1 -0
- package/dist/merkle.js +95 -0
- package/dist/merkle.js.map +1 -0
- package/dist/payment.d.ts +15 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +114 -0
- package/dist/payment.js.map +1 -0
- package/dist/prove.d.ts +12 -0
- package/dist/prove.d.ts.map +1 -0
- package/dist/prove.js +25 -0
- package/dist/prove.js.map +1 -0
- package/dist/session.d.ts +8 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +20 -0
- package/dist/session.js.map +1 -0
- package/dist/signer.d.ts +69 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +51 -0
- package/dist/signer.js.map +1 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/verify.d.ts +29 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +56 -0
- package/dist/verify.js.map +1 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
# @zkproofport-ai/sdk
|
|
2
|
+
|
|
3
|
+
Client SDK for ZKProofport zero-knowledge proof generation on Base Mainnet.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
@zkproofport-ai/sdk is a TypeScript SDK for generating privacy-preserving zero-knowledge proofs using Coinbase KYC attestations. Generate a proof with a single function call, or fine-tune each step for custom workflows.
|
|
8
|
+
|
|
9
|
+
Proofs are generated in trusted execution environments (Nitro Enclaves) with cryptographic attestation. Payment is handled transparently via the x402 protocol using EIP-3009 (no user gas costs).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @zkproofport-ai/sdk ethers
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using the SDK, you need:
|
|
20
|
+
|
|
21
|
+
1. **Coinbase account with KYC verification** — Complete identity verification on [Coinbase](https://www.coinbase.com/)
|
|
22
|
+
2. **Coinbase KYC EAS attestation on Base** — Obtain an attestation via [Coinbase Verifications](https://www.coinbase.com/onchain-verify). This creates an on-chain EAS attestation on Base linked to your wallet address.
|
|
23
|
+
3. **USDC balance on Base** — At least $0.10 per proof. Payment is gasless (EIP-3009 signature, facilitator pays gas).
|
|
24
|
+
4. **Attestation wallet private key** (required) — The private key of the wallet that holds the EAS attestation. This is always a raw private key because the attestation is tied to a specific address.
|
|
25
|
+
|
|
26
|
+
5. **Payment wallet** (optional) — Wallet with USDC balance for proof payment. Defaults to the attestation wallet. Choose one:
|
|
27
|
+
|
|
28
|
+
- **Same as attestation wallet** — No additional setup. The attestation wallet must hold USDC.
|
|
29
|
+
- **Separate private key** — A different wallet with USDC balance.
|
|
30
|
+
- **CDP MPC wallet** — Coinbase Developer Platform managed wallet. Private keys never leave Coinbase's TEE. Get credentials at [CDP Portal](https://portal.cdp.coinbase.com). Requires additional install:
|
|
31
|
+
```bash
|
|
32
|
+
npm install @coinbase/agentkit @coinbase/cdp-sdk
|
|
33
|
+
```
|
|
34
|
+
| Credential | Required | Description |
|
|
35
|
+
|------------|----------|-------------|
|
|
36
|
+
| `CDP_API_KEY_ID` | Yes | CDP API key ID |
|
|
37
|
+
| `CDP_API_KEY_SECRET` | Yes | CDP API key secret |
|
|
38
|
+
| `CDP_WALLET_SECRET` | Yes | CDP wallet encryption secret |
|
|
39
|
+
| `CDP_WALLET_ADDRESS` | No | Existing wallet address (creates new if omitted) |
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### Single Wallet (attestation + payment)
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { generateProof, createConfig, fromPrivateKey, verifyProof } from '@zkproofport-ai/sdk';
|
|
47
|
+
|
|
48
|
+
const config = createConfig();
|
|
49
|
+
const signer = fromPrivateKey(process.env.PRIVATE_KEY);
|
|
50
|
+
|
|
51
|
+
const result = await generateProof(
|
|
52
|
+
config,
|
|
53
|
+
{ attestation: signer },
|
|
54
|
+
{ circuit: 'coinbase_kyc', scope: 'my-app' }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const verification = await verifyProof(result);
|
|
58
|
+
console.log('Valid:', verification.valid);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Separate Payment Wallet
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { generateProof, createConfig, fromPrivateKey, verifyProof } from '@zkproofport-ai/sdk';
|
|
65
|
+
|
|
66
|
+
const config = createConfig();
|
|
67
|
+
const attestationSigner = fromPrivateKey(process.env.ATTESTATION_KEY);
|
|
68
|
+
const paymentSigner = fromPrivateKey(process.env.PAYMENT_KEY);
|
|
69
|
+
|
|
70
|
+
const result = await generateProof(
|
|
71
|
+
config,
|
|
72
|
+
{ attestation: attestationSigner, payment: paymentSigner },
|
|
73
|
+
{ circuit: 'coinbase_kyc', scope: 'my-app' }
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const verification = await verifyProof(result);
|
|
77
|
+
console.log('Valid:', verification.valid);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### With CDP Payment Wallet
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { generateProof, createConfig, fromPrivateKey, CdpWalletSigner, verifyProof } from '@zkproofport-ai/sdk';
|
|
84
|
+
|
|
85
|
+
const config = createConfig();
|
|
86
|
+
const attestationSigner = fromPrivateKey(process.env.ATTESTATION_KEY);
|
|
87
|
+
const paymentSigner = await CdpWalletSigner.create({
|
|
88
|
+
apiKeyId: process.env.CDP_API_KEY_ID,
|
|
89
|
+
apiKeySecret: process.env.CDP_API_KEY_SECRET,
|
|
90
|
+
walletSecret: process.env.CDP_WALLET_SECRET,
|
|
91
|
+
address: process.env.CDP_WALLET_ADDRESS,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const result = await generateProof(
|
|
95
|
+
config,
|
|
96
|
+
{ attestation: attestationSigner, payment: paymentSigner },
|
|
97
|
+
{ circuit: 'coinbase_kyc', scope: 'my-app' }
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const verification = await verifyProof(result);
|
|
101
|
+
console.log('Valid:', verification.valid);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { createConfig } from '@zkproofport-ai/sdk';
|
|
108
|
+
|
|
109
|
+
// Mainnet (default) — production use
|
|
110
|
+
const config = createConfig();
|
|
111
|
+
|
|
112
|
+
// Custom server or RPC endpoints
|
|
113
|
+
const config = createConfig({
|
|
114
|
+
baseUrl: 'https://ai.zkproofport.app',
|
|
115
|
+
easRpcUrl: 'https://mainnet.base.org',
|
|
116
|
+
easGraphqlUrl: 'https://base.easscan.org/graphql',
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Configuration fields:**
|
|
121
|
+
|
|
122
|
+
| Field | Type | Default | Description |
|
|
123
|
+
|-------|------|---------|-------------|
|
|
124
|
+
| `baseUrl` | string | `https://ai.zkproofport.app` | proofport-ai server URL |
|
|
125
|
+
| `easRpcUrl` | string | `https://mainnet.base.org` | Base Mainnet RPC for EAS attestation queries |
|
|
126
|
+
| `easGraphqlUrl` | string | `https://base.easscan.org/graphql` | EAS GraphQL endpoint for attestation schema queries |
|
|
127
|
+
|
|
128
|
+
## Proof Generation
|
|
129
|
+
|
|
130
|
+
### Single-Step Flow
|
|
131
|
+
|
|
132
|
+
The `generateProof()` function handles the entire proof generation pipeline: signing, attestation fetching, circuit input preparation, x402 payment, and proof generation.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { generateProof, createConfig, fromPrivateKey } from '@zkproofport-ai/sdk';
|
|
136
|
+
import type { StepResult } from '@zkproofport-ai/sdk';
|
|
137
|
+
|
|
138
|
+
const config = createConfig();
|
|
139
|
+
const attestationSigner = fromPrivateKey(process.env.ATTESTATION_KEY);
|
|
140
|
+
const paymentSigner = fromPrivateKey(process.env.PAYMENT_KEY); // optional
|
|
141
|
+
|
|
142
|
+
const result = await generateProof(
|
|
143
|
+
config,
|
|
144
|
+
{
|
|
145
|
+
attestation: attestationSigner,
|
|
146
|
+
payment: paymentSigner, // uses attestationSigner if not provided
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
circuit: 'coinbase_kyc',
|
|
150
|
+
scope: 'my-application',
|
|
151
|
+
// Optional: for country circuit
|
|
152
|
+
// countryList: ['US', 'KR'],
|
|
153
|
+
// isIncluded: true, // true = inclusion list, false = exclusion
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
onStep: (step: StepResult) => {
|
|
157
|
+
console.log(`[${step.step}] ${step.name} (${step.durationMs}ms)`);
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
console.log('Proof generated in', result.timing.totalMs, 'ms');
|
|
163
|
+
console.log('Proof:', result.proof);
|
|
164
|
+
console.log('Public inputs:', result.publicInputs);
|
|
165
|
+
console.log('Payment TX:', result.paymentTxHash);
|
|
166
|
+
|
|
167
|
+
// Attestation present if TEE mode enabled on server
|
|
168
|
+
if (result.attestation) {
|
|
169
|
+
console.log('TEE document:', result.attestation.document);
|
|
170
|
+
console.log('Verification:', result.attestation.verification);
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Proof generation flow:**
|
|
175
|
+
1. Sign signal hash with attestation signer
|
|
176
|
+
2. Fetch Coinbase KYC attestation from EAS
|
|
177
|
+
3. Build circuit inputs (Merkle tree, hashes)
|
|
178
|
+
4. Request 402 payment challenge
|
|
179
|
+
5. Sign EIP-3009 TransferWithAuthorization
|
|
180
|
+
6. Submit payment via x402 facilitator
|
|
181
|
+
7. Generate proof in TEE with payment proof
|
|
182
|
+
|
|
183
|
+
**Result fields:**
|
|
184
|
+
|
|
185
|
+
| Field | Type | Description |
|
|
186
|
+
|-------|------|-------------|
|
|
187
|
+
| `proof` | string | 0x-prefixed proof hex |
|
|
188
|
+
| `publicInputs` | string | 0x-prefixed public inputs hex |
|
|
189
|
+
| `proofWithInputs` | string | Combined proof + public inputs |
|
|
190
|
+
| `paymentTxHash` | string | Transaction hash of x402 payment |
|
|
191
|
+
| `attestation` | object | TEE attestation (document, proof_hash, verification) or null |
|
|
192
|
+
| `timing` | object | Execution times per step |
|
|
193
|
+
| `verification` | object | On-chain verifier info (chainId, address, rpcUrl) |
|
|
194
|
+
|
|
195
|
+
## On-Chain Verification
|
|
196
|
+
|
|
197
|
+
### Automatic Verification
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { verifyProof } from '@zkproofport-ai/sdk';
|
|
201
|
+
|
|
202
|
+
const verification = await verifyProof(result);
|
|
203
|
+
|
|
204
|
+
if (verification.valid) {
|
|
205
|
+
console.log('Proof is valid on-chain');
|
|
206
|
+
} else {
|
|
207
|
+
console.log('Proof verification failed:', verification.error);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Step-by-Step API
|
|
212
|
+
|
|
213
|
+
For advanced workflows or debugging, use individual step functions instead of `generateProof()`.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import {
|
|
217
|
+
prepareInputs,
|
|
218
|
+
requestChallenge,
|
|
219
|
+
makePayment,
|
|
220
|
+
submitProof,
|
|
221
|
+
computeSignalHash,
|
|
222
|
+
CIRCUIT_NAME_MAP,
|
|
223
|
+
USDC_ADDRESSES,
|
|
224
|
+
EthersWalletSigner,
|
|
225
|
+
createConfig,
|
|
226
|
+
} from '@zkproofport-ai/sdk';
|
|
227
|
+
import { ethers } from 'ethers';
|
|
228
|
+
|
|
229
|
+
const config = createConfig();
|
|
230
|
+
const circuit = 'coinbase_kyc';
|
|
231
|
+
const circuitId = CIRCUIT_NAME_MAP[circuit];
|
|
232
|
+
const scope = 'my-app';
|
|
233
|
+
|
|
234
|
+
// Step 1: Sign signal hash
|
|
235
|
+
const attestationWallet = new ethers.Wallet(process.env.ATTESTATION_KEY);
|
|
236
|
+
const signalHash = computeSignalHash(attestationWallet.address, scope, circuitId);
|
|
237
|
+
const signalHashBytes = ethers.getBytes(ethers.hexlify(signalHash));
|
|
238
|
+
const signature = await attestationWallet.signMessage(signalHashBytes);
|
|
239
|
+
|
|
240
|
+
// Step 2: Prepare circuit inputs
|
|
241
|
+
const inputs = await prepareInputs(config, {
|
|
242
|
+
circuitId,
|
|
243
|
+
userAddress: attestationWallet.address,
|
|
244
|
+
userSignature: signature,
|
|
245
|
+
scope,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Step 3: Request payment challenge
|
|
249
|
+
const challenge = await requestChallenge(config, circuit, inputs);
|
|
250
|
+
|
|
251
|
+
// Step 4: Make payment via x402 facilitator
|
|
252
|
+
const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');
|
|
253
|
+
const paymentWallet = new ethers.Wallet(process.env.PAYMENT_KEY, provider);
|
|
254
|
+
const paymentSigner = new EthersWalletSigner(paymentWallet);
|
|
255
|
+
|
|
256
|
+
const paymentTxHash = await makePayment(paymentSigner, {
|
|
257
|
+
nonce: challenge.nonce,
|
|
258
|
+
recipient: challenge.payment.payTo,
|
|
259
|
+
amount: parseInt(challenge.payment.maxAmountRequired),
|
|
260
|
+
asset: USDC_ADDRESSES['base'],
|
|
261
|
+
network: challenge.payment.network,
|
|
262
|
+
instruction: challenge.payment.description,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Step 5: Submit proof with payment proof
|
|
266
|
+
const proofResponse = await submitProof(config, {
|
|
267
|
+
circuit,
|
|
268
|
+
inputs,
|
|
269
|
+
paymentTxHash,
|
|
270
|
+
paymentNonce: challenge.nonce,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
console.log('Proof:', proofResponse.proof);
|
|
274
|
+
console.log('Public inputs:', proofResponse.publicInputs);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Circuits
|
|
278
|
+
|
|
279
|
+
### Coinbase KYC
|
|
280
|
+
|
|
281
|
+
Proves wallet holder passed Coinbase Know-Your-Customer verification.
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
const result = await generateProof(config, signers, {
|
|
285
|
+
circuit: 'coinbase_kyc',
|
|
286
|
+
scope: 'my-app', // any string; used to prevent proof replay
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Coinbase Country
|
|
291
|
+
|
|
292
|
+
Proves wallet holder's country is (or is not) in a specified list.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
const result = await generateProof(config, signers, {
|
|
296
|
+
circuit: 'coinbase_country',
|
|
297
|
+
countryList: ['US', 'KR'],
|
|
298
|
+
isIncluded: true, // true = prove in list, false = prove not in list
|
|
299
|
+
scope: 'my-app',
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Types Reference
|
|
304
|
+
|
|
305
|
+
**Circuit Types:**
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
type CircuitName = 'coinbase_kyc' | 'coinbase_country';
|
|
309
|
+
type CircuitId = 'coinbase_attestation' | 'coinbase_country_attestation';
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Configuration:**
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
interface ClientConfig {
|
|
316
|
+
baseUrl: string;
|
|
317
|
+
easRpcUrl?: string;
|
|
318
|
+
easGraphqlUrl?: string;
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Signer:**
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
interface ProofportSigner {
|
|
326
|
+
getAddress(): string | Promise<string>;
|
|
327
|
+
signMessage(message: Uint8Array): Promise<string>;
|
|
328
|
+
signTypedData(domain: {...}, types: {...}, message: {...}): Promise<string>;
|
|
329
|
+
sendTransaction(tx: {...}): Promise<{ hash: string; wait(): Promise<{...}> }>;
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**Proof Parameters:**
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
interface ProofParams {
|
|
337
|
+
circuit: CircuitName;
|
|
338
|
+
scope?: string; // defaults to 'proofport'
|
|
339
|
+
countryList?: string[]; // for coinbase_country only
|
|
340
|
+
isIncluded?: boolean; // for coinbase_country only
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Proof Result:**
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
interface ProofResult {
|
|
348
|
+
proof: string;
|
|
349
|
+
publicInputs: string;
|
|
350
|
+
proofWithInputs: string;
|
|
351
|
+
paymentTxHash: string;
|
|
352
|
+
attestation: {
|
|
353
|
+
document: string;
|
|
354
|
+
proof_hash: string;
|
|
355
|
+
verification: {
|
|
356
|
+
rootCaValid: boolean;
|
|
357
|
+
chainValid: boolean;
|
|
358
|
+
signatureValid: boolean;
|
|
359
|
+
pcrs: Record<number, string>;
|
|
360
|
+
};
|
|
361
|
+
} | null;
|
|
362
|
+
timing: {
|
|
363
|
+
totalMs: number;
|
|
364
|
+
paymentVerifyMs?: number;
|
|
365
|
+
inputBuildMs?: number;
|
|
366
|
+
proveMs?: number;
|
|
367
|
+
};
|
|
368
|
+
verification: {
|
|
369
|
+
chainId: number;
|
|
370
|
+
verifierAddress: string;
|
|
371
|
+
rpcUrl: string;
|
|
372
|
+
} | null;
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Callbacks:**
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
interface FlowCallbacks {
|
|
380
|
+
onStep?: (step: StepResult) => void;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
interface StepResult {
|
|
384
|
+
step: number;
|
|
385
|
+
name: string;
|
|
386
|
+
data: unknown;
|
|
387
|
+
durationMs: number;
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Payment
|
|
392
|
+
|
|
393
|
+
Payment is transparent to the application. When `generateProof()` runs, the user signs an EIP-3009 `TransferWithAuthorization` message (no gas cost). The signature is sent to the x402 facilitator, which completes the USDC transfer and proves payment to the server.
|
|
394
|
+
|
|
395
|
+
- Protocol: x402 (HTTP 402 Payment Required)
|
|
396
|
+
- Method: EIP-3009 `TransferWithAuthorization`
|
|
397
|
+
- Token: USDC on Base Mainnet
|
|
398
|
+
- Amount: $0.10 per proof
|
|
399
|
+
- Facilitator: https://www.x402.org/facilitator (pays gas)
|
|
400
|
+
- User cost: Only USDC, no ETH for gas
|
|
401
|
+
|
|
402
|
+
The payment transaction hash is included in `result.paymentTxHash` for settlement tracking.
|
|
403
|
+
|
|
404
|
+
## Error Handling
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { generateProof, createConfig, fromPrivateKey } from '@zkproofport-ai/sdk';
|
|
408
|
+
|
|
409
|
+
try {
|
|
410
|
+
const result = await generateProof(config, signers, params);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (error instanceof Error) {
|
|
413
|
+
if (error.message.includes('402')) {
|
|
414
|
+
console.error('Payment required or payment failed');
|
|
415
|
+
} else if (error.message.includes('attestation')) {
|
|
416
|
+
console.error('Attestation not found or invalid');
|
|
417
|
+
} else if (error.message.includes('Sumcheck')) {
|
|
418
|
+
console.error('Proof verification failed on-chain');
|
|
419
|
+
} else {
|
|
420
|
+
console.error('Proof generation failed:', error.message);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
Common errors:
|
|
427
|
+
|
|
428
|
+
| Error | Cause | Solution |
|
|
429
|
+
|-------|-------|----------|
|
|
430
|
+
| `Attestation not found` | Wallet has no Coinbase KYC attestation | Verify attestation on Base Mainnet via EAS |
|
|
431
|
+
| `402 Payment Required` | x402 payment failed or insufficient USDC | Ensure wallet has USDC balance, check x402 facilitator |
|
|
432
|
+
| `Sumcheck failed` | On-chain verification failed | Proof corrupted or verifier contract mismatch |
|
|
433
|
+
| `Transaction failed` | User rejected signature | Retry or check wallet |
|
|
434
|
+
|
|
435
|
+
## License
|
|
436
|
+
|
|
437
|
+
MIT
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CircuitId, EASAttestation, AttestationData, ClientConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Query EAS GraphQL for the latest attestation matching schemaId + recipient.
|
|
4
|
+
*/
|
|
5
|
+
export declare function fetchAttestationFromEAS(easGraphqlUrl: string, circuitId: CircuitId, recipientAddress: string): Promise<EASAttestation>;
|
|
6
|
+
/**
|
|
7
|
+
* Fetch raw transaction via eth_getTransactionByHash from an RPC endpoint.
|
|
8
|
+
* Includes retry logic for 429/5xx responses with exponential backoff.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetchRawTransaction(rpcUrl: string, txHash: string): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Reconstruct a raw signed transaction hex from RPC response fields.
|
|
13
|
+
* Uses ethers v6 Transaction class. Returns tx.serialized (SIGNED).
|
|
14
|
+
*/
|
|
15
|
+
export declare function reconstructRawTransaction(txData: {
|
|
16
|
+
to: string;
|
|
17
|
+
nonce: string;
|
|
18
|
+
gas: string;
|
|
19
|
+
gasPrice?: string;
|
|
20
|
+
maxFeePerGas?: string;
|
|
21
|
+
maxPriorityFeePerGas?: string;
|
|
22
|
+
input: string;
|
|
23
|
+
value: string;
|
|
24
|
+
chainId: string;
|
|
25
|
+
type: string;
|
|
26
|
+
v: string;
|
|
27
|
+
r: string;
|
|
28
|
+
s: string;
|
|
29
|
+
accessList?: Array<{
|
|
30
|
+
address: string;
|
|
31
|
+
storageKeys: string[];
|
|
32
|
+
}>;
|
|
33
|
+
}): string;
|
|
34
|
+
/**
|
|
35
|
+
* Validate the attestation transaction:
|
|
36
|
+
* - tx.to matches COINBASE_ATTESTER_CONTRACT
|
|
37
|
+
* - function selector matches the circuit's expected selector
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateAttestationTx(rawTransaction: string, circuitId: CircuitId): {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Recover the Coinbase attester's uncompressed public key from the transaction signature.
|
|
45
|
+
* Returns "0x04..." (130 hex chars).
|
|
46
|
+
*/
|
|
47
|
+
export declare function recoverAttesterPubkey(rawTransaction: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Get the signer address from a recovered public key.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getSignerAddress(pubkey: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Full attestation fetch pipeline:
|
|
54
|
+
* 1. Query EAS GraphQL for the latest attestation
|
|
55
|
+
* 2. Fetch the raw transaction from RPC
|
|
56
|
+
* 3. Validate transaction fields
|
|
57
|
+
* 4. Return attestation + raw transaction
|
|
58
|
+
*/
|
|
59
|
+
export declare function fetchAttestation(config: ClientConfig, circuitId: CircuitId, recipientAddress: string): Promise<AttestationData>;
|
|
60
|
+
//# sourceMappingURL=attestation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attestation.d.ts","sourceRoot":"","sources":["../src/attestation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkC3F;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,cAAc,CAAC,CAkCzB;AAID;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAgDjB;AAID;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CAChE,GAAG,MAAM,CAuBT;AAID;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,SAAS,GACnB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAsBpC;AAID;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CA0BpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAID;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,eAAe,CAAC,CAwB1B"}
|