add events and wrap NostrRPC as NostrSigner

This commit is contained in:
tiero
2023-01-14 03:10:54 +01:00
parent 52f6b6ced8
commit aa74344030
6 changed files with 196 additions and 6 deletions

View File

@@ -72,7 +72,7 @@ export class ConnectURI {
params: [getPublicKey(secretKey)],
},
},
{ skipResponse: true }
{ skipResponse: false }
);
}

View File

@@ -1,2 +1,3 @@
export * from './connect';
export * from './rpc';
export * from './nostr';

23
src/nostr.ts Normal file
View File

@@ -0,0 +1,23 @@
import { NostrRPC } from './rpc';
export class NostrSigner extends NostrRPC {
connectedAppIDs: string[];
constructor(opts: { relay?: string | undefined; secretKey: string }) {
super(opts);
this.connectedAppIDs = [];
}
addConnectedApp = (pubkey: string) => {
this.connectedAppIDs.push(pubkey);
};
removeConnectedApp = (pubkey: string) => {
this.connectedAppIDs = this.connectedAppIDs.filter(
(id: string) => id !== pubkey
);
};
isConnected(pubkey: string): boolean {
return this.connectedAppIDs.includes(pubkey);
}
}

View File

@@ -1,3 +1,4 @@
import EventEmitter from 'events';
import {
Event,
Filter,
@@ -29,6 +30,8 @@ export class NostrRPC {
event: Event | undefined;
// this is for implementing the response handlers for each method
[key: string]: any;
// events
events = new EventEmitter();
constructor(opts: { relay?: string; secretKey: string }) {
this.relay = opts.relay || 'wss://nostr.vulpem.com';