我已经从24个单词的助记键中为Alice生成了master pub/priv密钥对。
master_private_key='9f74f4534cbdf01a1f925e20108d86045bd96849af9c94534a10ef2a26ff133b',
master_public_key="0308de0952b00ebc83a41830794534ae912b86d3718832a36ce98c256ab5bfdc4e"
mnemonic='flash city relief spirit federal own metal history great hello toy volcano same subway loan bleak rapid swamp pigeon secret pyramid spoon famous blouse',
同样,我重复了相同的过程来为Bob生成密钥。现在我想从Alice的私钥和Bob的公钥生成diffie-hellman密钥。python中diffie-hellman的所有实现都会生成自己的公钥/私钥对。
ecdh(scalar) -> bytes
compute an EC Diffie-Hellman secret in constant time. The instance
public_key is used as the public point, and the scalar specified must be
composed of 32 bytes. It outputs 32 bytes representing the ECDH secret
computed. If the scalar is invalid, an Exception is raised.
注:只有在支持secp256k1 c库的情况下,才可以使用ecdh。如果没有支持,调用时将引发异常。
我只是不知道如何用libsecp256k1编译这个库。我认为Diffie-Hellman ECC版本更适合这里。
这是我得到的错误:
from sawtooth_signing.secp256k1 import Secp256k1PublicKey
bob_pub='033036dd96b7bef82556fe09eef42bef5e66545317c92a5deca99275f616729fef'
public_key = Secp256k1PublicKey.from_hex(bob_pub)
public_key.secp256k1_public_key.ecdh(alice_private_key)
----------------------
Exception Traceback (most recent call last)
in ()
----> 1 public_key.secp256k1_public_key.ecdh("dsds")
~/SawtoothClient/SawtoothClient/lib/python3.6/site-packages/secp256k1-0.13.2-py3.6-linux-x86_64.egg/secp256k1/__init__.py in ecdh(self, scalar)
305 assert self.public_key, "No public key defined"
306 if not HAS_ECDH:
--> 307 raise Exception("secp256k1_ecdh not enabled")
308 if not isinstance(scalar, bytes) or len(scalar) != 32:
309 raise TypeError('scalar must be composed of 32 bytes')
例外:secp256k1_ecdh未启用
Libraries have been installed in:
/usr/local/lib
现在,当我再次尝试用python 3.6安装secp256k1时,如他们的git页面上所述:
INCLUDE_DIR=include/ LIB_DIR=/usr/local/lib pip install --no-binary secp256k1,
我得到这个错误:
ERROR: You must give at least one requirement to install (see "pip help install")