@w3ux/utils 0.4.0 → 0.6.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/base.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/base.ts
@@ -45,7 +35,7 @@ __export(base_exports, {
45
35
  });
46
36
  module.exports = __toCommonJS(base_exports);
47
37
  var import_bignumber = require("bignumber.js");
48
- var import_keyring = __toESM(require("@polkadot/keyring"), 1);
38
+ var import_util_crypto = require("@polkadot/util-crypto");
49
39
  var camelize = (str) => {
50
40
  const convertToString = (string) => {
51
41
  if (string) {
@@ -142,15 +132,11 @@ var withTimeout = (ms, promise, options) => {
142
132
  };
143
133
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
144
134
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
145
- var formatAccountSs58 = (address, ss58) => {
135
+ var formatAccountSs58 = (address, ss58Prefix) => {
146
136
  try {
147
- const keyring = new import_keyring.default();
148
- keyring.setSS58Format(ss58);
149
- const formatted = keyring.addFromAddress(address).address;
150
- if (formatted !== address) {
151
- return formatted;
152
- }
153
- return null;
137
+ const decodedAddress = (0, import_util_crypto.decodeAddress)(address);
138
+ const formattedAddress = (0, import_util_crypto.encodeAddress)(decodedAddress, ss58Prefix);
139
+ return formattedAddress;
154
140
  } catch (e) {
155
141
  return null;
156
142
  }
package/base.d.cts CHANGED
@@ -63,10 +63,10 @@ declare const appendOrEmpty: (condition: boolean | string | undefined, value: st
63
63
  */
64
64
  declare const appendOr: (condition: boolean | string | undefined, value: string, fallback: string) => string;
65
65
  /**
66
- * @name appendOr
66
+ * @name formatAccountSs58
67
67
  * @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.
68
68
  */
69
- declare const formatAccountSs58: (address: string, ss58: number) => string;
69
+ declare const formatAccountSs58: (address: string, ss58Prefix: number) => string;
70
70
  /**
71
71
  * @name removeHexPrefix
72
72
  * @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
package/base.d.ts CHANGED
@@ -63,10 +63,10 @@ declare const appendOrEmpty: (condition: boolean | string | undefined, value: st
63
63
  */
64
64
  declare const appendOr: (condition: boolean | string | undefined, value: string, fallback: string) => string;
65
65
  /**
66
- * @name appendOr
66
+ * @name formatAccountSs58
67
67
  * @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.
68
68
  */
69
- declare const formatAccountSs58: (address: string, ss58: number) => string;
69
+ declare const formatAccountSs58: (address: string, ss58Prefix: number) => string;
70
70
  /**
71
71
  * @name removeHexPrefix
72
72
  * @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
package/base.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/base.ts
2
2
  import { BigNumber } from "bignumber.js";
3
- import Keyring from "@polkadot/keyring";
3
+ import { decodeAddress, encodeAddress } from "@polkadot/util-crypto";
4
4
  var camelize = (str) => {
5
5
  const convertToString = (string) => {
6
6
  if (string) {
@@ -97,15 +97,11 @@ var withTimeout = (ms, promise, options) => {
97
97
  };
98
98
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
99
99
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
100
- var formatAccountSs58 = (address, ss58) => {
100
+ var formatAccountSs58 = (address, ss58Prefix) => {
101
101
  try {
102
- const keyring = new Keyring();
103
- keyring.setSS58Format(ss58);
104
- const formatted = keyring.addFromAddress(address).address;
105
- if (formatted !== address) {
106
- return formatted;
107
- }
108
- return null;
102
+ const decodedAddress = decodeAddress(address);
103
+ const formattedAddress = encodeAddress(decodedAddress, ss58Prefix);
104
+ return formattedAddress;
109
105
  } catch (e) {
110
106
  return null;
111
107
  }
package/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/index.ts
@@ -73,7 +63,7 @@ module.exports = __toCommonJS(src_exports);
73
63
 
74
64
  // src/base.ts
75
65
  var import_bignumber = require("bignumber.js");
76
- var import_keyring = __toESM(require("@polkadot/keyring"), 1);
66
+ var import_util_crypto = require("@polkadot/util-crypto");
77
67
  var camelize = (str) => {
78
68
  const convertToString = (string) => {
79
69
  if (string) {
@@ -170,15 +160,11 @@ var withTimeout = (ms, promise, options) => {
170
160
  };
171
161
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
172
162
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
173
- var formatAccountSs58 = (address, ss58) => {
163
+ var formatAccountSs58 = (address, ss58Prefix) => {
174
164
  try {
175
- const keyring = new import_keyring.default();
176
- keyring.setSS58Format(ss58);
177
- const formatted = keyring.addFromAddress(address).address;
178
- if (formatted !== address) {
179
- return formatted;
180
- }
181
- return null;
165
+ const decodedAddress = (0, import_util_crypto.decodeAddress)(address);
166
+ const formattedAddress = (0, import_util_crypto.encodeAddress)(decodedAddress, ss58Prefix);
167
+ return formattedAddress;
182
168
  } catch (e) {
183
169
  return null;
184
170
  }
@@ -186,7 +172,7 @@ var formatAccountSs58 = (address, ss58) => {
186
172
  var removeHexPrefix = (str) => str.replace(/^0x/, "");
187
173
 
188
174
  // src/unit.ts
189
- var import_keyring2 = require("@polkadot/keyring");
175
+ var import_util_crypto2 = require("@polkadot/util-crypto");
190
176
  var import_util = require("@polkadot/util");
191
177
  var import_bignumber2 = require("bignumber.js");
192
178
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
@@ -218,7 +204,10 @@ var localStorageOrDefault = (key, _default, parse = false) => {
218
204
  };
219
205
  var isValidAddress = (address) => {
220
206
  try {
221
- (0, import_keyring2.encodeAddress)((0, import_util.isHex)(address) ? (0, import_util.hexToU8a)(address) : (0, import_keyring2.decodeAddress)(address));
207
+ if ((0, import_util.isHex)(address)) {
208
+ return true;
209
+ }
210
+ (0, import_util_crypto2.decodeAddress)(address);
222
211
  return true;
223
212
  } catch (e) {
224
213
  return false;
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/base.ts
2
2
  import { BigNumber } from "bignumber.js";
3
- import Keyring from "@polkadot/keyring";
3
+ import { decodeAddress, encodeAddress } from "@polkadot/util-crypto";
4
4
  var camelize = (str) => {
5
5
  const convertToString = (string) => {
6
6
  if (string) {
@@ -97,15 +97,11 @@ var withTimeout = (ms, promise, options) => {
97
97
  };
98
98
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
99
99
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
100
- var formatAccountSs58 = (address, ss58) => {
100
+ var formatAccountSs58 = (address, ss58Prefix) => {
101
101
  try {
102
- const keyring = new Keyring();
103
- keyring.setSS58Format(ss58);
104
- const formatted = keyring.addFromAddress(address).address;
105
- if (formatted !== address) {
106
- return formatted;
107
- }
108
- return null;
102
+ const decodedAddress = decodeAddress(address);
103
+ const formattedAddress = encodeAddress(decodedAddress, ss58Prefix);
104
+ return formattedAddress;
109
105
  } catch (e) {
110
106
  return null;
111
107
  }
@@ -113,8 +109,8 @@ var formatAccountSs58 = (address, ss58) => {
113
109
  var removeHexPrefix = (str) => str.replace(/^0x/, "");
114
110
 
115
111
  // src/unit.ts
116
- import { decodeAddress, encodeAddress } from "@polkadot/keyring";
117
- import { hexToU8a, isHex, u8aToString, u8aUnwrapBytes } from "@polkadot/util";
112
+ import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
113
+ import { isHex, u8aToString, u8aUnwrapBytes } from "@polkadot/util";
118
114
  import { BigNumber as BigNumber2 } from "bignumber.js";
119
115
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
120
116
  var planckToUnit = (val, units) => new BigNumber2(
@@ -145,7 +141,10 @@ var localStorageOrDefault = (key, _default, parse = false) => {
145
141
  };
146
142
  var isValidAddress = (address) => {
147
143
  try {
148
- encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
144
+ if (isHex(address)) {
145
+ return true;
146
+ }
147
+ decodeAddress2(address);
149
148
  return true;
150
149
  } catch (e) {
151
150
  return false;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@w3ux/utils",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
- "@polkadot/keyring": "^12.6.2",
7
- "@polkadot/util": "^12.6.2",
6
+ "@polkadot/util": "^13.1.1",
7
+ "@polkadot/util-crypto": "^13.1.1",
8
8
  "bignumber.js": "^9.1.1"
9
9
  },
10
10
  "main": "index.cjs",
package/unit.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/unit.ts
@@ -57,13 +47,13 @@ __export(unit_exports, {
57
47
  varToUrlHash: () => varToUrlHash
58
48
  });
59
49
  module.exports = __toCommonJS(unit_exports);
60
- var import_keyring2 = require("@polkadot/keyring");
50
+ var import_util_crypto2 = require("@polkadot/util-crypto");
61
51
  var import_util = require("@polkadot/util");
62
52
  var import_bignumber2 = require("bignumber.js");
63
53
 
64
54
  // src/base.ts
65
55
  var import_bignumber = require("bignumber.js");
66
- var import_keyring = __toESM(require("@polkadot/keyring"), 1);
56
+ var import_util_crypto = require("@polkadot/util-crypto");
67
57
  var ellipsisFn = (str, amount = 6, position = "center") => {
68
58
  const half = str.length / 2;
69
59
  if (amount <= 4) {
@@ -122,7 +112,10 @@ var localStorageOrDefault = (key, _default, parse = false) => {
122
112
  };
123
113
  var isValidAddress = (address) => {
124
114
  try {
125
- (0, import_keyring2.encodeAddress)((0, import_util.isHex)(address) ? (0, import_util.hexToU8a)(address) : (0, import_keyring2.decodeAddress)(address));
115
+ if ((0, import_util.isHex)(address)) {
116
+ return true;
117
+ }
118
+ (0, import_util_crypto2.decodeAddress)(address);
126
119
  return true;
127
120
  } catch (e) {
128
121
  return false;
package/unit.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // src/unit.ts
2
- import { decodeAddress, encodeAddress } from "@polkadot/keyring";
3
- import { hexToU8a, isHex, u8aToString, u8aUnwrapBytes } from "@polkadot/util";
2
+ import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
3
+ import { isHex, u8aToString, u8aUnwrapBytes } from "@polkadot/util";
4
4
  import { BigNumber as BigNumber2 } from "bignumber.js";
5
5
 
6
6
  // src/base.ts
7
7
  import { BigNumber } from "bignumber.js";
8
- import Keyring from "@polkadot/keyring";
8
+ import { decodeAddress, encodeAddress } from "@polkadot/util-crypto";
9
9
  var ellipsisFn = (str, amount = 6, position = "center") => {
10
10
  const half = str.length / 2;
11
11
  if (amount <= 4) {
@@ -64,7 +64,10 @@ var localStorageOrDefault = (key, _default, parse = false) => {
64
64
  };
65
65
  var isValidAddress = (address) => {
66
66
  try {
67
- encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
67
+ if (isHex(address)) {
68
+ return true;
69
+ }
70
+ decodeAddress2(address);
68
71
  return true;
69
72
  } catch (e) {
70
73
  return false;