$ npm install blind-pairing-coreThe pairing flow proceeds as follows:
{ discoveryKey, seed } with a candidate (invitee). publicKey is set aside for later use.userData signed by the invitation keyPair, this is encrypted to a key derived from the invite publicKey.publicKey, proving that the invitee has secretKey.userData and either confirm or deny the request. A response is returned to the candidate which may contain the { key, encryptionKey } needed to join the room.key corresponds to discoveryKey, confirming that the remote peer has read-access to key (is a valid member).import {
CandidateRequest,
MemberRequest,
createInvite
} from 'blind-pairing-core'
const { invite, publicKey } = createInvite(key) // key is a Hypercore or Autobase key
// candidate
const candidate = new CandidateRequest(invite, { userData: 'hello world' })
candidate.on('accepted', () => console.log('accepted!'))
const transport = candidate.encode()
// member
const request = MemberRequest.from(transport)
const userData = request.open(publicKey)
console.log(userData) // hello world
request.confirm({ key })
// candidate
candidate.handleResponse(request.response)
// candidate accepted event will fire
console.log(candidate.auth) // { key }
exports:
{
CandidateRequest,
MemberRequest,
createInvite,
decodeInvite,
verifyReceipt
}
CandidateRequest APIconst req = new CandidateRequest(invite, userData, opts = { session })Instanstiate a new candidate request from a given invite.
const auth = req.handleResponse(payload)Handle the response received from the peer.
req.destroy()Destroy the request.
const buf = req.encode()Encode the request to be sent to the peer.
req.idUnique id for this request.
req.inviteIdInvite id corresponding to this request.
req.discoveryKeyDiscovery key corresponding to this request.
req.on('accepted', key => { ... })An event that fires when an invite is accepted.
req.on('rejected', err => { ... })An event that fires when an invite is rejected.
const persisted = req.persist()Returns a buffer that can be used to restore the request at a later point.
CandidateRequest.from (persisted)Restore a persisted request.
MemberRequest APIconst req = new MemberRequest(inviteId, requestData)Instantiate a new member request using the request id and the request data
const userData = req.open(invitePublicKey)Open the request using the corresponding invitation public key.
req.confirm({ key, encryptionKey })Confirm the request with the requested auth data.
req.deny()Deny the request.
const req = MemberRequest.from(incomingRequest)Static method to create a member request directly from a received request.
req.inviteIdThe invite id corresponding to the request, this can be used to find the invitation public key.
req.idThe unique id corresponding to the request.
req.responseThe response that should be sent back to the candidate. Only populated after the request is either confirmed or denied.
req.receiptA stand alone receipt of this request that can be verified against the public key.
req.discoveryKeyDiscovery key corresponding to this request.
const { invite, discoveryKey, publicKey } = createInvite(key)Create invites for a given key.
const { discoveryKey, seed } = decodeInvite(invite)Decode an invite object.
const userData = verifyReceipt(receipt, invitePublicKey)Verify a previously opened request. Returns userData if receipt is valid and null otherwise.
Apache-2.0