This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function generateOneTimePassword(rawKey: Uint8Array, counter: number): Promise<number> { | |
const data = new DataView(new ArrayBuffer(8)); | |
data.setBigUint64(0, BigInt(Math.floor(counter)), false); | |
const algo = { name: 'HMAC', hash: 'SHA-1' }; | |
const key = await crypto.subtle.importKey('raw', rawKey, algo, false, ['sign']); | |
const hmacHash = new Uint8Array(await crypto.subtle.sign(algo, key, data.buffer)); | |
const offset = hmacHash[hmacHash.byteLength - 1] & 0x0f; | |
const hotp = (hmacHash[offset] & 0x7f) << 24 |