{"author":{"name":"Alex Bosworth","url":"https://twitter.com/alexbosworth"},"bugs":{"url":"https://github.com/alexbosworth/bolt07/issues"},"description":"Utilities for working with bolt07 data formats","engines":{"node":">=22"},"keywords":["bolt","channel-id","channel-number","lightning","lightning-network","lnd"],"license":"MIT","main":"index.js","name":"bolt07","repository":{"type":"git","url":"git+https://github.com/alexbosworth/bolt07.git"},"scripts":{"test":"node --experimental-test-coverage --test"},"version":"2.0.0","gitHead":"ccbc086a486041ff38cac9c1ca3bab6ccd707b13","_id":"bolt07@2.0.0","homepage":"https://github.com/alexbosworth/bolt07#readme","_nodeVersion":"24.18.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-z4muz79gfwnhk/HQO8jmf9nsmG/8HZW7KznE1g9DH/48rcF76i+j/p730AUt3IUK7hoHb9WliEIOty7GvGxJEQ==","shasum":"4c540bd4178df0669377d575ce2cf44f9bc7cb1d","tarball":"http://registry-npm.ywwl.com/bolt07/download/bolt07-2.0.0.tgz","fileCount":44,"unpackedSize":119634,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDAvnH0pOuNoeVxS9B40MgaIxvw7xcDZXnZ2qvb4FebsAiEAh5D0Mpn3SBA3lmP8HeHrjkxZ/dmXRFP0ErM2gd/M2Rg="}],"size":19963,"noattachment":false,"key":"/bolt07/-/bolt07-2.0.0.tgz"},"_npmUser":{"name":"alexbosworth","email":"alex.bosworth+npm@gmail.com"},"directories":{},"maintainers":[{"name":"alexbosworth","email":"alex.bosworth+npm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bolt07_2.0.0_1787417788565_0.579840436815958"},"_hasShrinkwrap":false,"readme":"# BOLT07\n\nUtilities for working with Lightning Network [BOLT 07](https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md)\n\n[![npm version](https://badge.fury.io/js/bolt07.svg)](https://badge.fury.io/js/bolt07)\n\n## Methods\n\n- [chanFormat](#chanformat) - convert number or raw bytes format channel id to standard format\n- [chanNumber](#channumber) - convert standard, raw bytes format channel id to number format\n- [decodeChanId](#decodechanid) - decode block height and index components of a channel id\n- [encodeChanId](#encodechanid) - encode block height and index components into a channel id\n- [hopsFromChannels](#hopsfromchannels) - derive policy hops from a list of channels\n- [rawChanId](#rawchanid) - convert numeric or standard channel id into a raw wire form\n- [routeFromChannels](#routefromchannels) - derive a route from a sequence of channels\n- [routeFromHops](#routefromhops) - derive a route from a sequence of policy hops\n\n## Examples\n\nSample code for working with bolt07 utility functions:\n\n### Formats\n\n- Channel: `x` delimited format designed to be readable.\n- Id: The raw channel id format specified by bolt07.\n- Number: Interpreting the raw channel id format as a uint64.\n\n### Chan Format\n\n```node\nconst {chanFormat} = require('bolt07');\n\nconst id = '15fbe70000260000';\nconst number = '1584113681139367936';\n\ntry {\n  const fromNumber = chanFormat({number}).channel;\n  // fromNumber === '1440743x38x0'\n} catch (err) {\n  // valid channel, no error\n}\n\ntry {\n  const fromId = chanFormat({id}).channel;\n  // fromId === '1440743x38x0'\n} catch (err) {\n  // valid id, no error\n}\n```\n\n### Chan Number\n\n```node\nconst {chanNumber} = require('bolt07');\n\nconst channel = '1440743x38x0';\nconst id = '15fbe70000260000';\n\ntry {\n  const fromChannel = chanNumber({channel}).number;\n  // fromChannel === '1584113681139367936'\n} catch (err) {\n  // valid channel, no error\n}\n\ntry {\n  const fromId = chanNumber({id}).number;\n  // fromId === '1584113681139367936'\n} catch (err) {\n  // valid id, no error\n}\n```\n\n### decodeChanId\n\nReturns components of a channel id or channel number.\n\n```node\nconst {decodeChanId} = require('bolt07');\n\nconst channel = '1440743x38x0';\nconst id = '15fbe70000260000';\nconst number = '1584113681139367936';\n\ntry {\n  const fromChannel = decodeChanId({channel});\n  // fromChannel.block_height === 1440743\n  // fromChannel.block_index === 38\n  // fromChannel.output_index === 0\n} catch (err) {\n  // valid channel, no error\n}\n\ntry {\n  const fromId = decodeChanId({id});\n  // fromId.block_height === 1440743\n  // fromId.block_index === 38\n  // fromId.output_index === 0\n} catch (err) {\n  // valid id, no error\n}\n\ntry {\n  const fromNumber = decodeChanId({channel});\n  // fromNumber.block_height === 1440743\n  // fromNumber.block_index === 38\n  // fromNumber.output_index === 0\n} catch (err) {\n  // valid number, no error\n}\n```\n\n### encodeChanId\n\nReturns channel id when components are specified\n\n```node\nconst {encodeChanId} = require('bolt07');\n\ntry {\n  const encoded = encodeChanId({\n    block_height: 1440743,\n    block_index: 38,\n    output_index: 0,\n  });\n\n  // encoded.channel === '1440743x38x0'\n  // encoded.id === '15fbe70000260000'\n  // encoded.number === '1584113681139367936'\n} catch (err) {\n  // valid components, no error\n}\n```\n\n### Raw Chan Id\n\nReturns a raw channel id in numeric format.\n\n```node\nconst {rawChanId} = require('bolt07');\n\nconst channel = '1440743x38x0';\nconst number = '1584113681139367936';\n\ntry {\n  const idFromNumber = rawChanId({number}).id;\n  // idFromNumber === '15fbe70000260000'\n} catch (err) {\n  // valid number, no error\n}\n\ntry {\n  const idFromChannel = rawChanId({channel}).id;\n  // idFromChannel === '15fbe70000260000'\n} catch (err) {\n  // valid channel, no error\n}\n```\n\n## Methods\n\n### chanFormat\n\nGet channel components formatted string\n\n    {\n      [id]: <Raw Channel Id String>\n      [number]: <Number Format Channel Id String>\n    }\n\n    @throws\n    <Error>\n\n    @returns\n    {\n      channel: <Components Channel Format String>\n    }\n\n### chanNumber\n\nChannel id in numeric format\n\n    {\n      [channel]: <Channel Components String>\n      [id]: <Channel Id Hex String>\n    }\n\n    @throws\n    <ExpectedChannelIdOrComponentsToConvertToNumber Error>\n\n    @returns\n    {\n      number: <Channel Id Number String>\n    }\n\n### decodeChanId\n\nDecode a short channel id into components\n\n    {\n      [channel]: <Channel Components String>\n      [id]: <Channel Id Hex String>\n      [number]: <Channel Id Number Format String>\n    }\n\n    @throws\n    <ExpectedShortChannelIdToDecode Error>\n    <UnexpectedErrorDecodingChannelIdNumber Error>\n    <UnexpectedLengthOfShortChannelId Error>\n\n    @returns\n    {\n      block_height: <Channel Funding Transaction Inclusion Block Height Number>\n      block_index: <Channel Funding Transaction Inclusion Block Position Number>\n      output_index: <Channel Funding Transaction Output Index Number>\n    }\n\n### encodeChanId\n\nEncode a short channel id from components\n\n    {\n      block_height: <Channel Funding Transaction Inclusion Block Height Number>\n      block_index: <Channel Funding Transaction Inclusion Block Position Number>\n      output_index: <Channel Funding Transaction Output Index Number>\n    }\n\n    @throws\n    <ExpectedBlockHeightForChannelId Error>\n    <ExpectedBlockIndexForChannelId Error>\n    <ExpectedTransactionOutputIndexForChannelId Error>\n\n    @returns\n    {\n      channel: <Channel Components Format String>\n      id: <Channel Id Hex String>\n      number: <Channel Number String>\n    }\n\n### rawChanId\n\nRaw channel id\n\n    {\n      [channel]: <Channel Components String>\n      [number]: <Channel Id In Number Format String>\n    }\n\n    @throws\n    <Error>\n\n    @returns\n    {\n      id: <Raw Channel Id Hex String>\n    }\n\n### routeFromChannels\n\nGet a route from a sequence of channels\n\nEither next hop destination in channels or final destination is required\n\n    {\n      channels: [{\n        capacity: <Maximum Tokens Number>\n        [destination]: <Next Node Public Key Hex String>\n        id: <Standard Format Channel Id String>\n        policies: [{\n          base_fee_mtokens: <Base Fee Millitokens String>\n          cltv_delta: <Locktime Delta Number>\n          fee_rate: <Fees Charged in Millitokens Per Million Number>\n          is_disabled: <Channel Is Disabled Bool>\n          max_htlc_mtokens: <Maximum HTLC Millitokens Value String>\n          min_htlc_mtokens: <Minimum HTLC Millitokens Value String>\n          public_key: <Node Public Key String>\n        }]\n      }]\n      [cltv_delta]: <Final CLTV Delta Number>\n      [destination]: <Destination Public Key Hex String>\n      height: <Current Block Height Number>\n      [messages]: [{\n        type: <Message Type Number String>\n        value: <Message Raw Value Hex Encoded String>\n      }]\n      mtokens: <Millitokens To Send String>\n      [payment]: <Payment Identification Value Hex String>\n      [total_mtokens]: <Sum of Shards Millitokens String>\n    }\n\n    @throws\n    <Error>\n\n    @returns\n    {\n      route: {\n        fee: <Total Fee Tokens To Pay Number>\n        fee_mtokens: <Total Fee Millitokens To Pay String>\n        hops: [{\n          channel: <Standard Format Channel Id String>\n          channel_capacity: <Channel Capacity Tokens Number>\n          fee: <Fee Number>\n          fee_mtokens: <Fee Millitokens String>\n          forward: <Forward Tokens Number>\n          forward_mtokens: <Forward Millitokens String>\n          [public_key]: <Public Key Hex String>\n          timeout: <Timeout Block Height Number>\n        }]\n        [messages]: [{\n          type: <Message Type Number String>\n          value: <Message Raw Value Hex Encoded String>\n        }]\n        mtokens: <Total Fee-Inclusive Millitokens String>\n        [payment]: <Payment Identification Value Hex String>\n        timeout: <Timeout Block Height Number>\n        tokens: <Total Fee-Inclusive Tokens Number>\n        [total_mtokens]: <Sum of Shards Millitokens String>\n      }\n    }\n\n### routeFromHops\n\nGiven hops to a destination, construct a payable route\n\n    {\n      [cltv_delta]: <Final Cltv Delta Number>\n      height: <Current Block Height Number>\n      hops: [{\n        base_fee_mtokens: <Base Fee Millitokens String>\n        channel: <Standard Format Channel Id String>\n        [channel_capacity]: <Channel Capacity Tokens Number>\n        cltv_delta: <CLTV Delta Number>\n        fee_rate: <Fee Rate In Millitokens Per Million Number>\n        public_key: <Next Hop Public Key Hex String>\n      }]\n      initial_cltv: <Initial CLTV Delta Number>\n      [messages]: [{\n        type: <Message Type Number String>\n        value: <Message Raw Value Hex Encoded String>\n      }]\n      mtokens: <Millitokens To Send String>\n      [payment]: <Payment Identification Value Hex String>\n      [total_mtokens]: <Total Millitokens For Sharded Payments String>\n    }\n\n    @throws\n    <Error>\n\n    @returns\n    {\n      fee: <Route Fee Tokens Number>\n      fee_mtokens: <Route Fee Millitokens String>\n      hops: [{\n        channel: <Standard Format Channel Id String>\n        channel_capacity: <Channel Capacity Tokens Number>\n        fee: <Fee Number>\n        fee_mtokens: <Fee Millitokens String>\n        forward: <Forward Tokens Number>\n        forward_mtokens: <Forward Millitokens String>\n        [public_key]: <Public Key Hex String>\n        timeout: <Timeout Block Height Number>\n      }]\n      [messages]: [{\n        type: <Message Type Number String>\n        value: <Message Raw Value Hex Encoded String>\n      }]\n      mtokens: <Total Fee-Inclusive Millitokens String>\n      [payment]: <Payment Identification Value Hex String>\n      timeout: <Timeout Block Height Number>\n      tokens: <Total Fee-Inclusive Tokens Number>\n      [total_mtokens]: <Sharded Payments Total Millitokens String>\n    }\n","publish_time":1787417788704,"_cnpm_publish_time":1787417788704,"dist-tags":{"latest":"2.0.0"}}