Make sure that your project meets the following requirements:
- minSdkVersion must be 23 or higher
- compileSdkVersion and targetSdkVersion must be 33 or higher
- Uses JavaVersion 11
- Uses Jetpack (AndroidX)
Before you can add Auth Core to your Android app, you need to create a Particle project to connect your app. Visit Particle Dashboard to learn more about Particle projects and apps.
👉 Sign up/log in and create your project now
Declare them in your module (app-level) Gradle file (usually app/build.gradle).
repositories {
google()
mavenCentral()
maven { setUrl("https://jitpack.io") }
//...
}
dependencies {
// Particle Auth Core
implementation("network.particle:auth-core:${latest_version}")
implementation("network.particle:mpc-core:${latest_version}")
//find the latest version of the sdk:
//https://search.maven.org/search?q=g:network.particle
//...
}
Declare them in you app AndroidManifest.xml (usually app/src/main/AndroidManifest.xml).
<!-- add fullBackupContent to exclude particle encrypted file -->
<application android:fullBackupContent="@xml/pn_backup_rules">
<!-- Particle Network config start -->
<meta-data
android:name="particle.network.project_id"
android:value="${pn_project_id}"
/>
<meta-data
android:name="particle.network.project_client_key"
android:value="${pn_project_client_key}"
/>
<meta-data
android:name="particle.network.app_id"
android:value="${pn_app_id}"
/>
<!-- Particle Network config end -->
</application>
{% hint style="info" %} Replace pn_project_id, pn_project_client_key, pn_app_id with the new values created in Particle Dashboard. {% endhint %}
Initialize the SDK by calling the ParticleNetwork.init()
method, passing the method a context. Do this as soon as your app starts, like in the onCreate()
method of your Application
.
import com.particle.base.Env
import com.particle.base.LanguageEnum
import com.particle.base.ParticleNetwork
import network.particle.chains.ChainInfo
class App : Application() {
override fun onCreate() {
super.onCreate()
ParticleNetwork.init(this, Env.PRODUCTION, ChainInfo.Ethereum)
}
}
Particle Network support Solana and EVM chains, you can init with below chain info:
👉 chainId and chainName configs
Login Particle with JWT.
{% tabs %} {% tab title="Kotlin" %}
AuthCore.connect(jwt, callback)
{% endtab %} {% endtabs %}
{% hint style="info" %}
After log-in success, you can obtain user info by calling AuthCore.getUserInfo()
{% endhint %}
The SDK will delete users' account information in cache.
{% tabs %} {% tab title="Kotlin" %}
AuthCore.disconnect(callback)
{% endtab %} {% endtabs %}
{% tabs %} {% tab title="Kotlin" %}
AuthCore.isConnected()
{% endtab %} {% endtabs %}
// EVM wallet address
val evmAddress = AuthCore.evm.getAddress()
// Solana wallet address
val solanaAddress = AuthCore.solana.getAddress()
{% tabs %} {% tab title="Kotlin" %}
AuthCore.switchChain(ChainInfo.BNBChain, callback)
{% endtab %} {% endtabs %}
Use Auth Core SDK to sign a transaction or message.
{% tabs %} {% tab title="EVM" %}
// personal sign
AuthCore.evm.personalSign(message, object : AuthCoreSignCallback<SignOutput> {
override fun success(output: SignOutput) {
val signature = output.signature
}
override fun failure(errMsg: ErrorInfo) {
}
})
// personal sign unique
AuthCore.evm.personalSignUnique(message, callback)
// sign typed data
AuthCore.evm.ko(typedData, callback)
//sign typed data unique
AuthCore.evm.signTypedDataUnique(typedData, callback)
//send evm transaction
AuthCore.evm.sendTransaction(transaction, callback)
// request public rpc
AuthCore.evm.request(payload)
{% endtab %}
{% tab title="Solana" %}
// sign message
AuthCore.solana.signMessage(message, callback)
// sign transaction
AuthCore.solana.signTransaction(transaction, callback)
// sign all transactions
AuthCore.solana.signAllTransactions(transactions, callback)
// sign and send transaction
AuthCore.solana.signAndSendTransaction(transaction, callback)
// request public rpc
AuthCore.solana.request(payload)
{% endtab %} {% endtabs %}
Wallet can set master password to protect assets.
// check user has master password or not
AuthCore.hasMasterPassword()
// set master password
AuthCore.setMasterPassword(callback)
//change master password
AuthCore.changeMasterPassword(callback)
If set a payment password, user should input password before sign message and transaction.
// check user has payment password or not
AuthCore.hasPaymentPassword()
Bind more login account, manage payment password etc.
AuthCore.openAccountAndSecurity(context)
You can open Particle Ramp to buy crypto tokens.
AuthCore.openBuy(
activity,
walletAddress: String? = null,//nullable,default is current wallet address
amount: Int? = null, //1000
fiatCoin: String = "usd",
cryptoCoin: String = "eth",
fixFiatCoin: Boolean = false,
fixFiatAmt: Boolean = false,
fixCryptoCoin: Boolean = false,
theme: String = "light", // light or dark
language: String = "en-us", //en-us、ko-kr、zh-cn、zh-tw、ja-jp
chainName: String? = null // ChainInfo.Ethereum.name、ChainInfo.Polygon.name ... , nullable,default ParticleNetwork.chainInfo.name
)
// set security account config,
// promptSettingWhenSign default value is 1.
// promptMasterPasswordSettingWhenLogin default value is 0.
// 0 no prompt
// 1 first time show prompt
// 2 every time show prompt
ParticleNetwork.setSecurityAccountConfig(
SecurityAccountConfig(
promptSettingWhenSign = 1,
promptMasterPasswordSettingWhenLogin = 2
)
)
//this is the default setting
ParticleNetwork.setAppearence(ThemeEnum.AUTO)
//dark
ParticleNetwork.setAppearence(ThemeEnum.DARK)
//light
ParticleNetwork.setAppearence(ThemeEnum.LIGHT)
//Set the language of the SDK
//support LanguageEnum.EN、LanguageEnum.JA、LanguageEnum.KO、LanguageEnum.ZH_CN、LanguageEnum.ZH_TW
ParticleNetwork.setLanguage(LanguageEnum.EN)
//Get Applied Language
val languageEnum = ParticleNetwork.getLanguage()
This switch will work if the following conditions are met:
- your account is connected with JWT
- your account does not set payment password
- SecurityAccountConfig.promptSettingWhenSign is 0, you can call ParticleNetwork.setSecurityAccountConfig to update its value.
// set blind sign enable
AuthCore.setBlindEnable(true)
// get current blind sign enable state
val result = AuthCore.getBlindEnable()
ErrorInfo
contains error details. You can check the information by printing the message
attribute.