Skip to main content
The SDK does not verify or sign anything. Never sign a transaction returned by the SDK without @lumenwipe/verify or an equivalent check of your own.
Closing an account is irreversible: it merges every remaining lumen into one destination. Every transaction the SDK returns is unsigned XDR built by the API from the data you provided. Before signing, your code must independently confirm that the transaction does exactly what the user asked.

Use @lumenwipe/verify

@lumenwipe/verify is the verifier the LumenWipe web app runs before every signature, as a package. It is compiled from the web’s own verify.ts, not ported, so there is one implementation. A shared set of conformance vectors runs against the package and against the web verifier in CI.
@stellar/stellar-sdk is a peer dependency, pinned to the version the web verifier is tested with, and is never bundled. Upgrade @lumenwipe/verify together with @lumenwipe/sdk: the API can start building a close an older verifier refuses, such as a classic liquidity pool withdrawal. Pass it as verify to runClose:
verifyCloseTransaction returns only when the transaction may be signed, and throws VerificationError otherwise. It is synchronous and reads no network.

Refusal codes

Every VerificationError carries a code (type VerificationErrorCode) next to its message. Branch on the code: it names the reason and stays stable across releases, while the message is English wording that may change. A rule that applies to several kinds of operation, such as the fee cap or the operation source, has one code for all of them.

Where each input comes from

Never take an input from the transaction under verification or from its intent summary. The values from the account read come from the same API that builds the transaction, so they catch a builder bug or a partial compromise, not an API that keeps both consistent.

What the package decides on its own

Whether the destination is a listed exchange, whether it needs a memo and of which type, and whether the merge must go through the shared mediator are not inputs. The package derives them from the exchange registry bundled in its release. It never fetches the copy the API serves itself. Without a snapshot:
  • An exchange listed after the release you installed is checked as a plain wallet, so a direct merge to it passes with whatever memo the user typed. Upgrade on every release.
  • Once the bundled registry’s validUntil date passes, every close to a listed exchange is refused until you upgrade.

Passing the served registry

Pass the body of GET /v1/config/exchange-registry as servedRegistry to narrow both gaps:
The snapshot is merged over the bundled registry with the same stricter-only rule the web client applies to the copy it is served. Pass it as served, signature included. Without a signature that verifies, it is not authenticated, and it comes from the same API that builds the transaction, so it is trusted only for what can make verification stricter: The mediated hand-off is limited to the exchanges bundled in the package for the close’s network and to the exchanges a snapshot with a verified signature adds. requiresMediator(address, network, servedRegistry?) answers by the same rule, so pass it the snapshot you pass to verifyCloseTransaction. A bundled entry marked "network": "testnet" is listed on testnet only: on mainnet requiresMediator answers false for it and a close to it is checked as a close to a plain wallet. An address an unsigned snapshot lists as needing the mediator refuses both a direct merge and the hand-off until you upgrade: accepting the hand-off on unauthenticated data would let the API, which also reports the balance the forward is checked against, route any close through an intermediary it names.

The signature

The API serves the registry with a signature: an Ed25519 signature, by one of two registry keys pinned in this package’s release, over the registry (version, lastVerified, validUntil, source, entries), a sequence and an issuedAt date. It verifies only when a pinned key made it, its sequence is at least the sequence of the registry bundled in this release (an older signed registry is never accepted), validUntil has not passed by your clock (the whole day counts), and issuedAt is no more than a day ahead of your clock. A missing, truncated, forged, stale or otherwise failing signature does not refuse the close: the snapshot is treated as unsigned, exactly as above. A verified signature lets the snapshot add exchanges that need the mediated hand-off, and nothing else: it changes no bundled entry, no memo type and no network scope. It gates the mediated shape; it does not vouch for the account a mediated close merges into, which the transaction’s structural checks bound. The keys are pinned in the release, so rotating one is a release of this package. The keys and the signing procedure are in the security scope, and vectors/registry-signing-v1.json holds conformance vectors for the signature scheme. An entry that is not well formed is dropped; a snapshot that is not a registry is refused with registry_snapshot_invalid. It also reads the system clock: a transaction valid for more than 900 seconds from now is refused.

Conformance vectors

The package ships vectors/close-v1.json: accepted and rejected transactions with the full input for each, the clock to set, and for each rejection the VerificationError code and exact message. Match on error.code; the message is asserted too, as the current wording. Every rejection is one named mutation of an accepted vector (its transaction, its servedRegistry snapshot, or both), and every key in the file is public. Pass input.servedRegistry to the verifier when a vector carries one, and decode each transaction for input.network: most vectors are on testnet, and the ones about the testnet-only registry entry also run on mainnet. Run them against your own verifier, or against a wrapper around this one.

Why

LumenWipe’s architecture puts the trust boundary at the signer. The API builds the bytes, and the client decides whether to sign them. If a compromised or faulty API could choose what you sign, it could divert funds. Your own check removes that risk.

What to check if you write your own

Decode the XDR yourself and compare it against your own inputs, never against values from the API response alone. At minimum:
  • The transaction source is the account being closed, and every operation is sourced from it.
  • The account merge goes only to the destination the user stated. For an exchange, the merge goes to the shared mediator, and a forward payment from the mediator goes to the user’s stated address in XLM for at least the observed balance.
  • Payments are only a return to the issuer, a transfer matching the user’s own asset, destination, and amount choice, or the mediator forward.
  • Conversions are to self or to native, with a positive destination minimum.
  • Removals only: trustlines, data entries, and offers.
  • SetOptions never adds a signer or raises a threshold.
  • The memo matches what the user supplied.
  • No unknown operation type. Reject anything you do not recognize rather than signing it.

Mediated closes: the destination is yours to check

The API’s co-sign endpoint checks the structure of the mediated pair, not where it pays. It caps the forward at the merged balance it reads at co-sign time, but it accepts a forward to any address other than the mediator, because it cannot know which exchange address the user meant. It does refuse a forward without a memo to a listed exchange that requires one or to an account whose config.memo_required data entry is set (SEP-29), and a memo of the wrong type to a listed exchange, but it cannot know which memo value the user meant. In the LumenWipe web client, verify() makes that check with the address the user typed. An integration that calls the API or the SDK directly has no such check unless it writes one, so for a mediated close confirm, from your own inputs:
  1. The destination the user entered needs the mediator (a known exchange that cannot receive a merge): requiresMediator(destination, network, servedRegistry) from @lumenwipe/verify answers this from its bundled registry for the close’s network and from a served registry whose signature verifies, never from an unsigned one. Otherwise the merge must go straight to the user’s address and the mediated shape is refused, so an intermediary the API names cannot be slipped into a close to a plain wallet.
  2. The transaction source is the account being closed, with exactly two operations: an accountMerge, then a payment.
  3. The merge is sourced from the account being closed (explicitly, or by inheriting the transaction source).
  4. The payment is sourced from the merge’s destination, the account the merge pays into.
  5. The payment goes to the exchange address the user entered.
  6. The payment is in native XLM.
  7. The payment’s amount is at least the native balance you observed, less a small fee tolerance (the web client allows 0.01 XLM).
  8. The memo and its type match what the user entered and what the exchange requires.
Pinning the mediator’s address in place of step 4 proves which account receives the merge, not that the payment moves the balance on. The threat model states this responsibility and the known forward window (S4a.Elevation.1) next to it. The intent field on a transaction is the API’s own summary. Do not use it as a check.

Reference implementations

  • @lumenwipe/verify, above, is the web client’s verifier as a package.
  • assertCloseIntent in the LumenWipe web client is the source it is compiled from.
  • The headless example wires the package into runClose.
Whatever you write, pass it as verify to runClose so it runs before every signature.