@leofcoin/codec-format-interface 1.7.12 → 1.7.13
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,7 @@
|
|
|
1
1
|
import type { base58String } from '@vandeurenglenn/base58';
|
|
2
2
|
import type { base32String } from '@vandeurenglenn/base32';
|
|
3
|
+
export declare const jsonStringifyBigInt: (key: any, value: any) => any;
|
|
4
|
+
export declare const jsonParseBigInt: (key: any, value: any) => any;
|
|
3
5
|
export default class BasicInterface {
|
|
4
6
|
#private;
|
|
5
7
|
name: string;
|
|
@@ -4,6 +4,8 @@ import isHex from '@vandeurenglenn/is-hex';
|
|
|
4
4
|
import proto from '@vandeurenglenn/proto-array';
|
|
5
5
|
import { fromBase58, fromHex, toHex, toBase32, toBase58 } from '@vandeurenglenn/typed-array-utils';
|
|
6
6
|
|
|
7
|
+
const jsonStringifyBigInt = (key, value) => typeof value === 'bigint' ? { $bigint: value.toString() } : value;
|
|
8
|
+
const jsonParseBigInt = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
|
|
7
9
|
class BasicInterface {
|
|
8
10
|
#encoded;
|
|
9
11
|
#decoded;
|
|
@@ -120,4 +122,4 @@ class BasicInterface {
|
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
export { BasicInterface as default };
|
|
125
|
+
export { BasicInterface as default, jsonParseBigInt, jsonStringifyBigInt };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BasicInterface from './basic-interface.js';
|
|
1
|
+
import BasicInterface, { jsonParseBigInt } from './basic-interface.js';
|
|
2
2
|
import Codec from './codec.js';
|
|
3
3
|
import CodecHash from './codec-hash.js';
|
|
4
4
|
import '@vandeurenglenn/base32';
|
|
@@ -128,13 +128,13 @@ class FormatInterface extends BasicInterface {
|
|
|
128
128
|
this.encoded = buffer;
|
|
129
129
|
return this.hasCodec()
|
|
130
130
|
? this.decode()
|
|
131
|
-
: this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
|
|
131
|
+
: this.create(JSON.parse(new TextDecoder().decode(this.encoded), jsonParseBigInt));
|
|
132
132
|
}
|
|
133
133
|
fromArrayBuffer(buffer) {
|
|
134
134
|
this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
|
|
135
135
|
return this.hasCodec()
|
|
136
136
|
? this.decode()
|
|
137
|
-
: this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
|
|
137
|
+
: this.create(JSON.parse(new TextDecoder().decode(this.encoded), jsonParseBigInt));
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* @param {Object} data
|
package/exports/codec-hash.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import BasicInterface from './basic-interface.js';
|
|
2
|
+
import Codec from './codec.js';
|
|
3
|
+
type CodecHashOptions = {
|
|
4
|
+
name: string;
|
|
5
|
+
codecs: object;
|
|
6
|
+
};
|
|
2
7
|
export default class CodecHash extends BasicInterface {
|
|
3
|
-
codec:
|
|
4
|
-
discoCodec:
|
|
5
|
-
|
|
8
|
+
codec: Uint8Array;
|
|
9
|
+
discoCodec: Codec;
|
|
10
|
+
size: number;
|
|
11
|
+
constructor(buffer: any, options: CodecHashOptions);
|
|
6
12
|
init(uint8Array: any): Promise<this>;
|
|
7
13
|
get prefix(): Uint8Array;
|
|
8
14
|
get length(): number[];
|
|
@@ -12,10 +18,11 @@ export default class CodecHash extends BasicInterface {
|
|
|
12
18
|
encode(buffer: any, name?: any): Promise<Uint8Array>;
|
|
13
19
|
validate(buffer: any): Promise<void>;
|
|
14
20
|
decode(buffer: any): {
|
|
15
|
-
codec:
|
|
21
|
+
codec: Uint8Array;
|
|
16
22
|
name: string;
|
|
17
|
-
size:
|
|
23
|
+
size: number;
|
|
18
24
|
length: number[];
|
|
19
25
|
digest: any;
|
|
20
26
|
};
|
|
21
27
|
}
|
|
28
|
+
export {};
|
package/exports/codec-hash.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import varint from 'varint';
|
|
2
|
-
import BasicInterface from './basic-interface.js';
|
|
2
|
+
import BasicInterface, { jsonStringifyBigInt } from './basic-interface.js';
|
|
3
3
|
import Codec from './codec.js';
|
|
4
4
|
import '@vandeurenglenn/base32';
|
|
5
5
|
import '@vandeurenglenn/base58';
|
|
@@ -11,20 +11,21 @@ import '@leofcoin/codecs';
|
|
|
11
11
|
class CodecHash extends BasicInterface {
|
|
12
12
|
codec;
|
|
13
13
|
discoCodec;
|
|
14
|
-
|
|
14
|
+
size;
|
|
15
|
+
constructor(buffer, options) {
|
|
15
16
|
super();
|
|
16
|
-
if (options
|
|
17
|
+
if (options?.name)
|
|
17
18
|
this.name = options.name;
|
|
18
19
|
else
|
|
19
20
|
this.name = 'disco-hash';
|
|
20
|
-
if (options
|
|
21
|
+
if (options?.codecs)
|
|
21
22
|
this.codecs = options.codecs;
|
|
22
23
|
return this.init(buffer);
|
|
23
24
|
}
|
|
24
25
|
async init(uint8Array) {
|
|
25
26
|
if (uint8Array) {
|
|
26
27
|
if (uint8Array instanceof Uint8Array) {
|
|
27
|
-
this.discoCodec = new Codec(uint8Array
|
|
28
|
+
this.discoCodec = new Codec(uint8Array);
|
|
28
29
|
const name = this.discoCodec.name;
|
|
29
30
|
if (name) {
|
|
30
31
|
this.name = name;
|
|
@@ -66,7 +67,7 @@ class CodecHash extends BasicInterface {
|
|
|
66
67
|
return this.encoded;
|
|
67
68
|
}
|
|
68
69
|
fromJSON(json) {
|
|
69
|
-
return this.encode(new TextEncoder().encode(JSON.stringify(json)));
|
|
70
|
+
return this.encode(new TextEncoder().encode(JSON.stringify(json, jsonStringifyBigInt)));
|
|
70
71
|
}
|
|
71
72
|
async encode(buffer, name) {
|
|
72
73
|
if (!this.name && name)
|
|
@@ -140,7 +141,7 @@ class CodecHash extends BasicInterface {
|
|
|
140
141
|
name: this.name,
|
|
141
142
|
size: this.size,
|
|
142
143
|
length: this.length,
|
|
143
|
-
digest: this.digest
|
|
144
|
+
digest: this.digest
|
|
144
145
|
};
|
|
145
146
|
}
|
|
146
147
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/codec-format-interface",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/leofcoin/codec-format-interface#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@leofcoin/codecs": "^1.0.
|
|
30
|
-
"@leofcoin/crypto": "^0.2.
|
|
29
|
+
"@leofcoin/codecs": "^1.0.7",
|
|
30
|
+
"@leofcoin/crypto": "^0.2.28",
|
|
31
31
|
"@vandeurenglenn/base32": "^1.2.4",
|
|
32
32
|
"@vandeurenglenn/base58": "^1.1.9",
|
|
33
33
|
"@vandeurenglenn/is-hex": "^1.1.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
41
41
|
"@types/varint": "^6.0.3",
|
|
42
|
-
"rollup": "^4.22.
|
|
42
|
+
"rollup": "^4.22.4",
|
|
43
43
|
"tape": "^5.9.0",
|
|
44
44
|
"tinybench": "^2.9.0",
|
|
45
45
|
"tslib": "^2.7.0"
|