1.0.0-alpha.4 • Published 2 months ago

@safe-and-trust/validation-contracts v1.0.0-alpha.4

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
2 months ago

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);
1.0.0-alpha.4

2 months ago

1.0.0-alpha.3

5 months ago

1.0.0-alpha.2

5 months ago

1.0.0-alpha.1

5 months ago