mirror of
https://github.com/bigchaindb/site.git
synced 2024-11-25 19:18:29 +01:00
require modules
This commit is contained in:
parent
0e6f3d1979
commit
bb71612b3f
@ -10,6 +10,7 @@ Then, include that as a module and connect to any BigchainDB node. You can creat
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const BigchainDB = require('bigchaindb-driver')
|
const BigchainDB = require('bigchaindb-driver')
|
||||||
|
const bip39 = require('bip39')
|
||||||
|
|
||||||
const API_PATH = 'https://test.bigchaindb.com/api/v1/'
|
const API_PATH = 'https://test.bigchaindb.com/api/v1/'
|
||||||
const conn = new BigchainDB.Connection(API_PATH, {
|
const conn = new BigchainDB.Connection(API_PATH, {
|
||||||
|
@ -44,6 +44,7 @@ So in our app, each object in the real world as the car, the telemetry box in th
|
|||||||
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.
|
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.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
const Orm = require('bigchaindb-orm')
|
||||||
|
|
||||||
class DID extends Orm {
|
class DID extends Orm {
|
||||||
constructor(entity) {
|
constructor(entity) {
|
||||||
|
@ -29,7 +29,7 @@ Let's create the app. You will create an asset for Admin type which will act as
|
|||||||
const nameSpace = 'rbac-bdb-tutorial'
|
const nameSpace = 'rbac-bdb-tutorial'
|
||||||
async function createApp(){
|
async function createApp(){
|
||||||
// Generate keypair for admin instance
|
// Generate keypair for admin instance
|
||||||
const admin1 = new driver.Ed25519Keypair()
|
const admin1 = new BigchainDB.Ed25519Keypair()
|
||||||
|
|
||||||
// Create admin user type. This is the asset representing the group of
|
// Create admin user type. This is the asset representing the group of
|
||||||
// admins
|
// admins
|
||||||
@ -67,20 +67,20 @@ The `createNewAsset` function looks like this
|
|||||||
```js
|
```js
|
||||||
async function createNewAsset(keypair, asset, metadata) {
|
async function createNewAsset(keypair, asset, metadata) {
|
||||||
|
|
||||||
let condition = driver.Transaction.makeEd25519Condition(keypair.publicKey,
|
let condition = BigchainDB.Transaction.makeEd25519Condition(keypair.publicKey,
|
||||||
true)
|
true)
|
||||||
|
|
||||||
let output = driver.Transaction.makeOutput(condition)
|
let output = BigchainDB.Transaction.makeOutput(condition)
|
||||||
output.public_keys = [keypair.publicKey]
|
output.public_keys = [keypair.publicKey]
|
||||||
|
|
||||||
const transaction = driver.Transaction.makeCreateTransaction(
|
const transaction = BigchainDB.Transaction.makeCreateTransaction(
|
||||||
asset,
|
asset,
|
||||||
metadata,
|
metadata,
|
||||||
[output],
|
[output],
|
||||||
keypair.publicKey
|
keypair.publicKey
|
||||||
)
|
)
|
||||||
|
|
||||||
const txSigned = driver.Transaction.signTransaction(transaction,
|
const txSigned = BigchainDB.Transaction.signTransaction(transaction,
|
||||||
keypair.privateKey)
|
keypair.privateKey)
|
||||||
let tx
|
let tx
|
||||||
await conn.postTransaction(txSigned)
|
await conn.postTransaction(txSigned)
|
||||||
@ -97,9 +97,9 @@ You have just generated the admin type and app asset, so now you are able to cre
|
|||||||
```js
|
```js
|
||||||
function createUsers() {
|
function createUsers() {
|
||||||
|
|
||||||
const user1 = new driver.Ed25519Keypair()
|
const user1 = new BigchainDB.Ed25519Keypair()
|
||||||
const user2 = new driver.Ed25519Keypair()
|
const user2 = new BigchainDB.Ed25519Keypair()
|
||||||
const user3 = new driver.Ed25519Keypair()
|
const user3 = new BigchainDB.Ed25519Keypair()
|
||||||
|
|
||||||
const adminuser1Metadata = {
|
const adminuser1Metadata = {
|
||||||
event: 'User Assigned',
|
event: 'User Assigned',
|
||||||
|
Loading…
Reference in New Issue
Block a user