ConnectSigner: make getPublicKey used the stored value instead of actually hitting the relay

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

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file require-await
import { NConnectSigner } from '@nostrify/nostrify';
import { AdminSigner } from '@/signers/AdminSigner.ts';
@ -9,18 +10,26 @@ import { Storages } from '@/storages.ts';
* Simple extension of nostrify's `NConnectSigner`, with our options to keep it DRY.
*/
export class ConnectSigner extends NConnectSigner {
private _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
// 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,
});
this._pubkey = pubkey;
}
// Prevent unnecessary NIP-46 round-trips.
async getPublicKey(): Promise<string> {
return this._pubkey;
}
/** 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 };