diff --git a/.eslintrc.js b/.eslintrc.js index 8d4d63e4..47d33768 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -240,7 +240,7 @@ module.exports = { }, }, { - files: ['e2e/cjs/**'], + files: ['e2e/**'], rules: { 'no-restricted-globals': 'off', }, diff --git a/e2e/cjs/tests/wasm.js b/e2e/cjs/tests/wasm.js new file mode 100644 index 00000000..8171f182 --- /dev/null +++ b/e2e/cjs/tests/wasm.js @@ -0,0 +1,27 @@ +const wasm = require('@mtcute/wasm') +const { describe, it, before } = require('mocha') +const { expect } = require('chai') + +before(() => wasm.initAsync()) + +describe('@mtcute/wasm', () => { + const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex') + const iv = Buffer.from('6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353', 'hex') + + const data = Buffer.from('99706487a1cde613bc6de0b6f24b1c7aa448c8b9c3403e3467a8cad89340f53b', 'hex') + const dataEnc = Buffer.from('792ea8ae577b1a66cb3bd92679b8030ca54ee631976bd3a04547fdcb4639fa69', 'hex') + + it('should work with Buffers', () => { + expect(wasm.ige256Encrypt(data, key, iv)).to.deep.equal(new Uint8Array(dataEnc)) + expect(wasm.ige256Decrypt(dataEnc, key, iv)).to.deep.equal(new Uint8Array(data)) + }) + + it('should work with Uint8Arrays', () => { + expect(wasm.ige256Encrypt(new Uint8Array(data), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal( + new Uint8Array(dataEnc), + ) + expect(wasm.ige256Decrypt(new Uint8Array(dataEnc), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal( + new Uint8Array(data), + ) + }) +}) diff --git a/e2e/esm/tests/wasm.js b/e2e/esm/tests/wasm.js new file mode 100644 index 00000000..acd40735 --- /dev/null +++ b/e2e/esm/tests/wasm.js @@ -0,0 +1,28 @@ +import { expect } from 'chai' +import { before, describe, it } from 'mocha' + +import { ige256Decrypt, ige256Encrypt, initAsync } from '@mtcute/wasm' + +before(() => initAsync()) + +describe('@mtcute/wasm', () => { + const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex') + const iv = Buffer.from('6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353', 'hex') + + const data = Buffer.from('99706487a1cde613bc6de0b6f24b1c7aa448c8b9c3403e3467a8cad89340f53b', 'hex') + const dataEnc = Buffer.from('792ea8ae577b1a66cb3bd92679b8030ca54ee631976bd3a04547fdcb4639fa69', 'hex') + + it('should work with Buffers', () => { + expect(ige256Encrypt(data, key, iv)).to.deep.equal(new Uint8Array(dataEnc)) + expect(ige256Decrypt(dataEnc, key, iv)).to.deep.equal(new Uint8Array(data)) + }) + + it('should work with Uint8Arrays', () => { + expect(ige256Encrypt(new Uint8Array(data), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal( + new Uint8Array(dataEnc), + ) + expect(ige256Decrypt(new Uint8Array(dataEnc), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal( + new Uint8Array(data), + ) + }) +}) diff --git a/e2e/ts/tests/wasm.ts b/e2e/ts/tests/wasm.ts new file mode 100644 index 00000000..acd40735 --- /dev/null +++ b/e2e/ts/tests/wasm.ts @@ -0,0 +1,28 @@ +import { expect } from 'chai' +import { before, describe, it } from 'mocha' + +import { ige256Decrypt, ige256Encrypt, initAsync } from '@mtcute/wasm' + +before(() => initAsync()) + +describe('@mtcute/wasm', () => { + const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex') + const iv = Buffer.from('6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353', 'hex') + + const data = Buffer.from('99706487a1cde613bc6de0b6f24b1c7aa448c8b9c3403e3467a8cad89340f53b', 'hex') + const dataEnc = Buffer.from('792ea8ae577b1a66cb3bd92679b8030ca54ee631976bd3a04547fdcb4639fa69', 'hex') + + it('should work with Buffers', () => { + expect(ige256Encrypt(data, key, iv)).to.deep.equal(new Uint8Array(dataEnc)) + expect(ige256Decrypt(dataEnc, key, iv)).to.deep.equal(new Uint8Array(data)) + }) + + it('should work with Uint8Arrays', () => { + expect(ige256Encrypt(new Uint8Array(data), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal( + new Uint8Array(dataEnc), + ) + expect(ige256Decrypt(new Uint8Array(dataEnc), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal( + new Uint8Array(data), + ) + }) +})