Use ethers.js Mnemonic for real BIP-39 phrase generation
All checks were successful
check / check (push) Successful in 22s

Replace stub wordlist with ethers.Mnemonic.fromEntropy() using
crypto.getRandomValues(). Add esbuild to bundle popup JS so it
can import ethers directly — no background messaging needed.
Each die click now generates a valid, random BIP-39 mnemonic.
This commit is contained in:
2026-02-25 15:40:41 +07:00
parent a967029511
commit da30c0667f
5 changed files with 219 additions and 185 deletions

View File

@@ -1,5 +1,5 @@
// AutistMask popup UI — view management and event wiring
// All wallet logic will live in background/; this file is purely UI.
const { Mnemonic } = require("ethers");
const VIEWS = [
"lock",
@@ -70,153 +70,11 @@ function makeStubAddress() {
};
}
// Stub wordlist for random phrase generation.
// TODO: replace with real BIP-39 generation via background.
const STUB_WORDLIST = [
"abandon",
"ability",
"able",
"about",
"above",
"absent",
"absorb",
"abstract",
"absurd",
"abuse",
"access",
"accident",
"account",
"accuse",
"achieve",
"acid",
"acoustic",
"acquire",
"across",
"act",
"action",
"actor",
"actual",
"adapt",
"add",
"addict",
"address",
"adjust",
"admit",
"adult",
"advance",
"advice",
"aerobic",
"affair",
"afford",
"afraid",
"again",
"age",
"agent",
"agree",
"ahead",
"aim",
"air",
"airport",
"aisle",
"alarm",
"album",
"alcohol",
"alert",
"alien",
"all",
"alley",
"allow",
"almost",
"alone",
"alpha",
"already",
"also",
"alter",
"always",
"amateur",
"amazing",
"among",
"amount",
"amused",
"analyst",
"anchor",
"ancient",
"anger",
"angle",
"angry",
"animal",
"ankle",
"announce",
"annual",
"another",
"answer",
"antenna",
"antique",
"anxiety",
"any",
"apart",
"apology",
"appear",
"apple",
"approve",
"april",
"arch",
"arctic",
"area",
"arena",
"argue",
"arm",
"armed",
"armor",
"army",
"around",
"arrange",
"arrest",
"arrive",
"arrow",
"art",
"artefact",
"artist",
"artwork",
"ask",
"aspect",
"assault",
"asset",
"assist",
"assume",
"asthma",
"athlete",
"atom",
"attack",
"attend",
"attitude",
"attract",
"auction",
"audit",
"august",
"aunt",
"author",
"auto",
"autumn",
"average",
"avocado",
"avoid",
"awake",
"aware",
"awesome",
"awful",
"awkward",
"axis",
];
function generateStubMnemonic() {
const phrase = [];
for (let i = 0; i < 12; i++) {
const bytes = new Uint32Array(1);
crypto.getRandomValues(bytes);
phrase.push(STUB_WORDLIST[bytes[0] % STUB_WORDLIST.length]);
}
return phrase.join(" ");
function generateMnemonic() {
const wallet = Mnemonic.fromEntropy(
globalThis.crypto.getRandomValues(new Uint8Array(16)),
);
return wallet.phrase;
}
// -- render wallet list on main view --
@@ -409,7 +267,7 @@ function init() {
// -- Add wallet (unified create/import) --
$("btn-generate-phrase").addEventListener("click", () => {
const phrase = generateStubMnemonic();
const phrase = generateMnemonic();
$("wallet-mnemonic").value = phrase;
$("add-wallet-phrase-warning").classList.remove("hidden");
});