@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/package.json CHANGED
@@ -1,47 +1,32 @@
1
- {
2
- "name": "@leofcoin/codec-format-interface",
3
- "version": "1.3.1",
4
- "description": "",
5
- "source": "src/index.js",
6
- "main": "dist/index.js",
7
- "module": "dist/module.js",
8
- "browser": "dist/browser.js",
9
- "browserslist": "> 0.5%, last 2 versions, not dead",
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
12
- "c": "rollup -c",
13
- "watch": "parcel watch",
14
- "build": "parcel build"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/leofcoin/codec-format-interface.git"
19
- },
20
- "keywords": [],
21
- "author": "",
22
- "license": "MIT",
23
- "bugs": {
24
- "url": "https://github.com/leofcoin/codec-format-interface/issues"
25
- },
26
- "homepage": "https://github.com/leofcoin/codec-format-interface#readme",
27
- "dependencies": {
28
- "@vandeurenglenn/base32": "^1.1.0",
29
- "@vandeurenglenn/base58": "^1.1.0",
30
- "@vandeurenglenn/is-hex": "^1.0.0",
31
- "keccak": "^3.0.2",
32
- "varint": "^6.0.0"
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
- const encoded = await this.protoEncode(typeof decoded === 'object' ? JSON.stringify(decoded) : decoded)
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
  }