@node-lightning/wire
Version:
Lightning Network Wire Protocol
54 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClosingSignedMessage = void 0;
const bufio_1 = require("@node-lightning/bufio");
const core_1 = require("@node-lightning/core");
const MessageType_1 = require("../MessageType");
/**
* The `closing_signed` message is sent by the channel funder after
* the `shutdown_message`. The funder chooses a fee it thinks
* is fair, and signs the closing transaction with the scriptpubkey fields from
* the shutdown messages (along with its chosen fee) and sends the signature.
* The other node then replies similarly, using a fee it thinks is fair.
* One of the benefits of mutual close is that the fee rate can be negotiated
* down from the existing fee rate(which is generally expensive) to a more reasonable one.
* In order for fee rate to converge, it has to be strictly between the last proposed
* and the counterparty's last proposed value. This exchange continues using the
* channelID until both agree on the same fee or when one side fails the channel.
*/
class ClosingSignedMessage {
constructor() {
/**
* The type for message. Closing_Signed = 39
*/
this.type = ClosingSignedMessage.type;
}
/**
* Deserializes the closing_signed message
* @param buf
* @returns
*/
static deserialize(buf) {
const instance = new ClosingSignedMessage();
const reader = new bufio_1.BufferReader(buf);
reader.readUInt16BE(); // read type
instance.channelId = new core_1.ChannelId(reader.readBytes(32));
instance.feeSatoshis = core_1.Value.fromSats(reader.readUInt64BE());
instance.signature = reader.readBytes(64);
return instance;
}
/**
* Serializes the message into a Buffer
*/
serialize() {
const writer = new bufio_1.BufferWriter();
writer.writeUInt16BE(this.type);
writer.writeBytes(this.channelId.toBuffer());
writer.writeUInt64BE(this.feeSatoshis.sats);
writer.writeBytes(this.signature);
return writer.toBuffer();
}
}
exports.ClosingSignedMessage = ClosingSignedMessage;
ClosingSignedMessage.type = MessageType_1.MessageType.ClosingSigned;
//# sourceMappingURL=ClosingSignedMessage.js.map