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

Commit b6168c6

Browse files
committed
[#10] Added security level param to API methods.
1 parent fe4fbf5 commit b6168c6

File tree

5 files changed

+258
-77
lines changed

5 files changed

+258
-77
lines changed

iota/multisig/api.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from iota import Address, Iota, ProposedTransaction
88
from iota.commands import discover_commands
9+
from iota.crypto.addresses import AddressGenerator
910
from iota.crypto.types import Digest
1011
from iota.multisig import commands
1112
from iota.multisig.types import MultisigAddress
@@ -22,7 +23,7 @@ class MultisigIota(Iota):
2223
**CAUTION:** Make sure you understand how multisig works before
2324
attempting to use it. If you are not careful, you could easily
2425
compromise the security of your private keys, send IOTAs to
25-
inaccessible addresses, etc.
26+
unspendable addresses, etc.
2627
2728
References:
2829
- https://github.com/iotaledger/wiki/blob/master/multisigs.md
@@ -53,8 +54,13 @@ def create_multisig_address(self, digests):
5354
digests = digests,
5455
)
5556

56-
def get_digests(self, index=0, count=1):
57-
# type: (int, int) -> dict
57+
def get_digests(
58+
self,
59+
index = 0,
60+
count = 1,
61+
security_level = AddressGenerator.DEFAULT_SECURITY_LEVEL,
62+
):
63+
# type: (int, int, int) -> dict
5864
"""
5965
Generates one or more key digests from the seed.
6066
@@ -66,6 +72,14 @@ def get_digests(self, index=0, count=1):
6672
:param count:
6773
Number of digests to generate.
6874
75+
:param security_level:
76+
Number of iterations to use when generating new addresses.
77+
78+
Larger values take longer, but the resulting signatures are more
79+
secure.
80+
81+
This value must be between 1 and 3, inclusive.
82+
6983
:return:
7084
Dict with the following items::
7185
@@ -76,13 +90,19 @@ def get_digests(self, index=0, count=1):
7690
}
7791
"""
7892
return commands.GetDigestsCommand(self.adapter)(
79-
seed = self.seed,
80-
index = index,
81-
count = count,
93+
seed = self.seed,
94+
index = index,
95+
count = count,
96+
securityLevel = security_level,
8297
)
8398

84-
def get_private_keys(self, index=0, count=1):
85-
# type: (int, int) -> dict
99+
def get_private_keys(
100+
self,
101+
index = 0,
102+
count = 1,
103+
security_level = AddressGenerator.DEFAULT_SECURITY_LEVEL,
104+
):
105+
# type: (int, int, int) -> dict
86106
"""
87107
Generates one or more private keys from the seed.
88108
@@ -95,6 +115,14 @@ def get_private_keys(self, index=0, count=1):
95115
:param count:
96116
Number of keys to generate.
97117
118+
:param security_level:
119+
Number of iterations to use when generating new keys.
120+
121+
Larger values take longer, but the resulting signatures are more
122+
secure.
123+
124+
This value must be between 1 and 3, inclusive.
125+
98126
:return:
99127
Dict with the following items::
100128
@@ -109,16 +137,17 @@ def get_private_keys(self, index=0, count=1):
109137
- https://github.com/iotaledger/wiki/blob/master/multisigs.md#how-m-of-n-works
110138
"""
111139
return commands.GetPrivateKeysCommand(self.adapter)(
112-
seed = self.seed,
113-
index = index,
114-
count = count,
140+
seed = self.seed,
141+
index = index,
142+
count = count,
143+
securityLevel = security_level,
115144
)
116145

117146
def prepare_multisig_transfer(
118147
self,
119148
transfers,
120149
multisig_input,
121-
change_address=None,
150+
change_address = None,
122151
):
123152
# type: (Iterable[ProposedTransaction], MultisigAddress, Optional[Address]) -> dict
124153
"""

iota/multisig/commands/get_digests.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
from __future__ import absolute_import, division, print_function, \
33
unicode_literals
44

5+
from typing import Optional
6+
57
import filters as f
8+
69
from iota.commands import FilterCommand, RequestFilter
10+
from iota.crypto.addresses import AddressGenerator
711
from iota.crypto.types import Seed
812
from iota.filters import Trytes
913
from iota.multisig.commands.get_private_keys import GetPrivateKeysCommand
10-
from typing import Optional
1114

1215
__all__ = [
1316
'GetDigestsCommand',
@@ -30,15 +33,18 @@ def get_response_filter(self):
3033
pass
3134

3235
def _execute(self, request):
33-
count = request['count'] # type: Optional[int]
34-
index = request['index'] # type: int
35-
seed = request['seed'] # type: Seed
36-
37-
gpk_result = GetPrivateKeysCommand(self.adapter)(
38-
seed = seed,
39-
count = count,
40-
index = index,
41-
)
36+
count = request['count'] # type: Optional[int]
37+
index = request['index'] # type: int
38+
seed = request['seed'] # type: Seed
39+
security_level = request['securityLevel'] # type: int
40+
41+
gpk_result =\
42+
GetPrivateKeysCommand(self.adapter)(
43+
seed = seed,
44+
count = count,
45+
index = index,
46+
securityLevel = security_level,
47+
)
4248

4349
return {
4450
'digests': [key.get_digest() for key in gpk_result['keys']],
@@ -49,15 +55,26 @@ class GetDigestsRequestFilter(RequestFilter):
4955
def __init__(self):
5056
super(GetDigestsRequestFilter, self).__init__(
5157
{
52-
# ``count`` and ``index`` are optional.
53-
'count': f.Type(int) | f.Min(1) | f.Optional(default=1),
54-
'index': f.Type(int) | f.Min(0) | f.Optional(default=0),
58+
# Optional Parameters
59+
'count':
60+
f.Type(int) | f.Min(1) | f.Optional(default=1),
61+
62+
'index':
63+
f.Type(int) | f.Min(0) | f.Optional(default=0),
64+
65+
'securityLevel':
66+
f.Type(int)
67+
| f.Min(1)
68+
| f.Optional(default=AddressGenerator.DEFAULT_SECURITY_LEVEL),
5569

56-
'seed': f.Required | Trytes(result_type=Seed),
70+
# Required Parameters
71+
'seed':
72+
f.Required | Trytes(result_type=Seed),
5773
},
5874

5975
allow_missing_keys = {
6076
'count',
6177
'index',
78+
'securityLevel',
6279
},
6380
)

iota/multisig/commands/get_private_keys.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
from __future__ import absolute_import, division, print_function, \
33
unicode_literals
44

5+
from typing import Optional
6+
57
import filters as f
8+
69
from iota.commands import FilterCommand, RequestFilter
10+
from iota.crypto.addresses import AddressGenerator
711
from iota.crypto.signing import KeyGenerator
812
from iota.crypto.types import Seed
913
from iota.filters import Trytes
10-
from typing import Optional
1114

1215
__all__ = [
1316
'GetPrivateKeysCommand',
@@ -31,30 +34,43 @@ def get_response_filter(self):
3134
pass
3235

3336
def _execute(self, request):
34-
count = request['count'] # type: Optional[int]
35-
index = request['index'] # type: int
36-
seed = request['seed'] # type: Seed
37+
count = request['count'] # type: Optional[int]
38+
index = request['index'] # type: int
39+
seed = request['seed'] # type: Seed
40+
security_level = request['securityLevel'] # type: int
3741

3842
generator = KeyGenerator(seed)
3943

4044
return {
41-
'keys': generator.get_keys(start=index, count=count),
45+
'keys':
46+
generator.get_keys(start=index, count=count, iterations=security_level),
4247
}
4348

4449

4550
class GetPrivateKeysRequestFilter(RequestFilter):
4651
def __init__(self):
4752
super(GetPrivateKeysRequestFilter, self).__init__(
4853
{
49-
# ``count`` and ``index`` are optional.
50-
'count': f.Type(int) | f.Min(1) | f.Optional(default=1),
51-
'index': f.Type(int) | f.Min(0) | f.Optional(default=0),
54+
# Optional Parameters
55+
'count':
56+
f.Type(int) | f.Min(1) | f.Optional(default=1),
57+
58+
'index':
59+
f.Type(int) | f.Min(0) | f.Optional(default=0),
60+
61+
'securityLevel':
62+
f.Type(int)
63+
| f.Min(1)
64+
| f.Optional(default=AddressGenerator.DEFAULT_SECURITY_LEVEL),
5265

53-
'seed': f.Required | Trytes(result_type=Seed),
66+
# Required Parameters
67+
'seed':
68+
f.Required | Trytes(result_type=Seed),
5469
},
5570

5671
allow_missing_keys = {
5772
'count',
5873
'index',
74+
'securityLevel',
5975
},
6076
)

0 commit comments

Comments
 (0)