@leofcoin/codec-format-interface 1.2.5 → 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 +32 -50
- package/package.json +1 -1
- package/src/basic-interface.js +11 -11
- package/src/codec-format-interface.js +3 -9
- package/src/codecs.js +2 -2
- package/src/index.js +11 -5
- /package/test/{test.js → index.js} +0 -0
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
|
-
class BasicInterface {
|
|
38
|
-
|
|
21
|
+
class BasicInterface$1 {
|
|
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
|
-
|
|
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 {
|
|
|
58
42
|
*/
|
|
59
43
|
fromBs32(encoded) {
|
|
60
44
|
this.encoded = bs32__default["default"].decode(encoded);
|
|
61
|
-
return this
|
|
45
|
+
return this.handleDecode()
|
|
62
46
|
}
|
|
63
47
|
|
|
64
48
|
/**
|
|
@@ -66,7 +50,7 @@ class BasicInterface {
|
|
|
66
50
|
*/
|
|
67
51
|
fromBs58(encoded) {
|
|
68
52
|
this.encoded = bs58__default["default"].decode(encoded);
|
|
69
|
-
return this
|
|
53
|
+
return this.handleDecode()
|
|
70
54
|
}
|
|
71
55
|
|
|
72
56
|
async toArray() {
|
|
@@ -79,12 +63,12 @@ class BasicInterface {
|
|
|
79
63
|
|
|
80
64
|
fromString(string) {
|
|
81
65
|
this.encoded = new Uint8Array(string.split(','));
|
|
82
|
-
return this
|
|
66
|
+
return this.handleDecode()
|
|
83
67
|
}
|
|
84
68
|
|
|
85
69
|
fromArray(array) {
|
|
86
70
|
this.encoded = new Uint8Array([...array]);
|
|
87
|
-
return this
|
|
71
|
+
return this.handleDecode()
|
|
88
72
|
}
|
|
89
73
|
|
|
90
74
|
/**
|
|
@@ -92,7 +76,7 @@ class BasicInterface {
|
|
|
92
76
|
*/
|
|
93
77
|
fromEncoded(encoded) {
|
|
94
78
|
this.encoded = encoded;
|
|
95
|
-
return this
|
|
79
|
+
return this.handleDecode()
|
|
96
80
|
}
|
|
97
81
|
|
|
98
82
|
/**
|
|
@@ -100,11 +84,11 @@ class BasicInterface {
|
|
|
100
84
|
*/
|
|
101
85
|
fromHex(encoded) {
|
|
102
86
|
this.encoded = Buffer.from(encoded, 'hex');
|
|
103
|
-
return this
|
|
87
|
+
return this.handleDecode()
|
|
104
88
|
}
|
|
105
89
|
|
|
106
90
|
async toString(encoding = 'utf8') {
|
|
107
|
-
if (!this.encoded) await this
|
|
91
|
+
if (!this.encoded) await this.handleEncode();
|
|
108
92
|
return this.encoded.toString(encoding)
|
|
109
93
|
}
|
|
110
94
|
|
|
@@ -119,7 +103,7 @@ class BasicInterface {
|
|
|
119
103
|
* @return {String} encoded
|
|
120
104
|
*/
|
|
121
105
|
async toBs32() {
|
|
122
|
-
if (!this.encoded) await this
|
|
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 {
|
|
|
127
111
|
* @return {String} encoded
|
|
128
112
|
*/
|
|
129
113
|
async toBs58() {
|
|
130
|
-
if (!this.encoded) await this
|
|
114
|
+
if (!this.encoded) await this.handleEncode();
|
|
131
115
|
return bs58__default["default"].encode(this.encoded)
|
|
132
116
|
}
|
|
133
117
|
|
|
@@ -232,17 +216,17 @@ var codecs = {
|
|
|
232
216
|
codec: parseInt('636d', 16),
|
|
233
217
|
hashAlg: 'dbl-keccak-256',
|
|
234
218
|
},
|
|
235
|
-
'peernet-
|
|
219
|
+
'peernet-file' : {
|
|
236
220
|
codec: parseInt('7066', 16),
|
|
237
221
|
hashAlg: 'keccak-256',
|
|
238
222
|
},
|
|
239
|
-
'peernet-
|
|
223
|
+
'peernet-file-response' : {
|
|
240
224
|
codec: parseInt('706672', 16),
|
|
241
225
|
hashAlg: 'keccak-256',
|
|
242
226
|
}
|
|
243
227
|
};
|
|
244
228
|
|
|
245
|
-
class PeernetCodec extends BasicInterface {
|
|
229
|
+
class PeernetCodec extends BasicInterface$1 {
|
|
246
230
|
get codecs() {
|
|
247
231
|
return {...globalThis.peernet.codecs, ...codecs}
|
|
248
232
|
}
|
|
@@ -333,7 +317,7 @@ class PeernetCodec extends BasicInterface {
|
|
|
333
317
|
}
|
|
334
318
|
}
|
|
335
319
|
|
|
336
|
-
class CodecHash extends BasicInterface {
|
|
320
|
+
class CodecHash$1 extends BasicInterface$1 {
|
|
337
321
|
constructor(buffer, options = {}) {
|
|
338
322
|
super();
|
|
339
323
|
if (options.name) this.name = options.name;
|
|
@@ -456,25 +440,17 @@ class CodecHash extends BasicInterface {
|
|
|
456
440
|
}
|
|
457
441
|
}
|
|
458
442
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
class FormatInterface extends BasicInterface {
|
|
462
|
-
async #importProtons() {
|
|
463
|
-
let importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "protons" */ 'protons')); });
|
|
464
|
-
return importee.default
|
|
465
|
-
}
|
|
443
|
+
class FormatInterface$1 extends BasicInterface$1 {
|
|
466
444
|
|
|
467
445
|
async protoEncode(data) {
|
|
468
|
-
|
|
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
|
-
|
|
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
|
|
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,14 +475,14 @@ class FormatInterface extends BasicInterface {
|
|
|
499
475
|
this.proto = proto;
|
|
500
476
|
this.hashFormat = options.hashFormat || 'bs32';
|
|
501
477
|
if (options.name) this.name = options.name;
|
|
502
|
-
return this
|
|
478
|
+
return this.init(buffer)
|
|
503
479
|
}
|
|
504
480
|
|
|
505
481
|
/**
|
|
506
482
|
* @return {PeernetHash}
|
|
507
483
|
*/
|
|
508
484
|
get peernetHash() {
|
|
509
|
-
return new CodecHash(this.decoded, {name: this.name})
|
|
485
|
+
return new CodecHash$1(this.decoded, {name: this.name})
|
|
510
486
|
}
|
|
511
487
|
|
|
512
488
|
/**
|
|
@@ -565,8 +541,14 @@ class FormatInterface extends BasicInterface {
|
|
|
565
541
|
}
|
|
566
542
|
}
|
|
567
543
|
|
|
544
|
+
const BasicInterface = BasicInterface$1;
|
|
545
|
+
const FormatInterface = FormatInterface$1;
|
|
546
|
+
const CodecHash = CodecHash$1;
|
|
547
|
+
const Codec = PeernetCodec;
|
|
548
|
+
const Codecs = codecs;
|
|
549
|
+
|
|
568
550
|
exports.BasicInterface = BasicInterface;
|
|
569
|
-
exports.Codec =
|
|
551
|
+
exports.Codec = Codec;
|
|
570
552
|
exports.CodecHash = CodecHash;
|
|
553
|
+
exports.Codecs = Codecs;
|
|
571
554
|
exports.FormatInterface = FormatInterface;
|
|
572
|
-
exports.codecs = codecs;
|
package/package.json
CHANGED
package/src/basic-interface.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
50
|
+
return this.handleDecode()
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
fromArray(array) {
|
|
54
54
|
this.encoded = new Uint8Array([...array])
|
|
55
|
-
return this
|
|
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
|
|
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
|
|
71
|
+
return this.handleDecode()
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async toString(encoding = 'utf8') {
|
|
75
|
-
if (!this.encoded) await this
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
41
|
+
return this.init(buffer)
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
/**
|
package/src/codecs.js
CHANGED
|
@@ -76,11 +76,11 @@ export default {
|
|
|
76
76
|
codec: parseInt('636d', 16),
|
|
77
77
|
hashAlg: 'dbl-keccak-256',
|
|
78
78
|
},
|
|
79
|
-
'peernet-
|
|
79
|
+
'peernet-file' : {
|
|
80
80
|
codec: parseInt('7066', 16),
|
|
81
81
|
hashAlg: 'keccak-256',
|
|
82
82
|
},
|
|
83
|
-
'peernet-
|
|
83
|
+
'peernet-file-response' : {
|
|
84
84
|
codec: parseInt('706672', 16),
|
|
85
85
|
hashAlg: 'keccak-256',
|
|
86
86
|
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import basicInterface from './basic-interface.js'
|
|
2
|
+
import formatInterface from './codec-format-interface.js'
|
|
3
|
+
import codecHash from './codec-hash.js'
|
|
4
|
+
import codec from './codec.js'
|
|
5
|
+
import codecs from './codecs.js'
|
|
6
|
+
|
|
7
|
+
export const BasicInterface = basicInterface
|
|
8
|
+
export const FormatInterface = formatInterface
|
|
9
|
+
export const CodecHash = codecHash
|
|
10
|
+
export const Codec = codec
|
|
11
|
+
export const Codecs = codecs
|
|
File without changes
|