first draft of service API for p2p payments

This commit is contained in:
Christian Grothoff 2022-03-24 13:06:04 +01:00
parent 6ffc2c68a3
commit c782dfe2aa
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 56 additions and 22 deletions

@ -1 +1 @@
Subproject commit 0958add542378a6ca9c411e2dc19527834e9f645
Subproject commit 25eb78f2d0e20a137020dd0ab1c6474123843dbe

View File

@ -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

View File

@ -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 purses 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 purses 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,

View File

@ -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 */

View File

@ -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 (