@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.
@@ -7445,7 +7445,7 @@ var RefreshServiceType;
7445
7445
  })(RefreshServiceType || (RefreshServiceType = {}));
7446
7446
  /**
7447
7447
  * PaymentRequestType type for payment requests
7448
- *
7448
+ * @beta
7449
7449
  * @enum {string}
7450
7450
  */
7451
7451
  var PaymentRequestType;
@@ -7454,7 +7454,7 @@ var PaymentRequestType;
7454
7454
  })(PaymentRequestType || (PaymentRequestType = {}));
7455
7455
  /**
7456
7456
  * PaymentRequestDataType type for payment requests
7457
- *
7457
+ * @beta
7458
7458
  * @enum {string}
7459
7459
  */
7460
7460
  var PaymentRequestDataType;
@@ -7463,13 +7463,22 @@ var PaymentRequestDataType;
7463
7463
  })(PaymentRequestDataType || (PaymentRequestDataType = {}));
7464
7464
  /**
7465
7465
  * PaymentType type for payment responses
7466
- *
7466
+ * @beta
7467
7467
  * @enum {string}
7468
7468
  */
7469
7469
  var PaymentType;
7470
7470
  (function (PaymentType) {
7471
7471
  PaymentType["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
7472
7472
  })(PaymentType || (PaymentType = {}));
7473
+ /**
7474
+ * Media types for Payment supported currencies
7475
+ * @beta
7476
+ * @enum {number}
7477
+ */
7478
+ var SupportedCurrencies;
7479
+ (function (SupportedCurrencies) {
7480
+ SupportedCurrencies["ETH"] = "ETH";
7481
+ })(SupportedCurrencies || (SupportedCurrencies = {}));
7473
7482
 
7474
7483
  /**
7475
7484
  * Iden3SparseMerkleProof is a iden3 protocol merkle tree proof
@@ -54171,10 +54180,23 @@ const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType,
54171
54180
  if (!isValidOperation(query.datatype, propertyQuery.operator)) {
54172
54181
  throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
54173
54182
  }
54174
- query.values =
54175
- propertyQuery.operator === Operators.EXISTS
54176
- ? transformExistsValue(propertyQuery.operatorValue)
54177
- : await transformQueryValueToBigInts(propertyQuery.operatorValue, query.datatype);
54183
+ if ((propertyQuery.operator === Operators.NOOP || propertyQuery.operator === Operators.SD) &&
54184
+ propertyQuery.operatorValue) {
54185
+ throw new Error(`operator value should be undefined for ${propertyQuery.operator} operator`);
54186
+ }
54187
+ let values;
54188
+ switch (propertyQuery.operator) {
54189
+ case Operators.NOOP:
54190
+ case Operators.SD:
54191
+ values = [];
54192
+ break;
54193
+ case Operators.EXISTS:
54194
+ values = transformExistsValue(propertyQuery.operatorValue);
54195
+ break;
54196
+ default:
54197
+ values = await transformQueryValueToBigInts(propertyQuery.operatorValue, query.datatype);
54198
+ }
54199
+ query.values = values;
54178
54200
  }
54179
54201
  return query;
54180
54202
  };
@@ -57547,9 +57569,17 @@ class FetchHandler extends AbstractMessageHandler {
57547
57569
  }
57548
57570
  async handle(message, ctx) {
57549
57571
  switch (message.type) {
57550
- case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE:
57551
- await this.handleOfferMessage(message, ctx);
57552
- return null;
57572
+ case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE: {
57573
+ const result = await this.handleOfferMessage(message, ctx);
57574
+ if (Array.isArray(result)) {
57575
+ const credWallet = this.opts?.credentialWallet;
57576
+ if (!credWallet)
57577
+ throw new Error('Credential wallet is not provided');
57578
+ await credWallet.saveAll(result);
57579
+ return null;
57580
+ }
57581
+ return result;
57582
+ }
57553
57583
  case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE:
57554
57584
  return this.handleFetchRequest(message);
57555
57585
  case PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:
@@ -57563,8 +57593,7 @@ class FetchHandler extends AbstractMessageHandler {
57563
57593
  ctx.mediaType = MediaType.ZKPMessage;
57564
57594
  }
57565
57595
  const credentials = [];
57566
- for (let index = 0; index < offerMessage.body.credentials.length; index++) {
57567
- const credentialInfo = offerMessage.body.credentials[index];
57596
+ for (const credentialInfo of offerMessage.body.credentials) {
57568
57597
  const guid = v4();
57569
57598
  const fetchRequest = {
57570
57599
  id: guid,
@@ -57588,7 +57617,6 @@ class FetchHandler extends AbstractMessageHandler {
57588
57617
  senderDID,
57589
57618
  ...packerOpts
57590
57619
  }));
57591
- let message;
57592
57620
  try {
57593
57621
  if (!offerMessage?.body?.url) {
57594
57622
  throw new Error(`could not fetch W3C credential, body url is missing`);
@@ -57601,14 +57629,18 @@ class FetchHandler extends AbstractMessageHandler {
57601
57629
  },
57602
57630
  body: token
57603
57631
  });
57604
- if (resp.status !== 200) {
57605
- throw new Error(`could not fetch W3C credential, ${credentialInfo?.id}`);
57632
+ const arrayBuffer = await resp.arrayBuffer();
57633
+ if (!arrayBuffer.byteLength) {
57634
+ throw new Error(`could not fetch , ${credentialInfo?.id}, response is empty`);
57635
+ }
57636
+ const { unpackedMessage: message } = await this._packerMgr.unpack(new Uint8Array(arrayBuffer));
57637
+ if (message.type !== PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE) {
57638
+ return message;
57606
57639
  }
57607
- message = await resp.json();
57608
57640
  credentials.push(W3CCredential.fromJSON(message.body.credential));
57609
57641
  }
57610
57642
  catch (e) {
57611
- throw new Error(`could not fetch W3C credential, ${credentialInfo?.id}, error: ${e.message ?? e}`);
57643
+ throw new Error(`could not fetch protocol message for credential offer id: , ${credentialInfo?.id}, error: ${e.message ?? e}`);
57612
57644
  }
57613
57645
  }
57614
57646
  return credentials;
@@ -57627,11 +57659,15 @@ class FetchHandler extends AbstractMessageHandler {
57627
57659
  throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
57628
57660
  }
57629
57661
  const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
57630
- return this.handleOfferMessage(offerMessage, {
57662
+ const result = await this.handleOfferMessage(offerMessage, {
57631
57663
  mediaType: opts?.mediaType,
57632
57664
  headers: opts?.headers,
57633
57665
  packerOptions: opts?.packerOptions
57634
57666
  });
57667
+ if (Array.isArray(result)) {
57668
+ return result;
57669
+ }
57670
+ throw new Error('invalid protocol message response');
57635
57671
  }
57636
57672
  async handleFetchRequest(msgRequest) {
57637
57673
  if (!msgRequest.to) {
@@ -57644,7 +57680,7 @@ class FetchHandler extends AbstractMessageHandler {
57644
57680
  const userDID = DID.parse(msgRequest.from);
57645
57681
  const credId = msgRequest.body?.id;
57646
57682
  if (!credId) {
57647
- throw new Error('nvalid credential id in fetch request body');
57683
+ throw new Error('invalid credential id in fetch request body');
57648
57684
  }
57649
57685
  if (!this.opts?.credentialWallet) {
57650
57686
  throw new Error('please, provide credential wallet in options');
@@ -58265,7 +58301,7 @@ class PaymentHandler extends AbstractMessageHandler {
58265
58301
  if (!paymentRequest.from) {
58266
58302
  throw new Error(`failed request. empty 'from' field`);
58267
58303
  }
58268
- if (!paymentRequest.body?.payments?.length) {
58304
+ if (!paymentRequest.body.payments?.length) {
58269
58305
  throw new Error(`failed request. no 'payments' in body`);
58270
58306
  }
58271
58307
  if (!ctx.paymentHandler) {
@@ -58336,12 +58372,12 @@ class PaymentHandler extends AbstractMessageHandler {
58336
58372
  if (opts.paymentRequest.from !== payment.to) {
58337
58373
  throw new Error(`sender of the request is not a target of response - expected ${opts.paymentRequest.from}, given ${payment.to}`);
58338
58374
  }
58339
- if (!payment.body?.payments.length) {
58375
+ if (!payment.body.payments.length) {
58340
58376
  throw new Error(`failed request. empty 'payments' field in body`);
58341
58377
  }
58342
58378
  for (let i = 0; i < payment.body.payments.length; i++) {
58343
- const p = payment.body?.payments[i];
58344
- const paymentRequestData = opts.paymentRequest.body?.payments.find((r) => r.data.id === p.id);
58379
+ const p = payment.body.payments[i];
58380
+ const paymentRequestData = opts.paymentRequest.body.payments.find((r) => r.data.id === p.id);
58345
58381
  if (!paymentRequestData) {
58346
58382
  throw new Error(`can't find payment request for payment id ${p.id}`);
58347
58383
  }
@@ -58365,5 +58401,5 @@ class PaymentHandler extends AbstractMessageHandler {
58365
58401
  }
58366
58402
  }
58367
58403
 
58368
- export { AbstractMessageHandler, AbstractPrivateKeyStore, AgentResolver, AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQueryMTPV2OnChainPubSignals, AtomicQueryMTPV2PubSignals, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainCircuitInputs, AtomicQuerySigV2OnChainInputs, AtomicQuerySigV2OnChainPubSignals, AtomicQuerySigV2PubSignals, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, AtomicQueryV3OnChainPubSignals, AtomicQueryV3PubSignals, AuthHandler, AuthV2Inputs, AuthV2PubSignals, BJJSignatureProof2021, BaseConfig, BjjProvider, BrowserDataSource, CircuitClaim, CircuitError, CircuitId, CircuitStorage, ContractRequestHandler, CredentialProposalHandler, CredentialStatusPublisherRegistry, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DataPrepareHandlerFunc, Ed25519Provider, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, Iden3OnchainSmtCredentialStatusPublisher, Iden3SmtRhsCredentialStatusPublisher, Iden3SparseMerkleTreeProof, IdentityStorage, IdentityWallet, InMemoryDataSource, InMemoryMerkleTreeStorage, InMemoryPrivateKeyStore, IndexedDBDataSource, IndexedDBPrivateKeyStore, InputGenerator, IssuerResolver, JSON_SCHEMA_VALIDATORS_REGISTRY, JWSPacker, JsonSchemaValidator, KMS, KmsKeyType, LDParser, LinkedMultiQueryInputs, LinkedMultiQueryPubSignals, LocalStoragePrivateKeyStore, MerkleTreeIndexedDBStorage, MerkleTreeLocalStorage, MerkleTreeType, MerklizedRootPosition, MessageBus, MessageHandler, NativeProver, OnChainResolver, OnChainRevocationStorage, OnChainZKPVerifier, Operators, constants as PROTOCOL_CONSTANTS, PackageManager, Parser, PaymentHandler, PaymentRequestDataType, PaymentRequestType, PaymentType, PlainPacker, ProofNode, ProofPurpose, ProofService, ProofType, PubSignalsVerifier, Query, QueryOperators, RHSResolver, RefreshHandler, RefreshServiceType, RevocationStatusHandler, SDK_EVENTS, Scalar, SearchError, Sec256k1Provider, StandardJSONCredentialsQueryFilter, StateTransitionInputs, StateTransitionPubSignals, SubjectPosition, TransactionService, ValueProof, Vector, VerifiableConstants, VerificationHandlerFunc, W3CCredential, XSDNS, ZKPPacker, availableTypesOperators, base58ToBytes$1 as base58ToBytes, base64ToBytes$1 as base64ToBytes, base64UrlToBytes, bigIntArrayToStringArray, bigIntCompare, buildDIDFromEthPubKey, buildFieldPath, buildTreeState, buildVerifierId, byteDecoder, byteEncoder, bytesToBase58$1 as bytesToBase58, bytesToBase64, bytesToBase64url$1 as bytesToBase64url, bytesToHex$3 as bytesToHex, cacheLoader, calculateCoreSchemaHash, calculateQueryHashV2, calculateQueryHashV3, checkCircuitOperator, checkCircuitQueriesLength, checkDataInField, checkQueryRequest, circuitValidator, comparatorOptions, createAuthorizationRequest, createAuthorizationRequestWithMessage, createPayment, createPaymentRequest, createProposal, createProposalRequest, createSchemaHash, createVerifiablePresentation, credentialSubjectKey, dataFillsSlot, decodeBase64url$1 as decodeBase64url, defaultEthConnectionConfig, defaultMTLevels, defaultMTLevelsClaim, defaultMTLevelsOnChain, defaultValueArraySize, defineMerklizedRootPosition, encodeBase64url, existenceToInt, extractProof, extractPublicKeyBytes, factoryComparer, fieldToByteArray, fieldValueFromVerifiablePresentation, fillCoreClaimSlot, fillSlot, findCredentialType, findValue, generateProfileDID, getFieldSlotIndex, getKMSIdByAuthCredential, getNodeAuxValue, getNodesRepresentation, getOperatorNameByValue, getProperties, getSerializationAttrFromContext, getSerializationAttrFromParsedContext, getUserDIDFromCredential, hexToBytes$3 as hexToBytes, isEthereumIdentity, isGenesisState, isGenesisStateId, isIssuerGenesis, isValidOperation, keyPath, mergeObjects, parseCoreClaimSlots, parseCredentialSubject, parseQueriesMetadata, parseQueryMetadata, parseSerializationAttr, prepareCircuitArrayValues, prepareSiblingsStr, processZeroKnowledgeProofRequests, pushHashesToRHS, resolveDIDDocumentAuth, resolvePath, resolveVerificationMethods, strMTHex, stringByPath, subjectPositionIndex, swapEndianness, toClaimNonRevStatus, toGISTProof, toRevocationStatus, transformQueryValueToBigInts, userStateError, validateDIDDocumentAuth, validateDisclosureNativeSDSupport, validateDisclosureV2Circuit, validateEmptyCredentialSubjectNoopNativeSupport, validateEmptyCredentialSubjectV2Circuit, validateOperators, validateTreeState, verifyFieldValueInclusionNativeExistsSupport, verifyFieldValueInclusionV2, witnessBuilder };
58404
+ export { AbstractMessageHandler, AbstractPrivateKeyStore, AgentResolver, AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQueryMTPV2OnChainPubSignals, AtomicQueryMTPV2PubSignals, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainCircuitInputs, AtomicQuerySigV2OnChainInputs, AtomicQuerySigV2OnChainPubSignals, AtomicQuerySigV2PubSignals, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, AtomicQueryV3OnChainPubSignals, AtomicQueryV3PubSignals, AuthHandler, AuthV2Inputs, AuthV2PubSignals, BJJSignatureProof2021, BaseConfig, BjjProvider, BrowserDataSource, CircuitClaim, CircuitError, CircuitId, CircuitStorage, ContractRequestHandler, CredentialProposalHandler, CredentialStatusPublisherRegistry, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DataPrepareHandlerFunc, Ed25519Provider, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, Iden3OnchainSmtCredentialStatusPublisher, Iden3SmtRhsCredentialStatusPublisher, Iden3SparseMerkleTreeProof, IdentityStorage, IdentityWallet, InMemoryDataSource, InMemoryMerkleTreeStorage, InMemoryPrivateKeyStore, IndexedDBDataSource, IndexedDBPrivateKeyStore, InputGenerator, IssuerResolver, JSON_SCHEMA_VALIDATORS_REGISTRY, JWSPacker, JsonSchemaValidator, KMS, KmsKeyType, LDParser, LinkedMultiQueryInputs, LinkedMultiQueryPubSignals, LocalStoragePrivateKeyStore, MerkleTreeIndexedDBStorage, MerkleTreeLocalStorage, MerkleTreeType, MerklizedRootPosition, MessageBus, MessageHandler, NativeProver, OnChainResolver, OnChainRevocationStorage, OnChainZKPVerifier, Operators, constants as PROTOCOL_CONSTANTS, PackageManager, Parser, PaymentHandler, PaymentRequestDataType, PaymentRequestType, PaymentType, PlainPacker, ProofNode, ProofPurpose, ProofService, ProofType, PubSignalsVerifier, Query, QueryOperators, RHSResolver, RefreshHandler, RefreshServiceType, RevocationStatusHandler, SDK_EVENTS, Scalar, SearchError, Sec256k1Provider, StandardJSONCredentialsQueryFilter, StateTransitionInputs, StateTransitionPubSignals, SubjectPosition, SupportedCurrencies, TransactionService, ValueProof, Vector, VerifiableConstants, VerificationHandlerFunc, W3CCredential, XSDNS, ZKPPacker, availableTypesOperators, base58ToBytes$1 as base58ToBytes, base64ToBytes$1 as base64ToBytes, base64UrlToBytes, bigIntArrayToStringArray, bigIntCompare, buildDIDFromEthPubKey, buildFieldPath, buildTreeState, buildVerifierId, byteDecoder, byteEncoder, bytesToBase58$1 as bytesToBase58, bytesToBase64, bytesToBase64url$1 as bytesToBase64url, bytesToHex$3 as bytesToHex, cacheLoader, calculateCoreSchemaHash, calculateQueryHashV2, calculateQueryHashV3, checkCircuitOperator, checkCircuitQueriesLength, checkDataInField, checkQueryRequest, circuitValidator, comparatorOptions, createAuthorizationRequest, createAuthorizationRequestWithMessage, createPayment, createPaymentRequest, createProposal, createProposalRequest, createSchemaHash, createVerifiablePresentation, credentialSubjectKey, dataFillsSlot, decodeBase64url$1 as decodeBase64url, defaultEthConnectionConfig, defaultMTLevels, defaultMTLevelsClaim, defaultMTLevelsOnChain, defaultValueArraySize, defineMerklizedRootPosition, encodeBase64url, existenceToInt, extractProof, extractPublicKeyBytes, factoryComparer, fieldToByteArray, fieldValueFromVerifiablePresentation, fillCoreClaimSlot, fillSlot, findCredentialType, findValue, generateProfileDID, getFieldSlotIndex, getKMSIdByAuthCredential, getNodeAuxValue, getNodesRepresentation, getOperatorNameByValue, getProperties, getSerializationAttrFromContext, getSerializationAttrFromParsedContext, getUserDIDFromCredential, hexToBytes$3 as hexToBytes, isEthereumIdentity, isGenesisState, isGenesisStateId, isIssuerGenesis, isValidOperation, keyPath, mergeObjects, parseCoreClaimSlots, parseCredentialSubject, parseQueriesMetadata, parseQueryMetadata, parseSerializationAttr, prepareCircuitArrayValues, prepareSiblingsStr, processZeroKnowledgeProofRequests, pushHashesToRHS, resolveDIDDocumentAuth, resolvePath, resolveVerificationMethods, strMTHex, stringByPath, subjectPositionIndex, swapEndianness, toClaimNonRevStatus, toGISTProof, toRevocationStatus, transformQueryValueToBigInts, userStateError, validateDIDDocumentAuth, validateDisclosureNativeSDSupport, validateDisclosureV2Circuit, validateEmptyCredentialSubjectNoopNativeSupport, validateEmptyCredentialSubjectV2Circuit, validateOperators, validateTreeState, verifyFieldValueInclusionNativeExistsSupport, verifyFieldValueInclusionV2, witnessBuilder };
58369
58405
  //# sourceMappingURL=index.js.map