feat: lnurl support

This commit is contained in:
Rafael Taranto 2024-02-29 13:23:49 +00:00
parent 83d18f9a10
commit 45fa1a8d93
4 changed files with 52 additions and 26 deletions

View file

@ -21,7 +21,7 @@ const logger = new winston.Logger({
}) })
], ],
rewriters: [ rewriters: [
(...[,, meta]) => meta instanceof Error ? { message: meta.message, stack: meta.stack } : meta (...[,, meta]) => meta instanceof Error ? { message: meta.message, stack: meta.stack, meta } : meta
], ],
exitOnError: false exitOnError: false
}) })

View file

@ -92,8 +92,12 @@ function getGaloyWallet (token, endpoint, walletId) {
}) })
} }
function isLightning (address) { function isLnInvoice (address) {
return address.substr(0, 2) === 'ln' return address.startsWith('lnbc')
}
function isLnurl (address) {
return address.startsWith('lnurl')
} }
function sendFundsOnChain (walletId, address, cryptoAtoms, token, endpoint) { function sendFundsOnChain (walletId, address, cryptoAtoms, token, endpoint) {
@ -116,6 +120,23 @@ function sendFundsOnChain (walletId, address, cryptoAtoms, token, endpoint) {
}) })
} }
function sendFundsLNURL (walletId, lnurl, cryptoAtoms, token, endpoint) {
const sendLnNoAmount = {
'operationName': 'lnurlPaymentSend',
'query': `mutation lnurlPaymentSend($input: LnurlPaymentSendInput!) {
lnurlPaymentSend(input: $input) {
errors {
message
path
}
status
}
}`,
'variables': { 'input': { 'lnurl': `${lnurl}`, 'walletId': `${walletId}`, 'amount': `${cryptoAtoms}` } }
}
return request(sendLnNoAmount, token, endpoint).then(result => result.data.lnurlPaymentSend)
}
function sendFundsLN (walletId, invoice, cryptoAtoms, token, endpoint) { function sendFundsLN (walletId, invoice, cryptoAtoms, token, endpoint) {
const sendLnNoAmount = { const sendLnNoAmount = {
'operationName': 'lnNoAmountInvoicePaymentSend', 'operationName': 'lnNoAmountInvoicePaymentSend',
@ -155,9 +176,12 @@ function sendCoins (account, tx, settings, operatorId) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId)) .then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId))
.then(wallet => { .then(wallet => {
if (isLightning(toAddress)) { if (isLnInvoice(toAddress)) {
return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint) return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
} }
if (isLnurl(toAddress)) {
return sendFundsLNURL(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
}
return sendFundsOnChain(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint) return sendFundsOnChain(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
}) })
.then(result => { .then(result => {
@ -272,7 +296,7 @@ function getStatus (account, tx, requested, settings, operatorId) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
const address = coinUtils.parseUrl(cryptoCode, account.environment, toAddress, false) const address = coinUtils.parseUrl(cryptoCode, account.environment, toAddress, false)
if (isLightning(address)) { if (isLnInvoice(address)) {
return getInvoiceStatus(account.apiSecret, account.endpoint, address) return getInvoiceStatus(account.apiSecret, account.endpoint, address)
.then(it => { .then(it => {
const isPaid = it === 'PAID' const isPaid = it === 'PAID'

42
package-lock.json generated
View file

@ -1078,6 +1078,25 @@
"fastpriorityqueue": "^0.7.1", "fastpriorityqueue": "^0.7.1",
"typeforce": "^1.11.3", "typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2" "varuint-bitcoin": "^1.1.2"
},
"dependencies": {
"bitcoinjs-lib": {
"version": "npm:@bitgo-forks/bitcoinjs-lib@7.1.0-master.7",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-lib/-/bitcoinjs-lib-7.1.0-master.7.tgz",
"integrity": "sha512-FZle7954KnbbVXFCc5uYGtjq+0PFOnFxVchNwt3Kcv2nVusezTp29aeQwDi2Y+lM1dCoup2gJGXMkkREenY7KQ==",
"requires": {
"bech32": "^2.0.0",
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"bs58check": "^2.1.2",
"create-hash": "^1.1.0",
"fastpriorityqueue": "^0.7.1",
"json5": "^2.2.3",
"ripemd160": "^2.0.2",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2",
"wif": "^2.0.1"
}
}
} }
}, },
"@bitgo/utxo-ord": { "@bitgo/utxo-ord": {
@ -2132,9 +2151,9 @@
} }
}, },
"@lamassu/coins": { "@lamassu/coins": {
"version": "1.4.3", "version": "1.4.9",
"resolved": "https://registry.npmjs.org/@lamassu/coins/-/coins-1.4.3.tgz", "resolved": "https://registry.npmjs.org/@lamassu/coins/-/coins-1.4.9.tgz",
"integrity": "sha512-29XRlhYZcKYQeUWUohBLvjdvhkIYUe+TAxWYN+crw/JXSd8Bz3yId88v+n6+F3eTAN6iCDtHnTTiYRhYD4DQ/Q==", "integrity": "sha512-psOTHCGJBaIP7mnMSY3zmAsX3k9m6PffnL1Kq9SE4waMyTX4fQu/heEkmWk/OACk2CSonahA4FbLNKc284cizg==",
"requires": { "requires": {
"@lamassu/bolt11": "1.5.1", "@lamassu/bolt11": "1.5.1",
"bech32": "2.0.0", "bech32": "2.0.0",
@ -4393,23 +4412,6 @@
"resolved": "https://registry.npmjs.org/bitcoind-rpc/-/bitcoind-rpc-0.7.2.tgz", "resolved": "https://registry.npmjs.org/bitcoind-rpc/-/bitcoind-rpc-0.7.2.tgz",
"integrity": "sha512-3alq5pH4/mAdEscucew98ls0s7BEaDvKTuYW34nSkTsmTC7G9R7Xh+ABXOxeVBfG/+rKfyQLmFAm2aRq92tJqw==" "integrity": "sha512-3alq5pH4/mAdEscucew98ls0s7BEaDvKTuYW34nSkTsmTC7G9R7Xh+ABXOxeVBfG/+rKfyQLmFAm2aRq92tJqw=="
}, },
"bitcoinjs-lib": {
"version": "npm:@bitgo-forks/bitcoinjs-lib@7.1.0-master.7",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-lib/-/bitcoinjs-lib-7.1.0-master.7.tgz",
"integrity": "sha512-FZle7954KnbbVXFCc5uYGtjq+0PFOnFxVchNwt3Kcv2nVusezTp29aeQwDi2Y+lM1dCoup2gJGXMkkREenY7KQ==",
"requires": {
"bech32": "^2.0.0",
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"bs58check": "^2.1.2",
"create-hash": "^1.1.0",
"fastpriorityqueue": "^0.7.1",
"json5": "^2.2.3",
"ripemd160": "^2.0.2",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2",
"wif": "^2.0.1"
}
},
"bitcoinjs-message": { "bitcoinjs-message": {
"version": "npm:@bitgo-forks/bitcoinjs-message@1.0.0-master.2", "version": "npm:@bitgo-forks/bitcoinjs-message@1.0.0-master.2",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-message/-/bitcoinjs-message-1.0.0-master.2.tgz", "resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-message/-/bitcoinjs-message-1.0.0-master.2.tgz",

View file

@ -15,7 +15,7 @@
"@ethereumjs/common": "^2.6.4", "@ethereumjs/common": "^2.6.4",
"@ethereumjs/tx": "^3.5.1", "@ethereumjs/tx": "^3.5.1",
"@graphql-tools/merge": "^6.2.5", "@graphql-tools/merge": "^6.2.5",
"@lamassu/coins": "v1.4.3", "@lamassu/coins": "v1.4.9",
"@simplewebauthn/server": "^3.0.0", "@simplewebauthn/server": "^3.0.0",
"@vonage/auth": "^1.5.0", "@vonage/auth": "^1.5.0",
"@vonage/sms": "^1.7.0", "@vonage/sms": "^1.7.0",