mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
Refactors the split between nip19 and the rest of the text.
This commit is contained in:
parent
5c882c81c8
commit
d723a8ab5c
@ -101,37 +101,50 @@ class NewMessageTagger(
|
|||||||
|
|
||||||
key = key.removePrefix("@")
|
key = key.removePrefix("@")
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (key.startsWith("nsec1", true)) {
|
||||||
if (key.length < 63) {
|
if (key.length < 63) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
val keyB32 = key.substring(0, 63)
|
val keyB32 = key.substring(0, 63)
|
||||||
val restOfWord = key.substring(63)
|
val restOfWord = key.substring(63)
|
||||||
|
|
||||||
if (key.startsWith("nsec1", true)) {
|
|
||||||
// Converts to npub
|
// Converts to npub
|
||||||
val pubkey = Nip19.uriToRoute(KeyPair(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null
|
val pubkey = Nip19.uriToRoute(KeyPair(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkey, restOfWord)
|
return DirtyKeyInfo(pubkey, restOfWord)
|
||||||
} else if (key.startsWith("npub1", true)) {
|
} else if (key.startsWith("npub1", true)) {
|
||||||
|
if (key.length < 63) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val keyB32 = key.substring(0, 63)
|
||||||
|
val restOfWord = key.substring(63)
|
||||||
|
|
||||||
val pubkey = Nip19.uriToRoute(keyB32) ?: return null
|
val pubkey = Nip19.uriToRoute(keyB32) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkey, restOfWord)
|
return DirtyKeyInfo(pubkey, restOfWord)
|
||||||
} else if (key.startsWith("note1", true)) {
|
} else if (key.startsWith("note1", true)) {
|
||||||
|
if (key.length < 63) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val keyB32 = key.substring(0, 63)
|
||||||
|
val restOfWord = key.substring(63)
|
||||||
|
|
||||||
val noteId = Nip19.uriToRoute(keyB32) ?: return null
|
val noteId = Nip19.uriToRoute(keyB32) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(noteId, restOfWord)
|
return DirtyKeyInfo(noteId, restOfWord)
|
||||||
} else if (key.startsWith("nprofile", true)) {
|
} else if (key.startsWith("nprofile", true)) {
|
||||||
val pubkeyRelay = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
val pubkeyRelay = Nip19.uriToRoute(key) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkeyRelay, pubkeyRelay.additionalChars)
|
return DirtyKeyInfo(pubkeyRelay, pubkeyRelay.additionalChars)
|
||||||
} else if (key.startsWith("nevent1", true)) {
|
} else if (key.startsWith("nevent1", true)) {
|
||||||
val noteRelayId = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
val noteRelayId = Nip19.uriToRoute(key) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(noteRelayId, noteRelayId.additionalChars)
|
return DirtyKeyInfo(noteRelayId, noteRelayId.additionalChars)
|
||||||
} else if (key.startsWith("naddr1", true)) {
|
} else if (key.startsWith("naddr1", true)) {
|
||||||
val address = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
val address = Nip19.uriToRoute(key) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(address, address.additionalChars) // no way to know when they address ends and dirt begins
|
return DirtyKeyInfo(address, address.additionalChars) // no way to know when they address ends and dirt begins
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user