Add weblock package
This commit is contained in:
parent
a72e9c1c04
commit
44411fdf29
4 changed files with 8 additions and 18 deletions
|
@ -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",
|
||||
|
|
|
@ -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<string, NostrSigner> {
|
|||
this.#storageKey = storageKey;
|
||||
|
||||
const data = this.#storage.getItem(storageKey);
|
||||
lockStorageKey(storageKey);
|
||||
WebLock.storages.lockKey(storageKey);
|
||||
|
||||
try {
|
||||
const nsecs = new Set(this.#dataSchema().parse(data));
|
||||
|
|
|
@ -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 };
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue