本文整理汇总了Python中mnemonic.Mnemonic.to_seed方法的典型用法代码示例。如果您正苦于以下问题:Python Mnemonic.to_seed方法的具体用法?Python Mnemonic.to_seed怎么用?Python Mnemonic.to_seed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mnemonic.Mnemonic
的用法示例。
在下文中一共展示了Mnemonic.to_seed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_utf8_nfkd
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def test_utf8_nfkd(self):
# The same sentence in various UTF-8 forms
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
words_nfkc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
words_nfd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
passphrase_nfkd = (
u"Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko"
)
passphrase_nfc = (
u"Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko"
)
passphrase_nfkc = (
u"Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko"
)
passphrase_nfd = (
u"Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko"
)
seed_nfkd = Mnemonic.to_seed(words_nfkd, passphrase_nfkd)
seed_nfc = Mnemonic.to_seed(words_nfc, passphrase_nfc)
seed_nfkc = Mnemonic.to_seed(words_nfkc, passphrase_nfkc)
seed_nfd = Mnemonic.to_seed(words_nfd, passphrase_nfd)
self.assertEqual(seed_nfkd, seed_nfc)
self.assertEqual(seed_nfkd, seed_nfkc)
self.assertEqual(seed_nfkd, seed_nfd)
示例2: processNext
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def processNext(self):
self.persoData['seed'] = None
if self.ui.RestoreWalletButton.isChecked():
# Check if it's an hexa string
seedText = str(self.ui.seed.text())
if len(seedText) == 0:
QMessageBox.warning(self, "Error", "Please enter a seed", "OK")
return
if seedText[-1] == 'X':
seedText = seedText[0:-1]
try:
self.persoData['seed'] = seedText.decode('hex')
except:
pass
if self.persoData['seed'] == None:
if not MNEMONIC:
QMessageBox.warning(self, "Error", "Mnemonic API not available. Please install https://github.com/trezor/python-mnemonic", "OK")
return
if not self.mnemonic.check(seedText):
QMessageBox.warning(self, "Error", "Invalid mnemonic", "OK")
return
self.persoData['seed'] = Mnemonic.to_seed(seedText)
else:
if (len(self.persoData['seed']) < 32) or (len(self.persoData['seed']) > 64):
QMessageBox.warning(self, "Error", "Invalid seed length", "OK")
return
dialog = SecurityDialog(self.persoData, self)
self.hide()
dialog.exec_()
示例3: testvectors
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def testvectors():
"""
This function exercises the libraries and double checks that they are
returning expected data.
"""
print "Self Checking",
print_dot()
if "51477815b762e495e0f7deb01fb2969f2e15ba4615fa4a5aafc23ccf5c3c8bd2".decode('hex') != \
privkey_to_pubkey("12fab77add10bcabe1b62b3fe8b167e966e4beee38ccf0062fdd207b5906c841".decode('hex'), False):
return False
print_dot()
doublecheck_key_works("12fab77add10bcabe1b62b3fe8b167e966e4beee38ccf0062fdd207b5906c841".decode('hex'), \
"51477815b762e495e0f7deb01fb2969f2e15ba4615fa4a5aafc23ccf5c3c8bd2".decode('hex'), False)
print_dot()
if "51477815-b762e495-e0f7deb0-1fb2969f-2e15ba46-15fa4a5a-afc23ccf-5c3c8bd2-6c4cf980" != \
pubkey_to_send("51477815b762e495e0f7deb01fb2969f2e15ba4615fa4a5aafc23ccf5c3c8bd2".decode('hex'), False):
return False
print_dot()
if "Fs1Ts7PsKMwo4ftCYxQJ3rW4pLiRBXyGEjMrxtHycLu52aDgKGEy" != \
private_key_to_human("12fab77add10bcabe1b62b3fe8b167e966e4beee38ccf0062fdd207b5906c841".decode('hex'), False):
return False
print_dot()
if not onlyB58chars("Xw1"):
return False
if onlyB58chars("$"):
return False
print_dot()
if "4f4488c609552caf2c7a508108809518e9a1ab3ae6dc259a1e2e9989d053018d".decode('hex') != \
hashlib.sha256(hashlib.sha256("647812fab77add10bcabe1b62b3fe8b167e966e4beee38ccf0062fdd207b5906c841" \
.decode('hex')).digest()).digest():
return False
print_dot()
if True != verify_koinify_words("legal winner thank year wave sausage worth useful legal winner thank yellow"):
return False
print_dot()
if True == verify_koinify_words("legal winner thank year wave sausage worth useful legal winner thank thank"):
return False
print_dot()
if "878386efb78845b3355bd15ea4d39ef97d179cb712b77d5c12b6be415fffeffe5f377ba02bf3f8544ab800b955e51fbff09828f682052a20faa6addbbddfb096" \
.decode('hex') != Mnemonic.to_seed("legal winner thank year wave sausage worth useful legal winner thank yellow", ''):
return False
print_dot()
if "0488ade4000000000000000000598b4595ea72802756519e65a797234231d7d4f13d650cb06db15957c2368b1b007e56ecf5943d79e1f5f87e11c768253d7f3fcf30ae71335611e366c578b4564e"\
.decode('hex') != BIP32Key.fromEntropy("878386efb78845b3355bd15ea4d39ef97d179cb712b77d5c12b6be415fffeffe5f377ba02bf3f8544ab800b955e51fbff09828f682052a20faa6addbbddfb096"\
.decode('hex'), public=False).ExtendedKey(private=True, encoded=False):
return False
print_dot()
if "7999d61b8f5efc24b437244ff82b69ba474deeadbf144421f05d5b4b5ab20a8e".decode('hex') != \
koinify_words_to_private_key("legal winner thank year wave sausage worth useful legal winner thank yellow", False):
return False
print("\n")
# everything checks out ok
return True
示例4: process
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def process(data, lst):
code = mnemo.to_mnemonic(unhexlify(data))
seed = b2h(Mnemonic.to_seed(code, passphrase = 'TREZOR'))
print('input : %s (%d bits)' % (data, len(data) * 4))
print('mnemonic : %s (%d words)' % (code, len(code.split(' '))))
print('seed : %s (%d bits)' % (seed, len(seed) * 4))
print()
lst.append((data, code, seed))
示例5: _check_list
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def _check_list(self, language, vectors):
mnemo = Mnemonic(language)
for v in vectors:
code = mnemo.to_mnemonic(unhexlify(v[0]))
seed = hexlify(Mnemonic.to_seed(code, passphrase = 'TREZOR'))
self.assertIs(mnemo.check(v[1]), True)
self.assertEqual(v[1], code)
self.assertEqual(v[2], seed)
示例6: process
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def process(ctr, p_hex):
print '(%i)' % ctr
print 'input : %s (%d bits)' % (p_hex, len(p_hex) * 4)
p_mnemonic = mnemo.to_mnemonic(unhexlify(p_hex))
print 'mnemonic : %s (%d words)' % (p_mnemonic, len(p_mnemonic.split(' ')))
p_seed = hexlify(Mnemonic.to_seed(p_mnemonic, passphrase = ''))
print 'seed : %s (%d bits)' % (p_seed, len(p_seed) * 4)
示例7: process
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def process(data, lst, mnemo):
code = mnemo.to_mnemonic(unhexlify(data))
_seed = Mnemonic.to_seed(code, passphrase='TREZOR')
xprv = BIP32Key.fromEntropy(_seed).ExtendedKey()
_seed = b2h(_seed)
print('input : %s (%d bits)' % (data, len(data) * 4))
print('mnemonic : %s (%d words)' % (code, len(code.split(' '))))
print('seed : %s (%d bits)' % (_seed, len(_seed) * 4))
print('xprv : %s\n' % xprv)
lst.append((data, code, _seed, xprv))
示例8: process
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def process(data, lst):
code = mnemo.to_mnemonic(unhexlify(data))
seed = Mnemonic.to_seed(code, passphrase="TREZOR")
xprv = BIP32Key.fromEntropy(seed).ExtendedKey()
seed = b2h(seed)
print("input : %s (%d bits)" % (data, len(data) * 4))
print("mnemonic : %s (%d words)" % (code, len(code.split(" "))))
print("seed : %s (%d bits)" % (seed, len(seed) * 4))
print("xprv : %s" % xprv)
print()
lst.append((data, code, seed, xprv))
示例9: showDetails
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def showDetails(mnemonic, passphrase="", i=1):
myMnemonic = mnemonic
passphrase = passphrase
mnemo = Mnemonic('english')
seed = hexlify(mnemo.to_seed(myMnemonic, passphrase=passphrase))
print 'Seed:\t\t\t\t', seed
priv = bitcoin.bip32_master_key(unhexlify(seed))
print 'Xpriv:\t\t\t\t', priv
key = bitcoin.encode_privkey(bitcoin.bip32_extract_key(priv), 'wif_compressed')
print 'Key:\t\t\t\t', key
pub = bitcoin.bip32_privtopub(priv)
print 'Derived public key:\t', pub
pubHex = bitcoin.bip32_extract_key(pub)
print 'public key (hex):\t', pubHex
print 'Master Key address:\t', bitcoin.pubtoaddr(pubHex)
print ""
print "TREZOR Keys:"
account = 0
derivedPrivateKey = bitcoin.bip32_ckd(bitcoin.bip32_ckd(bitcoin.bip32_ckd(priv, 44+HARDENED), HARDENED), HARDENED+account)
print 'Derived private key:', derivedPrivateKey
privateKey = bitcoin.encode_privkey(bitcoin.bip32_extract_key(derivedPrivateKey), 'wif_compressed')
print 'private key (wif):\t', privateKey
derivedPublicKey = bitcoin.bip32_privtopub(derivedPrivateKey)
print 'Derived public key:', derivedPublicKey
publicKeyHex = bitcoin.privtopub(privateKey)
print 'public key (hex):\t', publicKeyHex
address = bitcoin.pubtoaddr(publicKeyHex)
print 'address:\t\t\t', address
print ""
print "Account public keys (XPUB)"
xpubs = []
for i in range(0, i):
derivedPrivateKey = bitcoin.bip32_ckd(bitcoin.bip32_ckd(bitcoin.bip32_ckd(priv, 44+HARDENED), HARDENED), HARDENED+i)
xpub = bitcoin.bip32_privtopub(derivedPrivateKey)
print 'Account', i, 'xpub:', xpub
xpubs.append(xpub)
return xpubs
示例10: _check_list
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def _check_list(self, language, vectors):
mnemo = Mnemonic(language)
for v in vectors:
code = mnemo.to_mnemonic(unhexlify(v[0]))
seed = hexlify(Mnemonic.to_seed(code, passphrase="TREZOR"))
xprv = Mnemonic.to_hd_master_key(unhexlify(seed))
if sys.version >= "3":
seed = seed.decode("utf8")
self.assertIs(mnemo.check(v[1]), True)
self.assertEqual(v[1], code)
self.assertEqual(v[2], seed)
self.assertEqual(v[3], xprv)
示例11: getXPRIVKeys
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def getXPRIVKeys(mnemonic, passphrase="", i=1):
myMnemonic = mnemonic
passphrase = passphrase
mnemo = Mnemonic('english')
seed = hexlify(mnemo.to_seed(myMnemonic, passphrase=passphrase))
priv = bitcoin.bip32_master_key(unhexlify(seed))
account = 0
#derivedPrivateKey = bitcoin.bip32_ckd(bitcoin.bip32_ckd(bitcoin.bip32_ckd(priv, 44+HARDENED), HARDENED), HARDENED+account)
xprivs = []
for i in range(0, i):
derivedPrivateKey = bitcoin.bip32_ckd(bitcoin.bip32_ckd(bitcoin.bip32_ckd(priv, 44+HARDENED), HARDENED), HARDENED+i)
xprivs.append(derivedPrivateKey)
return xprivs
示例12: koinify_words_to_private_key
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def koinify_words_to_private_key(entered_words, advanced):
"""
This function takes in a string with 12 words.
It returns an ed25519 private key in binary format
It uses the same algorithm used in the
Koinify wallet during the factoid sale.
The advanced parameter set to true displays technical internal data
"""
seed = Mnemonic.to_seed(entered_words, '')
rootkey = BIP32Key.fromEntropy(seed, public=False)
factoidChildKey = rootkey.ChildKey(BIP32_HARDEN+7)
last32 = factoidChildKey.ExtendedKey(private=True, encoded=False)[-32:]
if advanced == True:
print "seed derived from words: " + seed.encode('hex')
print "BIP32 root key: " + rootkey.ExtendedKey(private=True, encoded=False).encode('hex')
print "BIP32 root of Factoid chain key: " + factoidChildKey.ExtendedKey(private=True, encoded=False).encode('hex')
print "Last 32 bytes, ed25519 private key: " + last32.encode('hex')
return last32
示例13: key
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
from binascii import hexlify, unhexlify
from mnemonic import Mnemonic
from bip32utils.BIP32Key import *
import ed25519
#Replace secret words from koinify wallet below
words = "legal winner thank year wave sausage worth useful legal winner thank yellow"
#uncomment print statements below to see interim datapoints
seed = Mnemonic.to_seed(words, '')
#print "seed derived from words: " + hexlify(seed)
rootkey = BIP32Key.fromEntropy(seed, public=False)
#print "BIP32 root key: " + rootkey.ExtendedKey(private=True, encoded=False).encode('hex')
factoidChildKey = rootkey.ChildKey(BIP32_HARDEN+7)
#print "BIP32 root of Factoid chain key: " + factoidChildKey.ExtendedKey(private=True, encoded=False).encode('hex')
last32 = factoidChildKey.ExtendedKey(private=True, encoded=False)[-32:]
#print "Last 32 bytes: " + last32.encode('hex')
signing_key = ed25519.SigningKey(last32)
#print "The private key (ed25519 seed k) is: " + signing_key.to_ascii(encoding="hex")
verifying_key = signing_key.get_verifying_key()
pubkeyHex = verifying_key.to_ascii(encoding="hex")
#print "The public key is: " + pubkeyHex
示例14: BIP39_to_seed
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
def BIP39_to_seed(words):
seed = hexlify(Mnemonic.to_seed(words))
return seed
示例15: PollyAudit
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_seed [as 别名]
class PollyAudit():
"""
Auditing tests and utilities for Polly.
"""
def __init__(self, wordfile = 'wordlist.txt'):
# Read create the mnemonic wordlist object
self.mnemonic = Mnemonic("english")
# Set up a default reference wallet
self.wallet = Wallet.from_master_secret(bytes(0))
# Set up a Polly communication pipe
self.polly = PollyCom()
# Default print padding
self.PAD = "{:35}"
#
# Tests
#
def test_set_seed(self, wordlist):
"""
Sets the wallet seed for Polly and the reference wallet.
Note: Subsequent tests will use the seed set by this routine.
wordlist - a space separated string of 18 mnemonic words from the Polly wordlist.
Note: the checksum must be correct (part of the 18th word) - see BIP0039.
gen_wordlist can be used to generate a wordlist including the proper checksum.
"""
assert len(wordlist.split(" ")) == 18, "expecting 18 words"
assert self.mnemonic.check(wordlist) == True, "invalid word list"
print (self.PAD.format("Set seed"), end='')
# Set polly
self.polly.send_set_master_seed(wordlist)
print (self.__outok())
# Set the reference wallet
seed = self.mnemonic.to_seed(wordlist)
self.wallet = Wallet.from_master_secret(seed)
def test_key(self, keytype, account = 0, chain = 0, address = 0):
"""
Performs a public key retrieval test, comparing Polly's key against the reference wallet.
keytype - Type of key to retrieve, valid values are KEY_MASTER, KEY_ACCOUNT, KEY_CHAIN, or KEY_ADDRESS.
account - Account to use for type KEY_ACCOUNT, KEY_CHAIN, KEY_ADDRESS.
chain - Chain to use for type KEY_CHAIN, KEY_ADDRESS.
address - Index (0 - 0x7FFFFFFF) to use for type KEY_ADDRESS.
"""
assert address < 0x80000000, "hardened address keys are not supported"
if keytype == PollyCom.KEY_MASTER:
print(self.PAD.format("Get master key"), end='')
refkey = self.wallet
check_chaincode = False
elif keytype == PollyCom.KEY_ACCOUNT:
print(self.PAD.format("Get account key m/" + str(account) + "h"), end='')
refkey = self.wallet.subkey(account, is_hardened = True)
check_chaincode = True
elif keytype == PollyCom.KEY_CHAIN:
print(self.PAD.format("Get chain key m/" + str(account) + "h/" + str(chain)), end='')
refkey = self.wallet.subkey(account, is_hardened = True).subkey(chain)
check_chaincode = True
else: # keytype == PollyCom.KEY_ADDRESS
print(self.PAD.format("Get address key m/" + str(account) + "h/" + str(chain) + "/" + str(address)), end='')
refkey = self.wallet.subkey(account, is_hardened = True).subkey(chain).subkey(address)
check_chaincode = False
# Get keypair from Polly
(pubx, puby, chaincode) = self.polly.send_get_public_key(keytype, account, chain, address)
print (self.__outok())
# Check against reference wallet
addr = encoding.public_pair_to_hash160_sec((pubx, puby))
addr_check = encoding.public_pair_to_hash160_sec(refkey.public_pair)
assert addr == addr_check, "public key mismatch\nexpected: " + self.hexstr(addr_check) + "\nactual: " + self.hexstr(addr)
if check_chaincode == True :
assert refkey.chain_code == chaincode, "chain code mismatch\nexpected: " + self.hexstr(refkey.chain_code) + "\nactual: " + self.hexstr(chaincode)
def test_sign(self, keynums_satoshi, out_addr, out_satoshi, change_keynum, change_satoshi, prevtx_keynums, prevtx_outputs, prevtx_inputs):
"""
#.........这里部分代码省略.........