@0xpolygonid/js-sdk 1.14.1 → 1.15.2

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 (38) hide show
  1. package/README.md +0 -4
  2. package/dist/browser/esm/index.js +3490 -3457
  3. package/dist/browser/esm/index.js.map +1 -1
  4. package/dist/browser/umd/index.js +3503 -3470
  5. package/dist/browser/umd/index.js.map +1 -1
  6. package/dist/node/cjs/iden3comm/constants.js +3 -1
  7. package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +11 -8
  8. package/dist/node/cjs/iden3comm/handlers/message-handler.js +14 -3
  9. package/dist/node/cjs/iden3comm/packers/zkp.js +23 -16
  10. package/dist/node/cjs/iden3comm/types/index.js +1 -0
  11. package/dist/node/cjs/iden3comm/types/models.js +2 -0
  12. package/dist/node/cjs/iden3comm/types/protocol/credentials.js +8 -0
  13. package/dist/node/cjs/identity/identity-wallet.js +4 -1
  14. package/dist/node/cjs/proof/proof-service.js +16 -15
  15. package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +4 -5
  16. package/dist/node/esm/iden3comm/constants.js +2 -0
  17. package/dist/node/esm/iden3comm/handlers/credential-proposal.js +7 -4
  18. package/dist/node/esm/iden3comm/handlers/message-handler.js +14 -3
  19. package/dist/node/esm/iden3comm/packers/zkp.js +24 -17
  20. package/dist/node/esm/iden3comm/types/index.js +1 -0
  21. package/dist/node/esm/iden3comm/types/models.js +1 -0
  22. package/dist/node/esm/iden3comm/types/protocol/credentials.js +7 -1
  23. package/dist/node/esm/identity/identity-wallet.js +4 -1
  24. package/dist/node/esm/proof/proof-service.js +18 -17
  25. package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +4 -5
  26. package/dist/types/iden3comm/constants.d.ts +2 -0
  27. package/dist/types/iden3comm/handlers/auth.d.ts +3 -5
  28. package/dist/types/iden3comm/handlers/message-handler.d.ts +2 -0
  29. package/dist/types/iden3comm/packers/zkp.d.ts +6 -5
  30. package/dist/types/iden3comm/types/index.d.ts +1 -0
  31. package/dist/types/iden3comm/types/models.d.ts +6 -0
  32. package/dist/types/iden3comm/types/packer.d.ts +2 -1
  33. package/dist/types/iden3comm/types/protocol/auth.d.ts +0 -2
  34. package/dist/types/iden3comm/types/protocol/credentials.d.ts +7 -0
  35. package/dist/types/identity/identity-wallet.d.ts +8 -0
  36. package/dist/types/proof/proof-service.d.ts +2 -2
  37. package/dist/types/proof/verifiers/pub-signals-verifier.d.ts +1 -1
  38. package/package.json +4 -4
@@ -13,10 +13,9 @@ import { checkQueryRequest, fieldValueFromVerifiablePresentation, validateDisclo
13
13
  import { parseQueriesMetadata } from '../common';
14
14
  import { Operators } from '../../circuits';
15
15
  import { calculateQueryHashV3 } from './query-hash';
16
+ import { PROTOCOL_CONSTANTS } from '../../iden3comm';
16
17
  export const userStateError = new Error(`user state is not valid`);
17
18
  const zeroInt = 0n;
18
- const defaultProofVerifyOpts = 1 * 60 * 60 * 1000; // 1 hour
19
- const defaultAuthVerifyOpts = 5 * 60 * 1000; // 5 minutes
20
19
  /**
21
20
  * PubSignalsVerifier provides verify method
22
21
  * @public
@@ -218,7 +217,7 @@ export class PubSignalsVerifier {
218
217
  // no query verification
219
218
  // verify state
220
219
  const gist = await this.checkGlobalState(authV2PubSignals.GISTRoot, this.userId);
221
- let acceptedStateTransitionDelay = defaultAuthVerifyOpts;
220
+ let acceptedStateTransitionDelay = PROTOCOL_CONSTANTS.DEFAULT_AUTH_VERIFY_DELAY;
222
221
  if (opts?.acceptedStateTransitionDelay) {
223
222
  acceptedStateTransitionDelay = opts.acceptedStateTransitionDelay;
224
223
  }
@@ -305,7 +304,7 @@ export class PubSignalsVerifier {
305
304
  };
306
305
  this.checkRevocationState = async (issuerID, issuerClaimNonRevState, opts) => {
307
306
  const issuerNonRevStateResolved = await this.checkRevocationStateForId(issuerID, issuerClaimNonRevState);
308
- const acceptedStateTransitionDelay = opts?.acceptedStateTransitionDelay ?? defaultProofVerifyOpts;
307
+ const acceptedStateTransitionDelay = opts?.acceptedStateTransitionDelay ?? PROTOCOL_CONSTANTS.DEFAULT_PROOF_VERIFY_DELAY;
309
308
  if (!issuerNonRevStateResolved.latest) {
310
309
  const timeDiff = Date.now() -
311
310
  getDateFromUnixTimestamp(Number(issuerNonRevStateResolved.transitionTimestamp)).getTime();
@@ -389,7 +388,7 @@ export class PubSignalsVerifier {
389
388
  catch (e) {
390
389
  const stateNotExistErr = (e?.errorArgs ?? [])[0];
391
390
  const errMsg = stateNotExistErr || e.message;
392
- if (errMsg === 'State does not exist') {
391
+ if (errMsg.includes('State does not exist')) {
393
392
  if (isGenesis) {
394
393
  return {
395
394
  latest: true,
@@ -36,3 +36,5 @@ export declare const SUPPORTED_PUBLIC_KEY_TYPES: {
36
36
  ES256K: string[];
37
37
  'ES256K-R': string[];
38
38
  };
39
+ export declare const DEFAULT_PROOF_VERIFY_DELAY: number;
40
+ export declare const DEFAULT_AUTH_VERIFY_DELAY: number;
@@ -1,6 +1,6 @@
1
1
  import { MediaType } from '../constants';
2
2
  import { IProofService } from '../../proof/proof-service';
3
- import { AuthorizationRequestMessage, AuthorizationResponseMessage, BasicMessage, IPackageManager, JWSPackerParams } from '../types';
3
+ import { StateVerificationOpts, AuthorizationRequestMessage, AuthorizationResponseMessage, BasicMessage, IPackageManager, JWSPackerParams } from '../types';
4
4
  import { DID } from '@iden3/js-iden3-core';
5
5
  import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
6
6
  /**
@@ -25,12 +25,10 @@ export declare function createAuthorizationRequestWithMessage(reason: string, me
25
25
  * Options to pass to auth response handler
26
26
  *
27
27
  * @public
28
- * @interface AuthResponseHandlerOptions
29
28
  */
30
- export interface AuthResponseHandlerOptions {
31
- acceptedStateTransitionDelay?: number;
29
+ export type AuthResponseHandlerOptions = StateVerificationOpts & {
32
30
  acceptedProofGenerationDelay?: number;
33
- }
31
+ };
34
32
  /**
35
33
  * Interface that allows the processing of the authorization request in the raw format for given identifier
36
34
  *
@@ -3,6 +3,7 @@ import { AuthMessageHandlerOptions } from './auth';
3
3
  import { RevocationStatusMessageHandlerOptions } from './revocation-status';
4
4
  import { ContractMessageHandlerOptions } from './contract-request';
5
5
  import { PaymentHandlerOptions, PaymentRequestMessageHandlerOptions } from './payment';
6
+ import { DID } from '@iden3/js-iden3-core';
6
7
  /**
7
8
  * iden3 Protocol message handler interface
8
9
  */
@@ -79,6 +80,7 @@ export declare class MessageHandler {
79
80
  * @returns A Promise that resolves to a Uint8Array of the packed response, or null if no response was generated.
80
81
  */
81
82
  handleMessage(bytes: Uint8Array, context: AuthMessageHandlerOptions | ContractMessageHandlerOptions | RevocationStatusMessageHandlerOptions | PaymentRequestMessageHandlerOptions | PaymentHandlerOptions | {
83
+ senderDID?: DID;
82
84
  [key: string]: unknown;
83
85
  }): Promise<Uint8Array | null>;
84
86
  }
@@ -1,4 +1,4 @@
1
- import { AuthDataPrepareFunc, BasicMessage, IPacker, ProvingParams, StateVerificationFunc, VerificationParams, ZKPPackerParams } from '../types';
1
+ import { StateVerificationOpts, AuthDataPrepareFunc, BasicMessage, IPacker, ProvingParams, StateVerificationFunc, VerificationParams, ZKPPackerParams } from '../types';
2
2
  import { CircuitId } from '../../circuits/index';
3
3
  import { DID } from '@iden3/js-iden3-core';
4
4
  import { MediaType } from '../constants';
@@ -45,7 +45,7 @@ export declare class VerificationHandlerFunc {
45
45
  * @param {Array<string>} pubSignals - signals that must contain user id and state
46
46
  * @returns `Promise<boolean>`
47
47
  */
48
- verify(id: string, pubSignals: Array<string>): Promise<boolean>;
48
+ verify(id: string, pubSignals: Array<string>, opts?: StateVerificationOpts): Promise<boolean>;
49
49
  }
50
50
  /**
51
51
  * Packer that can pack message to JWZ token,
@@ -55,14 +55,15 @@ export declare class VerificationHandlerFunc {
55
55
  * @implements implements IPacker interface
56
56
  */
57
57
  export declare class ZKPPacker implements IPacker {
58
- provingParamsMap: Map<string, ProvingParams>;
59
- verificationParamsMap: Map<string, VerificationParams>;
58
+ readonly provingParamsMap: Map<string, ProvingParams>;
59
+ readonly verificationParamsMap: Map<string, VerificationParams>;
60
+ private readonly _opts;
60
61
  /**
61
62
  * Creates an instance of ZKPPacker.
62
63
  * @param {Map<string, ProvingParams>} provingParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
63
64
  * @param {Map<string, VerificationParams>} verificationParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
64
65
  */
65
- constructor(provingParamsMap: Map<string, ProvingParams>, verificationParamsMap: Map<string, VerificationParams>);
66
+ constructor(provingParamsMap: Map<string, ProvingParams>, verificationParamsMap: Map<string, VerificationParams>, _opts?: StateVerificationOpts);
66
67
  /**
67
68
  * Packs a basic message using the specified parameters.
68
69
  * @param msg - The basic message to pack.
@@ -7,4 +7,5 @@ export * from './protocol/contract-request';
7
7
  export * from './protocol/proposal-request';
8
8
  export * from './protocol/payment';
9
9
  export * from './packer';
10
+ export * from './models';
10
11
  export * from './packageManager';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * State verification options
3
+ */
4
+ export type StateVerificationOpts = {
5
+ acceptedStateTransitionDelay?: number;
6
+ };
@@ -4,6 +4,7 @@ import { ProvingMethodAlg } from '@iden3/js-jwz';
4
4
  import { CircuitId } from '../../circuits';
5
5
  import { MediaType } from '../constants';
6
6
  import { DIDDocument, VerificationMethod } from 'did-resolver';
7
+ import { StateVerificationOpts } from './models';
7
8
  /**
8
9
  * Protocol message type
9
10
  */
@@ -67,7 +68,7 @@ export type AuthDataPrepareFunc = (hash: Uint8Array, did: DID, circuitId: Circui
67
68
  /**
68
69
  * signature of state function verifier
69
70
  */
70
- export type StateVerificationFunc = (id: string, pubSignals: Array<string>) => Promise<boolean>;
71
+ export type StateVerificationFunc = (id: string, pubSignals: Array<string>, opts?: StateVerificationOpts) => Promise<boolean>;
71
72
  /**
72
73
  * Defines method that must be implemented by any packer
73
74
  *
@@ -1,6 +1,5 @@
1
1
  import { ZKProof } from '@iden3/js-jwz';
2
2
  import { BasicMessage, JSONObject } from '../packer';
3
- import { DID } from '@iden3/js-iden3-core';
4
3
  /** AuthorizationResponseMessage is struct the represents iden3message authorization response */
5
4
  export type AuthorizationResponseMessage = BasicMessage & {
6
5
  body: AuthorizationMessageResponseBody;
@@ -34,7 +33,6 @@ export type ZeroKnowledgeProofRequest = {
34
33
  query: JSONObject;
35
34
  params?: {
36
35
  nullifierSessionId?: string | number;
37
- verifierDid?: DID;
38
36
  };
39
37
  };
40
38
  /** ZeroKnowledgeProofResponse represents structure of zkp response */
@@ -29,10 +29,17 @@ export type CredentialsOnchainOfferMessageBody = {
29
29
  credentials: CredentialOffer[];
30
30
  transaction_data: ContractInvokeTransactionData;
31
31
  };
32
+ /** CredentialOfferStatus is list of possible statuses for credential offer message */
33
+ export declare enum CredentialOfferStatus {
34
+ Pending = "pending",
35
+ Completed = "completed",
36
+ Rejected = "rejected"
37
+ }
32
38
  /** CredentialOffer is structure to fetch credential */
33
39
  export type CredentialOffer = {
34
40
  id: string;
35
41
  description: string;
42
+ status?: CredentialOfferStatus;
36
43
  };
37
44
  /** CredentialIssuanceMessage represent Iden3message for credential issuance */
38
45
  export type CredentialIssuanceMessage = Required<BasicMessage> & {
@@ -87,6 +87,13 @@ export interface IIdentityWallet {
87
87
  did: DID;
88
88
  credential: W3CCredential;
89
89
  }>;
90
+ /**
91
+ * Credential wallet getter
92
+ *
93
+ * @returns {ICredentialWallet}
94
+ * @memberof IIdentityWallet
95
+ */
96
+ get credentialWallet(): ICredentialWallet;
90
97
  /**
91
98
  * Create Identity based in Ethereum address and it provides an identifier in DID form.
92
99
  *
@@ -361,6 +368,7 @@ export declare class IdentityWallet implements IIdentityWallet {
361
368
  constructor(_kms: KMS, _storage: IDataStorage, _credentialWallet: ICredentialWallet, _opts?: {
362
369
  credentialStatusPublisherRegistry?: CredentialStatusPublisherRegistry | undefined;
363
370
  } | undefined);
371
+ get credentialWallet(): ICredentialWallet;
364
372
  private getCredentialStatusPublisherRegistry;
365
373
  private createAuthCoreClaim;
366
374
  private createAuthBJJCredential;
@@ -7,7 +7,7 @@ import { IZKProver } from './provers/prover';
7
7
  import { Options } from '@iden3/js-jsonld-merklization';
8
8
  import { ZKProof } from '@iden3/js-jwz';
9
9
  import { Signer } from 'ethers';
10
- import { JSONObject, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../iden3comm';
10
+ import { StateVerificationOpts, JSONObject, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../iden3comm';
11
11
  import { ICircuitStorage, IStateStorage } from '../storage';
12
12
  import { ProofGenerationOptions } from './provers/inputs-generator';
13
13
  import { VerifyOpts } from './verifiers';
@@ -139,7 +139,7 @@ export declare class ProofService implements IProofService {
139
139
  private loadLdContext;
140
140
  /** {@inheritdoc IProofService.generateAuthV2Inputs} */
141
141
  generateAuthV2Inputs(hash: Uint8Array, did: DID, circuitId: CircuitId): Promise<Uint8Array>;
142
- verifyState(circuitId: string, pubSignals: string[]): Promise<boolean>;
142
+ verifyState(circuitId: string, pubSignals: string[], opts?: StateVerificationOpts): Promise<boolean>;
143
143
  findCredentialByProofQuery(did: DID, query: ProofQuery): Promise<{
144
144
  cred: W3CCredential;
145
145
  revStatus: RevocationStatus | undefined;
@@ -1,10 +1,10 @@
1
1
  import { Id } from '@iden3/js-iden3-core';
2
2
  import { DocumentLoader } from '@iden3/js-jsonld-merklization';
3
- import { JSONObject } from '../../iden3comm';
4
3
  import { IStateStorage } from '../../storage';
5
4
  import { ProofQuery } from '../../verifiable';
6
5
  import { BaseConfig } from '../../circuits/common';
7
6
  import { VerifyOpts } from './query';
7
+ import { JSONObject } from '../../iden3comm';
8
8
  /**
9
9
  * Verify Context - params for pub signal verification
10
10
  * @type VerifyContext
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.14.1",
3
+ "version": "1.15.2",
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",
@@ -87,9 +87,9 @@
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@iden3/js-crypto": "1.1.0",
90
- "@iden3/js-iden3-core": "1.3.1",
91
- "@iden3/js-jsonld-merklization": "1.2.0",
92
- "@iden3/js-jwz": "1.5.0",
90
+ "@iden3/js-iden3-core": "1.3.2",
91
+ "@iden3/js-jsonld-merklization": "1.3.1",
92
+ "@iden3/js-jwz": "1.5.1",
93
93
  "@iden3/js-merkletree": "1.2.0",
94
94
  "ffjavascript": "0.3.0",
95
95
  "rfc4648": "1.5.3",