Authentication
Last updated
Was this helpful?
Last updated
Was this helpful?
There are multiple ways to connect a user’s account to the Verida protocol with different packages provided for different use cases.
Your application must install the appropriate account package and connect it to your client instance. The account package handles:
Signing consent messages to unlock application contexts
Creating a new decentralized identity if required
Publishing endpoints to the account’s DID document for all the account’s application contexts
There are two ways to authenticate a user to your application:
Designed for secure web applications
Your web application integrates the which displays a QR code to a user. A user scans the QR code and is walked through an onboarding process of installing the Verida Wallet, creating a blockchain account and then authenticating with your application.
See the for more details.
Designed for NodeJs and Mobile Apps
An existing Verida account private key is used to authenticate a user to your application.
This approach is ideal for integrating the Verida protocol into a server side NodeJs application or embedding Verida into an existing mobile application using the
Note: Change Network.BANKSIA
to Network.MYRTLE
to use a mainnet network.
DID_CLIENT_CONFIG.web3Config
supports additional options used when communicating with the blockchain. Here's the default configuration when using Verida Myrtle network (mainnet on the Polygon PoS blockchain):
Note: Only privateKey
is required, the other values (rpcUrl
, eip1559xxx
will be populated with defaults in the protocol based on the Verida network selected)
Verida accounts use the same standard the same as Ethereum accounts, so Ethers.js can be used to generate a new seed phrase or private key.
The above examples initialize a connection to the Verida network and a single context. Sometimes it’s useful to connect to the network and then connect to multiple application contexts for the connected user. The code sample below generates a re-usable client instance, then uses that to open a specific application context.
In your application, include the dependency and create a new client network instance:
The first parameter for AutoAccount()
is an interface that meets the AccountNodeConfig
definition:
privateKey
- Verida network private key for the account
network
- Verida network (Network.BANKSIA
or Network.MYRTLE
)
didClientConfig
- Instance of AccountNodeDIDClientConfig
countryCode
- (optional) Country to use for selecting storage and DID nodes on the network. If not specified, will choose random global nodes. If specified, will use nodes in that country. If not enough nodes are available in that country, it will fallback to selecting nodes in the same region as that country, then fallback to global nodes.
See the for more details.