@keplr-wallet/common 0.11.15 → 0.11.16-rc.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/build/json/index.d.ts +1 -1
- package/build/json/index.js +11 -16
- package/build/json/index.js.map +1 -1
- package/build/json/sort.d.ts +2 -0
- package/build/json/sort.js +23 -0
- package/build/json/sort.js.map +1 -0
- package/build/json/sort.spec.d.ts +1 -0
- package/build/json/sort.spec.js +38 -0
- package/build/json/sort.spec.js.map +1 -0
- package/package.json +3 -3
- package/src/json/index.ts +1 -14
- package/src/json/sort.spec.ts +30 -0
- package/src/json/sort.ts +18 -0
package/build/json/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./sort";
|
package/build/json/index.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports
|
|
4
|
-
function sortObjectByKey(obj) {
|
|
5
|
-
if (typeof obj !== "object" || obj === null) {
|
|
6
|
-
return obj;
|
|
7
|
-
}
|
|
8
|
-
if (Array.isArray(obj)) {
|
|
9
|
-
return obj.map(sortObjectByKey);
|
|
10
|
-
}
|
|
11
|
-
const sortedKeys = Object.keys(obj).sort();
|
|
12
|
-
const result = {};
|
|
13
|
-
sortedKeys.forEach((key) => {
|
|
14
|
-
result[key] = sortObjectByKey(obj[key]);
|
|
15
|
-
});
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
exports.sortObjectByKey = sortObjectByKey;
|
|
13
|
+
__exportStar(require("./sort"), exports);
|
|
19
14
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortedJsonByKeyStringify = exports.sortObjectByKey = void 0;
|
|
4
|
+
function sortObjectByKey(obj) {
|
|
5
|
+
if (typeof obj !== "object" || obj === null) {
|
|
6
|
+
return obj;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(obj)) {
|
|
9
|
+
return obj.map(sortObjectByKey);
|
|
10
|
+
}
|
|
11
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
12
|
+
const result = {};
|
|
13
|
+
sortedKeys.forEach((key) => {
|
|
14
|
+
result[key] = sortObjectByKey(obj[key]);
|
|
15
|
+
});
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
exports.sortObjectByKey = sortObjectByKey;
|
|
19
|
+
function sortedJsonByKeyStringify(obj) {
|
|
20
|
+
return JSON.stringify(sortObjectByKey(obj));
|
|
21
|
+
}
|
|
22
|
+
exports.sortedJsonByKeyStringify = sortedJsonByKeyStringify;
|
|
23
|
+
//# sourceMappingURL=sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.js","sourceRoot":"","sources":["../../src/json/sort.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,GAAwB;IACtD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE;QAC3C,OAAO,GAAG,CAAC;KACZ;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;KACjC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,0CAaC;AAED,SAAgB,wBAAwB,CAAC,GAAwB;IAC/D,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAFD,4DAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const sort_1 = require("./sort");
|
|
13
|
+
describe("Test json sorting", () => {
|
|
14
|
+
test("Test sorting", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const tests = [
|
|
16
|
+
{
|
|
17
|
+
input: `{"cosmos":"foo", "atom":"bar", "tendermint":"foobar"}`,
|
|
18
|
+
output: `{"atom":"bar","cosmos":"foo","tendermint":"foobar"}`,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
input: `{"consensus_params":{"block_size_params":{"max_bytes":22020096,"max_txs":100000,"max_gas":-1},"tx_size_params":{"max_bytes":10240,"max_gas":-1},"block_gossip_params":{"block_part_size_bytes":65536},"evidence_params":{"max_age":100000}},"validators":[{"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="},"power":100,"name":""}],"app_hash":"","genesis_time":"2018-05-11T15:52:25.424795506Z","chain_id":"test-chain-Q6VeoW","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"denom":"Token","amount":1000},{"denom":"stake","amount":50}]}],"stake":{"pool":{"total_supply":50,"bonded_shares":"0","unbonded_shares":"0","bonded_pool":0,"unbonded_pool":0,"inflation_last_time":0,"inflation":"7/100"},"params":{"inflation_rate_change":"13/100","inflation_max":"1/5","inflation_min":"7/100","goal_bonded":"67/100","max_validators":100,"bond_denom":"stake"},"candidates":null,"bonds":null}}}`,
|
|
22
|
+
output: `{"app_hash":"","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"amount":1000,"denom":"Token"},{"amount":50,"denom":"stake"}]}],"stake":{"bonds":null,"candidates":null,"params":{"bond_denom":"stake","goal_bonded":"67/100","inflation_max":"1/5","inflation_min":"7/100","inflation_rate_change":"13/100","max_validators":100},"pool":{"bonded_pool":0,"bonded_shares":"0","inflation":"7/100","inflation_last_time":0,"total_supply":50,"unbonded_pool":0,"unbonded_shares":"0"}}},"chain_id":"test-chain-Q6VeoW","consensus_params":{"block_gossip_params":{"block_part_size_bytes":65536},"block_size_params":{"max_bytes":22020096,"max_gas":-1,"max_txs":100000},"evidence_params":{"max_age":100000},"tx_size_params":{"max_bytes":10240,"max_gas":-1}},"genesis_time":"2018-05-11T15:52:25.424795506Z","validators":[{"name":"","power":100,"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="}}]}`,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
input: `{"chain_id":"test-chain-1","sequence":1,"fee_bytes":{"amount":[{"amount":5,"denom":"photon"}],"gas":10000},"msg_bytes":{"inputs":[{"address":"696E707574","coins":[{"amount":10,"denom":"atom"}]}],"outputs":[{"address":"6F7574707574","coins":[{"amount":10,"denom":"atom"}]}]},"alt_bytes":null}`,
|
|
26
|
+
output: `{"alt_bytes":null,"chain_id":"test-chain-1","fee_bytes":{"amount":[{"amount":5,"denom":"photon"}],"gas":10000},"msg_bytes":{"inputs":[{"address":"696E707574","coins":[{"amount":10,"denom":"atom"}]}],"outputs":[{"address":"6F7574707574","coins":[{"amount":10,"denom":"atom"}]}]},"sequence":1}`,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
input: `{"type":"cosmos-sdk/MsgGrant","value":{"granter":"secret145s07us09dr5hs9t5t4z5x57427fe34jk0t8jd","grant":{"authorization":{"type":"cosmos-sdk/StakeAuthorization","value":{"Validators":{"type":"cosmos-sdk/StakeAuthorization/AllowList","value":{"allow_list":{"address":["secretvaloper1x76f2c2cuwa4e3lttjgqeqva0725ftmqvgvfnv"]}}},"authorization_type":1}},"expiration":"2024-10-19T18:00:00Z"},"grantee":"secret195qz2llswagsypzgh79r6yhmps8cpqmcl5pt8q"}}`,
|
|
30
|
+
output: `{"type":"cosmos-sdk/MsgGrant","value":{"grant":{"authorization":{"type":"cosmos-sdk/StakeAuthorization","value":{"Validators":{"type":"cosmos-sdk/StakeAuthorization/AllowList","value":{"allow_list":{"address":["secretvaloper1x76f2c2cuwa4e3lttjgqeqva0725ftmqvgvfnv"]}}},"authorization_type":1}},"expiration":"2024-10-19T18:00:00Z"},"grantee":"secret195qz2llswagsypzgh79r6yhmps8cpqmcl5pt8q","granter":"secret145s07us09dr5hs9t5t4z5x57427fe34jk0t8jd"}}`,
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
for (const test of tests) {
|
|
34
|
+
expect(sort_1.sortedJsonByKeyStringify(JSON.parse(test.input))).toBe(test.output);
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=sort.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.spec.js","sourceRoot":"","sources":["../../src/json/sort.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAkD;AAElD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAI,CAAC,cAAc,EAAE,GAAS,EAAE;QAC9B,MAAM,KAAK,GAA0D;YACnE;gBACE,KAAK,EAAE,wDAAwD;gBAC/D,MAAM,EAAE,qDAAqD;aAC9D;YACD;gBACE,KAAK,EAAE,87BAA87B;gBACr8B,MAAM,EAAE,87BAA87B;aACv8B;YACD;gBACE,KAAK,EAAE,qSAAqS;gBAC5S,MAAM,EAAE,qSAAqS;aAC9S;YACD;gBACE,KAAK,EAAE,kcAAkc;gBACzc,MAAM,EAAE,kcAAkc;aAC3c;SACF,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,CAAC,+BAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAC3D,IAAI,CAAC,MAAM,CACZ,CAAC;SACH;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keplr-wallet/common",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.16-rc.0",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"author": "chainapsis",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\""
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@keplr-wallet/crypto": "0.11.
|
|
20
|
+
"@keplr-wallet/crypto": "0.11.16-rc.0",
|
|
21
21
|
"buffer": "^6.0.3",
|
|
22
22
|
"delay": "^4.4.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "b3edb75be1402ee9f679a692918922aaa0c99be7"
|
|
25
25
|
}
|
package/src/json/index.ts
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
if (typeof obj !== "object" || obj === null) {
|
|
3
|
-
return obj;
|
|
4
|
-
}
|
|
5
|
-
if (Array.isArray(obj)) {
|
|
6
|
-
return obj.map(sortObjectByKey);
|
|
7
|
-
}
|
|
8
|
-
const sortedKeys = Object.keys(obj).sort();
|
|
9
|
-
const result: Record<string, any> = {};
|
|
10
|
-
sortedKeys.forEach((key) => {
|
|
11
|
-
result[key] = sortObjectByKey(obj[key]);
|
|
12
|
-
});
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
1
|
+
export * from "./sort";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { sortedJsonByKeyStringify } from "./sort";
|
|
2
|
+
|
|
3
|
+
describe("Test json sorting", () => {
|
|
4
|
+
test("Test sorting", async () => {
|
|
5
|
+
const tests: { readonly input: string; readonly output: string }[] = [
|
|
6
|
+
{
|
|
7
|
+
input: `{"cosmos":"foo", "atom":"bar", "tendermint":"foobar"}`,
|
|
8
|
+
output: `{"atom":"bar","cosmos":"foo","tendermint":"foobar"}`,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
input: `{"consensus_params":{"block_size_params":{"max_bytes":22020096,"max_txs":100000,"max_gas":-1},"tx_size_params":{"max_bytes":10240,"max_gas":-1},"block_gossip_params":{"block_part_size_bytes":65536},"evidence_params":{"max_age":100000}},"validators":[{"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="},"power":100,"name":""}],"app_hash":"","genesis_time":"2018-05-11T15:52:25.424795506Z","chain_id":"test-chain-Q6VeoW","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"denom":"Token","amount":1000},{"denom":"stake","amount":50}]}],"stake":{"pool":{"total_supply":50,"bonded_shares":"0","unbonded_shares":"0","bonded_pool":0,"unbonded_pool":0,"inflation_last_time":0,"inflation":"7/100"},"params":{"inflation_rate_change":"13/100","inflation_max":"1/5","inflation_min":"7/100","goal_bonded":"67/100","max_validators":100,"bond_denom":"stake"},"candidates":null,"bonds":null}}}`,
|
|
12
|
+
output: `{"app_hash":"","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"amount":1000,"denom":"Token"},{"amount":50,"denom":"stake"}]}],"stake":{"bonds":null,"candidates":null,"params":{"bond_denom":"stake","goal_bonded":"67/100","inflation_max":"1/5","inflation_min":"7/100","inflation_rate_change":"13/100","max_validators":100},"pool":{"bonded_pool":0,"bonded_shares":"0","inflation":"7/100","inflation_last_time":0,"total_supply":50,"unbonded_pool":0,"unbonded_shares":"0"}}},"chain_id":"test-chain-Q6VeoW","consensus_params":{"block_gossip_params":{"block_part_size_bytes":65536},"block_size_params":{"max_bytes":22020096,"max_gas":-1,"max_txs":100000},"evidence_params":{"max_age":100000},"tx_size_params":{"max_bytes":10240,"max_gas":-1}},"genesis_time":"2018-05-11T15:52:25.424795506Z","validators":[{"name":"","power":100,"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="}}]}`,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
input: `{"chain_id":"test-chain-1","sequence":1,"fee_bytes":{"amount":[{"amount":5,"denom":"photon"}],"gas":10000},"msg_bytes":{"inputs":[{"address":"696E707574","coins":[{"amount":10,"denom":"atom"}]}],"outputs":[{"address":"6F7574707574","coins":[{"amount":10,"denom":"atom"}]}]},"alt_bytes":null}`,
|
|
16
|
+
output: `{"alt_bytes":null,"chain_id":"test-chain-1","fee_bytes":{"amount":[{"amount":5,"denom":"photon"}],"gas":10000},"msg_bytes":{"inputs":[{"address":"696E707574","coins":[{"amount":10,"denom":"atom"}]}],"outputs":[{"address":"6F7574707574","coins":[{"amount":10,"denom":"atom"}]}]},"sequence":1}`,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
input: `{"type":"cosmos-sdk/MsgGrant","value":{"granter":"secret145s07us09dr5hs9t5t4z5x57427fe34jk0t8jd","grant":{"authorization":{"type":"cosmos-sdk/StakeAuthorization","value":{"Validators":{"type":"cosmos-sdk/StakeAuthorization/AllowList","value":{"allow_list":{"address":["secretvaloper1x76f2c2cuwa4e3lttjgqeqva0725ftmqvgvfnv"]}}},"authorization_type":1}},"expiration":"2024-10-19T18:00:00Z"},"grantee":"secret195qz2llswagsypzgh79r6yhmps8cpqmcl5pt8q"}}`,
|
|
20
|
+
output: `{"type":"cosmos-sdk/MsgGrant","value":{"grant":{"authorization":{"type":"cosmos-sdk/StakeAuthorization","value":{"Validators":{"type":"cosmos-sdk/StakeAuthorization/AllowList","value":{"allow_list":{"address":["secretvaloper1x76f2c2cuwa4e3lttjgqeqva0725ftmqvgvfnv"]}}},"authorization_type":1}},"expiration":"2024-10-19T18:00:00Z"},"grantee":"secret195qz2llswagsypzgh79r6yhmps8cpqmcl5pt8q","granter":"secret145s07us09dr5hs9t5t4z5x57427fe34jk0t8jd"}}`,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
for (const test of tests) {
|
|
25
|
+
expect(sortedJsonByKeyStringify(JSON.parse(test.input))).toBe(
|
|
26
|
+
test.output
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
package/src/json/sort.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function sortObjectByKey(obj: Record<string, any>): any {
|
|
2
|
+
if (typeof obj !== "object" || obj === null) {
|
|
3
|
+
return obj;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(obj)) {
|
|
6
|
+
return obj.map(sortObjectByKey);
|
|
7
|
+
}
|
|
8
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
9
|
+
const result: Record<string, any> = {};
|
|
10
|
+
sortedKeys.forEach((key) => {
|
|
11
|
+
result[key] = sortObjectByKey(obj[key]);
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function sortedJsonByKeyStringify(obj: Record<string, any>): string {
|
|
17
|
+
return JSON.stringify(sortObjectByKey(obj));
|
|
18
|
+
}
|