Skip to content

feat: added two new utils for mnemonic/english-word-indices conversion - #300

Merged
lwin-kyaw merged 5 commits into
mainfrom
feat/mnemonic-english-idx-conversion
Aug 14, 2026
Merged

feat: added two new utils for mnemonic/english-word-indices conversion#300
lwin-kyaw merged 5 commits into
mainfrom
feat/mnemonic-english-idx-conversion

Conversation

@lwin-kyaw

@lwin-kyawlwin-kyaw commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Mnemonic-to-index conversion currently lives in app-specific code (for example MetaMask Mobile) and is not available as a shared, browser-safe helper in @metamask/utils. Callers that store BIP-39 phrases as little-endian Uint16 wordlist indices have to duplicate that logic.

This PR adds two utilities in src/mnemonic.ts:

  • uint8ArrayToMnemonic — reads little-endian Uint16 English BIP-39 word indices from a Uint8Array and returns the space-separated mnemonic string. Throws if the input is empty.
  • convertMnemonicToWordlistIndices — splits a mnemonic string and encodes each word’s English BIP-39 wordlist index as little-endian Uint16 bytes in a Uint8Array.

Both use the English wordlist from @metamask/scure-bip39. No Node Buffer is used, so the helpers work in browsers.


Note

Medium Risk
New utilities operate on seed-phrase representations; invalid words are silently encoded as 65535 rather than rejected, which could surprise callers handling recovery phrases.

Overview
Adds shared browser-safe helpers for converting between English BIP-39 mnemonics and little-endian Uint16 wordlist indices stored in a Uint8Array, so callers no longer need app-local copies of this logic.

uint8ArrayToMnemonic decodes those bytes into a space-separated mnemonic (throws on empty input). convertMnemonicToWordlistIndices does the reverse via @metamask/scure-bip39’s English wordlist; words not in the list are encoded as index -1 (65535 as Uint16). Both are re-exported from the package entrypoints, with tests and changelog; @metamask/scure-bip39 is added as a dependency.

Reviewed by Cursor Bugbot for commit e6ce3df. Bugbot is set up for automated code reviews on this repo. Configure here.

@socket-security

socket-securityBot commented Aug 13, 2026

Copy link
Copy Markdown

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

DiffPackageSupply Chain
Security
VulnerabilityQualityMaintenanceLicense
Updated@​scure/​base@​1.1.3 ⏵ 1.1.910010010082100
Added@​noble/​hashes@​1.3.310010010083100
Added@​metamask/​scure-bip39@​2.1.110010010085100

View full report

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ce170e3. Configure here.

Comment threadsrc/mnemonic.ts
Comment threadCHANGELOG.md Outdated
@lwin-kyaw
lwin-kyaw merged commit e5591e2 into mainAug 14, 2026
22 checks passed
@lwin-kyaw
lwin-kyaw deleted the feat/mnemonic-english-idx-conversion branch August 14, 2026 03:06
Sign up for freeto 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

@lwin-kyaw@cryptodev-2s