给 isSecword设置了easy|strict模式。
This commit is contained in:
parent
e96b61ed0d
commit
0baa845a16
3
index.js
3
index.js
@ -51,7 +51,7 @@ module.exports = {
|
|||||||
return false
|
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词的会抛出异常,很蠢。
|
//// for bitcore-mnemonic. 注意,bitcore-mnemonic 对少于12词的会抛出异常,很蠢。
|
||||||
// if (typeof secword==='string' && 12===secword.split(/ +/).length)
|
// if (typeof secword==='string' && 12===secword.split(/ +/).length)
|
||||||
// return BitcoreMnemonic.isValid(secword)
|
// return BitcoreMnemonic.isValid(secword)
|
||||||
@ -60,6 +60,7 @@ module.exports = {
|
|||||||
|
|
||||||
//// for bip39. 注意,bip39对当前defaultWordlist之外其他语言的合法 mnemonic 也返回 false,这一点不如 bitcore-mnemonic. 所以不能直接 bip39.validateMnemonic(secword)
|
//// 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 (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)) {
|
for (let lang of Object.keys(bip39.wordlists)) {
|
||||||
bip39.setDefaultWordlist(lang)
|
bip39.setDefaultWordlist(lang)
|
||||||
if (bip39.validateMnemonic(secword))
|
if (bip39.validateMnemonic(secword))
|
||||||
|
Loading…
Reference in New Issue
Block a user