new Script(from)
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
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
from |
Object | string | Buffer |
<optional> |
optional data to populate script |
Methods
-
<static> buildDataOut(to)
-
Parameters:
Name Type Description tostring | Buffer the data to embed in the output
Returns:
a new OP_RETURN script with data
-
<static> buildMultisigOut(pubkeys, m, opts)
-
Parameters:
Name Type Argument Description pubkeysArray.<PublicKey> list of all public keys controlling the output
mnumber amount of required signatures to spend the output
optsObject <optional>
Several options:
- noSorting: defaults to false, if true, don't sort the given public keys before creating the scriptReturns:
a new Multisig output script for given public keys, requiring m of those public keys to spend
-
<static> buildP2SHMultisigIn(pubkeys, threshold, signatures, opts)
-
A new P2SH Multisig input script for the given public keys, requiring m of those public keys to spend
Parameters:
Name Type Argument Description pubkeysArray.<PublicKey> list of all public keys controlling the output
thresholdnumber amount of required signatures to spend the output
signaturesArray signatures to append to the script
optsObject <optional>
Properties
Name Type Argument Description noSortingboolean <optional>
don't sort the given public keys before creating the script (false by default)
cachedMultisigScript <optional>
don't recalculate the redeemScript
Returns:
Script
-
<static> buildPublicKeyHashIn(publicKey, signature, sigtype)
-
Builds a scriptSig (a script for an input) that signs a public key hash output script.
Parameters:
Name Type Argument Description publicKeyBuffer | string | PublicKey signatureBuffer the signature in DER cannonical encoding
sigtypenumber <optional>
the type of the signature (defaults to SIGHASH_ALL)
-
<static> buildPublicKeyHashOut(to)
-
Parameters:
Name Type Description toAddress | PublicKey destination address or public key
Returns:
a new pay to public key hash output for the given address or public key
-
<static> buildPublicKeyOut()
-
Returns:
a new pay to public key output for the given public key
-
<static> buildScriptHashOut(script)
-
Parameters:
Name Type Description scriptScript the redeemScript for the new p2sh output
Returns:
Script new pay to script hash script for given script
-
<static> empty()
-
Returns:
Script an empty script
-
<static> fromAddress()
-
Returns:
Script a script built from the address
-
add(obj) → {Script}
-
Adds a script element to the end of the script.
Parameters:
Name Type Description obj* a string, number, Opcode, Bufer, or object to add
Returns:
this script instance
- Type
- Script
-
classify() → {object}
-
Returns:
The Script type if it is a known form, or Script.UNKNOWN if it isn't
- Type
- object
-
equals()
-
Compares a script with another script
-
isDataOut()
-
Returns:
true if this is an OP_RETURN data script
-
isMultisigIn()
-
Returns:
true if this is a multisig input script
-
isMultisigOut()
-
Returns:
true if this is a mutlsig output script
-
isPublicKeyHashIn()
-
Returns:
true if this is a pay to public key hash input script
-
isPublicKeyHashOut()
-
Returns:
true if this is a pay to pubkey hash output script
-
isPublicKeyIn()
-
Returns:
true if this is a pay to public key input script
-
isPublicKeyOut()
-
Returns:
true if this is a public key output script
-
isPushOnly()
-
Returns:
true if the script is only composed of data pushing opcodes or small int opcodes (OP_0, OP_1, ..., OP_16)
-
isScriptHashIn()
-
Returns:
true if this is a p2sh input script Note that these are frequently indistinguishable from pubkeyhashin
-
isScriptHashOut()
-
Returns:
true if this is a p2sh output script
-
isStandard()
-
Returns:
true if script is one of the known types
-
prepend(obj) → {Script}
-
Adds a script element at the start of the script.
Parameters:
Name Type Description obj* a string, number, Opcode, Bufer, or object to add
Returns:
this script instance
- Type
- Script
-
toScriptHashOut()
-
Returns:
Script a new pay to script hash script that pays to this script