Transaction Confirmation
Passkeys can also be used for digitial signed transactions, making them useful in situations like:
- Financial transactions: Ensures users confirm actions involving transfers or payments, preventing unauthorized activity.
- Data integrity: Validates any state-changing operation (e.g., updating sensitive records) with user authentication to avoid tampering.
- Non-repudiation: Provides legal proof of action approval in scenarios like contract signing or agreement approvals.
Prerequisites
- Create an application to obtain a base URL
Setup SDK
- Javascript
- Kotlin
- Swift
npm i @loginid/websdk3
Import and initialize an instance:
import { LoginIDWebSDK } from "@loginid/websdk3";
const lid = new LoginIDWebSDK({
baseUrl: process.env.LOGINID_BASE_URL,
});
Initialize a singleton configuration for the LoginID service in the application's onCreate
method.
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
// Initialize the singleton instance
val config = LoginIDServiceConfig("<BASE_URL>")
LoginID.configure(config).client()
}
}
Configure the singleton instance of LIDClient
with a base URL during the app's launch in the AppDelegate
.
import LoginID
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Initialize the singleton instance
LIDClient.shared.configure(baseURL: "<BASE_URL>")
return true
}
}
Sign a Transaction Using Transaction Confirmation
Transaction confirmation requires:
- username and transaction payload
- nonce (optional)
The transaction payload accepts a string, such as plain text or JSON string.
The nonce is any unique identifier or reference for the transaction payload.
- Javascript
- Kotlin
- Swift
import { LoginIDWebSDK } from "@loginid/websdk3";
const config = {
baseUrl: BASE_URL,
};
const lid = new LoginIDWebSDK(config);
async function handleTransactionConfirmation() {
try {
// The txPayload and nonce can be generated on the backend
const { username } = lid.getSession();
// The nonce value is optional
const options = { nonce: nonce };
const confirmationResult = await lid.confirmTransaction(
username,
txPayload,
options
);
// You can pass the LoginID token to your backend for verification
} catch (error) {
// Handle errors
console.error("Error during transaction confirmation:", error);
}
}
import loginid.LoginID
import services.modals.LoginIDOptions
class MainActivity : AppCompatActivity() {
private lateinit var errorTextView: TextView
private lateinit var confirmTransactionButton: Button
private fun handleTransactionConfirmation() {
val username = AuthContext.getUser().username
errorTextView.text = ""
GlobalScope.launch(Dispatchers.Main) {
try {
// Call backend to prepare the transaction
val result = BackendService.prepareTransaction(
amount = 100,
recipient = "bob@securepay.com"
)
// Confirm the transaction with LoginID SDK
val options = LoginIDOptions(nonce = result.nonce)
val confirmationResult = LoginID.client().confirmTransaction(
this@MainActivity,
username,
result.txPayload,
options,
)
// Pass the confirmation result to your backend for verification
BackendService.verifyTransaction(confirmationResult)
} catch (e: Exception) {
when (e) {
is LoginIDError -> {
errorTextView.text = e.message ?: "A LoginID error occurred"
}
else -> {
errorTextView.text = e.message ?: "An error occurred"
}
}
Log.e("Error", "Error during transaction confirmation", e)
}
}
}
}
Coming soon
After receiving the confirmTransaction result, send it to your backend to verify the token and transaction details. For more details, see our backend integration section.