2019-05-08 23:01:23 +00:00
|
|
|
const pathHelper = require("../pathHelper");
|
|
|
|
const fileNames = require("../fileNames");
|
2019-05-08 16:12:22 +00:00
|
|
|
|
|
|
|
module.exports.checkKeypair = (opts, options, s3) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
let id = opts.account.id || opts.email || "single-user";
|
|
|
|
console.log("accounts.checkKeypair for", id);
|
2019-05-08 16:12:22 +00:00
|
|
|
|
2019-05-08 23:01:23 +00:00
|
|
|
let key = pathHelper.accountsPath(options, id);
|
2019-05-08 16:12:22 +00:00
|
|
|
|
|
|
|
return s3.getObject({ Key: key, Bucket: options.bucketName }).promise().then((data) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.log("Successfully retrieved account keypair.");
|
|
|
|
let keypair = JSON.parse(data.Body.toString());
|
2019-05-08 16:12:22 +00:00
|
|
|
return {
|
|
|
|
privateKeyPem: keypair.privateKeyPem // string PEM private key
|
|
|
|
, privateKeyJwk: keypair.privateKeyJwk // object JWK private key
|
|
|
|
};
|
|
|
|
}).catch((err) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.error("There was an error retrieving your account keypair:", err.message);
|
2019-05-08 16:12:22 +00:00
|
|
|
return null;
|
|
|
|
});
|
2019-05-08 23:12:15 +00:00
|
|
|
};
|