@0xpolygonid/js-sdk 1.17.3 → 1.17.5

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.
@@ -8,7 +8,7 @@ const utils_1 = require("../../utils");
8
8
  * Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
9
9
  *
10
10
  * @param requestScope - An array of ZeroKnowledgeProofRequest objects.
11
- * @returns A Map<number, { query: JSONObject; linkNonce: number }> representing the grouped queries.
11
+ * @returns A Map<number, { query: JsonDocumentObject; linkNonce: number }> representing the grouped queries.
12
12
  */
13
13
  const getGroupedQueries = (requestScope) => requestScope.reduce((acc, proofReq) => {
14
14
  const groupId = proofReq.query.groupId;
@@ -741,6 +741,7 @@ class IdentityWallet {
741
741
  break;
742
742
  }
743
743
  catch (err) {
744
+ // eslint-disable-next-line no-console
744
745
  console.warn(`Error while transiting state, retrying state transition, attempt: ${attempt}`, err);
745
746
  }
746
747
  } while (--attempt);
@@ -176,12 +176,6 @@ class EthStateStorage {
176
176
  }
177
177
  getStateContractAndProviderForId(id) {
178
178
  const idTyped = js_iden3_core_1.Id.fromBigInt(id);
179
- if (!Array.isArray(this.ethConfig)) {
180
- return {
181
- stateContract: this.stateContract,
182
- provider: this.provider
183
- };
184
- }
185
179
  const chainId = (0, js_iden3_core_1.getChainId)(js_iden3_core_1.DID.blockchainFromId(idTyped), js_iden3_core_1.DID.networkIdFromId(idTyped));
186
180
  const config = this.networkByChainId(chainId);
187
181
  const provider = new ethers_1.JsonRpcProvider(config.url);
@@ -189,14 +183,12 @@ class EthStateStorage {
189
183
  return { stateContract, provider };
190
184
  }
191
185
  networkByChainId(chainId) {
192
- if (Array.isArray(this.ethConfig)) {
193
- const network = this.ethConfig.find((c) => c.chainId === chainId);
194
- if (!network) {
195
- throw new Error(`chainId "${chainId}" not supported`);
196
- }
197
- return network;
186
+ const config = Array.isArray(this.ethConfig) ? this.ethConfig : [this.ethConfig];
187
+ const network = config.find((c) => c.chainId === chainId);
188
+ if (!network) {
189
+ throw new Error(`chainId "${chainId}" not supported`);
198
190
  }
199
- return this.ethConfig;
191
+ return network;
200
192
  }
201
193
  }
202
194
  exports.EthStateStorage = EthStateStorage;
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * Merges two objects together, prioritizing the properties of the second object.
4
+ * If a property exists in both objects, the value from the second object will be used.
5
+ * @param credSubject - The first object to merge.
6
+ * @param otherCredSubject - The second object to merge.
7
+ * @returns A new object with the merged properties.
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.mergeObjects = void 0;
4
11
  function mergeObjects(credSubject, otherCredSubject) {
@@ -5,7 +5,7 @@ import { mergeObjects } from '../../utils';
5
5
  * Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
6
6
  *
7
7
  * @param requestScope - An array of ZeroKnowledgeProofRequest objects.
8
- * @returns A Map<number, { query: JSONObject; linkNonce: number }> representing the grouped queries.
8
+ * @returns A Map<number, { query: JsonDocumentObject; linkNonce: number }> representing the grouped queries.
9
9
  */
10
10
  const getGroupedQueries = (requestScope) => requestScope.reduce((acc, proofReq) => {
11
11
  const groupId = proofReq.query.groupId;
@@ -715,6 +715,7 @@ export class IdentityWallet {
715
715
  break;
716
716
  }
717
717
  catch (err) {
718
+ // eslint-disable-next-line no-console
718
719
  console.warn(`Error while transiting state, retrying state transition, attempt: ${attempt}`, err);
719
720
  }
720
721
  } while (--attempt);
@@ -170,12 +170,6 @@ export class EthStateStorage {
170
170
  }
171
171
  getStateContractAndProviderForId(id) {
172
172
  const idTyped = Id.fromBigInt(id);
173
- if (!Array.isArray(this.ethConfig)) {
174
- return {
175
- stateContract: this.stateContract,
176
- provider: this.provider
177
- };
178
- }
179
173
  const chainId = getChainId(DID.blockchainFromId(idTyped), DID.networkIdFromId(idTyped));
180
174
  const config = this.networkByChainId(chainId);
181
175
  const provider = new JsonRpcProvider(config.url);
@@ -183,13 +177,11 @@ export class EthStateStorage {
183
177
  return { stateContract, provider };
184
178
  }
185
179
  networkByChainId(chainId) {
186
- if (Array.isArray(this.ethConfig)) {
187
- const network = this.ethConfig.find((c) => c.chainId === chainId);
188
- if (!network) {
189
- throw new Error(`chainId "${chainId}" not supported`);
190
- }
191
- return network;
180
+ const config = Array.isArray(this.ethConfig) ? this.ethConfig : [this.ethConfig];
181
+ const network = config.find((c) => c.chainId === chainId);
182
+ if (!network) {
183
+ throw new Error(`chainId "${chainId}" not supported`);
192
184
  }
193
- return this.ethConfig;
185
+ return network;
194
186
  }
195
187
  }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Merges two objects together, prioritizing the properties of the second object.
3
+ * If a property exists in both objects, the value from the second object will be used.
4
+ * @param credSubject - The first object to merge.
5
+ * @param otherCredSubject - The second object to merge.
6
+ * @returns A new object with the merged properties.
7
+ */
1
8
  export function mergeObjects(credSubject, otherCredSubject) {
2
9
  let result = {};
3
10
  const credSubjectKeys = Object.keys(credSubject);
@@ -1,3 +1,4 @@
1
+ import { JsonDocumentObject } from '../iden3comm';
1
2
  import { CredentialStatusType, MerklizedRootPosition, RefreshService, SubjectPosition } from '../verifiable';
2
3
  /**
3
4
  * Represents the publish mode for identity wallet.
@@ -25,9 +26,7 @@ export interface CredentialRequest {
25
26
  /**
26
27
  * Credential subject, usually contains claims and identifier
27
28
  */
28
- credentialSubject: {
29
- [key: string]: string | object | number | boolean;
30
- };
29
+ credentialSubject: JsonDocumentObject;
31
30
  /**
32
31
  * expiration time
33
32
  */
@@ -1,4 +1,4 @@
1
- import { BasicMessage, IPackageManager, JSONObject, PackerParams } from '../types';
1
+ import { BasicMessage, IPackageManager, JsonDocumentObject, PackerParams } from '../types';
2
2
  import { DID } from '@iden3/js-iden3-core';
3
3
  import { Proposal, ProposalRequestCredential, ProposalRequestMessage, ProposalMessage } from '../types/protocol/proposal-request';
4
4
  import { IIdentityWallet } from '../../identity';
@@ -8,9 +8,9 @@ export type ProposalRequestCreationOptions = {
8
8
  credentials: ProposalRequestCredential[];
9
9
  metadata?: {
10
10
  type: string;
11
- data?: JSONObject;
11
+ data?: JsonDocumentObject;
12
12
  };
13
- did_doc?: JSONObject;
13
+ did_doc?: JsonDocumentObject;
14
14
  };
15
15
  /**
16
16
  * @beta
@@ -19,6 +19,16 @@ export type JSONValue = string | number | boolean | object | Array<object>;
19
19
  export type JSONObject = {
20
20
  [x: string]: JSONValue;
21
21
  };
22
+ /**
23
+ * JSON document object
24
+ */
25
+ export type JsonDocumentObject = {
26
+ [key: string]: JsonDocumentObjectValue;
27
+ };
28
+ /**
29
+ * JSON document object allowed values
30
+ */
31
+ export type JsonDocumentObjectValue = string | number | boolean | JsonDocumentObject | JsonDocumentObjectValue[];
22
32
  export type BasicMessage = {
23
33
  id: string;
24
34
  typ?: MediaType;
@@ -1,5 +1,5 @@
1
1
  import { ZKProof } from '@iden3/js-jwz';
2
- import { BasicMessage, JSONObject } from '../packer';
2
+ import { BasicMessage, JsonDocumentObject } from '../packer';
3
3
  import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
4
4
  /** AuthorizationResponseMessage is struct the represents iden3message authorization response */
5
5
  export type AuthorizationResponseMessage = BasicMessage & {
@@ -10,7 +10,7 @@ export type AuthorizationResponseMessage = BasicMessage & {
10
10
  };
11
11
  /** AuthorizationMessageResponseBody is struct the represents authorization response data */
12
12
  export type AuthorizationMessageResponseBody = {
13
- did_doc?: JSONObject;
13
+ did_doc?: JsonDocumentObject;
14
14
  message?: string;
15
15
  scope: Array<ZeroKnowledgeProofResponse>;
16
16
  };
@@ -25,7 +25,7 @@ export type AuthorizationRequestMessageBody = {
25
25
  callbackUrl: string;
26
26
  reason?: string;
27
27
  message?: string;
28
- did_doc?: JSONObject;
28
+ did_doc?: JsonDocumentObject;
29
29
  scope: Array<ZeroKnowledgeProofRequest>;
30
30
  };
31
31
  /** ZeroKnowledgeProofRequest represents structure of zkp request object */
@@ -33,7 +33,7 @@ export type ZeroKnowledgeProofRequest = {
33
33
  id: number;
34
34
  circuitId: string;
35
35
  optional?: boolean;
36
- query: JSONObject;
36
+ query: JsonDocumentObject;
37
37
  params?: {
38
38
  nullifierSessionId?: string | number;
39
39
  };
@@ -1,11 +1,11 @@
1
1
  import { W3CCredential } from '../../../verifiable';
2
2
  import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
3
- import { BasicMessage, JSONObject } from '../packer';
3
+ import { BasicMessage, JsonDocumentObject } from '../packer';
4
4
  import { ContractInvokeTransactionData } from './contract-request';
5
5
  /** CredentialIssuanceRequestMessageBody represents data for credential issuance request */
6
6
  export type CredentialIssuanceRequestMessageBody = {
7
7
  schema: Schema;
8
- data: JSONObject;
8
+ data: JsonDocumentObject;
9
9
  expiration: number;
10
10
  };
11
11
  /** CredentialIssuanceRequestMessage represent Iden3message for credential request */
@@ -56,7 +56,7 @@ export type IssuanceMessageBody = {
56
56
  };
57
57
  /** CredentialFetchRequestMessage represent Iden3message for credential fetch request */
58
58
  export type CredentialFetchRequestMessage = BasicMessage & {
59
- body?: CredentialFetchRequestMessageBody;
59
+ body: CredentialFetchRequestMessageBody;
60
60
  type: typeof PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE;
61
61
  };
62
62
  /** CredentialFetchRequestMessageBody is msg body for fetch request */
@@ -71,7 +71,7 @@ export type Schema = {
71
71
  };
72
72
  /** CredentialRefreshMessage represent Iden3message for credential refresh request */
73
73
  export type CredentialRefreshMessage = Required<BasicMessage> & {
74
- body?: CredentialRefreshMessageBody;
74
+ body: CredentialRefreshMessageBody;
75
75
  type: typeof PROTOCOL_MESSAGE_TYPE.CREDENTIAL_REFRESH_MESSAGE_TYPE;
76
76
  };
77
77
  /** CredentialRefreshMessageBody is msg body for refresh request */
@@ -2,7 +2,7 @@ import { BasicMessage } from '../';
2
2
  import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
3
3
  /** MessageFetchRequestMessage represent Iden3message for message fetch request. */
4
4
  export type MessageFetchRequestMessage = Required<BasicMessage> & {
5
- body?: MessageFetchRequestMessageBody;
5
+ body: MessageFetchRequestMessageBody;
6
6
  type: typeof PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE;
7
7
  };
8
8
  /** MessageFetchRequestMessageBody is struct the represents body for message fetch request. */
@@ -3,7 +3,7 @@ import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
3
3
  import { ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from './auth';
4
4
  /** ProofGenerationRequestMessage is struct the represents body for proof generation request */
5
5
  export type ProofGenerationRequestMessage = Required<BasicMessage> & {
6
- body?: ProofGenerationRequestMessageBody;
6
+ body: ProofGenerationRequestMessageBody;
7
7
  type: typeof PROTOCOL_MESSAGE_TYPE.PROOF_GENERATION_REQUEST_MESSAGE_TYPE;
8
8
  };
9
9
  /** ProofGenerationRequestMessageBody is struct the represents body for proof generation request */
@@ -12,7 +12,7 @@ export type ProofGenerationRequestMessageBody = {
12
12
  };
13
13
  /** ProofGenerationResponseMessage is struct the represents body for proof generation request */
14
14
  export type ProofGenerationResponseMessage = Required<BasicMessage> & {
15
- body?: ResponseMessageBody;
15
+ body: ResponseMessageBody;
16
16
  type: typeof PROTOCOL_MESSAGE_TYPE.PROOF_GENERATION_RESPONSE_MESSAGE_TYPE;
17
17
  };
18
18
  /** ResponseMessageBody is struct the represents request for revocation status */
@@ -1,8 +1,8 @@
1
- import { BasicMessage, JSONObject } from '../';
1
+ import { BasicMessage, JsonDocumentObject } from '../';
2
2
  import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
3
3
  /** @beta ProposalRequestMessage is struct the represents proposal-request message */
4
4
  export type ProposalRequestMessage = BasicMessage & {
5
- body?: ProposalRequestMessageBody;
5
+ body: ProposalRequestMessageBody;
6
6
  type: typeof PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE;
7
7
  };
8
8
  /** @beta ProposalRequestMessageBody is struct the represents body for proposal-request */
@@ -10,13 +10,13 @@ export type ProposalRequestMessageBody = {
10
10
  credentials: ProposalRequestCredential[];
11
11
  metadata?: {
12
12
  type: string;
13
- data?: JSONObject;
13
+ data?: JsonDocumentObject;
14
14
  };
15
- did_doc?: JSONObject;
15
+ did_doc?: JsonDocumentObject;
16
16
  };
17
17
  /** @beta ProposalMessage is struct the represents proposal message */
18
18
  export type ProposalMessage = BasicMessage & {
19
- body?: ProposalMessageBody;
19
+ body: ProposalMessageBody;
20
20
  type: typeof PROTOCOL_MESSAGE_TYPE.PROPOSAL_MESSAGE_TYPE;
21
21
  };
22
22
  /** @beta ProposalMessageBody is struct the represents body for proposal message */
@@ -30,7 +30,7 @@ export type ProposalRequestCredential = {
30
30
  };
31
31
  /** @beta Proposal is struct the represents proposal inside proposal protocol message */
32
32
  export type Proposal = {
33
- credentials?: ProposalRequestCredential[];
33
+ credentials: ProposalRequestCredential[];
34
34
  type: string;
35
35
  url?: string;
36
36
  expiration?: string;
@@ -3,7 +3,7 @@ import { RevocationStatus } from '../../../verifiable';
3
3
  import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
4
4
  /** RevocationStatusRequestMessage is struct the represents body for proof generation request */
5
5
  export type RevocationStatusRequestMessage = BasicMessage & {
6
- body?: RevocationStatusRequestMessageBody;
6
+ body: RevocationStatusRequestMessageBody;
7
7
  type: typeof PROTOCOL_MESSAGE_TYPE.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE;
8
8
  };
9
9
  /** RevocationStatusRequestMessageBody is struct the represents request for revocation status */
@@ -12,7 +12,7 @@ export type RevocationStatusRequestMessageBody = {
12
12
  };
13
13
  /** RevocationStatusResponseMessage is struct the represents body for proof generation request */
14
14
  export type RevocationStatusResponseMessage = Required<BasicMessage> & {
15
- body?: RevocationStatusResponseMessageBody;
15
+ body: RevocationStatusResponseMessageBody;
16
16
  type: typeof PROTOCOL_MESSAGE_TYPE.REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE;
17
17
  };
18
18
  /** RevocationStatusResponseMessageBody is struct the represents request for revocation status */
@@ -2,7 +2,7 @@ import { ClaimNonRevStatus, GISTProof, Operators } from '../circuits';
2
2
  import { StateProof } from '../storage/entities/state';
3
3
  import { MerkleTreeProofWithTreeState, RevocationStatus, W3CCredential } from '../verifiable';
4
4
  import { Options, Path } from '@iden3/js-jsonld-merklization';
5
- import { JSONObject } from '../iden3comm';
5
+ import { JsonDocumentObject } from '../iden3comm';
6
6
  import { Claim } from '@iden3/js-iden3-core';
7
7
  export type PreparedCredential = {
8
8
  credential: W3CCredential;
@@ -42,7 +42,7 @@ export type QueryMetadata = PropertyQuery & {
42
42
  datatype: string;
43
43
  merklizedSchema: boolean;
44
44
  };
45
- export declare const parseCredentialSubject: (credentialSubject?: JSONObject) => PropertyQuery[];
45
+ export declare const parseCredentialSubject: (credentialSubject?: JsonDocumentObject) => PropertyQuery[];
46
46
  export declare const parseQueryMetadata: (propertyQuery: PropertyQuery, ldContextJSON: string, credentialType: string, options: Options) => Promise<QueryMetadata>;
47
- export declare const parseQueriesMetadata: (credentialType: string, ldContextJSON: string, credentialSubject: JSONObject, options: Options) => Promise<QueryMetadata[]>;
47
+ export declare const parseQueriesMetadata: (credentialType: string, ldContextJSON: string, credentialSubject: JsonDocumentObject, options: Options) => Promise<QueryMetadata[]>;
48
48
  export declare const transformQueryValueToBigInts: (value: unknown, ldType: string) => Promise<bigint[]>;
@@ -5,8 +5,5 @@
5
5
  * @param otherCredSubject - The second object to merge.
6
6
  * @returns A new object with the merged properties.
7
7
  */
8
- type obj = {
9
- [k: string]: unknown;
10
- };
11
- export declare function mergeObjects(credSubject: obj, otherCredSubject: obj): obj;
12
- export {};
8
+ import { JsonDocumentObject } from '../iden3comm';
9
+ export declare function mergeObjects(credSubject: JsonDocumentObject, otherCredSubject: JsonDocumentObject): JsonDocumentObject;
@@ -5,6 +5,7 @@ import { Merklizer, Options } from '@iden3/js-jsonld-merklization';
5
5
  import { CredentialStatusResolverRegistry } from '../credentials';
6
6
  import { ProofType } from './constants';
7
7
  import { CoreClaimCreationOptions } from './core-utils';
8
+ import { JsonDocumentObject } from '../iden3comm';
8
9
  /**
9
10
  * W3C Verifiable credential
10
11
  *
@@ -20,9 +21,7 @@ export declare class W3CCredential {
20
21
  refreshService?: RefreshService;
21
22
  displayMethod?: DisplayMethod;
22
23
  issuanceDate?: string;
23
- credentialSubject: {
24
- [key: string]: object | string | number | boolean;
25
- };
24
+ credentialSubject: JsonDocumentObject;
26
25
  credentialStatus: CredentialStatus;
27
26
  issuer: string;
28
27
  credentialSchema: CredentialSchema;
@@ -1,10 +1,10 @@
1
1
  import { Options, Path } from '@iden3/js-jsonld-merklization';
2
2
  import { W3CCredential } from './credential';
3
3
  import { QueryMetadata } from '../proof';
4
- import { JSONObject } from '../iden3comm';
4
+ import { JsonDocumentObject } from '../iden3comm';
5
5
  export declare const stringByPath: (obj: {
6
6
  [key: string]: unknown;
7
7
  }, path: string) => string;
8
8
  export declare const buildFieldPath: (ldSchema: string, contextType: string, field: string, opts?: Options) => Promise<Path>;
9
- export declare const findValue: (fieldName: string, credential: W3CCredential) => JSONObject;
9
+ export declare const findValue: (fieldName: string, credential: W3CCredential) => JsonDocumentObject;
10
10
  export declare const createVerifiablePresentation: (context: string, tp: string, credential: W3CCredential, queries: QueryMetadata[]) => object;
@@ -3,7 +3,7 @@ import { ProofType, CredentialStatusType, RefreshServiceType, DisplayMethodType
3
3
  import { TreeState } from '../circuits';
4
4
  import { Signature } from '@iden3/js-crypto';
5
5
  import { Claim, DID } from '@iden3/js-iden3-core';
6
- import { JSONObject } from '../iden3comm';
6
+ import { JsonDocumentObject, JSONObject } from '../iden3comm';
7
7
  /**
8
8
  * Represents the published state of the issuer
9
9
  *
@@ -153,9 +153,7 @@ export declare class BJJSignatureProof2021 {
153
153
  */
154
154
  export interface ProofQuery {
155
155
  allowedIssuers?: string[];
156
- credentialSubject?: {
157
- [key: string]: unknown;
158
- };
156
+ credentialSubject?: JsonDocumentObject;
159
157
  schema?: string;
160
158
  claimId?: string;
161
159
  credentialSubjectId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.17.3",
3
+ "version": "1.17.5",
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",
@@ -36,7 +36,8 @@
36
36
  "lint": "eslint --fix --ext .ts src/** tests/**",
37
37
  "lint:check": "eslint --ext .ts src/** tests/**",
38
38
  "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
39
- "format:check": "prettier \"src/**/*.ts\" \"tests/**/*.ts\" --check"
39
+ "format:check": "prettier \"src/**/*.ts\" \"tests/**/*.ts\" --check",
40
+ "watch": "tsc --watch"
40
41
  },
41
42
  "repository": {
42
43
  "type": "git",