f5976a2d74
* feat: moved tl-runtime to esm and native ArrayBuffers * feat: migration to esm * fix(core): web-related fixes * test: finally, some good fucking e2e * chore: fixed linters etc * ci: added e2e to ci * build(tl): fixed gen-code on node 20 * fix: codegen Uint8Array, not Buffer never `git reset --hard` kids * build: only do type-aware linting for `packages/*` * build: ignore no-unresolved in ci for e2e * fix: node 16 doesn't have subtle crypto apparently? * fix(tests): use Uint8Array for gods sake please can i just merge this already * ci: don't parallel tasks in ci because machines are utter garbage and it may just randomly break * ci: pass secrets to e2e tests * ci: separate cli command for ci apparently im retarded * fix: run codegen in e2e im actually retarded * ci: more fixes for e2e * ci: debugging stuff * ci: still debugging * ci: hopefully fix ci???
23 lines
931 B
TypeScript
23 lines
931 B
TypeScript
import { expect } from 'chai'
|
|
import { describe, it } from 'mocha'
|
|
|
|
import { hexDecodeToBuffer, hexEncode } from '@mtcute/tl-runtime'
|
|
|
|
import { factorizePQSync } from '../src/utils/crypto/factorization.js'
|
|
|
|
describe('prime factorization', function () {
|
|
this.timeout(10000) // since PQ factorization relies on RNG, it may take a while (or may not!)
|
|
|
|
it('should decompose PQ to prime factors P and Q', () => {
|
|
const testFactorization = (pq: string, p: string, q: string) => {
|
|
const [p1, q1] = factorizePQSync(hexDecodeToBuffer(pq))
|
|
expect(hexEncode(p1)).eq(p.toLowerCase())
|
|
expect(hexEncode(q1)).eq(q.toLowerCase())
|
|
}
|
|
|
|
// from samples at https://core.telegram.org/mtproto/samples-auth_key
|
|
testFactorization('17ED48941A08F981', '494C553B', '53911073')
|
|
// random example
|
|
testFactorization('14fcab4dfc861f45', '494c5c99', '494c778d')
|
|
})
|
|
})
|