Skip to content

Instantly share code, notes, and snippets.

@vsuharnikov
Last active September 12, 2022 09:21
Show Gist options
  • Save vsuharnikov/fc74c829d23e947bf359477c3305725f to your computer and use it in GitHub Desktop.
Save vsuharnikov/fc74c829d23e947bf359477c3305725f to your computer and use it in GitHub Desktop.
Convert an address in the Ethereum format to the Waves format
eth addr: 526938a6106aec0b2ec994e2288fcabcad54bfcb
waves addr: 3MwRqEZ4cBFRXShgNCyvKuVjcvLLtgWVvuZ
expected: 3MwRqEZ4cBFRXShgNCyvKuVjcvLLtgWVvuZ
import pywaves.crypto as crypto
import base58
chain_id = 'T' # 'W' для MainNet
eth_addr = '0x526938a6106aec0b2ec994e2288fcabcad54bfcb'
if eth_addr.startswith('0x'):
eth_addr = eth_addr[2:]
# 1. Раскодировать HEX строку в байты (PK_HASH)
pk_hash = crypto.bytes2str(bytes.fromhex(eth_addr))
head_bytes = chr(1) + chain_id
# 2. Сделать чек-сумму CHECKSUM=keccak256(blake2b256([0x01, CHAIN_ID] + PK_HASH))
checksum = crypto.hashChain(crypto.str2bytes(head_bytes + pk_hash))
# 3. Склеить [0x01, CHAIN_ID] (два байта) + PK_HASH (изначальные 20 байт) + CHECKSUM[1:4] (первые четыре байта чек-суммы)
waves_addr_bytes = head_bytes + pk_hash + checksum[0:4]
# 4. Закодировать в Base58
waves_addr = base58.b58encode(crypto.str2bytes(waves_addr_bytes))
print('eth addr: ', eth_addr, '\nwaves addr:', waves_addr, '\nexpected: 3MwRqEZ4cBFRXShgNCyvKuVjcvLLtgWVvuZ')
#!/usr/bin/env bash
virtualenv default
source default/bin/activate
pip install -r requirements.txt
python run.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment