@safe-and-trust/validation-contracts
v1.1.0
Published
Safe and Trust contracts artifacts and validator functions
Downloads
250
Readme
Safe & Trust - Validation Contracts
This package contains contracts artifacts (ABI + types) and validation utils (hash generation, merkle tree proofs) for checking hash existance on the Blockchain.
Alpha release
Package is in alpha stage. Use with caution.
Getting Started
Code example
import {Contract, ethers, JsonRpcProvider} from "ethers";
import {contractsConfiguration, hashManagerAbi, ContractsEnvironment} from "@safe-and-trust/validation-contracts";
import {HashManagerLogicV1} from "@safe-and-trust/validation-contracts/typechain-types/";
function getHashManager(environment: ContractsEnvironment) {
const hmlAddress = contractsConfiguration[environment].HashManagerLogic;
const hmlProvider = contractsConfiguration[environment].HashManagerProvider;
const provider = new JsonRpcProvider(hmlProvider);
return new Contract(
hmlAddress,
hashManagerAbi,
provider
) as never as HashManagerLogicV1;
}
function sanitizeHashToBytes32(hash: string) {
if (ethers.isHexString(hash)) {
return ethers.getBytes(hash);
} else if (hash.length === 64) {
return ethers.getBytes(`0x${hash}`);
} else {
throw Error(`Unable to convert hash to bytes32: ${hash}`);
}
}
async function main(){
const hashManager = getHashManager("development");
// put your hash here
const hash = "963eb3aa7cfed9ed7d0912f15f03aee36b8637af308ebd28ecbeb24630250d74";
const hashB32 = sanitizeHashToBytes32(hash);
const hashExists = await hashManager.hashExists(hashB32);
console.log(`Hash check for ${hash} : ${hashExists}`);
if (hashExists){
console.log("Hash is saved on the Blockchain!");
}
}
main().then().catch(console.error);