iOS (Swift/Obj-C) - Auth
Interacting with Particle Auth on iOS using Swift or Objective-C.
Particle Auth for iOS
The Particle Auth iOS SDK is the primary means of integrating Particle’s Wallet-as-a-Service within applications on iOS. From initialization and configuration to onboarding and account utilization, this SDK acts as the master library for interacting with Particle on iOS.
The Particle Auth iOS SDK follows configuration and implementation mechanisms similar to the Particle Auth Android SDK. The specifics of integration, along with several examples, will be covered below.
Getting Started
Implementation of the Particle Auth iOS SDK only takes a few lines of code, although before getting to that point, you’ll need to meet a few key prerequisites in mind to ensure compatibility.
Prerequisites
- Xcode 15.0 or later.
- CocoaPods 1.14.3 or higher.
- Your project must target these platform versions or later:
- iOS 14.
Configuration
To begin the initialization process, you must head over to the Particle dashboard and create a project alongside a corresponding application.
These will control specific customizations, statistics, and more for your instance of Particle’s Wallet-as-a-Service. After creating an application, you’ll need to retrieve three key values: projectId
, clientKey
, and appId
. We’ll be using these down the road.
Follow the quickstart tutorial to set up a project and find the required keys: Create a new project.
Installation
Now that you’ve created a project and an application within the Particle dashboard, you’ll need to go ahead and install the Particle Auth SDK using CocoaPads (assuming you meet the previously mentioned minimum version requirements).
-
If you don’t already have a Podfile, create one from the root of your project directory with:
Terminal -
Within the newly created Podfile, add the
ParticleAuthCore
,ParticleMPCCore
, andThresh
pod.Podfile -
Install the pods, then open your .xcworkspace file to see the project in Xcode.
Terminal
For release updates, subscribe to the GitHub repository.
Podfile Configuration
Additionally, you’ll need to ensure that your resulting Podfile is properly configured and contains a snippet similar to the example below.
Initialization
Now that you’ve configured your Particle dashboard, installed the SDK, and configured a Podfile, it’s time to initialize the SDK with the aforementioned projectId
, clientKey
, and appId
retrieved from the Particle dashboard.
-
Create a
ParticleNetwork-Info.plist
file from the root of your corresponding Xcode project. -
Paste the following text into this file:
ParticleNetwork-Info.plist -
Replace the placeholders with the values retrieved from your project and application within the Particle dashboard.
-
Import the
ParticleNetworkBase
module in yourAppDelegate.swift
file.AppDelegate.swift -
Initialize the ParticleNetwork service, which is typically located within your app’s
application:didFinishLaunchingWithOptions
method:AppDelegate.swift -
Add Privacy - Face ID Usage Description to your info.plist file, head over to your
Info.plist
file and include the following snippet:Info.plist
Switch Chain
To switch the used chain after initial configuration, auth.switchChain
is used. This enables asynchronous switching. Similar to the initial configuration, chain information derived from ParticleNetwork.ChainInfo
can be passed as the primary parameter, determining the destination chain.
Field | Type | Description |
---|---|---|
chainInfo | ChainInfo | A chainInfo object, can be derived from ParticleNetwork.ChainInfo . |
Examples of utilization
Connect
auth.connect
is the main mechanism for facilitating login (account creation or sign in) with Particle’s Wallet-as-a-Service. Specifically, five key parameters are available within auth.connect
:
Field | Type | Description |
---|---|---|
type | LoginType | The specific social login to be used. This can be either .email , .phone , .google , .apple , .jwt , .facebook , .twitter , .discord , .github , .twitch , .microsoft or linkedin . |
account | String? | (Optional) When type is set to either .email , .phone , or .jwt , you can use the account parameter to pass in an expected email, phone number, or JWT. This is optional for the former two, but required for .jwt . When passing a phone number, it must be in E.164 format. |
code | String? | (Optional) When type is set to either .email pr .phone , you can use the code parameter to pass the verification code. |
socialLoginPrompt | SocialLoginPrompt? | (Optional) Changes what the OAuth provider prompts a user to do; either .none , .consent , or .select_account . Only Google, Discord and Microsoft support it. |
auth.presentLoginPage
is another mechanism for facilitating login (account creation or sign in) with Particle’s Wallet-as-a-Service. Upon calling this method, an authentication UI will be thrown, and the user will be asked to sign in with a specified login method. Specifically, five key parameters are available within auth.presentLoginPage
:
Field | Type | Description |
---|---|---|
type | LoginType | The specific social login to be used. This can be either .email , .phone , .google , .apple , .jwt , .facebook , .twitter , .discord , .github , .twitch , .microsoft or linkedin . |
account | String? | (Optional) When type is set to either .email , .phone , or .jwt , you can use the account parameter to pass in an expected email, phone number, or JWT. This is optional for the former two, but required for .jwt . When passing a phone number, it must be in E.164 format. |
supportAuthTypeode | [SupportAuthType] | The methods of authentication visible on the authentication popup UI. By default, this will be exclusive to the chosen social login method, although by passing in additional types, you can expand the UI to include the ability to login with those as an alternative to type. |
socialLoginPrompt | SocialLoginPrompt? | (Optional) Changes what the OAuth provider prompts a user to do; either .none , .consent , or .select_account . Only Google, Discord and Microsoft support it. |
config | LoginPageConfig? | (Optional) To customize the UI page, contains project name, icon and description. |
After connect is successful, detailed user information can be retrieved by calling auth.getUserInfo
.
Is Connected
To check the user’s login status, auth.getUserInfo() != nil
returns a Boolean based upon the current state of a session (whether or not a user is currently logged into an account). Additionally, an asynchronous method, auth.isConnected
can be called and subscribed to, returning userInfo
upon a status of true
.
Disconnect
auth.disconnect
will simply log a user out of their existing session, assuming they’re logged in.
UserInfo and Address Retrieval (post-login)
Once a user has logged in, you’ll have access to various methods such as auth.getUserInfo
and auth.evm.getAddress
to retrieve specific user details. The getUserInfo
response will, by default, include both an associated EVM and Solana address, while auth.evm.getAddress
will return an EVM address, auth.solana.getAddress
will return a Solana address.
Signatures
Once ParticleNetwork
has been initialized and a user has successfully logged in, signatures can be proposed for confirmation through a popup
EVM
Sign Message (EIP191)
To request an EIP191 signature from a user’s embedded wallet, you can use either the auth.evm.personalSign
or auth.evm.personalSignUnique
method. If you need the same message to return a unique signature each time, use the auth.evm.personalSignUnique
method. Otherwise, the auth.evm.personalSign
method is generally recommended.
Field | Type | Description |
---|---|---|
message | String | Either a hexadecimal string starting with ‘0x’ or a human-readable string is required. |
chainInfo | ChainInfo? | (Optional) Default is current chainInfo, the specific chain selected |
Sign Typed Data V4 (EIP712)
To request an EIP712 signature from a user’s embedded wallet, you can use either the auth.evm.signTypedData
or auth.evm.signTypedDataUnique
method. If you need the same message to return a unique signature each time, use the auth.evm.signTypedDataUnique
method. Otherwise, the auth.evm.signTypedData
method is generally recommended.
Field | Type | Description |
---|---|---|
message | String | Either a hexadecimal string starting with “0x” or a JSON string is required. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo, the specific use which chain to sign |
Transaction
To send a transaction from a user’s embedded wallet, you can use auth.evm.sendTransaction
.
Field | Type | Description |
---|---|---|
transaction | String | A hexadecimal string starting with “0x” is required. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo, the specific use which chain to sign and send |
Solana
Signing Messages
To request a signature from a user’s embedded wallet, you can use auth.solana.signMessage
.
Field | Type | Description |
---|---|---|
message | String | A base58 formatted string is required. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo, the specific use which chain to sign |
Transaction
To send a transaction from a user’s embedded wallet, you can use auth.solana.signAndSendTransaction
.
Field | Type | Description |
---|---|---|
transaction | String | A base58 formatted string is required. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo, the specific use which chain to sign and send |
To sign a transaction from a user’s embedded wallet, you can use auth.solana.signTransaction
.
Field | Type | Description |
---|---|---|
transaction | String | A base58 formatted string is required. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo, the specific use which chain to sign |
To sign multi transactions from a user’s embedded wallet, you can use auth.solana.signAllTransactions
.
Field | Type | Description |
---|---|---|
transactions | String | Base58 formatted strings are required. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo, the specific use which chain to sign |
You can create en EVM transaction with class TxData
or FeeMarketEIP1559TxData
, also you can use another SDK ParticleWalletAPI
to create transaction, you can reference the examples from Wallet SDK reference, all the rpc methods are defined in ParticleWalletAPI
.
Open Account and Security
If you’d like to force the “Account and Security” options to be opened on-screen (from which you can control payment passwords, additional accounts, and so on), then you can call auth.openAccountAndSecurity
. Upon calling this method, a popup allowing the user to control security settings will appear.
Set Security Account Config
Within the security settings, specific popups can be set to display upon confirmation or wallet UI entrance. These popups include promptSettingWhenSign
, which refers to payment (signature) passwords, and promptMasterPasswordSettingWhenLogin
, which refers to a login-based master password.
By default, promptSettingWhenSign
is set to 1, which will show the prompt upon the first signature a given account conducts. If it’s set to 0, it will never be shown; if it’s set to 2, it will be shown upon every signature confirmation, if it’s set to 3, it will be forced to set payment password.
This same logic applies to promptMasterPasswordSettingWhenLogin
, which by default is set to 0.
Master Password and Payment Password
User can set master password and payment password to protect assets, call auth.changeMasterPassword
to set or change master password, call auth.openAccountAndSecurity()
to set or change payment password.
Set Appearance
You can forcibly set a specific appearance to be used within the UI using ParticleNetwork.setAppearance
. By default, it will follow current system setting.
Field | Type | Description |
---|---|---|
appearance | UIUserInterfaceStyle | The specific appearance to be used. This can be either .unspefified , .dark , .light . |
Set and Get Language
You can forcibly set a specific language to be used within the UI using ParticleNetwork.setLanguage
, with retrieval of the current active language facilitated by ParticleNetwork.getLanguage
. By default, this is set to English.
Field | Type | Description |
---|---|---|
language | Language | The specific language to be used. This can be either .en , .ja , .zh_hans , .zh_hant , .ko . |
Set Custom UI JSON string
Set FiatCoin
You can set a specific fiat currency to be used within the UI using ParticleNetwork.setFiatCoin
, with retrieval of the current active language facilitated by ParticleNetwork.getFiatCoin
. By default, this is set to USD.
Field | Type | Description |
---|---|---|
fiatCoin | FiatCoin | The specific fiat currency in which value is denominated. This can be either .usd , .cny , .jpy , .hkd , .inr , .krw . |
Enable Blind Signing
Silently sign messages/transactions, this switch will work if the following conditions are met:
- Your account is connected with JWT
- Your account hasn’t set a payment password
- SecurityAccountConfig.promptSettingWhenSign is 0, you can call
ParticleNetwork.setSecurityAccountConfig
to update its value.
Was this page helpful?