New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

key-collection

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-collection

Hyperdb-based collection of 32-byte keys

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
7
40%
Maintainers
1
Weekly downloads
 
Created
Source

Key Collection

A hyperdb-based collection of 32-byte keys.

Install

npm i -g key-collection

Usage

Create

key-collection sync <location>

Where <location> is the path of a yaml file structured like example.yml.

This will first sync the database with the yaml file, deleting and adding entries as required, and then seed the database.

Consume

const KeyCollection = require('key-collection')
const Corestore = require('corestore')
const Hyperswarm = require('hyperswarm')
const IdEnc = require('hypercore-id-encoding')

async function main () {
  const key = IdEnc.decode('your key here') // Fill in with the public key of the collection db, as printed in the previous step

  const store = new Corestore('key-collection-store')
  const core = store.get({ key })
  const keyColl = new KeyCollection(core)
  await keyColl.ready()

  const swarm = new Hyperswarm()
  swarm.on('connection', (conn) => {
    console.log('connection opened')
    store.replicate(conn)
  })

  swarm.join(keyColl.discoveryKey, { client: true, server: false })
  console.log(await keyColl.toMap()) // Note: will print an empty map the first time it runs, because it hasn't synced with the server yet
}

main()

Keywords

key

FAQs

Package last updated on 16 Dec 2025

Related posts