DefinitelyTyped/types/notp/notp-tests.ts
Wilfred Tan 1f2dadb728 @types/notp { New type definition } (#37650)
* [@types/notp]
Initial commit

* [@types/notp]
Code revision and filling up test case

* [@types/notp]
+ Added missing optional 'window' to 'TOTPVerifyOpt'.
# Shortened the names for the interfaces (final)
# Minor edits to comments
2019-08-19 10:25:29 -07:00

26 lines
708 B
TypeScript

import * as notp from 'notp';
const genOpt: notp.HOTPGenOpt = {
counter: 0
};
const key: Buffer = Buffer.from("@DuMmy K3y!");
const token: string = notp.hotp.gen(key, genOpt);
const verifyOpt: notp.HOTPVerifyOpt = {};
const result = notp.hotp.verify(token, key, verifyOpt);
if (result) {
const resultCopy: notp.VerifyResult = result;
console.log(`result is ${resultCopy} with delta ${resultCopy.delta}.`);
} else {
const resultCopy: null = result;
console.log(`result is ${resultCopy}.`);
}
const token2: string = notp.totp.gen(key);
const opt: notp.TOTPVerifyOpt = {
window: 1
};
const result2 = notp.totp.verify(token2, key, opt);
console.log("final result: ", result2 ? result2 : result);