From 5ee7a1b406c3dfda8f55e32bccc602ffbe8763eb Mon Sep 17 00:00:00 2001 From: Susumu OTA <1632335+susumuota@users.noreply.github.com> Date: Sun, 26 Feb 2023 23:26:52 +0900 Subject: [PATCH 1/5] feat: add Windows install/uninstall scripts. --- public/windows/install_host.bat | 6 ++++++ public/windows/io.github.susumuota.nostr_keyx.json | 2 +- public/windows/uninstall_host.bat | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 public/windows/install_host.bat create mode 100644 public/windows/uninstall_host.bat diff --git a/public/windows/install_host.bat b/public/windows/install_host.bat new file mode 100644 index 0000000..5f3306a --- /dev/null +++ b/public/windows/install_host.bat @@ -0,0 +1,6 @@ +:: SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com> +:: SPDX-License-Identifier: MIT +:: +:: https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location + +REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx" /ve /t REG_SZ /d "%~dp0io.github.susumuota.nostr_keyx.json" /f diff --git a/public/windows/io.github.susumuota.nostr_keyx.json b/public/windows/io.github.susumuota.nostr_keyx.json index aff915f..fae6df7 100644 --- a/public/windows/io.github.susumuota.nostr_keyx.json +++ b/public/windows/io.github.susumuota.nostr_keyx.json @@ -1,7 +1,7 @@ { "name": "io.github.susumuota.nostr_keyx", "description": "A NIP-07 browser extension that uses the OS's native keychain application to protect your private keys.", - "path": "C:\\path\\to\\dist\\windows\\keychain.bat", + "path": "keychain.bat", "type": "stdio", "allowed_origins": [ "chrome-extension://(WRITE EXTENSION ID HERE WITHOUT BRACKETS)/" diff --git a/public/windows/uninstall_host.bat b/public/windows/uninstall_host.bat new file mode 100644 index 0000000..5e4bc61 --- /dev/null +++ b/public/windows/uninstall_host.bat @@ -0,0 +1,6 @@ +:: SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com> +:: SPDX-License-Identifier: MIT +:: +:: https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location + +REG DELETE "HKLM\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx" /f From 01bf32db50b3f403d24fab96f6353ff98ddbb8db Mon Sep 17 00:00:00 2001 From: Susumu OTA <1632335+susumuota@users.noreply.github.com> Date: Mon, 27 Feb 2023 02:53:26 +0900 Subject: [PATCH 2/5] feat: add install.ps1 and uninstall.ps1. --- public/windows/install.ps1 | 14 ++++++++++++++ public/windows/install_host.bat | 6 ------ ...on => io.github.susumuota.nostr_keyx.json.stab} | 2 +- public/windows/uninstall.ps1 | 8 ++++++++ public/windows/uninstall_host.bat | 6 ------ 5 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 public/windows/install.ps1 delete mode 100644 public/windows/install_host.bat rename public/windows/{io.github.susumuota.nostr_keyx.json => io.github.susumuota.nostr_keyx.json.stab} (77%) create mode 100644 public/windows/uninstall.ps1 delete mode 100644 public/windows/uninstall_host.bat diff --git a/public/windows/install.ps1 b/public/windows/install.ps1 new file mode 100644 index 0000000..e66da40 --- /dev/null +++ b/public/windows/install.ps1 @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com> +# SPDX-License-Identifier: MIT + +param([Parameter(Mandatory)][ValidatePattern("^[a-z]+$")][string] $extension_id) + +$json = ".\io.github.susumuota.nostr_keyx.json" +$path = "HKCU:\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx" +$stab = $json + ".stab" + +Get-Content $stab | ForEach-Object { $_ -creplace "__EXTENSION_ID__", $extension_id } | Out-File $json -Encoding ascii +New-Item -Path $path -Value (Convert-Path $json) -Force + +"Done!" +Pause diff --git a/public/windows/install_host.bat b/public/windows/install_host.bat deleted file mode 100644 index 5f3306a..0000000 --- a/public/windows/install_host.bat +++ /dev/null @@ -1,6 +0,0 @@ -:: SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com> -:: SPDX-License-Identifier: MIT -:: -:: https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location - -REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx" /ve /t REG_SZ /d "%~dp0io.github.susumuota.nostr_keyx.json" /f diff --git a/public/windows/io.github.susumuota.nostr_keyx.json b/public/windows/io.github.susumuota.nostr_keyx.json.stab similarity index 77% rename from public/windows/io.github.susumuota.nostr_keyx.json rename to public/windows/io.github.susumuota.nostr_keyx.json.stab index fae6df7..f8aae46 100644 --- a/public/windows/io.github.susumuota.nostr_keyx.json +++ b/public/windows/io.github.susumuota.nostr_keyx.json.stab @@ -4,6 +4,6 @@ "path": "keychain.bat", "type": "stdio", "allowed_origins": [ - "chrome-extension://(WRITE EXTENSION ID HERE WITHOUT BRACKETS)/" + "chrome-extension://__EXTENSION_ID__/" ] } diff --git a/public/windows/uninstall.ps1 b/public/windows/uninstall.ps1 new file mode 100644 index 0000000..a85dc69 --- /dev/null +++ b/public/windows/uninstall.ps1 @@ -0,0 +1,8 @@ +# SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com> +# SPDX-License-Identifier: MIT + +$path = "HKCU:\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx" + +Remove-Item -Path $path -Force + +"Done!" diff --git a/public/windows/uninstall_host.bat b/public/windows/uninstall_host.bat deleted file mode 100644 index 5e4bc61..0000000 --- a/public/windows/uninstall_host.bat +++ /dev/null @@ -1,6 +0,0 @@ -:: SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com> -:: SPDX-License-Identifier: MIT -:: -:: https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location - -REG DELETE "HKLM\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx" /f From 2d81b31c3b7b1c0f8e0724a9cc453182bbf088f4 Mon Sep 17 00:00:00 2001 From: Susumu OTA <1632335+susumuota@users.noreply.github.com> Date: Mon, 27 Feb 2023 03:15:45 +0900 Subject: [PATCH 3/5] fix: typo. --- public/windows/install.ps1 | 2 +- public/windows/uninstall.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/windows/install.ps1 b/public/windows/install.ps1 index e66da40..5583eb3 100644 --- a/public/windows/install.ps1 +++ b/public/windows/install.ps1 @@ -10,5 +10,5 @@ $stab = $json + ".stab" Get-Content $stab | ForEach-Object { $_ -creplace "__EXTENSION_ID__", $extension_id } | Out-File $json -Encoding ascii New-Item -Path $path -Value (Convert-Path $json) -Force -"Done!" +Write-Output "Done!" Pause diff --git a/public/windows/uninstall.ps1 b/public/windows/uninstall.ps1 index a85dc69..a884425 100644 --- a/public/windows/uninstall.ps1 +++ b/public/windows/uninstall.ps1 @@ -5,4 +5,5 @@ $path = "HKCU:\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.n Remove-Item -Path $path -Force -"Done!" +Write-Output "Done!" +Pause From 794d6880be814162a241a76611f375bca73dbe5f Mon Sep 17 00:00:00 2001 From: Susumu OTA <1632335+susumuota@users.noreply.github.com> Date: Mon, 27 Feb 2023 04:09:48 +0900 Subject: [PATCH 4/5] fix: rewrite to use install.sh. --- README.md | 68 ++++++++++++-------------- public/windows/register_nostr_keyx.reg | 3 -- 2 files changed, 30 insertions(+), 41 deletions(-) delete mode 100644 public/windows/register_nostr_keyx.reg diff --git a/README.md b/README.md index 419ba4a..9229570 100644 --- a/README.md +++ b/README.md @@ -101,33 +101,40 @@ cp -p dist/unix/io.github.susumuota.nostr_keyx.json ~/Library/Application\ Suppo #### For Windows -- You need to edit 2 lines in `dist/windows/io.github.susumuota.nostr_keyx.json`. - - Change `path` to specify the absolute path of `keychain.bat`. - - Change `allowed_origins` to specify the `id` of the extension. You can find the `id` of the extension in Chrome's extensions setting page `chrome://extensions`. - - See [this page](https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host) for more details. +- First, you need to allow PowerShell to run scripts. +- Open PowerShell as an **Administrator**. +- Run the following command to allow executing script. See details [here](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3#remotesigned). -```json -{ - "name": "io.github.susumuota.nostr_keyx", - "description": "A NIP-07 browser extension that uses the OS's native keychain application to protect your private keys.", - "path": "C:\\path\\to\\dist\\windows\\keychain.bat", - "type": "stdio", - "allowed_origins": [ - "chrome-extension://jhpjgkhjimkbjiigognoefgnclgngklh/" - ] -} +```powershell +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned ``` -- Edit `dist/windows/register_nostr_keyx.reg`. - - Change `@="..."` to specify the absolute path of `dist/windows/io.github.susumuota.nostr_keyx.json`. See [this page](https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location) for more details. +- Exit PowerShell of **Administrator**. +- Open PowerShell as a **normal user**. +- Run `Unblock-File` to unblock PowerShell script files that were downloaded from the internet so you can run them. See details [here](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/unblock-file?view=powershell-7.3). -```reg -Windows Registry Editor Version 5.00 -[HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx] -@="C:\\path\\to\\dist\\windows\\io.github.susumuota.nostr_keyx.json" +```powershell +cd C:\path\to\dist\windows +Unblock-File .\install.ps1 +Unblock-File .\uninstall.ps1 +Unblock-File .\add_privatekey.ps1 +Unblock-File .\get_privatekey.ps1 ``` -- Double click `register_nostr_keyx.reg` on Explorer. It will add registry key. You can check it on Registry Editor by searching `nostr_keyx`. If you want to uninstall this extension, delete the registry key too. +> **Note**: I recommend that you should check the contents of PowerShell script files before you run them. I have tested them in my environment, but I cannot guarantee anything. Basically, `install.ps1` performs the steps on [this page](https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location) in PowerShell. + +- Run `install.ps1` to install the extension. + +```powershell +.\install.ps1 +``` + +- Paste the `id` of the extension. You can find the `id` of the extension in Chrome's extensions setting page `chrome://extensions`. +- If you want to uninstall the extension, run `uninstall.ps1`. + +```powershell +.\uninstall.ps1 +``` ### Set your private key @@ -188,29 +195,14 @@ security find-generic-password -a default -s nostr-keyx -w #### For Windows: Using command `add_privatekey.ps1` -- You need to allow PowerShell to run local scripts. Open PowerShell as **Administrator** and run the following command to allow executing script. See details [here](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3#remotesigned). - -```powershell -Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -``` - -- Exit PowerShell as **Administrator**. Then, open PowerShell as a normal user. -- Run `Unblock-File` to unblock PowerShell script files that were downloaded from the internet so you can run them. See details [here](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/unblock-file?view=powershell-7.3). - -```powershell -cd C:\path\to\dist\windows -Unblock-File .\add_privatekey.ps1 -Unblock-File .\get_privatekey.ps1 -``` - - Copy private key (e.g. `nsec1...`) to clipboard. -- Run `add_privatekey.ps1` script to create a new entry for your private key. Here, `nostr-keyx` is the service name. It **MUST** be `nostr-keyx`. +- Run `add_privatekey.ps1` to create a new entry for your private key. You **MUST** pass `nostr-keyx` as an argument. ```powershell .\add_privatekey.ps1 "nostr-keyx" ``` -- Dialog will be shown. Type `default` to `User name` and paste your private key to `Password` and click `OK`. +- Dialog will be shown. Type `default` to `User name` field, paste your private key to `Password` field, then click `OK`. ![get_credential](https://user-images.githubusercontent.com/1632335/221339350-122fa0c2-e0a4-4843-bdd4-8fef58aec3a8.png) diff --git a/public/windows/register_nostr_keyx.reg b/public/windows/register_nostr_keyx.reg deleted file mode 100644 index 9700ae3..0000000 --- a/public/windows/register_nostr_keyx.reg +++ /dev/null @@ -1,3 +0,0 @@ -Windows Registry Editor Version 5.00 -[HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\io.github.susumuota.nostr_keyx] -@="C:\\path\\to\\dist\\windows\\io.github.susumuota.nostr_keyx.json" From 60c0662079198118536f3b79f6ef6af5600385ff Mon Sep 17 00:00:00 2001 From: Susumu OTA <1632335+susumuota@users.noreply.github.com> Date: Mon, 27 Feb 2023 14:34:51 +0900 Subject: [PATCH 5/5] docs: refine structure. --- README.md | 51 +++++++++++-------- ... io.github.susumuota.nostr_keyx.json.stab} | 0 2 files changed, 30 insertions(+), 21 deletions(-) rename public/unix/{io.github.susumuota.nostr_keyx.json => io.github.susumuota.nostr_keyx.json.stab} (100%) diff --git a/README.md b/README.md index 9229570..1ca6f87 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,16 @@ A [NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md) browser ext There are already great extensions like [nos2x](https://github.com/fiatjaf/nos2x) or [Alby](https://getalby.com/) for [NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md). Unlike these existing extensions, `nostr-keyx` uses the **OS's native keychain application** (e.g. [Keychain Access](https://support.apple.com/guide/keychain-access/what-is-keychain-access-kyca1083/mac) on MacOS) to store your private key instead of the web browser's local storage. In addition, all of the [NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md) functions (`signEvent`, `encrypt`, `decrypt`, etc.) are executed outside of the web browser's memory. So it might be less risky than other extensions. I hope this extension helps you too. -## Install - -### Install Node.js +## Download -- `nostr-keyx` uses [Node.js](https://nodejs.org/) to provide NIP-07 functions. -- Install [Node.js](https://nodejs.org/). e.g. `brew install node` for macOS with Homebrew. -- Open Terminal and run `which node` and copy the absolute path of `node` command. e.g. `/usr/local/bin/node`. We will use it later. +- There are 2 options to download `nostr-keyx`. ### Option 1: Download zip file - Download the latest zip file from [Releases](https://github.com/susumuota/nostr-keyx/releases). - Unzip it. `nostr-keyx-{version}.zip` will be extracted to `nostr-keyx-{version}` folder. -### Option 2: Build from source +### Option 2: Download with `git` and build from source > **Note**: For Windows, install [Git for Windows](https://gitforwindows.org/), start `git-bash` and run `npm config set script-shell /usr/bin/bash`. Otherwise, you will get error at `npm run build`. @@ -46,6 +42,16 @@ npm ci npm run build ``` +## Install + +- You need to install Node.js, a Chrome extension and a Chrome native messaging host to run `nostr-keyx`. + +### Install Node.js + +- `nostr-keyx` uses [Node.js](https://nodejs.org/) to provide NIP-07 functions and access the OS's native keychain application. +- Install [Node.js](https://nodejs.org/) and make sure `node` command is available in your terminal. +- Open a terminal and run `which node` and copy the absolute path of `node` command. e.g. `/usr/local/bin/node`. We will use it later. + ### Install Chrome extension - Open Chrome's extensions setting page `chrome://extensions`. @@ -55,9 +61,10 @@ npm run build - You will see error messages but it's OK for now. - Copy the `id` of the extension. e.g. `jhpjgkhjimkbjiigognoefgnclgngklh`. We will use it later. -### Setup Chrome's Native Messaging +### Install Chrome native messaging host -- This extension uses [Chrome's Native Messaging](https://developer.chrome.com/docs/apps/nativeMessaging/) to communicate with native Node.js script. +- This extension uses [Chrome Native Messaging](https://developer.chrome.com/docs/apps/nativeMessaging/) to communicate with native Node.js script. +- You need to install a native messaging host which is a JSON file that specifies the absolute path of the Node.js script. #### For macOS and Linux @@ -123,26 +130,28 @@ Unblock-File .\get_privatekey.ps1 > **Note**: I recommend that you should check the contents of PowerShell script files before you run them. I have tested them in my environment, but I cannot guarantee anything. Basically, `install.ps1` performs the steps on [this page](https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location) in PowerShell. -- Run `install.ps1` to install the extension. +- Run `install.ps1` to install the native messaging host. ```powershell .\install.ps1 ``` -- Paste the `id` of the extension. You can find the `id` of the extension in Chrome's extensions setting page `chrome://extensions`. -- If you want to uninstall the extension, run `uninstall.ps1`. +- Paste the `id` of the extension. e.g. `jhpjgkhjimkbjiigognoefgnclgngklh`. You can find the `id` of the extension in Chrome's extensions setting page `chrome://extensions`. +- If you want to uninstall the native messaging host, run `uninstall.ps1`. ```powershell .\uninstall.ps1 ``` -### Set your private key +## Setup + +- Save your private key to the OS's native keychain application. -> **Note**: If you need a private key for test, you can generate it with `npm run genkey`. +> **Note**: If you need private keys for test, you can generate them with `npm run genkey` (needs source, see option 2 above). -#### For macOS: Option 1: Using command `security` +### For macOS: Option 1: Using command `security` -- Here, I show you how to set your private key on Terminal. You can also use GUI [Keychain Access](https://support.apple.com/guide/keychain-access/what-is-keychain-access-kyca1083/mac). I will show you later. +- Here, I show you how to save your private key on Terminal. You can also use [Keychain Access](https://support.apple.com/guide/keychain-access/what-is-keychain-access-kyca1083/mac). I will show you later. - Copy private key (e.g. `nsec1...`) to clipboard. - Open Terminal. - Run `security add-generic-password` command to create a new entry for your private key. Here, `-a` specifies the account name e.g `default`, `-s` specifies the service name (service **MUST** be `nostr-keyx`), and `-w` means the password will be asked. @@ -165,11 +174,11 @@ security find-generic-password -a default -s nostr-keyx -w security delete-generic-password -a default -s nostr-keyx ``` -- You can create multiple accounts for multiple private keys. e.g. `default`, `bot`, `test`, etc. But service name must be `nostr-keyx`. +- You can create multiple accounts for multiple private keys. e.g. `default`, `bot`, `test`, etc. But service name **MUST** be `nostr-keyx`. > **Note**: Right now, `security` command can access the private key without password. But you can revoke that by Keychain Access application. See the next section. -#### For macOS: Option 2: Using GUI [Keychain Access](https://support.apple.com/guide/keychain-access/what-is-keychain-access-kyca1083/mac) +### For macOS: Option 2: Using [Keychain Access](https://support.apple.com/guide/keychain-access/what-is-keychain-access-kyca1083/mac) - Open spotlight search and type `Keychain Access` and open it. - `File` menu > `New Password Item...` @@ -193,7 +202,7 @@ security find-generic-password -a default -s nostr-keyx -w ![revoke_application](https://user-images.githubusercontent.com/1632335/220175649-39b206cc-a845-4c48-83ec-367668aacabe.png) -#### For Windows: Using command `add_privatekey.ps1` +### For Windows: Using command `add_privatekey.ps1` - Copy private key (e.g. `nsec1...`) to clipboard. - Run `add_privatekey.ps1` to create a new entry for your private key. You **MUST** pass `nostr-keyx` as an argument. @@ -211,7 +220,7 @@ security find-generic-password -a default -s nostr-keyx -w ![credential_manager](https://user-images.githubusercontent.com/1632335/221339296-9fa1eddb-bcff-47c1-859f-0ac717f2bf81.png) -#### For Linux: Using command `pass` +### For Linux: Using command `pass` - Setup `pass`. See [this page](https://www.passwordstore.org/). - Copy private key (e.g. `nsec1...`) to clipboard. @@ -268,7 +277,7 @@ await chrome.storage.session.clear(); - Post some notes. It should use `window.nostr.signEvent` to sign events with private key. - Send/receive direct messages. It should use `window.nostr.nip04.encrypt/decrypt` to encrypt/decrypt messages. -### Usage +## Usage - You can change account (private key) by popup UI of the extension. diff --git a/public/unix/io.github.susumuota.nostr_keyx.json b/public/unix/io.github.susumuota.nostr_keyx.json.stab similarity index 100% rename from public/unix/io.github.susumuota.nostr_keyx.json rename to public/unix/io.github.susumuota.nostr_keyx.json.stab