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

@peculiar/acme-client

v1.8.2

Published

Automatic Certificate Management Environment (ACME) client

Downloads

105

Readme

@peculiar/acme-client

License: AGPL v3 npm version

About

@peculiar/acme-client is anAutomatic Certificate Management Environment (ACME) implementing RFC 8555 client.

Installation

npm install @peculiar/acme-client

Usage

Browser

Every release of @peculiar/acme-client will have new build of ./build/acme.js for use in the browser. To get access to module classes use acme global variable.

WARN: We recommend hosting and controlling your own copy for security reasons

<script src="https://unpkg.com/@peculiar/acme-client"></script>

NodeJS

import * as acme  from "@peculiar/acme-client";

WARN: Client requires WebCrypto API and Fetch API modules. Use third-party modules to set crypto provider and fetch client in NodeJS (eg @peculiar/webcrypto, node-fetch).

import { Crypto } from "@peculiar/webcrypto";
import fetch from "node-fetch";

const client = new acme.ApiClient(keys, "https://path/to/acme/directory", {
    crypto,
    fetch,
  });

Examples

Create an ACME client and get a directory object

const client = await ApiClient.create(keys, "http://localhost:4000/acme/directory", {
  // fetch, // required for NodeJS
  // crypto, // required for NodeJS
});

const directory = await client.getDirectory();

Create a new account

// Generate account keys
const alg = { name: "ECDSA", namedCurve: "P-256" };
const keys = await crypto.subtle.generateKey(alg, false, ["sign", "verify"]);

const account = await client.newAccount({
  contact: ["mailto:[email protected]"],
  termsOfServiceAgreed: true,
});

Enroll certificate

WARN: That example uses @peculiar/x509 package for CSR generation

// Create a new order
let order = await client.newOrder({
  identifiers: [
    { type: "dns", value: "some.domain.com" },
  ],
});

for (const link of order.content.authorizations) {
  let authz = await client.getAuthorization(link);

  if (authz.content.status === "pending") {
    const httpChallenge = authz.content.challenges.find(o => o.type === "http-01");
    assert(httpChallenge, `Cannot find http-01 challenge for '${authz.content.identifier.type}:${authz.content.identifier.value}' authorization`);

    console.log(httpChallenge);
    // Get Token and put it to wellknown link of the Server

    // Validate challenge
    const resp = await client.getChallenge(httpChallenge.url, "POST");

    const up = /<([^<>]+)>/.exec(resp.headers.link.find(o => o.includes(`up"`)))[1];
    assert(up, "Cannot get up link from header");

    authz = await client.retryAuthorization(up);
    assert.strictEqual(authz.content.status, "valid");
  }
}

// Generate CSR
const reqKeys = await crypto.subtle.generateKey(alg, false, ["sign", "verify"]) as CryptoKeyPair;
const req = await x509.Pkcs10CertificateRequestGenerator.create({
  keys: reqKeys,
  name: "DC=some.domain.com",
  signingAlgorithm: alg,
}, crypto);

// Request certificate
await client.finalize(order.content.finalize, {
  csr: req.toString("base64url"),
});

// Waiting for enrollment
order = await client.retryOrder(order);
assert.strictEqual(order.content.status, "valid");

// Get issued certificate
const certs = await client.getCertificate(order.content.certificate);
console.log(certs.content);