Skip to Content
dApps
Sur cette page

lnurl

Demander l’exécution d’une requête LNURL . L’application doit transmettre une chaîne LNURL  qui doit être fournie, par exemple, par son backend. La fonction lnurl peut également accepter un identifiant statique LUD-16  (par exemple, [email protected]) à la place d’une chaîne LNURL.

La méthode renvoie une promesse qui se résout une fois le processus LNURL terminé. Elle renvoie la dernière réponse du serveur LNURL. Pour les demandes LNURL-pay, elle contient aussi les informations de paiement (préimage, hash de paiement) et, pour les demandes LNURL-auth, les informations d’authentification (message, signature)

Méthode

declare function lnurl(lnurl: string): Promise<LNURLResponse>;;

Réponse

type LNURLResponse = | { status: "OK"; data?: unknown } | { status: "ERROR"; reason: string };

Réponse LNURL-pay

type LNURLPayResponse = | { status: "OK"; data: { preimage: string, paymentHash: string, paymentRequest: string } } | { status: "ERROR"; reason: string };

Réponse LNURL-auth

type LNURLAuthResponse = | { status: "OK"; data: { message: string, signature: string } } | { status: "ERROR"; reason: string };

Exemple

const lnurl = "<LNURL_OR_LIGHTNING_ADDRESS>"; const provider = (window.$onekey && window.$onekey.webln) || window.webln; if (!provider || typeof provider.lnurl !== "function") { throw new Error("LNURL is not supported by this provider."); } await provider.enable(); const result = await provider.lnurl(lnurl); // promise resolves once the LNURL process is finished (e.g. a payment is sent or the login is complete)

Vérifiez result.status : une réponse ERROR contient un champ reason. Interceptez aussi les promesses rejetées, notamment les échecs de connexion ou d’approbation utilisateur. L’élément facultatif data dépend du processus LNURL ; ne supposez pas une structure fixe sans la vérifier.

Dernière mise à jour le