From 03182f8a5a260447173c0e40d9f6c388002ffabd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 12:14:27 -0500 Subject: [PATCH] ConnectSigner: implement getRelays, support nprofile auth again --- src/middleware/signerMiddleware.ts | 3 +++ src/signers/ConnectSigner.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/middleware/signerMiddleware.ts b/src/middleware/signerMiddleware.ts index 85a2ff1..8779937 100644 --- a/src/middleware/signerMiddleware.ts +++ b/src/middleware/signerMiddleware.ts @@ -22,6 +22,9 @@ export const signerMiddleware: AppMiddleware = async (c, next) => { case 'npub': c.set('signer', new ConnectSigner(decoded.data)); break; + case 'nprofile': + c.set('signer', new ConnectSigner(decoded.data.pubkey, decoded.data.relays)); + break; case 'nsec': c.set('signer', new NSecSigner(decoded.data)); break; diff --git a/src/signers/ConnectSigner.ts b/src/signers/ConnectSigner.ts index b98a59f..e7d61a8 100644 --- a/src/signers/ConnectSigner.ts +++ b/src/signers/ConnectSigner.ts @@ -9,12 +9,22 @@ import { Storages } from '@/storages.ts'; * Simple extension of nostrify's `NConnectSigner`, with our options to keep it DRY. */ export class ConnectSigner extends NConnectSigner { - constructor(pubkey: string) { + constructor(pubkey: string, private relays?: string[]) { super({ pubkey, + // TODO: use a remote relay for `nprofile` signing, if present and Conf.relay isn't already in the list relay: Storages.pubsub, signer: new AdminSigner(), timeout: 60000, }); } + + /** Get the user's relays if they passed in an `nprofile` auth token. */ + // deno-lint-ignore require-await + async getRelays(): Promise> { + return this.relays?.reduce>((acc, relay) => { + acc[relay] = { read: true, write: true }; + return acc; + }, {}) ?? {}; + } }