@keplr-wallet/common 0.12.4 → 0.12.5
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/build/json/index.d.ts +0 -1
- package/build/json/index.js +0 -1
- package/build/json/index.js.map +1 -1
- package/package.json +4 -4
- package/src/json/index.ts +0 -1
- package/build/json/hex.d.ts +0 -2
- package/build/json/hex.js +0 -31
- package/build/json/hex.js.map +0 -1
- package/build/json/uint8-array.d.ts +0 -6
- package/build/json/uint8-array.js +0 -52
- package/build/json/uint8-array.js.map +0 -1
- package/build/json/uint8-array.spec.d.ts +0 -1
- package/build/json/uint8-array.spec.js +0 -100
- package/build/json/uint8-array.spec.js.map +0 -1
- package/src/json/hex.ts +0 -28
- package/src/json/uint8-array.spec.ts +0 -116
- package/src/json/uint8-array.ts +0 -61
package/build/json/index.d.ts
CHANGED
package/build/json/index.js
CHANGED
|
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./sort"), exports);
|
|
18
|
-
__exportStar(require("./uint8-array"), exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
package/build/json/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keplr-wallet/common",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"author": "chainapsis",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\""
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@keplr-wallet/crypto": "0.12.
|
|
20
|
-
"@keplr-wallet/types": "0.12.
|
|
19
|
+
"@keplr-wallet/crypto": "0.12.5",
|
|
20
|
+
"@keplr-wallet/types": "0.12.5",
|
|
21
21
|
"buffer": "^6.0.3",
|
|
22
22
|
"delay": "^4.4.0",
|
|
23
23
|
"mobx": "^6.1.7"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "653eccdbc8e05b0579ebed8e481fbae0411df461"
|
|
26
26
|
}
|
package/src/json/index.ts
CHANGED
package/build/json/hex.d.ts
DELETED
package/build/json/hex.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Belows are from @cosmjs/encoding library.
|
|
4
|
-
To reduce the bundle size of provider, put them directly here.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.fromHex = exports.toHex = void 0;
|
|
8
|
-
function toHex(data) {
|
|
9
|
-
let out = "";
|
|
10
|
-
for (const byte of data) {
|
|
11
|
-
out += ("0" + byte.toString(16)).slice(-2);
|
|
12
|
-
}
|
|
13
|
-
return out;
|
|
14
|
-
}
|
|
15
|
-
exports.toHex = toHex;
|
|
16
|
-
function fromHex(hexstring) {
|
|
17
|
-
if (hexstring.length % 2 !== 0) {
|
|
18
|
-
throw new Error("hex string length must be a multiple of 2");
|
|
19
|
-
}
|
|
20
|
-
const listOfInts = [];
|
|
21
|
-
for (let i = 0; i < hexstring.length; i += 2) {
|
|
22
|
-
const hexByteAsString = hexstring.substr(i, 2);
|
|
23
|
-
if (!hexByteAsString.match(/[0-9a-f]{2}/i)) {
|
|
24
|
-
throw new Error("hex string contains invalid characters");
|
|
25
|
-
}
|
|
26
|
-
listOfInts.push(parseInt(hexByteAsString, 16));
|
|
27
|
-
}
|
|
28
|
-
return new Uint8Array(listOfInts);
|
|
29
|
-
}
|
|
30
|
-
exports.fromHex = fromHex;
|
|
31
|
-
//# sourceMappingURL=hex.js.map
|
package/build/json/hex.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../../src/json/hex.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,SAAgB,KAAK,CAAC,IAAgB;IACpC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACvB,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5C;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAND,sBAMC;AAED,SAAgB,OAAO,CAAC,SAAiB;IACvC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IAED,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QAC5C,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;YAC1C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAC3D;QACD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC;KAChD;IACD,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC;AAdD,0BAcC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONUint8Array = void 0;
|
|
4
|
-
// The JSON encoder that supports the `Uint8Array`.
|
|
5
|
-
const hex_1 = require("./hex");
|
|
6
|
-
class JSONUint8Array {
|
|
7
|
-
static parse(text) {
|
|
8
|
-
return JSON.parse(text, (key, value) => {
|
|
9
|
-
// Prevent potential prototype poisoning.
|
|
10
|
-
if (key === "__proto__") {
|
|
11
|
-
throw new Error("__proto__ is disallowed");
|
|
12
|
-
}
|
|
13
|
-
if (value &&
|
|
14
|
-
typeof value === "string" &&
|
|
15
|
-
value.startsWith("__uint8array__")) {
|
|
16
|
-
return (0, hex_1.fromHex)(value.replace("__uint8array__", ""));
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
static stringify(obj) {
|
|
22
|
-
return JSON.stringify(obj, (key, value) => {
|
|
23
|
-
// Prevent potential prototype poisoning.
|
|
24
|
-
if (key === "__proto__") {
|
|
25
|
-
throw new Error("__proto__ is disallowed");
|
|
26
|
-
}
|
|
27
|
-
if (value &&
|
|
28
|
-
(value instanceof Uint8Array ||
|
|
29
|
-
(typeof value === "object" &&
|
|
30
|
-
"type" in value &&
|
|
31
|
-
"data" in value &&
|
|
32
|
-
value.type === "Buffer" &&
|
|
33
|
-
Array.isArray(value.data)))) {
|
|
34
|
-
const array = value instanceof Uint8Array ? value : new Uint8Array(value.data);
|
|
35
|
-
return `__uint8array__${(0, hex_1.toHex)(array)}`;
|
|
36
|
-
}
|
|
37
|
-
return value;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
static wrap(obj) {
|
|
41
|
-
if (obj === undefined)
|
|
42
|
-
return undefined;
|
|
43
|
-
return JSON.parse(JSONUint8Array.stringify(obj));
|
|
44
|
-
}
|
|
45
|
-
static unwrap(obj) {
|
|
46
|
-
if (obj === undefined)
|
|
47
|
-
return undefined;
|
|
48
|
-
return JSONUint8Array.parse(JSON.stringify(obj));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.JSONUint8Array = JSONUint8Array;
|
|
52
|
-
//# sourceMappingURL=uint8-array.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uint8-array.js","sourceRoot":"","sources":["../../src/json/uint8-array.ts"],"names":[],"mappings":";;;AAAA,mDAAmD;AACnD,+BAAuC;AAEvC,MAAa,cAAc;IACzB,MAAM,CAAC,KAAK,CAAC,IAAY;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACrC,yCAAyC;YACzC,IAAI,GAAG,KAAK,WAAW,EAAE;gBACvB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;aAC5C;YAED,IACE,KAAK;gBACL,OAAO,KAAK,KAAK,QAAQ;gBACzB,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAClC;gBACA,OAAO,IAAA,aAAO,EAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,CAAC;aACrD;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,GAAY;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxC,yCAAyC;YACzC,IAAI,GAAG,KAAK,WAAW,EAAE;gBACvB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;aAC5C;YAED,IACE,KAAK;gBACL,CAAC,KAAK,YAAY,UAAU;oBAC1B,CAAC,OAAO,KAAK,KAAK,QAAQ;wBACxB,MAAM,IAAI,KAAK;wBACf,MAAM,IAAI,KAAK;wBACf,KAAK,CAAC,IAAI,KAAK,QAAQ;wBACvB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAC/B;gBACA,MAAM,KAAK,GACT,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAEnE,OAAO,iBAAiB,IAAA,WAAK,EAAC,KAAK,CAAC,EAAE,CAAC;aACxC;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAQ;QAClB,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAExC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,GAAQ;QACpB,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAExC,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AAzDD,wCAyDC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const assert_1 = __importDefault(require("assert"));
|
|
7
|
-
const uint8_array_1 = require("./uint8-array");
|
|
8
|
-
describe("Test json with Uint8Array", () => {
|
|
9
|
-
it("should stringify properly with uint8array", () => {
|
|
10
|
-
const test = {
|
|
11
|
-
a: 1,
|
|
12
|
-
b: "test",
|
|
13
|
-
c: new Uint8Array([1, 2, 3]),
|
|
14
|
-
d: Buffer.from([1, 2, 3]),
|
|
15
|
-
e: undefined,
|
|
16
|
-
f: null,
|
|
17
|
-
};
|
|
18
|
-
const text = uint8_array_1.JSONUint8Array.stringify(test);
|
|
19
|
-
assert_1.default.strictEqual(text, '{"a":1,"b":"test","c":"__uint8array__010203","d":"__uint8array__010203","f":null}');
|
|
20
|
-
});
|
|
21
|
-
it("should parse properly with the prefixed string with __uint8array__", () => {
|
|
22
|
-
const text = '{"a":1,"b":"test","c":"__uint8array__010203","d":"__uint8array__010203","f":null}';
|
|
23
|
-
const obj = uint8_array_1.JSONUint8Array.parse(text);
|
|
24
|
-
assert_1.default.deepStrictEqual(obj, {
|
|
25
|
-
a: 1,
|
|
26
|
-
b: "test",
|
|
27
|
-
c: new Uint8Array([1, 2, 3]),
|
|
28
|
-
d: new Uint8Array([1, 2, 3]),
|
|
29
|
-
f: null,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
it("should stringify properly with uint8array for nested obj", () => {
|
|
33
|
-
const test = {
|
|
34
|
-
a: 1,
|
|
35
|
-
b: "test",
|
|
36
|
-
c: new Uint8Array([1, 2, 3]),
|
|
37
|
-
d: {
|
|
38
|
-
a: new Uint8Array([1, 2, 3]),
|
|
39
|
-
b: Buffer.from([1, 2, 3]),
|
|
40
|
-
c: [new Uint8Array([1, 2, 3]), Buffer.from([1, 2, 3])],
|
|
41
|
-
d: [new Uint8Array([1, 2, 3]), null, undefined],
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const text = uint8_array_1.JSONUint8Array.stringify(test);
|
|
45
|
-
assert_1.default.strictEqual(text, '{"a":1,"b":"test","c":"__uint8array__010203","d":{"a":"__uint8array__010203","b":"__uint8array__010203","c":["__uint8array__010203","__uint8array__010203"],"d":["__uint8array__010203",null,null]}}');
|
|
46
|
-
});
|
|
47
|
-
it("should parse properly with uint8array for nested text", () => {
|
|
48
|
-
const text = '{"a":1,"b":"test","c":"__uint8array__010203","d":{"a":"__uint8array__010203","b":"__uint8array__010203","c":["__uint8array__010203","__uint8array__010203"],"d":["__uint8array__010203",null,null]}}';
|
|
49
|
-
const obj = uint8_array_1.JSONUint8Array.parse(text);
|
|
50
|
-
assert_1.default.deepStrictEqual(obj, {
|
|
51
|
-
a: 1,
|
|
52
|
-
b: "test",
|
|
53
|
-
c: new Uint8Array([1, 2, 3]),
|
|
54
|
-
d: {
|
|
55
|
-
a: new Uint8Array([1, 2, 3]),
|
|
56
|
-
b: new Uint8Array([1, 2, 3]),
|
|
57
|
-
c: [new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3])],
|
|
58
|
-
d: [new Uint8Array([1, 2, 3]), null, null],
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
it("should wrap/unwrap properly with uint8array for nested obj", () => {
|
|
63
|
-
const test = {
|
|
64
|
-
a: 1,
|
|
65
|
-
b: "test",
|
|
66
|
-
c: new Uint8Array([1, 2, 3]),
|
|
67
|
-
d: {
|
|
68
|
-
a: new Uint8Array([1, 2, 3]),
|
|
69
|
-
b: Buffer.from([1, 2, 3]),
|
|
70
|
-
c: [new Uint8Array([1, 2, 3]), Buffer.from([1, 2, 3])],
|
|
71
|
-
d: [new Uint8Array([1, 2, 3]), null, undefined],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
const wraped = uint8_array_1.JSONUint8Array.wrap(test);
|
|
75
|
-
assert_1.default.deepStrictEqual(wraped, {
|
|
76
|
-
a: 1,
|
|
77
|
-
b: "test",
|
|
78
|
-
c: "__uint8array__010203",
|
|
79
|
-
d: {
|
|
80
|
-
a: "__uint8array__010203",
|
|
81
|
-
b: "__uint8array__010203",
|
|
82
|
-
c: ["__uint8array__010203", "__uint8array__010203"],
|
|
83
|
-
d: ["__uint8array__010203", null, null],
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
const unwraped = uint8_array_1.JSONUint8Array.unwrap(wraped);
|
|
87
|
-
assert_1.default.deepStrictEqual(unwraped, {
|
|
88
|
-
a: 1,
|
|
89
|
-
b: "test",
|
|
90
|
-
c: new Uint8Array([1, 2, 3]),
|
|
91
|
-
d: {
|
|
92
|
-
a: new Uint8Array([1, 2, 3]),
|
|
93
|
-
b: new Uint8Array([1, 2, 3]),
|
|
94
|
-
c: [new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3])],
|
|
95
|
-
d: [new Uint8Array([1, 2, 3]), null, null],
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
//# sourceMappingURL=uint8-array.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uint8-array.spec.js","sourceRoot":"","sources":["../../src/json/uint8-array.spec.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,+CAA+C;AAE/C,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,IAAI,GAAG;YACX,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5B,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACzB,CAAC,EAAE,SAAS;YACZ,CAAC,EAAE,IAAI;SACR,CAAC;QAEF,MAAM,IAAI,GAAG,4BAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAE5C,gBAAM,CAAC,WAAW,CAChB,IAAI,EACJ,mFAAmF,CACpF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oEAAoE,EAAE,GAAG,EAAE;QAC5E,MAAM,IAAI,GACR,mFAAmF,CAAC;QAEtF,MAAM,GAAG,GAAG,4BAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvC,gBAAM,CAAC,eAAe,CAAC,GAAG,EAAE;YAC1B,CAAC,EAAE,CA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;gBACzD,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;aAC3C;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/src/json/hex.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Belows are from @cosmjs/encoding library.
|
|
3
|
-
To reduce the bundle size of provider, put them directly here.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export function toHex(data: Uint8Array): string {
|
|
7
|
-
let out = "";
|
|
8
|
-
for (const byte of data) {
|
|
9
|
-
out += ("0" + byte.toString(16)).slice(-2);
|
|
10
|
-
}
|
|
11
|
-
return out;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function fromHex(hexstring: string): Uint8Array {
|
|
15
|
-
if (hexstring.length % 2 !== 0) {
|
|
16
|
-
throw new Error("hex string length must be a multiple of 2");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const listOfInts: number[] = [];
|
|
20
|
-
for (let i = 0; i < hexstring.length; i += 2) {
|
|
21
|
-
const hexByteAsString = hexstring.substr(i, 2);
|
|
22
|
-
if (!hexByteAsString.match(/[0-9a-f]{2}/i)) {
|
|
23
|
-
throw new Error("hex string contains invalid characters");
|
|
24
|
-
}
|
|
25
|
-
listOfInts.push(parseInt(hexByteAsString, 16));
|
|
26
|
-
}
|
|
27
|
-
return new Uint8Array(listOfInts);
|
|
28
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
|
|
3
|
-
import { JSONUint8Array } from "./uint8-array";
|
|
4
|
-
|
|
5
|
-
describe("Test json with Uint8Array", () => {
|
|
6
|
-
it("should stringify properly with uint8array", () => {
|
|
7
|
-
const test = {
|
|
8
|
-
a: 1,
|
|
9
|
-
b: "test",
|
|
10
|
-
c: new Uint8Array([1, 2, 3]),
|
|
11
|
-
d: Buffer.from([1, 2, 3]),
|
|
12
|
-
e: undefined,
|
|
13
|
-
f: null,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const text = JSONUint8Array.stringify(test);
|
|
17
|
-
|
|
18
|
-
assert.strictEqual(
|
|
19
|
-
text,
|
|
20
|
-
'{"a":1,"b":"test","c":"__uint8array__010203","d":"__uint8array__010203","f":null}'
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should parse properly with the prefixed string with __uint8array__", () => {
|
|
25
|
-
const text =
|
|
26
|
-
'{"a":1,"b":"test","c":"__uint8array__010203","d":"__uint8array__010203","f":null}';
|
|
27
|
-
|
|
28
|
-
const obj = JSONUint8Array.parse(text);
|
|
29
|
-
assert.deepStrictEqual(obj, {
|
|
30
|
-
a: 1,
|
|
31
|
-
b: "test",
|
|
32
|
-
c: new Uint8Array([1, 2, 3]),
|
|
33
|
-
d: new Uint8Array([1, 2, 3]),
|
|
34
|
-
f: null,
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should stringify properly with uint8array for nested obj", () => {
|
|
39
|
-
const test = {
|
|
40
|
-
a: 1,
|
|
41
|
-
b: "test",
|
|
42
|
-
c: new Uint8Array([1, 2, 3]),
|
|
43
|
-
d: {
|
|
44
|
-
a: new Uint8Array([1, 2, 3]),
|
|
45
|
-
b: Buffer.from([1, 2, 3]),
|
|
46
|
-
c: [new Uint8Array([1, 2, 3]), Buffer.from([1, 2, 3])],
|
|
47
|
-
d: [new Uint8Array([1, 2, 3]), null, undefined],
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const text = JSONUint8Array.stringify(test);
|
|
52
|
-
|
|
53
|
-
assert.strictEqual(
|
|
54
|
-
text,
|
|
55
|
-
'{"a":1,"b":"test","c":"__uint8array__010203","d":{"a":"__uint8array__010203","b":"__uint8array__010203","c":["__uint8array__010203","__uint8array__010203"],"d":["__uint8array__010203",null,null]}}'
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should parse properly with uint8array for nested text", () => {
|
|
60
|
-
const text =
|
|
61
|
-
'{"a":1,"b":"test","c":"__uint8array__010203","d":{"a":"__uint8array__010203","b":"__uint8array__010203","c":["__uint8array__010203","__uint8array__010203"],"d":["__uint8array__010203",null,null]}}';
|
|
62
|
-
|
|
63
|
-
const obj = JSONUint8Array.parse(text);
|
|
64
|
-
assert.deepStrictEqual(obj, {
|
|
65
|
-
a: 1,
|
|
66
|
-
b: "test",
|
|
67
|
-
c: new Uint8Array([1, 2, 3]),
|
|
68
|
-
d: {
|
|
69
|
-
a: new Uint8Array([1, 2, 3]),
|
|
70
|
-
b: new Uint8Array([1, 2, 3]),
|
|
71
|
-
c: [new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3])],
|
|
72
|
-
d: [new Uint8Array([1, 2, 3]), null, null],
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should wrap/unwrap properly with uint8array for nested obj", () => {
|
|
78
|
-
const test = {
|
|
79
|
-
a: 1,
|
|
80
|
-
b: "test",
|
|
81
|
-
c: new Uint8Array([1, 2, 3]),
|
|
82
|
-
d: {
|
|
83
|
-
a: new Uint8Array([1, 2, 3]),
|
|
84
|
-
b: Buffer.from([1, 2, 3]),
|
|
85
|
-
c: [new Uint8Array([1, 2, 3]), Buffer.from([1, 2, 3])],
|
|
86
|
-
d: [new Uint8Array([1, 2, 3]), null, undefined],
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const wraped = JSONUint8Array.wrap(test);
|
|
91
|
-
assert.deepStrictEqual(wraped, {
|
|
92
|
-
a: 1,
|
|
93
|
-
b: "test",
|
|
94
|
-
c: "__uint8array__010203",
|
|
95
|
-
d: {
|
|
96
|
-
a: "__uint8array__010203",
|
|
97
|
-
b: "__uint8array__010203",
|
|
98
|
-
c: ["__uint8array__010203", "__uint8array__010203"],
|
|
99
|
-
d: ["__uint8array__010203", null, null],
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const unwraped = JSONUint8Array.unwrap(wraped);
|
|
104
|
-
assert.deepStrictEqual(unwraped, {
|
|
105
|
-
a: 1,
|
|
106
|
-
b: "test",
|
|
107
|
-
c: new Uint8Array([1, 2, 3]),
|
|
108
|
-
d: {
|
|
109
|
-
a: new Uint8Array([1, 2, 3]),
|
|
110
|
-
b: new Uint8Array([1, 2, 3]),
|
|
111
|
-
c: [new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3])],
|
|
112
|
-
d: [new Uint8Array([1, 2, 3]), null, null],
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
package/src/json/uint8-array.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// The JSON encoder that supports the `Uint8Array`.
|
|
2
|
-
import { fromHex, toHex } from "./hex";
|
|
3
|
-
|
|
4
|
-
export class JSONUint8Array {
|
|
5
|
-
static parse(text: string) {
|
|
6
|
-
return JSON.parse(text, (key, value) => {
|
|
7
|
-
// Prevent potential prototype poisoning.
|
|
8
|
-
if (key === "__proto__") {
|
|
9
|
-
throw new Error("__proto__ is disallowed");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
value &&
|
|
14
|
-
typeof value === "string" &&
|
|
15
|
-
value.startsWith("__uint8array__")
|
|
16
|
-
) {
|
|
17
|
-
return fromHex(value.replace("__uint8array__", ""));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return value;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static stringify(obj: unknown): string {
|
|
25
|
-
return JSON.stringify(obj, (key, value) => {
|
|
26
|
-
// Prevent potential prototype poisoning.
|
|
27
|
-
if (key === "__proto__") {
|
|
28
|
-
throw new Error("__proto__ is disallowed");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
value &&
|
|
33
|
-
(value instanceof Uint8Array ||
|
|
34
|
-
(typeof value === "object" &&
|
|
35
|
-
"type" in value &&
|
|
36
|
-
"data" in value &&
|
|
37
|
-
value.type === "Buffer" &&
|
|
38
|
-
Array.isArray(value.data)))
|
|
39
|
-
) {
|
|
40
|
-
const array =
|
|
41
|
-
value instanceof Uint8Array ? value : new Uint8Array(value.data);
|
|
42
|
-
|
|
43
|
-
return `__uint8array__${toHex(array)}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return value;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static wrap(obj: any): any {
|
|
51
|
-
if (obj === undefined) return undefined;
|
|
52
|
-
|
|
53
|
-
return JSON.parse(JSONUint8Array.stringify(obj));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static unwrap(obj: any): any {
|
|
57
|
-
if (obj === undefined) return undefined;
|
|
58
|
-
|
|
59
|
-
return JSONUint8Array.parse(JSON.stringify(obj));
|
|
60
|
-
}
|
|
61
|
-
}
|