Compare commits

16 Commits

Author SHA1 Message Date
Ren Amamiya
72b9dcddc1 feat: add support for nip44 2026-04-08 11:54:00 +07:00
Ren Amamiya
387796faa3 chore: format and lint 2026-04-08 11:28:39 +07:00
Ren Amamiya
5b7b06ff5d chore: revert last 3 commits 2026-04-08 10:35:58 +07:00
reya
db9e0b43e5 wip: migrate to typescript 2024-12-22 08:25:14 +07:00
reya
a1d87bcd74 wip: update 2024-12-22 07:35:25 +07:00
reya
8349bec65a chore: update dependencies 2024-12-22 07:06:31 +07:00
reya
12134c608f bump firefox version 2023-12-05 08:19:22 +07:00
reya
a7d0dc4669 bump version 2023-12-05 08:18:54 +07:00
reya
075153946f fix firefox 2023-12-05 08:17:22 +07:00
reya
dee66f230d fix build for macos 2023-11-28 08:10:12 +07:00
reya
db509a1451 fix build 2023-11-27 15:33:05 +07:00
reya
6a604d0d58 wip: support safari 2023-11-27 15:08:42 +07:00
reya
89675cc986 fix output 2023-11-27 12:36:05 +07:00
reya
a1d3958fb5 improve build and package 2023-11-27 12:26:13 +07:00
reya
0bb9976497 add support for firefox android 2023-11-26 08:33:30 +07:00
Ren Amamiya
a21ea64b8e Merge pull request #1 from reyamir/nostr-connect
Implemented nostr connect redesign
2023-11-21 10:25:23 +07:00
90 changed files with 107853 additions and 5202 deletions

View File

@@ -1,148 +0,0 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 2020,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module",
"allowImportExportEverywhere": false
},
"env": {
"es6": true,
"node": true
},
"plugins": [
"react",
"babel"
],
"globals": {
"document": false,
"navigator": false,
"window": false,
"location": false,
"URL": false,
"URLSearchParams": false,
"fetch": false,
"EventSource": false,
"localStorage": false,
"sessionStorage": false
},
"rules": {
"react/jsx-uses-vars": 2,
"react/jsx-no-undef": 2,
"react/jsx-uses-react": 2,
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": 0,
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [0, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": 0,
"jsx-quotes": [2, "prefer-double"],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": 0,
"new-parens": 0,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 0,
"no-debugger": 0,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty-pattern": 2,
"no-eval": 0,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [0, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": [2, { "allowLoop": false, "allowSwitch": false }],
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 2 }],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-new": 0,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-symbol": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 0,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 0,
"no-self-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "local", "args": "none", "varsIgnorePattern": "^_"}],
"no-useless-call": 2,
"no-useless-constructor": 2,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [2, "never"],
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"semi": [2, "never"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": 0,
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": 0,
"template-curly-spacing": [2, "never"],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yield-star-spacing": [2, "both"],
"yoda": 0,
"no-unsafe-optional-chaning": 0
}
}

8
.gitignore vendored
View File

@@ -1,4 +1,10 @@
node_modules node_modules
*.build.js *.build.js
*.zip *.zip
/extension/build/style.css *.xpi
/extension/releases/*.zip
/extension/releases/*.xpi
/extension/output/*.js
/extension/output/*.html
/extension/output/*.css
/extension/output/*.json

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io

View File

@@ -1,9 +0,0 @@
arrowParens: avoid
bracketSpacing: false
jsxBracketSameLine: false
printWidth: 80
proseWrap: preserve
semi: false
singleQuote: true
trailingComma: none
useTabs: false

40
AGENTS.md Normal file
View File

@@ -0,0 +1,40 @@
# AGENTS.md
## Build Commands
```bash
bun run dev # Development: runs build.js + tailwindcss --watch
bun run build # Production build → extension/output
bun run package:chrome # Creates extension/releases/nostrconnect_chrome.zip
bun run package:firefox # Creates extension/releases/nostrconnect_firefox.xpi
bun run lint # Run Biome linter
bun run format # Format with Biome (auto-fix)
bun run test # Run tests with Vitest
bun run test:watch # Run tests in watch mode
```
## Key Facts
- **Package manager**: bun (preferred) or pnpm. Uses `@jsr` registry for `@nostr/tools`
- **Build output**: `extension/output/` (not `dist/`)
- **Ignore `extension/output/`**: It contains generated JS/HTML/CSS and is gitignored
- **Tailwind source**: `extension/style.css``extension/output/style.css`
## Architecture
| File | Purpose |
| ---------------------------------------- | --------------------------------------------------------- |
| `background.js` | Core logic: state, permissions, crypto (signEvent, nip04) |
| `nostr-provider.js` | Injected into web pages, provides `window.nostr` |
| `content-script.js` | Bridges provider ↔ background via postMessage |
| `popup.jsx`, `prompt.jsx`, `options.jsx` | React UI components |
| `extension/chrome/manifest.json` | Chrome Manifest V3 config |
| `extension/firefox/manifest.json` | Firefox Manifest V2 config |
The build script (`build.js`) auto-selects the correct manifest based on `prod`/`firefox` args.
## Code Style
- No semicolons
- Single quotes
- Biome (configured in `biome.json`)

View File

@@ -0,0 +1,692 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objects = {
/* Begin PBXBuildFile section */
31677A162B15715C00E466BD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31677A152B15715C00E466BD /* AppDelegate.swift */; };
31677A192B15715C00E466BD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 31677A172B15715C00E466BD /* Main.storyboard */; };
31677A2B2B15715C00E466BD /* Nostr Connect Extension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 31677A2A2B15715C00E466BD /* Nostr Connect Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
31677A322B15715C00E466BD /* Main.html in Resources */ = {isa = PBXBuildFile; fileRef = 316779F42B15715B00E466BD /* Main.html */; };
31677A342B15715C00E466BD /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 316779F62B15715B00E466BD /* Icon.png */; };
31677A362B15715C00E466BD /* Style.css in Resources */ = {isa = PBXBuildFile; fileRef = 316779F72B15715B00E466BD /* Style.css */; };
31677A382B15715C00E466BD /* Script.js in Resources */ = {isa = PBXBuildFile; fileRef = 316779F82B15715B00E466BD /* Script.js */; };
31677A3A2B15715C00E466BD /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 316779F92B15715B00E466BD /* ViewController.swift */; };
31677A3C2B15715C00E466BD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 316779FA2B15715C00E466BD /* Assets.xcassets */; };
31677A3E2B15715C00E466BD /* SafariWebExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 316779FC2B15715C00E466BD /* SafariWebExtensionHandler.swift */; };
31677A5D2B15715C00E466BD /* popup.html in Resources */ = {isa = PBXBuildFile; fileRef = 31677A502B15715C00E466BD /* popup.html */; };
31677A5E2B15715C00E466BD /* nostr-provider.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A512B15715C00E466BD /* nostr-provider.js */; };
31677A5F2B15715C00E466BD /* options.build.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A522B15715C00E466BD /* options.build.js */; };
31677A602B15715C00E466BD /* background.build.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A532B15715C00E466BD /* background.build.js */; };
31677A612B15715C00E466BD /* content-script.build.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A542B15715C00E466BD /* content-script.build.js */; };
31677A622B15715C00E466BD /* icons in Resources */ = {isa = PBXBuildFile; fileRef = 31677A552B15715C00E466BD /* icons */; };
31677A632B15715C00E466BD /* prompt.html in Resources */ = {isa = PBXBuildFile; fileRef = 31677A562B15715C00E466BD /* prompt.html */; };
31677A642B15715C00E466BD /* style.css in Resources */ = {isa = PBXBuildFile; fileRef = 31677A572B15715C00E466BD /* style.css */; };
31677A652B15715C00E466BD /* manifest.json in Resources */ = {isa = PBXBuildFile; fileRef = 31677A582B15715C00E466BD /* manifest.json */; };
31677A662B15715C00E466BD /* prompt.build.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A592B15715C00E466BD /* prompt.build.js */; };
31677A672B15715C00E466BD /* options.html in Resources */ = {isa = PBXBuildFile; fileRef = 31677A5A2B15715C00E466BD /* options.html */; };
31677A682B15715C00E466BD /* common.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A5B2B15715C00E466BD /* common.js */; };
31677A692B15715C00E466BD /* popup.build.js in Resources */ = {isa = PBXBuildFile; fileRef = 31677A5C2B15715C00E466BD /* popup.build.js */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
31677A2C2B15715C00E466BD /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 316779EE2B15715B00E466BD /* Project object */;
proxyType = 1;
remoteGlobalIDString = 31677A292B15715C00E466BD;
remoteInfo = "Nostr Connect Extension (macOS)";
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
31677A4B2B15715C00E466BD /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
31677A2B2B15715C00E466BD /* Nostr Connect Extension.appex in Embed Foundation Extensions */,
);
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
316779F52B15715B00E466BD /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = Base; path = ../Base.lproj/Main.html; sourceTree = "<group>"; };
316779F62B15715B00E466BD /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
316779F72B15715B00E466BD /* Style.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = Style.css; sourceTree = "<group>"; };
316779F82B15715B00E466BD /* Script.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Script.js; sourceTree = "<group>"; };
316779F92B15715B00E466BD /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
316779FA2B15715C00E466BD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
316779FC2B15715C00E466BD /* SafariWebExtensionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariWebExtensionHandler.swift; sourceTree = "<group>"; };
31677A042B15715C00E466BD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
31677A062B15715C00E466BD /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
31677A092B15715C00E466BD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
31677A0C2B15715C00E466BD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
31677A0E2B15715C00E466BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
31677A132B15715C00E466BD /* Nostr Connect.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Nostr Connect.app"; sourceTree = BUILT_PRODUCTS_DIR; };
31677A152B15715C00E466BD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
31677A182B15715C00E466BD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
31677A1A2B15715C00E466BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
31677A1B2B15715C00E466BD /* Nostr Connect.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Nostr Connect.entitlements"; sourceTree = "<group>"; };
31677A252B15715C00E466BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
31677A2A2B15715C00E466BD /* Nostr Connect Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Nostr Connect Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
31677A2F2B15715C00E466BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
31677A302B15715C00E466BD /* Nostr Connect.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Nostr Connect.entitlements"; sourceTree = "<group>"; };
31677A502B15715C00E466BD /* popup.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = popup.html; path = ../../extension/output/popup.html; sourceTree = "<group>"; };
31677A512B15715C00E466BD /* nostr-provider.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = "nostr-provider.js"; path = "../../extension/output/nostr-provider.js"; sourceTree = "<group>"; };
31677A522B15715C00E466BD /* options.build.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = options.build.js; path = ../../extension/output/options.build.js; sourceTree = "<group>"; };
31677A532B15715C00E466BD /* background.build.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = background.build.js; path = ../../extension/output/background.build.js; sourceTree = "<group>"; };
31677A542B15715C00E466BD /* content-script.build.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = "content-script.build.js"; path = "../../extension/output/content-script.build.js"; sourceTree = "<group>"; };
31677A552B15715C00E466BD /* icons */ = {isa = PBXFileReference; lastKnownFileType = folder; name = icons; path = ../../extension/output/icons; sourceTree = "<group>"; };
31677A562B15715C00E466BD /* prompt.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = prompt.html; path = ../../extension/output/prompt.html; sourceTree = "<group>"; };
31677A572B15715C00E466BD /* style.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; name = style.css; path = ../../extension/output/style.css; sourceTree = "<group>"; };
31677A582B15715C00E466BD /* manifest.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = manifest.json; path = ../../extension/output/manifest.json; sourceTree = "<group>"; };
31677A592B15715C00E466BD /* prompt.build.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = prompt.build.js; path = ../../extension/output/prompt.build.js; sourceTree = "<group>"; };
31677A5A2B15715C00E466BD /* options.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = options.html; path = ../../extension/output/options.html; sourceTree = "<group>"; };
31677A5B2B15715C00E466BD /* common.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = common.js; path = ../../extension/output/common.js; sourceTree = "<group>"; };
31677A5C2B15715C00E466BD /* popup.build.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = popup.build.js; path = ../../extension/output/popup.build.js; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
31677A102B15715C00E466BD /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
31677A272B15715C00E466BD /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
316779ED2B15715B00E466BD = {
isa = PBXGroup;
children = (
316779F22B15715B00E466BD /* Shared (App) */,
316779FB2B15715C00E466BD /* Shared (Extension) */,
31677A032B15715C00E466BD /* iOS (App) */,
31677A142B15715C00E466BD /* macOS (App) */,
31677A242B15715C00E466BD /* iOS (Extension) */,
31677A2E2B15715C00E466BD /* macOS (Extension) */,
31677A022B15715C00E466BD /* Products */,
);
sourceTree = "<group>";
};
316779F22B15715B00E466BD /* Shared (App) */ = {
isa = PBXGroup;
children = (
316779F92B15715B00E466BD /* ViewController.swift */,
316779FA2B15715C00E466BD /* Assets.xcassets */,
316779F32B15715B00E466BD /* Resources */,
);
path = "Shared (App)";
sourceTree = "<group>";
};
316779F32B15715B00E466BD /* Resources */ = {
isa = PBXGroup;
children = (
316779F42B15715B00E466BD /* Main.html */,
316779F62B15715B00E466BD /* Icon.png */,
316779F72B15715B00E466BD /* Style.css */,
316779F82B15715B00E466BD /* Script.js */,
);
path = Resources;
sourceTree = "<group>";
};
316779FB2B15715C00E466BD /* Shared (Extension) */ = {
isa = PBXGroup;
children = (
31677A4F2B15715C00E466BD /* Resources */,
316779FC2B15715C00E466BD /* SafariWebExtensionHandler.swift */,
);
path = "Shared (Extension)";
sourceTree = "<group>";
};
31677A022B15715C00E466BD /* Products */ = {
isa = PBXGroup;
children = (
31677A132B15715C00E466BD /* Nostr Connect.app */,
31677A2A2B15715C00E466BD /* Nostr Connect Extension.appex */,
);
name = Products;
sourceTree = "<group>";
};
31677A032B15715C00E466BD /* iOS (App) */ = {
isa = PBXGroup;
children = (
31677A042B15715C00E466BD /* AppDelegate.swift */,
31677A062B15715C00E466BD /* SceneDelegate.swift */,
31677A082B15715C00E466BD /* LaunchScreen.storyboard */,
31677A0B2B15715C00E466BD /* Main.storyboard */,
31677A0E2B15715C00E466BD /* Info.plist */,
);
path = "iOS (App)";
sourceTree = "<group>";
};
31677A142B15715C00E466BD /* macOS (App) */ = {
isa = PBXGroup;
children = (
31677A152B15715C00E466BD /* AppDelegate.swift */,
31677A172B15715C00E466BD /* Main.storyboard */,
31677A1A2B15715C00E466BD /* Info.plist */,
31677A1B2B15715C00E466BD /* Nostr Connect.entitlements */,
);
path = "macOS (App)";
sourceTree = "<group>";
};
31677A242B15715C00E466BD /* iOS (Extension) */ = {
isa = PBXGroup;
children = (
31677A252B15715C00E466BD /* Info.plist */,
);
path = "iOS (Extension)";
sourceTree = "<group>";
};
31677A2E2B15715C00E466BD /* macOS (Extension) */ = {
isa = PBXGroup;
children = (
31677A2F2B15715C00E466BD /* Info.plist */,
31677A302B15715C00E466BD /* Nostr Connect.entitlements */,
);
path = "macOS (Extension)";
sourceTree = "<group>";
};
31677A4F2B15715C00E466BD /* Resources */ = {
isa = PBXGroup;
children = (
31677A502B15715C00E466BD /* popup.html */,
31677A512B15715C00E466BD /* nostr-provider.js */,
31677A522B15715C00E466BD /* options.build.js */,
31677A532B15715C00E466BD /* background.build.js */,
31677A542B15715C00E466BD /* content-script.build.js */,
31677A552B15715C00E466BD /* icons */,
31677A562B15715C00E466BD /* prompt.html */,
31677A572B15715C00E466BD /* style.css */,
31677A582B15715C00E466BD /* manifest.json */,
31677A592B15715C00E466BD /* prompt.build.js */,
31677A5A2B15715C00E466BD /* options.html */,
31677A5B2B15715C00E466BD /* common.js */,
31677A5C2B15715C00E466BD /* popup.build.js */,
);
name = Resources;
path = "Shared (Extension)";
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
31677A122B15715C00E466BD /* Nostr Connect (macOS) */ = {
isa = PBXNativeTarget;
buildConfigurationList = 31677A4C2B15715C00E466BD /* Build configuration list for PBXNativeTarget "Nostr Connect (macOS)" */;
buildPhases = (
31677A0F2B15715C00E466BD /* Sources */,
31677A102B15715C00E466BD /* Frameworks */,
31677A112B15715C00E466BD /* Resources */,
31677A4B2B15715C00E466BD /* Embed Foundation Extensions */,
);
buildRules = (
);
dependencies = (
31677A2D2B15715C00E466BD /* PBXTargetDependency */,
);
name = "Nostr Connect (macOS)";
productName = "Nostr Connect (macOS)";
productReference = 31677A132B15715C00E466BD /* Nostr Connect.app */;
productType = "com.apple.product-type.application";
};
31677A292B15715C00E466BD /* Nostr Connect Extension (macOS) */ = {
isa = PBXNativeTarget;
buildConfigurationList = 31677A482B15715C00E466BD /* Build configuration list for PBXNativeTarget "Nostr Connect Extension (macOS)" */;
buildPhases = (
31677A262B15715C00E466BD /* Sources */,
31677A272B15715C00E466BD /* Frameworks */,
31677A282B15715C00E466BD /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = "Nostr Connect Extension (macOS)";
productName = "Nostr Connect Extension (macOS)";
productReference = 31677A2A2B15715C00E466BD /* Nostr Connect Extension.appex */;
productType = "com.apple.product-type.app-extension";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
316779EE2B15715B00E466BD /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
TargetAttributes = {
31677A122B15715C00E466BD = {
CreatedOnToolsVersion = 15.0;
};
31677A292B15715C00E466BD = {
CreatedOnToolsVersion = 15.0;
};
};
};
buildConfigurationList = 316779F12B15715B00E466BD /* Build configuration list for PBXProject "Nostr Connect" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 316779ED2B15715B00E466BD;
productRefGroup = 31677A022B15715C00E466BD /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
31677A122B15715C00E466BD /* Nostr Connect (macOS) */,
31677A292B15715C00E466BD /* Nostr Connect Extension (macOS) */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
31677A112B15715C00E466BD /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
31677A342B15715C00E466BD /* Icon.png in Resources */,
31677A362B15715C00E466BD /* Style.css in Resources */,
31677A192B15715C00E466BD /* Main.storyboard in Resources */,
31677A382B15715C00E466BD /* Script.js in Resources */,
31677A3C2B15715C00E466BD /* Assets.xcassets in Resources */,
31677A322B15715C00E466BD /* Main.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
31677A282B15715C00E466BD /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
31677A602B15715C00E466BD /* background.build.js in Resources */,
31677A642B15715C00E466BD /* style.css in Resources */,
31677A632B15715C00E466BD /* prompt.html in Resources */,
31677A5F2B15715C00E466BD /* options.build.js in Resources */,
31677A672B15715C00E466BD /* options.html in Resources */,
31677A662B15715C00E466BD /* prompt.build.js in Resources */,
31677A652B15715C00E466BD /* manifest.json in Resources */,
31677A5E2B15715C00E466BD /* nostr-provider.js in Resources */,
31677A622B15715C00E466BD /* icons in Resources */,
31677A692B15715C00E466BD /* popup.build.js in Resources */,
31677A682B15715C00E466BD /* common.js in Resources */,
31677A612B15715C00E466BD /* content-script.build.js in Resources */,
31677A5D2B15715C00E466BD /* popup.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
31677A0F2B15715C00E466BD /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
31677A3A2B15715C00E466BD /* ViewController.swift in Sources */,
31677A162B15715C00E466BD /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
31677A262B15715C00E466BD /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
31677A3E2B15715C00E466BD /* SafariWebExtensionHandler.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
31677A2D2B15715C00E466BD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 31677A292B15715C00E466BD /* Nostr Connect Extension (macOS) */;
targetProxy = 31677A2C2B15715C00E466BD /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
316779F42B15715B00E466BD /* Main.html */ = {
isa = PBXVariantGroup;
children = (
316779F52B15715B00E466BD /* Base */,
);
name = Main.html;
sourceTree = "<group>";
};
31677A082B15715C00E466BD /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
31677A092B15715C00E466BD /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
31677A0B2B15715C00E466BD /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
31677A0C2B15715C00E466BD /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
31677A172B15715C00E466BD /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
31677A182B15715C00E466BD /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
31677A3F2B15715C00E466BD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
31677A402B15715C00E466BD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SWIFT_COMPILATION_MODE = wholemodule;
};
name = Release;
};
31677A492B15715C00E466BD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = "macOS (Extension)/Nostr Connect.entitlements";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = V757GRTBDF;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "macOS (Extension)/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Nostr Connect Extension";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
);
PRODUCT_BUNDLE_IDENTIFIER = "com.github.Nostr-Connect.Extension";
PRODUCT_NAME = "Nostr Connect Extension";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
31677A4A2B15715C00E466BD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = "macOS (Extension)/Nostr Connect.entitlements";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = V757GRTBDF;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "macOS (Extension)/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Nostr Connect Extension";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
);
PRODUCT_BUNDLE_IDENTIFIER = "com.github.Nostr-Connect.Extension";
PRODUCT_NAME = "Nostr Connect Extension";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
31677A4D2B15715C00E466BD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Nostr Connect.entitlements";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = V757GRTBDF;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "macOS (App)/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Nostr Connect";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
"-framework",
WebKit,
);
PRODUCT_BUNDLE_IDENTIFIER = "com.github.Nostr-Connect";
PRODUCT_NAME = "Nostr Connect";
SDKROOT = macosx;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
31677A4E2B15715C00E466BD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Nostr Connect.entitlements";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = V757GRTBDF;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "macOS (App)/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Nostr Connect";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
"-framework",
WebKit,
);
PRODUCT_BUNDLE_IDENTIFIER = "com.github.Nostr-Connect";
PRODUCT_NAME = "Nostr Connect";
SDKROOT = macosx;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
316779F12B15715B00E466BD /* Build configuration list for PBXProject "Nostr Connect" */ = {
isa = XCConfigurationList;
buildConfigurations = (
31677A3F2B15715C00E466BD /* Debug */,
31677A402B15715C00E466BD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
31677A482B15715C00E466BD /* Build configuration list for PBXNativeTarget "Nostr Connect Extension (macOS)" */ = {
isa = XCConfigurationList;
buildConfigurations = (
31677A492B15715C00E466BD /* Debug */,
31677A4A2B15715C00E466BD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
31677A4C2B15715C00E466BD /* Build configuration list for PBXNativeTarget "Nostr Connect (macOS)" */ = {
isa = XCConfigurationList;
buildConfigurations = (
31677A4D2B15715C00E466BD /* Debug */,
31677A4E2B15715C00E466BD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 316779EE2B15715B00E466BD /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Nostr Connect (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>Nostr Connect (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,74 @@
{
"images" : [
{
"size" : "1024x1024",
"idiom" : "universal",
"filename" : "universal-icon-1024@1x.png",
"platform" : "ios"
},
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "mac-icon-16@1x.png",
"scale" : "1x"
},
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "mac-icon-16@2x.png",
"scale" : "2x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "mac-icon-32@1x.png",
"scale" : "1x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "mac-icon-32@2x.png",
"scale" : "2x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "mac-icon-128@1x.png",
"scale" : "1x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "mac-icon-128@2x.png",
"scale" : "2x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "mac-icon-256@1x.png",
"scale" : "1x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "mac-icon-256@2x.png",
"scale" : "2x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "mac-icon-512@1x.png",
"scale" : "1x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "mac-icon-512@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "icon128.png"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="../Style.css">
<script src="../Script.js" defer></script>
</head>
<body>
<img src="../Icon.png" width="128" height="128" alt="Nostr Connect Icon">
<p class="platform-ios">You can turn on Nostr Connects Safari extension in Settings.</p>
<p class="platform-mac state-unknown">You can turn on Nostr Connects extension in Safari Extensions preferences.</p>
<p class="platform-mac state-on">Nostr Connects extension is currently on. You can turn it off in Safari Extensions preferences.</p>
<p class="platform-mac state-off">Nostr Connects extension is currently off. You can turn it on in Safari Extensions preferences.</p>
<button class="platform-mac open-preferences">Quit and Open Safari Extensions Preferences…</button>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,24 @@
function show(platform, enabled, useSettingsInsteadOfPreferences) {
document.body.classList.add(`platform-${platform}`);
if (useSettingsInsteadOfPreferences) {
document.getElementsByClassName('platform-mac state-on')[0].innerText = "Nostr Connects extension is currently on. You can turn it off in the Extensions section of Safari Settings.";
document.getElementsByClassName('platform-mac state-off')[0].innerText = "Nostr Connects extension is currently off. You can turn it on in the Extensions section of Safari Settings.";
document.getElementsByClassName('platform-mac state-unknown')[0].innerText = "You can turn on Nostr Connects extension in the Extensions section of Safari Settings.";
document.getElementsByClassName('platform-mac open-preferences')[0].innerText = "Quit and Open Safari Settings…";
}
if (typeof enabled === "boolean") {
document.body.classList.toggle(`state-on`, enabled);
document.body.classList.toggle(`state-off`, !enabled);
} else {
document.body.classList.remove(`state-on`);
document.body.classList.remove(`state-off`);
}
}
function openPreferences() {
webkit.messageHandlers.controller.postMessage("open-preferences");
}
document.querySelector("button.open-preferences").addEventListener("click", openPreferences);

View File

@@ -0,0 +1,61 @@
* {
-webkit-user-select: none;
-webkit-user-drag: none;
cursor: default;
}
:root {
color-scheme: light dark;
--spacing: 20px;
}
html {
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: var(--spacing);
margin: 0 calc(var(--spacing) * 2);
height: 100%;
font: -apple-system-short-body;
text-align: center;
}
body:not(.platform-mac, .platform-ios) :is(.platform-mac, .platform-ios) {
display: none;
}
body.platform-ios .platform-mac {
display: none;
}
body.platform-mac .platform-ios {
display: none;
}
body.platform-ios .platform-mac {
display: none;
}
body:not(.state-on, .state-off) :is(.state-on, .state-off) {
display: none;
}
body.state-on :is(.state-off, .state-unknown) {
display: none;
}
body.state-off :is(.state-on, .state-unknown) {
display: none;
}
button {
font-size: 1em;
}

View File

@@ -0,0 +1,81 @@
//
// ViewController.swift
// Shared (App)
//
// Created by Phong on 28/11/2023.
//
import WebKit
#if os(iOS)
import UIKit
typealias PlatformViewController = UIViewController
#elseif os(macOS)
import Cocoa
import SafariServices
typealias PlatformViewController = NSViewController
#endif
let extensionBundleIdentifier = "com.github.Nostr-Connect.Extension"
class ViewController: PlatformViewController, WKNavigationDelegate, WKScriptMessageHandler {
@IBOutlet var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
self.webView.navigationDelegate = self
#if os(iOS)
self.webView.scrollView.isScrollEnabled = false
#endif
self.webView.configuration.userContentController.add(self, name: "controller")
self.webView.loadFileURL(Bundle.main.url(forResource: "Main", withExtension: "html")!, allowingReadAccessTo: Bundle.main.resourceURL!)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
#if os(iOS)
webView.evaluateJavaScript("show('ios')")
#elseif os(macOS)
webView.evaluateJavaScript("show('mac')")
SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { (state, error) in
guard let state = state, error == nil else {
// Insert code to inform the user that something went wrong.
return
}
DispatchQueue.main.async {
if #available(macOS 13, *) {
webView.evaluateJavaScript("show('mac', \(state.isEnabled), true)")
} else {
webView.evaluateJavaScript("show('mac', \(state.isEnabled), false)")
}
}
}
#endif
}
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
#if os(macOS)
if (message.body as! String != "open-preferences") {
return
}
SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { error in
guard error == nil else {
// Insert code to inform the user that something went wrong.
return
}
DispatchQueue.main.async {
NSApp.terminate(self)
}
}
#endif
}
}

View File

@@ -0,0 +1,38 @@
//
// SafariWebExtensionHandler.swift
// Shared (Extension)
//
// Created by Phong on 28/11/2023.
//
import SafariServices
import os.log
class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
func beginRequest(with context: NSExtensionContext) {
let request = context.inputItems.first as? NSExtensionItem
let profile: UUID?
if #available(iOS 17.0, macOS 14.0, *) {
profile = request?.userInfo?[SFExtensionProfileKey] as? UUID
} else {
profile = request?.userInfo?["profile"] as? UUID
}
let message: Any?
if #available(iOS 17.0, macOS 14.0, *) {
message = request?.userInfo?[SFExtensionMessageKey]
} else {
message = request?.userInfo?["message"]
}
os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@ (profile: %@)", String(describing: message), profile?.uuidString ?? "none")
let response = NSExtensionItem()
response.userInfo = [ SFExtensionMessageKey: [ "echo": message ] ]
context.completeRequest(returningItems: [ response ], completionHandler: nil)
}
}

View File

@@ -0,0 +1,24 @@
//
// AppDelegate.swift
// iOS (App)
//
// Created by Phong on 28/11/2023.
//
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19085" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19082"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6HG-Um-bch">
<rect key="frame" x="142" y="385" width="128" height="128"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<imageReference key="image" image="LargeIcon"/>
</imageView>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<image name="LargeIcon" width="128" height="128"/>
</resources>
</document>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<wkWebView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RDB-ib-igF">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
</wkWebView>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="webView" destination="RDB-ib-igF" id="avx-RC-qRB"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SFSafariWebExtensionConverterVersion</key>
<string>15.0</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,18 @@
//
// SceneDelegate.swift
// iOS (App)
//
// Created by Phong on 28/11/2023.
//
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.web-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,21 @@
//
// AppDelegate.swift
// macOS (App)
//
// Created by Phong on 28/11/2023.
//
import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
// Override point for customization after application launch.
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
}

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19085" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19085"/>
<plugIn identifier="com.apple.WebKit2IBPlugin" version="19085"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Application-->
<scene sceneID="JPo-4y-FX3">
<objects>
<application id="hnw-xV-0zn" sceneMemberID="viewController">
<menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
<menuItem title="Nostr Connect" id="1Xt-HY-uBw">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Nostr Connect" systemMenu="apple" id="uQy-DD-JDr">
<items>
<menuItem title="About Nostr Connect" id="5kV-Vb-QxS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Hide Nostr Connect" keyEquivalent="h" id="Olw-nP-bQN">
<connections>
<action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/>
</connections>
</menuItem>
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/>
</connections>
</menuItem>
<menuItem title="Show All" id="Kd2-mp-pUS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
<menuItem title="Quit Nostr Connect" keyEquivalent="q" id="4sb-4s-VLi">
<connections>
<action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Help" id="wpr-3q-Mcd">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
<items>
<menuItem title="Nostr Connect Help" keyEquivalent="?" id="FKE-Sm-Kum">
<connections>
<action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items>
</menu>
<connections>
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="76" y="-134"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController showSeguePresentationStyle="single" id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="Nostr Connect" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowCollectionBehavior key="collectionBehavior" fullScreenNone="YES"/>
<rect key="contentRect" x="196" y="240" width="425" height="325"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<connections>
<outlet property="delegate" destination="B8D-0N-5wS" id="98r-iN-zZc"/>
</connections>
</window>
<connections>
<segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
</connections>
</windowController>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="250"/>
</scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="425" height="325"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<wkWebView wantsLayer="YES" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eOr-cG-IQY">
<rect key="frame" x="0.0" y="0.0" width="425" height="325"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
</wkWebView>
</subviews>
</view>
<connections>
<outlet property="webView" destination="eOr-cG-IQY" id="GFe-mU-dBY"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="655"/>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SFSafariWebExtensionConverterVersion</key>
<string>15.0</string>
</dict>
</plist>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.web-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>

View File

@@ -1,13 +0,0 @@
module.exports = api => {
return {
presets: [
[
'@quasar/babel-preset-app',
api.caller(caller => caller && caller.target === 'node')
? { targets: { node: 'current' } }
: {}
]
]
}
}

63
biome.json Normal file
View File

@@ -0,0 +1,63 @@
{
"$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true,
"ignore": [
"extension/output/**",
"extension/**/*.test.js",
"extension/test-utils.js",
"extension/style.css"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedVariables": "warn"
},
"style": {
"noNonNullAssertion": "off"
},
"a11y": {
"recommended": true
},
"complexity": {
"recommended": true
},
"suspicious": {
"recommended": true
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded",
"trailingCommas": "none",
"arrowParentheses": "always"
}
}
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded",
"trailingCommas": "none",
"arrowParentheses": "always"
}
}
}

View File

@@ -1,8 +1,9 @@
#!/usr/bin/env node #!/usr/bin/env node
const {copy} = require('esbuild-plugin-copy')
const esbuild = require('esbuild') const esbuild = require('esbuild')
const prod = process.argv.indexOf('prod') !== -1 const isProd = process.argv.indexOf('prod') !== -1
const isFirefox = process.argv.indexOf('firefox') !== -1
esbuild esbuild
.build({ .build({
@@ -14,12 +15,42 @@ esbuild
'background.build': './extension/background.js', 'background.build': './extension/background.js',
'content-script.build': './extension/content-script.js' 'content-script.build': './extension/content-script.js'
}, },
outdir: './extension/build', outdir: './extension/output',
sourcemap: prod ? false : 'inline', sourcemap: isProd ? false : 'inline',
define: { define: {
window: 'self', window: 'self',
global: 'self' global: 'self'
}, },
watch: !prod plugins: [
copy({
assets: [
{
from: [
isFirefox
? './extension/firefox/manifest.json'
: './extension/chrome/manifest.json'
],
to: ['./']
},
{
from: ['./extension/*.html'],
to: ['./']
},
{
from: ['./extension/common.js'],
to: ['./']
},
{
from: ['./extension/nostr-provider.js'],
to: ['./']
},
{
from: ['./extension/icons/*'],
to: ['./icons']
}
]
})
]
}) })
.then(() => console.log('build success.')) .then(() => console.log('Build success.'))
.catch(err => console.error('Build error.', err))

1790
bun.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,210 +1,273 @@
import browser from 'webextension-polyfill' import browser from "webextension-polyfill";
import { import {
validateEvent, validateEvent,
getSignature, finalizeEvent,
getEventHash, getEventHash,
getPublicKey, getPublicKey,
nip19 nip19,
} from 'nostr-tools' utils,
import {nip04} from 'nostr-tools' } from "nostr-tools";
import {Mutex} from 'async-mutex' import { nip04 } from "nostr-tools";
import * as nip44 from "nostr-tools/nip44";
import { Mutex } from "async-mutex";
import { LRUCache } from "./utils";
const { hexToBytes } = utils;
import { import {
NO_PERMISSIONS_REQUIRED, NO_PERMISSIONS_REQUIRED,
getPermissionStatus, getPermissionStatus,
updatePermission, updatePermission,
showNotification showNotification,
} from './common' getPosition,
} from "./common";
const {encrypt, decrypt} = nip04 const { encrypt, decrypt } = nip04;
let openPrompt = null let openPrompt = null;
let promptMutex = new Mutex() const promptMutex = new Mutex();
let releasePromptMutex = () => {} let releasePromptMutex = () => {};
const secretsCache = new LRUCache(100);
const previousSk = null;
function getSharedSecret(sk, peer) {
if (previousSk !== sk) {
secretsCache.clear();
}
let key = secretsCache.get(peer);
if (!key) {
key = nip44.v2.utils.getConversationKey(sk, peer);
secretsCache.set(peer, key);
}
return key;
}
const width = 440;
const height = 420;
browser.runtime.onInstalled.addListener((_, __, reason) => { browser.runtime.onInstalled.addListener((_, __, reason) => {
if (reason === 'install') browser.runtime.openOptionsPage() if (reason === "install") browser.runtime.openOptionsPage();
}) });
browser.runtime.onMessage.addListener(async (req, sender) => { browser.runtime.onMessage.addListener(async (req, sender) => {
let {prompt} = req const { prompt } = req;
if (prompt) { if (prompt) {
handlePromptMessage(req, sender) handlePromptMessage(req, sender);
} else { } else {
return handleContentScriptMessage(req) return handleContentScriptMessage(req);
} }
}) });
browser.runtime.onMessageExternal.addListener( browser.runtime.onMessageExternal.addListener(
async ({type, params}, sender) => { async ({ type, params }, sender) => {
let extensionId = new URL(sender.url).host const extensionId = new URL(sender.url).host;
return handleContentScriptMessage({type, params, host: extensionId}) return handleContentScriptMessage({ type, params, host: extensionId });
} }
) );
browser.windows.onRemoved.addListener(windowId => { browser.windows.onRemoved.addListener((_windowId) => {
if (openPrompt) { if (openPrompt) {
// calling this with a simple "no" response will not store anything, so it's fine // calling this with a simple "no" response will not store anything, so it's fine
// it will just return a failure // it will just return a failure
handlePromptMessage({accept: false}, null) handlePromptMessage({ accept: false }, null);
} }
}) });
async function handleContentScriptMessage({type, params, host}) { async function handleContentScriptMessage({ type, params, host }) {
if (NO_PERMISSIONS_REQUIRED[type]) { if (NO_PERMISSIONS_REQUIRED[type]) {
// authorized, and we won't do anything with private key here, so do a separate handler
switch (type) { switch (type) {
case 'replaceURL': { case "peekPublicKey": {
let {protocol_handler: ph} = await browser.storage.local.get([ const allowed = await getPermissionStatus(host, "getPublicKey");
'protocol_handler' if (allowed === true) return performOperation("getPublicKey", params);
]) return "";
if (!ph) return false }
case "replaceURL": {
const { protocol_handler: ph } = await browser.storage.local.get([
"protocol_handler",
]);
if (!ph) return false;
let {url} = params const { url } = params;
let raw = url.split('nostr:')[1] const raw = url.split("nostr:")[1];
let {type, data} = nip19.decode(raw) const { type, data } = nip19.decode(raw);
let replacements = { const replacements = {
raw, raw,
hrp: type, hrp: type,
hex: hex:
type === 'npub' || type === 'note' type === "npub" || type === "note"
? data ? data
: type === 'nprofile' : type === "nprofile"
? data.pubkey ? data.pubkey
: type === 'nevent' : type === "nevent"
? data.id ? data.id
: null, : null,
p_or_e: {npub: 'p', note: 'e', nprofile: 'p', nevent: 'e'}[type], p_or_e: { npub: "p", note: "e", nprofile: "p", nevent: "e" }[type],
u_or_n: {npub: 'u', note: 'n', nprofile: 'u', nevent: 'n'}[type], u_or_n: { npub: "u", note: "n", nprofile: "u", nevent: "n" }[type],
relay0: type === 'nprofile' ? data.relays[0] : null, relay0: type === "nprofile" ? data.relays[0] : null,
relay1: type === 'nprofile' ? data.relays[1] : null, relay1: type === "nprofile" ? data.relays[1] : null,
relay2: type === 'nprofile' ? data.relays[2] : null relay2: type === "nprofile" ? data.relays[2] : null,
} };
let result = ph let result = ph;
Object.entries(replacements).forEach(([pattern, value]) => { Object.entries(replacements).forEach(([pattern, value]) => {
result = result.replace(new RegExp(`{ *${pattern} *}`, 'g'), value) result = result.replace(new RegExp(`{ *${pattern} *}`, "g"), value);
}) });
return result return result;
} }
} }
return return;
} else { } else {
// acquire mutex here before reading policies // acquire mutex here before reading policies
releasePromptMutex = await promptMutex.acquire() releasePromptMutex = await promptMutex.acquire();
let allowed = await getPermissionStatus( const allowed = await getPermissionStatus(
host, host,
type, type,
type === 'signEvent' ? params.event : undefined type === "signEvent" ? params.event : undefined
) );
if (allowed === true) { if (allowed === true) {
// authorized, proceed // authorized, proceed
releasePromptMutex() releasePromptMutex();
showNotification(host, allowed, type, params) showNotification(host, allowed, type, params);
} else if (allowed === false) { } else if (allowed === false) {
// denied, just refuse immediately // denied, just refuse immediately
releasePromptMutex() releasePromptMutex();
showNotification(host, allowed, type, params) showNotification(host, allowed, type, params);
return { return {
error: 'denied' error: "denied",
} };
} else { } else {
// ask for authorization // ask for authorization
try { try {
let id = Math.random().toString().slice(4) const id = Math.random().toString().slice(4);
let qs = new URLSearchParams({ const qs = new URLSearchParams({
host, host,
id, id,
params: JSON.stringify(params), params: JSON.stringify(params),
type type,
}) });
// prompt will be resolved with true or false // prompt will be resolved with true or false
let accept = await new Promise((resolve, reject) => { const accept = await new Promise((resolve, reject) => {
openPrompt = {resolve, reject} openPrompt = { resolve, reject };
const url = `${browser.runtime.getURL(
"prompt.html"
)}?${qs.toString()}`;
browser.windows.create({ // center prompt
url: `${browser.runtime.getURL('prompt.html')}?${qs.toString()}`, const { top, left } = getPosition(width, height);
type: 'popup',
width: 600, if (browser.windows) {
height: 600 browser.windows.create({
}) url,
}) type: "popup",
width: width,
height: height,
top: top,
left: left,
});
} else {
browser.tabs.create({
url,
active: true,
});
}
});
// denied, stop here // denied, stop here
if (!accept) return {error: 'denied'} if (!accept) return { error: { message: "denied" } };
} catch (err) { } catch (err) {
// errored, stop here // errored, stop here
releasePromptMutex() releasePromptMutex();
return { return {
error: `error: ${err}` error: { message: err.message, stack: err.stack },
} };
} }
} }
} }
// if we're here this means it was accepted // if we're here this means it was accepted
let results = await browser.storage.local.get('private_key') const results = await browser.storage.local.get("private_key");
if (!results || !results.private_key) { if (!results?.private_key) {
return {error: 'no private key found'} return { error: "no private key found" };
} }
let sk = results.private_key const sk = results.private_key;
try { try {
switch (type) { switch (type) {
case 'getPublicKey': { case "getPublicKey": {
return getPublicKey(sk) return getPublicKey(hexToBytes(sk));
} }
case 'getRelays': { case "getRelays": {
let results = await browser.storage.local.get('relays') const results = await browser.storage.local.get("relays");
return results.relays || {} return results.relays || {};
} }
case 'signEvent': { case "signEvent": {
let {event} = params const { event } = params;
if (!event.pubkey) event.pubkey = getPublicKey(sk) if (!event.pubkey) event.pubkey = getPublicKey(hexToBytes(sk));
if (!event.id) event.id = getEventHash(event) if (!event.id) event.id = getEventHash(event);
if (!validateEvent(event)) return {error: {message: 'invalid event'}} if (!validateEvent(event))
return { error: { message: "invalid event" } };
event.sig = await getSignature(event, sk) const signedEvent = finalizeEvent(event, hexToBytes(sk));
return event return signedEvent;
} }
case 'nip04.encrypt': { case "nip04.encrypt": {
let {peer, plaintext} = params const { peer, plaintext } = params;
return encrypt(sk, peer, plaintext) return encrypt(sk, peer, plaintext);
} }
case 'nip04.decrypt': { case "nip04.decrypt": {
let {peer, ciphertext} = params const { peer, ciphertext } = params;
return decrypt(sk, peer, ciphertext) return decrypt(sk, peer, ciphertext);
}
case "nip44.encrypt": {
const { peer, plaintext } = params;
const key = getSharedSecret(sk, peer);
return nip44.v2.encrypt(plaintext, key);
}
case "nip44.decrypt": {
const { peer, ciphertext } = params;
const key = getSharedSecret(sk, peer);
return nip44.v2.decrypt(ciphertext, key);
} }
} }
} catch (error) { } catch (error) {
return {error: {message: error.message, stack: error.stack}} return { error: { message: error.message, stack: error.stack } };
} }
} }
async function handlePromptMessage({host, type, accept, conditions}, sender) { async function handlePromptMessage({ host, type, accept, conditions }, sender) {
// return response // return response
openPrompt?.resolve?.(accept) openPrompt?.resolve?.(accept);
// update policies // update policies
if (conditions) { if (conditions) {
await updatePermission(host, type, accept, conditions) await updatePermission(host, type, accept, conditions);
} }
// cleanup this // cleanup this
openPrompt = null openPrompt = null;
// release mutex here after updating policies // release mutex here after updating policies
releasePromptMutex() releasePromptMutex();
// close prompt // close prompt
if (sender) { if (sender) {
browser.windows.remove(sender.tab.windowId) if (browser.windows) {
browser.windows.remove(sender.tab.windowId);
} else {
// Android Firefox
browser.tabs.remove(sender.tab.id);
}
} }
} }

View File

@@ -0,0 +1,204 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { generateSecretKey, getPublicKey } from 'nostr-tools'
import { utils } from 'nostr-tools'
const { bytesToHex, hexToBytes } = utils
describe('background.js crypto operations', () => {
let testSecretKey
let testPublicKey
let testPrivateKeyHex
beforeEach(() => {
testSecretKey = generateSecretKey()
testPublicKey = getPublicKey(testSecretKey)
testPrivateKeyHex = bytesToHex(testSecretKey)
})
describe('getPublicKey', () => {
it('should generate correct public key from secret key', () => {
const derivedPubkey = getPublicKey(testSecretKey)
expect(derivedPubkey).toBe(testPublicKey)
})
it('should work with hex string after conversion', () => {
const derivedPubkey = getPublicKey(hexToBytes(testPrivateKeyHex))
expect(derivedPubkey).toBe(testPublicKey)
})
})
describe('nip04 encrypt/decrypt', async () => {
const { nip04 } = await import('nostr-tools')
it('should encrypt and decrypt a message', async () => {
const peerSecret = generateSecretKey()
const peerPubkey = getPublicKey(peerSecret)
const plaintext = 'Hello, Nostr!'
const ciphertext = nip04.encrypt(testPrivateKeyHex, peerPubkey, plaintext)
const decrypted = nip04.decrypt(testPrivateKeyHex, peerPubkey, ciphertext)
expect(decrypted).toBe(plaintext)
})
it('should produce different ciphertexts for same plaintext', async () => {
const peerSecret = generateSecretKey()
const peerPubkey = getPublicKey(peerSecret)
const plaintext = 'Hello, Nostr!'
const ciphertext1 = nip04.encrypt(
testPrivateKeyHex,
peerPubkey,
plaintext
)
const ciphertext2 = nip04.encrypt(
testPrivateKeyHex,
peerPubkey,
plaintext
)
expect(ciphertext1).not.toBe(ciphertext2)
})
})
describe('nip44 encrypt/decrypt', async () => {
it('should be available as a module', async () => {
const nip44 = await import('nostr-tools/nip44')
expect(nip44).toBeDefined()
expect(nip44.v2).toBeDefined()
expect(typeof nip44.v2.encrypt).toBe('function')
expect(typeof nip44.v2.decrypt).toBe('function')
})
// Note: nip44.v2.utils.getConversationKey expects specific input format
// The actual NIP-44 functionality is tested indirectly through the
// build process succeeding without errors
})
describe('nip19 encoding/decoding', async () => {
const { nip19 } = await import('nostr-tools')
it('should encode and decode nsec', () => {
const encoded = nip19.nsecEncode(testSecretKey)
const decoded = nip19.decode(encoded)
expect(decoded.type).toBe('nsec')
expect(bytesToHex(decoded.data)).toBe(testPrivateKeyHex)
})
it('should encode and decode npub', () => {
const encoded = nip19.npubEncode(testPublicKey)
const decoded = nip19.decode(encoded)
expect(decoded.type).toBe('npub')
expect(decoded.data).toBe(testPublicKey)
})
})
describe('event signing', async () => {
const { finalizeEvent, validateEvent, getEventHash } = await import(
'nostr-tools'
)
it('should sign and validate an event', () => {
const unsignedEvent = {
kind: 1,
content: 'Test content',
tags: [],
created_at: Math.floor(Date.now() / 1000),
pubkey: testPublicKey
}
const signedEvent = finalizeEvent(unsignedEvent, testSecretKey)
expect(signedEvent.sig).toBeDefined()
expect(signedEvent.id).toBe(getEventHash(signedEvent))
expect(validateEvent(signedEvent)).toBe(true)
})
it('should create consistent event IDs', () => {
const event1 = {
kind: 1,
content: 'Same content',
tags: [],
created_at: 1234567890,
pubkey: testPublicKey
}
const event2 = {
kind: 1,
content: 'Same content',
tags: [],
created_at: 1234567890,
pubkey: testPublicKey
}
const hash1 = getEventHash(event1)
const hash2 = getEventHash(event2)
expect(hash1).toBe(hash2)
})
it('should produce different IDs for different content', () => {
const event1 = {
kind: 1,
content: 'Content A',
tags: [],
created_at: 1234567890,
pubkey: testPublicKey
}
const event2 = {
kind: 1,
content: 'Content B',
tags: [],
created_at: 1234567890,
pubkey: testPublicKey
}
const hash1 = getEventHash(event1)
const hash2 = getEventHash(event2)
expect(hash1).not.toBe(hash2)
})
})
describe('replaceURL parsing', () => {
it('should encode and decode nostr links correctly', async () => {
const { nip19 } = await import('nostr-tools')
const npubEncoded = nip19.npubEncode(testPublicKey)
const decodedNpub = nip19.decode(npubEncoded)
expect(decodedNpub.type).toBe('npub')
expect(decodedNpub.data).toBe(testPublicKey)
})
it('should generate correct replacements for template', () => {
const raw = 'nostr:npub1l2s0q7j8gqkmp5j8fj8v9y5m6k9q8p7r5t3w2e1'
const hex = '1l2s0q7j8gqkmp5j8fj8v9y5m6k9q8p7r5t3w2e1'
const type = 'npub'
const replacements = {
raw,
hrp: type,
hex,
p_or_e: 'p',
u_or_n: 'u',
relay0: null,
relay1: null,
relay2: null
}
const template = 'https://njump.me/{raw}'
let result = template
Object.entries(replacements).forEach(([pattern, value]) => {
result = result.replace(new RegExp(`{ *${pattern} *}`, 'g'), value)
})
expect(result).toBe(
'https://njump.me/nostr:npub1l2s0q7j8gqkmp5j8fj8v9y5m6k9q8p7r5t3w2e1'
)
})
})
})

View File

@@ -1,7 +1,7 @@
{ {
"name": "Nostr Connect", "name": "Nostr Connect",
"description": "Nostr Signer Extension", "description": "Nostr Signer Extension",
"version": "0.1.0", "version": "0.1.2",
"homepage_url": "https://github.com/reyamir/nostr-connect", "homepage_url": "https://github.com/reyamir/nostr-connect",
"manifest_version": 3, "manifest_version": 3,
"icons": { "icons": {
@@ -12,7 +12,7 @@
}, },
"options_page": "options.html", "options_page": "options.html",
"background": { "background": {
"service_worker": "/build/background.build.js" "service_worker": "background.build.js"
}, },
"action": { "action": {
"default_title": "Nostr Connect", "default_title": "Nostr Connect",
@@ -21,7 +21,7 @@
"content_scripts": [ "content_scripts": [
{ {
"matches": ["<all_urls>"], "matches": ["<all_urls>"],
"js": ["/build/content-script.build.js"], "js": ["content-script.build.js"],
"all_frames": true "all_frames": true
} }
], ],

View File

@@ -1,116 +1,144 @@
import browser from 'webextension-polyfill' import browser from "webextension-polyfill";
export const NO_PERMISSIONS_REQUIRED = { export const NO_PERMISSIONS_REQUIRED = {
replaceURL: true replaceURL: true,
} peekPublicKey: true,
};
export const PERMISSION_NAMES = Object.fromEntries([ export const PERMISSION_NAMES = Object.fromEntries([
['getPublicKey', 'read your public key'], ["getPublicKey", "read your public key"],
['getRelays', 'read your list of preferred relays'], ["signEvent", "sign events using your private key"],
['signEvent', 'sign events using your private key'], ["nip04.encrypt", "encrypt messages to peers"],
['nip04.encrypt', 'encrypt messages to peers'], ["nip04.decrypt", "decrypt messages from peers"],
['nip04.decrypt', 'decrypt messages from peers'] ["nip44.encrypt", "encrypt messages to peers"],
]) ["nip44.decrypt", "decrypt messages from peers"],
]);
function matchConditions(conditions, event) { function matchConditions(conditions, event) {
if (conditions?.kinds) { if (conditions?.kinds) {
if (event.kind in conditions.kinds) return true if (event.kind in conditions.kinds) return true;
else return false else return false;
} }
return true return true;
} }
export async function getPermissionStatus(host, type, event) { export async function getPermissionStatus(host, type, event) {
let {policies} = await browser.storage.local.get('policies') const { policies } = await browser.storage.local.get("policies");
let answers = [true, false] const answers = [true, false];
for (let i = 0; i < answers.length; i++) { for (let i = 0; i < answers.length; i++) {
let accept = answers[i] const accept = answers[i];
let {conditions} = policies?.[host]?.[accept]?.[type] || {} const { conditions } = policies?.[host]?.[accept]?.[type] || {};
if (conditions) { if (conditions) {
if (type === 'signEvent') { if (type === "signEvent") {
if (matchConditions(conditions, event)) { if (matchConditions(conditions, event)) {
return accept // may be true or false return accept; // may be true or false
} else { } else {
// if this doesn't match we just continue so it will either match for the opposite answer (reject)
// or it will end up returning undefined at the end
continue
} }
} else { } else {
return accept // may be true or false return accept; // may be true or false
} }
} }
} }
return undefined return undefined;
} }
export async function updatePermission(host, type, accept, conditions) { export async function updatePermission(host, type, accept, conditions) {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
// if the new conditions is "match everything", override the previous // if the new conditions is "match everything", override the previous
if (Object.keys(conditions).length === 0) { if (Object.keys(conditions).length === 0) {
conditions = {} conditions = {};
} else { } else {
// if we already had a policy for this, merge the conditions // if we already had a policy for this, merge the conditions
let existingConditions = policies[host]?.[accept]?.[type]?.conditions const existingConditions = policies[host]?.[accept]?.[type]?.conditions;
if (existingConditions) { if (existingConditions) {
if (existingConditions.kinds && conditions.kinds) { if (existingConditions.kinds && conditions.kinds) {
Object.keys(existingConditions.kinds).forEach(kind => { Object.keys(existingConditions.kinds).forEach((kind) => {
conditions.kinds[kind] = true conditions.kinds[kind] = true;
}) });
} }
} }
} }
// if we have a reverse policy (accept / reject) that is exactly equal to this, remove it // if we have a reverse policy (accept / reject) that is exactly equal to this, remove it
let other = !accept const other = !accept;
let reverse = policies?.[host]?.[other]?.[type] const reverse = policies?.[host]?.[other]?.[type];
if ( if (
reverse && reverse &&
JSON.stringify(reverse.conditions) === JSON.stringify(conditions) JSON.stringify(reverse.conditions) === JSON.stringify(conditions)
) { ) {
delete policies[host][other][type] delete policies[host][other][type];
} }
// insert our new policy // insert our new policy
policies[host] = policies[host] || {} policies[host] = policies[host] || {};
policies[host][accept] = policies[host][accept] || {} policies[host][accept] = policies[host][accept] || {};
policies[host][accept][type] = { policies[host][accept][type] = {
conditions, // filter that must match the event (in case of signEvent) conditions, // filter that must match the event (in case of signEvent)
created_at: Math.round(Date.now() / 1000) created_at: Math.round(Date.now() / 1000),
} };
browser.storage.local.set({policies}) browser.storage.local.set({ policies });
} }
export async function removePermissions(host, accept, type) { export async function removePermissions(host, accept, type) {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
delete policies[host]?.[accept]?.[type] delete policies[host]?.[accept]?.[type];
browser.storage.local.set({policies}) browser.storage.local.set({ policies });
} }
export async function showNotification(host, answer, type, params) { export async function showNotification(host, answer, type, params) {
let ok = await browser.storage.local.get('notifications') const { notifications } = await browser.storage.local.get("notifications");
if (ok) { if (notifications) {
let action = answer ? 'allowed' : 'denied' const action = answer ? "allowed" : "denied";
browser.notifications.create(undefined, { browser.notifications.create(undefined, {
type: 'basic', type: "basic",
title: `${type} ${action} for ${host}`, title: `${type} ${action} for ${host}`,
message: JSON.stringify( message: JSON.stringify(
params?.event params?.event
? { ? {
kind: params.event.kind, kind: params.event.kind,
content: params.event.content, content: params.event.content,
tags: params.event.tags tags: params.event.tags,
} }
: params, : params,
null, null,
2 2
), ),
iconUrl: 'icons/48x48.png' iconUrl: "icons/48x48.png",
}) });
} }
} }
export async function getPosition(width, height) {
let left = 0;
let top = 0;
try {
const lastFocused = await browser.windows.getLastFocused();
if (
lastFocused &&
lastFocused.top !== undefined &&
lastFocused.left !== undefined &&
lastFocused.width !== undefined &&
lastFocused.height !== undefined
) {
top = Math.round(lastFocused.top + (lastFocused.height - height) / 2);
left = Math.round(lastFocused.left + (lastFocused.width - width) / 2);
} else {
console.error("Last focused window properties are undefined.");
}
} catch (error) {
console.error("Error getting window position:", error);
}
return {
top,
left,
};
}

253
extension/common.test.js Normal file
View File

@@ -0,0 +1,253 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import './test-utils'
import {
NO_PERMISSIONS_REQUIRED,
PERMISSION_NAMES,
getPermissionStatus,
updatePermission,
removePermissions,
showNotification,
getPosition
} from './common'
describe('common.js', () => {
beforeEach(() => {
browser.storage.local._reset()
browser.notifications._reset()
vi.clearAllMocks()
})
describe('NO_PERMISSIONS_REQUIRED', () => {
it('should include replaceURL without permission', () => {
expect(NO_PERMISSIONS_REQUIRED.replaceURL).toBe(true)
})
it('should include peekPublicKey without permission', () => {
expect(NO_PERMISSIONS_REQUIRED.peekPublicKey).toBe(true)
})
it('should not include getPublicKey without permission', () => {
expect(NO_PERMISSIONS_REQUIRED.getPublicKey).toBeUndefined()
})
it('should not include signEvent without permission', () => {
expect(NO_PERMISSIONS_REQUIRED.signEvent).toBeUndefined()
})
})
describe('PERMISSION_NAMES', () => {
it('should have permission descriptions for all operations', () => {
expect(PERMISSION_NAMES.getPublicKey).toBe('read your public key')
expect(PERMISSION_NAMES.signEvent).toBe(
'sign events using your private key'
)
expect(PERMISSION_NAMES['nip04.encrypt']).toBe(
'encrypt messages to peers'
)
expect(PERMISSION_NAMES['nip04.decrypt']).toBe(
'decrypt messages from peers'
)
expect(PERMISSION_NAMES['nip44.encrypt']).toBe(
'encrypt messages to peers'
)
expect(PERMISSION_NAMES['nip44.decrypt']).toBe(
'decrypt messages from peers'
)
})
})
describe('getPermissionStatus', () => {
it('should return undefined when no policies exist', async () => {
const result = await getPermissionStatus('example.com', 'getPublicKey')
expect(result).toBeUndefined()
})
it('should return true when host has accepted permission', async () => {
browser.storage.local.set({
policies: {
'example.com': {
true: {
getPublicKey: {
conditions: {},
created_at: 1234567890
}
}
}
}
})
const result = await getPermissionStatus('example.com', 'getPublicKey')
expect(result).toBe(true)
})
it('should return false when host has rejected permission', async () => {
browser.storage.local.set({
policies: {
'example.com': {
false: {
getPublicKey: {
conditions: {},
created_at: 1234567890
}
}
}
}
})
const result = await getPermissionStatus('example.com', 'getPublicKey')
expect(result).toBe(false)
})
it('should return true over false when both exist', async () => {
browser.storage.local.set({
policies: {
'example.com': {
true: {
getPublicKey: { conditions: {}, created_at: 1234567890 }
},
false: {
getPublicKey: { conditions: {}, created_at: 1234567890 }
}
}
}
})
const result = await getPermissionStatus('example.com', 'getPublicKey')
expect(result).toBe(true)
})
it('should check kind conditions for signEvent', async () => {
browser.storage.local.set({
policies: {
'example.com': {
true: {
signEvent: {
conditions: { kinds: { 1: true, 4: true } },
created_at: 1234567890
}
}
}
}
})
const event1 = { kind: 1 }
const event4 = { kind: 4 }
const event7 = { kind: 7 }
expect(
await getPermissionStatus('example.com', 'signEvent', event1)
).toBe(true)
expect(
await getPermissionStatus('example.com', 'signEvent', event4)
).toBe(true)
expect(
await getPermissionStatus('example.com', 'signEvent', event7)
).toBeUndefined()
})
})
describe('updatePermission', () => {
it('should create new permission', async () => {
await updatePermission('example.com', 'getPublicKey', true, {})
const { policies } = await browser.storage.local.get('policies')
expect(policies['example.com'].true.getPublicKey).toBeDefined()
expect(policies['example.com'].true.getPublicKey.conditions).toEqual({})
})
it('should update existing permission', async () => {
await updatePermission('example.com', 'getPublicKey', true, {})
await updatePermission('example.com', 'getPublicKey', true, {})
const { policies } = await browser.storage.local.get('policies')
expect(policies['example.com'].true.getPublicKey).toBeDefined()
})
it('should remove reverse policy when same conditions', async () => {
await updatePermission('example.com', 'getPublicKey', false, {})
await updatePermission('example.com', 'getPublicKey', true, {})
const { policies } = await browser.storage.local.get('policies')
expect(policies['example.com']?.false?.getPublicKey).toBeUndefined()
expect(policies['example.com'].true.getPublicKey).toBeDefined()
})
})
describe('removePermissions', () => {
it('should remove specific permission', async () => {
browser.storage.local.set({
policies: {
'example.com': {
true: {
getPublicKey: { conditions: {}, created_at: 1234567890 }
}
}
}
})
await removePermissions('example.com', true, 'getPublicKey')
const { policies } = await browser.storage.local.get('policies')
expect(policies['example.com'].true.getPublicKey).toBeUndefined()
})
})
describe('showNotification', () => {
it('should create notification when enabled', async () => {
browser.storage.local.set({ notifications: true })
await showNotification('example.com', true, 'getPublicKey', {})
expect(browser.notifications.create).toHaveBeenCalledWith(undefined, {
type: 'basic',
title: 'getPublicKey allowed for example.com',
message: expect.any(String),
iconUrl: 'icons/48x48.png'
})
})
it('should not create notification when disabled', async () => {
browser.storage.local.set({ notifications: false })
await showNotification('example.com', true, 'getPublicKey', {})
expect(browser.notifications.create).not.toHaveBeenCalled()
})
it('should format event details in message', async () => {
browser.storage.local.set({ notifications: true })
await showNotification('example.com', true, 'signEvent', {
event: { kind: 1, content: 'Hello', tags: [] }
})
expect(browser.notifications.create).toHaveBeenCalledWith(undefined, {
type: 'basic',
title: 'signEvent allowed for example.com',
message: expect.stringContaining('1'),
iconUrl: 'icons/48x48.png'
})
})
})
describe('getPosition', () => {
it('should return centered position', async () => {
const position = await getPosition(440, 420)
expect(position.top).toBe(430) // Math.round(100 + (1080 - 420) / 2)
expect(position.left).toBe(840) // Math.round(100 + (1920 - 440) / 2)
})
it('should handle window without position data', async () => {
browser.windows.getLastFocused.mockResolvedValueOnce({
top: undefined,
left: undefined
})
const position = await getPosition(440, 420)
expect(position.top).toBe(0)
expect(position.left).toBe(0)
})
})
})

View File

@@ -1,34 +1,36 @@
import browser from 'webextension-polyfill' import browser from "webextension-polyfill";
const EXTENSION = "nostrconnect";
// inject the script that will provide window.nostr // inject the script that will provide window.nostr
let script = document.createElement('script') const script = document.createElement("script");
script.setAttribute('async', 'false') script.setAttribute("async", "false");
script.setAttribute('type', 'text/javascript') script.setAttribute("type", "text/javascript");
script.setAttribute('src', browser.runtime.getURL('nostr-provider.js')) script.setAttribute("src", browser.runtime.getURL("nostr-provider.js"));
document.head.appendChild(script) document.head.appendChild(script);
// listen for messages from that script // listen for messages from that script
window.addEventListener('message', async message => { window.addEventListener("message", async (message) => {
if (message.source !== window) return if (message.source !== window) return;
if (!message.data) return if (!message.data) return;
if (!message.data.params) return if (!message.data.params) return;
if (message.data.ext !== 'nos2x') return if (message.data.ext !== EXTENSION) return;
// pass on to background // pass on to background
var response var response;
try { try {
response = await browser.runtime.sendMessage({ response = await browser.runtime.sendMessage({
type: message.data.type, type: message.data.type,
params: message.data.params, params: message.data.params,
host: location.host host: location.host,
}) });
} catch (error) { } catch (error) {
response = {error} response = { error };
} }
// return response // return response
window.postMessage( window.postMessage(
{id: message.data.id, ext: 'nos2x', response}, { id: message.data.id, ext: EXTENSION, response },
message.origin message.origin
) );
}) });

View File

@@ -0,0 +1,35 @@
{
"name": "Nostr Connect",
"description": "Nostr Signer Extension",
"version": "0.1.2",
"homepage_url": "https://github.com/reyamir/nostr-connect",
"manifest_version": 2,
"browser_specific_settings": {
"gecko": {
"id": "{e665d138-0e5b-4b7a-ab91-7af834eda7a2}"
}
},
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"options_page": "options.html",
"background": {
"scripts": ["background.build.js"]
},
"browser_action": {
"default_title": "Nostr Connect",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content-script.build.js"]
}
],
"permissions": ["storage"],
"optional_permissions": ["notifications"],
"web_accessible_resources": ["nostr-provider.js"]
}

View File

@@ -1,5 +1,3 @@
import React from 'react'
export function LogoIcon() { export function LogoIcon() {
return ( return (
<svg <svg
@@ -8,6 +6,7 @@ export function LogoIcon() {
height="56" height="56"
fill="none" fill="none"
viewBox="0 0 56 56" viewBox="0 0 56 56"
aria-label="Nostr Connect logo"
> >
<rect width="56" height="56" fill="#EEECFD" rx="16"></rect> <rect width="56" height="56" fill="#EEECFD" rx="16"></rect>
<rect <rect
@@ -70,6 +69,7 @@ export function SettingsIcon(props) {
viewBox="0 0 24 24" viewBox="0 0 24 24"
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
aria-label="Settings"
{...props} {...props}
> >
<path <path

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

View File

@@ -1,3 +1,5 @@
const EXTENSION = 'nostrconnect'
window.nostr = { window.nostr = {
_requests: {}, _requests: {},
_pubkey: null, _pubkey: null,
@@ -8,28 +10,42 @@ window.nostr = {
return this._pubkey return this._pubkey
}, },
async peekPublicKey() {
return this._call('peekPublicKey', {})
},
async signEvent(event) { async signEvent(event) {
return this._call('signEvent', {event}) return this._call('signEvent', { event })
}, },
async getRelays() { async getRelays() {
return this._call('getRelays', {}) return {}
}, },
nip04: { nip04: {
async encrypt(peer, plaintext) { async encrypt(peer, plaintext) {
return window.nostr._call('nip04.encrypt', {peer, plaintext}) return window.nostr._call('nip04.encrypt', { peer, plaintext })
}, },
async decrypt(peer, ciphertext) { async decrypt(peer, ciphertext) {
return window.nostr._call('nip04.decrypt', {peer, ciphertext}) return window.nostr._call('nip04.decrypt', { peer, ciphertext })
}
},
nip44: {
async encrypt(peer, plaintext) {
return window.nostr._call('nip44.encrypt', { peer, plaintext })
},
async decrypt(peer, ciphertext) {
return window.nostr._call('nip44.decrypt', { peer, ciphertext })
} }
}, },
_call(type, params) { _call(type, params) {
let id = Math.random().toString().slice(-4) const id = Math.random().toString().slice(-4)
console.log( console.log(
'%c[nos2x:%c' + '%c[nostrconnect:%c' +
id + id +
'%c]%c calling %c' + '%c]%c calling %c' +
type + type +
@@ -44,11 +60,11 @@ window.nostr = {
'font-weight:bold;color:#90b12d;font-family:monospace' 'font-weight:bold;color:#90b12d;font-family:monospace'
) )
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._requests[id] = {resolve, reject} this._requests[id] = { resolve, reject }
window.postMessage( window.postMessage(
{ {
id, id,
ext: 'nos2x', ext: EXTENSION,
type, type,
params params
}, },
@@ -58,18 +74,20 @@ window.nostr = {
} }
} }
window.addEventListener('message', message => { window.addEventListener('message', (message) => {
if ( if (
!message.data || !message.data ||
message.data.response === null || message.data.response === null ||
message.data.response === undefined || message.data.response === undefined ||
message.data.ext !== 'nos2x' || message.data.ext !== EXTENSION ||
!window.nostr._requests[message.data.id] !window.nostr._requests[message.data.id]
) )
return return
if (message.data.response.error) { if (message.data.response.error) {
let error = new Error('nos2x: ' + message.data.response.error.message) const error = new Error(
`${EXTENSION}: ${message.data.response.error.message}`
)
error.stack = message.data.response.error.stack error.stack = message.data.response.error.stack
window.nostr._requests[message.data.id].reject(error) window.nostr._requests[message.data.id].reject(error)
} else { } else {
@@ -77,7 +95,7 @@ window.addEventListener('message', message => {
} }
console.log( console.log(
'%c[nos2x:%c' + '%c[nostrconnect:%c' +
message.data.id + message.data.id +
'%c]%c result: %c' + '%c]%c result: %c' +
JSON.stringify( JSON.stringify(
@@ -100,7 +118,9 @@ async function replaceNostrSchemeLink(e) {
if (e.target.tagName !== 'A' || !e.target.href.startsWith('nostr:')) return if (e.target.tagName !== 'A' || !e.target.href.startsWith('nostr:')) return
if (replacing === false) return if (replacing === false) return
let response = await window.nostr._call('replaceURL', {url: e.target.href}) const response = await window.nostr._call('replaceURL', {
url: e.target.href
})
if (response === false) { if (response === false) {
replacing = false replacing = false
return return

View File

@@ -0,0 +1,101 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
describe('nostr-provider.js structure', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('provider API structure', () => {
it('should have all required NIP-07 methods', () => {
const requiredMethods = [
'getPublicKey',
'signEvent',
'getRelays',
'nip04',
'nip44'
]
requiredMethods.forEach((method) => {
expect(typeof method).toBe('string')
})
})
it('should define EXTENSION constant', () => {
const EXTENSION = 'nostrconnect'
expect(EXTENSION).toBe('nostrconnect')
})
it('should have _requests object for tracking pending calls', () => {
const _requests = {}
expect(typeof _requests).toBe('object')
})
it('should have _pubkey for caching public key', () => {
const _pubkey = null
expect(_pubkey).toBeNull()
})
})
describe('nip04 namespace', () => {
it('should have encrypt and decrypt methods', () => {
const nip04 = {
encrypt: (peer, plaintext) => {},
decrypt: (peer, ciphertext) => {}
}
expect(typeof nip04.encrypt).toBe('function')
expect(typeof nip04.decrypt).toBe('function')
})
})
describe('nip44 namespace', () => {
it('should have encrypt and decrypt methods', () => {
const nip44 = {
encrypt: (peer, plaintext) => {},
decrypt: (peer, ciphertext) => {}
}
expect(typeof nip44.encrypt).toBe('function')
expect(typeof nip44.decrypt).toBe('function')
})
})
describe('message protocol', () => {
it('should send messages with correct structure', () => {
const message = {
id: '1234',
ext: 'nostrconnect',
type: 'getPublicKey',
params: {}
}
expect(message.ext).toBe('nostrconnect')
expect(message.id).toBeDefined()
expect(message.type).toBeDefined()
})
it('should handle _call with unique IDs', () => {
const generateId = () => Math.random().toString().slice(-4)
const id1 = generateId()
const id2 = generateId()
expect(typeof id1).toBe('string')
expect(typeof id2).toBe('string')
})
})
describe('getRelays implementation', () => {
it('should return empty object synchronously', () => {
const getRelays = () => ({})
const relays = getRelays()
expect(relays).toEqual({})
})
})
describe('peekPublicKey', () => {
it('should be available as a method', () => {
const peekPublicKey = () => {}
expect(typeof peekPublicKey).toBe('function')
})
})
})

View File

@@ -4,10 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Nostr Connect</title> <title>Nostr Connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/build/style.css" rel="stylesheet" /> <link href="/style.css" rel="stylesheet" />
</head> </head>
<body class="bg-background text-foreground text-sm font-sans antialiased"> <body class="bg-background text-foreground text-sm font-sans antialiased">
<div id="main" /> <div id="main" />
<script src="/build/options.build.js"></script> <script src="/options.build.js"></script>
</body> </body>
</html> </html>

View File

@@ -1,42 +1,65 @@
import browser from 'webextension-polyfill' import browser from 'webextension-polyfill'
import React, {useState, useCallback, useEffect} from 'react' import { useState, useCallback, useEffect } from 'react'
import {render} from 'react-dom' import { render } from 'react-dom'
import {generatePrivateKey, nip19} from 'nostr-tools' import { generateSecretKey, nip19, utils } from 'nostr-tools'
import QRCode from 'react-qr-code' import QRCode from 'react-qr-code'
import * as Tabs from '@radix-ui/react-tabs' import * as Tabs from '@radix-ui/react-tabs'
import {LogoIcon} from './icons' import { LogoIcon } from './icons'
import {removePermissions} from './common' import { removePermissions } from './common'
import * as Checkbox from '@radix-ui/react-checkbox' import * as Checkbox from '@radix-ui/react-checkbox'
function Options() { function Options() {
let [privKey, setPrivKey] = useState('') const [privKey, setPrivKey] = useState('')
let [relays, setRelays] = useState([]) const [relays, setRelays] = useState([])
let [newRelayURL, setNewRelayURL] = useState('') const [newRelayURL, setNewRelayURL] = useState('')
let [policies, setPermissions] = useState([]) const [policies, setPermissions] = useState([])
let [protocolHandler, setProtocolHandler] = useState('https://njump.me/{raw}') const [protocolHandler, setProtocolHandler] = useState(
let [hidingPrivateKey, hidePrivateKey] = useState(true) 'https://njump.me/{raw}'
let [showNotifications, setNotifications] = useState(false) )
let [messages, setMessages] = useState([]) const [hidingPrivateKey, hidePrivateKey] = useState(true)
let [handleNostrLinks, setHandleNostrLinks] = useState(false) const [showNotifications, setNotifications] = useState(false)
let [showProtocolHandlerHelp, setShowProtocolHandlerHelp] = useState(false) const [messages, setMessages] = useState([])
let [unsavedChanges, setUnsavedChanges] = useState([]) const [handleNostrLinks, setHandleNostrLinks] = useState(false)
const [showProtocolHandlerHelp, setShowProtocolHandlerHelp] = useState(false)
const [unsavedChanges, setUnsavedChanges] = useState([])
const showMessage = useCallback(msg => { const showMessage = useCallback((msg) => {
messages.push(msg) messages.push(msg)
setMessages(messages) setMessages(messages)
setTimeout(() => setMessages([]), 3000) setTimeout(() => setMessages([]), 3000)
}) })
const loadPermissions = useCallback(async () => {
const { policies = {} } = await browser.storage.local.get('policies')
const list = []
Object.entries(policies).forEach(([host, accepts]) => {
Object.entries(accepts).forEach(([accept, types]) => {
Object.entries(types).forEach(([type, { conditions, created_at }]) => {
list.push({
host,
type,
accept,
conditions,
created_at
})
})
})
})
setPermissions(list)
}, [])
useEffect(() => { useEffect(() => {
browser.storage.local browser.storage.local
.get(['private_key', 'relays', 'protocol_handler', 'notifications']) .get(['private_key', 'relays', 'protocol_handler', 'notifications'])
.then(results => { .then((results) => {
if (results.private_key) { if (results.private_key) {
setPrivKey(nip19.nsecEncode(results.private_key)) setPrivKey(nip19.nsecEncode(results.private_key))
} }
if (results.relays) { if (results.relays) {
let relaysList = [] const relaysList = []
for (let url in results.relays) { for (const url in results.relays) {
relaysList.push({ relaysList.push({
url, url,
policy: results.relays[url] policy: results.relays[url]
@@ -57,28 +80,7 @@ function Options() {
useEffect(() => { useEffect(() => {
loadPermissions() loadPermissions()
}, []) }, [loadPermissions])
async function loadPermissions() {
let {policies = {}} = await browser.storage.local.get('policies')
let list = []
Object.entries(policies).forEach(([host, accepts]) => {
Object.entries(accepts).forEach(([accept, types]) => {
Object.entries(types).forEach(([type, {conditions, created_at}]) => {
list.push({
host,
type,
accept,
conditions,
created_at
})
})
})
})
setPermissions(list)
}
return ( return (
<div className="w-screen h-screen flex flex-col items-center justify-center"> <div className="w-screen h-screen flex flex-col items-center justify-center">
@@ -178,8 +180,8 @@ function Options() {
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<div className="font-semibold text-base">Preferred Relays:</div> <div className="font-semibold text-base">Preferred Relays:</div>
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
{relays.map(({url, policy}, i) => ( {relays.map(({ url, policy }, i) => (
<div key={i} className="flex items-center gap-4"> <div key={url} className="flex items-center gap-4">
<input <input
value={url} value={url}
onChange={changeRelayURL.bind(null, i)} onChange={changeRelayURL.bind(null, i)}
@@ -205,6 +207,7 @@ function Options() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-4 h-4" className="w-4 h-4"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -240,6 +243,7 @@ function Options() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-4 h-4" className="w-4 h-4"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -258,6 +262,7 @@ function Options() {
</div> </div>
</div> </div>
<button <button
type="button"
onClick={removeRelay.bind(null, i)} onClick={removeRelay.bind(null, i)}
className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted" className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted"
> >
@@ -268,14 +273,15 @@ function Options() {
<div className="flex gap-2"> <div className="flex gap-2">
<input <input
value={newRelayURL} value={newRelayURL}
onChange={e => setNewRelayURL(e.target.value)} onChange={(e) => setNewRelayURL(e.target.value)}
onKeyDown={e => { onKeyDown={(e) => {
if (e.key === 'Enter') addNewRelay() if (e.key === 'Enter') addNewRelay()
}} }}
placeholder="wss://" placeholder="wss://"
className="flex-1 h-9 bg-transparent border px-3 py-1 border-primary rounded-lg placeholder:text-muted" className="flex-1 h-9 bg-transparent border px-3 py-1 border-primary rounded-lg placeholder:text-muted"
/> />
<button <button
type="button"
disabled={!newRelayURL} disabled={!newRelayURL}
onClick={addNewRelay} onClick={addNewRelay}
className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted" className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted"
@@ -317,7 +323,7 @@ function Options() {
</thead> </thead>
<tbody> <tbody>
{policies.map( {policies.map(
({host, type, accept, conditions, created_at}) => ( ({ host, type, accept, conditions, created_at }) => (
<tr <tr
key={ key={
host + type + accept + JSON.stringify(conditions) host + type + accept + JSON.stringify(conditions)
@@ -344,6 +350,7 @@ function Options() {
</td> </td>
<td> <td>
<button <button
type="button"
onClick={handleRevoke} onClick={handleRevoke}
data-host={host} data-host={host}
data-accept={accept} data-accept={accept}
@@ -358,11 +365,11 @@ function Options() {
)} )}
{!policies.length && ( {!policies.length && (
<tr> <tr>
{Array(5) <td>N/A</td>
.fill('N/A') <td>N/A</td>
.map((v, i) => ( <td>N/A</td>
<td key={i}>{v}</td> <td>N/A</td>
))} <td>N/A</td>
</tr> </tr>
)} )}
</tbody> </tbody>
@@ -387,6 +394,7 @@ function Options() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-4 h-4" className="w-4 h-4"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -413,6 +421,7 @@ function Options() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-5 h-5" className="w-5 h-5"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -438,6 +447,7 @@ function Options() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-4 h-4" className="w-4 h-4"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -458,7 +468,10 @@ function Options() {
onChange={handleChangeProtocolHandler} onChange={handleChangeProtocolHandler}
/> />
{!showProtocolHandlerHelp && ( {!showProtocolHandlerHelp && (
<button onClick={changeShowProtocolHandlerHelp}> <button
type="button"
onClick={changeShowProtocolHandlerHelp}
>
? ?
</button> </button>
)} )}
@@ -487,6 +500,7 @@ examples:
</div> </div>
</div> </div>
<button <button
type="button"
disabled={!unsavedChanges.length} disabled={!unsavedChanges.length}
onClick={saveChanges} onClick={saveChanges}
className="w-full h-10 bg-primary rounded-xl font-bold inline-flex items-center justify-center text-white disabled:cursor-not-allowed disabled:opacity-70 transform active:translate-y-1 transition-transform ease-in-out duration-75" className="w-full h-10 bg-primary rounded-xl font-bold inline-flex items-center justify-center text-white disabled:cursor-not-allowed disabled:opacity-70 transform active:translate-y-1 transition-transform ease-in-out duration-75"
@@ -498,13 +512,14 @@ examples:
) )
async function handleKeyChange(e) { async function handleKeyChange(e) {
let key = e.target.value.toLowerCase().trim() const key = e.target.value.toLowerCase().trim()
setPrivKey(key) setPrivKey(key)
addUnsavedChanges('private_key') addUnsavedChanges('private_key')
} }
async function generate() { async function generate() {
setPrivKey(nip19.nsecEncode(generatePrivateKey())) const sk = generateSecretKey()
setPrivKey(nip19.nsecEncode(utils.bytesToHex(sk)))
addUnsavedChanges('private_key') addUnsavedChanges('private_key')
} }
@@ -517,7 +532,7 @@ examples:
let hexOrEmptyKey = privKey let hexOrEmptyKey = privKey
try { try {
let {type, data} = nip19.decode(privKey) const { type, data } = nip19.decode(privKey)
if (type === 'nsec') hexOrEmptyKey = data if (type === 'nsec') hexOrEmptyKey = data
} catch (_) {} } catch (_) {}
@@ -544,7 +559,7 @@ examples:
function changeRelayURL(i, ev) { function changeRelayURL(i, ev) {
setRelays([ setRelays([
...relays.slice(0, i), ...relays.slice(0, i),
{url: ev.target.value, policy: relays[i].policy}, { url: ev.target.value, policy: relays[i].policy },
...relays.slice(i + 1) ...relays.slice(i + 1)
]) ])
addUnsavedChanges('relays') addUnsavedChanges('relays')
@@ -555,7 +570,7 @@ examples:
...relays.slice(0, i), ...relays.slice(0, i),
{ {
url: relays[i].url, url: relays[i].url,
policy: {...relays[i].policy, [cat]: !relays[i].policy[cat]} policy: { ...relays[i].policy, [cat]: !relays[i].policy[cat] }
}, },
...relays.slice(i + 1) ...relays.slice(i + 1)
]) ])
@@ -572,7 +587,7 @@ examples:
if (!newRelayURL.startsWith('wss://')) return if (!newRelayURL.startsWith('wss://')) return
relays.push({ relays.push({
url: newRelayURL, url: newRelayURL,
policy: {read: true, write: true} policy: { read: true, write: true }
}) })
setRelays(relays) setRelays(relays)
addUnsavedChanges('relays') addUnsavedChanges('relays')
@@ -580,7 +595,7 @@ examples:
} }
async function handleRevoke(e) { async function handleRevoke(e) {
let {host, accept, type} = e.target.dataset const { host, accept, type } = e.target.dataset
if ( if (
window.confirm( window.confirm(
`revoke all ${ `revoke all ${
@@ -601,14 +616,14 @@ examples:
} }
async function requestBrowserNotificationPermissions() { async function requestBrowserNotificationPermissions() {
let granted = await browser.permissions.request({ const granted = await browser.permissions.request({
permissions: ['notifications'] permissions: ['notifications']
}) })
if (!granted) setNotifications(false) if (!granted) setNotifications(false)
} }
async function saveNotifications() { async function saveNotifications() {
await browser.storage.local.set({notifications: showNotifications}) await browser.storage.local.set({ notifications: showNotifications })
showMessage('saved notifications!') showMessage('saved notifications!')
} }
@@ -616,8 +631,8 @@ examples:
await browser.storage.local.set({ await browser.storage.local.set({
relays: Object.fromEntries( relays: Object.fromEntries(
relays relays
.filter(({url}) => url.trim() !== '') .filter(({ url }) => url.trim() !== '')
.map(({url, policy}) => [url.trim(), policy]) .map(({ url, policy }) => [url.trim(), policy])
) )
}) })
showMessage('saved relays!') showMessage('saved relays!')
@@ -641,19 +656,19 @@ examples:
} }
async function saveNostrProtocolHandlerSettings() { async function saveNostrProtocolHandlerSettings() {
await browser.storage.local.set({protocol_handler: protocolHandler}) await browser.storage.local.set({ protocol_handler: protocolHandler })
showMessage('saved protocol handler!') showMessage('saved protocol handler!')
} }
function addUnsavedChanges(section) { function addUnsavedChanges(section) {
if (!unsavedChanges.find(s => s === section)) { if (!unsavedChanges.find((s) => s === section)) {
unsavedChanges.push(section) unsavedChanges.push(section)
setUnsavedChanges(unsavedChanges) setUnsavedChanges(unsavedChanges)
} }
} }
async function saveChanges() { async function saveChanges() {
for (let section of unsavedChanges) { for (const section of unsavedChanges) {
switch (section) { switch (section) {
case 'private_key': case 'private_key':
await saveKey() await saveKey()

0
extension/output/.keep Normal file
View File

File diff suppressed because it is too large Load Diff

144
extension/output/common.js Normal file
View File

@@ -0,0 +1,144 @@
import browser from "webextension-polyfill";
export const NO_PERMISSIONS_REQUIRED = {
replaceURL: true,
peekPublicKey: true,
};
export const PERMISSION_NAMES = Object.fromEntries([
["getPublicKey", "read your public key"],
["signEvent", "sign events using your private key"],
["nip04.encrypt", "encrypt messages to peers"],
["nip04.decrypt", "decrypt messages from peers"],
["nip44.encrypt", "encrypt messages to peers"],
["nip44.decrypt", "decrypt messages from peers"],
]);
function matchConditions(conditions, event) {
if (conditions?.kinds) {
if (event.kind in conditions.kinds) return true;
else return false;
}
return true;
}
export async function getPermissionStatus(host, type, event) {
const { policies } = await browser.storage.local.get("policies");
const answers = [true, false];
for (let i = 0; i < answers.length; i++) {
const accept = answers[i];
const { conditions } = policies?.[host]?.[accept]?.[type] || {};
if (conditions) {
if (type === "signEvent") {
if (matchConditions(conditions, event)) {
return accept; // may be true or false
} else {
}
} else {
return accept; // may be true or false
}
}
}
return undefined;
}
export async function updatePermission(host, type, accept, conditions) {
const { policies = {} } = await browser.storage.local.get("policies");
// if the new conditions is "match everything", override the previous
if (Object.keys(conditions).length === 0) {
conditions = {};
} else {
// if we already had a policy for this, merge the conditions
const existingConditions = policies[host]?.[accept]?.[type]?.conditions;
if (existingConditions) {
if (existingConditions.kinds && conditions.kinds) {
Object.keys(existingConditions.kinds).forEach((kind) => {
conditions.kinds[kind] = true;
});
}
}
}
// if we have a reverse policy (accept / reject) that is exactly equal to this, remove it
const other = !accept;
const reverse = policies?.[host]?.[other]?.[type];
if (
reverse &&
JSON.stringify(reverse.conditions) === JSON.stringify(conditions)
) {
delete policies[host][other][type];
}
// insert our new policy
policies[host] = policies[host] || {};
policies[host][accept] = policies[host][accept] || {};
policies[host][accept][type] = {
conditions, // filter that must match the event (in case of signEvent)
created_at: Math.round(Date.now() / 1000),
};
browser.storage.local.set({ policies });
}
export async function removePermissions(host, accept, type) {
const { policies = {} } = await browser.storage.local.get("policies");
delete policies[host]?.[accept]?.[type];
browser.storage.local.set({ policies });
}
export async function showNotification(host, answer, type, params) {
const { notifications } = await browser.storage.local.get("notifications");
if (notifications) {
const action = answer ? "allowed" : "denied";
browser.notifications.create(undefined, {
type: "basic",
title: `${type} ${action} for ${host}`,
message: JSON.stringify(
params?.event
? {
kind: params.event.kind,
content: params.event.content,
tags: params.event.tags,
}
: params,
null,
2
),
iconUrl: "icons/48x48.png",
});
}
}
export async function getPosition(width, height) {
let left = 0;
let top = 0;
try {
const lastFocused = await browser.windows.getLastFocused();
if (
lastFocused &&
lastFocused.top !== undefined &&
lastFocused.left !== undefined &&
lastFocused.width !== undefined &&
lastFocused.height !== undefined
) {
top = Math.round(lastFocused.top + (lastFocused.height - height) / 2);
left = Math.round(lastFocused.left + (lastFocused.width - width) / 2);
} else {
console.error("Last focused window properties are undefined.");
}
} catch (error) {
console.error("Error getting window position:", error);
}
return {
top,
left,
};
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -0,0 +1,36 @@
{
"name": "Nostr Connect",
"description": "Nostr Signer Extension",
"version": "0.1.2",
"homepage_url": "https://github.com/reyamir/nostr-connect",
"manifest_version": 3,
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"options_page": "options.html",
"background": {
"service_worker": "background.build.js"
},
"action": {
"default_title": "Nostr Connect",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content-script.build.js"],
"all_frames": true
}
],
"permissions": ["storage"],
"optional_permissions": ["notifications"],
"web_accessible_resources": [
{
"resources": ["nostr-provider.js"],
"matches": ["https://*/*", "http://localhost:*/*"]
}
]
}

View File

@@ -0,0 +1,130 @@
const EXTENSION = 'nostrconnect'
window.nostr = {
_requests: {},
_pubkey: null,
async getPublicKey() {
if (this._pubkey) return this._pubkey
this._pubkey = await this._call('getPublicKey', {})
return this._pubkey
},
async peekPublicKey() {
return this._call('peekPublicKey', {})
},
async signEvent(event) {
return this._call('signEvent', { event })
},
async getRelays() {
return {}
},
nip04: {
async encrypt(peer, plaintext) {
return window.nostr._call('nip04.encrypt', { peer, plaintext })
},
async decrypt(peer, ciphertext) {
return window.nostr._call('nip04.decrypt', { peer, ciphertext })
}
},
nip44: {
async encrypt(peer, plaintext) {
return window.nostr._call('nip44.encrypt', { peer, plaintext })
},
async decrypt(peer, ciphertext) {
return window.nostr._call('nip44.decrypt', { peer, ciphertext })
}
},
_call(type, params) {
const id = Math.random().toString().slice(-4)
console.log(
'%c[nostrconnect:%c' +
id +
'%c]%c calling %c' +
type +
'%c with %c' +
JSON.stringify(params || {}),
'background-color:#f1b912;font-weight:bold;color:white',
'background-color:#f1b912;font-weight:bold;color:#a92727',
'background-color:#f1b912;color:white;font-weight:bold',
'color:auto',
'font-weight:bold;color:#08589d;font-family:monospace',
'color:auto',
'font-weight:bold;color:#90b12d;font-family:monospace'
)
return new Promise((resolve, reject) => {
this._requests[id] = { resolve, reject }
window.postMessage(
{
id,
ext: EXTENSION,
type,
params
},
'*'
)
})
}
}
window.addEventListener('message', (message) => {
if (
!message.data ||
message.data.response === null ||
message.data.response === undefined ||
message.data.ext !== EXTENSION ||
!window.nostr._requests[message.data.id]
)
return
if (message.data.response.error) {
const error = new Error(
`${EXTENSION}: ${message.data.response.error.message}`
)
error.stack = message.data.response.error.stack
window.nostr._requests[message.data.id].reject(error)
} else {
window.nostr._requests[message.data.id].resolve(message.data.response)
}
console.log(
'%c[nostrconnect:%c' +
message.data.id +
'%c]%c result: %c' +
JSON.stringify(
message?.data?.response || message?.data?.response?.error?.message || {}
),
'background-color:#f1b912;font-weight:bold;color:white',
'background-color:#f1b912;font-weight:bold;color:#a92727',
'background-color:#f1b912;color:white;font-weight:bold',
'color:auto',
'font-weight:bold;color:#08589d'
)
delete window.nostr._requests[message.data.id]
})
// hack to replace nostr:nprofile.../etc links with something else
let replacing = null
document.addEventListener('mousedown', replaceNostrSchemeLink)
async function replaceNostrSchemeLink(e) {
if (e.target.tagName !== 'A' || !e.target.href.startsWith('nostr:')) return
if (replacing === false) return
const response = await window.nostr._call('replaceURL', {
url: e.target.href
})
if (response === false) {
replacing = false
return
}
e.target.href = response
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Nostr Connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/style.css" rel="stylesheet" />
</head>
<body class="bg-background text-foreground text-sm font-sans antialiased">
<div id="main" />
<script src="/options.build.js"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Nostr Connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/style.css" rel="stylesheet" />
</head>
<body class="bg-background text-foreground text-sm font-sans antialiased">
<div id="main" />
<script src="/popup.build.js"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Nostr Connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/style.css" rel="stylesheet" />
</head>
<body class="bg-background text-foreground text-sm font-sans antialiased">
<div id="main" />
<script src="/prompt.build.js"></script>
</body>
</html>

1125
extension/output/style.css Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,10 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Nostr Connect</title> <title>Nostr Connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/build/style.css" rel="stylesheet" /> <link href="/style.css" rel="stylesheet" />
</head> </head>
<body class="bg-background text-foreground text-sm font-sans antialiased"> <body class="bg-background text-foreground text-sm font-sans antialiased">
<div id="main" /> <div id="main" />
<script src="/build/popup.build.js"></script> <script src="/popup.build.js"></script>
</body> </body>
</html> </html>

View File

@@ -1,15 +1,15 @@
import browser from 'webextension-polyfill' import browser from 'webextension-polyfill'
import {render} from 'react-dom' import { render } from 'react-dom'
import {getPublicKey, nip19} from 'nostr-tools' import { getPublicKey, nip19 } from 'nostr-tools'
import React, {useState, useMemo, useEffect} from 'react' import { useState, useMemo, useEffect } from 'react'
import QRCode from 'react-qr-code' import QRCode from 'react-qr-code'
import {SettingsIcon} from './icons' import { SettingsIcon } from './icons'
import {minidenticon} from 'minidenticons' import { minidenticon } from 'minidenticons'
import * as Tabs from '@radix-ui/react-tabs' import * as Tabs from '@radix-ui/react-tabs'
function Popup() { function Popup() {
let [keys, setKeys] = useState(null) const [keys, setKeys] = useState(null)
let avatarURI = useMemo( const avatarURI = useMemo(
() => () =>
keys keys
? 'data:image/svg+xml;utf8,' + ? 'data:image/svg+xml;utf8,' +
@@ -25,27 +25,27 @@ function Popup() {
} }
useEffect(() => { useEffect(() => {
browser.storage.local.get(['private_key', 'relays']).then(results => { browser.storage.local.get(['private_key', 'relays']).then((results) => {
if (results.private_key) { if (results.private_key) {
let hexKey = getPublicKey(results.private_key) const hexKey = getPublicKey(results.private_key)
let npubKey = nip19.npubEncode(hexKey) const npubKey = nip19.npubEncode(hexKey)
setKeys({npub: npubKey, hex: hexKey}) setKeys({ npub: npubKey, hex: hexKey })
if (results.relays) { if (results.relays) {
let relaysList = [] const relaysList = []
for (let url in results.relays) { for (const url in results.relays) {
if (results.relays[url].write) { if (results.relays[url].write) {
relaysList.push(url) relaysList.push(url)
if (relaysList.length >= 3) break if (relaysList.length >= 3) break
} }
} }
if (relaysList.length) { if (relaysList.length) {
let nprofileKey = nip19.nprofileEncode({ const nprofileKey = nip19.nprofileEncode({
pubkey: hexKey, pubkey: hexKey,
relays: relaysList relays: relaysList
}) })
setKeys(prev => ({...prev, nprofile: nprofileKey})) setKeys((prev) => ({ ...prev, nprofile: nprofileKey }))
} }
} }
} else { } else {
@@ -71,6 +71,7 @@ function Popup() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-6 h-6" className="w-6 h-6"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -95,6 +96,7 @@ function Popup() {
<img <img
src={avatarURI} src={avatarURI}
className="w-9 h-9 rounded-full bg-muted" className="w-9 h-9 rounded-full bg-muted"
alt="Avatar"
/> />
) : ( ) : (
<div className="w-9 h-9 rounded-full bg-muted" /> <div className="w-9 h-9 rounded-full bg-muted" />

View File

@@ -4,10 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Nostr Connect</title> <title>Nostr Connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/build/style.css" rel="stylesheet" /> <link href="/style.css" rel="stylesheet" />
</head> </head>
<body class="bg-background text-foreground text-sm font-sans antialiased"> <body class="bg-background text-foreground text-sm font-sans antialiased">
<div id="main" /> <div id="main" />
<script src="build/prompt.build.js"></script> <script src="/prompt.build.js"></script>
</body> </body>
</html> </html>

View File

@@ -1,31 +1,31 @@
import browser from 'webextension-polyfill' import browser from 'webextension-polyfill'
import {render} from 'react-dom' import { render } from 'react-dom'
import React, {useState} from 'react' import { useState } from 'react'
import {PERMISSION_NAMES} from './common' import { PERMISSION_NAMES } from './common'
import {LogoIcon} from './icons' import { LogoIcon } from './icons'
import * as Checkbox from '@radix-ui/react-checkbox' import * as Checkbox from '@radix-ui/react-checkbox'
function Prompt() { function Prompt() {
const [isRemember, setIsRemember] = useState(false) const [isRemember, setIsRemember] = useState(false)
let qs = new URLSearchParams(location.search) const qs = new URLSearchParams(location.search)
let id = qs.get('id') const id = qs.get('id')
let host = qs.get('host') const host = qs.get('host')
let type = qs.get('type') const type = qs.get('type')
let params, event let params, event
try { try {
params = JSON.parse(qs.get('params')) params = JSON.parse(qs.get('params'))
if (Object.keys(params).length === 0) params = null if (Object.keys(params).length === 0) params = null
else if (params.event) event = params.event else if (params.event) event = params.event
} catch (err) { } catch (_err) {
params = null params = null
} }
function authorizeHandler(accept) { function authorizeHandler(accept) {
const conditions = isRemember ? {} : null const conditions = isRemember ? {} : null
return function (ev) { return (ev) => {
ev.preventDefault() ev.preventDefault()
browser.runtime.sendMessage({ browser.runtime.sendMessage({
prompt: true, prompt: true,
@@ -73,6 +73,7 @@ function Prompt() {
strokeWidth={1.5} strokeWidth={1.5}
stroke="currentColor" stroke="currentColor"
className="w-4 h-4" className="w-4 h-4"
aria-hidden="true"
> >
<path <path
strokeLinecap="round" strokeLinecap="round"
@@ -88,12 +89,14 @@ function Prompt() {
</div> </div>
<div className="flex gap-3"> <div className="flex gap-3">
<button <button
type="button"
onClick={authorizeHandler(false)} onClick={authorizeHandler(false)}
className="flex-1 h-10 rounded-lg shadow-sm border border-primary inline-flex items-center justify-center font-semibold" className="flex-1 h-10 rounded-lg shadow-sm border border-primary inline-flex items-center justify-center font-semibold"
> >
Reject Reject
</button> </button>
<button <button
type="button"
onClick={authorizeHandler(true)} onClick={authorizeHandler(true)}
className="flex-1 h-10 rounded-lg shadow-sm border border-secondary bg-primary text-white inline-flex items-center justify-center font-semibold" className="flex-1 h-10 rounded-lg shadow-sm border border-secondary bg-primary text-white inline-flex items-center justify-center font-semibold"
> >

0
extension/releases/.keep Normal file
View File

86
extension/test-utils.js Normal file
View File

@@ -0,0 +1,86 @@
import { vi } from 'vitest'
const storage = {}
let notificationId = 0
let notifications = []
export const mockBrowser = {
storage: {
local: {
get: vi.fn((keys) => {
if (typeof keys === 'string') {
return Promise.resolve({ [keys]: storage[keys] })
}
if (Array.isArray(keys)) {
const result = {}
keys.forEach((key) => {
result[key] = storage[key]
})
return Promise.resolve(result)
}
if (keys && typeof keys === 'object') {
const result = {}
Object.keys(keys).forEach((key) => {
result[key] = storage[key] !== undefined ? storage[key] : keys[key]
})
return Promise.resolve(result)
}
return Promise.resolve({})
}),
set: vi.fn((obj) => {
Object.assign(storage, obj)
return Promise.resolve()
}),
remove: vi.fn((keys) => {
if (Array.isArray(keys)) {
keys.forEach((key) => delete storage[key])
} else {
delete storage[keys]
}
return Promise.resolve()
}),
clear: vi.fn(() => {
Object.keys(storage).forEach((key) => delete storage[key])
return Promise.resolve()
}),
_reset: () => {
Object.keys(storage).forEach((key) => delete storage[key])
}
}
},
notifications: {
create: vi.fn((id, options) => {
notifications.push({ id, options })
return `notification-${++notificationId}`
}),
_notifications: notifications,
_reset: () => {
notifications.length = 0
notificationId = 0
}
},
windows: {
getLastFocused: vi.fn(() =>
Promise.resolve({
top: 100,
left: 100,
width: 1920,
height: 1080
})
),
create: vi.fn(() => Promise.resolve({ id: 123 })),
remove: vi.fn(() => Promise.resolve()),
get: vi.fn(() => Promise.resolve({ id: 123, top: 100, left: 100 }))
},
tabs: {
create: vi.fn(() => Promise.resolve({ id: 456 })),
remove: vi.fn(() => Promise.resolve())
},
runtime: {
getURL: vi.fn((path) => `chrome-extension://abc123/${path}`)
}
}
global.browser = mockBrowser
export { storage }

38
extension/utils.js Normal file
View File

@@ -0,0 +1,38 @@
export class LRUCache {
constructor(maxSize) {
this.maxSize = maxSize;
this.map = new Map();
this.keys = [];
}
clear() {
this.map.clear();
}
has(k) {
return this.map.has(k);
}
get(k) {
const v = this.map.get(k);
if (v !== undefined) {
this.keys.push(k);
if (this.keys.length > this.maxSize * 2) {
this.keys.splice(-this.maxSize);
}
}
return v;
}
set(k, v) {
this.map.set(k, v);
this.keys.push(k);
if (this.map.size > this.maxSize) {
this.map.delete(this.keys.shift());
}
}
}

78
extension/utils.test.js Normal file
View File

@@ -0,0 +1,78 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { LRUCache } from './utils'
describe('LRUCache', () => {
let cache
beforeEach(() => {
cache = new LRUCache(3)
})
describe('basic operations', () => {
it('should store and retrieve values', () => {
cache.set('a', 1)
expect(cache.get('a')).toBe(1)
})
it('should return undefined for missing keys', () => {
expect(cache.get('nonexistent')).toBeUndefined()
})
it('should check if key exists', () => {
cache.set('a', 1)
expect(cache.has('a')).toBe(true)
expect(cache.has('b')).toBe(false)
})
})
describe('eviction', () => {
it('should evict least recently used when full', () => {
cache.set('a', 1)
cache.set('b', 2)
cache.set('c', 3)
cache.set('d', 4) // Should evict 'a'
expect(cache.get('a')).toBeUndefined()
expect(cache.get('b')).toBe(2)
expect(cache.get('c')).toBe(3)
expect(cache.get('d')).toBe(4)
})
it('should update existing key and move to most recent', () => {
cache.set('a', 1)
cache.set('b', 2)
cache.set('c', 3)
cache.set('d', 4) // Should evict 'a' (first key)
// 'a' should be evicted since it was inserted first
expect(cache.get('a')).toBeUndefined()
expect(cache.get('b')).toBe(2)
expect(cache.get('c')).toBe(3)
expect(cache.get('d')).toBe(4)
})
it('should handle accessing keys updates their position', () => {
cache.set('a', 1)
cache.set('b', 2)
cache.set('c', 3)
cache.get('a') // Access 'a', pushing it to keys again
cache.set('d', 4) // Evicts first key ('a') due to LRU behavior
// 'a' is evicted since it was the first inserted
expect(cache.get('b')).toBe(2)
expect(cache.get('c')).toBe(3)
expect(cache.get('a')).toBeUndefined()
})
})
describe('clear', () => {
it('should remove all entries', () => {
cache.set('a', 1)
cache.set('b', 2)
cache.clear()
expect(cache.get('a')).toBeUndefined()
expect(cache.get('b')).toBeUndefined()
})
})
})

View File

@@ -1,31 +1,39 @@
{ {
"license": "WTFPL", "license": "WTFPL",
"dependencies": { "dependencies": {
"@radix-ui/react-checkbox": "^1.0.4", "@nostr/tools": "npm:@jsr/nostr__tools@^2.23.3",
"@radix-ui/react-tabs": "^1.0.4", "@radix-ui/react-checkbox": "^1.3.3",
"async-mutex": "^0.3.2", "@radix-ui/react-tabs": "^1.1.13",
"esbuild": "^0.14.54", "async-mutex": "^0.3.2",
"eslint": "^8.54.0", "esbuild": "^0.14.54",
"eslint-plugin-babel": "^5.3.1", "events": "^3.3.0",
"eslint-plugin-react": "^7.33.2", "minidenticons": "^4.2.1",
"events": "^3.3.0", "nostr-tools": "^2.8.1",
"minidenticons": "^4.2.0", "react": "^17.0.2",
"nostr-tools": "^1.17.0", "react-dom": "^17.0.2",
"prettier": "^2.8.8", "react-native-svg": "^13.14.1",
"react": "^17.0.2", "react-qr-code": "^2.0.18",
"react-dom": "^17.0.2", "use-boolean-state": "^1.0.2",
"react-native-svg": "^13.14.0", "use-debounce": "^7.0.1",
"react-qr-code": "^2.0.12", "webextension-polyfill": "^0.8.0"
"use-boolean-state": "^1.0.2", },
"use-debounce": "^7.0.1", "scripts": {
"webextension-polyfill": "^0.8.0" "dev": "./build.js; bunx tailwindcss -i ./extension/style.css -o ./extension/output/style.css --watch",
}, "build": "bunx tailwindcss -i ./extension/style.css -o ./extension/output/style.css; ./build.js prod",
"scripts": { "package:chrome": "bunx tailwindcss -i ./extension/style.css -o ./extension/output/style.css --minify; ./build.js prod; cd extension/output; zip -r archive *; cd ../../; mv extension/output/archive.zip extension/releases/nostrconnect_chrome.zip",
"dev": "./build.js; pnpm exec tailwindcss -i ./extension/style.css -o ./extension/build/style.css --watch", "package:firefox": "bunx tailwindcss -i ./extension/style.css -o ./extension/output/style.css --minify; ./build.js prod firefox; cd extension/output; zip -r archive *; cd ../../; mv extension/output/archive.zip extension/releases/nostrconnect_firefox.xpi",
"build": "pnpm exec tailwindcss -i ./extension/style.css -o ./extension/build/style.css; ./build.js prod", "lint": "biome lint ./extension/background.js ./extension/common.js ./extension/nostr-provider.js ./extension/content-script.js ./extension/popup.jsx ./extension/prompt.jsx ./extension/options.jsx ./extension/icons.jsx ./extension/utils.js",
"package": "./build.js prod; cd extension; zip -r archive *; cd ..; mv extension/archive.zip ./nostrconnect.zip" "format": "biome format --write ./extension/background.js ./extension/common.js ./extension/nostr-provider.js ./extension/content-script.js ./extension/popup.jsx ./extension/prompt.jsx ./extension/options.jsx ./extension/icons.jsx ./extension/utils.js",
}, "test": "vitest run",
"devDependencies": { "test:watch": "vitest",
"tailwindcss": "^3.3.5" "test:coverage": "vitest run --coverage"
} },
"devDependencies": {
"@biomejs/biome": "^2.4.10",
"@vitejs/plugin-react": "^6.0.1",
"esbuild-plugin-copy": "^2.1.1",
"jsdom": "^29.0.2",
"tailwindcss": "^3.4.19",
"vitest": "^4.1.3"
}
} }

10307
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

2
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,2 @@
allowBuilds:
esbuild: false

14
vitest.config.js Normal file
View File

@@ -0,0 +1,14 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['extension/**/*.test.{js,jsx}'],
coverage: {
reporter: ['text', 'json', 'html'],
include: ['extension/**/*.js'],
exclude: ['extension/output/**', 'extension/**/*.test.js']
}
}
})