MCPcopy
hub / github.com/bcoin-org/bcoin / forWitness

Method forWitness

lib/script/script.js:2124–2139  ·  view source on GitHub ↗

* Get the script to the equivalent witness * program (mimics bitcoind's scriptForWitness). * @returns {Script|null}

()

Source from the content-addressed store, hash-verified

2122 */
2123
2124 forWitness() {
2125 if (this.isProgram())
2126 return this.clone();
2127
2128 const pk = this.getPubkey();
2129 if (pk) {
2130 const hash = hash160.digest(pk);
2131 return Script.fromProgram(0, hash);
2132 }
2133
2134 const pkh = this.getPubkeyhash();
2135 if (pkh)
2136 return Script.fromProgram(0, pkh);
2137
2138 return Script.fromProgram(0, this.sha256());
2139 }
2140
2141 /**
2142 * Test whether the output script is

Callers 2

createWitnessAddressMethod · 0.80
node-http-test.jsFile · 0.80

Calls 6

isProgramMethod · 0.95
cloneMethod · 0.95
getPubkeyMethod · 0.95
getPubkeyhashMethod · 0.95
sha256Method · 0.95
fromProgramMethod · 0.45

Tested by

no test coverage detected