1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#include "Signer.h"
8
#include "Address.h"
9
#include "Serialization.h"
10
#include "../PublicKey.h"
11
#include "HexCoding.h"
12

13
#include <google/protobuf/util/json_util.h>
14

15
using namespace TW;
16
using namespace TW::Elrond;
17

18 1
Proto::SigningOutput Signer::sign(const Proto::SigningInput &input) noexcept {
19 1
    auto privateKey = PrivateKey(input.private_key());
20 1
    auto signableAsString = serializeTransaction(input.transaction());
21 1
    auto signableAsData = TW::data(signableAsString);
22 1
    auto signature = privateKey.sign(signableAsData, TWCurveED25519);
23 1
    auto encodedSignature = hex(signature);
24 1
    auto encoded = serializeSignedTransaction(input.transaction(), encodedSignature);
25

26 1
    auto protoOutput = Proto::SigningOutput();
27 1
    protoOutput.set_signature(encodedSignature);
28 1
    protoOutput.set_encoded(encoded);
29 1
    return protoOutput;
30
}
31

32 1
std::string Signer::signJSON(const std::string& json, const Data& key) {
33 1
    auto input = Proto::SigningInput();
34 1
    google::protobuf::util::JsonStringToMessage(json, &input);
35 1
    input.set_private_key(key.data(), key.size());
36 1
    auto output = sign(input);
37 1
    return output.encoded();
38
}

Read our documentation on viewing source code .

Loading