Skip to content

Commit

Permalink
feat(wallet): support bolt11 in bip21
Browse files Browse the repository at this point in the history
Support lightning invoices that are encoded within a bip21 bitcoin uri

Fix LN-Zap#200
  • Loading branch information
mrfelton committed Nov 6, 2019
1 parent 576dade commit 1a09e16
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ let lnurlService
// Set up a couple of timers to track the app startup progress.
mainLog.time('Time until app is ready')

/**
* handleBitcoinLink - Handler for bitcoin: links.
*
* @param {string} input Bitcoin link
*/
const handleBitcoinLink = input => {
try {
const decoded = bip21.decode(input)
zap.sendMessage('bitcoinPaymentUri', decoded)
mainWindow.show()
} catch (e) {
mainLog.warn('Unable to process bitcoin uri: %s', e)
}
}

/**
* handleLnurlLink - Handler for lightning lnurl links.
*
Expand Down Expand Up @@ -135,6 +120,29 @@ const handleLndconnectLink = input => {
}
}

/**
* handleBitcoinLink - Handler for bitcoin: links.
*
* @param {string} input Bitcoin link
*/
const handleBitcoinLink = input => {
mainLog.info('Attempting to process bitcoin uri: %s', input)
try {
const decoded = bip21.decode(input)
// If the bip21 data includes a bolt11 invoice in the `lightning` key handle as an lightning payment.
// Otherwise, use the bitcoin address for on-chain payment.
const lightning = get(decoded, 'options.lightning')
if (lightning) {
handleLninvoiceLink(lightning)
return
}
zap.sendMessage('bitcoinPaymentUri', decoded)
mainWindow.show()
} catch (e) {
mainLog.warn('Unable to process bitcoin uri: %s', e)
}
}

const protocolHandlers = {
bitcoin: handleBitcoinLink,
lightning: handleLightningLink,
Expand Down

0 comments on commit 1a09e16

Please sign in to comment.