broadcast-encryption
Distribute encryption keys to a dynamic set of receivers
Usage
const core = new Hypercore(storage)
const broadcast = new BroadcastEncryption(core, { keyPair })
const encryptionKey = Buffer.alloc(32)
await broadcast.update(encryptionKey, [peer1, peer2, peer3])
encryptionKey.fill(0xff)
await broadcast.update(encryptionKey, [peer1, peer2])
await broadcast.get(id)
API
const broadcast = new BroadcastEncryption(core, opts)
Instantiate a new broadcast instance.
opts include:
{
keyPair, // receiver key pair used for decryption
bootstrap // initial key information to use
}
const current = broadcast.id()
The current encryption key id.
await broadcast.update(key, recipients)
Distribute the updated key to all members of recipients.
const { id, encryptionKey } = await broadcast.get(id)
Get the encryption key corresponding to id.
If id is passed as -1, the latest encryption key shall be returned.
const encryption = await broadcast.createEncryptionProvider(opts)
Create a HypercoreEncryption provider to pass to a hypercore.
broadcast.on('update', (id) => {})
An update event is emitted when a new encryption key is loaded.
const payload = BroadcastEncryption.encrypt(data, recipients)
Static helper to broadcast encrypt a message.
const data = BroadcastEncryption.decrypt(payload, recipientSecretKey)
Static helper to decrypt a broadcast encrypted message.
const payload = BroadcastEncryption.verify(payload, data, recipients)
Static helper to verify a payload. Returns true if all members on recipients can decrypt data.
License
Apache-2.0