Particle Auth for Android
The Particle Auth Android SDK is the flagship mechanism for integrating Particle’s Wallet-as-a-Service within Android applications. This SDK is the sole facilitator of Android integration for most applications and is built for simplicity. As with the other Particle Auth SDKs, it requires only a few lines of code. Unlike the Unity SDK and Web SDK, the Android SDK differs in installation and configuration; these specific intricacies and setup processes are detailed below.Getting Started
Using the Particle Auth Android SDK is straightforward but requires meeting a few minimum version prerequisites to ensure compatibility.Prerequisites
- minSdkVersion 23 or higher.
- compileSdkVersion, targetSdkVersion 34 or higher.
- JavaVersion 17.
- Jetpack (AndroidX).
- Android Gradle Plugin Version: 8.5.1 or higher.
- Gradle Version: 8.9 or higher.
Configuration
Before you begin using the Particle Auth Android SDK, you’ll need a few required universal values across all Particle Auth SDKs. These values areprojectId
, clientKey
, and appId
. All three can be retrieved by heading to the Particle dashboard.
Follow the quickstart tutorial to set up a project and find the required keys:
Create a new
project.
Installation
Once you’ve created a project and application on the Particle Dashboard, you can install and initializeParticleNetwork
.
Start by declaring the Particle Auth SDK in your Gradle file.
Kotlin
For release updates, subscribe to the GitHub
repository.
projectId
, clientKey
, and appId
within the relevant AndroidManifest.xml
file.
An example of such a configuration is attached below. Placeholders such as pn_project_id
will need to be filled in.
XML
Examples of utilization
Initialize the SDK
Upon application startup,ParticleNetwork
must be initialized to function correctly.
This can be done by calling the init
method on ParticleNetwork
and passing in the primary chain you intend to use within your application.
Kotlin
Switch Chain
To switch the chain after the initial configuration, useAuthCore.switchChain
. This allows for asynchronous switching, just like the initial setup.
Kotlin
Login
AuthCore.connect
triggers the standard login popup, which changes based on configurations like loginType
(similar to the Web SDK’s preferredAuthType
) and supportAuthTypeValues
.
This popup serves as the primary method for account creation and login for existing users.
The AuthCore.login
function accepts the following parameters:
Field | Type | Description |
---|---|---|
loginType | LoginType | Specifies the preferred social login method. Options include EMAIL , PHONE , TWITTER , GOOGLE , FACEBOOK , APPLE , DISCORD , GITHUB , TWITCH , MICROSOFT , LINKEDIN , and JWT . |
account | String | The account parameter allows you to pass an expected email, phone number, or JWT. This field is optional for email and phone logins but required for JWT . The phone number must be in E.164 format. |
supportLoginTypes | List<SupportLoginType> | Defines the supported social login methods. By default, all options are supported: EMAIL , PHONE , FACEBOOK , GOOGLE , APPLE , TWITTER , DISCORD , GITHUB , TWITCH , MICROSOFT , and LINKEDIN . You can also specify a subset of these types if needed. |
prompt | LoginPrompt? | Controls the prompt displayed after social login. Options are None , Consent , or SelectAccount . This is only supported by Google, Discord, and Microsoft. |
loginPageConfig | LoginPageConfig? | Customizes the UI of the login page, including the project name, icon, and description. |
loginCallback | AuthCoreServiceCallback<UserInfo> | Callback triggered after the login attempt. Success: Returns UserInfo .Failure: Returns ErrorInfo . |
You can use your existing user base or authentication method with Particle Auth through JWT. This way, your users can still log in with their current accounts. Check Custom Authentication (JWT) to learn how to configure it.
Kotlin
UserInfo and Address Retrieval (post-login)
After a successful login, you can retrieve detailed user information by calling the following methods.Kotlin
Logout
AuthCore.disconnect
logs the user out of their current session and returns them to their pre-login state.
Kotlin
Is User Logged In
AuthCore.isLogin
returns a Boolean indicating whether the user is currently logged in with Particle.
Kotlin
syncUserInfo
to synchronize the information.
Signatures
OnceParticleNetwork
has been initialized and a user has successfully logged in, signatures can be proposed for confirmation through a pop-up.
EVM
Signing Messages (EIP191)
To request an EIP191 signature from a user’s embedded wallet, you can use either theAuthCore.evm.personalSign
or AuthCore.evm.personalSignUnique
method.
If you need the same message to return a unique signature each time, use the AuthCore.evm.personalSignUnique
method. Otherwise, the AuthCore.evm.personalSign
method is generally recommended.
Field | Type | Description |
---|---|---|
hexUnSignedMessage | PrefixedHexString | A required field that accepts either a hexadecimal string starting with ‘0x’ or a human-readable string. |
callback | AuthCoreSignCallback<SignOutput> | Handles the response of the signing operation. Success: Returns the signature. Failure: Returns ErrorInfo . |
signAndSendTransaction (Kotlin)
Signing Typed Data V4 (EIP712)
To request an EIP712 signature from a user’s embedded wallet, you can use either theAuthCore.evm.signTypedData
or AuthCore.evm.signTypedDataUnique
method.
If you need the same message to return a unique signature each time, use the AuthCore.evm.signTypedDataUnique
method. Otherwise, the AuthCore.evm.signTypedData
method is generally recommended.
Field | Type | Description |
---|---|---|
data | PrefixedHexString | A hexadecimal string that must start with “0x”. |
callback | AuthCoreSignCallback<SignOutput> | Handles the response of the signing operation. Success: Returns the signature. Failure: Returns ErrorInfo . |
signAndSendTransaction (Kotlin)
Transaction
To send a transaction from a user’s embedded wallet, you can useAuthCore.evm.sendTransaction
.
Field | Type | Description |
---|---|---|
transaction | PrefixedHexString | A hexadecimal string that must start with “0x”. |
callback | AuthCoreSignCallback<SignOutput> | Handles the response of the signing operation. Success: Returns the signature. Failure: Returns ErrorInfo . |
feeMode | FeeMode | The mode for handling transaction fees. The default is FeeModeNative() . Use this field only when AA mode is enabled. |
ParticleNetwork.evm.createTransaction()
method.
Solana
Signing Messages
To request a signature from a user’s embedded wallet, useAuthCore.solana.signMessage
.
Field | Type | Description |
---|---|---|
message | String | A base58-formatted string that is required for the signature request. |
callback | AuthCoreSignCallback<SignOutput> | Handles the response of the signing operation. Success: Returns the signature. Failure: Returns ErrorInfo . |
Transaction
To send a transaction from a user’s embedded wallet, useAuthCore.solana.signAndSendTransaction
.
Field | Type | Description |
---|---|---|
transaction | String | A base58-formatted string that is required for the transaction. |
callback | AuthCoreSignCallback<SignOutput> | Handles the response of the transaction. Success: Returns the signature. Failure: Returns ErrorInfo . |
Field | Type | Description |
---|---|---|
transaction | String | A base58-formatted string is required. |
callback | AuthCoreSignCallback<SignOutput> | Success: Returns the signature. Failure: Returns ErrorInfo . |
AuthCore. Solana.signAllTransactions
.
Field | Type | Description |
---|---|---|
serializedTransactions | List<Base58String> | A list of base58-formatted strings is required. |
callback | AuthCoreSignCallback<SignAllOutput> | Success: Returns the signatures. Failure: Returns ErrorInfo . |
Open Account and Security
If you want to force the “Account and Security” options to open on-screen—where you can manage master passwords, payment passwords, additional accounts, and more—callAuthCore.openAccountAndSecurity
.
Kotlin
Set Security Account Config
Within the security settings, specific popups can be configured to display during confirmation or when entering the wallet UI. These includepromptSettingWhenSign
for payment (signature) passwords and promptMasterPasswordSettingWhenLogin
for a login-based master password.
By default, promptSettingWhenSign
is set to 1, prompting the user on the first signature for a given account. If set to 0, the prompt is never shown; if set to 2, it is shown for every signature confirmation.
The same logic applies to promptMasterPasswordSettingWhenLogin
, though it defaults to 0.
Kotlin
Master Password and Payment Password
Users can set a master password and payment password to protect their assets. To set or change the master password, callauth.changeMasterPassword
.
To set or change the payment password, call AuthCore.openAccountAndSecurity()
.
Language Setting
You can force a specific language within the UI usingParticleNetwork.setLanguage
and retrieve the currently active language with ParticleNetwork.getAppliedLanguage
. The default language is English.
Field | Type | Description |
---|---|---|
languageEnum | LanguageEnum | The specific language to be used. Options include ZH_CN , ZH_TW , EN , JA , KO . |
isRelaunch | Boolean | If true, the app will relaunch upon a language switch; if false, the activity will be recreated. |
isInit | Boolean | If isRelaunch is set to true, isInit defaults to true. The activity will not be recreated and should be called before methods like signMessage or sendTransaction . |
Enable Blind Signing
Silently sign messages/transactions if the following conditions are met:- Your account is connected via JWT.
- Your account does not have a payment password set.
SecurityAccountConfig.promptSettingWhenSign
is set to 0. You can update this value by callingParticleNetwork.setSecurityAccountConfig
.