-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewseed-funcs.ls
59 lines (59 loc) · 2.33 KB
/
newseed-funcs.ls
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
51
52
53
54
55
56
57
58
59
require! {
\./navigate.ls
\./seed.ls : seedmem
\../web3t/providers/deps.js : { bip39 }
\./pages/confirmation.ls : { alert }
\prelude-ls : { words, map, filter, join }
\./get-lang.ls
}
clean = ->
it.match(/[a-z]+/)?0
fix =
words >> (map clean) >> (filter (?)) >> (join " ")
not-in-dictionary = (word)->
word not in bip39.wordlists.EN
module.exports = (store, web3t)->
return null if not store? or not web3t?
lang = get-lang store
generate-seed = ->
/* Uncomment below for supporting valid 256-bits 24-seed-words mnemonic (must be fixed on all wallets types at the same time) */
seed = bip39.generate-mnemonic(256)
#seed = bip39.generate-mnemonic! + ' ' + bip39.generate-mnemonic!
store.current.seed-words = seed.split(' ').map(-> { part: it })
store.current.seed-generated = yes
next = ->
navigate store, web3t, \:init
verify-seed = (cb)->
empty =
store.current.seed-words
|> filter (.part.trim!.length is 0)
if empty.length is not 0
store.current.alert = "Please fill all words"
return cb "cancelled"
# wrong =
# store.current.seed-words
# |> map (.part)
# |> filter not-in-dictionary
# return cb null if wrong.length is 0
# res <- confirm store, "Some words do not match the dictionary. Do you want to continue?"
/* First check mnemonic generated with 256 bits length seed */
try
bip39.mnemonic-to-entropy store.current.seed-words.map(-> it.part).join(" ")
return cb null
catch e
/* If check fails continue to verify mnemonic generated with two 128 bits length seed phrases */
try
for i from 0 to store.current.seed-words.length-11 by 12
bip39.mnemonic-to-entropy store.current.seed-words.slice(i, i+12).map(-> it.part).join(" ")
cb null
catch
alert store, "Seed phrase checksum not match. Please try again."
store.current.page = \newseedrestore
save = ->
err <- verify-seed
return if err?
seedmem.mnemonic = store.current.seed-words.map(-> it.part).join(' ')
store.current.saved-seed = yes
seedmem.set seedmem.mnemonic
next!
{ save, generate-seed, next }