import { WrapPsbt as WasmPsbt, } from "../wasm/wasm_utxo.js";
import { Transaction } from "../transaction.js";
import { PsbtBase } from "../psbtBase.js";
export class Psbt extends PsbtBase {
    constructor(versionOrWasm, lockTime) {
        super(versionOrWasm instanceof WasmPsbt ? versionOrWasm : new WasmPsbt(versionOrWasm, lockTime));
    }
    /** @internal Access the underlying WASM instance */
    get wasm() {
        return this._wasm;
    }
    // -- Static / Factory --
    static create(version, lockTime) {
        return new Psbt(new WasmPsbt(version, lockTime));
    }
    static deserialize(bytes) {
        return new Psbt(WasmPsbt.deserialize(bytes));
    }
    // -- Serialization --
    clone() {
        return new Psbt(this._wasm.clone());
    }
    // -- IPsbt: introspection --
    getOutputsWithAddress(coin) {
        return this._wasm.get_outputs_with_address(coin);
    }
    // -- IPsbt: mutation --
    addInputAtIndex(index, txid, vout, value, script, sequence) {
        return this._wasm.add_input_at_index(index, txid, vout, value, script, sequence);
    }
    addInput(txid, vout, value, script, sequence) {
        return this._wasm.add_input(txid, vout, value, script, sequence);
    }
    addOutputAtIndex(index, script, value) {
        return this._wasm.add_output_at_index(index, script, value);
    }
    addOutput(script, value) {
        return this._wasm.add_output(script, value);
    }
    // -- Descriptor updates --
    updateInputWithDescriptor(inputIndex, descriptor) {
        this._wasm.update_input_with_descriptor(inputIndex, descriptor);
    }
    updateOutputWithDescriptor(outputIndex, descriptor) {
        this._wasm.update_output_with_descriptor(outputIndex, descriptor);
    }
    // -- Signing --
    signWithXprv(xprv) {
        return this._wasm.sign_with_xprv(xprv);
    }
    signWithPrv(prv) {
        return this._wasm.sign_with_prv(prv);
    }
    signAll(key) {
        return this._wasm.sign_all(key);
    }
    signAllWithEcpair(key) {
        return this._wasm.sign_all_with_ecpair(key);
    }
    // -- Signature introspection --
    getPartialSignatures(inputIndex) {
        return this._wasm.get_partial_signatures(inputIndex);
    }
    hasPartialSignatures(inputIndex) {
        return this._wasm.has_partial_signatures(inputIndex);
    }
    // -- Validation --
    validateSignatureAtInput(inputIndex, pubkey) {
        return this._wasm.validate_signature_at_input(inputIndex, pubkey);
    }
    verifySignatureWithKey(inputIndex, key) {
        return this._wasm.verify_signature_with_key(inputIndex, key);
    }
    // -- Transaction extraction --
    getUnsignedTx() {
        return this._wasm.get_unsigned_tx();
    }
    finalize() {
        this._wasm.finalize_mut();
    }
    extractTransaction() {
        return Transaction.fromWasm(this._wasm.extract_transaction());
    }
}
