1
0
mirror of https://github.com/bigchaindb/site.git synced 2024-11-22 01:36:55 +01:00

Merge pull request #260 from bigchaindb/feature/code-languages

Add more code example languages in guides
This commit is contained in:
Matthias Kretschmann 2018-09-04 12:28:36 +02:00 committed by GitHub
commit 3ab8520dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 6 deletions

View File

@ -1,16 +1,30 @@
# Setup
Start by installing the official [BigchainDB JavaScript driver](https://github.com/bigchaindb/js-bigchaindb-driver):
Start by installing the official BigchainDB [JavaScript driver](https://github.com/bigchaindb/js-bigchaindb-driver), [Python driver](https://github.com/bigchaindb/bigchaindb-driver) or [Java driver](https://github.com/bigchaindb/java-bigchaindb-driver):
```bash
# JavaScript driver
npm i bigchaindb-driver
```
```bash
# Python driver
pip install -U bigchaindb-driver
```
```xml
<!-- Java driver, in pom.xml for Maven users -->
<dependency>
<groupId>com.bigchaindb</groupId>
<artifactId>bigchaindb-driver</artifactId>
<version>1.0</version>
</dependency>
```
Then, include that as a module and connect to any BigchainDB node. You can create your own `app_id` and `app_key` on [BigchainDB Testnet](https://testnet.bigchaindb.com).
```js
const BigchainDB = require('bigchaindb-driver')
const bip39 = require('bip39')
const API_PATH = 'https://test.bigchaindb.com/api/v1/'
const conn = new BigchainDB.Connection(API_PATH, {
@ -18,3 +32,19 @@ const conn = new BigchainDB.Connection(API_PATH, {
app_key: 'Get one from testnet.bigchaindb.com'
})
```
```python
from bigchaindb_driver import BigchainDB
conn = BigchainDB(
'https://test.bigchaindb.com',
headers={'app_id': 'Get one from testnet.bigchaindb.com',
'app_key': 'Get one from testnet.bigchaindb.com'})
```
```java
BigchainDbConfigBuilder
.baseUrl("https://test.bigchaindb.com/")
.addToken("app_id", "Get one from testnet.bigchaindb.com")
.addToken("app_key","Get one from testnet.bigchaindb.com").setup();
```

View File

@ -33,7 +33,22 @@ In BigchainDB, users are represented as a private and public key pair. In our ca
For Alice, you can generate a key pair from a seed phrase using the BIP39 library, so you will just need to remember this particular seed phrase. The code below illustrates that.
```js
const alice = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').slice(0,32))
const bip39 = require('bip39')
const seed = bip39.mnemonicToSeed('seedPhrase').slice(0,32)
const alice = new BigchainDB.Ed25519Keypair(seed)
```
```python
from bigchaindb_driver.crypto import generate_keypair
alice = generate_keypair()
```
```java
net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
KeyPair alice = edDsaKpg.generateKeyPair();
```
# Decentralized Identifier Class

View File

@ -36,7 +36,22 @@ Before starting, you need to create a user in BigchainDB. In BigchainDB, users a
You can generate a key pair from a seed phrase using the BIP39 library, so you will just need to remember this particular seed phrase. The code below illustrates that.
```js
const alice = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').slice(0,32))
const bip39 = require('bip39')
const seed = bip39.mnemonicToSeed('seedPhrase').slice(0,32)
const alice = new BigchainDB.Ed25519Keypair(seed)
```
```python
from bigchaindb_driver.crypto import generate_keypair
alice = generate_keypair()
```
```java
net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
KeyPair alice = edDsaKpg.generateKeyPair();
```
# Digital registration of an asset on BigchainDB

View File

@ -14,6 +14,7 @@ learn: >
Hi there! Welcome to our next tutorial about Role-based access controls (RBAC) in BigchainDB. 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 the [Key concepts of BigchainDB](../key-concepts-of-bigchaindb/). We also assume that you have completed our [first tutorial](../tutorial-car-telemetry-app/).
# About RBAC
Role based access control is a way to restrict the system access to certain users. In BigchainDB this function enables the creation of hierarchies of role and permissions as assets. Furthermore, users can be assigned roles to “act on behalf of” or “represent” other users or groups.
In our example use-case scenario for this guide, we have different tribes or groups of users where they have different roles, users belonging to one tribe can create proposal assets and others can create vote assets on the BigchainDB blockchain.
@ -25,7 +26,6 @@ In our example use-case scenario for this guide, we have different tribes or gro
Let's create the app. You will create an asset for Admin type which will act as the admin group for the app. Async/await functions will be used in this tutorial
```js
const nameSpace = 'rbac-bdb-tutorial'
async function createApp(){
// Generate keypair for admin instance
@ -63,7 +63,8 @@ async function createApp(){
}
```
The `createNewAsset` function looks like this
The `createNewAsset` function looks like this:
```js
async function createNewAsset(keypair, asset, metadata) {