From 86e44b75eb166b600affdc5248e0fe246a6ebe9b Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 8 Nov 2023 10:22:43 -0300 Subject: [PATCH 01/12] Android Signer Application nip --- 100.md | 495 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 495 insertions(+) create mode 100644 100.md diff --git a/100.md b/100.md new file mode 100644 index 00000000..3b8bc8ee --- /dev/null +++ b/100.md @@ -0,0 +1,495 @@ +# NIP-100 + +## Android Signer Application + +`draft` `optional` `author:greenart7c3` + +This NIP describes a method for 2-way communication between a android signer and any Nostr client on Android. The Android signer is an Android Application and the Client can be a Web Client or an Android Application. + +# Usage for Android applications + +The Android signer uses Intents and Content Resolvers to communicate between applications. + +To be able to use The Android signer in your application you should add the package name of the signer to your AndroidManifest.xml: + +```xml + + + +``` + +## Using Intents + +To get the result back from the Signer Appication 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. + +Create the Intent using the **nostrsigner** scheme: + +```kotlin +val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$content")) +``` + +* Set the Signer package name + +```kotlin +intent.`package` = "com.example.signer" +``` + +### Methods + +- **get_public_key** + - params: + + ```kotlin + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:")) + intent.`package` = "com.example.signer" + intent.putExtra("type", "get_public_key") + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **npub** in the signature field + + ```kotlin + val npub = intent.data?.getStringExtra("signature") + ``` + +- **sign_event** + - params: + + ```kotlin + 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 + intent.putExtra("id", event.id) + // Send the current logged in user npub + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **signature**, **id** and **event** fields + + ```kotlin + val signature = intent.data?.getStringExtra("signature") + // the id you sent + val id = intent.data?.getStringExtra("id") + val signedEventJson = intent.data?.getStringExtra("event") + ``` + +- **nip04_encrypt** + - params: + + ```kotlin + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$plaintext")) + intent.`package` = "com.example.signer" + intent.putExtra("type", "nip04_encrypt") + // to control the result in your application in case you are not waiting the result before sending another intent + intent.putExtra("id", "some_id") + // Send the current logged in user npub + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + // Send the hex pubKey that will be used for encrypting the data + intent.putExtra("pubKey", pubKey) + + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **signature** and **id** fields + + ```kotlin + val encryptedText = intent.data?.getStringExtra("signature") + // the id you sent + val id = intent.data?.getStringExtra("id") + ``` + +- **nip44_encrypt** + - params: + + ```kotlin + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$plaintext")) + intent.`package` = "com.example.signer" + intent.putExtra("type", "nip44_encrypt") + // to control the result in your application in case you are not waiting the result before sending another intent + intent.putExtra("id", "some_id") + // Send the current logged in user npub + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + // Send the hex pubKey that will be used for encrypting the data + intent.putExtra("pubKey", pubKey) + + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **signature** and **id** fields + + ```kotlin + val encryptedText = intent.data?.getStringExtra("signature") + // the id you sent + val id = intent.data?.getStringExtra("id") + ``` + +- **nip04_decrypt** + - params: + + ```kotlin + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$encryptedText")) + intent.`package` = "com.example.signer" + intent.putExtra("type", "nip04_decrypt") + // to control the result in your application in case you are not waiting the result before sending another intent + intent.putExtra("id", "some_id") + // Send the current logged in user npub + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + // Send the hex pubKey that will be used for decrypting the data + intent.putExtra("pubKey", pubKey) + + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **signature** and **id** fields + + ```kotlin + val plainText = intent.data?.getStringExtra("signature") + // the id you sent + val id = intent.data?.getStringExtra("id") + ``` + +- **nip44_decrypt** + - params: + + ```kotlin + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$encryptedText")) + intent.`package` = "com.example.signer" + intent.putExtra("type", "nip04_decrypt") + // to control the result in your application in case you are not waiting the result before sending another intent + intent.putExtra("id", "some_id") + // Send the current logged in user npub + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + // Send the hex pubKey that will be used for decrypting the data + intent.putExtra("pubKey", pubKey) + + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **signature** and **id** fields + + ```kotlin + val plainText = intent.data?.getStringExtra("signature") + // the id you sent + val id = intent.data?.getStringExtra("id") + ``` + +- **decrypt_zap_event** + - params: + + ```kotlin + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$eventJson")) + intent.`package` = "com.example.signer" + intent.putExtra("type", "decrypt_zap_event") + // to control the result in your application in case you are not waiting the result before sending another intent + intent.putExtra("id", "some_id") + // Send the current logged in user npub + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + context.startActivity(intent) + ``` + - result: + - If the user approved intent it will return the **signature** and **id** fields + + ```kotlin + val eventJson = intent.data?.getStringExtra("signature") + // the id you sent + val id = intent.data?.getStringExtra("id") + ``` + +## Using Content Resolver + +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 + +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" + +### Methods + +- **get_public_key** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.GET_PUBLIC_KEY"), + listOf("login"), + null, + null, + null + ) + ``` + - result: + - Will return the **npub** in the signature column + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + if (index < 0) return + val npub = it.getString(index) + } + ``` + +- **sign_event** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.SIGN_EVENT"), + listOf("$eventJson", "", "${logged_in_user_npub}"), + null, + null, + null + ) + ``` + - result: + - Will return the **signature** and the **event** columns + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + val indexJson = it.getColumnIndex("event") + val signature = it.getString(index) + val eventJson = it.getString(indexJson) + } + ``` + +- **nip04_encrypt** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.NIP04_ENCRYPT"), + listOf("$plainText", "${hex_pub_key}", "${logged_in_user_npub}"), + null, + null, + null + ) + ``` + - result: + - Will return the **signature** column + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + val encryptedText = it.getString(index) + } + ``` + +- **nip44_encrypt** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.NIP44_ENCRYPT"), + listOf("$plainText", "${hex_pub_key}", "${logged_in_user_npub}"), + null, + null, + null + ) + ``` + - result: + - Will return the **signature** column + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + val encryptedText = it.getString(index) + } + ``` + +- **nip04_decrypt** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.NIP04_DECRYPT"), + listOf("$encryptedText", "${hex_pub_key}", "${logged_in_user_npub}"), + null, + null, + null + ) + ``` + - result: + - Will return the **signature** column + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + val encryptedText = it.getString(index) + } + ``` + +- **nip44_decrypt** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.NIP44_DECRYPT"), + listOf("$encryptedText", "${hex_pub_key}", "${logged_in_user_npub}"), + null, + null, + null + ) + ``` + - result: + - Will return the **signature** column + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + val encryptedText = it.getString(index) + } + ``` + +- **decrypt_zap_event** + - params: + + ```kotlin + val result = context.contentResolver.query( + Uri.parse("content://com.example.signer.DECRYPT_ZAP_EVENT"), + listOf("$eventJson", "", "${logged_in_user_npub}"), + null, + null, + null + ) + ``` + - result: + - Will return the **signature** column + + ```kotlin + if (result == null) return + + if (result.moveToFirst()) { + val index = it.getColumnIndex("signature") + val eventJson = it.getString(index) + } + ``` + +# 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. + +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. + +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 + +## Methods + +- **get_public_key** + - params: + + ```js + const intent = `intent:#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=get_public_key;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +- **sign_event** + - params: + + ```js + const intent = `intent:${eventJson}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=sign_event;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +- **nip04_encrypt** + - params: + + ```js + const intent = `intent:${plainText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip04_encrypt;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +- **nip44_encrypt** + - params: + + ```js + const intent = `intent:${plainText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip44_encrypt;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +- **nip04_decrypt** + - params: + + ```js + const intent = `intent:${encryptedText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip44_encrypt;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +- **nip44_decrypt** + - params: + + ```js + const intent = `intent:${encryptedText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip44_decrypt;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +- **decrypt_zap_event** + - params: + + ```js + const intent = `intent:${eventJson}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=decrypt_zap_event;S.callbackUrl=https://example.com/?event=;end`; + + window.href = intent; + ``` + +## Example + +```js + + + + + + Document + + +

Test

+ + + + +``` \ No newline at end of file From 70a722b5d6526bf871a06290df8833492ac77b92 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 29 Nov 2023 11:22:26 -0300 Subject: [PATCH 02/12] add permissions --- 100.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/100.md b/100.md index 3b8bc8ee..56b8a91c 100644 --- a/100.md +++ b/100.md @@ -43,6 +43,17 @@ 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 + val permissions = listOf( + Permission( + "sign_event", + 22242 + ), + Permission( + "nip44_decrypt" + ) + ) + intent.putExtra("permissions", permissions.toJson()) context.startActivity(intent) ``` - result: From e050386b849d0d293903a46646c89233bf19f489 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 29 Nov 2023 11:23:14 -0300 Subject: [PATCH 03/12] signer can return the application package name when sign in --- 100.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/100.md b/100.md index 56b8a91c..2c7b8f96 100644 --- a/100.md +++ b/100.md @@ -61,6 +61,8 @@ intent.`package` = "com.example.signer" ```kotlin val npub = intent.data?.getStringExtra("signature") + // The package name of the signer application + val packageName = intent.data?.getStringExtra("package") ``` - **sign_event** From c55678b30740c1aa4aa968239fb21fb05c38a92c Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 22 Jan 2024 11:25:25 -0300 Subject: [PATCH 04/12] change androidmanifest.xml, add rejected collumn if user chose to always reject some event kind --- 100.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/100.md b/100.md index 2c7b8f96..cddb8066 100644 --- a/100.md +++ b/100.md @@ -10,14 +10,32 @@ This NIP describes a method for 2-way communication between a android signer and The Android signer uses Intents and Content Resolvers to communicate between applications. -To be able to use The Android signer in your application you should add the package name of the signer to your AndroidManifest.xml: +To be able to use The Android signer in your application you should this to your AndroidManifest.xml: ```xml - + + + + + ``` +Then you can use this function to check if there's a signer application installed: + +```kotlin +fun isExternalSignerInstalled(context: Context): Boolean { + val intent = + Intent().apply { + action = Intent.ACTION_VIEW + data = Uri.parse("nostrsigner:") + } + val infos = context.packageManager.queryIntentActivities(intent, 0) + return infos.size > 0 +} +``` + ## Using Intents To get the result back from the Signer Appication 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. @@ -221,6 +239,8 @@ For the SIGN_EVENT type Signer Application returns two columns "signature" and " 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 + ### Methods - **get_public_key** From ded4c1659ce838625705f86bb563df7507d52503 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 14 Feb 2024 14:37:42 -0300 Subject: [PATCH 05/12] fix typo --- 100.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/100.md b/100.md index cddb8066..ee5149ae 100644 --- a/100.md +++ b/100.md @@ -468,7 +468,7 @@ Android intents and browsers url has limitations, so if you are using the return - params: ```js - const intent = `intent:${encryptedText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip44_encrypt;S.callbackUrl=https://example.com/?event=;end`; + const intent = `intent:${encryptedText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip04_decrypt;S.callbackUrl=https://example.com/?event=;end`; window.href = intent; ``` From bf7294b22362539eda549d8a7fd0d85261f40b3f Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Fri, 8 Mar 2024 07:59:54 -0300 Subject: [PATCH 06/12] Removed author --- 100.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/100.md b/100.md index ee5149ae..bf773962 100644 --- a/100.md +++ b/100.md @@ -2,7 +2,7 @@ ## Android Signer Application -`draft` `optional` `author:greenart7c3` +`draft` `optional` This NIP describes a method for 2-way communication between a android signer and any Nostr client on Android. The Android signer is an Android Application and the Client can be a Web Client or an Android Application. From 07074d8ba2615609fb702030151e191edcc91909 Mon Sep 17 00:00:00 2001 From: greenart7c3 <115044884+greenart7c3@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:20:19 -0300 Subject: [PATCH 07/12] Apply suggestions from code review Co-authored-by: dluvian <133484344+dluvian@users.noreply.github.com> --- 100.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/100.md b/100.md index bf773962..06d6b355 100644 --- a/100.md +++ b/100.md @@ -4,13 +4,13 @@ `draft` `optional` -This NIP describes a method for 2-way communication between a android signer and any Nostr client on Android. The Android signer is an Android Application and the Client can be a Web Client or an Android Application. +This NIP describes a method for 2-way communication between an Android signer and any Nostr client on Android. The Android signer is an Android Application and the client can be a web client or an Android application. # Usage for Android applications The Android signer uses Intents and Content Resolvers to communicate between applications. -To be able to use The Android signer in your application you should this to your AndroidManifest.xml: +To be able to use the Android signer in your application you should add this to your AndroidManifest.xml: ```xml @@ -38,7 +38,7 @@ fun isExternalSignerInstalled(context: Context): Boolean { ## Using Intents -To get the result back from the Signer Appication 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. +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. Create the Intent using the **nostrsigner** scheme: From 4842f8612f55d9c11ef228338f6ef6f658e788a1 Mon Sep 17 00:00:00 2001 From: greenart7c3 <115044884+greenart7c3@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:00:30 -0300 Subject: [PATCH 08/12] Apply suggestions from code review Co-authored-by: dluvian <133484344+dluvian@users.noreply.github.com> --- 100.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/100.md b/100.md index 06d6b355..386ec802 100644 --- a/100.md +++ b/100.md @@ -46,7 +46,7 @@ Create the Intent using the **nostrsigner** scheme: 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" @@ -61,14 +61,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", // Is it type? + kind = 22242 // Is it kind? ), Permission( - "nip44_decrypt" + type = "nip44_decrypt" ) ) intent.putExtra("permissions", permissions.toJson()) @@ -90,10 +90,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 +102,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 +233,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 +416,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 From 6b26ebe6c5c9834549aa9adec0d066bc5c6aae88 Mon Sep 17 00:00:00 2001 From: greenart7c3 <115044884+greenart7c3@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:01:03 -0300 Subject: [PATCH 09/12] Update 100.md --- 100.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/100.md b/100.md index 386ec802..79ced802 100644 --- a/100.md +++ b/100.md @@ -64,8 +64,8 @@ intent.`package` = "com.example.signer" // You can send some default permissions for the user to authorize for ever val permissions = listOf( Permission( - type = "sign_event", // Is it type? - kind = 22242 // Is it kind? + type = "sign_event", + kind = 22242 ), Permission( type = "nip44_decrypt" @@ -525,4 +525,4 @@ Android intents and browser urls have limitations, so if you are using the `retu -``` \ No newline at end of file +``` From a2aaa3c00b18e2e11dceae9400cd6fc429562622 Mon Sep 17 00:00:00 2001 From: greenart7c3 <115044884+greenart7c3@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:10:25 -0300 Subject: [PATCH 10/12] add example of rememberLauncherForActivityResult --- 100.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/100.md b/100.md index 79ced802..24bf09f1 100644 --- a/100.md +++ b/100.md @@ -40,6 +40,24 @@ 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 @@ -52,6 +70,12 @@ Set the Signer package name: intent.`package` = "com.example.signer" ``` +Send the Intent: + +```kotlin +launcher.launch(intent) +``` + ### Methods - **get_public_key** From b21e996a89a9fe2acb09136792c75b1dd8eb59f8 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 29 Apr 2024 08:55:55 -0300 Subject: [PATCH 11/12] Change web app methods do use nostrsigner: instead of intent: --- 100.md | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/100.md b/100.md index 06d6b355..99feebf0 100644 --- a/100.md +++ b/100.md @@ -432,63 +432,49 @@ Android intents and browsers url has limitations, so if you are using the return - params: ```js - const intent = `intent:#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=get_public_key;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:?compressionType=none;returnType=signature;type=get_public_key;callbackUrl=https://example.com/?event=`; ``` - **sign_event** - params: ```js - const intent = `intent:${eventJson}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=sign_event;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:${eventJson}?compressionType=none;returnType=signature;type=sign_event;callbackUrl=https://example.com/?event=`; ``` - **nip04_encrypt** - params: ```js - const intent = `intent:${plainText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip04_encrypt;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:${plainText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip04_encrypt;callbackUrl=https://example.com/?event=`; ``` - **nip44_encrypt** - params: ```js - const intent = `intent:${plainText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip44_encrypt;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:${plainText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip44_encrypt;callbackUrl=https://example.com/?event=`; ``` - **nip04_decrypt** - params: ```js - const intent = `intent:${encryptedText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip04_decrypt;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:${encryptedText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip04_decrypt;callbackUrl=https://example.com/?event=`; ``` - **nip44_decrypt** - params: ```js - const intent = `intent:${encryptedText}#Intent;scheme=nostrsigner;S.pubKey=${hex_pub_key};S.compressionType=none;S.returnType=signature;S.type=nip44_decrypt;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:${encryptedText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip44_decrypt;callbackUrl=https://example.com/?event=`; ``` - **decrypt_zap_event** - params: ```js - const intent = `intent:${eventJson}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=decrypt_zap_event;S.callbackUrl=https://example.com/?event=;end`; - - window.href = intent; + window.href = `nostrsigner:${eventJson}?compressionType=none;returnType=signature;type=decrypt_zap_event;callbackUrl=https://example.com/?event=`; ``` ## Example @@ -518,7 +504,7 @@ Android intents and browsers url has limitations, so if you are using the return } let encodedJson = encodeURIComponent(JSON.stringify(json)) var newAnchor = document.createElement("a"); - newAnchor.href = `intent:${encodedJson}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=sign_event;S.callbackUrl=https://example.com/?event=;end`; + newAnchor.href = `nostrsigner:${encodedJson}?compressionType=none;returnType=signature;type=sign_event;callbackUrl=https://example.com/?event=`; newAnchor.textContent = "Open External Signer"; document.body.appendChild(newAnchor) } From ff24a56355471761d89399167a75a74e3bbb5677 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 29 Apr 2024 09:25:04 -0300 Subject: [PATCH 12/12] ; -> & --- 100.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/100.md b/100.md index 571d1eb2..4a304c3a 100644 --- a/100.md +++ b/100.md @@ -456,49 +456,49 @@ Android intents and browser urls have limitations, so if you are using the `retu - params: ```js - window.href = `nostrsigner:?compressionType=none;returnType=signature;type=get_public_key;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:?compressionType=none&returnType=signature&type=get_public_key&callbackUrl=https://example.com/?event=`; ``` - **sign_event** - params: ```js - window.href = `nostrsigner:${eventJson}?compressionType=none;returnType=signature;type=sign_event;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:${eventJson}?compressionType=none&returnType=signature&type=sign_event&callbackUrl=https://example.com/?event=`; ``` - **nip04_encrypt** - params: ```js - window.href = `nostrsigner:${plainText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip04_encrypt;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:${plainText}?pubKey=${hex_pub_key}&compressionType=none&returnType=signature&type=nip04_encrypt&callbackUrl=https://example.com/?event=`; ``` - **nip44_encrypt** - params: ```js - window.href = `nostrsigner:${plainText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip44_encrypt;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:${plainText}?pubKey=${hex_pub_key}&compressionType=none&returnType=signature&type=nip44_encrypt&callbackUrl=https://example.com/?event=`; ``` - **nip04_decrypt** - params: ```js - window.href = `nostrsigner:${encryptedText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip04_decrypt;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:${encryptedText}?pubKey=${hex_pub_key}&compressionType=none&returnType=signature&type=nip04_decrypt&callbackUrl=https://example.com/?event=`; ``` - **nip44_decrypt** - params: ```js - window.href = `nostrsigner:${encryptedText}?pubKey=${hex_pub_key};compressionType=none;returnType=signature;type=nip44_decrypt;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:${encryptedText}?pubKey=${hex_pub_key}&compressionType=none&returnType=signature&type=nip44_decrypt&callbackUrl=https://example.com/?event=`; ``` - **decrypt_zap_event** - params: ```js - window.href = `nostrsigner:${eventJson}?compressionType=none;returnType=signature;type=decrypt_zap_event;callbackUrl=https://example.com/?event=`; + window.href = `nostrsigner:${eventJson}?compressionType=none&returnType=signature&type=decrypt_zap_event&callbackUrl=https://example.com/?event=`; ``` ## Example @@ -528,7 +528,7 @@ Android intents and browser urls have limitations, so if you are using the `retu } let encodedJson = encodeURIComponent(JSON.stringify(json)) var newAnchor = document.createElement("a"); - newAnchor.href = `nostrsigner:${encodedJson}?compressionType=none;returnType=signature;type=sign_event;callbackUrl=https://example.com/?event=`; + newAnchor.href = `nostrsigner:${encodedJson}?compressionType=none&returnType=signature&type=sign_event&callbackUrl=https://example.com/?event=`; newAnchor.textContent = "Open External Signer"; document.body.appendChild(newAnchor) }