Files
securebit-chat/node_modules/qrcode/lib/core/reed-solomon-encoder.js
lockbitchat 0f8399ec88 feat(security,ui): self-host React deps, Tailwind, fonts; strict CSP; local QR; better selection state
Replace CDN React/ReactDOM/Babel with local libs; remove Babel and inline scripts
Build Tailwind locally, add safelist; switch to assets/tailwind.css
Self-host Font Awesome and Inter (CSS + woff2); remove external font CDNs
Implement strict CSP (no unsafe-inline/eval; scripts/styles/fonts from self)
Extract inline handlers; move PWA scripts to external files
Add local QR code generation (qrcode lib) and remove api.qrserver.com
Improve SessionTypeSelector visual selection (highlighted background and ring)
Keep PWA working with service worker and offline assets
Refs: CSP hardening, offline-first, no external dependencies
2025-09-08 16:04:58 -04:00

57 lines
1.6 KiB
JavaScript

const Polynomial = require('./polynomial')
function ReedSolomonEncoder (degree) {
this.genPoly = undefined
this.degree = degree
if (this.degree) this.initialize(this.degree)
}
/**
* Initialize the encoder.
* The input param should correspond to the number of error correction codewords.
*
* @param {Number} degree
*/
ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
// create an irreducible generator polynomial
this.degree = degree
this.genPoly = Polynomial.generateECPolynomial(this.degree)
}
/**
* Encodes a chunk of data
*
* @param {Uint8Array} data Buffer containing input data
* @return {Uint8Array} Buffer containing encoded data
*/
ReedSolomonEncoder.prototype.encode = function encode (data) {
if (!this.genPoly) {
throw new Error('Encoder not initialized')
}
// Calculate EC for this data block
// extends data size to data+genPoly size
const paddedData = new Uint8Array(data.length + this.degree)
paddedData.set(data)
// The error correction codewords are the remainder after dividing the data codewords
// by a generator polynomial
const remainder = Polynomial.mod(paddedData, this.genPoly)
// return EC data blocks (last n byte, where n is the degree of genPoly)
// If coefficients number in remainder are less than genPoly degree,
// pad with 0s to the left to reach the needed number of coefficients
const start = this.degree - remainder.length
if (start > 0) {
const buff = new Uint8Array(this.degree)
buff.set(remainder, start)
return buff
}
return remainder
}
module.exports = ReedSolomonEncoder