UNPKG

@bigmi/core

Version:

TypeScript library for Bitcoin apps.

34 lines 1.1 kB
export function hexToBase64(hex) { const raw = hex .match(/.{1,2}/g) .map((byte) => String.fromCharCode(Number.parseInt(byte, 16))) .join(''); return btoa(raw); } export function base64ToHex(base64) { const raw = atob(base64); let hex = ''; for (let i = 0; i < raw.length; i++) { const hexByte = raw.charCodeAt(i).toString(16); hex += hexByte.length === 2 ? hexByte : `0${hexByte}`; } return hex; } export function base64urlEncode(str) { const bytes = new TextEncoder().encode(str); const encodedString = btoa(String.fromCharCode(...bytes)); return encodedString .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, ''); } export function stringToHex(value) { const hex = Array.from(value) .map((char) => char.charCodeAt(0).toString(16).padStart(2, '0')) .join(''); return `0x${hex}`; } export function hexToUnit8Array(value) { return new Uint8Array(value.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []); } //# sourceMappingURL=converter.js.map