首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何根据记忆短语验证创建的钱包?

如何根据记忆短语验证创建的钱包?
EN

Stack Overflow用户
提问于 2021-12-08 20:58:15
回答 1查看 546关注 0票数 0

我用bitcoinlib创建了一个钱包。这个钱包的名字叫“我的-太棒了-华尔特55”当我试图用一个新生成的助记符短语打开我现有的钱包时,我期望的行为是一个例外或安全错误,但是钱包无论如何都会打开。我可以手动检查私钥以创建我自己的安全检查,但是尝试打开带有错误密钥的现有钱包不应该失败吗?否则似乎是个相当大的安全问题。

代码语言:javascript
复制
    from bitcoinlib.wallets import Wallet, wallet_create_or_open
    from bitcoinlib.keys import HDKey
    from bitcoinlib.mnemonic import Mnemonic

    # Creating a new Mnemonic phrase to try and open an existing wallet with
    passphrase=Mnemonic().generate(strength=256, add_checksum=True)

    # Use new phrase to create key
    key = HDKey.from_passphrase(passphrase, witness_type='segwit', network='testnet')

    # In my opinion this should fail because I provided the wrong key, but it returns the wallet
    w = Wallet('my-awesome-wallet55', main_key_object=key)

    # Statement showing that our private keys are different
    print("key.private_hex: " + key.private_hex + "\nw.main_key.key_private.hex(): " + 
    w.main_key.key_private.hex()) 

    if key.private_hex == w.main_key.key_private.hex():
        # We don't make it here because our private keys don't match
        print("Wallet 'my-awesome-wallet55' authenticated")
        w.utxos_update()
        print("Balance: " + str(w.balance()))
        print("Wallet address: " + w.get_key().address)
        w.info()
    else:
        # Instead we make it here and still have access to the wallet
        print("Wallet Authentication failed")
        w.utxos_update()
        print("Balance: " + str(w.balance()))
        print("Wallet address: " + w.get_key().address)
        w.info()

是否有使用bitcoinlib验证钱包的标准方法?根据我这里的情况,似乎有人只需要知道钱包的名字就可以完全访问它。

更新:

在得到Frank的问题后,我更新了代码,尝试发送一个事务:

代码语言:javascript
复制
from bitcoinlib.wallets import Wallet, wallet_create_or_open
from bitcoinlib.keys import HDKey
from bitcoinlib.mnemonic import Mnemonic

passphrase=Mnemonic().generate(strength=256, add_checksum=True)
#passphrase='lumber romance negative child immense grab icon wasp silver essay enjoy jewel mom demise fit moral device hand capable toilet spirit age enforce deny'
print(passphrase)

key = HDKey.from_passphrase(passphrase, witness_type='segwit', network='testnet')
#wallet_create_or_open('my-awesome-wallet55', keys=passphrase, witness_type='segwit', network='testnet')
w = Wallet('my-awesome-wallet55', main_key_object=key)

print("key.private_hex: " + key.private_hex + "\nw.main_key.key_private.hex(): " + w.main_key.key_private.hex()) 

if key.private_hex == w.main_key.key_private.hex():
    print("Wallet 'my-awesome-wallet55' authenticated")
    w.utxos_update()
    print("Balance: " + str(w.balance()))
    t = w.send_to('tb1qprqnf4dqwuphxs9xqpzkjdgled6eeptn389nec', 4000, fee=1000)
    t.info()
else:
    print("Wallet Authentication failed")
    w.utxos_update()
    print("Balance: " + str(w.balance()))
    t = w.send_to('tb1qprqnf4dqwuphxs9xqpzkjdgled6eeptn389nec', 4000, fee=1000)
    t.info()

以下是研究结果:

代码语言:javascript
复制
Sonnys-MBP:TelegramBTCWallet sonnyparlin $ python test.py 
unfold royal atom rule electric ice quote spin fiber quality lady just garment nature secret six garden comic carpet mom endless lamp family arctic
key.private_hex: 23ac38dc5293ee53918c8dfe18abc28975c8fa6963c876302aa4473ddca2f14a
w.main_key.key_private.hex(): 8c11283bf21e9344930ab9519742d6f59cd220528e0be17886d27a21c9c127c7
Wallet Authentication failed
Balance: 95000.0
Transaction 5e729021da81a5e6fc3b3d88b5bf136d09c78b0ac9a08be2cf1c90107e7ae27c
Date: None
Network: testnet
Version: 1
Witness type: segwit
Status: unconfirmed
Verified: True
Inputs
- tb1q7dx79l3maq2cqynpjzxqxsk3v6jhhaggzl07c3 0.00095000 tBTC badb9dbe2b4741310137de774e058aaf6cbba28e2f36c11640b241284f780f86 1
  segwit sig_pubkey; sigs: 1 (1-of-1) valid
Outputs
- tb1qprqnf4dqwuphxs9xqpzkjdgled6eeptn389nec 0.00004000 tBTC p2wpkh U
- tb1q9wg0vnqx63ng39s80gwqqffe2z7c5vvh0f4h3g 0.00090000 tBTC p2wpkh U
Size: 139
Vsize: 139
Fee: 1000
Confirmations: 0
Block: None
Pushed to network: True
Wallet: my-awesome-wallet55
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-11 19:10:33

我将此作为bug发布给bitcoinlib开发人员,他们确认了这一点,您可以在下面这样做:

https://github.com/1200wd/bitcoinlib/issues/206#issuecomment-991265402

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70281626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档