LNURL-Auth

Usage

Rust
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";

if let Ok(InputType::LnUrlAuth { data: ad }) = parse(lnurl_auth_url).await {
    match sdk.lnurl_auth(ad).await {
        Ok(LnUrlCallbackStatus::Ok) => {
            info!("Successfully authenticated")
        }
        Ok(LnUrlCallbackStatus::ErrorStatus { data }) => {
            error!("Failed to authenticate: {}", data.reason)
        }
        Err(e) => {
            error!("Failed to connect: {e}")
        }
    }
}
Swift
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"

if let inputType = try? parse(input: lnurlAuthUrl) {
    if case .lnUrlAuth(let `data`) = inputType {
        let result = try? sdk.lnurlAuth(reqData: data)
        switch result {
        case .ok:
            print("Successfully authenticated")
        case .errorStatus(let error):
            print("Failed to authenticate: \(error)")
        case .none:
            print("Failed to authenticate")
        }
    }
}
Kotlin
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
val lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7..."
try {
    val inputType = parse(lnurlAuthUrl)
    if (inputType is InputType.LnUrlAuth) {
        when (val result = sdk.lnurlAuth(inputType.data)) {
            is LnUrlCallbackStatus.Ok -> {} // Log.v("Breez", "Successfully authenticated")
            is LnUrlCallbackStatus.ErrorStatus -> {} // Log.v("Breez", "Failed to authenticate: ${result.data.reason}")
        }
    }
} catch (e: Exception) {
    // handle error
}
React Native
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
const lnurlAuthUrl =
      'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu'

const input = await parse(lnurlAuthUrl)
if (input.type === InputTypeVariant.LN_URL_AUTH) {
  const result = await lnurlAuth(input.data)
  if (result.type === LnUrlCallbackStatusVariant.OK) {
    console.log('Successfully authenticated')
  } else {
    console.log('Failed to authenticate')
  }
}
Dart
/// Endpoint can also be of the form:
/// keyauth://domain.com/auth?key=val
String lnurlAuthUrl =
    "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";

InputType inputType = await parse(input: lnurlAuthUrl);
if (inputType is InputType_LnUrlAuth) {
  LnUrlCallbackStatus result = await breezSDKLiquid.instance!.lnurlAuth(reqData: inputType.data);
  if (result is LnUrlCallbackStatus_Ok) {
    print("Successfully authenticated");
  } else {
    print("Failed to authenticate");
  }
}
Python
# Endpoint can also be of the form:
# keyauth://domain.com/auth?key=val
lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"

try:
    parsed_input = breez_sdk_liquid.parse(lnurl_auth_url)     
    if isinstance(parsed_input, InputType.LN_URL_AUTH):      
        result = sdk.lnurl_auth(parsed_input.data)        
        if result.is_ok():
            logging.debug("Successfully authenticated")
        else:
            logging.debug("Failed to authenticate")
except Exception as error:
    logging.error(error)
    raise
Go
// keyauth://domain.com/auth?key=val
lnurlAuthUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"

if input, err := breez_sdk_liquid.Parse(lnurlAuthUrl); err != nil {
    switch inputType := input.(type) {
    case breez_sdk_liquid.InputTypeLnUrlAuth:
        if result, err := sdk.LnurlAuth(inputType.Data); err != nil {
            switch result.(type) {
            case breez_sdk_liquid.LnUrlCallbackStatusOk:
                log.Printf("Successfully authenticated")
            default:
                log.Printf("Failed to authenticate")
            }
        }
    }
}
C#
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
var lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";

try
{
    var input = BreezSdkLiquidMethods.Parse(lnurlAuthUrl);
    if (input is InputType.LnUrlAuth lnurla)
    {
        var result = sdk.LnurlAuth(lnurla.data);
        if (result is LnUrlCallbackStatus.Ok)
        {
            Console.WriteLine("Successfully authenticated");
        }
        else
        {
            Console.WriteLine("Failed to authenticate");
        }
    }
}
catch (Exception)
{
    // Handle error
}

Supported Specs

  • LUD-01 LNURL bech32 encoding
  • LUD-04 auth base spec
  • LUD-17 Support for keyauth prefix with non-bech32-encoded LNURL URLs