| 32 | }, |
| 33 | |
| 34 | setSecret(newSecret: string) { |
| 35 | const self = this as unknown as TWalletThis; |
| 36 | // Try to match words to the default slip39 wordlist and complete partial words |
| 37 | const lookupMap = WORD_LIST.reduce((map, word) => { |
| 38 | const prefix3 = word.substr(0, 3); |
| 39 | const prefix4 = word.substr(0, 4); |
| 40 | |
| 41 | map.set(prefix3, !map.has(prefix3) ? word : false); |
| 42 | map.set(prefix4, !map.has(prefix4) ? word : false); |
| 43 | |
| 44 | return map; |
| 45 | }, new Map()); |
| 46 | |
| 47 | self.secret = newSecret |
| 48 | .trim() |
| 49 | .split('\n') |
| 50 | .filter(s => s) |
| 51 | .map(s => { |
| 52 | let secret = s |
| 53 | .trim() |
| 54 | .toLowerCase() |
| 55 | .replace(/[^a-zA-Z0-9]/g, ' ') |
| 56 | .replace(/\s+/g, ' '); |
| 57 | |
| 58 | secret = secret |
| 59 | .split(' ') |
| 60 | .map(word => lookupMap.get(word) || word) |
| 61 | .join(' '); |
| 62 | |
| 63 | return secret; |
| 64 | }); |
| 65 | return self; |
| 66 | }, |
| 67 | |
| 68 | getID() { |
| 69 | const self = this as unknown as TWalletThis; |