mirror of
https://github.com/social-tw/social-tw-website.git
synced 2026-01-08 23:18:05 -05:00
feat: lint:fix
This commit is contained in:
@@ -16,18 +16,18 @@ export const defaultProver = {
|
||||
*/
|
||||
genProofAndPublicSignals: async (
|
||||
circuitName: string | Circuit,
|
||||
inputs: any,
|
||||
inputs: any
|
||||
): Promise<any> => {
|
||||
const circuitWasmPath = path.join(
|
||||
__dirname,
|
||||
buildPath,
|
||||
`${circuitName}.wasm`,
|
||||
`${circuitName}.wasm`
|
||||
)
|
||||
const zkeyPath = path.join(__dirname, buildPath, `${circuitName}.zkey`)
|
||||
const { proof, publicSignals } = await snarkjs.groth16.fullProve(
|
||||
inputs,
|
||||
circuitWasmPath,
|
||||
zkeyPath,
|
||||
zkeyPath
|
||||
)
|
||||
|
||||
return { proof, publicSignals }
|
||||
@@ -43,7 +43,7 @@ export const defaultProver = {
|
||||
verifyProof: async (
|
||||
circuitName: string | Circuit,
|
||||
publicSignals: snarkjs.PublicSignals,
|
||||
proof: snarkjs.Groth16Proof,
|
||||
proof: snarkjs.Groth16Proof
|
||||
): Promise<boolean> => {
|
||||
const vkey = require(path.join(buildPath, `${circuitName}.vkey.json`))
|
||||
return snarkjs.groth16.verify(vkey, publicSignals, proof)
|
||||
|
||||
@@ -30,7 +30,7 @@ async function main() {
|
||||
|
||||
await fs.promises.writeFile(
|
||||
path.join(outDir, `${name}_main.circom`),
|
||||
circuitContents[name],
|
||||
circuitContents[name]
|
||||
)
|
||||
|
||||
const inputFile = path.join(outDir, `${name}_main.circom`)
|
||||
@@ -49,7 +49,7 @@ async function main() {
|
||||
if (circuitOutFileExists) {
|
||||
console.log(
|
||||
circuitOut.split('/').pop(),
|
||||
'exists. Skipping compilation.',
|
||||
'exists. Skipping compilation.'
|
||||
)
|
||||
} else {
|
||||
console.log(`Compiling ${inputFile.split('/').pop()}...`)
|
||||
@@ -60,14 +60,14 @@ async function main() {
|
||||
(err, stdout, stderr) => {
|
||||
if (err) rj(err)
|
||||
else rs('')
|
||||
},
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
console.log(
|
||||
'Generated',
|
||||
circuitOut.split('/').pop(),
|
||||
'and',
|
||||
wasmOut.split('/').pop(),
|
||||
wasmOut.split('/').pop()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ async function main() {
|
||||
console.log(
|
||||
`Generated ${zkey.split('/').pop()} and ${vkOut
|
||||
.split('/')
|
||||
.pop()}`,
|
||||
.pop()}`
|
||||
)
|
||||
await fs.promises.rename(wasmOut, wasmOutFinal)
|
||||
await fs.promises.rm(wasmOutDir, { recursive: true, force: true })
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function downloadPtau() {
|
||||
readline.clearLine(process.stdout, 0)
|
||||
readline.cursorTo(process.stdout, 0)
|
||||
process.stdout.write(
|
||||
`Downloading ptau file, please wait... ${p}%`,
|
||||
`Downloading ptau file, please wait... ${p}%`
|
||||
)
|
||||
}
|
||||
const file = fs.createWriteStream(tmp, { flags: 'w' })
|
||||
@@ -32,15 +32,15 @@ export async function downloadPtau() {
|
||||
const contentLength = res.headers['content-length']
|
||||
if (statusCode !== 200) {
|
||||
return rj(
|
||||
`Received non-200 status code from ptau url: ${statusCode}`,
|
||||
`Received non-200 status code from ptau url: ${statusCode}`
|
||||
)
|
||||
}
|
||||
let totalReceived = 0
|
||||
const logTimer = setInterval(() => {
|
||||
logPercent(
|
||||
Math.floor(
|
||||
(100 * totalReceived) / Number(contentLength),
|
||||
),
|
||||
(100 * totalReceived) / Number(contentLength)
|
||||
)
|
||||
)
|
||||
}, 1000)
|
||||
res.on('data', (chunk) => {
|
||||
@@ -58,7 +58,7 @@ export async function downloadPtau() {
|
||||
console.log()
|
||||
rs('')
|
||||
})
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
await fs.promises.rename(tmp, ptau)
|
||||
|
||||
@@ -21,7 +21,7 @@ export class DataProof extends BaseProof {
|
||||
constructor(
|
||||
_publicSignals: PublicSignals,
|
||||
_proof: Groth16Proof,
|
||||
prover?: Prover,
|
||||
prover?: Prover
|
||||
) {
|
||||
super(_publicSignals, _proof, prover)
|
||||
this.stateTreeRoot = _publicSignals[this.idx.stateTreeRoot]
|
||||
|
||||
@@ -23,7 +23,7 @@ export class ReportIdentityProof extends BaseProof {
|
||||
constructor(
|
||||
publicSignals: (bigint | string)[],
|
||||
proof: Groth16Proof,
|
||||
prover?: Prover,
|
||||
prover?: Prover
|
||||
) {
|
||||
super(publicSignals, proof, prover)
|
||||
this.reportNullifier = this.publicSignals[this.input.reportNullifier]
|
||||
|
||||
@@ -30,14 +30,14 @@ export class ReportNonNullifierProof extends BaseProof {
|
||||
constructor(
|
||||
_publicSignals: PublicSignals,
|
||||
_proof: Groth16Proof,
|
||||
prover?: Prover,
|
||||
prover?: Prover
|
||||
) {
|
||||
super(_publicSignals, _proof, prover)
|
||||
this.reportedEpochKey = BigInt(
|
||||
_publicSignals[this.input.reportedEpochKey],
|
||||
_publicSignals[this.input.reportedEpochKey]
|
||||
)
|
||||
this.currentEpochKey = BigInt(
|
||||
_publicSignals[this.output.currentEpochKey],
|
||||
_publicSignals[this.output.currentEpochKey]
|
||||
)
|
||||
this.control = BigInt(this.publicSignals[this.output.control])
|
||||
|
||||
|
||||
@@ -31,15 +31,15 @@ export class ReportNullifierProof extends BaseProof {
|
||||
constructor(
|
||||
_publicSignals: PublicSignals,
|
||||
_proof: Groth16Proof,
|
||||
prover?: Prover,
|
||||
prover?: Prover
|
||||
) {
|
||||
super(_publicSignals, _proof, prover)
|
||||
this.reportNullifier = BigInt(
|
||||
_publicSignals[this.input.reportNullifier],
|
||||
_publicSignals[this.input.reportNullifier]
|
||||
)
|
||||
this.reportId = BigInt(_publicSignals[this.input.reportId])
|
||||
this.currentEpochKey = BigInt(
|
||||
_publicSignals[this.output.currentEpochKey],
|
||||
_publicSignals[this.output.currentEpochKey]
|
||||
)
|
||||
this.control = BigInt(this.publicSignals[this.output.control])
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export const decodeEpochKeyControl = (control: bigint): EpochKeyControl => {
|
||||
export const shiftBits = (
|
||||
data: bigint,
|
||||
shiftBits: bigint,
|
||||
variableBits: bigint,
|
||||
variableBits: bigint
|
||||
): bigint => {
|
||||
return (data >> shiftBits) & ((BigInt(1) << variableBits) - BigInt(1))
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ const genCircuitInput = (config: {
|
||||
replField: [],
|
||||
proveValues: [],
|
||||
},
|
||||
config,
|
||||
config
|
||||
)
|
||||
|
||||
const startBalance = [
|
||||
@@ -43,7 +43,7 @@ const genCircuitInput = (config: {
|
||||
BigInt(attesterId),
|
||||
epoch,
|
||||
startBalance as any,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
stateTree.insert(hashedLeaf)
|
||||
const stateTreeProof = stateTree.createProof(0) // if there is only one GST leaf, the index is 0
|
||||
@@ -68,7 +68,7 @@ const genCircuitInput = (config: {
|
||||
|
||||
const genProofAndVerify = async (
|
||||
circuit: Circuit | string,
|
||||
circuitInputs: any,
|
||||
circuitInputs: any
|
||||
) => {
|
||||
const startTime = new Date().getTime()
|
||||
const { proof, publicSignals } =
|
||||
@@ -76,13 +76,13 @@ const genProofAndVerify = async (
|
||||
const endTime = new Date().getTime()
|
||||
console.log(
|
||||
`Gen Proof time: ${endTime - startTime} ms (${Math.floor(
|
||||
(endTime - startTime) / 1000,
|
||||
)} s)`,
|
||||
(endTime - startTime) / 1000
|
||||
)} s)`
|
||||
)
|
||||
const isValid = await defaultProver.verifyProof(
|
||||
circuit,
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
return { isValid, proof, publicSignals }
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('Prove report identity in Unirep Social-TW', function () {
|
||||
const attesterId = BigInt(10210)
|
||||
const epoch = BigInt(120958)
|
||||
const tree: zkIncrementalMerkleTree = new utils.IncrementalMerkleTree(
|
||||
STATE_TREE_DEPTH,
|
||||
STATE_TREE_DEPTH
|
||||
)
|
||||
const data = randomData()
|
||||
const leaf = utils.genStateTreeLeaf(
|
||||
@@ -41,7 +41,7 @@ describe('Prove report identity in Unirep Social-TW', function () {
|
||||
attesterId,
|
||||
epoch,
|
||||
data,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
tree.insert(leaf)
|
||||
const leafIndex = tree.indexOf(leaf)
|
||||
@@ -66,17 +66,17 @@ describe('Prove report identity in Unirep Social-TW', function () {
|
||||
})
|
||||
const { isValid, proof, publicSignals } = await genProofAndVerify(
|
||||
circuit,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const reportIdentityProof = new ReportIdentityProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
expect(isValid).to.be.true
|
||||
expect(reportIdentityProof.reportNullifier.toString()).to.be.equal(
|
||||
poseidon2([identitySecret, reportId]).toString(),
|
||||
poseidon2([identitySecret, reportId]).toString()
|
||||
)
|
||||
expect(reportIdentityProof.attesterId).to.be.equal(attesterId)
|
||||
expect(reportIdentityProof.epoch).to.be.equal(epoch)
|
||||
@@ -106,7 +106,7 @@ describe('Prove report identity in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportIdentityProof_75 line: 34\n',
|
||||
'Error: Assert Failed. Error in template ReportIdentityProof_75 line: 34\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -135,7 +135,7 @@ describe('Prove report identity in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportIdentityProof_75 line: 38\n',
|
||||
'Error: Assert Failed. Error in template ReportIdentityProof_75 line: 38\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -163,7 +163,7 @@ describe('Prove report identity in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportIdentityProof_75 line: 38\n',
|
||||
'Error: Assert Failed. Error in template ReportIdentityProof_75 line: 38\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const circuitInputs = genReportNonNullifierCircuitInput({
|
||||
@@ -51,24 +51,24 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
|
||||
const { isValid, proof, publicSignals } = await genProofAndVerify(
|
||||
circuit,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const reportNonNullifierProof = new ReportNonNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
expect(isValid).to.be.true
|
||||
// decode other data
|
||||
expect(reportNonNullifierProof.epoch.toString()).to.be.equal(
|
||||
currentEpoch.toString(),
|
||||
currentEpoch.toString()
|
||||
)
|
||||
expect(reportNonNullifierProof.attesterId.toString()).to.be.equal(
|
||||
attesterId.toString(),
|
||||
attesterId.toString()
|
||||
)
|
||||
expect(reportNonNullifierProof.chainId.toString()).to.be.equal(
|
||||
chainId.toString(),
|
||||
chainId.toString()
|
||||
)
|
||||
|
||||
// we don't reveal the nonce, so this is equal to BigInt(0)
|
||||
@@ -80,11 +80,11 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
attesterId,
|
||||
currentEpoch,
|
||||
currentNonce,
|
||||
chainId,
|
||||
),
|
||||
chainId
|
||||
)
|
||||
)
|
||||
expect(reportNonNullifierProof.reportedEpochKey).to.be.equal(
|
||||
reportedEpochKey,
|
||||
reportedEpochKey
|
||||
)
|
||||
})
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
const identitySecret = BigInt(123)
|
||||
|
||||
@@ -122,7 +122,7 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -141,7 +141,7 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
attesterId,
|
||||
correctReportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
const reportedEpoch = 12
|
||||
const circuitInputs = genReportNonNullifierCircuitInput({
|
||||
@@ -160,7 +160,7 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -190,7 +190,7 @@ describe('Prove report non nullifier in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -40,23 +40,23 @@ describe('Prove report nullifier in Unirep Social-TW', function () {
|
||||
})
|
||||
const { isValid, proof, publicSignals } = await genProofAndVerify(
|
||||
circuit,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const reportNullifierProof = new ReportNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
expect(isValid).to.be.true
|
||||
// decode other data
|
||||
expect(reportNullifierProof.epoch.toString()).to.be.equal(
|
||||
currentEpoch.toString(),
|
||||
currentEpoch.toString()
|
||||
)
|
||||
expect(reportNullifierProof.attesterId.toString()).to.be.equal(
|
||||
attesterId.toString(),
|
||||
attesterId.toString()
|
||||
)
|
||||
expect(reportNullifierProof.chainId.toString()).to.be.equal(
|
||||
chainId.toString(),
|
||||
chainId.toString()
|
||||
)
|
||||
|
||||
// we don't reveal the nonce, so this is equal to BigInt(0)
|
||||
@@ -68,11 +68,11 @@ describe('Prove report nullifier in Unirep Social-TW', function () {
|
||||
attesterId,
|
||||
currentEpoch,
|
||||
currentNonce,
|
||||
chainId,
|
||||
),
|
||||
chainId
|
||||
)
|
||||
)
|
||||
expect(reportNullifierProof.reportNullifier).to.be.equal(
|
||||
reportNullifier,
|
||||
reportNullifier
|
||||
)
|
||||
})
|
||||
|
||||
@@ -99,7 +99,7 @@ describe('Prove report nullifier in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNullifierProof_79 line: 22\n',
|
||||
'Error: Assert Failed. Error in template ReportNullifierProof_79 line: 22\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -127,7 +127,7 @@ describe('Prove report nullifier in Unirep Social-TW', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNullifierProof_79 line: 22\n',
|
||||
'Error: Assert Failed. Error in template ReportNullifierProof_79 line: 22\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ProofGenerationError } from './error'
|
||||
|
||||
export const genProofAndVerify = async (
|
||||
circuit: Circuit | string,
|
||||
circuitInputs: any,
|
||||
circuitInputs: any
|
||||
) => {
|
||||
const startTime = new Date().getTime()
|
||||
let proof: any, publicSignals: any
|
||||
@@ -17,7 +17,7 @@ export const genProofAndVerify = async (
|
||||
;({ proof, publicSignals } =
|
||||
await defaultProver.genProofAndPublicSignals(
|
||||
circuit,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
))
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
@@ -29,13 +29,13 @@ export const genProofAndVerify = async (
|
||||
const endTime = new Date().getTime()
|
||||
console.log(
|
||||
`Gen Proof time: ${endTime - startTime} ms (${Math.floor(
|
||||
(endTime - startTime) / 1000,
|
||||
)} s)`,
|
||||
(endTime - startTime) / 1000
|
||||
)} s)`
|
||||
)
|
||||
const isValid = await defaultProver.verifyProof(
|
||||
circuit,
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
return { isValid, proof, publicSignals }
|
||||
}
|
||||
@@ -161,12 +161,12 @@ export const randomData = () => [
|
||||
.map(() => poseidon1([Math.floor(Math.random() * 199191919)])),
|
||||
...Array(
|
||||
CircuitConfig.default.FIELD_COUNT -
|
||||
CircuitConfig.default.SUM_FIELD_COUNT,
|
||||
CircuitConfig.default.SUM_FIELD_COUNT
|
||||
)
|
||||
.fill(0)
|
||||
.map(
|
||||
() =>
|
||||
poseidon1([Math.floor(Math.random() * 199191919)]) %
|
||||
BigInt(2) ** CircuitConfig.default.MAX_SAFE_BITS,
|
||||
BigInt(2) ** CircuitConfig.default.MAX_SAFE_BITS
|
||||
),
|
||||
]
|
||||
|
||||
@@ -4,5 +4,5 @@ import UNIREP_APP_ABI from '../artifacts/contracts/UnirepApp.sol/UnirepApp.json'
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '../abi/UnirepApp.json'),
|
||||
JSON.stringify(UNIREP_APP_ABI.abi),
|
||||
JSON.stringify(UNIREP_APP_ABI.abi)
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ export const createVerifierName = (circuit: string) => {
|
||||
export const genVerifier = (contractName: string, vk: any): string => {
|
||||
const templatePath = path.resolve(
|
||||
__dirname,
|
||||
'./template/groth16Verifier.txt',
|
||||
'./template/groth16Verifier.txt'
|
||||
)
|
||||
|
||||
let template = fs.readFileSync(templatePath, 'utf8')
|
||||
@@ -75,7 +75,7 @@ export const genVerifier = (contractName: string, vk: any): string => {
|
||||
|
||||
template = template.replaceAll(
|
||||
'<%vk_input_length%>',
|
||||
(vk.IC.length - 1).toString(),
|
||||
(vk.IC.length - 1).toString()
|
||||
)
|
||||
template = template.replace('<%vk_ic_length%>', vk.IC.length.toString())
|
||||
let vi = ''
|
||||
|
||||
@@ -24,12 +24,12 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
const epkHelper = await deployVerifierHelper(
|
||||
unirep.address,
|
||||
deployer,
|
||||
Circuit.epochKey,
|
||||
Circuit.epochKey
|
||||
)
|
||||
const epkLiteHelper = await deployVerifierHelper(
|
||||
unirep.address,
|
||||
deployer,
|
||||
Circuit.epochKeyLite,
|
||||
Circuit.epochKeyLite
|
||||
)
|
||||
|
||||
// deploy verifiers
|
||||
@@ -55,7 +55,7 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
const vHelperManager = await deploySingleContract(
|
||||
VHelperManager.abi,
|
||||
VHelperManager.bytecode,
|
||||
deployer,
|
||||
deployer
|
||||
)
|
||||
|
||||
// register verifierHelpers in vHelperManager
|
||||
@@ -74,7 +74,7 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
].map(({ identifier, address }) => {
|
||||
const encodedId = ethers.utils.defaultAbiCoder.encode(
|
||||
['string'],
|
||||
[identifier],
|
||||
[identifier]
|
||||
)
|
||||
const hashId = ethers.utils.keccak256(encodedId)
|
||||
return { identifier: hashId, address }
|
||||
@@ -83,7 +83,7 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
await vHelperManager
|
||||
.owner()
|
||||
.then((owner) =>
|
||||
console.log('Owner of verifier helper manager:', owner),
|
||||
console.log('Owner of verifier helper manager:', owner)
|
||||
)
|
||||
// 2. register address into vHelperManager
|
||||
for (const vHelper of vHelpers) {
|
||||
@@ -106,13 +106,13 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
epkLiteHelper.address,
|
||||
dataProofVerifier.address,
|
||||
vHelperManager.address,
|
||||
epochLength,
|
||||
epochLength
|
||||
)
|
||||
|
||||
await app.deployTransaction.wait()
|
||||
|
||||
console.log(
|
||||
`Unirep app with epoch length ${epochLength} is deployed to ${app.address}`,
|
||||
`Unirep app with epoch length ${epochLength} is deployed to ${app.address}`
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
@@ -11,14 +11,14 @@ export async function deploySingleContract(
|
||||
abi: ethers.ContractInterface,
|
||||
bytecode: string,
|
||||
deployer: ethers.Signer,
|
||||
constructorArgs: any[] = [], // default value is empty
|
||||
constructorArgs: any[] = [] // default value is empty
|
||||
): Promise<ethers.Contract> {
|
||||
try {
|
||||
// Create a new ContractFactory instance
|
||||
const ContractFactory = new ethers.ContractFactory(
|
||||
abi,
|
||||
bytecode,
|
||||
deployer,
|
||||
deployer
|
||||
)
|
||||
|
||||
// TODO: uncomment this line after
|
||||
@@ -44,19 +44,19 @@ export async function deployVerifiers(deployer: ethers.Signer) {
|
||||
const dataProofVerifier = await deploySingleContract(
|
||||
DataProofVerifier.abi,
|
||||
DataProofVerifier.bytecode,
|
||||
deployer,
|
||||
deployer
|
||||
)
|
||||
/// deploy reportNonNullifierProofVerifier
|
||||
const reportNonNullifierProofVerifier = await deploySingleContract(
|
||||
ReportNonNullifierProofVerifier.abi,
|
||||
ReportNonNullifierProofVerifier.bytecode,
|
||||
deployer,
|
||||
deployer
|
||||
)
|
||||
/// deploy reportNullifierProofVerifier
|
||||
const reportNullifierProofVerifier = await deploySingleContract(
|
||||
ReportNullifierProofVerifier.abi,
|
||||
ReportNullifierProofVerifier.bytecode,
|
||||
deployer,
|
||||
deployer
|
||||
)
|
||||
|
||||
return {
|
||||
@@ -72,7 +72,7 @@ export async function deployVHelpers(
|
||||
verifiers: {
|
||||
reportNonNullifierProofVerifier: any
|
||||
reportNullifierProofVerifier: any
|
||||
},
|
||||
}
|
||||
) {
|
||||
const reportNonNullifierProofVerifier =
|
||||
verifiers.reportNonNullifierProofVerifier
|
||||
@@ -83,7 +83,7 @@ export async function deployVHelpers(
|
||||
ReportNonNullifierVHelper.abi,
|
||||
ReportNonNullifierVHelper.bytecode,
|
||||
deployer,
|
||||
[unirep, reportNonNullifierProofVerifier],
|
||||
[unirep, reportNonNullifierProofVerifier]
|
||||
)
|
||||
|
||||
/// deploy reportNullifierProofVHelper
|
||||
@@ -91,7 +91,7 @@ export async function deployVHelpers(
|
||||
ReportNullifierVHelper.abi,
|
||||
ReportNullifierVHelper.bytecode,
|
||||
deployer,
|
||||
[unirep, reportNullifierProofVerifier],
|
||||
[unirep, reportNullifierProofVerifier]
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
const checkSignals = (signals, proof) => {
|
||||
expect(signals.epochKey.toString()).equal(proof.epochKey.toString())
|
||||
expect(signals.stateTreeRoot.toString()).equal(
|
||||
proof.stateTreeRoot.toString(),
|
||||
proof.stateTreeRoot.toString()
|
||||
)
|
||||
expect(signals.nonce.toString()).equal(proof.nonce.toString())
|
||||
expect(signals.epoch.toString()).equal(proof.epoch.toString())
|
||||
@@ -67,7 +67,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
repVerifierHelper = await deployVerifierHelper(
|
||||
unirep.address,
|
||||
deployer,
|
||||
Circuit.reputation,
|
||||
Circuit.reputation
|
||||
)
|
||||
|
||||
user = createRandomUserIdentity()
|
||||
@@ -83,7 +83,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
publicSignals,
|
||||
proof,
|
||||
user.hashUserId,
|
||||
false,
|
||||
false
|
||||
)
|
||||
await app
|
||||
.userRegistry(user.hashUserId)
|
||||
@@ -101,7 +101,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
app.address,
|
||||
epoch,
|
||||
0,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
const field = userState.sync.settings.sumFieldCount
|
||||
|
||||
@@ -146,7 +146,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
|
||||
const signals = await repVerifierHelper.verifyAndCheck(
|
||||
proof.publicSignals,
|
||||
proof.proof,
|
||||
proof.proof
|
||||
)
|
||||
checkSignals(signals, proof)
|
||||
|
||||
@@ -182,7 +182,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
const { publicSignals, proof } = await userState.genEpochKeyProof()
|
||||
|
||||
await expect(
|
||||
app.connect(notOwner).claimDailyLoginRep(publicSignals, proof),
|
||||
app.connect(notOwner).claimDailyLoginRep(publicSignals, proof)
|
||||
).to.be.reverted
|
||||
})
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId,
|
||||
attesterId
|
||||
)
|
||||
|
||||
const { publicSignals, proof } = await genEpochKeyProof({
|
||||
@@ -223,7 +223,7 @@ describe('Claim Daily Login Reputation Test', function () {
|
||||
})
|
||||
|
||||
await expect(
|
||||
app.claimDailyLoginRep(publicSignals, proof),
|
||||
app.claimDailyLoginRep(publicSignals, proof)
|
||||
).to.be.revertedWithCustomError(app, 'InvalidEpoch')
|
||||
|
||||
userState.stop()
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
const reporterPunishment: number = 1
|
||||
const circuit = 'reportNonNullifierProof'
|
||||
const identifier = genVHelperIdentifier(
|
||||
'reportNonNullifierProofVerifierHelper',
|
||||
'reportNonNullifierProofVerifierHelper'
|
||||
)
|
||||
let usedPublicSig: any
|
||||
let usedProof: any
|
||||
@@ -71,7 +71,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
posterPubSig,
|
||||
posterPf,
|
||||
poster.hashUserId,
|
||||
false,
|
||||
false
|
||||
)
|
||||
await app
|
||||
.userRegistry(poster.hashUserId)
|
||||
@@ -87,7 +87,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
reporterPubSig,
|
||||
reporterPf,
|
||||
reporter.hashUserId,
|
||||
false,
|
||||
false
|
||||
)
|
||||
await app
|
||||
.userRegistry(reporter.hashUserId)
|
||||
@@ -151,7 +151,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -161,7 +161,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
identifier,
|
||||
posterPunishment,
|
||||
posterPunishment
|
||||
)
|
||||
await expect(tx)
|
||||
.to.emit(app, 'ClaimNegRep')
|
||||
@@ -184,8 +184,8 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
identifier,
|
||||
posterPunishment,
|
||||
),
|
||||
posterPunishment
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
|
||||
@@ -195,8 +195,8 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
identifier,
|
||||
posterPunishment,
|
||||
),
|
||||
posterPunishment
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -240,7 +240,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -250,7 +250,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
identifier,
|
||||
reporterPunishment,
|
||||
reporterPunishment
|
||||
)
|
||||
await expect(tx)
|
||||
.to.emit(app, 'ClaimNegRep')
|
||||
@@ -270,8 +270,8 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
identifier,
|
||||
posterPunishment,
|
||||
),
|
||||
posterPunishment
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -299,7 +299,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
const flattenedProof = flattenProof(proof)
|
||||
flattenedProof[0] = BigInt(0)
|
||||
@@ -309,8 +309,8 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
identifier,
|
||||
posterPunishment,
|
||||
),
|
||||
posterPunishment
|
||||
)
|
||||
).to.be.reverted
|
||||
|
||||
posterState.stop()
|
||||
@@ -340,7 +340,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -350,8 +350,8 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
identifier,
|
||||
posterPunishment,
|
||||
),
|
||||
posterPunishment
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'InvalidEpoch')
|
||||
|
||||
posterState.stop()
|
||||
@@ -388,7 +388,7 @@ describe('Claim Report Negative Reputation Test', function () {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n'
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
const nullifierCircuit = 'reportNullifierProof'
|
||||
const nonNullifierCircuit = 'reportNonNullifierProof'
|
||||
const nullifierIdentifier = genVHelperIdentifier(
|
||||
'reportNullifierProofVerifierHelper',
|
||||
'reportNullifierProofVerifierHelper'
|
||||
)
|
||||
const nonNullifierIdentifier = genVHelperIdentifier(
|
||||
'reportNonNullifierProofVerifierHelper',
|
||||
'reportNonNullifierProofVerifierHelper'
|
||||
)
|
||||
let usedPublicSig: any
|
||||
let usedProof: any
|
||||
@@ -70,7 +70,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
upvoterSig,
|
||||
upvoterPf,
|
||||
upvoter.hashUserId,
|
||||
false,
|
||||
false
|
||||
)
|
||||
await app
|
||||
.userRegistry(upvoter.hashUserId)
|
||||
@@ -85,7 +85,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
reporterSig,
|
||||
reporterPf,
|
||||
reporter.hashUserId,
|
||||
false,
|
||||
false
|
||||
)
|
||||
await app
|
||||
.userRegistry(reporter.hashUserId)
|
||||
@@ -138,7 +138,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nullifierCircuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -148,7 +148,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
posReputation
|
||||
)
|
||||
await expect(tx)
|
||||
.to.emit(app, 'ClaimPosRep')
|
||||
@@ -172,8 +172,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
|
||||
@@ -183,8 +183,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -225,7 +225,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nonNullifierCircuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -235,7 +235,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
nonNullifierIdentifier,
|
||||
posReputation,
|
||||
posReputation
|
||||
)
|
||||
await expect(tx)
|
||||
.to.emit(app, 'ClaimPosRep')
|
||||
@@ -256,8 +256,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -267,8 +267,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
usedPublicSig,
|
||||
usedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -294,7 +294,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nullifierCircuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -305,8 +305,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.reverted
|
||||
|
||||
upvoterState.stop()
|
||||
@@ -334,7 +334,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nullifierCircuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -344,8 +344,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'InvalidEpoch')
|
||||
|
||||
upvoterState.stop()
|
||||
@@ -373,7 +373,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nullifierCircuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -383,8 +383,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
nullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.reverted
|
||||
|
||||
upvoterState.stop()
|
||||
@@ -411,7 +411,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nonNullifierCircuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -422,8 +422,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
nonNullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.reverted
|
||||
reporterState.stop()
|
||||
})
|
||||
@@ -446,7 +446,7 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
nonNullifierCircuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -456,8 +456,8 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
nonNullifierIdentifier,
|
||||
posReputation,
|
||||
),
|
||||
posReputation
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
|
||||
@@ -484,13 +484,13 @@ describe('Claim Report Positive Reputation Test', function () {
|
||||
try {
|
||||
await genProofAndVerify(
|
||||
nonNullifierCircuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
} catch (error: unknown) {
|
||||
expect?.(error).to.be.an.instanceof(ProofGenerationError)
|
||||
expect?.(error).to.have.property(
|
||||
'message',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n',
|
||||
'Error: Assert Failed. Error in template ReportNonNullifierProof_79 line: 42\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('Comment Test', function () {
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId,
|
||||
attesterId
|
||||
)
|
||||
const data = randomData()
|
||||
const { publicSignals, proof } = await genEpochKeyProof({
|
||||
@@ -101,7 +101,7 @@ describe('Comment Test', function () {
|
||||
})
|
||||
const postId = 0
|
||||
await expect(
|
||||
app.leaveComment(publicSignals, proof, postId, 'Invalid Epoch'),
|
||||
app.leaveComment(publicSignals, proof, postId, 'Invalid Epoch')
|
||||
).to.be.revertedWithCustomError(app, 'InvalidEpoch')
|
||||
userState.stop()
|
||||
})
|
||||
@@ -116,7 +116,7 @@ describe('Comment Test', function () {
|
||||
proof[0] = BigInt(0)
|
||||
|
||||
await expect(
|
||||
app.leaveComment(publicSignals, proof, BigInt(0), content),
|
||||
app.leaveComment(publicSignals, proof, BigInt(0), content)
|
||||
).to.be.reverted
|
||||
userState.stop()
|
||||
})
|
||||
@@ -136,7 +136,7 @@ describe('Comment Test', function () {
|
||||
inputProof = proof
|
||||
|
||||
await expect(
|
||||
app.leaveComment(publicSignals, proof, postId, content),
|
||||
app.leaveComment(publicSignals, proof, postId, content)
|
||||
)
|
||||
.to.emit(app, 'Comment')
|
||||
.withArgs(
|
||||
@@ -144,7 +144,7 @@ describe('Comment Test', function () {
|
||||
postId,
|
||||
commentId,
|
||||
epoch,
|
||||
content,
|
||||
content
|
||||
)
|
||||
userState.stop()
|
||||
})
|
||||
@@ -153,7 +153,7 @@ describe('Comment Test', function () {
|
||||
const postId = 0
|
||||
const content = 'Reused Proof'
|
||||
expect(
|
||||
app.leaveComment(inputPublicSig, inputProof, postId, content),
|
||||
app.leaveComment(inputPublicSig, inputProof, postId, content)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
})
|
||||
@@ -181,8 +181,8 @@ describe('Comment Test', function () {
|
||||
proof,
|
||||
postId,
|
||||
commentId,
|
||||
content,
|
||||
),
|
||||
content
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'InvalidEpoch')
|
||||
userState.stop()
|
||||
})
|
||||
@@ -203,8 +203,8 @@ describe('Comment Test', function () {
|
||||
proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent,
|
||||
),
|
||||
newContent
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'InvalidCommentId')
|
||||
userState.stop()
|
||||
})
|
||||
@@ -226,8 +226,8 @@ describe('Comment Test', function () {
|
||||
proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent,
|
||||
),
|
||||
newContent
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'InvalidCommentEpochKey')
|
||||
userState.stop()
|
||||
})
|
||||
@@ -249,8 +249,8 @@ describe('Comment Test', function () {
|
||||
proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent,
|
||||
),
|
||||
newContent
|
||||
)
|
||||
).to.be.reverted
|
||||
userState.stop()
|
||||
})
|
||||
@@ -272,8 +272,8 @@ describe('Comment Test', function () {
|
||||
proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent,
|
||||
),
|
||||
newContent
|
||||
)
|
||||
)
|
||||
.to.emit(app, 'UpdatedComment')
|
||||
.withArgs(
|
||||
@@ -281,7 +281,7 @@ describe('Comment Test', function () {
|
||||
postId,
|
||||
commentId,
|
||||
0, // epoch
|
||||
newContent,
|
||||
newContent
|
||||
)
|
||||
userState.stop()
|
||||
})
|
||||
@@ -296,8 +296,8 @@ describe('Comment Test', function () {
|
||||
inputProof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent,
|
||||
),
|
||||
newContent
|
||||
)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -319,7 +319,7 @@ describe('Comment Test', function () {
|
||||
await unirep
|
||||
.userStateTransition(
|
||||
userTransitionSignals,
|
||||
userTransitiionProof,
|
||||
userTransitiionProof
|
||||
)
|
||||
.then((tx) => tx.wait())
|
||||
|
||||
@@ -339,8 +339,8 @@ describe('Comment Test', function () {
|
||||
proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent,
|
||||
),
|
||||
newContent
|
||||
)
|
||||
)
|
||||
.to.emit(app, 'UpdatedComment')
|
||||
.withArgs(
|
||||
@@ -348,7 +348,7 @@ describe('Comment Test', function () {
|
||||
postId,
|
||||
commentId,
|
||||
0, // epoch
|
||||
newContent,
|
||||
newContent
|
||||
)
|
||||
userState.stop()
|
||||
})
|
||||
|
||||
@@ -65,8 +65,8 @@ describe('Unirep App', function () {
|
||||
publicSignals,
|
||||
proof,
|
||||
user.hashUserId,
|
||||
false,
|
||||
),
|
||||
false
|
||||
)
|
||||
)
|
||||
.to.emit(app, 'UserSignUp')
|
||||
.withArgs(user.hashUserId, false)
|
||||
@@ -83,7 +83,7 @@ describe('Unirep App', function () {
|
||||
const { publicSignals, proof } =
|
||||
await userState.genUserSignUpProof()
|
||||
await expect(
|
||||
app.userSignUp(publicSignals, proof, user.hashUserId, false),
|
||||
app.userSignUp(publicSignals, proof, user.hashUserId, false)
|
||||
).to.be.revertedWithCustomError(app, 'UserHasRegistered')
|
||||
|
||||
userState.stop()
|
||||
@@ -104,8 +104,8 @@ describe('Unirep App', function () {
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
user.hashUserId,
|
||||
true,
|
||||
),
|
||||
true
|
||||
)
|
||||
).to.be.reverted
|
||||
|
||||
userState.stop()
|
||||
@@ -162,7 +162,7 @@ describe('Unirep App', function () {
|
||||
it('should fail to post with reused proof', async function () {
|
||||
const content = 'Reused Proof'
|
||||
await expect(
|
||||
app.post(inputPublicSig, inputProof, content),
|
||||
app.post(inputPublicSig, inputProof, content)
|
||||
).to.be.revertedWithCustomError(app, 'ProofHasUsed')
|
||||
})
|
||||
|
||||
@@ -176,7 +176,7 @@ describe('Unirep App', function () {
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId,
|
||||
attesterId
|
||||
)
|
||||
const data = randomData()
|
||||
const { publicSignals, proof } = await genEpochKeyProof({
|
||||
@@ -190,7 +190,7 @@ describe('Unirep App', function () {
|
||||
data,
|
||||
})
|
||||
await expect(
|
||||
app.post(publicSignals, proof, 'Invalid Epoch'),
|
||||
app.post(publicSignals, proof, 'Invalid Epoch')
|
||||
).to.be.revertedWithCustomError(app, 'InvalidEpoch')
|
||||
|
||||
userState.stop()
|
||||
@@ -207,7 +207,7 @@ describe('Unirep App', function () {
|
||||
const epkVerifier = await deployVerifierHelper(
|
||||
unirep.address,
|
||||
deployer,
|
||||
Circuit.epochKey,
|
||||
Circuit.epochKey
|
||||
)
|
||||
await epkVerifier.verifyAndCheck(publicSignals, proof)
|
||||
|
||||
@@ -256,12 +256,12 @@ describe('Unirep App', function () {
|
||||
})
|
||||
const p = await prover.genProofAndPublicSignals(
|
||||
'dataProof',
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
const { publicSignals, proof } = new DataProof(
|
||||
p.publicSignals,
|
||||
p.proof,
|
||||
prover,
|
||||
prover
|
||||
)
|
||||
const isValid = await app.verifyDataProof(publicSignals, proof)
|
||||
expect(isValid).to.be.true
|
||||
|
||||
@@ -55,13 +55,13 @@ describe('Verifier Helper Manager Test', function () {
|
||||
const epkHelper = await deployVerifierHelper(
|
||||
unirep.address,
|
||||
deployer,
|
||||
Circuit.epochKey,
|
||||
Circuit.epochKey
|
||||
)
|
||||
const identifier = genVHelperIdentifier('epochKeyVerifierHelper')
|
||||
await expect(
|
||||
vHelperManager
|
||||
.connect(notOwner)
|
||||
.verifierRegister(identifier, epkHelper.address),
|
||||
.verifierRegister(identifier, epkHelper.address)
|
||||
).to.be.reverted
|
||||
})
|
||||
|
||||
@@ -81,7 +81,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const reportNonNullifierCircuitInputs =
|
||||
@@ -97,7 +97,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
expect(isValid).to.be.equal(true)
|
||||
@@ -105,7 +105,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
const currentEpochKey = publicSignals[0]
|
||||
// generate identifier
|
||||
const identifier = genVHelperIdentifier(
|
||||
'reportNonNullifierProofVerifierHelper',
|
||||
'reportNonNullifierProofVerifierHelper'
|
||||
)
|
||||
|
||||
// get verifier from identifier in unirepApp.vHelpManager
|
||||
@@ -114,7 +114,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
const signal = await app.verifyWithIdentifier(
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
identifier,
|
||||
identifier
|
||||
)
|
||||
expect(signal.epochKey.toString()).to.be.equal(
|
||||
genEpochKey(
|
||||
@@ -122,12 +122,12 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
currentEpoch,
|
||||
currentNonce,
|
||||
chainId,
|
||||
).toString(),
|
||||
chainId
|
||||
).toString()
|
||||
)
|
||||
expect(signal.epoch.toString()).to.be.equal(currentEpoch.toString())
|
||||
expect(signal.attesterId.toString()).to.be.equal(
|
||||
attesterId.toString(),
|
||||
attesterId.toString()
|
||||
)
|
||||
expect(signal.chainId.toString()).to.be.equal(chainId.toString())
|
||||
|
||||
@@ -149,7 +149,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const reportNonNullifierCircuitInputs =
|
||||
@@ -165,14 +165,14 @@ describe('Verifier Helper Manager Test', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
// generate identifier
|
||||
const identifier = genVHelperIdentifier(
|
||||
'reportNonNullifierProofVerifierHelper',
|
||||
'reportNonNullifierProofVerifierHelper'
|
||||
)
|
||||
|
||||
// get verifier from identifier in unirepApp.vHelpManager
|
||||
@@ -184,8 +184,8 @@ describe('Verifier Helper Manager Test', function () {
|
||||
app.verifyWithIdentifier(
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
identifier,
|
||||
),
|
||||
identifier
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
})
|
||||
@@ -211,19 +211,19 @@ describe('Verifier Helper Manager Test', function () {
|
||||
currentNonce,
|
||||
attesterId,
|
||||
chainId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
// generate identifier
|
||||
const identifier = genVHelperIdentifier(
|
||||
'reportNullifierProofVerifierHelper',
|
||||
'reportNullifierProofVerifierHelper'
|
||||
)
|
||||
|
||||
// get verifier from identifier in unirepApp.vHelpManager
|
||||
@@ -231,7 +231,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
const signal = await app.verifyWithIdentifier(
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
identifier,
|
||||
identifier
|
||||
)
|
||||
expect(signal.epochKey.toString()).to.be.equal(
|
||||
genEpochKey(
|
||||
@@ -239,12 +239,12 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
currentEpoch,
|
||||
currentNonce,
|
||||
chainId,
|
||||
).toString(),
|
||||
chainId
|
||||
).toString()
|
||||
)
|
||||
expect(signal.epoch.toString()).to.be.equal(currentEpoch.toString())
|
||||
expect(signal.attesterId.toString()).to.be.equal(
|
||||
attesterId.toString(),
|
||||
attesterId.toString()
|
||||
)
|
||||
expect(signal.chainId.toString()).to.be.equal(chainId.toString())
|
||||
|
||||
@@ -272,19 +272,19 @@ describe('Verifier Helper Manager Test', function () {
|
||||
currentNonce,
|
||||
attesterId,
|
||||
chainId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
// generate identifier
|
||||
const identifier = genVHelperIdentifier(
|
||||
'reportNullifierProofVerifierHelper',
|
||||
'reportNullifierProofVerifierHelper'
|
||||
)
|
||||
|
||||
// get verifier from identifier in unirepApp.vHelpManager
|
||||
@@ -296,8 +296,8 @@ describe('Verifier Helper Manager Test', function () {
|
||||
app.verifyWithIdentifier(
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
identifier,
|
||||
),
|
||||
identifier
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
})
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const reportNonNullifierCircuitInputs =
|
||||
@@ -83,7 +83,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
@@ -92,7 +92,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
|
||||
const signal = await reportNonNullifierVHelper.verifyAndCheck(
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
flattenedProof
|
||||
)
|
||||
|
||||
expect(signal.epochKey.toString()).to.be.equal(
|
||||
@@ -101,12 +101,12 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
currentEpoch,
|
||||
currentNonce,
|
||||
chainId,
|
||||
).toString(),
|
||||
chainId
|
||||
).toString()
|
||||
)
|
||||
expect(signal.epoch.toString()).to.be.equal(currentEpoch.toString())
|
||||
expect(signal.attesterId.toString()).to.be.equal(
|
||||
attesterId.toString(),
|
||||
attesterId.toString()
|
||||
)
|
||||
expect(signal.chainId.toString()).to.be.equal(chainId.toString())
|
||||
|
||||
@@ -130,7 +130,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const reportNonNullifierCircuitInputs =
|
||||
@@ -146,7 +146,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
@@ -158,8 +158,8 @@ describe('Verifier Helper Manager Test', function () {
|
||||
await expect(
|
||||
reportNonNullifierVHelper.verifyAndCheck(
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
),
|
||||
invalidProof
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
})
|
||||
@@ -185,19 +185,19 @@ describe('Verifier Helper Manager Test', function () {
|
||||
currentNonce,
|
||||
attesterId,
|
||||
chainId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
const signal = await reportNullifierVHelper.verifyAndCheck(
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
flattenedProof
|
||||
)
|
||||
expect(signal.epochKey.toString()).to.be.equal(
|
||||
genEpochKey(
|
||||
@@ -205,12 +205,12 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
currentEpoch,
|
||||
currentNonce,
|
||||
chainId,
|
||||
).toString(),
|
||||
chainId
|
||||
).toString()
|
||||
)
|
||||
expect(signal.epoch.toString()).to.be.equal(currentEpoch.toString())
|
||||
expect(signal.attesterId.toString()).to.be.equal(
|
||||
attesterId.toString(),
|
||||
attesterId.toString()
|
||||
)
|
||||
expect(signal.chainId.toString()).to.be.equal(chainId.toString())
|
||||
|
||||
@@ -238,12 +238,12 @@ describe('Verifier Helper Manager Test', function () {
|
||||
currentNonce,
|
||||
attesterId,
|
||||
chainId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
@@ -256,8 +256,8 @@ describe('Verifier Helper Manager Test', function () {
|
||||
await expect(
|
||||
reportNullifierVHelper.verifyAndCheck(
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
),
|
||||
invalidProof
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,7 +65,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const reportNonNullifierCircuitInputs =
|
||||
@@ -82,7 +82,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
// generating proof for report negative reputation proof
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
const flattenedProof = flattenProof(proof)
|
||||
const valid = await reportNonNullifierVerifier.verifyProof(
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
flattenedProof
|
||||
)
|
||||
expect(valid).to.be.equal(true)
|
||||
})
|
||||
@@ -109,7 +109,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
attesterId,
|
||||
reportedEpoch,
|
||||
reportedNonce,
|
||||
chainId,
|
||||
chainId
|
||||
)
|
||||
|
||||
const reportNonNullifierCircuitInputs =
|
||||
@@ -126,7 +126,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
// generating proof for report negative reputation proof
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNonNullifierCircuitInputs,
|
||||
reportNonNullifierCircuitInputs
|
||||
)
|
||||
|
||||
// get verifier from identifier in unirepApp.vHelpManager
|
||||
@@ -138,8 +138,8 @@ describe('Verifier Helper Manager Test', function () {
|
||||
await expect(
|
||||
reportNonNullifierVerifier.verifyProof(
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
),
|
||||
invalidProof
|
||||
)
|
||||
).to.be.reverted
|
||||
})
|
||||
})
|
||||
@@ -165,20 +165,20 @@ describe('Verifier Helper Manager Test', function () {
|
||||
currentNonce,
|
||||
attesterId,
|
||||
chainId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// generating proof for report negative reputation proof
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
expect(isValid).to.be.equal(true)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
const valid = await reportNullifierVerifier.verifyProof(
|
||||
publicSignals,
|
||||
flattenedProof,
|
||||
flattenedProof
|
||||
)
|
||||
expect(valid).to.be.equal(true)
|
||||
})
|
||||
@@ -202,13 +202,13 @@ describe('Verifier Helper Manager Test', function () {
|
||||
currentNonce,
|
||||
attesterId,
|
||||
chainId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// generating proof for report nullifier proof
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
circuit,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const flattenedProof = flattenProof(proof)
|
||||
@@ -217,10 +217,7 @@ describe('Verifier Helper Manager Test', function () {
|
||||
.concat(BigInt(0).toString())
|
||||
|
||||
await expect(
|
||||
reportNullifierVerifier.verifyProof(
|
||||
publicSignals,
|
||||
invalidProof,
|
||||
),
|
||||
reportNullifierVerifier.verifyProof(publicSignals, invalidProof)
|
||||
).to.be.reverted
|
||||
})
|
||||
})
|
||||
|
||||
@@ -92,7 +92,7 @@ export async function genEpochKeyProof(config: {
|
||||
{
|
||||
data: [],
|
||||
},
|
||||
config,
|
||||
config
|
||||
)
|
||||
const data = [..._data, ...Array(FIELD_COUNT - _data.length).fill(0)]
|
||||
const _proof = tree.createProof(leafIndex)
|
||||
@@ -110,13 +110,13 @@ export async function genEpochKeyProof(config: {
|
||||
}
|
||||
const r = await prover.genProofAndPublicSignals(
|
||||
Circuit.epochKey,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const { publicSignals, proof } = new EpochKeyProof(
|
||||
r.publicSignals,
|
||||
r.proof,
|
||||
prover,
|
||||
prover
|
||||
)
|
||||
|
||||
return { publicSignals, proof }
|
||||
@@ -136,7 +136,7 @@ export async function genEpochKeyLiteProof(config: {
|
||||
{
|
||||
data: [],
|
||||
},
|
||||
config,
|
||||
config
|
||||
)
|
||||
const circuitInputs = {
|
||||
identity_secret: id.secret,
|
||||
@@ -150,13 +150,13 @@ export async function genEpochKeyLiteProof(config: {
|
||||
|
||||
const r = await prover.genProofAndPublicSignals(
|
||||
Circuit.epochKeyLite,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const { publicSignals, proof } = new EpochKeyLiteProof(
|
||||
r.publicSignals,
|
||||
r.proof,
|
||||
prover,
|
||||
prover
|
||||
)
|
||||
|
||||
return { publicSignals, proof }
|
||||
@@ -171,7 +171,7 @@ export const randomData = () => [
|
||||
.map(
|
||||
() =>
|
||||
poseidon1([Math.floor(Math.random() * 199191919)]) %
|
||||
BigInt(2) ** BigInt(253),
|
||||
BigInt(2) ** BigInt(253)
|
||||
),
|
||||
]
|
||||
|
||||
@@ -239,7 +239,7 @@ export function genReportNullifierCircuitInput(config: {
|
||||
|
||||
export async function genProofAndVerify(
|
||||
circuit: Circuit | string,
|
||||
circuitInputs: any,
|
||||
circuitInputs: any
|
||||
) {
|
||||
const startTime = new Date().getTime()
|
||||
let proof: any, publicSignals: any
|
||||
@@ -247,7 +247,7 @@ export async function genProofAndVerify(
|
||||
;({ proof, publicSignals } =
|
||||
await defaultProver.genProofAndPublicSignals(
|
||||
circuit,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
))
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
@@ -259,13 +259,13 @@ export async function genProofAndVerify(
|
||||
const endTime = new Date().getTime()
|
||||
console.log(
|
||||
`Gen Proof time: ${endTime - startTime} ms (${Math.floor(
|
||||
(endTime - startTime) / 1000,
|
||||
)} s)`,
|
||||
(endTime - startTime) / 1000
|
||||
)} s)`
|
||||
)
|
||||
const isValid = await defaultProver.verifyProof(
|
||||
circuit,
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
return { isValid, proof, publicSignals }
|
||||
}
|
||||
@@ -273,7 +273,7 @@ export async function genProofAndVerify(
|
||||
export function genVHelperIdentifier(identifier: string): string {
|
||||
const encodedId = ethers.utils.defaultAbiCoder.encode(
|
||||
['string'],
|
||||
[identifier],
|
||||
[identifier]
|
||||
)
|
||||
return ethers.utils.keccak256(encodedId)
|
||||
}
|
||||
@@ -298,7 +298,7 @@ export function genNullifier(identity: Identity, reportId: number | bigint) {
|
||||
export async function userStateTransition(
|
||||
userState: UserState,
|
||||
unirep: any,
|
||||
app: any,
|
||||
app: any
|
||||
) {
|
||||
const latestEpoch = await unirep.attesterCurrentEpoch(app.address)
|
||||
const remainingTime = await unirep.attesterEpochRemainingTime(app.address)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
|
||||
@@ -9,8 +9,8 @@ export default function SignupProgress() {
|
||||
const message = isSignedUp
|
||||
? '恭喜註冊成功! 🙌🏻'
|
||||
: isSigningUp
|
||||
? '努力註冊中,先來認識平台的功能吧!'
|
||||
: ''
|
||||
? '努力註冊中,先來認識平台的功能吧!'
|
||||
: ''
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-2">
|
||||
|
||||
@@ -13,8 +13,9 @@ export function useLoginWithWallet() {
|
||||
} = useMutation({
|
||||
mutationFn: async () => {
|
||||
const hashUserId = LocalStorageHelper.getGuaranteedHashUserId()
|
||||
const signature =
|
||||
await EthereumHelper.signUserIdWithWallet(hashUserId)
|
||||
const signature = await EthereumHelper.signUserIdWithWallet(
|
||||
hashUserId,
|
||||
)
|
||||
await baseLogin({ signature })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -31,8 +31,9 @@ export class ReportService extends RelayApiService {
|
||||
|
||||
async fetchReportCategories() {
|
||||
const client = this.getClient()
|
||||
const response =
|
||||
await client.get<RelayRawReportCategory[]>(`/report/category`)
|
||||
const response = await client.get<RelayRawReportCategory[]>(
|
||||
`/report/category`,
|
||||
)
|
||||
return response.data
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,7 @@ import {
|
||||
} from './ReportFormStep'
|
||||
|
||||
class Option {
|
||||
constructor(
|
||||
public value: number,
|
||||
public label: string,
|
||||
) {}
|
||||
constructor(public value: number, public label: string) {}
|
||||
}
|
||||
|
||||
interface ReportFormCategoriesProps {
|
||||
|
||||
@@ -65,8 +65,8 @@ export default function ImageResizer({
|
||||
const maxWidthContainer = maxWidth
|
||||
? maxWidth
|
||||
: editorRootElement !== null
|
||||
? editorRootElement.getBoundingClientRect().width - 20
|
||||
: 100
|
||||
? editorRootElement.getBoundingClientRect().width - 20
|
||||
: 100
|
||||
const maxHeightContainer =
|
||||
editorRootElement !== null
|
||||
? editorRootElement.getBoundingClientRect().height - 20
|
||||
|
||||
@@ -72,8 +72,5 @@ export class InvalidFromToEpoch implements FromToEpoch {
|
||||
}
|
||||
|
||||
export class ValidFromToEpoch implements FromToEpoch {
|
||||
constructor(
|
||||
public from: number,
|
||||
public to: number,
|
||||
) {}
|
||||
constructor(public from: number, public to: number) {}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,6 @@ export default _schema
|
||||
default: () => nanoid(),
|
||||
},
|
||||
],
|
||||
}) as TableData,
|
||||
} as TableData)
|
||||
)
|
||||
.concat(schema)
|
||||
|
||||
@@ -43,7 +43,7 @@ async function main() {
|
||||
app.use(
|
||||
cors({
|
||||
origin: CLIENT_URL,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
const httpServer = createServer(app)
|
||||
@@ -64,7 +64,7 @@ async function main() {
|
||||
unirepAddress: UNIREP_ADDRESS,
|
||||
genesisBlock: parseInt(GENESIS_BLOCK),
|
||||
},
|
||||
new ethers.Contract(APP_ADDRESS, APP_ABI, provider),
|
||||
new ethers.Contract(APP_ADDRESS, APP_ABI, provider)
|
||||
)
|
||||
|
||||
// reset all data if reset flag is true and evn is not production
|
||||
|
||||
@@ -13,7 +13,7 @@ export const base64ToJson = (base64String) => {
|
||||
}
|
||||
|
||||
export const createCheckReputationMiddleware = (
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) =>
|
||||
async function (req, res, next) {
|
||||
const authentication = req.headers.authentication
|
||||
@@ -26,7 +26,7 @@ export const createCheckReputationMiddleware = (
|
||||
const reputationProof = await ProofHelper.getAndVerifyReputationProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
// check negative reputation
|
||||
|
||||
@@ -6,12 +6,12 @@ import { UnirepSocialSynchronizer } from '../services/singletons/UnirepSocialSyn
|
||||
export default (
|
||||
app: Express,
|
||||
_: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.get('/api/config', async (_, res) => {
|
||||
const epochLength =
|
||||
await synchronizer.unirepContract.attesterEpochLength(
|
||||
BigInt(APP_ADDRESS).toString(),
|
||||
BigInt(APP_ADDRESS).toString()
|
||||
)
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Errors } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/checkin',
|
||||
@@ -24,10 +24,10 @@ export default (
|
||||
publicSignals,
|
||||
proof,
|
||||
db,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
res.json({ txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
helia: Helia,
|
||||
helia: Helia
|
||||
) => {
|
||||
app.route('/api/comment')
|
||||
.get(
|
||||
@@ -25,18 +25,18 @@ export default (
|
||||
|
||||
const post = await postService.fetchSinglePost(
|
||||
postId as string,
|
||||
db,
|
||||
db
|
||||
)
|
||||
|
||||
if (!post) throw Errors.POST_NOT_EXIST()
|
||||
|
||||
const comments = await commentService.fetchComments(
|
||||
postId as string,
|
||||
db,
|
||||
db
|
||||
)
|
||||
|
||||
res.json(comments)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
.post(
|
||||
@@ -55,7 +55,7 @@ export default (
|
||||
|
||||
const post = await postService.fetchSinglePost(
|
||||
postId.toString(),
|
||||
db,
|
||||
db
|
||||
)
|
||||
|
||||
if (!post) throw Errors.POST_NOT_EXIST()
|
||||
@@ -67,10 +67,10 @@ export default (
|
||||
proof,
|
||||
db,
|
||||
synchronizer,
|
||||
helia,
|
||||
helia
|
||||
)
|
||||
res.json({ txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
.delete(
|
||||
@@ -87,10 +87,10 @@ export default (
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
db,
|
||||
db
|
||||
)
|
||||
res.json({ txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -105,9 +105,9 @@ export default (
|
||||
const history = await commentService.getCommentHistory(
|
||||
fromEpoch,
|
||||
toEpoch,
|
||||
db,
|
||||
db
|
||||
)
|
||||
res.status(200).json(history)
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Errors } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.get(
|
||||
'/api/counter',
|
||||
@@ -25,6 +25,6 @@ export default (
|
||||
const counter = await counterService.fetchActions(epks, db)
|
||||
|
||||
res.json({ counter })
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ export default (app: Express, db: DB) => {
|
||||
epks: string[],
|
||||
sortKey: 'publishedAt' | 'voteSum',
|
||||
direction: 'asc' | 'desc',
|
||||
db: DB,
|
||||
) => Promise<any[] | null>,
|
||||
db: DB
|
||||
) => Promise<any[] | null>
|
||||
) => {
|
||||
const epks = req.query.epks as string | undefined
|
||||
const parsedEpks = epks?.split('_') || []
|
||||
@@ -45,10 +45,10 @@ export default (app: Express, db: DB) => {
|
||||
epks,
|
||||
sortKey,
|
||||
direction,
|
||||
db,
|
||||
),
|
||||
db
|
||||
)
|
||||
)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -62,10 +62,10 @@ export default (app: Express, db: DB) => {
|
||||
epks,
|
||||
sortKey,
|
||||
direction,
|
||||
db,
|
||||
),
|
||||
db
|
||||
)
|
||||
)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -79,9 +79,9 @@ export default (app: Express, db: DB) => {
|
||||
epks,
|
||||
sortKey,
|
||||
direction,
|
||||
db,
|
||||
),
|
||||
db
|
||||
)
|
||||
)
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
helia: Helia,
|
||||
helia: Helia
|
||||
) => {
|
||||
app.get(
|
||||
'/api/post',
|
||||
@@ -31,7 +31,7 @@ export default (
|
||||
const keyword = req.query.q ? (req.query.q as string) : undefined
|
||||
const posts = await postService.fetchPosts(epks, page, keyword, db)
|
||||
res.json(posts)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.post(
|
||||
@@ -50,11 +50,11 @@ export default (
|
||||
proof,
|
||||
db,
|
||||
synchronizer,
|
||||
helia,
|
||||
helia
|
||||
)
|
||||
|
||||
res.json({ txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -69,10 +69,10 @@ export default (
|
||||
const history = await postService.getPostHistory(
|
||||
fromEpoch,
|
||||
toEpoch,
|
||||
db,
|
||||
db
|
||||
)
|
||||
res.status(200).json(history)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -88,6 +88,6 @@ export default (
|
||||
} else {
|
||||
res.json(post)
|
||||
}
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { AdjudicateValue, Errors } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/report',
|
||||
@@ -29,14 +29,14 @@ export default (
|
||||
_reportData,
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
// 2. Create a report
|
||||
const reportId = await reportService.createReport(db, reportData)
|
||||
// 3. Adjust Post / Comment Status
|
||||
await reportService.updateObjectStatus(db, reportData)
|
||||
res.json({ reportId })
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -51,16 +51,16 @@ export default (
|
||||
await ProofHelper.getAndVerifyEpochKeyLiteProof(
|
||||
JSON.parse(publicSignals as string) as PublicSignals,
|
||||
JSON.parse(proof as string) as Groth16Proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
const reports = await reportService.fetchReports(
|
||||
Number(status),
|
||||
synchronizer,
|
||||
db,
|
||||
db
|
||||
)
|
||||
res.json(reports)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.post(
|
||||
@@ -88,11 +88,11 @@ export default (
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
db,
|
||||
db
|
||||
)
|
||||
|
||||
res.status(201).json({})
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -100,7 +100,7 @@ export default (
|
||||
errorHandler((req, res, next) => {
|
||||
const reportCategories = reportService.fetchReportCategory()
|
||||
res.json(reportCategories)
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -117,16 +117,16 @@ export default (
|
||||
await ProofHelper.getAndVerifyEpochKeyLiteProof(
|
||||
JSON.parse(publicSignals as string) as PublicSignals,
|
||||
JSON.parse(proof as string) as Groth16Proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
const report = await reportService.fetchSingleReportWithDetails(
|
||||
id,
|
||||
db,
|
||||
db
|
||||
)
|
||||
if (!report) throw Errors.REPORT_NOT_EXIST()
|
||||
|
||||
res.json(report)
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Errors, ReportStatus } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/reputation/claim',
|
||||
@@ -20,7 +20,7 @@ export default (
|
||||
claimSignals,
|
||||
claimProof,
|
||||
userType,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
const isProofValid = await reportProof.verify()
|
||||
@@ -43,7 +43,7 @@ export default (
|
||||
await reportService.validateClaimRequest(
|
||||
report,
|
||||
userType,
|
||||
reportProof,
|
||||
reportProof
|
||||
)
|
||||
|
||||
const txHash = await reportService.claim(
|
||||
@@ -51,14 +51,14 @@ export default (
|
||||
claimChange,
|
||||
identifier,
|
||||
claimSignals,
|
||||
claimProof,
|
||||
claimProof
|
||||
)
|
||||
|
||||
await reportService.updateReportStatus(
|
||||
reportId,
|
||||
userType,
|
||||
db,
|
||||
reportProof,
|
||||
reportProof
|
||||
)
|
||||
|
||||
await reportService.createReputationHistory(
|
||||
@@ -67,7 +67,7 @@ export default (
|
||||
claimChange,
|
||||
repType,
|
||||
reportId,
|
||||
reportProof,
|
||||
reportProof
|
||||
)
|
||||
|
||||
res.json({
|
||||
@@ -81,6 +81,6 @@ export default (
|
||||
isPassed: isPassed,
|
||||
},
|
||||
})
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Errors } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.get(
|
||||
'/api/reputation/history',
|
||||
@@ -28,10 +28,10 @@ export default (
|
||||
await reputationService.findManyReputationHistory(
|
||||
fromEpoch,
|
||||
toEpoch,
|
||||
db,
|
||||
db
|
||||
)
|
||||
|
||||
res.json(reputations)
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { errorHandler } from '../services/utils/ErrorHandler'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/request',
|
||||
@@ -18,7 +18,7 @@ export default (
|
||||
const epochKeyProof = await ProofHelper.getAndVerifyEpochKeyProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
const epoch = epochKeyProof.epoch
|
||||
@@ -27,7 +27,7 @@ export default (
|
||||
if (keys.length === 1) {
|
||||
txHash = await TransactionManager.callContract(
|
||||
'submitAttestation',
|
||||
[epochKeyProof.epochKey, epoch, keys[0], reqData[keys[0]]],
|
||||
[epochKeyProof.epochKey, epoch, keys[0], reqData[keys[0]]]
|
||||
)
|
||||
} else if (keys.length > 1) {
|
||||
txHash = await TransactionManager.callContract(
|
||||
@@ -37,11 +37,11 @@ export default (
|
||||
epoch,
|
||||
keys,
|
||||
keys.map((k) => reqData[k]),
|
||||
],
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
res.json({ txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { errorHandler } from '../services/utils/ErrorHandler'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/signup',
|
||||
@@ -20,9 +20,9 @@ export default (
|
||||
proof,
|
||||
hashUserId,
|
||||
fromServer,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
res.status(200).json({ status: 'success', txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Errors } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/transition',
|
||||
@@ -18,7 +18,7 @@ export default (
|
||||
const transitionProof = new UserStateTransitionProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
const valid = await transitionProof.verify()
|
||||
if (!valid) throw Errors.INVALID_PROOF()
|
||||
@@ -26,13 +26,13 @@ export default (
|
||||
const calldata =
|
||||
synchronizer.unirepContract.interface.encodeFunctionData(
|
||||
'userStateTransition',
|
||||
[transitionProof.publicSignals, transitionProof.proof],
|
||||
[transitionProof.publicSignals, transitionProof.proof]
|
||||
)
|
||||
const txHash = await TransactionManager.queueTransaction(
|
||||
synchronizer.unirepContract.address,
|
||||
calldata,
|
||||
calldata
|
||||
)
|
||||
res.json({ txHash })
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ const code_challenge = crypto.randomUUID()
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.get('/api/login', async (_, res) => {
|
||||
const url = TwitterClient.authClient.generateAuthURL({
|
||||
@@ -29,7 +29,7 @@ export default (
|
||||
const user = await userService.login(
|
||||
state as string,
|
||||
code as string,
|
||||
db,
|
||||
db
|
||||
)
|
||||
var redirectUrl = `${CLIENT_URL}/twitter/callback?code=${user.hashUserId}&status=${user.status}&token=${user.token}&signMsg=${user.signMsg}`
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Errors } from '../types'
|
||||
export default (
|
||||
app: Express,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) => {
|
||||
app.post(
|
||||
'/api/vote',
|
||||
@@ -35,10 +35,10 @@ export default (
|
||||
publicSignals,
|
||||
proof,
|
||||
db,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
res.status(201).json({})
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
app.get(
|
||||
@@ -53,9 +53,9 @@ export default (
|
||||
const history = await voteService.getVoteHistory(
|
||||
fromEpoch,
|
||||
toEpoch,
|
||||
db,
|
||||
db
|
||||
)
|
||||
res.status(200).json(history)
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class CommentService {
|
||||
|
||||
async fetchComments(
|
||||
postId: string,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Partial<Comment>[] | null> {
|
||||
const comments = await db.findMany('Comment', {
|
||||
where: {
|
||||
@@ -49,7 +49,7 @@ export class CommentService {
|
||||
async fetchSingleComment(
|
||||
commentId: string,
|
||||
db: DB,
|
||||
status?: CommentStatus,
|
||||
status?: CommentStatus
|
||||
): Promise<Partial<Comment> | null> {
|
||||
const whereClause: any = { commentId }
|
||||
if (status !== undefined) {
|
||||
@@ -64,7 +64,7 @@ export class CommentService {
|
||||
epks: string[],
|
||||
sortKey: 'publishedAt' | 'voteSum',
|
||||
direction: 'asc' | 'desc',
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Partial<Comment>[] | null> {
|
||||
const comments = await db.findMany('Comment', {
|
||||
where: {
|
||||
@@ -93,12 +93,12 @@ export class CommentService {
|
||||
proof: Groth16Proof,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
helia: Helia,
|
||||
helia: Helia
|
||||
) {
|
||||
const epochKeyProof = await ProofHelper.getAndVerifyEpochKeyProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
// store content into helia ipfs node with json plain
|
||||
@@ -135,7 +135,7 @@ export class CommentService {
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
db: DB,
|
||||
db: DB
|
||||
) {
|
||||
const comment: Comment = await db.findOne('Comment', {
|
||||
where: {
|
||||
@@ -150,7 +150,7 @@ export class CommentService {
|
||||
await ProofHelper.getAndVerifyEpochKeyLiteProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
if (epochKeyLiteProof.epochKey.toString() !== comment.epochKey)
|
||||
@@ -181,7 +181,7 @@ export class CommentService {
|
||||
async getCommentHistory(
|
||||
fromEpoch: number,
|
||||
toEpoch: number,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Comment[]> {
|
||||
if (fromEpoch > toEpoch || fromEpoch < 0 || toEpoch < 0)
|
||||
throw Errors.INVALID_EPOCH_RANGE()
|
||||
|
||||
@@ -14,7 +14,7 @@ export class PostService {
|
||||
async fetchOrderedPosts(
|
||||
db: DB,
|
||||
offset: number,
|
||||
content: string | undefined,
|
||||
content: string | undefined
|
||||
): Promise<Post[]> {
|
||||
// TODO i think this sql is not really maintainable for long term, should consider to refactor it
|
||||
// if user just posted, get the first ten result from db
|
||||
@@ -79,8 +79,8 @@ export class PostService {
|
||||
postId
|
||||
) AS c ON p.postId = c.postId
|
||||
WHERE p.status IN (${PostStatus.ON_CHAIN}, ${
|
||||
PostStatus.REPORTED
|
||||
}, ${PostStatus.DISAGREED})
|
||||
PostStatus.REPORTED
|
||||
}, ${PostStatus.DISAGREED})
|
||||
|
||||
${content ? `AND p.content LIKE '%${content}%'` : ''}
|
||||
|
||||
@@ -120,14 +120,14 @@ export class PostService {
|
||||
epks: string[] | undefined,
|
||||
page: number,
|
||||
keyword: string | undefined,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Partial<Post>[] | null> {
|
||||
let posts: Post[]
|
||||
if (!epks) {
|
||||
posts = await this.fetchOrderedPosts(
|
||||
db,
|
||||
(page - 1) * LOAD_POST_COUNT,
|
||||
keyword,
|
||||
keyword
|
||||
)
|
||||
} else {
|
||||
let whereClause = {
|
||||
@@ -155,14 +155,14 @@ export class PostService {
|
||||
where: { postId: post.postId },
|
||||
})
|
||||
return { ...post, votes }
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async fetchSinglePost(
|
||||
postId: string,
|
||||
db: DB,
|
||||
status?: PostStatus,
|
||||
status?: PostStatus
|
||||
): Promise<Post | null> {
|
||||
const whereClause: any = { postId }
|
||||
if (status !== undefined) {
|
||||
@@ -192,7 +192,7 @@ export class PostService {
|
||||
epks: string[],
|
||||
sortKey: 'publishedAt' | 'voteSum',
|
||||
direction: 'asc' | 'desc',
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Post[] | null> {
|
||||
const posts = await db.findMany('Post', {
|
||||
where: {
|
||||
@@ -218,7 +218,7 @@ export class PostService {
|
||||
where: { postId: post.postId },
|
||||
})
|
||||
return { ...post, votes }
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -228,12 +228,12 @@ export class PostService {
|
||||
proof: Groth16Proof,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
helia: Helia,
|
||||
helia: Helia
|
||||
): Promise<string> {
|
||||
const epochKeyProof = await ProofHelper.getAndVerifyEpochKeyProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
// post content
|
||||
@@ -268,7 +268,7 @@ export class PostService {
|
||||
async updatePostStatus(
|
||||
postId: string,
|
||||
status: number,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<void> {
|
||||
await db.update('Post', {
|
||||
where: { postId },
|
||||
@@ -279,7 +279,7 @@ export class PostService {
|
||||
async getPostHistory(
|
||||
fromEpoch: number,
|
||||
toEpoch: number,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Post[]> {
|
||||
if (fromEpoch > toEpoch || fromEpoch < 0 || toEpoch < 0)
|
||||
throw Errors.INVALID_EPOCH_RANGE()
|
||||
|
||||
@@ -36,7 +36,7 @@ export class ReportService {
|
||||
reportData: ReportHistory,
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
): Promise<ReportHistory> {
|
||||
// 1.a Check if the post / comment exists is not reported already(post status = 1 / comment status = 1)
|
||||
if (reportData.type === ReportType.POST) {
|
||||
@@ -45,7 +45,7 @@ export class ReportService {
|
||||
|
||||
const post = await postService.fetchSinglePost(
|
||||
reportData.objectId.toString(),
|
||||
db,
|
||||
db
|
||||
)
|
||||
if (!post) throw Errors.POST_NOT_EXIST()
|
||||
if (post.status === PostStatus.REPORTED)
|
||||
@@ -56,7 +56,7 @@ export class ReportService {
|
||||
throw Errors.INVALID_COMMENT_ID()
|
||||
const comment = await commentService.fetchSingleComment(
|
||||
reportData.objectId.toString(),
|
||||
db,
|
||||
db
|
||||
)
|
||||
if (!comment) throw Errors.COMMENT_NOT_EXIST()
|
||||
if (comment.status === CommentStatus.REPORTED)
|
||||
@@ -69,7 +69,7 @@ export class ReportService {
|
||||
await ProofHelper.getAndVerifyEpochKeyProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
return reportData
|
||||
}
|
||||
@@ -99,13 +99,13 @@ export class ReportService {
|
||||
postService.updatePostStatus(
|
||||
reportData.objectId,
|
||||
PostStatus.REPORTED,
|
||||
db,
|
||||
db
|
||||
)
|
||||
} else if (reportData.type === ReportType.COMMENT) {
|
||||
commentService.updateCommentStatus(
|
||||
reportData.objectId,
|
||||
CommentStatus.REPORTED,
|
||||
db,
|
||||
db
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export class ReportService {
|
||||
async fetchReports(
|
||||
status: ReportStatus,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<ReportHistory[] | null> {
|
||||
const epoch = await synchronizer.loadCurrentEpoch()
|
||||
|
||||
@@ -175,7 +175,7 @@ export class ReportService {
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
db: DB,
|
||||
db: DB
|
||||
) {
|
||||
const report = await this.fetchSingleReport(reportId, db)
|
||||
const nullifier = publicSignals[0]
|
||||
@@ -186,7 +186,7 @@ export class ReportService {
|
||||
await ProofHelper.getAndVerifyReportIdentityProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
// check if user voted or not
|
||||
if (this.isVoted(nullifier, report)) throw Errors.USER_ALREADY_VOTED()
|
||||
@@ -194,7 +194,7 @@ export class ReportService {
|
||||
const adjudicatorsNullifier = this.upsertAdjudicatorsNullifier(
|
||||
nullifier,
|
||||
adjudicateValue,
|
||||
report,
|
||||
report
|
||||
)
|
||||
// default value is 0, but insert statement doesn't have this field
|
||||
// if this field is undefined, assume no one has voted yet.
|
||||
@@ -215,7 +215,7 @@ export class ReportService {
|
||||
upsertAdjudicatorsNullifier(
|
||||
nullifier: string,
|
||||
adjudicateValue: AdjudicateValue,
|
||||
report: ReportHistory,
|
||||
report: ReportHistory
|
||||
): Adjudicator[] {
|
||||
const newAdjudicator = {
|
||||
nullifier: nullifier,
|
||||
@@ -235,14 +235,14 @@ export class ReportService {
|
||||
// if nullifer is included in adjudicators, return true
|
||||
return adjudicators
|
||||
? adjudicators.some(
|
||||
(adjudicator) => adjudicator.nullifier == nullifier,
|
||||
(adjudicator) => adjudicator.nullifier == nullifier
|
||||
)
|
||||
: false
|
||||
}
|
||||
|
||||
async fetchSingleReport(
|
||||
reportId: string,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<ReportHistory | null> {
|
||||
const report = await db.findOne('ReportHistory', {
|
||||
where: {
|
||||
@@ -295,7 +295,7 @@ export class ReportService {
|
||||
change: RepChangeType,
|
||||
repType: ReputationType,
|
||||
reportId: string,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
await db.create('ReputationHistory', {
|
||||
transactionHash: txHash,
|
||||
@@ -321,7 +321,7 @@ export class ReportService {
|
||||
|
||||
getReputationType(
|
||||
isPassed: boolean,
|
||||
repUserType: RepUserType,
|
||||
repUserType: RepUserType
|
||||
): ReputationType {
|
||||
switch (repUserType) {
|
||||
case RepUserType.ADJUDICATOR:
|
||||
@@ -351,13 +351,13 @@ export class ReportService {
|
||||
|
||||
checkAdjudicatorNullifier(
|
||||
report: ReportHistory,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
if (
|
||||
!report.adjudicatorsNullifier?.some(
|
||||
(adj) =>
|
||||
!(reportProof instanceof ReportNonNullifierProof) &&
|
||||
adj.nullifier === reportProof.reportNullifier.toString(),
|
||||
adj.nullifier === reportProof.reportNullifier.toString()
|
||||
)
|
||||
) {
|
||||
throw new Error('Invalid adjudicator nullifier')
|
||||
@@ -366,14 +366,14 @@ export class ReportService {
|
||||
|
||||
checkAdjudicatorIsClaimed(
|
||||
report: ReportHistory,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
if (
|
||||
report.adjudicatorsNullifier?.some(
|
||||
(adj) =>
|
||||
!(reportProof instanceof ReportNonNullifierProof) &&
|
||||
adj.nullifier === reportProof.reportNullifier.toString() &&
|
||||
adj.claimed,
|
||||
adj.claimed
|
||||
)
|
||||
) {
|
||||
throw Errors.USER_ALREADY_CLAIMED()
|
||||
@@ -382,7 +382,7 @@ export class ReportService {
|
||||
|
||||
checkRespondentEpochKey(
|
||||
report: ReportHistory,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
if (
|
||||
!(reportProof instanceof ReportNonNullifierProof) ||
|
||||
@@ -395,7 +395,7 @@ export class ReportService {
|
||||
|
||||
checkReportorEpochKey(
|
||||
report: ReportHistory,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
if (
|
||||
!(reportProof instanceof ReportNonNullifierProof) ||
|
||||
@@ -420,7 +420,7 @@ export class ReportService {
|
||||
return ClaimMethods.CLAIM_NEGATIVE_REP
|
||||
} else {
|
||||
throw new Error(
|
||||
'Poster cannot claim reputation for failed reports',
|
||||
'Poster cannot claim reputation for failed reports'
|
||||
)
|
||||
}
|
||||
case RepUserType.REPORTER:
|
||||
@@ -479,7 +479,7 @@ export class ReportService {
|
||||
reportId: string,
|
||||
repUserType: RepUserType,
|
||||
db: DB,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
const report = await this.fetchSingleReport(reportId, db)
|
||||
if (!report) throw new Error('Report not found')
|
||||
@@ -532,7 +532,7 @@ export class ReportService {
|
||||
claimChange: RepChangeType,
|
||||
identifier: string,
|
||||
publicSignals: any,
|
||||
proof: any,
|
||||
proof: any
|
||||
): Promise<string> {
|
||||
let txHash: string | undefined
|
||||
|
||||
@@ -546,7 +546,7 @@ export class ReportService {
|
||||
|
||||
if (!txHash) {
|
||||
throw new Error(
|
||||
'Transaction hash is undefined after contract call',
|
||||
'Transaction hash is undefined after contract call'
|
||||
)
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ export class ReportService {
|
||||
async validateClaimRequest(
|
||||
report: ReportHistory,
|
||||
repUserType: RepUserType,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof,
|
||||
reportProof: ReportNullifierProof | ReportNonNullifierProof
|
||||
) {
|
||||
if (repUserType === RepUserType.ADJUDICATOR) {
|
||||
this.checkAdjudicatorNullifier(report, reportProof)
|
||||
@@ -579,20 +579,20 @@ export class ReportService {
|
||||
async getEpochAndEpochKey(
|
||||
claimSignals: any,
|
||||
claimProof: any,
|
||||
repUserType: RepUserType,
|
||||
repUserType: RepUserType
|
||||
) {
|
||||
let currentEpoch: any, currentEpochKey: any, reportedEpochKey: any
|
||||
if (repUserType === RepUserType.ADJUDICATOR) {
|
||||
const reportNullifierProof = new ReportNullifierProof(
|
||||
claimSignals,
|
||||
claimProof,
|
||||
claimProof
|
||||
)
|
||||
currentEpoch = reportNullifierProof.epoch
|
||||
currentEpochKey = reportNullifierProof.currentEpochKey
|
||||
} else {
|
||||
const reportNonNullifierProof = new ReportNonNullifierProof(
|
||||
claimSignals,
|
||||
claimProof,
|
||||
claimProof
|
||||
)
|
||||
currentEpoch = reportNonNullifierProof.epoch
|
||||
currentEpochKey = reportNonNullifierProof.currentEpochKey
|
||||
@@ -606,26 +606,26 @@ export class ReportService {
|
||||
claimSignals: any,
|
||||
claimProof: any,
|
||||
repUserType: RepUserType,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
): Promise<ReportNullifierProof | ReportNonNullifierProof> {
|
||||
if (repUserType === RepUserType.ADJUDICATOR) {
|
||||
return new ReportNullifierProof(
|
||||
claimSignals,
|
||||
claimProof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
} else {
|
||||
return new ReportNonNullifierProof(
|
||||
claimSignals,
|
||||
claimProof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async fetchSingleReportWithDetails(
|
||||
reportId: string,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<ReportHistory | null> {
|
||||
// Fetch the base report
|
||||
const report = await this.fetchSingleReport(reportId, db)
|
||||
|
||||
@@ -13,7 +13,7 @@ export class ReputationService {
|
||||
async findManyReputationHistory(
|
||||
fromEpoch: number,
|
||||
toEpoch: number,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<ReputationHistory[] | null> {
|
||||
const reputations = await db.findMany('ReputationHistory', {
|
||||
where: {
|
||||
@@ -37,17 +37,17 @@ export class ReputationService {
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) {
|
||||
const epochKeyProof = await ProofHelper.getAndVerifyEpochKeyProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
const txHash = await TransactionManager.callContract(
|
||||
'claimDailyLoginRep',
|
||||
[epochKeyProof.publicSignals, epochKeyProof.proof],
|
||||
[epochKeyProof.publicSignals, epochKeyProof.proof]
|
||||
)
|
||||
|
||||
db.create('ReputationHistory', {
|
||||
|
||||
@@ -28,7 +28,7 @@ export class UserService {
|
||||
|
||||
try {
|
||||
const response = await TwitterClient.authClient.requestAccessToken(
|
||||
code as string,
|
||||
code as string
|
||||
)
|
||||
const userInfo = await TwitterClient.client.users.findMyUser()
|
||||
const userId = userInfo.data?.id
|
||||
@@ -36,7 +36,7 @@ export class UserService {
|
||||
return await this.getLoginUser(
|
||||
db,
|
||||
userId,
|
||||
response.token.access_token,
|
||||
response.token.access_token
|
||||
)
|
||||
} catch (error: any) {
|
||||
console.error('Error in user login:', error)
|
||||
@@ -85,12 +85,12 @@ export class UserService {
|
||||
proof: Groth16Proof,
|
||||
hashUserId: string,
|
||||
fromServer: boolean,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) {
|
||||
const signupProof = new SignupProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
|
||||
// verify attesterId, should be the same as app
|
||||
@@ -140,7 +140,7 @@ export class UserService {
|
||||
|
||||
if (this.encodeUserId(response?.data?.id) != hashUserId) {
|
||||
console.error(
|
||||
`AccessToken is invalid or user ${hashUserId} is not matched`,
|
||||
`AccessToken is invalid or user ${hashUserId} is not matched`
|
||||
)
|
||||
throw Errors.INVALID_HASH_USER_ID()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export class VoteService {
|
||||
epks: string[],
|
||||
sortKey: 'publishedAt' | 'voteSum',
|
||||
direction: 'asc' | 'desc',
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<any[]> {
|
||||
return db.findMany('Vote', {
|
||||
where: {
|
||||
@@ -29,7 +29,7 @@ export class VoteService {
|
||||
async getVoteHistory(
|
||||
fromEpoch: number,
|
||||
toEpoch: number,
|
||||
db: DB,
|
||||
db: DB
|
||||
): Promise<Vote[]> {
|
||||
if (fromEpoch > toEpoch || fromEpoch < 0 || toEpoch < 0)
|
||||
throw Errors.INVALID_EPOCH_RANGE()
|
||||
@@ -66,13 +66,13 @@ export class VoteService {
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
db: DB,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
) {
|
||||
// get valid epoch key
|
||||
const epochKeyProof = await ProofHelper.getAndVerifyEpochKeyLiteProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer,
|
||||
synchronizer
|
||||
)
|
||||
|
||||
// find post which is voted
|
||||
@@ -97,7 +97,7 @@ export class VoteService {
|
||||
epochKey,
|
||||
Number(epochKeyProof.epoch),
|
||||
post,
|
||||
voteAction,
|
||||
voteAction
|
||||
)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ export class VoteService {
|
||||
epochKey: string,
|
||||
epoch: number,
|
||||
post: any,
|
||||
voteAction: VoteAction,
|
||||
voteAction: VoteAction
|
||||
): Promise<void> {
|
||||
const postId = post.postId
|
||||
let createVote = true
|
||||
@@ -224,7 +224,7 @@ export class VoteService {
|
||||
db,
|
||||
epochKey,
|
||||
epoch,
|
||||
actionCount,
|
||||
actionCount
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ export class UnirepSocialSynchronizer extends Synchronizer {
|
||||
unirepAddress: string
|
||||
genesisBlock?: number
|
||||
},
|
||||
unirepSocialContract: ethers.Contract,
|
||||
unirepSocialContract: ethers.Contract
|
||||
) {
|
||||
tempUnirepSocialContract = unirepSocialContract
|
||||
super(config)
|
||||
@@ -133,8 +133,8 @@ export class UnirepSocialSynchronizer extends Synchronizer {
|
||||
? 2
|
||||
: 1
|
||||
: content
|
||||
? 1
|
||||
: 2
|
||||
? 1
|
||||
: 2
|
||||
|
||||
// Use upsert to either create a new comment or update an existing one
|
||||
db.upsert('Comment', {
|
||||
@@ -249,11 +249,11 @@ export class UnirepSocialSynchronizer extends Synchronizer {
|
||||
const adjudicators = report.adjudicatorsNullifier || []
|
||||
const agreeVotes = adjudicators.filter(
|
||||
(adj: Adjudicator) =>
|
||||
adj.adjudicateValue === AdjudicateValue.AGREE,
|
||||
adj.adjudicateValue === AdjudicateValue.AGREE
|
||||
).length
|
||||
const disagreeVotes = adjudicators.filter(
|
||||
(adj: Adjudicator) =>
|
||||
adj.adjudicateValue === AdjudicateValue.DISAGREE,
|
||||
adj.adjudicateValue === AdjudicateValue.DISAGREE
|
||||
).length
|
||||
// If the current epoch > reportEpoch AND sum of votes > threshold AND vote value > 0
|
||||
if (
|
||||
|
||||
@@ -7,7 +7,7 @@ export class ActionCountManager {
|
||||
db: DB,
|
||||
epochKey: string,
|
||||
epoch: number,
|
||||
actionCount: number,
|
||||
actionCount: number
|
||||
): Promise<void> {
|
||||
const counter = await db.findOne('EpochKeyAction', {
|
||||
where: {
|
||||
|
||||
@@ -14,13 +14,13 @@ class ProofHelper {
|
||||
async getAndVerifyEpochKeyProof(
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
): Promise<EpochKeyProof> {
|
||||
// verify epochKeyProof of user
|
||||
const epochKeyProof = new EpochKeyProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
|
||||
// check if attester id is valid
|
||||
@@ -33,7 +33,7 @@ class ProofHelper {
|
||||
const isStateTreeValid = await synchronizer.stateTreeRootExists(
|
||||
epochKeyProof.stateTreeRoot,
|
||||
Number(epochKeyProof.epoch),
|
||||
epochKeyProof.attesterId,
|
||||
epochKeyProof.attesterId
|
||||
)
|
||||
if (!isStateTreeValid) throw Errors.INVALID_STATE_TREE()
|
||||
|
||||
@@ -48,12 +48,12 @@ class ProofHelper {
|
||||
async getAndVerifyEpochKeyLiteProof(
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
): Promise<EpochKeyLiteProof> {
|
||||
const epochKeyLiteProof = new EpochKeyLiteProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
|
||||
// check if attester id is valid
|
||||
@@ -68,12 +68,12 @@ class ProofHelper {
|
||||
async getAndVerifyReputationProof(
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
): Promise<ReputationProof> {
|
||||
const reputationProof = new ReputationProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
|
||||
this.validateAttesterId(synchronizer, reputationProof)
|
||||
@@ -90,12 +90,12 @@ class ProofHelper {
|
||||
async getAndVerifyReportIdentityProof(
|
||||
publicSignals: PublicSignals,
|
||||
proof: Groth16Proof,
|
||||
synchronizer: UnirepSocialSynchronizer,
|
||||
synchronizer: UnirepSocialSynchronizer
|
||||
): Promise<ReportIdentityProof> {
|
||||
const reportIdentityProof = new ReportIdentityProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
synchronizer.prover,
|
||||
synchronizer.prover
|
||||
)
|
||||
|
||||
this.validateAttesterId(synchronizer, reportIdentityProof)
|
||||
@@ -137,7 +137,7 @@ class ProofHelper {
|
||||
export function genVHelperIdentifier(identifier: string): string {
|
||||
const encodedId = ethers.utils.defaultAbiCoder.encode(
|
||||
['string'],
|
||||
[identifier],
|
||||
[identifier]
|
||||
)
|
||||
return ethers.utils.keccak256(encodedId)
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ export default {
|
||||
*/
|
||||
genProofAndPublicSignals: async (
|
||||
circuitName: string | Circuit,
|
||||
inputs: any,
|
||||
inputs: any
|
||||
) => {
|
||||
const circuitWasmPath = path.join(buildPath, `${circuitName}.wasm`)
|
||||
const zkeyPath = path.join(buildPath, `${circuitName}.zkey`)
|
||||
const { proof, publicSignals } = await snarkjs.groth16.fullProve(
|
||||
inputs,
|
||||
circuitWasmPath,
|
||||
zkeyPath,
|
||||
zkeyPath
|
||||
)
|
||||
|
||||
return { proof, publicSignals }
|
||||
@@ -40,10 +40,10 @@ export default {
|
||||
verifyProof: async (
|
||||
circuitName: string | Circuit,
|
||||
publicSignals: snarkjs.PublicSignals,
|
||||
proof: snarkjs.Groth16Proof,
|
||||
proof: snarkjs.Groth16Proof
|
||||
) => {
|
||||
const vkeyData = await fs.readFile(
|
||||
path.join(buildPath, `${circuitName}.vkey.json`),
|
||||
path.join(buildPath, `${circuitName}.vkey.json`)
|
||||
)
|
||||
const vkey = JSON.parse(vkeyData.toString())
|
||||
return snarkjs.groth16.verify(vkey, publicSignals, proof)
|
||||
|
||||
@@ -94,7 +94,7 @@ export class TransactionManager {
|
||||
err
|
||||
.toString()
|
||||
.indexOf(
|
||||
'Your app has exceeded its compute units per second capacity',
|
||||
'Your app has exceeded its compute units per second capacity'
|
||||
) !== -1
|
||||
) {
|
||||
await new Promise((r) => setTimeout(r, 1000))
|
||||
@@ -143,7 +143,7 @@ export class TransactionManager {
|
||||
*/
|
||||
async queueTransaction(
|
||||
to: string,
|
||||
data: string | any = {},
|
||||
data: string | any = {}
|
||||
): Promise<string> {
|
||||
const args = {} as any
|
||||
if (typeof data === 'string') {
|
||||
@@ -165,10 +165,10 @@ export class TransactionManager {
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error(
|
||||
`${error.code} - Transaction error while estimating gas limit: ${error}`,
|
||||
`${error.code} - Transaction error while estimating gas limit: ${error}`
|
||||
)
|
||||
throw Errors.TRANSACTION_FAILED(
|
||||
`Transaction Error: ${error.message}`,
|
||||
`Transaction Error: ${error.message}`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -206,14 +206,14 @@ export class TransactionManager {
|
||||
*/
|
||||
async callContract(
|
||||
functionSignature: string, // 'leaveComment' for example
|
||||
args: any[],
|
||||
args: any[]
|
||||
): Promise<string> {
|
||||
if (!this.appContract) throw Errors.UNINITIALIZED()
|
||||
const appContract = this.appContract
|
||||
|
||||
const calldata = appContract.interface.encodeFunctionData(
|
||||
functionSignature,
|
||||
[...args],
|
||||
[...args]
|
||||
)
|
||||
const hash = await this.queueTransaction(appContract.address, calldata)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ export class InternalError extends Error {
|
||||
constructor(
|
||||
public message: string,
|
||||
public httpStatusCode: number = 500,
|
||||
public code: string = 'INTERNAL_ERROR',
|
||||
public code: string = 'INTERNAL_ERROR'
|
||||
) {
|
||||
super(message)
|
||||
this.name = this.constructor.name
|
||||
@@ -12,7 +12,7 @@ export class InternalError extends Error {
|
||||
export const createErrorType = (
|
||||
defaultMessage: string,
|
||||
httpStatusCode: number = 400,
|
||||
code: string,
|
||||
code: string
|
||||
) => {
|
||||
return (customMessage?: string) =>
|
||||
new InternalError(customMessage || defaultMessage, httpStatusCode, code)
|
||||
@@ -23,24 +23,24 @@ export const Errors = {
|
||||
TRANSACTION_FAILED: createErrorType(
|
||||
'Transaction failed',
|
||||
400,
|
||||
'TRANSACTION_FAILED',
|
||||
'TRANSACTION_FAILED'
|
||||
),
|
||||
|
||||
// User related errors
|
||||
INVALID_HASH_USER_ID: createErrorType(
|
||||
'Invalid hashUserId',
|
||||
400,
|
||||
'INVALID_HASH_USER_ID',
|
||||
'INVALID_HASH_USER_ID'
|
||||
),
|
||||
USER_ALREADY_SIGNED_UP: createErrorType(
|
||||
'The user has already signed up.',
|
||||
400,
|
||||
'USER_ALREADY_SIGNED_UP',
|
||||
'USER_ALREADY_SIGNED_UP'
|
||||
),
|
||||
USER_LOGIN_ERROR: createErrorType(
|
||||
'Error in login',
|
||||
400,
|
||||
'USER_LOGIN_ERROR',
|
||||
'USER_LOGIN_ERROR'
|
||||
),
|
||||
|
||||
// General errors
|
||||
@@ -48,50 +48,50 @@ export const Errors = {
|
||||
INVALID_EPOCH_KEY: createErrorType(
|
||||
'Invalid epoch key',
|
||||
400,
|
||||
'INVALID_EPOCH_KEY',
|
||||
'INVALID_EPOCH_KEY'
|
||||
),
|
||||
INVALID_PARAMETERS: createErrorType(
|
||||
'Invalid parameters',
|
||||
400,
|
||||
'INVALID_PARAMETERS',
|
||||
'INVALID_PARAMETERS'
|
||||
),
|
||||
UNSPECIFIED_EPOCH_KEY: createErrorType(
|
||||
'Epoch keys must be specified and should be a non-empty string',
|
||||
400,
|
||||
'UNSPECIFIED_EPOCH_KEY',
|
||||
'UNSPECIFIED_EPOCH_KEY'
|
||||
),
|
||||
WRONG_EPOCH_KEY_NUMBER: createErrorType(
|
||||
'Wrong number of epoch keys',
|
||||
400,
|
||||
'WRONG_EPOCH_KEY_NUMBER',
|
||||
'WRONG_EPOCH_KEY_NUMBER'
|
||||
),
|
||||
INVALID_ATTESTER_ID: createErrorType(
|
||||
'Wrong attesterId',
|
||||
400,
|
||||
'INVALID_ATTESTER_ID',
|
||||
'INVALID_ATTESTER_ID'
|
||||
),
|
||||
INVALID_PROOF: createErrorType('Invalid proof', 400, 'INVALID_PROOF'),
|
||||
INVALID_STATE_TREE: createErrorType(
|
||||
'Invalid state tree',
|
||||
400,
|
||||
'INVALID_STATE_TREE',
|
||||
'INVALID_STATE_TREE'
|
||||
),
|
||||
INVALID_PUBLIC_SIGNAL: createErrorType(
|
||||
'Invalid public signal',
|
||||
400,
|
||||
'INVALID_PUBLIC_SIGNAL',
|
||||
'INVALID_PUBLIC_SIGNAL'
|
||||
),
|
||||
|
||||
// Sorting related errors
|
||||
INVALID_SORT_KEY: createErrorType(
|
||||
'sortKey must be "publishedAt" | "voteSum"',
|
||||
400,
|
||||
'INVALID_SORT_KEY',
|
||||
'INVALID_SORT_KEY'
|
||||
),
|
||||
INVALID_DIRECTION: createErrorType(
|
||||
'direction must be "asc" | "desc"',
|
||||
400,
|
||||
'INVALID_DIRECTION',
|
||||
'INVALID_DIRECTION'
|
||||
),
|
||||
|
||||
// General fetching errors
|
||||
@@ -102,51 +102,51 @@ export const Errors = {
|
||||
POST_NOT_EXIST: createErrorType(
|
||||
'Post does not exist',
|
||||
400,
|
||||
'POST_NOT_EXIST',
|
||||
'POST_NOT_EXIST'
|
||||
),
|
||||
POST_REPORTED: createErrorType(
|
||||
'Post has been reported',
|
||||
400,
|
||||
'POST_REPORTED',
|
||||
'POST_REPORTED'
|
||||
),
|
||||
|
||||
// Vote related errors
|
||||
INVALID_VOTE_ACTION: createErrorType(
|
||||
'Invalid vote action',
|
||||
400,
|
||||
'INVALID_VOTE_ACTION',
|
||||
'INVALID_VOTE_ACTION'
|
||||
),
|
||||
INVALID_PAGE: createErrorType(
|
||||
'Invalid page: page is undefined',
|
||||
400,
|
||||
'INVALID_PAGE',
|
||||
'INVALID_PAGE'
|
||||
),
|
||||
EMPTY_POST: createErrorType(
|
||||
'Could not have empty content',
|
||||
400,
|
||||
'EMPTY_POST',
|
||||
'EMPTY_POST'
|
||||
),
|
||||
|
||||
// Comment related errors
|
||||
INVALID_COMMENT_ID: createErrorType(
|
||||
'Invalid commentId',
|
||||
400,
|
||||
'INVALID_COMMENT_ID',
|
||||
'INVALID_COMMENT_ID'
|
||||
),
|
||||
COMMENT_NOT_EXIST: createErrorType(
|
||||
'Comment does not exist',
|
||||
400,
|
||||
'COMMENT_NOT_EXIST',
|
||||
'COMMENT_NOT_EXIST'
|
||||
),
|
||||
COMMENT_REPORTED: createErrorType(
|
||||
'Comment has been reported',
|
||||
400,
|
||||
'COMMENT_REPORTED',
|
||||
'COMMENT_REPORTED'
|
||||
),
|
||||
EMPTY_COMMENT: createErrorType(
|
||||
'Could not have empty content',
|
||||
400,
|
||||
'EMPTY_COMMENT',
|
||||
'EMPTY_COMMENT'
|
||||
),
|
||||
|
||||
// Transaction related errors
|
||||
@@ -157,91 +157,91 @@ export const Errors = {
|
||||
REPORT_OBJECT_TYPE_NOT_EXISTS: createErrorType(
|
||||
'Report object type does not exist',
|
||||
400,
|
||||
'REPORT_OBJECT_TYPE_NOT_EXISTS',
|
||||
'REPORT_OBJECT_TYPE_NOT_EXISTS'
|
||||
),
|
||||
INVALID_REPORT_STATUS: createErrorType(
|
||||
'Invalid report status',
|
||||
400,
|
||||
'INVALID_REPORT_STATUS',
|
||||
'INVALID_REPORT_STATUS'
|
||||
),
|
||||
INVALID_REPORT_NULLIFIER: createErrorType(
|
||||
'Invalid report nullifier',
|
||||
400,
|
||||
'INVALID_REPORT_NULLIFIER',
|
||||
'INVALID_REPORT_NULLIFIER'
|
||||
),
|
||||
USER_ALREADY_VOTED: createErrorType(
|
||||
'User has already voted',
|
||||
400,
|
||||
'USER_ALREADY_VOTED',
|
||||
'USER_ALREADY_VOTED'
|
||||
),
|
||||
INVALID_ADJUDICATE_VALUE: createErrorType(
|
||||
'Invalid adjudicate value',
|
||||
400,
|
||||
'INVALID_ADJUDICATE_VALUE',
|
||||
'INVALID_ADJUDICATE_VALUE'
|
||||
),
|
||||
INVALID_REPORT_ID: createErrorType(
|
||||
'Invalid report id',
|
||||
400,
|
||||
'INVALID_REPORT_ID',
|
||||
'INVALID_REPORT_ID'
|
||||
),
|
||||
REPORT_NOT_EXIST: createErrorType(
|
||||
'Report does not exist',
|
||||
400,
|
||||
'REPORT_NOT_EXIST',
|
||||
'REPORT_NOT_EXIST'
|
||||
),
|
||||
REPORT_VOTING_ENDED: createErrorType(
|
||||
'Report voting has ended',
|
||||
400,
|
||||
'REPORT_VOTING_ENDED',
|
||||
'REPORT_VOTING_ENDED'
|
||||
),
|
||||
INVALID_EPOCH_RANGE: createErrorType(
|
||||
'Invalid epoch range',
|
||||
400,
|
||||
'INVALID_EPOCH_RANGE',
|
||||
'INVALID_EPOCH_RANGE'
|
||||
),
|
||||
NO_POST_HISTORY_FOUND: createErrorType(
|
||||
'No post history found for the given epoch range',
|
||||
404,
|
||||
'NO_POST_HISTORY_FOUND',
|
||||
'NO_POST_HISTORY_FOUND'
|
||||
),
|
||||
NO_COMMENT_HISTORY_FOUND: createErrorType(
|
||||
'No comment history found for the given epoch range',
|
||||
404,
|
||||
'NO_COMMENT_HISTORY_FOUND',
|
||||
'NO_COMMENT_HISTORY_FOUND'
|
||||
),
|
||||
NO_VOTE_HISTORY_FOUND: createErrorType(
|
||||
'No vote history found for the given epoch range',
|
||||
404,
|
||||
'NO_VOTE_HISTORY_FOUND',
|
||||
'NO_VOTE_HISTORY_FOUND'
|
||||
),
|
||||
INVALID_REPUTATION_PROOF: createErrorType(
|
||||
'Invalid reputation proof',
|
||||
400,
|
||||
'INVALID_REPUTATION_PROOF',
|
||||
'INVALID_REPUTATION_PROOF'
|
||||
),
|
||||
NEGATIVE_REPUTATION_USER: createErrorType(
|
||||
'Negative reputation user',
|
||||
400,
|
||||
'NEGATIVE_REPUTATION_USER',
|
||||
'NEGATIVE_REPUTATION_USER'
|
||||
),
|
||||
POSITIVE_REPUTATION_USER: createErrorType(
|
||||
'Positive reputation user',
|
||||
400,
|
||||
'POSITIVE_REPUTATION_USER',
|
||||
'POSITIVE_REPUTATION_USER'
|
||||
),
|
||||
INVALID_AUTHENTICATION: createErrorType(
|
||||
'Invalid authentication',
|
||||
400,
|
||||
'INVALID_AUTHENTICATION',
|
||||
'INVALID_AUTHENTICATION'
|
||||
),
|
||||
USER_ALREADY_CLAIMED: createErrorType(
|
||||
'User has already claimed',
|
||||
400,
|
||||
'USER_ALREADY_CLAIMED',
|
||||
'USER_ALREADY_CLAIMED'
|
||||
),
|
||||
INVALID_REP_USER_TYPE: createErrorType(
|
||||
'Invalid RepUser Type Error',
|
||||
400,
|
||||
'INVALID_REP_USER_TYPE',
|
||||
'INVALID_REP_USER_TYPE'
|
||||
),
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('CheckReputation', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
Circuit.reputation,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const authentication = jsonToBase64({
|
||||
@@ -122,7 +122,7 @@ describe('CheckReputation', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
Circuit.reputation,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const authentication = jsonToBase64({
|
||||
@@ -145,7 +145,7 @@ describe('CheckReputation', function () {
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(400)
|
||||
@@ -174,7 +174,7 @@ describe('CheckReputation', function () {
|
||||
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
Circuit.reputation,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
proof.pi_a[0] = '0'
|
||||
@@ -198,7 +198,7 @@ describe('CheckReputation', function () {
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(400)
|
||||
@@ -221,7 +221,7 @@ describe('CheckReputation', function () {
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(400)
|
||||
|
||||
@@ -28,8 +28,9 @@ describe('POST /api/checkin', function () {
|
||||
before(async function () {
|
||||
snapshot = await ethers.provider.send('evm_snapshot', [])
|
||||
// deploy contracts
|
||||
const { unirep: _unirep, app: _app } =
|
||||
await deployContracts(EPOCH_LENGTH)
|
||||
const { unirep: _unirep, app: _app } = await deployContracts(
|
||||
EPOCH_LENGTH
|
||||
)
|
||||
// start server
|
||||
const {
|
||||
db: _db,
|
||||
@@ -77,13 +78,13 @@ describe('POST /api/checkin', function () {
|
||||
.set('content-type', 'application/json')
|
||||
.set(
|
||||
'authentication',
|
||||
jsonToBase64(stringifyBigInts({ publicSignals, proof })),
|
||||
jsonToBase64(stringifyBigInts({ publicSignals, proof }))
|
||||
)
|
||||
.send(
|
||||
stringifyBigInts({
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then(async (res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -107,13 +108,13 @@ describe('POST /api/checkin', function () {
|
||||
.set('content-type', 'application/json')
|
||||
.set(
|
||||
'authentication',
|
||||
jsonToBase64(stringifyBigInts({ publicSignals, proof })),
|
||||
jsonToBase64(stringifyBigInts({ publicSignals, proof }))
|
||||
)
|
||||
.send(
|
||||
stringifyBigInts({
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then(async (res) => {
|
||||
expect(res).to.have.status(400)
|
||||
|
||||
@@ -84,7 +84,7 @@ describe('COMMENT /comment', function () {
|
||||
const helia = await createHelia()
|
||||
const testContentHash = await IpfsHelper.createIpfsContent(
|
||||
helia,
|
||||
'create comment',
|
||||
'create comment'
|
||||
)
|
||||
let epochKeyProof = await userState.genEpochKeyProof({
|
||||
nonce: 1,
|
||||
@@ -112,7 +112,7 @@ describe('COMMENT /comment', function () {
|
||||
postId: 0,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -159,7 +159,7 @@ describe('COMMENT /comment', function () {
|
||||
|
||||
it('should get correct records from CommentHistory', async function () {
|
||||
const res = await express.get(
|
||||
'/api/comment/commentHistory?from_epoch=0&to_epoch=5',
|
||||
'/api/comment/commentHistory?from_epoch=0&to_epoch=5'
|
||||
)
|
||||
expect(res).to.have.status(200)
|
||||
expect(res.body).to.be.an('array').that.has.lengthOf(1)
|
||||
@@ -184,7 +184,7 @@ describe('COMMENT /comment', function () {
|
||||
postId: 0,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -202,7 +202,7 @@ describe('COMMENT /comment', function () {
|
||||
const tree = await sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId,
|
||||
attesterId
|
||||
)
|
||||
const id = userState.id
|
||||
const data = randomData()
|
||||
@@ -227,7 +227,7 @@ describe('COMMENT /comment', function () {
|
||||
postId: 0,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -255,7 +255,7 @@ describe('COMMENT /comment', function () {
|
||||
postId: 0,
|
||||
publicSignals: epochKeyLiteProof.publicSignals,
|
||||
proof: epochKeyLiteProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -280,7 +280,7 @@ describe('COMMENT /comment', function () {
|
||||
postId: 0,
|
||||
publicSignals: epochKeyLiteProof.publicSignals,
|
||||
proof: epochKeyLiteProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -305,7 +305,7 @@ describe('COMMENT /comment', function () {
|
||||
postId: 0,
|
||||
publicSignals: epochKeyLiteProof.publicSignals,
|
||||
proof: epochKeyLiteProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -325,7 +325,7 @@ describe('COMMENT /comment', function () {
|
||||
|
||||
it('should revert with invalid epoch range', async function () {
|
||||
const res = await express.get(
|
||||
'/api/comment/commentHistory?from_epoch=2&to_epoch=1',
|
||||
'/api/comment/commentHistory?from_epoch=2&to_epoch=1'
|
||||
)
|
||||
expect(res).to.have.status(400)
|
||||
expect(res.body.error).to.equal('Invalid epoch range')
|
||||
@@ -333,11 +333,11 @@ describe('COMMENT /comment', function () {
|
||||
|
||||
it('should return 404 when no comments found in the given epoch range', async function () {
|
||||
const res = await express.get(
|
||||
'/api/comment/commentHistory?from_epoch=100&to_epoch=101',
|
||||
'/api/comment/commentHistory?from_epoch=100&to_epoch=101'
|
||||
)
|
||||
expect(res).to.have.status(404)
|
||||
expect(res.body.error).to.equal(
|
||||
'No comment history found for the given epoch range',
|
||||
'No comment history found for the given epoch range'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('GET /api/config', function () {
|
||||
|
||||
const expectedEpochLength =
|
||||
await sync.unirepContract.attesterEpochLength(
|
||||
BigInt(app.address).toString(),
|
||||
BigInt(app.address).toString()
|
||||
)
|
||||
expect(res.body.EPOCH_LENGTH).to.equal(expectedEpochLength)
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ export const startServer = async (unirep: any, unirepApp: any) => {
|
||||
provider: provider,
|
||||
unirepAddress: unirep.address,
|
||||
},
|
||||
unirepApp,
|
||||
unirepApp
|
||||
)
|
||||
synchronizer.resetDatabase()
|
||||
|
||||
@@ -99,7 +99,7 @@ export const stopServer = async (
|
||||
testName: string,
|
||||
snapshot: any,
|
||||
sync: Synchronizer,
|
||||
server: ChaiHttp.Agent,
|
||||
server: ChaiHttp.Agent
|
||||
) => {
|
||||
console.log(`server ${testName} is shutting down`)
|
||||
sync.stop()
|
||||
|
||||
@@ -156,7 +156,7 @@ describe('LOGIN /login', function () {
|
||||
hashUserId: user.hashUserId,
|
||||
token: user.token,
|
||||
fromServer: true,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -181,7 +181,7 @@ describe('LOGIN /login', function () {
|
||||
hashUserId: user.hashUserId,
|
||||
token: user.token,
|
||||
fromServer: false,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res.body.status).to.equal('success')
|
||||
@@ -209,8 +209,8 @@ describe('LOGIN /login', function () {
|
||||
proof,
|
||||
user.hashUserId,
|
||||
true,
|
||||
this.synchronizer,
|
||||
),
|
||||
this.synchronizer
|
||||
)
|
||||
).to.be.rejectedWith(Error)
|
||||
})
|
||||
|
||||
@@ -241,7 +241,7 @@ describe('LOGIN /login', function () {
|
||||
hashUserId: user.hashUserId,
|
||||
token: user.token,
|
||||
fromServer: true,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -266,7 +266,7 @@ describe('LOGIN /login', function () {
|
||||
hashUserId: user.hashUserId,
|
||||
token: user.token,
|
||||
fromServer: true,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res.body.status).to.equal('success')
|
||||
@@ -296,7 +296,7 @@ describe('LOGIN /login', function () {
|
||||
hashUserId: user.hashUserId,
|
||||
token: user.token,
|
||||
fromServer: true,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -308,7 +308,7 @@ describe('LOGIN /login', function () {
|
||||
const registeredUser = await userService.getLoginUser(
|
||||
db,
|
||||
userId,
|
||||
'access-token',
|
||||
'access-token'
|
||||
)
|
||||
expect(registeredUser.status).to.equal(UserRegisterStatus.REGISTERER)
|
||||
})
|
||||
@@ -318,10 +318,10 @@ describe('LOGIN /login', function () {
|
||||
const registeredUser = await userService.getLoginUser(
|
||||
db,
|
||||
userId,
|
||||
'access-token',
|
||||
'access-token'
|
||||
)
|
||||
expect(registeredUser.status).to.equal(
|
||||
UserRegisterStatus.REGISTERER_SERVER,
|
||||
UserRegisterStatus.REGISTERER_SERVER
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -329,7 +329,7 @@ describe('LOGIN /login', function () {
|
||||
function prepareUserLoginTwitterApiMock(
|
||||
userId: string,
|
||||
code: string,
|
||||
accessToken: string,
|
||||
accessToken: string
|
||||
) {
|
||||
nock(TWITTER_API, { encodedQueryParams: true })
|
||||
.post('/2/oauth2/token')
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('My Account Page', function () {
|
||||
|
||||
it('should fetch posts', async function () {
|
||||
const res = await express.get(
|
||||
`/api/my-account/posts?epks=${postEpochKey}`,
|
||||
`/api/my-account/posts?epks=${postEpochKey}`
|
||||
)
|
||||
|
||||
expect(res.body.length).equal(1)
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('POST /post', function () {
|
||||
const helia = await createHelia()
|
||||
const testContentHash = await IpfsHelper.createIpfsContent(
|
||||
helia,
|
||||
testContent,
|
||||
testContent
|
||||
)
|
||||
const epochKeyProof = await userState.genEpochKeyProof({
|
||||
nonce: 0,
|
||||
@@ -90,7 +90,7 @@ describe('POST /post', function () {
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -166,7 +166,7 @@ describe('POST /post', function () {
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -185,7 +185,7 @@ describe('POST /post', function () {
|
||||
const tree = await sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId,
|
||||
attesterId
|
||||
)
|
||||
const id = userState.id
|
||||
const data = randomData()
|
||||
@@ -209,7 +209,7 @@ describe('POST /post', function () {
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -248,7 +248,7 @@ describe('POST /post', function () {
|
||||
expect(prevPost.sorting_score).gte(nextPost.sorting_score)
|
||||
if (prevPost.sorting_score == nextPost.sorting_score) {
|
||||
expect(BigInt(prevPost.publishedAt)).gte(
|
||||
BigInt(nextPost.publishedAt),
|
||||
BigInt(nextPost.publishedAt)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -262,14 +262,14 @@ describe('POST /post', function () {
|
||||
|
||||
if (prevPost.daily_upvotes == nextPost.daily_upvotes) {
|
||||
expect(prevPost.daily_comments).gte(
|
||||
nextPost.daily_comments,
|
||||
nextPost.daily_comments
|
||||
)
|
||||
|
||||
if (
|
||||
prevPost.daily_comments == nextPost.daily_comments
|
||||
) {
|
||||
expect(BigInt(prevPost.publishedAt)).gte(
|
||||
BigInt(nextPost.publishedAt),
|
||||
BigInt(nextPost.publishedAt)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -342,7 +342,7 @@ describe('POST /post', function () {
|
||||
})
|
||||
it('should get correct records from PostHistory', async function () {
|
||||
const res = await express.get(
|
||||
'/api/post/postHistory?from_epoch=0&to_epoch=5',
|
||||
'/api/post/postHistory?from_epoch=0&to_epoch=5'
|
||||
)
|
||||
expect(res).to.have.status(200)
|
||||
expect(res.body).to.be.an('array').that.has.lengthOf(11)
|
||||
@@ -350,7 +350,7 @@ describe('POST /post', function () {
|
||||
|
||||
it('should revert with invalid epoch range', async function () {
|
||||
const res = await express.get(
|
||||
'/api/post/postHistory?from_epoch=2&to_epoch=1',
|
||||
'/api/post/postHistory?from_epoch=2&to_epoch=1'
|
||||
)
|
||||
expect(res).to.have.status(400)
|
||||
expect(res.body.error).to.equal('Invalid epoch range')
|
||||
@@ -358,11 +358,11 @@ describe('POST /post', function () {
|
||||
|
||||
it('should return 404 when no posts found in the given epoch range', async function () {
|
||||
const res = await express.get(
|
||||
'/api/post/postHistory?from_epoch=100&to_epoch=101',
|
||||
'/api/post/postHistory?from_epoch=100&to_epoch=101'
|
||||
)
|
||||
expect(res).to.have.status(404)
|
||||
expect(res.body.error).to.equal(
|
||||
'No post history found for the given epoch range',
|
||||
'No post history found for the given epoch range'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -48,8 +48,9 @@ describe('POST /api/report', function () {
|
||||
this.timeout(600000)
|
||||
snapshot = await ethers.provider.send('evm_snapshot', [])
|
||||
// deploy contracts
|
||||
const { unirep: _unirep, app: _app } =
|
||||
await deployContracts(EPOCH_LENGTH)
|
||||
const { unirep: _unirep, app: _app } = await deployContracts(
|
||||
EPOCH_LENGTH
|
||||
)
|
||||
// start server
|
||||
const {
|
||||
db: _db,
|
||||
@@ -103,7 +104,7 @@ describe('POST /api/report', function () {
|
||||
await provider.waitForTransaction(txHash)
|
||||
await sync.waitForSync()
|
||||
nonce++
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const testContent = 'test content'
|
||||
@@ -121,13 +122,13 @@ describe('POST /api/report', function () {
|
||||
await provider.waitForTransaction(res.txHash)
|
||||
await sync.waitForSync()
|
||||
nonce++
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const resComment = await commentService.fetchSingleComment(
|
||||
'0',
|
||||
db,
|
||||
CommentStatus.ON_CHAIN,
|
||||
CommentStatus.ON_CHAIN
|
||||
)
|
||||
expect(resComment).to.be.exist
|
||||
}
|
||||
@@ -162,7 +163,7 @@ describe('POST /api/report', function () {
|
||||
_reportData: reportData,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then(async (res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -171,12 +172,12 @@ describe('POST /api/report', function () {
|
||||
|
||||
// Verify that the post status is updated and content is filtered
|
||||
const afterReportResponse = await express.get(
|
||||
`/api/post/${postId}?status=${PostStatus.REPORTED}`,
|
||||
`/api/post/${postId}?status=${PostStatus.REPORTED}`
|
||||
)
|
||||
expect(afterReportResponse).to.have.status(200)
|
||||
expect(afterReportResponse.body).to.have.property(
|
||||
'status',
|
||||
PostStatus.REPORTED,
|
||||
PostStatus.REPORTED
|
||||
)
|
||||
|
||||
// Verify that other properties are still present
|
||||
@@ -187,7 +188,7 @@ describe('POST /api/report', function () {
|
||||
const allPostsResponse = await express.get('/api/post')
|
||||
expect(allPostsResponse).to.have.status(200)
|
||||
const reportedPost = allPostsResponse.body.find(
|
||||
(post) => post.postId === postId,
|
||||
(post) => post.postId === postId
|
||||
)
|
||||
expect(reportedPost).to.exist
|
||||
expect(reportedPost).to.have.property('content', 'test content')
|
||||
@@ -222,7 +223,7 @@ describe('POST /api/report', function () {
|
||||
_reportData: reportData,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -256,7 +257,7 @@ describe('POST /api/report', function () {
|
||||
_reportData: reportData,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -267,13 +268,13 @@ describe('POST /api/report', function () {
|
||||
const afterReportComment = await commentService.fetchSingleComment(
|
||||
commentId,
|
||||
db,
|
||||
CommentStatus.REPORTED,
|
||||
CommentStatus.REPORTED
|
||||
)
|
||||
expect(afterReportComment).to.exist
|
||||
expect(afterReportComment).to.not.have.property('content')
|
||||
expect(afterReportComment).to.have.property(
|
||||
'status',
|
||||
CommentStatus.REPORTED,
|
||||
CommentStatus.REPORTED
|
||||
)
|
||||
|
||||
// Verify that other properties are still present
|
||||
@@ -284,17 +285,17 @@ describe('POST /api/report', function () {
|
||||
|
||||
// Optionally, verify that the comment is still accessible but filtered when fetching all comments for a post
|
||||
const allCommentsResponse = await express.get(
|
||||
`/api/comment?postId=${afterReportComment?.postId}`,
|
||||
`/api/comment?postId=${afterReportComment?.postId}`
|
||||
)
|
||||
expect(allCommentsResponse).to.have.status(200)
|
||||
const reportedComment = allCommentsResponse.body.find(
|
||||
(comment) => comment.commentId === commentId,
|
||||
(comment) => comment.commentId === commentId
|
||||
)
|
||||
expect(reportedComment).to.exist
|
||||
expect(reportedComment).to.not.have.property('content')
|
||||
expect(reportedComment).to.have.property(
|
||||
'status',
|
||||
CommentStatus.REPORTED,
|
||||
CommentStatus.REPORTED
|
||||
)
|
||||
})
|
||||
|
||||
@@ -323,7 +324,7 @@ describe('POST /api/report', function () {
|
||||
_reportData: reportData,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -356,7 +357,7 @@ describe('POST /api/report', function () {
|
||||
_reportData: reportData,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -371,13 +372,13 @@ describe('POST /api/report', function () {
|
||||
})
|
||||
|
||||
epochKeyLitePublicSignals = JSON.stringify(
|
||||
stringifyBigInts(publicSignals),
|
||||
stringifyBigInts(publicSignals)
|
||||
)
|
||||
epochKeyLiteProof = JSON.stringify(stringifyBigInts(proof))
|
||||
|
||||
await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -392,7 +393,7 @@ describe('POST /api/report', function () {
|
||||
|
||||
const reports = await express
|
||||
.get(
|
||||
`/api/report?status=0&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=0&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -421,7 +422,7 @@ describe('POST /api/report', function () {
|
||||
const wrongStatus = 6
|
||||
await express
|
||||
.get(
|
||||
`/api/report?status=${wrongStatus}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${wrongStatus}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -437,7 +438,7 @@ describe('POST /api/report', function () {
|
||||
it('should fail with invalid public signals or proof', async function () {
|
||||
await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.VOTING}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.VOTING}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -446,7 +447,7 @@ describe('POST /api/report', function () {
|
||||
|
||||
await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}`,
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -461,8 +462,8 @@ describe('POST /api/report', function () {
|
||||
`/api/report?status=${
|
||||
ReportStatus.VOTING
|
||||
}&publicSignals=${epochKeyLitePublicSignals}&proof=${JSON.stringify(
|
||||
wrongProof,
|
||||
)}`,
|
||||
wrongProof
|
||||
)}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -491,7 +492,7 @@ describe('POST /api/report', function () {
|
||||
|
||||
const votingReports = await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -501,14 +502,14 @@ describe('POST /api/report', function () {
|
||||
// filter out the report whose objectId is '0' and type is POST
|
||||
const filteredReports = votingReports.filter(
|
||||
(report: any) =>
|
||||
report.objectId !== '0' && report.type === ReportType.POST,
|
||||
report.objectId !== '0' && report.type === ReportType.POST
|
||||
)
|
||||
|
||||
expect(filteredReports.length).equal(0)
|
||||
|
||||
const waitingForTxReports = await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.WAITING_FOR_TRANSACTION}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.WAITING_FOR_TRANSACTION}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => res.body)
|
||||
|
||||
@@ -526,7 +527,7 @@ describe('POST /api/report', function () {
|
||||
// nobody vote on reports[1], it can be fetched on next epoch
|
||||
const reports = await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -562,7 +563,7 @@ describe('POST /api/report', function () {
|
||||
|
||||
const reports = await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.WAITING_FOR_TRANSACTION}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.WAITING_FOR_TRANSACTION}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -597,7 +598,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: report.reportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const authentication = await genAuthentication(userState)
|
||||
@@ -611,7 +612,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.AGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201)
|
||||
@@ -651,7 +652,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: report.reportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const authentication = await genAuthentication(userState)
|
||||
@@ -665,7 +666,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.DISAGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201)
|
||||
@@ -678,7 +679,7 @@ describe('POST /api/report', function () {
|
||||
expect(res?.adjudicateCount).equal(2)
|
||||
const adjudicator = res?.adjudicatorsNullifier![1]!
|
||||
expect(adjudicator.adjudicateValue).equal(
|
||||
AdjudicateValue.DISAGREE,
|
||||
AdjudicateValue.DISAGREE
|
||||
)
|
||||
expect(adjudicator.nullifier).to.be.equal(publicSignals[0])
|
||||
})
|
||||
@@ -707,7 +708,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: report.reportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
publicSignals[0] = '0'
|
||||
@@ -723,7 +724,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.AGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -747,7 +748,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: notExistReportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const authentication = await genAuthentication(userState)
|
||||
@@ -761,7 +762,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.AGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -792,7 +793,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: report.reportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const authentication = await genAuthentication(userState)
|
||||
@@ -806,7 +807,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: wrongAdjucateValue,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -834,7 +835,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: report.reportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const authentication = await genAuthentication(userState)
|
||||
@@ -848,7 +849,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.AGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -866,7 +867,7 @@ describe('POST /api/report', function () {
|
||||
|
||||
const nullifier = genReportNullifier(
|
||||
users[2].id,
|
||||
watingForTxReport.reportId,
|
||||
watingForTxReport.reportId
|
||||
)
|
||||
const toEpoch = await userStateTransition(userState, {
|
||||
express,
|
||||
@@ -880,7 +881,7 @@ describe('POST /api/report', function () {
|
||||
chainId,
|
||||
toEpoch,
|
||||
reportId: watingForTxReport.reportId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const authentication = await genAuthentication(userState)
|
||||
@@ -894,7 +895,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.AGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -922,7 +923,7 @@ describe('POST /api/report', function () {
|
||||
adjudicateValue: AdjudicateValue.AGREE,
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(400)
|
||||
@@ -961,14 +962,14 @@ describe('POST /api/report', function () {
|
||||
|
||||
const report = await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.WAITING_FOR_TRANSACTION}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.WAITING_FOR_TRANSACTION}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
const reports = res.body
|
||||
expect(reports.length).to.be.equal(1)
|
||||
expect(reports[0].status).to.be.equal(
|
||||
ReportStatus.WAITING_FOR_TRANSACTION,
|
||||
ReportStatus.WAITING_FOR_TRANSACTION
|
||||
)
|
||||
return reports[0]
|
||||
})
|
||||
@@ -1017,7 +1018,7 @@ describe('POST /api/report', function () {
|
||||
|
||||
const report = await express
|
||||
.get(
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`,
|
||||
`/api/report?status=${ReportStatus.VOTING}&publicSignals=${epochKeyLitePublicSignals}&proof=${epochKeyLiteProof}`
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
@@ -1039,32 +1040,32 @@ describe('POST /api/report', function () {
|
||||
.then((res) => res.body)
|
||||
expect(reportCategories.length).equal(
|
||||
Object.keys(ReportCategory).filter((category) =>
|
||||
isNaN(Number(category)),
|
||||
).length,
|
||||
isNaN(Number(category))
|
||||
).length
|
||||
)
|
||||
expect(reportCategories[0].number).equal(ReportCategory.ATTACK)
|
||||
expect(reportCategories[0].description).to.be.equal(
|
||||
'對使用者、特定個人、組織或群體發表中傷、歧視、挑釁、羞辱、謾罵、不雅字詞或人身攻擊等言論',
|
||||
'對使用者、特定個人、組織或群體發表中傷、歧視、挑釁、羞辱、謾罵、不雅字詞或人身攻擊等言論'
|
||||
)
|
||||
expect(reportCategories[1].number).equal(ReportCategory.SPAM)
|
||||
expect(reportCategories[1].description).to.be.equal(
|
||||
'張貼商業廣告內容與連結、邀請碼或內含個人代碼的邀請連結等',
|
||||
'張貼商業廣告內容與連結、邀請碼或內含個人代碼的邀請連結等'
|
||||
)
|
||||
expect(reportCategories[2].number).equal(ReportCategory.R18)
|
||||
expect(reportCategories[2].description).to.be.equal(
|
||||
'張貼色情裸露、性暗示意味濃厚的內容,惟內容具教育性者不在此限',
|
||||
'張貼色情裸露、性暗示意味濃厚的內容,惟內容具教育性者不在此限'
|
||||
)
|
||||
expect(reportCategories[3].number).equal(ReportCategory.VIOLATION)
|
||||
expect(reportCategories[3].description).to.be.equal(
|
||||
'違反政府法令之情事',
|
||||
'違反政府法令之情事'
|
||||
)
|
||||
expect(reportCategories[4].number).equal(ReportCategory.DUPLICATE)
|
||||
expect(reportCategories[4].description).to.be.equal(
|
||||
'重複張貼他人已發表過且完全相同的內容',
|
||||
'重複張貼他人已發表過且完全相同的內容'
|
||||
)
|
||||
expect(reportCategories[5].number).equal(ReportCategory.MEANINGLESS)
|
||||
expect(reportCategories[5].description).to.be.equal(
|
||||
'文章內容空泛或明顯無意義內容',
|
||||
'文章內容空泛或明顯無意義內容'
|
||||
)
|
||||
expect(reportCategories[6].number).equal(ReportCategory.OTHER)
|
||||
expect(reportCategories[6].description).to.be.equal('其他')
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('Reputation', () => {
|
||||
await insertReputationHistory(db)
|
||||
|
||||
const res = await express.get(
|
||||
`/api/reputation/history?from_epoch=2&to_epoch=5`,
|
||||
`/api/reputation/history?from_epoch=2&to_epoch=5`
|
||||
)
|
||||
const reputations = res.body
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('Reputation Claim', function () {
|
||||
const upsertAdjudicatorsNullifier = (
|
||||
nullifier: string,
|
||||
adjudicateValue: AdjudicateValue,
|
||||
report: ReportHistory,
|
||||
report: ReportHistory
|
||||
): Adjudicator[] => {
|
||||
const newAdjudicator = {
|
||||
nullifier: nullifier,
|
||||
@@ -93,7 +93,7 @@ describe('Reputation Claim', function () {
|
||||
db: DB,
|
||||
epoch: number,
|
||||
nullifier: string,
|
||||
status: ReportStatus,
|
||||
status: ReportStatus
|
||||
) {
|
||||
const reports = await db.findMany('ReportHistory', {
|
||||
where: {
|
||||
@@ -104,8 +104,8 @@ describe('Reputation Claim', function () {
|
||||
|
||||
return reports.find((report) =>
|
||||
report.adjudicatorsNullifier.some(
|
||||
(adj) => adj.nullifier === nullifier,
|
||||
),
|
||||
(adj) => adj.nullifier === nullifier
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ describe('Reputation Claim', function () {
|
||||
const adjudicatorsNullifier = upsertAdjudicatorsNullifier(
|
||||
nullifier.toString(),
|
||||
adjudicateValue,
|
||||
report,
|
||||
report
|
||||
)
|
||||
const adjudicateCount = (report.adjudicateCount ?? 0) + 1
|
||||
await db.update('ReportHistory', {
|
||||
@@ -261,7 +261,7 @@ describe('Reputation Claim', function () {
|
||||
const adjudicatorsNullifier2 = upsertAdjudicatorsNullifier(
|
||||
nullifier2.toString(),
|
||||
adjudicateValue2,
|
||||
report,
|
||||
report
|
||||
)
|
||||
await db.update('ReportHistory', {
|
||||
where: {
|
||||
@@ -311,7 +311,7 @@ describe('Reputation Claim', function () {
|
||||
const adjudicatorsNullifierFailed1 = upsertAdjudicatorsNullifier(
|
||||
nullifierFailed1.toString(),
|
||||
adjudicateValueFailed1,
|
||||
reportFailed,
|
||||
reportFailed
|
||||
)
|
||||
const adjudicateCountFailed1 = (reportFailed.adjudicateCount ?? 0) + 1
|
||||
await db.update('ReportHistory', {
|
||||
@@ -331,7 +331,7 @@ describe('Reputation Claim', function () {
|
||||
const adjudicatorsNullifierFailed2 = upsertAdjudicatorsNullifier(
|
||||
nullifierFailed2.toString(),
|
||||
adjudicateValueFailed2,
|
||||
reportFailed,
|
||||
reportFailed
|
||||
)
|
||||
await db.update('ReportHistory', {
|
||||
where: {
|
||||
@@ -371,12 +371,12 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NonNullifierProof,
|
||||
reportNonNullifierCircuitInput,
|
||||
reportNonNullifierCircuitInput
|
||||
)
|
||||
|
||||
const reportNullifierProof = new ReportNonNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -391,7 +391,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.REPORTER,
|
||||
}),
|
||||
})
|
||||
)
|
||||
expect(res).to.have.status(200)
|
||||
const message = res.body.message
|
||||
@@ -425,7 +425,7 @@ describe('Reputation Claim', function () {
|
||||
expect(reputationHistory).to.not.be.null
|
||||
expect(reputationHistory.epoch).to.equal(currentEpoch)
|
||||
expect(reputationHistory.epochKey).to.equal(
|
||||
reportNullifierProof.currentEpochKey.toString(),
|
||||
reportNullifierProof.currentEpochKey.toString()
|
||||
)
|
||||
expect(reputationHistory.score).to.equal(RepChangeType.REPORTER_REP)
|
||||
expect(reputationHistory.type).to.equal(ReputationType.REPORT_SUCCESS)
|
||||
@@ -451,12 +451,12 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NonNullifierProof,
|
||||
reportNonNullifierCircuitInput,
|
||||
reportNonNullifierCircuitInput
|
||||
)
|
||||
|
||||
const reportNullifierProof = new ReportNonNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -471,7 +471,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.REPORTER,
|
||||
}),
|
||||
})
|
||||
)
|
||||
expect(res).to.have.status(200)
|
||||
console.log('res a: ', res.body)
|
||||
@@ -506,10 +506,10 @@ describe('Reputation Claim', function () {
|
||||
expect(reputationHistory).to.not.be.null
|
||||
expect(reputationHistory.epoch).to.equal(currentEpoch)
|
||||
expect(reputationHistory.epochKey).to.equal(
|
||||
reportNullifierProof.currentEpochKey.toString(),
|
||||
reportNullifierProof.currentEpochKey.toString()
|
||||
)
|
||||
expect(reputationHistory.score).to.equal(
|
||||
RepChangeType.FAILED_REPORTER_REP,
|
||||
RepChangeType.FAILED_REPORTER_REP
|
||||
)
|
||||
expect(reputationHistory.type).to.equal(ReputationType.REPORT_FAILURE)
|
||||
expect(reputationHistory.reportId).to.equal(reportId2)
|
||||
@@ -535,12 +535,12 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NonNullifierProof,
|
||||
reportNonNullifierCircuitInput,
|
||||
reportNonNullifierCircuitInput
|
||||
)
|
||||
|
||||
const reportNonNullifierProof = new ReportNonNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -555,7 +555,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.RESPONDENT,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(200)
|
||||
@@ -590,7 +590,7 @@ describe('Reputation Claim', function () {
|
||||
expect(reputationHistory).to.not.be.null
|
||||
expect(reputationHistory.epoch).to.equal(currentEpoch)
|
||||
expect(reputationHistory.epochKey).to.equal(
|
||||
reportNonNullifierProof.currentEpochKey.toString(),
|
||||
reportNonNullifierProof.currentEpochKey.toString()
|
||||
)
|
||||
expect(reputationHistory.score).to.equal(RepChangeType.RESPONDENT_REP)
|
||||
expect(reputationHistory.type).to.equal(ReputationType.BE_REPORTED)
|
||||
@@ -618,12 +618,12 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NullifierProof,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const reportNullifierProof = new ReportNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -638,7 +638,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.ADJUDICATOR,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(200)
|
||||
@@ -673,7 +673,7 @@ describe('Reputation Claim', function () {
|
||||
expect(reputationHistory).to.not.be.null
|
||||
expect(reputationHistory.epoch).to.equal(currentEpoch)
|
||||
expect(reputationHistory.epochKey).to.equal(
|
||||
reportNullifierProof.currentEpochKey.toString(),
|
||||
reportNullifierProof.currentEpochKey.toString()
|
||||
)
|
||||
expect(reputationHistory.score).to.equal(RepChangeType.ADJUDICATOR_REP)
|
||||
expect(reputationHistory.type).to.equal(ReputationType.ADJUDICATE)
|
||||
@@ -699,7 +699,7 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NonNullifierProof,
|
||||
reportNonNullifierCircuitInput,
|
||||
reportNonNullifierCircuitInput
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -714,7 +714,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.REPORTER,
|
||||
}),
|
||||
})
|
||||
)
|
||||
expect(res).to.have.status(400)
|
||||
expect(res.body.error).to.include('User has already claimed')
|
||||
@@ -740,7 +740,7 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NullifierProof,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -756,7 +756,7 @@ describe('Reputation Claim', function () {
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.ADJUDICATOR,
|
||||
nullifier1: reportNullifier.toString(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(400)
|
||||
@@ -783,7 +783,7 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NonNullifierProof,
|
||||
reportNonNullifierCircuitInput,
|
||||
reportNonNullifierCircuitInput
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -798,7 +798,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.RESPONDENT,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(400)
|
||||
@@ -824,12 +824,12 @@ describe('Reputation Claim', function () {
|
||||
|
||||
const { publicSignals, proof } = await genProofAndVerify(
|
||||
NullifierProof,
|
||||
reportNullifierCircuitInputs,
|
||||
reportNullifierCircuitInputs
|
||||
)
|
||||
|
||||
const reportNullifierProof = new ReportNullifierProof(
|
||||
publicSignals,
|
||||
proof,
|
||||
proof
|
||||
)
|
||||
|
||||
usedPublicSig = publicSignals
|
||||
@@ -844,7 +844,7 @@ describe('Reputation Claim', function () {
|
||||
claimSignals: usedPublicSig,
|
||||
claimProof: usedProof,
|
||||
repUserType: RepUserType.ADJUDICATOR,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(200)
|
||||
@@ -872,7 +872,7 @@ describe('Reputation Claim', function () {
|
||||
expect(reputationHistory).to.not.be.null
|
||||
expect(reputationHistory.epoch).to.equal(currentEpoch)
|
||||
expect(reputationHistory.epochKey).to.equal(
|
||||
reportNullifierProof.currentEpochKey.toString(),
|
||||
reportNullifierProof.currentEpochKey.toString()
|
||||
)
|
||||
expect(reputationHistory.score).to.equal(RepChangeType.ADJUDICATOR_REP)
|
||||
expect(reputationHistory.type).to.equal(ReputationType.ADJUDICATE)
|
||||
|
||||
@@ -80,7 +80,7 @@ describe('Synchronize Post Test', function () {
|
||||
const helia = await createHelia()
|
||||
const contentHash = await IpfsHelper.createIpfsContent(
|
||||
helia,
|
||||
'test content',
|
||||
'test content'
|
||||
)
|
||||
|
||||
await provider.waitForTransaction(txHash)
|
||||
@@ -198,7 +198,7 @@ describe('Synchronize Comment Test', function () {
|
||||
})
|
||||
|
||||
await expect(
|
||||
app.leaveComment(publicSignals, proof, 0, commentContent),
|
||||
app.leaveComment(publicSignals, proof, 0, commentContent)
|
||||
)
|
||||
.to.emit(app, 'Comment')
|
||||
.withArgs(publicSignals[0], 0, 0, 0, commentContent)
|
||||
@@ -233,7 +233,7 @@ describe('Synchronize Comment Test', function () {
|
||||
await expect(
|
||||
app.editComment(publicSignals, proof, 0, 0, newContent, {
|
||||
gasLimit: 5000000,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.to.emit(app, 'UpdatedComment')
|
||||
.withArgs(publicSignals[1], 0, 0, 0, newContent)
|
||||
|
||||
@@ -7,7 +7,7 @@ export async function comment(
|
||||
userState: UserState,
|
||||
authentication: string,
|
||||
postId: string,
|
||||
nonce: number,
|
||||
nonce: number
|
||||
): Promise<any> {
|
||||
const testContent = 'test content'
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function comment(
|
||||
postId: postId,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200)
|
||||
|
||||
@@ -10,6 +10,6 @@ export const genAuthentication = async (userState: UserState) => {
|
||||
stringifyBigInts({
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export const randomData = () => [
|
||||
.map(
|
||||
() =>
|
||||
poseidon1([Math.floor(Math.random() * 199191919)]) %
|
||||
BigInt(2) ** BigInt(253),
|
||||
BigInt(2) ** BigInt(253)
|
||||
),
|
||||
]
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function genEpochKeyProof(config: {
|
||||
{
|
||||
data: [],
|
||||
},
|
||||
config,
|
||||
config
|
||||
)
|
||||
const data = [..._data, ...Array(FIELD_COUNT - _data.length).fill(0)]
|
||||
const _proof = tree.createProof(leafIndex)
|
||||
@@ -70,13 +70,13 @@ export async function genEpochKeyProof(config: {
|
||||
}
|
||||
const r = await prover.genProofAndPublicSignals(
|
||||
Circuit.epochKey,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
const { publicSignals, proof } = new EpochKeyProof(
|
||||
r.publicSignals,
|
||||
r.proof,
|
||||
prover,
|
||||
prover
|
||||
)
|
||||
|
||||
return { publicSignals, proof }
|
||||
@@ -125,7 +125,7 @@ export const genReputationCircuitInput = (config: {
|
||||
graffiti: 0,
|
||||
startBalance: [],
|
||||
},
|
||||
config,
|
||||
config
|
||||
)
|
||||
|
||||
const startBalance = [
|
||||
@@ -139,7 +139,7 @@ export const genReputationCircuitInput = (config: {
|
||||
BigInt(attesterId),
|
||||
epoch,
|
||||
startBalance as any,
|
||||
chainId ?? 0,
|
||||
chainId ?? 0
|
||||
)
|
||||
stateTree.insert(hashedLeaf)
|
||||
const stateTreeProof = stateTree.createProof(0) // if there is only one GST leaf, the index is 0
|
||||
@@ -168,18 +168,18 @@ export const genReputationCircuitInput = (config: {
|
||||
|
||||
export async function genProofAndVerify(
|
||||
circuit: string | Circuit,
|
||||
circuitInputs: any,
|
||||
circuitInputs: any
|
||||
) {
|
||||
const startTime = new Date().getTime()
|
||||
const { proof, publicSignals } = await Prover.genProofAndPublicSignals(
|
||||
circuit,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
const endTime = new Date().getTime()
|
||||
console.log(
|
||||
`Gen Proof time: ${endTime - startTime} ms (${Math.floor(
|
||||
(endTime - startTime) / 1000,
|
||||
)} s)`,
|
||||
(endTime - startTime) / 1000
|
||||
)} s)`
|
||||
)
|
||||
const isValid = await Prover.verifyProof(circuit, publicSignals, proof)
|
||||
return { isValid, proof, publicSignals }
|
||||
@@ -198,7 +198,7 @@ export async function genProveReputationProof(type, config) {
|
||||
})
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
Circuit.reputation,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
return {
|
||||
@@ -217,7 +217,7 @@ export async function genProveReputationProof(type, config) {
|
||||
})
|
||||
const { isValid, publicSignals, proof } = await genProofAndVerify(
|
||||
Circuit.reputation,
|
||||
circuitInputs,
|
||||
circuitInputs
|
||||
)
|
||||
|
||||
return {
|
||||
@@ -232,8 +232,9 @@ export async function userStateTransition(userState, context) {
|
||||
|
||||
const epoch = await sync.loadCurrentEpoch()
|
||||
const attesterId = sync.attesterId
|
||||
const remainingTime =
|
||||
await context.unirep.attesterEpochRemainingTime(attesterId)
|
||||
const remainingTime = await context.unirep.attesterEpochRemainingTime(
|
||||
attesterId
|
||||
)
|
||||
// epoch transition
|
||||
await ethers.provider.send('evm_increaseTime', [remainingTime])
|
||||
await ethers.provider.send('evm_mine', [])
|
||||
@@ -250,7 +251,7 @@ export async function userStateTransition(userState, context) {
|
||||
stringifyBigInts({
|
||||
publicSignals,
|
||||
proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
return res.body.txHash
|
||||
@@ -271,7 +272,7 @@ export async function genReportIdentityProof(userState, config) {
|
||||
const stateTree = await sync.genStateTree(toEpoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
toEpoch,
|
||||
attesterId,
|
||||
attesterId
|
||||
)
|
||||
const stateTreeProof = stateTree.createProof(leafIndex)
|
||||
|
||||
@@ -290,7 +291,7 @@ export async function genReportIdentityProof(userState, config) {
|
||||
|
||||
const { isValid, proof, publicSignals } = await genProofAndVerify(
|
||||
'reportIdentityProof',
|
||||
stringifyBigInts(circuitInput),
|
||||
stringifyBigInts(circuitInput)
|
||||
)
|
||||
return {
|
||||
proof,
|
||||
|
||||
@@ -6,7 +6,7 @@ export async function post(
|
||||
server: ChaiHttp.Agent,
|
||||
userState: UserState,
|
||||
authentication: string,
|
||||
nonce?: number,
|
||||
nonce?: number
|
||||
): Promise<any> {
|
||||
const testContent = 'test content'
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function post(
|
||||
content: testContent,
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(res).to.have.status(200)
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function airdropReputation(
|
||||
userState: UserState,
|
||||
unirep: Unirep,
|
||||
express: any,
|
||||
provider: any,
|
||||
provider: any
|
||||
): Promise<void> {
|
||||
const epoch = await userState.sync.loadCurrentEpoch()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { genUserState } from './userHelper'
|
||||
|
||||
export async function signUp(
|
||||
user: IdentityObject,
|
||||
context,
|
||||
context
|
||||
): Promise<UserState> {
|
||||
const { app, db, prover, provider, sync } = context
|
||||
const userState = await genUserState(user.id, app, prover)
|
||||
@@ -18,7 +18,7 @@ export async function signUp(
|
||||
proof,
|
||||
user.hashUserId,
|
||||
false,
|
||||
sync,
|
||||
sync
|
||||
)
|
||||
await provider.waitForTransaction(txHash)
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('POST /vote', function () {
|
||||
|
||||
const postResponses = await Promise.all(postPromises)
|
||||
await Promise.all(
|
||||
postResponses.map((txHash) => provider.waitForTransaction(txHash)),
|
||||
postResponses.map((txHash) => provider.waitForTransaction(txHash))
|
||||
)
|
||||
await sync.waitForSync()
|
||||
// get the post ids
|
||||
@@ -113,7 +113,7 @@ describe('POST /vote', function () {
|
||||
publicSignals: epochKeyProof.publicSignals,
|
||||
proof: epochKeyProof.proof,
|
||||
enableEpochValidation: true,
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
upvotePostId,
|
||||
VoteAction.UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(upvoteResponse).to.have.status(201)
|
||||
// check the post is upvoted only
|
||||
@@ -159,7 +159,7 @@ describe('POST /vote', function () {
|
||||
const downvoteResponse = await voteForPost(
|
||||
downvotePostId,
|
||||
VoteAction.DOWNVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(downvoteResponse).to.have.status(201)
|
||||
|
||||
@@ -179,7 +179,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
upvotePostId,
|
||||
VoteAction.UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(upvoteResponse).to.have.status(400)
|
||||
expect(upvoteResponse.body.error).equal('Invalid vote action')
|
||||
@@ -190,7 +190,7 @@ describe('POST /vote', function () {
|
||||
const downvoteResponse = await voteForPost(
|
||||
downvotePostId,
|
||||
VoteAction.DOWNVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(downvoteResponse).to.have.status(400)
|
||||
expect(downvoteResponse.body.error).equal('Invalid vote action')
|
||||
@@ -208,7 +208,7 @@ describe('POST /vote', function () {
|
||||
const downvoteResponse = await voteForPost(
|
||||
upvotePostId,
|
||||
VoteAction.DOWNVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(downvoteResponse).to.have.status(400)
|
||||
expect(downvoteResponse.body.error).equal('Invalid vote action')
|
||||
@@ -219,7 +219,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
downvotePostId,
|
||||
VoteAction.UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
|
||||
expect(upvoteResponse).to.have.status(400)
|
||||
@@ -238,7 +238,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
upvotePostId,
|
||||
VoteAction.CANCEL_UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(upvoteResponse).to.have.status(201)
|
||||
// check the post is neither upvoted nor downvoted
|
||||
@@ -250,7 +250,7 @@ describe('POST /vote', function () {
|
||||
const downvoteResponse = await voteForPost(
|
||||
downvotePostId,
|
||||
VoteAction.CANCEL_DOWNVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(downvoteResponse).to.have.status(201)
|
||||
// check the post is neither upvoted nor downvoted
|
||||
@@ -271,7 +271,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
upvotePostId,
|
||||
VoteAction.CANCEL_UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(upvoteResponse).to.have.status(400)
|
||||
expect(upvoteResponse.body.error).equal('Invalid vote action')
|
||||
@@ -282,7 +282,7 @@ describe('POST /vote', function () {
|
||||
const downvoteResponse = await voteForPost(
|
||||
downvotePostId,
|
||||
VoteAction.CANCEL_DOWNVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(downvoteResponse).to.have.status(400)
|
||||
expect(downvoteResponse.body.error).equal('Invalid vote action')
|
||||
@@ -300,7 +300,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
otherPostId,
|
||||
VoteAction.UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(upvoteResponse).to.have.status(400)
|
||||
expect(upvoteResponse.body.error).equal('Wrong attesterId')
|
||||
@@ -316,7 +316,7 @@ describe('POST /vote', function () {
|
||||
const upvoteResponse = await voteForPost(
|
||||
'invalid',
|
||||
VoteAction.UPVOTE,
|
||||
epochKeyProof,
|
||||
epochKeyProof
|
||||
)
|
||||
expect(upvoteResponse).to.have.status(400)
|
||||
expect(upvoteResponse.body.error).equal('Invalid postId')
|
||||
|
||||
@@ -24,8 +24,8 @@ for (;;) {
|
||||
// deploy a Unirep contract and the attester contract
|
||||
await new Promise((rs, rj) =>
|
||||
exec('yarn contracts deploy', (err) =>
|
||||
err ? rj(err) : rs(console.log('Contract has been deployed')),
|
||||
),
|
||||
err ? rj(err) : rs(console.log('Contract has been deployed'))
|
||||
)
|
||||
)
|
||||
|
||||
// start relay
|
||||
|
||||
Reference in New Issue
Block a user