15 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
fiatjaf 3588d30044 do the same for @noble/ciphers and @scure packages. 2026-01-27 22:43:54 -03:00
b40f59af74 Upgrade to @noble/curves ^2.0.1 and @noble/hashes ^2.0.1
This commit upgrades the noble cryptography dependencies to v2.0.1, which includes:

Breaking changes addressed:
- Updated all @noble imports to include .js extensions (required by v2 ESM-only API)
- Changed @noble/hashes/sha256 to @noble/hashes/sha2.js across 8 files
- Fixed secp256k1 API changes: methods now require Uint8Array instead of hex strings
- Updated schnorr.utils.randomPrivateKey() to schnorr.utils.randomSecretKey()

Files modified (27 total):
- package.json: Bump dependency versions
- Source files (12): pure.ts, nip04.ts, nip06.ts, nip13.ts, nip19.ts, nip44.ts,
  nip49.ts, nip77.ts, nip98.ts, nipb7.ts, utils.ts, wasm.ts
- Test files (14): All corresponding test files updated

Benefits:
- Latest security updates from audited noble libraries
- Smaller bundle sizes from v2 optimizations
- Future-proof ESM-only compatibility
- All tests passing

Co-authored-by: OpenCode <opencode@anomalyco.com>
2026-01-24 09:41:15 -03:00
fiatjaf 5876acd67a nip44: make the api less classy. 2024-05-19 14:40:23 -03:00
Alex Gleasonandfiatjaf_ 27a536f41d NIP44: fix slow types 2024-03-11 14:18:51 -03:00
Alex Gleasonandfiatjaf_ 9c0ade1329 Fix (most) slow types by adding explicit return types 2024-03-07 07:22:44 -03:00
fiatjaf 54b55b98f1 nip44: get rid of ensureBytes() since it was removed from upstream library. 2024-02-17 18:18:24 -03:00
Jon Staabandfiatjaf_ bf3818e434 Add nip44 v2 2023-12-21 08:55:23 -03:00
fiatjaf 0108e3b605 remove nip-44 stuff. 2023-12-16 12:39:07 -03:00
Paul MillerandGitHub 5e85bbc2ed Fix nip44 vectors (#308)
* Fix nip44 vectors

* Update vectors

* Update vectors
2023-09-30 18:46:45 -03:00
Paul MillerandGitHub eb0a9093f2 Implement NIP-44: secure versioned replacement for NIP4 (#221) 2023-09-29 20:43:48 -03:00
Alex Gleason 718032022c just format 2023-08-31 13:42:15 -05:00
fiatjaf 45e479d7aa let it throw. 2023-08-16 13:59:31 -03:00
b92407b156 nip44 updates (#278)
Co-authored-by: Jonathan Staab <shtaab@gmail.com>
2023-08-16 13:53:37 -03:00
Jonathan Staabandfiatjaf_ d13eecad4a Add support for nip44 2023-08-12 20:46:32 -03:00