reworked deposit initialisation
This commit is contained in:
parent
36e189ceef
commit
e99b6b931c
@ -166,89 +166,99 @@ PERF_TALER_MINTDB_refresh_session_free (struct TALER_MINTDB_RefreshSession *refr
|
|||||||
struct TALER_MINTDB_Deposit *
|
struct TALER_MINTDB_Deposit *
|
||||||
PERF_TALER_MINTDB_deposit_init ()
|
PERF_TALER_MINTDB_deposit_init ()
|
||||||
{
|
{
|
||||||
static int transaction_id = 0;
|
|
||||||
struct TALER_MINTDB_Deposit *deposit;
|
struct TALER_MINTDB_Deposit *deposit;
|
||||||
|
struct TALER_CoinPublicInfo coin;
|
||||||
|
struct TALER_CoinSpendSignatureP csig;
|
||||||
|
struct TALER_MerchantPublicKeyP merchant_pub;
|
||||||
|
struct GNUNET_HashCode h_contract;
|
||||||
|
struct GNUNET_HashCode h_wire;
|
||||||
|
const char wire[] = "{"
|
||||||
|
"\"type\":\"SEPA\","
|
||||||
|
"\"IBAN\":\"DE67830654080004822650\","
|
||||||
|
"\"NAME\":\"GNUNET E.\","
|
||||||
|
"\"BIC\":\"GENODEF1SRL\""
|
||||||
|
"}";
|
||||||
|
static uint64_t transaction_id = 0;
|
||||||
|
struct GNUNET_TIME_Absolute timestamp;
|
||||||
|
struct GNUNET_TIME_Absolute refund_deadline;
|
||||||
|
struct TALER_Amount amount_with_fee;
|
||||||
|
struct TALER_Amount deposit_fee;
|
||||||
|
|
||||||
GNUNET_assert (NULL !=
|
GNUNET_assert (NULL !=
|
||||||
(deposit = GNUNET_new (struct TALER_MINTDB_Deposit)));
|
(deposit = GNUNET_malloc (sizeof (struct TALER_MINTDB_Deposit) + sizeof (wire))));
|
||||||
deposit-> transaction_id = transaction_id;
|
{ // coin
|
||||||
GNUNET_assert (GNUNET_OK ==
|
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt;
|
||||||
TALER_string_to_amount (CURRENCY ":1.1",
|
struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_prv;
|
||||||
&deposit->amount_with_fee));
|
|
||||||
GNUNET_assert (GNUNET_OK ==
|
GNUNET_assert (NULL !=
|
||||||
TALER_string_to_amount (CURRENCY ":0.1",
|
(eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||||
&deposit->deposit_fee));
|
GNUNET_assert (NULL !=
|
||||||
deposit->timestamp = GNUNET_TIME_absolute_get ();
|
(rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (128)));
|
||||||
deposit->refund_deadline = GNUNET_TIME_absolute_get ();
|
GNUNET_assert (NULL !=
|
||||||
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
(coin.denom_pub.rsa_public_key =
|
||||||
&deposit->h_contract);
|
GNUNET_CRYPTO_rsa_private_key_get_public (rsa_prv)));
|
||||||
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
GNUNET_assert (NULL !=
|
||||||
&deposit->h_wire);
|
(coin.denom_sig.rsa_signature =
|
||||||
// Coin Spend Signature
|
GNUNET_CRYPTO_rsa_sign (rsa_prv,
|
||||||
{
|
&coin.coin_pub.eddsa_pub,
|
||||||
|
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))));
|
||||||
|
GNUNET_CRYPTO_eddsa_key_get_public (eddsa_prvt,
|
||||||
|
&coin.coin_pub.eddsa_pub);
|
||||||
|
GNUNET_CRYPTO_rsa_private_key_free (rsa_prv);
|
||||||
|
GNUNET_free (eddsa_prvt);
|
||||||
|
}
|
||||||
|
{ //csig
|
||||||
struct u32_presign
|
struct u32_presign
|
||||||
{
|
{
|
||||||
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
} unsigned_data;
|
} unsigned_data;
|
||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt;
|
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt;
|
||||||
uint32_t random_int;
|
|
||||||
|
|
||||||
GNUNET_assert (NULL !=
|
GNUNET_assert (NULL !=
|
||||||
(eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
(eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||||
|
unsigned_data.data = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
random_int = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
||||||
UINT32_MAX);
|
UINT32_MAX);
|
||||||
unsigned_data.purpose.size = htonl (sizeof (struct u32_presign));
|
unsigned_data.purpose.size = htonl (sizeof (struct u32_presign));
|
||||||
unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
|
unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
|
||||||
unsigned_data.data = random_int;
|
|
||||||
GNUNET_assert (GNUNET_OK ==
|
GNUNET_assert (GNUNET_OK ==
|
||||||
GNUNET_CRYPTO_eddsa_sign (eddsa_prvt,
|
GNUNET_CRYPTO_eddsa_sign (eddsa_prvt,
|
||||||
&unsigned_data.purpose,
|
&unsigned_data.purpose,
|
||||||
&deposit->csig.eddsa_signature));
|
&csig.eddsa_signature));
|
||||||
// No need to clear as this is a dummy key
|
|
||||||
GNUNET_free (eddsa_prvt);
|
GNUNET_free (eddsa_prvt);
|
||||||
}
|
}
|
||||||
// Merchant Key
|
{ //merchant_pub
|
||||||
{
|
|
||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prv;
|
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prv;
|
||||||
|
|
||||||
GNUNET_assert(NULL !=
|
GNUNET_assert(NULL !=
|
||||||
(eddsa_prv = GNUNET_CRYPTO_eddsa_key_create ()));
|
(eddsa_prv = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||||
GNUNET_CRYPTO_eddsa_key_get_public (
|
GNUNET_CRYPTO_eddsa_key_get_public (
|
||||||
eddsa_prv,
|
eddsa_prv,
|
||||||
&deposit->merchant_pub.eddsa_pub);
|
&merchant_pub.eddsa_pub);
|
||||||
GNUNET_free (eddsa_prv);
|
GNUNET_free (eddsa_prv);
|
||||||
}
|
}
|
||||||
// Coin
|
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
{
|
&h_contract);
|
||||||
{
|
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt;
|
&h_wire);
|
||||||
|
timestamp = GNUNET_TIME_absolute_get ();
|
||||||
GNUNET_assert (NULL !=
|
refund_deadline = GNUNET_TIME_absolute_get ();
|
||||||
(eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
GNUNET_assert (GNUNET_OK ==
|
||||||
GNUNET_CRYPTO_eddsa_key_get_public (
|
TALER_string_to_amount (CURRENCY ":1.1",
|
||||||
eddsa_prvt,
|
&amount_with_fee));
|
||||||
&deposit->coin.coin_pub.eddsa_pub);
|
GNUNET_assert (GNUNET_OK ==
|
||||||
GNUNET_free (eddsa_prvt);
|
TALER_string_to_amount (CURRENCY ":0.1",
|
||||||
}
|
&deposit_fee));
|
||||||
|
deposit->coin = coin;
|
||||||
{
|
deposit->csig = csig;
|
||||||
struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_prv;
|
deposit->h_contract = h_contract;
|
||||||
|
deposit->h_wire = h_wire;
|
||||||
GNUNET_assert (NULL !=
|
deposit->wire = json_loads (wire, 0, NULL);
|
||||||
(rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (128)));
|
deposit->transaction_id = transaction_id++;
|
||||||
GNUNET_assert (NULL !=
|
deposit->timestamp = timestamp;
|
||||||
(deposit->coin.denom_pub.rsa_public_key =
|
deposit->refund_deadline = refund_deadline;
|
||||||
GNUNET_CRYPTO_rsa_private_key_get_public (rsa_prv)));
|
deposit->amount_with_fee = amount_with_fee;
|
||||||
GNUNET_assert (NULL !=
|
deposit->deposit_fee = deposit_fee;
|
||||||
(deposit->coin.denom_sig.rsa_signature =
|
|
||||||
GNUNET_CRYPTO_rsa_sign (rsa_prv,
|
|
||||||
&deposit->coin.coin_pub.eddsa_pub,
|
|
||||||
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))));
|
|
||||||
GNUNET_CRYPTO_rsa_private_key_free (rsa_prv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deposit;
|
return deposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ PERF_TALER_MINTDB_refresh_session_free (struct TALER_MINTDB_RefreshSession *refr
|
|||||||
* Create a randomly generated deposit
|
* Create a randomly generated deposit
|
||||||
*/
|
*/
|
||||||
struct TALER_MINTDB_Deposit *
|
struct TALER_MINTDB_Deposit *
|
||||||
PERF_TALER_MINTDB_deposit_init ();
|
PERF_TALER_MINTDB_deposit_init (void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user