@@ -12,7 +12,7 @@ import {
1212import { amountSchema , validateSchema , withdrawlSchema , lnAddrSchema } from '@/lib/validate'
1313import assertGofacYourself from './ofac'
1414import assertApiKeyNotPermitted from './apiKey'
15- import { bolt11Info , isBolt11 } from '@/lib/bolt11-info '
15+ import { bolt11Tags , isBolt11 } from '@/lib/bolt11-tags '
1616import { bolt12Info } from '@/lib/bolt12-info'
1717import { finalizeHodlInvoice } from '@/worker/wallet'
1818import walletDefs from '@/wallets/server'
@@ -24,8 +24,10 @@ import validateWallet from '@/wallets/validate'
2424import { canReceive } from '@/wallets/common'
2525import performPaidAction from '../paidAction'
2626import performPayingAction from '../payingAction'
27- import { parseInvoice } from '@/lib/invoices '
27+ import { parseInvoice } from '@/lib/boltInvoices '
2828import lnd from '@/api/lnd'
29+ import { isBolt12Offer } from '@/lib/bolt12'
30+ import { fetchBolt12InvoiceFromOffer } from '@/lib/lndk'
2931
3032function injectResolvers ( resolvers ) {
3133 console . group ( 'injected GraphQL resolvers:' )
@@ -369,7 +371,7 @@ const resolvers = {
369371 f = { ...f , ...f . other }
370372
371373 if ( f . bolt11 ) {
372- f . description = isBolt11 ( f . bolt11 ) ? bolt11Info ( f . bolt11 ) . description : bolt12Info ( f . bolt11 ) . description
374+ f . description = isBolt11 ( f . bolt11 ) ? bolt11Tags ( f . bolt11 ) . description : bolt12Info ( f . bolt11 ) . description
373375 }
374376
375377 switch ( f . type ) {
@@ -481,6 +483,7 @@ const resolvers = {
481483 } ,
482484 createWithdrawl : createWithdrawal ,
483485 sendToLnAddr,
486+ sendToBolt12Offer,
484487 cancelInvoice : async ( parent , { hash, hmac } , { models, lnd, boss } ) => {
485488 verifyHmac ( hash , hmac )
486489 await finalizeHodlInvoice ( { data : { hash } , lnd, models, boss } )
@@ -940,7 +943,7 @@ export async function createWithdrawal (parent, { invoice, maxFee }, { me, model
940943 throw new GqlInputError ( 'SN cannot pay an invoice that SN is proxying' )
941944 }
942945
943- return await performPayingAction ( { invoice, maxFee, walletId : wallet ?. id } , { me, models, lnd } )
946+ return await performPayingAction ( { bolt11 : invoice , maxFee, walletId : wallet ?. id } , { me, models, lnd } )
944947}
945948
946949export async function sendToLnAddr ( parent , { addr, amount, maxFee, comment, ...payer } ,
@@ -961,6 +964,18 @@ export async function sendToLnAddr (parent, { addr, amount, maxFee, comment, ...
961964 return await createWithdrawal ( parent , { invoice : res . pr , maxFee } , { me, models, lnd, headers } )
962965}
963966
967+ export async function sendToBolt12Offer ( parent , { offer, amountSats, maxFee, comment } , { me, models, lnd, headers } ) {
968+ if ( ! me ) {
969+ throw new GqlAuthenticationError ( )
970+ }
971+ assertApiKeyNotPermitted ( { me } )
972+ if ( ! isBolt12Offer ( offer ) ) {
973+ throw new GqlInputError ( 'not a bolt12 offer' )
974+ }
975+ const invoice = await fetchBolt12InvoiceFromOffer ( { lnd, offer, msats : satsToMsats ( amountSats ) , description : comment } )
976+ return await createWithdrawal ( parent , { invoice, maxFee } , { me, models, lnd, headers } )
977+ }
978+
964979export async function fetchLnAddrInvoice (
965980 { addr, amount, maxFee, comment, ...payer } ,
966981 {
0 commit comments