@0xpolygonid/js-sdk 1.9.2 → 1.9.4
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 +2989 -1220
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +2956 -1176
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/comparer.js +6 -1
- package/dist/node/cjs/kms/key-providers/ed25519-provider.js +96 -0
- package/dist/node/cjs/kms/key-providers/index.js +1 -0
- package/dist/node/cjs/kms/store/types.js +1 -0
- package/dist/node/cjs/proof/provers/inputs-generator.js +16 -1
- package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +96 -3
- package/dist/node/cjs/proof/verifiers/query.js +90 -75
- package/dist/node/esm/circuits/comparer.js +4 -0
- package/dist/node/esm/kms/key-providers/ed25519-provider.js +69 -0
- package/dist/node/esm/kms/key-providers/index.js +1 -0
- package/dist/node/esm/kms/store/types.js +1 -0
- package/dist/node/esm/proof/provers/inputs-generator.js +17 -2
- package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +98 -5
- package/dist/node/esm/proof/verifiers/query.js +82 -76
- package/dist/types/circuits/comparer.d.ts +1 -0
- package/dist/types/kms/key-providers/ed25519-provider.d.ts +44 -0
- package/dist/types/kms/key-providers/index.d.ts +1 -0
- package/dist/types/kms/store/types.d.ts +2 -1
- package/dist/types/proof/provers/inputs-generator.d.ts +1 -0
- package/dist/types/proof/verifiers/pub-signals-verifier.d.ts +1 -0
- package/dist/types/proof/verifiers/query.d.ts +13 -1
- package/package.json +5 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DID, Id, getUnixTimestamp } from '@iden3/js-iden3-core';
|
|
2
2
|
import { ProofType } from '../../verifiable';
|
|
3
|
-
import { AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainInputs, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, CircuitClaim, CircuitId, LinkedMultiQueryInputs, Operators, QueryOperators, ValueProof } from '../../circuits';
|
|
3
|
+
import { AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainInputs, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, CircuitClaim, CircuitId, LinkedMultiQueryInputs, Operators, QueryOperators, ValueProof, getOperatorNameByValue } from '../../circuits';
|
|
4
4
|
import { toClaimNonRevStatus, toGISTProof } from '../common';
|
|
5
5
|
import { getUserDIDFromCredential } from '../../credentials';
|
|
6
6
|
const allOperations = Object.values(QueryOperators);
|
|
@@ -48,6 +48,7 @@ export class InputGenerator {
|
|
|
48
48
|
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
49
49
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
50
50
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
51
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
51
52
|
return circuitInputs.inputsMarshal();
|
|
52
53
|
};
|
|
53
54
|
this.credentialAtomicQueryMTPV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
@@ -95,6 +96,7 @@ export class InputGenerator {
|
|
|
95
96
|
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
96
97
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
97
98
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
99
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
98
100
|
return circuitInputs.inputsMarshal();
|
|
99
101
|
};
|
|
100
102
|
this.credentialAtomicQuerySigV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
@@ -116,6 +118,7 @@ export class InputGenerator {
|
|
|
116
118
|
query.operator = this.transformV2QueryOperator(query.operator);
|
|
117
119
|
circuitInputs.query = query;
|
|
118
120
|
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
121
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
119
122
|
return circuitInputs.inputsMarshal();
|
|
120
123
|
};
|
|
121
124
|
this.credentialAtomicQuerySigV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
@@ -163,6 +166,7 @@ export class InputGenerator {
|
|
|
163
166
|
const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
|
|
164
167
|
circuitInputs.signature = signature;
|
|
165
168
|
circuitInputs.challenge = params.challenge;
|
|
169
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
166
170
|
return circuitInputs.inputsMarshal();
|
|
167
171
|
};
|
|
168
172
|
this.credentialAtomicQueryV3PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
@@ -212,6 +216,7 @@ export class InputGenerator {
|
|
|
212
216
|
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
|
|
213
217
|
? BigInt(proofReq.params?.nullifierSessionId?.toString())
|
|
214
218
|
: BigInt(0);
|
|
219
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
215
220
|
return circuitInputs.inputsMarshal();
|
|
216
221
|
};
|
|
217
222
|
this.credentialAtomicQueryV3OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
@@ -290,15 +295,19 @@ export class InputGenerator {
|
|
|
290
295
|
circuitInputs.treeState = authClaimData.treeState;
|
|
291
296
|
circuitInputs.signature = signature;
|
|
292
297
|
}
|
|
298
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
293
299
|
return circuitInputs.inputsMarshal();
|
|
294
300
|
};
|
|
295
|
-
this.linkedMultiQuery10PrepareInputs = async ({ preparedCredential, params, circuitQueries }) => {
|
|
301
|
+
this.linkedMultiQuery10PrepareInputs = async ({ preparedCredential, params, proofReq, circuitQueries }) => {
|
|
296
302
|
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
297
303
|
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
298
304
|
const circuitInputs = new LinkedMultiQueryInputs();
|
|
299
305
|
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
300
306
|
circuitInputs.claim = circuitClaimData.claim;
|
|
301
307
|
circuitInputs.query = circuitQueries;
|
|
308
|
+
circuitQueries.forEach((query) => {
|
|
309
|
+
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
310
|
+
});
|
|
302
311
|
return circuitInputs.inputsMarshal();
|
|
303
312
|
};
|
|
304
313
|
}
|
|
@@ -383,4 +392,10 @@ export class InputGenerator {
|
|
|
383
392
|
transformV2QueryOperator(operator) {
|
|
384
393
|
return operator === Operators.SD || operator === Operators.NOOP ? Operators.EQ : operator;
|
|
385
394
|
}
|
|
395
|
+
checkOperatorSupport(circuitId, operator) {
|
|
396
|
+
const supportedOperators = circuitValidator[circuitId].supportedOperations;
|
|
397
|
+
if (!supportedOperators.includes(operator)) {
|
|
398
|
+
throw new Error(`operator ${getOperatorNameByValue(operator)} is not supported by ${circuitId}`);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
386
401
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DID, getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
|
|
2
|
-
import { Path } from '@iden3/js-jsonld-merklization';
|
|
2
|
+
import { getDocumentLoader, Path } from '@iden3/js-jsonld-merklization';
|
|
3
3
|
import { byteEncoder, isGenesisState } from '../../utils';
|
|
4
4
|
import { calculateCoreSchemaHash, ProofType } from '../../verifiable';
|
|
5
5
|
import { AtomicQueryMTPV2PubSignals } from '../../circuits/atomic-query-mtp-v2';
|
|
@@ -9,7 +9,7 @@ import { AuthV2PubSignals } from '../../circuits/auth-v2';
|
|
|
9
9
|
import { BaseConfig } from '../../circuits/common';
|
|
10
10
|
import { LinkedMultiQueryPubSignals, LinkedMultiQueryInputs } from '../../circuits/linked-multi-query';
|
|
11
11
|
import { CircuitId } from '../../circuits/models';
|
|
12
|
-
import { checkQueryRequest, fieldValueFromVerifiablePresentation } from './query';
|
|
12
|
+
import { checkQueryRequest, fieldValueFromVerifiablePresentation, validateDisclosureV2Circuit, validateEmptyCredentialSubjectV2Circuit, validateOperators, verifyFieldValueInclusionV2, validateDisclosureNativeSDSupport, validateEmptyCredentialSubjectNoopNativeSupport, verifyFieldValueInclusionNativeExistsSupport, checkCircuitOperator } from './query';
|
|
13
13
|
import { parseQueriesMetadata } from '../common';
|
|
14
14
|
import { Operators } from '../../circuits';
|
|
15
15
|
import { calculateQueryHashV3 } from './query-hash';
|
|
@@ -56,7 +56,7 @@ export class PubSignalsVerifier {
|
|
|
56
56
|
valueArraySize: mtpv2PubSignals.getValueArrSize(),
|
|
57
57
|
isRevocationChecked: mtpv2PubSignals.isRevocationChecked
|
|
58
58
|
};
|
|
59
|
-
await
|
|
59
|
+
await this.checkQueryV2Circuits(CircuitId.AtomicQueryMTPV2, query, outs, opts, verifiablePresentation);
|
|
60
60
|
// verify state
|
|
61
61
|
await this.checkStateExistenceForId(mtpv2PubSignals.issuerID, mtpv2PubSignals.issuerClaimIdenState);
|
|
62
62
|
if (mtpv2PubSignals.isRevocationChecked !== 0) {
|
|
@@ -85,7 +85,7 @@ export class PubSignalsVerifier {
|
|
|
85
85
|
valueArraySize: sigV2PubSignals.getValueArrSize(),
|
|
86
86
|
isRevocationChecked: sigV2PubSignals.isRevocationChecked
|
|
87
87
|
};
|
|
88
|
-
await
|
|
88
|
+
await this.checkQueryV2Circuits(CircuitId.AtomicQuerySigV2, query, outs, opts, verifiablePresentation);
|
|
89
89
|
// verify state
|
|
90
90
|
await this.checkStateExistenceForId(sigV2PubSignals.issuerID, sigV2PubSignals.issuerAuthState);
|
|
91
91
|
if (sigV2PubSignals.isRevocationChecked !== 0) {
|
|
@@ -111,9 +111,55 @@ export class PubSignalsVerifier {
|
|
|
111
111
|
merklized: v3PubSignals.merklized,
|
|
112
112
|
claimPathKey: v3PubSignals.claimPathKey,
|
|
113
113
|
valueArraySize: v3PubSignals.getValueArrSize(),
|
|
114
|
+
operatorOutput: v3PubSignals.operatorOutput,
|
|
114
115
|
isRevocationChecked: v3PubSignals.isRevocationChecked
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
+
if (!query.type) {
|
|
118
|
+
throw new Error(`proof query type is undefined`);
|
|
119
|
+
}
|
|
120
|
+
const loader = this._documentLoader ?? getDocumentLoader();
|
|
121
|
+
// validate schema
|
|
122
|
+
let context;
|
|
123
|
+
try {
|
|
124
|
+
context = (await loader(query.context ?? '')).document;
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
throw new Error(`can't load schema for request query`);
|
|
128
|
+
}
|
|
129
|
+
const queriesMetadata = await parseQueriesMetadata(query.type, JSON.stringify(context), query.credentialSubject, {
|
|
130
|
+
documentLoader: loader
|
|
131
|
+
});
|
|
132
|
+
const circuitId = CircuitId.AtomicQueryV3;
|
|
133
|
+
await checkQueryRequest(query, queriesMetadata, context, outs, circuitId, this._documentLoader, opts);
|
|
134
|
+
const queryMetadata = queriesMetadata[0]; // only one query is supported
|
|
135
|
+
checkCircuitOperator(circuitId, outs.operator);
|
|
136
|
+
// validate selective disclosure
|
|
137
|
+
if (queryMetadata.operator === Operators.SD) {
|
|
138
|
+
try {
|
|
139
|
+
await validateDisclosureNativeSDSupport(queryMetadata, outs, verifiablePresentation, loader);
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
throw new Error(`failed to validate selective disclosure: ${e.message}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (!queryMetadata.fieldName && queryMetadata.operator == Operators.NOOP) {
|
|
146
|
+
try {
|
|
147
|
+
await validateEmptyCredentialSubjectNoopNativeSupport(outs);
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
throw new Error(`failed to validate operators: ${e.message}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
try {
|
|
155
|
+
await validateOperators(queryMetadata, outs);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
throw new Error(`failed to validate operators: ${e.message}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// verify field inclusion / non-inclusion
|
|
162
|
+
verifyFieldValueInclusionNativeExistsSupport(outs, queryMetadata);
|
|
117
163
|
const { proofType, verifierID, nullifier, nullifierSessionID, linkID } = v3PubSignals;
|
|
118
164
|
switch (query.proofType) {
|
|
119
165
|
case ProofType.BJJSignature:
|
|
@@ -288,6 +334,53 @@ export class PubSignalsVerifier {
|
|
|
288
334
|
}
|
|
289
335
|
return fn(ctx);
|
|
290
336
|
}
|
|
337
|
+
async checkQueryV2Circuits(circuitId, query, outs, opts, verifiablePresentation) {
|
|
338
|
+
if (!query.type) {
|
|
339
|
+
throw new Error(`proof query type is undefined`);
|
|
340
|
+
}
|
|
341
|
+
const loader = this._documentLoader ?? getDocumentLoader();
|
|
342
|
+
// validate schema
|
|
343
|
+
let context;
|
|
344
|
+
try {
|
|
345
|
+
context = (await loader(query.context ?? '')).document;
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
throw new Error(`can't load schema for request query`);
|
|
349
|
+
}
|
|
350
|
+
const queriesMetadata = await parseQueriesMetadata(query.type, JSON.stringify(context), query.credentialSubject, {
|
|
351
|
+
documentLoader: loader
|
|
352
|
+
});
|
|
353
|
+
await checkQueryRequest(query, queriesMetadata, context, outs, circuitId, this._documentLoader, opts);
|
|
354
|
+
const queryMetadata = queriesMetadata[0]; // only one query is supported
|
|
355
|
+
checkCircuitOperator(circuitId, outs.operator);
|
|
356
|
+
// validate selective disclosure
|
|
357
|
+
if (queryMetadata.operator === Operators.SD) {
|
|
358
|
+
try {
|
|
359
|
+
await validateDisclosureV2Circuit(queryMetadata, outs, verifiablePresentation, loader);
|
|
360
|
+
}
|
|
361
|
+
catch (e) {
|
|
362
|
+
throw new Error(`failed to validate selective disclosure: ${e.message}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (!queryMetadata.fieldName && queryMetadata.operator == Operators.NOOP) {
|
|
366
|
+
try {
|
|
367
|
+
await validateEmptyCredentialSubjectV2Circuit(queryMetadata, outs);
|
|
368
|
+
}
|
|
369
|
+
catch (e) {
|
|
370
|
+
throw new Error(`failed to validate operators: ${e.message}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
try {
|
|
375
|
+
await validateOperators(queryMetadata, outs);
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
throw new Error(`failed to validate operators: ${e.message}`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// verify field inclusion
|
|
382
|
+
verifyFieldValueInclusionV2(outs, queryMetadata);
|
|
383
|
+
}
|
|
291
384
|
async resolve(id, state) {
|
|
292
385
|
const idBigInt = id.bigInt();
|
|
293
386
|
const did = DID.parseFromId(id);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { DID, getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
|
|
2
|
-
import {
|
|
2
|
+
import { Merklizer, Path } from '@iden3/js-jsonld-merklization';
|
|
3
3
|
import { byteEncoder } from '../../utils';
|
|
4
|
-
import { Operators } from '../../circuits/comparer';
|
|
4
|
+
import { getOperatorNameByValue, Operators, QueryOperators } from '../../circuits/comparer';
|
|
5
5
|
import { calculateCoreSchemaHash, VerifiableConstants } from '../../verifiable';
|
|
6
|
-
import { parseQueriesMetadata } from '../common';
|
|
7
6
|
import { circuitValidator } from '../provers';
|
|
8
7
|
const defaultProofGenerationDelayOpts = 24 * 60 * 60 * 1000; // 24 hours
|
|
9
|
-
export async function checkQueryRequest(query, outputs, circuitId, schemaLoader,
|
|
8
|
+
export async function checkQueryRequest(query, queriesMetadata, ldContext, outputs, circuitId, schemaLoader, opts) {
|
|
10
9
|
// validate issuer
|
|
11
10
|
const userDID = DID.parseFromId(outputs.issuerId);
|
|
12
11
|
const issuerAllowed = !query.allowedIssuers ||
|
|
@@ -14,19 +13,10 @@ export async function checkQueryRequest(query, outputs, circuitId, schemaLoader,
|
|
|
14
13
|
if (!issuerAllowed) {
|
|
15
14
|
throw new Error('issuer is not in allowed list');
|
|
16
15
|
}
|
|
17
|
-
// validate schema
|
|
18
|
-
let schema;
|
|
19
|
-
try {
|
|
20
|
-
const loader = schemaLoader ?? getDocumentLoader();
|
|
21
|
-
schema = (await loader(query.context ?? '')).document;
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
throw new Error(`can't load schema for request query`);
|
|
25
|
-
}
|
|
26
16
|
if (!query.type) {
|
|
27
|
-
throw new Error(
|
|
17
|
+
throw new Error('query type is missing');
|
|
28
18
|
}
|
|
29
|
-
const schemaId = await Path.getTypeIDFromContext(JSON.stringify(
|
|
19
|
+
const schemaId = await Path.getTypeIDFromContext(JSON.stringify(ldContext), query.type, {
|
|
30
20
|
documentLoader: schemaLoader
|
|
31
21
|
});
|
|
32
22
|
const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(schemaId));
|
|
@@ -36,75 +26,67 @@ export async function checkQueryRequest(query, outputs, circuitId, schemaLoader,
|
|
|
36
26
|
if (!query.skipClaimRevocationCheck && outputs.isRevocationChecked === 0) {
|
|
37
27
|
throw new Error(`check revocation is required`);
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
checkCircuitQueriesLength(circuitId, queriesMetadata);
|
|
30
|
+
// verify timestamp
|
|
31
|
+
let acceptedProofGenerationDelay = defaultProofGenerationDelayOpts;
|
|
32
|
+
if (opts?.acceptedProofGenerationDelay) {
|
|
33
|
+
acceptedProofGenerationDelay = opts.acceptedProofGenerationDelay;
|
|
34
|
+
}
|
|
35
|
+
const timeDiff = Date.now() - getDateFromUnixTimestamp(Number(outputs.timestamp)).getTime();
|
|
36
|
+
if (timeDiff > acceptedProofGenerationDelay) {
|
|
37
|
+
throw new Error('generated proof is outdated');
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
export function checkCircuitQueriesLength(circuitId, queriesMetadata) {
|
|
42
42
|
const circuitValidationData = circuitValidator[circuitId];
|
|
43
43
|
if (queriesMetadata.length > circuitValidationData.maxQueriesCount) {
|
|
44
44
|
throw new Error(`circuit ${circuitId} supports only ${circuitValidator[circuitId].maxQueriesCount} queries`);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
}
|
|
47
|
+
export function checkCircuitOperator(circuitId, operator) {
|
|
48
|
+
const circuitValidationData = circuitValidator[circuitId];
|
|
49
|
+
if (!circuitValidationData.supportedOperations.includes(operator)) {
|
|
50
|
+
throw new Error(`circuit ${circuitId} not support ${getOperatorNameByValue(operator)} operator`);
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
await validateDisclosure(metadata, outputs, verifiablePresentation, schemaLoader);
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
throw new Error(`failed to validate selective disclosure: ${e.message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (!metadata.fieldName && metadata.operator == Operators.NOOP) {
|
|
65
|
-
try {
|
|
66
|
-
await validateEmptyCredentialSubject(metadata, outputs);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
throw new Error(`failed to validate operators: ${e.message}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
try {
|
|
75
|
-
await validateOperators(metadata, outputs);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
throw new Error(`failed to validate operators: ${e.message}`);
|
|
79
|
-
}
|
|
52
|
+
}
|
|
53
|
+
export function verifyFieldValueInclusionV2(outputs, metadata) {
|
|
54
|
+
if (outputs.operator == QueryOperators.$noop) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (outputs.merklized === 1) {
|
|
58
|
+
if (outputs.claimPathNotExists === 1) {
|
|
59
|
+
throw new Error(`proof doesn't contains target query key`);
|
|
80
60
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (outputs.claimPathNotExists === 1) {
|
|
84
|
-
throw new Error(`proof doesn't contains target query key`);
|
|
85
|
-
}
|
|
86
|
-
if (outputs.claimPathKey !== metadata.claimPathKey) {
|
|
87
|
-
throw new Error(`proof was generated for another path`);
|
|
88
|
-
}
|
|
61
|
+
if (outputs.claimPathKey !== metadata.claimPathKey) {
|
|
62
|
+
throw new Error(`proof was generated for another path`);
|
|
89
63
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (outputs.slotIndex !== metadata.slotIndex) {
|
|
67
|
+
throw new Error(`wrong claim slot was used in claim`);
|
|
94
68
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function verifyFieldValueInclusionNativeExistsSupport(outputs, metadata) {
|
|
72
|
+
if (outputs.operator == Operators.NOOP) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (outputs.operator === Operators.EXISTS && !outputs.merklized) {
|
|
76
|
+
throw new Error('$exists operator is not supported for non-merklized credential');
|
|
77
|
+
}
|
|
78
|
+
if (outputs.merklized === 1) {
|
|
79
|
+
if (outputs.claimPathKey !== metadata.claimPathKey) {
|
|
80
|
+
throw new Error(`proof was generated for another path`);
|
|
99
81
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (outputs.slotIndex !== metadata.slotIndex) {
|
|
85
|
+
throw new Error(`wrong claim slot was used in claim`);
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
|
-
return;
|
|
106
88
|
}
|
|
107
|
-
async function
|
|
89
|
+
export async function validateEmptyCredentialSubjectV2Circuit(cq, outputs) {
|
|
108
90
|
if (outputs.operator !== Operators.EQ) {
|
|
109
91
|
throw new Error('empty credentialSubject request available only for equal operation');
|
|
110
92
|
}
|
|
@@ -120,7 +102,7 @@ async function validateEmptyCredentialSubject(cq, outputs) {
|
|
|
120
102
|
}
|
|
121
103
|
return;
|
|
122
104
|
}
|
|
123
|
-
async function validateOperators(cq, outputs) {
|
|
105
|
+
export async function validateOperators(cq, outputs) {
|
|
124
106
|
if (outputs.operator !== cq.operator) {
|
|
125
107
|
throw new Error(`operator that was used is not equal to request`);
|
|
126
108
|
}
|
|
@@ -137,7 +119,11 @@ async function validateOperators(cq, outputs) {
|
|
|
137
119
|
}
|
|
138
120
|
}
|
|
139
121
|
}
|
|
140
|
-
async function
|
|
122
|
+
export async function validateDisclosureV2Circuit(cq, outputs, verifiablePresentation, ldLoader) {
|
|
123
|
+
const bi = await fieldValueFromVerifiablePresentation(cq.fieldName, verifiablePresentation, ldLoader);
|
|
124
|
+
if (bi !== outputs.value[0]) {
|
|
125
|
+
throw new Error(`value that was used is not equal to requested in query`);
|
|
126
|
+
}
|
|
141
127
|
if (outputs.operator !== Operators.EQ) {
|
|
142
128
|
throw new Error(`operator for selective disclosure must be $eq`);
|
|
143
129
|
}
|
|
@@ -146,9 +132,29 @@ async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader)
|
|
|
146
132
|
throw new Error(`selective disclosure not available for array of values`);
|
|
147
133
|
}
|
|
148
134
|
}
|
|
135
|
+
}
|
|
136
|
+
export async function validateDisclosureNativeSDSupport(cq, outputs, verifiablePresentation, ldLoader) {
|
|
149
137
|
const bi = await fieldValueFromVerifiablePresentation(cq.fieldName, verifiablePresentation, ldLoader);
|
|
150
|
-
if (bi !== outputs.
|
|
151
|
-
throw new Error(`
|
|
138
|
+
if (bi !== outputs.operatorOutput) {
|
|
139
|
+
throw new Error(`operator output should be equal to disclosed value`);
|
|
140
|
+
}
|
|
141
|
+
if (outputs.operator !== Operators.SD) {
|
|
142
|
+
throw new Error(`operator for selective disclosure must be $sd`);
|
|
143
|
+
}
|
|
144
|
+
for (let index = 0; index < outputs.value.length; index++) {
|
|
145
|
+
if (outputs.value[index] !== 0n) {
|
|
146
|
+
throw new Error(`public signal values must be zero`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export async function validateEmptyCredentialSubjectNoopNativeSupport(outputs) {
|
|
151
|
+
if (outputs.operator !== Operators.NOOP) {
|
|
152
|
+
throw new Error('empty credentialSubject request available only for $noop operation');
|
|
153
|
+
}
|
|
154
|
+
for (let index = 1; index < outputs.value.length; index++) {
|
|
155
|
+
if (outputs.value[index] !== 0n) {
|
|
156
|
+
throw new Error(`empty credentialSubject request not available for array of values`);
|
|
157
|
+
}
|
|
152
158
|
}
|
|
153
159
|
}
|
|
154
160
|
export const fieldValueFromVerifiablePresentation = async (fieldName, verifiablePresentation, ldLoader) => {
|
|
@@ -50,6 +50,7 @@ export declare const QueryOperators: {
|
|
|
50
50
|
$sd: Operators;
|
|
51
51
|
$nullify: Operators;
|
|
52
52
|
};
|
|
53
|
+
export declare const getOperatorNameByValue: (operator: number) => string;
|
|
53
54
|
export declare const availableTypesOperators: Map<string, Operators[]>;
|
|
54
55
|
/**
|
|
55
56
|
* Checks if the given operation is valid for the specified datatype.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IKeyProvider } from '../kms';
|
|
2
|
+
import { AbstractPrivateKeyStore, KmsKeyId, KmsKeyType } from '../store';
|
|
3
|
+
/**
|
|
4
|
+
* Provider for Ed25519 keys
|
|
5
|
+
* @public
|
|
6
|
+
* @class Ed25519Provider
|
|
7
|
+
* @implements IKeyProvider interface
|
|
8
|
+
*/
|
|
9
|
+
export declare class Ed25519Provider implements IKeyProvider {
|
|
10
|
+
readonly keyType: KmsKeyType;
|
|
11
|
+
private readonly _keyStore;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of Ed25519Provider.
|
|
14
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
15
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
16
|
+
*/
|
|
17
|
+
constructor(keyType: KmsKeyType, _keyStore: AbstractPrivateKeyStore);
|
|
18
|
+
/**
|
|
19
|
+
* generates a ed25519 key from a seed phrase
|
|
20
|
+
* @param {Uint8Array} seed - byte array seed
|
|
21
|
+
* @returns {Promise<KmsKeyId>} kms key identifier
|
|
22
|
+
*/
|
|
23
|
+
newPrivateKeyFromSeed(seed: Uint8Array): Promise<KmsKeyId>;
|
|
24
|
+
/**
|
|
25
|
+
* Gets public key by kmsKeyId
|
|
26
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
27
|
+
* @returns {Promise<string>} Public key as a hex string
|
|
28
|
+
*/
|
|
29
|
+
publicKey(keyId: KmsKeyId): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* signs prepared payload of size,
|
|
32
|
+
* with a key id
|
|
33
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
34
|
+
* @param {Uint8Array} data - data to sign (32 bytes)
|
|
35
|
+
* @returns {Promise<Uint8Array>} signature
|
|
36
|
+
*/
|
|
37
|
+
sign(keyId: KmsKeyId, data: Uint8Array): Promise<Uint8Array>;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the private key for a given keyId from the key store.
|
|
40
|
+
* @param {KmsKeyId} keyId - The identifier of the key to retrieve.
|
|
41
|
+
* @returns {Promise<string>} The private key associated with the keyId.
|
|
42
|
+
*/
|
|
43
|
+
private privateKey;
|
|
44
|
+
}
|
|
@@ -2,6 +2,8 @@ import { Id, SchemaHash } from '@iden3/js-iden3-core';
|
|
|
2
2
|
import { DocumentLoader } from '@iden3/js-jsonld-merklization';
|
|
3
3
|
import { CircuitId } from '../../circuits/models';
|
|
4
4
|
import { ProofQuery } from '../../verifiable';
|
|
5
|
+
import { QueryMetadata } from '../common';
|
|
6
|
+
import { JsonLd } from 'jsonld/jsonld-spec';
|
|
5
7
|
/**
|
|
6
8
|
* Options to verify state
|
|
7
9
|
*/
|
|
@@ -14,6 +16,7 @@ export interface ClaimOutputs {
|
|
|
14
16
|
schemaHash: SchemaHash;
|
|
15
17
|
slotIndex?: number;
|
|
16
18
|
operator: number;
|
|
19
|
+
operatorOutput?: bigint;
|
|
17
20
|
value: bigint[];
|
|
18
21
|
timestamp: number;
|
|
19
22
|
merklized: number;
|
|
@@ -22,5 +25,14 @@ export interface ClaimOutputs {
|
|
|
22
25
|
valueArraySize: number;
|
|
23
26
|
isRevocationChecked: number;
|
|
24
27
|
}
|
|
25
|
-
export declare function checkQueryRequest(query: ProofQuery, outputs: ClaimOutputs, circuitId: CircuitId, schemaLoader?: DocumentLoader,
|
|
28
|
+
export declare function checkQueryRequest(query: ProofQuery, queriesMetadata: QueryMetadata[], ldContext: JsonLd, outputs: ClaimOutputs, circuitId: CircuitId, schemaLoader?: DocumentLoader, opts?: VerifyOpts): Promise<void>;
|
|
29
|
+
export declare function checkCircuitQueriesLength(circuitId: CircuitId, queriesMetadata: QueryMetadata[]): void;
|
|
30
|
+
export declare function checkCircuitOperator(circuitId: CircuitId, operator: number): void;
|
|
31
|
+
export declare function verifyFieldValueInclusionV2(outputs: ClaimOutputs, metadata: QueryMetadata): void;
|
|
32
|
+
export declare function verifyFieldValueInclusionNativeExistsSupport(outputs: ClaimOutputs, metadata: QueryMetadata): void;
|
|
33
|
+
export declare function validateEmptyCredentialSubjectV2Circuit(cq: QueryMetadata, outputs: ClaimOutputs): Promise<void>;
|
|
34
|
+
export declare function validateOperators(cq: QueryMetadata, outputs: ClaimOutputs): Promise<void>;
|
|
35
|
+
export declare function validateDisclosureV2Circuit(cq: QueryMetadata, outputs: ClaimOutputs, verifiablePresentation?: JSON, ldLoader?: DocumentLoader): Promise<void>;
|
|
36
|
+
export declare function validateDisclosureNativeSDSupport(cq: QueryMetadata, outputs: ClaimOutputs, verifiablePresentation?: JSON, ldLoader?: DocumentLoader): Promise<void>;
|
|
37
|
+
export declare function validateEmptyCredentialSubjectNoopNativeSupport(outputs: ClaimOutputs): Promise<void>;
|
|
26
38
|
export declare const fieldValueFromVerifiablePresentation: (fieldName: string, verifiablePresentation?: JSON, ldLoader?: DocumentLoader) => Promise<bigint>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xpolygonid/js-sdk",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.4",
|
|
4
4
|
"description": "SDK to work with Polygon ID",
|
|
5
5
|
"main": "dist/node/cjs/index.js",
|
|
6
6
|
"module": "dist/node/esm/index.js",
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
"require": "./dist/node/cjs/index.js"
|
|
12
12
|
},
|
|
13
13
|
"browser": "./dist/browser/esm/index.js",
|
|
14
|
-
"umd": "./dist/browser/umd/index.js"
|
|
14
|
+
"umd": "./dist/browser/umd/index.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
|
-
"
|
|
18
|
+
"types": "dist/types/index.d.ts",
|
|
18
19
|
"source": "./src/index.ts",
|
|
19
20
|
"files": [
|
|
20
21
|
"dist"
|
|
@@ -94,6 +95,7 @@
|
|
|
94
95
|
"snarkjs": "0.7.3"
|
|
95
96
|
},
|
|
96
97
|
"dependencies": {
|
|
98
|
+
"@noble/curves": "^1.4.0",
|
|
97
99
|
"ajv": "8.12.0",
|
|
98
100
|
"ajv-formats": "2.1.1",
|
|
99
101
|
"did-jwt": "6.11.6",
|