Skip to content

feat(stellar): memo-encoded structured metadata schema (#140)#151

Open
lockoabosede8-byte wants to merge 3 commits into
wraith-protocol:developfrom
lockoabosede8-byte:feat/140-memo-encoded-structured-metadata-schema
Open

feat(stellar): memo-encoded structured metadata schema (#140)#151
lockoabosede8-byte wants to merge 3 commits into
wraith-protocol:developfrom
lockoabosede8-byte:feat/140-memo-encoded-structured-metadata-schema

Conversation

@lockoabosede8-byte

@lockoabosede8-byte lockoabosede8-byte commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Implements #140 — Memo-encoded structured metadata schema for Stellar memos. Partners (Reflector, Soroswap) can now attach reason strings, invoice IDs, or reference bytes to transactions via a compact versioned binary schema that fits within Stellar's 32-byte MEMO_HASH / MEMO_RETURN constraint.

Changes

New files

src/chains/stellar/memo/schema.ts — Encoder + decoder for a structured memo schema:

  • Binary layout (32 bytes): version(1) + kind(1) + data_length(1) + data(29)
  • MemoKind enum: Reason(0x01), InvoiceId(0x02), Reference(0x03)
  • encodeMemoSchema(kind, data) — Encodes a string (UTF-8) or Uint8Array into a 32-byte schema buffer
  • decodeMemoSchema(bytes) — Decodes a 32-byte buffer; returns { bytes, schema? }. If the first byte is not the version marker (0x01), returns the buffer as raw bytes for backwards compatibility
  • Extension mechanism: kinds 0x04–0xEF reserved for future standardised kinds, 0xF0–0xFF for private/experimental use. Unknown kinds are decoded and forwarded without throwing

test/chains/stellar/memo/schema.test.ts — 33 tests covering:

  • Round-trip encode/decode for all 3 kinds
  • Backwards compatibility (non-schema-shaped bytes → raw result)
  • Data size constraints (max 29 bytes, zero-length, edge cases)
  • UTF-8 multi-byte character encoding
  • Unknown kind forwarding, private/experimental kind range
  • Data length clamping for malformed input
  • Determinism and export verification

Modified files

src/chains/stellar/index.ts — Exports the new symbols (encodeMemoSchema, decodeMemoSchema, MemoKind, constants, types)

How it works

import { encodeMemoSchema, decodeMemoSchema, MemoKind } from '@wraith-protocol/sdk/chains/stellar'
import { encodeMemo } from '@wraith-protocol/sdk/chains/stellar'

// Encode a reason string into a 32-byte schema buffer
const schemaBytes = encodeMemoSchema(MemoKind.Reason, 'Payment for order #123')

// Wrap in a Stellar MEMO_HASH
const memo = encodeMemo({ type: 'hash', value: schemaBytes })

// On the receiving side, decode the memo
const decoded = decodeMemoSchema(schemaBytes)
if (decoded.schema) {
  console.log(decoded.schema.kind)  // MemoKind.Reason
  console.log(new TextDecoder().decode(decoded.schema.data))  // 'Payment for order #123'
}

// Backwards compat: raw bytes that don't start with 0x01 are returned as-is
const raw = decodeMemoSchema(new Uint8Array(32).fill(0xab))
// raw.schema === undefined, raw.bytes === the original buffer

Verification

  • pnpm build — passes, new types appear in dist/chains/stellar
  • pnpm test test/chains/stellar/memo/schema.test.ts — 33/33 pass
  • All existing Stellar tests continue to pass (unaffected)

Closes #140

@lockoabosede8-byte
lockoabosede8-byte changed the base branch from main to develop July 24, 2026 11:00
@drips-wave

drips-wave Bot commented Jul 24, 2026

Copy link
Copy Markdown

@lockoabosede8-byte Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@lockoabosede8-byte

Copy link
Copy Markdown
Author

@truthixify, CI is failing on 2 pre-existing issues unrelated to this PR.

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.

Memo-encoded structured metadata schema

1 participant