totp.test.js 717 Bytes
/**
 * Created by lintry on 2017/5/19.
 */

const TOTP = require('../lib/totp');
const chalk = require('chalk');
const fs = require('fs-extra');

//根据第二个参数算法创建密钥,默认sha512
let algorithm = process.argv[2] || 'sha512';
let totp = new TOTP({algorithm: algorithm});

let secret = totp.createSecret();
console.log(chalk.cyan('创建totp的secret'));
console.log(secret);

console.log(chalk.magenta('secret'), secret);

let authenticator = totp.parse(secret);

console.log(authenticator.totp_options);

//根据实际生成token
let token = authenticator.totp();
console.log(chalk.green('token is'), token);
//验证token
console.log(chalk.magenta('verify is '), authenticator.verify(token));