Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including optional time for isValid in server #780

Merged
merged 11 commits into from
Nov 23, 2023
19 changes: 17 additions & 2 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,24 @@ export class ProsopoServer {
return this.contract
}

public async isVerified(payload: ProcaptchaOutput): Promise<boolean> {
/**
*
* @param payload Info output by procaptcha on completion of the captcha process
* @param maxVerifiedTime Maximum time in milliseconds since the blockNumber
* @returns
*/
public async isVerified(payload: ProcaptchaOutput, maxVerifiedTime?: number): Promise<boolean> {
const { user, dapp, providerUrl, commitmentId, blockNumber } = payload
// first check if the provider was actually chosen at blockNumber
// Check if blockNumber is too old
if (maxVerifiedTime && blockNumber) {
const currentBlockNumber = (await this.getApi().rpc.chain.getBlock()).block.header.number.toNumber()
const blockLength = this.getApi().consts.babe.expectedBlockTime.toNumber()
if ((currentBlockNumber - blockNumber) * blockLength > maxVerifiedTime) {
return false
}
}

// Check if the provider was actually chosen at blockNumber
const contractApi = await this.getContractApi()
const block = (await this.getApi().rpc.chain.getBlockHash(blockNumber)) as BlockHash
const getRandomProviderResponse = await this.getContract().queryAtBlock<RandomProvider>(
Expand Down
Loading