diff --git a/src/index.test.ts b/src/index.test.ts index 89c5be4..410288d 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -52,7 +52,7 @@ describe('index', () => { privateKey = priv; dataRequest = { healthDepartment: 'Test Health Department', - keyOfHealthDepartment: publicKey, + key: Buffer.from(publicKey, 'utf-8').toString('base64'), keyReferenz: 'random-string-keyref', start: '2011-10-05T14:48:00.000Z', end: '2021-10-05T14:48:00.000Z', @@ -77,7 +77,7 @@ describe('index', () => { }); expect(mockedAxios.get).toHaveBeenCalledWith('/data-requests/12345-abcde'); - mockedAxios.post.mockResolvedValue({ status: 200, data: { success: true } }); + mockedAxios.post.mockResolvedValue({ status: 201, data: { success: true } }); await iris.sendContactsEvents('12345-abcde', submission, { firstName: 'Hans', lastName: 'Müller', diff --git a/src/lib/Iris.ts b/src/lib/Iris.ts index 3d8c519..3dadfbf 100644 --- a/src/lib/Iris.ts +++ b/src/lib/Iris.ts @@ -36,7 +36,7 @@ export default class Iris { } const dataRequest = response.data as IrisDataRequestDTO; this.codeKeyMap.set(code, { - keyOfHealthDepartment: dataRequest.keyOfHealthDepartment, + key: dataRequest.key, keyReferenz: dataRequest.keyReferenz, }); return { @@ -52,15 +52,17 @@ export default class Iris { throw new Error("Code could not be found in key map. Did you perform 'getDataRequest' before?"); } const keys = this.codeKeyMap.get(code); - const { dataToTransport, keyToTransport, nonce } = encryptData(keys.keyOfHealthDepartment, data); + const { dataToTransport, keyToTransport, nonce } = encryptData(keys.key, data); const response = await this.axiosInstance.post(`/data-submissions/${code}/contacts_events`, { - checkCode: [ getNameCheckHash(user.firstName, user.lastName), getBirthDateCheckHash(user.birthDate) ].filter(c => !!c), + checkCode: [getNameCheckHash(user.firstName, user.lastName), getBirthDateCheckHash(user.birthDate)].filter( + (c) => !!c, + ), secret: keyToTransport, keyReferenz: keys.keyReferenz, encryptedData: dataToTransport, - nonce + nonce, } as IrisContactsEventsSubmissionDTO); - if (response.status !== 200) { + if (response.status !== 201) { console.error('IRIS Gateway responded the following data', response.data); throw new Error(`Request failed with status Code ${response.status}`); } diff --git a/src/lib/crypto.ts b/src/lib/crypto.ts index d13c081..e030072 100644 --- a/src/lib/crypto.ts +++ b/src/lib/crypto.ts @@ -9,7 +9,7 @@ export function encryptData( const cipher = crypto.createCipheriv('AES-256-CBC', key, nonce); const dataString = JSON.stringify(data); const encryptedData = Buffer.concat([cipher.update(dataString, 'utf8'), cipher.final()]); - const encryptedKey = crypto.publicEncrypt({ key: keyOfHealthDepartment }, key); + const encryptedKey = crypto.publicEncrypt({ key: Buffer.from(keyOfHealthDepartment, 'base64') }, key); return { dataToTransport: encryptedData.toString('base64'), keyToTransport: encryptedKey.toString('base64'), diff --git a/src/types/IrisCodeKeyMap.ts b/src/types/IrisCodeKeyMap.ts index 0a130cd..70f08bc 100644 --- a/src/types/IrisCodeKeyMap.ts +++ b/src/types/IrisCodeKeyMap.ts @@ -1,5 +1,5 @@ import IrisDataRequestDTO from './dto/IrisDataRequestDTO'; import IrisCode from './IrisCode'; -type IrisCodeKeyMap = Map>; +type IrisCodeKeyMap = Map>; export default IrisCodeKeyMap; diff --git a/src/types/dto/IrisDataRequestDTO.ts b/src/types/dto/IrisDataRequestDTO.ts index 1335608..1680e1c 100644 --- a/src/types/dto/IrisDataRequestDTO.ts +++ b/src/types/dto/IrisDataRequestDTO.ts @@ -1,6 +1,6 @@ export default interface IrisDataRequestDTO { healthDepartment: string; - keyOfHealthDepartment: string; + key: string; keyReferenz: string; start?: string; end?: string;