@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,243 @@
1
+ import KeetaNet from '../lib';
2
+ import type { GenericAccount, IdentifierKeyAlgorithm, NetworkAddress, TokenAddress } from '../lib/account';
3
+ import Account, { AccountKeyAlgorithm } from '../lib/account';
4
+ import type { AdjustMethod } from '../lib/block';
5
+ import Block, { BlockHash } from '../lib/block';
6
+ import type { P2PSwitchStatistics } from '../lib/p2p';
7
+ import * as Config from '../config';
8
+ import type { BuilderOptions } from './builder';
9
+ import { UserClientBuilder } from './builder';
10
+ import KeetaNetError from '../lib/error';
11
+ import type { AccountInfo, GetAllBalancesResponse, ACLRow, LedgerStatistics } from '../lib/ledger/types';
12
+ import type { LedgerSelector, LedgerStorage } from '../lib/ledger';
13
+ import type { AcceptedPermissionTypes } from '../lib/permissions';
14
+ type Vote = InstanceType<typeof KeetaNet['Vote']>;
15
+ type VoteStaple = InstanceType<typeof KeetaNet['Vote']['Staple']>;
16
+ type VoteBlocksHash = Vote['blocksHash'];
17
+ type GetAccountStateAPIResponseFormatted = {
18
+ account: GenericAccount;
19
+ currentHeadBlock: string | null;
20
+ representative: Account | null;
21
+ info: AccountInfo;
22
+ balances: GetAllBalancesResponse;
23
+ };
24
+ interface PeerInfo {
25
+ kind: number;
26
+ key?: string;
27
+ endpoint?: string;
28
+ }
29
+ interface GetPeersAPIResponse {
30
+ peers: PeerInfo[];
31
+ }
32
+ interface RepresentativeInfo {
33
+ representative: string;
34
+ weight: bigint;
35
+ }
36
+ interface PrincipalACLWithInfoParsed {
37
+ entity: GenericAccount;
38
+ principals: ACLRow[];
39
+ info: AccountInfo;
40
+ balances: GetAllBalancesResponse;
41
+ }
42
+ interface UserClientOptions {
43
+ usePublishAid?: boolean;
44
+ publishAidURL?: string;
45
+ account?: GenericAccount;
46
+ }
47
+ interface UserClientConfig extends UserClientOptions {
48
+ signer: Account | null;
49
+ client: Client;
50
+ network: bigint;
51
+ networkAlias: Config.Networks;
52
+ }
53
+ export declare class Client {
54
+ #private;
55
+ static readonly Builder: typeof UserClientBuilder;
56
+ static readonly Config: typeof Config;
57
+ static DefaultLogger: Pick<typeof console, 'log' | 'error' | 'warn'>;
58
+ logger: Pick<Console, "error" | "log" | "warn">;
59
+ readonly stats: {
60
+ api: {
61
+ called: number;
62
+ failures: number;
63
+ };
64
+ };
65
+ static fromNetwork(network: Config.Networks): Client;
66
+ static isInstance: (obj: any, strict?: boolean) => obj is Client;
67
+ constructor(reps: Config.Representative[]);
68
+ destroy(): Promise<void>;
69
+ makeBuilder(options: BuilderOptions): UserClientBuilder;
70
+ computeBuilderBlocks(network: bigint, builder: UserClientBuilder): Promise<import("./builder").ComputeBlocksResponse>;
71
+ transmit(blocks: Block[]): ReturnType<Client['transmitStaple']>;
72
+ transmit(blocks: UserClientBuilder, network: bigint): ReturnType<Client['transmitStaple']>;
73
+ transmitStaple(votesAndBlocks: VoteStaple, reps?: Config.Representative[]): Promise<any>;
74
+ getNodeStats(): Promise<{
75
+ ledger: LedgerStatistics;
76
+ switch: P2PSwitchStatistics;
77
+ }>;
78
+ getTokenSupply(token: TokenAddress | string): Promise<bigint>;
79
+ getAccountInfo(account: GenericAccount | string): Promise<GetAccountStateAPIResponseFormatted>;
80
+ getAccountsInfo(accounts: (GenericAccount | string)[]): Promise<{
81
+ [account: string]: GetAccountStateAPIResponseFormatted;
82
+ }>;
83
+ listACLsByPrincipal(account: GenericAccount | string, targets?: (GenericAccount | string)[]): Promise<ACLRow[]>;
84
+ listACLsByPrincipalWithInfo(account: GenericAccount | string, targets?: (GenericAccount | string)[]): Promise<PrincipalACLWithInfoParsed[]>;
85
+ listACLsByEntity(entity: GenericAccount | string): Promise<ACLRow[]>;
86
+ getBalance(account: GenericAccount | string, token: TokenAddress | string): Promise<bigint>;
87
+ getAllBalances(account: GenericAccount | string): Promise<GetAllBalancesResponse>;
88
+ getHeadBlock(account: GenericAccount | string): Promise<Block | null>;
89
+ getBlock(blockhash: BlockHash | string): Promise<Block | null>;
90
+ getBlock(blockhash: BlockHash | string, side?: LedgerSelector, rep?: Config.Representative | 'ANY'): Promise<Block | null>;
91
+ getVoteStaple(blockhash: BlockHash | string): Promise<VoteStaple | null>;
92
+ getVoteStaple(blockhash: BlockHash | string, side?: LedgerStorage): Promise<VoteStaple | null>;
93
+ getChain(account: GenericAccount | string, options?: {
94
+ startBlock?: BlockHash | string;
95
+ depth?: number;
96
+ }): Promise<Block[]>;
97
+ getHistory(account: GenericAccount | string, options?: {
98
+ startBlocksHash?: VoteBlocksHash | string;
99
+ depth?: number;
100
+ }): Promise<{
101
+ voteStaple: VoteStaple;
102
+ }[]>;
103
+ getSingleRepresentativeInfo(rep?: Account | string): Promise<RepresentativeInfo>;
104
+ getPeers(): Promise<GetPeersAPIResponse>;
105
+ getAllRepresentativeInfo(): Promise<RepresentativeInfo[]>;
106
+ get representatives(): Config.Representative[];
107
+ /**
108
+ * Get the network status of all representatives
109
+ *
110
+ * @param timeout Maximum time to wait for a response from a representative in milliseconds
111
+ */
112
+ getNetworkStatus(timeout?: number): Promise<({
113
+ rep: Config.Representative;
114
+ online: false;
115
+ } | {
116
+ rep: Config.Representative;
117
+ online: true;
118
+ ledger: {
119
+ moment: string;
120
+ momentRange: number;
121
+ blockCount: number;
122
+ transactionCount: number;
123
+ representativeCount: number;
124
+ settlementTimes: import("../lib/stats").TimeStats;
125
+ };
126
+ switch: {
127
+ incomingMessages: number;
128
+ outgoingMessagesPeerSuccess: number;
129
+ outgoingMessagesPeerFailure: number;
130
+ outgoingMessagesPeerFiltered: number;
131
+ outgoingMessagesPeerFailureUngreeted: number;
132
+ };
133
+ })[]>;
134
+ updateReps(): Promise<void>;
135
+ getVoteStaplesAfter(moment: Date, limit?: number, bloomFilter?: string): Promise<VoteStaple[]>;
136
+ getPendingBlock(account: GenericAccount): Promise<Block | null>;
137
+ /**
138
+ * Recover any unpublished or half-publish account artifacts
139
+ *
140
+ * @param account Account to recover
141
+ * @param publish Publish the recovered staple to the network (default is true)
142
+ */
143
+ recoverAccount(account: GenericAccount, publish?: boolean): Promise<VoteStaple | null>;
144
+ getLedgerChecksum(rep?: Config.Representative | 'ANY'): Promise<{
145
+ moment: string;
146
+ momentRange: number;
147
+ checksum: string;
148
+ }>;
149
+ getVersion(rep?: Config.Representative | 'ANY'): Promise<{
150
+ node: string;
151
+ }>;
152
+ }
153
+ interface UserClientListenerTypes {
154
+ change: ((data: GetAccountStateAPIResponseFormatted) => void);
155
+ }
156
+ type UserClientEventName = keyof UserClientListenerTypes;
157
+ export declare class UserClient {
158
+ #private;
159
+ static readonly Config: typeof Config;
160
+ readonly baseToken: TokenAddress;
161
+ readonly networkAddress: NetworkAddress;
162
+ static fromSimpleSingleRep(hostname: string, ssl: boolean, repKey: string | Account, networkID: bigint, networkAlias: Config.Networks, signer: Account | null, options?: UserClientOptions): UserClient;
163
+ static getConfigFromNetwork(network: Config.Networks, options?: UserClientOptions): Omit<UserClientConfig, 'signer'>;
164
+ static fromNetwork(network: Config.Networks, signer: Account | null, options?: UserClientOptions): UserClient;
165
+ static isInstance: (obj: any, strict?: boolean) => obj is UserClient;
166
+ constructor(config: UserClientConfig);
167
+ initializeChain(initOpts: {
168
+ addSupplyAmount: bigint;
169
+ delegateTo?: Account;
170
+ voteSerial?: bigint;
171
+ }, options?: UserClientOptions): Promise<any>;
172
+ modTokenSupplyAndBalance(amount: bigint, token: TokenAddress, options?: UserClientOptions): Promise<any>;
173
+ initBuilder(options?: UserClientOptions): UserClientBuilder;
174
+ computeBuilderBlocks(builder: UserClientBuilder): Promise<import("./builder").ComputeBlocksResponse>;
175
+ publishBuilder(builder: UserClientBuilder): Promise<any>;
176
+ setInfo(info: AccountInfo, options?: UserClientOptions): Promise<any>;
177
+ send(to: GenericAccount | string, amount: bigint | number, token: TokenAddress | string, external?: string, options?: UserClientOptions, retries?: number): Promise<void>;
178
+ generateIdentifier(type: IdentifierKeyAlgorithm, options?: UserClientOptions): Promise<import("./builder").PendingAccount<AccountKeyAlgorithm.NETWORK | AccountKeyAlgorithm.TOKEN | AccountKeyAlgorithm.STORAGE>>;
179
+ updatePermissions(principal: GenericAccount | string, permissions: AcceptedPermissionTypes, target?: GenericAccount | string, method?: AdjustMethod, options?: UserClientOptions): Promise<any>;
180
+ allBalances(options?: UserClientOptions): Promise<GetAllBalancesResponse>;
181
+ balance(token: TokenAddress | string, options?: UserClientOptions): Promise<bigint>;
182
+ head(options?: UserClientOptions): Promise<BlockHash | null>;
183
+ block(blockhash: BlockHash | string): Promise<Block | null>;
184
+ chain(query?: Parameters<Client['getChain']>[1], options?: UserClientOptions): Promise<Block[]>;
185
+ history(query?: Parameters<Client['getHistory']>[1], options?: UserClientOptions): Promise<{
186
+ voteStaple: import("../lib/vote").VoteStaple;
187
+ effects: import("../lib/ledger/effects").ComputedEffectOfBlocks;
188
+ }[]>;
189
+ state(options?: UserClientOptions): ReturnType<Client['getAccountInfo']>;
190
+ listACLsByPrincipal(entity?: (GenericAccount | string)[], options?: UserClientOptions): ReturnType<Client['listACLsByPrincipal']>;
191
+ listACLsByEntity(options?: UserClientOptions): ReturnType<Client['listACLsByEntity']>;
192
+ listACLsByPrincipalWithInfo(options?: UserClientOptions): ReturnType<Client['listACLsByPrincipalWithInfo']>;
193
+ pendingBlock(options?: UserClientOptions): Promise<Block | null>;
194
+ /**
195
+ * Recover any unpublished or half-publish account artifacts
196
+ *
197
+ * @param publish Publish the recovered staple to the network
198
+ * (default: true)
199
+ * @param options User client options (common options)
200
+ */
201
+ recover(publish?: boolean, options?: UserClientOptions): Promise<VoteStaple | null>;
202
+ /**
203
+ * Register a callback for change messages and set up a websocket filtered to our account only.
204
+ * Also set up long timeout polling for changes in case the websocket misses a change update
205
+ * Check that parameters of function complies with respective event function
206
+ */
207
+ on<EventName extends UserClientEventName>(event: EventName, handler: UserClientListenerTypes[EventName]): symbol;
208
+ /**
209
+ * Cancel a previously registered callback
210
+ */
211
+ off(id: symbol): void;
212
+ destroy(): Promise<void>;
213
+ get config(): UserClientConfig;
214
+ get client(): Client;
215
+ get signer(): Account | null;
216
+ get account(): GenericAccount;
217
+ get network(): bigint;
218
+ get readonly(): boolean;
219
+ }
220
+ export declare function blockGenerator(seed: string, index: number, transactionCount: number, network?: bigint): Promise<import("../lib/vote").VoteStaple>;
221
+ export declare function emitBlocks(client: Client, blocks: number, seed: string, index: number, transactionCount: number, network?: bigint): Promise<void>;
222
+ export declare const lib: {
223
+ Account: typeof Account;
224
+ Block: typeof Block;
225
+ Error: typeof KeetaNetError;
226
+ Ledger: typeof import("../lib/ledger").Ledger;
227
+ Node: typeof import("../lib/node").Node;
228
+ P2P: typeof import("../lib/p2p").P2PSwitch;
229
+ Permissions: typeof import("../lib/permissions").default;
230
+ Stats: typeof import("../lib/stats").Stats;
231
+ Vote: typeof import("../lib/vote").Vote;
232
+ Utils: {
233
+ ASN1: typeof import("../lib/utils/asn1");
234
+ Bloom: typeof import("../lib/utils/bloom");
235
+ Buffer: typeof import("../lib/utils/buffer");
236
+ Hash: typeof import("../lib/utils/hash");
237
+ Helper: typeof import("../lib/utils/helper");
238
+ Initial: typeof import("../lib/utils/initial");
239
+ Conversion: typeof import("../lib/utils/conversion");
240
+ Certificate: typeof import("../lib/utils/certificate");
241
+ };
242
+ };
243
+ export default Client;