Design Doc 013: Customer-to-Customer Payments ############################################# Summary ======= This design document proposes an extension of the Taler protocol that allows payments from customer-to-customer without a merchant. Motivation ========== To be usable as an electronic payment system with cash-like properties, customers should be able to transfer money between themselves without needing to setup anything beyond their wallet(s). This will be used for payments via e-mail and other messaging apps, as well as possibly for transfers via NFC/QR code between mobile phones. Requirements ============ * The protocol must permit transacting arbitrary amounts in any currency, as long as both parties trust the exchange involved. * The control data for customer-to-customer payments should be small enough to fit into a QR code or short message (so ideally less than 64 bytes). * No other direct communication channel between payer and payee should be required. * The customer-to-customer payment must be possible without trusting the other party beyond the point where the money has been received by the payee. Thus, sharing of coin private keys is not sufficient, we need transactional semantics resulting in exclusive control over the funds by the recipient. * The customer-to-customer payment protocol must not allow users to circumvent income transparency. That is, each customer-to-customer transaction must be visible on a KYCed transaction ledger (such as a bank account). * The money received via a customer-to-customer payment must be usable for further Taler payments with minimal delay (after KYC). * Two payment scenarios must be possible: (1) one where the payee first transmits a proposal to the payer (request-to-pay) that the payer accepts by making the payment, and (2) completely uni-directional payments where the payer includes a proposal with the payment and the payee accepts the proposal by taking the offered payment. * If the payment fails (i.e. the receiver refuses to accept the money or the message is lost), the payer must automatically recover the funds (minus applicable fees) without the need for further communication. * If funds flow back to the payer due to an aborted payment, it must be provable for the payer that these funds were not income but merely an aborted transaction. Furthermore, in this case, no KYC should be required from the payer. * If a payment would partially succeed, i.e. because the payer inadvertedly used some double-spent coins and some valid coins, this must fail before the uni-directional communication and be correctable payer-side. * The usual properties of Taler (everything auditable, unlinkability, high-performance in terms of CPU, bandwidth, latency, storage requirements, and the ability to levy fees on every operation that is costly for the exchange) need to be preserved. * The system must handle the case where a customer no longer intends to use the KYCed account (due to disuse, death, or key compromise). New Terminology =============== * An ``account`` is a non-expiring reserve for which entity knowing the reserve private key has completed a KYC procedure sufficient to enable receiving income under that address. * A ``purse`` is a public-private key pair where the public key is an exchange address from which any owners of an account can pick up an amount left at a ``purse`` assuming they know the purse private key. * A ``wad`` is an exchange-to-exchange wire transfer that wires money into a group of accounts at the target exchange. Proposed Solution ================= A complete solution for customer-to-customer payments consists of three possible operational flows. Account creation and withdrawal ------------------------------- 1. The payee generates an account key, which also yields a ``payto://taler/$EXCHANGE_BASE_URL/$ACCOUNT_PUB`` target address (for which the payee knows the corresponding account private key). 2. When withdrawing from an account, the exchange first checks if the customer has satisfied the KYC requirements. If not, the customer is redirected to a Web page where they can perform the necessary KYC operation. 3. For this, the exchange wire gateway is extended with a request to check the KYC status of a customer based on an ACCOUNT_PUB. Possible replies are in-progress and succeeded. An in-progress status should be accompanied with information how the customer may complete the KYC check. 4. A new exchange endpoint ``/account/$ACCOUNT_PUB/kyc`` allows wallets to request a KYC for an ACCOUNT_PUB. Such a request may include the requirement to pay a **KYC fee**. The KYC fee may be charged to that account (if it exists), or could be waved if the account was established via a wire transfer from a partner bank. 5. If the account owner fails to perform the KYC check, the funds in an account remain inaccessible. After a configurable duration, the funds may be considered forfeit and become the property of the exchange where the account is located. 6. When requesting an account's history (which can get quite long), the exchange only returns the last 3 months of data. Requesting the full history requires paying an **account history fee** (which is not done via a 402, but simply charged to the account when requested; full account histories for accounts with an insufficient balance cannot be requested -- except of course the wallet could simply top up the account balance first, see below). 7. If the exchange has received a **deposit** or **merge** into an account, or received an inbound wire transfer from a **wad** matching the account (see below), it adds the respective amount(s) to the account's balance, allowing the KYC'ed customer to withdraw the funds. 8. The account history endpoint should also allow long-polling. Note that long-polling should be limited to short durations, as inbound transfers via ``taler-exchange-wirewatch`` cannot cause the long polling to be resumed, only transfers within the same exchange can benefit from long polling acceleration. Account deletion ---------------- 1. The account owner can delete an account by signing a deletion message with the account private key. 2. This basically resets the KYC data at the exchange, preventing further use of the account. This is helpful in case a user is concerned about having accidentally disclosed the account private key to a third party. 3. If funds remain in the account, an error message is generated instead. The user can pass an extra override parameter to delete accounts even if they still contain funds. 4. A related endpoint should exist for the exchange operator, possibly using messages signed with the exchange offline key. This could be useful in case customers died or are otherwise in need for manual intervention that requires an account to be deleted. In this case, remaining funds in the account should be wired to a bank account designated in the message with the offline signature. The audit report should contain a special note for all of these account deletions. Payment into an unknown account ------------------------------- 1. If the payer does not know the payee's account, they can create a **purse** by computing a public-private key pair. 2. The payer then uses the ``/depost`` API to deposit coins into the purse, using ``payto://taler/$PURSE_PUB`` as the target address. Note that the lack of a hostname indicates that the target address is a purse. 3. The payer shares the purse's private key and the base URL of the exchange where the purse was created with the payee. This can be done using a ``taler://purse/BASE_URL/$PURSE_PRIV`` URL. 4. The payee uses the new ``/purse/$PURSE_PUB`` endpoint to retrieve the purse history, which includes all deposits and withdrawals involving the purse. 5. The payee can then POST to ``/purse/$PURSE_PUB/merge`` a request signed by the purse's private key to **merge** the funds into an account. The signature is only over a salted hash of the account public key, thus avoiding disclosure of the account public key in the purse history. The exchange processes the merge request akin to the logic for payments into known accounts, as detailed below, except that no **deposit fees** are charged at this time. The exchange confirms the merge, allowing the payee to instantly affirm to the user that the amount is inbound (even if it may not be instantly available). Payment directly into a known account at the same exchange ---------------------------------------------------------- 1. If the payer knows the payee's account and uses the same exchange, they may perform an ordinary ``/deposit`` operation, paying the usual **deposit fee**. 2. The exchange detects the use of the ``taler`` wire method, and directly credits the target account. Payment into known account at a remote exchange ----------------------------------------------- 1. If the payer knows the payee's account and uses a different exchange, they POST the coins to a new ``/wad/MASTER_PUB`` endpoint using the master public key of the target exchange, including a deposit permission, the base URL of the target exchange, and the target account, paying a **deposit fee** and a new **wad fee**. The **wad fees** can be used to cover the cost of the exchange-to-exchange wire transfer. 2. The payer's exchange creates a **wad** grouping all wad requests, executing the transaction when either the **wad threshold** (maximum number of transactons aggregated per wad) or the **wad delay** (maximum delay for transfers) has been reached. 3. If the (aggregated) wire transfer fails (say the ``/wire`` endpoint of the payee exchange does not resolve to a valid bank account), the originating exchange automatically creates a full refund for all aggregated deposits and **purses** (**refund fees** apply). .. note:: While the **refund fee** amount can be reused, these types of refunds are not approved by a merchant's signature. Thus, we will need a new message type in the coin history to represent these events. 4. The payee's exchange observes the wire transfer and uses a GET ``/wad/{MASTER_PUB}/{WTID}`` request to obtain details about the target accounts. 5. When the payer's exchange is requested to provide information about aggregated transfers under the WTID, it provides a signed list of account public keys and associated amounts that must add up to an amount below the total amount transferred. If they do not, the payee's exchange does not credit any of the accounts and instead preserves the bogus reply (to justify its inaction with its own auditor) and reports the issue to the auditor of the payer's exchange (keeping the received funds for future manual resolution). 6. ``taler-exchange-wirewatch`` and the Taler wire gateway API will need to be extended to allow passing inbound wire transfers with WTID and exchange base URL to the exchange. Furthermore, another tool is needed to lookup the **wad** data at remote exchanges. C2C Payment Metadata -------------------- The standard Taler Customer-to-Merchant payments always use a contract terms JSON object to record the modalities of the payment and the resulting obligations of a successful payment. The contract terms concept does not directly carry over to C2C payments, because: * Either party may initiate the payment * The payee does not have a merchant public key, and at the time of payment initiation, the payee account might not yet be known. * There is no nonce that the customer generates and uses to prove that they uniquely "own" the contract terms. * There is no negotiation of trusted auditors / exchanges possible or necessary. Metadata for C2C payments can be exchanged in two ways: 1. Inline, as part of the payment request / payment offer. 2. As an annotation on the purse, encrypted with the purse's public key. The exchange may charge for storing the annotation. In case of a "payment request purse", the fee should be taken from an account provided by the payee (which may even offer a limited number of free P2P payment initiations per time period). In case of a "payment offer purse", the fee should be taken from the coins deposited into the purse. Examples --------- Cross-exchange C2C payment request: * Bob borrowed 15 Eur from Alice to buy a train ticket. A few days later, Alice wants her money back. She creates a request for payment in her wallet. The wallet creates a pouch for 15 Eur at the only exchange that Alice is currently using. The wallet shows her a ``taler://payment-request/{EXCHANGE_URL}/{POUCH_PRIV}?i=Please+pay+me+Bob`` link that she can share with Bob. Bob receives the link and opens it with his Taler wallet. Bob is using a different EUR exchange than Alice. Bob's wallet makes a ``/wad`` request to his own exchange. Shortly after, Alice's exchange receives the wad from Bob's exchange, and credits the money into Alice's pouch. * How does Bob find out if Alices exchange supports a wad transfer from Bob's exchange? * How does Bob get a "receipt" to prove that he paid Alice? Is some signature from Bob's exchange enough, or should Bob also request a signature for Alice's exchange once the money has arrived? Bob's wallet could poll the purse at Alice's exchange for a receipt. Cross-exchange payment offer: * Carol wants to send some money to Dave as a birthday gift. Carol knows that Dave is using Taler, but she doesn't know which exchange he is using. She opens her Taler wallet and initiates a P2P payment. She sends the ``taler://payment-offer/{EXCHANGE_URL}/{POUCH_PRIV}?i=Happy+Birthday+from+Alice`` in an e-mail to Dave. Dave opens they link in the e-mail with his Taler wallet. Since Dave is using a different exchange than Alice, Dave's wallet issues a ``/wad`` request to Alice's exchange. Shortly after, Dave's exchange receives the wad, and credits Dave's account with the money. State machine for Purses ------------------------ .. code-block:: none // The "OPEN" starte state requires funding // the purse either from an account or from // a coin. -> OPEN // "Filled" means that it is filled with as many coins // as indicated in the creation request. OPEN -> FILLED // Canceled, all coins put into the purse are refunded FILLED -> CLOSED_REFUNDED // Sent via a wad to a different exchange FILLED -> PENDING_WAD // The associated wad transfer succeeded. PENDING_WAD -> CLOSED_WAD // Merged into an account at the same exchange FILLED -> CLOSED_MERGE Additional considerations ------------------------- * Creation of additional accounts per customer can be discouraged by asking for higher fees. * The global transaction volume of one customer can be easily determined by authorities, which can then trigger further audits of the customer * As a technically expensive but more water-tight measure, normal withdrawals from reserves could be disallowed. Instead, a modified refresh protocol could ensure that whoever has knowledge of the account private key can also learn the private keys of coins withdrawn from that account, thereby removing Taler's "one-hop withdrawal loohole". Alternatives ============ * The payer could directly give deposit permissions to the payee. This has two problems: 1. The payer doesn't know the wire details of the payee. Thus we would need to introduce some "wildcard deposit permission", where the exchange allows any wire details on ``/deposit``. 2. The payment information would be rather large, making it difficult to transfer via a QR code or short text message. * Account history exceeding a configurable time limit (like 6 years) could be subject to garbage collection. However, doing so may be difficult to square with onboarding new auditors in the presence of existing accounts, as the auditors could then not reconstruct the account balances from cryptographic proofs. * Accounts without KYC check could be eventually closed. However, even if the coins used to fill the account are refunded, it would be difficult to inform the originating wallet that the coins have received a refund. Thus, it is likely simpler to declare the funds forfeit. Drawbacks ========= The overall changes required are not small: * New **KYC fee**, **wad fee** and **account history fee** required in ``/keys`` endpoint (similar to closing and wire fees), requires some work across toolchain (offline signature, etc.) * New ``taler`` wire method needs special case to possibly bypass (same exchange scenario, with long-poll trigger) the usual aggregation logic. * New exchange table(s) required to store inbound amounts by account. Likely two tables, one for local exchange p2p and one for remote exchange p2p payments. * New exchange table for purses required (for remote p2p payments). * New exchange logic required to make ``transfers`` requests for purses (another separate process). * New ``/account/$ACCOUNT_PUB/kyc`` endpoint required. * New ``/purse/$PURSE_PUB/merge`` endpoint required. * Additional tables to be verified by the auditor. * ``taler-exchange-wirewatch`` needs to support receiving purses closures and exchange-to-exchange wire transfers with WTIDs. Aside from implementation complexity, the solution has the following drawbacks: * If a p2p payment failed (say the receiver lost the account private key), the customer's money can be forfeit. Q / A ===== * Q: Why are direct payments into accounts allowed? * A: Direct payments into accounts are used by the customer to fund the expenses for using the account. They should not be used for payments between customers, as contract terms for the ``/deposit`` of coins can't be negotiated. Furthermore, the sender of the payment can't be sure that the account of the sender is still valid. * Q: Who "owns" a purse? The payer of payee? * Both. Ownership is shared. Either the payer issues a refund on the purse, or the payee claims it by merging it with one of their accounts. * Q: Are purses created with a pre-determined "capacity"? * A: Yes. Otherwise there would be weird failure modes when the payee merges the purse before the payer fully deposited into it. * Q: Are account public keys considered private or public data? * A: Private. Making it public would make it too easy to accidentally send payments that nobody can receive, because the account is wrong/lost. Furthermore, making the account public makes it easy to receive unsolicited payments without consent from the payee. Since Taler should be as cash-like as possible, we might want to avoid that, especially for payees who aren't merchant. * Q: Why do merchant payments not use purses? * Refunds aren't possible with purses after they're closed * Partial refunds aren't possible * the customer can't prove that they own the contract terms (contract terms claiming isn't interactive) * the merchant can't cover deposit fees * (All of these could be addressed, but the resulting protocol isn't necessarily simpler than what we currently have.) * Q: What determines when a wad transfer can happen between two exchanges? * Heuristic: Both share an auditor, and the /wire info indicates that the exchanges both support wad payments over the same protocol.