ConnectSigner: implement getRelays, support nprofile auth again
This commit is contained in:
parent
084143c5c8
commit
03182f8a5a
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
}, {}) ?? {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue