Technical Details
Secret Generation
A secret is the preimage of the hash used to secure hashed timelock contract (HTLC).
To generate secrets, we utilize a ECDSA signing key (say S) that is generated securely client side and is persisted in user's browser (stored in browser's IndexedDB).
When user visits our URL, client side code inspects if this URL domain has an entry for the signing key. If it's not there, a new one is generated and stored else existing one is used.
At the time of initiating an atomic swap by user, say T, signature is obtained on this timestamp (T) using this signing key (S). This signature is then hashed (using SHA256) to obtain our secret.
Cross-chain Swap
Bitcoin -> Cardano
To initiate an atomic swap from Bitcoin to Cardano, user first needs to send their Bitcoin to a HTLC smart contract on Bitcoin. This smart contract has following parameters:
- SHA256 hash of the secret.
- Public key to get for refunds after timelock expiry. This public key is the public key of the intermediate bitcoin wallet. The intermediate bitcoin wallet is the one whose signing key is
S. Reason of using this intermediate wallet is that it allows client to generate signatures (in this case, if required, signature for refund transaction) without requiring user input thus improving the user-experience. - Public key of the recipient. This is the key of counterparty which is facilitating this swap.
- Timelock timestamp.
Note that before submitting the transaction funding this HTLC smart contract, we generate, sign & store refund transaction so as to allow for refunds in case user loses S which can happen if say, user loses access to their device.
Counterparty then proceeds to lock corresponding wrapped Bitcoins on Cardano guarded by the same secret hash but with significantly shorter timelock. User client would automatically submit the claim transaction when it detects deposit on Cardano, revealing the secret in process which is then used by counterparty to claim funds from Bitcoin contract.
Cardano -> Bitcoin
To initiate an atomic swap from Cardano to Bitcoin, user first needs to send their wrapped Bitcoin to a HTLC smart contract on Cardano. Validator on Cardano side is not parameterized as we make use of datums. Here we are not required to store refund transaction as Cardano supports expressive smart contracts where contract would check if owner is receiving the correct amount of funds back.
Counterparty then proceeds to lock corresponding Bitcoins on Bitcoin network guarded by the same secret hash but with significantly shorter timelock. User client would automatically submit the claim transaction as it would require signature from intermediate bitcoin wallet (avoiding again thus manual user input) when it detects deposit on Bitcoin, revealing the secret in process which is then used by counterparty to claim funds from Cardano validator.