Various updates

This commit is contained in:
Ricardo Garcia 2018-01-12 19:07:14 +01:00 committed by GitHub
parent d2250e08bb
commit e17706e1ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 18 deletions

View File

@ -8,27 +8,25 @@ order: 2
learn: >
- How BigchainDB can be used to record dynamic parameters of an asset
- How assets can be used on BigchainDB to represent real objects
- How to make a `CREATE` transaction to digitally register an asset on BigchainDB
- How decentralized identifiers can represent objects in BigchainDB
- How asset metadata is updated by using `TRANSFER` transactions to change the state of an asset (the mileage of a car in our example)
---
Hi there! Welcome to our first tutorial! For this tutorial, we assume that you are familiar with the BigchainDB primitives (assets, inputs, outputs, transactions etc.). If you are not, familiarize yourself with [Key concepts of BigchainDB](../key-concepts-of-bigchaindb/).
Hi there! Welcome to our next tutorial! For this tutorial, we assume that you are familiar with the BigchainDB primitives (assets, inputs, outputs, transactions etc.). If you are not, familiarize yourself with [Key concepts of BigchainDB](../key-concepts-of-bigchaindb/). We also assume that you have completed our [first tutorial](../tutorial-car-telemetry-app/).
# About digital twins
We are moving towards an era where the Internet of Things is becoming real. Cars become more connected, devices equipped with sensors can communicate their data, and objects become smarter and smarter. This triggers the need for a digital representation of these devices to store their data in a safe location and to have a complete audit trail of their activity. This is the core idea of the digital twin of an object.
BigchainDB is an ideal solution to create digital twins of smart devices. In this tutorial, you will learn how to build a simple and basic version of a digital twin of your car, which allows its owner to store and update the mileage of the car.
BigchainDB is an ideal solution to create digital twins of smart devices. In this tutorial, you will learn how to build a simple and basic version of a digital twin of your car, which allows its owner to store and update the mileage of the car. The car contains a GPS tracker to submit the mileage and the car, as well as the GPS sensor will have their own identity.
Let's get started!
{% include_relative _setup.md %}
# Create a key pair
# Creation of a key pair
In BigchainDB, users are represented as a private and public key pair. In our case, a key pair for Alice will be created.
@ -40,8 +38,8 @@ const alice = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').s
# Decentralized Identifier Class
In order to create different assets in BigchainDB we will use the Decentralized Identifiers which are identifiers intended for verifiable digital identity that is "self-sovereign". They do not dependent on a centralized registry, identity provider, or certificate authority.(https://w3c-ccg.github.io/did-spec/)
So in this case, each object in the real world as the car, the telemetry box, the GPS device, etc, will be represented by a DID. Each object will have a a tag or cryptochip containing a securely hidden private key.
In telemetry applications, certain objects like in our case e.g. the car, need to have an identity to conduct actions in the system. Ideally, this identity is not controlled by anyone, such that the device can truly act autonomously. For these use cases, in BigchainDB we will use decentralized identifiers (DID) which are identifiers intended for verifiable digital identity that is "self-sovereign". They do not dependent on a centralized registry, identity provider, or certificate authority. You can learn more about it in our [DID specification](https://w3c-ccg.github.io/did-spec/).
So in our app, each object in the real world as the car, the telemetry box in the car, the GPS device, etc. will be represented by a DID. Each object will have a tag or cryptochip containing a securely hidden private key that serves as unique identity.
You will create a DID class that inherits from Orm BigchainDB driver, so DID objects will have all of the methods available in Orm. The `entity` represents the public key of the object itself.
@ -61,7 +59,7 @@ class DID extends Orm {
```
So as each object has a keypair, is possible to create a DID from each object. The objects are "self-sovereign", there is not a central authority that controls them, they will just have a user or another object that will have the ownership over them. As in Orm driver, a model is needed, the default one can be used for this tutorial
So as now each object has its own keypair, it is possible to create a DID from each object. The objects are thus "self-sovereign", there is not a central authority that controls them. They will just have a user or another object that will have the ownership over them. Because in our Orm driver, a model is needed, the default one can be used for this tutorial.
```js
const car = new driver.Ed25519Keypair()
@ -75,28 +73,28 @@ userDID.define("myModel", "https://schema.org/v1/myModel")
carDID.define("myModel", "https://schema.org/v1/myModel")
gpsDID.define("myModel", "https://schema.org/v1/myModel")
```
As you can see, every object or actor (alice, car, GPS sensor) has now it's own key pair and identity in our system.
# Digital registration of assets on BigchainDB
# Digital registration of an asset on BigchainDB
After having generated key pairs (and identities), you can now create the actual assets in BigchainDB. There will be three assets in our system: the car, the user and the GPS sensor. Therefore, as a first step you will create an asset representing each object. As decentralized identifiers are used, you can easily call the `create` method that each of them have and an asset will be created.
After having generated key pairs, you can create assets in BigchainDB. First you will create an asset representing each object. As Decentralized Identifiers are used, you can easily call the `create` method that each of them have and an asset will be created.
These assets will now live in BigchainDB forever and there is no possibility to delete them. This is the immutability property of blockchain technology.
These assets will live in BigchainDB forever and there is no possibility to delete it. This is the immutability property of blockchain technology.
You can start creating the car asset, so the first thing needed is the definition of the asset field that represents the car. It has a JSON format:
You can start by creating the car asset. The first thing needed is the definition of the asset field that represents the car. It has a JSON format:
```js
const vehicle = {
value: '6sd8f68sd67',
power: {
engine: '2.5',
cv: '220 cv',
hp: '220 hp',
}
consumption: '10.8 l',
}
```
As a next step, you need to generate a `CREATE` transaction that represents the user DID in BigchainDB. The user is a self-owned identity, so you will use Alice keypair to create the `userDID`
As a next step, you need to generate a `CREATE` transaction that represents the user DID in BigchainDB as an asset. The user is a self-owned identity, so you will use Alice's keypair to create the `userDID`.
```js
userDID.myModel.create({
@ -112,7 +110,7 @@ userDID.myModel.create({
})
```
As you can see, inheriting the Orm class is very easy to create an asset in BigchainDB. The only thing needed is the keypair and the asset.
As you can see, by inheriting the Orm class it is very easy to create an asset in BigchainDB. The only thing needed is the keypair and the asset.
The id property is set in the DID object. This is the unique identifier of this asset.
Now you can create the DID for the car. The owner of the car is Alice, and she is the one who can transfer this asset in the future, so the Alice keypair is needed to create this asset