-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathindex.ts
464 lines (455 loc) · 9.2 KB
/
index.ts
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
export type Account = {
/**
* - The address of the account
*/
address: string
/**
* - The FLOW balance of the account in 10^8
*/
balance: number
/**
* - The code of any Cadence contracts stored in the account
*/
code: number
/**
* - Any contracts deployed to this account
*/
contracts: Record<string, string>
/**
* - The keys associated with the account
*/
keys: Array<AccountKey>
}
export type AccountKey = {
/**
* - The index of the key in the account
*/
index: number
/**
* - The public key of the account key
*/
publicKey: string
/**
* - The signature algorithm used by the key
*/
signAlgo: SignatureAlgorithm
/**
* - The signature algorithm used by the key as a string
*/
signAlgoString: string
/**
* - The hashing algorithm used by the key
*/
hashAlgo: HashAlgorithm
/**
* - The hashing algorithm used by the key as a string
*/
hashAlgoString: string
/**
* - The sequence number of the key
*/
sequenceNumber: number
/**
* - The weight of the key
*/
weight: number
/**
* - Whether or not the key has been revoked
*/
revoked: boolean
}
export enum SignatureAlgorithm {
ECDSA_P256 = 1,
ECDSA_secp256k1 = 2,
BLS_BLS12_381 = 3,
}
export enum HashAlgorithm {
SHA2_256 = 1,
SHA2_384 = 2,
SHA3_256 = 3,
SHA3_384 = 4,
KMAC128_BLS_BLS12_381 = 5,
}
export type Block = {
/**
* - The id of the block
*/
id: string
/**
* - The id of the parent block
*/
parentId: string
/**
* - The height of the block
*/
height: number
/**
* - Time related fields
*/
timestamp: string
/**
* - Contains the ids of collections included in the block
*/
collectionGuarantees: Array<CollectionGuarantee>
/**
* - The details of which nodes executed and sealed the blocks
*/
blockSeals: Array<BlockSeal>
/**
* - The cryptographic signature of the block
*/
signatures: Array<number>
}
export type CollectionGuarantee = {
/**
* - The id of the block
*/
collectionId: string
/**
* - The signer ids of the block
*/
signerIds: Array<object>
}
export type BlockSeal = {
/**
* - The id of the block
*/
blockId: string
/**
* - The execution receipt id of the block
*/
executionReceiptId: string
}
export type CompositeSignature = {
/**
* - A type identifier used internally by FCL
*/
f_type: string
/**
* - FCL protocol version
*/
f_vsn: string
/**
* - Flow Address (sans prefix)
*/
addr: string
/**
* - Key ID
*/
keyId: number
/**
* - Signature as a hex string
*/
signature: string
}
export type CurrentUser = {
/**
* - The public address of the current user
*/
addr?: string
/**
* - A wallet specified content identifier for user metadata
*/
cid?: string
/**
* - A wallet specified time-frame for a valid session
*/
expiresAt?: number
/**
* - A type identifier used internally by FCL
*/
f_type: string
/**
* - FCL protocol version
*/
f_vsn: string
/**
* - Whether or not the current user is logged in
*/
loggedIn?: boolean
/**
* - A list of trusted services that express ways of interacting with the current user's identity
*/
services: Array<Service>
}
export type Event = {
/**
* - ID of the block that contains the event.
*/
blockId: string
/**
* - Height of the block that contains the event.
*/
blockHeight: number
/**
* - The timestamp of when the block was sealed in a DateString format. eg. '2021-06-25T13:42:04.227Z'
*/
blockTimestamp: string
/**
* - A string containing the event name.
*/
type: string
/**
* - Can be used to query transaction information, eg. via a Flow block explorer.
*/
transactionId: string
/**
* - Used to prevent replay attacks.
*/
transactionIndex: number
/**
* - Used to prevent replay attacks.
*/
eventIndex: number
/**
* - The data emitted from the event.
*/
data: any
}
export type Key = {
/**
* - Sequence number of key used by the proposer of this transaction
*/
sequenceNumber: number
/**
* - The ID of the key in the account used by the proposer of this transaction
*/
keyId: number
/**
* - The address of the proposer of this transaction
*/
address: string
}
export type Service = {
/**
* - A type identifier used internally by FCL
*/
f_type: string
/**
* - FCL protocol version
*/
f_vsn: string
/**
* - Service type
*/
type: string
/**
* - Service method
*/
method: string
/**
* - Service uid
*/
uid?: string
/**
* - Service endpoint
*/
endpoint: string
/**
* - Service provider object
*/
provider: Provider
params: Record<string, string>
}
export type Signature = {
/**
* - Sequence number of the key used to perform this signature.
*/
sequenceNumber: string
/**
* - ID of the key in the account used to perform this signature.
*/
keyId: number
/**
* - The signature represented as a hex string.
*/
signature: string
}
export type Transaction = {
/**
* - The Cadence code used to execute this transaction.
*/
script: string
/**
* - The JSON-CDC encoded arguments passed in to the transaction.
*/
args: Array<string>
/**
* - The reference block id for this transaction.
*/
referenceBlockId: string
/**
* - The gas limit for the transaction.
*/
gasLimit: number
/**
* - The key used by the proposer of this transaction.
*/
proposalKey: Key
/**
* - Sequence number of the key used by the proposer of this transaction.
*/
sequenceNumber: string
/**
* - The ID of the key in the account used by the proposer of this transaction.
*/
keyId: number
/**
* - The address of the proposer of this transaction.
*/
address: string
/**
* - Address of the payer of the transaction.
*/
payer: string
/**
* - Address of the proposer of this transaction.
*/
proposer: string
/**
* - Array of addresses of authorizers of this transaction.
*/
authorizers: Array<string>
/**
* - The payload signatures for the transaction.
*/
payloadSignatures: Array<Signature>
/**
* - The envelope signatures for the transaction.
*/
envelopeSignatures: Array<Signature>
}
export type TransactionStatus = {
/**
* - The ID of the Block the transaction is included in.
*/
blockId: string
/**
* - The execution status of the transaction
*/
status: TransactionExecutionStatus
/**
* - The status as as descriptive text (e.g. "FINALIZED").
*/
statusString: string
/**
* - The result of the transaction, if executed (i.e. 0 for success, 1 for failure)
*/
statusCode: 0 | 1
/**
* - The error message of the transaction.
*/
errorMessage: string
/**
* - The events for this result.
*/
events: Array<Event>
}
/**
* The execution status of the transaction.
*/
export enum TransactionExecutionStatus {
UNKNOWN = 0,
PENDING = 1,
FINALIZED = 2,
EXECUTED = 3,
SEALED = 4,
EXPIRED = 5,
}
/*
* The Provider type describes a Wallet Provider associated with a specific Service.
*/
export type Provider = {
/**
* The blockchain address of the Wallet provider.
*/
address?: string
/**
* The name of the Wallet provider.
*/
name?: string
/**
* The icon of the Wallet provider (may be a URL or a data URI).
*/
icon?: string
/**
* A brief description of the Wallet provider.
*/
description?: string
/**
* The preferred color to represent the Wallet provider (e.g., for UI styling).
*/
color?: string
/**
* The support email address of the Wallet provider.
*/
supportEmail?: string
/**
* The website URL of the Wallet provider.
*/
website?: string
/**
* Indicates whether the Wallet provider is installed (if applicable).
*/
is_installed?: boolean
}
export type NodeVersionInfo = {
/**
* - The semver version of the node.
*/
semver: string
/**
* - The commit hash of the node.
*/
commit: string
/**
* - The spork id of the node.
*/
sporkId: string
/**
* - The protocol version of the node.
*/
protocolVersion: number
/**
* - The spork root block height of the node.
*/
sporkRootBlockHeight: number
/**
* - The node root block height of the node.
*/
nodeRootBlockHeight: number
}
export interface StreamConnection<ChannelMap extends {[name: string]: any}> {
on<C extends keyof ChannelMap>(
channel: C,
listener: (data: ChannelMap[C]) => void
): this
on(event: "close", listener: () => void): this
on(event: "error", listener: (err: any) => void): this
off<C extends keyof ChannelMap>(
event: C,
listener: (data: ChannelMap[C]) => void
): this
off(event: "close", listener: () => void): this
off(event: "error", listener: (err: any) => void): this
close(): void
}
export interface EventFilter {
eventTypes?: string[]
addresses?: string[]
contracts?: string[]
startBlockId?: string
startHeight?: number
heartbeatInterval?: number
}
export interface BlockHeartbeat {
blockId: string
blockHeight: number
timestamp: string
}
export type EventStream = StreamConnection<{
events: Event[]
heartbeat: BlockHeartbeat
}>
export * from "./interaction"
export * from "./fvm-errors"