JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3914
  • Score
    100M100P100Q122971F
  • License MIT

DTLS protocol implementation for Node.js written in TypeScript.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (werift-dtls) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    DTLS v1.2 server/client Implementation for TypeScript

    Example

    import { DtlsServer, DtlsClient, createUdpTransport } from "werift-dtls";
    import { readFileSync } from "fs";
    import { createSocket } from "dgram";
    
    const port = 55557;
    
    const socket = createSocket("udp4");
    socket.bind(port);
    
    const server = new DtlsServer({
      cert: readFileSync("assets/cert.pem").toString(),
      key: readFileSync("assets/key.pem").toString(),
      transport: createUdpTransport(socket),
    });
    
    const client = new DtlsClient({
      transport: createUdpTransport(createSocket("udp4"), {
        address: "127.0.0.1",
        port,
      }),
    });
    
    server.onData = (data) => {
      console.log(data.toString());
    };
    
    client.onConnect = () => {
      client.send(Buffer.from("ping"));
    };
    client.onData = (data) => {
      console.log(data.toString());
    };
    
    client.connect();

    reference

    create key & cert

    openssl genrsa 2048 > rsa.key
    openssl pkcs8 -in rsa.key -topk8 -out key.pem -nocrypt
    openssl req -new -key key.pem > cert.csr
    openssl x509 -req -days 3650 -signkey key.pem -in cert.csr -out  cert.pem