@node-lightning/wire
Version:
Lightning Network Wire Protocol
53 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShutdownMessage = void 0;
const bufio_1 = require("@node-lightning/bufio");
const MessageType_1 = require("../MessageType");
const core_1 = require("@node-lightning/core");
/**
* ShutdownMessage represents the `shutdown` message defined in BOLT #2 of the Lightning
* Specification. This message can be sent by either node. The scriptPubKey must be a valid P2WPKH,
* P2WSH, P2SH-P2WPKH, P2SH-P2WSH, or any valid witness script if option_shutdown_anysegwit is
* negotiated and it should be same as `shutdown_scriptpubkey` value if it was sent during
* `'open/accept' channel message`. Therefore, if both conditions hold true resulting transaction
* will propagate to miners. If shutdown is sent by either node, corresponding node should send
* commitment_signed to commit any outstanding changes before replying shutdown. Once shutdown is
* sent by both nodes no new HTLCs should be added or accepted by the channel. After successful
* handshake of shutdown message, fee negotiation and signature sending can begin with
* `closing_signed` message.
*/
class ShutdownMessage {
constructor() {
/**
* The type for message. Shutdown = 38
*/
this.type = ShutdownMessage.type;
}
/**
* Deserializes a shutdown message
* @param buf
*/
static deserialize(buf) {
const instance = new ShutdownMessage();
const reader = new bufio_1.BufferReader(buf);
reader.readUInt16BE(); // read type
instance.channelId = new core_1.ChannelId(reader.readBytes(32));
const len = reader.readUInt16BE();
instance.scriptPubKey = reader.readBytes(len);
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.writeUInt16BE(this.scriptPubKey.length);
writer.writeBytes(this.scriptPubKey);
return writer.toBuffer();
}
}
exports.ShutdownMessage = ShutdownMessage;
ShutdownMessage.type = MessageType_1.MessageType.Shutdown;
//# sourceMappingURL=ShutdownMessage.js.map