コード例 #1
0
    def verify_addr(cls, addr, hex_width, return_dict=False):

        if 'B' in cls.mmtypes and addr[:len(cls.bech32_hrp)] == cls.bech32_hrp:
            ret = bech32.decode(cls.bech32_hrp, addr)
            if ret[0] != cls.witness_vernum:
                msg('{}: Invalid witness version number'.format(ret[0]))
            elif ret[1]:
                return {
                    'hex': bytes(ret[1]).hex(),
                    'format': 'bech32'
                } if return_dict else True
            return False

        for addr_fmt in cls.addr_ver_num:
            ver_num, pfx = cls.addr_ver_num[addr_fmt]
            if type(pfx) == tuple:
                if addr[0] not in pfx: continue
            elif addr[:len(pfx)] != pfx: continue
            addr_hex = _b58chk_decode(addr)
            if addr_hex[:len(ver_num)] != ver_num: continue
            return {
                'hex': addr_hex[len(ver_num):],
                'format': {
                    'p2pkh': 'p2pkh',
                    'p2sh': 'p2sh',
                    'p2sh2': 'p2sh',
                    'zcash_z': 'zcash_z',
                    'viewkey': 'viewkey'
                }[addr_fmt]
            } if return_dict else True

        return False
コード例 #2
0
ファイル: protocol.py プロジェクト: mmgen/mmgen
	def verify_addr(cls,addr,hex_width,return_dict=False):

		if 'B' in cls.mmtypes and addr[:len(cls.bech32_hrp)] == cls.bech32_hrp:
			ret = bech32.decode(cls.bech32_hrp,addr)
			if ret[0] != cls.witness_vernum:
				msg('{}: Invalid witness version number'.format(ret[0]))
			elif ret[1]:
				return {
					'hex': bytes(ret[1]).hex(),
					'format': 'bech32'
				} if return_dict else True
			return False

		for addr_fmt in cls.addr_ver_num:
			ver_num,pfx = cls.addr_ver_num[addr_fmt]
			if type(pfx) == tuple:
				if addr[0] not in pfx: continue
			elif addr[:len(pfx)] != pfx: continue
			addr_hex = _b58chk_decode(addr)
			if addr_hex[:len(ver_num)] != ver_num: continue
			return {
				'hex': addr_hex[len(ver_num):],
				'format': { 'p2pkh':'p2pkh',
							'p2sh':'p2sh',
							'p2sh2':'p2sh',
							'zcash_z':'zcash_z',
							'viewkey':'viewkey'}[addr_fmt]
			} if return_dict else True

		return False
コード例 #3
0
ファイル: protocol.py プロジェクト: totaltrader/mmgen
		def parse_addr(self,addr):

			if 'B' in self.mmtypes and addr[:len(self.bech32_hrp)] == self.bech32_hrp:
				ret = bech32.decode(self.bech32_hrp,addr)

				if ret[0] != self.witness_vernum:
					msg(f'{ret[0]}: Invalid witness version number')
					return False

				return parsed_addr( bytes(ret[1]), 'bech32' ) if ret[1] else False

			return self.parse_addr_bytes(_b58chk_decode(addr))
コード例 #4
0
    def verify_addr(cls, addr, hex_width, return_dict=False):

        if 'B' in cls.mmtypes and addr[:len(cls.bech32_hrp)] == cls.bech32_hrp:
            ret = bech32.decode(cls.bech32_hrp, addr)
            if ret[0] != cls.witness_vernum:
                msg('{}: Invalid witness version number'.format(ret[0]))
            elif ret[1]:
                return {
                    'hex': ''.join(map(chr, ret[1])).encode('hex'),
                    'format': 'bech32'
                } if return_dict else True
            return False

        for addr_fmt in cls.addr_ver_num:
            ver_num, pfx = cls.addr_ver_num[addr_fmt]
            if type(pfx) == tuple:
                if addr[0] not in pfx: continue
            elif addr[:len(pfx)] != pfx: continue
            num = _b58tonum(addr)
            if num == False:
                if g.debug: Msg('Address cannot be converted to base 58')
                break
            addr_hex = '{:0{}x}'.format(num, len(ver_num) + hex_width + 8)
            #			pmsg(hex_width,len(addr_hex),addr_hex[:len(ver_num)],ver_num)
            if addr_hex[:len(ver_num)] != ver_num: continue
            if hash256(addr_hex[:-8])[:8] == addr_hex[-8:]:
                return {
                    'hex': addr_hex[len(ver_num):-8],
                    'format': {
                        'p2pkh': 'p2pkh',
                        'p2sh': 'p2sh',
                        'p2sh2': 'p2sh',
                        'zcash_z': 'zcash_z',
                        'viewkey': 'viewkey'
                    }[addr_fmt]
                } if return_dict else True
            else:
                if g.debug: Msg('Invalid checksum in address')
                break

        return False