@0xpolygonid/js-sdk 1.7.0 → 1.7.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 (31) hide show
  1. package/dist/browser/esm/index.js +102 -6
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +103 -7
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/comparer.js +20 -2
  6. package/dist/node/cjs/circuits/linked-multi-query.js +1 -1
  7. package/dist/node/cjs/credentials/credential-wallet.js +1 -0
  8. package/dist/node/cjs/iden3comm/constants.js +2 -0
  9. package/dist/node/cjs/iden3comm/handlers/fetch.js +2 -2
  10. package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
  11. package/dist/node/cjs/iden3comm/handlers/refresh.js +76 -0
  12. package/dist/node/cjs/verifiable/constants.js +10 -1
  13. package/dist/node/esm/circuits/comparer.js +20 -2
  14. package/dist/node/esm/circuits/linked-multi-query.js +1 -1
  15. package/dist/node/esm/credentials/credential-wallet.js +1 -0
  16. package/dist/node/esm/iden3comm/constants.js +2 -0
  17. package/dist/node/esm/iden3comm/handlers/fetch.js +2 -2
  18. package/dist/node/esm/iden3comm/handlers/index.js +1 -0
  19. package/dist/node/esm/iden3comm/handlers/refresh.js +72 -0
  20. package/dist/node/esm/verifiable/constants.js +9 -0
  21. package/dist/types/credentials/credential-wallet.d.ts +5 -1
  22. package/dist/types/iden3comm/constants.d.ts +1 -0
  23. package/dist/types/iden3comm/handlers/fetch.d.ts +2 -2
  24. package/dist/types/iden3comm/handlers/index.d.ts +1 -0
  25. package/dist/types/iden3comm/handlers/refresh.d.ts +56 -0
  26. package/dist/types/iden3comm/types/packer.d.ts +2 -1
  27. package/dist/types/iden3comm/types/protocol/credentials.d.ts +15 -0
  28. package/dist/types/verifiable/constants.d.ts +8 -0
  29. package/dist/types/verifiable/credential.d.ts +2 -1
  30. package/dist/types/verifiable/proof.d.ts +10 -1
  31. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- var PolygonIdSdk = (function (exports) {
1
+ var PolygonIdSdk = (function (exports, crypto$4) {
2
2
  'use strict';
3
3
 
4
4
  /**
@@ -32203,6 +32203,15 @@ var PolygonIdSdk = (function (exports) {
32203
32203
  // Value save subject in value part of claim.
32204
32204
  SubjectPosition["Value"] = "value";
32205
32205
  })(exports.SubjectPosition || (exports.SubjectPosition = {}));
32206
+ /**
32207
+ * RefreshServiceType type for refreshService
32208
+ *
32209
+ * @enum {string}
32210
+ */
32211
+ exports.RefreshServiceType = void 0;
32212
+ (function (RefreshServiceType) {
32213
+ RefreshServiceType["Iden3RefreshService2023"] = "Iden3RefreshService2023";
32214
+ })(exports.RefreshServiceType || (exports.RefreshServiceType = {}));
32206
32215
 
32207
32216
  /**
32208
32217
  * Checks if state is genesis state
@@ -32456,8 +32465,26 @@ var PolygonIdSdk = (function (exports) {
32456
32465
  [exports.XSDNS.Integer, allOperations],
32457
32466
  [exports.XSDNS.NonNegativeInteger, allOperations],
32458
32467
  [exports.XSDNS.PositiveInteger, allOperations],
32459
- [exports.XSDNS.Double, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$in, QueryOperators.$nin, QueryOperators.$sd]],
32460
- [exports.XSDNS.String, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$in, QueryOperators.$nin, QueryOperators.$sd]],
32468
+ [
32469
+ exports.XSDNS.Double,
32470
+ [
32471
+ QueryOperators.$eq,
32472
+ QueryOperators.$ne,
32473
+ QueryOperators.$in,
32474
+ QueryOperators.$nin,
32475
+ QueryOperators.$sd
32476
+ ]
32477
+ ],
32478
+ [
32479
+ exports.XSDNS.String,
32480
+ [
32481
+ QueryOperators.$eq,
32482
+ QueryOperators.$ne,
32483
+ QueryOperators.$in,
32484
+ QueryOperators.$nin,
32485
+ QueryOperators.$sd
32486
+ ]
32487
+ ],
32461
32488
  [exports.XSDNS.DateTime, allOperations]
32462
32489
  ]);
32463
32490
  /**
@@ -35130,7 +35157,7 @@ var PolygonIdSdk = (function (exports) {
35130
35157
  if (!this.query[i]) {
35131
35158
  enabled.push(0);
35132
35159
  claimPathNotExists.push(0);
35133
- claimPathMtp.push([]);
35160
+ claimPathMtp.push(new Array(this.getMTLevelsClaim()).fill('0'));
35134
35161
  claimPathMtpNoAux.push('0');
35135
35162
  claimPathMtpAuxHi.push('0');
35136
35163
  claimPathMtpAuxHv.push('0');
@@ -36876,6 +36903,8 @@ var PolygonIdSdk = (function (exports) {
36876
36903
  CREDENTIAL_OFFER_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/offer',
36877
36904
  // CredentialIssuanceResponseMessageType is type for message with a credential issuance
36878
36905
  CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/issuance-response',
36906
+ // CredentialRefreshMessageType is type for message with a credential issuance
36907
+ CREDENTIAL_REFRESH_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/refresh',
36879
36908
  // DeviceRegistrationRequestMessageType defines device registration request type of the communication protocol
36880
36909
  DEVICE_REGISTRATION_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'devices/1.0/registration',
36881
36910
  // MessageFetMessageFetchRequestMessageType defines message fetch request type of the communication protocol.
@@ -37371,6 +37400,7 @@ var PolygonIdSdk = (function (exports) {
37371
37400
  cr['@context'] = context;
37372
37401
  cr.type = credentialType;
37373
37402
  cr.expirationDate = expirationDate ? new Date(expirationDate * 1000).toISOString() : undefined;
37403
+ cr.refreshService = request.refreshService;
37374
37404
  cr.issuanceDate = new Date().toISOString();
37375
37405
  cr.credentialSubject = credentialSubject;
37376
37406
  cr.issuer = issuer.string();
@@ -84281,7 +84311,7 @@ var PolygonIdSdk = (function (exports) {
84281
84311
  */
84282
84312
  class FetchHandler {
84283
84313
  /**
84284
- * Creates an instance of AuthHandler.
84314
+ * Creates an instance of FetchHandler.
84285
84315
  * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
84286
84316
  */
84287
84317
  constructor(_packerMgr) {
@@ -84294,7 +84324,7 @@ var PolygonIdSdk = (function (exports) {
84294
84324
  * offer: Uint8Array; offer - raw offer message
84295
84325
  * opts
84296
84326
  * }) options how to fetch credential
84297
- * @returns `Promise<W3CCredential>`
84327
+ * @returns `Promise<W3CCredential[]>`
84298
84328
  */
84299
84329
  async handleCredentialOffer(offer, opts) {
84300
84330
  if (!opts) {
@@ -84450,6 +84480,71 @@ var PolygonIdSdk = (function (exports) {
84450
84480
  }
84451
84481
  }
84452
84482
 
84483
+ /**
84484
+ *
84485
+ * Allows to refresh credential from refresh service and return refreshed credential
84486
+ *
84487
+ * @public
84488
+
84489
+ * @class RefreshHandler
84490
+ * @implements implements RefreshHandler interface
84491
+ */
84492
+ class RefreshHandler {
84493
+ /**
84494
+ * Creates an instance of RefreshHandler.
84495
+ * @param {RefreshHandlerOptions} _options - refresh handler options
84496
+ */
84497
+ constructor(_options) {
84498
+ this._options = _options;
84499
+ }
84500
+ async refreshCredential(credential, opts) {
84501
+ if (!credential.refreshService) {
84502
+ throw new Error('refreshService not specified for W3CCredential');
84503
+ }
84504
+ if (credential.refreshService.type !== exports.RefreshServiceType.Iden3RefreshService2023) {
84505
+ throw new Error(`refresh service type ${credential.refreshService.type} is not supported`);
84506
+ }
84507
+ const otherIdentifier = credential.credentialSubject.id;
84508
+ if (!otherIdentifier) {
84509
+ throw new Error('self credentials do not support refresh');
84510
+ }
84511
+ const senderDID = W$2.parse(otherIdentifier);
84512
+ const zkpParams = {
84513
+ senderDID,
84514
+ provingMethodAlg: new l(T.provingMethodGroth16AuthV2Instance.methodAlg.alg, exports.CircuitId.AuthV2)
84515
+ };
84516
+ const refreshMsg = {
84517
+ id: crypto$4.randomUUID(),
84518
+ typ: MediaType.ZKPMessage,
84519
+ type: PROTOCOL_MESSAGE_TYPE.CREDENTIAL_REFRESH_MESSAGE_TYPE,
84520
+ thid: crypto$4.randomUUID(),
84521
+ body: {
84522
+ id: otherIdentifier,
84523
+ reason: opts?.reason ?? 'credential is expired'
84524
+ },
84525
+ from: otherIdentifier,
84526
+ to: credential.issuer
84527
+ };
84528
+ const msgBytes = byteEncoder.encode(JSON.stringify(refreshMsg));
84529
+ const jwzToken = await this._options.packageManager.pack(MediaType.ZKPMessage, msgBytes, zkpParams);
84530
+ const resp = await fetch(credential.refreshService.id, {
84531
+ method: 'post',
84532
+ headers: {
84533
+ 'Content-Type': 'application/json'
84534
+ },
84535
+ body: jwzToken
84536
+ });
84537
+ if (resp.status !== 200) {
84538
+ throw new Error(`could not refresh W3C credential, return status ${resp.status}`);
84539
+ }
84540
+ const respBody = await resp.json();
84541
+ if (!respBody.body?.credential) {
84542
+ throw new Error('no credential in CredentialIssuanceMessage response');
84543
+ }
84544
+ return W3CCredential.fromJSON(respBody.body.credential);
84545
+ }
84546
+ }
84547
+
84453
84548
  exports.AbstractPrivateKeyStore = AbstractPrivateKeyStore;
84454
84549
  exports.AgentResolver = AgentResolver;
84455
84550
  exports.AtomicQueryMTPV2Inputs = AtomicQueryMTPV2Inputs;
@@ -84530,6 +84625,7 @@ var PolygonIdSdk = (function (exports) {
84530
84625
  exports.Query = Query;
84531
84626
  exports.QueryOperators = QueryOperators;
84532
84627
  exports.RHSResolver = RHSResolver;
84628
+ exports.RefreshHandler = RefreshHandler;
84533
84629
  exports.Scalar = Scalar$1;
84534
84630
  exports.Sec256k1Provider = Sec256k1Provider;
84535
84631
  exports.StandardJSONCredentialsQueryFilter = StandardJSONCredentialsQueryFilter;
@@ -84614,5 +84710,5 @@ var PolygonIdSdk = (function (exports) {
84614
84710
 
84615
84711
  return exports;
84616
84712
 
84617
- })({});
84713
+ })({}, crypto$4);
84618
84714
  //# sourceMappingURL=index.js.map