@0xpolygonid/js-sdk 1.9.0 → 1.9.1

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.
@@ -0,0 +1,92 @@
1
+ import { PROTOCOL_MESSAGE_TYPE } from '../constants';
2
+ import { MediaType } from '../constants';
3
+ import { DID } from '@iden3/js-iden3-core';
4
+ import * as uuid from 'uuid';
5
+ import { byteEncoder } from '../../utils';
6
+ import { proving } from '@iden3/js-jwz';
7
+ /**
8
+ *
9
+ * Allows to process RevocationStatusRequest protocol message
10
+ *
11
+
12
+ * @class RevocationStatusHandler
13
+ * @implements implements IRevocationStatusHandler interface
14
+ */
15
+ export class RevocationStatusHandler {
16
+ /**
17
+ * Creates an instance of RevocationStatusHandler.
18
+ * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
19
+ * @param {IIdentityWallet} _identityWallet - identity wallet
20
+ *
21
+ */
22
+ constructor(_packerMgr, _identityWallet) {
23
+ this._packerMgr = _packerMgr;
24
+ this._identityWallet = _identityWallet;
25
+ }
26
+ /**
27
+ * @inheritdoc IRevocationStatusHandler#parseRevocationStatusRequest
28
+ */
29
+ async parseRevocationStatusRequest(request) {
30
+ const { unpackedMessage: message } = await this._packerMgr.unpack(request);
31
+ const ciRequest = message;
32
+ if (message.type !== PROTOCOL_MESSAGE_TYPE.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE) {
33
+ throw new Error('Invalid media type');
34
+ }
35
+ return ciRequest;
36
+ }
37
+ /**
38
+ * @inheritdoc IRevocationStatusHandler#handleRevocationStatusRequest
39
+ */
40
+ async handleRevocationStatusRequest(did, request, opts) {
41
+ if (!opts) {
42
+ opts = {
43
+ mediaType: MediaType.PlainMessage
44
+ };
45
+ }
46
+ if (opts.mediaType === MediaType.SignedMessage && !opts.packerOptions) {
47
+ throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
48
+ }
49
+ const rsRequest = await this.parseRevocationStatusRequest(request);
50
+ if (!rsRequest.to) {
51
+ throw new Error(`failed request. empty 'to' field`);
52
+ }
53
+ if (!rsRequest.from) {
54
+ throw new Error(`failed request. empty 'from' field`);
55
+ }
56
+ if (!rsRequest.body?.revocation_nonce) {
57
+ throw new Error(`failed request. empty 'revocation_nonce' field`);
58
+ }
59
+ const issuerDID = DID.parse(rsRequest.to);
60
+ const mtpWithTreeState = await this._identityWallet.generateNonRevocationMtpWithNonce(issuerDID, BigInt(rsRequest.body.revocation_nonce), opts?.treeState);
61
+ const treeState = mtpWithTreeState.treeState;
62
+ const revStatus = {
63
+ issuer: {
64
+ state: treeState?.state.string(),
65
+ claimsTreeRoot: treeState.claimsRoot.string(),
66
+ revocationTreeRoot: treeState.revocationRoot.string(),
67
+ rootOfRoots: treeState.rootOfRoots.string()
68
+ },
69
+ mtp: mtpWithTreeState.proof
70
+ };
71
+ const packerOpts = opts.mediaType === MediaType.SignedMessage
72
+ ? opts.packerOptions
73
+ : {
74
+ provingMethodAlg: proving.provingMethodGroth16AuthV2Instance.methodAlg
75
+ };
76
+ const senderDID = DID.parse(rsRequest.to);
77
+ const guid = uuid.v4();
78
+ const response = {
79
+ id: guid,
80
+ typ: MediaType.PlainMessage,
81
+ type: PROTOCOL_MESSAGE_TYPE.REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE,
82
+ thid: rsRequest.thid ?? guid,
83
+ body: revStatus,
84
+ from: did.string(),
85
+ to: rsRequest.from
86
+ };
87
+ return this._packerMgr.pack(opts.mediaType, byteEncoder.encode(JSON.stringify(response)), {
88
+ senderDID,
89
+ ...packerOpts
90
+ });
91
+ }
92
+ }
@@ -227,6 +227,10 @@ export class IdentityWallet {
227
227
  async generateNonRevocationMtp(did, credential, treeState) {
228
228
  const coreClaim = await this.getCoreClaimFromCredential(credential);
229
229
  const revNonce = coreClaim.getRevocationNonce();
230
+ return this.generateNonRevocationMtpWithNonce(did, revNonce, treeState);
231
+ }
232
+ /** {@inheritDoc IIdentityWallet.generateNonRevocationMtpWithNonce} */
233
+ async generateNonRevocationMtpWithNonce(did, revNonce, treeState) {
230
234
  const treesModel = await this.getDIDTreeModel(did);
231
235
  const revocationTree = await this._storage.mt.getMerkleTreeByIdentifierAndType(did.string(), MerkleTreeType.Revocations);
232
236
  const claimsRoot = await treesModel.claimsTree.root();
@@ -99,6 +99,7 @@ export interface AuthHandlerOptions {
99
99
  export declare class AuthHandler implements IAuthHandler {
100
100
  private readonly _packerMgr;
101
101
  private readonly _proofService;
102
+ private readonly _supportedCircuits;
102
103
  /**
103
104
  * Creates an instance of AuthHandler.
104
105
  * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
@@ -0,0 +1,23 @@
1
+ import { JWSPackerParams, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../types';
2
+ import { DID } from '@iden3/js-iden3-core';
3
+ import { IProofService } from '../../proof';
4
+ import { CircuitId } from '../../circuits';
5
+ import { MediaType } from '../constants';
6
+ import { Signer } from 'ethers';
7
+ /**
8
+ * Processes zero knowledge proof requests.
9
+ *
10
+ * @param senderIdentifier - The identifier of the sender.
11
+ * @param requests - An array of zero knowledge proof requests.
12
+ * @param from - The identifier of the sender.
13
+ * @param proofService - The proof service.
14
+ * @param opts - Additional options for processing the requests.
15
+ * @returns A promise that resolves to an array of zero knowledge proof responses.
16
+ */
17
+ export declare const processZeroKnowledgeProofRequests: (senderIdentifier: DID, requests: ZeroKnowledgeProofRequest[] | undefined, from: DID | undefined, proofService: IProofService, opts: {
18
+ mediaType?: MediaType;
19
+ packerOptions?: JWSPackerParams;
20
+ supportedCircuits: CircuitId[];
21
+ ethSigner?: Signer;
22
+ challenge?: bigint;
23
+ }) => Promise<ZeroKnowledgeProofResponse[]>;
@@ -46,7 +46,7 @@ export declare class ContractRequestHandler implements IContractRequestHandler {
46
46
  private readonly _packerMgr;
47
47
  private readonly _proofService;
48
48
  private readonly _zkpVerifier;
49
- private readonly _allowedCircuits;
49
+ private readonly _supportedCircuits;
50
50
  /**
51
51
  * Creates an instance of ContractRequestHandler.
52
52
  * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
@@ -2,3 +2,5 @@ export * from './auth';
2
2
  export * from './fetch';
3
3
  export * from './contract-request';
4
4
  export * from './refresh';
5
+ export * from './revocation-status';
6
+ export * from './common';
@@ -0,0 +1,59 @@
1
+ import { MediaType } from '../constants';
2
+ import { IPackageManager, JWSPackerParams, RevocationStatusRequestMessage } from '../types';
3
+ import { DID } from '@iden3/js-iden3-core';
4
+ import { TreeState } from '../../circuits';
5
+ import { IIdentityWallet } from '../../identity';
6
+ /**
7
+ * Interface that allows the processing of the revocation status
8
+ *
9
+ * @interface IRevocationStatusHandler
10
+ */
11
+ export interface IRevocationStatusHandler {
12
+ /**
13
+ * unpacks revocation status request
14
+ * @param {Uint8Array} request - raw byte message
15
+ * @returns `Promise<RevocationStatusRequestMessage>`
16
+ */
17
+ parseRevocationStatusRequest(request: Uint8Array): Promise<RevocationStatusRequestMessage>;
18
+ /**
19
+ * handle revocation status request
20
+ * @param {did} did - sender DID
21
+ * @param {Uint8Array} request - raw byte message
22
+ * @param {RevocationStatusHandlerOptions} opts - handler options
23
+ * @returns {Promise<Uint8Array>}` - revocation status response message
24
+ */
25
+ handleRevocationStatusRequest(did: DID, request: Uint8Array, opts?: RevocationStatusHandlerOptions): Promise<Uint8Array>;
26
+ }
27
+ /** RevocationStatusHandlerOptions represents revocation status handler options */
28
+ export type RevocationStatusHandlerOptions = {
29
+ mediaType: MediaType;
30
+ packerOptions?: JWSPackerParams;
31
+ treeState?: TreeState;
32
+ };
33
+ /**
34
+ *
35
+ * Allows to process RevocationStatusRequest protocol message
36
+ *
37
+
38
+ * @class RevocationStatusHandler
39
+ * @implements implements IRevocationStatusHandler interface
40
+ */
41
+ export declare class RevocationStatusHandler implements IRevocationStatusHandler {
42
+ private readonly _packerMgr;
43
+ private readonly _identityWallet;
44
+ /**
45
+ * Creates an instance of RevocationStatusHandler.
46
+ * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
47
+ * @param {IIdentityWallet} _identityWallet - identity wallet
48
+ *
49
+ */
50
+ constructor(_packerMgr: IPackageManager, _identityWallet: IIdentityWallet);
51
+ /**
52
+ * @inheritdoc IRevocationStatusHandler#parseRevocationStatusRequest
53
+ */
54
+ parseRevocationStatusRequest(request: Uint8Array): Promise<RevocationStatusRequestMessage>;
55
+ /**
56
+ * @inheritdoc IRevocationStatusHandler#handleRevocationStatusRequest
57
+ */
58
+ handleRevocationStatusRequest(did: DID, request: Uint8Array, opts?: RevocationStatusHandlerOptions): Promise<Uint8Array>;
59
+ }
@@ -114,7 +114,7 @@ export interface IIdentityWallet {
114
114
  */
115
115
  generateCredentialMtp(did: DID, credential: W3CCredential, treeState?: TreeState): Promise<MerkleTreeProofWithTreeState>;
116
116
  /**
117
- * Generates proof of credential revocation nonce inclusion / non-inclusion to the given revocation tree
117
+ * Generates proof of credential revocation nonce (with credential as a param) inclusion / non-inclusion to the given revocation tree
118
118
  * and its root or to the current root of the Revocation tree in the given Merkle tree storage.
119
119
  *
120
120
  * @param {DID} did
@@ -123,6 +123,16 @@ export interface IIdentityWallet {
123
123
  * @returns `Promise<MerkleTreeProofWithTreeState>` - MerkleTreeProof and TreeState on which proof has been generated
124
124
  */
125
125
  generateNonRevocationMtp(did: DID, credential: W3CCredential, treeState?: TreeState): Promise<MerkleTreeProofWithTreeState>;
126
+ /**
127
+ * Generates proof of credential revocation nonce (with revNonce as a param) inclusion / non-inclusion to the given revocation tree
128
+ * and its root or to the current root of the Revocation tree in the given Merkle tree storage.
129
+ *
130
+ * @param {DID} did
131
+ * @param {bigint} revNonce
132
+ * @param {TreeState} [treeState]
133
+ * @returns `Promise<MerkleTreeProofWithTreeState>` - MerkleTreeProof and TreeState on which proof has been generated
134
+ */
135
+ generateNonRevocationMtpWithNonce(did: DID, revNonce: bigint, treeState?: TreeState): Promise<MerkleTreeProofWithTreeState>;
126
136
  /**
127
137
  * Signs a payload of arbitrary size with an Auth BJJ Credential that identifies a key for signing.
128
138
  *
@@ -325,6 +335,8 @@ export declare class IdentityWallet implements IIdentityWallet {
325
335
  generateCredentialMtp(did: DID, credential: W3CCredential, treeState?: TreeState): Promise<MerkleTreeProofWithTreeState>;
326
336
  /** {@inheritDoc IIdentityWallet.generateNonRevocationMtp} */
327
337
  generateNonRevocationMtp(did: DID, credential: W3CCredential, treeState?: TreeState): Promise<MerkleTreeProofWithTreeState>;
338
+ /** {@inheritDoc IIdentityWallet.generateNonRevocationMtpWithNonce} */
339
+ generateNonRevocationMtpWithNonce(did: DID, revNonce: bigint, treeState?: TreeState): Promise<MerkleTreeProofWithTreeState>;
328
340
  /** {@inheritDoc IIdentityWallet.sign} */
329
341
  sign(message: Uint8Array, credential: W3CCredential): Promise<Signature>;
330
342
  /** {@inheritDoc IIdentityWallet.signChallenge} */
@@ -31,7 +31,7 @@ export declare class W3CCredential {
31
31
  };
32
32
  private proofToJSON;
33
33
  private static proofFromJSON;
34
- static fromJSON(obj: W3CCredential): W3CCredential;
34
+ static fromJSON(obj: any): W3CCredential;
35
35
  /**
36
36
  * merklization of the verifiable credential
37
37
  *
@@ -186,7 +186,11 @@ export interface CredentialStatus {
186
186
  id: string;
187
187
  type: CredentialStatusType;
188
188
  revocationNonce?: number;
189
- statusIssuer?: CredentialStatus;
189
+ statusIssuer?: {
190
+ id: string;
191
+ type: CredentialStatusType;
192
+ revocationNonce?: number;
193
+ };
190
194
  }
191
195
  /**
192
196
  * RefreshService contains type and id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
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",