Skip to content

Fall back to a portable scrypt when node:crypto has none - #1

Closed
Whamp wants to merge 1 commit into
plannotator:mainfrom
Whamp:upstream-password-fallback
Closed

Whamp wants to merge 1 commit into
plannotator:mainfrom
Whamp:upstream-password-fallback

Conversation

@Whamp

@Whamp Whamp commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

On a runtime that matches Better Auth's workerd export condition but has no node:crypto scrypt, creating an account fails: Better Auth's password hash throws ERR_METHOD_NOT_IMPLEMENTED and sign-up answers 503. celld, Deno's self-hosted Workers runtime, is one such runtime (denoland/celld#326).

TalkTo now passes Better Auth its own password functions (apps/server/src/better-auth-password.ts). They call Better Auth's built-in scrypt and, after the first ERR_METHOD_NOT_IMPLEMENTED, switch that isolate to @noble/hashes scrypt with the same parameters and salt:key format. Other errors are thrown as before. On Cloudflare nothing changes.

Tests (apps/server/test/better-auth-password.test.mjs), with Better Auth's own Node build as the oracle:

  • a portable hash verifies with Better Auth's native verify, and the reverse;
  • the default functions hash and verify with the runtime's scrypt;
  • after a refusal the portable hash is used, and the native side is asked only once;
  • any other native failure is still thrown.

pnpm lint, pnpm format:check, pnpm typecheck pass. With this change and #2's together, pnpm test passed in full (536 server tests). I also ran it on celld 0.6.3: an account was created and agents signed in over MCP.

🤖 Generated with Claude Code

Better Auth picks its node:crypto scrypt build through the workerd and
node export conditions. A runtime that matches those conditions but has
no scrypt, such as celld (Deno's self-hosted Workers runtime), throws
ERR_METHOD_NOT_IMPLEMENTED, so creating an account failed.

TalkTo now passes Better Auth its own password functions. They use the
built-in scrypt and switch to @noble/hashes scrypt, with the same
parameters and salt:key format, after the first such refusal. Hashes
from either side verify on the other.

Co-Authored-By: Claude <noreply@anthropic.com>
@backnotprop

Copy link
Copy Markdown
Contributor

Thanks, Will! This is in: 3a4c464 on main, credited to you in the commit message.

One addition: the first time the fallback takes over, it now logs a single warning, so operators can see which scrypt is hashing their passwords. Everything else is your code as written.

We don't merge PRs into this repo directly, because it's published from our main source, so I'm closing this one. Your celld PR is next: I'm pushing a few fixes to its branch and will merge it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants