This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from LedgerHQ/cleanup
Cleanup project
- Loading branch information
Showing
5 changed files
with
55 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
FROM python:alpine3.7 | ||
FROM python:3.10-slim | ||
|
||
COPY . /app | ||
WORKDIR /app | ||
RUN apt update && apt upgrade && apt install -y \ | ||
build-essential | ||
RUN pip install -r requirements.txt | ||
CMD python ./recoverMasterSeed.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,54 @@ | ||
from mnemonic.mnemonic import Mnemonic | ||
from functools import reduce | ||
from itertools import count | ||
from bip32utils import BIP32Key, BIP32_HARDEN | ||
from binascii import hexlify, unhexlify | ||
|
||
# parameters | ||
COMPONENTS = [] | ||
m = Mnemonic("english") | ||
from bip_utils import Bip39MnemonicValidator, Bip32Secp256k1, Bip39SeedGenerator | ||
|
||
VAULT_BIP32_PATH = "m/5655636'/4932953'" | ||
|
||
|
||
# util | ||
def xor(*argv): | ||
return bytes(map((lambda x: reduce((lambda a, b: a ^ b), x)), zip(*argv))) | ||
|
||
# get list of seeds | ||
print("Input each Shared Owner recovery mnemonic (24 words) when requested. End with an empty line.") | ||
for i in count(): | ||
|
||
def ask_seeds() -> list[bytes]: | ||
components = [] | ||
print( | ||
"Input each Shared Owner recovery mnemonic (24 words) when requested. End with an empty line." | ||
) | ||
for i in count(): | ||
while True: | ||
words = input(f"Shared Owner {i+1} recovery mnemonic : ") | ||
if len(words) == 0 or m.check(words): | ||
break | ||
print("Invalid 24 words") | ||
if len(words) == 0: | ||
words = input(f"Shared Owner {i + 1} recovery mnemonic: ") | ||
if len(words) == 0 or Bip39MnemonicValidator().IsValid(words): | ||
break | ||
bip32Key = BIP32Key.fromEntropy(m.to_seed(words)).ChildKey(0x80564C54).ChildKey(0x804B4559) | ||
COMPONENTS.append(bip32Key.PrivateKey() + bip32Key.ChainCode()) | ||
print("Invalid 24 words") | ||
if len(words) == 0: | ||
break | ||
|
||
seed = Bip39SeedGenerator(words).Generate() | ||
bip32_key = Bip32Secp256k1.FromSeedAndPath(seed, VAULT_BIP32_PATH) | ||
private_key = bip32_key.PrivateKey().Raw().ToBytes() | ||
chain_code = bip32_key.ChainCode().ToBytes() | ||
components.append(private_key + chain_code) | ||
return components | ||
|
||
if len(COMPONENTS) == 0: | ||
|
||
def main(): | ||
components = ask_seeds() | ||
if len(components) == 0: | ||
print("No shared owner recovery mnemonic provided.") | ||
exit(-1) | ||
|
||
# xor list of seeds | ||
masterSeed = xor(*COMPONENTS) | ||
print(f"Master Seed: {masterSeed.hex()}") | ||
|
||
# Print master seed in xprv format | ||
masterKey = BIP32Key.fromEntropy(masterSeed) | ||
print(f"Master Seed Root Key: {masterKey.ExtendedKey()}") | ||
btc0xprv = masterKey\ | ||
.ChildKey(44+BIP32_HARDEN)\ | ||
.ChildKey(0+BIP32_HARDEN)\ | ||
.ChildKey(0+BIP32_HARDEN)\ | ||
.ExtendedKey() | ||
print(f"Bitcoin account #0 xprv: {btc0xprv}") | ||
return | ||
|
||
# xor list of seeds | ||
master_seed = xor(*components) | ||
print(f"Master Seed: {master_seed.hex()}") | ||
|
||
# Print master seed in xprv format | ||
master_key = Bip32Secp256k1.FromSeed(master_seed) | ||
print(f"Master Seed Root Key: {master_key.PrivateKey().ToExtended()}") | ||
|
||
btc0xprv = master_key.DerivePath("m/44'/0'/0'").PrivateKey().ToExtended() | ||
print(f"Bitcoin account #0 xprv: {btc0xprv}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
pbkdf2==1.3 | ||
mnemonic==0.18 | ||
bip32utils==0.3.post4 | ||
bip-utils==2.3.0 |