Skip to main content

Create a Decentralized Identifier

Before creating your DID, be sure to check out the Quickstart guide to ensure you’ve properly imported the Web5 SDK. We also have guides to learn more about DIDs.

Create a DID

import {Web5} from '@tbd54566975/web5'
const web5 = new Web5();
const myDid = await web5.did.create('ion');

When calling create, be sure to pass in a Web5-supported DID method(). create returns a JSON representing your newly created DID, which we’ve stored in myDid. Here’s an example of what the myDid object will look like:

{
"id":"did:ion:EiD5iTx5H9P_LKxfKkAx4...",
"internalId":"did:ion:EiD5iTx5H9P_LKxfKkAx4J5oRIAsko9RSsbOoL2sURMsSg",
...
"keys":[
{
"id":"key-1",
"type":"JsonWebKey2020",
"keypair":{
"publicJwk":{
"kty":"EC",
"crv":"secp256k1",
"x":"_fhttpkgTd-icwBqoHoWrzIsULDLoM02Mv2ewFEl9_k",
"y":"wFNaCJ27Yu7Yh4yCgYxWHI2tcWsSZ7ugnc0UYeKn2uM"
},
"privateJwk":{
"kty":"EC",
"crv":"secp256k1",
"x":"_fhttpkgTd-icwBqoHoWrzIsULDLoM02Mv2ewFEl9_k",
"y":"wFNaCJ27Yu7Yh4yCgYxWHI2tcWsSZ7ugnc0UYeKn2uM",
"d":"dhQUKGtPgiVs0WOgY0frP8_5WR-tTgNbB1UI93h2iTw"
}
},
"purposes":[
"authentication"
]
}
],
...
}

Store DID Keys in Decentralized Web Node

When you instantiate Web5, the SDK internally creates a Decentralized Web Node (DWN) to act as a personal data store to store your DID keys. In order to store your DID, save and encrypt your keys with the Web5 SDK.

web5.did.manager.set(myDid.id, {
connected: true,
endpoint: 'app://dwn',
keys: ["#dwn"]: { keyPair: myDid.keys[0].keypair }
});