open-index/open-npm huggingface dataset:
npm package: @hyperswarm/hypersign
Description: Utility methods related to public key cryptography to be used with distributed mutable storage
Author: David Mark Clements
Latest version: 2.1.1

# @hyperswarm/hypersign

Utility methods related to public key cryptography to be used with distributed mutable storage.

```
npm install @hyperswarm/hypersign
```

## API

#### `const { keypair, salt, sign, signable } = hypersign()`

Call the exported function to get hypersign instance.

There is also a class `hypersign.HyperSign` which can be
extended.

#### `keypair()`

Use this method to generate an assymetric keypair.
Returns an object with `{publicKey, secretKey}`. `publicKey` holds a public key buffer, `secretKey` holds a private key buffer.

#### `salt([str, ]size = 32)`

Utility method for creating a random or hashed salt value.

If called with a string the string will be hashed, to a
generic hash of `size` length.

If called without any inputs, or with a number, random 
butes of `size` length will be

#### `sign(value, options)`

Utility method which can be used to create a `sig`.

Options:

* `keypair` – REQUIRED, use `keypair` to generate this.
* `salt` - OPTIONAL - default `undefined`, a buffer >= 16 and <= 64 bytes. If supplied it will salt the signature used to verify mutable values.
* `seq` - OPTIONAL - default `0`. The sequence number of the value.

#### `signable(value, options)`

Utility method which returns the exact buffer that would be signed in by `sign`. This is only needed when using a salt, otherwise it will return the same `value` passed in. This method is to facilitate out-of-band signing (e.g. hardware signing), do not pass the returned signable value into `sign`, it already uses `signable`.
If you need to sign a value that has already been passed 
through `signable`, use `cryptoSign`.

Options:

* `salt` - OPTIONAL - default `undefined`, a buffer >= 16 and <= 64 bytes. If supplied it will salt the signature used to verify mutable values.
* `seq` - OPTIONAL - default `0`. The sequence number of the value.

#### `cryptoSign(msg, keypair)`

Utility method which can be used to create a signature using the `crypto_sign_detached` Sodium method. This only needs to be used 
when you *do not* need to apply encoding to `value`, `salt` and `seq`(e.g. if value and options have already been passed to `signable`).

Options:

* `keypair` – REQUIRED, use `keypair` to generate this.
* `salt` - OPTIONAL - default `undefined`, a buffer >= 16 and <= 64 bytes. If supplied it will salt the signature used to verify mutable values.
* `seq` - OPTIONAL - default `0`. The sequence number of the value.

## License

MIT
npm package: @hyperswarm/immutable-record
Description: Stateful Immutable record that can reannounce itself and more
Author: Mathias Buus
Latest version: 1.1.0

# @hyperswarm/immutable-record

Stateful Immutable record that can reannounce itself and more.

```
npm install @hyperswarm/immutable-record
```

## Usage

``` js
const ImmutableRecord = require('@hyperswarm/immutable-record')
```

Inserting values in the DHT

``` js
const record = ImmutableRecord.put(dhtNode, Buffer.from('some value'))

// To announce it ~every 15-20 min
// Returns a promise that will resolve when its unannounced
record.announce()

// Call unannounce to stop announcing
// Resolves the promises returned above
record.unannounce()
```

Retrieving them

``` js
const record = ImmutableRecord.get(dhtNode, keyBufferOrHex)

console.log('value is', await record.get())

// Similar to the insertion above you can reinsert this as well
// with the announce/unannounce methods
record.announce()
```

Note that unannounce does not destroy the DHT instance.

## License

MIT
npm package: @hyperswarm/kat
Description: Key Address Translation for Hyperswarm
Author: Mathias Buus
Latest version: 0.0.7

# @hyperswarm/kat

Key Address Translation - for Hyperswarm.

The Hyperswarm KAT protocol translates Noise public keys into network IPs
and also provides modern STUN approaches to penetrating most network firewalls.

Note, that the API is still under development so subject to changes.

The protocol consists of primary abstractions, Gateways and Clients.

## Gateways

A Gateway is a simple UDP server, running on a public network.

The purpose of a Gateway in the KAT protocol is to act as a way for clients, identified by a Noise keypair, behind commodity firewalls, to receive the first part of a Noise handshake, from other peers also behind commodity firewalls.

After relaying the initial exchange, a Gateway can also help provide some simple network diagnostics, that can help each peer choose what kind of network holepunching technique to use.

Normally a client would use a series of Gateways to announce itself. This helps provide better security and redundancy.

## Clients

Clients interact with a gateway using a UDP-based protocol.

A Client can choose to announce a Noise keypair to a Gateway, by proving to a gateway that it owns a specific keypair using a Noise handshake.
After announcing a Gateway will relay introductions to other Clients that wish to connect.

## API

Note that the API is still experimental and subject to change.

``` js
const { Client } = require('hyperpunch')

const c = new Client([
  'bootstrap1.hyperdht.org',
  'bootstrap2.hyperdht.org'
])

// to join the swarm and accept connections on a public key:
await c.join(keyPair)

c.on('connection', function (noiseStream) {
  // emitted when a new connection is accepted
  // noiseStream is a NoiseSecretStream instance
})

// to connect to a public key to
const noiseStream = c.connect(publicKey, localKeyPair)

noiseStream.on('open', function () {
  console.log('stream is fully open')
})

noiseStream.write(Buffer.from('hello world'))
```
npm package: @hyperswarm/network
Description: The networking guts of Hyperswarm
Author: Mathias Buus
Latest version: 2.1.0

# @hyperswarm/network

The low level networking guts of the Hyperswarm stack.

```
npm install @hyperswarm/network
```

## Usage

``` js
const network = require('@hyperswarm/network')()

const nw = network()

nw.bind(function () {
  // topic should be a 32 byte buffer
  nw.lookupOne(topic, function (err, peer) {
    if (err) throw err
    nw.connect(peer, function (err, socket) {
      if (err) throw err
      socket.write('Hello World!')
    })
  })
})
```

## API

#### `net = network([options])`

Create a new network instance.

Options include:

``` js
{
  bind () {
    // called when the network is bound
  },
  close () {
    // called when the network is fully closed
  },
  socket (socket) {
    // called when an incoming socket is received
  },
  // Optionally overwrite the default set of bootstrap servers
  bootstrap: [addresses],
  // Set to false if this is a long running instance on a server
  // When running in ephemeral mode you don't join the DHT but just 
  // query it instead. If unset, or set to a non-boolean (default undefined)
  // then the node will start in short-lived (ephemeral) mode and switch 
  // to long-lived (non-ephemeral) mode after a certain period of uptime
  ephemeral: undefined
}
```

#### `nw.bind([preferredPort], [callback])`

Bind to a preferred port. Must be called before connecting.

Safe to call multiple times. If already bound or binding it will call
the callback when fully bound.

#### `nw.close([callback])`

Fully close the network.

Safe to call multiple times.

#### `nw.connect(peer, callback)`

Connect to a peer. Will do UDP holepunching.

Callback is called with `(err, socket, isTCP)`. If the underlying socket is a TCP socket `isTCP` will be true, if it is a UTP socket it will be false.

#### `announcer = nw.announce(topic)`

Start announcing the network on the Hyperswarm discovery network.

#### `lookup = nw.lookup(topic)`

Start doing a lookup on the Hyperswarm discovery network.

#### `nw.lookupOne(topic, callback)`

Lookup a single peer on the Hyperswarm discovery network.

## License

MIT
npm package: @hyperswarm/replicator
Description: Replicates data structures easily using hyperswarm
Author: Mathias Buus
Latest version: 2.0.2

# @hyperswarm/replicator

Replicate data structures easily using hyperswarm

## Install

```js
npm install @hyperswarm/replicator
```

## Usage

You data structure has to support a .replicate() stream, then you can replicate
them using the hyperswarm replicator.

```js
const Replicator = require('@hyperswarm/replicator')

const r = new Replicator()

r.add(aHypercore, {
  live: true // passed to .replicate
})
```

## API

#### `r = new Replicator([options])`

Make a new replicator. Options include:

```js
{
  bootstrap: [...], // optional set the DHT bootstrap servers
}
```

#### `promise = r.add(hyperDataStructure, [options])`

Add a hyper* data structure to replicate.

```js
{
  live: bool, // passed to .replicate
  upload: bool, // passed to .replicate
  download: bool, // passed to .replicate
  encrypt: bool, // passed to .replicate
  discoveryKey: <buf>, // optionally set your own discovery key
  announce: true, // should the swarm announce you?
  lookup: true, // should the swarm do lookups for you?
  keyPair: { publicKey, secretKey }, // noise keypair used for the connection
  onauthenticate (remotePublicKey, done) // the onauthenticate hook to verify remote key pairs
}
```

Promise resolves when the data structure has been fully added.


#### `promise = r.remove(hyperDataStructure)`

Remove a data structure from replication.
Promise resolves when the data structure has been fully removed.

#### `r.swarm`

The associated hyperswarm instance.

#### `r.on('discovery-key', (discoveryKey, remoteStream) => ...)`

Emitted when a remote asks for a discovery key of a data structure you are
not currently replicating.

#### `r = Replicator.replicate(hyperDataStructure[s])`

Easy "one off" replication of one or more data structures.

## License

MIT