decodeContentHash static method
Implementation
static String? decodeContentHash(Uint8List data) {
if (data.isEmpty) return null;
// IPFS: starts with 0xe3010170 (CIDv1 dag-pb)
// or 0xe5010172 (CIDv1 libp2p-key for IPNS)
if (data.length >= 2 && data[0] == 0xe3 && data[1] == 0x01) {
return 'ipfs://${hexEncode(data.sublist(2))}';
}
if (data.length >= 2 && data[0] == 0xe5 && data[1] == 0x01) {
return 'ipns://${hexEncode(data.sublist(2))}';
}
// Swarm: starts with 0xe4
if (data.isNotEmpty && data[0] == 0xe4) {
return 'bzz://${hexEncode(data.sublist(1))}';
}
return '0x${hexEncode(data)}';
}