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 "Hash.h"
9
#include "HexCoding.h"
10
#include "IoTeX/Staking.h"
11
#include "PrivateKey.h"
12

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

16 1
Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) noexcept {
17 1
    auto signer = Signer(input);
18 1
    return signer.build();
19
}
20

21 1
Data Signer::sign() const {
22 1
    auto key = PrivateKey(input.privatekey());
23 1
    return key.sign(hash(), TWCurveSECP256k1);
24
}
25

26 1
Proto::SigningOutput Signer::build() const {
27 1
    auto signedAction = Proto::Action();
28 1
    signedAction.mutable_core()->MergeFrom(action);
29 1
    auto key = PrivateKey(input.privatekey());
30 1
    auto pk = key.getPublicKey(TWPublicKeyTypeSECP256k1Extended).bytes;
31 1
    signedAction.set_senderpubkey(pk.data(), pk.size());
32 1
    auto sig = key.sign(hash(), TWCurveSECP256k1);
33 1
    signedAction.set_signature(sig.data(), sig.size());
34

35 1
    auto output = Proto::SigningOutput();
36 1
    auto serialized = signedAction.SerializeAsString();
37 1
    output.set_encoded(serialized);
38 1
    auto h = Hash::keccak256(serialized);
39 1
    output.set_hash(h.data(), h.size());
40 1
    return output;
41
}
42

43 1
Data Signer::hash() const {
44 1
    return Hash::keccak256(action.SerializeAsString());
45
}
46

47 1
void Signer::toActionCore() {
48 1
    action.ParseFromString(input.SerializeAsString());
49 1
    action.DiscardUnknownFields();
50
}

Read our documentation on viewing source code .

Loading