@0xpolygonid/js-sdk 1.7.5 → 1.8.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 +13041 -11748
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +13070 -11755
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2.js +3 -3
- package/dist/node/cjs/circuits/atomic-query-sig-v2.js +3 -3
- package/dist/node/cjs/circuits/auth-v2.js +1 -1
- package/dist/node/cjs/credentials/credential-wallet.js +1 -3
- package/dist/node/cjs/credentials/index.js +1 -0
- package/dist/node/cjs/credentials/models.js +2 -0
- package/dist/node/cjs/credentials/status/credential-status-publisher.js +23 -4
- package/dist/node/cjs/iden3comm/constants.js +3 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +119 -14
- package/dist/node/cjs/kms/key-providers/sec256k1-provider.js +5 -2
- package/dist/node/cjs/proof/common.js +3 -4
- package/dist/node/cjs/proof/index.js +2 -1
- package/dist/node/cjs/proof/proof-service.js +22 -2
- package/dist/node/cjs/proof/provers/index.js +19 -0
- package/dist/node/cjs/proof/{inputs-generator.js → provers/inputs-generator.js} +42 -23
- package/dist/node/cjs/proof/{prover.js → provers/prover.js} +1 -1
- package/dist/node/cjs/proof/verifiers/index.js +18 -0
- package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +344 -0
- package/dist/node/cjs/proof/verifiers/query.js +190 -0
- package/dist/node/cjs/schema-processor/json/parser.js +39 -198
- package/dist/node/cjs/schema-processor/utils.js +13 -26
- package/dist/node/cjs/storage/blockchain/state.js +53 -8
- package/dist/node/cjs/utils/compare-func.js +11 -0
- package/dist/node/cjs/utils/index.js +2 -0
- package/dist/node/cjs/utils/message-bus.js +73 -0
- package/dist/node/cjs/verifiable/core-utils.js +234 -0
- package/dist/node/cjs/verifiable/credential.js +139 -1
- package/dist/node/cjs/verifiable/index.js +1 -0
- package/dist/node/esm/circuits/atomic-query-mtp-v2.js +3 -3
- package/dist/node/esm/circuits/atomic-query-sig-v2.js +3 -3
- package/dist/node/esm/circuits/auth-v2.js +2 -2
- package/dist/node/esm/credentials/credential-wallet.js +1 -3
- package/dist/node/esm/credentials/index.js +1 -0
- package/dist/node/esm/credentials/models.js +1 -0
- package/dist/node/esm/credentials/status/credential-status-publisher.js +23 -4
- package/dist/node/esm/iden3comm/constants.js +3 -1
- package/dist/node/esm/iden3comm/handlers/auth.js +116 -13
- package/dist/node/esm/kms/key-providers/sec256k1-provider.js +5 -2
- package/dist/node/esm/proof/common.js +4 -5
- package/dist/node/esm/proof/index.js +2 -1
- package/dist/node/esm/proof/proof-service.js +22 -2
- package/dist/node/esm/proof/provers/index.js +3 -0
- package/dist/node/esm/proof/{inputs-generator.js → provers/inputs-generator.js} +39 -20
- package/dist/node/esm/proof/{prover.js → provers/prover.js} +1 -1
- package/dist/node/esm/proof/verifiers/index.js +2 -0
- package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +340 -0
- package/dist/node/esm/proof/verifiers/query.js +186 -0
- package/dist/node/esm/schema-processor/json/parser.js +40 -199
- package/dist/node/esm/schema-processor/utils.js +13 -26
- package/dist/node/esm/storage/blockchain/state.js +53 -8
- package/dist/node/esm/utils/compare-func.js +7 -0
- package/dist/node/esm/utils/index.js +2 -0
- package/dist/node/esm/utils/message-bus.js +66 -0
- package/dist/node/esm/verifiable/core-utils.js +200 -0
- package/dist/node/esm/verifiable/credential.js +118 -3
- package/dist/node/esm/verifiable/index.js +1 -0
- package/dist/types/credentials/credential-wallet.d.ts +2 -60
- package/dist/types/credentials/index.d.ts +1 -0
- package/dist/types/credentials/models.d.ts +68 -0
- package/dist/types/credentials/status/credential-status-publisher.d.ts +2 -0
- package/dist/types/iden3comm/constants.d.ts +1 -0
- package/dist/types/iden3comm/handlers/auth.d.ts +53 -13
- package/dist/types/iden3comm/types/protocol/credentials.d.ts +16 -0
- package/dist/types/identity/identity-wallet.d.ts +3 -1
- package/dist/types/kms/key-providers/sec256k1-provider.d.ts +1 -1
- package/dist/types/proof/index.d.ts +2 -1
- package/dist/types/proof/proof-service.d.ts +28 -3
- package/dist/types/proof/provers/index.d.ts +3 -0
- package/dist/types/proof/{inputs-generator.d.ts → provers/inputs-generator.d.ts} +14 -7
- package/dist/types/proof/{prover.d.ts → provers/prover.d.ts} +2 -2
- package/dist/types/proof/verifiers/index.d.ts +2 -0
- package/dist/types/proof/verifiers/pub-signals-verifier.d.ts +58 -0
- package/dist/types/proof/verifiers/query.d.ts +25 -0
- package/dist/types/schema-processor/json/parser.d.ts +47 -28
- package/dist/types/schema-processor/utils.d.ts +9 -4
- package/dist/types/storage/blockchain/state.d.ts +5 -1
- package/dist/types/storage/interfaces/state.d.ts +8 -0
- package/dist/types/utils/compare-func.d.ts +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/message-bus.d.ts +62 -0
- package/dist/types/verifiable/core-utils.d.ts +84 -0
- package/dist/types/verifiable/credential.d.ts +11 -1
- package/dist/types/verifiable/index.d.ts +1 -0
- package/dist/types/verifiable/proof.d.ts +4 -0
- package/package.json +10 -10
- /package/dist/node/cjs/proof/{witness_calculator.js → provers/witness_calculator.js} +0 -0
- /package/dist/node/esm/proof/{witness_calculator.js → provers/witness_calculator.js} +0 -0
- /package/dist/types/proof/{witness_calculator.d.ts → provers/witness_calculator.d.ts} +0 -0
|
@@ -5,6 +5,41 @@ import { proving } from '@iden3/js-jwz';
|
|
|
5
5
|
import * as uuid from 'uuid';
|
|
6
6
|
import { byteDecoder, byteEncoder, mergeObjects } from '../../utils';
|
|
7
7
|
import { getRandomBytes } from '@iden3/js-crypto';
|
|
8
|
+
/**
|
|
9
|
+
* createAuthorizationRequest is a function to create protocol authorization request
|
|
10
|
+
* @param {string} reason - reason to request proof
|
|
11
|
+
* @param {string} sender - sender did
|
|
12
|
+
* @param {string} callbackUrl - callback that user should use to send response
|
|
13
|
+
* @returns `Promise<AuthorizationRequestMessage>`
|
|
14
|
+
*/
|
|
15
|
+
export function createAuthorizationRequest(reason, sender, callbackUrl) {
|
|
16
|
+
return createAuthorizationRequestWithMessage(reason, '', sender, callbackUrl);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* createAuthorizationRequestWithMessage is a function to create protocol authorization request with explicit message to sign
|
|
20
|
+
* @param {string} reason - reason to request proof
|
|
21
|
+
* @param {string} message - message to sign in the response
|
|
22
|
+
* @param {string} sender - sender did
|
|
23
|
+
* @param {string} callbackUrl - callback that user should use to send response
|
|
24
|
+
* @returns `Promise<AuthorizationRequestMessage>`
|
|
25
|
+
*/
|
|
26
|
+
export function createAuthorizationRequestWithMessage(reason, message, sender, callbackUrl) {
|
|
27
|
+
const uuidv4 = uuid.v4();
|
|
28
|
+
const request = {
|
|
29
|
+
id: uuidv4,
|
|
30
|
+
thid: uuidv4,
|
|
31
|
+
from: sender,
|
|
32
|
+
typ: MediaType.PlainMessage,
|
|
33
|
+
type: PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
|
|
34
|
+
body: {
|
|
35
|
+
reason: reason,
|
|
36
|
+
message: message,
|
|
37
|
+
callbackUrl: callbackUrl,
|
|
38
|
+
scope: []
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return request;
|
|
42
|
+
}
|
|
8
43
|
/**
|
|
9
44
|
*
|
|
10
45
|
* Allows to process AuthorizationRequest protocol message and produce JWZ response.
|
|
@@ -26,10 +61,7 @@ export class AuthHandler {
|
|
|
26
61
|
this._proofService = _proofService;
|
|
27
62
|
}
|
|
28
63
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @public
|
|
31
|
-
* @param {Uint8Array} request - raw byte message
|
|
32
|
-
* @returns `Promise<AuthorizationRequestMessage>`
|
|
64
|
+
* @inheritdoc IAuthHandler#parseAuthorizationRequest
|
|
33
65
|
*/
|
|
34
66
|
async parseAuthorizationRequest(request) {
|
|
35
67
|
const { unpackedMessage: message } = await this._packerMgr.unpack(request);
|
|
@@ -40,15 +72,7 @@ export class AuthHandler {
|
|
|
40
72
|
return authRequest;
|
|
41
73
|
}
|
|
42
74
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @public
|
|
45
|
-
* @param {did} did - sender DID
|
|
46
|
-
* @param {Uint8Array} request - raw byte message
|
|
47
|
-
* @returns `Promise<{
|
|
48
|
-
token: string;
|
|
49
|
-
authRequest: AuthorizationRequestMessage;
|
|
50
|
-
authResponse: AuthorizationResponseMessage;
|
|
51
|
-
}>`
|
|
75
|
+
* @inheritdoc IAuthHandler#handleAuthorizationRequest
|
|
52
76
|
*/
|
|
53
77
|
async handleAuthorizationRequest(did, request, opts) {
|
|
54
78
|
const authRequest = await this.parseAuthorizationRequest(request);
|
|
@@ -145,4 +169,83 @@ export class AuthHandler {
|
|
|
145
169
|
}));
|
|
146
170
|
return { authRequest, authResponse, token };
|
|
147
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* @inheritdoc IAuthHandler#handleAuthorizationResponse
|
|
174
|
+
*/
|
|
175
|
+
async handleAuthorizationResponse(response, request, opts) {
|
|
176
|
+
if ((request.body.message ?? '') !== (response.body.message ?? '')) {
|
|
177
|
+
throw new Error('message for signing from request is not presented in response');
|
|
178
|
+
}
|
|
179
|
+
if (request.from !== response.to) {
|
|
180
|
+
throw new Error(`sender of the request is not a target of response - expected ${request.from}, given ${response.to}`);
|
|
181
|
+
}
|
|
182
|
+
this.verifyAuthRequest(request);
|
|
183
|
+
const requestScope = request.body.scope;
|
|
184
|
+
if (!response.from) {
|
|
185
|
+
throw new Error(`proof response doesn't contain from field`);
|
|
186
|
+
}
|
|
187
|
+
const groupIdToLinkIdMap = new Map();
|
|
188
|
+
// group requests by query group id
|
|
189
|
+
for (const proofRequest of requestScope) {
|
|
190
|
+
const groupId = proofRequest.query.groupId;
|
|
191
|
+
const proofResp = response.body.scope.find((resp) => resp.id === proofRequest.id);
|
|
192
|
+
if (!proofResp) {
|
|
193
|
+
throw new Error(`proof is not given for requestId ${proofRequest.id}`);
|
|
194
|
+
}
|
|
195
|
+
const circuitId = proofResp.circuitId;
|
|
196
|
+
if (circuitId !== proofRequest.circuitId) {
|
|
197
|
+
throw new Error(`proof is not given for requested circuit expected: ${proofRequest.circuitId}, given ${circuitId}`);
|
|
198
|
+
}
|
|
199
|
+
const params = proofRequest.params ?? {};
|
|
200
|
+
params.verifierDid = DID.parse(request.from);
|
|
201
|
+
const { linkID } = await this._proofService.verifyZKPResponse(proofResp, {
|
|
202
|
+
query: proofRequest.query,
|
|
203
|
+
sender: response.from,
|
|
204
|
+
params,
|
|
205
|
+
opts
|
|
206
|
+
});
|
|
207
|
+
// write linkId to the proof response
|
|
208
|
+
// const pubSig = pubSignals as unknown as { linkID?: number };
|
|
209
|
+
if (linkID && groupId) {
|
|
210
|
+
groupIdToLinkIdMap.set(groupId, [
|
|
211
|
+
...(groupIdToLinkIdMap.get(groupId) ?? []),
|
|
212
|
+
{ linkID: linkID, requestId: proofResp.id }
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// verify grouping links
|
|
217
|
+
for (const [groupId, metas] of groupIdToLinkIdMap.entries()) {
|
|
218
|
+
// check that all linkIds are the same
|
|
219
|
+
if (metas.some((meta) => meta.linkID !== metas[0].linkID)) {
|
|
220
|
+
throw new Error(`Link id validation failed for group ${groupId}, request linkID to requestIds info: ${JSON.stringify(metas)}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return { request, response };
|
|
224
|
+
}
|
|
225
|
+
verifyAuthRequest(request) {
|
|
226
|
+
const groupIdValidationMap = {};
|
|
227
|
+
const requestScope = request.body.scope;
|
|
228
|
+
for (const proofRequest of requestScope) {
|
|
229
|
+
const groupId = proofRequest.query.groupId;
|
|
230
|
+
if (groupId) {
|
|
231
|
+
const existingRequests = groupIdValidationMap[groupId] ?? [];
|
|
232
|
+
//validate that all requests in the group have the same schema, issuer and circuit
|
|
233
|
+
for (const existingRequest of existingRequests) {
|
|
234
|
+
if (existingRequest.query.type !== proofRequest.query.type) {
|
|
235
|
+
throw new Error(`all requests in the group should have the same type`);
|
|
236
|
+
}
|
|
237
|
+
if (existingRequest.query.context !== proofRequest.query.context) {
|
|
238
|
+
throw new Error(`all requests in the group should have the same context`);
|
|
239
|
+
}
|
|
240
|
+
const allowedIssuers = proofRequest.query.allowedIssuers;
|
|
241
|
+
const existingRequestAllowedIssuers = existingRequest.query.allowedIssuers;
|
|
242
|
+
if (!(allowedIssuers.includes('*') ||
|
|
243
|
+
allowedIssuers.every((issuer) => existingRequestAllowedIssuers.includes(issuer)))) {
|
|
244
|
+
throw new Error(`all requests in the group should have the same issuer`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
groupIdValidationMap[groupId] = [...(groupIdValidationMap[groupId] ?? []), proofRequest];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
148
251
|
}
|
|
@@ -24,8 +24,11 @@ export class Sec256k1Provider {
|
|
|
24
24
|
* @param {Uint8Array} seed - byte array seed
|
|
25
25
|
* @returns kms key identifier
|
|
26
26
|
*/
|
|
27
|
-
async newPrivateKeyFromSeed() {
|
|
28
|
-
|
|
27
|
+
async newPrivateKeyFromSeed(seed) {
|
|
28
|
+
if (seed.length !== 32) {
|
|
29
|
+
throw new Error('Seed should be 32 bytes');
|
|
30
|
+
}
|
|
31
|
+
const keyPair = this._ec.keyFromPrivate(seed);
|
|
29
32
|
const kmsId = {
|
|
30
33
|
type: this.keyType,
|
|
31
34
|
id: providerHelpers.keyPath(this.keyType, keyPair.getPublic().encode('hex', false))
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Hash, Proof, ZERO_HASH } from '@iden3/js-merkletree';
|
|
2
2
|
import { buildTreeState, isValidOperation, QueryOperators } from '../circuits';
|
|
3
|
-
import { buildFieldPath } from '../verifiable';
|
|
3
|
+
import { buildFieldPath, getSerializationAttrFromContext, getFieldSlotIndex } from '../verifiable';
|
|
4
4
|
import { Merklizer, Path } from '@iden3/js-jsonld-merklization';
|
|
5
|
-
import { Parser } from '../schema-processor/json';
|
|
6
5
|
import { byteEncoder } from '../utils';
|
|
7
6
|
import { poseidon } from '@iden3/js-crypto';
|
|
8
7
|
/**
|
|
@@ -60,7 +59,7 @@ export const toGISTProof = (smtProof) => {
|
|
|
60
59
|
export const parseCredentialSubject = (credentialSubject) => {
|
|
61
60
|
// credentialSubject is empty
|
|
62
61
|
if (!credentialSubject) {
|
|
63
|
-
return [{ operator: QueryOperators.$
|
|
62
|
+
return [{ operator: QueryOperators.$noop, fieldName: '' }];
|
|
64
63
|
}
|
|
65
64
|
const queries = [];
|
|
66
65
|
const entries = Object.entries(credentialSubject);
|
|
@@ -95,7 +94,7 @@ export const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentia
|
|
|
95
94
|
values: [],
|
|
96
95
|
path: new Path()
|
|
97
96
|
};
|
|
98
|
-
const serAttr = await
|
|
97
|
+
const serAttr = await getSerializationAttrFromContext(JSON.parse(ldContextJSON), options, credentialType);
|
|
99
98
|
if (!serAttr) {
|
|
100
99
|
query.merklizedSchema = true;
|
|
101
100
|
}
|
|
@@ -103,7 +102,7 @@ export const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentia
|
|
|
103
102
|
// and not a position of merklization root.
|
|
104
103
|
// it has no influence on check in the off-chain circuits, but it aligns with onchain verification standard
|
|
105
104
|
if (!query.merklizedSchema) {
|
|
106
|
-
query.slotIndex = await
|
|
105
|
+
query.slotIndex = await getFieldSlotIndex(propertyQuery.fieldName, credentialType, byteEncoder.encode(ldContextJSON));
|
|
107
106
|
}
|
|
108
107
|
else {
|
|
109
108
|
try {
|
|
@@ -4,11 +4,12 @@ import { Hash } from '@iden3/js-merkletree';
|
|
|
4
4
|
import { AuthV2Inputs, CircuitId, Operators, Query, StateTransitionInputs, ValueProof } from '../circuits';
|
|
5
5
|
import { createVerifiablePresentation } from '../verifiable';
|
|
6
6
|
import { parseCredentialSubject, parseQueryMetadata, toGISTProof, transformQueryValueToBigInts } from './common';
|
|
7
|
-
import { NativeProver } from './prover';
|
|
7
|
+
import { NativeProver } from './provers/prover';
|
|
8
8
|
import { getDocumentLoader } from '@iden3/js-jsonld-merklization';
|
|
9
9
|
import { cacheLoader } from '../schema-processor';
|
|
10
10
|
import { byteDecoder, byteEncoder } from '../utils/encoding';
|
|
11
|
-
import { InputGenerator } from './inputs-generator';
|
|
11
|
+
import { InputGenerator } from './provers/inputs-generator';
|
|
12
|
+
import { PubSignalsVerifier } from './verifiers/pub-signals-verifier';
|
|
12
13
|
/**
|
|
13
14
|
* Proof service is an implementation of IProofService
|
|
14
15
|
* that works with a native groth16 prover
|
|
@@ -32,11 +33,30 @@ export class ProofService {
|
|
|
32
33
|
this._prover = opts?.prover ?? new NativeProver(_circuitStorage);
|
|
33
34
|
this._ldOptions = { ...opts, documentLoader: opts?.documentLoader ?? cacheLoader(opts) };
|
|
34
35
|
this._inputsGenerator = new InputGenerator(_identityWallet, _credentialWallet, _stateStorage);
|
|
36
|
+
this._pubSignalsVerifier = new PubSignalsVerifier(opts?.documentLoader ?? cacheLoader(opts), _stateStorage);
|
|
35
37
|
}
|
|
36
38
|
/** {@inheritdoc IProofService.verifyProof} */
|
|
37
39
|
async verifyProof(zkp, circuitId) {
|
|
38
40
|
return this._prover.verify(zkp, circuitId);
|
|
39
41
|
}
|
|
42
|
+
/** {@inheritdoc IProofService.verify} */
|
|
43
|
+
async verifyZKPResponse(proofResp, opts) {
|
|
44
|
+
const proofValid = await this._prover.verify(proofResp, proofResp.circuitId);
|
|
45
|
+
if (!proofValid) {
|
|
46
|
+
throw Error(`Proof with circuit id ${proofResp.circuitId} and request id ${proofResp.id} is not valid`);
|
|
47
|
+
}
|
|
48
|
+
const verifyContext = {
|
|
49
|
+
pubSignals: proofResp.pub_signals,
|
|
50
|
+
query: opts.query,
|
|
51
|
+
verifiablePresentation: proofResp.vp,
|
|
52
|
+
sender: opts.sender,
|
|
53
|
+
challenge: BigInt(proofResp.id),
|
|
54
|
+
opts: opts.opts,
|
|
55
|
+
params: opts.params
|
|
56
|
+
};
|
|
57
|
+
const pubSignals = await this._pubSignalsVerifier.verify(proofResp.circuitId, verifyContext);
|
|
58
|
+
return { linkID: pubSignals.linkID };
|
|
59
|
+
}
|
|
40
60
|
/** {@inheritdoc IProofService.generateProof} */
|
|
41
61
|
async generateProof(proofReq, identifier, opts) {
|
|
42
62
|
if (!opts) {
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { DID, Id, getUnixTimestamp } from '@iden3/js-iden3-core';
|
|
2
|
-
import { ProofType } from '
|
|
3
|
-
import { AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainInputs, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, CircuitClaim, CircuitId, LinkedMultiQueryInputs, Operators } from '
|
|
4
|
-
import { toClaimNonRevStatus, toGISTProof } from '
|
|
5
|
-
import { getUserDIDFromCredential } from '
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { ProofType } from '../../verifiable';
|
|
3
|
+
import { AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainInputs, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, CircuitClaim, CircuitId, defaultValueArraySize, LinkedMultiQueryInputs, Operators, QueryOperators } from '../../circuits';
|
|
4
|
+
import { toClaimNonRevStatus, toGISTProof } from '../common';
|
|
5
|
+
import { getUserDIDFromCredential } from '../../credentials';
|
|
6
|
+
const allOperations = Object.values(QueryOperators);
|
|
7
|
+
const v2Operations = [
|
|
8
|
+
Operators.NOOP,
|
|
9
|
+
Operators.EQ,
|
|
10
|
+
Operators.LT,
|
|
11
|
+
Operators.GT,
|
|
12
|
+
Operators.IN,
|
|
13
|
+
Operators.NIN,
|
|
14
|
+
Operators.NE
|
|
15
|
+
];
|
|
16
|
+
export const circuitValidator = {
|
|
17
|
+
[CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1, supportedOperations: v2Operations },
|
|
18
|
+
[CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2Operations },
|
|
19
|
+
[CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1, supportedOperations: v2Operations },
|
|
20
|
+
[CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2Operations },
|
|
21
|
+
[CircuitId.AtomicQueryV3]: { maxQueriesCount: 1, supportedOperations: allOperations },
|
|
22
|
+
[CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1, supportedOperations: allOperations },
|
|
23
|
+
[CircuitId.AuthV2]: { maxQueriesCount: 0, supportedOperations: [] },
|
|
24
|
+
[CircuitId.StateTransition]: { maxQueriesCount: 0, supportedOperations: [] },
|
|
25
|
+
[CircuitId.LinkedMultiQuery10]: { maxQueriesCount: 10, supportedOperations: allOperations }
|
|
16
26
|
};
|
|
17
27
|
export class InputGenerator {
|
|
18
28
|
constructor(_identityWallet, _credentialWallet, _stateStorage) {
|
|
@@ -26,7 +36,7 @@ export class InputGenerator {
|
|
|
26
36
|
circuitInputs.id = DID.idFromDID(identifier);
|
|
27
37
|
circuitInputs.requestID = BigInt(proofReq.id);
|
|
28
38
|
const query = circuitQueries[0];
|
|
29
|
-
query.operator =
|
|
39
|
+
query.operator = this.transformV2QueryOperator(query.operator);
|
|
30
40
|
circuitInputs.query = query;
|
|
31
41
|
circuitInputs.claim = {
|
|
32
42
|
issuerID: circuitClaimData.issuerId,
|
|
@@ -73,7 +83,7 @@ export class InputGenerator {
|
|
|
73
83
|
circuitInputs.signature = signature;
|
|
74
84
|
circuitInputs.challenge = params.challenge;
|
|
75
85
|
const query = circuitQueries[0];
|
|
76
|
-
query.operator =
|
|
86
|
+
query.operator = this.transformV2QueryOperator(query.operator);
|
|
77
87
|
circuitInputs.query = query;
|
|
78
88
|
circuitInputs.claim = {
|
|
79
89
|
issuerID: circuitClaimData.issuerId,
|
|
@@ -103,7 +113,7 @@ export class InputGenerator {
|
|
|
103
113
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
104
114
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
105
115
|
const query = circuitQueries[0];
|
|
106
|
-
query.operator =
|
|
116
|
+
query.operator = this.transformV2QueryOperator(query.operator);
|
|
107
117
|
circuitInputs.query = query;
|
|
108
118
|
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
109
119
|
return circuitInputs.inputsMarshal();
|
|
@@ -130,7 +140,7 @@ export class InputGenerator {
|
|
|
130
140
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
131
141
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
132
142
|
const query = circuitQueries[0];
|
|
133
|
-
query.operator =
|
|
143
|
+
query.operator = this.transformV2QueryOperator(query.operator);
|
|
134
144
|
circuitInputs.query = query;
|
|
135
145
|
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
136
146
|
if (authClaimData.treeState) {
|
|
@@ -192,7 +202,10 @@ export class InputGenerator {
|
|
|
192
202
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
193
203
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
194
204
|
const query = circuitQueries[0];
|
|
195
|
-
query.values =
|
|
205
|
+
query.values =
|
|
206
|
+
query.operator === Operators.SD || query.operator === Operators.NOOP
|
|
207
|
+
? new Array(defaultValueArraySize).fill(0)
|
|
208
|
+
: query.values;
|
|
196
209
|
circuitInputs.query = query;
|
|
197
210
|
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
198
211
|
circuitInputs.proofType = proofType;
|
|
@@ -240,7 +253,10 @@ export class InputGenerator {
|
|
|
240
253
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
241
254
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
242
255
|
const query = circuitQueries[0];
|
|
243
|
-
query.values =
|
|
256
|
+
query.values =
|
|
257
|
+
query.operator === Operators.SD || query.operator === Operators.NOOP
|
|
258
|
+
? new Array(defaultValueArraySize).fill(0)
|
|
259
|
+
: query.values;
|
|
244
260
|
circuitInputs.query = query;
|
|
245
261
|
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
246
262
|
circuitInputs.proofType = proofType;
|
|
@@ -370,4 +386,7 @@ export class InputGenerator {
|
|
|
370
386
|
coreClaim: authCoreClaim
|
|
371
387
|
};
|
|
372
388
|
}
|
|
389
|
+
transformV2QueryOperator(operator) {
|
|
390
|
+
return operator === Operators.SD || operator === Operators.NOOP ? Operators.EQ : operator;
|
|
391
|
+
}
|
|
373
392
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { witnessBuilder } from './witness_calculator';
|
|
2
|
-
import { byteDecoder } from '../utils';
|
|
3
2
|
import { groth16 } from 'snarkjs';
|
|
4
3
|
import { getCurveFromName } from 'ffjavascript';
|
|
4
|
+
import { byteDecoder } from '../../utils';
|
|
5
5
|
/**
|
|
6
6
|
* NativeProver service responsible for zk generation and verification of groth16 algorithm with bn128 curve
|
|
7
7
|
* @public
|