Add regex fallback for WASM isValidAccountName failures

Related: #758 See also: wax#140

Problem

WASM memory corruption under concurrent load:

WaxError: RuntimeError: memory access out of bounds
    at nn.isValidAccountName

Solution (TEMPORARY WORKAROUND)

Keep wax as primary validation, add regex fallback when WASM fails:

try {
  const chain = await getChain();
  return chain.isValidAccountName(accountName);
} catch (error) {
  logger.warn({ err: error, accountName }, 'WASM isValidAccountName failed, using regex fallback');
  return isUsernameValidRegex(accountName);
}

This is intentionally a temporary fix until wax thread-safety is resolved (wax#140).

What this does

  • Tries wax WASM validation first (preserves intended behavior)
  • On WASM error, logs warning and falls back to regex
  • Logging helps track how often the issue occurs
  • Well-documented with TODO markers and issue references

Easy to revert

Once wax#140 is fixed, simply:

  1. Remove the try/catch wrapper
  2. Remove the isUsernameValidRegex function
  3. Remove the logger import if unused

Regex validation rules (matches Hive consensus)

  • 3-16 characters
  • Lowercase letters, numbers, dots, hyphens only
  • Must start with a letter
  • Cannot end with hyphen or dot
  • Each segment must start with a letter
  • No consecutive dots or hyphens

Test plan

  • Deploy and verify errors stop (fallback kicks in)
  • Check logs for "WASM isValidAccountName failed" warnings
  • Valid usernames work: gtg, alice.bob, test-user
  • Invalid usernames rejected: 123test, test-, ab
Edited by gandalf_automation

Merge request reports

Loading