Hot answers tagged

8

Heres how to do it in python, where the variable pubkey is the bytes array of the public key 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()


7

KT1 addresses are computed from origination nonce. The origination nonce is made of operation hash (the operation that creates the origination) and its index (the index starts from 0 and it gets incremented for each origination in the operation). The operation hash depends on block header of the branch where it was included.The CHAIN_ID depends on genesis ...


7

Take a byte representation of a particular block header: http://rpc.tzkt.io/mainnet/chains/main/blocks/head/header/raw. The format of the block header is described in the docs. Get a BLAKE2b (32bit) hash digest of it Prepend two bytes '\x01\x34' (they are responsible for "B" letter) Base58 encode it with checksum There is no randomness. The baker ...


6

In case someone needs precise calculations. Say, you have an operation group hash onvsLP3JFZia2mzZKWaFuFkWg2L5p3BDUhzh5Kr6CiDDN3rtQ1D and an origination index 0 which is increased for every origination operation in the group including internal operations. In order to calculate originated contract hash you need to do: Base58 decode (with checksum) the opg ...


5

Try https://github.com/murbard/pytezos/blob/master/pytezos/crypto.py from pytezos.crypto import Key key = Key(key='mnemonic', passphrase='******', email='foo@bar.com') key.public_key_hash() >>> edpk...


5

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;; ...


4

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)


3

I was unable to find a complete answer, but here are some pointers. First, to clarify, I think you're asking about the format of operation hashes. A block consists of a set of operations. An operation can be for instance a transaction (transfer tokens), a delegation, contract creations... The prefix for blocks is B, for operations o. As you write, operations ...


2

tl;dr: we serialize the michelson value to binary, we then hash those bytes it with Blake2b-256. We base58 encode the result. Long version Let's consider the case of the Ledger Blake2b has of the integer 1, as given by: $ tezos-client hash data 1 of type int Raw packed data: 0x050001 Script-expression-ID-Hash: ...


2

There is no instruction in Michelson to interpret arbitrary bytes as numbers. The simplest way to achieve what you want is to use a constant table (as a Michelson map) from bytes of length 1 to their values (between 0 and 255). Then, depending on how uniform you need your distribution to be, you can either take a modulo on the value of the last byte of your ...


1

So my specific questions: Is there a way to get the next block hash within a smart contract? No, there is no instruction in Michelson to query a block hash. Or some other way to get a value that isn't known at the time the contract is called? You could use the CREATE_CONTRACT instruction that is usually meant to originate a new contract, it returns the ...


1

You can test against the data that the official Tezos project uses for regression testing. This file might be of interest: https://gitlab.com/tezos/tezos/-/blob/master/tezt/_regressions/protocol.alpha.operation.internal.out


1

The PDF you received from the ICO contains everything you need to activate your address, including your public hash (starts with tz1, tz2, or tz3).


1

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


1

Part 1 of my question was answered by Michael. What about the second part? Well, I just had a look at it. What I did is: extract the full series of hash codes, from block 1 to the latest (VERY LONG). extract the numbers contained in such hash codes (i.e. remove letters). analyse the "randomness" of this series of numbers with purposely designed tests. The ...


Only top voted, non community-wiki answers of a minimum length are eligible