Class WebLNWallet

java.lang.Object
org.ngengine.wallets.webln.WebLNWallet
All Implemented Interfaces:
Wallet

public class WebLNWallet extends Object implements Wallet
WebLN browser wallet, accessed through the platform's JavaScript function bridge. Constructing a wallet never prompts for permissions; call waitForReady() from a user action. Providers do not expose standard invoice lookup or transaction history APIs.
  • Constructor Details

    • WebLNWallet

      public WebLNWallet()
      Creates a browser wallet adapter without requesting provider permissions. Invoke waitForReady() from a user action to enable the provider. Closing the adapter releases its executor and pending local waits; it cannot revoke a submitted payment.
  • Method Details

    • request

      protected org.ngengine.platform.AsyncTask<Object> request(String method, List<?> args)
      Invokes a method on the browser's WebLN provider through the platform bridge. The default target is window.webln. Hosts without a window, such as SharedWorkers, can override this method and the capability probe to route calls to their owner.
      Parameters:
      method - provider method name without the window.webln prefix
      args - arguments forwarded to the provider
      Returns:
      task containing the provider's result or failure
    • hasMethod

      protected org.ngengine.platform.AsyncTask<Boolean> hasMethod(String method)
      Checks for a browser runtime and a provider method through the default browser bridge. Override together with request() when routing provider calls through another host.
      Parameters:
      method - provider method name without the window.webln prefix
      Returns:
      whether the provider exposes the requested method
    • isAvailable

      public org.ngengine.platform.AsyncTask<Boolean> isAvailable()
      Checks for the provider's enable method without asking for permissions. Availability does not imply that the provider is enabled or supports every wallet method.
      Specified by:
      isAvailable in interface Wallet
      Returns:
      whether this open adapter can reach a WebLN provider
    • getReceivingAddress

      @Nullable public String getReceivingAddress()
      Returns the provider's lud16, lightningAddress or lud06, or null if unavailable.
      Specified by:
      getReceivingAddress in interface Wallet
    • waitForReady

      public org.ngengine.platform.AsyncTask<Boolean> waitForReady()
      Enables the provider and loads its wallet information. Call this from a user action because enable may prompt for permission. Concurrent callers share one attempt; a failed attempt can be retried explicitly. Ready wallets and existing attempts use volatile reads before the initialization monitor.
      Specified by:
      waitForReady in interface Wallet
      Returns:
      task reporting readiness, or a failure when the provider is unavailable or closed
    • isReady

      public boolean isReady()
      Description copied from interface: Wallet
      Check if the wallet is ready to use.
      Specified by:
      isReady in interface Wallet
      Returns:
      true if the wallet is ready, false otherwise
    • close

      public void close()
      Description copied from interface: Wallet
      Close the wallet and release any resources.
      Specified by:
      close in interface Wallet
    • isMethodSupported

      public org.ngengine.platform.AsyncTask<Boolean> isMethodSupported(Wallet.Methods method)
      Description copied from interface: Wallet
      Check if a specific method is supported by the wallet.
      Specified by:
      isMethodSupported in interface Wallet
      Parameters:
      method - the method to check support for
      Returns:
      an AsyncTask that resolves to true if the method is supported, false otherwise
    • payInvoice

      public org.ngengine.platform.AsyncTask<PayResponse> payInvoice(String invoice, Long amountMsats, Instant deadline)
      Description copied from interface: Wallet
      Pay a lightning invoice
      Specified by:
      payInvoice in interface Wallet
      Parameters:
      invoice - the lightning invoice to pay
      amountMsats - the amount in millisatoshis to pay, or null to use the invoice amount
      deadline - an optional Instant to expire the request at, or null for no expiration
      Returns:
      an AsyncTask that resolves to a PayResponse containing the payment result
    • makeInvoice

      public org.ngengine.platform.AsyncTask<InvoiceData> makeInvoice(InvoiceProperties properties, Instant deadline)
      Description copied from interface: Wallet
      Create a lightning invoice
      Specified by:
      makeInvoice in interface Wallet
      Parameters:
      properties - the properties for the invoice to create
      deadline - an optional Instant to expire the request at, or null for no expiration
      Returns:
    • getBalance

      public org.ngengine.platform.AsyncTask<Long> getBalance(Instant deadline)
      Description copied from interface: Wallet
      Get the msats balance of the wallet.
      Specified by:
      getBalance in interface Wallet
      Parameters:
      deadline - an optional Instant to expire the request at, or null for no expiration
      Returns:
      an AsyncTask that resolves to the balance in millisatoshis
    • getInfo

      public org.ngengine.platform.AsyncTask<WalletInfo> getInfo(Instant deadline)
      Description copied from interface: Wallet
      Get information about the wallet.
      Specified by:
      getInfo in interface Wallet
      Parameters:
      deadline - an optional Instant to expire the request at, or null for no expiration
      Returns:
      an AsyncTask that resolves to a WalletInfo containing the wallet details
    • lookupInvoice

      public org.ngengine.platform.AsyncTask<InvoiceData> lookupInvoice(String hash, String invoice, Instant deadline)
      Description copied from interface: Wallet
      Lookup an invoice by payment hash or invoice string.
      Specified by:
      lookupInvoice in interface Wallet
      Parameters:
      hash - the payment hash to lookup, or null if not available
      invoice - the invoice string to lookup, or null if not available
      deadline - an optional Instant to expire the request at, or null for no expiration
      Returns:
      an AsyncTask that resolves to an InvoiceData containing the invoice details
    • listTransactions

      public org.ngengine.platform.AsyncTask<List<TransactionInfo>> listTransactions(Instant from, Instant until, Integer limit, Integer offset, boolean includeUnpaid, TransactionType type, Instant deadline)
      Description copied from interface: Wallet
      List transactions in the wallet.
      Specified by:
      listTransactions in interface Wallet
      Parameters:
      from - the start time to filter transactions from, or null for no start time
      until - the end time to filter transactions until, or null for no end time
      limit - the maximum number of transactions to return, or null for no limit
      offset - the offset to start returning transactions from, or null for no offset
      includeUnpaid - whether to include unpaid transactions, or false to exclude them
      type - the type of transactions to filter by, or null for all types
      deadline - an optional Instant to expire the request at, or null for no expiration
      Returns:
      an AsyncTask that resolves to a List of TransactionInfo containing the transactions