mirror of
https://github.com/nostr-connect/connect.git
synced 2026-02-23 13:14:21 +01:00
add events and wrap NostrRPC as NostrSigner
This commit is contained in:
@@ -72,7 +72,7 @@ export class ConnectURI {
|
||||
params: [getPublicKey(secretKey)],
|
||||
},
|
||||
},
|
||||
{ skipResponse: true }
|
||||
{ skipResponse: false }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './connect';
|
||||
export * from './rpc';
|
||||
export * from './nostr';
|
||||
|
||||
23
src/nostr.ts
Normal file
23
src/nostr.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user