@0xpolygonid/js-sdk 1.32.1 → 1.32.4

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.
@@ -242,7 +242,10 @@ __export(index_exports, {
242
242
  isEthereumIdentity: () => isEthereumIdentity,
243
243
  isGenesisState: () => isGenesisState,
244
244
  isGenesisStateId: () => isGenesisStateId,
245
+ isIdentityDoesNotExistError: () => isIdentityDoesNotExistError,
245
246
  isIssuerGenesis: () => isIssuerGenesis,
247
+ isRootDoesNotExistError: () => isRootDoesNotExistError,
248
+ isStateDoesNotExistError: () => isStateDoesNotExistError,
246
249
  isValidOperation: () => isValidOperation,
247
250
  jsonLDMerklizer: () => jsonLDMerklizer,
248
251
  keyPath: () => keyPath,
@@ -1055,7 +1058,12 @@ var VerifiableConstants = Object.freeze({
1055
1058
  CONTEXT_TYPE_IS_EMPTY: "ctxType is empty",
1056
1059
  // ErrStateNotFound issuer state is genesis state.
1057
1060
  IDENTITY_DOES_NOT_EXIST: "Identity does not exist",
1061
+ IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR: "IdentityDoesNotExist",
1058
1062
  NO_AUTH_CRED_FOUND: "no auth credentials found",
1063
+ STATE_DOES_NOT_EXIST: "State does not exist",
1064
+ STATE_DOES_NOT_EXIST_CUSTOM_ERROR: "StateDoesNotExist",
1065
+ ROOT_DOES_NOT_EXIST: "Root does not exist",
1066
+ ROOT_DOES_NOT_EXIST_CUSTOM_ERROR: "RootDoesNotExist",
1059
1067
  // identity wallet
1060
1068
  ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY: "no credential satisfied query",
1061
1069
  ID_WALLET_SIGNER_IS_REQUIRED: "Ethereum signer is required to create Ethereum identities in order to transit state",
@@ -4946,10 +4954,258 @@ var InMemoryDataSource = class {
4946
4954
  }
4947
4955
  };
4948
4956
 
4957
+ // node_modules/quick-lru/index.js
4958
+ var QuickLRU = class extends Map {
4959
+ #size = 0;
4960
+ #cache = /* @__PURE__ */ new Map();
4961
+ #oldCache = /* @__PURE__ */ new Map();
4962
+ #maxSize;
4963
+ #maxAge;
4964
+ #onEviction;
4965
+ constructor(options = {}) {
4966
+ super();
4967
+ if (!(options.maxSize && options.maxSize > 0)) {
4968
+ throw new TypeError("`maxSize` must be a number greater than 0");
4969
+ }
4970
+ if (typeof options.maxAge === "number" && options.maxAge === 0) {
4971
+ throw new TypeError("`maxAge` must be a number greater than 0");
4972
+ }
4973
+ this.#maxSize = options.maxSize;
4974
+ this.#maxAge = options.maxAge || Number.POSITIVE_INFINITY;
4975
+ this.#onEviction = options.onEviction;
4976
+ }
4977
+ // For tests.
4978
+ get __oldCache() {
4979
+ return this.#oldCache;
4980
+ }
4981
+ #emitEvictions(cache) {
4982
+ if (typeof this.#onEviction !== "function") {
4983
+ return;
4984
+ }
4985
+ for (const [key, item] of cache) {
4986
+ this.#onEviction(key, item.value);
4987
+ }
4988
+ }
4989
+ #deleteIfExpired(key, item) {
4990
+ if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
4991
+ if (typeof this.#onEviction === "function") {
4992
+ this.#onEviction(key, item.value);
4993
+ }
4994
+ return this.delete(key);
4995
+ }
4996
+ return false;
4997
+ }
4998
+ #getOrDeleteIfExpired(key, item) {
4999
+ const deleted = this.#deleteIfExpired(key, item);
5000
+ if (deleted === false) {
5001
+ return item.value;
5002
+ }
5003
+ }
5004
+ #getItemValue(key, item) {
5005
+ return item.expiry ? this.#getOrDeleteIfExpired(key, item) : item.value;
5006
+ }
5007
+ #peek(key, cache) {
5008
+ const item = cache.get(key);
5009
+ return this.#getItemValue(key, item);
5010
+ }
5011
+ #set(key, value) {
5012
+ this.#cache.set(key, value);
5013
+ this.#size++;
5014
+ if (this.#size >= this.#maxSize) {
5015
+ this.#size = 0;
5016
+ this.#emitEvictions(this.#oldCache);
5017
+ this.#oldCache = this.#cache;
5018
+ this.#cache = /* @__PURE__ */ new Map();
5019
+ }
5020
+ }
5021
+ #moveToRecent(key, item) {
5022
+ this.#oldCache.delete(key);
5023
+ this.#set(key, item);
5024
+ }
5025
+ *#entriesAscending() {
5026
+ for (const item of this.#oldCache) {
5027
+ const [key, value] = item;
5028
+ if (!this.#cache.has(key)) {
5029
+ const deleted = this.#deleteIfExpired(key, value);
5030
+ if (deleted === false) {
5031
+ yield item;
5032
+ }
5033
+ }
5034
+ }
5035
+ for (const item of this.#cache) {
5036
+ const [key, value] = item;
5037
+ const deleted = this.#deleteIfExpired(key, value);
5038
+ if (deleted === false) {
5039
+ yield item;
5040
+ }
5041
+ }
5042
+ }
5043
+ get(key) {
5044
+ if (this.#cache.has(key)) {
5045
+ const item = this.#cache.get(key);
5046
+ return this.#getItemValue(key, item);
5047
+ }
5048
+ if (this.#oldCache.has(key)) {
5049
+ const item = this.#oldCache.get(key);
5050
+ if (this.#deleteIfExpired(key, item) === false) {
5051
+ this.#moveToRecent(key, item);
5052
+ return item.value;
5053
+ }
5054
+ }
5055
+ }
5056
+ set(key, value, { maxAge = this.#maxAge } = {}) {
5057
+ const expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : void 0;
5058
+ if (this.#cache.has(key)) {
5059
+ this.#cache.set(key, {
5060
+ value,
5061
+ expiry
5062
+ });
5063
+ } else {
5064
+ this.#set(key, { value, expiry });
5065
+ }
5066
+ return this;
5067
+ }
5068
+ has(key) {
5069
+ if (this.#cache.has(key)) {
5070
+ return !this.#deleteIfExpired(key, this.#cache.get(key));
5071
+ }
5072
+ if (this.#oldCache.has(key)) {
5073
+ return !this.#deleteIfExpired(key, this.#oldCache.get(key));
5074
+ }
5075
+ return false;
5076
+ }
5077
+ peek(key) {
5078
+ if (this.#cache.has(key)) {
5079
+ return this.#peek(key, this.#cache);
5080
+ }
5081
+ if (this.#oldCache.has(key)) {
5082
+ return this.#peek(key, this.#oldCache);
5083
+ }
5084
+ }
5085
+ delete(key) {
5086
+ const deleted = this.#cache.delete(key);
5087
+ if (deleted) {
5088
+ this.#size--;
5089
+ }
5090
+ return this.#oldCache.delete(key) || deleted;
5091
+ }
5092
+ clear() {
5093
+ this.#cache.clear();
5094
+ this.#oldCache.clear();
5095
+ this.#size = 0;
5096
+ }
5097
+ resize(newSize) {
5098
+ if (!(newSize && newSize > 0)) {
5099
+ throw new TypeError("`maxSize` must be a number greater than 0");
5100
+ }
5101
+ const items = [...this.#entriesAscending()];
5102
+ const removeCount = items.length - newSize;
5103
+ if (removeCount < 0) {
5104
+ this.#cache = new Map(items);
5105
+ this.#oldCache = /* @__PURE__ */ new Map();
5106
+ this.#size = items.length;
5107
+ } else {
5108
+ if (removeCount > 0) {
5109
+ this.#emitEvictions(items.slice(0, removeCount));
5110
+ }
5111
+ this.#oldCache = new Map(items.slice(removeCount));
5112
+ this.#cache = /* @__PURE__ */ new Map();
5113
+ this.#size = 0;
5114
+ }
5115
+ this.#maxSize = newSize;
5116
+ }
5117
+ *keys() {
5118
+ for (const [key] of this) {
5119
+ yield key;
5120
+ }
5121
+ }
5122
+ *values() {
5123
+ for (const [, value] of this) {
5124
+ yield value;
5125
+ }
5126
+ }
5127
+ *[Symbol.iterator]() {
5128
+ for (const item of this.#cache) {
5129
+ const [key, value] = item;
5130
+ const deleted = this.#deleteIfExpired(key, value);
5131
+ if (deleted === false) {
5132
+ yield [key, value.value];
5133
+ }
5134
+ }
5135
+ for (const item of this.#oldCache) {
5136
+ const [key, value] = item;
5137
+ if (!this.#cache.has(key)) {
5138
+ const deleted = this.#deleteIfExpired(key, value);
5139
+ if (deleted === false) {
5140
+ yield [key, value.value];
5141
+ }
5142
+ }
5143
+ }
5144
+ }
5145
+ *entriesDescending() {
5146
+ let items = [...this.#cache];
5147
+ for (let i = items.length - 1; i >= 0; --i) {
5148
+ const item = items[i];
5149
+ const [key, value] = item;
5150
+ const deleted = this.#deleteIfExpired(key, value);
5151
+ if (deleted === false) {
5152
+ yield [key, value.value];
5153
+ }
5154
+ }
5155
+ items = [...this.#oldCache];
5156
+ for (let i = items.length - 1; i >= 0; --i) {
5157
+ const item = items[i];
5158
+ const [key, value] = item;
5159
+ if (!this.#cache.has(key)) {
5160
+ const deleted = this.#deleteIfExpired(key, value);
5161
+ if (deleted === false) {
5162
+ yield [key, value.value];
5163
+ }
5164
+ }
5165
+ }
5166
+ }
5167
+ *entriesAscending() {
5168
+ for (const [key, value] of this.#entriesAscending()) {
5169
+ yield [key, value.value];
5170
+ }
5171
+ }
5172
+ get size() {
5173
+ if (!this.#size) {
5174
+ return this.#oldCache.size;
5175
+ }
5176
+ let oldCacheSize = 0;
5177
+ for (const key of this.#oldCache.keys()) {
5178
+ if (!this.#cache.has(key)) {
5179
+ oldCacheSize++;
5180
+ }
5181
+ }
5182
+ return Math.min(this.#size + oldCacheSize, this.#maxSize);
5183
+ }
5184
+ get maxSize() {
5185
+ return this.#maxSize;
5186
+ }
5187
+ entries() {
5188
+ return this.entriesAscending();
5189
+ }
5190
+ forEach(callbackFunction, thisArgument = this) {
5191
+ for (const [key, value] of this.entriesAscending()) {
5192
+ callbackFunction.call(thisArgument, value, key, this);
5193
+ }
5194
+ }
5195
+ get [Symbol.toStringTag]() {
5196
+ return "QuickLRU";
5197
+ }
5198
+ toString() {
5199
+ return `QuickLRU(${this.size}/${this.maxSize})`;
5200
+ }
5201
+ [Symbol.for("nodejs.util.inspect.custom")]() {
5202
+ return this.toString();
5203
+ }
5204
+ };
5205
+
4949
5206
  // src/storage/memory/cache-lru.ts
4950
- var import_quick_lru = __toESM(require("quick-lru"), 1);
4951
5207
  function createInMemoryCache(params) {
4952
- const cache = new import_quick_lru.default({ maxSize: params.maxSize, maxAge: params.ttl });
5208
+ const cache = new QuickLRU({ maxSize: params.maxSize, maxAge: params.ttl });
4953
5209
  return {
4954
5210
  get: async (key) => {
4955
5211
  return cache.get(key);
@@ -6503,6 +6759,31 @@ var OnChainRevocationStorage = class _OnChainRevocationStorage {
6503
6759
  // src/credentials/status/on-chain-revocation.ts
6504
6760
  var import_js_iden3_core20 = require("@iden3/js-iden3-core");
6505
6761
  var import_js_merkletree17 = require("@iden3/js-merkletree");
6762
+
6763
+ // src/storage/blockchain/errors.ts
6764
+ function isErrorWithArgs(error) {
6765
+ return typeof error === "object" && error !== null && "errorArgs" in error && Array.isArray(error.errorArgs);
6766
+ }
6767
+ function extractErrorMessage(error) {
6768
+ const errorArgs = isErrorWithArgs(error) ? error.errorArgs[0] : void 0;
6769
+ const errMsg = errorArgs || (error instanceof Error ? error.message : "");
6770
+ return errMsg;
6771
+ }
6772
+ function isError(error, errorMsg) {
6773
+ const errMsg = extractErrorMessage(error);
6774
+ return errMsg.includes(errorMsg);
6775
+ }
6776
+ function isIdentityDoesNotExistError(error) {
6777
+ return isError(error, VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST) || isError(error, VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR);
6778
+ }
6779
+ function isStateDoesNotExistError(error) {
6780
+ return isError(error, VerifiableConstants.ERRORS.STATE_DOES_NOT_EXIST) || isError(error, VerifiableConstants.ERRORS.STATE_DOES_NOT_EXIST_CUSTOM_ERROR);
6781
+ }
6782
+ function isRootDoesNotExistError(error) {
6783
+ return isError(error, VerifiableConstants.ERRORS.ROOT_DOES_NOT_EXIST) || isError(error, VerifiableConstants.ERRORS.ROOT_DOES_NOT_EXIST_CUSTOM_ERROR);
6784
+ }
6785
+
6786
+ // src/credentials/status/on-chain-revocation.ts
6506
6787
  var OnChainResolver = class {
6507
6788
  /**
6508
6789
  *
@@ -6550,8 +6831,7 @@ var OnChainResolver = class {
6550
6831
  }
6551
6832
  latestIssuerState = latestStateInfo.state;
6552
6833
  } catch (e) {
6553
- const errMsg = e?.reason ?? e.message ?? e;
6554
- if (!errMsg.includes(VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST)) {
6834
+ if (!isIdentityDoesNotExistError(e)) {
6555
6835
  throw e;
6556
6836
  }
6557
6837
  if (!stateHex) {
@@ -6759,8 +7039,7 @@ var RHSResolver = class {
6759
7039
  }
6760
7040
  latestState = latestStateInfo.state;
6761
7041
  } catch (e) {
6762
- const errMsg = e?.reason ?? e.message ?? e;
6763
- if (!errMsg.includes(VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST)) {
7042
+ if (!isIdentityDoesNotExistError(e)) {
6764
7043
  throw e;
6765
7044
  }
6766
7045
  const stateHex = this.extractState(credentialStatus.id);
@@ -12447,7 +12726,6 @@ var InputGenerator = class {
12447
12726
  circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
12448
12727
  const query = circuitQueries[0];
12449
12728
  query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
12450
- query.valueProof = query.operator === 0 /* NOOP */ ? new ValueProof() : query.valueProof;
12451
12729
  circuitInputs.query = query;
12452
12730
  circuitInputs.currentTimeStamp = (0, import_js_iden3_core36.getUnixTimestamp)(/* @__PURE__ */ new Date());
12453
12731
  circuitInputs.proofType = proofType;
@@ -12500,7 +12778,6 @@ var InputGenerator = class {
12500
12778
  circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
12501
12779
  const query = circuitQueries[0];
12502
12780
  query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
12503
- query.valueProof = query.operator === 0 /* NOOP */ ? new ValueProof() : query.valueProof;
12504
12781
  circuitInputs.query = query;
12505
12782
  circuitInputs.currentTimeStamp = (0, import_js_iden3_core36.getUnixTimestamp)(/* @__PURE__ */ new Date());
12506
12783
  circuitInputs.proofType = proofType;
@@ -12549,7 +12826,6 @@ var InputGenerator = class {
12549
12826
  });
12550
12827
  circuitQueries.forEach((query) => {
12551
12828
  query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
12552
- query.valueProof = query.operator === 0 /* NOOP */ ? new ValueProof() : query.valueProof;
12553
12829
  });
12554
12830
  return circuitInputs.inputsMarshal();
12555
12831
  };
@@ -13270,9 +13546,7 @@ var PubSignalsVerifier = class {
13270
13546
  try {
13271
13547
  contractState = await this._stateStorage.getStateInfoByIdAndState(idBigInt, state);
13272
13548
  } catch (e) {
13273
- const stateNotExistErr = (e?.errorArgs ?? [])[0];
13274
- const errMsg = stateNotExistErr || e.message;
13275
- if (errMsg.includes("State does not exist")) {
13549
+ if (isStateDoesNotExistError(e)) {
13276
13550
  if (isGenesis) {
13277
13551
  return {
13278
13552
  latest: true,
@@ -13305,7 +13579,7 @@ var PubSignalsVerifier = class {
13305
13579
  try {
13306
13580
  globalStateInfo = await this._stateStorage.getGISTRootInfo(state, id);
13307
13581
  } catch (e) {
13308
- if (e.errorArgs[0] === "Root does not exist") {
13582
+ if (isRootDoesNotExistError(e)) {
13309
13583
  throw new Error("GIST root does not exist in the smart contract");
13310
13584
  }
13311
13585
  throw e;
@@ -14676,7 +14950,10 @@ var jsonLDMerklizer = __toESM(require("@iden3/js-jsonld-merklization"), 1);
14676
14950
  isEthereumIdentity,
14677
14951
  isGenesisState,
14678
14952
  isGenesisStateId,
14953
+ isIdentityDoesNotExistError,
14679
14954
  isIssuerGenesis,
14955
+ isRootDoesNotExistError,
14956
+ isStateDoesNotExistError,
14680
14957
  isValidOperation,
14681
14958
  jsonLDMerklizer,
14682
14959
  keyPath,