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. The SDK uses this base URL to interact with the LoginID authentication service.
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,
});
First, ensure you have the Maven Central repository in your project's settings.gradle.kts file:
repositories {
google()
mavenCentral()
}
Next, add the SDK and required dependencies to your app module's build.gradle.kts:
dependencies {
// LoginID SDK
implementation("io.loginid:auth:1.0.1")
}
Import the class within your application:
import io.loginid.auth
class MainActivity : AppCompatActivity() {
val lid = LoginIDAuth(this, "<LOGINID_BASE_URL>")
override fun onCreate() {
super.onCreate()
// Additional setup...
}
}
Add the SDK dependency using Swift Package Manager in Xcode:
- In Xcode, open your project.
- Go to File → Add Package Dependencies….
- In the search bar, paste:
https://github.com/loginid1/loginid-ios
- Select the target(s) where you want to add the SDK and click Add Package.
Import the class within your view models:
import LoginIDAuth
@main
struct MyApp: App {
private let lid: LoginIDAuth
init() {
LoginIDAuth(baseUrl: "<LOGINID_BASE_URL>")
// Other setup code...
}
}
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.getSessionInfo();
// The nonce value is optional
const options = { nonce: nonce };
// Use passkey to confirm transaction
const confirmationResult = await lid.confirmTransaction(
username,
txPayload,
options
);
// Verify tx confirmationResult on your backend
} catch (error) {
// Handle errors
console.error("Error during transaction confirmation:", error);
}
}
import androidx.lifecycle.lifecycleScope
import io.loginid.auth.LoginIDAuth
import io.loginid.auth.models.ConfirmTransactionOptions
import io.loginid.core.errors.LoginIDError
import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
private lateinit var errorTextView: TextView
private lateinit var confirmTransactionButton: Button
private val lid = LoginIDAuth(this, "<BASE_URL>")
private fun handleTransactionConfirmation() {
val username = AuthContext.getUser().username
errorTextView.text = ""
lifecycleScope.launch {
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 = ConfirmTransactionOptions(nonce = result.nonce)
val confirmationResult = lid.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)
}
}
}
}
import SwiftUI
import LoginIDAuth
@main
struct ExampleApp: App {
private let lid = LoginIDAuth(baseUrl: "<BASE_URL>")
private func confirmTransaction() async {
do {
// The txPayload and nonce can be generated on the backend
let info = lid.getSessionInfo()
// The nonce value is optional
let options = ConfirmTransactionOptions(
nonce: nonce
)
// Use passkey to confirm transaction
let result = try await lid.confirmTransaction(
username: info?.username ?? "",
txPayload: txPayload,
options: options,
)
// Verify tx result on your backend
} catch let error as LoginIDError {
errorMessage = error.message
} catch {
errorMessage = error.localizedDescription
}
}
}
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.