implemented frontend including separate message system; started to implement backend

This commit is contained in:
User
2026-03-10 14:48:48 +01:00
committed by Jannik Luboeinski
parent 4275cbd795
commit 78d5352a48
1058 changed files with 101527 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
/**
* This is a GF2 Polynomial abstraction that is not meant for production!
*
* It is easy to understand and it's correctness is as obvious as possible. It can be used to verify
* efficient implementations of algorithms on GF2.
*/
export class GF2Polynomial {
/**
* @type {Set<number>}
*/
degrees: Set<number>;
}
export function createFromBytes(bytes: Uint8Array): GF2Polynomial;
export function toUint8Array(p: GF2Polynomial, byteLength?: number): Uint8Array<ArrayBuffer>;
export function createFromUint(uint: number): GF2Polynomial;
export function createRandom(degree: number): GF2Polynomial;
export function getHighestDegree(p: GF2Polynomial): number;
export function addInto(p1: GF2Polynomial, p2: GF2Polynomial): void;
export function orInto(p1: GF2Polynomial, p2: GF2Polynomial): void;
export function add(p1: GF2Polynomial, p2: GF2Polynomial): GF2Polynomial;
export function clone(p: GF2Polynomial): GF2Polynomial;
export function addDegreeInto(p: GF2Polynomial, degree: number): void;
export function multiply(p1: GF2Polynomial, p2: GF2Polynomial): GF2Polynomial;
export function shiftLeft(p: GF2Polynomial, shift: number): GF2Polynomial;
export function mod(p1: GF2Polynomial, p2: GF2Polynomial): GF2Polynomial;
export function modPow(p: GF2Polynomial, e: number, m: GF2Polynomial): GF2Polynomial;
export function gcd(p1: GF2Polynomial, p2: GF2Polynomial): GF2Polynomial;
export function equals(p1: GF2Polynomial, p2: GF2Polynomial): boolean;
export function isIrreducibleBenOr(p: GF2Polynomial): boolean;
export function createIrreducible(degree: number): GF2Polynomial;
export function fingerprint(buf: Uint8Array, m: GF2Polynomial): Uint8Array<ArrayBuffer>;
export class RabinPolynomialEncoder {
/**
* @param {GF2Polynomial} m The irreducible polynomial
*/
constructor(m: GF2Polynomial);
fingerprint: GF2Polynomial;
m: GF2Polynomial;
/**
* @param {number} b
*/
write(b: number): void;
getFingerprint(): Uint8Array<ArrayBuffer>;
}
//# sourceMappingURL=rabin-gf2-polynomial.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rabin-gf2-polynomial.d.ts","sourceRoot":"","sources":["rabin-gf2-polynomial.js"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH;IAEI;;QAEI;IACJ,SAFW,GAAG,CAAC,MAAM,CAAC,CAEE;CAE3B;AAOM,uCAFI,UAAU,iBAcpB;AAQM,gCAHI,aAAa,eACb,MAAM,2BAahB;AAOM,qCAFI,MAAM,iBAQhB;AAOM,qCAFI,MAAM,iBAYhB;AAMM,oCAHI,aAAa,UAG2D;AAU5E,4BAHI,aAAa,MACb,aAAa,QAUvB;AAUM,2BAHI,aAAa,MACb,aAAa,QAMvB;AAUM,wBAHI,aAAa,MACb,aAAa,iBAevB;AASM,yBAFI,aAAa,iBAMvB;AAUM,iCAHI,aAAa,UACb,MAAM,QAQhB;AAQM,6BAHI,aAAa,MACb,aAAa,iBAUvB;AAQM,6BAHI,aAAa,SACb,MAAM,iBAShB;AAQM,wBAHI,aAAa,MACb,aAAa,iBAavB;AAWM,0BAJI,aAAa,KACb,MAAM,KACN,aAAa,iBAcvB;AAQM,wBAHI,aAAa,MACb,aAAa,iBASvB;AAQM,2BAHI,aAAa,MACb,aAAa,WAQvB;AAgCM,sCAFI,aAAa,WAYvB;AAKM,0CAFI,MAAM,iBAOhB;AAQM,iCAHI,UAAU,KACV,aAAa,2BAE0G;AAElI;IACE;;OAEG;IACH,eAFW,aAAa,EAKvB;IAFC,2BAAsC;IACtC,iBAAU;IAGZ;;OAEG;IACH,SAFW,MAAM,QAOhB;IAED,0CAEC;CACF"}

379
yjs-poll/node_modules/lib0/hash/rabin-gf2-polynomial.js generated vendored Normal file
View File

@@ -0,0 +1,379 @@
/**
* The idea of the Rabin fingerprint algorithm is to represent the binary as a polynomial in a
* finite field (Galois Field G(2)). The polynomial will then be taken "modulo" by an irreducible
* polynomial of the desired size.
*
* This implementation is inefficient and is solely used to verify the actually performant
* implementation in `./rabin.js`.
*
* @module rabin-gf2-polynomial
*/
import * as math from '../math.js'
import * as webcrypto from 'lib0/webcrypto'
import * as array from '../array.js'
import * as buffer from '../buffer.js'
/**
* @param {number} degree
*/
const _degreeToMinByteLength = degree => math.floor(degree / 8) + 1
/**
* This is a GF2 Polynomial abstraction that is not meant for production!
*
* It is easy to understand and it's correctness is as obvious as possible. It can be used to verify
* efficient implementations of algorithms on GF2.
*/
export class GF2Polynomial {
constructor () {
/**
* @type {Set<number>}
*/
this.degrees = new Set()
}
}
/**
* From Uint8Array (MSB).
*
* @param {Uint8Array} bytes
*/
export const createFromBytes = bytes => {
const p = new GF2Polynomial()
for (let bsi = bytes.length - 1, currDegree = 0; bsi >= 0; bsi--) {
const currByte = bytes[bsi]
for (let i = 0; i < 8; i++) {
if (((currByte >>> i) & 1) === 1) {
p.degrees.add(currDegree)
}
currDegree++
}
}
return p
}
/**
* Transform to Uint8Array (MSB).
*
* @param {GF2Polynomial} p
* @param {number} byteLength
*/
export const toUint8Array = (p, byteLength = _degreeToMinByteLength(getHighestDegree(p))) => {
const buf = buffer.createUint8ArrayFromLen(byteLength)
/**
* @param {number} i
*/
const setBit = i => {
const bi = math.floor(i / 8)
buf[buf.length - 1 - bi] |= (1 << (i % 8))
}
p.degrees.forEach(setBit)
return buf
}
/**
* Create from unsigned integer (max 32bit uint) - read most-significant-byte first.
*
* @param {number} uint
*/
export const createFromUint = uint => {
const buf = new Uint8Array(4)
for (let i = 0; i < 4; i++) {
buf[i] = uint >>> 8 * (3 - i)
}
return createFromBytes(buf)
}
/**
* Create a random polynomial of a specified degree.
*
* @param {number} degree
*/
export const createRandom = degree => {
const bs = new Uint8Array(_degreeToMinByteLength(degree))
webcrypto.getRandomValues(bs)
// Get first byte and explicitly set the bit of "degree" to 1 (the result must have the specified
// degree).
const firstByte = bs[0] | 1 << (degree % 8)
// Find out how many bits of the first byte need to be filled with zeros because they are >degree.
const zeros = 7 - (degree % 8)
bs[0] = ((firstByte << zeros) & 0xff) >>> zeros
return createFromBytes(bs)
}
/**
* @param {GF2Polynomial} p
* @return number
*/
export const getHighestDegree = p => array.fold(array.from(p.degrees), 0, math.max)
/**
* Add (+) p2 int the p1 polynomial.
*
* Addition is defined as xor in F2. Substraction is equivalent to addition in F2.
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const addInto = (p1, p2) => {
p2.degrees.forEach(degree => {
if (p1.degrees.has(degree)) {
p1.degrees.delete(degree)
} else {
p1.degrees.add(degree)
}
})
}
/**
* Or (|) p2 into the p1 polynomial.
*
* Addition is defined as xor in F2. Substraction is equivalent to addition in F2.
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const orInto = (p1, p2) => {
p2.degrees.forEach(degree => {
p1.degrees.add(degree)
})
}
/**
* Add (+) p2 to the p1 polynomial.
*
* Addition is defined as xor in F2. Substraction is equivalent to addition in F2.
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const add = (p1, p2) => {
const result = new GF2Polynomial()
p2.degrees.forEach(degree => {
if (!p1.degrees.has(degree)) {
result.degrees.add(degree)
}
})
p1.degrees.forEach(degree => {
if (!p2.degrees.has(degree)) {
result.degrees.add(degree)
}
})
return result
}
/**
* Add (+) p2 to the p1 polynomial.
*
* Addition is defined as xor in F2. Substraction is equivalent to addition in F2.
*
* @param {GF2Polynomial} p
*/
export const clone = (p) => {
const result = new GF2Polynomial()
p.degrees.forEach(d => result.degrees.add(d))
return result
}
/**
* Add (+) p2 to the p1 polynomial.
*
* Addition is defined as xor in F2. Substraction is equivalent to addition in F2.
*
* @param {GF2Polynomial} p
* @param {number} degree
*/
export const addDegreeInto = (p, degree) => {
if (p.degrees.has(degree)) {
p.degrees.delete(degree)
} else {
p.degrees.add(degree)
}
}
/**
* Multiply (•) p1 with p2 and store the result in p1.
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const multiply = (p1, p2) => {
const result = new GF2Polynomial()
p1.degrees.forEach(degree1 => {
p2.degrees.forEach(degree2 => {
addDegreeInto(result, degree1 + degree2)
})
})
return result
}
/**
* Multiply (•) p1 with p2 and store the result in p1.
*
* @param {GF2Polynomial} p
* @param {number} shift
*/
export const shiftLeft = (p, shift) => {
const result = new GF2Polynomial()
p.degrees.forEach(degree => {
const r = degree + shift
r >= 0 && result.degrees.add(r)
})
return result
}
/**
* Computes p1 % p2. I.e. the remainder of p1/p2.
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const mod = (p1, p2) => {
const maxDeg1 = getHighestDegree(p1)
const maxDeg2 = getHighestDegree(p2)
const result = clone(p1)
for (let i = maxDeg1 - maxDeg2; i >= 0; i--) {
if (result.degrees.has(maxDeg2 + i)) {
const shifted = shiftLeft(p2, i)
addInto(result, shifted)
}
}
return result
}
/**
* Computes (p^e mod m).
*
* http://en.wikipedia.org/wiki/Modular_exponentiation
*
* @param {GF2Polynomial} p
* @param {number} e
* @param {GF2Polynomial} m
*/
export const modPow = (p, e, m) => {
let result = ONE
while (true) {
if ((e & 1) === 1) {
result = mod(multiply(result, p), m)
}
e >>>= 1
if (e === 0) {
return result
}
p = mod(multiply(p, p), m)
}
}
/**
* Find the greatest common divisor using Euclid's Algorithm.
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const gcd = (p1, p2) => {
while (p2.degrees.size > 0) {
const modded = mod(p1, p2)
p1 = p2
p2 = modded
}
return p1
}
/**
* true iff p1 equals p2
*
* @param {GF2Polynomial} p1
* @param {GF2Polynomial} p2
*/
export const equals = (p1, p2) => {
if (p1.degrees.size !== p2.degrees.size) return false
for (const d of p1.degrees) {
if (!p2.degrees.has(d)) return false
}
return true
}
const X = createFromBytes(new Uint8Array([2]))
const ONE = createFromBytes(new Uint8Array([1]))
/**
* Computes ( x^(2^p) - x ) mod f
*
* (shamelessly copied from
* https://github.com/opendedup/rabinfingerprint/blob/master/src/org/rabinfingerprint/polynomial/Polynomial.java)
*
* @param {GF2Polynomial} f
* @param {number} p
*/
const reduceExponent = (f, p) => {
// compute (x^q^p mod f)
const q2p = math.pow(2, p)
const x2q2p = modPow(X, q2p, f)
// subtract (x mod f)
return mod(add(x2q2p, X), f)
}
/**
* BenOr Reducibility Test
*
* Tests and Constructions of Irreducible Polynomials over Finite Fields
* (1997) Shuhong Gao, Daniel Panario
*
* http://citeseer.ist.psu.edu/cache/papers/cs/27167/http:zSzzSzwww.math.clemson.eduzSzfacultyzSzGaozSzpaperszSzGP97a.pdf/gao97tests.pdf
*
* @param {GF2Polynomial} p
*/
export const isIrreducibleBenOr = p => {
const degree = getHighestDegree(p)
for (let i = 1; i < degree / 2; i++) {
const b = reduceExponent(p, i)
const g = gcd(p, b)
if (!equals(g, ONE)) {
return false
}
}
return true
}
/**
* @param {number} degree
*/
export const createIrreducible = degree => {
while (true) {
const p = createRandom(degree)
if (isIrreducibleBenOr(p)) return p
}
}
/**
* Create a fingerprint of buf using the irreducible polynomial m.
*
* @param {Uint8Array} buf
* @param {GF2Polynomial} m
*/
export const fingerprint = (buf, m) => toUint8Array(mod(createFromBytes(buf), m), _degreeToMinByteLength(getHighestDegree(m) - 1))
export class RabinPolynomialEncoder {
/**
* @param {GF2Polynomial} m The irreducible polynomial
*/
constructor (m) {
this.fingerprint = new GF2Polynomial()
this.m = m
}
/**
* @param {number} b
*/
write (b) {
const bp = createFromBytes(new Uint8Array([b]))
const fingerprint = shiftLeft(this.fingerprint, 8)
orInto(fingerprint, bp)
this.fingerprint = mod(fingerprint, this.m)
}
getFingerprint () {
return toUint8Array(this.fingerprint, _degreeToMinByteLength(getHighestDegree(this.m) - 1))
}
}

29
yjs-poll/node_modules/lib0/hash/rabin-uncached.d.ts generated vendored Normal file
View File

@@ -0,0 +1,29 @@
export class RabinUncachedEncoder {
/**
* @param {Uint8Array} m assert(m[0] === 1)
*/
constructor(m: Uint8Array);
m: Uint8Array<ArrayBufferLike>;
blen: number;
bs: Uint8Array<ArrayBuffer>;
/**
* This describes the position of the most significant byte (starts with 0 and increases with
* shift)
*/
bpos: number;
/**
* Add/Xor/Substract bytes.
*
* Discards bytes that are out of range.
* @todo put this in function or inline
*
* @param {Uint8Array} cs
*/
add(cs: Uint8Array): void;
/**
* @param {number} byte
*/
write(byte: number): void;
getFingerprint(): Uint8Array<ArrayBuffer>;
}
//# sourceMappingURL=rabin-uncached.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rabin-uncached.d.ts","sourceRoot":"","sources":["rabin-uncached.js"],"names":[],"mappings":"AAUA;IACE;;OAEG;IACH,eAFW,UAAU,EAWpB;IARC,+BAAU;IACV,aAAwB;IACxB,4BAAmC;IACnC;;;OAGG;IACH,aAAa;IAGf;;;;;;;OAOG;IACH,QAFW,UAAU,QAQpB;IAED;;OAEG;IACH,YAFW,MAAM,QAgBhB;IAED,0CAMC;CACF"}

68
yjs-poll/node_modules/lib0/hash/rabin-uncached.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
/**
* It is not recommended to use this package. This is the uncached implementation of the rabin
* fingerprint algorithm. However, it can be used to verify the `rabin.js` implementation.
*
* @module rabin-uncached
*/
import * as math from '../math.js'
import * as buffer from '../buffer.js'
export class RabinUncachedEncoder {
/**
* @param {Uint8Array} m assert(m[0] === 1)
*/
constructor (m) {
this.m = m
this.blen = m.byteLength
this.bs = new Uint8Array(this.blen)
/**
* This describes the position of the most significant byte (starts with 0 and increases with
* shift)
*/
this.bpos = 0
}
/**
* Add/Xor/Substract bytes.
*
* Discards bytes that are out of range.
* @todo put this in function or inline
*
* @param {Uint8Array} cs
*/
add (cs) {
const copyLen = math.min(this.blen, cs.byteLength)
// copy from right to left until max is reached
for (let i = 0; i < copyLen; i++) {
this.bs[(this.bpos + this.blen - i - 1) % this.blen] ^= cs[cs.byteLength - i - 1]
}
}
/**
* @param {number} byte
*/
write (byte) {
// [0,m1,m2,b]
// x <- bpos
// Shift one byte to the left, add b
this.bs[this.bpos] = byte
this.bpos = (this.bpos + 1) % this.blen
// mod
for (let i = 7; i >= 0; i--) {
if (((this.bs[this.bpos] >>> i) & 1) === 1) {
this.add(buffer.shiftNBitsLeft(this.m, i))
}
}
// if (this.bs[this.bpos] !== 0) { error.unexpectedCase() }
// assert(this.bs[this.bpos] === 0)
}
getFingerprint () {
const result = new Uint8Array(this.blen - 1)
for (let i = 0; i < result.byteLength; i++) {
result[i] = this.bs[(this.bpos + i + 1) % this.blen]
}
return result
}
}

27
yjs-poll/node_modules/lib0/hash/rabin.d.ts generated vendored Normal file
View File

@@ -0,0 +1,27 @@
export const StandardIrreducible8: Uint8Array<ArrayBuffer>;
export const StandardIrreducible16: Uint8Array<ArrayBuffer>;
export const StandardIrreducible32: Uint8Array<ArrayBuffer>;
export const StandardIrreducible64: Uint8Array<ArrayBuffer>;
export const StandardIrreducible128: Uint8Array<ArrayBuffer>;
export class RabinEncoder {
/**
* @param {Uint8Array} m assert(m[0] === 1)
*/
constructor(m: Uint8Array);
m: Uint8Array<ArrayBufferLike>;
blen: number;
bs: Uint8Array<ArrayBuffer>;
cache: Uint8Array<ArrayBuffer>;
/**
* This describes the position of the most significant byte (starts with 0 and increases with
* shift)
*/
bpos: number;
/**
* @param {number} byte
*/
write(byte: number): void;
getFingerprint(): Uint8Array<ArrayBuffer>;
}
export function fingerprint(irreducible: Uint8Array, data: Uint8Array): Uint8Array<ArrayBuffer>;
//# sourceMappingURL=rabin.d.ts.map

1
yjs-poll/node_modules/lib0/hash/rabin.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"rabin.d.ts","sourceRoot":"","sources":["rabin.js"],"names":[],"mappings":"AAUA,2DAA4D;AAC5D,4DAAkE;AAClE,4DAA4E;AAC5E,4DAA+F;AAC/F,6DAAmI;AAmCnI;IACE;;OAEG;IACH,eAFW,UAAU,EAYpB;IATC,+BAAU;IACV,aAAwB;IACxB,4BAAmC;IACnC,+BAA2B;IAC3B;;;OAGG;IACH,aAAa;IAGf;;OAEG;IACH,YAFW,MAAM,QAYhB;IAED,0CAMC;CACF;AAMM,yCAHI,UAAU,QACV,UAAU,2BAQpB"}

100
yjs-poll/node_modules/lib0/hash/rabin.js generated vendored Normal file
View File

@@ -0,0 +1,100 @@
/**
* @module rabin
*
* Very efficient & versatile fingerprint/hashing algorithm. However, it is not cryptographically
* secure. Well suited for fingerprinting.
*/
import * as buffer from '../buffer.js'
import * as map from '../map.js'
export const StandardIrreducible8 = new Uint8Array([1, 221])
export const StandardIrreducible16 = new Uint8Array([1, 244, 157])
export const StandardIrreducible32 = new Uint8Array([1, 149, 183, 205, 191])
export const StandardIrreducible64 = new Uint8Array([1, 133, 250, 114, 193, 250, 28, 193, 231])
export const StandardIrreducible128 = new Uint8Array([1, 94, 109, 166, 228, 6, 222, 102, 239, 27, 128, 184, 13, 50, 112, 169, 199])
/**
* Maps from a modulo to the precomputed values.
*
* @type {Map<string,Uint8Array>}
*/
const _precomputedFingerprintCache = new Map()
/**
* @param {Uint8Array} m
*/
const ensureCache = m => map.setIfUndefined(_precomputedFingerprintCache, buffer.toBase64(m), () => {
const byteLen = m.byteLength
const cache = new Uint8Array(256 * byteLen)
// Use dynamic computing to compute the cached results.
// Starting values: cache(0) = 0; cache(1) = m
cache.set(m, byteLen)
for (let bit = 1; bit < 8; bit++) {
const mBitShifted = buffer.shiftNBitsLeft(m, bit)
const bitShifted = 1 << bit
for (let j = 0; j < bitShifted; j++) {
// apply the shifted result (reducing the degree of the polynomial)
const msb = bitShifted | j
const rest = msb ^ mBitShifted[0]
for (let i = 0; i < byteLen; i++) {
// rest is already precomputed in the cache
cache[msb * byteLen + i] = cache[rest * byteLen + i] ^ mBitShifted[i]
}
// if (cache[(bitShifted | j) * byteLen] !== (bitShifted | j)) { error.unexpectedCase() }
}
}
return cache
})
export class RabinEncoder {
/**
* @param {Uint8Array} m assert(m[0] === 1)
*/
constructor (m) {
this.m = m
this.blen = m.byteLength
this.bs = new Uint8Array(this.blen)
this.cache = ensureCache(m)
/**
* This describes the position of the most significant byte (starts with 0 and increases with
* shift)
*/
this.bpos = 0
}
/**
* @param {number} byte
*/
write (byte) {
// assert(this.bs[0] === 0)
// Shift one byte to the left, add b
this.bs[this.bpos] = byte
this.bpos = (this.bpos + 1) % this.blen
const msb = this.bs[this.bpos]
for (let i = 0; i < this.blen; i++) {
this.bs[(this.bpos + i) % this.blen] ^= this.cache[msb * this.blen + i]
}
// assert(this.bs[this.bpos] === 0)
}
getFingerprint () {
const result = new Uint8Array(this.blen - 1)
for (let i = 0; i < result.byteLength; i++) {
result[i] = this.bs[(this.bpos + i + 1) % this.blen]
}
return result
}
}
/**
* @param {Uint8Array} irreducible
* @param {Uint8Array} data
*/
export const fingerprint = (irreducible, data) => {
const encoder = new RabinEncoder(irreducible)
for (let i = 0; i < data.length; i++) {
encoder.write(data[i])
}
return encoder.getFingerprint()
}

8
yjs-poll/node_modules/lib0/hash/rabin.test.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
export function testPolynomialBasics(_tc: t.TestCase): void;
export function testIrreducibleInput(_tc: t.TestCase): void;
export function testIrreducibleSpread(_tc: t.TestCase): void;
export function testGenerateIrreducibles(_tc: t.TestCase): void;
export function testFingerprintCompatiblity(tc: t.TestCase): void;
export function testConflicts(tc: t.TestCase): void;
import * as t from '../testing.js';
//# sourceMappingURL=rabin.test.d.ts.map

1
yjs-poll/node_modules/lib0/hash/rabin.test.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"rabin.test.d.ts","sourceRoot":"","sources":["rabin.test.js"],"names":[],"mappings":"AAaO,0CAFI,CAAC,CAAC,QAAQ,QASpB;AAKM,0CAFI,CAAC,CAAC,QAAQ,QAapB;AAKM,2CAFI,CAAC,CAAC,QAAQ,QASpB;AAwBM,8CAFI,CAAC,CAAC,QAAQ,QAyBpB;AAmGM,gDAFI,CAAC,CAAC,QAAQ,QAQpB;AAKM,kCAFI,CAAC,CAAC,QAAQ,QA4BpB;mBAvOkB,eAAe"}

2
yjs-poll/node_modules/lib0/hash/sha256.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export function digest(data: Uint8Array): Uint8Array<ArrayBuffer>;
//# sourceMappingURL=sha256.d.ts.map

1
yjs-poll/node_modules/lib0/hash/sha256.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["sha256.js"],"names":[],"mappings":"AA+KO,6BAFI,UAAU,2BAEkC"}

176
yjs-poll/node_modules/lib0/hash/sha256.js generated vendored Normal file
View File

@@ -0,0 +1,176 @@
/**
* @module sha256
* Spec: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
* Resources:
* - https://web.archive.org/web/20150315061807/http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf
*/
import * as binary from '../binary.js'
/**
* @param {number} w - a 32bit uint
* @param {number} shift
*/
const rotr = (w, shift) => (w >>> shift) | (w << (32 - shift))
/**
* Helper for SHA-224 & SHA-256. See 4.1.2.
* @param {number} x
*/
const sum0to256 = x => rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22)
/**
* Helper for SHA-224 & SHA-256. See 4.1.2.
* @param {number} x
*/
const sum1to256 = x => rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25)
/**
* Helper for SHA-224 & SHA-256. See 4.1.2.
* @param {number} x
*/
const sigma0to256 = x => rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3
/**
* Helper for SHA-224 & SHA-256. See 4.1.2.
* @param {number} x
*/
const sigma1to256 = x => rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10
// @todo don't init these variables globally
/**
* See 4.2.2: Constant for sha256 & sha224
* These words represent the first thirty-two bits of the fractional parts of
* the cube roots of the first sixty-four prime numbers. In hex, these constant words are (from left to
* right)
*/
const K = new Uint32Array([
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
])
/**
* See 5.3.3. Initial hash value.
*
* These words were obtained by taking the first thirty-two bits of the fractional parts of the
* square roots of the first eight prime numbers.
*
* @todo shouldn't be a global variable
*/
const HINIT = new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
])
// time to beat: (large value < 4.35s)
class Hasher {
constructor () {
const buf = new ArrayBuffer(64 + 64 * 4)
// Init working variables using a single arraybuffer
this._H = new Uint32Array(buf, 0, 8)
this._H.set(HINIT)
// "Message schedule" - a working variable
this._W = new Uint32Array(buf, 64, 64)
}
_updateHash () {
const H = this._H
const W = this._W
for (let t = 16; t < 64; t++) {
W[t] = sigma1to256(W[t - 2]) + W[t - 7] + sigma0to256(W[t - 15]) + W[t - 16]
}
let a = H[0]
let b = H[1]
let c = H[2]
let d = H[3]
let e = H[4]
let f = H[5]
let g = H[6]
let h = H[7]
for (let tt = 0, T1, T2; tt < 64; tt++) {
T1 = (h + sum1to256(e) + ((e & f) ^ (~e & g)) + K[tt] + W[tt]) >>> 0
T2 = (sum0to256(a) + ((a & b) ^ (a & c) ^ (b & c))) >>> 0
h = g
g = f
f = e
e = (d + T1) >>> 0
d = c
c = b
b = a
a = (T1 + T2) >>> 0
}
H[0] += a
H[1] += b
H[2] += c
H[3] += d
H[4] += e
H[5] += f
H[6] += g
H[7] += h
}
/**
* Returns a 32-byte hash.
*
* @param {Uint8Array} data
*/
digest (data) {
let i = 0
for (; i + 56 <= data.length;) {
// write data in big endianess
let j = 0
for (; j < 16 && i + 3 < data.length; j++) {
this._W[j] = data[i++] << 24 | data[i++] << 16 | data[i++] << 8 | data[i++]
}
if (i % 64 !== 0) { // there is still room to write partial content and the ending bit.
this._W.fill(0, j, 16)
while (i < data.length) {
this._W[j] |= data[i] << ((3 - (i % 4)) * 8)
i++
}
this._W[j] |= binary.BIT8 << ((3 - (i % 4)) * 8)
}
this._updateHash()
}
// same check as earlier - the ending bit has been written
const isPaddedWith1 = i % 64 !== 0
this._W.fill(0, 0, 16)
let j = 0
for (; i < data.length; j++) {
for (let ci = 3; ci >= 0 && i < data.length; ci--) {
this._W[j] |= data[i++] << (ci * 8)
}
}
// Write padding of the message. See 5.1.2.
if (!isPaddedWith1) {
this._W[j - (i % 4 === 0 ? 0 : 1)] |= binary.BIT8 << ((3 - (i % 4)) * 8)
}
// write length of message (size in bits) as 64 bit uint
// @todo test that this works correctly
this._W[14] = data.byteLength / binary.BIT30 // same as data.byteLength >>> 30 - but works on floats
this._W[15] = data.byteLength * 8
this._updateHash()
// correct H endianness to use big endiannes and return a Uint8Array
const dv = new Uint8Array(32)
for (let i = 0; i < this._H.length; i++) {
for (let ci = 0; ci < 4; ci++) {
dv[i * 4 + ci] = this._H[i] >>> (3 - ci) * 8
}
}
return dv
}
}
/**
* Returns a 32-byte hash.
*
* @param {Uint8Array} data
*/
export const digest = data => new Hasher().digest(data)

2
yjs-poll/node_modules/lib0/hash/sha256.node.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export function digest(data: Uint8Array): Buffer<ArrayBufferLike>;
//# sourceMappingURL=sha256.node.d.ts.map

1
yjs-poll/node_modules/lib0/hash/sha256.node.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"sha256.node.d.ts","sourceRoot":"","sources":["sha256.node.js"],"names":[],"mappings":"AAKO,6BAFI,UAAU,2BAMpB"}

10
yjs-poll/node_modules/lib0/hash/sha256.node.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import { createHash } from 'node:crypto'
/**
* @param {Uint8Array} data
*/
export const digest = data => {
const hasher = createHash('sha256')
hasher.update(data)
return hasher.digest()
}

7
yjs-poll/node_modules/lib0/hash/sha256.test.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export function testSelfReferencingHash(_tc: t.TestCase): void;
export function testSha256Basics(_tc: t.TestCase): Promise<void>;
export function testLargeValue(_tc: t.TestCase): Promise<void>;
export function testRepeatSha256Hashing(tc: t.TestCase): Promise<void>;
export function testBenchmarkSha256(_tc: t.TestCase): Promise<void>;
import * as t from '../testing.js';
//# sourceMappingURL=sha256.test.d.ts.map

1
yjs-poll/node_modules/lib0/hash/sha256.test.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"sha256.test.d.ts","sourceRoot":"","sources":["sha256.test.js"],"names":[],"mappings":"AAcO,6CAFI,CAAC,CAAC,QAAQ,QAKpB;AAKM,sCAFI,CAAC,CAAC,QAAQ,iBA2BpB;AAOM,oCAFI,CAAC,CAAC,QAAQ,iBA4BpB;AAKM,4CAFI,CAAC,CAAC,QAAQ,iBAQpB;AAKM,yCAFI,CAAC,CAAC,QAAQ,iBAmDpB;mBAjJkB,eAAe"}