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 "../PublicKey.h"
10

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

14 1
const Data TRANSACTION_TAG = {84, 88};
15 1
const std::string TRANSACTION_PAY = "pay";
16

17 1
Proto::SigningOutput Signer::sign(const Proto::SigningInput &input) noexcept {
18 1
    auto protoOutput = Proto::SigningOutput();
19 1
    auto key = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
20 1
    auto pubkey = key.getPublicKey(TWPublicKeyTypeED25519);
21 1
    auto from = Address(pubkey);
22

23 1
    auto note = Data(input.note().begin(), input.note().end());
24 1
    auto genesisId = input.genesis_id();
25 1
    auto genesisHash = Data(input.genesis_hash().begin(), input.genesis_hash().end());
26 1
    if (input.has_transaction_pay()) {
27 1
        auto message = input.transaction_pay();
28 1
        auto to = Address(message.to_address());
29

30 1
        auto transaction = Transaction(from, to, message.fee(), message.amount(), message.first_round(),
31 1
                                   message.last_round(), note, TRANSACTION_PAY, genesisId, genesisHash);
32 1
        auto signature = sign(key, transaction);
33 1
        auto serialized = transaction.serialize(signature);
34 1
        protoOutput.set_encoded(serialized.data(), serialized.size());
35
    }
36
    
37 1
    return protoOutput;
38
}
39

40 1
Data Signer::sign(const PrivateKey &privateKey, Transaction &transaction) noexcept {
41 1
    Data data;
42 1
    append(data, TRANSACTION_TAG);
43 1
    append(data, transaction.serialize());
44 1
    auto signature = privateKey.sign(data, TWCurveED25519);
45 1
    return Data(signature.begin(), signature.end());
46
}

Read our documentation on viewing source code .

Loading