Skip to content

Commit de6b324

Browse files
committed
feat: Release version 0.4.3
- Enhanced logging system with better error handling - Development mode pretty printing with timestamps - Improved TypeScript support - Fixed lint issues and exported utility functions
2 parents 89a017d + ee17482 commit de6b324

6 files changed

Lines changed: 72 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.4.3] - 2024-12-29
11+
12+
### Added
13+
- Enhanced logging system with comprehensive error handling
14+
- Development mode pretty printing with timestamps
15+
- TypeScript type exports for logger
16+
- Export utility functions: `encodeBytes` and `getPublicKeyHex`
17+
18+
### Changed
19+
- Updated logger implementation to follow project-wide standards
20+
- Improved error object formatting with stack traces
21+
- Enhanced development mode output formatting
22+
- Removed unused code and variables
23+
24+
### Fixed
25+
- Error object serialization in logs now includes stack traces
26+
- Development mode logging now properly handles timestamps
27+
- Resolved lint issues in nip-19, nip-26, and validation utilities
28+
29+
## [0.4.2] - Previous Release
30+
... (previous entries)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nostr-crypto-utils",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "A comprehensive TypeScript library for Nostr protocol implementation, supporting multiple NIPs with strict validation",
55
"type": "module",
66
"main": "./dist/index.js",

src/nips/nip-19.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ export function decode(str: string): Nip19Data {
136136
}
137137

138138
// Helper functions
139-
function encodeBytes(prefix: string, hex: string): string {
140-
const data = Buffer.from(hex, 'hex');
139+
export function encodeBytes(prefix: string, data: Uint8Array): string {
141140
const words = bech32.toWords(data);
142141
return bech32.encode(prefix, words, 1000);
143142
}

src/nips/nip-26.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ export function checkDelegationConditions(
6969
event: NostrEvent,
7070
conditions: DelegationConditions
7171
): boolean {
72-
const now = Math.floor(Date.now() / 1000);
73-
7472
if (conditions.kind !== undefined && event.kind !== conditions.kind) {
7573
return false;
7674
}

src/utils/logger.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import pino from 'pino';
77

88
/**
9-
* Create a logger instance
9+
* Create a logger instance with consistent configuration
10+
* @param name - Component or module name for the logger
11+
* @param _options - Optional additional configuration
12+
* @returns Configured pino logger instance
1013
*/
1114
export function createLogger(name: string, _options?: unknown): pino.Logger {
1215
return pino({
@@ -15,41 +18,60 @@ export function createLogger(name: string, _options?: unknown): pino.Logger {
1518
transport: process.env.NODE_ENV === 'development' ? {
1619
target: 'pino-pretty',
1720
options: {
18-
colorize: true
21+
colorize: true,
22+
translateTime: 'HH:MM:ss',
23+
ignore: 'pid,hostname',
1924
}
20-
} : undefined
25+
} : undefined,
26+
formatters: {
27+
level: (label) => {
28+
return { level: label.toUpperCase() };
29+
}
30+
}
2131
});
2232
}
2333

2434
/**
25-
* @description Simple logger utility
26-
*/
27-
28-
/**
29-
* Log a message with optional data
35+
* Simple log function for basic logging needs
3036
* @param message - Message to log
31-
* @param data - Optional data to log
37+
* @param data - Optional data to include
3238
*/
3339
export function log(message: string, data?: unknown): void {
3440
console.log(message, data);
3541
}
3642

37-
// Export a default logger instance
3843
/**
39-
* Logger instance for the application
44+
* Default logger instance for the application
45+
* Includes enhanced error handling and formatting
4046
*/
4147
export const logger: pino.Logger = pino({
42-
name: 'default',
43-
level: 'info',
48+
name: 'nostr-crypto-utils',
49+
level: process.env.LOG_LEVEL || 'info',
50+
transport: process.env.NODE_ENV === 'development' ? {
51+
target: 'pino-pretty',
52+
options: {
53+
colorize: true,
54+
translateTime: 'HH:MM:ss',
55+
ignore: 'pid,hostname',
56+
}
57+
} : undefined,
4458
formatters: {
59+
level: (label) => {
60+
return { level: label.toUpperCase() };
61+
},
4562
log: (obj: Record<string, unknown>) => {
4663
// Convert error objects to strings for better logging
4764
if (obj && typeof obj === 'object' && 'err' in obj) {
4865
const newObj = { ...obj };
4966
if (newObj.err instanceof Error) {
50-
newObj.err = newObj.err.message;
67+
const err = newObj.err as Error;
68+
newObj.err = {
69+
message: err.message,
70+
stack: err.stack,
71+
name: err.name,
72+
};
5173
}
52-
return newObj as Record<string, unknown>;
74+
return newObj;
5375
}
5476
return obj;
5577
}

src/utils/validation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NostrEvent, NostrFilter, NostrSubscription, SignedNostrEvent, PublicKey } from '../types';
1+
import { NostrEvent, NostrFilter, NostrSubscription, SignedNostrEvent } from '../types';
22
import { isNostrEvent, isNostrFilter, isSignedNostrEvent } from '../types/guards';
33
import { schnorr } from '@noble/curves/secp256k1';
44
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
@@ -73,8 +73,8 @@ export function validateEvent(event: NostrEvent): ValidationResult {
7373
* @param pubkey - Public key in either hex or details format
7474
* @returns Hex representation of the public key
7575
*/
76-
function getPublicKeyHex(pubkey: PublicKey): string {
77-
return typeof pubkey === 'string' ? pubkey : pubkey.hex;
76+
export function getPublicKeyHex(pubkey: string): string {
77+
return pubkey.startsWith('npub1') ? pubkey.slice(5) : pubkey;
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)