UNPKG

@ton/core

Version:

Core TypeScript library that implements low level primitives for TON blockchain.

32 lines (31 loc) 1.05 kB
"use strict"; /** * Copyright (c) Whales Corp. * All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.crc32c = void 0; const POLY = 0x82f63b78; function crc32c(source) { let crc = 0 ^ 0xffffffff; for (let n = 0; n < source.length; n++) { crc ^= source[n]; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1; } crc = crc ^ 0xffffffff; // Convert endianness let res = Buffer.alloc(4); res.writeInt32LE(crc); return res; } exports.crc32c = crc32c;