npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

letsencrypt-client-v2

v2.1.0

Published

Let's Encrypt ACME client supporting the v2 API with minimal dependencies

Downloads

11

Readme

LetsEncrypt client v2

Implementation of the ACME protocol to request certificates from Let's Encrypt. Supporting LetsEncrypt's v2 API with minimal dependencies

Installation

npm install letsencrypt-client-v2

Usage

constructor(acccountKey, options)

Create a client by providing the PEM encoded account private key.

'use strict'

const fs = require("fs");
const LEClient = require("letsencrypt-client");

let accountKey = fs.readFileSync("account.key");

let client = new LEClient(accountKey);

To create a new private key, use the following OpenSSL command:

openssl genrsa 4096 > account.key

Options

  • email: account email to login
  • staging: use the staging API (instead)

register()

To register or login with Let's Encrypt, use the register() method.

client.register(email).then(() => {
    console.log("Registered successfully");
}, (error) => {
    console.log("An error occured", error);
});

This method returns a standard ES6 Promise.

Note: If an email is passed in the constructor options the client will try to call this method automatically.

start(domains)

Initiate an order for the domain variations of an SSL certificate.

let domains = ['www.domain.com', 'domain.com'];
client.start(domains).then(function(){
  // loop through all domains
});

requestAuthorization(domain)

To request a domain verification challenge, use the requestAuthorization(domain) method, by providing the domain that needs to be verified.

let domain = "example.com";
client.requestAuthorization(domain).then((challenge) => {
    console.log("Domain verification challenge requested successfully");
    console.log(challenge);
}, (error) => {
    console.log("An error occured", error);
});

This method returns a standard ES6 Promise.

The resulting challenge object will contain a path key with the path that the Let's Encrypt server will request, and a keyAuthorization key with the value that should be returned to the Let's Encrypt request.

triggerChallenge(challenge)

Once the HTTP server has been configured to respond with the correct value, use the triggerChallenge(challenge) method to trigger the challenge. Pass the challenge object from the requestAuthorization(domain) method.

client.triggerChallenge(challenge).then((res) => {
    console.log("Challenge triggered successfully");
    // poll url is in the response
    challenge.poll = res.url;
    // no need to poll if already valid, continue to the next domain (check if any left in the order)
    if(res.status == "valid") return;
    // otherwhise check the challenge with: client.checkChallenge(challenge)...
}, (error) => {
    console.log("An error occured", error);
});

This method returns a standard ES6 Promise.

checkChallenge(challenge)

You can check the status of a challenge with the checkChallenge(challenge) method. Pass the challenge object from the requestAuthorization(domain) method.

client.checkChallenge(challenge).then((status) => {
    console.log("Challenge checked successfully");
    console.log(status);
}, (error) => {
    console.log("An error occured", error);
});

This method returns a standard ES6 Promise.

The status value can be pending, valid (domain ownership confirmed) or invalid (domain ownership failed).

requestCertificate(csr)

Once all the domains of the certificate signing request (CSR) have been validated, use the requestCertificate(csr) method to request the certificate. The PEM encoded CSR needs to be provided.

let csr = fs.readFileSync("domain.csr");
client.requestCertificate(csr).then((certificate) => {
    console.log("Certificate requested successfully");
    console.log(certificate);
}, (error) => {
    console.log("An error occured", error);
});

This method returns a standard ES6 Promise.

The resulting certificate will contain the PEM encoded certificate string.

To create a new certificate signing request, use the following OpenSSL command (from diafygi/acme-tiny):

#for a single domain
openssl req -new -sha256 -key domain.key -subj "/CN=yoursite.com" > domain.csr

#for multiple domains (use this one if you want both www.yoursite.com and yoursite.com)
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:yoursite.com,DNS:www.yoursite.com")) > domain.csr

Credits

Based on the module letsencrypt-client by Quentin Adam