First, let's walk through the workflow for adding historical receipt/tx/storage data to your app via the Brevis TypeScript SDK which offers a convenient way for NodeJS to interact with the prover service and Brevis' system.
Install the Dependency
npminstallbrevis-sdk-typescript
Adding Source Data
Initialize a Proof Request to Your Prover Service
import { ProofRequest, Prover } from'brevis-sdk-typescript';// Assuming you started your prover service on port 33247, this is how you // initialize a client in your NodeJS program to interact with it.constprover=newProver('localhost:33247');constproofReq=newProofRequest();
Add the Data to the Proof Request
Depending on your project, you may want to first query an indexer, such as Dune, an Ethereum node, or your own service, to acquire the raw data (such as transactions) according to your business logic. This part is not handled by the Brevis SDK.
So why can't we just use the indexer data directly on chain?
If you directly post the data from an indexer to your contract without any validity proofs, your users would be trusting the entity who posted this data to behave correctly. Brevis's core role is to replace this trust of data validity on one party with a ZK proof so no one can fabricate data and computation results.
After you acquire the raw data, you add the data to the proofReq. The data you add here is closely tied to how you allocate data slots for your circuit and is available in CircuitInput passed in to your Define function. how to write an application circuit
If you define custom inputs for your circuit, you need to fully assign them here in ProofRequest.
// circuit custom input definitiontypeAppCircuitstruct{// example custom field `MerkleProof` MerkleProof [8]sdk.Bytes32}
// assigning custom input in typescriptproofReq.setCustomInput({// key names match what we defined in AppCircuit MerkleProof: [// type of the field should also match what we define in AppCircuitasBytes32('0x1111111111111111111111111111111111111111111111111111111111111111'),asBytes32('0x2222222222222222222222222222222222222222222222222222222222222222'),// ... ],});
The keys of the custom input object you add in typescript matches what you define in your app circuit. The first letter can also be lower cased, e.g. merkleProof in the above example
Custom Input Types
The types of the custom input you assign in ProofRequest must match what you define in your app circuit. All primitive circuit data types are allowed here through the following functions.