Skip to content

Instantly share code, notes, and snippets.

View adamTrz's full-sized avatar
🎯
Focusing

Adam Trzciński adamTrz

🎯
Focusing
View GitHub Profile
let options = {};
if (!__DEV__) {
options = {
key: fs.readFileSync('./ssl/key.pem', 'utf8'),
cert: fs.readFileSync('./ssl/cert.pem', 'utf8'),
};
}
const server = __DEV__ ? app : https.createServer(options, app);
export async function setItem(key: string, value: string) {
try {
return Keychain.setGenericPassword(key, encrypt(value), {
service: `${BUNDLE_ID}.${key}`,
});
} catch (error) {
Logger.warn(error.message);
return null;
}
}
let aes256key: ?Array<number>;
sha256([brand, deviceId, ...otherIds].join('')).then(
(hash: string) => {
aes256key = Array.from(
Array.from(hash)
.map((c, i) => (i % 2 ? c : null))
.filter(Boolean)
.map(c => c.charCodeAt(0))
);
const decrypt = (encryptedHex: string) => {
const encryptedBytes = aes.utils.hex.toBytes(encryptedHex);
const aesCtr = new aes.ModeOfOperation.ctr(aes256key);
const decryptedBytes = aesCtr.decrypt(encryptedBytes);
const decryptedText = aes.utils.utf8.fromBytes(decryptedBytes);
return decryptedText;
};
const encrypt = (text: string) => {
const textBytes = aes.utils.utf8.toBytes(text);
const aesCtr = new aes.ModeOfOperation.ctr(aes256key);
const encryptedBytes = aesCtr.encrypt(textBytes);
const encryptedHex = aes.utils.hex.fromBytes(encryptedBytes);
return encryptedHex;
};
export const encryptXOR = (text: string, key: string) => {
const bytes = utf8.encode(text);
const output = [];
for (let i = 0; i < bytes.length; i++) {
output[i] = String.fromCharCode(
bytes[i].charCodeAt(0) ^ key[i % key.length].charCodeAt(0)
);
}
import * as React from 'react'
import { View, Scene, PointLight, Animated } from 'react-vr'
import Planet from './Planet'
import Sun from './Sun'
class App extends React.Component {
render() {
return (
<Scene
@adamTrz
adamTrz / Sun.vr.js
Last active February 24, 2018 13:55
import * as React from 'react'
import { Sphere, PointLight, View, asset } from 'react-vr'
class Sun extends React.Component {
render() {
return (
<View>
<Sphere
radius={5}
widthSegments={30}
import React from 'react'
/*...*/
import AnimatedMath from 'react-native-animated-math'
/*...*/
export default class Globe extends React.Component {
/*...*/
rotation = new Animated.Value(0)
componentDidMount() {
this.spinAround()
@adamTrz
adamTrz / Planet.vr.js
Last active February 28, 2018 14:32
VR Earth
import React from 'react';
import {
AppRegistry,
Sphere,
asset,
View,
PointLight,
Animated,
} from 'react-vr';
import { Easing } from 'react-native';