Dyanmic Hypercore encryption provider
const HypercoreEncryption = require('hypercore-encryption')
const encryption = new HypercoreEncryption({
blindingKey,
getBlockKey (id, contexxt) {
// get key info corresponding to id and context...
return {
version, // encryption scheme
padding, // padding byte length
key // block key
}
}
})
const core = new Hypercore(storage, { encryption })
await core.ready()
await core.append('encrypt with key 1')
await encryption.load(99)
await core.append('encrypt with key 99')
Instantiate a new encryption provider. Optionally pass a preopen
promise that resolves to a key id to be loaded initially.
Provide a hooks with the signature:
function getBlockKey (id, context) {
// context provides information about the core, eg:
// context.key
// context.manifest
// id id is passed as -1, the module expects the key to be updated
return {
version, // encryption scheme
padding, // padding byte length
key // block key
}
}
function getBlockKey (context) {
return blindingKey // 32 byte blinding key
}
The number of padding bytes.
Boolean on whether the current scheme allows for seeks.
The version of the currently loaded scheme.
Load the key under id
and set to be the current encryption info.
Encrypt a block in place.
Decrypt a block in place.
Helper to generate namespaced block keys.
Apache-2.0