@0xpolygonid/js-sdk 1.21.1 → 1.23.0
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 +1394 -278
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +1399 -278
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/constants.js +25 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +52 -8
- package/dist/node/cjs/iden3comm/handlers/common.js +13 -1
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +5 -1
- package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +14 -3
- package/dist/node/cjs/iden3comm/handlers/fetch.js +12 -2
- package/dist/node/cjs/iden3comm/handlers/message-handler.js +4 -0
- package/dist/node/cjs/iden3comm/handlers/payment.js +240 -28
- package/dist/node/cjs/iden3comm/handlers/revocation-status.js +4 -0
- package/dist/node/cjs/iden3comm/index.js +1 -0
- package/dist/node/cjs/iden3comm/packageManager.js +12 -0
- package/dist/node/cjs/iden3comm/packers/jws.js +21 -0
- package/dist/node/cjs/iden3comm/packers/plain.js +19 -0
- package/dist/node/cjs/iden3comm/packers/zkp.js +25 -0
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/accept-profile.js +2 -0
- package/dist/node/cjs/iden3comm/utils/accept-profile.js +107 -0
- package/dist/node/cjs/iden3comm/utils/index.js +1 -0
- package/dist/node/cjs/proof/provers/inputs-generator.js +2 -1
- package/dist/node/cjs/storage/blockchain/abi/ERC20Permit.json +1 -0
- package/dist/node/cjs/storage/blockchain/erc20-permit-sig.js +46 -0
- package/dist/node/cjs/storage/blockchain/index.js +1 -0
- package/dist/node/cjs/storage/filters/jsonQuery.js +5 -3
- package/dist/node/cjs/verifiable/constants.js +28 -11
- package/dist/node/esm/iden3comm/constants.js +24 -0
- package/dist/node/esm/iden3comm/handlers/auth.js +55 -11
- package/dist/node/esm/iden3comm/handlers/common.js +11 -0
- package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -3
- package/dist/node/esm/iden3comm/handlers/credential-proposal.js +15 -4
- package/dist/node/esm/iden3comm/handlers/fetch.js +12 -2
- package/dist/node/esm/iden3comm/handlers/message-handler.js +4 -0
- package/dist/node/esm/iden3comm/handlers/payment.js +240 -29
- package/dist/node/esm/iden3comm/handlers/revocation-status.js +4 -0
- package/dist/node/esm/iden3comm/index.js +1 -0
- package/dist/node/esm/iden3comm/packageManager.js +12 -0
- package/dist/node/esm/iden3comm/packers/jws.js +22 -1
- package/dist/node/esm/iden3comm/packers/plain.js +19 -0
- package/dist/node/esm/iden3comm/packers/zkp.js +26 -1
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/accept-profile.js +1 -0
- package/dist/node/esm/iden3comm/utils/accept-profile.js +102 -0
- package/dist/node/esm/iden3comm/utils/index.js +1 -0
- package/dist/node/esm/proof/provers/inputs-generator.js +2 -1
- package/dist/node/esm/storage/blockchain/abi/ERC20Permit.json +1 -0
- package/dist/node/esm/storage/blockchain/erc20-permit-sig.js +39 -0
- package/dist/node/esm/storage/blockchain/index.js +1 -0
- package/dist/node/esm/storage/filters/jsonQuery.js +5 -3
- package/dist/node/esm/verifiable/constants.js +27 -10
- package/dist/types/iden3comm/constants.d.ts +16 -0
- package/dist/types/iden3comm/handlers/auth.d.ts +19 -7
- package/dist/types/iden3comm/handlers/common.d.ts +7 -1
- package/dist/types/iden3comm/handlers/contract-request.d.ts +2 -2
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts +9 -4
- package/dist/types/iden3comm/handlers/fetch.d.ts +22 -6
- package/dist/types/iden3comm/handlers/message-handler.d.ts +6 -0
- package/dist/types/iden3comm/handlers/payment.d.ts +70 -10
- package/dist/types/iden3comm/handlers/revocation-status.d.ts +2 -2
- package/dist/types/iden3comm/index.d.ts +1 -0
- package/dist/types/iden3comm/packageManager.d.ts +4 -0
- package/dist/types/iden3comm/packers/jws.d.ts +5 -0
- package/dist/types/iden3comm/packers/plain.d.ts +4 -0
- package/dist/types/iden3comm/packers/zkp.d.ts +6 -0
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/packageManager.d.ts +14 -0
- package/dist/types/iden3comm/types/packer.d.ts +25 -0
- package/dist/types/iden3comm/types/protocol/accept-profile.d.ts +7 -0
- package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
- package/dist/types/iden3comm/types/protocol/credentials.d.ts +6 -6
- package/dist/types/iden3comm/types/protocol/messages.d.ts +2 -2
- package/dist/types/iden3comm/types/protocol/payment.d.ts +87 -13
- package/dist/types/iden3comm/types/protocol/proof.d.ts +3 -3
- package/dist/types/iden3comm/types/protocol/revocation.d.ts +2 -2
- package/dist/types/iden3comm/utils/accept-profile.d.ts +3 -0
- package/dist/types/iden3comm/utils/index.d.ts +1 -0
- package/dist/types/storage/blockchain/erc20-permit-sig.d.ts +12 -0
- package/dist/types/storage/blockchain/index.d.ts +1 -0
- package/dist/types/verifiable/constants.d.ts +27 -11
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DID, buildDIDType, Id as Id$1, genesisFromEthAddress, BytesHelper, checkBigIntInField, Claim, SchemaHash, ClaimOptions, MerklizedRootPosition as MerklizedRootPosition$1, IdPosition, getChainId,
|
|
1
|
+
import { DID, buildDIDType, Id as Id$1, genesisFromEthAddress, BytesHelper, checkBigIntInField, Claim, SchemaHash, ClaimOptions, MerklizedRootPosition as MerklizedRootPosition$1, IdPosition, getChainId, getUnixTimestamp, ChainIds, getDateFromUnixTimestamp, DidMethod, Blockchain, NetworkId } from '@iden3/js-iden3-core';
|
|
2
2
|
import * as jsIden3Core from '@iden3/js-iden3-core';
|
|
3
3
|
export { jsIden3Core as core };
|
|
4
4
|
import { Path, Merklizer, getDocumentLoader } from '@iden3/js-jsonld-merklization';
|
|
@@ -7040,6 +7040,8 @@ function genBech32(encoding) {
|
|
|
7040
7040
|
function encode(prefix, words, limit = 90) {
|
|
7041
7041
|
if (typeof prefix !== 'string')
|
|
7042
7042
|
throw new Error(`bech32.encode prefix should be string, not ${typeof prefix}`);
|
|
7043
|
+
if (words instanceof Uint8Array)
|
|
7044
|
+
words = Array.from(words);
|
|
7043
7045
|
if (!Array.isArray(words) || (words.length && typeof words[0] !== 'number'))
|
|
7044
7046
|
throw new Error(`bech32.encode words should be array of numbers, not ${typeof words}`);
|
|
7045
7047
|
if (prefix.length === 0)
|
|
@@ -7078,7 +7080,19 @@ function genBech32(encoding) {
|
|
|
7078
7080
|
const { prefix, words } = decode(str, false);
|
|
7079
7081
|
return { prefix, words, bytes: fromWords(words) };
|
|
7080
7082
|
}
|
|
7081
|
-
|
|
7083
|
+
function encodeFromBytes(prefix, bytes) {
|
|
7084
|
+
return encode(prefix, toWords(bytes));
|
|
7085
|
+
}
|
|
7086
|
+
return {
|
|
7087
|
+
encode,
|
|
7088
|
+
decode,
|
|
7089
|
+
encodeFromBytes,
|
|
7090
|
+
decodeToBytes,
|
|
7091
|
+
decodeUnsafe,
|
|
7092
|
+
fromWords,
|
|
7093
|
+
fromWordsUnsafe,
|
|
7094
|
+
toWords,
|
|
7095
|
+
};
|
|
7082
7096
|
}
|
|
7083
7097
|
const bech32 = /* @__PURE__ */ genBech32('bech32');
|
|
7084
7098
|
|
|
@@ -7771,15 +7785,6 @@ var RefreshServiceType;
|
|
|
7771
7785
|
(function (RefreshServiceType) {
|
|
7772
7786
|
RefreshServiceType["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
7773
7787
|
})(RefreshServiceType || (RefreshServiceType = {}));
|
|
7774
|
-
/**
|
|
7775
|
-
* PaymentRequestType type for payment requests
|
|
7776
|
-
* @beta
|
|
7777
|
-
* @enum {string}
|
|
7778
|
-
*/
|
|
7779
|
-
var PaymentRequestType;
|
|
7780
|
-
(function (PaymentRequestType) {
|
|
7781
|
-
PaymentRequestType["PaymentRequest"] = "PaymentRequest";
|
|
7782
|
-
})(PaymentRequestType || (PaymentRequestType = {}));
|
|
7783
7788
|
/**
|
|
7784
7789
|
* PaymentRequestDataType type for payment requests
|
|
7785
7790
|
* @beta
|
|
@@ -7788,6 +7793,8 @@ var PaymentRequestType;
|
|
|
7788
7793
|
var PaymentRequestDataType;
|
|
7789
7794
|
(function (PaymentRequestDataType) {
|
|
7790
7795
|
PaymentRequestDataType["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
7796
|
+
PaymentRequestDataType["Iden3PaymentRailsRequestV1"] = "Iden3PaymentRailsRequestV1";
|
|
7797
|
+
PaymentRequestDataType["Iden3PaymentRailsERC20RequestV1"] = "Iden3PaymentRailsERC20RequestV1";
|
|
7791
7798
|
})(PaymentRequestDataType || (PaymentRequestDataType = {}));
|
|
7792
7799
|
/**
|
|
7793
7800
|
* PaymentType type for payment responses
|
|
@@ -7797,17 +7804,41 @@ var PaymentRequestDataType;
|
|
|
7797
7804
|
var PaymentType;
|
|
7798
7805
|
(function (PaymentType) {
|
|
7799
7806
|
PaymentType["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
7807
|
+
PaymentType["Iden3PaymentRailsV1"] = "Iden3PaymentRailsV1";
|
|
7808
|
+
PaymentType["Iden3PaymentRailsERC20V1"] = "Iden3PaymentRailsERC20V1";
|
|
7800
7809
|
})(PaymentType || (PaymentType = {}));
|
|
7810
|
+
/**
|
|
7811
|
+
* SupportedPaymentProofType type for payment proofs
|
|
7812
|
+
* @beta
|
|
7813
|
+
* @enum {string}
|
|
7814
|
+
*/
|
|
7815
|
+
var SupportedPaymentProofType;
|
|
7816
|
+
(function (SupportedPaymentProofType) {
|
|
7817
|
+
SupportedPaymentProofType["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
|
|
7818
|
+
})(SupportedPaymentProofType || (SupportedPaymentProofType = {}));
|
|
7801
7819
|
/**
|
|
7802
7820
|
* Media types for Payment supported currencies
|
|
7803
7821
|
* @beta
|
|
7804
|
-
* @enum {
|
|
7822
|
+
* @enum {string}
|
|
7805
7823
|
*/
|
|
7806
7824
|
var SupportedCurrencies;
|
|
7807
7825
|
(function (SupportedCurrencies) {
|
|
7808
7826
|
SupportedCurrencies["ETH"] = "ETH";
|
|
7827
|
+
SupportedCurrencies["ETH_WEI"] = "ETHWEI";
|
|
7828
|
+
SupportedCurrencies["ETH_GWEI"] = "ETHGWEI";
|
|
7809
7829
|
SupportedCurrencies["MATIC"] = "MATIC";
|
|
7830
|
+
SupportedCurrencies["USDT"] = "USDT";
|
|
7831
|
+
SupportedCurrencies["USDC"] = "USDC";
|
|
7810
7832
|
})(SupportedCurrencies || (SupportedCurrencies = {}));
|
|
7833
|
+
/**
|
|
7834
|
+
* Supported features for payment-request
|
|
7835
|
+
* @beta
|
|
7836
|
+
* @enum {string}
|
|
7837
|
+
*/
|
|
7838
|
+
var PaymentFeatures;
|
|
7839
|
+
(function (PaymentFeatures) {
|
|
7840
|
+
PaymentFeatures["EIP_2612"] = "EIP-2612";
|
|
7841
|
+
})(PaymentFeatures || (PaymentFeatures = {}));
|
|
7811
7842
|
/**
|
|
7812
7843
|
* DisplayMethodType type for display method
|
|
7813
7844
|
*
|
|
@@ -30280,7 +30311,7 @@ const cacheLoader = (opts) => {
|
|
|
30280
30311
|
/**
|
|
30281
30312
|
* The current version of Ethers.
|
|
30282
30313
|
*/
|
|
30283
|
-
const version = "6.13.
|
|
30314
|
+
const version = "6.13.4";
|
|
30284
30315
|
|
|
30285
30316
|
/**
|
|
30286
30317
|
* Property helper functions.
|
|
@@ -39833,6 +39864,12 @@ class TypedDataEncoder {
|
|
|
39833
39864
|
};
|
|
39834
39865
|
}
|
|
39835
39866
|
}
|
|
39867
|
+
/**
|
|
39868
|
+
* Compute the address used to sign the typed data for the %%signature%%.
|
|
39869
|
+
*/
|
|
39870
|
+
function verifyTypedData(domain, types, value, signature) {
|
|
39871
|
+
return recoverAddress(TypedDataEncoder.hash(domain, types, value), signature);
|
|
39872
|
+
}
|
|
39836
39873
|
|
|
39837
39874
|
/**
|
|
39838
39875
|
* A fragment is a single item from an ABI, which may represent any of:
|
|
@@ -46683,7 +46720,18 @@ class AbstractProvider {
|
|
|
46683
46720
|
}
|
|
46684
46721
|
this.emit("debug", { action: "sendCcipReadFetchRequest", request, index: i, urls });
|
|
46685
46722
|
let errorMessage = "unknown error";
|
|
46686
|
-
|
|
46723
|
+
// Fetch the resource...
|
|
46724
|
+
let resp;
|
|
46725
|
+
try {
|
|
46726
|
+
resp = await request.send();
|
|
46727
|
+
}
|
|
46728
|
+
catch (error) {
|
|
46729
|
+
// ...low-level fetch error (missing host, bad SSL, etc.),
|
|
46730
|
+
// so try next URL
|
|
46731
|
+
errorMessages.push(error.message);
|
|
46732
|
+
this.emit("debug", { action: "receiveCcipReadFetchError", request, result: { error } });
|
|
46733
|
+
continue;
|
|
46734
|
+
}
|
|
46687
46735
|
try {
|
|
46688
46736
|
const result = resp.bodyJson;
|
|
46689
46737
|
if (result.data) {
|
|
@@ -48279,7 +48327,7 @@ class JsonRpcSigner extends AbstractSigner {
|
|
|
48279
48327
|
// If the network changed: calling again will also fail
|
|
48280
48328
|
// If unsupported: likely destroyed
|
|
48281
48329
|
if (isError(error, "CANCELLED") || isError(error, "BAD_DATA") ||
|
|
48282
|
-
isError(error, "NETWORK_ERROR")) {
|
|
48330
|
+
isError(error, "NETWORK_ERROR") || isError(error, "UNSUPPORTED_OPERATION")) {
|
|
48283
48331
|
if (error.info == null) {
|
|
48284
48332
|
error.info = {};
|
|
48285
48333
|
}
|
|
@@ -51299,7 +51347,7 @@ class LinkedMultiQueryPubSignals {
|
|
|
51299
51347
|
}
|
|
51300
51348
|
}
|
|
51301
51349
|
|
|
51302
|
-
var abi$
|
|
51350
|
+
var abi$3 = [
|
|
51303
51351
|
{
|
|
51304
51352
|
inputs: [
|
|
51305
51353
|
],
|
|
@@ -52413,7 +52461,7 @@ class EthStateStorage {
|
|
|
52413
52461
|
this.ethConfig = ethConfig;
|
|
52414
52462
|
const config = Array.isArray(ethConfig) ? ethConfig[0] : ethConfig;
|
|
52415
52463
|
this.provider = new JsonRpcProvider(config.url);
|
|
52416
|
-
this.stateContract = new Contract(config.contractAddress, abi$
|
|
52464
|
+
this.stateContract = new Contract(config.contractAddress, abi$3, this.provider);
|
|
52417
52465
|
this._transactionService = new TransactionService(this.getRpcProvider());
|
|
52418
52466
|
}
|
|
52419
52467
|
/** {@inheritdoc IStateStorage.getLatestStateById} */
|
|
@@ -52553,7 +52601,7 @@ class EthStateStorage {
|
|
|
52553
52601
|
const chainId = getChainId(DID.blockchainFromId(idTyped), DID.networkIdFromId(idTyped));
|
|
52554
52602
|
const config = this.networkByChainId(chainId);
|
|
52555
52603
|
const provider = new JsonRpcProvider(config.url);
|
|
52556
|
-
const stateContract = new Contract(config.contractAddress, abi$
|
|
52604
|
+
const stateContract = new Contract(config.contractAddress, abi$3, provider);
|
|
52557
52605
|
return { stateContract, provider };
|
|
52558
52606
|
}
|
|
52559
52607
|
networkByChainId(chainId) {
|
|
@@ -52566,7 +52614,7 @@ class EthStateStorage {
|
|
|
52566
52614
|
}
|
|
52567
52615
|
}
|
|
52568
52616
|
|
|
52569
|
-
var abi$
|
|
52617
|
+
var abi$2 = [
|
|
52570
52618
|
{
|
|
52571
52619
|
inputs: [
|
|
52572
52620
|
],
|
|
@@ -53466,7 +53514,7 @@ class OnChainZKPVerifier {
|
|
|
53466
53514
|
const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
|
|
53467
53515
|
? BigInt(chainConfig.maxPriorityFeePerGas)
|
|
53468
53516
|
: feeData.maxPriorityFeePerGas;
|
|
53469
|
-
const verifierContract = new Contract(txData.contract_address, abi$
|
|
53517
|
+
const verifierContract = new Contract(txData.contract_address, abi$2);
|
|
53470
53518
|
for (const zkProofResponse of zkProofResponses) {
|
|
53471
53519
|
const txArgs = await this.prepareTxArgsSubmitV1(txData, zkProofResponse);
|
|
53472
53520
|
const payload = await verifierContract.submitZKPResponse.populateTransaction(...txArgs);
|
|
@@ -53514,7 +53562,7 @@ class OnChainZKPVerifier {
|
|
|
53514
53562
|
const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
|
|
53515
53563
|
? BigInt(chainConfig.maxPriorityFeePerGas)
|
|
53516
53564
|
: feeData.maxPriorityFeePerGas;
|
|
53517
|
-
const verifierContract = new Contract(txData.contract_address, abi$
|
|
53565
|
+
const verifierContract = new Contract(txData.contract_address, abi$2);
|
|
53518
53566
|
const txRequestData = await verifierContract.submitZKPResponseV2.populateTransaction(...txDataArgs);
|
|
53519
53567
|
const request = {
|
|
53520
53568
|
to: txData.contract_address,
|
|
@@ -53707,7 +53755,7 @@ class OnChainZKPVerifier {
|
|
|
53707
53755
|
}
|
|
53708
53756
|
}
|
|
53709
53757
|
|
|
53710
|
-
var abi = [
|
|
53758
|
+
var abi$1 = [
|
|
53711
53759
|
{
|
|
53712
53760
|
inputs: [
|
|
53713
53761
|
],
|
|
@@ -53995,7 +54043,7 @@ class OnChainRevocationStorage {
|
|
|
53995
54043
|
this._config = _config;
|
|
53996
54044
|
this._signer = _signer;
|
|
53997
54045
|
this._provider = new JsonRpcProvider(_config.url);
|
|
53998
|
-
let contract = new Contract(contractAddress, abi, this._provider);
|
|
54046
|
+
let contract = new Contract(contractAddress, abi$1, this._provider);
|
|
53999
54047
|
if (this._signer) {
|
|
54000
54048
|
this._signer = this._signer.connect(this._provider);
|
|
54001
54049
|
contract = contract.connect(this._signer);
|
|
@@ -54076,6 +54124,575 @@ class OnChainRevocationStorage {
|
|
|
54076
54124
|
}
|
|
54077
54125
|
}
|
|
54078
54126
|
|
|
54127
|
+
var abi = [
|
|
54128
|
+
{
|
|
54129
|
+
inputs: [
|
|
54130
|
+
],
|
|
54131
|
+
name: "ECDSAInvalidSignature",
|
|
54132
|
+
type: "error"
|
|
54133
|
+
},
|
|
54134
|
+
{
|
|
54135
|
+
inputs: [
|
|
54136
|
+
{
|
|
54137
|
+
internalType: "uint256",
|
|
54138
|
+
name: "length",
|
|
54139
|
+
type: "uint256"
|
|
54140
|
+
}
|
|
54141
|
+
],
|
|
54142
|
+
name: "ECDSAInvalidSignatureLength",
|
|
54143
|
+
type: "error"
|
|
54144
|
+
},
|
|
54145
|
+
{
|
|
54146
|
+
inputs: [
|
|
54147
|
+
{
|
|
54148
|
+
internalType: "bytes32",
|
|
54149
|
+
name: "s",
|
|
54150
|
+
type: "bytes32"
|
|
54151
|
+
}
|
|
54152
|
+
],
|
|
54153
|
+
name: "ECDSAInvalidSignatureS",
|
|
54154
|
+
type: "error"
|
|
54155
|
+
},
|
|
54156
|
+
{
|
|
54157
|
+
inputs: [
|
|
54158
|
+
{
|
|
54159
|
+
internalType: "address",
|
|
54160
|
+
name: "spender",
|
|
54161
|
+
type: "address"
|
|
54162
|
+
},
|
|
54163
|
+
{
|
|
54164
|
+
internalType: "uint256",
|
|
54165
|
+
name: "allowance",
|
|
54166
|
+
type: "uint256"
|
|
54167
|
+
},
|
|
54168
|
+
{
|
|
54169
|
+
internalType: "uint256",
|
|
54170
|
+
name: "needed",
|
|
54171
|
+
type: "uint256"
|
|
54172
|
+
}
|
|
54173
|
+
],
|
|
54174
|
+
name: "ERC20InsufficientAllowance",
|
|
54175
|
+
type: "error"
|
|
54176
|
+
},
|
|
54177
|
+
{
|
|
54178
|
+
inputs: [
|
|
54179
|
+
{
|
|
54180
|
+
internalType: "address",
|
|
54181
|
+
name: "sender",
|
|
54182
|
+
type: "address"
|
|
54183
|
+
},
|
|
54184
|
+
{
|
|
54185
|
+
internalType: "uint256",
|
|
54186
|
+
name: "balance",
|
|
54187
|
+
type: "uint256"
|
|
54188
|
+
},
|
|
54189
|
+
{
|
|
54190
|
+
internalType: "uint256",
|
|
54191
|
+
name: "needed",
|
|
54192
|
+
type: "uint256"
|
|
54193
|
+
}
|
|
54194
|
+
],
|
|
54195
|
+
name: "ERC20InsufficientBalance",
|
|
54196
|
+
type: "error"
|
|
54197
|
+
},
|
|
54198
|
+
{
|
|
54199
|
+
inputs: [
|
|
54200
|
+
{
|
|
54201
|
+
internalType: "address",
|
|
54202
|
+
name: "approver",
|
|
54203
|
+
type: "address"
|
|
54204
|
+
}
|
|
54205
|
+
],
|
|
54206
|
+
name: "ERC20InvalidApprover",
|
|
54207
|
+
type: "error"
|
|
54208
|
+
},
|
|
54209
|
+
{
|
|
54210
|
+
inputs: [
|
|
54211
|
+
{
|
|
54212
|
+
internalType: "address",
|
|
54213
|
+
name: "receiver",
|
|
54214
|
+
type: "address"
|
|
54215
|
+
}
|
|
54216
|
+
],
|
|
54217
|
+
name: "ERC20InvalidReceiver",
|
|
54218
|
+
type: "error"
|
|
54219
|
+
},
|
|
54220
|
+
{
|
|
54221
|
+
inputs: [
|
|
54222
|
+
{
|
|
54223
|
+
internalType: "address",
|
|
54224
|
+
name: "sender",
|
|
54225
|
+
type: "address"
|
|
54226
|
+
}
|
|
54227
|
+
],
|
|
54228
|
+
name: "ERC20InvalidSender",
|
|
54229
|
+
type: "error"
|
|
54230
|
+
},
|
|
54231
|
+
{
|
|
54232
|
+
inputs: [
|
|
54233
|
+
{
|
|
54234
|
+
internalType: "address",
|
|
54235
|
+
name: "spender",
|
|
54236
|
+
type: "address"
|
|
54237
|
+
}
|
|
54238
|
+
],
|
|
54239
|
+
name: "ERC20InvalidSpender",
|
|
54240
|
+
type: "error"
|
|
54241
|
+
},
|
|
54242
|
+
{
|
|
54243
|
+
inputs: [
|
|
54244
|
+
{
|
|
54245
|
+
internalType: "uint256",
|
|
54246
|
+
name: "deadline",
|
|
54247
|
+
type: "uint256"
|
|
54248
|
+
}
|
|
54249
|
+
],
|
|
54250
|
+
name: "ERC2612ExpiredSignature",
|
|
54251
|
+
type: "error"
|
|
54252
|
+
},
|
|
54253
|
+
{
|
|
54254
|
+
inputs: [
|
|
54255
|
+
{
|
|
54256
|
+
internalType: "address",
|
|
54257
|
+
name: "signer",
|
|
54258
|
+
type: "address"
|
|
54259
|
+
},
|
|
54260
|
+
{
|
|
54261
|
+
internalType: "address",
|
|
54262
|
+
name: "owner",
|
|
54263
|
+
type: "address"
|
|
54264
|
+
}
|
|
54265
|
+
],
|
|
54266
|
+
name: "ERC2612InvalidSigner",
|
|
54267
|
+
type: "error"
|
|
54268
|
+
},
|
|
54269
|
+
{
|
|
54270
|
+
inputs: [
|
|
54271
|
+
{
|
|
54272
|
+
internalType: "address",
|
|
54273
|
+
name: "account",
|
|
54274
|
+
type: "address"
|
|
54275
|
+
},
|
|
54276
|
+
{
|
|
54277
|
+
internalType: "uint256",
|
|
54278
|
+
name: "currentNonce",
|
|
54279
|
+
type: "uint256"
|
|
54280
|
+
}
|
|
54281
|
+
],
|
|
54282
|
+
name: "InvalidAccountNonce",
|
|
54283
|
+
type: "error"
|
|
54284
|
+
},
|
|
54285
|
+
{
|
|
54286
|
+
inputs: [
|
|
54287
|
+
],
|
|
54288
|
+
name: "InvalidShortString",
|
|
54289
|
+
type: "error"
|
|
54290
|
+
},
|
|
54291
|
+
{
|
|
54292
|
+
inputs: [
|
|
54293
|
+
{
|
|
54294
|
+
internalType: "string",
|
|
54295
|
+
name: "str",
|
|
54296
|
+
type: "string"
|
|
54297
|
+
}
|
|
54298
|
+
],
|
|
54299
|
+
name: "StringTooLong",
|
|
54300
|
+
type: "error"
|
|
54301
|
+
},
|
|
54302
|
+
{
|
|
54303
|
+
anonymous: false,
|
|
54304
|
+
inputs: [
|
|
54305
|
+
{
|
|
54306
|
+
indexed: true,
|
|
54307
|
+
internalType: "address",
|
|
54308
|
+
name: "owner",
|
|
54309
|
+
type: "address"
|
|
54310
|
+
},
|
|
54311
|
+
{
|
|
54312
|
+
indexed: true,
|
|
54313
|
+
internalType: "address",
|
|
54314
|
+
name: "spender",
|
|
54315
|
+
type: "address"
|
|
54316
|
+
},
|
|
54317
|
+
{
|
|
54318
|
+
indexed: false,
|
|
54319
|
+
internalType: "uint256",
|
|
54320
|
+
name: "value",
|
|
54321
|
+
type: "uint256"
|
|
54322
|
+
}
|
|
54323
|
+
],
|
|
54324
|
+
name: "Approval",
|
|
54325
|
+
type: "event"
|
|
54326
|
+
},
|
|
54327
|
+
{
|
|
54328
|
+
anonymous: false,
|
|
54329
|
+
inputs: [
|
|
54330
|
+
],
|
|
54331
|
+
name: "EIP712DomainChanged",
|
|
54332
|
+
type: "event"
|
|
54333
|
+
},
|
|
54334
|
+
{
|
|
54335
|
+
anonymous: false,
|
|
54336
|
+
inputs: [
|
|
54337
|
+
{
|
|
54338
|
+
indexed: true,
|
|
54339
|
+
internalType: "address",
|
|
54340
|
+
name: "from",
|
|
54341
|
+
type: "address"
|
|
54342
|
+
},
|
|
54343
|
+
{
|
|
54344
|
+
indexed: true,
|
|
54345
|
+
internalType: "address",
|
|
54346
|
+
name: "to",
|
|
54347
|
+
type: "address"
|
|
54348
|
+
},
|
|
54349
|
+
{
|
|
54350
|
+
indexed: false,
|
|
54351
|
+
internalType: "uint256",
|
|
54352
|
+
name: "value",
|
|
54353
|
+
type: "uint256"
|
|
54354
|
+
}
|
|
54355
|
+
],
|
|
54356
|
+
name: "Transfer",
|
|
54357
|
+
type: "event"
|
|
54358
|
+
},
|
|
54359
|
+
{
|
|
54360
|
+
inputs: [
|
|
54361
|
+
],
|
|
54362
|
+
name: "DOMAIN_SEPARATOR",
|
|
54363
|
+
outputs: [
|
|
54364
|
+
{
|
|
54365
|
+
internalType: "bytes32",
|
|
54366
|
+
name: "",
|
|
54367
|
+
type: "bytes32"
|
|
54368
|
+
}
|
|
54369
|
+
],
|
|
54370
|
+
stateMutability: "view",
|
|
54371
|
+
type: "function"
|
|
54372
|
+
},
|
|
54373
|
+
{
|
|
54374
|
+
inputs: [
|
|
54375
|
+
{
|
|
54376
|
+
internalType: "address",
|
|
54377
|
+
name: "owner",
|
|
54378
|
+
type: "address"
|
|
54379
|
+
},
|
|
54380
|
+
{
|
|
54381
|
+
internalType: "address",
|
|
54382
|
+
name: "spender",
|
|
54383
|
+
type: "address"
|
|
54384
|
+
}
|
|
54385
|
+
],
|
|
54386
|
+
name: "allowance",
|
|
54387
|
+
outputs: [
|
|
54388
|
+
{
|
|
54389
|
+
internalType: "uint256",
|
|
54390
|
+
name: "",
|
|
54391
|
+
type: "uint256"
|
|
54392
|
+
}
|
|
54393
|
+
],
|
|
54394
|
+
stateMutability: "view",
|
|
54395
|
+
type: "function"
|
|
54396
|
+
},
|
|
54397
|
+
{
|
|
54398
|
+
inputs: [
|
|
54399
|
+
{
|
|
54400
|
+
internalType: "address",
|
|
54401
|
+
name: "spender",
|
|
54402
|
+
type: "address"
|
|
54403
|
+
},
|
|
54404
|
+
{
|
|
54405
|
+
internalType: "uint256",
|
|
54406
|
+
name: "value",
|
|
54407
|
+
type: "uint256"
|
|
54408
|
+
}
|
|
54409
|
+
],
|
|
54410
|
+
name: "approve",
|
|
54411
|
+
outputs: [
|
|
54412
|
+
{
|
|
54413
|
+
internalType: "bool",
|
|
54414
|
+
name: "",
|
|
54415
|
+
type: "bool"
|
|
54416
|
+
}
|
|
54417
|
+
],
|
|
54418
|
+
stateMutability: "nonpayable",
|
|
54419
|
+
type: "function"
|
|
54420
|
+
},
|
|
54421
|
+
{
|
|
54422
|
+
inputs: [
|
|
54423
|
+
{
|
|
54424
|
+
internalType: "address",
|
|
54425
|
+
name: "account",
|
|
54426
|
+
type: "address"
|
|
54427
|
+
}
|
|
54428
|
+
],
|
|
54429
|
+
name: "balanceOf",
|
|
54430
|
+
outputs: [
|
|
54431
|
+
{
|
|
54432
|
+
internalType: "uint256",
|
|
54433
|
+
name: "",
|
|
54434
|
+
type: "uint256"
|
|
54435
|
+
}
|
|
54436
|
+
],
|
|
54437
|
+
stateMutability: "view",
|
|
54438
|
+
type: "function"
|
|
54439
|
+
},
|
|
54440
|
+
{
|
|
54441
|
+
inputs: [
|
|
54442
|
+
],
|
|
54443
|
+
name: "decimals",
|
|
54444
|
+
outputs: [
|
|
54445
|
+
{
|
|
54446
|
+
internalType: "uint8",
|
|
54447
|
+
name: "",
|
|
54448
|
+
type: "uint8"
|
|
54449
|
+
}
|
|
54450
|
+
],
|
|
54451
|
+
stateMutability: "view",
|
|
54452
|
+
type: "function"
|
|
54453
|
+
},
|
|
54454
|
+
{
|
|
54455
|
+
inputs: [
|
|
54456
|
+
],
|
|
54457
|
+
name: "eip712Domain",
|
|
54458
|
+
outputs: [
|
|
54459
|
+
{
|
|
54460
|
+
internalType: "bytes1",
|
|
54461
|
+
name: "fields",
|
|
54462
|
+
type: "bytes1"
|
|
54463
|
+
},
|
|
54464
|
+
{
|
|
54465
|
+
internalType: "string",
|
|
54466
|
+
name: "name",
|
|
54467
|
+
type: "string"
|
|
54468
|
+
},
|
|
54469
|
+
{
|
|
54470
|
+
internalType: "string",
|
|
54471
|
+
name: "version",
|
|
54472
|
+
type: "string"
|
|
54473
|
+
},
|
|
54474
|
+
{
|
|
54475
|
+
internalType: "uint256",
|
|
54476
|
+
name: "chainId",
|
|
54477
|
+
type: "uint256"
|
|
54478
|
+
},
|
|
54479
|
+
{
|
|
54480
|
+
internalType: "address",
|
|
54481
|
+
name: "verifyingContract",
|
|
54482
|
+
type: "address"
|
|
54483
|
+
},
|
|
54484
|
+
{
|
|
54485
|
+
internalType: "bytes32",
|
|
54486
|
+
name: "salt",
|
|
54487
|
+
type: "bytes32"
|
|
54488
|
+
},
|
|
54489
|
+
{
|
|
54490
|
+
internalType: "uint256[]",
|
|
54491
|
+
name: "extensions",
|
|
54492
|
+
type: "uint256[]"
|
|
54493
|
+
}
|
|
54494
|
+
],
|
|
54495
|
+
stateMutability: "view",
|
|
54496
|
+
type: "function"
|
|
54497
|
+
},
|
|
54498
|
+
{
|
|
54499
|
+
inputs: [
|
|
54500
|
+
],
|
|
54501
|
+
name: "name",
|
|
54502
|
+
outputs: [
|
|
54503
|
+
{
|
|
54504
|
+
internalType: "string",
|
|
54505
|
+
name: "",
|
|
54506
|
+
type: "string"
|
|
54507
|
+
}
|
|
54508
|
+
],
|
|
54509
|
+
stateMutability: "view",
|
|
54510
|
+
type: "function"
|
|
54511
|
+
},
|
|
54512
|
+
{
|
|
54513
|
+
inputs: [
|
|
54514
|
+
{
|
|
54515
|
+
internalType: "address",
|
|
54516
|
+
name: "owner",
|
|
54517
|
+
type: "address"
|
|
54518
|
+
}
|
|
54519
|
+
],
|
|
54520
|
+
name: "nonces",
|
|
54521
|
+
outputs: [
|
|
54522
|
+
{
|
|
54523
|
+
internalType: "uint256",
|
|
54524
|
+
name: "",
|
|
54525
|
+
type: "uint256"
|
|
54526
|
+
}
|
|
54527
|
+
],
|
|
54528
|
+
stateMutability: "view",
|
|
54529
|
+
type: "function"
|
|
54530
|
+
},
|
|
54531
|
+
{
|
|
54532
|
+
inputs: [
|
|
54533
|
+
{
|
|
54534
|
+
internalType: "address",
|
|
54535
|
+
name: "owner",
|
|
54536
|
+
type: "address"
|
|
54537
|
+
},
|
|
54538
|
+
{
|
|
54539
|
+
internalType: "address",
|
|
54540
|
+
name: "spender",
|
|
54541
|
+
type: "address"
|
|
54542
|
+
},
|
|
54543
|
+
{
|
|
54544
|
+
internalType: "uint256",
|
|
54545
|
+
name: "value",
|
|
54546
|
+
type: "uint256"
|
|
54547
|
+
},
|
|
54548
|
+
{
|
|
54549
|
+
internalType: "uint256",
|
|
54550
|
+
name: "deadline",
|
|
54551
|
+
type: "uint256"
|
|
54552
|
+
},
|
|
54553
|
+
{
|
|
54554
|
+
internalType: "uint8",
|
|
54555
|
+
name: "v",
|
|
54556
|
+
type: "uint8"
|
|
54557
|
+
},
|
|
54558
|
+
{
|
|
54559
|
+
internalType: "bytes32",
|
|
54560
|
+
name: "r",
|
|
54561
|
+
type: "bytes32"
|
|
54562
|
+
},
|
|
54563
|
+
{
|
|
54564
|
+
internalType: "bytes32",
|
|
54565
|
+
name: "s",
|
|
54566
|
+
type: "bytes32"
|
|
54567
|
+
}
|
|
54568
|
+
],
|
|
54569
|
+
name: "permit",
|
|
54570
|
+
outputs: [
|
|
54571
|
+
],
|
|
54572
|
+
stateMutability: "nonpayable",
|
|
54573
|
+
type: "function"
|
|
54574
|
+
},
|
|
54575
|
+
{
|
|
54576
|
+
inputs: [
|
|
54577
|
+
],
|
|
54578
|
+
name: "symbol",
|
|
54579
|
+
outputs: [
|
|
54580
|
+
{
|
|
54581
|
+
internalType: "string",
|
|
54582
|
+
name: "",
|
|
54583
|
+
type: "string"
|
|
54584
|
+
}
|
|
54585
|
+
],
|
|
54586
|
+
stateMutability: "view",
|
|
54587
|
+
type: "function"
|
|
54588
|
+
},
|
|
54589
|
+
{
|
|
54590
|
+
inputs: [
|
|
54591
|
+
],
|
|
54592
|
+
name: "totalSupply",
|
|
54593
|
+
outputs: [
|
|
54594
|
+
{
|
|
54595
|
+
internalType: "uint256",
|
|
54596
|
+
name: "",
|
|
54597
|
+
type: "uint256"
|
|
54598
|
+
}
|
|
54599
|
+
],
|
|
54600
|
+
stateMutability: "view",
|
|
54601
|
+
type: "function"
|
|
54602
|
+
},
|
|
54603
|
+
{
|
|
54604
|
+
inputs: [
|
|
54605
|
+
{
|
|
54606
|
+
internalType: "address",
|
|
54607
|
+
name: "to",
|
|
54608
|
+
type: "address"
|
|
54609
|
+
},
|
|
54610
|
+
{
|
|
54611
|
+
internalType: "uint256",
|
|
54612
|
+
name: "value",
|
|
54613
|
+
type: "uint256"
|
|
54614
|
+
}
|
|
54615
|
+
],
|
|
54616
|
+
name: "transfer",
|
|
54617
|
+
outputs: [
|
|
54618
|
+
{
|
|
54619
|
+
internalType: "bool",
|
|
54620
|
+
name: "",
|
|
54621
|
+
type: "bool"
|
|
54622
|
+
}
|
|
54623
|
+
],
|
|
54624
|
+
stateMutability: "nonpayable",
|
|
54625
|
+
type: "function"
|
|
54626
|
+
},
|
|
54627
|
+
{
|
|
54628
|
+
inputs: [
|
|
54629
|
+
{
|
|
54630
|
+
internalType: "address",
|
|
54631
|
+
name: "from",
|
|
54632
|
+
type: "address"
|
|
54633
|
+
},
|
|
54634
|
+
{
|
|
54635
|
+
internalType: "address",
|
|
54636
|
+
name: "to",
|
|
54637
|
+
type: "address"
|
|
54638
|
+
},
|
|
54639
|
+
{
|
|
54640
|
+
internalType: "uint256",
|
|
54641
|
+
name: "value",
|
|
54642
|
+
type: "uint256"
|
|
54643
|
+
}
|
|
54644
|
+
],
|
|
54645
|
+
name: "transferFrom",
|
|
54646
|
+
outputs: [
|
|
54647
|
+
{
|
|
54648
|
+
internalType: "bool",
|
|
54649
|
+
name: "",
|
|
54650
|
+
type: "bool"
|
|
54651
|
+
}
|
|
54652
|
+
],
|
|
54653
|
+
stateMutability: "nonpayable",
|
|
54654
|
+
type: "function"
|
|
54655
|
+
}
|
|
54656
|
+
];
|
|
54657
|
+
|
|
54658
|
+
/**
|
|
54659
|
+
* @beta
|
|
54660
|
+
* getPermitSignature is a function to create EIP712 Permit signature
|
|
54661
|
+
* @param {Signer} signer - User who owns the tokens
|
|
54662
|
+
* @param {string} tokenAddress - EIP-2612 contract address
|
|
54663
|
+
* @param {string} spender - The contract address that will spend tokens
|
|
54664
|
+
* @param {bigint} value - Amount of tokens to approve
|
|
54665
|
+
* @param {number} deadline - Timestamp when the permit expires
|
|
54666
|
+
* @returns {Promise<PaymentRequestMessage>}
|
|
54667
|
+
*/
|
|
54668
|
+
async function getPermitSignature(signer, tokenAddress, spender, value, deadline) {
|
|
54669
|
+
const erc20PermitContract = new Contract(tokenAddress, abi, signer);
|
|
54670
|
+
const nonce = await erc20PermitContract.nonces(await signer.getAddress());
|
|
54671
|
+
const domainData = await erc20PermitContract.eip712Domain();
|
|
54672
|
+
const domain = {
|
|
54673
|
+
version: domainData[2],
|
|
54674
|
+
chainId: domainData[3],
|
|
54675
|
+
verifyingContract: tokenAddress
|
|
54676
|
+
};
|
|
54677
|
+
const types = {
|
|
54678
|
+
Permit: [
|
|
54679
|
+
{ name: 'owner', type: 'address' },
|
|
54680
|
+
{ name: 'spender', type: 'address' },
|
|
54681
|
+
{ name: 'value', type: 'uint256' },
|
|
54682
|
+
{ name: 'nonce', type: 'uint256' },
|
|
54683
|
+
{ name: 'deadline', type: 'uint256' }
|
|
54684
|
+
]
|
|
54685
|
+
};
|
|
54686
|
+
const message = {
|
|
54687
|
+
owner: await signer.getAddress(),
|
|
54688
|
+
spender: spender,
|
|
54689
|
+
value: value,
|
|
54690
|
+
nonce: nonce,
|
|
54691
|
+
deadline: deadline
|
|
54692
|
+
};
|
|
54693
|
+
return signer.signTypedData(domain, types, message);
|
|
54694
|
+
}
|
|
54695
|
+
|
|
54079
54696
|
/**
|
|
54080
54697
|
* Type of MerkleTree
|
|
54081
54698
|
*
|
|
@@ -54188,10 +54805,12 @@ const betweenOperator = (a, b) => {
|
|
|
54188
54805
|
if (!Array.isArray(b) || b.length !== 2) {
|
|
54189
54806
|
throw new Error('$between/$nonbetween operator value should be 2 elements array');
|
|
54190
54807
|
}
|
|
54808
|
+
const [min, max] = b.map(BigInt);
|
|
54809
|
+
const predicate = (val) => val >= min && val <= max;
|
|
54191
54810
|
if (Array.isArray(a)) {
|
|
54192
|
-
return a.every(
|
|
54811
|
+
return a.map(BigInt).every(predicate);
|
|
54193
54812
|
}
|
|
54194
|
-
return a
|
|
54813
|
+
return predicate(BigInt(a));
|
|
54195
54814
|
};
|
|
54196
54815
|
const comparatorOptions = {
|
|
54197
54816
|
$noop: () => true,
|
|
@@ -54201,7 +54820,7 @@ const comparatorOptions = {
|
|
|
54201
54820
|
$in: (a, b) => inOperator(a, b),
|
|
54202
54821
|
$nin: (a, b) => !inOperator(a, b),
|
|
54203
54822
|
$gt: (a, b) => greaterThan(a, b),
|
|
54204
|
-
$lt: (a, b) => !
|
|
54823
|
+
$lt: (a, b) => !greaterThanOrEqual(a, b),
|
|
54205
54824
|
$ne: (a, b) => !equalsComparator(a, b),
|
|
54206
54825
|
$gte: (a, b) => greaterThanOrEqual(a, b),
|
|
54207
54826
|
$lte: (a, b) => lessThanOrEqual(a, b),
|
|
@@ -55561,16 +56180,45 @@ const SUPPORTED_PUBLIC_KEY_TYPES = {
|
|
|
55561
56180
|
'JsonWebKey2020'
|
|
55562
56181
|
]
|
|
55563
56182
|
};
|
|
56183
|
+
var ProtocolVersion;
|
|
56184
|
+
(function (ProtocolVersion) {
|
|
56185
|
+
ProtocolVersion["V1"] = "iden3comm/v1";
|
|
56186
|
+
})(ProtocolVersion || (ProtocolVersion = {}));
|
|
56187
|
+
var AcceptAuthCircuits;
|
|
56188
|
+
(function (AcceptAuthCircuits) {
|
|
56189
|
+
AcceptAuthCircuits["AuthV2"] = "authV2";
|
|
56190
|
+
AcceptAuthCircuits["AuthV3"] = "authV3";
|
|
56191
|
+
})(AcceptAuthCircuits || (AcceptAuthCircuits = {}));
|
|
56192
|
+
var AcceptJwzAlgorithms;
|
|
56193
|
+
(function (AcceptJwzAlgorithms) {
|
|
56194
|
+
AcceptJwzAlgorithms["Groth16"] = "groth16";
|
|
56195
|
+
})(AcceptJwzAlgorithms || (AcceptJwzAlgorithms = {}));
|
|
56196
|
+
var AcceptJwsAlgorithms;
|
|
56197
|
+
(function (AcceptJwsAlgorithms) {
|
|
56198
|
+
AcceptJwsAlgorithms["ES256K"] = "ES256K";
|
|
56199
|
+
AcceptJwsAlgorithms["ES256KR"] = "ES256K-R";
|
|
56200
|
+
})(AcceptJwsAlgorithms || (AcceptJwsAlgorithms = {}));
|
|
56201
|
+
const defaultAcceptProfile = {
|
|
56202
|
+
protocolVersion: ProtocolVersion.V1,
|
|
56203
|
+
env: MediaType.ZKPMessage,
|
|
56204
|
+
circuits: [AcceptAuthCircuits.AuthV2],
|
|
56205
|
+
alg: [AcceptJwzAlgorithms.Groth16]
|
|
56206
|
+
};
|
|
55564
56207
|
const DEFAULT_PROOF_VERIFY_DELAY = 1 * 60 * 60 * 1000; // 1 hour
|
|
55565
56208
|
const DEFAULT_AUTH_VERIFY_DELAY = 5 * 60 * 1000; // 5 minutes
|
|
55566
56209
|
|
|
55567
56210
|
var constants = /*#__PURE__*/Object.freeze({
|
|
55568
56211
|
__proto__: null,
|
|
56212
|
+
get AcceptAuthCircuits () { return AcceptAuthCircuits; },
|
|
56213
|
+
get AcceptJwsAlgorithms () { return AcceptJwsAlgorithms; },
|
|
56214
|
+
get AcceptJwzAlgorithms () { return AcceptJwzAlgorithms; },
|
|
55569
56215
|
DEFAULT_AUTH_VERIFY_DELAY: DEFAULT_AUTH_VERIFY_DELAY,
|
|
55570
56216
|
DEFAULT_PROOF_VERIFY_DELAY: DEFAULT_PROOF_VERIFY_DELAY,
|
|
55571
56217
|
get MediaType () { return MediaType; },
|
|
55572
56218
|
PROTOCOL_MESSAGE_TYPE: PROTOCOL_MESSAGE_TYPE,
|
|
55573
|
-
|
|
56219
|
+
get ProtocolVersion () { return ProtocolVersion; },
|
|
56220
|
+
SUPPORTED_PUBLIC_KEY_TYPES: SUPPORTED_PUBLIC_KEY_TYPES,
|
|
56221
|
+
defaultAcceptProfile: defaultAcceptProfile
|
|
55574
56222
|
});
|
|
55575
56223
|
|
|
55576
56224
|
/**
|
|
@@ -56694,6 +57342,18 @@ class PackageManager {
|
|
|
56694
57342
|
constructor() {
|
|
56695
57343
|
this.packers = new Map();
|
|
56696
57344
|
}
|
|
57345
|
+
/** {@inheritDoc IPackageManager.isProfileSupported} */
|
|
57346
|
+
isProfileSupported(mediaType, profile) {
|
|
57347
|
+
const p = this.packers.get(mediaType);
|
|
57348
|
+
if (!p) {
|
|
57349
|
+
return false;
|
|
57350
|
+
}
|
|
57351
|
+
return p.isProfileSupported(profile);
|
|
57352
|
+
}
|
|
57353
|
+
/** {@inheritDoc IPackageManager.getSupportedMediaTypes} */
|
|
57354
|
+
getSupportedMediaTypes() {
|
|
57355
|
+
return [...this.packers.keys()];
|
|
57356
|
+
}
|
|
56697
57357
|
/** {@inheritDoc IPackageManager.registerPackers} */
|
|
56698
57358
|
registerPackers(packers) {
|
|
56699
57359
|
packers.forEach((p) => {
|
|
@@ -56766,212 +57426,6 @@ class PackageManager {
|
|
|
56766
57426
|
}
|
|
56767
57427
|
}
|
|
56768
57428
|
|
|
56769
|
-
const { getProvingMethod } = proving;
|
|
56770
|
-
/**
|
|
56771
|
-
* Handler to
|
|
56772
|
-
*
|
|
56773
|
-
* @public
|
|
56774
|
-
* @class DataPrepareHandlerFunc
|
|
56775
|
-
*/
|
|
56776
|
-
class DataPrepareHandlerFunc {
|
|
56777
|
-
/**
|
|
56778
|
-
* Creates an instance of DataPrepareHandlerFunc.
|
|
56779
|
-
* @param {AuthDataPrepareFunc} dataPrepareFunc - function that produces marshaled inputs for auth circuits
|
|
56780
|
-
*/
|
|
56781
|
-
constructor(dataPrepareFunc) {
|
|
56782
|
-
this.dataPrepareFunc = dataPrepareFunc;
|
|
56783
|
-
}
|
|
56784
|
-
/**
|
|
56785
|
-
*
|
|
56786
|
-
*
|
|
56787
|
-
* @param {Uint8Array} hash - challenge that will be signed
|
|
56788
|
-
* @param {DID} did - did of identity that will prepare inputs
|
|
56789
|
-
* @param {CircuitId} circuitId - circuit id
|
|
56790
|
-
* @returns `Promise<Uint8Array>`
|
|
56791
|
-
*/
|
|
56792
|
-
prepare(hash, did, circuitId) {
|
|
56793
|
-
return this.dataPrepareFunc(hash, did, circuitId);
|
|
56794
|
-
}
|
|
56795
|
-
}
|
|
56796
|
-
/**
|
|
56797
|
-
* Handler to verify public signals of authorization circuits
|
|
56798
|
-
*
|
|
56799
|
-
* @public
|
|
56800
|
-
* @class VerificationHandlerFunc
|
|
56801
|
-
*/
|
|
56802
|
-
class VerificationHandlerFunc {
|
|
56803
|
-
/**
|
|
56804
|
-
* Creates an instance of VerificationHandlerFunc.
|
|
56805
|
-
* @param {StateVerificationFunc} stateVerificationFunc - state verification function
|
|
56806
|
-
*/
|
|
56807
|
-
constructor(stateVerificationFunc) {
|
|
56808
|
-
this.stateVerificationFunc = stateVerificationFunc;
|
|
56809
|
-
}
|
|
56810
|
-
/**
|
|
56811
|
-
*
|
|
56812
|
-
*
|
|
56813
|
-
* @param {string} id - id of circuit
|
|
56814
|
-
* @param {Array<string>} pubSignals - signals that must contain user id and state
|
|
56815
|
-
* @returns `Promise<boolean>`
|
|
56816
|
-
*/
|
|
56817
|
-
verify(id, pubSignals, opts) {
|
|
56818
|
-
return this.stateVerificationFunc(id, pubSignals, opts);
|
|
56819
|
-
}
|
|
56820
|
-
}
|
|
56821
|
-
/**
|
|
56822
|
-
* Packer that can pack message to JWZ token,
|
|
56823
|
-
* and unpack and validate JWZ envelope
|
|
56824
|
-
* @public
|
|
56825
|
-
* @class ZKPPacker
|
|
56826
|
-
* @implements implements IPacker interface
|
|
56827
|
-
*/
|
|
56828
|
-
class ZKPPacker {
|
|
56829
|
-
/**
|
|
56830
|
-
* Creates an instance of ZKPPacker.
|
|
56831
|
-
* @param {Map<string, ProvingParams>} provingParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
|
|
56832
|
-
* @param {Map<string, VerificationParams>} verificationParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
|
|
56833
|
-
*/
|
|
56834
|
-
constructor(provingParamsMap, verificationParamsMap, _opts = {
|
|
56835
|
-
acceptedStateTransitionDelay: DEFAULT_AUTH_VERIFY_DELAY
|
|
56836
|
-
}) {
|
|
56837
|
-
this.provingParamsMap = provingParamsMap;
|
|
56838
|
-
this.verificationParamsMap = verificationParamsMap;
|
|
56839
|
-
this._opts = _opts;
|
|
56840
|
-
}
|
|
56841
|
-
/**
|
|
56842
|
-
* Packs a basic message using the specified parameters.
|
|
56843
|
-
* @param msg - The basic message to pack.
|
|
56844
|
-
* @param param - The parameters for the ZKPPacker.
|
|
56845
|
-
* @returns A promise that resolves to a Uint8Array representing the packed message.
|
|
56846
|
-
*/
|
|
56847
|
-
packMessage(msg, param) {
|
|
56848
|
-
return this.pack(byteEncoder.encode(JSON.stringify(msg)), param);
|
|
56849
|
-
}
|
|
56850
|
-
/**
|
|
56851
|
-
* creates JSON Web Zeroknowledge token
|
|
56852
|
-
*
|
|
56853
|
-
* @param {Uint8Array} payload - serialized message
|
|
56854
|
-
* @param {ZKPPackerParams} params - sender id and proving alg are required
|
|
56855
|
-
* @returns `Promise<Uint8Array>`
|
|
56856
|
-
*/
|
|
56857
|
-
async pack(payload, params) {
|
|
56858
|
-
const provingMethod = await getProvingMethod(params.provingMethodAlg);
|
|
56859
|
-
const provingParams = this.provingParamsMap.get(params.provingMethodAlg.toString());
|
|
56860
|
-
if (!provingParams) {
|
|
56861
|
-
throw new Error(ErrNoProvingMethodAlg);
|
|
56862
|
-
}
|
|
56863
|
-
const token = new Token(provingMethod, byteDecoder.decode(payload), (hash, circuitId) => {
|
|
56864
|
-
return provingParams?.dataPreparer?.prepare(hash, params.senderDID, circuitId);
|
|
56865
|
-
});
|
|
56866
|
-
token.setHeader(Header.Type, MediaType.ZKPMessage);
|
|
56867
|
-
const tokenStr = await token.prove(provingParams.provingKey, provingParams.wasm);
|
|
56868
|
-
return byteEncoder.encode(tokenStr);
|
|
56869
|
-
}
|
|
56870
|
-
/**
|
|
56871
|
-
* validate envelope which is jwz token
|
|
56872
|
-
*
|
|
56873
|
-
* @param {Uint8Array} envelope
|
|
56874
|
-
* @returns `Promise<BasicMessage>`
|
|
56875
|
-
*/
|
|
56876
|
-
async unpack(envelope) {
|
|
56877
|
-
const token = await Token.parse(byteDecoder.decode(envelope));
|
|
56878
|
-
const provingMethodAlg = new ProvingMethodAlg(token.alg, token.circuitId);
|
|
56879
|
-
const verificationParams = this.verificationParamsMap.get(provingMethodAlg.toString());
|
|
56880
|
-
if (!verificationParams?.key) {
|
|
56881
|
-
throw new Error(ErrPackedWithUnsupportedCircuit);
|
|
56882
|
-
}
|
|
56883
|
-
const isValid = await token.verify(verificationParams?.key);
|
|
56884
|
-
if (!isValid) {
|
|
56885
|
-
throw new Error(ErrProofIsInvalid);
|
|
56886
|
-
}
|
|
56887
|
-
const verificationResult = await verificationParams?.verificationFn?.verify(token.circuitId, token.zkProof.pub_signals, this._opts);
|
|
56888
|
-
if (!verificationResult) {
|
|
56889
|
-
throw new Error(ErrStateVerificationFailed);
|
|
56890
|
-
}
|
|
56891
|
-
const message = bytesToProtocolMessage(byteEncoder.encode(token.getPayload()));
|
|
56892
|
-
// should throw if error
|
|
56893
|
-
verifySender(token, message);
|
|
56894
|
-
return message;
|
|
56895
|
-
}
|
|
56896
|
-
mediaType() {
|
|
56897
|
-
return MediaType.ZKPMessage;
|
|
56898
|
-
}
|
|
56899
|
-
}
|
|
56900
|
-
const verifySender = async (token, msg) => {
|
|
56901
|
-
switch (token.circuitId) {
|
|
56902
|
-
case CircuitId.AuthV2:
|
|
56903
|
-
{
|
|
56904
|
-
if (!msg.from) {
|
|
56905
|
-
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
56906
|
-
}
|
|
56907
|
-
const authSignals = new AuthV2PubSignals().pubSignalsUnmarshal(byteEncoder.encode(JSON.stringify(token.zkProof.pub_signals)));
|
|
56908
|
-
const did = DID.parseFromId(authSignals.userID);
|
|
56909
|
-
const msgHash = await token.getMessageHash();
|
|
56910
|
-
const challenge = BytesHelper.bytesToInt(msgHash.reverse());
|
|
56911
|
-
if (challenge !== authSignals.challenge) {
|
|
56912
|
-
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
56913
|
-
}
|
|
56914
|
-
if (msg.from !== did.string()) {
|
|
56915
|
-
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
56916
|
-
}
|
|
56917
|
-
}
|
|
56918
|
-
break;
|
|
56919
|
-
default:
|
|
56920
|
-
throw new Error(ErrUnknownCircuitID);
|
|
56921
|
-
}
|
|
56922
|
-
};
|
|
56923
|
-
|
|
56924
|
-
/**
|
|
56925
|
-
* Plain packer just serializes bytes to JSON and adds media type
|
|
56926
|
-
*
|
|
56927
|
-
* @public
|
|
56928
|
-
* @class PlainPacker
|
|
56929
|
-
* @implements implements IPacker interface
|
|
56930
|
-
*/
|
|
56931
|
-
class PlainPacker {
|
|
56932
|
-
/**
|
|
56933
|
-
* Packs a basic message using the specified parameters.
|
|
56934
|
-
*
|
|
56935
|
-
* @param msg - The basic message to pack.
|
|
56936
|
-
* @param param - The packer parameters.
|
|
56937
|
-
* @returns A promise that resolves to a Uint8Array representing the packed message.
|
|
56938
|
-
* @throws An error if the method is not implemented.
|
|
56939
|
-
*/
|
|
56940
|
-
packMessage(msg) {
|
|
56941
|
-
msg.typ = MediaType.PlainMessage;
|
|
56942
|
-
return Promise.resolve(byteEncoder.encode(JSON.stringify(msg)));
|
|
56943
|
-
}
|
|
56944
|
-
/**
|
|
56945
|
-
* Pack returns packed message to transport envelope
|
|
56946
|
-
*
|
|
56947
|
-
* @param {Uint8Array} payload - json message serialized
|
|
56948
|
-
* @param {PlainPackerParams} _params - not used here
|
|
56949
|
-
* @returns `Promise<Uint8Array>`
|
|
56950
|
-
*/
|
|
56951
|
-
async pack(payload) {
|
|
56952
|
-
const msg = JSON.parse(byteDecoder.decode(payload));
|
|
56953
|
-
msg.typ = MediaType.PlainMessage;
|
|
56954
|
-
return Promise.resolve(byteEncoder.encode(JSON.stringify(msg)));
|
|
56955
|
-
}
|
|
56956
|
-
/**
|
|
56957
|
-
* Unpack returns unpacked message from transport envelope
|
|
56958
|
-
*
|
|
56959
|
-
* @param {Uint8Array} envelope - packed envelope (serialized json with media type)
|
|
56960
|
-
* @returns `Promise<BasicMessage>`
|
|
56961
|
-
*/
|
|
56962
|
-
async unpack(envelope) {
|
|
56963
|
-
return JSON.parse(byteDecoder.decode(envelope));
|
|
56964
|
-
}
|
|
56965
|
-
/**
|
|
56966
|
-
* returns media type for plain message
|
|
56967
|
-
*
|
|
56968
|
-
* @returns MediaType
|
|
56969
|
-
*/
|
|
56970
|
-
mediaType() {
|
|
56971
|
-
return MediaType.PlainMessage;
|
|
56972
|
-
}
|
|
56973
|
-
}
|
|
56974
|
-
|
|
56975
57429
|
const DIDAuthenticationSection = 'authentication';
|
|
56976
57430
|
const resolveVerificationMethods = (didDocument) => {
|
|
56977
57431
|
const vms = didDocument.verificationMethod || [];
|
|
@@ -57028,6 +57482,356 @@ const extractPublicKeyBytes = (vm) => {
|
|
|
57028
57482
|
return { publicKeyBytes: null };
|
|
57029
57483
|
};
|
|
57030
57484
|
|
|
57485
|
+
function isProtocolVersion(value) {
|
|
57486
|
+
return Object.values(ProtocolVersion).includes(value);
|
|
57487
|
+
}
|
|
57488
|
+
function isMediaType(value) {
|
|
57489
|
+
return Object.values(MediaType).includes(value);
|
|
57490
|
+
}
|
|
57491
|
+
function isAcceptAuthCircuits(value) {
|
|
57492
|
+
return Object.values(AcceptAuthCircuits).includes(value);
|
|
57493
|
+
}
|
|
57494
|
+
function isAcceptJwsAlgorithms(value) {
|
|
57495
|
+
return Object.values(AcceptJwsAlgorithms).includes(value);
|
|
57496
|
+
}
|
|
57497
|
+
function isAcceptJwzAlgorithms(value) {
|
|
57498
|
+
return Object.values(AcceptJwzAlgorithms).includes(value);
|
|
57499
|
+
}
|
|
57500
|
+
const buildAccept = (profiles) => {
|
|
57501
|
+
const result = [];
|
|
57502
|
+
for (const profile of profiles) {
|
|
57503
|
+
let accept = `${profile.protocolVersion};env=${profile.env}`;
|
|
57504
|
+
if (profile.circuits?.length) {
|
|
57505
|
+
accept += `;circuitId=${profile.circuits.join(',')}`;
|
|
57506
|
+
}
|
|
57507
|
+
if (profile.alg?.length) {
|
|
57508
|
+
accept += `;alg=${profile.alg.join(',')}`;
|
|
57509
|
+
}
|
|
57510
|
+
result.push(accept);
|
|
57511
|
+
}
|
|
57512
|
+
return result;
|
|
57513
|
+
};
|
|
57514
|
+
const parseAcceptProfile = (profile) => {
|
|
57515
|
+
const params = profile.split(';');
|
|
57516
|
+
if (params.length < 2) {
|
|
57517
|
+
throw new Error('Invalid accept profile');
|
|
57518
|
+
}
|
|
57519
|
+
const protocolVersion = params[0].trim();
|
|
57520
|
+
if (!isProtocolVersion(protocolVersion)) {
|
|
57521
|
+
throw new Error(`Protocol version '${protocolVersion}' not supported`);
|
|
57522
|
+
}
|
|
57523
|
+
const envParam = params[1].split('=');
|
|
57524
|
+
if (envParam.length !== 2) {
|
|
57525
|
+
throw new Error(`Invalid accept profile 'env' parameter`);
|
|
57526
|
+
}
|
|
57527
|
+
const env = params[1].split('=')[1].trim();
|
|
57528
|
+
if (!isMediaType(env)) {
|
|
57529
|
+
throw new Error(`Envelop '${env}' not supported`);
|
|
57530
|
+
}
|
|
57531
|
+
const circuitsIndex = params.findIndex((i) => i.includes('circuitId='));
|
|
57532
|
+
if (env !== MediaType.ZKPMessage && circuitsIndex > 0) {
|
|
57533
|
+
throw new Error(`Circuits not supported for env '${env}'`);
|
|
57534
|
+
}
|
|
57535
|
+
let circuits = undefined;
|
|
57536
|
+
if (circuitsIndex > 0) {
|
|
57537
|
+
circuits = params[circuitsIndex]
|
|
57538
|
+
.split('=')[1]
|
|
57539
|
+
.split(',')
|
|
57540
|
+
.map((i) => i.trim())
|
|
57541
|
+
.map((i) => {
|
|
57542
|
+
if (!isAcceptAuthCircuits(i)) {
|
|
57543
|
+
throw new Error(`Circuit '${i}' not supported`);
|
|
57544
|
+
}
|
|
57545
|
+
return i;
|
|
57546
|
+
});
|
|
57547
|
+
}
|
|
57548
|
+
const algIndex = params.findIndex((i) => i.includes('alg='));
|
|
57549
|
+
let alg = undefined;
|
|
57550
|
+
if (algIndex > 0) {
|
|
57551
|
+
if (env === MediaType.ZKPMessage) {
|
|
57552
|
+
alg = params[algIndex]
|
|
57553
|
+
.split('=')[1]
|
|
57554
|
+
.split(',')
|
|
57555
|
+
.map((i) => {
|
|
57556
|
+
i = i.trim();
|
|
57557
|
+
if (!isAcceptJwzAlgorithms(i)) {
|
|
57558
|
+
throw new Error(`Algorithm '${i}' not supported for '${env}'`);
|
|
57559
|
+
}
|
|
57560
|
+
return i;
|
|
57561
|
+
});
|
|
57562
|
+
}
|
|
57563
|
+
else if (env === MediaType.SignedMessage) {
|
|
57564
|
+
alg = params[algIndex]
|
|
57565
|
+
.split('=')[1]
|
|
57566
|
+
.split(',')
|
|
57567
|
+
.map((i) => {
|
|
57568
|
+
i = i.trim();
|
|
57569
|
+
if (!isAcceptJwsAlgorithms(i)) {
|
|
57570
|
+
throw new Error(`Algorithm '${i}' not supported for '${env}'`);
|
|
57571
|
+
}
|
|
57572
|
+
return i;
|
|
57573
|
+
});
|
|
57574
|
+
}
|
|
57575
|
+
else {
|
|
57576
|
+
throw new Error(`Algorithm not supported for '${env}'`);
|
|
57577
|
+
}
|
|
57578
|
+
}
|
|
57579
|
+
return {
|
|
57580
|
+
protocolVersion,
|
|
57581
|
+
env,
|
|
57582
|
+
circuits,
|
|
57583
|
+
alg
|
|
57584
|
+
};
|
|
57585
|
+
};
|
|
57586
|
+
|
|
57587
|
+
const { getProvingMethod } = proving;
|
|
57588
|
+
/**
|
|
57589
|
+
* Handler to
|
|
57590
|
+
*
|
|
57591
|
+
* @public
|
|
57592
|
+
* @class DataPrepareHandlerFunc
|
|
57593
|
+
*/
|
|
57594
|
+
class DataPrepareHandlerFunc {
|
|
57595
|
+
/**
|
|
57596
|
+
* Creates an instance of DataPrepareHandlerFunc.
|
|
57597
|
+
* @param {AuthDataPrepareFunc} dataPrepareFunc - function that produces marshaled inputs for auth circuits
|
|
57598
|
+
*/
|
|
57599
|
+
constructor(dataPrepareFunc) {
|
|
57600
|
+
this.dataPrepareFunc = dataPrepareFunc;
|
|
57601
|
+
}
|
|
57602
|
+
/**
|
|
57603
|
+
*
|
|
57604
|
+
*
|
|
57605
|
+
* @param {Uint8Array} hash - challenge that will be signed
|
|
57606
|
+
* @param {DID} did - did of identity that will prepare inputs
|
|
57607
|
+
* @param {CircuitId} circuitId - circuit id
|
|
57608
|
+
* @returns `Promise<Uint8Array>`
|
|
57609
|
+
*/
|
|
57610
|
+
prepare(hash, did, circuitId) {
|
|
57611
|
+
return this.dataPrepareFunc(hash, did, circuitId);
|
|
57612
|
+
}
|
|
57613
|
+
}
|
|
57614
|
+
/**
|
|
57615
|
+
* Handler to verify public signals of authorization circuits
|
|
57616
|
+
*
|
|
57617
|
+
* @public
|
|
57618
|
+
* @class VerificationHandlerFunc
|
|
57619
|
+
*/
|
|
57620
|
+
class VerificationHandlerFunc {
|
|
57621
|
+
/**
|
|
57622
|
+
* Creates an instance of VerificationHandlerFunc.
|
|
57623
|
+
* @param {StateVerificationFunc} stateVerificationFunc - state verification function
|
|
57624
|
+
*/
|
|
57625
|
+
constructor(stateVerificationFunc) {
|
|
57626
|
+
this.stateVerificationFunc = stateVerificationFunc;
|
|
57627
|
+
}
|
|
57628
|
+
/**
|
|
57629
|
+
*
|
|
57630
|
+
*
|
|
57631
|
+
* @param {string} id - id of circuit
|
|
57632
|
+
* @param {Array<string>} pubSignals - signals that must contain user id and state
|
|
57633
|
+
* @returns `Promise<boolean>`
|
|
57634
|
+
*/
|
|
57635
|
+
verify(id, pubSignals, opts) {
|
|
57636
|
+
return this.stateVerificationFunc(id, pubSignals, opts);
|
|
57637
|
+
}
|
|
57638
|
+
}
|
|
57639
|
+
/**
|
|
57640
|
+
* Packer that can pack message to JWZ token,
|
|
57641
|
+
* and unpack and validate JWZ envelope
|
|
57642
|
+
* @public
|
|
57643
|
+
* @class ZKPPacker
|
|
57644
|
+
* @implements implements IPacker interface
|
|
57645
|
+
*/
|
|
57646
|
+
class ZKPPacker {
|
|
57647
|
+
/**
|
|
57648
|
+
* Creates an instance of ZKPPacker.
|
|
57649
|
+
* @param {Map<string, ProvingParams>} provingParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
|
|
57650
|
+
* @param {Map<string, VerificationParams>} verificationParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
|
|
57651
|
+
*/
|
|
57652
|
+
constructor(provingParamsMap, verificationParamsMap, _opts = {
|
|
57653
|
+
acceptedStateTransitionDelay: DEFAULT_AUTH_VERIFY_DELAY
|
|
57654
|
+
}) {
|
|
57655
|
+
this.provingParamsMap = provingParamsMap;
|
|
57656
|
+
this.verificationParamsMap = verificationParamsMap;
|
|
57657
|
+
this._opts = _opts;
|
|
57658
|
+
}
|
|
57659
|
+
/**
|
|
57660
|
+
* Packs a basic message using the specified parameters.
|
|
57661
|
+
* @param msg - The basic message to pack.
|
|
57662
|
+
* @param param - The parameters for the ZKPPacker.
|
|
57663
|
+
* @returns A promise that resolves to a Uint8Array representing the packed message.
|
|
57664
|
+
*/
|
|
57665
|
+
packMessage(msg, param) {
|
|
57666
|
+
return this.pack(byteEncoder.encode(JSON.stringify(msg)), param);
|
|
57667
|
+
}
|
|
57668
|
+
/**
|
|
57669
|
+
* creates JSON Web Zeroknowledge token
|
|
57670
|
+
*
|
|
57671
|
+
* @param {Uint8Array} payload - serialized message
|
|
57672
|
+
* @param {ZKPPackerParams} params - sender id and proving alg are required
|
|
57673
|
+
* @returns `Promise<Uint8Array>`
|
|
57674
|
+
*/
|
|
57675
|
+
async pack(payload, params) {
|
|
57676
|
+
const provingMethod = await getProvingMethod(params.provingMethodAlg);
|
|
57677
|
+
const provingParams = this.provingParamsMap.get(params.provingMethodAlg.toString());
|
|
57678
|
+
if (!provingParams) {
|
|
57679
|
+
throw new Error(ErrNoProvingMethodAlg);
|
|
57680
|
+
}
|
|
57681
|
+
const token = new Token(provingMethod, byteDecoder.decode(payload), (hash, circuitId) => {
|
|
57682
|
+
return provingParams?.dataPreparer?.prepare(hash, params.senderDID, circuitId);
|
|
57683
|
+
});
|
|
57684
|
+
token.setHeader(Header.Type, MediaType.ZKPMessage);
|
|
57685
|
+
const tokenStr = await token.prove(provingParams.provingKey, provingParams.wasm);
|
|
57686
|
+
return byteEncoder.encode(tokenStr);
|
|
57687
|
+
}
|
|
57688
|
+
/**
|
|
57689
|
+
* validate envelope which is jwz token
|
|
57690
|
+
*
|
|
57691
|
+
* @param {Uint8Array} envelope
|
|
57692
|
+
* @returns `Promise<BasicMessage>`
|
|
57693
|
+
*/
|
|
57694
|
+
async unpack(envelope) {
|
|
57695
|
+
const token = await Token.parse(byteDecoder.decode(envelope));
|
|
57696
|
+
const provingMethodAlg = new ProvingMethodAlg(token.alg, token.circuitId);
|
|
57697
|
+
const verificationParams = this.verificationParamsMap.get(provingMethodAlg.toString());
|
|
57698
|
+
if (!verificationParams?.key) {
|
|
57699
|
+
throw new Error(ErrPackedWithUnsupportedCircuit);
|
|
57700
|
+
}
|
|
57701
|
+
const isValid = await token.verify(verificationParams?.key);
|
|
57702
|
+
if (!isValid) {
|
|
57703
|
+
throw new Error(ErrProofIsInvalid);
|
|
57704
|
+
}
|
|
57705
|
+
const verificationResult = await verificationParams?.verificationFn?.verify(token.circuitId, token.zkProof.pub_signals, this._opts);
|
|
57706
|
+
if (!verificationResult) {
|
|
57707
|
+
throw new Error(ErrStateVerificationFailed);
|
|
57708
|
+
}
|
|
57709
|
+
const message = bytesToProtocolMessage(byteEncoder.encode(token.getPayload()));
|
|
57710
|
+
// should throw if error
|
|
57711
|
+
verifySender(token, message);
|
|
57712
|
+
return message;
|
|
57713
|
+
}
|
|
57714
|
+
mediaType() {
|
|
57715
|
+
return MediaType.ZKPMessage;
|
|
57716
|
+
}
|
|
57717
|
+
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
57718
|
+
getSupportedProfiles() {
|
|
57719
|
+
return [
|
|
57720
|
+
`env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}&circuitIds=${this.getSupportedCircuitIds().join(',')}`
|
|
57721
|
+
];
|
|
57722
|
+
}
|
|
57723
|
+
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
57724
|
+
isProfileSupported(profile) {
|
|
57725
|
+
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
57726
|
+
if (env !== this.mediaType()) {
|
|
57727
|
+
return false;
|
|
57728
|
+
}
|
|
57729
|
+
const supportedCircuitIds = this.getSupportedCircuitIds();
|
|
57730
|
+
const circuitIdSupported = !circuits?.length || circuits.some((c) => supportedCircuitIds.includes(c));
|
|
57731
|
+
const supportedAlgArr = this.getSupportedAlgorithms();
|
|
57732
|
+
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
57733
|
+
return algSupported && circuitIdSupported;
|
|
57734
|
+
}
|
|
57735
|
+
getSupportedAlgorithms() {
|
|
57736
|
+
return [AcceptJwzAlgorithms.Groth16];
|
|
57737
|
+
}
|
|
57738
|
+
getSupportedCircuitIds() {
|
|
57739
|
+
return [AcceptAuthCircuits.AuthV2];
|
|
57740
|
+
}
|
|
57741
|
+
}
|
|
57742
|
+
const verifySender = async (token, msg) => {
|
|
57743
|
+
switch (token.circuitId) {
|
|
57744
|
+
case CircuitId.AuthV2:
|
|
57745
|
+
{
|
|
57746
|
+
if (!msg.from) {
|
|
57747
|
+
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
57748
|
+
}
|
|
57749
|
+
const authSignals = new AuthV2PubSignals().pubSignalsUnmarshal(byteEncoder.encode(JSON.stringify(token.zkProof.pub_signals)));
|
|
57750
|
+
const did = DID.parseFromId(authSignals.userID);
|
|
57751
|
+
const msgHash = await token.getMessageHash();
|
|
57752
|
+
const challenge = BytesHelper.bytesToInt(msgHash.reverse());
|
|
57753
|
+
if (challenge !== authSignals.challenge) {
|
|
57754
|
+
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
57755
|
+
}
|
|
57756
|
+
if (msg.from !== did.string()) {
|
|
57757
|
+
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
57758
|
+
}
|
|
57759
|
+
}
|
|
57760
|
+
break;
|
|
57761
|
+
default:
|
|
57762
|
+
throw new Error(ErrUnknownCircuitID);
|
|
57763
|
+
}
|
|
57764
|
+
};
|
|
57765
|
+
|
|
57766
|
+
/**
|
|
57767
|
+
* Plain packer just serializes bytes to JSON and adds media type
|
|
57768
|
+
*
|
|
57769
|
+
* @public
|
|
57770
|
+
* @class PlainPacker
|
|
57771
|
+
* @implements implements IPacker interface
|
|
57772
|
+
*/
|
|
57773
|
+
class PlainPacker {
|
|
57774
|
+
/**
|
|
57775
|
+
* Packs a basic message using the specified parameters.
|
|
57776
|
+
*
|
|
57777
|
+
* @param msg - The basic message to pack.
|
|
57778
|
+
* @param param - The packer parameters.
|
|
57779
|
+
* @returns A promise that resolves to a Uint8Array representing the packed message.
|
|
57780
|
+
* @throws An error if the method is not implemented.
|
|
57781
|
+
*/
|
|
57782
|
+
packMessage(msg) {
|
|
57783
|
+
msg.typ = MediaType.PlainMessage;
|
|
57784
|
+
return Promise.resolve(byteEncoder.encode(JSON.stringify(msg)));
|
|
57785
|
+
}
|
|
57786
|
+
/**
|
|
57787
|
+
* Pack returns packed message to transport envelope
|
|
57788
|
+
*
|
|
57789
|
+
* @param {Uint8Array} payload - json message serialized
|
|
57790
|
+
* @param {PlainPackerParams} _params - not used here
|
|
57791
|
+
* @returns `Promise<Uint8Array>`
|
|
57792
|
+
*/
|
|
57793
|
+
async pack(payload) {
|
|
57794
|
+
const msg = JSON.parse(byteDecoder.decode(payload));
|
|
57795
|
+
msg.typ = MediaType.PlainMessage;
|
|
57796
|
+
return Promise.resolve(byteEncoder.encode(JSON.stringify(msg)));
|
|
57797
|
+
}
|
|
57798
|
+
/**
|
|
57799
|
+
* Unpack returns unpacked message from transport envelope
|
|
57800
|
+
*
|
|
57801
|
+
* @param {Uint8Array} envelope - packed envelope (serialized json with media type)
|
|
57802
|
+
* @returns `Promise<BasicMessage>`
|
|
57803
|
+
*/
|
|
57804
|
+
async unpack(envelope) {
|
|
57805
|
+
return JSON.parse(byteDecoder.decode(envelope));
|
|
57806
|
+
}
|
|
57807
|
+
/**
|
|
57808
|
+
* returns media type for plain message
|
|
57809
|
+
*
|
|
57810
|
+
* @returns MediaType
|
|
57811
|
+
*/
|
|
57812
|
+
mediaType() {
|
|
57813
|
+
return MediaType.PlainMessage;
|
|
57814
|
+
}
|
|
57815
|
+
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
57816
|
+
getSupportedProfiles() {
|
|
57817
|
+
return [`env=${this.mediaType()}`];
|
|
57818
|
+
}
|
|
57819
|
+
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
57820
|
+
isProfileSupported(profile) {
|
|
57821
|
+
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
57822
|
+
if (env !== this.mediaType()) {
|
|
57823
|
+
return false;
|
|
57824
|
+
}
|
|
57825
|
+
if (circuits) {
|
|
57826
|
+
throw new Error(`Circuits are not supported for ${env} media type`);
|
|
57827
|
+
}
|
|
57828
|
+
if (alg) {
|
|
57829
|
+
throw new Error(`Algorithms are not supported for ${env} media type`);
|
|
57830
|
+
}
|
|
57831
|
+
return true;
|
|
57832
|
+
}
|
|
57833
|
+
}
|
|
57834
|
+
|
|
57031
57835
|
/**
|
|
57032
57836
|
* Packer that can pack message to JWZ token,
|
|
57033
57837
|
* and unpack and validate JWZ envelope
|
|
@@ -57106,6 +57910,26 @@ class JWSPacker {
|
|
|
57106
57910
|
mediaType() {
|
|
57107
57911
|
return MediaType.SignedMessage;
|
|
57108
57912
|
}
|
|
57913
|
+
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
57914
|
+
getSupportedProfiles() {
|
|
57915
|
+
return [`env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}`];
|
|
57916
|
+
}
|
|
57917
|
+
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
57918
|
+
isProfileSupported(profile) {
|
|
57919
|
+
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
57920
|
+
if (env !== this.mediaType()) {
|
|
57921
|
+
return false;
|
|
57922
|
+
}
|
|
57923
|
+
if (circuits) {
|
|
57924
|
+
throw new Error(`Circuits are not supported for ${env} media type`);
|
|
57925
|
+
}
|
|
57926
|
+
const supportedAlgArr = this.getSupportedAlgorithms();
|
|
57927
|
+
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
57928
|
+
return algSupported;
|
|
57929
|
+
}
|
|
57930
|
+
getSupportedAlgorithms() {
|
|
57931
|
+
return [AcceptJwsAlgorithms.ES256K, AcceptJwsAlgorithms.ES256KR];
|
|
57932
|
+
}
|
|
57109
57933
|
async resolveDidDoc(from) {
|
|
57110
57934
|
let didDocument;
|
|
57111
57935
|
try {
|
|
@@ -57260,6 +58084,16 @@ const processZeroKnowledgeProofRequests = async (to, requests, from, proofServic
|
|
|
57260
58084
|
}
|
|
57261
58085
|
return zkpResponses;
|
|
57262
58086
|
};
|
|
58087
|
+
/**
|
|
58088
|
+
* Verifies that the expires_time field of a message is not in the past. Throws an error if it is.
|
|
58089
|
+
*
|
|
58090
|
+
* @param message - Basic message to verify.
|
|
58091
|
+
*/
|
|
58092
|
+
const verifyExpiresTime = (message) => {
|
|
58093
|
+
if (message?.expires_time && message.expires_time < getUnixTimestamp(new Date())) {
|
|
58094
|
+
throw new Error('Message expired');
|
|
58095
|
+
}
|
|
58096
|
+
};
|
|
57263
58097
|
|
|
57264
58098
|
/**
|
|
57265
58099
|
* Base implementation of protocol message handler
|
|
@@ -57275,6 +58109,9 @@ class AbstractMessageHandler {
|
|
|
57275
58109
|
return messageHandler;
|
|
57276
58110
|
}
|
|
57277
58111
|
async handle(message, context) {
|
|
58112
|
+
if (!context.allowExpiredMessages) {
|
|
58113
|
+
verifyExpiresTime(message);
|
|
58114
|
+
}
|
|
57278
58115
|
if (this.nextMessageHandler)
|
|
57279
58116
|
return this.nextMessageHandler.handle(message, context);
|
|
57280
58117
|
return Promise.reject('Message handler not provided or message not supported');
|
|
@@ -57367,10 +58204,11 @@ class MessageHandler {
|
|
|
57367
58204
|
* @param {string} reason - reason to request proof
|
|
57368
58205
|
* @param {string} sender - sender did
|
|
57369
58206
|
* @param {string} callbackUrl - callback that user should use to send response
|
|
58207
|
+
* @param {AuthorizationRequestCreateOptions} opts - authorization request options
|
|
57370
58208
|
* @returns `Promise<AuthorizationRequestMessage>`
|
|
57371
58209
|
*/
|
|
57372
|
-
function createAuthorizationRequest(reason, sender, callbackUrl) {
|
|
57373
|
-
return createAuthorizationRequestWithMessage(reason, '', sender, callbackUrl);
|
|
58210
|
+
function createAuthorizationRequest(reason, sender, callbackUrl, opts) {
|
|
58211
|
+
return createAuthorizationRequestWithMessage(reason, '', sender, callbackUrl, opts);
|
|
57374
58212
|
}
|
|
57375
58213
|
/**
|
|
57376
58214
|
* createAuthorizationRequestWithMessage is a function to create protocol authorization request with explicit message to sign
|
|
@@ -57378,9 +58216,10 @@ function createAuthorizationRequest(reason, sender, callbackUrl) {
|
|
|
57378
58216
|
* @param {string} message - message to sign in the response
|
|
57379
58217
|
* @param {string} sender - sender did
|
|
57380
58218
|
* @param {string} callbackUrl - callback that user should use to send response
|
|
58219
|
+
* @param {AuthorizationRequestCreateOptions} opts - authorization request options
|
|
57381
58220
|
* @returns `Promise<AuthorizationRequestMessage>`
|
|
57382
58221
|
*/
|
|
57383
|
-
function createAuthorizationRequestWithMessage(reason, message, sender, callbackUrl) {
|
|
58222
|
+
function createAuthorizationRequestWithMessage(reason, message, sender, callbackUrl, opts) {
|
|
57384
58223
|
const uuidv4 = v4();
|
|
57385
58224
|
const request = {
|
|
57386
58225
|
id: uuidv4,
|
|
@@ -57389,11 +58228,14 @@ function createAuthorizationRequestWithMessage(reason, message, sender, callback
|
|
|
57389
58228
|
typ: MediaType.PlainMessage,
|
|
57390
58229
|
type: PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
|
|
57391
58230
|
body: {
|
|
58231
|
+
accept: opts?.accept,
|
|
57392
58232
|
reason: reason,
|
|
57393
58233
|
message: message,
|
|
57394
58234
|
callbackUrl: callbackUrl,
|
|
57395
|
-
scope: []
|
|
57396
|
-
}
|
|
58235
|
+
scope: opts?.scope ?? []
|
|
58236
|
+
},
|
|
58237
|
+
created_time: getUnixTimestamp(new Date()),
|
|
58238
|
+
expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined
|
|
57397
58239
|
};
|
|
57398
58240
|
return request;
|
|
57399
58241
|
}
|
|
@@ -57452,17 +58294,18 @@ class AuthHandler extends AbstractMessageHandler {
|
|
|
57452
58294
|
}
|
|
57453
58295
|
// override sender did if it's explicitly specified in the auth request
|
|
57454
58296
|
const to = authRequest.to ? DID.parse(authRequest.to) : ctx.senderDid;
|
|
57455
|
-
const mediaType = ctx.mediaType || MediaType.ZKPMessage;
|
|
57456
58297
|
const guid = v4();
|
|
57457
58298
|
if (!authRequest.from) {
|
|
57458
58299
|
throw new Error('auth request should contain from field');
|
|
57459
58300
|
}
|
|
58301
|
+
const responseType = PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE;
|
|
58302
|
+
const mediaType = this.getSupportedMediaTypeByProfile(ctx, responseType, authRequest.body.accept);
|
|
57460
58303
|
const from = DID.parse(authRequest.from);
|
|
57461
58304
|
const responseScope = await processZeroKnowledgeProofRequests(to, authRequest?.body.scope, from, this._proofService, { mediaType, supportedCircuits: this._supportedCircuits });
|
|
57462
58305
|
return {
|
|
57463
58306
|
id: guid,
|
|
57464
|
-
typ:
|
|
57465
|
-
type:
|
|
58307
|
+
typ: mediaType,
|
|
58308
|
+
type: responseType,
|
|
57466
58309
|
thid: authRequest.thid ?? guid,
|
|
57467
58310
|
body: {
|
|
57468
58311
|
message: authRequest?.body?.message,
|
|
@@ -57477,6 +58320,9 @@ class AuthHandler extends AbstractMessageHandler {
|
|
|
57477
58320
|
*/
|
|
57478
58321
|
async handleAuthorizationRequest(did, request, opts) {
|
|
57479
58322
|
const authRequest = await this.parseAuthorizationRequest(request);
|
|
58323
|
+
if (!opts?.allowExpiredMessages) {
|
|
58324
|
+
verifyExpiresTime(authRequest);
|
|
58325
|
+
}
|
|
57480
58326
|
if (!opts) {
|
|
57481
58327
|
opts = {
|
|
57482
58328
|
mediaType: MediaType.ZKPMessage
|
|
@@ -57566,6 +58412,9 @@ class AuthHandler extends AbstractMessageHandler {
|
|
|
57566
58412
|
* @inheritdoc IAuthHandler#handleAuthorizationResponse
|
|
57567
58413
|
*/
|
|
57568
58414
|
async handleAuthorizationResponse(response, request, opts) {
|
|
58415
|
+
if (!opts?.allowExpiredMessages) {
|
|
58416
|
+
verifyExpiresTime(response);
|
|
58417
|
+
}
|
|
57569
58418
|
const authResp = (await this.handleAuthResponse(response, {
|
|
57570
58419
|
request,
|
|
57571
58420
|
acceptedStateTransitionDelay: opts?.acceptedStateTransitionDelay,
|
|
@@ -57599,6 +58448,37 @@ class AuthHandler extends AbstractMessageHandler {
|
|
|
57599
58448
|
}
|
|
57600
58449
|
}
|
|
57601
58450
|
}
|
|
58451
|
+
getSupportedMediaTypeByProfile(ctx, responseType, profile) {
|
|
58452
|
+
let mediaType;
|
|
58453
|
+
if (profile?.length) {
|
|
58454
|
+
const supportedMediaTypes = [];
|
|
58455
|
+
for (const acceptProfile of profile) {
|
|
58456
|
+
// 1. check protocol version
|
|
58457
|
+
const { protocolVersion, env } = parseAcceptProfile(acceptProfile);
|
|
58458
|
+
const responseTypeVersion = Number(responseType.split('/').at(-2));
|
|
58459
|
+
if (protocolVersion !== ProtocolVersion.V1 ||
|
|
58460
|
+
(protocolVersion === ProtocolVersion.V1 &&
|
|
58461
|
+
(responseTypeVersion < 1 || responseTypeVersion >= 2))) {
|
|
58462
|
+
continue;
|
|
58463
|
+
}
|
|
58464
|
+
// 2. check packer support
|
|
58465
|
+
if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
|
|
58466
|
+
supportedMediaTypes.push(env);
|
|
58467
|
+
}
|
|
58468
|
+
}
|
|
58469
|
+
if (!supportedMediaTypes.length) {
|
|
58470
|
+
throw new Error('no packer with profile which meets `accept` header requirements');
|
|
58471
|
+
}
|
|
58472
|
+
mediaType = supportedMediaTypes[0];
|
|
58473
|
+
if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
|
|
58474
|
+
mediaType = ctx.mediaType;
|
|
58475
|
+
}
|
|
58476
|
+
}
|
|
58477
|
+
else {
|
|
58478
|
+
mediaType = ctx.mediaType || MediaType.ZKPMessage;
|
|
58479
|
+
}
|
|
58480
|
+
return mediaType;
|
|
58481
|
+
}
|
|
57602
58482
|
}
|
|
57603
58483
|
|
|
57604
58484
|
/**
|
|
@@ -57715,6 +58595,9 @@ class FetchHandler extends AbstractMessageHandler {
|
|
|
57715
58595
|
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
57716
58596
|
}
|
|
57717
58597
|
const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
|
|
58598
|
+
if (!opts?.allowExpiredMessages) {
|
|
58599
|
+
verifyExpiresTime(offerMessage);
|
|
58600
|
+
}
|
|
57718
58601
|
const result = await this.handleOfferMessage(offerMessage, {
|
|
57719
58602
|
mediaType: opts?.mediaType,
|
|
57720
58603
|
headers: opts?.headers,
|
|
@@ -57762,8 +58645,11 @@ class FetchHandler extends AbstractMessageHandler {
|
|
|
57762
58645
|
/**
|
|
57763
58646
|
* @inheritdoc IFetchHandler#handleCredentialFetchRequest
|
|
57764
58647
|
*/
|
|
57765
|
-
async handleCredentialFetchRequest(envelope) {
|
|
58648
|
+
async handleCredentialFetchRequest(envelope, opts) {
|
|
57766
58649
|
const msgRequest = await FetchHandler.unpackMessage(this._packerMgr, envelope, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE);
|
|
58650
|
+
if (!opts?.allowExpiredMessages) {
|
|
58651
|
+
verifyExpiresTime(msgRequest);
|
|
58652
|
+
}
|
|
57767
58653
|
const request = await this.handleFetchRequest(msgRequest);
|
|
57768
58654
|
return this._packerMgr.pack(MediaType.PlainMessage, byteEncoder.encode(JSON.stringify(request)), {});
|
|
57769
58655
|
}
|
|
@@ -57780,8 +58666,11 @@ class FetchHandler extends AbstractMessageHandler {
|
|
|
57780
58666
|
/**
|
|
57781
58667
|
* @inheritdoc IFetchHandler#handleIssuanceResponseMessage
|
|
57782
58668
|
*/
|
|
57783
|
-
async handleIssuanceResponseMessage(envelop) {
|
|
58669
|
+
async handleIssuanceResponseMessage(envelop, opts) {
|
|
57784
58670
|
const issuanceMsg = await FetchHandler.unpackMessage(this._packerMgr, envelop, PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE);
|
|
58671
|
+
if (!opts?.allowExpiredMessages) {
|
|
58672
|
+
verifyExpiresTime(issuanceMsg);
|
|
58673
|
+
}
|
|
57785
58674
|
await this.handleIssuanceResponseMsg(issuanceMsg);
|
|
57786
58675
|
return Uint8Array.from([]);
|
|
57787
58676
|
}
|
|
@@ -57901,7 +58790,8 @@ class ContractRequestHandler extends AbstractMessageHandler {
|
|
|
57901
58790
|
body: {
|
|
57902
58791
|
transaction_data: request.body.transaction_data,
|
|
57903
58792
|
scope: []
|
|
57904
|
-
}
|
|
58793
|
+
},
|
|
58794
|
+
created_time: getUnixTimestamp(new Date())
|
|
57905
58795
|
};
|
|
57906
58796
|
for (const [txHash, zkpResponses] of txHashToZkpResponseMap) {
|
|
57907
58797
|
for (const zkpResponse of zkpResponses) {
|
|
@@ -57925,6 +58815,9 @@ class ContractRequestHandler extends AbstractMessageHandler {
|
|
|
57925
58815
|
*/
|
|
57926
58816
|
async handleContractInvokeRequest(did, request, opts) {
|
|
57927
58817
|
const ciRequest = await this.parseContractInvokeRequest(request);
|
|
58818
|
+
if (!opts.allowExpiredMessages) {
|
|
58819
|
+
verifyExpiresTime(ciRequest);
|
|
58820
|
+
}
|
|
57928
58821
|
if (ciRequest.body.transaction_data.method_id !== FunctionSignatures.SubmitZKPResponseV1) {
|
|
57929
58822
|
throw new Error(`please use handle method to work with other method ids`);
|
|
57930
58823
|
}
|
|
@@ -58103,6 +58996,9 @@ class RevocationStatusHandler extends AbstractMessageHandler {
|
|
|
58103
58996
|
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
58104
58997
|
}
|
|
58105
58998
|
const rsRequest = await this.parseRevocationStatusRequest(request);
|
|
58999
|
+
if (!opts.allowExpiredMessages) {
|
|
59000
|
+
verifyExpiresTime(rsRequest);
|
|
59001
|
+
}
|
|
58106
59002
|
const response = await this.handleRevocationStatusRequestMessage(rsRequest, {
|
|
58107
59003
|
senderDid: did,
|
|
58108
59004
|
mediaType: opts.mediaType,
|
|
@@ -58142,7 +59038,9 @@ function createProposalRequest(sender, receiver, opts) {
|
|
|
58142
59038
|
to: receiver.string(),
|
|
58143
59039
|
typ: MediaType.PlainMessage,
|
|
58144
59040
|
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
|
|
58145
|
-
body: opts
|
|
59041
|
+
body: opts,
|
|
59042
|
+
created_time: getUnixTimestamp(new Date()),
|
|
59043
|
+
expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined
|
|
58146
59044
|
};
|
|
58147
59045
|
return request;
|
|
58148
59046
|
}
|
|
@@ -58154,7 +59052,7 @@ function createProposalRequest(sender, receiver, opts) {
|
|
|
58154
59052
|
* @param {Proposal[]} proposals - proposals
|
|
58155
59053
|
* @returns `Promise<ProposalRequestMessage>`
|
|
58156
59054
|
*/
|
|
58157
|
-
function createProposal(sender, receiver, proposals) {
|
|
59055
|
+
function createProposal(sender, receiver, proposals, opts) {
|
|
58158
59056
|
const uuidv4 = v4();
|
|
58159
59057
|
const request = {
|
|
58160
59058
|
id: uuidv4,
|
|
@@ -58165,7 +59063,9 @@ function createProposal(sender, receiver, proposals) {
|
|
|
58165
59063
|
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_MESSAGE_TYPE,
|
|
58166
59064
|
body: {
|
|
58167
59065
|
proposals: proposals || []
|
|
58168
|
-
}
|
|
59066
|
+
},
|
|
59067
|
+
created_time: getUnixTimestamp(new Date()),
|
|
59068
|
+
expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined
|
|
58169
59069
|
};
|
|
58170
59070
|
return request;
|
|
58171
59071
|
}
|
|
@@ -58303,6 +59203,9 @@ class CredentialProposalHandler extends AbstractMessageHandler {
|
|
|
58303
59203
|
if (!proposalRequest.from) {
|
|
58304
59204
|
throw new Error(`failed request. empty 'from' field`);
|
|
58305
59205
|
}
|
|
59206
|
+
if (!opts?.allowExpiredMessages) {
|
|
59207
|
+
verifyExpiresTime(proposalRequest);
|
|
59208
|
+
}
|
|
58306
59209
|
const senderDID = DID.parse(proposalRequest.from);
|
|
58307
59210
|
const message = await this.handleProposalRequestMessage(proposalRequest);
|
|
58308
59211
|
const response = byteEncoder.encode(JSON.stringify(message));
|
|
@@ -58320,6 +59223,9 @@ class CredentialProposalHandler extends AbstractMessageHandler {
|
|
|
58320
59223
|
* @inheritdoc ICredentialProposalHandler#handleProposal
|
|
58321
59224
|
*/
|
|
58322
59225
|
async handleProposal(proposal, opts) {
|
|
59226
|
+
if (!opts?.allowExpiredMessages) {
|
|
59227
|
+
verifyExpiresTime(proposal);
|
|
59228
|
+
}
|
|
58323
59229
|
if (opts?.proposalRequest && opts.proposalRequest.from !== proposal.to) {
|
|
58324
59230
|
throw new Error(`sender of the request is not a target of response - expected ${opts.proposalRequest.from}, given ${proposal.to}`);
|
|
58325
59231
|
}
|
|
@@ -58336,7 +59242,7 @@ class CredentialProposalHandler extends AbstractMessageHandler {
|
|
|
58336
59242
|
* @param {PaymentRequestInfo[]} payments - payments
|
|
58337
59243
|
* @returns `PaymentRequestMessage`
|
|
58338
59244
|
*/
|
|
58339
|
-
function createPaymentRequest(sender, receiver, agent, payments) {
|
|
59245
|
+
function createPaymentRequest(sender, receiver, agent, payments, opts) {
|
|
58340
59246
|
const uuidv4 = v4();
|
|
58341
59247
|
const request = {
|
|
58342
59248
|
id: uuidv4,
|
|
@@ -58348,19 +59254,57 @@ function createPaymentRequest(sender, receiver, agent, payments) {
|
|
|
58348
59254
|
body: {
|
|
58349
59255
|
agent,
|
|
58350
59256
|
payments
|
|
58351
|
-
}
|
|
59257
|
+
},
|
|
59258
|
+
created_time: getUnixTimestamp(new Date()),
|
|
59259
|
+
expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined
|
|
58352
59260
|
};
|
|
58353
59261
|
return request;
|
|
58354
59262
|
}
|
|
59263
|
+
async function verifyEIP712TypedData(data, resolver) {
|
|
59264
|
+
const paymentData = data.type === PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
59265
|
+
? {
|
|
59266
|
+
recipient: data.recipient,
|
|
59267
|
+
amount: data.amount,
|
|
59268
|
+
expirationDate: new Date(data.expirationDate).getTime(),
|
|
59269
|
+
nonce: data.nonce,
|
|
59270
|
+
metadata: '0x'
|
|
59271
|
+
}
|
|
59272
|
+
: {
|
|
59273
|
+
tokenAddress: data.tokenAddress,
|
|
59274
|
+
recipient: data.recipient,
|
|
59275
|
+
amount: data.amount,
|
|
59276
|
+
expirationDate: new Date(data.expirationDate).getTime(),
|
|
59277
|
+
nonce: data.nonce,
|
|
59278
|
+
metadata: '0x'
|
|
59279
|
+
};
|
|
59280
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
59281
|
+
const typesFetchResult = await fetch(proof.eip712.types);
|
|
59282
|
+
const types = await typesFetchResult.json();
|
|
59283
|
+
delete types.EIP712Domain;
|
|
59284
|
+
const recovered = verifyTypedData(proof.eip712.domain, types, paymentData, proof.proofValue);
|
|
59285
|
+
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
59286
|
+
if (didDocument?.verificationMethod) {
|
|
59287
|
+
for (const verificationMethod of didDocument.verificationMethod) {
|
|
59288
|
+
if (verificationMethod.blockchainAccountId?.split(':').slice(-1)[0].toLowerCase() ===
|
|
59289
|
+
recovered.toLowerCase()) {
|
|
59290
|
+
return recovered;
|
|
59291
|
+
}
|
|
59292
|
+
}
|
|
59293
|
+
}
|
|
59294
|
+
else {
|
|
59295
|
+
throw new Error('failed request. issuer DIDDocument does not contain any verificationMethods');
|
|
59296
|
+
}
|
|
59297
|
+
throw new Error(`failed request. no matching verificationMethod`);
|
|
59298
|
+
}
|
|
58355
59299
|
/**
|
|
58356
59300
|
* @beta
|
|
58357
59301
|
* createPayment is a function to create protocol payment message
|
|
58358
59302
|
* @param {DID} sender - sender did
|
|
58359
59303
|
* @param {DID} receiver - receiver did
|
|
58360
|
-
* @param {
|
|
59304
|
+
* @param {PaymentMessageBody} body - payments
|
|
58361
59305
|
* @returns `PaymentMessage`
|
|
58362
59306
|
*/
|
|
58363
|
-
function createPayment(sender, receiver, payments) {
|
|
59307
|
+
function createPayment(sender, receiver, payments, opts) {
|
|
58364
59308
|
const uuidv4 = v4();
|
|
58365
59309
|
const request = {
|
|
58366
59310
|
id: uuidv4,
|
|
@@ -58371,7 +59315,9 @@ function createPayment(sender, receiver, payments) {
|
|
|
58371
59315
|
type: PROTOCOL_MESSAGE_TYPE.PAYMENT_MESSAGE_TYPE,
|
|
58372
59316
|
body: {
|
|
58373
59317
|
payments
|
|
58374
|
-
}
|
|
59318
|
+
},
|
|
59319
|
+
created_time: getUnixTimestamp(new Date()),
|
|
59320
|
+
expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined
|
|
58375
59321
|
};
|
|
58376
59322
|
return request;
|
|
58377
59323
|
}
|
|
@@ -58433,21 +59379,28 @@ class PaymentHandler extends AbstractMessageHandler {
|
|
|
58433
59379
|
const receiverDID = DID.parse(paymentRequest.from);
|
|
58434
59380
|
const payments = [];
|
|
58435
59381
|
for (let i = 0; i < paymentRequest.body.payments.length; i++) {
|
|
58436
|
-
const
|
|
58437
|
-
|
|
58438
|
-
|
|
59382
|
+
const { data } = paymentRequest.body.payments[i];
|
|
59383
|
+
const selectedPayment = Array.isArray(data)
|
|
59384
|
+
? data.find((p) => {
|
|
59385
|
+
return p.type === PaymentRequestDataType.Iden3PaymentRequestCryptoV1
|
|
59386
|
+
? p.id === ctx.nonce
|
|
59387
|
+
: p.nonce === ctx.nonce;
|
|
59388
|
+
})
|
|
59389
|
+
: data;
|
|
59390
|
+
if (!selectedPayment) {
|
|
59391
|
+
throw new Error(`failed request. no payment in request for nonce ${ctx.nonce}`);
|
|
58439
59392
|
}
|
|
58440
|
-
|
|
58441
|
-
|
|
59393
|
+
switch (selectedPayment.type) {
|
|
59394
|
+
case PaymentRequestDataType.Iden3PaymentRequestCryptoV1:
|
|
59395
|
+
payments.push(await this.handleIden3PaymentRequestCryptoV1(selectedPayment, ctx.paymentHandler));
|
|
59396
|
+
break;
|
|
59397
|
+
case PaymentRequestDataType.Iden3PaymentRailsRequestV1:
|
|
59398
|
+
payments.push(await this.handleIden3PaymentRailsRequestV1(selectedPayment, ctx.paymentHandler));
|
|
59399
|
+
break;
|
|
59400
|
+
case PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1:
|
|
59401
|
+
payments.push(await this.handleIden3PaymentRailsERC20RequestV1(selectedPayment, ctx.paymentHandler, ctx.erc20TokenApproveHandler));
|
|
59402
|
+
break;
|
|
58442
59403
|
}
|
|
58443
|
-
const txId = await ctx.paymentHandler(paymentReq.data);
|
|
58444
|
-
payments.push({
|
|
58445
|
-
id: paymentReq.data.id,
|
|
58446
|
-
type: PaymentType.Iden3PaymentCryptoV1,
|
|
58447
|
-
paymentData: {
|
|
58448
|
-
txId
|
|
58449
|
-
}
|
|
58450
|
-
});
|
|
58451
59404
|
}
|
|
58452
59405
|
const paymentMessage = createPayment(senderDID, receiverDID, payments);
|
|
58453
59406
|
const response = await this.packMessage(paymentMessage, senderDID);
|
|
@@ -58480,6 +59433,9 @@ class PaymentHandler extends AbstractMessageHandler {
|
|
|
58480
59433
|
if (!paymentRequest.to) {
|
|
58481
59434
|
throw new Error(`failed request. empty 'to' field`);
|
|
58482
59435
|
}
|
|
59436
|
+
if (!opts?.allowExpiredMessages) {
|
|
59437
|
+
verifyExpiresTime(paymentRequest);
|
|
59438
|
+
}
|
|
58483
59439
|
const agentMessage = await this.handlePaymentRequestMessage(paymentRequest, opts);
|
|
58484
59440
|
if (!agentMessage) {
|
|
58485
59441
|
return null;
|
|
@@ -58490,24 +59446,122 @@ class PaymentHandler extends AbstractMessageHandler {
|
|
|
58490
59446
|
/**
|
|
58491
59447
|
* @inheritdoc IPaymentHandler#handlePayment
|
|
58492
59448
|
*/
|
|
58493
|
-
async handlePayment(payment,
|
|
58494
|
-
if (
|
|
58495
|
-
|
|
59449
|
+
async handlePayment(payment, params) {
|
|
59450
|
+
if (!params?.allowExpiredMessages) {
|
|
59451
|
+
verifyExpiresTime(payment);
|
|
59452
|
+
}
|
|
59453
|
+
if (params.paymentRequest.from !== payment.to) {
|
|
59454
|
+
throw new Error(`sender of the request is not a target of response - expected ${params.paymentRequest.from}, given ${payment.to}`);
|
|
58496
59455
|
}
|
|
58497
59456
|
if (!payment.body.payments.length) {
|
|
58498
59457
|
throw new Error(`failed request. empty 'payments' field in body`);
|
|
58499
59458
|
}
|
|
59459
|
+
if (!params.paymentValidationHandler) {
|
|
59460
|
+
throw new Error(`please provide payment validation handler in options`);
|
|
59461
|
+
}
|
|
58500
59462
|
for (let i = 0; i < payment.body.payments.length; i++) {
|
|
58501
59463
|
const p = payment.body.payments[i];
|
|
58502
|
-
const
|
|
58503
|
-
|
|
58504
|
-
|
|
58505
|
-
|
|
58506
|
-
|
|
58507
|
-
|
|
58508
|
-
|
|
58509
|
-
|
|
59464
|
+
const nonce = p.type === PaymentType.Iden3PaymentCryptoV1 ? p.id : p.nonce;
|
|
59465
|
+
const requestDataArr = params.paymentRequest.body.payments
|
|
59466
|
+
.map((r) => (Array.isArray(r.data) ? r.data : [r.data]))
|
|
59467
|
+
.flat();
|
|
59468
|
+
const requestData = requestDataArr.find((r) => r.type === PaymentRequestDataType.Iden3PaymentRequestCryptoV1
|
|
59469
|
+
? r.id === nonce
|
|
59470
|
+
: r.nonce === nonce);
|
|
59471
|
+
if (!requestData) {
|
|
59472
|
+
throw new Error(`can't find payment request for payment ${p.type === PaymentType.Iden3PaymentCryptoV1 ? 'id' : 'nonce'} ${nonce}`);
|
|
59473
|
+
}
|
|
59474
|
+
await params.paymentValidationHandler(p.paymentData.txId, requestData);
|
|
59475
|
+
}
|
|
59476
|
+
}
|
|
59477
|
+
/**
|
|
59478
|
+
* @inheritdoc IPaymentHandler#createPaymentRailsV1
|
|
59479
|
+
*/
|
|
59480
|
+
async createPaymentRailsV1(sender, receiver, agent, signer, payments) {
|
|
59481
|
+
const paymentRequestInfo = [];
|
|
59482
|
+
for (let i = 0; i < payments.length; i++) {
|
|
59483
|
+
const { credentials, description } = payments[i];
|
|
59484
|
+
const dataArr = [];
|
|
59485
|
+
for (let j = 0; j < payments[i].chains.length; j++) {
|
|
59486
|
+
const { features, nonce, amount, currency, chainId, expirationDate, type } = payments[i].chains[j];
|
|
59487
|
+
const multiChainConfig = this._params.multiChainPaymentConfig?.find((c) => c.chainId === chainId);
|
|
59488
|
+
if (!multiChainConfig) {
|
|
59489
|
+
throw new Error(`failed request. no config for chain ${chainId}`);
|
|
59490
|
+
}
|
|
59491
|
+
const { recipient, paymentContract, erc20TokenAddressArr } = multiChainConfig;
|
|
59492
|
+
const tokenAddress = erc20TokenAddressArr.find((t) => t.symbol === currency)?.address;
|
|
59493
|
+
if (type === PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1 && !tokenAddress) {
|
|
59494
|
+
throw new Error(`failed request. no token address for currency ${currency}`);
|
|
59495
|
+
}
|
|
59496
|
+
const expirationTime = expirationDate
|
|
59497
|
+
? new Date(expirationDate).getTime()
|
|
59498
|
+
: new Date(new Date().setHours(new Date().getHours() + 1)).getTime();
|
|
59499
|
+
const typeUrl = `https://schema.iden3.io/core/json/${type}.json`;
|
|
59500
|
+
const typesFetchResult = await fetch(typeUrl);
|
|
59501
|
+
const types = await typesFetchResult.json();
|
|
59502
|
+
delete types.EIP712Domain;
|
|
59503
|
+
const paymentData = type === PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
59504
|
+
? {
|
|
59505
|
+
recipient,
|
|
59506
|
+
amount,
|
|
59507
|
+
expirationDate: expirationTime,
|
|
59508
|
+
nonce,
|
|
59509
|
+
metadata: '0x'
|
|
59510
|
+
}
|
|
59511
|
+
: {
|
|
59512
|
+
tokenAddress,
|
|
59513
|
+
recipient,
|
|
59514
|
+
amount,
|
|
59515
|
+
expirationDate: expirationTime,
|
|
59516
|
+
nonce,
|
|
59517
|
+
metadata: '0x'
|
|
59518
|
+
};
|
|
59519
|
+
const domain = {
|
|
59520
|
+
name: 'MCPayment',
|
|
59521
|
+
version: '1.0.0',
|
|
59522
|
+
chainId,
|
|
59523
|
+
verifyingContract: paymentContract
|
|
59524
|
+
};
|
|
59525
|
+
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
59526
|
+
const proof = [
|
|
59527
|
+
{
|
|
59528
|
+
type: SupportedPaymentProofType.EthereumEip712Signature2021,
|
|
59529
|
+
proofPurpose: 'assertionMethod',
|
|
59530
|
+
proofValue: signature,
|
|
59531
|
+
verificationMethod: `did:pkh:eip155:${chainId}:${await signer.getAddress()}`,
|
|
59532
|
+
created: new Date().toISOString(),
|
|
59533
|
+
eip712: {
|
|
59534
|
+
types: typeUrl,
|
|
59535
|
+
primaryType: 'Iden3PaymentRailsRequestV1',
|
|
59536
|
+
domain
|
|
59537
|
+
}
|
|
59538
|
+
}
|
|
59539
|
+
];
|
|
59540
|
+
const d = {
|
|
59541
|
+
type: PaymentRequestDataType.Iden3PaymentRailsRequestV1,
|
|
59542
|
+
'@context': [
|
|
59543
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`,
|
|
59544
|
+
'https://w3id.org/security/suites/eip712sig-2021/v1'
|
|
59545
|
+
],
|
|
59546
|
+
recipient,
|
|
59547
|
+
amount: amount.toString(),
|
|
59548
|
+
currency,
|
|
59549
|
+
expirationDate: new Date(expirationTime).toISOString(),
|
|
59550
|
+
nonce: nonce.toString(),
|
|
59551
|
+
metadata: '0x',
|
|
59552
|
+
proof
|
|
59553
|
+
};
|
|
59554
|
+
dataArr.push(type === PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
59555
|
+
? d
|
|
59556
|
+
: { ...d, type, tokenAddress: tokenAddress || '', features: features || [] });
|
|
59557
|
+
}
|
|
59558
|
+
paymentRequestInfo.push({
|
|
59559
|
+
data: dataArr,
|
|
59560
|
+
credentials,
|
|
59561
|
+
description
|
|
59562
|
+
});
|
|
58510
59563
|
}
|
|
59564
|
+
return createPaymentRequest(sender, receiver, agent, paymentRequestInfo);
|
|
58511
59565
|
}
|
|
58512
59566
|
async packMessage(message, senderDID) {
|
|
58513
59567
|
const responseEncoded = byteEncoder.encode(JSON.stringify(message));
|
|
@@ -58521,6 +59575,67 @@ class PaymentHandler extends AbstractMessageHandler {
|
|
|
58521
59575
|
...packerOpts
|
|
58522
59576
|
});
|
|
58523
59577
|
}
|
|
59578
|
+
async handleIden3PaymentRequestCryptoV1(data, paymentHandler) {
|
|
59579
|
+
if (data.expiration && new Date(data.expiration) < new Date()) {
|
|
59580
|
+
throw new Error(`failed request. expired request`);
|
|
59581
|
+
}
|
|
59582
|
+
const txId = await paymentHandler(data);
|
|
59583
|
+
return {
|
|
59584
|
+
id: data.id,
|
|
59585
|
+
'@context': 'https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentCryptoV1',
|
|
59586
|
+
type: PaymentType.Iden3PaymentCryptoV1,
|
|
59587
|
+
paymentData: {
|
|
59588
|
+
txId
|
|
59589
|
+
}
|
|
59590
|
+
};
|
|
59591
|
+
}
|
|
59592
|
+
async handleIden3PaymentRailsRequestV1(data, paymentHandler) {
|
|
59593
|
+
if (data.expirationDate && new Date(data.expirationDate) < new Date()) {
|
|
59594
|
+
throw new Error(`failed request. expired request`);
|
|
59595
|
+
}
|
|
59596
|
+
const signer = await verifyEIP712TypedData(data, this._params.documentResolver);
|
|
59597
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
59598
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
59599
|
+
}
|
|
59600
|
+
const txId = await paymentHandler(data);
|
|
59601
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
59602
|
+
return {
|
|
59603
|
+
nonce: data.nonce,
|
|
59604
|
+
type: PaymentType.Iden3PaymentRailsV1,
|
|
59605
|
+
'@context': 'https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsV1',
|
|
59606
|
+
paymentData: {
|
|
59607
|
+
txId,
|
|
59608
|
+
chainId: proof.eip712.domain.chainId
|
|
59609
|
+
}
|
|
59610
|
+
};
|
|
59611
|
+
}
|
|
59612
|
+
async handleIden3PaymentRailsERC20RequestV1(data, paymentHandler, approveHandler) {
|
|
59613
|
+
if (data.expirationDate && new Date(data.expirationDate) < new Date()) {
|
|
59614
|
+
throw new Error(`failed request. expired request`);
|
|
59615
|
+
}
|
|
59616
|
+
const signer = await verifyEIP712TypedData(data, this._params.documentResolver);
|
|
59617
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
59618
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
59619
|
+
}
|
|
59620
|
+
if (!data.features?.includes(PaymentFeatures.EIP_2612) && !approveHandler) {
|
|
59621
|
+
throw new Error(`please provide erc20TokenApproveHandler in context for ERC-20 payment type`);
|
|
59622
|
+
}
|
|
59623
|
+
if (approveHandler) {
|
|
59624
|
+
await approveHandler(data);
|
|
59625
|
+
}
|
|
59626
|
+
const txId = await paymentHandler(data);
|
|
59627
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
59628
|
+
return {
|
|
59629
|
+
nonce: data.nonce,
|
|
59630
|
+
type: PaymentType.Iden3PaymentRailsERC20V1,
|
|
59631
|
+
'@context': 'https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsERC20V1',
|
|
59632
|
+
paymentData: {
|
|
59633
|
+
txId,
|
|
59634
|
+
chainId: proof.eip712.domain.chainId,
|
|
59635
|
+
tokenAddress: data.tokenAddress
|
|
59636
|
+
}
|
|
59637
|
+
};
|
|
59638
|
+
}
|
|
58524
59639
|
}
|
|
58525
59640
|
|
|
58526
59641
|
const allOperations = Object.values(QueryOperators);
|
|
@@ -58531,7 +59646,8 @@ const v2Operations = [
|
|
|
58531
59646
|
Operators.GT,
|
|
58532
59647
|
Operators.IN,
|
|
58533
59648
|
Operators.NIN,
|
|
58534
|
-
Operators.NE
|
|
59649
|
+
Operators.NE,
|
|
59650
|
+
Operators.SD
|
|
58535
59651
|
];
|
|
58536
59652
|
const v2OnChainOperations = [
|
|
58537
59653
|
Operators.EQ,
|
|
@@ -60556,5 +61672,5 @@ class IdentityWallet {
|
|
|
60556
61672
|
}
|
|
60557
61673
|
}
|
|
60558
61674
|
|
|
60559
|
-
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, CredentialOfferStatus, CredentialProposalHandler, CredentialStatusPublisherRegistry, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DIDDocumentSignature, DataPrepareHandlerFunc, DisplayMethodType, Ed25519Provider, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, FunctionSignatures, 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,
|
|
61675
|
+
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, CredentialOfferStatus, CredentialProposalHandler, CredentialStatusPublisherRegistry, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DIDDocumentSignature, DataPrepareHandlerFunc, DisplayMethodType, Ed25519Provider, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, FunctionSignatures, 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, PaymentFeatures, PaymentHandler, PaymentRequestDataType, PaymentType, PlainPacker, ProofNode, ProofPurpose, ProofService, ProofType, PubSignalsVerifier, Query, QueryOperators, RHSResolver, RefreshHandler, RefreshServiceType, RevocationStatusHandler, SDK_EVENTS, Scalar, SearchError, Sec256k1Provider, StandardJSONCredentialsQueryFilter, StateTransitionInputs, StateTransitionPubSignals, SubjectPosition, SupportedCurrencies, SupportedPaymentProofType, TransactionService, ValueProof, Vector, VerifiableConstants, VerificationHandlerFunc, W3CCredential, XSDNS, ZKPPacker, availableTypesOperators, base58ToBytes$1 as base58ToBytes, base64ToBytes$1 as base64ToBytes, base64UrlToBytes, bigIntArrayToStringArray, bigIntCompare, buildAccept, 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, getPermitSignature, getProperties, getSerializationAttrFromContext, getSerializationAttrFromParsedContext, getUserDIDFromCredential, hexToBytes$3 as hexToBytes, isEthereumIdentity, isGenesisState, isGenesisStateId, isIssuerGenesis, isValidOperation, keyPath, mergeObjects, parseAcceptProfile, parseCoreClaimSlots, parseCredentialSubject, parseQueriesMetadata, parseQueryMetadata, parseSerializationAttr, prepareCircuitArrayValues, prepareSiblingsStr, processZeroKnowledgeProofRequests, pushHashesToRHS, resolveDIDDocumentAuth, resolveDidDocument, resolvePath, resolveVerificationMethods, strMTHex, stringByPath, subjectPositionIndex, swapEndianness, toClaimNonRevStatus, toGISTProof, toRevocationStatus, transformQueryValueToBigInts, userStateError, validateDIDDocumentAuth, validateDisclosureNativeSDSupport, validateDisclosureV2Circuit, validateEmptyCredentialSubjectNoopNativeSupport, validateEmptyCredentialSubjectV2Circuit, validateOperators, validateTreeState, verifyEIP712TypedData, verifyExpiresTime, verifyFieldValueInclusionNativeExistsSupport, verifyFieldValueInclusionV2, witnessBuilder };
|
|
60560
61676
|
//# sourceMappingURL=index.js.map
|