This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TextManipulationHelper from './text-manipulation'; | |
import CryptographyService from './cryptography.service'; | |
const decrypt = async (cipherText: string, secretKey: string, initialVector: string) => { | |
const keyBuffer = TextManipulationHelper.convertBase64ToStream(secretKey); | |
const decryptionKey = await CryptographyService.parseKey(keyBuffer); | |
const cipherBuffer = TextManipulationHelper.convertBase64ToStream(cipherText); | |
const ivBuffer = TextManipulationHelper.convertBase64ToStream<Uint8Array>(initialVector); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TextManipulationHelper from './text-manipulation'; | |
import CryptographyService from './cryptography.service'; | |
const base64 = 'string-in-base64'; | |
const { cipher, key, iv } = await CryptographyService.encrypt(base64); | |
const cipherText = TextManipulationHelper.convertStreamToBase64(cipher); | |
console.log('Cipher: ', cipherText); | |
console.log('Encryption key: ', key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TextManipulationHelper from './text-manipulation'; | |
import type { CryptographyManager, EncryptionKeyManager, EncryptionPayload } from './cryptography.model'; | |
class CryptographyService<T extends AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params = AesKeyGenParams> | |
implements EncryptionKeyManager, CryptographyManager | |
{ | |
public readonly algorithm: T; | |
constructor(algo: T) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface EncryptionKeyManager { | |
parseKey: (key: ArrayBuffer) => Promise<CryptoKey> | |
readKey: (key: CryptoKey) => Promise<ArrayBuffer> | |
} | |
export interface CryptographyManager { | |
generateIv: () => Uint8Array | |
encrypt: (data: string, key: CryptoKey) => Promise<EncryptionPayload> | |
decrypt: (cipher: ArrayBuffer, key: CryptoKey, iv: Uint8Array) => Promise<string> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Text representation conversion | |
const convertStreamToBase64 = (buffer: ArrayBuffer | Uint8Array): string => | |
window.btoa(new Uint8Array(buffer).reduce((a, b) => a + String.fromCharCode(b), '')); | |
const convertBase64ToStream = <T extends ArrayBuffer | Uint8Array>(base64: string, mimeType?: string): T => { | |
let sanitized = base64; | |
if (mimeType) sanitized = sanitized.replace(`data:${mimeType};base64,`, ''); | |
const bin = window.atob(sanitized); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { devices, PlaywrightTestConfig } from '@playwright/test' | |
const config: PlaywrightTestConfig = { | |
projects: [ | |
{ | |
name: 'Desktop__Chromium', | |
use: { ...devices['Desktop Chromium'] } | |
}, | |
{ | |
name: 'Desktop__Safari', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom | |
Object.defineProperty(window, 'matchMedia', { | |
writable: true, | |
value: jest.fn().mockImplementation(query => ({ | |
matches: false, | |
media: query, | |
onchange: null, | |
addEventListener: jest.fn(), | |
removeEventListener: jest.fn(), | |
dispatchEvent: jest.fn() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface DeviceState { | |
isDesktop: boolean | |
desktopOS: DesktopOS | undefined | |
isWindowsDesktop: boolean | |
isLinuxOrUnixDesktop: boolean | |
isMobile: boolean | |
mobileOS: MobileOS | undefined | |
isAndroidDevice: boolean | |
isAppleDevice: boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type DeviceOS = DesktopOS | MobileOS | |
const getDeviceOS = (): DeviceOS | undefined => getMobileOS() ?? getDesktopOS() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum DesktopOS { | |
Linux = 'linux', | |
MacOS = 'mac_os', | |
Unix = 'unix', | |
Unknown = 'unknown', | |
Windows = 'windows' | |
} | |
const getDesktopOS = (): DesktopOS | undefined => { | |
if (isDesktopDevice()) { |
NewerOlder