mirror of
https://github.com/kind-0/nsecbunkerd.git
synced 2026-05-03 07:00:11 +00:00
updates
This commit is contained in:
parent
919315bbf7
commit
ff5387b778
@ -39,7 +39,7 @@
|
|||||||
"@fastify/view": "^8.2.0",
|
"@fastify/view": "^8.2.0",
|
||||||
"@inquirer/password": "^1.1.2",
|
"@inquirer/password": "^1.1.2",
|
||||||
"@inquirer/prompts": "^1.2.3",
|
"@inquirer/prompts": "^1.2.3",
|
||||||
"@nostr-dev-kit/ndk": "^2.8.1",
|
"@nostr-dev-kit/ndk": "workspace:*",
|
||||||
"@prisma/client": "^5.4.1",
|
"@prisma/client": "^5.4.1",
|
||||||
"@scure/base": "^1.1.1",
|
"@scure/base": "^1.1.1",
|
||||||
"@types/yargs": "^17.0.24",
|
"@types/yargs": "^17.0.24",
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import "websocket-polyfill";
|
import "websocket-polyfill";
|
||||||
import NDK, { NDKKind, NDKPrivateKeySigner, NDKRpcRequest, NDKRpcResponse, NDKUser } from '@nostr-dev-kit/ndk';
|
import NDK, { NDKEvent, NDKKind, NDKPrivateKeySigner, NDKRpcRequest, NDKRpcResponse, NDKUser, NostrEvent } from '@nostr-dev-kit/ndk';
|
||||||
import { NDKNostrRpc } from '@nostr-dev-kit/ndk';
|
import { NDKNostrRpc } from '@nostr-dev-kit/ndk';
|
||||||
import createDebug from 'debug';
|
import createDebug from 'debug';
|
||||||
import { Key, KeyUser } from '../run';
|
import { Key, KeyUser } from '../run';
|
||||||
@ -121,6 +121,8 @@ class AdminInterface {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.rpc.on('request', (req) => this.handleRequest(req));
|
this.rpc.on('request', (req) => this.handleRequest(req));
|
||||||
|
|
||||||
|
pingOrDie(this.ndk);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log('❌ admin connection failed');
|
console.log('❌ admin connection failed');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -393,4 +395,44 @@ class AdminInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function pingOrDie(ndk: NDK) {
|
||||||
|
let deathTimer: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
function resetDeath() {
|
||||||
|
if (deathTimer) clearTimeout(deathTimer);
|
||||||
|
deathTimer = setTimeout(() => {
|
||||||
|
console.log(`❌ No ping event received in 30 seconds. Exiting.`);
|
||||||
|
process.exit(1);
|
||||||
|
}, 50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
const self = await ndk.signer!.user();
|
||||||
|
const sub = ndk.subscribe({
|
||||||
|
authors: [self.pubkey],
|
||||||
|
kinds: [NDKKind.NostrConnect],
|
||||||
|
"#p": [self.pubkey]
|
||||||
|
});
|
||||||
|
sub.on("event", (event: NDKEvent) => {
|
||||||
|
console.log(`🔔 Received ping event:`, event.created_at);
|
||||||
|
resetDeath();
|
||||||
|
});
|
||||||
|
sub.start();
|
||||||
|
|
||||||
|
resetDeath();
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
const event = new NDKEvent(ndk, {
|
||||||
|
kind: NDKKind.NostrConnect,
|
||||||
|
tags: [ ["p", self.pubkey] ],
|
||||||
|
content: "ping"
|
||||||
|
} as NostrEvent);
|
||||||
|
event.publish().then(() => {
|
||||||
|
console.log(`🔔 Sent ping event:`, event.created_at);
|
||||||
|
}).catch((e: any) => {
|
||||||
|
console.log(`❌ Failed to send ping event:`, e.message);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}, 20000);
|
||||||
|
}
|
||||||
|
|
||||||
export default AdminInterface;
|
export default AdminInterface;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import NDK, { NDKNip46Backend, Nip46PermitCallback } from '@nostr-dev-kit/ndk';
|
import NDK, { NDKNip46Backend, NDKPrivateKeySigner, Nip46PermitCallback } from '@nostr-dev-kit/ndk';
|
||||||
import prisma from '../../db.js';
|
import prisma from '../../db.js';
|
||||||
import type {FastifyInstance} from "fastify";
|
import type {FastifyInstance} from "fastify";
|
||||||
|
|
||||||
@ -13,7 +13,8 @@ export class Backend extends NDKNip46Backend {
|
|||||||
cb: Nip46PermitCallback,
|
cb: Nip46PermitCallback,
|
||||||
baseUrl?: string
|
baseUrl?: string
|
||||||
) {
|
) {
|
||||||
super(ndk, key, cb);
|
const signer = new NDKPrivateKeySigner(key);
|
||||||
|
super(ndk, signer, cb);
|
||||||
|
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.fastify = fastify;
|
this.fastify = fastify;
|
||||||
|
|||||||
@ -226,7 +226,20 @@ class Daemon {
|
|||||||
*/
|
*/
|
||||||
async startKey(name: string, nsec: string) {
|
async startKey(name: string, nsec: string) {
|
||||||
const cb = signingAuthorizationCallback(name, this.adminInterface);
|
const cb = signingAuthorizationCallback(name, this.adminInterface);
|
||||||
const hexpk = nip19.decode(nsec).data as string;
|
let hexpk: string;
|
||||||
|
|
||||||
|
if (nsec.startsWith('nsec1')) {
|
||||||
|
try {
|
||||||
|
const key = new NDKPrivateKeySigner(nsec);
|
||||||
|
hexpk = key.privateKey!;
|
||||||
|
} catch(e) {
|
||||||
|
console.error(`Error loading key ${name}:`, e);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hexpk = nsec;
|
||||||
|
}
|
||||||
|
|
||||||
const backend = new Backend(this.ndk, this.fastify, hexpk, cb, this.config.baseUrl);
|
const backend = new Backend(this.ndk, this.fastify, hexpk, cb, this.config.baseUrl);
|
||||||
await backend.start();
|
await backend.start();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user