mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
Cast Buffer/Uint8Array to appropriate types for TS 5.9 stricter ArrayBuffer type checking.
24 lines
632 B
TypeScript
24 lines
632 B
TypeScript
import { generateHOTP } from 'oslo/otp';
|
|
|
|
import { generateTwoFactorCredentialsFromEmail } from './generate-2fa-credentials-from-email';
|
|
|
|
export type GenerateTwoFactorTokenFromEmailOptions = {
|
|
envelopeId: string;
|
|
email: string;
|
|
period?: number;
|
|
};
|
|
|
|
export const generateTwoFactorTokenFromEmail = async ({
|
|
email,
|
|
envelopeId,
|
|
period = 30_000,
|
|
}: GenerateTwoFactorTokenFromEmailOptions) => {
|
|
const { secret } = generateTwoFactorCredentialsFromEmail({ email, envelopeId });
|
|
|
|
const counter = Math.floor(Date.now() / period);
|
|
|
|
const token = await generateHOTP(secret.buffer as ArrayBuffer, counter);
|
|
|
|
return token;
|
|
};
|