ConnectSigner: implement getRelays, support nprofile auth again

This commit is contained in:
Alex Gleason 2024-05-14 12:14:27 -05:00
parent 084143c5c8
commit 03182f8a5a
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,9 @@ export const signerMiddleware: AppMiddleware = async (c, next) => {
case 'npub': case 'npub':
c.set('signer', new ConnectSigner(decoded.data)); c.set('signer', new ConnectSigner(decoded.data));
break; break;
case 'nprofile':
c.set('signer', new ConnectSigner(decoded.data.pubkey, decoded.data.relays));
break;
case 'nsec': case 'nsec':
c.set('signer', new NSecSigner(decoded.data)); c.set('signer', new NSecSigner(decoded.data));
break; break;

View File

@ -9,12 +9,22 @@ import { Storages } from '@/storages.ts';
* Simple extension of nostrify's `NConnectSigner`, with our options to keep it DRY. * Simple extension of nostrify's `NConnectSigner`, with our options to keep it DRY.
*/ */
export class ConnectSigner extends NConnectSigner { export class ConnectSigner extends NConnectSigner {
constructor(pubkey: string) { constructor(pubkey: string, private relays?: string[]) {
super({ super({
pubkey, pubkey,
// TODO: use a remote relay for `nprofile` signing, if present and Conf.relay isn't already in the list
relay: Storages.pubsub, relay: Storages.pubsub,
signer: new AdminSigner(), signer: new AdminSigner(),
timeout: 60000, timeout: 60000,
}); });
} }
/** Get the user's relays if they passed in an `nprofile` auth token. */
// deno-lint-ignore require-await
async getRelays(): Promise<Record<string, { read: boolean; write: boolean }>> {
return this.relays?.reduce<Record<string, { read: boolean; write: boolean }>>((acc, relay) => {
acc[relay] = { read: true, write: true };
return acc;
}, {}) ?? {};
}
} }