Skip to content

Commit f3f147d

Browse files
committed
Merge branch 'docs/update-readme-and-changelog'
2 parents 78198c3 + 3e3311f commit f3f147d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3739
-354
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.6.5] - 2025-01-13
11+
12+
### Changed
13+
- Fixed TypeScript errors related to unknown type assignments across multiple files.
14+
- Improved error handling by converting error objects to strings before logging.
15+
- Updated logger imports to use default imports where necessary.
16+
- Ensured consistent logging practices throughout the codebase.
17+
18+
### Added
19+
- Created a CHECKLIST.md file for future development and maintenance reference.
20+
21+
## [0.6.4] - 2025-01-13
22+
23+
### Added
24+
- Enhanced webpack compatibility for client-side usage
25+
- Improved TypeScript type definitions
26+
- Additional documentation for module usage patterns
27+
28+
## [0.6.3] - 2025-01-05
29+
30+
### Changed
31+
- Updated dependency versions for better compatibility
32+
- Improved error handling in key management functions
33+
1034
## [0.6.2] - 2024-12-29
1135

1236
### Changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,35 @@ const isValid = await isDelegationValid(delegation);
180180
const expiry = getDelegationExpiry(delegation);
181181
```
182182

183+
## Module Support
184+
185+
This package supports both ESM and CommonJS usage:
186+
187+
### ESM (recommended)
188+
```typescript
189+
import { generateKeyPairWithSeed } from 'nostr-nsec-seedphrase';
190+
```
191+
192+
### CommonJS
193+
```javascript
194+
const { generateKeyPairWithSeed } = require('nostr-nsec-seedphrase');
195+
```
196+
197+
### Webpack Usage
198+
The package is fully compatible with webpack for client-side applications. Add to your webpack config:
199+
200+
```javascript
201+
module.exports = {
202+
resolve: {
203+
fallback: {
204+
"crypto": require.resolve("crypto-browserify"),
205+
"stream": require.resolve("stream-browserify"),
206+
"buffer": require.resolve("buffer/")
207+
}
208+
}
209+
};
210+
```
211+
183212
## Documentation
184213

185214
The library includes comprehensive TypeScript types and JSDoc documentation. You can:
@@ -189,7 +218,11 @@ The library includes comprehensive TypeScript types and JSDoc documentation. You
189218
```bash
190219
npm run docs
191220
```
192-
3. Access the generated documentation in the `docs` directory
221+
3. View the generated documentation locally:
222+
```bash
223+
npm run docs:serve
224+
```
225+
4. Access the generated documentation in the `docs` directory
193226

194227
### Key Format Utilities
195228

@@ -233,3 +266,10 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
233266
## License
234267

235268
MIT License - see the [LICENSE](LICENSE) file for details.
269+
270+
## Version 0.6.5
271+
- Fixed TypeScript errors related to unknown type assignments across multiple files.
272+
- Improved error handling by converting error objects to strings before logging.
273+
- Updated logger imports to use default imports where necessary.
274+
- Ensured consistent logging practices throughout the codebase.
275+
- Added a checklist for future reference.

dist/bips/bip39.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { generateMnemonic, validateMnemonic, mnemonicToEntropy } from 'bip39';
2-
import { logger } from '../utils/logger.js';
2+
import { logger } from '../utils/logger';
33
/**
44
* Generates a new BIP39 seed phrase
55
* @returns {string} The generated seed phrase
@@ -12,7 +12,7 @@ export function generateSeedPhrase() {
1212
return generateMnemonic();
1313
}
1414
catch (error) {
15-
logger.error('Failed to generate seed phrase:', error);
15+
logger.error('Failed to generate seed phrase:', error instanceof Error ? error.message : String(error));
1616
throw new Error('Failed to generate seed phrase');
1717
}
1818
}
@@ -29,7 +29,7 @@ export function validateSeedPhrase(seedPhrase) {
2929
return validateMnemonic(seedPhrase);
3030
}
3131
catch (error) {
32-
logger.error('Failed to validate seed phrase:', error);
32+
logger.error('Failed to validate seed phrase:', error instanceof Error ? error.message : String(error));
3333
return false;
3434
}
3535
}
@@ -57,7 +57,7 @@ export function getEntropyFromSeedPhrase(seedPhrase) {
5757
return entropyBytes;
5858
}
5959
catch (error) {
60-
logger.error('Failed to get entropy from seed phrase:', error);
60+
logger.error('Failed to get entropy from seed phrase:', error instanceof Error ? error.message : String(error));
6161
throw new Error('Failed to get entropy from seed phrase');
6262
}
6363
}

dist/browser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './index';

dist/browser.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Re-export everything from index
2+
export * from './index';
3+
// Add browser-specific implementations or overrides here
4+
import { Buffer } from 'buffer';
5+
if (typeof window !== 'undefined') {
6+
window.Buffer = Buffer;
7+
}
8+
// Add any browser-specific initialization code here
9+
const isBrowser = typeof window !== 'undefined';
10+
if (isBrowser) {
11+
// Initialize any browser-specific features
12+
console.log('NostrNsecSeedphrase loaded in browser environment');
13+
}

dist/browser/nostr-nsec-seedphrase.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*!
2+
* The buffer module from node.js, for the browser.
3+
*
4+
* @author Feross Aboukhadijeh <https://feross.org>
5+
* @license MIT
6+
*/
7+
8+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
9+
10+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11+
12+
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */

dist/browser/report.html

Lines changed: 39 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { bytesToHex as originalBytesToHex, hexToBytes as originalHexToBytes } from "@noble/hashes/utils";
2+
export declare function getPublicKey(privateKey: Uint8Array | string): Uint8Array;
3+
export declare const schnorr: {
4+
sign(message: Uint8Array | string, privateKey: Uint8Array | string): Promise<Uint8Array>;
5+
verify(signature: Uint8Array | string, message: Uint8Array | string, publicKey: Uint8Array | string): Promise<boolean>;
6+
};
7+
export declare const utils: {
8+
bytesToHex: typeof originalBytesToHex;
9+
hexToBytes: typeof originalHexToBytes;
10+
isValidPrivateKey(key: Uint8Array | string): boolean;
11+
randomPrivateKey(): Uint8Array;
12+
};
13+
declare const _default: {
14+
getPublicKey: typeof getPublicKey;
15+
schnorr: {
16+
sign(message: Uint8Array | string, privateKey: Uint8Array | string): Promise<Uint8Array>;
17+
verify(signature: Uint8Array | string, message: Uint8Array | string, publicKey: Uint8Array | string): Promise<boolean>;
18+
};
19+
utils: {
20+
bytesToHex: typeof originalBytesToHex;
21+
hexToBytes: typeof originalHexToBytes;
22+
isValidPrivateKey(key: Uint8Array | string): boolean;
23+
randomPrivateKey(): Uint8Array;
24+
};
25+
};
26+
export default _default;

dist/cjs/__mocks__/bech32.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
declare function toWords(data: Uint8Array): number[];
2+
declare function fromWords(words: number[]): number[];
3+
declare function encode(prefix: string, words: number[], limit: number): string;
4+
declare function decode(str: string, limit?: number): {
5+
prefix: string;
6+
words: number[];
7+
};
8+
export declare const bech32: {
9+
toWords: typeof toWords;
10+
fromWords: typeof fromWords;
11+
encode: typeof encode;
12+
decode: typeof decode;
13+
};
14+
export {};

dist/cjs/__mocks__/bip39.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare function generateMnemonic(): string;
2+
export declare function validateMnemonic(mnemonic: string): boolean;
3+
export declare function mnemonicToEntropy(mnemonic: string): string;

dist/cjs/bips/bip39.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Generates a new BIP39 seed phrase
3+
* @returns {string} The generated seed phrase
4+
* @example
5+
* const seedPhrase = generateSeedPhrase();
6+
* console.log(seedPhrase); // "witch collapse practice feed shame open despair creek road again ice least"
7+
*/
8+
export declare function generateSeedPhrase(): string;
9+
/**
10+
* Validates a BIP39 seed phrase
11+
* @param {string} seedPhrase - The seed phrase to validate
12+
* @returns {boolean} True if the seed phrase is valid
13+
* @example
14+
* const isValid = validateSeedPhrase("witch collapse practice feed shame open despair creek road again ice least");
15+
* console.log(isValid); // true
16+
*/
17+
export declare function validateSeedPhrase(seedPhrase: string): boolean;
18+
/**
19+
* Converts a BIP39 seed phrase to its entropy value
20+
* @param {string} seedPhrase - The BIP39 seed phrase to convert
21+
* @returns {Uint8Array} The entropy value
22+
* @throws {Error} If the seed phrase is invalid
23+
* @example
24+
* const entropy = getEntropyFromSeedPhrase("witch collapse practice feed shame open despair creek road again ice least");
25+
* console.log(entropy); // Uint8Array
26+
*/
27+
export declare function getEntropyFromSeedPhrase(seedPhrase: string): Uint8Array;

dist/cjs/bips/bip39.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports.generateSeedPhrase = generateSeedPhrase;
44
exports.validateSeedPhrase = validateSeedPhrase;
55
exports.getEntropyFromSeedPhrase = getEntropyFromSeedPhrase;
66
const bip39_1 = require("bip39");
7-
const logger_js_1 = require("../utils/logger.js");
7+
const logger_1 = require("../utils/logger");
88
/**
99
* Generates a new BIP39 seed phrase
1010
* @returns {string} The generated seed phrase
@@ -17,7 +17,7 @@ function generateSeedPhrase() {
1717
return (0, bip39_1.generateMnemonic)();
1818
}
1919
catch (error) {
20-
logger_js_1.logger.error('Failed to generate seed phrase:', error);
20+
logger_1.logger.error('Failed to generate seed phrase:', error instanceof Error ? error.message : String(error));
2121
throw new Error('Failed to generate seed phrase');
2222
}
2323
}
@@ -34,7 +34,7 @@ function validateSeedPhrase(seedPhrase) {
3434
return (0, bip39_1.validateMnemonic)(seedPhrase);
3535
}
3636
catch (error) {
37-
logger_js_1.logger.error('Failed to validate seed phrase:', error);
37+
logger_1.logger.error('Failed to validate seed phrase:', error instanceof Error ? error.message : String(error));
3838
return false;
3939
}
4040
}
@@ -62,7 +62,7 @@ function getEntropyFromSeedPhrase(seedPhrase) {
6262
return entropyBytes;
6363
}
6464
catch (error) {
65-
logger_js_1.logger.error('Failed to get entropy from seed phrase:', error);
65+
logger_1.logger.error('Failed to get entropy from seed phrase:', error instanceof Error ? error.message : String(error));
6666
throw new Error('Failed to get entropy from seed phrase');
6767
}
6868
}

dist/cjs/bips/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @module bips
3+
* @description Bitcoin Improvement Proposals (BIPs) implementations
4+
*/
5+
export * from './bip39.js';

dist/cjs/browser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './index';

dist/cjs/browser.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
14+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15+
};
16+
Object.defineProperty(exports, "__esModule", { value: true });
17+
// Re-export everything from index
18+
__exportStar(require("./index"), exports);
19+
// Add browser-specific implementations or overrides here
20+
const buffer_1 = require("buffer");
21+
if (typeof window !== 'undefined') {
22+
window.Buffer = buffer_1.Buffer;
23+
}
24+
// Add any browser-specific initialization code here
25+
const isBrowser = typeof window !== 'undefined';
26+
if (isBrowser) {
27+
// Initialize any browser-specific features
28+
console.log('NostrNsecSeedphrase loaded in browser environment');
29+
}

dist/cjs/constants.d.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @module constants
3+
* @description Constants used throughout the library
4+
*/
5+
/**
6+
* Standard Nostr message types as defined in NIP-01
7+
* @see https://github.com/nostr-protocol/nips/blob/master/01.md
8+
*/
9+
export declare const NOSTR_MESSAGE_TYPE: {
10+
readonly EVENT: "EVENT";
11+
readonly REQ: "REQ";
12+
readonly CLOSE: "CLOSE";
13+
readonly NOTICE: "NOTICE";
14+
readonly EOSE: "EOSE";
15+
readonly OK: "OK";
16+
readonly AUTH: "AUTH";
17+
readonly ERROR: "ERROR";
18+
};
19+
/**
20+
* Standard Nostr event kinds as defined in various NIPs
21+
* @see https://github.com/nostr-protocol/nips
22+
*/
23+
export declare const NOSTR_EVENT_KIND: {
24+
readonly SET_METADATA: 0;
25+
readonly TEXT_NOTE: 1;
26+
readonly RECOMMEND_SERVER: 2;
27+
readonly CONTACT_LIST: 3;
28+
readonly ENCRYPTED_DIRECT_MESSAGE: 4;
29+
readonly DELETE: 5;
30+
readonly REPOST: 6;
31+
readonly REACTION: 7;
32+
readonly BADGE_AWARD: 8;
33+
readonly CHANNEL_CREATE: 40;
34+
readonly CHANNEL_METADATA: 41;
35+
readonly CHANNEL_MESSAGE: 42;
36+
readonly CHANNEL_HIDE_MESSAGE: 43;
37+
readonly CHANNEL_MUTE_USER: 44;
38+
readonly CHANNEL_RESERVED_FIRST: 40;
39+
readonly CHANNEL_RESERVED_LAST: 49;
40+
readonly REPLACEABLE_FIRST: 10000;
41+
readonly REPLACEABLE_LAST: 19999;
42+
readonly EPHEMERAL_FIRST: 20000;
43+
readonly EPHEMERAL_LAST: 29999;
44+
readonly PARAMETERIZED_REPLACEABLE_FIRST: 30000;
45+
readonly PARAMETERIZED_REPLACEABLE_LAST: 39999;
46+
};
47+
/**
48+
* Standard Nostr tag types
49+
*/
50+
export declare const NOSTR_TAG: {
51+
readonly EVENT: "e";
52+
readonly PUBKEY: "p";
53+
readonly REFERENCE: "a";
54+
readonly DELEGATION: "delegation";
55+
readonly DEDUPLICATION: "d";
56+
readonly EXPIRATION: "expiration";
57+
readonly KIND: "k";
58+
readonly RELAY: "relay";
59+
};
60+
/**
61+
* Protocol-related constants
62+
*/
63+
export declare const Protocol: {
64+
readonly DEFAULT_RELAY_URL: "wss://relay.nostr.info";
65+
readonly RECONNECT_DELAY: 1000;
66+
readonly MAX_RECONNECT_DELAY: 30000;
67+
readonly PING_INTERVAL: 30000;
68+
readonly SUBSCRIPTION_TIMEOUT: 10000;
69+
};
70+
/**
71+
* Default values
72+
*/
73+
export declare const Defaults: {
74+
readonly KIND: 1;
75+
readonly CREATED_AT: () => number;
76+
readonly TAGS: string[][];
77+
readonly CONTENT: "";
78+
};

0 commit comments

Comments
 (0)