@0xpolygonid/js-sdk 1.21.3 → 1.24.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.
Files changed (114) hide show
  1. package/dist/browser/esm/index.js +4378 -545
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +4388 -545
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/credentials/credential-wallet.js +11 -78
  6. package/dist/node/cjs/credentials/index.js +1 -0
  7. package/dist/node/cjs/credentials/status/did-resolver-revocation.js +21 -0
  8. package/dist/node/cjs/iden3comm/constants.js +25 -1
  9. package/dist/node/cjs/iden3comm/handlers/auth.js +52 -8
  10. package/dist/node/cjs/iden3comm/handlers/common.js +13 -1
  11. package/dist/node/cjs/iden3comm/handlers/contract-request.js +5 -1
  12. package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +14 -3
  13. package/dist/node/cjs/iden3comm/handlers/fetch.js +44 -2
  14. package/dist/node/cjs/iden3comm/handlers/message-handler.js +4 -0
  15. package/dist/node/cjs/iden3comm/handlers/payment.js +265 -28
  16. package/dist/node/cjs/iden3comm/handlers/revocation-status.js +4 -0
  17. package/dist/node/cjs/iden3comm/index.js +1 -0
  18. package/dist/node/cjs/iden3comm/packageManager.js +12 -0
  19. package/dist/node/cjs/iden3comm/packers/jws.js +21 -0
  20. package/dist/node/cjs/iden3comm/packers/plain.js +19 -0
  21. package/dist/node/cjs/iden3comm/packers/zkp.js +25 -0
  22. package/dist/node/cjs/iden3comm/types/index.js +1 -0
  23. package/dist/node/cjs/iden3comm/types/protocol/accept-profile.js +2 -0
  24. package/dist/node/cjs/iden3comm/utils/accept-profile.js +107 -0
  25. package/dist/node/cjs/iden3comm/utils/index.js +1 -0
  26. package/dist/node/cjs/storage/blockchain/abi/ERC20.json +1 -0
  27. package/dist/node/cjs/storage/blockchain/abi/ERC20Permit.json +1 -0
  28. package/dist/node/cjs/storage/blockchain/did-resolver-readonly-storage.js +72 -0
  29. package/dist/node/cjs/storage/blockchain/erc20-helper.js +59 -0
  30. package/dist/node/cjs/storage/blockchain/index.js +3 -0
  31. package/dist/node/cjs/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +245 -0
  32. package/dist/node/cjs/storage/blockchain/onchain-issuer.js +82 -0
  33. package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +38 -34
  34. package/dist/node/cjs/storage/interfaces/index.js +1 -0
  35. package/dist/node/cjs/storage/interfaces/onchain-issuer.js +2 -0
  36. package/dist/node/cjs/utils/did-helper.js +3 -3
  37. package/dist/node/cjs/verifiable/constants.js +29 -11
  38. package/dist/node/cjs/verifiable/credential.js +86 -0
  39. package/dist/node/esm/credentials/credential-wallet.js +12 -79
  40. package/dist/node/esm/credentials/index.js +1 -0
  41. package/dist/node/esm/credentials/status/did-resolver-revocation.js +17 -0
  42. package/dist/node/esm/iden3comm/constants.js +24 -0
  43. package/dist/node/esm/iden3comm/handlers/auth.js +55 -11
  44. package/dist/node/esm/iden3comm/handlers/common.js +11 -0
  45. package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -3
  46. package/dist/node/esm/iden3comm/handlers/credential-proposal.js +15 -4
  47. package/dist/node/esm/iden3comm/handlers/fetch.js +44 -2
  48. package/dist/node/esm/iden3comm/handlers/message-handler.js +4 -0
  49. package/dist/node/esm/iden3comm/handlers/payment.js +264 -29
  50. package/dist/node/esm/iden3comm/handlers/revocation-status.js +4 -0
  51. package/dist/node/esm/iden3comm/index.js +1 -0
  52. package/dist/node/esm/iden3comm/packageManager.js +12 -0
  53. package/dist/node/esm/iden3comm/packers/jws.js +22 -1
  54. package/dist/node/esm/iden3comm/packers/plain.js +19 -0
  55. package/dist/node/esm/iden3comm/packers/zkp.js +26 -1
  56. package/dist/node/esm/iden3comm/types/index.js +1 -0
  57. package/dist/node/esm/iden3comm/types/protocol/accept-profile.js +1 -0
  58. package/dist/node/esm/iden3comm/utils/accept-profile.js +102 -0
  59. package/dist/node/esm/iden3comm/utils/index.js +1 -0
  60. package/dist/node/esm/storage/blockchain/abi/ERC20.json +1 -0
  61. package/dist/node/esm/storage/blockchain/abi/ERC20Permit.json +1 -0
  62. package/dist/node/esm/storage/blockchain/did-resolver-readonly-storage.js +68 -0
  63. package/dist/node/esm/storage/blockchain/erc20-helper.js +51 -0
  64. package/dist/node/esm/storage/blockchain/index.js +3 -0
  65. package/dist/node/esm/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +241 -0
  66. package/dist/node/esm/storage/blockchain/onchain-issuer.js +78 -0
  67. package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +38 -34
  68. package/dist/node/esm/storage/interfaces/index.js +1 -0
  69. package/dist/node/esm/storage/interfaces/onchain-issuer.js +1 -0
  70. package/dist/node/esm/utils/did-helper.js +3 -3
  71. package/dist/node/esm/verifiable/constants.js +28 -10
  72. package/dist/node/esm/verifiable/credential.js +88 -2
  73. package/dist/types/credentials/credential-wallet.d.ts +0 -6
  74. package/dist/types/credentials/index.d.ts +1 -0
  75. package/dist/types/credentials/models.d.ts +8 -0
  76. package/dist/types/credentials/status/did-resolver-revocation.d.ts +7 -0
  77. package/dist/types/iden3comm/constants.d.ts +16 -0
  78. package/dist/types/iden3comm/handlers/auth.d.ts +19 -7
  79. package/dist/types/iden3comm/handlers/common.d.ts +7 -1
  80. package/dist/types/iden3comm/handlers/contract-request.d.ts +2 -2
  81. package/dist/types/iden3comm/handlers/credential-proposal.d.ts +9 -4
  82. package/dist/types/iden3comm/handlers/fetch.d.ts +30 -6
  83. package/dist/types/iden3comm/handlers/message-handler.d.ts +6 -0
  84. package/dist/types/iden3comm/handlers/payment.d.ts +71 -10
  85. package/dist/types/iden3comm/handlers/revocation-status.d.ts +2 -2
  86. package/dist/types/iden3comm/index.d.ts +1 -0
  87. package/dist/types/iden3comm/packageManager.d.ts +4 -0
  88. package/dist/types/iden3comm/packers/jws.d.ts +5 -0
  89. package/dist/types/iden3comm/packers/plain.d.ts +4 -0
  90. package/dist/types/iden3comm/packers/zkp.d.ts +6 -0
  91. package/dist/types/iden3comm/types/index.d.ts +1 -0
  92. package/dist/types/iden3comm/types/packageManager.d.ts +14 -0
  93. package/dist/types/iden3comm/types/packer.d.ts +25 -0
  94. package/dist/types/iden3comm/types/protocol/accept-profile.d.ts +7 -0
  95. package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
  96. package/dist/types/iden3comm/types/protocol/credentials.d.ts +6 -6
  97. package/dist/types/iden3comm/types/protocol/messages.d.ts +2 -2
  98. package/dist/types/iden3comm/types/protocol/payment.d.ts +87 -13
  99. package/dist/types/iden3comm/types/protocol/proof.d.ts +3 -3
  100. package/dist/types/iden3comm/types/protocol/revocation.d.ts +2 -2
  101. package/dist/types/iden3comm/utils/accept-profile.d.ts +3 -0
  102. package/dist/types/iden3comm/utils/index.d.ts +1 -0
  103. package/dist/types/storage/blockchain/did-resolver-readonly-storage.d.ts +16 -0
  104. package/dist/types/storage/blockchain/erc20-helper.d.ts +19 -0
  105. package/dist/types/storage/blockchain/index.d.ts +3 -0
  106. package/dist/types/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.d.ts +66 -0
  107. package/dist/types/storage/blockchain/onchain-issuer.d.ts +40 -0
  108. package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +11 -12
  109. package/dist/types/storage/entities/state.d.ts +2 -0
  110. package/dist/types/storage/interfaces/index.d.ts +1 -0
  111. package/dist/types/storage/interfaces/onchain-issuer.d.ts +12 -0
  112. package/dist/types/verifiable/constants.d.ts +28 -11
  113. package/dist/types/verifiable/credential.d.ts +15 -2
  114. package/package.json +3 -2
@@ -37,23 +37,8 @@ export class OnChainZKPVerifier {
37
37
  constructor(_configs, _opts) {
38
38
  this._configs = _configs;
39
39
  this._opts = _opts;
40
- /**
41
- * supported circuits
42
- */
43
- this._supportedCircuits = [
44
- CircuitId.AtomicQueryMTPV2OnChain,
45
- CircuitId.AtomicQuerySigV2OnChain,
46
- CircuitId.AtomicQueryV3OnChain
47
- ];
48
- /**
49
- * abi coder to encode/decode structures to solidity bytes
50
- */
51
- this._abiCoder = new ethers.AbiCoder();
52
40
  }
53
- /**
54
- * {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
55
- */
56
- async prepareTxArgsSubmitV1(txData, zkProofResponse) {
41
+ static async prepareTxArgsSubmitV1(txData, zkProofResponse) {
57
42
  if (txData.method_id.replace('0x', '') !== FunctionSignatures.SubmitZKPResponseV1) {
58
43
  throw new Error(`prepareTxArgsSubmitV1 function doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV1}' is supported.`);
59
44
  }
@@ -71,6 +56,12 @@ export class OnChainZKPVerifier {
71
56
  ];
72
57
  return payload;
73
58
  }
59
+ /**
60
+ * {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
61
+ */
62
+ async prepareTxArgsSubmitV1(txData, zkProofResponse) {
63
+ return OnChainZKPVerifier.prepareTxArgsSubmitV1(txData, zkProofResponse);
64
+ }
74
65
  /**
75
66
  * {@inheritDoc IOnChainZKPVerifier.submitZKPResponse}
76
67
  */
@@ -160,13 +151,10 @@ export class OnChainZKPVerifier {
160
151
  const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
161
152
  return new Map().set(txnHash, zkProofResponses);
162
153
  }
163
- async prepareTxArgsSubmitV2(txData, zkProofResponses) {
154
+ static async prepareTxArgsSubmitV2(resolverUrl, txData, zkProofResponses) {
164
155
  if (txData.method_id.replace('0x', '') !== FunctionSignatures.SubmitZKPResponseV2) {
165
156
  throw new Error(`submit cross chain doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV2}' is supported.`);
166
157
  }
167
- if (!this._opts?.didResolverUrl) {
168
- throw new Error(`did resolver url required for crosschain verification`);
169
- }
170
158
  const gistUpdateArr = [];
171
159
  const stateUpdateArr = [];
172
160
  const payload = [];
@@ -191,7 +179,9 @@ export class OnChainZKPVerifier {
191
179
  continue;
192
180
  }
193
181
  gistUpdateResolutionsPending.push(JSON.stringify(gist));
194
- gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(gist.id), this._opts.didResolverUrl, { gist: gist.root }));
182
+ gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(gist.id), resolverUrl, {
183
+ gist: gist.root
184
+ }));
195
185
  }
196
186
  const stateUpdateResolutions = [];
197
187
  for (const state of stateInfo.states) {
@@ -200,7 +190,7 @@ export class OnChainZKPVerifier {
200
190
  continue;
201
191
  }
202
192
  stateUpdateResolutionsPending.push(JSON.stringify(state));
203
- stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(state.id), this._opts.didResolverUrl, {
193
+ stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(state.id), resolverUrl, {
204
194
  state: state.state
205
195
  }));
206
196
  }
@@ -234,10 +224,16 @@ export class OnChainZKPVerifier {
234
224
  const crossChainProofs = this.packCrossChainProofs(gistUpdateArr, stateUpdateArr);
235
225
  return [payload, crossChainProofs];
236
226
  }
237
- packZkpProof(inputs, a, b, c) {
238
- return this._abiCoder.encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
227
+ async prepareTxArgsSubmitV2(txData, zkProofResponses) {
228
+ if (!this._opts?.didResolverUrl) {
229
+ throw new Error(`did resolver url required for crosschain verification`);
230
+ }
231
+ return OnChainZKPVerifier.prepareTxArgsSubmitV2(this._opts.didResolverUrl, txData, zkProofResponses);
232
+ }
233
+ static packZkpProof(inputs, a, b, c) {
234
+ return new ethers.AbiCoder().encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
239
235
  }
240
- packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
236
+ static packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
241
237
  const proofs = [];
242
238
  for (const globalStateUpdate of gistUpdateArr) {
243
239
  proofs.push({
@@ -251,10 +247,10 @@ export class OnChainZKPVerifier {
251
247
  proof: this.packIdentityStateMsg(stateUpdate)
252
248
  });
253
249
  }
254
- return this._abiCoder.encode(['tuple(' + 'string proofType,' + 'bytes proof' + ')[]'], [proofs]);
250
+ return new ethers.AbiCoder().encode(['tuple(' + 'string proofType,' + 'bytes proof' + ')[]'], [proofs]);
255
251
  }
256
- packGlobalStateMsg(msg) {
257
- return this._abiCoder.encode([
252
+ static packGlobalStateMsg(msg) {
253
+ return new ethers.AbiCoder().encode([
258
254
  'tuple(' +
259
255
  'tuple(' +
260
256
  'uint256 timestamp,' +
@@ -266,8 +262,8 @@ export class OnChainZKPVerifier {
266
262
  ')'
267
263
  ], [msg]);
268
264
  }
269
- packIdentityStateMsg(msg) {
270
- return this._abiCoder.encode([
265
+ static packIdentityStateMsg(msg) {
266
+ return new ethers.AbiCoder().encode([
271
267
  'tuple(' +
272
268
  'tuple(' +
273
269
  'uint256 timestamp,' +
@@ -279,10 +275,10 @@ export class OnChainZKPVerifier {
279
275
  ')'
280
276
  ], [msg]);
281
277
  }
282
- packMetadatas(metas) {
283
- return this._abiCoder.encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
278
+ static packMetadatas(metas) {
279
+ return new ethers.AbiCoder().encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
284
280
  }
285
- getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
281
+ static getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
286
282
  let atomicQueryPubSignals;
287
283
  switch (onChainCircuitId) {
288
284
  case CircuitId.AtomicQueryMTPV2OnChain:
@@ -299,7 +295,7 @@ export class OnChainZKPVerifier {
299
295
  atomicQueryPubSignals.pubSignalsUnmarshal(encodedInputs);
300
296
  return atomicQueryPubSignals.getStatesInfo();
301
297
  }
302
- async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
298
+ static async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
303
299
  const didDoc = await resolveDidDocument(did, resolverUrl, {
304
300
  ...opts,
305
301
  signature: DIDDocumentSignature.EthereumEip712Signature2021
@@ -332,3 +328,11 @@ export class OnChainZKPVerifier {
332
328
  };
333
329
  }
334
330
  }
331
+ /**
332
+ * supported circuits
333
+ */
334
+ OnChainZKPVerifier._supportedCircuits = [
335
+ CircuitId.AtomicQueryMTPV2OnChain,
336
+ CircuitId.AtomicQuerySigV2OnChain,
337
+ CircuitId.AtomicQueryV3OnChain
338
+ ];
@@ -7,3 +7,4 @@ export * from './data-source';
7
7
  export * from './circuits';
8
8
  export * from './onchain-zkp-verifier';
9
9
  export * from './onchain-revocation';
10
+ export * from './onchain-issuer';
@@ -0,0 +1 @@
1
+ export {};
@@ -65,7 +65,7 @@ export const validateDIDDocumentAuth = async (did, resolverURL, state) => {
65
65
  }
66
66
  };
67
67
  export const resolveDIDDocumentAuth = async (did, resolveURL, state) => {
68
- let url = `${resolveURL}/${did.string().replace(/:/g, '%3A')}`;
68
+ let url = `${resolveURL}/${encodeURIComponent(did.string())}`;
69
69
  if (state) {
70
70
  url += `?state=${state.hex()}`;
71
71
  }
@@ -81,11 +81,11 @@ function emptyStateDID(did) {
81
81
  return emptyDID;
82
82
  }
83
83
  export const resolveDidDocument = async (did, resolverUrl, opts) => {
84
- let didString = did.string().replace(/:/g, '%3A');
84
+ let didString = encodeURIComponent(did.string());
85
85
  // for gist resolve we have to `hide` user did (look into resolver implementation)
86
86
  const isGistRequest = opts?.gist && !opts.state;
87
87
  if (isGistRequest) {
88
- didString = emptyStateDID(did).string();
88
+ didString = encodeURIComponent(emptyStateDID(did).string());
89
89
  }
90
90
  let url = `${resolverUrl}/1.0/identifiers/${didString}`;
91
91
  if (opts?.signature) {
@@ -112,15 +112,6 @@ export var RefreshServiceType;
112
112
  (function (RefreshServiceType) {
113
113
  RefreshServiceType["Iden3RefreshService2023"] = "Iden3RefreshService2023";
114
114
  })(RefreshServiceType || (RefreshServiceType = {}));
115
- /**
116
- * PaymentRequestType type for payment requests
117
- * @beta
118
- * @enum {string}
119
- */
120
- export var PaymentRequestType;
121
- (function (PaymentRequestType) {
122
- PaymentRequestType["PaymentRequest"] = "PaymentRequest";
123
- })(PaymentRequestType || (PaymentRequestType = {}));
124
115
  /**
125
116
  * PaymentRequestDataType type for payment requests
126
117
  * @beta
@@ -129,6 +120,8 @@ export var PaymentRequestType;
129
120
  export var PaymentRequestDataType;
130
121
  (function (PaymentRequestDataType) {
131
122
  PaymentRequestDataType["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
123
+ PaymentRequestDataType["Iden3PaymentRailsRequestV1"] = "Iden3PaymentRailsRequestV1";
124
+ PaymentRequestDataType["Iden3PaymentRailsERC20RequestV1"] = "Iden3PaymentRailsERC20RequestV1";
132
125
  })(PaymentRequestDataType || (PaymentRequestDataType = {}));
133
126
  /**
134
127
  * PaymentType type for payment responses
@@ -138,17 +131,42 @@ export var PaymentRequestDataType;
138
131
  export var PaymentType;
139
132
  (function (PaymentType) {
140
133
  PaymentType["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
134
+ PaymentType["Iden3PaymentRailsV1"] = "Iden3PaymentRailsV1";
135
+ PaymentType["Iden3PaymentRailsERC20V1"] = "Iden3PaymentRailsERC20V1";
141
136
  })(PaymentType || (PaymentType = {}));
137
+ /**
138
+ * SupportedPaymentProofType type for payment proofs
139
+ * @beta
140
+ * @enum {string}
141
+ */
142
+ export var SupportedPaymentProofType;
143
+ (function (SupportedPaymentProofType) {
144
+ SupportedPaymentProofType["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
145
+ })(SupportedPaymentProofType || (SupportedPaymentProofType = {}));
142
146
  /**
143
147
  * Media types for Payment supported currencies
144
148
  * @beta
145
- * @enum {number}
149
+ * @enum {string}
146
150
  */
147
151
  export var SupportedCurrencies;
148
152
  (function (SupportedCurrencies) {
149
153
  SupportedCurrencies["ETH"] = "ETH";
154
+ SupportedCurrencies["ETH_WEI"] = "ETHWEI";
155
+ SupportedCurrencies["ETH_GWEI"] = "ETHGWEI";
150
156
  SupportedCurrencies["MATIC"] = "MATIC";
157
+ SupportedCurrencies["POL"] = "POL";
158
+ SupportedCurrencies["USDT"] = "USDT";
159
+ SupportedCurrencies["USDC"] = "USDC";
151
160
  })(SupportedCurrencies || (SupportedCurrencies = {}));
161
+ /**
162
+ * Supported features for payment-request
163
+ * @beta
164
+ * @enum {string}
165
+ */
166
+ export var PaymentFeatures;
167
+ (function (PaymentFeatures) {
168
+ PaymentFeatures["EIP_2612"] = "EIP-2612";
169
+ })(PaymentFeatures || (PaymentFeatures = {}));
152
170
  /**
153
171
  * DisplayMethodType type for display method
154
172
  *
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { BJJSignatureProof2021, Iden3SparseMerkleTreeProof } from './proof';
3
- import { Claim, DID, MerklizedRootPosition as MerklizedRootPositionCore, IdPosition, ClaimOptions } from '@iden3/js-iden3-core';
3
+ import { Claim, DID, MerklizedRootPosition as MerklizedRootPositionCore, IdPosition, ClaimOptions, getChainId } from '@iden3/js-iden3-core';
4
4
  import { Hash, rootFromProof, verifyProof } from '@iden3/js-merkletree';
5
5
  import { Merklizer } from '@iden3/js-jsonld-merklization';
6
6
  import { PublicKey, poseidon } from '@iden3/js-crypto';
7
7
  import { getUserDIDFromCredential } from '../credentials/utils';
8
8
  import { byteEncoder, validateDIDDocumentAuth } from '../utils';
9
- import { MerklizedRootPosition, ProofType, SubjectPosition } from './constants';
9
+ import { CredentialStatusType, MerklizedRootPosition, ProofType, SubjectPosition, VerifiableConstants } from './constants';
10
10
  import { calculateCoreSchemaHash, findCredentialType, parseCoreClaimSlots } from './core-utils';
11
11
  import * as jsonld from 'jsonld/lib';
12
12
  import * as ldcontext from 'jsonld/lib/context';
@@ -25,6 +25,92 @@ export class W3CCredential {
25
25
  this.credentialSubject = {};
26
26
  this.issuer = '';
27
27
  }
28
+ /**
29
+ *
30
+ * @param issuer - DID of the issuer
31
+ * @param request - Credential request
32
+ * @returns - W3C Credential
33
+ */
34
+ static fromCredentialRequest(issuer, request) {
35
+ if (!request.id) {
36
+ throw new Error('Credential id is required');
37
+ }
38
+ if (!request.context) {
39
+ throw new Error('Credential context is required');
40
+ }
41
+ const context = [
42
+ VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018,
43
+ VerifiableConstants.JSONLD_SCHEMA.IDEN3_CREDENTIAL,
44
+ ...request.context
45
+ ];
46
+ const credentialType = [
47
+ VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_CREDENTIAL,
48
+ request.type
49
+ ];
50
+ const credentialSubject = request.credentialSubject;
51
+ credentialSubject['type'] = request.type;
52
+ const cr = new W3CCredential();
53
+ cr.id = request.id;
54
+ cr['@context'] = context;
55
+ cr.type = credentialType;
56
+ cr.credentialSubject = credentialSubject;
57
+ cr.issuer = issuer.string();
58
+ cr.credentialSchema = {
59
+ id: request.credentialSchema,
60
+ type: VerifiableConstants.JSON_SCHEMA_VALIDATOR
61
+ };
62
+ cr.credentialStatus = W3CCredential.buildCredentialStatus(request, issuer);
63
+ request.expiration && (cr.expirationDate = new Date(request.expiration).toISOString());
64
+ request.refreshService && (cr.refreshService = request.refreshService);
65
+ request.displayMethod && (cr.displayMethod = request.displayMethod);
66
+ request.issuanceDate && (cr.issuanceDate = new Date(request.issuanceDate).toISOString());
67
+ return cr;
68
+ }
69
+ /**
70
+ * Builds credential status
71
+ * @param {CredentialRequest} request
72
+ * @returns `CredentialStatus`
73
+ */
74
+ static buildCredentialStatus(request, issuer) {
75
+ const credentialStatus = {
76
+ id: request.revocationOpts.id,
77
+ type: request.revocationOpts.type,
78
+ revocationNonce: request.revocationOpts.nonce
79
+ };
80
+ switch (request.revocationOpts.type) {
81
+ case CredentialStatusType.SparseMerkleTreeProof:
82
+ return {
83
+ ...credentialStatus,
84
+ id: `${credentialStatus.id.replace(/\/$/, '')}/${credentialStatus.revocationNonce}`
85
+ };
86
+ case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof:
87
+ return {
88
+ ...credentialStatus,
89
+ id: request.revocationOpts.issuerState
90
+ ? `${credentialStatus.id.replace(/\/$/, '')}/node?state=${request.revocationOpts.issuerState}`
91
+ : `${credentialStatus.id.replace(/\/$/, '')}`
92
+ };
93
+ case CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023: {
94
+ const issuerId = DID.idFromDID(issuer);
95
+ const chainId = getChainId(DID.blockchainFromId(issuerId), DID.networkIdFromId(issuerId));
96
+ const searchParams = [
97
+ ['revocationNonce', request.revocationOpts.nonce?.toString() || ''],
98
+ ['contractAddress', `${chainId}:${request.revocationOpts.id}`],
99
+ ['state', request.revocationOpts.issuerState || '']
100
+ ]
101
+ .filter(([, value]) => Boolean(value))
102
+ .map(([key, value]) => `${key}=${value}`)
103
+ .join('&');
104
+ return {
105
+ ...credentialStatus,
106
+ // `[did]:[methodid]:[chain]:[network]:[id]/credentialStatus?(revocationNonce=value)&[contractAddress=[chainID]:[contractAddress]]&(state=issuerState)`
107
+ id: `${issuer.string()}/credentialStatus?${searchParams}`
108
+ };
109
+ }
110
+ default:
111
+ return credentialStatus;
112
+ }
113
+ }
28
114
  toJSON() {
29
115
  return {
30
116
  ...this,
@@ -160,12 +160,6 @@ export declare class CredentialWallet implements ICredentialWallet {
160
160
  * {@inheritDoc ICredentialWallet.createCredential}
161
161
  */
162
162
  createCredential: (issuer: DID, request: CredentialRequest, schema: JSONSchema) => W3CCredential;
163
- /**
164
- * Builds credential status
165
- * @param {CredentialRequest} request
166
- * @returns `CredentialStatus`
167
- */
168
- private buildCredentialStatus;
169
163
  /**
170
164
  * {@inheritDoc ICredentialWallet.findById}
171
165
  */
@@ -4,6 +4,7 @@ export * from './status/sparse-merkle-tree';
4
4
  export * from './status/resolver';
5
5
  export * from './status/agent-revocation';
6
6
  export * from './status/credential-status-publisher';
7
+ export * from './status/did-resolver-revocation';
7
8
  export * from './credential-wallet';
8
9
  export * from './rhs';
9
10
  export * from './utils';
@@ -15,6 +15,10 @@ export type PublishMode = 'sync' | 'async' | 'callback';
15
15
  * @interface CredentialRequest
16
16
  */
17
17
  export interface CredentialRequest {
18
+ /**
19
+ * Credential ID
20
+ */
21
+ id?: string;
18
22
  /**
19
23
  * JSON credential schema
20
24
  */
@@ -55,6 +59,10 @@ export interface CredentialRequest {
55
59
  * merklizedRootPosition (index / value / none)
56
60
  */
57
61
  merklizedRootPosition?: MerklizedRootPosition;
62
+ /**
63
+ * issuance Date
64
+ */
65
+ issuanceDate?: number;
58
66
  /**
59
67
  * Revocation options
60
68
  *
@@ -0,0 +1,7 @@
1
+ import { CredentialStatus, RevocationStatus } from '../../verifiable';
2
+ import { CredentialStatusResolveOptions, CredentialStatusResolver } from './resolver';
3
+ export declare class DidDocumentCredentialStatusResolver implements CredentialStatusResolver {
4
+ private readonly didResolverUrl;
5
+ constructor(didResolverUrl: string);
6
+ resolve(credentialStatus: CredentialStatus, opts?: CredentialStatusResolveOptions | undefined): Promise<RevocationStatus>;
7
+ }
@@ -1,3 +1,4 @@
1
+ import { AcceptProfile } from './types';
1
2
  /**
2
3
  * Constants for Iden3 protocol
3
4
  */
@@ -37,5 +38,20 @@ export declare const SUPPORTED_PUBLIC_KEY_TYPES: {
37
38
  ES256K: string[];
38
39
  'ES256K-R': string[];
39
40
  };
41
+ export declare enum ProtocolVersion {
42
+ V1 = "iden3comm/v1"
43
+ }
44
+ export declare enum AcceptAuthCircuits {
45
+ AuthV2 = "authV2",
46
+ AuthV3 = "authV3"
47
+ }
48
+ export declare enum AcceptJwzAlgorithms {
49
+ Groth16 = "groth16"
50
+ }
51
+ export declare enum AcceptJwsAlgorithms {
52
+ ES256K = "ES256K",
53
+ ES256KR = "ES256K-R"
54
+ }
55
+ export declare const defaultAcceptProfile: AcceptProfile;
40
56
  export declare const DEFAULT_PROOF_VERIFY_DELAY: number;
41
57
  export declare const DEFAULT_AUTH_VERIFY_DELAY: number;
@@ -1,32 +1,43 @@
1
1
  import { MediaType } from '../constants';
2
2
  import { IProofService } from '../../proof/proof-service';
3
- import { StateVerificationOpts, AuthorizationRequestMessage, AuthorizationResponseMessage, BasicMessage, IPackageManager, JWSPackerParams } from '../types';
3
+ import { StateVerificationOpts, AuthorizationRequestMessage, AuthorizationResponseMessage, BasicMessage, IPackageManager, JWSPackerParams, ZeroKnowledgeProofRequest } from '../types';
4
4
  import { DID } from '@iden3/js-iden3-core';
5
- import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
5
+ import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler } from './message-handler';
6
+ /**
7
+ * Options to pass to createAuthorizationRequest function
8
+ * @public
9
+ */
10
+ export type AuthorizationRequestCreateOptions = {
11
+ accept?: string[];
12
+ scope?: ZeroKnowledgeProofRequest[];
13
+ expires_time?: Date;
14
+ };
6
15
  /**
7
16
  * createAuthorizationRequest is a function to create protocol authorization request
8
17
  * @param {string} reason - reason to request proof
9
18
  * @param {string} sender - sender did
10
19
  * @param {string} callbackUrl - callback that user should use to send response
20
+ * @param {AuthorizationRequestCreateOptions} opts - authorization request options
11
21
  * @returns `Promise<AuthorizationRequestMessage>`
12
22
  */
13
- export declare function createAuthorizationRequest(reason: string, sender: string, callbackUrl: string): AuthorizationRequestMessage;
23
+ export declare function createAuthorizationRequest(reason: string, sender: string, callbackUrl: string, opts?: AuthorizationRequestCreateOptions): AuthorizationRequestMessage;
14
24
  /**
15
25
  * createAuthorizationRequestWithMessage is a function to create protocol authorization request with explicit message to sign
16
26
  * @param {string} reason - reason to request proof
17
27
  * @param {string} message - message to sign in the response
18
28
  * @param {string} sender - sender did
19
29
  * @param {string} callbackUrl - callback that user should use to send response
30
+ * @param {AuthorizationRequestCreateOptions} opts - authorization request options
20
31
  * @returns `Promise<AuthorizationRequestMessage>`
21
32
  */
22
- export declare function createAuthorizationRequestWithMessage(reason: string, message: string, sender: string, callbackUrl: string): AuthorizationRequestMessage;
33
+ export declare function createAuthorizationRequestWithMessage(reason: string, message: string, sender: string, callbackUrl: string, opts?: AuthorizationRequestCreateOptions): AuthorizationRequestMessage;
23
34
  /**
24
35
  *
25
36
  * Options to pass to auth response handler
26
37
  *
27
38
  * @public
28
39
  */
29
- export type AuthResponseHandlerOptions = StateVerificationOpts & {
40
+ export type AuthResponseHandlerOptions = StateVerificationOpts & BasicHandlerOptions & {
30
41
  acceptedProofGenerationDelay?: number;
31
42
  };
32
43
  /**
@@ -92,10 +103,10 @@ export type AuthMessageHandlerOptions = AuthReqOptions | AuthRespOptions;
92
103
  * @public
93
104
  * @interface AuthHandlerOptions
94
105
  */
95
- export interface AuthHandlerOptions {
106
+ export type AuthHandlerOptions = BasicHandlerOptions & {
96
107
  mediaType: MediaType;
97
108
  packerOptions?: JWSPackerParams;
98
- }
109
+ };
99
110
  /**
100
111
  *
101
112
  * Allows to process AuthorizationRequest protocol message and produce JWZ response.
@@ -139,5 +150,6 @@ export declare class AuthHandler extends AbstractMessageHandler implements IAuth
139
150
  response: AuthorizationResponseMessage;
140
151
  }>;
141
152
  private verifyAuthRequest;
153
+ private getSupportedMediaTypeByProfile;
142
154
  }
143
155
  export {};
@@ -1,4 +1,4 @@
1
- import { JWSPackerParams, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../types';
1
+ import { BasicMessage, JWSPackerParams, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../types';
2
2
  import { DID } from '@iden3/js-iden3-core';
3
3
  import { IProofService } from '../../proof';
4
4
  import { CircuitId } from '../../circuits';
@@ -21,3 +21,9 @@ export declare const processZeroKnowledgeProofRequests: (to: DID, requests: Zero
21
21
  ethSigner?: Signer;
22
22
  challenge?: bigint;
23
23
  }) => Promise<ZeroKnowledgeProofResponse[]>;
24
+ /**
25
+ * Verifies that the expires_time field of a message is not in the past. Throws an error if it is.
26
+ *
27
+ * @param message - Basic message to verify.
28
+ */
29
+ export declare const verifyExpiresTime: (message: BasicMessage) => void;
@@ -4,7 +4,7 @@ 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
+ import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler } from './message-handler';
8
8
  /**
9
9
  * Interface that allows the processing of the contract request
10
10
  *
@@ -30,7 +30,7 @@ export interface IContractRequestHandler {
30
30
  handleContractInvokeRequest(did: DID, request: Uint8Array, opts?: ContractInvokeHandlerOptions): Promise<Map<string, ZeroKnowledgeProofResponse>>;
31
31
  }
32
32
  /** ContractInvokeHandlerOptions represents contract invoke handler options */
33
- export type ContractInvokeHandlerOptions = {
33
+ export type ContractInvokeHandlerOptions = BasicHandlerOptions & {
34
34
  ethSigner: Signer;
35
35
  challenge?: bigint;
36
36
  };
@@ -2,7 +2,7 @@ import { BasicMessage, DIDDocument, IPackageManager, JsonDocumentObject, PackerP
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
+ import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler } from './message-handler';
6
6
  /** @beta ProposalRequestCreationOptions represents proposal-request creation options */
7
7
  export type ProposalRequestCreationOptions = {
8
8
  credentials: ProposalRequestCredential[];
@@ -11,6 +11,11 @@ export type ProposalRequestCreationOptions = {
11
11
  data?: JsonDocumentObject;
12
12
  };
13
13
  did_doc?: DIDDocument;
14
+ expires_time?: Date;
15
+ };
16
+ /** @beta ProposalCreationOptions represents proposal creation options */
17
+ export type ProposalCreationOptions = {
18
+ expires_time?: Date;
14
19
  };
15
20
  /**
16
21
  * @beta
@@ -29,7 +34,7 @@ export declare function createProposalRequest(sender: DID, receiver: DID, opts:
29
34
  * @param {Proposal[]} proposals - proposals
30
35
  * @returns `Promise<ProposalRequestMessage>`
31
36
  */
32
- export declare function createProposal(sender: DID, receiver: DID, proposals?: Proposal[]): ProposalMessage;
37
+ export declare function createProposal(sender: DID, receiver: DID, proposals?: Proposal[], opts?: ProposalCreationOptions): ProposalMessage;
33
38
  /**
34
39
  * @beta
35
40
  * Interface that allows the processing of the proposal-request
@@ -66,9 +71,9 @@ export interface ICredentialProposalHandler {
66
71
  }>;
67
72
  }
68
73
  /** @beta ProposalRequestHandlerOptions represents proposal-request handler options */
69
- export type ProposalRequestHandlerOptions = object;
74
+ export type ProposalRequestHandlerOptions = BasicHandlerOptions;
70
75
  /** @beta ProposalHandlerOptions represents proposal handler options */
71
- export type ProposalHandlerOptions = {
76
+ export type ProposalHandlerOptions = BasicHandlerOptions & {
72
77
  proposalRequest?: ProposalRequestMessage;
73
78
  };
74
79
  /** @beta CredentialProposalHandlerParams represents credential proposal handler params */