|
|
@ -7,6 +7,15 @@ var PublicKey = require('./publickey'); |
|
|
|
var Hash = require('./crypto/hash'); |
|
|
|
var bu = require('./util/buffer'); |
|
|
|
|
|
|
|
/** |
|
|
|
* A bitcoin transaction script. Each transaction's inputs and outputs |
|
|
|
* has a script that is evaluated to validate it's spending. |
|
|
|
* |
|
|
|
* See https://en.bitcoin.it/wiki/Script
|
|
|
|
* |
|
|
|
* @constructor |
|
|
|
* @param {Object|string|Buffer} [from] optional data to populate script |
|
|
|
*/ |
|
|
|
var Script = function Script(from) { |
|
|
|
if (!(this instanceof Script)) { |
|
|
|
return new Script(from); |
|
|
@ -427,6 +436,8 @@ Script.prototype._addBuffer = function(buf, prepend) { |
|
|
|
/** |
|
|
|
* @returns a new Multisig output script for given public keys, |
|
|
|
* requiring m of those public keys to spend |
|
|
|
* @param {PublicKey[]} pubkeys - list of all public keys controlling the output |
|
|
|
* @param {number} m - amount of required signatures to spend the output |
|
|
|
*/ |
|
|
|
Script.buildMultisigOut = function(pubkeys, m) { |
|
|
|
var s = new Script(); |
|
|
@ -443,6 +454,7 @@ Script.buildMultisigOut = function(pubkeys, m) { |
|
|
|
/** |
|
|
|
* @returns a new pay to public key hash output for the given |
|
|
|
* address or public key |
|
|
|
* @param {(Address|PublicKey)} to - destination address or public key |
|
|
|
*/ |
|
|
|
Script.buildPublicKeyHashOut = function(to) { |
|
|
|
if (to instanceof PublicKey) { |
|
|
@ -470,6 +482,7 @@ Script.buildPublicKeyOut = function(pubkey) { |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns a new OP_RETURN script with data |
|
|
|
* @param {(string|Buffer)} to - the data to embed in the output |
|
|
|
*/ |
|
|
|
Script.buildDataOut = function(data) { |
|
|
|
if (typeof data === 'string') { |
|
|
@ -483,6 +496,7 @@ Script.buildDataOut = function(data) { |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns a new pay to script hash script for given script |
|
|
|
* @param {Script} script - the redeemScript for the new p2sh output |
|
|
|
*/ |
|
|
|
Script.buildScriptHashOut = function(script) { |
|
|
|
var s = new Script(); |
|
|
|