uuid-to-bytes32
Version:
Convert uuid to bytes32
22 lines (19 loc) • 872 B
JavaScript
import { ethers } from 'ethers';
import { Buffer } from 'buffer';
function uuidToBytes32(uuid) {
// Remove hyphens and convert to a byte array
var hexString = uuid.replace(/-/g, '');
var encodeBase64 = ethers.encodeBase64(Buffer.from(hexString, 'hex'));
return ethers.encodeBytes32String(encodeBase64);
}
function bytes32ToUuid(bytes32) {
var decodeBase64 = ethers.decodeBytes32String(bytes32);
var byteArray = ethers.decodeBase64(decodeBase64);
// Convert the byte array to a hex string
var hexString = Buffer.from(byteArray).toString('hex');
// Insert hyphens to match the UUID format
var uuid = hexString.slice(0, 8) + "-" + hexString.slice(8, 12) + "-" + hexString.slice(12, 16) + "-" + hexString.slice(16, 20) + "-" + hexString.slice(20);
return uuid;
}
export { bytes32ToUuid, uuidToBytes32 };
//# sourceMappingURL=uuid-to-bytes32.esm.js.map