diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 0d70d58..0000000 --- a/jest.config.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} */ -export default { - preset: 'ts-jest', - testEnvironment: 'node', - extensionsToTreatAsEsm: ['.ts'], - moduleNameMapper: { - '^@/(.*)$': '/src/$1' - }, - transform: { - '^.+\\.tsx?$': ['ts-jest', { - useESM: true, - }], - }, - testMatch: ['**/__tests__/**/*.test.ts'], - moduleFileExtensions: ['ts', 'js'], - collectCoverage: true, - coverageDirectory: 'coverage', - coverageReporters: ['text', 'lcov'] -} diff --git a/package-lock.json b/package-lock.json index 6c5b3d0..1bc11e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,21 @@ { "name": "nostr-nsec-seedphrase", - "version": "0.6.1", + "version": "0.6.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nostr-nsec-seedphrase", - "version": "0.6.1", + "version": "0.6.2", "license": "MIT", "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": { @@ -29,6 +30,35 @@ "vitest": "^1.6.0" } }, + "../nostr-crypto-utils": { + "version": "0.4.10", + "license": "MIT", + "dependencies": { + "@noble/curves": "^1.3.0", + "@noble/hashes": "^1.3.3", + "@noble/secp256k1": "^2.0.0", + "bech32": "^2.0.0", + "buffer": "^6.0.3", + "crypto-js": "^4.2.0", + "pino": "^8.17.1" + }, + "devDependencies": { + "@types/crypto-js": "^4.2.1", + "@types/node": "^20.10.5", + "@typescript-eslint/eslint-plugin": "^6.15.0", + "@typescript-eslint/parser": "^6.15.0", + "eslint": "^8.56.0", + "gh-pages": "^6.2.0", + "prettier": "^3.1.1", + "typedoc": "^0.27.0", + "typedoc-plugin-markdown": "^4.3.3", + "typescript": "^5.3.3", + "vitest": "^1.6.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -1688,12 +1718,6 @@ "node": ">= 8" } }, - "node_modules/crypto-js": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", - "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==", - "license": "MIT" - }, "node_modules/debug": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", @@ -2776,22 +2800,8 @@ "license": "MIT" }, "node_modules/nostr-crypto-utils": { - "version": "0.4.5", - "resolved": "https://registry.npmjs.org/nostr-crypto-utils/-/nostr-crypto-utils-0.4.5.tgz", - "integrity": "sha512-I0tr8nzyMaAePz/6s7eQfHLp38VL+A17Oj6mMzsli5EHgrpN49mmw8YQZzrikmmbRs7diQuZIImbsxBrCn4dIg==", - "license": "MIT", - "dependencies": { - "@noble/curves": "^1.3.0", - "@noble/hashes": "^1.3.3", - "@noble/secp256k1": "^2.0.0", - "bech32": "^2.0.0", - "buffer": "^6.0.3", - "crypto-js": "^4.2.0", - "pino": "^8.17.1" - }, - "engines": { - "node": ">=16.0.0" - } + "resolved": "../nostr-crypto-utils", + "link": true }, "node_modules/npm-run-path": { "version": "5.3.0", diff --git a/package.json b/package.json index a5f89ce..dbfcf0b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/nips/nip-19.ts b/src/nips/nip-19.ts index e67be59..f26a6fc 100644 --- a/src/nips/nip-19.ts +++ b/src/nips/nip-19.ts @@ -9,7 +9,7 @@ import { logger } from '../utils/logger.js'; import { npubEncode, nsecEncode, noteEncode, decode as nip19Decode } from 'nostr-crypto-utils'; -import type { Nip19Data } from 'nostr-crypto-utils'; +import type { Nip19DataType } from 'nostr-crypto-utils'; /** * Encodes a public key into npub format @@ -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; } } diff --git a/src/types/index.ts b/src/types/index.ts index 8177da2..df6651e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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'; diff --git a/src/utils/logger.ts b/src/utils/logger.ts index be4cd74..713c30e 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -26,8 +26,8 @@ type CustomLogger = Logger & { log: (obj: string | Record, 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; diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..0b68e5e --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "moduleResolution": "node", + "outDir": "./dist/cjs" + } +} diff --git a/tsconfig.json b/tsconfig.json index f43d285..afd6d69 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "target": "ES2020", - "module": "Node16", - "moduleResolution": "Node16", + "module": "ES2020", + "moduleResolution": "bundler", "declaration": true, "declarationDir": "./dist", "outDir": "./dist", @@ -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"]