Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change API name from uriToRoute() to parse(). #26

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rhodium-core/src/commonMain/kotlin/rhodium/crypto/Nip19Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object Nip19Parser {
return null
}

fun uriToRoute(uri: String?): ParseReturn? {
fun parse(uri: String?): ParseReturn? {
if (uri == null) return null

try {
Expand Down Expand Up @@ -159,7 +159,7 @@ object Nip19Parser {
}

fun decodePublicKey(key: String): ByteArray =
when (val parsed = Nip19Parser.uriToRoute(key)?.entity) {
when (val parsed = Nip19Parser.parse(key)?.entity) {
is NSec -> Identity(privKey = key.bechToBytes()).pubKey
is NPub -> parsed.hex.toBytes()
is NProfile -> parsed.hex.toBytes()
Expand All @@ -168,7 +168,7 @@ fun decodePublicKey(key: String): ByteArray =

fun decodePrivateKeyAsHexOrNull(key: String): String? =
try {
when (val parsed = Nip19Parser.uriToRoute(key)?.entity) {
when (val parsed = Nip19Parser.parse(key)?.entity) {
is NSec -> parsed.hex
is NPub -> null
is NProfile -> null
Expand All @@ -186,7 +186,7 @@ fun decodePrivateKeyAsHexOrNull(key: String): String? =

fun decodePublicKeyAsHexOrNull(key: String): String? =
try {
when (val parsed = Nip19Parser.uriToRoute(key)?.entity) {
when (val parsed = Nip19Parser.parse(key)?.entity) {
is NSec -> Identity(privKey = key.bechToBytes()).pubKey.toHexString()
is NPub -> parsed.hex
is NProfile -> parsed.hex
Expand All @@ -204,7 +204,7 @@ fun decodePublicKeyAsHexOrNull(key: String): String? =

fun decodeEventIdAsHexOrNull(key: String): String? =
try {
when (val parsed = Nip19Parser.uriToRoute(key)?.entity) {
when (val parsed = Nip19Parser.parse(key)?.entity) {
is NSec -> null
is NPub -> null
is NProfile -> null
Expand Down