diff --git a/node/src/index.d.ts b/node/src/index.d.ts index cc63aad..e386dad 100644 --- a/node/src/index.d.ts +++ b/node/src/index.d.ts @@ -1,4 +1,4 @@ declare module '@wulkanowy/qr-node' { export function encode(password: string, content: string): string; - // export function decode(password: string, content: string): string; -} \ No newline at end of file + export function decode(password: string, content: string): string; +} diff --git a/node/src/index.js b/node/src/index.js index e236cbb..5a6d2eb 100644 --- a/node/src/index.js +++ b/node/src/index.js @@ -7,27 +7,21 @@ const BASE64 = 'base64'; const toArrayBuffer = (str) => new TextEncoder().encode(str); const encode = (password, content) => { - const pass = toArrayBuffer(password); - const cont = toArrayBuffer(content); - const cipher = crypto.createCipheriv(ALGORITHM, pass, Buffer.alloc(0)); - let encrypted = cipher.update(cont, UTF8, BASE64); + const cipher = crypto.createCipheriv(ALGORITHM, toArrayBuffer(password), Buffer.alloc(0)); + let encrypted = cipher.update(content, UTF8, BASE64); encrypted += cipher.final(BASE64); return encrypted; }; -/* const decode = (password, content) => { - const pass = toArrayBuffer(password); - const cont = toArrayBuffer(content); - const decipher = crypto.createDecipheriv(ALGORITHM, pass, Buffer.alloc(0)); - let decrypted = decipher.update(cont, BASE64, UTF8); + const decipher = crypto.createDecipheriv(ALGORITHM, toArrayBuffer(password), Buffer.alloc(0)); + let decrypted = decipher.update(content, BASE64, UTF8); decrypted += decipher.final(UTF8); return decrypted; }; -*/ module.exports = { encode, - // decode, + decode, __esModule: true, }; diff --git a/node/src/test/test.js b/node/src/test/test.js index 433405e..134231b 100644 --- a/node/src/test/test.js +++ b/node/src/test/test.js @@ -1,13 +1,20 @@ const vulcanQR = require('../index'); const assert = require('assert'); +const password = '0123456789ABCDEF'; +const content = 'CERT#https://api.fakelog.cf/Default/mobile-api#FK100000#ENDCERT'; +const base64 = '27Grk6d8ZDely5eeF7j2ngWrWV9eZa5Dz9ZmuiBavysDp74TCr6EHJOs6TaIXFh3HsROWSM11pv3cPvRGSi7Nw=='; + describe('encoder', () => { it('encodes', () => { - const password = '0123456789ABCDEF'; - const content = 'CERT#https://api.fakelog.cf/Default/mobile-api#FK100000#ENDCERT'; - const base64 = '27Grk6d8ZDely5eeF7j2ngWrWV9eZa5Dz9ZmuiBavysDp74TCr6EHJOs6TaIXFh3HsROWSM11pv3cPvRGSi7Nw=='; - const result = vulcanQR.encode(password, content); assert.equal(result, base64); }); }); + +describe('decoder', () => { + it('decodes', () => { + const result = vulcanQR.decode(password, base64); + assert.equal(result, content); + }); +});