@w3ux/utils 0.9.0 → 0.10.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
@@ -23,9 +23,11 @@ __export(base_exports, {
23
23
  appendOrEmpty: () => appendOrEmpty,
24
24
  camelize: () => camelize,
25
25
  ellipsisFn: () => ellipsisFn,
26
+ eqSet: () => eqSet,
26
27
  formatAccountSs58: () => formatAccountSs58,
27
28
  greaterThanZero: () => greaterThanZero,
28
29
  isNotZero: () => isNotZero,
30
+ isSuperset: () => isSuperset,
29
31
  minDecimalPlaces: () => minDecimalPlaces,
30
32
  pageFromUri: () => pageFromUri,
31
33
  removeHexPrefix: () => removeHexPrefix,
@@ -35,7 +37,7 @@ __export(base_exports, {
35
37
  });
36
38
  module.exports = __toCommonJS(base_exports);
37
39
  var import_bignumber = require("bignumber.js");
38
- var import_util_crypto = require("@polkadot/util-crypto");
40
+ var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
39
41
  var camelize = (str) => {
40
42
  const convertToString = (string) => {
41
43
  if (string) {
@@ -134,23 +136,33 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
134
136
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
135
137
  var formatAccountSs58 = (address, ss58Prefix) => {
136
138
  try {
137
- const decodedAddress = (0, import_util_crypto.decodeAddress)(address);
138
- const formattedAddress = (0, import_util_crypto.encodeAddress)(decodedAddress, ss58Prefix);
139
- return formattedAddress;
139
+ const codec = (0, import_substrate_bindings.AccountId)(ss58Prefix);
140
+ return codec.dec(codec.enc(address));
140
141
  } catch (e) {
141
142
  return null;
142
143
  }
143
144
  };
144
145
  var removeHexPrefix = (str) => str.replace(/^0x/, "");
146
+ var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
147
+ var isSuperset = (set, subset) => {
148
+ for (const elem of subset) {
149
+ if (!set.has(elem)) {
150
+ return false;
151
+ }
152
+ }
153
+ return true;
154
+ };
145
155
  // Annotate the CommonJS export names for ESM import in node:
146
156
  0 && (module.exports = {
147
157
  appendOr,
148
158
  appendOrEmpty,
149
159
  camelize,
150
160
  ellipsisFn,
161
+ eqSet,
151
162
  formatAccountSs58,
152
163
  greaterThanZero,
153
164
  isNotZero,
165
+ isSuperset,
154
166
  minDecimalPlaces,
155
167
  pageFromUri,
156
168
  removeHexPrefix,
package/base.d.cts CHANGED
@@ -73,5 +73,7 @@ declare const formatAccountSs58: (address: string, ss58Prefix: number) => string
73
73
  * exists at the beginning of the input string.
74
74
  */
75
75
  declare const removeHexPrefix: (str: string) => string;
76
+ declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
77
+ declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
76
78
 
77
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, formatAccountSs58, greaterThanZero, isNotZero, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
79
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
package/base.d.ts CHANGED
@@ -73,5 +73,7 @@ declare const formatAccountSs58: (address: string, ss58Prefix: number) => string
73
73
  * exists at the beginning of the input string.
74
74
  */
75
75
  declare const removeHexPrefix: (str: string) => string;
76
+ declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
77
+ declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
76
78
 
77
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, formatAccountSs58, greaterThanZero, isNotZero, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
79
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
package/base.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/base.ts
2
2
  import { BigNumber } from "bignumber.js";
3
- import { decodeAddress, encodeAddress } from "@polkadot/util-crypto";
3
+ import { AccountId } from "@polkadot-api/substrate-bindings";
4
4
  var camelize = (str) => {
5
5
  const convertToString = (string) => {
6
6
  if (string) {
@@ -99,22 +99,32 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
99
99
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
100
100
  var formatAccountSs58 = (address, ss58Prefix) => {
101
101
  try {
102
- const decodedAddress = decodeAddress(address);
103
- const formattedAddress = encodeAddress(decodedAddress, ss58Prefix);
104
- return formattedAddress;
102
+ const codec = AccountId(ss58Prefix);
103
+ return codec.dec(codec.enc(address));
105
104
  } catch (e) {
106
105
  return null;
107
106
  }
108
107
  };
109
108
  var removeHexPrefix = (str) => str.replace(/^0x/, "");
109
+ var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
110
+ var isSuperset = (set, subset) => {
111
+ for (const elem of subset) {
112
+ if (!set.has(elem)) {
113
+ return false;
114
+ }
115
+ }
116
+ return true;
117
+ };
110
118
  export {
111
119
  appendOr,
112
120
  appendOrEmpty,
113
121
  camelize,
114
122
  ellipsisFn,
123
+ eqSet,
115
124
  formatAccountSs58,
116
125
  greaterThanZero,
117
126
  isNotZero,
127
+ isSuperset,
118
128
  minDecimalPlaces,
119
129
  pageFromUri,
120
130
  removeHexPrefix,
package/index.cjs CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/index.ts
@@ -27,12 +37,14 @@ __export(src_exports, {
27
37
  capitalizeFirstLetter: () => capitalizeFirstLetter,
28
38
  determinePoolDisplay: () => determinePoolDisplay,
29
39
  ellipsisFn: () => ellipsisFn,
40
+ eqSet: () => eqSet,
30
41
  evalUnits: () => evalUnits,
31
42
  extractUrlValue: () => extractUrlValue,
32
43
  formatAccountSs58: () => formatAccountSs58,
33
44
  greaterThanZero: () => greaterThanZero,
34
45
  inChrome: () => inChrome,
35
46
  isNotZero: () => isNotZero,
47
+ isSuperset: () => isSuperset,
36
48
  isValidAddress: () => isValidAddress,
37
49
  isValidHttpUrl: () => isValidHttpUrl,
38
50
  localStorageOrDefault: () => localStorageOrDefault,
@@ -63,7 +75,7 @@ module.exports = __toCommonJS(src_exports);
63
75
 
64
76
  // src/base.ts
65
77
  var import_bignumber = require("bignumber.js");
66
- var import_util_crypto = require("@polkadot/util-crypto");
78
+ var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
67
79
  var camelize = (str) => {
68
80
  const convertToString = (string) => {
69
81
  if (string) {
@@ -162,19 +174,172 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
162
174
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
163
175
  var formatAccountSs58 = (address, ss58Prefix) => {
164
176
  try {
165
- const decodedAddress = (0, import_util_crypto.decodeAddress)(address);
166
- const formattedAddress = (0, import_util_crypto.encodeAddress)(decodedAddress, ss58Prefix);
167
- return formattedAddress;
177
+ const codec = (0, import_substrate_bindings.AccountId)(ss58Prefix);
178
+ return codec.dec(codec.enc(address));
168
179
  } catch (e) {
169
180
  return null;
170
181
  }
171
182
  };
172
183
  var removeHexPrefix = (str) => str.replace(/^0x/, "");
184
+ var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
185
+ var isSuperset = (set, subset) => {
186
+ for (const elem of subset) {
187
+ if (!set.has(elem)) {
188
+ return false;
189
+ }
190
+ }
191
+ return true;
192
+ };
193
+
194
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
195
+ var import_node_util = __toESM(require("util"), 1);
196
+
197
+ // ../../node_modules/@polkadot/x-global/index.js
198
+ function evaluateThis(fn) {
199
+ return fn("return this");
200
+ }
201
+ var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
202
+ function extractGlobal(name, fallback) {
203
+ return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
204
+ }
205
+
206
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
207
+ var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", import_node_util.default.TextDecoder);
208
+
209
+ // ../../node_modules/@polkadot/x-textencoder/node.js
210
+ var import_node_util2 = __toESM(require("util"), 1);
211
+ var Fallback = class {
212
+ __internal__encoder;
213
+ constructor() {
214
+ this.__internal__encoder = new import_node_util2.default.TextEncoder();
215
+ }
216
+ // For a Jest 26.0.1 environment, Buffer !== Uint8Array
217
+ encode(value) {
218
+ return Uint8Array.from(this.__internal__encoder.encode(value));
219
+ }
220
+ };
221
+ var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
222
+
223
+ // ../../node_modules/@polkadot/util/is/function.js
224
+ function isFunction(value) {
225
+ return typeof value === "function";
226
+ }
227
+
228
+ // ../../node_modules/@polkadot/x-bigint/index.js
229
+ function invalidFallback() {
230
+ return Number.NaN;
231
+ }
232
+ var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
233
+
234
+ // ../../node_modules/@polkadot/util/hex/toU8a.js
235
+ var CHR = "0123456789abcdef";
236
+ var U8 = new Uint8Array(256);
237
+ var U16 = new Uint8Array(256 * 256);
238
+ for (let i = 0, count = CHR.length; i < count; i++) {
239
+ U8[CHR[i].charCodeAt(0) | 0] = i | 0;
240
+ if (i > 9) {
241
+ U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
242
+ }
243
+ }
244
+ for (let i = 0; i < 256; i++) {
245
+ const s = i << 8;
246
+ for (let j = 0; j < 256; j++) {
247
+ U16[s | j] = U8[i] << 4 | U8[j];
248
+ }
249
+ }
250
+ function hexToU8a(value, bitLength = -1) {
251
+ if (!value) {
252
+ return new Uint8Array();
253
+ }
254
+ let s = value.startsWith("0x") ? 2 : 0;
255
+ const decLength = Math.ceil((value.length - s) / 2);
256
+ const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
257
+ const result = new Uint8Array(endLength);
258
+ const offset = endLength > decLength ? endLength - decLength : 0;
259
+ for (let i = offset; i < endLength; i++, s += 2) {
260
+ result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
261
+ }
262
+ return result;
263
+ }
264
+
265
+ // ../../node_modules/@polkadot/util/is/hex.js
266
+ var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
267
+ function isHex(value, bitLength = -1, ignoreLength) {
268
+ return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
269
+ }
270
+
271
+ // ../../node_modules/@polkadot/util/has.js
272
+ var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
273
+ var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
274
+ var hasProcess = typeof xglobal.process === "object";
275
+
276
+ // ../../node_modules/@polkadot/util/is/buffer.js
277
+ function isBuffer(value) {
278
+ return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
279
+ }
280
+
281
+ // ../../node_modules/@polkadot/util/is/u8a.js
282
+ function isU8a(value) {
283
+ return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
284
+ }
285
+
286
+ // ../../node_modules/@polkadot/util/string/toU8a.js
287
+ var encoder = new TextEncoder();
288
+ function stringToU8a(value) {
289
+ return value ? encoder.encode(value.toString()) : new Uint8Array();
290
+ }
291
+
292
+ // ../../node_modules/@polkadot/util/u8a/toU8a.js
293
+ function u8aToU8a(value) {
294
+ return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
295
+ }
296
+
297
+ // ../../node_modules/@polkadot/util/u8a/eq.js
298
+ function u8aEq(a, b) {
299
+ const u8aa = u8aToU8a(a);
300
+ const u8ab = u8aToU8a(b);
301
+ if (u8aa.length === u8ab.length) {
302
+ const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
303
+ const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
304
+ const mod = u8aa.length % 4 | 0;
305
+ const length = u8aa.length - mod | 0;
306
+ for (let i = 0; i < length; i += 4) {
307
+ if (dvA.getUint32(i) !== dvB.getUint32(i)) {
308
+ return false;
309
+ }
310
+ }
311
+ for (let i = length, count = u8aa.length; i < count; i++) {
312
+ if (u8aa[i] !== u8ab[i]) {
313
+ return false;
314
+ }
315
+ }
316
+ return true;
317
+ }
318
+ return false;
319
+ }
320
+
321
+ // ../../node_modules/@polkadot/util/u8a/toString.js
322
+ var decoder = new TextDecoder("utf-8");
323
+ function u8aToString(value) {
324
+ return value ? decoder.decode(value) : "";
325
+ }
326
+
327
+ // ../../node_modules/@polkadot/util/u8a/wrap.js
328
+ var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
329
+ var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
330
+ var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
331
+ var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
332
+ function u8aIsWrapped(u8a, withEthereum) {
333
+ return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
334
+ }
335
+ function u8aUnwrapBytes(bytes) {
336
+ const u8a = u8aToU8a(bytes);
337
+ return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
338
+ }
173
339
 
174
340
  // src/unit.ts
175
- var import_util_crypto2 = require("@polkadot/util-crypto");
176
- var import_util = require("@polkadot/util");
177
341
  var import_bignumber2 = require("bignumber.js");
342
+ var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
178
343
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
179
344
  var planckToUnit = (val, units) => new import_bignumber2.BigNumber(
180
345
  val.dividedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).toFixed(units)
@@ -204,10 +369,8 @@ var localStorageOrDefault = (key, _default, parse = false) => {
204
369
  };
205
370
  var isValidAddress = (address) => {
206
371
  try {
207
- if ((0, import_util.isHex)(address)) {
208
- return true;
209
- }
210
- (0, import_util_crypto2.decodeAddress)(address);
372
+ const codec = (0, import_substrate_bindings2.AccountId)();
373
+ codec.dec(codec.enc(address));
211
374
  return true;
212
375
  } catch (e) {
213
376
  return false;
@@ -216,7 +379,7 @@ var isValidAddress = (address) => {
216
379
  var determinePoolDisplay = (address, batchItem) => {
217
380
  const defaultDisplay = ellipsisFn(address, 6);
218
381
  let display = batchItem ?? defaultDisplay;
219
- const displayAsBytes = (0, import_util.u8aToString)((0, import_util.u8aUnwrapBytes)(display));
382
+ const displayAsBytes = u8aToString(u8aUnwrapBytes(display));
220
383
  if (displayAsBytes !== "") {
221
384
  display = displayAsBytes;
222
385
  }
@@ -446,12 +609,14 @@ var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(valu
446
609
  capitalizeFirstLetter,
447
610
  determinePoolDisplay,
448
611
  ellipsisFn,
612
+ eqSet,
449
613
  evalUnits,
450
614
  extractUrlValue,
451
615
  formatAccountSs58,
452
616
  greaterThanZero,
453
617
  inChrome,
454
618
  isNotZero,
619
+ isSuperset,
455
620
  isValidAddress,
456
621
  isValidHttpUrl,
457
622
  localStorageOrDefault,
package/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, formatAccountSs58, greaterThanZero, isNotZero, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
2
2
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, evalUnits, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
3
3
  import 'bignumber.js';
4
4
  import '@w3ux/types';
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, formatAccountSs58, greaterThanZero, isNotZero, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
2
2
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, evalUnits, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
3
3
  import 'bignumber.js';
4
4
  import '@w3ux/types';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/base.ts
2
2
  import { BigNumber } from "bignumber.js";
3
- import { decodeAddress, encodeAddress } from "@polkadot/util-crypto";
3
+ import { AccountId } from "@polkadot-api/substrate-bindings";
4
4
  var camelize = (str) => {
5
5
  const convertToString = (string) => {
6
6
  if (string) {
@@ -99,19 +99,172 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
99
99
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
100
100
  var formatAccountSs58 = (address, ss58Prefix) => {
101
101
  try {
102
- const decodedAddress = decodeAddress(address);
103
- const formattedAddress = encodeAddress(decodedAddress, ss58Prefix);
104
- return formattedAddress;
102
+ const codec = AccountId(ss58Prefix);
103
+ return codec.dec(codec.enc(address));
105
104
  } catch (e) {
106
105
  return null;
107
106
  }
108
107
  };
109
108
  var removeHexPrefix = (str) => str.replace(/^0x/, "");
109
+ var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
110
+ var isSuperset = (set, subset) => {
111
+ for (const elem of subset) {
112
+ if (!set.has(elem)) {
113
+ return false;
114
+ }
115
+ }
116
+ return true;
117
+ };
118
+
119
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
120
+ import util from "node:util";
121
+
122
+ // ../../node_modules/@polkadot/x-global/index.js
123
+ function evaluateThis(fn) {
124
+ return fn("return this");
125
+ }
126
+ var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
127
+ function extractGlobal(name, fallback) {
128
+ return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
129
+ }
130
+
131
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
132
+ var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", util.TextDecoder);
133
+
134
+ // ../../node_modules/@polkadot/x-textencoder/node.js
135
+ import util2 from "node:util";
136
+ var Fallback = class {
137
+ __internal__encoder;
138
+ constructor() {
139
+ this.__internal__encoder = new util2.TextEncoder();
140
+ }
141
+ // For a Jest 26.0.1 environment, Buffer !== Uint8Array
142
+ encode(value) {
143
+ return Uint8Array.from(this.__internal__encoder.encode(value));
144
+ }
145
+ };
146
+ var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
147
+
148
+ // ../../node_modules/@polkadot/util/is/function.js
149
+ function isFunction(value) {
150
+ return typeof value === "function";
151
+ }
152
+
153
+ // ../../node_modules/@polkadot/x-bigint/index.js
154
+ function invalidFallback() {
155
+ return Number.NaN;
156
+ }
157
+ var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
158
+
159
+ // ../../node_modules/@polkadot/util/hex/toU8a.js
160
+ var CHR = "0123456789abcdef";
161
+ var U8 = new Uint8Array(256);
162
+ var U16 = new Uint8Array(256 * 256);
163
+ for (let i = 0, count = CHR.length; i < count; i++) {
164
+ U8[CHR[i].charCodeAt(0) | 0] = i | 0;
165
+ if (i > 9) {
166
+ U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
167
+ }
168
+ }
169
+ for (let i = 0; i < 256; i++) {
170
+ const s = i << 8;
171
+ for (let j = 0; j < 256; j++) {
172
+ U16[s | j] = U8[i] << 4 | U8[j];
173
+ }
174
+ }
175
+ function hexToU8a(value, bitLength = -1) {
176
+ if (!value) {
177
+ return new Uint8Array();
178
+ }
179
+ let s = value.startsWith("0x") ? 2 : 0;
180
+ const decLength = Math.ceil((value.length - s) / 2);
181
+ const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
182
+ const result = new Uint8Array(endLength);
183
+ const offset = endLength > decLength ? endLength - decLength : 0;
184
+ for (let i = offset; i < endLength; i++, s += 2) {
185
+ result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
186
+ }
187
+ return result;
188
+ }
189
+
190
+ // ../../node_modules/@polkadot/util/is/hex.js
191
+ var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
192
+ function isHex(value, bitLength = -1, ignoreLength) {
193
+ return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
194
+ }
195
+
196
+ // ../../node_modules/@polkadot/util/has.js
197
+ var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
198
+ var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
199
+ var hasProcess = typeof xglobal.process === "object";
200
+
201
+ // ../../node_modules/@polkadot/util/is/buffer.js
202
+ function isBuffer(value) {
203
+ return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
204
+ }
205
+
206
+ // ../../node_modules/@polkadot/util/is/u8a.js
207
+ function isU8a(value) {
208
+ return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
209
+ }
210
+
211
+ // ../../node_modules/@polkadot/util/string/toU8a.js
212
+ var encoder = new TextEncoder();
213
+ function stringToU8a(value) {
214
+ return value ? encoder.encode(value.toString()) : new Uint8Array();
215
+ }
216
+
217
+ // ../../node_modules/@polkadot/util/u8a/toU8a.js
218
+ function u8aToU8a(value) {
219
+ return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
220
+ }
221
+
222
+ // ../../node_modules/@polkadot/util/u8a/eq.js
223
+ function u8aEq(a, b) {
224
+ const u8aa = u8aToU8a(a);
225
+ const u8ab = u8aToU8a(b);
226
+ if (u8aa.length === u8ab.length) {
227
+ const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
228
+ const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
229
+ const mod = u8aa.length % 4 | 0;
230
+ const length = u8aa.length - mod | 0;
231
+ for (let i = 0; i < length; i += 4) {
232
+ if (dvA.getUint32(i) !== dvB.getUint32(i)) {
233
+ return false;
234
+ }
235
+ }
236
+ for (let i = length, count = u8aa.length; i < count; i++) {
237
+ if (u8aa[i] !== u8ab[i]) {
238
+ return false;
239
+ }
240
+ }
241
+ return true;
242
+ }
243
+ return false;
244
+ }
245
+
246
+ // ../../node_modules/@polkadot/util/u8a/toString.js
247
+ var decoder = new TextDecoder("utf-8");
248
+ function u8aToString(value) {
249
+ return value ? decoder.decode(value) : "";
250
+ }
251
+
252
+ // ../../node_modules/@polkadot/util/u8a/wrap.js
253
+ var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
254
+ var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
255
+ var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
256
+ var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
257
+ function u8aIsWrapped(u8a, withEthereum) {
258
+ return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
259
+ }
260
+ function u8aUnwrapBytes(bytes) {
261
+ const u8a = u8aToU8a(bytes);
262
+ return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
263
+ }
110
264
 
111
265
  // src/unit.ts
112
- import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
113
- import { isHex, u8aToString, u8aUnwrapBytes } from "@polkadot/util";
114
266
  import { BigNumber as BigNumber2 } from "bignumber.js";
267
+ import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
115
268
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
116
269
  var planckToUnit = (val, units) => new BigNumber2(
117
270
  val.dividedBy(new BigNumber2(10).exponentiatedBy(units)).toFixed(units)
@@ -141,10 +294,8 @@ var localStorageOrDefault = (key, _default, parse = false) => {
141
294
  };
142
295
  var isValidAddress = (address) => {
143
296
  try {
144
- if (isHex(address)) {
145
- return true;
146
- }
147
- decodeAddress2(address);
297
+ const codec = AccountId2();
298
+ codec.dec(codec.enc(address));
148
299
  return true;
149
300
  } catch (e) {
150
301
  return false;
@@ -382,12 +533,14 @@ export {
382
533
  capitalizeFirstLetter,
383
534
  determinePoolDisplay,
384
535
  ellipsisFn,
536
+ eqSet,
385
537
  evalUnits,
386
538
  extractUrlValue,
387
539
  formatAccountSs58,
388
540
  greaterThanZero,
389
541
  inChrome,
390
542
  isNotZero,
543
+ isSuperset,
391
544
  isValidAddress,
392
545
  isValidHttpUrl,
393
546
  localStorageOrDefault,
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@w3ux/utils",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
- "@polkadot/util": "^13.1.1",
7
- "@polkadot/util-crypto": "^13.1.1",
6
+ "@polkadot-api/substrate-bindings": "^0.9.3",
8
7
  "bignumber.js": "^9.1.1"
9
8
  },
10
9
  "main": "index.cjs",
package/unit.cjs CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/unit.ts
@@ -47,13 +57,159 @@ __export(unit_exports, {
47
57
  varToUrlHash: () => varToUrlHash
48
58
  });
49
59
  module.exports = __toCommonJS(unit_exports);
50
- var import_util_crypto2 = require("@polkadot/util-crypto");
51
- var import_util = require("@polkadot/util");
60
+
61
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
62
+ var import_node_util = __toESM(require("util"), 1);
63
+
64
+ // ../../node_modules/@polkadot/x-global/index.js
65
+ function evaluateThis(fn) {
66
+ return fn("return this");
67
+ }
68
+ var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
69
+ function extractGlobal(name, fallback) {
70
+ return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
71
+ }
72
+
73
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
74
+ var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", import_node_util.default.TextDecoder);
75
+
76
+ // ../../node_modules/@polkadot/x-textencoder/node.js
77
+ var import_node_util2 = __toESM(require("util"), 1);
78
+ var Fallback = class {
79
+ __internal__encoder;
80
+ constructor() {
81
+ this.__internal__encoder = new import_node_util2.default.TextEncoder();
82
+ }
83
+ // For a Jest 26.0.1 environment, Buffer !== Uint8Array
84
+ encode(value) {
85
+ return Uint8Array.from(this.__internal__encoder.encode(value));
86
+ }
87
+ };
88
+ var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
89
+
90
+ // ../../node_modules/@polkadot/util/is/function.js
91
+ function isFunction(value) {
92
+ return typeof value === "function";
93
+ }
94
+
95
+ // ../../node_modules/@polkadot/x-bigint/index.js
96
+ function invalidFallback() {
97
+ return Number.NaN;
98
+ }
99
+ var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
100
+
101
+ // ../../node_modules/@polkadot/util/hex/toU8a.js
102
+ var CHR = "0123456789abcdef";
103
+ var U8 = new Uint8Array(256);
104
+ var U16 = new Uint8Array(256 * 256);
105
+ for (let i = 0, count = CHR.length; i < count; i++) {
106
+ U8[CHR[i].charCodeAt(0) | 0] = i | 0;
107
+ if (i > 9) {
108
+ U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
109
+ }
110
+ }
111
+ for (let i = 0; i < 256; i++) {
112
+ const s = i << 8;
113
+ for (let j = 0; j < 256; j++) {
114
+ U16[s | j] = U8[i] << 4 | U8[j];
115
+ }
116
+ }
117
+ function hexToU8a(value, bitLength = -1) {
118
+ if (!value) {
119
+ return new Uint8Array();
120
+ }
121
+ let s = value.startsWith("0x") ? 2 : 0;
122
+ const decLength = Math.ceil((value.length - s) / 2);
123
+ const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
124
+ const result = new Uint8Array(endLength);
125
+ const offset = endLength > decLength ? endLength - decLength : 0;
126
+ for (let i = offset; i < endLength; i++, s += 2) {
127
+ result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
128
+ }
129
+ return result;
130
+ }
131
+
132
+ // ../../node_modules/@polkadot/util/is/hex.js
133
+ var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
134
+ function isHex(value, bitLength = -1, ignoreLength) {
135
+ return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
136
+ }
137
+
138
+ // ../../node_modules/@polkadot/util/has.js
139
+ var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
140
+ var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
141
+ var hasProcess = typeof xglobal.process === "object";
142
+
143
+ // ../../node_modules/@polkadot/util/is/buffer.js
144
+ function isBuffer(value) {
145
+ return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
146
+ }
147
+
148
+ // ../../node_modules/@polkadot/util/is/u8a.js
149
+ function isU8a(value) {
150
+ return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
151
+ }
152
+
153
+ // ../../node_modules/@polkadot/util/string/toU8a.js
154
+ var encoder = new TextEncoder();
155
+ function stringToU8a(value) {
156
+ return value ? encoder.encode(value.toString()) : new Uint8Array();
157
+ }
158
+
159
+ // ../../node_modules/@polkadot/util/u8a/toU8a.js
160
+ function u8aToU8a(value) {
161
+ return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
162
+ }
163
+
164
+ // ../../node_modules/@polkadot/util/u8a/eq.js
165
+ function u8aEq(a, b) {
166
+ const u8aa = u8aToU8a(a);
167
+ const u8ab = u8aToU8a(b);
168
+ if (u8aa.length === u8ab.length) {
169
+ const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
170
+ const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
171
+ const mod = u8aa.length % 4 | 0;
172
+ const length = u8aa.length - mod | 0;
173
+ for (let i = 0; i < length; i += 4) {
174
+ if (dvA.getUint32(i) !== dvB.getUint32(i)) {
175
+ return false;
176
+ }
177
+ }
178
+ for (let i = length, count = u8aa.length; i < count; i++) {
179
+ if (u8aa[i] !== u8ab[i]) {
180
+ return false;
181
+ }
182
+ }
183
+ return true;
184
+ }
185
+ return false;
186
+ }
187
+
188
+ // ../../node_modules/@polkadot/util/u8a/toString.js
189
+ var decoder = new TextDecoder("utf-8");
190
+ function u8aToString(value) {
191
+ return value ? decoder.decode(value) : "";
192
+ }
193
+
194
+ // ../../node_modules/@polkadot/util/u8a/wrap.js
195
+ var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
196
+ var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
197
+ var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
198
+ var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
199
+ function u8aIsWrapped(u8a, withEthereum) {
200
+ return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
201
+ }
202
+ function u8aUnwrapBytes(bytes) {
203
+ const u8a = u8aToU8a(bytes);
204
+ return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
205
+ }
206
+
207
+ // src/unit.ts
52
208
  var import_bignumber2 = require("bignumber.js");
53
209
 
54
210
  // src/base.ts
55
211
  var import_bignumber = require("bignumber.js");
56
- var import_util_crypto = require("@polkadot/util-crypto");
212
+ var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
57
213
  var ellipsisFn = (str, amount = 6, position = "center") => {
58
214
  const half = str.length / 2;
59
215
  if (amount <= 4) {
@@ -83,6 +239,7 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
83
239
  var rmCommas = (val) => val.replace(/,/g, "");
84
240
 
85
241
  // src/unit.ts
242
+ var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
86
243
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
87
244
  var planckToUnit = (val, units) => new import_bignumber2.BigNumber(
88
245
  val.dividedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).toFixed(units)
@@ -112,10 +269,8 @@ var localStorageOrDefault = (key, _default, parse = false) => {
112
269
  };
113
270
  var isValidAddress = (address) => {
114
271
  try {
115
- if ((0, import_util.isHex)(address)) {
116
- return true;
117
- }
118
- (0, import_util_crypto2.decodeAddress)(address);
272
+ const codec = (0, import_substrate_bindings2.AccountId)();
273
+ codec.dec(codec.enc(address));
119
274
  return true;
120
275
  } catch (e) {
121
276
  return false;
@@ -124,7 +279,7 @@ var isValidAddress = (address) => {
124
279
  var determinePoolDisplay = (address, batchItem) => {
125
280
  const defaultDisplay = ellipsisFn(address, 6);
126
281
  let display = batchItem ?? defaultDisplay;
127
- const displayAsBytes = (0, import_util.u8aToString)((0, import_util.u8aUnwrapBytes)(display));
282
+ const displayAsBytes = u8aToString(u8aUnwrapBytes(display));
128
283
  if (displayAsBytes !== "") {
129
284
  display = displayAsBytes;
130
285
  }
package/unit.js CHANGED
@@ -1,11 +1,155 @@
1
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
2
+ import util from "node:util";
3
+
4
+ // ../../node_modules/@polkadot/x-global/index.js
5
+ function evaluateThis(fn) {
6
+ return fn("return this");
7
+ }
8
+ var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
9
+ function extractGlobal(name, fallback) {
10
+ return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
11
+ }
12
+
13
+ // ../../node_modules/@polkadot/x-textdecoder/node.js
14
+ var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", util.TextDecoder);
15
+
16
+ // ../../node_modules/@polkadot/x-textencoder/node.js
17
+ import util2 from "node:util";
18
+ var Fallback = class {
19
+ __internal__encoder;
20
+ constructor() {
21
+ this.__internal__encoder = new util2.TextEncoder();
22
+ }
23
+ // For a Jest 26.0.1 environment, Buffer !== Uint8Array
24
+ encode(value) {
25
+ return Uint8Array.from(this.__internal__encoder.encode(value));
26
+ }
27
+ };
28
+ var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
29
+
30
+ // ../../node_modules/@polkadot/util/is/function.js
31
+ function isFunction(value) {
32
+ return typeof value === "function";
33
+ }
34
+
35
+ // ../../node_modules/@polkadot/x-bigint/index.js
36
+ function invalidFallback() {
37
+ return Number.NaN;
38
+ }
39
+ var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
40
+
41
+ // ../../node_modules/@polkadot/util/hex/toU8a.js
42
+ var CHR = "0123456789abcdef";
43
+ var U8 = new Uint8Array(256);
44
+ var U16 = new Uint8Array(256 * 256);
45
+ for (let i = 0, count = CHR.length; i < count; i++) {
46
+ U8[CHR[i].charCodeAt(0) | 0] = i | 0;
47
+ if (i > 9) {
48
+ U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
49
+ }
50
+ }
51
+ for (let i = 0; i < 256; i++) {
52
+ const s = i << 8;
53
+ for (let j = 0; j < 256; j++) {
54
+ U16[s | j] = U8[i] << 4 | U8[j];
55
+ }
56
+ }
57
+ function hexToU8a(value, bitLength = -1) {
58
+ if (!value) {
59
+ return new Uint8Array();
60
+ }
61
+ let s = value.startsWith("0x") ? 2 : 0;
62
+ const decLength = Math.ceil((value.length - s) / 2);
63
+ const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
64
+ const result = new Uint8Array(endLength);
65
+ const offset = endLength > decLength ? endLength - decLength : 0;
66
+ for (let i = offset; i < endLength; i++, s += 2) {
67
+ result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
68
+ }
69
+ return result;
70
+ }
71
+
72
+ // ../../node_modules/@polkadot/util/is/hex.js
73
+ var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
74
+ function isHex(value, bitLength = -1, ignoreLength) {
75
+ return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
76
+ }
77
+
78
+ // ../../node_modules/@polkadot/util/has.js
79
+ var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
80
+ var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
81
+ var hasProcess = typeof xglobal.process === "object";
82
+
83
+ // ../../node_modules/@polkadot/util/is/buffer.js
84
+ function isBuffer(value) {
85
+ return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
86
+ }
87
+
88
+ // ../../node_modules/@polkadot/util/is/u8a.js
89
+ function isU8a(value) {
90
+ return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
91
+ }
92
+
93
+ // ../../node_modules/@polkadot/util/string/toU8a.js
94
+ var encoder = new TextEncoder();
95
+ function stringToU8a(value) {
96
+ return value ? encoder.encode(value.toString()) : new Uint8Array();
97
+ }
98
+
99
+ // ../../node_modules/@polkadot/util/u8a/toU8a.js
100
+ function u8aToU8a(value) {
101
+ return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
102
+ }
103
+
104
+ // ../../node_modules/@polkadot/util/u8a/eq.js
105
+ function u8aEq(a, b) {
106
+ const u8aa = u8aToU8a(a);
107
+ const u8ab = u8aToU8a(b);
108
+ if (u8aa.length === u8ab.length) {
109
+ const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
110
+ const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
111
+ const mod = u8aa.length % 4 | 0;
112
+ const length = u8aa.length - mod | 0;
113
+ for (let i = 0; i < length; i += 4) {
114
+ if (dvA.getUint32(i) !== dvB.getUint32(i)) {
115
+ return false;
116
+ }
117
+ }
118
+ for (let i = length, count = u8aa.length; i < count; i++) {
119
+ if (u8aa[i] !== u8ab[i]) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+
128
+ // ../../node_modules/@polkadot/util/u8a/toString.js
129
+ var decoder = new TextDecoder("utf-8");
130
+ function u8aToString(value) {
131
+ return value ? decoder.decode(value) : "";
132
+ }
133
+
134
+ // ../../node_modules/@polkadot/util/u8a/wrap.js
135
+ var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
136
+ var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
137
+ var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
138
+ var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
139
+ function u8aIsWrapped(u8a, withEthereum) {
140
+ return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
141
+ }
142
+ function u8aUnwrapBytes(bytes) {
143
+ const u8a = u8aToU8a(bytes);
144
+ return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
145
+ }
146
+
1
147
  // src/unit.ts
2
- import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
3
- import { isHex, u8aToString, u8aUnwrapBytes } from "@polkadot/util";
4
148
  import { BigNumber as BigNumber2 } from "bignumber.js";
5
149
 
6
150
  // src/base.ts
7
151
  import { BigNumber } from "bignumber.js";
8
- import { decodeAddress, encodeAddress } from "@polkadot/util-crypto";
152
+ import { AccountId } from "@polkadot-api/substrate-bindings";
9
153
  var ellipsisFn = (str, amount = 6, position = "center") => {
10
154
  const half = str.length / 2;
11
155
  if (amount <= 4) {
@@ -35,6 +179,7 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
35
179
  var rmCommas = (val) => val.replace(/,/g, "");
36
180
 
37
181
  // src/unit.ts
182
+ import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
38
183
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
39
184
  var planckToUnit = (val, units) => new BigNumber2(
40
185
  val.dividedBy(new BigNumber2(10).exponentiatedBy(units)).toFixed(units)
@@ -64,10 +209,8 @@ var localStorageOrDefault = (key, _default, parse = false) => {
64
209
  };
65
210
  var isValidAddress = (address) => {
66
211
  try {
67
- if (isHex(address)) {
68
- return true;
69
- }
70
- decodeAddress2(address);
212
+ const codec = AccountId2();
213
+ codec.dec(codec.enc(address));
71
214
  return true;
72
215
  } catch (e) {
73
216
  return false;
package/util/index.cjs DELETED
@@ -1,23 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/util/index.ts
17
- var util_exports = {};
18
- module.exports = __toCommonJS(util_exports);
19
- __reExport(util_exports, require("@polkadot/util"), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require("@polkadot/util")
23
- });
package/util/index.d.cts DELETED
@@ -1,2 +0,0 @@
1
- export * from '@polkadot/util';
2
- import '@polkadot/util-crypto';
package/util/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from '@polkadot/util';
2
- import '@polkadot/util-crypto';
package/util/index.js DELETED
@@ -1,2 +0,0 @@
1
- // src/util/index.ts
2
- export * from "@polkadot/util";
@@ -1,23 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/util-crypto/index.ts
17
- var util_crypto_exports = {};
18
- module.exports = __toCommonJS(util_crypto_exports);
19
- __reExport(util_crypto_exports, require("@polkadot/util-crypto"), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require("@polkadot/util-crypto")
23
- });
@@ -1 +0,0 @@
1
- export * from '@polkadot/util-crypto';
@@ -1 +0,0 @@
1
- export * from '@polkadot/util-crypto';
@@ -1,2 +0,0 @@
1
- // src/util-crypto/index.ts
2
- export * from "@polkadot/util-crypto";