@leofcoin/codec-format-interface 1.6.5 → 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 +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +7 -109
- package/package.json +1 -1
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('0x30', 16),
|
|
131
|
-
hashAlg: 'dbl-keccak-256', // ,
|
|
132
|
-
// testnet: 'olivia'
|
|
133
|
-
},
|
|
134
|
-
'peernet-peer-response': {
|
|
135
|
-
codec: parseInt('0x707072', 16),
|
|
136
|
-
hashAlg: 'keccak-256',
|
|
137
|
-
},
|
|
138
|
-
'peernet-peer': {
|
|
139
|
-
codec: parseInt('0x7070', 16),
|
|
140
|
-
hashAlg: 'keccak-256',
|
|
141
|
-
},
|
|
142
|
-
'peernet-dht': {
|
|
143
|
-
codec: parseInt('0x706468', 16),
|
|
144
|
-
hashAlg: 'keccak-256',
|
|
145
|
-
},
|
|
146
|
-
'peernet-dht-response': {
|
|
147
|
-
codec: parseInt('0x706472', 16),
|
|
148
|
-
hashAlg: 'keccak-256',
|
|
149
|
-
},
|
|
150
|
-
// data
|
|
151
|
-
'peernet-data': {
|
|
152
|
-
codec: parseInt('0x706461', 16),
|
|
153
|
-
hashAlg: 'keccak-256',
|
|
154
|
-
},
|
|
155
|
-
'peernet-data-response': {
|
|
156
|
-
codec: parseInt('0x70646172', 16),
|
|
157
|
-
hashAlg: 'keccak-256',
|
|
158
|
-
},
|
|
159
|
-
// message
|
|
160
|
-
'peernet-message': {
|
|
161
|
-
codec: parseInt('0x706d65', 16),
|
|
162
|
-
hashAlg: 'keccak-256',
|
|
163
|
-
},
|
|
164
|
-
// pubsub
|
|
165
|
-
'peernet-ps': {
|
|
166
|
-
codec: parseInt('0x707073', 16),
|
|
167
|
-
hashAlg: 'keccak-256',
|
|
168
|
-
},
|
|
169
|
-
'peernet-response': {
|
|
170
|
-
codec: parseInt('0x7072', 16),
|
|
171
|
-
hashAlg: 'keccak-256',
|
|
172
|
-
},
|
|
173
|
-
'peernet-request': {
|
|
174
|
-
codec: parseInt('0x707271', 16),
|
|
175
|
-
hashAlg: 'keccak-256',
|
|
176
|
-
},
|
|
177
|
-
// normal block
|
|
178
|
-
'leofcoin-block': {
|
|
179
|
-
codec: parseInt('0x6c62', 16),
|
|
180
|
-
hashAlg: 'dbl-keccak-512', // ,
|
|
181
|
-
// testnet: 'olivia'
|
|
182
|
-
},
|
|
183
|
-
'leofcoin-tx': {
|
|
184
|
-
codec: parseInt('0x6c74', 16),
|
|
185
|
-
hashAlg: 'dbl-keccak-512', // ,
|
|
186
|
-
// testnet: 'olivia'
|
|
187
|
-
},
|
|
188
|
-
// itx
|
|
189
|
-
'leofcoin-itx': {
|
|
190
|
-
codec: parseInt('0x6c69', 16),
|
|
191
|
-
hashAlg: 'keccak-512', // ,
|
|
192
|
-
// testnet: 'olivia'
|
|
193
|
-
},
|
|
194
|
-
// peer reputation
|
|
195
|
-
'leofcoin-pr': {
|
|
196
|
-
codec: parseInt('0x6c70', 16),
|
|
197
|
-
hashAlg: 'keccak-256', // ,
|
|
198
|
-
// testnet: 'olivia'
|
|
199
|
-
},
|
|
200
|
-
// chat message
|
|
201
|
-
'chat-message': {
|
|
202
|
-
codec: parseInt('0x70636d', 16),
|
|
203
|
-
hashAlg: 'dbl-keccak-256',
|
|
204
|
-
},
|
|
205
|
-
'peernet-file': {
|
|
206
|
-
codec: parseInt('0x7066', 16),
|
|
207
|
-
hashAlg: 'keccak-256',
|
|
208
|
-
},
|
|
209
|
-
'peernet-file-response': {
|
|
210
|
-
codec: parseInt('0x706672', 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 (
|
|
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 (
|
|
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
|
|
183
|
+
return utils.getCodec(name);
|
|
280
184
|
}
|
|
281
185
|
getCodecName(codec) {
|
|
282
|
-
return
|
|
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
|
|
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
|
|
457
|
+
export { BasicInterface, Codec, CodecHash, FormatInterface };
|