Hypercore encrypt enables block encryption for Hypercore v10 with authenticated encryption keys.
npm i hypercore-encrypt
const Hypercore = require('hypercore-encrypt')
const feed = new Hypercore('./my-encrypted-dataset', null, {
encryptionKey: key,
valueEncoding: 'json',
skipFirstBlock: false // remove this option if the feed is being used in something like Hyperbee
})
await feed.ready()
feed.append('hello world')
feed.get(0, console.log) // decrypts block 0 and prints hello world
Hypercore-encrypt mimics Hypercore v10's API except an encryption key can be passed into the options to encrypt and decipher blocks.
{
encryptionKey: key, // All blocks will be encrypted and deciphered with this AEAD key
skipFirstBlock: true // Skip encrypting the header block when using this in conjunction with something like Hyperbee
}
// Initializing a new feed without an encryption key will automatically generate a new one
const feed = new Hypercore('./my-encrypted-dataset', null, { valueEncoding: 'json' })
const key = feed.encryptionKey.tostring('hex')
// Initialize a new feed with an existing key
const feed = new Hypercore('./cloned-encrypted-dataset', feed.key, { encryptionKey: key, valueEncoding: 'json' })
MIT