@0xpolygonid/js-sdk 1.10.1 → 1.10.2

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.
@@ -255,7 +255,8 @@ class ProofService {
255
255
  throw new Error(`CircuitId is not supported ${circuitId}`);
256
256
  }
257
257
  const gistRoot = js_merkletree_1.Hash.fromString(pubSignals[2]).bigInt();
258
- const globalStateInfo = await this._stateStorage.getGISTRootInfo(gistRoot);
258
+ const userId = BigInt(pubSignals[0]);
259
+ const globalStateInfo = await this._stateStorage.getGISTRootInfo(gistRoot, userId);
259
260
  if (globalStateInfo.createdAtTimestamp === 0n) {
260
261
  throw new Error(`gist state doesn't exists in contract`);
261
262
  }
@@ -220,7 +220,7 @@ class PubSignalsVerifier {
220
220
  this.challenge = authV2PubSignals.challenge;
221
221
  // no query verification
222
222
  // verify state
223
- const gist = await this.checkGlobalState(authV2PubSignals.GISTRoot);
223
+ const gist = await this.checkGlobalState(authV2PubSignals.GISTRoot, this.userId);
224
224
  let acceptedStateTransitionDelay = defaultAuthVerifyOpts;
225
225
  if (opts?.acceptedStateTransitionDelay) {
226
226
  acceptedStateTransitionDelay = opts.acceptedStateTransitionDelay;
@@ -302,9 +302,8 @@ class PubSignalsVerifier {
302
302
  throw exports.userStateError;
303
303
  }
304
304
  };
305
- this.checkGlobalState = async (state) => {
306
- const gistStateResolved = await this.rootResolve(state.bigInt());
307
- return gistStateResolved;
305
+ this.checkGlobalState = async (state, id) => {
306
+ return this.rootResolve(state.bigInt(), id.bigInt());
308
307
  };
309
308
  this.checkRevocationStateForId = async (issuerId, issuerClaimNonRevState) => {
310
309
  const issuerNonRevStateResolved = await this.resolve(issuerId, issuerClaimNonRevState.bigInt());
@@ -420,10 +419,10 @@ class PubSignalsVerifier {
420
419
  }
421
420
  return { latest: true, transitionTimestamp: 0 };
422
421
  }
423
- async rootResolve(state) {
422
+ async rootResolve(state, id) {
424
423
  let globalStateInfo;
425
424
  try {
426
- globalStateInfo = await this._stateStorage.getGISTRootInfo(state);
425
+ globalStateInfo = await this._stateStorage.getGISTRootInfo(state, id);
427
426
  }
428
427
  catch (e) {
429
428
  if (e.errorArgs[0] === 'Root does not exist') {
@@ -133,9 +133,9 @@ class EthStateStorage {
133
133
  };
134
134
  }
135
135
  /** {@inheritdoc IStateStorage.getGISTRootInfo} */
136
- async getGISTRootInfo(id) {
136
+ async getGISTRootInfo(root, id) {
137
137
  const { stateContract } = this.getStateContractAndProviderForId(id);
138
- const data = await stateContract.getGISTRootInfo(id);
138
+ const data = await stateContract.getGISTRootInfo(root);
139
139
  return {
140
140
  root: BigInt(data.root.toString()),
141
141
  replacedByRoot: BigInt(data.replacedByRoot.toString()),
@@ -252,7 +252,8 @@ export class ProofService {
252
252
  throw new Error(`CircuitId is not supported ${circuitId}`);
253
253
  }
254
254
  const gistRoot = Hash.fromString(pubSignals[2]).bigInt();
255
- const globalStateInfo = await this._stateStorage.getGISTRootInfo(gistRoot);
255
+ const userId = BigInt(pubSignals[0]);
256
+ const globalStateInfo = await this._stateStorage.getGISTRootInfo(gistRoot, userId);
256
257
  if (globalStateInfo.createdAtTimestamp === 0n) {
257
258
  throw new Error(`gist state doesn't exists in contract`);
258
259
  }
@@ -217,7 +217,7 @@ export class PubSignalsVerifier {
217
217
  this.challenge = authV2PubSignals.challenge;
218
218
  // no query verification
219
219
  // verify state
220
- const gist = await this.checkGlobalState(authV2PubSignals.GISTRoot);
220
+ const gist = await this.checkGlobalState(authV2PubSignals.GISTRoot, this.userId);
221
221
  let acceptedStateTransitionDelay = defaultAuthVerifyOpts;
222
222
  if (opts?.acceptedStateTransitionDelay) {
223
223
  acceptedStateTransitionDelay = opts.acceptedStateTransitionDelay;
@@ -299,9 +299,8 @@ export class PubSignalsVerifier {
299
299
  throw userStateError;
300
300
  }
301
301
  };
302
- this.checkGlobalState = async (state) => {
303
- const gistStateResolved = await this.rootResolve(state.bigInt());
304
- return gistStateResolved;
302
+ this.checkGlobalState = async (state, id) => {
303
+ return this.rootResolve(state.bigInt(), id.bigInt());
305
304
  };
306
305
  this.checkRevocationStateForId = async (issuerId, issuerClaimNonRevState) => {
307
306
  const issuerNonRevStateResolved = await this.resolve(issuerId, issuerClaimNonRevState.bigInt());
@@ -417,10 +416,10 @@ export class PubSignalsVerifier {
417
416
  }
418
417
  return { latest: true, transitionTimestamp: 0 };
419
418
  }
420
- async rootResolve(state) {
419
+ async rootResolve(state, id) {
421
420
  let globalStateInfo;
422
421
  try {
423
- globalStateInfo = await this._stateStorage.getGISTRootInfo(state);
422
+ globalStateInfo = await this._stateStorage.getGISTRootInfo(state, id);
424
423
  }
425
424
  catch (e) {
426
425
  if (e.errorArgs[0] === 'Root does not exist') {
@@ -127,9 +127,9 @@ export class EthStateStorage {
127
127
  };
128
128
  }
129
129
  /** {@inheritdoc IStateStorage.getGISTRootInfo} */
130
- async getGISTRootInfo(id) {
130
+ async getGISTRootInfo(root, id) {
131
131
  const { stateContract } = this.getStateContractAndProviderForId(id);
132
- const data = await stateContract.getGISTRootInfo(id);
132
+ const data = await stateContract.getGISTRootInfo(root);
133
133
  return {
134
134
  root: BigInt(data.root.toString()),
135
135
  replacedByRoot: BigInt(data.replacedByRoot.toString()),
@@ -139,7 +139,7 @@ export declare class ProofService implements IProofService {
139
139
  private loadLdContext;
140
140
  /** {@inheritdoc IProofService.generateAuthV2Inputs} */
141
141
  generateAuthV2Inputs(hash: Uint8Array, did: DID, circuitId: CircuitId): Promise<Uint8Array>;
142
- verifyState(circuitId: string, pubSignals: Array<string>): Promise<boolean>;
142
+ verifyState(circuitId: string, pubSignals: string[]): Promise<boolean>;
143
143
  findCredentialByProofQuery(did: DID, query: ProofQuery): Promise<{
144
144
  cred: W3CCredential;
145
145
  revStatus: RevocationStatus | undefined;
@@ -51,7 +51,7 @@ export declare class EthStateStorage implements IStateStorage {
51
51
  /** {@inheritdoc IStateStorage.getGISTProof} */
52
52
  getGISTProof(id: bigint): Promise<StateProof>;
53
53
  /** {@inheritdoc IStateStorage.getGISTRootInfo} */
54
- getGISTRootInfo(id: bigint): Promise<RootInfo>;
54
+ getGISTRootInfo(root: bigint, id: bigint): Promise<RootInfo>;
55
55
  private getStateContractAndProviderForId;
56
56
  private networkByChainId;
57
57
  }
@@ -39,10 +39,11 @@ export interface IStateStorage {
39
39
  */
40
40
  getGISTProof(id: bigint): Promise<StateProof>;
41
41
  /**
42
+ * gets root info of global identity state tree
42
43
  *
43
- *
44
- * @param {bigint} root - returns info about global state root
45
- * @returns `{Promise<RootInfo>}`
44
+ * @param {bigint} root - root to check
45
+ * @param {bigint} userId - user id
46
+ * @returns `Promise<RootInfo>`
46
47
  */
47
- getGISTRootInfo(root: bigint): Promise<RootInfo>;
48
+ getGISTRootInfo(root: bigint, userId: bigint): Promise<RootInfo>;
48
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "description": "SDK to work with Polygon ID",
5
5
  "main": "dist/node/cjs/index.js",
6
6
  "module": "dist/node/esm/index.js",