From 0f4a591665c6b020780a6ad90444b3d4c87aa7a1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 30 Apr 2016 21:08:32 -0700 Subject: [PATCH] script: minor. --- lib/bcoin/hd.js | 2 +- lib/bcoin/protocol/parser.js | 2 +- lib/bcoin/script.js | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index 72ea8b28..07be97fa 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -146,7 +146,7 @@ Mnemonic.prototype.toSeed = function toSeed() { }; /** - * Generate mnemonic string from english words. + * Generate a mnemonic phrase from chosen language. * @returns {String} */ diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index a07f1b8b..869f9d37 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -689,7 +689,7 @@ Parser.parseBlockHeaders = function parseBlockHeaders(p) { ts: p.readU32(), bits: p.readU32(), nonce: p.readU32() - } + }; }; /** diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 18db23f2..386f2218 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -3494,7 +3494,7 @@ Script.formatASM = function formatASM(code, decode) { if (Buffer.isBuffer(op)) { if (op.length <= 4) { op = Script.num(op, constants.flags.VERIFY_NONE); - out.push(op.toNumber()); + out.push(op.toString(10)); continue; } @@ -3741,11 +3741,11 @@ Script.fromString = function fromString(code) { op = code[i]; symbol = op.toUpperCase(); - if (symbol.indexOf('OP_') === -1) + if (symbol.indexOf('OP_') !== 0) symbol = 'OP_' + symbol; if (opcodes[symbol] == null) { - if (op[0] === '\'' || op[0] === '"') { + if (op[0] === '\'') { op = op.slice(1, -1); p.writeBytes(Script.encode([new Buffer(op, 'ascii')])); continue; @@ -3756,8 +3756,8 @@ Script.fromString = function fromString(code) { p.writeBytes(Script.encode([op])); continue; } - assert(op.indexOf('0x') === 0) - op = op.slice(2); + assert(op.indexOf('0x') === 0); + op = op.substring(2); assert(utils.isHex(op), 'Unknown opcode.'); if (op.length % 2 !== 0) op = op + '0'; @@ -4105,10 +4105,14 @@ Script.checksig = function checksig(msg, sig, key, flags) { Script.sign = function sign(msg, key, type) { var sig = bcoin.ec.sign(msg, key); + var p = new BufferWriter(); // Add the sighash type as a single byte // to the signature. - return Buffer.concat([sig, new Buffer([type])]); + p.writeBytes(sig); + p.writeU8(type); + + return p.render(); }; /**