@0xpolygonid/js-sdk 1.17.8 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/esm/index.js +976 -64
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +976 -63
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2-on-chain.js +10 -0
- package/dist/node/cjs/circuits/atomic-query-sig-v2-on-chain.js +10 -0
- package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +10 -0
- package/dist/node/cjs/iden3comm/constants.js +2 -0
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +73 -10
- package/dist/node/cjs/storage/blockchain/abi/ZkpVerifier.json +530 -9
- package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +293 -42
- package/dist/node/cjs/utils/did-helper.js +37 -1
- package/dist/node/esm/circuits/atomic-query-mtp-v2-on-chain.js +10 -0
- package/dist/node/esm/circuits/atomic-query-sig-v2-on-chain.js +10 -0
- package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +10 -0
- package/dist/node/esm/iden3comm/constants.js +2 -0
- package/dist/node/esm/iden3comm/handlers/contract-request.js +73 -10
- package/dist/node/esm/storage/blockchain/abi/ZkpVerifier.json +530 -9
- package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +293 -42
- package/dist/node/esm/utils/did-helper.js +35 -0
- package/dist/types/circuits/atomic-query-mtp-v2-on-chain.d.ts +4 -2
- package/dist/types/circuits/atomic-query-sig-v2-on-chain.d.ts +4 -2
- package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +4 -2
- package/dist/types/circuits/common.d.ts +31 -0
- package/dist/types/iden3comm/constants.d.ts +1 -0
- package/dist/types/iden3comm/handlers/contract-request.d.ts +14 -3
- package/dist/types/iden3comm/types/protocol/auth.d.ts +11 -1
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts +16 -1
- package/dist/types/proof/verifiers/pub-signals-verifier.d.ts +2 -2
- package/dist/types/proof/verifiers/query.d.ts +4 -3
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +44 -12
- package/dist/types/storage/entities/state.d.ts +44 -0
- package/dist/types/storage/interfaces/onchain-zkp-verifier.d.ts +22 -1
- package/dist/types/utils/did-helper.d.ts +12 -1
- package/dist/types/verifiable/presentation.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1334,6 +1334,13 @@ var PolygonIdSdk = (function (exports) {
|
|
|
1334
1334
|
|
|
1335
1335
|
var sha3Exports = sha3$1.exports;
|
|
1336
1336
|
|
|
1337
|
+
/**
|
|
1338
|
+
* Supported DID Document Signatures
|
|
1339
|
+
*/
|
|
1340
|
+
exports.DIDDocumentSignature = void 0;
|
|
1341
|
+
(function (DIDDocumentSignature) {
|
|
1342
|
+
DIDDocumentSignature["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
|
|
1343
|
+
})(exports.DIDDocumentSignature || (exports.DIDDocumentSignature = {}));
|
|
1337
1344
|
/**
|
|
1338
1345
|
* Checks if state is genesis state
|
|
1339
1346
|
*
|
|
@@ -1397,6 +1404,34 @@ var PolygonIdSdk = (function (exports) {
|
|
|
1397
1404
|
const didResolutionRes = (await resp.json());
|
|
1398
1405
|
return didResolutionRes.didDocument?.verificationMethod?.find((i) => i.type === 'Iden3StateInfo2023');
|
|
1399
1406
|
};
|
|
1407
|
+
function emptyStateDID(did) {
|
|
1408
|
+
const id = Z$2.idFromDID(did);
|
|
1409
|
+
const didType = G$2(Z$2.methodFromId(id), Z$2.blockchainFromId(id), Z$2.networkIdFromId(id));
|
|
1410
|
+
const identifier = H$2.idGenesisFromIdenState(didType, 0n);
|
|
1411
|
+
const emptyDID = Z$2.parseFromId(identifier);
|
|
1412
|
+
return emptyDID;
|
|
1413
|
+
}
|
|
1414
|
+
const resolveDidDocument = async (did, resolverUrl, opts) => {
|
|
1415
|
+
let didString = did.string().replace(/:/g, '%3A');
|
|
1416
|
+
// for gist resolve we have to `hide` user did (look into resolver implementation)
|
|
1417
|
+
const isGistRequest = opts?.gist && !opts.state;
|
|
1418
|
+
if (isGistRequest) {
|
|
1419
|
+
didString = emptyStateDID(did).string();
|
|
1420
|
+
}
|
|
1421
|
+
let url = `${resolverUrl}/1.0/identifiers/${didString}`;
|
|
1422
|
+
if (opts?.signature) {
|
|
1423
|
+
url += `?signature=${opts.signature}`;
|
|
1424
|
+
}
|
|
1425
|
+
if (opts?.state) {
|
|
1426
|
+
url += `${url.includes('?') ? '&' : '?'}state=${opts.state.hex()}`;
|
|
1427
|
+
}
|
|
1428
|
+
if (opts?.gist) {
|
|
1429
|
+
url += `${url.includes('?') ? '&' : '?'}gist=${opts.gist.hex()}`;
|
|
1430
|
+
}
|
|
1431
|
+
const resp = await fetch(url);
|
|
1432
|
+
const data = await resp.json();
|
|
1433
|
+
return data;
|
|
1434
|
+
};
|
|
1400
1435
|
const buildDIDFromEthPubKey = (didType, pubKeyEth) => {
|
|
1401
1436
|
// Use Keccak-256 hash function to get public key hash
|
|
1402
1437
|
const hashOfPublicKey = sha3Exports.keccak256(hexToBytes$3(pubKeyEth));
|
|
@@ -49932,6 +49967,16 @@ var PolygonIdSdk = (function (exports) {
|
|
|
49932
49967
|
fieldIdx++;
|
|
49933
49968
|
return this;
|
|
49934
49969
|
}
|
|
49970
|
+
/** {@inheritDoc IStateInfoPubSignals.getStatesInfo} */
|
|
49971
|
+
getStatesInfo() {
|
|
49972
|
+
return {
|
|
49973
|
+
states: [
|
|
49974
|
+
{ id: this.issuerID, state: this.issuerClaimIdenState },
|
|
49975
|
+
{ id: this.issuerID, state: this.issuerClaimNonRevState }
|
|
49976
|
+
],
|
|
49977
|
+
gists: [{ id: this.userID, root: this.gistRoot }]
|
|
49978
|
+
};
|
|
49979
|
+
}
|
|
49935
49980
|
}
|
|
49936
49981
|
|
|
49937
49982
|
/**
|
|
@@ -50713,6 +50758,16 @@ var PolygonIdSdk = (function (exports) {
|
|
|
50713
50758
|
this.isBJJAuthEnabled = parseInt(sVals[fieldIdx]);
|
|
50714
50759
|
return this;
|
|
50715
50760
|
}
|
|
50761
|
+
/** {@inheritDoc IStateInfoPubSignals.getStatesInfo} */
|
|
50762
|
+
getStatesInfo() {
|
|
50763
|
+
return {
|
|
50764
|
+
states: [
|
|
50765
|
+
{ id: this.issuerID, state: this.issuerState },
|
|
50766
|
+
{ id: this.issuerID, state: this.issuerClaimNonRevState }
|
|
50767
|
+
],
|
|
50768
|
+
gists: [{ id: this.userID, root: this.gistRoot }]
|
|
50769
|
+
};
|
|
50770
|
+
}
|
|
50716
50771
|
}
|
|
50717
50772
|
|
|
50718
50773
|
/**
|
|
@@ -50938,6 +50993,16 @@ var PolygonIdSdk = (function (exports) {
|
|
|
50938
50993
|
fieldIdx++;
|
|
50939
50994
|
return this;
|
|
50940
50995
|
}
|
|
50996
|
+
/** {@inheritDoc IStateInfoPubSignals.getStatesInfo} */
|
|
50997
|
+
getStatesInfo() {
|
|
50998
|
+
return {
|
|
50999
|
+
states: [
|
|
51000
|
+
{ id: this.issuerID, state: this.issuerAuthState },
|
|
51001
|
+
{ id: this.issuerID, state: this.issuerClaimNonRevState }
|
|
51002
|
+
],
|
|
51003
|
+
gists: [{ id: this.userID, root: this.gistRoot }]
|
|
51004
|
+
};
|
|
51005
|
+
}
|
|
50941
51006
|
}
|
|
50942
51007
|
|
|
50943
51008
|
/**
|
|
@@ -52497,6 +52562,103 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52497
52562
|
}
|
|
52498
52563
|
|
|
52499
52564
|
var abi$1 = [
|
|
52565
|
+
{
|
|
52566
|
+
inputs: [
|
|
52567
|
+
],
|
|
52568
|
+
name: "InvalidInitialization",
|
|
52569
|
+
type: "error"
|
|
52570
|
+
},
|
|
52571
|
+
{
|
|
52572
|
+
inputs: [
|
|
52573
|
+
{
|
|
52574
|
+
internalType: "string",
|
|
52575
|
+
name: "message",
|
|
52576
|
+
type: "string"
|
|
52577
|
+
},
|
|
52578
|
+
{
|
|
52579
|
+
internalType: "uint64",
|
|
52580
|
+
name: "requestId",
|
|
52581
|
+
type: "uint64"
|
|
52582
|
+
},
|
|
52583
|
+
{
|
|
52584
|
+
internalType: "uint256",
|
|
52585
|
+
name: "linkID",
|
|
52586
|
+
type: "uint256"
|
|
52587
|
+
},
|
|
52588
|
+
{
|
|
52589
|
+
internalType: "uint64",
|
|
52590
|
+
name: "requestIdToCompare",
|
|
52591
|
+
type: "uint64"
|
|
52592
|
+
},
|
|
52593
|
+
{
|
|
52594
|
+
internalType: "uint256",
|
|
52595
|
+
name: "linkIdToCompare",
|
|
52596
|
+
type: "uint256"
|
|
52597
|
+
}
|
|
52598
|
+
],
|
|
52599
|
+
name: "LinkedProofError",
|
|
52600
|
+
type: "error"
|
|
52601
|
+
},
|
|
52602
|
+
{
|
|
52603
|
+
inputs: [
|
|
52604
|
+
],
|
|
52605
|
+
name: "NotInitializing",
|
|
52606
|
+
type: "error"
|
|
52607
|
+
},
|
|
52608
|
+
{
|
|
52609
|
+
inputs: [
|
|
52610
|
+
{
|
|
52611
|
+
internalType: "address",
|
|
52612
|
+
name: "owner",
|
|
52613
|
+
type: "address"
|
|
52614
|
+
}
|
|
52615
|
+
],
|
|
52616
|
+
name: "OwnableInvalidOwner",
|
|
52617
|
+
type: "error"
|
|
52618
|
+
},
|
|
52619
|
+
{
|
|
52620
|
+
inputs: [
|
|
52621
|
+
{
|
|
52622
|
+
internalType: "address",
|
|
52623
|
+
name: "account",
|
|
52624
|
+
type: "address"
|
|
52625
|
+
}
|
|
52626
|
+
],
|
|
52627
|
+
name: "OwnableUnauthorizedAccount",
|
|
52628
|
+
type: "error"
|
|
52629
|
+
},
|
|
52630
|
+
{
|
|
52631
|
+
anonymous: false,
|
|
52632
|
+
inputs: [
|
|
52633
|
+
{
|
|
52634
|
+
indexed: false,
|
|
52635
|
+
internalType: "uint64",
|
|
52636
|
+
name: "version",
|
|
52637
|
+
type: "uint64"
|
|
52638
|
+
}
|
|
52639
|
+
],
|
|
52640
|
+
name: "Initialized",
|
|
52641
|
+
type: "event"
|
|
52642
|
+
},
|
|
52643
|
+
{
|
|
52644
|
+
anonymous: false,
|
|
52645
|
+
inputs: [
|
|
52646
|
+
{
|
|
52647
|
+
indexed: true,
|
|
52648
|
+
internalType: "address",
|
|
52649
|
+
name: "previousOwner",
|
|
52650
|
+
type: "address"
|
|
52651
|
+
},
|
|
52652
|
+
{
|
|
52653
|
+
indexed: true,
|
|
52654
|
+
internalType: "address",
|
|
52655
|
+
name: "newOwner",
|
|
52656
|
+
type: "address"
|
|
52657
|
+
}
|
|
52658
|
+
],
|
|
52659
|
+
name: "OwnershipTransferStarted",
|
|
52660
|
+
type: "event"
|
|
52661
|
+
},
|
|
52500
52662
|
{
|
|
52501
52663
|
anonymous: false,
|
|
52502
52664
|
inputs: [
|
|
@@ -52516,6 +52678,62 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52516
52678
|
name: "OwnershipTransferred",
|
|
52517
52679
|
type: "event"
|
|
52518
52680
|
},
|
|
52681
|
+
{
|
|
52682
|
+
anonymous: false,
|
|
52683
|
+
inputs: [
|
|
52684
|
+
{
|
|
52685
|
+
indexed: true,
|
|
52686
|
+
internalType: "uint64",
|
|
52687
|
+
name: "requestId",
|
|
52688
|
+
type: "uint64"
|
|
52689
|
+
},
|
|
52690
|
+
{
|
|
52691
|
+
indexed: true,
|
|
52692
|
+
internalType: "address",
|
|
52693
|
+
name: "requestOwner",
|
|
52694
|
+
type: "address"
|
|
52695
|
+
},
|
|
52696
|
+
{
|
|
52697
|
+
indexed: false,
|
|
52698
|
+
internalType: "string",
|
|
52699
|
+
name: "metadata",
|
|
52700
|
+
type: "string"
|
|
52701
|
+
},
|
|
52702
|
+
{
|
|
52703
|
+
indexed: false,
|
|
52704
|
+
internalType: "address",
|
|
52705
|
+
name: "validator",
|
|
52706
|
+
type: "address"
|
|
52707
|
+
},
|
|
52708
|
+
{
|
|
52709
|
+
indexed: false,
|
|
52710
|
+
internalType: "bytes",
|
|
52711
|
+
name: "data",
|
|
52712
|
+
type: "bytes"
|
|
52713
|
+
}
|
|
52714
|
+
],
|
|
52715
|
+
name: "ZKPRequestSet",
|
|
52716
|
+
type: "event"
|
|
52717
|
+
},
|
|
52718
|
+
{
|
|
52719
|
+
anonymous: false,
|
|
52720
|
+
inputs: [
|
|
52721
|
+
{
|
|
52722
|
+
indexed: true,
|
|
52723
|
+
internalType: "uint64",
|
|
52724
|
+
name: "requestId",
|
|
52725
|
+
type: "uint64"
|
|
52726
|
+
},
|
|
52727
|
+
{
|
|
52728
|
+
indexed: true,
|
|
52729
|
+
internalType: "address",
|
|
52730
|
+
name: "caller",
|
|
52731
|
+
type: "address"
|
|
52732
|
+
}
|
|
52733
|
+
],
|
|
52734
|
+
name: "ZKPResponseSubmitted",
|
|
52735
|
+
type: "event"
|
|
52736
|
+
},
|
|
52519
52737
|
{
|
|
52520
52738
|
inputs: [
|
|
52521
52739
|
],
|
|
@@ -52530,6 +52748,165 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52530
52748
|
stateMutability: "view",
|
|
52531
52749
|
type: "function"
|
|
52532
52750
|
},
|
|
52751
|
+
{
|
|
52752
|
+
inputs: [
|
|
52753
|
+
],
|
|
52754
|
+
name: "VERSION",
|
|
52755
|
+
outputs: [
|
|
52756
|
+
{
|
|
52757
|
+
internalType: "string",
|
|
52758
|
+
name: "",
|
|
52759
|
+
type: "string"
|
|
52760
|
+
}
|
|
52761
|
+
],
|
|
52762
|
+
stateMutability: "view",
|
|
52763
|
+
type: "function"
|
|
52764
|
+
},
|
|
52765
|
+
{
|
|
52766
|
+
inputs: [
|
|
52767
|
+
],
|
|
52768
|
+
name: "acceptOwnership",
|
|
52769
|
+
outputs: [
|
|
52770
|
+
],
|
|
52771
|
+
stateMutability: "nonpayable",
|
|
52772
|
+
type: "function"
|
|
52773
|
+
},
|
|
52774
|
+
{
|
|
52775
|
+
inputs: [
|
|
52776
|
+
{
|
|
52777
|
+
internalType: "contract ICircuitValidator",
|
|
52778
|
+
name: "validator",
|
|
52779
|
+
type: "address"
|
|
52780
|
+
}
|
|
52781
|
+
],
|
|
52782
|
+
name: "addValidatorToWhitelist",
|
|
52783
|
+
outputs: [
|
|
52784
|
+
],
|
|
52785
|
+
stateMutability: "nonpayable",
|
|
52786
|
+
type: "function"
|
|
52787
|
+
},
|
|
52788
|
+
{
|
|
52789
|
+
inputs: [
|
|
52790
|
+
{
|
|
52791
|
+
internalType: "uint64",
|
|
52792
|
+
name: "requestId",
|
|
52793
|
+
type: "uint64"
|
|
52794
|
+
}
|
|
52795
|
+
],
|
|
52796
|
+
name: "disableZKPRequest",
|
|
52797
|
+
outputs: [
|
|
52798
|
+
],
|
|
52799
|
+
stateMutability: "nonpayable",
|
|
52800
|
+
type: "function"
|
|
52801
|
+
},
|
|
52802
|
+
{
|
|
52803
|
+
inputs: [
|
|
52804
|
+
{
|
|
52805
|
+
internalType: "uint64",
|
|
52806
|
+
name: "requestId",
|
|
52807
|
+
type: "uint64"
|
|
52808
|
+
}
|
|
52809
|
+
],
|
|
52810
|
+
name: "enableZKPRequest",
|
|
52811
|
+
outputs: [
|
|
52812
|
+
],
|
|
52813
|
+
stateMutability: "nonpayable",
|
|
52814
|
+
type: "function"
|
|
52815
|
+
},
|
|
52816
|
+
{
|
|
52817
|
+
inputs: [
|
|
52818
|
+
{
|
|
52819
|
+
internalType: "address",
|
|
52820
|
+
name: "sender",
|
|
52821
|
+
type: "address"
|
|
52822
|
+
},
|
|
52823
|
+
{
|
|
52824
|
+
internalType: "uint64",
|
|
52825
|
+
name: "requestId",
|
|
52826
|
+
type: "uint64"
|
|
52827
|
+
}
|
|
52828
|
+
],
|
|
52829
|
+
name: "getProofStatus",
|
|
52830
|
+
outputs: [
|
|
52831
|
+
{
|
|
52832
|
+
components: [
|
|
52833
|
+
{
|
|
52834
|
+
internalType: "bool",
|
|
52835
|
+
name: "isVerified",
|
|
52836
|
+
type: "bool"
|
|
52837
|
+
},
|
|
52838
|
+
{
|
|
52839
|
+
internalType: "string",
|
|
52840
|
+
name: "validatorVersion",
|
|
52841
|
+
type: "string"
|
|
52842
|
+
},
|
|
52843
|
+
{
|
|
52844
|
+
internalType: "uint256",
|
|
52845
|
+
name: "blockNumber",
|
|
52846
|
+
type: "uint256"
|
|
52847
|
+
},
|
|
52848
|
+
{
|
|
52849
|
+
internalType: "uint256",
|
|
52850
|
+
name: "blockTimestamp",
|
|
52851
|
+
type: "uint256"
|
|
52852
|
+
}
|
|
52853
|
+
],
|
|
52854
|
+
internalType: "struct IZKPVerifier.ProofStatus",
|
|
52855
|
+
name: "",
|
|
52856
|
+
type: "tuple"
|
|
52857
|
+
}
|
|
52858
|
+
],
|
|
52859
|
+
stateMutability: "view",
|
|
52860
|
+
type: "function"
|
|
52861
|
+
},
|
|
52862
|
+
{
|
|
52863
|
+
inputs: [
|
|
52864
|
+
{
|
|
52865
|
+
internalType: "address",
|
|
52866
|
+
name: "user",
|
|
52867
|
+
type: "address"
|
|
52868
|
+
},
|
|
52869
|
+
{
|
|
52870
|
+
internalType: "uint64",
|
|
52871
|
+
name: "requestId",
|
|
52872
|
+
type: "uint64"
|
|
52873
|
+
},
|
|
52874
|
+
{
|
|
52875
|
+
internalType: "string",
|
|
52876
|
+
name: "key",
|
|
52877
|
+
type: "string"
|
|
52878
|
+
}
|
|
52879
|
+
],
|
|
52880
|
+
name: "getProofStorageField",
|
|
52881
|
+
outputs: [
|
|
52882
|
+
{
|
|
52883
|
+
internalType: "uint256",
|
|
52884
|
+
name: "",
|
|
52885
|
+
type: "uint256"
|
|
52886
|
+
}
|
|
52887
|
+
],
|
|
52888
|
+
stateMutability: "view",
|
|
52889
|
+
type: "function"
|
|
52890
|
+
},
|
|
52891
|
+
{
|
|
52892
|
+
inputs: [
|
|
52893
|
+
{
|
|
52894
|
+
internalType: "uint64",
|
|
52895
|
+
name: "requestId",
|
|
52896
|
+
type: "uint64"
|
|
52897
|
+
}
|
|
52898
|
+
],
|
|
52899
|
+
name: "getRequestOwner",
|
|
52900
|
+
outputs: [
|
|
52901
|
+
{
|
|
52902
|
+
internalType: "address",
|
|
52903
|
+
name: "",
|
|
52904
|
+
type: "address"
|
|
52905
|
+
}
|
|
52906
|
+
],
|
|
52907
|
+
stateMutability: "view",
|
|
52908
|
+
type: "function"
|
|
52909
|
+
},
|
|
52533
52910
|
{
|
|
52534
52911
|
inputs: [
|
|
52535
52912
|
{
|
|
@@ -52559,7 +52936,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52559
52936
|
}
|
|
52560
52937
|
],
|
|
52561
52938
|
internalType: "struct IZKPVerifier.ZKPRequest",
|
|
52562
|
-
name: "",
|
|
52939
|
+
name: "zkpRequest",
|
|
52563
52940
|
type: "tuple"
|
|
52564
52941
|
}
|
|
52565
52942
|
],
|
|
@@ -52621,6 +52998,82 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52621
52998
|
stateMutability: "view",
|
|
52622
52999
|
type: "function"
|
|
52623
53000
|
},
|
|
53001
|
+
{
|
|
53002
|
+
inputs: [
|
|
53003
|
+
{
|
|
53004
|
+
internalType: "contract IStateCrossChain",
|
|
53005
|
+
name: "stateCrossChain",
|
|
53006
|
+
type: "address"
|
|
53007
|
+
}
|
|
53008
|
+
],
|
|
53009
|
+
name: "initialize",
|
|
53010
|
+
outputs: [
|
|
53011
|
+
],
|
|
53012
|
+
stateMutability: "nonpayable",
|
|
53013
|
+
type: "function"
|
|
53014
|
+
},
|
|
53015
|
+
{
|
|
53016
|
+
inputs: [
|
|
53017
|
+
{
|
|
53018
|
+
internalType: "address",
|
|
53019
|
+
name: "sender",
|
|
53020
|
+
type: "address"
|
|
53021
|
+
},
|
|
53022
|
+
{
|
|
53023
|
+
internalType: "uint64",
|
|
53024
|
+
name: "requestId",
|
|
53025
|
+
type: "uint64"
|
|
53026
|
+
}
|
|
53027
|
+
],
|
|
53028
|
+
name: "isProofVerified",
|
|
53029
|
+
outputs: [
|
|
53030
|
+
{
|
|
53031
|
+
internalType: "bool",
|
|
53032
|
+
name: "",
|
|
53033
|
+
type: "bool"
|
|
53034
|
+
}
|
|
53035
|
+
],
|
|
53036
|
+
stateMutability: "view",
|
|
53037
|
+
type: "function"
|
|
53038
|
+
},
|
|
53039
|
+
{
|
|
53040
|
+
inputs: [
|
|
53041
|
+
{
|
|
53042
|
+
internalType: "contract ICircuitValidator",
|
|
53043
|
+
name: "validator",
|
|
53044
|
+
type: "address"
|
|
53045
|
+
}
|
|
53046
|
+
],
|
|
53047
|
+
name: "isWhitelistedValidator",
|
|
53048
|
+
outputs: [
|
|
53049
|
+
{
|
|
53050
|
+
internalType: "bool",
|
|
53051
|
+
name: "",
|
|
53052
|
+
type: "bool"
|
|
53053
|
+
}
|
|
53054
|
+
],
|
|
53055
|
+
stateMutability: "view",
|
|
53056
|
+
type: "function"
|
|
53057
|
+
},
|
|
53058
|
+
{
|
|
53059
|
+
inputs: [
|
|
53060
|
+
{
|
|
53061
|
+
internalType: "uint64",
|
|
53062
|
+
name: "requestId",
|
|
53063
|
+
type: "uint64"
|
|
53064
|
+
}
|
|
53065
|
+
],
|
|
53066
|
+
name: "isZKPRequestEnabled",
|
|
53067
|
+
outputs: [
|
|
53068
|
+
{
|
|
53069
|
+
internalType: "bool",
|
|
53070
|
+
name: "",
|
|
53071
|
+
type: "bool"
|
|
53072
|
+
}
|
|
53073
|
+
],
|
|
53074
|
+
stateMutability: "view",
|
|
53075
|
+
type: "function"
|
|
53076
|
+
},
|
|
52624
53077
|
{
|
|
52625
53078
|
inputs: [
|
|
52626
53079
|
],
|
|
@@ -52637,26 +53090,30 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52637
53090
|
},
|
|
52638
53091
|
{
|
|
52639
53092
|
inputs: [
|
|
53093
|
+
],
|
|
53094
|
+
name: "pendingOwner",
|
|
53095
|
+
outputs: [
|
|
52640
53096
|
{
|
|
52641
53097
|
internalType: "address",
|
|
52642
53098
|
name: "",
|
|
52643
53099
|
type: "address"
|
|
52644
|
-
},
|
|
52645
|
-
{
|
|
52646
|
-
internalType: "uint64",
|
|
52647
|
-
name: "",
|
|
52648
|
-
type: "uint64"
|
|
52649
53100
|
}
|
|
52650
53101
|
],
|
|
52651
|
-
|
|
52652
|
-
|
|
53102
|
+
stateMutability: "view",
|
|
53103
|
+
type: "function"
|
|
53104
|
+
},
|
|
53105
|
+
{
|
|
53106
|
+
inputs: [
|
|
52653
53107
|
{
|
|
52654
|
-
internalType: "
|
|
52655
|
-
name: "",
|
|
52656
|
-
type: "
|
|
53108
|
+
internalType: "contract ICircuitValidator",
|
|
53109
|
+
name: "validator",
|
|
53110
|
+
type: "address"
|
|
52657
53111
|
}
|
|
52658
53112
|
],
|
|
52659
|
-
|
|
53113
|
+
name: "removeValidatorFromWhitelist",
|
|
53114
|
+
outputs: [
|
|
53115
|
+
],
|
|
53116
|
+
stateMutability: "nonpayable",
|
|
52660
53117
|
type: "function"
|
|
52661
53118
|
},
|
|
52662
53119
|
{
|
|
@@ -52687,6 +53144,25 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52687
53144
|
stateMutability: "view",
|
|
52688
53145
|
type: "function"
|
|
52689
53146
|
},
|
|
53147
|
+
{
|
|
53148
|
+
inputs: [
|
|
53149
|
+
{
|
|
53150
|
+
internalType: "uint64",
|
|
53151
|
+
name: "requestId",
|
|
53152
|
+
type: "uint64"
|
|
53153
|
+
},
|
|
53154
|
+
{
|
|
53155
|
+
internalType: "address",
|
|
53156
|
+
name: "requestOwner",
|
|
53157
|
+
type: "address"
|
|
53158
|
+
}
|
|
53159
|
+
],
|
|
53160
|
+
name: "setRequestOwner",
|
|
53161
|
+
outputs: [
|
|
53162
|
+
],
|
|
53163
|
+
stateMutability: "nonpayable",
|
|
53164
|
+
type: "function"
|
|
53165
|
+
},
|
|
52690
53166
|
{
|
|
52691
53167
|
inputs: [
|
|
52692
53168
|
{
|
|
@@ -52757,6 +53233,42 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52757
53233
|
stateMutability: "nonpayable",
|
|
52758
53234
|
type: "function"
|
|
52759
53235
|
},
|
|
53236
|
+
{
|
|
53237
|
+
inputs: [
|
|
53238
|
+
{
|
|
53239
|
+
components: [
|
|
53240
|
+
{
|
|
53241
|
+
internalType: "uint64",
|
|
53242
|
+
name: "requestId",
|
|
53243
|
+
type: "uint64"
|
|
53244
|
+
},
|
|
53245
|
+
{
|
|
53246
|
+
internalType: "bytes",
|
|
53247
|
+
name: "zkProof",
|
|
53248
|
+
type: "bytes"
|
|
53249
|
+
},
|
|
53250
|
+
{
|
|
53251
|
+
internalType: "bytes",
|
|
53252
|
+
name: "data",
|
|
53253
|
+
type: "bytes"
|
|
53254
|
+
}
|
|
53255
|
+
],
|
|
53256
|
+
internalType: "struct ZKPResponse[]",
|
|
53257
|
+
name: "responses",
|
|
53258
|
+
type: "tuple[]"
|
|
53259
|
+
},
|
|
53260
|
+
{
|
|
53261
|
+
internalType: "bytes",
|
|
53262
|
+
name: "crossChainProof",
|
|
53263
|
+
type: "bytes"
|
|
53264
|
+
}
|
|
53265
|
+
],
|
|
53266
|
+
name: "submitZKPResponseV2",
|
|
53267
|
+
outputs: [
|
|
53268
|
+
],
|
|
53269
|
+
stateMutability: "nonpayable",
|
|
53270
|
+
type: "function"
|
|
53271
|
+
},
|
|
52760
53272
|
{
|
|
52761
53273
|
inputs: [
|
|
52762
53274
|
{
|
|
@@ -52770,9 +53282,113 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52770
53282
|
],
|
|
52771
53283
|
stateMutability: "nonpayable",
|
|
52772
53284
|
type: "function"
|
|
53285
|
+
},
|
|
53286
|
+
{
|
|
53287
|
+
inputs: [
|
|
53288
|
+
{
|
|
53289
|
+
internalType: "address",
|
|
53290
|
+
name: "sender",
|
|
53291
|
+
type: "address"
|
|
53292
|
+
},
|
|
53293
|
+
{
|
|
53294
|
+
internalType: "uint64[]",
|
|
53295
|
+
name: "requestIds",
|
|
53296
|
+
type: "uint64[]"
|
|
53297
|
+
}
|
|
53298
|
+
],
|
|
53299
|
+
name: "verifyLinkedProofs",
|
|
53300
|
+
outputs: [
|
|
53301
|
+
],
|
|
53302
|
+
stateMutability: "view",
|
|
53303
|
+
type: "function"
|
|
53304
|
+
},
|
|
53305
|
+
{
|
|
53306
|
+
inputs: [
|
|
53307
|
+
{
|
|
53308
|
+
internalType: "uint64",
|
|
53309
|
+
name: "requestId",
|
|
53310
|
+
type: "uint64"
|
|
53311
|
+
},
|
|
53312
|
+
{
|
|
53313
|
+
internalType: "uint256[]",
|
|
53314
|
+
name: "inputs",
|
|
53315
|
+
type: "uint256[]"
|
|
53316
|
+
},
|
|
53317
|
+
{
|
|
53318
|
+
internalType: "uint256[2]",
|
|
53319
|
+
name: "a",
|
|
53320
|
+
type: "uint256[2]"
|
|
53321
|
+
},
|
|
53322
|
+
{
|
|
53323
|
+
internalType: "uint256[2][2]",
|
|
53324
|
+
name: "b",
|
|
53325
|
+
type: "uint256[2][2]"
|
|
53326
|
+
},
|
|
53327
|
+
{
|
|
53328
|
+
internalType: "uint256[2]",
|
|
53329
|
+
name: "c",
|
|
53330
|
+
type: "uint256[2]"
|
|
53331
|
+
},
|
|
53332
|
+
{
|
|
53333
|
+
internalType: "address",
|
|
53334
|
+
name: "sender",
|
|
53335
|
+
type: "address"
|
|
53336
|
+
}
|
|
53337
|
+
],
|
|
53338
|
+
name: "verifyZKPResponse",
|
|
53339
|
+
outputs: [
|
|
53340
|
+
{
|
|
53341
|
+
components: [
|
|
53342
|
+
{
|
|
53343
|
+
internalType: "string",
|
|
53344
|
+
name: "key",
|
|
53345
|
+
type: "string"
|
|
53346
|
+
},
|
|
53347
|
+
{
|
|
53348
|
+
internalType: "uint256",
|
|
53349
|
+
name: "inputValue",
|
|
53350
|
+
type: "uint256"
|
|
53351
|
+
}
|
|
53352
|
+
],
|
|
53353
|
+
internalType: "struct ICircuitValidator.KeyToInputValue[]",
|
|
53354
|
+
name: "",
|
|
53355
|
+
type: "tuple[]"
|
|
53356
|
+
}
|
|
53357
|
+
],
|
|
53358
|
+
stateMutability: "nonpayable",
|
|
53359
|
+
type: "function"
|
|
53360
|
+
},
|
|
53361
|
+
{
|
|
53362
|
+
inputs: [
|
|
53363
|
+
],
|
|
53364
|
+
name: "version",
|
|
53365
|
+
outputs: [
|
|
53366
|
+
{
|
|
53367
|
+
internalType: "string",
|
|
53368
|
+
name: "",
|
|
53369
|
+
type: "string"
|
|
53370
|
+
}
|
|
53371
|
+
],
|
|
53372
|
+
stateMutability: "pure",
|
|
53373
|
+
type: "function"
|
|
52773
53374
|
}
|
|
52774
53375
|
];
|
|
52775
53376
|
|
|
53377
|
+
const maxGasLimit = 10000000n;
|
|
53378
|
+
/**
|
|
53379
|
+
* Supported function signature for SubmitZKPResponse
|
|
53380
|
+
*/
|
|
53381
|
+
exports.FunctionSignatures = void 0;
|
|
53382
|
+
(function (FunctionSignatures) {
|
|
53383
|
+
/**
|
|
53384
|
+
* solidity identifier for function signature:
|
|
53385
|
+
* function submitZKPResponse(uint64 requestId, uint256[] calldata inputs,
|
|
53386
|
+
* uint256[2] calldata a, uint256[2][2] calldata b, uint256[2] calldata c) public
|
|
53387
|
+
*/
|
|
53388
|
+
FunctionSignatures["SubmitZKPResponseV1"] = "b68967e2";
|
|
53389
|
+
//function submitZKPResponseV2(tuple[](uint64 requestId,bytes zkProof,bytes data),bytes crossChainProof)
|
|
53390
|
+
FunctionSignatures["SubmitZKPResponseV2"] = "ade09fcd";
|
|
53391
|
+
})(exports.FunctionSignatures || (exports.FunctionSignatures = {}));
|
|
52776
53392
|
/**
|
|
52777
53393
|
* OnChainZKPVerifier is a class that allows to interact with the OnChainZKPVerifier contract
|
|
52778
53394
|
* and submitZKPResponse.
|
|
@@ -52787,71 +53403,303 @@ var PolygonIdSdk = (function (exports) {
|
|
|
52787
53403
|
* @beta
|
|
52788
53404
|
* @param {EthConnectionConfig[]} - array of ETH configs
|
|
52789
53405
|
*/
|
|
52790
|
-
constructor(_configs) {
|
|
53406
|
+
constructor(_configs, _opts) {
|
|
52791
53407
|
this._configs = _configs;
|
|
53408
|
+
this._opts = _opts;
|
|
53409
|
+
/**
|
|
53410
|
+
* supported circuits
|
|
53411
|
+
*/
|
|
53412
|
+
this._supportedCircuits = [
|
|
53413
|
+
exports.CircuitId.AtomicQueryMTPV2OnChain,
|
|
53414
|
+
exports.CircuitId.AtomicQuerySigV2OnChain,
|
|
53415
|
+
exports.CircuitId.AtomicQueryV3OnChain
|
|
53416
|
+
];
|
|
52792
53417
|
/**
|
|
52793
|
-
*
|
|
52794
|
-
* function submitZKPResponse(uint64 requestId, uint256[] calldata inputs,
|
|
52795
|
-
* uint256[2] calldata a, uint256[2][2] calldata b, uint256[2] calldata c) public
|
|
53418
|
+
* abi coder to encode/decode structures to solidity bytes
|
|
52796
53419
|
*/
|
|
52797
|
-
this.
|
|
53420
|
+
this._abiCoder = new AbiCoder();
|
|
52798
53421
|
}
|
|
52799
53422
|
/**
|
|
52800
|
-
*
|
|
52801
|
-
|
|
52802
|
-
|
|
52803
|
-
|
|
52804
|
-
|
|
52805
|
-
|
|
53423
|
+
* {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
|
|
53424
|
+
*/
|
|
53425
|
+
async prepareTxArgsSubmitV1(txData, zkProofResponse) {
|
|
53426
|
+
if (txData.method_id.replace('0x', '') !== exports.FunctionSignatures.SubmitZKPResponseV1) {
|
|
53427
|
+
throw new Error(`prepareTxArgsSubmitV1 function doesn't implement requested method id. Only '0x${exports.FunctionSignatures.SubmitZKPResponseV1}' is supported.`);
|
|
53428
|
+
}
|
|
53429
|
+
const requestID = zkProofResponse.id;
|
|
53430
|
+
const inputs = zkProofResponse.pub_signals;
|
|
53431
|
+
const payload = [
|
|
53432
|
+
requestID,
|
|
53433
|
+
inputs,
|
|
53434
|
+
zkProofResponse.proof.pi_a.slice(0, 2),
|
|
53435
|
+
[
|
|
53436
|
+
[zkProofResponse.proof.pi_b[0][1], zkProofResponse.proof.pi_b[0][0]],
|
|
53437
|
+
[zkProofResponse.proof.pi_b[1][1], zkProofResponse.proof.pi_b[1][0]]
|
|
53438
|
+
],
|
|
53439
|
+
zkProofResponse.proof.pi_c.slice(0, 2)
|
|
53440
|
+
];
|
|
53441
|
+
return payload;
|
|
53442
|
+
}
|
|
53443
|
+
/**
|
|
53444
|
+
* {@inheritDoc IOnChainZKPVerifier.submitZKPResponse}
|
|
52806
53445
|
*/
|
|
52807
53446
|
async submitZKPResponse(ethSigner, txData, zkProofResponses) {
|
|
52808
53447
|
const chainConfig = this._configs.find((i) => i.chainId == txData.chain_id);
|
|
52809
53448
|
if (!chainConfig) {
|
|
52810
53449
|
throw new Error(`config for chain id ${txData.chain_id} was not found`);
|
|
52811
53450
|
}
|
|
52812
|
-
if (txData.method_id.replace('0x', '') !==
|
|
52813
|
-
throw new Error(`
|
|
53451
|
+
if (txData.method_id.replace('0x', '') !== exports.FunctionSignatures.SubmitZKPResponseV1) {
|
|
53452
|
+
throw new Error(`submitZKPResponse function doesn't implement requested method id. Only '0x${exports.FunctionSignatures.SubmitZKPResponseV1}' is supported.`);
|
|
52814
53453
|
}
|
|
52815
53454
|
const provider = new JsonRpcProvider(chainConfig.url, chainConfig.chainId);
|
|
52816
|
-
const verifierContract = new Contract(txData.contract_address, abi$1, provider);
|
|
52817
53455
|
ethSigner = ethSigner.connect(provider);
|
|
52818
|
-
const contract = verifierContract.connect(ethSigner);
|
|
52819
53456
|
const response = new Map();
|
|
52820
|
-
|
|
52821
|
-
|
|
52822
|
-
|
|
52823
|
-
|
|
52824
|
-
|
|
52825
|
-
|
|
52826
|
-
|
|
52827
|
-
|
|
52828
|
-
|
|
52829
|
-
|
|
52830
|
-
|
|
52831
|
-
zkProof.proof.pi_c.slice(0, 2)
|
|
52832
|
-
];
|
|
52833
|
-
const feeData = await provider.getFeeData();
|
|
52834
|
-
const maxFeePerGas = chainConfig.maxFeePerGas
|
|
52835
|
-
? BigInt(chainConfig.maxFeePerGas)
|
|
52836
|
-
: feeData.maxFeePerGas;
|
|
52837
|
-
const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
|
|
52838
|
-
? BigInt(chainConfig.maxPriorityFeePerGas)
|
|
52839
|
-
: feeData.maxPriorityFeePerGas;
|
|
52840
|
-
const gasLimit = await contract.submitZKPResponse.estimateGas(...payload);
|
|
52841
|
-
const txData = await contract.submitZKPResponse.populateTransaction(...payload);
|
|
53457
|
+
const feeData = await provider.getFeeData();
|
|
53458
|
+
const maxFeePerGas = chainConfig.maxFeePerGas
|
|
53459
|
+
? BigInt(chainConfig.maxFeePerGas)
|
|
53460
|
+
: feeData.maxFeePerGas;
|
|
53461
|
+
const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
|
|
53462
|
+
? BigInt(chainConfig.maxPriorityFeePerGas)
|
|
53463
|
+
: feeData.maxPriorityFeePerGas;
|
|
53464
|
+
const verifierContract = new Contract(txData.contract_address, abi$1);
|
|
53465
|
+
for (const zkProofResponse of zkProofResponses) {
|
|
53466
|
+
const txArgs = await this.prepareTxArgsSubmitV1(txData, zkProofResponse);
|
|
53467
|
+
const payload = await verifierContract.submitZKPResponse.populateTransaction(...txArgs);
|
|
52842
53468
|
const request = {
|
|
52843
|
-
to: txData.
|
|
52844
|
-
data:
|
|
52845
|
-
gasLimit,
|
|
53469
|
+
to: txData.contract_address,
|
|
53470
|
+
data: payload.data,
|
|
52846
53471
|
maxFeePerGas,
|
|
52847
53472
|
maxPriorityFeePerGas
|
|
52848
53473
|
};
|
|
53474
|
+
let gasLimit;
|
|
53475
|
+
try {
|
|
53476
|
+
gasLimit = await ethSigner.estimateGas(request);
|
|
53477
|
+
}
|
|
53478
|
+
catch (e) {
|
|
53479
|
+
gasLimit = maxGasLimit;
|
|
53480
|
+
}
|
|
53481
|
+
request.gasLimit = gasLimit;
|
|
52849
53482
|
const transactionService = new TransactionService(provider);
|
|
52850
53483
|
const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
|
|
52851
|
-
response.set(txnHash,
|
|
53484
|
+
response.set(txnHash, zkProofResponse);
|
|
52852
53485
|
}
|
|
52853
53486
|
return response;
|
|
52854
53487
|
}
|
|
53488
|
+
/**
|
|
53489
|
+
* {@inheritDoc IOnChainZKPVerifier.submitZKPResponseV2}
|
|
53490
|
+
*/
|
|
53491
|
+
async submitZKPResponseV2(ethSigner, txData, zkProofResponses) {
|
|
53492
|
+
const chainConfig = this._configs.find((i) => i.chainId == txData.chain_id);
|
|
53493
|
+
if (!chainConfig) {
|
|
53494
|
+
throw new Error(`config for chain id ${txData.chain_id} was not found`);
|
|
53495
|
+
}
|
|
53496
|
+
if (txData.method_id.replace('0x', '') !== exports.FunctionSignatures.SubmitZKPResponseV2) {
|
|
53497
|
+
throw new Error(`submitZKPResponseV2 function doesn't implement requested method id. Only '0x${exports.FunctionSignatures.SubmitZKPResponseV2}' is supported.`);
|
|
53498
|
+
}
|
|
53499
|
+
if (!this._opts?.didResolverUrl) {
|
|
53500
|
+
throw new Error(`did resolver url required for crosschain verification`);
|
|
53501
|
+
}
|
|
53502
|
+
const provider = new JsonRpcProvider(chainConfig.url, chainConfig.chainId);
|
|
53503
|
+
ethSigner = ethSigner.connect(provider);
|
|
53504
|
+
const txDataArgs = await this.prepareTxArgsSubmitV2(txData, zkProofResponses);
|
|
53505
|
+
const feeData = await provider.getFeeData();
|
|
53506
|
+
const maxFeePerGas = chainConfig.maxFeePerGas
|
|
53507
|
+
? BigInt(chainConfig.maxFeePerGas)
|
|
53508
|
+
: feeData.maxFeePerGas;
|
|
53509
|
+
const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
|
|
53510
|
+
? BigInt(chainConfig.maxPriorityFeePerGas)
|
|
53511
|
+
: feeData.maxPriorityFeePerGas;
|
|
53512
|
+
const verifierContract = new Contract(txData.contract_address, abi$1);
|
|
53513
|
+
const txRequestData = await verifierContract.submitZKPResponseV2.populateTransaction(...txDataArgs);
|
|
53514
|
+
const request = {
|
|
53515
|
+
to: txData.contract_address,
|
|
53516
|
+
data: txRequestData.data,
|
|
53517
|
+
maxFeePerGas,
|
|
53518
|
+
maxPriorityFeePerGas
|
|
53519
|
+
};
|
|
53520
|
+
let gasLimit;
|
|
53521
|
+
try {
|
|
53522
|
+
gasLimit = await ethSigner.estimateGas(request);
|
|
53523
|
+
}
|
|
53524
|
+
catch (e) {
|
|
53525
|
+
gasLimit = maxGasLimit;
|
|
53526
|
+
}
|
|
53527
|
+
request.gasLimit = gasLimit;
|
|
53528
|
+
const transactionService = new TransactionService(provider);
|
|
53529
|
+
const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
|
|
53530
|
+
return new Map().set(txnHash, zkProofResponses);
|
|
53531
|
+
}
|
|
53532
|
+
async prepareTxArgsSubmitV2(txData, zkProofResponses) {
|
|
53533
|
+
if (txData.method_id.replace('0x', '') !== exports.FunctionSignatures.SubmitZKPResponseV2) {
|
|
53534
|
+
throw new Error(`submit cross chain doesn't implement requested method id. Only '0x${exports.FunctionSignatures.SubmitZKPResponseV2}' is supported.`);
|
|
53535
|
+
}
|
|
53536
|
+
if (!this._opts?.didResolverUrl) {
|
|
53537
|
+
throw new Error(`did resolver url required for crosschain verification`);
|
|
53538
|
+
}
|
|
53539
|
+
const gistUpdateArr = [];
|
|
53540
|
+
const stateUpdateArr = [];
|
|
53541
|
+
const payload = [];
|
|
53542
|
+
// Resolved gists and states to avoid duplicate requests
|
|
53543
|
+
const gistUpdateResolutionsPending = [];
|
|
53544
|
+
const stateUpdateResolutionsPending = [];
|
|
53545
|
+
for (const zkProof of zkProofResponses) {
|
|
53546
|
+
const requestID = zkProof.id;
|
|
53547
|
+
const inputs = zkProof.pub_signals;
|
|
53548
|
+
if (!this._supportedCircuits.includes(zkProof.circuitId)) {
|
|
53549
|
+
throw new Error(`Circuit ${zkProof.circuitId} not supported by OnChainZKPVerifier`);
|
|
53550
|
+
}
|
|
53551
|
+
const zkProofEncoded = this.packZkpProof(inputs, zkProof.proof.pi_a.slice(0, 2), [
|
|
53552
|
+
[zkProof.proof.pi_b[0][1], zkProof.proof.pi_b[0][0]],
|
|
53553
|
+
[zkProof.proof.pi_b[1][1], zkProof.proof.pi_b[1][0]]
|
|
53554
|
+
], zkProof.proof.pi_c.slice(0, 2));
|
|
53555
|
+
const stateInfo = this.getOnChainGistRootStatePubSignals(zkProof.circuitId, zkProof.pub_signals);
|
|
53556
|
+
const gistUpdateResolutions = [];
|
|
53557
|
+
for (const gist of stateInfo.gists) {
|
|
53558
|
+
const gistResolutionPending = gistUpdateResolutionsPending.find((g) => g == JSON.stringify(gist));
|
|
53559
|
+
if (gistResolutionPending) {
|
|
53560
|
+
continue;
|
|
53561
|
+
}
|
|
53562
|
+
gistUpdateResolutionsPending.push(JSON.stringify(gist));
|
|
53563
|
+
gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(Z$2.parseFromId(gist.id), this._opts.didResolverUrl, { gist: gist.root }));
|
|
53564
|
+
}
|
|
53565
|
+
const stateUpdateResolutions = [];
|
|
53566
|
+
for (const state of stateInfo.states) {
|
|
53567
|
+
const stateResolutionPending = stateUpdateResolutionsPending.find((s) => s == JSON.stringify(state));
|
|
53568
|
+
if (stateResolutionPending) {
|
|
53569
|
+
continue;
|
|
53570
|
+
}
|
|
53571
|
+
stateUpdateResolutionsPending.push(JSON.stringify(state));
|
|
53572
|
+
stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(Z$2.parseFromId(state.id), this._opts.didResolverUrl, {
|
|
53573
|
+
state: state.state
|
|
53574
|
+
}));
|
|
53575
|
+
}
|
|
53576
|
+
if (gistUpdateResolutions.length > 0) {
|
|
53577
|
+
gistUpdateArr.push(...(await Promise.all(gistUpdateResolutions)));
|
|
53578
|
+
}
|
|
53579
|
+
if (stateUpdateResolutions.length > 0) {
|
|
53580
|
+
stateUpdateArr.push(...(await Promise.all(stateUpdateResolutions)));
|
|
53581
|
+
}
|
|
53582
|
+
const metadataArr = [];
|
|
53583
|
+
if (zkProof.vp) {
|
|
53584
|
+
for (const key in zkProof.vp.verifiableCredential.credentialSubject) {
|
|
53585
|
+
if (key === '@type') {
|
|
53586
|
+
continue;
|
|
53587
|
+
}
|
|
53588
|
+
const metadataValue = $$2.hashBytes(byteEncoder.encode(JSON.stringify(zkProof.vp.verifiableCredential.credentialSubject[key])));
|
|
53589
|
+
const bytesValue = byteEncoder.encode(metadataValue.toString());
|
|
53590
|
+
metadataArr.push({
|
|
53591
|
+
key,
|
|
53592
|
+
value: bytesValue
|
|
53593
|
+
});
|
|
53594
|
+
}
|
|
53595
|
+
}
|
|
53596
|
+
const metadata = this.packMetadatas(metadataArr);
|
|
53597
|
+
payload.push({
|
|
53598
|
+
requestId: requestID,
|
|
53599
|
+
zkProof: zkProofEncoded,
|
|
53600
|
+
data: metadata
|
|
53601
|
+
});
|
|
53602
|
+
}
|
|
53603
|
+
const crossChainProofs = this.packCrossChainProofs(gistUpdateArr, stateUpdateArr);
|
|
53604
|
+
return [payload, crossChainProofs];
|
|
53605
|
+
}
|
|
53606
|
+
packZkpProof(inputs, a, b, c) {
|
|
53607
|
+
return this._abiCoder.encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
|
|
53608
|
+
}
|
|
53609
|
+
packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
|
|
53610
|
+
const proofs = [];
|
|
53611
|
+
for (const globalStateUpdate of gistUpdateArr) {
|
|
53612
|
+
proofs.push({
|
|
53613
|
+
proofType: 'globalStateProof',
|
|
53614
|
+
proof: this.packGlobalStateMsg(globalStateUpdate)
|
|
53615
|
+
});
|
|
53616
|
+
}
|
|
53617
|
+
for (const stateUpdate of stateUpdateArr) {
|
|
53618
|
+
proofs.push({
|
|
53619
|
+
proofType: 'stateProof',
|
|
53620
|
+
proof: this.packIdentityStateMsg(stateUpdate)
|
|
53621
|
+
});
|
|
53622
|
+
}
|
|
53623
|
+
return this._abiCoder.encode(['tuple(' + 'string proofType,' + 'bytes proof' + ')[]'], [proofs]);
|
|
53624
|
+
}
|
|
53625
|
+
packGlobalStateMsg(msg) {
|
|
53626
|
+
return this._abiCoder.encode([
|
|
53627
|
+
'tuple(' +
|
|
53628
|
+
'tuple(' +
|
|
53629
|
+
'uint256 timestamp,' +
|
|
53630
|
+
'bytes2 idType,' +
|
|
53631
|
+
'uint256 root,' +
|
|
53632
|
+
'uint256 replacedAtTimestamp' +
|
|
53633
|
+
') globalStateMsg,' +
|
|
53634
|
+
'bytes signature,' +
|
|
53635
|
+
')'
|
|
53636
|
+
], [msg]);
|
|
53637
|
+
}
|
|
53638
|
+
packIdentityStateMsg(msg) {
|
|
53639
|
+
return this._abiCoder.encode([
|
|
53640
|
+
'tuple(' +
|
|
53641
|
+
'tuple(' +
|
|
53642
|
+
'uint256 timestamp,' +
|
|
53643
|
+
'uint256 id,' +
|
|
53644
|
+
'uint256 state,' +
|
|
53645
|
+
'uint256 replacedAtTimestamp' +
|
|
53646
|
+
') idStateMsg,' +
|
|
53647
|
+
'bytes signature,' +
|
|
53648
|
+
')'
|
|
53649
|
+
], [msg]);
|
|
53650
|
+
}
|
|
53651
|
+
packMetadatas(metas) {
|
|
53652
|
+
return this._abiCoder.encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
|
|
53653
|
+
}
|
|
53654
|
+
getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
|
|
53655
|
+
let atomicQueryPubSignals;
|
|
53656
|
+
switch (onChainCircuitId) {
|
|
53657
|
+
case exports.CircuitId.AtomicQueryMTPV2OnChain:
|
|
53658
|
+
atomicQueryPubSignals = new AtomicQueryMTPV2OnChainPubSignals();
|
|
53659
|
+
break;
|
|
53660
|
+
case exports.CircuitId.AtomicQuerySigV2OnChain:
|
|
53661
|
+
atomicQueryPubSignals = new AtomicQuerySigV2OnChainPubSignals();
|
|
53662
|
+
break;
|
|
53663
|
+
case exports.CircuitId.AtomicQueryV3OnChain:
|
|
53664
|
+
atomicQueryPubSignals = new AtomicQueryV3OnChainPubSignals();
|
|
53665
|
+
break;
|
|
53666
|
+
}
|
|
53667
|
+
const encodedInputs = byteEncoder.encode(JSON.stringify(inputs));
|
|
53668
|
+
atomicQueryPubSignals.pubSignalsUnmarshal(encodedInputs);
|
|
53669
|
+
return atomicQueryPubSignals.getStatesInfo();
|
|
53670
|
+
}
|
|
53671
|
+
async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
|
|
53672
|
+
const didDoc = await resolveDidDocument(did, resolverUrl, {
|
|
53673
|
+
...opts,
|
|
53674
|
+
signature: exports.DIDDocumentSignature.EthereumEip712Signature2021
|
|
53675
|
+
});
|
|
53676
|
+
if (!didDoc.didResolutionMetadata.proof?.length) {
|
|
53677
|
+
throw new Error('No proof found in resolved DID document');
|
|
53678
|
+
}
|
|
53679
|
+
const message = didDoc.didResolutionMetadata.proof[0].eip712.message;
|
|
53680
|
+
const signature = didDoc.didResolutionMetadata.proof[0].proofValue;
|
|
53681
|
+
const isGistRequest = opts?.gist && !opts.state;
|
|
53682
|
+
if (isGistRequest) {
|
|
53683
|
+
return {
|
|
53684
|
+
globalStateMsg: {
|
|
53685
|
+
timestamp: message.timestamp,
|
|
53686
|
+
idType: message.idType,
|
|
53687
|
+
root: message.root,
|
|
53688
|
+
replacedAtTimestamp: message.replacedAtTimestamp
|
|
53689
|
+
},
|
|
53690
|
+
signature
|
|
53691
|
+
};
|
|
53692
|
+
}
|
|
53693
|
+
return {
|
|
53694
|
+
idStateMsg: {
|
|
53695
|
+
timestamp: message.timestamp,
|
|
53696
|
+
id: message.id,
|
|
53697
|
+
state: message.state,
|
|
53698
|
+
replacedAtTimestamp: message.replacedAtTimestamp
|
|
53699
|
+
},
|
|
53700
|
+
signature
|
|
53701
|
+
};
|
|
53702
|
+
}
|
|
52855
53703
|
}
|
|
52856
53704
|
|
|
52857
53705
|
var abi = [
|
|
@@ -54666,6 +55514,8 @@ var PolygonIdSdk = (function (exports) {
|
|
|
54666
55514
|
REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}revocation/1.0/status`,
|
|
54667
55515
|
// ContractInvokeRequestMessageType is type for request of contract invoke request
|
|
54668
55516
|
CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/contract-invoke-request`,
|
|
55517
|
+
// ContractInvokeResponseMessageType is type for response of contract invoke request
|
|
55518
|
+
CONTRACT_INVOKE_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/contract-invoke-response`,
|
|
54669
55519
|
// CredentialOnchainOfferMessageType is type of message with credential onchain offering
|
|
54670
55520
|
CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/onchain-offer`,
|
|
54671
55521
|
// ProposalRequestMessageType is type for proposal-request message
|
|
@@ -77709,9 +78559,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
77709
78559
|
}
|
|
77710
78560
|
async handle(message, ctx) {
|
|
77711
78561
|
switch (message.type) {
|
|
77712
|
-
case PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE:
|
|
77713
|
-
|
|
77714
|
-
|
|
78562
|
+
case PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: {
|
|
78563
|
+
const ciMessage = message;
|
|
78564
|
+
const txHashResponsesMap = await this.handleContractInvoke(ciMessage, ctx);
|
|
78565
|
+
return this.createContractInvokeResponse(ciMessage, txHashResponsesMap);
|
|
78566
|
+
}
|
|
77715
78567
|
default:
|
|
77716
78568
|
return super.handle(message, ctx);
|
|
77717
78569
|
}
|
|
@@ -77731,7 +78583,21 @@ var PolygonIdSdk = (function (exports) {
|
|
|
77731
78583
|
}
|
|
77732
78584
|
const verifierDid = message.from ? Z$2.parse(message.from) : undefined;
|
|
77733
78585
|
const zkpResponses = await processZeroKnowledgeProofRequests(did, message?.body?.scope, verifierDid, this._proofService, { ethSigner, challenge, supportedCircuits: this._supportedCircuits });
|
|
77734
|
-
|
|
78586
|
+
const methodId = message.body.transaction_data.method_id.replace('0x', '');
|
|
78587
|
+
switch (methodId) {
|
|
78588
|
+
case exports.FunctionSignatures.SubmitZKPResponseV2:
|
|
78589
|
+
return this._zkpVerifier.submitZKPResponseV2(ethSigner, message.body.transaction_data, zkpResponses);
|
|
78590
|
+
case exports.FunctionSignatures.SubmitZKPResponseV1: {
|
|
78591
|
+
const txHashZkpResponseMap = await this._zkpVerifier.submitZKPResponse(ethSigner, message.body.transaction_data, zkpResponses);
|
|
78592
|
+
const response = new Map();
|
|
78593
|
+
for (const [txHash, zkpResponse] of txHashZkpResponseMap) {
|
|
78594
|
+
response.set(txHash, [zkpResponse]);
|
|
78595
|
+
}
|
|
78596
|
+
return response;
|
|
78597
|
+
}
|
|
78598
|
+
default:
|
|
78599
|
+
throw new Error(`Not supported method id. Only '${exports.FunctionSignatures.SubmitZKPResponseV1} and ${exports.FunctionSignatures.SubmitZKPResponseV2} are supported.'`);
|
|
78600
|
+
}
|
|
77735
78601
|
}
|
|
77736
78602
|
/**
|
|
77737
78603
|
* unpacks contract-invoke request
|
|
@@ -77749,8 +78615,41 @@ var PolygonIdSdk = (function (exports) {
|
|
|
77749
78615
|
return ciRequest;
|
|
77750
78616
|
}
|
|
77751
78617
|
/**
|
|
77752
|
-
*
|
|
78618
|
+
* creates contract invoke response
|
|
78619
|
+
* @private
|
|
77753
78620
|
* @beta
|
|
78621
|
+
* @param {ContractInvokeRequest} request - ContractInvokeRequest
|
|
78622
|
+
* @param { Map<string, ZeroKnowledgeProofResponse[]>} responses - map tx hash to array of ZeroKnowledgeProofResponses
|
|
78623
|
+
* @returns `Promise<ContractInvokeResponse>`
|
|
78624
|
+
*/
|
|
78625
|
+
async createContractInvokeResponse(request, txHashToZkpResponseMap) {
|
|
78626
|
+
const contractInvokeResponse = {
|
|
78627
|
+
id: request.id,
|
|
78628
|
+
thid: request.thid,
|
|
78629
|
+
type: PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_RESPONSE_MESSAGE_TYPE,
|
|
78630
|
+
from: request.to,
|
|
78631
|
+
to: request.from,
|
|
78632
|
+
body: {
|
|
78633
|
+
transaction_data: request.body.transaction_data,
|
|
78634
|
+
reason: request.body.reason,
|
|
78635
|
+
scope: []
|
|
78636
|
+
}
|
|
78637
|
+
};
|
|
78638
|
+
for (const [txHash, zkpResponses] of txHashToZkpResponseMap) {
|
|
78639
|
+
for (const zkpResponse of zkpResponses) {
|
|
78640
|
+
contractInvokeResponse.body.scope.push({
|
|
78641
|
+
txHash,
|
|
78642
|
+
...zkpResponse
|
|
78643
|
+
});
|
|
78644
|
+
}
|
|
78645
|
+
}
|
|
78646
|
+
return contractInvokeResponse;
|
|
78647
|
+
}
|
|
78648
|
+
/**
|
|
78649
|
+
* handle contract invoke request
|
|
78650
|
+
* supports only 0xb68967e2 method id
|
|
78651
|
+
* @beta
|
|
78652
|
+
* @deprecated
|
|
77754
78653
|
* @param {did} did - sender DID
|
|
77755
78654
|
* @param {ContractInvokeRequest} request - contract invoke request
|
|
77756
78655
|
* @param {ContractInvokeHandlerOptions} opts - handler options
|
|
@@ -77758,11 +78657,24 @@ var PolygonIdSdk = (function (exports) {
|
|
|
77758
78657
|
*/
|
|
77759
78658
|
async handleContractInvokeRequest(did, request, opts) {
|
|
77760
78659
|
const ciRequest = await this.parseContractInvokeRequest(request);
|
|
77761
|
-
|
|
77762
|
-
|
|
77763
|
-
|
|
77764
|
-
|
|
77765
|
-
|
|
78660
|
+
if (ciRequest.body.transaction_data.method_id !== exports.FunctionSignatures.SubmitZKPResponseV1) {
|
|
78661
|
+
throw new Error(`please use handle method to work with other method ids`);
|
|
78662
|
+
}
|
|
78663
|
+
if (ciRequest.type !== PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE) {
|
|
78664
|
+
throw new Error('Invalid message type for contract invoke request');
|
|
78665
|
+
}
|
|
78666
|
+
const { ethSigner, challenge } = opts;
|
|
78667
|
+
if (!ethSigner) {
|
|
78668
|
+
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
78669
|
+
}
|
|
78670
|
+
const { chain_id } = ciRequest.body.transaction_data;
|
|
78671
|
+
const networkFlag = Object.keys(u$2).find((key) => u$2[key] === chain_id);
|
|
78672
|
+
if (!networkFlag) {
|
|
78673
|
+
throw new Error(`Invalid chain id ${chain_id}`);
|
|
78674
|
+
}
|
|
78675
|
+
const verifierDid = ciRequest.from ? Z$2.parse(ciRequest.from) : undefined;
|
|
78676
|
+
const zkpResponses = await processZeroKnowledgeProofRequests(did, ciRequest?.body?.scope, verifierDid, this._proofService, { ethSigner, challenge, supportedCircuits: this._supportedCircuits });
|
|
78677
|
+
return this._zkpVerifier.submitZKPResponse(ethSigner, ciRequest.body.transaction_data, zkpResponses);
|
|
77766
78678
|
}
|
|
77767
78679
|
}
|
|
77768
78680
|
|
|
@@ -80548,6 +81460,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
80548
81460
|
exports.processZeroKnowledgeProofRequests = processZeroKnowledgeProofRequests;
|
|
80549
81461
|
exports.pushHashesToRHS = pushHashesToRHS;
|
|
80550
81462
|
exports.resolveDIDDocumentAuth = resolveDIDDocumentAuth;
|
|
81463
|
+
exports.resolveDidDocument = resolveDidDocument;
|
|
80551
81464
|
exports.resolvePath = resolvePath;
|
|
80552
81465
|
exports.resolveVerificationMethods = resolveVerificationMethods;
|
|
80553
81466
|
exports.strMTHex = strMTHex;
|