Skip to content

Implement a secure Stellar memo parser and canonicalisation module #376

Description

@Lakes41

Difficulty: Advanced
Type: Feature
Recommended labels (if available in this repo): stellar, backend, type-safety, advanced

Background

Stellar transactions support multiple memo types. GuildPass may eventually need to construct, inspect or validate transaction memos for integrations without each module implementing memo parsing differently.

This issue introduces a standalone memo parser and formatter only. It does not perform transaction submission or network access.

Problem

There is currently no Core utility that provides a strongly typed, canonical representation of supported Stellar memo values with explicit validation rules.

Loose string handling can cause ambiguity between memo types and can allow invalid values to reach later transaction-building code.

Expected Outcome

Build a deterministic Stellar memo module that parses supported memo representations into a discriminated union and formats them back into one canonical representation.

Suggested Implementation

Support Stellar memo concepts such as:

type StellarMemo =
  | { type: "none" }
  | { type: "text"; value: string }
  | { type: "id"; value: bigint }
  | { type: "hash"; value: Uint8Array }
  | { type: "return"; value: Uint8Array };

The implementation should:

  • validate memo-text byte limits using UTF-8 bytes rather than character count;
  • support the valid range for memo IDs;
  • validate exact byte length for hash and return-hash memos;
  • define canonical string or structured input forms;
  • expose a formatter that round-trips supported values;
  • reject malformed hexadecimal or encoded hash values;
  • avoid implicit lossy conversions;
  • support Unicode text correctly;
  • perform no network requests;
  • remain independent of transaction-building code.

Acceptance Criteria

  • none, text, ID, hash and return-hash memo types have explicit typed representations.
  • Valid text memos are accepted.
  • Text limits are enforced using UTF-8 byte length.
  • Valid memo IDs parse safely without precision loss.
  • Out-of-range IDs are rejected.
  • Hash-based memo values enforce exact required length.
  • Malformed hash encodings are rejected.
  • Parse/format round trips are covered by tests.
  • Unicode boundary cases are tested.
  • No network or Stellar RPC access occurs.
  • pnpm typecheck passes.
  • pnpm build passes.
  • pnpm test passes.
  • No transaction submission or persistence functionality is included.

Likely Affected Files/Directories

packages/stellar-memo/ or equivalent isolated package
unit tests

Independence Requirement

This issue must not depend on the Stellar asset parser, wallet validator or any transaction-building issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesThird CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsadvancedAdvanced difficulty tasks requiring significant domain knowledge and implementation effortbackendBackend services, application logic, persistence integration, and server-side functionalitystellarStellar network integration, wallet support, on-chain membership, and Stellar-specific functionalitytype-safetyTypeScript type system improvements and strict type enforcement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions