fix build for macos
This commit is contained in:
8437
extension/output/background.build.js
Normal file
8437
extension/output/background.build.js
Normal file
File diff suppressed because it is too large
Load Diff
116
extension/output/common.js
Normal file
116
extension/output/common.js
Normal file
@@ -0,0 +1,116 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const NO_PERMISSIONS_REQUIRED = {
|
||||
replaceURL: true
|
||||
}
|
||||
|
||||
export const PERMISSION_NAMES = Object.fromEntries([
|
||||
['getPublicKey', 'read your public key'],
|
||||
['getRelays', 'read your list of preferred relays'],
|
||||
['signEvent', 'sign events using your private key'],
|
||||
['nip04.encrypt', 'encrypt messages to peers'],
|
||||
['nip04.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) {
|
||||
let {policies} = await browser.storage.local.get('policies')
|
||||
|
||||
let answers = [true, false]
|
||||
for (let i = 0; i < answers.length; i++) {
|
||||
let accept = answers[i]
|
||||
let {conditions} = policies?.[host]?.[accept]?.[type] || {}
|
||||
|
||||
if (conditions) {
|
||||
if (type === 'signEvent') {
|
||||
if (matchConditions(conditions, event)) {
|
||||
return accept // may be true or false
|
||||
} 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 {
|
||||
return accept // may be true or false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
export async function updatePermission(host, type, accept, conditions) {
|
||||
let {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
|
||||
let 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
|
||||
let other = !accept
|
||||
let 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) {
|
||||
let {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) {
|
||||
let ok = await browser.storage.local.get('notifications')
|
||||
if (ok) {
|
||||
let 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'
|
||||
})
|
||||
}
|
||||
}
|
||||
1056
extension/output/content-script.build.js
Normal file
1056
extension/output/content-script.build.js
Normal file
File diff suppressed because it is too large
Load Diff
36
extension/output/manifest.json
Normal file
36
extension/output/manifest.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "Nostr Connect",
|
||||
"description": "Nostr Signer Extension",
|
||||
"version": "0.1.1",
|
||||
"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:*/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
114
extension/output/nostr-provider.js
Normal file
114
extension/output/nostr-provider.js
Normal file
@@ -0,0 +1,114 @@
|
||||
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 signEvent(event) {
|
||||
return this._call('signEvent', {event})
|
||||
},
|
||||
|
||||
async getRelays() {
|
||||
return this._call('getRelays', {})
|
||||
},
|
||||
|
||||
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})
|
||||
}
|
||||
},
|
||||
|
||||
_call(type, params) {
|
||||
let 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) {
|
||||
let 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
|
||||
|
||||
let response = await window.nostr._call('replaceURL', {url: e.target.href})
|
||||
if (response === false) {
|
||||
replacing = false
|
||||
return
|
||||
}
|
||||
|
||||
e.target.href = response
|
||||
}
|
||||
32218
extension/output/options.build.js
Normal file
32218
extension/output/options.build.js
Normal file
File diff suppressed because it is too large
Load Diff
13
extension/output/options.html
Normal file
13
extension/output/options.html
Normal 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>
|
||||
31643
extension/output/popup.build.js
Normal file
31643
extension/output/popup.build.js
Normal file
File diff suppressed because it is too large
Load Diff
13
extension/output/popup.html
Normal file
13
extension/output/popup.html
Normal 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>
|
||||
22481
extension/output/prompt.build.js
Normal file
22481
extension/output/prompt.build.js
Normal file
File diff suppressed because it is too large
Load Diff
13
extension/output/prompt.html
Normal file
13
extension/output/prompt.html
Normal 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>
|
||||
1
extension/output/style.css
Normal file
1
extension/output/style.css
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user