Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 3ce90c0

Browse files
committed
[#145] Reformat multisig crypto for PEP-8.
1 parent 02f4767 commit 3ce90c0

File tree

2 files changed

+64
-57
lines changed

2 files changed

+64
-57
lines changed

iota/multisig/crypto/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# coding=utf-8
22
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
3+
unicode_literals

iota/multisig/crypto/addresses.py

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf-8
22
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
3+
unicode_literals
44

55
from typing import List, Optional
66

@@ -10,76 +10,83 @@
1010
from iota.multisig.types import MultisigAddress
1111

1212
__all__ = [
13-
'MultisigAddressBuilder',
13+
'MultisigAddressBuilder',
1414
]
1515

1616

1717
class MultisigAddressBuilder(object):
18-
"""
19-
Creates multisig addresses.
20-
21-
Note that this class generates a single address from multiple inputs,
22-
(digests) unlike :py:class:`iota.crypto.addresses.AddressGenerator`
23-
which generates multiple addresses from a single input (seed).
24-
"""
25-
def __init__(self):
26-
super(MultisigAddressBuilder, self).__init__()
27-
28-
self._digests = [] # type: List[Digest]
29-
"""
30-
Keeps track of digests that were added, so that we can attach them
31-
to the final :py:class:`MultisigAddress` object.
3218
"""
19+
Creates multisig addresses.
3320
34-
self._address = None # type: Optional[MultisigAddress]
21+
Note that this class generates a single address from multiple
22+
inputs (digests), unlike
23+
:py:class:`iota.crypto.addresses.AddressGenerator` which generates
24+
multiple addresses from a single input (seed).
3525
"""
36-
Caches the generated address.
3726

38-
Generating the address modifies the internal state of the curl
39-
sponge, so each :py:class:`MultisigAddressBuilder` instance can
40-
only generate a single address.
41-
"""
27+
def __init__(self):
28+
super(MultisigAddressBuilder, self).__init__()
4229

43-
self._sponge = Kerl()
30+
self._digests = [] # type: List[Digest]
31+
"""
32+
Keeps track of digests that were added, so that we can attach
33+
them to the final :py:class:`MultisigAddress` object.
34+
"""
4435

45-
def add_digest(self, digest):
46-
# type: (Digest) -> None
47-
"""
48-
Absorbs a digest into the sponge.
36+
self._address = None # type: Optional[MultisigAddress]
37+
"""
38+
Caches the generated address.
4939
50-
IMPORTANT: Keep track of the order that digests are added!
51-
To spend inputs from a multisig address, you must provide the
52-
private keys in the same order!
40+
Generating the address modifies the internal state of the curl
41+
sponge, so each :py:class:`MultisigAddressBuilder` instance can
42+
only generate a single address.
43+
"""
5344

54-
References:
55-
- https://github.com/iotaledger/wiki/blob/master/multisigs.md#spending-inputs
56-
"""
57-
if self._address:
58-
raise ValueError('Cannot add digests once an address is extracted.')
45+
self._sponge = Kerl()
5946

60-
self._sponge.absorb(digest.as_trits())
61-
self._digests.append(digest)
47+
def add_digest(self, digest):
48+
# type: (Digest) -> None
49+
"""
50+
Absorbs a digest into the sponge.
6251
63-
def get_address(self):
64-
# type: () -> MultisigAddress
65-
"""
66-
Returns the new multisig address.
52+
.. important::
53+
Keep track of the order that digests are added!
6754
68-
Note that you can continue to add digests after extracting an
69-
address; the next address will use *all* of the digests that have
70-
been added so far.
71-
"""
72-
if not self._digests:
73-
raise ValueError(
74-
'Must call ``add_digest`` at least once '
75-
'before calling ``get_address``.',
76-
)
55+
To spend inputs from a multisig address, you must provide
56+
the private keys in the same order!
57+
58+
References:
59+
60+
- https://github.com/iotaledger/wiki/blob/master/multisigs.md#spending-inputs
61+
"""
62+
if self._address:
63+
raise ValueError('Cannot add digests once an address is extracted.')
64+
65+
self._sponge.absorb(digest.as_trits())
66+
self._digests.append(digest)
67+
68+
def get_address(self):
69+
# type: () -> MultisigAddress
70+
"""
71+
Returns the new multisig address.
72+
73+
Note that you can continue to add digests after extracting an
74+
address; the next address will use *all* of the digests that
75+
have been added so far.
76+
"""
77+
if not self._digests:
78+
raise ValueError(
79+
'Must call ``add_digest`` at least once '
80+
'before calling ``get_address``.',
81+
)
7782

78-
if not self._address:
79-
address_trits = [0] * HASH_LENGTH
80-
self._sponge.squeeze(address_trits)
83+
if not self._address:
84+
address_trits = [0] * HASH_LENGTH
85+
self._sponge.squeeze(address_trits)
8186

82-
self._address =\
83-
MultisigAddress.from_trits(address_trits, digests=self._digests[:])
87+
self._address = MultisigAddress.from_trits(
88+
address_trits,
89+
digests=self._digests[:],
90+
)
8491

85-
return self._address
92+
return self._address

0 commit comments

Comments
 (0)