From 579f465c9b2ed1cd4602ee102073d633fda60cb9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Mar 2015 12:29:41 +0100 Subject: implementing #3632: generate proof of insufficient funds by converting transaction history to JSON --- src/util/json.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'src/util') diff --git a/src/util/json.c b/src/util/json.c index 02591d7bf..38f459200 100644 --- a/src/util/json.c +++ b/src/util/json.c @@ -90,8 +90,8 @@ TALER_JSON_from_abs (struct GNUNET_TIME_Absolute stamp) * @return the JSON reporesentation of the signature with purpose */ json_t * -TALER_JSON_from_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, - const struct GNUNET_CRYPTO_EddsaSignature *signature) +TALER_JSON_from_eddsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EddsaSignature *signature) { json_t *root; json_t *el; @@ -106,7 +106,37 @@ TALER_JSON_from_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, el = TALER_JSON_from_data (signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)); - json_object_set_new (root, "sig", el); + json_object_set_new (root, "eddsa-sig", el); + + return root; +} + + +/** + * Convert a signature (with purpose) to a JSON object representation. + * + * @param purpose purpose of the signature + * @param signature the signature + * @return the JSON reporesentation of the signature with purpose + */ +json_t * +TALER_JSON_from_ecdsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EcdsaSignature *signature) +{ + json_t *root; + json_t *el; + + root = json_object (); + + el = json_integer ((json_int_t) ntohl (purpose->size)); + json_object_set_new (root, "size", el); + + el = json_integer ((json_int_t) ntohl (purpose->purpose)); + json_object_set_new (root, "purpose", el); + + el = TALER_JSON_from_data (signature, + sizeof (struct GNUNET_CRYPTO_EddsaSignature)); + json_object_set_new (root, "ecdsa-sig", el); return root; } @@ -133,6 +163,20 @@ TALER_JSON_from_data (const void *data, size_t size) } +/** + * Convert binary hash to a JSON string with the base32crockford + * encoding. + * + * @param hc binary data + * @return json string that encodes @a hc + */ +json_t * +TALER_JSON_from_hash (const struct GNUNET_HashCode *hc) +{ + return TALER_JSON_from_data (hc, sizeof (struct GNUNET_HashCode)); +} + + /** * Parse given JSON object to Amount * -- cgit v1.2.3