-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.d.ts
322 lines (289 loc) · 9.21 KB
/
index.d.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
export interface ConstructorOptions {
apiKey: string;
}
export interface RandomOrgRPCResponse<T> {
random: {
/**
* Your requested random numbers or strings.
*/
data: T;
/**
* The time that request was completed, in ISO 8601 format (parsable with new Date(isoString)).
*/
completionTime: string;
};
/**
* The number of random bits generated in this request.
*/
bitsUsed: number;
/**
* An estimate of the number of remaining bits you can request.
*/
bitsLeft: number;
/**
* An estimate of the number of remaining api calls you can make.
*/
requestsLeft: number;
/**
* The recommended number of milliseconds you should wait before making another request.
*/
advisoryDelay: number;
}
export interface GenerateIntegersParams {
/**
* The number of random integers to generate (valid values: [1-10000]).
*/
n: number;
/**
* Lower bound for random integers (valid values: [-1e9 - 1e9] and `< max`).
*/
min: number;
/**
* Upper bound for random integers (valid values: [-1e9 - 1e9] and `> min`).
*/
max: number;
/**
* Whether or not the generated numbers can contain duplicates (default: true).
*/
replacement?: boolean;
/**
* The base of the generated numbers (default: 10; valid values: 2, 8, 10 or 16).
* If `base` is any value other than 10, the generated numbers will be returned as strings.
*/
base?: number;
}
export interface GenerateIntegerSequencesParams {
/**
* The number of random integer sequences to generate (valid values: [1-10000]).
*/
n: number;
/**
* The length of the sequences to generate (valid values: [1-10000]).
* Alternatively an array of `n` lengths if you need sequences of varying
* lengths (the sum of all lengths must be in the range: [1-10000]).
*/
length: number | number[];
/**
* Lower bound for random integers (valid values: [-1e9 - 1e9] and `< max`).
*/
min: number;
/**
* Upper bound for random integers (valid values: [-1e9 - 1e9] and `> min`).
*/
max: number;
/**
* Whether or not the generated numbers can contain duplicates (default: true).
*/
replacement?: boolean;
/**
* The base of the generated numbers (default: 10; valid values: 2, 8, 10 or 16).
* If `base` is any value other than 10, the generated numbers will be returned as strings.
*/
base?: number;
}
export interface GenerateDecimalFractionsParams {
/**
* The number of random reals to generate (valid values: [1-10000]).
*/
n: number;
/**
* The number of decimal places to use (valid values: [1-20]).
*/
decimalPlaces: number;
/**
* Whether or not the generated numbers can contain duplicates (default: true).
*/
replacement?: boolean;
}
export interface GenerateGaussiansParams {
/**
* The number of random numbers to generate (valid values: [1-10000]).
*/
n: number;
/**
* The mean of the distribution to pull numbers from (valid values: [-1e6 - 1e6]).
*/
mean: number;
/**
* Said distribution's standard deviation (valid values [-1e6 - 1e6]).
*/
standardDeviation: number;
/**
* The number of significant digits for your requested random numbers (valid values: [2-20]).
*/
significantDigits: number;
}
export interface GenerateStringsParams {
/**
* The number of random strings to generate (valid values: [1-10000]).
*/
n: number;
/**
* The length of each string you'd like generated.
*/
length: number;
/**
* The set of characters allowed to appear in the generated strings (maximum length: 80).
* Unicode characters are supported.
*/
characters: string;
/**
* Whether or not the generated numbers can contain duplicates (default: true).
*/
replacement?: boolean;
}
export interface GenerateUUIDsParams {
/**
* The number of UUIDs to generate (valid values: [1-1000]).
*/
n: number;
}
export interface GenerateBlobsParams {
/**
* The number of blobs you'd like (valid values: [1-100]).
*/
n: number;
/**
* The size of each blob, in bits (valid values: [1-1048576] and `size % 8 === 0`).
*/
size: number;
/**
* The format in which you'd like your blob (default: 'base64').
*/
format?: 'base64' | 'hex';
}
export type WithUserData<T> = T & {
userData?: Record<string, unknown>;
}
export interface SignedRandomOrgRPCResponse<Params, T> {
random: Params & {
/**
* The name of the method you called.
*/
method: string;
/**
* A base64-encoded SHA-512 hash of your api key.
* This allows you to provide this response to a third party without having to disclose your api key.
*/
hashedApiKey: string;
/**
* Your requested random numbers or strings.
*/
data: T;
/**
* The time that request was completed, in ISO 8601 format (parsable with new Date(isoString)).
*/
completionTime: string;
/**
* The serial number of this response (unique to your api key's requests).
*/
serialNumber: number;
/**
* Copied from the original request's `userData` parameter or `null` if not specified.
*/
userData: Record<string, unknown> | null;
/**
* An object describing the license terms under which the random data in this response can be used.
*/
license: Record<string, unknown>;
},
/**
* A base64-encoded signature of `response.random`, signed with Random.org's private key.
*/
signature: string;
/**
* The number of random bits generated in this request.
*/
bitsUsed: number;
/**
* An estimate of the number of remaining bits you can request.
*/
bitsLeft: number;
/**
* An estimate of the number of remaining api calls you can make.
*/
requestsLeft: number;
/**
* The recommended number of milliseconds you should wait before making another request.
*/
advisoryDelay: number;
}
export interface GetUsageResponse {
/**
* Your api key's current status. Either 'stopped', 'paused' or 'running'.
* In order request random bits, your api key must be 'running'.
*/
status: 'stopped' | 'paused' | 'running';
/**
* The timestamp at which your API key was created, in ISO 8601 format.
*/
creationTime: string;
/**
* An estimate of the number of remaining bits you can request.
*/
bitsLeft: number;
/**
* An estimate of the number of remaining api calls you can make.
*/
requestsLeft: number;
/**
* An integer containing the number of bits used by this API key since it was created.
*/
totalBits: number;
/**
* An integer containing the number of requests used by this API key since it was created.
*/
totalRequests: number;
}
interface VerifySignatureParams {
/**
* The original `response.random` object, received from one of the signed api calls.
*/
random: SignedRandomOrgRPCResponse<{}, unknown>['random'];
/**
* The corresponding `response.signature` string from the same request.
*/
signature: string;
}
interface VerifySignatureResponse {
/**
* True if the signed numbers were generated by Random.org, false if not.
*/
authenticity: boolean;
}
interface GetResultParams {
/**
* The serial number of the response you wish to fetch again.
*/
serialNumber: number;
}
export default class RandomOrg {
constructor(opts: ConstructorOptions);
// API Key usage
getUsage(): Promise<GetUsageResponse>;
// Basic methods
generateIntegers(params: GenerateIntegersParams): Promise<RandomOrgRPCResponse<number[]>>;
generateIntegerSequences(params: GenerateIntegerSequencesParams): Promise<RandomOrgRPCResponse<number[][]>>;
generateDecimalFractions(params: GenerateDecimalFractionsParams): Promise<RandomOrgRPCResponse<number[]>>;
generateGaussians(params: GenerateGaussiansParams): Promise<RandomOrgRPCResponse<number[]>>;
generateStrings(params: GenerateStringsParams): Promise<RandomOrgRPCResponse<string[]>>;
generateUUIDs(params: GenerateUUIDsParams): Promise<RandomOrgRPCResponse<string[]>>;
generateBlobs(params: GenerateBlobsParams): Promise<RandomOrgRPCResponse<string[]>>;
// Signed methods
generateSignedIntegers(params: WithUserData<GenerateIntegersParams>):
Promise<SignedRandomOrgRPCResponse<GenerateIntegersParams, number[]>>;
generateSignedIntegerSequences(params: WithUserData<GenerateIntegerSequencesParams>):
Promise<SignedRandomOrgRPCResponse<GenerateIntegerSequencesParams, number[][]>>;
generateSignedDecimalFractions(params: WithUserData<GenerateDecimalFractionsParams>):
Promise<SignedRandomOrgRPCResponse<GenerateDecimalFractionsParams, number[]>>;
generateSignedGaussians(params: WithUserData<GenerateGaussiansParams>):
Promise<SignedRandomOrgRPCResponse<GenerateGaussiansParams, number[]>>;
generateSignedStrings(params: WithUserData<GenerateStringsParams>):
Promise<SignedRandomOrgRPCResponse<GenerateStringsParams, string[]>>;
generateSignedUUIDs(params: WithUserData<GenerateUUIDsParams>):
Promise<SignedRandomOrgRPCResponse<GenerateUUIDsParams, string[]>>;
generateSignedBlobs(params: WithUserData<GenerateBlobsParams>):
Promise<SignedRandomOrgRPCResponse<GenerateBlobsParams, string[]>>;
verifySignature(params: VerifySignatureParams): Promise<VerifySignatureResponse>;
getResult<Params = {}, T = unknown>(params: GetResultParams): Promise<SignedRandomOrgRPCResponse<Params, T>>;
}