-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPolygonIdHelper.sol
56 lines (45 loc) · 1.65 KB
/
PolygonIdHelper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import { Bureau } from "../base/Bureau.sol";
import { Helper } from "../base/Helper.sol";
import "./xPolygonID/lib/GenesisUtils.sol";
import "./xPolygonID/verifiers/ZKPVerifier.sol";
import "./xPolygonID/interfaces/ICircuitValidator.sol";
contract PolygonIdHelper is Helper, ZKPVerifier {
event ProofAccepted(address indexed sender, uint256 indexed id);
uint64 public constant VERIFY_REQUEST_ID = 1;
mapping (uint256 => address) private _submittedProofs;
constructor(Bureau bureau_)
Helper(bureau_)
{}
function _beforeProofSubmit(
uint64, /* requestId */
uint256[] memory inputs,
ICircuitValidator validator
) internal view override {
address addr = GenesisUtils.int256ToAddress(
inputs[validator.getChallengeInputIndex()]
);
require(
_msgSender() == addr,
"address in proof is not a sender address"
);
}
function _afterProofSubmit(
uint64 requestId,
uint256[] memory inputs,
ICircuitValidator validator
) internal override {
require(requestId == VERIFY_REQUEST_ID, "PolygonIDHelper: Invalid request");
uint256 id = inputs[validator.getChallengeInputIndex()];
if (_submittedProofs[id] == address(0)) {
_bureau.verify(_msgSender());
_submittedProofs[id] = _msgSender();
emit ProofAccepted(_msgSender(), id);
}
}
/// @dev due to the bug with PolygonID app it only works with `name()`
function name() public pure returns (string memory) {
return "CryptoBureau";
}
}