adhere to standard 5.0.0

This commit is contained in:
Daniel Cousens 2015-08-13 14:25:32 +10:00
parent e97389ed08
commit 56160622ca
3 changed files with 13 additions and 24 deletions

View file

@ -64,6 +64,6 @@
"mocha": "^2.2.0", "mocha": "^2.2.0",
"proxyquire": "^1.4.0", "proxyquire": "^1.4.0",
"sinon": "^1.12.2", "sinon": "^1.12.2",
"standard": "^4.0.0" "standard": "^5.0.0"
} }
} }

View file

@ -33,7 +33,7 @@ function extractInput (txIn) {
var hashType, parsed, pubKeys, signatures var hashType, parsed, pubKeys, signatures
switch (scriptType) { switch (scriptType) {
case 'pubkeyhash': { case 'pubkeyhash':
parsed = ECSignature.parseScriptSignature(scriptSig.chunks[0]) parsed = ECSignature.parseScriptSignature(scriptSig.chunks[0])
hashType = parsed.hashType hashType = parsed.hashType
pubKeys = scriptSig.chunks.slice(1) pubKeys = scriptSig.chunks.slice(1)
@ -41,9 +41,8 @@ function extractInput (txIn) {
prevOutScript = scripts.pubKeyHashOutput(bcrypto.hash160(pubKeys[0])) prevOutScript = scripts.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
break break
}
case 'pubkey': { case 'pubkey':
parsed = ECSignature.parseScriptSignature(scriptSig.chunks[0]) parsed = ECSignature.parseScriptSignature(scriptSig.chunks[0])
hashType = parsed.hashType hashType = parsed.hashType
signatures = [parsed.signature] signatures = [parsed.signature]
@ -53,9 +52,8 @@ function extractInput (txIn) {
} }
break break
}
case 'multisig': { case 'multisig':
signatures = scriptSig.chunks.slice(1).map(function (chunk) { signatures = scriptSig.chunks.slice(1).map(function (chunk) {
if (chunk === ops.OP_0) return chunk if (chunk === ops.OP_0) return chunk
@ -71,7 +69,6 @@ function extractInput (txIn) {
break break
} }
}
return { return {
hashType: hashType, hashType: hashType,
@ -146,16 +143,14 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
// if we can, extract pubKey information // if we can, extract pubKey information
switch (prevOutType) { switch (prevOutType) {
case 'multisig': { case 'multisig':
input.pubKeys = prevOutScript.chunks.slice(1, -2) input.pubKeys = prevOutScript.chunks.slice(1, -2)
break break
}
case 'pubkey': { case 'pubkey':
input.pubKeys = prevOutScript.chunks.slice(0, 1) input.pubKeys = prevOutScript.chunks.slice(0, 1)
break break
} }
}
if (prevOutType !== 'scripthash') { if (prevOutType !== 'scripthash') {
input.scriptType = prevOutType input.scriptType = prevOutType
@ -230,13 +225,12 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
if (input.signatures) { if (input.signatures) {
switch (scriptType) { switch (scriptType) {
case 'pubkeyhash': { case 'pubkeyhash':
var pkhSignature = input.signatures[0].toScriptSignature(input.hashType) var pkhSignature = input.signatures[0].toScriptSignature(input.hashType)
scriptSig = scripts.pubKeyHashInput(pkhSignature, input.pubKeys[0]) scriptSig = scripts.pubKeyHashInput(pkhSignature, input.pubKeys[0])
break break
}
case 'multisig': { case 'multisig':
// Array.prototype.map is sparse-compatible // Array.prototype.map is sparse-compatible
var msSignatures = input.signatures.map(function (signature) { var msSignatures = input.signatures.map(function (signature) {
return signature && signature.toScriptSignature(input.hashType) return signature && signature.toScriptSignature(input.hashType)
@ -257,15 +251,13 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
var redeemScript = allowIncomplete ? undefined : input.redeemScript var redeemScript = allowIncomplete ? undefined : input.redeemScript
scriptSig = scripts.multisigInput(msSignatures, redeemScript) scriptSig = scripts.multisigInput(msSignatures, redeemScript)
break break
}
case 'pubkey': { case 'pubkey':
var pkSignature = input.signatures[0].toScriptSignature(input.hashType) var pkSignature = input.signatures[0].toScriptSignature(input.hashType)
scriptSig = scripts.pubKeyInput(pkSignature) scriptSig = scripts.pubKeyInput(pkSignature)
break break
} }
} }
}
// did we build a scriptSig? // did we build a scriptSig?
if (scriptSig) { if (scriptSig) {
@ -322,25 +314,22 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
var pubKeys = [] var pubKeys = []
switch (scriptType) { switch (scriptType) {
case 'multisig': { case 'multisig':
pubKeys = redeemScript.chunks.slice(1, -2) pubKeys = redeemScript.chunks.slice(1, -2)
break break
}
case 'pubkeyhash': { case 'pubkeyhash':
var pkh1 = redeemScript.chunks[2] var pkh1 = redeemScript.chunks[2]
var pkh2 = bcrypto.hash160(keyPair.getPublicKeyBuffer()) var pkh2 = bcrypto.hash160(keyPair.getPublicKeyBuffer())
assert.deepEqual(pkh1, pkh2, 'privateKey cannot sign for this input') assert.deepEqual(pkh1, pkh2, 'privateKey cannot sign for this input')
pubKeys = [kpPubKey] pubKeys = [kpPubKey]
break break
}
case 'pubkey': { case 'pubkey':
pubKeys = redeemScript.chunks.slice(0, 1) pubKeys = redeemScript.chunks.slice(0, 1)
break break
} }
}
if (!input.prevOutScript) { if (!input.prevOutScript) {
input.prevOutScript = scripts.scriptHashOutput(redeemScript.getHash()) input.prevOutScript = scripts.scriptHashOutput(redeemScript.getHash())