From f6a049d92a3caa42119e8fc18e080dd18eac503e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 15 Dec 2015 12:42:56 +0000 Subject: [PATCH] better state management --- lib/client.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/client.js b/lib/client.js index f86bfff..6c99fa5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -104,6 +104,11 @@ Acme.prototype.post=function(url, body, cb) { function registerNewAccount(state, options, cb) { + var state = {}; + + if (!options.accountPrivateKeyPem) { + return handleErr(new Error("options.accountPrivateKeyPem must be an ascii private key pem")); + } if (!options.agreeToTerms) { cb(new Error("options.agreeToTerms must be function (tosUrl, fn => (err, true))")); return; @@ -117,6 +122,10 @@ function registerNewAccount(state, options, cb) { return; } + state.accountKeyPem=options.accountPrivateKeyPem; + state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM); + state.acme=new Acme(state.accountKeyPair); + register(); function register() { @@ -216,7 +225,11 @@ function getCert(options, cb) { if (!options.removeChallenge) { return handleErr(new Error("options.removeChallenge must be function(hostname, challengeKey, done) {}")); } + if (!(options.domains && options.domains.length)) { + return handleErr(new Error("options.domains must be an array of domains such as ['example.com', 'www.example.com']")); + } + state.domains = options.domains.slice(0); // copy array try { state.accountKeyPem=options.accountPrivateKeyPem; state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM);