diff --git a/.gitignore b/.gitignore index 46dd5c4..d7e9ceb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ package-lock.json .svn ~* .gitattributes +dump.rdb diff --git a/dump.rdb b/dump.rdb deleted file mode 100644 index 54b7200..0000000 Binary files a/dump.rdb and /dev/null differ diff --git a/index.js b/index.js index 76be726..a831062 100644 --- a/index.js +++ b/index.js @@ -67,7 +67,10 @@ module.exports = { } , isSecword(secword){ - return Secword.isValid(secword) + if (typeof secword==='string' && 12===secword.split(/ +/)) + return Secword.isValid(secword) + else + return false } , isSeckey(seckey){ @@ -357,7 +360,7 @@ module.exports = { case 'devnet': prefix='74'; break; // Base58: 0x90 => d, Base 64: d=0x1d=0b00011101 => 0b 011101xx = 0x74~77 default: prefix='4c' } - let checksum = this.hash(this.hash(position)).slice(0,6) // 添加 checksum 使得能够检测大小写错误。注意,不包含 prefix,这样更纯粹、专注。 + let checksum = this.hash(this.hash(prefix+position)).slice(0,6) // 添加 checksum 使得能够检测大小写错误。[todo] 校验码里要不要包含 prefix? // address = this.hex2eip55(prefix + position + checksum) // 前缀1节,位置20节,校验3节,共24节=48字符(能够完全转化为8个色彩),再转eip55。 address = this.hex2b64u(prefix + position + checksum) // 实际采用 b64u (named by luk.lu as base 64 for url), 共 32字符。 return address @@ -384,16 +387,17 @@ module.exports = { } , isAddress(address){ - if (/^0x[\da-fA-F]{40}$/.test(address)){ + if (/^(0x)?[\da-fA-F]{40}$/.test(address)){ return 'ETH' - }else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address) // 格式合法 - && this.b58c2hex(address)){ // 内容合法 + }else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address)){ // 格式合法 + let prefixedPosition = this.b58c2hex(address) + if (prefixedPosition && prefixedPosition.length===42) // 内容合法 return 'BTC' }else if (/^[Ttd][0-9a-zA-Z\-_]{31}$/.test(address)){ // 格式合法 let b64 = address.replace('-', '+').replace('_', '/') let hex = Buffer.from(b64, 'base64').toString('hex') - let [all, prefix, position, checksum] = hex.match(/^([\da-fA-F]{2})([\da-fA-F]{40})([\da-fA-F]{6})$/) - return this.hash(this.hash(position)).slice(0,6) === checksum + let [all, prefix, position, checksum] = hex.match(/^([\da-fA-F]{2})([\da-fA-F]{40})([\da-fA-F]{6})$/) // 内容合法 + return this.hash(this.hash(prefix+position)).slice(0,6) === checksum // [todo] 校验码里要不要包含 prefix? } return null }