@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/dist/index.esm.js CHANGED
@@ -135,51 +135,6 @@ const DEFAULT_REQUEST_EXPIRY_MS = 10 * 60 * 1000;
135
135
  * ```
136
136
  */
137
137
  const MAX_QR_DATA_SIZE = 2953; // Version 40 with L error correction
138
- /**
139
- * ZKProofportNullifierRegistry contract ABI (V2).
140
- *
141
- * This is the current nullifier registry interface with relayer-only registration.
142
- * Public view functions allow checking nullifier status and verifying proofs without registration.
143
- *
144
- * Key functions:
145
- * - `isNullifierRegistered`: Check if a nullifier has been used
146
- * - `getNullifierInfo`: Get registration details for a nullifier
147
- * - `verifyOnly`: Verify a proof without registering the nullifier
148
- *
149
- * Note: Registration functions (verifyAndRegister) are relayer-only and not exposed in this ABI.
150
- *
151
- * @example
152
- * ```typescript
153
- * import { Contract } from 'ethers';
154
- *
155
- * const registry = new Contract(
156
- * registryAddress,
157
- * ZKPROOFPORT_NULLIFIER_REGISTRY_ABI,
158
- * provider
159
- * );
160
- *
161
- * const isUsed = await registry.isNullifierRegistered(nullifier);
162
- * ```
163
- */
164
- const ZKPROOFPORT_NULLIFIER_REGISTRY_ABI = [
165
- 'function isNullifierRegistered(bytes32 _nullifier) external view returns (bool)',
166
- 'function getNullifierInfo(bytes32 _nullifier) external view returns (uint64 registeredAt, bytes32 scope, bytes32 circuitId)',
167
- 'function verifyOnly(bytes32 _circuitId, bytes calldata _proof, bytes32[] calldata _publicInputs) external view returns (bool)',
168
- 'event NullifierRegistered(bytes32 indexed nullifier, bytes32 indexed scope, bytes32 indexed circuitId)',
169
- ];
170
-
171
- var constants = /*#__PURE__*/Object.freeze({
172
- __proto__: null,
173
- CIRCUIT_METADATA: CIRCUIT_METADATA,
174
- DEEP_LINK_HOSTS: DEEP_LINK_HOSTS,
175
- DEFAULT_REQUEST_EXPIRY_MS: DEFAULT_REQUEST_EXPIRY_MS,
176
- DEFAULT_SCHEME: DEFAULT_SCHEME,
177
- MAX_QR_DATA_SIZE: MAX_QR_DATA_SIZE,
178
- RELAY_URLS: RELAY_URLS,
179
- RPC_ENDPOINTS: RPC_ENDPOINTS,
180
- VERIFIER_ABI: VERIFIER_ABI,
181
- ZKPROOFPORT_NULLIFIER_REGISTRY_ABI: ZKPROOFPORT_NULLIFIER_REGISTRY_ABI
182
- });
183
138
 
184
139
  /**
185
140
  * Deep Link utilities for ZKProofport SDK
@@ -378,7 +333,6 @@ function parseProofResponseUrl(url) {
378
333
  if (timestamp) {
379
334
  response.timestamp = parseInt(timestamp, 10);
380
335
  }
381
- response.nullifier = urlObj.searchParams.get('nullifier') || undefined;
382
336
  }
383
337
  else if (status === 'error') {
384
338
  response.error = urlObj.searchParams.get('error') || undefined;
@@ -3773,41 +3727,6 @@ function extractScopeFromPublicInputs(publicInputsHex, circuit) {
3773
3727
  const scopeFields = publicInputsHex.slice(start, end + 1);
3774
3728
  return reconstructBytes32FromFields(scopeFields);
3775
3729
  }
3776
- /**
3777
- * Extract nullifier value from public inputs array.
3778
- *
3779
- * The nullifier is a bytes32 value encoded across 32 consecutive field elements
3780
- * in the public inputs. The exact position depends on the circuit type.
3781
- * Nullifiers are used for duplicate proof detection and must be unique per user+scope.
3782
- *
3783
- * @param publicInputsHex - Array of public input hex strings (zero-padded to 32 bytes)
3784
- * @param circuit - Optional circuit identifier to determine field positions
3785
- * @returns Reconstructed nullifier as hex string with 0x prefix, or null if inputs are insufficient
3786
- *
3787
- * @example
3788
- * ```typescript
3789
- * const nullifier = extractNullifierFromPublicInputs(publicInputsHex, 'coinbase_attestation');
3790
- * console.log(nullifier); // '0xabcd1234...'
3791
- *
3792
- * // Check if nullifier is already registered
3793
- * const isRegistered = await isNullifierRegistered(nullifier, registryAddress, provider);
3794
- * ```
3795
- */
3796
- function extractNullifierFromPublicInputs(publicInputsHex, circuit) {
3797
- let start, end;
3798
- if (circuit === 'coinbase_country_attestation') {
3799
- start = 118;
3800
- end = 149;
3801
- }
3802
- else {
3803
- start = 96;
3804
- end = 127;
3805
- }
3806
- if (publicInputsHex.length <= end)
3807
- return null;
3808
- const nullifierFields = publicInputsHex.slice(start, end + 1);
3809
- return reconstructBytes32FromFields(nullifierFields);
3810
- }
3811
3730
  /** @internal Reconstruct a bytes32 value from 32 individual field elements */
3812
3731
  function reconstructBytes32FromFields(fields) {
3813
3732
  if (fields.length !== 32) {
@@ -3819,83 +3738,6 @@ function reconstructBytes32FromFields(fields) {
3819
3738
  }).join('');
3820
3739
  return '0x' + bytes;
3821
3740
  }
3822
- /**
3823
- * Check if a nullifier is already registered on-chain in the ZKProofport nullifier registry.
3824
- *
3825
- * This function queries the on-chain nullifier registry contract to determine if a nullifier
3826
- * has been used before. This is used to prevent duplicate proof submissions from the same user
3827
- * for the same scope.
3828
- *
3829
- * @param nullifier - The nullifier hash as hex string with 0x prefix
3830
- * @param registryAddress - ZKProofportNullifierRegistry contract address
3831
- * @param provider - ethers.js Provider instance (v5 or v6 compatible)
3832
- * @returns Promise resolving to true if nullifier is registered, false otherwise
3833
- *
3834
- * @example
3835
- * ```typescript
3836
- * const nullifier = extractNullifierFromPublicInputs(publicInputsHex, circuit);
3837
- * const isRegistered = await isNullifierRegistered(
3838
- * nullifier,
3839
- * '0x...',
3840
- * provider
3841
- * );
3842
- *
3843
- * if (isRegistered) {
3844
- * console.log('This nullifier has already been used');
3845
- * }
3846
- * ```
3847
- */
3848
- async function isNullifierRegistered(nullifier, registryAddress, provider) {
3849
- const { ZKPROOFPORT_NULLIFIER_REGISTRY_ABI } = await Promise.resolve().then(function () { return constants; });
3850
- const contract = new ethers.Contract(registryAddress, ZKPROOFPORT_NULLIFIER_REGISTRY_ABI, provider);
3851
- try {
3852
- return await contract.isNullifierRegistered(nullifier);
3853
- }
3854
- catch {
3855
- return false;
3856
- }
3857
- }
3858
- /**
3859
- * Get detailed information about a registered nullifier from the on-chain registry.
3860
- *
3861
- * This function retrieves the registration timestamp, scope, and circuit ID for a nullifier
3862
- * that has been registered on-chain. This metadata is useful for auditing and analytics.
3863
- *
3864
- * @param nullifier - The nullifier hash as hex string with 0x prefix
3865
- * @param registryAddress - ZKProofportNullifierRegistry contract address
3866
- * @param provider - ethers.js Provider instance (v5 or v6 compatible)
3867
- * @returns Promise resolving to nullifier info object, or null if not registered
3868
- *
3869
- * @example
3870
- * ```typescript
3871
- * const info = await getNullifierInfo(nullifier, registryAddress, provider);
3872
- *
3873
- * if (info) {
3874
- * console.log('Registered at:', new Date(info.registeredAt * 1000));
3875
- * console.log('Scope:', info.scope);
3876
- * console.log('Circuit:', info.circuitId);
3877
- * } else {
3878
- * console.log('Nullifier not registered');
3879
- * }
3880
- * ```
3881
- */
3882
- async function getNullifierInfo(nullifier, registryAddress, provider) {
3883
- const { ZKPROOFPORT_NULLIFIER_REGISTRY_ABI } = await Promise.resolve().then(function () { return constants; });
3884
- const contract = new ethers.Contract(registryAddress, ZKPROOFPORT_NULLIFIER_REGISTRY_ABI, provider);
3885
- try {
3886
- const [registeredAt, scope, circuitId] = await contract.getNullifierInfo(nullifier);
3887
- if (BigInt(registeredAt) === 0n)
3888
- return null;
3889
- return {
3890
- registeredAt: Number(registeredAt),
3891
- scope: scope,
3892
- circuitId: circuitId,
3893
- };
3894
- }
3895
- catch {
3896
- return null;
3897
- }
3898
- }
3899
3741
 
3900
3742
  /**
3901
3743
  * Proofport SDK - Main class
@@ -3970,7 +3812,6 @@ class ProofportSDK {
3970
3812
  verifiers: config.verifiers || {},
3971
3813
  };
3972
3814
  this.relayUrl = config.relayUrl || '';
3973
- this.nullifierRegistry = config.nullifierRegistry;
3974
3815
  }
3975
3816
  // ============ Request Creation ============
3976
3817
  /**
@@ -5043,30 +4884,7 @@ class ProofportSDK {
5043
4884
  this.socket = null;
5044
4885
  }
5045
4886
  }
5046
- // ============ Nullifier Utilities ============
5047
- /**
5048
- * Extracts the nullifier from proof public inputs.
5049
- *
5050
- * The nullifier is a bytes32 value derived from the user's address and scope,
5051
- * used to prevent duplicate proof submissions. Each user+scope combination
5052
- * produces a unique nullifier.
5053
- *
5054
- * @param publicInputs - Array of public input hex strings from proof response
5055
- * @param circuit - Circuit type to determine field positions
5056
- * @returns Nullifier as hex string (0x...), or null if inputs are insufficient
5057
- *
5058
- * @example
5059
- * ```typescript
5060
- * const result = await sdk.waitForProof(relay.requestId);
5061
- * if (result.status === 'completed') {
5062
- * const nullifier = sdk.extractNullifier(result.publicInputs, result.circuit);
5063
- * console.log('Nullifier:', nullifier);
5064
- * }
5065
- * ```
5066
- */
5067
- extractNullifier(publicInputs, circuit) {
5068
- return extractNullifierFromPublicInputs(publicInputs, circuit);
5069
- }
4887
+ // ============ Public Input Utilities ============
5070
4888
  /**
5071
4889
  * Extracts the scope from proof public inputs.
5072
4890
  *
@@ -5089,66 +4907,6 @@ class ProofportSDK {
5089
4907
  extractScope(publicInputs, circuit) {
5090
4908
  return extractScopeFromPublicInputs(publicInputs, circuit);
5091
4909
  }
5092
- /**
5093
- * Checks if a nullifier is already registered on-chain.
5094
- *
5095
- * Queries the ZKProofportNullifierRegistry contract to determine if the
5096
- * nullifier has been used before. Used to prevent duplicate proof submissions.
5097
- *
5098
- * Requires `nullifierRegistry` in SDK config.
5099
- *
5100
- * @param nullifier - Nullifier hex string from extractNullifier()
5101
- * @param provider - Optional ethers provider (defaults to public RPC for configured chain)
5102
- * @returns True if nullifier is already registered
5103
- * @throws Error if nullifierRegistry is not configured
5104
- *
5105
- * @example
5106
- * ```typescript
5107
- * const sdk = ProofportSDK.create({
5108
- * relayUrl: 'https://relay.zkproofport.app',
5109
- * nullifierRegistry: { address: '0x...', chainId: 8453 }
5110
- * });
5111
- *
5112
- * const nullifier = sdk.extractNullifier(publicInputs, circuit);
5113
- * const isDuplicate = await sdk.checkNullifier(nullifier);
5114
- * ```
5115
- */
5116
- async checkNullifier(nullifier, provider) {
5117
- if (!this.nullifierRegistry) {
5118
- throw new Error('nullifierRegistry is required. Set it in ProofportSDK config.');
5119
- }
5120
- const p = provider || getDefaultProvider(this.nullifierRegistry.chainId);
5121
- return isNullifierRegistered(nullifier, this.nullifierRegistry.address, p);
5122
- }
5123
- /**
5124
- * Gets detailed information about a registered nullifier from on-chain registry.
5125
- *
5126
- * Retrieves the registration timestamp, scope, and circuit ID for a nullifier.
5127
- * Returns null if the nullifier is not registered.
5128
- *
5129
- * Requires `nullifierRegistry` in SDK config.
5130
- *
5131
- * @param nullifier - Nullifier hex string from extractNullifier()
5132
- * @param provider - Optional ethers provider (defaults to public RPC for configured chain)
5133
- * @returns Nullifier info or null if not registered
5134
- * @throws Error if nullifierRegistry is not configured
5135
- *
5136
- * @example
5137
- * ```typescript
5138
- * const info = await sdk.getNullifierDetails(nullifier);
5139
- * if (info) {
5140
- * console.log('Registered at:', new Date(info.registeredAt * 1000));
5141
- * console.log('Circuit:', info.circuitId);
5142
- * }
5143
- * ```
5144
- */
5145
- async getNullifierDetails(nullifier, provider) {
5146
- if (!this.nullifierRegistry) {
5147
- throw new Error('nullifierRegistry is required. Set it in ProofportSDK config.');
5148
- }
5149
- const p = provider || getDefaultProvider(this.nullifierRegistry.chainId);
5150
- return getNullifierInfo(nullifier, this.nullifierRegistry.address, p);
5151
- }
5152
4910
  }
5153
4911
 
5154
4912
  export { ProofportSDK, ProofportSDK as default };