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
Changes from 9 commits
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
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
sidebar_position: 9
---
# Using Identity Agents

Identity [agents](http://localhost:3000/docs/web5/learn/agents) manage [DIDs](https://developer.tbd.website/docs/web5/learn/decentralized-identifiers), data, and communication between [DWNs](https://developer.tbd.website/docs/web5/learn/decentralized-web-nodes).
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved

For convenience, the `Web5.connect()` function uses a default identity agent. However, Web5 also provides the ability for users to utilize their own custom agent.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved

This guide provides an overview of how to create an identity agent, import a DID into the agent, and connect the agent to a Web5 app.

<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, `DidDhtMethod` is not supported in this context.
</details>

## Initialize the Agent
Create an instance of `Web5UserAgent` to begin setting up the Identity Agent
```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.
blackgirlbytes marked this conversation as resolved.
Show resolved Hide resolved
```javascript
await agent.start({ passphrase: 'insecure-static-phrase' });
```

## Generate a portable DID
If you'd like to associate DWNs with a DID, you can do so. In the following example, we'll use the TBD-hosted DWN endpoints:

```javascript
// selects DWN endpoints that are provided by default during the Web5 tech preview period
const serviceEndpointNodes = await getTechPreviewDwnEndpoints();
// generates key pairs used for authorization and encryption when interfacing with DWNs
const didOptions = await DidIonMethod.generateDwnOptions({ serviceEndpointNodes });
// creates a new DID and its associated data
const portableDid = await DidIonMethod.create(didOptions);
```
<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 DID
Importing a DID gives the Identity Agent permission to manage data on the DID holder's behalf.

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

:::note
The `kms` field stands for Key Management Service and can securely store and manage the cryptographic keys associated with a DID. If you don't specify a particular key management service, such as AWS Key Management Service or Google Cloud Key Management, Web5 will default to an in-memory key manager.
:::

## Connect to Web5
To use a custom Identity Agent with Web5, pass the DID and the agent into `Web5.connect()`:
```javascript
const { web5, did } = await Web5.connect({
connectedDid: portableDid.did,
agent,
});
```
Loading