aegis/lib/dgb/psbt/sign.js

25 lines
1,022 B
JavaScript
Raw Normal View History

// Sign every input of a PSBT with the given key. Fails loudly if any
// input can't be signed by this key (rather than silently leaving it
// unsigned), so callers notice before broadcasting a half-signed tx.
export function signAllInputs(psbt, keyPair) {
psbt.signAllInputs(keyPair);
return psbt;
}
// After all inputs are signed by all necessary parties, finalize and
// extract the network-ready hex-encoded transaction.
export function finalizeAndExtract(psbt) {
psbt.finalizeAllInputs();
const tx = psbt.extractTransaction();
return { hex: tx.toHex(), txid: tx.getId() };
}
// Fee computed from the difference between total input value and total
// output value. Requires all inputs to have witnessUtxo or
// nonWitnessUtxo populated (which `buildPsbt` in this package
// guarantees when the caller populates Utxo.value fields).
export function feeSats(psbt) {
return psbt.getFee();
}
export function feeRateSatsPerByte(psbt) {
return psbt.getFeeRate();
}
//# sourceMappingURL=sign.js.map