Skip to content

refactor(wallet-cli): Wrap daemon password/SRP in opaque Password/Srp types#8863

Draft
sirtimid wants to merge 1 commit into
rekm/wallet-clifrom
sirtimid/wallet-cli-branded-password-srp
Draft

refactor(wallet-cli): Wrap daemon password/SRP in opaque Password/Srp types#8863
sirtimid wants to merge 1 commit into
rekm/wallet-clifrom
sirtimid/wallet-cli-branded-password-srp

Conversation

@sirtimid
Copy link
Copy Markdown

Summary

  • Introduce Password and Srp opaque class wrappers in packages/wallet-cli/src/daemon/secrets.ts. Both redact themselves under util.inspect, JSON.stringify, toString, and template-literal interpolation; the raw string is reachable only via unwrap().
  • Thread the new types through DaemonSpawnConfig, daemon start flag parsing, MM_WALLET_PASSWORD / MM_WALLET_SRP env reads in daemon-entry, and createWallet. unwrap() is called only at trust boundaries: the importSecretRecoveryPhrase call site in wallet-factory.ts and the child-process env-var assignment in daemon-spawn.ts.
  • Srp.from validates word count (12/15/18/21/24) and every word against the BIP-39 English wordlist, so typos fail fast at the CLI boundary instead of producing a malformed mnemonic inside the keyring.
  • Password.from matches the @metamask/keyring-controller convention: non-empty only, no minimum length.
  • @metamask/wallet's importSecretRecoveryPhrase signature stays on string — branding is scoped to wallet-cli, where the leak risk lives.

Closes #8778.

Test plan

  • yarn workspace @metamask/wallet-cli run test — 234 tests pass, 100% coverage on secrets.ts and all touched files
  • New secrets.test.ts covers validation, redaction (inspect, JSON, String, template literal), and unwrap round-trip
  • yarn lint:eslint packages/wallet-cli, yarn constraints, yarn lint:dependencies, yarn workspace @metamask/wallet-cli run changelog:validate all clean

🤖 Generated with Claude Code

… types

Daemon password and secret recovery phrase are now opaque class wrappers
that redact themselves under util.inspect, JSON.stringify, toString, and
template-literal interpolation. The underlying string is reachable only
via unwrap() at trust boundaries (the importSecretRecoveryPhrase call
site in wallet-factory and the child-process env-var spawn in
daemon-spawn). Srp.from validates word count (12/15/18/21/24) and every
word against the BIP-39 English wordlist, surfacing typos at the CLI
boundary instead of producing a malformed mnemonic downstream.

Closes #8778.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant