98 Commits
Author SHA1 Message Date
Alex GleasonandGitHub 8260e6245d nip44: support encryption of payloads larger than 65535 bytes (#527)
* nip44: support encryption of payloads larger than 65535 bytes

Implement the extended prefix format from nostr-protocol/nips#1907
with bug fixes:

- When plaintext length >= 65536, pad with a 6-byte prefix (2 zero
  sentinel bytes + 4-byte u32 BE length) instead of the 2-byte u16
- Detect the sentinel in unpad() and use dynamic prefix_len (2 or 6)
  for both data extraction and padding validation
- Remove upper-bound size limits in decodePayload() (was rejecting
  payloads > 87472 chars / 65603 bytes)
- Raise maxPlaintextSize from 0xffff to 0xffffffff (2^32-1)
- Add writeU32BE() helper for encoding large lengths
- Fix unpad() to use padded.byteOffset for correct DataView on
  subarrays (was using padded.buffer directly which could be wrong
  if padded is a subarray of a larger buffer)

Tests: add boundary tests at 65535/65536/65537 bytes and full
encrypt/decrypt round-trips at 65536 and 100000 bytes.
All 10 tests pass (5 existing + 5 new).

* nip44: fix calcPaddedLen overflow, enforce canonical prefix, add thorough tests

Fix three bugs found during security audit:

- calcPaddedLen: use 2** instead of 1<< to avoid signed 32-bit
  overflow in JS for plaintext lengths above 2^30
- unpad: reject extended 6-byte prefix when decoded length is below
  65536 (enforce canonical encoding, prevent ambiguous padding)
- decodePayload: document that callers should validate payload size
  before calling to prevent DoS from oversized inputs
- Fix stale size-range comments to match corrected spec arithmetic

Add 10 new tests covering:
- Non-canonical extended prefix rejection (len=1, 1000, 65535)
- Truncated extended prefix buffer
- calcPaddedLen at 2^30+1, 2^31, and 2^32-1
- Multi-byte UTF-8 at the 65536 byte boundary (pad/unpad + e2e)
- Spec test vectors with SHA-256 checksums for 65535/65536/65537
2026-04-10 23:21:52 -03:00
Alex Gleasonandfiatjaf_ 9c009ac543 getFilterLimit: handle parameterized replaceable events 2024-07-20 22:00:28 -03:00
Alex Gleasonandfiatjaf_ f8c3e20f3d getFilterLimit: empty tags return 0 2024-05-30 16:32:55 -03:00
Alex Gleasonandfiatjaf_ e858698cb9 Add stable sortEvents function 2024-04-12 21:20:06 -03:00
Alex GleasonandGitHub b349ee577d Merge pull request #392 from verbiricha/patch-1
fix typos in README
2024-04-12 17:57:49 -05:00
Alex GleasonandGitHub 849a2ac3f3 Merge pull request #397 from alexgleason/pure-test
core.test.ts -> pure.test.ts
2024-04-12 17:48:09 -05:00
Alex Gleason c18b94677c core.test.ts -> pure.test.ts 2024-04-12 17:44:36 -05:00
Alex Gleason 7aed747bb2 Remove GitHub actions flow for publishing to JSR because it's not working 2024-03-18 13:23:29 -05:00
Alex Gleason 747a7944d7 Wasm: add explicit type to i 2024-03-18 13:04:21 -05:00
Alex Gleason 9f8b7274b3 Revert "tsconfig: for sanity, go back to moduleResolution bundler and see if that fixes it"
This reverts commit ee565db7f5.
2024-03-18 13:02:35 -05:00
Alex Gleason ee565db7f5 tsconfig: for sanity, go back to moduleResolution bundler and see if that fixes it 2024-03-18 13:00:56 -05:00
Alex Gleason e9ee8258e7 tsconfig: module NodeNext 2024-03-18 11:54:38 -05:00
Alex Gleason ad07d260ab Add missing file extensions to imports 2024-03-18 11:51:00 -05:00
Alex Gleason 632184afb8 publish: npm install -g jsr 2024-03-18 11:45:11 -05:00
Alex Gleason d7d5d30f41 publish: try bunx instead of npx 2024-03-18 11:40:47 -05:00
Alex Gleason 387ce2c335 publish: --allow-dirty ¯\_(ツ)_/¯ 2024-03-18 11:35:27 -05:00
Alex Gleason b62b8f88af jsr: bump version to v2.3.2 2024-03-18 11:32:33 -05:00
Alex Gleason 6b43533f2e tsconfig: moduleResolution NodeNext 2024-03-18 11:32:04 -05:00
Alex Gleasonandfiatjaf_ 71456feb20 jsr: explicit exports 2024-03-13 00:17:07 -03:00
Alex Gleason ca928c697b publish: --allow-slow-types for now 2024-03-11 15:15:41 -05:00
Alex GleasonandGitHub 7b98cae7fa Merge pull request #382 from alexgleason/bundle-resolution
tsconfig: moduleResolution Bundler
2024-03-11 14:47:27 -05:00
Alex Gleason db53f37161 tsconfig: moduleResolution Bundler 2024-03-11 14:22:11 -05:00
Alex GleasonandGitHub 1691f0b51d Merge pull request #381 from nbd-wtf/alexgleason-patch-1
publish: bun i
2024-03-11 13:00:14 -05:00
Alex GleasonandGitHub 3b582a0206 publish: bun i 2024-03-11 12:59:36 -05:00
Alex Gleasonandfiatjaf_ 8ed2c13c28 Publish to JSR with GitHub actions 2024-03-11 14:20:19 -03:00
Alex Gleasonandfiatjaf_ 27a536f41d NIP44: fix slow types 2024-03-11 14:18:51 -03:00
Alex Gleasonandfiatjaf_ fbc82d0b73 Prepare for JSR publishing 2024-03-07 07:26:16 -03:00
Alex Gleasonandfiatjaf_ 9c0ade1329 Fix (most) slow types by adding explicit return types 2024-03-07 07:22:44 -03:00
Alex Gleasonandfiatjaf_ 677b679c2c NIP-57: build lnurl in more secure way 2024-01-15 21:26:34 -03:00
Alex Gleasonandfiatjaf_ c1efbbd919 Add NIP-40 module for event expiration 2024-01-09 16:16:43 -03:00
Alex Gleasonandfiatjaf_ 348d118ce4 Add getFilterLimit function 2024-01-04 09:56:02 -03:00
Alex Gleasonandfiatjaf_ 36e0de2a68 Add NIP-30 module for custom emojis 2023-12-16 10:13:40 -03:00
Alex GleasonandGitHub 8e932f0c5a Merge pull request #295 from AsaiToshiya/patch-1
Improve example for finishEvent
2023-09-10 22:59:46 -05:00
Alex Gleasonandfiatjaf_ 6db8b94275 nip13: add minePow function 2023-09-10 15:45:31 -03:00
Alex Gleasonandfiatjaf_ c890e29290 nip13: use a simpler implementation 2023-09-10 15:15:33 -03:00
Alex Gleasonandfiatjaf_ c18f050468 relay: sub.events async iterator 2023-09-09 19:05:21 -03:00
Alex Gleasonandfiatjaf_ 401b9c7864 Make TypeScript >= 5.0.0 an optional peer dependency 2023-09-03 20:56:05 -03:00
Alex Gleason 41265a19f5 event.test: tamper with things in a more evil way 2023-09-03 12:12:42 -05:00
Alex Gleason d88761907a verifySignature: set verifiedSymbol to false on failure, DRY return values 2023-09-02 18:08:09 -05:00
Alex Gleason 8325d4351e just format 2023-09-02 17:40:00 -05:00
Alex Gleason 62bf592d72 finishEvent: return a VerifiedEvent 2023-09-02 17:39:35 -05:00
Alex Gleason 54f3bedf38 verifySignature: return false if the id is invalid 2023-09-02 17:39:28 -05:00
Alex Gleasonandfiatjaf_ 34e0ad8c41 Add a symbol to verified events 2023-09-02 18:04:10 -03:00
Alex Gleason cf46560619 ci: ensure just is available to the runner 2023-08-31 13:52:56 -05:00
Alex Gleason e7aa23cb1d README: add a note about typescript 5.0 2023-08-31 13:51:17 -05:00
Alex Gleason 5977d68ec2 nip98.test: remove outdated/failing test 2023-08-31 13:47:16 -05:00
Alex Gleason 48767d382d relay.test: increase querying timeout to 10s 2023-08-31 13:45:39 -05:00
Alex Gleason 718032022c just format 2023-08-31 13:42:15 -05:00
Alex Gleason 2a70bb18ff pool: use triple-equals 2023-08-31 13:41:40 -05:00
Alex Gleason 9effe807d1 filter: remove unused import for Kind 2023-08-31 13:41:25 -05:00
Alex Gleason 899c2bd0dc eslint: remove conflicting generator-star-spacing rule 2023-08-31 13:41:06 -05:00
Alex Gleason 918d514a25 Upgrade all eslint deps 2023-08-31 13:37:45 -05:00
Alex Gleason 48cb9046c4 Add eslint-config-prettier to solve conflicts between prettier and eslint 2023-08-31 13:27:28 -05:00
Alex Gleason 864dd28b26 justfile: improve lint/format commands 2023-08-31 13:25:30 -05:00
Alex Gleason fa085367c9 Add eslint to just format 2023-08-31 13:22:43 -05:00
Alex Gleason 350951b88e Add eslint to just lint 2023-08-31 13:21:10 -05:00
Alex Gleason c6133f7160 ci: run prettier on every commit 2023-08-31 13:14:16 -05:00
Alex Gleason 470512bbeb prettier: increase printWidth, enable bracketSpacing, alphabetize 2023-08-31 13:00:50 -05:00
Alex Gleason c3acb82464 Upgrade Prettier to v3.0.3 2023-08-31 12:59:54 -05:00
Alex GleasonandGitHub fc23d05764 Merge pull request #283 from jiftechnify/fix-code-samples
Fix code samples in README
2023-08-27 12:14:32 -05:00
Alex Gleasonandfiatjaf_ 837a05e54d Add kinds module to classify events by kind 2023-08-26 22:26:04 -03:00
Alex Gleasonandfiatjaf_ df6f887d7e Event, Filter: allow any kind number
Fixes https://github.com/nbd-wtf/nostr-tools/issues/275
2023-08-12 20:13:53 -03:00
Alex Gleasonandfiatjaf_ e00362e7c9 Filter: let tag queries be undefined 2023-08-12 16:30:24 -03:00
Alex GleasonandGitHub de7e128818 Merge pull request #267 from Airtune/nip98-extract-pubkey
+nip98.unpackEventFromToken +nip98.validateEvent
2023-08-08 08:48:29 -05:00
Alex GleasonandGitHub fec40490a2 Merge pull request #249 from alexgleason/fix-nip27-type
Fix nip27 type
2023-07-13 11:02:33 -05:00
Alex Gleason bb3e41bb89 Also remove failing nip05 test due to server down (this should be mocked) 2023-07-13 10:57:30 -05:00
Alex Gleason 27b971eef3 Fix nip27 type 2023-07-13 10:48:22 -05:00
Alex GleasonandGitHub 75fc836cf6 Merge pull request #241 from alexgleason/nip19-cool-type
nip19: use template literal types
2023-07-02 12:22:04 -05:00
Alex Gleason 70b025b8da nip19: use a DRY type 2023-07-01 22:44:04 -05:00
Alex Gleason c9bc702d90 nip19: use template literal types 2023-07-01 21:28:01 -05:00
Alex Gleasonandfiatjaf_ 7652318185 Fix nip27 test 2023-06-29 16:44:44 -03:00
Alex Gleasonandfiatjaf_ 7507943253 Fix nip27.matchAll crash on invalid nip19 2023-06-29 15:24:25 -03:00
Alex Gleasonandfiatjaf_ 08885ab8da Refactor imports: use file extension, improve tree shaking, update tests 2023-05-12 17:03:41 -03:00
Alex Gleasonandfiatjaf_ 82caa2aad9 Use buildEvent function in more places 2023-05-10 21:20:27 -03:00
Alex Gleasonandfiatjaf_ 67a8ee23ce Don't build before test (??) 2023-05-10 21:20:27 -03:00
Alex Gleasonandfiatjaf_ 18e8227123 Convert all tests to TypeScript 2023-05-10 21:20:27 -03:00
Alex Gleasonandfiatjaf_ 64caef9cda Convert nip05 test to typescript 2023-05-10 21:20:27 -03:00
Alex Gleasonandfiatjaf_ 6a07d2d9d3 nip05: fix not calling underscored fetch 2023-05-07 21:18:22 -03:00
Alex Gleasonandfiatjaf_ 341ccc5ac5 nip05: move NIP05Result to the bottom, add another test 2023-05-07 21:18:22 -03:00
Alex Gleasonandfiatjaf_ d2a9af2586 nip05 refactoring 2023-05-07 21:18:22 -03:00
Alex Gleasonandfiatjaf_ ab6abe6815 Improve types of filter.ts 2023-05-06 21:00:25 -03:00
Alex Gleasonandfiatjaf_ 30fd6b6215 nip57: use Kind enum instead of using the number directly 2023-05-06 21:00:25 -03:00
Alex Gleasonandfiatjaf_ 8a53b3b8b3 Improve event types 2023-05-06 21:00:25 -03:00
Alex Gleasonandfiatjaf_ d0bd599ce8 Infer relay event types from filter 2023-05-06 20:59:39 -03:00
Alex Gleasonandfiatjaf_ 1cbb62e6b9 Move BECH32_REGEX to nip19.ts 2023-05-03 17:12:39 -03:00
Alex Gleasonandfiatjaf_ dd8f555094 Make Filter a generic type accepting Kind 2023-05-02 22:35:04 -03:00
Alex Gleasonandfiatjaf_ 9fa554ca8e Make Event a generic type accepting Kind 2023-04-30 09:26:40 -03:00
Alex Gleason 552530fa3f Add back deprecated signEvent function with a warning 2023-04-24 01:22:12 -05:00
Alex Gleason 9a3e05ce5f Rename signEvent to getSignature 2023-04-23 11:13:15 -05:00
Alex Gleason 45c07a5f45 nip27: make matchAll a generator function 2023-04-22 19:22:06 -05:00
Alex Gleason 6a037d1658 nip27.find --> nip27.matchAll 2023-04-22 19:06:53 -05:00
Alex Gleason dcf101c6c2 yarn format 2023-04-22 18:33:09 -05:00
Alex Gleason eb97dbd9ef Add NIP-21 and NIP-27 modules for parsing nostr URIs 2023-04-22 18:30:57 -05:00
Alex Gleasonandfiatjaf_ 92988051c6 Add Unlicense 2023-04-20 12:22:39 -03:00
Alex Gleasonandfiatjaf_ 56fe3dd5dd nip19: improve return type 2023-04-18 07:30:43 -03:00
Alex Gleasonandfiatjaf_ a05506468d Add NIP-13 (proof-of-work) module 2023-04-11 18:21:40 -03:00
Alex Gleasonandfiatjaf_ 94b382a49f Fix validateEvent type checking 2023-04-08 17:53:31 -03:00
Alex Gleasonandfiatjaf_ 5b59b93d86 validateEvent: use assertion function 2023-04-08 15:07:25 -03:00