Skip to content

Commit

Permalink
wip: Attempt to setup wss
Browse files Browse the repository at this point in the history
Resolves #50
  • Loading branch information
D4nte committed Apr 28, 2021
1 parent fb84c44 commit 4675ac3
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 6 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"eslint-plugin-import": "^2.22.0",
"fast-check": "^2.14.0",
"gh-pages": "^3.1.0",
"https": "^1.0.0",
"mocha": "^8.3.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
Expand Down
22 changes: 17 additions & 5 deletions src/lib/waku.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as fs from 'fs';
import * as https from 'https';

import { expect } from 'chai';
import TCP from 'libp2p-tcp';
import { multiaddr } from 'multiaddr';
Expand Down Expand Up @@ -104,15 +107,24 @@ describe('Waku Dial', function () {

it('wss', async function () {
this.timeout(10_000);

const httpServer = https.createServer({
cert: fs.readFileSync('./test_certs/cert.pem'),
key: fs.readFileSync('./test_certs/key.pem'),
});

const [waku1, waku2] = await Promise.all([
Waku.create({
staticNoiseKey: NOISE_KEY_1,
listenAddresses: ['/ip4/0.0.0.0/tcp/0/wss'],
}),
Waku.create(
{
staticNoiseKey: NOISE_KEY_1,
listenAddresses: ['/ip4/0.0.0.0/tcp/0/wss'],
},
httpServer
),
Waku.create({ staticNoiseKey: NOISE_KEY_2 }),
]);
const waku1MultiAddrWithId = waku1.getLocalMultiaddrWithID();

console.log(waku1MultiAddrWithId);
await waku2.dial(waku1MultiAddrWithId);

const waku2PeerId = waku2.libp2p.peerId;
Expand Down
7 changes: 6 additions & 1 deletion src/lib/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type CreateOptions =
staticNoiseKey: bytes | undefined;
modules: Partial<Libp2pModules>;
config: Partial<Libp2pConfig>;
listenerOptions: { server: any } | undefined;
}
| (Libp2pOptions & import('libp2p').CreateOptions);

Expand All @@ -41,7 +42,10 @@ export default class Waku {
* @throws If
* @returns {Promise<Waku>}
*/
static async create(options: Partial<CreateOptions>): Promise<Waku> {
static async create(
options: Partial<CreateOptions>,
server?: any
): Promise<Waku> {
const opts = Object.assign(
{
listenAddresses: [],
Expand All @@ -55,6 +59,7 @@ export default class Waku {
transport: {
[transportKey]: {
filter: filters.all,
listenerOptions: { server: server },
},
},
},
Expand Down
32 changes: 32 additions & 0 deletions test_certs/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFlzCCA3+gAwIBAgIUMYedwb9L/BtvZ7Lhu71iSKrXsa4wDQYJKoZIhvcNAQEL
BQAwajELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAlZBMREwDwYDVQQHDAhTb21lQ2l0
eTESMBAGA1UECgwJTXlDb21wYW55MRMwEQYDVQQLDApNeURpdmlzaW9uMRIwEAYD
VQQDDAkxMjcuMC4wLjEwHhcNMjEwNDI4MDIzMjA5WhcNMjIwNDI4MDIzMjA5WjBq
MQswCQYDVQQGEwJVUzELMAkGA1UECAwCVkExETAPBgNVBAcMCFNvbWVDaXR5MRIw
EAYDVQQKDAlNeUNvbXBhbnkxEzARBgNVBAsMCk15RGl2aXNpb24xEjAQBgNVBAMM
CTEyNy4wLjAuMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBANNhXBu0
GH1Kzl9iaQxCxEnyyAShS5FYScdKxqpYsgJT4poLWLQBZQEFLEqbdillIlTZqMss
jWqkFL2xmjqdcnOKFEZUarntVE2hxFYYQex2Fi8MYwFj+Pvt74d02xPyfzFNFgyX
a1EakoGBwClaf3I7jW7raPudjcf4HnwQ7r/NwiO8FqHFZgLcTnwI8bk+cxDoDAqu
mhqMB5nnerqvKEyR9Fb2PoL+8PwOPJOOKTDVwLMeMJu2WLR8AU2FzOj5SV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S6fR9vDc20SrtoNvKQM1U6+0VYs1nizfkmsqqqRODmERKbKwc
ahKJFubXfr8gz+PipAKFZbxr2EPAyoiNkx+0eM6Eedo55oP2BoGHEfXEoAonyMFM
F/xTbpFtdRYE2hwsZCk86fpbcPTmdCY8txeZ7+4Bme2d9XXsTAxF64usqQ==
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions test_certs/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQDTYVwbtBh9Ss5f
YmkMQsRJ8sgEoUuRWEnHSsaqWLICU+KaC1i0AWUBBSxKm3YpZSJU2ajLLI1qpBS9
sZo6nXJzihRGVGq57VRNocRWGEHsdhYvDGMBY/j77e+HdNsT8n8xTRYMl2tRGpKB
gcApWn9yO41u62j7nY3H+B58EO6/zcIjvBahxWYC3E58CPG5PnMQ6AwKrpoajAeZ
53q6ryhMkfRW9j6C/vD8DjyTjikw1cCzHjCbtli0fAFNhczo+UlSNqrLvT7OWs8r
A/CkADHMOMvbOnaN+kmjEEvOX271wVe1wajA9+BzwVGxYgqBaGgsyvWX26Ql8lST
FDZsOYcqvZ241LeCr6/+fG1NoI1CknT3+ioQcRZw2cJftqqj3VSG/6rcMxxMbSVq
t7qZJVzToNx6Eer3K9TvUXiR68y0TBG+dVj9Wjf6idv5UbJHGeAPNOqsK1uuwb5z
oOrN2bcRzfb927Mn7LwuusPDxHwpwlcboAu3FFtILVueAFO+U97pIO1/prxAq//q
iMzRASMcQj4HnwhvyQHSYUOUgr6AEQFT0rVCFg5ooA3jre4KOZym3VSCeO22wRVI
R09pkx7t9Hx4Uakg3B88BO2c+mCSCZiqtvVJs1GsxZypS1OuzIyycIgz5nwtxsjn
QFpJGROYY7ZIsvt8lqBB4WiWESNbtwIDAQABAoICAQCpGV3iG7Trpohp7gQzdsYo
kjxI1+/oGkULVVqQs9vT2N+SdDlF50eyBT1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