Skip to content

Commit d79e962

Browse files
committed
Check for "known" seed entropy, and add watermark to SLIP-39 output
o Start by reorganizing, and add tests for some known entropy o Begin to add copyright headers
1 parent 0e7883d commit d79e962

21 files changed

+1544
-1161
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else
4141
endif
4242

4343
# To see all pytest output, uncomment --capture=no
44-
PYTESTOPTS = -vv --doctest-modules --capture=no --log-cli-level=INFO
44+
PYTESTOPTS = -vv --doctest-modules --capture=no # --log-cli-level=INFO
4545

4646
PY3TEST = $(PY3) -m pytest $(PYTESTOPTS)
4747

slip39/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2+
#
3+
# Python-slip39 -- Ethereum SLIP-39 Account Generation and Recovery
4+
#
5+
# Copyright (c) 2022, Dominion Research & Development Corp.
6+
#
7+
# Python-slip39 is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU General Public License as published by the Free Software
9+
# Foundation, either version 3 of the License, or (at your option) any later
10+
# version. It is also available under alternative (eg. Commercial) licenses, at
11+
# your option. See the LICENSE file at the top of the source tree.
12+
#
13+
# Python-slip39 is distributed in the hope that it will be useful, but WITHOUT
14+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16+
#
17+
118
from .version import __version__, __version_info__ # noqa F401
219
from .api import * # noqa F403
320
from .layout import * # noqa F403

slip39/api.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2+
#
3+
# Python-slip39 -- Ethereum SLIP-39 Account Generation and Recovery
4+
#
5+
# Copyright (c) 2022, Dominion Research & Development Corp.
6+
#
7+
# Python-slip39 is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU General Public License as published by the Free Software
9+
# Foundation, either version 3 of the License, or (at your option) any later
10+
# version. It is also available under alternative (eg. Commercial) licenses, at
11+
# your option. See the LICENSE file at the top of the source tree.
12+
#
13+
# Python-slip39 is distributed in the hope that it will be useful, but WITHOUT
14+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16+
#
17+
118
import base58
219
import codecs
320
import hashlib
@@ -226,7 +243,7 @@ def p2pkh_address( self ):
226243

227244
class Account:
228245
"""A Cryptocurrency "Account" / Wallet, based on a variety of underlying Python crypto-asset
229-
support modules. Presently, only meherett/python-hdwallet is used
246+
support modules. Presently, only meherett/python-hdwallet is used.
230247
231248
An appropriate hdwallet-like wrapper is built, for any crypto-asset supported using another
232249
module. The required hdwallet API calls are:
@@ -441,11 +458,15 @@ def from_path( self, path: str = None ) -> "Account":
441458

442459
@property
443460
def address( self ):
444-
if self.format == "legacy":
461+
"""Returns the 1..., 3... or bc1... address, depending on whether format is legacy, segwit or bech32"""
462+
return self.formatted_address()
463+
464+
def formatted_address( self, format=None ):
465+
if ( format or self.format or '' ).lower() == "legacy":
445466
return self.legacy_address()
446-
elif self.format == "segwit":
467+
elif ( format or self.format or '' ).lower() == "segwit":
447468
return self.segwit_address()
448-
elif self.format == "bech32":
469+
elif ( format or self.format or '' ).lower() == "bech32":
449470
return self.bech32_address()
450471
raise ValueError( f"Unknown addresses semantic: {self.format}" )
451472

@@ -495,10 +516,19 @@ def path( self ):
495516
def key( self ):
496517
return self.hdwallet.private_key()
497518

519+
@property
520+
def xkey( self ):
521+
return self.hdwallet.xprivate_key()
522+
498523
@property
499524
def pubkey( self ):
500525
return self.hdwallet.public_key()
501526

527+
@property
528+
def xpubkey( self ):
529+
"""Returns the xpub, ypub or zpub, depending on whether format is legacy, segwit or bech32"""
530+
return self.hdwallet.xpublic_key()
531+
502532
def from_private_key( self, private_key ):
503533
self.hdwallet.from_private_key( private_key )
504534
return self
@@ -976,8 +1006,8 @@ def accountgroups(
9761006
yield from zip( *[
9771007
accounts(
9781008
master_secret = master_secret,
979-
paths = paths,
9801009
crypto = crypto,
1010+
paths = paths,
9811011
allow_unbounded = allow_unbounded,
9821012
)
9831013
for crypto,paths in cryptopaths_parser( cryptopaths )

slip39/defaults.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
#
33
# Python-slip39 -- Ethereum SLIP-39 Account Generation and Recovery
44
#
5-
# Copyright (c) 2021, Dominion Research & Development Corp.
5+
# Copyright (c) 2022, Dominion Research & Development Corp.
66
#
77
# Python-slip39 is free software: you can redistribute it and/or modify it under
88
# the terms of the GNU General Public License as published by the Free Software
99
# Foundation, either version 3 of the License, or (at your option) any later
10-
# version. See the LICENSE file at the top of the source tree.
10+
# version. It is also available under alternative (eg. Commercial) licenses, at
11+
# your option. See the LICENSE file at the top of the source tree.
1112
#
1213
# Python-slip39 is distributed in the hope that it will be useful, but WITHOUT
1314
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1415
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1516
#
1617

18+
__author__ = "Perry Kundert"
19+
__email__ = "[email protected]"
20+
__copyright__ = "Copyright (c) 2022 Dominion Research & Development Corp."
21+
__license__ = "Dual License: GPLv3 (or later) and Commercial (see LICENSE)"
22+
1723
#
1824
# HD Wallet Derivation Paths (Standard BIP-44 / Trezor)
1925
#
@@ -122,6 +128,8 @@
122128
# Default Crypto accounts (and optional paths) to generate
123129
CRYPTO_PATHS = ('ETH', 'BTC')
124130

131+
__d = "55"
132+
__m = "88"
125133
__o = "BB"
126134
__h = "DD"
127135
__f = "FF"
@@ -145,5 +153,20 @@
145153
f"0x{__o}{__h}{__h}", # Light Cyan
146154
f"0x{__h}{__o}{__h}", # Light Magenta
147155
f"0x{__h}{__h}{__o}", # Light Yellow
156+
# Greys
148157
f"0x{__h}{__h}{__h}", # Light grey,
158+
f"0x{__m}{__m}{__m}", # Medium grey,
159+
f"0x{__d}{__d}{__d}", # Dark grey,
160+
]
161+
162+
# Include any known seed bit sequences here; any seed containing any of these
163+
# segments will be printed with a "watermark" indicating that the seed is
164+
# invalid, indicating that it should probably not be used! These are clearly
165+
# non-random sequences of bits, or sequences known to be part of publicly
166+
# disclosed test sequences. The probability of these sequences showing up in a
167+
# legitimate, random seed is about 1 in 2^40 =~= 1 Trillion.
168+
KNOWN_SEQUENCES = [
169+
40 * "1",
170+
40 * "0",
171+
20 * "01",
149172
]

slip39/generator_test.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,3 @@ def read( self, size=1 ):
125125
file = ser
126126
):
127127
logging.info( f"Receive: {group}" )
128-
129-
130-
# def transmitter():
131-
132-
133-
# yield from addresses(
134-
# master_secret = b"\xFF" * 16,
135-
# paths
136-
137-
138-
# def test_serial_xonxoff():
139-
# """Ensure that flow-control works. The idealy secure solution is to use hardware RTS/CTS flow
140-
# control, with no tx circuit. However, even a regular serial link with software XON/XOFF flow
141-
# control is much more secure than a network-connected peer."""

slip39/known/__init__.py

Whitespace-only changes.

slip39/known/__main__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
#
3+
# Python-slip39 -- Ethereum SLIP-39 Account Generation and Recovery
4+
#
5+
# Copyright (c) 2022, Dominion Research & Development Corp.
6+
#
7+
# Python-slip39 is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU General Public License as published by the Free Software
9+
# Foundation, either version 3 of the License, or (at your option) any later
10+
# version. It is also available under alternative (eg. Commercial) licenses, at
11+
# your option. See the LICENSE file at the top of the source tree.
12+
#
13+
# Python-slip39 is distributed in the hope that it will be useful, but WITHOUT
14+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16+
#
17+
18+
import sys
19+
20+
from .main import main
21+
22+
sys.exit( main() )

slip39/known/generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
if __name__ == "__main__":
4+
sys.exit( main() )

slip39/known/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
from ..recovery.main import main as recovery_main
3+
4+
def main( argv=None ):
5+
"""Produce all "known" seeds, both in raw and BIP-39 encoded form (w/ no password). We'll get
6+
these from BIP-39 and SLIP-39 test vectors.
7+
8+
Finds all .bip39 and .slip39 files
9+
10+
"""
11+
12+
#for bip39 in
13+
14+
return 0

0 commit comments

Comments
 (0)