Contents

  • blocklet-sdk-node
    • Low level interface to manage blocklet usb devices; connect, manage keys, and perform raw crypto operations.
  • fabric-client
    • With fabric-ca-client below; a fork of the hyperledger fabric node client that supports blocklet usb devices
  • fabric-ca-client
    • A fork of the hyperledger certificate client to support fabric-client
  • ethereumjs-tx
    • A fork of the low level ethereum transaction library which supports blocklet usb devices
  • bigchaindb-driver
    • A fork of the bigchaindb client sdk which supports blocklet usb devices
  • devkit-ethereum
    • A simple script which uses blocklet usb to transact small amounts of ETH on the public testnet
  • devkit-bigchaindb
    • A simple script which uses blocklet usb to create assets on a BigchainDB ledger
  • devkit-fabric
    • A fork of the hyperledger fabric 'fabcar' app sample which uses blocklet usb to store all identities and issue transactions
  • devkit-iot
    • A daemon application which waits for a button press on a properly configured raspberry pi and publishes the pi's temperature to bigchaindb


Installation

The Raspberry Pis that came with your kit have already had these installation steps completed. If you would like to use the devkit on another developer machine, follow these steps.


Prerequisites

  • POSIX operating system preferred. Windows support is in Alpha
  • Node 10.13
  • build-essential (on linux) or comprable (for rebuilding native modules)
  • npm global installs configured for user, to avoid needing to use sudo. see option two here for instructions


Setup

Copy, via scp or similar, the blocklet-devkit-1.x.x.tgz file from the home directory of a devkit Raspberry Pi to the target machine, and then run

$ npm install -g blocklet-devkit-1.0.0.tgz
$ blocklet-devkit-install-demos


Installation will take several minutes, as several native dependencies are rebuilt to ensure compatibility with your system. This will install the demos onto your system with a devkit- prefix, and create a folder called blocklet-devkit-packages, the contents of which are listed above.


Demos

Blocklet DevKit comes with 4 demo CLI apps to showcase Blocklet USB devices interacting with three major blockchains.


Several demos depend on configuration via environment variables. Where possible, those variables have been preconfigued in the ~/.profile file on your devKit Raspberry Pis, and may be copied for use on a developer machine. Some demos require that you point to external services, and will require you to export some environment variables yourself. These will be highlighted within the appropriate section, but all configurable variables are listed for completeness.


BigchainDB

This demo creates a simple asset on a BigchainDB ledger according to a provided json payload.


Environment Variables

  • BIGCHAIN_CONNECTION_ENDPOINT - fully resolved url to a bigchainDB api, e.g. http://example.org:12345/api/v1/ (preconfigured on DevKit Raspberry Pis)
    • NOTE: don't forget the trailing slash
  • BIGCHAIN_X_ACCESS_TOKEN - the access token for your configured Bigchain Instance (preconfigured on DevKit Raspberry Pis)


Usage

$ echo '{"hello" : "world"}' > hello_world.json
$ devkit-bigchaindb-demo hello_world.json

# Outputs
getting connected blocklet usb device
ensuring bigchain key is available on blocklet device
have key info: { publicKey_bs58: '8tnsHaiwSPqdXWSBaWD43PrQUaDh3L6pWWtfWpuc42Qw',
  privateKey_bs58: '7d4u6Xg12Liu8J3Tbsyb7QZxBT5MMx6YYVtTV2Ffyc64',
  publicKey_buf:
   <Buffer 75 46 4a ae a4 57 ed d2 28 4e bf 38 7f f1 d6 63 16 d5 f0 6a dc fb 53 48 b6 2e 75 5a d6 ad 04 f8>,
  privateKey_buf:
   <Buffer 62 63 70 3a 36 38 63 64 66 38 37 30 3a 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31>,
  publicKey:
   <Buffer 75 46 4a ae a4 57 ed d2 28 4e bf 38 7f f1 d6 63 16 d5 f0 6a dc fb 53 48 b6 2e 75 5a d6 ad 04 f8>,
  bcp_buffer:
   <Buffer 62 63 70 3a 36 38 63 64 66 38 37 30 3a 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31>,
  uid: 'bf2cd5adc6d4986a77d89b131c186e30',
  keyFamily: 'bigchain',
  keyName: 'devkit-bcdb',
  algorithm: 'ed25519' }
preparing transaction for asset:
 { timestamp: 1541010304843, hello: 'world' }
signing transaction
transaction created:
 { id:
   'ea6affe680fa775705cca7fd1ceca85dd98dfb193d523d5eefe48427558c3b81',
  operation: 'CREATE',
  outputs:
   [ { condition: [Object], amount: '1', public_keys: [Array] } ],
  inputs:
   [ { fulfillment:
        'pGSAIHVGSq6kV-3SKE6_OH_x1mMW1fBq3PtTSLYudVrWrQT4gUDHO8IXNsedCU0l1YiwQuXE7Is_VIkS3l5AWe1tX0QXr5fuyGnfL_5-Im8wIPCokT-mIsxOHL1LIx_d5ljzKQ4B',
       fulfills: null,
       owners_before: [Array] } ],
  metadata: null,
  asset: { data: { timestamp: 1541010304843, hello: 'world' } },
  version: '2.0' }
posting transaction to http://dlt-lab-1:34138/api/v1/
asset created :  ea6affe680fa775705cca7fd1ceca85dd98dfb193d523d5eefe48427558c3b81


Ethereum

This demo transfers 0.0001 Ether, using the Blocklet USB Enclave as a hardware wallet.


Set Up

You must run one of two possible setup scripts and leave it running in another terminal window while you execute the demo. To demonstrate proper signing of ethereum transactions using blocklet-usb without external network access, use


$ devkit-ethereum-setup-local


To run against the public Rinkeby testnet, use


$ devkit-ethereum-setup-testnet


In either case, you will need a blocklet usb device plugged in, and will be prompted, after key generation, for which wallet address to associate with your local geth node.


Either of these scripts will eventually output a line like the following :


INFO [10-31|17:57:56.390] HTTP endpoint opened    url=http://10.3.2.195:8545  cors="\"http://10.3.2.195:8000\"" vhosts=localhost


Make note of your chosen wallet address and http://10.3.2.195:8545 above, you will need them in the next step.


NOTE: If using Rinkeby, you must allocate funds to your chosen wallet address with a faucet. Also note that the setup script will take several minutes to sync to the public chain.


Usage

devkit-ethereum-demo --to <wallet> <url>


You will be prompted again to choose a wallet to send from, make sure it is the same one you chose at setup. you can put anything you like as the --to parameter, but we suggest just transfering to yourself as a simple example.


If using the local setup script, you will recieve a confirmation message that the transaction has been accepted, but since mining cryptocurrency is outside the reasonable scope of a Raspberry PIs capability, the transaction will never be committed to a block.


If using the Rinkeby Test net, you will recieve confirmation, and then after several moments, a reciept:


The transaction got a valid hash and can be found at 0x61dd88eccc4588d7958f97b16c20b49b38315ddb83009be7b487e6a0434c9a32
The transaction has been confirmed: {
  "blockHash": "0xc2fa8f7e0db0c89a8a0c9ed696aeb4ffcfab852ef4e54c78dd81d8ddef230da7",
  "blockNumber": 3258898,
  "contractAddress": null,
  "cumulativeGasUsed": 1622090,
  "from": "0x78a3fed4241de7a199d5cfb796bf0a45abd013ca",
  "gasUsed": 21272,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": true,
  "to": "0x78a3fed4241de7a199d5cfb796bf0a45abd013ac",
  "transactionHash": "0x61dd88eccc4588d7958f97b16c20b49b38315ddb83009be7b487e6a0434c9a32",
  "transactionIndex": 13
}


You can then take the transaction hash above and explore using any online block explorer for the Rinkeby network, e.g https://rinkeby.etherscan.io/


Hyperledger Fabric

This demo lets you run a copy of the Hyperledger fabric car registration sample, using the Blocklet USB Enclave to manage administor and user keys.

Environment Variables

  • FABRIC_HOST - the hostname or ip of the network accessible machine running fabcar network (see setup below)


Setup

On a seperate machine with docker and docker-compose available, (running on the same network as your devkit machine):


$ git clone https://github.com/hyperledger/fabric-samples 
$ cd fabric-samples/fabcar
$ ./startFabric.sh


If all goes well, you will see:


...

Start by installing required packages run 'npm install'
Then run 'node enrollAdmin.js', then 'node registerUser'

The 'node invoke.js' will fail until it has been updated with valid arguments
The 'node query.js' may be run at anytime once the user has been registered


NOTE: you will not follow the instructions above, but rather use the corresponding devkit commands to utilize the network via blocklet usb device.


Usage

$ export FABRIC_HOST=<hostname/IP>
$ devkit-fabric-enrollAdmin 
$ devkit-fabric-registerUser
$ echo '["CAR13", "Honda", "Accord", "Black", "Tom"]' > car.json
$ devkit-fabric-invoke car.json
$ devkit-fabric-query


The last command above will query the fabric chain and end by returning a large json block which will contain your new entry for CAR13


IOT

This demo will start a long running process that waits for a button press on your Raspberry Pi case. When pressed, an attestation of the current CPU temperature (in Celsius) will be posted with a timestamp to BigchainDB.


Environment Variables

  • BIGCHAIN_CONNECTION_ENDPOINT - fully resolved url to a bigchainDB api, e.g. http://example.org:12345/api/v1/ (preconfigured on DevKit Raspberry Pis)
    • NOTE: don't forget the trailing slash
  • BIGCHAIN_X_ACCESS_TOKEN - the access token for your configured Bigchain Instance (preconfigured on DevKit Raspberry Pis)


Usage

$ devkit-iot