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(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? parseInput(s: lnurlAuthUrl) {
    if case let .lnUrlAuth(data) = inputType {
        let result = try? sdk.lnurlAuth(reqData: data)
        switch result {
        case .ok:
            print("Successfully authenticated")
        case let .errorStatus(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 = parseInput(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
try {
  const lnurlAuthUrl =
        'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu'

  const input = await parseInput(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')
    }
  }
} catch (err) {
  console.error(err)
}
Dart
/// Endpoint can also be of the form:
/// keyauth://domain.com/auth?key=val
String lnurlAuthUrl =
    "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";

InputType inputType = await breezSDK.parseInput(input: lnurlAuthUrl);
if (inputType is InputType_LnUrlAuth) {
  LnUrlCallbackStatus result = await breezSDK.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.parse_input(lnurl_auth_url)     
  if isinstance(parsed_input, breez_sdk.InputType.LN_URL_AUTH):      
    req = breez_sdk
    result = sdk_services.lnurl_auth(parsed_input.data)        
  if result.is_ok():
    print("Successfully authenticated")
  else:
    print("Failed to authenticate")
except Exception as error:
    print(error)
    raise
Go
// keyauth://domain.com/auth?key=val
lnurlAuthUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"

if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
    switch inputType := input.(type) {
    case breez_sdk.InputTypeLnUrlAuth:
        if result, err := sdk.LnurlAuth(inputType.Data); err != nil {
            switch result.(type) {
            case breez_sdk.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 = BreezSdkMethods.ParseInput(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