Skip to content

Commit

Permalink
chore: update to latest nostr-crypto-utils
Browse files Browse the repository at this point in the history
- Updated nostr-crypto-utils dependency
- Added tsconfig.cjs.json for CommonJS builds
- Removed jest.config.js as we've moved to vitest
- Updated TypeScript configurations
  • Loading branch information
vveerrgg committed Jan 6, 2025
1 parent 8af3e58 commit 9b06f85
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 59 deletions.
19 changes: 0 additions & 19 deletions jest.config.js

This file was deleted.

62 changes: 36 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
"import": "./dist/index.js",
"require": "./dist/cjs/index.js"
}
},
"scripts": {
"build": "tsc",
"build": "tsc && tsc -p tsconfig.cjs.json",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
Expand Down Expand Up @@ -55,12 +56,13 @@
},
"homepage": "https://github.com/humanjavaenterprises/nostr-nsec-seedphrase#readme",
"dependencies": {
"@noble/hashes": "^1.3.3",
"@noble/curves": "^1.3.0",
"@noble/hashes": "^1.3.2",
"@noble/secp256k1": "^2.1.0",
"@scure/base": "^1.2.1",
"bech32": "^2.0.0",
"bip39": "^3.1.0",
"nostr-crypto-utils": "^0.4.5",
"nostr-crypto-utils": "file:../nostr-crypto-utils",
"pino": "^8.17.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/nips/nip-19.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { logger } from '../utils/logger.js';
import { npubEncode, nsecEncode, noteEncode, decode as nip19Decode } from 'nostr-crypto-utils';

Check failure on line 11 in src/nips/nip-19.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

Check failure on line 11 in src/nips/nip-19.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

Check failure on line 11 in src/nips/nip-19.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.
import type { Nip19Data } from 'nostr-crypto-utils';
import type { Nip19DataType } from 'nostr-crypto-utils';

Check failure on line 12 in src/nips/nip-19.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

Check failure on line 12 in src/nips/nip-19.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

Check failure on line 12 in src/nips/nip-19.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

/**
* Encodes a public key into npub format
Expand Down Expand Up @@ -75,11 +75,11 @@ export function hexToNote(hex: string): string {
* const result = decode('npub1...');
* returns { type: 'npub', data: '...' }
*/
export function decode(str: string): Nip19Data {
export function decode(str: string): { type: Nip19DataType; data: string } {
try {
return nip19Decode(str);
} catch (error) {
logger.error({ error, str }, 'Failed to decode bech32-encoded string');
logger.error({ error, str }, 'Failed to decode bech32 string');
throw error;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export type {
PublicKeyDetails
} from './keys.js';

// Import and re-export Nip19Data type from nostr-crypto-utils
export type { Nip19Data } from 'nostr-crypto-utils';
// Import and re-export NIP-19 type from nostr-crypto-utils
export type { Nip19DataType } from 'nostr-crypto-utils';

Check failure on line 19 in src/types/index.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

Check failure on line 19 in src/types/index.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.

Check failure on line 19 in src/types/index.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Cannot find module 'nostr-crypto-utils' or its corresponding type declarations.
4 changes: 2 additions & 2 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type CustomLogger = Logger & {
log: (obj: string | Record<string, unknown>, msg?: string) => void;
};

// Create the logger instance with proper ESM/CJS compatibility
const baseLogger = (pino.default || pino)(options) as Logger;
// Create the logger instance
const baseLogger = pino(options) as Logger;

// Create the custom logger instance
const logger = baseLogger as CustomLogger;
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "./dist/cjs"
}
}
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "Node16",
"moduleResolution": "Node16",
"module": "ES2020",
"moduleResolution": "bundler",
"declaration": true,
"declarationDir": "./dist",
"outDir": "./dist",
Expand All @@ -18,7 +18,8 @@
"lib": ["es2020", "dom"],
"types": ["vitest/globals", "node"],
"allowJs": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
Expand Down

0 comments on commit 9b06f85

Please sign in to comment.