// Copyright Abridged, Inc. 2021,2024. All Rights Reserved. // Node module: @collabland/common // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT import bs58 from 'bs58'; const {decode, decodeUnsafe, encode} = bs58; /** * Encode the data with BS58 * @param data - Data to be encoded * @returns */ export function bs58Encode( data: Buffer | number[] | Uint8Array | string, ): string { if (typeof data === 'string') { data = Buffer.from(data, 'utf-8'); } return encode(data); } /** * Decode BS58 string * @param data - BS58 encoded string * @returns */ export function bs58Decode(data: string) { return decode(data); } /** * Check if a string is BS58 encoded * @param data - A string is possibly BS58 encoded * @returns */ export function isBS58Encoded(data: string) { return decodeUnsafe(data) != null; } export function baseEncode(value: Uint8Array | string): string { if (typeof value === 'string') { value = Buffer.from(value, 'utf8'); } return encode(Buffer.from(value)); } export function baseDecode(value: string): Buffer { return Buffer.from(decode(value)); }