@zkproofport-app/sdk 0.1.3-beta.1 → 0.2.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/README.md +80 -98
- package/dist/ProofportSDK.d.ts +0 -74
- package/dist/constants.d.ts +0 -42
- package/dist/index.esm.js +1 -243
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -243
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +0 -70
- package/dist/verifier.d.ts +0 -77
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -140,51 +140,6 @@ const DEFAULT_REQUEST_EXPIRY_MS = 10 * 60 * 1000;
|
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
142
|
const MAX_QR_DATA_SIZE = 2953; // Version 40 with L error correction
|
|
143
|
-
/**
|
|
144
|
-
* ZKProofportNullifierRegistry contract ABI (V2).
|
|
145
|
-
*
|
|
146
|
-
* This is the current nullifier registry interface with relayer-only registration.
|
|
147
|
-
* Public view functions allow checking nullifier status and verifying proofs without registration.
|
|
148
|
-
*
|
|
149
|
-
* Key functions:
|
|
150
|
-
* - `isNullifierRegistered`: Check if a nullifier has been used
|
|
151
|
-
* - `getNullifierInfo`: Get registration details for a nullifier
|
|
152
|
-
* - `verifyOnly`: Verify a proof without registering the nullifier
|
|
153
|
-
*
|
|
154
|
-
* Note: Registration functions (verifyAndRegister) are relayer-only and not exposed in this ABI.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* import { Contract } from 'ethers';
|
|
159
|
-
*
|
|
160
|
-
* const registry = new Contract(
|
|
161
|
-
* registryAddress,
|
|
162
|
-
* ZKPROOFPORT_NULLIFIER_REGISTRY_ABI,
|
|
163
|
-
* provider
|
|
164
|
-
* );
|
|
165
|
-
*
|
|
166
|
-
* const isUsed = await registry.isNullifierRegistered(nullifier);
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
const ZKPROOFPORT_NULLIFIER_REGISTRY_ABI = [
|
|
170
|
-
'function isNullifierRegistered(bytes32 _nullifier) external view returns (bool)',
|
|
171
|
-
'function getNullifierInfo(bytes32 _nullifier) external view returns (uint64 registeredAt, bytes32 scope, bytes32 circuitId)',
|
|
172
|
-
'function verifyOnly(bytes32 _circuitId, bytes calldata _proof, bytes32[] calldata _publicInputs) external view returns (bool)',
|
|
173
|
-
'event NullifierRegistered(bytes32 indexed nullifier, bytes32 indexed scope, bytes32 indexed circuitId)',
|
|
174
|
-
];
|
|
175
|
-
|
|
176
|
-
var constants = /*#__PURE__*/Object.freeze({
|
|
177
|
-
__proto__: null,
|
|
178
|
-
CIRCUIT_METADATA: CIRCUIT_METADATA,
|
|
179
|
-
DEEP_LINK_HOSTS: DEEP_LINK_HOSTS,
|
|
180
|
-
DEFAULT_REQUEST_EXPIRY_MS: DEFAULT_REQUEST_EXPIRY_MS,
|
|
181
|
-
DEFAULT_SCHEME: DEFAULT_SCHEME,
|
|
182
|
-
MAX_QR_DATA_SIZE: MAX_QR_DATA_SIZE,
|
|
183
|
-
RELAY_URLS: RELAY_URLS,
|
|
184
|
-
RPC_ENDPOINTS: RPC_ENDPOINTS,
|
|
185
|
-
VERIFIER_ABI: VERIFIER_ABI,
|
|
186
|
-
ZKPROOFPORT_NULLIFIER_REGISTRY_ABI: ZKPROOFPORT_NULLIFIER_REGISTRY_ABI
|
|
187
|
-
});
|
|
188
143
|
|
|
189
144
|
/**
|
|
190
145
|
* Deep Link utilities for ZKProofport SDK
|
|
@@ -383,7 +338,6 @@ function parseProofResponseUrl(url) {
|
|
|
383
338
|
if (timestamp) {
|
|
384
339
|
response.timestamp = parseInt(timestamp, 10);
|
|
385
340
|
}
|
|
386
|
-
response.nullifier = urlObj.searchParams.get('nullifier') || undefined;
|
|
387
341
|
}
|
|
388
342
|
else if (status === 'error') {
|
|
389
343
|
response.error = urlObj.searchParams.get('error') || undefined;
|
|
@@ -911,41 +865,6 @@ function extractScopeFromPublicInputs(publicInputsHex, circuit) {
|
|
|
911
865
|
const scopeFields = publicInputsHex.slice(start, end + 1);
|
|
912
866
|
return reconstructBytes32FromFields(scopeFields);
|
|
913
867
|
}
|
|
914
|
-
/**
|
|
915
|
-
* Extract nullifier value from public inputs array.
|
|
916
|
-
*
|
|
917
|
-
* The nullifier is a bytes32 value encoded across 32 consecutive field elements
|
|
918
|
-
* in the public inputs. The exact position depends on the circuit type.
|
|
919
|
-
* Nullifiers are used for duplicate proof detection and must be unique per user+scope.
|
|
920
|
-
*
|
|
921
|
-
* @param publicInputsHex - Array of public input hex strings (zero-padded to 32 bytes)
|
|
922
|
-
* @param circuit - Optional circuit identifier to determine field positions
|
|
923
|
-
* @returns Reconstructed nullifier as hex string with 0x prefix, or null if inputs are insufficient
|
|
924
|
-
*
|
|
925
|
-
* @example
|
|
926
|
-
* ```typescript
|
|
927
|
-
* const nullifier = extractNullifierFromPublicInputs(publicInputsHex, 'coinbase_attestation');
|
|
928
|
-
* console.log(nullifier); // '0xabcd1234...'
|
|
929
|
-
*
|
|
930
|
-
* // Check if nullifier is already registered
|
|
931
|
-
* const isRegistered = await isNullifierRegistered(nullifier, registryAddress, provider);
|
|
932
|
-
* ```
|
|
933
|
-
*/
|
|
934
|
-
function extractNullifierFromPublicInputs(publicInputsHex, circuit) {
|
|
935
|
-
let start, end;
|
|
936
|
-
if (circuit === 'coinbase_country_attestation') {
|
|
937
|
-
start = 118;
|
|
938
|
-
end = 149;
|
|
939
|
-
}
|
|
940
|
-
else {
|
|
941
|
-
start = 96;
|
|
942
|
-
end = 127;
|
|
943
|
-
}
|
|
944
|
-
if (publicInputsHex.length <= end)
|
|
945
|
-
return null;
|
|
946
|
-
const nullifierFields = publicInputsHex.slice(start, end + 1);
|
|
947
|
-
return reconstructBytes32FromFields(nullifierFields);
|
|
948
|
-
}
|
|
949
868
|
/** @internal Reconstruct a bytes32 value from 32 individual field elements */
|
|
950
869
|
function reconstructBytes32FromFields(fields) {
|
|
951
870
|
if (fields.length !== 32) {
|
|
@@ -957,83 +876,6 @@ function reconstructBytes32FromFields(fields) {
|
|
|
957
876
|
}).join('');
|
|
958
877
|
return '0x' + bytes;
|
|
959
878
|
}
|
|
960
|
-
/**
|
|
961
|
-
* Check if a nullifier is already registered on-chain in the ZKProofport nullifier registry.
|
|
962
|
-
*
|
|
963
|
-
* This function queries the on-chain nullifier registry contract to determine if a nullifier
|
|
964
|
-
* has been used before. This is used to prevent duplicate proof submissions from the same user
|
|
965
|
-
* for the same scope.
|
|
966
|
-
*
|
|
967
|
-
* @param nullifier - The nullifier hash as hex string with 0x prefix
|
|
968
|
-
* @param registryAddress - ZKProofportNullifierRegistry contract address
|
|
969
|
-
* @param provider - ethers.js Provider instance (v5 or v6 compatible)
|
|
970
|
-
* @returns Promise resolving to true if nullifier is registered, false otherwise
|
|
971
|
-
*
|
|
972
|
-
* @example
|
|
973
|
-
* ```typescript
|
|
974
|
-
* const nullifier = extractNullifierFromPublicInputs(publicInputsHex, circuit);
|
|
975
|
-
* const isRegistered = await isNullifierRegistered(
|
|
976
|
-
* nullifier,
|
|
977
|
-
* '0x...',
|
|
978
|
-
* provider
|
|
979
|
-
* );
|
|
980
|
-
*
|
|
981
|
-
* if (isRegistered) {
|
|
982
|
-
* console.log('This nullifier has already been used');
|
|
983
|
-
* }
|
|
984
|
-
* ```
|
|
985
|
-
*/
|
|
986
|
-
async function isNullifierRegistered(nullifier, registryAddress, provider) {
|
|
987
|
-
const { ZKPROOFPORT_NULLIFIER_REGISTRY_ABI } = await Promise.resolve().then(function () { return constants; });
|
|
988
|
-
const contract = new ethers.ethers.Contract(registryAddress, ZKPROOFPORT_NULLIFIER_REGISTRY_ABI, provider);
|
|
989
|
-
try {
|
|
990
|
-
return await contract.isNullifierRegistered(nullifier);
|
|
991
|
-
}
|
|
992
|
-
catch {
|
|
993
|
-
return false;
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* Get detailed information about a registered nullifier from the on-chain registry.
|
|
998
|
-
*
|
|
999
|
-
* This function retrieves the registration timestamp, scope, and circuit ID for a nullifier
|
|
1000
|
-
* that has been registered on-chain. This metadata is useful for auditing and analytics.
|
|
1001
|
-
*
|
|
1002
|
-
* @param nullifier - The nullifier hash as hex string with 0x prefix
|
|
1003
|
-
* @param registryAddress - ZKProofportNullifierRegistry contract address
|
|
1004
|
-
* @param provider - ethers.js Provider instance (v5 or v6 compatible)
|
|
1005
|
-
* @returns Promise resolving to nullifier info object, or null if not registered
|
|
1006
|
-
*
|
|
1007
|
-
* @example
|
|
1008
|
-
* ```typescript
|
|
1009
|
-
* const info = await getNullifierInfo(nullifier, registryAddress, provider);
|
|
1010
|
-
*
|
|
1011
|
-
* if (info) {
|
|
1012
|
-
* console.log('Registered at:', new Date(info.registeredAt * 1000));
|
|
1013
|
-
* console.log('Scope:', info.scope);
|
|
1014
|
-
* console.log('Circuit:', info.circuitId);
|
|
1015
|
-
* } else {
|
|
1016
|
-
* console.log('Nullifier not registered');
|
|
1017
|
-
* }
|
|
1018
|
-
* ```
|
|
1019
|
-
*/
|
|
1020
|
-
async function getNullifierInfo(nullifier, registryAddress, provider) {
|
|
1021
|
-
const { ZKPROOFPORT_NULLIFIER_REGISTRY_ABI } = await Promise.resolve().then(function () { return constants; });
|
|
1022
|
-
const contract = new ethers.ethers.Contract(registryAddress, ZKPROOFPORT_NULLIFIER_REGISTRY_ABI, provider);
|
|
1023
|
-
try {
|
|
1024
|
-
const [registeredAt, scope, circuitId] = await contract.getNullifierInfo(nullifier);
|
|
1025
|
-
if (BigInt(registeredAt) === 0n)
|
|
1026
|
-
return null;
|
|
1027
|
-
return {
|
|
1028
|
-
registeredAt: Number(registeredAt),
|
|
1029
|
-
scope: scope,
|
|
1030
|
-
circuitId: circuitId,
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
catch {
|
|
1034
|
-
return null;
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
879
|
|
|
1038
880
|
/**
|
|
1039
881
|
* Proofport SDK - Main class
|
|
@@ -1108,7 +950,6 @@ class ProofportSDK {
|
|
|
1108
950
|
verifiers: config.verifiers || {},
|
|
1109
951
|
};
|
|
1110
952
|
this.relayUrl = config.relayUrl || '';
|
|
1111
|
-
this.nullifierRegistry = config.nullifierRegistry;
|
|
1112
953
|
}
|
|
1113
954
|
// ============ Request Creation ============
|
|
1114
955
|
/**
|
|
@@ -2181,30 +2022,7 @@ class ProofportSDK {
|
|
|
2181
2022
|
this.socket = null;
|
|
2182
2023
|
}
|
|
2183
2024
|
}
|
|
2184
|
-
// ============
|
|
2185
|
-
/**
|
|
2186
|
-
* Extracts the nullifier from proof public inputs.
|
|
2187
|
-
*
|
|
2188
|
-
* The nullifier is a bytes32 value derived from the user's address and scope,
|
|
2189
|
-
* used to prevent duplicate proof submissions. Each user+scope combination
|
|
2190
|
-
* produces a unique nullifier.
|
|
2191
|
-
*
|
|
2192
|
-
* @param publicInputs - Array of public input hex strings from proof response
|
|
2193
|
-
* @param circuit - Circuit type to determine field positions
|
|
2194
|
-
* @returns Nullifier as hex string (0x...), or null if inputs are insufficient
|
|
2195
|
-
*
|
|
2196
|
-
* @example
|
|
2197
|
-
* ```typescript
|
|
2198
|
-
* const result = await sdk.waitForProof(relay.requestId);
|
|
2199
|
-
* if (result.status === 'completed') {
|
|
2200
|
-
* const nullifier = sdk.extractNullifier(result.publicInputs, result.circuit);
|
|
2201
|
-
* console.log('Nullifier:', nullifier);
|
|
2202
|
-
* }
|
|
2203
|
-
* ```
|
|
2204
|
-
*/
|
|
2205
|
-
extractNullifier(publicInputs, circuit) {
|
|
2206
|
-
return extractNullifierFromPublicInputs(publicInputs, circuit);
|
|
2207
|
-
}
|
|
2025
|
+
// ============ Public Input Utilities ============
|
|
2208
2026
|
/**
|
|
2209
2027
|
* Extracts the scope from proof public inputs.
|
|
2210
2028
|
*
|
|
@@ -2227,66 +2045,6 @@ class ProofportSDK {
|
|
|
2227
2045
|
extractScope(publicInputs, circuit) {
|
|
2228
2046
|
return extractScopeFromPublicInputs(publicInputs, circuit);
|
|
2229
2047
|
}
|
|
2230
|
-
/**
|
|
2231
|
-
* Checks if a nullifier is already registered on-chain.
|
|
2232
|
-
*
|
|
2233
|
-
* Queries the ZKProofportNullifierRegistry contract to determine if the
|
|
2234
|
-
* nullifier has been used before. Used to prevent duplicate proof submissions.
|
|
2235
|
-
*
|
|
2236
|
-
* Requires `nullifierRegistry` in SDK config.
|
|
2237
|
-
*
|
|
2238
|
-
* @param nullifier - Nullifier hex string from extractNullifier()
|
|
2239
|
-
* @param provider - Optional ethers provider (defaults to public RPC for configured chain)
|
|
2240
|
-
* @returns True if nullifier is already registered
|
|
2241
|
-
* @throws Error if nullifierRegistry is not configured
|
|
2242
|
-
*
|
|
2243
|
-
* @example
|
|
2244
|
-
* ```typescript
|
|
2245
|
-
* const sdk = ProofportSDK.create({
|
|
2246
|
-
* relayUrl: 'https://relay.zkproofport.app',
|
|
2247
|
-
* nullifierRegistry: { address: '0x...', chainId: 8453 }
|
|
2248
|
-
* });
|
|
2249
|
-
*
|
|
2250
|
-
* const nullifier = sdk.extractNullifier(publicInputs, circuit);
|
|
2251
|
-
* const isDuplicate = await sdk.checkNullifier(nullifier);
|
|
2252
|
-
* ```
|
|
2253
|
-
*/
|
|
2254
|
-
async checkNullifier(nullifier, provider) {
|
|
2255
|
-
if (!this.nullifierRegistry) {
|
|
2256
|
-
throw new Error('nullifierRegistry is required. Set it in ProofportSDK config.');
|
|
2257
|
-
}
|
|
2258
|
-
const p = provider || getDefaultProvider(this.nullifierRegistry.chainId);
|
|
2259
|
-
return isNullifierRegistered(nullifier, this.nullifierRegistry.address, p);
|
|
2260
|
-
}
|
|
2261
|
-
/**
|
|
2262
|
-
* Gets detailed information about a registered nullifier from on-chain registry.
|
|
2263
|
-
*
|
|
2264
|
-
* Retrieves the registration timestamp, scope, and circuit ID for a nullifier.
|
|
2265
|
-
* Returns null if the nullifier is not registered.
|
|
2266
|
-
*
|
|
2267
|
-
* Requires `nullifierRegistry` in SDK config.
|
|
2268
|
-
*
|
|
2269
|
-
* @param nullifier - Nullifier hex string from extractNullifier()
|
|
2270
|
-
* @param provider - Optional ethers provider (defaults to public RPC for configured chain)
|
|
2271
|
-
* @returns Nullifier info or null if not registered
|
|
2272
|
-
* @throws Error if nullifierRegistry is not configured
|
|
2273
|
-
*
|
|
2274
|
-
* @example
|
|
2275
|
-
* ```typescript
|
|
2276
|
-
* const info = await sdk.getNullifierDetails(nullifier);
|
|
2277
|
-
* if (info) {
|
|
2278
|
-
* console.log('Registered at:', new Date(info.registeredAt * 1000));
|
|
2279
|
-
* console.log('Circuit:', info.circuitId);
|
|
2280
|
-
* }
|
|
2281
|
-
* ```
|
|
2282
|
-
*/
|
|
2283
|
-
async getNullifierDetails(nullifier, provider) {
|
|
2284
|
-
if (!this.nullifierRegistry) {
|
|
2285
|
-
throw new Error('nullifierRegistry is required. Set it in ProofportSDK config.');
|
|
2286
|
-
}
|
|
2287
|
-
const p = provider || getDefaultProvider(this.nullifierRegistry.chainId);
|
|
2288
|
-
return getNullifierInfo(nullifier, this.nullifierRegistry.address, p);
|
|
2289
|
-
}
|
|
2290
2048
|
}
|
|
2291
2049
|
|
|
2292
2050
|
exports.ProofportSDK = ProofportSDK;
|