forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.js
More file actions
301 lines (275 loc) · 7 KB
/
account.js
File metadata and controls
301 lines (275 loc) · 7 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* @flow */
import type { TxInputType, TxOutputType, CardanoDerivationType } from './trezor/protobuf';
import type { VinVout, BlockbookTransaction } from './backend/transactions';
export type DiscoveryAccountType = 'p2pkh' | 'p2sh' | 'p2tr' | 'p2wpkh';
// getAccountInfo params
export type GetAccountInfo = {
coin: string,
path?: string,
descriptor?: string,
details?: 'basic' | 'tokens' | 'tokenBalances' | 'txids' | 'txs',
tokens?: 'nonzero' | 'used' | 'derived',
page?: number,
pageSize?: number,
from?: number,
to?: number,
contractFilter?: string,
gap?: number,
marker?: {
ledger: number,
seq: number,
},
defaultAccountType?: DiscoveryAccountType,
derivationType?: CardanoDerivationType,
};
export type TokenInfo = {
type: string, // token type: ERC20...
address: string, // token address
balance?: string, // token balance
name?: string, // token name
symbol?: string, // token symbol
decimals: number, // token decimals or 0
// transfers: number, // total transactions?
};
export type AccountAddress = {
address: string,
path: string,
transfers?: number,
balance?: string,
sent?: string,
received?: string,
};
export type AccountAddresses = {
change: AccountAddress[],
used: AccountAddress[],
unused: AccountAddress[],
};
export type AccountUtxo = {
txid: string,
vout: number,
amount: string,
blockHeight: number,
address: string,
path: string,
confirmations: number,
coinbase?: boolean,
required?: boolean,
cardanoSpecific?: {
unit: string,
},
};
// Transaction object
type TokenTransfer = {
type: 'sent' | 'recv' | 'self' | 'unknown',
name: string,
symbol: string,
address: string,
decimals: number,
amount: string,
from?: string,
to?: string,
};
// Transaction object
type TransactionTarget = {
addresses?: string[],
isAddress: boolean,
amount?: string,
coinbase?: string,
isAccountTarget?: boolean,
n: number,
};
// Transaction from @trezor/blockchain-link
export type AccountTransaction = {
type: 'sent' | 'recv' | 'self' | 'failed' | 'unknown',
txid: string,
blockTime?: number,
blockHeight?: number,
blockHash?: string,
lockTime?: number,
amount: string,
fee: string,
totalSpent: string, // amount + fee
targets: TransactionTarget[],
tokens: TokenTransfer[],
rbf?: boolean,
ethereumSpecific?: $ElementType<BlockbookTransaction, 'ethereumSpecific'>,
cardanoSpecific?: {
subtype:
| 'withdrawal'
| 'stake_delegation'
| 'stake_registration'
| 'stake_deregistration'
| null,
},
details: {
vin: VinVout[],
vout: VinVout[],
size: number,
totalInput: string,
totalOutput: string,
},
};
// getAccountInfo response from @trezor/blockchain-link
export type AccountInfo = {
empty: boolean,
path: string,
descriptor: string, // address or xpub
legacyXpub?: string, // bitcoin-like descriptor in legacy format (xpub) used by labeling (metadata)
balance: string,
availableBalance: string,
tokens?: TokenInfo[], // ethereum tokens
addresses?: AccountAddresses, // bitcoin addresses
utxo?: AccountUtxo[], // bitcoin utxo
history: {
total: number, // total transactions (unknown in ripple)
tokens?: number, // tokens transactions (unknown in ripple)
unconfirmed?: number, // unconfirmed transactions (unknown in ripple)
transactions?: AccountTransaction[], // list of transactions
txids?: string[], // not implemented
},
misc?: {
// ETH
nonce?: string,
erc20Contract?: TokenInfo,
// XRP
sequence?: number,
reserve?: string,
// ADA
staking: {
address: string,
isActive: boolean,
rewards: string,
poolId: string | null,
},
},
page?: {
// blockbook
index: number,
size: number,
total: number,
},
marker?: {
// ripple-lib
ledger: number,
seq: number,
},
};
// Compose transaction
export type RegularOutput = {
type?: 'external',
address: string,
address_n?: typeof undefined,
amount: string,
script_type?: 'PAYTOADDRESS',
};
export type InternalOutput = {
type?: 'internal',
address?: typeof undefined,
address_n: number[],
amount: string,
script_type?: string,
};
export type SendMaxOutput = {
type: 'send-max',
address: string,
};
export type OpReturnOutput = {
type: 'opreturn',
dataHex: string,
};
export type NoAddressOutput = {
type: 'noaddress',
amount: string,
};
export type NoAddressSendMaxOutput = {
type: 'send-max-noaddress',
};
export type ComposeOutput =
| RegularOutput
| InternalOutput
| SendMaxOutput
| OpReturnOutput
| NoAddressOutput
| NoAddressSendMaxOutput;
export type PrecomposeParams = {
outputs: ComposeOutput[],
account: {
path: string,
addresses: AccountAddresses,
utxo: AccountUtxo[],
},
feeLevels: {
feePerUnit: string,
}[],
baseFee?: number,
floorBaseFee?: boolean,
sequence?: number,
skipPermutation?: boolean,
coin: string,
};
export type PrecomposedTransaction =
| {
type: 'error',
error: string,
}
| {
type: 'nonfinal',
max: string | typeof undefined,
totalSpent: string, // all the outputs, no fee, no change
fee: string,
feePerByte: string,
bytes: number,
}
| {
type: 'final',
max: string | typeof undefined,
totalSpent: string, // all the outputs, no fee, no change
fee: string,
feePerByte: string,
bytes: number,
transaction: {
inputs: TxInputType[],
outputs: TxOutputType[],
outputsPermutation: number[],
},
};
export type ComposeParams = {
outputs: ComposeOutput[],
coin: string,
push?: boolean,
sequence?: number,
account?: typeof undefined,
feeLevels?: typeof undefined,
baseFee?: number,
floorBaseFee?: boolean,
skipPermutation?: boolean,
};
export type DiscoveryAccount = {
type: DiscoveryAccountType,
label: string,
descriptor: string,
address_n: number[],
empty?: boolean,
balance?: string,
addresses?: AccountAddresses,
};
export type FeeLevel = {
label: 'high' | 'normal' | 'economy' | 'low' | 'custom',
feePerUnit: string,
blocks: number,
feeLimit?: string, // eth gas limit
feePerTx?: string, // fee for BlockchainEstimateFeeParams.request.specific
};
export type SelectFeeLevel =
| {
name: string,
fee: '0',
disabled: true,
}
| {
name: string,
fee: string,
feePerByte: string,
minutes: number,
total: string,
};