js-libp2p-secio/src/index.js

37 lines
747 B
JavaScript
Raw Normal View History

2016-05-20 21:29:53 +02:00
'use strict'
const pull = require('pull-stream')
const Connection = require('interface-connection').Connection
2016-05-22 13:19:17 +02:00
2016-05-22 01:51:15 +02:00
const handshake = require('./handshake')
const State = require('./state')
2016-05-22 01:51:15 +02:00
2016-05-22 13:19:17 +02:00
exports.SecureSession = class SecureSession {
2016-05-22 01:51:15 +02:00
constructor (local, key, insecure) {
if (!local) {
2016-05-22 01:51:15 +02:00
throw new Error('no local id provided')
}
if (!key) {
2016-05-22 01:51:15 +02:00
throw new Error('no local private key provided')
}
if (!insecure) {
throw new Error('no insecure stream provided')
}
this.state = new State(local, key)
this.insecure = insecure
pull(
this.insecure,
handshake(this.state),
this.insecure
)
}
get secure () {
return new Connection(this.state.secure, this.insecure)
2016-05-22 01:51:15 +02:00
}
}