Cross-Consensus Atomic Swap
Hash time lock contract, or HTLC for short, is a composition of a hash lock and a time lock.[1] The hash lock authorizes a claim transaction. The time lock authorizes a refund transaction. The result of this contract is either claim or refund for both parties[2], assuming that transactions are timely confirmed by the consensus algorithms. It is also named an atomic swap.
Hash Lock
Hash lock is a cross-consensus authorization mechanism that requires a preimage of a cryptographic hash.
Implemented types:
- BLAKE2b-256
- SHA-256
- Keccak-256
- RIPEMD-160
Time Lock
Time lock is a cross-consensus authorization mechanism that requires a specified consensus time or height to pass.
Implemented types:
- Absolute consensus time
- Absolute consensus height
- Relative consensus time
- Relative consensus height
Summary
Atomic swaps can be seen as two-way cross-consensus communication, albeit limited to exchange of fungible or non-fungible tokens. As well HTLC is a building block of second layer (L2) solutions such as payment channel networks.
RPC API
RPC API implementation is targeted for Blacknet version 0.3.
The proposed API is subject to change due to an issue 144.
Create atomic swap Type POST Path /createswap Parameters mnemonic mnemonic of wallet fee transaction fee amount amount to transfer to address of receiving account timelocktype 0 for absolute time, 1 for absolute height, 2 for relative time, 3 for relative height timelockdata time or height depending on type hashlocktype 0 for BLAKE2b-256, 1 for SHA-256, 2 for Keccak-256, 3 for RIPEMD-160 hashlockdata HEX-encoded hash Returns transaction hash.
Claim atomic swap Type POST Path /claimswap Parameters mnemonic mnemonic of wallet fee transaction fee id address of atomic swap preimage HEX-encoded preimage Returns transaction hash.
Refund atomic swap Type POST Path /refundswap Parameters mnemonic mnemonic of wallet fee transaction fee id address of atomic swap Returns transaction hash.
References
- gmaxwell, Re: P2PTradeX: P2P Trading between cryptocurrencies, .
- satoshi, Re: BitDNS and Generalizing Bitcoin, .