完善 isSecword,使用 bip39.mnemonicToEntropy 来精确判断。
This commit is contained in:
parent
9454bfd5a0
commit
b923fec9cc
BIN
README.xlsx
Normal file
BIN
README.xlsx
Normal file
Binary file not shown.
29
index.js
29
index.js
@ -51,7 +51,7 @@ module.exports = {
|
||||
return false
|
||||
}
|
||||
,
|
||||
isSecword(secword){ // 注意 not all 12 words combinations are valid for both bitcore and bip39. Must be generated automatically. 另外,实际上bitcore和bip39对12, 15, 18, ... 长度的合法助记词都返回 true。
|
||||
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。
|
||||
//// for bitcore-mnemonic. 注意,bitcore-mnemonic 对少于12词的会抛出异常,很蠢。
|
||||
// if (typeof secword==='string' && 12===secword.split(/ +/).length)
|
||||
// return BitcoreMnemonic.isValid(secword)
|
||||
@ -59,10 +59,15 @@ module.exports = {
|
||||
// return false
|
||||
|
||||
//// for bip39. 注意,bip39对当前defaultWordlist之外其他语言的合法 mnemonic 也返回 false,这一点不如 bitcore-mnemonic. 所以不能直接 bip39.validateMnemonic(secword)
|
||||
if (typeof secword==='string' && 12===secword.split(/ +/).length)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
if (typeof secword==='string' && 12===secword.split(/ +/).length) {
|
||||
try {
|
||||
bip39.mnemonicToEntropy(secword)
|
||||
return true
|
||||
}catch(exception){
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
,
|
||||
isSeckey(seckey){
|
||||
@ -374,7 +379,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
return address
|
||||
}else if (coin === 'BTC'){ // 对比特币,把纯位置转换为大小写敏感能自我验证的bs58check地址:先加前缀,再加校验,共25字节,再转base58。得到26~34个字符,大多数34个。
|
||||
}else if (coin === 'BTC'){ // 对比特币,把纯位置转换为大小写敏感能自我验证的bs58check地址:先加前缀1,再加校验4,共25字节,再转base58。得到26~34个字符,大多数34个。
|
||||
let prefix
|
||||
switch (net) {
|
||||
case 'mainnet': prefix='00'; break; // pubkey hash => 1
|
||||
@ -461,13 +466,13 @@ module.exports = {
|
||||
|
||||
// for bip39
|
||||
const langMap = { zhcn: 'chinese_simplified', zhtw: 'chinese_traditional', enus: 'english', frfr: 'french', itit: 'italian', jajp: 'japanese', kokr: 'korean', eses: 'spanish' }
|
||||
langMap.chinese=langMap.cn=langMap.zhcn
|
||||
langMap.chinese=langMap.cn=langMap.zh=langMap.china=langMap.zhcn
|
||||
langMap.taiwanese=langMap.tw=langMap.zhtw
|
||||
langMap.en=langMap.enus
|
||||
langMap.fr=langMap.frfr
|
||||
langMap.it=langMap.itit
|
||||
langMap.ko=langMap.kr=langMap.kokr
|
||||
langMap.ja=langMap.jp=langMap.jajp
|
||||
langMap.en=langMap.us=langMap.uk=langMap.enus
|
||||
langMap.fr=langMap.france=langMap.frfr
|
||||
langMap.it=langMap.italy=langMap.itit
|
||||
langMap.ko=langMap.kr=langMap.korean=langMap.kokr
|
||||
langMap.ja=langMap.jp=langMap.japan=langMap.jajp
|
||||
|
||||
let language = 'english'
|
||||
if (typeof(lang)==='string'){
|
||||
|
Loading…
Reference in New Issue
Block a user