Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleanup #432

Merged
merged 4 commits into from
Aug 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ecsignature.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ECSignature.parseScriptSignature = function (buffer) {
var hashType = buffer.readUInt8(buffer.length - 1)
var hashTypeMod = hashType & ~0x80

assert(hashTypeMod > 0x00 && hashTypeMod < 0x04, 'Invalid hashType ' + hashType)
if (hashTypeMod <= 0x00 || hashTypeMod >= 0x04) throw new Error('Invalid hashType ' + hashType)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving away from assert as the string warning messages always get evaluated, which has lead to various performance issues in the past.
It was nice while it lasted.


return {
signature: ECSignature.fromDER(buffer.slice(0, -1)),
Expand Down
1 change: 0 additions & 1 deletion src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function sign (keyPair, message, network) {
return signature.toCompact(i, keyPair.compressed)
}

// TODO: network could be implied from address
function verify (address, signature, message, network) {
if (!Buffer.isBuffer(signature)) {
signature = new Buffer(signature, 'base64')
Expand Down
3 changes: 0 additions & 3 deletions src/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module.exports = {
bitcoin: {
magic: 0xd9b4bef9,
messagePrefix: '\x18Bitcoin Signed Message:\n',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't stored all the chainParams that exist here.
It seems inconsistent to just have this one, which feels very out of place among constants that are actually used and tested by this library.

Open to ideas on this one, removing it for now.
Maybe it should come back as chain: { magicPrefix: ? }}?

Technically this is a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes

bip32: {
public: 0x0488b21e,
Expand All @@ -15,7 +14,6 @@ module.exports = {
dustThreshold: 546 // https://github.com/bitcoin/bitcoin/blob/v0.9.2/src/core.h#L151-L162
},
testnet: {
magic: 0xd9b4bef9,
messagePrefix: '\x18Bitcoin Signed Message:\n',
bip32: {
public: 0x043587cf,
Expand All @@ -27,7 +25,6 @@ module.exports = {
dustThreshold: 546
},
litecoin: {
magic: 0xd9b4bef9,
messagePrefix: '\x19Litecoin Signed Message:\n',
bip32: {
public: 0x019da462,
Expand Down
6 changes: 3 additions & 3 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Transaction.prototype.clone = function () {
return newTx
}

var one = new Buffer('0000000000000000000000000000000000000000000000000000000000000001', 'hex')
var ONE = new Buffer('0000000000000000000000000000000000000000000000000000000000000001', 'hex')

/**
* Hash transaction for signing a specific input.
Expand All @@ -195,7 +195,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
assert(inIndex >= 0, 'Invalid vin index')

// https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29
if (inIndex >= this.ins.length) return one
if (inIndex >= this.ins.length) return ONE

var txTmp = this.clone()

Expand Down Expand Up @@ -225,7 +225,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT

// only lock-in the txOut payee at same index as txIn
// https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L60
if (nOut >= this.outs.length) return one
if (nOut >= this.outs.length) return ONE

txTmp.outs = txTmp.outs.slice(0, nOut + 1)

Expand Down