upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgreenart7c3 <greenart7c3@proton.me>2024-04-29 08:56:19 -0300
committergreenart7c3 <greenart7c3@proton.me>2024-04-29 08:56:19 -0300
commit6ee0648f0002cd776e310093fdda8e4942553f37 (patch)
tree1148a256d71183991715f7f151dfddaba2f00e3a
parentb21e996a89a9fe2acb09136792c75b1dd8eb59f8 (diff)
parenta2aaa3c00b18e2e11dceae9400cd6fc429562622 (diff)
Merge branch 'master' of https://github.com/greenart7c3/nips
-rw-r--r--100.md56
1 files changed, 40 insertions, 16 deletions
diff --git a/100.md b/100.md
index 99feebf..571d1eb 100644
--- a/100.md
+++ b/100.md
@@ -40,18 +40,42 @@ fun isExternalSignerInstalled(context: Context): Boolean {
40 40
41To get the result back from the Signer Application you should use `registerForActivityResult` or `rememberLauncherForActivityResult` in Kotlin. If you are using another framework check the documentation of your framework or a third party library to get the result. 41To get the result back from the Signer Application you should use `registerForActivityResult` or `rememberLauncherForActivityResult` in Kotlin. If you are using another framework check the documentation of your framework or a third party library to get the result.
42 42
43```kotlin
44val launcher = rememberLauncherForActivityResult(
45 contract = ActivityResultContracts.StartActivityForResult(),
46 onResult = { result ->
47 if (result.resultCode != Activity.RESULT_OK) {
48 Toast.makeText(
49 context,
50 "Sign request rejected",
51 Toast.LENGTH_SHORT
52 ).show()
53 } else {
54 val signature = activityResult.data?.getStringExtra("signature")
55 // Do something with signature ...
56 }
57 }
58)
59```
60
43Create the Intent using the **nostrsigner** scheme: 61Create the Intent using the **nostrsigner** scheme:
44 62
45```kotlin 63```kotlin
46val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$content")) 64val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$content"))
47``` 65```
48 66
49* Set the Signer package name 67Set the Signer package name:
50 68
51```kotlin 69```kotlin
52intent.`package` = "com.example.signer" 70intent.`package` = "com.example.signer"
53``` 71```
54 72
73Send the Intent:
74
75```kotlin
76launcher.launch(intent)
77```
78
55### Methods 79### Methods
56 80
57- **get_public_key** 81- **get_public_key**
@@ -61,14 +85,14 @@ intent.`package` = "com.example.signer"
61 val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:")) 85 val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:"))
62 intent.`package` = "com.example.signer" 86 intent.`package` = "com.example.signer"
63 intent.putExtra("type", "get_public_key") 87 intent.putExtra("type", "get_public_key")
64 // You can send some default permissions for the user authorize for ever 88 // You can send some default permissions for the user to authorize for ever
65 val permissions = listOf( 89 val permissions = listOf(
66 Permission( 90 Permission(
67 "sign_event", 91 type = "sign_event",
68 22242 92 kind = 22242
69 ), 93 ),
70 Permission( 94 Permission(
71 "nip44_decrypt" 95 type = "nip44_decrypt"
72 ) 96 )
73 ) 97 )
74 intent.putExtra("permissions", permissions.toJson()) 98 intent.putExtra("permissions", permissions.toJson())
@@ -90,10 +114,10 @@ intent.`package` = "com.example.signer"
90 val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$eventJson")) 114 val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$eventJson"))
91 intent.`package` = "com.example.signer" 115 intent.`package` = "com.example.signer"
92 intent.putExtra("type", "sign_event") 116 intent.putExtra("type", "sign_event")
93 // to control the result in your application in case you are not waiting the result before sending another intent 117 // To handle results when not waiting between intents
94 intent.putExtra("id", event.id) 118 intent.putExtra("id", event.id)
95 // Send the current logged in user npub 119 // Send the current logged in user npub
96 intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) 120 intent.putExtra("current_user", npub)
97 121
98 context.startActivity(intent) 122 context.startActivity(intent)
99 ``` 123 ```
@@ -102,7 +126,7 @@ intent.`package` = "com.example.signer"
102 126
103 ```kotlin 127 ```kotlin
104 val signature = intent.data?.getStringExtra("signature") 128 val signature = intent.data?.getStringExtra("signature")
105 // the id you sent 129 // The id you sent
106 val id = intent.data?.getStringExtra("id") 130 val id = intent.data?.getStringExtra("id")
107 val signedEventJson = intent.data?.getStringExtra("event") 131 val signedEventJson = intent.data?.getStringExtra("event")
108 ``` 132 ```
@@ -233,13 +257,13 @@ intent.`package` = "com.example.signer"
233 257
234To get the result back from Signer Application you should use contentResolver.query in Kotlin. If you are using another framework check the documentation of your framework or a third party library to get the result. 258To get the result back from Signer Application you should use contentResolver.query in Kotlin. If you are using another framework check the documentation of your framework or a third party library to get the result.
235 259
236If the user did not check the remember my choice option, the npub is not in Signer Application or the signer type is not recognized the contentResolver will return null 260If the user did not check the "remember my choice" option, the npub is not in Signer Application or the signer type is not recognized the `contentResolver` will return null
237 261
238For the SIGN_EVENT type Signer Application returns two columns "signature" and "event". The column event is the signed event json 262For the SIGN_EVENT type Signer Application returns two columns "signature" and "event". The column event is the signed event json
239 263
240For the other types Signer Application returns the column "signature" 264For the other types Signer Application returns the column "signature"
241 265
242If the user chose to always reject the event signer application will return the column "rejected" and you should not open signer application 266If the user chose to always reject the event, signer application will return the column "rejected" and you should not open signer application
243 267
244### Methods 268### Methods
245 269
@@ -416,15 +440,15 @@ If the user chose to always reject the event signer application will return the
416 440
417# Usage for Web Applications 441# Usage for Web Applications
418 442
419Since web applications can't receive a result from the intent you should add a modal to paste the signature or the event json or create a callback url. 443Since web applications can't receive a result from the intent, you should add a modal to paste the signature or the event json or create a callback url.
420 444
421If you send the callback url parameter Signer Application will send the result to the url. 445If you send the callback url parameter, Signer Application will send the result to the url.
422 446
423If you don't send a callback url Signer Application will copy the result to the clipboard. 447If you don't send a callback url, Signer Application will copy the result to the clipboard.
424 448
425You can configure the returnType to be **signature** or **event**. 449You can configure the `returnType` to be **signature** or **event**.
426 450
427Android intents and browsers url has limitations, so if you are using the returnType of **event** consider using the parameter **compressionType=gzip** that will return "Signer1" + Base 64 gzip encoded event json 451Android intents and browser urls have limitations, so if you are using the `returnType` of **event** consider using the parameter **compressionType=gzip** that will return "Signer1" + Base64 gzip encoded event json
428 452
429## Methods 453## Methods
430 454
@@ -511,4 +535,4 @@ Android intents and browsers url has limitations, so if you are using the return
511 </script> 535 </script>
512</body> 536</body>
513</html> 537</html>
514``` \ No newline at end of file 538```