Skip to content

feat: add compressMetadata, estimateFeeForAmount, buildPaymentMemo helpers (Closes #619, #615, #610) - #629

Open
waterWang wants to merge 2 commits into
Stellar-split:mainfrom
waterWang:feat/619-compress-metadata
Open

feat: add compressMetadata, estimateFeeForAmount, buildPaymentMemo helpers (Closes #619, #615, #610)#629
waterWang wants to merge 2 commits into
Stellar-split:mainfrom
waterWang:feat/619-compress-metadata

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Adds three independent SDK helpers:

#619compressMetadata / decompressMetadata (src/compression.ts)

  • JSON + base64url round-trip with no padding
  • compressMetadata throws StellarSplitError (CONTRACT_REJECTED) when encoded output exceeds maxBytes (default 512)
  • decompressMetadata validates base64url charset, throws StellarSplitError (CONTRACT_REJECTED) on invalid input / JSON

#615estimateFeeForAmount (src/feeEstimator.ts)

  • estimateFeeForAmount(amount, feeStats){ feeLumens, feePercent, totalWithFee }
  • feeLumens stays bigint; totalWithFee = amount + feeLumens; feePercent is 0 for zero amount
  • Throws StellarSplitError (INVALID_RECIPIENT) for negative amount
  • FeeStats type { baseFee, p50Fee, p99Fee } exported

#610buildPaymentMemo / parsePaymentMemo (src/memoBuilder.ts)

  • Canonical split:{invoiceId} format, split:{invoiceId}:t{tranche} when tranche provided
  • Truncated to Stellar's 28-byte text memo limit without cutting a multi-byte UTF-8 character
  • parsePaymentMemo returns null for non-split memos, round-trips both formats

All helpers exported from src/index.ts.

Tests

  • test/compressMetadata.test.ts — 10 tests (round-trip, oversized, invalid base64, empty object)
  • test/estimateFeeForAmount.test.ts — 5 tests (fee calc, bigint, zero amount, negative throw)
  • test/paymentMemo.test.ts — 8 tests (base/tranche format, truncation, round-trip, null)

23/23 tests passing.

Closes #619, #615, #610

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.

Add compressMetadata and decompressMetadata to compression.ts

1 participant