import { WrapPsbt as WasmPsbt, } from "../wasm/wasm_utxo.js";
import { Transaction } from "../transaction.js";
export class Psbt {
    _wasm;
    constructor(versionOrWasm, lockTime) {
        if (versionOrWasm instanceof WasmPsbt) {
            this._wasm = versionOrWasm;
        }
        else {
            this._wasm = 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 --
    serialize() {
        return this._wasm.serialize();
    }
    clone() {
        return new Psbt(this._wasm.clone());
    }
    // -- IPsbt: introspection --
    inputCount() {
        return this._wasm.input_count();
    }
    outputCount() {
        return this._wasm.output_count();
    }
    version() {
        return this._wasm.version();
    }
    lockTime() {
        return this._wasm.lock_time();
    }
    unsignedTxId() {
        return this._wasm.unsigned_tx_id();
    }
    getInputs() {
        return this._wasm.get_inputs();
    }
    getOutputs() {
        return this._wasm.get_outputs();
    }
    getGlobalXpubs() {
        return this._wasm.get_global_xpubs();
    }
    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);
    }
    removeInput(index) {
        this._wasm.remove_input(index);
    }
    removeOutput(index) {
        this._wasm.remove_output(index);
    }
    // -- 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());
    }
}
