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
#include "../uint256.h"
11
#include <boost/multiprecision/cpp_int.hpp>
12

13
using namespace TW;
14
using namespace TW::Aion;
15

16 1
Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) noexcept {
17
    using boost::multiprecision::uint128_t;
18

19 1
    auto key = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
20 1
    auto transaction = Transaction(
21 1
        /* nonce: */ static_cast<uint128_t>(load(input.nonce())),
22 1
        /* gasPrice: */ static_cast<uint128_t>(load(input.gas_price())),
23 1
        /* gasLimit: */ static_cast<uint128_t>(load(input.gas_limit())),
24 1
        /* to: */ Address(input.to_address()),
25 1
        /* amount: */ static_cast<uint128_t>(load(input.amount())),
26 1
        /* timestamp */ static_cast<uint128_t>(input.timestamp()),
27 1
        /* payload: */ Data(input.payload().begin(), input.payload().end()));
28 1
    Signer::sign(key, transaction);
29

30 1
    auto output = Proto::SigningOutput();
31 1
    auto encoded = transaction.encode();
32 1
    output.set_encoded(encoded.data(), encoded.size());
33 1
    output.set_signature(transaction.signature.data(), transaction.signature.size());
34 1
    return output;
35
}
36

37 1
void Signer::sign(const PrivateKey& privateKey, Transaction& transaction) noexcept {
38 1
    auto encoded = transaction.encode();
39 1
    auto hashData = Hash::blake2b(encoded, 32);
40 1
    auto hashSignature = privateKey.sign(hashData, TWCurveED25519);
41 1
    auto publicKeyData = privateKey.getPublicKey(TWPublicKeyTypeED25519).bytes;
42

43
    // Aion signature = pubKeyBytes + signatureBytes
44 1
    Data result(publicKeyData.begin(), publicKeyData.end());
45 1
    result.insert(result.end(), hashSignature.begin(), hashSignature.end());
46

47 1
    transaction.signature = result;
48
}

Read our documentation on viewing source code .

Loading