mirror of
https://github.com/certd/certd.git
synced 2026-07-21 18:37:33 +08:00
refactor(acme-client): 将acme-client改造成ts包并优化项目结构
重构acme-client模块,将原有JavaScript代码迁移至TypeScript 添加类型定义文件(.d.ts)和类型检查 更新构建配置和脚本以支持TypeScript编译 优化项目目录结构和模块导出方式 更新相关依赖和开发工具配置
This commit is contained in:
+5
-4
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* Legacy node-forge crypto interface
|
||||
*
|
||||
@@ -112,7 +113,7 @@ function parseDomains(obj) {
|
||||
* ```
|
||||
*/
|
||||
|
||||
export async function createPrivateKey(size = 2048) {
|
||||
export async function createPrivateKey(size = 2048): Promise<Buffer> {
|
||||
const keyPair = await generateKeyPair({ bits: size });
|
||||
const pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
||||
return Buffer.from(pemKey);
|
||||
@@ -131,7 +132,7 @@ export async function createPrivateKey(size = 2048) {
|
||||
* ```
|
||||
*/
|
||||
|
||||
export const createPublicKey = async (key) => {
|
||||
export const createPublicKey = async (key): Promise<Buffer> => {
|
||||
const privateKey = forge.pki.privateKeyFromPem(key);
|
||||
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
||||
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
||||
@@ -174,7 +175,7 @@ export const splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode
|
||||
* ```
|
||||
*/
|
||||
|
||||
export const getModulus = async (input) => {
|
||||
export const getModulus = async (input): Promise<Buffer> => {
|
||||
if (!Buffer.isBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
@@ -197,7 +198,7 @@ export const getModulus = async (input) => {
|
||||
* ```
|
||||
*/
|
||||
|
||||
export const getPublicExponent = async (input) => {
|
||||
export const getPublicExponent = async (input): Promise<Buffer> => {
|
||||
if (!Buffer.isBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
+4
-3
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* Native Node.js crypto interface
|
||||
*
|
||||
@@ -67,7 +68,7 @@ function getKeyInfo(keyPem) {
|
||||
* ```
|
||||
*/
|
||||
|
||||
export async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8') {
|
||||
export async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8'): Promise<Buffer> {
|
||||
const pair = await generateKeyPair('rsa', {
|
||||
modulusLength,
|
||||
privateKeyEncoding: {
|
||||
@@ -105,7 +106,7 @@ export const createPrivateKey = createPrivateRsaKey;
|
||||
* ```
|
||||
*/
|
||||
|
||||
export const createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkcs8') => {
|
||||
export const createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkcs8'): Promise<Buffer> => {
|
||||
const pair = await generateKeyPair('ec', {
|
||||
namedCurve,
|
||||
privateKeyEncoding: {
|
||||
@@ -129,7 +130,7 @@ export const createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType =
|
||||
* ```
|
||||
*/
|
||||
|
||||
export const getPublicKey = (keyPem) => {
|
||||
export const getPublicKey = (keyPem): Buffer => {
|
||||
const info = getKeyInfo(keyPem);
|
||||
|
||||
const publicKey = info.publicKey.export({
|
||||
Reference in New Issue
Block a user