import hash = require('object-hash');
import jwt = require('jsonwebtoken');

export const md5 = (text: string) => hash(text, { algorithm: 'md5' });

/**
 * 加密payload生成token
 */
export const createToken = (payload: any): string =>
  jwt.sign({ ...payload }, 'mozzie');

/**
 * 解 token payload
 */
export const decodeToken = (token: string): any => jwt.verify(token, 'mozzie');
