@chainflip/utils 0.2.0 → 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-F5VHSRYQ.js";
5
- import "./chunk-34J3OMUQ.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
@@ -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 reverseBytes = (input) => bytesToHex(hexToBytes(input).reverse());
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 const reverseBytes: (input: HexString) => HexString;
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 const reverseBytes: (input: HexString) => HexString;
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
@@ -4,7 +4,7 @@ import {
4
4
  encodeBytesWithCharset,
5
5
  hexToBytes,
6
6
  reverseBytes
7
- } from "./chunk-34J3OMUQ.js";
7
+ } from "./chunk-D7RIA7SA.js";
8
8
  import "./chunk-MYP3UYWE.js";
9
9
  import "./chunk-CZNX6EUV.js";
10
10
  export {
@@ -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 reverseBytes = (input) => bytesToHex(hexToBytes(input).reverse());
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,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  decodeBytesWithCharset,
3
3
  encodeBytesWithCharset
4
- } from "./chunk-34J3OMUQ.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-F5VHSRYQ.js";
4
+ } from "./chunk-UPA7KLTI.js";
5
5
  import {
6
6
  hexToBytes
7
- } from "./chunk-34J3OMUQ.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.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",