Skip to content

Instantly share code, notes, and snippets.

View morloy's full-sized avatar

Timo Horstschaefer morloy

View GitHub Profile
from qutip import *
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from IPython.display import Image
tau = 1.
J = 4e-1
A = 0.5
0xDa514178E98109226C4890Af75f533A452133eA9
// /imports/startup/server/twoFactorAuthServer.js
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import SimpleSchema from 'simpl-schema';
import otplib from 'otplib';
import { TwoFactorToken } from '/imports/api/methods/twoFactorAuth';
// Invalidate password login attempt, if 2FA is enabled
// /imports/api/methods/twoFactorAuth.js
import { Meteor } from 'meteor/meteor';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import otplib from 'otplib';
const userIsLoggedIn = (userId: string) => {
if (!userId) {
throw new Meteor.Error('users.not-authorized');
}
// /imports/api/methods/twoFactorAuth.js
import SimpleSchema from 'simpl-schema';
export const TwoFactorToken = {
type: SimpleSchema.Integer, min: 0, max: 999999, optional: true,
};
export const tokenIsValid = (token: string, secret: string) => {
if (!otplib.authenticator.check(token, secret)) {
import { Accounts } from 'meteor/accounts-base';
class LoginForm extends React.Component {
state = {
email: '',
password: '',
token: '',
requiresTwoFactor: false,
loading: false,
};
import { sign } from 'tweetnacl';
import { Buffer } from 'buffer';
const secretKey = Buffer.from('…', 'base64');
const generateCertificateForDocument =
(filename: string, sha256: string, user: string, email: string, userId: string, companyId: string, createdByLedgy: boolean): string => {
const certificate = JSON.stringify({
filename, sha256, user, email, company, createdByLedgy, userId, companyId, version: '1.0.0',
});
import OTS from 'javascript-opentimestamps';
import { getOtsFromCertificate, encodeOts } from './helpers.js';
export const stampCertificate = async (certificate: string): Promise<string> => {
const ots = getOtsFromCertificate(certificate);
await OTS.stamp(ots);
return encodeOts(ots);
};
import OTS from 'javascript-opentimestamps';
import { SHA256, getOtsFromCertificate, decodeOts } from './helpers.js';
const publicKey = Buffer.from('fTrOd0HG8opCEgb+dXvNUXQmzPQqyMGC/IQinDJof1g=', 'base64');
const verifyDocumentOnBlockchain = async (certificate: string, ots: string, docUrl: string) => {
const verifiedCertificate = sign.open(Buffer.from(certificate, 'base64'), publickKey);
if (!verifiedCertificate) {
throw new Error('WARNING: Certificate is invalid');
}
@morloy
morloy / helpers.js
Last active September 12, 2018 17:45
const hexToBytes = (hex: string): Array<number> => {
const bytes = [];
for (let c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return bytes;
};
export const SHA256 = async (doc: ArrayBuffer): Promise<string> => (
crypto ?