@0xpolygonid/js-sdk 1.24.1 → 1.26.0
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.
- package/dist/browser/esm/index.js +376 -748
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +377 -747
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/auth-v2.js +6 -0
- package/dist/node/cjs/iden3comm/constants.js +6 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +16 -24
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +7 -1
- package/dist/node/cjs/iden3comm/handlers/discovery-protocol.js +198 -0
- package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
- package/dist/node/cjs/iden3comm/handlers/payment.js +27 -46
- package/dist/node/cjs/iden3comm/packageManager.js +12 -0
- package/dist/node/cjs/iden3comm/packers/jws.js +8 -7
- package/dist/node/cjs/iden3comm/packers/plain.js +8 -2
- package/dist/node/cjs/iden3comm/packers/zkp.js +10 -12
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/discovery-protocol.js +16 -0
- package/dist/node/cjs/iden3comm/utils/contract-request.utils.js +59 -0
- package/dist/node/cjs/iden3comm/utils/index.js +1 -0
- package/dist/node/cjs/proof/proof-service.js +6 -0
- package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +56 -47
- package/dist/node/cjs/utils/did-helper.js +8 -3
- package/dist/node/cjs/verifiable/constants.js +1 -2
- package/dist/node/esm/circuits/auth-v2.js +6 -0
- package/dist/node/esm/iden3comm/constants.js +6 -1
- package/dist/node/esm/iden3comm/handlers/auth.js +17 -25
- package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -1
- package/dist/node/esm/iden3comm/handlers/discovery-protocol.js +169 -0
- package/dist/node/esm/iden3comm/handlers/index.js +1 -0
- package/dist/node/esm/iden3comm/handlers/payment.js +28 -46
- package/dist/node/esm/iden3comm/packageManager.js +12 -0
- package/dist/node/esm/iden3comm/packers/jws.js +9 -8
- package/dist/node/esm/iden3comm/packers/plain.js +9 -3
- package/dist/node/esm/iden3comm/packers/zkp.js +11 -13
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/discovery-protocol.js +13 -0
- package/dist/node/esm/iden3comm/utils/contract-request.utils.js +54 -0
- package/dist/node/esm/iden3comm/utils/index.js +1 -0
- package/dist/node/esm/proof/proof-service.js +6 -0
- package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +58 -49
- package/dist/node/esm/utils/did-helper.js +8 -3
- package/dist/node/esm/verifiable/constants.js +1 -2
- package/dist/types/circuits/auth-v2.d.ts +3 -2
- package/dist/types/iden3comm/constants.d.ts +2 -0
- package/dist/types/iden3comm/handlers/discovery-protocol.d.ts +100 -0
- package/dist/types/iden3comm/handlers/index.d.ts +1 -0
- package/dist/types/iden3comm/handlers/payment.d.ts +5 -9
- package/dist/types/iden3comm/packageManager.d.ts +2 -0
- package/dist/types/iden3comm/packers/jws.d.ts +2 -1
- package/dist/types/iden3comm/packers/plain.d.ts +1 -0
- package/dist/types/iden3comm/packers/zkp.d.ts +3 -2
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/packageManager.d.ts +6 -0
- package/dist/types/iden3comm/types/protocol/discovery-protocol.d.ts +41 -0
- package/dist/types/iden3comm/types/protocol/payment.d.ts +6 -5
- package/dist/types/iden3comm/utils/contract-request.utils.d.ts +20 -0
- package/dist/types/iden3comm/utils/index.d.ts +1 -0
- package/dist/types/proof/proof-service.d.ts +10 -0
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +2 -0
- package/dist/types/verifiable/constants.d.ts +2 -3
- 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
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
|
22508
|
+
var names = {};
|
|
22505
22509
|
|
|
22506
22510
|
var hasRequiredNames;
|
|
22507
22511
|
|
|
22508
22512
|
function requireNames () {
|
|
22509
|
-
if (hasRequiredNames) return names
|
|
22513
|
+
if (hasRequiredNames) return names;
|
|
22510
22514
|
hasRequiredNames = 1;
|
|
22511
|
-
Object.defineProperty(names
|
|
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
|
|
22540
|
+
names.default = names$1;
|
|
22537
22541
|
|
|
22538
|
-
return names
|
|
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$
|
|
30973
|
-
const BN_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$
|
|
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$
|
|
30991
|
-
const mask = (BN_1$
|
|
30992
|
-
return -(((~value) & mask) + BN_1$
|
|
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$
|
|
31006
|
-
if (value < BN_0$
|
|
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$
|
|
31012
|
-
return ((~value) & mask) + BN_1$
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
|
54383
|
-
const
|
|
53835
|
+
const gistUpdates = [];
|
|
53836
|
+
const stateUpdates = [];
|
|
54384
53837
|
const payload = [];
|
|
54385
|
-
|
|
54386
|
-
const gistUpdateResolutionsPending = [];
|
|
54387
|
-
const stateUpdateResolutionsPending = [];
|
|
53838
|
+
const emptyBytes = '0x';
|
|
54388
53839
|
for (const zkProof of zkProofResponses) {
|
|
54389
|
-
const
|
|
54390
|
-
const
|
|
54391
|
-
if (!this._supportedCircuits.includes(
|
|
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(
|
|
54399
|
-
const
|
|
54400
|
-
|
|
54401
|
-
|
|
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
|
-
|
|
53862
|
+
gistUpdates.push(...(await Promise.all(gistUpdateResolutions)));
|
|
54423
53863
|
}
|
|
54424
53864
|
if (stateUpdateResolutions.length > 0) {
|
|
54425
|
-
|
|
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) :
|
|
53881
|
+
const metadata = metadataArr.length ? this.packMetadatas(metadataArr) : emptyBytes;
|
|
54442
53882
|
payload.push({
|
|
54443
|
-
requestId:
|
|
53883
|
+
requestId: requestId,
|
|
54444
53884
|
zkProof: zkProofEncoded,
|
|
54445
53885
|
data: metadata
|
|
54446
53886
|
});
|
|
54447
53887
|
}
|
|
54448
|
-
const crossChainProofs =
|
|
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
|
-
|
|
54507
|
-
|
|
54508
|
-
|
|
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
|
{
|
|
@@ -58983,6 +58425,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
58983
58425
|
}
|
|
58984
58426
|
|
|
58985
58427
|
const IDEN3_PROTOCOL = 'https://iden3-communication.io/';
|
|
58428
|
+
const DIDCOMM_PROTOCOL = 'https://didcomm.org/';
|
|
58986
58429
|
/**
|
|
58987
58430
|
* Constants for Iden3 protocol
|
|
58988
58431
|
*/
|
|
@@ -59026,7 +58469,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
59026
58469
|
// PaymentRequestMessageType is type for payment-request message
|
|
59027
58470
|
PAYMENT_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment-request`,
|
|
59028
58471
|
// PaymentMessageType is type for payment message
|
|
59029
|
-
PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment
|
|
58472
|
+
PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`,
|
|
58473
|
+
// DiscoveryProtocolQueriesMessageType is type for didcomm discovery protocol queries
|
|
58474
|
+
DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/queries`,
|
|
58475
|
+
// DiscoveryProtocolDiscloseMessageType is type for didcomm discovery protocol disclose
|
|
58476
|
+
DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/disclose`
|
|
59030
58477
|
});
|
|
59031
58478
|
/**
|
|
59032
58479
|
* Media types for iden3 comm communication protocol
|
|
@@ -80913,6 +80360,18 @@ var PolygonIdSdk = (function (exports) {
|
|
|
80913
80360
|
constructor() {
|
|
80914
80361
|
this.packers = new Map();
|
|
80915
80362
|
}
|
|
80363
|
+
/** {@inheritDoc IPackageManager.getSupportedProfiles} */
|
|
80364
|
+
getSupportedProfiles() {
|
|
80365
|
+
const acceptProfiles = [];
|
|
80366
|
+
const mediaTypes = this.getSupportedMediaTypes();
|
|
80367
|
+
for (const mediaType of mediaTypes) {
|
|
80368
|
+
const p = this.packers.get(mediaType);
|
|
80369
|
+
if (p) {
|
|
80370
|
+
acceptProfiles.push(...p.getSupportedProfiles());
|
|
80371
|
+
}
|
|
80372
|
+
}
|
|
80373
|
+
return [...new Set(acceptProfiles)];
|
|
80374
|
+
}
|
|
80916
80375
|
/** {@inheritDoc IPackageManager.isProfileSupported} */
|
|
80917
80376
|
isProfileSupported(mediaType, profile) {
|
|
80918
80377
|
const p = this.packers.get(mediaType);
|
|
@@ -81226,6 +80685,9 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81226
80685
|
this.provingParamsMap = provingParamsMap;
|
|
81227
80686
|
this.verificationParamsMap = verificationParamsMap;
|
|
81228
80687
|
this._opts = _opts;
|
|
80688
|
+
this.supportedProtocolVersions = [ProtocolVersion.V1];
|
|
80689
|
+
this.supportedAlgorithms = [AcceptJwzAlgorithms.Groth16];
|
|
80690
|
+
this.supportedCircuitIds = [AcceptAuthCircuits.AuthV2];
|
|
81229
80691
|
}
|
|
81230
80692
|
/**
|
|
81231
80693
|
* Packs a basic message using the specified parameters.
|
|
@@ -81287,28 +80749,23 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81287
80749
|
}
|
|
81288
80750
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
81289
80751
|
getSupportedProfiles() {
|
|
81290
|
-
return
|
|
81291
|
-
`env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}&circuitIds=${this.getSupportedCircuitIds().join(',')}`
|
|
81292
|
-
];
|
|
80752
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')};circuitIds=${this.supportedCircuitIds.join(',')}`);
|
|
81293
80753
|
}
|
|
81294
80754
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
81295
80755
|
isProfileSupported(profile) {
|
|
81296
|
-
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
80756
|
+
const { protocolVersion, env, circuits, alg } = parseAcceptProfile(profile);
|
|
80757
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
80758
|
+
return false;
|
|
80759
|
+
}
|
|
81297
80760
|
if (env !== this.mediaType()) {
|
|
81298
80761
|
return false;
|
|
81299
80762
|
}
|
|
81300
|
-
const supportedCircuitIds = this.
|
|
80763
|
+
const supportedCircuitIds = this.supportedCircuitIds;
|
|
81301
80764
|
const circuitIdSupported = !circuits?.length || circuits.some((c) => supportedCircuitIds.includes(c));
|
|
81302
|
-
const supportedAlgArr = this.
|
|
80765
|
+
const supportedAlgArr = this.supportedAlgorithms;
|
|
81303
80766
|
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
81304
80767
|
return algSupported && circuitIdSupported;
|
|
81305
80768
|
}
|
|
81306
|
-
getSupportedAlgorithms() {
|
|
81307
|
-
return [AcceptJwzAlgorithms.Groth16];
|
|
81308
|
-
}
|
|
81309
|
-
getSupportedCircuitIds() {
|
|
81310
|
-
return [AcceptAuthCircuits.AuthV2];
|
|
81311
|
-
}
|
|
81312
80769
|
}
|
|
81313
80770
|
const verifySender = async (token, msg) => {
|
|
81314
80771
|
switch (token.circuitId) {
|
|
@@ -81342,6 +80799,9 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81342
80799
|
* @implements implements IPacker interface
|
|
81343
80800
|
*/
|
|
81344
80801
|
class PlainPacker {
|
|
80802
|
+
constructor() {
|
|
80803
|
+
this.supportedProtocolVersions = [ProtocolVersion.V1];
|
|
80804
|
+
}
|
|
81345
80805
|
/**
|
|
81346
80806
|
* Packs a basic message using the specified parameters.
|
|
81347
80807
|
*
|
|
@@ -81385,11 +80845,14 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81385
80845
|
}
|
|
81386
80846
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
81387
80847
|
getSupportedProfiles() {
|
|
81388
|
-
return
|
|
80848
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()}`);
|
|
81389
80849
|
}
|
|
81390
80850
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
81391
80851
|
isProfileSupported(profile) {
|
|
81392
|
-
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
80852
|
+
const { protocolVersion, env, circuits, alg } = parseAcceptProfile(profile);
|
|
80853
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
80854
|
+
return false;
|
|
80855
|
+
}
|
|
81393
80856
|
if (env !== this.mediaType()) {
|
|
81394
80857
|
return false;
|
|
81395
80858
|
}
|
|
@@ -81421,6 +80884,8 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81421
80884
|
constructor(_kms, _documentResolver) {
|
|
81422
80885
|
this._kms = _kms;
|
|
81423
80886
|
this._documentResolver = _documentResolver;
|
|
80887
|
+
this.supportedAlgorithms = [AcceptJwsAlgorithms.ES256K, AcceptJwsAlgorithms.ES256KR];
|
|
80888
|
+
this.supportedProtocolVersions = [ProtocolVersion.V1];
|
|
81424
80889
|
}
|
|
81425
80890
|
/**
|
|
81426
80891
|
* Packs the given payload and returns a promise that resolves to the packed data.
|
|
@@ -81483,24 +80948,23 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81483
80948
|
}
|
|
81484
80949
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
81485
80950
|
getSupportedProfiles() {
|
|
81486
|
-
return
|
|
80951
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')}`);
|
|
81487
80952
|
}
|
|
81488
80953
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
81489
80954
|
isProfileSupported(profile) {
|
|
81490
|
-
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
80955
|
+
const { protocolVersion, env, circuits, alg } = parseAcceptProfile(profile);
|
|
80956
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
80957
|
+
return false;
|
|
80958
|
+
}
|
|
81491
80959
|
if (env !== this.mediaType()) {
|
|
81492
80960
|
return false;
|
|
81493
80961
|
}
|
|
81494
80962
|
if (circuits) {
|
|
81495
80963
|
throw new Error(`Circuits are not supported for ${env} media type`);
|
|
81496
80964
|
}
|
|
81497
|
-
const
|
|
81498
|
-
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
80965
|
+
const algSupported = !alg?.length || alg.some((a) => this.supportedAlgorithms.includes(a));
|
|
81499
80966
|
return algSupported;
|
|
81500
80967
|
}
|
|
81501
|
-
getSupportedAlgorithms() {
|
|
81502
|
-
return [AcceptJwsAlgorithms.ES256K, AcceptJwsAlgorithms.ES256KR];
|
|
81503
|
-
}
|
|
81504
80968
|
async resolveDidDoc(from) {
|
|
81505
80969
|
let didDocument;
|
|
81506
80970
|
try {
|
|
@@ -81576,6 +81040,20 @@ var PolygonIdSdk = (function (exports) {
|
|
|
81576
81040
|
CredentialOfferStatus["Rejected"] = "rejected";
|
|
81577
81041
|
})(exports.CredentialOfferStatus || (exports.CredentialOfferStatus = {}));
|
|
81578
81042
|
|
|
81043
|
+
/** @beta DiscoverFeatureQueryType is enum for query type fields */
|
|
81044
|
+
exports.DiscoverFeatureQueryType = void 0;
|
|
81045
|
+
(function (DiscoverFeatureQueryType) {
|
|
81046
|
+
DiscoverFeatureQueryType["FeatureType"] = "feature-type";
|
|
81047
|
+
})(exports.DiscoverFeatureQueryType || (exports.DiscoverFeatureQueryType = {}));
|
|
81048
|
+
/** @beta DiscoveryProtocolFeatureType is enum for supported feature-types */
|
|
81049
|
+
exports.DiscoveryProtocolFeatureType = void 0;
|
|
81050
|
+
(function (DiscoveryProtocolFeatureType) {
|
|
81051
|
+
DiscoveryProtocolFeatureType["Accept"] = "accept";
|
|
81052
|
+
DiscoveryProtocolFeatureType["Protocol"] = "protocol";
|
|
81053
|
+
DiscoveryProtocolFeatureType["GoalCode"] = "goal-code";
|
|
81054
|
+
DiscoveryProtocolFeatureType["Header"] = "header";
|
|
81055
|
+
})(exports.DiscoveryProtocolFeatureType || (exports.DiscoveryProtocolFeatureType = {}));
|
|
81056
|
+
|
|
81579
81057
|
/**
|
|
81580
81058
|
* Groups the ZeroKnowledgeProofRequest objects based on their groupId.
|
|
81581
81059
|
* Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
|
|
@@ -82021,32 +81499,24 @@ var PolygonIdSdk = (function (exports) {
|
|
|
82021
81499
|
}
|
|
82022
81500
|
getSupportedMediaTypeByProfile(ctx, responseType, profile) {
|
|
82023
81501
|
let mediaType;
|
|
82024
|
-
if (profile?.length) {
|
|
82025
|
-
|
|
82026
|
-
|
|
82027
|
-
|
|
82028
|
-
|
|
82029
|
-
|
|
82030
|
-
|
|
82031
|
-
|
|
82032
|
-
(responseTypeVersion < 1 || responseTypeVersion >= 2))) {
|
|
82033
|
-
continue;
|
|
82034
|
-
}
|
|
82035
|
-
// 2. check packer support
|
|
82036
|
-
if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
|
|
82037
|
-
supportedMediaTypes.push(env);
|
|
82038
|
-
}
|
|
82039
|
-
}
|
|
82040
|
-
if (!supportedMediaTypes.length) {
|
|
82041
|
-
throw new Error('no packer with profile which meets `accept` header requirements');
|
|
82042
|
-
}
|
|
82043
|
-
mediaType = supportedMediaTypes[0];
|
|
82044
|
-
if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
|
|
82045
|
-
mediaType = ctx.mediaType;
|
|
81502
|
+
if (!profile?.length) {
|
|
81503
|
+
return ctx.mediaType || MediaType.ZKPMessage;
|
|
81504
|
+
}
|
|
81505
|
+
const supportedMediaTypes = [];
|
|
81506
|
+
for (const acceptProfile of profile) {
|
|
81507
|
+
const { env } = parseAcceptProfile(acceptProfile);
|
|
81508
|
+
if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
|
|
81509
|
+
supportedMediaTypes.push(env);
|
|
82046
81510
|
}
|
|
82047
81511
|
}
|
|
82048
|
-
|
|
82049
|
-
|
|
81512
|
+
if (!supportedMediaTypes.length) {
|
|
81513
|
+
throw new Error('no packer with profile which meets `accept` header requirements');
|
|
81514
|
+
}
|
|
81515
|
+
mediaType = supportedMediaTypes.includes(MediaType.ZKPMessage)
|
|
81516
|
+
? MediaType.ZKPMessage
|
|
81517
|
+
: supportedMediaTypes[0];
|
|
81518
|
+
if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
|
|
81519
|
+
mediaType = ctx.mediaType;
|
|
82050
81520
|
}
|
|
82051
81521
|
return mediaType;
|
|
82052
81522
|
}
|
|
@@ -82313,6 +81783,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
82313
81783
|
this._proofService = _proofService;
|
|
82314
81784
|
this._zkpVerifier = _zkpVerifier;
|
|
82315
81785
|
this._supportedCircuits = [
|
|
81786
|
+
exports.CircuitId.AuthV2,
|
|
82316
81787
|
exports.CircuitId.AtomicQueryMTPV2OnChain,
|
|
82317
81788
|
exports.CircuitId.AtomicQuerySigV2OnChain,
|
|
82318
81789
|
exports.CircuitId.AtomicQueryV3OnChain
|
|
@@ -82343,7 +81814,12 @@ var PolygonIdSdk = (function (exports) {
|
|
|
82343
81814
|
throw new Error(`Invalid chain id ${chain_id}`);
|
|
82344
81815
|
}
|
|
82345
81816
|
const verifierDid = message.from ? Q$2.parse(message.from) : undefined;
|
|
82346
|
-
const
|
|
81817
|
+
const { scope = [] } = message.body;
|
|
81818
|
+
const zkpResponses = await processZeroKnowledgeProofRequests(did, scope, verifierDid, this._proofService, {
|
|
81819
|
+
ethSigner,
|
|
81820
|
+
challenge,
|
|
81821
|
+
supportedCircuits: this._supportedCircuits
|
|
81822
|
+
});
|
|
82347
81823
|
const methodId = message.body.transaction_data.method_id.replace('0x', '');
|
|
82348
81824
|
switch (methodId) {
|
|
82349
81825
|
case exports.FunctionSignatures.SubmitZKPResponseV2:
|
|
@@ -82864,11 +82340,10 @@ var PolygonIdSdk = (function (exports) {
|
|
|
82864
82340
|
return request;
|
|
82865
82341
|
}
|
|
82866
82342
|
async function verifyEIP712TypedData(data, resolver) {
|
|
82867
|
-
const convertedAmount = await convertPaymentAmount(data.amount, data.currency);
|
|
82868
82343
|
const paymentData = data.type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
82869
82344
|
? {
|
|
82870
82345
|
recipient: data.recipient,
|
|
82871
|
-
amount:
|
|
82346
|
+
amount: data.amount,
|
|
82872
82347
|
expirationDate: b$4(new Date(data.expirationDate)),
|
|
82873
82348
|
nonce: data.nonce,
|
|
82874
82349
|
metadata: '0x'
|
|
@@ -82876,7 +82351,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
82876
82351
|
: {
|
|
82877
82352
|
tokenAddress: data.tokenAddress,
|
|
82878
82353
|
recipient: data.recipient,
|
|
82879
|
-
amount:
|
|
82354
|
+
amount: data.amount,
|
|
82880
82355
|
expirationDate: b$4(new Date(data.expirationDate)),
|
|
82881
82356
|
nonce: data.nonce,
|
|
82882
82357
|
metadata: '0x'
|
|
@@ -82900,30 +82375,6 @@ var PolygonIdSdk = (function (exports) {
|
|
|
82900
82375
|
}
|
|
82901
82376
|
throw new Error(`failed request. no matching verificationMethod`);
|
|
82902
82377
|
}
|
|
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
82378
|
/**
|
|
82928
82379
|
* @beta
|
|
82929
82380
|
* createPayment is a function to create protocol payment message
|
|
@@ -83110,35 +82561,38 @@ var PolygonIdSdk = (function (exports) {
|
|
|
83110
82561
|
for (let i = 0; i < payments.length; i++) {
|
|
83111
82562
|
const { credentials, description } = payments[i];
|
|
83112
82563
|
const dataArr = [];
|
|
83113
|
-
for (let j = 0; j < payments[i].
|
|
83114
|
-
const {
|
|
82564
|
+
for (let j = 0; j < payments[i].options.length; j++) {
|
|
82565
|
+
const { nonce, amount, chainId, optionId, expirationDate } = payments[i].options[j];
|
|
83115
82566
|
const multiChainConfig = this._params.multiChainPaymentConfig?.find((c) => c.chainId === chainId);
|
|
83116
82567
|
if (!multiChainConfig) {
|
|
83117
82568
|
throw new Error(`failed request. no config for chain ${chainId}`);
|
|
83118
82569
|
}
|
|
83119
|
-
const { recipient,
|
|
83120
|
-
const
|
|
83121
|
-
if (
|
|
83122
|
-
throw new Error(`failed request. no
|
|
82570
|
+
const { recipient, paymentRails, options } = multiChainConfig;
|
|
82571
|
+
const option = options.find((t) => t.id === optionId);
|
|
82572
|
+
if (!option) {
|
|
82573
|
+
throw new Error(`failed request. no option for id ${optionId}`);
|
|
82574
|
+
}
|
|
82575
|
+
if (option.type === exports.PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1 &&
|
|
82576
|
+
!option.contractAddress) {
|
|
82577
|
+
throw new Error(`failed request. no token address for option id ${optionId}`);
|
|
83123
82578
|
}
|
|
83124
82579
|
const expirationDateRequired = expirationDate ?? new Date(new Date().setHours(new Date().getHours() + 1));
|
|
83125
|
-
const typeUrl = `https://schema.iden3.io/core/json/${type}.json`;
|
|
82580
|
+
const typeUrl = `https://schema.iden3.io/core/json/${option.type}.json`;
|
|
83126
82581
|
const typesFetchResult = await fetch(typeUrl);
|
|
83127
82582
|
const types = await typesFetchResult.json();
|
|
83128
82583
|
delete types.EIP712Domain;
|
|
83129
|
-
const
|
|
83130
|
-
const paymentData = type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
82584
|
+
const paymentData = option.type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
83131
82585
|
? {
|
|
83132
82586
|
recipient,
|
|
83133
|
-
amount:
|
|
82587
|
+
amount: amount,
|
|
83134
82588
|
expirationDate: b$4(expirationDateRequired),
|
|
83135
82589
|
nonce,
|
|
83136
82590
|
metadata: '0x'
|
|
83137
82591
|
}
|
|
83138
82592
|
: {
|
|
83139
|
-
tokenAddress,
|
|
82593
|
+
tokenAddress: option.contractAddress,
|
|
83140
82594
|
recipient,
|
|
83141
|
-
amount:
|
|
82595
|
+
amount: amount,
|
|
83142
82596
|
expirationDate: b$4(expirationDateRequired),
|
|
83143
82597
|
nonce,
|
|
83144
82598
|
metadata: '0x'
|
|
@@ -83147,7 +82601,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
83147
82601
|
name: 'MCPayment',
|
|
83148
82602
|
version: '1.0.0',
|
|
83149
82603
|
chainId,
|
|
83150
|
-
verifyingContract:
|
|
82604
|
+
verifyingContract: paymentRails
|
|
83151
82605
|
};
|
|
83152
82606
|
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
83153
82607
|
const proof = [
|
|
@@ -83167,20 +82621,24 @@ var PolygonIdSdk = (function (exports) {
|
|
|
83167
82621
|
const d = {
|
|
83168
82622
|
type: exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1,
|
|
83169
82623
|
'@context': [
|
|
83170
|
-
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`,
|
|
82624
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
83171
82625
|
'https://w3id.org/security/suites/eip712sig-2021/v1'
|
|
83172
82626
|
],
|
|
83173
82627
|
recipient,
|
|
83174
82628
|
amount: amount.toString(),
|
|
83175
|
-
currency,
|
|
83176
82629
|
expirationDate: expirationDateRequired.toISOString(),
|
|
83177
82630
|
nonce: nonce.toString(),
|
|
83178
82631
|
metadata: '0x',
|
|
83179
82632
|
proof
|
|
83180
82633
|
};
|
|
83181
|
-
dataArr.push(type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
82634
|
+
dataArr.push(option.type === exports.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
83182
82635
|
? d
|
|
83183
|
-
: {
|
|
82636
|
+
: {
|
|
82637
|
+
...d,
|
|
82638
|
+
type: option.type,
|
|
82639
|
+
tokenAddress: option.contractAddress || '',
|
|
82640
|
+
features: option.features || []
|
|
82641
|
+
});
|
|
83184
82642
|
}
|
|
83185
82643
|
paymentRequestInfo.push({
|
|
83186
82644
|
data: dataArr,
|
|
@@ -83265,6 +82723,170 @@ var PolygonIdSdk = (function (exports) {
|
|
|
83265
82723
|
}
|
|
83266
82724
|
}
|
|
83267
82725
|
|
|
82726
|
+
/**
|
|
82727
|
+
* @beta
|
|
82728
|
+
* createDiscoveryFeatureQueryMessage is a function to create didcomm protocol discovery-feature query message
|
|
82729
|
+
* @param opts - discovery-feature query options
|
|
82730
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
82731
|
+
*/
|
|
82732
|
+
function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
82733
|
+
const uuidv4 = v4();
|
|
82734
|
+
return {
|
|
82735
|
+
id: uuidv4,
|
|
82736
|
+
thid: uuidv4,
|
|
82737
|
+
typ: MediaType.PlainMessage,
|
|
82738
|
+
type: PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE,
|
|
82739
|
+
body: {
|
|
82740
|
+
queries
|
|
82741
|
+
},
|
|
82742
|
+
from: opts?.from,
|
|
82743
|
+
to: opts?.to,
|
|
82744
|
+
created_time: b$4(new Date()),
|
|
82745
|
+
expires_time: opts?.expires_time
|
|
82746
|
+
};
|
|
82747
|
+
}
|
|
82748
|
+
/**
|
|
82749
|
+
* @beta
|
|
82750
|
+
* createDiscoveryFeatureDiscloseMessage is a function to create didcomm protocol discovery-feature disclose message
|
|
82751
|
+
* @param {DiscoverFeatureDisclosure[]} disclosures - array of disclosures
|
|
82752
|
+
* @param opts - basic message options
|
|
82753
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
82754
|
+
*/
|
|
82755
|
+
function createDiscoveryFeatureDiscloseMessage(disclosures, opts) {
|
|
82756
|
+
const uuidv4 = v4();
|
|
82757
|
+
return {
|
|
82758
|
+
id: uuidv4,
|
|
82759
|
+
typ: MediaType.PlainMessage,
|
|
82760
|
+
thid: uuidv4,
|
|
82761
|
+
type: PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE,
|
|
82762
|
+
body: {
|
|
82763
|
+
disclosures
|
|
82764
|
+
},
|
|
82765
|
+
from: opts?.from,
|
|
82766
|
+
to: opts?.to,
|
|
82767
|
+
created_time: b$4(new Date()),
|
|
82768
|
+
expires_time: opts?.expires_time
|
|
82769
|
+
};
|
|
82770
|
+
}
|
|
82771
|
+
/**
|
|
82772
|
+
*
|
|
82773
|
+
* Handler for discovery protocol
|
|
82774
|
+
*
|
|
82775
|
+
* @public
|
|
82776
|
+
* @beta
|
|
82777
|
+
* @class DiscoveryProtocolHandler
|
|
82778
|
+
* @implements implements DiscoveryProtocolHandler interface
|
|
82779
|
+
*/
|
|
82780
|
+
class DiscoveryProtocolHandler extends AbstractMessageHandler {
|
|
82781
|
+
/**
|
|
82782
|
+
* Creates an instance of DiscoveryProtocolHandler.
|
|
82783
|
+
* @param {DiscoveryProtocolOptions} _options - discovery protocol options
|
|
82784
|
+
*/
|
|
82785
|
+
constructor(_options) {
|
|
82786
|
+
super();
|
|
82787
|
+
this._options = _options;
|
|
82788
|
+
const headers = [
|
|
82789
|
+
'id',
|
|
82790
|
+
'typ',
|
|
82791
|
+
'type',
|
|
82792
|
+
'thid',
|
|
82793
|
+
'body',
|
|
82794
|
+
'from',
|
|
82795
|
+
'to',
|
|
82796
|
+
'created_time',
|
|
82797
|
+
'expires_time'
|
|
82798
|
+
];
|
|
82799
|
+
if (!_options.headers) {
|
|
82800
|
+
_options.headers = headers;
|
|
82801
|
+
}
|
|
82802
|
+
}
|
|
82803
|
+
/**
|
|
82804
|
+
* @inheritdoc IProtocolMessageHandler#handle
|
|
82805
|
+
*/
|
|
82806
|
+
async handle(message, context) {
|
|
82807
|
+
switch (message.type) {
|
|
82808
|
+
case PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE:
|
|
82809
|
+
return await this.handleDiscoveryQuery(message, context);
|
|
82810
|
+
default:
|
|
82811
|
+
return super.handle(message, context);
|
|
82812
|
+
}
|
|
82813
|
+
}
|
|
82814
|
+
/**
|
|
82815
|
+
* @inheritdoc IDiscoveryProtocolHandler#handleDiscoveryQuery
|
|
82816
|
+
*/
|
|
82817
|
+
async handleDiscoveryQuery(message, opts) {
|
|
82818
|
+
if (!opts?.allowExpiredMessages) {
|
|
82819
|
+
verifyExpiresTime(message);
|
|
82820
|
+
}
|
|
82821
|
+
const disclosures = [];
|
|
82822
|
+
for (const query of message.body.queries) {
|
|
82823
|
+
disclosures.push(...this.handleQuery(query));
|
|
82824
|
+
}
|
|
82825
|
+
return Promise.resolve(createDiscoveryFeatureDiscloseMessage(disclosures, {
|
|
82826
|
+
to: message.from,
|
|
82827
|
+
from: message.to,
|
|
82828
|
+
expires_time: opts?.disclosureExpiresDate
|
|
82829
|
+
? b$4(opts.disclosureExpiresDate)
|
|
82830
|
+
: undefined
|
|
82831
|
+
}));
|
|
82832
|
+
}
|
|
82833
|
+
handleQuery(query) {
|
|
82834
|
+
let result = [];
|
|
82835
|
+
switch (query[exports.DiscoverFeatureQueryType.FeatureType]) {
|
|
82836
|
+
case exports.DiscoveryProtocolFeatureType.Accept:
|
|
82837
|
+
result = this.handleAcceptQuery();
|
|
82838
|
+
break;
|
|
82839
|
+
case exports.DiscoveryProtocolFeatureType.Protocol:
|
|
82840
|
+
result = this.handleProtocolQuery();
|
|
82841
|
+
break;
|
|
82842
|
+
case exports.DiscoveryProtocolFeatureType.GoalCode:
|
|
82843
|
+
result = this.handleGoalCodeQuery();
|
|
82844
|
+
break;
|
|
82845
|
+
case exports.DiscoveryProtocolFeatureType.Header:
|
|
82846
|
+
result = this.handleHeaderQuery();
|
|
82847
|
+
break;
|
|
82848
|
+
}
|
|
82849
|
+
return this.handleMatch(result, query.match);
|
|
82850
|
+
}
|
|
82851
|
+
handleAcceptQuery() {
|
|
82852
|
+
const acceptProfiles = this._options.packageManager.getSupportedProfiles();
|
|
82853
|
+
return acceptProfiles.map((profile) => ({
|
|
82854
|
+
[exports.DiscoverFeatureQueryType.FeatureType]: exports.DiscoveryProtocolFeatureType.Accept,
|
|
82855
|
+
id: profile
|
|
82856
|
+
}));
|
|
82857
|
+
}
|
|
82858
|
+
handleProtocolQuery() {
|
|
82859
|
+
return (this._options.protocols?.map((protocol) => ({
|
|
82860
|
+
[exports.DiscoverFeatureQueryType.FeatureType]: exports.DiscoveryProtocolFeatureType.Protocol,
|
|
82861
|
+
id: protocol
|
|
82862
|
+
})) ?? []);
|
|
82863
|
+
}
|
|
82864
|
+
handleGoalCodeQuery() {
|
|
82865
|
+
return (this._options.goalCodes?.map((goalCode) => ({
|
|
82866
|
+
[exports.DiscoverFeatureQueryType.FeatureType]: exports.DiscoveryProtocolFeatureType.GoalCode,
|
|
82867
|
+
id: goalCode
|
|
82868
|
+
})) ?? []);
|
|
82869
|
+
}
|
|
82870
|
+
handleHeaderQuery() {
|
|
82871
|
+
return (this._options.headers?.map((header) => ({
|
|
82872
|
+
[exports.DiscoverFeatureQueryType.FeatureType]: exports.DiscoveryProtocolFeatureType.Header,
|
|
82873
|
+
id: header
|
|
82874
|
+
})) ?? []);
|
|
82875
|
+
}
|
|
82876
|
+
handleMatch(disclosures, match) {
|
|
82877
|
+
if (!match || match === '*') {
|
|
82878
|
+
return disclosures;
|
|
82879
|
+
}
|
|
82880
|
+
const regExp = this.wildcardToRegExp(match);
|
|
82881
|
+
return disclosures.filter((disclosure) => regExp.test(disclosure.id));
|
|
82882
|
+
}
|
|
82883
|
+
wildcardToRegExp(match) {
|
|
82884
|
+
// Escape special regex characters, then replace `*` with `.*`
|
|
82885
|
+
const regexPattern = match.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
82886
|
+
return new RegExp(`^${regexPattern}$`);
|
|
82887
|
+
}
|
|
82888
|
+
}
|
|
82889
|
+
|
|
83268
82890
|
const allOperations = Object.values(QueryOperators);
|
|
83269
82891
|
const v2Operations = [
|
|
83270
82892
|
exports.Operators.NOOP,
|
|
@@ -84535,6 +84157,12 @@ var PolygonIdSdk = (function (exports) {
|
|
|
84535
84157
|
authInputs.gistProof = gistProof;
|
|
84536
84158
|
return authInputs.inputsMarshal();
|
|
84537
84159
|
}
|
|
84160
|
+
/** {@inheritdoc IProofService.generateAuthV2Proof} */
|
|
84161
|
+
async generateAuthV2Proof(challenge, did) {
|
|
84162
|
+
const authInputs = await this.generateAuthV2Inputs(challenge, did, exports.CircuitId.AuthV2);
|
|
84163
|
+
const zkProof = await this._prover.generate(authInputs, exports.CircuitId.AuthV2);
|
|
84164
|
+
return zkProof;
|
|
84165
|
+
}
|
|
84538
84166
|
async verifyState(circuitId, pubSignals, opts = {
|
|
84539
84167
|
acceptedStateTransitionDelay: DEFAULT_AUTH_VERIFY_DELAY
|
|
84540
84168
|
}) {
|
|
@@ -85334,6 +84962,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
85334
84962
|
exports.DataPrepareHandlerFunc = DataPrepareHandlerFunc;
|
|
85335
84963
|
exports.DidDocumentCredentialStatusResolver = DidDocumentCredentialStatusResolver;
|
|
85336
84964
|
exports.DidResolverStateReadonlyStorage = DidResolverStateReadonlyStorage;
|
|
84965
|
+
exports.DiscoveryProtocolHandler = DiscoveryProtocolHandler;
|
|
85337
84966
|
exports.Ed25519Provider = Ed25519Provider;
|
|
85338
84967
|
exports.ErrorEmptyAuthClaimNonRevProof = ErrorEmptyAuthClaimNonRevProof;
|
|
85339
84968
|
exports.ErrorEmptyAuthClaimProof = ErrorEmptyAuthClaimProof;
|
|
@@ -85430,10 +85059,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
85430
85059
|
exports.checkQueryRequest = checkQueryRequest;
|
|
85431
85060
|
exports.circuitValidator = circuitValidator;
|
|
85432
85061
|
exports.comparatorOptions = comparatorOptions;
|
|
85433
|
-
exports.convertPaymentAmount = convertPaymentAmount;
|
|
85434
85062
|
exports.core = index$1;
|
|
85435
85063
|
exports.createAuthorizationRequest = createAuthorizationRequest;
|
|
85436
85064
|
exports.createAuthorizationRequestWithMessage = createAuthorizationRequestWithMessage;
|
|
85065
|
+
exports.createDiscoveryFeatureDiscloseMessage = createDiscoveryFeatureDiscloseMessage;
|
|
85066
|
+
exports.createDiscoveryFeatureQueryMessage = createDiscoveryFeatureQueryMessage;
|
|
85437
85067
|
exports.createPayment = createPayment;
|
|
85438
85068
|
exports.createPaymentRequest = createPaymentRequest;
|
|
85439
85069
|
exports.createProposal = createProposal;
|