smartacme/ts/smartacme.helpers.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-01-14 13:14:50 +00:00
import 'typings-global'
2017-04-28 16:56:55 +00:00
import * as q from 'smartq'
2017-01-14 13:14:50 +00:00
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 => {
2017-04-28 16:56:55 +00:00
let result = plugins.rsaKeygen.generate(bit)
return {
publicKey: result.public_key,
privateKey: result.private_key
}
2017-01-14 13:14:50 +00:00
}
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 => {
2017-04-28 16:56:55 +00:00
return '_acme-challenge.' + domainNameArg
2017-01-15 21:30:33 +00:00
}
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-04-28 16:56:55 +00:00
let done = q.defer()
let body = { resource: 'reg' }
SmartAcmeArg.rawacmeClient.post(
location,
body,
SmartAcmeArg.keyPair,
(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
2017-01-14 13:14:50 +00:00
}