diff --git a/package.json b/package.json index ad83d983ccc..5cc293476db 100644 --- a/package.json +++ b/package.json @@ -322,6 +322,7 @@ "bip21": "2.0.3", "bip39-en": "1.1.1", "bitcoinjs-lib": "5.1.7", + "bolt07": "1.5.0", "bolt11": "1.2.7", "coininfo": "https://github.com/LN-Zap/coininfo#d7ac7be9c9c4ee74dada187f7762a55887a9c6ca", "comlinkjs": "3.2.0", diff --git a/renderer/reducers/payment/utils.js b/renderer/reducers/payment/utils.js index 40e22db1981..09e14a04d61 100644 --- a/renderer/reducers/payment/utils.js +++ b/renderer/reducers/payment/utils.js @@ -1,6 +1,7 @@ import config from 'config' import get from 'lodash/get' import cloneDeep from 'lodash/cloneDeep' +import { chanNumber } from 'bolt07' import { getTag, decodePayReq, getNodeAlias, generatePreimage } from '@zap/utils/crypto' import { convert } from '@zap/utils/btc' import { getIntl } from '@zap/i18n' @@ -184,12 +185,23 @@ export const prepareBolt11Probe = (payReq, feeLimit) => { const invoice = decodePayReq(payReq) const { millisatoshis, payeeNodeKey: pubkey } = invoice + // Extract route hints from the invoice. + const routingInfo = getTag(invoice, 'routing_info') || [] + const hopHints = routingInfo.map(hint => ({ + nodeId: hint.pubkey, + chanId: chanNumber({ id: hint.short_channel_id }).number, + feeBaseMsat: hint.fee_base_msat, + feeProportionalMillionths: hint.fee_proportional_millionths, + cltvExpiryDelta: hint.cltv_expiry_delta, + })) + return { ...getPaymentConfig(), dest: Buffer.from(pubkey, 'hex'), feeLimitSat: feeLimit, amtMsat: millisatoshis, finalCltvDelta: getTag(invoice, 'min_final_cltv_expiry') || DEFAULT_CLTV_DELTA, + routeHints: [{ hopHints }], } } diff --git a/yarn.lock b/yarn.lock index b0195992479..096e47753ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4810,6 +4810,11 @@ bluebird@^3.3.5, bluebird@^3.5.0, bluebird@^3.5.5: resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== +bn.js@5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5" + integrity sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA== + bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0: version "4.11.8" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" @@ -4831,6 +4836,13 @@ body-parser@1.19.0: raw-body "2.4.0" type-is "~1.6.17" +bolt07@1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bolt07/-/bolt07-1.5.0.tgz#4200e574226c7d540a36e6cce42a35c9f4ac0213" + integrity sha512-56MzzIej8xP5Ksl+8AwOSMkbFWX9HG3/3qG+2lwxpvkoUQJVUSjyj/JKx+6qaJdarv1XcpNbtGfpixCKIlI+sg== + dependencies: + bn.js "5.1.1" + bolt11@1.2.7: version "1.2.7" resolved "https://registry.yarnpkg.com/bolt11/-/bolt11-1.2.7.tgz#75852e215aeb28d6ccd6dd7c721c09d8ccb40a88"