NKeyStorage: fix schema parser

This commit is contained in:
Alex Gleason 2024-02-19 15:13:10 -06:00
parent 623fb234b3
commit 0a3eb6b187
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,5 @@
import { getPublicKey, nip19 } from 'nostr-tools'; import { getPublicKey, nip19 } from 'nostr-tools';
import { NSchema as n, NostrSigner, NSecSigner } from 'nspec'; import { NSchema as n, NostrSigner, NSecSigner } from 'nspec';
import { z } from 'zod';
import { lockStorageKey } from 'soapbox/utils/storage'; import { lockStorageKey } from 'soapbox/utils/storage';
@ -23,7 +22,9 @@ export class NKeyStorage implements ReadonlyMap<string, NostrSigner> {
lockStorageKey(storageKey); lockStorageKey(storageKey);
try { try {
for (const nsec of this.#dataSchema().parse(data)) { const nsecs = new Set(this.#dataSchema().parse(data));
for (const nsec of nsecs) {
const { data: secretKey } = nip19.decode(nsec); const { data: secretKey } = nip19.decode(nsec);
const pubkey = getPublicKey(secretKey); const pubkey = getPublicKey(secretKey);
this.#keypairs.set(pubkey, secretKey); this.#keypairs.set(pubkey, secretKey);
@ -34,7 +35,7 @@ export class NKeyStorage implements ReadonlyMap<string, NostrSigner> {
} }
#dataSchema() { #dataSchema() {
return n.json().pipe(z.set(n.bech32('nsec'))); return n.json().pipe(n.bech32('nsec').array());
} }
#syncStorage() { #syncStorage() {