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

9
#include "../Hash.h"
10

11
using namespace TW;
12
using namespace TW::Waves;
13

14 1
Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) noexcept {
15 1
    auto privateKey = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
16 1
    auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeCURVE25519);
17 1
    auto transaction = Transaction(input, publicKey.bytes);
18

19 1
    Data signature = Signer::sign(privateKey, transaction);
20

21 1
    Proto::SigningOutput output = Proto::SigningOutput();
22 1
    output.set_signature(reinterpret_cast<const char *>(signature.data()), signature.size());
23 1
    output.set_json(transaction.buildJson(signature).dump());
24 1
    return output;
25
}
26

27 1
Data Signer::sign(const PrivateKey &privateKey, Transaction &transaction) noexcept {
28
    try {
29 1
        auto bytesToSign = transaction.serializeToSign();
30 1
        auto signature = privateKey.sign(bytesToSign, TWCurveCurve25519);
31 1
        return signature;
32 1
    } catch (...) {
33 0
        return Data();
34
    }
35
}

Read our documentation on viewing source code .

Loading