Skip to main content

Types

Shared types for API requests, responses, and swap state.

Re-exports the OpenAPI-generated request/response types and enums, and adds SwapInStatus and SwapOutStatus - discriminated unions keyed by status that model each swap direction's lifecycle, carrying only the fields available in each state.

Enumerations​

Chain​

Enumeration Members​

Enumeration MemberValue
Bitcoin"bitcoin"
Liquid"liquid"

ErrorCode​

Machine-readable code carried beside message in every error response, so a client never infers semantics from the HTTP status.

Enumeration Members​

Enumeration MemberValue
BadRequest"BadRequest"
Forbidden"Forbidden"
InsufficientLiquidity"InsufficientLiquidity"
Internal"Internal"
NotImplemented"NotImplemented"
PayloadTooLarge"PayloadTooLarge"
PolicyError"PolicyError"
QuoteExpired"QuoteExpired"
SwapAlreadyExists"SwapAlreadyExists"
SwapNotFound"SwapNotFound"
TooManyConnections"TooManyConnections"
TransitionRejected"TransitionRejected"
Unavailable"Unavailable"

SwapNetwork​

On-chain network for swap operations.

Enumeration Members​

Enumeration MemberValue
Mainnet"mainnet"
Regtest"regtest"
Signet"signet"
Testnet"testnet"

SwapType​

Swap kind. Directions are relative to Lightning: SwapIn is on-chain to Lightning, SwapOut is Lightning to on-chain, SwapChain is on-chain to on-chain across two different chains.

Enumeration Members​

Enumeration MemberValue
SwapChain"SwapChain"
SwapIn"SwapIn"
SwapOut"SwapOut"

Interfaces​

ApiError​

Error body returned by the server on a non-2xx response. Branch on code rather than message or the HTTP status; the fields are absent only when the body could not be parsed.

Properties​

PropertyType
code?ErrorCode
message?string

AssetPolicyResponse​

Properties​

PropertyType
asset_idstring
max_amountstring
min_amountstring

CancelRequest​

Properties​

PropertyType
cancel_messagestring

ChainPolicyResponse​

Properties​

PropertyTypeDescription
assetPartial<Record<string, AssetPolicyResponse>>-
block_timenumberMin 0
confsnumberMin 0
dest_csvnumberCSV timelock on a swap-out opening tx, in this chain's blocks. Min 0
min_base_fee_multipliernumberDust-guard floor: minimum receive amount as a multiple of this chain's base fee. Min 0
service_ppmnumberMin 0
source_csvnumberCSV timelock on a swap-in opening tx, in this chain's blocks. Min 0
timeoutsTimeoutResponseDeadlines this chain enforces as a SwapIn source, in seconds. A swap left in the matching status past its deadline is canceled. SwapOut has no deadline here: once its opening tx confirms, the bound is the dest_csv timelock in blocks.

CreateSwapRequest​

Body of createSwap. As the service documents it, amounts as decimal strings, except that webhook.statuses are typed to the statuses a swap can reach, so a misspelled one fails to compile.

Extends​

  • Omit<GeneratedCreateSwapRequest, "webhook">

Properties​

PropertyTypeDescriptionInherited from
claim_invoice?string | nullswap-in only.Omit.claim_invoice
dest_asset_id?string | null-Omit.dest_asset_id
dest_blinding_pubkey?string | nullswap-out and swap-chain, Liquid only.Omit.dest_blinding_pubkey
dest_chain?Chain | null-Omit.dest_chain
dest_claim_pubkey?string | nullswap-out and swap-chain.Omit.dest_claim_pubkey
payment_hash?string | nullswap-out and swap-chain: preimage hash for the destination HTLC.Omit.payment_hash
protocol_versionstring-Omit.protocol_version
quote_id?string | nullOptional GET /v1/info quote locking the base fee.Omit.quote_id
receive_amountstring-Omit.receive_amount
send_amountstring-Omit.send_amount
source_asset_id?string | null-Omit.source_asset_id
source_blinding_pubkey?string | nullswap-in and swap-chain, Liquid only.Omit.source_blinding_pubkey
source_chain?Chain | null-Omit.source_chain
source_refund_pubkey?string | nullswap-in and swap-chain.Omit.source_refund_pubkey
swap_idstring-Omit.swap_id
user_claim_address?string | nullswap-out and swap-chain.Omit.user_claim_address
user_idstring-Omit.user_id
user_refund_address?string | nullswap-in and swap-chain.Omit.user_refund_address
webhook?SwapWebhook<SwapStatus> | nullStatus webhook to register with the swap.-

FeeEstimate​

Properties​

PropertyType
deststring
sourcestring

InfoResponse​

Properties​

PropertyTypeDescription
fee_estimates?Partial<Record<"bitcoin" | "liquid", FeeEstimate>>-
onlinebooleanWhether the Lightning node pays and receives; false while it runs in offline mode.
policyPolicy-
quote_id?string | null-
quote_ttlnumberSeconds a quote_id stays valid once issued. Min 0
webhook?WebhookInfo-

LightningPolicyResponse​

Properties​

PropertyTypeDescription
max_amountstring-
min_amountstring-
service_ppmnumberMin 0

OutPoint​

On-chain opening-transaction output that funds a swap.

Properties​

PropertyTypeDescription
txidstringOpening transaction id.
voutnumberOpening transaction output index.

Pagination​

Properties​

PropertyTypeDescription
has_nextboolean-
limitnumberMin 0
offsetnumberMin 0
totalnumberMin 0

Policy​

Properties​

PropertyTypeDescription
chainPartial<Record<"bitcoin" | "liquid", ChainPolicyResponse>>-
invoice_expirynumberMin 0
lightningLightningPolicyResponse-
networkSwapNetworkOn-chain network for swap operations.
protocol_versionstring-

RevealClaimRequest​

Properties​

PropertyType
source_refund_privkeystring

RevealPreimageRequest​

Properties​

PropertyType
preimagestring

SwapListQuery​

Filters for GET /v1/swap. They intersect, and all of them apply before limit and offset, so Pagination::total counts what they matched. A filter sent with nothing in it means the same as one left out.

Properties​

PropertyTypeDescription
created_after?number | nullKeeps swaps created at or after this unix timestamp, in seconds. Min 0
created_before?number | nullKeeps swaps created at or before this unix timestamp, in seconds. Min 0
error_type?string | nullComma-separated cancellation reasons to keep, e.g. UserCanceled,Timeout. Only a cancelled swap has one, so this filters out every other swap too.
is_active?boolean | nulltrue keeps only active swaps, false only finished ones; omit for both.
limitnumberPage size, at most 100. A larger one is rejected, not clamped. Min 0 Max 100
max_amount?number | nullKeeps swaps whose receive_amount is at most this many sats. Min 0
min_amount?number | nullKeeps swaps whose receive_amount is at least this many sats. Min 0
offsetnumberMin 0
search?string | nullKeeps swaps where swap_id, payment_hash, claim_invoice, source_txid, dest_txid, or user_claim_address equals this value. The match ignores case but is exact, not a prefix.
status?string | nullComma-separated FSM statuses to keep, e.g. Claimed,Refunded.
swap_type?string | nullKeeps only swaps of this type: SwapIn, SwapOut, or SwapChain.
user_idstring-
with_create_request?booleantrue carries each swap's create_request_* fields as GET /v1/swap/{id} does; a page omits them otherwise.

SwapListResponse​

Properties​

PropertyType
paginationPagination
swapsSwapState[]

SwapState​

Properties​

PropertyTypeDescription
base_feestring-
cancel_message?string | null-
claim_invoice?string | null-
create_request_body?string | nullThe POST /v1/swap body this swap was created from, verbatim. With the two fields below it lets a client verify the swap's terms against its own signature rather than against this response. Returned by GET /v1/swap/{id}, and by the listing under with_create_request.
create_request_signature?string | nullHex of the 64-byte Schnorr signature over that request.
create_request_timestamp?number | null-
created_atnumberMin 0
dest_asset?string | null-
dest_chain?Chain | null-
dest_claim_pubkey?string | null-
dest_csv?number | nullMin 0
dest_refund_privkey?string | null-
dest_refund_pubkey?string | null-
dest_service_blinding_pubkey?string | nullLiquid: anyswap's blinding pubkey for the destination output.
dest_txid?string | null-
dest_user_blinding_pubkey?string | nullLiquid: the user's blinding pubkey for the destination output.
dest_vout?number | nullMin 0
error_type?string | null-
payment_hashstring-
preimage?string | null-
protocol_versionstring-
receive_amountstring-
send_amountstring-
service_feestring-
source_asset?string | null-
source_chain?Chain | null-
source_claim_privkey?string | null-
source_claim_pubkey?string | null-
source_csv?number | nullMin 0
source_refund_pubkey?string | null-
source_service_blinding_pubkey?string | nullLiquid: anyswap's blinding pubkey for the source output.
source_txid?string | null-
source_user_blinding_pubkey?string | nullLiquid: the user's blinding pubkey for the source output.
source_vout?number | nullMin 0
statusstring-
swap_idstring-
swap_typeSwapTypeSwap kind. Directions are relative to Lightning: SwapIn is on-chain to Lightning, SwapOut is Lightning to on-chain, SwapChain is on-chain to on-chain across two different chains.
transitioned_atnumberMin 0
user_claim_address?string | null-
user_refund_address?string | null-

SwapStateUpdate​

Properties​

PropertyType
statusstring
swap_idstring

SwapWebhook​

Status webhook registered with a swap and fixed for its lifetime. The service POSTs { event: "swap.update", data: { id, status } } to url on every subscribed change. Deliveries are unsigned, unordered, and not guaranteed: treat one as a prompt to read getSwap, not as state.

S bounds statuses; SwapInWebhook and SwapOutWebhook pin it to one direction.

Type Parameters​

Type ParameterDefault type
S extends SwapStatusSwapStatus

Properties​

PropertyTypeDescription
hash_swap_id?booleanSend the SHA256 of the swap id instead of the id itself.
statuses?S[]Statuses to deliver. Omitted or empty delivers every status change.
urlstringDestination the service posts to, at most 250 characters.

TimeoutResponse​

Deadlines this chain enforces as a SwapIn source, in seconds. A swap left in the matching status past its deadline is canceled. SwapOut has no deadline here: once its opening tx confirms, the bound is the dest_csv timelock in blocks.

Properties​

PropertyTypeDescription
await_claim_key_reveal_messagenumberDeadline to reveal the cooperative claim key. Min 0
await_opening_txnumberMaximum wait for the opening tx to appear at the swap address and confirm. The claim invoice expiry may end it sooner. Min 0

WebhookInfo​

Properties​

PropertyTypeDescription
enabledbooleanWhether this node accepts webhook registrations.
https_requiredbooleanWhether a registered url must use https.

Type Aliases​

SwapEndpoint​

type SwapEndpoint =
| {
asset?: string;
chain: Chain;
}
| "lightning";

A swap endpoint: an on-chain asset, or Lightning.

asset is the policy label the server files the asset under in policy.chain[chain].asset, not the on-chain id. It defaults to NATIVE_ASSET, which is the only label the server currently accepts. The id that goes on the wire as source_asset_id / dest_asset_id is a separate value, which the driver reads from the server's policy; destAsset resolves a destination's.


SwapErrorCode​

type SwapErrorCode =
| "UserCanceled"
| "Timeout"
| "TxValidationFailed"
| "PayInvoiceFailed"
| "TxBroadcastFailed";

Machine-readable reason a swap reached Canceled, carried by errorCode alongside the human-readable cancelMessage. Each maps to the terminal event that canceled the swap.

  • UserCanceled: the user aborted the swap.
  • Timeout: a waiting state's deadline elapsed.
  • TxValidationFailed (swap-in): two or more deposits paid the exact swap amount, so the service could not tell which to claim.
  • PayInvoiceFailed (swap-in): the claim invoice payment failed terminally.
  • TxBroadcastFailed (swap-out): the destination opening tx was never broadcast.

SwapInStatus​

type SwapInStatus =
| {
status: "AwaitOpeningTxConfirmation";
}
| {
outpoint: OutPoint;
status: "PayInvoice";
}
| {
outpoint: OutPoint;
preimage: string;
status: "AwaitClaimKeyRevealMessage";
}
| {
outpoint: OutPoint;
status: "AwaitClaimTxConfirmation";
}
| {
outpoint: OutPoint;
status: "Claimed";
}
| {
cancelMessage: string;
claimPrivkey: string;
errorCode: SwapErrorCode;
status: "Canceled";
};

Swap-in lifecycle state, discriminated by status. Each variant carries only the fields available in that state, so narrowing on status exposes them safely. Normal flow: AwaitOpeningTxConfirmation -> PayInvoice -> AwaitClaimKeyRevealMessage -> AwaitClaimTxConfirmation -> Claimed. The server discovers the deposit by watching the swap address, so there is no announcement step and AwaitOpeningTxConfirmation carries no outpoint. AwaitClaimKeyRevealMessage carries the preimage the server obtained by paying the invoice, which the driver checks before revealing the refund key. Canceled is terminal: errorCode is the machine-readable reason, and the server reveals its claimPrivkey; the user finds the deposit by re-deriving the swap address and refunds it.


SwapInWebhook​

type SwapInWebhook = SwapWebhook<SwapInStatus["status"]>;

SwapWebhook restricted to the swap-in lifecycle.


SwapOutStatus​

type SwapOutStatus =
| {
status: "AwaitClaimInvoicePay";
}
| {
status: "OpeningTxBroadcast";
}
| {
outpoint: OutPoint;
status: "AwaitPreimageRevealed";
}
| {
outpoint: OutPoint;
status: "AwaitRefundTxConfirmation";
}
| {
outpoint: OutPoint;
refundPrivkey: string;
status: "Claimed";
}
| {
cancelMessage: string;
errorCode: SwapErrorCode;
status: "Canceled";
}
| {
outpoint: OutPoint;
status: "Refunded";
};

Swap-out lifecycle state, discriminated by status. Normal flow: AwaitClaimInvoicePay -> OpeningTxBroadcast -> AwaitPreimageRevealed -> Claimed (the server reveals refundPrivkey for a cooperative keypath claim). If the user never claims: AwaitRefundTxConfirmation -> Refunded. Canceled is terminal.


SwapOutWebhook​

type SwapOutWebhook = SwapWebhook<SwapOutStatus["status"]>;

SwapWebhook restricted to the swap-out lifecycle.


SwapStatus​

type SwapStatus =
| SwapInStatus["status"]
| SwapOutStatus["status"];

Every status either flow reports, derived from SwapInStatus and SwapOutStatus so it cannot drift from them. Used to filter a swap listing by status.

Variables​

NATIVE_ASSET​

const NATIVE_ASSET: "native" = "native";

Policy label for a chain's native asset (BTC on Bitcoin, L-BTC on Liquid). The server keys its per-chain asset policy under this label, and execution is single-asset, so it is the only label a swap can name.

On Bitcoin it doubles as the on-chain asset id: source_asset_id is literally "native". On Liquid the id is the asset's 32-byte hex instead, which lives in policy.chain.liquid.asset.native.asset_id. Use destAsset rather than hardcoding this constant as an asset id.