@0xpolygonid/js-sdk 1.4.0 → 1.4.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.
@@ -5,6 +5,7 @@ const js_iden3_core_1 = require("@iden3/js-iden3-core");
5
5
  const js_merkletree_1 = require("@iden3/js-merkletree");
6
6
  const constants_1 = require("../../verifiable/constants");
7
7
  const utils_1 = require("./utils");
8
+ const sparse_merkle_tree_1 = require("./sparse-merkle-tree");
8
9
  /**
9
10
  * ProofNode is a partial Reverse Hash Service result
10
11
  * it contains the current node hash and its children
@@ -99,13 +100,13 @@ class RHSResolver {
99
100
  catch (e) {
100
101
  if (credentialStatus?.statusIssuer?.type === constants_1.CredentialStatusType.SparseMerkleTreeProof) {
101
102
  try {
102
- return await (await fetch(credentialStatus.id)).json();
103
+ return await new sparse_merkle_tree_1.IssuerResolver().resolve(credentialStatus.statusIssuer);
103
104
  }
104
105
  catch (e) {
105
- throw new Error(`can't fetch revocation status from backup endpoint`);
106
+ throw new Error(`can't fetch revocation status from backup endpoint: ${e?.message}`);
106
107
  }
107
108
  }
108
- throw new Error(`can't fetch revocation status`);
109
+ throw new Error(`can't fetch revocation status: ${e?.message}`);
109
110
  }
110
111
  }
111
112
  /**
@@ -31,7 +31,7 @@ class ProofService {
31
31
  this._identityWallet = _identityWallet;
32
32
  this._credentialWallet = _credentialWallet;
33
33
  this._stateStorage = _stateStorage;
34
- this._prover = new prover_1.NativeProver(_circuitStorage);
34
+ this._prover = opts?.prover ?? new prover_1.NativeProver(_circuitStorage);
35
35
  this._ldOptions = { ...opts, documentLoader: opts?.documentLoader ?? (0, schema_processor_1.cacheLoader)(opts) };
36
36
  }
37
37
  /** {@inheritdoc IProofService.verifyProof} */
@@ -63,7 +63,23 @@ class OnChainZKPVerifier {
63
63
  ],
64
64
  zkProof.proof.pi_c.slice(0, 2)
65
65
  ];
66
- const tx = await contract.submitZKPResponse(...payload);
66
+ const feeData = await provider.getFeeData();
67
+ const maxFeePerGas = chainConfig.maxFeePerGas
68
+ ? BigInt(chainConfig.maxFeePerGas)
69
+ : feeData.maxFeePerGas;
70
+ const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
71
+ ? BigInt(chainConfig.maxPriorityFeePerGas)
72
+ : feeData.maxPriorityFeePerGas;
73
+ const gasLimit = await contract.submitZKPResponse.estimateGas(...payload);
74
+ const txData = await contract.submitZKPResponse.populateTransaction(...payload);
75
+ const request = {
76
+ to: txData.to,
77
+ data: txData.data,
78
+ gasLimit,
79
+ maxFeePerGas,
80
+ maxPriorityFeePerGas
81
+ };
82
+ const tx = await ethSigner.sendTransaction(request);
67
83
  const txnReceipt = await tx.wait();
68
84
  if (!txnReceipt) {
69
85
  throw new Error(`transaction: ${tx.hash} failed to mined`);
@@ -70,8 +70,23 @@ class EthStateStorage {
70
70
  ],
71
71
  proof.proof.pi_c.slice(0, 2)
72
72
  ];
73
- await contract.transitState.estimateGas(...payload);
74
- const tx = await contract.transitState(...payload);
73
+ const feeData = await this.provider.getFeeData();
74
+ const maxFeePerGas = exports.defaultEthConnectionConfig.maxFeePerGas
75
+ ? BigInt(exports.defaultEthConnectionConfig.maxFeePerGas)
76
+ : feeData.maxFeePerGas;
77
+ const maxPriorityFeePerGas = exports.defaultEthConnectionConfig.maxPriorityFeePerGas
78
+ ? BigInt(exports.defaultEthConnectionConfig.maxPriorityFeePerGas)
79
+ : feeData.maxPriorityFeePerGas;
80
+ const gasLimit = await contract.transitState.estimateGas(...payload);
81
+ const txData = await contract.transitState.populateTransaction(...payload);
82
+ const request = {
83
+ to: txData.to,
84
+ data: txData.data,
85
+ gasLimit,
86
+ maxFeePerGas,
87
+ maxPriorityFeePerGas
88
+ };
89
+ const tx = await signer.sendTransaction(request);
75
90
  const txnReceipt = await tx.wait();
76
91
  if (!txnReceipt) {
77
92
  throw new Error(`transaction: ${tx.hash} failed to mined`);
@@ -2,6 +2,7 @@ import { buildDIDType, BytesHelper, DID, Id } from '@iden3/js-iden3-core';
2
2
  import { Hash, Proof, ZERO_HASH, testBit } from '@iden3/js-merkletree';
3
3
  import { VerifiableConstants, CredentialStatusType } from '../../verifiable/constants';
4
4
  import { isGenesisState } from './utils';
5
+ import { IssuerResolver } from './sparse-merkle-tree';
5
6
  /**
6
7
  * ProofNode is a partial Reverse Hash Service result
7
8
  * it contains the current node hash and its children
@@ -95,13 +96,13 @@ export class RHSResolver {
95
96
  catch (e) {
96
97
  if (credentialStatus?.statusIssuer?.type === CredentialStatusType.SparseMerkleTreeProof) {
97
98
  try {
98
- return await (await fetch(credentialStatus.id)).json();
99
+ return await new IssuerResolver().resolve(credentialStatus.statusIssuer);
99
100
  }
100
101
  catch (e) {
101
- throw new Error(`can't fetch revocation status from backup endpoint`);
102
+ throw new Error(`can't fetch revocation status from backup endpoint: ${e?.message}`);
102
103
  }
103
104
  }
104
- throw new Error(`can't fetch revocation status`);
105
+ throw new Error(`can't fetch revocation status: ${e?.message}`);
105
106
  }
106
107
  }
107
108
  /**
@@ -28,7 +28,7 @@ export class ProofService {
28
28
  this._identityWallet = _identityWallet;
29
29
  this._credentialWallet = _credentialWallet;
30
30
  this._stateStorage = _stateStorage;
31
- this._prover = new NativeProver(_circuitStorage);
31
+ this._prover = opts?.prover ?? new NativeProver(_circuitStorage);
32
32
  this._ldOptions = { ...opts, documentLoader: opts?.documentLoader ?? cacheLoader(opts) };
33
33
  }
34
34
  /** {@inheritdoc IProofService.verifyProof} */
@@ -57,7 +57,23 @@ export class OnChainZKPVerifier {
57
57
  ],
58
58
  zkProof.proof.pi_c.slice(0, 2)
59
59
  ];
60
- const tx = await contract.submitZKPResponse(...payload);
60
+ const feeData = await provider.getFeeData();
61
+ const maxFeePerGas = chainConfig.maxFeePerGas
62
+ ? BigInt(chainConfig.maxFeePerGas)
63
+ : feeData.maxFeePerGas;
64
+ const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
65
+ ? BigInt(chainConfig.maxPriorityFeePerGas)
66
+ : feeData.maxPriorityFeePerGas;
67
+ const gasLimit = await contract.submitZKPResponse.estimateGas(...payload);
68
+ const txData = await contract.submitZKPResponse.populateTransaction(...payload);
69
+ const request = {
70
+ to: txData.to,
71
+ data: txData.data,
72
+ gasLimit,
73
+ maxFeePerGas,
74
+ maxPriorityFeePerGas
75
+ };
76
+ const tx = await ethSigner.sendTransaction(request);
61
77
  const txnReceipt = await tx.wait();
62
78
  if (!txnReceipt) {
63
79
  throw new Error(`transaction: ${tx.hash} failed to mined`);
@@ -64,8 +64,23 @@ export class EthStateStorage {
64
64
  ],
65
65
  proof.proof.pi_c.slice(0, 2)
66
66
  ];
67
- await contract.transitState.estimateGas(...payload);
68
- const tx = await contract.transitState(...payload);
67
+ const feeData = await this.provider.getFeeData();
68
+ const maxFeePerGas = defaultEthConnectionConfig.maxFeePerGas
69
+ ? BigInt(defaultEthConnectionConfig.maxFeePerGas)
70
+ : feeData.maxFeePerGas;
71
+ const maxPriorityFeePerGas = defaultEthConnectionConfig.maxPriorityFeePerGas
72
+ ? BigInt(defaultEthConnectionConfig.maxPriorityFeePerGas)
73
+ : feeData.maxPriorityFeePerGas;
74
+ const gasLimit = await contract.transitState.estimateGas(...payload);
75
+ const txData = await contract.transitState.populateTransaction(...payload);
76
+ const request = {
77
+ to: txData.to,
78
+ data: txData.data,
79
+ gasLimit,
80
+ maxFeePerGas,
81
+ maxPriorityFeePerGas
82
+ };
83
+ const tx = await signer.sendTransaction(request);
69
84
  const txnReceipt = await tx.wait();
70
85
  if (!txnReceipt) {
71
86
  throw new Error(`transaction: ${tx.hash} failed to mined`);
@@ -4,6 +4,7 @@ import { CircuitId, Query, TreeState } from '../circuits';
4
4
  import { ICredentialWallet } from '../credentials';
5
5
  import { IIdentityWallet } from '../identity';
6
6
  import { W3CCredential } from '../verifiable';
7
+ import { IZKProver } from './prover';
7
8
  import { Options } from '@iden3/js-jsonld-merklization';
8
9
  import { ZKProof } from '@iden3/js-jwz';
9
10
  import { Signer } from 'ethers';
@@ -24,6 +25,12 @@ export interface DIDProfileMetadata {
24
25
  authProfileNonce: number;
25
26
  credentialSubjectProfileNonce: number;
26
27
  }
28
+ /**
29
+ * List of options to customize ProofService
30
+ */
31
+ export type ProofServiceOptions = Options & {
32
+ prover?: IZKProver;
33
+ };
27
34
  export interface IProofService {
28
35
  /**
29
36
  * Verification of zkp proof for given circuit id
@@ -97,7 +104,7 @@ export declare class ProofService implements IProofService {
97
104
  * @param {ICircuitStorage} _circuitStorage - circuit storage to load proving / verification files
98
105
  * @param {IStateStorage} _stateStorage - state storage to get GIST proof / publish state
99
106
  */
100
- constructor(_identityWallet: IIdentityWallet, _credentialWallet: ICredentialWallet, _circuitStorage: ICircuitStorage, _stateStorage: IStateStorage, opts?: Options);
107
+ constructor(_identityWallet: IIdentityWallet, _credentialWallet: ICredentialWallet, _circuitStorage: ICircuitStorage, _stateStorage: IStateStorage, opts?: ProofServiceOptions);
101
108
  /** {@inheritdoc IProofService.verifyProof} */
102
109
  verifyProof(zkp: ZKProof, circuitId: CircuitId): Promise<boolean>;
103
110
  /** {@inheritdoc IProofService.generateProof} */
@@ -14,6 +14,8 @@ export interface EthConnectionConfig {
14
14
  defaultGasLimit: number;
15
15
  minGasPrice?: string;
16
16
  maxGasPrice?: string;
17
+ maxFeePerGas?: string;
18
+ maxPriorityFeePerGas?: string;
17
19
  confirmationBlockCount: number;
18
20
  confirmationTimeout: number;
19
21
  contractAddress: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.4.0",
3
+ "version": "1.4.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",