Socket
Book a DemoInstallSign in
Socket

blind-pairing

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blind-pairing

Blind pairing using Hyperswarm

latest
Source
npmnpm
Version
2.3.1
Version published
Maintainers
1
Created
Source

blind-pairing

Blind pairing over HyperDHT

npm install blind-pairing

Usage

import createTestnet from 'hyperdht/testnet.js'
import Hyperswarm from 'hyperswarm'
import BlindPairing from './index.js'

const t = await createTestnet()
const autobaseKey = Buffer.alloc(32).fill('the-autobase-key')

const { invite, publicKey, discoveryKey } = BlindPairing.createInvite(autobaseKey)

const a = new BlindPairing(new Hyperswarm({ bootstrap: t.bootstrap }), { poll: 5000 })

const m = a.addMember({
  discoveryKey,
  async onadd (candidate) {
    console.log('candiate id is', candidate.inviteId)
    candidate.open(publicKey)
    console.log('add candidate:', candidate.userData)
    candidate.confirm({ key: autobaseKey })
  }
})

await m.flushed()

const userData = Buffer.alloc(32).fill('i am a candidate')

const b = new BlindPairing(new Hyperswarm({ bootstrap: t.bootstrap }), {
  poll: 5000
})

const c = b.addCandidate({
  invite,
  userData,
  async onadd (result) {
    console.log('got the result!', result)
  }
})

console.time('paired')
await c.pairing
console.timeEnd('paired')
console.log('paired:', c.paired)

await a.close()
await b.close()

console.log('closed')

await a.swarm.destroy()
await b.swarm.destroy()

console.log('fully closed')

await t.destroy()

License

Apache-2.0

FAQs

Package last updated on 31 Oct 2024

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