Class: Witness

script.Witness

new Witness(items)

Refers to the witness field of segregated witness transactions.

Parameters:
Name Type Description
items Array:.<Buffer:> | NakedWitness

Array of stack items.

Properties:
Name Type Attributes Description
items Array:.<Buffer:>
redeem Script <nullable>
length Number
Source:

Methods

(static) encodeItem(data) → {Buffer}

Encode a witness item.

Parameters:
Name Type Description
data Number | String | Buffer | BN
Source:
Returns:
Type
Buffer

(static) fromArray(items) → {Witness}

Insantiate witness from an array of buffers.

Parameters:
Name Type Description
items Array:.<Buffer:>
Source:
Returns:
Type
Witness

(static) fromJSON(json) → {Witness}

Insantiate witness from a hex string.

Parameters:
Name Type Description
json String
Source:
Returns:
Type
Witness

(static) fromOptions(options) → {Witness}

Instantiate witness from options.

Parameters:
Name Type Description
options Object
Source:
Returns:
Type
Witness

(static) fromRaw(data, encnullable) → {Witness}

Create a witness from a serialized buffer.

Parameters:
Name Type Attributes Description
data Buffer | String

Serialized witness.

enc String <nullable>

Either "hex" or null.

Source:
Returns:
Type
Witness

(static) fromReader(br)

Create a witness from a buffer reader.

Parameters:
Name Type Description
br BufferReader
Source:

(static) fromString(items) → {Witness}

Parse a test script/array string into a witness object. Must contain only stack items (no non-push opcodes).

Parameters:
Name Type Description
items String | Array:.<String:>

Script string.

Source:
Throws:

Parse error.

Returns:
Type
Witness

(static) isWitness(obj) → {Boolean}

Test an object to see if it is a Witness.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

clear()

Clear the witness items.

Source:

clone() → {Witness}

Clone the witness object.

Source:
Returns:

A clone of the current witness object.

Type
Witness

compile()

Does nothing currently.

Source:

(private) fromArray(items)

Inject properties from an array of buffers.

Parameters:
Name Type Description
items Array:.<Buffer:>
Source:

(private) fromJSON(json)

Inject properties from json object.

Parameters:
Name Type Description
json String
Source:

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options Object
Source:

(private) fromRaw(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:

(private) fromReader(br)

Inject properties from buffer reader.

Parameters:
Name Type Description
br BufferReader
Source:

(private) fromString(items)

Inject items from string.

Parameters:
Name Type Description
items String | Array:.<String:>
Source:

get(index) → {Buffer}

Get an item from the witness vector.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
Buffer

getInputAddress() → {Address|null}

"Guess" the address of the witness. This method is not 100% reliable.

Source:
Returns:
Type
Address | null

getInputType() → {ScriptType}

"Guess" the type of the witness. This method is not 100% reliable.

Source:
Returns:
Type
ScriptType

getNumber(index) → {BN}

Get a number from the witness vector.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
BN

getRedeem() → {Script}

Grab and deserialize the redeem script from the witness.

Source:
Returns:

Redeem script.

Type
Script

getSize() → {Number}

Calculate size of the witness excluding the varint size bytes.

Source:
Returns:
Type
Number

getSmall(index) → {Number}

Get a small int (0-16) from the witness vector.

Parameters:
Name Type Description
index Number
Source:
Returns:

-1 on non-existent.

Type
Number

getString(index) → {String}

Get a string from the witness vector.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
String

getVarSize() → {Number}

Calculate size of the witness including the varint size bytes.

Source:
Returns:
Type
Number

indexOf(data) → {Number}

Find a data element in a witness.

Parameters:
Name Type Description
data Buffer

Data element to match against.

Source:
Returns:

Index (-1 if not present).

Type
Number

(private) inject(witness) → {Witness}

Inject properties from witness. Used for cloning.

Parameters:
Name Type Description
witness Witness
Source:
Returns:
Type
Witness

insert(index, data)

Insert an item into the witness vector.

Parameters:
Name Type Description
index Number
data Number | String | Buffer | BN
Source:

inspect() → {String}

Inspect a Witness object.

Source:
Returns:

Human-readable script.

Type
String

isMultisigInput() → {Boolean}

"Test" whether the witness is a multisig input. Always returns false.

Source:
Returns:
Type
Boolean

isPubkeyhashInput() → {Boolean}

"Guess" whether the witness is a pubkeyhash input. This method is not 100% reliable.

Source:
Returns:
Type
Boolean

isPubkeyInput() → {Boolean}

"Test" whether the witness is a pubkey input. Always returns false.

Source:
Returns:
Type
Boolean

isScripthashInput() → {Boolean}

"Guess" whether the witness is a scripthash input. This method is not 100% reliable.

Source:
Returns:
Type
Boolean

isUnknownInput() → {Boolean}

"Guess" whether the witness is an unknown/non-standard type. This method is not 100% reliable.

Source:
Returns:
Type
Boolean

(private) length_getter() → {Number}

Getter to retrieve witness vector length.

Source:
Returns:
Type
Number

(private) length_setter(value) → {Number}

Setter to set witness vector length.

Parameters:
Name Type Description
value Number
Source:
Returns:
Type
Number

pop() → {Buffer}

Shift an item off the witness vector.

Source:
Returns:
Type
Buffer

push(data) → {Number}

Push an item onto the witness vector.

Parameters:
Name Type Description
data Number | String | Buffer | BN
Source:
Returns:
Type
Number

remove(index) → {Buffer}

Remove an item from the witness vector.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
Buffer

set(index, data)

Set an item in the witness vector.

Parameters:
Name Type Description
index Number
data Number | String | Buffer | BN
Source:

shift() → {Buffer}

Shift an item off the witness vector.

Source:
Returns:
Type
Buffer

test(filter) → {Boolean}

Test the witness against a bloom filter.

Parameters:
Name Type Description
filter Bloom
Source:
Returns:
Type
Boolean

toArray() → {Array:.<Buffer:>}

Convert witness to an array of buffers.

Source:
Returns:
Type
Array:.<Buffer:>

toASM(decodenullable) → {String}

Format the witness object as bitcoind asm.

Parameters:
Name Type Attributes Description
decode Boolean <nullable>

Attempt to decode hash types.

Source:
Returns:

Human-readable script.

Type
String

toJSON() → {String}

Convert witness to a hex string.

Source:
Returns:
Type
String

toRaw(enc) → {Buffer|String}

Encode the witness to a Buffer.

Parameters:
Name Type Description
enc String

Encoding, either 'hex' or null.

Source:
Returns:

Serialized script.

Type
Buffer | String

toStack() → {Stack}

Convert the Witness to a Stack object. This is usually done before executing a witness program.

Source:
Returns:
Type
Stack

toString() → {String}

Convert a Witness object to a String.

Source:
Returns:

Human-readable script.

Type
String

toWriter(bw)

Write witness to a buffer writer.

Parameters:
Name Type Description
bw BufferWriter
Source:

unshift(data) → {Number}

Unshift an item onto the witness vector.

Parameters:
Name Type Description
data Number | String | Buffer | BN
Source:
Returns:
Type
Number