Skip to content

Commit 6a101b3

Browse files
authored
Merge pull request #66 from hyperledger/master
Master
2 parents dfb28e5 + 0aed0ae commit 6a101b3

40 files changed

+1052
-583
lines changed

README.md

Lines changed: 70 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,112 +5,99 @@ Indy. As such, it provides features somewhat similar in scope to those
55
found in Fabric. However, it is special-purposed for use in an identity
66
system, whereas Fabric is general purpose.
77

8-
You can log bugs against Plenum in [Hyperledger's Jira](https://jira.hyperledger.org); use
9-
project "INDY".
10-
11-
Plenum makes extensive use of coroutines and the async/await keywords in
12-
Python, and as such, requires Python version 3.5.0 or later. Plenum also
13-
depends on libsodium, an awesome crypto library. These need to be installed
14-
separately. Read below to see how.
15-
16-
Plenum has other dependencies, including the impressive
17-
[RAET](https://github.com/saltstack/raet) for secure reliable communication
18-
over UDP, but this and other dependencies are installed automatically with
19-
Plenum.
20-
21-
### Installing Plenum
22-
23-
```
24-
pip install indy-plenum
25-
```
26-
27-
From here, you can play with the command-line interface (see the [tutorial](https://github.com/hyperledger/indy-plenum/wiki))...
28-
29-
Note: For Windows, we recommended using either [cmder](http://cmder.net/) or [conemu](https://conemu.github.io/).
30-
31-
```
32-
plenum
33-
```
34-
35-
...or run the tests.
36-
37-
```
38-
git clone https://github.com/hyperledger/indy-plenum.git
39-
cd indy-plenum
40-
python -m plenum.test
41-
```
42-
43-
**Details about the protocol, including a great tutorial, can be found on the [wiki](https://github.com/hyperledger/indy-plenum/wiki).**
44-
45-
### Installing python 3.5 and libsodium:
46-
47-
**Ubuntu:**
48-
49-
1. Run ```sudo add-apt-repository ppa:fkrull/deadsnakes```
50-
51-
2. Run ```sudo apt-get update```
52-
53-
3. On Ubuntu 14, run ```sudo apt-get install python3.5``` (python3.5 is pre-installed on most Ubuntu 16 systems; if not, do it there as well.)
54-
55-
4. We need to install libsodium with the package manager. This typically requires a package repo that's not active by default. Inspect ```/etc/apt/sources.list``` file with your favorite editor (using sudo). On ubuntu 16, you are looking for a line that says ```deb http://us.archive.ubuntu.com/ubuntu xenial main universe```. On ubuntu 14, look for or add: ```deb http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main``` and ```deb-src http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main```.
56-
57-
5. Run ```sudo apt-get update```. On ubuntu 14, if you get a GPG error about public key not available, run this command and then, after, retry apt-get update: ```sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B9316A7BC7917B12```
58-
59-
6. Install libsodium; the version depends on your distro version. On Ubuntu 14, run ```sudo apt-get install libsodium13```; on Ubuntu 16, run ```sudo apt-get install libsodium18```
60-
61-
8. If you still get the error ```E: Unable to locate package libsodium13``` then add ```deb http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main``` and ```deb-src http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main``` to your ```/etc/apt/sources.list```.
62-
Now run ```sudo apt-get update``` and then ```sudo apt-get install libsodium13```
63-
64-
**CentOS/Redhat:**
8+
## Other Documentation
9+
10+
- Details about the protocol, including a great tutorial, can be found on the [wiki](https://github.com/hyperledger/indy-plenum/wiki).
11+
- Please have a look at aggregated documentation at [indy-node-documentation](https://github.com/hyperledger/indy-node/blob/master/README.md) which describes workflows and setup scripts common for both projects.
12+
13+
## Indy Plenum Repository Structure
14+
15+
- plenum:
16+
- the main codebase for plenum including Byzantine Fault Tolerant Protocol based on [RBFT](https://pakupaku.me/plaublin/rbft/5000a297.pdf)
17+
- common:
18+
- common and utility code
19+
- crypto:
20+
- basic crypto-related code (in particular, [indy-crypto](https://github.com/hyperledger/indy-crypto) wrappers)
21+
- ledger:
22+
- Provides a simple, python-based, immutable, ordered log of transactions
23+
backed by a merkle tree.
24+
- This is an efficient way to generate verifiable proofs of presence
25+
and data consistency.
26+
- The scope of concerns here is fairly narrow; it is not a full-blown
27+
distributed ledger technology like Fabric, but simply the persistence
28+
mechanism that Plenum needs.
29+
- state:
30+
- state storage using python 3 version of Ethereum's Patricia Trie
31+
- stp:
32+
- secure transport abstraction
33+
- it has two implementations: RAET and ZeroMQ
34+
- Although RAET implementation is there, it's not supported anymore, and [ZeroMQ](http://zeromq.org/) is the default secure transport in plenum.
35+
- storage:
36+
- key-value storage abstractions
37+
- contains [leveldb](http://leveldb.org/) implementation as the main key-valued storage used in Plenum (for ledger, state, etc.)
6538

66-
1. Run ```sudo yum install python3.5```
39+
## Dependencies
6740

68-
2. Run ```sudo yum install libsodium-devel```
41+
- Plenum makes extensive use of coroutines and the async/await keywords in
42+
Python, and as such, requires Python version 3.5.0 or later.
43+
- Plenum also depends on [libsodium](https://download.libsodium.org/doc/), an awesome crypto library. These need to be installed
44+
separately.
45+
- Plenum uses [ZeroMQ](http://zeromq.org/) as a secure transport
46+
- [indy-crypto](https://github.com/hyperledger/indy-crypto)
47+
- A shared crypto library
48+
- It's based on [AMCL](https://github.com/milagro-crypto/amcl)
49+
- In particular, it contains BLS multi-signature crypto needed for state proofs support in Indy.
6950

7051

71-
**Mac:**
52+
## Contact us
7253

73-
1. Go to [python.org](https://www.python.org) and from the "Downloads" menu, download the Python 3.5.0 package (python-3.5.0-macosx10.6.pkg) or later.
54+
- Bugs, stories, and backlog for this codebase are managed in [Hyperledger's Jira](https://jira.hyperledger.org).
55+
Use project name `INDY`.
56+
- Join us on [Jira's Rocket.Chat](https://chat.hyperledger.org/channel/indy) at `#indy` and/or `#indy-node` channels to discuss.
7457

75-
2. Open the downloaded file to install it.
58+
## How to Contribute
7659

77-
3. If you are a homebrew fan, you can install it using this brew command: ```brew install python3```
60+
- We'd love your help; see these [instructions on how to contribute](http://bit.ly/2ugd0bq).
61+
- You may also want to read this info about [maintainers](https://github.com/hyperledger/indy-node/blob/stable/MAINTAINERS.md).
7862

79-
4. To install homebrew package manager, see: [brew.sh](http://brew.sh/)
8063

81-
5. Once you have homebrew installed, run ```brew install libsodium``` to install libsodium.
64+
## How to Start Working with the Code
8265

66+
Please have a look at [Dev Setup](https://github.com/hyperledger/indy-node/blob/master/docs/setup-dev.md) in indy-node repo.
67+
It contains common setup for both indy-plenum and indy-node.
8368

84-
**Windows:**
8569

86-
1. Go to https://download.libsodium.org/libsodium/releases/ and download the latest libsodium package (libsodium-1.0.8-mingw.tar.gz is the latest version as of this writing)
70+
## Installing Plenum
8771

88-
2. When you extract the contents of the downloaded tar file, you will see 2 folders with the names libsodium-win32 and libsodium-win64.
72+
#### Install from pypi
8973

90-
3. As the name suggests, use the libsodium-win32 if you are using 32-bit machine or libsodium-win64 if you are using a 64-bit operating system.
9174

92-
4. Copy the libsodium-x.dll from libsodium-win32\bin or libsodium-win64\bin to C:\Windows\System or System32 and rename it to libsodium.dll.
75+
```
76+
pip install indy-plenum
77+
```
9378

94-
5. Download the latest build (pywin32-220.win-amd64-py3.5.exe is the latest build as of this writing) from [here](https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/) and run the downloaded executable.
79+
From here, you can play with the command-line interface (see the [tutorial](https://github.com/hyperledger/indy-plenum/wiki)).
9580

81+
Note: For Windows, we recommended using either [cmder](http://cmder.net/) or [conemu](https://conemu.github.io/).
9682

97-
### Using a virtual environment (recommended)
98-
We recommend creating a new Python virtual environment for trying out Plenum.
99-
a virtual environment is a Python environment which is isolated from the
100-
system's default Python environment (you can change that) and any other
101-
virtual environment you create. You can create a new virtual environment by:
10283
```
103-
virtualenv -p python3.5 <name of virtual environment>
84+
plenum
10485
```
10586

106-
And activate it by:
87+
...or run the tests.
10788

10889
```
109-
source <name of virtual environment>/bin/activate
90+
git clone https://github.com/hyperledger/indy-plenum.git
91+
cd indy-plenum
92+
python -m plenum.test
11093
```
11194

11295

113-
### Initializing Keep
96+
#### Initializing Keys
97+
Each Node needs to have keys initialized
98+
- ed25519 transport keys (used by ZMQ for Node-to-Node and Node-to-Client communication)
99+
- BLS keys for BLS multi-signature and state proofs support
100+
114101
```
115102
init_plenum_keys --name Alpha --seeds 000000000000000000000000000Alpha Alpha000000000000000000000000000 --force
116103
```
@@ -129,21 +116,21 @@ init_plenum_keys --name Delta --seeds 000000000000000000000000000Delta Delta0000
129116
Note: Seed can be any randomly chosen 32 byte value. It does not have to be in the format `00..<name of the node>`.
130117

131118

132-
### Seeds used for generating clients
119+
#### Seeds used for generating clients
133120
1. Seed used for steward Bob's signing key pair ```11111111111111111111111111111111```
134121
2. Seed used for steward Bob's public private key pair ```33333333333333333333333333333333```
135122
3. Seed used for client Alice's signing key pair ```22222222222222222222222222222222```
136123
4. Seed used for client Alice's public private key pair ```44444444444444444444444444444444```
137124

138125

139-
### Running Node
126+
#### Running Node
140127

141128
```
142129
start_plenum_node Alpha
143130
```
144131

145132

146-
### Updating configuration
133+
#### Updating configuration
147134
To update any configuration parameters, you need to update the `plenum_config.py` in `.plenum/YOUR_NETWORK_NAME` directory inside your home directory.
148135
eg. To update the node registry to use `127.0.0.1` as host put these in your `plenum_config.py`.
149136

@@ -164,26 +151,3 @@ cliNodeReg = OrderedDict([
164151
('DeltaC', (('127.0.0.1', 9708), '3af81a541097e3e042cacbe8761c0f9e54326049e1ceda38017c95c432312f6f', '8b112025d525c47e9df81a6de2966e1b4ee1ac239766e769f19d831175a04264'))
165152
])
166153
```
167-
168-
# Immutable Ledger used in Plenum.
169-
170-
This codebase provides a simple, python-based, immutable, ordered log of transactions
171-
backed by a merkle tree. This is an efficient way to generate verifiable proofs of presence
172-
and data consistency.
173-
174-
The scope of concerns here is fairly narrow; it is not a full-blown
175-
distributed ledger technology like Fabric, but simply the persistence
176-
mechanism that Plenum needs. The repo is intended to be collapsed into the indy-node codebase
177-
over time; hence there is no wiki, no documentation, and no intention to
178-
use github issues to track bugs.
179-
180-
You can log issues against this codebase in [Hyperledger's Jira](https://jira.hyperledger.org).
181-
182-
Join us on [Hyperledger's Rocket.Chat](http://chat.hyperledger.org), on the #indy
183-
channel, to discuss.
184-
185-
# state
186-
Plenum's state storage using python 3 version of Ethereum's Patricia Trie
187-
188-
# stp
189-
Secure Transport Protocol

common/serializers/serialization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
multi_sig_store_serializer = JsonSerializer()
1616
state_roots_serializer = Base58Serializer()
1717
proof_nodes_serializer = Base64Serializer()
18+
multi_signature_value_serializer = MsgPackSerializer()
1819

1920

2021
# TODO: separate data, metadata and signature, so that we don't need to have topLevelKeysToIgnore

crypto/bls/bls_crypto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def generate_keys(params: GroupParams, seed=None) -> (str, str):
2626
pass
2727

2828
@abstractmethod
29-
def sign(self, message: str) -> str:
29+
def sign(self, message: bytes) -> str:
3030
pass
3131

3232

@@ -36,9 +36,9 @@ def create_multi_sig(self, signatures: Sequence[str]) -> str:
3636
pass
3737

3838
@abstractmethod
39-
def verify_sig(self, signature: str, message: str, pk: str) -> bool:
39+
def verify_sig(self, signature: str, message: bytes, pk: str) -> bool:
4040
pass
4141

4242
@abstractmethod
43-
def verify_multi_sig(self, signature: str, message: str, pks: Sequence[str]) -> bool:
43+
def verify_multi_sig(self, signature: str, message: bytes, pks: Sequence[str]) -> bool:
4444
pass

crypto/bls/bls_multi_signature.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from collections import OrderedDict
22

3+
from common.serializers.serialization import multi_signature_value_serializer
4+
35

46
class MultiSignatureValue:
57
"""
@@ -37,8 +39,7 @@ def __init__(self,
3739
self.timestamp = timestamp
3840

3941
def as_single_value(self):
40-
values = [str(v) for v in self.as_dict().values()]
41-
return "".join(values)
42+
return multi_signature_value_serializer.serialize(self.as_dict())
4243

4344
def as_dict(self):
4445
return OrderedDict(sorted(self.__dict__.items()))
@@ -55,6 +56,9 @@ def as_list(self):
5556
def __eq__(self, other):
5657
return isinstance(other, MultiSignatureValue) and self.as_dict() == other.as_dict()
5758

59+
def __str__(self) -> str:
60+
return str(self.as_dict())
61+
5862

5963
class MultiSignature:
6064
"""
@@ -104,3 +108,6 @@ def as_list(self):
104108

105109
def __eq__(self, other):
106110
return isinstance(other, MultiSignature) and self.as_dict() == other.as_dict()
111+
112+
def __str__(self) -> str:
113+
return str(self.as_dict())

crypto/bls/indy_crypto/bls_crypto_indy_crypto.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ def bls_from_str(v: str, cls) -> Optional[BlsEntity]:
3939
return None
4040
return cls.from_bytes(bts)
4141

42-
@staticmethod
43-
def msg_to_bls_bytes(msg: str) -> bytes:
44-
return msg.encode()
45-
4642
@staticmethod
4743
def prepare_seed(seed):
4844
seed_bytes = None
@@ -65,19 +61,19 @@ def __init__(self, params: GroupParams):
6561
self._generator = \
6662
IndyCryptoBlsUtils.bls_from_str(params.g, Generator) # type: Generator
6763

68-
def verify_sig(self, signature: str, message: str, pk: str) -> bool:
64+
def verify_sig(self, signature: str, message: bytes, pk: str) -> bool:
6965
bls_signature = IndyCryptoBlsUtils.bls_from_str(signature, Signature)
7066
if bls_signature is None:
7167
return False
7268
bls_pk = IndyCryptoBlsUtils.bls_from_str(pk, VerKey)
7369
if bls_pk is None:
7470
return False
7571
return Bls.verify(bls_signature,
76-
IndyCryptoBlsUtils.msg_to_bls_bytes(message),
72+
message,
7773
bls_pk,
7874
self._generator)
7975

80-
def verify_multi_sig(self, signature: str, message: str, pks: Sequence[str]) -> bool:
76+
def verify_multi_sig(self, signature: str, message: bytes, pks: Sequence[str]) -> bool:
8177
epks = [IndyCryptoBlsUtils.bls_from_str(p, VerKey) for p in pks]
8278
if None in epks:
8379
return False
@@ -87,9 +83,8 @@ def verify_multi_sig(self, signature: str, message: str, pks: Sequence[str]) ->
8783
if multi_signature is None:
8884
return False
8985

90-
message_bytes = IndyCryptoBlsUtils.msg_to_bls_bytes(message)
9186
return Bls.verify_multi_sig(multi_sig=multi_signature,
92-
message=message_bytes,
87+
message=message,
9388
ver_keys=epks,
9489
gen=self._generator)
9590

@@ -117,7 +112,6 @@ def generate_keys(params: GroupParams, seed=None) -> (str, str):
117112
vk_str = IndyCryptoBlsUtils.bls_to_str(vk)
118113
return sk_str, vk_str
119114

120-
def sign(self, message: str) -> str:
121-
bts = IndyCryptoBlsUtils.msg_to_bls_bytes(message)
122-
sign = Bls.sign(bts, self._sk_bls)
115+
def sign(self, message: bytes) -> str:
116+
sign = Bls.sign(message, self._sk_bls)
123117
return IndyCryptoBlsUtils.bls_to_str(sign)

0 commit comments

Comments
 (0)