forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSigner.cpp
More file actions
47 lines (39 loc) · 1.54 KB
/
Copy pathSigner.cpp
File metadata and controls
47 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright © 2017-2020 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#include "Hash.h"
#include "HexCoding.h"
#include "PrivateKey.h"
#include "Signer.h"
using namespace TW;
using namespace TW::IoTeX;
Data Signer::sign() const {
auto key = PrivateKey(input.privatekey());
return key.sign(hash(), TWCurveSECP256k1);
}
Proto::SigningOutput Signer::build() const {
auto signedAction = IoTeX::Proto::Action();
signedAction.mutable_core()->MergeFrom(action);
auto key = PrivateKey(input.privatekey());
auto pk = key.getPublicKey(TWPublicKeyTypeSECP256k1Extended).bytes;
signedAction.set_senderpubkey(pk.data(), pk.size());
auto sig = key.sign(hash(), TWCurveSECP256k1);
signedAction.set_signature(sig.data(), sig.size());
auto output = IoTeX::Proto::SigningOutput();
auto serialized = signedAction.SerializeAsString();
output.set_encoded(serialized);
auto h = Hash::keccak256(serialized);
output.set_hash(h.data(), h.size());
return output;
}
Data Signer::hash() const {
return Hash::keccak256(action.SerializeAsString());
}
void Signer::toActionCore() {
// ActionCore is same as SigningInput, except missing field privateKey = 5;
// we could leverage this and directly load SigningInput proto msg into ActionCore
action.ParseFromString(input.SerializeAsString());
action.DiscardUnknownFields();
}