TestCredential
The TestCredential object abstracts most of the Block Qualified logic away, allowing you to easily interact with the protocol. It incorporates an OpenZeppelin Autotask for a transaction relayer, making it easier to onboard users.
Defining a TestCredential Object
You can define a new TestCredential object with the following syntax:
const testCredential = await TestCredential.init(
credentialId,
{
provider: "provider",
apiKey: process.env.PROVIDER_KEY
},
"network",
openAnswersHashes
)The value for openAnswersHashes needs to be provided for tests that implement an open answers component, as defined for Block Qualified tests
Grading a Solution to a Test
Once initialized, you can use the TestCredential object to grade solutions to the test:
const result = testCredential.gradeSolution({ multipleChoiceAnswers, openAnswers })Where result will be an object containing the following values:
grade: over 100, grade obtained in the test.minimumGrade: over 100, minimum grade needed to pass the test.pass: whether the test was passed or not.nQuestions: number of open answer questions that make up this test.multipleChoiceGrade: grade obtained in the multiple choice component of this test.openAnswerGrade: grade obtained in the open answer component of this test.multipleChoiceWeight: percentage that the multiple choice component contributes towards the final grade.openAnswerResultsarray containing boolean values indicating the result for each open answer question.
Generating and Verifying a Solution Proof
You can generate a test solution proof as described in Block Qualified Proofs by calling:
const proof = await testCredential.generateSolutionProof(identity, { multipleChoiceAnswers, openAnswers })Where the value for identity is a valid Semaphore identity that is then added to a given group, as described in the Block Qualified contracts.
You can then verify this proof by calling:
const proofIsValid = await testCredential.verifySolutionProof(proof)Which will return true or false.
Sending a Solution Transaction
You can use the implemented OpenZeppelin Relayer to send this transaction free of gas.
await testCredential.sendSolutionTransaction(proof)Generating and Verifying a Rating Proof
You can generate a rating proof as described in Rating the Credential Issuer by calling:
const rateProof = await testCredential.generateRateIssuerProof(identity, rating, comment)Where the value for identity is a valid Semaphore identity that must have already gained this test credential.
You can then verify this proof by calling:
const proofIsValid = await testCredential.verifyRateIssuerProof(rateProof)Which will return true or false.
Sending a Rating Transaction
You can use the implemented OpenZeppelin Relayer to send this transaction free of gas.
await testCredential.sendRateIssuerTransaction(rateProof)Last updated