Skip to content

Commit ba4b767

Browse files
committed
v7.9.38
1 parent 935bafc commit ba4b767

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nosflare",
3-
"version": "7.9.37",
3+
"version": "7.9.38",
44
"main": "worker.js",
55
"type": "module",
66
"scripts": {

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const PAY_TO_RELAY_ENABLED = true; // Set to false to disable pay to rela
1212
export const RELAY_ACCESS_PRICE_SATS = 212121; // Price in SATS for relay access
1313

1414
// NIP-42 Authentication
15-
export const AUTH_REQUIRED = false; // Set to false to disable NIP-42 authentication requirement
15+
export const AUTH_REQUIRED = true; // Set to false to disable NIP-42 authentication requirement
1616
export const AUTH_TIMEOUT_MS = 600000; // 10 minutes - how long the challenge is valid
1717

1818
// Relay info
@@ -23,7 +23,7 @@ export const relayInfo: RelayInfo = {
2323
contact: "lux@fed.wtf",
2424
supported_nips: [1, 2, 4, 5, 9, 11, 12, 15, 16, 17, 20, 22, 33, 40, 42],
2525
software: "https://github.com/Spl0itable/nosflare",
26-
version: "7.9.37",
26+
version: "7.9.38",
2727
icon: "https://raw.githubusercontent.com/Spl0itable/nosflare/main/images/flare.png",
2828

2929
// Optional fields (uncomment as needed):

src/durable-object.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,21 @@ export class RelayWebSocket implements DurableObject {
778778
return;
779779
}
780780

781-
// NIP-42: Check if the event's pubkey is authenticated
782-
if (AUTH_REQUIRED && !session.authenticatedPubkeys.has(event.pubkey)) {
783-
this.sendOK(session.webSocket, event.id, false, 'auth-required: authenticate to publish events');
784-
return;
781+
// NIP-42: Check authentication
782+
if (AUTH_REQUIRED) {
783+
if (session.authenticatedPubkeys.size === 0) {
784+
// Not authenticated at all
785+
this.sendOK(session.webSocket, event.id, false, 'auth-required: authenticate to publish events');
786+
return;
787+
}
788+
// Kind 1059 (gift wrap / NIP-59) uses throwaway pubkeys, so only require
789+
// connection-level auth, not per-pubkey auth
790+
if (event.kind !== 1059 && !session.authenticatedPubkeys.has(event.pubkey)) {
791+
// Authenticated but event pubkey doesn't match - use "restricted:" per NIP-42
792+
// so the client knows not to retry auth
793+
this.sendOK(session.webSocket, event.id, false, 'restricted: event pubkey does not match authenticated pubkey');
794+
return;
795+
}
785796
}
786797

787798
// Rate limiting (skip for excluded kinds)
@@ -802,7 +813,8 @@ export class RelayWebSocket implements DurableObject {
802813
}
803814

804815
// Check if pay to relay is enabled (payment status cached on session at AUTH time)
805-
if (PAY_TO_RELAY_ENABLED) {
816+
// Skip for kind 1059 (gift wrap) since the pubkey is a throwaway key with no payment record
817+
if (PAY_TO_RELAY_ENABLED && event.kind !== 1059) {
806818
if (session.hasPaid === false) {
807819
const protocol = 'https:';
808820
const relayUrl = `${protocol}//${session.host}`;

worker.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __export(config_exports, {
7373
var relayNpub = "npub16jdfqgazrkapk0yrqm9rdxlnys7ck39c7zmdzxtxqlmmpxg04r0sd733sv";
7474
var PAY_TO_RELAY_ENABLED = true;
7575
var RELAY_ACCESS_PRICE_SATS = 212121;
76-
var AUTH_REQUIRED = false;
76+
var AUTH_REQUIRED = true;
7777
var AUTH_TIMEOUT_MS = 6e5;
7878
var relayInfo = {
7979
name: "Nosflare",
@@ -82,7 +82,7 @@ var relayInfo = {
8282
contact: "lux@fed.wtf",
8383
supported_nips: [1, 2, 4, 5, 9, 11, 12, 15, 16, 17, 20, 22, 33, 40, 42],
8484
software: "https://github.com/Spl0itable/nosflare",
85-
version: "7.9.37",
85+
version: "7.9.38",
8686
icon: "https://raw.githubusercontent.com/Spl0itable/nosflare/main/images/flare.png",
8787
// Optional fields (uncomment as needed):
8888
// banner: "https://example.com/banner.jpg",
@@ -4974,9 +4974,15 @@ var _RelayWebSocket = class _RelayWebSocket {
49744974
this.sendOK(session.webSocket, event.id, false, "invalid: kind 22242 events are for authentication only");
49754975
return;
49764976
}
4977-
if (AUTH_REQUIRED && !session.authenticatedPubkeys.has(event.pubkey)) {
4978-
this.sendOK(session.webSocket, event.id, false, "auth-required: authenticate to publish events");
4979-
return;
4977+
if (AUTH_REQUIRED) {
4978+
if (session.authenticatedPubkeys.size === 0) {
4979+
this.sendOK(session.webSocket, event.id, false, "auth-required: authenticate to publish events");
4980+
return;
4981+
}
4982+
if (event.kind !== 1059 && !session.authenticatedPubkeys.has(event.pubkey)) {
4983+
this.sendOK(session.webSocket, event.id, false, "restricted: event pubkey does not match authenticated pubkey");
4984+
return;
4985+
}
49804986
}
49814987
if (!excludedRateLimitKinds.has(event.kind)) {
49824988
if (!session.pubkeyRateLimiter.removeToken()) {
@@ -4991,7 +4997,7 @@ var _RelayWebSocket = class _RelayWebSocket {
49914997
this.sendOK(session.webSocket, event.id, false, "invalid: signature verification failed");
49924998
return;
49934999
}
4994-
if (PAY_TO_RELAY_ENABLED) {
5000+
if (PAY_TO_RELAY_ENABLED && event.kind !== 1059) {
49955001
if (session.hasPaid === false) {
49965002
const protocol = "https:";
49975003
const relayUrl = `${protocol}//${session.host}`;

0 commit comments

Comments
 (0)