tldr;
Current onion3 contenthash implementation is NOT following CIDv1 properly.
From test files of ENS/contatn-hash:
Onion3 multiaddr/multiformat codecs
here,
varint(0x01bd) = prefix bd03, which is a multiaddr.
Same prefix for IPFS/NS and swarm is using proper Namespace but there’s no onion3 namespace, so current implementation is using this format
const onion3 = "p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd";
const onion3_contentHash = "bd03"+hexBytes(onion3);
Following Tor/Onion3 Address Spec :
https://spec.torproject.org/rend-spec/encoding-onion-addresses.html
onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"
CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2]
where:
- PUBKEY is the 32 bytes ed25519 master pubkey of the hidden service.
- VERSION is a one byte version field (default value '\x03')
- ".onion checksum" is a constant string
- CHECKSUM is truncated to two bytes before inserting it in onion_address
Here are a few example addresses:
pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion
sp3k262uwy4r2k3ycr5awluarykdpag6a7y33jxop4cs2lu5uz5sseqd.onion
xa4r2iadxm55fbnqgwwi5mymqdcofiu3w6rpbtqn7b2dyn7mgwj64jyd.onion
** H = SHA3
Alt format *IF using same “bd03” multiaddr prefix as NS & base32 decoder.
0xbd03+ decodebase32(onion3_addr)
0xbd03 + 7f76b2f7f075714ada42f5db17bf0f5e3759c19f5f9e27054cc424871704cb4b4ed203
Correct formats :
cidv1 onion multiaddr format without using bd03
multiaddr as NS. * there’s no NS for onion3.
a) onion3 multi addr + identity with checksum & onion version =3
<v=1><multiaddr=onion3><id=0><length=32+2+1>
= 01bd0300247f76b2f7f075714ada42f5db17bf0f5e3759c19f5f9e27054cc424871704cb4b4ed203
base32 : bag6qgabdp53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd
base36 : k62lgnso3wxo2p8d18ab5igmlsdvz4l54gbhyxj78rdvex9s20lzrp8zcy270j
b) onion3 multiaddr with proper ed25519 id & NO checksum and onion3 version suffix.
<v=1><multiaddr=onion3><Iden/type=ed01><len=32>
= 01bd03ed01207f76b2f7f075714ada42f5db17bf0f5e3759c19f5f9e27054cc424871704cb4b
base32 : bag6qh3ibeb7xnmxx6b2xcsw2il25wf57b5pdowobt5pz4jyfjtccjbyxatfuw
This proves current onion3 contenthash is make believe CIDv1. Proper fix will require a new namespace for onion3 or could use ENS side of NS specs. speaking of which, @raffy could rebrand current PR for datauri NS to be full ENS namespace for everything ENS… & for record, we’re all doing this cid thing in reverse, ENS should specify its own NS/specs and ask multiformats to include those specs in table, not other way around.