smartacme/ts/smartacme.helpers.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-01-14 13:14:50 +00:00
import 'typings-global'
import * as q from 'q'
import * as plugins from './smartacme.plugins'
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
2017-01-14 17:36:33 +00:00
import { AcmeAccount } from './smartacme.classes.acmeaccount'
2017-01-14 13:14:50 +00:00
/**
* creates a keypair to use with requests and to generate JWK from
*/
export let createKeypair = (bit = 2048): IRsaKeypair => {
let result = plugins.rsaKeygen.generate(bit)
return {
publicKey: result.public_key,
privateKey: result.private_key
}
}
2017-01-15 21:30:33 +00:00
/**
* prefix a domain name to make sure it complies with letsencrypt
*/
export let prefixName = (domainNameArg: string): string => {
return '_acme-challenge.' + domainNameArg
}
2017-01-14 13:14:50 +00:00
/**
* gets an existing registration
* @executes ASYNC
*/
2017-01-14 17:36:33 +00:00
let getReg = (SmartAcmeArg: SmartAcme, location: string) => {
2017-01-14 13:14:50 +00:00
let done = q.defer()
let body = { resource: 'reg' }
2017-01-14 17:36:33 +00:00
SmartAcmeArg.rawacmeClient.post(
location,
body,
SmartAcmeArg.keyPair,
2017-01-14 13:14:50 +00:00
(err, res) => {
if (err) {
console.error('smartacme: something went wrong:')
console.log(err)
done.reject(err)
return
}
console.log(JSON.stringify(res.body))
done.resolve()
}
)
return done.promise
}