Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz authored May 6, 2024
2 parents b448216 + 76ec91e commit eb3165f
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 135 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@noble/curves": "^1.4.0",
"@noble/hashes": "^1.4.0",
"@noble/secp256k1": "^2.0.0",
"@popicons/react": "^0.0.9",
"@popicons/react": "^0.0.11",
"@scure/base": "^1.1.6",
"@scure/bip32": "^1.3.3",
"@scure/bip39": "^1.2.2",
Expand All @@ -55,7 +55,7 @@
"bolt11-signet": "1.4.1",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.10",
"dexie": "^3.2.6",
"dexie": "^3.2.7",
"elliptic": "^6.5.4",
"events": "^3.3.0",
"html5-qrcode": "^2.3.8",
Expand All @@ -75,10 +75,10 @@
"react-loading-skeleton": "^3.3.1",
"react-modal": "^3.16.1",
"react-qr-code": "^2.0.12",
"react-router-dom": "^6.22.2",
"react-router-dom": "^6.22.3",
"slip77": "^0.2.0",
"stream": "^0.0.2",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.3",
"uuid": "^9.0.1",
"webextension-polyfill": "^0.10.0",
"zustand": "^4.5.2"
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/AccountMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
PopiconsChevronBottomLine,
PopiconsCirclePlusLine,
PopiconsGlobeLine,
PopiconsWalletLine,
} from "@popicons/react";
import { useEffect } from "react";
Expand All @@ -14,7 +15,6 @@ import { useAccounts } from "~/app/context/AccountsContext";
import { isAlbyLNDHubAccount, isAlbyOAuthAccount } from "~/app/utils";
import utils from "~/common/lib/utils";

import PopiconsGlobeLine from "~/app/icons/popicons/GlobeLine";
import Menu from "../Menu";

export type Props = {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function Badge({
return (
<div
className={classNames(
"inline-flex items-center leading-none rounded-full font-medium mr-2 py-1 pr-2 pl-3 mb-2 text-xs cursor-default",
"inline-flex items-center leading-none rounded-full font-medium py-1.5 px-2 text-xs cursor-default",
className
)}
title={description}
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/BadgesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export default function BadgesList({ allowance }: Props) {
if (allowance.remainingBudget > 0) {
badges.push({
label: "budget",
className: "bg-blue-500 text-white",
className: "bg-blue-500 text-white mr-2",
});
}
if (allowance.lnurlAuth) {
badges.push({
label: "auth",
className: "bg-green-bitcoin text-white",
className: "bg-green-bitcoin text-white mr-2",
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/components/SitePreferences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) {
)
);
}}
className="bg-green-50 dark:bg-emerald-950 border border-green-100 dark:border-emerald-900 text-gray-800 dark:text-neutral-200 gap-1"
className="bg-green-50 dark:bg-emerald-950 border border-green-100 dark:border-emerald-900 text-gray-800 dark:text-neutral-200 mr-2 mb-2"
/>
</>
))}
Expand Down Expand Up @@ -319,7 +319,7 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) {
)
);
}}
className="bg-red-50 dark:bg-red-950 border border-red-100 dark:border-red-900 text-gray-800 dark:text-neutral-200 gap-1"
className="bg-red-50 dark:bg-red-950 border border-red-100 dark:border-red-900 text-gray-800 dark:text-neutral-200 mr-2 mb-2"
/>
</>
))}
Expand Down
27 changes: 0 additions & 27 deletions src/app/icons/popicons/BitcoinCircleLine.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions src/app/icons/popicons/GlobeLine.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/screens/Nostr/ConfirmDecrypt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function NostrConfirmDecrypt() {
<p className="mb-2">{t("allow", { host: origin.host })}</p>
<p className="dark:text-white">
<PopiconsCheckLine className="w-5 h-5 mr-2 inline" />
{tPermissions("nostr.decrypt")}
{tPermissions("nostr.decrypt.title")}
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const decryptOrPrompt = async (message: MessageDecryptGet, sender: Sender) => {

try {
const hasPermission = await hasPermissionFor(
PermissionMethodNostr["NOSTR_NIP04DECRYPT"],
PermissionMethodNostr["NOSTR_DECRYPT"],
host
);

Expand All @@ -39,7 +39,7 @@ const decryptOrPrompt = async (message: MessageDecryptGet, sender: Sender) => {
// add permission to db only if user decided to always allow this request
if (promptResponse.data.rememberPermission) {
await addPermissionFor(
PermissionMethodNostr["NOSTR_NIP04DECRYPT"],
PermissionMethodNostr["NOSTR_DECRYPT"],
host,
promptResponse.data.blocked
);
Expand Down
6 changes: 2 additions & 4 deletions src/extension/background-script/actions/nostr/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ const enable = async (message: MessageAllowanceEnable, sender: Sender) => {
// Add permissions
const permissions: PermissionMethodNostr[] = [
PermissionMethodNostr.NOSTR_GETPUBLICKEY,
PermissionMethodNostr.NOSTR_NIP04ENCRYPT,
PermissionMethodNostr.NOSTR_NIP04DECRYPT,
PermissionMethodNostr.NOSTR_NIP44ENCRYPT,
PermissionMethodNostr.NOSTR_NIP44DECRYPT,
PermissionMethodNostr.NOSTR_ENCRYPT,
PermissionMethodNostr.NOSTR_DECRYPT,
];
permissions.forEach(async (permission) => {
await addPermissionFor(permission, host, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const encryptOrPrompt = async (message: MessageEncryptGet, sender: Sender) => {

try {
const hasPermission = await hasPermissionFor(
PermissionMethodNostr["NOSTR_NIP04ENCRYPT"],
PermissionMethodNostr["NOSTR_ENCRYPT"],
host
);

Expand Down Expand Up @@ -45,7 +45,7 @@ const encryptOrPrompt = async (message: MessageEncryptGet, sender: Sender) => {
// add permission to db only if user decided to always allow this request
if (promptResponse.data.rememberPermission) {
await addPermissionFor(
PermissionMethodNostr["NOSTR_NIP04ENCRYPT"],
PermissionMethodNostr["NOSTR_ENCRYPT"],
host,
promptResponse.data.blocked
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const nip44DecryptOrPrompt = async (

try {
const hasPermission = await hasPermissionFor(
PermissionMethodNostr["NOSTR_NIP44DECRYPT"],
PermissionMethodNostr["NOSTR_DECRYPT"],
host
);

Expand All @@ -42,7 +42,7 @@ const nip44DecryptOrPrompt = async (
// add permission to db only if user decided to always allow this request
if (promptResponse.data.rememberPermission) {
await addPermissionFor(
PermissionMethodNostr["NOSTR_NIP44DECRYPT"],
PermissionMethodNostr["NOSTR_DECRYPT"],
host,
promptResponse.data.blocked
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const nip44EncryptOrPrompt = async (

try {
const hasPermission = await hasPermissionFor(
PermissionMethodNostr["NOSTR_NIP44ENCRYPT"],
PermissionMethodNostr["NOSTR_ENCRYPT"],
host
);

Expand Down Expand Up @@ -47,7 +47,7 @@ const nip44EncryptOrPrompt = async (
// add permission to db only if user decided to always allow this request
if (promptResponse.data.rememberPermission) {
await addPermissionFor(
PermissionMethodNostr["NOSTR_NIP44ENCRYPT"],
PermissionMethodNostr["NOSTR_ENCRYPT"],
host,
promptResponse.data.blocked
);
Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/connectors/lndhub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default class LndHub implements Connector {
(transaction, index): ConnectorTransaction => ({
id: `${index}`,
memo: transaction.memo,
custom_records: transaction.custom_records,
preimage: transaction.payment_preimage,
payment_hash: Buffer.from(transaction.payment_hash.data).toString(
"hex"
Expand Down
84 changes: 78 additions & 6 deletions src/extension/background-script/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// import db from "../db";
// import state from "../state";
import db from "../db";
import state from "../state";

export type Migration = keyof typeof migrations;

/*
// TS does not want unused code.
// we need this for the next migration again

Expand All @@ -30,9 +28,71 @@ const setMigrated = (name: Migration): Promise<void> => {
return state.getState().saveToStorage();
};

*/
const migrations = {
migrateEncryptPermission: async () => {
const allowances = await db.allowances.toArray();

for (const allowance of allowances) {
const permissions = await db.permissions
.where({ allowanceId: allowance.id })
.toArray();

let isupdated = false;

for (const permission of permissions) {
if (
permission.method === "nostr/nip04encrypt" ||
permission.method === "nostr/nip44encrypt"
) {
if (isupdated === false) {
permission.id &&
(await db.permissions.update(permission.id, {
method: "nostr/encrypt",
}));

isupdated = true;
} else {
permission.id && (await db.permissions.delete(permission.id));
}
}
}
}

console.info("Migration migrateEncryptPermission complete.");
},

migrateDecryptPermission: async () => {
const allowances = await db.allowances.toArray();

for (const allowance of allowances) {
const permissions = await db.permissions
.where({ allowanceId: allowance.id })
.toArray();

const migrations = {};
let isupdated = false;

for (const permission of permissions) {
if (
permission.method === "nostr/nip04decrypt" ||
permission.method === "nostr/nip44decrypt"
) {
if (isupdated === false) {
permission.id &&
(await db.permissions.update(permission.id, {
method: "nostr/decrypt",
}));

isupdated = true;
} else {
permission.id && (await db.permissions.delete(permission.id));
}
}
}
}

console.info("Migration migrateDecryptPermission complete.");
},
};

const migrate = async () => {
// going forward we can iterate through the the migrations object above and DRY this up:
Expand All @@ -43,6 +103,18 @@ const migrate = async () => {
// await migrations["migratePermissionsWithoutAccountId"]();
// await setMigrated("migratePermissionsWithoutAccountId");
//}

if (shouldMigrate("migrateEncryptPermission")) {
console.info("Running migration for: migrateEncryptPermission");
await migrations["migrateEncryptPermission"]();
await setMigrated("migrateEncryptPermission");
}

if (shouldMigrate("migrateDecryptPermission")) {
console.info("Running migration for: migrateDecryptPermission");
await migrations["migrateDecryptPermission"]();
await setMigrated("migrateDecryptPermission");
}
};

export default migrate;
7 changes: 5 additions & 2 deletions src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,8 @@
"edit_allowance": {
"title": "Seiten Einstellung",
"screen_reader": "Zulässigkeitsoptionen",
"always_allow": "Immer erlauben"
"always_allow": "Immer erlauben",
"always_reject": "Immer ablehnen"
},
"enable_login": {
"title": "Anmeldung auf der Webseite aktivieren",
Expand Down Expand Up @@ -1211,7 +1212,9 @@
"disconnect": "Verbindung trennen",
"copied_to_clipboard": "In die Zwischenablage kopiert",
"hide": "Ausblenden",
"finish": "Oberfläche"
"finish": "Oberfläche",
"deny": "Verweigern",
"sign": "Unterschrift"
},
"discover": "Apps entdecken",
"errors": {
Expand Down
18 changes: 5 additions & 13 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1290,23 +1290,15 @@
"title": "read public key",
"description": "Read your public key"
},
"decrypt": "Decrypt data",
"nip04decrypt": {
"title": "decrypt (nip04)",
"decrypt": {
"title": "decrypt",
"description": "Decrypt data"
},
"nip04encrypt": {
"title": "encrypt (nip04)",
"description": "Encrypt data"
},
"nip44decrypt": {
"title": "decrypt (nip44)",
"description": "Decrypt data"
},
"nip44encrypt": {
"title": "encrypt (nip44)",
"encrypt": {
"title": "encrypt",
"description": "Encrypt data"
},

"signmessage": {
"title": "Sign Message",
"description": "Sign all nostr events"
Expand Down
Loading

0 comments on commit eb3165f

Please sign in to comment.