-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathhtlc.equity
35 lines (31 loc) · 1.51 KB
/
htlc.equity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-License-Identifier: AGPL-3.0
/**
* @title Hash Time Lock Contract (HTLC)
*
* @author Meheret Tesfaye Batu <[email protected]>
*
* HTLC -> A Hash Time Lock Contract is essentially a type of payment in which two people
* agree to a financial arrangement where one party will pay the other party a certain amount
* of cryptocurrencies, such as Bitcoin or Vapor assets.
* However, because these contracts are Time-Locked, the receiving party only has a certain
* amount of time to accept the payment, otherwise the money can be returned to the sender.
*
* Hash-Locked -> A Hash locked functions like “two-factor authentication” (2FA). It requires
* the intended recipient to provide the correct secret passphrase to withdraw the funds.
*
* Time-Locked -> A Time locked adds a “timeout” expiration date to a payment. It requires
* the intended recipient to claim the funds prior to the expiry. Otherwise, the transaction
* defaults to enabling the original sender of funds to withdraw a refund.
*/
contract HTLC (secret_hash: Hash, recipient_public_key: PublicKey, sender_public_key: PublicKey, endblock: Integer) locks valueAmount of valueAsset {
clause withdraw (preimage: String, signature: Signature) {
verify sha256(preimage) == secret_hash
verify checkTxSig(recipient_public_key, signature)
unlock valueAmount of valueAsset
}
clause refund (signature: Signature) {
verify above(endblock)
verify checkTxSig(sender_public_key, signature)
unlock valueAmount of valueAsset
}
}