@leofcoin/codec-format-interface 1.7.3 → 1.7.4
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,9 +1,11 @@
|
|
|
1
1
|
export default class BasicInterface {
|
|
2
2
|
#private;
|
|
3
|
-
encoded: Uint8Array;
|
|
4
|
-
decoded: object;
|
|
5
3
|
keys: string[];
|
|
6
4
|
name: string;
|
|
5
|
+
get encoded(): Uint8Array;
|
|
6
|
+
set encoded(value: Uint8Array);
|
|
7
|
+
get decoded(): object;
|
|
8
|
+
set decoded(value: object);
|
|
7
9
|
set proto(value: object);
|
|
8
10
|
get proto(): object;
|
|
9
11
|
decode(encoded?: Uint8Array): Object;
|
|
@@ -5,11 +5,27 @@ import proto from '@vandeurenglenn/proto-array';
|
|
|
5
5
|
import { fromBase58, fromHex, toHex, toBase32, toBase58 } from '@vandeurenglenn/typed-array-utils';
|
|
6
6
|
|
|
7
7
|
class BasicInterface {
|
|
8
|
-
encoded;
|
|
9
|
-
decoded;
|
|
8
|
+
#encoded;
|
|
9
|
+
#decoded;
|
|
10
10
|
keys;
|
|
11
11
|
name;
|
|
12
12
|
#proto;
|
|
13
|
+
get encoded() {
|
|
14
|
+
if (!this.#encoded)
|
|
15
|
+
this.#encoded = this.encode();
|
|
16
|
+
return this.#encoded;
|
|
17
|
+
}
|
|
18
|
+
set encoded(value) {
|
|
19
|
+
this.#encoded = value;
|
|
20
|
+
}
|
|
21
|
+
get decoded() {
|
|
22
|
+
if (!this.#decoded)
|
|
23
|
+
this.#decoded = this.decode();
|
|
24
|
+
return this.#decoded;
|
|
25
|
+
}
|
|
26
|
+
set decoded(value) {
|
|
27
|
+
this.#decoded = value;
|
|
28
|
+
}
|
|
13
29
|
set proto(value) {
|
|
14
30
|
this.#proto = value;
|
|
15
31
|
this.keys = Object.keys(value);
|
package/exports/codec-hash.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export default class CodecHash extends BasicInterface {
|
|
|
9
9
|
get buffer(): Uint8Array;
|
|
10
10
|
get hash(): Uint8Array;
|
|
11
11
|
fromJSON(json: any): Promise<Uint8Array>;
|
|
12
|
-
encode(buffer: any, name
|
|
12
|
+
encode(buffer: any, name?: any): Promise<Uint8Array>;
|
|
13
13
|
validate(buffer: any): Promise<void>;
|
|
14
14
|
decode(buffer: any): {
|
|
15
15
|
codec: any;
|
package/exports/codec-hash.js
CHANGED
|
@@ -66,14 +66,14 @@ class CodecHash extends BasicInterface {
|
|
|
66
66
|
return this.encoded;
|
|
67
67
|
}
|
|
68
68
|
fromJSON(json) {
|
|
69
|
-
return this.encode(
|
|
69
|
+
return this.encode(new TextEncoder().encode(JSON.stringify(json)));
|
|
70
70
|
}
|
|
71
71
|
async encode(buffer, name) {
|
|
72
72
|
if (!this.name && name)
|
|
73
73
|
this.name = name;
|
|
74
74
|
if (!buffer)
|
|
75
75
|
buffer = this.buffer;
|
|
76
|
-
this.discoCodec = new Codec(this.name
|
|
76
|
+
this.discoCodec = new Codec(this.name);
|
|
77
77
|
this.discoCodec.fromName(this.name);
|
|
78
78
|
let hashAlg = this.discoCodec.hashAlg;
|
|
79
79
|
const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import BasicInterface from './basic-interface.js';
|
|
2
|
+
import Hash from './codec-hash.js';
|
|
3
|
+
export default class JsonInterface extends BasicInterface implements JsonInterface {
|
|
4
|
+
#private;
|
|
5
|
+
hashFormat: string;
|
|
6
|
+
init(buffer: Uint8Array | ArrayBuffer | JsonInterface | string): JsonInterface;
|
|
7
|
+
hasCodec(): boolean;
|
|
8
|
+
decode(encoded?: string): object;
|
|
9
|
+
encode(decoded?: object): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
|
|
12
|
+
* @param {Object} proto - {protoObject}
|
|
13
|
+
* @param {Object} options - {hashFormat, name}
|
|
14
|
+
*/
|
|
15
|
+
constructor(buffer: any, proto: any, options?: {
|
|
16
|
+
hashFormat?: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
});
|
|
19
|
+
get format(): string;
|
|
20
|
+
/**
|
|
21
|
+
* @return {PeernetHash}
|
|
22
|
+
*/
|
|
23
|
+
get peernetHash(): Hash;
|
|
24
|
+
/**
|
|
25
|
+
* @return {peernetHash}
|
|
26
|
+
*/
|
|
27
|
+
hash(): Promise<any>;
|
|
28
|
+
fromUint8Array(buffer: any): object;
|
|
29
|
+
fromArrayBuffer(buffer: any): object;
|
|
30
|
+
/**
|
|
31
|
+
* @param {Object} data
|
|
32
|
+
*/
|
|
33
|
+
create(data: object): Uint8Array;
|
|
34
|
+
}
|