Skip to content

Add LNURL-verify use case #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/python/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def receive_payment(params):

Args:
params (argparse.Namespace): Command-line arguments containing:
- method (str): The payment method (e.g., 'LIGHTNING', 'BITCOIN_ADDRESS', 'LIQUID_ADDRESS')
- amount_sat (int): The amount to receive in satoshis
- method (str): The payment method (e.g., 'LIGHTNING', 'BOLT12_OFFER', 'BITCOIN_ADDRESS', 'LIQUID_ADDRESS')
- amount_sat (int): The optional amount to receive in satoshis
- asset_id (str): The optional id of the asset to receive
- amount (float): The optional amount to receive of the asset

Expand Down Expand Up @@ -311,7 +311,7 @@ def main():
# receive
receive_parser = subparser.add_parser('receive', help='Receive a payment')
receive_parser.add_argument('-m', '--method',
choices=['LIGHTNING', 'BITCOIN_ADDRESS', 'LIQUID_ADDRESS'],
choices=['LIGHTNING', 'BOLT12_OFFER', 'BITCOIN_ADDRESS', 'LIQUID_ADDRESS'],
help='The payment method',
required=True)
receive_parser.add_argument('-a', '--amount_sat',
Expand Down
4 changes: 4 additions & 0 deletions snippets/csharp/ParsingInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public void ParseInput(BindingLiquidSdk sdk)
Console.WriteLine($"Input is BOLT11 invoice for {amount} msats");
break;

case InputType.Bolt12Offer bolt12:
Console.WriteLine($"Input is BOLT12 offer for min {bolt12.offer.minAmount} msats - BIP353 was used: {bolt12.bip353Address != null}");
break;

case InputType.LnUrlPay lnUrlPay:
Console.WriteLine(
$"Input is LNURL-Pay/Lightning address accepting min/max {lnUrlPay.data.minSendable}/{lnUrlPay.data.maxSendable} msats - BIP353 was used: {lnUrlPay.bip353Address != null}"
Expand Down
22 changes: 21 additions & 1 deletion snippets/csharp/ReceivePayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Set the invoice amount you wish the payer to send, which should be within the above limits
var optionalAmount = new ReceiveAmount.Bitcoin(5000);
var prepareRequest = new PrepareReceiveRequest(PaymentMethod.Lightning, optionalAmount);
var prepareRequest = new PrepareReceiveRequest(PaymentMethod.Bolt11Invoice, optionalAmount);

Check failure on line 17 in snippets/csharp/ReceivePayment.cs

View workflow job for this annotation

GitHub Actions / Check C# snippets

'PaymentMethod' does not contain a definition for 'Bolt11Invoice'

Check failure on line 17 in snippets/csharp/ReceivePayment.cs

View workflow job for this annotation

GitHub Actions / Check C# snippets

'PaymentMethod' does not contain a definition for 'Bolt11Invoice'
var prepareResponse = sdk.PrepareReceivePayment(prepareRequest);

// If the fees are acceptable, continue to create the Receive Payment
Expand All @@ -28,6 +28,26 @@
// ANCHOR_END: prepare-receive-payment-lightning
}

public void PrepareReceiveLightningBolt12(BindingLiquidSdk sdk)
{
// ANCHOR: prepare-receive-payment-lightning-bolt12
try
{
var prepareRequest = new PrepareReceiveRequest(PaymentMethod.Bolt12Offer);

Check failure on line 36 in snippets/csharp/ReceivePayment.cs

View workflow job for this annotation

GitHub Actions / Check C# snippets

'PaymentMethod' does not contain a definition for 'Bolt12Offer'

Check failure on line 36 in snippets/csharp/ReceivePayment.cs

View workflow job for this annotation

GitHub Actions / Check C# snippets

'PaymentMethod' does not contain a definition for 'Bolt12Offer'
var prepareResponse = sdk.PrepareReceivePayment(prepareRequest);

// If the fees are acceptable, continue to create the Receive Payment
var minReceiveFeesSat = prepareResponse.feesSat;
var swapperFeerate = prepareResponse.swapperFeerate;
Console.WriteLine($"Fees: {minReceiveFeesSat} sats + {swapperFeerate}% of the sent amount");
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: prepare-receive-payment-lightning-bolt12
}

public void PrepareReceiveOnchain(BindingLiquidSdk sdk)
{
// ANCHOR: prepare-receive-payment-onchain
Expand Down
2 changes: 2 additions & 0 deletions snippets/dart_snippets/lib/parsing_inputs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Future<void> parseInput() async {
String amountStr =
inputType.invoice.amountMsat != null ? inputType.invoice.amountMsat.toString() : "unknown";
print("Input is BOLT11 invoice for $amountStr msats");
} else if (inputType is InputType_Bolt12Offer) {
print("Input is BOLT12 offer for min ${inputType.offer.minAmount} msats - BIP353 was used: ${inputType.bip353Address != null}");
} else if (inputType is InputType_LnUrlPay) {
print(
"Input is LNURL-Pay/Lightning address accepting min/max ${inputType.data.minSendable}/${inputType.data.maxSendable} msats - BIP353 was used: ${inputType.bip353Address != null}");
Expand Down
16 changes: 15 additions & 1 deletion snippets/dart_snippets/lib/receive_payment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<PrepareReceiveResponse> prepareReceivePaymentLightning() async {
ReceiveAmount_Bitcoin optionalAmount = ReceiveAmount_Bitcoin(payerAmountSat: 5000 as BigInt);
PrepareReceiveResponse prepareResponse = await breezSDKLiquid.instance!.prepareReceivePayment(
req: PrepareReceiveRequest(
paymentMethod: PaymentMethod.lightning,
paymentMethod: PaymentMethod.bolt11Invoice,
amount: optionalAmount,
),
);
Expand All @@ -25,6 +25,20 @@ Future<PrepareReceiveResponse> prepareReceivePaymentLightning() async {
return prepareResponse;
}

Future<PrepareReceiveResponse> prepareReceivePaymentLightningBolt12() async {
// ANCHOR: prepare-receive-payment-lightning-bolt12
PrepareReceiveResponse prepareResponse = await breezSDKLiquid.instance!.prepareReceivePayment(
req: PrepareReceiveRequest(paymentMethod: PaymentMethod.bolt12Offer),
);

// If the fees are acceptable, continue to create the Receive Payment
BigInt minReceiveFeesSat = prepareResponse.feesSat;
double? swapperFeerate = prepareResponse.swapperFeerate;
print("Fees: $minReceiveFeesSat sats + $swapperFeerate% of the sent amount");
// ANCHOR_END: prepare-receive-payment-lightning-bolt12
return prepareResponse;
}

Future<PrepareReceiveResponse> prepareReceivePaymentOnchain() async {
// ANCHOR: prepare-receive-payment-onchain
// Fetch the Receive onchain limits
Expand Down
4 changes: 4 additions & 0 deletions snippets/go/parsing_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func ParseInput(sdk *breez_sdk_liquid.BindingLiquidSdk) {
}
log.Printf("Input is BOLT11 invoice for %s msats", amount)

case breez_sdk_liquid.InputTypeBolt12Offer:
log.Printf("Input is BOLT12 offer for min %v msats - BIP353 was used: %t",
inputType.Offer.MinAmount, inputType.Bip353Address != nil)

case breez_sdk_liquid.InputTypeLnUrlPay:
log.Printf("Input is LNURL-Pay/Lightning address accepting min/max %d/%d msats - BIP353 was used: %t",
inputType.Data.MinSendable, inputType.Data.MaxSendable, inputType.Bip353Address != nil)
Expand Down
16 changes: 15 additions & 1 deletion snippets/go/receive_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrepareReceiveLightning(sdk *breez_sdk_liquid.BindingLiquidSdk) {
PayerAmountSat: uint64(5_000),
}
prepareRequest := breez_sdk_liquid.PrepareReceiveRequest{
PaymentMethod: breez_sdk_liquid.PaymentMethodLightning,
PaymentMethod: breez_sdk_liquid.PaymentMethodBolt11Invoice,
Amount: &optionalAmount,
}
if prepareResponse, err := sdk.PrepareReceivePayment(prepareRequest); err == nil {
Expand All @@ -30,6 +30,20 @@ func PrepareReceiveLightning(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR_END: prepare-receive-payment-lightning
}

func PrepareReceiveLightningBolt12(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-receive-payment-lightning-bolt12
prepareRequest := breez_sdk_liquid.PrepareReceiveRequest{
PaymentMethod: breez_sdk_liquid.PaymentMethodBolt12Offer,
}
if prepareResponse, err := sdk.PrepareReceivePayment(prepareRequest); err == nil {
// If the fees are acceptable, continue to create the Receive Payment
minReceiveFeesSat := prepareResponse.FeesSat
swapperFeerate := prepareResponse.SwapperFeerate
log.Printf("Fees: %v sats + %v%% of the sent amount", minReceiveFeesSat, swapperFeerate)
}
// ANCHOR_END: prepare-receive-payment-lightning-bolt12
}

func PrepareReceiveOnchain(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-receive-payment-onchain
// Fetch the onchain Receive limits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class ParsingInputs {
val amountStr = inputType.invoice.amountMsat?.toString() ?: "unknown"
println("Input is BOLT11 invoice for $amountStr msats")
}
is InputType.Bolt12Offer -> {
println("Input is BOLT12 offer for min ${inputType.offer.minAmount} msats - BIP353 was used: ${inputType.bip353Address != null}")
}
is InputType.LnUrlPay -> {
println("Input is LNURL-Pay/Lightning address accepting min/max " +
"${inputType.data.minSendable}/${inputType.data.maxSendable} msats - BIP353 was used: ${inputType.bip353Address != null}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ReceivePayment {

// Set the invoice amount you wish the payer to send, which should be within the above limits
val optionalAmount = ReceiveAmount.Bitcoin(5_000.toULong())
val prepareRequest = PrepareReceiveRequest(PaymentMethod.LIGHTNING, optionalAmount)
val prepareRequest = PrepareReceiveRequest(PaymentMethod.BOLT11_INVOICE, optionalAmount)
val prepareResponse = sdk.prepareReceivePayment(prepareRequest)

// If the fees are acceptable, continue to create the Receive Payment
Expand All @@ -23,6 +23,22 @@ class ReceivePayment {
}
// ANCHOR_END: prepare-receive-payment-lightning
}

fun prepareReceiveLightningBolt12(sdk: BindingLiquidSdk) {
// ANCHOR: prepare-receive-payment-lightning-bolt12
try {
val prepareRequest = PrepareReceiveRequest(PaymentMethod.BOLT12_OFFER)
val prepareResponse = sdk.prepareReceivePayment(prepareRequest)

// If the fees are acceptable, continue to create the Receive Payment
val minReceiveFeesSat = prepareResponse.feesSat;
val swapperFeerate = prepareResponse.swapperFeerate;
// Log.v("Breez", "Fees: ${minReceiveFeesSat} sats + ${swapperFeerate}% of the sent amount")
} catch (e: Exception) {
// handle error
}
// ANCHOR_END: prepare-receive-payment-lightning-bolt12
}

fun prepareReceiveOnchain(sdk: BindingLiquidSdk) {
// ANCHOR: prepare-receive-payment-onchain
Expand Down
2 changes: 2 additions & 0 deletions snippets/python/src/parsing_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def parse_input(sdk: BindingLiquidSdk):
if parsed_input.invoice.amount_msat:
amount = str(parsed_input.invoice.amount_msat)
logging.debug(f"Input is BOLT11 invoice for {amount} msats")
elif isinstance(parsed_input, InputType.BOLT12_OFFER):
logging.debug(f"Input is BOLT12 offer for min {parsed_input.offer.min_amount} msats - BIP353 was used: {parsed_input.bip353_address is not None}")
elif isinstance(parsed_input, InputType.LN_URL_PAY):
logging.debug(f"Input is LNURL-Pay/Lightning address accepting min/max {parsed_input.data.min_sendable}/{parsed_input.data.max_sendable} msats - BIP353 was used: {parsed_input.bip353_address is not None}")
elif isinstance(parsed_input, InputType.LN_URL_WITHDRAW):
Expand Down
20 changes: 19 additions & 1 deletion snippets/python/src/receive_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def prepare_receive_lightning(sdk: BindingLiquidSdk):
# Set the invoice amount you wish the payer to send, which should be within the above limits
optional_amount = ReceiveAmount.BITCOIN(5_000)
prepare_request = PrepareReceiveRequest(
payment_method=PaymentMethod.LIGHTNING,
payment_method=PaymentMethod.BOLT11_INVOICE,
amount=optional_amount
)
prepare_response = sdk.prepare_receive_payment(prepare_request)
Expand All @@ -27,6 +27,24 @@ def prepare_receive_lightning(sdk: BindingLiquidSdk):
raise
# ANCHOR_END: prepare-receive-payment-lightning

def prepare_receive_lightning_bolt12(sdk: BindingLiquidSdk):
# ANCHOR: prepare-receive-payment-lightning-bolt12
try:
prepare_request = PrepareReceiveRequest(
payment_method=PaymentMethod.BOLT12_OFFER
)
prepare_response = sdk.prepare_receive_payment(prepare_request)

# If the fees are acceptable, continue to create the Receive Payment
min_receive_fees_sat = prepare_response.fees_sat
swapper_feerate = prepare_response.swapper_feerate
logging.debug(f"Fees: {min_receive_fees_sat} sats + {swapper_feerate}% of the sent amount")
return prepare_response
except Exception as error:
logging.error(error)
raise
# ANCHOR_END: prepare-receive-payment-lightning-bolt12

def prepare_receive_onchain(sdk: BindingLiquidSdk):
# ANCHOR: prepare-receive-payment-onchain
try:
Expand Down
8 changes: 7 additions & 1 deletion snippets/react-native/parsing_inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ const parseInputs = async () => {
console.log(
`Input is BOLT11 invoice for ${
parsed.invoice.amountMsat != null
? parsed.invoice.amountMsat.toString()
? JSON.stringify(parsed.invoice.amountMsat)
: 'unknown'
} msats`
)
break

case InputTypeVariant.BOLT12_OFFER:
console.log(
`Input is BOLT12 offer for min ${JSON.stringify(parsed.offer.minAmount)} msats - BIP353 was used: ${parsed.bip353Address != null}`
)
break

case InputTypeVariant.LN_URL_PAY:
console.log(
`Input is LNURL-Pay/Lightning address accepting min/max ${parsed.data.minSendable}/${parsed.data.maxSendable} msats - BIP353 was used: ${parsed.bip353Address != null}`
Expand Down
15 changes: 14 additions & 1 deletion snippets/react-native/receive_payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const examplePrepareLightningPayment = async () => {
}

const prepareResponse = await prepareReceivePayment({
paymentMethod: PaymentMethod.LIGHTNING,
paymentMethod: PaymentMethod.BOLT11_INVOICE,
amount: optionalAmount
})

Expand All @@ -35,6 +35,19 @@ const examplePrepareLightningPayment = async () => {
// ANCHOR_END: prepare-receive-payment-lightning
}

const examplePrepareLightningBolt12Payment = async () => {
// ANCHOR: prepare-receive-payment-lightning-bolt12
const prepareResponse = await prepareReceivePayment({
paymentMethod: PaymentMethod.BOLT12_OFFER
})

// If the fees are acceptable, continue to create the Receive Payment
const minReceiveFeesSat = prepareResponse.feesSat
const swapperFeerate = prepareResponse.swapperFeerate
console.log(`Fees: ${minReceiveFeesSat} sats + ${swapperFeerate}% of the sent amount`)
// ANCHOR_END: prepare-receive-payment-lightning-bolt12
}

const examplePrepareOnchainPayment = async () => {
// ANCHOR: prepare-receive-payment-onchain
// Fetch the Onchain lightning limits
Expand Down
7 changes: 7 additions & 0 deletions snippets/rust/src/parsing_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ async fn parse_input(sdk: Arc<LiquidSdk>) -> Result<()> {
.map_or("unknown".to_string(), |a| a.to_string())
);
}
InputType::Bolt12Offer { offer, bip353_address } => {
println!(
"Input is BOLT12 offer for min {:?} msats - BIP353 was used: {}",
offer.min_amount,
bip353_address.is_some()
);
}
InputType::LnUrlPay { data, bip353_address } => {
println!(
"Input is LNURL-Pay/Lightning address accepting min/max {}/{} msats - BIP353 was used: {}",
Expand Down
19 changes: 18 additions & 1 deletion snippets/rust/src/receive_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn prepare_receive_lightning(sdk: Arc<LiquidSdk>) -> Result<()> {
});
let prepare_response = sdk
.prepare_receive_payment(&PrepareReceiveRequest {
payment_method: PaymentMethod::Lightning,
payment_method: PaymentMethod::Bolt11Invoice,
amount: optional_amount,
})
.await?;
Expand All @@ -29,6 +29,23 @@ async fn prepare_receive_lightning(sdk: Arc<LiquidSdk>) -> Result<()> {
Ok(())
}

async fn prepare_receive_lightning_bolt12(sdk: Arc<LiquidSdk>) -> Result<()> {
// ANCHOR: prepare-receive-payment-lightning-bolt12
let prepare_response = sdk
.prepare_receive_payment(&PrepareReceiveRequest {
payment_method: PaymentMethod::Bolt12Offer,
amount: None,
})
.await?;

// If the fees are acceptable, continue to create the Receive Payment
let min_receive_fees_sat = prepare_response.fees_sat;
let swapper_feerate = prepare_response.swapper_feerate;
info!("Fees: {} sats + {:?}% of the sent amount", min_receive_fees_sat, swapper_feerate);
// ANCHOR_END: prepare-receive-payment-lightning-bolt12
Ok(())
}

async fn prepare_receive_onchain(sdk: Arc<LiquidSdk>) -> Result<()> {
// ANCHOR: prepare-receive-payment-onchain
// Fetch the Receive onchain limits
Expand Down
3 changes: 3 additions & 0 deletions snippets/swift/BreezSDKExamples/Sources/ParsingInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func parseInput(sdk: BindingLiquidSdk) {
let amount = invoice.amountMsat.map { String($0) } ?? "unknown"
print("Input is BOLT11 invoice for \(amount) msats")

case .bolt12Offer(let offer, let bip353Address):
print("Input is BOLT12 offer for min \(offer.minAmount) msats - BIP353 was used: \(bip353Address != nil)")

case .lnUrlPay(let data, let bip353Address):
print(
"Input is LNURL-Pay/Lightning address accepting min/max \(data.minSendable)/\(data.maxSendable) msats - BIP353 was used: \(bip353Address != nil)"
Expand Down
18 changes: 17 additions & 1 deletion snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func prepareReceiveLightning(sdk: BindingLiquidSdk) -> PrepareReceiveResponse? {
let optionalAmount = ReceiveAmount.bitcoin(payerAmountSat: 5_000)
let prepareResponse = try? sdk
.prepareReceivePayment(req: PrepareReceiveRequest(
paymentMethod: PaymentMethod.lightning,
paymentMethod: PaymentMethod.bolt11Invoice,
amount: optionalAmount
));

Expand All @@ -23,6 +23,22 @@ func prepareReceiveLightning(sdk: BindingLiquidSdk) -> PrepareReceiveResponse? {
return prepareResponse
}

func prepareReceiveLightningBolt12(sdk: BindingLiquidSdk) -> PrepareReceiveResponse? {
// ANCHOR: prepare-receive-payment-lightning-bolt12
let prepareResponse = try? sdk
.prepareReceivePayment(req: PrepareReceiveRequest(
paymentMethod: PaymentMethod.bolt12Offer
));

// If the fees are acceptable, continue to create the Receive Payment
let minReceiveFeesSat = prepareResponse!.feesSat;
let swapperFeerate = prepareResponse!.swapperFeerate;
print("Fees: {} sats + {}% of the sent amount", minReceiveFeesSat, swapperFeerate);
// ANCHOR_END: prepare-receive-payment-lightning-bolt12

return prepareResponse
}

func prepareReceiveOnchain(sdk: BindingLiquidSdk) -> PrepareReceiveResponse? {
// ANCHOR: prepare-receive-payment-onchain
// Fetch the Receive onchain limits
Expand Down
6 changes: 6 additions & 0 deletions snippets/wasm/parsing_inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const parseInputs = async (sdk: BindingLiquidSdk) => {
)
break

case 'bolt12Offer':
console.log(
`Input is BOLT12 offer for min ${JSON.stringify(parsed.offer.minAmount)} msats - BIP353 was used: ${parsed.bip353Address != null}`
)
break

case 'lnUrlPay':
console.log(
`Input is LNURL-Pay/Lightning address accepting min/max ${parsed.data.minSendable}/${
Expand Down
Loading
Loading