@0xpolygonid/js-sdk 1.7.2 → 1.7.3

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.
@@ -33567,6 +33567,9 @@ class W3CCredential {
33567
33567
  throw new Error('signature proof: invalid tree state of the issuer while checking credential status of singing key');
33568
33568
  }
33569
33569
  const revocationNonce = BigInt(proof.issuerData.credentialStatus.revocationNonce || 0);
33570
+ if (revocationNonce !== proof.issuerData.authCoreClaim.getRevocationNonce()) {
33571
+ throw new Error(`revocation nonce mismatch: revocation nonce from core representation of auth credential is not the same as in its credential`);
33572
+ }
33570
33573
  const proofValid = await verifyProof(Hash$1.fromHex(credStatus.issuer.revocationTreeRoot), credStatus.mtp, revocationNonce, BigInt(0));
33571
33574
  if (!proofValid) {
33572
33575
  throw new Error(`proof validation failed. revNonce=${revocationNonce}`);
@@ -63415,8 +63418,9 @@ class FetchHandler {
63415
63418
  * Creates an instance of FetchHandler.
63416
63419
  * @param {IPackageManager} _packerMgr - package manager to unpack message envelope
63417
63420
  */
63418
- constructor(_packerMgr) {
63421
+ constructor(_packerMgr, opts) {
63419
63422
  this._packerMgr = _packerMgr;
63423
+ this.opts = opts;
63420
63424
  }
63421
63425
  /**
63422
63426
  * Handles only messages with credentials/1.0/offer type
@@ -63436,11 +63440,7 @@ class FetchHandler {
63436
63440
  if (opts.mediaType === MediaType.SignedMessage && !opts.packerOptions) {
63437
63441
  throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
63438
63442
  }
63439
- const { unpackedMessage: message } = await this._packerMgr.unpack(offer);
63440
- const offerMessage = message;
63441
- if (message.type !== PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE) {
63442
- throw new Error('Invalid media type');
63443
- }
63443
+ const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
63444
63444
  const credentials = [];
63445
63445
  for (let index = 0; index < offerMessage.body.credentials.length; index++) {
63446
63446
  const credentialInfo = offerMessage.body.credentials[index];
@@ -63492,6 +63492,69 @@ class FetchHandler {
63492
63492
  }
63493
63493
  return credentials;
63494
63494
  }
63495
+ /**
63496
+ * @inheritdoc IFetchHandler#handleCredentialFetchRequest
63497
+ */
63498
+ async handleCredentialFetchRequest(envelope) {
63499
+ const msgRequest = await FetchHandler.unpackMessage(this._packerMgr, envelope, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE);
63500
+ if (!msgRequest.to) {
63501
+ throw new Error("failed request. empty 'to' field");
63502
+ }
63503
+ if (!msgRequest.from) {
63504
+ throw new Error("failed request. empty 'from' field");
63505
+ }
63506
+ const issuerDID = DID.parse(msgRequest.to);
63507
+ const userDID = DID.parse(msgRequest.from);
63508
+ const credId = msgRequest.body?.id;
63509
+ if (!credId) {
63510
+ throw new Error('nvalid credential id in fetch request body');
63511
+ }
63512
+ if (!this.opts?.credentialWallet) {
63513
+ throw new Error('please, provide credential wallet in options');
63514
+ }
63515
+ const cred = await this.opts.credentialWallet.findById(credId);
63516
+ if (!cred) {
63517
+ throw new Error('credential not found');
63518
+ }
63519
+ const userToVerifyDID = getUserDIDFromCredential(issuerDID, cred);
63520
+ if (userToVerifyDID.string() !== userDID.string()) {
63521
+ throw new Error('credential subject is not a sender DID');
63522
+ }
63523
+ return this._packerMgr.pack(MediaType.PlainMessage, byteEncoder.encode(JSON.stringify({
63524
+ id: v4(),
63525
+ type: PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE,
63526
+ typ: msgRequest.typ ?? MediaType.PlainMessage,
63527
+ thid: msgRequest.thid ?? v4(),
63528
+ body: { credential: cred },
63529
+ from: msgRequest.to,
63530
+ to: msgRequest.from
63531
+ })), {});
63532
+ }
63533
+ /**
63534
+ * @inheritdoc IFetchHandler#handleIssuanceResponseMessage
63535
+ */
63536
+ async handleIssuanceResponseMessage(envelop) {
63537
+ const issuanceMsg = await FetchHandler.unpackMessage(this._packerMgr, envelop, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE);
63538
+ if (!this.opts?.credentialWallet) {
63539
+ throw new Error('please provide credential wallet in options');
63540
+ }
63541
+ if (!issuanceMsg.body?.credential) {
63542
+ throw new Error('credential is missing in issuance response message');
63543
+ }
63544
+ await this.opts.credentialWallet.save(W3CCredential.fromJSON(issuanceMsg.body.credential));
63545
+ return Promise.resolve(Uint8Array.from([]));
63546
+ }
63547
+ /**
63548
+ * @inheritdoc IFetchHandler#unpackMessage
63549
+ */
63550
+ static async unpackMessage(packerMgr, envelope, messageType) {
63551
+ const { unpackedMessage: message } = await packerMgr.unpack(envelope);
63552
+ const msgRequest = message;
63553
+ if (message.type !== messageType) {
63554
+ throw new Error('Invalid message type');
63555
+ }
63556
+ return msgRequest;
63557
+ }
63495
63558
  }
63496
63559
 
63497
63560
  /**