Skip to content

Thread mnemonic password through wallet SDK#132

Merged
zy0n merged 5 commits into
mainfrom
zy0n/mnemonic-password-creation-flow
Jun 19, 2026
Merged

Thread mnemonic password through wallet SDK#132
zy0n merged 5 commits into
mainfrom
zy0n/mnemonic-password-creation-flow

Conversation

@zy0n

@zy0n zy0n commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This pull request adds support for creating and using wallets derived from a mnemonic with a password, and updates the transaction and wallet services to consistently accept and propagate an optional mnemonicPassword parameter. This allows for enhanced wallet security and flexibility in transaction generation and gas estimation flows. Additionally, a new helper function is introduced for wallet creation with a mnemonic password, along with corresponding tests.

Wallet creation and management:

  • Added a new function createRailgunWalletFromMnemonicWithPassword in wallets.ts to support creating wallets using a mnemonic and password, including error handling.
  • Updated the internal wallet creation logic (createWallet) to handle optional mnemonicPassword, selecting the appropriate engine method based on its presence.
  • Added a test case for creating and loading a wallet from a mnemonic with password in wallets.test.ts.
  • Updated the standard createRailgunWallet function to pass an empty string for mnemonicPassword to maintain compatibility.
  • Imported the new wallet creation function in the test file.

Transaction generation and proof flows:

  • Added mnemonicPassword as an optional parameter to all transaction generation, proof, and gas estimation functions in tx-generator.ts, tx-cross-contract-calls.ts, tx-proof-transfer.ts, tx-proof-unshield.ts, tx-transfer.ts, and tx-unshield.ts, ensuring it is properly threaded through all relevant calls. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]
  • Updated all internal function calls and transaction batching logic to propagate the mnemonicPassword parameter where needed. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]

These updates ensure that all wallet and transaction operations can securely utilize a mnemonic password when required, improving overall security and flexibility.

zy0n added 4 commits June 11, 2026 14:45
The engine requires the BIP39 mnemonic password on load (loadExisting
verifies it reproduces the wallet ID and throws otherwise), but the
wallet SDK load path never carried it. Password-protected wallets
created via createRailgunWalletFromMnemonicWithPassword could therefore
never be reloaded after unload/restart.

Thread an optional mnemonicPassword through loadExistingWallet and the
public loadWalletByID, forwarding it to engine.loadExistingWallet.

Fix the round-trip test to supply the password on reload, and add a
negative test asserting a missing/wrong password is rejected.
Remove the ambiguous createRailgunWalletFromMnemonicWithPassword and add
an optional trailing mnemonicPassword to createRailgunWallet instead, so
there is a single create entrypoint. Omitted/empty preserves the legacy
no-password wallet ID; the internal createWallet still routes empty to
engine.createWalletFromMnemonic.

Update tests to the consolidated API.
The engine added a password param to Mnemonic.to0xPrivateKey, but the
exported mnemonicTo0xPKey util still derived without it, silently
returning the wrong 0x private key for password-protected wallets.

Forward an optional mnemonicPassword; omitting/empty preserves the
legacy no-password key. Add a test covering both cases.
@zy0n zy0n requested review from Copilot and mesquka June 17, 2026 21:30
@zy0n zy0n removed the request for review from Copilot June 17, 2026 21:32
mesquka
mesquka previously approved these changes Jun 18, 2026
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​railgun-community/​engine@​9.5.4 ⏵ 9.6.082 +410010090100

View full report

@zy0n zy0n merged commit 11e7c31 into main Jun 19, 2026
3 of 4 checks passed
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