@leofcoin/codec-format-interface 1.2.7 → 1.2.8

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/dist/index.js CHANGED
@@ -7,40 +7,24 @@ var bs58 = require('@vandeurenglenn/base58');
7
7
  var isHex = require('@vandeurenglenn/is-hex');
8
8
  var varint = require('varint');
9
9
  var createKeccakHash = require('keccak');
10
+ var protons = require('protons');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n["default"] = e;
28
- return Object.freeze(n);
29
- }
30
-
31
14
  var bs32__default = /*#__PURE__*/_interopDefaultLegacy(bs32);
32
15
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
33
16
  var isHex__default = /*#__PURE__*/_interopDefaultLegacy(isHex);
34
17
  var varint__default = /*#__PURE__*/_interopDefaultLegacy(varint);
35
18
  var createKeccakHash__default = /*#__PURE__*/_interopDefaultLegacy(createKeccakHash);
19
+ var protons__default = /*#__PURE__*/_interopDefaultLegacy(protons);
36
20
 
37
21
  class BasicInterface$1 {
38
- #handleDecode() {
22
+ handleDecode() {
39
23
  if (!this.decode) throw new Error('bad implementation: needs decode func')
40
24
  return this.decode()
41
25
  }
42
26
 
43
- #handleEncode() {
27
+ handleEncode() {
44
28
  if (!this.encode) throw new Error('bad implementation: needs encode func')
45
29
  return this.encode()
46
30
  }
@@ -58,7 +42,7 @@ class BasicInterface$1 {
58
42
  */
59
43
  fromBs32(encoded) {
60
44
  this.encoded = bs32__default["default"].decode(encoded);
61
- return this.#handleDecode()
45
+ return this.handleDecode()
62
46
  }
63
47
 
64
48
  /**
@@ -66,7 +50,7 @@ class BasicInterface$1 {
66
50
  */
67
51
  fromBs58(encoded) {
68
52
  this.encoded = bs58__default["default"].decode(encoded);
69
- return this.#handleDecode()
53
+ return this.handleDecode()
70
54
  }
71
55
 
72
56
  async toArray() {
@@ -79,12 +63,12 @@ class BasicInterface$1 {
79
63
 
80
64
  fromString(string) {
81
65
  this.encoded = new Uint8Array(string.split(','));
82
- return this.#handleDecode()
66
+ return this.handleDecode()
83
67
  }
84
68
 
85
69
  fromArray(array) {
86
70
  this.encoded = new Uint8Array([...array]);
87
- return this.#handleDecode()
71
+ return this.handleDecode()
88
72
  }
89
73
 
90
74
  /**
@@ -92,7 +76,7 @@ class BasicInterface$1 {
92
76
  */
93
77
  fromEncoded(encoded) {
94
78
  this.encoded = encoded;
95
- return this.#handleDecode()
79
+ return this.handleDecode()
96
80
  }
97
81
 
98
82
  /**
@@ -100,11 +84,11 @@ class BasicInterface$1 {
100
84
  */
101
85
  fromHex(encoded) {
102
86
  this.encoded = Buffer.from(encoded, 'hex');
103
- return this.#handleDecode()
87
+ return this.handleDecode()
104
88
  }
105
89
 
106
90
  async toString(encoding = 'utf8') {
107
- if (!this.encoded) await this.#handleEncode();
91
+ if (!this.encoded) await this.handleEncode();
108
92
  return this.encoded.toString(encoding)
109
93
  }
110
94
 
@@ -119,7 +103,7 @@ class BasicInterface$1 {
119
103
  * @return {String} encoded
120
104
  */
121
105
  async toBs32() {
122
- if (!this.encoded) await this.#handleEncode();
106
+ if (!this.encoded) await this.handleEncode();
123
107
  return bs32__default["default"].encode(this.encoded)
124
108
  }
125
109
 
@@ -127,7 +111,7 @@ class BasicInterface$1 {
127
111
  * @return {String} encoded
128
112
  */
129
113
  async toBs58() {
130
- if (!this.encoded) await this.#handleEncode();
114
+ if (!this.encoded) await this.handleEncode();
131
115
  return bs58__default["default"].encode(this.encoded)
132
116
  }
133
117
 
@@ -456,25 +440,17 @@ class CodecHash$1 extends BasicInterface$1 {
456
440
  }
457
441
  }
458
442
 
459
- let protons;
460
-
461
443
  class FormatInterface$1 extends BasicInterface$1 {
462
- async #importProtons() {
463
- let importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "protons" */ 'protons')); });
464
- return importee.default
465
- }
466
444
 
467
445
  async protoEncode(data) {
468
- if (!protons) protons = await this.#importProtons();
469
- return protons(this.proto)[this.messageName].encode(data)
446
+ return protons__default["default"](this.proto)[this.messageName].encode(data)
470
447
  }
471
448
 
472
449
  async protoDecode(data) {
473
- if (!protons) protons = await this.#importProtons();
474
- return protons(this.proto)[this.messageName].decode(data)
450
+ return protons__default["default"](this.proto)[this.messageName].decode(data)
475
451
  }
476
452
 
477
- async #init(buffer) {
453
+ async init(buffer) {
478
454
  if (buffer instanceof Uint8Array) await this.fromUint8Array(buffer);
479
455
  else if (buffer instanceof ArrayBuffer) await this.fromArrayBuffer(buffer);
480
456
  else if (buffer?.name === this.name) return buffer
@@ -499,7 +475,7 @@ class FormatInterface$1 extends BasicInterface$1 {
499
475
  this.proto = proto;
500
476
  this.hashFormat = options.hashFormat || 'bs32';
501
477
  if (options.name) this.name = options.name;
502
- return this.#init(buffer)
478
+ return this.init(buffer)
503
479
  }
504
480
 
505
481
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/codec-format-interface",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
@@ -3,12 +3,12 @@ import bs58 from '@vandeurenglenn/base58';
3
3
  import isHex from '@vandeurenglenn/is-hex';
4
4
 
5
5
  export default class BasicInterface {
6
- #handleDecode() {
6
+ handleDecode() {
7
7
  if (!this.decode) throw new Error('bad implementation: needs decode func')
8
8
  return this.decode()
9
9
  }
10
10
 
11
- #handleEncode() {
11
+ handleEncode() {
12
12
  if (!this.encode) throw new Error('bad implementation: needs encode func')
13
13
  return this.encode()
14
14
  }
@@ -26,7 +26,7 @@ export default class BasicInterface {
26
26
  */
27
27
  fromBs32(encoded) {
28
28
  this.encoded = bs32.decode(encoded)
29
- return this.#handleDecode()
29
+ return this.handleDecode()
30
30
  }
31
31
 
32
32
  /**
@@ -34,7 +34,7 @@ export default class BasicInterface {
34
34
  */
35
35
  fromBs58(encoded) {
36
36
  this.encoded = bs58.decode(encoded)
37
- return this.#handleDecode()
37
+ return this.handleDecode()
38
38
  }
39
39
 
40
40
  async toArray() {
@@ -47,12 +47,12 @@ export default class BasicInterface {
47
47
 
48
48
  fromString(string) {
49
49
  this.encoded = new Uint8Array(string.split(','))
50
- return this.#handleDecode()
50
+ return this.handleDecode()
51
51
  }
52
52
 
53
53
  fromArray(array) {
54
54
  this.encoded = new Uint8Array([...array])
55
- return this.#handleDecode()
55
+ return this.handleDecode()
56
56
  }
57
57
 
58
58
  /**
@@ -60,7 +60,7 @@ export default class BasicInterface {
60
60
  */
61
61
  fromEncoded(encoded) {
62
62
  this.encoded = encoded
63
- return this.#handleDecode()
63
+ return this.handleDecode()
64
64
  }
65
65
 
66
66
  /**
@@ -68,11 +68,11 @@ export default class BasicInterface {
68
68
  */
69
69
  fromHex(encoded) {
70
70
  this.encoded = Buffer.from(encoded, 'hex')
71
- return this.#handleDecode()
71
+ return this.handleDecode()
72
72
  }
73
73
 
74
74
  async toString(encoding = 'utf8') {
75
- if (!this.encoded) await this.#handleEncode()
75
+ if (!this.encoded) await this.handleEncode()
76
76
  return this.encoded.toString(encoding)
77
77
  }
78
78
 
@@ -87,7 +87,7 @@ export default class BasicInterface {
87
87
  * @return {String} encoded
88
88
  */
89
89
  async toBs32() {
90
- if (!this.encoded) await this.#handleEncode()
90
+ if (!this.encoded) await this.handleEncode()
91
91
  return bs32.encode(this.encoded)
92
92
  }
93
93
 
@@ -95,7 +95,7 @@ export default class BasicInterface {
95
95
  * @return {String} encoded
96
96
  */
97
97
  async toBs58() {
98
- if (!this.encoded) await this.#handleEncode()
98
+ if (!this.encoded) await this.handleEncode()
99
99
  return bs58.encode(this.encoded)
100
100
  }
101
101
 
@@ -1,25 +1,19 @@
1
1
  import BasicInterface from './basic-interface.js'
2
2
  import Codec from './codec.js';
3
3
  import Hash from './codec-hash.js'
4
- let protons
4
+ import protons from 'protons'
5
5
 
6
6
  export default class FormatInterface extends BasicInterface {
7
- async #importProtons() {
8
- let importee = await import(/* webpackChunkName: "protons" */ 'protons')
9
- return importee.default
10
- }
11
7
 
12
8
  async protoEncode(data) {
13
- if (!protons) protons = await this.#importProtons()
14
9
  return protons(this.proto)[this.messageName].encode(data)
15
10
  }
16
11
 
17
12
  async protoDecode(data) {
18
- if (!protons) protons = await this.#importProtons()
19
13
  return protons(this.proto)[this.messageName].decode(data)
20
14
  }
21
15
 
22
- async #init(buffer) {
16
+ async init(buffer) {
23
17
  if (buffer instanceof Uint8Array) await this.fromUint8Array(buffer)
24
18
  else if (buffer instanceof ArrayBuffer) await this.fromArrayBuffer(buffer)
25
19
  else if (buffer?.name === this.name) return buffer
@@ -44,7 +38,7 @@ export default class FormatInterface extends BasicInterface {
44
38
  this.proto = proto
45
39
  this.hashFormat = options.hashFormat || 'bs32'
46
40
  if (options.name) this.name = options.name
47
- return this.#init(buffer)
41
+ return this.init(buffer)
48
42
  }
49
43
 
50
44
  /**