text: shadow$provide.module$node_modules$bitcoinjs_lib$src$payments$p2wsh=function(global,process,require,module,exports,shadow$shims){function stacksEqual(a,b){return a.length!==b.length?!1:a.every(function(x,i){return x.equals(b[i])})}var lazy=require("module$node_modules$bitcoinjs_lib$src$payments$lazy"),typef=require("module$node_modules$typeforce$index"),OPS=require("module$node_modules$bitcoin_ops$index_json"),bech32=require("module$node_modules$bech32$index"),bcrypto=require("module$node_modules$bitcoinjs_lib$src$crypto"),
  bscript=require("module$node_modules$bitcoinjs_lib$src$script"),BITCOIN_NETWORK=require("module$node_modules$bitcoinjs_lib$src$networks").bitcoin,EMPTY_BUFFER=shadow$shims.Buffer.alloc(0);module.exports=function(a,opts){if(!(a.address||a.hash||a.output||a.redeem||a.witness))throw new TypeError("Not enough data");opts=Object.assign({validate:!0},opts||{});typef({network:typef.maybe(typef.Object),address:typef.maybe(typef.String),hash:typef.maybe(typef.BufferN(32)),output:typef.maybe(typef.BufferN(34)),
  redeem:typef.maybe({input:typef.maybe(typef.Buffer),network:typef.maybe(typef.Object),output:typef.maybe(typef.Buffer),witness:typef.maybe(typef.arrayOf(typef.Buffer))}),input:typef.maybe(typef.BufferN(0)),witness:typef.maybe(typef.arrayOf(typef.Buffer))},a);var _address=lazy.value(function(){var result=bech32.decode(a.address),version=result.words.shift(),data=bech32.fromWords(result.words);return{version:version,prefix:result.prefix,data:shadow$shims.Buffer.from(data)}}),_rchunks=lazy.value(function(){return bscript.decompile(a.redeem.input)}),
  network=a.network||BITCOIN_NETWORK,o={network:network};lazy.prop(o,"address",function(){if(o.hash){var words=bech32.toWords(o.hash);words.unshift(0);return bech32.encode(network.bech32,words)}});lazy.prop(o,"hash",function(){if(a.output)return a.output.slice(2);if(a.address)return _address().data;if(o.redeem&&o.redeem.output)return bcrypto.sha256(o.redeem.output)});lazy.prop(o,"output",function(){if(o.hash)return bscript.compile([OPS.OP_0,o.hash])});lazy.prop(o,"redeem",function(){if(a.witness)return{output:a.witness[a.witness.length-
  1],input:EMPTY_BUFFER,witness:a.witness.slice(0,-1)}});lazy.prop(o,"input",function(){if(o.witness)return EMPTY_BUFFER});lazy.prop(o,"witness",function(){if(a.redeem&&a.redeem.input&&0<a.redeem.input.length&&a.redeem.output&&0<a.redeem.output.length){var stack=bscript.toStack(_rchunks());o.redeem=Object.assign({witness:stack},a.redeem);o.redeem.input=EMPTY_BUFFER;return[].concat(stack,a.redeem.output)}if(a.redeem&&a.redeem.output&&a.redeem.witness)return[].concat(a.redeem.witness,a.redeem.output)});
  if(opts.validate){if(a.address){if(_address().prefix!==network.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==_address().version)throw new TypeError("Invalid address version");if(32!==_address().data.length)throw new TypeError("Invalid address data");var hash=_address().data}if(a.hash){if(hash&&!hash.equals(a.hash))throw new TypeError("Hash mismatch");hash=a.hash}if(a.output){if(34!==a.output.length||a.output[0]!==OPS.OP_0||32!==a.output[1])throw new TypeError("Output is invalid");
  opts=a.output.slice(2);if(hash&&!hash.equals(opts))throw new TypeError("Hash mismatch");hash=opts}if(a.redeem){if(a.redeem.network&&a.redeem.network!==network)throw new TypeError("Network mismatch");if(a.redeem.input&&0<a.redeem.input.length&&a.redeem.witness&&0<a.redeem.witness.length)throw new TypeError("Ambiguous witness source");if(a.redeem.output){if(0===bscript.decompile(a.redeem.output).length)throw new TypeError("Redeem.output is invalid");opts=bcrypto.sha256(a.redeem.output);if(hash&&!hash.equals(opts))throw new TypeError("Hash mismatch");
  hash=opts}if(a.redeem.input&&!bscript.isPushOnly(_rchunks()))throw new TypeError("Non push-only scriptSig");if(a.witness&&a.redeem.witness&&!stacksEqual(a.witness,a.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");}if(a.witness&&a.redeem&&a.redeem.output&&!a.redeem.output.equals(a.witness[a.witness.length-1]))throw new TypeError("Witness and redeem.output mismatch");}return Object.assign(o,a)}}
  //# sourceMappingURL=module$node_modules$bitcoinjs_lib$src$payments$p2wsh.js.map
  