Gaiahub

Gaiahub

1563
Views

How to configure a Gaiahub on Amazon EC2,step by step tutorial

Othersblockstack app store posted the article • 0 comments • 1563 views • 2019-06-26 22:36 • data from similar tags

 
 
 
This teaches you how to run a Gaia hub on Amazon EC2. Amazon EC2 is an affordable and convenient cloud computing provider. This example uses Amazon EC2 together with an EB3 instance for file storage.
 

Prerequisites you need
Task 1: Launch an EC2 instance
Task 2: Test your Gaia server
Task 3: Configure a domain name
AWS hub tips and tricks

SSH into the Host
Displaying the docker services
Locations of key files
Restart services and reload certificates

 
 
Prerequisites you need
 
This procedure uses Amazon AWS to choose and configure an Amazon Machine Image (AMI) running a Gaia service. For this reason, you should have an AWS account on the Amazon AWS free tier, personal account, or corporate account. These instructions assume you are using a free tier account.

These instructions assume you have already created a free domain through the freenom service. If you have another domain, you can use that instead.

Finally, setting up the SSL certificates on your EC2 instance requires you to use the terminal command line on your workstation. Make sure you have the watch command installed using the which command.$ which watch
/usr/local/bin/watchIf watch is not located, install it on your workstation.
 
 
Task 1: Launch an EC2 instance
 
1.Visit the AWS Free Tier page and choose Sign in to the Console.
 

 
 
 
2. Make sure your region is set to one close to you.
 

 
 
 
 
3.  Under Build a solution choose Launch a virtual machine.

The system opens the EC2 dashboard.

4.  Enter Blockstack Gaia in the search bar.

5.  The system finds AMIs in the Marketplace and the Community.

Choose Community AMIs.

The system displays the available Gaia hub images.
 
 
 
 
6. Select the most recent version of the image.

Each image name has this format:

blockstack-gaia_hub-STORAGETYPE-VERSION-hvm - ami-BUILDTAG

So, the blockstack-gaia_hub-ephemeral-0001.0.1-hvm - ami-0425cf8c91bb2d331image uses ephemeral storage, is at version 0001.0.1 and has the 0425cf8c91bb2d331 tag.

You can choose an image that uses ephemeral or EBS storage. The ephemeral storage is very small but free. Only choose this if you plan to test or use a personal hub. Otherwise, choose the AMI for elastic block storage (EBS).

After you select an image, the system displays Step 2: Choose an Instance Type page.
 
 

 
 
7.  Select t2.micro and choose Next: Configure Instance Details.
 
 
To configure instance details, do the following:

1. Select a VPC.

A default VPC is created with a free tier account. You can use this default VPC. Or you can choose another VPC. If you choose another VPC, ensure the Subnetvalue is set to a subnet reachable by a public IP.Important: If you're using a private subnet, you should attach an elastic IP (EIP) to the VM. This EIP allows you to reboot the instance without worrying whether the address will reset. To attach an IP, press allocate new address and follow the instructions to attach the EIP to your new EC2 instance.
 
2. Set Protect against accidental termination.

If you terminate a Gaia instance, you lose all the data associated with it. Protection adds an extra step to terminating your Gaia instance.

3. Open the Advanced Details.

At this point, you are going to configure environment variables for your instance.

4. Paste the following into the Advanced Details.{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3D<KEYPHRASE>%0ADOMAIN%3D<DOMAIN_NAME_VALUE>%0ASTAGING%3D<STAGING_VALUE>"
}
}]
}
}
5.  Replace the following values in the JSON.
 
 
VALUE DESCRIPTION
<KEYPHRASE> A phrase to pass when using the hub admin. For example, hubba is a fun key phrase.
<DOMAIN_NAME_VALUE> Your hub's domain name. For example, maryhub.mlis the domain name in this example.
<STAGING_VALUE>

Indicates what type of SSL to create, testing (`1`) or production (`0`). Set testing if you want to test without worrying about rate limiting. A testing cerificate is not secure.

For this tutorial, use production (`0`).
 
6.Check your Advanced Details they should look similar to the following:{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3Dhubba%0ADOMAIN%3Dmaryhub.ml%0ASTAGING%3D0"
}
}]
}
}
 
 
At this point, you have configured your instance details.
 
8. Choose Next: Add Storage.
 

 
 
 
 
The storage is set according to the AMI you selected.

9. Choose Next: Add tags.

10. Add a Key of purpose with the Value gaia.
 
 
 11. Choose Next: Configure Security Group.

12. Create a security group with the following three types:
 
 
 





 13. Choose Review and Launch.

The system may warn you that the selection is not free tier eligible. You can ignore this for now.

14. Press Launch.

The system prompts you for a key pair.

15. Select Create a new keypair or Choose an existing key pair.

16. Select Launch Instances.
The system launches your instance.
 

 
During the launch process the machine starts and runs some initial setup processes. These processes take a few minutes depending on the network, typically launching does not take more than 10 minutes. While this is happening the instance Status Checks reflect the Initializing status.
 

 
 
 
 Task 2: Test your Gaia server
 
 
Now, you are ready to test your Gaia server and make sure it is up and running.

1.Visit the AWS Free Tier page and choose Sign in to the Console.

 
 
2. Choose All services > EC2.

The system displays the EC2 Dashboard.
 

 
 
3. Select Running Instances.

The system displays your running instances.

4. Locate your recently launched Gaia server.

Make sure the instance shows as running and Status Checks are complete. Completed status checks ensures the Gaia processes and service were started.

5. Select the Description tab.
 

 
 
 
 
 
6. Locate the IPv4 Public IP value.

7. Copy the IP and paste it in your browser.

You should see a message that your connection is not private.
8. Press Advanced.
  
 
9. Choose to proceed.

10. Extend the IP with the PUBLIC_IP/hub_info tag like so.
 You should see a response from your Gaia hub!

 
 
 
 
At this point, you should see a Not secure message in the browser. That’s because you haven’t yet enabled SSL certification. While HTTPS is not required simple to run the hub services, Blockstack will only connect to a hub and write to its storage over a valid HTTPS connection.
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
  view all
 
 
 
This teaches you how to run a Gaia hub on Amazon EC2. Amazon EC2 is an affordable and convenient cloud computing provider. This example uses Amazon EC2 together with an EB3 instance for file storage.
 


Prerequisites you need
Task 1: Launch an EC2 instance
Task 2: Test your Gaia server
Task 3: Configure a domain name
AWS hub tips and tricks

SSH into the Host
Displaying the docker services
Locations of key files
Restart services and reload certificates


 
 
Prerequisites you need
 
This procedure uses Amazon AWS to choose and configure an Amazon Machine Image (AMI) running a Gaia service. For this reason, you should have an AWS account on the Amazon AWS free tier, personal account, or corporate account. These instructions assume you are using a free tier account.

These instructions assume you have already created a free domain through the freenom service. If you have another domain, you can use that instead.

Finally, setting up the SSL certificates on your EC2 instance requires you to use the terminal command line on your workstation. Make sure you have the watch command installed using the which command.
$ which watch
/usr/local/bin/watch
If watch is not located, install it on your workstation.
 
 
Task 1: Launch an EC2 instance
 
1.Visit the AWS Free Tier page and choose Sign in to the Console.
 

 
 
 
2. Make sure your region is set to one close to you.
 

 
 
 
 
3.  Under Build a solution choose Launch a virtual machine.

The system opens the EC2 dashboard.

4.  Enter Blockstack Gaia in the search bar.

5.  The system finds AMIs in the Marketplace and the Community.

Choose Community AMIs.

The system displays the available Gaia hub images.
 
 
 
 
6. Select the most recent version of the image.

Each image name has this format:

blockstack-gaia_hub-STORAGETYPE-VERSION-hvm - ami-BUILDTAG

So, the blockstack-gaia_hub-ephemeral-0001.0.1-hvm - ami-0425cf8c91bb2d331image uses ephemeral storage, is at version 0001.0.1 and has the 0425cf8c91bb2d331 tag.

You can choose an image that uses ephemeral or EBS storage. The ephemeral storage is very small but free. Only choose this if you plan to test or use a personal hub. Otherwise, choose the AMI for elastic block storage (EBS).

After you select an image, the system displays Step 2: Choose an Instance Type page.
 
 

 
 
7.  Select t2.micro and choose Next: Configure Instance Details.
 
 
To configure instance details, do the following:

1. Select a VPC.

A default VPC is created with a free tier account. You can use this default VPC. Or you can choose another VPC. If you choose another VPC, ensure the Subnetvalue is set to a subnet reachable by a public IP.
Important: If you're using a private subnet, you should attach an elastic IP (EIP) to the VM. This EIP allows you to reboot the instance without worrying whether the address will reset. To attach an IP, press allocate new address and follow the instructions to attach the EIP to your new EC2 instance.

 
2. Set Protect against accidental termination.

If you terminate a Gaia instance, you lose all the data associated with it. Protection adds an extra step to terminating your Gaia instance.

3. Open the Advanced Details.

At this point, you are going to configure environment variables for your instance.

4. Paste the following into the Advanced Details.
{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3D<KEYPHRASE>%0ADOMAIN%3D<DOMAIN_NAME_VALUE>%0ASTAGING%3D<STAGING_VALUE>"
}
}]
}
}

5.  Replace the following values in the JSON.
 
 
VALUE DESCRIPTION
<KEYPHRASE> A phrase to pass when using the hub admin. For example, hubba is a fun key phrase.
<DOMAIN_NAME_VALUE> Your hub's domain name. For example, maryhub.mlis the domain name in this example.
<STAGING_VALUE>

Indicates what type of SSL to create, testing (`1`) or production (`0`). Set testing if you want to test without worrying about rate limiting. A testing cerificate is not secure.

For this tutorial, use production (`0`).
 
6.Check your Advanced Details they should look similar to the following:
{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3Dhubba%0ADOMAIN%3Dmaryhub.ml%0ASTAGING%3D0"
}
}]
}
}

 
 
At this point, you have configured your instance details.
 
8. Choose Next: Add Storage.
 

 
 
 
 
The storage is set according to the AMI you selected.

9. Choose Next: Add tags.

10. Add a Key of purpose with the Value gaia.
 
 
 11. Choose Next: Configure Security Group.

12. Create a security group with the following three types:
 
 
 
屏幕快照_2019-06-26_下午8.39_.06_.png


 13. Choose Review and Launch.

The system may warn you that the selection is not free tier eligible. You can ignore this for now.

14. Press Launch.

The system prompts you for a key pair.

15. Select Create a new keypair or Choose an existing key pair.

16. Select Launch Instances.
The system launches your instance.
 

 
During the launch process the machine starts and runs some initial setup processes. These processes take a few minutes depending on the network, typically launching does not take more than 10 minutes. While this is happening the instance Status Checks reflect the Initializing status.
 

 
 
 
 Task 2: Test your Gaia server
 
 
Now, you are ready to test your Gaia server and make sure it is up and running.

1.Visit the AWS Free Tier page and choose Sign in to the Console.

 
 
2. Choose All services > EC2.

The system displays the EC2 Dashboard.
 

 
 
3. Select Running Instances.

The system displays your running instances.

4. Locate your recently launched Gaia server.

Make sure the instance shows as running and Status Checks are complete. Completed status checks ensures the Gaia processes and service were started.

5. Select the Description tab.
 

 
 
 
 
 
6. Locate the IPv4 Public IP value.

7. Copy the IP and paste it in your browser.

You should see a message that your connection is not private.
8. Press Advanced.
  
 
9. Choose to proceed.

10. Extend the IP with the PUBLIC_IP/hub_info tag like so.
 You should see a response from your Gaia hub!

 
 
 
 
At this point, you should see a Not secure message in the browser. That’s because you haven’t yet enabled SSL certification. While HTTPS is not required simple to run the hub services, Blockstack will only connect to a hub and write to its storage over a valid HTTPS connection.
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
1341
Views

How Gaiahub Storage write and read

Othersblockstack app store posted the article • 0 comments • 1341 views • 2019-06-26 22:31 • data from similar tags

Once a user authenticates and a DApp obtains authentication, the application interacts with Gaia through the blockstack.js library. There are two simple methods for working with data in Gaia hub: the putFile() and getFile() methods. This section goes into greater detail about the methods, how they interact with a hub, and how to use them.
 
Write-to and Read-from URL Guarantees
 
 
Gaia is built on a driver model that supports many storage services. So, with very few lines of code, you can interact with providers on Amazon S3, Dropbox, and so forth. The simple getFile and putFile interfaces are kept simple because Blockstack assumes and wants to encourage a community of open-source-data-management libraries.

The performance and simplicity-oriented guarantee of the Gaia specification is that when an application submits a write-to  URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:]https://myhub.service.org/store/foo/bar URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:[/url]
 
GET /hub_info/
The endpoint returns a JSON object with a read_url_prefix, for example, if my service returns:
 
{ ...,
"read_url_prefix": "[url=https://myservice.org/read/"]https://myservice.org/read/"[/url]
}The data be read with this getFile() and this address:
[url=https://myservice.org/read/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/read/1DH ... .json[/url]


The application is guaranteed that the profile is written with putFile() this request address:
 
[url=https://myservice.org/store/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/store/1D ... .json[/url]
 
 
When you use the putFile() method it takes the user data and POSTs it to the user’s Gaia storage hub. The data POSTs directly to the hub, the blockchain is not used and no data is stored there. The limit on file upload is currently 25mb.
 
Address-based access-control
 
Access control in a Gaia storage hub is performed on a per-address basis. Writes to URLs /store/<address>/<file> are allowed only if the writer can demonstrate that they control that address. This is achieved via the authentication token which is a message signed by the private key associated with that address. The message itself is a challenge text, returned via the /hub_info/ endpoint.
  view all
Once a user authenticates and a DApp obtains authentication, the application interacts with Gaia through the blockstack.js library. There are two simple methods for working with data in Gaia hub: the putFile() and getFile() methods. This section goes into greater detail about the methods, how they interact with a hub, and how to use them.
 
Write-to and Read-from URL Guarantees
 
 
Gaia is built on a driver model that supports many storage services. So, with very few lines of code, you can interact with providers on Amazon S3, Dropbox, and so forth. The simple getFile and putFile interfaces are kept simple because Blockstack assumes and wants to encourage a community of open-source-data-management libraries.

The performance and simplicity-oriented guarantee of the Gaia specification is that when an application submits a write-to  URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:]https://myhub.service.org/store/foo/bar URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:[/url]
 
GET /hub_info/

The endpoint returns a JSON object with a read_url_prefix, for example, if my service returns:
 
{ ...,
"read_url_prefix": "[url=https://myservice.org/read/"]https://myservice.org/read/"[/url]
}
The data be read with this getFile() and this address:
[url=https://myservice.org/read/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/read/1DH ... .json[/url] 


The application is guaranteed that the profile is written with putFile() this request address:
 
[url=https://myservice.org/store/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/store/1D ... .json[/url]

 
 
When you use the putFile() method it takes the user data and POSTs it to the user’s Gaia storage hub. The data POSTs directly to the hub, the blockchain is not used and no data is stored there. The limit on file upload is currently 25mb.
 
Address-based access-control
 
Access control in a Gaia storage hub is performed on a per-address basis. Writes to URLs /store/<address>/<file> are allowed only if the writer can demonstrate that they control that address. This is achieved via the authentication token which is a message signed by the private key associated with that address. The message itself is a challenge text, returned via the /hub_info/ endpoint.
 
1340
Views

How to understand blockstack Authentication and Gaia

Othersblockstack app store posted the article • 0 comments • 1340 views • 2019-06-26 22:24 • data from similar tags

Blockstack authentication is a bearer token-based authentication system. From an app user’s perspective, login similar to third-party authentication techniques that they’re familiar with. For an app developer, the flow is unlike the typical client-server flow of centralized sign-in services such as OAuth. With Blockstack the authentication flow happens entirely client-side.
In this section, you get an overview of the authentication system and learn how Gaia fits into it.
 
Authentication and Gaia
 
A decentralized application (DApp) and the Blockstack Browser communicate during the authentication flow by passing back and forth two tokens. The requesting application sends the Blockstack Browser an authRequest token. Once a user approves a sign-in, the Blockstack Browser responds to the application with an authResponse token. These tokens are JSON Web Tokens, and they are passed via URL query strings.

When a user chooses to “Sign in with Blockstack” on your DApp, the redirectToSignIn()method sends the user to the Blockstack Browser. The browser responds with an authentication token and an app private key.
 

The app private key is application-specific. It is generated from the user’s identity address private key using the appDomain as input. This key is deterministic, meaning that for a given Blockstack ID and domain name, the same private key is generated each time. The app private key is securely shared with the app on each authentication and encrypted by the Blockstack Browser. The key serves three functions, it:
 
 
is used to create the credentials that give an app access to the Gaia hub storage bucket for that specific appis used in the end-to-end encryption of files stored for the app on the user’s Gaia hubserves as a cryptographic secret that apps can use to perform other cryptographic functions

When an application writes to a Gaia hub, the authentication token, key, and the data are passed to the Gaia hub.
 
 

 
The token ensures the DApp has the authorization to write to the hub on the user’s behalf.
 
 
 
  view all
Blockstack authentication is a bearer token-based authentication system. From an app user’s perspective, login similar to third-party authentication techniques that they’re familiar with. For an app developer, the flow is unlike the typical client-server flow of centralized sign-in services such as OAuth. With Blockstack the authentication flow happens entirely client-side.
In this section, you get an overview of the authentication system and learn how Gaia fits into it.
 
Authentication and Gaia
 
A decentralized application (DApp) and the Blockstack Browser communicate during the authentication flow by passing back and forth two tokens. The requesting application sends the Blockstack Browser an authRequest token. Once a user approves a sign-in, the Blockstack Browser responds to the application with an authResponse token. These tokens are JSON Web Tokens, and they are passed via URL query strings.

When a user chooses to “Sign in with Blockstack” on your DApp, the redirectToSignIn()method sends the user to the Blockstack Browser. The browser responds with an authentication token and an app private key.
 

The app private key is application-specific. It is generated from the user’s identity address private key using the appDomain as input. This key is deterministic, meaning that for a given Blockstack ID and domain name, the same private key is generated each time. The app private key is securely shared with the app on each authentication and encrypted by the Blockstack Browser. The key serves three functions, it:
 
 
  • is used to create the credentials that give an app access to the Gaia hub storage bucket for that specific app
  • is used in the end-to-end encryption of files stored for the app on the user’s Gaia hub
  • serves as a cryptographic secret that apps can use to perform other cryptographic functions


When an application writes to a Gaia hub, the authentication token, key, and the data are passed to the Gaia hub.
 
 

 
The token ensures the DApp has the authorization to write to the hub on the user’s behalf.
 
 
 
 
1512
Views

how gaiahub work as a decentralized storage architecture

Othersblockstack app store posted the article • 0 comments • 1512 views • 2019-06-26 22:18 • data from similar tags

The Blockstack Network stores application data using a storage system called Gaia. Transactional metadata is stored on the Blockstack blockchain and user application data is stored in Gaia storage. Storing data off of the blockchain ensures that Blockstack applications can provide users with high performance and high availability for data reads and writes without introducing central trust parties.
 

Understand Gaia in the Blockstack architecture
User control or how is Gaia decentralized?
Understand data storage
Gaia versus other storage systems

 
Understand Gaia in the Blockstack architecture
 

 
 
 Blockchains require consensus among large numbers of people, so they can be slow. Additionally, a blockchain is not designed to hold a lot of data. This means using a blockchain for every bit of data a user might write and store is expensive. For example, imagine if an application were storing every tweet in the chain.
 
Blockstack addresses blockchain performance problems using a layered approach. At the base of the system is a blockchain and the Blockstack Naming System (BNS). The blockchain governs ownership of names (identities) in the system, names such as domain names, usernames, and application names.
 
Names in Blockstack correspond to routing data in the OSI stack. The routing data is stored in the Atlas Peer Network, the second layer. Every core node that joins the Blockstack Network is able to obtain an entire copy of this routing data. Blockstack uses the routing data to associate names (usernames, domains, and application names) with a particular storage location.
 
The final layer is the Gaia Storage System. A Gaia system consists of a hub service and storage resource on a cloud software provider such as Azure, DigitalOcean, Amazon EC2, and so forth. Typically the compute resource and the storage resource belong to same cloud vendor. Gaia currently has driver support for S3 and Azure Blob Storage, but the driver model allows for other backend support as well.
 
Because Gaia stores application and user data off the blockchain, a Blockstack DApp is typically more performant than DApps created on other blockchains. Moreover, users choose where their data lives, and Gaia enables applications to access that user data via a uniform API. When the user logs in, the authentication process gives the application the URL of a Gaia hub, which then writes to storage on behalf of that user.
 
User control or how is Gaia decentralized?
 
 
A Gaia hub runs as a service which writes to data storage. The hub service writes to data storage by requiring a valid authentication token from a requestor. Typically, the hub service runs on a compute resource and the storage itself on separate, dedicated storage resource. Typically, both resources belong to the same cloud computing provider.
 
 

 
 
 Gaia’s approach to decentralization focuses on user control of data and its storage. If a user can choose which Gaia hub provider to use, then that choice is all the decentralization required to enable user-controlled applications.
The control of user data lies in the way that user data is accessed. When an application fetches a file data.txt for a given user alice.id, the lookup will follow these steps:
 
1. Fetch the zonefile for alice.id.
2. Read her profile URL from her zonefile.
3. Fetch Alice’s profile.
4. Verify that the profile is signed by alice.id’s key
5. Read the gaiaHubUrl (e.g. https://gaia.alice.org/) out of the profile
6. Fetch the file from https://gaia.alice.org/data.txt.
 
Because alice.id has access to her zonefile, she can change where her profile is stored. For example, she may do this if the current profile’s service or storage is compromised. To change where her profile is stored, she changes her Gaia hub URL to another Gaia hub URL from another hub provider. If Alice has sufficient compute and storage resources herself, she may run her own Gaia Storage System and bypass a commercial Gaia hub provider all together.
 Note: Users with existing identities cannot yet migrate their data from one hub to another.
Applications writing directly on behalf of Alice do not need to perform a lookup. Instead, the Blockstack authentication flow provides Alice’s chosen application root URL to the application. This authentication flow is also within Alice’s control because Alice’s browser must generate the authentication response.
 
Understand data storage
 
A Gaia hub stores the written data exactly as given. It offers minimal guarantees about the data. It does not ensure that data is validly formatted, contains valid signatures, or is encrypted. Rather, the design philosophy is that these concerns are client-side concerns.

Client libraries (such as blockstack.js) are capable of providing these guarantees. Blockstack used a liberal definition of the end-to-end principle to guide this design decision.
 
 
 
 

 
  view all
The Blockstack Network stores application data using a storage system called Gaia. Transactional metadata is stored on the Blockstack blockchain and user application data is stored in Gaia storage. Storing data off of the blockchain ensures that Blockstack applications can provide users with high performance and high availability for data reads and writes without introducing central trust parties.
 


Understand Gaia in the Blockstack architecture
User control or how is Gaia decentralized?
Understand data storage
Gaia versus other storage systems


 
Understand Gaia in the Blockstack architecture
 

 
 
 Blockchains require consensus among large numbers of people, so they can be slow. Additionally, a blockchain is not designed to hold a lot of data. This means using a blockchain for every bit of data a user might write and store is expensive. For example, imagine if an application were storing every tweet in the chain.
 
Blockstack addresses blockchain performance problems using a layered approach. At the base of the system is a blockchain and the Blockstack Naming System (BNS). The blockchain governs ownership of names (identities) in the system, names such as domain names, usernames, and application names.
 
Names in Blockstack correspond to routing data in the OSI stack. The routing data is stored in the Atlas Peer Network, the second layer. Every core node that joins the Blockstack Network is able to obtain an entire copy of this routing data. Blockstack uses the routing data to associate names (usernames, domains, and application names) with a particular storage location.
 
The final layer is the Gaia Storage System. A Gaia system consists of a hub service and storage resource on a cloud software provider such as Azure, DigitalOcean, Amazon EC2, and so forth. Typically the compute resource and the storage resource belong to same cloud vendor. Gaia currently has driver support for S3 and Azure Blob Storage, but the driver model allows for other backend support as well.
 
Because Gaia stores application and user data off the blockchain, a Blockstack DApp is typically more performant than DApps created on other blockchains. Moreover, users choose where their data lives, and Gaia enables applications to access that user data via a uniform API. When the user logs in, the authentication process gives the application the URL of a Gaia hub, which then writes to storage on behalf of that user.
 
User control or how is Gaia decentralized?
 
 
A Gaia hub runs as a service which writes to data storage. The hub service writes to data storage by requiring a valid authentication token from a requestor. Typically, the hub service runs on a compute resource and the storage itself on separate, dedicated storage resource. Typically, both resources belong to the same cloud computing provider.
 
 

 
 
 Gaia’s approach to decentralization focuses on user control of data and its storage. If a user can choose which Gaia hub provider to use, then that choice is all the decentralization required to enable user-controlled applications.
The control of user data lies in the way that user data is accessed. When an application fetches a file data.txt for a given user alice.id, the lookup will follow these steps:
 
1. Fetch the zonefile for alice.id.
2. Read her profile URL from her zonefile.
3. Fetch Alice’s profile.
4. Verify that the profile is signed by alice.id’s key
5. Read the gaiaHubUrl (e.g. https://gaia.alice.org/) out of the profile
6. Fetch the file from https://gaia.alice.org/data.txt.
 
Because alice.id has access to her zonefile, she can change where her profile is stored. For example, she may do this if the current profile’s service or storage is compromised. To change where her profile is stored, she changes her Gaia hub URL to another Gaia hub URL from another hub provider. If Alice has sufficient compute and storage resources herself, she may run her own Gaia Storage System and bypass a commercial Gaia hub provider all together.
 
Note: Users with existing identities cannot yet migrate their data from one hub to another.

Applications writing directly on behalf of Alice do not need to perform a lookup. Instead, the Blockstack authentication flow provides Alice’s chosen application root URL to the application. This authentication flow is also within Alice’s control because Alice’s browser must generate the authentication response.
 
Understand data storage
 
A Gaia hub stores the written data exactly as given. It offers minimal guarantees about the data. It does not ensure that data is validly formatted, contains valid signatures, or is encrypted. Rather, the design philosophy is that these concerns are client-side concerns.

Client libraries (such as blockstack.js) are capable of providing these guarantees. Blockstack used a liberal definition of the end-to-end principle to guide this design decision.
 
 
 
 

 
 
1735
Views

What is Blockstack?

Questionsblockstack app store replied • 2 users followed • 1 replies • 1735 views • 2019-06-26 22:02 • data from similar tags

1645
Views

What is Blockstack Core?

Questionsblockstack app store replied • 2 users followed • 1 replies • 1645 views • 2019-06-26 22:01 • data from similar tags

1933
Views

Which is the best cloud storage server in 2019?Gaiahub? XOR Drive, Azure?or AWS ?

Reply

Questionsdacre posted a question • 1 users followed • 0 replies • 1933 views • 2019-06-03 00:48 • data from similar tags

1735
Views

What is Blockstack?

Reply

Questionsblockstack app store replied • 2 users followed • 1 replies • 1735 views • 2019-06-26 22:02 • data from similar tags

1645
Views

What is Blockstack Core?

Reply

Questionsblockstack app store replied • 2 users followed • 1 replies • 1645 views • 2019-06-26 22:01 • data from similar tags

1933
Views

Which is the best cloud storage server in 2019?Gaiahub? XOR Drive, Azure?or AWS ?

Reply

Questionsdacre posted a question • 1 users followed • 0 replies • 1933 views • 2019-06-03 00:48 • data from similar tags

1563
Views

How to configure a Gaiahub on Amazon EC2,step by step tutorial

Othersblockstack app store posted the article • 0 comments • 1563 views • 2019-06-26 22:36 • data from similar tags

 
 
 
This teaches you how to run a Gaia hub on Amazon EC2. Amazon EC2 is an affordable and convenient cloud computing provider. This example uses Amazon EC2 together with an EB3 instance for file storage.
 

Prerequisites you need
Task 1: Launch an EC2 instance
Task 2: Test your Gaia server
Task 3: Configure a domain name
AWS hub tips and tricks

SSH into the Host
Displaying the docker services
Locations of key files
Restart services and reload certificates

 
 
Prerequisites you need
 
This procedure uses Amazon AWS to choose and configure an Amazon Machine Image (AMI) running a Gaia service. For this reason, you should have an AWS account on the Amazon AWS free tier, personal account, or corporate account. These instructions assume you are using a free tier account.

These instructions assume you have already created a free domain through the freenom service. If you have another domain, you can use that instead.

Finally, setting up the SSL certificates on your EC2 instance requires you to use the terminal command line on your workstation. Make sure you have the watch command installed using the which command.$ which watch
/usr/local/bin/watchIf watch is not located, install it on your workstation.
 
 
Task 1: Launch an EC2 instance
 
1.Visit the AWS Free Tier page and choose Sign in to the Console.
 

 
 
 
2. Make sure your region is set to one close to you.
 

 
 
 
 
3.  Under Build a solution choose Launch a virtual machine.

The system opens the EC2 dashboard.

4.  Enter Blockstack Gaia in the search bar.

5.  The system finds AMIs in the Marketplace and the Community.

Choose Community AMIs.

The system displays the available Gaia hub images.
 
 
 
 
6. Select the most recent version of the image.

Each image name has this format:

blockstack-gaia_hub-STORAGETYPE-VERSION-hvm - ami-BUILDTAG

So, the blockstack-gaia_hub-ephemeral-0001.0.1-hvm - ami-0425cf8c91bb2d331image uses ephemeral storage, is at version 0001.0.1 and has the 0425cf8c91bb2d331 tag.

You can choose an image that uses ephemeral or EBS storage. The ephemeral storage is very small but free. Only choose this if you plan to test or use a personal hub. Otherwise, choose the AMI for elastic block storage (EBS).

After you select an image, the system displays Step 2: Choose an Instance Type page.
 
 

 
 
7.  Select t2.micro and choose Next: Configure Instance Details.
 
 
To configure instance details, do the following:

1. Select a VPC.

A default VPC is created with a free tier account. You can use this default VPC. Or you can choose another VPC. If you choose another VPC, ensure the Subnetvalue is set to a subnet reachable by a public IP.Important: If you're using a private subnet, you should attach an elastic IP (EIP) to the VM. This EIP allows you to reboot the instance without worrying whether the address will reset. To attach an IP, press allocate new address and follow the instructions to attach the EIP to your new EC2 instance.
 
2. Set Protect against accidental termination.

If you terminate a Gaia instance, you lose all the data associated with it. Protection adds an extra step to terminating your Gaia instance.

3. Open the Advanced Details.

At this point, you are going to configure environment variables for your instance.

4. Paste the following into the Advanced Details.{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3D<KEYPHRASE>%0ADOMAIN%3D<DOMAIN_NAME_VALUE>%0ASTAGING%3D<STAGING_VALUE>"
}
}]
}
}
5.  Replace the following values in the JSON.
 
 
VALUE DESCRIPTION
<KEYPHRASE> A phrase to pass when using the hub admin. For example, hubba is a fun key phrase.
<DOMAIN_NAME_VALUE> Your hub's domain name. For example, maryhub.mlis the domain name in this example.
<STAGING_VALUE>

Indicates what type of SSL to create, testing (`1`) or production (`0`). Set testing if you want to test without worrying about rate limiting. A testing cerificate is not secure.

For this tutorial, use production (`0`).
 
6.Check your Advanced Details they should look similar to the following:{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3Dhubba%0ADOMAIN%3Dmaryhub.ml%0ASTAGING%3D0"
}
}]
}
}
 
 
At this point, you have configured your instance details.
 
8. Choose Next: Add Storage.
 

 
 
 
 
The storage is set according to the AMI you selected.

9. Choose Next: Add tags.

10. Add a Key of purpose with the Value gaia.
 
 
 11. Choose Next: Configure Security Group.

12. Create a security group with the following three types:
 
 
 





 13. Choose Review and Launch.

The system may warn you that the selection is not free tier eligible. You can ignore this for now.

14. Press Launch.

The system prompts you for a key pair.

15. Select Create a new keypair or Choose an existing key pair.

16. Select Launch Instances.
The system launches your instance.
 

 
During the launch process the machine starts and runs some initial setup processes. These processes take a few minutes depending on the network, typically launching does not take more than 10 minutes. While this is happening the instance Status Checks reflect the Initializing status.
 

 
 
 
 Task 2: Test your Gaia server
 
 
Now, you are ready to test your Gaia server and make sure it is up and running.

1.Visit the AWS Free Tier page and choose Sign in to the Console.

 
 
2. Choose All services > EC2.

The system displays the EC2 Dashboard.
 

 
 
3. Select Running Instances.

The system displays your running instances.

4. Locate your recently launched Gaia server.

Make sure the instance shows as running and Status Checks are complete. Completed status checks ensures the Gaia processes and service were started.

5. Select the Description tab.
 

 
 
 
 
 
6. Locate the IPv4 Public IP value.

7. Copy the IP and paste it in your browser.

You should see a message that your connection is not private.
8. Press Advanced.
  
 
9. Choose to proceed.

10. Extend the IP with the PUBLIC_IP/hub_info tag like so.
 You should see a response from your Gaia hub!

 
 
 
 
At this point, you should see a Not secure message in the browser. That’s because you haven’t yet enabled SSL certification. While HTTPS is not required simple to run the hub services, Blockstack will only connect to a hub and write to its storage over a valid HTTPS connection.
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
  view all
 
 
 
This teaches you how to run a Gaia hub on Amazon EC2. Amazon EC2 is an affordable and convenient cloud computing provider. This example uses Amazon EC2 together with an EB3 instance for file storage.
 


Prerequisites you need
Task 1: Launch an EC2 instance
Task 2: Test your Gaia server
Task 3: Configure a domain name
AWS hub tips and tricks

SSH into the Host
Displaying the docker services
Locations of key files
Restart services and reload certificates


 
 
Prerequisites you need
 
This procedure uses Amazon AWS to choose and configure an Amazon Machine Image (AMI) running a Gaia service. For this reason, you should have an AWS account on the Amazon AWS free tier, personal account, or corporate account. These instructions assume you are using a free tier account.

These instructions assume you have already created a free domain through the freenom service. If you have another domain, you can use that instead.

Finally, setting up the SSL certificates on your EC2 instance requires you to use the terminal command line on your workstation. Make sure you have the watch command installed using the which command.
$ which watch
/usr/local/bin/watch
If watch is not located, install it on your workstation.
 
 
Task 1: Launch an EC2 instance
 
1.Visit the AWS Free Tier page and choose Sign in to the Console.
 

 
 
 
2. Make sure your region is set to one close to you.
 

 
 
 
 
3.  Under Build a solution choose Launch a virtual machine.

The system opens the EC2 dashboard.

4.  Enter Blockstack Gaia in the search bar.

5.  The system finds AMIs in the Marketplace and the Community.

Choose Community AMIs.

The system displays the available Gaia hub images.
 
 
 
 
6. Select the most recent version of the image.

Each image name has this format:

blockstack-gaia_hub-STORAGETYPE-VERSION-hvm - ami-BUILDTAG

So, the blockstack-gaia_hub-ephemeral-0001.0.1-hvm - ami-0425cf8c91bb2d331image uses ephemeral storage, is at version 0001.0.1 and has the 0425cf8c91bb2d331 tag.

You can choose an image that uses ephemeral or EBS storage. The ephemeral storage is very small but free. Only choose this if you plan to test or use a personal hub. Otherwise, choose the AMI for elastic block storage (EBS).

After you select an image, the system displays Step 2: Choose an Instance Type page.
 
 

 
 
7.  Select t2.micro and choose Next: Configure Instance Details.
 
 
To configure instance details, do the following:

1. Select a VPC.

A default VPC is created with a free tier account. You can use this default VPC. Or you can choose another VPC. If you choose another VPC, ensure the Subnetvalue is set to a subnet reachable by a public IP.
Important: If you're using a private subnet, you should attach an elastic IP (EIP) to the VM. This EIP allows you to reboot the instance without worrying whether the address will reset. To attach an IP, press allocate new address and follow the instructions to attach the EIP to your new EC2 instance.

 
2. Set Protect against accidental termination.

If you terminate a Gaia instance, you lose all the data associated with it. Protection adds an extra step to terminating your Gaia instance.

3. Open the Advanced Details.

At this point, you are going to configure environment variables for your instance.

4. Paste the following into the Advanced Details.
{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3D<KEYPHRASE>%0ADOMAIN%3D<DOMAIN_NAME_VALUE>%0ASTAGING%3D<STAGING_VALUE>"
}
}]
}
}

5.  Replace the following values in the JSON.
 
 
VALUE DESCRIPTION
<KEYPHRASE> A phrase to pass when using the hub admin. For example, hubba is a fun key phrase.
<DOMAIN_NAME_VALUE> Your hub's domain name. For example, maryhub.mlis the domain name in this example.
<STAGING_VALUE>

Indicates what type of SSL to create, testing (`1`) or production (`0`). Set testing if you want to test without worrying about rate limiting. A testing cerificate is not secure.

For this tutorial, use production (`0`).
 
6.Check your Advanced Details they should look similar to the following:
{
"ignition": { "version": "2.2.0" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/environment",
"mode": 420,
"contents": {
"source": "data:application/octet-stream,API_KEY%3Dhubba%0ADOMAIN%3Dmaryhub.ml%0ASTAGING%3D0"
}
}]
}
}

 
 
At this point, you have configured your instance details.
 
8. Choose Next: Add Storage.
 

 
 
 
 
The storage is set according to the AMI you selected.

9. Choose Next: Add tags.

10. Add a Key of purpose with the Value gaia.
 
 
 11. Choose Next: Configure Security Group.

12. Create a security group with the following three types:
 
 
 
屏幕快照_2019-06-26_下午8.39_.06_.png


 13. Choose Review and Launch.

The system may warn you that the selection is not free tier eligible. You can ignore this for now.

14. Press Launch.

The system prompts you for a key pair.

15. Select Create a new keypair or Choose an existing key pair.

16. Select Launch Instances.
The system launches your instance.
 

 
During the launch process the machine starts and runs some initial setup processes. These processes take a few minutes depending on the network, typically launching does not take more than 10 minutes. While this is happening the instance Status Checks reflect the Initializing status.
 

 
 
 
 Task 2: Test your Gaia server
 
 
Now, you are ready to test your Gaia server and make sure it is up and running.

1.Visit the AWS Free Tier page and choose Sign in to the Console.

 
 
2. Choose All services > EC2.

The system displays the EC2 Dashboard.
 

 
 
3. Select Running Instances.

The system displays your running instances.

4. Locate your recently launched Gaia server.

Make sure the instance shows as running and Status Checks are complete. Completed status checks ensures the Gaia processes and service were started.

5. Select the Description tab.
 

 
 
 
 
 
6. Locate the IPv4 Public IP value.

7. Copy the IP and paste it in your browser.

You should see a message that your connection is not private.
8. Press Advanced.
  
 
9. Choose to proceed.

10. Extend the IP with the PUBLIC_IP/hub_info tag like so.
 You should see a response from your Gaia hub!

 
 
 
 
At this point, you should see a Not secure message in the browser. That’s because you haven’t yet enabled SSL certification. While HTTPS is not required simple to run the hub services, Blockstack will only connect to a hub and write to its storage over a valid HTTPS connection.
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
1341
Views

How Gaiahub Storage write and read

Othersblockstack app store posted the article • 0 comments • 1341 views • 2019-06-26 22:31 • data from similar tags

Once a user authenticates and a DApp obtains authentication, the application interacts with Gaia through the blockstack.js library. There are two simple methods for working with data in Gaia hub: the putFile() and getFile() methods. This section goes into greater detail about the methods, how they interact with a hub, and how to use them.
 
Write-to and Read-from URL Guarantees
 
 
Gaia is built on a driver model that supports many storage services. So, with very few lines of code, you can interact with providers on Amazon S3, Dropbox, and so forth. The simple getFile and putFile interfaces are kept simple because Blockstack assumes and wants to encourage a community of open-source-data-management libraries.

The performance and simplicity-oriented guarantee of the Gaia specification is that when an application submits a write-to  URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:]https://myhub.service.org/store/foo/bar URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:[/url]
 
GET /hub_info/
The endpoint returns a JSON object with a read_url_prefix, for example, if my service returns:
 
{ ...,
"read_url_prefix": "[url=https://myservice.org/read/"]https://myservice.org/read/"[/url]
}The data be read with this getFile() and this address:
[url=https://myservice.org/read/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/read/1DH ... .json[/url]


The application is guaranteed that the profile is written with putFile() this request address:
 
[url=https://myservice.org/store/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/store/1D ... .json[/url]
 
 
When you use the putFile() method it takes the user data and POSTs it to the user’s Gaia storage hub. The data POSTs directly to the hub, the blockchain is not used and no data is stored there. The limit on file upload is currently 25mb.
 
Address-based access-control
 
Access control in a Gaia storage hub is performed on a per-address basis. Writes to URLs /store/<address>/<file> are allowed only if the writer can demonstrate that they control that address. This is achieved via the authentication token which is a message signed by the private key associated with that address. The message itself is a challenge text, returned via the /hub_info/ endpoint.
  view all
Once a user authenticates and a DApp obtains authentication, the application interacts with Gaia through the blockstack.js library. There are two simple methods for working with data in Gaia hub: the putFile() and getFile() methods. This section goes into greater detail about the methods, how they interact with a hub, and how to use them.
 
Write-to and Read-from URL Guarantees
 
 
Gaia is built on a driver model that supports many storage services. So, with very few lines of code, you can interact with providers on Amazon S3, Dropbox, and so forth. The simple getFile and putFile interfaces are kept simple because Blockstack assumes and wants to encourage a community of open-source-data-management libraries.

The performance and simplicity-oriented guarantee of the Gaia specification is that when an application submits a write-to  URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:]https://myhub.service.org/store/foo/bar URL, the application is guaranteed to be able to read from the https://myreads.com/foo/bar URL. Note that, while the prefix in the write-to url (for example,myhub.service.org/store) and the read-from URL (https://myreads.com) are different, the foo/bar suffixes are the same.Consistent, identical suffixes allow an application to know exactly where a written file can be read from, given the read prefix. The Gaia service defines a hub_info endpoint to obtain that read prefix:[/url]
 
GET /hub_info/

The endpoint returns a JSON object with a read_url_prefix, for example, if my service returns:
 
{ ...,
"read_url_prefix": "[url=https://myservice.org/read/"]https://myservice.org/read/"[/url]
}
The data be read with this getFile() and this address:
[url=https://myservice.org/read/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/read/1DH ... .json[/url] 


The application is guaranteed that the profile is written with putFile() this request address:
 
[url=https://myservice.org/store/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/store/1D ... .json[/url]

 
 
When you use the putFile() method it takes the user data and POSTs it to the user’s Gaia storage hub. The data POSTs directly to the hub, the blockchain is not used and no data is stored there. The limit on file upload is currently 25mb.
 
Address-based access-control
 
Access control in a Gaia storage hub is performed on a per-address basis. Writes to URLs /store/<address>/<file> are allowed only if the writer can demonstrate that they control that address. This is achieved via the authentication token which is a message signed by the private key associated with that address. The message itself is a challenge text, returned via the /hub_info/ endpoint.
 
1340
Views

How to understand blockstack Authentication and Gaia

Othersblockstack app store posted the article • 0 comments • 1340 views • 2019-06-26 22:24 • data from similar tags

Blockstack authentication is a bearer token-based authentication system. From an app user’s perspective, login similar to third-party authentication techniques that they’re familiar with. For an app developer, the flow is unlike the typical client-server flow of centralized sign-in services such as OAuth. With Blockstack the authentication flow happens entirely client-side.
In this section, you get an overview of the authentication system and learn how Gaia fits into it.
 
Authentication and Gaia
 
A decentralized application (DApp) and the Blockstack Browser communicate during the authentication flow by passing back and forth two tokens. The requesting application sends the Blockstack Browser an authRequest token. Once a user approves a sign-in, the Blockstack Browser responds to the application with an authResponse token. These tokens are JSON Web Tokens, and they are passed via URL query strings.

When a user chooses to “Sign in with Blockstack” on your DApp, the redirectToSignIn()method sends the user to the Blockstack Browser. The browser responds with an authentication token and an app private key.
 

The app private key is application-specific. It is generated from the user’s identity address private key using the appDomain as input. This key is deterministic, meaning that for a given Blockstack ID and domain name, the same private key is generated each time. The app private key is securely shared with the app on each authentication and encrypted by the Blockstack Browser. The key serves three functions, it:
 
 
is used to create the credentials that give an app access to the Gaia hub storage bucket for that specific appis used in the end-to-end encryption of files stored for the app on the user’s Gaia hubserves as a cryptographic secret that apps can use to perform other cryptographic functions

When an application writes to a Gaia hub, the authentication token, key, and the data are passed to the Gaia hub.
 
 

 
The token ensures the DApp has the authorization to write to the hub on the user’s behalf.
 
 
 
  view all
Blockstack authentication is a bearer token-based authentication system. From an app user’s perspective, login similar to third-party authentication techniques that they’re familiar with. For an app developer, the flow is unlike the typical client-server flow of centralized sign-in services such as OAuth. With Blockstack the authentication flow happens entirely client-side.
In this section, you get an overview of the authentication system and learn how Gaia fits into it.
 
Authentication and Gaia
 
A decentralized application (DApp) and the Blockstack Browser communicate during the authentication flow by passing back and forth two tokens. The requesting application sends the Blockstack Browser an authRequest token. Once a user approves a sign-in, the Blockstack Browser responds to the application with an authResponse token. These tokens are JSON Web Tokens, and they are passed via URL query strings.

When a user chooses to “Sign in with Blockstack” on your DApp, the redirectToSignIn()method sends the user to the Blockstack Browser. The browser responds with an authentication token and an app private key.
 

The app private key is application-specific. It is generated from the user’s identity address private key using the appDomain as input. This key is deterministic, meaning that for a given Blockstack ID and domain name, the same private key is generated each time. The app private key is securely shared with the app on each authentication and encrypted by the Blockstack Browser. The key serves three functions, it:
 
 
  • is used to create the credentials that give an app access to the Gaia hub storage bucket for that specific app
  • is used in the end-to-end encryption of files stored for the app on the user’s Gaia hub
  • serves as a cryptographic secret that apps can use to perform other cryptographic functions


When an application writes to a Gaia hub, the authentication token, key, and the data are passed to the Gaia hub.
 
 

 
The token ensures the DApp has the authorization to write to the hub on the user’s behalf.
 
 
 
 
1512
Views

how gaiahub work as a decentralized storage architecture

Othersblockstack app store posted the article • 0 comments • 1512 views • 2019-06-26 22:18 • data from similar tags

The Blockstack Network stores application data using a storage system called Gaia. Transactional metadata is stored on the Blockstack blockchain and user application data is stored in Gaia storage. Storing data off of the blockchain ensures that Blockstack applications can provide users with high performance and high availability for data reads and writes without introducing central trust parties.
 

Understand Gaia in the Blockstack architecture
User control or how is Gaia decentralized?
Understand data storage
Gaia versus other storage systems

 
Understand Gaia in the Blockstack architecture
 

 
 
 Blockchains require consensus among large numbers of people, so they can be slow. Additionally, a blockchain is not designed to hold a lot of data. This means using a blockchain for every bit of data a user might write and store is expensive. For example, imagine if an application were storing every tweet in the chain.
 
Blockstack addresses blockchain performance problems using a layered approach. At the base of the system is a blockchain and the Blockstack Naming System (BNS). The blockchain governs ownership of names (identities) in the system, names such as domain names, usernames, and application names.
 
Names in Blockstack correspond to routing data in the OSI stack. The routing data is stored in the Atlas Peer Network, the second layer. Every core node that joins the Blockstack Network is able to obtain an entire copy of this routing data. Blockstack uses the routing data to associate names (usernames, domains, and application names) with a particular storage location.
 
The final layer is the Gaia Storage System. A Gaia system consists of a hub service and storage resource on a cloud software provider such as Azure, DigitalOcean, Amazon EC2, and so forth. Typically the compute resource and the storage resource belong to same cloud vendor. Gaia currently has driver support for S3 and Azure Blob Storage, but the driver model allows for other backend support as well.
 
Because Gaia stores application and user data off the blockchain, a Blockstack DApp is typically more performant than DApps created on other blockchains. Moreover, users choose where their data lives, and Gaia enables applications to access that user data via a uniform API. When the user logs in, the authentication process gives the application the URL of a Gaia hub, which then writes to storage on behalf of that user.
 
User control or how is Gaia decentralized?
 
 
A Gaia hub runs as a service which writes to data storage. The hub service writes to data storage by requiring a valid authentication token from a requestor. Typically, the hub service runs on a compute resource and the storage itself on separate, dedicated storage resource. Typically, both resources belong to the same cloud computing provider.
 
 

 
 
 Gaia’s approach to decentralization focuses on user control of data and its storage. If a user can choose which Gaia hub provider to use, then that choice is all the decentralization required to enable user-controlled applications.
The control of user data lies in the way that user data is accessed. When an application fetches a file data.txt for a given user alice.id, the lookup will follow these steps:
 
1. Fetch the zonefile for alice.id.
2. Read her profile URL from her zonefile.
3. Fetch Alice’s profile.
4. Verify that the profile is signed by alice.id’s key
5. Read the gaiaHubUrl (e.g. https://gaia.alice.org/) out of the profile
6. Fetch the file from https://gaia.alice.org/data.txt.
 
Because alice.id has access to her zonefile, she can change where her profile is stored. For example, she may do this if the current profile’s service or storage is compromised. To change where her profile is stored, she changes her Gaia hub URL to another Gaia hub URL from another hub provider. If Alice has sufficient compute and storage resources herself, she may run her own Gaia Storage System and bypass a commercial Gaia hub provider all together.
 Note: Users with existing identities cannot yet migrate their data from one hub to another.
Applications writing directly on behalf of Alice do not need to perform a lookup. Instead, the Blockstack authentication flow provides Alice’s chosen application root URL to the application. This authentication flow is also within Alice’s control because Alice’s browser must generate the authentication response.
 
Understand data storage
 
A Gaia hub stores the written data exactly as given. It offers minimal guarantees about the data. It does not ensure that data is validly formatted, contains valid signatures, or is encrypted. Rather, the design philosophy is that these concerns are client-side concerns.

Client libraries (such as blockstack.js) are capable of providing these guarantees. Blockstack used a liberal definition of the end-to-end principle to guide this design decision.
 
 
 
 

 
  view all
The Blockstack Network stores application data using a storage system called Gaia. Transactional metadata is stored on the Blockstack blockchain and user application data is stored in Gaia storage. Storing data off of the blockchain ensures that Blockstack applications can provide users with high performance and high availability for data reads and writes without introducing central trust parties.
 


Understand Gaia in the Blockstack architecture
User control or how is Gaia decentralized?
Understand data storage
Gaia versus other storage systems


 
Understand Gaia in the Blockstack architecture
 

 
 
 Blockchains require consensus among large numbers of people, so they can be slow. Additionally, a blockchain is not designed to hold a lot of data. This means using a blockchain for every bit of data a user might write and store is expensive. For example, imagine if an application were storing every tweet in the chain.
 
Blockstack addresses blockchain performance problems using a layered approach. At the base of the system is a blockchain and the Blockstack Naming System (BNS). The blockchain governs ownership of names (identities) in the system, names such as domain names, usernames, and application names.
 
Names in Blockstack correspond to routing data in the OSI stack. The routing data is stored in the Atlas Peer Network, the second layer. Every core node that joins the Blockstack Network is able to obtain an entire copy of this routing data. Blockstack uses the routing data to associate names (usernames, domains, and application names) with a particular storage location.
 
The final layer is the Gaia Storage System. A Gaia system consists of a hub service and storage resource on a cloud software provider such as Azure, DigitalOcean, Amazon EC2, and so forth. Typically the compute resource and the storage resource belong to same cloud vendor. Gaia currently has driver support for S3 and Azure Blob Storage, but the driver model allows for other backend support as well.
 
Because Gaia stores application and user data off the blockchain, a Blockstack DApp is typically more performant than DApps created on other blockchains. Moreover, users choose where their data lives, and Gaia enables applications to access that user data via a uniform API. When the user logs in, the authentication process gives the application the URL of a Gaia hub, which then writes to storage on behalf of that user.
 
User control or how is Gaia decentralized?
 
 
A Gaia hub runs as a service which writes to data storage. The hub service writes to data storage by requiring a valid authentication token from a requestor. Typically, the hub service runs on a compute resource and the storage itself on separate, dedicated storage resource. Typically, both resources belong to the same cloud computing provider.
 
 

 
 
 Gaia’s approach to decentralization focuses on user control of data and its storage. If a user can choose which Gaia hub provider to use, then that choice is all the decentralization required to enable user-controlled applications.
The control of user data lies in the way that user data is accessed. When an application fetches a file data.txt for a given user alice.id, the lookup will follow these steps:
 
1. Fetch the zonefile for alice.id.
2. Read her profile URL from her zonefile.
3. Fetch Alice’s profile.
4. Verify that the profile is signed by alice.id’s key
5. Read the gaiaHubUrl (e.g. https://gaia.alice.org/) out of the profile
6. Fetch the file from https://gaia.alice.org/data.txt.
 
Because alice.id has access to her zonefile, she can change where her profile is stored. For example, she may do this if the current profile’s service or storage is compromised. To change where her profile is stored, she changes her Gaia hub URL to another Gaia hub URL from another hub provider. If Alice has sufficient compute and storage resources herself, she may run her own Gaia Storage System and bypass a commercial Gaia hub provider all together.
 
Note: Users with existing identities cannot yet migrate their data from one hub to another.

Applications writing directly on behalf of Alice do not need to perform a lookup. Instead, the Blockstack authentication flow provides Alice’s chosen application root URL to the application. This authentication flow is also within Alice’s control because Alice’s browser must generate the authentication response.
 
Understand data storage
 
A Gaia hub stores the written data exactly as given. It offers minimal guarantees about the data. It does not ensure that data is validly formatted, contains valid signatures, or is encrypted. Rather, the design philosophy is that these concerns are client-side concerns.

Client libraries (such as blockstack.js) are capable of providing these guarantees. Blockstack used a liberal definition of the end-to-end principle to guide this design decision.
 
 
 
 

 
 
    
This document describes the high-level design and implementation of the Gaia storage system. It includes specifications for backend storage drivers and interactions between developer APIs and the Gaia service.

Developers who wish to use the Gaia storage system should see the blockstack.js APIs documented here and here.

If you would like to deploy your own hub, there are instructions available here

Instructions on setting up and configuring a Gaia Hub can be found in this readme.

Overview
Gaia works by hosting data in one or more existing storage systems of the user's choice. These storage systems are typically cloud storage systems. We currently have driver support for S3 and Azure Blob Storage, but the driver model allows for other backend support as well. The point is, the user gets to choose where their data lives, and Gaia enables applications to access it via a uniform API.

Blockstack applications use the Gaia storage system to store data on behalf of a user. When the user logs in to an application, the authentication process gives the application the URL of a Gaia hub, which performs writes on behalf of that user. The Gaia hub authenticates writes to a location by requiring a valid authentication token, generated by a private key authorized to write at that location.

User Control: How is Gaia Decentralized?
Gaia's approach to decentralization focuses on user-control of data and storage. If a user can choose which gaia hub and which backend provider to store data with, then that is all the decentralization required to enable user-controlled applications.

In Gaia, the control of user data lies in the way that user data is accessed. When an application fetches a file data.txt for a given user alice.id, the lookup will follow these steps:

Fetch the zonefile for alice.id, and read her profile URL from that zonefile
Fetch the Alice's profile and verify that it is signed by alice.id's key
Read the application root URL (e.g. [url=https://gaia.alice.org]https://gaia.alice.org[/url]/) out of the profile
Fetch file from [url=https://gaia.alice.org/data.txt]https://gaia.alice.org/data.txt[/url]
Because alice.id controls her zonefile, she can change where her profile is stored, if the current storage of the profile is compromised. Similarly, if Alice wishes to change her gaia provider, or run her own gaia node, she can change the entry in her profile.

For applications writing directly on behalf of Alice, they do not need to perform this lookup. Instead, the blockstack authentication flow provides Alice's chosen application root URL to the application. This authentication flow is also within Alice's control, because the authentication response must be generated by Alice's browser.

While it is true that many Gaia hubs will use backend providers like AWS or Azure, allowing users to easily operate their own hubs, which may select different backend providers (and we'd like to implement more backend drivers), enables truly user-controlled data, while enabling high performance and high availability for data reads and writes.

Write-to and Read-from URL Guarantees
A performance and simplicity oriented guarantee of the Gaia specification is that when an application submits a write to a URL [url=https://myhub.service.org/store/foo/bar]https://myhub.service.org/store/foo/bar[/url], the application is guaranteed to be able to read from a URL [url=https://myreads.com/foo/bar.]https://myreads.com/foo/bar.[/url] While the prefix of the read-from URL may change between the two, the suffix must be the same as the write-to URL.

This allows an application to know exactly where a written file can be read from, given the read prefix. To obtain that read prefix, the Gaia service defines an endpoint:

GET /hub_info/
which returns a JSON object with a read_url_prefix.

For example, if my service returns:

{ ...,
"read_url_prefix": "[url=https://myservice.org/read/"]https://myservice.org/read/"[/url]
}
I know that if I submit a write request to:

[url=https://myservice.org/store/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/store/1D ... .json[/url]
That I will be able to read that file from:

[url=https://myservice.org/read/1DHvWDj834zPAkwMhpXdYbCYh4PomwQfzz/0/profile.json]https://myservice.org/read/1DH ... .json[/url]
Address-based Access-Control
Access control in a gaia storage hub is performed on a per-address basis. Writes to URLs /store/<address>/<file> are only allowed if the writer can demonstrate that they control that address. This is achieved via an authentication token, which is a message signed by the private-key associated with that address. The message itself is a challenge-text, returned via the /hub_info/ endpoint.

V1 Authentication Scheme
The V1 authentication scheme uses a JWT, prefixed with v1: as a bearer token in the HTTP authorization field. The expected JWT payload structure is:

{
'type': 'object',
'properties': {
'iss': { 'type': 'string' },
'exp': { 'type': 'IntDate' },
'iat': { 'type': 'IntDate' },
'gaiaChallenge': { 'type': 'string' },
'associationToken': { 'type': 'string' },
'salt': { 'type': 'string' }
}
'required': [ 'iss', 'gaiaChallenge' ]
}
In addition to iss, exp, and gaiaChallenge claims, clients may add other properties (e.g., a salt field) to the payload, and they will not affect the validity of the JWT. Rather, the validity of the JWT is checked by ensuring:

That the JWT is signed correctly by verifying with the pubkey hex provided as iss
That iss matches the address associated with the bucket.
That gaiaChallenge is equal to the server's challenge text.
That the epoch time exp is greater than the server's current epoch time.
That the epoch time iat (issued-at date) is greater than the bucket's revocation date (only if such a date has been set by the bucket owner).
Association Tokens
The association token specification is considered private, as it is mostly used for internal Gaia use cases. This means that this specification can change or become deprecated in the future.

Often times, a single user will use many different keys to store data. These keys may be generated on-the-fly. Instead of requiring the user to explicitly whitelist each key, the v1 authentication scheme allows the user to bind a key to an already-whitelisted key via an association token.

An association token is a JWT signed by a whitelisted key that, in turn, contains the public key that signs the authentication JWT that contains it. Put another way, the Gaia hub will accept a v1 authentication JWT if it contains an associationToken JWT that (1) was sigend by a whitelisted address, and (2) identifies the signer of the authentication JWT.

The association token JWT has the following structure in its payload:

{
'type': 'object',
'properties': {
'iss': { 'type': 'string' },
'exp': { 'type': 'IntDate' },
'iat': { 'type': 'IntDate' },
'childToAssociate': { 'type': 'string' },
'salt': { 'type': 'string' },
},
'required': [ 'iss', 'exp', 'childToAssociate' ]
}
Here, the iss field should be the public key of a whitelisted address. The childtoAssociate should be equal to the iss field of the authentication JWT. Note that the exp field is required in association tokens.

Legacy authentication scheme
In more detail, this signed message is:

BASE64({ "signature" : ECDSA_SIGN(SHA256(challenge-text)),
"publickey" : PUBLICKEY_HEX })
Currently, challenge-text must match the known challenge-text on the gaia storage hub. However, as future work enables more extensible forms of authentication, we could extend this to allow the auth token to include the challenge-text as well, which the gaia storage hub would then need to also validate.

Data storage format
A gaia storage hub will store the written data exactly as given. This means that the storage hub does not provide many different kinds of guarantees about the data. It does not ensure that data is validly formatted, contains valid signatures, or is encrypted. Rather, the design philosophy is that these concerns are client-side concerns. Client libraries (such as blockstack.js) are capable of providing these guarantees, and we use a liberal definition of the end-to-end principle to guide this design decision.

Operation of a Gaia Hub
Configuration files
A configuration JSON file should be stored either in the top-level directory of the hub server, or a file location may be specified in the environment variable CONFIG_PATH.

An example configuration file is provided in (./hub/config.sample.json) You can specify the logging level, the number of social proofs required for addresses to write to the system, the backend driver, the credentials for that backend driver, and the readURL for the storage provider.

Private hubs
A private hub services requests for a single user. This is controlled via whitelisting the addresses allowed to write files. In order to support application storage, because each application uses a different app- and user-specific address, each application you wish to use must be added to the whitelist separately.

Alternatively, the user's client must use the v1 authentication scheme and generate an association token for each app. The user should whitelist her address, and use her associated private key to sign each app's association token. This removes the need to whitelist each application, but with the caveat that the user needs to take care that her association tokens do not get misused.

Open-membership hubs
An open-membership hub will allow writes for any address top-level directory, each request will still be validated such that write requests must provide valid authentication tokens for that address. Operating in this mode is recommended for service and identity providers who wish to support many different users.

In order to limit the users that may interact with such a hub to users who provide social proofs of identity, we support an execution mode where the hub checks that a user's profile.json object contains social proofs in order to be able to write to other locations. This can be configured via the config.json.


[b]Driver model[/b]
Gaia hub drivers are fairly simple. The biggest requirement is the ability to fulfill the write-to/read-from URL guarantee. As currently implemented a gaia hub driver must implement the following two functions:

/**
* Performs the actual write of a file to `path`
* the file must be readable at `${getReadURLPrefix()}/${storageToplevel}/${path}`
*
* @param { String } options.path - path of the file.
* @param { String } options.storageToplevel - the top level directory to store the file in
* @param { String } options.contentType - the HTTP content-type of the file
* @param { stream.Readable } options.stream - the data to be stored at `path`
* @param { Integer } options.contentLength - the bytes of content in the stream
* @returns { Promise } that resolves to the public-readable URL of the stored content.
*/
performWrite (options: { path, storageToplevel, contentType,
stream, contentLength: Number })

/**
* Deletes a file. Throws a `DoesNotExist` if the file does not exist.
* @param { String } options.path - path of the file
* @param { String } options.storageToplevel - the top level directory
* @param { String } options.contentType - the HTTP content-type of the file
* @returns {Promise}
*/
performDelete (options: { path, storageToplevel })

/**
* Return the prefix for reading files from.
* a write to the path `foo` should be readable from
* `${getReadURLPrefix()}foo`
* @returns {String} the read url prefix.
*/
getReadURLPrefix ()

/**
* Return a list of files beginning with the given prefix,
* as well as a driver-specific page identifier for requesting
* the next page of entries. The return structure should
* take the form { "entries": [string], "page": string }
* @returns {Promise} the list of files and a page identifier.
*/
listFiles(prefix: string, page: string)
HTTP API
The Gaia storage API defines the following endpoints:

GET ${read-url-prefix}/${address}/${path}
This returns the data stored by the gaia hub at ${path}. In order for this to be usable from web applications, this read path must set the appropriate CORS headers. The HTTP Content-Type of the file should match the Content-Type of the corresponding write.

POST ${hubUrl}/store/${address}/${path}
This performs a write to the gaia hub at ${path}.

On success, it returns a 202 status, and a JSON object:

{
"publicUrl": "${read-url-prefix}/${address}/${path}"
}
The POST must contain an authentication header with a bearer token. The bearer token's content and generation is described in the access control section of this document.

Some backend storage drivers will return error 409 Conflict when a concurrent write to the same file path occurs. This can be handled with a retry. Other storage drivers tend to use last writer wins conflict resolution and will not throw an error.

DELETE ${hubUrl}/delete/${address}/${path}
This performs a deletion of a file in the gaia hub at ${path}.

On success, it returns a 202 status. Returns a 404 if the path does not exist. Returns 400 if the path is invalid.

The DELETE must contain an authentication header with a bearer token. The bearer token's content and generation is described in the access control section of this document.

GET ${hubUrl}/hub_info/
Returns a JSON object:

{
"challenge_text": "text-which-must-be-signed-to-validate-requests",
"read_url_prefix": "${read-url-prefix}"
"latest_auth_version": "v1"
}
The latest auth version allows the client to figure out which auth versions the gaia hub supports.

POST ${hubUrl}/revoke-all/${address}
The post body must be a JSON object with the following field:

{ "oldestValidTimestamp": "${timestamp}" }
Where the timestamp is an epoch time in seconds. The timestamp is written to a bucket-specific file (/${address}-auth). This becomes the oldest valid iat timestamp for authentication tokens that write to the /${address}/ bucket.

On success, it returns a 202 status, and a JSON object:

{ "status": "success" }
The POST must contain an authentication header with a bearer token. The bearer token's content and generation is described in the access control section of this document.

Future Design Goals
Dependency on DNS
The gaia specification requires that a gaia hub return a URL that a user's client will be able to fetch. In practice, most gaia hubs will use URLs with DNS entries for hostnames (though URLs with IP addresses would work as well). However, even though the spec uses URLs, that doesn't necessarily make an opinionated claim on underlying mechanisms for that URL. If a browser supported new URL schemes which enabled lookups without traditional DNS (for example, with the Blockstack Name System instead), then gaia hubs could return URLs implementing that scheme. As the Blockstack ecosystem develops and supports these kinds of features, we expect users would deploy gaia hubs that would take advantage.

Extensibly limiting membership sets
Some service providers may wish to provide hub services to a limited set of different users, with a provider-specific method of authenticating that a user or address is within that set. In order to provide that functionality, our hub implementation would need to be extensible enough to allow plugging in different authentication models.

A .storage Namespace
Gaia nodes can request data from other Gaia nodes, and can store data to other Gaia nodes. In effect, Gaia nodes can be "chained together" in arbitrarily complex ways. This creates an opportunity to create a decentralized storage marketplace.



[b]Example[/b]
For example, Alice can make her Gaia node public and program it to store data to her Amazon S3 bucket and her Dropbox account. Bob can then POST data to Alice's node, causing her node to replicate data to both providers. Later, Charlie can read Bob's data from Alice's node, causing Alice's node to fetch and serve back the data from her cloud storage. Neither Bob nor Charlie have to set up accounts on Amazon S3 and Dropbox this way, since Alice's node serves as an intermediary between them and the storage providers.

Since Alice is on the read/write path between Bob and Charlie and cloud storage, she has the opportunity to make optimizations. First, she can program her Gaia node to synchronously write data to local disk and asynchronously back it up to S3 and Dropbox. This would speed up Bob's writes, but at the cost of durability (i.e. Alice's node could crash before replicating to the cloud).

In addition, Alice can program her Gaia node to service all reads from disk. This would speed up Charlie's reads, since he'll get the latest data without having to hit back-end cloud storage providers.

[b]Service Description[/b]
Since Alice is providing a service to Bob and Charlie, she will want compensation. This can be achieved by having both of them send her money via the underlying blockchain.

To do so, she would register her node's IP address in a .storage namespace in Blockstack, and post her rates per gigabyte in her node's profile and her payment address. Once Bob and Charlie sent her payment, her node would begin accepting reads and writes from them up to the capacity purchased. They would continue sending payments as long as Alice provides them with service.

Other experienced Gaia node operators would register their nodes in .storage, and compete for users by offerring better durability, availability, performance, extra storage features, and so on.

Notes on our deployed service
Our deployed service places some modest limitations on file uploads and rate limits. Currently, the service will only allow up to 20 write requests per second and a maximum file size of 5MB. However, these limitations are only for our service, if you deploy your own Gaia hub, these limitations are not necessary.

Project Comparison
Here's how Gaia stacks up against other decentralized storage systems. Features that are common to all storage systems are omitted for brevity.