@0xpolygonid/js-sdk 1.5.0 → 1.6.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 +1685 -468
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +1706 -473
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2.js +1 -1
- package/dist/node/cjs/circuits/atomic-query-sig-v2-on-chain.js +2 -2
- package/dist/node/cjs/circuits/atomic-query-sig-v2.js +11 -14
- package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +320 -0
- package/dist/node/cjs/circuits/atomic-query-v3.js +275 -0
- package/dist/node/cjs/circuits/common.js +5 -7
- package/dist/node/cjs/circuits/comparer.js +57 -2
- package/dist/node/cjs/circuits/index.js +4 -0
- package/dist/node/cjs/circuits/linked-multi-query.js +128 -0
- package/dist/node/cjs/circuits/linked-nullifier.js +57 -0
- package/dist/node/cjs/circuits/models.js +25 -1
- package/dist/node/cjs/credentials/credential-wallet.js +2 -10
- package/dist/node/cjs/credentials/index.js +1 -0
- package/dist/node/cjs/credentials/utils.js +23 -0
- package/dist/node/cjs/iden3comm/handlers/auth.js +49 -8
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +20 -8
- package/dist/node/cjs/proof/common.js +104 -1
- package/dist/node/cjs/proof/inputs-generator.js +393 -0
- package/dist/node/cjs/proof/proof-service.js +105 -372
- package/dist/node/cjs/schema-processor/json/parser.js +7 -0
- package/dist/node/cjs/schema-processor/json/validator.js +1 -0
- package/dist/node/cjs/storage/filters/jsonQuery.js +73 -8
- package/dist/node/cjs/utils/did-helper.js +14 -0
- package/dist/node/cjs/utils/index.js +2 -0
- package/dist/node/cjs/utils/object.js +42 -0
- package/dist/node/cjs/verifiable/presentation.js +34 -33
- package/dist/node/cjs/verifiable/proof.js +2 -0
- package/dist/node/esm/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
- package/dist/node/esm/circuits/atomic-query-mtp-v2.js +1 -1
- package/dist/node/esm/circuits/atomic-query-sig-v2-on-chain.js +2 -2
- package/dist/node/esm/circuits/atomic-query-sig-v2.js +11 -14
- package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +315 -0
- package/dist/node/esm/circuits/atomic-query-v3.js +270 -0
- package/dist/node/esm/circuits/common.js +4 -6
- package/dist/node/esm/circuits/comparer.js +55 -1
- package/dist/node/esm/circuits/index.js +4 -0
- package/dist/node/esm/circuits/linked-multi-query.js +123 -0
- package/dist/node/esm/circuits/linked-nullifier.js +52 -0
- package/dist/node/esm/circuits/models.js +25 -1
- package/dist/node/esm/credentials/credential-wallet.js +2 -10
- package/dist/node/esm/credentials/index.js +1 -0
- package/dist/node/esm/credentials/utils.js +19 -0
- package/dist/node/esm/iden3comm/handlers/auth.js +50 -9
- package/dist/node/esm/iden3comm/handlers/contract-request.js +20 -8
- package/dist/node/esm/proof/common.js +101 -2
- package/dist/node/esm/proof/inputs-generator.js +389 -0
- package/dist/node/esm/proof/proof-service.js +111 -377
- package/dist/node/esm/schema-processor/json/parser.js +7 -0
- package/dist/node/esm/schema-processor/json/validator.js +1 -0
- package/dist/node/esm/storage/filters/jsonQuery.js +74 -9
- package/dist/node/esm/utils/did-helper.js +10 -0
- package/dist/node/esm/utils/index.js +2 -0
- package/dist/node/esm/utils/object.js +38 -0
- package/dist/node/esm/verifiable/presentation.js +30 -29
- package/dist/node/esm/verifiable/proof.js +2 -0
- package/dist/types/circuits/atomic-query-mtp-v2.d.ts +13 -13
- package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +142 -0
- package/dist/types/circuits/atomic-query-v3.d.ts +120 -0
- package/dist/types/circuits/common.d.ts +4 -4
- package/dist/types/circuits/comparer.d.ts +33 -1
- package/dist/types/circuits/index.d.ts +4 -0
- package/dist/types/circuits/linked-multi-query.d.ts +38 -0
- package/dist/types/circuits/linked-nullifier.d.ts +37 -0
- package/dist/types/circuits/models.d.ts +20 -2
- package/dist/types/credentials/index.d.ts +1 -0
- package/dist/types/credentials/utils.d.ts +12 -0
- package/dist/types/iden3comm/types/packer.d.ts +1 -2
- package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
- package/dist/types/proof/common.d.ts +34 -3
- package/dist/types/proof/inputs-generator.d.ts +46 -0
- package/dist/types/proof/proof-service.d.ts +14 -25
- package/dist/types/schema-processor/json/parser.d.ts +1 -0
- package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
- package/dist/types/utils/did-helper.d.ts +6 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/object.d.ts +12 -0
- package/dist/types/verifiable/presentation.d.ts +6 -10
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BytesHelper, checkBigIntInField, Claim, DID, IdPosition, MerklizedRootPosition as MerklizedRootPosition$1,
|
|
1
|
+
import { BytesHelper, checkBigIntInField, genesisFromEthAddress, buildDIDType, Id, Claim, DID, IdPosition, MerklizedRootPosition as MerklizedRootPosition$1, SchemaHash, ClaimOptions, getChainId, DidMethod, Blockchain, NetworkId, getUnixTimestamp, ChainIds } from '@iden3/js-iden3-core';
|
|
2
2
|
import * as jsIden3Core from '@iden3/js-iden3-core';
|
|
3
3
|
export { jsIden3Core as core };
|
|
4
4
|
import { Merklizer, Path, getDocumentLoader } from '@iden3/js-jsonld-merklization';
|
|
@@ -13709,6 +13709,54 @@ function bytesToHex$1(b) {
|
|
|
13709
13709
|
return Hex.encodeString(b);
|
|
13710
13710
|
}
|
|
13711
13711
|
|
|
13712
|
+
function mergeObjects(credSubject, otherCredSubject) {
|
|
13713
|
+
let result = {};
|
|
13714
|
+
const credSubjectKeys = Object.keys(credSubject);
|
|
13715
|
+
for (const key of credSubjectKeys) {
|
|
13716
|
+
if (typeof otherCredSubject[key] !== 'undefined') {
|
|
13717
|
+
if (typeof credSubject[key] !== 'object' && typeof otherCredSubject[key] !== 'object') {
|
|
13718
|
+
throw new Error('Invalid query');
|
|
13719
|
+
}
|
|
13720
|
+
const subjectProperty = credSubject[key];
|
|
13721
|
+
const otherSubjectProperty = otherCredSubject[key];
|
|
13722
|
+
const propertyOperators = Object.keys(subjectProperty);
|
|
13723
|
+
const subjectPropertyResult = {};
|
|
13724
|
+
for (const operatorKey of propertyOperators) {
|
|
13725
|
+
if (typeof otherSubjectProperty[operatorKey] !== 'undefined') {
|
|
13726
|
+
const operatorValue1 = subjectProperty[operatorKey];
|
|
13727
|
+
const operatorValue2 = otherSubjectProperty[operatorKey];
|
|
13728
|
+
subjectPropertyResult[operatorKey] = [
|
|
13729
|
+
...new Set([
|
|
13730
|
+
...(subjectPropertyResult[operatorKey] ?? []),
|
|
13731
|
+
operatorValue1,
|
|
13732
|
+
...(Array.isArray(operatorValue2) ? operatorValue2 : [operatorValue2])
|
|
13733
|
+
])
|
|
13734
|
+
];
|
|
13735
|
+
}
|
|
13736
|
+
else {
|
|
13737
|
+
subjectPropertyResult[operatorKey] = subjectProperty[operatorKey];
|
|
13738
|
+
}
|
|
13739
|
+
}
|
|
13740
|
+
result[key] = {
|
|
13741
|
+
...otherCredSubject[key],
|
|
13742
|
+
...subjectPropertyResult
|
|
13743
|
+
};
|
|
13744
|
+
}
|
|
13745
|
+
}
|
|
13746
|
+
// Add remaining keys from obj2
|
|
13747
|
+
result = { ...credSubject, ...otherCredSubject, ...result };
|
|
13748
|
+
return result;
|
|
13749
|
+
}
|
|
13750
|
+
|
|
13751
|
+
const buildVerifierId = (address, info) => {
|
|
13752
|
+
address = address.replace('0x', '');
|
|
13753
|
+
const ethAddrBytes = Hex.decodeString(address);
|
|
13754
|
+
const ethAddr = ethAddrBytes.slice(0, 20);
|
|
13755
|
+
const genesis = genesisFromEthAddress(ethAddr);
|
|
13756
|
+
const tp = buildDIDType(info.method, info.blockchain, info.networkId);
|
|
13757
|
+
return new Id(tp, genesis);
|
|
13758
|
+
};
|
|
13759
|
+
|
|
13712
13760
|
/**
|
|
13713
13761
|
* Provider for Sec256p1 keys256p1
|
|
13714
13762
|
* @public
|
|
@@ -14129,6 +14177,7 @@ class Iden3SparseMerkleTreeProof {
|
|
|
14129
14177
|
mtp: this.mtp.toJSON()
|
|
14130
14178
|
};
|
|
14131
14179
|
}
|
|
14180
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14132
14181
|
static fromJSON(obj) {
|
|
14133
14182
|
let mtp;
|
|
14134
14183
|
if (obj?.mtp?.notEmpties && obj?.mtp?.depth && obj?.mtp?.siblings) {
|
|
@@ -14207,6 +14256,7 @@ class BJJSignatureProof2021 {
|
|
|
14207
14256
|
* fromJSON is a method to deserialize BJJSignatureProof2021 from json
|
|
14208
14257
|
* @param obj
|
|
14209
14258
|
*/
|
|
14259
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14210
14260
|
static fromJSON(obj) {
|
|
14211
14261
|
return new BJJSignatureProof2021({
|
|
14212
14262
|
issuerData: {
|
|
@@ -14408,19 +14458,23 @@ const stringByPath = (obj, path) => {
|
|
|
14408
14458
|
}
|
|
14409
14459
|
return value.toString();
|
|
14410
14460
|
};
|
|
14411
|
-
const
|
|
14412
|
-
let
|
|
14413
|
-
|
|
14414
|
-
|
|
14461
|
+
const buildFieldPath = async (ldSchema, contextType, field, opts) => {
|
|
14462
|
+
let path = new Path();
|
|
14463
|
+
if (field) {
|
|
14464
|
+
path = await Path.getContextPathKey(ldSchema, contextType, field, opts);
|
|
14415
14465
|
}
|
|
14416
|
-
catch (error) {
|
|
14417
|
-
throw new Error(`context not found: ${error.message}`);
|
|
14418
|
-
}
|
|
14419
|
-
const path = await Path.getContextPathKey(JSON.stringify(resp), contextType, field, opts);
|
|
14420
14466
|
path.prepend([VerifiableConstants.CREDENTIAL_SUBJECT_PATH]);
|
|
14421
14467
|
return path;
|
|
14422
14468
|
};
|
|
14423
|
-
const
|
|
14469
|
+
const findValue = (fieldName, credential) => {
|
|
14470
|
+
const [first, ...rest] = fieldName.split('.');
|
|
14471
|
+
let v = credential.credentialSubject[first];
|
|
14472
|
+
for (const part of rest) {
|
|
14473
|
+
v = v[part];
|
|
14474
|
+
}
|
|
14475
|
+
return v;
|
|
14476
|
+
};
|
|
14477
|
+
const createVerifiablePresentation = (context, tp, credential, queries) => {
|
|
14424
14478
|
const baseContext = [VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018];
|
|
14425
14479
|
const ldContext = baseContext[0] === context ? baseContext : [...baseContext, context];
|
|
14426
14480
|
const vc = VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_CREDENTIAL;
|
|
@@ -14428,36 +14482,33 @@ const createVerifiablePresentation = (context, tp, path, value) => {
|
|
|
14428
14482
|
if (tp !== vc) {
|
|
14429
14483
|
vcTypes.push(tp);
|
|
14430
14484
|
}
|
|
14431
|
-
const
|
|
14432
|
-
const obj = rest.reduceRight((acc, key) => ({ [key]: acc }), value);
|
|
14433
|
-
return {
|
|
14485
|
+
const skeleton = {
|
|
14434
14486
|
'@context': baseContext,
|
|
14435
14487
|
'@type': VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_PRESENTATION,
|
|
14436
14488
|
verifiableCredential: {
|
|
14437
14489
|
'@context': ldContext,
|
|
14438
14490
|
'@type': vcTypes,
|
|
14439
14491
|
credentialSubject: {
|
|
14440
|
-
'@type': tp
|
|
14441
|
-
[first]: obj
|
|
14492
|
+
'@type': tp
|
|
14442
14493
|
}
|
|
14443
14494
|
}
|
|
14444
14495
|
};
|
|
14445
|
-
};
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
|
|
14452
|
-
|
|
14453
|
-
|
|
14454
|
-
|
|
14455
|
-
|
|
14456
|
-
|
|
14457
|
-
|
|
14458
|
-
|
|
14459
|
-
}
|
|
14460
|
-
return
|
|
14496
|
+
let result = {};
|
|
14497
|
+
for (const query of queries) {
|
|
14498
|
+
const parts = query.fieldName.split('.');
|
|
14499
|
+
const current = parts.reduceRight((acc, part) => {
|
|
14500
|
+
if (result[part]) {
|
|
14501
|
+
return { [part]: { ...result[part], ...acc } };
|
|
14502
|
+
}
|
|
14503
|
+
return { [part]: acc };
|
|
14504
|
+
}, findValue(query.fieldName, credential));
|
|
14505
|
+
result = { ...result, ...current };
|
|
14506
|
+
}
|
|
14507
|
+
skeleton.verifiableCredential.credentialSubject = {
|
|
14508
|
+
...skeleton.verifiableCredential.credentialSubject,
|
|
14509
|
+
...result
|
|
14510
|
+
};
|
|
14511
|
+
return skeleton;
|
|
14461
14512
|
};
|
|
14462
14513
|
|
|
14463
14514
|
/** DIDDocumentJSONSchema is a basic schema of did document */
|
|
@@ -27532,6 +27583,13 @@ class Parser {
|
|
|
27532
27583
|
const ldCtx = await jsonld.processContext(context.getInitialContext({}), credential['@context'], opts);
|
|
27533
27584
|
return Parser.getSerializationAttrFromParsedContext(ldCtx, tp);
|
|
27534
27585
|
}
|
|
27586
|
+
// Get `iden3_serialization` attr definition from context document either using
|
|
27587
|
+
// type name like DeliverAddressMultiTestForked or by type id like
|
|
27588
|
+
// urn:uuid:ac2ede19-b3b9-454d-b1a9-a7b3d5763100.
|
|
27589
|
+
static async getSerializationAttrFromContext(context$1, opts, tp) {
|
|
27590
|
+
const ldCtx = await jsonld.processContext(context.getInitialContext({}), context$1, opts);
|
|
27591
|
+
return Parser.getSerializationAttrFromParsedContext(ldCtx, tp);
|
|
27592
|
+
}
|
|
27535
27593
|
static async getSerializationAttrFromParsedContext(ldCtx, tp) {
|
|
27536
27594
|
const termDef = ldCtx.mappings;
|
|
27537
27595
|
if (!termDef) {
|
|
@@ -36800,6 +36858,7 @@ class JsonSchemaValidator {
|
|
|
36800
36858
|
const validate = (schema.$id ? validator.getSchema(schema.$id) : undefined) || validator.compile(schema);
|
|
36801
36859
|
const valid = validate(data);
|
|
36802
36860
|
if (!valid) {
|
|
36861
|
+
// TODO: extract correct error messages
|
|
36803
36862
|
throw new Error(validate.errors?.map((e) => e.message).join(', '));
|
|
36804
36863
|
}
|
|
36805
36864
|
return true;
|
|
@@ -55149,7 +55208,7 @@ function isGenesisState(did, state) {
|
|
|
55149
55208
|
const defaultMTLevels = 40; // max MT levels, default value for identity circuits
|
|
55150
55209
|
const defaultValueArraySize = 64; // max value array size, default value for identity circuits
|
|
55151
55210
|
const defaultMTLevelsOnChain = 64; // max MT levels on chain, default value for identity circuits
|
|
55152
|
-
const
|
|
55211
|
+
const defaultMTLevelsClaim = 32; // max MT levels of JSON-LD merklization on claim
|
|
55153
55212
|
const ErrorEmptyAuthClaimProof = 'empty auth claim mtp proof';
|
|
55154
55213
|
const ErrorEmptyAuthClaimNonRevProof = 'empty auth claim non-revocation mtp proof';
|
|
55155
55214
|
const ErrorEmptyChallengeSignature = 'empty challenge signature';
|
|
@@ -55175,14 +55234,12 @@ class BaseConfig {
|
|
|
55175
55234
|
return this.mtLevel ? this.mtLevel : defaultMTLevels;
|
|
55176
55235
|
}
|
|
55177
55236
|
/**
|
|
55178
|
-
*
|
|
55237
|
+
* GetMTLevelsClaim max jsonld Claim levels
|
|
55179
55238
|
*
|
|
55180
55239
|
* @returns number
|
|
55181
55240
|
*/
|
|
55182
|
-
|
|
55183
|
-
return this.
|
|
55184
|
-
? this.mtLevelClaimsMerklization
|
|
55185
|
-
: defaultMTLevelsClaimsMerklization;
|
|
55241
|
+
getMTLevelsClaim() {
|
|
55242
|
+
return this.mtLevelClaim ? this.mtLevelClaim : defaultMTLevelsClaim;
|
|
55186
55243
|
}
|
|
55187
55244
|
/**
|
|
55188
55245
|
* GetValueArrSize return size of circuits value array size
|
|
@@ -55326,6 +55383,21 @@ function getProperties(obj) {
|
|
|
55326
55383
|
return result;
|
|
55327
55384
|
}
|
|
55328
55385
|
|
|
55386
|
+
/**
|
|
55387
|
+
* Represents the XSD namespace and its corresponding data types.
|
|
55388
|
+
*/
|
|
55389
|
+
var XSDNS;
|
|
55390
|
+
(function (XSDNS) {
|
|
55391
|
+
XSDNS["Boolean"] = "http://www.w3.org/2001/XMLSchema#boolean";
|
|
55392
|
+
XSDNS["Integer"] = "http://www.w3.org/2001/XMLSchema#integer";
|
|
55393
|
+
XSDNS["NonNegativeInteger"] = "http://www.w3.org/2001/XMLSchema#nonNegativeInteger";
|
|
55394
|
+
XSDNS["NonPositiveInteger"] = "http://www.w3.org/2001/XMLSchema#nonPositiveInteger";
|
|
55395
|
+
XSDNS["NegativeInteger"] = "http://www.w3.org/2001/XMLSchema#negativeInteger";
|
|
55396
|
+
XSDNS["PositiveInteger"] = "http://www.w3.org/2001/XMLSchema#positiveInteger";
|
|
55397
|
+
XSDNS["DateTime"] = "http://www.w3.org/2001/XMLSchema#dateTime";
|
|
55398
|
+
XSDNS["Double"] = "http://www.w3.org/2001/XMLSchema#double";
|
|
55399
|
+
XSDNS["String"] = "http://www.w3.org/2001/XMLSchema#string";
|
|
55400
|
+
})(XSDNS || (XSDNS = {}));
|
|
55329
55401
|
/**
|
|
55330
55402
|
* List of available operators.
|
|
55331
55403
|
*
|
|
@@ -55340,6 +55412,11 @@ var Operators;
|
|
|
55340
55412
|
Operators[Operators["IN"] = 4] = "IN";
|
|
55341
55413
|
Operators[Operators["NIN"] = 5] = "NIN";
|
|
55342
55414
|
Operators[Operators["NE"] = 6] = "NE";
|
|
55415
|
+
Operators[Operators["LTE"] = 7] = "LTE";
|
|
55416
|
+
Operators[Operators["GTE"] = 8] = "GTE";
|
|
55417
|
+
Operators[Operators["BETWEEN"] = 9] = "BETWEEN";
|
|
55418
|
+
Operators[Operators["SD"] = 16] = "SD";
|
|
55419
|
+
Operators[Operators["NULLIFY"] = 17] = "NULLIFY";
|
|
55343
55420
|
})(Operators || (Operators = {}));
|
|
55344
55421
|
/** QueryOperators represents operators for atomic circuits */
|
|
55345
55422
|
const QueryOperators = {
|
|
@@ -55349,7 +55426,41 @@ const QueryOperators = {
|
|
|
55349
55426
|
$gt: Operators.GT,
|
|
55350
55427
|
$in: Operators.IN,
|
|
55351
55428
|
$nin: Operators.NIN,
|
|
55352
|
-
$ne: Operators.NE
|
|
55429
|
+
$ne: Operators.NE,
|
|
55430
|
+
$lte: Operators.LTE,
|
|
55431
|
+
$gte: Operators.GTE,
|
|
55432
|
+
$between: Operators.BETWEEN,
|
|
55433
|
+
$sd: Operators.SD,
|
|
55434
|
+
$nullify: Operators.NULLIFY
|
|
55435
|
+
};
|
|
55436
|
+
const allOperations = Object.values(QueryOperators);
|
|
55437
|
+
const availableTypesOperators = new Map([
|
|
55438
|
+
[XSDNS.Boolean, [QueryOperators.$eq, QueryOperators.$ne]],
|
|
55439
|
+
[XSDNS.Integer, allOperations],
|
|
55440
|
+
[XSDNS.NonNegativeInteger, allOperations],
|
|
55441
|
+
[XSDNS.PositiveInteger, allOperations],
|
|
55442
|
+
[XSDNS.Double, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$in, QueryOperators.$nin]],
|
|
55443
|
+
[XSDNS.String, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$in, QueryOperators.$nin]],
|
|
55444
|
+
[XSDNS.DateTime, allOperations]
|
|
55445
|
+
]);
|
|
55446
|
+
/**
|
|
55447
|
+
* Checks if the given operation is valid for the specified datatype.
|
|
55448
|
+
* @param datatype - The datatype to check the operation for.
|
|
55449
|
+
* @param op - The operation to check.
|
|
55450
|
+
* @returns True if the operation is valid, false otherwise.
|
|
55451
|
+
*/
|
|
55452
|
+
const isValidOperation = (datatype, op) => {
|
|
55453
|
+
if (op === Operators.NOOP) {
|
|
55454
|
+
return true;
|
|
55455
|
+
}
|
|
55456
|
+
if (!availableTypesOperators.has(datatype)) {
|
|
55457
|
+
return false;
|
|
55458
|
+
}
|
|
55459
|
+
const ops = availableTypesOperators.get(datatype);
|
|
55460
|
+
if (!ops) {
|
|
55461
|
+
return false;
|
|
55462
|
+
}
|
|
55463
|
+
return ops.includes(op);
|
|
55353
55464
|
};
|
|
55354
55465
|
/**
|
|
55355
55466
|
* Scalar is used to compare two scalar value.
|
|
@@ -55461,7 +55572,9 @@ class Query {
|
|
|
55461
55572
|
*
|
|
55462
55573
|
*/
|
|
55463
55574
|
validate() {
|
|
55464
|
-
if (this.operator !== QueryOperators.$noop &&
|
|
55575
|
+
if (this.operator !== QueryOperators.$noop &&
|
|
55576
|
+
this.operator !== QueryOperators.$sd &&
|
|
55577
|
+
this.values?.some((v) => typeof v !== 'bigint'))
|
|
55465
55578
|
throw new Error(CircuitError.EmptyQueryValue);
|
|
55466
55579
|
}
|
|
55467
55580
|
}
|
|
@@ -55484,6 +55597,26 @@ var CircuitId;
|
|
|
55484
55597
|
CircuitId["AtomicQuerySigV2"] = "credentialAtomicQuerySigV2";
|
|
55485
55598
|
// AtomicQuerySigOnChain is a type for credentialAtomicQuerySigOnChain.circom
|
|
55486
55599
|
CircuitId["AtomicQuerySigV2OnChain"] = "credentialAtomicQuerySigV2OnChain";
|
|
55600
|
+
/**
|
|
55601
|
+
* @beta
|
|
55602
|
+
*/
|
|
55603
|
+
// AtomicQueryV3CircuitID is a type for credentialAtomicQueryV3.circom
|
|
55604
|
+
CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.0";
|
|
55605
|
+
/**
|
|
55606
|
+
* @beta
|
|
55607
|
+
*/
|
|
55608
|
+
// AtomicQueryV3OnChainCircuitID is a type for credentialAtomicQueryV3OnChain.circom
|
|
55609
|
+
CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.0";
|
|
55610
|
+
/**
|
|
55611
|
+
* @beta
|
|
55612
|
+
*/
|
|
55613
|
+
// LinkedNullifier is a type for linkedNullifier.circom
|
|
55614
|
+
CircuitId["LinkedNullifier"] = "linkedNullifier-beta.0";
|
|
55615
|
+
/**
|
|
55616
|
+
* @beta
|
|
55617
|
+
*/
|
|
55618
|
+
// LinkedMultiQuery is a type for linkedMultiQuery.circom
|
|
55619
|
+
CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.0";
|
|
55487
55620
|
})(CircuitId || (CircuitId = {}));
|
|
55488
55621
|
/**
|
|
55489
55622
|
* Claim structure for circuit inputs
|
|
@@ -55517,7 +55650,9 @@ var CircuitError;
|
|
|
55517
55650
|
CircuitError["EmptyId"] = "empty Id";
|
|
55518
55651
|
CircuitError["EmptyChallenge"] = "empty challenge";
|
|
55519
55652
|
CircuitError["EmptyGISTProof"] = "empty GIST merkle tree proof";
|
|
55653
|
+
CircuitError["EmptyTreeState"] = "empty tree state";
|
|
55520
55654
|
CircuitError["EmptyRequestID"] = "empty request ID";
|
|
55655
|
+
CircuitError["InvalidProofType"] = "invalid proof type";
|
|
55521
55656
|
})(CircuitError || (CircuitError = {}));
|
|
55522
55657
|
/**
|
|
55523
55658
|
* ValueProof represents a Merkle Proof for a value stored as MT
|
|
@@ -55606,7 +55741,7 @@ class AtomicQueryMTPV2Inputs extends BaseConfig {
|
|
|
55606
55741
|
.toString(),
|
|
55607
55742
|
issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(),
|
|
55608
55743
|
claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
|
|
55609
|
-
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.
|
|
55744
|
+
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
|
|
55610
55745
|
claimPathValue: valueProof.value.toString(),
|
|
55611
55746
|
operator: this.query.operator,
|
|
55612
55747
|
slotIndex: this.query.slotIndex,
|
|
@@ -55787,7 +55922,7 @@ class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
|
|
|
55787
55922
|
issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots?.string(),
|
|
55788
55923
|
issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.string(),
|
|
55789
55924
|
claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
|
|
55790
|
-
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.
|
|
55925
|
+
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
|
|
55791
55926
|
claimPathValue: valueProof.value.toString(),
|
|
55792
55927
|
operator: this.query.operator,
|
|
55793
55928
|
slotIndex: this.query.slotIndex,
|
|
@@ -55944,6 +56079,9 @@ class AtomicQuerySigV2Inputs extends BaseConfig {
|
|
|
55944
56079
|
this.query.valueProof.validate();
|
|
55945
56080
|
}
|
|
55946
56081
|
const valueProof = this.query.valueProof ?? new ValueProof();
|
|
56082
|
+
const treeState = this.skipClaimRevocationCheck
|
|
56083
|
+
? this.claim.signatureProof?.issuerAuthNonRevProof.treeState
|
|
56084
|
+
: this.claim.nonRevProof?.treeState;
|
|
55947
56085
|
const s = {
|
|
55948
56086
|
requestID: this.requestID.toString(),
|
|
55949
56087
|
userGenesisID: this.id.bigInt().toString(),
|
|
@@ -55951,16 +56089,10 @@ class AtomicQuerySigV2Inputs extends BaseConfig {
|
|
|
55951
56089
|
claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(),
|
|
55952
56090
|
issuerID: this.claim.issuerID?.bigInt().toString(),
|
|
55953
56091
|
issuerClaim: this.claim.claim?.marshalJson(),
|
|
55954
|
-
issuerClaimNonRevClaimsTreeRoot:
|
|
55955
|
-
|
|
55956
|
-
|
|
55957
|
-
|
|
55958
|
-
?.bigInt()
|
|
55959
|
-
.toString(),
|
|
55960
|
-
issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots
|
|
55961
|
-
?.bigInt()
|
|
55962
|
-
.toString(),
|
|
55963
|
-
issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(),
|
|
56092
|
+
issuerClaimNonRevClaimsTreeRoot: treeState?.claimsRoot.bigInt().toString(),
|
|
56093
|
+
issuerClaimNonRevRevTreeRoot: treeState?.revocationRoot.bigInt().toString(),
|
|
56094
|
+
issuerClaimNonRevRootsTreeRoot: treeState?.rootOfRoots.bigInt().toString(),
|
|
56095
|
+
issuerClaimNonRevState: treeState?.state.bigInt().toString(),
|
|
55964
56096
|
issuerClaimNonRevMtp: this.claim.nonRevProof?.proof &&
|
|
55965
56097
|
prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
|
|
55966
56098
|
issuerClaimSignatureR8x: this.claim.signatureProof?.signature.R8[0].toString(),
|
|
@@ -55970,18 +56102,18 @@ class AtomicQuerySigV2Inputs extends BaseConfig {
|
|
|
55970
56102
|
issuerAuthClaimMtp: this.claim.signatureProof?.issuerAuthIncProof?.proof &&
|
|
55971
56103
|
prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel()),
|
|
55972
56104
|
issuerAuthClaimsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof.treeState?.claimsRoot
|
|
55973
|
-
|
|
56105
|
+
.bigInt()
|
|
55974
56106
|
.toString(),
|
|
55975
56107
|
issuerAuthRevTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot
|
|
55976
|
-
|
|
56108
|
+
.bigInt()
|
|
55977
56109
|
.toString(),
|
|
55978
56110
|
issuerAuthRootsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots
|
|
55979
|
-
|
|
56111
|
+
.bigInt()
|
|
55980
56112
|
.toString(),
|
|
55981
56113
|
issuerAuthClaimNonRevMtp: this.claim.signatureProof?.issuerAuthNonRevProof?.proof &&
|
|
55982
56114
|
prepareSiblingsStr(this.claim.signatureProof.issuerAuthNonRevProof.proof, this.getMTLevel()),
|
|
55983
56115
|
claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
|
|
55984
|
-
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.
|
|
56116
|
+
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
|
|
55985
56117
|
claimPathValue: valueProof.value.toString(),
|
|
55986
56118
|
operator: this.query.operator,
|
|
55987
56119
|
timestamp: this.currentTimeStamp,
|
|
@@ -56111,6 +56243,581 @@ class AtomicQuerySigV2PubSignals extends BaseConfig {
|
|
|
56111
56243
|
}
|
|
56112
56244
|
}
|
|
56113
56245
|
|
|
56246
|
+
const zero$1 = '0';
|
|
56247
|
+
/**
|
|
56248
|
+
* AtomicQueryV3Inputs ZK private inputs for credentialAtomicQueryV3.circom
|
|
56249
|
+
*
|
|
56250
|
+
* @beta
|
|
56251
|
+
* @class AtomicQueryV3Inputs
|
|
56252
|
+
* @extends {BaseConfig}
|
|
56253
|
+
*/
|
|
56254
|
+
class AtomicQueryV3Inputs extends BaseConfig {
|
|
56255
|
+
validate() {
|
|
56256
|
+
if (!this.requestID) {
|
|
56257
|
+
throw new Error(CircuitError.EmptyRequestID);
|
|
56258
|
+
}
|
|
56259
|
+
if (!this.claim.nonRevProof.proof) {
|
|
56260
|
+
throw new Error(CircuitError.EmptyClaimNonRevProof);
|
|
56261
|
+
}
|
|
56262
|
+
if (!this.query.values) {
|
|
56263
|
+
throw new Error(CircuitError.EmptyQueryValue);
|
|
56264
|
+
}
|
|
56265
|
+
if (!this.proofType) {
|
|
56266
|
+
throw new Error(CircuitError.InvalidProofType);
|
|
56267
|
+
}
|
|
56268
|
+
if (this.proofType === ProofType.BJJSignature) {
|
|
56269
|
+
if (!this.claim.signatureProof?.issuerAuthIncProof.proof) {
|
|
56270
|
+
throw new Error(CircuitError.EmptyIssuerAuthClaimProof);
|
|
56271
|
+
}
|
|
56272
|
+
if (!this.claim.signatureProof.issuerAuthNonRevProof.proof) {
|
|
56273
|
+
throw new Error(CircuitError.EmptyIssuerAuthClaimNonRevProof);
|
|
56274
|
+
}
|
|
56275
|
+
if (!this.claim.signatureProof.signature) {
|
|
56276
|
+
throw new Error(CircuitError.EmptyClaimSignature);
|
|
56277
|
+
}
|
|
56278
|
+
}
|
|
56279
|
+
if (this.proofType === ProofType.Iden3SparseMerkleTreeProof) {
|
|
56280
|
+
if (!this.claim?.incProof?.proof) {
|
|
56281
|
+
throw new Error(CircuitError.EmptyClaimProof);
|
|
56282
|
+
}
|
|
56283
|
+
}
|
|
56284
|
+
}
|
|
56285
|
+
fillMTPProofsWithZero(s) {
|
|
56286
|
+
s.issuerClaimMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56287
|
+
s.issuerClaimClaimsTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56288
|
+
s.issuerClaimRevTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56289
|
+
s.issuerClaimRootsTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56290
|
+
s.issuerClaimIdenState = ZERO_HASH.bigInt().toString();
|
|
56291
|
+
}
|
|
56292
|
+
fillSigProofWithZero(s) {
|
|
56293
|
+
s.issuerClaimSignatureR8x = zero$1;
|
|
56294
|
+
s.issuerClaimSignatureR8y = zero$1;
|
|
56295
|
+
s.issuerClaimSignatureS = zero$1;
|
|
56296
|
+
s.issuerAuthClaim = new Claim().marshalJson();
|
|
56297
|
+
s.issuerAuthClaimMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56298
|
+
s.issuerAuthClaimsTreeRoot = zero$1;
|
|
56299
|
+
s.issuerAuthRevTreeRoot = zero$1;
|
|
56300
|
+
s.issuerAuthRootsTreeRoot = zero$1;
|
|
56301
|
+
s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56302
|
+
s.issuerAuthClaimNonRevMtpAuxHi = ZERO_HASH.bigInt().toString();
|
|
56303
|
+
s.issuerAuthClaimNonRevMtpAuxHv = ZERO_HASH.bigInt().toString();
|
|
56304
|
+
s.issuerAuthClaimNonRevMtpNoAux = zero$1;
|
|
56305
|
+
s.issuerAuthState = zero$1;
|
|
56306
|
+
}
|
|
56307
|
+
// InputsMarshal returns Circom private inputs for credentialAtomicQueryV3.circom
|
|
56308
|
+
inputsMarshal() {
|
|
56309
|
+
this.validate();
|
|
56310
|
+
if (this.query.valueProof) {
|
|
56311
|
+
this.query.validate();
|
|
56312
|
+
this.query.valueProof.validate();
|
|
56313
|
+
}
|
|
56314
|
+
let valueProof = this.query.valueProof;
|
|
56315
|
+
if (!valueProof) {
|
|
56316
|
+
valueProof = new ValueProof();
|
|
56317
|
+
valueProof.path = 0n;
|
|
56318
|
+
valueProof.value = 0n;
|
|
56319
|
+
valueProof.mtp = new Proof();
|
|
56320
|
+
}
|
|
56321
|
+
let treeState = this.claim.nonRevProof.treeState;
|
|
56322
|
+
if (this.proofType === ProofType.BJJSignature && this.skipClaimRevocationCheck) {
|
|
56323
|
+
treeState = this.claim.signatureProof?.issuerAuthNonRevProof.treeState;
|
|
56324
|
+
}
|
|
56325
|
+
if (!treeState) {
|
|
56326
|
+
throw new Error(CircuitError.EmptyTreeState);
|
|
56327
|
+
}
|
|
56328
|
+
const s = {
|
|
56329
|
+
requestID: this.requestID.toString(),
|
|
56330
|
+
userGenesisID: this.id.bigInt().toString(),
|
|
56331
|
+
profileNonce: this.profileNonce.toString(),
|
|
56332
|
+
claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
|
|
56333
|
+
issuerID: this.claim.issuerID.bigInt().toString(),
|
|
56334
|
+
issuerClaim: this.claim.claim.marshalJson(),
|
|
56335
|
+
issuerClaimNonRevClaimsTreeRoot: treeState.claimsRoot.bigInt().toString(),
|
|
56336
|
+
issuerClaimNonRevRevTreeRoot: treeState.revocationRoot.bigInt().toString(),
|
|
56337
|
+
issuerClaimNonRevRootsTreeRoot: treeState.rootOfRoots.bigInt().toString(),
|
|
56338
|
+
issuerClaimNonRevState: treeState.state.bigInt().toString(),
|
|
56339
|
+
issuerClaimNonRevMtp: prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
|
|
56340
|
+
claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
|
|
56341
|
+
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
|
|
56342
|
+
claimPathValue: valueProof.value.toString(),
|
|
56343
|
+
operator: this.query.operator,
|
|
56344
|
+
timestamp: this.currentTimeStamp,
|
|
56345
|
+
// value in this path in merklized json-ld document
|
|
56346
|
+
slotIndex: this.query.slotIndex,
|
|
56347
|
+
isRevocationChecked: 1
|
|
56348
|
+
};
|
|
56349
|
+
if (this.skipClaimRevocationCheck) {
|
|
56350
|
+
s.isRevocationChecked = 0;
|
|
56351
|
+
}
|
|
56352
|
+
if (this.proofType === ProofType.BJJSignature) {
|
|
56353
|
+
s.proofType = '1';
|
|
56354
|
+
s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
|
|
56355
|
+
s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
|
|
56356
|
+
s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
|
|
56357
|
+
s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
|
|
56358
|
+
s.issuerAuthClaimMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthIncProof.proof, this.getMTLevel());
|
|
56359
|
+
s.issuerAuthClaimsTreeRoot = treeState.claimsRoot.bigInt().toString();
|
|
56360
|
+
s.issuerAuthRevTreeRoot = treeState.revocationRoot.bigInt().toString();
|
|
56361
|
+
s.issuerAuthRootsTreeRoot = treeState.rootOfRoots.bigInt().toString();
|
|
56362
|
+
s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthNonRevProof.proof, this.getMTLevel());
|
|
56363
|
+
const nodeAuxIssuerAuthNonRev = getNodeAuxValue(this.claim.signatureProof?.issuerAuthNonRevProof.proof);
|
|
56364
|
+
s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
|
|
56365
|
+
s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
|
|
56366
|
+
s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
|
|
56367
|
+
s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
|
|
56368
|
+
.bigInt()
|
|
56369
|
+
.toString();
|
|
56370
|
+
this.fillMTPProofsWithZero(s);
|
|
56371
|
+
}
|
|
56372
|
+
else if (this.proofType === ProofType.Iden3SparseMerkleTreeProof) {
|
|
56373
|
+
s.proofType = '2';
|
|
56374
|
+
const incProofTreeState = this.claim.incProof?.treeState;
|
|
56375
|
+
if (!incProofTreeState) {
|
|
56376
|
+
throw new Error(CircuitError.EmptyTreeState);
|
|
56377
|
+
}
|
|
56378
|
+
s.issuerClaimMtp = prepareSiblingsStr(this.claim.incProof?.proof, this.getMTLevel());
|
|
56379
|
+
s.issuerClaimClaimsTreeRoot = incProofTreeState.claimsRoot.bigInt().toString();
|
|
56380
|
+
s.issuerClaimRevTreeRoot = incProofTreeState.revocationRoot.bigInt().toString();
|
|
56381
|
+
s.issuerClaimRootsTreeRoot = incProofTreeState.rootOfRoots.bigInt().toString();
|
|
56382
|
+
s.issuerClaimIdenState = incProofTreeState.state.bigInt().toString();
|
|
56383
|
+
this.fillSigProofWithZero(s);
|
|
56384
|
+
}
|
|
56385
|
+
const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof.proof);
|
|
56386
|
+
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
|
|
56387
|
+
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
|
|
56388
|
+
s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
|
|
56389
|
+
s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
|
|
56390
|
+
const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
|
|
56391
|
+
s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
|
|
56392
|
+
s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
|
|
56393
|
+
s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
|
|
56394
|
+
s.claimPathKey = valueProof.path.toString();
|
|
56395
|
+
const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
|
|
56396
|
+
s.value = bigIntArrayToStringArray(values);
|
|
56397
|
+
s.linkNonce = this.linkNonce.toString();
|
|
56398
|
+
s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
|
|
56399
|
+
s.nullifierSessionID = this.nullifierSessionID.toString();
|
|
56400
|
+
return byteEncoder.encode(JSON.stringify(s));
|
|
56401
|
+
}
|
|
56402
|
+
}
|
|
56403
|
+
/**
|
|
56404
|
+
* @beta
|
|
56405
|
+
* AtomicQueryV3PubSignals public inputs
|
|
56406
|
+
*/
|
|
56407
|
+
class AtomicQueryV3PubSignals extends BaseConfig {
|
|
56408
|
+
constructor() {
|
|
56409
|
+
super(...arguments);
|
|
56410
|
+
this.value = [];
|
|
56411
|
+
}
|
|
56412
|
+
// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
|
|
56413
|
+
pubSignalsUnmarshal(data) {
|
|
56414
|
+
// expected order:
|
|
56415
|
+
// merklized
|
|
56416
|
+
// userID
|
|
56417
|
+
// issuerState
|
|
56418
|
+
// linkID
|
|
56419
|
+
// nullifier
|
|
56420
|
+
// operatorOutput
|
|
56421
|
+
// proofType
|
|
56422
|
+
// requestID
|
|
56423
|
+
// issuerID
|
|
56424
|
+
// isRevocationChecked
|
|
56425
|
+
// issuerClaimNonRevState
|
|
56426
|
+
// timestamp
|
|
56427
|
+
// claimSchema
|
|
56428
|
+
// claimPathNotExists
|
|
56429
|
+
// claimPathKey
|
|
56430
|
+
// slotIndex
|
|
56431
|
+
// operator
|
|
56432
|
+
// value
|
|
56433
|
+
// verifierID
|
|
56434
|
+
// nullifierSessionID
|
|
56435
|
+
// 19 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
|
|
56436
|
+
// it is length could be different base on the circuit configuration. The length could be modified by set value
|
|
56437
|
+
// in ValueArraySize
|
|
56438
|
+
const fieldLength = 19;
|
|
56439
|
+
const sVals = JSON.parse(byteDecoder.decode(data));
|
|
56440
|
+
if (sVals.length !== fieldLength + this.getValueArrSize()) {
|
|
56441
|
+
throw new Error(`invalid number of Output values expected ${fieldLength + this.getValueArrSize()} got ${sVals.length}`);
|
|
56442
|
+
}
|
|
56443
|
+
let fieldIdx = 0;
|
|
56444
|
+
// -- merklized
|
|
56445
|
+
this.merklized = parseInt(sVals[fieldIdx]);
|
|
56446
|
+
fieldIdx++;
|
|
56447
|
+
// - userID
|
|
56448
|
+
this.userID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
56449
|
+
fieldIdx++;
|
|
56450
|
+
// - issuerState
|
|
56451
|
+
this.issuerState = Hash$1.fromString(sVals[fieldIdx]);
|
|
56452
|
+
fieldIdx++;
|
|
56453
|
+
// - linkID
|
|
56454
|
+
this.linkID = BigInt(sVals[fieldIdx]);
|
|
56455
|
+
fieldIdx++;
|
|
56456
|
+
// - nullifier
|
|
56457
|
+
this.nullifier = BigInt(sVals[fieldIdx]);
|
|
56458
|
+
fieldIdx++;
|
|
56459
|
+
// - operatorOutput
|
|
56460
|
+
this.operatorOutput = BigInt(sVals[fieldIdx]);
|
|
56461
|
+
fieldIdx++;
|
|
56462
|
+
// - proofType
|
|
56463
|
+
this.proofType = parseInt(sVals[fieldIdx]);
|
|
56464
|
+
fieldIdx++;
|
|
56465
|
+
// - requestID
|
|
56466
|
+
this.requestID = BigInt(sVals[fieldIdx]);
|
|
56467
|
+
fieldIdx++;
|
|
56468
|
+
// - issuerID
|
|
56469
|
+
this.issuerID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
56470
|
+
fieldIdx++;
|
|
56471
|
+
// - isRevocationChecked
|
|
56472
|
+
this.isRevocationChecked = parseInt(sVals[fieldIdx]);
|
|
56473
|
+
fieldIdx++;
|
|
56474
|
+
// - issuerClaimNonRevState
|
|
56475
|
+
this.issuerClaimNonRevState = Hash$1.fromString(sVals[fieldIdx]);
|
|
56476
|
+
fieldIdx++;
|
|
56477
|
+
// - timestamp
|
|
56478
|
+
this.timestamp = parseInt(sVals[fieldIdx]);
|
|
56479
|
+
fieldIdx++;
|
|
56480
|
+
// - claimSchema
|
|
56481
|
+
this.claimSchema = SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
|
|
56482
|
+
fieldIdx++;
|
|
56483
|
+
// - ClaimPathNotExists
|
|
56484
|
+
this.claimPathNotExists = parseInt(sVals[fieldIdx]);
|
|
56485
|
+
fieldIdx++;
|
|
56486
|
+
// - ClaimPathKey
|
|
56487
|
+
this.claimPathKey = BigInt(sVals[fieldIdx]);
|
|
56488
|
+
fieldIdx++;
|
|
56489
|
+
// - slotIndex
|
|
56490
|
+
this.slotIndex = parseInt(sVals[fieldIdx]);
|
|
56491
|
+
fieldIdx++;
|
|
56492
|
+
// - operator
|
|
56493
|
+
this.operator = parseInt(sVals[fieldIdx]);
|
|
56494
|
+
fieldIdx++;
|
|
56495
|
+
// - values
|
|
56496
|
+
for (let index = 0; index < this.getValueArrSize(); index++) {
|
|
56497
|
+
this.value.push(BigInt(sVals[fieldIdx]));
|
|
56498
|
+
fieldIdx++;
|
|
56499
|
+
}
|
|
56500
|
+
// - verifierID
|
|
56501
|
+
if (sVals[fieldIdx] !== '0') {
|
|
56502
|
+
this.verifierID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
56503
|
+
}
|
|
56504
|
+
fieldIdx++;
|
|
56505
|
+
// - nullifierSessionID
|
|
56506
|
+
this.nullifierSessionID = BigInt(sVals[fieldIdx]);
|
|
56507
|
+
return this;
|
|
56508
|
+
}
|
|
56509
|
+
}
|
|
56510
|
+
|
|
56511
|
+
const zero = '0';
|
|
56512
|
+
/**
|
|
56513
|
+
* AtomicQueryV3OnChainInputs ZK private inputs for credentialAtomicQueryV3OnChain.circom
|
|
56514
|
+
*
|
|
56515
|
+
* @beta
|
|
56516
|
+
* @class AtomicQueryV3OnChainInputs
|
|
56517
|
+
* @extends {BaseConfig}
|
|
56518
|
+
*/
|
|
56519
|
+
class AtomicQueryV3OnChainInputs extends BaseConfig {
|
|
56520
|
+
validate() {
|
|
56521
|
+
if (!this.requestID) {
|
|
56522
|
+
throw new Error(CircuitError.EmptyRequestID);
|
|
56523
|
+
}
|
|
56524
|
+
if (!this.claim.nonRevProof.proof) {
|
|
56525
|
+
throw new Error(CircuitError.EmptyClaimNonRevProof);
|
|
56526
|
+
}
|
|
56527
|
+
if (!this.query.values) {
|
|
56528
|
+
throw new Error(CircuitError.EmptyQueryValue);
|
|
56529
|
+
}
|
|
56530
|
+
if (!this.proofType) {
|
|
56531
|
+
throw new Error(CircuitError.InvalidProofType);
|
|
56532
|
+
}
|
|
56533
|
+
if (!this.challenge) {
|
|
56534
|
+
throw new Error(CircuitError.EmptyChallenge);
|
|
56535
|
+
}
|
|
56536
|
+
if (this.authEnabled === 1) {
|
|
56537
|
+
if (!this.authClaimIncMtp) {
|
|
56538
|
+
throw new Error(CircuitError.EmptyAuthClaimProof);
|
|
56539
|
+
}
|
|
56540
|
+
if (!this.authClaimNonRevMtp) {
|
|
56541
|
+
throw new Error(CircuitError.EmptyAuthClaimNonRevProof);
|
|
56542
|
+
}
|
|
56543
|
+
if (!this.signature) {
|
|
56544
|
+
throw new Error(CircuitError.EmptyChallengeSignature);
|
|
56545
|
+
}
|
|
56546
|
+
if (!this.gistProof.proof) {
|
|
56547
|
+
throw new Error(CircuitError.EmptyGISTProof);
|
|
56548
|
+
}
|
|
56549
|
+
}
|
|
56550
|
+
if (this.proofType === ProofType.BJJSignature) {
|
|
56551
|
+
if (!this.claim.signatureProof?.issuerAuthIncProof.proof) {
|
|
56552
|
+
throw new Error(CircuitError.EmptyIssuerAuthClaimProof);
|
|
56553
|
+
}
|
|
56554
|
+
if (!this.claim.signatureProof.issuerAuthNonRevProof.proof) {
|
|
56555
|
+
throw new Error(CircuitError.EmptyIssuerAuthClaimNonRevProof);
|
|
56556
|
+
}
|
|
56557
|
+
if (!this.claim.signatureProof.signature) {
|
|
56558
|
+
throw new Error(CircuitError.EmptyClaimSignature);
|
|
56559
|
+
}
|
|
56560
|
+
}
|
|
56561
|
+
if (this.proofType === ProofType.Iden3SparseMerkleTreeProof) {
|
|
56562
|
+
if (!this.claim?.incProof?.proof) {
|
|
56563
|
+
throw new Error(CircuitError.EmptyClaimProof);
|
|
56564
|
+
}
|
|
56565
|
+
}
|
|
56566
|
+
}
|
|
56567
|
+
fillMTPProofsWithZero(s) {
|
|
56568
|
+
s.issuerClaimMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56569
|
+
s.issuerClaimClaimsTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56570
|
+
s.issuerClaimRevTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56571
|
+
s.issuerClaimRootsTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56572
|
+
s.issuerClaimIdenState = ZERO_HASH.bigInt().toString();
|
|
56573
|
+
}
|
|
56574
|
+
fillSigProofWithZero(s) {
|
|
56575
|
+
s.issuerClaimSignatureR8x = zero;
|
|
56576
|
+
s.issuerClaimSignatureR8y = zero;
|
|
56577
|
+
s.issuerClaimSignatureS = zero;
|
|
56578
|
+
s.issuerAuthClaim = new Claim().marshalJson();
|
|
56579
|
+
s.issuerAuthClaimMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56580
|
+
s.issuerAuthClaimsTreeRoot = zero;
|
|
56581
|
+
s.issuerAuthRevTreeRoot = zero;
|
|
56582
|
+
s.issuerAuthRootsTreeRoot = zero;
|
|
56583
|
+
s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56584
|
+
s.issuerAuthClaimNonRevMtpAuxHi = ZERO_HASH.bigInt().toString();
|
|
56585
|
+
s.issuerAuthClaimNonRevMtpAuxHv = ZERO_HASH.bigInt().toString();
|
|
56586
|
+
s.issuerAuthClaimNonRevMtpNoAux = zero;
|
|
56587
|
+
s.issuerAuthState = zero;
|
|
56588
|
+
}
|
|
56589
|
+
fillAuthWithZero(s) {
|
|
56590
|
+
s.authClaim = new Claim().marshalJson();
|
|
56591
|
+
s.userClaimsTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56592
|
+
s.userRevTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56593
|
+
s.userRootsTreeRoot = ZERO_HASH.bigInt().toString();
|
|
56594
|
+
s.userState = ZERO_HASH.bigInt().toString();
|
|
56595
|
+
s.authClaimIncMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56596
|
+
s.authClaimNonRevMtp = prepareSiblingsStr(new Proof(), this.getMTLevel());
|
|
56597
|
+
s.challengeSignatureR8x = zero;
|
|
56598
|
+
s.challengeSignatureR8y = zero;
|
|
56599
|
+
s.challengeSignatureS = zero;
|
|
56600
|
+
s.gistRoot = ZERO_HASH.bigInt().toString();
|
|
56601
|
+
s.gistMtp = prepareSiblingsStr(new Proof(), this.getMTLevelOnChain());
|
|
56602
|
+
s.authClaimNonRevMtpAuxHi = ZERO_HASH.bigInt().toString();
|
|
56603
|
+
s.authClaimNonRevMtpAuxHv = ZERO_HASH.bigInt().toString();
|
|
56604
|
+
s.authClaimNonRevMtpNoAux = zero;
|
|
56605
|
+
s.gistMtpAuxHi = ZERO_HASH.bigInt().toString();
|
|
56606
|
+
s.gistMtpAuxHv = ZERO_HASH.bigInt().toString();
|
|
56607
|
+
s.gistMtpNoAux = zero;
|
|
56608
|
+
}
|
|
56609
|
+
// InputsMarshal returns Circom private inputs for credentialAtomicQueryV3OnChain.circom
|
|
56610
|
+
inputsMarshal() {
|
|
56611
|
+
this.validate();
|
|
56612
|
+
if (this.query.valueProof) {
|
|
56613
|
+
this.query.validate();
|
|
56614
|
+
this.query.valueProof.validate();
|
|
56615
|
+
}
|
|
56616
|
+
let valueProof = this.query.valueProof;
|
|
56617
|
+
if (!valueProof) {
|
|
56618
|
+
valueProof = new ValueProof();
|
|
56619
|
+
valueProof.path = 0n;
|
|
56620
|
+
valueProof.value = 0n;
|
|
56621
|
+
valueProof.mtp = new Proof();
|
|
56622
|
+
}
|
|
56623
|
+
const treeState = this.claim.nonRevProof.treeState;
|
|
56624
|
+
if (!treeState) {
|
|
56625
|
+
throw new Error(CircuitError.EmptyTreeState);
|
|
56626
|
+
}
|
|
56627
|
+
const s = {
|
|
56628
|
+
requestID: this.requestID.toString(),
|
|
56629
|
+
userGenesisID: this.id.bigInt().toString(),
|
|
56630
|
+
profileNonce: this.profileNonce.toString(),
|
|
56631
|
+
claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
|
|
56632
|
+
issuerID: this.claim.issuerID.bigInt().toString(),
|
|
56633
|
+
issuerClaim: this.claim.claim.marshalJson(),
|
|
56634
|
+
issuerClaimNonRevClaimsTreeRoot: treeState.claimsRoot.bigInt().toString(),
|
|
56635
|
+
issuerClaimNonRevRevTreeRoot: treeState.revocationRoot.bigInt().toString(),
|
|
56636
|
+
issuerClaimNonRevRootsTreeRoot: treeState.rootOfRoots.bigInt().toString(),
|
|
56637
|
+
issuerClaimNonRevState: treeState.state.bigInt().toString(),
|
|
56638
|
+
issuerClaimNonRevMtp: prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
|
|
56639
|
+
claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
|
|
56640
|
+
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
|
|
56641
|
+
claimPathValue: valueProof.value.toString(),
|
|
56642
|
+
operator: this.query.operator,
|
|
56643
|
+
timestamp: this.currentTimeStamp,
|
|
56644
|
+
// value in this path in merklized json-ld document
|
|
56645
|
+
slotIndex: this.query.slotIndex,
|
|
56646
|
+
isRevocationChecked: 1
|
|
56647
|
+
};
|
|
56648
|
+
s.challenge = this.challenge?.toString();
|
|
56649
|
+
if (this.authEnabled === 1) {
|
|
56650
|
+
s.authClaim = this.authClaim?.marshalJson();
|
|
56651
|
+
s.userClaimsTreeRoot = this.treeState.claimsRoot?.bigInt().toString();
|
|
56652
|
+
s.userRevTreeRoot = this.treeState.revocationRoot?.bigInt().toString();
|
|
56653
|
+
s.userRootsTreeRoot = this.treeState.rootOfRoots?.bigInt().toString();
|
|
56654
|
+
s.userState = this.treeState.state?.bigInt().toString();
|
|
56655
|
+
s.authClaimIncMtp = prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel());
|
|
56656
|
+
s.authClaimNonRevMtp = prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel());
|
|
56657
|
+
s.challengeSignatureR8x = this.signature.R8[0].toString();
|
|
56658
|
+
s.challengeSignatureR8y = this.signature.R8[1].toString();
|
|
56659
|
+
s.challengeSignatureS = this.signature.S.toString();
|
|
56660
|
+
s.gistMtp =
|
|
56661
|
+
this.gistProof && prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain());
|
|
56662
|
+
const nodeAuxAuth = getNodeAuxValue(this.authClaimNonRevMtp);
|
|
56663
|
+
s.authClaimNonRevMtpAuxHi = nodeAuxAuth.key.bigInt().toString();
|
|
56664
|
+
s.authClaimNonRevMtpAuxHv = nodeAuxAuth.value.bigInt().toString();
|
|
56665
|
+
s.authClaimNonRevMtpNoAux = nodeAuxAuth.noAux;
|
|
56666
|
+
const globalNodeAux = getNodeAuxValue(this.gistProof.proof);
|
|
56667
|
+
s.gistMtpAuxHi = globalNodeAux.key.bigInt().toString();
|
|
56668
|
+
s.gistMtpAuxHv = globalNodeAux.value.bigInt().toString();
|
|
56669
|
+
s.gistMtpNoAux = globalNodeAux.noAux;
|
|
56670
|
+
s.gistRoot = this.gistProof.root.bigInt().toString();
|
|
56671
|
+
}
|
|
56672
|
+
else {
|
|
56673
|
+
this.fillAuthWithZero(s);
|
|
56674
|
+
}
|
|
56675
|
+
if (this.skipClaimRevocationCheck) {
|
|
56676
|
+
s.isRevocationChecked = 0;
|
|
56677
|
+
}
|
|
56678
|
+
if (this.proofType === ProofType.BJJSignature) {
|
|
56679
|
+
s.proofType = '1';
|
|
56680
|
+
s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
|
|
56681
|
+
s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
|
|
56682
|
+
s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
|
|
56683
|
+
s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
|
|
56684
|
+
s.issuerAuthClaimMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthIncProof.proof, this.getMTLevel());
|
|
56685
|
+
const issuerAuthTreeState = this.claim.nonRevProof.treeState;
|
|
56686
|
+
if (!issuerAuthTreeState) {
|
|
56687
|
+
throw new Error(CircuitError.EmptyTreeState);
|
|
56688
|
+
}
|
|
56689
|
+
s.issuerAuthClaimsTreeRoot = issuerAuthTreeState.claimsRoot.bigInt().toString();
|
|
56690
|
+
s.issuerAuthRevTreeRoot = issuerAuthTreeState.revocationRoot.bigInt().toString();
|
|
56691
|
+
s.issuerAuthRootsTreeRoot = issuerAuthTreeState.rootOfRoots.bigInt().toString();
|
|
56692
|
+
s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthNonRevProof.proof, this.getMTLevel());
|
|
56693
|
+
const nodeAuxIssuerAuthNonRev = getNodeAuxValue(this.claim.signatureProof?.issuerAuthNonRevProof.proof);
|
|
56694
|
+
s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
|
|
56695
|
+
s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
|
|
56696
|
+
s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
|
|
56697
|
+
s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
|
|
56698
|
+
.bigInt()
|
|
56699
|
+
.toString();
|
|
56700
|
+
this.fillMTPProofsWithZero(s);
|
|
56701
|
+
}
|
|
56702
|
+
else if (this.proofType === ProofType.Iden3SparseMerkleTreeProof) {
|
|
56703
|
+
s.proofType = '2';
|
|
56704
|
+
const incProofTreeState = this.claim.incProof?.treeState;
|
|
56705
|
+
if (!incProofTreeState) {
|
|
56706
|
+
throw new Error(CircuitError.EmptyTreeState);
|
|
56707
|
+
}
|
|
56708
|
+
s.issuerClaimMtp = prepareSiblingsStr(this.claim.incProof?.proof, this.getMTLevel());
|
|
56709
|
+
s.issuerClaimClaimsTreeRoot = incProofTreeState.claimsRoot.bigInt().toString();
|
|
56710
|
+
s.issuerClaimRevTreeRoot = incProofTreeState.revocationRoot.bigInt().toString();
|
|
56711
|
+
s.issuerClaimRootsTreeRoot = incProofTreeState.rootOfRoots.bigInt().toString();
|
|
56712
|
+
s.issuerClaimIdenState = incProofTreeState.state.bigInt().toString();
|
|
56713
|
+
this.fillSigProofWithZero(s);
|
|
56714
|
+
}
|
|
56715
|
+
const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof.proof);
|
|
56716
|
+
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
|
|
56717
|
+
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
|
|
56718
|
+
s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
|
|
56719
|
+
s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
|
|
56720
|
+
const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
|
|
56721
|
+
s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
|
|
56722
|
+
s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
|
|
56723
|
+
s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
|
|
56724
|
+
s.claimPathKey = valueProof.path.toString();
|
|
56725
|
+
const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
|
|
56726
|
+
s.value = bigIntArrayToStringArray(values);
|
|
56727
|
+
s.linkNonce = this.linkNonce.toString();
|
|
56728
|
+
s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
|
|
56729
|
+
s.nullifierSessionID = this.nullifierSessionID.toString();
|
|
56730
|
+
s.authEnabled = this.authEnabled.toString();
|
|
56731
|
+
return byteEncoder.encode(JSON.stringify(s));
|
|
56732
|
+
}
|
|
56733
|
+
}
|
|
56734
|
+
/**
|
|
56735
|
+
* @beta
|
|
56736
|
+
* AtomicQueryV3OnChainPubSignals public inputs
|
|
56737
|
+
*/
|
|
56738
|
+
class AtomicQueryV3OnChainPubSignals extends BaseConfig {
|
|
56739
|
+
// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
|
|
56740
|
+
pubSignalsUnmarshal(data) {
|
|
56741
|
+
// expected order:
|
|
56742
|
+
// merklized
|
|
56743
|
+
// userID
|
|
56744
|
+
// circuitQueryHash
|
|
56745
|
+
// issuerState
|
|
56746
|
+
// linkID
|
|
56747
|
+
// nullifier
|
|
56748
|
+
// operatorOutput
|
|
56749
|
+
// proofType
|
|
56750
|
+
// requestID
|
|
56751
|
+
// challenge
|
|
56752
|
+
// gistRoot
|
|
56753
|
+
// issuerID
|
|
56754
|
+
// isRevocationChecked
|
|
56755
|
+
// issuerClaimNonRevState
|
|
56756
|
+
// timestamp
|
|
56757
|
+
// verifierID
|
|
56758
|
+
// nullifierSessionID
|
|
56759
|
+
// authEnabled
|
|
56760
|
+
const sVals = JSON.parse(byteDecoder.decode(data));
|
|
56761
|
+
let fieldIdx = 0;
|
|
56762
|
+
// -- merklized
|
|
56763
|
+
this.merklized = parseInt(sVals[fieldIdx]);
|
|
56764
|
+
fieldIdx++;
|
|
56765
|
+
// - userID
|
|
56766
|
+
this.userID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
56767
|
+
fieldIdx++;
|
|
56768
|
+
// - circuitQueryHash
|
|
56769
|
+
this.circuitQueryHash = BigInt(sVals[fieldIdx]);
|
|
56770
|
+
fieldIdx++;
|
|
56771
|
+
// - issuerState
|
|
56772
|
+
this.issuerState = Hash$1.fromString(sVals[fieldIdx]);
|
|
56773
|
+
fieldIdx++;
|
|
56774
|
+
// - linkID
|
|
56775
|
+
this.linkID = BigInt(sVals[fieldIdx]);
|
|
56776
|
+
fieldIdx++;
|
|
56777
|
+
// - nullifier
|
|
56778
|
+
this.nullifier = BigInt(sVals[fieldIdx]);
|
|
56779
|
+
fieldIdx++;
|
|
56780
|
+
// - operatorOutput
|
|
56781
|
+
this.operatorOutput = BigInt(sVals[fieldIdx]);
|
|
56782
|
+
fieldIdx++;
|
|
56783
|
+
// - proofType
|
|
56784
|
+
this.proofType = parseInt(sVals[fieldIdx]);
|
|
56785
|
+
fieldIdx++;
|
|
56786
|
+
// - requestID
|
|
56787
|
+
this.requestID = BigInt(sVals[fieldIdx]);
|
|
56788
|
+
fieldIdx++;
|
|
56789
|
+
// - challenge
|
|
56790
|
+
this.challenge = BigInt(sVals[fieldIdx]);
|
|
56791
|
+
fieldIdx++;
|
|
56792
|
+
// - gistRoot
|
|
56793
|
+
this.gistRoot = Hash$1.fromString(sVals[fieldIdx]);
|
|
56794
|
+
fieldIdx++;
|
|
56795
|
+
// - issuerID
|
|
56796
|
+
this.issuerID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
56797
|
+
fieldIdx++;
|
|
56798
|
+
// - isRevocationChecked
|
|
56799
|
+
this.isRevocationChecked = parseInt(sVals[fieldIdx]);
|
|
56800
|
+
fieldIdx++;
|
|
56801
|
+
// - issuerClaimNonRevState
|
|
56802
|
+
this.issuerClaimNonRevState = Hash$1.fromString(sVals[fieldIdx]);
|
|
56803
|
+
fieldIdx++;
|
|
56804
|
+
// - timestamp
|
|
56805
|
+
this.timestamp = parseInt(sVals[fieldIdx]);
|
|
56806
|
+
fieldIdx++;
|
|
56807
|
+
// - verifierID
|
|
56808
|
+
if (sVals[fieldIdx] !== '0') {
|
|
56809
|
+
this.verifierID = Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
56810
|
+
}
|
|
56811
|
+
fieldIdx++;
|
|
56812
|
+
// - nullifierSessionID
|
|
56813
|
+
this.nullifierSessionID = BigInt(sVals[fieldIdx]);
|
|
56814
|
+
fieldIdx++;
|
|
56815
|
+
// - authEnabled
|
|
56816
|
+
this.authEnabled = parseInt(sVals[fieldIdx]);
|
|
56817
|
+
return this;
|
|
56818
|
+
}
|
|
56819
|
+
}
|
|
56820
|
+
|
|
56114
56821
|
/**
|
|
56115
56822
|
* AtomicQuerySigV2OnChainInputs ZK private inputs for credentialAtomicQuerySig.circom
|
|
56116
56823
|
*
|
|
@@ -56208,9 +56915,9 @@ class AtomicQuerySigV2OnChainInputs extends BaseConfig {
|
|
|
56208
56915
|
issuerAuthClaimNonRevMtp: this.claim.signatureProof?.issuerAuthNonRevProof?.proof &&
|
|
56209
56916
|
prepareSiblingsStr(this.claim.signatureProof.issuerAuthNonRevProof.proof, this.getMTLevel()),
|
|
56210
56917
|
claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
|
|
56211
|
-
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.
|
|
56918
|
+
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
|
|
56212
56919
|
claimPathValue: valueProof.value.toString(),
|
|
56213
|
-
operator: this.query
|
|
56920
|
+
operator: this.query.operator,
|
|
56214
56921
|
timestamp: this.currentTimeStamp,
|
|
56215
56922
|
// value in this path in merklized json-ld document
|
|
56216
56923
|
slotIndex: this.query?.slotIndex,
|
|
@@ -56506,6 +57213,179 @@ class StateTransitionPubSignals {
|
|
|
56506
57213
|
}
|
|
56507
57214
|
}
|
|
56508
57215
|
|
|
57216
|
+
/**
|
|
57217
|
+
* LinkedNullifier circuit representation
|
|
57218
|
+
* Inputs and public signals declaration, marshalling and parsing
|
|
57219
|
+
*
|
|
57220
|
+
* @beta
|
|
57221
|
+
* @class LinkedNullifierInputs
|
|
57222
|
+
*/
|
|
57223
|
+
class LinkedNullifierInputs {
|
|
57224
|
+
// InputsMarshal returns Circom private inputs for nullifier.circom
|
|
57225
|
+
inputsMarshal() {
|
|
57226
|
+
const s = {
|
|
57227
|
+
linkNonce: this.linkNonce.toString(),
|
|
57228
|
+
issuerClaim: this.issuerClaim.marshalJson(),
|
|
57229
|
+
userGenesisID: this.id.bigInt().toString(),
|
|
57230
|
+
claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
|
|
57231
|
+
claimSchema: this.issuerClaim.getSchemaHash().bigInt().toString(),
|
|
57232
|
+
verifierID: this.verifierID?.bigInt().toString() ?? '0',
|
|
57233
|
+
nullifierSessionID: this.nullifierSessionID.toString()
|
|
57234
|
+
};
|
|
57235
|
+
return byteEncoder.encode(JSON.stringify(s));
|
|
57236
|
+
}
|
|
57237
|
+
}
|
|
57238
|
+
// LinkedNullifierPubSignals nullifier.circom public signals
|
|
57239
|
+
/**
|
|
57240
|
+
* public signals
|
|
57241
|
+
*
|
|
57242
|
+
* @beta
|
|
57243
|
+
* @class LinkedNullifierPubSignals
|
|
57244
|
+
*/
|
|
57245
|
+
class LinkedNullifierPubSignals {
|
|
57246
|
+
/**
|
|
57247
|
+
* PubSignalsUnmarshal unmarshal nullifier.circom public inputs to LinkedNullifierPubSignals
|
|
57248
|
+
*
|
|
57249
|
+
* @beta
|
|
57250
|
+
* @param {Uint8Array} data
|
|
57251
|
+
* @returns LinkedNullifierPubSignals
|
|
57252
|
+
*/
|
|
57253
|
+
pubSignalsUnmarshal(data) {
|
|
57254
|
+
const len = 4;
|
|
57255
|
+
const sVals = JSON.parse(byteDecoder.decode(data));
|
|
57256
|
+
if (sVals.length !== len) {
|
|
57257
|
+
throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
|
|
57258
|
+
}
|
|
57259
|
+
this.nullifier = BigInt(sVals[0]);
|
|
57260
|
+
this.linkID = BigInt(sVals[1]);
|
|
57261
|
+
this.verifierID = Id.fromBigInt(BigInt(sVals[2]));
|
|
57262
|
+
this.nullifierSessionID = BigInt(sVals[3]);
|
|
57263
|
+
return this;
|
|
57264
|
+
}
|
|
57265
|
+
}
|
|
57266
|
+
|
|
57267
|
+
/**
|
|
57268
|
+
* LinkedMultiQuery circuit representation
|
|
57269
|
+
* Inputs and public signals declaration, marshalling and parsing
|
|
57270
|
+
*
|
|
57271
|
+
* @beta
|
|
57272
|
+
* @class LinkedMultiQueryInputs
|
|
57273
|
+
*/
|
|
57274
|
+
class LinkedMultiQueryInputs extends BaseConfig {
|
|
57275
|
+
// InputsMarshal returns Circom private inputs for linkedMultiQueryInputs.circom
|
|
57276
|
+
inputsMarshal() {
|
|
57277
|
+
const enabled = [];
|
|
57278
|
+
const claimPathNotExists = [];
|
|
57279
|
+
const claimPathMtp = [];
|
|
57280
|
+
const claimPathMtpNoAux = [];
|
|
57281
|
+
const claimPathMtpAuxHi = [];
|
|
57282
|
+
const claimPathMtpAuxHv = [];
|
|
57283
|
+
const claimPathKey = [];
|
|
57284
|
+
const claimPathValue = [];
|
|
57285
|
+
const slotIndex = [];
|
|
57286
|
+
const operator = [];
|
|
57287
|
+
const value = [];
|
|
57288
|
+
for (let i = 0; i < this.queryLength; i++) {
|
|
57289
|
+
if (!this.query) {
|
|
57290
|
+
enabled.push(0);
|
|
57291
|
+
claimPathNotExists.push(0);
|
|
57292
|
+
claimPathMtp.push([]);
|
|
57293
|
+
claimPathMtpNoAux.push('0');
|
|
57294
|
+
claimPathMtpAuxHi.push('0');
|
|
57295
|
+
claimPathMtpAuxHv.push('0');
|
|
57296
|
+
claimPathKey.push('0');
|
|
57297
|
+
claimPathValue.push('0');
|
|
57298
|
+
slotIndex.push(0);
|
|
57299
|
+
operator.push(0);
|
|
57300
|
+
const valuesArr = prepareCircuitArrayValues([], this.getValueArrSize());
|
|
57301
|
+
value.push(bigIntArrayToStringArray(valuesArr));
|
|
57302
|
+
continue;
|
|
57303
|
+
}
|
|
57304
|
+
enabled.push(1);
|
|
57305
|
+
const valueProof = this.query[i].valueProof;
|
|
57306
|
+
claimPathNotExists.push(existenceToInt(valueProof.mtp.existence));
|
|
57307
|
+
claimPathMtp.push(prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()));
|
|
57308
|
+
const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
|
|
57309
|
+
claimPathMtpNoAux.push(nodAuxJSONLD.noAux);
|
|
57310
|
+
claimPathMtpAuxHi.push(nodAuxJSONLD.key.bigInt().toString());
|
|
57311
|
+
claimPathMtpAuxHv.push(nodAuxJSONLD.value.bigInt().toString());
|
|
57312
|
+
claimPathKey.push(valueProof.path.toString());
|
|
57313
|
+
claimPathValue.push(valueProof.value.toString());
|
|
57314
|
+
slotIndex.push(this.query[i].slotIndex);
|
|
57315
|
+
operator.push(this.query[i].operator);
|
|
57316
|
+
const valuesArr = prepareCircuitArrayValues(this.query[i].values, this.getValueArrSize());
|
|
57317
|
+
value.push(bigIntArrayToStringArray(valuesArr));
|
|
57318
|
+
}
|
|
57319
|
+
const s = {
|
|
57320
|
+
linkNonce: this.linkNonce.toString(),
|
|
57321
|
+
issuerClaim: this.claim.marshalJson(),
|
|
57322
|
+
enabled,
|
|
57323
|
+
claimSchema: this.claim.getSchemaHash().bigInt().toString(),
|
|
57324
|
+
claimPathNotExists,
|
|
57325
|
+
claimPathMtp,
|
|
57326
|
+
claimPathMtpNoAux,
|
|
57327
|
+
claimPathMtpAuxHi,
|
|
57328
|
+
claimPathMtpAuxHv,
|
|
57329
|
+
claimPathKey,
|
|
57330
|
+
claimPathValue,
|
|
57331
|
+
slotIndex,
|
|
57332
|
+
operator,
|
|
57333
|
+
value
|
|
57334
|
+
};
|
|
57335
|
+
return byteEncoder.encode(JSON.stringify(s));
|
|
57336
|
+
}
|
|
57337
|
+
}
|
|
57338
|
+
// LinkedMultiQueryPubSignals linkedMultiQuery.circom public signals
|
|
57339
|
+
/**
|
|
57340
|
+
* public signals
|
|
57341
|
+
*
|
|
57342
|
+
* @beta
|
|
57343
|
+
* @class LinkedMultiQueryPubSignals
|
|
57344
|
+
*/
|
|
57345
|
+
class LinkedMultiQueryPubSignals {
|
|
57346
|
+
/**
|
|
57347
|
+
* PubSignalsUnmarshal unmarshal linkedMultiQuery.circom public inputs to LinkedMultiQueryPubSignals
|
|
57348
|
+
*
|
|
57349
|
+
* @beta
|
|
57350
|
+
* @param {Uint8Array} data
|
|
57351
|
+
* @returns LinkedMultiQueryPubSignals
|
|
57352
|
+
*/
|
|
57353
|
+
pubSignalsUnmarshal(data, queryLength) {
|
|
57354
|
+
const len = queryLength * 3 + 2;
|
|
57355
|
+
const sVals = JSON.parse(byteDecoder.decode(data));
|
|
57356
|
+
if (sVals.length !== len) {
|
|
57357
|
+
throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
|
|
57358
|
+
}
|
|
57359
|
+
let fieldIdx = 0;
|
|
57360
|
+
// -- linkID
|
|
57361
|
+
this.linkID = BigInt(sVals[fieldIdx]);
|
|
57362
|
+
fieldIdx++;
|
|
57363
|
+
// -- merklized
|
|
57364
|
+
this.merklized = parseInt(sVals[fieldIdx]);
|
|
57365
|
+
fieldIdx++;
|
|
57366
|
+
// - operatorOutput
|
|
57367
|
+
this.operatorOutput = [];
|
|
57368
|
+
for (let i = 0; i < queryLength; i++) {
|
|
57369
|
+
this.operatorOutput.push(BigInt(sVals[fieldIdx]));
|
|
57370
|
+
fieldIdx++;
|
|
57371
|
+
}
|
|
57372
|
+
// - circuitQueryHash
|
|
57373
|
+
this.circuitQueryHash = [];
|
|
57374
|
+
for (let i = 0; i < queryLength; i++) {
|
|
57375
|
+
this.circuitQueryHash.push(BigInt(sVals[fieldIdx]));
|
|
57376
|
+
fieldIdx++;
|
|
57377
|
+
}
|
|
57378
|
+
// - enabled
|
|
57379
|
+
this.enabled = [];
|
|
57380
|
+
for (let i = 0; i < queryLength; i++) {
|
|
57381
|
+
const enabledNum = parseInt(sVals[fieldIdx]);
|
|
57382
|
+
this.enabled.push(enabledNum === 1);
|
|
57383
|
+
fieldIdx++;
|
|
57384
|
+
}
|
|
57385
|
+
return this;
|
|
57386
|
+
}
|
|
57387
|
+
}
|
|
57388
|
+
|
|
56509
57389
|
var abi$1 = [
|
|
56510
57390
|
{
|
|
56511
57391
|
inputs: [
|
|
@@ -58260,6 +59140,25 @@ function buildRevocationMessageRequest(from, to, revocationNonce) {
|
|
|
58260
59140
|
};
|
|
58261
59141
|
}
|
|
58262
59142
|
|
|
59143
|
+
/**
|
|
59144
|
+
* Retrieves the user DID from a given credential.
|
|
59145
|
+
* If the credential does not have a credentialSubject.id property, the issuer DID is returned.
|
|
59146
|
+
* If the credentialSubject.id is not a string, an error is thrown.
|
|
59147
|
+
* @param issuerDID The DID of the issuer.
|
|
59148
|
+
* @param credential The credential object.
|
|
59149
|
+
* @returns The user DID parsed from the credential.
|
|
59150
|
+
* @throws Error if the credentialSubject.id is not a string.
|
|
59151
|
+
*/
|
|
59152
|
+
const getUserDIDFromCredential = (issuerDID, credential) => {
|
|
59153
|
+
if (!credential.credentialSubject.id) {
|
|
59154
|
+
return issuerDID;
|
|
59155
|
+
}
|
|
59156
|
+
if (typeof credential.credentialSubject.id !== 'string') {
|
|
59157
|
+
throw new Error('credential subject `id` is not a string');
|
|
59158
|
+
}
|
|
59159
|
+
return DID.parse(credential.credentialSubject.id);
|
|
59160
|
+
};
|
|
59161
|
+
|
|
58263
59162
|
// ErrAllClaimsRevoked all claims are revoked.
|
|
58264
59163
|
const ErrAllClaimsRevoked = 'all claims are revoked';
|
|
58265
59164
|
/**
|
|
@@ -58355,16 +59254,7 @@ class CredentialWallet {
|
|
|
58355
59254
|
? mtpProof.issuerData.state
|
|
58356
59255
|
: sigProof?.issuerData.state;
|
|
58357
59256
|
const issuerDID = DID.parse(cred.issuer);
|
|
58358
|
-
|
|
58359
|
-
if (!cred.credentialSubject.id) {
|
|
58360
|
-
userDID = issuerDID;
|
|
58361
|
-
}
|
|
58362
|
-
else {
|
|
58363
|
-
if (typeof cred.credentialSubject.id !== 'string') {
|
|
58364
|
-
throw new Error('credential status `id` is not a string');
|
|
58365
|
-
}
|
|
58366
|
-
userDID = DID.parse(cred.credentialSubject.id);
|
|
58367
|
-
}
|
|
59257
|
+
const userDID = getUserDIDFromCredential(issuerDID, cred);
|
|
58368
59258
|
const opts = {
|
|
58369
59259
|
issuerGenesisState: stateInfo,
|
|
58370
59260
|
issuerDID,
|
|
@@ -59407,6 +60297,17 @@ var SearchError;
|
|
|
59407
60297
|
const truthyValues = [true, 1, 'true'];
|
|
59408
60298
|
const falsyValues = [false, 0, 'false'];
|
|
59409
60299
|
const equalsComparator = (a, b) => {
|
|
60300
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
60301
|
+
return (a.length === b.length && a.every((val, index) => val === b[index]));
|
|
60302
|
+
}
|
|
60303
|
+
if (!Array.isArray(a) && Array.isArray(b)) {
|
|
60304
|
+
return b.includes(a);
|
|
60305
|
+
}
|
|
60306
|
+
if (Array.isArray(a) && !Array.isArray(b)) {
|
|
60307
|
+
return a.includes(b);
|
|
60308
|
+
}
|
|
60309
|
+
a = a;
|
|
60310
|
+
b = b;
|
|
59410
60311
|
if (truthyValues.includes(a) && truthyValues.includes(b)) {
|
|
59411
60312
|
return true;
|
|
59412
60313
|
}
|
|
@@ -59415,14 +60316,65 @@ const equalsComparator = (a, b) => {
|
|
|
59415
60316
|
}
|
|
59416
60317
|
return a === b;
|
|
59417
60318
|
};
|
|
60319
|
+
const greaterThan = (a, b) => {
|
|
60320
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
60321
|
+
return a.every((val, index) => val > b[index]);
|
|
60322
|
+
}
|
|
60323
|
+
if (!Array.isArray(a) && Array.isArray(b)) {
|
|
60324
|
+
return b.every((val) => a > val);
|
|
60325
|
+
}
|
|
60326
|
+
if (Array.isArray(a) && !Array.isArray(b)) {
|
|
60327
|
+
return a.every((val) => val > b);
|
|
60328
|
+
}
|
|
60329
|
+
return a > b;
|
|
60330
|
+
};
|
|
60331
|
+
const greaterThanOrEqual = (a, b) => {
|
|
60332
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
60333
|
+
return a.every((val, index) => val >= b[index]);
|
|
60334
|
+
}
|
|
60335
|
+
if (!Array.isArray(a) && Array.isArray(b)) {
|
|
60336
|
+
return b.every((val) => a >= val);
|
|
60337
|
+
}
|
|
60338
|
+
if (Array.isArray(a) && !Array.isArray(b)) {
|
|
60339
|
+
return a.every((val) => val >= b);
|
|
60340
|
+
}
|
|
60341
|
+
return a >= b;
|
|
60342
|
+
};
|
|
60343
|
+
const lessThanOrEqual = (a, b) => {
|
|
60344
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
60345
|
+
return a.every((val, index) => val <= b[index]);
|
|
60346
|
+
}
|
|
60347
|
+
if (!Array.isArray(a) && Array.isArray(b)) {
|
|
60348
|
+
return b.every((val) => a <= val);
|
|
60349
|
+
}
|
|
60350
|
+
if (Array.isArray(a) && !Array.isArray(b)) {
|
|
60351
|
+
return a.every((val) => val <= b);
|
|
60352
|
+
}
|
|
60353
|
+
return a <= b;
|
|
60354
|
+
};
|
|
60355
|
+
const inOperator = (a, b) => {
|
|
60356
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
60357
|
+
return a.every((val) => b.includes(val));
|
|
60358
|
+
}
|
|
60359
|
+
if (!Array.isArray(a) && Array.isArray(b)) {
|
|
60360
|
+
return b.includes(a);
|
|
60361
|
+
}
|
|
60362
|
+
if (Array.isArray(a) && !Array.isArray(b)) {
|
|
60363
|
+
return a.includes(b);
|
|
60364
|
+
}
|
|
60365
|
+
return false;
|
|
60366
|
+
};
|
|
59418
60367
|
const comparatorOptions = {
|
|
59419
60368
|
$noop: () => true,
|
|
60369
|
+
$sd: () => true,
|
|
59420
60370
|
$eq: (a, b) => equalsComparator(a, b),
|
|
59421
|
-
$in: (a, b) =>
|
|
59422
|
-
$nin: (a, b) => !
|
|
59423
|
-
$gt: (a, b) => a
|
|
59424
|
-
$lt: (a, b) => a
|
|
59425
|
-
$ne: (a, b) => !equalsComparator(a, b)
|
|
60371
|
+
$in: (a, b) => inOperator(a, b),
|
|
60372
|
+
$nin: (a, b) => !inOperator(a, b),
|
|
60373
|
+
$gt: (a, b) => greaterThan(a, b),
|
|
60374
|
+
$lt: (a, b) => !greaterThan(a, b),
|
|
60375
|
+
$ne: (a, b) => !equalsComparator(a, b),
|
|
60376
|
+
$gte: (a, b) => greaterThanOrEqual(a, b),
|
|
60377
|
+
$lte: (a, b) => lessThanOrEqual(a, b)
|
|
59426
60378
|
};
|
|
59427
60379
|
/**
|
|
59428
60380
|
* credential search path resolver
|
|
@@ -59506,8 +60458,6 @@ const StandardJSONCredentialsQueryFilter = (query) => {
|
|
|
59506
60458
|
return acc.concat(new FilterQuery('credentialSubject.id', comparatorOptions.$eq, queryValue));
|
|
59507
60459
|
case 'schema':
|
|
59508
60460
|
return acc.concat(new FilterQuery('credentialSchema.id', comparatorOptions.$eq, queryValue));
|
|
59509
|
-
case 'skipClaimRevocationCheck':
|
|
59510
|
-
return acc;
|
|
59511
60461
|
case 'credentialSubject': {
|
|
59512
60462
|
const reqFilters = Object.keys(queryValue).reduce((acc, fieldKey) => {
|
|
59513
60463
|
const fieldParams = queryValue[fieldKey];
|
|
@@ -59525,8 +60475,13 @@ const StandardJSONCredentialsQueryFilter = (query) => {
|
|
|
59525
60475
|
}, []);
|
|
59526
60476
|
return acc.concat(reqFilters);
|
|
59527
60477
|
}
|
|
60478
|
+
case 'proofType':
|
|
60479
|
+
case 'groupId':
|
|
60480
|
+
case 'skipClaimRevocationCheck': {
|
|
60481
|
+
return acc;
|
|
60482
|
+
}
|
|
59528
60483
|
default:
|
|
59529
|
-
throw new Error(SearchError.NotDefinedQueryKey);
|
|
60484
|
+
throw new Error(`${queryKey} : ${SearchError.NotDefinedQueryKey}`);
|
|
59530
60485
|
}
|
|
59531
60486
|
}, []);
|
|
59532
60487
|
};
|
|
@@ -60225,6 +61180,18 @@ class FSCircuitStorage {
|
|
|
60225
61180
|
* @returns {ClaimNonRevStatus}
|
|
60226
61181
|
*/
|
|
60227
61182
|
const toClaimNonRevStatus = (s) => {
|
|
61183
|
+
if (!s) {
|
|
61184
|
+
const hash = poseidon.hash(new Array(3).fill(0n));
|
|
61185
|
+
return {
|
|
61186
|
+
proof: new Proof(),
|
|
61187
|
+
treeState: {
|
|
61188
|
+
state: Hash$1.fromBigInt(hash),
|
|
61189
|
+
claimsRoot: ZERO_HASH,
|
|
61190
|
+
revocationRoot: ZERO_HASH,
|
|
61191
|
+
rootOfRoots: ZERO_HASH
|
|
61192
|
+
}
|
|
61193
|
+
};
|
|
61194
|
+
}
|
|
60228
61195
|
return {
|
|
60229
61196
|
proof: s.mtp,
|
|
60230
61197
|
treeState: buildTreeState(s.issuer.state, s.issuer.claimsTreeRoot, s.issuer.revocationTreeRoot, s.issuer.rootOfRoots)
|
|
@@ -60258,6 +61225,88 @@ const toGISTProof = (smtProof) => {
|
|
|
60258
61225
|
proof
|
|
60259
61226
|
};
|
|
60260
61227
|
};
|
|
61228
|
+
const parseCredentialSubject = (credentialSubject) => {
|
|
61229
|
+
// credentialSubject is empty
|
|
61230
|
+
if (!credentialSubject) {
|
|
61231
|
+
return [{ operator: QueryOperators.$eq, fieldName: '' }];
|
|
61232
|
+
}
|
|
61233
|
+
const queries = [];
|
|
61234
|
+
const entries = Object.entries(credentialSubject);
|
|
61235
|
+
if (!entries.length) {
|
|
61236
|
+
throw new Error(`query must have at least 1 predicate`);
|
|
61237
|
+
}
|
|
61238
|
+
for (const [fieldName, fieldReq] of entries) {
|
|
61239
|
+
const fieldReqEntries = Object.entries(fieldReq);
|
|
61240
|
+
const isSelectiveDisclosure = fieldReqEntries.length === 0;
|
|
61241
|
+
if (isSelectiveDisclosure) {
|
|
61242
|
+
queries.push({ operator: QueryOperators.$sd, fieldName: fieldName });
|
|
61243
|
+
continue;
|
|
61244
|
+
}
|
|
61245
|
+
for (const [operatorName, operatorValue] of fieldReqEntries) {
|
|
61246
|
+
if (!QueryOperators[operatorName]) {
|
|
61247
|
+
throw new Error(`operator is not supported by lib`);
|
|
61248
|
+
}
|
|
61249
|
+
const operator = QueryOperators[operatorName];
|
|
61250
|
+
queries.push({ operator, fieldName, operatorValue });
|
|
61251
|
+
}
|
|
61252
|
+
}
|
|
61253
|
+
return queries;
|
|
61254
|
+
};
|
|
61255
|
+
const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType, options) => {
|
|
61256
|
+
const datatype = await Path.newTypeFromContext(ldContextJSON, `${credentialType}.${propertyQuery.fieldName}`, options);
|
|
61257
|
+
const query = {
|
|
61258
|
+
...propertyQuery,
|
|
61259
|
+
slotIndex: 0,
|
|
61260
|
+
merklizedSchema: false,
|
|
61261
|
+
datatype: datatype,
|
|
61262
|
+
claimPathKey: BigInt(0),
|
|
61263
|
+
values: [],
|
|
61264
|
+
path: new Path()
|
|
61265
|
+
};
|
|
61266
|
+
const serAttr = await Parser.getSerializationAttrFromContext(JSON.parse(ldContextJSON), options, credentialType);
|
|
61267
|
+
if (!serAttr) {
|
|
61268
|
+
query.merklizedSchema = true;
|
|
61269
|
+
}
|
|
61270
|
+
// for merklized credentials slotIndex in query must be equal to zero
|
|
61271
|
+
// and not a position of merklization root.
|
|
61272
|
+
// it has no influence on check in the off-chain circuits, but it aligns with onchain verification standard
|
|
61273
|
+
if (!query.merklizedSchema) {
|
|
61274
|
+
query.slotIndex = await Parser.getFieldSlotIndex(propertyQuery.fieldName, credentialType, byteEncoder.encode(ldContextJSON));
|
|
61275
|
+
}
|
|
61276
|
+
else {
|
|
61277
|
+
try {
|
|
61278
|
+
const path = await buildFieldPath(ldContextJSON, credentialType, propertyQuery.fieldName, options);
|
|
61279
|
+
query.claimPathKey = await path.mtEntry();
|
|
61280
|
+
query.path = path;
|
|
61281
|
+
}
|
|
61282
|
+
catch (e) {
|
|
61283
|
+
throw new Error(`field does not exist in the schema ${e.message}`);
|
|
61284
|
+
}
|
|
61285
|
+
}
|
|
61286
|
+
if (propertyQuery.operatorValue) {
|
|
61287
|
+
if (!isValidOperation(datatype, propertyQuery.operator)) {
|
|
61288
|
+
throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${datatype}`);
|
|
61289
|
+
}
|
|
61290
|
+
query.values = await transformQueryValueToBigInts(propertyQuery.operatorValue, datatype);
|
|
61291
|
+
}
|
|
61292
|
+
return query;
|
|
61293
|
+
};
|
|
61294
|
+
const parseQueriesMetadata = async (credentialType, ldContextJSON, credentialSubject, options) => {
|
|
61295
|
+
const queriesMetadata = parseCredentialSubject(credentialSubject);
|
|
61296
|
+
return Promise.all(queriesMetadata.map((m) => parseQueryMetadata(m, ldContextJSON, credentialType, options)));
|
|
61297
|
+
};
|
|
61298
|
+
const transformQueryValueToBigInts = async (value, ldType) => {
|
|
61299
|
+
const values = new Array(64).fill(BigInt(0));
|
|
61300
|
+
if (Array.isArray(value)) {
|
|
61301
|
+
for (let index = 0; index < value.length; index++) {
|
|
61302
|
+
values[index] = await Merklizer.hashValue(ldType, value[index]);
|
|
61303
|
+
}
|
|
61304
|
+
}
|
|
61305
|
+
else {
|
|
61306
|
+
values[0] = await Merklizer.hashValue(ldType, value);
|
|
61307
|
+
}
|
|
61308
|
+
return values;
|
|
61309
|
+
};
|
|
60261
61310
|
|
|
60262
61311
|
/* eslint-disable require-await */
|
|
60263
61312
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -60604,6 +61653,391 @@ class NativeProver {
|
|
|
60604
61653
|
}
|
|
60605
61654
|
NativeProver.curveName = 'bn128';
|
|
60606
61655
|
|
|
61656
|
+
const circuitValidator = {
|
|
61657
|
+
[CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1 },
|
|
61658
|
+
[CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1 },
|
|
61659
|
+
[CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1 },
|
|
61660
|
+
[CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1 },
|
|
61661
|
+
[CircuitId.AtomicQueryV3]: { maxQueriesCount: 1 },
|
|
61662
|
+
[CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1 },
|
|
61663
|
+
[CircuitId.AuthV2]: { maxQueriesCount: 0 },
|
|
61664
|
+
[CircuitId.StateTransition]: { maxQueriesCount: 0 },
|
|
61665
|
+
[CircuitId.LinkedNullifier]: { maxQueriesCount: 1 },
|
|
61666
|
+
[CircuitId.LinkedMultiQuery10]: { maxQueriesCount: 10 }
|
|
61667
|
+
};
|
|
61668
|
+
class InputGenerator {
|
|
61669
|
+
constructor(_identityWallet, _credentialWallet, _stateStorage) {
|
|
61670
|
+
this._identityWallet = _identityWallet;
|
|
61671
|
+
this._credentialWallet = _credentialWallet;
|
|
61672
|
+
this._stateStorage = _stateStorage;
|
|
61673
|
+
this.credentialAtomicQueryMTPV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
61674
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61675
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61676
|
+
const circuitInputs = new AtomicQueryMTPV2Inputs();
|
|
61677
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
61678
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
61679
|
+
const query = circuitQueries[0];
|
|
61680
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
61681
|
+
circuitInputs.query = query;
|
|
61682
|
+
circuitInputs.claim = {
|
|
61683
|
+
issuerID: circuitClaimData.issuerId,
|
|
61684
|
+
claim: circuitClaimData.claim,
|
|
61685
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
61686
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
61687
|
+
};
|
|
61688
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
61689
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61690
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
61691
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
61692
|
+
return circuitInputs.inputsMarshal();
|
|
61693
|
+
};
|
|
61694
|
+
this.credentialAtomicQueryMTPV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
61695
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61696
|
+
const authInfo = await this.prepareAuthBJJCredential(identifier);
|
|
61697
|
+
const authClaimData = await this.newCircuitClaimData({
|
|
61698
|
+
credential: authInfo.credential,
|
|
61699
|
+
credentialCoreClaim: authInfo.coreClaim
|
|
61700
|
+
});
|
|
61701
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61702
|
+
const circuitInputs = new AtomicQueryMTPV2OnChainInputs();
|
|
61703
|
+
const id = DID.idFromDID(identifier);
|
|
61704
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
61705
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
61706
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
61707
|
+
const gistProof = toGISTProof(stateProof);
|
|
61708
|
+
circuitInputs.gistProof = gistProof;
|
|
61709
|
+
if (authClaimData?.treeState) {
|
|
61710
|
+
circuitInputs.treeState = {
|
|
61711
|
+
state: authClaimData?.treeState?.state,
|
|
61712
|
+
claimsRoot: authClaimData?.treeState?.claimsRoot,
|
|
61713
|
+
revocationRoot: authClaimData?.treeState?.revocationRoot,
|
|
61714
|
+
rootOfRoots: authClaimData?.treeState?.rootOfRoots
|
|
61715
|
+
};
|
|
61716
|
+
}
|
|
61717
|
+
circuitInputs.authClaim = authClaimData.claim;
|
|
61718
|
+
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
61719
|
+
circuitInputs.authClaimNonRevMtp = authInfo.nonRevProof.proof;
|
|
61720
|
+
if (!params.challenge) {
|
|
61721
|
+
throw new Error('challenge must be provided for onchain circuits');
|
|
61722
|
+
}
|
|
61723
|
+
const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
|
|
61724
|
+
circuitInputs.signature = signature;
|
|
61725
|
+
circuitInputs.challenge = params.challenge;
|
|
61726
|
+
const query = circuitQueries[0];
|
|
61727
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
61728
|
+
circuitInputs.query = query;
|
|
61729
|
+
circuitInputs.claim = {
|
|
61730
|
+
issuerID: circuitClaimData.issuerId,
|
|
61731
|
+
claim: circuitClaimData.claim,
|
|
61732
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
61733
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
61734
|
+
};
|
|
61735
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
61736
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61737
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
61738
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
61739
|
+
return circuitInputs.inputsMarshal();
|
|
61740
|
+
};
|
|
61741
|
+
this.credentialAtomicQuerySigV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
61742
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61743
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61744
|
+
const circuitInputs = new AtomicQuerySigV2Inputs();
|
|
61745
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
61746
|
+
circuitInputs.claim = {
|
|
61747
|
+
issuerID: circuitClaimData?.issuerId,
|
|
61748
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
61749
|
+
claim: circuitClaimData.claim,
|
|
61750
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
61751
|
+
};
|
|
61752
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
61753
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61754
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
61755
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
61756
|
+
const query = circuitQueries[0];
|
|
61757
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
61758
|
+
circuitInputs.query = query;
|
|
61759
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
61760
|
+
return circuitInputs.inputsMarshal();
|
|
61761
|
+
};
|
|
61762
|
+
this.credentialAtomicQuerySigV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
61763
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61764
|
+
const authInfo = await this.prepareAuthBJJCredential(identifier);
|
|
61765
|
+
const authClaimData = await this.newCircuitClaimData({
|
|
61766
|
+
credential: authInfo.credential,
|
|
61767
|
+
credentialCoreClaim: authInfo.coreClaim
|
|
61768
|
+
});
|
|
61769
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61770
|
+
const circuitInputs = new AtomicQuerySigV2OnChainInputs();
|
|
61771
|
+
const id = DID.idFromDID(identifier);
|
|
61772
|
+
circuitInputs.id = id;
|
|
61773
|
+
circuitInputs.claim = {
|
|
61774
|
+
issuerID: circuitClaimData.issuerId,
|
|
61775
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
61776
|
+
claim: circuitClaimData.claim,
|
|
61777
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
61778
|
+
};
|
|
61779
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
61780
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61781
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
61782
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
61783
|
+
const query = circuitQueries[0];
|
|
61784
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
61785
|
+
circuitInputs.query = query;
|
|
61786
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
61787
|
+
if (authClaimData.treeState) {
|
|
61788
|
+
circuitInputs.treeState = {
|
|
61789
|
+
state: authClaimData.treeState?.state,
|
|
61790
|
+
claimsRoot: authClaimData.treeState?.claimsRoot,
|
|
61791
|
+
revocationRoot: authClaimData.treeState?.revocationRoot,
|
|
61792
|
+
rootOfRoots: authClaimData.treeState?.rootOfRoots
|
|
61793
|
+
};
|
|
61794
|
+
}
|
|
61795
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
61796
|
+
const gistProof = toGISTProof(stateProof);
|
|
61797
|
+
circuitInputs.gistProof = gistProof;
|
|
61798
|
+
circuitInputs.authClaim = authClaimData.claim;
|
|
61799
|
+
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
61800
|
+
circuitInputs.authClaimNonRevMtp = authInfo.nonRevProof.proof;
|
|
61801
|
+
if (!params.challenge) {
|
|
61802
|
+
throw new Error('challenge must be provided for onchain circuits');
|
|
61803
|
+
}
|
|
61804
|
+
const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
|
|
61805
|
+
circuitInputs.signature = signature;
|
|
61806
|
+
circuitInputs.challenge = params.challenge;
|
|
61807
|
+
return circuitInputs.inputsMarshal();
|
|
61808
|
+
};
|
|
61809
|
+
this.credentialAtomicQueryV3PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
61810
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61811
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61812
|
+
let proofType;
|
|
61813
|
+
switch (proofReq.query.proofType) {
|
|
61814
|
+
case ProofType.BJJSignature:
|
|
61815
|
+
proofType = ProofType.BJJSignature;
|
|
61816
|
+
break;
|
|
61817
|
+
case ProofType.Iden3SparseMerkleTreeProof:
|
|
61818
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
61819
|
+
break;
|
|
61820
|
+
default:
|
|
61821
|
+
if (circuitClaimData.proof) {
|
|
61822
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
61823
|
+
}
|
|
61824
|
+
else if (circuitClaimData.signatureProof) {
|
|
61825
|
+
proofType = ProofType.BJJSignature;
|
|
61826
|
+
}
|
|
61827
|
+
else {
|
|
61828
|
+
throw Error('claim has no MTP or signature proof');
|
|
61829
|
+
}
|
|
61830
|
+
break;
|
|
61831
|
+
}
|
|
61832
|
+
const circuitInputs = new AtomicQueryV3Inputs();
|
|
61833
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
61834
|
+
circuitInputs.claim = {
|
|
61835
|
+
issuerID: circuitClaimData?.issuerId,
|
|
61836
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
61837
|
+
claim: circuitClaimData.claim,
|
|
61838
|
+
nonRevProof: circuitClaimData.nonRevProof,
|
|
61839
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState }
|
|
61840
|
+
};
|
|
61841
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
61842
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61843
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
61844
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
61845
|
+
const query = circuitQueries[0];
|
|
61846
|
+
query.values = query.operator === Operators.SD ? new Array(64).fill(0) : query.values;
|
|
61847
|
+
circuitInputs.query = query;
|
|
61848
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
61849
|
+
circuitInputs.proofType = proofType;
|
|
61850
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
61851
|
+
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
|
|
61852
|
+
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
|
|
61853
|
+
? BigInt(proofReq.params?.nullifierSessionId?.toString())
|
|
61854
|
+
: BigInt(0);
|
|
61855
|
+
return circuitInputs.inputsMarshal();
|
|
61856
|
+
};
|
|
61857
|
+
this.credentialAtomicQueryV3OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
61858
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61859
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61860
|
+
let proofType;
|
|
61861
|
+
switch (proofReq.query.proofType) {
|
|
61862
|
+
case ProofType.BJJSignature:
|
|
61863
|
+
proofType = ProofType.BJJSignature;
|
|
61864
|
+
break;
|
|
61865
|
+
case ProofType.Iden3SparseMerkleTreeProof:
|
|
61866
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
61867
|
+
break;
|
|
61868
|
+
default:
|
|
61869
|
+
if (circuitClaimData.proof) {
|
|
61870
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
61871
|
+
}
|
|
61872
|
+
else if (circuitClaimData.signatureProof) {
|
|
61873
|
+
proofType = ProofType.BJJSignature;
|
|
61874
|
+
}
|
|
61875
|
+
else {
|
|
61876
|
+
throw Error('claim has no MTP or signature proof');
|
|
61877
|
+
}
|
|
61878
|
+
break;
|
|
61879
|
+
}
|
|
61880
|
+
const circuitInputs = new AtomicQueryV3OnChainInputs();
|
|
61881
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
61882
|
+
circuitInputs.claim = {
|
|
61883
|
+
issuerID: circuitClaimData?.issuerId,
|
|
61884
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
61885
|
+
claim: circuitClaimData.claim,
|
|
61886
|
+
nonRevProof: circuitClaimData.nonRevProof,
|
|
61887
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState }
|
|
61888
|
+
};
|
|
61889
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
61890
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61891
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
61892
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
61893
|
+
const query = circuitQueries[0];
|
|
61894
|
+
query.values = query.operator === Operators.SD ? new Array(64).fill(0) : query.values;
|
|
61895
|
+
circuitInputs.query = query;
|
|
61896
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
61897
|
+
circuitInputs.proofType = proofType;
|
|
61898
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
61899
|
+
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
|
|
61900
|
+
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
|
|
61901
|
+
? BigInt(proofReq.params?.nullifierSessionID?.toString())
|
|
61902
|
+
: BigInt(0);
|
|
61903
|
+
let isEthIdentity = true;
|
|
61904
|
+
try {
|
|
61905
|
+
Id.ethAddressFromId(circuitInputs.id);
|
|
61906
|
+
}
|
|
61907
|
+
catch {
|
|
61908
|
+
isEthIdentity = false;
|
|
61909
|
+
}
|
|
61910
|
+
circuitInputs.authEnabled = isEthIdentity ? 0 : 1;
|
|
61911
|
+
circuitInputs.challenge = BigInt(params.challenge ?? 0);
|
|
61912
|
+
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
|
|
61913
|
+
const id = DID.idFromDID(genesisDID);
|
|
61914
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
61915
|
+
const gistProof = toGISTProof(stateProof);
|
|
61916
|
+
circuitInputs.gistProof = gistProof;
|
|
61917
|
+
// auth inputs
|
|
61918
|
+
if (circuitInputs.authEnabled === 1) {
|
|
61919
|
+
const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
|
|
61920
|
+
const authClaimData = await this.newCircuitClaimData({
|
|
61921
|
+
credential: authPrepared.credential,
|
|
61922
|
+
credentialCoreClaim: authPrepared.coreClaim
|
|
61923
|
+
});
|
|
61924
|
+
const signature = await this._identityWallet.signChallenge(circuitInputs.challenge, authPrepared.credential);
|
|
61925
|
+
circuitInputs.profileNonce = BigInt(authProfileNonce);
|
|
61926
|
+
circuitInputs.authClaim = authClaimData.claim;
|
|
61927
|
+
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
61928
|
+
circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
|
|
61929
|
+
circuitInputs.treeState = authClaimData.treeState;
|
|
61930
|
+
circuitInputs.signature = signature;
|
|
61931
|
+
}
|
|
61932
|
+
return circuitInputs.inputsMarshal();
|
|
61933
|
+
};
|
|
61934
|
+
this.linkedNullifierPrepareInputs = async ({ preparedCredential, identifier, proofReq, params }) => {
|
|
61935
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61936
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61937
|
+
const circuitInputs = new LinkedNullifierInputs();
|
|
61938
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
61939
|
+
circuitInputs.issuerClaim = circuitClaimData.claim;
|
|
61940
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
61941
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
61942
|
+
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
|
|
61943
|
+
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
|
|
61944
|
+
? BigInt(proofReq.params?.nullifierSessionID?.toString())
|
|
61945
|
+
: BigInt(0);
|
|
61946
|
+
return circuitInputs.inputsMarshal();
|
|
61947
|
+
};
|
|
61948
|
+
this.linkedMultiQuery10PrepareInputs = async ({ preparedCredential, proofReq, params, circuitQueries }) => {
|
|
61949
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
61950
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
61951
|
+
const circuitInputs = new LinkedMultiQueryInputs();
|
|
61952
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
61953
|
+
circuitInputs.claim = circuitClaimData.claim;
|
|
61954
|
+
circuitInputs.query = circuitQueries;
|
|
61955
|
+
circuitInputs.queryLength = circuitValidator[proofReq.circuitId].maxQueriesCount;
|
|
61956
|
+
return circuitInputs.inputsMarshal();
|
|
61957
|
+
};
|
|
61958
|
+
}
|
|
61959
|
+
async generateInputs(ctx) {
|
|
61960
|
+
const { circuitId } = ctx.proofReq;
|
|
61961
|
+
const fnName = `${circuitId.split('-')[0]}PrepareInputs`;
|
|
61962
|
+
const queriesLength = ctx.circuitQueries.length;
|
|
61963
|
+
if (queriesLength > circuitValidator[circuitId].maxQueriesCount) {
|
|
61964
|
+
throw new Error(`circuit ${circuitId} supports only ${circuitValidator[circuitId].maxQueriesCount} queries`);
|
|
61965
|
+
}
|
|
61966
|
+
const fn = this[fnName];
|
|
61967
|
+
if (!fn) {
|
|
61968
|
+
throw new Error(`inputs generator for ${circuitId} not found`);
|
|
61969
|
+
}
|
|
61970
|
+
return fn(ctx);
|
|
61971
|
+
}
|
|
61972
|
+
async newCircuitClaimData(preparedCredential) {
|
|
61973
|
+
const smtProof = preparedCredential.credential.getIden3SparseMerkleTreeProof();
|
|
61974
|
+
const circuitClaim = new CircuitClaim();
|
|
61975
|
+
circuitClaim.claim = preparedCredential.credentialCoreClaim;
|
|
61976
|
+
circuitClaim.issuerId = DID.idFromDID(DID.parse(preparedCredential.credential.issuer));
|
|
61977
|
+
if (smtProof) {
|
|
61978
|
+
circuitClaim.proof = smtProof.mtp;
|
|
61979
|
+
circuitClaim.treeState = {
|
|
61980
|
+
state: smtProof.issuerData.state.value,
|
|
61981
|
+
claimsRoot: smtProof.issuerData.state.claimsTreeRoot,
|
|
61982
|
+
revocationRoot: smtProof.issuerData.state.revocationTreeRoot,
|
|
61983
|
+
rootOfRoots: smtProof.issuerData.state.rootOfRoots
|
|
61984
|
+
};
|
|
61985
|
+
}
|
|
61986
|
+
const sigProof = preparedCredential.credential.getBJJSignature2021Proof();
|
|
61987
|
+
if (sigProof) {
|
|
61988
|
+
const issuerDID = sigProof.issuerData.id;
|
|
61989
|
+
const userDID = getUserDIDFromCredential(issuerDID, preparedCredential.credential);
|
|
61990
|
+
const { credentialStatus, mtp, authCoreClaim } = sigProof.issuerData;
|
|
61991
|
+
if (!credentialStatus) {
|
|
61992
|
+
throw new Error("can't check the validity of issuer auth claim: no credential status in proof");
|
|
61993
|
+
}
|
|
61994
|
+
if (!mtp) {
|
|
61995
|
+
throw new Error('issuer auth credential must have a mtp proof');
|
|
61996
|
+
}
|
|
61997
|
+
if (!authCoreClaim) {
|
|
61998
|
+
throw new Error('issuer auth credential must have a core claim proof');
|
|
61999
|
+
}
|
|
62000
|
+
const opts = {
|
|
62001
|
+
issuerGenesisState: sigProof.issuerData.state,
|
|
62002
|
+
issuerDID,
|
|
62003
|
+
userDID
|
|
62004
|
+
};
|
|
62005
|
+
const rs = await this._credentialWallet.getRevocationStatus(credentialStatus, opts);
|
|
62006
|
+
const issuerAuthNonRevProof = toClaimNonRevStatus(rs);
|
|
62007
|
+
circuitClaim.signatureProof = {
|
|
62008
|
+
signature: sigProof.signature,
|
|
62009
|
+
issuerAuthIncProof: {
|
|
62010
|
+
proof: sigProof.issuerData.mtp,
|
|
62011
|
+
treeState: {
|
|
62012
|
+
state: sigProof.issuerData.state.value,
|
|
62013
|
+
claimsRoot: sigProof.issuerData.state.claimsTreeRoot,
|
|
62014
|
+
revocationRoot: sigProof.issuerData.state.revocationTreeRoot,
|
|
62015
|
+
rootOfRoots: sigProof.issuerData.state.rootOfRoots
|
|
62016
|
+
}
|
|
62017
|
+
},
|
|
62018
|
+
issuerAuthClaim: sigProof.issuerData.authCoreClaim,
|
|
62019
|
+
issuerAuthNonRevProof
|
|
62020
|
+
};
|
|
62021
|
+
}
|
|
62022
|
+
return circuitClaim;
|
|
62023
|
+
}
|
|
62024
|
+
async prepareAuthBJJCredential(did, treeStateInfo) {
|
|
62025
|
+
const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
|
|
62026
|
+
const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
|
|
62027
|
+
const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
|
|
62028
|
+
const authCoreClaim = authCredential.getCoreClaimFromProof(ProofType.Iden3SparseMerkleTreeProof);
|
|
62029
|
+
if (!authCoreClaim) {
|
|
62030
|
+
throw new Error('auth core claim is not defined for auth bjj credential');
|
|
62031
|
+
}
|
|
62032
|
+
return {
|
|
62033
|
+
credential: authCredential,
|
|
62034
|
+
incProof,
|
|
62035
|
+
nonRevProof,
|
|
62036
|
+
coreClaim: authCoreClaim
|
|
62037
|
+
};
|
|
62038
|
+
}
|
|
62039
|
+
}
|
|
62040
|
+
|
|
60607
62041
|
/**
|
|
60608
62042
|
* Proof service is an implementation of IProofService
|
|
60609
62043
|
* that works with a native groth16 prover
|
|
@@ -60626,6 +62060,7 @@ class ProofService {
|
|
|
60626
62060
|
this._stateStorage = _stateStorage;
|
|
60627
62061
|
this._prover = opts?.prover ?? new NativeProver(_circuitStorage);
|
|
60628
62062
|
this._ldOptions = { ...opts, documentLoader: opts?.documentLoader ?? cacheLoader(opts) };
|
|
62063
|
+
this._inputsGenerator = new InputGenerator(_identityWallet, _credentialWallet, _stateStorage);
|
|
60629
62064
|
}
|
|
60630
62065
|
/** {@inheritdoc IProofService.verifyProof} */
|
|
60631
62066
|
async verifyProof(zkp, circuitId) {
|
|
@@ -60639,20 +62074,61 @@ class ProofService {
|
|
|
60639
62074
|
challenge: 0n
|
|
60640
62075
|
};
|
|
60641
62076
|
}
|
|
60642
|
-
|
|
60643
|
-
|
|
62077
|
+
let credentialWithRevStatus = { cred: opts.credential, revStatus: opts.credentialRevocationStatus };
|
|
62078
|
+
if (!opts.credential) {
|
|
62079
|
+
credentialWithRevStatus = await this.findCredentialByProofQuery(identifier, proofReq.query);
|
|
62080
|
+
}
|
|
62081
|
+
if (opts.credential && !opts.credentialRevocationStatus && !opts.skipRevocation) {
|
|
62082
|
+
const revStatus = await this._credentialWallet.getRevocationStatusFromCredential(opts.credential);
|
|
62083
|
+
credentialWithRevStatus = { cred: opts.credential, revStatus };
|
|
62084
|
+
}
|
|
62085
|
+
if (!credentialWithRevStatus.cred) {
|
|
62086
|
+
throw new Error(`credential not found for query ${JSON.stringify(proofReq.query)}`);
|
|
62087
|
+
}
|
|
62088
|
+
const credentialCoreClaim = await this._identityWallet.getCoreClaimFromCredential(credentialWithRevStatus.cred);
|
|
60644
62089
|
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
|
|
60645
|
-
const preparedCredential =
|
|
62090
|
+
const preparedCredential = {
|
|
62091
|
+
credential: credentialWithRevStatus.cred,
|
|
62092
|
+
credentialCoreClaim,
|
|
62093
|
+
revStatus: credentialWithRevStatus.revStatus
|
|
62094
|
+
};
|
|
60646
62095
|
const subjectDID = DID.parse(preparedCredential.credential.credentialSubject['id']);
|
|
60647
62096
|
const { nonce: credentialSubjectProfileNonce, genesisDID: subjectGenesisDID } = await this._identityWallet.getGenesisDIDMetadata(subjectDID);
|
|
60648
62097
|
if (subjectGenesisDID.string() !== genesisDID.string()) {
|
|
60649
62098
|
throw new Error('subject and auth profiles are not derived from the same did');
|
|
60650
62099
|
}
|
|
60651
|
-
const
|
|
62100
|
+
const propertiesMetadata = parseCredentialSubject(proofReq.query.credentialSubject);
|
|
62101
|
+
if (!propertiesMetadata.length) {
|
|
62102
|
+
throw new Error('no queries in zkp request');
|
|
62103
|
+
}
|
|
62104
|
+
const mtPosition = preparedCredential.credentialCoreClaim.getMerklizedPosition();
|
|
62105
|
+
let mk;
|
|
62106
|
+
if (mtPosition !== MerklizedRootPosition$1.None) {
|
|
62107
|
+
mk = await preparedCredential.credential.merklize(this._ldOptions);
|
|
62108
|
+
}
|
|
62109
|
+
const context = proofReq.query['context'];
|
|
62110
|
+
const groupId = proofReq.query['groupId'];
|
|
62111
|
+
const ldContext = await this.loadLdContext(context);
|
|
62112
|
+
const credentialType = proofReq.query['type'];
|
|
62113
|
+
const queriesMetadata = [];
|
|
62114
|
+
const circuitQueries = [];
|
|
62115
|
+
for (const propertyMetadata of propertiesMetadata) {
|
|
62116
|
+
const queryMetadata = await parseQueryMetadata(propertyMetadata, byteDecoder.decode(ldContext), credentialType, this._ldOptions);
|
|
62117
|
+
queriesMetadata.push(queryMetadata);
|
|
62118
|
+
const circuitQuery = await this.toCircuitsQuery(preparedCredential.credential, queryMetadata, mk);
|
|
62119
|
+
circuitQueries.push(circuitQuery);
|
|
62120
|
+
}
|
|
62121
|
+
const inputs = await this.generateInputs(preparedCredential, genesisDID, proofReq, {
|
|
60652
62122
|
...opts,
|
|
60653
62123
|
authProfileNonce,
|
|
60654
|
-
credentialSubjectProfileNonce
|
|
60655
|
-
|
|
62124
|
+
credentialSubjectProfileNonce,
|
|
62125
|
+
linkNonce: groupId ? opts.linkNonce : 0n
|
|
62126
|
+
}, circuitQueries);
|
|
62127
|
+
const sdQueries = queriesMetadata.filter((q) => q.operator === Operators.SD);
|
|
62128
|
+
let vp;
|
|
62129
|
+
if (sdQueries.length) {
|
|
62130
|
+
vp = createVerifiablePresentation(context, credentialType, preparedCredential.credential, sdQueries);
|
|
62131
|
+
}
|
|
60656
62132
|
const { proof, pub_signals } = await this._prover.generate(inputs, proofReq.circuitId);
|
|
60657
62133
|
return {
|
|
60658
62134
|
id: proofReq.id,
|
|
@@ -60664,7 +62140,7 @@ class ProofService {
|
|
|
60664
62140
|
}
|
|
60665
62141
|
/** {@inheritdoc IProofService.transitState} */
|
|
60666
62142
|
async transitState(did, oldTreeState, isOldStateGenesis, stateStorage, ethSigner) {
|
|
60667
|
-
const authInfo = await this.prepareAuthBJJCredential(did, oldTreeState);
|
|
62143
|
+
const authInfo = await this._inputsGenerator.prepareAuthBJJCredential(did, oldTreeState);
|
|
60668
62144
|
const newTreeModel = await this._identityWallet.getDIDTreeModel(did);
|
|
60669
62145
|
const claimsRoot = await newTreeModel.claimsTree.root();
|
|
60670
62146
|
const rootOfRoots = await newTreeModel.rootsTree.root();
|
|
@@ -60676,17 +62152,17 @@ class ProofService {
|
|
|
60676
62152
|
rootOfRoots
|
|
60677
62153
|
};
|
|
60678
62154
|
const challenge = Poseidon.hash([oldTreeState.state.bigInt(), newTreeState.state.bigInt()]);
|
|
60679
|
-
const signature = await this._identityWallet.signChallenge(challenge, authInfo.
|
|
62155
|
+
const signature = await this._identityWallet.signChallenge(challenge, authInfo.credential);
|
|
60680
62156
|
const circuitInputs = new StateTransitionInputs();
|
|
60681
62157
|
circuitInputs.id = DID.idFromDID(did);
|
|
60682
62158
|
circuitInputs.signature = signature;
|
|
60683
62159
|
circuitInputs.isOldStateGenesis = isOldStateGenesis;
|
|
60684
|
-
const authClaimIncProofNewState = await this._identityWallet.generateCredentialMtp(did, authInfo.
|
|
62160
|
+
const authClaimIncProofNewState = await this._identityWallet.generateCredentialMtp(did, authInfo.credential, newTreeState);
|
|
60685
62161
|
circuitInputs.newTreeState = authClaimIncProofNewState.treeState;
|
|
60686
62162
|
circuitInputs.authClaimNewStateIncProof = authClaimIncProofNewState.proof;
|
|
60687
62163
|
circuitInputs.oldTreeState = oldTreeState;
|
|
60688
62164
|
circuitInputs.authClaim = {
|
|
60689
|
-
claim: authInfo.
|
|
62165
|
+
claim: authInfo.coreClaim,
|
|
60690
62166
|
incProof: authInfo.incProof,
|
|
60691
62167
|
nonRevProof: authInfo.nonRevProof
|
|
60692
62168
|
};
|
|
@@ -60696,370 +62172,65 @@ class ProofService {
|
|
|
60696
62172
|
await this._identityWallet.updateIdentityState(did, true, newTreeState);
|
|
60697
62173
|
return txId;
|
|
60698
62174
|
}
|
|
60699
|
-
async
|
|
60700
|
-
|
|
60701
|
-
|
|
60702
|
-
|
|
62175
|
+
async generateInputs(preparedCredential, identifier, proofReq, params, circuitQueries) {
|
|
62176
|
+
return this._inputsGenerator.generateInputs({
|
|
62177
|
+
preparedCredential,
|
|
62178
|
+
identifier,
|
|
62179
|
+
proofReq,
|
|
62180
|
+
params,
|
|
62181
|
+
circuitQueries
|
|
62182
|
+
});
|
|
60703
62183
|
}
|
|
60704
|
-
async
|
|
60705
|
-
|
|
60706
|
-
|
|
60707
|
-
const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
|
|
60708
|
-
const authCoreClaim = authCredential.getCoreClaimFromProof(ProofType.Iden3SparseMerkleTreeProof);
|
|
60709
|
-
if (!authCoreClaim) {
|
|
60710
|
-
throw new Error('auth core claim is not defined for auth bjj credential');
|
|
62184
|
+
async toCircuitsQuery(credential, queryMetadata, merklizedCredential) {
|
|
62185
|
+
if (queryMetadata.merklizedSchema && !merklizedCredential) {
|
|
62186
|
+
throw new Error('merklized root position is set to None for merklized schema');
|
|
60711
62187
|
}
|
|
60712
|
-
|
|
60713
|
-
|
|
60714
|
-
async generateInputs(preparedCredential, identifier, proofReq, params) {
|
|
60715
|
-
let generateInputFn;
|
|
60716
|
-
switch (proofReq.circuitId) {
|
|
60717
|
-
case CircuitId.AtomicQueryMTPV2:
|
|
60718
|
-
generateInputFn = this.generateMTPV2Inputs.bind(this);
|
|
60719
|
-
break;
|
|
60720
|
-
case CircuitId.AtomicQueryMTPV2OnChain:
|
|
60721
|
-
generateInputFn = this.generateMTPV2OnChainInputs.bind(this);
|
|
60722
|
-
break;
|
|
60723
|
-
case CircuitId.AtomicQuerySigV2:
|
|
60724
|
-
generateInputFn = this.generateQuerySigV2Inputs.bind(this);
|
|
60725
|
-
break;
|
|
60726
|
-
case CircuitId.AtomicQuerySigV2OnChain:
|
|
60727
|
-
generateInputFn = this.generateQuerySigV2OnChainInputs.bind(this);
|
|
60728
|
-
break;
|
|
60729
|
-
default:
|
|
60730
|
-
throw new Error(`circuit with id ${proofReq.circuitId} is not supported by issuer`);
|
|
60731
|
-
}
|
|
60732
|
-
return generateInputFn(preparedCredential, identifier, proofReq, params);
|
|
60733
|
-
}
|
|
60734
|
-
async generateMTPV2Inputs(preparedCredential, identifier, proofReq, params) {
|
|
60735
|
-
const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
|
|
60736
|
-
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
60737
|
-
const circuitInputs = new AtomicQueryMTPV2Inputs();
|
|
60738
|
-
circuitInputs.id = DID.idFromDID(identifier);
|
|
60739
|
-
circuitInputs.requestID = BigInt(proofReq.id);
|
|
60740
|
-
const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
|
|
60741
|
-
circuitInputs.query = query;
|
|
60742
|
-
circuitInputs.claim = {
|
|
60743
|
-
issuerID: circuitClaimData.issuerId,
|
|
60744
|
-
claim: circuitClaimData.claim,
|
|
60745
|
-
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
60746
|
-
nonRevProof: circuitClaimData.nonRevProof
|
|
60747
|
-
};
|
|
60748
|
-
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
60749
|
-
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
60750
|
-
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
60751
|
-
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
60752
|
-
return { inputs: circuitInputs.inputsMarshal(), vp };
|
|
60753
|
-
}
|
|
60754
|
-
async generateMTPV2OnChainInputs(preparedCredential, identifier, proofReq, params) {
|
|
60755
|
-
const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
|
|
60756
|
-
const authPrepared = await this.prepareAuthBJJCredential(identifier);
|
|
60757
|
-
const authClaimData = await this.newCircuitClaimData(authPrepared.authCredential, authPrepared.authCoreClaim);
|
|
60758
|
-
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
60759
|
-
const circuitInputs = new AtomicQueryMTPV2OnChainInputs();
|
|
60760
|
-
const id = DID.idFromDID(identifier);
|
|
60761
|
-
circuitInputs.id = DID.idFromDID(identifier);
|
|
60762
|
-
circuitInputs.requestID = BigInt(proofReq.id);
|
|
60763
|
-
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
60764
|
-
const gistProof = toGISTProof(stateProof);
|
|
60765
|
-
circuitInputs.gistProof = gistProof;
|
|
60766
|
-
if (authClaimData?.treeState) {
|
|
60767
|
-
circuitInputs.treeState = {
|
|
60768
|
-
state: authClaimData?.treeState?.state,
|
|
60769
|
-
claimsRoot: authClaimData?.treeState?.claimsRoot,
|
|
60770
|
-
revocationRoot: authClaimData?.treeState?.revocationRoot,
|
|
60771
|
-
rootOfRoots: authClaimData?.treeState?.rootOfRoots
|
|
60772
|
-
};
|
|
62188
|
+
if (!queryMetadata.merklizedSchema && merklizedCredential) {
|
|
62189
|
+
throw new Error('merklized root position is not set to None for non-merklized schema');
|
|
60773
62190
|
}
|
|
60774
|
-
|
|
60775
|
-
|
|
60776
|
-
|
|
60777
|
-
|
|
60778
|
-
|
|
60779
|
-
|
|
60780
|
-
|
|
60781
|
-
|
|
60782
|
-
|
|
60783
|
-
|
|
60784
|
-
|
|
60785
|
-
|
|
60786
|
-
|
|
60787
|
-
|
|
60788
|
-
|
|
60789
|
-
|
|
60790
|
-
|
|
60791
|
-
|
|
60792
|
-
|
|
60793
|
-
|
|
60794
|
-
|
|
60795
|
-
|
|
60796
|
-
|
|
60797
|
-
|
|
60798
|
-
|
|
60799
|
-
|
|
60800
|
-
|
|
60801
|
-
|
|
60802
|
-
|
|
60803
|
-
|
|
60804
|
-
|
|
60805
|
-
|
|
60806
|
-
|
|
60807
|
-
};
|
|
60808
|
-
circuitInputs.requestID = BigInt(proofReq.id);
|
|
60809
|
-
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
60810
|
-
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
60811
|
-
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
60812
|
-
const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
|
|
60813
|
-
circuitInputs.query = query;
|
|
60814
|
-
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
60815
|
-
return { inputs: circuitInputs.inputsMarshal(), vp };
|
|
60816
|
-
}
|
|
60817
|
-
async generateQuerySigV2OnChainInputs(preparedCredential, identifier, proofReq, params) {
|
|
60818
|
-
const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
|
|
60819
|
-
const authPrepared = await this.prepareAuthBJJCredential(identifier);
|
|
60820
|
-
const authClaimData = await this.newCircuitClaimData(authPrepared.authCredential, authPrepared.authCoreClaim);
|
|
60821
|
-
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
60822
|
-
const circuitInputs = new AtomicQuerySigV2OnChainInputs();
|
|
60823
|
-
const id = DID.idFromDID(identifier);
|
|
60824
|
-
circuitInputs.id = id;
|
|
60825
|
-
circuitInputs.claim = {
|
|
60826
|
-
issuerID: circuitClaimData.issuerId,
|
|
60827
|
-
signatureProof: circuitClaimData.signatureProof,
|
|
60828
|
-
claim: circuitClaimData.claim,
|
|
60829
|
-
nonRevProof: circuitClaimData.nonRevProof
|
|
60830
|
-
};
|
|
60831
|
-
circuitInputs.requestID = BigInt(proofReq.id);
|
|
60832
|
-
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
60833
|
-
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
60834
|
-
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
60835
|
-
const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
|
|
60836
|
-
circuitInputs.query = query;
|
|
60837
|
-
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
60838
|
-
if (authClaimData.treeState) {
|
|
60839
|
-
circuitInputs.treeState = {
|
|
60840
|
-
state: authClaimData.treeState?.state,
|
|
60841
|
-
claimsRoot: authClaimData.treeState?.claimsRoot,
|
|
60842
|
-
revocationRoot: authClaimData.treeState?.revocationRoot,
|
|
60843
|
-
rootOfRoots: authClaimData.treeState?.rootOfRoots
|
|
60844
|
-
};
|
|
60845
|
-
}
|
|
60846
|
-
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
60847
|
-
const gistProof = toGISTProof(stateProof);
|
|
60848
|
-
circuitInputs.gistProof = gistProof;
|
|
60849
|
-
circuitInputs.authClaim = authClaimData.claim;
|
|
60850
|
-
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
60851
|
-
circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
|
|
60852
|
-
if (!params.challenge) {
|
|
60853
|
-
throw new Error('challenge must be provided for onchain circuits');
|
|
60854
|
-
}
|
|
60855
|
-
const signature = await this._identityWallet.signChallenge(params.challenge, authPrepared.authCredential);
|
|
60856
|
-
circuitInputs.signature = signature;
|
|
60857
|
-
circuitInputs.challenge = params.challenge;
|
|
60858
|
-
return { inputs: circuitInputs.inputsMarshal(), vp };
|
|
60859
|
-
}
|
|
60860
|
-
// NewCircuitClaimData generates circuits claim structure
|
|
60861
|
-
async newCircuitClaimData(credential, coreClaim) {
|
|
60862
|
-
const smtProof = credential.getIden3SparseMerkleTreeProof();
|
|
60863
|
-
const circuitClaim = new CircuitClaim();
|
|
60864
|
-
circuitClaim.claim = coreClaim;
|
|
60865
|
-
circuitClaim.issuerId = DID.idFromDID(DID.parse(credential.issuer));
|
|
60866
|
-
if (smtProof) {
|
|
60867
|
-
circuitClaim.proof = smtProof.mtp;
|
|
60868
|
-
circuitClaim.treeState = {
|
|
60869
|
-
state: smtProof.issuerData.state.value,
|
|
60870
|
-
claimsRoot: smtProof.issuerData.state.claimsTreeRoot,
|
|
60871
|
-
revocationRoot: smtProof.issuerData.state.revocationTreeRoot,
|
|
60872
|
-
rootOfRoots: smtProof.issuerData.state.rootOfRoots
|
|
60873
|
-
};
|
|
60874
|
-
}
|
|
60875
|
-
const sigProof = credential.getBJJSignature2021Proof();
|
|
60876
|
-
if (sigProof) {
|
|
60877
|
-
const issuerDID = sigProof.issuerData.id;
|
|
60878
|
-
let userDID;
|
|
60879
|
-
if (!credential.credentialSubject.id) {
|
|
60880
|
-
userDID = issuerDID;
|
|
60881
|
-
}
|
|
60882
|
-
else {
|
|
60883
|
-
if (typeof credential.credentialSubject.id !== 'string') {
|
|
60884
|
-
throw new Error('credential status `id` is not a string');
|
|
60885
|
-
}
|
|
60886
|
-
userDID = DID.parse(credential.credentialSubject.id);
|
|
60887
|
-
}
|
|
60888
|
-
if (!sigProof.issuerData.credentialStatus) {
|
|
60889
|
-
throw new Error("can't check the validity of issuer auth claim: no credential status in proof");
|
|
60890
|
-
}
|
|
60891
|
-
const opts = {
|
|
60892
|
-
issuerGenesisState: sigProof.issuerData.state,
|
|
60893
|
-
issuerDID,
|
|
60894
|
-
userDID
|
|
60895
|
-
};
|
|
60896
|
-
const rs = await this._credentialWallet.getRevocationStatus(sigProof.issuerData.credentialStatus, opts);
|
|
60897
|
-
if (!rs) {
|
|
60898
|
-
throw new Error("can't fetch the credential status of issuer auth claim");
|
|
60899
|
-
}
|
|
60900
|
-
const issuerAuthNonRevProof = toClaimNonRevStatus(rs);
|
|
60901
|
-
if (!sigProof.issuerData.mtp) {
|
|
60902
|
-
throw new Error('issuer auth credential must have a mtp proof');
|
|
60903
|
-
}
|
|
60904
|
-
if (!sigProof.issuerData.authCoreClaim) {
|
|
60905
|
-
throw new Error('issuer auth credential must have a core claim proof');
|
|
60906
|
-
}
|
|
60907
|
-
circuitClaim.signatureProof = {
|
|
60908
|
-
signature: sigProof.signature,
|
|
60909
|
-
issuerAuthIncProof: {
|
|
60910
|
-
proof: sigProof.issuerData.mtp,
|
|
60911
|
-
treeState: {
|
|
60912
|
-
state: sigProof.issuerData.state.value,
|
|
60913
|
-
claimsRoot: sigProof.issuerData.state.claimsTreeRoot,
|
|
60914
|
-
revocationRoot: sigProof.issuerData.state.revocationTreeRoot,
|
|
60915
|
-
rootOfRoots: sigProof.issuerData.state.rootOfRoots
|
|
60916
|
-
}
|
|
60917
|
-
},
|
|
60918
|
-
issuerAuthClaim: sigProof.issuerData.authCoreClaim,
|
|
60919
|
-
issuerAuthNonRevProof
|
|
60920
|
-
};
|
|
60921
|
-
}
|
|
60922
|
-
return circuitClaim;
|
|
60923
|
-
}
|
|
60924
|
-
async toCircuitsQuery(query, credential, coreClaim) {
|
|
60925
|
-
const mtPosition = coreClaim.getMerklizedPosition();
|
|
60926
|
-
return mtPosition === MerklizedRootPosition$1.None
|
|
60927
|
-
? this.prepareNonMerklizedQuery(query, credential)
|
|
60928
|
-
: this.prepareMerklizedQuery(query, credential);
|
|
60929
|
-
}
|
|
60930
|
-
async prepareMerklizedQuery(query, credential) {
|
|
60931
|
-
const parsedQuery = await this.parseRequest(query.credentialSubject);
|
|
60932
|
-
const ldContext = await this.loadLdContextFromJSONSchema(credential.credentialSchema.id);
|
|
60933
|
-
let path = new Path();
|
|
60934
|
-
if (parsedQuery.fieldName) {
|
|
60935
|
-
path = await Path.getContextPathKey(byteDecoder.decode(ldContext), credential.type[1], parsedQuery.fieldName, this._ldOptions);
|
|
60936
|
-
}
|
|
60937
|
-
path.prepend(['https://www.w3.org/2018/credentials#credentialSubject']);
|
|
60938
|
-
const mk = await credential.merklize(this._ldOptions);
|
|
60939
|
-
const { proof, value: mtValue } = await mk.proof(path);
|
|
60940
|
-
const pathKey = await path.mtEntry();
|
|
60941
|
-
parsedQuery.query.valueProof = new ValueProof();
|
|
60942
|
-
parsedQuery.query.valueProof.mtp = proof;
|
|
60943
|
-
parsedQuery.query.valueProof.path = pathKey;
|
|
60944
|
-
parsedQuery.query.valueProof.mtp = proof;
|
|
60945
|
-
const mtEntry = await mtValue?.mtEntry();
|
|
60946
|
-
if (!mtEntry) {
|
|
60947
|
-
throw new Error(`can't merklize credential: no merkle tree entry found`);
|
|
60948
|
-
}
|
|
60949
|
-
parsedQuery.query.valueProof.value = mtEntry;
|
|
60950
|
-
// for merklized credentials slotIndex in query must be equal to zero
|
|
60951
|
-
// and not a position of merklization root.
|
|
60952
|
-
// it has no influence on check in the off-chain circuits, but it aligns with onchain verification standard
|
|
60953
|
-
parsedQuery.query.slotIndex = 0;
|
|
60954
|
-
if (!parsedQuery.fieldName) {
|
|
60955
|
-
const resultQuery = parsedQuery.query;
|
|
60956
|
-
resultQuery.operator = QueryOperators.$eq;
|
|
60957
|
-
resultQuery.values = [mtEntry];
|
|
60958
|
-
return { query: resultQuery };
|
|
60959
|
-
}
|
|
60960
|
-
if (parsedQuery.isSelectiveDisclosure) {
|
|
60961
|
-
const rawValue = mk.rawValue(path);
|
|
60962
|
-
const vp = createVerifiablePresentation(query.context ?? '', query.type ?? '', parsedQuery.fieldName, rawValue);
|
|
60963
|
-
const resultQuery = parsedQuery.query;
|
|
60964
|
-
resultQuery.operator = QueryOperators.$eq;
|
|
60965
|
-
resultQuery.values = [mtEntry];
|
|
60966
|
-
return { query: resultQuery, vp };
|
|
60967
|
-
}
|
|
60968
|
-
if (parsedQuery.rawValue === null || parsedQuery.rawValue === undefined) {
|
|
60969
|
-
throw new Error('value is not presented in the query');
|
|
60970
|
-
}
|
|
60971
|
-
const ldType = await mk.jsonLDType(path);
|
|
60972
|
-
parsedQuery.query.values = await this.transformQueryValueToBigInts(parsedQuery.rawValue, ldType);
|
|
60973
|
-
return { query: parsedQuery.query };
|
|
60974
|
-
}
|
|
60975
|
-
async prepareNonMerklizedQuery(query, credential) {
|
|
60976
|
-
const ldContext = await this.loadLdContextFromJSONSchema(credential.credentialSchema.id);
|
|
60977
|
-
if (query.credentialSubject && Object.keys(query.credentialSubject).length > 1) {
|
|
60978
|
-
throw new Error('multiple requests are not supported');
|
|
60979
|
-
}
|
|
60980
|
-
const parsedQuery = await this.parseRequest(query.credentialSubject);
|
|
60981
|
-
if (!query.type) {
|
|
60982
|
-
throw new Error('query type is not defined');
|
|
60983
|
-
}
|
|
60984
|
-
parsedQuery.query.slotIndex = await Parser.getFieldSlotIndex(parsedQuery.fieldName, query.type, ldContext);
|
|
60985
|
-
const { vp, mzValue, dataType } = await verifiablePresentationFromCred(credential, query, parsedQuery.fieldName, this._ldOptions);
|
|
60986
|
-
if (parsedQuery.isSelectiveDisclosure) {
|
|
60987
|
-
const resultQuery = parsedQuery.query;
|
|
60988
|
-
resultQuery.operator = QueryOperators.$eq;
|
|
60989
|
-
resultQuery.values = [await mzValue.mtEntry()];
|
|
60990
|
-
return { query: resultQuery, vp };
|
|
60991
|
-
}
|
|
60992
|
-
if (parsedQuery.rawValue === null || parsedQuery.rawValue === undefined) {
|
|
60993
|
-
throw new Error('value is not presented in the query');
|
|
60994
|
-
}
|
|
60995
|
-
parsedQuery.query.values = await this.transformQueryValueToBigInts(parsedQuery.rawValue, dataType);
|
|
60996
|
-
return { query: parsedQuery.query };
|
|
60997
|
-
}
|
|
60998
|
-
async loadLdContextFromJSONSchema(jsonSchemaURL) {
|
|
62191
|
+
const query = new Query();
|
|
62192
|
+
query.slotIndex = queryMetadata.slotIndex;
|
|
62193
|
+
query.operator = queryMetadata.operator;
|
|
62194
|
+
query.values = queryMetadata.values;
|
|
62195
|
+
if (queryMetadata.merklizedSchema && merklizedCredential) {
|
|
62196
|
+
const { proof, value: mtValue } = await merklizedCredential.proof(queryMetadata.path);
|
|
62197
|
+
query.valueProof = new ValueProof();
|
|
62198
|
+
query.valueProof.mtp = proof;
|
|
62199
|
+
query.valueProof.path = queryMetadata.claimPathKey;
|
|
62200
|
+
const mtEntry = await mtValue?.mtEntry();
|
|
62201
|
+
if (!mtEntry) {
|
|
62202
|
+
throw new Error(`can't merklize credential: no merkle tree entry found`);
|
|
62203
|
+
}
|
|
62204
|
+
query.valueProof.value = mtEntry;
|
|
62205
|
+
if (!queryMetadata.fieldName) {
|
|
62206
|
+
query.values = [mtEntry];
|
|
62207
|
+
return query;
|
|
62208
|
+
}
|
|
62209
|
+
}
|
|
62210
|
+
if (queryMetadata.operator === Operators.SD) {
|
|
62211
|
+
const [first, ...rest] = queryMetadata.fieldName.split('.');
|
|
62212
|
+
let v = credential.credentialSubject[first];
|
|
62213
|
+
for (const part of rest) {
|
|
62214
|
+
v = v[part];
|
|
62215
|
+
}
|
|
62216
|
+
if (typeof v === 'undefined') {
|
|
62217
|
+
throw new Error(`credential doesn't contain value for field ${queryMetadata.fieldName}`);
|
|
62218
|
+
}
|
|
62219
|
+
query.values = await transformQueryValueToBigInts(v, queryMetadata.datatype);
|
|
62220
|
+
}
|
|
62221
|
+
return query;
|
|
62222
|
+
}
|
|
62223
|
+
async loadLdContext(context) {
|
|
60999
62224
|
const loader = getDocumentLoader(this._ldOptions);
|
|
61000
|
-
let schema;
|
|
61001
|
-
try {
|
|
61002
|
-
schema = (await loader(jsonSchemaURL)).document;
|
|
61003
|
-
}
|
|
61004
|
-
catch (e) {
|
|
61005
|
-
throw new Error(`can't load credential schema ${jsonSchemaURL}`);
|
|
61006
|
-
}
|
|
61007
|
-
const jsonSchema = schema;
|
|
61008
62225
|
let ldSchema;
|
|
61009
|
-
let ldContextUrl = '';
|
|
61010
62226
|
try {
|
|
61011
|
-
|
|
61012
|
-
if (!ldContextUrl) {
|
|
61013
|
-
throw new Error('ldContext is not defined in json schema metadata');
|
|
61014
|
-
}
|
|
61015
|
-
ldSchema = (await loader(ldContextUrl)).document;
|
|
62227
|
+
ldSchema = (await loader(context)).document;
|
|
61016
62228
|
}
|
|
61017
62229
|
catch (e) {
|
|
61018
|
-
throw new Error(`can't load ld context from url ${
|
|
62230
|
+
throw new Error(`can't load ld context from url ${context}`);
|
|
61019
62231
|
}
|
|
61020
62232
|
return byteEncoder.encode(JSON.stringify(ldSchema));
|
|
61021
62233
|
}
|
|
61022
|
-
async parseRequest(req) {
|
|
61023
|
-
if (!req) {
|
|
61024
|
-
const query = new Query();
|
|
61025
|
-
query.operator = QueryOperators.$eq;
|
|
61026
|
-
return { query, fieldName: '' };
|
|
61027
|
-
}
|
|
61028
|
-
const entries = Object.entries(req);
|
|
61029
|
-
if (entries.length > 1) {
|
|
61030
|
-
throw new Error(`multiple requests not supported`);
|
|
61031
|
-
}
|
|
61032
|
-
const [fieldName, fieldReq] = entries[0];
|
|
61033
|
-
const fieldReqEntries = Object.entries(fieldReq);
|
|
61034
|
-
if (fieldReqEntries.length > 1) {
|
|
61035
|
-
throw new Error(`multiple predicates for one field not supported`);
|
|
61036
|
-
}
|
|
61037
|
-
const isSelectiveDisclosure = fieldReqEntries.length === 0;
|
|
61038
|
-
const query = new Query();
|
|
61039
|
-
if (isSelectiveDisclosure) {
|
|
61040
|
-
return { query, fieldName, isSelectiveDisclosure };
|
|
61041
|
-
}
|
|
61042
|
-
let operator = 0;
|
|
61043
|
-
const [key, value] = fieldReqEntries[0];
|
|
61044
|
-
if (!QueryOperators[key]) {
|
|
61045
|
-
throw new Error(`operator is not supported by lib`);
|
|
61046
|
-
}
|
|
61047
|
-
operator = QueryOperators[key];
|
|
61048
|
-
query.operator = operator;
|
|
61049
|
-
return { query, fieldName, rawValue: value };
|
|
61050
|
-
}
|
|
61051
|
-
async transformQueryValueToBigInts(value, ldType) {
|
|
61052
|
-
const values = new Array(64).fill(BigInt(0));
|
|
61053
|
-
if (Array.isArray(value)) {
|
|
61054
|
-
for (let index = 0; index < value.length; index++) {
|
|
61055
|
-
values[index] = await Merklizer.hashValue(ldType, value[index]);
|
|
61056
|
-
}
|
|
61057
|
-
}
|
|
61058
|
-
else {
|
|
61059
|
-
values[0] = await Merklizer.hashValue(ldType, value);
|
|
61060
|
-
}
|
|
61061
|
-
return values;
|
|
61062
|
-
}
|
|
61063
62234
|
/** {@inheritdoc IProofService.generateAuthV2Inputs} */
|
|
61064
62235
|
async generateAuthV2Inputs(hash, did, circuitId) {
|
|
61065
62236
|
if (circuitId !== CircuitId.AuthV2) {
|
|
@@ -61067,9 +62238,12 @@ class ProofService {
|
|
|
61067
62238
|
}
|
|
61068
62239
|
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(did);
|
|
61069
62240
|
const challenge = BytesHelper.bytesToInt(hash.reverse());
|
|
61070
|
-
const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
|
|
61071
|
-
const authClaimData = await this.newCircuitClaimData(
|
|
61072
|
-
|
|
62241
|
+
const authPrepared = await this._inputsGenerator.prepareAuthBJJCredential(genesisDID);
|
|
62242
|
+
const authClaimData = await this._inputsGenerator.newCircuitClaimData({
|
|
62243
|
+
credential: authPrepared.credential,
|
|
62244
|
+
credentialCoreClaim: authPrepared.coreClaim
|
|
62245
|
+
});
|
|
62246
|
+
const signature = await this._identityWallet.signChallenge(challenge, authPrepared.credential);
|
|
61073
62247
|
const id = DID.idFromDID(genesisDID);
|
|
61074
62248
|
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
61075
62249
|
const gistProof = toGISTProof(stateProof);
|
|
@@ -61105,7 +62279,7 @@ class ProofService {
|
|
|
61105
62279
|
}
|
|
61106
62280
|
return true;
|
|
61107
62281
|
}
|
|
61108
|
-
async
|
|
62282
|
+
async findCredentialByProofQuery(did, query) {
|
|
61109
62283
|
const credentials = await this._identityWallet.findOwnedCredentialsByDID(did, query);
|
|
61110
62284
|
if (!credentials.length) {
|
|
61111
62285
|
throw new Error(`no credentials belong to did or its profiles`);
|
|
@@ -61113,18 +62287,11 @@ class ProofService {
|
|
|
61113
62287
|
// For EQ / IN / NIN / LT / GT operations selective if credential satisfies query - we can get any.
|
|
61114
62288
|
// TODO: choose credential for selective credentials
|
|
61115
62289
|
const credential = query.skipClaimRevocationCheck
|
|
61116
|
-
? credentials[0]
|
|
61117
|
-
:
|
|
62290
|
+
? { cred: credentials[0], revStatus: undefined }
|
|
62291
|
+
: await this._credentialWallet.findNonRevokedCredential(credentials);
|
|
61118
62292
|
return credential;
|
|
61119
62293
|
}
|
|
61120
62294
|
}
|
|
61121
|
-
// BJJSignatureFromHexString converts hex to babyjub.Signature
|
|
61122
|
-
const bJJSignatureFromHexString = async (sigHex) => {
|
|
61123
|
-
const signatureBytes = Hex.decodeString(sigHex);
|
|
61124
|
-
const compressedSig = Uint8Array.from(signatureBytes).slice(0, 64);
|
|
61125
|
-
const bjjSig = Signature$5.newFromCompressed(compressedSig);
|
|
61126
|
-
return bjjSig;
|
|
61127
|
-
};
|
|
61128
62295
|
|
|
61129
62296
|
/**
|
|
61130
62297
|
* creates empty basic message
|
|
@@ -61776,15 +62943,55 @@ class AuthHandler {
|
|
|
61776
62943
|
from: did.string(),
|
|
61777
62944
|
to: authRequest.from
|
|
61778
62945
|
};
|
|
61779
|
-
|
|
61780
|
-
|
|
61781
|
-
|
|
61782
|
-
|
|
61783
|
-
|
|
61784
|
-
}
|
|
62946
|
+
const requestScope = authRequest.body.scope;
|
|
62947
|
+
const combinedQueries = requestScope.reduce((acc, proofReq) => {
|
|
62948
|
+
const groupId = proofReq.query.groupId;
|
|
62949
|
+
if (!groupId) {
|
|
62950
|
+
return acc;
|
|
62951
|
+
}
|
|
62952
|
+
const existedData = acc.get(groupId);
|
|
62953
|
+
if (!existedData) {
|
|
62954
|
+
const seed = getRandomBytes(12);
|
|
62955
|
+
const dataView = new DataView(seed.buffer);
|
|
62956
|
+
const linkNonce = dataView.getUint32(0);
|
|
62957
|
+
acc.set(groupId, { query: proofReq.query, linkNonce });
|
|
62958
|
+
return acc;
|
|
62959
|
+
}
|
|
62960
|
+
const credentialSubject = mergeObjects(existedData.query.credentialSubject, proofReq.query.credentialSubject);
|
|
62961
|
+
acc.set(groupId, {
|
|
62962
|
+
...existedData,
|
|
62963
|
+
query: {
|
|
62964
|
+
skipClaimRevocationCheck: existedData.query.skipClaimRevocationCheck || proofReq.query.skipClaimRevocationCheck,
|
|
62965
|
+
...existedData.query,
|
|
62966
|
+
credentialSubject
|
|
62967
|
+
}
|
|
62968
|
+
});
|
|
62969
|
+
return acc;
|
|
62970
|
+
}, new Map());
|
|
62971
|
+
const groupedCredentialsCache = new Map();
|
|
62972
|
+
for (const proofReq of requestScope) {
|
|
61785
62973
|
const query = proofReq.query;
|
|
61786
|
-
const
|
|
61787
|
-
|
|
62974
|
+
const groupId = query.groupId;
|
|
62975
|
+
const combinedQueryData = combinedQueries.get(groupId);
|
|
62976
|
+
if (groupId) {
|
|
62977
|
+
if (!combinedQueryData) {
|
|
62978
|
+
throw new Error(`Invalid group id ${query.groupId}`);
|
|
62979
|
+
}
|
|
62980
|
+
const combinedQuery = combinedQueryData.query;
|
|
62981
|
+
if (!groupedCredentialsCache.has(groupId)) {
|
|
62982
|
+
const credWithRevStatus = await this._proofService.findCredentialByProofQuery(did, combinedQueryData.query);
|
|
62983
|
+
if (!credWithRevStatus.cred) {
|
|
62984
|
+
throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
|
|
62985
|
+
}
|
|
62986
|
+
groupedCredentialsCache.set(groupId, credWithRevStatus);
|
|
62987
|
+
}
|
|
62988
|
+
}
|
|
62989
|
+
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
62990
|
+
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
62991
|
+
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
62992
|
+
credential: credWithRevStatus?.cred,
|
|
62993
|
+
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
62994
|
+
linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
|
|
61788
62995
|
});
|
|
61789
62996
|
authResponse.body.scope.push(zkpRes);
|
|
61790
62997
|
}
|
|
@@ -61918,7 +63125,8 @@ class ContractRequestHandler {
|
|
|
61918
63125
|
this._zkpVerifier = _zkpVerifier;
|
|
61919
63126
|
this._allowedCircuits = [
|
|
61920
63127
|
CircuitId.AtomicQueryMTPV2OnChain,
|
|
61921
|
-
CircuitId.AtomicQuerySigV2OnChain
|
|
63128
|
+
CircuitId.AtomicQuerySigV2OnChain,
|
|
63129
|
+
CircuitId.AtomicQueryV3OnChain
|
|
61922
63130
|
];
|
|
61923
63131
|
}
|
|
61924
63132
|
/**
|
|
@@ -61952,19 +63160,28 @@ class ContractRequestHandler {
|
|
|
61952
63160
|
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
61953
63161
|
}
|
|
61954
63162
|
const zkRequests = [];
|
|
63163
|
+
const { contract_address, chain_id } = ciRequest.body.transaction_data;
|
|
63164
|
+
const networkFlag = Object.keys(ChainIds).find((key) => ChainIds[key] === chain_id);
|
|
63165
|
+
if (!networkFlag) {
|
|
63166
|
+
throw new Error(`Invalid chain id ${chain_id}`);
|
|
63167
|
+
}
|
|
63168
|
+
const [blockchain, networkId] = networkFlag.split(':');
|
|
63169
|
+
const verifierId = buildVerifierId(contract_address, {
|
|
63170
|
+
blockchain,
|
|
63171
|
+
networkId,
|
|
63172
|
+
// DidMethod.Iden3 is used based on discussions: all onchain issuers have iden3 did method by default. This can be changed in the release of v3 circuit.
|
|
63173
|
+
method: DidMethod.Iden3
|
|
63174
|
+
});
|
|
63175
|
+
const verifierDid = DID.parseFromId(verifierId);
|
|
61955
63176
|
for (const proofReq of ciRequest.body.scope) {
|
|
61956
63177
|
if (!this._allowedCircuits.includes(proofReq.circuitId)) {
|
|
61957
63178
|
throw new Error(`Can't handle circuit ${proofReq.circuitId}. Only onchain circuits are allowed.`);
|
|
61958
63179
|
}
|
|
61959
|
-
const zkpReq = {
|
|
61960
|
-
id: proofReq.id,
|
|
61961
|
-
circuitId: proofReq.circuitId,
|
|
61962
|
-
query: proofReq.query
|
|
61963
|
-
};
|
|
61964
63180
|
const query = proofReq.query;
|
|
61965
|
-
const zkpRes = await this._proofService.generateProof(
|
|
63181
|
+
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
61966
63182
|
skipRevocation: query.skipClaimRevocationCheck ?? false,
|
|
61967
|
-
challenge: opts.challenge
|
|
63183
|
+
challenge: opts.challenge,
|
|
63184
|
+
verifierDid
|
|
61968
63185
|
});
|
|
61969
63186
|
zkRequests.push(zkpRes);
|
|
61970
63187
|
}
|
|
@@ -61972,5 +63189,5 @@ class ContractRequestHandler {
|
|
|
61972
63189
|
}
|
|
61973
63190
|
}
|
|
61974
63191
|
|
|
61975
|
-
export { AbstractPrivateKeyStore, AgentResolver, AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQueryMTPV2OnChainPubSignals, AtomicQueryMTPV2PubSignals, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainCircuitInputs, AtomicQuerySigV2OnChainInputs, AtomicQuerySigV2OnChainPubSignals, AtomicQuerySigV2PubSignals, AuthHandler, AuthV2Inputs, AuthV2PubSignals, BJJSignatureProof2021, BaseConfig, BjjProvider, BrowserDataSource, CircuitClaim, CircuitError, CircuitId, CircuitStorage, ContractRequestHandler, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DataPrepareHandlerFunc, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, Iden3SparseMerkleTreeProof, IdentityStorage, IdentityWallet, InMemoryDataSource, InMemoryMerkleTreeStorage, InMemoryPrivateKeyStore, IndexedDBDataSource, IndexedDBPrivateKeyStore, IssuerResolver, JSON_SCHEMA_VALIDATORS_REGISTRY, JWSPacker, JsonSchemaValidator, KMS, KmsKeyType, LDParser, LocalStoragePrivateKeyStore, MerkleTreeIndexedDBStorage, MerkleTreeLocalStorage, MerkleTreeType, MerklizedRootPosition, NativeProver, OnChainResolver, OnChainZKPVerifier, Operators, constants as PROTOCOL_CONSTANTS, PackageManager, Parser, PlainPacker, ProofNode, ProofPurpose, ProofService, ProofType, Query, QueryOperators, RHSResolver, Scalar, SearchError, Sec256k1Provider, StandardJSONCredentialsQueryFilter, StateTransitionInputs, StateTransitionPubSignals, SubjectPosition, ValueProof, Vector, VerifiableConstants, VerificationHandlerFunc, W3CCredential, ZKPPacker,
|
|
63192
|
+
export { AbstractPrivateKeyStore, AgentResolver, AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQueryMTPV2OnChainPubSignals, AtomicQueryMTPV2PubSignals, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainCircuitInputs, AtomicQuerySigV2OnChainInputs, AtomicQuerySigV2OnChainPubSignals, AtomicQuerySigV2PubSignals, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, AtomicQueryV3OnChainPubSignals, AtomicQueryV3PubSignals, AuthHandler, AuthV2Inputs, AuthV2PubSignals, BJJSignatureProof2021, BaseConfig, BjjProvider, BrowserDataSource, CircuitClaim, CircuitError, CircuitId, CircuitStorage, ContractRequestHandler, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DataPrepareHandlerFunc, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, Iden3SparseMerkleTreeProof, IdentityStorage, IdentityWallet, InMemoryDataSource, InMemoryMerkleTreeStorage, InMemoryPrivateKeyStore, IndexedDBDataSource, IndexedDBPrivateKeyStore, IssuerResolver, JSON_SCHEMA_VALIDATORS_REGISTRY, JWSPacker, JsonSchemaValidator, KMS, KmsKeyType, LDParser, LinkedMultiQueryInputs, LinkedMultiQueryPubSignals, LinkedNullifierInputs, LinkedNullifierPubSignals, LocalStoragePrivateKeyStore, MerkleTreeIndexedDBStorage, MerkleTreeLocalStorage, MerkleTreeType, MerklizedRootPosition, NativeProver, OnChainResolver, OnChainZKPVerifier, Operators, constants as PROTOCOL_CONSTANTS, PackageManager, Parser, PlainPacker, ProofNode, ProofPurpose, ProofService, ProofType, Query, QueryOperators, RHSResolver, Scalar, SearchError, Sec256k1Provider, StandardJSONCredentialsQueryFilter, StateTransitionInputs, StateTransitionPubSignals, SubjectPosition, ValueProof, Vector, VerifiableConstants, VerificationHandlerFunc, W3CCredential, XSDNS, ZKPPacker, availableTypesOperators, base58ToBytes, base64ToBytes, base64UrlToBytes, bigIntArrayToStringArray, buildFieldPath, buildTreeState, buildVerifierId, byteDecoder, byteEncoder, bytesToBase58, bytesToBase64, bytesToBase64url, bytesToHex$1 as bytesToHex, cacheLoader, checkDataInField, comparatorOptions, createSchemaHash, createVerifiablePresentation, credentialSubjectKey, dataFillsSlot, decodeBase64url, defaultEthConnectionConfig, defaultMTLevels, defaultMTLevelsClaim, defaultMTLevelsOnChain, defaultValueArraySize, defineMerklizedRootPosition, encodeBase64url, existenceToInt, extractProof, extractPublicKeyBytes, factoryComparer, fieldToByteArray, fillSlot, findValue, generateProfileDID, getNodeAuxValue, getProperties, getUserDIDFromCredential, hexToBytes$1 as hexToBytes, isGenesisState, isGenesisStateId, isIssuerGenesis, isValidOperation, keyPath, mergeObjects, parseCredentialSubject, parseQueriesMetadata, parseQueryMetadata, prepareCircuitArrayValues, prepareSiblingsStr, pushHashesToRHS, resolvePath, resolveVerificationMethods, strMTHex, stringByPath, subjectPositionIndex, swapEndianness, toClaimNonRevStatus, toGISTProof, toRevocationStatus, transformQueryValueToBigInts };
|
|
61976
63193
|
//# sourceMappingURL=index.js.map
|