@chainflip/utils 0.2.0 → 0.3.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/dist/base58.js +2 -2
- package/dist/bytes.cjs +9 -1
- package/dist/bytes.d.cts +2 -1
- package/dist/bytes.d.ts +2 -1
- package/dist/bytes.js +1 -1
- package/dist/{chunk-34J3OMUQ.js → chunk-D7RIA7SA.js} +9 -1
- package/dist/{chunk-F5VHSRYQ.js → chunk-UPA7KLTI.js} +1 -1
- package/dist/math.cjs +33 -0
- package/dist/math.d.cts +4 -0
- package/dist/math.d.ts +4 -0
- package/dist/math.js +7 -0
- package/dist/ss58.js +2 -2
- package/package.json +1 -1
package/dist/base58.js
CHANGED
package/dist/bytes.cjs
CHANGED
|
@@ -87,7 +87,15 @@ var decodeBytesWithCharset = (input, charset) => {
|
|
|
87
87
|
const bytes = input.split("").map((char) => charMap[char]);
|
|
88
88
|
return new Uint8Array(convertBase(bytes, charset.length, 256));
|
|
89
89
|
};
|
|
90
|
-
var
|
|
90
|
+
var addPrefix = (input) => {
|
|
91
|
+
const [, bytes] = /^(?:0x)?([a-f\d]*)$/i.exec(input) || [];
|
|
92
|
+
assert(bytes, "Invalid hex string");
|
|
93
|
+
return `0x${bytes}`;
|
|
94
|
+
};
|
|
95
|
+
function reverseBytes(input) {
|
|
96
|
+
const reversed = bytesToHex(hexToBytes(addPrefix(input)).reverse());
|
|
97
|
+
return input.startsWith("0x") ? reversed : reversed.slice(2);
|
|
98
|
+
}
|
|
91
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
92
100
|
0 && (module.exports = {
|
|
93
101
|
bytesToHex,
|
package/dist/bytes.d.cts
CHANGED
|
@@ -4,6 +4,7 @@ declare const bytesToHex: (input: Uint8Array | number[]) => `0x${string}`;
|
|
|
4
4
|
declare const hexToBytes: (input: HexString) => Uint8Array;
|
|
5
5
|
declare const encodeBytesWithCharset: (bytes: Uint8Array | number[], charset: string) => string;
|
|
6
6
|
declare const decodeBytesWithCharset: (input: string, charset: string) => Uint8Array;
|
|
7
|
-
declare
|
|
7
|
+
declare function reverseBytes(input: HexString): HexString;
|
|
8
|
+
declare function reverseBytes(input: string): string;
|
|
8
9
|
|
|
9
10
|
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes, reverseBytes };
|
package/dist/bytes.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const bytesToHex: (input: Uint8Array | number[]) => `0x${string}`;
|
|
|
4
4
|
declare const hexToBytes: (input: HexString) => Uint8Array;
|
|
5
5
|
declare const encodeBytesWithCharset: (bytes: Uint8Array | number[], charset: string) => string;
|
|
6
6
|
declare const decodeBytesWithCharset: (input: string, charset: string) => Uint8Array;
|
|
7
|
-
declare
|
|
7
|
+
declare function reverseBytes(input: HexString): HexString;
|
|
8
|
+
declare function reverseBytes(input: string): string;
|
|
8
9
|
|
|
9
10
|
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes, reverseBytes };
|
package/dist/bytes.js
CHANGED
|
@@ -44,7 +44,15 @@ var decodeBytesWithCharset = (input, charset) => {
|
|
|
44
44
|
const bytes = input.split("").map((char) => charMap[char]);
|
|
45
45
|
return new Uint8Array(convertBase(bytes, charset.length, 256));
|
|
46
46
|
};
|
|
47
|
-
var
|
|
47
|
+
var addPrefix = (input) => {
|
|
48
|
+
const [, bytes] = /^(?:0x)?([a-f\d]*)$/i.exec(input) || [];
|
|
49
|
+
assert(bytes, "Invalid hex string");
|
|
50
|
+
return `0x${bytes}`;
|
|
51
|
+
};
|
|
52
|
+
function reverseBytes(input) {
|
|
53
|
+
const reversed = bytesToHex(hexToBytes(addPrefix(input)).reverse());
|
|
54
|
+
return input.startsWith("0x") ? reversed : reversed.slice(2);
|
|
55
|
+
}
|
|
48
56
|
|
|
49
57
|
export {
|
|
50
58
|
bytesToHex,
|
package/dist/math.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math.ts
|
|
21
|
+
var math_exports = {};
|
|
22
|
+
__export(math_exports, {
|
|
23
|
+
average: () => average,
|
|
24
|
+
sum: () => sum
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(math_exports);
|
|
27
|
+
var sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
28
|
+
var average = (arr) => sum(arr) / arr.length;
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
average,
|
|
32
|
+
sum
|
|
33
|
+
});
|
package/dist/math.d.cts
ADDED
package/dist/math.d.ts
ADDED
package/dist/math.js
ADDED
package/dist/ss58.js
CHANGED