Skip to content

feat(frontend): add memo byte-size estimator module (#374) - #473

Open
jdjioe5-cpu wants to merge 1 commit into
Kitewell-lab:mainfrom
jdjioe5-cpu:feat/issue-374-memo-size-estimator
Open

jdjioe5-cpu wants to merge 1 commit into
Kitewell-lab:mainfrom
jdjioe5-cpu:feat/issue-374-memo-size-estimator

Conversation

@jdjioe5-cpu

Copy link
Copy Markdown

Summary

Implements the memo byte-size estimator in frontend/src/memoSizeEstimate.js to estimate encoded byte size against Stellar's protocol limits per #374.

Changes

  • Add frontend/src/memoSizeEstimate.js exporting estimateMemoSize (and memoSizeEstimate alias) and getUtf8ByteLength
  • Support Stellar memo types: text (up to 28 bytes UTF-8), id (64-bit unsigned integer, 8 bytes), hash/return (32 bytes), and none (0 bytes)
  • Accurately calculate UTF-8 byte lengths using TextEncoder
  • Handle 64-bit unsigned bounds up to 18446744073709551615n for memo IDs
  • Validate 32-byte hex string (64 characters) or Uint8Array/Buffer payloads for hashes
  • Export constants in frontend/src/memoSizeEstimateConstants.js (MEMO_LIMITS, MAX_MEMO_ID, MEMO_TYPES)
  • Add 9 single-behavior Vitest test files in frontend/src/:
    • memoSizeEstimate-text-happy.test.js (valid ASCII and UTF-8 text within 28 bytes)
    • memoSizeEstimate-text-overflow.test.js (text exceeding 28 UTF-8 bytes)
    • memoSizeEstimate-id-valid.test.js (valid ID numbers, strings, and bigints)
    • memoSizeEstimate-id-overflow.test.js (IDs exceeding 64-bit uint limits or negative numbers)
    • memoSizeEstimate-hash.test.js (valid and invalid 32-byte hash and return memos)
    • memoSizeEstimate-none.test.js (none memo type with 0 bytes)
    • memoSizeEstimate-options-object.test.js (options object interface)
    • memoSizeEstimate-invalid-type.test.js (unknown memo type rejection)
    • memoSizeEstimate-constants.test.js (constant immutability verification)
  • Add documentation in docs/features/memoSizeEstimate.md
  • No existing files modified

Verification

  • npm test -- --run run from frontend/ passes 190/190 test files and 432/432 tests clean

Closes #374

- Implement frontend/src/memoSizeEstimate.js to estimate encoded memo byte size against Stellar protocol limits
- Support text (28 bytes UTF-8), id (uint64, 8 bytes), hash/return (32 bytes), and none (0 bytes)
- Export constants MEMO_LIMITS, MAX_MEMO_ID, and MEMO_TYPES
- Handle multi-byte UTF-8, integer overflow checks, hex verification, and options object invocation
- Add 9 single-behavior Vitest test files covering happy path, UTF-8, overflow, hex validation, constants, and error cases
- Add documentation under docs/features/memoSizeEstimate.md

Closes Kitewell-lab#374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New frontend module: frontend/src/memoSizeEstimate.js — Memo byte-size estimator

1 participant