namespace _aum.helpers { /** */ /* export function yaml_encode( thing : any ) : string { } */ /** * @todo outsource */ export async function bcrypt_compute( input : string, options : { rounds ?: int; } = {} ) : Promise { options = Object.assign( { "rounds": 12, }, options ); const nm_bcrypt = require("bcrypt"); const salt : string = await nm_bcrypt.genSalt(options.rounds) const result : string = await nm_bcrypt.hash(input, salt); return result; } /** * @todo outsource */ export async function bcrypt_compare( password_shall_image : string, password_is : string ) : Promise { const nm_bcrypt = require("bcrypt"); const result = await nm_bcrypt.compare(password_is, password_shall_image); return result; } /** */ export function database_implementation( ) : lib_plankton.database.type_database { return lib_plankton.database.sqlite_database( { "path": _aum.conf.get().database_path, "verbose": false, } ); } /** */ export async function verification_get( data : any ) : Promise { return lib_plankton.sha256.get( lib_plankton.json.encode(data), _aum.conf.get().verification_secret ); } /** */ export async function verification_check( data : any, verification : string ) : Promise { const verification_expected : string = lib_plankton.sha256.get( lib_plankton.json.encode(data), _aum.conf.get().verification_secret ); return (verification === verification_expected); } /** */ export async function email_send( receivers : Array, subject : string, content : string ) : Promise { const mode : string = _aum.conf.get().email.mode; lib_plankton.log.info( "email_send", { "mode": mode, "receivers": receivers, "subject": subject, } ); switch (mode) { case "regular": { // TODO break; } case "redirect": { // TODO break; } case "console": { lib_plankton.log.info( "email_send_content", { "content": content, } ); break; } case "drop": { // do nothing break; } default: { throw (new Error("unhandled email mode: " + mode)); break; } } } }