Skip to content

Commit

Permalink
added info on authentication and updated info on creating DIDs (#11)
Browse files Browse the repository at this point in the history
* added info on authentication and updated info on creating DIDs

* shortened subject
  • Loading branch information
angiejones authored Aug 9, 2023
1 parent 39af661 commit 010432c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
25 changes: 25 additions & 0 deletions content/authentication.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Explains how to authenticate a user with Web5 using DIDs

-----

Web5 revolutionizes digital identity through Decentralized Identifiers (DIDs), enabling individuals to control their data while navigating online platforms autonomously.

Decentralized Identifiers, or DIDs, lie at the heart of Web5's identity management. DIDs provide individuals with unique and globally resolvable identifiers that are persistent and always under their control. By using a DID, users establish their online presence, similar to a username. This paradigm shift empowers individuals to manage and control their personal information, granting them the freedom to partake in various online platforms all while owning the content and data they share.

Web5 applications eliminate the need for centralized authorities to authenticate us through methods such as two-factor authentication or username/password combinations. Instead, DIDs, alongside data associated with DIDs like Verifiable Credentials, become the foundation of trust. When users interact with Web5 applications, they present claims associated with their DIDs as proof of identity. These applications can verify the authenticity of the user's attestations without the need for traditional username/password authentication.

How It Works
When you acquire a DID, it comes with a public-private key pair. Your DID can be resolved by anyone into a DID document, containing your public key, similar to a username that can be copied and pasted into a login screen.

However, to prove that you are the rightful owner of the DID and it is indeed you logging in, your private key becomes crucial. Your private key should never be shared, and it allows you to generate a digital signature. Whenever you author a message, it automatically carries a digital signature. To verify the same message, it requires the public key. For example, when logging into example.com, sending a message and successfully authenticating it, the online platform will utilize your public key for verification. If the verification process is successful, they can confirm that you are the rightful owner of the given DID, without ever needing your private key.

With Web5 authentication, you can effortlessly create an account, free from the hassle of coming up with a new handle or hoping your existing usernames are available. Instead, you can embrace the simplicity of using your DID. Your DID becomes a personalized "username" that you can use to log into any supporting app's login screen.

Your DID serves as a URI (Unique Resource Identifier) that leads to your DID document, acting as a special hub providing a glimpse into your digital identity. Within your DID document, the application utilizes the URIs as guideposts, leading them to your DWNs (Decentralized Web Nodes) which store your content and data.

This user-friendly approach relieves you from the burdens of creating new content or manually downloading from one platform to upload on another. All the content to which you have granted the application access to will be readily available for the application to read/write to, simply by logging in with your DID.

Benefits of Authentication with Web5
One of the biggest benefits of this is the shift in content ownership. In traditional web applications, content is often stored on centralized servers, placing it under the control of the service provider you've created an account with or you're logged into. However, in Web5, individuals maintain ownership and control over their content. When users create and publish content within a Web5 application, their DIDs are linked to that content, establishing a clear link between the creator and their work. The user's content is stored in their own datastore, a DWN, as opposed to stored on the platform they’ve logged into. This ownership grants users greater autonomy and enables them to decide how their content is shared, used, and monetized.

Another benefit is the enhanced security this type of content ownership and authentication provides. With traditional web applications, data breaches and unauthorized access are a common problem that pose a significant risk to the user and the company that holds this data. In Web5, the distributed nature of the infrastructure gives the users full ownership over their data/content that is stored and protected in their DWN. By reducing the reliance on centralized servers, where multiple people have access to a user’s data the impact of potential security breaches is lower. Empowering users to have more confidence in their online interactions.
30 changes: 20 additions & 10 deletions content/did.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
Create a Decentralized Identifier (DID). This one creates one of the ION did method type.

How to create a DID
-----

const did = await web5.did.create('ion');
In Web5, there are two ways to create a Decentralized Identifier (DID):

// note that when you use web5.connect() method, a did will be created for you if one isn't already available:
1. Create a DID automatically
The Web5.connect() function creates a decentralized identifier (DID) or obtains connection to an existing one either by direct creation or connection to an identity agent app. This function also creates an instance of Web5.

const { web5, did: myDid } = await Web5.connect();

// myDid is the did supplied by the agent for this application. It is a bit like a publicly shareable public key or URL.
By default, the Web5.connect() function creates the DID using the ION DID method.

Here’s an example of what the myDid object will look like:

did:ion:EiD3a17O2DCebpcZli-1BHRtMQ0LtTfrU85hHnAux6LrRQ:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24iLCJwdWJsaWNLZXlKd2siOnsiY3J2Ijoic2VjcDI1NmsxIiwia3R5IjoiRUMiLCJ4IjoiR1hoNkpFeHlqaWk0UHNiQ2NQdG5OWmlCT0MxZGVaSDdiYS1oVERXajlFZyIsInkiOiJ4SFF6VjhXR0VGdVZyelFIN0tFN1lQTDBEdWtkbUhwY0lOM1doQmlYSEhrIn0sInB1cnBvc2VzIjpbImF1dGhlbnRpY2F0aW9uIl0sInR5cGUiOiJKc29uV2ViS2V5MjAyMCJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQ3Z4bHlrZ0ZpeVZfLThxdUdVMjlkN0JTX1hMV0REVnFjUGxVVnBVNGFXU3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUQwT3didlJxQngwc1Atai16YjlXbzRZekp4Q1N3QU1oeUw2NnlySEVmSXR3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEbk1JcVFLRTdPbWQwcFd0UHM0RmVKSFkxY1RCTllzMHdhX0stRWdnVEJFQSJ9fQ

2. Create a DID manually
The Web5.connect() function is the preferred way to create a DID, but there may be a case where you need to create another DID in real time. You can do so by calling did.create().

When calling create(), be sure to pass in a Web5-supported DID method.

const myDid = await Web5.did.create('ion');

Here’s an example of what the myDid object will look like:

{
id: 'did:ion:EiA2ZoP6qQm6rmuibI2LCysFfFpG9_j1fI7GxWmI_vLbFA:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24iLCJwdWJsaWNLZXlKd2siOnsiY3J2Ijoic2VjcDI1NmsxIiwia3R5IjoiRUMiLCJ4IjoiWXFlX1JrWW1rd2lsZFJvelF4Yk05bGc1cVpnc2VpdjFBUzdacXl6QUJQayIsInkiOiJsYVlGTDBlbWVfTWU0c3JfYVNETU9QMWdCTnQ1aXRVUkhlMTd0MmpiYm1zIn0sInB1cnBvc2VzIjpbImF1dGhlbnRpY2F0aW9uIl0sInR5cGUiOiJKc29uV2ViS2V5Mj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4IjoiOEpVUE5kSmxhQW50d2RyeUlDZEJUdEljeGdYRHJiXzRmYjJ5bFd3UlZrcyIsInkiOiJRR3o2QjhGTVRuaUhlMFhxY19SdmduTnQ4djJ0NFFJMW5mRVRiOXpsYldZIn0sInB1cnBvc2VzIjpbImF1dGhlbnRpY2F0aW9uIl0sInR5cGUiOiJKc29uV2ViS2V5MjAyMCJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQkFtTE5RaDdkX1NBcDRDOUV6SmV0M240ajJWNmJ6VVJGSUk4NE9mOS1KbUEifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUR3U05saVE3RjBXLU9zX2hRUkp1WnlPbzBTUTUzMjBCR3pBRG5Od053ZmJ3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlCUmYxY05pbUJFRXJZU1gtelJNNHdFSGRJZXdzUGZYNGRBVklYd0xKaFg0USJ9fQ',
verificationMethod: [ [Object] ],
authentication: [ '#dwn' ]
},
Expand All @@ -32,9 +42,9 @@ Here’s an example of what the myDid object will look like:
],
keys: [
{
id: 'did:ion:EiA2ZoP6qQm6rmuibI2LCysFfFpG9_j1fI7GxWmI_vLbFA:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24iLCJwdWJsaWNLZXlKd2siOnsiY3J2Ijoic2VjcDI1NmsxIiwia3R5IjoiRUMiLCJ4IjoiWXFlX1JrWW1rd2lsZFJvelF4Yk05bGc1cVpnc2VpdjFBUzdacXl6QUJQayIsInkiOiJsYVlGTDBlbWVfTWU0c3JfYVNETU9QMWdCTnQ1aXRVUkhlMTd0MmpiYm1zIn0sInB1cnBvc2VzIjpbImF1dGhlbnRpY2F0aW9uIl0sInR5cGUiOiJKc29uV2ViS2V5MjAyMCJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQ3YwVWFsTkRpTEty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c29uV2ViS2V5MjAyMCJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQkFtTE5RaDdkX1NBcDRDOUV6SmV0M240ajJWNmJ6VVJGSUk4NE9mOS1KbUEifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUR3U05saVE3RjBXLU9zX2hRUkp1WnlPbzBTUTUzMjBCR3pBRG5Od053ZmJ3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlCUmYxY05pbUJFRXJZU1gtelJNNHdFSGRJZXdzUGZYNGRBVklYd0xKaFg0USJ9fQ',
publicKeyJwk: [Object],
privateKeyJwk: [Object]
}
Expand Down
7 changes: 3 additions & 4 deletions content/dwn_write.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Show how to write to Decentralized Web Nodes.
Show how to write to Decentralized Web Nodes (DWN).

-----


// The following snippet allows you to create a record in your Web5 instance’s DWN using a DID object called myDid:

// Create a plain text record in the in-memory DWN

const { record } = await web5.dwn.records.create({
data: "Hello Web5",
message: {
Expand All @@ -16,5 +15,5 @@ const { record } = await web5.dwn.records.create({

The create request must contain the following:

message - object: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message. schema, is an optional parameter, and if used it does not need to be a resolvable url. dataFormat should conform to one of the IANA media types.
data - blob | stream | file: The data object of the bytes to be sent.
message - object: The properties of the DWN Message Descriptor that will be used to construct a valid DWN message. schema, is an optional parameter, and if used it does not need to be a resolvable url. dataFormat should conform to one of the IANA media types.
data - string | json | blob | stream | file: The data object of the bytes to be sent.
7 changes: 4 additions & 3 deletions content/query.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Method for querying the DWeb Node of a provided target DID.
Method for querying the DWN for records of a provided target DID.
-----

// The query request can contain the following:
// from - string: The DID of the DWN the query will fetch results from.
// message - object: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message.
// message - object: The properties of the DWN Message Descriptor that will be used to construct a valid DWeb Node message.


const response = await web5.dwn.records.query({
Expand All @@ -16,4 +16,5 @@ const response = await web5.dwn.records.query({
}
});

console.log(response.entries) // logs array of Record class instances
// logs array of Record class instances
console.log(response.entries)
2 changes: 1 addition & 1 deletion content/query_full.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Query from your DWN or remote DWeb nodes. Uses protocol as filter criteria but can also use a 'schema' field instead of protocol (which is a jsonschema)
Query protocols from your DWN or remote DWeb nodes. Uses protocol as filter criteria but can also use a 'schema' field instead of protocol (which is a jsonschema)

-----

Expand Down
2 changes: 1 addition & 1 deletion content/sync.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Explains how sync works with DWeb Nodes (DWNs) and web5
Explains how to sync data across multiple DWeb Nodes (DWNs) in Web5

-----

Expand Down
2 changes: 1 addition & 1 deletion content/write_send.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Create a record in Alice's DWN, and send it directly to Bobs DWeb Nodes.
Create a record in one DWN, and send it directly to another user's DWeb Nodes.

-----

Expand Down

0 comments on commit 010432c

Please sign in to comment.