@0xpolygonid/js-sdk 1.9.2 → 1.9.3

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.
@@ -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 } 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 checkQueryRequest(query, outs, CircuitId.AtomicQueryMTPV2, this._documentLoader, verifiablePresentation, opts);
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 checkQueryRequest(query, outs, CircuitId.AtomicQuerySigV2, this._documentLoader, verifiablePresentation, opts);
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,53 @@ 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
- await checkQueryRequest(query, outs, CircuitId.AtomicQueryV3, this._documentLoader, verifiablePresentation, opts);
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
+ await checkQueryRequest(query, queriesMetadata, context, outs, CircuitId.AtomicQueryV3, this._documentLoader, opts);
133
+ const queryMetadata = queriesMetadata[0]; // only one query is supported
134
+ // validate selective disclosure
135
+ if (queryMetadata.operator === Operators.SD) {
136
+ try {
137
+ await validateDisclosureNativeSDSupport(queryMetadata, outs, verifiablePresentation, loader);
138
+ }
139
+ catch (e) {
140
+ throw new Error(`failed to validate selective disclosure: ${e.message}`);
141
+ }
142
+ }
143
+ else if (!queryMetadata.fieldName && queryMetadata.operator == Operators.NOOP) {
144
+ try {
145
+ await validateEmptyCredentialSubjectNoopNativeSupport(outs);
146
+ }
147
+ catch (e) {
148
+ throw new Error(`failed to validate operators: ${e.message}`);
149
+ }
150
+ }
151
+ else {
152
+ try {
153
+ await validateOperators(queryMetadata, outs);
154
+ }
155
+ catch (e) {
156
+ throw new Error(`failed to validate operators: ${e.message}`);
157
+ }
158
+ }
159
+ // verify field inclusion / non-inclusion
160
+ verifyFieldValueInclusionNativeExistsSupport(outs, queryMetadata);
117
161
  const { proofType, verifierID, nullifier, nullifierSessionID, linkID } = v3PubSignals;
118
162
  switch (query.proofType) {
119
163
  case ProofType.BJJSignature:
@@ -288,6 +332,52 @@ export class PubSignalsVerifier {
288
332
  }
289
333
  return fn(ctx);
290
334
  }
335
+ async checkQueryV2Circuits(circuitId, query, outs, opts, verifiablePresentation) {
336
+ if (!query.type) {
337
+ throw new Error(`proof query type is undefined`);
338
+ }
339
+ const loader = this._documentLoader ?? getDocumentLoader();
340
+ // validate schema
341
+ let context;
342
+ try {
343
+ context = (await loader(query.context ?? '')).document;
344
+ }
345
+ catch (e) {
346
+ throw new Error(`can't load schema for request query`);
347
+ }
348
+ const queriesMetadata = await parseQueriesMetadata(query.type, JSON.stringify(context), query.credentialSubject, {
349
+ documentLoader: loader
350
+ });
351
+ await checkQueryRequest(query, queriesMetadata, context, outs, circuitId, this._documentLoader, opts);
352
+ const queryMetadata = queriesMetadata[0]; // only one query is supported
353
+ // validate selective disclosure
354
+ if (queryMetadata.operator === Operators.SD) {
355
+ try {
356
+ await validateDisclosureV2Circuit(queryMetadata, outs, verifiablePresentation, loader);
357
+ }
358
+ catch (e) {
359
+ throw new Error(`failed to validate selective disclosure: ${e.message}`);
360
+ }
361
+ }
362
+ else if (!queryMetadata.fieldName && queryMetadata.operator == Operators.NOOP) {
363
+ try {
364
+ await validateEmptyCredentialSubjectV2Circuit(queryMetadata, outs);
365
+ }
366
+ catch (e) {
367
+ throw new Error(`failed to validate operators: ${e.message}`);
368
+ }
369
+ }
370
+ else {
371
+ try {
372
+ await validateOperators(queryMetadata, outs);
373
+ }
374
+ catch (e) {
375
+ throw new Error(`failed to validate operators: ${e.message}`);
376
+ }
377
+ }
378
+ // verify field inclusion
379
+ verifyFieldValueInclusionV2(outs, queryMetadata);
380
+ }
291
381
  async resolve(id, state) {
292
382
  const idBigInt = id.bigInt();
293
383
  const did = DID.parseFromId(id);
@@ -1,12 +1,11 @@
1
1
  import { DID, getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
2
- import { getDocumentLoader, Merklizer, Path } from '@iden3/js-jsonld-merklization';
2
+ import { Merklizer, Path } from '@iden3/js-jsonld-merklization';
3
3
  import { byteEncoder } from '../../utils';
4
- import { Operators } from '../../circuits/comparer';
4
+ import { 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, verifiablePresentation, opts) {
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(`proof query type is undefined`);
17
+ throw new Error('query type is missing');
28
18
  }
29
- const schemaId = await Path.getTypeIDFromContext(JSON.stringify(schema), query.type, {
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,9 +26,6 @@ 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
- const queriesMetadata = await parseQueriesMetadata(query.type, JSON.stringify(schema), query.credentialSubject, {
40
- documentLoader: schemaLoader
41
- });
42
29
  const circuitValidationData = circuitValidator[circuitId];
43
30
  if (queriesMetadata.length > circuitValidationData.maxQueriesCount) {
44
31
  throw new Error(`circuit ${circuitId} supports only ${circuitValidator[circuitId].maxQueriesCount} queries`);
@@ -47,64 +34,54 @@ export async function checkQueryRequest(query, outputs, circuitId, schemaLoader,
47
34
  if (notSupportedOpIndx > -1) {
48
35
  throw new Error(`circuit ${circuitId} not support ${queriesMetadata[notSupportedOpIndx].operator} operator`);
49
36
  }
50
- for (let i = 0; i < queriesMetadata.length; i++) {
51
- const metadata = queriesMetadata[i];
52
- if (!query.type) {
53
- throw new Error(`proof query type is undefined`);
54
- }
55
- // validate selective disclosure
56
- if (metadata.operator === Operators.SD) {
57
- try {
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
- }
37
+ // verify timestamp
38
+ let acceptedProofGenerationDelay = defaultProofGenerationDelayOpts;
39
+ if (opts?.acceptedProofGenerationDelay) {
40
+ acceptedProofGenerationDelay = opts.acceptedProofGenerationDelay;
41
+ }
42
+ const timeDiff = Date.now() - getDateFromUnixTimestamp(Number(outputs.timestamp)).getTime();
43
+ if (timeDiff > acceptedProofGenerationDelay) {
44
+ throw new Error('generated proof is outdated');
45
+ }
46
+ return;
47
+ }
48
+ export function verifyFieldValueInclusionV2(outputs, metadata) {
49
+ if (outputs.operator == QueryOperators.$noop) {
50
+ return;
51
+ }
52
+ if (outputs.merklized === 1) {
53
+ if (outputs.claimPathNotExists === 1) {
54
+ throw new Error(`proof doesn't contains target query key`);
80
55
  }
81
- // verify claim
82
- if (outputs.merklized === 1) {
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
- }
56
+ if (outputs.claimPathKey !== metadata.claimPathKey) {
57
+ throw new Error(`proof was generated for another path`);
89
58
  }
90
- else {
91
- if (outputs.slotIndex !== metadata.slotIndex) {
92
- throw new Error(`wrong claim slot was used in claim`);
93
- }
59
+ }
60
+ else {
61
+ if (outputs.slotIndex !== metadata.slotIndex) {
62
+ throw new Error(`wrong claim slot was used in claim`);
94
63
  }
95
- // verify timestamp
96
- let acceptedProofGenerationDelay = defaultProofGenerationDelayOpts;
97
- if (opts?.acceptedProofGenerationDelay) {
98
- acceptedProofGenerationDelay = opts.acceptedProofGenerationDelay;
64
+ }
65
+ }
66
+ export function verifyFieldValueInclusionNativeExistsSupport(outputs, metadata) {
67
+ if (outputs.operator == Operators.NOOP) {
68
+ return;
69
+ }
70
+ if (outputs.operator === Operators.EXISTS && !outputs.merklized) {
71
+ throw new Error('$exists operator is not supported for non-merklized credential');
72
+ }
73
+ if (outputs.merklized === 1) {
74
+ if (outputs.claimPathKey !== metadata.claimPathKey) {
75
+ throw new Error(`proof was generated for another path`);
99
76
  }
100
- const timeDiff = Date.now() - getDateFromUnixTimestamp(Number(outputs.timestamp)).getTime();
101
- if (timeDiff > acceptedProofGenerationDelay) {
102
- throw new Error('generated proof is outdated');
77
+ }
78
+ else {
79
+ if (outputs.slotIndex !== metadata.slotIndex) {
80
+ throw new Error(`wrong claim slot was used in claim`);
103
81
  }
104
82
  }
105
- return;
106
83
  }
107
- async function validateEmptyCredentialSubject(cq, outputs) {
84
+ export async function validateEmptyCredentialSubjectV2Circuit(cq, outputs) {
108
85
  if (outputs.operator !== Operators.EQ) {
109
86
  throw new Error('empty credentialSubject request available only for equal operation');
110
87
  }
@@ -120,7 +97,7 @@ async function validateEmptyCredentialSubject(cq, outputs) {
120
97
  }
121
98
  return;
122
99
  }
123
- async function validateOperators(cq, outputs) {
100
+ export async function validateOperators(cq, outputs) {
124
101
  if (outputs.operator !== cq.operator) {
125
102
  throw new Error(`operator that was used is not equal to request`);
126
103
  }
@@ -137,7 +114,11 @@ async function validateOperators(cq, outputs) {
137
114
  }
138
115
  }
139
116
  }
140
- async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader) {
117
+ export async function validateDisclosureV2Circuit(cq, outputs, verifiablePresentation, ldLoader) {
118
+ const bi = await fieldValueFromVerifiablePresentation(cq.fieldName, verifiablePresentation, ldLoader);
119
+ if (bi !== outputs.value[0]) {
120
+ throw new Error(`value that was used is not equal to requested in query`);
121
+ }
141
122
  if (outputs.operator !== Operators.EQ) {
142
123
  throw new Error(`operator for selective disclosure must be $eq`);
143
124
  }
@@ -146,9 +127,29 @@ async function validateDisclosure(cq, outputs, verifiablePresentation, ldLoader)
146
127
  throw new Error(`selective disclosure not available for array of values`);
147
128
  }
148
129
  }
130
+ }
131
+ export async function validateDisclosureNativeSDSupport(cq, outputs, verifiablePresentation, ldLoader) {
149
132
  const bi = await fieldValueFromVerifiablePresentation(cq.fieldName, verifiablePresentation, ldLoader);
150
- if (bi !== outputs.value[0]) {
151
- throw new Error(`value that was used is not equal to requested in query`);
133
+ if (bi !== outputs.operatorOutput) {
134
+ throw new Error(`operator output should be equal to disclosed value`);
135
+ }
136
+ if (outputs.operator !== Operators.SD) {
137
+ throw new Error(`operator for selective disclosure must be $sd`);
138
+ }
139
+ for (let index = 0; index < outputs.value.length; index++) {
140
+ if (outputs.value[index] !== 0n) {
141
+ throw new Error(`public signal values must be zero`);
142
+ }
143
+ }
144
+ }
145
+ export async function validateEmptyCredentialSubjectNoopNativeSupport(outputs) {
146
+ if (outputs.operator !== Operators.NOOP) {
147
+ throw new Error('empty credentialSubject request available only for $noop operation');
148
+ }
149
+ for (let index = 1; index < outputs.value.length; index++) {
150
+ if (outputs.value[index] !== 0n) {
151
+ throw new Error(`empty credentialSubject request not available for array of values`);
152
+ }
152
153
  }
153
154
  }
154
155
  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
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './bjj-provider';
2
+ export * from './ed25519-provider';
2
3
  export * from './sec256k1-provider';
@@ -5,7 +5,8 @@
5
5
  */
6
6
  export declare enum KmsKeyType {
7
7
  BabyJubJub = "BJJ",
8
- Secp256k1 = "Secp256k1"
8
+ Secp256k1 = "Secp256k1",
9
+ Ed25519 = "Ed25519"
9
10
  }
10
11
  /**
11
12
  * ID of the key that describe contain key type
@@ -48,5 +48,6 @@ export declare class InputGenerator {
48
48
  private credentialAtomicQueryV3OnChainPrepareInputs;
49
49
  private linkedMultiQuery10PrepareInputs;
50
50
  private transformV2QueryOperator;
51
+ private checkOperatorSupport;
51
52
  }
52
53
  export {};
@@ -49,6 +49,7 @@ export declare class PubSignalsVerifier {
49
49
  private authV2Verify;
50
50
  private linkedMultiQuery10Verify;
51
51
  private verifyIdOwnership;
52
+ private checkQueryV2Circuits;
52
53
  private resolve;
53
54
  private rootResolve;
54
55
  private checkStateExistenceForId;
@@ -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,12 @@ 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, verifiablePresentation?: JSON, opts?: VerifyOpts): Promise<void>;
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 verifyFieldValueInclusionV2(outputs: ClaimOutputs, metadata: QueryMetadata): void;
30
+ export declare function verifyFieldValueInclusionNativeExistsSupport(outputs: ClaimOutputs, metadata: QueryMetadata): void;
31
+ export declare function validateEmptyCredentialSubjectV2Circuit(cq: QueryMetadata, outputs: ClaimOutputs): Promise<void>;
32
+ export declare function validateOperators(cq: QueryMetadata, outputs: ClaimOutputs): Promise<void>;
33
+ export declare function validateDisclosureV2Circuit(cq: QueryMetadata, outputs: ClaimOutputs, verifiablePresentation?: JSON, ldLoader?: DocumentLoader): Promise<void>;
34
+ export declare function validateDisclosureNativeSDSupport(cq: QueryMetadata, outputs: ClaimOutputs, verifiablePresentation?: JSON, ldLoader?: DocumentLoader): Promise<void>;
35
+ export declare function validateEmptyCredentialSubjectNoopNativeSupport(outputs: ClaimOutputs): Promise<void>;
26
36
  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.2",
3
+ "version": "1.9.3",
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",
@@ -94,6 +94,7 @@
94
94
  "snarkjs": "0.7.3"
95
95
  },
96
96
  "dependencies": {
97
+ "@noble/curves": "^1.4.0",
97
98
  "ajv": "8.12.0",
98
99
  "ajv-formats": "2.1.1",
99
100
  "did-jwt": "6.11.6",