Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@stacksjs/tlsx

stacksjs1.1kMIT0.10.0TypeScript support: included

A TLS/HTTPS library with automation.

tls, https, ssl, security, https, cryptography, x509, keys, certificates, rootca, ca-bundle, development, environment, bun, stacks, node-forge, typescript, javascript

readme

Social Card of this repo

npm version GitHub Actions Commitizen friendly

tlsx

A TLS library with automation. HTTPS by default through a light-weight library and/or CLI. Similar to mkcert.

Features

  • 🔒 SSL Support (HTTPS by default)
  • 0️⃣ Zero-Config & Zero-Setup HTTPS
  • 🛠️ Configurable Library & CLI
  • 🔀 Multi-domain Support
  • 🏗️ Cross-platform System Trust Store Integration

Install

bun install -d @stacksjs/tlsx

# or, invoke immediately
bunx @stacksjs/tlsx
npx @stacksjs/tlsx

Please note, we are looking to publish this package to npm under the name tlsx.

Here's to hoping npm will release the name for us 🙏🏽

Get Started

There are two ways of using this reverse proxy: as a library or as a CLI.

Library

Given the npm package is installed:

import type { AddCertOptions, CAOptions, CertificateOptions, TlsConfig, TlsOptions } from '@stacksjs/tlsx'
import { addCertToSystemTrustStoreAndSaveCert, cleanupTrustStore, config, forge, generateCertificate, pki, removeCertFromSystemTrustStore, storeCertificate, tls } from '@stacksjs/tlsx'

// Generate a certificate for a single domain
const cert = await generateCertificate({
  domain: 'example.com',
  rootCA: existingCA,
  validityDays: 365,
})

// Generate a certificate for multiple domains
const multiDomainCert = await generateCertificate({
  domains: ['example.com', 'api.example.com', '*.example.com'],
  rootCA: existingCA,
  validityDays: 365,
})

// Generate a certificate with both primary domain and additional domains
const combinedCert = await generateCertificate({
  domain: 'example.com',
  domains: ['api.example.com', '*.example.com'],
  rootCA: existingCA,
  validityDays: 365,
})

// Store and trust the certificate
await addCertToSystemTrustStoreAndSaveCert(cert, rootCA.certificate)

// Remove a specific certificate
await removeCertFromSystemTrustStore('example.com')

// Remove a certificate with a specific name
await removeCertFromSystemTrustStore('example.com', {}, 'My Custom Certificate Name')

// Clean up all TLSX certificates from the system trust store
await cleanupTrustStore()

// Clean up certificates matching a specific pattern
await cleanupTrustStore({}, 'My Custom Pattern')

CLI

# Generate certificate for a single domain
tlsx secure example.com

# Generate certificate for multiple domains
tlsx secure -d "example.com,api.example.com,*.example.com"

# Generate certificate with primary domain and additional domains
tlsx secure example.com -d "api.example.com,*.example.com"

# Generate certificate with custom validity and organization
tlsx secure example.com --validity-days 365 --organization-name "My Company"

# Revoke a certificate for a domain
tlsx revoke example.com

# Revoke a certificate with a specific name
tlsx revoke example.com --cert-name "My Custom Certificate"

# Clean up all TLSX certificates from the system trust store
tlsx cleanup

# Clean up certificates matching a specific pattern
tlsx cleanup --pattern "My Custom Pattern"

# List all certificates
tlsx list

# Verify a certificate
tlsx verify path/to/cert.crt

# Show system configuration and paths
tlsx info

# Show all available options
tlsx secure --help

# Show version
tlsx version

Configuration

tlsx can be configured using a tls.config.ts (or tls.config.js) file and it will be automatically loaded when running the tlsx command.

// tlsx.config.{ts,js}
import type { TlsConfig } from '@stacksjs/tlsx'

export default {
  domain: 'stacks.localhost',
  hostCertCN: 'stacks.localhost',
  caCertPath: path.join(os.homedir(), '.stacks', 'ssl', `tlsx.localhost.ca.crt`),
  certPath: path.join(os.homedir(), '.stacks', 'ssl', `tlsx.localhost.crt`),
  keyPath: path.join(os.homedir(), '.stacks', 'ssl', `tlsx.localhost.crt.key`),
  altNameIPs: ['127.0.0.1'],
  altNameURIs: ['localhost'],
  organizationName: 'stacksjs.org',
  countryName: 'US',
  stateName: 'California',
  localityName: 'Playa Vista',
  commonName: 'stacks.localhost',
  validityDays: 180,
  verbose: false,
} satisfies TlsConfig

Then run:

tlsx

To learn more, head over to the documentation.

Testing

bun test

Changelog

Please see our releases page for more information on what has changed recently.

Contributing

Please review the Contributing Guide for details.

Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discussions on GitHub

For casual chit-chat with others using this package:

Join the Stacks Discord Server

Postcardware

"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where tlsx is being used! We showcase them on our website too.

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎

Sponsors

We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

Made with 💙

changelog

Changelog

v0.10.0...main

compare changes

🚀 Enhancements

📖 Documentation

🏡 Chore

❤️ Contributors

v0.9.0...main

compare changes

🚀 Enhancements

  • Allow creating cert for multiple domains (182414b)

🏡 Chore

❤️ Contributors

v0.8.5...main

compare changes

🏡 Chore

❤️ Contributors

v0.8.4...main

compare changes

🩹 Fixes

  • Adjust paths after splitting (7102a68)

❤️ Contributors

v0.8.3...main

compare changes

🏡 Chore

  • Use bun instead of bunx (004201f)
  • Update bun version (595d8ff)
  • Adjust vitepress config (6c05a1c)
  • Add minification and splitting to build (92ce125)

❤️ Contributors

v0.8.2...main

compare changes

🩹 Fixes

  • Ensure caCertPath is properly defined (c2f6545)

🏡 Chore

  • Ensure default basePath is defined (ed0d76a)

❤️ Contributors

v0.8.1...main

compare changes

🩹 Fixes

  • Ensure certPath & certKeyPath are properly defined (553dc9b)

❤️ Contributors

v0.8.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.7.6...main

compare changes

🚀 Enhancements

🏡 Chore

  • Rename to rootCA (36b0d80)
  • Update generateCertificate name (a334711)
  • Make hostCertCN optional (3c1cb49)

❤️ Contributors

v0.7.5...main

compare changes

🏡 Chore

❤️ Contributors

v0.7.4...main

compare changes

🏡 Chore

  • Make subjectAltNames nullable (c527087)

❤️ Contributors

v0.7.3...main

compare changes

🏡 Chore

  • Ensure rootCAObject is nullable (e2de06f)

❤️ Contributors

v0.7.2...main

compare changes

🩹 Fixes

❤️ Contributors

v0.7.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.7.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.6.0...main

compare changes

🚀 Enhancements

  • Allow for more configurations (0e92763)

🏡 Chore

❤️ Contributors

v0.5.6...main

compare changes

🏡 Chore

  • Improve dynamic usage of config and options (6b1d90a)

❤️ Contributors

v0.5.5...main

compare changes

🏡 Chore

  • Add missing verbose type (76ab785)

❤️ Contributors

v0.5.4...main

compare changes

🏡 Chore

  • Improve storeCert debug log (0b7682e)

❤️ Contributors

v0.5.3...main

compare changes

🩹 Fixes

❤️ Contributors

v0.5.2...main

compare changes

🏡 Chore

❤️ Contributors

v0.5.1...main

compare changes

🩹 Fixes

❤️ Contributors

v0.5.0...main

compare changes

🏡 Chore

  • Update readme (dc7bafe)
  • Ensure verbose output is configurable (b225a04)

❤️ Contributors

v0.4.3...main

compare changes

🚀 Enhancements

🏡 Chore

❤️ Contributors

v0.4.2...main

compare changes

🚀 Enhancements

❤️ Contributors

v0.4.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.4.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.3.3...main

compare changes

🚀 Enhancements

  • Compile & release bin for all OS (338502a)

🏡 Chore

❤️ Contributors

v0.3.2...main

compare changes

🏡 Chore

❤️ Contributors

v0.3.1...main

compare changes

🩹 Fixes

🏡 Chore

❤️ Contributors

v0.3.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.2.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.1.3...main

compare changes

🚀 Enhancements

  • Add caCertPath, certPath and keyPath (62a4fa3)

🏡 Chore

❤️ Contributors

v0.1.2...main

compare changes

🩹 Fixes

❤️ Contributors

v0.1.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.1.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.0.4...main

compare changes

🏡 Chore

✅ Tests

❤️ Contributors

v0.0.3...main

compare changes

🏡 Chore

❤️ Contributors

v0.0.2...main

compare changes

🏡 Chore

❤️ Contributors

v0.0.1...main

compare changes

🏡 Chore

❤️ Contributors

...main

🏡 Chore

❤️ Contributors