@0xpolygonid/js-sdk 1.10.3 → 1.11.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 (107) hide show
  1. package/README.md +11 -0
  2. package/dist/browser/esm/index.js +8360 -17399
  3. package/dist/browser/esm/index.js.map +1 -1
  4. package/dist/browser/umd/index.js +8381 -17415
  5. package/dist/browser/umd/index.js.map +1 -1
  6. package/dist/node/cjs/blockchain/index.js +17 -0
  7. package/dist/node/cjs/blockchain/transaction-service.js +55 -0
  8. package/dist/node/cjs/credentials/credential-wallet.js +1 -1
  9. package/dist/node/cjs/credentials/status/reverse-sparse-merkle-tree.js +5 -1
  10. package/dist/node/cjs/iden3comm/handlers/auth.js +62 -27
  11. package/dist/node/cjs/iden3comm/handlers/common.js +4 -4
  12. package/dist/node/cjs/iden3comm/handlers/contract-request.js +34 -15
  13. package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +33 -14
  14. package/dist/node/cjs/iden3comm/handlers/fetch.js +65 -34
  15. package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
  16. package/dist/node/cjs/iden3comm/handlers/message-handler.js +96 -0
  17. package/dist/node/cjs/iden3comm/handlers/revocation-status.js +58 -30
  18. package/dist/node/cjs/iden3comm/packageManager.js +16 -0
  19. package/dist/node/cjs/iden3comm/packers/jws.js +63 -49
  20. package/dist/node/cjs/iden3comm/packers/plain.js +13 -3
  21. package/dist/node/cjs/iden3comm/packers/zkp.js +9 -0
  22. package/dist/node/cjs/iden3comm/utils/did.js +11 -11
  23. package/dist/node/cjs/identity/identity-wallet.js +228 -43
  24. package/dist/node/cjs/index.js +1 -0
  25. package/dist/node/cjs/kms/key-providers/bjj-provider.js +9 -0
  26. package/dist/node/cjs/kms/key-providers/ed25519-provider.js +13 -1
  27. package/dist/node/cjs/kms/key-providers/index.js +1 -1
  28. package/dist/node/cjs/kms/key-providers/{sec256k1-provider.js → secp256k1-provider.js} +37 -26
  29. package/dist/node/cjs/kms/kms.js +15 -0
  30. package/dist/node/cjs/proof/proof-service.js +3 -33
  31. package/dist/node/cjs/proof/provers/inputs-generator.js +2 -7
  32. package/dist/node/cjs/proof/verifiers/pub-signals-verifier.js +4 -5
  33. package/dist/node/cjs/storage/blockchain/onchain-revocation.js +4 -12
  34. package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +3 -10
  35. package/dist/node/cjs/storage/blockchain/state.js +39 -10
  36. package/dist/node/cjs/utils/did-helper.js +36 -2
  37. package/dist/node/cjs/verifiable/constants.js +2 -1
  38. package/dist/node/esm/blockchain/index.js +1 -0
  39. package/dist/node/esm/blockchain/transaction-service.js +51 -0
  40. package/dist/node/esm/credentials/credential-wallet.js +1 -1
  41. package/dist/node/esm/credentials/status/reverse-sparse-merkle-tree.js +6 -2
  42. package/dist/node/esm/iden3comm/handlers/auth.js +62 -27
  43. package/dist/node/esm/iden3comm/handlers/common.js +4 -4
  44. package/dist/node/esm/iden3comm/handlers/contract-request.js +34 -15
  45. package/dist/node/esm/iden3comm/handlers/credential-proposal.js +33 -14
  46. package/dist/node/esm/iden3comm/handlers/fetch.js +65 -34
  47. package/dist/node/esm/iden3comm/handlers/index.js +1 -0
  48. package/dist/node/esm/iden3comm/handlers/message-handler.js +91 -0
  49. package/dist/node/esm/iden3comm/handlers/revocation-status.js +58 -30
  50. package/dist/node/esm/iden3comm/packageManager.js +16 -0
  51. package/dist/node/esm/iden3comm/packers/jws.js +63 -49
  52. package/dist/node/esm/iden3comm/packers/plain.js +13 -3
  53. package/dist/node/esm/iden3comm/packers/zkp.js +9 -0
  54. package/dist/node/esm/iden3comm/utils/did.js +11 -8
  55. package/dist/node/esm/identity/identity-wallet.js +230 -45
  56. package/dist/node/esm/index.js +1 -0
  57. package/dist/node/esm/kms/key-providers/bjj-provider.js +10 -1
  58. package/dist/node/esm/kms/key-providers/ed25519-provider.js +13 -1
  59. package/dist/node/esm/kms/key-providers/index.js +1 -1
  60. package/dist/node/esm/kms/key-providers/secp256k1-provider.js +85 -0
  61. package/dist/node/esm/kms/kms.js +15 -0
  62. package/dist/node/esm/proof/proof-service.js +4 -34
  63. package/dist/node/esm/proof/provers/inputs-generator.js +3 -8
  64. package/dist/node/esm/proof/verifiers/pub-signals-verifier.js +4 -5
  65. package/dist/node/esm/storage/blockchain/onchain-revocation.js +4 -12
  66. package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +3 -10
  67. package/dist/node/esm/storage/blockchain/state.js +39 -10
  68. package/dist/node/esm/utils/did-helper.js +33 -1
  69. package/dist/node/esm/verifiable/constants.js +2 -1
  70. package/dist/types/blockchain/index.d.ts +1 -0
  71. package/dist/types/blockchain/transaction-service.d.ts +80 -0
  72. package/dist/types/iden3comm/handlers/auth.d.ts +17 -2
  73. package/dist/types/iden3comm/handlers/common.d.ts +2 -2
  74. package/dist/types/iden3comm/handlers/contract-request.d.ts +10 -2
  75. package/dist/types/iden3comm/handlers/credential-proposal.d.ts +5 -2
  76. package/dist/types/iden3comm/handlers/fetch.d.ts +15 -6
  77. package/dist/types/iden3comm/handlers/index.d.ts +1 -0
  78. package/dist/types/iden3comm/handlers/message-handler.d.ts +83 -0
  79. package/dist/types/iden3comm/handlers/revocation-status.d.ts +18 -2
  80. package/dist/types/iden3comm/packageManager.d.ts +10 -0
  81. package/dist/types/iden3comm/packers/jws.d.ts +9 -0
  82. package/dist/types/iden3comm/packers/plain.d.ts +10 -2
  83. package/dist/types/iden3comm/packers/zkp.d.ts +7 -0
  84. package/dist/types/iden3comm/types/packageManager.d.ts +10 -0
  85. package/dist/types/iden3comm/types/packer.d.ts +24 -2
  86. package/dist/types/iden3comm/types/protocol/auth.d.ts +5 -15
  87. package/dist/types/iden3comm/types/protocol/contract-request.d.ts +2 -6
  88. package/dist/types/iden3comm/types/protocol/credentials.d.ts +7 -44
  89. package/dist/types/iden3comm/types/protocol/messages.d.ts +2 -9
  90. package/dist/types/iden3comm/types/protocol/proof.d.ts +3 -16
  91. package/dist/types/iden3comm/types/protocol/revocation.d.ts +3 -16
  92. package/dist/types/identity/identity-wallet.d.ts +80 -7
  93. package/dist/types/index.d.ts +1 -0
  94. package/dist/types/kms/key-providers/bjj-provider.d.ts +1 -0
  95. package/dist/types/kms/key-providers/ed25519-provider.d.ts +8 -0
  96. package/dist/types/kms/key-providers/index.d.ts +1 -1
  97. package/dist/types/kms/key-providers/{sec256k1-provider.d.ts → secp256k1-provider.d.ts} +15 -9
  98. package/dist/types/kms/kms.d.ts +18 -0
  99. package/dist/types/proof/proof-service.d.ts +2 -2
  100. package/dist/types/storage/blockchain/onchain-revocation.d.ts +1 -0
  101. package/dist/types/storage/blockchain/state.d.ts +7 -2
  102. package/dist/types/storage/interfaces/state.d.ts +26 -2
  103. package/dist/types/utils/did-helper.d.ts +9 -1
  104. package/dist/types/verifiable/constants.d.ts +1 -0
  105. package/package.json +10 -12
  106. package/LICENSE +0 -691
  107. package/dist/node/esm/kms/key-providers/sec256k1-provider.js +0 -71
@@ -1,7 +1,6 @@
1
- import { Poseidon } from '@iden3/js-crypto';
2
1
  import { BytesHelper, DID, MerklizedRootPosition } from '@iden3/js-iden3-core';
3
2
  import { Hash } from '@iden3/js-merkletree';
4
- import { AuthV2Inputs, CircuitId, Operators, Query, StateTransitionInputs, ValueProof } from '../circuits';
3
+ import { AuthV2Inputs, CircuitId, Operators, Query, ValueProof } from '../circuits';
5
4
  import { createVerifiablePresentation } from '../verifiable';
6
5
  import { parseCredentialSubject, parseQueryMetadata, toGISTProof, transformQueryValueToBigInts } from './common';
7
6
  import { NativeProver } from './provers/prover';
@@ -130,38 +129,9 @@ export class ProofService {
130
129
  };
131
130
  }
132
131
  /** {@inheritdoc IProofService.transitState} */
133
- async transitState(did, oldTreeState, isOldStateGenesis, stateStorage, ethSigner) {
134
- const authInfo = await this._inputsGenerator.prepareAuthBJJCredential(did, oldTreeState);
135
- const newTreeModel = await this._identityWallet.getDIDTreeModel(did);
136
- const claimsRoot = await newTreeModel.claimsTree.root();
137
- const rootOfRoots = await newTreeModel.rootsTree.root();
138
- const revocationRoot = await newTreeModel.revocationTree.root();
139
- const newTreeState = {
140
- revocationRoot,
141
- claimsRoot,
142
- state: newTreeModel.state,
143
- rootOfRoots
144
- };
145
- const challenge = Poseidon.hash([oldTreeState.state.bigInt(), newTreeState.state.bigInt()]);
146
- const signature = await this._identityWallet.signChallenge(challenge, authInfo.credential);
147
- const circuitInputs = new StateTransitionInputs();
148
- circuitInputs.id = DID.idFromDID(did);
149
- circuitInputs.signature = signature;
150
- circuitInputs.isOldStateGenesis = isOldStateGenesis;
151
- const authClaimIncProofNewState = await this._identityWallet.generateCredentialMtp(did, authInfo.credential, newTreeState);
152
- circuitInputs.newTreeState = authClaimIncProofNewState.treeState;
153
- circuitInputs.authClaimNewStateIncProof = authClaimIncProofNewState.proof;
154
- circuitInputs.oldTreeState = oldTreeState;
155
- circuitInputs.authClaim = {
156
- claim: authInfo.coreClaim,
157
- incProof: authInfo.incProof,
158
- nonRevProof: authInfo.nonRevProof
159
- };
160
- const inputs = circuitInputs.inputsMarshal();
161
- const proof = await this._prover.generate(inputs, CircuitId.StateTransition);
162
- const txId = await stateStorage.publishState(proof, ethSigner);
163
- await this._identityWallet.updateIdentityState(did, true, newTreeState);
164
- return txId;
132
+ async transitState(did, oldTreeState, isOldStateGenesis, stateStorage, // for compatibility with previous versions we leave this parameter
133
+ ethSigner) {
134
+ return this._identityWallet.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, this._prover);
165
135
  }
166
136
  async generateInputs(preparedCredential, identifier, proofReq, params, circuitQueries) {
167
137
  return this._inputsGenerator.generateInputs({
@@ -1,8 +1,9 @@
1
- import { DID, Id, getUnixTimestamp } from '@iden3/js-iden3-core';
1
+ import { DID, getUnixTimestamp } from '@iden3/js-iden3-core';
2
2
  import { ProofType } from '../../verifiable';
3
3
  import { AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainInputs, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, CircuitClaim, CircuitId, LinkedMultiQueryInputs, Operators, QueryOperators, ValueProof, getOperatorNameByValue } from '../../circuits';
4
4
  import { toClaimNonRevStatus, toGISTProof } from '../common';
5
5
  import { getUserDIDFromCredential } from '../../credentials';
6
+ import { isEthereumIdentity } from '../../utils';
6
7
  const allOperations = Object.values(QueryOperators);
7
8
  const v2Operations = [
8
9
  Operators.NOOP,
@@ -266,13 +267,7 @@ export class InputGenerator {
266
267
  circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
267
268
  ? BigInt(proofReq.params?.nullifierSessionId?.toString())
268
269
  : BigInt(0);
269
- let isEthIdentity = true;
270
- try {
271
- Id.ethAddressFromId(circuitInputs.id);
272
- }
273
- catch {
274
- isEthIdentity = false;
275
- }
270
+ const isEthIdentity = isEthereumIdentity(identifier);
276
271
  circuitInputs.isBJJAuthEnabled = isEthIdentity ? 0 : 1;
277
272
  circuitInputs.challenge = BigInt(params.challenge ?? 0);
278
273
  const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
@@ -294,10 +294,7 @@ export class PubSignalsVerifier {
294
294
  }
295
295
  };
296
296
  this.checkStateExistenceForId = async (userId, userState) => {
297
- const { latest } = await this.resolve(userId, userState.bigInt());
298
- if (!latest) {
299
- throw userStateError;
300
- }
297
+ await this.resolve(userId, userState.bigInt());
301
298
  };
302
299
  this.checkGlobalState = async (state, id) => {
303
300
  return this.rootResolve(state.bigInt(), id.bigInt());
@@ -390,7 +387,9 @@ export class PubSignalsVerifier {
390
387
  contractState = await this._stateStorage.getStateInfoByIdAndState(idBigInt, state);
391
388
  }
392
389
  catch (e) {
393
- if (e.errorArgs[0] === 'State does not exist') {
390
+ const stateNotExistErr = (e?.errorArgs ?? [])[0];
391
+ const errMsg = stateNotExistErr || e.message;
392
+ if (errMsg === 'State does not exist') {
394
393
  if (isGenesis) {
395
394
  return {
396
395
  latest: true,
@@ -1,6 +1,7 @@
1
1
  import { Contract, JsonRpcProvider } from 'ethers';
2
2
  import { Proof, Hash } from '@iden3/js-merkletree';
3
3
  import abi from '../blockchain/abi/CredentialStatusResolver.json';
4
+ import { TransactionService } from '../../blockchain';
4
5
  /**
5
6
  * OnChainRevocationStore is a class that allows to interact with the onchain contract
6
7
  * and build the revocation status.
@@ -26,6 +27,7 @@ export class OnChainRevocationStorage {
26
27
  contract = contract.connect(this._signer);
27
28
  }
28
29
  this._contract = contract;
30
+ this._transactionService = new TransactionService(this._provider);
29
31
  }
30
32
  /**
31
33
  * Get revocation status by issuerId, issuerState and nonce from the onchain.
@@ -75,18 +77,8 @@ export class OnChainRevocationStorage {
75
77
  maxFeePerGas,
76
78
  maxPriorityFeePerGas
77
79
  };
78
- const tx = await this._signer.sendTransaction(request);
79
- return tx.wait().then((txReceipt) => {
80
- if (!txReceipt) {
81
- throw new Error(`transaction: ${tx.hash} failed to mine`);
82
- }
83
- const status = txReceipt.status;
84
- const txnHash = txReceipt.hash;
85
- if (!status) {
86
- throw new Error(`transaction: ${txnHash} failed to mine`);
87
- }
88
- return txReceipt;
89
- });
80
+ const { txnReceipt } = await this._transactionService.sendTransactionRequest(this._signer, request);
81
+ return txnReceipt;
90
82
  }
91
83
  static convertIssuerInfo(issuer) {
92
84
  const [state, claimsTreeRoot, revocationTreeRoot, rootOfRoots] = issuer.map((i) => Hash.fromBigInt(i).hex());
@@ -1,5 +1,6 @@
1
1
  import { JsonRpcProvider, Contract } from 'ethers';
2
2
  import abi from './abi/ZkpVerifier.json';
3
+ import { TransactionService } from '../../blockchain';
3
4
  /**
4
5
  * OnChainZKPVerifier is a class that allows to interact with the OnChainZKPVerifier contract
5
6
  * and submitZKPResponse.
@@ -73,16 +74,8 @@ export class OnChainZKPVerifier {
73
74
  maxFeePerGas,
74
75
  maxPriorityFeePerGas
75
76
  };
76
- const tx = await ethSigner.sendTransaction(request);
77
- const txnReceipt = await tx.wait();
78
- if (!txnReceipt) {
79
- throw new Error(`transaction: ${tx.hash} failed to mined`);
80
- }
81
- const status = txnReceipt.status;
82
- const txnHash = txnReceipt.hash;
83
- if (!status) {
84
- throw new Error(`transaction: ${txnHash} failed to mined`);
85
- }
77
+ const transactionService = new TransactionService(provider);
78
+ const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
86
79
  response.set(txnHash, zkProof);
87
80
  }
88
81
  return response;
@@ -3,6 +3,7 @@ import { StateTransitionPubSignals } from '../../circuits';
3
3
  import { byteEncoder } from '../../utils';
4
4
  import abi from './abi/State.json';
5
5
  import { DID, getChainId, Id } from '@iden3/js-iden3-core';
6
+ import { TransactionService } from '../../blockchain';
6
7
  export /** @type {EthConnectionConfig} - default configuration for EthConnectionConfig */ const defaultEthConnectionConfig = {
7
8
  url: 'http://localhost:8545',
8
9
  defaultGasLimit: 600000,
@@ -33,6 +34,7 @@ export class EthStateStorage {
33
34
  const config = Array.isArray(ethConfig) ? ethConfig[0] : ethConfig;
34
35
  this.provider = new JsonRpcProvider(config.url);
35
36
  this.stateContract = new Contract(config.contractAddress, abi, this.provider);
37
+ this._transactionService = new TransactionService(this.getRpcProvider());
36
38
  }
37
39
  /** {@inheritdoc IStateStorage.getLatestStateById} */
38
40
  async getLatestStateById(id) {
@@ -99,16 +101,39 @@ export class EthStateStorage {
99
101
  maxFeePerGas,
100
102
  maxPriorityFeePerGas
101
103
  };
102
- const tx = await signer.sendTransaction(request);
103
- const txnReceipt = await tx.wait();
104
- if (!txnReceipt) {
105
- throw new Error(`transaction: ${tx.hash} failed to mined`);
106
- }
107
- const status = txnReceipt.status;
108
- const txnHash = txnReceipt.hash;
109
- if (!status) {
110
- throw new Error(`transaction: ${txnHash} failed to mined`);
111
- }
104
+ const { txnHash } = await this._transactionService.sendTransactionRequest(signer, request);
105
+ return txnHash;
106
+ }
107
+ /** {@inheritdoc IStateStorage.publishStateGeneric} */
108
+ async publishStateGeneric(signer, userStateTransitionInfo) {
109
+ const { userId, oldUserState, newUserState, isOldStateGenesis, methodId, methodParams } = userStateTransitionInfo;
110
+ const { stateContract, provider } = this.getStateContractAndProviderForId(userId.bigInt());
111
+ const contract = stateContract.connect(signer);
112
+ const feeData = await provider.getFeeData();
113
+ const maxFeePerGas = defaultEthConnectionConfig.maxFeePerGas
114
+ ? BigInt(defaultEthConnectionConfig.maxFeePerGas)
115
+ : feeData.maxFeePerGas;
116
+ const maxPriorityFeePerGas = defaultEthConnectionConfig.maxPriorityFeePerGas
117
+ ? BigInt(defaultEthConnectionConfig.maxPriorityFeePerGas)
118
+ : feeData.maxPriorityFeePerGas;
119
+ const payload = [
120
+ userId.bigInt().toString(),
121
+ oldUserState.bigInt().toString(),
122
+ newUserState.bigInt().toString(),
123
+ isOldStateGenesis,
124
+ methodId,
125
+ methodParams //'0x'
126
+ ];
127
+ const gasLimit = await contract.transitStateGeneric.estimateGas(...payload);
128
+ const txData = await contract.transitStateGeneric.populateTransaction(...payload);
129
+ const request = {
130
+ to: txData.to,
131
+ data: txData.data,
132
+ gasLimit,
133
+ maxFeePerGas,
134
+ maxPriorityFeePerGas
135
+ };
136
+ const { txnHash } = await this._transactionService.sendTransactionRequest(signer, request);
112
137
  return txnHash;
113
138
  }
114
139
  /** {@inheritdoc IStateStorage.getGISTProof} */
@@ -139,6 +164,10 @@ export class EthStateStorage {
139
164
  replacedAtBlock: BigInt(data.replacedAtBlock.toString())
140
165
  };
141
166
  }
167
+ /** {@inheritdoc IStateStorage.getRpcProvider} */
168
+ getRpcProvider() {
169
+ return this.provider;
170
+ }
142
171
  getStateContractAndProviderForId(id) {
143
172
  const idTyped = Id.fromBigInt(id);
144
173
  if (!Array.isArray(this.ethConfig)) {
@@ -1,10 +1,12 @@
1
1
  import { Hex } from '@iden3/js-crypto';
2
2
  import { Id, buildDIDType, genesisFromEthAddress, DID } from '@iden3/js-iden3-core';
3
3
  import { Hash } from '@iden3/js-merkletree';
4
+ import { keccak256 } from 'js-sha3';
5
+ import { hexToBytes } from './encoding';
4
6
  /**
5
7
  * Checks if state is genesis state
6
8
  *
7
- * @param {string} did - did
9
+ * @param {DID} did - did
8
10
  * @param {bigint|string} state - hash on bigInt or hex string format
9
11
  * @returns boolean
10
12
  */
@@ -18,6 +20,24 @@ export function isGenesisState(did, state) {
18
20
  const idFromState = Id.idGenesisFromIdenState(type, state);
19
21
  return id.bigInt().toString() === idFromState.bigInt().toString();
20
22
  }
23
+ /**
24
+ * Checks if DID is an ethereum identity
25
+ *
26
+ * @param {DID} did - did
27
+ * @returns boolean
28
+ */
29
+ export function isEthereumIdentity(did) {
30
+ const issuerId = DID.idFromDID(did);
31
+ try {
32
+ Id.ethAddressFromId(issuerId);
33
+ // is an ethereum identity
34
+ return true;
35
+ }
36
+ catch {
37
+ // not an ethereum identity (BabyJubJub or other)
38
+ return false;
39
+ }
40
+ }
21
41
  export const buildVerifierId = (address, info) => {
22
42
  address = address.replace('0x', '');
23
43
  const ethAddrBytes = Hex.decodeString(address);
@@ -46,3 +66,15 @@ export const resolveDIDDocumentAuth = async (did, resolveURL, state) => {
46
66
  const didResolutionRes = (await resp.json());
47
67
  return didResolutionRes.didDocument?.verificationMethod?.find((i) => i.type === 'Iden3StateInfo2023');
48
68
  };
69
+ export const buildDIDFromEthPubKey = (didType, pubKeyEth) => {
70
+ // Use Keccak-256 hash function to get public key hash
71
+ const hashOfPublicKey = keccak256(hexToBytes(pubKeyEth));
72
+ // Convert hash to buffer
73
+ const ethAddressBuffer = hexToBytes(hashOfPublicKey);
74
+ // Ethereum Address is '0x' concatenated with last 20 bytes
75
+ // of the public key hash
76
+ const ethAddr = ethAddressBuffer.slice(-20);
77
+ const genesis = genesisFromEthAddress(ethAddr);
78
+ const identifier = new Id(didType, genesis);
79
+ return DID.parseFromId(identifier);
80
+ };
@@ -4,7 +4,8 @@ export const VerifiableConstants = Object.freeze({
4
4
  FiELD_IS_EMPTY: 'fieldPath is empty',
5
5
  CONTEXT_TYPE_IS_EMPTY: 'ctxType is empty',
6
6
  // ErrStateNotFound issuer state is genesis state.
7
- IDENTITY_DOES_NOT_EXIST: 'Identity does not exist'
7
+ IDENTITY_DOES_NOT_EXIST: 'Identity does not exist',
8
+ NO_AUTH_CRED_FOUND: 'no auth credentials found'
8
9
  },
9
10
  CREDENTIAL_TYPE: {
10
11
  // VerifiableCredential is a W3C verifiable credential type
@@ -0,0 +1 @@
1
+ export * from './transaction-service';
@@ -0,0 +1,80 @@
1
+ import { Block, JsonRpcProvider, Signer, TransactionReceipt, TransactionRequest } from 'ethers';
2
+ /**
3
+ * Resend transaction options
4
+ * @type ResendTxnOptions
5
+ */
6
+ export type ResendTxnOptions = {
7
+ increasedFeesPercentage?: number;
8
+ };
9
+ /**
10
+ * Interface for TransactionService
11
+ * @public
12
+ */
13
+ export interface ITransactionService {
14
+ /**
15
+ * Returns transaction receipt and block by transaction hash
16
+ *
17
+ * @param {string} transactionHash - transaction hash.
18
+ * @returns `Promise<{receipt?: TransactionReceipt , block?: Block}>` - returns transaction receipt and block
19
+ * @public
20
+ */
21
+ getTransactionReceiptAndBlock(transactionHash: string): Promise<{
22
+ receipt?: TransactionReceipt;
23
+ block?: Block;
24
+ }>;
25
+ /**
26
+ * Send transaction.
27
+ *
28
+ * @param {Signer} signer - transaction signer.
29
+ * @param {TransactionRequest} request - transaction request.
30
+ * @returns `Promise<txnHash: string, txnReceipt: TransactionReceipt` - returns txn hash and txn receipt.
31
+ * @public
32
+ */
33
+ sendTransactionRequest(signer: Signer, request: TransactionRequest): Promise<{
34
+ txnHash: string;
35
+ txnReceipt: TransactionReceipt;
36
+ }>;
37
+ /**
38
+ * Resend transaction with options. Useful when `transaction underpriced` error thrown on transaction.
39
+ *
40
+ * @param {Signer} signer - transaction signer.
41
+ * @param {TransactionRequest} request - transaction request.
42
+ * @param {ResendTxnOptions} opts - resend transaction options.
43
+ * @returns `Promise<{ txnHash: string; txnReceipt: TransactionReceipt }>` -returns txn hash and txn receipt.
44
+ * @public
45
+ */
46
+ resendTransaction(signer: Signer, request: TransactionRequest, opts?: ResendTxnOptions): Promise<{
47
+ txnHash: string;
48
+ txnReceipt: TransactionReceipt;
49
+ }>;
50
+ }
51
+ /**
52
+ * Transaction service to provide interaction with blockchain transactions.
53
+ * allows to: get tx receipt by tx id, send and resend transaction with new fees.
54
+ * @class TransactionService
55
+ * @public
56
+ * @implements ITransactionService interface
57
+ */
58
+ export declare class TransactionService implements ITransactionService {
59
+ private readonly _provider;
60
+ /**
61
+ * Creates an instance of TransactionService.
62
+ * @param {JsonRpcProvider} - RPC provider
63
+ */
64
+ constructor(_provider: JsonRpcProvider);
65
+ /** {@inheritDoc ITransactionService.getTransactionReceiptAndBlock} */
66
+ getTransactionReceiptAndBlock(txnHash: string): Promise<{
67
+ receipt?: TransactionReceipt;
68
+ block?: Block;
69
+ }>;
70
+ /** {@inheritDoc ITransactionService.sendTransactionRequest} */
71
+ sendTransactionRequest(signer: Signer, request: TransactionRequest): Promise<{
72
+ txnHash: string;
73
+ txnReceipt: TransactionReceipt;
74
+ }>;
75
+ /** {@inheritDoc ITransactionService.resendTransaction} */
76
+ resendTransaction(signer: Signer, request: TransactionRequest, opts?: ResendTxnOptions): Promise<{
77
+ txnHash: string;
78
+ txnReceipt: TransactionReceipt;
79
+ }>;
80
+ }
@@ -1,7 +1,8 @@
1
1
  import { MediaType } from '../constants';
2
2
  import { IProofService } from '../../proof/proof-service';
3
- import { AuthorizationRequestMessage, AuthorizationResponseMessage, IPackageManager, JWSPackerParams } from '../types';
3
+ import { AuthorizationRequestMessage, AuthorizationResponseMessage, BasicMessage, IPackageManager, JWSPackerParams } from '../types';
4
4
  import { DID } from '@iden3/js-iden3-core';
5
+ import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
5
6
  /**
6
7
  * createAuthorizationRequest is a function to create protocol authorization request
7
8
  * @param {string} reason - reason to request proof
@@ -76,6 +77,16 @@ export interface IAuthHandler {
76
77
  response: AuthorizationResponseMessage;
77
78
  }>;
78
79
  }
80
+ type AuthReqOptions = {
81
+ senderDid: DID;
82
+ mediaType?: MediaType;
83
+ };
84
+ type AuthRespOptions = {
85
+ request: AuthorizationRequestMessage;
86
+ acceptedStateTransitionDelay?: number;
87
+ acceptedProofGenerationDelay?: number;
88
+ };
89
+ export type AuthMessageHandlerOptions = AuthReqOptions | AuthRespOptions;
79
90
  /**
80
91
  *
81
92
  * Options to pass to auth handler
@@ -96,7 +107,7 @@ export interface AuthHandlerOptions {
96
107
  * @class AuthHandler
97
108
  * @implements implements IAuthHandler interface
98
109
  */
99
- export declare class AuthHandler implements IAuthHandler {
110
+ export declare class AuthHandler extends AbstractMessageHandler implements IAuthHandler, IProtocolMessageHandler {
100
111
  private readonly _packerMgr;
101
112
  private readonly _proofService;
102
113
  private readonly _supportedCircuits;
@@ -107,10 +118,12 @@ export declare class AuthHandler implements IAuthHandler {
107
118
  *
108
119
  */
109
120
  constructor(_packerMgr: IPackageManager, _proofService: IProofService);
121
+ handle(message: BasicMessage, ctx: AuthMessageHandlerOptions): Promise<BasicMessage | null>;
110
122
  /**
111
123
  * @inheritdoc IAuthHandler#parseAuthorizationRequest
112
124
  */
113
125
  parseAuthorizationRequest(request: Uint8Array): Promise<AuthorizationRequestMessage>;
126
+ private handleAuthRequest;
114
127
  /**
115
128
  * @inheritdoc IAuthHandler#handleAuthorizationRequest
116
129
  */
@@ -119,6 +132,7 @@ export declare class AuthHandler implements IAuthHandler {
119
132
  authRequest: AuthorizationRequestMessage;
120
133
  authResponse: AuthorizationResponseMessage;
121
134
  }>;
135
+ private handleAuthResponse;
122
136
  /**
123
137
  * @inheritdoc IAuthHandler#handleAuthorizationResponse
124
138
  */
@@ -128,3 +142,4 @@ export declare class AuthHandler implements IAuthHandler {
128
142
  }>;
129
143
  private verifyAuthRequest;
130
144
  }
145
+ export {};
@@ -7,14 +7,14 @@ import { Signer } from 'ethers';
7
7
  /**
8
8
  * Processes zero knowledge proof requests.
9
9
  *
10
- * @param senderIdentifier - The identifier of the sender.
10
+ * @param to - The identifier of the recipient.
11
11
  * @param requests - An array of zero knowledge proof requests.
12
12
  * @param from - The identifier of the sender.
13
13
  * @param proofService - The proof service.
14
14
  * @param opts - Additional options for processing the requests.
15
15
  * @returns A promise that resolves to an array of zero knowledge proof responses.
16
16
  */
17
- export declare const processZeroKnowledgeProofRequests: (senderIdentifier: DID, requests: ZeroKnowledgeProofRequest[] | undefined, from: DID | undefined, proofService: IProofService, opts: {
17
+ export declare const processZeroKnowledgeProofRequests: (to: DID, requests: ZeroKnowledgeProofRequest[] | undefined, from: DID | undefined, proofService: IProofService, opts: {
18
18
  mediaType?: MediaType;
19
19
  packerOptions?: JWSPackerParams;
20
20
  supportedCircuits: CircuitId[];
@@ -1,9 +1,10 @@
1
1
  import { IProofService } from '../../proof/proof-service';
2
- import { IPackageManager, ZeroKnowledgeProofResponse } from '../types';
2
+ import { BasicMessage, IPackageManager, ZeroKnowledgeProofResponse } from '../types';
3
3
  import { ContractInvokeRequest } from '../types/protocol/contract-request';
4
4
  import { DID } from '@iden3/js-iden3-core';
5
5
  import { IOnChainZKPVerifier } from '../../storage';
6
6
  import { Signer } from 'ethers';
7
+ import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
7
8
  /**
8
9
  * Interface that allows the processing of the contract request
9
10
  *
@@ -33,6 +34,11 @@ export type ContractInvokeHandlerOptions = {
33
34
  ethSigner: Signer;
34
35
  challenge?: bigint;
35
36
  };
37
+ export type ContractMessageHandlerOptions = {
38
+ senderDid: DID;
39
+ ethSigner: Signer;
40
+ challenge?: bigint;
41
+ };
36
42
  /**
37
43
  *
38
44
  * Allows to process ContractInvokeRequest protocol message
@@ -42,7 +48,7 @@ export type ContractInvokeHandlerOptions = {
42
48
  * @class ContractRequestHandler
43
49
  * @implements implements IContractRequestHandler interface
44
50
  */
45
- export declare class ContractRequestHandler implements IContractRequestHandler {
51
+ export declare class ContractRequestHandler extends AbstractMessageHandler implements IContractRequestHandler, IProtocolMessageHandler {
46
52
  private readonly _packerMgr;
47
53
  private readonly _proofService;
48
54
  private readonly _zkpVerifier;
@@ -55,6 +61,8 @@ export declare class ContractRequestHandler implements IContractRequestHandler {
55
61
  *
56
62
  */
57
63
  constructor(_packerMgr: IPackageManager, _proofService: IProofService, _zkpVerifier: IOnChainZKPVerifier);
64
+ handle(message: BasicMessage, ctx: ContractMessageHandlerOptions): Promise<BasicMessage | null>;
65
+ private handleContractInvoke;
58
66
  /**
59
67
  * unpacks contract-invoke request
60
68
  * @beta
@@ -1,7 +1,8 @@
1
- import { IPackageManager, JSONObject, PackerParams } from '../types';
1
+ import { BasicMessage, IPackageManager, JSONObject, 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';
5
+ import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
5
6
  /** @beta ProposalRequestCreationOptions represents proposal-request creation options */
6
7
  export type ProposalRequestCreationOptions = {
7
8
  credentials: ProposalRequestCredential[];
@@ -83,7 +84,7 @@ export type CredentialProposalHandlerParams = {
83
84
  * @class CredentialProposalHandler
84
85
  * @implements implements ICredentialProposalHandler interface
85
86
  */
86
- export declare class CredentialProposalHandler implements ICredentialProposalHandler {
87
+ export declare class CredentialProposalHandler extends AbstractMessageHandler implements ICredentialProposalHandler, IProtocolMessageHandler {
87
88
  private readonly _packerMgr;
88
89
  private readonly _identityWallet;
89
90
  private readonly _params;
@@ -95,10 +96,12 @@ export declare class CredentialProposalHandler implements ICredentialProposalHan
95
96
  *
96
97
  */
97
98
  constructor(_packerMgr: IPackageManager, _identityWallet: IIdentityWallet, _params: CredentialProposalHandlerParams);
99
+ handle(message: BasicMessage, context: ProposalRequestHandlerOptions): Promise<BasicMessage | null>;
98
100
  /**
99
101
  * @inheritdoc ICredentialProposalHandler#parseProposalRequest
100
102
  */
101
103
  parseProposalRequest(request: Uint8Array): Promise<ProposalRequestMessage>;
104
+ private handleProposalRequestMessage;
102
105
  /**
103
106
  * @inheritdoc ICredentialProposalHandler#handleProposalRequest
104
107
  */
@@ -1,7 +1,8 @@
1
1
  import { MediaType } from '../constants';
2
- import { IPackageManager, JWSPackerParams } from '../types';
2
+ import { BasicMessage, IPackageManager, JWSPackerParams } from '../types';
3
3
  import { W3CCredential } from '../../verifiable';
4
4
  import { ICredentialWallet } from '../../credentials';
5
+ import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
5
6
  /**
6
7
  *
7
8
  * Options to pass to fetch handler
@@ -9,13 +10,14 @@ import { ICredentialWallet } from '../../credentials';
9
10
  * @public
10
11
  * @interface FetchHandlerOptions
11
12
  */
12
- export interface FetchHandlerOptions {
13
+ export type FetchHandlerOptions = {
13
14
  mediaType: MediaType;
14
15
  packerOptions?: JWSPackerParams;
15
16
  headers?: {
16
17
  [key: string]: string;
17
18
  };
18
- }
19
+ };
20
+ export type FetchMessageHandlerOptions = FetchHandlerOptions;
19
21
  /**
20
22
  * Interface that allows the processing of the credential offer in the raw format for given identifier
21
23
  *
@@ -61,16 +63,21 @@ export interface IFetchHandler {
61
63
  * @class FetchHandler
62
64
  * @implements implements IFetchHandler interface
63
65
  */
64
- export declare class FetchHandler implements IFetchHandler {
66
+ export declare class FetchHandler extends AbstractMessageHandler implements IFetchHandler, IProtocolMessageHandler {
65
67
  private readonly _packerMgr;
66
68
  private readonly opts?;
67
69
  /**
68
- * Creates an instance of FetchHandler.
69
- * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
70
+ * Constructs a new instance of the FetchHandler class.
71
+ *
72
+ * @param _packerMgr The package manager used for packing and unpacking data.
73
+ * @param opts Optional configuration options for the FetchHandler.
74
+ * @param opts.credentialWallet The credential wallet used for managing credentials.
70
75
  */
71
76
  constructor(_packerMgr: IPackageManager, opts?: {
72
77
  credentialWallet: ICredentialWallet;
73
78
  } | undefined);
79
+ handle(message: BasicMessage, ctx: FetchMessageHandlerOptions): Promise<BasicMessage | null>;
80
+ private handleOfferMessage;
74
81
  /**
75
82
  * Handles only messages with credentials/1.0/offer type
76
83
  *
@@ -81,10 +88,12 @@ export declare class FetchHandler implements IFetchHandler {
81
88
  * @returns `Promise<W3CCredential[]>`
82
89
  */
83
90
  handleCredentialOffer(offer: Uint8Array, opts?: FetchHandlerOptions): Promise<W3CCredential[]>;
91
+ private handleFetchRequest;
84
92
  /**
85
93
  * @inheritdoc IFetchHandler#handleCredentialFetchRequest
86
94
  */
87
95
  handleCredentialFetchRequest(envelope: Uint8Array): Promise<Uint8Array>;
96
+ private handleIssuanceResponseMsg;
88
97
  /**
89
98
  * @inheritdoc IFetchHandler#handleIssuanceResponseMessage
90
99
  */
@@ -5,3 +5,4 @@ export * from './refresh';
5
5
  export * from './revocation-status';
6
6
  export * from './common';
7
7
  export * from './credential-proposal';
8
+ export * from './message-handler';