@zkproofport-app/sdk 0.1.2-beta.1
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/LICENSE +21 -0
- package/README.md +469 -0
- package/dist/ProofportSDK.d.ts +1011 -0
- package/dist/constants.d.ts +223 -0
- package/dist/deeplink.d.ts +192 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.esm.js +5225 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2364 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5225 -0
- package/dist/index.mjs.map +1 -0
- package/dist/qrcode.d.ts +120 -0
- package/dist/types.d.ts +434 -0
- package/dist/verifier.d.ts +224 -0
- package/package.json +75 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-chain verification utilities for ZKProofport SDK
|
|
3
|
+
*
|
|
4
|
+
* Compatible with both ethers v5 and v6.
|
|
5
|
+
*/
|
|
6
|
+
import { ethers } from 'ethers';
|
|
7
|
+
import type { CircuitType, ParsedProof, VerifierContract } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Get verifier contract instance for interacting with on-chain verifier contracts.
|
|
10
|
+
*
|
|
11
|
+
* @param providerOrSigner - ethers.js Provider or Signer instance (v5 or v6 compatible)
|
|
12
|
+
* @param verifier - Verifier contract configuration containing address and ABI
|
|
13
|
+
* @returns ethers.Contract instance connected to the verifier
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
18
|
+
* const contract = getVerifierContract(provider, {
|
|
19
|
+
* address: '0x...',
|
|
20
|
+
* chainId: 11155111,
|
|
21
|
+
* abi: VERIFIER_ABI
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function getVerifierContract(providerOrSigner: any, verifier: VerifierContract): ethers.Contract;
|
|
26
|
+
/**
|
|
27
|
+
* Get default JSON-RPC provider for a chain using pre-configured RPC endpoints.
|
|
28
|
+
*
|
|
29
|
+
* @param chainId - The chain ID (e.g., 11155111 for Sepolia, 84532 for Base Sepolia)
|
|
30
|
+
* @returns ethers.JsonRpcProvider instance for the specified chain
|
|
31
|
+
* @throws Error if no RPC endpoint is configured for the chain
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const provider = getDefaultProvider(11155111); // Sepolia
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function getDefaultProvider(chainId: number): any;
|
|
39
|
+
/**
|
|
40
|
+
* Verify a zero-knowledge proof on-chain by calling the verifier smart contract.
|
|
41
|
+
*
|
|
42
|
+
* This function resolves the verifier contract from SDK config or proof response,
|
|
43
|
+
* connects to the blockchain, and calls the verify() method with the proof and public inputs.
|
|
44
|
+
*
|
|
45
|
+
* @param circuit - The canonical circuit identifier (e.g., "coinbase_attestation")
|
|
46
|
+
* @param parsedProof - Parsed proof object containing proofHex and publicInputsHex
|
|
47
|
+
* @param providerOrSigner - Optional ethers.js Provider or Signer instance. If not provided, uses default RPC for the chain
|
|
48
|
+
* @param customVerifier - Optional custom verifier contract config (takes priority over responseVerifier)
|
|
49
|
+
* @param responseVerifier - Optional verifier info from proof generation response
|
|
50
|
+
* @returns Promise resolving to verification result with valid flag and optional error message
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const parsed = parseProofForOnChain(proof, publicInputs, numPublicInputs);
|
|
55
|
+
* const result = await verifyProofOnChain(
|
|
56
|
+
* 'coinbase_attestation',
|
|
57
|
+
* parsed,
|
|
58
|
+
* provider,
|
|
59
|
+
* { address: '0x...', chainId: 11155111, abi: VERIFIER_ABI }
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* if (result.valid) {
|
|
63
|
+
* console.log('Proof is valid!');
|
|
64
|
+
* } else {
|
|
65
|
+
* console.error('Verification failed:', result.error);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifyProofOnChain(circuit: CircuitType, parsedProof: ParsedProof, providerOrSigner?: any, customVerifier?: VerifierContract, responseVerifier?: {
|
|
70
|
+
verifierAddress?: string;
|
|
71
|
+
chainId?: number;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
valid: boolean;
|
|
74
|
+
error?: string;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Parse proof response into format suitable for on-chain verification.
|
|
78
|
+
*
|
|
79
|
+
* Converts proof and public inputs from relay response format to the format
|
|
80
|
+
* expected by Solidity verifier contracts. Public inputs are zero-padded to
|
|
81
|
+
* 32 bytes (bytes32) to match Solidity's bytes32[] type.
|
|
82
|
+
*
|
|
83
|
+
* @param proof - Proof bytes as hex string (with or without 0x prefix)
|
|
84
|
+
* @param publicInputs - Array of public input values as hex strings
|
|
85
|
+
* @param numPublicInputs - Number of public inputs (for validation)
|
|
86
|
+
* @returns Parsed proof object ready for on-chain verification
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const parsed = parseProofForOnChain(
|
|
91
|
+
* '0x1a2b3c...',
|
|
92
|
+
* ['0x01', '0x02', '0x03'],
|
|
93
|
+
* 3
|
|
94
|
+
* );
|
|
95
|
+
*
|
|
96
|
+
* // parsed.proofHex: '0x1a2b3c...'
|
|
97
|
+
* // parsed.publicInputsHex: ['0x0000...01', '0x0000...02', '0x0000...03']
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function parseProofForOnChain(proof: string, publicInputs: string[], numPublicInputs: number): ParsedProof;
|
|
101
|
+
/**
|
|
102
|
+
* Get verifier contract address for a circuit.
|
|
103
|
+
*
|
|
104
|
+
* @param circuit - The canonical circuit identifier (e.g., "coinbase_attestation")
|
|
105
|
+
* @param customVerifier - Optional custom verifier contract config
|
|
106
|
+
* @returns Verifier contract address as hex string
|
|
107
|
+
* @throws Error if no verifier is configured for the circuit
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const address = getVerifierAddress('coinbase_attestation', verifierConfig);
|
|
112
|
+
* console.log(address); // '0x1234...'
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function getVerifierAddress(circuit: CircuitType, customVerifier?: VerifierContract): string;
|
|
116
|
+
/**
|
|
117
|
+
* Get chain ID for a circuit's verifier contract.
|
|
118
|
+
*
|
|
119
|
+
* @param circuit - The canonical circuit identifier (e.g., "coinbase_attestation")
|
|
120
|
+
* @param customVerifier - Optional custom verifier contract config
|
|
121
|
+
* @returns Chain ID number (e.g., 11155111 for Sepolia, 84532 for Base Sepolia)
|
|
122
|
+
* @throws Error if no verifier is configured for the circuit
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const chainId = getVerifierChainId('coinbase_attestation', verifierConfig);
|
|
127
|
+
* console.log(chainId); // 11155111
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function getVerifierChainId(circuit: CircuitType, customVerifier?: VerifierContract): number;
|
|
131
|
+
/**
|
|
132
|
+
* Extract scope value from public inputs array.
|
|
133
|
+
*
|
|
134
|
+
* The scope is a bytes32 value encoded across 32 consecutive field elements
|
|
135
|
+
* in the public inputs. The exact position depends on the circuit type.
|
|
136
|
+
*
|
|
137
|
+
* @param publicInputsHex - Array of public input hex strings (zero-padded to 32 bytes)
|
|
138
|
+
* @param circuit - Optional circuit identifier to determine field positions
|
|
139
|
+
* @returns Reconstructed scope as hex string with 0x prefix, or null if inputs are insufficient
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const scope = extractScopeFromPublicInputs(publicInputsHex, 'coinbase_attestation');
|
|
144
|
+
* console.log(scope); // '0x7a6b70726f6f66706f72742e636f6d...'
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function extractScopeFromPublicInputs(publicInputsHex: string[], circuit?: string): string | null;
|
|
148
|
+
/**
|
|
149
|
+
* Extract nullifier value from public inputs array.
|
|
150
|
+
*
|
|
151
|
+
* The nullifier is a bytes32 value encoded across 32 consecutive field elements
|
|
152
|
+
* in the public inputs. The exact position depends on the circuit type.
|
|
153
|
+
* Nullifiers are used for duplicate proof detection and must be unique per user+scope.
|
|
154
|
+
*
|
|
155
|
+
* @param publicInputsHex - Array of public input hex strings (zero-padded to 32 bytes)
|
|
156
|
+
* @param circuit - Optional circuit identifier to determine field positions
|
|
157
|
+
* @returns Reconstructed nullifier as hex string with 0x prefix, or null if inputs are insufficient
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const nullifier = extractNullifierFromPublicInputs(publicInputsHex, 'coinbase_attestation');
|
|
162
|
+
* console.log(nullifier); // '0xabcd1234...'
|
|
163
|
+
*
|
|
164
|
+
* // Check if nullifier is already registered
|
|
165
|
+
* const isRegistered = await isNullifierRegistered(nullifier, registryAddress, provider);
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function extractNullifierFromPublicInputs(publicInputsHex: string[], circuit?: string): string | null;
|
|
169
|
+
/**
|
|
170
|
+
* Check if a nullifier is already registered on-chain in the ZKProofport nullifier registry.
|
|
171
|
+
*
|
|
172
|
+
* This function queries the on-chain nullifier registry contract to determine if a nullifier
|
|
173
|
+
* has been used before. This is used to prevent duplicate proof submissions from the same user
|
|
174
|
+
* for the same scope.
|
|
175
|
+
*
|
|
176
|
+
* @param nullifier - The nullifier hash as hex string with 0x prefix
|
|
177
|
+
* @param registryAddress - ZKProofportNullifierRegistry contract address
|
|
178
|
+
* @param provider - ethers.js Provider instance (v5 or v6 compatible)
|
|
179
|
+
* @returns Promise resolving to true if nullifier is registered, false otherwise
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const nullifier = extractNullifierFromPublicInputs(publicInputsHex, circuit);
|
|
184
|
+
* const isRegistered = await isNullifierRegistered(
|
|
185
|
+
* nullifier,
|
|
186
|
+
* '0x...',
|
|
187
|
+
* provider
|
|
188
|
+
* );
|
|
189
|
+
*
|
|
190
|
+
* if (isRegistered) {
|
|
191
|
+
* console.log('This nullifier has already been used');
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export declare function isNullifierRegistered(nullifier: string, registryAddress: string, provider: any): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Get detailed information about a registered nullifier from the on-chain registry.
|
|
198
|
+
*
|
|
199
|
+
* This function retrieves the registration timestamp, scope, and circuit ID for a nullifier
|
|
200
|
+
* that has been registered on-chain. This metadata is useful for auditing and analytics.
|
|
201
|
+
*
|
|
202
|
+
* @param nullifier - The nullifier hash as hex string with 0x prefix
|
|
203
|
+
* @param registryAddress - ZKProofportNullifierRegistry contract address
|
|
204
|
+
* @param provider - ethers.js Provider instance (v5 or v6 compatible)
|
|
205
|
+
* @returns Promise resolving to nullifier info object, or null if not registered
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const info = await getNullifierInfo(nullifier, registryAddress, provider);
|
|
210
|
+
*
|
|
211
|
+
* if (info) {
|
|
212
|
+
* console.log('Registered at:', new Date(info.registeredAt * 1000));
|
|
213
|
+
* console.log('Scope:', info.scope);
|
|
214
|
+
* console.log('Circuit:', info.circuitId);
|
|
215
|
+
* } else {
|
|
216
|
+
* console.log('Nullifier not registered');
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function getNullifierInfo(nullifier: string, registryAddress: string, provider: any): Promise<{
|
|
221
|
+
registeredAt: number;
|
|
222
|
+
scope: string;
|
|
223
|
+
circuitId: string;
|
|
224
|
+
} | null>;
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zkproofport-app/sdk",
|
|
3
|
+
"version": "0.1.2-beta.1",
|
|
4
|
+
"description": "ZKProofport SDK for requesting zero-knowledge proofs from the ZKProofport mobile app and verifying them on-chain",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.esm.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rollup -c",
|
|
22
|
+
"dev": "rollup -c -w",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"demo": "cd demo && node server.js",
|
|
25
|
+
"docs": "typedoc",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"qrcode": "^1.5.3",
|
|
30
|
+
"socket.io-client": "^4.8.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
34
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
35
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
36
|
+
"@types/qrcode": "^1.5.5",
|
|
37
|
+
"ethers": "^6.16.0",
|
|
38
|
+
"rollup": "^4.9.6",
|
|
39
|
+
"tslib": "^2.8.1",
|
|
40
|
+
"typedoc": "^0.28.16",
|
|
41
|
+
"typescript": "^5.3.3",
|
|
42
|
+
"vitest": "^4.0.18"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"ethers": "^5.7.0 || ^6.0.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"ethers": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"zk",
|
|
54
|
+
"zero-knowledge",
|
|
55
|
+
"proof",
|
|
56
|
+
"verification",
|
|
57
|
+
"ethereum",
|
|
58
|
+
"blockchain",
|
|
59
|
+
"zkproofport"
|
|
60
|
+
],
|
|
61
|
+
"author": "ZKProofport",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/zkproofport/proofport-app-sdk.git"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/zkproofport/proofport-app-sdk#readme",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/zkproofport/proofport-app-sdk/issues"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=16.0.0"
|
|
73
|
+
},
|
|
74
|
+
"sideEffects": false
|
|
75
|
+
}
|