forked from iota-community/python-iota-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe00_generate_seed.py
More file actions
29 lines (25 loc) · 1.4 KB
/
Copy pathe00_generate_seed.py
File metadata and controls
29 lines (25 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# This example generates a new mnemonic using iota_wallet library.
# This step is not necessary since in the following examples is an "example" seed provided.
# However, if you want to try this workshop with the Firefly wallet, you may want to use this example file.
# In that case, import the generated Mnemonic in the Firefly wallet and replace Seed values in the following exercises
# with the generated Seed.
# YOU SHOULD NEVER TRUST 3RD PARTY TOOLS/PROGRAMS WITH YOUR SEED/MNEMONIC!
# USE THE PRIVATE KEYS GENERATED BY THIS EXAMPLE ONLY IN THIS WORKSHOP!
# IN PRACTISE, NEVER STORE YOUR PRIVATE KEYS IN YOUR CODE. USE ENVIROMENT VARIABLES!
import binascii
import hashlib
import unicodedata
import iota_wallet
# Creates an AccountManager class from iota_wallet library to generate a mnemonic
mnemonic = iota_wallet.AccountManager(storage_path='./storage').generate_mnemonic()
# iota_wallet's AccountManager creates its own ./storage folder. We won't need it for this workshop
# since we will be using iota_client, that uses Seed instead of Accounts stored in Stronghold.
# Feel free to remove that folder if it was created BY THIS WORKSHOP (not by you or your applications)
seed = hashlib.pbkdf2_hmac(
"sha512",
unicodedata.normalize("NFKD", mnemonic).encode("utf-8"),
"mnemonic".encode("utf-8"),
2048
)
print(f'Generated mnemonic: {mnemonic}')
print(f'Generated seed: {binascii.hexlify(seed).decode("utf-8")}')