@leofcoin/codec-format-interface 1.7.6 → 1.7.7
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { base58String } from '@vandeurenglenn/base58';
|
|
2
|
+
import type { base32String } from '@vandeurenglenn/base32';
|
|
1
3
|
export default class BasicInterface {
|
|
2
4
|
#private;
|
|
3
|
-
keys: string[];
|
|
4
5
|
name: string;
|
|
6
|
+
get keys(): string[];
|
|
5
7
|
get encoded(): Uint8Array;
|
|
6
8
|
set encoded(value: Uint8Array);
|
|
7
9
|
get decoded(): object;
|
|
@@ -27,7 +29,7 @@ export default class BasicInterface {
|
|
|
27
29
|
/**
|
|
28
30
|
* @return {String} encoded
|
|
29
31
|
*/
|
|
30
|
-
toBs32():
|
|
32
|
+
toBs32(): base32String;
|
|
31
33
|
/**
|
|
32
34
|
* @return {String} encoded
|
|
33
35
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import base32 from '@vandeurenglenn/base32';
|
|
2
2
|
import base58 from '@vandeurenglenn/base58';
|
|
3
3
|
import isHex from '@vandeurenglenn/is-hex';
|
|
4
4
|
import proto from '@vandeurenglenn/proto-array';
|
|
@@ -7,9 +7,13 @@ import { fromBase58, fromHex, toHex, toBase32, toBase58 } from '@vandeurenglenn/
|
|
|
7
7
|
class BasicInterface {
|
|
8
8
|
#encoded;
|
|
9
9
|
#decoded;
|
|
10
|
-
keys;
|
|
11
10
|
name;
|
|
12
11
|
#proto;
|
|
12
|
+
get keys() {
|
|
13
|
+
// handles proto keys
|
|
14
|
+
// protokey -> key
|
|
15
|
+
return Object.keys(this.#proto).map((key) => (key.endsWith('?') ? key.split('?')[0] : key));
|
|
16
|
+
}
|
|
13
17
|
get encoded() {
|
|
14
18
|
if (!this.#encoded)
|
|
15
19
|
this.#encoded = this.encode();
|
|
@@ -28,7 +32,6 @@ class BasicInterface {
|
|
|
28
32
|
}
|
|
29
33
|
set proto(value) {
|
|
30
34
|
this.#proto = value;
|
|
31
|
-
this.keys = Object.keys(value);
|
|
32
35
|
}
|
|
33
36
|
get proto() {
|
|
34
37
|
return this.#proto;
|
|
@@ -54,13 +57,13 @@ class BasicInterface {
|
|
|
54
57
|
return isHex(string);
|
|
55
58
|
}
|
|
56
59
|
isBase32(string) {
|
|
57
|
-
return
|
|
60
|
+
return base32.isBase32(string);
|
|
58
61
|
}
|
|
59
62
|
isBase58(string) {
|
|
60
63
|
return base58.isBase58(string);
|
|
61
64
|
}
|
|
62
65
|
fromBs32(encoded) {
|
|
63
|
-
return this.decode(
|
|
66
|
+
return this.decode(base32.decode(encoded));
|
|
64
67
|
}
|
|
65
68
|
fromBs58(encoded) {
|
|
66
69
|
return this.decode(fromBase58(encoded));
|
|
@@ -74,7 +77,7 @@ class BasicInterface {
|
|
|
74
77
|
}
|
|
75
78
|
fromString(string) {
|
|
76
79
|
const array = string.split(',');
|
|
77
|
-
const arrayLike = array.map(string => Number(string));
|
|
80
|
+
const arrayLike = array.map((string) => Number(string));
|
|
78
81
|
return this.decode(Uint8Array.from(arrayLike));
|
|
79
82
|
}
|
|
80
83
|
fromHex(string) {
|
|
@@ -94,7 +97,10 @@ class BasicInterface {
|
|
|
94
97
|
toHex() {
|
|
95
98
|
if (!this.encoded)
|
|
96
99
|
this.encode();
|
|
97
|
-
return toHex(this.encoded
|
|
100
|
+
return toHex(this.encoded
|
|
101
|
+
.toString()
|
|
102
|
+
.split(',')
|
|
103
|
+
.map((number) => Number(number)));
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
100
106
|
* @return {String} encoded
|