@node-dlc/wire
Version:
Lightning Network Wire Protocol
71 lines • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorMessage = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
/**
* This message is defined in BOLT #1 and is used for telling
* a peer that something is incorrect. The message can indicate
* which channel is in error, or if channelId is 0, it refers
* to all channels.
*
* These message can indicate protocol violations or internal
* errors that make channels unusable or that make further
* communication unusable.
*/
class ErrorMessage {
constructor() {
/**
* Message type 17
*/
this.type = MessageType_1.MessageType.Error;
/**
* channelId is used to indicate the failing channel. It
* can have a value of 0 to indicate there is an error with
* all channels.
*
* All error messsagees sent before (and including) the
* funding_created messagee should use the temporary_channel_id
* instead of the channel_id.
*/
this.channelId = 0;
/**
* Data field may be empty. May contain the raw, hex-encoded
* transaction in reply to a invalid signature check in
* funding_created, funding_signed, closing_signed, or
* commitment_signed messages.
*/
this.data = Buffer.alloc(0);
}
/**
* Deserializes an error message into an ErrorMessage
* instance.
*/
static deserialize(payload) {
const reader = new bufio_1.BufferReader(payload);
reader.readUInt16BE(); // read type
const instance = new ErrorMessage();
instance.channelId = reader.readUInt32BE();
const len = reader.readUInt16BE();
instance.data = reader.readBytes(len);
return instance;
}
/**
* Serialize the ErorrMessage into a Buffer that
* can be send on the wire.
*/
serialize() {
const len = 2 + // type
4 + // channel_id
2 + // len
this.data.length;
const writer = new bufio_1.BufferWriter(Buffer.alloc(len));
writer.writeUInt16BE(this.type);
writer.writeUInt32BE(this.channelId);
writer.writeUInt16BE(this.data.length);
writer.writeBytes(this.data);
return writer.toBuffer();
}
}
exports.ErrorMessage = ErrorMessage;
//# sourceMappingURL=ErrorMessage.js.map