-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.d.ts
576 lines (417 loc) · 15.4 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
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
import {Decimal} from 'decimal.js'
export as namespace nkn
export = nkn
declare namespace nkn {
export class MultiClient {
addr: string
identifier: string
isClosed: boolean
isReady: boolean
defaultClient: Client
constructor(options?: MultiClientOptions)
close(): Promise<void>
deleteName(name: string, options?: TransactionOptions): Promise<TxnOrHash>
dial(remoteAddr: string, options?: DialOptions): Promise<Session>
getBalance(address?: string): Promise<Amount>
getLatestBlock(): Promise<{
height: number
hash: string
}>
getNonce(address?: string, options?: { txPool: boolean }): Promise<number>
getPublicKey(): string
getRegistrant(name: string): Promise<{
registrant: string
expiresAt: number
}>
getSeed(): string
getSubscribers(topic: string, options?: {
offset?: number
limit?: number
meta?: boolean
txPool?: boolean
}): Promise<{
subscribers: Array<string> | Record<string, string>
subscribersInTxPool?: Array<string> | Record<string, string>
}>
getSubscribersCount(topic: string): Promise<number>
getSubscription(topic: string, subscriber: string): Promise<{
meta: string
expiresAt: number
}>
listen(addrs: (RegExp | Array<RegExp> | string | Array<string> | null | void)): void
onConnect(f: ConnectHandler): void
onConnectFailed(f: ConnectFailedHandler): void
onMessage(func: MessageHandler): void
onSession(func: SessionHandler): void
publish(topic: string, data: MessageData, options?: PublishOptions): Promise<null>
readyClientIDs(): Array<string>
registerName(name: string, options?: TransactionOptions): Promise<TxnOrHash>
send(dest: Destination, data: MessageData, options?: SendOptions): Promise<ReplyData>
sendTransaction(txn: Transaction): Promise<string>
sendWithClient(clientID: string, dest: Destination, data: Uint8Array, options?: SendOptions): Promise<ReplyData>
subscribe(topic: string, duration: number, identifier?: string, meta?: string, options?: TransactionOptions): Promise<TxnOrHash>
transferName(name: string, recipient: string, options?: TransactionOptions): Promise<TxnOrHash>
transferTo(toAddress: string, amount: (number | string | Amount), options?: TransactionOptions): Promise<TxnOrHash>
unsubscribe(topic: string, identifier: string, options?: TransactionOptions): Promise<TxnOrHash>
}
export class Client {
addr: string
identifier: string
constructor(options?: ClientOptions)
close(): void
deleteName(name: string, options?: TransactionOptions): Promise<TxnOrHash>
getBalance(address?: string): Promise<Amount>
getLatestBlock(): Promise<{ height: number, hash: string }>
getNonce(address?: string, options?: {
txPool: boolean
}): Promise<number>
getPublicKey(): string
getRegistrant(name: string): Promise<{
registrant: string
expiresAt: number
}>
getSeed(): string
getSubscribers(topic: string, options?: {
offset?: number
limit?: number
meta?: boolean
txPool?: boolean
}): Promise<{
subscribers: Array<string> | Record<string, string>
subscribersInTxPool?: Array<string> | Record<string, string>
}>
getSubscribersCount(topic: string): Promise<number>
getSubscription(topic: string, subscriber: string): Promise<{
meta: string
expiresAt: number
}>
onConnect(func: ConnectHandler): void
onConnectFailed(f: ConnectFailedHandler): void
onMessage(func: MessageHandler): void
publish(topic: string, data: MessageData, options?: PublishOptions): Promise<null>
registerName(name: string, options?: TransactionOptions): Promise<TxnOrHash>
send(dest: Destination, data: MessageData, options?: SendOptions): Promise<ReplyData>
sendTransaction(txn: Transaction): Promise<string>
subscribe(topic: string, duration: number, identifier?: string, meta?: string, options?: TransactionOptions): Promise<TxnOrHash>
transferName(name: string, recipient: string, options?: TransactionOptions): Promise<TxnOrHash>
transferTo(toAddress: string, amount: (number | string | Amount), options?: TransactionOptions): Promise<TxnOrHash>
unsubscribe(topic: string, identifier: string, options?: TransactionOptions): Promise<TxnOrHash>
}
export class Wallet {
address: string
version: number
constructor(options?: {
seed?: string
password?: string
rpcServerAddr?: string
iv?: string
masterKey?: string
scrypt?: ScryptParams
worker?: boolean | (() => Worker | Promise<Worker>)
passwordKey?: Record<string, string>
version?: number
})
createOrUpdateNanoPay(
toAddress: string,
amount: (number | string | Amount),
expiration: number,
id: number,
options?: TransactionOptions,
): Promise<Transaction>
deleteName(name: string, options?: TransactionOptions): Promise<TxnOrHash>
static fromJSON(walletJson: (string | WalletJson), options?: {
password: string
rpcServerAddr?: string
async?: boolean
}): (Wallet | Promise<Wallet>)
static getBalance(address: string, options?: {
rpcServerAddr: string
}): Promise<Amount>
getBalance(address?: string): Promise<Amount>
static getLatestBlock(options?: {
rpcServerAddr: string
}): Promise<{
height: number
hash: string
}>
getLatestBlock(): Promise<{
height: number
hash: string
}>
static getNonce(address: string, options?: {
rpcServerAddr: string
txPool: boolean
}): Promise<number>
getNonce(address?: string, options?: { txPool: boolean }): Promise<number>
getPublicKey(): string
static getRegistrant(name: string, options?: {
rpcServerAddr: string
}): Promise<{
registrant: string
expiresAt: number
}>
getRegistrant(name: string): Promise<{
registrant: string
expiresAt: number
}>
getSeed(): string
static getSubscribers(topic: string, options?: {
offset?: number
limit?: number
meta?: boolean
txPool?: boolean
rpcServerAddr?: string
}): Promise<{
subscribers: Array<string> | Record<string, string>
subscribersInTxPool?: Array<string> | Record<string, string>
}>
getSubscribers(topic: string, options?: {
offset?: number
limit?: number
meta?: boolean
txPool?: boolean
}): Promise<{
subscribers: Array<string> | Record<string, string>
subscribersInTxPool?: Array<string> | Record<string, string>
}>
static getSubscribersCount(topic: string, options?: {
rpcServerAddr: string
}): Promise<number>
getSubscribersCount(topic: string): Promise<number>
static getSubscription(topic: string, subscriber: string, options?: {
rpcServerAddr: string
}): Promise<{
meta: string
expiresAt: number
}>
getSubscription(topic: string, subscriber: string): Promise<{
meta: string
expiresAt: number
}>
static publicKeyToAddress(publicKey: string): string
registerName(name: string, options?: TransactionOptions): Promise<TxnOrHash>
static sendTransaction(txn: Transaction, options?: {
rpcServerAddr: string
}): Promise<string>
sendTransaction(txn: Transaction): Promise<string>
subscribe(topic: string, duration: number, identifier: string, meta: string, options?: TransactionOptions): Promise<TxnOrHash>
toJSON(): WalletJson
transferName(name: string, recipient: string, options?: TransactionOptions): Promise<TxnOrHash>
transferTo(toAddress: string, amount: (number | string | Amount), options?: TransactionOptions): Promise<TxnOrHash>
unsubscribe(topic: string, identifier: string, options?: TransactionOptions): Promise<TxnOrHash>
static verifyAddress(addr: string): boolean
verifyPassword(password: string, options?: {
async: boolean
}): boolean | Promise<boolean>
}
export class Amount extends Decimal {
}
export class Key {
seed: string
publicKey: string
privateKey: Uint8Array
curvePrivateKey: Uint8Array
useWorker: boolean
worker: Worker | null
workerMsgID: number
constructor(seed: string, options?: {
worker?: boolean | (() => Worker | Promise<Worker>)
})
computeSharedKey(otherPubkey: string): Promise<string>
getOrComputeSharedKey(otherPubkey: string): Promise<string>
encrypt(message: string, destPubkey: string, options?: {
nonce?: Uint8Array
}): Promise<{
message: Uint8Array
nonce: Uint8Array
}>
decrypt(message: Uint8Array, nonce: Uint8Array, srcPubkey: string, options?: {}): Promise<string>
sign(message: string): string
}
export type ConnectHandler = (params: {addr: string}) => void
export type ConnectFailedHandler = () => void
export type CreateTransactionOptions = {
fee: number | string | Amount | null | void
attrs: string | null | undefined
buildOnly: boolean | null | undefined
}
export type Destination = string | Array<string>
type DialOptions = {
dialTimeout?: number
sessionConfig?: SessionConfig
}
export type Message = {
src: string
payload: MessageData
payloadType: PayloadType
isEncrypted: boolean
messageId: Uint8Array
noReply: boolean
}
export type MessageData = Uint8Array | string
export type MessageHandler = (message: Message) => ReplyData | false | void | Promise<ReplyData | false | void>
export type PublishOptions = {
encrypt?: boolean
msgHoldingSeconds?: number
messageId?: Uint8Array
replyToId?: Uint8Array
txPool?: boolean
offset?: number
limit?: number
}
export type ReplyData = MessageData | null
export type SendOptions = {
responseTimeout?: number
encrypt?: boolean
msgHoldingSeconds?: number
noReply?: boolean
messageId?: Uint8Array
replyToId?: Uint8Array
}
export type SessionHandler = (session: Session) => void
export type TransactionOptions = CreateTransactionOptions & {
nonce?: number
}
export type TxnOrHash = string | Transaction
// eslint-disable-next-line import/no-anonymous-default-export
interface ClientOptions {
identifier?: string
reconnectIntervalMin?: number
reconnectIntervalMax?: number
responseTimeout?: number
msgHoldingSeconds?: number
encrypt?: boolean
rpcServerAddr?: string
tls?: boolean
worker?: boolean | (() => Worker | Promise<Worker>)
}
interface MultiClientOptions extends ClientOptions {
seed?: string
numSubClients?: number
originalClient?: boolean
msgCacheExpiration?: number
sessionConfig?: SessionConfig
}
enum PayloadType {
BINARY = 0,
TEXT = 1,
ACK = 2,
SESSION = 3,
}
type Session = Object // TODO: import from NCP types
type SessionConfig = Object // TODO: import from NCP types
type Transaction = Object // TODO
export type ScryptParams = {
salt: string,
N: number,
r: number,
p: number,
};
type WalletJson = {
Version: number
MasterKey: string
IV: string
SeedEncrypted: string
Address: string
Scrypt?: ScryptParams
}
export namespace aes {
export function encrypt(plaintext: string, password: string, iv: string): string
export function decrypt(ciphertext: string, password: string, iv: string): string
}
export namespace crypto {
export const keyLength: number
export const nonceLength: number
export const publicKeyLength: number
export const seedLength: number
export const signatureLength: number
export function keyPair(seed: string): KeyPair
export function ed25519SkToCurve25519(sk: Uint8Array): Uint8Array
export function ed25519PkToCurve25519(pk: string): Promise<Uint8Array>
export function computeSharedKey(myCurvePrivateKey: Uint8Array, otherPubkey: string): Promise<string>
export function encryptSymmetric(message: Uint8Array, nonce: Uint8Array, key: Uint8Array): Promise<Uint8Array>
export function decryptSymmetric(message: Uint8Array, nonce: Uint8Array, key: Uint8Array): Promise<Uint8Array | null>
export function sign(privateKey: Uint8Array, message: string): Promise<string>
type KeyPair = {
seed: string
publicKey: string
privateKey: Uint8Array
curvePrivateKey: Uint8Array
}
}
export namespace errors {
const rpcRespErrCodes: Object
const AddrNotAllowedError: ErrorConstructor
const ClientNotReadyError: ErrorConstructor
const DataSizeTooLargeError: ErrorConstructor
const DecryptionError: ErrorConstructor
const UnknownError: ErrorConstructor
const NotEnoughBalanceError: ErrorConstructor
const WrongPasswordError: ErrorConstructor
const InvalidAddressError: ErrorConstructor
const InvalidWalletFormatError: ErrorConstructor
const InvalidWalletVersionError: ErrorConstructor
const InvalidArgumentError: ErrorConstructor
const InvalidResponseError: ErrorConstructor
const ServerError: ErrorConstructor
const InvalidDestinationError: ErrorConstructor
const RpcTimeoutError: ErrorConstructor
const RpcError: ErrorConstructor
}
export namespace hash {
export function cryptoHexStringParse(hexString: string): string
export function sha256(str: string): string
export function sha256Hex(hexStr: string): string
export function doubleSha256(str: string): string
export function doubleSha256Hex(hexStr: string): string
export function ripemd160(str: string): string
export function ripemd160Hex(hexStr: string): string
}
export namespace serialize {
export const maxUintBits: number
export const maxUint: number
export function encodeUint8(value: number): string
export function encodeUint16(value: number): string
export function encodeUint32(value: number): string
export function encodeUint64(value: number): string
export function encodeUint(value: number): string
export function encodeBytes(value: number): string
export function encodeString(value: number): string
export function encodeBool(value: number): string
}
export namespace util {
import TypedArray = NodeJS.TypedArray
export function hexToBytes(hex: string): Uint8Array
export function bytesToHex(bytes: Uint8Array): string
export function randomBytes(n: number): Uint8Array
export function setPRNG(fn: (x: Uint8Array, n: number) => void): void
export function randomBytesHex(len: number): string
export function randomInt32(): number
export function randomUint64(): number
export function mergeTypedArrays(a: TypedArray, b: TypedArray): TypedArray
export function assignDefined(target: Object, ...sources: Object[]): void
export function utf8ToBytes(s: string): Uint8Array
export function toLowerKeys(obj: Object): Object
}
export function setPRNG(fn: (x: Uint8Array, n: number) => void): void
}
declare interface nkn {
MultiClient: nkn.MultiClient
Client: nkn.Client
Wallet: nkn.Wallet
Amount: nkn.Amount
ConnectHandler: nkn.ConnectHandler
ConnectFailedHandler: nkn.ConnectFailedHandler
CreateTransactionOptions: nkn.CreateTransactionOptions
Destination: nkn.Destination
DialOptions: nkn.DialOptions
Message: nkn.Message
MessageData: nkn.MessageData
MessageHandler: nkn.MessageHandler
PublishOptions: nkn.PublishOptions
ReplyData: nkn.ReplyData
SendOptions: nkn.SendOptions
SessionHandler: nkn.SessionHandler
TransactionOptions: nkn.TransactionOptions
TxnOrHash: nkn.TxnOrHash
}