Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 2.38 KB

File metadata and controls

70 lines (51 loc) · 2.38 KB

DID Account Basics

this example, assumes you have already gone through the first example of creating a manager instance and further expands on that.

DID Account, Referred to as IdentityAccount, is a utility class which contains all the functions a did might ever need to use

Creating a new DID

to create a new DID, we can use the existing manager instance and invoke the createDid method

// import the `getIdentityManager` and `constructFileStore` functions here

async function createDid() {
  const manager = await getIdentityManager();

  // this storage is used to store credentials for a particular DID
  const identityStore = constructFileStore({
    path: path.resolve(__dirname, "./mydid-store"),
    password: "foopass",
  });

  const myDid = await manager.createDid({
    // alias is a human readable nickname you can give to this id, in a regular
    // usecase this can be used to tie a DID to a username or a userId
    alias: "myDid",
    // method specifies which method you want to create the identity with, it
    // takes the method name as specified in DIDs for example for did:key it's key
    // and for did:web -> web etc
    method: "web",
    store: identityStore,
  });
}

Getting an existing DID

if you want to retrieve an already existing DID, then you can do so using the getDid method the getDid method can take either alias or the did, where the did is the did identifier such as (did:method:<foo-bar>).

The method loads an existing DID stored on the disk in the store provided previously to identity manager

async function getDid({ alias, did }: { alias?: string; did?: string }) {
  const manager = await getIdentityManager();

  // this storage is used to store credentials for a particular DID
  const identityStore = constructFileStore({
    path: path.resolve(__dirname, "./mydid-store"),
    password: "foopass",
  });

  const myDid = await manager.getDid({
    // ONLY ONE out of did and alias needs to be passed here
    alias,
    did,
    store: identityStore,
  });
}

DID Operations

On the created DID Account now you can do various operations, such as getting the document, getting the DID tag, or creating a presentation.

myDid.getDid() returns the did tag

myDid.getDocument() returns the did document

myDid.createPresentation(credentials) takes a credentials array in form of VC-JWTs and returns a verifiable presentation