修复一个bug: isAddress()里比特币长度不可能为32,否则会和TIC地址冲突。
This commit is contained in:
parent
7345c64de6
commit
9454bfd5a0
6
index.js
6
index.js
@ -152,7 +152,7 @@ module.exports = {
|
|||||||
let signer=crypto.createSign(hasher)
|
let signer=crypto.createSign(hasher)
|
||||||
signer.update(this.hash(data, option)).end()
|
signer.update(this.hash(data, option)).end()
|
||||||
let signature = signer.sign(seckeyPEM, 'hex')
|
let signature = signer.sign(seckeyPEM, 'hex')
|
||||||
return signature // 发现同样的输入,每次调用会生成不同的 signature, 且长度不定(140,142,144 hex) 但都可以通过 verify。
|
return signature // 发现同样的输入,nodejs里每次调用会生成不同的 signature, 且长度不定(140,142,144 hex) 但都可以通过 verify。但在浏览器里调用,signature却是固定的。
|
||||||
}else if (option.tool==='nacl') {
|
}else if (option.tool==='nacl') {
|
||||||
// 这样不行,无法和verify共享一套公私钥。
|
// 这样不行,无法和verify共享一套公私钥。
|
||||||
// let naclSeckey = this.buf2hex(nacl.sign.keyPair.fromSeed(seckey).seckey)
|
// let naclSeckey = this.buf2hex(nacl.sign.keyPair.fromSeed(seckey).seckey)
|
||||||
@ -185,7 +185,7 @@ module.exports = {
|
|||||||
// let naclPubkey = nacl.sign.keyPair.fromSeed()
|
// let naclPubkey = nacl.sign.keyPair.fromSeed()
|
||||||
}else { // 默认使用 eccrypto
|
}else { // 默认使用 eccrypto
|
||||||
try {
|
try {
|
||||||
await eccrypto.verify(Buffer.from(pubkey, 'hex'), this.hash(data, {output:'buf'}), Buffer.from(signature, 'hex')) // 如果给signature添加1位hex,eccrypto 的 verify结果也是true! 估计因为一位hex不被转成字节。
|
let result = await eccrypto.verify(Buffer.from(pubkey, 'hex'), this.hash(data, {output:'buf'}), Buffer.from(signature, 'hex')) // 如果给signature添加1位hex,eccrypto 的 verify结果也是true! 估计因为一位hex不被转成字节。
|
||||||
return true
|
return true
|
||||||
}catch(exception){
|
}catch(exception){
|
||||||
return false
|
return false
|
||||||
@ -426,7 +426,7 @@ module.exports = {
|
|||||||
isAddress(address){
|
isAddress(address){
|
||||||
if (/^(0x)?[\da-fA-F]{40}$/.test(address)){
|
if (/^(0x)?[\da-fA-F]{40}$/.test(address)){
|
||||||
return 'ETH'
|
return 'ETH'
|
||||||
}else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address)){ // 格式合法
|
}else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address) && address.length!==32){ // 格式合法。常见的是 33或34字符长度
|
||||||
let prefixedPosition = this.b58c2hex(address)
|
let prefixedPosition = this.b58c2hex(address)
|
||||||
if (prefixedPosition && prefixedPosition.length===42) // 内容合法
|
if (prefixedPosition && prefixedPosition.length===42) // 内容合法
|
||||||
return 'BTC'
|
return 'BTC'
|
||||||
|
Loading…
Reference in New Issue
Block a user