Files
esign/packages/lib/server-only/2fa/email/generate-2fa-credentials-from-email.ts
zeekay d2144b647e rebrand: Documenso → Hanzo eSign across user-facing surfaces
Mechanical brand swap across user-visible strings only. Internal package
identifiers (@hanzo/sign-*), database column names, and upstream npm package
names are unchanged so existing installs and APIs keep working.

- 'Hanzo Sign' → 'Hanzo eSign' in README, docs, marketing pages, email
  copy, UI strings, page titles, meta tags, alt text.
- sign.hanzo.ai → esign.hanzo.ai on every marketing link, FROM_ADDRESS
  fallback ([email protected]), support email, OAuth callback hosts,
  documentation domain, OG image URL.
- github.com/hanzoai/sign → github.com/hanzoai/esign in README badges,
  CONTRIBUTING, docs, deploy workflow, openpage-api github proxy routes.
2026-06-07 12:15:29 -07:00

39 lines
1.0 KiB
TypeScript

import { hmac } from '@noble/hashes/hmac';
import { sha256 } from '@noble/hashes/sha256';
import { createTOTPKeyURI } from 'oslo/otp';
import { SIGN_ENCRYPTION_KEY } from '../../../constants/crypto';
const ISSUER = `${process.env.NEXT_PUBLIC_APP_NAME || 'Hanzo eSign'} Email 2FA`;
export type GenerateTwoFactorCredentialsFromEmailOptions = {
envelopeId: string;
email: string;
};
/**
* Generate an encrypted token containing a 6-digit 2FA code for email verification.
*
* @param options - The options for generating the token
* @returns Object containing the token and the 6-digit code
*/
export const generateTwoFactorCredentialsFromEmail = ({
envelopeId,
email,
}: GenerateTwoFactorCredentialsFromEmailOptions) => {
if (!SIGN_ENCRYPTION_KEY) {
throw new Error('Missing SIGN_ENCRYPTION_KEY');
}
const identity = `email-2fa|v1|email:${email}|id:${envelopeId}`;
const secret = hmac(sha256, SIGN_ENCRYPTION_KEY, identity);
const uri = createTOTPKeyURI(ISSUER, email, secret.buffer as ArrayBuffer);
return {
uri,
secret,
};
};