diff --git a/package.json b/package.json index 5a7e6bca4..5fdca8015 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@sentry/react": "^7.74.1", "@soapbox.pub/wasmboy": "^0.8.0", "@soapbox/nspec": "npm:@jsr/soapbox__nspec", + "@soapbox/weblock": "npm:@jsr/soapbox__weblock", "@tabler/icons": "^2.0.0", "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/forms": "^0.5.7", diff --git a/src/features/nostr/NKeyStorage.ts b/src/features/nostr/NKeyStorage.ts index d5ed117b9..e297edb96 100644 --- a/src/features/nostr/NKeyStorage.ts +++ b/src/features/nostr/NKeyStorage.ts @@ -1,9 +1,8 @@ import { NSchema as n, NostrSigner, NSecSigner } from '@soapbox/nspec'; +import { WebLock } from '@soapbox/weblock'; import { getPublicKey, nip19 } from 'nostr-tools'; import { z } from 'zod'; -import { lockStorageKey } from 'soapbox/utils/storage'; - /** * Gets Nostr keypairs from storage and returns a `Map`-like object of signers. * When instantiated, it will lock the storage key to prevent tampering. @@ -20,7 +19,7 @@ export class NKeyStorage implements ReadonlyMap { this.#storageKey = storageKey; const data = this.#storage.getItem(storageKey); - lockStorageKey(storageKey); + WebLock.storages.lockKey(storageKey); try { const nsecs = new Set(this.#dataSchema().parse(data)); diff --git a/src/utils/storage.ts b/src/utils/storage.ts deleted file mode 100644 index a269b1504..000000000 --- a/src/utils/storage.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** Lock a key from being accessed by `localStorage` and `sessionStorage`. */ -function lockStorageKey(key: string): void { - const proto = Object.getPrototypeOf(localStorage ?? sessionStorage); - const _getItem = proto.getItem; - - proto.getItem = function(_key: string) { - if (_key === key) { - throw new Error(`${_key} is locked`); - } else { - return _getItem.bind(this)(_key); - } - }; -} - -export { lockStorageKey }; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index efe92922f..8a450c10b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2277,6 +2277,11 @@ websocket-ts "^2.1.5" zod "^3.22.4" +"@soapbox/weblock@npm:@jsr/soapbox__weblock": + version "0.1.0" + resolved "https://npm.jsr.io/~/7/@jsr/soapbox__weblock/0.1.0.tgz#749AEE0872D23CC4E37366D5F0D092B87986C5E1" + integrity sha512-FLLJL6xYk+k7f2bMXJ1nbcn3lhbEZXA0yboKLm8wns0hrcoEDOrWwmxkYF7xpVRndiAzFBctBGVbIAa3sA72ew== + "@surma/rollup-plugin-off-main-thread@^2.2.3": version "2.2.3" resolved "https://registry.yarnpkg.com/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz#ee34985952ca21558ab0d952f00298ad2190c053"