From c782dfe2aadfd06e47ed354c1fb389fecc715433 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 24 Mar 2022 13:06:04 +0100 Subject: first draft of service API for p2p payments --- src/exchangedb/exchange-0001.sql | 3 ++ src/include/taler_crypto_lib.h | 4 +++ src/include/taler_exchange_service.h | 56 ++++++++++++++++++++++-------------- src/util/wallet_signatures.c | 13 +++++++++ 4 files changed, 55 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql index 5acb8995b..e723a3677 100644 --- a/src/exchangedb/exchange-0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -1540,6 +1540,7 @@ COMMENT ON COLUMN close_requests.close_val CREATE TABLE IF NOT EXISTS purse_deposits (purse_deposit_serial_id BIGSERIAL UNIQUE + ,partner_serial_id INT8 REFERENCES partners(partner_serial_id) ON DELETE CASCADE ,purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32) ,coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE ,amount_with_fee_val INT8 NOT NULL @@ -1549,6 +1550,8 @@ CREATE TABLE IF NOT EXISTS purse_deposits ); -- partition by purse_pub, plus a materialized index by coin_pub! COMMENT ON TABLE purse_deposits IS 'Requests depositing coins into a purse'; +COMMENT ON COLUMN purse_deposits.partner_serial_id + IS 'identifies the partner exchange, NULL in case the target purse lives at this exchange'; COMMENT ON COLUMN purse_deposits.purse_pub IS 'Public key of the purse'; COMMENT ON COLUMN purse_deposits.coin_pub diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index ba7f05bcf..7117c67fe 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -2727,6 +2727,7 @@ TALER_wallet_purse_status_verify ( /** * Sign a request to deposit a coin into a purse. * + * @param exchange_base_url URL of the exchange hosting the purse * @param purse_pub purse’s public key * @param amount amount of the coin's value to transfer to the purse * @param coin_priv key identifying the coin to be deposited @@ -2734,6 +2735,7 @@ TALER_wallet_purse_status_verify ( */ void TALER_wallet_purse_deposit_sign ( + const char *exchange_base_url, const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_Amount *amount, const struct TALER_CoinSpendPrivateKeyP *coin_priv, @@ -2743,6 +2745,7 @@ TALER_wallet_purse_deposit_sign ( /** * Verify a purse deposit request. * + * @param exchange_base_url URL of the exchange hosting the purse * @param purse_pub purse’s public key * @param amount amount of the coin's value to transfer to the purse * @param coin_pub key identifying the coin that is being deposited @@ -2751,6 +2754,7 @@ TALER_wallet_purse_deposit_sign ( */ enum GNUNET_GenericReturnValue TALER_wallet_purse_deposit_verify ( + const char *exchange_base_url, const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_Amount *amount, const struct TALER_CoinSpendPublicKeyP *coin_pub, diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 229ab9e9e..2c52e366c 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -4104,7 +4104,7 @@ struct TALER_EXCHANGE_PurseDeposit /** * Hash of the denomination's public key. */ - struct TALER_DenominationHash h_denom_pub; + struct TALER_DenominationHashP h_denom_pub; /** * Amount of the coin to transfer into the purse. @@ -4144,7 +4144,7 @@ TALER_EXCHANGE_purse_create_with_deposit ( const struct TALER_Amount *purse_value_after_fees, unsigned int num_deposits, const struct TALER_EXCHANGE_PurseDeposit *deposits, - TALER_EXCHANGE_PurseCreateCallback cb, + TALER_EXCHANGE_PurseCreateDepositCallback cb, void *cb_cls); @@ -4155,7 +4155,7 @@ TALER_EXCHANGE_purse_create_with_deposit ( */ void TALER_EXCHANGE_purse_create_with_deposit_cancel ( - struct TALER_EXCHANGE_PurseCreateHandle *pch); + struct TALER_EXCHANGE_PurseCreateDepositHandle *pch); /** @@ -4198,7 +4198,12 @@ struct TALER_EXCHANGE_AccountMergeHandle; * with a reserve. * * @param ctx the context - * @param url HTTP base URL for the exchange + * @param url HTTP base URL for the exchange with the purse + * @param reserve_exchange_url base URL of the exchange with the reserve + * @param reserve_priv private key of the reserve to merge into + * @param purse_pub public key of the purse to merge + * @param merge_priv private key granting us the right to merge + * @param merge_timestamp when is the merge happening (current time) * @param cb function to call with the exchange's result * @param cb_cls closure for @a cb * @return the request handle; NULL upon error @@ -4207,11 +4212,12 @@ struct TALER_EXCHANGE_AccountMergeHandle * TALER_EXCHANGE_account_merge ( struct GNUNET_CURL_Context *ctx, const char *url, + const char *reserve_exchange_url, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_PurseMergePrivateKeyP *merge_priv, struct GNUNET_TIME_Timestamp merge_timestamp, - TALER_EXCHANGE_PurseCreateCallback cb, + TALER_EXCHANGE_AccountMergeCallback cb, void *cb_cls); @@ -4271,6 +4277,7 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle; * @param contract_terms contract the purse is about * @param min_age minimum age we need to prove for the purse * @param purse_expiration when will the unmerged purse expire + * @paran merge_timestamp when should the merge happen (use current time) * @param purse_value_after_fees target amount in the purse * @param cb function to call with the exchange's result * @param cb_cls closure for @a cb @@ -4280,11 +4287,12 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle * TALER_EXCHANGE_purse_create_with_merge ( struct GNUNET_CURL_Context *ctx, const char *url, - const struct TALER_PurseReservePrivateKeyP *reserve_priv, + const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PurseContractPrivateKeyP *purse_priv, const json_t *contract_terms, uint32_t min_age, struct GNUNET_TIME_Timestamp purse_expiration, + struct GNUNET_TIME_Timestamp merge_timestamp, const struct TALER_Amount *purse_value_after_fees, TALER_EXCHANGE_PurseCreateMergeCallback cb, void *cb_cls); @@ -4317,16 +4325,16 @@ struct TALER_EXCHANGE_PurseDepositResponse }; /** - * Function called with information about a deposit-into-purse + * Function called with information about a purse-deposit * operation. * * @param cls closure - * @param pcr HTTP response data + * @param pdr HTTP response data */ typedef void (*TALER_EXCHANGE_PurseDepositCallback) ( void *cls, - const struct TALER_EXCHANGE_PurseDepositResponse *amr); + const struct TALER_EXCHANGE_PurseDepositResponse *pdr); /** @@ -4336,35 +4344,41 @@ struct TALER_EXCHANGE_PurseDepositHandle; /** - * Inform the exchange that a purse should be merged - * with a reserve. + * Inform the exchange that a deposit should be made into + * a purse. * * @param ctx the context - * @param url HTTP base URL for the exchange + * @param url HTTP base URL for the exchange where we make the deposit + * @param purse_exchange_url base URL of the exchange hosting the purse + * @param purse_pub public key of the purse to merge + * @param min_age minimum age we need to prove for the purse + * @param num_deposits length of the @a deposits array + * @param deposits array of deposits to make into the purse * @param cb function to call with the exchange's result * @param cb_cls closure for @a cb * @return the request handle; NULL upon error */ -struct TALER_EXCHANGE_AccountMergeHandle * -TALER_EXCHANGE_account_merge ( +struct TALER_EXCHANGE_PurseDepositHandle * +TALER_EXCHANGE_purse_deposit ( struct GNUNET_CURL_Context *ctx, const char *url, - const struct TALER_ReservePrivateKeyP *reserve_priv, + const char *purse_exchange_url, const struct TALER_PurseContractPublicKeyP *purse_pub, - const struct TALER_PurseMergePrivateKeyP *merge_priv, - struct GNUNET_TIME_Timestamp merge_timestamp, - TALER_EXCHANGE_PurseCreateCallback cb, + uint32_t min_age, + unsigned int num_deposits, + const struct TALER_EXCHANGE_PurseDeposit *deposits, + TALER_EXCHANGE_PurseDepositCallback cb, void *cb_cls); /** - * Cancel #TALER_EXCHANGE_account_merge() operation. + * Cancel #TALER_EXCHANGE_purse_deposit() operation. * * @param amh handle of the operation to cancel */ void -TALER_EXCHANGE_account_merge_cancel ( - struct TALER_EXCHANGE_AccountMergeHandle *amh); +TALER_EXCHANGE_purse_deposit_cancel ( + struct TALER_EXCHANGE_PurseDepositHandle *amh); #endif /* _TALER_EXCHANGE_SERVICE_H */ diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c index 097b8ed8a..756856d2a 100644 --- a/src/util/wallet_signatures.c +++ b/src/util/wallet_signatures.c @@ -902,11 +902,17 @@ struct TALER_PurseDepositPS */ struct TALER_PurseContractPublicKeyP purse_pub; + /** + * Hash of the base URL of the exchange hosting the + * @e purse_pub. + */ + struct GNUNET_HashCode h_exchange_base_url; }; void TALER_wallet_purse_deposit_sign ( + const char *exchange_base_url, const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_Amount *amount, const struct TALER_CoinSpendPrivateKeyP *coin_priv, @@ -918,6 +924,9 @@ TALER_wallet_purse_deposit_sign ( .purse_pub = *purse_pub, }; + GNUNET_CRYPTO_hash (exchange_base_url, + strlen (exchange_base_url) + 1, + &pm.h_exchange_base_url); TALER_amount_hton (&pm.coin_amount, amount); GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv, @@ -928,6 +937,7 @@ TALER_wallet_purse_deposit_sign ( enum GNUNET_GenericReturnValue TALER_wallet_purse_deposit_verify ( + const char *exchange_base_url, const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_Amount *amount, const struct TALER_CoinSpendPublicKeyP *coin_pub, @@ -939,6 +949,9 @@ TALER_wallet_purse_deposit_verify ( .purse_pub = *purse_pub, }; + GNUNET_CRYPTO_hash (exchange_base_url, + strlen (exchange_base_url) + 1, + &pm.h_exchange_base_url); TALER_amount_hton (&pm.coin_amount, amount); return GNUNET_CRYPTO_eddsa_verify ( -- cgit v1.2.3