Socket
Book a DemoInstallSign in
Socket

broadcast-encryption

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broadcast-encryption

Distribute encryption keys to a dynamic set of receivers

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

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)

// distribute key to everyone
await broadcast.update(encryptionKey, [peer1, peer2, peer3])

encryptionKey.fill(0xff) // update encryption key

// distribute new key to everyone except peer3
await broadcast.update(encryptionKey, [peer1, peer2])

await broadcast.get(id) // get the encryption key corresponding to 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

FAQs

Package last updated on 08 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts