@tchain/tcabci-read-js-client 2.5.11 → 2.6.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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TXType } from './transaction'
1
+ import { Transaction, TXType } from './transaction'
2
2
  import { SuccessCallback, ErrorCallback, CloseCallback, ListenCallback } from './callback'
3
3
 
4
4
  declare class TCaBCIClient {
@@ -36,8 +36,8 @@ declare class TCaBCIClient {
36
36
  LastBlock(
37
37
  chainName?: null,
38
38
  chainVersion?: null,
39
- ): { blocks: Record<string, any>; total_count: number }
40
- Tx(id: string, signature: string): Promise<{ tx: Record<string, any> }>
39
+ ): { blocks: Transaction[]; total_count: number }
40
+ Tx(id: string, signature: string): Promise<{ tx: Transaction }>
41
41
  TxSummary({
42
42
  recipientAddrs,
43
43
  senderAddrs,
@@ -50,9 +50,9 @@ declare class TCaBCIClient {
50
50
  chain_name: string
51
51
  chain_version: string
52
52
  first_block_height: number
53
- first_transaction: Record<string, any>
53
+ first_transaction: Transaction
54
54
  last_block_height: number
55
- last_transaction: Record<string, any>
55
+ last_transaction: Transaction
56
56
  total_count: number
57
57
  }>
58
58
  TxSearch({
@@ -72,12 +72,14 @@ declare class TCaBCIClient {
72
72
  orderBy,
73
73
  chainName,
74
74
  chainVersion,
75
- }): Promise<{ txs: Record<string, any>[]; total_count: number }>
75
+ }): Promise<{ txs: Transaction[]; total_count: number }>
76
76
  BroadcastCommit({
77
77
  id,
78
78
  version,
79
79
  type,
80
80
  data,
81
+ additional_data,
82
+ cipher_data,
81
83
  sender_addr,
82
84
  recipient_addr,
83
85
  sign,
@@ -88,6 +90,8 @@ declare class TCaBCIClient {
88
90
  version,
89
91
  type,
90
92
  data,
93
+ additional_data,
94
+ cipher_data,
91
95
  sender_addr,
92
96
  recipient_addr,
93
97
  sign,
@@ -98,6 +102,8 @@ declare class TCaBCIClient {
98
102
  version,
99
103
  type,
100
104
  data,
105
+ additional_data,
106
+ cipher_data,
101
107
  sender_addr,
102
108
  recipient_addr,
103
109
  sign,
package/client.js CHANGED
@@ -10,27 +10,21 @@ import {
10
10
  TRANSACTION_NOT_BROADCAST,
11
11
  TRANSACTION_TYPE_NOT_VALID,
12
12
  } from './errors.js'
13
- import {
14
- SUBSCRIBEMessage,
15
- UNSUBSCRIBEMessage,
16
- READ_NODE_ADDRESS,
17
- READ_NODE_WS_ADDRESS,
18
- } from './constants.js'
19
- import Message from './message.js'
20
- import { isJSON, fromJSON } from './util.js'
13
+ import { READ_NODE_ADDRESS, READ_NODE_WS_ADDRESS } from './constants.js'
14
+ import Message, { SUBSCRIBEMessage, UNSUBSCRIBEMessage } from './message.js'
21
15
  import { Options } from './websocketOptions.js'
22
16
  import { TWebSocket } from './websocket.js'
23
- import { TX_TYPE_LIST } from './transaction.js'
17
+ import { Transaction, TX_TYPE_LIST } from './transaction.js'
24
18
 
25
19
  /**
26
20
  * @callback SuccessCallback
27
- * @param {Event} event
21
+ * @param {Transaction} event
28
22
  * @return void
29
23
  */
30
24
 
31
25
  /**
32
26
  * @callback ErrorCallback
33
- * @param {Event} event
27
+ * @param {Error|Event|ErrorEvent} event
34
28
  * @return void
35
29
  */
36
30
 
@@ -53,7 +47,7 @@ export default class TCaBCIClient {
53
47
  _connected = false
54
48
  _chainName = 'transferchain'
55
49
  _chainVersion = 'v1'
56
- _version = `v2.5.11`
50
+ _version = `v2.6.2`
57
51
  /**
58
52
  * @type {?SuccessCallback}
59
53
  */
@@ -249,7 +243,7 @@ export default class TCaBCIClient {
249
243
  if (!this.IsConnected()) throw new Error(NOT_CONNECTED)
250
244
 
251
245
  const addrs = [],
252
- sdata = signedData ?? this.SubscribedSignedData
246
+ _signedData = signedData ?? this.SubscribedSignedData
253
247
 
254
248
  addrs.push(...addresses)
255
249
 
@@ -264,7 +258,13 @@ export default class TCaBCIClient {
264
258
  addrs.push(...newAddress)
265
259
  }
266
260
 
267
- const message = new Message(true, SUBSCRIBEMessage, addrs, sdata, txTypes)
261
+ const message = new Message(
262
+ true,
263
+ SUBSCRIBEMessage,
264
+ addrs,
265
+ _signedData,
266
+ txTypes,
267
+ )
268
268
 
269
269
  this._ws.send(message.ToJSON())
270
270
  this._setSubscribeAddresses(addrs, true)
@@ -294,7 +294,7 @@ export default class TCaBCIClient {
294
294
  /**
295
295
  * @param {?string} chainName
296
296
  * @param {?string} chainVersion
297
- * @return {Promise<{blocks: Object<string, *>, total_count: number}>}
297
+ * @return {Promise<{blocks: Transaction[], total_count: number}>}
298
298
  */
299
299
  LastBlock(chainName = null, chainVersion = null) {
300
300
  return this._httpClient(
@@ -304,7 +304,15 @@ export default class TCaBCIClient {
304
304
  },
305
305
  )
306
306
  .then((res) => {
307
- return { blocks: res.data, total_count: res.total_count }
307
+ const data = []
308
+
309
+ for (const _data of res.data) {
310
+ const { transaction, error } = Transaction.FromObject(_data)
311
+ if (error) return Promise.reject(error)
312
+ data.push(transaction)
313
+ }
314
+
315
+ return { blocks: data, total_count: res.total_count }
308
316
  })
309
317
  .catch((e) => this._handleRestError(e, new Error(BLOCK_NOT_FOUND)))
310
318
  }
@@ -324,7 +332,10 @@ export default class TCaBCIClient {
324
332
  headers: { 'X-Signature': signature },
325
333
  })
326
334
  .then((res) => {
327
- return { tx: res.data }
335
+ const { transaction, error } = Transaction.FromObject(res.data)
336
+ if (error) return Promise.reject(error)
337
+
338
+ return { tx: transaction }
328
339
  })
329
340
  .catch((e) => this._handleRestError(e))
330
341
  }
@@ -337,7 +348,15 @@ export default class TCaBCIClient {
337
348
  * @param {?Array<string>} types
338
349
  * @param {?string} chainName
339
350
  * @param {?string} chainVersion
340
- * @return {Promise<any>}
351
+ * @return {Promise<{
352
+ * chain_name: string,
353
+ * chain_version: string,
354
+ * first_block_height: number,
355
+ * first_transaction: Transaction,
356
+ * last_block_height: number,
357
+ * last_transaction: Transaction,
358
+ * total_count: number,
359
+ * }>}
341
360
  */
342
361
  TxSummary({
343
362
  recipientAddrs,
@@ -364,13 +383,22 @@ export default class TCaBCIClient {
364
383
  }),
365
384
  })
366
385
  .then((res) => {
386
+ const { transaction, error } = Transaction.FromObject(
387
+ res.data.first_transaction,
388
+ )
389
+ if (error) return Promise.reject(error)
390
+
391
+ const { transaction: lastTransaction, error: errorTwo } =
392
+ Transaction.FromObject(res.data.last_transaction)
393
+ if (errorTwo) return Promise.reject(errorTwo)
394
+
367
395
  return {
368
396
  chain_name: res.data.chain_name,
369
397
  chain_version: res.data.chain_version,
370
398
  first_block_height: res.data.first_block_height,
371
- first_transaction: res.data.first_transaction,
399
+ first_transaction: transaction,
372
400
  last_block_height: res.data.last_block_height,
373
- last_transaction: res.data.last_transaction,
401
+ last_transaction: lastTransaction,
374
402
  total_count: res.total_count,
375
403
  }
376
404
  })
@@ -394,7 +422,7 @@ export default class TCaBCIClient {
394
422
  * @param {string} orderBy
395
423
  * @param {?string} chainName
396
424
  * @param {?string} chainVersion
397
- * @return {Promise<any>}
425
+ * @return {Promise<{txs: Transaction[], total_count: number}>}
398
426
  */
399
427
  TxSearch({
400
428
  heightOperator,
@@ -434,8 +462,16 @@ export default class TCaBCIClient {
434
462
  }),
435
463
  })
436
464
  .then((res) => {
465
+ const data = []
466
+
467
+ for (const _data of res.data) {
468
+ const { transaction, error } = Transaction.FromObject(_data)
469
+ if (error) return Promise.reject(error)
470
+ data.push(transaction)
471
+ }
472
+
437
473
  return {
438
- txs: res.data,
474
+ txs: data,
439
475
  total_count: res.total_count,
440
476
  }
441
477
  })
@@ -484,6 +520,8 @@ export default class TCaBCIClient {
484
520
  * @param {number} version
485
521
  * @param {string} type
486
522
  * @param {string} data
523
+ * @param {?string} additional_data
524
+ * @param {?string} cipher_data
487
525
  * @param {string} sender_addr
488
526
  * @param {string} recipient_addr
489
527
  * @param {string} sign
@@ -495,6 +533,8 @@ export default class TCaBCIClient {
495
533
  version,
496
534
  type,
497
535
  data,
536
+ additional_data = null,
537
+ cipher_data = null,
498
538
  sender_addr,
499
539
  recipient_addr,
500
540
  sign,
@@ -506,6 +546,8 @@ export default class TCaBCIClient {
506
546
  version,
507
547
  type,
508
548
  data,
549
+ additional_data,
550
+ cipher_data,
509
551
  sender_addr,
510
552
  recipient_addr,
511
553
  sign,
@@ -521,6 +563,8 @@ export default class TCaBCIClient {
521
563
  * @param {number} version
522
564
  * @param {string} type
523
565
  * @param {string} data
566
+ * @param {?string} additional_data
567
+ * @param {?string} cipher_data
524
568
  * @param {string} sender_addr
525
569
  * @param {string} recipient_addr
526
570
  * @param {string} sign
@@ -532,6 +576,8 @@ export default class TCaBCIClient {
532
576
  version,
533
577
  type,
534
578
  data,
579
+ additional_data = null,
580
+ cipher_data = null,
535
581
  sender_addr,
536
582
  recipient_addr,
537
583
  sign,
@@ -543,6 +589,8 @@ export default class TCaBCIClient {
543
589
  version,
544
590
  type,
545
591
  data,
592
+ additional_data,
593
+ cipher_data,
546
594
  sender_addr,
547
595
  recipient_addr,
548
596
  sign,
@@ -554,7 +602,18 @@ export default class TCaBCIClient {
554
602
  }
555
603
 
556
604
  broadcast(
557
- { id, version, type, data, sender_addr, recipient_addr, sign, fee },
605
+ {
606
+ id,
607
+ version,
608
+ type,
609
+ data,
610
+ additional_data = null,
611
+ cipher_data = null,
612
+ sender_addr,
613
+ recipient_addr,
614
+ sign,
615
+ fee,
616
+ },
558
617
  sync = false,
559
618
  commit = false,
560
619
  ) {
@@ -571,6 +630,8 @@ export default class TCaBCIClient {
571
630
  version,
572
631
  type,
573
632
  data,
633
+ ...(additional_data ? { additional_data } : {}),
634
+ ...(cipher_data ? { cipher_data } : {}),
574
635
  sender_addr,
575
636
  recipient_addr,
576
637
  sign,
@@ -614,22 +675,6 @@ export default class TCaBCIClient {
614
675
  })
615
676
  }
616
677
 
617
- _callSuccessCallback(event) {
618
- if (this._successCb) this._successCb(event)
619
- }
620
-
621
- _callErrorCallback(event) {
622
- if (this._errorCb) this._errorCb(event)
623
- }
624
-
625
- _callCloseCallback(event) {
626
- if (this._closeCb) this._closeCb(event)
627
- }
628
-
629
- _callListenCallback(message) {
630
- if (this._listenCb) this._listenCb(message)
631
- }
632
-
633
678
  /**
634
679
  * @return {Promise<TWebSocket>}
635
680
  */
@@ -658,9 +703,7 @@ export default class TCaBCIClient {
658
703
  return { status: message.data }
659
704
  }
660
705
 
661
- this._callListenCallback(
662
- !isJSON(message.data) ? message.data : fromJSON(message.data),
663
- )
706
+ this._callListenCallback(message.data)
664
707
  })
665
708
 
666
709
  this._ws.addCloseListener((e) => {
@@ -723,15 +766,33 @@ export default class TCaBCIClient {
723
766
  return this
724
767
  }
725
768
 
769
+ _callSuccessCallback(event) {
770
+ if (this._successCb) this._successCb(event)
771
+ }
772
+
773
+ _callErrorCallback(event) {
774
+ if (this._errorCb) this._errorCb(event)
775
+ }
776
+
777
+ _callCloseCallback(event) {
778
+ if (this._closeCb) this._closeCb(event)
779
+ }
780
+
781
+ _callListenCallback(message) {
782
+ const { transaction, error } = Transaction.FromJSON(message)
783
+ if (error) this._callErrorCallback(error)
784
+ else if (this._listenCb) this._listenCb(transaction)
785
+ }
786
+
726
787
  /**
727
788
  * @param {string} uri
728
789
  * @param {RequestInit} req
729
- * @return {Promise<any>}
790
+ * @return {Promise<Record<string, any>>}
730
791
  */
731
792
  _httpClient(uri, req) {
732
793
  req.cache = 'no-cache'
733
794
  req.headers = {
734
- Client: `tcabaci-read-js-client-${this._version}`,
795
+ Client: `tcabaci-read-js-client/${this._version}`,
735
796
  }
736
797
  req.priority = 'high'
737
798
 
package/constants.js CHANGED
@@ -1,5 +1,2 @@
1
- export const SUBSCRIBEMessage = 'subscribe',
2
- UNSUBSCRIBEMessage = 'unsubscribe',
3
- CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
4
- READ_NODE_ADDRESS = 'https://read-node-01.transferchain.io',
1
+ export const READ_NODE_ADDRESS = 'https://read-node-01.transferchain.io',
5
2
  READ_NODE_WS_ADDRESS = 'wss://read-node-01.transferchain.io/ws'
package/message.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { INVALID_ARGUMENTS, INVALID_ARGUMENT_WITH_CS } from './errors.js'
2
- import { SUBSCRIBEMessage, UNSUBSCRIBEMessage } from './constants.js'
3
2
  import { TX_TYPE_LIST } from './transaction.js'
4
3
 
4
+ export const SUBSCRIBEMessage = 'subscribe',
5
+ UNSUBSCRIBEMessage = 'unsubscribe'
6
+
5
7
  export default class Message {
6
8
  _is_web = false
7
9
  _type = ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tchain/tcabci-read-js-client",
3
- "version": "2.5.11",
3
+ "version": "2.6.2",
4
4
  "description": "TransferChain Fastest Read Network WebSocket Client",
5
5
  "main": "client.js",
6
6
  "type": "module",
@@ -26,20 +26,20 @@
26
26
  },
27
27
  "homepage": "https://github.com/TransferChain/tcabci-read-js-client#readme",
28
28
  "devDependencies": {
29
- "@eslint/js": "^9.39.1",
29
+ "@eslint/js": "^9.39.2",
30
30
  "@types/chai": "^5.2.3",
31
- "chai": "^6.2.1",
32
- "eslint": "^9.39.1",
31
+ "chai": "^6.2.2",
32
+ "eslint": "^9.39.2",
33
33
  "eslint-config-prettier": "^10.1.8",
34
- "eslint-plugin-prettier": "^5.5.4",
34
+ "eslint-plugin-prettier": "^5.5.5",
35
35
  "esm": "^3.2.25",
36
36
  "express": "^5.2.1",
37
37
  "globals": "^16.5.0",
38
38
  "mocha": "^11.7.5",
39
39
  "nyc": "^17.1.0",
40
- "prettier": "^3.7.4",
40
+ "prettier": "^3.8.1",
41
41
  "unit.js": "^2.1.1",
42
- "ws": "^8.18.3"
42
+ "ws": "^8.19.0"
43
43
  },
44
44
  "dependencies": {
45
45
  "reconnecting-websocket": "^4.4.0"
package/transaction.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type TXType = string;
1
+ export declare type TXType = string
2
2
 
3
3
  export declare const TX_TYPE_MASTER: TXType,
4
4
  TX_TYPE_ADDRESS: TXType,
@@ -50,34 +50,43 @@ export declare const TX_TYPE_MASTER: TXType,
50
50
  TX_TYPE_PASSWD_DATAV2: TXType,
51
51
  TX_TYPE_PASSWD_DATAV2_POLICY: TXType,
52
52
  TX_TYPE_COLLECTION: TXType,
53
- TX_TYPE_COLLECTION_POLICY: TXType;
53
+ TX_TYPE_COLLECTION_POLICY: TXType
54
54
 
55
- export declare const TX_TYPE_LIST: TXType[];
55
+ export declare const TX_TYPE_LIST: TXType[]
56
56
 
57
57
  export declare class Transaction {
58
- constructor(
59
- id: string,
60
- height: number,
61
- version: number,
62
- typ: TXType,
63
- sender_addr: string,
64
- recipient_addr: string,
65
- data: string,
66
- sign: string,
67
- fee: number,
68
- hash: string,
69
- inserted_at: Date,
70
- )
71
- get ID(): string;
72
- get Height(): number;
73
- get Version(): number;
74
- get Typ(): TXType;
75
- get SenderAddr(): string;
76
- get RecipientAddr(): string;
77
- get Data(): string;
78
- get Sign(): string;
79
- get Fee(): number;
80
- get Hash(): string;
81
- get InsertedAt(): Date;
82
- ToJSON(): string;
58
+ constructor({
59
+ id,
60
+ height,
61
+ version,
62
+ typ,
63
+ sender_addr,
64
+ recipient_addr,
65
+ data,
66
+ sign,
67
+ fee,
68
+ hash,
69
+ inserted_at,
70
+ additionalData,
71
+ cipherData,
72
+ }?: Record<string, any>)
73
+ get ID(): string
74
+ get Height(): number
75
+ get Version(): number
76
+ get Typ(): TXType
77
+ get SenderAddr(): string
78
+ get RecipientAddr(): string
79
+ get Data(): string
80
+ get AdditionalData(): string
81
+ get CipherData(): string
82
+ get Sign(): string
83
+ get Fee(): number
84
+ get Hash(): string
85
+ get InsertedAt(): Date
86
+ static FromJSON(value: string): { transaction?: Transaction; error?: Error }
87
+ static FromObject(obj: Record<string, any>): {
88
+ transaction?: Transaction
89
+ error?: Error
90
+ }
91
+ ToJSON(): string
83
92
  }
package/transaction.js CHANGED
@@ -106,13 +106,17 @@ export const TX_TYPE_MASTER = 'initial_storage',
106
106
  ]
107
107
 
108
108
  export class Transaction {
109
+ _order
109
110
  _id
111
+ _identifier
110
112
  _height
111
113
  _version
112
114
  _typ
113
115
  _sender_addr
114
116
  _recipient_addr
115
117
  _data
118
+ _additionalData
119
+ _cipherData
116
120
  _sign
117
121
  _fee
118
122
  _hash
@@ -130,9 +134,11 @@ export class Transaction {
130
134
  * @param {number} fee
131
135
  * @param {string} hash
132
136
  * @param {Date} inserted_at
137
+ * @param {?string} additionalData
138
+ * @param {?string} cipherData
133
139
  * @throws Error
134
140
  */
135
- constructor(
141
+ constructor({
136
142
  id,
137
143
  height,
138
144
  version,
@@ -144,7 +150,9 @@ export class Transaction {
144
150
  fee,
145
151
  hash,
146
152
  inserted_at,
147
- ) {
153
+ additionalData = null,
154
+ cipherData = null,
155
+ } = {}) {
148
156
  this._id = id
149
157
  this._height = height
150
158
  this._version = version
@@ -156,8 +164,8 @@ export class Transaction {
156
164
  this._fee = fee
157
165
  this._hash = hash
158
166
  this._inserted_at = inserted_at
159
-
160
- this._validate()
167
+ if (additionalData) this._additionalData = additionalData
168
+ if (cipherData) this._cipherData = cipherData
161
169
  }
162
170
 
163
171
  get ID() {
@@ -188,6 +196,14 @@ export class Transaction {
188
196
  return this._data
189
197
  }
190
198
 
199
+ get AdditionalData() {
200
+ return this._additionalData
201
+ }
202
+
203
+ get CipherData() {
204
+ return this._cipherData
205
+ }
206
+
191
207
  get Sign() {
192
208
  return this._sign
193
209
  }
@@ -204,6 +220,57 @@ export class Transaction {
204
220
  return this._inserted_at
205
221
  }
206
222
 
223
+ static FromJSON(value) {
224
+ try {
225
+ const parsed = JSON.parse(value),
226
+ tx = new Transaction()
227
+
228
+ if (parsed.order) tx._order = parsed.order
229
+ tx._id = parsed.id
230
+ if (parsed.identifier) tx._identifier = parsed.identifier
231
+ tx._height = parsed.height
232
+ tx._version = parsed.version
233
+ tx._sender_addr = parsed.sender_addr
234
+ tx._recipient_addr = parsed.recipient_addr
235
+ tx._data = parsed.data
236
+ if (parsed.additional_data) tx._additionalData = parsed.additional_data
237
+ if (parsed.cipher_data) tx._cipherData = parsed.cipher_data
238
+ tx._sign = parsed.sign
239
+ tx._fee = parsed.fee
240
+ tx._hash = parsed.hash
241
+ tx._inserted_at = new Date(parsed.inserted_at)
242
+
243
+ return { transaction: tx, error: null }
244
+ } catch (e) {
245
+ return { transaction: null, error: e }
246
+ }
247
+ }
248
+
249
+ static FromObject(obj) {
250
+ try {
251
+ const tx = new Transaction()
252
+
253
+ if (obj.order) tx._order = obj.order
254
+ tx._id = obj.id
255
+ if (obj.identifier) tx._identifier = obj.identifier
256
+ tx._height = obj.height
257
+ tx._version = obj.version
258
+ tx._sender_addr = obj.sender_addr
259
+ tx._recipient_addr = obj.recipient_addr
260
+ tx._data = obj.data
261
+ if (obj.additional_data) tx._additionalData = obj.additional_data
262
+ if (obj.cipher_data) tx._cipherData = obj.cipher_data
263
+ tx._sign = obj.sign
264
+ tx._fee = obj.fee
265
+ tx._hash = obj.hash
266
+ tx._inserted_at = new Date(obj.inserted_at)
267
+
268
+ return { transaction: tx, error: null }
269
+ } catch (e) {
270
+ return { transaction: null, error: e }
271
+ }
272
+ }
273
+
207
274
  /**
208
275
  * @return {string}
209
276
  * @throws Error
@@ -223,11 +290,15 @@ export class Transaction {
223
290
  fee: this._fee,
224
291
  hash: this._hash,
225
292
  inserted_at: this._inserted_at.toISOString(),
293
+ ...(this._additionalData
294
+ ? { additional_data: this._additionalData }
295
+ : {}),
296
+ ...(this._cipherData ? { cipher_data: this._cipherData } : {}),
226
297
  })
227
298
  }
228
299
 
229
- _validate() {
230
- if (typeof this._id !== 'number')
300
+ Validate() {
301
+ if (typeof this._id === 'undefined')
231
302
  throw new Error(INVALID_ARGUMENT_WITH_CS('id'))
232
303
  if (typeof this._height !== 'number')
233
304
  throw new Error(INVALID_ARGUMENT_WITH_CS('height'))
@@ -241,8 +312,18 @@ export class Transaction {
241
312
  throw new Error(INVALID_ARGUMENT_WITH_CS('senderAddr'))
242
313
  if (typeof this._recipient_addr !== 'string')
243
314
  throw new Error(INVALID_ARGUMENT_WITH_CS('recipientAddr'))
244
- if (typeof this._data !== 'object')
315
+ if (typeof this._data !== 'string')
245
316
  throw new Error(INVALID_ARGUMENT_WITH_CS('data'))
317
+ if (
318
+ typeof this._additionalData !== 'undefined' &&
319
+ typeof this._additionalData !== 'string'
320
+ )
321
+ throw new Error(INVALID_ARGUMENT_WITH_CS('additionalData'))
322
+ if (
323
+ typeof this._cipherData !== 'undefined' &&
324
+ typeof this._cipherData !== 'string'
325
+ )
326
+ throw new Error(INVALID_ARGUMENT_WITH_CS('cipherData'))
246
327
  if (typeof this._sign !== 'object')
247
328
  throw new Error(INVALID_ARGUMENT_WITH_CS('sign'))
248
329
  if (typeof this._fee !== 'number')
package/websocket.js CHANGED
@@ -26,6 +26,8 @@ export class TWebSocket {
26
26
  _errorCallbacks = []
27
27
  _closeCallbacks = []
28
28
 
29
+ _connectionErrorCount = 0
30
+
29
31
  /**
30
32
  * @param {Options} options
31
33
  * @constructor
@@ -251,6 +253,8 @@ export class TWebSocket {
251
253
  }
252
254
 
253
255
  _make() {
256
+ if (this._connectionErrorCount > 15) return
257
+
254
258
  this._client = new ReconnectingWebSocket(
255
259
  this._options.url,
256
260
  this._options.protocols,
@@ -258,6 +262,7 @@ export class TWebSocket {
258
262
  )
259
263
 
260
264
  this._openListener = (e) => {
265
+ this._connectionErrorCount = 0
261
266
  this._onOpen(e)
262
267
  }
263
268
  this._client.addEventListener('open', this._openListener)
@@ -274,6 +279,15 @@ export class TWebSocket {
274
279
 
275
280
  this._errorListener = (e) => {
276
281
  this._onError(e)
282
+ if (this._connectionErrorCount > 15) {
283
+ this._onError(new Error('Internet connectivity problem!'))
284
+ this._disconnect().catch((err) => {
285
+ this._onError(err)
286
+ })
287
+
288
+ return
289
+ }
290
+ this._connectionErrorCount++
277
291
  }
278
292
  this._client.addEventListener('error', this._errorListener)
279
293
  }
@@ -308,6 +322,7 @@ export class TWebSocket {
308
322
  this._messageListener = () => {}
309
323
 
310
324
  this._client.close(code)
325
+ this._connectionErrorCount = 0
311
326
  }
312
327
 
313
328
  /**
@@ -319,7 +334,7 @@ export class TWebSocket {
319
334
  }
320
335
 
321
336
  /**
322
- * @param {ErrorEvent} event
337
+ * @param {Error|Event|ErrorEvent} event
323
338
  * @private
324
339
  */
325
340
  _onError(event) {
@@ -13,7 +13,7 @@ export class Options {
13
13
  _protocols = []
14
14
  _customWS
15
15
  _endpoints = ['ws', 'longpoll']
16
- _version = `v2.5.11`
16
+ _version = `v2.6.2`
17
17
 
18
18
  _maxConnectionDelay = 10000
19
19
  _minReconnectionDelay = 1000 + Math.random() * 4000