@keetanetwork/keetanet-client 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/._version.d.ts +0 -0
  2. package/LICENSE +35 -0
  3. package/api/index.d.ts +181 -0
  4. package/api/node.d.ts +216 -0
  5. package/api/vote.d.ts +25 -0
  6. package/client/builder.d.ts +129 -0
  7. package/client/client_common_tests.d.ts +72 -0
  8. package/client/index-browser.d.ts +243 -0
  9. package/client/index-browser.js +141899 -0
  10. package/client/index.d.ts +243 -0
  11. package/client/index.js +89118 -0
  12. package/config/index.d.ts +62 -0
  13. package/lib/account.d.ts +544 -0
  14. package/lib/block/index.d.ts +181 -0
  15. package/lib/block/operations.d.ts +407 -0
  16. package/lib/bootstrap.d.ts +27 -0
  17. package/lib/error/account.d.ts +9 -0
  18. package/lib/error/block.d.ts +9 -0
  19. package/lib/error/client.d.ts +9 -0
  20. package/lib/error/index.d.ts +20 -0
  21. package/lib/error/kv.d.ts +9 -0
  22. package/lib/error/ledger.d.ts +12 -0
  23. package/lib/error/permissions.d.ts +9 -0
  24. package/lib/error/vote.d.ts +9 -0
  25. package/lib/index.d.ts +39 -0
  26. package/lib/kv/index.d.ts +22 -0
  27. package/lib/kv/index.test.data.d.ts +9 -0
  28. package/lib/kv/kv_dynamodb.d.ts +20 -0
  29. package/lib/kv/kv_memory.d.ts +17 -0
  30. package/lib/kv/kv_redis.d.ts +22 -0
  31. package/lib/kv/providers.d.ts +9 -0
  32. package/lib/ledger/cache.d.ts +14 -0
  33. package/lib/ledger/common.d.ts +115 -0
  34. package/lib/ledger/db_dynamodb.d.ts +129 -0
  35. package/lib/ledger/db_memory.d.ts +6 -0
  36. package/lib/ledger/db_postgres.d.ts +70 -0
  37. package/lib/ledger/db_spanner.d.ts +116 -0
  38. package/lib/ledger/db_spanner_helper.d.ts +487 -0
  39. package/lib/ledger/db_sqlite.d.ts +64 -0
  40. package/lib/ledger/drivers.d.ts +7 -0
  41. package/lib/ledger/effects.d.ts +78 -0
  42. package/lib/ledger/index.d.ts +312 -0
  43. package/lib/ledger/types.d.ts +49 -0
  44. package/lib/node/index.d.ts +114 -0
  45. package/lib/node/local.d.ts +30 -0
  46. package/lib/node/timing.d.ts +12 -0
  47. package/lib/node/utils.d.ts +4 -0
  48. package/lib/p2p.d.ts +300 -0
  49. package/lib/permissions.d.ts +121 -0
  50. package/lib/pubsub/index.d.ts +7 -0
  51. package/lib/pubsub/providers.d.ts +7 -0
  52. package/lib/pubsub/ps_memory.d.ts +9 -0
  53. package/lib/pubsub/ps_redis.d.ts +10 -0
  54. package/lib/stats.d.ts +51 -0
  55. package/lib/utils/asn1.d.ts +205 -0
  56. package/lib/utils/bitfield.d.ts +13 -0
  57. package/lib/utils/bloom.d.ts +6 -0
  58. package/lib/utils/buffer.d.ts +27 -0
  59. package/lib/utils/certificate.d.ts +340 -0
  60. package/lib/utils/conversion.d.ts +46 -0
  61. package/lib/utils/dynamodb.d.ts +17 -0
  62. package/lib/utils/ed2curve.d.ts +7 -0
  63. package/lib/utils/hash.d.ts +17 -0
  64. package/lib/utils/helper.d.ts +67 -0
  65. package/lib/utils/helper_testing.d.ts +37 -0
  66. package/lib/utils/initial.d.ts +32 -0
  67. package/lib/utils/never.d.ts +7 -0
  68. package/lib/utils/redis.d.ts +11 -0
  69. package/lib/vote.d.ts +273 -0
  70. package/package.json +35 -0
  71. package/version.d.ts +2 -0
@@ -0,0 +1,312 @@
1
+ import { VoteStaple, Vote, VoteBlockHashMap } from '../vote';
2
+ import { Block, BlockHash } from '../block';
3
+ import type { VoteBlockHash } from '../vote';
4
+ import type { GenericAccount, IdentifierAddress, NetworkAddress, TokenAddress } from '../account';
5
+ import Account from '../account';
6
+ import type Node from '../node';
7
+ import type { BloomFilter } from '../utils/bloom';
8
+ import type { ComputedEffectOfBlocks } from './effects';
9
+ import type { ACLRow, AccountInfo, GetAllBalancesResponse, LedgerStatistics } from './types';
10
+ import LedgerRequestCache from './cache';
11
+ /**
12
+ * Kind of ledger
13
+ */
14
+ export declare enum LedgerKind {
15
+ REPRESENTATIVE = 0,
16
+ ACCOUNT = 1
17
+ }
18
+ /**
19
+ * Ledger configuration
20
+ */
21
+ export interface LedgerConfig {
22
+ initialTrustedAccount: Account;
23
+ network: bigint;
24
+ subnet?: bigint;
25
+ /**
26
+ * Kind of ledger
27
+ */
28
+ kind: LedgerKind;
29
+ /**
30
+ * Private key for the ledger if it is acting as a representative
31
+ */
32
+ privateKey?: Account;
33
+ /**
34
+ * Storage mechanism
35
+ */
36
+ storageDriver: LedgerStorageAPI;
37
+ /**
38
+ * Options to pass to the storage driver
39
+ */
40
+ storageOptions?: any;
41
+ /**
42
+ * Is this ledger in read-only mode ?
43
+ *
44
+ * bootstrap-only: Bootstrapping can still occur
45
+ * read-only: No bootstrapping, no voting
46
+ * read-write: Normal mode (read-write enabled)
47
+ */
48
+ ledgerWriteMode?: 'bootstrap-only' | 'read-only' | 'read-write';
49
+ /**
50
+ * Logging method
51
+ */
52
+ log?: (...args: any[]) => any;
53
+ }
54
+ /**
55
+ * Which ledger to store this data in
56
+ */
57
+ export type LedgerStorage = 'main' | 'side';
58
+ /**
59
+ * Which ledger(s) to pull the data from
60
+ */
61
+ export type LedgerSelector = LedgerStorage | 'both';
62
+ /**
63
+ * A set of votes and a pointer to the next set/page
64
+ */
65
+ export type PaginatedVotes = {
66
+ votes: Vote[];
67
+ nextKey?: string;
68
+ };
69
+ /**
70
+ * Options for "getVotesAfter"
71
+ */
72
+ export type GetVotesAfterOptions = {
73
+ /**
74
+ * Limit the page size when requesting votes
75
+ */
76
+ maxVotesPerPage?: number;
77
+ /**
78
+ * Bloom filter to apply to VoteStaples
79
+ */
80
+ bloomFilter?: BloomFilter;
81
+ /**
82
+ * Timeout for fetching votes
83
+ */
84
+ timeout?: number;
85
+ };
86
+ /**
87
+ * Each Ledger Storage backend must implement this interface
88
+ */
89
+ export interface LedgerStorageAPI {
90
+ /**
91
+ * Initialization
92
+ */
93
+ init: (config: LedgerConfig, ledger: Ledger) => void;
94
+ /**
95
+ * Optional destructor
96
+ */
97
+ destroy?: () => Promise<void>;
98
+ /**
99
+ * Begin a transaction
100
+ */
101
+ beginTransaction: (readOnly?: boolean) => Promise<any>;
102
+ /**
103
+ * Commit an active transaction
104
+ */
105
+ commitTransaction: (transaction: any) => Promise<void>;
106
+ /**
107
+ * Abort an active transaction
108
+ */
109
+ abortTransaction: (transaction: any) => Promise<void>;
110
+ /**
111
+ * Evaluate error and return expected error (eg. KeetaNetLedgerError)
112
+ * @param error
113
+ */
114
+ evaluateError: (error: any) => Promise<any>;
115
+ /**
116
+ * Get the amount of delegated weight for an account,
117
+ * if "rep" is not supplied get the total delegated weight
118
+ */
119
+ delegatedWeight: (transaction: any, rep?: Account) => Promise<bigint>;
120
+ /**
121
+ * Get the balance of an account or token
122
+ */
123
+ getBalance: (transaction: any, account: GenericAccount, token: TokenAddress) => Promise<bigint>;
124
+ /**
125
+ * Get all balances on a user account for a token
126
+ */
127
+ getAllBalances: (transaction: any, account: GenericAccount) => Promise<GetAllBalancesResponse>;
128
+ /**
129
+ * Get account information (name, description)
130
+ * If token account, return supply
131
+ * If non user account, returns default permissions
132
+ */
133
+ getAccountInfo: (transaction: any, account: GenericAccount | string) => Promise<AccountInfo>;
134
+ /**
135
+ * List all owners of an account
136
+ */
137
+ listOwners: (transaction: any, identifier: IdentifierAddress, target?: GenericAccount) => Promise<GenericAccount[]>;
138
+ /**
139
+ * List permissions principal has on all provided entity's
140
+ */
141
+ listACLsByPrincipal: (transaction: any, principal: GenericAccount, entityList?: GenericAccount[]) => Promise<ACLRow[]>;
142
+ /**
143
+ * List permissions any principal has on provided entity
144
+ */
145
+ listACLsByEntity: (transaction: any, entity: GenericAccount) => Promise<ACLRow[]>;
146
+ /**
147
+ * Adjust the ledger by performing a set of changes based on some blocks and votes
148
+ */
149
+ adjust: (transaction: any, input: VoteStaple, changes: ComputedEffectOfBlocks) => Promise<BlockHash[]>;
150
+ /**
151
+ * Add a transitional vote (to the side-ledger)
152
+ */
153
+ addPendingVote: (transaction: any, blocksAndVote: VoteStaple) => Promise<void>;
154
+ /**
155
+ * Request a block
156
+ */
157
+ getBlock: (transaction: any, block: BlockHash, from: LedgerSelector) => Promise<Block | null>;
158
+ /**
159
+ * Get the block height from a given block hash
160
+ */
161
+ getBlockHeight: (transaction: any, blockHash: BlockHash, account: GenericAccount) => Promise<{
162
+ blockHeight: string | null;
163
+ } | null>;
164
+ /**
165
+ * Get the votes for a given block
166
+ */
167
+ getVotes: (transaction: any, block: BlockHash, from: LedgerSelector) => Promise<Vote[] | null>;
168
+ /**
169
+ * Get a vote based on the previous hash of a block
170
+ */
171
+ getVotesFromPrevious: (transaction: any, block: BlockHash, from: LedgerSelector) => Promise<Vote[] | null>;
172
+ /**
173
+ * Get multiple votes based on the successors of provided block hashes (both sides)
174
+ */
175
+ getVotesFromMultiplePrevious: (transaction: any, prevBlocks: BlockHash[], from: LedgerSelector, issuer?: Account) => Promise<{
176
+ [hash: string]: Vote[] | null;
177
+ }>;
178
+ /**
179
+ * Get a vote staple from a Vote Block Hash, which uniquely identifies a set of blocks voted on together
180
+ */
181
+ getVoteStaples: (transaction: any, voteBlockHashes: VoteBlockHash[], from: LedgerSelector) => Promise<VoteBlockHashMap<VoteStaple | null>>;
182
+ /**
183
+ * Get the history for a specific account
184
+ */
185
+ getHistory: (transaction: any, account: GenericAccount, start: VoteBlockHash | null, limit?: number) => Promise<VoteBlockHash[]>;
186
+ /**
187
+ * Get multiple head blocks at the same time for a set of accounts
188
+ */
189
+ getHeadBlocks: (transaction: any, accounts: GenericAccount[], from: LedgerSelector) => Promise<{
190
+ [account: string]: Block | null;
191
+ }>;
192
+ /**
193
+ * Get the HEAD block for an account (implemented by LedgerStorageBase using getHeadBlocks())
194
+ */
195
+ getHeadBlock: (transaction: any, account: GenericAccount, from: LedgerSelector) => Promise<Block | null>;
196
+ /**
197
+ * Get a block based on the previous hash of a block
198
+ */
199
+ getBlockFromPrevious: (transaction: any, block: BlockHash, from: LedgerSelector) => Promise<Block | null>;
200
+ /**
201
+ * Get the Account Representative
202
+ */
203
+ getAccountRep: (transaction: any, account: Account | string) => Promise<Account | null>;
204
+ /**
205
+ * Get Votes after a specific moment
206
+ */
207
+ getVotesAfter: (transaction: any, moment: Date, startKey?: string, options?: GetVotesAfterOptions) => Promise<PaginatedVotes>;
208
+ /**
209
+ * Get Vote Staples from a set of block hashes (optional)
210
+ */
211
+ getVoteStaplesFromBlockHash?: (transaction: any, blocks: BlockHash[], from: LedgerSelector) => Promise<VoteStaple[]>;
212
+ /**
213
+ * Get the cache for a transaction (optional)
214
+ */
215
+ cache?: (transaction: any) => LedgerRequestCache | undefined;
216
+ /**
217
+ * Perform Garbage Collection
218
+ */
219
+ gc: (transaction: any) => Promise<true>;
220
+ /**
221
+ * Get the next serial number for a representative
222
+ */
223
+ getNextSerialNumber: (transaction?: any) => Promise<bigint>;
224
+ /**
225
+ * Get ledger statistics
226
+ */
227
+ stats: () => Promise<LedgerStatistics>;
228
+ }
229
+ /**
230
+ * Atomic transactional interface to a storage backend
231
+ */
232
+ declare class LedgerAtomicInterface {
233
+ #private;
234
+ constructor(transaction: any, storage: LedgerStorageAPI, config: LedgerConfig, ledger: Ledger);
235
+ commit(): Promise<void>;
236
+ abort(): Promise<void>;
237
+ vote(blocks: Block[], otherVotes?: Vote[]): Promise<Vote>;
238
+ add(votesAndBlocks: VoteStaple, from?: 'bootstrap' | string): Promise<BlockHash[]>;
239
+ getBalance(account: GenericAccount, token: TokenAddress): Promise<bigint>;
240
+ getAllBalances(account: GenericAccount): Promise<GetAllBalancesResponse>;
241
+ listACLsByPrincipal(principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
242
+ listACLsByEntity(entity: GenericAccount): Promise<ACLRow[]>;
243
+ votingPower(rep?: Account): Promise<bigint>;
244
+ getVotes(block: BlockHash, from?: LedgerStorage): Promise<Vote[] | null>;
245
+ getVotesFromMultiplePrevious(prevBlocks: BlockHash[], from?: LedgerSelector, issuer?: Account): Promise<{
246
+ [hash: string]: Vote[] | null;
247
+ }>;
248
+ getBlockFromPrevious(block: BlockHash, from: LedgerSelector): Promise<Block | null>;
249
+ getHeadBlocks(accounts: GenericAccount[], from: LedgerSelector): Promise<{
250
+ [account: string]: Block | null;
251
+ }>;
252
+ getHeadBlock(account: GenericAccount, from: LedgerSelector): Promise<Block | null>;
253
+ getAccountRep(account: Account | string): Promise<Account | null>;
254
+ getAccountInfo(account: GenericAccount | string): Promise<AccountInfo>;
255
+ getBlock(blockhash: BlockHash, from?: LedgerSelector): Promise<Block | null>;
256
+ getVoteStaple(stapleBlockHash: VoteBlockHash, from?: LedgerSelector): Promise<VoteStaple | null>;
257
+ getVoteStaples(stapleBlockHashes: VoteBlockHash[], from?: LedgerSelector): Promise<VoteBlockHashMap<VoteStaple | null>>;
258
+ getHistory(account: GenericAccount, start: VoteBlockHash | null, limit?: number): Promise<VoteStaple[]>;
259
+ getStaplesFromBlockHashes(hashes: BlockHash[]): Promise<VoteStaple[]>;
260
+ getVoteStaplesAfter(moment: Date, limit?: number, options?: GetVotesAfterOptions): Promise<VoteStaple[]>;
261
+ gc(): Promise<true>;
262
+ _testingRunStorageFunction<T>(code: (storage: LedgerStorageAPI, transaction: any) => Promise<T>): Promise<T>;
263
+ }
264
+ /**
265
+ * The core Ledger components
266
+ */
267
+ export declare class Ledger implements Omit<LedgerAtomicInterface, 'commit' | 'abort'> {
268
+ #private;
269
+ static Kind: typeof LedgerKind;
270
+ readonly baseToken: TokenAddress;
271
+ readonly networkAddress: NetworkAddress;
272
+ readonly initialTrustedAccount: Account;
273
+ readonly node?: Node;
274
+ static isInstance: (obj: any, strict?: boolean) => obj is Ledger;
275
+ constructor(config: LedgerConfig, node?: Node, existingStorage?: LedgerStorageAPI);
276
+ get ledgerWriteMode(): NonNullable<LedgerConfig['ledgerWriteMode']>;
277
+ copy(newNode: Node): Ledger;
278
+ /**
279
+ * Execute some code with a transaction held, if the code fails the
280
+ * transaction is aborted, otherwise it is committed
281
+ *
282
+ * @param code - Code to run
283
+ * @returns The return value from "code"
284
+ */
285
+ run<T>(identifier: string, code: (transaction: LedgerAtomicInterface) => Promise<T>, readOnly?: boolean): Promise<T>;
286
+ runReadOnly<T>(identifier: string, code: (transaction: LedgerAtomicInterface) => Promise<T>): ReturnType<typeof code>;
287
+ beginTransaction(readOnly?: boolean): Promise<LedgerAtomicInterface>;
288
+ vote(...args: Parameters<LedgerAtomicInterface['vote']>): ReturnType<LedgerAtomicInterface['vote']>;
289
+ add(...args: Parameters<LedgerAtomicInterface['add']>): ReturnType<LedgerAtomicInterface['add']>;
290
+ listACLsByPrincipal(...args: Parameters<LedgerAtomicInterface['listACLsByPrincipal']>): ReturnType<LedgerAtomicInterface['listACLsByPrincipal']>;
291
+ listACLsByEntity(...args: Parameters<LedgerAtomicInterface['listACLsByEntity']>): ReturnType<LedgerAtomicInterface['listACLsByEntity']>;
292
+ getBalance(...args: Parameters<LedgerAtomicInterface['getBalance']>): ReturnType<LedgerAtomicInterface['getBalance']>;
293
+ getAllBalances(...args: Parameters<LedgerAtomicInterface['getAllBalances']>): ReturnType<LedgerAtomicInterface['getAllBalances']>;
294
+ votingPower(...args: Parameters<LedgerAtomicInterface['votingPower']>): ReturnType<LedgerAtomicInterface['votingPower']>;
295
+ getVotes(...args: Parameters<LedgerAtomicInterface['getVotes']>): ReturnType<LedgerAtomicInterface['getVotes']>;
296
+ getVotesFromMultiplePrevious(...args: Parameters<LedgerAtomicInterface['getVotesFromMultiplePrevious']>): ReturnType<LedgerAtomicInterface['getVotesFromMultiplePrevious']>;
297
+ getBlockFromPrevious(...args: Parameters<LedgerAtomicInterface['getBlockFromPrevious']>): ReturnType<LedgerAtomicInterface['getBlockFromPrevious']>;
298
+ getHeadBlocks(...args: Parameters<LedgerAtomicInterface['getHeadBlocks']>): ReturnType<LedgerAtomicInterface['getHeadBlocks']>;
299
+ getHeadBlock(...args: Parameters<LedgerAtomicInterface['getHeadBlock']>): ReturnType<LedgerAtomicInterface['getHeadBlock']>;
300
+ getAccountRep(...args: Parameters<LedgerAtomicInterface['getAccountRep']>): ReturnType<LedgerAtomicInterface['getAccountRep']>;
301
+ getAccountInfo(...args: Parameters<LedgerAtomicInterface['getAccountInfo']>): ReturnType<LedgerAtomicInterface['getAccountInfo']>;
302
+ getBlock(...args: Parameters<LedgerAtomicInterface['getBlock']>): ReturnType<LedgerAtomicInterface['getBlock']>;
303
+ getVoteStaple(...args: Parameters<LedgerAtomicInterface['getVoteStaple']>): ReturnType<LedgerAtomicInterface['getVoteStaple']>;
304
+ getVoteStaples(...args: Parameters<LedgerAtomicInterface['getVoteStaples']>): ReturnType<LedgerAtomicInterface['getVoteStaples']>;
305
+ getHistory(...args: Parameters<LedgerAtomicInterface['getHistory']>): ReturnType<LedgerAtomicInterface['getHistory']>;
306
+ getStaplesFromBlockHashes(...args: Parameters<LedgerAtomicInterface['getStaplesFromBlockHashes']>): ReturnType<LedgerAtomicInterface['getStaplesFromBlockHashes']>;
307
+ getVoteStaplesAfter(...args: Parameters<LedgerAtomicInterface['getVoteStaplesAfter']>): ReturnType<LedgerAtomicInterface['getVoteStaplesAfter']>;
308
+ gc(...args: Parameters<LedgerAtomicInterface['gc']>): ReturnType<LedgerAtomicInterface['gc']>;
309
+ stats(): Promise<LedgerStatistics>;
310
+ _testingRunStorageFunction<T>(code: (storage: LedgerStorageAPI, transaction: any) => Promise<T>): Promise<T>;
311
+ }
312
+ export default Ledger;
@@ -0,0 +1,49 @@
1
+ import type { GenericAccount, TokenAddress } from '../account';
2
+ import type { AdjustMethod } from '../block';
3
+ import type Permissions from '../permissions';
4
+ import type { TimeStats } from '../stats';
5
+ /**
6
+ * Account info entry
7
+ */
8
+ export interface AccountInfo {
9
+ name: string;
10
+ description: string;
11
+ metadata: string;
12
+ supply?: bigint;
13
+ defaultPermission?: Permissions;
14
+ }
15
+ /**
16
+ * Permissions types
17
+ */
18
+ export interface ACLRow {
19
+ principal: GenericAccount;
20
+ entity: GenericAccount;
21
+ target: GenericAccount;
22
+ permissions: Permissions;
23
+ }
24
+ export interface ACLEntry extends Omit<ACLRow, 'target'> {
25
+ target?: GenericAccount;
26
+ method?: AdjustMethod.SET;
27
+ }
28
+ export interface ACLUpdate extends Omit<ACLEntry, 'method' | 'permissions'> {
29
+ method: AdjustMethod;
30
+ permissions: Permissions | null;
31
+ }
32
+ /**
33
+ * All balances for each token on an account
34
+ */
35
+ export type GetAllBalancesResponse = {
36
+ balance: bigint;
37
+ token: TokenAddress;
38
+ }[];
39
+ /**
40
+ * Ledger statistics
41
+ */
42
+ export interface LedgerStatistics {
43
+ moment: string;
44
+ momentRange: number;
45
+ blockCount: number;
46
+ transactionCount: number;
47
+ representativeCount: number;
48
+ settlementTimes: TimeStats;
49
+ }
@@ -0,0 +1,114 @@
1
+ import type { LedgerConfig } from '../ledger';
2
+ import Ledger from '../ledger';
3
+ import type { NetworkAddress, TokenAddress } from '../account';
4
+ import Account from '../account';
5
+ import type { StatsConfig } from '../stats';
6
+ import { Stats } from '../stats';
7
+ import type { P2PConnection, P2PPeer, P2PConfig } from '../p2p';
8
+ import { P2PSwitch } from '../p2p';
9
+ import { VoteStaple } from '../vote';
10
+ import RequestTiming from './timing';
11
+ import * as Config from '../../config';
12
+ export declare enum NodeKind {
13
+ PARTICIPANT = 0,
14
+ REPRESENTATIVE = 1,
15
+ RELAY = 2,
16
+ ARCHIVAL = 3
17
+ }
18
+ interface HTTPConfig {
19
+ timeoutSeconds: number;
20
+ }
21
+ export interface NodeConfig {
22
+ /**
23
+ * Kind of node
24
+ */
25
+ kind: NodeKind;
26
+ /**
27
+ * Account that can bypass permissions for opening blocks on baseToken and networkAddress
28
+ * This account also will become the source of authority when there is no weight on the network
29
+ */
30
+ initialTrustedAccount: Account;
31
+ /**
32
+ * Ledger private key (for representatives to issue votes)
33
+ */
34
+ ledgerPrivateKey?: Account;
35
+ /**
36
+ * Network information
37
+ */
38
+ network: bigint;
39
+ subnet?: bigint;
40
+ /**
41
+ * Node alias
42
+ */
43
+ nodeAlias?: string;
44
+ /**
45
+ * Network alias
46
+ */
47
+ networkAlias: Config.Networks;
48
+ /**
49
+ * Endpoints for this node
50
+ */
51
+ endpoints?: {
52
+ p2p?: string;
53
+ api?: string;
54
+ };
55
+ /**
56
+ * Peer to Peer configuration
57
+ */
58
+ p2p?: P2PConfig;
59
+ /**
60
+ * HTTP Configuration
61
+ */
62
+ http?: HTTPConfig;
63
+ /**
64
+ * Manual of peers
65
+ */
66
+ manualPeers?: P2PPeer[];
67
+ /**
68
+ * Information for the ledger
69
+ */
70
+ ledger: Omit<LedgerConfig, 'baseToken' | 'network' | 'kind' | 'networkAddress' | 'initialTrustedAccount'>;
71
+ /**
72
+ * Stats manager
73
+ */
74
+ stats: StatsConfig;
75
+ /**
76
+ * Extra information for the particular kind of node
77
+ */
78
+ nodeOptions?: any;
79
+ /**
80
+ * Changes to default handlers
81
+ */
82
+ callbacks?: {
83
+ /**
84
+ * Method for calling "sendMessage"
85
+ */
86
+ sendMessage?: (node: Node, ...args: Parameters<P2PSwitch['sendMessage']>) => Promise<Awaited<ReturnType<P2PSwitch['sendMessage']>>>;
87
+ };
88
+ }
89
+ export declare class Node {
90
+ ledger: Ledger;
91
+ config: NodeConfig;
92
+ switch: P2PSwitch;
93
+ stats: Stats;
94
+ timing: RequestTiming;
95
+ readonly networkAddress: NetworkAddress;
96
+ readonly baseToken: TokenAddress;
97
+ static Kind: typeof NodeKind;
98
+ static isInstance: (obj: any, strict?: boolean) => obj is Node;
99
+ log: {
100
+ debug: (from: string, ...message: any[]) => void;
101
+ error: (from: string, ...message: any[]) => void;
102
+ };
103
+ static getDefaultConfig(network: Config.Networks): Omit<NodeConfig, 'ledger' | 'stats'>;
104
+ static main(config: NodeConfig): void;
105
+ constructor(configOrNode: Node | NodeConfig);
106
+ copy(): Node;
107
+ run(): Promise<void>;
108
+ stop(): Promise<void>;
109
+ sync(): Promise<void>;
110
+ addToLedger(votesAndBlocks: VoteStaple, broadcast?: boolean): Promise<boolean>;
111
+ recvMessageFromPeer(from: P2PConnection, id: string, type: string, data: any, ttl?: number): Promise<boolean>;
112
+ sendMessage(id: string, type: string, data: any, ttl?: number, exclude?: (P2PConnection | string)[]): Promise<boolean>;
113
+ }
114
+ export default Node;
@@ -0,0 +1,30 @@
1
+ import type { NodeConfig } from './';
2
+ import { Node } from './';
3
+ import type { BootstrapConfig } from '../bootstrap';
4
+ import { BootstrapClient } from '../bootstrap';
5
+ import type { ErrorCode } from '../error';
6
+ export type LocalNodeConfig = NodeConfig & {
7
+ bootstrap?: BootstrapConfig;
8
+ invokeSecret?: string;
9
+ };
10
+ export type ApiErrorResponse = {
11
+ error: boolean;
12
+ message: string;
13
+ type?: string | null;
14
+ code?: ErrorCode | null;
15
+ };
16
+ type LocalNodeRunOptions = {
17
+ startWebSocketServer?: boolean;
18
+ };
19
+ export declare class LocalNode extends Node {
20
+ #private;
21
+ static isInstance: (obj: any, strict?: boolean) => obj is LocalNode;
22
+ constructor(config: LocalNodeConfig);
23
+ addRoutes(prefix?: string): void;
24
+ get _app(): import("express-serve-static-core").Express;
25
+ run(options?: LocalNodeRunOptions): Promise<void>;
26
+ static main(config: LocalNodeConfig): void;
27
+ stop(): Promise<void>;
28
+ get bootstrap(): BootstrapClient | undefined;
29
+ }
30
+ export default LocalNode;
@@ -0,0 +1,12 @@
1
+ export declare class RequestTiming {
2
+ #private;
3
+ startTime(section: string): void;
4
+ endTime(section: string, deduplicate?: boolean): void;
5
+ runTimer<T>(section: string, code: () => Promise<T>, deduplicate?: boolean): Promise<T>;
6
+ getTiming(section: string): number;
7
+ getAllTiming(): {
8
+ [section: string]: number;
9
+ };
10
+ counter(): number;
11
+ }
12
+ export default RequestTiming;
@@ -0,0 +1,4 @@
1
+ import type { NodeConfig } from '.';
2
+ export declare function getConfigFromEnv(type: 'local' | 'lambda'): Partial<Omit<NodeConfig, 'ledger'> & {
3
+ ledger: Partial<NodeConfig['ledger']>;
4
+ }>;