diff --git a/src/hotp.js b/src/hotp.js index 0e18e79..3761ee7 100644 --- a/src/hotp.js +++ b/src/hotp.js @@ -22,7 +22,8 @@ export class HOTP extends OTP { * ``` */ at(count) { - return "HOTP.at"; + let digit = super.generate_otp(count); + return digit; } /** @@ -47,6 +48,12 @@ export class HOTP extends OTP { * ``` */ verify(otp, counter) { - return "HOTP.verify"; + let otp_count = this.at(counter); + + if (otp === otp_count) { + return true; + } else { + return false; + } } } \ No newline at end of file diff --git a/test/hotp_test.js b/test/hotp_test.js index 2965ff8..8b5a18c 100644 --- a/test/hotp_test.js +++ b/test/hotp_test.js @@ -4,17 +4,18 @@ var assert = require('assert'); describe('HOTP module test', function() { var HOTP = hotp.HOTP; - var a = new HOTP("BASE32_ENCODED_SECRET"); + var a = new HOTP("J22U6B3WIWRRBTAV"); describe('at() function', function() { - it("should print 'HOTP.at'", function() { - assert.equal("HOTP.at", a.at()); + it("should return string", function() { + assert.equal("string", typeof(a.at(0))); }); }); describe('verify() function', function() { - it("should print 'HOTP.verify'", function() { - assert.equal("HOTP.verify", a.verify()); + it("should verify the digit", function() { + assert.equal(true, a.verify(a.at(0), 0)); + assert.equal(false, a.verify(a.at(0), 1)); }) }) }); diff --git a/test/totp_test.js b/test/totp_test.js index 253af40..9541ef5 100644 --- a/test/totp_test.js +++ b/test/totp_test.js @@ -13,7 +13,7 @@ describe('TOTP module test', function() { }); describe('verify() function', function() { - it("should print 'TOTP.verify'", function() { + it("should verify the digit", function() { assert.equal(true, a.verify(a.now())); }) })