From c14e626c1304d7d51e805c062128bff11e8e1503 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Tue, 9 Aug 2022 21:04:52 -0400 Subject: [PATCH 01/12] use brightid v6 api --- vue-app/src/api/bright-id.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vue-app/src/api/bright-id.ts b/vue-app/src/api/bright-id.ts index 2b1290e42..693ff071c 100644 --- a/vue-app/src/api/bright-id.ts +++ b/vue-app/src/api/bright-id.ts @@ -4,7 +4,7 @@ import { formatBytes32String } from '@ethersproject/strings' import { BrightIdUserRegistry } from './abi' -const NODE_URL = 'https://app.brightid.org/node/v5' +const NODE_URL = 'https://app.brightid.org/node/v6' const CONTEXT = process.env.VUE_APP_BRIGHTID_CONTEXT || 'clr.fund' export interface BrightId { From 9233d16d9633b7b12c0c68fee145e393e335aa12 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Tue, 9 Aug 2022 21:05:50 -0400 Subject: [PATCH 02/12] enable brightid blind signatures --- vue-app/src/api/bright-id.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vue-app/src/api/bright-id.ts b/vue-app/src/api/bright-id.ts index 693ff071c..554cd59bb 100644 --- a/vue-app/src/api/bright-id.ts +++ b/vue-app/src/api/bright-id.ts @@ -33,8 +33,7 @@ export async function selfSponsor( } export function getBrightIdLink(userAddress: string): string { - const nodeUrl = 'http:%2f%2fnode.brightid.org' - const deepLink = `brightid://link-verification/${nodeUrl}/${CONTEXT}/${userAddress}` + const deepLink = `brightid://link-verification/${CONTEXT}/${userAddress}` return deepLink } From f387a0f01ccb63def57153915505c01b0bba4532 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 12 Aug 2022 19:50:16 -0400 Subject: [PATCH 03/12] update brightid verification check to work with v6 and fix ipfs upload error due to infura requiring project id --- .../userRegistry/BrightIdSponsor.sol | 15 + .../userRegistry/BrightIdUserRegistry.sol | 39 +- contracts/scripts/deployBrightIdSponsor.ts | 60 + contracts/scripts/deployUserRegistry.ts | 71 + subgraph/abis/BrightIdUserRegistry.json | 330 ++-- .../BrightIdUserRegistry.ts | 100 +- .../generated/FundingRoundFactory/MACI.ts | 1634 ----------------- .../BrightIdUserRegistry.ts | 100 +- .../FundingRound/BrightIdUserRegistry.ts | 100 +- subgraph/src/BrightIdUserRegistryMapping.ts | 21 +- subgraph/src/FundingRoundFactoryMapping.ts | 21 +- subgraph/subgraph.template.yaml | 4 +- subgraph/subgraph.yaml | 4 +- vue-app/.env.example | 7 +- vue-app/package.json | 2 +- vue-app/src/api/bright-id.ts | 9 +- vue-app/src/api/core.ts | 5 + vue-app/src/api/ipfs.ts | 28 + vue-app/src/components/IpfsImageUpload.vue | 26 +- vue-app/src/views/Verify.vue | 28 - yarn.lock | 21 +- 21 files changed, 669 insertions(+), 1956 deletions(-) create mode 100644 contracts/contracts/userRegistry/BrightIdSponsor.sol create mode 100644 contracts/scripts/deployBrightIdSponsor.ts create mode 100644 contracts/scripts/deployUserRegistry.ts delete mode 100644 subgraph/generated/FundingRoundFactory/MACI.ts create mode 100644 vue-app/src/api/ipfs.ts diff --git a/contracts/contracts/userRegistry/BrightIdSponsor.sol b/contracts/contracts/userRegistry/BrightIdSponsor.sol new file mode 100644 index 000000000..312e1e7b4 --- /dev/null +++ b/contracts/contracts/userRegistry/BrightIdSponsor.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity ^0.6.12; + +contract BrightIdSponsor { + event Sponsor(address indexed addr); + + /** + * @dev sponsor a BrightId user by emitting an event + * that a BrightId node is listening for + */ + function sponsor(address addr) public { + emit Sponsor(addr); + } +} diff --git a/contracts/contracts/userRegistry/BrightIdUserRegistry.sol b/contracts/contracts/userRegistry/BrightIdUserRegistry.sol index 6a8a2f08c..db6da4c20 100644 --- a/contracts/contracts/userRegistry/BrightIdUserRegistry.sol +++ b/contracts/contracts/userRegistry/BrightIdUserRegistry.sol @@ -3,6 +3,7 @@ pragma solidity ^0.6.12; import './IUserRegistry.sol'; +import './BrightIdSponsor.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; contract BrightIdUserRegistry is Ownable, IUserRegistry { @@ -13,6 +14,8 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { bytes32 public context; address public verifier; + BrightIdSponsor public brightIdSponsor; + struct Verification { uint256 time; @@ -20,19 +23,20 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { } mapping(address => Verification) public verifications; - event SetBrightIdSettings(bytes32 context, address verifier); - event Sponsor(address indexed addr); + event SetBrightIdSettings(bytes32 context, address verifier, address sponsor); + event Registered(address indexed addr, uint256 timestamp, bool isVerified); /** * @param _context BrightID context used for verifying users * @param _verifier BrightID verifier address that signs BrightID verifications */ - constructor(bytes32 _context, address _verifier) public { + constructor(bytes32 _context, address _verifier, address _sponsor) public { // ecrecover returns zero on error require(_verifier != address(0), ERROR_INVALID_VERIFIER); context = _context; verifier = _verifier; + brightIdSponsor = BrightIdSponsor(_sponsor); } /** @@ -40,7 +44,7 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { * @param addr BrightID context id */ function sponsor(address addr) public { - emit Sponsor(addr); + brightIdSponsor.sponsor(addr); } /** @@ -48,13 +52,14 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { * @param _context BrightID context used for verifying users * @param _verifier BrightID verifier address that signs BrightID verifications */ - function setSettings(bytes32 _context, address _verifier) external onlyOwner { + function setSettings(bytes32 _context, address _verifier, address _sponsor) external onlyOwner { // ecrecover returns zero on error require(_verifier != address(0), ERROR_INVALID_VERIFIER); context = _context; verifier = _verifier; - emit SetBrightIdSettings(_context, _verifier); + brightIdSponsor = BrightIdSponsor(_sponsor); + emit SetBrightIdSettings(_context, _verifier, _sponsor); } /** @@ -74,7 +79,8 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { /** * @notice Register a user by BrightID verification * @param _context The context used in the users verification - * @param _addrs The history of addresses used by this user in this context + * @param _addr The address used by this user in this context + * @param _verificationHash sha256 of the verification expression * @param _timestamp The BrightID node's verification timestamp * @param _v Component of signature * @param _r Component of signature @@ -82,26 +88,23 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { */ function register( bytes32 _context, - address[] calldata _addrs, + address _addr, + bytes32 _verificationHash, uint _timestamp, uint8 _v, bytes32 _r, bytes32 _s ) external { require(context == _context, ERROR_INVALID_CONTEXT); - require(verifications[_addrs[0]].time < _timestamp, ERROR_NEWER_VERIFICATION); + require(verifications[_addr].time < _timestamp, ERROR_NEWER_VERIFICATION); - bytes32 message = keccak256(abi.encodePacked(_context, _addrs, _timestamp)); + bytes32 message = keccak256(abi.encodePacked(_context, _addr, _verificationHash, _timestamp)); address signer = ecrecover(message, _v, _r, _s); require(verifier == signer, ERROR_NOT_AUTHORIZED); - verifications[_addrs[0]].time = _timestamp; - verifications[_addrs[0]].isVerified = true; - for(uint i = 1; i < _addrs.length; i++) { - // update time of all previous context ids to be sure no one can use old verifications again - verifications[_addrs[i]].time = _timestamp; - // set old verifications unverified - verifications[_addrs[i]].isVerified = false; - } + verifications[_addr].time = _timestamp; + verifications[_addr].isVerified = true; + + emit Registered(_addr, _timestamp, true); } } diff --git a/contracts/scripts/deployBrightIdSponsor.ts b/contracts/scripts/deployBrightIdSponsor.ts new file mode 100644 index 000000000..979ac79fc --- /dev/null +++ b/contracts/scripts/deployBrightIdSponsor.ts @@ -0,0 +1,60 @@ +import { ethers } from 'hardhat' +import { Contract, utils } from 'ethers' + +async function main() { + console.log('*******************') + console.log('Deploying a user registry!') + console.log('*******************') + + if (!process.env.BRIGHTID_USER_REGISTRY) { + console.error('Missing BRIGHTID_USER_REGISTRY environment variable') + return + } + if (!process.env.BRIGHTID_CONTEXT) { + console.error('Missing BRIGHTID_CONTEXT environment variable') + return + } + if (!process.env.BRIGHTID_VERIFIER_ADDR) { + console.error('Missing BRIGHTID_VERIFIER_ADDR environment variable') + return + } + + const [deployer] = await ethers.getSigners() + console.log('deployer.address: ', deployer.address) + + console.log('deploying brightid sponsor contract') + const BrightIdSponsor = await ethers.getContractFactory( + 'BrightIdSponsor', + deployer + ) + const sponsor = await BrightIdSponsor.deploy() + const receipt = await sponsor.deployTransaction.wait() + console.log(`Deployed BrightId Sponsor Contract at ${sponsor.address}`) + console.log('transaction hash', receipt.transactionHash) + + const userRegistry = await ethers.getContractAt( + 'BrightIdUserRegistry', + process.env.BRIGHTID_USER_REGISTRY + ) + const tx = await userRegistry.setSettings( + utils.formatBytes32String(process.env.BRIGHTID_CONTEXT), + process.env.BRIGHTID_VERIFIER_ADDR, + sponsor.address + ) + const settingReceipt = await tx.wait() + console.log( + 'Set user registry settings at hash', + settingReceipt.transactionHash + ) + + console.log('*******************') + console.log('Deploy complete!') + console.log('*******************') +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + }) diff --git a/contracts/scripts/deployUserRegistry.ts b/contracts/scripts/deployUserRegistry.ts new file mode 100644 index 000000000..21a1ff1d3 --- /dev/null +++ b/contracts/scripts/deployUserRegistry.ts @@ -0,0 +1,71 @@ +import { ethers } from 'hardhat' +import { Contract, utils } from 'ethers' + +async function main() { + console.log('*******************') + console.log('Deploying a user registry!') + console.log('*******************') + const [deployer] = await ethers.getSigners() + console.log('deployer.address: ', deployer.address) + + const fundingRoundFactoryAddress = process.env.FUNDING_ROUND_FACTORY_ADDRESS + + if (!fundingRoundFactoryAddress) { + throw new Error( + 'Environment variable FUNDING_ROUND_FACTORY_ADDRESS is not setup' + ) + } + const fundingRoundFactory = await ethers.getContractAt( + 'FundingRoundFactory', + fundingRoundFactoryAddress + ) + console.log('funding round factory address ', fundingRoundFactory.address) + + const userRegistryType = process.env.USER_REGISTRY_TYPE || 'simple' + let userRegistry: Contract + if (userRegistryType === 'simple') { + const SimpleUserRegistry = await ethers.getContractFactory( + 'SimpleUserRegistry', + deployer + ) + userRegistry = await SimpleUserRegistry.deploy() + } else if (userRegistryType === 'brightid') { + console.log('deploying brightid user registry') + const BrightIdUserRegistry = await ethers.getContractFactory( + 'BrightIdUserRegistry', + deployer + ) + userRegistry = await BrightIdUserRegistry.deploy( + utils.formatBytes32String(process.env.BRIGHTID_CONTEXT), + process.env.BRIGHTID_VERIFIER_ADDR, + process.env.BRIGHTID_SPONSOR + ) + } else { + throw new Error('unsupported user registry type') + } + const receipt = await userRegistry.deployTransaction.wait() + console.log( + `Deployed ${userRegistryType} user registry at ${userRegistry.address}` + ) + console.log('transaction hash', receipt.transactionHash) + + const setUserRegistryTx = await fundingRoundFactory.setUserRegistry( + userRegistry.address + ) + await setUserRegistryTx.wait() + console.log( + 'set user registry in funding round factory', + setUserRegistryTx.hash + ) + + console.log('*******************') + console.log('Deploy complete!') + console.log('*******************') +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + }) diff --git a/subgraph/abis/BrightIdUserRegistry.json b/subgraph/abis/BrightIdUserRegistry.json index ebfabde04..d6e00bcba 100644 --- a/subgraph/abis/BrightIdUserRegistry.json +++ b/subgraph/abis/BrightIdUserRegistry.json @@ -1,180 +1,286 @@ [ { - "type": "constructor", - "stateMutability": "nonpayable", - "payable": false, "inputs": [ - { "type": "bytes32", "name": "_context", "internalType": "bytes32" }, - { "type": "address", "name": "_verifier", "internalType": "address" } - ] + { + "internalType": "bytes32", + "name": "_context", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "_verifier", + "type": "address" + }, + { + "internalType": "address", + "name": "_sponsor", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" }, { - "type": "event", - "name": "OwnershipTransferred", + "anonymous": false, "inputs": [ { - "type": "address", - "name": "previousOwner", + "indexed": true, "internalType": "address", - "indexed": true + "name": "previousOwner", + "type": "address" }, { - "type": "address", - "name": "newOwner", + "indexed": true, "internalType": "address", - "indexed": true + "name": "newOwner", + "type": "address" } ], - "anonymous": false + "name": "OwnershipTransferred", + "type": "event" }, { - "type": "event", - "name": "SetBrightIdSettings", + "anonymous": false, "inputs": [ { - "type": "bytes32", - "name": "context", - "internalType": "bytes32", - "indexed": false + "indexed": true, + "internalType": "address", + "name": "addr", + "type": "address" }, { - "type": "address", - "name": "verifier", - "internalType": "address", - "indexed": false + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bool", + "name": "isVerified", + "type": "bool" } ], - "anonymous": false + "name": "Registered", + "type": "event" }, { - "type": "event", - "name": "Sponsor", + "anonymous": false, "inputs": [ { - "type": "address", - "name": "addr", + "indexed": false, + "internalType": "bytes32", + "name": "context", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "verifier", + "type": "address" + }, + { + "indexed": false, "internalType": "address", - "indexed": true + "name": "sponsor", + "type": "address" } ], - "anonymous": false + "name": "SetBrightIdSettings", + "type": "event" }, { - "type": "function", - "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "bytes32", "name": "", "internalType": "bytes32" }], - "name": "context", "inputs": [], - "constant": true + "name": "brightIdSponsor", + "outputs": [ + { + "internalType": "contract BrightIdSponsor", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" }, { - "type": "function", - "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }], - "name": "isOwner", "inputs": [], - "constant": true + "name": "context", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" }, { - "type": "function", - "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }], - "name": "isVerifiedUser", "inputs": [ - { "type": "address", "name": "_user", "internalType": "address" } + { + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "isVerifiedUser", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } ], - "constant": true + "stateMutability": "view", + "type": "function" }, { - "type": "function", - "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "address", "name": "", "internalType": "address" }], - "name": "owner", "inputs": [], - "constant": true + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "register", "inputs": [ - { "type": "bytes32", "name": "_context", "internalType": "bytes32" }, - { "type": "address[]", "name": "_addrs", "internalType": "address[]" }, - { "type": "uint256", "name": "_timestamp", "internalType": "uint256" }, - { "type": "uint8", "name": "_v", "internalType": "uint8" }, - { "type": "bytes32", "name": "_r", "internalType": "bytes32" }, - { "type": "bytes32", "name": "_s", "internalType": "bytes32" } - ], - "constant": false + { + "internalType": "bytes32", + "name": "_context", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "_addr", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_verificationHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_timestamp", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "_v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "_r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "_s", + "type": "bytes32" + } + ], + "name": "register", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "renounceOwnership", "inputs": [], - "constant": false + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "setSettings", "inputs": [ - { "type": "bytes32", "name": "_context", "internalType": "bytes32" }, - { "type": "address", "name": "_verifier", "internalType": "address" } + { + "internalType": "bytes32", + "name": "_context", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "_verifier", + "type": "address" + }, + { + "internalType": "address", + "name": "_sponsor", + "type": "address" + } ], - "constant": false + "name": "setSettings", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "sponsor", "inputs": [ - { "type": "address", "name": "addr", "internalType": "address" } + { + "internalType": "address", + "name": "addr", + "type": "address" + } ], - "constant": false + "name": "sponsor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "transferOwnership", "inputs": [ - { "type": "address", "name": "newOwner", "internalType": "address" } + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } ], - "constant": false + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", - "stateMutability": "view", - "payable": false, - "outputs": [ - { "type": "uint256", "name": "time", "internalType": "uint256" }, - { "type": "bool", "name": "isVerified", "internalType": "bool" } + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } ], "name": "verifications", - "inputs": [{ "type": "address", "name": "", "internalType": "address" }], - "constant": true + "outputs": [ + { + "internalType": "uint256", + "name": "time", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isVerified", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" }, { - "type": "function", - "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "address", "name": "", "internalType": "address" }], - "name": "verifier", "inputs": [], - "constant": true + "name": "verifier", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" } ] diff --git a/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts b/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts index 40919cd1e..e1591f36b 100644 --- a/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts +++ b/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts @@ -32,6 +32,32 @@ export class OwnershipTransferred__Params { } } +export class Registered extends ethereum.Event { + get params(): Registered__Params { + return new Registered__Params(this); + } +} + +export class Registered__Params { + _event: Registered; + + constructor(event: Registered) { + this._event = event; + } + + get addr(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get timestamp(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get isVerified(): boolean { + return this._event.parameters[2].value.toBoolean(); + } +} + export class SetBrightIdSettings extends ethereum.Event { get params(): SetBrightIdSettings__Params { return new SetBrightIdSettings__Params(this); @@ -52,23 +78,9 @@ export class SetBrightIdSettings__Params { get verifier(): Address { return this._event.parameters[1].value.toAddress(); } -} - -export class Sponsor extends ethereum.Event { - get params(): Sponsor__Params { - return new Sponsor__Params(this); - } -} - -export class Sponsor__Params { - _event: Sponsor; - - constructor(event: Sponsor) { - this._event = event; - } - get addr(): Address { - return this._event.parameters[0].value.toAddress(); + get sponsor(): Address { + return this._event.parameters[2].value.toAddress(); } } @@ -94,34 +106,42 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return new BrightIdUserRegistry("BrightIdUserRegistry", address); } - context(): Bytes { - let result = super.call("context", "context():(bytes32)", []); + brightIdSponsor(): Address { + let result = super.call( + "brightIdSponsor", + "brightIdSponsor():(address)", + [] + ); - return result[0].toBytes(); + return result[0].toAddress(); } - try_context(): ethereum.CallResult { - let result = super.tryCall("context", "context():(bytes32)", []); + try_brightIdSponsor(): ethereum.CallResult
{ + let result = super.tryCall( + "brightIdSponsor", + "brightIdSponsor():(address)", + [] + ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBytes()); + return ethereum.CallResult.fromValue(value[0].toAddress()); } - isOwner(): boolean { - let result = super.call("isOwner", "isOwner():(bool)", []); + context(): Bytes { + let result = super.call("context", "context():(bytes32)", []); - return result[0].toBoolean(); + return result[0].toBytes(); } - try_isOwner(): ethereum.CallResult { - let result = super.tryCall("isOwner", "isOwner():(bool)", []); + try_context(): ethereum.CallResult { + let result = super.tryCall("context", "context():(bytes32)", []); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); + return ethereum.CallResult.fromValue(value[0].toBytes()); } isVerifiedUser(_user: Address): boolean { @@ -235,6 +255,10 @@ export class ConstructorCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } + + get _sponsor(): Address { + return this._call.inputValues[2].value.toAddress(); + } } export class ConstructorCall__Outputs { @@ -266,24 +290,28 @@ export class RegisterCall__Inputs { return this._call.inputValues[0].value.toBytes(); } - get _addrs(): Array
{ - return this._call.inputValues[1].value.toAddressArray(); + get _addr(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _verificationHash(): Bytes { + return this._call.inputValues[2].value.toBytes(); } get _timestamp(): BigInt { - return this._call.inputValues[2].value.toBigInt(); + return this._call.inputValues[3].value.toBigInt(); } get _v(): i32 { - return this._call.inputValues[3].value.toI32(); + return this._call.inputValues[4].value.toI32(); } get _r(): Bytes { - return this._call.inputValues[4].value.toBytes(); + return this._call.inputValues[5].value.toBytes(); } get _s(): Bytes { - return this._call.inputValues[5].value.toBytes(); + return this._call.inputValues[6].value.toBytes(); } } @@ -345,6 +373,10 @@ export class SetSettingsCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } + + get _sponsor(): Address { + return this._call.inputValues[2].value.toAddress(); + } } export class SetSettingsCall__Outputs { diff --git a/subgraph/generated/FundingRoundFactory/MACI.ts b/subgraph/generated/FundingRoundFactory/MACI.ts deleted file mode 100644 index de37f2956..000000000 --- a/subgraph/generated/FundingRoundFactory/MACI.ts +++ /dev/null @@ -1,1634 +0,0 @@ -// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. - -import { - ethereum, - JSONValue, - TypedMap, - Entity, - Bytes, - Address, - BigInt -} from "@graphprotocol/graph-ts"; - -export class PublishMessage extends ethereum.Event { - get params(): PublishMessage__Params { - return new PublishMessage__Params(this); - } -} - -export class PublishMessage__Params { - _event: PublishMessage; - - constructor(event: PublishMessage) { - this._event = event; - } - - get _message(): PublishMessage_messageStruct { - return this._event.parameters[0].value.toTuple() as PublishMessage_messageStruct; - } - - get _encPubKey(): PublishMessage_encPubKeyStruct { - return this._event.parameters[1].value.toTuple() as PublishMessage_encPubKeyStruct; - } -} - -export class PublishMessage_messageStruct extends ethereum.Tuple { - get iv(): BigInt { - return this[0].toBigInt(); - } - - get data(): Array { - return this[1].toBigIntArray(); - } -} - -export class PublishMessage_encPubKeyStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class SignUp extends ethereum.Event { - get params(): SignUp__Params { - return new SignUp__Params(this); - } -} - -export class SignUp__Params { - _event: SignUp; - - constructor(event: SignUp) { - this._event = event; - } - - get _userPubKey(): SignUp_userPubKeyStruct { - return this._event.parameters[0].value.toTuple() as SignUp_userPubKeyStruct; - } - - get _stateIndex(): BigInt { - return this._event.parameters[1].value.toBigInt(); - } - - get _voiceCreditBalance(): BigInt { - return this._event.parameters[2].value.toBigInt(); - } -} - -export class SignUp_userPubKeyStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class MACI__coordinatorPubKeyResult { - value0: BigInt; - value1: BigInt; - - constructor(value0: BigInt, value1: BigInt) { - this.value0 = value0; - this.value1 = value1; - } - - toMap(): TypedMap { - let map = new TypedMap(); - map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); - map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); - return map; - } -} - -export class MACI__genBatchUstPublicSignalsInput_ecdhPubKeysStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class MACI__hashMessageInput_messageStruct extends ethereum.Tuple { - get iv(): BigInt { - return this[0].toBigInt(); - } - - get data(): Array { - return this[1].toBigIntArray(); - } -} - -export class MACI__hashStateLeafInput_stateLeafStruct extends ethereum.Tuple { - get pubKey(): MACI__hashStateLeafInput_stateLeafPubKeyStruct { - return this[0].toTuple() as MACI__hashStateLeafInput_stateLeafPubKeyStruct; - } - - get voteOptionTreeRoot(): BigInt { - return this[1].toBigInt(); - } - - get voiceCreditBalance(): BigInt { - return this[2].toBigInt(); - } - - get nonce(): BigInt { - return this[3].toBigInt(); - } -} - -export class MACI__hashStateLeafInput_stateLeafPubKeyStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class MACI__treeDepthsResult { - value0: i32; - value1: i32; - value2: i32; - - constructor(value0: i32, value1: i32, value2: i32) { - this.value0 = value0; - this.value1 = value1; - this.value2 = value2; - } - - toMap(): TypedMap { - let map = new TypedMap(); - map.set( - "value0", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value0)) - ); - map.set( - "value1", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value1)) - ); - map.set( - "value2", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value2)) - ); - return map; - } -} - -export class MACI extends ethereum.SmartContract { - static bind(address: Address): MACI { - return new MACI("MACI", address); - } - - calcEmptyVoteOptionTreeRoot(_levels: i32): BigInt { - let result = super.call( - "calcEmptyVoteOptionTreeRoot", - "calcEmptyVoteOptionTreeRoot(uint8):(uint256)", - [ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(_levels))] - ); - - return result[0].toBigInt(); - } - - try_calcEmptyVoteOptionTreeRoot(_levels: i32): ethereum.CallResult { - let result = super.tryCall( - "calcEmptyVoteOptionTreeRoot", - "calcEmptyVoteOptionTreeRoot(uint8):(uint256)", - [ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(_levels))] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - calcSignUpDeadline(): BigInt { - let result = super.call( - "calcSignUpDeadline", - "calcSignUpDeadline():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_calcSignUpDeadline(): ethereum.CallResult { - let result = super.tryCall( - "calcSignUpDeadline", - "calcSignUpDeadline():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - calcVotingDeadline(): BigInt { - let result = super.call( - "calcVotingDeadline", - "calcVotingDeadline():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_calcVotingDeadline(): ethereum.CallResult { - let result = super.tryCall( - "calcVotingDeadline", - "calcVotingDeadline():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - computeEmptyQuinRoot(_treeLevels: i32, _zeroValue: BigInt): BigInt { - let result = super.call( - "computeEmptyQuinRoot", - "computeEmptyQuinRoot(uint8,uint256):(uint256)", - [ - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(_treeLevels)), - ethereum.Value.fromUnsignedBigInt(_zeroValue) - ] - ); - - return result[0].toBigInt(); - } - - try_computeEmptyQuinRoot( - _treeLevels: i32, - _zeroValue: BigInt - ): ethereum.CallResult { - let result = super.tryCall( - "computeEmptyQuinRoot", - "computeEmptyQuinRoot(uint8,uint256):(uint256)", - [ - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(_treeLevels)), - ethereum.Value.fromUnsignedBigInt(_zeroValue) - ] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - computeEmptyRoot(_treeLevels: i32, _zeroValue: BigInt): BigInt { - let result = super.call( - "computeEmptyRoot", - "computeEmptyRoot(uint8,uint256):(uint256)", - [ - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(_treeLevels)), - ethereum.Value.fromUnsignedBigInt(_zeroValue) - ] - ); - - return result[0].toBigInt(); - } - - try_computeEmptyRoot( - _treeLevels: i32, - _zeroValue: BigInt - ): ethereum.CallResult { - let result = super.tryCall( - "computeEmptyRoot", - "computeEmptyRoot(uint8,uint256):(uint256)", - [ - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(_treeLevels)), - ethereum.Value.fromUnsignedBigInt(_zeroValue) - ] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - coordinatorAddress(): Address { - let result = super.call( - "coordinatorAddress", - "coordinatorAddress():(address)", - [] - ); - - return result[0].toAddress(); - } - - try_coordinatorAddress(): ethereum.CallResult
{ - let result = super.tryCall( - "coordinatorAddress", - "coordinatorAddress():(address)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); - } - - coordinatorPubKey(): MACI__coordinatorPubKeyResult { - let result = super.call( - "coordinatorPubKey", - "coordinatorPubKey():(uint256,uint256)", - [] - ); - - return new MACI__coordinatorPubKeyResult( - result[0].toBigInt(), - result[1].toBigInt() - ); - } - - try_coordinatorPubKey(): ethereum.CallResult { - let result = super.tryCall( - "coordinatorPubKey", - "coordinatorPubKey():(uint256,uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue( - new MACI__coordinatorPubKeyResult( - value[0].toBigInt(), - value[1].toBigInt() - ) - ); - } - - currentMessageBatchIndex(): BigInt { - let result = super.call( - "currentMessageBatchIndex", - "currentMessageBatchIndex():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_currentMessageBatchIndex(): ethereum.CallResult { - let result = super.tryCall( - "currentMessageBatchIndex", - "currentMessageBatchIndex():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - currentPerVOSpentVoiceCreditsCommitment(): BigInt { - let result = super.call( - "currentPerVOSpentVoiceCreditsCommitment", - "currentPerVOSpentVoiceCreditsCommitment():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_currentPerVOSpentVoiceCreditsCommitment(): ethereum.CallResult { - let result = super.tryCall( - "currentPerVOSpentVoiceCreditsCommitment", - "currentPerVOSpentVoiceCreditsCommitment():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - currentQvtBatchNum(): BigInt { - let result = super.call( - "currentQvtBatchNum", - "currentQvtBatchNum():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_currentQvtBatchNum(): ethereum.CallResult { - let result = super.tryCall( - "currentQvtBatchNum", - "currentQvtBatchNum():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - currentResultsCommitment(): BigInt { - let result = super.call( - "currentResultsCommitment", - "currentResultsCommitment():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_currentResultsCommitment(): ethereum.CallResult { - let result = super.tryCall( - "currentResultsCommitment", - "currentResultsCommitment():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - currentSpentVoiceCreditsCommitment(): BigInt { - let result = super.call( - "currentSpentVoiceCreditsCommitment", - "currentSpentVoiceCreditsCommitment():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_currentSpentVoiceCreditsCommitment(): ethereum.CallResult { - let result = super.tryCall( - "currentSpentVoiceCreditsCommitment", - "currentSpentVoiceCreditsCommitment():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - emptyVoteOptionTreeRoot(): BigInt { - let result = super.call( - "emptyVoteOptionTreeRoot", - "emptyVoteOptionTreeRoot():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_emptyVoteOptionTreeRoot(): ethereum.CallResult { - let result = super.tryCall( - "emptyVoteOptionTreeRoot", - "emptyVoteOptionTreeRoot():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - genBatchUstPublicSignals( - _newStateRoot: BigInt, - _ecdhPubKeys: Array - ): Array { - let result = super.call( - "genBatchUstPublicSignals", - "genBatchUstPublicSignals(uint256,(uint256,uint256)[]):(uint256[])", - [ - ethereum.Value.fromUnsignedBigInt(_newStateRoot), - ethereum.Value.fromTupleArray(_ecdhPubKeys) - ] - ); - - return result[0].toBigIntArray(); - } - - try_genBatchUstPublicSignals( - _newStateRoot: BigInt, - _ecdhPubKeys: Array - ): ethereum.CallResult> { - let result = super.tryCall( - "genBatchUstPublicSignals", - "genBatchUstPublicSignals(uint256,(uint256,uint256)[]):(uint256[])", - [ - ethereum.Value.fromUnsignedBigInt(_newStateRoot), - ethereum.Value.fromTupleArray(_ecdhPubKeys) - ] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigIntArray()); - } - - genQvtPublicSignals( - _intermediateStateRoot: BigInt, - _newResultsCommitment: BigInt, - _newSpentVoiceCreditsCommitment: BigInt, - _newPerVOSpentVoiceCreditsCommitment: BigInt, - _totalVotes: BigInt - ): Array { - let result = super.call( - "genQvtPublicSignals", - "genQvtPublicSignals(uint256,uint256,uint256,uint256,uint256):(uint256[])", - [ - ethereum.Value.fromUnsignedBigInt(_intermediateStateRoot), - ethereum.Value.fromUnsignedBigInt(_newResultsCommitment), - ethereum.Value.fromUnsignedBigInt(_newSpentVoiceCreditsCommitment), - ethereum.Value.fromUnsignedBigInt(_newPerVOSpentVoiceCreditsCommitment), - ethereum.Value.fromUnsignedBigInt(_totalVotes) - ] - ); - - return result[0].toBigIntArray(); - } - - try_genQvtPublicSignals( - _intermediateStateRoot: BigInt, - _newResultsCommitment: BigInt, - _newSpentVoiceCreditsCommitment: BigInt, - _newPerVOSpentVoiceCreditsCommitment: BigInt, - _totalVotes: BigInt - ): ethereum.CallResult> { - let result = super.tryCall( - "genQvtPublicSignals", - "genQvtPublicSignals(uint256,uint256,uint256,uint256,uint256):(uint256[])", - [ - ethereum.Value.fromUnsignedBigInt(_intermediateStateRoot), - ethereum.Value.fromUnsignedBigInt(_newResultsCommitment), - ethereum.Value.fromUnsignedBigInt(_newSpentVoiceCreditsCommitment), - ethereum.Value.fromUnsignedBigInt(_newPerVOSpentVoiceCreditsCommitment), - ethereum.Value.fromUnsignedBigInt(_totalVotes) - ] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigIntArray()); - } - - getMessageTreeRoot(): BigInt { - let result = super.call( - "getMessageTreeRoot", - "getMessageTreeRoot():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_getMessageTreeRoot(): ethereum.CallResult { - let result = super.tryCall( - "getMessageTreeRoot", - "getMessageTreeRoot():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - getStateTreeRoot(): BigInt { - let result = super.call( - "getStateTreeRoot", - "getStateTreeRoot():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_getStateTreeRoot(): ethereum.CallResult { - let result = super.tryCall( - "getStateTreeRoot", - "getStateTreeRoot():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - hasUnprocessedMessages(): boolean { - let result = super.call( - "hasUnprocessedMessages", - "hasUnprocessedMessages():(bool)", - [] - ); - - return result[0].toBoolean(); - } - - try_hasUnprocessedMessages(): ethereum.CallResult { - let result = super.tryCall( - "hasUnprocessedMessages", - "hasUnprocessedMessages():(bool)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); - } - - hasUntalliedStateLeaves(): boolean { - let result = super.call( - "hasUntalliedStateLeaves", - "hasUntalliedStateLeaves():(bool)", - [] - ); - - return result[0].toBoolean(); - } - - try_hasUntalliedStateLeaves(): ethereum.CallResult { - let result = super.tryCall( - "hasUntalliedStateLeaves", - "hasUntalliedStateLeaves():(bool)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); - } - - hash11(array: Array): BigInt { - let result = super.call("hash11", "hash11(uint256[]):(uint256)", [ - ethereum.Value.fromUnsignedBigIntArray(array) - ]); - - return result[0].toBigInt(); - } - - try_hash11(array: Array): ethereum.CallResult { - let result = super.tryCall("hash11", "hash11(uint256[]):(uint256)", [ - ethereum.Value.fromUnsignedBigIntArray(array) - ]); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - hash5(array: Array): BigInt { - let result = super.call("hash5", "hash5(uint256[5]):(uint256)", [ - ethereum.Value.fromUnsignedBigIntArray(array) - ]); - - return result[0].toBigInt(); - } - - try_hash5(array: Array): ethereum.CallResult { - let result = super.tryCall("hash5", "hash5(uint256[5]):(uint256)", [ - ethereum.Value.fromUnsignedBigIntArray(array) - ]); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - hashLeftRight(_left: BigInt, _right: BigInt): BigInt { - let result = super.call( - "hashLeftRight", - "hashLeftRight(uint256,uint256):(uint256)", - [ - ethereum.Value.fromUnsignedBigInt(_left), - ethereum.Value.fromUnsignedBigInt(_right) - ] - ); - - return result[0].toBigInt(); - } - - try_hashLeftRight( - _left: BigInt, - _right: BigInt - ): ethereum.CallResult { - let result = super.tryCall( - "hashLeftRight", - "hashLeftRight(uint256,uint256):(uint256)", - [ - ethereum.Value.fromUnsignedBigInt(_left), - ethereum.Value.fromUnsignedBigInt(_right) - ] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - hashMessage(_message: MACI__hashMessageInput_messageStruct): BigInt { - let result = super.call( - "hashMessage", - "hashMessage((uint256,uint256[10])):(uint256)", - [ethereum.Value.fromTuple(_message)] - ); - - return result[0].toBigInt(); - } - - try_hashMessage( - _message: MACI__hashMessageInput_messageStruct - ): ethereum.CallResult { - let result = super.tryCall( - "hashMessage", - "hashMessage((uint256,uint256[10])):(uint256)", - [ethereum.Value.fromTuple(_message)] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - hashStateLeaf(_stateLeaf: MACI__hashStateLeafInput_stateLeafStruct): BigInt { - let result = super.call( - "hashStateLeaf", - "hashStateLeaf(((uint256,uint256),uint256,uint256,uint256)):(uint256)", - [ethereum.Value.fromTuple(_stateLeaf)] - ); - - return result[0].toBigInt(); - } - - try_hashStateLeaf( - _stateLeaf: MACI__hashStateLeafInput_stateLeafStruct - ): ethereum.CallResult { - let result = super.tryCall( - "hashStateLeaf", - "hashStateLeaf(((uint256,uint256),uint256,uint256,uint256)):(uint256)", - [ethereum.Value.fromTuple(_stateLeaf)] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - hashedBlankStateLeaf(): BigInt { - let result = super.call( - "hashedBlankStateLeaf", - "hashedBlankStateLeaf():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_hashedBlankStateLeaf(): ethereum.CallResult { - let result = super.tryCall( - "hashedBlankStateLeaf", - "hashedBlankStateLeaf():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - initialVoiceCreditProxy(): Address { - let result = super.call( - "initialVoiceCreditProxy", - "initialVoiceCreditProxy():(address)", - [] - ); - - return result[0].toAddress(); - } - - try_initialVoiceCreditProxy(): ethereum.CallResult
{ - let result = super.tryCall( - "initialVoiceCreditProxy", - "initialVoiceCreditProxy():(address)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); - } - - maxMessages(): BigInt { - let result = super.call("maxMessages", "maxMessages():(uint256)", []); - - return result[0].toBigInt(); - } - - try_maxMessages(): ethereum.CallResult { - let result = super.tryCall("maxMessages", "maxMessages():(uint256)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - maxUsers(): BigInt { - let result = super.call("maxUsers", "maxUsers():(uint256)", []); - - return result[0].toBigInt(); - } - - try_maxUsers(): ethereum.CallResult { - let result = super.tryCall("maxUsers", "maxUsers():(uint256)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - messageBatchSize(): i32 { - let result = super.call( - "messageBatchSize", - "messageBatchSize():(uint8)", - [] - ); - - return result[0].toI32(); - } - - try_messageBatchSize(): ethereum.CallResult { - let result = super.tryCall( - "messageBatchSize", - "messageBatchSize():(uint8)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toI32()); - } - - messageTree(): Address { - let result = super.call("messageTree", "messageTree():(address)", []); - - return result[0].toAddress(); - } - - try_messageTree(): ethereum.CallResult
{ - let result = super.tryCall("messageTree", "messageTree():(address)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); - } - - messageTreeMaxLeafIndex(): BigInt { - let result = super.call( - "messageTreeMaxLeafIndex", - "messageTreeMaxLeafIndex():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_messageTreeMaxLeafIndex(): ethereum.CallResult { - let result = super.tryCall( - "messageTreeMaxLeafIndex", - "messageTreeMaxLeafIndex():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - numMessages(): BigInt { - let result = super.call("numMessages", "numMessages():(uint256)", []); - - return result[0].toBigInt(); - } - - try_numMessages(): ethereum.CallResult { - let result = super.tryCall("numMessages", "numMessages():(uint256)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - numSignUps(): BigInt { - let result = super.call("numSignUps", "numSignUps():(uint256)", []); - - return result[0].toBigInt(); - } - - try_numSignUps(): ethereum.CallResult { - let result = super.tryCall("numSignUps", "numSignUps():(uint256)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - originalCurrentResultsCommitment(): BigInt { - let result = super.call( - "originalCurrentResultsCommitment", - "originalCurrentResultsCommitment():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_originalCurrentResultsCommitment(): ethereum.CallResult { - let result = super.tryCall( - "originalCurrentResultsCommitment", - "originalCurrentResultsCommitment():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - originalSpentVoiceCreditsCommitment(): BigInt { - let result = super.call( - "originalSpentVoiceCreditsCommitment", - "originalSpentVoiceCreditsCommitment():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_originalSpentVoiceCreditsCommitment(): ethereum.CallResult { - let result = super.tryCall( - "originalSpentVoiceCreditsCommitment", - "originalSpentVoiceCreditsCommitment():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - signUpDurationSeconds(): BigInt { - let result = super.call( - "signUpDurationSeconds", - "signUpDurationSeconds():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_signUpDurationSeconds(): ethereum.CallResult { - let result = super.tryCall( - "signUpDurationSeconds", - "signUpDurationSeconds():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - signUpGatekeeper(): Address { - let result = super.call( - "signUpGatekeeper", - "signUpGatekeeper():(address)", - [] - ); - - return result[0].toAddress(); - } - - try_signUpGatekeeper(): ethereum.CallResult
{ - let result = super.tryCall( - "signUpGatekeeper", - "signUpGatekeeper():(address)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); - } - - signUpTimestamp(): BigInt { - let result = super.call( - "signUpTimestamp", - "signUpTimestamp():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_signUpTimestamp(): ethereum.CallResult { - let result = super.tryCall( - "signUpTimestamp", - "signUpTimestamp():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - stateRoot(): BigInt { - let result = super.call("stateRoot", "stateRoot():(uint256)", []); - - return result[0].toBigInt(); - } - - try_stateRoot(): ethereum.CallResult { - let result = super.tryCall("stateRoot", "stateRoot():(uint256)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - stateRootBeforeProcessing(): BigInt { - let result = super.call( - "stateRootBeforeProcessing", - "stateRootBeforeProcessing():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_stateRootBeforeProcessing(): ethereum.CallResult { - let result = super.tryCall( - "stateRootBeforeProcessing", - "stateRootBeforeProcessing():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - stateTree(): Address { - let result = super.call("stateTree", "stateTree():(address)", []); - - return result[0].toAddress(); - } - - try_stateTree(): ethereum.CallResult
{ - let result = super.tryCall("stateTree", "stateTree():(address)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); - } - - tallyBatchSize(): i32 { - let result = super.call("tallyBatchSize", "tallyBatchSize():(uint8)", []); - - return result[0].toI32(); - } - - try_tallyBatchSize(): ethereum.CallResult { - let result = super.tryCall( - "tallyBatchSize", - "tallyBatchSize():(uint8)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toI32()); - } - - totalVotes(): BigInt { - let result = super.call("totalVotes", "totalVotes():(uint256)", []); - - return result[0].toBigInt(); - } - - try_totalVotes(): ethereum.CallResult { - let result = super.tryCall("totalVotes", "totalVotes():(uint256)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - treeDepths(): MACI__treeDepthsResult { - let result = super.call( - "treeDepths", - "treeDepths():(uint8,uint8,uint8)", - [] - ); - - return new MACI__treeDepthsResult( - result[0].toI32(), - result[1].toI32(), - result[2].toI32() - ); - } - - try_treeDepths(): ethereum.CallResult { - let result = super.tryCall( - "treeDepths", - "treeDepths():(uint8,uint8,uint8)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue( - new MACI__treeDepthsResult( - value[0].toI32(), - value[1].toI32(), - value[2].toI32() - ) - ); - } - - verifySpentVoiceCredits(_spent: BigInt, _salt: BigInt): boolean { - let result = super.call( - "verifySpentVoiceCredits", - "verifySpentVoiceCredits(uint256,uint256):(bool)", - [ - ethereum.Value.fromUnsignedBigInt(_spent), - ethereum.Value.fromUnsignedBigInt(_salt) - ] - ); - - return result[0].toBoolean(); - } - - try_verifySpentVoiceCredits( - _spent: BigInt, - _salt: BigInt - ): ethereum.CallResult { - let result = super.tryCall( - "verifySpentVoiceCredits", - "verifySpentVoiceCredits(uint256,uint256):(bool)", - [ - ethereum.Value.fromUnsignedBigInt(_spent), - ethereum.Value.fromUnsignedBigInt(_salt) - ] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); - } - - voteOptionsMaxLeafIndex(): BigInt { - let result = super.call( - "voteOptionsMaxLeafIndex", - "voteOptionsMaxLeafIndex():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_voteOptionsMaxLeafIndex(): ethereum.CallResult { - let result = super.tryCall( - "voteOptionsMaxLeafIndex", - "voteOptionsMaxLeafIndex():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } - - votingDurationSeconds(): BigInt { - let result = super.call( - "votingDurationSeconds", - "votingDurationSeconds():(uint256)", - [] - ); - - return result[0].toBigInt(); - } - - try_votingDurationSeconds(): ethereum.CallResult { - let result = super.tryCall( - "votingDurationSeconds", - "votingDurationSeconds():(uint256)", - [] - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } -} - -export class ConstructorCall extends ethereum.Call { - get inputs(): ConstructorCall__Inputs { - return new ConstructorCall__Inputs(this); - } - - get outputs(): ConstructorCall__Outputs { - return new ConstructorCall__Outputs(this); - } -} - -export class ConstructorCall__Inputs { - _call: ConstructorCall; - - constructor(call: ConstructorCall) { - this._call = call; - } - - get _treeDepths(): ConstructorCall_treeDepthsStruct { - return this._call.inputValues[0].value.toTuple() as ConstructorCall_treeDepthsStruct; - } - - get _batchSizes(): ConstructorCall_batchSizesStruct { - return this._call.inputValues[1].value.toTuple() as ConstructorCall_batchSizesStruct; - } - - get _maxValues(): ConstructorCall_maxValuesStruct { - return this._call.inputValues[2].value.toTuple() as ConstructorCall_maxValuesStruct; - } - - get _signUpGatekeeper(): Address { - return this._call.inputValues[3].value.toAddress(); - } - - get _batchUstVerifier(): Address { - return this._call.inputValues[4].value.toAddress(); - } - - get _qvtVerifier(): Address { - return this._call.inputValues[5].value.toAddress(); - } - - get _signUpDurationSeconds(): BigInt { - return this._call.inputValues[6].value.toBigInt(); - } - - get _votingDurationSeconds(): BigInt { - return this._call.inputValues[7].value.toBigInt(); - } - - get _initialVoiceCreditProxy(): Address { - return this._call.inputValues[8].value.toAddress(); - } - - get _coordinatorPubKey(): ConstructorCall_coordinatorPubKeyStruct { - return this._call.inputValues[9].value.toTuple() as ConstructorCall_coordinatorPubKeyStruct; - } - - get _coordinatorAddress(): Address { - return this._call.inputValues[10].value.toAddress(); - } -} - -export class ConstructorCall__Outputs { - _call: ConstructorCall; - - constructor(call: ConstructorCall) { - this._call = call; - } -} - -export class ConstructorCall_treeDepthsStruct extends ethereum.Tuple { - get stateTreeDepth(): i32 { - return this[0].toI32(); - } - - get messageTreeDepth(): i32 { - return this[1].toI32(); - } - - get voteOptionTreeDepth(): i32 { - return this[2].toI32(); - } -} - -export class ConstructorCall_batchSizesStruct extends ethereum.Tuple { - get tallyBatchSize(): i32 { - return this[0].toI32(); - } - - get messageBatchSize(): i32 { - return this[1].toI32(); - } -} - -export class ConstructorCall_maxValuesStruct extends ethereum.Tuple { - get maxUsers(): BigInt { - return this[0].toBigInt(); - } - - get maxMessages(): BigInt { - return this[1].toBigInt(); - } - - get maxVoteOptions(): BigInt { - return this[2].toBigInt(); - } -} - -export class ConstructorCall_coordinatorPubKeyStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class BatchProcessMessageCall extends ethereum.Call { - get inputs(): BatchProcessMessageCall__Inputs { - return new BatchProcessMessageCall__Inputs(this); - } - - get outputs(): BatchProcessMessageCall__Outputs { - return new BatchProcessMessageCall__Outputs(this); - } -} - -export class BatchProcessMessageCall__Inputs { - _call: BatchProcessMessageCall; - - constructor(call: BatchProcessMessageCall) { - this._call = call; - } - - get _newStateRoot(): BigInt { - return this._call.inputValues[0].value.toBigInt(); - } - - get _ecdhPubKeys(): Array { - return this._call.inputValues[1].value.toTupleArray< - BatchProcessMessageCall_ecdhPubKeysStruct - >(); - } - - get _proof(): Array { - return this._call.inputValues[2].value.toBigIntArray(); - } -} - -export class BatchProcessMessageCall__Outputs { - _call: BatchProcessMessageCall; - - constructor(call: BatchProcessMessageCall) { - this._call = call; - } -} - -export class BatchProcessMessageCall_ecdhPubKeysStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class CoordinatorResetCall extends ethereum.Call { - get inputs(): CoordinatorResetCall__Inputs { - return new CoordinatorResetCall__Inputs(this); - } - - get outputs(): CoordinatorResetCall__Outputs { - return new CoordinatorResetCall__Outputs(this); - } -} - -export class CoordinatorResetCall__Inputs { - _call: CoordinatorResetCall; - - constructor(call: CoordinatorResetCall) { - this._call = call; - } -} - -export class CoordinatorResetCall__Outputs { - _call: CoordinatorResetCall; - - constructor(call: CoordinatorResetCall) { - this._call = call; - } -} - -export class ProveVoteTallyBatchCall extends ethereum.Call { - get inputs(): ProveVoteTallyBatchCall__Inputs { - return new ProveVoteTallyBatchCall__Inputs(this); - } - - get outputs(): ProveVoteTallyBatchCall__Outputs { - return new ProveVoteTallyBatchCall__Outputs(this); - } -} - -export class ProveVoteTallyBatchCall__Inputs { - _call: ProveVoteTallyBatchCall; - - constructor(call: ProveVoteTallyBatchCall) { - this._call = call; - } - - get _intermediateStateRoot(): BigInt { - return this._call.inputValues[0].value.toBigInt(); - } - - get _newResultsCommitment(): BigInt { - return this._call.inputValues[1].value.toBigInt(); - } - - get _newSpentVoiceCreditsCommitment(): BigInt { - return this._call.inputValues[2].value.toBigInt(); - } - - get _newPerVOSpentVoiceCreditsCommitment(): BigInt { - return this._call.inputValues[3].value.toBigInt(); - } - - get _totalVotes(): BigInt { - return this._call.inputValues[4].value.toBigInt(); - } - - get _proof(): Array { - return this._call.inputValues[5].value.toBigIntArray(); - } -} - -export class ProveVoteTallyBatchCall__Outputs { - _call: ProveVoteTallyBatchCall; - - constructor(call: ProveVoteTallyBatchCall) { - this._call = call; - } -} - -export class PublishMessageCall extends ethereum.Call { - get inputs(): PublishMessageCall__Inputs { - return new PublishMessageCall__Inputs(this); - } - - get outputs(): PublishMessageCall__Outputs { - return new PublishMessageCall__Outputs(this); - } -} - -export class PublishMessageCall__Inputs { - _call: PublishMessageCall; - - constructor(call: PublishMessageCall) { - this._call = call; - } - - get _message(): PublishMessageCall_messageStruct { - return this._call.inputValues[0].value.toTuple() as PublishMessageCall_messageStruct; - } - - get _encPubKey(): PublishMessageCall_encPubKeyStruct { - return this._call.inputValues[1].value.toTuple() as PublishMessageCall_encPubKeyStruct; - } -} - -export class PublishMessageCall__Outputs { - _call: PublishMessageCall; - - constructor(call: PublishMessageCall) { - this._call = call; - } -} - -export class PublishMessageCall_messageStruct extends ethereum.Tuple { - get iv(): BigInt { - return this[0].toBigInt(); - } - - get data(): Array { - return this[1].toBigIntArray(); - } -} - -export class PublishMessageCall_encPubKeyStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} - -export class SignUpCall extends ethereum.Call { - get inputs(): SignUpCall__Inputs { - return new SignUpCall__Inputs(this); - } - - get outputs(): SignUpCall__Outputs { - return new SignUpCall__Outputs(this); - } -} - -export class SignUpCall__Inputs { - _call: SignUpCall; - - constructor(call: SignUpCall) { - this._call = call; - } - - get _userPubKey(): SignUpCall_userPubKeyStruct { - return this._call.inputValues[0].value.toTuple() as SignUpCall_userPubKeyStruct; - } - - get _signUpGatekeeperData(): Bytes { - return this._call.inputValues[1].value.toBytes(); - } - - get _initialVoiceCreditProxyData(): Bytes { - return this._call.inputValues[2].value.toBytes(); - } -} - -export class SignUpCall__Outputs { - _call: SignUpCall; - - constructor(call: SignUpCall) { - this._call = call; - } -} - -export class SignUpCall_userPubKeyStruct extends ethereum.Tuple { - get x(): BigInt { - return this[0].toBigInt(); - } - - get y(): BigInt { - return this[1].toBigInt(); - } -} diff --git a/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts b/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts index 40919cd1e..e1591f36b 100644 --- a/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts +++ b/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts @@ -32,6 +32,32 @@ export class OwnershipTransferred__Params { } } +export class Registered extends ethereum.Event { + get params(): Registered__Params { + return new Registered__Params(this); + } +} + +export class Registered__Params { + _event: Registered; + + constructor(event: Registered) { + this._event = event; + } + + get addr(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get timestamp(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get isVerified(): boolean { + return this._event.parameters[2].value.toBoolean(); + } +} + export class SetBrightIdSettings extends ethereum.Event { get params(): SetBrightIdSettings__Params { return new SetBrightIdSettings__Params(this); @@ -52,23 +78,9 @@ export class SetBrightIdSettings__Params { get verifier(): Address { return this._event.parameters[1].value.toAddress(); } -} - -export class Sponsor extends ethereum.Event { - get params(): Sponsor__Params { - return new Sponsor__Params(this); - } -} - -export class Sponsor__Params { - _event: Sponsor; - - constructor(event: Sponsor) { - this._event = event; - } - get addr(): Address { - return this._event.parameters[0].value.toAddress(); + get sponsor(): Address { + return this._event.parameters[2].value.toAddress(); } } @@ -94,34 +106,42 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return new BrightIdUserRegistry("BrightIdUserRegistry", address); } - context(): Bytes { - let result = super.call("context", "context():(bytes32)", []); + brightIdSponsor(): Address { + let result = super.call( + "brightIdSponsor", + "brightIdSponsor():(address)", + [] + ); - return result[0].toBytes(); + return result[0].toAddress(); } - try_context(): ethereum.CallResult { - let result = super.tryCall("context", "context():(bytes32)", []); + try_brightIdSponsor(): ethereum.CallResult
{ + let result = super.tryCall( + "brightIdSponsor", + "brightIdSponsor():(address)", + [] + ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBytes()); + return ethereum.CallResult.fromValue(value[0].toAddress()); } - isOwner(): boolean { - let result = super.call("isOwner", "isOwner():(bool)", []); + context(): Bytes { + let result = super.call("context", "context():(bytes32)", []); - return result[0].toBoolean(); + return result[0].toBytes(); } - try_isOwner(): ethereum.CallResult { - let result = super.tryCall("isOwner", "isOwner():(bool)", []); + try_context(): ethereum.CallResult { + let result = super.tryCall("context", "context():(bytes32)", []); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); + return ethereum.CallResult.fromValue(value[0].toBytes()); } isVerifiedUser(_user: Address): boolean { @@ -235,6 +255,10 @@ export class ConstructorCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } + + get _sponsor(): Address { + return this._call.inputValues[2].value.toAddress(); + } } export class ConstructorCall__Outputs { @@ -266,24 +290,28 @@ export class RegisterCall__Inputs { return this._call.inputValues[0].value.toBytes(); } - get _addrs(): Array
{ - return this._call.inputValues[1].value.toAddressArray(); + get _addr(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _verificationHash(): Bytes { + return this._call.inputValues[2].value.toBytes(); } get _timestamp(): BigInt { - return this._call.inputValues[2].value.toBigInt(); + return this._call.inputValues[3].value.toBigInt(); } get _v(): i32 { - return this._call.inputValues[3].value.toI32(); + return this._call.inputValues[4].value.toI32(); } get _r(): Bytes { - return this._call.inputValues[4].value.toBytes(); + return this._call.inputValues[5].value.toBytes(); } get _s(): Bytes { - return this._call.inputValues[5].value.toBytes(); + return this._call.inputValues[6].value.toBytes(); } } @@ -345,6 +373,10 @@ export class SetSettingsCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } + + get _sponsor(): Address { + return this._call.inputValues[2].value.toAddress(); + } } export class SetSettingsCall__Outputs { diff --git a/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts b/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts index 40919cd1e..e1591f36b 100644 --- a/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts +++ b/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts @@ -32,6 +32,32 @@ export class OwnershipTransferred__Params { } } +export class Registered extends ethereum.Event { + get params(): Registered__Params { + return new Registered__Params(this); + } +} + +export class Registered__Params { + _event: Registered; + + constructor(event: Registered) { + this._event = event; + } + + get addr(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get timestamp(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get isVerified(): boolean { + return this._event.parameters[2].value.toBoolean(); + } +} + export class SetBrightIdSettings extends ethereum.Event { get params(): SetBrightIdSettings__Params { return new SetBrightIdSettings__Params(this); @@ -52,23 +78,9 @@ export class SetBrightIdSettings__Params { get verifier(): Address { return this._event.parameters[1].value.toAddress(); } -} - -export class Sponsor extends ethereum.Event { - get params(): Sponsor__Params { - return new Sponsor__Params(this); - } -} - -export class Sponsor__Params { - _event: Sponsor; - - constructor(event: Sponsor) { - this._event = event; - } - get addr(): Address { - return this._event.parameters[0].value.toAddress(); + get sponsor(): Address { + return this._event.parameters[2].value.toAddress(); } } @@ -94,34 +106,42 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return new BrightIdUserRegistry("BrightIdUserRegistry", address); } - context(): Bytes { - let result = super.call("context", "context():(bytes32)", []); + brightIdSponsor(): Address { + let result = super.call( + "brightIdSponsor", + "brightIdSponsor():(address)", + [] + ); - return result[0].toBytes(); + return result[0].toAddress(); } - try_context(): ethereum.CallResult { - let result = super.tryCall("context", "context():(bytes32)", []); + try_brightIdSponsor(): ethereum.CallResult
{ + let result = super.tryCall( + "brightIdSponsor", + "brightIdSponsor():(address)", + [] + ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBytes()); + return ethereum.CallResult.fromValue(value[0].toAddress()); } - isOwner(): boolean { - let result = super.call("isOwner", "isOwner():(bool)", []); + context(): Bytes { + let result = super.call("context", "context():(bytes32)", []); - return result[0].toBoolean(); + return result[0].toBytes(); } - try_isOwner(): ethereum.CallResult { - let result = super.tryCall("isOwner", "isOwner():(bool)", []); + try_context(): ethereum.CallResult { + let result = super.tryCall("context", "context():(bytes32)", []); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); + return ethereum.CallResult.fromValue(value[0].toBytes()); } isVerifiedUser(_user: Address): boolean { @@ -235,6 +255,10 @@ export class ConstructorCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } + + get _sponsor(): Address { + return this._call.inputValues[2].value.toAddress(); + } } export class ConstructorCall__Outputs { @@ -266,24 +290,28 @@ export class RegisterCall__Inputs { return this._call.inputValues[0].value.toBytes(); } - get _addrs(): Array
{ - return this._call.inputValues[1].value.toAddressArray(); + get _addr(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _verificationHash(): Bytes { + return this._call.inputValues[2].value.toBytes(); } get _timestamp(): BigInt { - return this._call.inputValues[2].value.toBigInt(); + return this._call.inputValues[3].value.toBigInt(); } get _v(): i32 { - return this._call.inputValues[3].value.toI32(); + return this._call.inputValues[4].value.toI32(); } get _r(): Bytes { - return this._call.inputValues[4].value.toBytes(); + return this._call.inputValues[5].value.toBytes(); } get _s(): Bytes { - return this._call.inputValues[5].value.toBytes(); + return this._call.inputValues[6].value.toBytes(); } } @@ -345,6 +373,10 @@ export class SetSettingsCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } + + get _sponsor(): Address { + return this._call.inputValues[2].value.toAddress(); + } } export class SetSettingsCall__Outputs { diff --git a/subgraph/src/BrightIdUserRegistryMapping.ts b/subgraph/src/BrightIdUserRegistryMapping.ts index 2f685fa49..80e7257f2 100644 --- a/subgraph/src/BrightIdUserRegistryMapping.ts +++ b/subgraph/src/BrightIdUserRegistryMapping.ts @@ -2,7 +2,7 @@ import { log } from '@graphprotocol/graph-ts' import { OwnershipTransferred, SetBrightIdSettings, - Sponsor, + Registered, } from '../generated/templates/BrightIdUserRegistry/BrightIdUserRegistry' import { BrightIdUserRegistry as BrightIdUserRegistryContract } from '../generated/templates/BrightIdUserRegistry/BrightIdUserRegistry' @@ -33,24 +33,13 @@ export function handleSetBrightIdSettings(event: SetBrightIdSettings): void { log.info('handleSetBrightIdSettings', []) } -export function handleSponsor(event: Sponsor): void { - log.info('handleSponsor', []) - - //TODO: create contributorRegistry entity here if it does not exist. +export function handleRegister(event: Registered): void { + log.info('handleRegister', []) let contributorId = event.params.addr.toHexString() - let brightIdUserRegistryContract = BrightIdUserRegistryContract.bind( - event.address - ) - - //DEBT: Retroactively register here as there are no events emitted in registration function let contributor = new Contributor(contributorId) - contributor.verified = brightIdUserRegistryContract.verifications( - event.params.addr - ).value1 - contributor.verifiedTimeStamp = brightIdUserRegistryContract - .verifications(event.params.addr) - .value0.toString() + contributor.verified = event.params.isVerified + contributor.verifiedTimeStamp = event.params.timestamp.toString() contributor.contributorAddress = event.params.addr contributor.contributorRegistry = event.address.toHexString() contributor.save() diff --git a/subgraph/src/FundingRoundFactoryMapping.ts b/subgraph/src/FundingRoundFactoryMapping.ts index 21dbe152a..66318bc5b 100644 --- a/subgraph/src/FundingRoundFactoryMapping.ts +++ b/subgraph/src/FundingRoundFactoryMapping.ts @@ -117,22 +117,27 @@ export function handleRoundStarted(event: RoundStarted): void { //NOTE: If the contracts aren't being tracked initialize them if (recipientRegistry == null) { - log.info('New recipientRegistry', []) + log.info('New recipientRegistry {}', [recipientRegistryAddress.toHex()]) + let recipientRegistry = new RecipientRegistry(recipientRegistryId) + recipientRegistryTemplate.create(recipientRegistryAddress) let recipientRegistryContract = RecipientRegistryContract.bind( recipientRegistryAddress ) - let baseDeposit = recipientRegistryContract.baseDeposit() - let challengePeriodDuration = - recipientRegistryContract.challengePeriodDuration() + let baseDeposit = recipientRegistryContract.try_baseDeposit() + if (baseDeposit.reverted) { + recipientRegistry.baseDeposit = BigInt.fromI32(0) + recipientRegistry.challengePeriodDuration = BigInt.fromI32(0) + } else { + recipientRegistry.baseDeposit = baseDeposit.value + let challengePeriodDuration = + recipientRegistryContract.challengePeriodDuration() + recipientRegistry.challengePeriodDuration = challengePeriodDuration + } let controller = recipientRegistryContract.controller() let maxRecipients = recipientRegistryContract.maxRecipients() let owner = recipientRegistryContract.owner() - let recipientRegistry = new RecipientRegistry(recipientRegistryId) - - recipientRegistry.baseDeposit = baseDeposit - recipientRegistry.challengePeriodDuration = challengePeriodDuration recipientRegistry.controller = controller recipientRegistry.maxRecipients = maxRecipients recipientRegistry.owner = owner diff --git a/subgraph/subgraph.template.yaml b/subgraph/subgraph.template.yaml index 4e391d58b..2dc52de33 100644 --- a/subgraph/subgraph.template.yaml +++ b/subgraph/subgraph.template.yaml @@ -149,10 +149,8 @@ templates: eventHandlers: - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - - event: SetBrightIdSettings(bytes32,address) + - event: SetBrightIdSettings(bytes32,address,address) handler: handleSetBrightIdSettings - - event: Sponsor(indexed address) - handler: handleSponsor file: ./src/BrightIdUserRegistryMapping.ts - name: MACI kind: ethereum/contract diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index db5674c69..4e9d5059e 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -149,10 +149,8 @@ templates: eventHandlers: - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - - event: SetBrightIdSettings(bytes32,address) + - event: SetBrightIdSettings(bytes32,address,address) handler: handleSetBrightIdSettings - - event: Sponsor(indexed address) - handler: handleSponsor file: ./src/BrightIdUserRegistryMapping.ts - name: MACI kind: ethereum/contract diff --git a/vue-app/.env.example b/vue-app/.env.example index 0ca3ec51c..410768892 100644 --- a/vue-app/.env.example +++ b/vue-app/.env.example @@ -6,6 +6,11 @@ VUE_APP_ETHEREUM_API_URL=http://localhost:18545 VUE_APP_ETHEREUM_API_CHAINID=31337 VUE_APP_INFURA_ID= VUE_APP_IPFS_GATEWAY_URL=https://ipfs.io + +# ipfs file upload and pinning url +VUE_APP_IPFS_PINNING_URL=https://api.pinata.cloud/pinning/pinFileToIPFS +# pinata api JWT for api authorization +VUE_APP_IPFS_PINNING_JWT= VUE_APP_SUBGRAPH_URL=http://localhost:8000/subgraphs/name/daodesigner/clrfund # Comma-separated list of URLs @@ -42,4 +47,4 @@ GOOGLE_APPLICATION_CREDENTIALS= # Spreadsheet ID to send recipients data VUE_APP_GOOGLE_SPREADSHEET_ID= # Select the sheet's name to write the data, by default 'Raw' -GOOGLE_SHEET_NAME= \ No newline at end of file +GOOGLE_SHEET_NAME= diff --git a/vue-app/package.json b/vue-app/package.json index f86df88cf..79c6d1e92 100644 --- a/vue-app/package.json +++ b/vue-app/package.json @@ -15,6 +15,7 @@ "@kleros/gtcr-encoder": "^1.4.0", "@openfonts/inter_all": "^1.0.2", "@walletconnect/web3-provider": "^1.5.1", + "axios": "^0.27.2", "core-js": "^3.6.4", "crypto-js": "^4.0.0", "ethereum-blockies-base64": "^1.0.2", @@ -23,7 +24,6 @@ "graphql-request": "^3.5.0", "gun": "https://github.com/amark/gun", "humanize-duration": "^3.25.1", - "ipfs-mini": "^1.1.5", "is-ipfs": "^2.0.0", "luxon": "^1.26.0", "maci-domainobjs": "~0.7.4", diff --git a/vue-app/src/api/bright-id.ts b/vue-app/src/api/bright-id.ts index 554cd59bb..21a97f17f 100644 --- a/vue-app/src/api/bright-id.ts +++ b/vue-app/src/api/bright-id.ts @@ -16,7 +16,8 @@ export interface BrightId { export interface Verification { unique: boolean - contextIds: string[] + appUserId: string + verificationHash: string sig: { r: string; s: string; v: number } timestamp: number app: string @@ -55,10 +56,11 @@ export async function getVerification( const apiUrl = `${NODE_URL}/verifications/${CONTEXT}/${userAddress}?signed=eth×tamp=seconds` const response = await fetch(apiUrl) const data = await response.json() + if (data['error']) { throw new BrightIdError(data['errorNum']) } else { - return data['data'] + return data['data'][0] } } @@ -70,7 +72,8 @@ export async function registerUser( const registry = new Contract(registryAddress, BrightIdUserRegistry, signer) const transaction = await registry.register( formatBytes32String(CONTEXT), - verification.contextIds, + verification.appUserId, + '0x' + verification.verificationHash, verification.timestamp, verification.sig.v, '0x' + verification.sig.r, diff --git a/vue-app/src/api/core.ts b/vue-app/src/api/core.ts index 015b69c07..fc9ddbac0 100644 --- a/vue-app/src/api/core.ts +++ b/vue-app/src/api/core.ts @@ -17,6 +17,11 @@ export const gunPeers: string[] = process.env.VUE_APP_GUN_PEERS ? process.env.VUE_APP_GUN_PEERS.split(',') : [] +export const ipfsPinningUrl = process.env.VUE_APP_IPFS_PINNING_URL +if (!ipfsPinningUrl) throw new Error('invalid ipfs pinning url') +export const ipfsPinningJwt = process.env.VUE_APP_IPFS_PINNING_JWT +if (!ipfsPinningJwt) throw new Error('invalid ipfs pinning JWT') + //TODO: need to be able to pass the factory contract address dynamically, note all places this is used make factory address a parameter that defaults to the env. variable set //NOTE: these calls will be replaced by subgraph queries eventually. export const factory = new ethers.Contract( diff --git a/vue-app/src/api/ipfs.ts b/vue-app/src/api/ipfs.ts new file mode 100644 index 000000000..7ddc191ca --- /dev/null +++ b/vue-app/src/api/ipfs.ts @@ -0,0 +1,28 @@ +import { ipfsPinningUrl, ipfsPinningJwt } from './core' +import axios from 'axios' + +export class IPFS { + url: string + jwt: string + + constructor() { + this.url = ipfsPinningUrl || '' + this.jwt = ipfsPinningJwt || '' + } + + async add(file: Blob): Promise { + const data = new FormData() + data.append('file', file) + + const options = { + method: 'POST', + url: this.url, + headers: { + Authorization: `Bearer ${this.jwt}`, + }, + data, + } + const response = await axios(options) + return response.data.IpfsHash + } +} diff --git a/vue-app/src/components/IpfsImageUpload.vue b/vue-app/src/components/IpfsImageUpload.vue index 051ab1e89..0e4045cc8 100644 --- a/vue-app/src/components/IpfsImageUpload.vue +++ b/vue-app/src/components/IpfsImageUpload.vue @@ -20,7 +20,7 @@ type="submit" label="Upload" class="btn-primary" - :disabled="loading || error || !loadedImageData" + :disabled="loading || error || !loadedImageHeight" > {{ loading ? 'Uploading...' : 'Upload' }} @@ -68,7 +68,7 @@ import { ipfsGatewayUrl } from '@/api/core' import Loader from '@/components/Loader.vue' import IpfsCopyWidget from '@/components/IpfsCopyWidget.vue' -import IPFS from 'ipfs-mini' +import { IPFS } from '@/api/ipfs' @Component({ components: { @@ -85,17 +85,13 @@ export default class IpfsImageUpload extends Vue { ipfs: any = null hash = '' loading = false - loadedImageData = '' + loadedImageFile: File | null = null loadedImageHeight: number | null = null loadedImageWidth: number | null = null error = '' created() { - this.ipfs = new IPFS({ - host: 'ipfs.infura.io', - port: 5001, - protocol: 'https', - }) + this.ipfs = new IPFS() } // TODO raise error if not valid image (JPG / PNG / GIF) @@ -113,11 +109,11 @@ export default class IpfsImageUpload extends Vue { this.error = 'Upload an image smaller than 512 kB' return } + this.loadedImageFile = data const reader = new FileReader() reader.onload = (() => (e) => { - this.loadedImageData = e.target.result const img = new Image() - img.src = this.loadedImageData + img.src = String(e.target?.result) img.onload = () => { this.loadedImageHeight = img.height this.loadedImageWidth = img.width @@ -129,21 +125,18 @@ export default class IpfsImageUpload extends Vue { // TODO display error in UI handleUploadToIPFS(event) { event.preventDefault() - // Work-around: Raw image data can be loaded through an SVG - // https://github.com/SilentCicero/ipfs-mini/issues/4#issuecomment-792351498 - const fileContents = `` if ( - this.loadedImageData !== '' && + this.loadedImageFile && this.loadedImageHeight && this.loadedImageWidth ) { this.loading = true this.ipfs - .add(fileContents) + .add(this.loadedImageFile) .then((hash) => { this.hash = hash /* eslint-disable-next-line no-console */ - console.log(`Uploaded file hash: ${hash}`) + console.log(`Uploaded file hash:`, hash) this.onUpload(this.formProp, hash) this.loading = false }) @@ -159,7 +152,6 @@ export default class IpfsImageUpload extends Vue { handleRemoveImage(): void { this.hash = '' this.loading = false - this.loadedImageData = '' this.error = '' this.onUpload(this.formProp, '') diff --git a/vue-app/src/views/Verify.vue b/vue-app/src/views/Verify.vue index eaba2be68..9af9098d9 100644 --- a/vue-app/src/views/Verify.vue +++ b/vue-app/src/views/Verify.vue @@ -96,17 +96,6 @@
{{ errorMessage }} - - A different verified account was found. Please use - - {{ - differentVerifiedAccountShortAddress - }} - or a new account. - Account is not verified @@ -310,7 +299,6 @@ export default class VerifyView extends Vue { loadingManualVerify = false showVerificationResult = false errorMessage = '' - differentVerifiedAccount = '' get currentUser(): User { return this.$store.state.currentUser @@ -412,7 +400,6 @@ export default class VerifyView extends Vue { async handleIsVerifiedClick() { this.loadingManualVerify = true this.errorMessage = '' - this.differentVerifiedAccount = '' this.showVerificationResult = false try { @@ -425,13 +412,6 @@ export default class VerifyView extends Vue { brightId, }) }, 5000) - } else { - if (brightId.verification) { - if (!brightId.verification.unique) { - this.differentVerifiedAccount = - brightId.verification?.contextIds[0] || '' - } - } } } catch (error) { if (!(error instanceof BrightIdError)) { @@ -503,14 +483,6 @@ export default class VerifyView extends Vue { return false } } - - get differentVerifiedAccountExplorerUrl(): string { - return `${chain.explorer}/address/${this.differentVerifiedAccount}` - } - - get differentVerifiedAccountShortAddress(): string { - return renderAddressOrHash(this.differentVerifiedAccount, 8) - } } diff --git a/yarn.lock b/yarn.lock index d72ca8d30..b1b082981 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4761,6 +4761,14 @@ axios@^0.21.1: dependencies: follow-redirects "^1.14.0" +axios@^0.27.2: + version "0.27.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" + integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== + dependencies: + follow-redirects "^1.14.9" + form-data "^4.0.0" + babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -9904,7 +9912,7 @@ fnv-plus@^1.3.1: resolved "https://registry.yarnpkg.com/fnv-plus/-/fnv-plus-1.3.1.tgz#c34cb4572565434acb08ba257e4044ce2b006d67" integrity sha512-Gz1EvfOneuFfk4yG458dJ3TLJ7gV19q3OM/vVvvHf7eT02Hm1DleB4edsia6ahbKgAYxO9gvyQ1ioWZR+a00Yw== -follow-redirects@^1.0.0, follow-redirects@^1.12.1, follow-redirects@^1.14.0: +follow-redirects@^1.0.0, follow-redirects@^1.12.1, follow-redirects@^1.14.0, follow-redirects@^1.14.9: version "1.15.1" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA== @@ -9940,7 +9948,7 @@ fork-ts-checker-webpack-plugin@^3.1.1: tapable "^1.0.0" worker-rpc "^0.1.0" -form-data@4.0.0: +form-data@4.0.0, form-data@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== @@ -11483,13 +11491,6 @@ ipfs-http-client@^34.0.0: tar-stream "^2.0.1" through2 "^3.0.1" -ipfs-mini@^1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/ipfs-mini/-/ipfs-mini-1.1.5.tgz#1ffd1f0b048814aabbdfa24c77cde255c5b11fc7" - integrity sha512-BzsoCa3V/gxN2eEHnyqggOdreAwnvbddj4jUvp6Q7jXuzXx9q5XakXe8mG8qV0bn4bMKdH/7BUDbiWBCEMuYBg== - dependencies: - xmlhttprequest "^1.8.0" - ipfs-only-hash@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/ipfs-only-hash/-/ipfs-only-hash-2.0.1.tgz#4756dfdeb73160d557a0d4512f7f70e40f127ee3" @@ -20664,7 +20665,7 @@ xmlchars@^2.1.1: resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb" integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw== -xmlhttprequest@1.8.0, xmlhttprequest@^1.8.0: +xmlhttprequest@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw= From 736589e32d264de0892786a71699008c635eef93 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 12 Aug 2022 19:52:01 -0400 Subject: [PATCH 04/12] fix lint warning --- vue-app/src/views/Verify.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/vue-app/src/views/Verify.vue b/vue-app/src/views/Verify.vue index 9af9098d9..443e336ed 100644 --- a/vue-app/src/views/Verify.vue +++ b/vue-app/src/views/Verify.vue @@ -254,8 +254,6 @@ import { getBrightId, } from '@/api/bright-id' import { User } from '@/api/user' -import { chain } from '@/api/core' -import { renderAddressOrHash } from '@/utils/accounts' import Transaction from '@/components/Transaction.vue' import Loader from '@/components/Loader.vue' import Links from '@/components/Links.vue' From bddbd411b19fc06be8f9accf5c0f5ea882fdb7c0 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Tue, 16 Aug 2022 12:27:54 -0400 Subject: [PATCH 05/12] replace axios with fetch --- vue-app/package.json | 1 - vue-app/src/api/ipfs.ts | 12 ++++++------ vue-app/src/components/IpfsImageUpload.vue | 6 ++++-- yarn.lock | 12 ++---------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/vue-app/package.json b/vue-app/package.json index 79c6d1e92..58650289b 100644 --- a/vue-app/package.json +++ b/vue-app/package.json @@ -15,7 +15,6 @@ "@kleros/gtcr-encoder": "^1.4.0", "@openfonts/inter_all": "^1.0.2", "@walletconnect/web3-provider": "^1.5.1", - "axios": "^0.27.2", "core-js": "^3.6.4", "crypto-js": "^4.0.0", "ethereum-blockies-base64": "^1.0.2", diff --git a/vue-app/src/api/ipfs.ts b/vue-app/src/api/ipfs.ts index 7ddc191ca..afb4d4342 100644 --- a/vue-app/src/api/ipfs.ts +++ b/vue-app/src/api/ipfs.ts @@ -1,5 +1,4 @@ import { ipfsPinningUrl, ipfsPinningJwt } from './core' -import axios from 'axios' export class IPFS { url: string @@ -10,19 +9,20 @@ export class IPFS { this.jwt = ipfsPinningJwt || '' } - async add(file: Blob): Promise { + async add(file: File): Promise { const data = new FormData() data.append('file', file) const options = { method: 'POST', - url: this.url, headers: { Authorization: `Bearer ${this.jwt}`, }, - data, + body: data, } - const response = await axios(options) - return response.data.IpfsHash + + const result = await fetch(this.url, options) + const json = await result.json() + return json.IpfsHash } } diff --git a/vue-app/src/components/IpfsImageUpload.vue b/vue-app/src/components/IpfsImageUpload.vue index 0e4045cc8..03a505c74 100644 --- a/vue-app/src/components/IpfsImageUpload.vue +++ b/vue-app/src/components/IpfsImageUpload.vue @@ -20,7 +20,7 @@ type="submit" label="Upload" class="btn-primary" - :disabled="loading || error || !loadedImageHeight" + :disabled="loading || error || !loadedImageFile" > {{ loading ? 'Uploading...' : 'Upload' }} @@ -82,7 +82,7 @@ export default class IpfsImageUpload extends Vue { @Prop() formProp!: string @Prop() onUpload!: (key: string, value: string) => void - ipfs: any = null + ipfs: IPFS | null = null hash = '' loading = false loadedImageFile: File | null = null @@ -126,6 +126,7 @@ export default class IpfsImageUpload extends Vue { handleUploadToIPFS(event) { event.preventDefault() if ( + this.ipfs && this.loadedImageFile && this.loadedImageHeight && this.loadedImageWidth @@ -153,6 +154,7 @@ export default class IpfsImageUpload extends Vue { this.hash = '' this.loading = false this.error = '' + this.loadedImageFile = null this.onUpload(this.formProp, '') // Clear file selector input diff --git a/yarn.lock b/yarn.lock index b1b082981..407d44c89 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4761,14 +4761,6 @@ axios@^0.21.1: dependencies: follow-redirects "^1.14.0" -axios@^0.27.2: - version "0.27.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== - dependencies: - follow-redirects "^1.14.9" - form-data "^4.0.0" - babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -9912,7 +9904,7 @@ fnv-plus@^1.3.1: resolved "https://registry.yarnpkg.com/fnv-plus/-/fnv-plus-1.3.1.tgz#c34cb4572565434acb08ba257e4044ce2b006d67" integrity sha512-Gz1EvfOneuFfk4yG458dJ3TLJ7gV19q3OM/vVvvHf7eT02Hm1DleB4edsia6ahbKgAYxO9gvyQ1ioWZR+a00Yw== -follow-redirects@^1.0.0, follow-redirects@^1.12.1, follow-redirects@^1.14.0, follow-redirects@^1.14.9: +follow-redirects@^1.0.0, follow-redirects@^1.12.1, follow-redirects@^1.14.0: version "1.15.1" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA== @@ -9948,7 +9940,7 @@ fork-ts-checker-webpack-plugin@^3.1.1: tapable "^1.0.0" worker-rpc "^0.1.0" -form-data@4.0.0, form-data@^4.0.0: +form-data@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== From a7b992b2048a7c1db048470b54d706f93ffe11d2 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Tue, 16 Aug 2022 23:33:05 -0400 Subject: [PATCH 06/12] pass sponsor address to create brightId user registry --- contracts/scripts/deploy.ts | 3 ++- contracts/scripts/deployRound.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/scripts/deploy.ts b/contracts/scripts/deploy.ts index 512abc22e..9f7dfc93c 100644 --- a/contracts/scripts/deploy.ts +++ b/contracts/scripts/deploy.ts @@ -44,7 +44,8 @@ async function main() { userRegistry = await BrightIdUserRegistry.deploy( utils.formatBytes32String(process.env.BRIGHTID_CONTEXT || 'clr.fund'), - process.env.BRIGHTID_VERIFIER_ADDR + process.env.BRIGHTID_VERIFIER_ADDR, + process.env.BRIGHTID_SPONSOR ) } else { throw new Error('unsupported user registry type') diff --git a/contracts/scripts/deployRound.ts b/contracts/scripts/deployRound.ts index 0402539d1..abf5cf51e 100644 --- a/contracts/scripts/deployRound.ts +++ b/contracts/scripts/deployRound.ts @@ -48,7 +48,8 @@ async function main() { ) userRegistry = await BrightIdUserRegistry.deploy( utils.formatBytes32String(process.env.BRIGHTID_CONTEXT || 'clr.fund'), - process.env.BRIGHTID_VERIFIER_ADDR + process.env.BRIGHTID_VERIFIER_ADDR, + process.env.BRIGHTID_SPONSOR ) } else { throw new Error('unsupported user registry type') From 2335e0befa476eba7e3ba2ebe181c662b4a684a7 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Tue, 23 Aug 2022 01:12:56 -0400 Subject: [PATCH 07/12] Changed user verification and registration flow for BrightId v6 --- contracts/.env.example | 6 + .../userRegistry/BrightIdUserRegistry.sol | 65 ++- contracts/scripts/deployRound.ts | 13 + contracts/scripts/deployTestRound.ts | 17 + contracts/scripts/deployUserRegistry.ts | 7 +- contracts/scripts/newRound.ts | 73 ++++ contracts/tests/userRegistryBrightId.ts | 223 ++++++++++ subgraph/abis/BrightIdUserRegistry.json | 112 ++++- .../BrightIdUserRegistry.ts | 200 +++++++-- subgraph/generated/schema.ts | 9 - .../BrightIdUserRegistry.ts | 200 +++++++-- .../FundingRound/BrightIdUserRegistry.ts | 200 +++++++-- subgraph/schema.graphql | 1 - subgraph/src/BrightIdUserRegistryMapping.ts | 1 - subgraph/src/FundingRoundMapping.ts | 2 - subgraph/subgraph.template.yaml | 8 +- subgraph/subgraph.yaml | 8 +- vue-app/src/App.vue | 2 + vue-app/src/api/bright-id.ts | 39 +- vue-app/src/components/BrightIdWidget.vue | 36 +- vue-app/src/components/CallToActionCard.vue | 2 +- vue-app/src/router/index.ts | 27 ++ vue-app/src/store/actions.ts | 7 +- vue-app/src/views/AboutSybilResistance.vue | 21 +- vue-app/src/views/BrightIdGuide.vue | 49 +++ vue-app/src/views/BrightIdSponsor.vue | 105 +++++ vue-app/src/views/BrightIdSponsored.vue | 166 ++++++++ vue-app/src/views/Profile.vue | 5 +- vue-app/src/views/Verified.vue | 2 +- vue-app/src/views/Verify.vue | 389 +----------------- vue-app/src/views/VerifyLanding.vue | 29 +- 31 files changed, 1431 insertions(+), 593 deletions(-) create mode 100644 contracts/scripts/newRound.ts create mode 100644 contracts/tests/userRegistryBrightId.ts create mode 100644 vue-app/src/views/BrightIdGuide.vue create mode 100644 vue-app/src/views/BrightIdSponsor.vue create mode 100644 vue-app/src/views/BrightIdSponsored.vue diff --git a/contracts/.env.example b/contracts/.env.example index 8d6b37a9c..98d3a8243 100644 --- a/contracts/.env.example +++ b/contracts/.env.example @@ -8,6 +8,12 @@ BRIGHTID_CONTEXT=clr.fund # BrightId node addr that signs verifications. Node One uses this one BRIGHTID_VERIFIER_ADDR=0xb1d71F62bEe34E9Fc349234C201090c33BCdF6DB +# used in the BrightId sponsor deployment script +BRIGHTID_USER_REGISTRY= + +# used in the BrightId user registry deployment script +FUNDING_ROUND_FACTORY_ADDRESS + # JSON-RPC endpoint to the selected network JSONRPC_HTTP_URL=https://eth-goerli.alchemyapi.io/v2/ADD_API_KEY diff --git a/contracts/contracts/userRegistry/BrightIdUserRegistry.sol b/contracts/contracts/userRegistry/BrightIdUserRegistry.sol index db6da4c20..2b2e8ce1f 100644 --- a/contracts/contracts/userRegistry/BrightIdUserRegistry.sol +++ b/contracts/contracts/userRegistry/BrightIdUserRegistry.sol @@ -11,28 +11,39 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { string private constant ERROR_NOT_AUTHORIZED = 'NOT AUTHORIZED'; string private constant ERROR_INVALID_VERIFIER = 'INVALID VERIFIER'; string private constant ERROR_INVALID_CONTEXT = 'INVALID CONTEXT'; + string private constant ERROR_INVALID_SPONSOR = 'INVALID SPONSOR'; + string private constant ERROR_INVALID_REGISTRATION_PERIOD = 'INVALID REGISTRATION PERIOD'; + string private constant ERROR_EXPIRED_VERIFICATION = 'EXPIRED VERIFICATION'; + string private constant ERROR_REGISTRATION_CLOSED = 'REGISTRATION CLOSED'; bytes32 public context; address public verifier; BrightIdSponsor public brightIdSponsor; + // Only register a verified user during this period + uint256 public registrationStartTime; + uint256 public registrationDeadline; struct Verification { uint256 time; - bool isVerified; } mapping(address => Verification) public verifications; - event SetBrightIdSettings(bytes32 context, address verifier, address sponsor); - event Registered(address indexed addr, uint256 timestamp, bool isVerified); + event SetBrightIdSettings(bytes32 context, address verifier); + + event Registered(address indexed addr, uint256 timestamp); + event RegistrationPeriodChanged(uint256 startTime, uint256 deadline); + event SponsorChanged(address sponsor); /** * @param _context BrightID context used for verifying users * @param _verifier BrightID verifier address that signs BrightID verifications + * @param _sponsor Contract address that emits BrightID sponsor event */ constructor(bytes32 _context, address _verifier, address _sponsor) public { // ecrecover returns zero on error require(_verifier != address(0), ERROR_INVALID_VERIFIER); + require(_sponsor != address(0), ERROR_INVALID_SPONSOR); context = _context; verifier = _verifier; @@ -52,14 +63,37 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { * @param _context BrightID context used for verifying users * @param _verifier BrightID verifier address that signs BrightID verifications */ - function setSettings(bytes32 _context, address _verifier, address _sponsor) external onlyOwner { + function setSettings(bytes32 _context, address _verifier) external onlyOwner { // ecrecover returns zero on error require(_verifier != address(0), ERROR_INVALID_VERIFIER); context = _context; verifier = _verifier; + emit SetBrightIdSettings(_context, _verifier); + } + + /** + * @notice Set BrightID sponsor + * @param _sponsor Contract address that emits BrightID sponsor event + */ + function setSponsor(address _sponsor) external onlyOwner { + require(_sponsor != address(0), ERROR_INVALID_SPONSOR); + brightIdSponsor = BrightIdSponsor(_sponsor); - emit SetBrightIdSettings(_context, _verifier, _sponsor); + emit SponsorChanged(_sponsor); + } + + /** + * @notice Set the registration period for verified users + * @param _startTime Registration start time + * @param _deadline Registration deadline + */ + function setRegistrationPeriod(uint256 _startTime, uint256 _deadline) external onlyOwner { + require(_startTime <= _deadline, ERROR_INVALID_REGISTRATION_PERIOD); + + registrationStartTime = _startTime; + registrationDeadline = _deadline; + emit RegistrationPeriodChanged(_startTime, _deadline); } /** @@ -72,9 +106,23 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { view returns (bool) { - return verifications[_user].isVerified; + Verification memory verification = verifications[_user]; + return canRegister(verification.time); } + /** + * @notice check if the registry is open for registration + * @param _timestamp timestamp + */ + function canRegister(uint256 _timestamp) + public + view + returns (bool) + { + return _timestamp > 0 + && _timestamp >= registrationStartTime + && _timestamp < registrationDeadline; + } /** * @notice Register a user by BrightID verification @@ -97,14 +145,15 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { ) external { require(context == _context, ERROR_INVALID_CONTEXT); require(verifications[_addr].time < _timestamp, ERROR_NEWER_VERIFICATION); + require(canRegister(block.timestamp), ERROR_REGISTRATION_CLOSED); + require(canRegister(_timestamp), ERROR_EXPIRED_VERIFICATION); bytes32 message = keccak256(abi.encodePacked(_context, _addr, _verificationHash, _timestamp)); address signer = ecrecover(message, _v, _r, _s); require(verifier == signer, ERROR_NOT_AUTHORIZED); verifications[_addr].time = _timestamp; - verifications[_addr].isVerified = true; - emit Registered(_addr, _timestamp, true); + emit Registered(_addr, _timestamp); } } diff --git a/contracts/scripts/deployRound.ts b/contracts/scripts/deployRound.ts index abf5cf51e..ebd71e53d 100644 --- a/contracts/scripts/deployRound.ts +++ b/contracts/scripts/deployRound.ts @@ -167,6 +167,7 @@ async function main() { deployer.address ) await addFundingSourceTx.wait() + console.log('Added funding source', addFundingSourceTx.hash) const deployNewRoundTx = await fundingRoundFactory.deployNewRound() await deployNewRoundTx.wait() @@ -228,6 +229,18 @@ async function main() { const maciAddress = await fundingRound.maci() console.log('maci.address: ', maciAddress) + if (userRegistryType === 'brightid') { + const maci = await ethers.getContractAt('MACI', maciAddress) + const startTime = await maci.signUpTimestamp() + const endTime = await maci.calcSignUpDeadline() + const periodTx = await userRegistry.setRegistrationPeriod( + startTime, + endTime + ) + console.log('Set user registration period', periodTx.hash) + await periodTx.wait() + } + console.log('*******************') console.log('Deploy complete!') console.log('*******************') diff --git a/contracts/scripts/deployTestRound.ts b/contracts/scripts/deployTestRound.ts index 9e2f89fec..e3b05c4e7 100644 --- a/contracts/scripts/deployTestRound.ts +++ b/contracts/scripts/deployTestRound.ts @@ -288,6 +288,23 @@ async function main() { const maciAddress = await fundingRound.maci() console.log(`MACI address: ${maciAddress}`) + if (userRegistryType === 'brightid') { + const userRegistryAddress = await fundingRound.userRegistry() + const userRegistry = await ethers.getContractAt( + 'BrightIdUserRegistry', + userRegistryAddress + ) + const maci = await ethers.getContractAt('MACI', maciAddress) + const startTime = await maci.signUpTimestamp() + const endTime = await maci.calcSignUpDeadline() + const periodTx = await userRegistry.setRegistrationPeriod( + startTime, + endTime + ) + console.log('Set user registration period', periodTx.hash) + await periodTx.wait() + } + const recipientRegistryType = process.env.RECIPIENT_REGISTRY_TYPE || 'simple' const recipientRegistryAddress = await factory.recipientRegistry() if (recipientRegistryType === 'simple') { diff --git a/contracts/scripts/deployUserRegistry.ts b/contracts/scripts/deployUserRegistry.ts index 21a1ff1d3..cfaf9e542 100644 --- a/contracts/scripts/deployUserRegistry.ts +++ b/contracts/scripts/deployUserRegistry.ts @@ -35,19 +35,20 @@ async function main() { 'BrightIdUserRegistry', deployer ) + userRegistry = await BrightIdUserRegistry.deploy( - utils.formatBytes32String(process.env.BRIGHTID_CONTEXT), + utils.formatBytes32String(process.env.BRIGHTID_CONTEXT || 'clr.fund'), process.env.BRIGHTID_VERIFIER_ADDR, process.env.BRIGHTID_SPONSOR ) + console.log('transaction hash', userRegistry.deployTransaction.hash) } else { throw new Error('unsupported user registry type') } - const receipt = await userRegistry.deployTransaction.wait() + await userRegistry.deployTransaction.wait() console.log( `Deployed ${userRegistryType} user registry at ${userRegistry.address}` ) - console.log('transaction hash', receipt.transactionHash) const setUserRegistryTx = await fundingRoundFactory.setUserRegistry( userRegistry.address diff --git a/contracts/scripts/newRound.ts b/contracts/scripts/newRound.ts new file mode 100644 index 000000000..7ba3466d7 --- /dev/null +++ b/contracts/scripts/newRound.ts @@ -0,0 +1,73 @@ +import { ethers } from 'hardhat' + +async function main() { + console.log('*******************') + console.log('Start a new funding round!') + console.log('*******************') + const [deployer] = await ethers.getSigners() + console.log('deployer.address: ', deployer.address) + + const fundingRoundFactoryAddress = process.env.FUNDING_ROUND_FACTORY_ADDRESS + const userRegistryType = process.env.USER_REGISTRY_TYPE + + if (!fundingRoundFactoryAddress) { + throw new Error( + 'Environment variable FUNDING_ROUND_FACTORY_ADDRESS is not setup' + ) + } + if (!userRegistryType) { + throw new Error('Environment variable USER_REGISTRY_TYPE is not setup') + } + + const factory = await ethers.getContractAt( + 'FundingRoundFactory', + fundingRoundFactoryAddress + ) + console.log('funding round factory address ', factory.address) + + const tx = await factory.deployNewRound() + console.log('deployNewRound tx hash: ', tx.hash) + await tx.wait() + + const fundingRoundAddress = await factory.getCurrentRound() + console.log('new funding round address: ', fundingRoundAddress) + + // for BrightId user registry, we need to activate the registry + // by setting the registration period to match maci signup period + if (userRegistryType === 'brightid') { + // get maci signup period + const fundingRound = await ethers.getContractAt( + 'FundingRound', + fundingRoundAddress + ) + const maciAddress = await fundingRound.maci() + console.log('maci address: ', maciAddress) + const maci = await ethers.getContractAt('MACI', maciAddress) + const startTime = await maci.signUpTimestamp() + const endTime = await maci.calcSignUpDeadline() + + // set user registration period + const userRegistryAddress = await fundingRound.userRegistry() + const userRegistry = await ethers.getContractAt( + 'BrightIdUserRegistry', + userRegistryAddress + ) + const periodTx = await userRegistry.setRegistrationPeriod( + startTime, + endTime + ) + console.log('User registration period changed at', periodTx.hash) + await periodTx.wait() + } + + console.log('*******************') + console.log('Script complete!') + console.log('*******************') +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + }) diff --git a/contracts/tests/userRegistryBrightId.ts b/contracts/tests/userRegistryBrightId.ts new file mode 100644 index 000000000..5fc719b58 --- /dev/null +++ b/contracts/tests/userRegistryBrightId.ts @@ -0,0 +1,223 @@ +import { ethers, waffle } from 'hardhat' +import { use, expect } from 'chai' +import { solidity } from 'ethereum-waffle' +import { Contract, providers, utils } from 'ethers' +import { ZERO_ADDRESS } from '../utils/constants' + +use(solidity) + +const verifier = ethers.Wallet.createRandom() +const signingKey = new utils.SigningKey(verifier.privateKey) + +const context = utils.formatBytes32String('clrfund-goerli') +const verificationHash = + '0xc99d46ae8baaa7ed2766cbf34e566de43decc2ff7d8e3da5cb80e72f3b5e20de' + +type Verification = { + appUserId: string + sig: { + r: string + s: string + v: number + } + timestamp: number + verificationHash: string +} + +async function getBlockTimestamp( + provider: providers.Provider +): Promise { + const blockNumber = await provider.getBlockNumber() + const block = await provider.getBlock(blockNumber) + return block.timestamp +} + +function generateVerification( + appUserId: string, + timestamp: number, + anotherSigner?: utils.SigningKey +): Verification { + const message = utils.solidityKeccak256( + ['bytes32', 'address', 'bytes32', 'uint256'], + [context, appUserId, verificationHash, timestamp] + ) + const sig = anotherSigner + ? anotherSigner.signDigest(message) + : signingKey.signDigest(message) + + return { + appUserId, + sig, + timestamp, + verificationHash, + } +} + +function register(registry: Contract, verification: Verification) { + return registry.register( + context, + verification.appUserId, + verification.verificationHash, + verification.timestamp, + verification.sig.v, + verification.sig.r, + verification.sig.s + ) +} + +describe('BrightId User Registry', () => { + const provider = waffle.provider + const [, deployer, user] = provider.getWallets() + + let registry: Contract + let sponsor: Contract + + beforeEach(async () => { + const BrightIdSponsor = await ethers.getContractFactory( + 'BrightIdSponsor', + deployer + ) + sponsor = await BrightIdSponsor.deploy() + + const BrightIdUserRegistry = await ethers.getContractFactory( + 'BrightIdUserRegistry', + deployer + ) + registry = await BrightIdUserRegistry.deploy( + context, + verifier.address, + sponsor.address + ) + }) + + describe('registration period not set', () => { + it('rejects registration', async () => { + const timestamp = await getBlockTimestamp(provider) + const verification = generateVerification(user.address, timestamp) + await expect(register(registry, verification)).to.be.revertedWith( + 'REGISTRATION CLOSED' + ) + }) + it('isVerifiedUser returns false', async () => { + expect(await registry.isVerifiedUser(deployer.address)).to.equal(false) + }) + }) + + it('reject invalid registration period', async () => { + await expect(registry.setRegistrationPeriod(3, 2)).to.be.revertedWith( + 'INVALID REGISTRATION PERIOD' + ) + }) + it('reject invalid verifier', async () => { + await expect( + registry.setSettings(context, ZERO_ADDRESS) + ).to.be.revertedWith('INVALID VERIFIER') + }) + it('reject invalid sponsor', async () => { + await expect(registry.setSponsor(ZERO_ADDRESS)).to.be.revertedWith( + 'INVALID SPONSOR' + ) + }) + + it('allows valid settings', async () => { + await expect(registry.setSettings(context, verifier.address)) + .to.emit(registry, 'SetBrightIdSettings') + .withArgs(context, verifier.address) + }) + + it('allows valid sponsor', async () => { + await expect(registry.setSponsor(sponsor.address)) + .to.emit(registry, 'SponsorChanged') + .withArgs(sponsor.address) + }) + + it('allows valid registration period', async () => { + await expect(registry.setRegistrationPeriod(1, 2)) + .to.emit(registry, 'RegistrationPeriodChanged') + .withArgs(1, 2) + }) + + describe('registration', () => { + let blockTimestamp: number + let invalidTimestamp: number + let deadline: number + + beforeEach(async () => { + const blockNumber = await provider.getBlockNumber() + const block = await provider.getBlock(blockNumber) + invalidTimestamp = block.timestamp + 1 + const startTime = block.timestamp + 2 + blockTimestamp = block.timestamp + 5 + deadline = startTime + 500 + const tx = await registry.setRegistrationPeriod(startTime, deadline) + await tx.wait() + }) + + describe('canRegister', () => { + it('returns true for valid timestamp', async () => { + await expect(await registry.canRegister(blockTimestamp)).to.equal(true) + }) + + it('returns false for invalid timestamp', async () => { + await expect(await registry.canRegister(invalidTimestamp)).to.equal( + false + ) + }) + }) + + it('allows valid verified user to register', async () => { + const verification = generateVerification(user.address, blockTimestamp) + expect(await registry.isVerifiedUser(user.address)).to.equal(false) + await expect(register(registry, verification)) + .to.emit(registry, 'Registered') + .withArgs(user.address, verification.timestamp) + + expect(await registry.isVerifiedUser(user.address)).to.equal(true) + }) + + it('rejects older verifications', async () => { + expect(await registry.isVerifiedUser(user.address)).to.equal(false) + const oldTime = blockTimestamp + const newTime = blockTimestamp + 1 + const oldVerification = generateVerification(user.address, oldTime) + const newVerification = generateVerification(user.address, newTime) + await expect(register(registry, newVerification)) + .to.emit(registry, 'Registered') + .withArgs(user.address, newVerification.timestamp) + + await expect(register(registry, oldVerification)).to.be.revertedWith( + 'NEWER VERIFICATION REGISTERED BEFORE' + ) + + expect(await registry.isVerifiedUser(user.address)).to.equal(true) + }) + + it('rejects invalid verifications', async () => { + const timestamp = blockTimestamp + const signer = new utils.SigningKey(user.privateKey) + const verification = generateVerification(user.address, timestamp, signer) + await expect(register(registry, verification)).to.be.revertedWith( + 'NOT AUTHORIZED' + ) + }) + + it('rejects verifications after deadline', async () => { + const verification = generateVerification(user.address, deadline + 1) + await expect(register(registry, verification)).to.be.revertedWith( + 'EXPIRED VERIFICATION' + ) + }) + + it('rejects invalid context', async () => { + const verification = generateVerification(user.address, blockTimestamp) + const tx = await registry.setSettings( + utils.formatBytes32String('invalid'), + verifier.address + ) + await tx.wait() + await expect(register(registry, verification)).to.be.revertedWith( + 'INVALID CONTEXT' + ) + }) + }) +}) diff --git a/subgraph/abis/BrightIdUserRegistry.json b/subgraph/abis/BrightIdUserRegistry.json index d6e00bcba..d7a1b1e4c 100644 --- a/subgraph/abis/BrightIdUserRegistry.json +++ b/subgraph/abis/BrightIdUserRegistry.json @@ -53,15 +53,28 @@ "internalType": "uint256", "name": "timestamp", "type": "uint256" + } + ], + "name": "Registered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "startTime", + "type": "uint256" }, { "indexed": false, - "internalType": "bool", - "name": "isVerified", - "type": "bool" + "internalType": "uint256", + "name": "deadline", + "type": "uint256" } ], - "name": "Registered", + "name": "RegistrationPeriodChanged", "type": "event" }, { @@ -78,7 +91,14 @@ "internalType": "address", "name": "verifier", "type": "address" - }, + } + ], + "name": "SetBrightIdSettings", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ { "indexed": false, "internalType": "address", @@ -86,7 +106,7 @@ "type": "address" } ], - "name": "SetBrightIdSettings", + "name": "SponsorChanged", "type": "event" }, { @@ -102,6 +122,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_timestamp", + "type": "uint256" + } + ], + "name": "canRegister", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "context", @@ -190,6 +229,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "registrationDeadline", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "registrationStartTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "renounceOwnership", @@ -197,6 +262,24 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_startTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_deadline", + "type": "uint256" + } + ], + "name": "setRegistrationPeriod", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -208,14 +291,22 @@ "internalType": "address", "name": "_verifier", "type": "address" - }, + } + ], + "name": "setSettings", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ { "internalType": "address", "name": "_sponsor", "type": "address" } ], - "name": "setSettings", + "name": "setSponsor", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -260,11 +351,6 @@ "internalType": "uint256", "name": "time", "type": "uint256" - }, - { - "internalType": "bool", - "name": "isVerified", - "type": "bool" } ], "stateMutability": "view", diff --git a/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts b/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts index e1591f36b..26a35e7b0 100644 --- a/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts +++ b/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts @@ -52,9 +52,27 @@ export class Registered__Params { get timestamp(): BigInt { return this._event.parameters[1].value.toBigInt(); } +} - get isVerified(): boolean { - return this._event.parameters[2].value.toBoolean(); +export class RegistrationPeriodChanged extends ethereum.Event { + get params(): RegistrationPeriodChanged__Params { + return new RegistrationPeriodChanged__Params(this); + } +} + +export class RegistrationPeriodChanged__Params { + _event: RegistrationPeriodChanged; + + constructor(event: RegistrationPeriodChanged) { + this._event = event; + } + + get startTime(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get deadline(): BigInt { + return this._event.parameters[1].value.toBigInt(); } } @@ -78,26 +96,23 @@ export class SetBrightIdSettings__Params { get verifier(): Address { return this._event.parameters[1].value.toAddress(); } +} - get sponsor(): Address { - return this._event.parameters[2].value.toAddress(); +export class SponsorChanged extends ethereum.Event { + get params(): SponsorChanged__Params { + return new SponsorChanged__Params(this); } } -export class BrightIdUserRegistry__verificationsResult { - value0: BigInt; - value1: boolean; +export class SponsorChanged__Params { + _event: SponsorChanged; - constructor(value0: BigInt, value1: boolean) { - this.value0 = value0; - this.value1 = value1; + constructor(event: SponsorChanged) { + this._event = event; } - toMap(): TypedMap { - let map = new TypedMap(); - map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); - map.set("value1", ethereum.Value.fromBoolean(this.value1)); - return map; + get sponsor(): Address { + return this._event.parameters[0].value.toAddress(); } } @@ -129,6 +144,25 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } + canRegister(_timestamp: BigInt): boolean { + let result = super.call("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); + + return result[0].toBoolean(); + } + + try_canRegister(_timestamp: BigInt): ethereum.CallResult { + let result = super.tryCall("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + context(): Bytes { let result = super.call("context", "context():(bytes32)", []); @@ -182,37 +216,73 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } - verifications(param0: Address): BrightIdUserRegistry__verificationsResult { + registrationDeadline(): BigInt { + let result = super.call( + "registrationDeadline", + "registrationDeadline():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_registrationDeadline(): ethereum.CallResult { + let result = super.tryCall( + "registrationDeadline", + "registrationDeadline():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + registrationStartTime(): BigInt { + let result = super.call( + "registrationStartTime", + "registrationStartTime():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_registrationStartTime(): ethereum.CallResult { + let result = super.tryCall( + "registrationStartTime", + "registrationStartTime():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + verifications(param0: Address): BigInt { let result = super.call( "verifications", - "verifications(address):(uint256,bool)", + "verifications(address):(uint256)", [ethereum.Value.fromAddress(param0)] ); - return new BrightIdUserRegistry__verificationsResult( - result[0].toBigInt(), - result[1].toBoolean() - ); + return result[0].toBigInt(); } - try_verifications( - param0: Address - ): ethereum.CallResult { + try_verifications(param0: Address): ethereum.CallResult { let result = super.tryCall( "verifications", - "verifications(address):(uint256,bool)", + "verifications(address):(uint256)", [ethereum.Value.fromAddress(param0)] ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue( - new BrightIdUserRegistry__verificationsResult( - value[0].toBigInt(), - value[1].toBoolean() - ) - ); + return ethereum.CallResult.fromValue(value[0].toBigInt()); } verifier(): Address { @@ -349,6 +419,40 @@ export class RenounceOwnershipCall__Outputs { } } +export class SetRegistrationPeriodCall extends ethereum.Call { + get inputs(): SetRegistrationPeriodCall__Inputs { + return new SetRegistrationPeriodCall__Inputs(this); + } + + get outputs(): SetRegistrationPeriodCall__Outputs { + return new SetRegistrationPeriodCall__Outputs(this); + } +} + +export class SetRegistrationPeriodCall__Inputs { + _call: SetRegistrationPeriodCall; + + constructor(call: SetRegistrationPeriodCall) { + this._call = call; + } + + get _startTime(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } + + get _deadline(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class SetRegistrationPeriodCall__Outputs { + _call: SetRegistrationPeriodCall; + + constructor(call: SetRegistrationPeriodCall) { + this._call = call; + } +} + export class SetSettingsCall extends ethereum.Call { get inputs(): SetSettingsCall__Inputs { return new SetSettingsCall__Inputs(this); @@ -373,10 +477,6 @@ export class SetSettingsCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } - - get _sponsor(): Address { - return this._call.inputValues[2].value.toAddress(); - } } export class SetSettingsCall__Outputs { @@ -387,6 +487,36 @@ export class SetSettingsCall__Outputs { } } +export class SetSponsorCall extends ethereum.Call { + get inputs(): SetSponsorCall__Inputs { + return new SetSponsorCall__Inputs(this); + } + + get outputs(): SetSponsorCall__Outputs { + return new SetSponsorCall__Outputs(this); + } +} + +export class SetSponsorCall__Inputs { + _call: SetSponsorCall; + + constructor(call: SetSponsorCall) { + this._call = call; + } + + get _sponsor(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetSponsorCall__Outputs { + _call: SetSponsorCall; + + constructor(call: SetSponsorCall) { + this._call = call; + } +} + export class SponsorCall extends ethereum.Call { get inputs(): SponsorCall__Inputs { return new SponsorCall__Inputs(this); diff --git a/subgraph/generated/schema.ts b/subgraph/generated/schema.ts index a868e9c45..b437eedd9 100644 --- a/subgraph/generated/schema.ts +++ b/subgraph/generated/schema.ts @@ -1820,15 +1820,6 @@ export class Contributor extends Entity { } } - get verified(): boolean { - let value = this.get("verified"); - return value.toBoolean(); - } - - set verified(value: boolean) { - this.set("verified", Value.fromBoolean(value)); - } - get verifiedTimeStamp(): string | null { let value = this.get("verifiedTimeStamp"); if (value === null || value.kind == ValueKind.NULL) { diff --git a/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts b/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts index e1591f36b..26a35e7b0 100644 --- a/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts +++ b/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts @@ -52,9 +52,27 @@ export class Registered__Params { get timestamp(): BigInt { return this._event.parameters[1].value.toBigInt(); } +} - get isVerified(): boolean { - return this._event.parameters[2].value.toBoolean(); +export class RegistrationPeriodChanged extends ethereum.Event { + get params(): RegistrationPeriodChanged__Params { + return new RegistrationPeriodChanged__Params(this); + } +} + +export class RegistrationPeriodChanged__Params { + _event: RegistrationPeriodChanged; + + constructor(event: RegistrationPeriodChanged) { + this._event = event; + } + + get startTime(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get deadline(): BigInt { + return this._event.parameters[1].value.toBigInt(); } } @@ -78,26 +96,23 @@ export class SetBrightIdSettings__Params { get verifier(): Address { return this._event.parameters[1].value.toAddress(); } +} - get sponsor(): Address { - return this._event.parameters[2].value.toAddress(); +export class SponsorChanged extends ethereum.Event { + get params(): SponsorChanged__Params { + return new SponsorChanged__Params(this); } } -export class BrightIdUserRegistry__verificationsResult { - value0: BigInt; - value1: boolean; +export class SponsorChanged__Params { + _event: SponsorChanged; - constructor(value0: BigInt, value1: boolean) { - this.value0 = value0; - this.value1 = value1; + constructor(event: SponsorChanged) { + this._event = event; } - toMap(): TypedMap { - let map = new TypedMap(); - map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); - map.set("value1", ethereum.Value.fromBoolean(this.value1)); - return map; + get sponsor(): Address { + return this._event.parameters[0].value.toAddress(); } } @@ -129,6 +144,25 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } + canRegister(_timestamp: BigInt): boolean { + let result = super.call("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); + + return result[0].toBoolean(); + } + + try_canRegister(_timestamp: BigInt): ethereum.CallResult { + let result = super.tryCall("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + context(): Bytes { let result = super.call("context", "context():(bytes32)", []); @@ -182,37 +216,73 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } - verifications(param0: Address): BrightIdUserRegistry__verificationsResult { + registrationDeadline(): BigInt { + let result = super.call( + "registrationDeadline", + "registrationDeadline():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_registrationDeadline(): ethereum.CallResult { + let result = super.tryCall( + "registrationDeadline", + "registrationDeadline():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + registrationStartTime(): BigInt { + let result = super.call( + "registrationStartTime", + "registrationStartTime():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_registrationStartTime(): ethereum.CallResult { + let result = super.tryCall( + "registrationStartTime", + "registrationStartTime():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + verifications(param0: Address): BigInt { let result = super.call( "verifications", - "verifications(address):(uint256,bool)", + "verifications(address):(uint256)", [ethereum.Value.fromAddress(param0)] ); - return new BrightIdUserRegistry__verificationsResult( - result[0].toBigInt(), - result[1].toBoolean() - ); + return result[0].toBigInt(); } - try_verifications( - param0: Address - ): ethereum.CallResult { + try_verifications(param0: Address): ethereum.CallResult { let result = super.tryCall( "verifications", - "verifications(address):(uint256,bool)", + "verifications(address):(uint256)", [ethereum.Value.fromAddress(param0)] ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue( - new BrightIdUserRegistry__verificationsResult( - value[0].toBigInt(), - value[1].toBoolean() - ) - ); + return ethereum.CallResult.fromValue(value[0].toBigInt()); } verifier(): Address { @@ -349,6 +419,40 @@ export class RenounceOwnershipCall__Outputs { } } +export class SetRegistrationPeriodCall extends ethereum.Call { + get inputs(): SetRegistrationPeriodCall__Inputs { + return new SetRegistrationPeriodCall__Inputs(this); + } + + get outputs(): SetRegistrationPeriodCall__Outputs { + return new SetRegistrationPeriodCall__Outputs(this); + } +} + +export class SetRegistrationPeriodCall__Inputs { + _call: SetRegistrationPeriodCall; + + constructor(call: SetRegistrationPeriodCall) { + this._call = call; + } + + get _startTime(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } + + get _deadline(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class SetRegistrationPeriodCall__Outputs { + _call: SetRegistrationPeriodCall; + + constructor(call: SetRegistrationPeriodCall) { + this._call = call; + } +} + export class SetSettingsCall extends ethereum.Call { get inputs(): SetSettingsCall__Inputs { return new SetSettingsCall__Inputs(this); @@ -373,10 +477,6 @@ export class SetSettingsCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } - - get _sponsor(): Address { - return this._call.inputValues[2].value.toAddress(); - } } export class SetSettingsCall__Outputs { @@ -387,6 +487,36 @@ export class SetSettingsCall__Outputs { } } +export class SetSponsorCall extends ethereum.Call { + get inputs(): SetSponsorCall__Inputs { + return new SetSponsorCall__Inputs(this); + } + + get outputs(): SetSponsorCall__Outputs { + return new SetSponsorCall__Outputs(this); + } +} + +export class SetSponsorCall__Inputs { + _call: SetSponsorCall; + + constructor(call: SetSponsorCall) { + this._call = call; + } + + get _sponsor(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetSponsorCall__Outputs { + _call: SetSponsorCall; + + constructor(call: SetSponsorCall) { + this._call = call; + } +} + export class SponsorCall extends ethereum.Call { get inputs(): SponsorCall__Inputs { return new SponsorCall__Inputs(this); diff --git a/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts b/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts index e1591f36b..26a35e7b0 100644 --- a/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts +++ b/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts @@ -52,9 +52,27 @@ export class Registered__Params { get timestamp(): BigInt { return this._event.parameters[1].value.toBigInt(); } +} - get isVerified(): boolean { - return this._event.parameters[2].value.toBoolean(); +export class RegistrationPeriodChanged extends ethereum.Event { + get params(): RegistrationPeriodChanged__Params { + return new RegistrationPeriodChanged__Params(this); + } +} + +export class RegistrationPeriodChanged__Params { + _event: RegistrationPeriodChanged; + + constructor(event: RegistrationPeriodChanged) { + this._event = event; + } + + get startTime(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get deadline(): BigInt { + return this._event.parameters[1].value.toBigInt(); } } @@ -78,26 +96,23 @@ export class SetBrightIdSettings__Params { get verifier(): Address { return this._event.parameters[1].value.toAddress(); } +} - get sponsor(): Address { - return this._event.parameters[2].value.toAddress(); +export class SponsorChanged extends ethereum.Event { + get params(): SponsorChanged__Params { + return new SponsorChanged__Params(this); } } -export class BrightIdUserRegistry__verificationsResult { - value0: BigInt; - value1: boolean; +export class SponsorChanged__Params { + _event: SponsorChanged; - constructor(value0: BigInt, value1: boolean) { - this.value0 = value0; - this.value1 = value1; + constructor(event: SponsorChanged) { + this._event = event; } - toMap(): TypedMap { - let map = new TypedMap(); - map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); - map.set("value1", ethereum.Value.fromBoolean(this.value1)); - return map; + get sponsor(): Address { + return this._event.parameters[0].value.toAddress(); } } @@ -129,6 +144,25 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } + canRegister(_timestamp: BigInt): boolean { + let result = super.call("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); + + return result[0].toBoolean(); + } + + try_canRegister(_timestamp: BigInt): ethereum.CallResult { + let result = super.tryCall("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + context(): Bytes { let result = super.call("context", "context():(bytes32)", []); @@ -182,37 +216,73 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } - verifications(param0: Address): BrightIdUserRegistry__verificationsResult { + registrationDeadline(): BigInt { + let result = super.call( + "registrationDeadline", + "registrationDeadline():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_registrationDeadline(): ethereum.CallResult { + let result = super.tryCall( + "registrationDeadline", + "registrationDeadline():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + registrationStartTime(): BigInt { + let result = super.call( + "registrationStartTime", + "registrationStartTime():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_registrationStartTime(): ethereum.CallResult { + let result = super.tryCall( + "registrationStartTime", + "registrationStartTime():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + verifications(param0: Address): BigInt { let result = super.call( "verifications", - "verifications(address):(uint256,bool)", + "verifications(address):(uint256)", [ethereum.Value.fromAddress(param0)] ); - return new BrightIdUserRegistry__verificationsResult( - result[0].toBigInt(), - result[1].toBoolean() - ); + return result[0].toBigInt(); } - try_verifications( - param0: Address - ): ethereum.CallResult { + try_verifications(param0: Address): ethereum.CallResult { let result = super.tryCall( "verifications", - "verifications(address):(uint256,bool)", + "verifications(address):(uint256)", [ethereum.Value.fromAddress(param0)] ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue( - new BrightIdUserRegistry__verificationsResult( - value[0].toBigInt(), - value[1].toBoolean() - ) - ); + return ethereum.CallResult.fromValue(value[0].toBigInt()); } verifier(): Address { @@ -349,6 +419,40 @@ export class RenounceOwnershipCall__Outputs { } } +export class SetRegistrationPeriodCall extends ethereum.Call { + get inputs(): SetRegistrationPeriodCall__Inputs { + return new SetRegistrationPeriodCall__Inputs(this); + } + + get outputs(): SetRegistrationPeriodCall__Outputs { + return new SetRegistrationPeriodCall__Outputs(this); + } +} + +export class SetRegistrationPeriodCall__Inputs { + _call: SetRegistrationPeriodCall; + + constructor(call: SetRegistrationPeriodCall) { + this._call = call; + } + + get _startTime(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } + + get _deadline(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class SetRegistrationPeriodCall__Outputs { + _call: SetRegistrationPeriodCall; + + constructor(call: SetRegistrationPeriodCall) { + this._call = call; + } +} + export class SetSettingsCall extends ethereum.Call { get inputs(): SetSettingsCall__Inputs { return new SetSettingsCall__Inputs(this); @@ -373,10 +477,6 @@ export class SetSettingsCall__Inputs { get _verifier(): Address { return this._call.inputValues[1].value.toAddress(); } - - get _sponsor(): Address { - return this._call.inputValues[2].value.toAddress(); - } } export class SetSettingsCall__Outputs { @@ -387,6 +487,36 @@ export class SetSettingsCall__Outputs { } } +export class SetSponsorCall extends ethereum.Call { + get inputs(): SetSponsorCall__Inputs { + return new SetSponsorCall__Inputs(this); + } + + get outputs(): SetSponsorCall__Outputs { + return new SetSponsorCall__Outputs(this); + } +} + +export class SetSponsorCall__Inputs { + _call: SetSponsorCall; + + constructor(call: SetSponsorCall) { + this._call = call; + } + + get _sponsor(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetSponsorCall__Outputs { + _call: SetSponsorCall; + + constructor(call: SetSponsorCall) { + this._call = call; + } +} + export class SponsorCall extends ethereum.Call { get inputs(): SponsorCall__Inputs { return new SponsorCall__Inputs(this); diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index c87363f76..824f1b5fe 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -137,7 +137,6 @@ type Contributor @entity { contributorRegistry: ContributorRegistry! votes: [Vote!] @derivedFrom(field: "contributor") - verified: Boolean verifiedTimeStamp: String # sponsors: [Bytes] contributorAddress: Bytes diff --git a/subgraph/src/BrightIdUserRegistryMapping.ts b/subgraph/src/BrightIdUserRegistryMapping.ts index 80e7257f2..8bd6943ae 100644 --- a/subgraph/src/BrightIdUserRegistryMapping.ts +++ b/subgraph/src/BrightIdUserRegistryMapping.ts @@ -38,7 +38,6 @@ export function handleRegister(event: Registered): void { let contributorId = event.params.addr.toHexString() let contributor = new Contributor(contributorId) - contributor.verified = event.params.isVerified contributor.verifiedTimeStamp = event.params.timestamp.toString() contributor.contributorAddress = event.params.addr contributor.contributorRegistry = event.address.toHexString() diff --git a/subgraph/src/FundingRoundMapping.ts b/subgraph/src/FundingRoundMapping.ts index e2aa78a6c..8eb25f6a2 100644 --- a/subgraph/src/FundingRoundMapping.ts +++ b/subgraph/src/FundingRoundMapping.ts @@ -74,7 +74,6 @@ export function handleContribution(event: Contribution): void { contributor.fundingRounds = _fundingRounds contributor.contributorRegistry = contributorRegistryId - contributor.verified = true contributor.contributorAddress = contributorAddress contributor.verifiedTimeStamp = event.block.timestamp.toString() @@ -90,7 +89,6 @@ export function handleContribution(event: Contribution): void { } contributor.contributorRegistry = contributorRegistryId - contributor.verified = true contributor.contributorAddress = contributorAddress contributor.verifiedTimeStamp = event.block.timestamp.toString() diff --git a/subgraph/subgraph.template.yaml b/subgraph/subgraph.template.yaml index 2dc52de33..451a6f7c2 100644 --- a/subgraph/subgraph.template.yaml +++ b/subgraph/subgraph.template.yaml @@ -1,6 +1,6 @@ specVersion: 0.0.2 -description: clr.fund sandbox -repository: https://github.com/daodesigner/clrfund-deployer +description: clr.fund +repository: https://github.com/clrfund/monorepo schema: file: ./schema.graphql dataSources: @@ -149,7 +149,7 @@ templates: eventHandlers: - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - - event: SetBrightIdSettings(bytes32,address,address) + - event: SetBrightIdSettings(bytes32,address) handler: handleSetBrightIdSettings file: ./src/BrightIdUserRegistryMapping.ts - name: MACI @@ -174,4 +174,4 @@ templates: handler: handlePublishMessage - event: SignUp((uint256,uint256),uint256,uint256) handler: handleSignUp - file: ./src/MACIMapping.ts \ No newline at end of file + file: ./src/MACIMapping.ts diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index 4e9d5059e..91bdea694 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -1,6 +1,6 @@ specVersion: 0.0.2 -description: clr.fund sandbox -repository: https://github.com/daodesigner/clrfund-deployer +description: clr.fund +repository: https://github.com/clrfund/monorepo schema: file: ./schema.graphql dataSources: @@ -149,7 +149,7 @@ templates: eventHandlers: - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - - event: SetBrightIdSettings(bytes32,address,address) + - event: SetBrightIdSettings(bytes32,address) handler: handleSetBrightIdSettings file: ./src/BrightIdUserRegistryMapping.ts - name: MACI @@ -174,4 +174,4 @@ templates: handler: handlePublishMessage - event: SignUp((uint256,uint256),uint256,uint256) handler: handleSignUp - file: ./src/MACIMapping.ts \ No newline at end of file + file: ./src/MACIMapping.ts diff --git a/vue-app/src/App.vue b/vue-app/src/App.vue index acfb0f6ae..03a65687f 100644 --- a/vue-app/src/App.vue +++ b/vue-app/src/App.vue @@ -184,6 +184,7 @@ export default class App extends Vue { 'verify', 'verify-step', 'verified', + 'sponsored', ] return !excludedRoutes.includes(this.$route.name || '') } @@ -198,6 +199,7 @@ export default class App extends Vue { 'verify', 'verify-step', 'verified', + 'sponsored', ] return !excludedRoutes.includes(this.$route.name || '') } diff --git a/vue-app/src/api/bright-id.ts b/vue-app/src/api/bright-id.ts index 21a97f17f..3a7cbc6a2 100644 --- a/vue-app/src/api/bright-id.ts +++ b/vue-app/src/api/bright-id.ts @@ -8,8 +8,6 @@ const NODE_URL = 'https://app.brightid.org/node/v6' const CONTEXT = process.env.VUE_APP_BRIGHTID_CONTEXT || 'clr.fund' export interface BrightId { - isLinked: boolean - isSponsored: boolean isVerified: boolean // If is verified in BrightID verification?: Verification } @@ -23,6 +21,13 @@ export interface Verification { app: string } +export interface Sponsorship { + timestamp: number + app: string + appHasAuthorized: boolean + spendRequested: boolean +} + export async function selfSponsor( registryAddress: string, signer: Signer @@ -50,6 +55,20 @@ export class BrightIdError extends Error { } } +export async function getSponsorship( + userAddress: string +): Promise { + const apiUrl = `${NODE_URL}/sponsorships/${userAddress}` + const response = await fetch(apiUrl) + const data = await response.json() + + if (data['error']) { + throw new BrightIdError(data['errorNum']) + } else { + return data['data'] + } +} + export async function getVerification( userAddress: string ): Promise { @@ -84,15 +103,11 @@ export async function registerUser( export async function getBrightId(contextId: string): Promise { const brightId: BrightId = { - isLinked: false, - isSponsored: false, isVerified: false, } try { const verification = await getVerification(contextId) - brightId.isLinked = true - brightId.isSponsored = true // the `unique` field tell us if the user is a verified user brightId.isVerified = !!verification?.unique brightId.verification = verification @@ -101,18 +116,6 @@ export async function getBrightId(contextId: string): Promise { /* eslint-disable-next-line no-console */ console.error(error) } - - // Not verified user - if (error.code === 3) { - brightId.isLinked = true - brightId.isSponsored = true - } - - // Not sponsored user - if (error.code === 4) { - brightId.isLinked = true - } } - return brightId } diff --git a/vue-app/src/components/BrightIdWidget.vue b/vue-app/src/components/BrightIdWidget.vue index 9c1de75c3..555a2e87e 100644 --- a/vue-app/src/components/BrightIdWidget.vue +++ b/vue-app/src/components/BrightIdWidget.vue @@ -21,21 +21,19 @@ />

BrightID setup

-

{{ getCurrentStep }} / 4

+

{{ getCurrentStep }} / 2

-
+
Start contributing @@ -77,13 +75,6 @@ export default class BrightIdWidget extends Vue { @Prop() balance!: string @Prop() isProjectCard!: boolean - get isLinked(): boolean { - return ( - this.$store.state.currentUser && - this.$store.state.currentUser.brightId.isLinked - ) - } - get isVerified(): boolean { return ( this.$store.state.currentUser && @@ -91,13 +82,6 @@ export default class BrightIdWidget extends Vue { ) } - get isSponsored(): boolean { - return ( - this.$store.state.currentUser && - this.$store.state.currentUser.brightId.isSponsored - ) - } - get isRegistered(): boolean { return ( this.$store.state.currentUser && @@ -106,23 +90,15 @@ export default class BrightIdWidget extends Vue { } get getCurrentStep(): number { - if (!this.isLinked) { - return 0 - } - - if (!this.isSponsored) { - return 1 - } - if (!this.isVerified) { - return 2 + return 0 } if (!this.isRegistered) { - return 3 + return 1 } - return 4 + return 2 } } diff --git a/vue-app/src/components/CallToActionCard.vue b/vue-app/src/components/CallToActionCard.vue index 1b9e2d1b8..99881e934 100644 --- a/vue-app/src/components/CallToActionCard.vue +++ b/vue-app/src/components/CallToActionCard.vue @@ -62,7 +62,7 @@ export default class CallToActionCard extends Vue { return ( this.$store.state.currentUser && this.$store.state.currentUser.brightId && - this.$store.state.currentUser.brightId.isLinked + this.$store.state.currentUser.brightId.isVerified ) } diff --git a/vue-app/src/router/index.ts b/vue-app/src/router/index.ts index 0e2a13229..09932d59a 100644 --- a/vue-app/src/router/index.ts +++ b/vue-app/src/router/index.ts @@ -25,6 +25,9 @@ import VerifyView from '../views/Verify.vue' import RecipientRegistryView from '@/views/RecipientRegistry.vue' import CartView from '@/views/Cart.vue' import TransactionSuccess from '@/views/TransactionSuccess.vue' +import BrightIdGuide from '@/views/BrightIdGuide.vue' +import BrightIdSponsor from '@/views/BrightIdSponsor.vue' +import BrightIdSponsored from '@/views/BrightIdSponsored.vue' Vue.use(VueRouter) @@ -233,6 +236,30 @@ const routes = [ title: 'Transaction Success', }, }, + { + path: '/brightid', + name: 'brightid', + component: BrightIdGuide, + meta: { + title: 'BrightId', + }, + }, + { + path: '/brightid/sponsor', + name: 'brightid-sponsor', + component: BrightIdSponsor, + meta: { + title: 'BrightId Sponsor', + }, + }, + { + path: '/brightid/sponsored/:hash', + name: 'sponsored', + component: BrightIdSponsored, + meta: { + title: 'Sponsored', + }, + }, ] const router = new VueRouter({ base: window.location.pathname, diff --git a/vue-app/src/store/actions.ts b/vue-app/src/store/actions.ts index 189745fdf..b0a047130 100644 --- a/vue-app/src/store/actions.ts +++ b/vue-app/src/store/actions.ts @@ -161,6 +161,10 @@ const actions = { state.currentUser.walletAddress ) + // if users are registered, they are also verified + const brightId = state.currentUser.brightid || {} + brightId.isVerified = isRegistered ? true : brightId.isVerified || false + if (nativeTokenAddress) { balance = await getTokenBalance( nativeTokenAddress, @@ -177,6 +181,7 @@ const actions = { isRegistered, balance, etherBalance, + brightId, ensName, }) }, @@ -184,8 +189,6 @@ const actions = { if (state.currentUser && userRegistryType === UserRegistryType.BRIGHT_ID) { // If the user is registered, we assume all brightId steps as done let brightId: BrightId = { - isLinked: true, - isSponsored: true, isVerified: true, } diff --git a/vue-app/src/views/AboutSybilResistance.vue b/vue-app/src/views/AboutSybilResistance.vue index d393c85ff..105931c38 100644 --- a/vue-app/src/views/AboutSybilResistance.vue +++ b/vue-app/src/views/AboutSybilResistance.vue @@ -52,7 +52,7 @@ Get verified by following the directions here.

-

How to set up BrightID

+

How to set up BrightID

The app walks you through getting set up, but here's a quick look at what you can expect: @@ -68,18 +68,18 @@ >Android -

  • - Link your wallet to your BrightID profile, so you can't use multiple - Ethereum addresses to sway voting. -
  • Get verified in BrightID so we know you're a human and not a bot.
  • - Submit a transaction for clr.fund to sponsor you in BrightID + Submit a transaction for clr.fund to sponsor you in BrightID. More on BrightID sponsorship
  • +
  • + Link your wallet to your BrightID profile, so you can't use multiple + Ethereum addresses to sway voting. +
  • Add yourself to the clr.fund user registry. This is a requirement for MACI, our anti-bribery tech. @@ -100,5 +100,12 @@ import Component from 'vue-class-component' import Links from '@/components/Links.vue' @Component({ components: { Links } }) -export default class AboutSybilResistance extends Vue {} +export default class AboutSybilResistance extends Vue { + mounted() { + if (this.$route.hash) { + const hash = this.$route.hash.replace('#', '') + document.getElementById(hash)?.scrollIntoView({ behavior: 'smooth' }) + } + } +} diff --git a/vue-app/src/views/BrightIdGuide.vue b/vue-app/src/views/BrightIdGuide.vue new file mode 100644 index 000000000..1ec4b9409 --- /dev/null +++ b/vue-app/src/views/BrightIdGuide.vue @@ -0,0 +1,49 @@ + + + + + diff --git a/vue-app/src/views/BrightIdSponsor.vue b/vue-app/src/views/BrightIdSponsor.vue new file mode 100644 index 000000000..7252d6b30 --- /dev/null +++ b/vue-app/src/views/BrightIdSponsor.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/vue-app/src/views/BrightIdSponsored.vue b/vue-app/src/views/BrightIdSponsored.vue new file mode 100644 index 000000000..c7f3db338 --- /dev/null +++ b/vue-app/src/views/BrightIdSponsored.vue @@ -0,0 +1,166 @@ +@ -0,0 +1,36 @@ + + + + + diff --git a/vue-app/src/views/Profile.vue b/vue-app/src/views/Profile.vue index 49f0ee226..b541eec00 100644 --- a/vue-app/src/views/Profile.vue +++ b/vue-app/src/views/Profile.vue @@ -165,7 +165,10 @@ export default class Profile extends Vue { } get showBrightIdWidget(): boolean { - return userRegistryType === UserRegistryType.BRIGHT_ID + return ( + userRegistryType === UserRegistryType.BRIGHT_ID && + !this.$store.getters.hasContributionPhaseEnded + ) } get chain(): ChainInfo { diff --git a/vue-app/src/views/Verified.vue b/vue-app/src/views/Verified.vue index c762d9f1c..8bf06b46a 100644 --- a/vue-app/src/views/Verified.vue +++ b/vue-app/src/views/Verified.vue @@ -18,7 +18,7 @@
  • You’re on board this funding round! And fully verified for BrightID - – you’ll never have to do that again. + for this funding round.

    You can now start contributing to your favorite projects.

    diff --git a/vue-app/src/views/Verify.vue b/vue-app/src/views/Verify.vue index 443e336ed..29a3061ea 100644 --- a/vue-app/src/views/Verify.vue +++ b/vue-app/src/views/Verify.vue @@ -18,7 +18,7 @@ >