@zkpassport/sdk 0.4.1 → 0.4.3

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.
@@ -205,7 +205,7 @@ export declare class ZKPassport {
205
205
  * @param evmChain The EVM chain to use for the request (if using the proof onchain)
206
206
  * @returns The query builder object.
207
207
  */
208
- request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, }: {
208
+ request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, cloudProverUrl, bridgeUrl, }: {
209
209
  name: string;
210
210
  logo: string;
211
211
  purpose: string;
@@ -219,6 +219,8 @@ export declare class ZKPassport {
219
219
  privateKey: Uint8Array;
220
220
  publicKey: Uint8Array;
221
221
  };
222
+ cloudProverUrl?: string;
223
+ bridgeUrl?: string;
222
224
  }): Promise<QueryBuilder>;
223
225
  private checkDiscloseBytesPublicInputs;
224
226
  private checkAgePublicInputs;
@@ -280,6 +282,7 @@ export declare class ZKPassport {
280
282
  scope?: string;
281
283
  devMode?: boolean;
282
284
  }): SolidityVerifierParameters;
285
+ private _getUrl;
283
286
  /**
284
287
  * @notice Returns the URL of the request.
285
288
  * @param requestId The request ID.
package/dist/cjs/index.js CHANGED
@@ -13,6 +13,7 @@ const utils_3 = require("@noble/hashes/utils");
13
13
  const ZKPassportVerifier_json_1 = tslib_1.__importDefault(require("./assets/abi/ZKPassportVerifier.json"));
14
14
  const registry_1 = require("@zkpassport/registry");
15
15
  const bridge_1 = require("@obsidion/bridge");
16
+ const VERSION = "0.4.2";
16
17
  const DEFAULT_DATE_VALUE = new Date(1111, 10, 11);
17
18
  // If Buffer is not defined, then we use the Buffer from the buffer package
18
19
  if (typeof globalThis.Buffer === "undefined") {
@@ -334,12 +335,9 @@ class ZKPassport {
334
335
  return this.getZkPassportRequest(topic);
335
336
  },
336
337
  done: () => {
337
- const base64Config = buffer_1.Buffer.from(JSON.stringify(this.topicToConfig[topic])).toString("base64");
338
- const base64Service = buffer_1.Buffer.from(JSON.stringify(this.topicToService[topic])).toString("base64");
339
- const pubkey = this.topicToPublicKey[topic];
340
338
  this.setExpectedProofCount(topic);
341
339
  return {
342
- url: `https://zkpassport.id/r?d=${this.domain}&t=${topic}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[topic].mode}`,
340
+ url: this._getUrl(topic),
343
341
  requestId: topic,
344
342
  onRequestReceived: (callback) => this.onRequestReceivedCallbacks[topic].push(callback),
345
343
  onGeneratingProof: (callback) => this.onGeneratingProofCallbacks[topic].push(callback),
@@ -365,10 +363,11 @@ class ZKPassport {
365
363
  * @param evmChain The EVM chain to use for the request (if using the proof onchain)
366
364
  * @returns The query builder object.
367
365
  */
368
- async request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, }) {
366
+ async request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, cloudProverUrl, bridgeUrl, }) {
369
367
  const bridge = await bridge_1.Bridge.create({
370
368
  keyPair: keyPairOverride,
371
369
  bridgeId: topicOverride,
370
+ bridgeUrl,
372
371
  });
373
372
  const topic = bridge.connection.getBridgeId();
374
373
  this.topicToConfig[topic] = {};
@@ -378,6 +377,8 @@ class ZKPassport {
378
377
  purpose,
379
378
  scope,
380
379
  chainId: evmChain ? getChainIdFromEVMChain(evmChain) : undefined,
380
+ cloudProverUrl,
381
+ bridgeUrl,
381
382
  };
382
383
  this.topicToProofs[topic] = [];
383
384
  this.topicToExpectedProofCount[topic] = 0;
@@ -1267,7 +1268,7 @@ class ZKPassport {
1267
1268
  // Maintained certificate registry settled onchain
1268
1269
  // Here we use Ethereum Sepolia
1269
1270
  const registryClient = new registry_1.RegistryClient({ chainId: 11155111 });
1270
- await registryClient.getCertificates(`0x${root}`);
1271
+ await registryClient.getCertificates(`0x${root.padStart(64, "0")}`);
1271
1272
  }
1272
1273
  catch (error) {
1273
1274
  console.warn(error);
@@ -2241,16 +2242,19 @@ class ZKPassport {
2241
2242
  };
2242
2243
  return params;
2243
2244
  }
2245
+ _getUrl(requestId) {
2246
+ const base64Config = buffer_1.Buffer.from(JSON.stringify(this.topicToConfig[requestId])).toString("base64");
2247
+ const base64Service = buffer_1.Buffer.from(JSON.stringify(this.topicToService[requestId])).toString("base64");
2248
+ const pubkey = this.topicToPublicKey[requestId];
2249
+ return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}&v=${VERSION}`;
2250
+ }
2244
2251
  /**
2245
2252
  * @notice Returns the URL of the request.
2246
2253
  * @param requestId The request ID.
2247
2254
  * @returns The URL of the request.
2248
2255
  */
2249
2256
  getUrl(requestId) {
2250
- const pubkey = this.topicToPublicKey[requestId];
2251
- const base64Config = buffer_1.Buffer.from(JSON.stringify(this.topicToConfig[requestId])).toString("base64");
2252
- const base64Service = buffer_1.Buffer.from(JSON.stringify(this.topicToService[requestId])).toString("base64");
2253
- return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}`;
2257
+ return this._getUrl(requestId);
2254
2258
  }
2255
2259
  /**
2256
2260
  * @notice Cancels a request by closing the WebSocket connection and deleting the associated data.
@@ -205,7 +205,7 @@ export declare class ZKPassport {
205
205
  * @param evmChain The EVM chain to use for the request (if using the proof onchain)
206
206
  * @returns The query builder object.
207
207
  */
208
- request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, }: {
208
+ request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, cloudProverUrl, bridgeUrl, }: {
209
209
  name: string;
210
210
  logo: string;
211
211
  purpose: string;
@@ -219,6 +219,8 @@ export declare class ZKPassport {
219
219
  privateKey: Uint8Array;
220
220
  publicKey: Uint8Array;
221
221
  };
222
+ cloudProverUrl?: string;
223
+ bridgeUrl?: string;
222
224
  }): Promise<QueryBuilder>;
223
225
  private checkDiscloseBytesPublicInputs;
224
226
  private checkAgePublicInputs;
@@ -280,6 +282,7 @@ export declare class ZKPassport {
280
282
  scope?: string;
281
283
  devMode?: boolean;
282
284
  }): SolidityVerifierParameters;
285
+ private _getUrl;
283
286
  /**
284
287
  * @notice Returns the URL of the request.
285
288
  * @param requestId The request ID.
package/dist/esm/index.js CHANGED
@@ -9,6 +9,7 @@ import { hexToBytes } from "@noble/hashes/utils";
9
9
  import ZKPassportVerifierAbi from "./assets/abi/ZKPassportVerifier.json";
10
10
  import { RegistryClient } from "@zkpassport/registry";
11
11
  import { Bridge } from "@obsidion/bridge";
12
+ const VERSION = "0.4.2";
12
13
  const DEFAULT_DATE_VALUE = new Date(1111, 10, 11);
13
14
  // If Buffer is not defined, then we use the Buffer from the buffer package
14
15
  if (typeof globalThis.Buffer === "undefined") {
@@ -324,12 +325,9 @@ export class ZKPassport {
324
325
  return this.getZkPassportRequest(topic);
325
326
  },
326
327
  done: () => {
327
- const base64Config = Buffer.from(JSON.stringify(this.topicToConfig[topic])).toString("base64");
328
- const base64Service = Buffer.from(JSON.stringify(this.topicToService[topic])).toString("base64");
329
- const pubkey = this.topicToPublicKey[topic];
330
328
  this.setExpectedProofCount(topic);
331
329
  return {
332
- url: `https://zkpassport.id/r?d=${this.domain}&t=${topic}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[topic].mode}`,
330
+ url: this._getUrl(topic),
333
331
  requestId: topic,
334
332
  onRequestReceived: (callback) => this.onRequestReceivedCallbacks[topic].push(callback),
335
333
  onGeneratingProof: (callback) => this.onGeneratingProofCallbacks[topic].push(callback),
@@ -355,10 +353,11 @@ export class ZKPassport {
355
353
  * @param evmChain The EVM chain to use for the request (if using the proof onchain)
356
354
  * @returns The query builder object.
357
355
  */
358
- async request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, }) {
356
+ async request({ name, logo, purpose, scope, mode, evmChain, validity, devMode, topicOverride, keyPairOverride, cloudProverUrl, bridgeUrl, }) {
359
357
  const bridge = await Bridge.create({
360
358
  keyPair: keyPairOverride,
361
359
  bridgeId: topicOverride,
360
+ bridgeUrl,
362
361
  });
363
362
  const topic = bridge.connection.getBridgeId();
364
363
  this.topicToConfig[topic] = {};
@@ -368,6 +367,8 @@ export class ZKPassport {
368
367
  purpose,
369
368
  scope,
370
369
  chainId: evmChain ? getChainIdFromEVMChain(evmChain) : undefined,
370
+ cloudProverUrl,
371
+ bridgeUrl,
371
372
  };
372
373
  this.topicToProofs[topic] = [];
373
374
  this.topicToExpectedProofCount[topic] = 0;
@@ -1257,7 +1258,7 @@ export class ZKPassport {
1257
1258
  // Maintained certificate registry settled onchain
1258
1259
  // Here we use Ethereum Sepolia
1259
1260
  const registryClient = new RegistryClient({ chainId: 11155111 });
1260
- await registryClient.getCertificates(`0x${root}`);
1261
+ await registryClient.getCertificates(`0x${root.padStart(64, "0")}`);
1261
1262
  }
1262
1263
  catch (error) {
1263
1264
  console.warn(error);
@@ -2231,16 +2232,19 @@ export class ZKPassport {
2231
2232
  };
2232
2233
  return params;
2233
2234
  }
2235
+ _getUrl(requestId) {
2236
+ const base64Config = Buffer.from(JSON.stringify(this.topicToConfig[requestId])).toString("base64");
2237
+ const base64Service = Buffer.from(JSON.stringify(this.topicToService[requestId])).toString("base64");
2238
+ const pubkey = this.topicToPublicKey[requestId];
2239
+ return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}&v=${VERSION}`;
2240
+ }
2234
2241
  /**
2235
2242
  * @notice Returns the URL of the request.
2236
2243
  * @param requestId The request ID.
2237
2244
  * @returns The URL of the request.
2238
2245
  */
2239
2246
  getUrl(requestId) {
2240
- const pubkey = this.topicToPublicKey[requestId];
2241
- const base64Config = Buffer.from(JSON.stringify(this.topicToConfig[requestId])).toString("base64");
2242
- const base64Service = Buffer.from(JSON.stringify(this.topicToService[requestId])).toString("base64");
2243
- return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}`;
2247
+ return this._getUrl(requestId);
2244
2248
  }
2245
2249
  /**
2246
2250
  * @notice Cancels a request by closing the WebSocket connection and deleting the associated data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zkpassport/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Privacy-preserving identity verification using passports and ID cards",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -42,9 +42,9 @@
42
42
  "@noble/ciphers": "^1.2.1",
43
43
  "@noble/hashes": "^1.7.2",
44
44
  "@noble/secp256k1": "^2.2.3",
45
- "@obsidion/bridge": "^0.9.0",
46
- "@zkpassport/registry": "^0.1.9",
47
- "@zkpassport/utils": "^0.9.4",
45
+ "@obsidion/bridge": "^0.10.1",
46
+ "@zkpassport/registry": "^0.2.1",
47
+ "@zkpassport/utils": "^0.9.6",
48
48
  "buffer": "^6.0.3",
49
49
  "i18n-iso-countries": "^7.12.0",
50
50
  "pako": "^2.1.0",
package/src/index.ts CHANGED
@@ -62,10 +62,10 @@ import {
62
62
  getBindEVMParameterCommitment,
63
63
  getBindParameterCommitment,
64
64
  formatBoundData,
65
+ Service,
65
66
  } from "@zkpassport/utils"
66
67
  import { bytesToHex } from "@noble/ciphers/utils"
67
68
  import { noLogger as logger } from "./logger"
68
- import { inflate } from "pako"
69
69
  import i18en from "i18n-iso-countries/langs/en.json"
70
70
  import { Buffer } from "buffer/"
71
71
  import { sha256 } from "@noble/hashes/sha2"
@@ -74,6 +74,8 @@ import ZKPassportVerifierAbi from "./assets/abi/ZKPassportVerifier.json"
74
74
  import { RegistryClient } from "@zkpassport/registry"
75
75
  import { Bridge, BridgeInterface } from "@obsidion/bridge"
76
76
 
77
+ const VERSION = "0.4.2"
78
+
77
79
  const DEFAULT_DATE_VALUE = new Date(1111, 10, 11)
78
80
 
79
81
  // If Buffer is not defined, then we use the Buffer from the buffer package
@@ -382,10 +384,7 @@ export class ZKPassport {
382
384
  private topicToPublicKey: Record<string, string> = {}
383
385
  private topicToBridge: Record<string, BridgeInterface> = {}
384
386
  private topicToRequestReceived: Record<string, boolean> = {}
385
- private topicToService: Record<
386
- string,
387
- { name: string; logo: string; purpose: string; scope?: string; chainId?: number }
388
- > = {}
387
+ private topicToService: Record<string, Service> = {}
389
388
  private topicToProofs: Record<string, Array<ProofResult>> = {}
390
389
  private topicToExpectedProofCount: Record<string, number> = {}
391
390
  private topicToFailedProofCount: Record<string, number> = {}
@@ -659,16 +658,9 @@ export class ZKPassport {
659
658
  return this.getZkPassportRequest(topic)
660
659
  },
661
660
  done: () => {
662
- const base64Config = Buffer.from(JSON.stringify(this.topicToConfig[topic])).toString(
663
- "base64",
664
- )
665
- const base64Service = Buffer.from(JSON.stringify(this.topicToService[topic])).toString(
666
- "base64",
667
- )
668
- const pubkey = this.topicToPublicKey[topic]
669
661
  this.setExpectedProofCount(topic)
670
662
  return {
671
- url: `https://zkpassport.id/r?d=${this.domain}&t=${topic}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[topic].mode}`,
663
+ url: this._getUrl(topic),
672
664
  requestId: topic,
673
665
  onRequestReceived: (callback: () => void) =>
674
666
  this.onRequestReceivedCallbacks[topic].push(callback),
@@ -718,6 +710,8 @@ export class ZKPassport {
718
710
  devMode,
719
711
  topicOverride,
720
712
  keyPairOverride,
713
+ cloudProverUrl,
714
+ bridgeUrl,
721
715
  }: {
722
716
  name: string
723
717
  logo: string
@@ -729,10 +723,13 @@ export class ZKPassport {
729
723
  devMode?: boolean
730
724
  topicOverride?: string
731
725
  keyPairOverride?: { privateKey: Uint8Array; publicKey: Uint8Array }
726
+ cloudProverUrl?: string
727
+ bridgeUrl?: string
732
728
  }): Promise<QueryBuilder> {
733
729
  const bridge = await Bridge.create({
734
730
  keyPair: keyPairOverride,
735
731
  bridgeId: topicOverride,
732
+ bridgeUrl,
736
733
  })
737
734
 
738
735
  const topic = bridge.connection.getBridgeId()
@@ -744,6 +741,8 @@ export class ZKPassport {
744
741
  purpose,
745
742
  scope,
746
743
  chainId: evmChain ? getChainIdFromEVMChain(evmChain) : undefined,
744
+ cloudProverUrl,
745
+ bridgeUrl,
747
746
  }
748
747
  this.topicToProofs[topic] = []
749
748
  this.topicToExpectedProofCount[topic] = 0
@@ -1801,7 +1800,7 @@ export class ZKPassport {
1801
1800
  // Maintained certificate registry settled onchain
1802
1801
  // Here we use Ethereum Sepolia
1803
1802
  const registryClient = new RegistryClient({ chainId: 11155111 })
1804
- await registryClient.getCertificates(`0x${root}`)
1803
+ await registryClient.getCertificates(`0x${root.padStart(64, "0")}`)
1805
1804
  } catch (error) {
1806
1805
  console.warn(error)
1807
1806
  // Check the legacy static roots that were used before the registry was deployed onchain
@@ -3055,20 +3054,24 @@ export class ZKPassport {
3055
3054
  return params
3056
3055
  }
3057
3056
 
3058
- /**
3059
- * @notice Returns the URL of the request.
3060
- * @param requestId The request ID.
3061
- * @returns The URL of the request.
3062
- */
3063
- public getUrl(requestId: string) {
3064
- const pubkey = this.topicToPublicKey[requestId]
3057
+ private _getUrl(requestId: string) {
3065
3058
  const base64Config = Buffer.from(JSON.stringify(this.topicToConfig[requestId])).toString(
3066
3059
  "base64",
3067
3060
  )
3068
3061
  const base64Service = Buffer.from(JSON.stringify(this.topicToService[requestId])).toString(
3069
3062
  "base64",
3070
3063
  )
3071
- return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}`
3064
+ const pubkey = this.topicToPublicKey[requestId]
3065
+ return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}&v=${VERSION}`
3066
+ }
3067
+
3068
+ /**
3069
+ * @notice Returns the URL of the request.
3070
+ * @param requestId The request ID.
3071
+ * @returns The URL of the request.
3072
+ */
3073
+ public getUrl(requestId: string) {
3074
+ return this._getUrl(requestId)
3072
3075
  }
3073
3076
 
3074
3077
  /**