@0xpolygonid/js-sdk 1.24.1 → 1.25.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.
Files changed (31) hide show
  1. package/dist/browser/esm/index.js +138 -702
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +136 -701
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/auth-v2.js +6 -0
  6. package/dist/node/cjs/iden3comm/handlers/contract-request.js +7 -1
  7. package/dist/node/cjs/iden3comm/handlers/payment.js +27 -46
  8. package/dist/node/cjs/iden3comm/utils/contract-request.utils.js +59 -0
  9. package/dist/node/cjs/iden3comm/utils/index.js +1 -0
  10. package/dist/node/cjs/proof/proof-service.js +6 -0
  11. package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +56 -47
  12. package/dist/node/cjs/utils/did-helper.js +8 -3
  13. package/dist/node/cjs/verifiable/constants.js +1 -2
  14. package/dist/node/esm/circuits/auth-v2.js +6 -0
  15. package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -1
  16. package/dist/node/esm/iden3comm/handlers/payment.js +28 -46
  17. package/dist/node/esm/iden3comm/utils/contract-request.utils.js +54 -0
  18. package/dist/node/esm/iden3comm/utils/index.js +1 -0
  19. package/dist/node/esm/proof/proof-service.js +6 -0
  20. package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +58 -49
  21. package/dist/node/esm/utils/did-helper.js +8 -3
  22. package/dist/node/esm/verifiable/constants.js +1 -2
  23. package/dist/types/circuits/auth-v2.d.ts +3 -2
  24. package/dist/types/iden3comm/handlers/payment.d.ts +5 -9
  25. package/dist/types/iden3comm/types/protocol/payment.d.ts +6 -5
  26. package/dist/types/iden3comm/utils/contract-request.utils.d.ts +20 -0
  27. package/dist/types/iden3comm/utils/index.d.ts +1 -0
  28. package/dist/types/proof/proof-service.d.ts +10 -0
  29. package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +2 -0
  30. package/dist/types/verifiable/constants.d.ts +2 -3
  31. package/package.json +1 -1
@@ -1428,9 +1428,14 @@ var PolygonIdSdk = (function (exports) {
1428
1428
  if (opts?.gist) {
1429
1429
  url += `${url.includes('?') ? '&' : '?'}gist=${opts.gist.hex()}`;
1430
1430
  }
1431
- const resp = await fetch(url);
1432
- const data = await resp.json();
1433
- return data;
1431
+ try {
1432
+ const resp = await fetch(url);
1433
+ const data = await resp.json();
1434
+ return data;
1435
+ }
1436
+ catch (e) {
1437
+ throw new Error(`Failed to resolve DID document for ${did} ${e}`);
1438
+ }
1434
1439
  };
1435
1440
  const buildDIDFromEthPubKey = (didType, pubKeyEth) => {
1436
1441
  // Use Keccak-256 hash function to get public key hash
@@ -5451,7 +5456,7 @@ var PolygonIdSdk = (function (exports) {
5451
5456
  throw new Error('Unknown type, must be binary type');
5452
5457
  };
5453
5458
  const fromString$2 = str => new TextEncoder().encode(str);
5454
- const toString$8 = b => new TextDecoder().decode(b);
5459
+ const toString$7 = b => new TextDecoder().decode(b);
5455
5460
 
5456
5461
  class Encoder {
5457
5462
  constructor(name, prefix, baseEncode) {
@@ -5608,7 +5613,7 @@ var PolygonIdSdk = (function (exports) {
5608
5613
  const identity$1 = from({
5609
5614
  prefix: '\0',
5610
5615
  name: 'identity',
5611
- encode: buf => toString$8(buf),
5616
+ encode: buf => toString$7(buf),
5612
5617
  decode: str => fromString$2(str)
5613
5618
  });
5614
5619
 
@@ -5972,7 +5977,7 @@ var PolygonIdSdk = (function (exports) {
5972
5977
  return base.decoder.decode(`${ base.prefix }${ string }`);
5973
5978
  }
5974
5979
 
5975
- function toString$7(array, encoding = 'utf8') {
5980
+ function toString$6(array, encoding = 'utf8') {
5976
5981
  const base = BASES[encoding];
5977
5982
  if (!base) {
5978
5983
  throw new Error(`Unsupported encoding "${ encoding }"`);
@@ -6366,19 +6371,19 @@ var PolygonIdSdk = (function (exports) {
6366
6371
  ];
6367
6372
 
6368
6373
  /** @type {Record<BaseName,Base>} */
6369
- const names$2 = constants$2.reduce((prev, tupple) => {
6374
+ const names$1 = constants$2.reduce((prev, tupple) => {
6370
6375
  prev[tupple[0]] = new Base(tupple[0], tupple[1], tupple[2], tupple[3]);
6371
6376
  return prev
6372
6377
  }, /** @type {Record<BaseName,Base>} */({}));
6373
6378
 
6374
6379
  /** @type {Record<BaseCode,Base>} */
6375
6380
  const codes$1 = constants$2.reduce((prev, tupple) => {
6376
- prev[tupple[1]] = names$2[tupple[0]];
6381
+ prev[tupple[1]] = names$1[tupple[0]];
6377
6382
  return prev
6378
6383
  }, /** @type {Record<BaseCode,Base>} */({}));
6379
6384
 
6380
6385
  var constants_1 = {
6381
- names: names$2,
6386
+ names: names$1,
6382
6387
  codes: codes$1
6383
6388
  };
6384
6389
 
@@ -7150,7 +7155,7 @@ var PolygonIdSdk = (function (exports) {
7150
7155
  const bech32 = /* @__PURE__ */ genBech32('bech32');
7151
7156
 
7152
7157
  const u8a$2 = {
7153
- toString: toString$7,
7158
+ toString: toString$6,
7154
7159
  fromString: fromString$1,
7155
7160
  concat: concat$2
7156
7161
  };
@@ -7348,7 +7353,7 @@ var PolygonIdSdk = (function (exports) {
7348
7353
  const keccak = keccak_256$1;
7349
7354
  function toEthereumAddress(hexPublicKey) {
7350
7355
  const hashInput = fromString$1(hexPublicKey.slice(2), 'base16');
7351
- return `0x${toString$7(keccak(hashInput).slice(-20), 'base16')}`;
7356
+ return `0x${toString$6(keccak(hashInput).slice(-20), 'base16')}`;
7352
7357
  }
7353
7358
 
7354
7359
  /**
@@ -7872,6 +7877,7 @@ var PolygonIdSdk = (function (exports) {
7872
7877
  /**
7873
7878
  * Media types for Payment supported currencies
7874
7879
  * @beta
7880
+ * @deprecated
7875
7881
  * @enum {string}
7876
7882
  */
7877
7883
  exports.SupportedCurrencies = void 0;
@@ -7881,8 +7887,6 @@ var PolygonIdSdk = (function (exports) {
7881
7887
  SupportedCurrencies["ETH_GWEI"] = "ETHGWEI";
7882
7888
  SupportedCurrencies["MATIC"] = "MATIC";
7883
7889
  SupportedCurrencies["POL"] = "POL";
7884
- SupportedCurrencies["USDT"] = "USDT";
7885
- SupportedCurrencies["USDC"] = "USDC";
7886
7890
  })(exports.SupportedCurrencies || (exports.SupportedCurrencies = {}));
7887
7891
  /**
7888
7892
  * Supported features for payment-request
@@ -22501,16 +22505,16 @@ var PolygonIdSdk = (function (exports) {
22501
22505
 
22502
22506
  } (util));
22503
22507
 
22504
- var names$1 = {};
22508
+ var names = {};
22505
22509
 
22506
22510
  var hasRequiredNames;
22507
22511
 
22508
22512
  function requireNames () {
22509
- if (hasRequiredNames) return names$1;
22513
+ if (hasRequiredNames) return names;
22510
22514
  hasRequiredNames = 1;
22511
- Object.defineProperty(names$1, "__esModule", { value: true });
22515
+ Object.defineProperty(names, "__esModule", { value: true });
22512
22516
  const codegen_1 = requireCodegen();
22513
- const names = {
22517
+ const names$1 = {
22514
22518
  // validation function arguments
22515
22519
  data: new codegen_1.Name("data"),
22516
22520
  // args passed from referencing schema
@@ -22533,9 +22537,9 @@ var PolygonIdSdk = (function (exports) {
22533
22537
  jsonLen: new codegen_1.Name("jsonLen"),
22534
22538
  jsonPart: new codegen_1.Name("jsonPart"),
22535
22539
  };
22536
- names$1.default = names;
22540
+ names.default = names$1;
22537
22541
 
22538
- return names$1;
22542
+ return names;
22539
22543
  }
22540
22544
 
22541
22545
  var hasRequiredErrors;
@@ -30969,8 +30973,8 @@ var PolygonIdSdk = (function (exports) {
30969
30973
  *
30970
30974
  * @_subsection: api/utils:Math Helpers [about-maths]
30971
30975
  */
30972
- const BN_0$9 = BigInt(0);
30973
- const BN_1$4 = BigInt(1);
30976
+ const BN_0$8 = BigInt(0);
30977
+ const BN_1$3 = BigInt(1);
30974
30978
  //const BN_Max256 = (BN_1 << BigInt(256)) - BN_1;
30975
30979
  // IEEE 754 support 53-bits of mantissa
30976
30980
  const maxValue = 0x1fffffffffffff;
@@ -30983,13 +30987,13 @@ var PolygonIdSdk = (function (exports) {
30983
30987
  function fromTwos(_value, _width) {
30984
30988
  const value = getUint(_value, "value");
30985
30989
  const width = BigInt(getNumber(_width, "width"));
30986
- assert$2((value >> width) === BN_0$9, "overflow", "NUMERIC_FAULT", {
30990
+ assert$2((value >> width) === BN_0$8, "overflow", "NUMERIC_FAULT", {
30987
30991
  operation: "fromTwos", fault: "overflow", value: _value
30988
30992
  });
30989
30993
  // Top bit set; treat as a negative value
30990
- if (value >> (width - BN_1$4)) {
30991
- const mask = (BN_1$4 << width) - BN_1$4;
30992
- return -(((~value) & mask) + BN_1$4);
30994
+ if (value >> (width - BN_1$3)) {
30995
+ const mask = (BN_1$3 << width) - BN_1$3;
30996
+ return -(((~value) & mask) + BN_1$3);
30993
30997
  }
30994
30998
  return value;
30995
30999
  }
@@ -31002,14 +31006,14 @@ var PolygonIdSdk = (function (exports) {
31002
31006
  function toTwos(_value, _width) {
31003
31007
  let value = getBigInt(_value, "value");
31004
31008
  const width = BigInt(getNumber(_width, "width"));
31005
- const limit = (BN_1$4 << (width - BN_1$4));
31006
- if (value < BN_0$9) {
31009
+ const limit = (BN_1$3 << (width - BN_1$3));
31010
+ if (value < BN_0$8) {
31007
31011
  value = -value;
31008
31012
  assert$2(value <= limit, "too low", "NUMERIC_FAULT", {
31009
31013
  operation: "toTwos", fault: "overflow", value: _value
31010
31014
  });
31011
- const mask = (BN_1$4 << width) - BN_1$4;
31012
- return ((~value) & mask) + BN_1$4;
31015
+ const mask = (BN_1$3 << width) - BN_1$3;
31016
+ return ((~value) & mask) + BN_1$3;
31013
31017
  }
31014
31018
  else {
31015
31019
  assert$2(value < limit, "too high", "NUMERIC_FAULT", {
@@ -31024,7 +31028,7 @@ var PolygonIdSdk = (function (exports) {
31024
31028
  function mask(_value, _bits) {
31025
31029
  const value = getUint(_value, "value");
31026
31030
  const bits = BigInt(getNumber(_bits, "bits"));
31027
- return value & ((BN_1$4 << bits) - BN_1$4);
31031
+ return value & ((BN_1$3 << bits) - BN_1$3);
31028
31032
  }
31029
31033
  /**
31030
31034
  * Gets a BigInt from %%value%%. If it is an invalid value for
@@ -31059,7 +31063,7 @@ var PolygonIdSdk = (function (exports) {
31059
31063
  */
31060
31064
  function getUint(value, name) {
31061
31065
  const result = getBigInt(value, name);
31062
- assert$2(result >= BN_0$9, "unsigned value cannot be negative", "NUMERIC_FAULT", {
31066
+ assert$2(result >= BN_0$8, "unsigned value cannot be negative", "NUMERIC_FAULT", {
31063
31067
  fault: "overflow", operation: "getUint", value
31064
31068
  });
31065
31069
  return result;
@@ -31145,7 +31149,7 @@ var PolygonIdSdk = (function (exports) {
31145
31149
  */
31146
31150
  function toBeArray(_value) {
31147
31151
  const value = getUint(_value, "value");
31148
- if (value === BN_0$9) {
31152
+ if (value === BN_0$8) {
31149
31153
  return new Uint8Array([]);
31150
31154
  }
31151
31155
  let hex = value.toString(16);
@@ -32377,526 +32381,6 @@ var PolygonIdSdk = (function (exports) {
32377
32381
  return new Promise((resolve) => setTimeout(resolve, delay));
32378
32382
  }
32379
32383
 
32380
- /**
32381
- * The **FixedNumber** class permits using values with decimal places,
32382
- * using fixed-pont math.
32383
- *
32384
- * Fixed-point math is still based on integers under-the-hood, but uses an
32385
- * internal offset to store fractional components below, and each operation
32386
- * corrects for this after each operation.
32387
- *
32388
- * @_section: api/utils/fixed-point-math:Fixed-Point Maths [about-fixed-point-math]
32389
- */
32390
- const BN_N1 = BigInt(-1);
32391
- const BN_0$8 = BigInt(0);
32392
- const BN_1$3 = BigInt(1);
32393
- const BN_5 = BigInt(5);
32394
- const _guard$3 = {};
32395
- // Constant to pull zeros from for multipliers
32396
- let Zeros$1 = "0000";
32397
- while (Zeros$1.length < 80) {
32398
- Zeros$1 += Zeros$1;
32399
- }
32400
- // Returns a string "1" followed by decimal "0"s
32401
- function getTens(decimals) {
32402
- let result = Zeros$1;
32403
- while (result.length < decimals) {
32404
- result += result;
32405
- }
32406
- return BigInt("1" + result.substring(0, decimals));
32407
- }
32408
- function checkValue(val, format, safeOp) {
32409
- const width = BigInt(format.width);
32410
- if (format.signed) {
32411
- const limit = (BN_1$3 << (width - BN_1$3));
32412
- assert$2(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", {
32413
- operation: safeOp, fault: "overflow", value: val
32414
- });
32415
- if (val > BN_0$8) {
32416
- val = fromTwos(mask(val, width), width);
32417
- }
32418
- else {
32419
- val = -fromTwos(mask(-val, width), width);
32420
- }
32421
- }
32422
- else {
32423
- const limit = (BN_1$3 << width);
32424
- assert$2(safeOp == null || (val >= 0 && val < limit), "overflow", "NUMERIC_FAULT", {
32425
- operation: safeOp, fault: "overflow", value: val
32426
- });
32427
- val = (((val % limit) + limit) % limit) & (limit - BN_1$3);
32428
- }
32429
- return val;
32430
- }
32431
- function getFormat(value) {
32432
- if (typeof (value) === "number") {
32433
- value = `fixed128x${value}`;
32434
- }
32435
- let signed = true;
32436
- let width = 128;
32437
- let decimals = 18;
32438
- if (typeof (value) === "string") {
32439
- // Parse the format string
32440
- if (value === "fixed") ;
32441
- else if (value === "ufixed") {
32442
- signed = false;
32443
- }
32444
- else {
32445
- const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);
32446
- assertArgument(match, "invalid fixed format", "format", value);
32447
- signed = (match[1] !== "u");
32448
- width = parseInt(match[2]);
32449
- decimals = parseInt(match[3]);
32450
- }
32451
- }
32452
- else if (value) {
32453
- // Extract the values from the object
32454
- const v = value;
32455
- const check = (key, type, defaultValue) => {
32456
- if (v[key] == null) {
32457
- return defaultValue;
32458
- }
32459
- assertArgument(typeof (v[key]) === type, "invalid fixed format (" + key + " not " + type + ")", "format." + key, v[key]);
32460
- return v[key];
32461
- };
32462
- signed = check("signed", "boolean", signed);
32463
- width = check("width", "number", width);
32464
- decimals = check("decimals", "number", decimals);
32465
- }
32466
- assertArgument((width % 8) === 0, "invalid FixedNumber width (not byte aligned)", "format.width", width);
32467
- assertArgument(decimals <= 80, "invalid FixedNumber decimals (too large)", "format.decimals", decimals);
32468
- const name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals);
32469
- return { signed, width, decimals, name };
32470
- }
32471
- function toString$6(val, decimals) {
32472
- let negative = "";
32473
- if (val < BN_0$8) {
32474
- negative = "-";
32475
- val *= BN_N1;
32476
- }
32477
- let str = val.toString();
32478
- // No decimal point for whole values
32479
- if (decimals === 0) {
32480
- return (negative + str);
32481
- }
32482
- // Pad out to the whole component (including a whole digit)
32483
- while (str.length <= decimals) {
32484
- str = Zeros$1 + str;
32485
- }
32486
- // Insert the decimal point
32487
- const index = str.length - decimals;
32488
- str = str.substring(0, index) + "." + str.substring(index);
32489
- // Trim the whole component (leaving at least one 0)
32490
- while (str[0] === "0" && str[1] !== ".") {
32491
- str = str.substring(1);
32492
- }
32493
- // Trim the decimal component (leaving at least one 0)
32494
- while (str[str.length - 1] === "0" && str[str.length - 2] !== ".") {
32495
- str = str.substring(0, str.length - 1);
32496
- }
32497
- return (negative + str);
32498
- }
32499
- /**
32500
- * A FixedNumber represents a value over its [[FixedFormat]]
32501
- * arithmetic field.
32502
- *
32503
- * A FixedNumber can be used to perform math, losslessly, on
32504
- * values which have decmial places.
32505
- *
32506
- * A FixedNumber has a fixed bit-width to store values in, and stores all
32507
- * values internally by multiplying the value by 10 raised to the power of
32508
- * %%decimals%%.
32509
- *
32510
- * If operations are performed that cause a value to grow too high (close to
32511
- * positive infinity) or too low (close to negative infinity), the value
32512
- * is said to //overflow//.
32513
- *
32514
- * For example, an 8-bit signed value, with 0 decimals may only be within
32515
- * the range ``-128`` to ``127``; so ``-128 - 1`` will overflow and become
32516
- * ``127``. Likewise, ``127 + 1`` will overflow and become ``-127``.
32517
- *
32518
- * Many operation have a normal and //unsafe// variant. The normal variant
32519
- * will throw a [[NumericFaultError]] on any overflow, while the //unsafe//
32520
- * variant will silently allow overflow, corrupting its value value.
32521
- *
32522
- * If operations are performed that cause a value to become too small
32523
- * (close to zero), the value loses precison and is said to //underflow//.
32524
- *
32525
- * For example, an value with 1 decimal place may store a number as small
32526
- * as ``0.1``, but the value of ``0.1 / 2`` is ``0.05``, which cannot fit
32527
- * into 1 decimal place, so underflow occurs which means precision is lost
32528
- * and the value becomes ``0``.
32529
- *
32530
- * Some operations have a normal and //signalling// variant. The normal
32531
- * variant will silently ignore underflow, while the //signalling// variant
32532
- * will thow a [[NumericFaultError]] on underflow.
32533
- */
32534
- class FixedNumber {
32535
- /**
32536
- * The specific fixed-point arithmetic field for this value.
32537
- */
32538
- format;
32539
- #format;
32540
- // The actual value (accounting for decimals)
32541
- #val;
32542
- // A base-10 value to multiple values by to maintain the magnitude
32543
- #tens;
32544
- /**
32545
- * This is a property so console.log shows a human-meaningful value.
32546
- *
32547
- * @private
32548
- */
32549
- _value;
32550
- // Use this when changing this file to get some typing info,
32551
- // but then switch to any to mask the internal type
32552
- //constructor(guard: any, value: bigint, format: _FixedFormat) {
32553
- /**
32554
- * @private
32555
- */
32556
- constructor(guard, value, format) {
32557
- assertPrivate(guard, _guard$3, "FixedNumber");
32558
- this.#val = value;
32559
- this.#format = format;
32560
- const _value = toString$6(value, format.decimals);
32561
- defineProperties(this, { format: format.name, _value });
32562
- this.#tens = getTens(format.decimals);
32563
- }
32564
- /**
32565
- * If true, negative values are permitted, otherwise only
32566
- * positive values and zero are allowed.
32567
- */
32568
- get signed() { return this.#format.signed; }
32569
- /**
32570
- * The number of bits available to store the value.
32571
- */
32572
- get width() { return this.#format.width; }
32573
- /**
32574
- * The number of decimal places in the fixed-point arithment field.
32575
- */
32576
- get decimals() { return this.#format.decimals; }
32577
- /**
32578
- * The value as an integer, based on the smallest unit the
32579
- * [[decimals]] allow.
32580
- */
32581
- get value() { return this.#val; }
32582
- #checkFormat(other) {
32583
- assertArgument(this.format === other.format, "incompatible format; use fixedNumber.toFormat", "other", other);
32584
- }
32585
- #checkValue(val, safeOp) {
32586
- /*
32587
- const width = BigInt(this.width);
32588
- if (this.signed) {
32589
- const limit = (BN_1 << (width - BN_1));
32590
- assert(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", {
32591
- operation: <string>safeOp, fault: "overflow", value: val
32592
- });
32593
-
32594
- if (val > BN_0) {
32595
- val = fromTwos(mask(val, width), width);
32596
- } else {
32597
- val = -fromTwos(mask(-val, width), width);
32598
- }
32599
-
32600
- } else {
32601
- const masked = mask(val, width);
32602
- assert(safeOp == null || (val >= 0 && val === masked), "overflow", "NUMERIC_FAULT", {
32603
- operation: <string>safeOp, fault: "overflow", value: val
32604
- });
32605
- val = masked;
32606
- }
32607
- */
32608
- val = checkValue(val, this.#format, safeOp);
32609
- return new FixedNumber(_guard$3, val, this.#format);
32610
- }
32611
- #add(o, safeOp) {
32612
- this.#checkFormat(o);
32613
- return this.#checkValue(this.#val + o.#val, safeOp);
32614
- }
32615
- /**
32616
- * Returns a new [[FixedNumber]] with the result of %%this%% added
32617
- * to %%other%%, ignoring overflow.
32618
- */
32619
- addUnsafe(other) { return this.#add(other); }
32620
- /**
32621
- * Returns a new [[FixedNumber]] with the result of %%this%% added
32622
- * to %%other%%. A [[NumericFaultError]] is thrown if overflow
32623
- * occurs.
32624
- */
32625
- add(other) { return this.#add(other, "add"); }
32626
- #sub(o, safeOp) {
32627
- this.#checkFormat(o);
32628
- return this.#checkValue(this.#val - o.#val, safeOp);
32629
- }
32630
- /**
32631
- * Returns a new [[FixedNumber]] with the result of %%other%% subtracted
32632
- * from %%this%%, ignoring overflow.
32633
- */
32634
- subUnsafe(other) { return this.#sub(other); }
32635
- /**
32636
- * Returns a new [[FixedNumber]] with the result of %%other%% subtracted
32637
- * from %%this%%. A [[NumericFaultError]] is thrown if overflow
32638
- * occurs.
32639
- */
32640
- sub(other) { return this.#sub(other, "sub"); }
32641
- #mul(o, safeOp) {
32642
- this.#checkFormat(o);
32643
- return this.#checkValue((this.#val * o.#val) / this.#tens, safeOp);
32644
- }
32645
- /**
32646
- * Returns a new [[FixedNumber]] with the result of %%this%% multiplied
32647
- * by %%other%%, ignoring overflow and underflow (precision loss).
32648
- */
32649
- mulUnsafe(other) { return this.#mul(other); }
32650
- /**
32651
- * Returns a new [[FixedNumber]] with the result of %%this%% multiplied
32652
- * by %%other%%. A [[NumericFaultError]] is thrown if overflow
32653
- * occurs.
32654
- */
32655
- mul(other) { return this.#mul(other, "mul"); }
32656
- /**
32657
- * Returns a new [[FixedNumber]] with the result of %%this%% multiplied
32658
- * by %%other%%. A [[NumericFaultError]] is thrown if overflow
32659
- * occurs or if underflow (precision loss) occurs.
32660
- */
32661
- mulSignal(other) {
32662
- this.#checkFormat(other);
32663
- const value = this.#val * other.#val;
32664
- assert$2((value % this.#tens) === BN_0$8, "precision lost during signalling mul", "NUMERIC_FAULT", {
32665
- operation: "mulSignal", fault: "underflow", value: this
32666
- });
32667
- return this.#checkValue(value / this.#tens, "mulSignal");
32668
- }
32669
- #div(o, safeOp) {
32670
- assert$2(o.#val !== BN_0$8, "division by zero", "NUMERIC_FAULT", {
32671
- operation: "div", fault: "divide-by-zero", value: this
32672
- });
32673
- this.#checkFormat(o);
32674
- return this.#checkValue((this.#val * this.#tens) / o.#val, safeOp);
32675
- }
32676
- /**
32677
- * Returns a new [[FixedNumber]] with the result of %%this%% divided
32678
- * by %%other%%, ignoring underflow (precision loss). A
32679
- * [[NumericFaultError]] is thrown if overflow occurs.
32680
- */
32681
- divUnsafe(other) { return this.#div(other); }
32682
- /**
32683
- * Returns a new [[FixedNumber]] with the result of %%this%% divided
32684
- * by %%other%%, ignoring underflow (precision loss). A
32685
- * [[NumericFaultError]] is thrown if overflow occurs.
32686
- */
32687
- div(other) { return this.#div(other, "div"); }
32688
- /**
32689
- * Returns a new [[FixedNumber]] with the result of %%this%% divided
32690
- * by %%other%%. A [[NumericFaultError]] is thrown if underflow
32691
- * (precision loss) occurs.
32692
- */
32693
- divSignal(other) {
32694
- assert$2(other.#val !== BN_0$8, "division by zero", "NUMERIC_FAULT", {
32695
- operation: "div", fault: "divide-by-zero", value: this
32696
- });
32697
- this.#checkFormat(other);
32698
- const value = (this.#val * this.#tens);
32699
- assert$2((value % other.#val) === BN_0$8, "precision lost during signalling div", "NUMERIC_FAULT", {
32700
- operation: "divSignal", fault: "underflow", value: this
32701
- });
32702
- return this.#checkValue(value / other.#val, "divSignal");
32703
- }
32704
- /**
32705
- * Returns a comparison result between %%this%% and %%other%%.
32706
- *
32707
- * This is suitable for use in sorting, where ``-1`` implies %%this%%
32708
- * is smaller, ``1`` implies %%this%% is larger and ``0`` implies
32709
- * both are equal.
32710
- */
32711
- cmp(other) {
32712
- let a = this.value, b = other.value;
32713
- // Coerce a and b to the same magnitude
32714
- const delta = this.decimals - other.decimals;
32715
- if (delta > 0) {
32716
- b *= getTens(delta);
32717
- }
32718
- else if (delta < 0) {
32719
- a *= getTens(-delta);
32720
- }
32721
- // Comnpare
32722
- if (a < b) {
32723
- return -1;
32724
- }
32725
- if (a > b) {
32726
- return 1;
32727
- }
32728
- return 0;
32729
- }
32730
- /**
32731
- * Returns true if %%other%% is equal to %%this%%.
32732
- */
32733
- eq(other) { return this.cmp(other) === 0; }
32734
- /**
32735
- * Returns true if %%other%% is less than to %%this%%.
32736
- */
32737
- lt(other) { return this.cmp(other) < 0; }
32738
- /**
32739
- * Returns true if %%other%% is less than or equal to %%this%%.
32740
- */
32741
- lte(other) { return this.cmp(other) <= 0; }
32742
- /**
32743
- * Returns true if %%other%% is greater than to %%this%%.
32744
- */
32745
- gt(other) { return this.cmp(other) > 0; }
32746
- /**
32747
- * Returns true if %%other%% is greater than or equal to %%this%%.
32748
- */
32749
- gte(other) { return this.cmp(other) >= 0; }
32750
- /**
32751
- * Returns a new [[FixedNumber]] which is the largest **integer**
32752
- * that is less than or equal to %%this%%.
32753
- *
32754
- * The decimal component of the result will always be ``0``.
32755
- */
32756
- floor() {
32757
- let val = this.#val;
32758
- if (this.#val < BN_0$8) {
32759
- val -= this.#tens - BN_1$3;
32760
- }
32761
- val = (this.#val / this.#tens) * this.#tens;
32762
- return this.#checkValue(val, "floor");
32763
- }
32764
- /**
32765
- * Returns a new [[FixedNumber]] which is the smallest **integer**
32766
- * that is greater than or equal to %%this%%.
32767
- *
32768
- * The decimal component of the result will always be ``0``.
32769
- */
32770
- ceiling() {
32771
- let val = this.#val;
32772
- if (this.#val > BN_0$8) {
32773
- val += this.#tens - BN_1$3;
32774
- }
32775
- val = (this.#val / this.#tens) * this.#tens;
32776
- return this.#checkValue(val, "ceiling");
32777
- }
32778
- /**
32779
- * Returns a new [[FixedNumber]] with the decimal component
32780
- * rounded up on ties at %%decimals%% places.
32781
- */
32782
- round(decimals) {
32783
- if (decimals == null) {
32784
- decimals = 0;
32785
- }
32786
- // Not enough precision to not already be rounded
32787
- if (decimals >= this.decimals) {
32788
- return this;
32789
- }
32790
- const delta = this.decimals - decimals;
32791
- const bump = BN_5 * getTens(delta - 1);
32792
- let value = this.value + bump;
32793
- const tens = getTens(delta);
32794
- value = (value / tens) * tens;
32795
- checkValue(value, this.#format, "round");
32796
- return new FixedNumber(_guard$3, value, this.#format);
32797
- }
32798
- /**
32799
- * Returns true if %%this%% is equal to ``0``.
32800
- */
32801
- isZero() { return (this.#val === BN_0$8); }
32802
- /**
32803
- * Returns true if %%this%% is less than ``0``.
32804
- */
32805
- isNegative() { return (this.#val < BN_0$8); }
32806
- /**
32807
- * Returns the string representation of %%this%%.
32808
- */
32809
- toString() { return this._value; }
32810
- /**
32811
- * Returns a float approximation.
32812
- *
32813
- * Due to IEEE 754 precission (or lack thereof), this function
32814
- * can only return an approximation and most values will contain
32815
- * rounding errors.
32816
- */
32817
- toUnsafeFloat() { return parseFloat(this.toString()); }
32818
- /**
32819
- * Return a new [[FixedNumber]] with the same value but has had
32820
- * its field set to %%format%%.
32821
- *
32822
- * This will throw if the value cannot fit into %%format%%.
32823
- */
32824
- toFormat(format) {
32825
- return FixedNumber.fromString(this.toString(), format);
32826
- }
32827
- /**
32828
- * Creates a new [[FixedNumber]] for %%value%% divided by
32829
- * %%decimal%% places with %%format%%.
32830
- *
32831
- * This will throw a [[NumericFaultError]] if %%value%% (once adjusted
32832
- * for %%decimals%%) cannot fit in %%format%%, either due to overflow
32833
- * or underflow (precision loss).
32834
- */
32835
- static fromValue(_value, _decimals, _format) {
32836
- const decimals = (_decimals == null) ? 0 : getNumber(_decimals);
32837
- const format = getFormat(_format);
32838
- let value = getBigInt(_value, "value");
32839
- const delta = decimals - format.decimals;
32840
- if (delta > 0) {
32841
- const tens = getTens(delta);
32842
- assert$2((value % tens) === BN_0$8, "value loses precision for format", "NUMERIC_FAULT", {
32843
- operation: "fromValue", fault: "underflow", value: _value
32844
- });
32845
- value /= tens;
32846
- }
32847
- else if (delta < 0) {
32848
- value *= getTens(-delta);
32849
- }
32850
- checkValue(value, format, "fromValue");
32851
- return new FixedNumber(_guard$3, value, format);
32852
- }
32853
- /**
32854
- * Creates a new [[FixedNumber]] for %%value%% with %%format%%.
32855
- *
32856
- * This will throw a [[NumericFaultError]] if %%value%% cannot fit
32857
- * in %%format%%, either due to overflow or underflow (precision loss).
32858
- */
32859
- static fromString(_value, _format) {
32860
- const match = _value.match(/^(-?)([0-9]*)\.?([0-9]*)$/);
32861
- assertArgument(match && (match[2].length + match[3].length) > 0, "invalid FixedNumber string value", "value", _value);
32862
- const format = getFormat(_format);
32863
- let whole = (match[2] || "0"), decimal = (match[3] || "");
32864
- // Pad out the decimals
32865
- while (decimal.length < format.decimals) {
32866
- decimal += Zeros$1;
32867
- }
32868
- // Check precision is safe
32869
- assert$2(decimal.substring(format.decimals).match(/^0*$/), "too many decimals for format", "NUMERIC_FAULT", {
32870
- operation: "fromString", fault: "underflow", value: _value
32871
- });
32872
- // Remove extra padding
32873
- decimal = decimal.substring(0, format.decimals);
32874
- const value = BigInt(match[1] + whole + decimal);
32875
- checkValue(value, format, "fromString");
32876
- return new FixedNumber(_guard$3, value, format);
32877
- }
32878
- /**
32879
- * Creates a new [[FixedNumber]] with the big-endian representation
32880
- * %%value%% with %%format%%.
32881
- *
32882
- * This will throw a [[NumericFaultError]] if %%value%% cannot fit
32883
- * in %%format%% due to overflow.
32884
- */
32885
- static fromBytes(_value, _format) {
32886
- let value = toBigInt(getBytes(_value, "value"));
32887
- const format = getFormat(_format);
32888
- if (format.signed) {
32889
- value = fromTwos(value, format.width);
32890
- }
32891
- checkValue(value, format, "fromBytes");
32892
- return new FixedNumber(_guard$3, value, format);
32893
- }
32894
- }
32895
- //const f1 = FixedNumber.fromString("12.56", "fixed16x2");
32896
- //const f2 = FixedNumber.fromString("0.3", "fixed16x2");
32897
- //console.log(f1.divSignal(f2));
32898
- //const BUMP = FixedNumber.from("0.5");
32899
-
32900
32384
  //See: https://github.com/ethereum/wiki/wiki/RLP
32901
32385
  function hexlifyByte(value) {
32902
32386
  let result = value.toString(16);
@@ -33021,62 +32505,6 @@ var PolygonIdSdk = (function (exports) {
33021
32505
  return result;
33022
32506
  }
33023
32507
 
33024
- /**
33025
- * Most interactions with Ethereum requires integer values, which use
33026
- * the smallest magnitude unit.
33027
- *
33028
- * For example, imagine dealing with dollars and cents. Since dollars
33029
- * are divisible, non-integer values are possible, such as ``$10.77``.
33030
- * By using the smallest indivisible unit (i.e. cents), the value can
33031
- * be kept as the integer ``1077``.
33032
- *
33033
- * When receiving decimal input from the user (as a decimal string),
33034
- * the value should be converted to an integer and when showing a user
33035
- * a value, the integer value should be converted to a decimal string.
33036
- *
33037
- * This creates a clear distinction, between values to be used by code
33038
- * (integers) and values used for display logic to users (decimals).
33039
- *
33040
- * The native unit in Ethereum, //ether// is divisible to 18 decimal places,
33041
- * where each individual unit is called a //wei//.
33042
- *
33043
- * @_subsection api/utils:Unit Conversion [about-units]
33044
- */
33045
- const names = [
33046
- "wei",
33047
- "kwei",
33048
- "mwei",
33049
- "gwei",
33050
- "szabo",
33051
- "finney",
33052
- "ether",
33053
- ];
33054
- /**
33055
- * Converts the //decimal string// %%value%% to a BigInt, assuming
33056
- * %%unit%% decimal places. The %%unit%% may the number of decimal places
33057
- * or the name of a unit (e.g. ``"gwei"`` for 9 decimal places).
33058
- */
33059
- function parseUnits$1(value, unit) {
33060
- assertArgument(typeof (value) === "string", "value must be a string", "value", value);
33061
- let decimals = 18;
33062
- if (typeof (unit) === "string") {
33063
- const index = names.indexOf(unit);
33064
- assertArgument(index >= 0, "invalid unit", "unit", unit);
33065
- decimals = 3 * index;
33066
- }
33067
- else if (unit != null) {
33068
- decimals = getNumber(unit, "unit");
33069
- }
33070
- return FixedNumber.fromString(value, { decimals, width: 512 }).value;
33071
- }
33072
- /**
33073
- * Converts the //decimal string// %%ether%% to a BigInt, using 18
33074
- * decimal places.
33075
- */
33076
- function parseEther(ether) {
33077
- return parseUnits$1(ether, 18);
33078
- }
33079
-
33080
32508
  /**
33081
32509
  * @_ignore:
33082
32510
  */
@@ -51945,6 +51373,12 @@ var PolygonIdSdk = (function (exports) {
51945
51373
  this.GISTRoot = V$1.fromString(sVals[2]);
51946
51374
  return this;
51947
51375
  }
51376
+ getStatesInfo() {
51377
+ return {
51378
+ states: [],
51379
+ gists: [{ id: this.userID, root: this.GISTRoot }]
51380
+ };
51381
+ }
51948
51382
  }
51949
51383
 
51950
51384
  /**
@@ -54375,54 +53809,60 @@ var PolygonIdSdk = (function (exports) {
54375
53809
  const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
54376
53810
  return new Map().set(txnHash, zkProofResponses);
54377
53811
  }
53812
+ static getCrossChainResolvers(source, txDataChainId, type, didResolverUrl) {
53813
+ return [
53814
+ ...new Set(source.map((info) => JSON.stringify({
53815
+ id: info.id.string(),
53816
+ [type]: type === 'gist' ? info.root?.string() : info.state?.string()
53817
+ })))
53818
+ ].reduce((acc, s) => {
53819
+ const info = JSON.parse(s);
53820
+ const id = $$1.fromString(info.id);
53821
+ const chainId = rt$2(Q$2.parseFromId(id));
53822
+ if (txDataChainId === chainId) {
53823
+ return acc;
53824
+ }
53825
+ const promise = this.resolveDidDocumentEip712MessageAndSignature(Q$2.parseFromId($$1.fromString(info.id)), didResolverUrl, {
53826
+ [type]: V$1.fromString(info[type])
53827
+ });
53828
+ return [...acc, promise];
53829
+ }, []);
53830
+ }
54378
53831
  static async prepareTxArgsSubmitV2(resolverUrl, txData, zkProofResponses) {
54379
53832
  if (txData.method_id.replace('0x', '') !== exports.FunctionSignatures.SubmitZKPResponseV2) {
54380
53833
  throw new Error(`submit cross chain doesn't implement requested method id. Only '0x${exports.FunctionSignatures.SubmitZKPResponseV2}' is supported.`);
54381
53834
  }
54382
- const gistUpdateArr = [];
54383
- const stateUpdateArr = [];
53835
+ const gistUpdates = [];
53836
+ const stateUpdates = [];
54384
53837
  const payload = [];
54385
- // Resolved gists and states to avoid duplicate requests
54386
- const gistUpdateResolutionsPending = [];
54387
- const stateUpdateResolutionsPending = [];
53838
+ const emptyBytes = '0x';
54388
53839
  for (const zkProof of zkProofResponses) {
54389
- const requestID = zkProof.id;
54390
- const inputs = zkProof.pub_signals;
54391
- if (!this._supportedCircuits.includes(zkProof.circuitId)) {
53840
+ const { id: requestId, pub_signals: inputs } = zkProof;
53841
+ const proofCircuitId = zkProof.circuitId;
53842
+ if (!this._supportedCircuits.includes(proofCircuitId)) {
54392
53843
  throw new Error(`Circuit ${zkProof.circuitId} not supported by OnChainZKPVerifier`);
54393
53844
  }
53845
+ if (inputs.length === 0) {
53846
+ payload.push({
53847
+ requestId: requestId,
53848
+ zkProof: emptyBytes,
53849
+ data: emptyBytes
53850
+ });
53851
+ continue;
53852
+ }
54394
53853
  const zkProofEncoded = this.packZkpProof(inputs, zkProof.proof.pi_a.slice(0, 2), [
54395
53854
  [zkProof.proof.pi_b[0][1], zkProof.proof.pi_b[0][0]],
54396
53855
  [zkProof.proof.pi_b[1][1], zkProof.proof.pi_b[1][0]]
54397
53856
  ], zkProof.proof.pi_c.slice(0, 2));
54398
- const stateInfo = this.getOnChainGistRootStatePubSignals(zkProof.circuitId, zkProof.pub_signals);
54399
- const gistUpdateResolutions = [];
54400
- for (const gist of stateInfo.gists) {
54401
- const gistResolutionPending = gistUpdateResolutionsPending.find((g) => g == JSON.stringify(gist));
54402
- if (gistResolutionPending) {
54403
- continue;
54404
- }
54405
- gistUpdateResolutionsPending.push(JSON.stringify(gist));
54406
- gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(Q$2.parseFromId(gist.id), resolverUrl, {
54407
- gist: gist.root
54408
- }));
54409
- }
54410
- const stateUpdateResolutions = [];
54411
- for (const state of stateInfo.states) {
54412
- const stateResolutionPending = stateUpdateResolutionsPending.find((s) => s == JSON.stringify(state));
54413
- if (stateResolutionPending) {
54414
- continue;
54415
- }
54416
- stateUpdateResolutionsPending.push(JSON.stringify(state));
54417
- stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(Q$2.parseFromId(state.id), resolverUrl, {
54418
- state: state.state
54419
- }));
54420
- }
53857
+ const stateInfo = this.getOnChainGistRootStatePubSignals(proofCircuitId, inputs);
53858
+ const chainId = txData.chain_id;
53859
+ const gistUpdateResolutions = this.getCrossChainResolvers(stateInfo.gists, chainId, 'gist', resolverUrl);
53860
+ const stateUpdateResolutions = this.getCrossChainResolvers(stateInfo.states, chainId, 'state', resolverUrl);
54421
53861
  if (gistUpdateResolutions.length > 0) {
54422
- gistUpdateArr.push(...(await Promise.all(gistUpdateResolutions)));
53862
+ gistUpdates.push(...(await Promise.all(gistUpdateResolutions)));
54423
53863
  }
54424
53864
  if (stateUpdateResolutions.length > 0) {
54425
- stateUpdateArr.push(...(await Promise.all(stateUpdateResolutions)));
53865
+ stateUpdates.push(...(await Promise.all(stateUpdateResolutions)));
54426
53866
  }
54427
53867
  const metadataArr = [];
54428
53868
  if (zkProof.vp) {
@@ -54438,14 +53878,16 @@ var PolygonIdSdk = (function (exports) {
54438
53878
  });
54439
53879
  }
54440
53880
  }
54441
- const metadata = metadataArr.length ? this.packMetadatas(metadataArr) : '0x';
53881
+ const metadata = metadataArr.length ? this.packMetadatas(metadataArr) : emptyBytes;
54442
53882
  payload.push({
54443
- requestId: requestID,
53883
+ requestId: requestId,
54444
53884
  zkProof: zkProofEncoded,
54445
53885
  data: metadata
54446
53886
  });
54447
53887
  }
54448
- const crossChainProofs = this.packCrossChainProofs(gistUpdateArr, stateUpdateArr);
53888
+ const crossChainProofs = gistUpdates.length || stateUpdates.length
53889
+ ? this.packCrossChainProofs(gistUpdates, stateUpdates)
53890
+ : emptyBytes;
54449
53891
  return [payload, crossChainProofs];
54450
53892
  }
54451
53893
  async prepareTxArgsSubmitV2(txData, zkProofResponses) {
@@ -54503,18 +53945,11 @@ var PolygonIdSdk = (function (exports) {
54503
53945
  return new AbiCoder().encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
54504
53946
  }
54505
53947
  static getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
54506
- let atomicQueryPubSignals;
54507
- switch (onChainCircuitId) {
54508
- case exports.CircuitId.AtomicQueryMTPV2OnChain:
54509
- atomicQueryPubSignals = new AtomicQueryMTPV2OnChainPubSignals();
54510
- break;
54511
- case exports.CircuitId.AtomicQuerySigV2OnChain:
54512
- atomicQueryPubSignals = new AtomicQuerySigV2OnChainPubSignals();
54513
- break;
54514
- case exports.CircuitId.AtomicQueryV3OnChain:
54515
- atomicQueryPubSignals = new AtomicQueryV3OnChainPubSignals();
54516
- break;
53948
+ const PubSignals = this._supportedCircuitsPubSignalsMap[onChainCircuitId];
53949
+ if (!PubSignals) {
53950
+ throw new Error(`Circuit ${onChainCircuitId} not supported by OnChainZKPVerifier`);
54517
53951
  }
53952
+ const atomicQueryPubSignals = new PubSignals();
54518
53953
  const encodedInputs = byteEncoder.encode(JSON.stringify(inputs));
54519
53954
  atomicQueryPubSignals.pubSignalsUnmarshal(encodedInputs);
54520
53955
  return atomicQueryPubSignals.getStatesInfo();
@@ -54556,10 +53991,17 @@ var PolygonIdSdk = (function (exports) {
54556
53991
  * supported circuits
54557
53992
  */
54558
53993
  OnChainZKPVerifier._supportedCircuits = [
53994
+ exports.CircuitId.AuthV2,
54559
53995
  exports.CircuitId.AtomicQueryMTPV2OnChain,
54560
53996
  exports.CircuitId.AtomicQuerySigV2OnChain,
54561
53997
  exports.CircuitId.AtomicQueryV3OnChain
54562
53998
  ];
53999
+ OnChainZKPVerifier._supportedCircuitsPubSignalsMap = {
54000
+ [exports.CircuitId.AtomicQueryMTPV2OnChain]: AtomicQueryMTPV2OnChainPubSignals,
54001
+ [exports.CircuitId.AtomicQuerySigV2OnChain]: AtomicQuerySigV2OnChainPubSignals,
54002
+ [exports.CircuitId.AtomicQueryV3OnChain]: AtomicQueryV3OnChainPubSignals,
54003
+ [exports.CircuitId.AuthV2]: AuthV2PubSignals
54004
+ };
54563
54005
 
54564
54006
  var abi$1 = [
54565
54007
  {
@@ -82313,6 +81755,7 @@ var PolygonIdSdk = (function (exports) {
82313
81755
  this._proofService = _proofService;
82314
81756
  this._zkpVerifier = _zkpVerifier;
82315
81757
  this._supportedCircuits = [
81758
+ exports.CircuitId.AuthV2,
82316
81759
  exports.CircuitId.AtomicQueryMTPV2OnChain,
82317
81760
  exports.CircuitId.AtomicQuerySigV2OnChain,
82318
81761
  exports.CircuitId.AtomicQueryV3OnChain
@@ -82343,7 +81786,12 @@ var PolygonIdSdk = (function (exports) {
82343
81786
  throw new Error(`Invalid chain id ${chain_id}`);
82344
81787
  }
82345
81788
  const verifierDid = message.from ? Q$2.parse(message.from) : undefined;
82346
- const zkpResponses = await processZeroKnowledgeProofRequests(did, message?.body?.scope, verifierDid, this._proofService, { ethSigner, challenge, supportedCircuits: this._supportedCircuits });
81789
+ const { scope = [] } = message.body;
81790
+ const zkpResponses = await processZeroKnowledgeProofRequests(did, scope, verifierDid, this._proofService, {
81791
+ ethSigner,
81792
+ challenge,
81793
+ supportedCircuits: this._supportedCircuits
81794
+ });
82347
81795
  const methodId = message.body.transaction_data.method_id.replace('0x', '');
82348
81796
  switch (methodId) {
82349
81797
  case exports.FunctionSignatures.SubmitZKPResponseV2:
@@ -82864,11 +82312,10 @@ var PolygonIdSdk = (function (exports) {
82864
82312
  return request;
82865
82313
  }
82866
82314
  async function verifyEIP712TypedData(data, resolver) {
82867
- const convertedAmount = await convertPaymentAmount(data.amount, data.currency);
82868
82315
  const paymentData = data.type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
82869
82316
  ? {
82870
82317
  recipient: data.recipient,
82871
- amount: convertedAmount,
82318
+ amount: data.amount,
82872
82319
  expirationDate: b$4(new Date(data.expirationDate)),
82873
82320
  nonce: data.nonce,
82874
82321
  metadata: '0x'
@@ -82876,7 +82323,7 @@ var PolygonIdSdk = (function (exports) {
82876
82323
  : {
82877
82324
  tokenAddress: data.tokenAddress,
82878
82325
  recipient: data.recipient,
82879
- amount: convertedAmount,
82326
+ amount: data.amount,
82880
82327
  expirationDate: b$4(new Date(data.expirationDate)),
82881
82328
  nonce: data.nonce,
82882
82329
  metadata: '0x'
@@ -82900,30 +82347,6 @@ var PolygonIdSdk = (function (exports) {
82900
82347
  }
82901
82348
  throw new Error(`failed request. no matching verificationMethod`);
82902
82349
  }
82903
- async function convertPaymentAmount(amount, currency) {
82904
- let convertedAmount = 0n;
82905
- switch (currency) {
82906
- case exports.SupportedCurrencies.ETH:
82907
- case exports.SupportedCurrencies.POL:
82908
- case exports.SupportedCurrencies.MATIC:
82909
- convertedAmount = parseEther(amount.toString());
82910
- break;
82911
- case exports.SupportedCurrencies.ETH_WEI:
82912
- convertedAmount = parseUnits$1(amount.toString(), 'wei');
82913
- break;
82914
- case exports.SupportedCurrencies.ETH_GWEI:
82915
- convertedAmount = parseUnits$1(amount.toString(), 'gwei');
82916
- break;
82917
- case exports.SupportedCurrencies.USDC:
82918
- case exports.SupportedCurrencies.USDT: {
82919
- convertedAmount = parseUnits$1(amount.toString(), 6);
82920
- break;
82921
- }
82922
- default:
82923
- throw new Error(`failed request. unsupported currency ${currency}`);
82924
- }
82925
- return convertedAmount;
82926
- }
82927
82350
  /**
82928
82351
  * @beta
82929
82352
  * createPayment is a function to create protocol payment message
@@ -83110,35 +82533,38 @@ var PolygonIdSdk = (function (exports) {
83110
82533
  for (let i = 0; i < payments.length; i++) {
83111
82534
  const { credentials, description } = payments[i];
83112
82535
  const dataArr = [];
83113
- for (let j = 0; j < payments[i].chains.length; j++) {
83114
- const { features, nonce, amount, currency, chainId, expirationDate, type } = payments[i].chains[j];
82536
+ for (let j = 0; j < payments[i].options.length; j++) {
82537
+ const { nonce, amount, chainId, optionId, expirationDate } = payments[i].options[j];
83115
82538
  const multiChainConfig = this._params.multiChainPaymentConfig?.find((c) => c.chainId === chainId);
83116
82539
  if (!multiChainConfig) {
83117
82540
  throw new Error(`failed request. no config for chain ${chainId}`);
83118
82541
  }
83119
- const { recipient, paymentContract, erc20TokenAddressArr } = multiChainConfig;
83120
- const tokenAddress = erc20TokenAddressArr.find((t) => t.symbol === currency)?.address;
83121
- if (type === exports.PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1 && !tokenAddress) {
83122
- throw new Error(`failed request. no token address for currency ${currency}`);
82542
+ const { recipient, paymentRails, options } = multiChainConfig;
82543
+ const option = options.find((t) => t.id === optionId);
82544
+ if (!option) {
82545
+ throw new Error(`failed request. no option for id ${optionId}`);
82546
+ }
82547
+ if (option.type === exports.PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1 &&
82548
+ !option.contractAddress) {
82549
+ throw new Error(`failed request. no token address for option id ${optionId}`);
83123
82550
  }
83124
82551
  const expirationDateRequired = expirationDate ?? new Date(new Date().setHours(new Date().getHours() + 1));
83125
- const typeUrl = `https://schema.iden3.io/core/json/${type}.json`;
82552
+ const typeUrl = `https://schema.iden3.io/core/json/${option.type}.json`;
83126
82553
  const typesFetchResult = await fetch(typeUrl);
83127
82554
  const types = await typesFetchResult.json();
83128
82555
  delete types.EIP712Domain;
83129
- const convertedAmount = await convertPaymentAmount(amount, currency);
83130
- const paymentData = type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
82556
+ const paymentData = option.type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
83131
82557
  ? {
83132
82558
  recipient,
83133
- amount: convertedAmount,
82559
+ amount: amount,
83134
82560
  expirationDate: b$4(expirationDateRequired),
83135
82561
  nonce,
83136
82562
  metadata: '0x'
83137
82563
  }
83138
82564
  : {
83139
- tokenAddress,
82565
+ tokenAddress: option.contractAddress,
83140
82566
  recipient,
83141
- amount: convertedAmount,
82567
+ amount: amount,
83142
82568
  expirationDate: b$4(expirationDateRequired),
83143
82569
  nonce,
83144
82570
  metadata: '0x'
@@ -83147,7 +82573,7 @@ var PolygonIdSdk = (function (exports) {
83147
82573
  name: 'MCPayment',
83148
82574
  version: '1.0.0',
83149
82575
  chainId,
83150
- verifyingContract: paymentContract
82576
+ verifyingContract: paymentRails
83151
82577
  };
83152
82578
  const signature = await signer.signTypedData(domain, types, paymentData);
83153
82579
  const proof = [
@@ -83167,20 +82593,24 @@ var PolygonIdSdk = (function (exports) {
83167
82593
  const d = {
83168
82594
  type: exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1,
83169
82595
  '@context': [
83170
- `https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`,
82596
+ `https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
83171
82597
  'https://w3id.org/security/suites/eip712sig-2021/v1'
83172
82598
  ],
83173
82599
  recipient,
83174
82600
  amount: amount.toString(),
83175
- currency,
83176
82601
  expirationDate: expirationDateRequired.toISOString(),
83177
82602
  nonce: nonce.toString(),
83178
82603
  metadata: '0x',
83179
82604
  proof
83180
82605
  };
83181
- dataArr.push(type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
82606
+ dataArr.push(option.type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
83182
82607
  ? d
83183
- : { ...d, type, tokenAddress: tokenAddress || '', features: features || [] });
82608
+ : {
82609
+ ...d,
82610
+ type: option.type,
82611
+ tokenAddress: option.contractAddress || '',
82612
+ features: option.features || []
82613
+ });
83184
82614
  }
83185
82615
  paymentRequestInfo.push({
83186
82616
  data: dataArr,
@@ -84535,6 +83965,12 @@ var PolygonIdSdk = (function (exports) {
84535
83965
  authInputs.gistProof = gistProof;
84536
83966
  return authInputs.inputsMarshal();
84537
83967
  }
83968
+ /** {@inheritdoc IProofService.generateAuthV2Proof} */
83969
+ async generateAuthV2Proof(challenge, did) {
83970
+ const authInputs = await this.generateAuthV2Inputs(challenge, did, exports.CircuitId.AuthV2);
83971
+ const zkProof = await this._prover.generate(authInputs, exports.CircuitId.AuthV2);
83972
+ return zkProof;
83973
+ }
84538
83974
  async verifyState(circuitId, pubSignals, opts = {
84539
83975
  acceptedStateTransitionDelay: DEFAULT_AUTH_VERIFY_DELAY
84540
83976
  }) {
@@ -85430,7 +84866,6 @@ var PolygonIdSdk = (function (exports) {
85430
84866
  exports.checkQueryRequest = checkQueryRequest;
85431
84867
  exports.circuitValidator = circuitValidator;
85432
84868
  exports.comparatorOptions = comparatorOptions;
85433
- exports.convertPaymentAmount = convertPaymentAmount;
85434
84869
  exports.core = index$1;
85435
84870
  exports.createAuthorizationRequest = createAuthorizationRequest;
85436
84871
  exports.createAuthorizationRequestWithMessage = createAuthorizationRequestWithMessage;