如何对Tezos公钥进行哈希处理
4 个回答
- 投票数
-
- 2020-01-16
此处介绍了如何在python中执行此操作,其中变量
pubkey
是公钥的字节数组P2HASH_MAGIC = bytes.fromhex('06a1a4') blake2bhash = blake2b(pubkey, digest_size=20).digest() shabytes = sha256(sha256(P2HASH_MAGIC + blake2bhash).digest()).digest()[:4] pkhash = b58encode(P2HASH_MAGIC + blake2bhash + shabytes).decode()
Heres how to do it in python, where the variable
pubkey
is the bytes array of the public keyP2HASH_MAGIC = bytes.fromhex('06a1a4') blake2bhash = blake2b(pubkey, digest_size=20).digest() shabytes = sha256(sha256(P2HASH_MAGIC + blake2bhash).digest()).digest()[:4] pkhash = b58encode(P2HASH_MAGIC + blake2bhash + shabytes).decode()
-
谢谢,太好了.您是否愿意通过添加解释那里发生的情况的评论来改善该答案?例如-什么是P2HASH_MAGIC以及为什么我们在第3行中切出一些字节.Thanks, that's great. Would you mind to improve that answer by adding comments explaining what happens there? For example - what is P2HASH_MAGIC and why do we cut out some bytes in line 3.
- 0
- 2020-01-16
- K SS
-
b58encode的输入将是51个字节长(" P2HASH_MAGIC"是3个字节,"blake2bhash"是20个字节" shabytes"是32-4=28个字节).这将产生一个49字符长的`base58check`字符串.但是,"tz1"地址的长度为36个字符.当然,这种方法不正确,对吗?Input for b58encode is going to be 51 bytes long (`P2HASH_MAGIC` is 3 bytes, `blake2bhash` is 20 bytes `shabytes` is 32 - 4 = 28 bytes) . This is going to produce a 49-char long `base58check` string. However, a `tz1` address is 36-char long. Surely, this method is not correct, is it?
- 0
- 2020-02-11
- K SS
-
- 2020-01-16
您是否构建了tezos回购协议?如果是,则可以使用tezos-crypto运行ocaml CLI:
$ dune utop src/lib_crypto
然后:
ocaml# open Tezos_crypto;; ocaml# Ed25519.Public_key.of_b58check_exn "edpkuoK2J2UVbDcSTdJgP85JmDN3gxBCswcgApbtY5d7zHVunwCKNR" |> Ed25519.Public_key.hash |> Ed25519.Public_key_hash.to_b58check;; - : string = "tz1L1bypLzuxGHmx3d6bHFJ2WCi4ZDbocSCA"
Do you have the tezos repo built? If yes, you can run the ocaml CLI with tezos-crypto:
$ dune utop src/lib_crypto
and then:
ocaml# open Tezos_crypto;; ocaml# Ed25519.Public_key.of_b58check_exn "edpkuoK2J2UVbDcSTdJgP85JmDN3gxBCswcgApbtY5d7zHVunwCKNR" |> Ed25519.Public_key.hash |> Ed25519.Public_key_hash.to_b58check;; - : string = "tz1L1bypLzuxGHmx3d6bHFJ2WCi4ZDbocSCA"
-
虽然这可能是一个很好的答案,但对我而言却无济于事.我需要在nodejs应用中以编程方式进行操作.While this is probably a good answer, it is not helpful in my case. I need to do it programatically, in a nodejs app.
- 0
- 2020-01-16
- K SS
-
- 2020-01-17
在python中,使用pytezos 的git版本:
来自pytezos.crypto导入密钥的from pytezos.crypto import Key public_key = 'edpkuoK2J2UVbDcSTdJgP85JmDN3gxBCswcgApbtY5d7zHVunwCKNR' hash = Key(public_key).public_key_hash() print(hash)
In python, using the git version of pytezos:
from pytezos.crypto import Key public_key = 'edpkuoK2J2UVbDcSTdJgP85JmDN3gxBCswcgApbtY5d7zHVunwCKNR' hash = Key(public_key).public_key_hash() print(hash)
-
- 2020-01-17
在NodeJS中,也可以使用
sotez
:import {Key} from 'sotez'; const sotezKey = new Key({ key: 'edpktx799pgw7M4z8551URER52VcENNCSZwE9f9cst4v6h5vCrQmJE' }); await sotezKey.ready; console.log(sotezKey.publicKeyHash());
张照片:
tz1Xv78KMT7cHyVDLi9RmQP1KuWULHDafZdK
In NodeJS it is also possible to do it using
sotez
:import {Key} from 'sotez'; const sotezKey = new Key({ key: 'edpktx799pgw7M4z8551URER52VcENNCSZwE9f9cst4v6h5vCrQmJE' }); await sotezKey.ready; console.log(sotezKey.publicKeyHash());
prints:
tz1Xv78KMT7cHyVDLi9RmQP1KuWULHDafZdK
我只需要基于公共
ed25519
密钥创建Tezos公共密钥哈希.我知道一个实用程序可以基于助记符生成整个密钥库-这不是我所需要的.
我将欢迎逐步说明如何从
edpk
转换为tz1
表单或代码段.谢谢.