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
constHypercoreEncryption=require('hypercore-encryption')constgetEncryptionKey=async(id)=>{// get key info corresponding to id...return{
id,// encryption scheme
encryptionKey // encryption key}}constencryption=newHypercoreEncryption(getEncryptionKey)constcore=newHypercore(storage,{encryption: encryption.createEncryptionProvider({transform(ctx,entropy,compat){return{block: deriveBlockKey(entropy),hash: deriveHashKey(entropy)}}})})awaitcore.ready()awaitcore.append('encrypt with key')
API
const enc = new HypercoreEncryption(getEncryptionKey)
Instantiate a new encryption provider.
Takes a hook with the signature:
asyncfunctiongetEncryptionKey(id){// if id is passed as -1, the module expects the latest keyreturn{
id,// encryption id
encryptionKey // encryption key}}
{functiontransform(ctx,entropy,compat){// implement custom block key derivation// compat will be passed as true when a compat is expected// block key and hash/blinding key should be distinctreturn{
block,
hash,// not required for compat keys
blinding // only required for compat keys}},functioncompat(ctx,index){// return true or false whether a compat key is expected}}