@0xpolygonid/js-sdk 1.19.0 → 1.20.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.
@@ -2031,10 +2031,16 @@ function randomBytes$1(bytesLength = 32) {
2031
2031
  if (crypto$3 && typeof crypto$3.getRandomValues === 'function') {
2032
2032
  return crypto$3.getRandomValues(new Uint8Array(bytesLength));
2033
2033
  }
2034
+ // Legacy Node.js compatibility
2035
+ if (crypto$3 && typeof crypto$3.randomBytes === 'function') {
2036
+ return crypto$3.randomBytes(bytesLength);
2037
+ }
2034
2038
  throw new Error('crypto.getRandomValues must be defined');
2035
2039
  }
2036
2040
 
2037
- // Polyfill for Safari 14
2041
+ /**
2042
+ * Polyfill for Safari 14
2043
+ */
2038
2044
  function setBigUint64$1(view, byteOffset, value, isLE) {
2039
2045
  if (typeof view.setBigUint64 === 'function')
2040
2046
  return view.setBigUint64(byteOffset, value, isLE);
@@ -2047,9 +2053,13 @@ function setBigUint64$1(view, byteOffset, value, isLE) {
2047
2053
  view.setUint32(byteOffset + h, wh, isLE);
2048
2054
  view.setUint32(byteOffset + l, wl, isLE);
2049
2055
  }
2050
- // Choice: a ? b : c
2056
+ /**
2057
+ * Choice: a ? b : c
2058
+ */
2051
2059
  const Chi$1 = (a, b, c) => (a & b) ^ (~a & c);
2052
- // Majority function, true if any two inpust is true
2060
+ /**
2061
+ * Majority function, true if any two inputs is true
2062
+ */
2053
2063
  const Maj$1 = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
2054
2064
  /**
2055
2065
  * Merkle-Damgard hash construction base class.
@@ -3239,6 +3249,60 @@ function wNAF$1(c, bits) {
3239
3249
  },
3240
3250
  };
3241
3251
  }
3252
+ /**
3253
+ * Pippenger algorithm for multi-scalar multiplication (MSM).
3254
+ * MSM is basically (Pa + Qb + Rc + ...).
3255
+ * 30x faster vs naive addition on L=4096, 10x faster with precomputes.
3256
+ * For N=254bit, L=1, it does: 1024 ADD + 254 DBL. For L=5: 1536 ADD + 254 DBL.
3257
+ * Algorithmically constant-time (for same L), even when 1 point + scalar, or when scalar = 0.
3258
+ * @param c Curve Point constructor
3259
+ * @param field field over CURVE.N - important that it's not over CURVE.P
3260
+ * @param points array of L curve points
3261
+ * @param scalars array of L scalars (aka private keys / bigints)
3262
+ */
3263
+ function pippenger(c, field, points, scalars) {
3264
+ // If we split scalars by some window (let's say 8 bits), every chunk will only
3265
+ // take 256 buckets even if there are 4096 scalars, also re-uses double.
3266
+ // TODO:
3267
+ // - https://eprint.iacr.org/2024/750.pdf
3268
+ // - https://tches.iacr.org/index.php/TCHES/article/view/10287
3269
+ // 0 is accepted in scalars
3270
+ if (!Array.isArray(points) || !Array.isArray(scalars) || scalars.length !== points.length)
3271
+ throw new Error('arrays of points and scalars must have equal length');
3272
+ scalars.forEach((s, i) => {
3273
+ if (!field.isValid(s))
3274
+ throw new Error(`wrong scalar at index ${i}`);
3275
+ });
3276
+ points.forEach((p, i) => {
3277
+ if (!(p instanceof c))
3278
+ throw new Error(`wrong point at index ${i}`);
3279
+ });
3280
+ const wbits = bitLen$1(BigInt(points.length));
3281
+ const windowSize = wbits > 12 ? wbits - 3 : wbits > 4 ? wbits - 2 : wbits ? 2 : 1; // in bits
3282
+ const MASK = (1 << windowSize) - 1;
3283
+ const buckets = new Array(MASK + 1).fill(c.ZERO); // +1 for zero array
3284
+ const lastBits = Math.floor((field.BITS - 1) / windowSize) * windowSize;
3285
+ let sum = c.ZERO;
3286
+ for (let i = lastBits; i >= 0; i -= windowSize) {
3287
+ buckets.fill(c.ZERO);
3288
+ for (let j = 0; j < scalars.length; j++) {
3289
+ const scalar = scalars[j];
3290
+ const wbits = Number((scalar >> BigInt(i)) & BigInt(MASK));
3291
+ buckets[wbits] = buckets[wbits].add(points[j]);
3292
+ }
3293
+ let resI = c.ZERO; // not using this will do small speed-up, but will lose ct
3294
+ // Skip first bucket, because it is zero
3295
+ for (let j = buckets.length - 1, sumI = c.ZERO; j > 0; j--) {
3296
+ sumI = sumI.add(buckets[j]);
3297
+ resI = resI.add(sumI);
3298
+ }
3299
+ sum = sum.add(resI);
3300
+ if (i !== 0)
3301
+ for (let j = 0; j < windowSize; j++)
3302
+ sum = sum.double();
3303
+ }
3304
+ return sum;
3305
+ }
3242
3306
  function validateBasic$1(curve) {
3243
3307
  validateField$1(curve.Fp);
3244
3308
  validateObject$1(curve, {
@@ -3293,6 +3357,7 @@ function twistedEdwards(curveDef) {
3293
3357
  const { Fp, n: CURVE_ORDER, prehash: prehash, hash: cHash, randomBytes, nByteLength, h: cofactor, } = CURVE;
3294
3358
  const MASK = _2n$7 << (BigInt(nByteLength * 8) - _1n$a);
3295
3359
  const modP = Fp.create; // Function overrides
3360
+ const Fn = Field$1(CURVE.n, CURVE.nBitLength);
3296
3361
  // sqrt(u/v)
3297
3362
  const uvRatio = CURVE.uvRatio ||
3298
3363
  ((u, v) => {
@@ -3391,6 +3456,10 @@ function twistedEdwards(curveDef) {
3391
3456
  const toInv = Fp.invertBatch(points.map((p) => p.ez));
3392
3457
  return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
3393
3458
  }
3459
+ // Multiscalar Multiplication
3460
+ static msm(points, scalars) {
3461
+ return pippenger(Point, Fn, points, scalars);
3462
+ }
3394
3463
  // "Private method", don't use it directly
3395
3464
  _setWindowSize(windowSize) {
3396
3465
  wnaf.setWindowSize(this, windowSize);
@@ -4040,6 +4109,10 @@ let HMAC$1 = class HMAC extends Hash$1 {
4040
4109
  * @param hash - function that would be used e.g. sha256
4041
4110
  * @param key - message key
4042
4111
  * @param message - message data
4112
+ * @example
4113
+ * import { hmac } from '@noble/hashes/hmac';
4114
+ * import { sha256 } from '@noble/hashes/sha2';
4115
+ * const mac1 = hmac(sha256, 'key', 'message');
4043
4116
  */
4044
4117
  const hmac$1 = (hash, key, message) => new HMAC$1(hash, key).update(message).digest();
4045
4118
  hmac$1.create = (hash, key) => new HMAC$1(hash, key);
@@ -4079,8 +4152,14 @@ function validatePointOpts$1(curve) {
4079
4152
  }
4080
4153
  return Object.freeze({ ...opts });
4081
4154
  }
4082
- // ASN.1 DER encoding utilities
4083
4155
  const { bytesToNumberBE: b2n$1, hexToBytes: h2b$1 } = ut$1;
4156
+ /**
4157
+ * ASN.1 DER encoding utilities. ASN is very complex & fragile. Format:
4158
+ *
4159
+ * [0x30 (SEQUENCE), bytelength, 0x02 (INTEGER), intLength, R, 0x02 (INTEGER), intLength, S]
4160
+ *
4161
+ * Docs: https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/, https://luca.ntop.org/Teaching/Appunti/asn1.html
4162
+ */
4084
4163
  const DER$1 = {
4085
4164
  // asn.1 DER encoding utils
4086
4165
  Err: class DERErr extends Error {
@@ -4088,54 +4167,103 @@ const DER$1 = {
4088
4167
  super(m);
4089
4168
  }
4090
4169
  },
4091
- _parseInt(data) {
4092
- const { Err: E } = DER$1;
4093
- if (data.length < 2 || data[0] !== 0x02)
4094
- throw new E('Invalid signature integer tag');
4095
- const len = data[1];
4096
- const res = data.subarray(2, len + 2);
4097
- if (!len || res.length !== len)
4098
- throw new E('Invalid signature integer: wrong length');
4099
- // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
4100
- // since we always use positive integers here. It must always be empty:
4101
- // - add zero byte if exists
4102
- // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
4103
- if (res[0] & 0b10000000)
4104
- throw new E('Invalid signature integer: negative');
4105
- if (res[0] === 0x00 && !(res[1] & 0b10000000))
4106
- throw new E('Invalid signature integer: unnecessary leading zero');
4107
- return { d: b2n$1(res), l: data.subarray(len + 2) }; // d is data, l is left
4170
+ // Basic building block is TLV (Tag-Length-Value)
4171
+ _tlv: {
4172
+ encode: (tag, data) => {
4173
+ const { Err: E } = DER$1;
4174
+ if (tag < 0 || tag > 256)
4175
+ throw new E('tlv.encode: wrong tag');
4176
+ if (data.length & 1)
4177
+ throw new E('tlv.encode: unpadded data');
4178
+ const dataLen = data.length / 2;
4179
+ const len = numberToHexUnpadded$1(dataLen);
4180
+ if ((len.length / 2) & 128)
4181
+ throw new E('tlv.encode: long form length too big');
4182
+ // length of length with long form flag
4183
+ const lenLen = dataLen > 127 ? numberToHexUnpadded$1((len.length / 2) | 128) : '';
4184
+ return `${numberToHexUnpadded$1(tag)}${lenLen}${len}${data}`;
4185
+ },
4186
+ // v - value, l - left bytes (unparsed)
4187
+ decode(tag, data) {
4188
+ const { Err: E } = DER$1;
4189
+ let pos = 0;
4190
+ if (tag < 0 || tag > 256)
4191
+ throw new E('tlv.encode: wrong tag');
4192
+ if (data.length < 2 || data[pos++] !== tag)
4193
+ throw new E('tlv.decode: wrong tlv');
4194
+ const first = data[pos++];
4195
+ const isLong = !!(first & 128); // First bit of first length byte is flag for short/long form
4196
+ let length = 0;
4197
+ if (!isLong)
4198
+ length = first;
4199
+ else {
4200
+ // Long form: [longFlag(1bit), lengthLength(7bit), length (BE)]
4201
+ const lenLen = first & 127;
4202
+ if (!lenLen)
4203
+ throw new E('tlv.decode(long): indefinite length not supported');
4204
+ if (lenLen > 4)
4205
+ throw new E('tlv.decode(long): byte length is too big'); // this will overflow u32 in js
4206
+ const lengthBytes = data.subarray(pos, pos + lenLen);
4207
+ if (lengthBytes.length !== lenLen)
4208
+ throw new E('tlv.decode: length bytes not complete');
4209
+ if (lengthBytes[0] === 0)
4210
+ throw new E('tlv.decode(long): zero leftmost byte');
4211
+ for (const b of lengthBytes)
4212
+ length = (length << 8) | b;
4213
+ pos += lenLen;
4214
+ if (length < 128)
4215
+ throw new E('tlv.decode(long): not minimal encoding');
4216
+ }
4217
+ const v = data.subarray(pos, pos + length);
4218
+ if (v.length !== length)
4219
+ throw new E('tlv.decode: wrong value length');
4220
+ return { v, l: data.subarray(pos + length) };
4221
+ },
4222
+ },
4223
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
4224
+ // since we always use positive integers here. It must always be empty:
4225
+ // - add zero byte if exists
4226
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
4227
+ _int: {
4228
+ encode(num) {
4229
+ const { Err: E } = DER$1;
4230
+ if (num < _0n$6)
4231
+ throw new E('integer: negative integers are not allowed');
4232
+ let hex = numberToHexUnpadded$1(num);
4233
+ // Pad with zero byte if negative flag is present
4234
+ if (Number.parseInt(hex[0], 16) & 0b1000)
4235
+ hex = '00' + hex;
4236
+ if (hex.length & 1)
4237
+ throw new E('unexpected assertion');
4238
+ return hex;
4239
+ },
4240
+ decode(data) {
4241
+ const { Err: E } = DER$1;
4242
+ if (data[0] & 128)
4243
+ throw new E('Invalid signature integer: negative');
4244
+ if (data[0] === 0x00 && !(data[1] & 128))
4245
+ throw new E('Invalid signature integer: unnecessary leading zero');
4246
+ return b2n$1(data);
4247
+ },
4108
4248
  },
4109
4249
  toSig(hex) {
4110
4250
  // parse DER signature
4111
- const { Err: E } = DER$1;
4251
+ const { Err: E, _int: int, _tlv: tlv } = DER$1;
4112
4252
  const data = typeof hex === 'string' ? h2b$1(hex) : hex;
4113
4253
  abytes(data);
4114
- let l = data.length;
4115
- if (l < 2 || data[0] != 0x30)
4116
- throw new E('Invalid signature tag');
4117
- if (data[1] !== l - 2)
4118
- throw new E('Invalid signature: incorrect length');
4119
- const { d: r, l: sBytes } = DER$1._parseInt(data.subarray(2));
4120
- const { d: s, l: rBytesLeft } = DER$1._parseInt(sBytes);
4121
- if (rBytesLeft.length)
4254
+ const { v: seqBytes, l: seqLeftBytes } = tlv.decode(0x30, data);
4255
+ if (seqLeftBytes.length)
4122
4256
  throw new E('Invalid signature: left bytes after parsing');
4123
- return { r, s };
4257
+ const { v: rBytes, l: rLeftBytes } = tlv.decode(0x02, seqBytes);
4258
+ const { v: sBytes, l: sLeftBytes } = tlv.decode(0x02, rLeftBytes);
4259
+ if (sLeftBytes.length)
4260
+ throw new E('Invalid signature: left bytes after parsing');
4261
+ return { r: int.decode(rBytes), s: int.decode(sBytes) };
4124
4262
  },
4125
4263
  hexFromSig(sig) {
4126
- // Add leading zero if first byte has negative bit enabled. More details in '_parseInt'
4127
- const slice = (s) => (Number.parseInt(s[0], 16) & 0b1000 ? '00' + s : s);
4128
- const h = (num) => {
4129
- const hex = num.toString(16);
4130
- return hex.length & 1 ? `0${hex}` : hex;
4131
- };
4132
- const s = slice(h(sig.s));
4133
- const r = slice(h(sig.r));
4134
- const shl = s.length / 2;
4135
- const rhl = r.length / 2;
4136
- const sl = h(shl);
4137
- const rl = h(rhl);
4138
- return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
4264
+ const { _tlv: tlv, _int: int } = DER$1;
4265
+ const seq = `${tlv.encode(0x02, int.encode(sig.r))}${tlv.encode(0x02, int.encode(sig.s))}`;
4266
+ return tlv.encode(0x30, seq);
4139
4267
  },
4140
4268
  };
4141
4269
  // Be friendly to bad ECMAScript parsers by not using bigint literals
@@ -4144,6 +4272,7 @@ const _0n$6 = BigInt(0), _1n$8 = BigInt(1); BigInt(2); const _3n$2 = BigInt(3);
4144
4272
  function weierstrassPoints$1(opts) {
4145
4273
  const CURVE = validatePointOpts$1(opts);
4146
4274
  const { Fp } = CURVE; // All curves has same field / group length as for now, but they can differ
4275
+ const Fn = Field$1(CURVE.n, CURVE.nBitLength);
4147
4276
  const toBytes = CURVE.toBytes ||
4148
4277
  ((_c, point, _isCompressed) => {
4149
4278
  const a = point.toAffine();
@@ -4317,6 +4446,10 @@ function weierstrassPoints$1(opts) {
4317
4446
  static fromPrivateKey(privateKey) {
4318
4447
  return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
4319
4448
  }
4449
+ // Multiscalar Multiplication
4450
+ static msm(points, scalars) {
4451
+ return pippenger(Point, Fn, points, scalars);
4452
+ }
4320
4453
  // "Private method", don't use it directly
4321
4454
  _setWindowSize(windowSize) {
4322
4455
  wnaf.setWindowSize(this, windowSize);
@@ -7557,7 +7690,7 @@ const VerifiableConstants = Object.freeze({
7557
7690
  PUSH_NOTIFICATION: 'push-notification'
7558
7691
  },
7559
7692
  AUTH: {
7560
- AUTH_BJJ_CREDENTAIL_HASH: '013fd3f623559d850fb5b02ff012d0e2',
7693
+ AUTH_BJJ_CREDENTIAL_HASH: '013fd3f623559d850fb5b02ff012d0e2',
7561
7694
  AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL: 'https://schema.iden3.io/core/json/auth.json',
7562
7695
  AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL: 'https://schema.iden3.io/core/jsonld/auth.jsonld',
7563
7696
  AUTH_BJJ_CREDENTIAL_TYPE: 'AuthBJJCredential',
@@ -7589,7 +7722,7 @@ var CredentialStatusType;
7589
7722
  CredentialStatusType["Iden3ReverseSparseMerkleTreeProof"] = "Iden3ReverseSparseMerkleTreeProof";
7590
7723
  // Iden3commRevocationStatusV1 is CredentialStatusType for iden3comm revocation status
7591
7724
  CredentialStatusType["Iden3commRevocationStatusV1"] = "Iden3commRevocationStatusV1.0";
7592
- // Iden3OnсhainSparseMerkleTreeProof2023 is a proof type for MTP proofs with iden3 metadata from blockchain
7725
+ // Iden3OnchainSparseMerkleTreeProof2023 is a proof type for MTP proofs with iden3 metadata from blockchain
7593
7726
  CredentialStatusType["Iden3OnchainSparseMerkleTreeProof2023"] = "Iden3OnchainSparseMerkleTreeProof2023";
7594
7727
  })(CredentialStatusType || (CredentialStatusType = {}));
7595
7728
  /**
@@ -20007,7 +20140,7 @@ class W3CCredential {
20007
20140
  }
20008
20141
  async verifyIden3SparseMerkleTreeProof(proof, coreClaim, resolverURL) {
20009
20142
  await validateDIDDocumentAuth(proof.issuerData.id, resolverURL, proof.issuerData.state.value);
20010
- // root from proof == issuerData.state.сlaimsTreeRoot
20143
+ // root from proof == issuerData.state.claimsTreeRoot
20011
20144
  const { hi, hv } = coreClaim.hiHv();
20012
20145
  const rootFromProofValue = await rootFromProof(proof.mtp, hi, hv);
20013
20146
  if (!rootFromProofValue.equals(proof.issuerData.state.claimsTreeRoot)) {
@@ -20905,169 +21038,162 @@ var codegen = {};
20905
21038
 
20906
21039
  var code$1 = {};
20907
21040
 
20908
- var hasRequiredCode$1;
20909
-
20910
- function requireCode$1 () {
20911
- if (hasRequiredCode$1) return code$1;
20912
- hasRequiredCode$1 = 1;
20913
- (function (exports) {
20914
- Object.defineProperty(exports, "__esModule", { value: true });
20915
- exports.regexpCode = exports.getEsmExportName = exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;
20916
- class _CodeOrName {
20917
- }
20918
- exports._CodeOrName = _CodeOrName;
20919
- exports.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
20920
- class Name extends _CodeOrName {
20921
- constructor(s) {
20922
- super();
20923
- if (!exports.IDENTIFIER.test(s))
20924
- throw new Error("CodeGen: name must be a valid identifier");
20925
- this.str = s;
20926
- }
20927
- toString() {
20928
- return this.str;
20929
- }
20930
- emptyStr() {
20931
- return false;
20932
- }
20933
- get names() {
20934
- return { [this.str]: 1 };
20935
- }
20936
- }
20937
- exports.Name = Name;
20938
- class _Code extends _CodeOrName {
20939
- constructor(code) {
20940
- super();
20941
- this._items = typeof code === "string" ? [code] : code;
20942
- }
20943
- toString() {
20944
- return this.str;
20945
- }
20946
- emptyStr() {
20947
- if (this._items.length > 1)
20948
- return false;
20949
- const item = this._items[0];
20950
- return item === "" || item === '""';
20951
- }
20952
- get str() {
20953
- var _a;
20954
- return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, "")));
20955
- }
20956
- get names() {
20957
- var _a;
20958
- return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {
20959
- if (c instanceof Name)
20960
- names[c.str] = (names[c.str] || 0) + 1;
20961
- return names;
20962
- }, {})));
20963
- }
20964
- }
20965
- exports._Code = _Code;
20966
- exports.nil = new _Code("");
20967
- function _(strs, ...args) {
20968
- const code = [strs[0]];
20969
- let i = 0;
20970
- while (i < args.length) {
20971
- addCodeArg(code, args[i]);
20972
- code.push(strs[++i]);
20973
- }
20974
- return new _Code(code);
20975
- }
20976
- exports._ = _;
20977
- const plus = new _Code("+");
20978
- function str(strs, ...args) {
20979
- const expr = [safeStringify(strs[0])];
20980
- let i = 0;
20981
- while (i < args.length) {
20982
- expr.push(plus);
20983
- addCodeArg(expr, args[i]);
20984
- expr.push(plus, safeStringify(strs[++i]));
20985
- }
20986
- optimize(expr);
20987
- return new _Code(expr);
20988
- }
20989
- exports.str = str;
20990
- function addCodeArg(code, arg) {
20991
- if (arg instanceof _Code)
20992
- code.push(...arg._items);
20993
- else if (arg instanceof Name)
20994
- code.push(arg);
20995
- else
20996
- code.push(interpolate(arg));
20997
- }
20998
- exports.addCodeArg = addCodeArg;
20999
- function optimize(expr) {
21000
- let i = 1;
21001
- while (i < expr.length - 1) {
21002
- if (expr[i] === plus) {
21003
- const res = mergeExprItems(expr[i - 1], expr[i + 1]);
21004
- if (res !== undefined) {
21005
- expr.splice(i - 1, 3, res);
21006
- continue;
21007
- }
21008
- expr[i++] = "+";
21009
- }
21010
- i++;
21011
- }
21012
- }
21013
- function mergeExprItems(a, b) {
21014
- if (b === '""')
21015
- return a;
21016
- if (a === '""')
21017
- return b;
21018
- if (typeof a == "string") {
21019
- if (b instanceof Name || a[a.length - 1] !== '"')
21020
- return;
21021
- if (typeof b != "string")
21022
- return `${a.slice(0, -1)}${b}"`;
21023
- if (b[0] === '"')
21024
- return a.slice(0, -1) + b.slice(1);
21025
- return;
21026
- }
21027
- if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
21028
- return `"${a}${b.slice(1)}`;
21029
- return;
21030
- }
21031
- function strConcat(c1, c2) {
21032
- return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str `${c1}${c2}`;
21033
- }
21034
- exports.strConcat = strConcat;
21035
- // TODO do not allow arrays here
21036
- function interpolate(x) {
21037
- return typeof x == "number" || typeof x == "boolean" || x === null
21038
- ? x
21039
- : safeStringify(Array.isArray(x) ? x.join(",") : x);
21040
- }
21041
- function stringify(x) {
21042
- return new _Code(safeStringify(x));
21043
- }
21044
- exports.stringify = stringify;
21045
- function safeStringify(x) {
21046
- return JSON.stringify(x)
21047
- .replace(/\u2028/g, "\\u2028")
21048
- .replace(/\u2029/g, "\\u2029");
21049
- }
21050
- exports.safeStringify = safeStringify;
21051
- function getProperty(key) {
21052
- return typeof key == "string" && exports.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _ `[${key}]`;
21053
- }
21054
- exports.getProperty = getProperty;
21055
- //Does best effort to format the name properly
21056
- function getEsmExportName(key) {
21057
- if (typeof key == "string" && exports.IDENTIFIER.test(key)) {
21058
- return new _Code(`${key}`);
21059
- }
21060
- throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`);
21061
- }
21062
- exports.getEsmExportName = getEsmExportName;
21063
- function regexpCode(rx) {
21064
- return new _Code(rx.toString());
21065
- }
21066
- exports.regexpCode = regexpCode;
21067
-
21068
- } (code$1));
21069
- return code$1;
21070
- }
21041
+ (function (exports) {
21042
+ Object.defineProperty(exports, "__esModule", { value: true });
21043
+ exports.regexpCode = exports.getEsmExportName = exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;
21044
+ class _CodeOrName {
21045
+ }
21046
+ exports._CodeOrName = _CodeOrName;
21047
+ exports.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
21048
+ class Name extends _CodeOrName {
21049
+ constructor(s) {
21050
+ super();
21051
+ if (!exports.IDENTIFIER.test(s))
21052
+ throw new Error("CodeGen: name must be a valid identifier");
21053
+ this.str = s;
21054
+ }
21055
+ toString() {
21056
+ return this.str;
21057
+ }
21058
+ emptyStr() {
21059
+ return false;
21060
+ }
21061
+ get names() {
21062
+ return { [this.str]: 1 };
21063
+ }
21064
+ }
21065
+ exports.Name = Name;
21066
+ class _Code extends _CodeOrName {
21067
+ constructor(code) {
21068
+ super();
21069
+ this._items = typeof code === "string" ? [code] : code;
21070
+ }
21071
+ toString() {
21072
+ return this.str;
21073
+ }
21074
+ emptyStr() {
21075
+ if (this._items.length > 1)
21076
+ return false;
21077
+ const item = this._items[0];
21078
+ return item === "" || item === '""';
21079
+ }
21080
+ get str() {
21081
+ var _a;
21082
+ return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, "")));
21083
+ }
21084
+ get names() {
21085
+ var _a;
21086
+ return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {
21087
+ if (c instanceof Name)
21088
+ names[c.str] = (names[c.str] || 0) + 1;
21089
+ return names;
21090
+ }, {})));
21091
+ }
21092
+ }
21093
+ exports._Code = _Code;
21094
+ exports.nil = new _Code("");
21095
+ function _(strs, ...args) {
21096
+ const code = [strs[0]];
21097
+ let i = 0;
21098
+ while (i < args.length) {
21099
+ addCodeArg(code, args[i]);
21100
+ code.push(strs[++i]);
21101
+ }
21102
+ return new _Code(code);
21103
+ }
21104
+ exports._ = _;
21105
+ const plus = new _Code("+");
21106
+ function str(strs, ...args) {
21107
+ const expr = [safeStringify(strs[0])];
21108
+ let i = 0;
21109
+ while (i < args.length) {
21110
+ expr.push(plus);
21111
+ addCodeArg(expr, args[i]);
21112
+ expr.push(plus, safeStringify(strs[++i]));
21113
+ }
21114
+ optimize(expr);
21115
+ return new _Code(expr);
21116
+ }
21117
+ exports.str = str;
21118
+ function addCodeArg(code, arg) {
21119
+ if (arg instanceof _Code)
21120
+ code.push(...arg._items);
21121
+ else if (arg instanceof Name)
21122
+ code.push(arg);
21123
+ else
21124
+ code.push(interpolate(arg));
21125
+ }
21126
+ exports.addCodeArg = addCodeArg;
21127
+ function optimize(expr) {
21128
+ let i = 1;
21129
+ while (i < expr.length - 1) {
21130
+ if (expr[i] === plus) {
21131
+ const res = mergeExprItems(expr[i - 1], expr[i + 1]);
21132
+ if (res !== undefined) {
21133
+ expr.splice(i - 1, 3, res);
21134
+ continue;
21135
+ }
21136
+ expr[i++] = "+";
21137
+ }
21138
+ i++;
21139
+ }
21140
+ }
21141
+ function mergeExprItems(a, b) {
21142
+ if (b === '""')
21143
+ return a;
21144
+ if (a === '""')
21145
+ return b;
21146
+ if (typeof a == "string") {
21147
+ if (b instanceof Name || a[a.length - 1] !== '"')
21148
+ return;
21149
+ if (typeof b != "string")
21150
+ return `${a.slice(0, -1)}${b}"`;
21151
+ if (b[0] === '"')
21152
+ return a.slice(0, -1) + b.slice(1);
21153
+ return;
21154
+ }
21155
+ if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
21156
+ return `"${a}${b.slice(1)}`;
21157
+ return;
21158
+ }
21159
+ function strConcat(c1, c2) {
21160
+ return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str `${c1}${c2}`;
21161
+ }
21162
+ exports.strConcat = strConcat;
21163
+ // TODO do not allow arrays here
21164
+ function interpolate(x) {
21165
+ return typeof x == "number" || typeof x == "boolean" || x === null
21166
+ ? x
21167
+ : safeStringify(Array.isArray(x) ? x.join(",") : x);
21168
+ }
21169
+ function stringify(x) {
21170
+ return new _Code(safeStringify(x));
21171
+ }
21172
+ exports.stringify = stringify;
21173
+ function safeStringify(x) {
21174
+ return JSON.stringify(x)
21175
+ .replace(/\u2028/g, "\\u2028")
21176
+ .replace(/\u2029/g, "\\u2029");
21177
+ }
21178
+ exports.safeStringify = safeStringify;
21179
+ function getProperty(key) {
21180
+ return typeof key == "string" && exports.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _ `[${key}]`;
21181
+ }
21182
+ exports.getProperty = getProperty;
21183
+ //Does best effort to format the name properly
21184
+ function getEsmExportName(key) {
21185
+ if (typeof key == "string" && exports.IDENTIFIER.test(key)) {
21186
+ return new _Code(`${key}`);
21187
+ }
21188
+ throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`);
21189
+ }
21190
+ exports.getEsmExportName = getEsmExportName;
21191
+ function regexpCode(rx) {
21192
+ return new _Code(rx.toString());
21193
+ }
21194
+ exports.regexpCode = regexpCode;
21195
+
21196
+ } (code$1));
21071
21197
 
21072
21198
  var scope = {};
21073
21199
 
@@ -21079,7 +21205,7 @@ function requireScope () {
21079
21205
  (function (exports) {
21080
21206
  Object.defineProperty(exports, "__esModule", { value: true });
21081
21207
  exports.ValueScope = exports.ValueScopeName = exports.Scope = exports.varKinds = exports.UsedValueState = void 0;
21082
- const code_1 = requireCode$1();
21208
+ const code_1 = code$1;
21083
21209
  class ValueError extends Error {
21084
21210
  constructor(name) {
21085
21211
  super(`CodeGen: "code" for ${name} not defined`);
@@ -21231,9 +21357,9 @@ function requireCodegen () {
21231
21357
  (function (exports) {
21232
21358
  Object.defineProperty(exports, "__esModule", { value: true });
21233
21359
  exports.or = exports.and = exports.not = exports.CodeGen = exports.operators = exports.varKinds = exports.ValueScopeName = exports.ValueScope = exports.Scope = exports.Name = exports.regexpCode = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;
21234
- const code_1 = requireCode$1();
21360
+ const code_1 = code$1;
21235
21361
  const scope_1 = requireScope();
21236
- var code_2 = requireCode$1();
21362
+ var code_2 = code$1;
21237
21363
  Object.defineProperty(exports, "_", { enumerable: true, get: function () { return code_2._; } });
21238
21364
  Object.defineProperty(exports, "str", { enumerable: true, get: function () { return code_2.str; } });
21239
21365
  Object.defineProperty(exports, "strConcat", { enumerable: true, get: function () { return code_2.strConcat; } });
@@ -21935,7 +22061,7 @@ var util = {};
21935
22061
  Object.defineProperty(exports, "__esModule", { value: true });
21936
22062
  exports.checkStrictMode = exports.getErrorPath = exports.Type = exports.useFunc = exports.setEvaluated = exports.evaluatedPropsToName = exports.mergeEvaluated = exports.eachItem = exports.unescapeJsonPointer = exports.escapeJsonPointer = exports.escapeFragment = exports.unescapeFragment = exports.schemaRefOrVal = exports.schemaHasRulesButRef = exports.schemaHasRules = exports.checkUnknownRules = exports.alwaysValidSchema = exports.toHash = void 0;
21937
22063
  const codegen_1 = requireCodegen();
21938
- const code_1 = requireCode$1();
22064
+ const code_1 = code$1;
21939
22065
  // TODO refactor to use Set
21940
22066
  function toHash(arr) {
21941
22067
  const hash = {};
@@ -22368,37 +22494,29 @@ rules.getRules = getRules;
22368
22494
 
22369
22495
  var applicability = {};
22370
22496
 
22371
- var hasRequiredApplicability;
22372
-
22373
- function requireApplicability () {
22374
- if (hasRequiredApplicability) return applicability;
22375
- hasRequiredApplicability = 1;
22376
- Object.defineProperty(applicability, "__esModule", { value: true });
22377
- applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
22378
- function schemaHasRulesForType({ schema, self }, type) {
22379
- const group = self.RULES.types[type];
22380
- return group && group !== true && shouldUseGroup(schema, group);
22381
- }
22382
- applicability.schemaHasRulesForType = schemaHasRulesForType;
22383
- function shouldUseGroup(schema, group) {
22384
- return group.rules.some((rule) => shouldUseRule(schema, rule));
22385
- }
22386
- applicability.shouldUseGroup = shouldUseGroup;
22387
- function shouldUseRule(schema, rule) {
22388
- var _a;
22389
- return (schema[rule.keyword] !== undefined ||
22390
- ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== undefined)));
22391
- }
22392
- applicability.shouldUseRule = shouldUseRule;
22393
-
22394
- return applicability;
22497
+ Object.defineProperty(applicability, "__esModule", { value: true });
22498
+ applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
22499
+ function schemaHasRulesForType({ schema, self }, type) {
22500
+ const group = self.RULES.types[type];
22501
+ return group && group !== true && shouldUseGroup(schema, group);
22502
+ }
22503
+ applicability.schemaHasRulesForType = schemaHasRulesForType;
22504
+ function shouldUseGroup(schema, group) {
22505
+ return group.rules.some((rule) => shouldUseRule(schema, rule));
22506
+ }
22507
+ applicability.shouldUseGroup = shouldUseGroup;
22508
+ function shouldUseRule(schema, rule) {
22509
+ var _a;
22510
+ return (schema[rule.keyword] !== undefined ||
22511
+ ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== undefined)));
22395
22512
  }
22513
+ applicability.shouldUseRule = shouldUseRule;
22396
22514
 
22397
22515
  (function (exports) {
22398
22516
  Object.defineProperty(exports, "__esModule", { value: true });
22399
22517
  exports.reportTypeError = exports.checkDataTypes = exports.checkDataType = exports.coerceAndCheckDataType = exports.getJSONTypes = exports.getSchemaTypes = exports.DataType = void 0;
22400
22518
  const rules_1 = rules;
22401
- const applicability_1 = requireApplicability();
22519
+ const applicability_1 = applicability;
22402
22520
  const errors_1 = requireErrors();
22403
22521
  const codegen_1 = requireCodegen();
22404
22522
  const util_1 = util;
@@ -22646,143 +22764,135 @@ var keyword = {};
22646
22764
 
22647
22765
  var code = {};
22648
22766
 
22649
- var hasRequiredCode;
22650
-
22651
- function requireCode () {
22652
- if (hasRequiredCode) return code;
22653
- hasRequiredCode = 1;
22654
- Object.defineProperty(code, "__esModule", { value: true });
22655
- code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
22656
- const codegen_1 = requireCodegen();
22657
- const util_1 = util;
22658
- const names_1 = requireNames();
22659
- const util_2 = util;
22660
- function checkReportMissingProp(cxt, prop) {
22661
- const { gen, data, it } = cxt;
22662
- gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
22663
- cxt.setParams({ missingProperty: (0, codegen_1._) `${prop}` }, true);
22664
- cxt.error();
22665
- });
22666
- }
22667
- code.checkReportMissingProp = checkReportMissingProp;
22668
- function checkMissingProp({ gen, data, it: { opts } }, properties, missing) {
22669
- return (0, codegen_1.or)(...properties.map((prop) => (0, codegen_1.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1._) `${missing} = ${prop}`)));
22670
- }
22671
- code.checkMissingProp = checkMissingProp;
22672
- function reportMissingProp(cxt, missing) {
22673
- cxt.setParams({ missingProperty: missing }, true);
22674
- cxt.error();
22675
- }
22676
- code.reportMissingProp = reportMissingProp;
22677
- function hasPropFunc(gen) {
22678
- return gen.scopeValue("func", {
22679
- // eslint-disable-next-line @typescript-eslint/unbound-method
22680
- ref: Object.prototype.hasOwnProperty,
22681
- code: (0, codegen_1._) `Object.prototype.hasOwnProperty`,
22682
- });
22683
- }
22684
- code.hasPropFunc = hasPropFunc;
22685
- function isOwnProperty(gen, data, property) {
22686
- return (0, codegen_1._) `${hasPropFunc(gen)}.call(${data}, ${property})`;
22687
- }
22688
- code.isOwnProperty = isOwnProperty;
22689
- function propertyInData(gen, data, property, ownProperties) {
22690
- const cond = (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(property)} !== undefined`;
22691
- return ownProperties ? (0, codegen_1._) `${cond} && ${isOwnProperty(gen, data, property)}` : cond;
22692
- }
22693
- code.propertyInData = propertyInData;
22694
- function noPropertyInData(gen, data, property, ownProperties) {
22695
- const cond = (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(property)} === undefined`;
22696
- return ownProperties ? (0, codegen_1.or)(cond, (0, codegen_1.not)(isOwnProperty(gen, data, property))) : cond;
22697
- }
22698
- code.noPropertyInData = noPropertyInData;
22699
- function allSchemaProperties(schemaMap) {
22700
- return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
22701
- }
22702
- code.allSchemaProperties = allSchemaProperties;
22703
- function schemaProperties(it, schemaMap) {
22704
- return allSchemaProperties(schemaMap).filter((p) => !(0, util_1.alwaysValidSchema)(it, schemaMap[p]));
22705
- }
22706
- code.schemaProperties = schemaProperties;
22707
- function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
22708
- const dataAndSchema = passSchema ? (0, codegen_1._) `${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
22709
- const valCxt = [
22710
- [names_1.default.instancePath, (0, codegen_1.strConcat)(names_1.default.instancePath, errorPath)],
22711
- [names_1.default.parentData, it.parentData],
22712
- [names_1.default.parentDataProperty, it.parentDataProperty],
22713
- [names_1.default.rootData, names_1.default.rootData],
22714
- ];
22715
- if (it.opts.dynamicRef)
22716
- valCxt.push([names_1.default.dynamicAnchors, names_1.default.dynamicAnchors]);
22717
- const args = (0, codegen_1._) `${dataAndSchema}, ${gen.object(...valCxt)}`;
22718
- return context !== codegen_1.nil ? (0, codegen_1._) `${func}.call(${context}, ${args})` : (0, codegen_1._) `${func}(${args})`;
22719
- }
22720
- code.callValidateCode = callValidateCode;
22721
- const newRegExp = (0, codegen_1._) `new RegExp`;
22722
- function usePattern({ gen, it: { opts } }, pattern) {
22723
- const u = opts.unicodeRegExp ? "u" : "";
22724
- const { regExp } = opts.code;
22725
- const rx = regExp(pattern, u);
22726
- return gen.scopeValue("pattern", {
22727
- key: rx.toString(),
22728
- ref: rx,
22729
- code: (0, codegen_1._) `${regExp.code === "new RegExp" ? newRegExp : (0, util_2.useFunc)(gen, regExp)}(${pattern}, ${u})`,
22730
- });
22731
- }
22732
- code.usePattern = usePattern;
22733
- function validateArray(cxt) {
22734
- const { gen, data, keyword, it } = cxt;
22735
- const valid = gen.name("valid");
22736
- if (it.allErrors) {
22737
- const validArr = gen.let("valid", true);
22738
- validateItems(() => gen.assign(validArr, false));
22739
- return validArr;
22740
- }
22741
- gen.var(valid, true);
22742
- validateItems(() => gen.break());
22743
- return valid;
22744
- function validateItems(notValid) {
22745
- const len = gen.const("len", (0, codegen_1._) `${data}.length`);
22746
- gen.forRange("i", 0, len, (i) => {
22747
- cxt.subschema({
22748
- keyword,
22749
- dataProp: i,
22750
- dataPropType: util_1.Type.Num,
22751
- }, valid);
22752
- gen.if((0, codegen_1.not)(valid), notValid);
22753
- });
22754
- }
22755
- }
22756
- code.validateArray = validateArray;
22757
- function validateUnion(cxt) {
22758
- const { gen, schema, keyword, it } = cxt;
22759
- /* istanbul ignore if */
22760
- if (!Array.isArray(schema))
22761
- throw new Error("ajv implementation error");
22762
- const alwaysValid = schema.some((sch) => (0, util_1.alwaysValidSchema)(it, sch));
22763
- if (alwaysValid && !it.opts.unevaluated)
22764
- return;
22765
- const valid = gen.let("valid", false);
22766
- const schValid = gen.name("_valid");
22767
- gen.block(() => schema.forEach((_sch, i) => {
22768
- const schCxt = cxt.subschema({
22769
- keyword,
22770
- schemaProp: i,
22771
- compositeRule: true,
22772
- }, schValid);
22773
- gen.assign(valid, (0, codegen_1._) `${valid} || ${schValid}`);
22774
- const merged = cxt.mergeValidEvaluated(schCxt, schValid);
22775
- // can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true)
22776
- // or if all properties and items were evaluated (it.props === true && it.items === true)
22777
- if (!merged)
22778
- gen.if((0, codegen_1.not)(valid));
22779
- }));
22780
- cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
22781
- }
22782
- code.validateUnion = validateUnion;
22783
-
22784
- return code;
22767
+ Object.defineProperty(code, "__esModule", { value: true });
22768
+ code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
22769
+ const codegen_1$r = requireCodegen();
22770
+ const util_1$q = util;
22771
+ const names_1$6 = requireNames();
22772
+ const util_2$1 = util;
22773
+ function checkReportMissingProp(cxt, prop) {
22774
+ const { gen, data, it } = cxt;
22775
+ gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
22776
+ cxt.setParams({ missingProperty: (0, codegen_1$r._) `${prop}` }, true);
22777
+ cxt.error();
22778
+ });
22779
+ }
22780
+ code.checkReportMissingProp = checkReportMissingProp;
22781
+ function checkMissingProp({ gen, data, it: { opts } }, properties, missing) {
22782
+ return (0, codegen_1$r.or)(...properties.map((prop) => (0, codegen_1$r.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$r._) `${missing} = ${prop}`)));
22783
+ }
22784
+ code.checkMissingProp = checkMissingProp;
22785
+ function reportMissingProp(cxt, missing) {
22786
+ cxt.setParams({ missingProperty: missing }, true);
22787
+ cxt.error();
22788
+ }
22789
+ code.reportMissingProp = reportMissingProp;
22790
+ function hasPropFunc(gen) {
22791
+ return gen.scopeValue("func", {
22792
+ // eslint-disable-next-line @typescript-eslint/unbound-method
22793
+ ref: Object.prototype.hasOwnProperty,
22794
+ code: (0, codegen_1$r._) `Object.prototype.hasOwnProperty`,
22795
+ });
22796
+ }
22797
+ code.hasPropFunc = hasPropFunc;
22798
+ function isOwnProperty(gen, data, property) {
22799
+ return (0, codegen_1$r._) `${hasPropFunc(gen)}.call(${data}, ${property})`;
22800
+ }
22801
+ code.isOwnProperty = isOwnProperty;
22802
+ function propertyInData(gen, data, property, ownProperties) {
22803
+ const cond = (0, codegen_1$r._) `${data}${(0, codegen_1$r.getProperty)(property)} !== undefined`;
22804
+ return ownProperties ? (0, codegen_1$r._) `${cond} && ${isOwnProperty(gen, data, property)}` : cond;
22805
+ }
22806
+ code.propertyInData = propertyInData;
22807
+ function noPropertyInData(gen, data, property, ownProperties) {
22808
+ const cond = (0, codegen_1$r._) `${data}${(0, codegen_1$r.getProperty)(property)} === undefined`;
22809
+ return ownProperties ? (0, codegen_1$r.or)(cond, (0, codegen_1$r.not)(isOwnProperty(gen, data, property))) : cond;
22810
+ }
22811
+ code.noPropertyInData = noPropertyInData;
22812
+ function allSchemaProperties(schemaMap) {
22813
+ return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
22814
+ }
22815
+ code.allSchemaProperties = allSchemaProperties;
22816
+ function schemaProperties(it, schemaMap) {
22817
+ return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$q.alwaysValidSchema)(it, schemaMap[p]));
22818
+ }
22819
+ code.schemaProperties = schemaProperties;
22820
+ function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
22821
+ const dataAndSchema = passSchema ? (0, codegen_1$r._) `${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
22822
+ const valCxt = [
22823
+ [names_1$6.default.instancePath, (0, codegen_1$r.strConcat)(names_1$6.default.instancePath, errorPath)],
22824
+ [names_1$6.default.parentData, it.parentData],
22825
+ [names_1$6.default.parentDataProperty, it.parentDataProperty],
22826
+ [names_1$6.default.rootData, names_1$6.default.rootData],
22827
+ ];
22828
+ if (it.opts.dynamicRef)
22829
+ valCxt.push([names_1$6.default.dynamicAnchors, names_1$6.default.dynamicAnchors]);
22830
+ const args = (0, codegen_1$r._) `${dataAndSchema}, ${gen.object(...valCxt)}`;
22831
+ return context !== codegen_1$r.nil ? (0, codegen_1$r._) `${func}.call(${context}, ${args})` : (0, codegen_1$r._) `${func}(${args})`;
22832
+ }
22833
+ code.callValidateCode = callValidateCode;
22834
+ const newRegExp = (0, codegen_1$r._) `new RegExp`;
22835
+ function usePattern({ gen, it: { opts } }, pattern) {
22836
+ const u = opts.unicodeRegExp ? "u" : "";
22837
+ const { regExp } = opts.code;
22838
+ const rx = regExp(pattern, u);
22839
+ return gen.scopeValue("pattern", {
22840
+ key: rx.toString(),
22841
+ ref: rx,
22842
+ code: (0, codegen_1$r._) `${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern}, ${u})`,
22843
+ });
22844
+ }
22845
+ code.usePattern = usePattern;
22846
+ function validateArray(cxt) {
22847
+ const { gen, data, keyword, it } = cxt;
22848
+ const valid = gen.name("valid");
22849
+ if (it.allErrors) {
22850
+ const validArr = gen.let("valid", true);
22851
+ validateItems(() => gen.assign(validArr, false));
22852
+ return validArr;
22853
+ }
22854
+ gen.var(valid, true);
22855
+ validateItems(() => gen.break());
22856
+ return valid;
22857
+ function validateItems(notValid) {
22858
+ const len = gen.const("len", (0, codegen_1$r._) `${data}.length`);
22859
+ gen.forRange("i", 0, len, (i) => {
22860
+ cxt.subschema({
22861
+ keyword,
22862
+ dataProp: i,
22863
+ dataPropType: util_1$q.Type.Num,
22864
+ }, valid);
22865
+ gen.if((0, codegen_1$r.not)(valid), notValid);
22866
+ });
22867
+ }
22868
+ }
22869
+ code.validateArray = validateArray;
22870
+ function validateUnion(cxt) {
22871
+ const { gen, schema, keyword, it } = cxt;
22872
+ /* istanbul ignore if */
22873
+ if (!Array.isArray(schema))
22874
+ throw new Error("ajv implementation error");
22875
+ const alwaysValid = schema.some((sch) => (0, util_1$q.alwaysValidSchema)(it, sch));
22876
+ if (alwaysValid && !it.opts.unevaluated)
22877
+ return;
22878
+ const valid = gen.let("valid", false);
22879
+ const schValid = gen.name("_valid");
22880
+ gen.block(() => schema.forEach((_sch, i) => {
22881
+ const schCxt = cxt.subschema({
22882
+ keyword,
22883
+ schemaProp: i,
22884
+ compositeRule: true,
22885
+ }, schValid);
22886
+ gen.assign(valid, (0, codegen_1$r._) `${valid} || ${schValid}`);
22887
+ const merged = cxt.mergeValidEvaluated(schCxt, schValid);
22888
+ // can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true)
22889
+ // or if all properties and items were evaluated (it.props === true && it.items === true)
22890
+ if (!merged)
22891
+ gen.if((0, codegen_1$r.not)(valid));
22892
+ }));
22893
+ cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
22785
22894
  }
22895
+ code.validateUnion = validateUnion;
22786
22896
 
22787
22897
  var hasRequiredKeyword;
22788
22898
 
@@ -22793,7 +22903,7 @@ function requireKeyword () {
22793
22903
  keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
22794
22904
  const codegen_1 = requireCodegen();
22795
22905
  const names_1 = requireNames();
22796
- const code_1 = requireCode();
22906
+ const code_1 = code;
22797
22907
  const errors_1 = requireErrors();
22798
22908
  function macroKeywordCode(cxt, def) {
22799
22909
  const { gen, keyword, schema, parentSchema, it } = cxt;
@@ -23311,7 +23421,7 @@ function requireValidate () {
23311
23421
  validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
23312
23422
  const boolSchema_1 = requireBoolSchema();
23313
23423
  const dataType_1 = dataType;
23314
- const applicability_1 = requireApplicability();
23424
+ const applicability_1 = applicability;
23315
23425
  const dataType_2 = dataType;
23316
23426
  const defaults_1 = requireDefaults();
23317
23427
  const keyword_1 = requireKeyword();
@@ -26197,7 +26307,7 @@ var ref = {};
26197
26307
  Object.defineProperty(ref, "__esModule", { value: true });
26198
26308
  ref.callRef = ref.getValidate = void 0;
26199
26309
  const ref_error_1 = requireRef_error();
26200
- const code_1$8 = requireCode();
26310
+ const code_1$8 = code;
26201
26311
  const codegen_1$p = requireCodegen();
26202
26312
  const names_1$4 = requireNames();
26203
26313
  const compile_1$2 = compile;
@@ -26443,7 +26553,7 @@ limitLength.default = def$x;
26443
26553
  var pattern = {};
26444
26554
 
26445
26555
  Object.defineProperty(pattern, "__esModule", { value: true });
26446
- const code_1$7 = requireCode();
26556
+ const code_1$7 = code;
26447
26557
  const codegen_1$l = requireCodegen();
26448
26558
  const error$h = {
26449
26559
  message: ({ schemaCode }) => (0, codegen_1$l.str) `must match pattern "${schemaCode}"`,
@@ -26493,7 +26603,7 @@ limitProperties.default = def$v;
26493
26603
  var required = {};
26494
26604
 
26495
26605
  Object.defineProperty(required, "__esModule", { value: true });
26496
- const code_1$6 = requireCode();
26606
+ const code_1$6 = code;
26497
26607
  const codegen_1$j = requireCodegen();
26498
26608
  const util_1$l = util;
26499
26609
  const error$f = {
@@ -26835,7 +26945,7 @@ Object.defineProperty(items, "__esModule", { value: true });
26835
26945
  items.validateTuple = void 0;
26836
26946
  const codegen_1$d = requireCodegen();
26837
26947
  const util_1$g = util;
26838
- const code_1$5 = requireCode();
26948
+ const code_1$5 = code;
26839
26949
  const def$o = {
26840
26950
  keyword: "items",
26841
26951
  type: "array",
@@ -26898,7 +27008,7 @@ var items2020 = {};
26898
27008
  Object.defineProperty(items2020, "__esModule", { value: true });
26899
27009
  const codegen_1$c = requireCodegen();
26900
27010
  const util_1$f = util;
26901
- const code_1$4 = requireCode();
27011
+ const code_1$4 = code;
26902
27012
  const additionalItems_1$1 = additionalItems;
26903
27013
  const error$9 = {
26904
27014
  message: ({ params: { len } }) => (0, codegen_1$c.str) `must NOT have more than ${len} items`,
@@ -27027,7 +27137,7 @@ var dependencies = {};
27027
27137
  exports.validateSchemaDeps = exports.validatePropertyDeps = exports.error = void 0;
27028
27138
  const codegen_1 = requireCodegen();
27029
27139
  const util_1 = util;
27030
- const code_1 = requireCode();
27140
+ const code_1 = code;
27031
27141
  exports.error = {
27032
27142
  message: ({ params: { property, depsCount, deps } }) => {
27033
27143
  const property_ies = depsCount === 1 ? "property" : "properties";
@@ -27151,7 +27261,7 @@ propertyNames.default = def$k;
27151
27261
  var additionalProperties = {};
27152
27262
 
27153
27263
  Object.defineProperty(additionalProperties, "__esModule", { value: true });
27154
- const code_1$3 = requireCode();
27264
+ const code_1$3 = code;
27155
27265
  const codegen_1$9 = requireCodegen();
27156
27266
  const names_1$3 = requireNames();
27157
27267
  const util_1$c = util;
@@ -27259,7 +27369,7 @@ var properties$g = {};
27259
27369
 
27260
27370
  Object.defineProperty(properties$g, "__esModule", { value: true });
27261
27371
  const validate_1 = requireValidate();
27262
- const code_1$2 = requireCode();
27372
+ const code_1$2 = code;
27263
27373
  const util_1$b = util;
27264
27374
  const additionalProperties_1$1 = additionalProperties;
27265
27375
  const def$i = {
@@ -27313,7 +27423,7 @@ properties$g.default = def$i;
27313
27423
  var patternProperties = {};
27314
27424
 
27315
27425
  Object.defineProperty(patternProperties, "__esModule", { value: true });
27316
- const code_1$1 = requireCode();
27426
+ const code_1$1 = code;
27317
27427
  const codegen_1$8 = requireCodegen();
27318
27428
  const util_1$a = util;
27319
27429
  const util_2 = util;
@@ -27416,7 +27526,7 @@ not.default = def$g;
27416
27526
  var anyOf = {};
27417
27527
 
27418
27528
  Object.defineProperty(anyOf, "__esModule", { value: true });
27419
- const code_1 = requireCode();
27529
+ const code_1 = code;
27420
27530
  const def$f = {
27421
27531
  keyword: "anyOf",
27422
27532
  schemaType: "array",
@@ -53468,7 +53578,7 @@ class OnChainZKPVerifier {
53468
53578
  });
53469
53579
  }
53470
53580
  }
53471
- const metadata = this.packMetadatas(metadataArr);
53581
+ const metadata = metadataArr.length ? this.packMetadatas(metadataArr) : '0x';
53472
53582
  payload.push({
53473
53583
  requestId: requestID,
53474
53584
  zkProof: zkProofEncoded,
@@ -53858,7 +53968,7 @@ class OnChainRevocationStorage {
53858
53968
  *
53859
53969
  * Creates an instance of OnChainIssuer.
53860
53970
  * @public
53861
- * @param {string} - onhcain contract address
53971
+ * @param {string} - onchain contract address
53862
53972
  * @param {string} - rpc url to connect to the blockchain
53863
53973
  */
53864
53974
  constructor(_config, contractAddress, _signer) {
@@ -54989,7 +55099,7 @@ class OnChainResolver {
54989
55099
  }
54990
55100
  return network;
54991
55101
  }
54992
- // TODO (illia-korotia): is dirty hack for mock in tests.
55102
+ // TODO: is dirty hack for mock in tests.
54993
55103
  // need to pass to constructor list of state stores not list of network configs
54994
55104
  _getStateStorageForIssuer(issuerId) {
54995
55105
  const issuerChainId = getChainId(DID.blockchainFromId(issuerId), DID.networkIdFromId(issuerId));
@@ -56383,10 +56493,10 @@ function fnvHash(str) {
56383
56493
  hash *= BigInt(0x100000001b3);
56384
56494
  hash %= uint64_max;
56385
56495
  }
56386
- let shash = hash.toString(16);
56387
- const n = 16 - shash.length;
56388
- shash = '0'.repeat(n).concat(shash);
56389
- return shash;
56496
+ let hashHex = hash.toString(16);
56497
+ const n = 16 - hashHex.length;
56498
+ hashHex = '0'.repeat(n).concat(hashHex);
56499
+ return hashHex;
56390
56500
  }
56391
56501
 
56392
56502
  /**