mirror of https://github.com/certd/certd
chore: node-acme-client转换为esm
parent
a9a0967a6f
commit
087c0b8253
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"extends": [
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"plugins": [
|
||||
"eslint-plugin-import"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
// "no-unused-expressions": "off",
|
||||
"max-len": [
|
||||
0,
|
||||
160,
|
||||
2,
|
||||
{
|
||||
"ignoreUrls": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
extends:
|
||||
- 'airbnb-base'
|
||||
|
||||
env:
|
||||
browser: false
|
||||
node: true
|
||||
mocha: true
|
||||
|
||||
rules:
|
||||
indent: [2, 4, { SwitchCase: 1, VariableDeclarator: 1 }]
|
||||
brace-style: [2, 'stroustrup', { allowSingleLine: true }]
|
||||
func-names: 0
|
||||
class-methods-use-this: 0
|
||||
no-param-reassign: 0
|
||||
max-len: [1, 200, 2, { ignoreUrls: true, ignoreComments: false }]
|
||||
import/no-useless-path-segments: 0
|
|
@ -4,6 +4,8 @@
|
|||
"private": false,
|
||||
"author": "nmorsman",
|
||||
"version": "1.27.2",
|
||||
"type": "module",
|
||||
"module": "scr/index.js",
|
||||
"main": "src/index.js",
|
||||
"types": "types/index.d.ts",
|
||||
"license": "MIT",
|
||||
|
@ -22,21 +24,23 @@
|
|||
"debug": "^4.3.5",
|
||||
"http-proxy-agent": "^7.0.2",
|
||||
"https-proxy-agent": "^7.0.5",
|
||||
"node-forge": "^1.3.1"
|
||||
"node-forge": "^1.3.1",
|
||||
"lodash-es": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.10",
|
||||
"chai": "^4.4.1",
|
||||
"chai-as-promised": "^7.1.2",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"jsdoc-to-markdown": "^8.0.1",
|
||||
"mocha": "^10.6.0",
|
||||
"nock": "^13.5.4",
|
||||
"prettier": "^2.8.8",
|
||||
"tsd": "^0.31.1",
|
||||
"typescript": "^5.4.2"
|
||||
"typescript": "^5.4.2",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build-docs": "jsdoc2md src/client.js > docs/client.md && jsdoc2md src/crypto/index.js > docs/crypto.md && jsdoc2md src/crypto/forge.js > docs/forge.md",
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
const nodeHttp = require('node:http');
|
||||
const https = require('node:https');
|
||||
const { HttpProxyAgent } = require('http-proxy-agent');
|
||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
||||
const { log } = require('./logger');
|
||||
|
||||
import nodeHttp from 'node:http'
|
||||
import https from 'https'
|
||||
import {HttpProxyAgent} from "http-proxy-agent";
|
||||
import {HttpsProxyAgent} from "https-proxy-agent";
|
||||
import {log} from './logger.js'
|
||||
import {merge} from 'lodash-es'
|
||||
function createAgent(opts = {}) {
|
||||
opts = merge(
|
||||
{
|
||||
autoSelectFamily: true,
|
||||
autoSelectFamilyAttemptTimeout: 2000,
|
||||
},
|
||||
opts,
|
||||
);
|
||||
|
||||
let httpAgent;
|
||||
let
|
||||
httpsAgent;
|
||||
let httpsAgent;
|
||||
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
||||
if (httpProxy) {
|
||||
log(`acme use httpProxy:${httpProxy}`);
|
||||
httpAgent = new HttpProxyAgent(httpProxy, opts);
|
||||
merge(httpAgent.options, opts);
|
||||
}
|
||||
else {
|
||||
httpAgent = new nodeHttp.Agent(opts);
|
||||
|
@ -20,6 +28,7 @@ function createAgent(opts = {}) {
|
|||
if (httpsProxy) {
|
||||
log(`acme use httpsProxy:${httpsProxy}`);
|
||||
httpsAgent = new HttpsProxyAgent(httpsProxy, opts);
|
||||
merge(httpsAgent.options, opts);
|
||||
}
|
||||
else {
|
||||
httpsAgent = new https.Agent(opts);
|
||||
|
@ -102,7 +111,7 @@ class HttpError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
setGlobalProxy,
|
||||
createAgent,
|
||||
getGlobalAgents,
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/**
|
||||
* ACME API client
|
||||
*/
|
||||
|
||||
const util = require('./util');
|
||||
const { log } = require('./logger');
|
||||
import * as util from './util.js';
|
||||
|
||||
/**
|
||||
* AcmeApi
|
||||
|
@ -248,4 +246,4 @@ class AcmeApi {
|
|||
}
|
||||
|
||||
/* Export API */
|
||||
module.exports = AcmeApi;
|
||||
export default AcmeApi;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* ACME auto helper
|
||||
*/
|
||||
import { readCsrDomains } from './crypto/index.js';
|
||||
import { log } from './logger.js';
|
||||
import { wait } from './wait.js';
|
||||
import { CancelError } from './error.js';
|
||||
|
||||
const { readCsrDomains } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
const { wait } = require('./wait');
|
||||
const { CancelError } = require('./error');
|
||||
|
||||
const defaultOpts = {
|
||||
csr: null,
|
||||
|
@ -30,7 +30,7 @@ const defaultOpts = {
|
|||
* @returns {Promise<buffer>} Certificate
|
||||
*/
|
||||
|
||||
module.exports = async (client, userOpts) => {
|
||||
export default async (client, userOpts) => {
|
||||
const opts = { ...defaultOpts, ...userOpts };
|
||||
const accountPayload = { termsOfServiceAgreed: opts.termsOfServiceAgreed };
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Axios instance
|
||||
*/
|
||||
const axios = require('axios');
|
||||
const { parseRetryAfterHeader } = require('./util');
|
||||
const { log } = require('./logger');
|
||||
const pkg = require('./../package.json');
|
||||
const Agents = require('./agents');
|
||||
|
||||
import axios from 'axios';
|
||||
import { parseRetryAfterHeader } from './util.js';
|
||||
import { log } from './logger.js';
|
||||
import * as Agents from './agents.js';
|
||||
const { AxiosError } = axios;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +14,7 @@ const { AxiosError } = axios;
|
|||
const instance = axios.create();
|
||||
|
||||
/* Default User-Agent */
|
||||
instance.defaults.headers.common['User-Agent'] = `node-${pkg.name}/${pkg.version}`;
|
||||
instance.defaults.headers.common['User-Agent'] = `@certd/acme-client`;
|
||||
|
||||
/* Default ACME settings */
|
||||
instance.defaults.acmeSettings = {
|
||||
|
@ -144,4 +142,4 @@ instance.interceptors.response.use(null, async (error) => {
|
|||
* Export instance
|
||||
*/
|
||||
|
||||
module.exports = instance;
|
||||
export default instance;
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
*
|
||||
* @namespace Client
|
||||
*/
|
||||
import { createHash } from 'crypto';
|
||||
import { getPemBodyAsB64u } from './crypto/index.js';
|
||||
import { log } from './logger.js';
|
||||
import HttpClient from './http.js';
|
||||
import AcmeApi from './api.js';
|
||||
import verify from './verify.js';
|
||||
import * as util from './util.js';
|
||||
import auto from './auto.js';
|
||||
import { CancelError } from './error.js';
|
||||
|
||||
|
||||
const { createHash } = require('crypto');
|
||||
const { getPemBodyAsB64u } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
const HttpClient = require('./http');
|
||||
const AcmeApi = require('./api');
|
||||
const verify = require('./verify');
|
||||
const util = require('./util');
|
||||
const auto = require('./auto');
|
||||
const { CancelError } = require('./error');
|
||||
|
||||
/**
|
||||
* ACME states
|
||||
|
@ -719,4 +720,4 @@ class AcmeClient {
|
|||
}
|
||||
|
||||
/* Export client */
|
||||
module.exports = AcmeClient;
|
||||
export default AcmeClient;
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
*
|
||||
* @namespace forge
|
||||
*/
|
||||
|
||||
const net = require('net');
|
||||
const { promisify } = require('util');
|
||||
const forge = require('node-forge');
|
||||
const { createPrivateEcdsaKey, getPublicKey } = require('./index');
|
||||
import net from 'net';
|
||||
import { promisify } from 'util';
|
||||
import forge from 'node-forge';
|
||||
import { createPrivateEcdsaKey } from './index.js';
|
||||
|
||||
const generateKeyPair = promisify(forge.pki.rsa.generateKeyPair);
|
||||
|
||||
|
@ -113,13 +112,12 @@ function parseDomains(obj) {
|
|||
* ```
|
||||
*/
|
||||
|
||||
async function createPrivateKey(size = 2048) {
|
||||
export async function createPrivateKey(size = 2048) {
|
||||
const keyPair = await generateKeyPair({ bits: size });
|
||||
const pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
||||
return Buffer.from(pemKey);
|
||||
}
|
||||
|
||||
exports.createPrivateKey = createPrivateKey;
|
||||
|
||||
/**
|
||||
* Create public key from a private RSA key
|
||||
|
@ -133,7 +131,7 @@ exports.createPrivateKey = createPrivateKey;
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.createPublicKey = async (key) => {
|
||||
export const createPublicKey = async (key) => {
|
||||
const privateKey = forge.pki.privateKeyFromPem(key);
|
||||
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
||||
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
||||
|
@ -148,7 +146,7 @@ exports.createPublicKey = async (key) => {
|
|||
* @returns {string} PEM body
|
||||
*/
|
||||
|
||||
exports.getPemBody = (str) => {
|
||||
export const getPemBody = (str) => {
|
||||
const msg = forge.pem.decode(str)[0];
|
||||
return forge.util.encode64(msg.body);
|
||||
};
|
||||
|
@ -160,7 +158,7 @@ exports.getPemBody = (str) => {
|
|||
* @returns {string[]} Array of PEM bodies
|
||||
*/
|
||||
|
||||
exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||
export const splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||
|
||||
/**
|
||||
* Get modulus
|
||||
|
@ -176,7 +174,7 @@ exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.getModulus = async (input) => {
|
||||
export const getModulus = async (input) => {
|
||||
if (!Buffer.isBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
|
@ -199,7 +197,7 @@ exports.getModulus = async (input) => {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.getPublicExponent = async (input) => {
|
||||
export const getPublicExponent = async (input) => {
|
||||
if (!Buffer.isBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ exports.getPublicExponent = async (input) => {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.readCsrDomains = async (csr) => {
|
||||
export const readCsrDomains = async (csr) => {
|
||||
if (!Buffer.isBuffer(csr)) {
|
||||
csr = Buffer.from(csr);
|
||||
}
|
||||
|
@ -251,7 +249,7 @@ exports.readCsrDomains = async (csr) => {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.readCertificateInfo = async (cert) => {
|
||||
export const readCertificateInfo = async (cert) => {
|
||||
if (!Buffer.isBuffer(cert)) {
|
||||
cert = Buffer.from(cert);
|
||||
}
|
||||
|
@ -379,7 +377,7 @@ function formatCsrAltNames(altNames) {
|
|||
* }, certificateKey);
|
||||
*/
|
||||
|
||||
exports.createCsr = async (data, keyType = null) => {
|
||||
export const createCsr = async (data, keyType = null) => {
|
||||
let key = null;
|
||||
if (keyType === 'ec') {
|
||||
key = await createPrivateEcdsaKey();
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
*
|
||||
* @namespace crypto
|
||||
*/
|
||||
import net from 'net';
|
||||
import { promisify } from 'util';
|
||||
import crypto from 'crypto';
|
||||
import asn1js from 'asn1js';
|
||||
import x509 from '@peculiar/x509';
|
||||
|
||||
const net = require('net');
|
||||
const { promisify } = require('util');
|
||||
const crypto = require('crypto');
|
||||
const asn1js = require('asn1js');
|
||||
const x509 = require('@peculiar/x509');
|
||||
|
||||
const randomInt = promisify(crypto.randomInt);
|
||||
const generateKeyPair = promisify(crypto.generateKeyPair);
|
||||
|
@ -67,7 +67,7 @@ function getKeyInfo(keyPem) {
|
|||
* ```
|
||||
*/
|
||||
|
||||
async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8') {
|
||||
export async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8') {
|
||||
const pair = await generateKeyPair('rsa', {
|
||||
modulusLength,
|
||||
privateKeyEncoding: {
|
||||
|
@ -79,7 +79,6 @@ async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8')
|
|||
return Buffer.from(pair.privateKey);
|
||||
}
|
||||
|
||||
exports.createPrivateRsaKey = createPrivateRsaKey;
|
||||
|
||||
/**
|
||||
* Alias of `createPrivateRsaKey()`
|
||||
|
@ -87,7 +86,7 @@ exports.createPrivateRsaKey = createPrivateRsaKey;
|
|||
* @function
|
||||
*/
|
||||
|
||||
exports.createPrivateKey = createPrivateRsaKey;
|
||||
export const createPrivateKey = createPrivateRsaKey;
|
||||
|
||||
/**
|
||||
* Generate a private ECDSA key
|
||||
|
@ -106,7 +105,7 @@ exports.createPrivateKey = createPrivateRsaKey;
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkcs8') => {
|
||||
export const createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkcs8') => {
|
||||
const pair = await generateKeyPair('ec', {
|
||||
namedCurve,
|
||||
privateKeyEncoding: {
|
||||
|
@ -130,7 +129,7 @@ exports.createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkc
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.getPublicKey = (keyPem) => {
|
||||
export const getPublicKey = (keyPem) => {
|
||||
const info = getKeyInfo(keyPem);
|
||||
|
||||
const publicKey = info.publicKey.export({
|
||||
|
@ -155,7 +154,7 @@ exports.getPublicKey = (keyPem) => {
|
|||
* ```
|
||||
*/
|
||||
|
||||
function getJwk(keyPem) {
|
||||
export function getJwk(keyPem) {
|
||||
const jwk = crypto.createPublicKey(keyPem).export({
|
||||
format: 'jwk',
|
||||
});
|
||||
|
@ -167,7 +166,6 @@ function getJwk(keyPem) {
|
|||
}, {});
|
||||
}
|
||||
|
||||
exports.getJwk = getJwk;
|
||||
|
||||
/**
|
||||
* Produce CryptoKeyPair and signing algorithm from a PEM encoded private key
|
||||
|
@ -215,7 +213,7 @@ async function getWebCryptoKeyPair(keyPem) {
|
|||
* @returns {string[]} Array of PEM objects including headers
|
||||
*/
|
||||
|
||||
function splitPemChain(chainPem) {
|
||||
export function splitPemChain(chainPem) {
|
||||
if (Buffer.isBuffer(chainPem)) {
|
||||
chainPem = chainPem.toString();
|
||||
}
|
||||
|
@ -225,7 +223,6 @@ function splitPemChain(chainPem) {
|
|||
.map((params) => x509.PemConverter.encode([params]));
|
||||
}
|
||||
|
||||
exports.splitPemChain = splitPemChain;
|
||||
|
||||
/**
|
||||
* Parse body of PEM encoded object and return a Base64URL string
|
||||
|
@ -235,7 +232,7 @@ exports.splitPemChain = splitPemChain;
|
|||
* @returns {string} Base64URL-encoded body
|
||||
*/
|
||||
|
||||
exports.getPemBodyAsB64u = (pem) => {
|
||||
export const getPemBodyAsB64u = (pem) => {
|
||||
const chain = splitPemChain(pem);
|
||||
|
||||
if (!chain.length) {
|
||||
|
@ -286,7 +283,7 @@ function parseDomains(input) {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.readCsrDomains = (csrPem) => {
|
||||
export const readCsrDomains = (csrPem) => {
|
||||
if (Buffer.isBuffer(csrPem)) {
|
||||
csrPem = csrPem.toString();
|
||||
}
|
||||
|
@ -315,7 +312,7 @@ exports.readCsrDomains = (csrPem) => {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.readCertificateInfo = (certPem) => {
|
||||
export const readCertificateInfo = (certPem) => {
|
||||
if (Buffer.isBuffer(certPem)) {
|
||||
certPem = certPem.toString();
|
||||
}
|
||||
|
@ -449,7 +446,7 @@ function createSubjectAltNameExtension(altNames) {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.createCsr = async (data, keyPem = null) => {
|
||||
export const createCsr = async (data, keyPem = null) => {
|
||||
if (!keyPem) {
|
||||
keyPem = await createPrivateRsaKey(data.keySize);
|
||||
}
|
||||
|
@ -520,7 +517,7 @@ exports.createCsr = async (data, keyPem = null) => {
|
|||
* ```
|
||||
*/
|
||||
|
||||
exports.createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) => {
|
||||
export const createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) => {
|
||||
if (!keyPem) {
|
||||
keyPem = await createPrivateRsaKey();
|
||||
}
|
||||
|
@ -583,7 +580,7 @@ exports.createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) =
|
|||
* @returns {boolean} True when valid
|
||||
*/
|
||||
|
||||
exports.isAlpnCertificateAuthorizationValid = (certPem, keyAuthorization) => {
|
||||
export const isAlpnCertificateAuthorizationValid = (certPem, keyAuthorization) => {
|
||||
const expected = crypto.createHash('sha256').update(keyAuthorization).digest('hex');
|
||||
|
||||
/* Attempt to locate ALPN extension */
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
class CancelError extends Error {
|
||||
export class CancelError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'CancelError';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CancelError,
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* ACME HTTP client
|
||||
*/
|
||||
|
||||
const { createHmac, createSign, constants: { RSA_PKCS1_PADDING } } = require('crypto');
|
||||
const { getJwk } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
const axios = require('./axios');
|
||||
import { createHmac, createSign, constants } from 'crypto';
|
||||
const { RSA_PKCS1_PADDING } = constants;
|
||||
import axios from './axios.js';
|
||||
import { log } from './logger.js';
|
||||
import { getJwk } from './crypto/index.js';
|
||||
|
||||
/**
|
||||
* ACME HTTP client
|
||||
|
@ -324,4 +324,4 @@ class HttpClient {
|
|||
}
|
||||
|
||||
/* Export client */
|
||||
module.exports = HttpClient;
|
||||
export default HttpClient;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/**
|
||||
* acme-client
|
||||
*/
|
||||
|
||||
exports.Client = require('./client');
|
||||
import AcmeClinet from './client.js'
|
||||
export const Client = AcmeClinet
|
||||
|
||||
/**
|
||||
* Directory URLs
|
||||
*/
|
||||
|
||||
exports.directory = {
|
||||
export const directory = {
|
||||
buypass: {
|
||||
staging: 'https://api.test4.buypass.no/acme/directory',
|
||||
production: 'https://api.buypass.com/acme/directory',
|
||||
|
@ -31,21 +31,19 @@ exports.directory = {
|
|||
* Crypto
|
||||
*/
|
||||
|
||||
exports.crypto = require('./crypto');
|
||||
exports.forge = require('./crypto/forge');
|
||||
export * as crypto from './crypto/index.js'
|
||||
export * from './crypto/forge.js'
|
||||
|
||||
/**
|
||||
* Axios
|
||||
*/
|
||||
|
||||
exports.axios = require('./axios');
|
||||
exports.agents = require('./agents');
|
||||
|
||||
export * from './axios.js'
|
||||
export * as agents from './agents.js'
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
|
||||
exports.setLogger = require('./logger').setLogger;
|
||||
|
||||
exports.walkTxtRecord = require('./verify').walkTxtRecord;
|
||||
exports.CancelError = require('./error').CancelError;
|
||||
export * from './logger.js'
|
||||
export * from './verify.js'
|
||||
export * from './error.js'
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
* ACME logger
|
||||
*/
|
||||
|
||||
const debug = require('debug')('acme-client');
|
||||
import debugg from 'debug'
|
||||
const debug = debugg('acme-client');
|
||||
|
||||
let logger = () => {};
|
||||
|
||||
|
@ -12,7 +13,7 @@ let logger = () => {};
|
|||
* @param {function} fn Logger function
|
||||
*/
|
||||
|
||||
exports.setLogger = (fn) => {
|
||||
export const setLogger = (fn) => {
|
||||
logger = fn;
|
||||
};
|
||||
|
||||
|
@ -22,7 +23,7 @@ exports.setLogger = (fn) => {
|
|||
* @param {string} msg Message
|
||||
*/
|
||||
|
||||
exports.log = (...msg) => {
|
||||
export const log = (...msg) => {
|
||||
debug(...msg);
|
||||
logger(...msg);
|
||||
};
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
* Utility methods
|
||||
*/
|
||||
|
||||
const tls = require('tls');
|
||||
const dns = require('dns').promises;
|
||||
const { readCertificateInfo, splitPemChain } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
import tls from 'tls';
|
||||
import dnsSdk from 'dns';
|
||||
import { readCertificateInfo, splitPemChain }from './crypto/index.js'
|
||||
import { log } from './logger.js'
|
||||
|
||||
const dns = dnsSdk.promises;
|
||||
/**
|
||||
* Exponential backoff
|
||||
*
|
||||
|
@ -329,7 +330,7 @@ async function retrieveTlsAlpnCertificate(host, port, timeout = 30000) {
|
|||
* Export utils
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
retry,
|
||||
parseLinkHeader,
|
||||
parseRetryAfterHeader,
|
||||
|
@ -338,3 +339,4 @@ module.exports = {
|
|||
getAuthoritativeDnsResolver,
|
||||
retrieveTlsAlpnCertificate,
|
||||
};
|
||||
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
* ACME challenge verification
|
||||
*/
|
||||
|
||||
const dns = require('dns').promises;
|
||||
const https = require('https');
|
||||
const { log } = require('./logger');
|
||||
const axios = require('./axios');
|
||||
const util = require('./util');
|
||||
const { isAlpnCertificateAuthorizationValid } = require('./crypto');
|
||||
import dnsSdk from "dns"
|
||||
import https from 'https'
|
||||
import {log} from './logger.js'
|
||||
import axios from './axios.js'
|
||||
import * as util from './util.js'
|
||||
import {isAlpnCertificateAuthorizationValid} from './crypto/index.js'
|
||||
|
||||
|
||||
const dns = dnsSdk.promises
|
||||
/**
|
||||
* Verify ACME HTTP challenge
|
||||
*
|
||||
|
@ -79,7 +81,7 @@ async function walkDnsChallengeRecord(recordName, resolver = dns) {
|
|||
}
|
||||
}
|
||||
|
||||
async function walkTxtRecord(recordName) {
|
||||
export async function walkTxtRecord(recordName) {
|
||||
try {
|
||||
/* Default DNS resolver first */
|
||||
log('Attempting to resolve TXT with default DNS resolver first');
|
||||
|
@ -153,9 +155,8 @@ async function verifyTlsAlpnChallenge(authz, challenge, keyAuthorization) {
|
|||
* Export API
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
'http-01': verifyHttpChallenge,
|
||||
'dns-01': verifyDnsChallenge,
|
||||
'tls-alpn-01': verifyTlsAlpnChallenge,
|
||||
walkTxtRecord,
|
||||
};
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
async function wait(ms) {
|
||||
export async function wait(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
wait,
|
||||
};
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"compileOnSave": true,
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"strict": true,
|
||||
"noEmit": false,
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": ".",
|
||||
"composite": false,
|
||||
"paths": { "acme-client": ["."] }
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"version": "1.27.2",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"version": "1.27.2",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"description": "midway with flyway, sql upgrade way ",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"module": "./dist/index.js",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue