Skip to content

Commit

Permalink
fix lowercase keys
Browse files Browse the repository at this point in the history
  • Loading branch information
7heMech authored and bellstrand committed Jul 8, 2024
1 parent c38623d commit 139f25d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ describe("totp generation", () => {
beforeEach(() => jest.useFakeTimers())
afterEach(() => jest.resetAllMocks())

test("should generate token with lowercase key characters", async () => {
jest.setSystemTime(0)
await expect(TOTP.generate("jbswY3dpehpk3pxp")).resolves.toEqual(expect.objectContaining({ otp: "282760" }))
})

test("should generate token with date now = 1971", async () => {
jest.setSystemTime(0)
await expect(TOTP.generate("JBSWY3DPEHPK3PXP")).resolves.toEqual(expect.objectContaining({ otp: "282760" }))
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class TOTP {
* @returns {ArrayBuffer} The ArrayBuffer representation of the base32 encoded string.
*/
private static base32ToBuffer(str: string): ArrayBuffer {
str = str.toUpperCase()
let length = str.length
while (str.charCodeAt(length - 1) === 61) length-- // Remove pads

Expand Down

0 comments on commit 139f25d

Please sign in to comment.