Allow multiple base58 prefix bytes.

This commit is contained in:
tecnovert
2024-03-25 13:37:35 +02:00
parent 2a28f336e2
commit 1cbc2f44b0
6 changed files with 72 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import basicswap.contrib.Keccak as Keccak
from basicswap.util.integer import encode_varint
from .contrib.MoneroPy.base58 import encode as xmr_b58encode
@@ -9,8 +10,9 @@ def cn_fast_hash(s):
return k.Keccak((len(s) * 8, s.hex()), 1088, 512, 32 * 8, False).lower() # r = bitrate = 1088, c = capacity, n = output length in bits
def encode_address(view_point, spend_point, version=18):
buf = bytes((version,)) + spend_point + view_point
def encode_address(view_point: bytes, spend_point: bytes, version=18) -> str:
prefix_bytes = version if isinstance(version, bytes) else encode_varint(version)
buf = prefix_bytes + spend_point + view_point
h = cn_fast_hash(buf)
buf = buf + bytes.fromhex(h[0: 8])