The Binance DEX Python Crypto Package provides capabilities to manage keys locally
Step1:
Create Crypto instance
from binance_dex.crypto import BinanceChainCrypto
crypto_instance = BinanceChainCrypto(is_test_net)
NOTES:
class BinanceChainCrypto
has one positional argument during initializing:
- If
is_test_net = True
, Encapsulation of a Bitcoin ECDSA public key, addressprefix = 'tbnb'
, otherwiseprefix = 'bnb'
Step2:
call the specific function
crypto_instance.generate_XXX()
Service Name | WebSockets |
---|---|
generate_mnemonic | √ |
generate_key | √ |
generate_key_from_mnemonic | √ |
generate_keys_from_mnemonic | √ |
√: Able to Use ◯: Unfinished ⊖:Unstable ×: Official Unsupported
The following document list the funcs in class BinanceChainCrypto
.
- Genereate Mnemonic words as string. Binance chain using
strength=256
, will return24
words.
Sample Return :
> crypto_instance.generate_mnemonic()
party wear unknown cause cement select wood veteran spoon spider paddle stumble twist length fly budget helmet
pilot robust brand public boat define battle
WARNING:
PLEASE TAKE GOOD CARE OF YOUR OWN MNEMONIC WORDS. ANY LEAK OF THE MNEMONIC WORDS MAY CAUSE ENORMOUS AND IRREVERSIBLE
LOSSES OF YOUR WALLET PROPERTY.
Brief algorithm flow chart refer to bip-39:
The mnemonic must encode entropy in a multiple of 32 bits.
With more entropy security is improved but the sentence length increases.
We refer to the initial entropy length as ENT. The allowed size of ENT is 128-256 bits.
First, an initial entropy of ENT bits is generated. A checksum is generated by taking the first
ENT / 32
bits of its SHA256 hash. This checksum is appended to the end of the initial entropy.
Next, these concatenated bits are split into groups of 11 bits, each encoding a number from 0-2047,
serving as an index into a wordlist. Finally, we convert these numbers into words and use the
joined words as a mnemonic sentence.
The following table describes the relation between the initial entropy length (ENT), the checksum length (CS) and the length of the generated mnemonic sentence (MS) in words.
CS = ENT / 32
MS = (ENT + CS) / 11
ENT | CS | ENT+CS | MS |
---|---|---|---|
128 | 4 | 132 | 12 |
160 | 5 | 165 | 15 |
192 | 6 | 198 | 18 |
224 | 7 | 231 | 21 |
256 | 8 | 264 | 24 |
More information bip39.
- Generate Private Key, Public Address and mnemonic.
Sample Return :
> crypto_instance.generate_key()
{'private_key': '33b1ffceb5a80e4436035f71573b3198e5dff64bc1d620625d3ae94ca9cexxxx',
'public_address': 'bnb1xzx5lungjnlc8fmx7qa7c7njxsqphcr7y9j9za',
'mnemonic': 'world supply word message critic woman donate romance sleep safe voyage faint maid utility fish
shuffle offer pulse tail owner burger vicious until xxxxx'
}
- Generate Private Key, Public Address from mnemonic words.
Sample Return :
> mnemonic_words = crypto_instance.generate_mnemonic()
> crypto_instance.generate_key_from_mnemonic(mnemonic_words)
{'private_key': '0225fb7752873b93f3bf9afc8a3bdd35e9052e04e21ffd91e42d8aa45a5xxxxx',
'public_address': 'bnb1ejk8eah9ct5rgl3k4s4kqc3udf7jy9qvzjw56m'
}
- Generat bunch of Private Keys, Public Address from one set of Mnemonic words.
Sample Return :
> mnemonic_words = crypto_instance.generate_mnemonic()
> crypto_instance.generate_keys_from_mnemonic(mnemonic_words, 10)
[{'private_key': 'bedd712859eb0c6c3519dcae1749088e2168b545844f5fb6a93f97fef44xxxxx',
'public_address': 'tbnb1uj5056ys4ssr4zdzq9c7n92yndd5e5hm5m77nl'},
{'private_key': '0b303f09175ce3ab018cafb84caee1d15a7fc5862f40302f8a5ee181b48xxxxx',
'public_address': 'tbnb1j93zkpj7u03g4s240h5n6wf8ttdesau6s2sl97'},
{'private_key': 'a6ba3f2efbb229e774f89c8d793f1d24be8b7270e43f04d39724936cc9dxxxxx',
'public_address': 'tbnb1v9unkets8tj44m075pfqeefvd0e930jm82ryl9'},
...
{'private_key': 'e287292e5f8c65bb59528e372bf8fe90972e02ffd3da085677140ef3e90xxxxx',
'public_address': 'tbnb1muln7lrsl4y7mmt07rplevzfsvkfgdunm2f42k'}
]
NOTES:
Current func only realize to Depth=1
, which means derivation from mnemonic words stops at Wallets/Accounts
, and
each wallet has its own Private key and Public Address. (depth=3
need further work)