An example of a simple blockchain app written entirely in JavaScript with Hyperledger Sawtooth. This app has the following functionalitites:
- Can add users and generate unique public-private keypairs for them.
- Allows users to add named (IoT) devices and generate unique bootstrapping parameters for each of them.
- Can make signed transfers of the devices between users.
- Can perform encrypted and signed transfer of bootstrapping parameters using ECIES
- Uses the transferred parameters to bootstrap the device
Different owners are designated by their public keys.
This repo includes a Transaction Processor which will can interface with a Sawtooth validator and handle validation of transactions, and a simple browser-based client which can manage public/private key-pairs and submit transactions to the Sawtooth REST API.
This project requires both Docker and Node/NPM. After installing, download this repo and run the following commands to install dependencies for the transaction processor:
cd {project directory}/processor
npm install
And these commands to install dependencies for and build the client:
cd {project directory}/client
npm install
npm run build
Use the included docker compose file to spin up some default Sawtooth components, including a validator and a REST API. Full instructions are available in the Sawtooth Documentation, but all you really need to know is, from the project directory, run this command to start Sawtooth up:
docker-compose up
And run this command to shut them down:
docker-compose down
Once running, you should be able to access the validator at
tcp://localhost:4004
and the REST API at http://localhost:8008
.
In a new terminal window, start up the transaction processor:
cd {project directory}/processor
npm start
Start the client simply by opening client/index.html
in any browser.
Users are just public/private key-pairs stored in localStorage. Create one from the "Select User" dropdown. You can use this same dropdown to switch between multiple users in localStorage.
Simply type in the name of your device under "Create device" and click the create button. If you selected a user, you should see that device appear in the list at the bottom.
Any device you own can be transferred to another public key using the dropdowns under "Transfer device". Note that the transfer must be accepted by that user before it is finalized.
Any pending transfers for the selected user will appear under "Accept device". These can be accepted (with an immediate change in ownership) or rejected with the corresponding buttons.
Once a device is accepted, its owner is authenticated and a bootstrapping connection is automatically established.