@leofcoin/codec-format-interface 1.6.4 → 1.6.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.
package/dist/codec.d.ts CHANGED
@@ -3,7 +3,6 @@ export default class Codec extends BasicInterface {
3
3
  codecBuffer: Uint8Array;
4
4
  codec: number;
5
5
  hashAlg: string;
6
- get codecs(): any;
7
6
  constructor(buffer: string | number | object | Uint8Array | ArrayBuffer);
8
7
  fromEncoded(encoded: Uint8Array): object;
9
8
  getCodec(name: string): number;
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import basicInterface from './basic-interface.js';
2
2
  import formatInterface from './codec-format-interface.js';
3
3
  import codecHash from './codec-hash.js';
4
4
  import codec from './codec.js';
5
- export * as codecs from './codecs.js';
6
5
  export declare const BasicInterface: typeof basicInterface;
7
6
  export declare const FormatInterface: typeof formatInterface;
8
7
  export declare const CodecHash: typeof codecHash;
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import proto from '@vandeurenglenn/proto-array';
4
4
  import { fromBase58, fromHex, toHex, toBase32, toBase58 } from '@vandeurenglenn/typed-array-utils';
5
5
  import { createKeccak } from 'hash-wasm';
6
6
  import varint from 'varint';
7
+ import { utils } from '@leofcoin/codecs';
7
8
 
8
9
  /**
9
10
  * @param {string}
@@ -124,107 +125,10 @@ let BasicInterface$1 = class BasicInterface {
124
125
  }
125
126
  };
126
127
 
127
- var codecs = {
128
- // just a hash
129
- 'disco-hash': {
130
- codec: parseInt('30', 16),
131
- hashAlg: 'dbl-keccak-256', // ,
132
- // testnet: 'olivia'
133
- },
134
- 'peernet-peer-response': {
135
- codec: parseInt('707072', 16),
136
- hashAlg: 'keccak-256',
137
- },
138
- 'peernet-peer': {
139
- codec: parseInt('7070', 16),
140
- hashAlg: 'keccak-256',
141
- },
142
- 'peernet-dht': {
143
- codec: parseInt('706468', 16),
144
- hashAlg: 'keccak-256',
145
- },
146
- 'peernet-dht-response': {
147
- codec: parseInt('706472', 16),
148
- hashAlg: 'keccak-256',
149
- },
150
- // data
151
- 'peernet-data': {
152
- codec: parseInt('706461', 16),
153
- hashAlg: 'keccak-256',
154
- },
155
- 'peernet-data-response': {
156
- codec: parseInt('70646172', 16),
157
- hashAlg: 'keccak-256',
158
- },
159
- // message
160
- 'peernet-message': {
161
- codec: parseInt('706d65', 16),
162
- hashAlg: 'keccak-256',
163
- },
164
- // pubsub
165
- 'peernet-ps': {
166
- codec: parseInt('707073', 16),
167
- hashAlg: 'keccak-256',
168
- },
169
- 'peernet-response': {
170
- codec: parseInt('7072', 16),
171
- hashAlg: 'keccak-256',
172
- },
173
- 'peernet-request': {
174
- codec: parseInt('707271', 16),
175
- hashAlg: 'keccak-256',
176
- },
177
- // normal block
178
- 'leofcoin-block': {
179
- codec: parseInt('6c62', 16),
180
- hashAlg: 'dbl-keccak-512', // ,
181
- // testnet: 'olivia'
182
- },
183
- 'leofcoin-tx': {
184
- codec: parseInt('6c74', 16),
185
- hashAlg: 'dbl-keccak-512', // ,
186
- // testnet: 'olivia'
187
- },
188
- // itx
189
- 'leofcoin-itx': {
190
- codec: parseInt('6c69', 16),
191
- hashAlg: 'keccak-512', // ,
192
- // testnet: 'olivia'
193
- },
194
- // peer reputation
195
- 'leofcoin-pr': {
196
- codec: parseInt('6c70', 16),
197
- hashAlg: 'keccak-256', // ,
198
- // testnet: 'olivia'
199
- },
200
- // chat message
201
- 'chat-message': {
202
- codec: parseInt('70636d', 16),
203
- hashAlg: 'dbl-keccak-256',
204
- },
205
- 'peernet-file': {
206
- codec: parseInt('7066', 16),
207
- hashAlg: 'keccak-256',
208
- },
209
- 'peernet-file-response': {
210
- codec: parseInt('706672', 16),
211
- hashAlg: 'keccak-256',
212
- }
213
- };
214
-
215
- var codecs$1 = /*#__PURE__*/Object.freeze({
216
- __proto__: null,
217
- default: codecs
218
- });
219
-
220
128
  let Codec$1 = class Codec extends BasicInterface$1 {
221
129
  codecBuffer;
222
130
  codec;
223
131
  hashAlg;
224
- get codecs() {
225
- const globalCodecs = globalThis.peernet?.codecs || {};
226
- return { ...globalCodecs, ...codecs };
227
- }
228
132
  constructor(buffer) {
229
133
  super();
230
134
  if (buffer) {
@@ -252,7 +156,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
252
156
  }
253
157
  }
254
158
  else if (typeof buffer === 'string') {
255
- if (this.codecs[buffer])
159
+ if (utils.getCodec[buffer])
256
160
  this.fromName(buffer);
257
161
  else if (this.isHex(buffer))
258
162
  this.fromHex(buffer);
@@ -264,7 +168,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
264
168
  throw new Error(`unsupported string ${buffer}`);
265
169
  }
266
170
  if (!isNaN(buffer))
267
- if (this.codecs[this.getCodecName(buffer)])
171
+ if (utils.getCodec(buffer))
268
172
  this.fromCodec(buffer);
269
173
  }
270
174
  }
@@ -276,19 +180,13 @@ let Codec$1 = class Codec extends BasicInterface$1 {
276
180
  return this.decode(encoded);
277
181
  }
278
182
  getCodec(name) {
279
- return this.codecs[name].codec;
183
+ return utils.getCodec(name);
280
184
  }
281
185
  getCodecName(codec) {
282
- return Object.keys(this.codecs).reduce((p, c) => {
283
- const item = this.codecs[c];
284
- if (item.codec === codec)
285
- return c;
286
- else
287
- return p;
288
- }, undefined);
186
+ return utils.getCodecName(codec);
289
187
  }
290
188
  getHashAlg(name) {
291
- return this.codecs[name].hashAlg;
189
+ return utils.getHashAlg(name);
292
190
  }
293
191
  fromCodec(codec) {
294
192
  this.name = this.getCodecName(codec);
@@ -556,4 +454,4 @@ const FormatInterface = FormatInterface$1;
556
454
  const CodecHash = CodecHash$1;
557
455
  const Codec = Codec$1;
558
456
 
559
- export { BasicInterface, Codec, CodecHash, FormatInterface, codecs$1 as codecs };
457
+ export { BasicInterface, Codec, CodecHash, FormatInterface };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/codec-format-interface",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "typings": "dist/index.d.ts",
13
13
  "scripts": {
14
- "publish": "npm run build && npm version patch && npm publish",
14
+ "prepublish": "npm run build && npm version patch",
15
15
  "build": "rollup -c",
16
16
  "test": "node test"
17
17
  },
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/leofcoin/codec-format-interface#readme",
29
29
  "dependencies": {
30
+ "@leofcoin/codecs": "^1.0.0",
30
31
  "@vandeurenglenn/base32": "^1.1.0",
31
32
  "@vandeurenglenn/base58": "^1.1.1",
32
33
  "@vandeurenglenn/is-hex": "^1.0.0",