@hyperdivision/heimdall-pairing

Pair a new user (initator) and an existing user (responder) in Heimdall

Usage no npm install needed!

<script type="module">
  import hyperdivisionHeimdallPairing from 'https://cdn.skypack.dev/@hyperdivision/heimdall-pairing';
</script>

README

heimdall-pairing

Pair a new user (initator) and an existing user (responder) in Heimdall

npm install @hyperdivision/heimdall-pairing

Usage

const { Initiator, Responder } = require('@hyperdivision/heimdall-pairing')

const i = new Initiator({
  keypair,
  profile
})

const r = new Responder({
  propose (key, profile, profileSignature, done) {
    // human validate the profile and propose it on the network
    // then reply back with the server key
    done(null, serverKey)
  })
})

// share the discovery key
r.setDiscoveryKey(i.discoveryKey)

r.on('pin', function (pin) {
  // communicate the security ping to i
  i.setPin(pin)
})

i.on('server-key', function (serverKey) {
  // and you are paired!
  // once the network approves you the server will
  // start replicating with you if you join the swarm using the above key
})

API

i.setProfile(profile)

Set the profile asynchrously in case you cannot pass one in the constructor

i.on('connected')

Emitted when it connects to the other peer before it is verified

i.on('verified')

Emitted when the other peer is verified (the pin matched)

i.on('server-key', serverKey)

Emitted when the pairing is done and the responder sends the server key

i.on('announcing')

Emitted when the initiator starts announcing on the network

i.on('error', err)

Emitted when there was an error in the pairing flow

i.discoveryKey

Share this discovery key with the responder (3 words)

i.setPin(pin)

Call this when the responder communicates the pin to you

i.destroy(err)

Call this to forcefully shutdown the pairing.

r.on('discovery-key', dk)

Emitted when the discovery key is set on the responder.

r.on('peer', peer)

Emitted when the responder founds a peer on the DHT that could be the initiator.

r.on('connecting', peer)

Emitted when the responder tries to connect to peer.

r.on('connected')

Emitted when the responder established connection with a potential initiator.

r.on('profile', key, profile, profileSignature)

Emitted when a profile is received from the initiator.

r.on('error', error)

Emitted when there was an error in the pairing flow.

r.on('server-key', serverKey)

Emitted when the responder sends the server key.

r.destroy(err)

Call this to forcefully shutdown the pairing.

bool = Responder.validateDiscoveryKey(dk)

Static helper to check if a discovery consists of valid words.

License

MIT