LightsparkCoroutinesWalletClient

Main entry point for the Lightspark Wallet SDK.

// Initialize the client with account token info:
val oAuthHelper = OauthHelper(applicationContext)
val lightsparkClient = LightsparkCoroutinesWalletClient(ClientConfig(
authProvider = OAuthProvider(oAuthHelper)
))

// An example API call fetching the dashboard info for the active account:
val dashboard = lightsparkClient.getWalletDashboard()

Note: This client object keeps a local cache in-memory, so a single instance should be reused throughout the lifetime of your app.

Constructors

Link copied to clipboard
constructor(config: ClientConfig)

Functions

Link copied to clipboard

Creates an L1 Bitcoin wallet address which can be used to deposit or withdraw funds from the Lightning wallet.

Link copied to clipboard
suspend fun createInvoice(amountMsats: Long, memo: String? = null, type: InvoiceType = InvoiceType.STANDARD): InvoiceData

Creates a lightning invoice from the current wallet.

Link copied to clipboard
suspend fun decodeInvoice(encodedInvoice: String): InvoiceData

Decode a lightning invoice to get its details included payment amount, destination, etc.

Link copied to clipboard
suspend fun deployWallet(): Wallet

Deploys a wallet in the Lightspark infrastructure. This is an asynchronous operation, the caller should then poll the wallet frequently (or subscribe to its modifications). When this process is over, the Wallet status will change to DEPLOYED (or FAILED).

Link copied to clipboard

Deploys a wallet in the Lightspark infrastructure and triggers updates as state changes. This is an asynchronous operation, which will continue sending the wallet state updates until the Wallet status changes to DEPLOYED (or FAILED).

Link copied to clipboard
suspend fun <T> executeQuery(query: Query<T>): T

Executes a raw graphql query against the server.

Link copied to clipboard

Get the L1 fee estimate for a deposit or withdrawal.

Link copied to clipboard
suspend fun getCurrentWallet(): Wallet?
Link copied to clipboard
suspend fun getLightningFeeEstimateForInvoice(encodedPaymentRequest: String, amountMsats: Long? = null): CurrencyAmount

Gets an estimate of the fees that will be paid for a Lightning invoice.

Link copied to clipboard
suspend fun getLightningFeeEstimateForNode(destinationNodePublicKey: String, amountMsats: Long): CurrencyAmount

Returns an estimate of the fees that will be paid to send a payment to another Lightning node.

Link copied to clipboard
suspend fun getWalletDashboard(numTransactions: Int = 20, numPaymentRequests: Int = 20): WalletDashboard?

Get the dashboard overview for a Lightning wallet. Includes balance info and the most recent transactions and payment requests.

Link copied to clipboard
suspend fun initializeWallet(keyType: KeyType, signingPublicKey: String): Wallet

Initializes a wallet in the Lightspark infrastructure and syncs it to the Bitcoin network. This is an asynchronous operation, the caller should then poll the wallet frequently (or subscribe to its modifications). When this process is over, the Wallet status will change to READY (or FAILED).

Link copied to clipboard
suspend fun initializeWalletAndWaitForInitialized(keyType: KeyType, signingPublicKey: String): Flow<Wallet>

Initializes a wallet in the Lightspark infrastructure and syncs it to the Bitcoin network and triggers updates as state changes. This is an asynchronous operation, which will continue sending the wallet state updates until the Wallet status changes to READY (or FAILED).

Link copied to clipboard
Link copied to clipboard
fun loadWalletSigningKey(signingKeyBytesPEM: ByteArray)

Unlocks the wallet for use with the SDK for the current application session. This function must be called before any other functions that require wallet signing keys, including payInvoice.

Link copied to clipboard
fun loadWalletSigningKeyAlias(signingKeyAlias: String)

Unlocks the wallet for use with the SDK for the current application session by specifying a key alias in the KeyStore where the wallet's key is stored.

Link copied to clipboard
suspend fun loginWithJWT(accountId: String, jwt: String, storage: JwtStorage): LoginWithJWTOutput

Login using the Custom JWT authentication scheme described in our documentation.

Link copied to clipboard
Link copied to clipboard
suspend fun payInvoice(encodedInvoice: String, maxFeesMsats: Long, amountMsats: Long? = null, timeoutSecs: Int = 60): OutgoingPayment

Pay a lightning invoice from the current wallet.

Link copied to clipboard
suspend fun requestWithdrawal(amountSats: Long, bitcoinAddress: String): WithdrawalRequest

Withdraws funds from the account and sends it to the requested bitcoin address.

Link copied to clipboard
suspend fun sendPayment(destinationPublicKey: String, amountMsats: Long, maxFeesMsats: Long, timeoutSecs: Int = 60): OutgoingPayment

Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.

Link copied to clipboard
fun setAuthProvider(authProvider: AuthProvider)

Override the auth token provider for this client to provide custom headers on all API calls.

Link copied to clipboard
fun setServerEnvironment(environment: ServerEnvironment, invalidateAuth: Boolean)
Link copied to clipboard

Removes the wallet from Lightspark infrastructure. It won't be connected to the Lightning network anymore and its funds won't be accessible outside of the Funds Recovery Kit process.

Link copied to clipboard
suspend fun terminateWallet(): Wallet

Removes the wallet from Lightspark infrastructure. It won't be connected to the Lightning network anymore and its funds won't be accessible outside of the Funds Recovery Kit process.