🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

hypercore-encryption

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypercore-encryption

Block encryption provider for hypercore

Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
11
10%
Maintainers
2
Weekly downloads
 
Created
Source

hypercore-encryption

Dyanmic Hypercore encryption provider

Usage

const HypercoreEncryption = require('hypercore-encryption')

async function get (id) {
  // get key info corresponding to id...

  return {
    version, // encryption scheme
    padding, // padding byte length
    key // block key
  }
}

const encryption = new HypercoreEncryption(blindingKey, get, {
  preopen: Promise.resolve(1) // optionally pass for initial id
})

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')

API

const enc = new HypercoreEncryption(blindingKey, getBlockKey, { promise })

Instantiate a new encryption provider. Optionally pass a preopen promise that resolves to a key id to be loaded initially.

Provide a hook with the signature:

function getBlockKey (id) {
  return {
    version, // encryption scheme
    padding, // padding byte length
    key // block key
  }
}

Note: in compat mode, the key info returned at 0 should always be version 0.

await enc.ready()

Wait for initial key to load if provided.

enc.padding

The number of padding bytes used by the current scheme.

enc.seekable

Boolean on whether the current scheme allows for seeks.

enc.id

The currently loaded key id.

enc.version

The version of the currently loaded scheme.

await enc.load(id)

Load the key under id and set to be the current encryption info.

await enc.encrypt(index, block, fork)

Encrypt a block in place.

await enc.decrypt(index, block)

Decrypt a block in place.

HypercoreEncryption.isHypercoreEncryption(enc)

Returns a boolean on whether enc is a valid encryption provider.

const blockKey = HypercoreEncryption.getBlockKey(hypercoreKey, encryptionKey)

Helper to generate namespaced block keys.

const legacy = HypercoreEncryption.createLegacyProvider(blockKey)

Create an encryption provider compatible with Hypercore's legacy encryption scheme.

License

Apache-2.0

FAQs

Package last updated on 02 Apr 2025

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