Skip to Content
dApp 接入
本页目录

lnurl

请求执行 LNURL  操作。应用需传入 LNURL  字符串,例如由应用后端提供。lnurl 方法也接受 LUD-16  静态标识(如 [email protected]),用于代替 LNURL 字符串。

该方法返回一个 Promise,在 LNURL 流程完成后解析。它返回来自 LNURL 服务器的最后响应。对于 LNURL-pay 请求,它还包含支付信息(preimage、payment hash),对于 LNURL-auth 请求,它包含认证信息(message、signature)

方法

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

响应

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

LNURL-pay 响应

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

LNURL-auth 响应

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

示例

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)

检查 result.status:ERROR 响应包含 reason。同时捕获 Promise 拒绝,包括连接失败或用户未批准。可选的 data 内容取决于 LNURL 流程,读取前不要假定其结构固定。

最后更新于