You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Kavach is an encryption SDK that allows you to build your trustless, decentralized and fault-tolerant Applications using distributed key shards with threshold cryptography
Features
Randomized key shard generation
Shard Key support for privateKey and other security keys
minimum amount of key required to recover master key
keyCount
number(optional)
5
number of shades to be generated (Note: must be greater than or equal to threshold)
returns
Name
Type
Description
isShardable
boolean
return true is the key could be sharded
keyShards
keyShard[]
shards
Demo
import{shardKey,recoverKey}from"@lighthouse-web3/kavach";asyncfunctionmain(){// known key customly generated or from ether random wallet privateKey// Note: Not all keys are shardableconstknownKey="554f886019b74852ab679258eb3cddf72f12f84dd6a946f8afc4283e48cc9467";const{ isShardable, keyShards }=awaitshardKey(knownKey);console.log(isShardable);// true//recover keys from shardsconst{ masterKey }=awaitrecoverKey(keyShards);//check if the key recovered was recoveredconsole.log(masterKey===knownKey);//true}main().then(()=>process.exit(0)).catch((error)=>{console.error(error);process.exit(1);});
Add more granular access Conditions based on on-Chain Data, this supports custom EVM contracts, block timestamps and so on.
with support for over 15 Ethereum Virtual Machine (EVM) based networks and based Solana RPC calls
Ethereum
Rinkeby
Polygon
Fantom
FantomTest
AVAX
Fuji
BSC
BSCTest
Optimism
OptimismGoerli
OptimismKovan
Mumbai
FVM
Wallaby
Calibration
Shardeum
Goerli
Hyperspace
BTTC
BTTC_Testnet
Sepolia_PGN
Arbitrum_Sepolia
Sepolia:
BASE_Goerli
Solana
DEVNET
TESTNET
MAINNET
Parameters
Name
Type
Description
address
string
Address of the owner of the key
cid
string
Unique id or file CID
auth_token
string
Signed Message gotten from getAuthMessage /JWT
conditions
Array< Condition >
This Array contains a list of conditions to be tested on chain
aggregator
string
This is a template string that structures how the conditions should be computed
chainType
string
This defaults to EVM and can be set to Solana for Solana conditions
keyShards?
Array<{key:string; index:string}>
This Field is optional, you can use it to set, overWrite or rotate key shards
decryptionType?
string
This value can be set to ACCESS_CONDITIONS to first time shard is added, WARNING: This sets Owner to address zero(0x0000000000000000000000000000)
returns
Name
Type
Description
isSuccess
boolean
return true if successful
error
ErrorValue
Errors
Demo
import{recoverShards,getAuthMessage,saveShards,AuthMessage,accessControl,generate,}from"@lighthouse-web3/kavach";import{ethers}from"ethers";asyncfunctionmain(){letsigner=newethers.Wallet("0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b");letsigner2=newethers.Wallet("0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c99");constcid="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwVM";//save file{constauthMessage: AuthMessage=awaitgetAuthMessage(signer.address);constsignedMessage=awaitsigner.signMessage(authMessage.message);const{ masterKey, keyShards }=awaitgenerate();const{ error, isSuccess }=awaitsaveShards(signer.address,cid,signedMessage,keyShards);console.log(error==null);//true;console.log(isSuccess==true);//true;}// add access control to cid direct shared address{constauthMessage: AuthMessage=awaitgetAuthMessage(signer.address);constsignedMessage=awaitsigner.signMessage(authMessage.message);const{ error, isSuccess }=awaitaccessControl(signer.address,cid,signedMessage,[{id: 3,chain: "Polygon",method: "getBlockNumber",standardContractType: "",returnValueTest: {comparator: ">=",value: "0"},},{id: 2,chain: "Optimism",method: "getBalance",standardContractType: "",returnValueTest: {comparator: ">=",value: "0"},},{id: 1,chain: "FantomTest",method: "balanceOf",standardContractType: "ERC20",contractAddress: "0xF0Bc72fA04aea04d04b1fA80B359Adb566E1c8B1",returnValueTest: {comparator: ">=",value: "0"},parameters: [":userAddress"],},],"([2] and [1]) or [3]");console.log(error==null);console.log(isSuccess==true);}// recover shared from an address that matches the above condition// that is// has a balance equal to or greater than Zero on the Optimism mainnet and has a token balance greater than equal to zero of the token 0xF0Bc72fA04aea04d04b1fA80B359Adb566E1c8B1 on fantom's testnet// or if block height is greater than zero{constauthMessage: AuthMessage=awaitgetAuthMessage(signer2.address);constsignedMessage=awaitsigner2.signMessage(authMessage.message);console.log(signer2.address);//retrieve 3 keysconst{ error, shards }=awaitrecoverShards(signer2.address,cid,signedMessage,3,dynamicData);console.log(error==null);//true;console.log(shards.length===3);// true;}}main().then(()=>process.exit(0)).catch((error)=>{console.error(error);process.exit(1);});
Auth Methods
getAuthMessage( address: string)
Get Consensus Message to Sign
Parameters
Name
Type
Default
Description
address
string
address of the owner of the key
returns
Name
Type
Description
message
string
return consensus message
error
ErrorValue
Errors
import{getAuthMessage,AuthMessage}from"@lighthouse-web3/kavach";import{ethers}from"ethers";asyncfunctionmain(){letsigner=newethers.Wallet("0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b");// get consensus messageconstauthMessage: AuthMessage=awaitgetAuthMessage(signer.address);constsignedMessage=awaitsigner.signMessage(authMessage.message);console.log(typeofauthMessage.message=="string");//true;console.log(authMessage.error==null);//true;}main().then(()=>process.exit(0)).catch((error)=>{console.error(error);process.exit(1);});
import{transferOwnership}from"@lighthouse-web3/kavach";// Example usage of transferOwnership functionasyncfunctionmain(){constcurrentOwner="0x1234567890abcdef";constresourceId="QmXyZAbCdEfGhIjK";constnewOwner="0x9876543210fedcba";constauthPayload="your-authentication-token";const{ result, error }=awaittransferOwnership(currentOwner,resourceId,newOwner,authPayload);if(error){console.error("Error:",error);}else{console.log("Ownership transfer result:",result);}}main().then(()=>process.exit(0)).catch((error)=>{console.error(error);process.exit(1);});