Compare commits
16 Commits
b3173978bd
...
b5c74a3336
Author | SHA1 | Date | |
---|---|---|---|
|
b5c74a3336 | ||
|
a639f284ea | ||
|
3b691766d0 | ||
|
f7d4af5d9c | ||
|
8e45793111 | ||
|
6cb6f67efb | ||
|
b4f10ebb9a | ||
|
c932010a0e | ||
|
87132fa2ff | ||
|
40ef14af6b | ||
|
6b06abc41c | ||
|
b144a208f8 | ||
|
a6aa09e555 | ||
|
a2161b8c46 | ||
|
a1c481cef4 | ||
|
c914473c5c |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.sol linguist-language=Solidity
|
236
.gitignore
vendored
Normal file
236
.gitignore
vendored
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
build
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
.temp
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
661
LICENSE
Normal file
661
LICENSE
Normal file
@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
3
build.sh
Normal file
3
build.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
truffle compile && truffle migrate --reset && cp build/contracts/DeviceManager.json frontend/src/artifacts/DeviceManager.json
|
319
contracts/DeviceManager.sol
Normal file
319
contracts/DeviceManager.sol
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
import "./MerkleProof.sol";
|
||||||
|
import "./ECRecovery.sol";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Provides base functionalities for entities.
|
||||||
|
*/
|
||||||
|
contract EntityBase {
|
||||||
|
/// @dev Entity in the device management system.
|
||||||
|
struct Entity {
|
||||||
|
// Arbitrary data in case entity wants to have some public information available.
|
||||||
|
string data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @notice Maps owner to an Entity structure.
|
||||||
|
mapping (address => Entity) public ownerToEntity;
|
||||||
|
|
||||||
|
/// @dev Fired on entity data update.
|
||||||
|
event EntityDataUpdated(address indexed owner, string newData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Update entity data.
|
||||||
|
* @param _data Entity data.
|
||||||
|
*/
|
||||||
|
function updateEntityData(string memory _data) public {
|
||||||
|
ownerToEntity[msg.sender].data = _data;
|
||||||
|
|
||||||
|
emit EntityDataUpdated(msg.sender, _data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Provides base functionalities for devices.
|
||||||
|
*/
|
||||||
|
contract DeviceBase {
|
||||||
|
/// @dev Main device structure.
|
||||||
|
struct Device {
|
||||||
|
// Ethereum address of a device owner.
|
||||||
|
address owner;
|
||||||
|
|
||||||
|
// Unique device identifier. Can hold anything that fits into 32 bytes. Different from device ID.
|
||||||
|
// Supposed to be a public key or a representation of one, such as fingerprint of RSA/ECC
|
||||||
|
// public key or simply an Ethereum address. To make identifier be an Ethereum address,
|
||||||
|
// use secp256k1 curve to generate public and private key pair, run keccak256 hash function
|
||||||
|
// on public key and take last 20 bytes of generated hash to get Ethereum address.
|
||||||
|
// If a device wants to be it's own entity, use same address as in owner property.
|
||||||
|
bytes32 identifier;
|
||||||
|
|
||||||
|
// Merkle root hash of metadata or simple hash of concatenated data.
|
||||||
|
// It is recommended to use Merkle tree to store information on device as it enables to
|
||||||
|
// prove membership of specific data by providing Merkle proof without revealing whole dataset.
|
||||||
|
bytes32 metadataHash;
|
||||||
|
|
||||||
|
// Holds a hash of actual firmware hash. Actual firmware hash is not supposed to be stored.
|
||||||
|
// Plain text or hash would expose data that is meant to be private, so "hash of hash" principle
|
||||||
|
// gives privacy and makes integrity verification possible.
|
||||||
|
bytes32 firmwareHash;
|
||||||
|
|
||||||
|
// Additional data linked to device. Can be used to store hash of encrypted firmware on IPFS.
|
||||||
|
//string offChainLink;
|
||||||
|
|
||||||
|
// Full public key (even though parties can exchange public key other ways then use
|
||||||
|
// blockchain to verify.)
|
||||||
|
//string publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @notice State variable for storing devices. Index in the array is also a device ID.
|
||||||
|
/// Array can hold a maximum of 2^256-1 entries.
|
||||||
|
Device[] public devices;
|
||||||
|
|
||||||
|
/// @notice Keeps track of total devices for each owner.
|
||||||
|
mapping (address => uint) public ownerDeviceCount;
|
||||||
|
|
||||||
|
/// @dev Fired on creation of new device.
|
||||||
|
event DeviceCreated(uint indexed deviceId, address indexed owner, bytes32 identifier, bytes32 metadataHash, bytes32 firmwareHash);
|
||||||
|
|
||||||
|
/// @dev Modifier for ensuring that the message sender is owner of provided device ID.
|
||||||
|
modifier onlyOwnerOf(uint _deviceId) {
|
||||||
|
require(devices[_deviceId].owner == msg.sender, "Only for device owner");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Creates and saves device into storage. Emits DeviceCreated.
|
||||||
|
* @param _identifier Unique device identifier, such as fingerprint of RSA/ECC public key or Ethereum address (recommended).
|
||||||
|
* @param _metadataHash Merkle root hash of metadata (recommended) or simple hash of concatenated metadata.
|
||||||
|
* @param _firmwareHash Hash of actual firmware hash.
|
||||||
|
* @return Created device ID.
|
||||||
|
*/
|
||||||
|
function createDevice(bytes32 _identifier, bytes32 _metadataHash, bytes32 _firmwareHash) public returns (uint) {
|
||||||
|
Device memory newDevice = Device(msg.sender, _identifier, _metadataHash, _firmwareHash);
|
||||||
|
uint deviceId = devices.push(newDevice) - 1;
|
||||||
|
ownerDeviceCount[msg.sender]++;
|
||||||
|
|
||||||
|
emit DeviceCreated(deviceId, msg.sender, _identifier, _metadataHash, _firmwareHash);
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Provides extra functionalities for devices.
|
||||||
|
*/
|
||||||
|
contract DeviceHelper is DeviceBase {
|
||||||
|
/**
|
||||||
|
* @notice Gets all devices owned by specified address.
|
||||||
|
* @dev Use this function instead of filtering DeviceCreated event since devices could have been transferred between owners.
|
||||||
|
* @param _owner Owner address.
|
||||||
|
* @return Array of device IDs.
|
||||||
|
*/
|
||||||
|
function getDevicesByOwner(address _owner) public view returns (uint[] memory) {
|
||||||
|
uint[] memory deviceIds = new uint[](ownerDeviceCount[_owner]);
|
||||||
|
uint counter = 0;
|
||||||
|
for (uint i = 0; i < devices.length; i++) {
|
||||||
|
if (devices[i].owner == _owner) {
|
||||||
|
deviceIds[counter] = i;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Checks if device is also an entity.
|
||||||
|
* @param _deviceId ID of a device.
|
||||||
|
* @return Boolean status.
|
||||||
|
*/
|
||||||
|
function isDeviceAnEntity(uint _deviceId) public view returns (bool) {
|
||||||
|
return devices[_deviceId].owner == address(uint160(uint256(devices[_deviceId].identifier)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Checks if provided leaf is a member of metadata contained in Merkle tree.
|
||||||
|
* Assumes that each pair of leaves and each pair of pre-images are sorted.
|
||||||
|
* @param _deviceId ID of a device containing metadata hash.
|
||||||
|
* @param _proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree.
|
||||||
|
* @param _leaf Leaf of Merkle tree.
|
||||||
|
* @return Boolean status.
|
||||||
|
*/
|
||||||
|
function isValidMetadataMember(uint _deviceId, bytes32[] memory _proof, bytes32 _leaf) public view returns (bool) {
|
||||||
|
return MerkleProof.verifyProof(_proof, devices[_deviceId].metadataHash, _leaf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Checks if provided firmware hash is equal to firmware hash device property.
|
||||||
|
* @param _deviceId ID of a device containing firmware hash.
|
||||||
|
* @param _firmwareHash Firmware hash (not the actual hash).
|
||||||
|
* @return Boolean status.
|
||||||
|
*/
|
||||||
|
function isValidFirmwareHash(uint _deviceId, bytes32 _firmwareHash) public view returns (bool) {
|
||||||
|
return devices[_deviceId].firmwareHash == _firmwareHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Validate authenticity of message signed by Etherium private key.
|
||||||
|
* On-chain validation is available only for Ethereum signed messages.
|
||||||
|
* @param _deviceId ID of a device that signed the message.
|
||||||
|
* @param _messageHash Hash of sent message.
|
||||||
|
* @param _signature Signature generated using web3.eth.sign().
|
||||||
|
* @return Boolean status.
|
||||||
|
*/
|
||||||
|
function isValidEthMessage(uint _deviceId, bytes32 _messageHash, bytes memory _signature) public view returns (bool) {
|
||||||
|
return ECRecovery.recover(_messageHash, _signature) == address(uint160(uint256(devices[_deviceId].identifier)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Provides base functionalities for signatures.
|
||||||
|
*/
|
||||||
|
contract SignatureBase {
|
||||||
|
/// @dev Main signature structure.
|
||||||
|
struct Signature {
|
||||||
|
// Ethereum address of the signer.
|
||||||
|
address signer;
|
||||||
|
|
||||||
|
// ID of device to sign.
|
||||||
|
uint deviceId;
|
||||||
|
|
||||||
|
// Using 256 bits ensures no overflow on year 2038 (Unix seconds).
|
||||||
|
uint expiryTime;
|
||||||
|
|
||||||
|
// Updates to true once signer decides to revoke signature.
|
||||||
|
bool revoked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @notice State variable for storing signatures. Index in the array is also a signature ID.
|
||||||
|
/// Array can hold a maximum of 2^256-1 entries.
|
||||||
|
Signature[] public signatures;
|
||||||
|
|
||||||
|
/// @notice Keeps track of total signatures for each device.
|
||||||
|
mapping (uint => uint) public deviceSignatureCount;
|
||||||
|
|
||||||
|
/// @dev Fired when an address signs a device.
|
||||||
|
event DeviceSigned(uint indexed signatureId, uint indexed deviceId, address indexed signer, uint expiryTime);
|
||||||
|
|
||||||
|
/// @dev Fired when signature is revoked.
|
||||||
|
event SignatureRevoked(uint indexed signatureId, uint indexed deviceId);
|
||||||
|
|
||||||
|
/// @dev Modifier for ensuring that the device hasn't been signed already.
|
||||||
|
modifier notSigned(uint _deviceId) {
|
||||||
|
require(deviceSignatureCount[_deviceId] == 0, "Must not be signed");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Signs a device and signature into storage. Emits DeviceSigned.
|
||||||
|
* @param _deviceId ID of to be signed device.
|
||||||
|
* @param _expiryTime Expiry time in Unix seconds.
|
||||||
|
* @return Created signature ID.
|
||||||
|
*/
|
||||||
|
function signDevice(uint _deviceId, uint _expiryTime) public returns (uint) {
|
||||||
|
Signature memory signature = Signature(msg.sender, _deviceId, _expiryTime, false);
|
||||||
|
uint signatureId = signatures.push(signature) - 1;
|
||||||
|
deviceSignatureCount[_deviceId]++;
|
||||||
|
|
||||||
|
emit DeviceSigned(signatureId, _deviceId, msg.sender, _expiryTime);
|
||||||
|
return signatureId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Revokes a signature. Emits SignatureRevoked.
|
||||||
|
* @param _signatureId ID of to be revoked signature.
|
||||||
|
*/
|
||||||
|
function revokeSignature(uint _signatureId) public {
|
||||||
|
require(signatures[_signatureId].signer == msg.sender, "Only for creator of the signature");
|
||||||
|
require(signatures[_signatureId].revoked == false, "Signature mustn't be revoked already");
|
||||||
|
Signature storage signature = signatures[_signatureId];
|
||||||
|
signature.revoked = true;
|
||||||
|
deviceSignatureCount[signature.deviceId]--;
|
||||||
|
|
||||||
|
emit SignatureRevoked(_signatureId, signature.deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Provides extra functionalities for signatures.
|
||||||
|
*/
|
||||||
|
contract SignatureHelper is SignatureBase {
|
||||||
|
/**
|
||||||
|
* @notice Gets all signatures for specific device.
|
||||||
|
* @dev Use this function instead of filtering DeviceSigned event since signatures could have been revoked.
|
||||||
|
* @param _deviceId ID of a device.
|
||||||
|
* @return Array of signature IDs.
|
||||||
|
*/
|
||||||
|
function getActiveSignaturesForDevice(uint _deviceId) public view returns (uint[] memory) {
|
||||||
|
uint[] memory signatureIds = new uint[](deviceSignatureCount[_deviceId]);
|
||||||
|
uint counter = 0;
|
||||||
|
for (uint i = 0; i < signatures.length; i++) {
|
||||||
|
if (signatures[i].deviceId == _deviceId && signatures[i].revoked == false) {
|
||||||
|
signatureIds[counter] = i;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return signatureIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Enriches devices giving them option to be updated only if not signed already.
|
||||||
|
*/
|
||||||
|
contract DeviceUpdatable is DeviceHelper, SignatureHelper {
|
||||||
|
/// @dev Fired on device ownership transfer, keeps track of historical device owners.
|
||||||
|
event DeviceTransfered(uint indexed deviceId, address oldOwner, address newOwner);
|
||||||
|
|
||||||
|
/// @dev Fired on device property update, keeps track of historical property values.
|
||||||
|
event DevicePropertyUpdated(uint indexed deviceId, bytes32 indexed property, bytes32 newValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Transfer device ownership from one external account to another. Emits DeviceTransfered.
|
||||||
|
* @param _deviceId ID of to be transferred device.
|
||||||
|
* @param _to Address of new owner.
|
||||||
|
*/
|
||||||
|
function transferDevice(uint _deviceId, address _to) public onlyOwnerOf(_deviceId) notSigned(_deviceId) {
|
||||||
|
address currentOwner = devices[_deviceId].owner;
|
||||||
|
devices[_deviceId].owner = _to;
|
||||||
|
ownerDeviceCount[msg.sender]--;
|
||||||
|
ownerDeviceCount[_to]++;
|
||||||
|
|
||||||
|
emit DeviceTransfered(_deviceId, currentOwner, _to);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Update device with new identifier. Emits DevicePropertyUpdated.
|
||||||
|
* @param _deviceId ID of a device.
|
||||||
|
* @param _newIdentifier New identifier.
|
||||||
|
*/
|
||||||
|
function updateIdentifier(uint _deviceId, bytes32 _newIdentifier) public onlyOwnerOf(_deviceId) notSigned(_deviceId) {
|
||||||
|
devices[_deviceId].identifier = _newIdentifier;
|
||||||
|
|
||||||
|
emit DevicePropertyUpdated(_deviceId, "identifier", _newIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Update device with new metadata hash. Emits DevicePropertyUpdated.
|
||||||
|
* @param _deviceId ID of a device.
|
||||||
|
* @param _newMetadataHash New metadata hash.
|
||||||
|
*/
|
||||||
|
function updateMetadataHash(uint _deviceId, bytes32 _newMetadataHash) public onlyOwnerOf(_deviceId) notSigned(_deviceId) {
|
||||||
|
devices[_deviceId].metadataHash = _newMetadataHash;
|
||||||
|
|
||||||
|
emit DevicePropertyUpdated(_deviceId, "metadata", _newMetadataHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notice Update device with new firmware hash. Emits DevicePropertyUpdated.
|
||||||
|
* @param _deviceId ID of a device.
|
||||||
|
* @param _newFirmwareHash New firmware hash.
|
||||||
|
*/
|
||||||
|
function updateFirmwareHash(uint _deviceId, bytes32 _newFirmwareHash) public onlyOwnerOf(_deviceId) notSigned(_deviceId) {
|
||||||
|
devices[_deviceId].firmwareHash = _newFirmwareHash;
|
||||||
|
|
||||||
|
emit DevicePropertyUpdated(_deviceId, "firmware", _newFirmwareHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @title Device manager core contract.
|
||||||
|
contract DeviceManager is EntityBase, DeviceUpdatable {
|
||||||
|
/// @dev Merges contracts.
|
||||||
|
}
|
68
contracts/ECRecovery.sol
Normal file
68
contracts/ECRecovery.sol
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Elliptic curve signature operations
|
||||||
|
* @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d
|
||||||
|
* TODO Remove this library once solidity supports passing a signature to ecrecover.
|
||||||
|
* See https://github.com/ethereum/solidity/issues/864
|
||||||
|
* Source: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ECRecovery.sol
|
||||||
|
*/
|
||||||
|
library ECRecovery {
|
||||||
|
/**
|
||||||
|
* @dev Recover signer address from a message by using their signature
|
||||||
|
* @param _hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
|
||||||
|
* @param _signature bytes signature, the signature is generated using web3.eth.sign()
|
||||||
|
*/
|
||||||
|
function recover(bytes32 _hash, bytes memory _signature)
|
||||||
|
internal
|
||||||
|
pure
|
||||||
|
returns (address)
|
||||||
|
{
|
||||||
|
bytes32 r;
|
||||||
|
bytes32 s;
|
||||||
|
uint8 v;
|
||||||
|
|
||||||
|
// Check the signature length
|
||||||
|
if (_signature.length != 65) {
|
||||||
|
return (address(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Divide the signature in r, s and v variables
|
||||||
|
// ecrecover takes the signature parameters, and the only way to get them
|
||||||
|
// currently is to use assembly.
|
||||||
|
// solium-disable-next-line security/no-inline-assembly
|
||||||
|
assembly {
|
||||||
|
r := mload(add(_signature, 32))
|
||||||
|
s := mload(add(_signature, 64))
|
||||||
|
v := byte(0, mload(add(_signature, 96)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions
|
||||||
|
if (v < 27) {
|
||||||
|
v += 27;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the version is correct return the signer address
|
||||||
|
if (v != 27 && v != 28) {
|
||||||
|
return (address(0));
|
||||||
|
} else {
|
||||||
|
// solium-disable-next-line arg-overflow
|
||||||
|
return ecrecover(_hash, v, r, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev prefix a bytes32 value with "\x19Ethereum Signed Message:" and hash the result
|
||||||
|
*/
|
||||||
|
function toEthSignedMessageHash(bytes32 _hash)
|
||||||
|
internal
|
||||||
|
pure
|
||||||
|
returns (bytes32)
|
||||||
|
{
|
||||||
|
// 32 is the length in bytes of hash,
|
||||||
|
// enforced by the type signature above
|
||||||
|
return keccak256(
|
||||||
|
abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
42
contracts/MerkleProof.sol
Normal file
42
contracts/MerkleProof.sol
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title MerkleProof
|
||||||
|
* @dev Merkle proof verification based on https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol
|
||||||
|
* Source: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/MerkleProof.sol
|
||||||
|
*/
|
||||||
|
library MerkleProof {
|
||||||
|
/**
|
||||||
|
* @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves
|
||||||
|
* and each pair of pre-images are sorted.
|
||||||
|
* @param _proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree
|
||||||
|
* @param _root Merkle root
|
||||||
|
* @param _leaf Leaf of Merkle tree
|
||||||
|
*/
|
||||||
|
function verifyProof(
|
||||||
|
bytes32[] memory _proof,
|
||||||
|
bytes32 _root,
|
||||||
|
bytes32 _leaf
|
||||||
|
)
|
||||||
|
internal
|
||||||
|
pure
|
||||||
|
returns (bool)
|
||||||
|
{
|
||||||
|
bytes32 computedHash = _leaf;
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < _proof.length; i++) {
|
||||||
|
bytes32 proofElement = _proof[i];
|
||||||
|
|
||||||
|
if (computedHash < proofElement) {
|
||||||
|
// Hash(current computed hash + current element of the proof)
|
||||||
|
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
|
||||||
|
} else {
|
||||||
|
// Hash(current element of the proof + current computed hash)
|
||||||
|
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the computed hash (root) is equal to the provided root
|
||||||
|
return computedHash == _root;
|
||||||
|
}
|
||||||
|
}
|
23
contracts/Migrations.sol
Normal file
23
contracts/Migrations.sol
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
contract Migrations {
|
||||||
|
address public owner;
|
||||||
|
uint public last_completed_migration;
|
||||||
|
|
||||||
|
constructor() public {
|
||||||
|
owner = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier restricted() {
|
||||||
|
if (msg.sender == owner) _;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCompleted(uint completed) public restricted {
|
||||||
|
last_completed_migration = completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function upgrade(address new_address) public restricted {
|
||||||
|
Migrations upgraded = Migrations(new_address);
|
||||||
|
upgraded.setCompleted(last_completed_migration);
|
||||||
|
}
|
||||||
|
}
|
21
frontend/.gitignore
vendored
Normal file
21
frontend/.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
2444
frontend/README.md
Normal file
2444
frontend/README.md
Normal file
File diff suppressed because it is too large
Load Diff
19227
frontend/package-lock.json
generated
Normal file
19227
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
frontend/package.json
Normal file
25
frontend/package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"antd": "3.8.1",
|
||||||
|
"elliptic": "6.4.1",
|
||||||
|
"ethereumjs-util": "5.2.0",
|
||||||
|
"ethereumjs-wallet": "0.6.2",
|
||||||
|
"merkle-tree-solidity": "1.0.8",
|
||||||
|
"react": "16.4.2",
|
||||||
|
"react-dom": "16.4.2",
|
||||||
|
"react-router-dom": "4.3.1",
|
||||||
|
"react-scripts": "1.1.4",
|
||||||
|
"secp256k1": "^4.0.3",
|
||||||
|
"truffle-contract": "3.0.6",
|
||||||
|
"web3": "0.20.6"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test --env=jsdom",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
}
|
||||||
|
}
|
BIN
frontend/public/favicon.ico
Normal file
BIN
frontend/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
40
frontend/public/index.html
Normal file
40
frontend/public/index.html
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<meta name="theme-color" content="#000000">
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is added to the
|
||||||
|
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||||
|
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>IoT Device Management</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
You need to enable JavaScript to run this app.
|
||||||
|
</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
15
frontend/public/manifest.json
Normal file
15
frontend/public/manifest.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"short_name": "IoT Device Management",
|
||||||
|
"name": "IoT Device Management",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": "./index.html",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#000000",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
9
frontend/src/App.css
Normal file
9
frontend/src/App.css
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
@import '~antd/dist/antd.css';
|
||||||
|
|
||||||
|
.loading-spin {
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding: 30px 50px;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
190
frontend/src/App.js
Normal file
190
frontend/src/App.js
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
import getWeb3 from './utils/web3';
|
||||||
|
import DeviceManager from './DeviceManager';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
|
import Home from './components/Home';
|
||||||
|
import RegisterDevice from './components/RegisterDevice';
|
||||||
|
import ManageDevices from './components/ManageDevices';
|
||||||
|
import EditEntity from './components/EditEntity';
|
||||||
|
import LookupEntity from './components/LookupEntity';
|
||||||
|
import ManageDevice from './components/ManageDevice';
|
||||||
|
import LookupDevice from './components/LookupDevice';
|
||||||
|
import CheckSignature from './components/CheckSignature';
|
||||||
|
|
||||||
|
import { Layout, Menu, Icon, Tag, Alert, Spin } from 'antd';
|
||||||
|
|
||||||
|
const { SubMenu } = Menu;
|
||||||
|
const { Header, Content, Footer, Sider } = Layout;
|
||||||
|
|
||||||
|
class App extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
web3: null,
|
||||||
|
deviceManagerInstance: null,
|
||||||
|
errorMessage: '',
|
||||||
|
loading: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount() {
|
||||||
|
getWeb3.then(results => {
|
||||||
|
this.setState({
|
||||||
|
web3: results.web3,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Using address: ${this.state.web3.eth.accounts[0]}`);
|
||||||
|
|
||||||
|
return DeviceManager.then(instance => {
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
deviceManagerInstance: instance
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Contract address: ${instance.address}`);
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
this.setState({
|
||||||
|
errorMessage: error.message,
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
let errorMessage = 'Error finding web3. Please install MetaMask.';
|
||||||
|
console.log(errorMessage);
|
||||||
|
this.setState({
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mainContent() {
|
||||||
|
if (!this.state.loading) {
|
||||||
|
let childComponent;
|
||||||
|
|
||||||
|
if (this.state.web3 == null || this.state.deviceManagerInstance == null) {
|
||||||
|
childComponent = <div>
|
||||||
|
<h1>Resolve the following issues to continue</h1>
|
||||||
|
<Alert
|
||||||
|
message="Error"
|
||||||
|
description={this.state.errorMessage}
|
||||||
|
type="error"
|
||||||
|
showIcon
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
} else {
|
||||||
|
childComponent = <div>
|
||||||
|
<Route exact path="/" component={Home} />
|
||||||
|
<Route path="/edit-entity" component={EditEntity} />
|
||||||
|
<Route path="/lookup-entity/:address?" component={LookupEntity} />
|
||||||
|
<Route path="/register-device" component={RegisterDevice} />
|
||||||
|
<Route path="/manage-devices" component={ManageDevices} />
|
||||||
|
<Route path="/manage-device/:deviceId" component={ManageDevice} />
|
||||||
|
<Route path="/lookup-device" component={LookupDevice} />
|
||||||
|
<Route path="/check-signature/:signatureId" component={CheckSignature} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{childComponent}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
let statusTag;
|
||||||
|
|
||||||
|
if (this.state.web3 == null) {
|
||||||
|
statusTag = <Tag color="red">Web3 missing</Tag>;
|
||||||
|
} else if (this.state.deviceManagerInstance == null) {
|
||||||
|
statusTag = <Tag color="red">Network error</Tag>;
|
||||||
|
} else {
|
||||||
|
statusTag = <Tag color="green">OK</Tag>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Router>
|
||||||
|
<Layout style={{ height: "100vh" }}>
|
||||||
|
<Header className="header">
|
||||||
|
<Menu
|
||||||
|
theme="dark"
|
||||||
|
mode="horizontal"
|
||||||
|
defaultSelectedKeys={['1']}
|
||||||
|
style={{ lineHeight: '64px' }}
|
||||||
|
>
|
||||||
|
<Menu.Item key="1">
|
||||||
|
<Link to="/" className="nav-text">IoT Device Management</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
<Menu.Item key="2" style={{ float: 'right' }}>
|
||||||
|
Status: {statusTag}
|
||||||
|
</Menu.Item>
|
||||||
|
</Menu>
|
||||||
|
</Header>
|
||||||
|
<Content style={{ padding: '24px 50px' }}>
|
||||||
|
<Layout style={{ padding: '24px 0', background: '#fff' }}>
|
||||||
|
<Sider width={200} style={{ background: '#fff' }}>
|
||||||
|
<Menu
|
||||||
|
mode="inline"
|
||||||
|
defaultSelectedKeys={['']}
|
||||||
|
defaultOpenKeys={['sub1', 'sub2', 'sub3']}
|
||||||
|
style={{ height: '100%' }}
|
||||||
|
>
|
||||||
|
<SubMenu key="sub1" title={<span><Icon type="user" />Entities</span>}>
|
||||||
|
<Menu.Item key="1">
|
||||||
|
<Link to="/edit-entity" className="nav-text">Edit</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
<Menu.Item key="2">
|
||||||
|
<Link to="/lookup-entity" className="nav-text">Lookup</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
</SubMenu>
|
||||||
|
<SubMenu key="sub2" title={<span><Icon type="laptop" />Devices</span>}>
|
||||||
|
<Menu.Item key="3">
|
||||||
|
<Link to="/register-device" className="nav-text">Register</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
<Menu.Item key="4">
|
||||||
|
<Link to="/manage-devices" className="nav-text">Manage</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
<Menu.Item key="5">
|
||||||
|
<Link to="/lookup-device" className="nav-text">Lookup</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
{/*
|
||||||
|
<Menu.Item key="5">
|
||||||
|
<Link to="#" className="nav-text">Filter</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
*/}
|
||||||
|
</SubMenu>
|
||||||
|
{/*
|
||||||
|
<SubMenu key="sub3" title={<span><Icon type="form" />Signatures</span>}>
|
||||||
|
|
||||||
|
<Menu.Item key="6">
|
||||||
|
<Link to="#" className="nav-text">Sign</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
<Menu.Item key="7">
|
||||||
|
<Link to="/check-signature" className="nav-text">Check</Link>
|
||||||
|
</Menu.Item>
|
||||||
|
</SubMenu>
|
||||||
|
*/}
|
||||||
|
</Menu>
|
||||||
|
</Sider>
|
||||||
|
<Content style={{ padding: '0 24px', minHeight: 400 }}>
|
||||||
|
<Spin spinning={this.state.loading} className="loading-spin">
|
||||||
|
{this.mainContent()}
|
||||||
|
</Spin>
|
||||||
|
</Content>
|
||||||
|
</Layout>
|
||||||
|
</Content>
|
||||||
|
<Footer style={{ textAlign: 'center' }}>
|
||||||
|
IoT Device Management © 2024 物联网大作业
|
||||||
|
</Footer>
|
||||||
|
</Layout>
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
28
frontend/src/DeviceManager.js
Normal file
28
frontend/src/DeviceManager.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import getWeb3 from './utils/web3';
|
||||||
|
import TruffleContract from 'truffle-contract';
|
||||||
|
import DeviceManagerArtifact from './artifacts/DeviceManager.json';
|
||||||
|
|
||||||
|
let web3;
|
||||||
|
let DeviceManager = new Promise(function (resolve, reject) {
|
||||||
|
getWeb3.then(results => {
|
||||||
|
web3 = results.web3;
|
||||||
|
|
||||||
|
const deviceManager = TruffleContract(DeviceManagerArtifact);
|
||||||
|
deviceManager.setProvider(web3.currentProvider);
|
||||||
|
|
||||||
|
return deviceManager.deployed().then(instance => {
|
||||||
|
console.log('Initiating DeviceManager instance...');
|
||||||
|
resolve(instance);
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export function getDefaultAccount() {
|
||||||
|
return web3.eth.accounts[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DeviceManager;
|
18100
frontend/src/artifacts/DeviceManager.json
Normal file
18100
frontend/src/artifacts/DeviceManager.json
Normal file
File diff suppressed because one or more lines are too long
99
frontend/src/components/CheckSignature.js
Normal file
99
frontend/src/components/CheckSignature.js
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import getWeb3 from '../utils/web3';
|
||||||
|
import DeviceManager from '../DeviceManager';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { Tag, Divider, Spin, Alert } from 'antd';
|
||||||
|
|
||||||
|
class CheckSignature extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
signatureId: this.props.match.params.signatureId,
|
||||||
|
loading: true,
|
||||||
|
showError: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps({ match }) {
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
showError: false,
|
||||||
|
signatureId: match.params.signatureId
|
||||||
|
}, () => this.updateSignatureData());
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount() {
|
||||||
|
try {
|
||||||
|
let web3 = (await getWeb3).web3;
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
web3,
|
||||||
|
instance
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.updateSignatureData();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
//message.error(error.message);
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
showError: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateSignatureData() {
|
||||||
|
try {
|
||||||
|
const { instance, signatureId } = this.state;
|
||||||
|
let signature = await instance.signatures(signatureId);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
signer: signature[0],
|
||||||
|
deviceId: signature[1].toNumber(),
|
||||||
|
expiryTime: signature[2].toNumber(),
|
||||||
|
revoked: signature[3],
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
//message.error(error.message);
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
showError: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { loading, showError, signer, deviceId, expiryTime, revoked } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Spin spinning={loading} className="loading-spin">
|
||||||
|
{loading === false && showError === false &&
|
||||||
|
<div>
|
||||||
|
<h3><div style={{ marginBottom: '20px' }}>Signature created by {signer} </div></h3>
|
||||||
|
<Divider />
|
||||||
|
<div style={{ marginBottom: '20px' }}>For device with <Link to={"/manage-device/" + deviceId}><Tag>ID {deviceId}</Tag></Link></div>
|
||||||
|
<div style={{ marginBottom: '20px' }}>Expires on {new Date(expiryTime * 1000).toString()} </div>
|
||||||
|
{revoked === true ? <div style={{ marginBottom: '20px' }}><strong>This signature has been revoked!</strong> </div> : <div></div>}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{loading === false && showError &&
|
||||||
|
<Alert
|
||||||
|
message="Error"
|
||||||
|
description="Error loading signature: invalid ID format or signature doesn't exist."
|
||||||
|
type="error"
|
||||||
|
showIcon
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</Spin >
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CheckSignature;
|
135
frontend/src/components/EditEntity.js
Normal file
135
frontend/src/components/EditEntity.js
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
import getWeb3 from '../utils/web3';
|
||||||
|
import DeviceManager, { getDefaultAccount } from '../DeviceManager';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { Card, Input, Button, Icon, message, notification } from 'antd';
|
||||||
|
|
||||||
|
const { TextArea } = Input;
|
||||||
|
|
||||||
|
const openNotificationWithIcon = (type, message, description) => {
|
||||||
|
notification[type]({
|
||||||
|
message,
|
||||||
|
description
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
class EditEntity extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
myData: null,
|
||||||
|
showEdit: false,
|
||||||
|
web3: null,
|
||||||
|
instance: null,
|
||||||
|
loading: true,
|
||||||
|
filter: null
|
||||||
|
}
|
||||||
|
|
||||||
|
this.toggleEdit = this.toggleEdit.bind(this);
|
||||||
|
this.commonChange = this.commonChange.bind(this);
|
||||||
|
this.saveMyData = this.saveMyData.bind(this);
|
||||||
|
this.updateMyData = this.updateMyData.bind(this);
|
||||||
|
this.watchForChanges = this.watchForChanges.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount() {
|
||||||
|
try {
|
||||||
|
let results = await getWeb3;
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
web3: results.web3,
|
||||||
|
instance
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.updateMyData();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watchForChanges() {
|
||||||
|
let filter = this.state.web3.eth.filter('latest', (error, result) => {
|
||||||
|
if (!error) {
|
||||||
|
openNotificationWithIcon('success', 'Transaction mined', 'Your entity data has been updated.');
|
||||||
|
this.state.filter.stopWatching();
|
||||||
|
this.updateMyData();
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
filter
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateMyData() {
|
||||||
|
try {
|
||||||
|
let result = await this.state.instance.ownerToEntity(getDefaultAccount());
|
||||||
|
this.setState({
|
||||||
|
myData: result,
|
||||||
|
myDataNew: result,
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleEdit() {
|
||||||
|
this.setState(prevState => ({
|
||||||
|
showEdit: !prevState.showEdit
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
commonChange(e) {
|
||||||
|
this.setState({
|
||||||
|
[e.target.name]: e.target.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveMyData() {
|
||||||
|
try {
|
||||||
|
if (this.state.myDataNew !== this.state.myData) {
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
await instance.updateEntityData(this.state.myDataNew, { from: getDefaultAccount() });
|
||||||
|
this.watchForChanges();
|
||||||
|
openNotificationWithIcon('info', 'Transaction sent', 'Once mined, your entity data will be updated.');
|
||||||
|
this.setState({
|
||||||
|
loading: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.toggleEdit();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Edit your entity details.
|
||||||
|
</p>
|
||||||
|
<Card style={{ maxWidth: '500px' }} loading={this.state.loading} title={getDefaultAccount()}>
|
||||||
|
{this.state.showEdit ?
|
||||||
|
<div>
|
||||||
|
<TextArea name="myDataNew" value={this.state.myDataNew} onChange={this.commonChange} />
|
||||||
|
<Button type="primary" style={{ marginTop: '10px' }} onClick={this.saveMyData}>Save</Button>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<p>{this.state.myData || <em>empty data</em>} <a><Icon type="edit" onClick={this.toggleEdit} /></a></p>
|
||||||
|
}
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditEntity;
|
13
frontend/src/components/Home.js
Normal file
13
frontend/src/components/Home.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
class Home extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Using blockchain for registration and control of IoT devices.
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Home;
|
56
frontend/src/components/LookupDevice.js
Normal file
56
frontend/src/components/LookupDevice.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import ManageDevice from './ManageDevice';
|
||||||
|
|
||||||
|
import { Input, Divider } from 'antd';
|
||||||
|
|
||||||
|
const { Search } = Input;
|
||||||
|
|
||||||
|
class LookupDevice extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
match: {
|
||||||
|
params: {
|
||||||
|
deviceId: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
searched: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lookupDevice(value) {
|
||||||
|
this.setState({
|
||||||
|
match: {
|
||||||
|
params: {
|
||||||
|
deviceId: value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
searched: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Search for any device.
|
||||||
|
</p>
|
||||||
|
<Search
|
||||||
|
placeholder="Device ID"
|
||||||
|
onSearch={value => this.lookupDevice(value)}
|
||||||
|
size="large"
|
||||||
|
enterButton
|
||||||
|
/>
|
||||||
|
{this.state.searched &&
|
||||||
|
<div>
|
||||||
|
<Divider />
|
||||||
|
<ManageDevice match={this.state.match} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LookupDevice;
|
121
frontend/src/components/LookupEntity.js
Normal file
121
frontend/src/components/LookupEntity.js
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
import DeviceManager, { getDefaultAccount } from '../DeviceManager';
|
||||||
|
import ethUtil from 'ethereumjs-util';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { Button, Tag, Card, Input, Divider, Timeline, message } from 'antd';
|
||||||
|
|
||||||
|
const Search = Input.Search;
|
||||||
|
|
||||||
|
const eventsToSave = ['EntityDataUpdated', 'DeviceCreated', 'DeviceTransfered', 'DeviceSigned'];
|
||||||
|
|
||||||
|
class LookupEntity extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
loading: false,
|
||||||
|
searchValue: '',
|
||||||
|
address: this.props.match.params.address,
|
||||||
|
data: [],
|
||||||
|
searched: false
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lookupEntity = this.lookupEntity.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
const { address } = this.state;
|
||||||
|
if (address != null) {
|
||||||
|
this.reloadWithAddress(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadWithAddress(address) {
|
||||||
|
this.setState({
|
||||||
|
searchValue: address
|
||||||
|
})
|
||||||
|
this.lookupEntity(address).then(() => { });
|
||||||
|
}
|
||||||
|
|
||||||
|
async lookupEntity(address) {
|
||||||
|
if (!ethUtil.isValidAddress(address)) {
|
||||||
|
message.error('Invalid entity address.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
loading: true
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
|
||||||
|
let allEvents = instance.allEvents({ fromBlock: 0, toBlock: 'latest' });
|
||||||
|
allEvents.get((error, logs) => {
|
||||||
|
let filteredData = logs.filter(el => eventsToSave.includes(el.event) && (el.args.owner === address || el.args.oldOwner === address || el.args.newOwner === address || el.args.signer === address));
|
||||||
|
if (!error) {
|
||||||
|
this.setState({
|
||||||
|
address: address,
|
||||||
|
data: filteredData,
|
||||||
|
loading: false,
|
||||||
|
searched: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Search for any entity.
|
||||||
|
</p>
|
||||||
|
<Search
|
||||||
|
placeholder="Input address"
|
||||||
|
onSearch={value => this.lookupEntity(value)}
|
||||||
|
size="large"
|
||||||
|
enterButton
|
||||||
|
value={this.state.searchValue}
|
||||||
|
onChange={(e) => this.setState({ searchValue: e.target.value })}
|
||||||
|
/>
|
||||||
|
<br /><br />
|
||||||
|
<Button size="small" onClick={() => this.setState({ searchValue: getDefaultAccount() })}>Set to my address</Button>
|
||||||
|
{this.state.searched &&
|
||||||
|
<div>
|
||||||
|
<Divider />
|
||||||
|
<Card loading={this.state.loading} title={'Historical events for entity (oldest to newest)'}>
|
||||||
|
{this.state.data.length !== 0 ?
|
||||||
|
<div>
|
||||||
|
<p style={{ marginBottom: '20px' }}>Events that are filtered are {eventsToSave.join(', ')} </p>
|
||||||
|
<Timeline style={{ marginTop: '10px' }}>
|
||||||
|
{this.state.data.map(el => {
|
||||||
|
if (el.event === 'EntityDataUpdated')
|
||||||
|
return <Timeline.Item>Entity data updated to <code>{el.args.newData}</code></Timeline.Item>
|
||||||
|
if (el.event === 'DeviceCreated')
|
||||||
|
return <Timeline.Item color='green'>Created device with <Link to={"/manage-device/" + el.args.deviceId.toNumber()}><Tag>ID {el.args.deviceId.toNumber()}</Tag></Link>, identifier <code>{el.args.identifier}</code>, metadata hash <code>{el.args.metadataHash}</code> and firmware hash <code>{el.args.firmwareHash}</code></Timeline.Item>
|
||||||
|
if (el.event === 'DeviceTransfered')
|
||||||
|
return <Timeline.Item color='orange'>Device with <Link to={"/manage-device/" + el.args.deviceId.toNumber()}><Tag>ID {el.args.deviceId.toNumber()}</Tag></Link>transfered {el.args.newOwner === this.state.address && <span>from <Tag onClick={() => this.reloadWithAddress(el.args.oldOwner)}>{el.args.oldOwner}</Tag></span>}{el.args.oldOwner === this.state.address && <span>to <Tag onClick={() => this.reloadWithAddress(el.args.newOwner)}>{el.args.newOwner}</Tag></span>}</Timeline.Item>
|
||||||
|
if (el.event === 'DeviceSigned')
|
||||||
|
return <Timeline.Item color='purple'>Signed device with <Link to={"/manage-device/" + el.args.deviceId.toNumber()}><Tag>ID {el.args.deviceId.toNumber()}</Tag></Link></Timeline.Item>
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
})}
|
||||||
|
</Timeline>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<p><em>empty</em></p>
|
||||||
|
}
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LookupEntity;
|
357
frontend/src/components/ManageDevice.js
Normal file
357
frontend/src/components/ManageDevice.js
Normal file
@ -0,0 +1,357 @@
|
|||||||
|
import getWeb3 from '../utils/web3';
|
||||||
|
import DeviceManager, { getDefaultAccount } from '../DeviceManager';
|
||||||
|
import { addHexPrefix } from 'ethereumjs-util';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { Tag, Button, Input, Card, Timeline, Divider, Spin, Alert, Icon, notification, message } from 'antd';
|
||||||
|
|
||||||
|
const openNotificationWithIcon = (type, message, description) => {
|
||||||
|
notification[type]({
|
||||||
|
message,
|
||||||
|
description
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const eventsToSave = ['DeviceCreated', 'DevicePropertyUpdated', 'DeviceTransfered', 'DeviceSigned', 'SignatureRevoked'];
|
||||||
|
|
||||||
|
class ManageDevice extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
deviceId: this.props.match.params.deviceId,
|
||||||
|
loading: true,
|
||||||
|
showError: false,
|
||||||
|
showEditIdentifier: false,
|
||||||
|
showEditMetadata: false,
|
||||||
|
showEditFirmware: false,
|
||||||
|
showEditOwner: false
|
||||||
|
}
|
||||||
|
|
||||||
|
this.commonChange = this.commonChange.bind(this);
|
||||||
|
this.watchForChanges = this.watchForChanges.bind(this);
|
||||||
|
this.updateDeviceData = this.updateDeviceData.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps({ match }) {
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
showError: false,
|
||||||
|
deviceId: match.params.deviceId
|
||||||
|
}, () => this.updateDeviceData());
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount() {
|
||||||
|
try {
|
||||||
|
let web3 = (await getWeb3).web3;
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
web3,
|
||||||
|
instance
|
||||||
|
});
|
||||||
|
|
||||||
|
this.updateDeviceData();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
//message.error(error.message);
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
showError: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateDeviceData() {
|
||||||
|
try {
|
||||||
|
const { instance, deviceId } = this.state;
|
||||||
|
let device = await instance.devices(deviceId);
|
||||||
|
let signatureCount = await instance.deviceSignatureCount(deviceId);
|
||||||
|
let allEvents = instance.allEvents({ fromBlock: 0, toBlock: 'latest' });
|
||||||
|
allEvents.get((error, logs) => {
|
||||||
|
let filteredData = logs.filter(el => eventsToSave.includes(el.event) && el.args.deviceId.toNumber() === parseInt(deviceId, 10));
|
||||||
|
if (!error) {
|
||||||
|
this.setState({
|
||||||
|
data: filteredData,
|
||||||
|
loading: false,
|
||||||
|
owner: device[0],
|
||||||
|
identifier: device[1],
|
||||||
|
metadataHash: device[2],
|
||||||
|
firmwareHash: device[3],
|
||||||
|
signatureCount: signatureCount.toNumber()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let { identifier, metadataHash, firmwareHash, owner } = this.state;
|
||||||
|
this.setState({
|
||||||
|
identifierNew: identifier,
|
||||||
|
metadataHashNew: metadataHash,
|
||||||
|
firmwareHashNew: firmwareHash,
|
||||||
|
ownerNew: owner
|
||||||
|
})
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
//message.error(error.message);
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
showError: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleEdit(property) {
|
||||||
|
const { showEditFirmware, showEditIdentifier, showEditMetadata, showEditOwner } = this.state;
|
||||||
|
|
||||||
|
switch (property) {
|
||||||
|
case 'identifier':
|
||||||
|
this.setState({
|
||||||
|
showEditIdentifier: !showEditIdentifier
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case 'metadata':
|
||||||
|
this.setState({
|
||||||
|
showEditMetadata: !showEditMetadata
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case 'firmware':
|
||||||
|
this.setState({
|
||||||
|
showEditFirmware: !showEditFirmware
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case 'transfer':
|
||||||
|
this.setState({
|
||||||
|
showEditOwner: !showEditOwner
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watchForChanges(property) {
|
||||||
|
let filter = this.state.web3.eth.filter('latest', (error, result) => {
|
||||||
|
if (!error) {
|
||||||
|
openNotificationWithIcon('success', 'Transaction mined', `Property ${property} has been updated.`);
|
||||||
|
this.state.filter.stopWatching();
|
||||||
|
this.updateDeviceData();
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
filter
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveData(property) {
|
||||||
|
const { instance, deviceId, identifier, identifierNew, metadataHash, metadataHashNew, firmwareHash, firmwareHashNew, owner, ownerNew } = this.state;
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (property) {
|
||||||
|
case 'identifier':
|
||||||
|
if (identifier !== identifierNew) {
|
||||||
|
await instance.updateIdentifier(deviceId, addHexPrefix(identifierNew), { from: getDefaultAccount() });
|
||||||
|
this.watchForChanges(property);
|
||||||
|
openNotificationWithIcon('info', 'Transaction sent', 'Once mined, identifier for this device will be updated.');
|
||||||
|
this.setState({
|
||||||
|
loading: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'metadata':
|
||||||
|
if (metadataHash !== metadataHashNew) {
|
||||||
|
await instance.updateMetadataHash(deviceId, addHexPrefix(metadataHashNew), { from: getDefaultAccount() });
|
||||||
|
this.watchForChanges(property + ' hash');
|
||||||
|
openNotificationWithIcon('info', 'Transaction sent', 'Once mined, metadata hash for this device will be updated.');
|
||||||
|
this.setState({
|
||||||
|
loading: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'firmware':
|
||||||
|
if (firmwareHash !== firmwareHashNew) {
|
||||||
|
await instance.updateFirmwareHash(deviceId, addHexPrefix(firmwareHashNew), { from: getDefaultAccount() });
|
||||||
|
this.watchForChanges(property + ' hash');
|
||||||
|
openNotificationWithIcon('info', 'Transaction sent', 'Once mined, firmware hash for this device will be updated.');
|
||||||
|
this.setState({
|
||||||
|
loading: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'transfer':
|
||||||
|
if (owner !== ownerNew) {
|
||||||
|
await instance.transferDevice(deviceId, addHexPrefix(ownerNew), { from: getDefaultAccount() });
|
||||||
|
this.watchForChanges('owner');
|
||||||
|
openNotificationWithIcon('info', 'Transaction sent', 'Once mined, owner for this device will be updated.');
|
||||||
|
this.setState({
|
||||||
|
loading: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
this.toggleEdit(property);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
this.toggleEdit(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
commonChange(e) {
|
||||||
|
this.setState({
|
||||||
|
[e.target.name]: e.target.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { web3, loading, showError, owner, identifier, metadataHash, firmwareHash, signatureCount, showEditFirmware, showEditIdentifier, showEditMetadata, showEditOwner } = this.state;
|
||||||
|
|
||||||
|
let identifierContent = () => {
|
||||||
|
if (showEditIdentifier) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Input name="identifierNew" value={this.state.identifierNew} onChange={this.commonChange} maxLength="66" />
|
||||||
|
<Button type="primary" style={{ marginTop: '10px' }} onClick={() => this.saveData('identifier')}>Save</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Identifier {identifier}
|
||||||
|
{owner === getDefaultAccount() &&
|
||||||
|
<a><Icon type="edit" onClick={() => this.toggleEdit('identifier')} /></a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let metadataContent = () => {
|
||||||
|
if (showEditMetadata) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Input name="metadataHashNew" value={this.state.metadataHashNew} onChange={this.commonChange} maxLength="66" />
|
||||||
|
<Button type="primary" style={{ marginTop: '10px' }} onClick={() => this.saveData('metadata')}>Save</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Metadata hash {metadataHash.length > 0 ? metadataHash : 'empty'}
|
||||||
|
{owner === getDefaultAccount() &&
|
||||||
|
<a><Icon type="edit" onClick={() => this.toggleEdit('metadata')} /></a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let firmwareContent = () => {
|
||||||
|
if (showEditFirmware) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Input name="firmwareHashNew" value={this.state.firmwareHashNew} onChange={this.commonChange} maxLength="66" />
|
||||||
|
<Button type="primary" style={{ marginTop: '10px' }} onClick={() => this.saveData('firmware')}>Save</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Firmware hash {firmwareHash.length > 0 ? firmwareHash : 'empty'}
|
||||||
|
{owner === getDefaultAccount() &&
|
||||||
|
<a><Icon type="edit" onClick={() => this.toggleEdit('firmware')} /></a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let transferContent = () => {
|
||||||
|
if (showEditOwner) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Input name="ownerNew" value={this.state.ownerNew} onChange={this.commonChange} maxLength="66" />
|
||||||
|
<Button type="primary" style={{ marginTop: '10px' }} onClick={() => this.saveData('transfer')}>Save</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{owner === getDefaultAccount() &&
|
||||||
|
<Button type="dashed" onClick={() => this.toggleEdit('transfer')}> Transfer ownership</Button>
|
||||||
|
}
|
||||||
|
{owner !== getDefaultAccount() &&
|
||||||
|
<div>
|
||||||
|
Owned by <Link to={"/lookup-entity/" + owner}><Tag>{owner}</Tag></Link>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Spin spinning={loading} className="loading-spin">
|
||||||
|
{loading === false && showError === false && typeof metadataHash !== 'undefined' &&
|
||||||
|
<div>
|
||||||
|
<h3><div style={{ marginBottom: '20px' }}>{identifierContent()}</div></h3>
|
||||||
|
<Divider />
|
||||||
|
<div style={{ marginBottom: '20px' }}>{metadataContent()}</div>
|
||||||
|
<div style={{ marginBottom: '20px' }}>{firmwareContent()}</div>
|
||||||
|
{transferContent()}
|
||||||
|
<Divider />
|
||||||
|
{signatureCount > 0 &&
|
||||||
|
<div>
|
||||||
|
<div>This device has <strong>{signatureCount}</strong> active signature(s). Devices that have been signed can't be updated.</div>
|
||||||
|
<Divider />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<Card title={'Historical events for device (oldest to newest)'}>
|
||||||
|
{this.state.data.length !== 0 ?
|
||||||
|
<div>
|
||||||
|
<p style={{ marginBottom: '20px' }}>Events that are filtered are {eventsToSave.join(', ')} </p>
|
||||||
|
<Timeline style={{ marginTop: '10px' }}>
|
||||||
|
{this.state.data.map(el => {
|
||||||
|
if (el.event === 'DeviceCreated')
|
||||||
|
return <Timeline.Item color='green'>Device created by <Link to={"/lookup-entity/" + el.args.owner}><Tag>{el.args.owner}</Tag></Link>with <Link to={"/manage-device/" + el.args.deviceId.toNumber()}><Tag>ID {el.args.deviceId.toNumber()}</Tag></Link>, identifier <code>{el.args.identifier}</code>, metadata hash <code>{el.args.metadataHash}</code> and firmware hash <code>{el.args.firmwareHash}</code></Timeline.Item>
|
||||||
|
if (el.event === 'DevicePropertyUpdated')
|
||||||
|
return <Timeline.Item>Property {web3.toUtf8(el.args.property)} updated to <code>{el.args.newValue}</code></Timeline.Item>
|
||||||
|
if (el.event === 'DeviceTransfered')
|
||||||
|
return <Timeline.Item color='orange'>Device transfered to <Link to={"/lookup-entity/" + el.args.newOwner}><Tag>{el.args.newOwner}</Tag></Link></Timeline.Item>
|
||||||
|
if (el.event === 'DeviceSigned')
|
||||||
|
return <Timeline.Item color='purple'>Signature with <Link to={"/check-signature/" + el.args.signatureId.toNumber()}><Tag>ID {el.args.signatureId.toNumber()}</Tag></Link>created by {el.args.signer}</Timeline.Item>
|
||||||
|
if (el.event === 'SignatureRevoked')
|
||||||
|
return <Timeline.Item color='purple'>Signature with <Link to={"/check-signature/" + el.args.signatureId.toNumber()}><Tag>ID {el.args.signatureId.toNumber()}</Tag></Link>revoked</Timeline.Item>
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
})}
|
||||||
|
</Timeline>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<p><em>empty</em></p>
|
||||||
|
}
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{/*
|
||||||
|
{loading === false && owner !== getDefaultAccount() &&
|
||||||
|
<Alert message="You don't own this device." type="error" showIcon />
|
||||||
|
}
|
||||||
|
*/}
|
||||||
|
{loading === false && showError &&
|
||||||
|
<Alert
|
||||||
|
message="Error"
|
||||||
|
description="Error loading device: invalid ID format or device doesn't exist."
|
||||||
|
type="error"
|
||||||
|
showIcon
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</Spin >
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ManageDevice;
|
78
frontend/src/components/ManageDevices.js
Normal file
78
frontend/src/components/ManageDevices.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import DeviceManager, { getDefaultAccount } from '../DeviceManager';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { Spin, List, message } from 'antd';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
class ManageDevices extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
loading: true,
|
||||||
|
instance: null,
|
||||||
|
devices: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidMount() {
|
||||||
|
try {
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
let deviceIds = (await instance.getDevicesByOwner(getDefaultAccount())).map(el => el.toNumber());
|
||||||
|
|
||||||
|
let devicePromises = [];
|
||||||
|
for (let deviceId of deviceIds) {
|
||||||
|
let devicePromise = instance.devices(deviceId);
|
||||||
|
devicePromises.push(devicePromise);
|
||||||
|
}
|
||||||
|
|
||||||
|
let devices = await Promise.all(devicePromises);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
instance,
|
||||||
|
devices,
|
||||||
|
deviceIds,
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { devices, loading } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Spin spinning={loading} className="loading-spin">
|
||||||
|
{devices.length > 0 && !loading &&
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Below you can find your devices. Click to see more details and manage.
|
||||||
|
</p>
|
||||||
|
<List
|
||||||
|
bordered={true}
|
||||||
|
itemLayout="horizontal"
|
||||||
|
dataSource={devices}
|
||||||
|
renderItem={(device, index) => (
|
||||||
|
<List.Item>
|
||||||
|
<List.Item.Meta
|
||||||
|
/*avatar={<Icon type="profile" style={{ fontSize: 36 }} />}*/
|
||||||
|
title={<Link to={`/manage-device/${this.state.deviceIds[index]}`}>{`Device ID ${this.state.deviceIds[index]}`}</Link>}
|
||||||
|
description={`Identifier ${device[1]}`}
|
||||||
|
/>
|
||||||
|
</List.Item>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{devices.length === 0 && !loading &&
|
||||||
|
<p>You don't have any devices registered.</p>
|
||||||
|
}
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ManageDevices;
|
28
frontend/src/components/RegisterDevice.css
Normal file
28
frontend/src/components/RegisterDevice.css
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
.steps-content {
|
||||||
|
margin-top: 16px;
|
||||||
|
border: 1px dashed #e9e9e9;
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: #fafafa;
|
||||||
|
padding: 80px 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.steps-action {
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynamic-delete-button {
|
||||||
|
cursor: pointer;
|
||||||
|
position: relative;
|
||||||
|
top: 4px;
|
||||||
|
font-size: 24px;
|
||||||
|
color: #999;
|
||||||
|
transition: all .3s;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
.dynamic-delete-button:hover {
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
.dynamic-delete-button[disabled] {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
526
frontend/src/components/RegisterDevice.js
Normal file
526
frontend/src/components/RegisterDevice.js
Normal file
@ -0,0 +1,526 @@
|
|||||||
|
import getWeb3 from '../utils/web3';
|
||||||
|
import DeviceManager, { getDefaultAccount } from '../DeviceManager';
|
||||||
|
|
||||||
|
import elliptic from 'elliptic';
|
||||||
|
import ethWallet from 'ethereumjs-wallet';
|
||||||
|
import { sha3, addHexPrefix, setLengthLeft } from 'ethereumjs-util';
|
||||||
|
import { merkleRoot } from 'merkle-tree-solidity';
|
||||||
|
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import './RegisterDevice.css';
|
||||||
|
|
||||||
|
import { Steps, Button, Input, Card, Spin, Alert, Divider, Form, Icon, Dropdown, Menu, message, notification } from 'antd';
|
||||||
|
|
||||||
|
const Step = Steps.Step;
|
||||||
|
const { Meta } = Card;
|
||||||
|
const EC = elliptic.ec;
|
||||||
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
const steps = [{
|
||||||
|
title: 'Identifier',
|
||||||
|
}, {
|
||||||
|
title: 'Metadata',
|
||||||
|
}, {
|
||||||
|
title: 'Firmware',
|
||||||
|
}, {
|
||||||
|
title: 'Confirm',
|
||||||
|
}];
|
||||||
|
|
||||||
|
const openNotificationWithIcon = (type, message, description) => {
|
||||||
|
notification[type]({
|
||||||
|
message,
|
||||||
|
description
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
class RegisterDevice extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = this.getInitialState();
|
||||||
|
}
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
current: 0,
|
||||||
|
identifier: '',
|
||||||
|
metadataHash: '',
|
||||||
|
firmwareHash: '',
|
||||||
|
showIdentifierInfo: false,
|
||||||
|
publicKey: '',
|
||||||
|
privateKey: '',
|
||||||
|
address: '',
|
||||||
|
metadata: [{ value: '' }],
|
||||||
|
firmware: '',
|
||||||
|
curve: '',
|
||||||
|
deviceId: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.setState(this.getInitialState());
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount() {
|
||||||
|
try {
|
||||||
|
let results = await getWeb3;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
web3: results.web3,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async watchForChanges(txHash) {
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
let deviceCreatedEvent = instance.DeviceCreated()
|
||||||
|
|
||||||
|
deviceCreatedEvent.watch((error, result) => {
|
||||||
|
if (!error) {
|
||||||
|
if (result.transactionHash === txHash) {
|
||||||
|
openNotificationWithIcon('success', 'Transaction mined', 'Your device has been registered.');
|
||||||
|
this.state.deviceCreatedEvent.stopWatching();
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
deviceId: result.args.deviceId.toNumber()
|
||||||
|
})
|
||||||
|
this.next();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
deviceCreatedEvent
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
next() {
|
||||||
|
const { current, identifier/*, metadataHash, firmwareHash*/ } = this.state;
|
||||||
|
|
||||||
|
if ((current === 0) && (identifier === null || identifier === '')) {
|
||||||
|
message.error('Invalid identifier: can\'t be empty');
|
||||||
|
//} else if ((current === 1) && (metadataHash === null || metadataHash === '')) {
|
||||||
|
// message.error('Invalid metadata hash.');
|
||||||
|
//} else if ((current === 2) && (firmwareHash === null || firmwareHash === '')) {
|
||||||
|
// message.error('Invalid firmware hash.');
|
||||||
|
} else {
|
||||||
|
this.setState(prevState => ({ current: prevState.current + 1 }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev() {
|
||||||
|
const current = this.state.current - 1;
|
||||||
|
this.setState({ current });
|
||||||
|
}
|
||||||
|
|
||||||
|
gotoStep(i) {
|
||||||
|
this.setState({ current: i });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChange(e) {
|
||||||
|
this.setState({
|
||||||
|
[e.target.name]: e.target.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.state.current === 0) {
|
||||||
|
this.setState({
|
||||||
|
showIdentifierInfo: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.current === 0 && e.target.name === 'identifier') {
|
||||||
|
this.setState({
|
||||||
|
showIdentifierInfo: false,
|
||||||
|
publicKey: '',
|
||||||
|
privateKey: '',
|
||||||
|
address: '',
|
||||||
|
curve: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.current === 1 && e.target.name === 'metadataHash') {
|
||||||
|
this.setState({
|
||||||
|
metadata: [{ value: '' }]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.current === 2 && e.target.name === 'firmwareHash') {
|
||||||
|
this.setState({
|
||||||
|
firmware: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateEthWallet() {
|
||||||
|
console.log(`Generating new Ethereum wallet`);
|
||||||
|
const newWallet = ethWallet.generate();
|
||||||
|
|
||||||
|
let publicKey = newWallet.getPublicKey().toString('hex');
|
||||||
|
let privateKey = newWallet.getPrivateKey().toString('hex');
|
||||||
|
let address = newWallet.getAddressString();
|
||||||
|
|
||||||
|
console.log(`Private key: ${privateKey}`);
|
||||||
|
console.log(`Public key: ${publicKey}`);
|
||||||
|
console.log(`Address: ${address}`);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
identifier: address,
|
||||||
|
showIdentifierInfo: true,
|
||||||
|
address,
|
||||||
|
publicKey,
|
||||||
|
privateKey,
|
||||||
|
curve: 'secp256k1'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
generateEcKeyPair(curve) {
|
||||||
|
let ec = new EC(curve);
|
||||||
|
console.log(`Generating new ${curve} key pair`);
|
||||||
|
let keyPair = ec.genKeyPair();
|
||||||
|
|
||||||
|
let publicKey = keyPair.getPublic(true, 'hex');
|
||||||
|
let privateKey = keyPair.getPrivate('hex');
|
||||||
|
|
||||||
|
console.log(`Private key: ${privateKey}`);
|
||||||
|
console.log(`Public key compressed: ${publicKey}`);
|
||||||
|
console.log(`Public key uncompressed: ${keyPair.getPublic().encode('hex')}`);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
identifier: publicKey,
|
||||||
|
showIdentifierInfo: true,
|
||||||
|
address: '',
|
||||||
|
publicKey,
|
||||||
|
privateKey,
|
||||||
|
curve
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateMetadataHash() {
|
||||||
|
let elements = this.state.metadata.map(el => sha3(el.value));
|
||||||
|
console.log(`Generating Merkle root hash`);
|
||||||
|
|
||||||
|
let metadataRootSha3 = merkleRoot(elements);
|
||||||
|
console.log(`Merkle root hash ${metadataRootSha3.toString('hex')}`);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
metadataHash: metadataRootSha3.toString('hex')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateFirmwareHash() {
|
||||||
|
let firmwareHash = sha3(this.state.firmware);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
firmwareHash: firmwareHash.toString('hex')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
removeMetadataField(k) {
|
||||||
|
const { metadata } = this.state;
|
||||||
|
metadata.splice(k, 1);
|
||||||
|
this.setState({
|
||||||
|
metadata
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
addMetadataField() {
|
||||||
|
const { metadata } = this.state;
|
||||||
|
metadata.push({ value: '' });
|
||||||
|
this.setState({
|
||||||
|
metadata
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMetadataChange(e, index) {
|
||||||
|
const { metadata } = this.state;
|
||||||
|
metadata[index].value = e.target.value;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
metadata
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadConfiguration() {
|
||||||
|
const { identifier, metadataHash, firmwareHash, metadata, firmware, address, publicKey, privateKey, curve, deviceId } = this.state;
|
||||||
|
|
||||||
|
const configuration = {
|
||||||
|
identifier,
|
||||||
|
metadataHash,
|
||||||
|
firmwareHash,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (metadata.length > 0 && metadata[0].value !== '' && metadataHash !== '') {
|
||||||
|
configuration.metadata = metadata.map(el => el.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firmware !== '' && firmwareHash !== '') {
|
||||||
|
configuration.firmware = firmware;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (address !== '') {
|
||||||
|
configuration.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (publicKey !== '') {
|
||||||
|
configuration.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (privateKey !== '') {
|
||||||
|
configuration.privateKey = privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curve !== '') {
|
||||||
|
configuration.curve = curve;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceId !== '') {
|
||||||
|
configuration.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
let configurationJson = JSON.stringify(configuration);
|
||||||
|
|
||||||
|
let element = document.createElement("a");
|
||||||
|
let file = new Blob([configurationJson], { type: 'text/json' });
|
||||||
|
element.href = URL.createObjectURL(file);
|
||||||
|
element.download = `device_${deviceId}.json`;
|
||||||
|
element.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
onCurveSelect({ key }) {
|
||||||
|
this.generateEcKeyPair(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
getContentForStep(step) {
|
||||||
|
const { identifier, metadataHash, firmwareHash, metadata, firmware } = this.state;
|
||||||
|
|
||||||
|
// Identifier
|
||||||
|
if (step === 0) {
|
||||||
|
const curves = ['p224', 'curve25519'];
|
||||||
|
const ecMenu = (
|
||||||
|
<Menu onClick={(e) => this.onCurveSelect(e)}>
|
||||||
|
{curves.map(curve => <Menu.Item key={curve}>{curve}</Menu.Item>)}
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<strong>Unique device identifier</strong> is a public key or a fingerprint of RSA/ECC public key. It can also be an Ethereum address (recommended).
|
||||||
|
</p>
|
||||||
|
<Input
|
||||||
|
placeholder="Identifier e.g. Ethereum address"
|
||||||
|
style={{ maxWidth: '800px' }}
|
||||||
|
value={identifier}
|
||||||
|
name="identifier"
|
||||||
|
maxLength="66"
|
||||||
|
onChange={(e) => this.handleChange(e)}
|
||||||
|
/>
|
||||||
|
<br /><br />
|
||||||
|
<Button.Group size="large">
|
||||||
|
<Button type="primary" onClick={() => this.generateEthWallet()}>Generate Ethereum wallet</Button>
|
||||||
|
<Dropdown overlay={ecMenu}>
|
||||||
|
<Button type="primary">
|
||||||
|
Generate elliptic curve key pair
|
||||||
|
</Button>
|
||||||
|
</Dropdown>
|
||||||
|
</Button.Group>
|
||||||
|
{this.state.showIdentifierInfo ?
|
||||||
|
<div>
|
||||||
|
<br />
|
||||||
|
<Alert message="You will be given private key and device configuration on the last step." type="info" showIcon />
|
||||||
|
</div> : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metadata hash
|
||||||
|
if (step === 1) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<strong>Metadash hash</strong> is Merkle root hash of device information or just a hash of any data.
|
||||||
|
</p>
|
||||||
|
<Input
|
||||||
|
placeholder="Metadata hash"
|
||||||
|
style={{ maxWidth: '800px' }}
|
||||||
|
value={metadataHash}
|
||||||
|
name="metadataHash"
|
||||||
|
maxLength="66"
|
||||||
|
onChange={(e) => this.handleChange(e)}
|
||||||
|
/>
|
||||||
|
<Divider />
|
||||||
|
<p>
|
||||||
|
If you already don't have one, you can use inputs below to generate SHA-3 (Keccak) hash. With multiple fields, Merkle tree will be used.
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<Form>
|
||||||
|
{metadata.map((key, index) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<Input
|
||||||
|
placeholder="Some information"
|
||||||
|
style={{ width: '60%' }}
|
||||||
|
value={key.value}
|
||||||
|
maxLength="66"
|
||||||
|
onChange={(e) => this.handleMetadataChange(e, index)}
|
||||||
|
/>
|
||||||
|
{metadata.length > 1 ? (
|
||||||
|
<Icon
|
||||||
|
className="dynamic-delete-button"
|
||||||
|
type="minus-circle-o"
|
||||||
|
disabled={metadata.length === 1}
|
||||||
|
onClick={() => this.removeMetadataField(index)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</FormItem>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
<FormItem>
|
||||||
|
<Button type="dashed" onClick={() => this.addMetadataField()} style={{ width: '60%' }}>
|
||||||
|
<Icon type="plus" /> Add field
|
||||||
|
</Button>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem>
|
||||||
|
<Button type="primary" onClick={() => this.calculateMetadataHash()}>Generate</Button>
|
||||||
|
</FormItem>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Firmware hash
|
||||||
|
if (step === 2) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<strong>Firmware hash</strong> is a hash of actual firmware hash. Actual firmware hash is not supposed to be stored.
|
||||||
|
</p>
|
||||||
|
<Input
|
||||||
|
placeholder="Firmware hash"
|
||||||
|
style={{ maxWidth: '800px' }}
|
||||||
|
value={firmwareHash}
|
||||||
|
name="firmwareHash"
|
||||||
|
maxLength="66"
|
||||||
|
onChange={(e) => this.handleChange(e)}
|
||||||
|
/>
|
||||||
|
<Divider />
|
||||||
|
<p>
|
||||||
|
You can use input to generate SHA-3 (Keccak) hash of any data.
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<Input
|
||||||
|
placeholder="Some data"
|
||||||
|
style={{ width: '60%' }}
|
||||||
|
value={firmware}
|
||||||
|
name="firmware"
|
||||||
|
onChange={(e) => this.handleChange(e)}
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<Button type="primary" onClick={() => this.calculateFirmwareHash()}>Generate</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overview/confirm
|
||||||
|
if (step === 3) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Card title={<div>Identifier {identifier} <a><Icon type="edit" onClick={() => this.gotoStep(0)} /></a></div>} bordered={false}>
|
||||||
|
<Meta
|
||||||
|
title={<div>Metadata hash {metadataHash.length > 0 ? metadataHash : 'empty'} <a><Icon type="edit" onClick={() => this.gotoStep(1)} /></a></div>}
|
||||||
|
description={<div>Firmware hash {firmwareHash.length > 0 ? firmwareHash : 'empty'} <a><Icon type="edit" onClick={() => this.gotoStep(2)} /></a></div>}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
if (step === 4) {
|
||||||
|
return (
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<Icon type="check-circle-o" style={{ fontSize: 46 }} />
|
||||||
|
<br /><br />
|
||||||
|
<p>
|
||||||
|
Click below to download device configuration.
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<Button type="primary" onClick={() => this.downloadConfiguration()}>Download</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async createDevice() {
|
||||||
|
const { identifier, metadataHash, firmwareHash, address } = this.state;
|
||||||
|
try {
|
||||||
|
let instance = await DeviceManager;
|
||||||
|
|
||||||
|
let identifierToSave = identifier;
|
||||||
|
if (address !== '') {
|
||||||
|
let addressToPad = address;
|
||||||
|
if (address.startsWith('0x')) {
|
||||||
|
addressToPad = addressToPad.substring(2);
|
||||||
|
}
|
||||||
|
identifierToSave = setLengthLeft(Buffer.from(addressToPad, 'hex'), 32).toString('hex');
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = await instance.createDevice(addHexPrefix(identifierToSave), addHexPrefix(metadataHash), addHexPrefix(firmwareHash), { from: getDefaultAccount() });
|
||||||
|
await this.watchForChanges(result.tx);
|
||||||
|
openNotificationWithIcon('info', 'Transaction sent', 'Once mined, your device will be registered.');
|
||||||
|
this.setState({
|
||||||
|
loading: true
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { current } = this.state;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Spin spinning={this.state.loading} className="loading-spin">
|
||||||
|
<Steps current={current}>
|
||||||
|
{steps.map(item => <Step key={item.title} title={item.title} />)}
|
||||||
|
</Steps>
|
||||||
|
<div className="steps-content">{this.getContentForStep(current)}</div>
|
||||||
|
<div className="steps-action">
|
||||||
|
{
|
||||||
|
current < steps.length - 1
|
||||||
|
&& <Button type="primary" onClick={() => this.next()}>Next</Button>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
current === steps.length - 1
|
||||||
|
&& <Button type="primary" onClick={() => this.createDevice()}>Register</Button>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
current > 0 && current !== 4
|
||||||
|
&& (
|
||||||
|
<Button style={{ marginLeft: 8 }} onClick={() => this.prev()}>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
current === 4
|
||||||
|
&& (
|
||||||
|
<Button type="primary" onClick={() => this.reset()}>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RegisterDevice;
|
7
frontend/src/index.js
Normal file
7
frontend/src/index.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import App from './App';
|
||||||
|
import registerServiceWorker from './registerServiceWorker';
|
||||||
|
|
||||||
|
ReactDOM.render(<App />, document.getElementById('root'));
|
||||||
|
registerServiceWorker();
|
117
frontend/src/registerServiceWorker.js
Normal file
117
frontend/src/registerServiceWorker.js
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// In production, we register a service worker to serve assets from local cache.
|
||||||
|
|
||||||
|
// This lets the app load faster on subsequent visits in production, and gives
|
||||||
|
// it offline capabilities. However, it also means that developers (and users)
|
||||||
|
// will only see deployed updates on the "N+1" visit to a page, since previously
|
||||||
|
// cached resources are updated in the background.
|
||||||
|
|
||||||
|
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
|
||||||
|
// This link also includes instructions on opting out of this behavior.
|
||||||
|
|
||||||
|
const isLocalhost = Boolean(
|
||||||
|
window.location.hostname === 'localhost' ||
|
||||||
|
// [::1] is the IPv6 localhost address.
|
||||||
|
window.location.hostname === '[::1]' ||
|
||||||
|
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||||
|
window.location.hostname.match(
|
||||||
|
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export default function register() {
|
||||||
|
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||||
|
// The URL constructor is available in all browsers that support SW.
|
||||||
|
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
|
||||||
|
if (publicUrl.origin !== window.location.origin) {
|
||||||
|
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||||
|
// from what our page is served on. This might happen if a CDN is used to
|
||||||
|
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||||
|
|
||||||
|
if (isLocalhost) {
|
||||||
|
// This is running on localhost. Lets check if a service worker still exists or not.
|
||||||
|
checkValidServiceWorker(swUrl);
|
||||||
|
|
||||||
|
// Add some additional logging to localhost, pointing developers to the
|
||||||
|
// service worker/PWA documentation.
|
||||||
|
navigator.serviceWorker.ready.then(() => {
|
||||||
|
console.log(
|
||||||
|
'This web app is being served cache-first by a service ' +
|
||||||
|
'worker. To learn more, visit https://goo.gl/SC7cgQ'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Is not local host. Just register service worker
|
||||||
|
registerValidSW(swUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerValidSW(swUrl) {
|
||||||
|
navigator.serviceWorker
|
||||||
|
.register(swUrl)
|
||||||
|
.then(registration => {
|
||||||
|
registration.onupdatefound = () => {
|
||||||
|
const installingWorker = registration.installing;
|
||||||
|
installingWorker.onstatechange = () => {
|
||||||
|
if (installingWorker.state === 'installed') {
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
// At this point, the old content will have been purged and
|
||||||
|
// the fresh content will have been added to the cache.
|
||||||
|
// It's the perfect time to display a "New content is
|
||||||
|
// available; please refresh." message in your web app.
|
||||||
|
console.log('New content is available; please refresh.');
|
||||||
|
} else {
|
||||||
|
// At this point, everything has been precached.
|
||||||
|
// It's the perfect time to display a
|
||||||
|
// "Content is cached for offline use." message.
|
||||||
|
console.log('Content is cached for offline use.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error during service worker registration:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkValidServiceWorker(swUrl) {
|
||||||
|
// Check if the service worker can be found. If it can't reload the page.
|
||||||
|
fetch(swUrl)
|
||||||
|
.then(response => {
|
||||||
|
// Ensure service worker exists, and that we really are getting a JS file.
|
||||||
|
if (
|
||||||
|
response.status === 404 ||
|
||||||
|
response.headers.get('content-type').indexOf('javascript') === -1
|
||||||
|
) {
|
||||||
|
// No service worker found. Probably a different app. Reload the page.
|
||||||
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
|
registration.unregister().then(() => {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Service worker found. Proceed as normal.
|
||||||
|
registerValidSW(swUrl);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log(
|
||||||
|
'No internet connection found. App is running in offline mode.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unregister() {
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
|
registration.unregister();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
35
frontend/src/utils/web3.js
Normal file
35
frontend/src/utils/web3.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import Web3 from 'web3'
|
||||||
|
|
||||||
|
let getWeb3 = new Promise(function (resolve, reject) {
|
||||||
|
window.addEventListener('load', function () {
|
||||||
|
let results;
|
||||||
|
let web3 = window.web3;
|
||||||
|
|
||||||
|
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
|
||||||
|
if (typeof web3 !== 'undefined') {
|
||||||
|
// Use Mist/MetaMask's provider.
|
||||||
|
web3 = new Web3(web3.currentProvider);
|
||||||
|
|
||||||
|
results = {
|
||||||
|
web3: web3
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('Injected web3 detected.');
|
||||||
|
resolve(results)
|
||||||
|
} else {
|
||||||
|
let provider = new Web3.providers.HttpProvider('http://127.0.0.1:8545');
|
||||||
|
web3 = new Web3(provider);
|
||||||
|
|
||||||
|
results = {
|
||||||
|
web3: web3
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('No web3 instance injected, using Local web3.');
|
||||||
|
|
||||||
|
// should be resolved, leave reject for dev as there should always be metamask installed
|
||||||
|
reject(results);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
export default getWeb3;
|
5
migrations/1_initial_migration.js
Normal file
5
migrations/1_initial_migration.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
var Migrations = artifacts.require("./Migrations.sol");
|
||||||
|
|
||||||
|
module.exports = function(deployer) {
|
||||||
|
deployer.deploy(Migrations);
|
||||||
|
};
|
5
migrations/2_deploy_contracts.js
Normal file
5
migrations/2_deploy_contracts.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
var DeviceManager = artifacts.require("./DeviceManager.sol");
|
||||||
|
|
||||||
|
module.exports = function(deployer) {
|
||||||
|
deployer.deploy(DeviceManager);
|
||||||
|
};
|
13640
package-lock.json
generated
Normal file
13640
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"truffle": "^5.11.5"
|
||||||
|
}
|
||||||
|
}
|
2
simulations/.gitignore
vendored
Normal file
2
simulations/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
config*.json
|
74
simulations/device.js
Normal file
74
simulations/device.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
const request = require('request');
|
||||||
|
const { hashPersonalMessage, ecsign, ecrecover, toRpcSig, fromRpcSig, keccak256, addHexPrefix, sha3 } = require('ethereumjs-util');
|
||||||
|
const { default: MerkleTree } = require('merkle-tree-solidity');
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const [configPath] = args;
|
||||||
|
|
||||||
|
// Configuration file downloaded after registering device
|
||||||
|
const deviceConfig = require(configPath);
|
||||||
|
|
||||||
|
const hashMessageEth = message => hashPersonalMessage(Buffer.from(message));
|
||||||
|
|
||||||
|
const signMessageEth = (message, privateKey) => {
|
||||||
|
let messageHash = hashMessageEth(message);
|
||||||
|
//console.log('Message hash: ' + messageHash.toString('hex'));
|
||||||
|
let { v, r, s } = ecsign(messageHash, privateKey);
|
||||||
|
let rpcSignature = toRpcSig(v, r, s);
|
||||||
|
//console.log('Message signature: ' + rpcSignature);
|
||||||
|
return rpcSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validateSignatureEth = (messageHash, signature, publicKey, address) => {
|
||||||
|
signature = fromRpcSig(signature);
|
||||||
|
let recoveredPublicKey = ecrecover(messageHash, signature.v, signature.r, signature.s);
|
||||||
|
let recoveredPublicKeyHex = recoveredPublicKey.toString('hex');
|
||||||
|
let recoveredAddress = addHexPrefix(keccak256(recoveredPublicKey).toString('hex').substring(64 - 40));
|
||||||
|
//console.log('Recovered public key: ' + recoveredPublicKeyHex);
|
||||||
|
//console.log('Recovered address: ' + recoveredAddress);
|
||||||
|
if (recoveredPublicKeyHex === publicKey && recoveredAddress === address) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gather data and sign
|
||||||
|
const privateKey = Buffer.from(deviceConfig.privateKey, 'hex');
|
||||||
|
|
||||||
|
let message = 'test';
|
||||||
|
let signature = signMessageEth(message, privateKey);
|
||||||
|
|
||||||
|
// Validate signature
|
||||||
|
if (!validateSignatureEth(hashMessageEth(message), signature, deviceConfig.publicKey, deviceConfig.address)) {
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct Merkle tree
|
||||||
|
const metadataHashes = deviceConfig.metadata.map(el => sha3(el));
|
||||||
|
const merkleTree = new MerkleTree(metadataHashes);
|
||||||
|
|
||||||
|
// Index of metadata element to send
|
||||||
|
const elementToSend = 0;
|
||||||
|
|
||||||
|
// Generate proof
|
||||||
|
let proof = merkleTree.getProof(metadataHashes[elementToSend]);
|
||||||
|
proof = proof.map(el => addHexPrefix(el.toString('hex')));
|
||||||
|
|
||||||
|
// Build payload
|
||||||
|
let payload = {
|
||||||
|
deviceId: deviceConfig.deviceId,
|
||||||
|
message,
|
||||||
|
signature: signature,
|
||||||
|
metadata: deviceConfig.metadata[elementToSend],
|
||||||
|
proof,
|
||||||
|
firmware: deviceConfig.firmware,
|
||||||
|
curve: deviceConfig.curve
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send to platform
|
||||||
|
const platformEndpoint = 'http://localhost:1337/receive'
|
||||||
|
request.post({ url: platformEndpoint, json: payload }, function (error, response, body) {
|
||||||
|
if (!error) {
|
||||||
|
console.log(body)
|
||||||
|
} else {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
})
|
4737
simulations/package-lock.json
generated
Normal file
4737
simulations/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
simulations/package.json
Normal file
11
simulations/package.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "simulations",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"dependencies": {
|
||||||
|
"ethereumjs-util": "5.2.0",
|
||||||
|
"express": "4.16.3",
|
||||||
|
"merkle-tree-solidity": "1.0.8",
|
||||||
|
"request": "2.88.0",
|
||||||
|
"web3": "0.20.6"
|
||||||
|
}
|
||||||
|
}
|
49
simulations/platform.js
Normal file
49
simulations/platform.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const Web3 = require('web3');
|
||||||
|
const { hashPersonalMessage, addHexPrefix, sha3 } = require('ethereumjs-util');
|
||||||
|
|
||||||
|
const hashMessageHex = message => addHexPrefix(hashPersonalMessage(Buffer.from(message)).toString('hex'));
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
const DeviceManagerArtifact = require('../build/contracts/DeviceManager.json');
|
||||||
|
let latestNetwork = DeviceManagerArtifact.networks[Object.keys(DeviceManagerArtifact.networks).reduce((res, curr) => curr > res ? curr : res)];
|
||||||
|
|
||||||
|
// Connect to local node
|
||||||
|
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
||||||
|
web3.eth.defaultAccount = web3.eth.accounts[0];
|
||||||
|
|
||||||
|
// Instance using ABI and contract address
|
||||||
|
const deviceManager = web3.eth.contract(DeviceManagerArtifact.abi).at(latestNetwork.address);
|
||||||
|
|
||||||
|
// Receive payload and validate on blockchain
|
||||||
|
app.post('/receive', function (req, res) {
|
||||||
|
console.log('received payload: ' + JSON.stringify(req.body));
|
||||||
|
|
||||||
|
// Validate message
|
||||||
|
const { deviceId, message, signature } = req.body;
|
||||||
|
let validMessage = deviceManager.isValidEthMessage(deviceId, hashMessageHex(message), signature);
|
||||||
|
console.log('valid message: ' + validMessage);
|
||||||
|
|
||||||
|
// Validate metadata
|
||||||
|
const { metadata, proof } = req.body;
|
||||||
|
let metadataHash = addHexPrefix(sha3(metadata).toString('hex'));
|
||||||
|
let validMetadata = deviceManager.isValidMetadataMember(deviceId, proof, metadataHash);
|
||||||
|
console.log('valid metadata: ' + validMetadata);
|
||||||
|
|
||||||
|
// Validate firmware
|
||||||
|
const { firmware } = req.body;
|
||||||
|
let firmwareHash = addHexPrefix(sha3(firmware).toString('hex'));
|
||||||
|
let validFirmware = deviceManager.isValidFirmwareHash(deviceId, firmwareHash);
|
||||||
|
console.log('valid firmware: ' + validFirmware);
|
||||||
|
|
||||||
|
// Respond back with status
|
||||||
|
res.send({
|
||||||
|
validMessage,
|
||||||
|
validMetadata,
|
||||||
|
validFirmware
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
app.listen(1337, () => console.log('Platform simulation listening on port 1337'));
|
39
test/TestDeviceManager.sol
Normal file
39
test/TestDeviceManager.sol
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
pragma solidity ^0.4.24;
|
||||||
|
// FIXME - cannot be resolved by truffle
|
||||||
|
import "truffle/Assert.sol";
|
||||||
|
import "truffle/DeployedAddresses.sol";
|
||||||
|
import "../contracts/DeviceManager.sol";
|
||||||
|
|
||||||
|
contract TestDeviceManager {
|
||||||
|
DeviceManager deviceManager = DeviceManager(DeployedAddresses.DeviceManager());
|
||||||
|
uint constant createdDeviceId = 0;
|
||||||
|
|
||||||
|
function testCreateDevice() public {
|
||||||
|
uint deviceId = deviceManager.createDevice(
|
||||||
|
sha256("identifier"),
|
||||||
|
sha256("metadata"),
|
||||||
|
sha256("firmware")
|
||||||
|
);
|
||||||
|
|
||||||
|
Assert.equal(deviceId, createdDeviceId, "New device should be recorded with ID of 0.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCreatedDeviceOwner() public {
|
||||||
|
address owner;
|
||||||
|
(owner,,,) = deviceManager.devices(createdDeviceId);
|
||||||
|
|
||||||
|
Assert.equal(owner, this, "Created device should be recorded and owned by this address");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetDevicesByOwner() public {
|
||||||
|
uint[] memory deviceIds = deviceManager.getDevicesByOwner(this);
|
||||||
|
uint[] memory expectedIds = new uint[](1);
|
||||||
|
expectedIds[0] = 0;
|
||||||
|
|
||||||
|
Assert.equal(
|
||||||
|
keccak256(abi.encodePacked(deviceIds)),
|
||||||
|
keccak256(abi.encodePacked(expectedIds)),
|
||||||
|
"Only one device should have been created owned by this address"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
9
truffle-config.js
Normal file
9
truffle-config.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
networks: {
|
||||||
|
development: {
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: 8545,
|
||||||
|
network_id: "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
9
truffle.js
Normal file
9
truffle.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
networks: {
|
||||||
|
development: {
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: 8545,
|
||||||
|
network_id: "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user