diff --git a/benchmark/script.js b/benchmark/script.js index 7442d1a..1ec27f3 100644 --- a/benchmark/script.js +++ b/benchmark/script.js @@ -32,6 +32,14 @@ async.series([ } } + function isPublicKeyOut() { + if (c >= scripts.length) { + c = 0; + } + scripts[c].isPublicKeyOut(); + c++; + } + function isPublicKeyHashIn() { if (c >= scripts.length) { c = 0; @@ -58,6 +66,7 @@ async.series([ var suite = new benchmark.Suite(); suite.add('isPublicKeyHashIn', isPublicKeyHashIn, {maxTime: maxTime}); + suite.add('isPublicKeyOut', isPublicKeyOut, {maxTime: maxTime}); suite.add('toAddress', toAddress, {maxTime: maxTime}); suite.add('getAddressInfo', getAddressInfo, {maxTime: maxTime}); suite diff --git a/lib/script/script.js b/lib/script/script.js index 5bcdce6..0fe1435 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -276,10 +276,21 @@ Script.prototype.getPublicKeyHash = function() { * @returns {boolean} if this is a public key output script */ Script.prototype.isPublicKeyOut = function() { - return this.chunks.length === 2 && - BufferUtil.isBuffer(this.chunks[0].buf) && - PublicKey.isValid(this.chunks[0].buf) && - this.chunks[1].opcodenum === Opcode.OP_CHECKSIG; + if (this.chunks.length === 2 && + this.chunks[0].buf && + this.chunks[0].buf.length && + this.chunks[1].opcodenum === Opcode.OP_CHECKSIG) { + var pubkeyBuf = this.chunks[0].buf; + var version = pubkeyBuf[0]; + if ((version === 0x04 || + version === 0x06 || + version === 0x07) && pubkeyBuf.length === 65) { + return true; + } else if ((version === 0x03 || version === 0x02) && pubkeyBuf.length === 33) { + return true; + } + } + return false; }; /**