@layerzerolabs/common-encoding-utils 0.2.64 → 0.2.66

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/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './byte-codec';
2
+
1
3
  export type HexString = `0x${string}`;
2
4
 
3
5
  const base58regex = /^[A-HJ-NP-Za-km-z1-9]*$/;
@@ -94,7 +96,9 @@ export function hexToBytes(hex: string): Uint8Array {
94
96
  }
95
97
 
96
98
  export function bytesToHex(bytes: Uint8Array | ArrayBuffer): string {
97
- return Buffer.from(bytes).toString('hex');
99
+ return Buffer.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes).toString(
100
+ 'hex',
101
+ );
98
102
  }
99
103
 
100
104
  /**
@@ -106,7 +110,13 @@ export function bytesToHexPrefixed(bytes: Uint8Array | ArrayBuffer): HexString {
106
110
  }
107
111
 
108
112
  export function bytesToBase64(bytes: Uint8Array | ArrayBuffer): string {
109
- return Buffer.from(bytes).toString('base64');
113
+ return Buffer.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes).toString(
114
+ 'base64',
115
+ );
116
+ }
117
+
118
+ export function base64ToBytes(base64: string): Uint8Array {
119
+ return Uint8Array.from(Buffer.from(base64, 'base64'));
110
120
  }
111
121
 
112
122
  export function hexToBase64(hexString: string): string {