mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-30 14:57:59 +00:00
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.
39 lines
1.0 KiB
TypeScript
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,
|
|
};
|
|
};
|