Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function calculateChecksum(payload) {
// This code calculates CRC16-XModem checksum of payload
// and returns it as Buffer in little-endian order.
const checksum = new Buffer(2);
checksum.writeUInt16LE(crc16xmodem(payload), 0);
return checksum;
}
export function encodeEd25519PublicKey(rawPublicKey: Buffer): string {
let versionByte = 6 << 3; // 'G'
let data = Buffer.from(rawPublicKey);
let versionBuffer = Buffer.from([versionByte]);
let payload = Buffer.concat([versionBuffer, data]);
let checksum = Buffer.alloc(2);
checksum.writeUInt16LE(crc16xmodem(payload), 0);
let unencoded = Buffer.concat([payload, checksum]);
return base32.encode(unencoded);
}