Files
memind_adm/server/argon2-polyfill.mjs
John 7a5b9cc912 Add argon2 polyfill and unified preview/API startup for admin login.
Node < 24 lacks crypto.argon2Sync; wire @node-rs/argon2 fallback and start Admin API alongside vite preview in local and remote deploy flows.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-17 16:38:58 -07:00

24 lines
802 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import crypto from 'node:crypto';
import { Algorithm, hashRawSync } from '@node-rs/argon2';
/** Node < 24 无 crypto.argon2SyncMemind user-auth 登录会崩溃。 */
export function ensureArgon2Sync() {
if (typeof crypto.argon2Sync === 'function') return;
crypto.argon2Sync = (algorithm, options = {}) => {
if (algorithm !== 'argon2id') {
throw new Error(`unsupported argon2 algorithm: ${algorithm}`);
}
const message = options.message ?? '';
const nonce = options.nonce ?? Buffer.alloc(0);
return hashRawSync(String(message), {
algorithm: Algorithm.Argon2id,
salt: nonce,
parallelism: options.parallelism ?? 1,
outputLen: options.tagLength ?? 32,
memoryCost: options.memory ?? 65536,
timeCost: options.passes ?? 3,
});
};
}