mtcute/packages/core/tests/auth-key.spec.ts
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* 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???
2023-10-16 19:23:53 +03:00

53 lines
1.7 KiB
TypeScript

/* eslint-disable no-restricted-globals */
import chai, { expect } from 'chai'
import spies from 'chai-spies'
import { describe, it } from 'mocha'
import { TlReaderMap } from '@mtcute/tl-runtime'
import { AuthKey } from '../src/network/auth-key.js'
import { NodeCryptoProvider } from '../src/utils/crypto/node-crypto.js'
import { LogManager } from '../src/utils/index.js'
chai.use(spies)
const authKey = Buffer.alloc(
2048 / 8,
Buffer.from('98cb29c6ffa89e79da695a54f572e6cb101e81c688b63a4bf73c3622dec230e0', 'hex'),
)
describe('AuthKey', () => {
const crypto = new NodeCryptoProvider()
const logger = new LogManager()
const readerMap: TlReaderMap = {}
it('should correctly calculate derivatives', async () => {
const key = new AuthKey(crypto, logger, readerMap)
await key.setup(authKey)
expect(key.key).to.eql(authKey)
expect(key.clientSalt).to.eql(
Buffer.from('f73c3622dec230e098cb29c6ffa89e79da695a54f572e6cb101e81c688b63a4b', 'hex'),
)
expect(key.serverSalt).to.eql(
Buffer.from('98cb29c6ffa89e79da695a54f572e6cb101e81c688b63a4bf73c3622dec230e0', 'hex'),
)
expect(key.id).to.eql(Buffer.from('40fa5bb7cb56a895', 'hex'))
})
// todo - need predictable random bytes
// it('should correctly encrypt a message', async () => {
// const crypto = new NodeCryptoProvider()
// const key = new AuthKey(crypto, logger, readerMap)
// await key.setup(authKey)
//
// const msg = await key.encryptMessage(message, serverSalt, sessionId)
//
// expect(msg).to.eql(
// Buffer.from(
// '...',
// 'hex',
// ),
// )
// })
})