smartacme/dist/smartacme.classes.smartacme.js

60 lines
4.0 KiB
JavaScript
Raw Normal View History

2016-11-01 17:27:57 +00:00
"use strict";
2016-11-11 13:17:50 +00:00
require("typings-global");
const q = require("q");
let rsaKeygen = require('rsa-keygen');
let rawacme = require('rawacme');
const smartacme_classes_helper_1 = require("./smartacme.classes.helper");
2016-11-11 13:17:50 +00:00
/**
* class SmartAcme exports methods for maintaining SSL Certificates
*/
2016-11-01 17:27:57 +00:00
class SmartAcme {
2016-11-07 17:41:52 +00:00
/**
* the constructor for class SmartAcme
2016-11-11 13:17:50 +00:00
*/
constructor(productionArg = false) {
this.productionBool = productionArg;
this.helper = new smartacme_classes_helper_1.SmartacmeHelper();
this.keyPair = this.helper.createKeypair();
if (this.productionBool) {
this.acmeUrl = rawacme.LETSENCRYPT_STAGING_URL;
2016-11-11 13:17:50 +00:00
}
else {
this.acmeUrl = rawacme.LETSENCRYPT_URL;
2016-11-11 13:17:50 +00:00
}
}
/**
* creates an account if not currently present in module
* @executes ASYNC
2016-11-07 17:41:52 +00:00
*/
2016-11-01 19:16:43 +00:00
createAccount() {
2016-11-11 13:17:50 +00:00
let done = q.defer();
rawacme.createClient({
url: this.acmeUrl,
publicKey: this.keyPair.publicKey,
privateKey: this.keyPair.privateKey
}, (err, client) => {
if (err) {
console.error('smartacme: something went wrong:');
console.log(err);
done.reject(err);
return;
}
client.newReg({
contact: ['mailto:domains@lossless.org']
}, (err, res) => {
2016-11-11 13:17:50 +00:00
if (err) {
console.error('smartacme: something went wrong:');
2016-11-11 13:17:50 +00:00
console.log(err);
done.reject(err);
return;
2016-11-11 13:17:50 +00:00
}
this.JWK = res.body.key;
console.log(this.JWK);
done.resolve();
2016-11-17 12:32:16 +00:00
});
2016-11-11 13:17:50 +00:00
});
return done.promise;
2016-11-07 17:41:52 +00:00
}
2016-11-01 17:27:57 +00:00
}
exports.SmartAcme = SmartAcme;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic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