@0xpolygonid/js-sdk 1.8.2 → 1.9.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.
Files changed (54) hide show
  1. package/dist/browser/esm/index.js +240 -124
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +243 -124
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +8 -25
  6. package/dist/node/cjs/circuits/atomic-query-v3.js +6 -5
  7. package/dist/node/cjs/circuits/common.js +1 -1
  8. package/dist/node/cjs/circuits/comparer.js +24 -3
  9. package/dist/node/cjs/circuits/linked-multi-query.js +6 -17
  10. package/dist/node/cjs/circuits/models.js +47 -3
  11. package/dist/node/cjs/iden3comm/handlers/auth.js +5 -3
  12. package/dist/node/cjs/iden3comm/handlers/contract-request.js +3 -11
  13. package/dist/node/cjs/proof/common.js +11 -5
  14. package/dist/node/cjs/proof/provers/inputs-generator.js +6 -10
  15. package/dist/node/cjs/proof/verifiers/index.js +1 -0
  16. package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +37 -22
  17. package/dist/node/cjs/proof/verifiers/query-hash.js +40 -0
  18. package/dist/node/cjs/proof/verifiers/query.js +24 -16
  19. package/dist/node/cjs/schema-processor/utils.js +2 -2
  20. package/dist/node/cjs/storage/filters/jsonQuery.js +28 -2
  21. package/dist/node/cjs/verifiable/core-utils.js +3 -3
  22. package/dist/node/cjs/verifiable/credential.js +1 -1
  23. package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +9 -26
  24. package/dist/node/esm/circuits/atomic-query-v3.js +7 -6
  25. package/dist/node/esm/circuits/common.js +1 -1
  26. package/dist/node/esm/circuits/comparer.js +24 -3
  27. package/dist/node/esm/circuits/linked-multi-query.js +7 -18
  28. package/dist/node/esm/circuits/models.js +48 -4
  29. package/dist/node/esm/iden3comm/handlers/auth.js +5 -3
  30. package/dist/node/esm/iden3comm/handlers/contract-request.js +4 -12
  31. package/dist/node/esm/proof/common.js +12 -6
  32. package/dist/node/esm/proof/provers/inputs-generator.js +7 -11
  33. package/dist/node/esm/proof/verifiers/index.js +1 -0
  34. package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +41 -26
  35. package/dist/node/esm/proof/verifiers/query-hash.js +35 -0
  36. package/dist/node/esm/proof/verifiers/query.js +23 -16
  37. package/dist/node/esm/schema-processor/utils.js +3 -3
  38. package/dist/node/esm/storage/filters/jsonQuery.js +28 -2
  39. package/dist/node/esm/verifiable/core-utils.js +1 -1
  40. package/dist/node/esm/verifiable/credential.js +2 -2
  41. package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +4 -8
  42. package/dist/types/circuits/atomic-query-v3.d.ts +2 -2
  43. package/dist/types/circuits/common.d.ts +1 -1
  44. package/dist/types/circuits/comparer.d.ts +4 -0
  45. package/dist/types/circuits/linked-multi-query.d.ts +0 -1
  46. package/dist/types/circuits/models.d.ts +7 -4
  47. package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -0
  48. package/dist/types/proof/verifiers/index.d.ts +1 -0
  49. package/dist/types/proof/verifiers/query-hash.d.ts +3 -0
  50. package/dist/types/proof/verifiers/query.d.ts +1 -0
  51. package/dist/types/schema-processor/utils.d.ts +1 -1
  52. package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
  53. package/dist/types/verifiable/core-utils.d.ts +1 -1
  54. package/package.json +1 -1
@@ -66,6 +66,19 @@ const lessThanOrEqual = (a, b) => {
66
66
  }
67
67
  return a <= b;
68
68
  };
69
+ // a - field value
70
+ // b - true / false (exists operator values)
71
+ const existsComparator = (a, b) => {
72
+ if (truthyValues.includes(b) && typeof a !== 'undefined') {
73
+ // if exists val is true , a field val exists
74
+ return true;
75
+ }
76
+ // if exists val is false , a field val doesn't exist
77
+ if (falsyValues.includes(b) && (a === undefined || (Array.isArray(a) && !a.length))) {
78
+ return true;
79
+ }
80
+ return false;
81
+ };
69
82
  const inOperator = (a, b) => {
70
83
  if (Array.isArray(a) && Array.isArray(b)) {
71
84
  return a.every((val) => b.includes(val));
@@ -78,9 +91,19 @@ const inOperator = (a, b) => {
78
91
  }
79
92
  return false;
80
93
  };
94
+ const betweenOperator = (a, b) => {
95
+ if (!Array.isArray(b) || b.length !== 2) {
96
+ throw new Error('$between/$nonbetween operator value should be 2 elements array');
97
+ }
98
+ if (Array.isArray(a)) {
99
+ return a.every((val) => val >= b[0] && val <= b[1]);
100
+ }
101
+ return a >= b[0] && a <= b[1];
102
+ };
81
103
  export const comparatorOptions = {
82
104
  $noop: () => true,
83
105
  $sd: () => true,
106
+ $exists: (a, b) => existsComparator(a, b),
84
107
  $eq: (a, b) => equalsComparator(a, b),
85
108
  $in: (a, b) => inOperator(a, b),
86
109
  $nin: (a, b) => !inOperator(a, b),
@@ -88,7 +111,9 @@ export const comparatorOptions = {
88
111
  $lt: (a, b) => !greaterThan(a, b),
89
112
  $ne: (a, b) => !equalsComparator(a, b),
90
113
  $gte: (a, b) => greaterThanOrEqual(a, b),
91
- $lte: (a, b) => lessThanOrEqual(a, b)
114
+ $lte: (a, b) => lessThanOrEqual(a, b),
115
+ $between: (a, b) => betweenOperator(a, b),
116
+ $nonbetween: (a, b) => !betweenOperator(a, b)
92
117
  };
93
118
  /**
94
119
  * credential search path resolver
@@ -136,7 +161,8 @@ export class FilterQuery {
136
161
  throw new Error(SearchError.NotDefinedComparator);
137
162
  }
138
163
  const credentialPathValue = resolvePath(credential, this.path);
139
- if (credentialPathValue === null || credentialPathValue === undefined) {
164
+ if ((credentialPathValue === null || credentialPathValue === undefined) &&
165
+ this.operatorFunc !== existsComparator) {
140
166
  return false;
141
167
  }
142
168
  if (this.isReverseParams) {
@@ -194,7 +194,7 @@ export const parseCoreClaimSlots = async (ldCtx, mz, credentialType) => {
194
194
  * @param {Uint8Array} schemaId
195
195
  * @returns {*} {SchemaHash}
196
196
  */
197
- export const caclulateCoreSchemaHash = (schemaId) => {
197
+ export const calculateCoreSchemaHash = (schemaId) => {
198
198
  const sHash = Hex.decodeString(keccak256(schemaId));
199
199
  return new SchemaHash(sHash.slice(sHash.length - 16, sHash.length));
200
200
  };
@@ -7,7 +7,7 @@ import { PublicKey, poseidon } from '@iden3/js-crypto';
7
7
  import { getUserDIDFromCredential } from '../credentials/utils';
8
8
  import { byteEncoder, validateDIDDocumentAuth } from '../utils';
9
9
  import { MerklizedRootPosition, ProofType, SubjectPosition } from './constants';
10
- import { caclulateCoreSchemaHash, findCredentialType, parseCoreClaimSlots } from './core-utils';
10
+ import { calculateCoreSchemaHash, findCredentialType, parseCoreClaimSlots } from './core-utils';
11
11
  import * as jsonld from 'jsonld/lib';
12
12
  import * as ldcontext from 'jsonld/lib/context';
13
13
  /**
@@ -119,7 +119,7 @@ export class W3CCredential {
119
119
  if (!nonMerklized && opts.merklizedRootPosition === MerklizedRootPosition.None) {
120
120
  opts.merklizedRootPosition = MerklizedRootPosition.Index;
121
121
  }
122
- const schemaHash = caclulateCoreSchemaHash(byteEncoder.encode(credentialType));
122
+ const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(credentialType));
123
123
  const claim = Claim.newClaim(schemaHash, ClaimOptions.withIndexDataBytes(slots.indexA, slots.indexB), ClaimOptions.withValueDataBytes(slots.valueA, slots.valueB), ClaimOptions.withRevocationNonce(BigInt(opts.revNonce)), ClaimOptions.withVersion(opts.version));
124
124
  if (opts.updatable) {
125
125
  claim.setFlagUpdatable(opts.updatable);
@@ -32,7 +32,7 @@ export declare class AtomicQueryV3OnChainInputs extends BaseConfig {
32
32
  linkNonce: bigint;
33
33
  verifierID?: Id;
34
34
  nullifierSessionID: bigint;
35
- authEnabled: number;
35
+ isBJJAuthEnabled: number;
36
36
  validate(): void;
37
37
  fillMTPProofsWithZero(s: Partial<AtomicQueryV3OnChainCircuitInputs>): void;
38
38
  fillSigProofWithZero(s: Partial<AtomicQueryV3OnChainCircuitInputs>): void;
@@ -73,7 +73,6 @@ interface AtomicQueryV3OnChainCircuitInputs {
73
73
  issuerAuthRootsTreeRoot: string;
74
74
  issuerAuthState: string;
75
75
  isRevocationChecked: number;
76
- claimPathNotExists: number;
77
76
  claimPathMtp: string[];
78
77
  claimPathMtpNoAux: string;
79
78
  claimPathMtpAuxHi: string;
@@ -84,6 +83,7 @@ interface AtomicQueryV3OnChainCircuitInputs {
84
83
  slotIndex: number;
85
84
  timestamp: number;
86
85
  value: string[];
86
+ valueArraySize: number;
87
87
  issuerClaimMtp: string[];
88
88
  issuerClaimClaimsTreeRoot: string;
89
89
  issuerClaimRevTreeRoot: string;
@@ -112,7 +112,7 @@ interface AtomicQueryV3OnChainCircuitInputs {
112
112
  linkNonce: string;
113
113
  verifierID: string;
114
114
  nullifierSessionID: string;
115
- authEnabled: string;
115
+ isBJJAuthEnabled: string;
116
116
  }
117
117
  /**
118
118
  * @beta
@@ -125,8 +125,6 @@ export declare class AtomicQueryV3OnChainPubSignals extends BaseConfig {
125
125
  issuerState: Hash;
126
126
  issuerClaimNonRevState: Hash;
127
127
  timestamp: number;
128
- merklized: number;
129
- isRevocationChecked: number;
130
128
  circuitQueryHash: bigint;
131
129
  challenge: bigint;
132
130
  gistRoot: Hash;
@@ -134,9 +132,7 @@ export declare class AtomicQueryV3OnChainPubSignals extends BaseConfig {
134
132
  linkID: bigint;
135
133
  nullifier: bigint;
136
134
  operatorOutput: bigint;
137
- verifierID: Id;
138
- nullifierSessionID: bigint;
139
- authEnabled: number;
135
+ isBJJAuthEnabled: number;
140
136
  pubSignalsUnmarshal(data: Uint8Array): AtomicQueryV3OnChainPubSignals;
141
137
  }
142
138
  export {};
@@ -69,7 +69,6 @@ interface AtomicQueryV3CircuitInputs {
69
69
  issuerAuthRootsTreeRoot: string;
70
70
  issuerAuthState: string;
71
71
  isRevocationChecked: number;
72
- claimPathNotExists: number;
73
72
  claimPathMtp: string[];
74
73
  claimPathMtpNoAux: string;
75
74
  claimPathMtpAuxHi: string;
@@ -80,6 +79,7 @@ interface AtomicQueryV3CircuitInputs {
80
79
  slotIndex: number;
81
80
  timestamp: number;
82
81
  value: string[];
82
+ valueArraySize: number;
83
83
  issuerClaimMtp: string[];
84
84
  issuerClaimClaimsTreeRoot: string;
85
85
  issuerClaimRevTreeRoot: string;
@@ -104,10 +104,10 @@ export declare class AtomicQueryV3PubSignals extends BaseConfig {
104
104
  slotIndex: number;
105
105
  operator: number;
106
106
  value: bigint[];
107
+ valueArraySize: number;
107
108
  timestamp: number;
108
109
  merklized: number;
109
110
  claimPathKey: bigint;
110
- claimPathNotExists: number;
111
111
  isRevocationChecked: number;
112
112
  proofType: number;
113
113
  linkID: bigint;
@@ -21,7 +21,7 @@ export declare const ErrorEmptyIssuerAuthClaimNonRevProof = "empty issuer auth c
21
21
  */
22
22
  export declare class BaseConfig {
23
23
  mtLevel: number;
24
- valueArraySize: number;
24
+ maxValueArraySize: number;
25
25
  mtLevelOnChain: number;
26
26
  mtLevelClaim: number;
27
27
  /**
@@ -28,6 +28,8 @@ export declare enum Operators {
28
28
  LTE = 7,
29
29
  GTE = 8,
30
30
  BETWEEN = 9,
31
+ NONBETWEEN = 10,
32
+ EXISTS = 11,
31
33
  SD = 16,
32
34
  NULLIFY = 17
33
35
  }
@@ -43,6 +45,8 @@ export declare const QueryOperators: {
43
45
  $lte: Operators;
44
46
  $gte: Operators;
45
47
  $between: Operators;
48
+ $nonbetween: Operators;
49
+ $exists: Operators;
46
50
  $sd: Operators;
47
51
  $nullify: Operators;
48
52
  };
@@ -26,7 +26,6 @@ export declare class LinkedMultiQueryPubSignals {
26
26
  merklized: number;
27
27
  operatorOutput: bigint[];
28
28
  circuitQueryHash: bigint[];
29
- enabled: boolean[];
30
29
  /**
31
30
  * PubSignalsUnmarshal unmarshal linkedMultiQuery10.circom public inputs to LinkedMultiQueryPubSignals
32
31
  *
@@ -40,6 +40,7 @@ export declare class Query {
40
40
  *
41
41
  */
42
42
  validate(): void;
43
+ validateValueArraySize(maxArrSize: number): void;
43
44
  }
44
45
  /**
45
46
  * CircuitID is alias for circuit identifier
@@ -56,15 +57,15 @@ export declare enum CircuitId {
56
57
  /**
57
58
  * @beta
58
59
  */
59
- AtomicQueryV3 = "credentialAtomicQueryV3-beta.0",
60
+ AtomicQueryV3 = "credentialAtomicQueryV3-beta.1",
60
61
  /**
61
62
  * @beta
62
63
  */
63
- AtomicQueryV3OnChain = "credentialAtomicQueryV3OnChain-beta.0",
64
+ AtomicQueryV3OnChain = "credentialAtomicQueryV3OnChain-beta.1",
64
65
  /**
65
66
  * @beta
66
67
  */
67
- LinkedMultiQuery10 = "linkedMultiQuery10-beta.0"
68
+ LinkedMultiQuery10 = "linkedMultiQuery10-beta.1"
68
69
  }
69
70
  /**
70
71
  * Claim structure for circuit inputs
@@ -161,7 +162,9 @@ export declare enum CircuitError {
161
162
  EmptyGISTProof = "empty GIST merkle tree proof",
162
163
  EmptyTreeState = "empty tree state",
163
164
  EmptyRequestID = "empty request ID",
164
- InvalidProofType = "invalid proof type"
165
+ InvalidProofType = "invalid proof type",
166
+ InvalidValuesArrSize = "invalid query Values array size",
167
+ InvalidOperationType = "invalid operation type"
165
168
  }
166
169
  /**
167
170
  * ValueProof represents a Merkle Proof for a value stored as MT
@@ -6,6 +6,7 @@ export type ContractInvokeRequest = {
6
6
  type: string;
7
7
  thid: string;
8
8
  body: ContractInvokeRequestBody;
9
+ from?: string;
9
10
  };
10
11
  /** ContractInvokeRequestBody represents structure of contract invoke request body object */
11
12
  export type ContractInvokeRequestBody = {
@@ -1,2 +1,3 @@
1
1
  export * from './pub-signals-verifier';
2
2
  export * from './query';
3
+ export * from './query-hash';
@@ -0,0 +1,3 @@
1
+ import { SchemaHash } from '@iden3/js-iden3-core';
2
+ export declare function calculateQueryHashV2(values: bigint[], schema: SchemaHash, slotIndex: string | number, operator: string | number, claimPathKey: string | number, claimPathNotExists: string | number): bigint;
3
+ export declare function calculateQueryHashV3(values: bigint[], schema: SchemaHash, slotIndex: string | number, operator: string | number, claimPathKey: string | number, valueArraySize: string | number, merklized: string | number, isRevocationChecked: string | number, verifierID: string | number, nullifierSessionID: string | number): bigint;
@@ -23,3 +23,4 @@ export interface ClaimOutputs {
23
23
  isRevocationChecked: number;
24
24
  }
25
25
  export declare function checkQueryRequest(query: ProofQuery, outputs: ClaimOutputs, circuitId: CircuitId, schemaLoader?: DocumentLoader, verifiablePresentation?: JSON, opts?: VerifyOpts): Promise<void>;
26
+ export declare const fieldValueFromVerifiablePresentation: (fieldName: string, verifiablePresentation?: JSON, ldLoader?: DocumentLoader) => Promise<bigint>;
@@ -32,7 +32,7 @@ export declare function dataFillsSlot(slot: Uint8Array, newData: Uint8Array): bo
32
32
  export declare function checkDataInField(data: Uint8Array): boolean;
33
33
  /**
34
34
  *
35
- * @deprecated The method should not be used. Use caclulateCoreSchemaHash from verifiable.
35
+ * @deprecated The method should not be used. Use calculateCoreSchemaHash from verifiable.
36
36
  * Calculates schema hash
37
37
  *
38
38
  * @param {Uint8Array} schemaId
@@ -9,7 +9,7 @@ export declare enum SearchError {
9
9
  NotDefinedComparator = "not defined comparator"
10
10
  }
11
11
  /** allowed operators to search */
12
- export type FilterOperatorMethod = '$noop' | '$eq' | '$in' | '$nin' | '$gt' | '$lt' | '$ne' | '$gte' | '$lte' | '$sd';
12
+ export type FilterOperatorMethod = '$noop' | '$eq' | '$in' | '$nin' | '$gt' | '$lt' | '$ne' | '$gte' | '$lte' | '$sd' | '$exists' | '$between' | '$nonbetween';
13
13
  /** filter function type */
14
14
  export type FilterOperatorFunction = (a: any, b: any) => boolean;
15
15
  /**
@@ -81,4 +81,4 @@ export declare const parseCoreClaimSlots: (ldCtx: {
81
81
  * @param {Uint8Array} schemaId
82
82
  * @returns {*} {SchemaHash}
83
83
  */
84
- export declare const caclulateCoreSchemaHash: (schemaId: Uint8Array) => SchemaHash;
84
+ export declare const calculateCoreSchemaHash: (schemaId: Uint8Array) => SchemaHash;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
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",