Last active
April 2, 2024 11:06
-
-
Save SeverinAlexB/76bef46ca35c81ffa553f945709037fb to your computer and use it in GitHub Desktop.
Lightning Network short channel id (CLN) to decimal id (LND) converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** By LnRouter.app */ | |
function bitShift(n: number, shiftBy: number): number { | |
let base = n; | |
for (let i = 0; i < shiftBy; i++) { | |
base = base * 2; | |
} | |
return base; | |
} | |
export function shortChannelIdToDecimalId(shortChannelId: string): string { | |
const [blockHeightS, transactionIndexS, outputIndexS] = shortChannelId.split("x"); | |
const blockHeight = Number.parseInt(blockHeightS); | |
const transactionIndex = Number.parseInt(transactionIndexS); | |
const outputIndex = Number.parseInt(outputIndexS); | |
const result = BigInt(bitShift(blockHeight, 40)) | BigInt(bitShift(transactionIndex, 16)) | BigInt(outputIndex); | |
return result.toString(); | |
} | |
const decimalId = shortChannelIdToDecimalId('799046x927x0') | |
console.log(decimalId) // 878560368188653568 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment