2016-05-22 01:03:53 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const debug = require('debug')
|
2016-11-03 10:23:33 +01:00
|
|
|
const waterfall = require('async/waterfall')
|
2016-06-13 19:10:38 +02:00
|
|
|
|
|
|
|
const support = require('../support')
|
|
|
|
const crypto = require('./crypto')
|
2016-05-22 01:33:50 +02:00
|
|
|
|
2016-05-23 12:42:21 +02:00
|
|
|
const log = debug('libp2p:secio')
|
|
|
|
log.error = debug('libp2p:secio:error')
|
2016-05-22 01:03:53 +02:00
|
|
|
|
2016-05-22 18:36:31 +02:00
|
|
|
// step 2. Exchange
|
|
|
|
// -- exchange (signed) ephemeral keys. verify signatures.
|
2016-06-13 19:10:38 +02:00
|
|
|
module.exports = function exchange (state, cb) {
|
2016-05-23 12:42:21 +02:00
|
|
|
log('2. exchange - start')
|
2016-05-22 22:39:36 +02:00
|
|
|
|
2016-06-13 19:10:38 +02:00
|
|
|
log('2. exchange - writing exchange')
|
2016-11-03 10:23:33 +01:00
|
|
|
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) => {
|
2018-01-07 13:58:30 +00:00
|
|
|
if (err) { return cb(err) }
|
2016-05-22 18:36:31 +02:00
|
|
|
|
|
|
|
log('2. exchange - finish')
|
|
|
|
cb()
|
|
|
|
})
|
|
|
|
}
|