New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dht-keyvalue

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dht-keyvalue

Key-value store powered by bittorrent-dht

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-88.89%
Maintainers
1
Weekly downloads
 
Created
Source

dht-keyvalue

Store key-value pairs on the mainline bittorrent DHT network, and retreive them by key lookup.

Status

This is a work in progress, but is minimally viable for use as of this revision.

Notes

  • A local hash table of key name and DHT hash address is maintained to allow for key name lookups
  • Any value datatype is accepted
  • dht-keyvalue will reject objects larger than 1000 Bytes
  • Initial puts on DHT may take some time (seconds)
  • Updates to existing records on DHT happen faster
  • Data contained in the record is plain text. Anyone with the hash address for the record can retrieve and view the data
  • Consider encorporating your own encryption solution on top of dht-kevalue to protect the data

Install

npm i dht-keyvalue

Usage

const dhtKv = require('dht-keyvalue')

let opts = {
 keep: true, // default = true. Keep the DHT object alive in the mainline bittorrent network
 keepalive: 3600000 // default = 3600000. Interval to refresh the DHT object (milliseconds)
}

const dkv = new dhtKv(opts)

Examples

Put, get, update one record on DHT

let item = [
 { key: 'my cool key', value: 'my cool key initial value' }
]

dkv.put(item, (hash, key) => {
 console.log('Successfully announced:', key, 'DHT address:', hash)

 // Now that it is announced, retrieve it from DHT
 dkv.get(item[0].key, value => {
  console.log(value)
 })

 // Update the key's value in DHT
 let newValue = 'Updated value for my cool key'
 dkv.update(item[0].key, newValue, updated => {
  console.log('Updated in DHT', updated)

  // Retrieve the updated value
  dkv.get(item[0].key, value => {
   console.log(value)
  })
 })
})

Put, get, update multiple records on DHT

let items = [
 { key: "first key", value: "first value" }, 
 { key: "second key", value: "second value" },
 //...
]

dkv.put(items, (hash, key) => {
 console.log('Successfully announced:', key, 'DHT address:', hash)

 // Now that it is announced, retrieve it from DHT
 dkv.get(key, value => {
  console.log(value)
 })

 // Update the key's value in DHT
 let newValue = Math.random() // some updated value
 dkv.update(key, newValue, updated => {
  console.log('Updated in DHT', updated)

  // Retrieve the updated value
  dkv.get(key, value => {
   console.log(value)
  })
 })
})

Keywords

FAQs

Package last updated on 17 Jul 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc