smartacme/ts/smartacme.helpers.ts

44 lines
1.1 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
}
}
/**
* 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
}