use baddress/bcrypto/bscript for ambuigities

This commit is contained in:
Daniel Cousens 2015-08-20 13:37:19 +10:00
parent 6ec687deba
commit 8934de591c
9 changed files with 113 additions and 113 deletions

View file

@ -1,5 +1,5 @@
var bs58check = require('bs58check')
var script = require('./script')
var bscript = require('./script')
var networks = require('./networks')
var typeforce = require('typeforce')
var types = require('./types')
@ -18,11 +18,11 @@ function fromBase58Check (address) {
function fromOutputScript (scriptPubKey, network) {
network = network || networks.bitcoin
var chunks = script.decompile(scriptPubKey)
if (script.isPubKeyHashOutput(chunks)) return toBase58Check(chunks[2], network.pubKeyHash)
if (script.isScriptHashOutput(chunks)) return toBase58Check(chunks[1], network.scriptHash)
var chunks = bscript.decompile(scriptPubKey)
if (bscript.isPubKeyHashOutput(chunks)) return toBase58Check(chunks[2], network.pubKeyHash)
if (bscript.isScriptHashOutput(chunks)) return toBase58Check(chunks[1], network.scriptHash)
throw new Error(script.toASM(chunks) + ' has no matching Address')
throw new Error(bscript.toASM(chunks) + ' has no matching Address')
}
function toBase58Check (hash, version) {
@ -45,8 +45,8 @@ function toOutputScript (address, network) {
var version = payload.readUInt8(0)
var hash = payload.slice(1)
if (version === network.pubKeyHash) return script.pubKeyHashOutput(hash)
if (version === network.scriptHash) return script.scriptHashOutput(hash)
if (version === network.pubKeyHash) return bscript.pubKeyHashOutput(hash)
if (version === network.scriptHash) return bscript.scriptHashOutput(hash)
throw new Error(address + ' has no matching Script')
}

View file

@ -1,5 +1,5 @@
var bufferutils = require('./bufferutils')
var crypto = require('./crypto')
var bcrypto = require('./crypto')
var Transaction = require('./transaction')
@ -66,7 +66,7 @@ Block.fromHex = function (hex) {
}
Block.prototype.getHash = function () {
return crypto.hash256(this.toBuffer(true))
return bcrypto.hash256(this.toBuffer(true))
}
Block.prototype.getId = function () {

View file

@ -1,5 +1,5 @@
var bufferutils = require('./bufferutils')
var crypto = require('./crypto')
var bcrypto = require('./crypto')
var ecdsa = require('./ecdsa')
var networks = require('./networks')
@ -16,7 +16,7 @@ function magicHash (message, network) {
var lengthBuffer = bufferutils.varIntBuffer(messageBuffer.length)
var buffer = Buffer.concat([messagePrefix, lengthBuffer, messageBuffer])
return crypto.hash256(buffer)
return bcrypto.hash256(buffer)
}
function sign (keyPair, message, network) {

View file

@ -1,7 +1,7 @@
var bufferutils = require('./bufferutils')
var crypto = require('./crypto')
var bcrypto = require('./crypto')
var opcodes = require('./opcodes')
var script = require('./script')
var bscript = require('./script')
var typeforce = require('typeforce')
var types = require('./types')
@ -191,7 +191,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
// in case concatenating two scripts ends up with two codeseparators,
// or an extra one at the end, this prevents all those possible incompatibilities.
var hashScript = script.compile(script.decompile(prevOutScript).filter(function (x) {
var hashScript = bscript.compile(bscript.decompile(prevOutScript).filter(function (x) {
return x !== opcodes.OP_CODESEPARATOR
}))
var i
@ -250,11 +250,11 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
buffer.writeInt32LE(hashType, buffer.length - 4)
txTmp.toBuffer().copy(buffer, 0)
return crypto.hash256(buffer)
return bcrypto.hash256(buffer)
}
Transaction.prototype.getHash = function () {
return crypto.hash256(this.toBuffer())
return bcrypto.hash256(this.toBuffer())
}
Transaction.prototype.getId = function () {

View file

@ -1,9 +1,9 @@
var address = require('./address')
var baddress = require('./address')
var bcrypto = require('./crypto')
var bscript = require('./script')
var bufferutils = require('./bufferutils')
var networks = require('./networks')
var ops = require('./opcodes')
var script = require('./script')
var ECPair = require('./ecpair')
var ECSignature = require('./ecsignature')
@ -12,21 +12,21 @@ var Transaction = require('./transaction')
function extractInput (txIn) {
var redeemScript
var scriptSig = txIn.script
var scriptSigChunks = script.decompile(scriptSig)
var scriptSigChunks = bscript.decompile(scriptSig)
var prevOutScript
var prevOutType = script.classifyInput(scriptSig, true)
var prevOutType = bscript.classifyInput(scriptSig, true)
var scriptType
// Re-classify if scriptHash
if (prevOutType === 'scripthash') {
redeemScript = scriptSigChunks.slice(-1)[0]
prevOutScript = script.scriptHashOutput(bcrypto.hash160(redeemScript))
prevOutScript = bscript.scriptHashOutput(bcrypto.hash160(redeemScript))
scriptSig = script.compile(scriptSigChunks.slice(0, -1))
scriptSig = bscript.compile(scriptSigChunks.slice(0, -1))
scriptSigChunks = scriptSigChunks.slice(0, -1)
scriptType = script.classifyInput(scriptSig, true)
scriptType = bscript.classifyInput(scriptSig, true)
} else {
scriptType = prevOutType
}
@ -34,7 +34,7 @@ function extractInput (txIn) {
// pre-empt redeemScript decompilation
var redeemScriptChunks
if (redeemScript) {
redeemScriptChunks = script.decompile(redeemScript)
redeemScriptChunks = bscript.decompile(redeemScript)
}
// Extract hashType, pubKeys and signatures
@ -46,7 +46,7 @@ function extractInput (txIn) {
hashType = parsed.hashType
pubKeys = scriptSigChunks.slice(1)
signatures = [parsed.signature]
prevOutScript = script.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
prevOutScript = bscript.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
break
@ -147,8 +147,8 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
var input = {}
if (prevOutScript) {
var prevOutScriptChunks = script.decompile(prevOutScript)
var prevOutType = script.classifyOutput(prevOutScriptChunks)
var prevOutScriptChunks = bscript.decompile(prevOutScript)
var prevOutType = bscript.classifyOutput(prevOutScriptChunks)
// if we can, extract pubKey information
switch (prevOutType) {
@ -198,7 +198,7 @@ TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) {
// Attempt to get a script if it's a base58 address string
if (typeof scriptPubKey === 'string') {
scriptPubKey = address.toOutputScript(scriptPubKey, this.network)
scriptPubKey = baddress.toOutputScript(scriptPubKey, this.network)
}
return this.tx.addOutput(scriptPubKey, value)
@ -240,7 +240,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
switch (scriptType) {
case 'pubkeyhash':
var pkhSignature = input.signatures[0].toScriptSignature(input.hashType)
scriptSig = script.pubKeyHashInput(pkhSignature, input.pubKeys[0])
scriptSig = bscript.pubKeyHashInput(pkhSignature, input.pubKeys[0])
break
case 'multisig':
@ -262,12 +262,12 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
}
var redeemScript = allowIncomplete ? undefined : input.redeemScript
scriptSig = script.multisigInput(msSignatures, redeemScript)
scriptSig = bscript.multisigInput(msSignatures, redeemScript)
break
case 'pubkey':
var pkSignature = input.signatures[0].toScriptSignature(input.hashType)
scriptSig = script.pubKeyInput(pkSignature)
scriptSig = bscript.pubKeyInput(pkSignature)
break
}
}
@ -276,7 +276,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
if (scriptSig) {
// wrap as scriptHash if necessary
if (input.prevOutType === 'scripthash') {
scriptSig = script.scriptHashInput(scriptSig, input.redeemScript)
scriptSig = bscript.scriptHashInput(scriptSig, input.redeemScript)
}
tx.setInputScript(index, scriptSig)
@ -318,14 +318,14 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
if (input.prevOutScript) {
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')
var scriptHash = script.decompile(input.prevOutScript)[1]
var scriptHash = bscript.decompile(input.prevOutScript)[1]
if (!bufferutils.equal(scriptHash, bcrypto.hash160(redeemScript))) throw new Error('RedeemScript does not match ' + scriptHash.toString('hex'))
}
var scriptType = script.classifyOutput(redeemScript)
var scriptType = bscript.classifyOutput(redeemScript)
if (!canSignTypes[scriptType]) throw new Error('RedeemScript not supported (' + scriptType + ')')
var redeemScriptChunks = script.decompile(redeemScript)
var redeemScriptChunks = bscript.decompile(redeemScript)
var pubKeys = []
switch (scriptType) {
case 'multisig':
@ -347,7 +347,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
// if we don't have a prevOutScript, generate a P2SH script
if (!input.prevOutScript) {
input.prevOutScript = script.scriptHashOutput(bcrypto.hash160(redeemScript))
input.prevOutScript = bscript.scriptHashOutput(bcrypto.hash160(redeemScript))
input.prevOutType = 'scripthash'
}
@ -365,7 +365,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
// we know nothin' Jon Snow, assume pubKeyHash
} else {
input.prevOutScript = script.pubKeyHashOutput(bcrypto.hash160(keyPair.getPublicKeyBuffer()))
input.prevOutScript = bscript.pubKeyHashOutput(bcrypto.hash160(keyPair.getPublicKeyBuffer()))
input.prevOutType = 'pubkeyhash'
input.pubKeys = [kpPubKey]
input.scriptType = input.prevOutType

View file

@ -1,7 +1,7 @@
/* global describe, it */
var assert = require('assert')
var crypto = require('../src/crypto')
var bcrypto = require('../src/crypto')
var fixtures = require('./fixtures/crypto')
@ -9,7 +9,7 @@ describe('Crypto', function () {
['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach(function (algorithm) {
describe(algorithm, function () {
fixtures.valid.forEach(function (f) {
var fn = crypto[algorithm]
var fn = bcrypto[algorithm]
var expected = f[algorithm]
it('returns ' + expected + ' for ' + f.hex, function () {

View file

@ -1,7 +1,7 @@
/* global describe, it */
var assert = require('assert')
var crypto = require('../src/crypto')
var bcrypto = require('../src/crypto')
var ecdsa = require('../src/ecdsa')
var message = require('../src/message')
var networks = require('../src/networks')
@ -24,7 +24,7 @@ describe('ecdsa', function () {
fixtures.valid.ecdsa.forEach(function (f) {
it('for "' + f.message + '"', function () {
var d = BigInteger.fromHex(f.d)
var h1 = crypto.sha256(f.message)
var h1 = bcrypto.sha256(f.message)
var k = ecdsa.deterministicGenerateK(curve, h1, d, checkSig)
assert.strictEqual(k.toHex(), f.k)
@ -68,7 +68,7 @@ describe('ecdsa', function () {
fixtures.valid.rfc6979.forEach(function (f) {
it('produces the expected k values for ' + f.message + " if k wasn't suitable", function () {
var d = BigInteger.fromHex(f.d)
var h1 = crypto.sha256(f.message)
var h1 = bcrypto.sha256(f.message)
var results = []
ecdsa.deterministicGenerateK(curve, h1, d, function (k) {
@ -90,7 +90,7 @@ describe('ecdsa', function () {
var d = BigInteger.fromHex(f.d)
var Q = curve.G.multiply(d)
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
var h1 = crypto.sha256(f.message)
var h1 = bcrypto.sha256(f.message)
var e = BigInteger.fromBuffer(h1)
var Qprime = ecdsa.recoverPubKey(curve, e, signature, f.i)
@ -137,7 +137,7 @@ describe('ecdsa', function () {
fixtures.valid.ecdsa.forEach(function (f) {
it('produces a deterministic signature for "' + f.message + '"', function () {
var d = BigInteger.fromHex(f.d)
var hash = crypto.sha256(f.message)
var hash = bcrypto.sha256(f.message)
var signature = ecdsa.sign(curve, hash, d).toDER()
assert.strictEqual(signature.toString('hex'), f.signature)
@ -145,7 +145,7 @@ describe('ecdsa', function () {
})
it('should sign with low S value', function () {
var hash = crypto.sha256('Vires in numeris')
var hash = bcrypto.sha256('Vires in numeris')
var sig = ecdsa.sign(curve, hash, BigInteger.ONE)
// See BIP62 for more information
@ -158,7 +158,7 @@ describe('ecdsa', function () {
fixtures.valid.ecdsa.forEach(function (f) {
it('verifies a valid signature for "' + f.message + '"', function () {
var d = BigInteger.fromHex(f.d)
var H = crypto.sha256(f.message)
var H = bcrypto.sha256(f.message)
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
var Q = curve.G.multiply(d)
@ -168,7 +168,7 @@ describe('ecdsa', function () {
fixtures.invalid.verify.forEach(function (f) {
it('fails to verify with ' + f.description, function () {
var H = crypto.sha256(f.message)
var H = bcrypto.sha256(f.message)
var d = BigInteger.fromHex(f.d)
var signature

View file

@ -2,8 +2,8 @@
var assert = require('assert')
var bcrypto = require('../src/crypto')
var bscript = require('../src/script')
var ops = require('../src/opcodes')
var script = require('../src/script')
var fixtures = require('./fixtures/script.json')
@ -16,17 +16,17 @@ describe('script', function () {
fixtures.valid.forEach(function (f) {
if (f.scriptSig) {
it('encodes/decodes ' + f.scriptSig, function () {
var scriptSig = script.fromASM(f.scriptSig)
var scriptSig = bscript.fromASM(f.scriptSig)
assert.strictEqual(script.toASM(scriptSig), f.scriptSig)
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
})
}
if (f.scriptPubKey) {
it('encodes/decodes ' + f.scriptPubKey, function () {
var scriptPubKey = script.fromASM(f.scriptPubKey)
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
assert.strictEqual(script.toASM(scriptPubKey), f.scriptPubKey)
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
})
}
})
@ -36,17 +36,17 @@ describe('script', function () {
fixtures.valid.forEach(function (f) {
if (f.scriptSig) {
it('compiles ' + f.scriptSig, function () {
var scriptSig = script.fromASM(f.scriptSig)
var scriptSig = bscript.fromASM(f.scriptSig)
assert.strictEqual(script.compile(scriptSig).toString('hex'), f.scriptSigHex)
assert.strictEqual(bscript.compile(scriptSig).toString('hex'), f.scriptSigHex)
})
}
if (f.scriptPubKey) {
it('compiles ' + f.scriptPubKey, function () {
var scriptPubKey = script.fromASM(f.scriptPubKey)
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
assert.strictEqual(script.compile(scriptPubKey).toString('hex'), f.scriptPubKeyHex)
assert.strictEqual(bscript.compile(scriptPubKey).toString('hex'), f.scriptPubKeyHex)
})
}
})
@ -56,24 +56,24 @@ describe('script', function () {
fixtures.valid.forEach(function (f) {
if (f.scriptSigHex) {
it('decompiles ' + f.scriptSig, function () {
var chunks = script.decompile(new Buffer(f.scriptSigHex, 'hex'))
var chunks = bscript.decompile(new Buffer(f.scriptSigHex, 'hex'))
assert.strictEqual(script.toASM(chunks), f.scriptSig)
assert.strictEqual(bscript.toASM(chunks), f.scriptSig)
})
}
if (f.scriptPubKeyHex) {
it('decompiles ' + f.scriptPubKey, function () {
var chunks = script.decompile(new Buffer(f.scriptPubKeyHex, 'hex'))
var chunks = bscript.decompile(new Buffer(f.scriptPubKeyHex, 'hex'))
assert.strictEqual(script.toASM(chunks), f.scriptPubKey)
assert.strictEqual(bscript.toASM(chunks), f.scriptPubKey)
})
}
})
fixtures.invalid.decompile.forEach(function (f) {
it('decompiles ' + f.hex + ' to [] because of "' + f.description + '"', function () {
var chunks = script.decompile(new Buffer(f.hex, 'hex'))
var chunks = bscript.decompile(new Buffer(f.hex, 'hex'))
assert.strictEqual(chunks.length, 0)
})
@ -85,8 +85,8 @@ describe('script', function () {
if (!f.scriptSig) return
it('classifies ' + f.scriptSig + ' as ' + f.type, function () {
var scriptSig = script.fromASM(f.scriptSig)
var type = script.classifyInput(scriptSig)
var scriptSig = bscript.fromASM(f.scriptSig)
var type = bscript.classifyInput(scriptSig)
assert.strictEqual(type, f.type)
})
@ -97,8 +97,8 @@ describe('script', function () {
if (!f.typeIncomplete) return
it('classifies incomplete ' + f.scriptSig + ' as ' + f.typeIncomplete, function () {
var scriptSig = script.fromASM(f.scriptSig)
var type = script.classifyInput(scriptSig, true)
var scriptSig = bscript.fromASM(f.scriptSig)
var type = bscript.classifyInput(scriptSig, true)
assert.strictEqual(type, f.typeIncomplete)
})
@ -110,8 +110,8 @@ describe('script', function () {
if (!f.scriptPubKey) return
it('classifies ' + f.scriptPubKey + ' as ' + f.type, function () {
var scriptPubKey = script.fromASM(f.scriptPubKey)
var type = script.classifyOutput(scriptPubKey)
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
var type = bscript.classifyOutput(scriptPubKey)
assert.strictEqual(type, f.type)
})
@ -122,15 +122,15 @@ describe('script', function () {
var inputFnName = 'is' + type + 'Input'
var outputFnName = 'is' + type + 'Output'
var inputFn = script[inputFnName]
var outputFn = script[outputFnName]
var inputFn = bscript[inputFnName]
var outputFn = bscript[outputFnName]
describe('is' + type + 'Input', function () {
fixtures.valid.forEach(function (f) {
var expected = type.toLowerCase() === f.type
if (inputFn && f.scriptSig) {
var scriptSig = script.fromASM(f.scriptSig)
var scriptSig = bscript.fromASM(f.scriptSig)
it('returns ' + expected + ' for ' + f.scriptSig, function () {
assert.strictEqual(inputFn(scriptSig), expected)
@ -154,9 +154,9 @@ describe('script', function () {
var scriptSig
if (f.scriptSig) {
scriptSig = script.fromASM(f.scriptSig)
scriptSig = bscript.fromASM(f.scriptSig)
} else {
scriptSig = script.fromHex(f.scriptSigHex)
scriptSig = bscript.fromHex(f.scriptSigHex)
}
assert.strictEqual(inputFn(scriptSig), false)
@ -171,7 +171,7 @@ describe('script', function () {
if (outputFn && f.scriptPubKey) {
it('returns ' + expected + ' for ' + f.scriptPubKey, function () {
var scriptPubKey = script.fromASM(f.scriptPubKey)
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
assert.strictEqual(outputFn(scriptPubKey), expected)
})
@ -183,7 +183,7 @@ describe('script', function () {
fixtures.invalid[outputFnName].forEach(function (f) {
if (outputFn && f.scriptPubKey) {
it('returns false for ' + f.description + ' (' + f.scriptPubKey + ')', function () {
var scriptPubKey = script.fromASM(f.scriptPubKey)
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
assert.strictEqual(outputFn(scriptPubKey), false)
})
@ -199,8 +199,8 @@ describe('script', function () {
it('returns ' + f.scriptSig, function () {
var signature = new Buffer(f.signature, 'hex')
var scriptSig = script.pubKeyInput(signature)
assert.strictEqual(script.toASM(scriptSig), f.scriptSig)
var scriptSig = bscript.pubKeyInput(signature)
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
})
})
})
@ -211,9 +211,9 @@ describe('script', function () {
it('returns ' + f.scriptPubKey, function () {
var pubKey = new Buffer(f.pubKey, 'hex')
var scriptPubKey = script.pubKeyOutput(pubKey)
var scriptPubKey = bscript.pubKeyOutput(pubKey)
assert.strictEqual(script.toASM(scriptPubKey), f.scriptPubKey)
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
})
})
})
@ -227,8 +227,8 @@ describe('script', function () {
it('returns ' + f.scriptSig, function () {
var signature = new Buffer(f.signature, 'hex')
var scriptSig = script.pubKeyHashInput(signature, pubKey)
assert.strictEqual(script.toASM(scriptSig), f.scriptSig)
var scriptSig = bscript.pubKeyHashInput(signature, pubKey)
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
})
})
})
@ -241,8 +241,8 @@ describe('script', function () {
var pubKeyHash = bcrypto.hash160(pubKey)
it('returns ' + f.scriptPubKey, function () {
var scriptPubKey = script.pubKeyHashOutput(pubKeyHash)
assert.strictEqual(script.toASM(scriptPubKey), f.scriptPubKey)
var scriptPubKey = bscript.pubKeyHashOutput(pubKeyHash)
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
})
})
@ -251,7 +251,7 @@ describe('script', function () {
it('throws on ' + f.exception, function () {
assert.throws(function () {
script.pubKeyHashOutput(hash)
bscript.pubKeyHashOutput(hash)
}, new RegExp(f.exception))
})
})
@ -266,13 +266,13 @@ describe('script', function () {
return signature ? new Buffer(signature, 'hex') : ops.OP_0
})
var scriptSig = script.multisigInput(signatures)
assert.strictEqual(script.toASM(scriptSig), f.scriptSig)
var scriptSig = bscript.multisigInput(signatures)
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
})
})
fixtures.invalid.multisigInput.forEach(function (f) {
var scriptPubKey = script.fromASM(f.scriptPubKey)
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
it('throws on ' + f.exception, function () {
var signatures = f.signatures.map(function (signature) {
@ -280,7 +280,7 @@ describe('script', function () {
})
assert.throws(function () {
script.multisigInput(signatures, scriptPubKey)
bscript.multisigInput(signatures, scriptPubKey)
}, new RegExp(f.exception))
})
})
@ -291,10 +291,10 @@ describe('script', function () {
if (f.type !== 'multisig') return
var pubKeys = f.pubKeys.map(function (p) { return new Buffer(p, 'hex') })
var scriptPubKey = script.multisigOutput(pubKeys.length, pubKeys)
var scriptPubKey = bscript.multisigOutput(pubKeys.length, pubKeys)
it('returns ' + f.scriptPubKey, function () {
assert.strictEqual(script.toASM(scriptPubKey), f.scriptPubKey)
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
})
})
@ -305,7 +305,7 @@ describe('script', function () {
it('throws on ' + f.exception, function () {
assert.throws(function () {
script.multisigOutput(f.m, pubKeys)
bscript.multisigOutput(f.m, pubKeys)
}, new RegExp(f.exception))
})
})
@ -315,14 +315,14 @@ describe('script', function () {
fixtures.valid.forEach(function (f) {
if (f.type !== 'scripthash') return
var redeemScript = script.fromASM(f.redeemScript)
var redeemScriptSig = script.fromASM(f.redeemScriptSig)
var redeemScript = bscript.fromASM(f.redeemScript)
var redeemScriptSig = bscript.fromASM(f.redeemScriptSig)
it('returns ' + f.scriptSig, function () {
var scriptSig = script.scriptHashInput(redeemScriptSig, redeemScript)
var scriptSig = bscript.scriptHashInput(redeemScriptSig, redeemScript)
if (f.scriptSig) {
assert.strictEqual(script.toASM(scriptSig), f.scriptSig)
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
} else {
assert.strictEqual(scriptSig.toString('hex'), f.scriptSigHex)
@ -337,10 +337,10 @@ describe('script', function () {
if (!f.scriptPubKey) return
it('returns ' + f.scriptPubKey, function () {
var redeemScript = script.fromASM(f.redeemScript)
var scriptPubKey = script.scriptHashOutput(bcrypto.hash160(redeemScript))
var redeemScript = bscript.fromASM(f.redeemScript)
var scriptPubKey = bscript.scriptHashOutput(bcrypto.hash160(redeemScript))
assert.strictEqual(script.toASM(scriptPubKey), f.scriptPubKey)
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
})
})
@ -349,7 +349,7 @@ describe('script', function () {
it('throws on ' + f.exception, function () {
assert.throws(function () {
script.scriptHashOutput(hash)
bscript.scriptHashOutput(hash)
}, new RegExp(f.exception))
})
})
@ -360,10 +360,10 @@ describe('script', function () {
if (f.type !== 'nulldata') return
var data = new Buffer(f.data, 'hex')
var scriptPubKey = script.nullDataOutput(data)
var scriptPubKey = bscript.nullDataOutput(data)
it('returns ' + f.scriptPubKey, function () {
assert.strictEqual(script.toASM(scriptPubKey), f.scriptPubKey)
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
})
})
})

View file

@ -1,9 +1,9 @@
/* global describe, it, beforeEach */
var address = require('../src/address')
var assert = require('assert')
var baddress = require('../src/address')
var bscript = require('../src/script')
var ops = require('../src/opcodes')
var script = require('../src/script')
var BigInteger = require('bigi')
var ECPair = require('../src/ecpair')
@ -21,14 +21,14 @@ function construct (f, sign) {
var prevTxScript
if (input.prevTxScript) {
prevTxScript = script.fromASM(input.prevTxScript)
prevTxScript = bscript.fromASM(input.prevTxScript)
}
txb.addInput(input.txId, input.vout, input.sequence, prevTxScript)
})
f.outputs.forEach(function (output) {
txb.addOutput(script.fromASM(output.script), output.value)
txb.addOutput(bscript.fromASM(output.script), output.value)
})
if (sign === undefined || sign) {
@ -38,7 +38,7 @@ function construct (f, sign) {
var redeemScript
if (sign.redeemScript) {
redeemScript = script.fromASM(sign.redeemScript)
redeemScript = bscript.fromASM(sign.redeemScript)
}
txb.sign(index, keyPair, redeemScript, sign.hashType)
@ -65,7 +65,7 @@ describe('TransactionBuilder', function () {
'1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH',
'1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP'
].map(function (x) {
return address.toOutputScript(x)
return baddress.toOutputScript(x)
})
var txHash = new Buffer('0e7cea811c0be9f73c0aca591034396e7264473fc25c1ca45195d7417b36cbe2', 'hex')
var txb
@ -198,7 +198,7 @@ describe('TransactionBuilder', function () {
var redeemScript
if (sign.redeemScript) {
redeemScript = script.fromASM(sign.redeemScript)
redeemScript = bscript.fromASM(sign.redeemScript)
}
if (!sign.throws) {
@ -260,7 +260,7 @@ describe('TransactionBuilder', function () {
var network = NETWORKS[f.network]
f.inputs.forEach(function (input, i) {
var redeemScript = script.fromASM(input.redeemScript)
var redeemScript = bscript.fromASM(input.redeemScript)
input.signs.forEach(function (sign) {
// rebuild the transaction each-time after the first
@ -270,11 +270,11 @@ describe('TransactionBuilder', function () {
var scriptSig = tx.ins[i].script
// ignore OP_0 on the front, ignore redeemScript
var signatures = script.decompile(scriptSig).slice(1, -1).filter(function (x) { return x !== ops.OP_0 })
var signatures = bscript.decompile(scriptSig).slice(1, -1).filter(function (x) { return x !== ops.OP_0 })
// rebuild/replace the scriptSig without them
var replacement = script.scriptHashInput(script.multisigInput(signatures), redeemScript)
assert.strictEqual(script.toASM(replacement), sign.scriptSigFiltered)
var replacement = bscript.scriptHashInput(bscript.multisigInput(signatures), redeemScript)
assert.strictEqual(bscript.toASM(replacement), sign.scriptSigFiltered)
tx.ins[i].script = replacement
}
@ -290,7 +290,7 @@ describe('TransactionBuilder', function () {
tx = txb.buildIncomplete()
// now verify the serialized scriptSig is as expected
assert.strictEqual(script.toASM(tx.ins[i].script), sign.scriptSig)
assert.strictEqual(bscript.toASM(tx.ins[i].script), sign.scriptSig)
})
})
@ -307,7 +307,7 @@ describe('TransactionBuilder', function () {
txb = TransactionBuilder.fromTransaction(lameTx, network)
var redeemScript = script.fromASM('OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 OP_3 OP_CHECKMULTISIG')
var redeemScript = bscript.fromASM('OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 OP_3 OP_CHECKMULTISIG')
var keyPair = ECPair.fromWIF('91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgx3cTMqe', network)
txb.sign(0, keyPair, redeemScript)