Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Identity Agent Guide #1149

Merged
merged 36 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b3d4281
initial guide; code snippets and tests need to be added
blackgirlbytes Jan 12, 2024
c912494
update wording
blackgirlbytes Jan 12, 2024
b6dd161
move to dwn
blackgirlbytes Jan 12, 2024
8cb8ad8
put apps back to 4th position
blackgirlbytes Jan 12, 2024
b1950d2
typo
blackgirlbytes Jan 12, 2024
e71aa21
updating based on review
blackgirlbytes Jan 12, 2024
fdc1e1b
linking agents guide
blackgirlbytes Jan 12, 2024
f2b04f5
Update site/docs/web5/build/decentralized-web-nodes/using-identity-ag…
blackgirlbytes Jan 12, 2024
12db33c
passphrase update; users can use whatever they want
blackgirlbytes Jan 12, 2024
9f158b1
Update site/docs/web5/build/decentralized-web-nodes/using-identity-ag…
blackgirlbytes Jan 12, 2024
2da72ce
using identity agent wrapper instead
blackgirlbytes Jan 13, 2024
d5dc8b6
Merge branch 'main' into create-idenity-agent-guide
blackgirlbytes Jan 13, 2024
cc84425
update test descriptions
blackgirlbytes Jan 13, 2024
d0754df
more details in guide
blackgirlbytes Jan 16, 2024
496187d
adding for more clarity
blackgirlbytes Jan 16, 2024
bc7bd9c
Merge branch 'main' into create-idenity-agent-guide
blackgirlbytes Jan 16, 2024
a290b2d
capitalization
blackgirlbytes Jan 16, 2024
8353376
fix typo
blackgirlbytes Jan 16, 2024
9b2ebb4
remove unnecessary wording
blackgirlbytes Jan 16, 2024
cb8c650
combine create identities code snippet
blackgirlbytes Jan 16, 2024
f4581ec
agent tests
blackgirlbytes Jan 16, 2024
dcb4abb
Merge branch 'main' into create-idenity-agent-guide
blackgirlbytes Jan 16, 2024
cd95000
Merge branch 'main' into create-idenity-agent-guide
angiejones Jan 18, 2024
ad40860
how the agent connects to web5
blackgirlbytes Jan 19, 2024
633ca54
pinning version
blackgirlbytes Jan 19, 2024
ffce08f
Merge branch 'main' into create-idenity-agent-guide
blackgirlbytes Jan 19, 2024
8b9a556
updating lock file to match packagejson
blackgirlbytes Jan 19, 2024
6025097
Update site/code-snippets/web5/build/decentralized-web-nodes/use-iden…
blackgirlbytes Jan 19, 2024
c2996a6
Update site/docs/web5/build/decentralized-web-nodes/using-identity-ag…
blackgirlbytes Jan 19, 2024
cbefcfb
separate apps
blackgirlbytes Jan 19, 2024
91d06ba
Update site/docs/web5/build/decentralized-web-nodes/using-identity-ag…
blackgirlbytes Jan 19, 2024
348dbab
bolding the word separate to emphasize separate apps
blackgirlbytes Jan 19, 2024
c1c6a34
italic to bold
blackgirlbytes Jan 19, 2024
5165a7f
Update site/docs/web5/build/decentralized-web-nodes/using-identity-ag…
blackgirlbytes Jan 19, 2024
7e8b890
Update site/docs/web5/build/decentralized-web-nodes/using-identity-ag…
blackgirlbytes Jan 19, 2024
c1af9dd
connectToWeb5 snippet
blackgirlbytes Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions site/docs/web5/build/Agent/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Agents",
"position": 4
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
}
104 changes: 104 additions & 0 deletions site/docs/web5/build/Agent/how-to-create-identity-agent.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
sidebar_position: 1
---
# Create an identity agent
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved

Identity agents manage [Decentralized Identifiers (DIDs)](https://developer.tbd.website/docs/web5/learn/decentralized-identifiers), data, and communication between [Decentralized Web Nodes (DWNs)](https://developer.tbd.website/docs/web5/learn/decentralized-web-nodes). For developers' convenience, the `Web5.connect()` function uses default settings to connect to an identity agent. However, there can be scenarios where setting up a custom agent is necessary. This guide provides a step-by-step demonstration of how to create an identity agent equipped with a [portable DID](https://developer.tbd.website/docs/web5/build/decentralized-identifiers/how-to-create-did#portable-did).
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved

<details>
<summary>Prerequisites</summary>

**Install the following packages**

```bash
npm i @web5/dids @web5/user-agent @web5/api
```

**Import the following modules**
```js
import { DidIonMethod, DidKeyMethod } from '@web5/dids';
import { Web5UserAgent } from '@web5/user-agent';
import { Web5, getTechPreviewDwnEndpoints } from '@web5/api';
```
This guide focuses on utilizing `DidIonMethod` and `DidKeyMethod` for setting up an identity agent. Currently, DID methods like the `DidDhtMethod` are not supported in this context.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
</details>

## Initialize the Agent
Create an instance of the Web5 User Agent to begin your identity agent setup.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
```javascript
const agent = await Web5UserAgent.create();
```

## Authenticate with a passphrase
For security purposes, the identity agent prompts the end user to enter a secure passphrase when it initially launches. In this example, `insecure-static-phrase` is used as a placeholder.
```javascript
await agent.start({ passphrase: 'insecure-static-phrase' });
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
```

## Generate a portable DID
Generating a portable DID document requires the following steps
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
- **getTechPreviewDwnEndpoints()** - selects up to 2 DWN endpoints that are provided by default during the Tech Preview period.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
* **DidIonMethod.generateDwnOptions({ serviceEndpointNodes })** - generates two key pairs used for authorization and encryption purposes when interfacing with DWNs. The IDs of these keys are referenced in the service object that includes the dwnUrls provided.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
* **DidIonMethod.create(didOptions)** - creates the DID document with the given options
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
```javascript
const serviceEndpointNodes = await getTechPreviewDwnEndpoints();
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
const didOptions = await DidIonMethod.generateDwnOptions({ serviceEndpointNodes });
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
const portableDid = await DidIonMethod.create(didOptions);
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
```
<details>
<summary>The above code snippet is the equivalent of:</summary>

```javascript
await DidIonMethod.create({
services: [{
type: 'DecentralizedWebNode',
id: '#dwn',
serviceEndpoint: {
"encryptionKeys": [
"#dwn-enc"
],
"nodes": [
"https://dwn.tbddev.org/dwn0",
"https://dwn.tbddev.org/dwn2"
],
"signingKeys": [
"#dwn-sig"
]
}
}]
})
```
</details>

## Import your portable DID
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
Importing your portable DID, gives the identity agent permission to manage data on your behalf. This step links your agent you your unique decentralized identifier (DID).
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved

```js
await agent.didManager.import({
did: portableDid,
kms: "local"
});
```

:::note
The KMS field stands for Key Management Store. It acts as a password manager for cryptographic keys. If you don't specify a particular key management service, such as AWS Key Management Service or Google Cloud Key Management, it will default to Web5's default implementation
angiejones marked this conversation as resolved.
Show resolved Hide resolved
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
:::

## Connect to Web5
Now, you can take portable DID and your identity agent to connect to Web5 and return an instance of Web5.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
```javascript
const { web5, did } = await Web5.connect({
connectedDid: portableDid.did,
agent,
});
```

## Interact with the Web5 API
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
You can now use the web5 instance to interact with DWNs and store Verifiable Credentials. The example below demonstrates how to create a record with a simple "Hello World!" message:
```javascript
const { record } = await web5.dwn.records.create({
data: "Hello World!",
message: { dataFormat: "text/plain" },
});

```
2 changes: 1 addition & 1 deletion site/docs/web5/build/apps/_category_.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"label": "Apps",
"position": 4
"position": 5
}
Loading