aboutsummaryrefslogtreecommitdiff
path: root/src/js/jsbip39.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/jsbip39.js')
-rw-r--r--src/js/jsbip39.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/js/jsbip39.js b/src/js/jsbip39.js
index 455615a..80ce656 100644
--- a/src/js/jsbip39.js
+++ b/src/js/jsbip39.js
@@ -93,11 +93,11 @@ var Mnemonic = function(language) {
93 var idx = parseInt(b.substring(i * 11, (i + 1) * 11), 2); 93 var idx = parseInt(b.substring(i * 11, (i + 1) * 11), 2);
94 result.push(wordlist[idx]); 94 result.push(wordlist[idx]);
95 } 95 }
96 return result.join(' '); 96 return self.joinWords(result);
97 } 97 }
98 98
99 self.check = function(mnemonic) { 99 self.check = function(mnemonic) {
100 var mnemonic = mnemonic.split(' ') 100 var mnemonic = self.splitWords(mnemonic);
101 if (mnemonic.length % 3 > 0) { 101 if (mnemonic.length % 3 > 0) {
102 return false 102 return false
103 } 103 }
@@ -130,7 +130,7 @@ var Mnemonic = function(language) {
130 130
131 self.toSeed = function(mnemonic, passphrase) { 131 self.toSeed = function(mnemonic, passphrase) {
132 passphrase = passphrase || ''; 132 passphrase = passphrase || '';
133 mnemonic = self.normalizeString(mnemonic).split(' ').filter(function(x) { return x.length; }).join(' '); 133 mnemonic = self.joinWords(self.splitWords(self.normalizeString(mnemonic))); // removes blanks
134 passphrase = self.normalizeString(passphrase) 134 passphrase = self.normalizeString(passphrase)
135 passphrase = "mnemonic" + passphrase; 135 passphrase = "mnemonic" + passphrase;
136 var mnemonicBits = sjcl.codec.utf8String.toBits(mnemonic); 136 var mnemonicBits = sjcl.codec.utf8String.toBits(mnemonic);
@@ -140,6 +140,20 @@ var Mnemonic = function(language) {
140 return hashHex; 140 return hashHex;
141 } 141 }
142 142
143 self.splitWords = function(mnemonic) {
144 return mnemonic.split(/\s/g).filter(function(x) { return x.length; });
145 }
146
147 self.joinWords = function(words) {
148 // Set space correctly depending on the language
149 // see https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese
150 var space = " ";
151 if (language == "japanese") {
152 space = "\u3000"; // ideographic space
153 }
154 return words.join(space);
155 }
156
143 self.normalizeString = function(str) { 157 self.normalizeString = function(str) {
144 if (typeof str.normalize == "function") { 158 if (typeof str.normalize == "function") {
145 return str.normalize("NFKD"); 159 return str.normalize("NFKD");