@node-dlc/core
Version:
52 lines • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelId = void 0;
const bitcoin_1 = require("@node-dlc/bitcoin");
/**
* ChannelId type that that encapsulates an outpoint as a 32-byte value
* and is used to identify a channel. This type is defined in BOLT 2
* under the peer protocol. It is defined as combinging the funding_txid
* and the funding_output_index, using big-endian XOR (meaning the
* output_index modifies the last two bytes).
*/
class ChannelId {
static fromOutPoint(outpoint) {
const txid = outpoint.txid.serialize(bitcoin_1.HashByteOrder.RPC);
if (outpoint.outputIndex > 0xffff) {
throw new Error('Invalid output index length');
}
txid[30] ^= outpoint.outputIndex >> 8;
txid[31] ^= outpoint.outputIndex & 0xff;
return new ChannelId(txid);
}
constructor(value) {
this.value = value;
}
/**
* Converts the ChannelId into a buffer
*/
toBuffer() {
return Buffer.from(this.value);
}
/**
* Converts the ChannelId into a hex-encoded string
*/
toString() {
return this.toHex();
}
/**
* Converts the ChannelId to a hex-encoded string
*/
toHex() {
return this.value.toString('hex');
}
/**
* Returns true if the ChannelIds are byte-wise equal
* @param other
*/
equals(other) {
return this.value.equals(other.value);
}
}
exports.ChannelId = ChannelId;
//# sourceMappingURL=ChannelId.js.map