From 0baa845a168b7e4b6b862cbd72c39d02b9022a0e Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Fri, 13 Mar 2020 18:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=20isSecword=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=BA=86easy|strict=E6=A8=A1=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 44e3078..debe651 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ module.exports = { return false } , - isSecword(secword){ // 注意 not all 12 words combinations are valid for both bitcore and bip39, because there are checksum in mnemonic. 另外,实际上bitcore和bip39对12, 15, 18, ... 长度的合法助记词都返回 true。 + isSecword(secword, {mode='strict'}={}){ // 注意 not all 12 words combinations are valid for both bitcore and bip39, because there are checksum in mnemonic. 另外,实际上bitcore和bip39对12, 15, 18, ... 长度的合法助记词都返回 true。 //// for bitcore-mnemonic. 注意,bitcore-mnemonic 对少于12词的会抛出异常,很蠢。 // if (typeof secword==='string' && 12===secword.split(/ +/).length) // return BitcoreMnemonic.isValid(secword) @@ -60,6 +60,7 @@ module.exports = { //// for bip39. 注意,bip39对当前defaultWordlist之外其他语言的合法 mnemonic 也返回 false,这一点不如 bitcore-mnemonic. 所以不能直接 bip39.validateMnemonic(secword) if (typeof secword==='string' && !/(^\s)|\s\s|(\s$)/.test(secword) && 12===secword.split(/\s+/).length) { + if (mode==='easy') return true // easy模式不检查校验等等严格的合法性了,反正 secword2seed是接受一切字符串的 for (let lang of Object.keys(bip39.wordlists)) { bip39.setDefaultWordlist(lang) if (bip39.validateMnemonic(secword))