-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d8f19d
commit eb0d499
Showing
1 changed file
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
![Kadem](https://i.imgur.com/5yfwRZM.png) | ||
[![CI](https://github.com/jameskeane/kadem/actions/workflows/ci.yml/badge.svg)](https://github.com/jameskeane/kadem/actions/workflows/ci.yml) | ||
|
||
An implementation of the Kademlia DHT. | ||
An implementation of the BiTorrent DHT (Kademlia). | ||
|
||
Supports: | ||
- BEP-42 with `sse4_crc32` optional dependency. | ||
- BEP-44 with `ed25519-supercop` optional dependency. | ||
|
||
## Usage | ||
`npm install kadem` | ||
|
||
```javascript | ||
import DHT from 'kadem'; | ||
import DHT from 'kadem'; | ||
|
||
// load DHT from stored state file; if it doesn't | ||
// exist or is not provided it'll bootstrap itself. | ||
const dht = DHT.load('.dht_state'); | ||
dht.listen(/** listening port, can be anything */ 8468); | ||
|
||
// create a public/secret key pair to use BEP-44 | ||
const keys = ed25519.createKeyPair(); | ||
|
||
// load DHT from stored state file; if it doesn't | ||
// exist or is not provided it'll bootstrap itself. | ||
const dht = DHT.load('.dht_state'); | ||
dht.listen(/** listening port, can be anything */ 8468); | ||
// store mutable value | ||
dht.put(keys.publicKey, (sign, r) => sign({ v: 'example-mutable'}, keys.secretKey)); | ||
|
||
const value = await dht.get({ k: key, salt: salt }); | ||
// retrieve mutable value | ||
const value = await dht.get({ k: keys.publicKey }); | ||
assert value.v == 'example-mutable'; | ||
``` |