-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
entry.rs
96 lines (86 loc) · 2.95 KB
/
entry.rs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
use crate::address::GreenfieldAddress;
use crate::compiler::GreenfieldCompiler;
use crate::signer::GreenfieldSigner;
use std::str::FromStr;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::{CoinEntry, PublicKeyBytes, SignatureBytes};
use tw_coin_entry::derivation::Derivation;
use tw_coin_entry::error::prelude::*;
use tw_coin_entry::modules::json_signer::NoJsonSigner;
use tw_coin_entry::modules::message_signer::NoMessageSigner;
use tw_coin_entry::modules::plan_builder::NoPlanBuilder;
use tw_coin_entry::modules::transaction_decoder::NoTransactionDecoder;
use tw_coin_entry::modules::wallet_connector::NoWalletConnector;
use tw_coin_entry::prefix::NoPrefix;
use tw_keypair::tw::PublicKey;
use tw_proto::Greenfield::Proto;
use tw_proto::TxCompiler::Proto as CompilerProto;
pub struct GreenfieldEntry;
impl CoinEntry for GreenfieldEntry {
type AddressPrefix = NoPrefix;
type Address = GreenfieldAddress;
type SigningInput<'a> = Proto::SigningInput<'a>;
type SigningOutput = Proto::SigningOutput<'static>;
type PreSigningOutput = CompilerProto::PreSigningOutput<'static>;
// Optional modules:
type JsonSigner = NoJsonSigner;
type PlanBuilder = NoPlanBuilder;
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
#[inline]
fn parse_address(
&self,
_coin: &dyn CoinContext,
address: &str,
_prefix: Option<Self::AddressPrefix>,
) -> AddressResult<Self::Address> {
GreenfieldAddress::from_str(address)
}
#[inline]
fn parse_address_unchecked(
&self,
_coin: &dyn CoinContext,
address: &str,
) -> AddressResult<Self::Address> {
GreenfieldAddress::from_str(address)
}
#[inline]
fn derive_address(
&self,
_coin: &dyn CoinContext,
public_key: PublicKey,
_derivation: Derivation,
_prefix: Option<Self::AddressPrefix>,
) -> AddressResult<Self::Address> {
let public_key = public_key
.to_secp256k1()
.ok_or(AddressError::PublicKeyTypeMismatch)?;
Ok(GreenfieldAddress::with_secp256k1_pubkey(public_key))
}
#[inline]
fn sign(&self, coin: &dyn CoinContext, input: Self::SigningInput<'_>) -> Self::SigningOutput {
GreenfieldSigner::sign(coin, input)
}
#[inline]
fn preimage_hashes(
&self,
coin: &dyn CoinContext,
input: Self::SigningInput<'_>,
) -> Self::PreSigningOutput {
GreenfieldCompiler::preimage_hashes(coin, input)
}
#[inline]
fn compile(
&self,
coin: &dyn CoinContext,
input: Self::SigningInput<'_>,
signatures: Vec<SignatureBytes>,
public_keys: Vec<PublicKeyBytes>,
) -> Self::SigningOutput {
GreenfieldCompiler::compile(coin, input, signatures, public_keys)
}
}