This commit is contained in:
greenart7c3 2024-04-29 08:56:19 -03:00
commit 6ee0648f00
No known key found for this signature in database
GPG Key ID: 885822EED3A26A6D

56
100.md
View File

@ -40,18 +40,42 @@ fun isExternalSignerInstalled(context: Context): Boolean {
To 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.
```kotlin
val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = { result ->
if (result.resultCode != Activity.RESULT_OK) {
Toast.makeText(
context,
"Sign request rejected",
Toast.LENGTH_SHORT
).show()
} else {
val signature = activityResult.data?.getStringExtra("signature")
// Do something with signature ...
}
}
)
```
Create the Intent using the **nostrsigner** scheme:
```kotlin
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$content"))
```
* Set the Signer package name
Set the Signer package name:
```kotlin
intent.`package` = "com.example.signer"
```
Send the Intent:
```kotlin
launcher.launch(intent)
```
### Methods
- **get_public_key**
@ -61,14 +85,14 @@ intent.`package` = "com.example.signer"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:"))
intent.`package` = "com.example.signer"
intent.putExtra("type", "get_public_key")
// You can send some default permissions for the user authorize for ever
// You can send some default permissions for the user to authorize for ever
val permissions = listOf(
Permission(
"sign_event",
22242
type = "sign_event",
kind = 22242
),
Permission(
"nip44_decrypt"
type = "nip44_decrypt"
)
)
intent.putExtra("permissions", permissions.toJson())
@ -90,10 +114,10 @@ intent.`package` = "com.example.signer"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$eventJson"))
intent.`package` = "com.example.signer"
intent.putExtra("type", "sign_event")
// to control the result in your application in case you are not waiting the result before sending another intent
// To handle results when not waiting between intents
intent.putExtra("id", event.id)
// Send the current logged in user npub
intent.putExtra("current_user", account.keyPair.pubKey.toNpub())
intent.putExtra("current_user", npub)
context.startActivity(intent)
```
@ -102,7 +126,7 @@ intent.`package` = "com.example.signer"
```kotlin
val signature = intent.data?.getStringExtra("signature")
// the id you sent
// The id you sent
val id = intent.data?.getStringExtra("id")
val signedEventJson = intent.data?.getStringExtra("event")
```
@ -233,13 +257,13 @@ intent.`package` = "com.example.signer"
To 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.
If 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
If 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
For the SIGN_EVENT type Signer Application returns two columns "signature" and "event". The column event is the signed event json
For the other types Signer Application returns the column "signature"
If the user chose to always reject the event signer application will return the column "rejected" and you should not open signer application
If the user chose to always reject the event, signer application will return the column "rejected" and you should not open signer application
### Methods
@ -416,15 +440,15 @@ If the user chose to always reject the event signer application will return the
# Usage for Web Applications
Since 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.
Since 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.
If you send the callback url parameter Signer Application will send the result to the url.
If you send the callback url parameter, Signer Application will send the result to the url.
If you don't send a callback url Signer Application will copy the result to the clipboard.
If you don't send a callback url, Signer Application will copy the result to the clipboard.
You can configure the returnType to be **signature** or **event**.
You can configure the `returnType` to be **signature** or **event**.
Android 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
Android 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
## Methods
@ -511,4 +535,4 @@ Android intents and browsers url has limitations, so if you are using the return
</script>
</body>
</html>
```
```