@leofcoin/codec-format-interface 1.2.8 → 1.3.2
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/index.js +10 -5
- package/dist/module.js +4836 -0
- package/package.json +33 -34
- package/rollup.config.js +12 -0
- package/src/codec-format-interface.js +10 -4
package/package.json
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@leofcoin/codec-format-interface",
|
|
3
|
-
"version": "1.2
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"c": "rollup -c"
|
|
10
|
-
},
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/leofcoin/codec-format-interface.git"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [],
|
|
16
|
-
"author": "",
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"bugs": {
|
|
19
|
-
"url": "https://github.com/leofcoin/codec-format-interface/issues"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/leofcoin/codec-format-interface#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@vandeurenglenn/base32": "^1.1.0",
|
|
24
|
-
"@vandeurenglenn/base58": "^1.1.0",
|
|
25
|
-
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
26
|
-
"keccak": "^3.0.2",
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@leofcoin/codec-format-interface",
|
|
3
|
+
"version": "1.3.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/module.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"c": "rollup -c"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/leofcoin/codec-format-interface.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/leofcoin/codec-format-interface/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/leofcoin/codec-format-interface#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@vandeurenglenn/base32": "^1.1.0",
|
|
24
|
+
"@vandeurenglenn/base58": "^1.1.0",
|
|
25
|
+
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
26
|
+
"keccak": "^3.0.2",
|
|
27
|
+
"varint": "^6.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"rollup": "^2.75.5",
|
|
31
|
+
"tape": "^5.5.3"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
import resolve from 'rollup-plugin-node-resolve'
|
|
2
|
+
import commonjs from 'rollup-plugin-commonjs'
|
|
1
3
|
export default [{
|
|
2
4
|
input: ['src/index.js'],
|
|
3
5
|
output: [{
|
|
4
6
|
dir: 'dist',
|
|
5
7
|
format: 'cjs'
|
|
6
8
|
}]
|
|
9
|
+
}, {
|
|
10
|
+
input: ['src/index.js'],
|
|
11
|
+
output: [{
|
|
12
|
+
file: 'dist/module.js',
|
|
13
|
+
format: 'es'
|
|
14
|
+
}],
|
|
15
|
+
plugins: [
|
|
16
|
+
commonjs(),
|
|
17
|
+
resolve()
|
|
18
|
+
]
|
|
7
19
|
}]
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import BasicInterface from './basic-interface.js'
|
|
2
2
|
import Codec from './codec.js';
|
|
3
3
|
import Hash from './codec-hash.js'
|
|
4
|
-
import protons from 'protons'
|
|
5
4
|
|
|
6
5
|
export default class FormatInterface extends BasicInterface {
|
|
7
6
|
|
|
8
7
|
async protoEncode(data) {
|
|
9
|
-
|
|
8
|
+
// check schema
|
|
9
|
+
return new TextEncoder().encode(data)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async protoDecode(data) {
|
|
13
|
-
|
|
13
|
+
// check schema
|
|
14
|
+
return new TextDecoder().decode(data)
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
async init(buffer) {
|
|
@@ -66,6 +67,11 @@ export default class FormatInterface extends BasicInterface {
|
|
|
66
67
|
encoded = encoded.slice(discoCodec.codecBuffer.length)
|
|
67
68
|
this.name = discoCodec.name
|
|
68
69
|
this.decoded = await this.protoDecode(encoded)
|
|
70
|
+
try {
|
|
71
|
+
this.decoded = JSON.parse(this.decoded)
|
|
72
|
+
} catch {
|
|
73
|
+
|
|
74
|
+
}
|
|
69
75
|
return this.decoded
|
|
70
76
|
}
|
|
71
77
|
|
|
@@ -75,7 +81,7 @@ export default class FormatInterface extends BasicInterface {
|
|
|
75
81
|
async encode(decoded) {
|
|
76
82
|
if (!decoded) decoded = this.decoded;
|
|
77
83
|
const codec = new Codec(this.name)
|
|
78
|
-
const encoded = await this.protoEncode(decoded)
|
|
84
|
+
const encoded = await this.protoEncode(typeof decoded === 'object' ? JSON.stringify(decoded) : decoded)
|
|
79
85
|
const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length)
|
|
80
86
|
uint8Array.set(codec.codecBuffer)
|
|
81
87
|
uint8Array.set(encoded, codec.codecBuffer.length)
|