"""ERC-55 public test vectors and deliberate text transformations; no wallet/RPC.""" import csv,hashlib,json,re,sys from Crypto.Hash import keccak import Crypto VECTORS=['0x52908400098527886E0F7030069857D2E4169EE7','0x8617E340B3D01FA5F11F306F4090FD50E238070D','0xde709f2102306220921060314715629080e2fb77','0x27b1fdb04752bbc536007a920d24acb045561c26','0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed','0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359','0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB','0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb'] def encode(address): if not re.fullmatch(r'0x[0-9a-fA-F]{40}',address):raise ValueError('Expected 0x and40ASCIIhexcharacters') lower=address[2:].lower();digest=keccak.new(digest_bits=256,data=lower.encode('ascii')).hexdigest() canonical='0x'+''.join(c.upper()if c in 'abcdef'and int(digest[i],16)>=8 else c for i,c in enumerate(lower)) return canonical,digest def calculate(): rows=[] for i,official in enumerate(VECTORS,1): canonical,digest=encode(official);assert canonical==official first=next(j for j,c in enumerate(official[2:])if c.lower()in 'abcdef');flipped=official[:first+2]+official[first+2].swapcase()+official[first+3:] changed=official[:-1]+('1'if official[-1]!='1'else'2');changed=encode(changed)[0] for name,text in [('official',official),('lowercase',official.lower()),('uppercase','0x'+official[2:].upper()),('one_case_flipped',flipped),('changed_hex_rechecksummed',changed)]: expected,h=encode(text);same_bytes=text[2:].lower()==official[2:].lower() rows.append({'vector':i,'scenario':name,'input':text,'canonical':expected,'keccak_lower_hex':h,'strict_erc55_text_match':text==expected,'same_20_bytes_as_official':same_bytes,'positions':[{'one_based_position':n+1,'input':c,'expected':expected[n+2],'hash_nibble':h[n],'uppercase_rule':c.lower()in'abcdef'and int(h[n],16)>=8}for n,c in enumerate(text[2:])]}) assert len(rows)==40 and sum(r['strict_erc55_text_match']for r in rows if r['scenario']=='official')==8 assert all(not r['strict_erc55_text_match']for r in rows if r['scenario']=='one_case_flipped') assert all(r['strict_erc55_text_match']and not r['same_20_bytes_as_official']for r in rows if r['scenario']=='changed_hex_rechecksummed') sha3='0x'+''.join(c.upper()if c in 'abcdef'and int(hashlib.sha3_256(VECTORS[4][2:].lower().encode('ascii')).hexdigest()[i],16)>=8 else c for i,c in enumerate(VECTORS[4][2:].lower())) assert sha3!=VECTORS[4] return {'kind':'official_erc55_vectors_and_deliberate_text_variants_not_wallet_transactions','calculated_on':'2026-11-02','specification':'https://eips.ethereum.org/EIPS/eip-55','pycryptodome_version':Crypto.__version__,'official_vectors':VECTORS,'rows':rows,'sha3_counterexample':{'input_lower_hex':VECTORS[4][2:].lower(),'erc55_keccak_result':VECTORS[4],'nist_sha3_256_result':sha3,'same':False},'scope':'Text encoding only. Uniform-case text may equal the canonical spelling for some official vectors; do not assume all uppercase/lowercase strings fail. Rechecksummed changed20bytes still pass: no owner/network/token/recipient identity or wallet safety validation. No RPC/wallet/key/transfer.'} if __name__=='__main__':print(json.dumps(calculate(),ensure_ascii=False,indent=2))