an SDK class that exposes basic operations, such as get, put, update and remove.
an Admin class that additionally exposes higher authorized operations, such as changing the state, transferring ownership, and changing the mode of operation.
Both these are instantiated the same way:
a signer object that is your account, explained in the next section
a contractTxId to connect to HollowDB SmartWeave contract
a warp object instantiated from WarpFactory
import {SDK, Admin} from'hollowdb';import {WarpFactory} from'warp-contracts';constsigner=/* more info on this later */constwarp=WarpFactory.forMainnet();constsdk=newSDK(signer, contractTxId, warp);constadmin=newAdmin(signer, contractTxId, warp);
SDK
SDK provides the basic CRUD (create, read, update, delete) functionality; we refer to these actions as put, get, update, remove respectively.
// we will explain these shortlyimport {Prover, computeKey} from'hollowdb-prover';constprover=newProver(WASM_PATH,PROVERKEY_PATH,PROTOCOL);constkey=computeKey(yourSecret);// GET is open to everyoneawaitsdk.get(key);// PUT does not require a proofawaitsdk.put(key, value);// UPDATE with a prooflet {proof: updateProof} =awaitprover.prove(keyPreimage, curValue, newValue);awaitsdk.update(key, newValue, updateProof);// UPDATE without a proofawaitsdk.update(key, newValue);// REMOVE with a prooflet {proof: removalProof} =awaitprover.prove(keyPreimage, curValue,null);awaitsdk.remove(key, removalProof);// REMOVE without a proofawaitsdk.remove(key);// read state variablesconst {cachedValue} =awaitsdk.readState();
To learn more about hollowdb-prover, see the following sections:
Admin
The admin has all capabilities of the SDK, and in addition to those, it can alter the contract state!
// update the new owner to be the specified addressawaitadmin.updateOwner(address);// update verification key for a specific circuit// e.g. update the `auth` circuit's verification keyawaitadmin.updateVerificationKey("auth", verificationKey);// update proof requirements for a specific circuit// e.g. disable proof checking for `auth` circuitawaitadmin.updateProofRequirement("auth",false);// update whitelisting requirements for a specific list// e.g. disable whitelist checking for `put` operationsawaitadmin.updateWhitelistRequirement("put",false);// add addresses to a whitelist// e.g. add alice & bob to `put` whitelistawaitadmin.updateWhitelist([aliceAddr, bobAddr],"put","add");// remove addresses from a whitelist// e.g. remove bob from `update` whitelistawaitadmin.updateWhitelist([bobAddr],"update","remove");
This design is made with making HollowDB extendable in mind; that is, we allow for many more types of lists and multiple circuits to be used in HollowDB! We will have more updates in the future that allows extending HollowDB this way.
Admin class has two static utility functions:
Admin.deploy provides an easy way for you to deploy your own contract to Arweave.
Admin.evolve allows you to evolve an existing contract to a new source code.