-
Notifications
You must be signed in to change notification settings - Fork 5
feat: support pubky contact deep links #1320
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
91d083a
feat: support pubky contact deep links
ben-kaufman db45d05
fix: reject malformed contact links before startup
ben-kaufman 94405b0
fix: reject recovery paths in contact links
ben-kaufman 54d174c
fix: release contact links after load failure
ben-kaufman cc87440
fix: retry contacts before deeplink routing
ben-kaufman 456680c
fix: wait for concurrent contact loads
ben-kaufman 712fdf1
docs: keep contact deeplink setup in journey
ben-kaufman 603332e
Merge master into codex/pubky-contact-deeplink
ben-kaufman 55b25e5
Merge master into codex/pubky-contact-deeplink
ben-kaufman 285db62
fix: canonicalize pubky contact links
ben-kaufman 0c774ea
fix: canonicalize pubky contact inputs
ben-kaufman ff3e8c1
Merge master into codex/pubky-contact-deeplink
ben-kaufman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package to.bitkit.models | ||
|
|
||
| import android.net.Uri | ||
|
|
||
| object PubkyContactLink { | ||
| fun matches(uri: Uri): Boolean = | ||
| uri.scheme.equals("bitkit", ignoreCase = true) && uri.host.equals("contact", ignoreCase = true) | ||
|
|
||
| fun publicKey(uri: Uri): String? { | ||
| if (!matches(uri)) return null | ||
| if (!uri.encodedAuthority.equals("contact", ignoreCase = true) || | ||
| !uri.path.isNullOrEmpty() || uri.fragment != null | ||
| ) { | ||
| return null | ||
| } | ||
| if (uri.queryParameterNames != setOf("pubky") || uri.encodedQuery.orEmpty().contains('&')) return null | ||
| val key = uri.getQueryParameters("pubky").singleOrNull() | ||
| ?.takeIf { it.length <= PubkyPublicKeyFormat.maximumInputLength } ?: return null | ||
|
|
||
| return PubkyPublicKeyFormat.canonicalized(key) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/test/java/to/bitkit/models/PubkyContactLinkTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package to.bitkit.models | ||
|
|
||
| import androidx.core.net.toUri | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(sdk = [34]) | ||
| class PubkyContactLinkTest { | ||
| private val key = "pubky3rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xy" | ||
| private val nonCanonicalKey = "pubky3rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg" | ||
|
|
||
| @Test | ||
| fun `accepts raw prefixed and encoded keys`() { | ||
| listOf( | ||
| nonCanonicalKey.removePrefix("pubky"), | ||
| nonCanonicalKey, | ||
| nonCanonicalKey.uppercase(), | ||
| nonCanonicalKey.replace("pubky", "%70ubky"), | ||
| ).forEach { value -> | ||
| assertEquals(key, PubkyContactLink.publicKey("bitkit://contact?pubky=$value".toUri())) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `rejects malformed links and non-key payloads`() { | ||
| listOf( | ||
| "https://contact?pubky=$key", | ||
| "bitkit://other?pubky=$key", | ||
| "bitkit://user@contact?pubky=$key", | ||
| "bitkit://contact:123?pubky=$key", | ||
| "bitkit://contact:invalid?pubky=$key", | ||
| "bitkit://contact/path?pubky=$key", | ||
| "bitkit://contact?pubky=$key#fragment", | ||
| "bitkit://contact", | ||
| "bitkit://contact?pubky=", | ||
| "bitkit://contact?pubky=$key&pubky=$key", | ||
| "bitkit://contact?pubky=$key&other=value", | ||
| "bitkit://contact?pubky=${key}extra", | ||
| "bitkit://contact?pubky=invalid", | ||
| "bitkit://contact?pubky=bitcoin%3Abc1example", | ||
| "bitkit://contact?pubky=pubkyauth%3A%2F%2Fsignin_grant", | ||
| ).forEach { link -> | ||
| assertNull(PubkyContactLink.publicKey(link.toUri()), link) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.