Identity management

Introduction

Let's review some code examples on how to manage Identities:

Tip: using a RemoteIdentity allows the JavaScript application to use a user's existing private key in their Desktop Wallet application, without the user exposing their private key to your app.

Creating a simple identity

Note: a SimpleIdentity keeps both public and private keys in memory.

In the following code example, we create a new simple identity using the RadixIdentityManager's generateSimpleIdentity() method:

const identityManager = new RadixIdentityManager()
const myIdentity = identityManager.generateSimpleIdentity()

With it, we can easily access our own Account using the account reference:

const myAccount = myIdentity.account
console.log('My account address: ', myAccount.getAddress())

Creating a remote identity

Note: a RemoteIdentity only holds the public key in memory, while a Wallet keeps the private key. The user must accept a request from the JavaScript application to allow the Wallet to sign atoms on its behalf.

In the following code snippet, we try to create a new remote Identity and catch any errors in the console log:

RadixRemoteIdentity.createNew('my dApp', 'my dApp description').then(identity => {
//Do stuff with identity here
}).catch(error => {
console.log(error)
})

We can also specify a remote host and port for the remote identity:

RadixRemoteIdentity.createNew('my dApp', 'my dApp description', '192.168.0.123', '53433').then(identity => {
//Do stuff with identity here
}).catch(error => {
console.log(error)
})

In case we want to validate if the remote wallet is up and running:

RadixRemoteIdentity.isServerUp().then(isServerUp => {
if (isServerUp) {
// Do something
}
})

As an alternative, we can also generate a RemoteIdentity using RadixIdentityManager:

const identityManager = new RadixIdentityManager()
identityManager.generateRemoteIdentity('my dApp', 'my dApp description').then(identity => {
//Do stuff with identity here
}).catch(error => {
console.log(error)
})