def to_addr(self,pubhex): # pubhex is really privhex key = bytes.fromhex(pubhex) assert len(key) == 32,'{}: incorrect privkey length'.format(len(key)) from nacl.bindings import crypto_scalarmult_base p2 = crypto_scalarmult_base(self.zhash256(key,1)) from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['zcash_z'][0] + (self.zhash256(key,0)+p2).hex()) assert len(ret) == self.addr_width,'Invalid Zcash z-address length' return CoinAddr(ret)
def to_addr(self, pubhex): # pubhex is really privhex key = bytes.fromhex(pubhex) assert len(key) == 32, '{}: incorrect privkey length'.format(len(key)) from nacl.bindings import crypto_scalarmult_base p2 = crypto_scalarmult_base(self.zhash256(key, 1)) from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['zcash_z'][0] + (self.zhash256(key, 0) + p2).hex()) assert len(ret) == self.addr_width, 'Invalid Zcash z-address length' return CoinAddr(ret)
def to_viewkey(self,pubhex): # pubhex is really privhex key = bytes.fromhex(pubhex) assert len(key) == 32,'{}: incorrect privkey length'.format(len(key)) vk = bytearray(self.zhash256(key,0)+self.zhash256(key,1)) vk[32] &= 0xf8 vk[63] &= 0x7f vk[63] |= 0x40 from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['viewkey'][0] + vk.hex()) assert len(ret) == self.vk_width,'Invalid Zcash view key length' return ZcashViewKey(ret)
def to_viewkey(self, pubhex): # pubhex is really privhex key = bytes.fromhex(pubhex) assert len(key) == 32, '{}: incorrect privkey length'.format(len(key)) vk = bytearray(self.zhash256(key, 0) + self.zhash256(key, 1)) vk[32] &= 0xf8 vk[63] &= 0x7f vk[63] |= 0x40 from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['viewkey'][0] + vk.hex()) assert len(ret) == self.vk_width, 'Invalid Zcash view key length' return ZcashViewKey(ret)
def to_viewkey(self,pubhex): # pubhex is really privhex key = pubhex.decode('hex') assert len(key) == 32,'{}: incorrect privkey length'.format(len(key)) vk = map(ord,self.zhash256(key,0)+self.zhash256(key,1)) vk[32] &= 0xf8 vk[63] &= 0x7f vk[63] |= 0x40 from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['viewkey'][0] + hexlify(''.join(map(chr,vk)))) assert len(ret) == g.proto.addr_width,'Invalid Zcash view key length' return ZcashViewKey(ret)
def to_viewkey(self, pubhex): # pubhex is really privhex key = pubhex.decode('hex') assert len(key) == 32, '{}: incorrect privkey length'.format(len(key)) vk = map(ord, self.zhash256(key, 0) + self.zhash256(key, 1)) vk[32] &= 0xf8 vk[63] &= 0x7f vk[63] |= 0x40 from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['viewkey'][0] + hexlify(''.join(map(chr, vk)))) assert len(ret) == self.vk_width, 'Invalid Zcash view key length' return ZcashViewKey(ret)
def to_addr(self, pubhex): # pubhex is really privhex key = pubhex.decode('hex') assert len(key) == 32, '{}: incorrect privkey length'.format(len(key)) if g.platform == 'win': ydie(1, 'Zcash z-addresses not supported on Windows platform') from nacl.bindings import crypto_scalarmult_base p2 = crypto_scalarmult_base(self.zhash256(key, 1)) from mmgen.protocol import _b58chk_encode ret = _b58chk_encode(g.proto.addr_ver_num['zcash_z'][0] + hexlify(self.zhash256(key, 0) + p2)) assert len(ret) == self.addr_width, 'Invalid Zcash z-address length' return CoinAddr(ret)
def phash2addr(ver_num,pk_hash): from mmgen.protocol import _b58chk_encode s = '{:0{}x}'.format(ver_num,2 if ver_num < 256 else 4) + pk_hash lzeroes = (len(s) - len(s.lstrip('0'))) / 2 # non-zero only for ver num '00' (BTC p2pkh) return ('1' * lzeroes) + _b58chk_encode(s)
def phash2addr(ver_num, pk_hash): from mmgen.protocol import _b58chk_encode bl = ver_num.bit_length() ver_bytes = int.to_bytes(ver_num, bl // 8 + bool(bl % 8), 'big') return _b58chk_encode(ver_bytes + pk_hash)
def phash2addr(ver_num, pk_hash): from mmgen.protocol import _b58chk_encode s = '{:0{}x}'.format(ver_num, 2 if ver_num < 256 else 4) + pk_hash lzeroes = (len(s) - len(s.lstrip('0')) ) / 2 # non-zero only for ver num '00' (BTC p2pkh) return ('1' * lzeroes) + _b58chk_encode(s)
def Hextob58chk(s): from mmgen.protocol import _b58chk_encode Msg(_b58chk_encode(s))
def phash2addr(ver_num, pk_hash): from mmgen.protocol import _b58chk_encode return _b58chk_encode( '{:0{}x}'.format(ver_num, 2 if ver_num < 256 else 4) + pk_hash)
def hextob58chk(self,hexstr:'sstr'): "convert a hexadecimal number to base58-check encoding" from mmgen.protocol import _b58chk_encode return _b58chk_encode(hexstr)
def phash2addr(ver_num,pk_hash): from mmgen.protocol import _b58chk_encode return _b58chk_encode('{:0{}x}'.format(ver_num,2 if ver_num < 256 else 4) + pk_hash)