@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 CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  decode,
3
3
  encode
4
- } from "./chunk-O4WBUIAN.js";
5
- import "./chunk-4RHM5374.js";
4
+ } from "./chunk-UPA7KLTI.js";
5
+ import "./chunk-D7RIA7SA.js";
6
6
  import "./chunk-MYP3UYWE.js";
7
7
  import "./chunk-CZNX6EUV.js";
8
8
  export {
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
- } from "./chunk-4RHM5374.js";
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
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  decodeBytesWithCharset,
3
3
  encodeBytesWithCharset
4
- } from "./chunk-4RHM5374.js";
4
+ } from "./chunk-D7RIA7SA.js";
5
5
 
6
6
  // src/base58.ts
7
7
  var charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
package/dist/ss58.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  decode,
3
3
  encode
4
- } from "./chunk-O4WBUIAN.js";
4
+ } from "./chunk-UPA7KLTI.js";
5
5
  import {
6
6
  hexToBytes
7
- } from "./chunk-4RHM5374.js";
7
+ } from "./chunk-D7RIA7SA.js";
8
8
  import {
9
9
  assert
10
10
  } from "./chunk-MYP3UYWE.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "0.1.5",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",