@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
|
@@ -33705,6 +33705,9 @@ var PolygonIdSdk = (function (exports, crypto$4) {
|
|
|
33705
33705
|
throw new Error('signature proof: invalid tree state of the issuer while checking credential status of singing key');
|
|
33706
33706
|
}
|
|
33707
33707
|
const revocationNonce = BigInt(proof.issuerData.credentialStatus.revocationNonce || 0);
|
|
33708
|
+
if (revocationNonce !== proof.issuerData.authCoreClaim.getRevocationNonce()) {
|
|
33709
|
+
throw new Error(`revocation nonce mismatch: revocation nonce from core representation of auth credential is not the same as in its credential`);
|
|
33710
|
+
}
|
|
33708
33711
|
const proofValid = await Mt$1(V$1.fromHex(credStatus.issuer.revocationTreeRoot), credStatus.mtp, revocationNonce, BigInt(0));
|
|
33709
33712
|
if (!proofValid) {
|
|
33710
33713
|
throw new Error(`proof validation failed. revNonce=${revocationNonce}`);
|
|
@@ -84279,6 +84282,7 @@ var PolygonIdSdk = (function (exports, crypto$4) {
|
|
|
84279
84282
|
}
|
|
84280
84283
|
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
84281
84284
|
const zkpRes = await this._proofService.generateProof(proofReq, did, {
|
|
84285
|
+
verifierDid: W$2.parse(authRequest.from),
|
|
84282
84286
|
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
84283
84287
|
credential: credWithRevStatus?.cred,
|
|
84284
84288
|
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
@@ -84314,8 +84318,9 @@ var PolygonIdSdk = (function (exports, crypto$4) {
|
|
|
84314
84318
|
* Creates an instance of FetchHandler.
|
|
84315
84319
|
* @param {IPackageManager} _packerMgr - package manager to unpack message envelope
|
|
84316
84320
|
*/
|
|
84317
|
-
constructor(_packerMgr) {
|
|
84321
|
+
constructor(_packerMgr, opts) {
|
|
84318
84322
|
this._packerMgr = _packerMgr;
|
|
84323
|
+
this.opts = opts;
|
|
84319
84324
|
}
|
|
84320
84325
|
/**
|
|
84321
84326
|
* Handles only messages with credentials/1.0/offer type
|
|
@@ -84335,11 +84340,7 @@ var PolygonIdSdk = (function (exports, crypto$4) {
|
|
|
84335
84340
|
if (opts.mediaType === MediaType.SignedMessage && !opts.packerOptions) {
|
|
84336
84341
|
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
84337
84342
|
}
|
|
84338
|
-
const
|
|
84339
|
-
const offerMessage = message;
|
|
84340
|
-
if (message.type !== PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE) {
|
|
84341
|
-
throw new Error('Invalid media type');
|
|
84342
|
-
}
|
|
84343
|
+
const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
|
|
84343
84344
|
const credentials = [];
|
|
84344
84345
|
for (let index = 0; index < offerMessage.body.credentials.length; index++) {
|
|
84345
84346
|
const credentialInfo = offerMessage.body.credentials[index];
|
|
@@ -84391,6 +84392,69 @@ var PolygonIdSdk = (function (exports, crypto$4) {
|
|
|
84391
84392
|
}
|
|
84392
84393
|
return credentials;
|
|
84393
84394
|
}
|
|
84395
|
+
/**
|
|
84396
|
+
* @inheritdoc IFetchHandler#handleCredentialFetchRequest
|
|
84397
|
+
*/
|
|
84398
|
+
async handleCredentialFetchRequest(envelope) {
|
|
84399
|
+
const msgRequest = await FetchHandler.unpackMessage(this._packerMgr, envelope, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE);
|
|
84400
|
+
if (!msgRequest.to) {
|
|
84401
|
+
throw new Error("failed request. empty 'to' field");
|
|
84402
|
+
}
|
|
84403
|
+
if (!msgRequest.from) {
|
|
84404
|
+
throw new Error("failed request. empty 'from' field");
|
|
84405
|
+
}
|
|
84406
|
+
const issuerDID = W$2.parse(msgRequest.to);
|
|
84407
|
+
const userDID = W$2.parse(msgRequest.from);
|
|
84408
|
+
const credId = msgRequest.body?.id;
|
|
84409
|
+
if (!credId) {
|
|
84410
|
+
throw new Error('nvalid credential id in fetch request body');
|
|
84411
|
+
}
|
|
84412
|
+
if (!this.opts?.credentialWallet) {
|
|
84413
|
+
throw new Error('please, provide credential wallet in options');
|
|
84414
|
+
}
|
|
84415
|
+
const cred = await this.opts.credentialWallet.findById(credId);
|
|
84416
|
+
if (!cred) {
|
|
84417
|
+
throw new Error('credential not found');
|
|
84418
|
+
}
|
|
84419
|
+
const userToVerifyDID = getUserDIDFromCredential(issuerDID, cred);
|
|
84420
|
+
if (userToVerifyDID.string() !== userDID.string()) {
|
|
84421
|
+
throw new Error('credential subject is not a sender DID');
|
|
84422
|
+
}
|
|
84423
|
+
return this._packerMgr.pack(MediaType.PlainMessage, byteEncoder.encode(JSON.stringify({
|
|
84424
|
+
id: v4(),
|
|
84425
|
+
type: PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE,
|
|
84426
|
+
typ: msgRequest.typ ?? MediaType.PlainMessage,
|
|
84427
|
+
thid: msgRequest.thid ?? v4(),
|
|
84428
|
+
body: { credential: cred },
|
|
84429
|
+
from: msgRequest.to,
|
|
84430
|
+
to: msgRequest.from
|
|
84431
|
+
})), {});
|
|
84432
|
+
}
|
|
84433
|
+
/**
|
|
84434
|
+
* @inheritdoc IFetchHandler#handleIssuanceResponseMessage
|
|
84435
|
+
*/
|
|
84436
|
+
async handleIssuanceResponseMessage(envelop) {
|
|
84437
|
+
const issuanceMsg = await FetchHandler.unpackMessage(this._packerMgr, envelop, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE);
|
|
84438
|
+
if (!this.opts?.credentialWallet) {
|
|
84439
|
+
throw new Error('please provide credential wallet in options');
|
|
84440
|
+
}
|
|
84441
|
+
if (!issuanceMsg.body?.credential) {
|
|
84442
|
+
throw new Error('credential is missing in issuance response message');
|
|
84443
|
+
}
|
|
84444
|
+
await this.opts.credentialWallet.save(W3CCredential.fromJSON(issuanceMsg.body.credential));
|
|
84445
|
+
return Promise.resolve(Uint8Array.from([]));
|
|
84446
|
+
}
|
|
84447
|
+
/**
|
|
84448
|
+
* @inheritdoc IFetchHandler#unpackMessage
|
|
84449
|
+
*/
|
|
84450
|
+
static async unpackMessage(packerMgr, envelope, messageType) {
|
|
84451
|
+
const { unpackedMessage: message } = await packerMgr.unpack(envelope);
|
|
84452
|
+
const msgRequest = message;
|
|
84453
|
+
if (message.type !== messageType) {
|
|
84454
|
+
throw new Error('Invalid message type');
|
|
84455
|
+
}
|
|
84456
|
+
return msgRequest;
|
|
84457
|
+
}
|
|
84394
84458
|
}
|
|
84395
84459
|
|
|
84396
84460
|
/**
|