-
Notifications
You must be signed in to change notification settings - Fork 17
/
example.js
28 lines (20 loc) · 924 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const noise = require('./index2')
const sClient = noise.keygen()
const sServer = noise.keygen()
const client = noise.initialize('KK', true, Buffer.alloc(0), sClient, null, sServer.publicKey)
const server = noise.initialize('KK', false, Buffer.alloc(0), sServer, null, sClient.publicKey)
const clientTx = Buffer.alloc(128)
const serverTx = Buffer.alloc(128)
const clientRx = Buffer.alloc(128)
const serverRx = Buffer.alloc(128)
// -> e, es, ss
noise.writeMessage(client, Buffer.alloc(0), clientTx)
noise.readMessage(server, clientTx.subarray(0, noise.writeMessage.bytes), serverRx)
// <- e, ee, se
const serverSplit = noise.writeMessage(server, Buffer.alloc(0), serverTx)
const clientSplit = noise.readMessage(client, serverTx.subarray(0, noise.writeMessage.bytes), clientRx)
noise.destroy(client)
noise.destroy(server)
// Can now do transport encryption with splits
console.log(serverSplit)
console.log(clientSplit)