@leofcoin/codec-format-interface 1.3.1 → 1.4.0
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 +533 -457
- package/dist/module.js +4783 -424
- package/package.json +32 -47
- package/src/codec-format-interface.js +6 -1
- package/dist/browser.js +0 -4228
- package/dist/browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/module.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@leofcoin/codec-format-interface",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"url": "
|
|
19
|
-
},
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"parcel": "^2.7.0",
|
|
36
|
-
"rollup": "^2.75.5",
|
|
37
|
-
"tape": "^5.5.3"
|
|
38
|
-
},
|
|
39
|
-
"targets": {
|
|
40
|
-
"browser": {
|
|
41
|
-
"isLibrary": false,
|
|
42
|
-
"context": "browser",
|
|
43
|
-
"outputFormat": "esmodule",
|
|
44
|
-
"includeNodeModules": true
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@leofcoin/codec-format-interface",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"c": "rollup -c"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/leofcoin/codec-format-interface.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/leofcoin/codec-format-interface/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/leofcoin/codec-format-interface#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@vandeurenglenn/base32": "^1.1.0",
|
|
23
|
+
"@vandeurenglenn/base58": "^1.1.0",
|
|
24
|
+
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
25
|
+
"keccak": "^3.0.2",
|
|
26
|
+
"varint": "^6.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"rollup": "^2.75.5",
|
|
30
|
+
"tape": "^5.5.3"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -79,12 +79,17 @@ export default class FormatInterface extends BasicInterface {
|
|
|
79
79
|
* @return {Buffer}
|
|
80
80
|
*/
|
|
81
81
|
async encode(decoded) {
|
|
82
|
+
let encoded
|
|
82
83
|
if (!decoded) decoded = this.decoded;
|
|
83
84
|
const codec = new Codec(this.name)
|
|
84
|
-
|
|
85
|
+
|
|
86
|
+
if (decoded instanceof Uint8Array) encoded = decoded
|
|
87
|
+
else encoded = await this.protoEncode(typeof decoded === 'object' ? JSON.stringify(decoded) : decoded)
|
|
88
|
+
|
|
85
89
|
const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length)
|
|
86
90
|
uint8Array.set(codec.codecBuffer)
|
|
87
91
|
uint8Array.set(encoded, codec.codecBuffer.length)
|
|
92
|
+
|
|
88
93
|
this.encoded = uint8Array
|
|
89
94
|
return this.encoded
|
|
90
95
|
}
|