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/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..2b2e8ce1f 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 { @@ -10,29 +11,43 @@ 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); - event Sponsor(address indexed addr); + + 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) public { + 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; + brightIdSponsor = BrightIdSponsor(_sponsor); } /** @@ -40,7 +55,7 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { * @param addr BrightID context id */ function sponsor(address addr) public { - emit Sponsor(addr); + brightIdSponsor.sponsor(addr); } /** @@ -57,6 +72,30 @@ contract BrightIdUserRegistry is Ownable, IUserRegistry { 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 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); + } + /** * @notice Check a user is verified or not * @param _user BrightID context id used for verifying users @@ -67,14 +106,29 @@ 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 * @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 +136,24 @@ 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); + require(canRegister(block.timestamp), ERROR_REGISTRATION_CLOSED); + require(canRegister(_timestamp), ERROR_EXPIRED_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; + + emit Registered(_addr, _timestamp); } } 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/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/deployRound.ts b/contracts/scripts/deployRound.ts index 0402539d1..ebd71e53d 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') @@ -166,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() @@ -227,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 new file mode 100644 index 000000000..cfaf9e542 --- /dev/null +++ b/contracts/scripts/deployUserRegistry.ts @@ -0,0 +1,72 @@ +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 || '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') + } + await userRegistry.deployTransaction.wait() + console.log( + `Deployed ${userRegistryType} user registry at ${userRegistry.address}` + ) + + 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/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/docs/brightid.md b/docs/brightid.md index ef381a401..3301cb93d 100644 --- a/docs/brightid.md +++ b/docs/brightid.md @@ -18,8 +18,12 @@ USER_REGISTRY_TYPE=brightid Available envs: -- Testing: `CLRFundTest` -- Production: `clr.fund` +| Network/Env | Context | Sponsor Contract | +| ----------- | ------- | ---------------- | +| goerli | clrfund-goerli | 0xF045234A776C87060DEEc5689056455A24a59c08 | +| xdai | clrfund-gnosis-chain || +| Arbitrum | clrfund-arbitrum || + ```.sh # /vue-app/.env @@ -29,23 +33,11 @@ VUE_APP_BRIGHTID_CONTEXT={CONTEXT} BRIGHTID_CONTEXT={CONTEXT} ``` -Note: the BrightID context is specific to the BrightID network - it's independent from the Ethereum network you choose to run the app on. It refers to the BrightID app context where you want to burn sponsorship tokens. For instance, you could use the production `clr.fund` context on xDAI or Arbitrum (or any network). - -[Learn more about context in the BrightID docs](https://dev.brightid.org/docs/guides/ZG9jOjQxNTE1NDU-basic-integration). - -## Testing +Note: the BrightID context is specific to the BrightID network - it's independent from the Ethereum network you choose to run the app on. It refers to the BrightID app context where you want to burn sponsorship tokens. +The `Sponsor Contract` is the contract set up in the BrightID node to track the sponsorship event. -The following tool provided by BrightID is used for manual linking, sponsoring, and verifying a contextId (in our case, the user wallet address). -https://acolytec3.github.io/brightid_test_app/ - -Required fields: - -- Context: `CLRFundTest` -- Testing key: `55HhFtQvaHB0BJeR` -- ContextId: `{walletAddress}` you want to test - -Note: this tool is only going to work with **testing** contexts, like `CLRFundTest`. Production contexts like `clr.fund` are not going to work. +[Learn more about context in the BrightID docs](https://dev.brightid.org/docs/guides/ZG9jOjQxNTE1NDU-basic-integration). ## Resources diff --git a/subgraph/abis/BrightIdUserRegistry.json b/subgraph/abis/BrightIdUserRegistry.json index ebfabde04..d7a1b1e4c 100644 --- a/subgraph/abis/BrightIdUserRegistry.json +++ b/subgraph/abis/BrightIdUserRegistry.json @@ -1,180 +1,372 @@ [ { - "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", + "indexed": true, + "internalType": "address", "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, "internalType": "address", - "indexed": true + "name": "addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" } ], - "anonymous": false + "name": "Registered", + "type": "event" }, { - "type": "event", - "name": "SetBrightIdSettings", + "anonymous": false, "inputs": [ { - "type": "bytes32", - "name": "context", + "indexed": false, + "internalType": "uint256", + "name": "startTime", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "RegistrationPeriodChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, "internalType": "bytes32", - "indexed": false + "name": "context", + "type": "bytes32" }, { - "type": "address", - "name": "verifier", + "indexed": false, "internalType": "address", - "indexed": false + "name": "verifier", + "type": "address" } ], - "anonymous": false + "name": "SetBrightIdSettings", + "type": "event" }, { - "type": "event", - "name": "Sponsor", + "anonymous": false, "inputs": [ { - "type": "address", - "name": "addr", + "indexed": false, "internalType": "address", - "indexed": true + "name": "sponsor", + "type": "address" } ], - "anonymous": false + "name": "SponsorChanged", + "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", + "inputs": [ + { + "internalType": "uint256", + "name": "_timestamp", + "type": "uint256" + } + ], + "name": "canRegister", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }], - "name": "isOwner", - "inputs": [], - "constant": true + "type": "function" }, { - "type": "function", + "inputs": [], + "name": "context", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], "stateMutability": "view", - "payable": false, - "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }], - "name": "isVerifiedUser", + "type": "function" + }, + { "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" } + { + "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" + } ], - "constant": false + "name": "register", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "renounceOwnership", "inputs": [], - "constant": false + "name": "registrationDeadline", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" }, { - "type": "function", - "stateMutability": "nonpayable", - "payable": false, - "outputs": [], - "name": "setSettings", - "inputs": [ - { "type": "bytes32", "name": "_context", "internalType": "bytes32" }, - { "type": "address", "name": "_verifier", "internalType": "address" } + "inputs": [], + "name": "registrationStartTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } ], - "constant": false + "stateMutability": "view", + "type": "function" }, { - "type": "function", + "inputs": [], + "name": "renounceOwnership", + "outputs": [], "stateMutability": "nonpayable", - "payable": false, + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_startTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_deadline", + "type": "uint256" + } + ], + "name": "setRegistrationPeriod", "outputs": [], - "name": "sponsor", + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [ - { "type": "address", "name": "addr", "internalType": "address" } + { + "internalType": "bytes32", + "name": "_context", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "_verifier", + "type": "address" + } ], - "constant": false + "name": "setSettings", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "type": "function", + "inputs": [ + { + "internalType": "address", + "name": "_sponsor", + "type": "address" + } + ], + "name": "setSponsor", + "outputs": [], "stateMutability": "nonpayable", - "payable": false, + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "sponsor", "outputs": [], - "name": "transferOwnership", + "stateMutability": "nonpayable", + "type": "function" + }, + { "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" + } + ], + "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..26a35e7b0 100644 --- a/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts +++ b/subgraph/generated/FundingRoundFactory/BrightIdUserRegistry.ts @@ -32,6 +32,50 @@ 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(); + } +} + +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(); + } +} + export class SetBrightIdSettings extends ethereum.Event { get params(): SetBrightIdSettings__Params { return new SetBrightIdSettings__Params(this); @@ -54,69 +98,64 @@ export class SetBrightIdSettings__Params { } } -export class Sponsor extends ethereum.Event { - get params(): Sponsor__Params { - return new Sponsor__Params(this); +export class SponsorChanged extends ethereum.Event { + get params(): SponsorChanged__Params { + return new SponsorChanged__Params(this); } } -export class Sponsor__Params { - _event: Sponsor; +export class SponsorChanged__Params { + _event: SponsorChanged; - constructor(event: Sponsor) { + constructor(event: SponsorChanged) { this._event = event; } - get addr(): Address { + get sponsor(): Address { return this._event.parameters[0].value.toAddress(); } } -export class BrightIdUserRegistry__verificationsResult { - value0: BigInt; - value1: boolean; - - constructor(value0: BigInt, value1: boolean) { - 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.fromBoolean(this.value1)); - return map; - } -} - export class BrightIdUserRegistry extends ethereum.SmartContract { static bind(address: Address): BrightIdUserRegistry { 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)", []); + canRegister(_timestamp: BigInt): boolean { + let result = super.call("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); return result[0].toBoolean(); } - try_isOwner(): ethereum.CallResult { - let result = super.tryCall("isOwner", "isOwner():(bool)", []); + 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(); } @@ -124,6 +163,21 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toBoolean()); } + context(): Bytes { + let result = super.call("context", "context():(bytes32)", []); + + return result[0].toBytes(); + } + + 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].toBytes()); + } + isVerifiedUser(_user: Address): boolean { let result = super.call( "isVerifiedUser", @@ -162,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 { @@ -235,6 +325,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 +360,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(); } } @@ -321,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); @@ -355,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/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/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 40919cd1e..26a35e7b0 100644 --- a/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts +++ b/subgraph/generated/templates/BrightIdUserRegistry/BrightIdUserRegistry.ts @@ -32,6 +32,50 @@ 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(); + } +} + +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(); + } +} + export class SetBrightIdSettings extends ethereum.Event { get params(): SetBrightIdSettings__Params { return new SetBrightIdSettings__Params(this); @@ -54,69 +98,64 @@ export class SetBrightIdSettings__Params { } } -export class Sponsor extends ethereum.Event { - get params(): Sponsor__Params { - return new Sponsor__Params(this); +export class SponsorChanged extends ethereum.Event { + get params(): SponsorChanged__Params { + return new SponsorChanged__Params(this); } } -export class Sponsor__Params { - _event: Sponsor; +export class SponsorChanged__Params { + _event: SponsorChanged; - constructor(event: Sponsor) { + constructor(event: SponsorChanged) { this._event = event; } - get addr(): Address { + get sponsor(): Address { return this._event.parameters[0].value.toAddress(); } } -export class BrightIdUserRegistry__verificationsResult { - value0: BigInt; - value1: boolean; - - constructor(value0: BigInt, value1: boolean) { - 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.fromBoolean(this.value1)); - return map; - } -} - export class BrightIdUserRegistry extends ethereum.SmartContract { static bind(address: Address): BrightIdUserRegistry { 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)", []); + canRegister(_timestamp: BigInt): boolean { + let result = super.call("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); return result[0].toBoolean(); } - try_isOwner(): ethereum.CallResult { - let result = super.tryCall("isOwner", "isOwner():(bool)", []); + 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(); } @@ -124,6 +163,21 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toBoolean()); } + context(): Bytes { + let result = super.call("context", "context():(bytes32)", []); + + return result[0].toBytes(); + } + + 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].toBytes()); + } + isVerifiedUser(_user: Address): boolean { let result = super.call( "isVerifiedUser", @@ -162,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 { @@ -235,6 +325,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 +360,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(); } } @@ -321,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); @@ -355,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 40919cd1e..26a35e7b0 100644 --- a/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts +++ b/subgraph/generated/templates/FundingRound/BrightIdUserRegistry.ts @@ -32,6 +32,50 @@ 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(); + } +} + +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(); + } +} + export class SetBrightIdSettings extends ethereum.Event { get params(): SetBrightIdSettings__Params { return new SetBrightIdSettings__Params(this); @@ -54,69 +98,64 @@ export class SetBrightIdSettings__Params { } } -export class Sponsor extends ethereum.Event { - get params(): Sponsor__Params { - return new Sponsor__Params(this); +export class SponsorChanged extends ethereum.Event { + get params(): SponsorChanged__Params { + return new SponsorChanged__Params(this); } } -export class Sponsor__Params { - _event: Sponsor; +export class SponsorChanged__Params { + _event: SponsorChanged; - constructor(event: Sponsor) { + constructor(event: SponsorChanged) { this._event = event; } - get addr(): Address { + get sponsor(): Address { return this._event.parameters[0].value.toAddress(); } } -export class BrightIdUserRegistry__verificationsResult { - value0: BigInt; - value1: boolean; - - constructor(value0: BigInt, value1: boolean) { - 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.fromBoolean(this.value1)); - return map; - } -} - export class BrightIdUserRegistry extends ethereum.SmartContract { static bind(address: Address): BrightIdUserRegistry { 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)", []); + canRegister(_timestamp: BigInt): boolean { + let result = super.call("canRegister", "canRegister(uint256):(bool)", [ + ethereum.Value.fromUnsignedBigInt(_timestamp) + ]); return result[0].toBoolean(); } - try_isOwner(): ethereum.CallResult { - let result = super.tryCall("isOwner", "isOwner():(bool)", []); + 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(); } @@ -124,6 +163,21 @@ export class BrightIdUserRegistry extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toBoolean()); } + context(): Bytes { + let result = super.call("context", "context():(bytes32)", []); + + return result[0].toBytes(); + } + + 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].toBytes()); + } + isVerifiedUser(_user: Address): boolean { let result = super.call( "isVerifiedUser", @@ -162,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 { @@ -235,6 +325,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 +360,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(); } } @@ -321,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); @@ -355,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 2f685fa49..8bd6943ae 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,12 @@ 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.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/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 4e391d58b..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: @@ -151,8 +151,6 @@ templates: handler: handleOwnershipTransferred - event: SetBrightIdSettings(bytes32,address) handler: handleSetBrightIdSettings - - event: Sponsor(indexed address) - handler: handleSponsor file: ./src/BrightIdUserRegistryMapping.ts - name: MACI kind: ethereum/contract @@ -176,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 db5674c69..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: @@ -151,8 +151,6 @@ templates: handler: handleOwnershipTransferred - event: SetBrightIdSettings(bytes32,address) handler: handleSetBrightIdSettings - - event: Sponsor(indexed address) - handler: handleSponsor file: ./src/BrightIdUserRegistryMapping.ts - name: MACI kind: ethereum/contract @@ -176,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/.env.example b/vue-app/.env.example index 0ca3ec51c..d765d0c3d 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 @@ -17,7 +22,7 @@ VUE_APP_CLRFUND_FACTORY_ADDRESS=0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 VUE_APP_USER_REGISTRY_TYPE=simple # clr.fund (prod) or CLRFundTest (testing) # Learn more about BrightID and context in /docs/brightid.md -VUE_APP_BRIGHTID_CONTEXT=clr.fund +VUE_APP_BRIGHTID_CONTEXT=clrfund-goerli # Optional matching pool address to override the funding round factory address # e.g. if using a safe multisig for the matching pool @@ -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 fd896c6ef..0e5cbef3b 100644 --- a/vue-app/package.json +++ b/vue-app/package.json @@ -23,7 +23,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/App.vue b/vue-app/src/App.vue index 2e4be17f5..211369ad5 100644 --- a/vue-app/src/App.vue +++ b/vue-app/src/App.vue @@ -190,6 +190,7 @@ export default class App extends Vue { 'verify', 'verify-step', 'verified', + 'sponsored', ] return !excludedRoutes.includes(this.$route.name || '') } @@ -204,6 +205,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 2b1290e42..eede63b3e 100644 --- a/vue-app/src/api/bright-id.ts +++ b/vue-app/src/api/bright-id.ts @@ -4,24 +4,30 @@ 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 { - isLinked: boolean - isSponsored: boolean isVerified: boolean // If is verified in BrightID verification?: Verification } export interface Verification { unique: boolean - contextIds: string[] + appUserId: string + verificationHash: string sig: { r: string; s: string; v: number } timestamp: number app: string } +export interface Sponsorship { + timestamp: number + app: string + appHasAuthorized: boolean + spendRequested: boolean +} + export async function selfSponsor( registryAddress: string, signer: Signer @@ -33,8 +39,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 } @@ -50,16 +55,34 @@ 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 { + // do not cache result so we get the status change sooner + const headers = new Headers() + headers.append('cache-control', 'no-store') const apiUrl = `${NODE_URL}/verifications/${CONTEXT}/${userAddress}?signed=eth×tamp=seconds` - const response = await fetch(apiUrl) + const response = await fetch(apiUrl, { headers }) const data = await response.json() + if (data['error']) { throw new BrightIdError(data['errorNum']) } else { - return data['data'] + return data['data'][0] } } @@ -71,7 +94,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, @@ -82,15 +106,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 @@ -99,18 +119,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/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..afb4d4342 --- /dev/null +++ b/vue-app/src/api/ipfs.ts @@ -0,0 +1,28 @@ +import { ipfsPinningUrl, ipfsPinningJwt } from './core' + +export class IPFS { + url: string + jwt: string + + constructor() { + this.url = ipfsPinningUrl || '' + this.jwt = ipfsPinningJwt || '' + } + + async add(file: File): Promise { + const data = new FormData() + data.append('file', file) + + const options = { + method: 'POST', + headers: { + Authorization: `Bearer ${this.jwt}`, + }, + body: data, + } + + const result = await fetch(this.url, options) + const json = await result.json() + return json.IpfsHash + } +} 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/components/IpfsImageUpload.vue b/vue-app/src/components/IpfsImageUpload.vue index 051ab1e89..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 || !loadedImageData" + :disabled="loading || error || !loadedImageFile" > {{ 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: { @@ -82,20 +82,16 @@ 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 - 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,19 @@ 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.ipfs && + 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,8 +153,8 @@ export default class IpfsImageUpload extends Vue { handleRemoveImage(): void { this.hash = '' this.loading = false - this.loadedImageData = '' this.error = '' + this.loadedImageFile = null this.onUpload(this.formProp, '') // Clear file selector input 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..98298950d 100644 --- a/vue-app/src/store/actions.ts +++ b/vue-app/src/store/actions.ts @@ -184,8 +184,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..be648e967 100644 --- a/vue-app/src/views/Profile.vue +++ b/vue-app/src/views/Profile.vue @@ -153,6 +153,9 @@ export default class Profile extends Vue { async created() { this.isLoading = true await this.loadProjects() + if (this.showBrightIdWidget) { + await this.$store.dispatch('LOAD_BRIGHT_ID') + } this.isLoading = false } @@ -165,7 +168,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 eaba2be68..890a05e89 100644 --- a/vue-app/src/views/Verify.vue +++ b/vue-app/src/views/Verify.vue @@ -18,7 +18,7 @@ >