Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement different languages in website
  • Loading branch information
Hardik Mathur committed Dec 14, 2025
commit 4d61eda74e0d5d03bfeca56db2d0fd981c4828a0
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ object WordList {
Try(loadFile()).map(r => try r.getLines().toList finally r.close())

private def resourceLoader(fileName: String): () => BufferedSource =
() => Source.fromInputStream(getClass.getResourceAsStream(s"/wordlist/$fileName"))(Codec.UTF8)
() => {
val path = s"/wordlist/$fileName"
val stream =
Option(getClass.getResourceAsStream(path))
.orElse(Option(Thread.currentThread().getContextClassLoader.getResourceAsStream(path)))
.orElse(Option(ClassLoader.getSystemResourceAsStream(path)))
.getOrElse(throw new IllegalArgumentException(s"Wordlist resource not found: $path"))
Source.fromInputStream(stream)(Codec.UTF8)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.ergoplatform.wallet.mnemonic

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class WordListSpec extends AnyFlatSpec with Matchers {

behavior of "WordList and Mnemonic"

it should "load all available wordlists and have 2048 words each" in {
WordList.AvailableLanguages.foreach { lang =>
val wl = WordList.load(lang).get
wl.words.length shouldBe 2048
wl.words.forall(_.nonEmpty) shouldBe true
}
}

it should "use ideographic space for Japanese and space for others" in {
val ja = WordList.load("japanese").get
ja.delimiter shouldBe "\u3000"

WordList.AvailableLanguages.filterNot(_ == "japanese").foreach { lang =>
val wl = WordList.load(lang).get
wl.delimiter shouldBe " "
}
}

it should "generate mnemonic for each language with fixed entropy" in {
val entropy = Array.fill[Byte](20)(1) // 160 bits entropy
WordList.AvailableLanguages.foreach { lang =>
val m = new Mnemonic(lang, 160)
val phrase = m.toMnemonic(entropy).get
phrase.getData().nonEmpty shouldBe true
}
}
}