@leofcoin/codec-format-interface 1.7.4 → 1.7.6

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,5 +1,5 @@
1
- import BasicInterface from './basic-interface.js';
2
- import Hash from './codec-hash.js';
1
+ import BasicInterface from "./basic-interface.js";
2
+ import Hash from "./codec-hash.js";
3
3
  export default class FormatInterface extends BasicInterface implements FormatInterface {
4
4
  #private;
5
5
  hashFormat: string;
@@ -25,10 +25,10 @@ export default class FormatInterface extends BasicInterface implements FormatInt
25
25
  * @return {peernetHash}
26
26
  */
27
27
  hash(): Promise<any>;
28
- fromUint8Array(buffer: any): object;
29
- fromArrayBuffer(buffer: any): object;
28
+ fromUint8Array(buffer: any): void | object;
29
+ fromArrayBuffer(buffer: any): void | object;
30
30
  /**
31
31
  * @param {Object} data
32
32
  */
33
- create(data: object): Uint8Array;
33
+ create(data: object): void;
34
34
  }
@@ -13,13 +13,13 @@ class FormatInterface extends BasicInterface {
13
13
  hashFormat;
14
14
  #hash;
15
15
  init(buffer) {
16
- if (buffer instanceof Uint8Array)
16
+ if (buffer instanceof FormatInterface && buffer?.name === this.name)
17
+ return buffer;
18
+ else if (buffer instanceof Uint8Array)
17
19
  this.fromUint8Array(buffer);
18
20
  else if (buffer instanceof ArrayBuffer)
19
21
  this.fromArrayBuffer(buffer);
20
- else if (buffer instanceof FormatInterface && buffer?.name === this.name)
21
- return buffer;
22
- else if (typeof buffer === 'string') {
22
+ else if (typeof buffer === "string") {
23
23
  if (this.isHex(buffer))
24
24
  this.fromHex(buffer);
25
25
  else if (this.isBase58(buffer))
@@ -85,7 +85,7 @@ class FormatInterface extends BasicInterface {
85
85
  constructor(buffer, proto, options) {
86
86
  super();
87
87
  this.proto = proto;
88
- this.hashFormat = options?.hashFormat ? options.hashFormat : 'bs32';
88
+ this.hashFormat = options?.hashFormat ? options.hashFormat : "bs32";
89
89
  if (options?.name)
90
90
  this.name = options.name;
91
91
  this.init(buffer);
@@ -116,17 +116,22 @@ class FormatInterface extends BasicInterface {
116
116
  }
117
117
  fromUint8Array(buffer) {
118
118
  this.encoded = buffer;
119
- return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
119
+ return this.hasCodec()
120
+ ? this.decode()
121
+ : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
120
122
  }
121
123
  fromArrayBuffer(buffer) {
122
124
  this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
123
- return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
125
+ return this.hasCodec()
126
+ ? this.decode()
127
+ : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
124
128
  }
125
129
  /**
126
130
  * @param {Object} data
127
131
  */
128
132
  create(data) {
129
133
  const decoded = {};
134
+ // @ts-ignore
130
135
  if (data.hash)
131
136
  this.#hash = data.hash;
132
137
  if (this.keys?.length > 0) {
package/exports/codec.js CHANGED
@@ -75,6 +75,12 @@ class Codec extends BasicInterface {
75
75
  this.hashAlg = this.getHashAlg(this.name);
76
76
  this.codec = this.getCodec(this.name);
77
77
  this.codecBuffer = varint.encode(this.codec);
78
+ this.decoded = {
79
+ name: this.name,
80
+ hashAlg: this.hashAlg,
81
+ codec: this.codec,
82
+ codecBuffer: this.codecBuffer
83
+ };
78
84
  }
79
85
  fromName(name) {
80
86
  const codec = this.getCodec(name);
@@ -82,6 +88,12 @@ class Codec extends BasicInterface {
82
88
  this.codec = codec;
83
89
  this.hashAlg = this.getHashAlg(name);
84
90
  this.codecBuffer = varint.encode(this.codec);
91
+ this.decoded = {
92
+ name: this.name,
93
+ hashAlg: this.hashAlg,
94
+ codec: this.codec,
95
+ codecBuffer: this.codecBuffer
96
+ };
85
97
  }
86
98
  decode(encoded) {
87
99
  encoded = encoded || this.encoded;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/codec-format-interface",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {