diff --git a/src/script.js b/src/script.js index 24e8e56..8a28f10 100644 --- a/src/script.js +++ b/src/script.js @@ -268,6 +268,16 @@ Script.prototype.writeBytes = function(data) { this.chunks.push(data) } +// {pubKey} OP_CHECKSIG +Script.createPubKeyScriptPubKey = function(pubKey) { + var script = new Script() + + script.writeBytes(pubKey.toBuffer()) + script.writeOp(opcodes.OP_CHECKSIG) + + return script +} + // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG Script.createPubKeyHashScriptPubKey = function(hash) { var script = new Script() @@ -309,6 +319,13 @@ Script.createMultisigScriptPubKey = function(m, pubKeys) { return script } +// {signature} +Script.createPubKeyScriptSig = function(signature) { + var script = new Script() + script.writeBytes(signature) + return script +} + // {signature} {pubKey} Script.createPubKeyHashScriptSig = function(signature, pubKey) { var script = new Script() diff --git a/test/fixtures/script.json b/test/fixtures/script.json index 17d2f64..1c1fa4a 100644 --- a/test/fixtures/script.json +++ b/test/fixtures/script.json @@ -1,5 +1,13 @@ { "valid": [ + { + "description": "pay-to-PubKey", + "hex": "21031f1e68f82112b373f0fe980b3a89d212d2b5c01fb51eb25acb8b4c4b4299ce95ac", + "type": "pubkey", + "hash": "26e645ab170255f2a0a82d29e48f35b14ae7c826", + "pubKey": "031f1e68f82112b373f0fe980b3a89d212d2b5c01fb51eb25acb8b4c4b4299ce95", + "scriptPubKey": true + }, { "description": "P2SH ScriptPubKey", "hex": "a914e8c300c87986efa84c37c0519929019ef86eb5b487", diff --git a/test/script.js b/test/script.js index 1de6cbd..41efcbd 100644 --- a/test/script.js +++ b/test/script.js @@ -70,21 +70,34 @@ describe('Script', function() { describe('pay-to-pubKeyHash', function() { it('matches the test data', function() { + // FIXME: bad + var f = fixtures.valid[2] var address = Address.fromBase58Check('19E6FV3m3kEPoJD5Jz6dGKdKwTVvjsWUvu') var script = Script.createPubKeyHashScriptPubKey(address.hash) - // FIXME: not good TDD - assert.equal(script.toHex(), fixtures.valid[1].hex) + assert.equal(script.toHex(), f.hex) + }) + }) + + describe('pay-to-pubkey', function() { + it('matches the test data', function() { + // FIXME: bad + var f = fixtures.valid[0] + var pubKey = ECPubKey.fromHex(f.pubKey) + var script = Script.createPubKeyScriptPubKey(pubKey) + + assert.equal(script.toHex(), f.hex) }) }) describe('pay-to-scriptHash', function() { it('matches the test data', function() { - var hash = new Buffer('e8c300c87986efa84c37c0519929019ef86eb5b4', 'hex') - var script = Script.createP2SHScriptPubKey(hash) + // FIXME: bad + var f = fixtures.valid[1] + var address = Address.fromBase58Check('3NukJ6fYZJ5Kk8bPjycAnruZkE5Q7UW7i8') + var script = Script.createP2SHScriptPubKey(address.hash) - // FIXME: not good TDD - assert.equal(script.toHex(), fixtures.valid[0].hex) + assert.equal(script.toHex(), f.hex) }) })