@chainflip/utils 0.1.5 → 0.2.1
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 +13 -2
- package/dist/bytes.d.cts +3 -1
- package/dist/bytes.d.ts +3 -1
- package/dist/bytes.js +5 -3
- package/dist/{chunk-4RHM5374.js → chunk-D7RIA7SA.js} +11 -1
- package/dist/{chunk-O4WBUIAN.js → chunk-UPA7KLTI.js} +1 -1
- package/dist/ss58.js +2 -2
- package/package.json +1 -1
package/dist/base58.js
CHANGED
package/dist/bytes.cjs
CHANGED
|
@@ -23,7 +23,8 @@ __export(bytes_exports, {
|
|
|
23
23
|
bytesToHex: () => bytesToHex,
|
|
24
24
|
decodeBytesWithCharset: () => decodeBytesWithCharset,
|
|
25
25
|
encodeBytesWithCharset: () => encodeBytesWithCharset,
|
|
26
|
-
hexToBytes: () => hexToBytes
|
|
26
|
+
hexToBytes: () => hexToBytes,
|
|
27
|
+
reverseBytes: () => reverseBytes
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(bytes_exports);
|
|
29
30
|
|
|
@@ -86,10 +87,20 @@ var decodeBytesWithCharset = (input, charset) => {
|
|
|
86
87
|
const bytes = input.split("").map((char) => charMap[char]);
|
|
87
88
|
return new Uint8Array(convertBase(bytes, charset.length, 256));
|
|
88
89
|
};
|
|
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
|
+
}
|
|
89
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
100
|
0 && (module.exports = {
|
|
91
101
|
bytesToHex,
|
|
92
102
|
decodeBytesWithCharset,
|
|
93
103
|
encodeBytesWithCharset,
|
|
94
|
-
hexToBytes
|
|
104
|
+
hexToBytes,
|
|
105
|
+
reverseBytes
|
|
95
106
|
});
|
package/dist/bytes.d.cts
CHANGED
|
@@ -4,5 +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 function reverseBytes(input: HexString): HexString;
|
|
8
|
+
declare function reverseBytes(input: string): string;
|
|
7
9
|
|
|
8
|
-
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes };
|
|
10
|
+
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes, reverseBytes };
|
package/dist/bytes.d.ts
CHANGED
|
@@ -4,5 +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 function reverseBytes(input: HexString): HexString;
|
|
8
|
+
declare function reverseBytes(input: string): string;
|
|
7
9
|
|
|
8
|
-
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes };
|
|
10
|
+
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes, reverseBytes };
|
package/dist/bytes.js
CHANGED
|
@@ -2,13 +2,15 @@ import {
|
|
|
2
2
|
bytesToHex,
|
|
3
3
|
decodeBytesWithCharset,
|
|
4
4
|
encodeBytesWithCharset,
|
|
5
|
-
hexToBytes
|
|
6
|
-
|
|
5
|
+
hexToBytes,
|
|
6
|
+
reverseBytes
|
|
7
|
+
} from "./chunk-D7RIA7SA.js";
|
|
7
8
|
import "./chunk-MYP3UYWE.js";
|
|
8
9
|
import "./chunk-CZNX6EUV.js";
|
|
9
10
|
export {
|
|
10
11
|
bytesToHex,
|
|
11
12
|
decodeBytesWithCharset,
|
|
12
13
|
encodeBytesWithCharset,
|
|
13
|
-
hexToBytes
|
|
14
|
+
hexToBytes,
|
|
15
|
+
reverseBytes
|
|
14
16
|
};
|
|
@@ -44,10 +44,20 @@ 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 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
|
+
}
|
|
47
56
|
|
|
48
57
|
export {
|
|
49
58
|
bytesToHex,
|
|
50
59
|
hexToBytes,
|
|
51
60
|
encodeBytesWithCharset,
|
|
52
|
-
decodeBytesWithCharset
|
|
61
|
+
decodeBytesWithCharset,
|
|
62
|
+
reverseBytes
|
|
53
63
|
};
|
package/dist/ss58.js
CHANGED