aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2022-03-28 13:19:21 +0200
committerChristian Grothoff <grothoff@gnunet.org>2022-03-28 13:19:40 +0200
commitee4077ef8001e0570a0333ed6b24c69eb2504760 (patch)
tree401d14c8b3b0f5c0a95e00d73dde8f65072c6f95 /src/include
parent30985c09752ca7ed917d737655efa9dc6cade16e (diff)
starting with purse creation client API
Diffstat (limited to 'src/include')
-rw-r--r--src/include/taler_crypto_lib.h60
-rw-r--r--src/include/taler_exchange_service.h220
2 files changed, 257 insertions, 23 deletions
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h
index ef5096405..179c62662 100644
--- a/src/include/taler_crypto_lib.h
+++ b/src/include/taler_crypto_lib.h
@@ -25,6 +25,7 @@
#include <gnunet/gnunet_util_lib.h>
#include "taler_error_codes.h"
#include <gcrypt.h>
+#include <jansson.h>
/**
@@ -2183,6 +2184,48 @@ TALER_refresh_get_commitment (struct TALER_RefreshCommitmentP *rc,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_Amount *amount_with_fee);
+
+/**
+ * Encrypt contract for transmission to a party that will
+ * merge it into a reserve.
+ *
+ * @param purse_pub public key of the purse
+ * @param contract_priv private key of the contract
+ * @param merge_priv merge capability to include
+ * @param contract_terms contract terms to encrypt
+ * @param[out] econtract set to encrypted contract
+ * @param[out] econtract_size set to number of bytes in @a econtract
+ */
+void
+TALER_CRYPTO_contract_encrypt_for_merge (
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ContractDiffiePrivateP *contract_priv,
+ const struct TALER_PurseMergePrivateKeyP *merge_priv,
+ const json_t *contract_terms,
+ void **econtract,
+ size_t *econtract_size);
+
+
+/**
+ * Encrypt contract for the party that will
+ * merge it into a reserve.
+ *
+ * @param purse_pub public key of the purse
+ * @param contract_priv private key of the contract
+ * @param econtract encrypted contract
+ * @param econtract_size number of bytes in @a econtract
+ * @param[out] merge_priv set to merge capability
+ * @return decrypted contract terms, or NULL on failure
+ */
+json_t *
+TALER_CRYPTO_contract_decrypt_for_merge (
+ const struct TALER_ContractDiffiePrivateP *contract_priv,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const void *econtract,
+ size_t econtract_size,
+ struct TALER_PurseMergePrivateKeyP *merge_priv);
+
+
/* **************** Helper-based RSA operations **************** */
/**
@@ -4050,7 +4093,8 @@ struct TALER_AgeCommitmentProof
struct TALER_AgeProof proof;
};
-/*
+
+/**
* @brief Generates a hash of the public keys in the age commitment.
*
* @param commitment the age commitment - one public key per age group
@@ -4061,14 +4105,15 @@ TALER_age_commitment_hash (
const struct TALER_AgeCommitment *commitment,
struct TALER_AgeCommitmentHash *hash);
-/*
+
+/**
* @brief Generates an age commitent for the given age.
*
* @param mask The age mask the defines the age groups
* @param age The actual age for which an age commitment is generated
* @param salt The salt that goes into the key generation. MUST be choosen uniformly random.
* @param comm_proof[out] The generated age commitment, ->priv and ->pub allocated via GNUNET_malloc on success
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
enum GNUNET_GenericReturnValue
TALER_age_restriction_commit (
@@ -4077,13 +4122,14 @@ TALER_age_restriction_commit (
const uint64_t salt,
struct TALER_AgeCommitmentProof *comm_proof);
-/*
+
+/**
* @brief Derives another, equivalent age commitment for a given one.
*
* @param orig Original age commitment
* @param salt Salt to randomly move the points on the elliptic curve in order to generate another, equivalent commitment.
* @param[out] derived The resulting age commitment, ->priv and ->pub allocated via GNUNET_malloc on success.
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
enum GNUNET_GenericReturnValue
TALER_age_commitment_derive (
@@ -4092,13 +4138,13 @@ TALER_age_commitment_derive (
struct TALER_AgeCommitmentProof *derived);
-/*
+/**
* @brief Provide attestation for a given age, from a given age commitment, if possible.
*
* @param comm_proof The age commitment to be used for attestation. For successful attestation, it must contain the private key for the corresponding age group.
* @param age Age (not age group) for which the an attestation should be done
* @param[out] attest Signature of the age with the appropriate key from the age commitment for the corresponding age group, if applicaple.
- * @return GNUNET_OK on success, GNUNET_NO when no attestation can be made for that age with the given commitment, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_NO when no attestation can be made for that age with the given commitment, #GNUNET_SYSERR otherwise
*/
enum GNUNET_GenericReturnValue
TALER_age_commitment_attest (
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index 2c52e366c..cf4624252 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -3978,6 +3978,126 @@ TALER_EXCHANGE_add_auditor_denomination_cancel (
/**
+ * Response generated for a contract get request.
+ */
+struct TALER_EXCHANGE_ContractGetResponse
+{
+ /**
+ * Full HTTP response.
+ */
+ struct TALER_EXCHANGE_HttpResponse *hr;
+
+ union
+ {
+ struct
+ {
+
+ /**
+ * What is the type of the transaction?
+ */
+ enum
+ {
+ /**
+ * This is a request for payment.
+ */
+ TALER_EXCHANGE_CONTRACT_PAYMENT_REQUEST,
+
+ /**
+ * This is a payment, the receiver needs to
+ * accepts the terms.
+ */
+ TALER_EXCHANGE_CONTRACT_PAYMENT_OFFER
+ } type;
+
+ /**
+ * Key material, depending on @e type.
+ */
+ union
+ {
+ /**
+ * Set if @e type is #TALER_EXCHANGE_CONTRACT_PAYMENT_REQUEST.
+ */
+ struct TALER_PurseContractPublicKeyP purse_pub;
+
+ /**
+ * Set if @e type is #TALER_EXCHANGE_CONTRACT_PAYMENT_OFFER.
+ */
+ struct TALER_PurseMergePrivateKeyP merge_priv;
+ } keys;
+
+ /**
+ * Total value of the purse.
+ */
+ struct TALER_Amount amount;
+
+ /**
+ * Contract terms.
+ */
+ json_t *contract_terms;
+
+ /**
+ * Minimum age required to pay for the contract.
+ */
+ uint8_t min_age;
+
+ /**
+ * When will the purse expire?
+ */
+ struct GNUNET_TIME_Timestamp purse_expiration;
+
+ } success;
+ } details;
+
+};
+
+/**
+ * Function called with information about the a purse.
+ *
+ * @param cls closure
+ * @param pgr HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ContractGetCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ContractGetResponse *pgr);
+
+
+/**
+ * @brief Handle for a GET /contracts/$CPUB request.
+ */
+struct TALER_EXCHANGE_ContractsGetHandle;
+
+
+/**
+ * Request information about a contract from the exchange.
+ *
+ * @param ctx the context
+ * @param url HTTP base URL for the exchange
+ * @param contract_priv private key of the contract
+ * @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_ContractGetHandle *
+TALER_EXCHANGE_contract_get (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_ContractDiffiePrivateP *contract_priv,
+ TALER_EXCHANGE_ContractGetCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_contract_get() operation.
+ *
+ * @param cgh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_contract_get_cancel (
+ struct TALER_EXCHANGE_ContractGetHandle *cgh);
+
+
+/**
* Response generated for a purse get request.
*/
struct TALER_EXCHANGE_PurseGetResponse
@@ -3987,12 +4107,36 @@ struct TALER_EXCHANGE_PurseGetResponse
*/
struct TALER_EXCHANGE_HttpResponse *hr;
+ /**
+ * Details depending on the HTTP status.
+ */
union
{
+ /**
+ * Response on #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * Time when the purse was merged (or zero if it
+ * was not merged).
+ */
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+
+ /**
+ * Time when the full amount was deposited into
+ * the purse (or zero if a sufficient amount
+ * was not yet deposited).
+ */
+ struct GNUNET_TIME_Timestamp deposit_timestamp;
+
+ } success;
+
} details;
};
+
/**
* Function called with information about the a purse.
*
@@ -4016,10 +4160,9 @@ struct TALER_EXCHANGE_PurseGetHandle;
*
* @param ctx the context
* @param url HTTP base URL for the exchange
- * @param purse_priv private key of the purse to check
+ * @param purse_priv private key of the purse
* @param merge_timeout how long to wait for a merge to happen
* @param deposit_timeout how long to wait for a deposit to happen
- * @param return_contract true if we should return the contract (if available)
* @param cb function to call with the exchange's result
* @param cb_cls closure for @a cb
* @return the request handle; NULL upon error
@@ -4031,7 +4174,6 @@ TALER_EXCHANGE_purse_get (
const struct TALER_PurseContractPrivateKeyP *purse_priv,
struct GNUNET_TIME_Relative merge_timeout,
struct GNUNET_TIME_Relative deposit_timeout,
- bool return_contract,
TALER_EXCHANGE_PurseGetCallback cb,
void *cb_cls);
@@ -4054,10 +4196,27 @@ struct TALER_EXCHANGE_PurseCreateDepositResponse
/**
* Full HTTP response.
*/
- struct TALER_EXCHANGE_HttpResponse *hr;
+ struct TALER_EXCHANGE_HttpResponse hr;
+ /**
+ * Details depending on the HTTP status.
+ */
union
{
+
+ /**
+ * Detailed returned on #MHD_HTTP_OK.
+ */
+ struct
+ {
+
+ /**
+ * Private key that can be used to obtain the contract.
+ */
+ struct TALER_ContractDiffiePrivateP contract_priv;
+
+ } success;
+
} details;
};
@@ -4086,10 +4245,12 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle;
*/
struct TALER_EXCHANGE_PurseDeposit
{
+#if FIXME_OEC
/**
* Age commitment data.
*/
struct TALER_AgeCommitment age_commitment;
+#endif
/**
* Private key of the coin.
@@ -4118,14 +4279,12 @@ struct TALER_EXCHANGE_PurseDeposit
* Inform the exchange that a purse should be created
* and coins deposited into it.
*
- * @param ctx the context
- * @param url HTTP base URL for the exchange
+ * @param exchange the exchange to interact with
* @param purse_priv private key of the purse
- * @param merge_pub identifies merge credential
+ * @param merge_priv the merge credential
+ * @param contract_priv key needed to obtain and decrypt the contract
* @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
- * @param purse_value_after_fees target amount in 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
@@ -4134,14 +4293,12 @@ struct TALER_EXCHANGE_PurseDeposit
*/
struct TALER_EXCHANGE_PurseCreateDepositHandle *
TALER_EXCHANGE_purse_create_with_deposit (
- struct GNUNET_CURL_Context *ctx,
- const char *url,
+ struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
+ const struct TALER_PurseMergePrivateKeyP *merge_priv,
+ const struct TALER_ContractDiffiePrivateP *contract_priv,
const json_t *contract_terms,
- uint32_t min_age,
struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_Amount *purse_value_after_fees,
unsigned int num_deposits,
const struct TALER_EXCHANGE_PurseDeposit *deposits,
TALER_EXCHANGE_PurseCreateDepositCallback cb,
@@ -4168,8 +4325,19 @@ struct TALER_EXCHANGE_AccountMergeResponse
*/
struct TALER_EXCHANGE_HttpResponse *hr;
+ /**
+ * Details depending on the HTTP status.
+ */
union
{
+ /**
+ * Detailed returned on #MHD_HTTP_OK.
+ */
+ struct
+ {
+
+ } success;
+
} details;
};
@@ -4241,8 +4409,18 @@ struct TALER_EXCHANGE_PurseCreateMergeResponse
*/
struct TALER_EXCHANGE_HttpResponse *hr;
+ /**
+ * Details depending on the HTTP status.
+ */
union
{
+ /**
+ * Detailed returned on #MHD_HTTP_OK.
+ */
+ struct
+ {
+
+ } success;
} details;
};
@@ -4290,7 +4468,7 @@ TALER_EXCHANGE_purse_create_with_merge (
const struct TALER_ReservePrivateKeyP *reserve_priv,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
const json_t *contract_terms,
- uint32_t min_age,
+ uint8_t min_age,
struct GNUNET_TIME_Timestamp purse_expiration,
struct GNUNET_TIME_Timestamp merge_timestamp,
const struct TALER_Amount *purse_value_after_fees,
@@ -4318,8 +4496,18 @@ struct TALER_EXCHANGE_PurseDepositResponse
*/
struct TALER_EXCHANGE_HttpResponse *hr;
+ /**
+ * Details depending on the HTTP status.
+ */
union
{
+ /**
+ * Detailed returned on #MHD_HTTP_OK.
+ */
+ struct
+ {
+
+ } success;
} details;
};
@@ -4364,7 +4552,7 @@ TALER_EXCHANGE_purse_deposit (
const char *url,
const char *purse_exchange_url,
const struct TALER_PurseContractPublicKeyP *purse_pub,
- uint32_t min_age,
+ uint8_t min_age,
unsigned int num_deposits,
const struct TALER_EXCHANGE_PurseDeposit *deposits,
TALER_EXCHANGE_PurseDepositCallback cb,