mirror of
https://github.com/fluencelabs/js-libp2p-secio
synced 2025-04-11 22:56:09 +00:00
36 lines
836 B
JavaScript
36 lines
836 B
JavaScript
'use strict'
|
|
|
|
const debug = require('debug')
|
|
const waterfall = require('async/waterfall')
|
|
|
|
const support = require('../support')
|
|
const crypto = require('./crypto')
|
|
|
|
const log = debug('libp2p:secio')
|
|
log.error = debug('libp2p:secio:error')
|
|
|
|
// step 2. Exchange
|
|
// -- exchange (signed) ephemeral keys. verify signatures.
|
|
module.exports = function exchange (state, cb) {
|
|
log('2. exchange - start')
|
|
|
|
log('2. exchange - writing exchange')
|
|
waterfall([
|
|
(cb) => crypto.createExchange(state, cb),
|
|
(ex, cb) => {
|
|
support.write(state, ex)
|
|
support.read(state.shake, cb)
|
|
},
|
|
(msg, cb) => {
|
|
log('2. exchange - reading exchange')
|
|
crypto.verify(state, msg, cb)
|
|
},
|
|
(cb) => crypto.generateKeys(state, cb)
|
|
], (err) => {
|
|
if (err) { return cb(err) }
|
|
|
|
log('2. exchange - finish')
|
|
cb()
|
|
})
|
|
}
|