@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.
- package/._version.d.ts +0 -0
- package/LICENSE +35 -0
- package/api/index.d.ts +181 -0
- package/api/node.d.ts +216 -0
- package/api/vote.d.ts +25 -0
- package/client/builder.d.ts +129 -0
- package/client/client_common_tests.d.ts +72 -0
- package/client/index-browser.d.ts +243 -0
- package/client/index-browser.js +141899 -0
- package/client/index.d.ts +243 -0
- package/client/index.js +89118 -0
- package/config/index.d.ts +62 -0
- package/lib/account.d.ts +544 -0
- package/lib/block/index.d.ts +181 -0
- package/lib/block/operations.d.ts +407 -0
- package/lib/bootstrap.d.ts +27 -0
- package/lib/error/account.d.ts +9 -0
- package/lib/error/block.d.ts +9 -0
- package/lib/error/client.d.ts +9 -0
- package/lib/error/index.d.ts +20 -0
- package/lib/error/kv.d.ts +9 -0
- package/lib/error/ledger.d.ts +12 -0
- package/lib/error/permissions.d.ts +9 -0
- package/lib/error/vote.d.ts +9 -0
- package/lib/index.d.ts +39 -0
- package/lib/kv/index.d.ts +22 -0
- package/lib/kv/index.test.data.d.ts +9 -0
- package/lib/kv/kv_dynamodb.d.ts +20 -0
- package/lib/kv/kv_memory.d.ts +17 -0
- package/lib/kv/kv_redis.d.ts +22 -0
- package/lib/kv/providers.d.ts +9 -0
- package/lib/ledger/cache.d.ts +14 -0
- package/lib/ledger/common.d.ts +115 -0
- package/lib/ledger/db_dynamodb.d.ts +129 -0
- package/lib/ledger/db_memory.d.ts +6 -0
- package/lib/ledger/db_postgres.d.ts +70 -0
- package/lib/ledger/db_spanner.d.ts +116 -0
- package/lib/ledger/db_spanner_helper.d.ts +487 -0
- package/lib/ledger/db_sqlite.d.ts +64 -0
- package/lib/ledger/drivers.d.ts +7 -0
- package/lib/ledger/effects.d.ts +78 -0
- package/lib/ledger/index.d.ts +312 -0
- package/lib/ledger/types.d.ts +49 -0
- package/lib/node/index.d.ts +114 -0
- package/lib/node/local.d.ts +30 -0
- package/lib/node/timing.d.ts +12 -0
- package/lib/node/utils.d.ts +4 -0
- package/lib/p2p.d.ts +300 -0
- package/lib/permissions.d.ts +121 -0
- package/lib/pubsub/index.d.ts +7 -0
- package/lib/pubsub/providers.d.ts +7 -0
- package/lib/pubsub/ps_memory.d.ts +9 -0
- package/lib/pubsub/ps_redis.d.ts +10 -0
- package/lib/stats.d.ts +51 -0
- package/lib/utils/asn1.d.ts +205 -0
- package/lib/utils/bitfield.d.ts +13 -0
- package/lib/utils/bloom.d.ts +6 -0
- package/lib/utils/buffer.d.ts +27 -0
- package/lib/utils/certificate.d.ts +340 -0
- package/lib/utils/conversion.d.ts +46 -0
- package/lib/utils/dynamodb.d.ts +17 -0
- package/lib/utils/ed2curve.d.ts +7 -0
- package/lib/utils/hash.d.ts +17 -0
- package/lib/utils/helper.d.ts +67 -0
- package/lib/utils/helper_testing.d.ts +37 -0
- package/lib/utils/initial.d.ts +32 -0
- package/lib/utils/never.d.ts +7 -0
- package/lib/utils/redis.d.ts +11 -0
- package/lib/vote.d.ts +273 -0
- package/package.json +35 -0
- package/version.d.ts +2 -0
package/lib/p2p.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type net from 'net';
|
|
2
|
+
import { WebSocket } from 'ws';
|
|
3
|
+
import Node, { NodeKind } from './node';
|
|
4
|
+
import Account from './account';
|
|
5
|
+
import type { JSONSerializable, JSONSerializableObject } from './utils/conversion';
|
|
6
|
+
import type { DistributiveOmit } from './utils/helper';
|
|
7
|
+
import type { KVStorageProvider } from './kv';
|
|
8
|
+
import type { Representative } from '../config';
|
|
9
|
+
/**
|
|
10
|
+
* Peer to Peer connection configuration
|
|
11
|
+
*/
|
|
12
|
+
export interface P2PConfig {
|
|
13
|
+
/**
|
|
14
|
+
* How long should a P2P connection allowed to be idle (after
|
|
15
|
+
* greeting, excluding listeners) (ms)
|
|
16
|
+
*/
|
|
17
|
+
timeoutIdle?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How long should a P2P connection be allowed to be idle for a
|
|
20
|
+
* greeting to complete (ms)
|
|
21
|
+
*/
|
|
22
|
+
timeoutIdleGreeting?: number;
|
|
23
|
+
/**
|
|
24
|
+
* How long should a P2P connection from a listener allowed to be
|
|
25
|
+
* idle (ms)
|
|
26
|
+
*/
|
|
27
|
+
timeoutIdleListener?: number;
|
|
28
|
+
/**
|
|
29
|
+
* How frequently should the idle connection checker run and terminate
|
|
30
|
+
* connections (ms)
|
|
31
|
+
*/
|
|
32
|
+
timeoutIdleCheck?: number;
|
|
33
|
+
/**
|
|
34
|
+
* How frequently should manual peers be connected to in order to get
|
|
35
|
+
* additional peering information (ms)
|
|
36
|
+
*/
|
|
37
|
+
manualPeersCheckInFreq?: number;
|
|
38
|
+
/**
|
|
39
|
+
* How many peers should messages that are being broadcast be
|
|
40
|
+
* forwarded to
|
|
41
|
+
*/
|
|
42
|
+
forwardingPeerCount?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Key-Value Storage Instance (null means a new in-memory instance will be created)
|
|
45
|
+
*/
|
|
46
|
+
kv?: KVStorageProvider | null;
|
|
47
|
+
/**
|
|
48
|
+
* Forget about seen message ids after this many milliseconds
|
|
49
|
+
*/
|
|
50
|
+
seenMessageTTL?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Shape of statistics
|
|
54
|
+
*/
|
|
55
|
+
export interface P2PSwitchStatistics {
|
|
56
|
+
incomingMessages: number;
|
|
57
|
+
outgoingMessagesPeerSuccess: number;
|
|
58
|
+
outgoingMessagesPeerFailure: number;
|
|
59
|
+
outgoingMessagesPeerFiltered: number;
|
|
60
|
+
outgoingMessagesPeerFailureUngreeted: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* How we should represent peers internally. Peers are known endpoints we can
|
|
64
|
+
* connect to or placeholders for inbound connections
|
|
65
|
+
*/
|
|
66
|
+
interface P2PPeerBase {
|
|
67
|
+
kind: NodeKind;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Peering information for a Representative (Basic, unsigned information)
|
|
71
|
+
*/
|
|
72
|
+
interface P2PPeerRepBase extends P2PPeerBase {
|
|
73
|
+
kind: NodeKind.REPRESENTATIVE;
|
|
74
|
+
/**
|
|
75
|
+
* Endpoint to reach the representative
|
|
76
|
+
*/
|
|
77
|
+
endpoint: string;
|
|
78
|
+
/**
|
|
79
|
+
* Public key of the representative (used as the ID)
|
|
80
|
+
*/
|
|
81
|
+
key: Account;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Peering information for a Representative
|
|
85
|
+
*/
|
|
86
|
+
type P2PPeerRep = P2PPeerRepBase & ({
|
|
87
|
+
/**
|
|
88
|
+
* Certificate from this peer which confirms its endpoints
|
|
89
|
+
*/
|
|
90
|
+
certificate: null;
|
|
91
|
+
} | {
|
|
92
|
+
/**
|
|
93
|
+
* Direct signature of the peer information
|
|
94
|
+
*/
|
|
95
|
+
signature: ArrayBuffer;
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Peering information for an inbound socket which has no callback information
|
|
99
|
+
*/
|
|
100
|
+
interface P2PPeerListener extends P2PPeerBase {
|
|
101
|
+
kind: NodeKind.PARTICIPANT;
|
|
102
|
+
/**
|
|
103
|
+
* Temporary ID to use for identifying this peer while we are connected to it
|
|
104
|
+
*/
|
|
105
|
+
id: string;
|
|
106
|
+
}
|
|
107
|
+
export type P2PPeer = P2PPeerRep | P2PPeerListener;
|
|
108
|
+
type P2PPeerUnsigned = DistributiveOmit<P2PPeer, 'certificate' | 'signature'>;
|
|
109
|
+
export declare function generateP2PPeerSigned(peer: P2PPeerUnsigned): Promise<P2PPeer>;
|
|
110
|
+
/**
|
|
111
|
+
* Options for the "peers" method
|
|
112
|
+
*/
|
|
113
|
+
interface GetPeersOptions {
|
|
114
|
+
/**
|
|
115
|
+
* Whether or not to consider ourselves (if we are attached to a
|
|
116
|
+
* representative node) as a peer. Default is false.
|
|
117
|
+
*/
|
|
118
|
+
includeSelf?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Whether or not to include peers which are potentially stale
|
|
121
|
+
* because we have not heard from them in a while. Default is false.
|
|
122
|
+
*/
|
|
123
|
+
includeStale?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Whether or not to include peers which have not been validated
|
|
126
|
+
* yet. Default is false.
|
|
127
|
+
*/
|
|
128
|
+
includeUnverified?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export declare function P2PPeerFromJSO(object: any): P2PPeer | null;
|
|
131
|
+
export declare function P2PPeerToJSO(peer: P2PPeer): JSONSerializableObject;
|
|
132
|
+
type SerializedConnection = {
|
|
133
|
+
[key: string]: JSONSerializable;
|
|
134
|
+
type: string;
|
|
135
|
+
data: string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Represents an active connection on the P2P network
|
|
139
|
+
*/
|
|
140
|
+
export interface P2PConnection {
|
|
141
|
+
/**
|
|
142
|
+
* Signal to abort the connection
|
|
143
|
+
*/
|
|
144
|
+
abort: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Peer information, if null the peer has not yet greeted us so we do
|
|
147
|
+
* not know who they are
|
|
148
|
+
*/
|
|
149
|
+
peer: P2PPeer | null;
|
|
150
|
+
/**
|
|
151
|
+
* Printable form of the peer
|
|
152
|
+
*/
|
|
153
|
+
peerString: string | null;
|
|
154
|
+
/**
|
|
155
|
+
* Printable form of the connection
|
|
156
|
+
*/
|
|
157
|
+
connString: string;
|
|
158
|
+
/**
|
|
159
|
+
* The peering information is normally untrusted since it just what
|
|
160
|
+
* the peer gave us once it has been validated we can populate this.
|
|
161
|
+
*
|
|
162
|
+
* Validation can be via a callback to the peer or a certificate
|
|
163
|
+
*
|
|
164
|
+
* A callback isn't as reliable since it could be a MITM proxy
|
|
165
|
+
*/
|
|
166
|
+
validatedPeer: P2PPeer | null;
|
|
167
|
+
/**
|
|
168
|
+
* Timeout of when to close this connection (Date.valueOf)
|
|
169
|
+
*/
|
|
170
|
+
timeout: number;
|
|
171
|
+
/**
|
|
172
|
+
* If this connection can be serialized to our KV store,
|
|
173
|
+
* return the type.
|
|
174
|
+
*
|
|
175
|
+
* @see P2PSwitch.RegisterP2PConnectionDeserializer
|
|
176
|
+
* for registering a handler to convert it back
|
|
177
|
+
*/
|
|
178
|
+
serialize?: () => SerializedConnection;
|
|
179
|
+
/**
|
|
180
|
+
* Method to send a message to this peer
|
|
181
|
+
*/
|
|
182
|
+
send: (data: Buffer) => Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* Method to close this connection
|
|
185
|
+
*/
|
|
186
|
+
close: () => Promise<void>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Transportable form a of a message
|
|
190
|
+
*/
|
|
191
|
+
type JSONMessage = {
|
|
192
|
+
valid: true;
|
|
193
|
+
id: string;
|
|
194
|
+
type: string;
|
|
195
|
+
data: any;
|
|
196
|
+
ttl: number | undefined;
|
|
197
|
+
};
|
|
198
|
+
export declare function randomizeReps(reps: Representative[]): Representative[];
|
|
199
|
+
export declare function formatRepEndpoints(peers: P2PPeer[]): Representative[];
|
|
200
|
+
/**
|
|
201
|
+
* A P2PConnection using the "ws" package
|
|
202
|
+
*/
|
|
203
|
+
export declare class P2PWebSocket implements P2PConnection {
|
|
204
|
+
#private;
|
|
205
|
+
abort: boolean;
|
|
206
|
+
peer: P2PPeer | null;
|
|
207
|
+
validatedPeer: P2PPeer | null;
|
|
208
|
+
timeout: number;
|
|
209
|
+
/**
|
|
210
|
+
* Initiate an outbound websocket connection and attach it to the specified switch
|
|
211
|
+
*/
|
|
212
|
+
static initiate(peer: P2PPeer, p2pSwitch: P2PSwitch): Promise<P2PWebSocket | null>;
|
|
213
|
+
/**
|
|
214
|
+
* Attach a new "ws" connection to the switch
|
|
215
|
+
*/
|
|
216
|
+
static connectToSwitch(socket: WebSocket, p2pSwitch: P2PSwitch, underlyingSocket?: net.Socket): Promise<P2PWebSocket>;
|
|
217
|
+
static isInstance: (obj: any, strict?: boolean) => obj is P2PWebSocket;
|
|
218
|
+
constructor(socket: WebSocket, p2pSwitch: P2PSwitch, underlyingSocket?: net.Socket);
|
|
219
|
+
get connString(): string;
|
|
220
|
+
get peerString(): string | null;
|
|
221
|
+
send(messageBuffer: Buffer): Promise<boolean>;
|
|
222
|
+
close(): Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The interfaces from the Node that the P2P switch uses
|
|
226
|
+
*/
|
|
227
|
+
type NodeLike = Pick<Node, 'recvMessageFromPeer' | 'config' | 'stats' | 'log'>;
|
|
228
|
+
/**
|
|
229
|
+
* Deserializer DB
|
|
230
|
+
*/
|
|
231
|
+
type DeserializerCallback = (node: NodeLike, data: string) => P2PConnection;
|
|
232
|
+
/**
|
|
233
|
+
* A P2PSwitch is a method of coordinating messages from peers (either
|
|
234
|
+
* connected or known) with a Node.
|
|
235
|
+
*/
|
|
236
|
+
export declare class P2PSwitch {
|
|
237
|
+
#private;
|
|
238
|
+
readonly config: Omit<Required<P2PConfig>, 'kv'> & {
|
|
239
|
+
kv: NonNullable<P2PConfig['kv']>;
|
|
240
|
+
};
|
|
241
|
+
static RegisterP2PConnectionDeserializer(type: string, deserializer: DeserializerCallback): void;
|
|
242
|
+
static isInstance: (obj: any, strict?: boolean) => obj is P2PSwitch;
|
|
243
|
+
DeserializeP2PConnection(connString: string): Promise<P2PConnection | undefined>;
|
|
244
|
+
constructor(node: NodeLike);
|
|
245
|
+
/**
|
|
246
|
+
* Get a list of known peers
|
|
247
|
+
*/
|
|
248
|
+
peers(options?: GetPeersOptions): Promise<P2PPeer[]>;
|
|
249
|
+
/**
|
|
250
|
+
* Add a manual peer to initiate peering process
|
|
251
|
+
*
|
|
252
|
+
* The switch will periodically reach out to this peer to build its
|
|
253
|
+
* peer database
|
|
254
|
+
*/
|
|
255
|
+
addManualPeer(peer: P2PPeer, schedule?: boolean): void;
|
|
256
|
+
/**
|
|
257
|
+
* Stop this switch
|
|
258
|
+
*/
|
|
259
|
+
stop(): Promise<void>;
|
|
260
|
+
/**
|
|
261
|
+
* Handle any waiting that needs to be done
|
|
262
|
+
*/
|
|
263
|
+
wait(): Promise<void>;
|
|
264
|
+
stats(): Promise<P2PSwitchStatistics>;
|
|
265
|
+
registerConnection(conn: P2PConnection): Promise<void>;
|
|
266
|
+
unregisterConnection(conn: P2PConnection): Promise<void>;
|
|
267
|
+
static parseJSONMessage(messageBuffer: Buffer | ArrayBuffer): {
|
|
268
|
+
valid: false;
|
|
269
|
+
reason: string;
|
|
270
|
+
} | JSONMessage;
|
|
271
|
+
/**
|
|
272
|
+
* Our own peer information
|
|
273
|
+
*/
|
|
274
|
+
selfPeer(): Promise<P2PPeer | null>;
|
|
275
|
+
/**
|
|
276
|
+
* Receive a message from a connection
|
|
277
|
+
*
|
|
278
|
+
* This message will get sent to our local node, which may then rebroadcast it
|
|
279
|
+
*/
|
|
280
|
+
recvMessageFromPeer(from: P2PConnection, messageBuffer: Buffer | ArrayBuffer): Promise<boolean>;
|
|
281
|
+
/**
|
|
282
|
+
* Send a message to one or more peers
|
|
283
|
+
*
|
|
284
|
+
* If they are already connected that connection will be re-used,
|
|
285
|
+
* otherwise a new connection will be established.
|
|
286
|
+
*
|
|
287
|
+
* If "to" is null then it will be sent to a sampling of peers
|
|
288
|
+
*
|
|
289
|
+
* @param to - Where to send the message
|
|
290
|
+
* @param id - Unique message identifier
|
|
291
|
+
* @param type - Message type
|
|
292
|
+
* @param data - Message data, must be serializable to JSON
|
|
293
|
+
* @param ttl - Maximum number of hops to pass through
|
|
294
|
+
* @param exclude - List of connections to exclude (e.g., because we got the message from that connection) if "to" is null
|
|
295
|
+
* @param skipConnectToPeers - Skip creating new connections to send to, only connected clients will be sent the message
|
|
296
|
+
* @returns If the message could be delivered to at least one peer
|
|
297
|
+
*/
|
|
298
|
+
sendMessage(to: P2PConnection | Account | P2PPeer | null, id: string, type: string, data: any, ttl?: number, exclude?: (string | P2PConnection)[], skipConnectToPeers?: boolean): Promise<boolean>;
|
|
299
|
+
}
|
|
300
|
+
export default P2PSwitch;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { GenericAccount } from './account';
|
|
2
|
+
import BitField from './utils/bitfield';
|
|
3
|
+
declare const externalFlagPrefix: "EXTERNAL_";
|
|
4
|
+
/**
|
|
5
|
+
* Flags we have for non-external permissions
|
|
6
|
+
*/
|
|
7
|
+
declare enum BaseFlag {
|
|
8
|
+
ACCESS = 0,/* 0x0001 */
|
|
9
|
+
OWNER = 1,/* 0x0002 */
|
|
10
|
+
ADMIN = 2,/* 0x0004 */
|
|
11
|
+
UPDATE_INFO = 3,/* 0x0008 */
|
|
12
|
+
SEND_ON_BEHALF = 4,/* 0x0010 */
|
|
13
|
+
STORAGE_CAN_HOLD = 9,/* 0x0200 */
|
|
14
|
+
STORAGE_DEPOSIT = 10,/* 0x0400 */
|
|
15
|
+
STORAGE_CREATE = 8,/* 0x0100 */
|
|
16
|
+
TOKEN_ADMIN_CREATE = 5,/* 0x0020 */
|
|
17
|
+
TOKEN_ADMIN_SUPPLY = 6,/* 0x0040 */
|
|
18
|
+
TOKEN_ADMIN_MODIFY_BALANCE = 7,/* 0x0080 */
|
|
19
|
+
PERMISSION_DELEGATE_ADD = 11,/* 0x0800 */
|
|
20
|
+
PERMISSION_DELEGATE_REMOVE = 12
|
|
21
|
+
}
|
|
22
|
+
type ExternalFlagName = `${typeof externalFlagPrefix}${string}`;
|
|
23
|
+
export type BaseFlagName = keyof typeof BaseFlag;
|
|
24
|
+
export type BaseFlagNames = BaseFlagName[];
|
|
25
|
+
type FlagOrExternalName = BaseFlagName | ExternalFlagName;
|
|
26
|
+
type FlagOrExternalNames = FlagOrExternalName[];
|
|
27
|
+
type ExternalPermissionOffsetSet = {
|
|
28
|
+
[key: ExternalFlagName]: number;
|
|
29
|
+
};
|
|
30
|
+
type BasePermissionOffsetSet = {
|
|
31
|
+
[K in BaseFlagName]: number;
|
|
32
|
+
};
|
|
33
|
+
type PermissionOffsetSet = ExternalPermissionOffsetSet | BasePermissionOffsetSet;
|
|
34
|
+
/**
|
|
35
|
+
* Handles what flags are in what groups, groups cannot be mixed (except BASE)
|
|
36
|
+
* network/token permissions must be granted on network/token identifiers
|
|
37
|
+
*/
|
|
38
|
+
declare enum BasePermissionGroup {
|
|
39
|
+
NEVER = 0,
|
|
40
|
+
ANY = 1,
|
|
41
|
+
NONIDENTIFIER = 2,
|
|
42
|
+
NETWORK = 3,
|
|
43
|
+
TOKEN = 4,
|
|
44
|
+
STORAGE = 5
|
|
45
|
+
}
|
|
46
|
+
interface BaseFlagRule {
|
|
47
|
+
canBeDefault: boolean;
|
|
48
|
+
entity: BasePermissionGroup;
|
|
49
|
+
principal: BasePermissionGroup;
|
|
50
|
+
target: BasePermissionGroup;
|
|
51
|
+
}
|
|
52
|
+
type FlagGroupType = Exclude<keyof BaseFlagRule, 'canBeDefault'>;
|
|
53
|
+
/**
|
|
54
|
+
* Abstract class to hold permissions, handles storage and some basic functions
|
|
55
|
+
*/
|
|
56
|
+
declare abstract class PermissionSetHolder {
|
|
57
|
+
protected storage: BitField;
|
|
58
|
+
constructor(initialValue: bigint | number[]);
|
|
59
|
+
protected computeFlagsFromOffsetSet(offsets: PermissionOffsetSet): FlagOrExternalNames;
|
|
60
|
+
get bigint(): bigint;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Base Set permission holder
|
|
64
|
+
*/
|
|
65
|
+
declare class BaseSet extends PermissionSetHolder {
|
|
66
|
+
#private;
|
|
67
|
+
static isInstance: (obj: any, strict?: boolean) => obj is BaseSet;
|
|
68
|
+
static BasePermissionGroup: typeof BasePermissionGroup;
|
|
69
|
+
constructor(presetFlags: bigint | number[]);
|
|
70
|
+
static Create(presetFlags: bigint | number[] | BaseFlagNames): BaseSet;
|
|
71
|
+
hasFlags(flags: BaseFlagName | BaseFlagNames): boolean;
|
|
72
|
+
checkAccountMatchesGroup(type: FlagGroupType, account?: GenericAccount): boolean;
|
|
73
|
+
get flags(): BaseFlagNames;
|
|
74
|
+
get isValidForDefault(): boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* External permission set holder
|
|
78
|
+
*/
|
|
79
|
+
declare class ExternalSet extends PermissionSetHolder {
|
|
80
|
+
#private;
|
|
81
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ExternalSet;
|
|
82
|
+
constructor(presetOffsets?: bigint | number[]);
|
|
83
|
+
static Create(presetFlags: bigint | number[]): ExternalSet;
|
|
84
|
+
validate(network: bigint): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Takes an offset set
|
|
87
|
+
* Returns an array of external flags that are true in relation to current storage
|
|
88
|
+
*/
|
|
89
|
+
computeFlagNames(offsets: ExternalPermissionOffsetSet): FlagOrExternalNames;
|
|
90
|
+
hasOffset(offset: number): boolean;
|
|
91
|
+
setOffset(offset: number, value: boolean): void;
|
|
92
|
+
setFromTrueOffsets(trueOffset: number[]): void;
|
|
93
|
+
get trueOffsets(): number[];
|
|
94
|
+
}
|
|
95
|
+
export type { BaseSet, ExternalSet };
|
|
96
|
+
export type AcceptedPermissionTypes = Permissions | [string, number[]] | [string, string] | [BaseFlagNames | number[], number[]] | [bigint, bigint] | false;
|
|
97
|
+
/**
|
|
98
|
+
* Class to hold a Base and External permission set
|
|
99
|
+
*/
|
|
100
|
+
export default class Permissions {
|
|
101
|
+
#private;
|
|
102
|
+
static isInstance: (obj: any, strict?: boolean) => obj is Permissions;
|
|
103
|
+
static BaseSet: typeof BaseSet;
|
|
104
|
+
static ExternalSet: typeof ExternalSet;
|
|
105
|
+
static FromAcceptedTypes(perms: AcceptedPermissionTypes): Permissions;
|
|
106
|
+
constructor(baseFlags?: BaseSet | BaseFlagNames | bigint, externalOffsets?: ExternalSet | number[] | bigint);
|
|
107
|
+
validate(network: bigint): boolean;
|
|
108
|
+
has(flags: BaseFlagNames, offsets?: number[]): boolean;
|
|
109
|
+
has(instance: Permissions): boolean;
|
|
110
|
+
static combine(combineFrom: Permissions, toCombine: Permissions): Permissions;
|
|
111
|
+
combine(toCombine: Permissions): Permissions;
|
|
112
|
+
static remove(removeFrom: Permissions, toRemove: Permissions): Permissions;
|
|
113
|
+
remove(toRemove: Permissions): Permissions;
|
|
114
|
+
compare(toCompare?: Permissions): boolean;
|
|
115
|
+
get toUpdateRequires(): Permissions;
|
|
116
|
+
get canUseDelegation(): boolean;
|
|
117
|
+
get base(): BaseSet;
|
|
118
|
+
get external(): ExternalSet;
|
|
119
|
+
static toJSONSerializablePrefix: string;
|
|
120
|
+
static toJSONSerializable(value: Permissions): bigint[];
|
|
121
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
2
|
+
export type SubscriptionCallback = (message: JSONSerializable) => void;
|
|
3
|
+
export interface PubSubProviderAPI {
|
|
4
|
+
subscribe: (channel: string, callback: SubscriptionCallback) => Promise<void>;
|
|
5
|
+
publish: (channel: string, message: JSONSerializable) => Promise<void>;
|
|
6
|
+
destroy: () => Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
2
|
+
import type { PubSubProviderAPI, SubscriptionCallback } from './';
|
|
3
|
+
export declare class PubSubProviderMemory implements PubSubProviderAPI {
|
|
4
|
+
#private;
|
|
5
|
+
publish(channel: string, message: JSONSerializable): Promise<void>;
|
|
6
|
+
subscribe(channel: string, callback: SubscriptionCallback): Promise<void>;
|
|
7
|
+
destroy(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export default PubSubProviderMemory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JSONSerializable } from '../utils/conversion';
|
|
2
|
+
import type { PubSubProviderAPI, SubscriptionCallback } from './';
|
|
3
|
+
export declare class PubSubProviderRedis implements PubSubProviderAPI {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(host: string, password: string, port?: number);
|
|
6
|
+
subscribe(channel: string, callback: SubscriptionCallback): Promise<void>;
|
|
7
|
+
publish(channel: string, message: JSONSerializable): Promise<void>;
|
|
8
|
+
destroy(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export default PubSubProviderRedis;
|
package/lib/stats.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { KVStorageProvider } from './kv';
|
|
2
|
+
import BufferStorage from './utils/buffer';
|
|
3
|
+
import type { BlockHash } from './block';
|
|
4
|
+
export interface StatsConfig {
|
|
5
|
+
kv: KVStorageProvider | null;
|
|
6
|
+
}
|
|
7
|
+
declare const durationRanges: {
|
|
8
|
+
readonly '-1ms': readonly [-1, -1];
|
|
9
|
+
readonly '0ms': readonly [0, 0];
|
|
10
|
+
readonly '10ms': readonly [1, 10];
|
|
11
|
+
readonly '100ms': readonly [11, 100];
|
|
12
|
+
readonly '200ms': readonly [101, 200];
|
|
13
|
+
readonly '300ms': readonly [201, 300];
|
|
14
|
+
readonly '400ms': readonly [301, 400];
|
|
15
|
+
readonly '500ms': readonly [401, 500];
|
|
16
|
+
readonly '600ms': readonly [501, 600];
|
|
17
|
+
readonly '700ms': readonly [601, 700];
|
|
18
|
+
readonly '800ms': readonly [701, 800];
|
|
19
|
+
readonly '900ms': readonly [801, 900];
|
|
20
|
+
readonly '1000ms': readonly [901, 1000];
|
|
21
|
+
readonly '1500ms': readonly [1001, 1500];
|
|
22
|
+
readonly '2000ms': readonly [1501, 2000];
|
|
23
|
+
readonly '5000ms': readonly [2001, 5000];
|
|
24
|
+
readonly '10000ms': readonly [5001, 10000];
|
|
25
|
+
readonly '100000ms': readonly [10001, 100000];
|
|
26
|
+
readonly ExtraLong: readonly [100000, number];
|
|
27
|
+
};
|
|
28
|
+
export type DurationBreakdowns = keyof typeof durationRanges;
|
|
29
|
+
type TimeStat = {
|
|
30
|
+
count: number;
|
|
31
|
+
range: [number, number];
|
|
32
|
+
};
|
|
33
|
+
export type TimeStats = {
|
|
34
|
+
[duration in DurationBreakdowns]: TimeStat;
|
|
35
|
+
};
|
|
36
|
+
export declare class Stats {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(config: StatsConfig);
|
|
39
|
+
static durationBreakdownList(): DurationBreakdowns[];
|
|
40
|
+
static assertDurationBreakdown(duration: string): asserts duration is DurationBreakdowns;
|
|
41
|
+
static durationBreakdown(duration: number): DurationBreakdowns;
|
|
42
|
+
static placeholderTimingData(): TimeStats;
|
|
43
|
+
incr(arena: string, key: string, change?: number): void;
|
|
44
|
+
xor(key: string, change: BlockHash | BufferStorage): void;
|
|
45
|
+
getXor(key: string): Promise<BufferStorage>;
|
|
46
|
+
addTimingPoint(arena: string, category: string, duration: number, returnOnly?: boolean): Parameters<Stats['incr']>;
|
|
47
|
+
get(arena: string, key: string): Promise<number>;
|
|
48
|
+
getTimingData(arena: string, category: string): Promise<TimeStats>;
|
|
49
|
+
sync(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export default Stats;
|