Identity Management
Identities represent users via DIDs on the SELF network.
Ensure that Keymaster is installed, initialized, and started as described in the Keymaster installation documentation before creating a schema.
Create a new identity with an initialized keymaster by simply passing in a name. The name is public on the SELF network:
- Node.js
- Java
await Keymaster.createId({ name: "Paul Revere" });
keymaster.createId("Paul Revere");
The identity is stored in the keymaster and is saved via the keymaster wallet config's saveWallet function.
Select an identity
To select an identity, use the selectId function with the DID of the identity you want to select.
- Node.js
- Java
const identityDID =
"did:test:z3v8AuagJiXARFGw3B8Mc6DrLBC2thMzjgeUZWQvHcyPVBxAYZv";
await Keymaster.selectId(identityDID);
// Select using the wallet identity name
String identityName = "Paul Revere";
keymaster.setCurrentId(identityName);
// If you only have a DID, find its wallet name first, then select
String identityDID = "did:test:z3v8AuagJiXARFGw3B8Mc6DrLBC2thMzjgeUZWQvHcyPVBxAYZv";
String matchingName = null;
for (String name : keymaster.listIds()) {
if (identityDID.equals(keymaster.lookupDID(name))) {
matchingName = name;
break;
}
}
if (matchingName == null) {
throw new IllegalArgumentException("Unknown identity DID");
}
keymaster.setCurrentId(matchingName);
The selected identity will be used for all subsequent operations until another identity is selected.
Get a DID Document
To get the DID document of an identity, use the resolveDID function with the DID of the identity you want to resolve.
- Node.js
- Java
const identityDID =
"did:test:z3v8AuagJiXARFGw3B8Mc6DrLBC2thMzjgeUZWQvHcyPVBxAYZv";
const didDocument = await Keymaster.resolveDID(identityDID);
String identityDID =
"did:test:z3v8AuagJiXARFGw3B8Mc6DrLBC2thMzjgeUZWQvHcyPVBxAYZv";
MdipDocument didDocument = keymaster.resolveDID(identityDID);
Delete an Identity
To delete an identity, use the removeId function with the DID of the identity you want to delete.
- Node.js
- Java
const identityDID =
"did:test:z3v8AuagJiXARFGw3B8Mc6DrLBC2thMzjgeUZWQvHcyPVBxAYZv";
await Keymaster.removeId(identityDID);
String identityName = "Paul Revere";
String identityDID =
"did:test:z3v8AuagJiXARFGw3B8Mc6DrLBC2thMzjgeUZWQvHcyPVBxAYZv";
keymaster.revokeDID(identityDID); // deactivates DID on network
keymaster.removeId(identityName); // removes local wallet entry
This will remove the identity from the keymaster and delete the associated DID document from the SELF network.