|
1 | 1 | # coding=utf-8 |
2 | 2 | from __future__ import absolute_import, division, print_function, \ |
3 | | - unicode_literals |
| 3 | + unicode_literals |
4 | 4 |
|
5 | 5 | from typing import List, Optional |
6 | 6 |
|
|
10 | 10 | from iota.multisig.types import MultisigAddress |
11 | 11 |
|
12 | 12 | __all__ = [ |
13 | | - 'MultisigAddressBuilder', |
| 13 | + 'MultisigAddressBuilder', |
14 | 14 | ] |
15 | 15 |
|
16 | 16 |
|
17 | 17 | 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. |
32 | 18 | """ |
| 19 | + Creates multisig addresses. |
33 | 20 |
|
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). |
35 | 25 | """ |
36 | | - Caches the generated address. |
37 | 26 |
|
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__() |
42 | 29 |
|
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 | + """ |
44 | 35 |
|
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. |
49 | 39 |
|
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 | + """ |
53 | 44 |
|
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() |
59 | 46 |
|
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. |
62 | 51 |
|
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! |
67 | 54 |
|
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 | + ) |
77 | 82 |
|
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) |
81 | 86 |
|
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 | + ) |
84 | 91 |
|
85 | | - return self._address |
| 92 | + return self._address |
0 commit comments