Class WebLNWallet
java.lang.Object
org.ngengine.wallets.webln.WebLNWallet
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Wallet
Wallet.Methods -
Constructor Summary
ConstructorsConstructorDescriptionCreates a browser wallet adapter without requesting provider permissions. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the wallet and release any resources.org.ngengine.platform.AsyncTask<Long> getBalance(Instant deadline) Get the msats balance of the wallet.org.ngengine.platform.AsyncTask<WalletInfo> Get information about the wallet.Returns the provider's lud16, lightningAddress or lud06, or null if unavailable.protected org.ngengine.platform.AsyncTask<Boolean> Checks for a browser runtime and a provider method through the default browser bridge.org.ngengine.platform.AsyncTask<Boolean> Checks for the provider's enable method without asking for permissions.org.ngengine.platform.AsyncTask<Boolean> isMethodSupported(Wallet.Methods method) Check if a specific method is supported by the wallet.booleanisReady()Check if the wallet is ready to use.org.ngengine.platform.AsyncTask<List<TransactionInfo>> listTransactions(Instant from, Instant until, Integer limit, Integer offset, boolean includeUnpaid, TransactionType type, Instant deadline) List transactions in the wallet.org.ngengine.platform.AsyncTask<InvoiceData> lookupInvoice(String hash, String invoice, Instant deadline) Lookup an invoice by payment hash or invoice string.org.ngengine.platform.AsyncTask<InvoiceData> makeInvoice(InvoiceProperties properties, Instant deadline) Create a lightning invoiceorg.ngengine.platform.AsyncTask<PayResponse> payInvoice(String invoice, Long amountMsats, Instant deadline) Pay a lightning invoiceprotected org.ngengine.platform.AsyncTask<Object> Invokes a method on the browser's WebLN provider through the platform bridge.org.ngengine.platform.AsyncTask<Boolean> Enables the provider and loads its wallet information.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Wallet
getBalance, getInfo, listTransactions, lookupInvoice, makeInvoice, payInvoice
-
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
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 prefixargs- arguments forwarded to the provider- Returns:
- task containing the provider's result or failure
-
hasMethod
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
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:
isAvailablein interfaceWallet- Returns:
- whether this open adapter can reach a WebLN provider
-
getReceivingAddress
Returns the provider's lud16, lightningAddress or lud06, or null if unavailable.- Specified by:
getReceivingAddressin interfaceWallet
-
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:
waitForReadyin interfaceWallet- Returns:
- task reporting readiness, or a failure when the provider is unavailable or closed
-
isReady
-
close
-
isMethodSupported
Description copied from interface:WalletCheck if a specific method is supported by the wallet.- Specified by:
isMethodSupportedin interfaceWallet- 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:WalletPay a lightning invoice- Specified by:
payInvoicein interfaceWallet- Parameters:
invoice- the lightning invoice to payamountMsats- the amount in millisatoshis to pay, or null to use the invoice amountdeadline- 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:WalletCreate a lightning invoice- Specified by:
makeInvoicein interfaceWallet- Parameters:
properties- the properties for the invoice to createdeadline- an optional Instant to expire the request at, or null for no expiration- Returns:
-
getBalance
Description copied from interface:WalletGet the msats balance of the wallet.- Specified by:
getBalancein interfaceWallet- 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
Description copied from interface:WalletGet information about the wallet. -
lookupInvoice
public org.ngengine.platform.AsyncTask<InvoiceData> lookupInvoice(String hash, String invoice, Instant deadline) Description copied from interface:WalletLookup an invoice by payment hash or invoice string.- Specified by:
lookupInvoicein interfaceWallet- Parameters:
hash- the payment hash to lookup, or null if not availableinvoice- the invoice string to lookup, or null if not availabledeadline- 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:WalletList transactions in the wallet.- Specified by:
listTransactionsin interfaceWallet- Parameters:
from- the start time to filter transactions from, or null for no start timeuntil- the end time to filter transactions until, or null for no end timelimit- the maximum number of transactions to return, or null for no limitoffset- the offset to start returning transactions from, or null for no offsetincludeUnpaid- whether to include unpaid transactions, or false to exclude themtype- the type of transactions to filter by, or null for all typesdeadline- 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
-