Skip to content

Commit

Permalink
update nip42 relays to pass test
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Feb 15, 2024
1 parent 43b4fd8 commit 5897e1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
7 changes: 0 additions & 7 deletions nips/42/protocol.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "../../core/protocol.d.ts";
import "../../core/relays.ts";
import type { Signer } from "../../lib/signs.ts";

declare module "../../core/protocol.d.ts" {
interface NipRecord {
Expand Down Expand Up @@ -29,9 +28,3 @@ declare module "../../core/protocol.d.ts" {
"challenge": [string];
}
}

declare module "../../core/relays.ts" {
interface RelayConfig {
signer?: Signer;
}
}
20 changes: 14 additions & 6 deletions nips/42/relays.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { Stringified } from "../../core/types.ts";
import type { RelayModule } from "../../core/relays.ts";
import type { EventInit } from "../../lib/events.ts";
import type { Signer } from "../../lib/signs.ts";
import "./protocol.d.ts";

export default {
handleRelayToClientMessage({ message, relay }) {
const type = message[0];
if (type !== "AUTH") {
declare module "../../core/relays.ts" {
interface RelayConfig {
signer?: Signer;
}
}

const install: RelayModule["default"] = (relay) => {
relay.addEventListener("message", ({ data: message }) => {
if (message[0] !== "AUTH") {
// This NIP only handles AUTH messages
return;
}
Expand All @@ -23,5 +29,7 @@ export default {
content: "" as Stringified<"">,
};
return relay.publish(relay.config.signer.sign(event));
},
} satisfies RelayModule["default"];
});
};

export default install;

0 comments on commit 5897e1b

Please sign in to comment.