docs: Add comments to explain purpose and functionality of source files

This commit is contained in:
rabble (aider) 2024-12-09 22:40:07 +13:00
parent 21d7c5724f
commit 114cb73ef5
6 changed files with 58 additions and 2 deletions

View File

@ -1,3 +1,14 @@
/**
* CLI client for interacting with nsecBunker
* Supports:
* - Signing events (NIP-46)
* - Creating new accounts
* - Managing authorization flows
* - Publishing to relays
*
* Uses NDK for Nostr protocol interactions
*/
import "websocket-polyfill";
import NDK, { NDKUser, NDKEvent, NDKPrivateKeySigner, NDKNip46Signer, NostrEvent } from '@nostr-dev-kit/ndk';
import fs from 'fs';

View File

@ -1,3 +1,11 @@
/**
* Command to add a new encrypted nsec to the bunker
* Handles:
* - Prompting for passphrase and nsec
* - Encrypting and storing the nsec in config
* - Validation of provided nsec format
*/
import {nip19} from 'nostr-tools';
import readline from 'readline';
import { getCurrentConfig, saveCurrentConfig } from '../config/index.js';

View File

@ -1,3 +1,9 @@
/**
* Initial setup command for nsecBunker
* Configures the first administrator npub that will have
* remote control access to the bunker
*/
import readline from 'readline';
import { getCurrentConfig, saveCurrentConfig } from '../config/index.js';
@ -18,4 +24,4 @@ export async function setup(config: string) {
console.log(`Administrator npub added!`);
});
}
}

View File

@ -1,3 +1,11 @@
/**
* Command to start the nsecBunker daemon
* Handles:
* - Loading and decrypting keys
* - Publishing NIP-89 announcements for configured domains
* - Starting the daemon process with loaded configuration
*/
import readline from 'readline';
import { DomainConfig, IConfig, getCurrentConfig, saveCurrentConfig } from '../config/index.js';
import { decryptNsec } from '../config/keys.js';

View File

@ -1,3 +1,9 @@
/**
* Configuration management for nsecBunker
* Handles reading/writing config files and provides type definitions
* for the configuration schema
*/
import { readFileSync, writeFileSync } from 'fs';
import { NDKPrivateKeySigner, NDKUserProfile } from '@nostr-dev-kit/ndk';
import { IAdminOpts } from '../daemon/admin';
@ -95,4 +101,4 @@ export function saveCurrentConfig(config: string, currentConfig: any) {
}
}
export {getCurrentConfig};
export {getCurrentConfig};

View File

@ -1,5 +1,15 @@
import crypto from 'crypto';
/**
* Encryption utilities for securely storing nsec (private keys)
*/
/**
* Encrypts an nsec using AES-256-CBC with a key derived from the passphrase
* @param nsec - The private key to encrypt
* @param passphrase - User provided passphrase to derive encryption key
* @returns Object containing initialization vector and encrypted data as hex strings
*/
export function encryptNsec(nsec: string, passphrase: string): { iv: string, data: string } {
const algorithm = 'aes-256-cbc';
const key = crypto.createHash('sha256').update(passphrase).digest();
@ -14,6 +24,13 @@ export function encryptNsec(nsec: string, passphrase: string): { iv: string, dat
};
}
/**
* Decrypts an encrypted nsec using the original passphrase
* @param iv - Initialization vector as hex string
* @param data - Encrypted data as hex string
* @param passphrase - Original passphrase used for encryption
* @returns Decrypted nsec string
*/
export function decryptNsec(iv: string, data: string, passphrase: string): string {
const algorithm = 'aes-256-cbc';
const key = crypto.createHash('sha256').update(passphrase).digest();