

const require_base58 = require('./base58.js');

//#region src/utils/MultiBaseEncoder.ts
const multibaseEncodingMap = { base58btc: (data) => `z${require_base58.encodeToBase58(data)}` };
const multibaseDecodingMap = { z: (data) => ({
	data: require_base58.decodeFromBase58(data.substring(1)),
	baseName: "base58btc"
}) };
var MultiBaseEncoder = class MultiBaseEncoder {
	/**
	*
	* Encodes a buffer into a multibase
	*
	* @param buffer the buffer that has to be encoded
	* @param baseName the encoding algorithm
	*/
	static encode(buffer, baseName) {
		const encode = multibaseEncodingMap[baseName];
		if (!encode) throw new Error(`Unsupported encoding '${baseName}'`);
		return encode(buffer);
	}
	/**
	*
	* Decodes a multibase into a Uint8Array
	*
	* @param data the multibase that has to be decoded
	*
	* @returns decoded data and the multi base name
	*/
	static decode(data) {
		const prefix = data[0];
		const decode = multibaseDecodingMap[prefix];
		if (!decode) throw new Error(`No decoder found for multibase prefix '${prefix}'`);
		return decode(data);
	}
	static isValid(data) {
		try {
			MultiBaseEncoder.decode(data);
			return true;
		} catch (_error) {
			return false;
		}
	}
};

//#endregion
exports.MultiBaseEncoder = MultiBaseEncoder;