smartacme/dist/smartacme.classes.smartacme.js

101 lines
6.1 KiB
JavaScript

"use strict";
require("typings-global");
const q = require("q");
let ACME = require('le-acme-core').ACME.create();
let RSA = require('rsa-compat').RSA;
let bitlen = 1024;
let exp = 65537;
let options = {
public: true,
pem: true,
internal: true
};
/**
* class SmartAcme exports methods for maintaining SSL Certificates
*/
class SmartAcme {
constructor(productionArg = false) {
this.preparedBool = false;
this.productionBool = productionArg;
}
/**
* prepares the SmartAcme class
*/
prepareAcme() {
let done = q.defer();
if (this.preparedBool === false) {
this.getAcmeUrls()
.then(() => {
return this.createKeyPair();
})
.then((x) => {
console.log('prepared smartacme instance');
done.resolve();
});
}
else {
done.resolve();
}
return done.promise;
}
/**
* creates an account if not currently present in module
*/
createAccount() {
let done = q.defer();
this.prepareAcme()
.then(() => {
let options = {
newRegUrl: this.acmeUrls.newReg,
email: 'domains@lossless.org',
accountKeypair: {
privateKeyPem: this.keyPair
},
agreeToTerms: function (tosUrl, done) {
done(null, tosUrl);
}
};
ACME.registerNewAccount(options, (err, regr) => {
if (err) {
console.log(err);
done.reject(err);
}
done.resolve(regr);
});
}).catch(err => { console.log(err); });
return done.promise;
}
/**
* creates a keyPair
*/
createKeyPair() {
let done = q.defer();
RSA.generateKeypair(bitlen, exp, options, (err, keypair) => {
if (err) {
console.log(err);
done.reject(err);
}
console.log(keypair);
this.keyPair = keypair;
});
done.resolve();
return done.promise;
}
/**
* gets the Acme Urls
*/
getAcmeUrls() {
let done = q.defer();
ACME.getAcmeUrls(ACME.stagingServerUrl, (err, urls) => {
if (err) {
throw err;
}
this.acmeUrls = urls;
console.log(this.acmeUrls);
done.resolve();
});
return done.promise;
}
}
exports.SmartAcme = SmartAcme;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZX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