@0xpolygonid/js-sdk 1.7.1 → 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.
- package/dist/browser/esm/index.js +70 -6
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +70 -6
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +1 -0
- package/dist/node/cjs/iden3comm/handlers/fetch.js +68 -7
- package/dist/node/cjs/verifiable/credential.js +3 -0
- package/dist/node/esm/iden3comm/handlers/auth.js +1 -0
- package/dist/node/esm/iden3comm/handlers/fetch.js +68 -7
- package/dist/node/esm/verifiable/credential.js +3 -0
- package/dist/types/iden3comm/handlers/fetch.d.ts +33 -1
- package/package.json +1 -1
|
@@ -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}`);
|
|
@@ -63379,6 +63382,7 @@ class AuthHandler {
|
|
|
63379
63382
|
}
|
|
63380
63383
|
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
63381
63384
|
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
63385
|
+
verifierDid: DID.parse(authRequest.from),
|
|
63382
63386
|
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
63383
63387
|
credential: credWithRevStatus?.cred,
|
|
63384
63388
|
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
@@ -63414,8 +63418,9 @@ class FetchHandler {
|
|
|
63414
63418
|
* Creates an instance of FetchHandler.
|
|
63415
63419
|
* @param {IPackageManager} _packerMgr - package manager to unpack message envelope
|
|
63416
63420
|
*/
|
|
63417
|
-
constructor(_packerMgr) {
|
|
63421
|
+
constructor(_packerMgr, opts) {
|
|
63418
63422
|
this._packerMgr = _packerMgr;
|
|
63423
|
+
this.opts = opts;
|
|
63419
63424
|
}
|
|
63420
63425
|
/**
|
|
63421
63426
|
* Handles only messages with credentials/1.0/offer type
|
|
@@ -63435,11 +63440,7 @@ class FetchHandler {
|
|
|
63435
63440
|
if (opts.mediaType === MediaType.SignedMessage && !opts.packerOptions) {
|
|
63436
63441
|
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
63437
63442
|
}
|
|
63438
|
-
const
|
|
63439
|
-
const offerMessage = message;
|
|
63440
|
-
if (message.type !== PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE) {
|
|
63441
|
-
throw new Error('Invalid media type');
|
|
63442
|
-
}
|
|
63443
|
+
const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
|
|
63443
63444
|
const credentials = [];
|
|
63444
63445
|
for (let index = 0; index < offerMessage.body.credentials.length; index++) {
|
|
63445
63446
|
const credentialInfo = offerMessage.body.credentials[index];
|
|
@@ -63491,6 +63492,69 @@ class FetchHandler {
|
|
|
63491
63492
|
}
|
|
63492
63493
|
return credentials;
|
|
63493
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
|
+
}
|
|
63494
63558
|
}
|
|
63495
63559
|
|
|
63496
63560
|
/**
|