decode static method
Decode a NIP-19 encoded string (npub, note, nevent, nprofile, naddr) Returns the decoded hex string
Implementation
static String decode(String nip19String) {
try {
var decoder = Bech32Decoder();
var bech32Result = decoder.convert(nip19String, nip19String.length);
var data = Nip19Utils.convertBits(bech32Result.data, 5, 8, false);
if (bech32Result.hrp != Hrps.kNoteId &&
bech32Result.hrp != Hrps.kPublicKey &&
bech32Result.hrp != Hrps.kPrivateKey) {
final tlv = Nip19TLV.parseTLV(data);
final special = tlv.firstWhereOrNull((t) => t.type == 0)?.value;
if (special != null) {
return hex.encode(special);
} else {
throw "Missing 'special' kind in TLV entity, cant decode to hex";
}
} else {
return hex.encode(data);
}
} catch (e) {
Logger.log.e("Nip19 decode error ${e.toString()}");
return "";
}
}