-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBip39.test.scala
50 lines (45 loc) · 1.55 KB
/
Bip39.test.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import ecc.*
import Secp256k1.*
import scodec.bits.*
import bips.*
class Bip39Test extends munit.FunSuite {
test("read wordlist from file") {
assertEquals(Bip39.words.size, 2048)
assertEquals(Bip39.words(0), "abandon")
}
test("encode entropy to mnemonic sentence") {
assertEquals(
Bip39.toMnemonics(ByteVector.fill(16)(0)),
List.fill(11)("abandon") :+ "about"
)
assertEquals(
Bip39.toMnemonics(ByteVector.fill(32)(0)),
List.fill(23)("abandon") :+ "art"
)
}
test("decode mnemonic to entropy") {
assertEquals(
Bip39.toEntropy(List.fill(11)("abandon") :+ "about"),
ByteVector.fill(16)(0)
)
assertEquals(
Bip39.toEntropy(List.fill(23)("abandon") :+ "art"),
ByteVector.fill(32)(0)
)
}
// test vectors from https://github.com/trezor/python-mnemonic/blob/master/vectors.json
// passphrase for all tests is "TREZOR"
test("create BIP32-compatible seed") {
val mnemonics = List.fill(11)("abandon") :+ "about"
val entropy = Bip39.toEntropy(mnemonics)
assertEquals(
Bip39.toSeed(mnemonics,"TREZOR"),
ByteVector.fromValidHex("c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04")
)
// now check with empty password (from https://iancoleman.io/bip39 tool)
assertEquals(
Bip39.toSeed(mnemonics,""),
ByteVector.fromValidHex("5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4")
)
}
}