Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private emitPhysicalRecord = async (
record: Buffer,
type: RecordType
): Promise => {
const head = Buffer.alloc(kHeaderSize)
const length = record.length
head[4] = length & 0xff
head[5] = length >> 8
head[6] = type
const crc = crc32(
Buffer.concat([Buffer.from([type]), record, Buffer.from([record.length])])
)
head.fill(crc, 0, 4)
this._blockOffset += record.length + kHeaderSize
await this.appendFile(Buffer.concat([head, record]))
}
async writeRawBlock(
blockContent: Slice,
type: CompressionTypes,
handle: BlockHandle
): Promise {
handle.offset = this._offset
handle.size = blockContent.size
await this.appendFile(blockContent.buffer)
const trailer = Buffer.alloc(kBlockTrailerSize)
trailer[0] = type
const crc32buffer = crc32(
Buffer.concat([blockContent.buffer, Buffer.from([type])])
)
trailer.fill(crc32buffer, 1, 5)
await this.appendFile(trailer)
this._offset += blockContent.size + kBlockTrailerSize
}
get buffer(): Buffer {
const lengthBuf = Buffer.from(
createHexStringFromDecimal(this.data.length),
'hex'
)
const typeBuf = Buffer.from([this.type])
const sum = crc32(Buffer.concat([typeBuf, this.data.buffer]))
return Buffer.concat([sum, lengthBuf, typeBuf, this.data.buffer])
}
}
export default function decodeMappings ( mappings ) {
let checksum = crc32( mappings );
if ( !cache[ checksum ] ) {
cache[ checksum ] = decode( mappings );
}
return cache[ checksum ];
}
export function createAccountPlate(accountPubHash: string): WalletAccountNumberPlate {
const hash = blakejs.blake2bHex(accountPubHash);
const [a, b, c, d] = crc32(hash);
const alpha = `ABCDEJHKLNOPSTXZ`;
const letters = x => `${alpha[Math.floor(x / 16)]}${alpha[x % 16]}`;
const numbers = `${((c << 8) + d) % 10000}`.padStart(4, '0');
const id = `${letters(a)}${letters(b)}-${numbers}`;
return { hash, id };
}