Swap keys and preimages
The SDK derives everything a swap needs on your side from your wallet mnemonic. No key material is sent to the maker.- Swap mnemonic.
SwapMasterKey.fromWalletMnemonic(walletMnemonic, network)derives a BIP85 child (index 26589) of the wallet mnemonic. That child is the swap mnemonic. Persist it (swapMnemonic()) and reload it later withfromSwapMnemonic, so the wallet mnemonic itself is not needed for every swap. - Per-swap material.
deriveSwapKey(index)returns a key pair andderivePreimage(index)returns a preimage with itssha256hash.
bigint in TypeScript (0n, not 0).
Which key does what:
swapAuth: store it with the swap
Every create response from the KaleidoSwap maker carries a swapAuth, a per-swap credential issued once. It authorizes:
- accepting a chain-swap re-quote (
acceptQuote), and - cooperative refunds (pass it in the refund parameters).
swap.id instead. Nothing re-issues it on request. If it is lost, the swap still has its script-path refund after the timeout, and the signed recovery flow below can recover it with the swap’s key.
Store the whole create response with toJson(swap); swapAuth is part of it. Move funds between chains shows it in use.
Restoring swaps
SwapMasterKey.restore(client) asks the maker for every swap created with keys from this swap mnemonic. restoreIndex(client) returns the highest index the maker has seen. Both use the account xpub (masterXpub()) and accept an optional gap limit.
TypeScript
client.swapRestore or client.swapRestoreIndex directly with masterXpub(), pass "m" as the derivation path. Without it the maker searches a different set of keys and can return nothing.
Keep your own highest index as well. Restore is bounded by the gap limit, so an empty result does not prove that an index was never used.
Rebuilding a script from a restored swap
SwapScript.fromRestored(entry, ourPublicKey, network, side?) rebuilds and validates the swap script from a restore entry, without the original create response:
TypeScript
Recovering swapAuth
Restore returns swap records, not credentials. Recover each credential with the restored swap’s key, then save it:
TypeScript
swapAuth.