@0xpolygonid/js-sdk 1.13.0 → 1.14.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.
- package/dist/browser/esm/index.js +60 -24
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +59 -23
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/handlers/fetch.js +26 -12
- package/dist/node/cjs/iden3comm/handlers/payment.js +4 -4
- package/dist/node/cjs/proof/common.js +17 -4
- package/dist/node/cjs/verifiable/constants.js +13 -4
- package/dist/node/esm/iden3comm/handlers/fetch.js +26 -12
- package/dist/node/esm/iden3comm/handlers/payment.js +4 -4
- package/dist/node/esm/proof/common.js +17 -4
- package/dist/node/esm/verifiable/constants.js +12 -3
- package/dist/types/iden3comm/types/protocol/credentials.d.ts +3 -3
- package/dist/types/iden3comm/types/protocol/payment.d.ts +8 -7
- package/dist/types/verifiable/constants.d.ts +11 -3
- package/package.json +1 -1
|
@@ -7498,7 +7498,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
7498
7498
|
})(exports.RefreshServiceType || (exports.RefreshServiceType = {}));
|
|
7499
7499
|
/**
|
|
7500
7500
|
* PaymentRequestType type for payment requests
|
|
7501
|
-
*
|
|
7501
|
+
* @beta
|
|
7502
7502
|
* @enum {string}
|
|
7503
7503
|
*/
|
|
7504
7504
|
exports.PaymentRequestType = void 0;
|
|
@@ -7507,7 +7507,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
7507
7507
|
})(exports.PaymentRequestType || (exports.PaymentRequestType = {}));
|
|
7508
7508
|
/**
|
|
7509
7509
|
* PaymentRequestDataType type for payment requests
|
|
7510
|
-
*
|
|
7510
|
+
* @beta
|
|
7511
7511
|
* @enum {string}
|
|
7512
7512
|
*/
|
|
7513
7513
|
exports.PaymentRequestDataType = void 0;
|
|
@@ -7516,13 +7516,22 @@ var PolygonIdSdk = (function (exports) {
|
|
|
7516
7516
|
})(exports.PaymentRequestDataType || (exports.PaymentRequestDataType = {}));
|
|
7517
7517
|
/**
|
|
7518
7518
|
* PaymentType type for payment responses
|
|
7519
|
-
*
|
|
7519
|
+
* @beta
|
|
7520
7520
|
* @enum {string}
|
|
7521
7521
|
*/
|
|
7522
7522
|
exports.PaymentType = void 0;
|
|
7523
7523
|
(function (PaymentType) {
|
|
7524
7524
|
PaymentType["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
7525
7525
|
})(exports.PaymentType || (exports.PaymentType = {}));
|
|
7526
|
+
/**
|
|
7527
|
+
* Media types for Payment supported currencies
|
|
7528
|
+
* @beta
|
|
7529
|
+
* @enum {number}
|
|
7530
|
+
*/
|
|
7531
|
+
exports.SupportedCurrencies = void 0;
|
|
7532
|
+
(function (SupportedCurrencies) {
|
|
7533
|
+
SupportedCurrencies["ETH"] = "ETH";
|
|
7534
|
+
})(exports.SupportedCurrencies || (exports.SupportedCurrencies = {}));
|
|
7526
7535
|
|
|
7527
7536
|
/**
|
|
7528
7537
|
* Iden3SparseMerkleProof is a iden3 protocol merkle tree proof
|
|
@@ -54310,10 +54319,23 @@ var PolygonIdSdk = (function (exports) {
|
|
|
54310
54319
|
if (!isValidOperation(query.datatype, propertyQuery.operator)) {
|
|
54311
54320
|
throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
|
|
54312
54321
|
}
|
|
54313
|
-
|
|
54314
|
-
propertyQuery.
|
|
54315
|
-
|
|
54316
|
-
|
|
54322
|
+
if ((propertyQuery.operator === exports.Operators.NOOP || propertyQuery.operator === exports.Operators.SD) &&
|
|
54323
|
+
propertyQuery.operatorValue) {
|
|
54324
|
+
throw new Error(`operator value should be undefined for ${propertyQuery.operator} operator`);
|
|
54325
|
+
}
|
|
54326
|
+
let values;
|
|
54327
|
+
switch (propertyQuery.operator) {
|
|
54328
|
+
case exports.Operators.NOOP:
|
|
54329
|
+
case exports.Operators.SD:
|
|
54330
|
+
values = [];
|
|
54331
|
+
break;
|
|
54332
|
+
case exports.Operators.EXISTS:
|
|
54333
|
+
values = transformExistsValue(propertyQuery.operatorValue);
|
|
54334
|
+
break;
|
|
54335
|
+
default:
|
|
54336
|
+
values = await transformQueryValueToBigInts(propertyQuery.operatorValue, query.datatype);
|
|
54337
|
+
}
|
|
54338
|
+
query.values = values;
|
|
54317
54339
|
}
|
|
54318
54340
|
return query;
|
|
54319
54341
|
};
|
|
@@ -78455,9 +78477,17 @@ var PolygonIdSdk = (function (exports) {
|
|
|
78455
78477
|
}
|
|
78456
78478
|
async handle(message, ctx) {
|
|
78457
78479
|
switch (message.type) {
|
|
78458
|
-
case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE:
|
|
78459
|
-
await this.handleOfferMessage(message, ctx);
|
|
78460
|
-
|
|
78480
|
+
case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE: {
|
|
78481
|
+
const result = await this.handleOfferMessage(message, ctx);
|
|
78482
|
+
if (Array.isArray(result)) {
|
|
78483
|
+
const credWallet = this.opts?.credentialWallet;
|
|
78484
|
+
if (!credWallet)
|
|
78485
|
+
throw new Error('Credential wallet is not provided');
|
|
78486
|
+
await credWallet.saveAll(result);
|
|
78487
|
+
return null;
|
|
78488
|
+
}
|
|
78489
|
+
return result;
|
|
78490
|
+
}
|
|
78461
78491
|
case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE:
|
|
78462
78492
|
return this.handleFetchRequest(message);
|
|
78463
78493
|
case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:
|
|
@@ -78471,8 +78501,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
78471
78501
|
ctx.mediaType = MediaType.ZKPMessage;
|
|
78472
78502
|
}
|
|
78473
78503
|
const credentials = [];
|
|
78474
|
-
for (
|
|
78475
|
-
const credentialInfo = offerMessage.body.credentials[index];
|
|
78504
|
+
for (const credentialInfo of offerMessage.body.credentials) {
|
|
78476
78505
|
const guid = v4();
|
|
78477
78506
|
const fetchRequest = {
|
|
78478
78507
|
id: guid,
|
|
@@ -78496,7 +78525,6 @@ var PolygonIdSdk = (function (exports) {
|
|
|
78496
78525
|
senderDID,
|
|
78497
78526
|
...packerOpts
|
|
78498
78527
|
}));
|
|
78499
|
-
let message;
|
|
78500
78528
|
try {
|
|
78501
78529
|
if (!offerMessage?.body?.url) {
|
|
78502
78530
|
throw new Error(`could not fetch W3C credential, body url is missing`);
|
|
@@ -78509,14 +78537,18 @@ var PolygonIdSdk = (function (exports) {
|
|
|
78509
78537
|
},
|
|
78510
78538
|
body: token
|
|
78511
78539
|
});
|
|
78512
|
-
|
|
78513
|
-
|
|
78540
|
+
const arrayBuffer = await resp.arrayBuffer();
|
|
78541
|
+
if (!arrayBuffer.byteLength) {
|
|
78542
|
+
throw new Error(`could not fetch , ${credentialInfo?.id}, response is empty`);
|
|
78543
|
+
}
|
|
78544
|
+
const { unpackedMessage: message } = await this._packerMgr.unpack(new Uint8Array(arrayBuffer));
|
|
78545
|
+
if (message.type !== PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE) {
|
|
78546
|
+
return message;
|
|
78514
78547
|
}
|
|
78515
|
-
message = await resp.json();
|
|
78516
78548
|
credentials.push(W3CCredential.fromJSON(message.body.credential));
|
|
78517
78549
|
}
|
|
78518
78550
|
catch (e) {
|
|
78519
|
-
throw new Error(`could not fetch
|
|
78551
|
+
throw new Error(`could not fetch protocol message for credential offer id: , ${credentialInfo?.id}, error: ${e.message ?? e}`);
|
|
78520
78552
|
}
|
|
78521
78553
|
}
|
|
78522
78554
|
return credentials;
|
|
@@ -78535,11 +78567,15 @@ var PolygonIdSdk = (function (exports) {
|
|
|
78535
78567
|
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
78536
78568
|
}
|
|
78537
78569
|
const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
|
|
78538
|
-
|
|
78570
|
+
const result = await this.handleOfferMessage(offerMessage, {
|
|
78539
78571
|
mediaType: opts?.mediaType,
|
|
78540
78572
|
headers: opts?.headers,
|
|
78541
78573
|
packerOptions: opts?.packerOptions
|
|
78542
78574
|
});
|
|
78575
|
+
if (Array.isArray(result)) {
|
|
78576
|
+
return result;
|
|
78577
|
+
}
|
|
78578
|
+
throw new Error('invalid protocol message response');
|
|
78543
78579
|
}
|
|
78544
78580
|
async handleFetchRequest(msgRequest) {
|
|
78545
78581
|
if (!msgRequest.to) {
|
|
@@ -78552,7 +78588,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
78552
78588
|
const userDID = Z$2.parse(msgRequest.from);
|
|
78553
78589
|
const credId = msgRequest.body?.id;
|
|
78554
78590
|
if (!credId) {
|
|
78555
|
-
throw new Error('
|
|
78591
|
+
throw new Error('invalid credential id in fetch request body');
|
|
78556
78592
|
}
|
|
78557
78593
|
if (!this.opts?.credentialWallet) {
|
|
78558
78594
|
throw new Error('please, provide credential wallet in options');
|
|
@@ -79173,7 +79209,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
79173
79209
|
if (!paymentRequest.from) {
|
|
79174
79210
|
throw new Error(`failed request. empty 'from' field`);
|
|
79175
79211
|
}
|
|
79176
|
-
if (!paymentRequest.body
|
|
79212
|
+
if (!paymentRequest.body.payments?.length) {
|
|
79177
79213
|
throw new Error(`failed request. no 'payments' in body`);
|
|
79178
79214
|
}
|
|
79179
79215
|
if (!ctx.paymentHandler) {
|
|
@@ -79244,12 +79280,12 @@ var PolygonIdSdk = (function (exports) {
|
|
|
79244
79280
|
if (opts.paymentRequest.from !== payment.to) {
|
|
79245
79281
|
throw new Error(`sender of the request is not a target of response - expected ${opts.paymentRequest.from}, given ${payment.to}`);
|
|
79246
79282
|
}
|
|
79247
|
-
if (!payment.body
|
|
79283
|
+
if (!payment.body.payments.length) {
|
|
79248
79284
|
throw new Error(`failed request. empty 'payments' field in body`);
|
|
79249
79285
|
}
|
|
79250
79286
|
for (let i = 0; i < payment.body.payments.length; i++) {
|
|
79251
|
-
const p = payment.body
|
|
79252
|
-
const paymentRequestData = opts.paymentRequest.body
|
|
79287
|
+
const p = payment.body.payments[i];
|
|
79288
|
+
const paymentRequestData = opts.paymentRequest.body.payments.find((r) => r.data.id === p.id);
|
|
79253
79289
|
if (!paymentRequestData) {
|
|
79254
79290
|
throw new Error(`can't find payment request for payment id ${p.id}`);
|
|
79255
79291
|
}
|