@leofcoin/codec-format-interface 1.6.10 → 1.6.12

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.
@@ -30,8 +30,4 @@ export default class BasicInterface {
30
30
  * @return {String} encoded
31
31
  */
32
32
  toBs58(): base58String;
33
- /**
34
- * @param {Object} data
35
- */
36
- create(data: object): Uint8Array;
37
33
  }
@@ -25,4 +25,8 @@ export default class FormatInterface extends BasicInterface implements FormatInt
25
25
  hash(): Promise<any>;
26
26
  fromUint8Array(buffer: any): object;
27
27
  fromArrayBuffer(buffer: any): object;
28
+ /**
29
+ * @param {Object} data
30
+ */
31
+ create(data: object): Uint8Array;
28
32
  }
package/dist/index.js CHANGED
@@ -104,26 +104,6 @@ let BasicInterface$1 = class BasicInterface {
104
104
  this.encode();
105
105
  return toBase58(this.encoded);
106
106
  }
107
- /**
108
- * @param {Object} data
109
- */
110
- create(data) {
111
- const decoded = {};
112
- if (this.keys?.length > 0) {
113
- for (const key of this.keys) {
114
- Object.defineProperties(decoded, {
115
- [key]: {
116
- enumerable: true,
117
- configurable: true,
118
- set: (value) => data[key],
119
- get: () => data[key]
120
- }
121
- });
122
- }
123
- this.decoded = decoded;
124
- return this.encode(decoded);
125
- }
126
- }
127
107
  };
128
108
 
129
109
  let Codec$1 = class Codec extends BasicInterface$1 {
@@ -142,7 +122,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
142
122
  this.decode(buffer);
143
123
  }
144
124
  else {
145
- this.encode(buffer);
125
+ this.encode(Number(new TextDecoder().decode(buffer)));
146
126
  }
147
127
  }
148
128
  else if (buffer instanceof ArrayBuffer) {
@@ -153,7 +133,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
153
133
  this.decode(buffer);
154
134
  }
155
135
  else {
156
- this.encode(buffer);
136
+ this.encode(Number(new TextDecoder().decode(new Uint8Array(buffer))));
157
137
  }
158
138
  }
159
139
  else if (typeof buffer === 'string') {
@@ -166,7 +146,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
166
146
  else if (this.isBase58(buffer))
167
147
  this.fromBs58(buffer);
168
148
  else
169
- throw new Error(`unsupported string ${buffer}`);
149
+ this.fromString(buffer);
170
150
  }
171
151
  if (!isNaN(buffer))
172
152
  if (utils.getCodec(buffer))
@@ -193,14 +173,14 @@ let Codec$1 = class Codec extends BasicInterface$1 {
193
173
  this.name = this.getCodecName(codec);
194
174
  this.hashAlg = this.getHashAlg(this.name);
195
175
  this.codec = this.getCodec(this.name);
196
- this.codecBuffer = varint.encode(codec);
176
+ this.codecBuffer = varint.encode(this.codec);
197
177
  }
198
178
  fromName(name) {
199
179
  const codec = this.getCodec(name);
200
180
  this.name = name;
201
181
  this.codec = codec;
202
182
  this.hashAlg = this.getHashAlg(name);
203
- this.codecBuffer = varint.encode(codec);
183
+ this.codecBuffer = varint.encode(this.codec);
204
184
  }
205
185
  decode(encoded) {
206
186
  encoded = encoded || this.encoded;
@@ -354,7 +334,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
354
334
  this.fromArrayBuffer(buffer);
355
335
  else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
356
336
  return buffer;
357
- else if (buffer instanceof String) {
337
+ else if (typeof buffer === 'string') {
358
338
  if (this.isHex(buffer))
359
339
  this.fromHex(buffer);
360
340
  else if (this.isBase58(buffer))
@@ -362,7 +342,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
362
342
  else if (this.isBase32(buffer))
363
343
  this.fromBs32(buffer);
364
344
  else
365
- throw new Error(`unsupported ${buffer}`);
345
+ this.fromString(buffer);
366
346
  }
367
347
  else {
368
348
  this.create(buffer);
@@ -448,6 +428,26 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
448
428
  this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
449
429
  return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
450
430
  }
431
+ /**
432
+ * @param {Object} data
433
+ */
434
+ create(data) {
435
+ const decoded = {};
436
+ if (this.keys?.length > 0) {
437
+ for (const key of this.keys) {
438
+ Object.defineProperties(decoded, {
439
+ [key]: {
440
+ enumerable: true,
441
+ configurable: true,
442
+ set: (value) => data[key],
443
+ get: () => data[key]
444
+ }
445
+ });
446
+ }
447
+ this.decoded = decoded;
448
+ return this.encode(decoded);
449
+ }
450
+ }
451
451
  };
452
452
 
453
453
  const BasicInterface = BasicInterface$1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/codec-format-interface",
3
- "version": "1.6.10",
3
+ "version": "1.6.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {