btcutil-js - v0.2.0
    Preparing search index...

    Variable psbtConst

    psbt: {
        addInBip32Derivation(
            base64Psbt: string,
            inIndex: number,
            fingerprint: number,
            path: number[],
            pubKey: Bytes,
        ): Promise<string>;
        addInNonWitnessUtxo(
            base64Psbt: string,
            inIndex: number,
            rawTx: Bytes,
        ): Promise<string>;
        addInRedeemScript(
            base64Psbt: string,
            inIndex: number,
            redeemScript: Bytes,
        ): Promise<string>;
        addInSighashType(
            base64Psbt: string,
            inIndex: number,
            sighashType: number,
        ): Promise<string>;
        addInWitnessScript(
            base64Psbt: string,
            inIndex: number,
            witnessScript: Bytes,
        ): Promise<string>;
        addInWitnessUtxo(
            base64Psbt: string,
            inIndex: number,
            value: number,
            pkScript: Bytes,
        ): Promise<string>;
        addOutBip32Derivation(
            base64Psbt: string,
            outIndex: number,
            fingerprint: number,
            path: number[],
            pubKey: Bytes,
        ): Promise<string>;
        addOutRedeemScript(
            base64Psbt: string,
            outIndex: number,
            redeemScript: Bytes,
        ): Promise<string>;
        addOutWitnessScript(
            base64Psbt: string,
            outIndex: number,
            witnessScript: Bytes,
        ): Promise<string>;
        allUnknowns(base64Psbt: string): Promise<PsbtUnknownEntry[]>;
        create(
            inputs: PsbtInput[],
            outputs: PsbtOutput[],
            version?: number,
            lockTime?: number,
        ): Promise<string>;
        decode(base64Psbt: string): Promise<PsbtDecodeResult>;
        decodeExtendedKey(extendedKey: Bytes): Promise<string>;
        encode(data: PsbtData): Promise<string>;
        encodeExtendedKey(
            extendedKey: string,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        extract(base64Psbt: string): Promise<Uint8Array<ArrayBufferLike>>;
        finalize(base64Psbt: string, inIndex: number): Promise<string>;
        fromBase64(base64Psbt: string): Promise<Uint8Array<ArrayBufferLike>>;
        fromUnsignedTx(rawTx: Bytes): Promise<string>;
        getFee(base64Psbt: string): Promise<number>;
        inPlaceSort(base64Psbt: string): Promise<string>;
        inputsReadyToSign(base64Psbt: string): Promise<void>;
        isComplete(base64Psbt: string): Promise<boolean>;
        maybeFinalize(
            base64Psbt: string,
            inIndex: number,
        ): Promise<PsbtMaybeFinalizeResult>;
        maybeFinalizeAll(base64Psbt: string): Promise<string>;
        sanityCheck(base64Psbt: string): Promise<void>;
        sign(
            base64Psbt: string,
            inIndex: number,
            sig: Bytes,
            pubKey: Bytes,
            redeemScript?: Bytes,
            witnessScript?: Bytes,
        ): Promise<PsbtSignResult>;
        sumUtxoInputValues(base64Psbt: string): Promise<number>;
        toBase64(psbtData: Bytes): Promise<string>;
    } = ...

    Partially Signed Bitcoin Transaction (BIP-174) utilities.

    Mutating functions (addIn*, addOut*, sign, finalize*) take a base64 PSBT, apply the change, and return a new base64 PSBT. Chain calls to build up a transaction:

    let p = await psbt.create(inputs, outputs);
    p = await psbt.addInWitnessUtxo(p, 0, 50000, pkScript);
    const { psbt: signed } = await psbt.sign(p, 0, sig, pubKey);
    const finalized = await psbt.maybeFinalizeAll(signed);
    const rawTx = await psbt.extract(finalized);

    Type Declaration

    • addInBip32Derivation: function
      • Add BIP-32 derivation info to an input. Calls Go: psbt.Updater.AddInBip32Derivation() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • fingerprint: number
        • path: number[]
        • pubKey: Bytes

        Returns Promise<string>

    • addInNonWitnessUtxo: function
      • Add a full previous transaction for a non-segwit input. Calls Go: psbt.Updater.AddInNonWitnessUtxo() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • rawTx: Bytes

        Returns Promise<string>

    • addInRedeemScript: function
      • Add a P2SH redeem script to an input. Calls Go: psbt.Updater.AddInRedeemScript() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • redeemScript: Bytes

        Returns Promise<string>

    • addInSighashType: function
      • Set the sighash type for an input. Calls Go: psbt.Updater.AddInSighashType() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • sighashType: number

        Returns Promise<string>

    • addInWitnessScript: function
      • Add a witness script to an input. Calls Go: psbt.Updater.AddInWitnessScript() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • witnessScript: Bytes

        Returns Promise<string>

    • addInWitnessUtxo: function
      • Add a witness UTXO (value + pkScript) for a segwit input. Calls Go: psbt.Updater.AddInWitnessUtxo() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • value: number
        • pkScript: Bytes

        Returns Promise<string>

    • addOutBip32Derivation: function
      • Add BIP-32 derivation info to an output. Calls Go: psbt.Updater.AddOutBip32Derivation() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • outIndex: number
        • fingerprint: number
        • path: number[]
        • pubKey: Bytes

        Returns Promise<string>

    • addOutRedeemScript: function
      • Add a P2SH redeem script to an output. Calls Go: psbt.Updater.AddOutRedeemScript() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • outIndex: number
        • redeemScript: Bytes

        Returns Promise<string>

    • addOutWitnessScript: function
      • Add a witness script to an output. Calls Go: psbt.Updater.AddOutWitnessScript() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • outIndex: number
        • witnessScript: Bytes

        Returns Promise<string>

    • allUnknowns: function
      • Return every unknown TLV entry from a PSBT, flattened across all three levels (global / input / output) into a single stream.

        Parameters

        • base64Psbt: string

        Returns Promise<PsbtUnknownEntry[]>

    • create: function
      • Create a new PSBT from inputs and outputs. Calls Go: psbt.New() from btcutil/psbt.

        Parameters

        • inputs: PsbtInput[]

          Array of { txid, vout, sequence? }.

        • outputs: PsbtOutput[]

          Array of { value, script }.

        • Optionalversion: number
        • OptionallockTime: number

        Returns Promise<string>

        Base64-encoded PSBT.

    • decode: function
      • Decode a base64-encoded PSBT and return structured info including all per-input and per-output fields (partial sigs, BIP-32 derivation, taproot fields, etc.) plus the unsigned transaction as unsignedTx. Calls Go: psbt.NewFromRawBytes() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<PsbtDecodeResult>

    • decodeExtendedKey: function
      • Decode the 78-byte PSBT-format byte slice back to the base58 xpub/xprv string. Wraps psbt.DecodeExtendedKey.

        Parameters

        Returns Promise<string>

    • encode: function
      • Encode a PSBT (the encode-input shape PsbtData) back to a base64-encoded PSBT string. Round-trips with decode(). Empty PSBTs (zero inputs / zero outputs) are accepted — useful when building one from scratch. Calls Go: btcpsbt.Packet.Serialize() via direct construction.

        Parameters

        Returns Promise<string>

    • encodeExtendedKey: function
      • Encode an xpub/xprv string to the 78-byte PSBT-format byte slice (i.e. the checksum-less base58 decoding) used in the PSBT_GLOBAL_XPUB key. Wraps psbt.EncodeExtendedKey.

        Parameters

        • extendedKey: string

        Returns Promise<Uint8Array<ArrayBufferLike>>

    • extract: function
      • Extract the final signed transaction from a completed PSBT. Calls Go: psbt.Extract() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<Uint8Array<ArrayBufferLike>>

    • finalize: function
      • Finalize a specific input (create final scriptSig/witness). Calls Go: psbt.Finalize() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number

        Returns Promise<string>

    • fromBase64: function
      • Convert a base64 PSBT to raw bytes. Calls Go: psbt.Packet.Serialize() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<Uint8Array<ArrayBufferLike>>

    • fromUnsignedTx: function
      • Create a new PSBT from an unsigned raw transaction. Calls Go: psbt.NewFromUnsignedTx() from btcutil/psbt.

        Parameters

        Returns Promise<string>

    • getFee: function
      • Get the transaction fee in satoshis (requires UTXO info on all inputs). Calls Go: psbt.Packet.GetTxFee() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<number>

    • inPlaceSort: function
      • Sort inputs and outputs in-place per BIP-69. Calls Go: psbt.InPlaceSort() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<string>

    • inputsReadyToSign: function
      • Verify all inputs have UTXO information attached. Throws on error. Calls Go: psbt.InputsReadyToSign() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<void>

    • isComplete: function
      • Check if all inputs are finalized and ready to extract. Calls Go: psbt.Packet.IsComplete() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<boolean>

    • maybeFinalize: function
      • Try to finalize a specific input. Returns whether it was finalized. Calls Go: psbt.MaybeFinalize() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number

        Returns Promise<PsbtMaybeFinalizeResult>

    • maybeFinalizeAll: function
      • Try to finalize all inputs at once. Calls Go: psbt.MaybeFinalizeAll() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<string>

    • sanityCheck: function
      • Validate PSBT format per BIP-174. Throws on error. Calls Go: psbt.Packet.SanityCheck() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<void>

    • sign: function
      • Attach a signature to an input. Returns the updated PSBT and the sign outcome (0=success, 1=already finalized, -1=invalid). Calls Go: psbt.Updater.Sign() from btcutil/psbt.

        Parameters

        • base64Psbt: string
        • inIndex: number
        • sig: Bytes
        • pubKey: Bytes
        • OptionalredeemScript: Bytes
        • OptionalwitnessScript: Bytes

        Returns Promise<PsbtSignResult>

    • sumUtxoInputValues: function
      • Sum all input UTXO values in satoshis. Calls Go: psbt.SumUtxoInputValues() from btcutil/psbt.

        Parameters

        • base64Psbt: string

        Returns Promise<number>

    • toBase64: function
      • Convert raw PSBT bytes to base64. Calls Go: psbt.Packet.B64Encode() from btcutil/psbt.

        Parameters

        Returns Promise<string>